from __future__ import * 2004/6

2004-06-28

Talking Panda

My first commercial consumer application, Talking Panda, has just been released! We offer a set of foreign language phrase books for iPods.

The installer is written in PyObjC, and I've described some of the development process in this pythonmac-sig message.

posted at 17:21:20    #    comment []    trackback []
 
2004-06-19

Determining the number of common bytes at the beginning of N files

I have a need to compare binary files that are slightly different. I haven't found or written any particularly good tools yet, but here is a script that prints the number of bytes N files have in common before they differ, or nothing if all the files are identical.

#!/usr/bin/env python
from itertools import izip

def blockread(f, size=1024):
    while True:
        block = f.read(size)
        if not block:
            break
        yield block

def blockseq(blocks):
    blocks = iter(blocks)
    first = blocks.next()
    for block in blocks:
        if block != first:
            return False
    return True

def byteseq(blocks):
    idx = 0
    for idx, bytes in enumerate(izip(*blocks)):
        if not blockseq(bytes):
            return idx
    else:
        # this shouldn't happen
        return idx + 1

def firstdiff(generators):
    offset = 0
    for blocks in izip(*generators):
        if not blockseq(blocks):
            break
        offset += len(blocks[0])
    else:
        return None
    return offset + byteseq(blocks)

if __name__ == '__main__':
    import sys
    rval = firstdiff([blockread(file(fn, 'rb')) for fn in sys.argv[1:]])
    if rval is not None:
        print rval
posted at 13:05:20    #    comment []    trackback []
 
2004-06-17

Checking the current directory for progressive JPEGs

This is a quick hack, you'll need PIL with JPEG support installed to use it.

import glob, Image
print '\n'.join([fn for fn in glob.glob('*.jpg') if Image.open(fn).info.get('progression')])
posted at 15:13:20    #    comment []    trackback []
June
MoTuWeThFrSaSu
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
282930    
May Jul

Bob's Rants

XML-Image Letterimage

© 2004, Bob Ippolito