Skip to content

Instantly share code, notes, and snippets.

View ritch's full-sized avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
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);
@ritch
ritch / gist:1014074
Created June 8, 2011 09:15
Hello Hive
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) {
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) {
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});
(function(original) {
original = original || function(o) {
var f = function() {
// body...
};
f.prototype = o;
return new f();
}
Object.create = function(obj) {
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 August 8, 2011 14:40
Last argument is a callback
// 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 August 30, 2011 16:09
Simple jQuery method dependency loader
// 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 September 13, 2011 06:32
Async via EventEmitter
// 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 October 14, 2011 02:58
Scriptable Markup

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');