Skip to content

Instantly share code, notes, and snippets.

Working from home

Michael Richardson rainabba

Working from home
View GitHub Profile
rainabba /
Created Dec 13, 2021
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 Nov 23, 2021
Understanding execution order in Express handlers
View index.js
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 Oct 12, 2021
Clarifying javascript execution order
View index.js
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 Mar 24, 2021
Where did 'IntelDataApi' come from and why is my deploy failing because of it?
View input_template.yaml
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 Mar 10, 2021
Binding AWS Lambda, API Gateway, Route 53 (DNS) and SSL; with and without SAM
View template-using-sam.yaml
Type: String
Description: Major version changes should get new values (v1, v2, etc..)
Default: v1
!Equals [!Ref ZoneId, 'none']
rainabba /
Last active Oct 23, 2020
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 Sep 16, 2020
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
rainabba / pdfToImageTest.js
Created Feb 8, 2019
Testing common solutions to PDF -> image conversion
View pdfToImageTest.js
// SPOILER: Only 1 of these tests passes at this point and it bypasses
// all the fluff and complication so it's the one I will end up using
const { expect } = require('code'),
Lab = require('lab'),
lab = exports.lab = Lab.script(),
fs = require("fs"),
path = require("path"),
mkdirp = require('mkdirp'),
rimraf = require('rimraf'),
rainabba /
Last active Jul 24, 2020
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 / Promise-all.js
Created Jun 30, 2017
Promise.all() demonstration with iterations for refactoring
View Promise-all.js
// Wait for ALL promises to return OR any to crash and then return the array of values to the caller of .all()
// // //Itteration 1
// // function runParallelPromisesSum() {
// // //Our function returns its own promise with our value that needed both the promises to return first
// // return new Promise( ( resolveAll, rejectAll ) => {
// // let promise1 = new Promise( ( resolvePromise1, rejectPromise1 ) => {
// // console.log("resolving 1");
// // resolvePromise1( 1 );