Skip to content

Instantly share code, notes, and snippets.

View felixzapata's full-sized avatar

Félix Zapata felixzapata

View GitHub Profile
@felixzapata
felixzapata / gist:8971755
Created February 13, 2014 08:38
Cross-browser event handler
var EventUtil = {
addHandler: function(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + type, handler);
} else {
element["on" + type] = handler;
}
},
@felixzapata
felixzapata / gist:8958680
Created February 12, 2014 16:14
A One-Time Event Creation Function
// create a one-time event
function onetime(node, type, callback) {
// create event
node.addEventListener(type, function(e) {
// remove event
e.target.removeEventListener(e.type, arguments.callee);
// call handler
return callback(e);
});
@felixzapata
felixzapata / gist:8952298
Created February 12, 2014 09:18
Avoid `console` errors in browsers that lack a console.
// Avoid `console` errors in browsers that lack a console.
// via http://django.is/
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
@felixzapata
felixzapata / gist:8510944
Created January 19, 2014 21:01
Spawning a Child Process
'use strict';
const
fs = require('fs'),
spawn = require('child_process').spawn;
fs.watch(filename, function(){
let ls = spawn('ls', ['-lh', filename]);
ls.stdout.pipe(process.stdout);
});
@felixzapata
felixzapata / gist:7159552
Created October 25, 2013 18:32
copia ficheros via Node
var grunt = require('grunt');
var path = require('path');
var ncp = require('ncp').ncp;
//grunt.file.copy(path.normalize(__dirname + '/tasks/copy_all_docs.js'), path.normalize(__dirname + '/tasks2/copy_all_docs.js'));
grunt.file.mkdir(path.normalize(__dirname + '/.tmp/docs/rp1'));
ncp(path.normalize(__dirname + '/test/fixtures/repos/rp1/docs'), '.tmp/docs/rp1', function(err) {
if (err) {
return console.error(err);
@felixzapata
felixzapata / gist:7159513
Created October 25, 2013 18:29
tarea copiar dentro de Grunt
/*
* grunt-copy-all-docs
*
*/
'use strict';
module.exports = function(grunt) {
var fs = require('fs'),
@felixzapata
felixzapata / gist:7013891
Created October 16, 2013 20:05
grunt file
'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
var path = require('path');
var mountFolder = function(connect, dir) {
return connect.static(require('path').resolve(dir));
};
module.exports = function(grunt) {
// load all grunt tasks
@felixzapata
felixzapata / gist:6540192
Created September 12, 2013 16:17
Launch the Photo Chooser
<input type="file" name="image" accept="image/*" capture>
@felixzapata
felixzapata / gist:6521203
Created September 11, 2013 09:13
Common skeleton unit test for a directive
describe('myDir directive', function () {
var element, scope;
beforeEach(module('myDirModule'));
beforeEach(inject(function ($compile, $rootScope) {
var linkingFn = $compile('<my-dir></my-dir>');
scope = $rootScope;
element = linkingFn(scope);
}));
@felixzapata
felixzapata / gist:6037845
Created July 19, 2013 09:16
Igualador de alturas de elementos parametrizado
var setEqualHeight = function(){
"use strict";
function init(){
var obj = $(".setEqualHeight");
obj.each(function(){
var $that = $(this),
itemToSetHeight = $that.attr('data-itemToSetHeight'),
elementsToCompare = $that.attr('data-elementsToCompare');