Skip to content

Instantly share code, notes, and snippets.

@madsonic
madsonic / impersonation
Created November 27, 2019 07:37
impersonation kubectl
kubectl auth can-i list secrets --namespace dev --as dave
@madsonic
madsonic / systemctl timer
Last active November 26, 2019 03:26
timer service systemctl
# foo.service
[Unit]
Description=do something
[Service]
Type=oneshot
ExecStart=/usr/bin/script1
ExecStart=/usr/bin/script2
[Install]
@madsonic
madsonic / pre-commit
Created October 22, 2019 12:10
githooks
#!/bin/sh
set -exuo pipefail
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
# do some validation here e.g.
@madsonic
madsonic / dockerconfigjson
Created October 10, 2019 09:48
dockerconfigjson
# create dockerconfigjson from scratch
cat <<EOF >> dockerconfigjson
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "$(base64 --input=credfile)"
}
}
}
@madsonic
madsonic / dockerconfigjson
Created October 10, 2019 09:48
dockerconfigjson
# create dockerconfigjson from scratch
cat <<EOF >> dockerconfigjson
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "$(base64 --input=credfile)"
}
}
}
@madsonic
madsonic / certbot.sh
Last active October 9, 2019 07:30
certbot
# manual
certbot --help all
# Add Certbot PPA
sudo apt-get update -y
sudo apt-get install -y software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update -y
@madsonic
madsonic / cloud sql proxy
Last active October 3, 2019 03:41
Cloud SQL proxy cheatsheet
INSTANCE_CONNECTION_NAME: <projname>:<region>:<db-instance-name> (myproject:us-central1:myinstance)
# tcp socket
/cloud_sql_proxy -instances=<INSTANCE_CONECTION_NAME>=tcp:<port-number> \
-crendential_file=<PATH_TO_KEY_FILE>
psql "host=127.0.0.1 sslmode=disable dbname=<DB_NAME> user=<USER_NAME>"
# unix socket
sudo mkdir /cloudsql; sudo chmod 777 /cloudsql
# service account based (explicit instance)
@madsonic
madsonic / send udp message
Created September 13, 2019 04:07
graylog
echo '{"facility": "testfacility", "short_message": "test message"}' | nc -w 2 -u <endpoint> <port>
@madsonic
madsonic / kubectl
Last active November 29, 2019 01:01
kubectl output format
# customise output format with go template
kubectl ... -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}"
kubectl get deploy -o go-template --template='{{range .items}}{{printf "%s\n" .metadata.name}}{{end}}'
# for keys with dots or special characters
kubectl get secrets regcred -o "jsonpath={ .data['\.somesecret'] }"
@madsonic
madsonic / git.sh
Created August 16, 2019 06:16
gitfu
# list of commands useful for scripting
# there are other shorter but gives less precise command mainly for human consumption
# rather than scripts. those commands are not the focus of this gist
# accidentally tracking a large repo via git fetch
# and to stop tracking unused remote branches
git br -d -r <branch-name>
# to remove everything in one command
git br -r | xargs git br -d -r