Skip to content

Instantly share code, notes, and snippets.

View leopd's full-sized avatar

Leo Dirac leopd

View GitHub Profile
@leopd
leopd / zfs-delegate-all.sh
Created January 25, 2021 23:58
Delegating all permissions to myself on zfs
sudo zfs allow -s @allperm allow,clone,create,destroy,mount,promote,receive,rename,rollback,send,share,snapshot rustinside
sudo zfs allow leo @allperm rustinside
@leopd
leopd / block_dataset.py
Last active July 30, 2020 19:42
Rough idea of how to write a block-oriented prefetching dataset wrapper for pytorch.
import functools
from torch.utils.data import Dataset
class BlockCachingDatasetWrapper(Dataset):
"""Wraps a pytorch dataset with an LRU cache
that fetches an entire block of records at once.
"""
def __init__(self, base_dataset:Dataset, block_size:int=16):
self._dataset = base_dataset
@leopd
leopd / overthrow-master.sh
Created June 30, 2020 21:54
How to make your source control a little less racist
#!/bin/bash
git checkout -b main
git branch --delete master
git push origin main
echo "Go to github, Settings, Branches, Default branch, main, update."
read -p "Press enter when done: " dontcare
git push origin --delete master
@leopd
leopd / pick-gpu.py
Created June 17, 2020 17:00
How to use a specific GPU, not just the first one
# How to use a specific GPU other than the first one.
# Put this at the very top of your python script or notebook.
# Do this before importing your deep learning libraries.
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1'
@leopd
leopd / setup-git-dag.sh
Created January 3, 2020 20:05
Git dag - visualize git graph in ascii-color
#!/bin/bash
git config --global alias.dag "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches"
# This adds a line to ~/.gitconfig like
# [alias]
# dag = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches
@leopd
leopd / almost-attention.py
Last active April 21, 2023 22:35
Explanatory (non-vectorized) code for how attention works
# This code doesn't work, and isn't intended to.
# The goal of this code is to explain how attention mechansisms work, in code.
# It is deliberately not vectorized to make it clearer.
def attention(self, X_in:List[Tensor]):
# For every token transform previous layer's out
for i in range(self.sequence_length):
query[i] = self.Q * X_in[i]
key[i] = self.K * X_in[i]
value[i] = self.V * X_in[i]
@leopd
leopd / file_reader_dataset.py
Last active June 8, 2019 15:47
PyTorch Dataset class to access line-delimited text files too big to hold in memory.
from functools import lru_cache
import subprocess
from torch.utils.data import Dataset
class FileReaderDataset(Dataset):
"""Exposes a line-delimited text file as a PyTorch Dataset.
Maintains an LRU cache of lines it has read, while supporting random access into
files too large to hold in memory. Memory requirement still scales by O(N), but just
for pointers into the file, about 8 bytes per line. After the file has been scanned,
random access will be very fast - as fast as the disk plus the OS's cache of it.
@leopd
leopd / gist:6b1e5875305f6dde6556
Created October 10, 2014 15:56
Configuring a new linux login
set -o vi # Switch bash to vi mode
@leopd
leopd / .vimrc
Created September 4, 2013 19:10
My .vimrc file
" turn off compatibility with the old vi
set nocompatible
set ts=4
set et
" turn syntax highlighting on by default
syntax on
" set auto-indenting on for programming
@leopd
leopd / groupby.js
Created August 28, 2013 15:37 — forked from srleo/groupby.js
count_by = function(collection,field) {
return collection.aggregate({
$group: {
_id: "$" + field,
count: { $sum: 1 }
}
})
}
 
count_by(db.vid10,'char');