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 OrderedDictionary: DictionaryLiteralConvertible { | |
init(dictionaryLiteral elements: (Key, Value)...) { | |
for (key, value) in elements { | |
self[key] = value | |
} | |
} | |
} |
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 NSData { | |
var hex: String { | |
let pointer = UnsafePointer<UInt8>(self.bytes) | |
var hex = "" | |
for i in 0..<self.length { | |
hex += String(format: "%02x", pointer[i]) | |
} | |
return hex | |
} | |
} |
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
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
guard #available(iOS 9.0, *) else { | |
return | |
} | |
// MAX FORCE! | |
guard let maxForce = touches.maxElement({ $0.force < $1.force })?.force where maxForce > 3 else { | |
return | |
} | |
// Forceful touching is going on. | |
} |
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 UIKit | |
extension String { | |
var hexColor: UIColor? { | |
let hex = self.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet) | |
var int = UInt32() | |
guard NSScanner(string: hex).scanHexInt(&int) else { | |
return nil | |
} | |
let a, r, g, b: UInt32 |
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
function format(strings, ...values) { | |
const pieces = []; | |
for (let [index, string] of strings.entries()) { | |
let value = values[index]; | |
const formatIndex = string.lastIndexOf('$'); | |
if (formatIndex != -1) { | |
const format = string.substr(formatIndex + 1); | |
string = string.substr(0, formatIndex); | |
// TODO: Use an actual format engine here. |
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 | |
private class Invoker<EventData> { | |
weak var listener: AnyObject? | |
let closure: (EventData) -> Bool | |
init<Listener : AnyObject>(listener: Listener, method: (Listener) -> (EventData) -> Void) { | |
self.listener = listener | |
self.closure = { | |
[weak listener] (data: EventData) in |
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
// Update: See a solution here: | |
// https://gist.github.com/blixt/08434b74f0c043f83fcb | |
// (NSMapTable holds onto the weak keys longer than I expected) | |
import Foundation | |
private class ClosureWrapper<EventData> { | |
typealias EventHandler = (EventData) -> Void | |
let closure: EventHandler | |
init(_ closure: EventHandler) { |
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
struct OrderedDictionary<Key : Hashable, Value> { | |
typealias Element = (key: Key, value: Value) | |
private var dictionary = [Key: Value]() | |
private var orderedKeys = [Key]() | |
var count: Int { | |
return self.orderedKeys.count | |
} |
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 ListDiff<T : Hashable> { | |
typealias IndexList = [Int] | |
typealias FromIndexToIndexList = [(from: Int, to: Int)] | |
// A list of indexes of where items were added. | |
let added: IndexList | |
// A list of indexes where items that have disappeared used to be. | |
let deleted: IndexList | |
// A list of tuples of indexes representing the old and new indexes of items that moved. | |
let moved: FromIndexToIndexList |
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
#=============================================================================# | |
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown # | |
#=============================================================================# | |
rng_name | filename |rands/second| | |
file_input| dieharder.txt| 4.31e+06 | | |
#=============================================================================# | |
test_name |ntup| tsamples |psamples| p-value |Assessment | |
#=============================================================================# | |
diehard_birthdays| 0| 100| 100|0.15936729| PASSED | |
diehard_operm5| 0| 1000000| 100|0.95725635| PASSED |