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
app.use(express.cookieParser()); | |
app.use(express.session({ | |
secret: 'MySecret', //Should be the same across all the apps that share the same sessions. | |
store: Bla, //Init your store here | |
cookie: {domain: '.mydomain.com'} //The point in front here is important so that the same sessions work across all sub-domains. | |
})); |
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
//That's your route | |
function(req,res,next){ | |
var username = req.session.username; | |
var filteredArray = _.filter(myArray,function(value){ | |
return value == username; //username is in your closure there... | |
}); | |
} |
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
//Animal constructor | |
function Animal( legCount ){ | |
this.legCount = legCount; | |
} | |
//Methods | |
Animal.prototype.legCount = function(){ | |
return( this.legCount ); | |
}; |
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
//Mongodb shell script | |
db.MyCollection.update( | |
{'comments._id' : {$exists : true}}, | |
{$set : {'comments.$.author': PutYourValueHere}}, | |
false, | |
true); |
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
//Javascript magic here | |
//We grab the value from the dom element, split it in terms where every | |
//term is delimited by a comma, then trim every term, re-combine them | |
//together using a comma as separator and then URI encode the whole thing. | |
var fieldVals = encodeURIComponent( | |
this.$('#product_search #field_val').val().split(',').map(function(v){ | |
return v.trim(); | |
}).join(',') | |
); |
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
//The application model itself. | |
var Router = Backbone.Router.extend({ | |
//Attributes | |
routes : { | |
//Home sweet home! | |
'home' : 'home', | |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var FooSchema = new Schema({ | |
dob: { type: Date}, | |
num: {type : Number}, | |
test : { | |
bla : {type: Number} | |
} | |
}); |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var FooSchema = new Schema({ | |
dob: { type: Date}, | |
num: {type : Number}, | |
}); | |
Foo = mongoose.model('Foo', FooSchema); |
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 app = express(); | |
var server = http.createServer(app); | |
var io = require('socket.io').listen(server); //We're listening to the server here, not the express app. |
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
//That's your middleware code | |
function myMiddleware(app){ | |
var myVar = 42; //Put middleware-wide vars in the closure. | |
var actualMiddleware = function(req, res, next){ | |
//Do stuffs here | |
next(); |