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
// 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
// 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
"use strict"; | |
ObjC.import('Foundation'); | |
var fm = $.NSFileManager.defaultManager; | |
var app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
var path = $.NSString.alloc.initWithUTF8String(app.pathTo(this)).stringByDeletingLastPathComponent.js + "/"; |
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
////////////////////// | |
// File 1 | |
public class Base { | |
public struct Overridable { // Do not store | |
private init() {} | |
} | |
public struct Protected { // OK to store |
OlderNewer