Skip to content

Instantly share code, notes, and snippets.

@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 / 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)
@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
@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 / 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 / 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 / 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)
#!/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 / 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 / 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")