Skip to content

Instantly share code, notes, and snippets.

Avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
View gist:981203
hive
.at('/tweets')
//http://hello-world.dev/tweets/?limit=24
.find('/', hive.queries.tweets)
//http://hello-world.dev/tweets/:id
.find('/detail/:id', hive.models.tweet)
//http://hello-world.dev/tweets/new
.post('/new', hive.models.tweet)
//http://hello-world.dev/tweets/delete/:id
.delete('/delete/:id', hive.models.tweet);
View gist:1014074
var hive = require('hive');
var view = hive.view;
var redirect = hive.redirect;
var User = hive.models.User;
var Users = hive.queries.Users;
hive
.at('/user')
.get('/all', Users)
.post('/new', function(req, res) {
View gist:1015329
var hive = require('hive');
var view = hive.view;
var redirect = hive.redirect;
var Task = hive.models.Task;
var Tasks = hive.queries.Tasks;
hive
.at('/todo')
.find('/all', Tasks)
.get('/mine', function(req, res) {
View gist:1028427
var hive = require('hive');
exports = module.exports = hive.Model.extend({
_name: 'user',
activity: [],
following: [],
did: function(method, action, type, id) {
var activity = {type: type, at: new Date().getTime(), id: id};
activity[method] = action;
this.push({activity: activity});
View gist:1081024
(function(original) {
original = original || function(o) {
var f = function() {
// body...
};
f.prototype = o;
return new f();
}
Object.create = function(obj) {
View gist:1099788
var ex = [
{id: 1, name: 'blah'},
{id: 2, name: 'blah'},
{id: 3, name: 'blah'},
{id: 3, name: 'blah'},
{id: 3, name: 'blah'},
{id: 3, name: 'blah'},
{id: 4, name: 'blah'}
]
@ritch
ritch / gist:1131874
Created Aug 8, 2011
Last argument is a callback
View gist:1131874
// when the last arg is a function - call it.
function test() {
var args = arguments.length
, callback = args && arguments[args - 1]
, result = callback.call && callback.call();
console.log(result);
}
@ritch
ritch / example.js
Created Aug 30, 2011
Simple jQuery method dependency loader
View example.js
// simple script dependency delegation
// built specifically for backbone + jQuery
// loads scripts[] in parallel
var use = function(scripts, fn) {
var complete = 0,
total = scripts.length,
script;
function done() {
if(++complete === total && fn) fn();
}
@ritch
ritch / parallel.js
Created Sep 13, 2011
Async via EventEmitter
View parallel.js
// parallel
// 3 requests happen in parallel
var urls = ['google.com', 'yahoo.com']
, emitter = new EventEmitter()
, done = []
;
function increment(res) {
done.push(res);
if(done.length === urls.length) {
@ritch
ritch / rml.md
Created Oct 14, 2011
Scriptable Markup
View rml.md

I'm getting tired of writing documents to then parse and rebuild in JavaScript. HTML is not a markup language for complex interactive applications. rml is. Chekk-it.

// html
<img src="http://google.com/logo.png" />

Same thing in simple rml.

// rml
img('http://google.com/logo.png');
You can’t perform that action at this time.