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:6af05239585cec8e580f
Last active August 29, 2015 14:13
How to access the angular $scope variable in browser's console?
// http://stackoverflow.com/questions/13743058/how-to-access-the-angular-scope-variable-in-browsers-console
angular.element($0).scope()
// Access whole scope
angular.element(myDomElement).scope();
// Access and change variable in scope
angular.element(myDomElement).scope().myVar = 5;
angular.element(myDomElement).scope().myArray.push(newItem);
@felixzapata
felixzapata / gist:aacb743a9bfd94e08932
Created November 9, 2014 10:33
node.js glob pattern for excluding multiple files
/**
Walk directory,
list tree without regex excludes
http://stackoverflow.com/questions/23809897/node-js-glob-pattern-for-excluding-multiple-files
*/
var fs = require('fs');
var path = require('path');
var walk = function (dir, regExcludes, done) {
@felixzapata
felixzapata / gist:4a049a64bc7c713a8a12
Created November 6, 2014 07:42
Count the number of bindings in your app
function getScopes(root) {
var scopes = [];
function traverse(scope) {
scopes.push(scope);
if (scope.$$nextSibling)
traverse(scope.$$nextSibling);
if (scope.$$childHead)
traverse(scope.$$childHead);
}
traverse(root);
@felixzapata
felixzapata / gist:d26d9d276d1a7da4f885
Created October 30, 2014 13:20
Create IE + others compatible event handler
// Create IE + others compatible event handler
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from child window
eventer(messageEvent,function(e) {
console.log('parent received message!: ',e.data);
},false);
@felixzapata
felixzapata / gist:ef4a399aaf6fa16775bb
Created September 26, 2014 08:44
Generate a string of 5 random characters in Javascript
// http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
Math.random().toString(36).substring(7)
@felixzapata
felixzapata / gist:8bc885c74b03e7503d63
Created August 21, 2014 18:19
Formato fecha dd/mm/yyyy
return (/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/).test(valor);
// http://www.mkyong.com/regular-expressions/how-to-validate-date-with-regular-expression/
// revisado
^(0?[1-9]|[12][0-9]|3[01])\/(0?[1-9]|1[012])\/((19|20)\d\d)
Object.prototype.extend = function(obj) {
for(i in obj)
this[i] = obj[i];
};
var o = { member: "some member" };
var x = { extension: "some extension" };
o.extend(x);
@felixzapata
felixzapata / gist:4089eb567c0929e688bd
Created August 21, 2014 07:50
Extending JavaScript Functions
// http://jondavidjohn.com/extend-javascript-functions/
Array.prototype.join = (function(_super) {
// return our new `join()` function
return function() {
console.log("Hey, you called join!");
return _super.apply(this, arguments);
};
// Pass control back to the original join()
var menu = document.querySelector('.menu')
var menuPosition = menu.getBoundingClientRect().top;
window.addEventListener('scroll', function() {
if (window.pageYOffset >= menuPosition) {
menu.style.position = 'fixed';
menu.style.top = '0px';
} else {
menu.style.position = 'static';
menu.style.top = '';
}
@felixzapata
felixzapata / gist:7242afdbe31f1cbccfcd
Created July 13, 2014 08:08
Which might cause horizontal overflow scrolling
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);