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

Showing 571–600 of 770 public snippets

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.
52m ago 0
PHP
Safe Path Join
Concatenate path segments and produce a normalized canonical path that resists "../" escape attempts. Throws if the result would land outside the given base directory.
52m ago 0
PHP
Build WHERE IN with Placeholders
Safely interpolate a variable-length list into a "WHERE col IN (...)" clause. Returns the SQL fragment plus the bound parameters — never concatenate user values into SQL.
52m ago 0
TypeScript
groupBy (with key callback)
Group a list into a record keyed by whatever the callback returns. Like Lodash _.groupBy or the new Object.groupBy in modern runtimes. Generic enough to handle string, number, or symbol keys.
52m ago 0
Python
Bulk Insert with executemany
Insert many rows in one round-trip using executemany. Orders-of-magnitude faster than a loop of single inserts — and the driver handles batching/parametrization for you.
52m ago 0
Bash
Encrypt / Decrypt File with openssl
Symmetric AES-256-GCM encryption of arbitrary files. Use PBKDF2 + a password (good for backups) or pass an explicit key.
52m ago 0
Go
Fan-Out / Fan-In
Distribute work across N workers (fan-out), then merge their results back into one channel (fan-in). Used when you can't process items strictly in order but want to retain output as one stream.
52m ago 0
Go
database/sql — Transaction Helper
Wrap your transaction in a function that commits on success and rolls back on error or panic. Drop-in: pass any `func(*sql.Tx) error` and forget about manual cleanup.
52m ago 0
Java
HttpClient — Synchronous GET (Java 11+)
`java.net.http.HttpClient` ships in the JDK — no Apache HttpClient or OkHttp needed for most cases. Reuse one client across the app; configure timeouts and follow-redirects up front.
52m ago 0
SQL
JSONB Columns (PostgreSQL)
`jsonb` stores binary-optimized JSON. Index sub-fields with GIN for fast containment queries. Most-used operators: `->` (get field), `->>` (get as text), `@>` (contains), `?` (key exists).
52m ago 0
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.
52m ago 0
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.
52m ago 0
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.
52m ago 0
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.
52m ago 0
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.
52m ago 0
PHP
Validate Uploaded File
A defense-in-depth check for $_FILES uploads: confirms the upload completed, the size is within bounds, the MIME type matches an allow-list (by libmagic, not by extension), and the file landed where PHP expected.
52m ago 0
PHP
Encrypt / Decrypt with libsodium
Symmetric AEAD encryption using the libsodium "secretbox" (XSalsa20-Poly1305). Built into PHP since 7.2 — no extension needed. Returns base64 ciphertext with the nonce prepended.
52m ago 0
PHP
Set Cookie with Modern Options
PHP 7.3+ accepts an options array on setcookie() — use it. Sets HttpOnly, Secure on HTTPS, SameSite=Lax by default, and a sensible expiry.
52m ago 0
PHP
Get Nested Value by Dot Path
Read deeply-nested array values like Lodash _.get(). Use a "a.b.c" string instead of nested isset checks; returns a default on any missing segment.
52m ago 0
TypeScript
partition — Split by Predicate
Split an array into [pass, fail] in a single pass. Type guard overload lets the truthy bucket get a narrowed type when you pass a `x is T` predicate.
52m ago 0
Python
Sliding Window Iterator
Iterate over an iterable with a rolling window of N items. itertools.batched (Python 3.12+) gives you NON-overlapping chunks; this helper gives overlapping ones, common for moving averages or n-gram analysis.
52m ago 0
Python
pathlib Quick Reference
Forget os.path.* — pathlib.Path is the modern, OS-aware way to work with paths. Operator overloading for joins, attribute access for components, methods for reads/writes/iterations.
52m ago 0
Bash
Days Between Two Dates
Convert both dates to epoch seconds, subtract, divide. Works for hours/minutes too with the obvious divisor.
52m ago 0
Bash
HMAC-SHA256 with openssl
Sign a payload with a shared secret for webhook verification (Stripe, GitHub, etc.). openssl reads the input from stdin or -in.
52m ago 0
Rust
Walk a Directory Tree
`walkdir` recursively iterates every entry under a path, skipping inaccessible directories cleanly. The standard-library alternative requires manual recursion.
52m ago 0
Go
JSON Marshal / Unmarshal
`encoding/json` is the standard library JSON parser. `Marshal` produces compact JSON; `MarshalIndent` produces pretty-printed. `Unmarshal` decodes into a typed value (struct, map, or any).
52m ago 0
Go
Goroutine Leak Prevention
A goroutine that's blocked forever on a channel send/receive leaks — it's never garbage-collected. Always pair channels with `select { case <-ctx.Done(): return }` to give them an exit path.
52m ago 0
Kotlin
Exposed — Kotlin-First ORM
JetBrains' Exposed combines a SQL DSL with a lightweight ORM. Either style is fully type-safe; both compile to plain SQL.
52m ago 0
Bash
Download with Progress Bar
Show a progress bar for long downloads. wget gives a great built-in bar; curl needs an explicit flag.
52m ago 0
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".
52m ago 0