Skip to content

Instantly share code, notes, and snippets.

View nmichlo's full-sized avatar
🐋

Nathan nmichlo

🐋
View GitHub Profile
@nmichlo
nmichlo / xterm_control_sequences.py
Last active January 27, 2024 15:12
XTerm Control Sequences
# XTerm Control Sequences based on:
# - https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
# ========================================================================= #
# XTerm Control Sequences from invisible-island.net as pythonic code.
# Basic control sequences are string variables.
# - eg: ESC = '\033'
# CSI = ESC + '['
# Control sequences that have args can be called to return a string.
# - eg: sgr = CSI + Ps + 'm'
@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 / colab_vscode.py
Last active October 4, 2022 09:59
Run vscode on colab!
# Adapted from https://amitness.com/vscode-on-colab
# Copy this script into a colab cell
# install deps if needed
!(command -v "code-server" 1>/dev/null) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
!(python -c "import pyngrok" 2>/dev/null) || (pip install -qqq pyngrok)
# run vscode in background if needed
!(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)
@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
@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 / available_pypi_synonyms.py
Last active June 26, 2022 00:34
available pypi synonyms
# check for available pypi synonyms of a given word
# $ available_pypi_synonyms.py <words...>
import argparse
import itertools
import re
import diskcache as dc
import requests
from bs4 import BeautifulSoup
@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