Skip to content

Instantly share code, notes, and snippets.

View ovaillancourt's full-sized avatar

Olivier Vaillancourt ovaillancourt

  • Montreal, QC, Can
View GitHub Profile
// url :
/user/:userId/upload/delete
//post-body :
{
_id : <imageId>
}
var data = {
id : uploaded_file._id,
filters : [
{
name : 'image',
options : [
{
operation : 'resize',
width : $placeholder_img.width(),
height : $placeholder_img.height()
/**
* Very simple Mealy style finite state machine relying on a nodejs event emitter. Absolutely not tested
* and contains absolutely no fancy feature. You can put multiple "from" and "to" states by separating
* them with a space. Putting no "from" or "to" amounts to setting them as "undefined", a supported state.
*/
// Example:
/*
var fsm = new Fsm([
{ name : 'wakingup' , from: 'sleeping' , to : 'awake' },
app.get( '/bob', function( req, res, next ){
if( !req.session ){
console.log( 'no session!' );
}
else{
console.log( req.session );
req.session.counter++;
}
{
file: < the file>
name: filename
hook: {
name : "user_avatar",
userid : "09a8019238402a9sdfsa0",
}
}
var validation = require( './validation' );
var v = require('./validators' );
function lowerCase( value, err ){
return value.toLowerCase();
}
var userSchema = {
firstname : [ v.trim() ],
lastname : [ v.trim() ],
var user = {
name : [ purity.isString ], //Simple validation that the
//name is a string.
email : [ purity.trim, purity.isString, purity.isEmail ],
age : [ purity.isNumber, purity.greater(0), purity.toInt ],
//Array of friends
function findMostRecent(folder){
var mostRecent = null
var contentList = getFolderContentList(folder.path);
for(var i = 0; i < contentList.length; ++i){
if(contentList[i].type === 'file' &&
(mostRecent === null || contentList[i].date > mostRecent.date)){
mostRecent = contentList[i];
authmethods : [
{ type: 'facebook',
id: '12304912835812304192384'
token : 'asd0fa0sd9fasjdlfasdf9as0d98fasd',
salt: '1029384as0d9fasd8fasdf09asdf8as0df9as8dfasdf0asd9',
data: {...}
},
{
type: 'password',
var purity = require('virtue-purity'); //virtue's validation
//& sanitization lib.
var user = {
name : [ purity.isString ], //Simple validation that the
//name is a string.
email : [ purity.trim, purity.isString, purity.isEmail ],