Skip to content

Instantly share code, notes, and snippets.

View mlorant's full-sized avatar

Maxime Lorant mlorant

  • Orfeo
  • Bretagne, France
View GitHub Profile
@mlorant
mlorant / region-dpts-France.py
Created December 20, 2016 15:24
Liste des régions et départements français (dict. Python)
REGIONS = {
'Auvergne-Rhône-Alpes': ['01', '03', '07', '15', '26', '38', '42', '43', '63', '69', '73', '74'],
'Bourgogne-Franche-Comté': ['21', '25', '39', '58', '70', '71', '89', '90'],
'Bretagne': ['35', '22', '56', '29'],
'Centre-Val de Loire': ['18', '28', '36', '37', '41', '45'],
'Corse': ['2A', '2B'],
'Grand Est': ['08', '10', '51', '52', '54', '55', '57', '67', '68', '88'],
'Guadeloupe': ['971'],
'Guyane': ['973'],
'Hauts-de-France': ['02', '59', '60', '62', '80'],
@mlorant
mlorant / git-pre-commit-hook-django
Created March 26, 2015 09:17
Django - Avoid duplicate in migration names before committing changes in Git
#!/usr/bin/python
"""
Pre-commit hook for git written in Python.
Check if there is any migration number used more than one in each
migrations folder of South or Django >= 1.7.
You can install this pre-hook by executing the command:
ln -s ./git-pre-commit-hook .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
@mlorant
mlorant / twitter_timeline.py
Last active December 18, 2015 12:48
Access to your own twitter timeline, with the Twitter API 1.1
import re
import oauth2 as oauth
from dateutil.parser import parse
from json import loads
CONSUMER_KEY = "***************"
CONSUMER_SECRET = "***************"
ACCESS_TOKEN = "***************"
ACCESS_TOKEN_SECRET = "***************"
@mlorant
mlorant / hash.php
Created May 18, 2013 16:10
Advanced method to hash password
<?php
define('SALT_LENGTH', 6);
define('ITERATIONS', 10000);
/** Génère le hash complet d'un mot de passe donné en clair */
function create_hash($password) {
$salt = get_rand_salt();
$hash = get_hash($password, $salt, ITERATIONS);
return ITERATIONS."$".$salt."$".$hash;
@mlorant
mlorant / get_thumbnail.py
Last active December 15, 2015 15:19
Just a little function to get thumbnail of video on Youtube or Dailymotion, based on the watch URL. Works with every youtube links, thanks to a great regex, found on stackoverflow, again. Useful when you want to do video list, without displaying every video embed on the same page.
import re
# List of format available on Youtube
YOUTUBE_CHOICES = ("default", "hqdefault", "0", "1", "2")
# Default image if no thumbnail is found
NO_PREVIEW = "/static/img/no_preview.png"
def get_video_thumbnail(url, version="hqdefault"):