Skip to content

Instantly share code, notes, and snippets.

View brycebaril's full-sized avatar

Bryce Baril brycebaril

View GitHub Profile
@brycebaril
brycebaril / hwm.js
Created October 29, 2013 05:31
Demonstrating how highWaterMark works with objectMode streams
var spigot = require("stream-spigot")
var through2 = require("through2")
var HWM = 10000
var limit = 40000
var count = 0
function gen() {
var record = (count++ < limit) ? {record: count} : null
this.push(record)
@brycebaril
brycebaril / protobuf.js
Created October 10, 2013 05:36
Run setup.js to create the file the other two use
var probuf = require("leveljs-coding/protobuf")
var fs = require("fs")
var concat = require("concat-stream")
var input = fs.createReadStream("buffs")
input.pipe(concat(function (buffer) {
var offset = 0
var blen = buffer.length
while (offset < blen) {
@brycebaril
brycebaril / README.md
Created September 7, 2013 04:38 — forked from rvagg/README.md

Work in progress, I'll write this up properly when I'm done.

Almost all credit goes to @maxogden for putting me on to this and pointing me in the right direction for each of these items.

Prerequisites:

  • Raspberry Pi
  • Kindle Paperwhite freed from its locked down state (jailbroken) http://www.mobileread.com/forums/showthread.php?t=198446
    • You have to downgrade your Kindle to 5.3.1 to install the current jailbreak; that's just a matter of getting the old version image, putting it on your Kindle via USB and telling it to install "upgrade". Then you put in the Jailbreak files, load the ebook and break.
  • Your kindle will be quick to detect an upgrade is available so it'll want to upgrade soon afterwards but the jailbreak will last but you have to reinstall the developer certificates so it's a bit of a pain but doable. Find all the instructions on the mobileread.com forums and wiki.
@brycebaril
brycebaril / align.js
Last active December 21, 2015 23:18
Zip two ordered time streams. A full version of this can be found here: https://github.com/brycebaril/node-sosj
module.exports = align
var Transform = require("stream").Transform
|| require("readable-stream/transform")
var inherits = require("util").inherits
var map = require("through2-map")
/**
* align takes two objectMode streams and a sequence key and will create a stream
* aligning records from each stream resulting in a stream that emits record doublets
@brycebaril
brycebaril / entry.js
Created August 9, 2013 00:27
eeevil! Ok, not too evil...
require("pipechain").install()
var spigot = require("stream-spigot") // or whatever you like to create streams
var s = spigot(["a", "b", "c", "\n"])
+s
require("./other.js")
// console will read abc
@brycebaril
brycebaril / through2_extension.js
Last active December 20, 2015 14:19
A Transform type constructor possible extension for through2
var Transform = require("stream").Transform
var inherits = require("util").inherits
module.exports.ctor = function ctor(fn) {
function T(options) {
if (!(this instanceof T)) return new T(options)
Transform.call(this, options)
}
inherits(T, Transform)
T.prototype._transform = fn
var lvlup = require("levelup")
var db = lvlup("/tmp/source_db")
var batch = 10000
function makeBatch(num) {
var b = []
for (var i = num; i < num + batch; i++) {
b.push({type: "put", key: "z~" + i, value: Math.random()})
fs.readFile('/proc/meminfo', 'utf8', function (err, str) {
var fields = {};
str.split('\n').forEach(function (line) {
var parts = line.split(':');
if (parts.length === 2) {
fields[parts[0]] = parts[1].trim().split(' ', 1)[0];
}
});
cb(fields['MemTotal'] + fields['Buffers'] + fields['Cached']);
> var redis = require("redis")
undefined
> var c = redis.createClient()
undefined
> c.blpop("Dispo", 0, console.log)
true
> null [ 'Dispo', 'foo' ]
var cluster = require('cluster');
var PORT = +process.env.PORT || 1337;
if (cluster.isMaster) {
// In real life, you'd probably use more than just 2 workers,
// and perhaps not put the master and worker in the same file.
cluster.fork();
cluster.fork();
cluster.on('disconnect', function(worker) {