LaTeX
# installing LaTeX on macOS
brew install --cask basictex
tlmgr init-usertree
tlmgr --usermode install $PACKAGE_NAME
Software 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
Software development
Codex
# linux
npm install -g @openai/codex
# macOS
brew install codex
~/.codex/config.tomlmodel = "gpt-5.2"
model_reasoning_effort = "medium"
[features]
web_search_request = true
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.95" --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> <ScrollWheelUp> ScrollGate('up')
nnoremap <silent><expr> <ScrollWheelDown> ScrollGate('down')
xnoremap <silent><expr> <ScrollWheelUp> ScrollGate('up')
xnoremap <silent><expr> <ScrollWheelDown> ScrollGate('down')
inoremap <silent><expr> <ScrollWheelUp> ScrollGate('up')
inoremap <silent><expr> <ScrollWheelDown> ScrollGate('down')
" Some terminals report these names instead:
nnoremap <silent><expr> <MouseScrollUp> ScrollGate('up')
nnoremap <silent><expr> <MouseScrollDown> ScrollGate('down')
xnoremap <silent><expr> <MouseScrollUp> ScrollGate('up')
xnoremap <silent><expr> <MouseScrollDown> ScrollGate('down')
inoremap <silent><expr> <MouseScrollUp> ScrollGate('up')
inoremap <silent><expr> <MouseScrollDown> ScrollGate('down')
" Safety: restore mouse on exit
augroup ScrollGateRestore
autocmd!
autocmd VimLeavePre * call s:MaybeEnableMouse()
augroup END