Skip to content

Instantly share code, notes, and snippets.

@harryscholes
harryscholes / pretty_print_class_attrs.py
Created November 16, 2017 16:19
Pretty print Python class attrs
def attr_printer(cls, indentation=0):
for attr_name in getattr(cls, "__dict__"):
attr = getattr(cls, attr_name)
print(" " * indentation, attr_name, "=", attr)
if hasattr(attr, "__dict__"): # recursion
indentation+=1
attr_printer(attr, indentation)
@harryscholes
harryscholes / pretty_print_class_attrs2.py
Last active April 16, 2018 15:39
Pretty print Python class attrs
import jsonpickle # pip install jsonpickle
import json
def pprint_obj(obj, max_depth=None):
"""Pretty print all attributes of an object recursively.
Arguments:
obj (object): object whose attributes are to be printed
max_depth (int, optional): maximum recursion depth
"""
@harryscholes
harryscholes / hide_jupyter_code.sh
Created November 23, 2017 17:58
Hide code when presenting Jupyter notebooks with RISE
pip install hide_code
jupyter nbextension install --py hide_code
jupyter nbextension enable --py hide_code
jupyter serverextension enable --py hide_code
@harryscholes
harryscholes / xkcd_password_generator.py
Last active April 16, 2018 16:01
Password generator inspired by xkcd #936
import requests, secrets
url = "https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt"
words = requests.get(url).text.split("\n")
def generate_password(length=4,
min_word_length=4,
max_word_length=8,
as_string=False):

Keybase proof

I hereby claim:

  • I am harryscholes on github.
  • I am harryscholes (https://keybase.io/harryscholes) on keybase.
  • I have a public key ASB46XcHPdiNgGh6EaQhhLHvrpQGAMwzN0FLjDAHulJ65wo

To claim this, I am signing this object:

@harryscholes
harryscholes / README.md
Last active February 20, 2018 16:30
Build Tensorflow from source on macOS into Conda environment

Why?

Build Tensorflow from source to make use of all supported processor instructions.

Requirements

  • git
  • brew
  • anaconda
@harryscholes
harryscholes / ud730.sh
Created February 22, 2018 13:34
Google Deep Learning Udacity course Docker image
# First time
docker run -p 5000:8888 --name tensorflow-udacity -it gcr.io/tensorflow/udacity-assignments:1.0.0
# Subsequently
docker start -ai tensorflow-udacity
@harryscholes
harryscholes / tf_cs_cluster.sh
Last active February 28, 2018 13:08
Run TensorFlow on UCL CS cluster
###########
## Shell ##
###########
qrsh -verbose -l tmem=1G,gpu=1 -P gpu
echo $CUDA_VISIBLE_DEVICES
source /share/apps/examples/tensorflow-1.4.0.sh
@harryscholes
harryscholes / easyplot.py
Last active March 20, 2018 10:41
Automate repetitive plotting commands in Python using a context manager
from contextlib import contextmanager
import matplotlib.pyplot as plt
@contextmanager
def easyplot(filename, nrows=1, ncols=1, figsize=(6, 6), *,
x="", y="", tight_layout=True, savefig=True, **kw):
fig, ax = plt.subplots(nrows, ncols, figsize=figsize, **kw)
@harryscholes
harryscholes / OffsetArrays.jl
Created April 2, 2018 18:03
Subtyping Julia Arrays with offset indexing
module OffsetArrays
export OffsetArray
importall Base
immutable OffsetArray{T,N,A<:AbstractArray} <: AbstractArray{T,N}
array::A
offset::NTuple{N,Int}
end