Skip to content

Instantly share code, notes, and snippets.

View dpsmith's full-sized avatar

Daniel P. Smith dpsmith

  • Apertus Solutions, LLC
View GitHub Profile
@dpsmith
dpsmith / gist:c5977aede599ce85e61d244ede05b501
Created October 22, 2019 18:53
Bash YAML parser function
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@dpsmith
dpsmith / gist:8c889f17c38516c0ab116823505f05a4
Last active March 22, 2018 12:08
Git: add only untracked files
echo -e "a\n*\nq\n"|git add -i
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@dpsmith
dpsmith / gist:3abe1b6d018b39b629b80cb7c79425d0
Created April 5, 2016 22:20
Debug a daemon that forks(clone) using strace
#!/bin/bash
self=$0
pid=$1
while read line; do
echo $line >> ${pid}.log
if $(echo $line | grep -q -e '^clone'); then
child=$(echo $line|awk '{ print $5 }')