Skip to content

Instantly share code, notes, and snippets.

View zats's full-sized avatar

Sash Zats zats

View GitHub Profile
@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 / 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 / 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 / UIViewController.m
Last active October 5, 2015 02:35
UIViewController implementation details for view and loadViewIfNeeded
- (UIView *)view {
[self loadViewIfRequired];
return _existingView;
}
- (void)loadViewIfNeeded {
[self loadViewIfRequired];
}
@zats
zats / gist:4068316
Created November 13, 2012 20:52
Updating fork from original repository
# Adding original repository as a fork
git remote add --track master forked_from git://github.com/user/repo.git
# Fetch from remote called forked_from
git fetch forked_from
# Merging codeabase
git merge forked_from/master
@zats
zats / gist:5212898
Last active December 15, 2015 05:59
Dynamic category icons – Foursquare approach
- (AFHTTPRequestOperation *)imageFetchOperationForCategoryWithURL:(NSURL *)URL success:(void(^)(AFHTTPRequestOperation *operation, id response))success failure:(void(^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
static NSString *categoriesCacheDirectory;
static NSCache *inMemoryCache;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
inMemoryCache = [[NSCache alloc] init];
categoriesCacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
categoriesCacheDirectory = [categoriesCacheDirectory stringByAppendingPathComponent:@"location_icons"];
@zats
zats / ChangeType.md
Last active December 25, 2015 23:58
Knowing the nature of text changes, helps to deal with it better.

Change type enumeration

typedef NS_ENUM(NSUInteger, SZSTextChangeType) {
	SZSTextChangeTypeDelete,
	SZSTextChangeTypeInsert,
	SZSTextChangeTypeReplace
};
@zats
zats / UIStoryboardSegueTemplate.m
Last active January 2, 2016 12:59
Guessed implementation of the `-[UIStoryboardSegueTemplate _perform:]`
- (void)_perform:(id)sender {
NSString *identifier = self.destinationViewControllerIdentifier;
UIViewController *sourceViewController = self.viewController;
UIStoryboard *storyboard = sourceViewController.storyboard;
UIViewController *destinationViewController = [storyboard instantiateViewControllerWithIdentifier:identifier];
UIStoryboardSegue *segue = [self segueWithDestinationViewController:destinationViewController];
[sourceViewController prepareForSegue:segue
sender:destinationViewController];
[segue perform];
}
@zats
zats / post-checkout.sh
Last active January 3, 2016 14:19
Git hook to run pod install automatically upon checkout if Podfile change comparing to the last commit
# Existent podfile
current_directory="${PWD}"
current_podfile_path="$current_directory/Podfile"
current_directory_md5=`md5 -q -s "$current_directory"`
temporary_podfile_path="/tmp/${current_directory_md5}.podfile"
echo "Comparing Podfiles\nOld: $current_podfile_path\nNew: $temporary_podfile_path"
# Comparing it to the new Podfile
comparison_result=`comm -1 -3 -i $current_podfile_path $temporary_podfile_path`
@zats
zats / 0_reuse_code.js
Created January 20, 2014 15:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console