Code Snippets
Small, ready-to-use pieces of code I keep coming back to — across languages and frameworks.
This is a personal, hand-picked library of short code snippets — utility functions and patterns Alex Rel reuses across projects, organized by language and searchable by keyword.
React context + useReducer for global state
Replace a state management library with Context and useReducer — a predictable, testable global state pattern without external dependencies.
React useMediaQuery — responsive hook
Track CSS media queries in React components — detect breakpoints, render different UI for mobile/tablet/desktop, and react to orientation changes.
Tailwind CSS animations — keyframes and transition
Craft custom animations with Tailwind's `animate-*` utilities and `@keyframes` — from micro-interactions to full page transitions — without leaving your config.
Tailwind CSS custom theme with CSS variables
Extend Tailwind's default theme with custom colors, fonts, spacing, and breakpoints — all driven by CSS variables for runtime theme switching.
Tailwind CSS dark mode with class strategy
Toggle dark mode on demand instead of relying on system preferences — the class strategy lets users switch themes with a button, persisted in localStorage or cookie.
Prisma migrations — create, apply, and roll back
Manage database schema changes with Prisma Migrate — create migrations from schema changes, apply them to production, and handle drift.
Prisma pagination — cursor and offset
Efficiently paginate large datasets with Prisma — offset pagination for simple lists, cursor-based pagination for infinite scroll and real-time feeds.
Prisma CRUD — create, read, update, delete
The four basic data operations with Prisma Client — create a user, find by email, update profile, and delete an account — all fully typed.
Nginx WebSocket proxy for real-time apps
Proxy WebSocket connections through nginx — required for Socket.io, live chat, and collaborative editing behind a reverse proxy.
Nginx load balancing between Node.js instances
Distribute traffic across multiple Node.js backend instances with round-robin, health checks, and passive failover — no application changes needed.
Nginx static file server with caching
Serve static assets (CSS, JS, images) with far-future cache headers, gzip compression, and directory index — no app server needed.
GitHub Actions — scheduled tasks with cron
Run workflows on a schedule — daily backups, weekly dependency updates, or hourly health checks — using cron syntax.
GitHub Actions — build and push Docker image to registry
Automatically build and push a Docker image to Docker Hub or GitHub Container Registry on every push to main — with layer caching.
GitHub Actions — CI pipeline for PRs
Run linting, type-checking, and tests on every pull request before merge — fail fast with clear annotations on the PR.
Git log — filtering and formatting commit history
Search, filter, and format your Git log — find commits by author, date, file, or content with a readable one-line output.
Git cherry-pick and bisect — target specific commits
Cherry-pick applies a specific commit from any branch to your current branch. Bisect performs a binary search through history to find the commit that introduced a bug.
Git stash — save and restore work in progress
Temporarily save uncommitted changes with git stash — switch branches, pull updates, and restore your work later without losing anything.
Docker security — non-root user and read-only filesystem
Harden your containers by running as a non-root user with a read-only root filesystem and dropped kernel capabilities.
Contact Information
Submit a request or write to me directly on Telegram. I'll reply within 24 hours.