Skip to content

Instantly share code, notes, and snippets.

View chill-cod3r's full-sized avatar
🎯
Focusing

chill-cod3r

🎯
Focusing
View GitHub Profile
@chill-cod3r
chill-cod3r / docker-compose.yml
Created October 7, 2023 13:25
docker compose file for starting postgres and pgadmin
version: '3.8'
services:
db:
container_name: pg_container
image: postgres
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: postgres
@chill-cod3r
chill-cod3r / dynamic-import.ts
Created March 28, 2022 02:30
Hacky typescript esmodule commonjs interop dynamic import
export const dynamicImport = (packageName: string) =>
new Function(`return import('${packageName}');`)();
@chill-cod3r
chill-cod3r / cache-decorator.ts
Last active March 21, 2022 01:50
typescript decorator to cache method response - rough example
// @experimentalDecorators
// @emitDecoratorMetadata
// use a more elegant cache in prod - something like node-cache or another cache
// this is a simplified example - for simplicity after the first method call we will simply set it to true.
// We also will not implement the cache expiration for simplicity.
// also note this is for cached aggregation of data that doesn't change, not "multi-tenant" data
let cacheObject: any = null;
@chill-cod3r
chill-cod3r / strongly-typed-array-keys-appconfig.ts
Created March 8, 2022 03:07
Example of strongly typed appconfig validation with simple array of keys
const configKeys = [
"NODE_ENV",
"PORT",
"SECRET1",
"SECRET2",
"SECRET3",
"ASYNC_SECRET",
] as const;
export type AppConfig = {
@chill-cod3r
chill-cod3r / Dockerfile
Created February 25, 2021 01:12
Node.js Multi-Stage Docker Build
FROM node:12-alpine as local-dev
EXPOSE 3001
RUN mkdir -p /app
WORKDIR /app
COPY *.json ./
RUN npm install
COPY . /app
RUN npm run build
CMD ["npm", "run", "start:watch"]
@chill-cod3r
chill-cod3r / setup-typescript-eslint-prettier.js
Last active June 3, 2023 19:28
Automate TypeScript ESLint Prettier + my opinionated ESLint rules
const fs = require('fs');
const cp = require('child_process');
const util = require('util');
const path = require('path');
const exec = util.promisify(cp.exec);
const writeFile = util.promisify(fs.writeFile);
const prettierConfigVscode = {
'editor.codeActionsOnSave': {
FROM node:10-alpine AS build
# install gyp tools
# if you have an npm dependency that depends on native code
# like the redis package, you'll need these tools to compile
# that dependency
RUN apk add --update --no-cache \
python \
make \
g++