Skip to content

Instantly share code, notes, and snippets.

@wildthink
wildthink / Relay.swift
Last active March 29, 2016 21:12
Relay offers a Swift, type safe way to find a conforming target along the Responder chain and invoke any protocol method on it.
//
// Relay.swift
// XjSwiftLab
//
// Created by Jason Jobe on 5/11/15.
// Copyright (c) 2015 Jason Jobe. All rights reserved.
// https://gist.github.com/wildthink/19d43871964821c4f293
//
import Foundation
@wildthink
wildthink / NSBlockInit.swift
Last active March 28, 2016 17:28
NSBlockInit offers a Swift extension to the initialization protocols so you can easily chain a setup block as part of the basic init() are by using setup(Self) chained onto the init.
//
// NSBlockInit.swift
// XjSwiftLab
//
// Created by Jason Jobe on 3/19/16.
// Copyright (c) 2016 Jason Jobe. All rights reserved.
// https://gist.github.com/wildthink/48cce4cd2f27695ebb08
//
// Thanks to Mike Ash for his expertise and support of the community
// https://www.mikeash.com/pyblog/friday-qa-2015-12-25-swifty-targetaction.html
@wildthink
wildthink / ActionTrampoline.swift
Last active December 5, 2019 21:08
ActionTrampoline - Use Swift blocks for your Control actions
//
// ActionTrampoline.swift
// Swift 3
//
// Created by Jason Jobe on 3/17/16.
// Copyright © 2016 WildThink. All rights reserved.
//
// https://gist.githubusercontent.com/wildthink/677308084ab364044c76/raw/f713efca9ec6ca9b56c4405bd82ae33b1db98ec7/ActionTrampoline.swift
//
// Kudos (again) to Mike Ash!
@wildthink
wildthink / EnumCollection.swift
Last active October 27, 2017 16:45
Swift Integer enum sequence
// Distilation of ideas and examples from these great contributions to the community
// http://stackoverflow.com/questions/24007461/how-to-enumerate-an-enum-with-string-type
// https://forums.developer.apple.com/thread/4404
// https://www.natashatherobot.com/swift-conform-to-sequence-protocol/
// https://theswiftdev.com/2017/10/12/swift-enum-all-values/
import Foundation
public protocol EnumCollection: Hashable {
static func cases() -> AnySequence<Self>
@wildthink
wildthink / transducers.swift
Created November 21, 2016 18:21 — forked from rjchatfield/transducers.swift
Transducers & Reducers in Swift 2
//-- This is an introduction to Transducers in Swift, inspired by
// Talk: https://www.youtube.com/watch?v=estNbh2TF3E
// Code: https://github.com/mbrandonw/learn-transducers-playground
// Updated with Swift 2
/**
* Define a few test methods
*/
/// REDUCER
func append <A> (xs: [A], x: A) -> [A] { return xs + [x] }
@wildthink
wildthink / StringLiteral.swift
Created December 30, 2016 19:23 — forked from russbishop/StringLiteral.swift
Make ExpressibleByStringLiteral tolerable
// If you want types initializable from String literals
// but don't want to implement three separate initializers.
extension ExpressibleByUnicodeScalarLiteral where Self: ExpressibleByStringLiteral, Self.StringLiteralType == String {
public init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
}
I am jason_ at onename.com
@wildthink
wildthink / dawg.py
Created January 10, 2017 19:37 — forked from smhanov/dawg.py
Use a DAWG as a map
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Updated 2014 to use DAWG as a mapping.
import sys
import time
DICTIONARY = "/usr/share/dict/words"
QUERY = sys.argv[1:]
# This class represents a node in the directed acyclic word graph (DAWG). It
@wildthink
wildthink / Domain.swift
Last active January 13, 2017 17:46
Simple data store API for Swift applications.
//
// Domain.swift
// Inspired by Eve
//
// Created by Jason Jobe on 11/26/16.
// Copyright © 2016 Jason Jobe. All rights reserved.
// https://gist.github.com/wildthink/b911a5b8e0d7dc6ef190fd8fe4f7a2ee
//
import Foundation
//
// Relay.swift
// XjSwiftLab
//
// Created by Jason Jobe on 5/11/15.
// Copyright (c) 2015, 2016 Jason Jobe. All rights reserved.
// https://gist.github.com/wildthink/acfdf82c2625dc73ad6e42d399d91846
//
/* Example usage