Skip to content

Instantly share code, notes, and snippets.

View glarrain's full-sized avatar
🤘
rockin'

Germán Larraín glarrain

🤘
rockin'
View GitHub Profile
@glarrain
glarrain / sessionstorage.py
Created July 10, 2012 00:51
Custom Django SessionStorage. Removed all the functionality that dealt with files. Based on Django-1.4's django.contrib.formtools.wizard.storage.base.BaseStorage django.contrib.formtools.wizard.storage.session.SessionStorage.
from django.utils.datastructures import MultiValueDict
class SessionStorage(object):
"""Custom SessionStorage class. Removed all the functionality that dealt
with files.
Based in Django-1.4's:
`django.contrib.formtools.wizard.storage.base.BaseStorage`
`django.contrib.formtools.wizard.storage.session.SessionStorage`
@glarrain
glarrain / views.py
Created July 12, 2012 15:19
Multi-page form manager, arranged as a (math) graph, with dynamic paths (next form depends on actual state and user input) and number of forms. Storage and validation are handled. Based in Django-1.4's `django.contrib.formtools.wizard.views.SessionWizard`
import copy
import logging
import re
from django.forms import ValidationError
from django.views.generic import TemplateView
from django.utils.datastructures import MultiValueDict
from django.contrib.formtools.wizard.forms import ManagementForm
@glarrain
glarrain / are-domains-up.sh
Created October 17, 2012 12:42
Test whether each of the domains in the list is up or not
#!/usr/bin/env sh
# Uses curl to connect to www.isup.me, a website that checks if a given domain
# is up or not. The response will contain "It's just you" if the domain is up.
# If not, it will contain "It's not just you".
test $# -lt 1 && (echo "Usage: $0 domain [domain2] [domain3] ..."; exit 1;)
for domain in "$@"; do
echo -n "$domain: "
@glarrain
glarrain / tweets.py
Created October 17, 2012 12:54
Retrieve a user's last tweets
from urllib2 import urlopen
from django.utils.simplejson import loads
from oauth2 import Token
from social_auth.backends.utils import build_consumer_oauth_request
from social_auth.backends.twitter import TwitterAuth
@glarrain
glarrain / gist:3982485
Created October 30, 2012 19:37
Decode session data, no matter what hashes say. It helps in some cases where the Session.get_decoded method returns an empty dictionary because it is "suspicious" of user-data tampering. Based on source code from the Django project.
import base64
import pickle
from django.contrib.sessions.models import Session
from django.utils.encoding import force_unicode
def decode_session_data(session_key):
"""Decode the data in a session object stored under ``session_key``.
@glarrain
glarrain / MySQL-Chile:regiones-provincias-comunas
Created November 16, 2012 19:49 — forked from juque/MySQL-Chile:regiones-provincias-comunas
Chile: Regiones, Provincias, Comunas
/* Estructura y Datos de las Regiones, Provincias */
/* y Comunas de Chile. */
/* */
/* Fecha: Julio 2010 */
/* Autor: Juan Pablo Aqueveque - juque.cl */
--
-- Comunas
--
DROP TABLE IF EXISTS `comunas`;
@glarrain
glarrain / comunas por region.json
Last active November 25, 2019 18:17
Administrative divisions of Chile: Comunas, Provincias, Regiones
{
"Región de los Ríos": [
"Panguipulli",
"Corral",
"Paillaco",
"La Unión",
"Los Lagos",
"Río Bueno",
"Futrono",
"Lago Ranco",
@glarrain
glarrain / dump division_chile.json
Created November 19, 2012 22:54
Division politica del territorio de Chile, en formato JSON para modelos creados en Django
[
{
"pk": 6,
"model": "lu_base.region",
"fields": {
"codigo": "15",
"orden_geo": 1,
"nombre_corto": "Arica y Parinacota",
"nombre_largo": ""
}
sudo apt-get install build-essential libsqlite3-dev zlib1g-dev libncurses5-dev libgdbm-dev libbz2-dev libreadline5-dev libssl-dev
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar xz Python-2.7.3.tgz
cd Python-2.7.3
./configure
make
sudo make altinstall
python2.7
@glarrain
glarrain / test_connection.py
Created December 19, 2012 21:38
Remote Redis server
import redis
redis_host = 'ec2-xxx.amazonaws.com'
value = raw_input()
r = redis.StrictRedis(host=redis_host, password=value)
r.set('foo', 'hellooo')
r.get('foo')