This file contains hidden or 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
extension String { | |
subscript(safe index: String.CharacterView.Index) -> Character? { | |
guard index < endIndex else { return nil } | |
return self[index] | |
} | |
} | |
public final class Brainfuck { | |
public enum Token { |
This file contains hidden or 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
import Darwin.C | |
import Venice | |
struct SubProcess { | |
let path: String | |
let arguments: [String] | |
func run(sync sync: Bool = true) -> Int? { |
This file contains hidden or 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 the url for my server. | |
let client = Client(base: "www.myblog.com", method: .GET) | |
//This is the api path. | |
let api = client.endpoint("/api/v1", method: .GET) | |
//This endpoint builds off of the api endpoint. | |
let posts = api.endpoint("/posts", method: .GET) | |
//This endpoint takes the response from that endpoint, uses it as a parameter for this endpoint |
This file contains hidden or 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
postfix operator +++ {} | |
postfix func +++(inout x: Int) -> Int { | |
let y = x | |
x += 1 | |
return y | |
} | |
var i = 0 // -> 0 | |
i+++ // -> 0 |
This file contains hidden or 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
struct RouteStorage { | |
var componentsTrie = Trie<Character, Int>() | |
var routesTrie = Trie<Int, Route>() | |
var nextComponentId = 1 | |
init(routes: [Route]) { | |
for route in routes { |
This file contains hidden or 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
// Add <https://github.com/samhann/Every.swift/blob/master/NSDateComponentsExtensions.swift> here | |
import Foundation | |
import XCPlayground | |
struct Every { | |
class Executor: NSObject { | |
let closure: NSTimer -> Void | |
var timer: NSTimer! | |
init(closure: NSTimer -> Void) { self.closure = closure } |
This file contains hidden or 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
struct Request {} | |
struct Response {} | |
enum MiddlewareBeforeResult { | |
case Next(Request) | |
case Respond(Response) | |
} | |
typealias MiddlewareBefore = Request -> MiddlewareBeforeResult | |
typealias MiddlewareAfter = (Request, Response) -> Response |
This file contains hidden or 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
struct Task<Input, Output> { | |
typealias TaskExecutor = Input -> Output | |
let task: TaskExecutor? | |
var subTasks = [Task<Any,Any>]() | |
init(task: TaskExecutor? = nil) { | |
self.task = task | |
} |
This file contains hidden or 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
enum ReturnType<T> { | |
case Normal(T) | |
case Early(T) | |
} | |
extension SequenceType { | |
func rreduce<T>(initial: T, combine: (T, Self.Generator.Element) -> ReturnType<T>) -> T { | |
var result = initial | |
for el in self { | |
switch combine(result, el) { |
This file contains hidden or 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
// | |
// GameViewController.swift | |
// WordMatch | |
// | |
// Created by Dan Appel on 12/17/15. | |
// Copyright (c) 2015 Dan Appel. All rights reserved. | |
// | |
import UIKit | |
import QuartzCore |