Skip to content

Instantly share code, notes, and snippets.

View nmichlo's full-sized avatar
🐋

Nathan nmichlo

🐋
View GitHub Profile
@nmichlo
nmichlo / make_submission.sh
Last active February 19, 2020 09:39
Python Fatfile Packager - Stickytape
#!/bin/bash
# get the directory that this script is in so you can call it from anywhere
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# your output folder, where sub0MyAgent.py.zip will be placed
# TODO: EDIT
out_dir="$script_dir/submissions/latest"
# locations of your files
@nmichlo
nmichlo / remove_tuxera.sh
Created December 15, 2020 19:45 — forked from miguelmota/remove_tuxera.sh
Completely uninstall and remove Tuxera NTFS on MacOS (resets trial version)
unload_files=(
"/Library/LaunchAgents/com.tuxera.ntfs.agent.plist"
)
for unload_file in "${unload_files[@]}"; do
echo "Unloading: ${unload_file}"
launchctl unload "${unload_file}"
echo
done
@nmichlo
nmichlo / portrait_ig_pad.py
Last active January 20, 2021 08:41
Pad portrait images that do not fit for instagram.
import imageio
import numpy as np
import sys
import os
import imagesize
if __name__ == '__main__':
assert len(sys.argv) >= 2, 'must supply at least 1 file argument'
@nmichlo
nmichlo / pytorch_pca_svd.py
Created March 22, 2021 20:32
PCA with SVD using pytorch
def torch_pca_svd(X, center=True):
n, _ = X.shape
# center points along axes
if center:
X = X - X.mean(dim=0)
# perform singular value decomposition
u, s, v = torch.svd(X)
# extract components
components = v.T
explained_variance = torch.mul(s, s) / (n-1)
@nmichlo
nmichlo / cluster-disk-info.bash
Last active March 29, 2021 14:33
Quick MS Cluster disk debug information.
#!/bin/bash
# TPS corresponds to IOPS:
# https://en.wikipedia.org/wiki/IOPS
function cluster-disk-info() {
folders="/tmp /home-mscluster/ /scratch"
# disk space
df -h -P $folders
disks=$(df -h -P $folders | perl -n -e '/.*.dev.(...).*/ && print "$1 "')
@nmichlo
nmichlo / check_cyclic.py
Created August 2, 2021 10:26
Check for cyclic dependencies in a python project
# ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
# MIT License
#
# Copyright (c) 2021 Nathan Juraj Michlo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@nmichlo
nmichlo / ordered_dithering.py
Created August 23, 2021 16:41
Ordered Dithering
@functools.lru_cache()
def dither_matrix(n: int):
assert isinstance(n, int) and (n > 0)
if n == 1:
return np.array([[0]])
matrix = (1/n**2) * np.asarray(np.bmat([
[n**2 * dither_matrix(int(n/2)) + 0, n**2 * dither_matrix(int(n/2)) + 2],
[n**2 * dither_matrix(int(n/2)) + 3, n**2 * dither_matrix(int(n/2)) + 1],
]))
matrix.flags.writeable = False # because we are caching this
@nmichlo
nmichlo / torchsort_dims.py
Created March 14, 2022 13:10
torchsort but allow specifying the dimension
from functools import lru_cache
from typing import Tuple
from typing import Union
import numpy as np
import torch
# ========================================================================= #
@nmichlo
nmichlo / tasks.py
Created July 27, 2021 10:58
task handler
import dataclasses
import inspect
from functools import lru_cache
from typing import Any
from typing import Dict
from typing import Set
from typing import Tuple
from typing import Union
@nmichlo
nmichlo / run_streamlit.py
Last active June 22, 2022 23:29
Run streamlit directly from python without the command line.
# Copyright (c) 2020 Nathan Juraj Michlo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all