Skip to content

Instantly share code, notes, and snippets.

Gavin Gray gngdb

Block or report user

Report or block gngdb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from scipy import optimize
from obj import PyTorchObjective
gngdb /
Last active Feb 11, 2020
Display Images from arrays and tensors in Python 3 (based on
from io import BytesIO
import PIL.Image
from IPython.display import clear_output, Image, display
def showarray(a, fmt='jpeg'):
a = a - a.min()
a = 255.*(a/a.max())
a = np.uint8(np.clip(a, 0, 255))
f = BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
View Index Cartesian Product.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
gngdb / Parameter Redundancy Through Time.ipynb
Last active Oct 17, 2019
Parameter redundancy from 5 pruning papers through time.
View Parameter Redundancy Through Time.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
gngdb /
Created Sep 17, 2019
Pointwise convolution in PyTorch without using conv2d.
import torch
from torch.nn.functional import conv2d
def pointwise(X, W):
n,c_in,h,w = X.size() # (n examples, c_in channels, height, width)
c_out,c_in,_,_ = W.size() # (c_out channels, c_in channels, 1, 1)
W = W.view(c_out,c_in) # squeeze size 1 dims, shape=(c_out, c_in)
X = X.view(n,c_in,h*w) # flatten spatial dims
X = X.permute(0,2,1) # transpose, shape=(n,h*w, c_in)
K = X.reshape(n*h*w,c_in) # kernel matrix, shape=(n*h*w, c_in)
gngdb / i3lock-bashrc
Created Sep 17, 2019
bashrc snippet for creating images for i3lock to use as a lockscreen background.
View i3lock-bashrc
# for making lockscreen images
set-i3lock-bg() {
if [ ! -f ~/lock.png ]; then
curl > ~/lock.png
SIZE=`xdpyinfo | grep dimensions | cut -d " " -f 7`
convert $1 -font Liberation-Sans \
-geometry $SIZE -gravity center\
-pointsize 26 -fill white -extent $SIZE -gravity center \
-annotate +0+160 "Type Password to Unlock" ~/lock.png \

So, you want to be able to work from anywhere. You want to be on a mountain somewhere, two bars of 3G signal, and you forward that to your laptop with a WiFi hotspot. Open your laptop and your shell on remote is already open and as responsive as possible. Work/life balance? With power like this, who cares?

Problem Scenario

Often, in academic institutions at least, you have the following situation:

gngdb / mosh-algo
Created Sep 9, 2019
Script for easy mosh connections
View mosh-algo
ALGO_IP=`ip addr | awk '
/^[0-9]+:/ {
sub(/:/,"",$2); iface=$2 }
/^[[:space:]]*inet / {
split($2, a, "/")
print iface" : "a[1]
}' | grep tun | cut -b 8- | cut -d "." -f 1-3 | sed 's/$/.1/'`
mosh --ssh="ssh -i algo.pem" ubuntu@$ALGO_IP
gngdb /
Last active Sep 6, 2019
Script to install algo requirements to a cloud shell environment.
sudo apt-get update && sudo apt-get install \
build-essential \
libssl-dev \
libffi-dev \
python-dev \
python-pip \
python-setuptools \
python-virtualenv -y
sudo pip2 install -r requirements.txt
You can’t perform that action at this time.