Zig Examples

ZigOct 23, 2026

Zig base64 encode and validated decode

Encodes bytes to standard Base64 and decodes back with size checks so invalid padding is reported as an error.

decodingencodingbase64
000
ZigOct 23, 2026

Zig aligned plain-text terminal table

Prints rows as an aligned plain-text table using format-specifier padding and a dashed header separator.

formattingtablecli
000
ZigOct 23, 2026

Zig field-level input validation errors

Validates name, email, and age fields, collecting field-level error messages instead of stopping at the first.

errorsvalidationforms
000
ZigOct 23, 2026

Zig query string encoder and pair splitter

Percent-encodes key/value pairs into a query string and splits an existing query string into a hash map.

query-stringurlencoding
000
ZigOct 23, 2026

Zig JSON parse errors with line and column

Decodes a JSON object into a struct and logs the exact line and column when parsing or validation fails.

errorsjsondiagnostics
000
ZigOct 23, 2026

Zig bounded worker pool with atomic index

Runs tasks on a fixed number of threads, hands out jobs via an atomic counter, and records results or errors.

concurrencyatomicsthread-pool
000
ZigOct 23, 2026

Zig POSIX HTTP JSON fetch with deadline

Fetches a JSON document over plain HTTP with a POSIX poll deadline, then parses it into a std.json.Value.

networkinghttpjsontimeout
000
ZigOct 23, 2026

Zig env config with defaults and checks

Reads port, host, and debug flags from environment variables, applying defaults and rejecting bad values.

environmentconfigurationvalidation
000
ZigOct 23, 2026

Zig token bucket rate limiter with burst

A token bucket limiter that allows short bursts while enforcing a steady average request rate.

throughputtoken-bucketrate-limiting
000
ZigOct 23, 2026

Zig bounded LRU cache over slot array

A fixed-size recency cache that tracks a use counter per slot and evicts the least recently used entry.

boundedlrucache
000
ZigOct 23, 2026

Zig stable multi-key sort with null scores

Sorts records by group, then descending score, keeping null scores last and preserving stable order.

nullssortingrecordscomparator
000
ZigOct 23, 2026

Zig chunk slice into fixed-size batches

Splits a slice into consecutive batches of at most N items and reports how many batches were filled.

chunkingbatchslice
000
ZigOct 23, 2026

Zig stream file lines with buffered reader

Streams a text file line by line with a buffered reader and trims Windows carriage returns.

streamingbuffered-readerfile-io
000
ZigOct 23, 2026

Zig deep clone and merge for config maps

Deep-copies a config and its string map, then merges another config's non-empty fields over it.

mergeconfigdeep-copystructs
000
ZigOct 23, 2026

Zig capped exponential backoff retry loop

Retries a fallible operation with capped exponential backoff, full jitter, and a hard attempt limit.

resiliencebackoffretryjitter
000