Instantly share code, notes, and snippets.

View LongOptionsParse.cpp
#include <getopt.h>
#include <iostream>
using namespace std;
void usage(const char* appName, int exitCode, string errMsg="")
{
if (!errMsg.empty())
cout<<"\n"<<errMsg<<endl;
View yaml2json.py
# Converts input YAML file to JSON and writes the JSON to same filename but with ".json" ext.
import os, json, sys, yaml
if len(sys.argv) < 2:
print("Usage: "+sys.argv[0]+" <input.yaml>")
exit
try:
yamlFname = sys.argv[1]
pre, ext = os.path.splitext(yamlFname)
jsonFname = pre + ".json"
View printHorizontalLine
# Usage: printHorizontalLine [c]
function printHorizontalLine {
local c="-"
local strlen=1
if [ -n "$1" ]; then
c=$1
strlen=${#c}
fi
echo
View answerYesNo.sh
# Bash function to prompt terminal user for yes|no
# Author: Oscar Kramer
#
# If interactive shell, prompts user for confirmation considering optional default (Y|N) specified.
# The default is returned if <enter> is typed in lieu of a y|n character. The prompt is appended with
# " [Y|n]:" or " [y|N]:" depending on default provided.
#
# If not interactive, returns answerYes=1, answerNo=0
# Returns boolean
#