Snippets

Contents

Snippets#

Short pieces of code the operator pastes into a shell, a notebook, or a fresh script. Each page collects idioms for one slice of the language: one-liners, file scans, network shortcuts, data shaping. The blocks are deliberately small, copy-paste ready, and each block stands alone.

For the language fundamentals these snippets build on, see Types, Control flow, and Functions.

One-liners

Single-expression idioms: dedupe, flatten, batch, group, invert, count, swap, walrus, conditional.

One-liners
Files

Read, write, scan, tail, hash, glob. pathlib and with open recipes.

Files
Text

Strip, slice, split, format, regex. The operator’s string-bashing kit.

Text
Data

JSON, CSV, TOML, base64, hashlib. Codec round-trips and one-pass extractions.

Data
Time

datetime, timedelta, time.monotonic, strftime. Parsing, formatting, deadlines.

Time
Network

urllib, httpx, socket, ipaddress. HTTP fetch, port check, address arithmetic.

Network
Shells

HTTP server, reverse shell (callback), bind shell (listener). Plain and TLS-wrapped.

Shells

References#

  • Types for the underlying types.

  • Control flow for if / for / while / match.

  • Functions for comprehensions and generator expressions.

  • Python for the project-wide Python snippet shelf.