Skip to content

Instantly share code, notes, and snippets.

@Alan-Gomes
Alan-Gomes / flatten.js
Created January 14, 2018 17:27
Recursively flattens array
const tst = [[1, [2], 3], 4 ,[5]];
const flatten = arr => Array.isArray(arr) ? arr.reduce((ac, val) => ac.concat(flatten(val)), []) : [arr];
console.log(flatten(tst)); // -> [1, 2, 3, 4, 5]
@Alan-Gomes
Alan-Gomes / SeleniumImage.js
Last active November 11, 2017 13:22
Downloading an already loaded image with selenium and node
const base64 = await driver.executeScript(`
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
var img = document.getElementById("loadedImage");
c.width = img.naturalWidth || img.width;
c.height = img.naturalHeight || img.height;
ctx.drawImage(img, 0, 0, c.width, c.height);
return c.toDataURL();
`).replace(/^data:image\/png;base64,/, "");