Skip to content

Instantly share code, notes, and snippets.

@rajesh-s
Last active March 11, 2024 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajesh-s/c2b5a475da66b3fe6533efca3c1315cf to your computer and use it in GitHub Desktop.
Save rajesh-s/c2b5a475da66b3fe6533efca3c1315cf to your computer and use it in GitHub Desktop.
Reference to get around

Reference to get around

Screen

screen -S <session_name>
screen -ls
screen -r <attach_to_session>
Ctrl + A and then D to detach
screen -X -S <screen session> quit
# Enabled scrolling in screen. Add following lines in ~/.screenrc
# Enable mouse scrolling and scroll bar history scrolling
termcapinfo xterm* ti@:te@

Docker

Install docker https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

# Running containers
docker ps
# Copying files
docker cp containerId:source_path destination_path
# Access other cmd as user
sudo chmod 666 /var/run/docker.sock

Tmux

Rsync

rsync -avz hostname:/file/path .

SSH

  • To keep SSH connection alive
# Add this to ~/.ssh/config
Host *
    ServerAliveInterval 240
    ServerAliveCountMax 2

AWK

  • Extract between multiple lines matching a start and an end pattern: bash awk '/start/,/end/' <file>

Initial config on new VM

sudo apt update && sudo apt upgrade -y && sudo apt install -y git vim-gtk3 build-essential

Python

  • VENV:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --user --upgrade pip
  • Switch Python versions:
ls /usr/bin/python*
sudo update-alternatives --list python
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
sudo update-alternatives --config python

Git

# In order to switch to a remote branch, make sure to fetch your remote branch with “git fetch” first. You can then switch to it by executing “git checkout” with the “-t” option and the name of the branch.
$ git fetch
$ git checkout -t <remote_name>/<branch_name>

# Moving repos around
git remote set-url origin <new-repo-url>
git push

# Undo git add
git reset

# Undo git commit before push
git reset --soft --HEAD~2

# Move git repo retaining history
git clone https://sourceRepoURL
cd sourceRepoFolder
git push --mirror https://targetRepoURL

# Create a standalone patch
git add . 
git commit -m <message>
git format-patch -1

Linux stuff

  • wget: Unable to resolve host address xxx wget --no-proxy --no-check-certificate
  • Always use ls --color=auto to avoid issues with weird characters when piping ls into a file
  • Copy ssh to remote server ssh-copy-id -i ~/.ssh/id_rsa.pub login@serverIP
  • Enable bash on login servers
    if [ -f ~/.bashrc ]; then
      . ~/.bashrc
    fi

Nvidia profiling

  • sudo -E env PATH=$PATH ncu --metrics lts__t_request_hit_rate --log-file output ./bfs.out ../../data/bfs/graph65536.txt

ML Environment

Windows

  • To add a new env to jupyter
# Create a new env
$ conda create -n new_env -y
# Install ipykernel and add the env
$ pip install ipykernel
$ ipython kernel install --user --name=new_env
# Remove an environment
jupyter kernelspec uninstall env_name
  • To enter jupyer "jupyter lab --no-browser" on WSL2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment