Skip to content

Instantly share code, notes, and snippets.

View ariesmcrae's full-sized avatar
💭
typescript, node.js, aws, java, go (golang)

A. M. ariesmcrae

💭
typescript, node.js, aws, java, go (golang)
View GitHub Profile
@ariesmcrae
ariesmcrae / check-bash-version.md
Created October 24, 2024 11:21
Bash v5 scripting: Check Bash version
usr/bin/env bash

set -euo pipefail

check_bash_version() {
    if [[ ${BASH_VERSINFO[0]} -lt 5 ]]; then
        echo "Error: At least Bash version 5 is required."
        echo "Your Bash version is: ${BASH_VERSINFO[0]}"        
 exit 1
@ariesmcrae
ariesmcrae / bash-5-hash-set.md
Last active October 24, 2024 23:03
Bash v5 scripting: Hash Set example
#!/usr/bin/env bash

set -euo pipefail

declare -A hash_set

# Add elements to the hash set
hash_set["name1"]="Matthew"
hash_set["name2"]="Luke"
@ariesmcrae
ariesmcrae / bash-method-multiple-return-values.md
Last active October 24, 2024 10:47
Bash v5 scripting: Method returns multiple values
get_person_details() {
    local name="John"
    local age=25

    # Return the values
    echo "$name $age"
}

# Extract the values from the func
@ariesmcrae
ariesmcrae / apple-silicon-macOS-Bash-upgrade.md
Created October 24, 2024 10:40
Upgrade Apple Silicon macOS Bash from v3.x to 5.x

Find out which Bash version you're currently using

# check current Bash version
bash -version

# output:
# GNU bash, version 3.2.57(1)-release (arm64-apple-darwin23)
@ariesmcrae
ariesmcrae / pyenv.md
Last active December 20, 2024 05:23
Install python on macOS using pyenv

Pyenv will allow you to switch to different versions of python locally (much like nvm for node.js or jenv for java)

Install pyenv

brew install pyenv

Add this to your ~/.zshrc

export PYENV_ROOT="$HOME/.pyenv"
@ariesmcrae
ariesmcrae / sign-git-commit-with-gpg.md
Created March 31, 2024 05:17
Sign git commits with GPG
@ariesmcrae
ariesmcrae / polyline.md
Last active October 11, 2023 12:02
Typescript: How to decode google maps encoded polylines

npm i @mapbox/polyline

npm i -D @types/mapbox__polyline

import * as polyline from '@mapbox/polyline';

/**
* coords is encoded using the Google Maps algorithm for polyline encoding. See
* https://developers.google.com/maps/documentation/utilities/polylinealgorithm
* Use this for decoding https://www.npmjs.com/package/@mapbox/polyline
@ariesmcrae
ariesmcrae / date_now_utc.md
Last active September 11, 2023 01:17
Typescript: Convert current date object to UTC string using the 'date-fns-tz' library

Typescript: Convert current date object to UTC string using the 'date-fns-tz' library

// npm i date-fns-tz

import { utcToZonedTime, format as utcFormat } from 'date-fns-tz'

const main = async (): Promise<void> => {
  const dateInUtc: Date = utcToZonedTime(new Date(), 'UTC')
 const formattedDateInUTC = utcFormat(dateInUtc, 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', { timeZone: 'UTC' })
@ariesmcrae
ariesmcrae / git_branch_names.md
Created September 7, 2023 03:41
Git Semantic Branch Names
branch prefix desc touches prod code
+:refs/heads/(feature/*) add new feature Y
+:refs/heads/(fix/), +:refs/heads/(hotfix/) bug fix Y
+:refs/heads/(refactor/*) change code.e.g. renaming a variable Y
+:refs/heads/(docs/*) changes to docs N
+:refs/heads/(style/*) formatting, missing semi colons N
+:refs/heads/(test/*) adding missing tests, refactoring tests N
+:refs/heads/(chore/*) updating build scripts N
@ariesmcrae
ariesmcrae / dependency_injection.md
Last active September 6, 2023 01:41
The importance of dependency injection

The importance of dependency injection

Say you have a class named AbcClass.

If AbcClass depends on AnotherClass, and AnotherClass eventually needs to make a network call (e.g. to S3, Databse, GIS, some other party), then don't instantiate AnotherClass inside AbcClass. AnotherClass should be injected into the constructor of AbcClass.

Why? Here's the reason why:

Say AnotherClass is instantiated inside AbcClass. When you write a test for AbcClass, AnotherClass will inevitably make a network call.