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
Bash Spinner During Long Task
Show a rotating spinner next to a status message while a background command runs. Cosmetic but vastly improves the user experience of long scripts.
Bash Check Systemd Service Is Running
`systemctl is-active` is the right tool — exit code 0 if running, non-zero otherwise. Combine with restart-on-fail for poor-man's supervision.
Bash Download with Progress Bar
Show a progress bar for long downloads. wget gives a great built-in bar; curl needs an explicit flag.
Rust Parse Strings to Typed Values
`str::parse::<T>()` works for every type that implements `FromStr` — every numeric type, `bool`, `IpAddr`, `Uuid` (with the crate), etc. Returns `Result` so you can chain with `?`.
Bash Progress Bar (basic)
Draw a single-line progress bar that updates in place. Useful for batch jobs where you know the total work count up front.
Bash Create User With Sensible Defaults
Provision a new user account with a home directory, default shell, and sudo membership. Idempotent — re-running on an existing user is a no-op.
Bash Tar Archive with Timestamp
Pack up a directory with a date-stamped filename for easy backups. -z for gzip, -j for bzip2, -J for xz (smallest, slowest).
Bash Generate a Random Password
Three approaches: pwgen (purpose-built), openssl (universally available), /dev/urandom + tr (zero deps). Pick by what's installed.
Bash Memory / CPU / Load Quick Check
One-liners for the three most-requested system metrics. Use in monitoring scripts or as ad-hoc sanity checks.
Bash Disk Space Alert
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
Kotlin Enums with Properties and Methods
Kotlin enums can carry constructor properties and define methods — including abstract methods overridden per constant. Way more expressive than Java enums.
Kotlin groupBy and partition
`groupBy` returns a `Map<Key, List<T>>` keyed by what the lambda returns. `partition` is a special-case `groupBy` for booleans — returns `(matching, nonMatching)` Pair.
Kotlin Sequences — Lazy Collections
A `List` materializes every intermediate `map`/`filter` result. A `Sequence` processes ONE element through the whole pipeline at a time — better for big inputs or short-circuiting (`first`, `take`).
Kotlin fold and scan
`fold` accumulates from a seed across all items. `runningFold` / `scan` yields every intermediate accumulator value — running totals, cumulative metrics.
Kotlin map / filter / reduce
The three classic functional combinators. Each takes a lambda and returns a new collection (or a single value for reduce). Chain freely — intermediate allocations only matter at very large scale (use `Sequence` then).
Kotlin StateFlow — Observable State
`StateFlow<T>` is a hot Flow holding a single current value. Perfect for UI state in Compose/Android — always has a value, conflates intermediate values, multi-subscriber.
TypeScript takeWhile / dropWhile
Consume or skip leading elements as long as a predicate holds. Useful for parsing prefixed sequences (e.g. all leading whitespace tokens, all unread notifications, etc.).
PHP Build & Sign a JWT (HS256)
Generate a JWT manually using only base64-url and hash_hmac — no library required. Demonstrates header/payload/signature concatenation and the exp claim.