Skip to content

Instantly share code, notes, and snippets.

aaugustin /
Last active Jan 24, 2021
Hook a Griffin PowerMate to a Raspberry Pi running HifiBerry!
#!/usr/bin/env python3.8
To enable this service, copy this file to /opt, then:
# chmod +x /opt/
# pip3.8 install websockets
# cat > /etc/systemd/system/powermate.service
aaugustin /
Last active Dec 30, 2018
WebSocket compression benchmark
#!/usr/bin/env python
import getpass
import json
import pickle
import subprocess
import sys
import time
import zlib
aaugustin / dates.js
Created Apr 21, 2017
Date arithmetic in JavaScript
View dates.js
export function addYears(date, numYears) {
// Make a copy to avoid mutating the date argument
date = new Date(date.getTime())
// If adding years to a February 29th ends up in a non-leap year, this
// returns March 1st, which is the expected result.
date.setFullYear(date.getFullYear() + numYears)
// DST can also mess with us. Thanks, JavaScript, for not having dates.
if (date.getHours() === 23) {
aaugustin / isValidDate.js
Created Feb 15, 2017
isValidDate in JavaScript
View isValidDate.js
export const DAYS_IN_MONTH = [null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
function daysInMonth(year, month) {
// isValidDate checked that year and month are integers already.
// February of leap years. Assumes that the Gregorian calendar extends
// infinitely in the future and in the past.
if (month === 2 && (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0))) {
return 29
aaugustin /
Last active Jun 24, 2021
Accessibility in browsers: zoom level vs. font size

Scroll to the bottom for the answer


There's two ways to increase the default font size in browsers:

  1. set a default zoom level > 100% ("page zooming")
  2. set a default font size > 16px ("text scaling")

Option 1 relies on the browser's proportional scaling. This feature was

View .git_hooks_pre-commit
#!/usr/bin/env python3.4
"""Git pre-commit hook"""
import os
import subprocess
import sys
def run_linter(cmd, files):
View vega-bug-259.html
<!DOCTYPE html>
<title>Vega - bug 259</title>
<script src=""></script>
<script src=""></script>
<div id="chart"></div>
<script type="text/javascript">
#!/usr/bin/env python
# Copyright (c) 2014 Aymeric Augustin
# Released under the WTFPLv2 -
Quick'n'dirty solver for
Install requests or save next to this
file. Then run: python Tested with Python 2.7 and 3.4.
aaugustin /
Created Jul 29, 2014
WSGI middleware that authenticates against a Django user database.
WSGI middleware that authenticates against a Django user database.
DJANGO_SETTINGS_MODULE should point to a valid Django settings module.
In addition, the following settings are available:
- BASIC_AUTH_LOGIN_URL: DjangoAuth will trigger basic authentication on this
URL. Since browsers only propagate auth to resources on the same level or
below, this URL will usually be '/<something>' without a trailing slash.

Kerberos setup

This guide explains how to set up Kerberos authentication for:

  • SSH access to a server,
  • HTTP access to a service.

It assumes you're running Active Directory and Debian servers.