Skip to content

Instantly share code, notes, and snippets.

View zats's full-sized avatar

Sash Zats zats

View GitHub Profile
@zats
zats / script.swift
Last active March 5, 2021 01:32
Update all your plugins for the latest Xcode beta with a single
#!/usr/bin/env xcrun swift
// $ chmod +x script.swift
// $ ./script.swift
// or $ ./script.swift -xcode=/Applications/Xcode-beta.app
import Foundation
@noreturn private func failWithError(message: String) {
print("🚫 \(message)")
@zats
zats / dictionary_diff.swift
Created August 20, 2015 20:53
Abandoned dictionary diffing in swift
import Foundation
extension Dictionary {
static func keyDifference<Value: Equatable>(dictionary1 dic1: Dictionary<Key, Value>, dictionary2 dic2: Dictionary<Key, Value>, inout inserted: Set<Key>, inout deleted: Set<Key>, inout updated:Set<Key>, inout unchanged: Set<Key>) {
let keys1 = Set(dic1.keys.array)
let keys2 = Set(dic2.keys.array)
let allKeys = keys1.union(keys2)
inserted = []
@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