Examples

Page 42 of 50

Browse code examples

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.

javascriptSnippet

Throttle a Function

Throttle limits how often a function runs by allowing at most one call per interval, useful for scroll and resize handlers that fire continuously.

pythonSnippet

Celery Beat Crontab Schedules

Schedule recurring Celery tasks with beat crontabs, mixing timezones, staggered offsets, and task-specific routing to dedicated queues.