Skip to content

Instantly share code, notes, and snippets.

View alexpirine's full-sized avatar
🍄

Alexandre Syenchuk alexpirine

🍄
View GitHub Profile
class ActivationCode: # facultatif
pass
class ActivationCodeGeneratorInterface:
def generate(self, key: str, counter: int, duration_days: int) -> ActivationCode:
raise NotImplementedError
class RESTAPI:
from datetime import datetime
from datetime import timezone
current_date = datetime.now(timezone.utc)

Keybase proof

I hereby claim:

  • I am alexpirine on github.
  • I am alexpirine (https://keybase.io/alexpirine) on keybase.
  • I have a public key ASBQjyxrhPzjtpNjBsz9ROY4ZXzWcdMee3zn57gJ4rYYhAo

To claim this, I am signing this object:

@alexpirine
alexpirine / required_empty_label.html
Created October 20, 2016 19:24
Django's ModelChoiceField with empty_label generates an invalid <select>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<select id="id_some_field" name="some_field" required>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
@alexpirine
alexpirine / middleware.py
Created September 4, 2016 05:22
Django (1.10-compatible) thread local (TLS) middleware
# coding: utf-8
# Copyright (c) Alexandre Syenchuk (alexpirine), 2016
try:
from threading import local
except ImportError:
from django.utils._threading_local import local
_thread_locals = local()
@alexpirine
alexpirine / trim_py_whitespace.sh
Created April 1, 2016 14:33
Trim whitespace in all python files
#!/bin/bash
find . -not \( -name .svn -prune -o -name .hg -prune -o -name .git -prune \) -type f -name '*.py' -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
@alexpirine
alexpirine / fields.py
Last active November 12, 2018 19:59
Automatically round Django's DecimalField according to the max_digits and decimal_places attributes
# coding: utf-8
# Copyright (c) Alexandre Syenchuk (alexpirine), 2016
import decimal
from django.db import models
class RoundedDecimalField(models.DecimalField):
"""
Usage: my_field = RoundedDecimalField("my field", max_digits = 6, decimal_places = 2)
@alexpirine
alexpirine / decrypt_cf_email.py
Last active February 9, 2016 15:27
Decrypts a cloudflare-encrypted e-mail
def decrypt_cf_email(email):
# a small python function that decrypts a cloudflare-encrypted e-mail
email_key = int(email[:2], 16)
email_chars = [chr(int(email[k:k+2], 16) ^ email_key) for k in range(2, len(email), 2)]
return ''.join(email_chars)
@alexpirine
alexpirine / code128.py
Last active December 28, 2015 09:19
Produces SVG containing a Code 128 barcode
modes = {
'A': (
' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '\x00', '\x01', '\x02',
'\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B',
'\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14',
'\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
// -*- coding: utf-8; tab-width: 2; indent-tabs-mode: nil; -*-
//
// Generates Wi-Fi passwords generated in the web interface of the “La box de
// SFR” home router.
//
// In many browsers, this implementation is broken because of a very short
// period of the pseudo-random Math.random() funciton, usually around 2^30.
//
// You can generate a passwords file of several gigabytes and run a
// successfull bruteforce attack in a couple of hours against A WPA key.