Skip to content

Instantly share code, notes, and snippets.

@pedroburon
pedroburon / election_update_data.html
Created January 4, 2012 14:14
election_update_data.html
{% extends 'elections/base_edits.html' %}
{% load i18n %}
{% block content %}
<div class="fondo_formulario">
<div class="numero_off uno">1.</div>
<div class="numero_off dos">
<a href="{% url candidate_create election_slug=election.slug %}">2.</a>
</div>
@pedroburon
pedroburon / form_bootstrap.html
Created January 24, 2012 14:59
bootstrap compatible template for forms in django
{% load i18n %}
<form method="post"
{% if action_url %}action="{{ action_url }}"{%endif %}
{% if form.is_multipart %}enctype="multipart/form-data"{% endif %}>
{% csrf_token %}
<fieldset>
{% if form_legend %}
<legend>{% trans form_legend noop %}</legend>
{% endif %}{# form_legend #}
@pedroburon
pedroburon / gist:1870274
Created February 20, 2012 17:47
scrapping correos de chile
>>> import urllib2
>>> from BeautifulSoup import BeautifulSoup
>>> DATA_STRING = 'origen=p&szEstConsulta=OK&calle=%(street)s&numero=%(number)s&comuna=%(commune)s'
>>> URL_STRING = 'http://codigopostal.correos.cl/correos_cp/soporte_web/consulta_web/versionphp2006/' \
... 'pagina_interior/codigo_postal/Correos_codigoPostal_NEW/pgn_modulo_codigopostal.asp'
>>> params = {'number': '229', 'commune': 'providencia', 'street': 'providencia'} # Urban Station
>>> data = (DATA_STRING % params).replace(' ', '+')
>>> page = urllib2.urlopen(URL_STRING, data)
>>> soup = BeautifulSoup(page)
@pedroburon
pedroburon / gist:1970087
Created March 4, 2012 02:18 — forked from alfredo/gist:1542184
Install node.js and coffee-script inside a python virtualenv
To install node.js and coffee-script inside a virtualenv and keep it self-contained:
1. Activate the virtualenv::
$ workon test
2. Move inside the virtualenv directory::
(test)$ cdvirtualenv
@pedroburon
pedroburon / login_context_processor.py
Created May 8, 2012 15:59
login context processor for django
def login_forms(request):
if not request.user.is_authenticated():
return {
'registration_form': RegistrationForm(),
'authentication_form': AuthenticationForm(),
}
return {}
@pedroburon
pedroburon / profile_picture_django_social_auth.py
Created June 26, 2012 21:53 — forked from kouroshshafi/profile_picture_django_social_auth
Extending User class to save profile picture in django-social-auth when registering
# This is models.py for a new user profile that you would like to create.
"""
this gist gets an id from django-social-auth and based on that saves the photo from social networks into your model. This is one of the best ways to extend User model because this way, you don't need to redefine a CustomUser as explained in the doc for django-social-auth. this is a new implementation based on https://gist.github.com/1248728
"""
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models
@pedroburon
pedroburon / decorators.py
Created January 15, 2013 18:45
apikey authorization decorator
import logging
from django import http
from apikey.models import ApiKey
def apikey_authorization(view):
def new_view(request, *args, **kwargs):
key_pair = request.META.get('HTTP_X_API')
function get_short_commit {
git log -n 1 --format=oneline --abbrev-commit 2> /dev/null | sed -e 's/\([0-9a-f]*\)\(.*\)/\1/'
}
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1 $(get_short_commit)]$(parse_git_dirty)/"
}
@pedroburon
pedroburon / post_compile
Created March 15, 2013 16:15
Post compile hook for django heroku projects
#!/usr/bin/env bash
set -eo pipefail
# The post_compile hook is run by heroku-buildpack-python
echo "-----> I'm post-compile hook"
# Work around Heroku bug whereby pylibmc isn't available during
# compile phase. See: https://github.com/heroku/heroku-buildpack-python/issues/57
export MEMCACHE_SERVERS='' MEMCACHIER_SERVERS=''
@pedroburon
pedroburon / greenrunserver.py
Created November 13, 2014 19:32
greenrunserver.py
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
server_address = (addr, port)
from gevent.wsgi import WSGIServer
WSGIServer(server_address, wsgi_handler).serve_forever()
def patch_runserver(run=run):
from django.core.servers import basehttp
basehttp.run = run