Skip to content

Instantly share code, notes, and snippets.

@plugnburn
plugnburn / democode.js
Last active December 25, 2015 19:09
Some democode routines (will be updated from time to time)
//bytebeat: beat(pattern,length)
beat=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))}
//bytebeat with math: beatm(pattern,length)
beatm=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("with(Math)for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))}
//konamicode: konami(callback)
konami=function(k,c){onkeyup=function(e){/113302022928$/.test(c+=[e.which-37])&&k()}}
//circle gesture detection: circgest(callback[, clockwiseflag])
//clockwiseflag: 1 - counterclockwise, 0 or absent - clockwise
circgest=function(f,a,v,i,c,o){c=v="";addEventListener("mousemove",function(e){o&&(i=2*(e.screenX>o.screenX)+(e.screenY>o.screenY),i^c&&(v+=i,c=i),(a?/3201$/:/2310$/).test(v)&&(f(),v=""));o=e},0)}
@lancejpollard
lancejpollard / example.coffee
Created August 23, 2012 01:50
node.js domain module async error handling
(req, res, next) ->
# req and res are also created in the scope of serverDomain
# however, we'd prefer to have a separate domain for each request.
# create it first thing, and add req and res to it.
reqd = domain.create()
reqd.add(req)
reqd.add(res)
reqd.on "error", (er) ->
console.error "Error", er, req.url
try