Skip to content

Instantly share code, notes, and snippets.

@bengourley
bengourley / cache.js
Created April 8, 2019 13:35
Solving the stampede/dog-piling problem in JS
// simple cache implementation provide a key that you're looking for and
// a function that will compute the value in case of a cache miss
async get (key, expensiveFn) {
let result = await storage.get(key)
if (result === undefined) {
result = await expensiveFn
await storage.save(result)
}
return result
}
//
// This program reads a sourcemap from stdin
// and replaces the "mappings" property with
// human readable content. It writes the output
// to stdout.
//
// 1. install the dependencies:
// npm i concat-stream vlq
//
// 2. optional: install jq for pretty printing json
<!DOCTYPE html>
<html>
<head>
<title>callee.arguments test</title>
</head>
<body>
<script src="https://rawgit.com/stacktracejs/stackframe/master/dist/stackframe.js"></script>
<script src="https://rawgit.com/stacktracejs/stack-generator/master/dist/stack-generator.js"></script>
<script>
@bengourley
bengourley / .tmux.conf
Last active October 29, 2015 12:23
The best tmux config in all of Bath https://cloudup.com/cgbt0eQzG7k
# Use 'C-a' as the prefix
unbind C-b
set-option -g prefix C-a
# Shell
set -g default-command /bin/zsh
set -g default-shell /bin/zsh
# I want to manage my own names with prefix-comma
set -g automatic-rename off
//
// ANYTIME DATE/TIME PICKER
// =============
//
//
// -- Essential styles --
// These styles are the bare minimum to have a working date/time picker.
// These are copied and converted to stylus from
// https://github.com/bengourley/anytime/blob/master/anytime.css
@bengourley
bengourley / index.js
Last active August 29, 2015 14:10
requirebin sketch
var moment = require('moment')
, View = require('ventnor')
, months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
, days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]
function DatePickerView() {
View.apply(this, arguments)
this.startYear = 1960
this.endYear = 2030
this.currentView = { month: 11, year: 2014 }
@bengourley
bengourley / dependencies.txt
Created May 7, 2014 16:54
List of dependencies from a recent Clock project
async
backbone
brfs
browjadify
browserify
bunyan
bytes
cf-api
cf-auth-middleware
cf-auth-provider
@bengourley
bengourley / index.js
Created April 23, 2014 15:38
requirebin sketch
var thesaurus = require('thesaurus')
var words = 'Short tutorial on how to write like Russell Brand:\n\n1. Write an article\n2. Replace every word with a synonym from thesaurus.com'.split(' ')
console.log(words.map(function (word) {
var synonyms = thesaurus(word)
if (!synonyms.length) return word
return synonyms[0]
}).join(' '))
/* global slate */
slate.config('defaultToCurrentScreen', true)
slate.config('windowHintsShowIcons', true)
slate.config('windowHintsIgnoreHiddenWindows', false)
var hint = slate.operation('hint')
slate.bind('esc:ctrl', hint)
var fullScreen = slate.operation('push', { direction: 'top', style: 'bar-resize:screenSizeY' })
@bengourley
bengourley / image.js
Last active December 15, 2015 10:19 — forked from serby/image.js
{ '2:3':
{ w: 2000
, h: 3000
, x1: 0
, y1: 0
, x2: 200
, y2 300
}
}