A place to collect some code snippets I seem to usually need and forget at the same time...
import some_package
some_package.__version__
import some_module
dir(some_module)
$ pip list | grep the_pip_package_you_seek
pip install git+https://github.com/username/repo-name.git@commit-hash
import torch
torch.cuda.device_count()
import torch
torch.cuda.set_device(device_num)
cat /usr/local/cuda/version.txt
or with nvcc installed:
$ nvcc --version
Install nvcc:
$ (sudo) apt install nvidia-cuda-toolkit
$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
$ nvidia-smi
$ pip install gpustat
$ gpustat -cp
$ CUDA_VISIBLE_DEVICES=0 python some_script.py
or
$ export CUDA_VISIBLE_DEVICES=0
$ python some_script.py
In the example we replace all *.JPG files with *.jpg:
$ find . -name "*.JPG" -exec bash -c 'mv "$1" "${1%.JPG}".jpg' - '{}' \;
$ ls -lR | grep jpg | wc -l
#!/bin/bash
for pkg in *.tar; do
where="${pkg%.tar}"
echo $where
[ -d "$where" ] || mkdir -p "$where"
tar xfv $pkg -C "$where"
done
$ nginx -t
$ systemctl restart nginx
$ tmux list-sessions
$ tmux attach-session -t #tmux_session_id
Ctrl+b d
$ tmux kill-session -t SESSION_ID
Ctrl+b %
Ctrl+b "
Ctrl+b o
Ctrl+b z
# Use again to zoom out again
Ctrl+b x
Ctrl+b, Alt+1
Or (default on Ubuntu)
Ctrl+b, Esc+1
$ cat /etc/*-release
#!/bin/sh
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
sudo apt-get autoclean -y
if [ -f "/var/run/reboot-required" ]; then
/bin/cat /var/run/reboot-required
fi
$ uname -r
Ipbastola: Safest way to clean up boot partition
# Running containers
$ docker ps
# Local container images
$ docker images
$ docker build -t container_tag_name .
# -d: detached
# -p: external_port:internal_port
# --name: running container name
# (frontend): container_tag_name
$ docker run -d -p 8080:80 --name=frontendlocal frontend
$ docker exec -it container_name /bin/bash
(note: the --network flag is not mentioned in the docs, but I needed it to fix a connection problem)
$ docker run -e VIRTUAL_HOST=DNS_NAME --network=nginx-proxy -d zerotosingularity_site
$ docker rmi -f <image_id>
$ docker rmi $(docker images | grep none | awk '{print $3}')
$ docker system prune -a
$ conda env update
$ conda create --name myenv
$ conda env create -f environment.yml
$ conda create -n myenv python=3.6 # change 'myenv' and '3.6' to your values
$ conda info --envs
# OR
$ conda env list
conda list -e > requirements.txt
conda env remove --name ENV_NAME
$ python -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2
$ python3 -c 'import tensorflow as tf; print(tf.__version__)' # for Python 3