Skip to content

Instantly share code, notes, and snippets.

@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 \
@un-def
un-def / luaversion.lua
Last active March 5, 2023 11:42
A simple function to detect Lua version
local luaversion = function()
if ({false, [1] = true})[1] then -- luacheck: ignore 314
return 'LuaJIT'
elseif 1 / 0 == 1 / '-0' then
return 0 + '0' .. '' == '0' and 'Lua 5.4' or 'Lua 5.3'
end
local f = function() return function() end end
return f() == f() and 'Lua 5.2' or 'Lua 5.1'
end
@un-def
un-def / wikirender.sh
Created July 4, 2020 20:05
Render wikitext to HTML using Wikipedia API
#!/bin/sh
curl https://en.wikipedia.org/w/api.php -F format=json -F action=parse -F contentmodel=wikitext -F text='<-' 2> /dev/null | jq -r '.parse.text["*"]'
@un-def
un-def / lua-cmsgpack-0.4.0-0.rockspec
Created June 15, 2020 21:42
lua-cmsgpack patch for null values in hash tables
package = "lua-cmsgpack"
version = "0.4.0-0"
source = {
url = "git://github.com/antirez/lua-cmsgpack.git",
tag = "0.4.0"
}
description = {
summary = "MessagePack C implementation and bindings for Lua 5.1/5.2/5.3",
homepage = "http://github.com/antirez/lua-cmsgpack",
license = "Two-clause BSD",
@un-def
un-def / _just
Created January 13, 2020 18:52
ohmyzsh just autocompletion
#compdef _just just
#autoload
_just() {
local -a subcmds
subcmds=($(just --summary)) 2> /dev/null || return 1
_describe 'command' subcmds
}