Skip to content

Instantly share code, notes, and snippets.

@raydog
Created April 18, 2013 18:01
Show Gist options
  • Save raydog/5c1d328bd14759cd5e58 to your computer and use it in GitHub Desktop.
Save raydog/5c1d328bd14759cd5e58 to your computer and use it in GitHub Desktop.
node cupcake.js & ; curl localhost:3030/cupcake # RECV CUPCAKES
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