Skip to content

Instantly share code, notes, and snippets.

View drscotthawley's full-sized avatar
Solving environment /

Scott H. Hawley drscotthawley

Solving environment /
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drscotthawley
drscotthawley / run_on.ipynb
Last active October 6, 2025 15:23
demo script for switching function execution between solveit @ Modal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drscotthawley
drscotthawley / cnn_res_vae.py
Last active October 30, 2025 08:58
Code & utils re. a convolutional VAE with residual connections
import torch
from torch import nn
import matplotlib.pyplot as plt
import torch.nn.functional as F
import wandb
class ResidualBlock(nn.Module):
def __init__(self, channels, use_skip=True, use_bn=True, act=nn.GELU):
super().__init__()
@drscotthawley
drscotthawley / fix_notebook.py
Last active October 2, 2025 21:49
fixes up jupyter notebook widgets state so GitHub can visualize notebooks again
# Usage: python fix_notebook.py <.ipynb file>
# WARNING: this overwrites the file, so save a backup first
# To execute on a whole folder of files, run this bash command:
# find . -name "*.ipynb" -exec python fix_notebook.py {} \;
import json
import sys
def fix_notebook(filename):
@drscotthawley
drscotthawley / pysync.sh
Last active February 13, 2025 21:36
bash function to rsync Python files in dir & subdirs so I can just use VSCode locally since their Remote eats up server resources
# syncs python files in dir and subdirs so you don't have to run resource-hogging VSCode Remote
# usage: pysync /path/to/local/directory/ user@remote:/path/to/remote/directory/
# UPDATED version: more code than before, but now it follows symbolic links on the remote server instead of just overwriting them
pysync() {
if [ "$#" -ne 2 ]; then
echo "Usage: pysync <source> <destination>"
return 1
fi
fswatch -o "$1" | while read f; do
@drscotthawley
drscotthawley / run-config.py
Created January 4, 2025 23:36
Wrapper to run another script with CLI args read from a JSON config file stored on WandB; allows override via new CLI args. Gen'd by Claude 3.5 Sonnet.
#!/usr/bin/env python3
import json
import subprocess
import argparse
import sys
import os
def parse_override_args(args):
"""Parse CLI arguments that start with '--' into a dict."""
overrides = {}
@drscotthawley
drscotthawley / audio_data2url.py
Last active September 3, 2024 19:52
Move audio data in Jupyter notebooks to external urls stored on separate Git branch
#!/usr/bin/env python3
# audio_data2url.py
# Author: Scott H. Hawley
# License: MIT
# Date: Sep 2, 2024
# Description: This script will convert base64 audio src data in a Jupyter notebook to URLs of the same audio
# which is saved in a separate branch of the same GitHub repository. The script will save the audio files in a
# directory named 'audio_files' and commit them to the 'audio-storage' branch. The script will then replace the
# base64 data with the raw URL of the audio file in the notebook. The script can be run on a single notebook file
@drscotthawley
drscotthawley / dualsense_listener.py
Last active December 2, 2023 13:49
PS5 DualSense Controller Listener
#! /usr/bin/env python
# OS-Agnostic PS5 DualSense Controller Listener
# Author: Scott H. Hawley
# Instructions:
# 1. Pair the DualSense controller with your computer
# 2. Install hidapi system binary, e.g. on Mac: brew install hidapi
# 3. Install Python packages: pip install hidapi pygame numpy
# 4. Run this script!
@drscotthawley
drscotthawley / tailtop
Last active June 15, 2023 17:02
bash aliases for SLURM: "tailjob <jobid>" or just "tailtop" for most recent job
# tails output of any SLURM job that is listed in the queue.
# if job is pending, tailjob will wait until the output file exists
# usage: tailjob <job_id>
tailjob() {
local job_id=$1
if [[ -n "$job_id" ]]; then
local stdout_file=$(scontrol show job "$job_id" | awk -F= '/StdOut=/{print $2}')
echo "Running tail -F $stdout_file"
tail -F "$stdout_file"
else
@drscotthawley
drscotthawley / rearrangewrapper.py
Last active October 30, 2022 01:52
Wrapper to give einops.rearrange an "inverse"
from einops import rearrange as _rearrange
class RearrangeWrapper():
"wrapper to endow einops.rearrange with an 'inverse' operation"
def __init__(self):
self.shape, self.s = None, None # just in case someone tries to call inverse first
def __call__(self, x, s:str, **kwargs): # this 'forward' call is lightweight to preserve original usage
self.shape, self.s = x.shape, s
return _rearrange(x, s, **kwargs)