Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import asyncio
import binascii
import sys
from bleak import BleakClient
from bleak.backends.characteristic import BleakGATTCharacteristic
NOTIFY_UUID = "aae28f01-71b5-42a1-8c3c-f9cf6ac969d0"
#!/usr/bin/env python3
import asyncio
from pyvelop.mesh import Mesh
async def setEnabled(mesh, enabled):
await mesh._async_make_request(action="http://linksys.com/jnap/routerupnp/SetUPnPSettings", payload={"isUPnPEnabled": enabled,"canUsersConfigure": False, "canUsersDisableWANAccess": False})
async def main():
async with Mesh(node="192.168.1.1", password="INSERT_PASSWORD_HERE") as mesh:
#!/usr/bin/env python3
# * Browse to https://app.expopass.com/events/4jrvzmj/schedule
# * Use devtools to grab the JSON responses from *both* requests like
# https://api.expopass.com/rest/sessions/?ids=...
from datetime import datetime
from dateutil import tz
from hashids import Hashids
import csv
@chrisboyle
chrisboyle / webcam-monitor-inotify.py
Last active March 8, 2023 18:30
Tells Home Assistant whether my webcam is in use. The inotify one is unreliable, alas, as Discord leaks webcam file descriptors e.g. every time you test video :-(
#!/usr/bin/env python3
from pathlib import Path
from asyncinotify import Inotify, Mask
from collections import Counter
from homeassistant_api import Client
import asyncio
import glob
import os
#!/usr/bin/env python3
import os
import googlemaps
from datetime import datetime
# https://console.cloud.google.com/google/maps-apis/start
key = os.getenv('GOOGLE_MAPS_API_KEY')
gmaps = googlemaps.Client(key = key)
@chrisboyle
chrisboyle / aiohue2sonoff.py
Created July 20, 2022 23:36
A simple bridge from Hue switches to eWeLink/Sonoff relays
#!/usr/bin/env python3
import asyncio
import logging
from aiohue import HueBridgeV2
from aiohue.v2 import EventType
from aiohue.v2.models.button import Button, ButtonEvent
import ewelink
from ewelink import Client, DeviceOffline, Power
@chrisboyle
chrisboyle / dp855.patch
Created March 28, 2021 22:20
Vasco DP855 PIN pad support (horrible hack) in GnuPG, created for 2.2.19-3ubuntu2.1
Description: Support Vasco DP855 PIN pad with horrible hacks
Disable varlen and assume PIN lengths.
Author: Chris Boyle <[email protected]>
---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: <vendor|upstream|other>, <url of original patch>
@chrisboyle
chrisboyle / corsair-virtuoso.py
Last active December 28, 2019 00:32
Custom LED / mic button behaviour and battery checking on Corsair Virtuoso
#!/usr/bin/env python3
# Custom LED / mic button behaviour and battery checking on Corsair Virtuoso
# Suggested udev rules to put in e.g. /etc/udev/rules.d/52-corsair.rules
# SUBSYSTEM=="usb", ATTR{idVendor}=="1b1c", ATTR{idProduct}=="0a41", MODE="0660", GROUP="plugdev"
# SUBSYSTEM=="usb", ATTR{idVendor}=="1b1c", ATTR{idProduct}=="0a42", MODE="0660", GROUP="plugdev"
import alsaaudio
import enum
import hid
@chrisboyle
chrisboyle / hue2sonoff.py
Last active November 4, 2019 12:51
Quick hack to make my Hue switches control a Sonoff/eWeLink device as well.
#!/usr/bin/env python3
HUE_POLL_SECONDS = 5
HUE_IP = '192.168.1.123'
HUE_USERNAME = 'xyz123' # see https://github.com/quentinsf/qhue#creating-a-user
HUE_NAME_LOWER_SUBSTRINGS = ['living room', 'front door']
EWELINK_USERNAME = '[email protected]'
EWELINK_PASSWORD = 'password'
EWELINK_REGION = 'eu'
EWELINK_OUTLET = None
#!/usr/bin/env python3
import bgtunnel
import requests
import subprocess
import sys
if sys.version_info >= (3, 0):
from urllib.parse import urlsplit, urlunsplit
else: