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) } | |
} |
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 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
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
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
#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
string add(const string & s1, const string & s2) | |
{ | |
int flag = 0; | |
string ret(std::max(s1.size(),s2.size())+1, '0'); | |
for (int i = 0; i < ret.size(); i++) { | |
int v = (i < s1.size() ? s1[s1.size()-1-i]-'0' : 0) | |
+ (i < s2.size() ? s2[s2.size()-1-i]-'0' : 0) + flag; | |
flag = v/10; | |
v -= flag*10; | |
ret[ret.size()-1-i] = v+'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
struct RefString | |
{ | |
RefString(const string & s, int i, int l) : s(s), i(i), l(l) {} | |
const char & operator [] (int x) const { | |
return s[i+x]; | |
} | |
size_t length() const { | |
return l; |
OlderNewer