This file contains 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 result() -> A { | |
var result : A = dispatch_sync(resultQueue, { | |
return self.result | |
}) | |
return result | |
} | |
func dispatch_sync<R> (queue: dispatch_queue_t, block: Void -> R ) -> R { | |
var result: R! | |
dispatch_sync(queue) { |
This file contains 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 Swift | |
import Cocoa | |
// Properties you need as an enum - problem of key value coding is it allows you to type *anything*, typos compile fine. | |
enum SyncObjectPropertyName { | |
case Archived | |
case Title | |
} | |
// Protocol shared both for local and server |
This file contains 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 protocol CountableCollectionType: CollectionType { | |
var count: Int { get } | |
} | |
extension Array: CountableCollectionType {} | |
public protocol CollectionViewCellFactoryType { | |
typealias Item | |
typealias Cell: UICollectionViewCell | |
func cellForItem(item: Item, inCollectionView collectionView: UICollectionView, atIndexPath indexPath: NSIndexPath) -> Cell |
This file contains 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 | |
infix operator >>= { associativity left } | |
func >>=<A,B>(l: A?, r: A -> B?) -> B? { | |
if let x = l { | |
return r(x) | |
} | |
return nil |
This file contains 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
/* | |
* coalesce takes in a list of optional values | |
* and returns the first one that is not nil | |
*/ | |
func coalesce<T>(all: @autoclosure () -> T? ...) -> T? { | |
for f: () -> T? in all { | |
if let x = f() { return x } | |
} | |
return nil |
This file contains 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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "appscript" | |
include Appscript | |
oo = app("OmniOutliner Professional") | |
outline = oo.documents[1].get |
This file contains 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
protocol ValidatorType { | |
typealias ValidatedType | |
func isValid(object: ValidatedType) -> Bool | |
} | |
// You might want to make it a reference type, depending on your case. | |
struct AnyValidator<T>: ValidatorType { | |
private let validatorBlock: (T) -> Bool | |
init<V: ValidatorType where V.ValidatedType == T>(validator: V) { |
This file contains 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
clojure.core/mapcat | |
(All [c b ...] | |
[[b ... b -> (Option (Seqable c))] (Option (Seqable b)) ... b -> (Seq c)]) |
This file contains 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 Security | |
public class Keychain | |
{ | |
public class func set(key: String, value: String) -> Bool | |
{ | |
if let data = value.dataUsingEncoding(NSUTF8StringEncoding) | |
{ | |
return set(key, value: data) | |
} |
This file contains 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 | |
// Executes an array of blocks in parallel, but only returns after they're all done. | |
func parallel(blocks: [() -> ()]) { | |
let group = dispatch_group_create() | |
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
for block in blocks { | |
dispatch_group_async(group, queue, block) | |
} |
OlderNewer