[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(){
        
    }
});

[objective-c]UIScrollViewのスクロール先のページインデックスを取得

pagingEnabled=YESのUIScrollViewのスクロール先のページインデックスを取得

ヘッダーファイル

<UIScrollViewDelegate>

メインファイル

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    CGFloat width = scrollView.frame.size.width;
    NSInteger page = (targetContentOffset->x + (0.5f * width)) / width;
    int index=(int)page;   
}

[objective-c]performSelectorの警告を消す

performSelectorの警告を消す

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

if (_delegate && _selector && [_delegate respondsToSelector:_selector]) {
    SuppressPerformSelectorLeakWarning([_delegate performSelector:_selector withObject:[NSNumber numberWithBool:success]]);
}

[objective-c]フォルダを作る

フォルダを作る

-(BOOL)makeDir:(NSString*)dirPath
{
    NSString* path=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    path=[path stringByAppendingPathComponent:dirPath];
    NSError *error;
    BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:path
                                            withIntermediateDirectories:YES
                                                             attributes:nil
                                                                  error:&error];
    return result;
}

[self makeDir:@"test1/test2/jack"];

上記を実行すると下記の3つのフォルダが作られる。
test1
test1/test2
test1/test2/jack