Zig Examples
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.
Zig aligned plain-text terminal table
Prints rows as an aligned plain-text table using format-specifier padding and a dashed header separator.
Zig field-level input validation errors
Validates name, email, and age fields, collecting field-level error messages instead of stopping at the first.
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.
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.
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.
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.
Zig env config with defaults and checks
Reads port, host, and debug flags from environment variables, applying defaults and rejecting bad values.
Zig token bucket rate limiter with burst
A token bucket limiter that allows short bursts while enforcing a steady average request rate.
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.
Zig stable multi-key sort with null scores
Sorts records by group, then descending score, keeping null scores last and preserving stable order.
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.
Zig stream file lines with buffered reader
Streams a text file line by line with a buffered reader and trims Windows carriage returns.
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.
Zig capped exponential backoff retry loop
Retries a fallible operation with capped exponential backoff, full jitter, and a hard attempt limit.