Skip to content

Instantly share code, notes, and snippets.

View zats's full-sized avatar

Sash Zats zats

View GitHub Profile
@zats
zats / Output
Last active August 29, 2015 14:27
Fizz Buzz with Gameplay Kit in Swift
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
@zats
zats / random.swift
Last active August 29, 2015 14:27
GKRandomDistribution vs GKShuffledDistribution
import Cocoa
import GameplayKit
let randoms = NSCountedSet()
let shuffles = NSCountedSet()
let gausians = NSCountedSet()
let randomD3 = GKRandomDistribution(lowestValue: 1, highestValue: 3)
let shuffledD3 = GKShuffledDistribution(lowestValue: 1, highestValue: 3)
let gausianD3 = GKGaussianDistribution(lowestValue: 1, highestValue: 3)
@zats
zats / gist:e1524d10e6bd35f15088
Last active August 29, 2015 14:23
Don't let me down
let str: String
dispatch_sync(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0)) { // Variable 'str' used before being initialized
str = "Hello"
}
print(str) // Variable 'str' used before being initialized
@zats
zats / WMLViewDebugging.m
Last active June 28, 2016 01:46
Improving View Debugging in Xcode by showing ViewController class this view belongs to http://blog.zats.io/2015/06/16/improving-view-debugging-in-xcode/
#ifdef DEBUG
#import "WMLSwizzler.h"
static SEL wml_loadViewSEL;
static void wml_swizzleLoadViewForClass(Class class) {
typedef void(*load_view_t)(id, SEL);
__block load_view_t loadView = (load_view_t)[class S_replaceInstanceMethod:wml_loadViewSEL withBlock:^(UIViewController *self){
loadView(self, wml_loadViewSEL);
@zats
zats / README.md
Last active July 11, 2021 16:06
Jeeves configuration sample
  • routes – an array of route objects
    • request - configuration of a request.
      • method – a string according to RFC 2616.
      • pattern - a string to match, can be an escaped regex string. If regex is specified, it must match the entire request path.
    • response - configuration of the response.
      • resourcePath - relative path of the resource to serve, if the request was matched.
      • contentType - optional an override for the resource content type. By default it's automatically deduced from the file MIME type.
@zats
zats / README.md
Last active August 29, 2015 14:19
Make ViewDebugger in Xcode slightly less confusing

Enchance your view debugging with UIView-<MyViewController>

@zats
zats / WMLPushNotificationRegistrationService.h
Last active August 29, 2015 14:13
Push notifications registration: iOS7 & iOS8
#import <Foundation/Foundation.h>
@interface WMLPushNotificationRegistrationService : NSObject
+ (instancetype)sharedInstance;
@property (nonatomic, readonly, getter=isRegisteredForPushNotifications) BOOL registeredForPushNotifications;
/**
* Must be called every app startup, once got user's permission to send push notificaitons
@zats
zats / Node.h
Last active March 18, 2021 17:48
Implementing NSCopying, NSMutableCopying for immutable class with mutable counterpart
#import <Foundation/Foundation.h>
@interface Node : NSObject <NSCopying, NSMutableCopying>
@property (nonatomic, weak, readonly) Node *parent;
@property (nonatomic, strong, readonly) Node *left;
@property (nonatomic, strong, readonly) Node *right;
- (instancetype)initWithParent:(Node *)parent left:(Node *)left right:(Node *)right;
@end
@interface MutableNode : Node
@zats
zats / gist:178d829fed1242b27694
Created December 6, 2014 22:03
Dinamyc programming.swift
func memoize<T: Hashable, U>( body: ((T)->U, T)->U ) -> (T)->U {
var memo = Dictionary<T, U>()
var result: ((T)->U)!
result = { x in
if let q = memo[x] { return q }
let r = body(result, x)
memo[x] = r
return r
}
return result
@zats
zats / NSProcessInfo+WMLCompatibility.m
Created October 5, 2014 11:46
Backport of -[NSProcessInfo isOperatingSystemAtLeastVersion:]
@implementation NSProcessInfo (WMLCompatibility)
+ (void)wml_addSelector:(SEL)originalSelector implementedWithSelector:(SEL)newSelector {
if (![self instancesRespondToSelector:originalSelector]) {
Method newMethod = class_getInstanceMethod(self, newSelector);
class_addMethod(self, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod));
}
}
+ (void)load {