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 delay(delay:Double, closure:()->()) { | |
dispatch_after( | |
dispatch_time( | |
DISPATCH_TIME_NOW, | |
Int64(delay * Double(NSEC_PER_SEC)) | |
), | |
dispatch_get_main_queue(), closure) | |
} |
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 ObjectiveC | |
// Declare a global var to produce a unique address as the assoc object handle | |
var AssociatedObjectHandle: UInt8 = 0 | |
extension CCNode { | |
var previousX: CGFloat? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat | |
} |
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 UIKit | |
import ReactiveCocoa | |
struct AssociationKey { | |
static var hidden: UInt8 = 1 | |
static var alpha: UInt8 = 2 | |
static var text: UInt8 = 3 | |
} | |
// lazily creates a gettable associated property via the given factory |
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
<# type #> <# extendedType #> : ArrayLiteralConvertible { | |
required init(arrayLiteral elements: <# elementType #>...) { | |
self.<# storage #> = elements | |
} | |
} |
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
extension <# extendedType #> : CollectionType { | |
var startIndex: <# indexType : ForwardIndexType #> { return <# startIndex #> } | |
var endIndex: <# indexType : ForwardIndexType #> { return <# endIndex #> } | |
subscript (index: <# indexType : ForwardIndexType #>) -> <# elementType #> { | |
return <# subscript value #> | |
} | |
} |
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
extension <# extendedType #> : Hashable { | |
var hashValue: Int { return <# hashValue #> } | |
} | |
func ==(lhs: <# extendedType #>, rhs: <# extendedType #>) -> Bool { | |
return <# comparator #> | |
} |
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
extension <# extendedType #> : SequenceType { | |
func generate() -> <# generatorType #><<# elementType #>> { | |
<# generator state #> | |
return anyGenerator { | |
if <# terminal condition #> { | |
return nil | |
} | |
<# iteration logic #> |
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/Foundation.h> | |
@interface KeyValueObserver : NSObject | |
@property (nonatomic, weak) id target; | |
@property (nonatomic) SEL selector; | |
/// Create a Key-Value Observing helper object. |
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 "KeyValueObserver.h" | |
@interface KeyValueObserver () | |
@property (nonatomic, weak) id observedObject; | |
@property (nonatomic, copy) NSString* keyPath; | |
@end | |
@implementation KeyValueObserver | |
- (id)initWithObject:(id)object keyPath:(NSString*)keyPath target:(id)target selector:(SEL)selector options:(NSKeyValueObservingOptions)options; |
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 | |
// MARK: Standard Input | |
/// Reads a line from standard input | |
///:returns: string form stdin | |
public func getLine() -> String { | |
var buf = String() | |
var c = getchar() | |
// 10 is ascii code for newline |
OlderNewer