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 / settings.json
Created March 31, 2023 05:33
Visual Studio Code default terminal in settings.json
{
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
@ariesmcrae
ariesmcrae / information-hiding.md
Last active August 29, 2023 13:32
information hiding by not putting information on the interface that are likely to change, thus making your MS independently deployable and stand alone

information hiding is a concept where you don't put information on the interface that are likely to change, thus making your microservice independently deployable and stand alone

  • Information hiding (aka encapsulation aka decoupling): you hide the parts of the application that are most likely to change, thus protecting other parts of the program from extensive modification, if the design decision is changed.

  • Information hiding is the ability to prevent certain aspects of a class or software component from being accessible to its clients (like private variables), thus minimises the blast radius.

  • Information hiding makes your app independently deployable, more modular.

  • Any information (e.g. interface, swagger, function, method, property, object, data structure) that you expose outside of your microservice boundary, an external consumer will make use of that. You try and limit what you expose so that you minimize the affect to your consumer if you ever change the interface to your microservice. O

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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';