My name is Paul Bissex, and e-scribe.com is my consulting business. I build web applications using as much open source software as possible. From September to June I teach web design and other important non-photographic professional skills to photographers. In the '90s I wrote technology commentary and reviews for magazines, newspapers, and web publications, including Wired, Salon.com, FamilyPC, the late lamented Web Review, and the Chicago Tribune. Feel free to email me.
I'm co-author of "Python Web Development with Django", an excellent guide to my favorite web framework. Its strong points include an introduction to Python, and better coverage of Django 1.0 than nearly anybody else. Published by Addison-Wesley, it is available from Amazon and your favorite technical bookstore as well.
This runs on Django, served by Apache and mod_python. The database is SQLite. The operating system is FreeBSD, on a VPS hosted at Johncompanies.com. Comment-spam protection by Akismet. Vintage topo imagery from the Maptech archive. The markup engine is Markdown.
Akismet, del.icio.us, Django, dpaste.com, Emacs, FreeBSD, Freenode, jQuery, LaunchBar, MacPorts, Markdown, Mercurial, OS X, Postfix, Python, SQLite, Subversion, TextMate, Trac, Ubuntu Linux, wmii
At least 59046 pieces of comment spam killed since January 2008, mostly via Akismet.
This is a function that takes an integer and returns its ordinal representation, e.g. "1st" for 1 and so on.
It's not the most readable thing, but once I saw the pieces falling into place I couldn't help myself. Repetition of the "th" literal is the only thing that bugs me. Oh well.
ord_text = lambda n: "%d%s" % (n, "th" if 10 < n % 100 < 14 else {1:"st", 2:"nd", 3:"rd"}.get(n % 10, "th"))
Comes with a one-line test suite!
for t in "1st 2nd 3rd 4th 11th 12th 13th 21st 22nd 23rd 111th 112th 113th".split(): assert(ord_text(int(t[:-2])) == t)
Excelllent catch, Matt, thanks! Fixed.
And yes, I should have mentioned that this is Python 2.5+ only, due to the ternary logic.
Unfortunately, your one-liner is so desirous to be a one-liner that on my resolution it reaches way out of the central column of your layout and past the 'Atom feed' link.
Great! Now add internationalization for Russian, Swahili, and Chinese.
Here's a version that eliminates the repeated "th" AND runs in both Python 2.3 and 2.5.
ord_text = lambda n: str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n % (10 < n % 100 < 14 or 10), 'th')
Hi,
Excellent blogroll/site there. Infact I was happy to find this site running on Django. However, the CSS (I believe, since I'm not too good with web-technologies), may need some mending, because using Google Chrome (or even IE), in a 800px wide window the code-snippets run outside the central pane boundary, and onto the right pane, rendering the text undreadable. Hope that you fix it.
cheers, Banibrata
Banibrata, thanks for the note. Keep in mind that the lines above are extra-wide by design -- they're supposed to look too long for their own good. Though a style makeover of the site is inevitable, this post won't be driving it!
Comments use Markdown syntax. Your comment will not appear until approved, which may take a few hours or more. Spammers will be torpedoed.
SPF-enabled spam domains
1 comment
Chess via iPod
2 comments
Aesthetics and computation
2 comments
robots.txt via Django, in one line
4 comments
zoot
Offsite, online backup: rsync.net
16 days ago
Craig
Bicycle Repair Man bundle for TextMate
24 days ago
Fazal Majid
SPF-enabled spam domains
29 days ago
Adrian Holovaty
Chess via iPod
53 days ago
Alexander Kahn
Aesthetics and computation
58 days ago
Copyright 2009
by Paul Bissex
and E-Scribe New Media
I think you might need to add 111th, 112th and 113th to the string in your test suite.
(Can't be certain though because I get a SyntaxError when trying to run your one-liner in python 2.3.4)