Snippets I Keep Coming Back To

December 10, 2025

A collection of snippets I find myself reaching for again and again. Some are commands I always forget, others are configs I copy into every project.

I'll keep this post updated as I discover new ones worth saving.

Quick random string

sh
openssl rand -hex <n-of-bytes>

Flush DNS cache on MacOS

sh
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

I use this quite often and I often forget the command, so I put it as an alias in my fish config (works also in bash/zsh):

sh
alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"

Prettier config

This config gets copied to 90% of my JS/TS projects. I like Prettier's defaults, so the only thing I disable are semicolons.
I also like to have imports and Tailwind classes sorted to reduce git conflicts.

jsonc
{
  "$schema": "https://json.schemastore.org/prettierrc",
  "semi": false,
  "plugins": [
    "@trivago/prettier-plugin-sort-imports",
    "prettier-plugin-tailwindcss"
  ],
  "importOrder": [
    "<BUILTIN_MODULES>",
    "<THIRD_PARTY_MODULES>",
    "^#/(.*)$",
    "^@/(.*)$",
    "^~/(.*)$",
    "^[./]"
  ],
  "importOrderSortSpecifiers": true,
  # Don't forget to replace the following line 
  # with your Tailwind CSS entrypoint.
  "tailwindStylesheet": "./app/global.css",
  "tailwindFunctions": ["clsx", "cva", "cn"]
}

Postgres for development

yaml
services:
  pg:
    image: postgres:18.1
    environment: # sourced from .env
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_DATABASE}
    ports:
      - 5433:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      interval: "2s"
      retries: 20
    volumes:
      - pg:/var/lib/postgresql
    networks: # Don't forget to replace
      - your_project_network
 
volumes:
  pg:
 
networks: # Don't forget to replace
  your_project_network:

React Router Dockerfile

dockerfile
FROM node:22-alpine AS prod
##################################################
FROM prod AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN npm i -g pnpm
##################################################
FROM base AS development-dependencies
COPY ./package.json pnpm-lock.yaml /app/
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --frozen-lockfile --prefer-offline
##################################################
FROM base AS production-dependencies
COPY ./package.json pnpm-lock.yaml /app/
WORKDIR /app
ENV NODE_ENV=production
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --prod --frozen-lockfile --prefer-offline
##################################################
FROM development-dependencies AS build
ARG COMMIT_SHA
 
# Copy configuration files first (these change less frequently)
COPY ./.env.production /app/
COPY ./tsconfig.json /app/
COPY ./vite.config.ts /app/
COPY ./react-router.config.ts /app/
COPY ./drizzle.config.ts /app/
COPY ./auth-schema.ts /app/
 
# Copy source directories (order by likelihood of change)
COPY ./public /app/public
COPY ./app /app/app
 
WORKDIR /app
ENV COMMIT_SHA=${COMMIT_SHA}
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \
    export SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) && \
    pnpm build
##################################################
FROM prod
 
ARG COMMIT_SHA
 
COPY ./package.json pnpm-lock.yaml /app/
COPY --from=production-dependencies /app/node_modules /app/node_modules
COPY --from=build /app/build /app/build
 
COPY ./bin /app/bin
COPY ./drizzle /app/drizzle
COPY ./app/lib /app/app/lib
COPY ./app/.server /app/app/.server
COPY ./auth-schema.ts /app/
COPY ./bootstrap.ts /app/
 
WORKDIR /app
 
ENV TZ=UTC
ENV NODE_ENV=production
ENV COMMIT_SHA=${COMMIT_SHA}
 
ENTRYPOINT ["/app/bin/entrypoint.sh"]
 
EXPOSE 3000
 
CMD ["node", "--experimental-transform-types", "bootstrap.ts"]