Skip to content

Instantly share code, notes, and snippets.

View ehaynes99's full-sized avatar

Eric Haynes ehaynes99

View GitHub Profile
import { sortBy, pick } from 'lodash';
/**
* NOT A REAL IMPLEMENTATION!! This is just a high level example of how
* dynamo stores data.
*/
type Row = {
hashKey: string;
rangeKey: string;
[k: string]: any;
#!/usr/bin/env node
const { exec } = require('child_process');
const { resolve } = require('path');
const cwd = process.argv[2] ? resolve(process.argv[2]) : process.cwd();
const maxBuffer = 10 * 1024 * 1024;
const execShell = (command) => {
return new Promise((resolve) => {
exec(command, { cwd, maxBuffer }, (error, stdout, stderr) => {
type Semaphore = {
acquire: () => Promise<void>;
release: () => void;
};
export const simpleSemaphore = (size: number): Semaphore => {
const waiting: (() => void)[] = [];
let available = size;
const acquire = async (): Promise<void> => {

Workspaces Module Resolution

Originally introduced by yarn, starting with version 7 npm also provides support for this.

What is it?

Workspaces are first-class support in the package manager for monorepo structures in npm packages. A monorepo is simply a collection of related packages, and having them share a single git repo can help eliminate a lot of redundancy in the project setup, as well as make it easier to work with interdependencies during development.

What does a workspaces project look like?

They're relatively simple. They consist of:

  • a parent directory whose package.json contains a list (or wildcard pattern) defining subprojects

Critique of NestJS

Here, I am going to examine NestJS -- primarily focusing on its dependency injection --

The basics

Nest's DI system is based on a custom-defined module system. For every service defined in the application, there is a module file that "owns" that service. I use the term "service" loosely here to simply mean "anything we want to be part of the DI system". For example:

@Injectable()
@ehaynes99
ehaynes99 / docker-commands.md
Last active November 6, 2022 01:20
docker-commands.md

Nuke the world!!!!!

# kill anything running
docker kill $(docker ps -q)
docker system prune -af --volumes # aka --all --force --volumes

ssh

docker exec -it  /bin/bash
@ehaynes99
ehaynes99 / vscode-debug-current.md
Last active September 28, 2023 12:30
VSCode debugging current typescript file

Debugging TypeScript with ts-node in VSCode

These launch configs will allow you to debug typescript files directly from VSCode. It will honor the tsconfig and resolve node modules properly. You do not need to install ts-node or nodemon, as everything is run using npx. The first

Launch Config

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
@ehaynes99
ehaynes99 / stream-examples.ts
Last active October 19, 2022 15:58
node async Writable or Transform stream
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Readable, Transform, Writable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
export const asyncHandler = (handle: (value: any) => Promise<void>) => {
return new Writable({
objectMode: true,
write: async (value, _, next) => {
try {
await handle(value)