Skip to content

Instantly share code, notes, and snippets.

@aaugustin
aaugustin / gist:2351479
Created April 10, 2012 13:44
Django: log all database queries in the console
import logging
logger = logging.getLogger('django.db.backends')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
@aaugustin
aaugustin / kerberos.md
Last active April 10, 2023 01:06
Kerberos

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.

@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 / 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

@aaugustin
aaugustin / convert_to_utc.py
Created June 22, 2012 08:52
Convert datetimes in the database when switching USE_TZ from False to True.
"""Convert datetimes in the database when switching USE_TZ from False to True.
tl;dr RUNNING THIS SCRIPT CAN RESULT IN DATA CORRUPTION, DATA LOSS AND EVEN
SERVER CRASHES. USE IT AT YOUR OWN RISK. NO WARRANTY WHATSOEVER.
This is a management command. Put it in the management.commands package of
one of your applications, then run: ./manage.py convert_to_utc <app_name> ...
This script assumes that no write operations take place while it's running.
It will rewrite every single record in your database; that's its whole point.
@aaugustin
aaugustin / admin.py
Last active August 7, 2022 19:39
Read-only ModelAdmin for Django
from django.contrib import admin
class ReadOnlyModelAdmin(admin.ModelAdmin):
"""
ModelAdmin class that prevents modifications through the admin.
The changelist and the detail view work, but a 403 is returned
if one actually tries to edit an object.
@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 / 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 / HOWTO.md
Last active December 3, 2019 20:18
Connecting a Django application to a Microsoft SQL Server database from Debian GNU/Linux
  1. Install and register the FreeTDS driver for unixODBC.

     apt-get install tdsodbc
     odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini
    
  2. (Optional) Test the DSN-less connection with pyodbc.

     apt-get install python-pyodbc
    

>>> import pyodbc

@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