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 / 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 / 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:

@ariesmcrae
ariesmcrae / python_venv.md
Last active August 29, 2023 13:25
Why does my oh-my-zsh powerlevel10k prompt not show my python .venv virtual environment?

Why does my oh-my-zsh powerlevel10k prompt not show my python .venv virtual environment?

Your Powerlevel10k prompt might not be showing your Python virtual environment because it's configured to display the more informative name of the Python virtual environment. By default, Powerlevel10k may display the name of the directory containing the Python virtual environment rather than the less informative name "venv". This is more useful because it tells you which Python virtual environment is active rather than simply that a Python virtual environment is active.

However, you can change this configuration if you want. If you'd like your prompt to display "venv" when a Python virtual environment is active, you can add the following line to your ~/.p10k.zsh file:

typeset -g POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES=()

This will configure Powerlevel10k to display the less meaningful "venv" when a Python virtual environment is active. Please note that this will make your prompt less informative, which is w

@ariesmcrae
ariesmcrae / threadlocal.md
Last active August 29, 2023 13:27
Java ThreadLocal vs Node.js AsyncLocalStorage vs Python contextvars

How to store data within the request context using ThreadLocal (java), AsyncLocalStorage (node.js) vs contextvars (python)

Java's ThreadLocal

  • ThreadLocal is a class in Java that allows you to create variables that can only be read and written by the same thread. Even if two threads are executing the same code, and the code has a reference to a ThreadLocal variable, then the two threads can't see each other's ThreadLocal variables. So, it's a form of thread confinement which is useful for preventing thread-safety issues.
  • The primary limitation of ThreadLocal is that it is specifically tied to thread-based parallelism, so it's not as useful in event-driven or asynchronous programming models.

Python's contextvars

  • The contextvars module in Python 3.7+ provides a way to manage context-specific variables in a way that is more flexible than ThreadLocal, and specifically designed to work well with asynchronous tasks. The ContextVar class represents a variable that has different values depending on t
@ariesmcrae
ariesmcrae / M5Stack.ino
Last active September 4, 2022 10:32
Arduino Cloud: M5Stack Core 2 with ENV III temperature/humidity sensor
#include "thingProperties.h"
// M5Unit-ENV - Version: 0.0.6
#include <M5_ENV.h>
SHT3X sht30;
void setup() {
Wire.begin(); // Wire init, adding the I2C bus.
@ariesmcrae
ariesmcrae / Logger.ts
Created June 9, 2022 11:43
node.js singleton example in typescript
class Logger {
public error(msg: string, exception: Error): void {
console.error(msg, exception);
}
}
const instance = new Logger();
// Prevent modification to properties and values of the object.
@ariesmcrae
ariesmcrae / EventPublisher.js
Last active July 11, 2021 12:00
NodeJS AWS SDK for JavaScript v2 SNS: publishing a message from your local laptop when behind your corporate firewall
// I was getting this error when publishing sns from my local laptop:
// arn:aws:sns:ap-southeast-2:396497070286:int-afl-sns-topic
// Inaccessible host: `sns.ap-southeast-2.amazonaws.com'.
// This service may not be available in the `ap-southeast-2' region.",
// "code":"UnknownEndpoint",
// "region":"ap-southeast-2",
// "hostname":"sns.ap-southeast-2.amazonaws.com"
// getaddrinfo ENOTFOUND sns.ap-southeast-2.amazonaws.com
// This is the solution