Skip to content

Instantly share code, notes, and snippets.

@venam
venam / pw-setvol.sh
Last active Jul 5, 2021
Set PipeWire volume natively on the default sink
View pw-setvol.sh
#! /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 Jun 5, 2021
Script to list master/slave pseudoterminal ends on Linux
View pty_ends.pl
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 Sep 14, 2020
Fontconfig for Grouping Win Fonts
View 01-windows.conf
<?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 Sep 2, 2020
Take an ascii string and output possible unicode string equivalent in NFKD so that it is understood by IDNA within URLs
View unicode_from_ascii.js
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 Jul 12, 2018
hosts block autofetcher
View fetch_all_hosts.sh
#!/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 Nov 26, 2015
watermark a bunch of image files in a dir
View watermark.sh
#!/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 Nov 25, 2015
convert a list of pdfs to images of good quality
View pdf_to_images.sh
#!/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 Feb 2, 2017
Convert flv to mkv
View converter.sh
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "usage: ${0} <extension> <replace>"
exit 1
fi
for f in *.${1}
do
newname="${f%${1}}${2}"