Werbung
Apple iPhone 3G S vertragsfrei, ohne Simlock, kostenlose Lieferung, Turicom Online Shop

Back to the main page

Archive for the 'Programming' Category

Compare files in two directories

Sunday, February 17th, 2008

Sometimes I have two versions of a directory stored on my computer. When cleaning up, it is handy to be able to see which files are in common and which files differ. To do that, I wrote a small Python script that compares two directories. The script also shows duplicate files in each of the directories. MD5 checksums are used to determine if files are equal – no file name comparison is used. Also, the script goes recursively into subdirectories.

Download script (compare.py)

The usage is simple:

Usage: compare.py [-d] dir1 dir2
Compares files in two directories, based on their MD5 checksum.
-d: Debug. Prints the MD5 checksum of every file to stderr.

Sample usage and output:

% python compare.py dir1 dir2
Duplicate files
============================================================

dir1/file 2.pdf
dir1/file.pdf

Common files
============================================================

dir1/image.png
dir2/image.png

dir1/test.pdf
dir2/subdir/foobar.pdf

Files only in dir1
============================================================

dir1/hello.jpg

Files only in dir2
============================================================

dir2/something.jpg
dir2/video.mov

Django newforms: How to create dynamic forms

Thursday, February 15th, 2007

Django is a great framework for building web applications. Recently they started to create the newforms library that makes it easy to handle forms.

But the newforms library works only for static forms. Forms that have a fixed number of fields. What I wanted to do, is create a page that allows you to edit multiple instances of a model at once. It should be similar to edit_inline, but there should be a JavaScript link that allows you to add another instance of the object.

That’s why I have written classes that make it possible to handle this type of forms using Django. No AJAX is utilized to make this work.

(more…)

RSS-Reader Widget: Universal Binary and new features

Friday, June 23rd, 2006

RSS-Reader

My RSS-Reader Dashboard Widget for Mac OS X is now a Universal Binary and should run on Intel Macs. Because I don’t own an Intel Mac yet, contact me if it does not work correctly.

It also supports automatic reloading of the feed and scrolling using the mouse scroller and keyboard arrows (Thanks to Nicolas Weber or implementing scrolling).

Automatische Ansage des Anrufenden

Friday, June 16th, 2006

Bei einem eingehenden Telefonanruf wird bei mir nun Name, Beruf und Ortschaft des Anrufenden automatisch mit einer synthetischen Stimme angesagt. Bei Bedarf wird dies sogar im Telefonbuch über das Internet nachgeschlagen.

Voraussetzung für das Setup sind ein Telefonanschluss bei GGAdigiPhone und natürlich Programmier- und Bastelkenntnisse…

Die Installation und alle benötigten Scripts finden sich in meinem Telefonie-Text.

Vielleicht kann dies ja jemand auf ein Setup mit analogem Telefonanschluss (und Modem im Computer) portieren?

Quick script to count occurrences of words

Tuesday, March 7th, 2006

I wanted to know how many times the words in a file appear. So I wrote a Python script that counts them. Please note that the code was written in a hurry and I know it’s possible to make it better.

Here’s it:

import sys

print sys.argv[1]
f = file(sys.argv[1])
buf = ''
while True:
        line = f.readline()
        if len(line) == 0:
                break
        buf += line
f.close()

buf = buf.replace('n', ' ')
buf = buf.replace('(', ' ')
buf = buf.replace(')', ' ')

arr = buf.split(' ')
dict = {}
for word in arr:
        if not word in dict:
                dict[word] = 0
        dict[word] += 1

for i in sorted(dict.items(), lambda a, b: cmp(b[1], a[1])):
        print '%s: %s' % i

eggdrop.ch blog is powered by WordPress
Entries (RSS) and Comments (RSS).