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 / 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 / convert_json_to_yaml.py
Last active July 23, 2023 16:08
Python script to load a JSON file and print its contents converted to YAML.
#!/usr/bin/env python3
"""Load a JSON file and print its contents converted to YAML.
Based on:
- https://stackoverflow.com/questions/15941996/dump-json-into-yaml/28506011#28506011
- https://gist.github.com/sbp/985889
"""
import json
import sys
@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 / connect-heroku-app-to-postgres-rds-with-ssl.md
Last active January 4, 2023 14:01 — forked from jonyt/connect_heroku_to_amazon_rds
How to connect a Heroku application to an Amazon RDS PostgreSQL instance, forcing SSL and certificate chain verification

1 - Download the RDS certificates (root plus region-specific intermediate ones) bundle:

wget -O config/rds-combined-ca-bundle.pem https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

2 - Add config/rds-combined-ca-bundle.pem to the repository and redeploy to Heroku.

3 - Update the DATABASE_URL env var:

@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 / 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 / generate_django_secret_key.py
Created October 22, 2015 15:44
Generate a 50-char random string, adequate for Django's `SECRET_KEY`
#!/usr/bin/env python
# coding: utf-8
"""Generate a 50-char random string, adequate for Django's ``SECRET_KEY``.
source: part of
https://github.com/django/django/blob/1.8.5/django/utils/crypto.py
"""
from __future__ import absolute_import, print_function, unicode_literals
@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 / requirements.txt
Last active April 10, 2020 17:00
pip - install from GitHub repo
# For commits, prefer full hash
# https://pip.pypa.io/en/stable/reference/pip_install/#git
-e git+ssh://git@github.com/fyntex/lib-cl-sii-python.git@995af20f289c41c690d47c35720a6005b93287ba#egg=cl-sii
-e git+ssh://git@github.com/fyntex/lib-cl-sii-python.git@master#egg=cl-sii
-e git+ssh://git@github.com/fyntex/lib-cl-sii-python.git@v1.5#egg=cl-sii
-e git+ssh://git@github.com/fyntex/lib-cl-sii-python.git@refs/pull/123/head#egg=cl-sii