Skip to content

Instantly share code, notes, and snippets.

View wspringer's full-sized avatar

Wilfred Springer wspringer

View GitHub Profile
@wspringer
wspringer / bower.coffee
Created January 23, 2015 16:28
Bower support for Metalsmith
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()
@wspringer
wspringer / ng-scroll-support.coffee
Created October 28, 2015 08:07
Angular directive for tracking scroll events
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'
@wspringer
wspringer / grabs.sh
Last active March 14, 2016 09:14
List of all dependencies, ready to be processed by something else, like https://github.com/sindresorhus/package-json
npm ls | gawk 'match($0, "[| +--`]*([^@]*).*", ary) { print ary[1] }' | sort | uniq
@wspringer
wspringer / 0_reuse_code.js
Created March 14, 2016 09:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
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);
}
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
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(
@wspringer
wspringer / machine.js
Created December 13, 2019 14:06
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
let bottles = (number) => switch(number) {
| 0 => "no more bottles of beer"
| 1 => "1 bottle of beer"
| n => {
let formatted = string_of_int(n);
{j|$formatted bottles of beer|j};
}
}
let rec countdownFrom = (current) => current == 0 ? {
@wspringer
wspringer / machine.js
Last active March 29, 2020 14:15
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions