admin
@admin ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes

Showing 511–540 of 770 public snippets

SQL
INNER JOIN — Match Rows in Both Tables
Returns rows where the join condition matches in BOTH tables. The default JOIN. Use table aliases (`u`, `o`) for readability when joining 3+ tables.
1h ago 0
SQL
Soft Delete with Partial Index
Set a `deleted_at` timestamp instead of physically removing rows — preserves history and lets you "undelete". Pair with a partial index for fast queries that skip the soft-deleted rows.
1h ago 0
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.
1h ago 0
PHP
Safe JSON Decode (no exceptions)
Wrap json_decode so invalid input gives you a clear false rather than a silent null. PHP 7.3+ JSON_THROW_ON_ERROR makes this cleaner — but the wrapper preserves a simple bool API.
1h ago 0
TypeScript
Format Duration in ms
Render a number of milliseconds as a human-friendly duration: "1h 23m 45s". Skips leading-zero units automatically so short durations are concise.
1h ago 0
Python
Word-Safe Truncate
Cap a string at `max_len` chars without splitting a word; append an ellipsis when truncated. Backs off to the last space if cutting mid-word would happen.
1h ago 0
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.
1h ago 0
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.
1h ago 0
Go
Crypto-Random Bytes + Hex/Base64
`crypto/rand` is the cryptographic CSPRNG. Use it for tokens, session IDs, API keys, password salts — anywhere `math/rand` would be a security bug.
1h ago 0
SQL
WITH Clause — Common Table Expressions
Name a subquery so you can refer to it like a table. Improves readability for complex multi-stage queries — and lets you reuse the same logical block multiple times.
1h ago 0
Kotlin
kotlinx.serialization — JSON Basics
Compile-time code generation for JSON serialization. Annotate `@Serializable` on a data class; `Json.encodeToString` and `Json.decodeFromString` are typed.
1h ago 0
JavaScript
Format Currency
Formats a number as a locale-aware currency string using the built-in Intl.NumberFormat API. Supports any ISO 4217 currency code and any BCP 47 locale tag. No external library required — handles symbol placement, thousands separators, and decimal places automatically per locale rules.
1h ago 0
JavaScript
Simple State Machine
A lightweight finite state machine that defines valid states and allowed transitions between them. Attempting an invalid transition throws an error. Supports entry/exit hooks per state for side effects. Useful for modelling UI flows (idle → loading → success/error), auth states, and multi-step forms.
1h ago 0
JavaScript
Download File from Client
Programmatically triggers a file download from a Blob, File object, or plain text/JSON string without a server round-trip. Creates a temporary anchor element with a download attribute and revokes the object URL after use to prevent memory leaks. Supports custom filenames and MIME types.
1h ago 0
PHP
Email Address Obfuscator
Render an email address as HTML that is human-readable but resistant to naive scraping bots. Uses entity encoding and an optional Caesar-style ROT for the mailto link.
1h ago 0
PHP
Recursively Delete Directory
Remove a directory and everything under it. Defensive against symlinks (unlinks the symlink rather than recursing into it). Returns the count of items removed.
1h ago 0
Bash
Format Date Like a Pro
`date` accepts a format string + optional override of the date being formatted. The +%FT%TZ form gives you ISO-8601 / RFC-3339 in one call.
1h ago 0
Bash
Hash File (SHA-256)
Compute and verify file checksums for downloads, backups, and integrity audits. sha256sum on Linux; shasum -a 256 on macOS.
1h ago 0
Java
Text Blocks (Java 15+)
Multi-line string literals with proper indentation handling. Stop concatenating newlines by hand. The compiler removes the common leading whitespace automatically.
1h ago 0
Java
Wildcards — extends vs super (PECS)
Producer-Extends, Consumer-Super. `? extends T` is read-only (you can take items OUT). `? super T` is write-only (you can put items IN). Lets generic APIs accept a wider range of types.
1h ago 0
Kotlin
OkHttp Client (Java interop)
OkHttp is the JVM-standard HTTP library. Works fine from Kotlin; use the `await()` extension from `okhttp3.coroutines` to get suspend support.
1h ago 0
JavaScript
Event Emitter (Pub/Sub)
A lightweight publish/subscribe event system. Listeners register with on(), fire once with once(), are removed with off(), and events are dispatched with emit(). Useful for decoupling modules, building plugin systems, and implementing the Observer pattern without a framework dependency.
1h ago 0
JavaScript
Delegate Event Listener
Attaches a single event listener to a parent element and handles events from matching descendant elements via event delegation. More efficient than attaching listeners to many individual elements, and works for elements added dynamically to the DOM after the listener is registered.
1h ago 0
PHP
Pretty-Print JSON
One-liner wrapper around json_encode with the right flags: indented, no escaped slashes, no escaped unicode. Use it everywhere instead of raw json_encode for human-readable output.
1h ago 0
TypeScript
Throttle (leading-edge, typed)
Pair to debounce: fire on the first call, then ignore further calls for `interval` ms. Useful for rate-limiting scroll handlers or button clicks.
1h ago 0
TypeScript
Shuffle (Fisher-Yates)
Uniformly shuffle an array in place using the modern Fisher-Yates algorithm. Returns the same array for chaining. Use crypto.getRandomValues for cryptographic uses.
1h ago 0
TypeScript
Crypto-Strong Random Password
Generate a strong random password in browser or modern Node. Uses crypto.getRandomValues with rejection sampling for an unbiased distribution.
1h ago 0
Python
Password Hashing with hashlib.scrypt
Hash a password with the stdlib scrypt (memory-hard, slow by design — resistant to GPU/ASIC attacks). Stores salt + parameters inline so verification doesn't need a separate config.
1h ago 0
Bash
Extract JSON Field with jq
jq is the de-facto JSON tool. Pipe any JSON in, get a parsed/filtered/reshaped result out. Indispensable in deploy scripts that consume API output.
1h ago 0
Bash
Add / Subtract Time from Date
GNU date accepts natural-language deltas: "+1 day", "-3 weeks", "now + 2 hours". Combine with -d to compute against any reference date.
1h ago 0