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
@interface UIImage (ResizeableFallback) | |
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets; | |
@end | |
@implementation | |
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets | |
{ | |
if ([UIImage respondsToSelector:@selector(resizableImageWithCapInsets:)]) | |
return [self resizableImageWithCapInsets: insets]; | |
return [self stretchableImageWithLeftCapWidth:insets.left topCapWidth:insets.top]; | |
} |
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
// | |
// Usage: `[item.self anyMethod]` is valid for `item` equals to `[NSNull null]` | |
// | |
@interface NSNull (SelfOrNil) | |
@end |
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
// Copyright 2013 (c) Anton Bukov - https://github.com/k06a | |
// Inspired by http://graphics.stanford.edu/~seander/bithacks.html | |
#define P0(a) (a) | |
#define P1(a) (((P0(a) & 0x55555555) << 1) | ((P0(a) & 0xAAAAAAAA) >> 1)) | |
#define P2(a) (((P1(a) & 0x33333333) << 2) | ((P1(a) & 0xCCCCCCCC) >> 2)) | |
#define P3(a) (((P2(a) & 0x0F0F0F0F) << 4) | ((P2(a) & 0xF0F0F0F0) >> 4)) | |
#define P4(a) (((P3(a) & 0x00FF00FF) << 8) | ((P3(a) & 0xFF00FF00) >> 8)) | |
#define P5(a) (((P4(a) & 0x0000FFFF) << 16) | ((P4(a) & 0xFFFF0000) >> 16)) |
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
template<typename TI, typename TV> | |
int BinSearch(TI begin, TI end, TV value) | |
{ | |
int minIndex = 0; | |
int maxIndex = end - begin - 1; | |
while (minIndex <= maxIndex) | |
{ | |
int midIndex = (minIndex + maxIndex) / 2; | |
TI comparison = begin + midIndex; |
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
// | |
// Here is some illustration of central kick: | |
// https://commons.wikimedia.org/wiki/File:Elastischer_stoß3.gif | |
// | |
// V -V | |
// [m = 2]---> <---[m = 1] | |
// [m = 2] [m = 1] | |
// [m = 2][m = 1] | |
// [m = 2] [m = 1] | |
// <-[m = 2] [m = 1]-----> |
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]; |
OlderNewer