Skip to content

Instantly share code, notes, and snippets.

View ehaynes99's full-sized avatar

Eric Haynes ehaynes99

View GitHub Profile
ehaynes99 /
Created March 21, 2023 00:04
TypeBox example

Schema Definition

export const Customer = Type.Object({
  firstName: Type.String(),
  lastName: Type.String(),
  age: Type.Number(),
  dob: Type.Date(),
  address: Type.Object({
    streetAddress: Type.String(),
    city: Type.String(),
View timer.ts
import { performance } from 'perf_hooks'
export type Timer = ReturnType<typeof createTimer>
* High resolution timer. Note that Number.MAX_SAFE_INTEGER
* limits the total duration to ~104 hours.
export const createTimer = () => {
const times: number[] = []
ehaynes99 / stream-examples.ts
Last active October 19, 2022 15:58
node async Writable or Transform stream
View stream-examples.ts
/* 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)
ehaynes99 /
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 / eslintrc.json
Created June 15, 2022 05:39
View eslintrc.json
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
ehaynes99 /
Last active November 6, 2022 01:20

Nuke the world!!!!!

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


docker exec -it  /bin/bash
View vscode-nodemon-current-file.json
// Debug the currently-opened file in watch mode
// Sets `cwd` to the directory contianing the file,
// which makes it work correctly with monorepos.
// E.g. if the currently opened file is /path/to/some-file.ts, this is equivalent to
// running in the shell like:
// cd /path/to && npx -y nodemon some-file.ts
"version": "0.2.0",

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
View simple-semaphore.ts
type Semaphore = {
acquire: () => Promise<void>;
release: () => void;
export const simpleSemaphore = (size: number): Semaphore => {
const waiting: (() => void)[] = [];
let available = size;
const acquire = async (): Promise<void> => {