Skip to content

Instantly share code, notes, and snippets.

View pete-otaqui's full-sized avatar

Pete Otaqui pete-otaqui

View GitHub Profile
@pete-otaqui
pete-otaqui / filterKeys.js
Last active August 14, 2019 10:14
Filter out keys from an object
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 March 8, 2019 09:47
Convert Image to Base 64 WebDriver JS and Node style
// 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 July 12, 2017 06:23
Combinations and Pairs in javascript
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 January 11, 2021 04:19
Lloyds Fonts
@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 / hyper-sync-settings.json
Created November 8, 2016 09:08
hyper-sync-settings
{}
@pete-otaqui
pete-otaqui / download-website.sh
Created October 21, 2016 07:52
download a website for offline browsing with wget
#!/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 December 11, 2015 08:07
Monokai-style colours for windows 16-color command prompt
{
"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 October 26, 2015 16:33
wallmaker - bad geometry
// 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 August 29, 2015 14:13
Javascript Throttle
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 December 7, 2014 19:07
Simple Gulpfile with static serving and live reload
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,