Skip to content

Instantly share code, notes, and snippets.

@dsugden
dsugden / FooRoute.scala
Created September 1, 2014 12:49
Spray Routes with API versioning
/**
* Foo restful interface.
*/
trait FooRoute extends HttpService with AskSupport {
import examples.FooProtocol._
import examples.FooProtocolV2._
implicit val timeout: Timeout
implicit val fooActorPath: ActorPath
@chriseidhof
chriseidhof / routes.swift
Created August 17, 2014 21:04
Type-safe routes in Swift
//
// main.swift
// Routes
//
// Created by Chris Eidhof on 17/08/14.
// Copyright (c) 2014 Chris Eidhof. All rights reserved.
//
import Foundation
@chriseidhof
chriseidhof / parsing.swift
Last active April 16, 2023 02:38
JSON Parsing in Swift
// This code accompanies a blog post: http://chris.eidhof.nl/posts/json-parsing-in-swift.html
//
// As of Beta5, the >>= operator is already defined, so I changed it to >>>=
import Foundation
let parsedJSON : [String:AnyObject] = [
"stat": "ok",
"blogs": [
@hooman
hooman / AssociatedObjects.swift
Last active May 4, 2022 07:33
Take 2.0: A completely new take on Objective-C associated types. (See history for the ancient approach)
// Playground - noun: a place where people can play
//
//
// By: Hooman Mehr ([email protected])
// Gist: https://gist.github.com/hooman/599e381d5f037b87d20b (The latest version is always here)
//
//
// Update: 07/30/2014
// Added WeaklyOwned & removeOrphans for memory management support, added more generics & basic access control.
// 08/06/2014
#import <Foundation/Foundation.h>
#define GENERIC(type, parameterType) __typeof__(type (^)(parameterType))
#define GENERIC_DERIVED_TYPE(genericObject) __typeof__(genericObject(NULL))
@interface MAList : NSObject
- (id)initWithArray: (NSArray *)array;
#!/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -i -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
import Foundation
class JSON {
struct Path: Printable {
enum Element {
case Index(Int)
case Key(String)
@berkus
berkus / memoize.swift
Last active April 2, 2017 19:19
A "fast" memoization generic in Swift
Promised speed:
0.1s https://dl.dropboxusercontent.com/s/bpgountdjrbs17n/2014-06-09%20at%2019.00.png
Actual speed:
575s https://dl.dropboxusercontent.com/s/2kbn5p1g4t03fvl/2014-06-09%20at%2019.00%20%281%29.png
With optimizations:
//
// ColorExtension.swift
//
// Created by Bastian Hoyer on 07.06.14.
// Copyright (c) 2014 Bastian Hoyer. All rights reserved.
//
import UIKit
func int2rgb(rgbValue: CUnsignedInt) -> (CGFloat, CGFloat, CGFloat) {
@plumhead
plumhead / gist:c4597bdda147073cf791
Created June 6, 2014 22:01
Hiding GCD behing Async
//
// Async.swift
// TestSwiftUI
//
// Created by Plumhead on 06/06/2014.
//
// There are many holes in this which will be ironed out over time - put up as a starting point for ideas
//
import Foundation
@mchambers
mchambers / reflect.swift
Last active March 5, 2021 09:20
Basic Reflection in Swift.
// Let's define a basic Swift class.
class Fruit {
var type=1
var name="Apple"
var delicious=true
}
// We can get at some info about an instance of an object using reflect(), which returns a Mirror.
reflect(Fruit()).count
reflect(Fruit())[1].0