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
('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
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
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
// A trivial type just for this example | |
final class Id <A> { | |
let raw: A | |
init(_ a: A) { self.raw = a } | |
} | |
// A typeclass of the Monad | |
infix operator >>| { associativity left precedence 95 } | |
public protocol Monad { | |
typealias Elem |
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
#include <utility> | |
#include <tuple> | |
namespace { | |
using std::forward; | |
using std::move; | |
using std::tuple; | |
template<size_t H, size_t ...T> struct apply_by_tuple |
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
# http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects | |
.DS_Store | |
*.swp | |
*~.nib | |
DerivedData/ | |
build/ | |
xcuserdata | |
xcuserdata/**/* | |
*.pbxuser |
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
#include <iconv.h> | |
static NSString *decode(const char *encoding, char *src, size_t len, double capacityRatio=2) | |
{ | |
if (len == 0) { | |
return @""; | |
} | |
auto size = size_t(len * capacityRatio); | |
auto dest = (char*) malloc(size); | |
size_t pos = 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
#ifndef __sf_iOS_SFRLUCache_hpp_ | |
#define __sf_iOS_SFRLUCache_hpp_ | |
#include <unordered_map> | |
#include <utility> | |
namespace sf { | |
// http://twitter.github.io/commons/apidocs/com/twitter/common/util/caching/LRUCache.html | |
template<typename KeyT, typename ValT |
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
#ifndef __sf_iOS_SFSeq_hpp_ | |
#define __sf_iOS_SFSeq_hpp_ | |
#include <memory> | |
#include <vector> | |
#include <iostream> | |
namespace sf { | |
template<typename A> class SeqBuilder; |