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
map([ 'a', 'b', 'c' ], function( value ) {
return value.toUpperCase();
}); // [ 'A', 'B', 'C' ]
@kevincennis
kevincennis / gist:3762778
Created September 21, 2012 17:28
Block labels in JS
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:4186867
Created December 2, 2012 03:44
67 char fizzbuzz in JS
i=0;while(i++<100)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i)
@kevincennis
kevincennis / gist:4189099
Created December 2, 2012 14:43
66 char fizzbuzz in JS
for(i=0;i++<100;)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i)
@kevincennis
kevincennis / gist:4192135
Created December 3, 2012 02:04
invert polarity
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)
@kevincennis
kevincennis / gist:4192424
Created December 3, 2012 03:16
crush me maybe
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)
@kevincennis
kevincennis / gist:4196937
Created December 3, 2012 18:33
lazy sum
var arr = [1,2,3,4,5,6,7,8,9]
var sum = eval(arr.join('+'))
@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 / memoize.js
Created October 24, 2015 03:40
Generic Memoize
function memoize( fn ) {
const map = new Map();
const key = Symbol('key');
return function() {
let item = map;
let cached = false;
for ( let i = 0; i < arguments.length; ++i ) {
let cache = item.get( arguments[ i ] );
@kevincennis
kevincennis / img2table.js
Last active December 14, 2015 06:49
image2table
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