Results for “read lines”
Small, practical examples. Search by task or narrow things down below.
Parse a JSON string
Convert a JSON string into a Python dictionary and read values by key.
json✓ Tested
Parse a short option with getopts
Read a named option and handle invalid flags explicitly.
getopts✓ Tested
Parse and format a date
Convert a date string into a datetime object, then format it in a different, human-readable order.
date✓ Tested
Parse JSON text
Read a JavaScript object from JSON text.
JavaScript✓ Tested
Parse quoted CSV from an in-memory string
Python: Use StringIO with csv.reader so quoted commas are handled correctly.
Python✓ Tested
Preconfigure some function arguments
Python: Use partial to produce a callable with selected arguments already bound.
Python✓ Tested
Preserve equal-key order while sorting records
C++: stable_sort retains encounter order for records whose selected sort keys compare equal.
C++✓ Tested
Print a number with two decimal places
C++: Format a small decimal value consistently for display.
C++✓ Tested
Process a first-in first-out queue
C++: Queue exposes its front item separately from the operation that removes it.
C++✓ Tested
Protect a shared container with a mutex
C++: A scoped lock_guard releases the mutex when its scope ends.
C++✓ Tested
Refresh a cached data attribute deliberately
jQuery: After the first read, data caches a parsed value; removeData forces a new attribute read.
jQuery✓ Tested
Refuse to overwrite an existing file with redirection
Bash Scripts: Noclobber makes a plain greater-than redirection fail when the target already exists.
Bash Scripts✓ Tested