Skip to content

Instantly share code, notes, and snippets.

@raidzero
raidzero / paswitch.sh
Created March 3, 2014 00:08
Pulseaudio: switch all apps playing sound to play on a specific device
#!/bin/sh
# switch all apps playing sound to a given device.
# usage: paswitch.sh [HEADPHONES|SPEAKERS] (really meant to be bound a key shortcut)
# these are the sink names of the devices we want to use
HEADPHONES="alsa_output.usb-FiiO_DigiHug_USB_Audio-01-Audio.analog-stereo"
SPEAKERS="alsa_output.pci-0000_00_1b.0.analog-stereo"
# get a list of ID's of everything playing sound
INPUTS=`pacmd list-sink-inputs | grep index | cut -d ':' -f2 | sed 's/^ *//g'`
@raidzero
raidzero / hottestcore.sh
Created March 3, 2014 00:15
CPU core temperature monitoring utility
#!/bin/sh
# cpu core temp monitor tool for my i7 4930k
SENSOR="coretemp-isa-0000"
COLUMNS=`tput cols`
if [ "$COLUMNS" -lt 106 ]; then
echo "Terminal needs to be 106 columns wide for hottestcore to work correctly."
exit 1
fi
@raidzero
raidzero / grub2-reboot-do.sh
Last active August 29, 2015 13:56
Openbox pipe menu: grub2 reboot/hibernate
#!/bin/sh
CHOICE=$1
HIBERNATE=$2
if [ "$CHOICE" == 9999 ]; then
STAYOFF="STAYOFF"
fi
if [ -z "$HIBERNATE" ]; then
#su raidzero -c '/home/raidzero/bin/sess.sh save'
@raidzero
raidzero / vb_launch.py
Created March 3, 2014 00:29
Openbox pipe menu: launch Virtualbox VM's
#!/usr/bin/python
import os
"""Pipe Menu to launch VirtualBox Machines"""
# build the list of VM's
VM_LIST = os.listdir("/home/raidzero/.VirtualBox/Machines")
print """<openbox_pipe_menu>
@raidzero
raidzero / kbd_repeat_dialog.sh
Created March 3, 2014 00:32
Xdialog for adjusting keyboard repeat options
#!/bin/sh
FILE=~/.tmp/kbdfile
DELAY=$1
RATE=$2
DEFAULTDELAY=`xset q | grep "auto repeat delay" | awk '{print $1" "$2" "$3" "$4}' | cut -d ':' -f2 | sed 's/ //g'`
DEFAULTRATE=`xset q | grep "repeat rate" | awk '{print $7}'`
@raidzero
raidzero / weather.sh
Created March 3, 2014 00:35
Get weather data from yahoo weather (meant for conky)
#!/bin/sh
# USAGE: weather.sh [NULL|both|forecast]
LOCATION_URL="http://weather.yahooapis.com/forecastrss?p=USCO0105&u=" #Denver
WEATHER=`curl -s "$LOCATION_URL" | grep "F<BR" | awk -F ' F<BR' '{print$1}'`
TOMORROW=`date --date="tomorrow" +%a`
FORECAST=`curl -s "$LOCATION_URL" | grep -oE "^[A-Z][a-z]{2} - .*-?[0-9]{1,3}" | grep "^$TOMORROW" | sed -r 's_High: \<(-?[0-9]{1,3})\> Low: \<(-?[0-9]{1,3})\>_\2\/\1_'`
FORECAST=`echo $FORECAST | sed -r ' \
@raidzero
raidzero / lastboot.sh
Created March 3, 2014 00:38
Get last boot time
#!/bin/sh
# get the last boot time and display it in 12 hour format
# USAGE: lastboot.sh [date|time|both]
LASTBOOT_LINE=`last | grep reboot | head -n 1`
DATE=`echo $LASTBOOT_LINE | awk '{print$5,$6,$7}'`
TIME=`echo $LASTBOOT_LINE | awk '{print$8}'`
#convert to 12 hour
HOUR=`echo $TIME | cut -d : -f1`
@raidzero
raidzero / verscomp.c
Last active August 29, 2015 13:56
Version number comparator
/*
* Uses stdin to evaluate a statement such as "2.5.3" <= 2.4". Returns strings "True" or "False" to terminal
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define DEBUG 0
@raidzero
raidzero / passgen.c
Created March 3, 2014 20:59
Password generator. Takes password requirements as arguments using getopt()
/*
* USAGE: passgen [-u UPPER] [-l LOWER] [-n NUMBER] -s [SPECIAL] -a LENGTH
* The approach is take the desired length, and set aside positions in the result
* string for the required characters, then fill in the other positions
* with random characters
*/
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
@raidzero
raidzero / datemath.py
Created March 3, 2014 20:26
Determine if a date is within a given number of days or past (designed for OS X certificates)
#!/usr/bin/python
# defaults to 45 days if number of days is not given
# USAGE: datemath.py Aug 17 18:24:44 2014 GMT 45
import time, datetime, sys
NOW = datetime.datetime.now().strftime("%s")
END = time.mktime(datetime.datetime.strptime(sys.argv[1], "%b %d %X %Y GMT").timetuple())
if len(sys.argv) > 2:
WARN_DAYS = int(sys.argv[2])