This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C# equivalent of buckets.swift | |
using System; | |
using System.Collections.Generic; | |
interface IFeed { | |
String url { get; } | |
} | |
class LocalFeed : IFeed { | |
public String url { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Protocol | |
protocol Feed { | |
var url : String { get } | |
} | |
// Concrete classes | |
class LocalFeed : Feed { | |
var url : String = "file://Local" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Types work but are not optimal - no error handling | |
// Demo in response to https://gist.github.com/sketchytech/029c00a74a4217a89797 | |
extension CollectionType { | |
func reorder<T>(sorter: [(index: Self.Index, element: T)]) -> Array<Self.Generator.Element> { | |
return sorter.map({self[$0.index]}) | |
} | |
} | |
func sortColumns<T0, T1>(_ col0: Array<T0>, _ col1: Array<T1>, _ cmp: (T0,T0)->Bool) -> (Array<T0>, Array<T1>) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sizes = [ | |
// [ 640, 960, "phone-35"], | |
[ 640, 1136, "phone-40"], | |
[ 750, 1334, "phone-47"], | |
[1242, 2208, "phone-55"], | |
// [ 768, 1024, "pad-x1"], | |
[1536, 2048, "pad-x2"], | |
[2048, 2732, "pad-pro"], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just some noodling based on Brent's interest in Swift responder chains: http://inessential.com/2016/05/15/a_hypothetical_responder_chain_written_i | |
// Just showing that responder chain can easily fit with the level of dynamism in Swift today | |
infix operator >>> { associativity left } | |
func >>> <In, Middle, Out>(first: In -> Middle, second: Middle -> Out) -> In -> Out { | |
return { x in second(first(x)) } | |
} | |
func >>> <In, Out>(deduce: In.Type, fn: In -> Out) -> In -> Out { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code generation! | |
let props = ["name", "value", "thing"] | |
for prop in props { | |
print([ | |
"if local.\(prop) != remote.\(prop) {", | |
" local.\(prop) = remote.\(prop)", | |
" changes[\(prop)Key] = remote.\(prop)", | |
"}", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dynamic cast without bridging | |
func dynamicCast<T>(_ type: T.Type, _ v: Any)->T? { | |
guard let result = v as? T where v.dynamicType is T.Type else { | |
return nil; | |
} | |
return result | |
} | |
// Return a 2uple if both objects are convertible to type T, otherwise nil | |
func matchCast<T>(_ type: T.Type, _ l: Any, _ r: Any)->(T, T)? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> | |
inline T* as(NSObject* o) { | |
if ([o isKindOfClass: [T class]]) { | |
return (T*)o; | |
} | |
return nil; | |
} | |
template <class T> | |
inline bool is(NSObject* o) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift Ver. 3.0.1 (Release) | |
// Platform: Linux (x86_64) | |
// Noodling with syntax for call avoidance with optional arguments | |
// Just to get a sense of what it could look like | |
// Given a function "fn" that takes 2 non-optional arguments | |
// We can enable this syntax: | |
// let result = fn<-?(a, b) | |
// where a and b are optionals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"include": { | |
"prefix": "#inc", | |
"body": [ | |
"#include \"$1\"", | |
"$0" | |
], | |
"description": "#include \"\"" | |
} | |
,"include-system": { |
OlderNewer