Skip to content

Instantly share code, notes, and snippets.

View nick-thompson's full-sized avatar

Nick Thompson nick-thompson

View GitHub Profile
@nick-thompson
nick-thompson / gist:3971849
Created October 29, 2012 06:04
Audio buffer processing functions
# Returns a reversed copy of the supplied sample buffer
reverse = (buffer) ->
data = buffer.getChannelData 0
ret = audioContext.createBuffer 1, data.length, 44100
retData = ret.getChannelData 0
i = 0
j = data.length
retData[i++] = data[j] while j--
ret
@nick-thompson
nick-thompson / Midikeys.js
Created November 1, 2012 18:22
A simple script that mocks midi commands on keyboard input, compatible with the Web MIDI API.
/*
* Midikeys.js
* > Turn your keyboard into a midi keyboard, compatible with the Web MIDI API.
* Copyright 2012 Nick Thompson
* MIT License
* https://gist.github.com/3995530
*/
(function (window, document, undefined) {
// Keycode to MIDI note values
@nick-thompson
nick-thompson / Monokai.terminal
Created December 6, 2012 19:48
Monokai theme for Terminal.app on OS X Lion.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OViRjbGFzc1xOU0NvbG9yU3BhY2VVTlNSR0KAAhAC
TxAnMC4xNTI5NDExODIzIDAuMTU2ODYyNzUwNiAwLjEzMzMzMzM0MDMA0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
@nick-thompson
nick-thompson / ScriptProcessorLoad.js
Last active December 10, 2015 19:19
Testing the load on the browser using many ScriptProcessor nodes. Chrome Canary v26.0.1367.0 suggests that around 15 ScriptProcessor nodes performing simple functions is enough to noticeably disrupt the audio output.
var context = new webkitAudioContext()
, source = context.createOscillator()
, through = context.createScriptProcessor(1024, 1, 1)
, count = 0;
// The most basic of ScriptProcessing functions, copying the input buffer
// directly into the output buffer.
through.onaudioprocess = function (e) {
var input = e.inputBuffer.getChannelData(0)
, output = e.outputBuffer.getChannelData(0);
@nick-thompson
nick-thompson / Metronome.js
Created January 16, 2013 21:25
A reliable metronome library using HTML5 Web Workers to maintain the tick interval even when the parent thread is run in the background. In early 2011, both Firefox and Chrome clamped the minimum wait time for setTimeout and setInterval to one second when running in a tab that is not the active tab for its window.
/*!
* Metronome.js
*
* A reliable metronome using HTML5 Web Workers to maintain the tick
* interval even when the parent thread is run in the background.
*
* For details, see:
* http://pivotallabs.com/chrome-and-firefox-throttle-settimeout-setinterval-in-inactive-tabs/
*
/**
* A cool trick for making a transparent background image
* using only pseudo-elements.
*/
body:after {
content: "",
background: url(/path/to/your/sweet/image.png) no-repeat center center fixed;
background-size: cover;
@nick-thompson
nick-thompson / index.js
Created July 18, 2013 18:48
requirebin sketch
var context = new webkitAudioContext()
, node = context.createOscillator()
, Overdrive = require("wa-overdrive")
, overdrive = new Overdrive(context, {
preBand: 1.0,
color: 4000,
drive: 0.8,
postCut: 8000
});
bootstrap:
@curl -X POST -H 'Content-Type: application/json' -d @bootstrap.json \
https://nick-thompson.cloudant.com/_replicate
update:
@./scripts/update.js
// New version
async.parallel([
stores[BY_SEQ_STORE].put.bind(null, formatSeq(doc.metadata.seq, doc.data),
stores[DOC_STORE].put.bind(null, doc.metadata.id, doc.metadata)
], function(err) {
results.push(doc);
return saveUpdateSeq(callback2);
});
// Old version
@nick-thompson
nick-thompson / .block
Last active January 10, 2017 16:46 — forked from mbostock/.block
Point-Along-Path Interpolation
license: gpl-3.0