Skip to content

Instantly share code, notes, and snippets.

View k06a's full-sized avatar
🚀
DeFi dreamer

Anton Bukov k06a

🚀
DeFi dreamer
View GitHub Profile
#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:)),
@k06a
k06a / UIColor+Interpolation.m
Created June 16, 2015 14:59
UIColor+Interpolation
+ (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
#import <UIKit/UIKit.h>
@interface TintedButton : UIButton
@end
@k06a
k06a / ViewController.m
Created May 20, 2015 15:02
Show/hide navigation bar on push/pop
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if (self.isMovingFromParentViewController)
@k06a
k06a / gist:7daf00b7c72e3db15adc
Created February 1, 2015 01:02
Prime numbers integral by Eratosthenes
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);
}
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];
@k06a
k06a / SwiftHaskellElem
Created August 30, 2014 23:01
Swift implementation of Haskell elem function
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
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) }
}
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) }
}
@interface NSIndexPath (SharedIndexPath)
@end
@implementation NSIndexPath (SharedIndexPath)
+ (instancetype)sharedIndexPathForRow:(NSInteger)row inSection:(NSInteger)section
{
static NSIndexPath *arr[10][10] = {nil};
if (arr[row][section] == nil)
arr[row][section] = [NSIndexPath indexPathForRow:row inSection:section];
return arr[row][section];
}