Blog / Software Development

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: …

Django Tip: How to configure Gunicorn to auto-reload your code during development

March 30, 2014

I just finished fully automating my entire server stack for my Django app with Ansible and Vagrant (using VirtualBox). One of the reasons I did this is to make my development environment as close to production as possible to hopefully eliminate any surprises when deploying to production. It also allows me to setup a development environment very quickly as I won’t have to deal with manual installation and configuration of different packages. In a team …

Deploying your Django app with Fabric

January 25, 2014

I’ve been making quite a bit of improvements and changes to my Django app, GlucoseTracker, lately that the small amount of time I spent creating a deployment script using Fabric had already paid off.

Fabric is basically a library written in Python that lets you run commands on remote servers (works locally as well) via SSH. It’s very easy to use and can save you a lot of time. It eliminates the need to …

Writing Android apps in Python with the Kivy library

September 9, 2013

Being able to write Android apps in Python sounded very appealing to me so I decided to try out Kivy, a Python library that lets you do just that.

Kivy actually allows you to run your Python app not just on Android, but on other platforms as well such as IOS, Linux, Windows, and Mac OSX. So it’s also a good option for writing desktop applications. The project seems to be very active and …