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
| // uniq func for Swift 1.2 | |
| func uniq<C: ExtensibleCollectionType where C.Generator.Element: Hashable>(collection: C) -> C { | |
| var seen:Set<C.Generator.Element> = Set() | |
| return reduce(collection, C()) { result, item in | |
| if seen.contains(item) { | |
| return result | |
| } | |
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
| // Declared as a curried function | |
| func fizzBuzzWithOptions(opts:[(divisor: Int, str: String)]) (num: Int) -> String { | |
| let returnString = opts.reduce(String()) { acc, opt in | |
| num % opt.divisor == 0 ? acc + opt.str : acc | |
| } | |
| return returnString.isEmpty ? String(num) : returnString + "!" | |
| } | |
| // Can be called inline with one argument to map | |
| let array1 = [Int](1...100).map(fizzBuzzWithOptions([(3, "Fizz"), (5, "Buzz")])) |
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 FiberError < StandardError; end | |
| class Fiber | |
| attr_accessor :name | |
| def initialize &block | |
| raise ArgumentError, 'new Fiber requires a block' unless block_given? | |
| @block = block | |
| @yield_sem = Dispatch::Semaphore.new(0) | |
| @resume_sem = Dispatch::Semaphore.new(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
| framework 'Cocoa' | |
| framework 'avfoundation' | |
| class Santa | |
| t_url = NSURL.URLWithString("http://dl.dropbox.com/u/349788/mustache.png") | |
| t_source = CGImageSourceCreateWithURL t_url, nil | |
| @@tache = CGImageSourceCreateImageAtIndex t_source, 0, nil | |
| g_url = NSURL.URLWithString("http://dl.dropbox.com/u/349788/glasses.png") | |
| g_source = CGImageSourceCreateWithURL g_url, nil |
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
| framework 'Cocoa' | |
| framework 'avfoundation' | |
| class FaceDetectionDelegate | |
| attr_accessor :window | |
| def applicationDidFinishLaunching(aNotification) | |
| width = 640 | |
| height = 480 | |
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
| framework 'Cocoa' | |
| class FaceDetectionDelegate | |
| attr_accessor :window | |
| def initWithURL(url) | |
| case url | |
| when String | |
| @photo_url = NSURL.URLWithString(url) | |
| when NSURL |
NewerOlder