Skip to content

Instantly share code, notes, and snippets.

@craigmbooth
craigmbooth / solve_sudoku.py
Created July 12, 2012 12:55
Simple Sudoku Solver
"""Provides methods check_sudoku and solve_sudoku
Expects input of a list of 9 lists, each of length 9, representing
a Sudoku board. Unfilled numbers may be represented with a zero. For
example:
valid = [[5,3,4,6,7,8,9,1,2],
[6,7,2,1,9,5,3,4,8],
[1,9,8,3,4,2,5,6,7],
[8,5,9,7,6,1,4,2,3],
[4,2,6,8,5,3,7,9,1],
[7,1,3,9,2,4,8,5,6],
@craigmbooth
craigmbooth / generate_credit_card.py
Created July 15, 2012 19:56
Generate Valid Credit Card Number
"""Provides method generate(prefix,length), which for a given prefix and
total length will return a valid credit card number. generate returns
None for invalid inputs.
Credit card numbers have the following form: PPPPPP NNNNNNNNN C
Where P is a prefix that identifies the issuing authority, N is an
account number and C is a checksum digit, calculated with Luhn's
algorithm.
@craigmbooth
craigmbooth / .gitignore
Last active December 12, 2015 01:48
My default .gitignore file. Deals with the common extensions that I have to ignore, including LaTeX temporary files and Emacs temporary files
# Compiled files
################
*.o
*.so
*.mod
# Emacs temporary files
#######################
*~
\#*\#
@craigmbooth
craigmbooth / nloadct.pro
Created February 5, 2013 18:29
This is my replacement for IDL's loadct command. It is pretty much interchangable with the default version but the number of colour tables runs over 100. Also allows easy creation of new colour tables by automatic interpolation from a series of rgb values.
;+
; NAME:
; NLOADCT
;
; PURPOSE:
; Load predefined color tables.
;
; CATEGORY:
; Image display.
;
@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;
@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 / 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 / .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 / 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 / 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__":