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 / whitenoise.js
Created February 28, 2013 02:34
White noise
var sr = 48e3
, sec = 5
, len = sr * sec
, ctx = new webkitAudioContext()
, arr = new Float32Array(len)
, buf = ctx.createBuffer(1, len, sr)
, src = ctx.createBufferSource()
, i = 0
for ( ; i < len; ++i ) arr[i] = Math.random()
@kevincennis
kevincennis / fizzbuzz.js
Created March 16, 2013 05:27
64 char fizzbuzz
for(i=0;++i<100;)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)
@kevincennis
kevincennis / 25.js
Created March 24, 2013 00:23
Euler 25
function fibonacci( n ){
var val = '1', last = '0', tmp, i = 1
for ( ; val.length < n; ++i ){
tmp = val
val = add(last, val)
last = tmp
}
return i
}
@kevincennis
kevincennis / 21.js
Last active December 15, 2015 08:19
Euler 21
var max = 1e4, obj = {}, val = t = i = 0
function sum( n ) {
for ( var m = Math.sqrt(n), v = 1, i = 2; i <= m; ++i )
!(n % i) && (v += i) && i != m && (v += n / i)
return n ? v : 0
}
for ( ; i < max; ++i )
if ( !obj[i] && (t = sum(i)) != i && sum(t) == i )
@kevincennis
kevincennis / obvious.js
Created March 26, 2013 02:34
Find the sum of all primes under 2,000,000 that contain a 7 or 9
var i, l, max = 2e6, primes = [], val = 0
function isPrime( n ) {
var i = 2
if ( n < 2 ) return false
if ( n == 2 ) return true
for ( ; i < n; ++i )
if ( n % i === 0 )
return false
return true
@kevincennis
kevincennis / linspace.js
Last active December 15, 2015 12:29
spacing
// return an array containing (len) linearly-spaced values from (min) to (max)
function linspace(from, to, len){
var arr = new Array(len)
, step = ( to - from ) / ( len - 1 )
, i = 0
for ( ; i < len; ++i )
arr[i] = from + ( i * step )
return arr
}
// populate
$('.sections').each(function(){
var min = $(this).offset().top
, height = $(this).outerHeight();
offsets.push({min: min, max: min + height});
});
// turns into this...
var offsets = [
{min: 300, max: 600},
// audioContext == webkitAudioContext
// bufferSource == AudioBufferSourceNode
var tremolo = new Tremolo(audioContext)
bufferSource.connect(tremolo.input)
tremolo.connect(audioContext.destination)
tremolo.depth = 0.5
tremolo.frequency = 7
@kevincennis
kevincennis / fx.md
Last active December 17, 2015 14:29
FX

#effect params

Quick and dirty overview of what things are and how you can change them


##tremolo periodic modulation of gain.

example: opening guitar riff here

var global = (function(){
return (function(){
return this.constructor.prototype;
}());
}());