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
js / .gitconfig
Last active May 22, 2019
fuzzy selection of git branch, files to (un)stage using https://github.com/lotabout/skim
View .gitconfig
....
[alias]
sel = select
asel = add-select
rsel = reset-select
...
View git-recent
#!/bin/sh
git log --no-walk --date-order --oneline --decorate $(git rev-list --branches --no-walk)
View keymap.eep
:10000000FFFFFFFFFFFFFFFF012300230060FFFF53
:1000100041F7F1A100000000000000000000000016
:1000200000000000000000000000000000000000D0
:1000300000000000000000000000000000000000C0
:1000400000000000000000000000000000000000B0
:100050000000291E1F20212223242526272D2E2A99
:100060004C0000002B141A0815171C180C12132F23
:1000700030314A00000039041607090A0B0D0E0F33
:10008000333400284E000000E1641D1B06190511E1
:1000900010363738E5524B000000C0E2E3000000A4
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)")
View config.fish
function current_git_branch
sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
end
View shadowing-self.swift
// weak-strong dance by shadowing self
foo { [weak self] in
guard let `self` = self else { return }
self.bar()
}
@js
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)