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
Kotlin
windowed and chunked
`chunked(n)` splits a list into NON-overlapping pieces of size n. `windowed(n)` slides a fixed-size window across — overlapping. Useful for moving averages, n-grams, batch APIs.
4h ago
0
TypeScript
range — Lazy Number Iterator
A generator-based numeric range: `[start, end)` with an optional step. Lazy so it doesn't allocate a huge array up front; consume with for…of or Array.from.
4h ago
0
Go
Pipeline (channel chain)
A pipeline is a chain of stages connected by channels — each stage runs in its own goroutine. Classic Go pattern for streaming transformations with backpressure built in.
4h ago
0
SQL
Generated / Computed Columns
A column whose value is derived from other columns and maintained automatically. PostgreSQL has STORED (persisted) and MySQL adds VIRTUAL (computed on read). Saves you from triggers for derived data.
4h ago
0
PHP
Unique by Callback
Like array_unique, but the uniqueness test is a callback that returns the key to dedupe by. Useful for "unique by ID" or "unique by lowercased email" across arrays of objects/rows.
4h ago
0
Java
Immutable Collections — List.of / Map.of
Java 9+ static factory methods return immutable collections with no nulls allowed. Concise, fast, and safer to share across threads or APIs than mutable equivalents.
4h ago
0
SQL
date_trunc — Bucket Times into Hours/Days/Weeks
`date_trunc('day', ts)` rounds a timestamp down to the start of the day. Use for time-series GROUP BYs — daily/weekly/hourly buckets without messy arithmetic.
4h ago
0
HTML
Textarea with Character Counter
Combine `maxlength` (hard cap) with a small JS-driven live counter. Browsers won't let users paste past `maxlength`, so this is purely UX feedback.
4h ago
0
HTML
File Upload (single, multiple, drag-and-drop)
`accept`, `multiple`, and `capture` give you a lot of polish without any JavaScript. Wrap the input in a styled label for a custom-looking drop zone.
4h ago
0
PHP
Chunk Array With Preserved Keys
Slice an array into chunks of a given size while preserving the original keys in each chunk. Useful for paginating ordered datasets without losing the row IDs.
4h ago
0
SQL
GROUP BY — Aggregation Basics
`GROUP BY` collapses rows into buckets; the SELECT list must be aggregates OR grouped columns. The most common reporting pattern in SQL.
4h ago
0
PHP
Detect MIME Type via Magic Bytes
Use PHP's built-in finfo (libmagic) to detect a file's true MIME type from its bytes — not from the extension, which can be lied about. Critical for validating user uploads.
4h ago
0
SQL
Transactions and Isolation Levels
Wrap related changes in a transaction so they commit or roll back together. Isolation levels trade consistency for concurrency — pick the weakest one that meets your correctness needs.
4h ago
0
PHP
Parse Query String Without Mangling
PHP's parse_str converts dots/spaces in keys to underscores. This alternative preserves them — important when parsing third-party query strings (e.g., webhook payloads).
4h ago
0
Kotlin
Immutable vs Mutable Collections
`listOf` / `setOf` / `mapOf` build READ-ONLY views; `mutableListOf` / `mutableSetOf` / `mutableMapOf` are mutable. Default to immutable — the call site is a contract about intent.
4h ago
0
Kotlin
flatMap and Flattening
`flatMap` maps each item to a collection, then concatenates. Use it when "for each X, produce N Y's, collect all Y's". `flatten()` is the no-mapping version.
4h ago
0
Go
Generic Result / Option Type
Go doesn't have built-in Result types, but generics make them ergonomic. Combine with `errors.Is` and you have type-safe railroaded error handling.
4h ago
0
Go
HTTP Middleware (Decorator Pattern)
Middleware in Go is `func(http.Handler) http.Handler`. Wrap a handler with logging, auth, recovery, CORS, or rate limiting — chain them together for a real middleware stack.
4h ago
0
Kotlin
Channel — Coroutine Communication
A `Channel<T>` is a coroutine-safe queue — producer side sends, consumer side receives. Bounded buffer applies backpressure. Use Flow when broadcasting; use Channel for hand-off between coroutines.
4h ago
0
Python
Result / Either with Generics
Encode "this might fail" in the type signature instead of throwing. Python 3.12+ generics syntax keeps it compact. Forces the caller to handle the failure branch.
4h ago
0
JavaScript
IndexedDB Wrapper
A Promise-based wrapper for the IndexedDB API — simplifies the verbose request/onsuccess/onerror pattern into clean async/await calls. Supports get, set, delete, and getAll operations on a named object store. Ideal for storing large client-side datasets, offline data, and blobs that exceed localStorage limits.
4h ago
0
PHP
JSON Lines (NDJSON) Stream Reader
Read newline-delimited JSON (one object per line) as a generator. Each yield gives you the next decoded record without holding the whole file in memory.
4h ago
0
TypeScript
Promise.allSettled — Typed Results
`Promise.all` rejects on the first failure; `allSettled` waits for every promise and gives you per-promise status. Pair with a type guard to split fulfilled from rejected.
4h ago
0
Python
unique_everseen — Order-Preserving Dedupe
Remove duplicates while preserving original order (set() loses order on collisions). Optional key function lets you dedupe by a derived value — e.g., lowercased email.
4h ago
0
Python
AES-GCM Encrypt / Decrypt (cryptography)
Authenticated symmetric encryption using AES-256-GCM from the `cryptography` package. Stores nonce + ciphertext + tag together as base64 so storage is a single column.
4h ago
0
Go
text/template — Simple Templating
Stdlib templating with `{{.Field}}` placeholders, range loops, if/else, and function pipelines. Safe alternative for non-HTML text (e.g. emails, config files).
4h ago
0
Java
Collectors.partitioningBy — Split by Predicate
Special case of groupingBy when the key is boolean — returns a `Map<Boolean, List<T>>` for the "true" and "false" buckets. Slightly more efficient than groupingBy.
4h ago
0
HTML
ARIA Live Region for Dynamic Announcements
Use `aria-live` on a container so screen readers announce its content changes (toast notifications, form errors, loading states). `polite` waits for a pause; `assertive` interrupts.
4h ago
0
TypeScript
JSON POST Helper
Companion to `http<T>` — POST a JSON body and parse a JSON response, both typed. Handles the boilerplate Content-Type header and JSON serialization.
4h ago
0
Python
group_by — Group Items by a Key
A dict-returning groupby that doesn't require sorted input. Like itertools.groupby but materializes the groups so consumers can iterate them multiple times.
4h ago
0
1
…
17
18
19
20
21
…
26