This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
#import <objc/runtime.h> | |
@implementation NSControl (Subclasses) | |
+ (void)load | |
{ | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
method_exchangeImplementations(class_getInstanceMethod([self class], @selector(initWithCoder:)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIColor *)colorBetweenColor:(UIColor *)color1 | |
andColor:(UIColor *)color2 | |
atProgress:(CGFloat)progress | |
{ | |
CGFloat r1,g1,b1,a1,r2,g2,b2,a2; | |
[color1 getRed:&r1 green:&g1 blue:&b1 alpha:&a1]; | |
[color2 getRed:&r2 green:&g2 blue:&b2 alpha:&a2]; | |
return [UIColor colorWithRed:r1+(r2-r1)*progress | |
green:g1+(g2-g1)*progress | |
blue:b1+(b2-b1)*progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
[self.navigationController setNavigationBarHidden:NO animated:YES]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
if (self.isMovingFromParentViewController) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int64_t nn = 100000000; | |
vector<int> ip(nn,1); | |
size_t pos = 2; | |
ip[0] = 0; | |
ip[1] = 0; | |
while ((pos = find(ip.begin()+pos, ip.end(), 1) - ip.begin()) < nn) { | |
for (size_t j = pos*pos; j < ip.size(); j+=pos) | |
ip[j] = 0; | |
pos += 1 + (pos>2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before iOS 8, you do this: | |
``` | |
[backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext]; | |
[backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil]; | |
``` | |
in iOS 8, you have to do this: | |
``` | |
backgroundViewController.providesPresentationContextTransitionStyle = YES; | |
backgroundController.definesPresentationContext = YES; | |
[overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func elem<T: Equatable>(item: @autoclosure ()->T) -> (@autoclosure ()->[T]) -> Bool { | |
return { (arr: @autoclosure ()->[T]) in find(arr(), item()) != nil } | |
} | |
let found = elem (2) ([1,2,3]) // Hope to avoid braces in future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefix func !<T>(f: (T)->Bool) -> (T)->Bool | |
{ | |
return { !f($0) } | |
} | |
func &&<T>(f1: (T)->Bool, f2: (T)->Bool) -> (T)->Bool | |
{ | |
return { f1($0) && f2($0) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func bind1<T1,V>(f: (T1)->V, t1: T1) -> ()->V | |
{ | |
return { () -> V in f(t1) } | |
} | |
func bind1<T1,T2,V>(f: (T1,T2)->V, t1: T1) -> (T2)->V | |
{ | |
return { t2 -> V in f(t1,t2) } | |
} |