Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vidoss
vidoss / gist:2178987
Created March 24, 2012 06:20
Using underscore.js while scripting mongodb shell.
MongoDB provides a Javascript shell. But Javascript is no fun without underscore.js
Turned out its straight forward to use underscore.js while scripting mongodb.
Here are the steps.
1) Use underscore to write your db script file (say my_commands.js)
E.g: _.each(db.dbname.find().toArray(), function(itm) { ... })
@vidoss
vidoss / gist:3354438
Created August 15, 2012 01:04
Backbone for server rendered markup!
This Gist is for the case where your html is generated on the server side, but you still want to use Backbone to manage
the incremental user actions. The idea is to parse the already rendered DOM and create the model / collection on the
first time, hence we can still follow the Backbone pattern to update models and the bindings reflect view and update server etc.
Lets do step by step for the infamous TODO application:
Step 1) Add a function dom2coll() to the AppView that will parse the rendered DOM and convert to data.
dom2coll: function() {
// To update model/view from already rendered DOM from backend.