Skip to content

Instantly share code, notes, and snippets.

View rainabba's full-sized avatar
Working from home

Michael Richardson rainabba

Working from home
  • Asurion
  • Manassas, VA
View GitHub Profile
rainabba /
Last active May 8, 2023 16:24
Bash retry with exponential backoff

A 1-liner bash function to provide basic non-zero exit retry with exponential backoff:


function retry_backoff {local m=${ATTEMPTS:-5};local t=${TIMEOUT:-1};local a=0;local e=1;while (($a < $m));do "$@";e=$?;if (($e == 0)); then break;fi;echo "Failure! Retrying in $t.." 1>&2;sleep $t;((a++));t=$((t*2));done;if (($e != 0));then echo "Max attempts reached!" 1>&2;fi;return $e; }


retry_backoff $YOUR_COMMAND # default of 5 retries, starting with 1 second timeout
rainabba /
Last active November 13, 2022 05:09
Building ffmpeg on AWS Linux AMI (G2 instance)

First, I should be clear that this was done on a G2 AWS instance and I started with working nvidia support by following

From that (or if you're feeling more bold), the thing to take is getting the right binary install package and running it. Look at and get the package you want (at the time, I'm using 'Latest Long Lived Branch version: 361.45.11'), then run the file you get. For example, sudo sh ./

I do not have time to test on a clean instance so you may need a bit more setup that I've not mentioned and I make no guarantees anyway since I hardly know what I'm doing here :)

The script was mostly copy/paste from the guide at and with significant help from folks on FreeNode #ffmpeg (notably furq and JEEB though there were others).

The steps for adding OpenCL headers support was borrowed

rainabba /
Last active September 6, 2022 03:46
Install docker-ce, docker-compose and docker-sync in Ubuntu for WSL
#This script assumes very little other than a fresh Ubuntu install (using the Windows store) on Win10 1709 or newer with WSL installed already
#In Powershell, run the following to install WSL and Ubuntu
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
#Invoke-WebRequest -Uri -OutFile ~/ -UseBasicParsing
#Expand-Archive ~/ ~/Ubuntu
rainabba /
Created December 13, 2021 20:25
How to IIFE the switch statement and more

First, credit to the answer at

Second, if you aren't comfortable with an IIFE (immediately executed function), you will want to check out

Now, because switch() {} is a "statement" in JavaScript and not a function, it can't be IIFE executed with the following

let failure = ( switch(x) { default: return true; } )(x);

You will get: "Uncaught SyntaxError: Unexpected token 'switch'"

rainabba / index.js
Last active November 23, 2021 17:08
Understanding execution order in Express handlers
To demonstrate the importance of understanding async execution order in the context of Express route handlers
Try in your browser at
const express = require('express'),
app = express(),
PORT = 3000,
rainabba / index.js
Created October 12, 2021 01:37
Clarifying javascript execution order
console.time('full execution');
console.time('code block');
function showExecutionOrder(parm) {
console.time('outside promise');
new Promise((resolve, reject) => {
console.time('inside promise');
console.timeEnd('inside promise');
}).then((data) => {
// Lookup mdn and invoke the account sync as required
rainabba / input_template.yaml
Created March 24, 2021 20:22
Where did 'IntelDataApi' come from and why is my deploy failing because of it?
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
# ... much omitted because it's unrelated
OpenApiVersion: 3.0.1
DefaultAuthorizer: NONE # AWS_IAM changed because we can't override on lambdas at this time. See
rainabba / template-using-sam.yaml
Created March 10, 2021 21:28
Binding AWS Lambda, API Gateway, Route 53 (DNS) and SSL; with and without SAM
Type: String
Description: Major version changes should get new values (v1, v2, etc..)
Default: v1
!Equals [!Ref ZoneId, 'none']
rainabba /
Last active October 23, 2020 21:40
Quickly and easily map/include field from an array of objects

My use case was an array of objects coming from a document-store so they're extremely variable and we only want a sub-set of the returned fields. There are plenty of ways to go about this and I hope snippet will serve that purpose, but for me this was more about realizing the power of () to do a bit more with the Lambda passed to map(). I regularly pull up ANY chrome page, hit Ctrl+Shift+J and develop small snippets right in the console, which is what led to 1 of 2 discoveries today.

How I would have gone about this in the past

let result = { Items: [{ a: 1, b: 2, x: 3 }] },
 newList = o => { return { a: o.a, b: o.b }; );

My new solution

rainabba /
Created September 16, 2020 23:27
cp - 'are the same file'
## Below is a script/log (anonymized) of an instance where I'm getting "are the same file" errors from `cp`
## Clearly they are not "the same file", but have identical contents and the 2nd is from a `git clone` command
# me@myhost:/mnt/c/prj/someorg/some-project$ ls -lah;
ls -lah;
# total 0
# drwxr-xr-x 1 someuser root 512 Sep 15 10:26 .
# drwxr-xr-x 1 someuser root 512 Jun 3 06:48 ..
# drwxr-xr-x 1 someuser root 512 Apr 16 10:46 .vscode