Skip to content

Instantly share code, notes, and snippets.

@aaugustin
aaugustin / powermate.py
Last active Jan 24, 2021
Hook a Griffin PowerMate to a Raspberry Pi running HifiBerry!
View powermate.py
#!/usr/bin/env python3.8
"""
To enable this service, copy this file to /opt, then:
# chmod +x /opt/powermate.py
# pip3.8 install websockets
# cat > /etc/systemd/system/powermate.service
[Unit]
Description=PowerMate
@aaugustin
aaugustin / compression.py
Last active Dec 30, 2018
WebSocket compression benchmark
View compression.py
#!/usr/bin/env python
import getpass
import json
import pickle
import subprocess
import sys
import time
import zlib
@aaugustin
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
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
aaugustin / question.md
Last active Jun 24, 2021
Accessibility in browsers: zoom level vs. font size
View question.md

Scroll to the bottom for the answer

Question

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>
<html>
<head>
<title>Vega - bug 259</title>
<script src="http://vega.github.io/vega/lib/d3.v3.min.js"></script>
<script src="http://vega.github.io/vega/vega.min.js"></script>
</head>
<body>
<div id="chart"></div>
<script type="text/javascript">
View gameaboutsquares.py
#!/usr/bin/env python
# Copyright (c) 2014 Aymeric Augustin
# Released under the WTFPLv2 - http://www.wtfpl.net/txt/copying/
"""
Quick'n'dirty solver for http://gameaboutsquares.com/.
Install requests or save http://gameaboutsquares.com/game.c.js next to this
file. Then run: python gameaboutsquares.py. Tested with Python 2.7 and 3.4.
@aaugustin
aaugustin / djangoauth.py
Created Jul 29, 2014
WSGI middleware that authenticates against a Django user database.
View djangoauth.py
"""
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.
View kerberos.md

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.