Skip to content

Instantly share code, notes, and snippets.

@nodokodo
nodokodo / app.js
Created December 4, 2012 15:39 — forked from katanacrimson/app.js
nodejs app - expressjs 3.0 + socket.io v9 + passport + redis
var express = require('express'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
connect = require('connect'),
http = require('http'),
path = require('path'),
util = require('util'),
fs = require('fs'),
redis = require('redis'),
cookie = require('cookie'),
// Which do you prefer more?
// trigger event and get out
var vent = _.extend({}, Backbone.Events);
App.Router = Backbone.Router.extend({
routes: {
'show/:id': 'show'
},
show: function(id) {
@pksunkara
pksunkara / resourceful.md
Last active October 12, 2015 06:18
Many-to-Many in resourceful

One-to-Many relationship

In some web applications, we need to define a one-to-many relationship between two entities. For example, let's take github.

Example: One-to-Many relationship exists between user and repository. User pksunkara have 2 repositories octonode and hub

The entities are defined as the following:

var resourceful = require('resourceful');
@junosuarez
junosuarez / gist:3768642
Created September 23, 2012 02:46
Async Collection
/*global define:false */
define(['backbone','underscore','deferred'], function (B, _, flow) {
/**
* @constructor
*/
var AsyncCollection = B.Collection.extend({
initialize: function () {
// if the initialize function is overriden in an
// extended class of AsyncCollection, ensure
@tbjers
tbjers / menu.js
Created September 3, 2012 17:12
Express resources with authentication middleware
module.exports = {
menu: {
'wall': { title: 'Wall', name: 'wall' },
'logs': { title: 'Logs', name: 'logs', submenu: {
'system': { title: 'System', name: 'system' }
} },
'stats': { title: 'Stats', name: 'stats' },
'admin': { title: 'Admin', name: 'admin', submenu: {
'users': { title: 'Users', name: 'users' },
'grants': { title: 'Grants', name: 'grants' }
@distracteddev
distracteddev / index.js
Created April 15, 2012 04:13
Example of a Resourceful.js Model with a custom MapReduce Filter
var Resourceful = require('resourceful');
var tagFilter = {
map: function (post) {
post.tags.forEach(function (tag) {
emit(tag, 1);
});
},
reduce: function(keys, values) {
@PatrickHeneise
PatrickHeneise / gist:2132062
Created March 20, 2012 06:38
passport.js with flatiron.js, union and director
var flatiron = require('flatiron')
, connect = require('connect')
, path = require('path')
, fs = require('fs')
, plates = require('plates')
, director = require('director')
, util = require('util')
, keys = require('./auth_keys')
, passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');
@timoxley
timoxley / gist:1721593
Created February 2, 2012 04:58
Recursively run all tests in test directory using mocha
// this will find all files ending with _test.js and run them with Mocha. Put this in your package.json
"scripts": {
"test": "find ./tests -name '*_test.js' | xargs mocha -R spec"
},