Skip to content

Instantly share code, notes, and snippets.

View juanpaco's full-sized avatar

Ethan Garofolo juanpaco

View GitHub Profile
var isAuthenticatedHandler = function(mountPoint) {
return function(req, res, next) {
if (!req.session.username) {
res.redirect(mountPoint + '/login');
} else {
next();
}
}
};
@juanpaco
juanpaco / gist:8417295
Created January 14, 2014 12:05
Warning, as currently coded this will give an endless redirect.
var express = require("express")
, app = express()
, parentApp = express()
var isAuthenticatedHandler = function(req, res, next) {
if (!req.session.username) {
res.redirect('login');
} else {
next();
}
@juanpaco
juanpaco / gist:8410206
Created January 13, 2014 23:40
How to populate those colors
exports.new = function(req, res){
Colour.list({}, function(err,colours) {
res.render('cars/new', {
title: 'New Car',
event: new Car({}),
colours: colours
})
})
}
@juanpaco
juanpaco / test.js
Created March 9, 2013 13:18
Sparse indexes in Mongo with Mongoose
// Assumes you've already somehow configured your db access. I left that part out
var mongoose = require("mongoose")
var es = new mongoose.Schema({
'firstname': { type: String, required: true },
'lastname': { type: String, required: true },
'email': { type: String, required: true, index: { unique: true, sparse: true }, validate: /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/ },
'departmentId': { type: mongoose.Schema.ObjectId, required: true },
'enddate': String,
@juanpaco
juanpaco / Output
Created February 14, 2013 13:45
Custom validator not being called in Mongoose on document creation
{ __v: 0, _id: 511cea75f01700e675000001 }
/home/dev/source/bigoh/vapor/node_modules/mongoose/lib/utils.js:398
throw err;
^
AssertionError: null == true
at /home/dev/source/bigoh/vapor/noCustom.js:20:3
at Promise.Model.create (/home/dev/source/bigoh/vapor/node_modules/mongoose/lib/model.js:1289:21)
at Promise.onResolve (/home/dev/source/bigoh/vapor/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8)
at Promise.EventEmitter.emit (events.js:99:17)
@juanpaco
juanpaco / The output
Created November 2, 2012 23:45
Exploration of return values from begin/rescue in Ruby
check ensure block
check ensure block
With no exception: good
With exception: bad
With exception and ensure: bad
With no exception and else: else
@juanpaco
juanpaco / gist:3304903
Created August 9, 2012 14:54
Asterisk extensions.conf
; extensions.conf - the Asterisk dial plan
;
; Static extension configuration file, used by
; the pbx_config module. This is where you configure all your
; inbound and outbound calls in Asterisk.
;
; This configuration file is reloaded
; - With the "dialplan reload" command in the CLI
; - With the "reload" command (that reloads everything) in the CLI