Skip to content

Instantly share code, notes, and snippets.

View heapwolf's full-sized avatar
🕷️
Vault of the Black Spiders

heapwolf heapwolf

🕷️
Vault of the Black Spiders
View GitHub Profile
@heapwolf
heapwolf / index.js
Last active August 29, 2015 13:56
a transform stream
var stream = require('stream')
module.exports = function(opts) {
opts = opts || { objectMode: true }
return function(fn) {
var s = new stream.Transform(opts)
s._transform = function (chunk, encoding, done) {
@heapwolf
heapwolf / gist:9310937
Created March 2, 2014 18:11
tmux.colors.sh
#!/usr/bin/env bash
for i in $(seq 0 4 255); do
for j in $(seq $i $(expr $i + 3)); do
for k in $(seq 1 $(expr 3 - ${#j})); do
printf " "
done
printf "\x1b[48;5;${j}mcolour${j}\x1b[48;0;"
[[ $(expr $j % 4) != 3 ]] && printf " "
done
printf "\n"
@heapwolf
heapwolf / levelup.md
Last active August 29, 2015 13:57 — forked from dshaw/levelup.md

img

@heapwolf
heapwolf / cont-storage.js
Last active August 29, 2015 13:57
scope chain storage
function get(name) {
var c = arguments.callee.caller
while(c) {
if (c[name]) return c[name]
c = c.arguments.callee.caller
}
}
function set(name, value) {
var p = arguments.callee.caller
@heapwolf
heapwolf / thoughts.md
Last active August 29, 2015 14:01
normalize.github.io

thoughts on normalize for node.

The big questions users will have are

Q. How available will my source files be for development and for runtime?

A. normalize works like a browser. This value proposition should be the loudest on the site. Since people already understand how this works, it's a good mental gateway. The next thing people will ask is: "where are my files?". Since this is a radical departure from the existing workflow of downloading shit-tons of files and having even more copies of them everywhere, an explaination of how files get onto your disk and where they are kept would be great.

Q. What is the proxy and how does the proxy work?

var level = require('level')
var net = require('net')
var mts = require('monotonic-timestamp')
var multilevel = require('multilevel')
var db = level('./db', { valueEncoding: 'json' })
var cl = level('./cl', { valueEncoding: 'json' })
var put = db.put
db.put = function(key, value, options, cb) {
~/w/g/h/l/test (master) $ g++ -o bigdb ../deps/leveldb/libleveldb.a bigdb.cc -I../deps/leveldb/include/ -lpthread -std=gnu++11
~/w/g/h/l/test (master) $ rm -rf testdb/
~/w/g/h/l/test (master) $ time ./bigdb
524288 keys generated with 1024 bytes of random data in each value using 16 threads 2.99 real 3.19 user 2.87 sys
~/w/g/h/l/test (master) $ rm -rf testdb/
~/w/g/h/l/test (master) $ time ./bigdb
524288 keys generated with 1024 bytes of random data in each value using 16 threads 2.60 real 3.01 user 2.90 sys
~/w/g/h/l/test (master) $ time ./bigdb
524288 keys generated with 1024 bytes of random data in each value using 16 threads 3.36 real 3.39 user 3.06 sys
~/w/g/h/l/test (master) $ time ./bigdb
@heapwolf
heapwolf / bigdb.cc
Last active August 29, 2015 14:01
leveldb batches; nodejs vs c++
#include <iostream>
#include <iomanip>
#include <thread>
#include <string>
#include "leveldb/db.h"
#include "leveldb/write_batch.h"
using namespace std;
A man in a hot air balloon realized he was lost. He reduced altitude and
spotted a woman below. He descended a bit more and shouted, "Excuse me,
can you help me? I promised a friend I would meet him an hour ago, but I
don't know where I am."
The woman below replied, "You're in a hot air balloon hovering
approximately 30 feet above the ground. You're between 40 and 41 degrees
north latitude and between 59 and 60 degrees west longitude."
"You must be an engineer," said the balloonist. "I am," replied the woman,
@heapwolf
heapwolf / net.cc
Last active August 29, 2015 14:01
/*
* To compile
*
* smpl net.cc
*
*/
#include <net>
#include <through>