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 + ]

MySQL Snippets

Create User and Database Create user webapp, database webappdb and grant all privileges to user. To generate random passwords I use: https://passwordsgenerator.net/ CREATE DATABASE webappdb; CREATE USER 'webapp'@'%' identified by "LbAh52s6MnKQZasH"; GRANT ALL PRIVILEGES ON webappdb.* TO 'webapp'@'%' Grant read-only permission Grant read-only permission to user webapp_ro to database webappdb GRANT SELECT ON webappdb.* TO 'webapp_ro'@'%'; Export to CSV from mysql shell SELECT * FROM <> WHERE <> INTO OUTFILE '/tmp/output.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; Load CSV from mysql shell LOAD DATA LOCAL INFILE '<path-to-csv-file>' INTO TABLE <table_name> enclosed by '"' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'; Create index CREATE INDEX <index_name> ON <table_name>(<column_name>); Get size of tables SELECT TABLE_SCHEMA AS `Database`, TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.

RoR Cheatsheet

To list all jobs in Delayed Job queue Delayed::Job.all

psql cheatsheet

\? - help \l - list databases \c <db name> - to connect to a database \d - to list tables Create database CREATE DATABASE <DB_NAME>; CREATE USER <DB_USER> WITH PASSWORD '<PASSWORD>'; GRANT ALL PRIVILEGES ON DATABASE "<DB_NAME>" TO "<DB_USER>"; Backups and Restoring pg_dump -U <DB_USER> -Fp <DB_NAME> > <DB_DUMP_FILENAME> psql -U <DB_USER> -d <DB_NAME> -f <DB_DUMP_FILENAME>

awk Cheatsheet

Notes Column numbering starts with $1 in print. $0 will print the entire line To read CSV awk -F "," '{print $6}' <file_name.csv>

Kubernetes cheatsheet

To renew all certs kubectl cert-manager renew --all -n <namespace> Get all resources at once kubectl get <resource_name> | awk '{print $1}' | grep -vi name | xargs -I{} sh -c 'kubectl get <resource_name> {} -o yaml > {}.yaml' kubectl get deployments | awk '{print $1}' | grep -vi name | xargs -I{} sh -c 'kubectl get deployment {} -o yaml > {}.yaml' Apply all resources in a directory kubectl apply -f . kubectl apply -f <directory> --recursive

Postgres Snippets

Postgres shell psql postgres Create User and Database Create user webapp, database webappdb and grant all privileges to user. To generate random passwords I use: https://passwordsgenerator.net/ CREATE DATABASE webappdb; CREATE USER webapp WITH PASSWORD 'DXw3BzFsNERfPwjg'; GRANT ALL PRIVILEGES ON DATABASE "webappdb" TO "webapp"; Grant read-only permission Grant read-only permission to user webapp_ro to database webappdb GRANT SELECT ON ALL TABLES IN SCHEMA webappdb TO webapp;

Evernote Shortcuts (Mac)

Cmd + J - Switch to a note or a notebook Cmd + n - Create a new note in the current notebook