Skip to content

Instantly share code, notes, and snippets.


Aloïs Guillopé Atala

View GitHub Profile
Atala /
Created Dec 1, 2014
Django TEST_MIRROR issue
#! debug
ipdb> connections['default'].cursor().db.connection
<connection object at 0x10646d180; dsn: 'dbname=test_master', closed: 0>
ipdb> connections['prestashop'].cursor().db.connection
<connection object at 0x10670d3e0; dsn: 'dbname=test_master', closed: 0>
#! settings
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Atala / gevent.unpatch
Last active Aug 29, 2015
Proposal for switching threading module
View gevent.unpatch
import sys
# keep original thread module for later use
original_thread_module = sys.modules.pop('threading', None)
import gevent.monkey
Atala / Unzip file
Created Oct 16, 2014
Unzip a file in python - note that extractall() is sensible to traversal attacks
View Unzip file
import zipfile,os.path
def unzip(source_filename, dest_dir):
with zipfile.ZipFile(source_filename) as zf:
for member in zf.infolist():
# Path traversal defense copied from
words = member.filename.split('/')
path = dest_dir
for word in words[:-1]:
drive, word = os.path.splitdrive(word)
Atala / postdeactivate
Created Sep 30, 2014
Postdeactivate hook for virtulenvwrapper
View postdeactivate
# This hook is sourced after every virtualenv is deactivated.
# remove virtualenv
Atala / postactivate
Last active Aug 29, 2015
Snippet for postactivate hook
View postactivate
# This hook is sourced after every virtualenv is activated.
proj_name=$(basename $VIRTUAL_ENV)
cd ~/src/$proj_name
# show virtualenv
RPROMPT="%{${fg_bold[white]}%}(env: %{${fg[green]}%}`basename \"$VIRTUAL_ENV\"`%{${fg_bold[white]}%})%{${reset_color}%} $RPROMPT"
Atala / postmkvirtualenv
Created Sep 25, 2014
Snippet for postmkvirtualenv hook
View postmkvirtualenv
# This hook is sourced after a new virtualenv is activated.
proj_name=$(basename $VIRTUAL_ENV)
mkdir $HOME/src/$proj_name
add2virtualenv $HOME/src/$proj_name
cd $HOME/src/$proj_name
Atala / Euler 11
Created Dec 17, 2013
This is my solution to the projecteuler 11th problem
View Euler 11
from sys import stdin
def up(x, y, f):
return reduce(lambda u,v: int(u)*int(v), f[x][y:y+4])
except IndexError:
return 0
def down(x, y, f):