Skip to content

Instantly share code, notes, and snippets.

View ssokolow's full-sized avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / update_flatpak_cli.py
Last active November 4, 2024 19:38
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 / 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 / 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,
@ssokolow
ssokolow / completingplaintextedit.py
Created May 10, 2024 05:44
QPlainTextEdit subclass with completion and extras, suitable for Qt Designer promotion
"""A QPlainTextEdit subclass with completion and some extras
Adapted from
https://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.html
with the intent to be a minimally complicated way to get as-you-type
autocomplete in a QTextEdit.
As such, a lot of needless complexity has been removed, and odd design choices
which make the code needlessly difficult to maintain have been corrected.
@ssokolow
ssokolow / openraster_test.py
Created October 7, 2024 09:13
Proof of Concept for OpenRaster-based "Use external editor" option
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Proof of concept code for generating and opening an OpenRaster image in the
user's preferred OpenRaster editor.
"""
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__appname__ = "OpenRaster Proof of Concept"
__version__ = "0.1"
__license__ = "MIT"
@ssokolow
ssokolow / update_check.py
Last active September 16, 2024 19:52
Simple apt-get update notifier using desktop notifications and cron
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Simple notify2-based apt-get update notifier
Requires:
- dbus-python (A.K.A. python-dbus)
- notify2
- python-gobject (for Python 2.x)
(Though it shouldn't be too difficult to adapt to Python 3.x since
@ssokolow
ssokolow / dialog_collapsed_with_reporting_callback.png
Last active September 9, 2024 04:12
Port and refactoring of gtkexcepthook.py for PyQt 5.x and Python 3.5+
dialog_collapsed_with_reporting_callback.png
@ssokolow
ssokolow / x11_watch_active_window.py
Last active September 4, 2024 21:19
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 / transmission_vpn.py
Last active August 1, 2024 18:57
Wrapper to bind Transmission to the IP for a VPN interface on Linux or refuse to start on failure
#!/usr/bin/env python
"""Simple wrapper to update Transmission's IPv4 binding on startup for use with VPNs.
(For Linux systems. Tested on Ubuntu 14.04 LTS)
"""
import json, os, subprocess
VPN_IF = "tun0"
TRANSMISSION_CFG = os.path.expanduser('~/.config/transmission/settings.json')
@ssokolow
ssokolow / trackball.sh
Last active July 13, 2024 17:20
xinput configuration for an old two-button Logitech Marble Mouse
#!/bin/sh
# Setup for comfortable use of an old two-button Logitech Marble Mouse
# via a cheap USB-PS/2 adapter.
#
# Resulting functionality:
# 1. Pointer acceleration is tweaked to be usable on a three-monitor spread
# 2. Press and hold left button for 300ms to get right-click
# 3. Right mouse button is remapped to middle mouse button
# 4. Holding the right button turns the trackball into a scroll wheel
# 5. Both vertical and horizontal scrolling are enabled