Examples

Page 5 of 14

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.

javascriptSnippet

Minimal Typed Event Emitter

Build a small publish and subscribe emitter that registers listeners per event name and supports one-shot subscribers and clean removal.

javascriptSnippet

Group Array Items by Key

Group an array of records into a map keyed by one of their fields, a building block for reports, indexes, and bucketed aggregations.

javascriptSnippet

Decode JWT Claims and Check Expiry

Decode the payload of a JSON Web Token and verify that its expiry and not-before claims are respected, without trusting the token's signature blindly.

javascriptSnippet

Levenshtein Edit Distance

Compute the minimum number of insertions, deletions, and substitutions between two strings, the basis of fuzzy matching and spell suggestions.

javascriptSnippet

LRU Cache With Map Ordering

Implement a least-recently-used cache that evicts the oldest entry when capacity is exceeded, reusing Map insertion order to track recency.

javascriptSnippet

Memoize With a Time to Live

Cache a function's result by argument key with an expiry, so expensive pure calls are reused briefly and stale values eventually recompute.

javascriptSnippet

Diff Two Flat Objects

Compare two flat objects field by field and report added, removed, and changed keys, the core of audit logging and change detection.

javascriptSnippet

Paginate an In-Memory Array

Slice an array into a page and return metadata such as total pages and whether more results follow, the shape most list endpoints expose.

javascriptSnippet

Bounded Concurrency Promise Pool

Run an array of async tasks with a maximum concurrency, so a large batch does not open all connections at once and overwhelm a downstream service.