Skip to content

Instantly share code, notes, and snippets.

View rothwerx's full-sized avatar

Jeremiah Roth rothwerx

View GitHub Profile
@rothwerx
rothwerx / gist:97c8c591be1021522b60
Created March 11, 2015 02:35
Bash: resample the lines of a multiline variable
function resample() {
sample_interval=$1
fh=$2
ctr=1
while read line; do
[[ $sample_interval -eq $ctr ]] && echo "$line" && ctr=0
((ctr++))
done < <(echo "$fh")
}
@rothwerx
rothwerx / gist:065fbdfd5eec6aa56e1f
Created March 18, 2015 22:15
C: Print the USER_HZ for a platform
/* CPU values in /proc/stat are measured in USER_HZ which is
generally 1/100th of a second, but you can verify with this.
See http://man7.org/linux/man-pages/man5/proc.5.html
*/
#include <unistd.h>
#include <stdio.h>
int main()
{
printf("USER_HZ is %d\n", sysconf(_SC_CLK_TCK));
@rothwerx
rothwerx / gist:b60f1fa7b543e8761b3c
Created July 13, 2015 21:42
Bash: Ensure processes run on allowed CPUs
#!/bin/bash
# function to expand the range of allowed CPUs
range_expand () (
IFS=,
set -- $1
n=$#
for element; do
if [[ $element =~ ^(-?[0-9]+)-(-?[0-9]+)$ ]]; then
set -- "$@" $(eval echo "{${BASH_REMATCH[1]}..${BASH_REMATCH[2]}}")
@rothwerx
rothwerx / gist:e1308d61512d7c278268
Created August 10, 2015 17:13
Bash: Collect HBA/HCA information for facter
#!/bin/bash
# Produce custom facts about HBA/HCA cards for facter
# This file should be executable in /etc/facter/facts.d/
# Look for Mellanox, Emulex, and QLogic cards
varq=$(lspci | awk '/[Mm]ellanox/ {
printf "mellanox=%s\n", $1 }
/[Ee]mulex/ {
printf "emulex=%s\n", $1 }
/[Qq][Ll]ogic/ {
@rothwerx
rothwerx / gist:7aa31f5437a4fc2b9416
Created October 21, 2015 16:24
Bash: Logging helper function
function pecho {
if [[ $LOGGING ]]; then
printf "$@" | tee -a some.log
else
printf "$@"
fi
}
pecho "%-10s %10s\n" "Logging:" "On"
@rothwerx
rothwerx / gist:f1843fe5e295f0c18d21
Created December 5, 2015 03:50
Python: YAML to JSON preprocessor
#!/usr/bin/env python
import yaml
import json
import sys
with open(sys.argv[2], "w") as outf, open(sys.argv[1]) as inf:
o = yaml.safe_load(inf)
json.dump(o, outf)
@rothwerx
rothwerx / gist:96d71d9abedab96f7033c674b1b8e876
Last active July 14, 2016 16:21
Python: Get time delta from log with YYYY-MM-DD hh:mm:ss format
#!/usr/bin/env python
import sys
from datetime import datetime
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('logfile', help='Log file')
parser.add_argument('-s', '--seconds', default=1, type=int,
help='Only log entries that took over n seconds')
@rothwerx
rothwerx / gist:ebef10660b42ae4e3235f47b0236b518
Created December 4, 2017 21:55
Shell: Installing iPython in Python 2.7
# iPython 6 dropped support for Python 2.7
sudo pip install "pathlib2==2.1.0"
sudo pip install "ipython<6.0"
# set -g default-terminal "screen-256color"
# fix pbpaste and pbcopy commands on OSX https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
# set-option -g default-command "reattach-to-user-namespace -l $SHELL"
# Report support for 256 colors
set -g default-terminal "screen-256color"
# remap prefix to C-a
set -g prefix C-a

Keybase proof

I hereby claim:

  • I am rothwerx on github.
  • I am rothwerx (https://keybase.io/rothwerx) on keybase.
  • I have a public key ASBy7WRKEIU2UJRhUTIcRrHbXliZjB8p5pDriDHcUa6mywo

To claim this, I am signing this object: