Skip to content

Instantly share code, notes, and snippets.

@benji6
benji6 / jingleBells.js
Created December 19, 2019 12:24
Jingle bells
const audioCtx = new AudioContext
const gain = audioCtx.createGain()
gain.connect(audioCtx.destination)
gain.gain.value = 0.2
const noteDuration = 0.2
const notes = [
[659.25, 1], [659.25, 1], [659.25, 2],
[659.25, 1], [659.25, 1], [659.25, 2],
[659.25, 1], [783.99, 1], [523.25, 1], [587.33, 1],
[659.25, 4],
@benji6
benji6 / computeHash.js
Created December 27, 2018 20:41
Compute cache busting hash
const crypto = require('crypto')
const computeHash = data =>
crypto
.createHash('md5')
.update(data)
.digest('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '')
@benji6
benji6 / .npmrc
Created December 25, 2018 16:15
.npmrc
init-license=MIT
init.author.name=Ben Hall
init.version=0.0.0
@benji6
benji6 / vs-code-settings.json
Last active May 12, 2020 13:18
VS Code Settings
{
"editor.minimap.enabled": false,
"editor.scrollBeyondLastLine": false,
"editor.tabSize": 2,
"editor.wordWrap": "on",
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"editor.accessibilitySupport": "off",
"editor.formatOnSave": true,
"extensions.ignoreRecommendations": false,
@benji6
benji6 / index.html
Last active July 27, 2020 09:50
index.html boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="theme-color" content="{{ themeColor }}">
<meta name="viewport" content="initial-scale=1, width=device-width">
<title>{{ title }}</title>
<script defer src="index.js"></script>
<link href="style.css" rel="stylesheet">
</head>
@benji6
benji6 / move2dPoints.html
Created June 16, 2017 13:04
wasm experiments
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WASM</title>
<style>
html {
height: 100%;
}
body {
@benji6
benji6 / lazyIterablesShowAndTell.js
Last active April 28, 2016 22:53
Lazy iterables in JS
// imlazy show and tell
// utils
const compose = (...fns) => x => fns.reduceRight((acc, f) => f(acc), x)
const log = (x, ...xs) => (console.log(...[x + ':', '\n', ...xs, '\n']))
// Generator expression
const oneTwoThreeGenerator = function * () {
yield 1
yield 2
// there's got to be a better name for this function
const analyze = (xForms, data) => Object.keys(xForms).reduce(
(acc, key) => Object.assign(acc, {[key]: xForms[key](data)}),
{}
)
// it allows application of multiple transformations to a single value
// and combines the results of those transformations into a single object
const rectangleSideLengths = [3, 4]
const area = ([a, b]) => a * b