Skip to content

Instantly share code, notes, and snippets.

View mjf's full-sized avatar

Matouš Jan Fialka mjf

View GitHub Profile
@mjf
mjf / dockercat
Last active July 13, 2021 11:48
Docker Object Tools
#! /bin/sh
# dockercat - Print Docker config or secret object
# Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz/>
# Released under the terms of the "MIT License"
PROGRAM="${0##*/}"
if [ $# -eq 0 -o $# -ne 2 ]; then
echo "Usage: $PROGRAM { config | secret } OBJECT" >&2
@mjf
mjf / hp4pid
Last active July 9, 2021 11:40
Huge Pages for PID
#! /bin/sh
[ $# -eq 1 ] && {
grep -B 11 'KernelPageSize' "/proc/$1/smaps" |
awk '/^Size:/ { sum += $2 } END { printf("%.2F GiB\n", sum / 1024 / 1024) }'
} || {
printf "Usage: %s PID\n" "${0##*/}" >&2
exit 1
}
@mjf
mjf / prom_api_extras.pgsql
Last active May 14, 2021 10:26
Promscale API Extras
-- PL/PgSQL Functions for Promscale API Schema
-- Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz/>
-- Released under the terms of "The MIT License"
-- LABEL VALUES FUNCTIONS
--
-- label_values([<metric>,] <label>[, <time from>[, <time to>]])
--
-- Where:
-- <metric> is name of a metric
@mjf
mjf / PromQL_to_SQL_Idioms_for_Promscale.md
Last active August 23, 2022 19:48
PromQL to SQL Idioms for Promscale

PromQL to SQL Idioms for Promscale

Legend

Variable Meaning
METRIC Metric name (i.e. cpu_usage_system)
NAME Name for the metric value (corresponds to AS "NAME" in SQL)
@mjf
mjf / HtUPg12wTsDBExtCMngbyPtPg13oEL8S.md
Last active May 28, 2024 08:01
Upgrade PostgreSQL 12 with TimescaleDB Extension Cluster Managed by Patroni to PostgreSQL 13 on CentOS 8 Stream

How to Upgrade PostgreSQL 12 with TimescaleDB Extension Cluster Managed by Patroni to PostgreSQL 13 on CentOS 8 Stream

Flag Meaning
[---] Holds for nothing (i.e. work in progress)
[M--] Holds exclusively for master
[-S-] Holds exclusively for slave
[--C] Holds exclusively for cluster management
[MS-] Holds for both master and slave
@mjf
mjf / haproxy-pgsql-tcp-check
Last active June 9, 2022 19:51
Generate HAProxy PostgreSQL TCP Check
#! /bin/sh
# haproxy-pgsql-tcp-check - Generate HAProxy PostgreSQL TCP Check
# Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz/>
# Released under the terms of "The MIT License"
#
# See https://www.postgresql.org/docs/current/protocol-message-formats.html
if [ $# -lt 2 -o $# -gt 3 ]; then
printf -- 'Usage: %s USER DATABASE ["leader"]\n' "${0##*/}" >&2
@mjf
mjf / pingfmt
Last active January 20, 2021 09:41
pingfmt - Format output of the ping(1) program
#! /usr/bin/awk --exec
# pingfmt - Format output of the ping(1) program
# Copyright (C) 2012, 2021 Matouš J. Fialka, <https://mjf.cz/>
# Released under the terms of The MIT License
BEGIN {
# ----- HELP SCREEN -----
help = help "Usage: pingfmt [-h|-help|-usage] [+[no][show]<opt>[=<val>]]\n"
@mjf
mjf / move-centos8-to-stream.sh
Last active January 20, 2021 12:53
Move CentOS 8 to Stream
#! /bin/sh
# Script "memo" to move CentOS 8 to AppStream
# Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz/>
# Released under the terms of "The MIT License"
dnf update -y && \
dnf install -y centos-release-stream && \
dnf distro-sync -y
@mjf
mjf / Postgres.md
Last active May 23, 2025 11:02
Postgres

⚠️ WARNING
The ordering of listed projects or documents is random and has no connection to relevance or maturity levels!

Postgres

Extensions

Extension Description
pgaudit Postgres auditing extension
@mjf
mjf / postgresql_gimmicks.sql
Last active October 1, 2021 11:46
PostgreSQL "gimmicks"
-- PostgreSQL Gimmicks
-- Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz/>
-- Released under the terms of "The MIT License"
-- 1. BEWARE USING BETWEEN OPERATOR WITH DATE AND TIME TYPES
-- 1.1 INCORRECT
-- Note: intervals are written in ISO 8601 format