Skip to content

Instantly share code, notes, and snippets.

View creationix's full-sized avatar
💚
<3

Tim Caswell creationix

💚
<3
View GitHub Profile
-- The base object `Object`
local Object = {}
Object.meta = {__index = Object}
-- Create a new instance of this object
function Object:create()
local meta = rawget(self, "meta")
if not meta then error("Cannot inherit from instance object") end
return setmetatable({}, meta)
@creationix
creationix / chatServer.js
Created November 19, 2010 20:47
A simple TCP based chat server written in node.js
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
@creationix
creationix / server.js
Created June 26, 2012 15:11
meta server for sites on creationix.com server.
// Load some built-in modules
var HTTP = require('http'),
HTTPS = require('https'),
ChildProcess = require('child_process'),
QueryString = require('querystring'),
FS = require('fs');
// Load some npm community modules
var Stack = require('stack'),
Wheat = require('wheat'),
@creationix
creationix / node.conf
Created June 26, 2012 15:05
Upstart scripts for my various live sites
description "Run node server"
env PATH=/home/tim/nvm/v0.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
respawn
start on runlevel [23]
script
cd /home/tim/
exec node server.js > access.log 2>> error.log

I've come up with an interesting design for a hash map that instead of bucket lists, recursivly embeds more hash maps, but with a new key for each level.

Each hash map is super simple with two slots and hashe keys are 1 bit. However, the initial value is hashed to a 32-bit integer where each bit in the number is the key for each level in the recursive hash map.

In C, my structure looks like:

struct hash_tree_node {
  void *key;
 void *value;
/*
* Simple MD5 implementation
*
* Compile with: gcc -o md5 -O3 -lm md5.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
@creationix
creationix / shed.scad
Last active March 12, 2024 21:01
Shed design. Open in OpenScad to view 3d model.
windows = false; // show windows
stuff = false; // Show bikes, table, mower
l = 32; // Length of building in feet (16, 20, 24, 28, 32, ...)
h = 8*12-4.5+.5;
rl=6*12+1.375+.1; // cut to 73.5" long with 22.5 degree angles
tl = 68.7; // Used to tweak headers on top walls
// 2x6 concrete forms for foundation
// 10" wide grid
@creationix
creationix / path.js
Created November 12, 2013 18:10
Simple path join and dirname functions for generic javascript
// Joins path segments. Preserves initial "/" and resolves ".." and "."
// Does not support using ".." to go above/outside the root.
// This means that join("foo", "../../bar") will not resolve to "../bar"
function join(/* path segments */) {
// Split the inputs into a list of path commands.
var parts = [];
for (var i = 0, l = arguments.length; i < l; i++) {
parts = parts.concat(arguments[i].split("/"));
}
// Interpret the path commands to get the new resolved path.
@creationix
creationix / jsonparse.js
Last active December 11, 2023 15:37
A streaming JSON parser as an embeddable state machine.
// A streaming byte oriented JSON parser. Feed it a single byte at a time and
// it will emit complete objects as it comes across them. Whitespace within and
// between objects is ignored. This means it can parse newline delimited JSON.
function jsonMachine(emit, next) {
next = next || $value;
return $value;
function $value(byte) {
if (!byte) return;
if (byte === 0x09 || byte === 0x0a || byte === 0x0d || byte === 0x20) {
../bench/corgis/website/datasets/json/tate/tate.json (2.60 MiB)
Action Duration Used Kept Output
cjson_resty.decode 38.9ms 3.87 MiB 3.63 MiB table: 0x419b8440
Tibs.decode 42.1ms 2.95 MiB 2.91 MiB table: 0x4209dad8
cjson_resty.encode 13.2ms 1.88 MiB 1.88 MiB string: 1.88 MiB
Tibs.encode 48.3ms 8.24 MiB 1.97 MiB string: 1.84 MiB
encoded sizes mismatch: 1968571 1933719
cjson_resty = "data":{"url":"http:\/\/www.tate.org.uk\/