The art of "searching on internet" is very crucial. Many times we face some technical tasks, which require us to frequently visit some blogs and Ask Ubuntu pages. So I thought of compiling some of the most common to-dos that I frequently search on the Internet.

How To Configure SSH Key-Based Authentication on a Remote Server

Saving your time to enter the password for SSH login into the remote machine every day. 😉

https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server

How to terminate Ubuntu under WSL

Sometimes WSL occupies a lot of memory and CPU usage. It does not gets killed once no longer used.

Short answer: wsl --shutdown in Windows terminal. (terminates all WSL distributions)

Long answer: https://askubuntu.com/questions/1131122/cant-restart-shutdown-ubuntu-under-wsl

How to enable 'blackcellmagic' in VS Code Jupyter notebook?

%load_ext blackcellmagic

To use:

%%black

in code cell's beginning.

How to save csv with gzip compression in pandas?

Writing
df.to_csv('dfsavename.csv.gz', compression='gzip')
Reading
df = pd.read_csv('dfsavename.csv.gz', compression='gzip')

How to give path relative to python file script directory than relative path to running directory?

We sometimes use paths like

with open("../a.txt") as file:
    pass

This can be wrong the relatives path are taken in relative to running directory (the directory in terminal from where the python script is run) not the directory of python file.

To overcome this use:

import os.path
script_dir = os.path.dirname(__file__)
with open(script_dir + "/../a.txt") as file:
    pass

script_dir now stores directory of the python script file, irrespective of from wherever it is run.

Note: This issue does not occur in jupyter notebooks. Also, in jupyter notebooks, varibles like __file__ and __main__ are not defined.

How to check memory usage of each directory?

The command is the du command. But I need to add few arguments to make it more useful. Currently, it shows memory recursively in each directory.

For showing memory in MB, only folders in current directory (and not recursively):

du -m -a --max-depth 1