SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
541–570
of
770
public snippets
SQL
DELETE with JOIN / USING
Delete rows from one table conditional on a related table. PostgreSQL uses `USING`; MySQL uses join syntax in the DELETE. Run as a SELECT first to verify what you're about to remove.
1h ago
0
SQL
Array Columns (PostgreSQL)
Native array columns avoid an extra join for "small list of things per row" patterns — tags, categories, allowed_roles. Combine with GIN index for fast `@>` / `&&` operators.
1h ago
0
Kotlin
Extension Properties
Like extension functions, but as a property. Must have a custom getter (and optionally a setter) since extensions can't have backing fields. Reads like a real property at the call site.
1h ago
0
Kotlin
associate and associateBy
`associateBy` builds a `Map<K, T>` keyed by a derived value. `associateWith` keys by the items themselves with derived values. `associate` lets you build both key and value from each item.
1h ago
0
Kotlin
java.time — When You Need JVM Interop
On the JVM, `java.time` is fine — and often necessary for interop with Java APIs. Kotlin's extension methods make it ergonomic enough that you might never reach for kotlinx-datetime.
1h ago
0
JavaScript
Calculate Reading Time
Estimates the reading time of a block of text based on an average adult reading speed (default 200 words per minute). Strips HTML tags before counting to handle rich-text content. Returns the result in minutes, rounded up, so a short article always shows at least "1 min read".
1h ago
0
Python
flatten — Recursively Flatten Nested Lists
Yield every leaf from arbitrarily-nested lists/tuples. Strings are intentionally treated as atomic (we don't want to "flatten" "hi" into ["h", "i"]).
1h ago
0
Python
Walk Directory Tree (Filtered)
Recursively yield every file under a directory matching a predicate. Built on pathlib.rglob; the predicate gives you precise control without listing the whole tree up front.
1h ago
0
Bash
Associative Array (hash map)
Bash 4+ supports key-value associative arrays. Must `declare -A` first — Bash won't infer it. Iterate keys with !arr[@].
1h ago
0
Rust
CSV Read/Write with the csv Crate
`csv` + `serde` lets you read/write CSVs directly into typed structs. No manual field parsing; column order tolerant via headers.
1h ago
0
Go
sync.Once — Lazy One-Time Initialization
Run a function exactly once, even from many goroutines. Standard pattern for lazy singletons, expensive setup, and one-time configuration.
1h ago
0
Go
net/url — Build Query Strings Safely
Stop concatenating `?a=1&b=2` by hand. `url.Values` (a `map[string][]string`) escapes correctly, handles repeated keys, and `url.URL.String()` renders the canonical form.
1h ago
0
Go
iter.Seq — Range-Over-Func (Go 1.23+)
Go 1.23 added "range over func" — your own functions can produce values that work with `for v := range fn`. Cleaner than channels for in-process iteration without goroutine overhead.
1h ago
0
SQL
Recursive CTE — Walk a Hierarchy
`WITH RECURSIVE` lets a CTE refer to itself. The standard way to walk parent/child trees (org charts, comment threads, category nestings) in a single query.
1h ago
0
PHP
Pluck Column From Array of Rows
Extract a single column from a list of associative arrays into a flat list. Common transformation for SELECT results — equivalent to array_column with optional indexing key.
1h ago
0
PHP
TOTP Code Generate + Verify
Generate and verify a 6-digit time-based one-time password (RFC 6238) compatible with Google Authenticator / Authy. Uses a base32-encoded secret and 30-second time steps.
1h ago
0
PHP
PDO Connection with Sensible Defaults
Open a PDO connection with all the options you almost always want: real prepared statements, exceptions on error, associative-array fetch mode, UTF-8 charset.
1h ago
0
PHP
Number to Ordinal (1st, 2nd, 3rd)
Convert an integer to its English ordinal form ("1st", "2nd", "3rd", "11th", "22nd", "103rd"). Pure rule-based; no library needed.
1h ago
0
PHP
Compound Interest Calculator
Compute the future value of an investment compounded n times per year for t years. Returns both the final value and the interest earned.
1h ago
0
Python
Mask Sensitive Strings (PII)
Mask the middle of a string while keeping a few chars at each end. Useful for displaying credit cards, emails, or API keys in UI / logs without leaking the whole value.
1h ago
0
Rust
Option Combinators (no unwrap!)
`Option<T>` has a rich combinator API that lets you avoid both `unwrap()` and the verbose `match`. Chain `map`, `and_then`, `unwrap_or`, `or_else` to compose fallible operations.
1h ago
0
Rust
Serde — Field Rename, Skip, and Tagging
Per-field attributes let you map between Rust's snake_case and the JSON's camelCase, skip optional fields, and tag enum variants the way external APIs expect.
1h ago
0
Go
UUID Generation (google/uuid)
`github.com/google/uuid` is the standard UUID library. v4 (random) for IDs, v7 (time-ordered) when you want UUIDs that sort chronologically and play nicely with B-tree indexes.
1h ago
0
Kotlin
Smart Casts
After a successful `is` check (or null check), the compiler "smart-casts" the variable to the narrower type in that scope. No explicit cast needed.
1h ago
0
JavaScript
Format Relative Time
Returns a human-readable relative time string ("3 days ago", "in 2 hours") using the Intl.RelativeTimeFormat API. Automatically selects the most appropriate unit (seconds, minutes, hours, days, weeks, months, years) based on the elapsed time. Fully localised — pass any BCP 47 locale.
1h ago
0
JavaScript
Copy Text to Clipboard
Copies a string to the system clipboard. Uses the modern navigator.clipboard.writeText API (requires HTTPS or localhost) and falls back to the deprecated document.execCommand approach for older browsers or non-secure contexts. Returns a Promise so you can show success/error feedback.
1h ago
0
PHP
Convert Timestamp to User Timezone
Convert a stored UTC timestamp into the viewer's timezone for display. Round-trip safe: re-converting to UTC always gives back the original timestamp.
1h ago
0
Java
java.time — Format and Parse
`DateTimeFormatter` replaces `SimpleDateFormat` (which was not thread-safe). Constants for the common formats; pattern strings for custom layouts.
1h ago
0
HTML
Radio Group with Fieldset + Legend
Always wrap radio groups (and checkboxes that share semantics) in a `<fieldset>` with a `<legend>`. Screen readers announce the legend before each option — without it, the choice is contextless.
1h ago
0
Kotlin
kotlinx-datetime — Multiplatform Dates
`kotlinx-datetime` is the multiplatform date/time library — works on JVM, JS, Native. `Instant` (UTC moment), `LocalDate`, `TimeZone` are the building blocks.
1h ago
0
1
…
17
18
19
20
21
…
26