Blog

A Python function for flattening irregular list of lists

July 20, 2014

Here’s a nice short function for flattening irregular lists in Python that I found on Stackoverflow a few weeks back. It returns a generator so should work fine for very big lists.

def flatten_list(object_list):
    """
    Flattens a list of objects.
    """
    for element in object_list:
        if isinstance(element, collections.Iterable) and not \
                isinstance(element, basestring):
            for sublist in flatten_list(element):
                yield sublist
        else:
            yield element

I tested it with lists like the following and it did the job: …

Ansible Playbook for a Django Stack (Nginx, Gunicorn, PostgreSQL, Memcached, Virtualenv, Supervisor)

April 20, 2014

I decided to create a separate GitHub project for the Ansible playbook I'm currently using to fully provision a production server for my open-source app, GlucoseTracker, so it can be reused by people who are using the same stack.

You can download the playbook here: https://github.com/jcalazan/ansible-django-stack

The playbook can fully provision an Ubuntu 12.04 LTS server (will test 14.04 soon) from the base image with the following applications, which are quite popular in the …

How to configure Nginx so you can quickly put your website into maintenance mode

April 6, 2014

I had to rebuild my Rackspace VPS last night where my Django app runs as I wanted to downgrade it because it was underutilized. Since I was already at the lowest tier for that category of servers, there's no option to resize it down, I would need to spin up a new server from a different server category.

Thanks to Ansible, though, provisioning a new server with all the applications and configurations I needed …

How to deploy encrypted copies of your SSL keys and other files with Ansible and OpenSSL

April 5, 2014

I've been working on fully automating server provisioning and deployment of my Django app, GlucoseTracker, the last couple of weeks with Ansible. Since I made this project open-source, I needed to make sure that passwords, secret keys, and other sensitive information are encrypted when I push my code to my repository.

Of course, I have the option to not commit them to the repo, but I want to be able to build …