Skip to content

Instantly share code, notes, and snippets.

View anthony-tresontani's full-sized avatar

anthony-tresontani anthony-tresontani

View GitHub Profile
@anthony-tresontani
anthony-tresontani / gist:5143673
Created March 12, 2013 15:07
deployment notification with changes (done originally for fabric)
def send_email():
content = "This is an automatic email to notify you a new release has been deployed for CDK\n\n"
content += "CHANGES:\n"
new_tag = local("git tag | sort -V | tail -1", capture=True)
prev_tag = local("git tag | sort -V | tail -2 | head -1", capture=True)
content += local('git log %s...%s --pretty=format:"%%h - %%an - %%s"' % (new_tag, prev_tag), capture=True)
msg = MIMEText(content)
msg['Subject'] = "Release %s version in %s" % (env.version, env.build)
msg['From'] = "CDK dev team"
msg['To'] = "ABC@tangentlabs.co.uk"
@anthony-tresontani
anthony-tresontani / gist:4426452
Created January 1, 2013 10:35
Sudoku genetic algorithm
from random import choice, shuffle
from pygene.gene import BaseGene
from pygene.organism import Organism, MendelOrganism
from pygene.population import Population
def flat_to_square(list_, size=9):
return [list_[i:i+size] for i in range(len(list_)/size)]
@anthony-tresontani
anthony-tresontani / multilingual_solr_backend
Created August 23, 2012 14:54
Provide an easy way to get a multingual search with haystack
# Full explaination here: http://anthony-tresontani.github.com/Django/2012/09/20/multilingual-search/
"""
Provide an easy way to get solr multilingual search with Haystack.
To use it, define an haystack connexion string by language.
HAYSTACK_CONNECTIONS = {
'default_en':{
'ENGINE': 'wdm.core.search.backend.MultilingualSolrEngine',
'URL': 'http://127.0.0.1:8080/solr-en',
},
@anthony-tresontani
anthony-tresontani / timeout_interrupt.py
Created July 5, 2012 12:44
Timeout decorator for testing
def timeout_interrupt(timeout):
def timeout_handler(signum, frame):
raise TimeoutException()
def wrap(fn):
@wraps(fn)
def wrapped(*args, **kwargs):
old_handler = signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(timeout)
try: