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
Go Static File Server
`http.FileServer` serves a directory; combine with `http.StripPrefix` to mount it at a URL path. One line for the most common static-asset use case.
Go JSON Marshal / Unmarshal
`encoding/json` is the standard library JSON parser. `Marshal` produces compact JSON; `MarshalIndent` produces pretty-printed. `Unmarshal` decodes into a typed value (struct, map, or any).
Go HTTP POST JSON Body
Build a request with `http.NewRequestWithContext`, set headers, send via your client. The context plumbing is what lets callers cancel mid-request.
PHP Tail Last N Lines of File
Efficiently read the last N lines of a (possibly large) file by seeking to the end and walking backwards in fixed-size chunks. Avoids loading the entire file into memory.
Bash Pretty-Print Last Exit Code
A tiny prompt-trick that shows the previous command's exit code in red when it failed. Stops you from missing silent errors in long terminal sessions.
Java Stream.reduce — Aggregate to a Single Value
`reduce` collapses a stream to one value: sum, product, max, min, custom accumulation. Two-arg form needs an identity (zero/seed); three-arg form supports parallel streams via a combiner.
PHP Rotating Log Writer
Append to a single log file but auto-rotate to .1/.2/.3 once the file exceeds a configurable size. No external dependencies — just rename + size check.
TypeScript Retry with Exponential Backoff + Jitter
Retry an async operation up to N times, doubling the delay each attempt with random jitter to avoid thundering herd. Decide retryability via an optional predicate so 4xx errors stop immediately.
Kotlin Safe Call Chain + Elvis Default
`?.` is the safe-call operator — short-circuits to `null` at the first null in a chain. Pair with `?:` (Elvis) for "this or a default". Replaces nested if-not-null ladders.
Kotlin Nullable Types — String? and the ? Operator
Kotlin distinguishes `String` (never null) from `String?` (may be null) in the type system. The compiler refuses to compile code that could deref a possibly-null value — the famous "no more NullPointerException" feature.
Go iter.Seq — Range-Over-Func (Go 1.23+)
Go 1.23 added "range over func" — your own functions can produce values that work with `for v := range fn`. Cleaner than channels for in-process iteration without goroutine overhead.
Bash DNS Lookup (dig / host / getent)
Three options depending on what's installed: dig is most flexible, host is concise, getent uses the system's resolver and respects /etc/hosts.
Rust Read a File — Whole / Lines / Bytes
Three common patterns: load it all into memory, iterate line-by-line, or stream bytes. Pick by file size — `read_to_string` is convenient but bad for huge files.
SQL Recursive CTE — Walk a Hierarchy
`WITH RECURSIVE` lets a CTE refer to itself. The standard way to walk parent/child trees (org charts, comment threads, category nestings) in a single query.
Go net/url — Build Query Strings Safely
Stop concatenating `?a=1&b=2` by hand. `url.Values` (a `map[string][]string`) escapes correctly, handles repeated keys, and `url.URL.String()` renders the canonical form.
Kotlin with — Scope an Existing Object
`with(x) { ... }` is `run` flipped: the receiver is the first argument. Reads naturally when you're doing several things to an existing object without chaining.
HTML Video Element with Captions
`<video>` with multiple `<source>` formats (MP4 + WebM), `controls`, `poster`, and a captions track via `<track kind="captions">`. All shipped with the browser — no JS player needed.
TypeScript Environment Variable Validator
Validate process.env at boot-time and exit fast if anything's missing. The returned object is typed so the rest of the code reads `env.DATABASE_URL` instead of `process.env.DATABASE_URL!`.