Skip to content

Instantly share code, notes, and snippets.

View martinsam's full-sized avatar
🎯
Focusing

Samuel Martin martinsam

🎯
Focusing
View GitHub Profile
@martinsam
martinsam / gist:5525185
Last active December 17, 2015 00:59
pre-commit - Check po
if check_po /home/sam/opquast/pdn/locale/fr/LC_MESSAGES/django.po | grep 'FUZZY'; then
echo "\033[44m----------------------------------------------------\033[0m"
echo "\033[31m FUZZY présent dans locale/fr/LC_MESSAGES/django.po\033[0m"
exit 1
else
echo -n "\033[32m"
check_po /home/sam/opquast/pdn/locale/fr/LC_MESSAGES/django.po
echo -n "\033[0m"
fi
@martinsam
martinsam / Git: Prev - Next
Created January 29, 2013 22:44
Git: Prev - Next
dans ~/.gitconfig
[alias]
prev = checkout HEAD^1
next = "!sh -c 'git log --reverse --pretty=%H master | awk \"/$(git rev-parse HEAD)/{getline;print}\" | xargs git checkout'"
Permet :
git next
git prev
Mettez le code suivant du le fichier .git/hooks/post-merge de votre repo en local :
#!/bin/bash
# On met ici tous les fichiers (ou pattern de nom) qu'on veut surveiller
# changez les pour les adapter à votre projet
files=('settings.py' 'migrations');
# on récupère tous les noms de fichiers modifiés depuis le dernier merge
modified_files=`git diff "HEAD@{1}" --name-only`
@martinsam
martinsam / pdftk
Created December 11, 2012 14:13
Unix: Get/Set pdf metadata
# GET DATA
pdftk example.pdf dump_data
pdftk example.pdf dump_data output info.txt
# SET DATA
pdftk example.pdf update_info info.txt output example.pdf
@martinsam
martinsam / crypt.py
Created December 11, 2012 10:17
Python: Crypt base36
import struct
from Crypto.Cipher import DES
def base36encode(number):
"""Encode number to string of alphanumeric characters (0 to z). (Code taken from Wikipedia)."""
if not isinstance(number, (int, long)):
raise TypeError('number must be an integer')
if number < 0:
raise ValueError('number must be positive')
@martinsam
martinsam / gist:1314699
Created October 25, 2011 23:11
Rapporter un bug : Les bonnes pratiques
* Mentionner l'url
* Décrire précisemment la procédure
* Identifier le couple OS / UA (plateforme : Exemple Windows 7 IE 8)
* Définir un vocabulaire commun
* Définir la gravité du bug
* Rédiger dans un français correct votre rapport
* Relisez vous
* Vérifier si le bug est reproductible
@martinsam
martinsam / gist:1228995
Created September 20, 2011 12:43
Unix: Vider le swap
#attention vérfier que swap < mémoire vive restante
sudo swapoff -a && swapon -a
@martinsam
martinsam / gist:1204819
Created September 8, 2011 21:33
Chargement constante - template tag
from pdn import constants
@register.simple_tag
def get_constant(constant, value, constant_type="CHOICES_DICT"):
try:
return getattr(getattr(constants, constant), constant_type)[int(value)]
except AttributeError:
return "NC"
@martinsam
martinsam / gist:1122814
Created August 3, 2011 14:51
Email parsing
from email import message_from_string
email = message_from_string(data)
for part in email.walk():
if type_email == "multipart/alternative":
if part.get_content_type() == "text/html":
body = part.get_payload(decode=True)
else:
if part.get_content_type() == "text/plain":
body = part.get_payload(decode=True)
@martinsam
martinsam / gist:1050173
Created June 28, 2011 00:07
Import OPML
from pyquery import PyQuery as pq
from lxml import etree
from django.template.defaultfilters import slugify
my_file = open('/home/sam/feedlist.opml', 'r')
data = my_file.read()
opml = pq(data)
outlines = opml("body > outline")