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
| // (c) 2014 Nate Cook, licensed under the MIT license | |
| // | |
| // Fisher-Yates shuffle as top-level functions and array extension methods | |
| /// Shuffle the elements of `list`. | |
| func shuffle<C: MutableCollectionType where C.Index == Int>(inout list: C) { | |
| let c = count(list) | |
| for i in 0..<(c - 1) { | |
| let j = Int(arc4random_uniform(UInt32(c - i))) + i | |
| swap(&list[i], &list[j]) |
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
| public struct ZipOuter2<S1: SequenceType, S2: SequenceType>: SequenceType { | |
| private let _s1: S1 | |
| private let _s2: S2 | |
| init(_ s1: S1, _ s2: S2) { | |
| _s1 = s1 | |
| _s2 = s2 | |
| } | |
| public typealias Generator = GeneratorOf<(S1.Generator.Element?, S2.Generator.Element?)> |
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 NSTimer { | |
| /** | |
| Creates and schedules a one-time `NSTimer` instance. | |
| - Parameters: | |
| - delay: The delay before execution. | |
| - handler: A closure to execute after `delay`. | |
| - Returns: The newly-created `NSTimer` instance. | |
| */ |
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
| // Playground - noun: a place where people can play | |
| import UIKit | |
| // Setup the calendar object | |
| let calendar = NSCalendar.currentCalendar() | |
| // Set up date object | |
| let date = NSDate() |
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 unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? { | |
| switch (optional1, optional2) { | |
| case let (.Some(value1), .Some(value2)): | |
| return (value1, value2) | |
| default: | |
| return nil | |
| } | |
| } | |
| func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? { |
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
| [ | |
| { | |
| "timestamp": 0, | |
| "input": "W", | |
| "type": "search_local", | |
| "latency": 0 | |
| }, | |
| { | |
| "local_results": [ | |
| "ddg_search", |
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
| // | |
| // CollectionViewDataSource.swift | |
| // | |
| // Created by Bill Richards on 10/1/14. | |
| // Copyright (c) 2014 Bill Richards. All rights reserved. | |
| // | |
| import Foundation | |
| typealias CollectionViewCellConfigureBlock = (cell:UICollectionViewCell, item:AnyObject?) -> () |
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
| // Public domain. | |
| // Free to use. | |
| // Use like this: | |
| var world = "Hello, world!" | |
| let convertedRange = world.convertRange(0..<5) | |
| world.removeRange(convertedRange) | |
| // Converts a regular range (0..5) to a proper String.Index range. | |
| extension String { |
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
| // Playground - noun: a place where people can play | |
| import Foundation | |
| /** Protocol and extensions for integerFromBitsArray. Bit hakish for me, but I can't do it in any other way */ | |
| protocol Initiable { | |
| init(_ v: Int) | |
| init(_ v: UInt) | |
| } |
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 | |
| class Foo { | |
| let length = 255 | |
| // !!! not like this because self.length can't be used here | |
| // var arrayConstantLength = [Byte](count:self.length, repeatedValue:0) | |
| // but like this (with lazy I can use self.length constant) | |
| lazy var arrayConstantLength:[Byte] = { |