Skip to content

Instantly share code, notes, and snippets.

@davebulaval
Last active March 26, 2022 16:10
Show Gist options
  • Save davebulaval/2364b263875550569857759be64be69d to your computer and use it in GitHub Desktop.
Save davebulaval/2364b263875550569857759be64be69d to your computer and use it in GitHub Desktop.
Cheat Sheet

Personal Cheat sheet

SSH and SCP

Config SSH Credential

To config a ssh credential edit the config file ~/.ssh/config as show bellow

Host {credential_name}
    Hostname {ip_address}
    User {username}

Connexion with SSH to a remote computer

ssh username@{ip_address}

or with the credential ssh {hostname}

SSH key binding to avoid password connexion

ssh-copy-id {hostname}

To bind a specific port to your localport with credential

ssh -L {port_to_bind_local}:localhost:{port_to_bind_remote} {hostname}

SCP

File transfert: scp {remote_Hostname}:{distant_file_path} {local_target_path}

File transfert with regex pattern: scp -r {remote_Hostname}:'{distant_file_path}{pattern}' {local_target_path}

Exemple of pattern *.png

IP

To get the ip address of a computer ifconfig

ZSH

#!/bin/zsh

SSMTP

To send email from the terminal.

tmux

Show session: tmux ls

Connect to session {id}: tmux a -t {id}

Create a new session:tmux

Create a new named session: tmux new -s {name}

Press ctrl + B and Press d to detach. You must not hold ctrl + B with d

Openconnect

sudo openconnect vpn.ulaval.ca --user={username} or sudo openconnect vpn.ulaval.ca -u {username}

To see your GPU usage

watch -n 1 nvidia-smi

Crontab

sudo /etc/init.d/cron start

sudo /etc/init.d/cron restart

See your Cron job log: sudo grep CRON /var/log/syslog

Start a new crontab: crontab -e

Log the output of the job: > ./`date +\%Y\%m\%d\%H\%M\%S`-cron.log

Alternative to Crontab

ufw

To manage your firewall setting.

Python

Start python module

python -m module1.src.file_name.script

May also need to define the PYTHONPATH variable export PYTHONPATH=.

Jupyter Notebook

To run the jupyter notebook and bind it to the port 5000 jupyter notebook notebook.ipynb --port 5000

Scrapy

  • Start a new scrapy project scrapy startproject {project_name}

  • Add a spider scrapy genspider -t crawl {name} {domain}

    crawl is the template used to created the spider

  • Start a scrapy shell to access variables. scrapy shell {url}

  • Extract response variable. response.xpath('{commnad}').extract()

  • Crawl and export into S3 bucket scrapy crawl basic -o "s3://aws_key:aws_secret@{file_path_local}"

Linux

Get all the disk usage:

df -h

Get directory usage:

ll

Hibernate command: https://bentalbot.com/posts/creating-a-hibernate-shortcut-in-ubuntu-20.04

Docker

docker run -di -p {dockerport}:{localport} --name {nomDudocker} {image}

docker exec -it {dockername} {image}

MongoDB & docker

docker run -di -p {dockerport}:{localport} --name {nomDudocker} mongo

docker exec -it {dockername} mongo

Tensorboard

python3 -m tensorboard.main --port=8888 --logdir tensorboard

Valeria setting

dvc remote add -d storage s3:// && dvc remote modify storage endpointurl https://s3.valeria.science && dvc remote add -f storage s3:// --local && dvc remote modify storage endpointurl https://s3.valeria.science --local && dvc remote modify storage profile --local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment