Some commands & shortcuts I use in daily life. Also contains some interesting prompts as well for Generative AI tools.
- Git Commands
- Conda virtual environments
- PEP8 Checking in code
- Docker Commands
- Azure Commands
- Kubernetes Commands
- Linux Commands
- Prefect Commands
- Other Tips
First Time Cloning an Azure/Git repository:
- For Windows: Install Git Credentials Manager
- For Mac:
brew tap microsoft/git
brew install --cask git-credential-manager-core
and Log-in from browser
git clone https://github.com/<repo-name>.git
- To clone a repositorygit checkout origin/master
- To set branch to master/maingit status
- To check the git status of the directorygit pull origin develop
- To pull all contents fromdevelop
branchgit log
- To get a history of the latest changes made in the repositorygit checkout -b <new branch name>
- To create a new branch before starting to make changes. Branch names can begin withfeature/12345_new_model
/patch/12345_add_item
/bugfix/12345_fix_issue
-- make code changes--git status
git add <filenames>
- Add modified files from the output of the previousgit status
commandgit commit -m "comments"
- A meaningful message for the commitgit push origin -u <new branch name>:<remote branch name>
- Justgit push origin
is enough if you're pushing directly to master.git push origin HEAD:<branch name>
- To directly push the changes to a branch.
Other git commands:
git fetch
- If some new branches are missing in localgit diff
git stash
- To delete all existing changes & start freshgit reset --merge
git checkout -f origin/master
git pull origin bug/12345-existing_error
git config --global http.sslVerify true
- Step 1: in case of SSL certificate errorgit config --global http.sslbackend schannel
- Step 2: in case of SSL certificate error
conda create -y -n "<env name>" python=3.9 pip=21.1
- To create virtual environment using Python 3.9 & a compatible pip versionconda activate <env name>
- To activate the virtual environmentconda env list
- To list all available environmentsconda env create -f conda.yml
conda deactivate
- To deactivate a conda environment
To update an existing conda environment:
conda env update --file "./Dependencies/conda.yml" --prune
If the organization is not allowed to create a conda env:
conda config --set ssl_verify no
python -m pip install PACKAGENAME --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
- This bypasses Firewallpip freeze | grep PACKAGENAME
- To get the version of a specific packagepip freeze > requirements.txt
- To save all the package requirements in a virtual environmentpip show PACKAGENAME
- To get more details of a specific package
Pytesting:
python -m pytest --rootdir=./Tests --junitxml=./Tests/junit/unit-test.xml -vv -rP
- To test all tests from the folderpytest -v tests/my-directory/test_demo.py::test_specific_function
- To test a specific function
Command to get all python packages used in a project:
pip install pipreqs
pipreqs "<location where you want requirements to be saved>"
To install from within a repository (if it has setup.py)
pip install - e .
(This installs the repo in 'editable' mode.
First install Flake8 package (pip install Flake8
)
flake8 <code path> --max-line-length=120
orpython -m flake8 <code path> --max-line-length=120
First open 'Docker CLI' for SSO authentication
docker login <host-name> -u <user name> -p <password>
- Enable logging in with SSO if connected to VPN/Remote Connect.docker pull <image-name>
- A working sample command to pull a repository.docker images
- List the available docker images.docker build . -f dockerfile -t <image name>
- Build a docker image using the available dockerfile in the repositorydocker build -t <image-name> -f dockerfile .
- This can also be used. Check & understand the difference before using it.docker build -t <another-image-name> -f dockerfile .
docker tag <tag name> <ACR hostname/folder:latest
- To tag the image manuallydocker push <host name/folder:latest>
- To push to container registries/remote locations.docker run -it -e PYTHONUNBUFFERED=1 --publish 8080:8080 <image name>
- Run & publish the docker imagedocker run -p 5000:5000 -v //home//project-location//://home//project-location// -d <image-name>
docker run -p 4200:4200 -d <image-name>
docker-compose -f db-docker-compose.yaml up
- If it's only to run a MSSQL database locally- `
systemctl show --property ActiveState docker|cut -d"=" -f2
- To list active docker images
Full list For command-line:
az login
- Login with webaz login -u myemail@address.com
- Login in CLIaz account list
- List accountsaz account list-locations
- List all locationsaz account get-access-token --output json --resource https://vault.azure.net
az resource list
- List all my resource groupsazure --version
- Get what version of the CLI you haveaz vm list
- List your VMsazure help
- Get helpaz account show -o jsonc
- Check if logged in or notaz account set --subscription <subscription-id>
- To set the currently active subscription for your Azure accountaz aks get-credentials --resource-group <resource-group-name> --name <name-of-AKS-cluster> --admin
- To configure kubectl with the credentials and context required to connect to an Azure Kubernetes Service (AKS) cluster
kubectl get pods -n <name of the cluster>
- Used to retrieve information about resources in the cluster.kubectl get pods -A -o wide > file-name.txt
- Used to get complete information about available pods and the tasks undertaken by them (stores it in a text file).kubectl get nodes
- Used to get all available nodes.kubectl describe pod -n <name of the cluster> <name of the pod>
- Gives detailed information from the yaml file used to configure the pod.kubectl get hpa <name assigned to the HPA> --watch
- Gives real-time load info and pod count by HorizontalPodAutoscaler. 1 2kubectl logs <name of the pod> -n <name of the cluster>
- To get the logs of a podkubectl top pod <name of the pod> -n <name of the cluster>
- To retrieve usage statistics of a podkubectl apply -f manifest-file-name.yaml
- Apply changes made in the yaml file and recreate the pods based on it.kubectl port-forward <resource-you-want-to-forward-a-port-to> 4200:4200 -n <name-space>
- For port-forwarding.kubectl get secret
- List the secrets availablekubectl describe secret
- To get all details of the namespace including the token.kubectl config get-contexts
- Used to display information about the available contexts in your Kubernetes configurationkubectl get hpa -n <name-space>
- Used to retrieve information about Horizontal Pod Autoscalers (HPA) in a namespacekubectl -n <name-space> patch hpa <name-of-the-hpa> --patch '{"spec":{"maxReplicas":2}}'
- To configure maximum replicas of a HPA.kubectl patch secret <secret-name> -n <name-space> -p '<value>'
- To update regcred secrets inside a cluster.
sudo lsof -i -P -n | grep LISTEN
kill -9 <container id>
Curl Commands:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://127.0.0.1:8000/<page-url>/
For Azure Portal: Steps:
- Enable SSH
- Install NVIDIA Drivers
ssh -L 1234:localhost:8888 avinash@<IP-Address>
- Port forwarding
Enabling SSH:
ls .ssh
ssh-copy-id -i ~/.ssh/id_rsa avinash@<IP-Address>
ssh avinash@172.190.120.45
Inside VM:
tmux kill-session -t 1
tmux a -t 1
tmux ls
tmux
sudo shutdown
df -h
htop
ps
ssh-copy-id -i ~/.ssh/mykey user@host
Also refer Tmux cheat-sheet & SSH Basics
prefect version
prefect server start
prefect deployment build prefect_tryouts.py:hello_world -n demo-deployment
prefect deployment apply hello_world-deployment.yaml
prefect agent start -q <work_queue_name>
prefect cloud login
To reduce the size of PDFs in PDF X-Change Editor:
Organize -> Resize -> Percentage -> [Reduce to a size which fit the requirement]. (Keep 'Context Scale Options' all check)
To beautify JSONs: Ctrl + Alt + L
(Option + cmd + L
on Mac)
To select a URL fully: Ctrl + W
Extend Selection:
-
In Mac:
Option + Up
orOption + Down
-
In Windows:
Ctrl + W
Get IP address of the Mac:
curl ifconfig.me
To convert a string to base64 in Mac:
- `echo 'string' | base64 # To encode
- 'c3RyaW5nCg==' | base64 -D # To decode
These commands are written in such a way that helps me understand them. I might add more, or delete some, based on whatever is relevant to me.
Note: I'll keep on updating these commands as I use them.