Skip to content

Instantly share code, notes, and snippets.


Tom Lokhorst tomlokhorst

View GitHub Profile
tomlokhorst / AppDelegate.swift
Created Jun 6, 2019
Xcode 11 iOS 12 crash: failed to demangle witness for associated type
View AppDelegate.swift
import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
tomlokhorst / NSUserDefaults+Keys.swift
Created Jul 26, 2015
Strongly typed NSUserDefaults using Phantom Types.
View NSUserDefaults+Keys.swift
// We can use Phantom Types to provide strongly typed acces to NSUserDefaults
// Similar to:
// A key to UserDefaults has a name and phantom type
struct Key<T> {
let name: String
tomlokhorst / gist:663733aa392e5dc19438
Created May 27, 2015
Json model vs Domain model
View gist:663733aa392e5dc19438
/* Domain model */
// A Profile consists of a person name and an optional avatar
struct Profile {
let personName: PersonName
let avatarURL: NSURL?
// These are the UX rules for showing a greeting:
tomlokhorst / invalid-cast.swift
Created Mar 4, 2015
Invalid cast causing runtime crash in Swift <= 1.2
View invalid-cast.swift
import Foundation
let obj = NSNumber(int: 2)
func correct<T>() -> T? {
if let val = obj as? T {
println("matching types")
return val
tomlokhorst /
Last active Aug 29, 2015
Example of wrapping a RxJava Observable to get promise semantics.
// This is now available as a full library instead of a gist:
tomlokhorst / gist:413457d8956d01638993
Created Dec 18, 2014
Don't zoom in on Google Maps when scrolling through a website
View gist:413457d8956d01638993
function fixMapScrollwheel(map) {
map.setOptions({ scrollwheel: false });
google.maps.event.addListener(map, 'click', function() {
map.setOptions({ scrollwheel: true });
google.maps.event.addListener(map, 'mouseout', function() {
map.setOptions({ scrollwheel: false });
View gist:6ed40e0e00cd2989a282
tomlokhorst / Optional+Unwrap.swift
Last active Dec 26, 2017
Unwrap multiple optionals in Swift 1.0
View Optional+Unwrap.swift
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
return nil
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
View gist:d9d19559f7e2ab3610a7
// Current (C# 5) syntax
var request = new CreateIndexRequest("new-index-name")
IndexSettings = new IndexSettings
Settings = new Dictionary<string, object>
{"index.settings", "value"}
Mappings = new List<RootObjectMapping>
View tyingtheknot.hs
, TemplateHaskell
module Tie where
import Prelude hiding ((.), id)
import Control.Category
import Data.Record.Label
You can’t perform that action at this time.