Skip to content

Instantly share code, notes, and snippets.

View DecodingHomogeneousArrays.swift
import UIKit
enum Item: Codable {
case int(Int)
case string(String)
private enum CodingKeys: String, CodingKey {
case kind
case value
js / .gitconfig
Last active May 22, 2019
fuzzy selection of git branch, files to (un)stage using
View .gitconfig
sel = select
asel = add-select
rsel = reset-select
View git-recent
git log --no-walk --date-order --oneline --decorate $(git rev-list --branches --no-walk)
View keymap.eep
View Observable.swift
//: Playground - noun: a place where people can play
import UIKit
struct Person {
var name = Observable("Bob")
enum Event<T> {
case next(T)
View rx.swift
enum Event<T> {
case next(T)
case error(Error)
case completed
final class AnyObservable<T> {
let handler: (@escaping (Event<T>) -> Void) -> Void
init(handler: @escaping (@escaping (Event<T>) -> Void) -> Void) {
View valist.swift
func fetch1(where predicateFormat: String, _ args: CVarArg...) {
// using: public convenience init(format predicateFormat: String, _ args: CVarArg...)
let predicate = NSPredicate(format: predicateFormat, args)
print("fetch1 predicate: \(predicate)")
func fetch2(where predicateFormat: String, _ args: Any...) {
// Using: public init(format predicateFormat: String, argumentArray arguments: [Any]?)
let predicate = NSPredicate(format: predicateFormat, argumentArray: args)
print("fetch2 predicate: \(predicate)")
function current_git_branch
sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
View shadowing-self.swift
// weak-strong dance by shadowing self
foo { [weak self] in
guard let `self` = self else { return }
js / gist:9277611
Created Feb 28, 2014
You shouldn't use objc exceptions for flow control, among many reasons they're a tad slow.
View gist:9277611
// Output on this particular Mac
// Exceptions took 5.054922
// BOOL return + NSError took 0.251062
#import <Foundation/Foundation.h>
#import <mach/mach_time.h>
static inline void TimeDuration(NSString *description, NSUInteger runs, dispatch_block_t block)