Skip to content

Instantly share code, notes, and snippets.

View ovaillancourt's full-sized avatar

Olivier Vaillancourt ovaillancourt

  • Workleap
  • Montreal, QC, Can
View GitHub Profile
app.get( '/bob', function( req, res, next ){
if( !req.session ){
console.log( 'no session!' );
}
else{
console.log( req.session );
req.session.counter++;
}
/**
* 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' },
var data = {
id : uploaded_file._id,
filters : [
{
name : 'image',
options : [
{
operation : 'resize',
width : $placeholder_img.width(),
height : $placeholder_img.height()
// url :
/user/:userId/upload/delete
//post-body :
{
_id : <imageId>
}
@ovaillancourt
ovaillancourt / gist:4392412
Created December 27, 2012 21:56
Separator snippet for sublime text 2
<snippet>
<content><![CDATA[
// ${1:SECTION-NAME}
////////////////////////////////////////////////////////////////////////////////
$2
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>sep</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
function wrap( middleware, trigger ){
return function( req, res, next ){
// The trigger can be a function that gets dynamically evaluated every time
// or a static truthy/falsy variable
if( typeof trigger === 'function' ? trigger() : trigger ){
middleware( req, res, next )
}
else{
next();
}
// Template loading code
////////////////////////////////////////////////////////////////////////////////
// Reload the cached files when it changes.
function onFileChange( filename, filePath, cb ){
function exec( event ){
if( process.env.NODE_ENV !== 'production' ){
console.error( 'Loading template:'.yellow, filePath.grey );
}
function add( x,y ){
return x + y;
}
function staticAdd( x ){
return function( y ){
return x + y;
}
}
^.*(?:\.\$)([a-zA-Z0-9_]+)\s*.*$
var EventEmitter = require( 'events' ).EventEmitter;
var emitter = new EventEmitter();
// SECTION-NAME
////////////////////////////////////////////////////////////////////////////////
function emitterClass(){
EventEmitter.call( this );
}