Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / prompt_gentoo_setup.sh
Created Aug 12, 2022
My performance-optimized Zsh prompt
View prompt_gentoo_setup.sh
#!/bin/zsh
# Modified gentoo prompt theme
# customized by Stephan Sokolow for git branch and virtualenv display based on:
# http://www.jukie.net/~bart/blog/20071219221358
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/#comment-4166
# https://virtualenvwrapper.readthedocs.io/en/latest/tips.html
#
# See also:
# https://www.topbug.net/blog/2016/10/11/speed-test-check-the-existence-of-a-command-in-bash-and-zsh/
@ssokolow
ssokolow / update_flatpak_cli.sh
Last active Aug 1, 2022
Proof of concept for making Flatpak-installed GUI apps available in the terminal through their normal command names
View update_flatpak_cli.sh
#!/bin/sh
# Flatpak CLI Shortcut Proof of Concept
# Copyright 2021 Stephan Sokolow (deitarion/SSokolow)
#
# License: MIT
#
# Known shortcomings in this quick and dirty PoC:
# * In order to support non-local URL arguments to Flatpak'd browsers, use of
# --file-forwarding assumes all installed programs will accept file:// URLs.
# (A proper solution would parse the .desktop files to identify what kinds of
@ssokolow
ssokolow / onelinespelltextedit.py
Last active Jul 22, 2022
QLineEdit replacement with automatic PyEnchant spell-checking (based on QPlainTextEdit because it's easier to implement)
View onelinespelltextedit.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Single-Line QPlainTextEdit With Inline Spell Check mimicking QLineEdit
Original PyQt4 Version:
https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
Multi-Line Version:
https://gist.github.com/ssokolow/0e69b9bd9ca442163164c8a9756aa15f
TODO:
@ssokolow
ssokolow / term_qt.py
Created Apr 26, 2020
Example of creating a simple terminal emulator widget from a QTextEdit
View term_qt.py
"""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 / x11_watch_active_window.py
Last active Jul 21, 2022
python-xlib example which reacts to changing the active window
View x11_watch_active_window.py
#!/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 / escape_non_utf8_paths.rs
Last active Jun 20, 2022
Code for storing Rust Path/PathBuf data as valid UTF-8 (eg. JSON) strings
View escape_non_utf8_paths.rs
/*
Copyright 2018-2020, Stephan Sokolow
This code is released under your choice of the MIT or Apache-2.0 licenses.
https://opensource.org/licenses/MIT
https://opensource.org/licenses/Apache-2.0
*/
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
@ssokolow
ssokolow / godot_game.iss
Created Mar 23, 2022
Example Inno Setup script for Godot games
View godot_game.iss
; IMPORTANT: Follow the instructions at
; https://docs.godotengine.org/en/stable/getting_started/workflow/export/changing_application_icon_for_windows.html
; and make sure the "Options > Application > Product Version" field is set
; in Godot's Export dialog before exporting your EXE file. Otherwise,
; Inno Setup will mistake the Godot version for your game's version.
;
; You can check whether you were successful by examining the .EXE file's
; properties dialog on Windows, or by using the `peres -v` command from `pev`
; on Linux.
;
@ssokolow
ssokolow / camelcase.rs
Last active Jun 20, 2022
CamelCase parser for Rust
View camelcase.rs
//! Routines for parsing camelcase strings
//!
use std::mem::replace;
use unicode_categories::UnicodeCategories;
use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation};
// --== Enums ==--
// TODO: Refresh my memory of which other traits I'm advised to derive on this.
@ssokolow
ssokolow / trackball.sh
Last active Jun 4, 2022
xinput configuration for an old two-button Logitech Marble Mouse
View trackball.sh
#!/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
@ssokolow
ssokolow / pagination_example.sql
Created Dec 23, 2009
Reasonably efficient pagination without OFFSET (SQLite version)
View pagination_example.sql
-- 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