Skip to content

Instantly share code, notes, and snippets.

View kevincennis's full-sized avatar
💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
View GitHub Profile
@kevincennis
kevincennis / privacy.js
Created February 4, 2015 04:58
WeakMap privacy
var User = (function() {
var cache = new WeakMap();
function User( name ) {
cache.set( this, {} );
this.name = name;
}
User.prototype = {
@kevincennis
kevincennis / curry.js
Last active August 29, 2015 14:14
curry
Function.prototype.curry = function curry() {
var fn = this,
arity = fn.length,
slice = Array.prototype.slice,
args = slice.call( arguments );
function accumulator() {
var locArgs = args;
if ( arguments.length > 0 ) {
@kevincennis
kevincennis / index.js
Last active August 29, 2015 14:11
"Native" YAML `require()`
// needs to be required once per process to set up the hook
require('./yaml.js');
// now i can require a yml file. yay!
console.log( require('./test') );
@kevincennis
kevincennis / Class.js
Last active July 16, 2016 03:48
Class.js (Simple inheritance setup)
function construct() {
if ( this && typeof this.init === 'function' ) {
this.init.apply( this, arguments );
}
}
function extend( obj ) {
var proto = Object.create( this && this.prototype || {} ),
type = typeof obj,
key;
@kevincennis
kevincennis / music.js
Last active April 21, 2022 02:30
simple, lightweight sequencer in javascript with the web audio api
// For more documentation and a newer version,
// check out the full repo: https://github.com/kevincennis/TinyMusic
@kevincennis
kevincennis / y.js
Last active October 16, 2015 15:06
Y Combinator
// Y Combinator
// λf.(λg.f(λy.g g y))(λg.f(λy.g g y))
//
// derives the fixed-point of the input function
// such that Y( f ) and f( Y( f ) ) are computationally equivalent
function Y( f ) {
return (function( g ) {
return f(function( y ) {
@kevincennis
kevincennis / v8.md
Last active March 2, 2024 21:50
V8 Installation and d8 shell usage

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)
  • Install depot_tools
    • $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    • $ nano ~/.zshrc
    • Add path=('/path/to/depot_tools' $path)
@kevincennis
kevincennis / tmpl.js
Last active August 29, 2015 14:05
tmpl.js
// KEWL TEMPLATING LIBRARY
function tmpl( fn ) {
return function( data ) {
return fn( data );
};
}
// DEMO...
@kevincennis
kevincennis / buffertowav.js
Last active February 17, 2024 14:05
Buffer to WAV
// assuming a var named `buffer` exists and is an AudioBuffer instance
// start a new worker
// we can't use Recorder directly, since it doesn't support what we're trying to do
var worker = new Worker('recorderWorker.js');
// initialize the new worker
worker.postMessage({
command: 'init',
@kevincennis
kevincennis / mergebuffers.js
Last active August 29, 2015 13:56
Merge buffers
// assuming `rec1` and `rec2` are both instances of Recorder...
var buf1L, buf1R, buf2L, buf2R, worker, count = 0;
// start a new worker
// we can't use Recorder directly, since it doesn't support what we're trying to do
worker = new Worker('recorderWorker.js');
// initialize the new worker
worker.postMessage({