Sep 14, 2025

Grep

ignore commented and empty lines

grep -v "^#\|^$"  /path/to/dir
Sep 14, 2025

Vim

delete

:g/^#/d       # delete all the lines starting with #  g=>global d=>delete
:g/^\s*$/d    # deleting all lines that are empty or that contain whitespace only
:g!/^\s*#/d     # delete all the lines that are not comment

substitution

:%s/old/new/gc  # substitute with prompt
&   = repeat last substitution, in the current line
g&  = repeat last substitution on all lines 

repeat something

30i/I/a/A   #horizontally
3o/O        #vertically     

extras

:set paste          # allows pasting w/o indentation mess

C-x C-f         # completing file names too, as well as
C-x C-l         # completing entire lines.
Aug 28, 2025

nvim

Multi-line change

C-q    # after rip-grep
:cdo %s/old/new/g          # apply the regex accross all the quick fixlist
Mar 14, 2025

k8s Cheat Sheet

Context & Namespace

k config get-contexts                       # List all contexts
k config current-context                    # Show current context

Pods

k exec -it pod_name -c container_name -n namespace -- bash   # Exec into a container shell
k logs pod_name -c container_name -n namespace                # View logs for container
k logs --previous pod_name -c container_name -n namespace     # View logs from previous crash
k logs pod_name --all-containers -n namespace                 # View logs from all containers
k top po pod_name --containers -n namespace                   # Show CPU & memory usage per container
k delete po pod_name -n namespace                             # Delete pod

Secrets

kubectl get secret datadog-agent -n namespace -o jsonpath='{.data.api-key}' | base64 -d

Deployments

k rollout restart deploy deploy_name -n namespace   # Restart a deployment

HPA & Events

k describe hpa hpa_name -n namespace                # Describe HPA details
k get ev --field-selector involvedObject.name=obj_name -n namespace   # Get events for specific object
Feb 13, 2025

SSH

Stop typing long SSH commands! Use ~/.ssh/config:

Host prod-server
    HostName 192.168.1.100
    User deploy
    Port 2222
    IdentityFile ~/.ssh/prod_key
    ForwardAgent yes

Host dev-*
    User developer
    Port 22
    IdentityFile ~/.ssh/dev_key

Now just type: ssh prod-server or ssh dev-anything

Host frontend-github
    HostName github.com
    User git
    IdentityFile ~/.ssh/ssh-frontend
    IdentitiesOnly yes

git clone git@frontend-github:repo_link.git # replace github.com with frontend-github after key is added.

Docker Cleanup

get in

docker exec -it container_name sh

clean up Docker system resources:

# Remove all stopped containers
docker container prune -f

# Remove unused images
docker image prune -a -f

# Remove unused volumes
docker volume prune -f

# Nuclear option - clean everything
docker system prune -a --volumes -f

Always be careful with the nuclear option in production!

Jan 13, 2025

Bash prompt colors

🎨 Bash Prompt in 10 Colors#

Color NameANSI CodePrompt Line
Red0;31export PS1='\[\e[0;31m\]\u@myhost:\w\$ \[\e[0m\]'
Green0;32export PS1='\[\e[0;32m\]\u@myhost:\w\$ \[\e[0m\]'
Yellow0;33export PS1='\[\e[0;33m\]\u@myhost:\w\$ \[\e[0m\]'
Blue0;34export PS1='\[\e[0;34m\]\u@myhost:\w\$ \[\e[0m\]'
Magenta0;35export PS1='\[\e[0;35m\]\u@myhost:\w\$ \[\e[0m\]'
Cyan0;36export PS1='\[\e[0;36m\]\u@myhost:\w\$ \[\e[0m\]'
White0;37export PS1='\[\e[0;37m\]\u@myhost:\w\$ \[\e[0m\]'
Bright Red1;31export PS1='\[\e[1;31m\]\u@myhost:\w\$ \[\e[0m\]'
Bright Green1;32export PS1='\[\e[1;32m\]\u@myhost:\w\$ \[\e[0m\]'
Bright Blue1;34export PS1='\[\e[1;34m\]\u@myhost:\w\$ \[\e[0m\]'

Jan 12, 2025

Python One-Liners

Python one-liners :

# Start a simple HTTP server
python -m http.server 8000

# Generate random password
python -c "import secrets, string; print(''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(12)))"