Skip to content

Instantly share code, notes, and snippets.

@vuknje
vuknje / get_styles_without_inherited.js
Last active January 13, 2016 09:51
Get element computed styles without the inherited ones (Chrome dev tools functionality when 'Show all' is unchecked.
// 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) {
// Makes the browser unresponsive for timeMs milliseconds
function kill(timeMs) {
var start = +new Date;
while (+new Date - start < timeMs){}
}
kill(2000);
angular
.module 'djokica'
.directive 'djokaChart', ->
restrict: 'E'
replace: true
template: '<div></div>'
scope:
params: '='
data: '='
@vuknje
vuknje / gist:828dae51860d4ce3fe77
Last active August 29, 2015 14:05
_.indexBy, _.groupBy, _.countBy
# _.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"
# 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
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);