Examples

Page 4 of 50

Browse code examples

goSnippet

Benchmark With B.Loop

Replace the manual for-i-less-than-b.N loop with b.Loop on Go 1.24: iteration count, timer reset, and memory stats are handled automatically.

goSnippet

Varint Packs Signed Integers

Store signed integers in one to ten bytes with binary.PutVarint, and walk the buffer back with binary.Varint to recover each value and its width.

javaSnippet

Strip ANSI Escape Sequences

Strip ANSI escape sequences from colored CLI output with one regex covering CSI, OSC, and two-byte controls, leaving plain text untouched.

javaSnippet

Zip Entry Size Budget Guard

Cap ZipInputStream entries with a streaming byte budget: declared sizes can be unknown, so count every read and abort the moment an entry overshoots.

rustSnippet

Checked Arithmetic On Durations

Enforce duration budgets with checked_add and checked_sub, which return Option instead of wrapping past zero the way Duration cannot go negative.