Created
April 18, 2013 18:01
-
-
Save raydog/5c1d328bd14759cd5e58 to your computer and use it in GitHub Desktop.
node cupcake.js & ; curl localhost:3030/cupcake # RECV CUPCAKES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jinx = require('jinx'); | |
var DELIVERY = 1024; | |
var DELIVERIES = 60; | |
function choice(l) { return l[Math.floor(Math.random() * l.length)]; } | |
function cupcake() { return ["cC", "uU", "pP", "cC", "aA4", "kK", "eE3"].map(choice).join(""); } | |
jinx.get("^/cupcake$", function (req, res, next) { | |
var left = DELIVERIES; | |
(function cupcakeFactory() { | |
var out = []; | |
for(var i=0; i<DELIVERY; i++) { | |
out.push(cupcake()); | |
} | |
out = out.join(" ") + " "; | |
if (--left <= 0) { | |
res.end(out); | |
return; | |
} else { | |
res.write(out); | |
setTimeout(cupcakeFactory, 1000); | |
} | |
})(); | |
}); | |
jinx.listen(3030); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment