Most Frequent How-Tos
- How To Configure SSH Key-Based Authentication on a Remote Server
- How to terminate Ubuntu under WSL
- How to enable 'blackcellmagic' in VS Code Jupyter notebook?
- How to save csv with gzip compression in pandas?
- How to give path relative to python file script directory than relative path to running directory?
- How to check memory usage of each directory?
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 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
'blackcellmagic' in VS Code Jupyter notebook?
How to enable%load_ext blackcellmagic
To use:
%%black
in code cell's beginning.
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.