Blog / Howto

Docker Cleanup Commands

October 4, 2014

I've been working quite a bit with Docker these last few weeks and one thing that I found really annoying was all these unused containers and images taking up precious disk space.

I wish Docker has a 'docker clean' command that would delete stopped containers and untagged images. Perhaps sometime in the near future as the project is very active. But for the time being, these commands should do the job.

Kill all running containers …

How to delete Python .pyc and .pyo files on Ubuntu 14.04

September 2, 2014

I just realized today that Ubuntu has a command called pyclean already installed by default that will recursively delete all .pyc and .pyo files.

For example, to recursively delete .pyc and .pyo files from the current working directory, you can do:

pyclean .

If you’re not on Ubuntu, you can run this command instead:

find . -name “*.pyc” -delete

Source

How to make images responsive by default in Twitter Bootstrap 3

July 23, 2014

I'm currently working on a simple blog app in Django and noticed that my images are not getting resized by default when using Bootstrap 3.

To change this behavior, simply change the img tag in bootstrap.css to this:

img {
  display: inline-block;
  height: auto !important;
  max-width: 100%;
  border: 0;
}

Source

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