Skip to content

Instantly share code, notes, and snippets.

View raphaelm's full-sized avatar

Raphael Michel raphaelm

View GitHub Profile
@raphaelm
raphaelm / django-database-connection-pool-eventlet.py
Created December 20, 2022 13:18
Database connection pool when using eventlet
from django.core import signals
from django.db import connections
from django.db.utils import ConnectionHandler
from eventlet.pools import Pool
_unpatched_get_item = ConnectionHandler.__getitem__
class ConnectionPool(Pool):
def __init__(self, alias, max_size=4):
@raphaelm
raphaelm / wichteln.py
Last active November 6, 2022 15:36 — forked from P3nny/wichteln.py
Wichtel-Programm für die Familienweihnachtsfeier
# -*- coding: UTF-8 -*-
# Patricia Ennenbach - 15-12-21 - Wichteln
# Aufgaben:
# - Jedes Kind soll einem Kind etwas schenken
# - Kinder sollen sich nicht selbst beschenken
# - Kinder sollen nicht ihre Geschwister beschenken
# - Jedes Kind soll nur einmal beschenkt werden
# Ich habe den Hauptteil relativ stark verändert, aus zwei Gründen:
# * Du hast die Liste "kinder" bearbeitet, während du in einer Schleife
@raphaelm
raphaelm / decrypt.py
Created August 19, 2013 14:37
EasyMoney (Android expense tracker) backup files are obfuscated. This script decrypts them and stores the data in an SQLite3 file (just like it is stored on the Android device).
#!/usr/bin/env python3
import sys
import re
import sqlite3
import os.path
try:
INFILE = sys.argv[1]
OUTFILE = sys.argv[2]
except:
@raphaelm
raphaelm / storage.py
Created March 20, 2018 21:08
NanoCDN Storage driver
import hashlib
import urllib.parse
import os
from io import BytesIO, StringIO
import requests
from django.conf import settings
from django.core.exceptions import SuspiciousFileOperation
from django.core.files import File
@raphaelm
raphaelm / INSTRUCTIONS.md
Last active November 26, 2019 20:01
letsencrypt.sh ansible role

Step zero: Install this role by creating the directories roles/letsencrypt/, roles/letsencrypt/files/ and roles/letsencrypt/tasks/. Then save the tasks.yml from this gist as roles/letsencrypt/tasks/main.yml and config.sh from this gist as roles/letsencrypt/files/config.sh.

Step one: Add the following to your nginx server config

location /.well-known/acme-challenge {
    root /var/www/letsencrypt;
}

Step two: Execute the ansible role, e.g. using

# Debian lighttpd configuration file
#
############ Options you really have to take care of ####################
## modules to load
# mod_access, mod_accesslog and mod_alias are loaded by default
# all other module should only be loaded if neccesary
# - saves some time
# - saves memory
# History
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
zstyle :compinstall filename '/home/raphael/.zshrc'
# Load colors
autoload -U colors && colors
#!/usr/bin/env python
"""
From https://github.com/docker/docker/issues/6354#issuecomment-60817733
All credit goes to https://github.com/adamhadani
Check all existing Docker containers for their mapped paths, and then purge any
zombie directories in docker's volumes directory which don't correspond to an
existing container.
"""
@raphaelm
raphaelm / elements.py
Last active December 12, 2015 03:58
Checks whether it is possible to compose a given name out of chemical element symbols, like Caroline out of Carbon (C), Argon (Ar), Oxygen (O), Lithium (Li) and Neon (Ne).
#!/usr/bin/env python
#
# elements.py
#
# Checks whether it is possible to compose a given name out of chemical
# element symbols, like Caroline out of Carbon (C), Argon (Ar), Oxygen (O)
# Lithium (Li) and Neon (Ne).
#
# The implementation consists of a simple backtracking algorithm.
#
@raphaelm
raphaelm / my_i3status.bash
Created December 28, 2012 21:30
Thinkpad X230 mic mute button status displayed in i3status, because even though you can make the button function via an ACPI event, it is impossible to use the button's LED with kernel 3.5 Requires: jshon
#!/bin/bash
i3status | while :
do
read line
if [[ "$line" == *"full_text"* ]] ; then
if ! amixer sget 'Capture',0 | grep '\[on\]' > /dev/null 2>&1 ; then
if [[ "$line" == ","* ]]; then
echo -n ","
fi
echo $line | sed s/^,//g | jshon -n object -i 0 -e 0 -s "name" -i "micmute" -s "mic muted" -i "full_text" -p | tr '\n' ' '