Format Records Into Reused Buffers With AppendInt
Build structured telemetry lines in a preallocated byte slice using strconv.AppendInt for decimal and hex fields while keeping buffer capacity fixed.
Build command line tools with parsed args and safe exits.
386 published examples — showing latest 48
Build structured telemetry lines in a preallocated byte slice using strconv.AppendInt for decimal and hex fields while keeping buffer capacity fixed.
Pass maxDepth to Files.walk to stop at 0, 1, or N directory levels, keeping deep subdirectories unread while closing the stream via try-with-resources.
Implement java.util.Formattable so a custom type honors alternate #, precision .N, left-justify -, width, and uppercase %S flags in String.format.
Remove ANSI SGR and VT control escapes with Node util.stripVTControlCharacters so log parsers, checksums, and alignment widths stay accurate.
Iterate NUL-delimited byte records via BufRead::split, skipping empty gaps and turning invalid UTF-8 bytes into io::ErrorKind::InvalidData failures.
Check Formatter::alternate() inside a custom std::fmt::Display impl so {} emits a compact one-line summary while {:#} prints a multi-line breakdown.
Scan a character stream using Iterator::peekable to group multi-digit integers, identifiers, and two-character operators like == and !=.
Refine string[] output from String.prototype.split into a fixed-length tuple using a custom type guard so positional destructuring stays strictly typed.
Type variadic prefixes and packet interiors with leading and middle rest elements in labeled tuples so fixed header and trailing targets stay strongly typed.
Consume a two-ended work queue with ArrayDeque pollFirst and pollLast, pairing entries from both sides until the deque runs empty.
Accept CharSequence at API boundaries so String, StringBuilder, and StringBuffer all pass through without intermediate toString copies.
Create a missing directory tree with Files.createDirectories, which succeeds silently when the directory exists instead of throwing like createDirectory.
Split a Duration into day, hour, minute, and second parts with toXxxPart methods, where each part is a remainder and toHours is the total.
Insert at both ends with addFirst and addLast from the JDK 21 SequencedCollection interface, then poll from either side without index arithmetic.
String.compareTo compares UTF-16 code units one position at a time, so uppercase letters sort before lowercase and prefixes yield a length difference.
Duplicate strings with repeat for indentation and separator lines: zero returns the empty string, while negative or infinite counts raise RangeError.
Center strings in a fixed width with str.center, which splits leftover padding between the sides, rejects multi-character fills, and never truncates.
Render strings with str.format positional, named, and indexed fields — the one path where the template itself can live in a variable, unlike f-strings.
Render datetimes with strftime format codes — %Y %m %d %H %M %S for fields, %f for microseconds — and round-trip the output through strptime.
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.
Register a flag whose parsing logic is a plain callback with flag.Func, so repeatable values accumulate without a custom flag.Value type.
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.
Vector.elements() returns an Enumeration; asIterator and Collections.list bridge it into for-each and the Stream API without rewriting legacy code.
find() resumes at the previous match end, so overlapping hits are invisible; restarting find from start+1 reveals every occurrence.
One getPathMatcher call serves both syntaxes: glob: patterns cross directories with ** while regex: matches paths with a plain regular expression.
Strip ANSI escape sequences from colored CLI output with one regex covering CSI, OSC, and two-byte controls, leaving plain text untouched.
Break a Duration into hours, minutes, and seconds for human readable CLI output, since Debug prints machine units like 90061s.
Start a child process with spawn and probe it non-blockingly via try_wait: None means still running, and wait() finally blocks for the exit status.
Point csv.Reader and csv.Writer at a semicolon delimiter with the Comma field, so European dialect files roundtrip without any manual splitting.
Feed a child process through cmd.Stdin with any io.Reader, avoiding temp files while the command consumes the data as a stream.
Register in-process metrics with expvar Ints and Maps, retrieve them by name with Get, and walk every published variable with Do — no metrics library.
Turn absolute targets into root-relative paths with filepath.Rel for reports and allowlist checks, expecting the leading .. when a target escapes the root.
Durations parse with flag.Duration while TextVar routes richer types like netip.Addr through encoding.TextUnmarshaler, so bad text aborts the run early.
Distinguish user-set flags from declared defaults with flag.Visit and VisitAll, so help output only shows what was actually passed.
format.Source reformats complete Go snippets with the same rules as gofmt and returns a parse error instead of panicking on broken syntax.
Insert a comma every three digits by walking the formatted bytes, so reports read 1,234,567 without pulling in any formatting library.
SplitHostPort separates host and port with required brackets for IPv6 literals, and JoinHostPort adds them back when joining either address family.
http.StatusText turns numeric status codes into canonical reason phrases and returns an empty string for unregistered codes like 599.
Pipe data through a subprocess with StdinPipe and StdoutPipe: write lines to the child, stream its sorted output back with a Scanner, then Wait for exit.
Greedy wrapping breaks text into lines no wider than the limit, splitting only at spaces and pushing an overlong word to its own line.
Emit ANSI SGR escape sequences to color terminal output, then strip every sequence with a regex so piped or CI output stays clean.
Character.getName reports the official Unicode name of any code point, or null for unassigned ones, ideal for debugging odd glyphs.
System.console() may be null when the program runs without a terminal; guard it, prompt with readLine, and take secrets as char arrays from readPassword.
user.dir anchors relative paths for the whole JVM: Paths.get("").toAbsolutePath() lands on the same directory that System.getProperty("user.dir") reports.
Pattern letter B formats the finer day period — morning, afternoon, evening, night — where am/pm collapses the whole day into two halves.
Count terminal columns where CJK and fullwidth characters occupy two cells, so padded tables align where String length() undercounts wide text.
Stream the whole directory tree with Files.walk, sort by byte size, and keep only the top entries for disk usage triage.
Reference arguments out of order with %2$ indices, repeat the previous value with the %< flag, and fail loudly on indices beyond the argument list.
Showing 48 of 386 verified Cli Tooling examples. Filter the full catalog by language, framework, or keyword in Explore.
Browse & filter all 386 examples in Explore →