Skip to content

Instantly share code, notes, and snippets.

sUser.pre('save', function (next) {
var self = this
, now = Date.now()
this.updatedAt = now
if (this.isNew) this.createdAt = now
if (!this.isModified('password')) return next();
co(function *() {
self.password = yield self.encryptPassword(self.password)
next()
})()
var AlbumSchema = new Schema({
parent: {
type: Schema.Types.ObjectId,
ref: 'Album'
},
children: [{
type: Schema.Types.ObjectId,
ref: 'Album'
}],
createdAt: {
getActionByName : function(name, callback) {
//need to wait for data here
this.find(function(actionModel) {
console.log("Trying to get an action name");
callback(null, actionModel.getName().toLowerCase() === name.toLowerCase());
});
}
var session = require('express-session')
, config = require('../config')
, mongoStore = require('connect-mongo')({session: session});
module.exports = function() {
return session({
secret: config.sessions.secret,
store: new mongoStore({
url: config.db.url,
collection : config.sessions.collection
// 1. Save gist as fixsvpplylinks.js
// 2. Install node.js (http://nodejs.org/)
// 3. 'npm install async request'
// 4. 'node fixsvpplylinks.js /path/to/wants.json'
// 5. Wait.
// 6. Don't worry about those EventEmitter warnings!
// 7. Done.
// 8. If there's any issues then give me a tweet (@artcommacode)
// Page is the returned mongoose Model for 'Page'
Page
// finding all pages that have isPublished set to true
.find({isPublished: true})
// populating the sub-documents 'album' from the 'Album' Model
.populate({
path: 'album'
})
// execute the query
.exec(function (error, pages) {
// is there a "neater" or "better" way of doing this?
function getNextSlide(right) {
return right ?
slideshow.$current.next().length ?
slideshow.$current.next() :
$(slideshow.slides).first() :
slideshow.$current.prev().length ?
slideshow.$current.prev() :
$(slideshow.slides).last();
var index = lunr(function () {
this.field('title', {boost: 10});
this.field('text');
this.ref('_id');
});
pages.forEach(function (page) {
if (page.album) index.add(page);
});
var currentlyIn = false;
// we need somewhere to hold state so that we don't continuously emit events
$(window).bind('scroll', function() {
// bind the scroll event from the window so this function's called when the user scrolls
var inView = ($(this).scrollTop() + $(this).height()) > $('.some-element').offset().top;
// check if the top of the element is less than the bottom of the window
if (inView === currentlyIn) return true;
// if the new state is the same as the old then don't do anything
$('.some-element').trigger(inView ? 'in-view' : 'out-view');
// payment
{ intent: 'sale',
redirect_urls:
{ return_url: 'http://localhost:3000/payment/accepted?uuid=f54a5320-e80b-11e3-bbcd-ef7d2f770fd4',
cancel_url: 'http://localhost:3000/payment/cancelled' },
payer: { payment_method: 'paypal' },
transactions: [ { amount: [Object] } ] }
// response