Skip to content

Instantly share code, notes, and snippets.

@juliangruber
juliangruber / gist:3160726
Created July 22, 2012 19:06
Pubsub in Dart
class Pubsub {
Map channels;
Pubsub() {
channels = new Map();
}
subscribe(String channel, Function cb) {
if (channels[channel] == null) {
channels[channel] = new List<Function>();
@juliangruber
juliangruber / gist:3805393
Created September 29, 2012 23:08
nodejs.org dns problems
traceroute nodejs.org
traceroute to nodejs.org (199.59.166.108), 30 hops max, 60 byte packets
1 ip-173-236-216-1.dreamhost.com (173.236.216.1) 0.327 ms 0.319 ms 0.496 ms
2 ip-66-33-201-222.dreamhost.com (66.33.201.222) 0.229 ms 0.262 ms 0.242 ms
3 64.124.196.85 (64.124.196.85) 0.291 ms 0.447 ms 0.311 ms
4 xe-1-0-1.mpr1.lax12.us.above.net (64.125.30.10) 0.804 ms 0.846 ms 0.826 ms
5 TenGE13-2.br02.lax04.pccwbtn.net (206.223.123.93) 1.201 ms 1.169 ms 1.186 ms
@juliangruber
juliangruber / gist:3846423
Created October 6, 2012 22:51
Distributed Datastore

Distributed Datastore

Building a distributed database/api on an eventually consistent distribution mechanism like scuttlebutt.

Data model

There are users and (possibly anonymous) posts with permalinks that only take strings/buffers.

Think of information you...

var Contre = require('contre');
var http = require('http');
var contre = Contre({
from : __dirname + '/repos',
to : __dirname + '/static'
});
var contre = Contre({
repos : __dirname + '/repos',
@juliangruber
juliangruber / gist:3940097
Created October 23, 2012 17:02
node mem tests
/*
This generates 4Mio timeseries values and stores them in different data structures in memory, dependent on process.argv[2].
Test results on my laptop are included. Performance was not important here, only mem usage. The background: In mem node DB.
Results:
- 115mb : { 1 : 'd,12,1d,lo', ... }
- 150mb : { 1 : [12,34,56,78], ... }
@juliangruber
juliangruber / Usage.md
Created October 23, 2012 20:24
c++0x timing utility

Compile with -std=c++0x.

double duration = time([](){
  do_some_heavy_stuff();
})
var state = require('state')({
getLastUpdate : db.get.bind(db, 'lastUpdate'),
setLastUpdate : db.put.bind(db)
})
// 1) EE interface
// receive updates if not connected to master
state.on('update', function (update, ts) {
db.put(update.key, update.value)
})
var timeseries = require('timeseries')
var ts = timeseries('./db')
var s = ts.createStream()
s.pipe(net.connect(3000)).pipe(s)
// display chart with realtime updates!
ts('the-id').createRangeStream(start).pipe(listener)
@juliangruber
juliangruber / README.md
Created November 13, 2012 20:55
authoritee

authoritee

restepk my authoritee!

Add authoritative nodes to your net of scuttlebutt models.

Usage

In a game you might want to limit players' movements to no more than 1 length entity per second, to prevent cheating.

@juliangruber
juliangruber / _results.md
Created November 18, 2012 12:52
LevelUp Leveled comparison

Levelup Leveled comparison

This is only for speed, Levelup provides some nice streaming abstractions that Leveled doesn't have.

Every benchmarked operation has to deal with 120000 entries, 29 chars each. Times were averaged from 3 runs.

The 2nd benchmark's output includes the factor of which leveled is faster/slower.