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
| func undefined<A>() -> A { return (nil as A?)! } |
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 | |
| class TouchToEndEditView: UIView { | |
| private var keyboardRect: CGRect? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| setUp() | |
| } |
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
| ('A' to 'F').foldLeft(Seq(Seq[Char]())) { (a, c) => a :+ (a.last :+ c)}.tail.foreach { a => | |
| val `A,` = a.mkString(", ") | |
| val `->` = a.mkString(" -> ") | |
| println(s""" | |
| func curried<${`A,`}, Z>(fn: (${`A,`}) -> Z) -> (${`->`} -> Z) { | |
| return ${ a.foldRight(s"fn(${`A,`})") { (c, a) => s"{ $c in $a }" }.toLowerCase } | |
| } | |
| """) | |
| } |
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
| def HMAC_SHA1(key: Array[Byte], text: Array[Byte]): Array[Byte] = { | |
| val mac = Mac.getInstance("HmacSHA1") | |
| mac.init(new SecretKeySpec(key, "RAW")) | |
| mac.doFinal(text) | |
| } | |
| def hton64(n: Long): Array[Byte] = | |
| (0 to 7) | |
| .map(i => (n >>> 8 * (7 - i)) & 0xff) | |
| .map(_.toByte) |
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
| var pc = new webkitRTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]}); | |
| pc.createDataChannel("hello"); | |
| pc.createOffer(function (desc){ | |
| pc.setLocalDescription(desc, function() { | |
| console.log(desc.sdp); | |
| }); | |
| }); | |
| /* | |
| v=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
| // This returns something like an ID of given type | |
| func unsafeGetTypeId(type: Any.Type) -> uintptr_t { | |
| return unsafeBitCast(type, uintptr_t.self) | |
| } | |
| func isOfType(value: Any, type: Any.Type) -> Bool { | |
| return unsafeGetTypeId(reflect(value).valueType) == unsafeGetTypeId(type) | |
| } | |
| let a: Any = "Hello" |
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 | |
| public class UDKey<T> { | |
| let key: String | |
| let map: BiMap<AnyObject, T> | |
| public init(_ key: String, _ map: BiMap<AnyObject, T>) { | |
| self.key = key | |
| self.map = map |
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
| :- op(200, xfy, <--). | |
| :- op(200, xfy, /^\). | |
| :- op(200, xfy, /^ ). | |
| :- op(200, xfy, ^\). | |
| tree_empty(zip(nil, [])). | |
| tree_lhs(zip(L, [step(lhs, V, R)|XS]), zip(node(V, L, R), XS)). | |
| tree_rhs(zip(R, [step(rhs, V, L)|XS]), zip(node(V, L, R), XS)). | |
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
| // Playground - noun: a place where people can play | |
| import UIKit | |
| class MyControl { | |
| private var closures: [(UIControlEvents, MyControl -> ())] = [] | |
| init() {} | |
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 Record { | |
| let time: NSDate | |
| let name: String | |
| } | |
| extension Array { | |
| func sortedGroupBy(isOrderedBefore: (T, T) -> Bool) -> [[T]] { | |
| let tmp = sorted(isOrderedBefore) | |
| var out = [[T]]() | |
| for (i, e) in enumerate(tmp) { |