Getting an iterable in batches

From http://code.activestate.com/recipes/303279-getting-items-in-batches/