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
PHP Parse Link Header for Pagination
Parse the standard HTTP Link header (RFC 5988) into a relation → URL map. Lets you follow rel="next" pagination in APIs like GitHub without manually building URLs.
Java Jackson — Annotations (rename, ignore, etc)
Field-level annotations let you map between snake_case JSON and camelCase Java, skip nulls, never serialize secrets, set defaults on missing fields.
Go strings.Builder — Efficient Concatenation
Building strings with `+` allocates O(n²) memory. `strings.Builder` writes to an internal buffer with a single final allocation — orders of magnitude faster in loops.
HTML Time Element with datetime Attribute
`<time datetime="...">` lets you display a human-friendly date while giving machines an ISO-8601 timestamp. Used by browsers, Schema.org parsers, and screen readers.
Java Singleton via enum
`enum` with a single value is the simplest correct singleton implementation: lazy, thread-safe, serialization-safe, reflection-safe. Joshua Bloch's recommendation in Effective Java.
TypeScript Date Range Generator
Yield each day (or step) between two dates as a Date object. Generator-based so consumers can `break` early without computing the whole range.
PHP Format Duration in Seconds
Render a number of seconds as a human-friendly duration like "1h 23m 45s" — automatically trimming leading zero units. Handy for elapsed-time displays in dashboards.
HTML Open Graph + Twitter Card Tags
How your page renders when shared to Facebook, LinkedIn, Slack, Discord, X. Every public page needs these — they dramatically improve click-through on shares.
Bash Wait For Service With Timeout
Block until a TCP port accepts connections, with a deadline. Used everywhere in docker-compose entrypoints — wait for the DB to be ready before running the app.
Rust mpsc Channel Between Threads
`std::sync::mpsc` is the standard cross-thread channel. Multiple producers, single consumer. Send any `Send` type; the receiver blocks on `recv()` until something arrives.
PHP Measure Code Block Execution Time
Time a closure with microsecond precision and return both its result and the elapsed milliseconds. Great for quick perf experiments without pulling in a profiler.
Kotlin Room — Android Database
Room is the official Android persistence library — annotation-driven, compile-time SQL verification, coroutine + Flow integration out of the box.
Rust tokio::spawn — Independent Tasks
`spawn` runs a future on the runtime as an independent task — fire-and-forget, or `.await` the returned `JoinHandle` to get its result. Equivalent to threads but multiplexed onto the worker pool.
Go database/sql — Open + Query
`database/sql` is driver-agnostic — pick a driver (`pgx/stdlib`, `go-sql-driver/mysql`, `mattn/sqlite3`). Always `defer db.Close()` only on app exit; the pool is meant to be long-lived.
Bash Cron Entry From Script
Append a cron job idempotently — grep first to avoid duplicates on re-run. Doesn't require editing files manually.
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.
Kotlin reified Type Parameters
In an `inline` function, a `reified` type parameter survives erasure — you can use `T::class`, `is T`, `as T` at runtime. The killer use-case for JSON parsers ("give me a List<User>").
Bash Detect Whether Running as Root
Several scripts must run as root (or refuse to). EUID is more reliable than `whoami == root` because sudo without -E may change one but not the other.