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 April 25, 2024 06:40
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 / escape_non_utf8_paths.rs
Last active April 11, 2024 05:42
Code for storing Rust Path/PathBuf data as valid UTF-8 (eg. JSON) strings
/* POSIX paths in JSON via escaping which
doesn't alter valid UTF-8 paths.
The trick is recognizing that JSON can store binary nulls in strings
but nulls are the only character that can't occur in POSIX paths,
so we can use it as an escape character that won't change how existing
serialized paths get interpreted.
Copyright 2018-2020, Stephan Sokolow
@ssokolow
ssokolow / firefox_migration.rst
Last active February 26, 2024 04:35
Disaster Plans for Firefox XUL Sunset

Disaster Plans for Firefox XUL Sunset

Public URL

Github Gist

Status

Incomplete

Last Updated

2018-08-23 04:10 EDT

Threat Summary

@ssokolow
ssokolow / pycalendar.py
Last active February 8, 2024 21:00
Refactored version of Bill Mill's printable calendar code
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Generate a printable calendar in PDF format, suitable for embedding
into another document.
Tested with Python 2.7.
Dependencies:
- Python
- Reportlab
@ssokolow
ssokolow / x11_watch_active_window.py
Last active February 6, 2024 22:50
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 / dialog_collapsed_with_reporting_callback.png
Last active January 17, 2024 09:34
Port and refactoring of gtkexcepthook.py for PyQt 5.x and Python 3.5+
dialog_collapsed_with_reporting_callback.png
@ssokolow
ssokolow / python_boilerplate.py
Created October 13, 2019 08:54
The raw/initial output from "boiler" in my ~/.vim/snippets/python.snippets
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""[application description here]"""
# Prevent Python 2.x PyLint from complaining if run on this
from __future__ import (absolute_import, division, print_function,
with_statement, unicode_literals)
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__appname__ = "[application name here]"
@ssokolow
ssokolow / manga_to_html.py
Created November 23, 2023 07:15
Quick script to split a CBZ file full of two-page scans into pages and then bundle them into data URIs in a .html file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A quick helper for splitting manga pages in a CBZ containing two-page
spreads and then bundling them into base64 URLs in an HTML file so the mobile
Safari preview inside the iOS Files app can act as a quick-and-dirty manga
reader.
Takes .cbz files and produces large .html files.
Currently assumes first image will be a cover and doesn't split it.
@ssokolow
ssokolow / manga_split.py
Created November 23, 2023 06:05
Quick script to split manga CBZs scanned as two-page spreads so they'll convert with proper page order in Calibre
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A quick helper for splitting manga pages so Calibre doesn't split them for
you and present them in the wrong order.
Takes and produces .cbz files.
Currently assumes first image will be a cover and doesn't split it.
"""