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 / 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 / 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 / gmimap.py
Last active July 17, 2020 04:33
Class and example for using the Gmail IMAP Extensions
#!/usr/bin/python -tt
#
# Note that this uses xlist, which is deprecated.
#
# This also predates the GMail REST API, which is probably a better mechanism
# https://developers.google.com/gmail/api/
#
#
""" Example of how to use Google IMAP Extensions using Python
@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
"""
@davesteele
davesteele / macmon.py
Last active March 19, 2020 01:11
Python asyncio MAC address monitoring
#!/usr/bin/python3
import socket
import logging
import asyncio
import time
from collections import defaultdict
import json
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
#!/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 / 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/