Skip to content

Snippets, ready to run.

One task per page, implemented across the whole language registry — every snippet copy-ready, SQL runnable in the playground, each with a careful explanation of the when and the gotcha.

71 recipes15 languages

Files & Data19

14 languages

Append a line to a file

Add one line to an existing file without reading or rewriting it — the shape of every log, history, and queue-file write.

files →
14 languages

Check if a file or directory exists

Answer "is this path there?" before touching config, cache or lock files — and treat the answer as a hint, not a promise.

filesystem →
1 languages

Compute a running total (cumulative sum)

A running total sums every row up to and including the current one — the classic window-function job, no self-join and no subquery.

sql →
14 languages

Copy or move a file

Duplicate a file or relocate it.

files →
14 languages

Create and clean up a temp file

Create a uniquely named scratch file, use it, then delete it — the backbone of atomic-save patterns, handing work to external programs, and keeping tests from littering the filesystem.

temp-files →
13 languages

Deep clone a nested value

A shallow copy duplicates the outer container and shares everything nested — mutate a field one level down and both copies change.

clone →
14 languages

Get a file's size and modified time

Ask the filesystem for a file's size and last-modified time in a single stat call — the raw input to cache invalidation ('re-download unless the remote file is newer'), staleness banners, log-rotation checks, and directory listings.

files →
14 languages

Group a list of items by a key

Every real program groups things: orders by customer, errors by type, events by day.

group-by →
1 languages

Paginate with keyset (seek) instead of OFFSET

OFFSET pagination walks past N rows on every page — page 1000 re-reads 999 pages of data, and any insert between requests shifts rows so items repeat or vanish.

sql →
10 languages

Read a CSV file

Parse a CSV file row by row.

csv →
14 languages

Read a file line by line

Iterate a text file one line at a time without holding it in memory — the shape of every log scan and batch feed.

files →
14 languages

Read a JSON file

Read a JSON config from disk into a usable value in one step.

json →
14 languages

Read an entire file into a string

Slurp a whole file into a string in one call — the right shape for configs, templates and other small inputs, and the wrong one for multi-gigabyte logs: these calls allocate file-sized memory, sometimes twice during the byte-to-character decode, and the streaming primitive is what you want past a few dozen megabytes.

files →
14 languages

Remove duplicates from a list, keeping order

Deduplicating looks trivial — put it in a set — and that is exactly where two bugs live.

dedupe →
1 languages

Select the top N rows per group

Keep the top N rows inside every group — the top 3 earners per department, the latest order per customer.

sql →
12 languages

Sort a list of objects by a field

Sort a list of objects by a field — the everyday sort.

sort →
1 languages

Upsert a row (INSERT or UPDATE in one statement)

An upsert inserts the row if it does not exist and updates it if it does — in ONE statement, no read-then-write race.

sql →
14 languages

Walk a directory recursively

Enumerate every entry beneath a root, depth-first.

filesystem →
14 languages

Write a pretty-printed JSON file

Serialize an in-memory value to JSON with indentation a human can read — the right default for config files, fixtures, and anything headed for a diff or a code review.

json →

Text & Parsing10

12 languages

Build and parse URL query strings

Query strings look like string concatenation and punish it: values containing &, =, spaces, or non-ASCII corrupt the URL the moment you skip encoding — and hand-rolling the encoding invites the classic + vs %20 mixup.

url →
15 languages

Compare strings case-insensitively

Decide whether two strings are 'the same' ignoring case — matching user input, header names, enum values.

strings →
15 languages

Extract a substring safely (slice semantics)

Every language slices differently the moment bounds go bad: Python and JavaScript clamp out-of-range indices and never throw, while Go panics, Rust panics twice over (out of range AND non-char-boundary), and Java, Kotlin and C# throw when the start runs past the end.

string →
15 languages

Join array elements into a delimited string

Flatten a list into one delimited string — CSV lines, IN-clauses, log fields.

strings →
15 languages

Parse a key=value string into a map

Turn a 'k=v k2=v2' string — query-ish config, CLI tags, env dumps — into a lookup structure.

parsing →
15 languages

Replace all occurrences in a string

Swap every occurrence of a substring for another.

strings →
15 languages

Reverse a string (Unicode-safe)

Reverse 'café Foo' without corrupting it.

strings →
12 languages

Slugify a string (URL-safe)

Turn any title into a URL-safe slug: lowercase, fold accents, everything non-alphanumeric becomes a dash, dashes collapse and trim.

slug →
15 languages

Split a string on any whitespace

Tokenize input on any run of whitespace — spaces, tabs, newlines — rather than one literal character.

strings →
12 languages

Truncate a string without breaking characters

Truncating "to 10 characters" breaks three ways: bytes cut a multi-byte UTF-8 sequence in half, code points cut surrogate pairs apart, and neither matches what a human calls a character — flags and skin-tone emoji are single GRAPHEMES built from several code points.

truncate →

HTTP & APIs5

Crypto & Encoding5

Dates & Time3

System & CLI4

Testing & QA3

Concurrency & Parallelism3

Algorithms & Data Structures3

Regex & Text Processing3

Databases & SQL3

Files & Streams3

Frontend & DOM3

Security Hardening4