SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
481–510
of
770
public snippets
Go
Generic Function with Type Parameters
Go 1.18+ generics. `[T any]` is unconstrained; `[T comparable]` allows == and !=; custom constraints work too. The compiler infers T from arguments.
1h ago
0
SQL
Pattern Matching — LIKE / ILIKE / SIMILAR
`LIKE` uses `%` (any string) and `_` (single char). PostgreSQL `ILIKE` is case-insensitive. For real regex, reach for `SIMILAR TO` (POSIX) or `~` (PostgreSQL).
1h ago
0
SQL
Pagination with LIMIT / OFFSET
`LIMIT N OFFSET M` is universal — but degrades on deep pages (the DB still has to scan past M rows). Keyset (cursor) pagination is much faster for huge tables.
1h ago
0
HTML
Login Form (with autocomplete hints)
A complete login form with the autocomplete attributes that browsers + password managers depend on. Missing these causes 1Password, Bitwarden, and Chrome to mis-detect the form.
1h ago
0
JavaScript
Curry Function
Transforms a multi-argument function into a chain of single-argument functions. Each call returns a new function until all arguments are supplied, then the original function executes. Enables partial application and cleaner function composition pipelines.
1h ago
0
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.
1h ago
0
PHP
UPSERT (INSERT ... ON DUPLICATE KEY UPDATE)
A MySQL upsert helper: insert a row, or if a unique key collides, update the same row with the new values. Returns whether the row was inserted (true) or updated (false).
1h ago
0
TypeScript
Format Relative Time ("3 days ago")
Use the built-in Intl.RelativeTimeFormat to render "3 days ago" / "in 5 hours". Localized for free — pass any BCP 47 locale. No date library needed.
1h ago
0
Bash
Array Basics (index + iterate)
Bash 4+ arrays — declare, access by index, get all elements with [@], length with #. The quoting matters: "${arr[@]}" preserves each element; ${arr[@]} word-splits.
1h ago
0
Java
Generic Method + Bounded Type Parameters
A method can have its own type parameter independent of the class. `<T extends Comparable<T>>` constrains T to types that can be compared.
1h ago
0
HTML
Search Form with Accessible Label
A search input usually has a visible-only icon — but screen readers need a real label. Pair a visually-hidden `<label>` with the icon, OR use `aria-label` on the input.
1h ago
0
Kotlin
Path Operations with java.nio.file
Modern Kotlin code uses `java.nio.file.Path` over the legacy `File`. Operator overloads + Kotlin extensions make it ergonomic.
1h ago
0
JavaScript
Deep Merge Objects
Recursively merges two or more objects, combining nested properties rather than overwriting them. Unlike Object.assign or spread, this preserves deep keys from all sources. Useful for merging configuration objects, default settings with user overrides, and API response patching.
1h ago
0
JavaScript
Pipe & Compose
pipe applies a list of functions left-to-right (first function runs first), while compose applies them right-to-left. Both pass the result of each step as input to the next. Fundamental building blocks for functional programming in JavaScript — build data transformation pipelines without intermediate variables.
1h ago
0
PHP
Auto-Reconnect on "MySQL has gone away"
Long-running daemons sometimes lose their MySQL connection mid-run. Wrap your DB calls to retry once after a transient connection-lost error.
1h ago
0
PHP
Verify a JWT (HS256)
Pair to jwtSign: verify the signature, check the exp claim, and return the decoded payload — or null on any failure. Uses hash_equals for constant-time signature comparison.
1h ago
0
Python
requests Session with Retry + Timeouts
A pre-configured requests.Session that auto-retries 5xx + connect errors with exponential backoff, applies a default timeout, and uses connection pooling. Use this everywhere instead of bare requests.get().
1h ago
0
Rust
Format Strings (println! / write!)
Rust's format macros take an inline format string with `{}` placeholders. Named arguments, alignment, precision, debug formatting — all in the format spec.
1h ago
0
Rust
Builder Pattern with Method Chaining
Construct complex objects step-by-step with `self`-returning methods. Type-state can enforce required vs. optional fields at compile time — but the simple version is plenty for most cases.
1h ago
0
SQL
Median with PERCENTILE_CONT
SQL has no `MEDIAN()` — use `PERCENTILE_CONT(0.5) WITHIN GROUP`. The same function gets you P95, P99, quartiles, etc. for latency analysis.
1h ago
0
SQL
Correlated Subquery
A subquery that references the outer query's row. Slower than a JOIN for big result sets but sometimes the most readable expression.
1h ago
0
JavaScript
Validate Email Address
Validates an email address using a battle-tested regex that covers the vast majority of real-world addresses without being overly strict. For server-side code, pair this with a confirmation email step — client-side regex alone is not a security measure. Returns a boolean for easy conditional use.
1h ago
0
PHP
UTF-8 Safe substr / strlen
Wrap mb_* with sensible defaults so you stop accidentally chopping multi-byte characters in half. Defensive helpers for projects where input is not guaranteed ASCII.
1h ago
0
PHP
Simple File-Backed Cache
A tiny key-value cache with TTL, persisted as a serialized PHP file per key. Good enough for memoizing expensive computations on a single machine; replace with Redis when scaling out.
1h ago
0
PHP
Format Money with Currency
Format an amount of cents as a localized currency string using NumberFormatter from intl. Falls back to a basic sprintf if intl isn't available.
1h ago
0
TypeScript
Concurrency Limiter (semaphore)
Run an array of async tasks but limit concurrency to N at a time — like p-limit, in 30 lines. Preserves input order in the output array.
1h ago
0
Bash
Pretty-Print JSON from cURL
Pipe API responses through jq for syntax-colored, indented output. Also great for extracting specific fields without writing a parser.
1h ago
0
Go
Graceful HTTP Shutdown
On SIGINT/SIGTERM, stop accepting new connections but let in-flight requests finish. The `http.Server.Shutdown` method does exactly that — with a deadline.
1h ago
0
Java
Collectors.groupingBy — Group by Key
Like SQL GROUP BY for streams. Produces a `Map<K, List<V>>` (or any downstream collector you specify). Indispensable for analytics-style aggregations.
1h ago
0
Java
Path Operations — Resolve, Relativize, Normalize
`Path` (NIO) replaces `File` for new code. Operator-like methods compose paths cleanly across OSes — and the underlying file isn't touched until you do I/O.
1h ago
0
1
…
15
16
17
18
19
…
26