Examples

Page 18 of 50

Browse code examples

goSnippet

Parse Go Source With go parser

Parse Go source text into a syntax tree with go/parser, then walk it with ast.Inspect to report every function declaration and its parameter count.

goSnippet

Filter Slices In Place

Filter a slice into its own backing array with s[:0] and append, then prove the aliasing by reading the stale tail beyond the truncated length.

goSnippet

TrimLeft Cutset Versus Prefix

Strip leading characters correctly: strings.TrimLeft removes any leading cutset runes, TrimPrefix removes one exact prefix, and confusing them corrupts data.

javaSnippet

Exit Codes For CLI Errors

Follow the CLI exit-code convention: zero for success, one for business failures, two for usage errors, with diagnostics written to stderr.

javaSnippet

Wrap Words To A Fixed Width

Break text into lines no wider than the limit with a greedy pass: fill each line with as many words as fit, then start the next line.

javascriptSnippet

fs.stat Reads Path Metadata

Read a path's size, timestamps, and entry kind with fs.stat, distinguishing files from directories before acting on the metadata.