Skip to content

Code Snippets

Small, ready-to-use pieces of code I keep coming back to — across languages and frameworks.

// In short

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.

Found 132 snippets
React.jsReact.js

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 #Context #useReducer #State Management
React.jsReact.js

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.

#React #Hooks #Responsive #Media Query
Tailwind CSS

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 #Animation #Keyframes #UX
Tailwind CSS

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 #Theme #Customization #Design System
Tailwind CSS

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.

#Tailwind CSS #Dark Mode #Theme #Styling
Prisma

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 #ORM #Migrations #Database
Prisma

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 #ORM #Pagination #Performance
Prisma

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.

#Prisma #ORM #CRUD #TypeScript
NginxNginx

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 #WebSocket #Proxy #Real-time
NginxNginx

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 #Load Balancing #Node.js #DevOps
NginxNginx

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.

#Nginx #Static Files #Caching #Performance
GitHub Actions

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 #Automation #DevOps
GitHub Actions

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 #Docker #CI/CD #DevOps
GitHub Actions

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.

#GitHub Actions #CI/CD #Testing #DevOps
GitGit

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 #Workflow #Debugging
GitGit

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 #Workflow #Debugging
GitGit

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.

#Git #Workflow #Version Control
Docker

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.

#Docker #Security #DevOps #Production
// CONNECT

Contact Information

Submit a request or write to me directly on Telegram. I'll reply within 24 hours.