Skip to content

Instantly share code, notes, and snippets.

@venam
venam / pw-setvol.sh
Last active May 21, 2024 18:21
Set PipeWire volume natively on the default sink
#! /bin/sh
# the metadata only contains the name of the default sink
default_sink_name=$(pw-metadata 0 'default.audio.sink' | grep 'value' | sed "s/.* value:'//;s/' type:.*$//;" | jq .name)
default_sink_id=$(pw-dump Node Device | jq '.[].info.props|select(."node.name" == '" $default_sink_name "') | ."object.id"')
current_volume=$(pw-cli enum-params "$default_sink_id" 'Props' | grep -A 2 'Spa:Pod:Object:Param:Props:channelVolumes' | awk '/Float / {gsub(/.*Float\s/," "); print $1^(1/3) }')
change="${1:-0.1}" # defaults to increment of 0.1
new_volume=$(echo "$current_volume $change" | awk '{printf "%f", $1 + $2}')
# we need to reconvert to cubic root
#new_volume_cube=$(echo "$new_volume" | awk '{ print $1^3 }')
@venam
venam / pty_ends.pl
Created June 5, 2021 12:31
Script to list master/slave pseudoterminal ends on Linux
use strict;
use warnings;
print "MASTER\tSLAVES\n";
my $pid = -1;
for my $master_end (qx#lsof -F pcf /dev/ptmx#) {
chomp $master_end;
if ($master_end =~ /p.*/) {
print "\n" if $pid>0;
$pid = substr($master_end, 1);
@venam
venam / 01-windows.conf
Created September 14, 2020 05:13
Fontconfig for Grouping Win Fonts
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<description>Make Windows Font Look Good</description>
<match target="font">
<edit name="iswindowsfont" mode="assign">
<or>
<eq>
@venam
venam / unicode_from_ascii.js
Last active September 2, 2020 00:13
Take an ascii string and output possible unicode string equivalent in NFKD so that it is understood by IDNA within URLs
function conv_to_uni(st) {
udata = {"66":["7470","8492","9399","119809","119861","119913","120017","120069","120121","120173","120225","120277","120329","120381","120433","127281","65314"],"87":["7490","9420","119830","119882","119934","119986","120038","120090","120142","120194","120246","120298","120350","120402","120454","127302","65335"],"77":["7481","8499","8559","9410","119820","119872","119924","120028","120080","120132","120184","120236","120288","120340","120392","120444","127292","65325"],"69":["7473","8496","9402","119812","119864","119916","120020","120072","120124","120176","120228","120280","120332","120384","120436","127284","65317"],"90":["8484","8488","9423","119833","119885","119937","119989","120041","120197","120249","120301","120353","120405","120457","127305","65338"],"98":["7495","9425","119835","119887","119939","119991","120043","120095","120147","120199","120251","120303","120355","120407","120459","65346"],"117":["7512","7524","9444","119854","119906","119958","120010","120062",
@venam
venam / fetch_all_hosts.sh
Created July 12, 2018 04:35
hosts block autofetcher
#!/bin/bash
# fetch the new block list
wget 'https://v.firebog.net/hosts/lists.php?type=all' -O list_all
# reset the old hosts directory
rm -r all_hosts
mkdir all_hosts
# read the file and download into the all_hosts directory
while read a; do
@venam
venam / watermark.sh
Last active November 26, 2015 06:23
watermark a bunch of image files in a dir
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "Usage: $0 dir text" >&2
exit 1
fi
# 1275x1650 - the size of the A4 images
dir=$1
text=$2
@venam
venam / pdf_to_images.sh
Created November 25, 2015 17:28
convert a list of pdfs to images of good quality
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 pdfs" >&2
exit 1
fi
for pdf in "$@"
do
echo "Converting $pdf to images"
pages="$( pdfinfo "$pdf" |grep Pages | sed -e 's/Pages:\( \)\+//')"
@venam
venam / converter.sh
Last active February 2, 2017 07:07
Convert flv to mkv
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "usage: ${0} <extension> <replace>"
exit 1
fi
for f in *.${1}
do
newname="${f%${1}}${2}"