Utilities
VSCode
# fix VSCode update permissions on macOS
sudo chown -R $USER ~/Library/Caches/com.microsoft.VSCode.ShipIt
sudo chown -R $USER /Applications/Visual \ Studio \ Code.app
LaTeX
# installing LaTeX on macOS
brew install --cask basictex
tlmgr init-usertree
tlmgr --usermode install $PACKAGE_NAME
TikZ
# PDF to PNG
pdftoppm -png -singlefile -r 600 figure.pdf figure
# PDF to PNG
pdftocairo -png -singlefile -antialias best -r 600 figure.pdf figure
# additional options:
# -transp
pdfcrop --margins 10 in.pdf out.pdf
# margins are in bp, i.e. 1 bp = 1/72 inch
Claude Code
# install
curl -fsSL https://claude.ai/install.sh | bash
// keeps .git and .jj outside of devcontainer so that Claude
// is not able to destroy version history
// devcontainer.json
{
" mounts " : [
" source=${localEnv:HOME}/FOLDER,target=/workspace/FOLDER,type=bind " ,
" type=volume,target=/workspace/FOLDER/.git,volume-nocopy " ,
" type=volume,target=/workspace/FOLDER/.jj,volume-nocopy "
]
}
Codex
# linux
npm install -g @openai/codex
# macOS
brew install codex
~/.codex/config.toml model = "gpt-5.2"
model_reasoning_effort = "medium"
[features]
web_search_request = true
codex exec --skip-git-repo-check --image page-01.jpg,page-02.jpg,page-03.jpg -- "summarize" | glow
Dev Containers
npm i -g @devcontainers/cli
devcontainer up --workspace-folder .
docker ps
docker rm $CONTAINER_NAME
{
" mounts " : [
" source=claude-code-bashhistory-${devcontainerId},target=/commandhistory,type=volume " ,
" source=claude-code-config-${devcontainerId},target=/home/node/.claude,type=volume " ,
" source=${localEnv:HOME}/presslab,target=/workspace/presslab,type=bind " ,
" source=${localEnv:HOME}/laminar,target=/workspace/laminar,type=bind " ,
" type=volume,target=/workspace/presslab/.git,volume-nocopy " ,
" type=volume,target=/workspace/presslab/.jj,volume-nocopy "
" type=volume,target=/workspace/laminar/.git,volume-nocopy " ,
" type=volume,target=/workspace/laminar/.jj,volume-nocopy "
]
}
tmux
tmux break-pane -t : $WINDOW
set -g status 2
set -g status-format[1] ''
set -g message-line 2
Python
fire
# install
pip install fire
# run without code edits
python -m fire FILE FUNCTION
uv
tool.uv.sources
Specifies custom source locations (where to fetch dependencies)
Only used by uv, so use uv build --no-sources for builds that are be published.
uv sync
Use uv sync whenever pyproject.toml, uv.lock, and the current state of the virtual environment may be diverged.
Common cases: cloning/fetching a repository
uv sync
# keep "extra" packages (i.e. packages not found in lockfile) in the environment
uv sync --inexact
Deployment
PM2
# install PM2
apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash -
# setup completions
pm2 completion install
# check processes managed by PM2
pm2 list
# view process logs
pm2 logs
# install a startup script for PM2
pm2 startup
# freeze a process list for respawning
pm2 save
Deep learning
mamba create -n $ENV_NAME python= 3.11
mamba activate $ENV_NAME
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
pip install tqdm einops jaxtyping
pip install ipykernel ipywidgets
python -m ipykernel install --user --name " $ENV_NAME "
Jupyter
Install Jupyter notebook globally
pipx install notebook --include-deps # notebook 7.3.2
pipx inject notebook jupyterlab-vim jupyter-collaboration jupyterlab-freeze widgetsnbextension
Adding and removing IPython kernels
# list existing kernels
jupyter kernelspec list
# add a kernel
python -m ipykernel install --user --name " $ENV_NAME "
# remove a kernel
jupyter kernelspec uninstall " $ENV_NAME "
NVIDIA
# driver install
sudo apt-get install nvidia-headless- $VERSION -server
# CUDA install
mamba install cuda -c nvidia/label/cuda-12.8.1
JAX
pip install --upgrade "jax[cuda12]"
# check devices JAX recognizes
print ( jax.devices ())
# expected output: [CudaDevice(id=0)]
Equinox
pip install equinox
Utilities
# view OS version
cat /etc/os-release
JSON
# prettyify JSON file
jq . ugly.json > tidy.json
PDFs
# binarize scanned PDF file
ocrmypdf --force-ocr --deskew --unpaper-args "--type pbm --black-threshold 0.45 --white-threshold 0.85" --clean --clean-final -O 1 --jbig2-lossy --output-type pdf $INPUT_PDF $OUTPUT_PDF
# remove PDF/A annotation
brew install qpdf
qpdf --remove-metadata $INPUT_PDF --replace-input
Convert file types
# convert image to PDF
sips -s format pdf $INPUT --out $OUTPUT
Vim
" Throttle mouse wheel when the wheel input backlog is huge
" This is for Logitech MX Master free-scrolling
" Tuning knobs
let g:scroll_gate_threshold = get (g:, 'scroll_gate_threshold' , 1000 )
let g:scroll_gate_resume_at = get (g:, 'scroll_gate_resume_at' , 900 ) " hysteresis
let g:scroll_gate_tick_ms = get (g:, 'scroll_gate_tick_ms' , 10 )
let g:scroll_gate_batch_events = get (g:, 'scroll_gate_batch_events' , 50 )
let g:scroll_gate_disable_mouse = get (g:, 'scroll_gate_disable_mouse' , 0 )
" Internal state
let s:pending_up = 0
let s:pending_down = 0
let s:last_dir = 'down'
let s:timer_id = - 1
let s:mouse_saved = &mouse
let s:mouse_off = 0
function ! s:WheelLines () abort
" Try to respect 'mousescroll' (when available); fallback to 3 lines/event.
if exists ( '+mousescroll' )
" Example values: "ver:3,hor:6" or "ver:5"
let m = matchlist (&mousescroll, 'ver:\(\d\+\)' )
if len (m) > 1
return str2nr (m[ 1 ])
endif
endif
return 3
endfunction
function ! s:QueueLen () abort
return s:pending_up + s:pending_down
endfunction
function ! s:MaybeDisableMouse () abort
if ! g:scroll_gate_disable_mouse | return | endif
if s:mouse_off | return | endif
let s:mouse_saved = &mouse
set mouse =
let s:mouse_off = 1
endfunction
function ! s:MaybeEnableMouse () abort
if ! g:scroll_gate_disable_mouse | return | endif
if ! s:mouse_off | return | endif
let &mouse = s:mouse_saved
let s:mouse_off = 0
endfunction
function ! s:StopTimer () abort
if s:timer_id != - 1
call timer_stop (s:timer_id)
let s:timer_id = - 1
endif
endfunction
function ! s:Drain (timer) abort
" Avoid scrolling while in command-line or hit-enter prompts
if mode () =~# '^[cR]' || v: hlsearch ==# - 1
return
endif
let qlen = s:QueueLen ()
if qlen < = 0
call s:StopTimer ()
call s:MaybeEnableMouse ()
return
endif
let lines_per_event = s:WheelLines ()
let remaining = g:scroll_gate_batch_events
" Drain in a way that keeps the "feel" (prefer the last scroll direction),
" while compressing multiple wheel events into a single counted scroll.
while remaining > 0 && s:QueueLen () > 0
if s:last_dir ==# 'down'
if s:pending_down > 0
let n = min ([s:pending_down, remaining])
execute 'normal! ' . (n * lines_per_event) . "\<C-E>"
let s:pending_down - = n
let remaining - = n
elseif s:pending_up > 0
let s:last_dir = 'up'
endif
else
if s:pending_up > 0
let n = min ([s:pending_up, remaining])
execute 'normal! ' . (n * lines_per_event) . "\<C-Y>"
let s:pending_up - = n
let remaining - = n
elseif s:pending_down > 0
let s:last_dir = 'down'
endif
endif
endwhile
if s:QueueLen () < g:scroll_gate_resume_at
call s:MaybeEnableMouse ()
endif
endfunction
function ! ScrollGate (dir) abort
" a:dir is 'up' or 'down'
if s:QueueLen () >= g:scroll_gate_threshold
call s:MaybeDisableMouse ()
return "\<Ignore>" " swallow incoming wheel events while overloaded
endif
if a:dir ==# 'down'
let s:pending_down += 1
let s:last_dir = 'down'
else
let s:pending_up += 1
let s:last_dir = 'up'
endif
if s:timer_id == - 1
let s:timer_id = timer_start (g:scroll_gate_tick_ms, function ( 's:Drain' ), { 'repeat' : - 1 })
endif
return "\<Ignore>" " mapping already handled it
endfunction
" Map wheel in normal/visual/insert
nnoremap < silent >< expr > < S cr ollWheel Up > ScrollGate ( 'up' )
nnoremap < silent >< expr > < S cr ollWheel Down > ScrollGate ( 'down' )
xnoremap < silent >< expr > < S cr ollWheel Up > ScrollGate ( 'up' )
xnoremap < silent >< expr > < S cr ollWheel Down > ScrollGate ( 'down' )
inoremap < silent >< expr > < S cr ollWheel Up > ScrollGate ( 'up' )
inoremap < silent >< expr > < S cr ollWheel Down > ScrollGate ( 'down' )
" Some terminals report these names instead:
nnoremap < silent >< expr > < Mous eSc roll Up > ScrollGate ( 'up' )
nnoremap < silent >< expr > < Mous eSc roll Down > ScrollGate ( 'down' )
xnoremap < silent >< expr > < Mous eSc roll Up > ScrollGate ( 'up' )
xnoremap < silent >< expr > < Mous eSc roll Down > ScrollGate ( 'down' )
inoremap < silent >< expr > < Mous eSc roll Up > ScrollGate ( 'up' )
inoremap < silent >< expr > < Mous eSc roll Down > ScrollGate ( 'down' )
" Safety: restore mouse on exit
augroup ScrollGateRestore
autocmd!
autocmd VimLeavePre * call s:MaybeEnableMouse ()
augroup END
Web development
pnpm
# add a new package
pnpm add $PACKAGE
# remove a package
pnpm remove $PACKAGE
# install all added packages
pnpm install
# npm run <command>
pnpm < comman d >
Frontend
pnpm dlx shadcn@latest init
pnpm dlx shadcn@latest add button
pnpm dlx shadcn@latest add separator
pnpm dlx shadcn@latest add dropdown-menu
# next-themes
# https://ui.shadcn.com/docs/dark-mode/next
pnpm add next-themes
# GSAP animations
pnpm add gsap @gsap/react
Ubuntu
apt
# list APT source entries
# note: .list are classic one-line style for APT repos
# .sources are deb822 style for APT repos
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
WiFi
vim /etc/netplan/50-cloud-init.yaml
PyMOL
.. set labels in front always
set float_labels, on
YouTube
.. keyboard shortcuts
, previous frame
. next frame