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 DOM Ready Helper
Runs a callback when the DOM is fully parsed and ready, without waiting for images or stylesheets. Works whether called before or after DOMContentLoaded has already fired — unlike a bare addEventListener which misses the event if the DOM is already ready when the script runs.
TypeScript Promise.allSettled — Typed Results
`Promise.all` rejects on the first failure; `allSettled` waits for every promise and gives you per-promise status. Pair with a type guard to split fulfilled from rejected.
JavaScript Capitalize Words (Title Case)
Converts a string to title case by capitalising the first letter of each word. Handles multiple spaces and mixed-case input. Optionally skips common English stopwords (a, an, the, of, in, …) so article/preposition words are not capitalised in the middle of a title — matching standard editorial style guides.
Python Mask Sensitive Strings (PII)
Mask the middle of a string while keeping a few chars at each end. Useful for displaying credit cards, emails, or API keys in UI / logs without leaking the whole value.
PHP Validate UUID (any version)
Match the canonical 8-4-4-4-12 hex format, optionally pinning to a specific UUID version (1-5). Case-insensitive.
SQL COALESCE / NULLIF — Null Handling
`COALESCE(a, b, c)` returns the first non-NULL value — perfect for fallbacks. `NULLIF(a, b)` returns NULL when a equals b — handy for "treat sentinel as null".
Kotlin Extension Functions
Add methods to ANY type — including stdlib types like String, List, or Int — without subclassing. Compiled as a static dispatched function, so no runtime overhead.
Kotlin Operator Overloading
Specially-named methods or extensions get operator syntax: `plus → +`, `minus → -`, `times → *`, `get → []`, `invoke → ()`, `contains → in`. Use sparingly for types that have natural arithmetic semantics.
JavaScript Unique Array Values
Returns a new array with duplicate values removed. The fast version uses a Set for primitives. The deep version supports deduplicating objects by a specific key, making it suitable for deduplicating API results or merged data sets.
Kotlin Extension Properties
Like extension functions, but as a property. Must have a custom getter (and optionally a setter) since extensions can't have backing fields. Reads like a real property at the call site.
Java Switch Expressions (Java 14+)
`switch` is now also an expression — it returns a value. Use `->` arrows for fall-through-free arms; `yield` inside `{ }` blocks for multi-statement arms. No more accidental forgotten `break`.
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".
JavaScript Base64 Encode & Decode (Unicode-safe)
Encodes and decodes strings to/from Base64. The native btoa/atob only handles Latin-1 characters, so these wrappers use TextEncoder/Uint8Array to handle the full Unicode range including emoji and CJK characters. Useful for encoding binary data, tokens, and payloads for URLs or localStorage.
TypeScript Deferred / Externally-Resolvable Promise
Create a Promise whose `resolve` and `reject` are exposed externally. Useful when you need to settle a promise from outside its executor — e.g. waiting on an event-driven response.