Skip to content

Instantly share code, notes, and snippets.

View smithamax's full-sized avatar

Dominic Smith smithamax

View GitHub Profile
function stringProduct(n1, n2) {
return toString(toInt(n1) * toInt(n2))
}
const CHAR_0 = "0".charCodeAt(0) // 48
function toInt(str) {
return [...str].reverse().reduce((acc, c, i) => {
return acc + BigInt(c.charCodeAt(0) - CHAR_0) * (10n**BigInt(i))
}, 0n)
@smithamax
smithamax / README.md
Last active August 6, 2021 06:21
Error patterns

Do's

Don't catch errors in the first place

Not catching an error is perfectly fine, if it's something that shouldn't happen just let it fall through and cause a 500 so we know to fix it

Mapping errors

Most of the time when you catch an error you want to map from an infrastructure

(function () {
const canvas = document.createElement('canvas');
canvas.style = 'position: fixed; top: 0; right: 0; z-index: -100;'
// const canvas = document.getElementById('background');
function charRange(start, len) {
let chars = [];

Keybase proof

I hereby claim:

  • I am smithamax on github.
  • I am smithamax (https://keybase.io/smithamax) on keybase.
  • I have a public key ASCodZFss_KEPPoTo7Pg2CF764a6axA3Yryxp6Ma5kbmyAo

To claim this, I am signing this object:

@smithamax
smithamax / README.md
Last active July 5, 2017 15:04
Docker for nodejs and buildkite

Usage

Run service locally (mounts project dir)

docker-compose up

Develop locally (open bash prompt)

docker-compose run --rm app bash
@smithamax
smithamax / setup.sh
Last active May 30, 2017 02:15
Setup macos ready for remote admin
#!/bin/bash
# bash <(curl -sL http://mywebsite.com/myscript.txt)
set -e
sudo systemsetup -setremotelogin on
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew cask install anybar keepingyouawake
echo -n 'administrator@loke.com.au apple password: '
read -s PASSWORD
@smithamax
smithamax / gist:fa890c7dd108effcd916
Created February 4, 2016 01:13
universalMapper
function universalMapper(obj, fn) {
if (!obj) return obj;
if (Array.isArray(obj)) return obj.map(fn);
return fn(obj);
}
@smithamax
smithamax / README.md
Created December 15, 2015 05:47
bitbucket domains

bitbucket.com

$ dig bitbucket.com

; <<>> DiG 9.8.3-P1 <<>> bitbucket.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25393
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
@smithamax
smithamax / 0_reuse_code.js
Created October 21, 2015 01:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function Colourizer (colors) {
this._colors = colors;
}
Colourizer.prototype.getStringColor = function (str) {
var letters = str.split('');
return this._colors[letters.reduce(function (n, c) {
return n + c.charCodeAt(0)