Skip to content

Instantly share code, notes, and snippets.

View kontza's full-sized avatar

Juha Ruotsalainen kontza

View GitHub Profile
@kontza
kontza / snippet-wezterm.lua
Last active January 8, 2024 09:24
Change WezTerm background color based on SSH host; copy this snippet to your WezTerm config + define your own host_to_color mapping
-- Hash char is here to make good editors show the color in situ.
local host_to_color = {
["main.*p"] = "#660000",
["other.*q"] = "#660066",
-- key = a pattern to match a hostname
-- value = the color to use as pane background for the hostname
}
local colored_panes = {}
wezterm.on("update-status", function(window, pane)
local fg = pane:get_foreground_process_info() or {}
@kontza
kontza / main.go
Created December 21, 2023 08:38
Injecting data into Influx from a pre-named CSV file. Downsampled to 5 minutes.
package main
import (
"bufio"
"context"
"log"
"os"
"strconv"
"strings"
"time"
@kontza
kontza / yaml2properties.py
Last active April 13, 2023 03:35
Convert either a given YAML file or a YAML from stdin into Java style properties. Requires click, flatdict & pyyaml.
#!/usr/bin/env python3
import click
import flatdict
import yaml
import sys
class DefaultToStdin(click.Argument):
def __init__(self, *args, **kwargs):
kwargs["nargs"] = 1
@kontza
kontza / db.sh
Created November 9, 2022 08:09
Extract DB specs from .pgpass and open a psql session there
#!/bin/sh
IFS=':' read -r -a PARTS <<< $(fgrep "$1" ~/.pgpass)
if test -n "${PARTS[3]}";then
psql -h ${PARTS[0]} -p ${PARTS[1]} -U ${PARTS[3]} ${PARTS[2]}
else
echo "No database defined! Cannot continue."
fi
@kontza
kontza / ssc.fish
Last active October 10, 2022 11:36
Change macOS iTerm background its font name and size based on the desired ssh hostname. This script is named `ssc` so that I can SSH into some host without these tweaks.
#!/opt/local/bin/fish
function set_bg
osascript -e "tell application \"Terminal\" to set background color of window 1 to $argv[1]"
end
function set_profile
osascript -e "tell application \"Terminal\" to set current settings of window 1 to settings set \"$argv[1]\""
end
function set_iterm_bg
clear && \
sudo netstat -tUlpn|\
awk '/java/{gsub(/\/java/, "", $7);gsub(/^[0-9.]+\:/, "", $4);printf "%6s = ",$4; system("ps -o user,args -p " $7 " --no-headers")}'|\
sort
@kontza
kontza / loop-it.sh
Created September 25, 2020 11:56
A sample Bash-script for processing a list file line by line and omitting lines starting with a '#'.
while IFS= read -r LINE
do
LINE=$(echo $LINE|xargs)
# The next line's magic bypasses lines starting with a '#'.
[[ $LINE =~ ^#.* ]] && continue
echo ">>> Processing '$LINE'..."
done < list.file
@kontza
kontza / loop-it.fish
Created September 25, 2020 11:50
A sample Fish-script for processing a list file line by line and omitting lines starting with a '#'.
while read LINE
set -l LINE (string trim $LINE)
if string match -rqv '^#' $LINE
echo ">>> Processing line '$LINE'..."
end
end < list.file
@kontza
kontza / 20-pull-the-brake.fish
Created April 9, 2020 05:50
This is how I transcode DVB-T recordings. Created a gist out of it to demo how Fish's `argparse` works. Fish rulez!
# Special functions to make video encoding easier.
set -g __default_encode "Playstation 720p30"
set -g __high_quality_encode "HQ 1080p30 Surround"
function pull_the_brake_help
for line in "Usage: [options] files..." \
"Options:" \
" -a/--start-at <number>" \
" Start encoding at a given offset in seconds." \
" -c/--crop <top:bottom:left:right>" \
@kontza
kontza / multicaster.py
Last active February 10, 2022 07:35
A simple multicast sender/listener. Adapted from https://pymotw.com/3/socket/multicast.html to contain both the sender and the listener in the same script.
#!/usr/bin/env python
import argparse
import datetime
import socket
import struct
import time
def listener(args):