Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / anon.sh
Last active Sep 10, 2020
Zsh command to make an "incognito mode" for a terminal
View anon.sh
# Convenience helper to set up an "incognito mode" for a shell session.
#
# Installation:
# 1. Create a folder like ~/.zsh/functions
# 2. Add it to your ZSH function path with fpath=(~/.zsh/functions(:A) $fpath) in ~/.zshenv
# 3. Save this script as ~/.zsh/functions/anonsh
# 4. Add `autoload -Uz anonsh` to your ~/.zshrc
#
# Now you can type `anonsh` in any zsh session
#
@ssokolow
ssokolow / 1_screenshot.png
Last active Sep 10, 2020
Simple PyQt5 application to inspect drag-and-drop or clipboard data
@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 / ocv.py
Created Apr 24, 2020
OpenCV's :ocv: Sphinx domain, patched up for Sphinx 2.3
View ocv.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
ocv domain, a modified copy of sphinx.domains.cpp + shpinx.domains.python.
The original copyright is below
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The OpenCV C/C++/Python/Java/... language domain.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
@ssokolow
ssokolow / tweets.py
Created Mar 15, 2020
Alternative viewer for tweets in a Twitter data export
View tweets.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A simple script to preview the text of tweets in tweet.js from a Twitter
dump.
Accepts Zip files fresh from Twitter or extracted tweet.js files as input.
"""
# Prevent Python 2.x PyLint from complaining if run on this
from __future__ import (absolute_import, division, print_function,
@ssokolow
ssokolow / audit_python2.py
Last active Feb 13, 2020
Quick script to find Python files which may need porting to run on Python 3
View audit_python2.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A simple helper to search for Python scripts which still don't declare
python3 in their shebang lines as a proxy for finding un-migrated scripts.
"""
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__appname__ = "Python 2.x Auditor"
__version__ = "0.1"
__license__ = "MIT"
@ssokolow
ssokolow / escape_non_utf8_paths.rs
Last active Feb 2, 2020
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 / python_boilerplate.py
Created Oct 13, 2019
The raw/initial output from "boiler" in my ~/.vim/snippets/python.snippets
View python_boilerplate.py
#!/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 / mass_diff.py
Created Oct 4, 2019
Quick helper script to cross-compare large numbers of dumps of a ROM or disk to identify bits that vary between dumps
View mass_diff.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Simple tool to identify bad bits in a cartridge by comparing many dumps
--snip--
Requires numpy.
"""
@ssokolow
ssokolow / gist:5b59998d2245325758ac9bbf462605c2
Created Aug 25, 2019
Helper script to override Firefox's attempt to open .cbz files as Zip files, regardless of OS file associations
View gist:5b59998d2245325758ac9bbf462605c2
#!/bin/sh
# NOTE: Despite this script using KDE commands like ark and kdialog, Firefox
# doesn't obey KDE's file associations, so you'll need to use a non-KDE
# file manager like PCManFM to edit the file associations.
open_zip() {
exec ark "$@"
}
offer_comix() {
You can’t perform that action at this time.