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 / 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 / admin__base.html
Created July 11, 2013 22:08
Django custom admin site. App name `custom_admin`
{% load admin_static %}{% load url from future %}<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
{% comment %}
This template is almost a copy (with indentation corrections and modifications listed below) of
'django/contrib/admin/templates/admin/base.html' and overrides it by living in directory
'/templates/admin/', as instructed in documentation:
"For those templates that cannot be overridden in this way, you may still override them for
your entire project. Just place the new version in your templates/admin directory."
https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#overriding-admin-templates
@glarrain
glarrain / create-ec2-key-and-generate-pem-file.sh
Last active October 4, 2017 21:32
Create EC2 key pair and "generate" PEM file
#!/usr/bin/env bash
# Tools:
# - aws-cli version 1.11.143
# - jp version 0.1.3
# https://github.com/jmespath/jp
# Notes:
# - 'sed' pattern
# https://stackoverflow.com/questions/13610639/tr-command-how-to-replace-the-string-n-with-an-actual-newline-n/13611446#13611446
@glarrain
glarrain / create-gif-from-images.sh
Created March 2, 2017 17:59
Create GIF using images
# Ubuntu 14.04: requires pkg 'imagemagick'.
convert -resize 50% -delay 100 -loop 0 *.png myimage.gif
@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 / simplest_wsgi_server.py
Created December 21, 2015 21:14
simplest HTTP (using WSGI) server ever
#!/usr/bin/env python3
from datetime import datetime
from wsgiref.simple_server import make_server
def my_application(environ, start_response):
path = environ['PATH_INFO']
method = environ['REQUEST_METHOD']
print("received a HTTP request. path: %s, method: %s" % (path, method))
@glarrain
glarrain / htpasswd.py
Last active December 14, 2015 12:58
Script to replace htpasswd, a program to manipulate basic authentication files, included in package (debian) apache2-utils
#!/usr/bin/env python
"""Replacement for htpasswd.
Original author: Eli Carter
source (rev 6551):
http://trac.edgewall.org/browser/trunk/contrib/htpasswd.py
"""
import os
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/python");</script>
@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')
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