Skip to content

Instantly share code, notes, and snippets.

Avatar

Pete Otaqui pete-otaqui

View GitHub Profile
@pete-otaqui
pete-otaqui / filterKeys.js
Last active Aug 14, 2019
Filter out keys from an object
View filterKeys.js
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' };
@pete-otaqui
pete-otaqui / convert-img-to-base64.js
Created Mar 8, 2019
Convert Image to Base 64 WebDriver JS and Node style
View convert-img-to-base64.js
// 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);
@pete-otaqui
pete-otaqui / combos-and-pairs.js
Created Jul 12, 2017
Combinations and Pairs in javascript
View combos-and-pairs.js
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);
}
@pete-otaqui
pete-otaqui / lloyds.css
Last active Jan 11, 2021
Lloyds Fonts
View lloyds.css
@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;
}
@pete-otaqui
pete-otaqui / download-website.sh
Created Oct 21, 2016
download a website for offline browsing with wget
View download-website.sh
#!/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)
@pete-otaqui
pete-otaqui / colors.json
Created Dec 11, 2015
Monokai-style colours for windows 16-color command prompt
View colors.json
{
"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",
@pete-otaqui
pete-otaqui / wallmaker.js
Last active Oct 26, 2015
wallmaker - bad geometry
View wallmaker.js
// 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
@pete-otaqui
pete-otaqui / throttle.js
Last active Aug 29, 2015
Javascript Throttle
View throttle.js
function throttle(fn, ms, scope) {
var last = 0;
var fn = function() {
var now = Date.now();
if ( now - last > ms ) {
last = now;
fn.apply(scope, arguments);
}
};
return scope ? fn.bind(scope) : fn;
@pete-otaqui
pete-otaqui / Gulpfile.js
Created Dec 7, 2014
Simple Gulpfile with static serving and live reload
View Gulpfile.js
var gulp = require('gulp'),
connect = require('connect'),
serveStatic = require('serve-static'),
livereloadInjector = require('connect-livereload'),
livereloadTinyLR = require('tiny-lr'),
path = require('path'),
gutil = require('gulp-util');
var FOLDER_DEST = '.',
PORT_SERVER = process.env.PORT || 8888,