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
- (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
+ (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
#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; |
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
@implementation UIImage (Grayscale) | |
UIImage *grayscaleImageFromCIImage(CIImage *image, CGFloat scale) { | |
CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, image, @"inputBrightness", @0.0, @"inputContrast", @1.1, @"inputSaturation", @0.0, nil].outputImage; | |
CIImage *output = [CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", @0.7, nil].outputImage; | |
CGImageRef ref = [[CIContext contextWithOptions:nil] createCGImage:output fromRect:output.extent]; | |
UIImage *result = [UIImage imageWithCGImage:ref scale:scale orientation:UIImageOrientationUp]; | |
CGImageRelease(ref); | |
return result; | |
} |
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
# Fetch | |
git clone https://github.com/username/reponame reponame | |
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done | |
# Analyze | |
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py && sudo python get-pip.py && rm get-pip.py | |
sudo pip install git-fat | |
git fat -a find 1000000 | |
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4 |
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 <Foundation/Foundation.h> | |
namespace cv { | |
class Mat; | |
} | |
@interface NSValue (CVMat) | |
+ (instancetype)valueWithCVMat:(cv::Mat)mat; | |
@property (readonly) cv::Mat CVMatValue; |