Auto-loading Drupal CCK Nodes

10 12 2008

Now online: Auto-loading Drupal CCK Nodes slides for the presentation I gave at the Twin Cities Drupal user group last week.





Simplifying Sofeng’s Python Recursion Example

29 08 2008

In Python recursion example to navigate tree data, Sofeng presents this solution…

def outer(data):
    class Namespace: pass
    ns = Namespace()
    ns.level = 1

    def inner(data):
        print ' ' * ns.level + data['text']
        if data['count'] > 0:
            ns.level += 1
            for kid in data['kids']:
                inner(kid)
            ns.level -= 1

    inner(data)

if __name__ == '__main__':
    outer(data)

…for traversing a dictionary of the form:

data = {'count': 2,
        'text': '1',
        'kids': [{'count': 3,
                  'text': '1.1',
                  'kids': [{'count': 1,
                            'text': '1.1.1',
                            'kids': [{'count':0,
                                      'text': '1.1.1.1',
                                      'kids': []}]},
...
}

Since his blog doesn’t seem to support code formatting in the comments, I’m repeating my comment here:

You actually don’t need the ‘count’ keys in the data dictionary, nor do you need the “if data['count'] > 0:” block. The code can be simplified even further by using a closure instead of the ‘Namespace’ class, eliminating the need for two (“outer” & “inner”) routines:

def traverse(data):
    print ' ' * traverse.level + data['text']
    for kid in data['kids']:
        traverse.level += 1
        traverse(kid)
        traverse.level -= 1
if __name__ == '__main__':
    traverse.level = 1
    traverse(data)




Python Packages via Easy Install for a Unified-Installer-built Plone

18 12 2007

Because Plone/Zope requires an older version of Python than comes out of the box with many OS’s, some people recommend installing Plone with the Unified Installer. On Unix-like systems, the Unified Installer builds Python, Zope, Plone, and some dependencies from source and keeps the whole shebang relatively segregated from the rest of the OS.

This is great until you need to install an additional Python package for a Plone product. For which of your multiple Python versions will your installer build the package? This question would be frustrating enough even if there weren’t at least five different installers for Python packages.

The installer I use, and the one I’ll write about here, is Easy Install, which comes with setuptools. Having much experience with Perl, I chose Easy Install because it’s supposedly “the closest thing to CPAN currently available for Python.” One problem with Easy Install is that it tends to install packages in the system Python site-packages directory. Here’s how to easy_install packages for the Python built by the Unified Installer:

  1. cd $ZOPE/bin
  2. wget http://peak.telecommunity.com/dist/ez_setup.py
  3. ./python ez_setup.py
  4. ./python -m easy_install $package_name

Voila! See the Easy Install docs for details about why this works.

You may also want to set up some aliases for your various Pythons.





Zope debug-mode: designed to produce silent failures!

12 12 2007

Much to my bemusement, a minor change to a Plone product I’m writing caused Zope to silently fail to start. Why no error message? Since I was running Zope in debug-mode, this seemed like a problem. After exhausting what I thought were the obvious approaches to diagnosing the problem, I finally decided to review what debug-mode does. From the zope.conf that comes with Zope 2.9.7-final:

# Directive: debug-mode
#
# Description:
# A switch which controls several aspects of Zope operation useful for
# developing under Zope. When debug mode is on:
#
# - The process will not detach from the controlling terminal
#
# - Errors in product initialization will cause startup to fail
# (instead of writing error messages to the event log file).

So Zope debug-mode is designed to produce silent failures for “errors in product initialization”. Absolute fucking genius. Principle of Least Astonishment, anyone?





“I am your father.”

30 11 2007

So my dad’s watching Judge Judy now. Not just for laughs, either. He seems to adore her no-nonsense, tough love, take-no-prisoners approach to TV justice. I wonder if he has a crush on her. Just when I thought we couldn’t have much less in common.

This is becoming a pattern. A few years ago, Dad was there when a few friends of mine and I were discussing classic comedy TV: Monty Python, old Saturday Night Live, the Honeymooners. Dad joined in with “The show I really liked was Knight Rider. That talking car was really neat!”

Is this man really my father? Maybe I was adopted…

Dad: No. I am your father.
nihiliad: No. No. That’s not true! That’s impossible!





Howard Nemerov and the Rainforest Cafe

26 11 2007

The following is a minor rewrite of an email message I sent to a friend a few years ago. Since then, several friends to whom I’ve forwarded it have urged me to start a blog. What better for a first post?


I went to the Rainforest Cafe the other night. I never would have, had I not received a gift certificate for a free dinner from a relative. I won’t be going back, and I’m scheming how to get even.

It should have been a tip-off that the gift certificate described it as a “Landry Restaurants, Inc. owned concept” [my emphasis]. The same company owns Joe’s Crabshack, which is almost as obnoxious. The Rainforest Cafe is covered in faux flora and fauna, in more ways than one. When was the last time you saw lions and giraffes in a rain forest? Anyway, a lot of this cheap, plastic crap was animatronic Disneyland shit, and accompanied by loud, high-school-play-quality sound effects, thunder and lightning and stampeding cud-chewers of some sort. There were some live animals, but they were all coral reef sea creatures. I don’t know what they have to do with the rain forest, either. What a fun atmosphere!

What really got me, though, was when our “safari guide” informed us that today’s “special” was a steak. That’s right, a fucking steak special at the Rainforest Cafe. When I asked our server/crocodile hunter if he saw any irony in that, he replied “Oh, I know. All of the food we serve here isn’t even from the rain forest. It’s all American.” A little while later, he added “Most of these animals we have here aren’t from the rain forest, either.” I’m not sure that whoever named the entrees is aware of even that much, given such titles as “Canopy Chicken Salad”, “Tree Top Filet”, “Sudan Shrimp Salad” and “Rumble in the Jungle Turkey Wrap”. Whoever wrote the “educational” part of the menu must have been aware, at least long enough to copy it down, that “20 years ago, rain forests covered 14% of the earth’s land. Today they cover less than 6%”, and that “at the current rate of destruction, rain forests could be wiped out in 40 years”. Whether or not the Rainforest Cafe is contributing to that destruction to make more room to raise cattle for their “Rainforest Burgers”, the menu didn’t say.

The whole experience reminded me of this poem:

Grace to Be Said at the Supermarket

This God of ours, the Great Geometer,
Does something for us here, where He hath put
(if you want to put it that way) things in shape,
Compressing the little lambs into orderly cubes,
Making the roast a decent cylinder,
Fairing the tin ellipsoid of a ham,
Getting the luncheon meat anonymous
In squares and oblongs with all the edges bevelled
Or rounded (streamlined, maybe, for greater speed).

Praise Him, He hath conferred aesthetic distance
Upon our appetites, and on the bloody
Mess of our birthright, our unseemly need,
Imposed significant form. Through Him the brutes
Enter the pure Euclidean kingdom of number,
Free of their bulging and blood-swollen lives
They come to us holy, in cellophane
Transparencies, in the mystical body,
That we may look unflinchingly on death
As the greatest good, like a philosopher should.

— Howard Nemerov