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
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
// 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
// | |
// 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
@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]; | |
} |
NewerOlder