Examples

Page 41 of 50

Browse code examples

bashSnippet

Parse Options With getopts

Parse short options and their arguments with getopts so a shell script exposes a predictable CLI instead of positional guesswork.

bashSnippet

Retry a Command With Backoff

Retry a shell command that may fail transiently, waiting longer between attempts and reporting the last error when all tries are exhausted.

goSnippet

Gin JWT Claims Middleware

Extract and verify JWT claims in Gin middleware, checking issuer and role before handlers, with claims injected into context.

goSnippet

Slog Structured Logging JSON

Adopt Go structured logging with slog: leveled JSON handlers, grouped attributes, log record routing, and child loggers with bound context.

goSnippet

Structured Logging With slog

Emit structured logs with the standard slog package so records carry typed key-value attributes that are easy to filter and correlate.

goSnippet

Table Driven Unit Test Go

Cover function branches with table-driven tests: declarative cases with names, parallel subtests, and precise failure output.

javascriptSnippet

Async Timeout Wrapper

Race a promise against a timer so a slow dependency cannot hold a request open indefinitely, aborting the underlying signal when the deadline passes.

javascriptSnippet

Curry a Function

Curry a function so partial application returns a new function until every argument is supplied, enabling reusable configured variants.

javascriptSnippet

Debounce a Function

Debounce wraps a callback so it runs only after activity stops for a set wait, collapsing bursts of calls into a single trailing invocation.

javascriptSnippet

Deep Clone Plain Data Objects

Clone nested objects and arrays without sharing references, using the structured clone algorithm so dates, maps, and cycles are handled correctly.