Tuesday, March 22, 2005

New Projects

As if things haven't been busy enough, with work, etc., I've got a couple python/twisted/Nevow projects in the works.

The first one is PyKon (Python Ikon), a gallery application for managing galleries, photo albums, and images. It's just getting started, so there's nothing to show yet, but it uses Nevow and the Python Imaging Library. This project actually comes at the request of many friends who have been bugging me about this for quite some time. You know who you are ;-) This will be the first non-technical, user-oriented app I have built with Nevow, and am therefore quite looking forward to it. I will also be delighted to not have to install, run, and manage any more PHP-based galleries.

The second project is a complete whim: I want to be able to provide fellow developers on mail lists and irc channels with a means of using something like TinyURL, but with the additional ability of being able to add an optional, distinguishing string at the end. This will make it more clear when reading a post to a mail list or seeing a bunch of URLs pop up on IRC. I'm calling it URLdb. I started by copying the Nevow pastebin example app (which totally rocks, btw). The code is here.


supybot IRC Channel Bot and Subversion Commits

programming :: python :: internet



Last night at the Hacking Society meeting in Fort Collins, I finished
my latest utility. I use supybot on our dev channel and the other day,
I learned how to write plugins for it. After writing one, I realized
that wasn't exactly what I needed. What I really needed was to add my
own daemon to run inside supybot's daemon. Then I learned the complete
internals of supybot. Quite an interesting experience. I wrote a
daemon/notification server last year that monitors arbitrary
directories and files for changes to contents, time stamps, etc. I
wanted my daemon to monitor a directory where our subversion hooks post
updates, see which files (updates) have been added, and then parse the
updates for information that is useful to post on an IRC channel. *And*
I wanted this daemon to run inside the supybot daemon. In less than 24
hours, supybot was learned and my daemon was buried inside of it nicely
;-)


At the Hacking Society meeting, I finished up the parsing for the
subversion commit updates... today, the results were viewable as
everyone made their code changes. Ah, data is wonderful.


Sunday, March 20, 2005

Living in an Epic Tolkien Setting

leisure :: nature



We worked pretty hard at Adytum last week, so Friday and the weekend
were filled with little rewards... like pizza, going to the movies, and
most importantly, hiking in the Rockies. I have been in the Alps;I have
been in the Himalayas. Each are impressive and beautiful. The Rockies,
though... mmm. That's home.


I am now the proud owner of a season pass to the US National Parks.
This sponsorship ranks among the highest causes I contribute to -- just
as important as preserving indigenous cultures and human rights.
Environment, ecologies, biosystems -- these are insanely precious
resources. And, you know, one of the most potent ways to recharge,
de-stress, and get reconnected to the stuff that's really important in
life: living.

We drove up into Rocky Mountain National Park, just West of Estes Park,
CO. It was less than an hour from my front door, a fact I am
continually in awe of and grateful for. (Yes, those're *two* dangling
prepositions.) Driving down Routes 34 and 36, seeing these Immense
Mountains and then More Immensity behind those Immensities was just
extraordinary. I was just giggling all yesterday. My mind simply went
on overload and I reverted to the state of a 4-year-old who is fresh to
the world, has absorbed all he can handle, and simply babbles in
synaptic twitching.

The Rockies. This is my home, now. I just can't get over it. Whenever I
am hiking or driving or bicycling in those mountains, I feel like those
enormous, snow-capped peaks are my big brothers, or uncles... like
they're sheltering and taking care of me. It feels like an excerpt from
the Silmarillion or The Two Towers, where -- like the Ents -- the
mountains will, at any moment, begin speaking in deep, booming voices.

I simply couldn't be happier with living in Colorado. I see now that
I've been waiting to live here all my life. I'm home. And I'll let you
know if the mountains start talking about little people or feisty
rings.


Friday, March 18, 2005

Constantine

entertainment



I haven't seen any reviews, and I don't want to. I just got back from
the movies where I saw this little gem, and I've got to say that it was
awesome! I had such a great time watching it. I laughed at all the
jokes, enjoyed the fun occult references, and thought that Keanu did a
great job. My biggest fear was that this was going to be a poor attempt
at Matrixhood (like the first half of Underworld), and it totally
wasn't. There were a couple humorous nods to the Matrix, but the feel
was entirely different. Not having read the original comic, I have no
idea how true they stayed to the story, but whatever the case may be,
they told a great story ;-)


