Skip to content

Instantly share code, notes, and snippets.

View npyoung's full-sized avatar

Noah Young npyoung

  • Mashgin, Inc
  • Palo Alto
View GitHub Profile
@npyoung
npyoung / .bashrc
Last active July 3, 2026 21:59
Auto-attach to most recent tmux session on ssh
# Auto-attach to most recently used tmux session on SSH login, or start fresh
if [[ -n "$SSH_CONNECTION" && -z "$TMUX" ]]; then
last_session=$(tmux list-sessions -F "#{session_last_attached}|#{session_name}" 2>/dev/null | sort -rn | head -1 | cut -d'|' -f2)
if [[ -n "$last_session" ]] && tmux has-session -t "$last_session" 2>/dev/null; then
exec tmux attach-session -t "$last_session" 2>/dev/null || exec bash
else
exec tmux 2>/dev/null || exec bash
fi
fi
@npyoung
npyoung / joy.py
Created February 24, 2022 23:45
Apply Joy Division to your timeseries data
import numpy as np
from scipy.signal.windows import hamming
class Joy:
def __truediv__(cls, arr):
T, N = arr.shape
spacer = 2 * np.arange(N)
t = np.arange(T)
window = hamming(T)
normed = (arr - arr.mean(0)) / (1e-3 + arr.std(0))
@npyoung
npyoung / movietools.py
Last active July 3, 2020 06:47
Video creation and editing tools
import argparse as ap
from pathlib import Path
import ffmpeg
def compress(in_file):
out_file = in_file.parent / (in_file.stem + ' (1440p)' + in_file.suffix)
opts = {
'c:a': 'copy',
'c:v': 'libx265',
'crf': '24',
@npyoung
npyoung / kspmod.py
Created March 16, 2020 05:08
Install a KSP mod from github
#!/usr/bin/env python
import argparse as ap
import re
import requests
import json
from tempfile import TemporaryFile
from zipfile import ZipFile
def main(project_path, ksp_path):
@npyoung
npyoung / killport
Last active September 26, 2019 19:19
Kill process on port
ports=$(lsof -t -i tcp:$1);
for port in $ports; do
echo "killing PID $port";
kill $port;
done
@npyoung
npyoung / htoprc
Created August 16, 2019 01:41
Settings for htop that work well with many-cored machinse
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=46
sort_direction=-1
hide_threads=0
hide_kernel_threads=1
hide_userland_threads=0
shadow_other_users=0
show_thread_names=0
@npyoung
npyoung / awstools
Created November 4, 2018 09:39
Some shortcuts to make your life easier when your work machine lives in EC2
#!/usr/bin/env python
# Drop this in your ~/bin folder and chmod u+x it for maximum slickness
import click
import boto3
import subprocess
ec2 = boto3.resource('ec2')
def instances_by_name(name):
@npyoung
npyoung / design_doublets.py
Created October 2, 2018 02:21
Rough dual lens design
import argparse as ap
if __name__ == "__main__":
parser = ap.ArgumentParser()
parser.add_argument('f', type=float, help="Overall focal length")
parser.add_argument('library', type=int, nargs='+', help="Focal length of available lenses")
args = parser.parse_args()
f = args.f
fs = args.library
@npyoung
npyoung / codeserver.service
Last active October 9, 2019 06:46
Run jupyter lab as a userspace service
# Place this in ~/.config/systemd/user
[Unit]
Description=Code Server IDE
After=network.target
[Service]
Type=simple
EnvironmentFile=/home/ubuntu/.profile
WorkingDirectory=/home/ubuntu
Restart=on-failure
@npyoung
npyoung / dark_lab.mplstyle
Last active March 30, 2020 18:00
Dark Matplotlib theme for Jupyter Lab
# Set transparent background default line colors to white.
lines.color: white
patch.edgecolor: white
text.color: white
axes.facecolor: ffffff00
axes.edgecolor: white
axes.labelcolor: white