Docker cheatsheet

Using Docker host services To use services in host machine, use host.docker.internal as the host. eg: to connect to host mysql Kill running containers docker kill $(docker ps -q) Removing Dangling images docker rmi $(docker images --filter "dangling=true" -q --no-trunc) Delete all stopped containers docker rm $(docker ps -a -q) Delete an image(s) docker rmi <image_name>:<tag> <image_name>:<tag> docker rmi <image_id> Prune commands # delete all resources docker system prune -a # delete all dangling images docker image prune -f # delete all containers docker container prune -f # delete build cache docker builder prune -f

Command Line Tools

k9s - Terminal UI for Kubernetes lazygit - Terminal UI for Git

Podcasts

The Knowledge Project The Changelog Latent Space: The AI Engineer Podcast Acquired Huberman Lab Think like a CEO

pyenv Cheatsheet

To create a virtualenv pyenv virtualenv <python_version> <env_name> To activate a virtualenv pyenv activate python_3.7.17 To list virtualenvs pyenv virtualenvs To remove a virtualenv pyenv virtualenv-delete <env_name>

Linux Commandline

Know the size of the uncompressed file without extracting gzip -l <file_name> | awk 'NR==2 {print $2}' | numfmt --to=iec-i --suffix=B Enddate of ssl certificate cho | openssl s_client -servername <domain> -connect <domain> 2>/dev/null | openssl x509 -noout -enddate Find a file recursively find needs a starting point, . is the current directory find . -name "*.py"

Ruby snippets

Read CSV to a hash filepath = "path/to/file.csv" data = CSV.read(filepath, headers: true).map(&:to_h)

Golang Timer and Ticker

Golang provides two types of timers: time.Timer and time.Ticker. Each have different use Case. time.Timer is used to create a timer that fires once after the specified duration, while time.Ticker is used to create a timer that fires periodically at the specified interval. Example 1: Timer https://goplay.tools/snippet/tSGKq126doi package main import ( "fmt" "time" ) func main() { timer := time.NewTimer(2 * time.Second) go func() { fmt.Println("Inside go routine. Sleeping for 10 seconds") time.Sleep(10 * time.Second) }() <-timer.C fmt.Println("Exited after two seconds") } Example 2: Ticker https://goplay.tools/snippet/MiiE4p4fLjb package main import ( "time" "fmt" ) func main() { ticker := time.NewTicker(1 * time.

Golang Cheatsheet

Testing # To get coverage report # -v is for verbose go test -v ./... --cover # To know which lines are covered go test ./... --coverprofile=coverage.out go tool cover -html="coverage.out" Delve debugging # To print large outputs configure the following config max-string-len 200000 p string(byteSlice)

Jenkins

Deleting old builds cd /var/jenkins_home/jobs/ du -h -d 1 ls | grep -E '[0-9]' | xargs rm -rf Access secrets from the script console import com.cloudbees.plugins.credentials.CredentialsProvider import com.cloudbees.plugins.credentials.domains.Domain import jenkins.model.Jenkins import hudson.util.Secret import org.apache.commons.io.IOUtils def credentialsId = "<credentials_id>" def credentials = CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.common.StandardCredentials.class, Jenkins.instance, null, null ).find { it.id == credentialsId } def inputStream = credentials.content def content = IOUtils.toString(inputStream, "UTF-8") println(content)

VS code Shortcuts (Mac)

Terminal # to open a terminal cmd + ` # to open a new terminal cmd + shift + ` # move between terminal windows cmd + shift + [ cmd + shift + ]