This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# ------------------------------------------------------------------------------ | |
# SOME INFOS : fairly standard (debian) init script. | |
# Note that node doesn't create a PID file (hence --make-pidfile) | |
# has to be run in the background (hence --background) | |
# and NOT as root (hence --chuid) | |
# | |
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit | |
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts | |
# INSTALL/REMOVE http://www.debian-administration.org/articles/28 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.mixin({ | |
filterByObject: function (arg, object) { | |
var obj = {}; | |
for (var a in object) { | |
if (typeof arg[a] == "object") { | |
obj[a] = this.filterByObject(arg[a], object[a]); | |
} else if (arg[a]) { | |
obj[a] = arg[a]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filterByMongooseSchema: function (arg, schema) { | |
return _.filterByObject(arg, schema.paths); | |
}, | |
filterByObject: function (arg, object) { | |
var obj = {}; | |
for (var a in object) { | |
if (typeof arg[a] == "object") { | |
obj[a] = this.filterByObject(arg[a], object[a]); | |
} else if (arg[a]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filterMongoosePrivates: function(doc) { | |
var obj = {}; | |
var keys = _.reject(_.keys(doc._doc), function (key) { | |
return key.indexOf("_") === 0; | |
}); | |
for (var i=0,j=keys.length;i<j;i++) { | |
obj[keys[i]] = doc[keys[i]]; | |
} | |
return obj; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filterMongoosePrivatesArray: function(docs) { | |
var arr = new Array(); | |
for (var i=0,j=docs.length;i<j;i++) { | |
arr.push(_.filterMongoosePrivates(docs[i])); | |
} | |
return arr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var Session, SessionSchema, SessionStore, defaultCallback; | |
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { | |
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } | |
function ctor() { this.constructor = child; } | |
ctor.prototype = parent.prototype; | |
child.prototype = new ctor; | |
child.__super__ = parent.prototype; | |
return child; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mongoose single embedded docs with 5 middlewares | |
var AccountObj = { | |
id: {type:ObjectId, index: {unique:true}}, | |
fname: String, | |
lname: String, | |
email: String, | |
phone: String | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MongooseUpserts = function (schema, options) { | |
options = options || {}; | |
schema.method('removeDefaults', function () { | |
var paths = schema.paths; | |
var defaults = {}; | |
for (var key in paths) { | |
if (this._doc[key] === paths[key].defaultValue) { | |
delete this._doc[key]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserSchema = new Schema({ | |
created: {type:Date, default:Date.now}, | |
last_update: {type:Date, default:Date.now}, | |
name: {type:String, default:'anonymous'}, | |
email: {type:String, default:'none', lowercase:true, index:true}, | |
}); | |
User = Mongoose.model('User', UserSchema); | |
var doc = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MongooseFilter = function (schema, options) { | |
options = options || {}; | |
schema.pre('save', function (next) { | |
this.filter(); | |
next(); | |
}); | |
schema.method('filter', function () { | |
var self = this; |
OlderNewer