Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / pg-full-hoover.sh
Last active April 13, 2022 21:07
psql full vaccum + analysis + verbose of every table in all DBs in a given instance of postgresql
(sudo -iu postgres psql 2>/dev/null -Atc '\l'| \
awk -F"|" '!/^=|^postgres=|template/{print $1}')| \
xargs -rn1 -P1 bash -c 'sudo -iu postgres psql 2>/dev/null ${0} -Atc "\dt+;"| \
awk -vH=${0} -F"|" '"'"'{print H,$2}'"'"''| \
xargs -rn2 -P1 bash -c \
'printf "\n\e[1;34mHoovering table $1 in DB $0\e[0m\n\n";
sudo -iu postgres psql $0 -c "VACUUM(FULL, ANALYZE, VERBOSE) ${1}"
'
@ThinGuy
ThinGuy / maas-list-ppas.py
Created January 14, 2022 17:58
Get all PPA urls for MAAS
#!/usr/bin/env python3
import sys
import codecs
import os
from launchpadlib.launchpad import Launchpad
cachedir = "~/.launchpadlib/cache"
l = Launchpad.login_anonymously('anonymously', 'production', cachedir)
if sys.stdout.encoding is None:
sys.stdout = codecs.open("/dev/stdout", "w", 'utf-8')
for URL in [ ppa.web_link for ppa in l.people['maas'].ppas ]:
@ThinGuy
ThinGuy / fix-fonts.sh
Created January 13, 2022 17:52
Fix fontconfig parsing issue; Fontconfig warning; unknown element; invalid attribute
#!/bin/bash
# This fixes an error happening on impish with fontconfig parsing various font .conf files
# Example when launching chromium (snap version)
#
# $ chromium http://ubuntu.com
#
# Fontconfig warning: "/etc/fonts/conf.d/10-hinting-slight.conf", line 4: unknown element "its:rules"
# Fontconfig warning: "/etc/fonts/conf.d/10-hinting-slight.conf", line 5: unknown element "its:translateRule"
# ... <100+ more errors> ...
@ThinGuy
ThinGuy / timesync.vbs
Created January 11, 2022 16:31
Force windows timesync
'Source: https://www.robvanderwoude.com/sourcecode.php?src=timesyncweb_vbs
Option Explicit
Dim arrDateTime
Dim blnTest
Dim dtmDateTime, dtmNewDateTime
Dim intDateDiff, intOffset, intStatus, intThreshold, intTimeDiff
dim colItems, objHTTP, objItem, objRE, objWMIService
Dim strDateTime, strLocalDateTime, strMsg, strNewdateTime, strURL
@ThinGuy
ThinGuy / barrier-client-systemd.sh
Created January 6, 2022 23:03
Automatically start barrier client at startup
#!/bin/bash
# Github: https://github.com/debauchee/barrier
# Barrier is available in Ubuntu Repos (Universe)
# Other distros: https://github.com/debauchee/barrier#distro-specific-packages
# Change these variables as required per client
export BDISP=':1'
export BUSER='craigbender'
@ThinGuy
ThinGuy / lxd-show-images.sh
Last active December 1, 2021 15:33
Pretty Print images.linuxcontainers.org by distro/release
lxd-show-images() {
declare -ag IMGS=($(lxc image list images: amd64 -cl --format csv|sed -r 's/ \(.*$//g;/cloud|desktop/d'|sort -uV))
(printf '%s\n' ${IMGS[@]%%/*}|sort -uV)|xargs -rn1 -P0 bash -c 'printf "\n\e[1m${0}:\e[0m\n$(lxc image list images: $0 amd64 -cl --format csv|sed '"'"'s/ (.*)//g;s/^/ /g'"'"'|awk '"'"'!seen[$0]++'"'"')\n"'
};export -f lxd-show-images
@ThinGuy
ThinGuy / maas-backup-params.sh
Last active June 9, 2023 15:50
Back up MAAS Regional Settings
maas-backup-params() {
(maas ${MAAS_PROFILE:-admin} maas get-config --help|awk -F: '/^:/&&!/^$|param|type/{print $2}')|\
xargs -rn1 -P1 bash -c 'printf "maas \${MAAS_PROFILE:-admin} maas set-config name=$0 value=$(maas 2>/dev/null ${MAAS_PROFILE:-admin} maas get-config name=$0)\n"|sed -r "s/(^.*null$)/#\1/"'
};export -f maas-backup-params
@ThinGuy
ThinGuy / dns-rrtype-dump.sh
Last active April 13, 2022 21:07
dump dns record types from www.iana.org
curl -sSLl https://www.iana.org/assignments/dns-parameters/dns-parameters-4.csv|\
awk -F',' 'NR>1{if (NF==6 && !/OBS|EXP|^Una|^Pri|^Res/) print $1"|"$2"|"$3}'|\
sort -uV|\
column -ets"|"
@ThinGuy
ThinGuy / yaml-flip-indent.bash
Created August 3, 2021 15:56
Change 2-space indented yaml to 4-space indent or 4-space indented yaml to 2-space-indent
yaml-flip-indent() {
yaml-flip-indent_usage() {
printf "\n\e[2GUsage: ${FUNCNAME%%_*} [-f,--file <filename>] [-i,--in-place] \e[0m\n" 1>&2
printf "\n\e[9Gecho \"\${MYYAMLVAR}\"|${FUNCNAME%%_*} \e[0m\n" 1>&2
printf "\n\e[9Gcat /path/to/file.yaml|${FUNCNAME%%_*} \e[0m\n" 1>&2
printf "\n\e[2GOptions:\n\n"
printf "\e[2G-i, --in-place\e[25GIf a filename is given, edit file in-place\n\n"
printf "\e[2G-f, --file\e[25GFile to change indent\n\n"
printf "\e[2G-h, --help\e[25GThis message\n\n"
printf "\n"
@ThinGuy
ThinGuy / maas-get-profile
Created July 30, 2021 12:24
Get list of MAAS profile names, in case you forgot
maas-get-profile() {
sudo -iu postgres psql maasdb -Atc 'select username from auth_user where is_superuser = true and last_login is not null;'
};export -f maas-get-profile