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
Kotlin val vs var — Prefer Immutability
`val` is read-only (can't reassign the reference); `var` is mutable. Default to `val` everywhere — Kotlin's style guide recommends it, and a Compiler warning fires if a `var` is never reassigned.
HTML JSON-LD Structured Data (Schema.org)
JSON-LD is Google's preferred way to mark up structured data for rich search results. Drop it in a <script type="application/ld+json"> tag in <head>. Validate with Google's Rich Results Test.
PHP Minimal PSR-3 Logger
A 30-line PSR-3 compatible logger you can drop into any project that expects \Psr\Log\LoggerInterface. Writes to a file using the JSON structured format.
HTML Audio Element
`<audio>` is video's simpler sibling. Use it for podcasts, music samples, sound effects on play. Same multi-`<source>` pattern for cross-browser format support.
PHP Simple File-Backed Cache
A tiny key-value cache with TTL, persisted as a serialized PHP file per key. Good enough for memoizing expensive computations on a single machine; replace with Redis when scaling out.
HTML Main Content + Aside Sidebar
`<main>` wraps the unique-to-this-page content (screen readers jump to it with a keyboard shortcut). `<aside>` is supporting / tangential content — sidebars, callouts, related links.
Go struct Tags for JSON Marshaling
Backtick string tags on struct fields control how `encoding/json` serializes them — rename to camelCase, omit zero values, skip entirely. The same tag system is used by many other libraries.
TypeScript Generic Constraints with `extends`
Generics start unbounded — you can't access any properties of `T`. `T extends { … }` adds a constraint so the body can safely use known shape, while callers can still pass in narrower types.
Python ThreadPoolExecutor for I/O-Bound Work
Parallelize I/O-bound tasks (HTTP requests, file reads, DB queries) without writing thread management code. The default thread count is min(32, os.cpu_count() + 4) — usually the right call.
Rust tracing — Structured Logging Setup
`tracing` is the structured-logging story for async Rust — better than `log` for anything tokio-based. Drop in this initializer and use `info!`, `warn!`, `error!` macros throughout.
Bash Read Single Keystroke Without Enter
For menus and confirm prompts where you want one-key response (no need to press Enter). -n 1 reads exactly one character, -s silences the echo.
Python Retry Decorator with Exponential Backoff
Generic retry decorator: attempts × base delay, exponential ramp, random jitter. Filter retryable exceptions via the `on` tuple so logical errors aren't retried.
Go UUID Generation (google/uuid)
`github.com/google/uuid` is the standard UUID library. v4 (random) for IDs, v7 (time-ordered) when you want UUIDs that sort chronologically and play nicely with B-tree indexes.
Rust match with Guards, Ranges, and Bindings
`match` arms can have `if` guards, range patterns (`1..=5`), bindings (`x @ pattern`), and ORs (`A | B`). Combine them for very expressive dispatch.
SQL INSERT … SELECT — Bulk Copy
Copy/transform rows from a SELECT into another table — the cheapest way to move data within the database. Skip column lists at your peril; positional matching is fragile.
PHP Compound Interest Calculator
Compute the future value of an investment compounded n times per year for t years. Returns both the final value and the interest earned.
JavaScript Calculate Reading Time
Estimates the reading time of a block of text based on an average adult reading speed (default 200 words per minute). Strips HTML tags before counting to handle rich-text content. Returns the result in minutes, rounded up, so a short article always shows at least "1 min read".
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.