This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Works in Firefox only | |
| function getStylesWithoutInherited(el) { | |
| return diffObjs( | |
| computedStylesToObj(window.getComputedStyle(el)), | |
| // window.getDefaultComputedStyle works in Firefox only | |
| computedStylesToObj(window.getDefaultComputedStyle(el)) | |
| ); | |
| } | |
| function diffObjs(obj1, obj2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Makes the browser unresponsive for timeMs milliseconds | |
| function kill(timeMs) { | |
| var start = +new Date; | |
| while (+new Date - start < timeMs){} | |
| } | |
| kill(2000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular | |
| .module 'djokica' | |
| .directive 'djokaChart', -> | |
| restrict: 'E' | |
| replace: true | |
| template: '<div></div>' | |
| scope: | |
| params: '=' | |
| data: '=' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # _.indexBy | |
| # Useful when you have an array of objects, but also need a quick access to the objects. Requires property with unique values. | |
| people = [{ id: 100, name: 'joe'}, { id: 101, name: 'jerry' }, { id: 102, name: 'jerry' }] | |
| peopleById = _(people).indexBy 'id' | |
| # returns | |
| { | |
| "100": { | |
| "id": 100, | |
| "name": "joe" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # An elegant little pattern for making array from the value that can be an array of a primitive | |
| # From: https://github.com/tvbeat/dimple/blob/master/src/methods/_addGradient.js#L6 | |
| sucks = (arg) -> | |
| # arg can be an array or a primitive | |
| someArray = [] | |
| if arg instanceof Array | |
| someArray = arg | |
| else | |
| someArray.push arg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ar = ['a', 'b', 'c', 'b', 'c', 'a', 'b', 'b'], | |
| data = []; | |
| var ar2 = ar.filter(function(element, position) { | |
| data.push({ 'element': element, 'ar.indexOf(element)': ar.indexOf(element)}); | |
| return ar.indexOf(element) === position; | |
| }); | |
| console.log('Original array:', ar); | |
| console.log('Array without duplicates:', ar2); |