Skip to content

Instantly share code, notes, and snippets.

View npyoung's full-sized avatar

Noah Young npyoung

  • IndustrialNext
  • San Francisco
View GitHub Profile
@npyoung
npyoung / rl.py
Last active April 6, 2018 19:55
Simple Richardson-Lucy 3D on the CPU for testing purposes.
#!/usr/bin/env python3
import numpy as np
def centered(arr, newshape):
# Return the center newshape portion of the array.
newshape = np.asarray(newshape)
currshape = np.array(arr.shape)
startind = (currshape - newshape) // 2
endind = startind + newshape
myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
@npyoung
npyoung / makevid.sh
Created April 11, 2018 02:57
Frames to video
ffmpeg -pattern_type glob -i "img *.png" -c:v libx264 -crf 18 -pix_fmt yuv420p -preset slow -r 60 out.mp4
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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',