This file contains 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
/** | |
* Perform a function with exponential backoff in the event of an error. | |
* | |
* @param fn The function to perform with backoff | |
* @param options Options for the backoff | |
* @returns The result of `fn()` after it has been successfully executed | |
* @throws Any error thrown by `fn()` after the maximum number of attempts has | |
* been reached, or if `options.retryError` returns false | |
* | |
* @example |
This file contains 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
function lpad(numOrStr, size) { | |
let s = `${numOrStr}`; | |
while (s.length < size) { | |
s = ` ${s}`; | |
} | |
return s; | |
} | |
/** | |
* Live progress log on a single shell line. |
This file contains 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
const filterKeys = (obj, keys) => | |
Object.entries(obj).reduce( | |
(acc, [k, v]) => (keys.includes(k) ? acc : { ...acc, [k]: v }), | |
{} | |
); | |
/** | |
// Usage: | |
const myObject = { foo: 'foo', bar: 'bar', baz: 'baz', eck: 'eck' }; |
This file contains 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
// This runs in a browser, | |
// it's usable with WebDriver as an injected script | |
function convertImagetoBase64(selector) { | |
const image = document.querySelector(selector); | |
const canvas = document.createElement("canvas"); | |
const context = canvas.getContext("2d"); | |
const { width, height } = image; | |
canvas.width = width; | |
canvas.height = height; | |
context.drawImage(image, 0, 0, width, height); |
This file contains 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
const _ = require('lodash'); | |
function getPairs(arr) { | |
let rCount = 0; | |
const results = arr.map(i => [i]); | |
const f = (base, rest) => { | |
for (let i = 0, max = rest.length; i < max; i += 1) { | |
const entry = [base, rest[i]]; | |
results.push(entry); | |
} |
This file contains 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
@font-face { | |
font-family: "Lloyds Jack Light"; | |
src: url("https://www.lloydsbank.com/assets/fonts/LloydsBankJackLight/lloyds_bank_jack-lightWEB.woff") format('woff'); | |
} | |
@font-face { | |
font-family: "Lloyds Jack Light"; | |
src: url("https://www.lloydsbank.com/assets/fonts/LloydsBankJackMedium/lloyds_bank_jack-mediumWEB.woff") format('woff'); | |
font-weight: bold; | |
} |
This file contains 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
{} |
This file contains 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
#!/bin/bash | |
wget -E -k -r -p -e robots=off https://some-site.com/docs/ | |
#### Note the following arguments: | |
# -E : converts downloaded HTML filenames to have a ".html" suffix | |
# -k : converts internal links within downloaded files to point to other downloaded files | |
# -r : recursively download by scanning for internal links in pages | |
# -p : download "page requisites", i.e. images, styles, scripts | |
# -e robots=off : ignore robots.txt (because some sites use it to avoid indexing) |
This file contains 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
{ | |
"black":"39/40/34", | |
"red":"249/38/114", | |
"green":"166/226/46", | |
"yellow":"244/191/117", | |
"blue":"102/217/239", | |
"magenta":"174/129/255", | |
"cyan":"161/239/228", | |
"white":"248/248/242", | |
"brightBlack":"117/113/94", |
This file contains 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
// do once per "row" (going down) | |
for ( let y=0; y<boxesDown; y++ ) { | |
// do once per "column" (going across) | |
for ( let x=0; x<boxesAcross; x++ ) { | |
// rx = top-left x coord of current square | |
let rx = x * size; | |
// ry = top-left y coord of current square | |
let ry = y * size; | |
// cx = centre point x coord of current square |
NewerOlder