Skip to content

Instantly share code, notes, and snippets.

View ssokolow's full-sized avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / prep_scummvm_games.py
Last active April 27, 2025 02:39
Script to automate adding ScummVM games to EmulationStation Desktop Edition
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# prep_scummvm_games.py
# Copyright 2025 Stephan Sokolow
#
# Helper for batch-adding ScummVM games to ES-DE.
#
# License: MIT (https://opensource.org/license/mit)
#
@ssokolow
ssokolow / term_qt.py
Created April 26, 2020 09:04
Example of creating a simple terminal emulator widget from a QTextEdit
"""Primitive terminal emulator example made from a PyQt QTextEdit widget."""
import fcntl, locale, os, pty, struct, sys, termios
import subprocess # nosec
# Quick hack to limit the scope of the PyLint warning disabler
try:
# pylint: disable=no-name-in-module
from PyQt5.QtCore import Qt, QSocketNotifier # type: ignore
from PyQt5.QtGui import QFont, QPalette, QTextCursor # type: ignore
@ssokolow
ssokolow / partial_shell_parser.py
Last active March 27, 2025 02:12
Python code to extract variables from a shell script
import shlex
def lex_shellscript(script_path, statement_cb):
"""Given a file-like object, use a POSIX-mode shlex.shlex object to split
it into statements and call the given statement processor to convert
statements into dicts.
"""
fields = {}
with open(script_path, 'r') as fobj:
@ssokolow
ssokolow / update_flatpak_cli.py
Last active February 28, 2025 20:20
Utility for making Flatpak-installed apps available in the terminal through their normal command names
#!/usr/bin/env python3
"""Flatpak CLI Shortcut Generator
A simple no-argument tool that generates launchers with traditional non-flatpak
command names for your installed Flatpak applications in ~/.local/bin/flatpak.
Does full collision detection and warns you if you forgot to add its output
directory to your PATH. Also overrules the command-line specified in the
``.desktop`` file if the Flatpak maintainer didn't include support for
command-line arguments.
@ssokolow
ssokolow / x11_watch_active_window.py
Last active February 22, 2025 20:46
python-xlib example which reacts to changing the active window
#!/usr/bin/env python
"""python-xlib example which reacts to changing the active window/title.
Requires:
- Python
- python-xlib
Tested with Python 2.x because my Kubuntu 14.04 doesn't come with python-xlib
for Python 3.x.
@ssokolow
ssokolow / win7.sh
Created February 12, 2025 05:05
Script to trigger a KVM switch on Linux by blinking Scroll Lock
#!/bin/bash
# Toggle the KVM switch programmatically by toggling the Scroll Lock LED
# Source: https://askubuntu.com/a/546989/23552
SLEEP=0.5
LEDNAME="Scroll Lock"
echo "Switching..."
xset led named "$LEDNAME"
sleep $SLEEP
@ssokolow
ssokolow / Cargo.toml
Last active February 9, 2025 22:14
Simple example of getting the rust-cpython and setuptools-rust examples working together
[package]
name = "unimportant_if_subsumed_by_setuptools"
version = "0.1.0"
authors = ["Your Name Here <your@email.com>"]
[lib]
name = "unimportant_if_subsumed_by_setuptools"
crate-type = ["cdylib"]
[dependencies.cpython]
@ssokolow
ssokolow / pagination_example.sql
Created December 23, 2009 13:02
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
@ssokolow
ssokolow / ksni_practice.py
Created December 5, 2024 22:24
Python+QtDBUS reimplementation of (most of) org.kde.StatusNotifierItem
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""A demonstration of implementing (most of) org.kde.StatusNotifierItem using
QtDBus to serve as as an example of how more advanced QtDBus features map to
PyQt5, absent robust documentation for how the schema annotations translate.
"""
import os
import signal
import sys
@ssokolow
ssokolow / image_widget.py
Last active October 25, 2024 22:12
PyQt 5.x code for Just Do What I Mean™ image display in the presence of animated GIFs and containers with no fixed aspect ratio
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Example code for a PyQt image-display widget which Just Works™
TODO: Split this into a loader wrapper and a widget wrapper so it can be used
in designs which maintain a preloaded queue of upcoming images to improve
the perception of quick load times.
"""
from __future__ import (absolute_import, division, print_function,