Skip to content

Instantly share code, notes, and snippets.

var request = require('request'),
fs = require('fs');
var writeStream = fs.createWriteStream('bz2.bz2');
request({
url: 'http://planet.openstreetmap.org/changesets-120801.osm.bz2',
proxy: process.env.HTTP_PROXY
}, function() {}).pipe(writeStream);
@TooTallNate
TooTallNate / gyp-clean-configure-build.js
Created August 13, 2012 19:29
Using node-gyp programmatically. This could be made better...
var Gyp = require('node-gyp')
var gyp = Gyp()
gyp.parseArgv([])
// run "clean", "configure", then "build"
gyp.commands.clean([], function (err) {
console.error('clean', arguments);
mitsuhiko at atherton in ~ exited 2 on git:master? workon fireteam-sandbox
$ python -mtimeit -s 'from marshal import dumps, loads; x = [[1, 2, 3], [4, 5, 6]]' 'loads(dumps(x))'
1000000 loops, best of 3: 1.16 usec per loop
mitsuhiko at atherton in ~ on git:master? workon fireteam-sandbox
$ python -mtimeit -s 'from copy import deepcopy; x = [[1, 2, 3], [4, 5, 6]]' 'deepcopy(x)'
10000 loops, best of 3: 20 usec per loop
@tmcw
tmcw / archive_gists.py
Created August 1, 2012 17:34
Archive Gists
import requests, os, glob, json, codecs
# requires requests. pip install requests
you = 'tmcw'
data = 'gists'
try: os.mkdir(data)
except Exception: pass
@mraleph
mraleph / gist:3104414
Created July 13, 2012 11:29
stupid GC stressing code
// To make the benchmark results predictable, we replace Math.random
// with a 100% deterministic alternative.
Math.random = (function() {
var seed = 49734321;
return function() {
// Robert Jenkins' 32 bit integer hash function.
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
@jedisct1
jedisct1 / latency.txt
Created July 8, 2012 04:18 — forked from h2oai/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD 150,000 ns 0.15 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
@ajashton
ajashton / gist:3043796
Created July 3, 2012 22:23
Drop shadows in Carto
#countries {
::shadow1, ::shadow2, ::shadow3 {
line-color: #024;
line-join: round;
}
::shadow1 {
line-opacity: 0.03;
line-width: 7;
}
::shadow2 {
@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'),
@zhm
zhm / osmstats.sh
Created June 25, 2012 02:15
osmstats
OSMUSER="coleman"; curl -s "www.overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%3B%28node%28user%3A%22$OSMUSER%22%29%3Bway%28user%3A%22$OSMUSER%22%29%3Brelation%28user%3A%22$OSMUSER%22%29%3B%29%3Bout%3B" | ruby -e "require 'json'; osm = JSON.parse(STDIN.read); nodes = osm['elements'].select {|e| e['type'] == 'node'}; ways = osm['elements'].select {|e| e['type'] == 'way'}; relations = osm['elements'].select {|e| e['type'] == 'relation'}; puts ''; puts 'stats for $OSMUSER:'; puts 'nodes: ' + nodes.count.to_s; puts 'ways: ' + ways.count.to_s; puts 'relations: ' + relations.count.to_s; puts ''"
var net = require('net');
var serverConnections = 0;
var clientConnections = 0;
// Server: accept connections and set keep-alive
net.createServer(function(socket) {
socket.setKeepAlive(true, 0); // <-----
serverConnections++;
console.log(serverConnections);