Skip to content

Instantly share code, notes, and snippets.

View teodorescuserban's full-sized avatar
🎯
Focusing

Serban Teodorescu teodorescuserban

🎯
Focusing
  • Bucharest - Romania
View GitHub Profile
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 10;
@teodorescuserban
teodorescuserban / nginx_graceful_shutdown.sh
Last active December 3, 2018 15:59
tricking a s6-overlay driven nginx in docker to gracefully shutdown
# assuming the service is called nginx,
# to stop it gracefully
docker exec -it <container>
s6-svc -o /var/run/s6/services/nginx # puts the service in "run-once" mode
s6-svc -q /var/run/s6/services/nginx # sends the SIGQUIT signal required bby nginx for a graceful shutdown
# to start the service again
s6-svc -u /var/run/s6/services/nginx # puts the service back up in "run-always" mode
@teodorescuserban
teodorescuserban / gist:bc57889adf033c19157652f8d138b4ff
Created November 28, 2018 09:34
add k8s dashboard to docker for mac
kubectl config use-context docker-for-desktop
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
cat > k8s-dashboard-nodeport-service.yaml << EOF
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: kubernetes-dashboard
@teodorescuserban
teodorescuserban / pr.sh
Last active October 30, 2018 10:11
jenkins: create PRs in the stack repos upon deployment.
# COMMIT_TO_REPO is a boolean parameter
# STACK is a choice parameter
if [ "${COMMIT_TO_REPO}" == "true" ]; then
# commit, push and create PR to the stack repo
REPONAME=XXX-stack
BRANCH=${STACK}-$(date +%Y%m%d-%H%M%S)
FILE_TO_COMMIT=$(readlink -f $PROJDIR/.env | sed "s|${BASEDIR}/${REPONAME}/||")
# don't care about possible wonky private files; we only care about that .env file
rsync -a ${BASEDIR}/${REPONAME} ${WORKSPACE}/ 2>/dev/null || echo -en ""
cd ${WORKSPACE}/${REPONAME}
@teodorescuserban
teodorescuserban / rmi.sh
Last active October 30, 2018 10:11
jenkins remove old docker image
# SERVICE is the docker-compose service name
OLD_IMAGE_ID=$(docker-compose images -q $SERVICE)
# CLEAN_UP_OLD_IMAGE is a jenkins boolean param
if [ "${CLEAN_UP_OLD_IMAGE}" == "true" ]; then
echo -en "\n\nTrying to remove the old image used for ${SERVICE} (ID: ${OLD_IMAGE_ID})...\n"
docker rmi ${OLD_IMAGE_ID} 2>/dev/null || echo -en "\nThis image is still in use and has NOT been removed.\n"
else
echo -en "\nThe old image remains on disk (ID: ${OLD_IMAGE_ID})...\n"
fi
@teodorescuserban
teodorescuserban / delete_old_email.sh
Last active August 30, 2018 15:06
Remove old email from dovecot
#!/bin/bash
MAX_DAYS=180
USER=YOUR_USER
[ -z $1 ] || MAX_DAYS=$1
LAST_DATE=$(date --date ${MAX_DAYS}' days ago' +'%d-%b-%Y')
echo "Mailbox status before proceeding:"