Skip to content

Instantly share code, notes, and snippets.

var request = require('request')
, gunzip = require('zlib').createGunzip()
, json = new (require('jstream'))();
request('http://data.githubarchive.org/2012-03-11-12.json.gz')
.pipe(gunzip)
.pipe(json)
.on('data', function(obj) {
console.log(obj);
});
@polotek
polotek / readable_test.js
Created September 11, 2012 17:12
readable stream test
var readstream = require('fs').createReadStream('./data.json')
, buffer = []
, len = 0;
readstream.on('data', function(data) {
buffer.push(data);
len += data.length;
});
readstream.on('end', function() {
buffer = Buffer.concat(buffer, len);
@polotek
polotek / prototypes.js
Created August 9, 2012 21:33
A short explanation of prototypal inheritance.
function MyConstructor() {
this.foo = [ "foo" ];
}
MyConstructor.prototype.bar = [ "bar" ];
var obj = new MyConstructor();
obj.foo // The "foo" property is available directly on the object
obj.bar // The object has no "bar" property so it looks it up on the prototype
@polotek
polotek / backbone_plus_cs.md
Created July 29, 2012 18:07
Some thoughts on a small project with Backbone and CoffeeScript

I spent some time on a little scripting project yesterday and decided to use Backbone and CoffeeScript. I've been looking for a reason to use Backbone just to become more familiar. I don't really use CoffeeScript, and even went through my periods as a CS hater. But it's always a good idea to stay familiar with what's out there. At the very least it'll make sure you're not full of shit when you talk to people about pros and cons. Anyway, this isn't comprehensive or even useful per se. I just thought I'd jot down some thoughts.

I should make a disclaimer that this wasn't a traditional project for Backbone. It was a node script that only uses models a collections. I needed to perform a bunch of actions on a dataset by hitting a REST api. I've been thinking for a while that tasks like this are often nicer if you can mock up a quick model domain around the api. Then you can work with Forum and Topic models and just do update and delete operations on them. Once you set these up, the scripting tasks become much mor

{
// turn on to ENABLE warnings
"bitwise": false
, "curly": true
, "eqeqeq": false
, "forin": false
, "immed": true
, "latedef": false
, "newcap": true
, "noarg": true
@polotek
polotek / args-test.js
Created May 28, 2012 23:06
Testing @substack's shell-quote lib for parsing cli arg strings
var s = require('shell-quote');
console.log(s.parse('"foo = \"foo\""')); // [ 'foo', '=', 'foo' ]
// this is what I want
console.log(s.parse('"foo = \\"foo\\""')); // [ 'foo = "foo"' ]
// why does this also work? shouldn't it have slashes in it?
console.log(s.parse('"foo = \\\"foo\\\""')); // [ 'foo = "foo"' ]
diff --git a/couchie.js b/couchie.js
index 57e5f6e..b48effa 100644
--- a/couchie.js
+++ b/couchie.js
@@ -7,13 +7,15 @@
function Couchie (name) {
if (name.indexOf('__') !== -1) throw new Error('Cannot have double underscores in name')
this.name = name
- this.n = '_couchie__'+name+'__'
+ this._prefix = '_couchie__'+name+'__'
@polotek
polotek / test.jpg
Created May 28, 2012 06:52
Testing image embedding
test.jpg
diff --git a/couchie.js b/couchie.js
index 57e5f6e..4b66d50 100644
--- a/couchie.js
+++ b/couchie.js
@@ -7,13 +7,14 @@
function Couchie (name) {
if (name.indexOf('__') !== -1) throw new Error('Cannot have double underscores in name')
this.name = name
- this.n = '_couchie__'+name+'__'
+ this._storage = new Storage('_couchie__'+name+'__')
@polotek
polotek / .gitignore
Last active October 5, 2015 13:57
A little wrapper around localStorage that supports compound keys and non-string values
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover