Search This Blog

12 October 2015

Output a log message every x% of a long computation
import logging

logging.basicConfig(level=logging.INFO)


def time_to_log(data, percent=10):
    percent = percent if percent > 1 else percent * 100
    data_size = len(data)
    log_every = data_size * percent / 100
    return float(data_size), lambda i: not i % log_every


data = range(100)
data_size, is_time_to_log = time_to_log(data, 0.2)

for i, d in enumerate(data):
    if is_time_to_log(i):
        logging.info("processing... {:.2%}".format(i / data_size))
    pass  # do whatever is needed
logging.info("processing... 100.00%")

10 October 2015

another reader's digest

https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSWDdsxk6ho-2FMay5rVbvceNMNg55I6KZazOsPlvbG2-hmbEv2Og
The borg pattern


http://images.fineartamerica.com/images-medium-large/2-neural-network-pasieka.jpg
Neural network, 11 LOC

http://farm2.static.flickr.com/1303/1368498596_b9abff25bb.jpg
Best practices
to manage a Python code library


http://www.funbrain.com/guess/magic.gif
0x5f3759df
Another magic number

comprendo comprehension ?

 Youtube File System
 

http://static5.businessinsider.com/image/4e7f557369beddb21d00003b-480/crystal-ball-fortune-teller.jpg
A peek in the future

Print
>>> print

>>> from __future__ import print_function
>>> print
<built-in function print>

division
>>> 3/2
1
>>> from __future__ import division
>>> 3/2
1.5

Hold your brace
>>> from __future__ import braces
SyntaxError: not a chance (<input>, line 1)