Skip to content

Instantly share code, notes, and snippets.

@craigmbooth
craigmbooth / toggle_keyboard_lights
Created May 3, 2020 20:25
Toggles the keyboard lights on a Thinkpad
#!/bin/bash
# Script that switches on and off the keyboard light on my Thinkpad
backlight_set() {
value="$1"
dbus-send --type=method_call --print-reply=literal --system \
--dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' \
'org.freedesktop.UPower.KbdBacklight.SetBrightness' \
"int32:${value}}"
@craigmbooth
craigmbooth / change_brightness
Created May 3, 2020 18:46
Bash snippet that changes the brightness of a monitor
#!/bin/bash
# Usage: change_brightness <device_name> (+/-)
# I use this in my i3 config to allow the brightness buttons to work on my Thinkpad
set -e
get_display_info() {
local device=$1
local key=$2
echo $(xrandr --verbose | grep -m 1 -w "$device connected" -A8 | \

Keybase proof

I hereby claim:

  • I am craigmbooth on github.
  • I am craigmbooth (https://keybase.io/craigmbooth) on keybase.
  • I have a public key ASBj1u_Cb-yjBoBbodMIUghLVapJTHrSKpGYYspDThh2kgo

To claim this, I am signing this object:

@craigmbooth
craigmbooth / cidr_to_ips.py
Created October 20, 2017 17:37
Given a CIDR block produce an iterator over IP addresses
"""CIDR blocks share the first part of the bit sequence that comprises the
binary representation of the IP address
We determine the network portion of the address by applying a bitwise AND
operation to between the address and the netmask. A bitwise AND operation will
basically save the networking portion of the address and discard the host
portion.
In the CIDR notation 192.0.1.0/24, the prefix is 192.0.1.0, and the total number
of bits in the address is 24. The least significant 8 bits are the IP addresses
@craigmbooth
craigmbooth / download_robert_montgomery_art.py
Created April 2, 2017 15:20
This script downloads all of the images from the billboard gallery on the website of Robert Montgomery.
"""I wanted a screensaver of Robert Montgomery poems. This script pulls
them from the gallery on his website
"""
import os
import sys
from bs4 import BeautifulSoup
import requests
if __name__ == "__main__":
@craigmbooth
craigmbooth / nfl_height_weight.csv
Created December 22, 2015 16:26
CSV file containing height and weight data on all the players on 2013 NFL teams
number full_name position height_in_inches weight_in_lbs date_of_birth team
23 Alford, Robert CB 70 186 11/1/1988 ATL
95 Babineaux, Jonathan DT 74 300 10/12/1981 ATL
72 Baker, Sam T 77 301 5/30/1985 ATL
59 Bartu, Joplo OLB 74 230 10/3/1990 ATL
71 Biermann, Kroy OLB 75 255 9/12/1985 ATL
63 Blalock, Justin G 76 326 12/20/1983 ATL
5 Bosher, Matt P 72 208 10/18/1987 ATL
3 Bryant, Matt K 69 203 5/29/1975 ATL
51 Chaney, Jamar LB 72 242 10/11/1986 ATL
@craigmbooth
craigmbooth / .tmux.conf
Created December 9, 2013 00:00
My .tmux.conf.
##########################################################################
# _
# | |_ _ __ ___ _ ___ __
# | __| '_ ` _ \| | | \ \/ /
# | |_| | | | | | |_| |> <
# . \__|_| |_| |_|\__,_/_/\_\.conf
#
##########################################################################
#C-o doesn't conflict with too much in Emacs
unbind-key C-b
@craigmbooth
craigmbooth / teams.txt
Created October 15, 2013 16:53
List of NFL teams, host cities and names for use by the iPython notebook that scrapes the web for player heights and weights.
ATL - Atlanta - FALCONS
BUF - Buffalo - BILLS
CHI - Chicago - BEARS
CIN - Cincinnati - BENGALS
CLE - Cleveland - BROWNS
BAL - Baltimore - RAVENS
DAL - Dallas - COWBOYS
DEN - Denver - BRONCOS
DET - Detroit - LIONS
GB - Green Bay - PACKERS
@craigmbooth
craigmbooth / ParseNFLHeightWeight.ipynb
Last active December 25, 2015 14:59
ipython notebook that takes the file teams.txt, goes to nfl.com and scrapes the team roster for each time and puts the output into a SQLite database. Also requires file teams.txt, which is also in my github gists.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@craigmbooth
craigmbooth / matrix_multiply.sql
Created May 18, 2013 16:13
Sparse matrix multiply in SQL
-- Join columns to rows, group by rows and columns, then filter to get the cell you want.
SELECT A.row_num, B.col_num, SUM(A.value*B.value)
FROM A,B
WHERE A.col_num=B.row_num
GROUP BY A.row_num, B.col_num;