Skip to content

Instantly share code, notes, and snippets.

View rizumita's full-sized avatar
🏠
Working from home

Ryoichi Izumita rizumita

🏠
Working from home
View GitHub Profile
@rizumita
rizumita / Use UISearchBar & UISearchDisplayController.m
Created May 16, 2011 08:13
Use UISearchBar & UISearchDisplayController
UISearchBar *searchBar = [[[UISearchBar alloc] initWithFrame:CGRectZero] autorelease];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
[[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.searchResultsDelegate = self;
@rizumita
rizumita / MBProgressHUD with Blocks.m
Created May 20, 2011 03:38
MBProgressHUD with Blocks
#if NS_BLOCKS_AVAILABLE
- (void)showWhileExecutingBlock:(void (^)())block animated:(BOOL)animated {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
block();
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self cleanUp];
});
});
@rizumita
rizumita / gist:986108
Created May 23, 2011 02:09
NSString and NSNumber times repeat method like Ruby's times method
@interface NSString (Times)
- (void)times:(void (^)(void))block;
@end
@implementation NSString (Times)
- (void)times:(void (^)(void))block {
for (NSUInteger index = 0; index < [self longLongValue]; index++) {
block();
}
}
@rizumita
rizumita / gist:1394522
Created November 25, 2011 22:03
Objective-C Currying
@interface NSObject (Curry)
- (id)curry:(SEL)selector;
@end
@implementation NSObject (Curry)
- (id)curry:(SEL)selector {
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
if (signature) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.selector = selector;
@rizumita
rizumita / Flip Segue.m
Created February 3, 2012 21:36
Flip Segue
- (void)perform {
UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;
[UIView transitionWithView:sourceViewController.navigationController.view
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}
completion:nil];
@rizumita
rizumita / gist:4016111
Created November 5, 2012 08:59
Mail.appで選択したメールのMailTagsによるキーワードとプロジェクトを取得するAppleScript
tell application "Mail"
set selectedMails to the selection
using terms from application "MailTagsHelper"
set keyword to keywords of item 1 of selectedMails
set myproject to project of item 1 of selectedMails
end using terms from
display dialog keyword
display dialog myproject
end tell
@rizumita
rizumita / gist:5178986
Created March 17, 2013 00:31
NSEG 第37回勉強会で作成したコード
println(args(0).toList.reverse.zipWithIndex.map{case(x,i)=>val k=" 十百千"(i)
val n=" 一二三四五六七八九"(x.toString.toInt)
n match{case' '=>""case'一'if k!=' '=>k
case _=>n+k.toString}}.reverse.mkString.trim)
@rizumita
rizumita / gist:7725401
Created November 30, 2013 22:24
画像を左、タイトルを右に配置したNSButtonを作る
NSButton *button = [[NSButton alloc] init];
[button setImage:[NSImage imageNamed:@"Foo"]];
button.imagePosition = NSImageLeft;
button.title = @"text"
[button setBordered:NO];
@rizumita
rizumita / gist:7802174
Created December 5, 2013 08:53
NSNotificationCenter/NSNotificationをReactiveCocoaで利用する方法。selfが解放される時に自動的に通知が停止する。
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:notification object:nil] takeUntil:[self rac_willDeallocSignal]] subscribeNext:^(NSNotification *notification) {
NSLog(@"%@", notification);
}];
@rizumita
rizumita / gist:7978754
Created December 15, 2013 21:59
ReactiveCocoaでKVOの新旧の値を受け取る
[[object rac_valuesAndChangesForKeyPath:@keypath(object, keypath) options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld observer:nil] subscribeNext:^(RACTuple *tuple) {
NSDictionary *changeDictionary = tuple.second;
if (![changeDictionary[@"new"] isEqualToNumber:changeDictionary[@"old"]]) {
}
}];