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 / 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);
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 / 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(){

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 / 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();
@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 / 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 / index.js
Last active August 29, 2015 14:07
Boom, require dir
var fs = require('fs');
var path = require('path');
var fileList = fs.readdirSync(
path.resolve(path.dirname(module.parent.filename), path.basename(__dirname))
).slice(1);
exports = module.exports = { };
fileList.forEach(function(fileName){
@stringparser
stringparser / document.addEventListener
Created October 26, 2014 00:45
document.addEventListener('keydown', function(e){ /* do stuff */ })
var util = { };
document.addEventListener('keydown', function(e){
var key = util.key[e.which];
if( key ){
e.preventDefault();
}
if( key === 'F1' ){

The browser field is provided by a module author as a hint to javascript bundlers or component tools when preparing modules for client side use.

terms

Below are common terms used in the rest of the document

server

This is a non-dom based javascript execution environment. It usually only contains the base javascript language spec libraries and objects along with modules to communicate with OS features (available through commonjs require).

client