Skip to content

Instantly share code, notes, and snippets.

View medmunds's full-sized avatar

Mike Edmunds medmunds

  • Planapple
  • San Francisco, CA, USA
  • 22:37 (UTC -07:00)
View GitHub Profile
@medmunds
medmunds / zen34.yaml
Last active August 7, 2023 21:13 — forked from flyingsubs/zen34.yaml
blueprint tutorial for Zen34
blueprint:
name: Zooz ZEN34
description: Automations helper for the Zooz ZEN34 S2 Switch using the Zwave
JS integration.
domain: automation
input:
zooz_zen34:
name: Zooz ZEN34
description: The ZEN34 Switch to interact with.
selector:
@medmunds
medmunds / README.md
Last active August 6, 2020 22:13
Dexie TrackedTransaction addon

This is an addon for [Dexie][] v3+ that adds a new db.trackedTransaction() method, using DBCore middleware.

trackedTransaction() is called just like transaction(), but takes an additional report function that is called with a list of TrackedChange records once the transaction is ready to commit (but before it actually commits).

See additional docs in the module declaration, and examples in the test file.

@medmunds
medmunds / patch_boto.py
Created September 21, 2018 00:48
Monkey-patch botocore to improve performance on large API requests
# Monkeypatch botocore.awsrequest.AWSRequest.body to improve performance by caching result.
# Usage: import this file once, at some point before making boto3 requests
# See https://github.com/boto/botocore/issues/1561
import six
from botocore.awsrequest import AWSRequest
# Monkeypatch AWSRequest.body to improve performance by caching result.
# - AWSRequest.body is accessed multiple times during request signing.
@medmunds
medmunds / lambda_function.py
Created September 20, 2018 23:36
Test botocore performance preparing large API requests in AWS Lambda
# This is an AWS Lambda function to help isolate apparent botocore performance issues
# when posting API requests with large parameters (e.g., SES.SendRawEmail with an 8MB
# RawMessage). See https://github.com/boto/botocore/issues/1561.
#
# Recommended Lambda config:
# Runtime: Python 3.6
# Handler: lambda_function.run_test
# Environment variables: SES_FROM = "your-validated-ses-sender@example.com"
# (if not set, SES will complain, but the timings should still be valid)
# Memory: 256 MB
@medmunds
medmunds / first_working_email_backend.py
Last active September 6, 2016 20:52
Django FirstWorkingEmailBackend uses ESP status APIs to find an "up" ESP for sending
# *Untested* implementation of a Django email backend that checks
# several ESP status APIs to see which are working, and uses the first
# available one to send.
#
# This caches the ESP API status check results for one hour (by default).
# You can subscribe to webhook notifications on the ESP status pages
# to force status re-checks after ESPs update their status pages.
#
# See https://github.com/anymail/django-anymail/issues/31 for discussion.
#
@medmunds
medmunds / compare_vtimezones.py
Created May 28, 2016 19:05
Compare vobject VTIMEZONEs for pytz and dateutil.tz timezones
# Detect differences between pytz and dateutil.tz.gettz,
# by comparing the vobject VTIMEZONEs for each.
#
# (Might actually be finding problems in vobject's
# timezone rule detection.)
#
# Requirements::
# pip install pytz dateutil vobject
import dateutil.tz
@medmunds
medmunds / README.md
Created March 29, 2016 02:32
Taking back your Mandrill click-tracking links

Taking back your Mandrill click-tracking links

My company, like many, has recently switched away from using Mandrill for our transactional email.

We'd been using Mandrill's [click-tracking][mandrill-click-tracking] feature, and became worried about what would happen to all those old emailed links after we cancel our Mandrill account.

Why should we care about links in emails sent a month or more ago?

@medmunds
medmunds / winstate.js
Created May 9, 2015 00:41
Save and restore window state for Electron (Atom-Shell)
// Preserve and restore window state in localStorage.
// Adapted for Electron from nw.js:
// https://github.com/nwjs/nw.js/wiki/Preserve-window-state-between-sessions
//
// As written, it only handles a single-window app.
//
// This code is meant to run in the renderer process.
// To use, load from index.html (or whatever file you loadUrl into your BrowserWindow):
// <script src="winstate.js"></script>
@medmunds
medmunds / find-focus-stealer.py
Created February 6, 2015 00:51
Find the Mac OSX app that's stealing the active window away
#!/usr/bin/python
# Print the active OSX app whenever it changes.
# (Use to figure out which ill-behaved app is stealing focus away from you.)
# Adapted from http://apple.stackexchange.com/a/148094/112614
try:
from AppKit import NSWorkspace
except ImportError:
print "Can't import AppKit -- maybe you're running python from brew?"
print "Try running with Apple's /usr/bin/python instead."
@medmunds
medmunds / mail.py
Created January 15, 2015 22:13
queue_message for use with django-mailer
# queue_message(message, priority="medium")
# Queues an EmailMessage object, in apps using django-mailer.
# (https://github.com/pinax/django-mailer)
# Respects django-mailer's DontSendEntry blacklist.
# If django-mailer is not loaded, just sends the message immediately.
from django.conf import settings
if "mailer" in settings.INSTALLED_APPS:
# Sigh. Django-mailer doesn't expose its queuing API in a useful way, so we replicate parts of it here.