Skip to content

Instantly share code, notes, and snippets.

View fritzy's full-sized avatar
💽
Please Insert Disk III

Nathan Fritz fritzy

💽
Please Insert Disk III
  • Kennewick, WA
  • 09:04 (UTC -07:00)
  • X @fritzy
View GitHub Profile
@fritzy
fritzy / jsonb_columns
Last active August 29, 2015 14:17
I've been playing around with JSON(B) columns in Postgres 9.4. I haven't found a great way to join from one value into another (without crazy JSON reconstruction), but this is close.
fritzy=# select * from authors;
id | value
----+--------------------------
1 | {"name": "Nathan Fritz"}
(1 row)
fritzy=# select * from books;
id | value
----+----------------------------------------------------
1 | {"title": "Ham, and Eating It", "author": 1}
@fritzy
fritzy / create_documentstore.sql
Last active August 29, 2015 14:05
Using Posgres as an Indexed Document Store
CREATE TABLE document_store (key CHAR(100) PRIMARY KEY, bucket CHAR(100), value JSON);
@fritzy
fritzy / postgres_doc_store.sql
Last active August 29, 2015 14:05
Postgres Document Store Functions (work in progress)
CREATE TABLE pgdown_default(key text, bucket text, value json, indexed json);
CREATE OR REPLACE FUNCTION pgdown_replace_row(tname TEXT, bucket TEXT, key TEXT, value TEXT, indexed JSON) RETURNS VOID AS
$$
BEGIN
LOOP
-- first try to update the key
EXECUTE 'UPDATE '
|| quote_ident(tname)
|| ' SET value = '
@fritzy
fritzy / writeableSave.js
Created July 2, 2014 04:37
Writeable stream for saving into Dulcimer.
var util = require('util');
var stream = require('stream');
function WriteData() {
stream.Writeable.call(this, {highWaterMark: 20, objectMode: true});
}
util.inherits(WriteData, stream.Writeable);
WriteData.prototype._write = function (obj, _, next) {
@fritzy
fritzy / levellog.js
Created July 1, 2014 05:07
An example of how to wrap levelup to add functionality. LevelLog writes to a log key every time you put.
var Exclusive = require('exclusive');
var uuid = require('node-uuid');
function LevelLog(db_, wrap_opts) {
function DB() { }
//assiging the parent db as the prototype
//makes anything not overridden accessable
DB.prototype = db_;
var db = new DB;
@fritzy
fritzy / pixi-skel.js
Last active August 29, 2015 14:02
A basic start to a pixi game.
function Game(somediv) {
this.stage = new PIXI.Stage(0xFFFFFF);
this.renderer = PIXI.autoDetectRenderer(800, 600);
somediv.appendChild(this.renderer.view);
this.lastframe = Date.now();
this.rocket = new Rocket(this);
this.update();
}
Game.protototype.update = function () {
#!/bin/bash
brew tap homebrew/nginx
brew install nginx
brew install lua-nginx-module
brew install go
brew install etcd
git clone git@github.com:fritzy/confd.git
cd confd
go get
@fritzy
fritzy / buffer_reversestring.js
Last active August 29, 2015 14:01
keep reverse sorted mapped indexes in addition to forward
function reverseString(sin) {
sin = new Buffer(sin);
for (var idx = 0, l = sin.length; idx < l; idx++) {
sin.writeUInt8(0xFF - sin.readUInt8(idx), idx);
}
return sin;
}
@fritzy
fritzy / riaklevelproxy.js
Last active August 29, 2015 14:01
Create a levelup multilevel server that proxies to a Riak bucket
var levelup = require('levelup');
var multilevel = require('multilevel');
var net = require('net');
var util = require('util');
var argv = require('optimist')
.default({host: 'localhost', port: 8087, listen: 8091})
.usage('Usage: level2riak --host 127.0.0.1 --port 8087 --listen 8091 --bucket somebucket'
+ '\n\nlevel2riak uses the riak protocol buffer and pb port (default: 8087)'
+ '\nConnect with a multilevel client.')
var levelup = require('levelup');
var db = levelup('riak://localhost:8087/somebucket', { db: require('riakdown'), valueEncoding: 'json'});
var multilevel = require('multilevel');
var net = require('net');
net.createServer(function (con) {
con.pipe(multilevel.server(db)).pipe(con);
}).listen(3000);