Skip to content

Instantly share code, notes, and snippets.

View abn's full-sized avatar

Arun Babu Neelicattu abn

View GitHub Profile
@abn
abn / cpython-patched-getfqdn.py
Created June 4, 2023 16:02
A patched version of socket.getfqdn() based on the patch provided in cpython#49254
import socket
# patched socket.getfqdn() - see https://github.com/python/cpython/issues/49254
def getfqdn(name=''):
"""Get fully qualified domain name from name.
An empty argument is interpreted as meaning the local host.
"""
name = name.strip()
if not name or name == '0.0.0.0':
name = socket.gethostname()
@abn
abn / console-logs-comment.md
Created June 1, 2022 11:00
Collapsible GitHub Markdown Block (console.log)
console.log

# insert log here

@abn
abn / nm-create-resolved-custom-port-dns-dispatcher.sh
Last active December 23, 2022 12:42
NetworkManager Dispatcher: Configure systemd-resolved DNS server with custom port on connection up event
# NetworkManager connection config does not like custom ports for DNS servers
# we work around this by using a dispatcher to configure this on up events
# change these to your desired configs
CONNECTION_ID=wg0
DNS_TARGET=10.10.0.1:5300
DNS_SEARCH_DOMAIN=~testing
cat > /etc/NetworkManager/dispatcher.d/99-${CONNECTION_ID}.sh <<EOF
#!/usr/bin/env bash
@abn
abn / fix-keychron-k1-fn.sh
Last active February 26, 2023 20:49
Fix keychron k1 function keys on Fedora
#!/usr/bin/env bash
FNMODE=0
# session fix
echo $FNMODE | sudo tee /sys/module/hid_apple/parameters/fnmode
# permanent fix
# https://ask.fedoraproject.org/t/getting-the-function-keys-to-work-properly-with-a-varmilo-keyboard/11297
echo "options hid_apple fnmode=$FNMODE" | sudo tee /etc/modprobe.d/hid_apple.conf
@abn
abn / jigsaw-outline-uninstall.sh
Last active March 7, 2024 10:25
Jigsaw Outline: Uninstall (purge) the persistent thing
#!/usr/bin/env bash
# this is not extensively tested, worked for personal use case.
# script is intentionally aggressive, use at your own peril :)
# reference: https://github.com/Jigsaw-Code/outline-client/issues/648
function uninstall-outline() {
set -x
sudo systemctl disable --now outline_proxy_controller
@abn
abn / run-poetry-pull-request.sh
Last active October 8, 2020 16:29
Python Poetry: Run Pull Request Container
PULL_ID=3147
PYTHON_VERSION=${PYTHON_VERSION:-3.8}
podman run --rm -i --entrypoint bash python:${PYTHON_VERSION} <<EOF
set -e
python -m pip install -q git+https://github.com/python-poetry/poetry.git@refs/pull/${PULL_ID}/head
python -m poetry new foobar
pushd foobar
sed -i /pytest/d pyproject.toml
python -m poetry add pycowsay
@abn
abn / jsonb_array_to_text_array.sql
Created September 14, 2020 21:27
Implicit casting from jsonb array to psql text array
-- https://stackoverflow.com/a/45244285
CREATE OR REPLACE FUNCTION public.jsonb_array_to_text_array(
JSONB
) RETURNS TEXT[] AS
$f$
SELECT array_agg(x::TEXT) FROM jsonb_array_elements($1) t(x);
$f$
LANGUAGE sql
IMMUTABLE;
@abn
abn / Makefle
Created June 25, 2020 22:23
Makefile: Using a custom bashrc file for default shell used by all targets
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
ROOT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
BASH_ENV := $(ROOT_DIR)/.bashrc
export BASH_ENV
SHELL := $(shell which bash) -e
@abn
abn / slugify.postgres.sql
Last active March 14, 2024 20:29
A slugify function for postgres
-- original source: https://medium.com/adhawk-engineering/using-postgresql-to-generate-slugs-5ec9dd759e88
-- https://www.postgresql.org/docs/9.6/unaccent.html
CREATE EXTENSION IF NOT EXISTS unaccent;
-- create the function in the public schema
CREATE OR REPLACE FUNCTION public.slugify(
v TEXT
) RETURNS TEXT
LANGUAGE plpgsql
@abn
abn / az-list-all-vhd.sh
Last active July 25, 2018 12:35
Azure: List all VHD blobs in all containers in all storage accounts of a specified resource group
#!/usr/bin/env bash
# This script lists all blobs in all containers in all storage accounts of a specified resource group
for storageAccount in `az storage account list -g ${1} | jq -r '.[] | .name'`; do
for containerName in `az storage container list --account-name ${storageAccount} | jq -r '.[] | .name'`; do
blobName=`az storage blob list -c ${containerName} --account-name ${storageAccount} | jq -r '.[] | .name'`
[[ ! -z "${blobName}" ]] && echo "${storageAccount}/${containerName}/${blobName}"
done
done