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
JavaScript Cookie Helpers (Get / Set / Delete)
Minimal cookie utilities: getCookie retrieves a value by name, setCookie writes a cookie with optional expiry days and path, deleteCookie removes it by setting an expired date. No library needed for simple first-party cookie management. For complex scenarios (SameSite, Secure, partitioned) extend the options object.
JavaScript Flatten Object (Dot Notation)
Flattens a deeply nested object into a single-level object with dot-notation keys. Useful for comparing configs, building form field names from nested data, logging structured objects to analytics, or preparing data for flat key-value stores like Redis or environment variables.
JavaScript Middleware Pipeline
A simple Koa/Express-style middleware runner for client-side use. Middleware functions receive a context object and a next() function — call next() to pass control to the next middleware or skip it to short-circuit the chain. Useful for building plugin systems, request pipelines, and composable validation logic.
JavaScript i18n Minimal Translator
A tiny internationalisation helper that loads a locale dictionary and resolves translation strings by dot-notation key. Supports variable interpolation via {{placeholder}} syntax. Falls back to the key itself when a translation is missing, keeping the UI readable during development. Swap the locale at runtime without a page reload.
JavaScript Serialize Form to Object
Converts all named form fields into a plain JavaScript object using the FormData API. Handles text inputs, selects, textareas, and checkboxes. Multiple values for the same name (e.g. multi-select, checkboxes) are collected into an array. Ready to JSON.stringify and POST to an API.
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 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 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.
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.
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.).
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 Sealed Interfaces (Kotlin 1.5+)
Like sealed classes, but for interfaces — and a class can implement multiple sealed interfaces. Cleaner state modeling when you want "this is both a Loadable and a Cacheable".
Kotlin kotlin.time — Duration and measureTime
`kotlin.time.Duration` is a typesafe time amount with friendly literal syntax (`5.seconds`, `2.minutes`). `measureTime { }` benchmarks a block.
Kotlin ViewModel + StateFlow + Compose
Standard Android pattern: ViewModel holds state in a `StateFlow`, Compose collects it as state. Survives config changes; isolates business logic from UI.
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 Custom Exception + Sealed Result Pattern
For library / service code, define your own exception hierarchy. Pair with `sealed` + `when` for type-safe error handling at the call site.
JavaScript Detect Dark Mode Preference
Reads the user's OS-level dark mode preference using the prefers-color-scheme media query and watches for live changes. Useful for initialising theme state before any user interaction and reacting automatically when the user switches their system theme without reloading the page.