Examples

Page 43 of 50

Browse code examples

pythonSnippet

Token Bucket Rate Limiter

Implement a token bucket that refills at a steady rate and allows short bursts, a standard algorithm for shaping request traffic.

pythonSnippet

Redis Sentinel Failover Client

Connect through Redis Sentinel for automatic failover, detecting role changes, retrying reads on replicas, and fencing split-brain writes.

pythonSnippet

Retry Decorator With Backoff

Decorate a function so transient exceptions are retried a fixed number of times with growing delay, keeping call sites free of retry plumbing.

pythonSnippet

Rich Table Live Display CLI

Render dynamic CLI tables with Rich Live mode, updating rows in place as background tasks progress and finishing with a clean summary.

pythonSnippet

Typer Async Command Options

Build async CLI commands with Typer, combining type-annotated options, enum choices, environment fallbacks, and per-command validation.

rustSnippet

Anyhow Context Error Chains

Enrich errors with anyhow context layers, converting foreign error types into chains that print root causes and section context.

rustSnippet

Tokio Timeout With select!

Race an async operation against a timer using tokio select!, so a slow future is abandoned cleanly when the deadline fires first.

sqlSnippet

Select For Update Skip Locked

Claim a batch of jobs from a queue by locking only unlocked rows, letting concurrent workers drain the queue without blocking each other.

sqlSnippet

Upsert With ON CONFLICT

Insert a row or update it when the unique key already exists, in one atomic statement that avoids a race between read and write.