Skip to content

Instantly share code, notes, and snippets.

@jpsutton
jpsutton / toggle_mic_mutes.py
Created March 12, 2025 18:51
Toggle all microphones mute status with on-screen indicator
#!/usr/bin/env python3
import pulsectl
import dbus
def show_notification(title, message, icon_name):
"""
Show a desktop notification using D-Bus directly.
Args:
@jpsutton
jpsutton / README.md
Last active January 28, 2025 19:00
Run AI models on Docker Compose in a more secure way (no egress)

Notes

  1. This is jank.
  2. Modify setup_model.sh to change the AI model in use. If you change the model, you may need to delete the "ollama_data" folder.
  3. This setup assumes that you're using an Nvidia GPU and have the Nvidia Container Toolkit setup on the host OS.
  4. Steps to running this:
    • Download files from the gist to a folder.
    • Open a terminal to that folder, and run docker-compose up
  5. After everything is running, the web UI should be available on http://localhost:3000
@jpsutton
jpsutton / systemd-shutdown-diag.py
Created January 27, 2025 14:43
Python application to analyze the most recent systemd shutdown events to see what was services were taking time to shutdown.
import sys
import subprocess
from datetime import datetime
from tabulate import tabulate
# Dictionary to store the 'Stopping' event timestamps
stopping_events = {}
# Dictionary to store the elapsed time for each service
@jpsutton
jpsutton / evolution-audio-notify.py
Created January 22, 2025 22:07
DBus listener which looks for Evolution new mail and calendar reminder notifications and plays audio in repsonse
#!/usr/bin/env python3
import os
import sys
import dbus
import pygame
import argparse
import datetime
from gi.repository import GLib
@jpsutton
jpsutton / max_brightness_on_wakeup.py
Created November 3, 2024 21:37
KDE+Linux: Set all displays to max brightness when resuming from sleep
#!/usr/bin/env python
import dbus
import dbus.mainloop.glib
import gi
from gi.repository import GLib
# Initialize the D-Bus main loop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@jpsutton
jpsutton / pyfanctrl.py
Last active July 29, 2024 18:33
Simple fan controller in Python using Linux hwmon sensors and liquidctl
#!/usr/bin/env python
import sys
import json
import time
import subprocess
import statistics
"""
{ "sensor_low": 35, "sensor_high": 40, "fan_level": 30 },
@jpsutton
jpsutton / toggle_touchpad.sh
Last active May 31, 2024 16:53
Bash script to toggle the enabled status on your touchpad while running under KDE Plasma 5
#!/bin/bash
SERVICE="org.kde.KWin"
DBUS_PATH="/org/kde/KWin/InputDevice"
INTERFACE="org.kde.KWin.InputDevice"
METHOD_GET="org.freedesktop.DBus.Properties.Get"
METHOD_SET="org.freedesktop.DBus.Properties.Set"
function find_touchpad {
DM_INTERFACE="org.kde.KWin.InputDeviceManager"
@jpsutton
jpsutton / get-nv-temp.sh
Created September 5, 2023 20:34
Reading an Nvidia GPU temperature value from a libvirt Windows guest
#!/bin/bash
GUEST_NAME=Win10_With_GPU
job_exited="false"
exec_result=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec", "arguments": { "path": "nvidia-smi.exe", "arg": [ "--format=csv,noheader", "--query-gpu=temperature.gpu" ], "capture-output": true }}')
exec_pid=$(echo "$exec_result" | jq ".return.pid")
while [ "$job_exited" == "false" ]; do
exec_job_data=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec-status", "arguments": { "pid": '" ${exec_pid}}}")
@jpsutton
jpsutton / TheDivision-PreLauncher.sh
Created January 16, 2023 06:37
The Division - Lutris Pre-Launcher Script
#!/bin/bash
# This is a quick-and-dirty script to monitor the execution of a process, wait for it to die,
# and then ensure that the Ubisoft client dies shortly thereafter. This is useful, as when
# running under Lutris, Ubisoft games spawn the Ubisoft client, and it remains running after
# the game itself has quit. On my system, the Ubisoft client remaining running will keep
# the screen awake, which is decidedly undesirable.
# Enable the following 3 lines for debugging, if needed
#set -x
@jpsutton
jpsutton / yay-wrapper.sh
Last active September 2, 2023 23:09
yay-wrapper
#!/bin/bash
# Flags to enable/disable various functionality (set flag to zero to disable)
UPDATE_MIRRORLIST=1
UPDATE_KEYRING=1
USE_POWERPILL=1
REPORT_CACHE_STATS=1
# Config elements
MIRRORLIST="/etc/pacman.d/mirrorlist"