Skip to content

Instantly share code, notes, and snippets.

@n-st
n-st / pkg-list_fully_installed_groups
Created January 26, 2022 02:31
Arch Linux pacman: List all "groups" that are "fully installed", i.e. all their member packages are installed on this system
#!/bin/sh
set -e -u
tempprefix="$(basename "$0")"
tempdir="$(mktemp -d -t "${tempprefix}.XXXXXXXXXX")"
trap 'rm -rf "$tempdir"' EXIT
cd "$tempdir" || exit
@n-st
n-st / i3status-wrapper.py
Created September 7, 2021 12:41
i3status wrapper to add microphone mute/unmute status
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This script is a simple wrapper which prefixes each i3status line with custom
# information. It is a python reimplementation of:
# http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl
#
# To use it, ensure your ~/.i3status.conf contains this line:
# output_format = "i3bar"
# in the 'general' section.
@n-st
n-st / microphone-toggle
Created April 27, 2020 18:18
Keyboard shortcut to mute/unmute default microphone (or other default audio source)
#!/bin/sh
notify-send \
--expire-time=700 \
"$(pacmd list-sources | awk 'BEGIN { FPAT = "[^ \t]+|\"[^\"]+\"" } $1 == "*" { find=1 } $1 == "device.description" { if (find) { print substr($NF,2,length($NF)-2); exit; } }')" \
"→ $(amixer set Capture toggle | grep -oP '(?<=\[)o[nf]+(?=\])' | sort -u)"
@n-st
n-st / pavusetup.sh
Last active April 15, 2020 09:23
PulseAudio configuration to stream video files and microphone audio to v4l2sink; locally hearing the video files but not the microphone.
#!/bin/sh
# PulseAudio configuration to stream video files and microphone audio to
# v4l2sink; locally hearing the video files but not the microphone.
# Video files -> OBS -> OBS Monitor -> "MediaInterim" \
# |-> Speakers
# `-> "FinalStream"
# Microphone -> "FinalStream"
@n-st
n-st / ixp-peerlist.sh
Created October 28, 2019 16:30
Get parsable peer list for given IXP from PeeringDB
# Compare which peers are present at different IXPs:
curl -s https://www.peeringdb.com/api/ix/123 | jq .data[0].ixlan_set[].id | xargs -I@ curl -s https://www.peeringdb.com/api/ixlan/@ | jq -j -r '.data[0].net_set[]|(.name,", AS ",.asn, "\n")' | sort > kleyrex.txt
# Let's you do things like "show me peers that are present at Locix, but not at Kleyrex"
comm -23 locix.txt kleyrex.txt
@n-st
n-st / colortrans.py
Last active May 28, 2019 15:01 — forked from MicahElliott/colortrans.py
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python2
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code
@n-st
n-st / free-pens.sh
Created November 16, 2018 12:36
List unassigned IANA PENs ("gaps" in the assignment list)
#!/bin/sh
wget https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
awk -F '[ ]' 'BEGIN {nr=-1} NF==1 && $1 == 0+$1 {if ($1 != (nr+1)) {for (i=nr+1; i<$1; i++) {print i}}; nr=$1}' enterprise-numbers
@n-st
n-st / dnsinfo.sh
Last active October 9, 2018 16:10
Quick DNS overview for one or multiple domains. Requires bash, GNU awk, coreutils, dig.
#!/usr/bin/env bash
ip_to_hostname ()
{
if [ -z "$1" ]
then
printf '%s\n' "unknown"
else
nc -w 1 "$1" 587 < /dev/null | head -n 1 | awk '{if ($0 == "") {print "none"} else if ($1 == "220" && $0 ~ "SMTP ") {print $2} else {print "unknown"}}'
fi
@n-st
n-st / fix-umlauts.sh
Created September 13, 2017 17:29
Converts umlauts (äöüß) to "Code page 437" encoding for PXELINUX boot menus
#!/usr/bin/env bash
## fix-umlauts.sh
# Converts umlauts (äöüß) in files to "Code page 437" encoding, so they will
# display correctly in PXELINUX boot menus.
# Expects one or more file paths as arguments, e.g.:
# $ ./fix-umlaut.sh "pxelinux.cfg/menus/main.menu" "pxelinux.cfg/menus/admin.submenu"
# The files are overwritten in place (using a temp file).
# -------
@n-st
n-st / bash-history-to-zsh-history.py
Created May 31, 2017 18:01 — forked from op/bash-history-to-zsh-history.py
Bash history to Zsh history
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This is how I used it:
# $ cat ~/.bash_history | bash-history-to-zsh-history >> ~/.zsh_history
import sys
def main():