Very good fun.


iTunes Playtlist with cElementTree

python :: programming :: music



When we moved to Colorado from Maryland in January, a Tibetan friend of
ours who is a monk helped us pack, drive, unpack, and setup house when
we got here. During the drive, we spent many hours practicing English,
Tibetan, and listening to "injee" music on my iPod. There were certain
songs that he could listen to more easily than others. It was sometimes
surprising to me the songs where lyrics were enunciated well enough to
be mimicked without understanding the content. The one that made me
laugh the hardest was "Cold As Ice" by Foreigner... there is something
totally hilarious about driving cross-country with a Tibetan monk, both
of you singing "She's as cold as ice!" at the top of your lungs. It's
one of those moments you know will stick with you forever. Another good
one was KC & the Sunshine Band's "Shake Your Booty" -- it turns out
English "shake" is cognate with a Tibetan colloquial word of similar
pronunciation and meaning.


Anyway, I was supposed to build CDs of photos and music from our
several weeks together and send them back home to Lama Gyaltsen. iTunes
exports playlists in several formats, including XML. This was a perfect
excuse to play with ElementTree some more, while the CDs burned (that's
another cool thing about iTunes: got a play list that's 3 and a half
hours worth of music and you want to burn to CD? No problem! It splits
them up for you. Save your brain cells for the important stuff like
playing with python).

Here's the code:

import cElementTree as et
filename = '/Users/oubiwann/Desktop/Mix - Lama Gyaltsen.xml'
tree = et.parser(filename)
root = tree.getroot()
template = '%s: %s'
for i in root.find('./*/dict').getchildren():
if i.tag == 'dict':
data = i.getchildren()
for j in range(0,len(data)):
if data[j].tag == 'key':
if data[j].text == 'Name':
print template % ('Song Name', data[j+1].text)
if data[j].text == 'Artist':
print template % ('Band Name', data[j+1].text)
if data[j].text == 'Total Time':
converted = '%s:%.2s' %
divmod(int(data[j+1].text), 60000)
print template % ('Length', converted)


Update: Fredrik Lundh has just blogged about this :-) He has a
added simpler loader for for iTunes playlists to ElementTree. Read
about it here.


Nevow + Twisted, or mod_python?

python :: web :: programming



To twist or not to twist, this is always the question.


Or, rather, I always want to use twisted, but can I produce the numbers
and the tests for customers that show it performs as well as
mod_python?

Or, even better: how does one architect a killer twisted web app server
that performs insanely well with high concurrency and blinding speed?
Hmm, It's been a while since I checked out the Nevow code base, so I
just did an svn update, and I see there there is now a wsgi cgi for
mod_python in the examples directory. This is cool, I shall have to
test... Perhaps I can have my cake and eat it too.

Well, I just installed it on a server of mine and have been running
apache bench against the following:

nevow wsgi mod_python code
a nevow example running on the twisted daemon
the AdytumSolutions web page (custom mod_python/publisher mini-cms)
a tomcat example jsp page.

I ran 5000 requests, 20 concurrent requests for each. Here are some
results:

