Skip to content

Instantly share code, notes, and snippets.

//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
import Darwin.C
import Venice
struct SubProcess {
let path: String
let arguments: [String]
func run(sync sync: Bool = true) -> Int? {
@Danappelxx
Danappelxx / brainfuck.swift
Created March 15, 2016 17:09
A simple recursive Brainfuck parser & interpreter (`,` not supported).
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 {
@Danappelxx
Danappelxx / hungarian.swift
Last active May 13, 2016 09:28
A simple expression interpreter which parses tokens, arranges them into Hungarian Notation, and finally evaluates them.
// For evaluation purposes
indirect enum Token: CustomStringConvertible {
case Value(Int)
case Add(Token, Token)
case Subtract(Token, Token)
case Multiply(Token, Token)
case Divide(Token, Token)
var description: String {
switch self {
let length = 10
let ptr = UnsafeMutablePointer<UInt8>(allocatingCapacity: length)
defer { ptr.deallocateCapacity(length) }
for i in 0..<length {
ptr.advanced(by: i).pointee = UInt8(i)
}
let buffer = UnsafeMutableBufferPointer(start: ptr, count: length)
protocol Event {}
protocol ErasedListener {
func dispatchIfMatches(event: Event)
}
struct Listener<T: Event>: ErasedListener {
let dispatch: T -> Void
func dispatchIfMatches(event: Event) {
(event as? T).flatMap(dispatch)
enum Heap<Key: Comparable> {
case empty(key: Key)
indirect case halfFull(key: Key, left: Heap<Key>)
indirect case full(key: Key, left: Heap<Key>, right: Heap<Key>)
}
extension Heap {
var isFull: Bool {
if case .full(key: _, left: _, right: _) = self {
return true

Extensible Enums

Introduction

This proposal introduces a new keyword that can be applied to enums which allows new cases to be introduced in extensions.

notifications:
slack: zewo:VjyVCCQvTOw9yrbzQysZezD1
os:
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode8
install:
@Danappelxx
Danappelxx / simple-sql.swift
Created July 2, 2016 06:02
An exercise to execute basic SQL queries (skipped parsing)
indirect enum Query {
case equal(field: String, value: String)
case notEqual(field: String, value: String)
case not(query: Query)
case or(first: Query, second: Query)
case and(first: Query, second: Query)
}
func &&(lhs: Query, rhs: Query) -> Query {