Skip to content

Instantly share code, notes, and snippets.

@Graham42
Graham42 / paste-snippet-to-webconsole.js
Last active January 12, 2022 02:51
Show All GitHub History for a user
/*
* To use this open your GitHub profile page and then open the browser dev tools
* console and paste this in.
*/
async function sleep(n) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), n);
});
}
@Graham42
Graham42 / Dockerfile
Last active January 20, 2020 03:51
Serve directory with https (SSL, TLS) self-signed
FROM python:3-alpine
RUN apk --no-cache upgrade && \
apk --no-cache add \
openssl
WORKDIR /app
RUN openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes \
-subj "/C=CA/ST=Ontario/L=Toronto"
COPY serve.py index.html /app/
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@Graham42
Graham42 / bootstrap-ts-project.sh
Created November 8, 2019 17:03
rough idea how to start a ts project
#!/usr/bin/env bash
set -e;
npm init -y
node -e "const pkg = require('./package.json');
pkg.version = '0.0.0-dev'
pkg.license = 'MIT';
pkg.scripts = pkg.scripts || {};
pkg.scripts['lint:eslint'] = 'eslint --ext .ts,.js . ';
@Graham42
Graham42 / square-feet-function.js
Created October 24, 2018 02:15
Square Feet function for google sheets
/**
* @param {string} dimensions Ex. 12"3'x10"7'
* @customfunction
*/
function SQUAREFT(dimensions) {
var parts = dimensions.split("x")
var width = parseFeet(parts[0])
var height = parseFeet(parts[1])
return width * height
}
mkdir -p ~/Pictures/Wallpapers
WIDTH=1280
HEIGHT=800
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')
curl -JL -o "$HOME/Pictures/Wallpapers/${RANDOM_NAME}.jpeg" https://picsum.photos/g/$WIDTH/$HEIGHT?random
osascript -e "tell application 'Finder' to set desktop picture to POSIX file '$HOME/Pictures/Wallpapers/${RANDOM_NAME}.jpeg'"
@Graham42
Graham42 / retry.sh
Last active September 26, 2018 14:51 — forked from sj26/LICENSE.md
Bash retry function
# echo, but to stderr
function echoerr {
echo "$@" 1>&2;
}
# Retry a command up to a specific numer of times until it exits successfully,
# with exponential back off.
#
# $ retry 5 echo Hello
# Hello
#
@Graham42
Graham42 / bootstrap-node-project.sh
Last active December 20, 2018 21:08
Start a fresh nodejs project
#!/usr/bin/env bash
set -e;
npm init -y
node -e "const pkg = require('./package.json');
pkg.version = '0.0.0-dev'
pkg.license = 'MIT';
pkg.scripts = pkg.scripts || {};
pkg.scripts.lint = \"eslint . \";
@Graham42
Graham42 / map-filter-reduce-example.groovy
Last active May 25, 2022 16:48
Groovy example for map, filter, reduce
// In Groovy
// collect = "map"
// inject = "reduce"
//
// See http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html for docs
////////////////////////////////////////////////////////////////////////////////
// Arrays
def myNumbers = [3, 5, 1]
@Graham42
Graham42 / nope-to-IE.html
Last active December 16, 2017 22:35
refuse to serve IE - this is conditionally useful
<body>
<noscript>
<p>You need to enable JavaScript to run this app.</p>
</noscript>
<!-- Check for IE 9 and below -->
<!--[if IE]>
<p>Sorry! Your browser is not supported. We recommend using
<a href="https://www.google.com/chrome/browser/">Chrome</a> or
<a href="https://www.mozilla.org/en-US/firefox/new/">Firefox</a>.
</p>