FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

3000 snippets foundClear filters
JavaScriptGetting Started

Read the beginning of a text value

JavaScript: Extract or display the first three ASCII characters from a known nonempty string.

JavaScript✓ Tested
TypeScriptGetting Started

Read the beginning of a text value

TypeScript: Extract or display the first three ASCII characters from a known nonempty string.

TypeScript✓ Tested
C++Getting Started

Read the beginning of a text value

C++: Extract or display the first three ASCII characters from a known nonempty string.

C++✓ Tested
CGetting Started

Read the beginning of a text value

C: Extract or display the first three ASCII characters from a known nonempty string.

C✓ Tested
Linux CommandsGetting Started

Read the beginning of piped text

Linux Commands: Read the beginning of piped text using GNU/Linux commands in an empty practice directory.

Linux Commands✓ Tested
C++Filesystem operations

Read the byte size of a regular file

C++: file_size reads filesystem metadata without loading file contents.

C++✓ Tested
GitBranches & ancestry

Read the current branch name

Git: show-current returns an empty string when HEAD is detached.

Git✓ Tested
Linux CommandsGetting Started

Read the directory portion of a path

Linux Commands: Read the directory portion of a path using GNU/Linux commands in an empty practice directory.

Linux Commands✓ Tested
Linux CommandsGetting Started

Read the end of piped text

Linux Commands: Read the end of piped text using GNU/Linux commands in an empty practice directory.

Linux Commands✓ Tested
GitInspecting the working tree

Read the exact version currently staged

Git: The colon path syntax reads a blob from the index rather than from HEAD or the working file.

Git✓ Tested
Linux CommandsGetting Started

Read the filename portion of a path

Linux Commands: Read the filename portion of a path using GNU/Linux commands in an empty practice directory.

Linux Commands✓ Tested
JavaScriptArray traversal & selection

Read the final array item with a negative index

JavaScript: at supports negative positions counted from the end.

JavaScript✓ Tested