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 / 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
@ariesmcrae
ariesmcrae / parse_utc_datetime.md
Last active August 30, 2023 12:38
Typescript: How to parse a UTC date using the date-fns library

Typescript: How to parse a UTC date using the date-fns library

Say you want to parse this date: 2023-05-31 T06:52:03Z. Note: This date is non-standard as it has a space between 31 and T

  // npm install date-fns date-fns-tz

  import { parseISO } from 'date-fns';
  import { utcToZonedTime, format as utcFormat } from 'date-fns-tz';
@ariesmcrae
ariesmcrae / javascript_map.md
Last active August 29, 2023 13:24
Typescript: How to use Map(k, v) collection to store unique key/value pairs and perform fast key lookup

Typescript: How to use Map(k, v) collection to store unique key/value pairs and perform fast key lookup

Insert a unique key/value pair

interface Person {
  name: string;
  age: number;
}
@ariesmcrae
ariesmcrae / s3-eventbridge-lambda.md
Created August 27, 2023 11:37
Direct S3 to Lambda vs EventBridge between S3 and Lambda

When should you use direct S3 to Lambda vs an EventBridge in between S3 and Lambda

S3 ==> Lambda 
    vs 
S3 ==> EventBridge ==> Lambda

TL;DR

@ariesmcrae
ariesmcrae / axios.md
Last active August 27, 2023 11:39
Creating an Axios instance vs using Axios directly

Creating an Axios instance vs using Axios directly

TL;DR

It's preferable to create an Axios instance in node.js. Why? Because it offers several advantages over using Axios directly. It provides a more flexible, organized, and maintainable way to manage HTTP requests:

1. Custom Configuration

When you create an instance, you can set default configurations like base URL, headers, timeouts, etc., that will be applied to all requests made using that instance. This eliminates the need to specify these settings for each request.

@ariesmcrae
ariesmcrae / logic-apps.md
Last active August 29, 2023 13:17
Reasons why workflows should be grouped into multiple multiple Azure Logic Apps

Reasons why workflows should be grouped into multiple AWS Logic Apps in order to help improve the development and maintenance lifecycle of workflows.

Reason 1: Business process affinity

Grouping workflows by related business process helps you implement, test and deploy a logic app without impacting other logic apps.

workflow

In the example above there are three Logic App Standard apps - Orders, Shipment Notification, Overnight Batches - each one with multiple logic app workflows that are used to fulfil a specific business process.

Organizing the logic apps this way, allows changes in the Orders Logic App Standard app to be implemented, tested, and deployed without having any impact on Shipment Notification or Overnight Batches.

@ariesmcrae
ariesmcrae / parallelism_vs_concurrency.md
Last active August 29, 2023 13:21
Parallelism vs Concurrency: when to use

Parallelism vs Concurrency: when to use

TL;DR

  • Use concurrency for I/O bound calls (e.g. REST API calls)
  • Use parallelizm for CPU bound calls

Scenario

You're working on a python 3.X codebase. You have a service that has 1,000 TODO IDs. For each TODO IDs, you want to get the TODO details via https://jsonplaceholder.typicode.com/todos/{tod_id}. How should you fan out the 1,000 calls to the TODO details web api? Which one of these techniques should you use? Either: