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 | |
/// Timeout wrapps a callback deferral that may be cancelled. | |
/// | |
/// Usage: | |
/// Timeout(1.0) { println("1 second has passed.") } | |
/// | |
class Timeout: NSObject | |
{ | |
private var timer: NSTimer? |
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
package main | |
import "fmt" | |
func fab() (int, error) { | |
return 0, nil | |
} | |
func main() { | |
if i, err := fab(); err != 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
★°.. . ☾°☆ .*●¸. ★ °:. .•○°★ . * . . | |
° .●. °☾°☆ ¸.●. ★ ★°☾☆¸.¸ ★ :. .•○°★ . * . | |
. ¸. ° ¸.*●¸. °☾° ¸.●¸. ★ °:. .•° . * :. . ¸. | |
●¸ ★ ★☾°★. . °☆ .●¸. ★ °. •○°★ . | |
* . ☾° ¸.*●¸ °☾°☆ .*¸. ★ | |
★°.. . ☾°☆ .*●¸. ★ °:. .•○°★ . * . . ° . | |
●. °☾°☆ ¸.●. ★ ★°☾☆¸.¸ ★ :. .•○°★ . * . . | |
. ¸. ° ¸.*●¸. °☾° ¸.●¸. ★ °:. .•° | |
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
// Thanks http://www.swiftsoda.com/swift-coding/get-bytes-from-nsdata/ | |
func hexDump(data: NSData) -> String { | |
var len = data.length | |
var s = NSMutableString(capacity: len*2) | |
var byteArray = [UInt8](count: len, repeatedValue: 0x0) | |
data.getBytes(&byteArray, length:len) | |
for v in byteArray { | |
s.appendFormat("%02x", v) | |
} | |
return s |
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 Int { | |
/// Returns the digits of the number in the given base. | |
/// The array of digits is ordered from most to least significant. | |
func digits(base: Int = 10) -> [Int] { | |
if self < base { | |
return [self] | |
} | |
var n = self | |
var d: [Int] = [] |
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
class AtomicBoolean { | |
private var val: Byte = 0 | |
/// Sets the value, and returns the previous value. | |
/// The test/set is an atomic operation. | |
func testAndSet(value: Bool) -> Bool { | |
if value { | |
return OSAtomicTestAndSet(0, &val) | |
} else { |
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
/// RWSync provides methods for executing read/write blocks through the Grand Central Dispatch. | |
/// Multiple reads may execute concurrently, but a write will block all other executions in the queue. | |
class RWSync { | |
private let queue: dispatch_queue_t | |
/// Instantiates RWSync with a new concurrent queue. | |
init() { | |
let queueName = "rwsync.\(mach_absolute_time())" | |
self.queue = dispatch_queue_create(queueName, DISPATCH_QUEUE_CONCURRENT) |
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 { Handlebars } from 'ember'; | |
// Thanks for the inspiration: https://coderwall.com/p/ryo_3w | |
Handlebars.registerBoundHelper('pluralize', function(number, options) { | |
var phrase = options.hash.phrase || '{|s}'; | |
return phrase.replace(/\{(.*?)\|(.*?)\}/, function(match, singular, plural) { | |
return number == 1 ? singular : plural; | |
}); | |
}); |
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 Ember from 'ember'; | |
import DS from 'ember-data'; | |
/** | |
* Returns the model class name, dasherized, which can be used to find | |
* and create new models of the same type through the store. | |
*/ | |
export function getClassName(model) { | |
// typeKey introduced in Ember Data 1.0.0.beta.3 | |
var typeKey = model.constructor.typeKey; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>EmberJS demo</title> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/ember.js/1.5.1/ember.min.js"></script> |