Skip to content

Instantly share code, notes, and snippets.

@un-def
un-def / kbdl.sh
Last active July 18, 2024 12:33
Multi–layout Switcher based on kbdd
#!/bin/sh
### Constants
# the index of the first layout in the primary layer
PRIMARY_LAYER=0
# the index of the first and only layout in the secondary layer
SECONDARY_LAYER=2
### Functions
@un-def
un-def / i3pws.py
Last active July 15, 2024 21:02
i3 persistent workspaces
from __future__ import annotations
import argparse
import json
import subprocess
from typing import Callable, Iterable, Iterator, TypedDict
class Workspace(TypedDict):
name: str
@un-def
un-def / sqlite.lua
Created May 23, 2024 06:12
LuaJIT FFI SQLite C Interface Demo
local sql = arg[1]
if not sql then
print(('usage: %s SQL'):format(arg[0]))
os.exit()
end
local ffi = require('ffiex')
local lib = ffi.load('sqlite3')
@un-def
un-def / nginx.conf
Created May 17, 2024 17:50
Nginx fix Location header on redirects behind reverse proxy
http {
map $http_x_forwarded_proto=$http_x_forwarded_port $redirect_port {
http=80 '';
https=443 '';
default :$http_x_forwarded_port;
}
server {
listen 8080;
@un-def
un-def / switch-sink.bash
Created January 27, 2022 21:15
Switch PulseAudio sinks
#!/usr/bin/env bash
die() {
notify-send "${NOTIFICATION_SUMMARY}" "${1}" -i audio-volume-muted -t 3000
exit 1
}
config_path="${XDG_CONFIG_HOME:-$HOME/.config}/switch-sink.conf.bash"
[[ -f ${config_path} ]] || die 'Config not found'
# shellcheck disable=SC1090
@un-def
un-def / switch-sink.sh
Created January 12, 2022 11:30
Switch between two PulseAudio sinks
#!/bin/sh
INTEGRATED='pci-0000_0c_00.4'
VIDEOCARD='pci-0000_0a_00.1'
TRAY_APP='volumeicon'
NOTIFICATION_SUMMARY='Audio Output'
die() {
@un-def
un-def / Dockerfile
Last active December 23, 2021 09:31
Python Docker multistage build template
ARG python_version
FROM python:${python_version}-alpine AS base
FROM base AS builder
COPY requirements.txt /tmp/
RUN pip install --target=/tmp/build --no-deps -r /tmp/requirements.txt
FROM base
ARG python_version
WORKDIR /opt/project/
/* @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); */
/* hide the native tabs */
#main-window:not([privatebrowsingmode]) #TabsToolbar {
visibility: collapse;
}
/* hide the sidebar header */
local tcp_sock_mt = getmetatable(ngx.socket.tcp())
local udp_sock_mt = getmetatable(ngx.socket.udp())
local is_socket_object = function(obj)
local obj_mt = getmetatable(obj)
return obj_mt == tcp_sock_mt or obj_mt == udp_sock_mt
end
--------
@un-def
un-def / i3blocks-vpn.sh
Created October 8, 2020 17:36
Persistent i3blocks blocket displaying VPN connection status
#!/bin/sh
ON='{"full_text": "", "color": "#00ff00"}'
OFF='{"full_text": "", "color": "#ff0000"}'
dbus-send --system \
--print-reply \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \