Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
View GitHub Profile
@kevincennis
kevincennis / gist:3762778
Created Sep 21, 2012
Block labels in JS
View gist:3762778
function isEven(val){
evaluate: { // Block label, not an object literal
if ( val % 2 == 0 ) break evaluate;
return false;
}
return true;
}
isEven(4) // true
isEven(7) // false
@kevincennis
kevincennis / gist:3928503
Created Oct 21, 2012
Instant karaoke track with the Web Audio API
View gist:3928503
var url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3'
, audio = new Audio(url)
, context = new webkitAudioContext()
// 512 samples per frame, stereo input, mono output
, processor = context.createJavaScriptNode(512, 2, 1)
, sourceNode
audio.addEventListener('canplaythrough', function(){
sourceNode = context.createMediaElementSource(audio)
sourceNode.connect(processor)
@kevincennis
kevincennis / gist:4186867
Created Dec 2, 2012
67 char fizzbuzz in JS
View gist:4186867
i=0;while(i++<100)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i)
@kevincennis
kevincennis / gist:4189099
Created Dec 2, 2012
66 char fizzbuzz in JS
View gist:4189099
for(i=0;i++<100;)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i)
View gist:4192135
var url = 'monoSound.wav'
, audio = new Audio(url)
, context = new webkitAudioContext()
, processor = context.createJavaScriptNode(512, 1, 1)
, sourceNode
audio.addEventListener('canplaythrough', function(){
sourceNode = context.createMediaElementSource(audio)
sourceNode.connect(processor)
processor.connect(context.destination)
View gist:4192424
var url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3'
, audio = new Audio(url)
, context = new webkitAudioContext()
, waveShaper = context.createWaveShaper()
, bassify = context.createBiquadFilter()
, sourceNode
audio.addEventListener('canplaythrough', function(){
sourceNode = context.createMediaElementSource(audio)
sourceNode.connect(waveShaper)
View gist:4196937
var arr = [1,2,3,4,5,6,7,8,9]
var sum = eval(arr.join('+'))
View img2table.js
function img2table( img ){
var canvas = document.createElement('canvas')
, ctx = canvas.getContext('2d')
, table = document.createElement('table')
, width = canvas.width = img.width
, height = canvas.height = img.height
, pixels
, i, j, l1, l2
, tr, td, r, g, b
View whitenoise.js
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()
View fizzbuzz.js
for(i=0;++i<100;)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)