Skip to content

Instantly share code, notes, and snippets.

View rothwerx's full-sized avatar

Jeremiah Roth rothwerx

View GitHub Profile
@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: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:700f275d078b3483509f
Created January 4, 2015 21:05
8x8 bit matrix characters
// These were written specifically for the Adafruit 8x8 LED matrix,
// https://www.adafruit.com/product/870 but they could be used anywhere you need
// 64 bit character representations. I wasn't happy with any of the characters I
// found, so I created these. They're nice and bold, not silly line letters.
B00110000,B01111000,B11001100,B11001100,B11111100,B11001100,B11001100,B00000000,25, // A
B11111100,B01100110,B01100110,B01111100,B01100110,B01100110,B11111100,B00000000,25, // B
B00111100,B01100110,B11000000,B11000000,B11000000,B01100110,B00111100,B00000000,25, // C
B11111000,B01101100,B01100110,B01100110,B01100110,B01101100,B11111000,B00000000,25, // D
B11111110,B01100010,B01101000,B01111000,B01101000,B01100010,B11111110,B00000000,25, // E
@rothwerx
rothwerx / gist:4bfc8ce77c23e788d4a0
Last active February 12, 2016 21:47
viminstall.sh
#!/bin/bash
# This file can be wget'ed at http://is.gd/vimme
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
if ! command -v git; then
echo "You really need git."
exit 1
@rothwerx
rothwerx / gist:c894bd8b08fee8ab1a53
Created December 14, 2014 03:34
Get the install date of a linux system
tune2fs -l /dev/sda1 | awk -F" +" '/Filesystem created/ { print $2 }'
@rothwerx
rothwerx / gist:3392745ab7bef150a73a
Created December 9, 2014 16:48
ISC DHCP configuration that updates Windows DDNS
isc-dhcpd-4.1.1-P1
authoritative;
option domain-name "int.domain.com";
option domain-search "int.domain.com";
option domain-name-servers 10.50.10.74, 10.50.10.75, 10.50.10.20, 10.50.10.21;
ddns-updates on;
ddns-update-style interim;
update-static-leases on;
set nocompatible
if has("syntax")
syntax on
endif
if has("autocmd")
" Automatically reload vimrc after saving
autocmd bufwritepost .vimrc source $MYVIMRC
" Remember last position in file
@rothwerx
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.
!/usr/bin/env python
import RPi.GPIO as GPIO
import datetime
import socket
import time
import os
metric_path = "sun.loc1"
@rothwerx
rothwerx / gist:7146476
Created October 24, 2013 22:48
Go: Small example of running system commands
package main
import "os/exec"
import "fmt"
import "bytes"
func main() {
cmd := exec.Command("/bin/ls", "-al")
var out bytes.Buffer
cmd.Stdout = &out
@rothwerx
rothwerx / gist:6574543
Last active December 23, 2015 03:39
Bash: Animated dance. Useful for your celebrating when your multi-pipe one-liner works on the first try.
function _totheleft() {
echo "(°_°)"
echo "<) )╯"
echo ' / \'
}
function _totheright() {
echo " (°_°)"
echo "\( (>"
echo ' / \'