Skip to content

Instantly share code, notes, and snippets.

View Qard's full-sized avatar
👨‍💻
In an epic battle with my keyboard.

Stephen Belanger Qard

👨‍💻
In an epic battle with my keyboard.
View GitHub Profile
@Qard
Qard / ringo.md
Created November 22, 2013 05:13
Ringo - a self-healing, distributed storage engine built in Go, using a neighbor-coordinated ring network topology

Ringo

Ringo is a self-healing, distributed storage engine built in Go, using a neighbor-coordinated ring network topology. It is a simple key/value storage engine that more sophisticated database interfaces can layer on top of.

What is a neighbor-coordinated ring network topology?

You might be familiar with the typical ring network topology. This is a network structure where each node in a cluster has a connection to a left node and a right node. These connections form a ring.

The problem with a typical ring topology is that, if a link in the ring is broken, messages may not reach the destination. To get around this, some have created a reversible ring where any failure to send from one node to another will reverse the direction of the message and eventually it should reach the destination by looping back around the other side. This can result in terrible latency, but more importantly, it does not self-heal. If another link were to be broken, the cluster will be severed in two.

@Qard
Qard / qwry.js
Last active December 20, 2015 11:29
ActiveRecord-like query builder
var events = require('events');
var actions = [
'find'
, 'create'
, 'update'
, 'remove'
];
// These accept hashes to transform to key/val property pairs
#include "js_api.h"
// Sometimes you want to access the js "this" value in a function
// function Point(x, y) { this.x = x; this.y = y; }
bool point_constructor(js_context* C) {
js_set(C, 0, "x", 1); // this.x = arguments[0]
js_set(C, 0, "y", 2); // this.y = arguments[1]
return true; // js returns undefined, but C returns true meaning no error.
}
@Qard
Qard / gist:5711086
Created June 5, 2013 01:51
Gunzip buffers.
var JSONStream = require('JSONStream')
, zlib = require('zlib');
// With compression
var inputA = JSONStream.stringify()
, outputA = JSONStream.parse([true]);
inputA.pipe(zlib.createGzip()).pipe(zlib.createGunzip()).pipe(outputA);
outputA.on('data', function (data) {
@Qard
Qard / ab.rb
Created September 15, 2012 06:47
Formula to fix ab on OSX Lion
require 'formula'
class Ab < Formula
homepage 'http://httpd.apache.org/docs/trunk/programs/ab.html'
url 'http://www.apache.org/dist/httpd/httpd-2.4.3.tar.bz2'
sha1 '0ef1281bb758add937efe61c345287be2f27f662'
depends_on 'pcre'
def install
system './configure'
@Qard
Qard / index.js
Created April 1, 2012 13:39
Micro event dispatcher
function ev (m,e) {
m = this, e = []
m.on = function (a, b) { e.push([a,b]) }
m.emit = function (a) {
for (var i in e) e[i][0].test(a) && e[i][1].apply(m, [].slice.call(arguments, 1))
}
}
@Qard
Qard / backbone.behaviour.js
Created January 24, 2012 08:06
Behaviour abstraction system for backbone.js
!function (Backbone) {
// Store blank stuff here
var blankEl = $()
, blankModel = new Backbone.Model.extend()
, blankCollection = new Backbone.Collection.extend({
model: blankModel
})
, blankView = new Backbone.View.extend({
el: blankEl
})
@Qard
Qard / gist:1086780
Created July 16, 2011 20:55
Vennly.js rewrite
/**
* Some basic rewriting to connect the functions via prototype.
* It's faster that way as the functions are only addressed to memory once.
*
* Also stores the canvas and context as instance properties rather than passing them through everything.
* Again, it is faster that way.
*/
/**
*
@Qard
Qard / Chainer
Created April 9, 2011 23:47
Build callback chains without ridiculous indentation!
function chainer(){
var chain = [];
function add(callback) { chain.push(callback); }
function next() { if (chain.length) { chain[0](); chain.shift(); } }
return { add: add, push: add, run: next, start: next, next: next };
}
// Make a new chain.
var chain = new chainer();
@Qard
Qard / JSON.fstringify
Created April 9, 2011 10:36
JSON.stringify that retains functions. Simple, but handy.
JSON.fstringify = function(object) {
return JSON.stringify(object, function(key, value){
if (typeof value == 'function') {
return value.toString();
}
return value;
});
};