Skip to content

Instantly share code, notes, and snippets.

View albertodeago's full-sized avatar

Alberto De Agostini albertodeago

View GitHub Profile
@albertodeago
albertodeago / index.js
Created December 29, 2021 07:51
Download memes from imgflip (scraping with puppeteer)
const puppeteer = require("puppeteer");
const fs = require("fs");
const pageUrl = "https://imgflip.com/memetemplates";
const viewport = {
width: 1600,
height: 1200,
};
const MEME_LIST_SELECTOR = ".mt-boxes";
@albertodeago
albertodeago / allColors.js
Created September 5, 2019 10:15
A snippet to run in any web page to list all the colours (and how many times) used in that page
// 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 September 5, 2019 10:14
A snippet to run in any web page to highlight all elements
(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 February 11, 2019 19:32
Simple JS implementation of the fizzbuzz problem
/**
* 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 October 23, 2018 08:26
Using reduce to sequentially handle promises
function getInSequence(array, asyncFunc) {
return array.reduce((previous, current) => (
previous.then(accumulator => (
asyncFunc(current).then(result => accumulator.concat(result))
))
), Promise.resolve([]));
}
/**
example of use: