Skip to content

Instantly share code, notes, and snippets.

View oscarkramer's full-sized avatar

Oscar Kramer oscarkramer

  • Miami Beach
View GitHub Profile
// C Program for IPC Message Queue. Adapted from https://www.geeksforgeeks.org/ipc-using-message-queues/
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <cstring>
using namespace std;
// structure for message queue
@oscarkramer
oscarkramer / scriptdir.sh
Created March 30, 2023 12:42
Bash get script directory
#!/bin/bash
pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
SCRIPT_DIR=`pwd -P`
popd >/dev/null
echo "Script directory is $SCRIPT_DIR"
#!/bin/bash
usage() {
echo;
echo "Description here."
echo
echo "Usage: $0 [options] <arg1> "
echo
echo " <arg1> Arg1 blah blah"
echo
@oscarkramer
oscarkramer / LongOptionsParse.cpp
Last active March 8, 2023 18:25
Long Option Parsing in C++
#include <getopt.h>
#include <iostream>
using namespace std;
void usage(const char* appName, int exitCode, string errMsg="")
{
if (!errMsg.empty())
cout<<"\n"<<errMsg<<endl;
cout<<"\nProgram description goes here..."
@oscarkramer
oscarkramer / yaml2json.py
Last active July 31, 2018 14:46
YAML to JSON File converter in python
# 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"
@oscarkramer
oscarkramer / printHorizontalLine
Created May 18, 2018 15:47
Bash script to output a horizontal line spanning the width of the terminal using dashes (or optional string provided)
# Usage: printHorizontalLine [c]
function printHorizontalLine {
local c="-"
local strlen=1
if [ -n "$1" ]; then
c=$1
strlen=${#c}
fi
echo
@oscarkramer
oscarkramer / answerYesNo.sh
Last active April 22, 2022 14:39
Bash functions for prompting yes/no question
# 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
#