Skip to content

Instantly share code, notes, and snippets.

View abn's full-sized avatar

Arun Babu Neelicattu abn

View GitHub Profile
@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 / 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 / 00-lenovo-x1-5th-gen-thinkfan-setup.md
Last active January 30, 2024 19:31
Fedora thinkfan configuration for Lenovo X1 Carbon (5th Gen)

Thinkfan Configuration Notes

This are notes for configuration thinkfan for Fedora. This configuration procedure was followed on a Lenovo Thinkpad X1 Carbon (5th Gen) running Fedora 25.

Non standard (default) configuration was required for this machine as the default sensors are not available. Eg: /proc/acpi/ibm/thermal does not exist for this model.

An annoted configuration file has been included below. However, there is no guarentee that this will work as-is on every machine.

Installation

dnf -y install thinkfan
@abn
abn / install-jetbrains-toolbox.sh
Last active December 1, 2023 14:00
Install JetBrains Toolbox App
#!/usr/bin/env bash
# Reference: https://github.com/nagygergo/jetbrains-toolbox-install/blob/master/jetbrains-toolbox.sh
# Note that we grep for linux here, if you are using this on mac/windows please see json output
TOOLBOX_URL=$(curl --silent 'https://data.services.jetbrains.com//products/releases?code=TBA&latest=true&type=release' \
-H 'Origin: https://www.jetbrains.com' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-US,en;q=0.8' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Referer: https://www.jetbrains.com/toolbox/download/' \
@abn
abn / heredoc-dockerfile.snip
Last active October 5, 2023 17:43
Dockerfile alternatives for heredoc
#printf
RUN printf '#!/bin/bash\n\
echo hello world from line 1\n\
echo hello world from line 2'\
>> /tmp/hello
#echo
RUN echo -e '#!/bin/bash\n\
echo hello world from line 1\n\
echo hello world from line 2'\
@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 / 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 / install-homebrew-osx.sh
Last active January 5, 2023 09:24
Install homebrew from behind a proxy on Mac OS X.
#!/usr/bin/env bash
# Based on: http://godlessheathenmemoirs.blogspot.com.au/2015/03/homebrew-aka-brew-on-mac-os-x-behind.html
function usage() {
echo 2>&1 ""
echo 2>&1 "usage: $(basename $0) PROXY_HOST PROXY_PORT"
exit 1
}
PROXY_HOST=${PROXY_HOST:-$1}
@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 / logstash.service
Last active November 30, 2022 13:17
logstash systemd service file
[Unit]
Description=Logstash
Documentation=https://www.elastic.co/products/logstash
After=network.target
ConditionPathExists=/etc/logstash.conf
[Service]
ExecStart=/opt/logstash/bin/logstash agent -f /etc/logstash.conf
[Install]