[objective-c]UILabelを複製する

UILabelを複製する

-(UILabel*)getCloneUILabelByUILabel:(UILabel*)label
{
    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:label];
    return [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
}
UILabel*cloneLabel = [self getCloneUILabelByUILabel:modelLabel];

[JavaScript]プロパティ名を指定してソート

プロパティ名を指定してソート

function g_sortOn(_propertyName){
    return function(a,b){
        if( a[_propertyName] > b[_propertyName] )return 1;
        if( a[_propertyName] < b[_propertyName] )return -1;
        return 0;
    }
}
var tmp = targetArray.sort( g_sortOn('name') );

[MySQL]ビット演算#1

ビット演算#1
type(INTEGER)を4ビット右シフトして右端が1であるレコードのidとtypeを取得する。

SELECT id,type FROM target_table_name WHERE type >> 4 & 1 = 1;

[objective-c]2つの日付の差を日数で出す

2つの日付の差を日数で出す

int dayCount = [self getDaysCountByTwoDateString:@"2014-04-01" endDateString:@"2014-04-04"];
-(int)getDaysCountByTwoDateString:(NSString*)startDateString endDateString:(NSString*)endDateString
{
    NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init];
    [inputDateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *startInputDate = [inputDateFormatter dateFromString:startDateString];
    NSDate *endInputDate = [inputDateFormatter dateFromString:endDateString];
    
    float tmp= [endInputDate timeIntervalSinceDate:startInputDate];
    int day=(int)( tmp / (3600.0*24.0) );
    return day;
}

[PHP]URLを取得

URLを取得

$url = (empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

[objective-c]animateWithDurationを途中で止める

animateWithDurationを途中で止める

アニメーション実行

[UIView animateWithDuration:10.0f animations:^{
    targetView.frame=CGRectMalke(0.0,0.0,100.0,100.0);
} completion:^(BOOL finished) {
    
}];

アニメーション中止

[UIView setAnimationBeginsFromCurrentState:YES];
[UIView animateWithDuration:0.001 animations:^{
    targetView.alpha = 1.0;
}];

[jQuery]$.ajaxでcookieも送信

$.ajaxでcookieも送信
IE10未満は不可

$.ajax({
    type:'post',
    url:'url',
    dataType:'text',
    data:data,
    crossDomain:true,
    cache:false,
    xhrFields: {
        withCredentials:true
    },
    success:function(data, dataType){
        
    },
    error:function(XMLHttpRequest, textStatus, errorThrown){
        
    },
    complete:function(){
        
    }
});