Skip to content

Instantly share code, notes, and snippets.

@katsuhide
katsuhide / NSThreadTest.m
Created June 2, 2013 13:25
スレッド周り
// 3秒スリープ
[NSThread sleepForTimeInterval:3];
// DB設定情報
NSString *databaseName = @"main.db";
NSString *path = @"/tmp";
NSString *databasePath = [path stringByAppendingPathComponent:databaseName];
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
// Query
NSString *sql = @"select hoge1, hoge2 participants from hoge;";
// Open DB
@katsuhide
katsuhide / NSTimerTest.m
Last active December 17, 2015 22:59
タイマー周りの処理
/*
* main
*/
- (void)run{
// タイマーで使うデータ
NSNumber *number = [[NSNumber alloc] initWithInt:1];
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:number forKey:@"count"];
// タイマーを作成
NSTimer *timer = [NSTimer
@katsuhide
katsuhide / NSDateTest.m
Created May 31, 2013 15:25
時間まわりの処理
// 現在時間を取得
NSDate *now = [NSDate date];
NSLog(@"now:%@", [now toLocalTime]); // now:2013-06-01 00:19:46 +0000
// 現在時間にインターバル時間を足す
NSTimeInterval interval = 3600; // 秒
NSDate *after = [now dateByAddingTimeInterval:interval];
NSLog(@"after:%@", [after toLocalTime]); // after:2013-06-01 01:19:46 +0000
// 時間の判定
@katsuhide
katsuhide / NSDate+Util.h
Created May 31, 2013 15:14
ローカル時刻を取得するようにNSDateを拡張
@interface NSDate (Util)
- (NSDate*)toLocalTime;
@end
@katsuhide
katsuhide / reg.rb
Created April 2, 2013 00:03
正規表現を使った文字列の加工
a = "foo bar baz"
puts a
puts a.scan(/f+/)
puts "========"
b = "foo 10 bar 20 baz 30"
puts b
puts b.scan(/\w+/)
puts "========"