الجمعة، 13 فبراير 2009

Generate emails with mailto URLs and Python

Scenario: You want to send several emails where only small things change. This sounds like a job for a mail merge program. But if you use mailto: links and Python, you get a nice shell-based solution. This combination also has the advantage of opening each generated email in your email client so that you can take one last look before sending it.



mailto: URL syntax



"mailto:" recipients ( "?" key "=" value ("&" key "=" value)* )?


Open mailto URLs with Python


#!/usr/bin/python

from urllib import quote
import webbrowser

def mailto(recipients, subject, body):
"recipients: string with comma-separated emails (no spaces!)"
webbrowser.open("mailto:%s?subject=%s&body=%s" %
(recipients, quote(subject), quote(body)))

body_template = """Hello %(name)s!

How are you?"""

def gen(email, name):
mailto(email, "Hi!", body_template % locals())

gen("joe@example.com", "Joe")
gen("jane@example.com,jill@example.com", "Jane and Jill")

Related:

Flattr

الأربعاء، 4 فبراير 2009

incsync – incremental backups with rsync on Unix

Time Machine was always a bit troublesome for me on Mac OS X, so I did some research about how to do incremental backups with open source software. The result is the script presented in this post.


Rsync is really cool for backups (if you need bi-directional file synchronization, take a look at Unison): If you specify a source and a target directory, rsync makes sure that files are copied from target to source or removed from target until both directories have the same content. Thus, whatever the state of source and target, after invoking rsync, the target is an exact copy of the source. Rsync has command line options that allow one to only back up changes relative to a “previous” directory:


  • Usage: incsync.sh [timestamp]

    • No arguments: Perform a new backup with the current time as a timestamp.

    • One argument – a timestamp: Continue a previous backup.



  • What it does: Each time, it is invoked, only what has changed (since the last invocation) is backed up, in a new directory with a time stamp.

  • How it works: incsync uses the open source tool rsync for incremental backups. rsync uses Unix hard links (references to files) to do so: Before creating a new backup, one makes a complete copy of the last backup, but the copy does not contain files, only hard links to files. Then one brings the copy up to date with the source directory. Afterwards, the copy looks like a complete backup, but consumes relatively little space on disk. The kicker is that you could now delete the previous backup and the newly created directory would still contain a complete backup. The reason lies in Unix’s handling of hard links: it only deletes a file after there are no more references to it.

  • Inspiration: This script has been inspired by the article “Time Machine for every Unix out there”.

  • Download: on GitHub at incsync.

الأحد، 1 فبراير 2009

JavaScript is becoming a nice language

Apart from impressive speed improvements via Google Chrome's V8 or Firefox's TraceMonkey, I had forgotten that new versions of JavaScript had some really nice language features (I still hope that optional types make it into ECMAScript 4). The article “Pythonic Javascript, it's Python with braces!” reminded me.

What's new in client-side Java?

Client-side Java's evolutionary leap” gives a great overview of interesting things that happened for client-side Java in 2008. Recommended additional reading: