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 / pyrographics.py
Created October 10, 2013 13:42
Single-module 2D graphics Python library, plaform-independent with no dependencies! (only tkinter)
# source: https://svn.cs.brynmawr.edu/pyrobot/trunk/pyrographics.py
# grabbed in 2013.10.10 by German Larrain
#
# I modified it a bit to be able to run and import this module by itself
# (i.e. with no dependencies towards "pyrobot").
# --- pyrographics.py.0 2013-10-10 10:37:03.784159860 -0300
# +++ pyrographics.py.1 2013-10-10 10:37:44.564362077 -0300
# @@ -126,14 +126,9 @@
@glarrain
glarrain / supervisor
Created August 6, 2013 16:14
logrotate.d/supervisor: config file for logrotate for Supervisor logs (includes explanation of each directive)
/var/log/supervisor/*.log {
weekly
rotate 52
compress
delaycompress
notifempty
missingok
copytruncate
}
@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 / download_and_pickle_stories.py
Last active February 20, 2024 08:27
Exporting data from Pivotal Tracker is a pain in the ass. The following scripts let you download all the stories of a given project, and then (optionally) extract all the attachments linked to those, and download them
"""Download stories of a Pivotal Tracker project.
You need the project ID (an int) and your API token. The latter can be
obtained in ``https://www.pivotaltracker.com/profile``, or using curl::
$ curl -u username:password -X GET https://www.pivotaltracker.com/services/v3/tokens/active
"""
import getpass
import pickle
@glarrain
glarrain / model_mixins.py
Created April 23, 2013 23:18
Django model mixin to force Django to validate (i.e. call `full_clean`) before `save`
class ValidateModelMixin(object):
"""Make :meth:`save` call :meth:`full_clean`.
.. warning:
This should be the left-most mixin/super-class of a model.
Do you think Django models ``save`` method will validate all fields
(i.e. call ``full_clean``) before saving or any time at all? Wrong!
@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
@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": ""
}