A collection of boilerplates, random sketches, and useful stuff.
Some bash tools to use and learn. For debugging commands use explainshell.
# 16 character alphanumeric string
identifier=$(< /dev/urandom tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)function cleanup() {
echo >&2 "CLEANING UP TEMPORARY DIRECTORY ${TEMP_DIR}"
rm -rf "${TEMP_DIR}"
}
function create_temporary_directory_with_cleanup() {
TEMP_DIR=$(mktemp --directory "/tmp/temporary_dir".XXXXXXXX)
export TEMP_DIR
trap cleanup EXIT
echo "TEMPORARY WORKING DIRECTORY CREATED AT ${TEMP_DIR}"
}if [[ -n "${_condition:-}" ]] && \
[[ "${_condition:-}" != *"aaa"* ]] && \
[[ "${_condition:-}" != *"bbb"* ]]; then
echo "Checked!"
fi# cut at spaces
IFS=" " read -r -a version_list <<< "${VERSION_LIST}"for version in "${version_list[@]}"; do
EXEC_STRING+=" --version ${version}"
done- python3 -m venv ./bin-python
- bash source ./bin-python/bin/activate
- pip install -r your_requirements.txt"
- pip freeze -l > your_requirements.txt"
logger.warning("Bad expression: %s. No matches found at %s", expression, location)
parameter = "Stuff_and_{version}".format(version=version)
# f-strings in python 3.6
name = "Peter"
age = 21
f"Hello, {name}. You are {age}."def read_testfile(test_file):
with test_file.open() as infile:
test_data = infile.read().splitlines() # json.load(infile)
return test_dataimport argparse
def parse_arguments():
parser = argparse.ArgumentParser(description='Default.')
parser.add_argument('--param', help='an integer for the accumulator')
return parser.parse_args()
def main():
args = parse_arguments()
return args
if __name__ == '__main__':
main()