Skip to content

Instantly share code, notes, and snippets.

@ancri
ancri / same_length.txt
Last active March 18, 2024 21:18
lucky coincidences of words that end up being the same number of characters
It's pleasant when code lines up. Recording here oft-used-together words have the same length:
train
valid
prediction from
actual value in
pred
resp
@ancri
ancri / gist:ea4b923692f2d0954a5228700f3e1d44
Created November 17, 2023 02:35
connect to jupyter session on remote server via ssh
(optional) set up pubkey authorization
(taken from https://unix.stackexchange.com/questions/23291/how-to-ssh-to-remote-server-using-a-private-key)
$ scp -p your_pub_key.pub user@host:
$ ssh user@host
$ cat id_dsa.pub >> ~/.ssh/authorized_keys
make sure this is in ~/.ssh/config on the remote:
PubkeyAuthentication yes
from contextlib import contextmanager
@contextmanager
def optional(condition, context_manager):
# taken from https://stackoverflow.com/a/41251962/12558195
if condition:
with context_manager:
yield
else:
yield
@ancri
ancri / auto_linear_input_size.py
Last active May 19, 2022 09:57
Quickly calculate required Linear layer input size in a Conv --> Linear architecture
# Below is a cheeky little utility that helps you
# avoid doing all the tedious math by piggy-backing
# on torch’s error messages. The assumption is that
# net is your Module which is composed of a sequence
# of input shape-agnostic layers (such as Conv & ReLU
# & BatchNorm & MaxPool layers), followed at some
# point by a flattening and a linear layer whose required
# size you’re trying to figure out. height and width
# refer to your desired input image shape.