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 Cron Singleton with flock
Make sure only one copy of a long-running cron job runs at a time. Uses a non-blocking advisory lock on a sentinel file — second invocation exits immediately if the lock is held.
JavaScript Keyboard Shortcut Manager
Registers global keyboard shortcuts with a simple key-combo syntax ("ctrl+k", "meta+shift+p"). Handles modifier keys (ctrl, alt, shift, meta) and prevents default browser behaviour when a shortcut matches. Shortcuts can be unregistered individually or all at once, making it easy to scope shortcuts to page sections or modals.
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 Pick & Omit Object Keys
pick returns a new object containing only the specified keys. omit returns a new object with the specified keys removed. Both are pure (non-mutating) and handle missing keys gracefully. Essential for cleaning API payloads, projecting data shapes, and avoiding over-sending sensitive fields.
JavaScript UUID v4 Generator
Generates a RFC 4122 compliant version-4 UUID. Uses crypto.randomUUID() in modern environments (Node 14.17+, all modern browsers) and falls back to a Math.random()-based implementation for older runtimes. The fallback is suitable for non-security-critical IDs such as UI element keys and local correlation IDs.
SQL Recursive CTE — Date Spine Generator
Generate a row per day (or month, year, hour) without a calendar table. Useful for filling gaps when a date has no events but you still want it in your output.
SQL LEFT JOIN — Keep Unmatched Left Rows
Returns every row from the LEFT side, NULL-filled where the right side doesn't match. The standard pattern for "this entity and its optional children".
Bash Download with Progress Bar
Show a progress bar for long downloads. wget gives a great built-in bar; curl needs an explicit flag.
Kotlin Ktor Client — POST JSON with Serialization
Combine Ktor + kotlinx.serialization: register the JSON plugin, declare `@Serializable` data classes, the client (de)serializes automatically.
Go JSON API Endpoint
Decode an incoming JSON body into a typed struct, do work, encode a JSON response. The whole roundtrip is ~20 lines of standard library.
Go Custom Error Type with Fields
Implement the `error` interface (`Error() string`) on your own type to carry structured data. Pair with `errors.As` so callers can extract the fields.
Rust axum with Shared State + Extractors
Use `State` to inject shared application state (DB pool, config, etc.) into every handler. `Path` and `Json` extractors deserialize URL params and request bodies for you.
Bash Get Script's Own Directory
The "where am I" boilerplate that every nontrivial bash script needs. Resolves symlinks correctly with realpath, falls back gracefully if realpath is missing.
PHP Constant-Time String Compare
Compare two strings in constant time to avoid timing-attack leaks when checking secrets like API keys, session tokens, or HMAC signatures. Always use hash_equals — never ===.
Java HttpClient — POST JSON
POST a JSON body with `HttpRequest.BodyPublishers.ofString` + the right Content-Type. Pair with Jackson / Gson to serialize objects to JSON.
Go database/sql — Open + Query
`database/sql` is driver-agnostic — pick a driver (`pgx/stdlib`, `go-sql-driver/mysql`, `mattn/sqlite3`). Always `defer db.Close()` only on app exit; the pool is meant to be long-lived.
Rust reqwest GET + JSON Deserialize
`reqwest` is the standard HTTP client. Combined with serde, you can fetch and parse a JSON API response into a typed struct in three lines.
Bash Convert Between Timezones
Set TZ inline to print a date in a specific timezone, then read with another TZ. Avoids messing with the system timezone.