Skip to content

Instantly share code, notes, and snippets.

Alberto De Agostini albertodeago

View GitHub Profile
@albertodeago
albertodeago / allColors.js
Created Sep 5, 2019
A snippet to run in any web page to list all the colours (and how many times) used in that page
View allColors.js
// allcolors.js
// https://github.com/bgrins/devtools-snippets
// Print out CSS colors used in elements on the page.
(function () {
// Should include colors from elements that have a border color but have a zero width?
var includeBorderColorsWithZeroWidth = false;
var allColors = {};
var props = ["background-color", "color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color"];
@albertodeago
albertodeago / highlightElements.js
Created Sep 5, 2019
A snippet to run in any web page to highlight all elements
View highlightElements.js
(function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
if (items.length > 0) {
for (var i = 0; i < items.length; i++) {
@albertodeago
albertodeago / fizzbuzz.js
Last active Feb 11, 2019
Simple JS implementation of the fizzbuzz problem
View fizzbuzz.js
/**
* Write a program that prints the numbers from 1 to 100.
* But for multiples of three print “Fizz” instead of the
* number and for the multiples of five print “Buzz”.
* For numbers which are multiples of both three and five print “FizzBuzz”.
*/
function fizzBuzz(num) {
var i = 0;
while(i <= num) {
var output = "";
@albertodeago
albertodeago / reduce-promises.js
Created Oct 23, 2018
Using reduce to sequentially handle promises
View reduce-promises.js
function getInSequence(array, asyncFunc) {
return array.reduce((previous, current) => (
previous.then(accumulator => (
asyncFunc(current).then(result => accumulator.concat(result))
))
), Promise.resolve([]));
}
/**
example of use:
You can’t perform that action at this time.