Skip to content

Instantly share code, notes, and snippets.

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

Aries McRae ariesmcrae

💭
typescript, node.js, aws, java, go (golang)
View GitHub Profile
@ariesmcrae
ariesmcrae / pyenv.md
Last active April 1, 2024 04:59
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
brew install xz

Add this to your ~/.zshrc

@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.

@ariesmcrae
ariesmcrae / find_item.md
Last active September 1, 2023 09:04
Typescript: Find an item from one list to another

Typescript: Find an item from one list to another

Version 1: the imperative approach

type Item = {
  id: string
  name: string
}

const items1: Item[] = [
@ariesmcrae
ariesmcrae / basic_auth.md
Last active August 31, 2023 01:44
Typescript: Basic auth (username/password) with Axios

Typescript: Basic auth (username/password) with Axios

// npm install axios

import axios, { AxiosInstance } from 'axios'

const axiosInstance: AxiosInstance = axios.create({
  baseURL: 'https://jsonplaceholder.typicode.com',
 timeout: 3000,
@ariesmcrae
ariesmcrae / date-comparison.md
Created August 29, 2023 15:10
Typescript: Date comparison using `date-fns`

Typescript: Date comparison using date-fns

import { compareAsc, parseISO } from 'date-fns';

type UltraMarathoner = {
  id: string;
  name: string;
  finishTime: string;
};
@ariesmcrae
ariesmcrae / parse_unix_epoch_date.md
Last active August 30, 2023 12:38
Typescript: How to parse a unix epoch date using date-fns library

Typescript: How to parse a unix epoch date using date-fns library

  // npm install date-fns date-fns-tz
  
  import { fromUnixTime, } from 'date-fns';
  import { utcToZonedTime, format as utcFormat } from 'date-fns-tz';

  // Unix epoch timestamp is a string in milliseconds in UTC
  const unixTimestampString = '1692761130000'; // 2023-08-23 03:25:30.000Z