I hereby claim:
- I am piotch on github.
- I am piotch (https://keybase.io/piotch) on keybase.
- I have a public key whose fingerprint is 74D3 18AA 5E06 5306 5E63 E73D 3E33 D27A C49F 1CD2
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
a=`gsort -R /usr/share/dict/words | head -n1` | |
s="London is a $a machine." | |
echo | |
echo $s | |
echo | |
echo "Happy with this one ? [yn]" | |
read yn | |
case $yn in | |
y ) | |
t update "$s" ;; |
from requests.auth import AuthBase | |
class DRFTokenAuth(AuthBase): | |
""" | |
Attaches Django Rest Framework token auth header to the given Request object. | |
http://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication | |
http://docs.python-requests.org/en/latest/user/authentication/#new-forms-of-authentication | |
""" | |
def __init__(self, api_key): | |
self.api_key = api_key |
from importlib import import_module | |
_module = lambda x: x[:x.rfind('.')] | |
_cls = lambda x: x[x.rfind('.')+1:] | |
s = 'some.module.class' | |
getattr(import_module(_module(s)), _cls(s)) |
class Singleton(type): | |
_instances = {} | |
def __call__(cls, *args, **kwargs): | |
if cls not in cls._instances: | |
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
return cls._instances[cls] | |
class Blah(object): | |
__metaclass__ = Singleton |
SELECT | |
COLUMN_NAME, | |
TABLE_NAME, | |
CHARACTER_SET_NAME, | |
COLUMN_TYPE, | |
COLLATION_NAME | |
FROM information_schema.COLUMNS | |
WHERE TABLE_SCHEMA = 'your_database_name' |
from django.db.models import get_app, get_models | |
from django.conf import settings | |
from south.db import db | |
from south.v2 import SchemaMigration | |
class Migration(SchemaMigration): | |
""" | |
This is a generic migration to convert tables and column from latin-1 to utf-8 | |
To use it create an empty migration: |
python manage.py schemamigration app_name convert_utf8 --empty | |
# ici éditer le contenu de la nouvelle migration pour avoir les méthodes backward et forward de la migration générique | |
python manage.py dumpdata app_name --indent=4 > before.json | |
python manage.py migrate XXXX_convert_utf8 # remplacer XXXX par le numéro de la migration | |
python manage.py dumpdata app_name --indent=4 > after.json |
from django.utils import six # Python 3 compatibility | |
from django.utils.functional import lazy | |
from django.utils.safestring import mark_safe | |
from django.utils.translation import ugettext_lazy as _ | |
mark_safe_lazy = lazy(mark_safe, six.text_type) |
svn log | perl -l40pe 's/^-+/\n/' | head |