Skip to content

Instantly share code, notes, and snippets.


Jeremiah Roth rothwerx

View GitHub Profile
rothwerx / gist:10440939
Created April 11, 2014 04:31
Python: Raspberry Pi: Read photocell values and graph with Graphite. I used this with cron for determining the best place to grow tomatoes.
View gist:10440939
!/usr/bin/env python
import RPi.GPIO as GPIO
import datetime
import socket
import time
import os
metric_path = "sun.loc1"
rothwerx / gist:3392745ab7bef150a73a
Created December 9, 2014 16:48
ISC DHCP configuration that updates Windows DDNS
View gist:3392745ab7bef150a73a
option domain-name "";
option domain-search "";
option domain-name-servers,,,;
ddns-updates on;
ddns-update-style interim;
update-static-leases on;
rothwerx / gist:c894bd8b08fee8ab1a53
Created December 14, 2014 03:34
Get the install date of a linux system
View gist:c894bd8b08fee8ab1a53
tune2fs -l /dev/sda1 | awk -F" +" '/Filesystem created/ { print $2 }'
rothwerx / gist:97c8c591be1021522b60
Created March 11, 2015 02:35
Bash: resample the lines of a multiline variable
View gist:97c8c591be1021522b60
function resample() {
while read line; do
[[ $sample_interval -eq $ctr ]] && echo "$line" && ctr=0
done < <(echo "$fh")
rothwerx / gist:065fbdfd5eec6aa56e1f
Created March 18, 2015 22:15
C: Print the USER_HZ for a platform
View gist:065fbdfd5eec6aa56e1f
/* CPU values in /proc/stat are measured in USER_HZ which is
generally 1/100th of a second, but you can verify with this.
#include <unistd.h>
#include <stdio.h>
int main()
printf("USER_HZ is %d\n", sysconf(_SC_CLK_TCK));
rothwerx / gist:b60f1fa7b543e8761b3c
Created July 13, 2015 21:42
Bash: Ensure processes run on allowed CPUs
View gist:b60f1fa7b543e8761b3c
# function to expand the range of allowed CPUs
range_expand () (
set -- $1
for element; do
if [[ $element =~ ^(-?[0-9]+)-(-?[0-9]+)$ ]]; then
set -- "$@" $(eval echo "{${BASH_REMATCH[1]}..${BASH_REMATCH[2]}}")
rothwerx / gist:e1308d61512d7c278268
Created August 10, 2015 17:13
Bash: Collect HBA/HCA information for facter
View gist:e1308d61512d7c278268
# 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 / gist:7aa31f5437a4fc2b9416
Created October 21, 2015 16:24
Bash: Logging helper function
View gist:7aa31f5437a4fc2b9416
function pecho {
if [[ $LOGGING ]]; then
printf "$@" | tee -a some.log
printf "$@"
pecho "%-10s %10s\n" "Logging:" "On"
rothwerx / gist:f1843fe5e295f0c18d21
Created December 5, 2015 03:50
Python: YAML to JSON preprocessor
View gist:f1843fe5e295f0c18d21
#!/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 /
Last active December 16, 2015 17:09 — forked from cluther/zenoss-shell-functions
Bash: CuRL Zenoss
# Source this file
# Your Zenoss server settings.
# Generic call to make Zenoss JSON API calls easier on the shell.