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 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
SQL ROLLUP — Subtotals and Grand Totals
`GROUP BY ROLLUP` adds subtotal rows (with NULL for the rolled-up columns) plus a grand total. Drop into reports without writing UNIONs by hand.
Rust Async/Await with tokio
`async fn` returns a future; `.await` drives it. tokio is the de-facto runtime. The `#[tokio::main]` attribute turns `main` into the runtime entry point.
Rust From / Into Conversions
Implement `From` and you get `Into` for free. Then `.into()` and `T::from(x)` both work. The single most idiomatic way to express type conversions in Rust.
Python Context Manager via @contextmanager
Build a custom context manager without writing a class — just a generator with one `yield`. The code before yield runs on enter, after yield runs on exit (even on exception).
Bash Default Value for Unset Variable
Three parameter-expansion idioms for "use this if the variable is empty / unset". Replaces the verbose `if [[ -z "$VAR" ]]; then VAR=default; fi` everywhere.
SQL Pivot Without PIVOT (Conditional Aggregation)
Most databases don't have a real `PIVOT` keyword (SQL Server does). The portable answer is conditional aggregation — `SUM(CASE WHEN ...) AS col` for each pivoted value.
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.