Skip to content

Instantly share code, notes, and snippets.

@davesteele
davesteele / curses_demo.py
Last active February 6, 2024 17:26
A Python asyncio curses template
#
# This file supports http://davesteele.github.io/development/2021/08/29/python-asyncio-curses/
#
import asyncio
from abc import ABC, abstractmethod
from curses import ERR, KEY_RESIZE, curs_set, wrapper
import _curses
@davesteele
davesteele / rc.local
Last active September 7, 2023 18:42
Implement a Pi Keyboard Jiggler using pizero-usb-hid-keyboard
#!/usr/bin/env bash
/home/pi/pizero-usb-hid-keyboard/rpi-hid.sh
chmod 777 /dev/hidg0
/home/pi/tickle.py &
exit 0
@davesteele
davesteele / gettodo.py
Created July 20, 2020 13:18
Synchronize Dropbox todo.txt on a Raspberry Pi
#!/home/pi/virtualenvs/todo/bin/python
import dropbox
access_token = ""
dbx = dropbox.Dropbox(access_token)
dbx.files_download_to_file("/home/pi/Dropbox/todo/todo.txt", "/todo/todo.txt")
@davesteele
davesteele / git_to_discord.py
Last active April 23, 2020 14:11
Automatic git commit submission to Discord
#!/usr/bin/python3
from collections import namedtuple
from datetime import datetime
import re
import requests
import subprocess
import sys
"""
#!/usr/bin/python3
"""
Report the pejacevic piuparts waiting count, by day, in csv format.
Counts are broken out by section precedence.
"""
from collections import defaultdict
import csv
@davesteele
davesteele / exception_text
Last active January 5, 2020 20:34
Capture Python exception text for future logging
#!/usr/bin/python
import io
import traceback
try:
1.0/0.0
except ZeroDivisionError as e:
with io.StringIO() as fp:
traceback.print_exc(file=fp)
@davesteele
davesteele / foo-dbus.conf
Last active December 3, 2019 00:17
Possible dbussy ravel listen_signal bug?
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!-- store in /etc/dbus-1/system.d -->
<busconfig>
<policy user="root">
<allow own="com.foo"/>
</policy>
<policy context="default">
<allow send_destination="com.foo"/>
@davesteele
davesteele / bignotify.py
Last active December 14, 2019 16:34
Hexchat - Really noticable message notification plugin
import hexchat
"""
Restore and raise the hexchat main window whenever a message is received.
To get this working on a recent Ubuntu GNOME environment, you also need to:
- Install the Firefox GNOME Shell Integration extension.
https://addons.mozilla.org/en-US/firefox/addon/gnome-shell-integration/
- Install the GNOME "Steal My Focus" extension.
https://extensions.gnome.org/extension/234/steal-my-focus/
@davesteele
davesteele / cache_dict.py
Last active October 19, 2023 14:23
Python LRU Caching Dictionary - a dict with a limited number of entries, removing LRU elements as necessary
from collections import OrderedDict
# >>> import cache_dict
# >>> c = cache_dict.CacheDict(cache_len=2)
# >>> c[1] = 1
# >>> c[2] = 2
# >>> c[3] = 3
# >>> c
# CacheDict([(2, 2), (3, 3)])
# >>> c[2]
@davesteele
davesteele / command_collision.py
Last active June 4, 2019 21:15
Find duplicate executable names in Debian
#!/usr/bin/python3
import aiohttp
from asyncio import create_task, sleep, wait, Semaphore,\
Queue, run, ALL_COMPLETED
from collections import defaultdict
import json
import re
#import random