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
# | |
# A CORS (Cross-Origin Resouce Sharing) config for nginx | |
# | |
# == Purpose | |
# | |
# This nginx configuration enables CORS requests in the following way: | |
# - enables CORS just for origins on a whitelist specified by a regular expression | |
# - CORS preflight request (OPTIONS) are responded immediately | |
# - Access-Control-Allow-Credentials=true for GET and POST requests |
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
// | |
// UIImageView+ALGDataTask.h | |
// VideoClient | |
// | |
// Created by Alexis Gallagher on 2014-01-18. | |
// Copyright (c) 2014 Bloom Filter. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
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 gist illustrates how Swift's "immutable" arrays are actually | |
mutable, and why that is sad. Load it into a playground to experiment. | |
"let"-defining an array should produce a truly immutable value. Instead, it | |
now produces a constant reference to a mutable, fixed-size array. This is like | |
C. So it is no better than C. And it's worse than Objective-C, where you | |
could produce a reliably constant array with code like: |
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
// | |
// Set | |
// | |
struct MySet<KeyType : Hashable> : Sequence | |
{ | |
var dictionaryOfItems = Dictionary<KeyType,Bool>() | |
init() {} | |
init(array:Array<KeyType>) { |
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
class Bag<T: Hashable>: Sequence, Printable { | |
var _storage = Dictionary<T, Int>() | |
typealias GeneratorType = Dictionary<T,Int>.GeneratorType | |
func addItem(item: T) { | |
if let count = _storage[item] { | |
_storage[item] = count + 1 | |
} else { | |
_storage[item] = 1 | |
} |
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 Foundation | |
// Swift 2.0 | |
// poor man's parsers for (TSV) tab-separated value files | |
// for something more full-featured, the best avenue is CHCSVParser | |
/** | |
Reads a multiline, tab-separated String and returns an Array<NSictionary>, taking column names from the first line or an explicit parameter | |
*/ |
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
func groupBy<T>(equivalent:(a:T,b:T)->Bool, items:[T]) -> [[T]] { | |
var lastItem:T? = nil | |
var groups:[[T]] = [] | |
var currentGroup:[T] = [] | |
for item in items { | |
if lastItem == nil { | |
// first item | |
currentGroup.append(item) | |
} | |
else { |
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 Foundation | |
import ImageIO | |
// | |
// before | |
// | |
func datesFromImagesInDir(dir: String) -> [NSDate] { | |
let fm = NSFileManager.defaultManager() |
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
class Box<T> { | |
let unbox:T | |
init(unbox:T) { self.unbox = unbox } | |
} | |
/* | |
Boxing is necessary because Swift does not allow recursive enum types. | |
However, AFAICT, is it also desirable here because it enables structural |
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
/* | |
The examples below show two ways to model a state machine with two states, | |
On and Off, with an additional constant Int property. | |
On -> Off and Off -> On transitions must be inititated by calling flip() | |
*/ | |
OlderNewer