Instantly share code, notes, and snippets.

View keybase.md

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:

View required_empty_label.html
<!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>
View middleware.py
# 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()
View trim_py_whitespace.sh
#!/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:]]*$//"
View fields.py
# 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)
View decrypt_cf_email.py
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)
View code128.py
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',
View gen_wifi_pwd_sfr_box.js
// -*- 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.
View mit.txt
The MIT License (MIT)
Copyright (c) 2013 Alexandre Syenchuk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
View logtemp.py
# coding: utf-8
import re
import subprocess
import time
LOG_FILE = '/var/log/temperature.csv'
res = subprocess.check_output(['sensors'])
res = re.findall(r':\s+\+(\d\d\.\d)°C', res)