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 jwt from 'jsonwebtoken' | |
import { certToPEM } from './utils' | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
async function latestKeys() { | |
console.log('Fetching latest') | |
const latest = await fetch( |
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
const numberRegexp = /^[0-9]+$/; | |
export type Validator<T> = (t: T) => boolean | |
export function validZip(s: string) { | |
return s.length === 5 && numberRegexp.test(s); | |
} | |
validZip("09809"); // true |
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
let numberRegexp = /^[0-9]+$/; | |
export interface Validator<T> { | |
isAcceptable(t: T): boolean; | |
} | |
export class ZipCodeValidator implements Validator<String> { | |
isAcceptable(s: string) { | |
return s.length === 5 && numberRegexp.test(s); | |
} |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
npm ls | gawk 'match($0, "[| +--`]*([^@]*).*", ary) { print ary[1] }' | sort | uniq |
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
angular.module 'ngScrollSupport', [] | |
.directive 'ngScrollSupport', -> | |
restrict: 'A' | |
link: (scope, element, attrs) -> | |
atTop = true | |
atBottom = false | |
check = -> | |
scrollTop = element.prop 'scrollTop' | |
scrollHeight = element.prop 'scrollHeight' | |
clientHeight = element.prop 'clientHeight' |
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
bower = (files, metalsmith, done) -> | |
include = (root, included) -> | |
for file in included | |
contents = readFileSync(file) | |
files["#{root}/#{basename(file)}"] = | |
contents: contents | |
include('css', lib.self().ext('css').files) | |
include('js', lib.self().ext('js').files) | |
include('fonts', lib.self().ext(['eot','otf','ttf','woff']).files) | |
done() |
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 Cocoa | |
enum Try<T>: Printable, DebugPrintable { | |
// Captures a successful outcome | |
case Success(@autoclosure() -> T) | |
// Captures a failure, including the root cause, which for now can be anything | |
case Failure(Any) | |
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 Traversable-alike abstraction of a traversable collection of tuples, without actually creating the tuples. | |
* I'd hope this would prevent me from polluting the heap with actual Tuple2 instances I never actually need. | |
*/ | |
trait Tuple2Traversable[+A, +B] { | |
def foreach[T](fn: (A, B) => T) | |
def map[T](fn: (A, B) => T): Traversable[T] = new Traversable[T] { | |
def foreach[U](f: (T) => U) { |
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 math._ | |
object Jaro { | |
def distance(first: String, second: String) = { | |
val maxLength = max(first.length, second.length) | |
val maxDistance = (maxLength / 2) - 1 | |
var matches = 0 | |
var halfTranspositions = 0 | |
for (i <- 0 until first.length) { |