Skip to content

Instantly share code, notes, and snippets.

View dypsilon's full-sized avatar

Tim Navrotskyy dypsilon

View GitHub Profile
@dypsilon
dypsilon / withEventPool.js
Created January 17, 2014 00:42
This is a flight mixin for channeling and containing events of a component.
/**
* See: http://blog.michaelhamrah.com/2009/12/organizing-javascript-for-event-pooling-with-jquery/
*
* Using this mixin you can create self contained components which are listening only to the events
* of the parent node.
*
* Suppose you have several instances of the same "class" on one page. In this case, if you listen
* on the Document you will get the events from both instances and not know which one belong to
* your parent. This mixin helps you by passing around a node you can listen to, insted of the document.
*
@dypsilon
dypsilon / concat.js
Last active January 2, 2016 14:48
concat
var runner = require('./runner.js');
var path = require('path');
var async = require('async');
var fs = require('fs');
var mkdirp = require('mkdirp');
module.exports = function(dest, files, done) {
mkdirp(path.dirname(dest));
@dypsilon
dypsilon / runner.js
Last active January 2, 2016 11:49
This snippet runs a node module if it's called directly through the console or exports it's main function if it's required.
// file: runner.js
module.exports.accept = function(mod) {
if (require.main === mod) {
mod.exports(function(err) {
if (err) return console.error(err);
runner.log('Everything done.');
});
}
};
@dypsilon
dypsilon / async-hapi-plugin-example.js
Created October 22, 2013 10:00
This is a simple plugin for a mongodb connection.
var lib = require('mongodb');
var MongoClient = require('mongodb').MongoClient;
var ObjectID = require('mongodb').ObjectID;
var _ = require('lodash');
exports.register = function(plugin, options, next) {
MongoClient.connect(options.url, function(err, db) {
if(err) return next(new Error('Could not connect to the mongodb: ' + err));
var composer = new Hapi.Composer(nconf.get('manifest'));
composer.compose(function(err) {
if (err) {
console.log('Failed composing.');
console.log(err);
exit(1);
}
composer.start(function() {