<!-- template_file.html -->
<div>
<p class="title">{title}</p>
<span class="timestamp">{created_date}</span>
</div>
Post({
<!-- template_file.html -->
<div>
<p class="title">{title}</p>
<span class="timestamp">{created_date}</span>
</div>
Post({
| 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); | |
| }); |
| 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); |
| 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 |
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 |
| 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+'__' |
| 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+'__') |