Skip to content

Instantly share code, notes, and snippets.

@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"
@jpsutton
jpsutton / explainshell.sh
Last active August 25, 2022 15:55
CLI interface to explainshell.com
#!/usr/bin/env sh
#
# Explain a given shell command using explanation from explainshell.com
#
# Usage: explainshell <command>
#
# Credit: Derived from https://github.com/benjamine/explain.sh
# License: MIT
URL="$*"
@jpsutton
jpsutton / springframework_scanner.py
Created April 1, 2022 16:03
This python application scans all fixed-disk filesystems (or the root fs on non-windows systems) for jar/war files and reports any with "spring" in the file name or with "springframework" inside of them
#!/usr/bin/env python
import os
import sys
import platform
import tempfile
from zipfile import ZipFile
if platform.system() == "Windows":
import win32api, win32con, win32process
@jpsutton
jpsutton / decorate_private.py
Created May 9, 2019 14:22
Decorate a method to provide it similar "private" semantics as other languages (e.g., C++)
from functools import wraps
import inspect
# This defines a decorator that can be used on an instance method, to stop it from being inherited by child classes
class _private_method(object):
def __init__(self, decorated):
self._decorated = decorated
def __set_name__(self, owner, name):
@wraps(self._decorated)