nevow wsgi - Requests per second: 48.96 [#/sec] (mean)
nevow twisted - Requests per second: 64.85 [#/sec] (mean)
simple mod_python app - Requests per second: 824.22 [#/sec] (mean)
tomcat - Requests per second: 288.01 [#/sec] (mean)

I've just spent about an hour reviewing the Nevow example apps (started
up the examples by cd'ing to the examples directory and
running 'twistd -noy examples.tac'). I must say: Donavan,
Matt, and company have done an amazing job in the last year. Truly
impressive. Lots of really good examples that get the creative juices
flowing and jump start one right into seeing how to solve all kinds of
problems with Nevow. In fact, I am so impressed that, if I can learn
how to get as much performance out of Nevow, I would gladly sacrifice
some raw running/processing speed for ease of development and
maintenance. And extensibility. And joy.

I wonder if I can get my clients to see things this way?

Perhaps it's time to hop back on #twisted.web and start asking
questions I'm sure they are quite tired of answering...


Tuesday, March 15, 2005

Advogato Diary Archiver

web :: python :: programming



Last night I finished the script to pull (XML-RPC) my diary entries on
Advogato into a custom archive format. I had to use an ugly sys.stdout
hack to use the cElementTree.dump() method... but discouraging it's
misuse was probably a motivating factor for Fredrik Lundh to send its
output to stdout in the first place. I just wanted the entire contents
of a particular div, and I didn't want to have to do all that text/tail
crap.


The really nice thing thing about this, though, is piece of mind: a
single server crash anywhere will no longer result in catastrophic loss
of blog entries. Because, you know, blog entries are so damned
important ;-)


Update: Duh. cElementTree.tostring(aElement). Say no more.



Sunday, March 13, 2005

America Beyond Capitalism -- Posters!

economics :: governance :: politics



Today, I got an email from Ted Howard (director of the Democracy
Collaborative
) letting me know that there are posters based on the
book America Beyond
Capitalism
available for download here. Very cool stuff. Some very good facts to know and
be aware of. One that really pisses me off is in 1945 corporate
taxes provided 35.4% of federal revenues and now corps are only paying
7.4%. That shit just ain't right. I also like this one -- and in to answer their question,
no! it's not what I want. In fact, since working for myself, I have
changed my work week to less than 40 hours a week. I strive for 30, but
would like to get it down to 25 hours/week. With more time off, I get
to spend my time relaxing, hiking, volunteering for projects I care
about -- improving my quality of life. As a result, during my work
hours, I am much more productive and energetic, happy about life and
working.


BTW, if you haven't read the book America Beyond
Capitalism
, you really ought to check it out. It's a fast read with
some intense (but accessible) data. And it's not a doom and gloom thing,
either - there is all kinds of information in it about what various
groups, researchers, corporations, communities, etc., are doing to
change the immense imbalance of power and wealth.


Thursday, March 10, 2005

Advogato and Bad HTML

web :: programming :: python :: html



I don't know if I'm the only one who's trying to use Advogato in
non-ordinary ways (and I'd guess that at least Titus Brown is), but
I'm having a hell of a time getting mechanize to
work with the site. I love vi and I won't apologize for it ;-) I love
using it as my IDE as well as my CMS. I want to be able to edit
valuable information in a vi/vim terminal window. Sean Reifschneider wrote a nifty little python
script for editing messages in vi (I forget which RFC to which they
were compliant) and posting to websites. Alex Levy did something related, where you
could edit pickled data files via command line editors. I just totally
dig that stuff. I've written three mini-CMSs in PHP, perl, and python
(over the past 5 years) that use the command line as the primary means
of adding and editing data. Now, I want to do the same thing with my
Advogato account.


Alas, this is proving very difficult so far. Advogato does not seem to
be using proper html! So far, none of the text input fields in the
forms I have looked at are labled type="text" -- they are missing the
"type" attribute all together. As a result (at least, I think the lack
of "type" is the cause), mechanize does not see these inputs as
controls, and I can therefore not manipulate them. This means that I
cannot login and I cannot update my account settings. Very troublesome.
Additionally, it would be wonderful if the forms could be given
name attributes for easy access. I would love for someone to point out
a way around this or my misunderstanding of mechanize.

Of course, there is always the hope that the Advogato XML-RPC API will
be extended to allow for the managing of account data as well as for
publishing articles. Then I wouldn't care how the html gets abused ;-)


Update:
It seems that I can, in fact, get controls for all the account form
elements in mechanize, even though the text boxes are missing the
"type" attribute. However, I am still unable to process the login form
via mechanize. I am able to login, but that requires passing the
passphrase for the account in a GET, the consequence being that the
account password will turn up in log files.




Wednesday, March 09, 2005

pymon

python :: programming :: networking



Well, after several months, I've finally had a chance to sit down and
work on pymon again. We're plugging
away, slowly but surely, on the next alpha release. Every time I dig
into twisted code, I am just delighted. Those guys just rock. The
flexibility it provides in writing network-oriented apps is just
amazing. I'm really excited to see how this project matures.


However, I'm getting tons of Zope/Plone work now, and that's stuff's
currently paying the bills, so pymon might have to wait for a few more
weeks. Until I get crazy with working with Zope/Plone and need a real
coding break ;-)