Wang Yuqi's Blog

Cheat Sheet

Tmux

(sudo) apt install tmux # for Ubuntu
tmux new -s mysession
tmux attach -t mysession
tmux detach
tmux ls
tmux kill-session -t mysession
tmux rename-session -t old-session-name new-session-name

Conda

conda env list
conda create -n py311 python=3.11
conda remove --name ENVIRONMENT --all
echo 'export PATH=/path/to/anaconda3/bin:$PATH' >> ~/.bashrc

Git

# local
git config user.name "Your Name Here"
git config user.email your@email.example
# global
git config --global user.name "Your Name Here"
git config --global user.email your@email.example

# push a existing local repo to remote
git remote add origin git@github.com:<username>/<reponame>.git
git branch -M main
git push -u origin main

Slurm

# show idle cpus and free memory
sinfo -o "%n %e %m %a %c %C"
# show resources the job uses
scontrol show job [job_id]
# run execution time of a finish job
sacct --format=JobID,JobName,Elapsed,Start,End

Shell

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

# linter
autopep8 --in-place --aggressive --aggressive <filename>

# substr
string='My long string'
if [[ $string == *"My long"* ]]; then
  echo "It's there!"
fi

# file exists
if [ -e tmp.txt ]
then
    echo "exist"
else
    echo "not exist"
fi

# memory size
grep MemTotal /proc/meminfo

# basename of a file
stem=$(basename "${file}" .gz)
$(basename NAME [SUFFIX])
$(basename OPTION NAME)

# wget till success
while true;do
  wget -T 15 -c http://example.com && break
done

ls -lrt | awk '{ total += $5 }; END { print total }'

HugginceFace

# ssh config
eval `ssh-agent -s`
ssh-add ~/.ssh/id_ed25519

git lfs track *.parquet

git@hf.co:<username>/<name of model> 

Markdown

foldable markdown cheatsheet

Torch

python -m torch.utils.collect_env