Skip to content

Instantly share code, notes, and snippets.

View cstrap's full-sized avatar
🐍

Christian Strappazzon cstrap

🐍
View GitHub Profile
@cstrap
cstrap / localize
Created November 24, 2015 10:30
A way to generate localization files :: Python
# Creating Template
$ find . -iname "*.py" -exec xgettext -o messages.pot {} \;
# Copy template message.pot into locale/XX/LC_MESSAGES
# For example (this is a typical django app tree structure)
...
│   ├── locale
│   │   ├── en
│   │   │   └── LC_MESSAGES
│   │   │   ├── django.mo
@cstrap
cstrap / bobp-python.md
Created November 17, 2015 08:29 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@cstrap
cstrap / search.py
Created November 9, 2015 11:37 — forked from frague59/search.py
search features with attachment supports
# -*- coding: utf-8 -*-
"""
Search features for an elasticsearch / haystack / elasticstack
:creationdate: 05/11/15 15:05
:moduleauthor: François GUÉRIN <[email protected]>
:modulename: intrautils.search
"""
import base64
@cstrap
cstrap / introrx.md
Created October 16, 2015 16:09 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@cstrap
cstrap / django_haystack_testing.py
Last active September 14, 2018 13:07 — forked from justquick/django_haystack_testing
Django haystack testing index
import haystack
from django.core.management import call_command
from django.test.utils import override_settings
TEST_INDEX = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
@cstrap
cstrap / check_imports.py
Created July 2, 2015 14:15
Print order imports by rewriting builtin __import__ in order to see circular references. Put this on e.g. manage.py. From [email protected] S.Federici
import __builtin__
original_import = __builtin__.__import__
def log_import(name, globals={}, locals={}, fromlist=[], level=-1):
print name
return original_import(name, globals=globals, locals=locals, fromlist=fromlist, level=level)
__builtin__.__import__ = log_import
@cstrap
cstrap / backend.py
Created June 16, 2015 09:43
Extending Haystack Elasticsearch backend - multi_match query from http://www.stamkracht.com/extending-haystacks-elasticsearch-backend/
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.conf import settings
from haystack.backends.elasticsearch_backend import (
ElasticsearchSearchBackend, ElasticsearchSearchEngine, ElasticsearchSearchQuery)
from haystack.query import SearchQuerySet
"""
Script to identify accounts followed older than 4 months.
Source blogpost: http://www.rainbowbreeze.it/identify-your-twitter-followings-older-that-4-months
"""
import tweetpony
from datetime import timedelta, datetime
import urllib3.contrib.pyopenssl
import time
@cstrap
cstrap / memoize.py
Created April 30, 2015 07:54
Memoize with Python decorator
# -*- coding: utf-8 -*-
from functools import wraps
def memoize(obj):
"""
From Python Decorator Library
"""
cache = obj.cache = {}
class MyForm(forms.Form):
some_field = forms.CharField()
class MyWizard(SessionWizardView):
# ...do some stuff...
# And a url like:
url(r'^wizard/$', views.MyWizard.as_view([MyForm, MyOtherForm]))