Skip to content

Instantly share code, notes, and snippets.

View stringparser's full-sized avatar
🏠
Working from home

Javier Carrillo Milla stringparser

🏠
Working from home
View GitHub Profile
@stringparser
stringparser / bdd_minimal.sh
Last active August 29, 2015 14:07
bdd minimal tests
#!/bin/sh
# taked from TJ
# https://github.com/visionmedia/commander.js/blob/master/test/run
export NODE_ENV=test
echo
for file in $@; do
printf " \033[90m${file#test/}\033[0m\n --- \n"
@stringparser
stringparser / bdd_minimal.js
Last active August 29, 2015 14:07
bdd minimal tests
var ansiJS = require('ansi-highlight');
var timer, exitCode;
function format(type, str, fn){
var test, badge;
try {
test = (fn || function(){})() || 'passed';
} catch(err){
test = err;
@stringparser
stringparser / gulpfile.js
Created September 19, 2014 15:45
dumb gulp@4.0 file
'use strict';
var gulp = require('./.');
gulp.task('js', function(done){
done();
});
gulp.task(function jsx(done){
done();

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@stringparser
stringparser / stdoutHook.md
Last active April 3, 2022 06:09
node stdout hook with knobs

Inspired on this other gist

function hook(callback){
  
  var oldWrite = process.stdout.write;
  var output = { str : '' };

  return {
    restore : function(){
var util = require('util')
function hook_stdout(callback) {
var old_write = process.stdout.write
process.stdout.write = (function(write) {
return function(string, encoding, fd) {
write.apply(process.stdout, arguments)
callback(string, encoding, fd)
}
@stringparser
stringparser / eventListenerList.js
Last active November 6, 2018 16:50
`eventListenerList`
;[Element].forEach(function(self){
self.prototype.eventListenerList = {};
self.prototype._addEventListener = self.prototype.addEventListener;
self.prototype.addEventListener = function(type, handle, useCapture) {
useCapture = useCapture === void 0 ? false : useCapture;
var node = this;
node._addEventListener(type, handle, useCapture);