Skip to content

Instantly share code, notes, and snippets.

@skratchdot
skratchdot / midi.json
Last active March 1, 2017 05:44
General Midi Info as a javascript/JSON array. Data From: http://en.wikipedia.org/wiki/General_MIDI#Program_change_events
[ { "val": 0, "name": "Acoustic Grand Piano", "group": "Piano"}
, { "val": 1, "name": "Bright Acoustic Piano", "group": "Piano"}
, { "val": 2, "name": "Electric Grand Piano", "group": "Piano"}
, { "val": 3, "name": "Honky-tonk Piano", "group": "Piano"}
, { "val": 4, "name": "Electric Piano 1", "group": "Piano"}
, { "val": 5, "name": "Electric Piano 2", "group": "Piano"}
, { "val": 6, "name": "Harpsichord", "group": "Piano"}
, { "val": 7, "name": "Clavinet", "group": "Piano"}
, { "val": 8, "name": "Celesta", "group": "Chromatic Percussion"}
@skratchdot
skratchdot / function-to-blob.js
Created September 23, 2013 22:40
Converts a javascript function to a blob. Doesn't perform browser support checks (it will error out in browsers that don't support Blobs).
var functionToBlob = function (fn) {
return new Blob([fn.toString()], {type: 'text/javascript'});
};
@skratchdot
skratchdot / function-to-url.js
Created September 23, 2013 22:42
Converts a javascript function to a blob url. Doesn't perform browser support checks (it will error out in browsers that don't support Blobs or window.URL.createObjectURL()).
/* you should eventually call window.URL.revokeObjectURL(result) on this result */
var functionToUrl = function (fn) {
return window.URL.createObjectURL(new Blob([fn.toString()], {type: 'text/javascript'}));
};
@skratchdot
skratchdot / mesh.sizeinfo.test.js
Created September 26, 2013 03:39
A test script for (mesh)[https://github.com/skratchdot/mesh] that shows that looping through all the documents in "mycollection" and summing Object.bsonsize(doc) values is not the same as what's reported in db.mycollection.stats()
/*global db, printjson */
(function () {
var numRecords = 1000, maxValue = 1000, i, keys = 'abcdefghijklmnopqrstuvwxyz'.split(''),
randomBetween, randomSubarray, generateObject,
resultStats, resultSizeInfo;
/* i was lazy: http://stackoverflow.com/questions/4959975/generate-random-value-between-two-numbers-in-javascript */
randomBetween = function (from, to) {
return Math.floor(Math.random()*(to-from+1)+from);
};
@skratchdot
skratchdot / getKeysByType.js
Created December 13, 2013 02:07
Get a map of types from an object in js
/* does not traverse input object, only reports top-level keys */
var getKeysByType = function (input) {
var key, item, type,
keys = {},
getType = function (obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1];
};
// loop through input, populating a hash of types
for (key in input) {
item = input[key];
@skratchdot
skratchdot / worker_snippet.js
Last active January 1, 2016 23:09
a very simple inline web worker that echos messages sent to it.
// create a worker that simply echoes messages sent to it
var worker = new Worker(window.URL.createObjectURL(new Blob(["self.addEventListener('message',function(e){self.postMessage(e.data);},false);"])));
// listen for messages from worker
worker.addEventListener('message', function (event) {
console.log('From Worker:');
console.dir(event);
}, false);
// post a test message
@skratchdot
skratchdot / coffeelint.md
Created March 24, 2014 22:11
Eclipse External Tools and Node Modules: coffeelint

In the external tools configuration, set the items included below:

coffeelint:

npm install -g coffeelint

external tools:

name:
@skratchdot
skratchdot / patatap.random.keys.js
Last active August 29, 2015 13:57
patatap.com random keys
/*
visit http://www.patatap.com/ then run this code in your
console. change the bpm and maxNotes variables
*/
(function (global) {
var bpm = 80,
maxNotes = 5,
interval = (60 * 1000) / bpm,
between = function (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
@skratchdot
skratchdot / react-seed.sh
Created June 18, 2014 00:05
React Seed Project (instead of using `git clone`)
curl https://codeload.github.com/fizerkhan/react-seed/tar.gz/master | tar xvz