Chasing a dot on a HTML5 canvas

A forum question about how to detect a collision of two balls for a school project (in Python) lead me to write my first HTML5 <canvas> element code.

Move the mouse over the square below and try to catch the blue dot with the red one.

Sorry, this needs a browser with <canvas> support.

Read more...

More Than Just ASCII Digits

Python’s int() converts more than just ASCII digits. It also converts decimal digits from other scripts.

>>> int('42')
42
>>> int(u'୨୩')
23

It’s also possible to mix differnt scripts. int() only cares about the decimal value of each digit character.

>>> int(u'௧౩౩೭')
1337

The following snippet creates CSV data for all digits int() can convert:

#!/usr/bin/env python
# coding: utf8
from __future__ import absolute_import, division, print_function
import sys
import unicodedata


def main():
    for i in xrange(sys.maxunicode + 1):
        try:
            character = unichr(i)
            value = int(character)
        except ValueError:
            pass
        else:
            print(
                u'{0},{1},{2:x},{3}'.format(
                    character, value, i, unicodedata.name(character).lower()
                ).encode('utf8')
            )


if __name__ == '__main__':
    main()

And here’s the table generated by that script:

Read more...

summer.py version 0.0.2

A software I use from time to time but a source code I haven’t touched for almost ten years, except for changing some small things when moving from a private Subversion repository to a public Mercurial one hosted at Bitbucket.

There is no new functionality, just updated the code which was written with ancient Python 2.3 in mind. Some modules where deprecated (md5 and sha1), command line handling is now done with argparse, and the Checksums class was replaced by a function because a class with just __init__() and one other method usually isn’t a real class but just a function in disguise. Quite a poor design choice I’ve made ten years ago. :-)

The doc target is gone from the Makefile because epydoc seems to be dead.

Source code can be found at the project’s page at Bitbucket.