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 Group Array by Key
Groups an array of objects into a map keyed by the result of a callback or property name. Uses Object.groupBy when available (ES2024) and falls back to a reduce implementation. Returns an object whose keys are the group names and values are arrays of matching items.
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.
JavaScript Deep Equal Comparison
Performs a recursive structural equality check between two values. Handles primitives, arrays, objects, Dates, Maps, Sets, null, and undefined. Faster than JSON.stringify comparison (which ignores undefined and Map/Set), and avoids the false-positive trap of == or Object.is for nested structures.
JavaScript Generate Initials Avatar (Canvas)
Draws a coloured circular avatar with up to two initials on an HTML5 Canvas and returns it as a data URL. Generates a consistent background colour from the name string so the same user always gets the same colour. Useful as a fallback when a user has no profile photo.
JavaScript Parse URL Query String
Parses a URL query string into a plain key-value object. Uses the built-in URLSearchParams API — no regex required. Handles duplicate keys (returns the first value), percent-encoded characters, and works with both full URLs and raw query strings. Pairs nicely with buildQueryString.
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.
JavaScript Deep Clone Object
Creates a true deep copy of any serialisable object or array — nested objects, arrays, dates (as ISO strings). Uses structuredClone when available (modern browsers/Node 17+) and falls back to JSON round-trip for older environments. Does not handle functions, undefined, or circular references.
JavaScript Truncate String
Truncates a string to a maximum character length and appends an ellipsis (or custom suffix). The smart version breaks at the last word boundary to avoid cutting in the middle of a word, making truncated text look natural in card previews, notifications, and list views.
JavaScript Hex ↔ RGB Conversion
Converts between hex colour strings (#rrggbb / #rgb) and RGB component objects. hexToRgb parses both shorthand and full hex formats. rgbToHex converts R, G, B integers (0–255) back to a hex string. Handy for colour manipulation, generating CSS variables, and passing colour data between libraries.
Rust if let / while let
When you only care about one variant, `if let` is shorter than `match`. `while let` keeps looping as long as the pattern matches — great for draining iterators or option-returning APIs.
SQL ALTER TABLE — Add / Drop / Rename Column
Evolve your schema in place. Most DBs run these as cheap metadata-only operations IF you avoid expensive rewrites — e.g. don't set a NOT NULL default on a huge table without thinking.
Bash Check URL Returns 200
Quick health-check helper: returns 0 if a URL responds with a 2xx status, non-zero otherwise. Use in pre-deploy smoke tests.
Bash Uppercase / Lowercase / Title Case
Bash 4+ has built-in case conversion via parameter expansion. No need for `tr` or `awk` for most cases.
Rust Concurrency Limit with Semaphore
Fan out N tasks but limit how many run at once via `tokio::sync::Semaphore`. Standard pattern for HTTP fan-out where you must respect a server's rate limit.
Bash Find Commit That Introduced a String
`git log -S` (the "pickaxe") finds commits whose diff added or removed a given string. The fastest way to answer "when did this line first appear?"
Bash flock — Cron-Singleton Lock
Prevent two copies of a cron job from running simultaneously. flock takes an FD to a lock file; if the lock is held, the second invocation exits immediately.
PHP Haversine Distance Between Two Coordinates
Compute the great-circle distance between two latitude/longitude points using the haversine formula. Returns kilometers; multiply by 0.621 for miles. Useful for "stores near me" features.
PHP Discord Webhook Notification
Same idea as Slack but for Discord webhooks — supports rich embeds with a title, description, and color. Useful for dev/ops dashboards or bot integrations.