Skip to content

Instantly share code, notes, and snippets.

@aaugustin
aaugustin / ca-download-helper.js
Created January 22, 2023 11:33
Automate downloading documents from www.credit-agricole.fr
// Pagination is done on the client-side. Remove it.
document.querySelectorAll('tr[id^="ligne"]').forEach(tr => { tr.style.removeProperty("display") });
// There is a 30s mandatory wait between each click. Click one link every 40s.
var delay = 10;
document.querySelectorAll('tr[id^="ligne"] a[href*="ouvreTelechargement"]').forEach(a => {
var tr = a.closest('tr');
if (tr.querySelector('.imgbam-picto-nouveau') !== null) {
setTimeout(() => {
tr.style.setProperty("background-color", "chartreuse");
@aaugustin
aaugustin / check_media_files.py
Created November 20, 2021 18:00
Locate and remove unreferenced media files.
#!/usr/bin/env python
"""
Locate and remove unreferenced media files.
Expects DJANGO_SETTINGS_MODULE to be set in the environment.
"""
import collections
@aaugustin
aaugustin / powermate.py
Last active January 25, 2022 14:59
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/powermate.py
# pip3.8 install websockets
# cat > /etc/systemd/system/powermate.service
[Unit]
Description=PowerMate
@aaugustin
aaugustin / compression.py
Last active December 30, 2018 20:18
WebSocket compression benchmark
#!/usr/bin/env python
import getpass
import json
import pickle
import subprocess
import sys
import time
import zlib
@aaugustin
aaugustin / dates.js
Created April 21, 2017 09:31
Date arithmetic in JavaScript
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 February 15, 2017 15:12
isValidDate in JavaScript
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 January 4, 2023 05:04
Accessibility in browsers: zoom level vs. font size

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

#!/usr/bin/env python3.4
"""Git pre-commit hook"""
import os
import subprocess
import sys
def run_linter(cmd, files):
<!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">
@aaugustin
aaugustin / gameaboutsquares.py
Last active November 4, 2015 05:02
Quick'n'dirty solver for http://gameaboutsquares.com/.
#!/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.