Skip to content

Instantly share code, notes, and snippets.

View foxbunny's full-sized avatar

Hajime Yamasaki Vukelic foxbunny

  • Devius LLP
  • Belgrade, Serbia
View GitHub Profile
@foxbunny
foxbunny / gist:1082433
Created July 14, 2011 13:22
Bind node-validator to req
/*
* This binds the node-validator library to the req object so that
* the validation / sanitization methods can be called on parameter
* names rather than the actual strings.
*
* 1. Be sure to include `req.mixinParams()` as middleware to merge
* query string, body and named parameters into `req.params`
*
* 2. To validate parameters, use `req.check(param_name, [err_message])`
* e.g. req.check('param1').len(1, 6).isInt();
@foxbunny
foxbunny / fixtures.js
Created July 22, 2011 21:18
Problematic fixture module
var async = require('async'),
assert = require('assert');
// Clean up database
function cleanUp(Model, callback) {
Model.remove({}, function(err) {
Model.find({}, function(err, docs) {
assert.equal(docs.length, 0, 'Documents should not exist, found ' + docs.length);
callback(err);
});
@foxbunny
foxbunny / fixture.js
Created July 23, 2011 10:39
Broken fixture module
var async = require('async'),
assert = require('assert');
// Clean up database
function cleanUp(Model, callback) {
Model.remove({}, function(err) {
Model.find({}, function(err, docs) {
assert.equal(docs.length, 0, 'Documents should not exist, found ' +
docs.length);
callback(err);
@foxbunny
foxbunny / fixture.js
Created July 26, 2011 17:45
Fixture module
// Loads fixtures using given data, and executes callback
//
// The fixutres are loaded in recursive callbacks from the documents' save
// methods, therefore the loadFixtures call is asynchronous itself, even though
// it will load documents serially.
//
// When using loadFixtues in testing, you need to keep above in mind. Running
// multiple tests that use loadFixtures one after another _will_ cause trouble.
//
// The callback function is passed data that has been entered into the
@foxbunny
foxbunny / router.coffee
Last active December 21, 2015 05:39
Highly customizable helper class for generating ExpressJS routes that provide a REST interface for Mongoose models
###!
Router
======
@author Branko Vukelic <branko@brankovukelic.com>
@license MIT
@version 0.0.1
###
###
@foxbunny
foxbunny / gist:6352500
Last active December 21, 2015 19:09
CoffeeScript UMD wrapper for modules that use CommonJS format. Also does some dependency checks when not using a module loader. The exported value is also put under a namespace `MyModule.somePath`.
define = ((root) ->
if typeof root.define isnt 'function' or not root.define.amd
if GLOBAL? and typeof module is 'object' and module.exports
(factory) ->
module.exports = factory(GLOBAL.require)
else
require = (dep) ->
(() =>
switch dep
when 'underscore' then @_
propset: (o, p, v=null) ->
[f, r...] = p.split('.')
if not f of o
o[f] = if not r.length then v else {}
h.propset o[f], r.join '.', v
start on runlevel [2345]
stop on runlevel [06]
exec /path/to/start.sh
var path = require('path')
module.exports = {
entry: './src/index.js',
output: {
path: './static',
publicPath: '/static/',
filename: 'app.js',
},
module: {
module.exports = {
entry: './src/index.js',
output: {
path: './pub/static',
publicPath: '/static/',
filename: 'bundle.js',
}
}