Skip to content

Instantly share code, notes, and snippets.

View hughdbrown's full-sized avatar

Hugh Brown hughdbrown

View GitHub Profile
@hughdbrown
hughdbrown / nvidia-debugdump.txt
Created June 1, 2017 21:12
nvidia-debugdump
{17-06-01 15:10}lambda-devbox:~ ubuntu% nvidia-debugdump -l
Found 4 NVIDIA devices
Device ID: 0
Device name: Graphics Device (*PrimaryCard)
GPU internal ID: 0321017145676
Device ID: 1
Device name: Graphics Device
GPU internal ID: 0321017095492
@hughdbrown
hughdbrown / osx-install-xgboost.sh
Created May 31, 2017 13:12
Install xgboost on OSX
#!/bin/sh
brew install gcc@5
sudo -H pip install --upgrade --force xgboost
@hughdbrown
hughdbrown / fibonacci.py
Created May 17, 2017 04:36
Function to calculate fibonacci function
import numpy as np
m = np.matrix([[1, 1], [1, 0]])
def fib(n):
return (m ** n)[0, 1]
@hughdbrown
hughdbrown / fixer.py
Created May 1, 2017 04:49
Python code to remove duplicate files with soft links. Good for video courses that put the same course into multiple directories.
#!/usr/bin/env python
from __future__ import print_function
from hashlib import sha1
from collections import defaultdict
import os.path
import os
def calc_sha(filename, size=256 * 1000 * 1000):
@hughdbrown
hughdbrown / find_empty_folders.py
Created April 3, 2017 20:41
List directories that are empty
#!/usr/bin/env python
from __future__ import print_function
import os
import os.path
def find_empty_folders(start_dir='.'):
for root, dirs, files in os.walk(start_dir):
for d in dirs:
fulldir = os.path.join(root, d)
@hughdbrown
hughdbrown / mobility.py
Last active April 2, 2017 21:27
How correlated is rank of most mobile cities versus rank of most foreign-born cities?
#!/usr/bin/env python
from __future__ import print_function
from re import compile
from abc import abstractmethod
from scipy.stats import spearmanr, pearsonr, linregress
import numpy as np
import matplotlib.pyplot as plt
@hughdbrown
hughdbrown / bash-prefix.sh
Created March 23, 2017 14:44
How bash scripts should start
set -o errexit
set -o nounset # same as 'set -u'
set -o pipefail
# See notes in:
# http://www.davidpashley.com/articles/writing-robust-shell-scripts/
@hughdbrown
hughdbrown / progressbar-test.py
Last active February 16, 2017 17:24
Use of python progressbar
# pip install progressbar2
import time
from progressbar import (
ProgressBar,
Percentage, Bar, ETA,
)
values = list(range(1, 10 + 1))
with ProgressBar(widgets=[Percentage(), Bar(), ETA()], max_value=len(values)) as pbar:
for i in values:
@hughdbrown
hughdbrown / caesar-cipher-solve.py
Created November 11, 2016 18:55
Produce candidates for solution of a Caesar cipher using a dictionary
from os.path import expanduser
def match_word(pattern, wordfile=None):
wordfile = wordfile or os.path.expanduser("~/Downloads/sowpods.txt")
with open(wordfile) as handle:
for line in handle:
word = line.rstrip().lower()
lookup = {c: d for c, d in zip(pattern, word)}
if "".join(lookup.get(c, '!') for c in pattern) == word:
@hughdbrown
hughdbrown / sync-files.py
Created September 27, 2016 19:27
Move updated files from src directory to dst directory
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
from collections import defaultdict
from fnmatch import fnmatch
from pprint import pprint
from hashlib import sha1