Skip to content

Instantly share code, notes, and snippets.

@raydog
raydog / simple_async_profile.js
Created August 4, 2014 19:03
Super-simple profiler for async operations
function _test(cb) {
var file_line = new Error().stack.split(/\n/g)[2].trim();
var start = Date.now();
return function () {
console.log("%d :: %s", (Date.now() - start)/1000, file_line);
cb.apply(null, arguments);
}
}
@raydog
raydog / udp_client.js
Created June 16, 2014 22:38
UDP experiment with Node.js
var dgram = require('dgram');
function Timer() {
this.st = Date.now();
}
Timer.prototype.poll = function poll(name) {
var now = Date.now();
console.log("%s :: %d", (name || "--"), (now - this.st));
this.st = now;
@raydog
raydog / walmarts per state.txt
Created June 11, 2014 18:32
List of Walmarts per state, along with census data from 2013 and People per walmart.
State WalMart Retail Units 2013 Population People / Walmart
ALABAMA 121 4833722 39948.116
ALASKA 13 735132 56548.615
ARIZONA 121 6626624 54765.488
ARKANSAS 107 2959373 27657.692
CALIFORNIA 282 38332521 135930.926
COLORADO 100 5268367 52683.670
CONNECTICUT 39 3596080 92207.179
DELAWARE 10 925749 92574.900
FLORIDA 317 19552860 61680.946
@raydog
raydog / bullshit.js
Last active October 19, 2023 22:27
Bullshit as a Service
var E_PREFIX_RATE = 0.25;
// All of our word lists:
var _word_lists = {
verb : [
"implement", "utilize", "integrate", "streamline", "optimize", "evolve", "transform", "embrace",
"enable", "orchestrate", "leverage", "reinvent", "aggregate", "architect", "enhance", "incentivize",
"morph", "empower", "envisioneer", "monetize", "harness", "facilitate", "seize", "disintermediate",
@raydog
raydog / linebuffer.c
Last active March 24, 2016 23:35
A simple utility to read a plain text file into a buffer, and safely iterate over it line-by-line.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "linebuffer.h"
#define LINE_BUFFER_LENGTH 1024
@raydog
raydog / resource.js
Created March 18, 2014 03:38
Very simple resource-based routing thing for the new Express
var urllib = require('url');
var VALID_PARAM = /^[a-z0-9_]+$/i;
var ACTIONS = [
{ name: "index", verb:"get", path: "" },
{ name: "new", verb:"get", path: "/new" },
{ name: "create", verb:"post", path: "" },
{ name: "show", verb:"get", path: "/:param" },
{ name: "edit", verb:"get", path: "/:param/edit" },
@raydog
raydog / cupcake.js
Created April 18, 2013 18:01
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;
@raydog
raydog / maze.js
Created February 25, 2013 09:42
A simple maze generation algorithm. Currently only has an inefficient variant of the Kruskal's maze algorithm coded, but it works, and new algorithms can be easily implemented. Can be required as a node.js module.
var Maze = (function () {
// Fisher-Yates shuffle:
function shuffle_list(l) {
for(var i=l.length-1; i>0; i--) {
var j = Math.floor(Math.random() * (i+1));
var temp = l[i];
l[i] = l[j];
l[j] = temp;
}