Skip to content

Instantly share code, notes, and snippets.

View leopd's full-sized avatar

Leo Dirac leopd

View GitHub Profile
@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 / 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 / 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 / FifteenPuzzle.java
Created July 13, 2013 22:42
Solving the fifteen puzzle in Java using A* and Dijkstra's algorithm.
package algostudy;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
@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