Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Rust Newtype Pattern (zero-cost wrappers)
Wrap a primitive in a tuple struct to give it a distinct type identity at the type level — without runtime cost. Replaces "is this number a UserId or a PostId?" bugs.
Bash ANSI Color Output Helpers
Wrap printf with ANSI escape codes for color and bold. Auto-disable if stdout isn't a TTY (so piping to a file doesn't pollute it with escape sequences).
TypeScript usePrevious — Track Last Render's Value
Returns the value the prop/state had on the previous render. Useful for detecting transitions (e.g. "the count just went from 0 to 1") inside effects.
PHP Validate UUID (any version)
Match the canonical 8-4-4-4-12 hex format, optionally pinning to a specific UUID version (1-5). Case-insensitive.
Bash Clean Up Merged Branches
Delete every local branch that's been merged to main. Filters out main/master and the current branch as a safety net.
Python Walk Directory Tree (Filtered)
Recursively yield every file under a directory matching a predicate. Built on pathlib.rglob; the predicate gives you precise control without listing the whole tree up front.
TypeScript Type-Safe Event Emitter
A 30-line type-safe mini EventEmitter. The event-name → payload map is enforced at compile time, so emit and on calls can't drift apart.
PHP Dump Variable to Browser (var_dump replacement)
A nicer var_dump-style dumper that wraps output in <pre> with monospaced font for browser inspection. Drop-in replacement for var_dump while debugging.
SQL CREATE TABLE with Constraints
Declare data integrity rules right in the schema — primary keys, foreign keys, unique constraints, NOT NULL, CHECK constraints, defaults. The DB enforces them so application bugs can't corrupt your data.
Go sync/atomic — Lock-Free Counter
For simple counters and flags, atomic ops are much faster than `sync.Mutex`. Go 1.19+ added typed wrappers (`atomic.Int64`) — clearer than the raw functions.
Go errors.Join — Aggregate Multiple Errors
Go 1.20+ ships `errors.Join`, which combines multiple errors into one. Stop accumulating errors in a slice and stringifying yourself — use the standard library.
Bash docker exec — Drop Into Running Container
`docker exec` is your debugger. Get a shell, inspect env, tail logs, run one-off commands inside a live container.
Bash Rotate Logs Manually
If a service doesn't hook into logrotate, you can still rotate a log file yourself in one safe pattern: rename current → .1, truncate the original, signal the process to re-open if needed.
Bash Disk Space Alert
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
Bash Check Command Exists Before Using It
`command -v` is the portable, fast way to check whether a binary is on $PATH. Avoid `which` (its behavior varies between systems).
Bash Sort an Array
Bash itself doesn't sort arrays — you pipe through `sort`. readarray captures the sorted output back into an array, preserving each element verbatim (including spaces).
TypeScript Conditional Types Basics
`T extends U ? X : Y` lets types branch on shape. Combine with `infer` to extract pieces of complex types — the building block under `ReturnType`, `Parameters`, and most utility libraries.
Go Signal Handling with signal.NotifyContext
Go 1.16+ `signal.NotifyContext` returns a context that's canceled on the listed signals. Cleaner than the legacy `signal.Notify(channel)` dance for graceful shutdown.