Skip to content

Instantly share code, notes, and snippets.

@tomlokhorst
tomlokhorst / gist:663733aa392e5dc19438
Created May 27, 2015 18:00
Json model vs Domain model
/* 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
tomlokhorst / invalid-cast.swift
Created March 4, 2015 18:29
Invalid cast causing runtime crash in Swift <= 1.2
import Foundation
let obj = NSNumber(int: 2)
func correct<T>() -> T? {
if let val = obj as? T {
println("matching types")
return val
}
@tomlokhorst
tomlokhorst / Promise.java
Last active August 29, 2015 14:16
Example of wrapping a RxJava Observable to get promise semantics.
// This is now available as a full library instead of a gist: https://github.com/Q42/RxPromise
@tomlokhorst
tomlokhorst / gist:413457d8956d01638993
Created December 18, 2014 09:01
Don't zoom in on Google Maps when scrolling through a website
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 });
});
@tomlokhorst
tomlokhorst / gist:6ed40e0e00cd2989a282
Last active August 29, 2015 14:08
SegueManager.swift
// 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>