2007/10/29

CherryPy 3: interpreting error messages

I'm stubbing out a method in a nested CherryPy application object. I keep getting error messages of the form


File "/path/to/CherryPy-3.0.2-py2.5.egg/cherrypy/_cprequest.py", line 551, in respond
cherrypy.response.body = self.handler()
File "/path/to/CherryPy-3.0.2-py2.5.egg/cherrypy/_cpdispatch.py", line 24, in __call__
return self.callable(*self.args, **self.kwargs)

TypeError: 'Data' object is not callable


And the cause? Almost every time, in the browser I've mistyped the URL for my server's Ajax method. I might be invoking foo instead of bar, and the result is always this sort of error message.

Why don't I instead get the old "We didn't find anything"? Dunno. It's probably something in my configuration.

2007/10/26

Exhibitionist spiny anteater reveals bizarre penis - New Scientist Environment

Science can be funny.

New Scientist Environment:

The spiny anteater ... is notoriously difficult to observe in the wild and shows little enthusiasm for breeding in captivity...

Four-headed phallus

Then Steve Johnston of the University of Queensland in Gatton, Australia, and his colleagues inherited a male spiny anteater that ... had been ‘retired’ from a zoo as it produced an erection when being handled at public viewing sessions.


This reminds me of a Panda exhibit at the Cincinnati Zoo in the late 80s. We were ushered into the viewing gallery in groups, at regular intervals. There we stood gazing in reverent silence upon an artificial bamboo forest -- a quiet, still forest, in the midst of which lay an inert black and white lump.

Minutes passed. The lump stirred. The crowd gasped.

The lump rolled over. The crowd went "Aahhhwww," and broke into applause.

They seemed not to care that they were now facing a leering, semi-conscious panda, sprawled on its back, legs spread wide like a drunken flasher.

Er, anyway... when doing science, one must be careful with electricity:

The spiny anteater's four-headed phallus had been puzzling scientists. "When we tried to collect semen by [electrically-stimulated ejaculation] before, not only did we not get a single drop, but the whole penis swelled up to a four-headed monster that wouldn't fit the female reproductive tract..."


2007/10/19

New Scientist: Cold weather really does spread flu

Cold weather really does spread flu - New Scientist Environment

Flu virus can spread without the aid of coughing/sneezing -- you just gotta breathe. It stays in suspension longer in cold, dry air than in warm, moist air. And it doesn't help that mucus flows more poorly in cold weather.

"...Virtually no lab animals get it the way humans do... The most useful animal has been the ferret... “They’re big, they’re expensive, and they bite,” Peter Palese of Mount Sinai Medical School in New York City told New Scientist.

In 1919, US Army doctors at Camp Cody in New Mexico reported (Journal of the American Medical Association, vol 72 p1056) that the 1918 flu pandemic had killed their guinea pigs – kept at the time for medical tests. “We didn’t know guinea pigs got flu,” says Palese. They are no longer popular lab animals, and no-one had tried them."


Bad news for air travelers:
"“It spread just in the air they exhaled,” says Palese. “Guinea pigs with flu don’t cough or sneeze.”"


2007/09/27

Thank Goodness for the Judiciary (again)

Oregon judge knocks down part of Patriot Act:

"SEATTLE (Reuters) - An Oregon judge on Wednesday ruled that two provisions of the Patriot Act violated the U.S. Constitution's protection against unlawful searches and seizures.

U.S. District Judge Ann Aiken ruled in favor of Brandon Mayfield, a lawyer wrongly arrested by the FBI in 2004 for possible ties to the Madrid train bombings, who challenged the secret searches of his home and office.

The judge said the amendments made by the Patriot Act to the Foreign Intelligence Surveillance Act allows the government to conduct searches and monitor American citizens without probable cause, which is typically required by the Fourth Amendment to the U.S. Constitution.

'The defendant here is asking this court to, in essence, amend the Bill of Rights by giving it an interpretation that would deprive it of any real meaning. This court declines to do so,' Aiken wrote in her ruling."

2007/09/25

Stucco color matching for fun, if not profit

This summer I've bought two buckets of stucco patch for the house. I can't seem to hold a color chart up against the wall and have any chance of picking the right color.

Today I finally realized the digicam could do most of the work.

  1. Tape the color chart to the wall.
  2. Take a picture.
  3. Import it into iPhoto.
  4. Create a new OmniGraffle document.
  5. Create a big rectangle.
  6. Set its fill color by sampling the wall color from the imported photo.
  7. Create a bunch of little rectangles.
  8. Lay them out over the "wall" rectangle.
  9. Set their fill colors by sampling the swatches in the photo.

Stucco Color Matching 145 Solana.jpg

You don't even have to do any white balance correction. Everything in the photo should have its color skewed in roughly the same way.

Seempuhl. Wish I'd thought of this about ten dollars ago...

2007/09/24

Marching Morons

Getting ready to launch a glider at Kamuela/Weimea, Island of Hawaii. 1182 on Flickr.

The war on terror looks so often like a war on civil liberties. Our airports showcase the problem: law enforcement does its job literally and vigorously, enforcing "the law" without regard for whether enforcement is warranted or the law is even constitutional. Vision Aerie's experience at Kamuela airport is just one more example.

And when it turns out that the enforcers have over-reacted? Admit no wrong. Note the good fortune, of those detained in error, that law enforcement has shown such great self-restraint.

2007/09/20

Canon Scanners, Spotlight and OCR

When I scan receipts and invoices with my Canon LIDE 600F, OS X's Spotlight somehow, magically, is able to find them based on their text content. But I'm just scanning the documents, not running OCR software on them.

For example, this morning I scanned the receipt for my new MacBook, so I could send it in for a shipping rebate. Just for grins I then did a Spotlight search for "MacBook". There it was, near the top of the list.

mdls showed that "MacBook" didn't appear anywhere in the file's metadata. And the filename, "File0001.PDF", certainly didn't match. Yet somehow mdfind identified it as a match.

Searching for the string "MacBook" in the PDF turned up nothing. (Granted, I used 'strings -a' to extract the strings, and that command is ASCII only.)

Google, and David Creemer, provided the answer. Creemer also showed that the text in "CanoScanned" documents is selectable in Preview.app.

What's going on? It seems that the CanoScan Toolbox application is automatically performing OCR when it finishes scanning documents. For more info see zachary.com : Easy and cheap PDF Document Management (with OCR) on Mac OS X.

Synergy kudos to Canon and Apple!

2007/09/16

Water consumption in Santa Fe

Future Water, part 1: A big straw:

"Despite growth, the citywide annual demand for water is lower now than it was in most of the 1980s and '90s. Residents used 9,600 acre-feet last year. That compares to nearly 12,000 acre-feet in 2001."


The area's estimated population: 80,000, growing at 20% per year.

Maybe it's okay that I don't water the lawn :)

2007/09/15

Jon Udell: Discussing the re-invention of air travel with Ed Iacobucci

A conversation with Ed Iacobucci about the reinvention of air travel --
This article by Jon Udell ties together several items of significance to me: Eclipse Aviation; the Santa Fe Institute and the BIOS Group (now part of NuTech Solutions); complexity theory, Free Flight, general aviation and Byte Magazine (may it rest in peace).

2007/09/10

Viking ship resurfaces under Merseyside boozer | The Register

From
The Register -- too funny:

"A team from Nottingham University [...] believes it has rediscovered [...] an intact Viking boat under a Merseyside pub - originally unearthed in the 1930s [...], but quickly reburied because [the builders] feared 'an archaeological dig would disrupt their work'."

2007/08/29

www.neweurasia.net - Blogging Central Asia » Kiran over Mongolia: Interview with Joseph Spaid

www.neweurasia.net - Blogging Central Asia » Kiran over Mongolia: Interview with Joseph Spaid:

Q: What motivated you to shoot the documentary?

I was moved by the rugged and natural beauty of the eagle hunters and their lifestyle. Berkutchis [...] are just so damn strong and tough. They typically don’t even wear gloves, although it regularly gets below -25ْ F where they hunt. They are true ‘badasses’ by my definition.

2007/08/28

A'bit an hour of Stephen Fry

Stephen Fry just turned 50. BBC did a documentary on him:
http://www.snitchseeker.com/harry-potter-news/j-k-rowling-potter-stars-talk-stephen-fry-49899/

It seems as if everybody is involved with the man, including many of the folks behind Harry Potter.

Would I could write. A pun of Fry and (six degrees of) Bacon is trying hard to form in my head.


2007/08/23

Ted Leung summarizes Erlang

Some simple thoughts...:

Semantically, there is a lot to like about Erlang - the actor based concurrency model, hot code swapping, higher order functions, and (once one gets used to it) pattern matching. The OTP libraries have been refined by many years of production usage in demanding, commercial applications.

2007/08/20

Posting Syntax-Highlighted Code to the Web, Redux

Following up on July's post, I've modified my TextMate 'rawhtml' command so it no longer generates inline <style> sections. (They may work, but AFAIK <style> should appear only in a document's <head>.)

Instead, the command now wraps its output in a div of class SourceCode, and it expects the containing web page to include an appropriate <style> section.

Here's a test to see if this works :) I've added the following CSS to the Bottled Text template HTML:

div.SourceCode {
font-family: "Bitstream Vera Sans Mono", "Monaco", monospace;
font-size: 12px;
width: 500px;
overflow: auto;
margin: auto;
white-space: nowrap;
padding: 4px;
background-color: #ffffff;
border: 1px solid #777788;
}

div.SourceCode .comment {
font-style: italic;
color: #888;
}

div.SourceCode .keyword {
font-weight: bold;
}

div.SourceCode .string {
color: #00F;
}

div.SourceCode .entity {
text-decoration: underline;
}

div.SourceCode .storage {
color: #888;
}

div.SourceCode .support {
color: #0b0;
}

div.SourceCode .constant, div.SourceCode .variable {
color: #F0F;
}




The "rawhtml" command script now looks like this:
#!/bin/sh
cat <<HTML
<div class="SourceCode">
<div style="white-space: pre; -khtml-line-break: after-white-space;">
HTML


perl -pe 's/<\/[^>]+>/<\/span>/g' \
| perl -pe 's/<([^\/.>]+)[^>]*>/<span class="$1">/g' \
| perl -pe 's/\t/&nbsp;&nbsp;&nbsp;/g'

echo "</div></div>"


To get a realistic preview in MarsEdit, click the "Edit Template" button in the preview window and add a <style> section to the preview template for your blog. Paste in the CSS above and you're good to go.

2007/08/14

Sci Foo 2007 Gossip Liveblog (Aaron Swartz's Raw Thought)

Engrossing summary: Sci Foo 2007 Gossip Liveblog (Aaron Swartz's Raw Thought).

Dyson: Climate models are rubbish | The Register

Dyson: Climate models are rubbish | The Register:

"Dyson can expect another round of crucifixion with the predictable chorus that he's not a climate 'scientist'.
His contention, that the models aren't really science when they're programmed to produce the expected results, will no doubt be overlooked. ®"


I love the way Dyson writes. His article is full of thought-provoking observations and assertions, not all of them as directly concerned with global warming as you might expect. For example:
All our fashionable worries and all our prevailing dogmas will probably be obsolete in fifty years.

2007/08/06

Death, taxes and beyond

I thought bureaucracy could follow you only as far as the grave. But then there's eastern religion:
China tells living Buddhas to obtain permission before they reincarnate - Times Online

Via Ottmar Liebert

2007/07/19

Posting Syntax-Highlighted Code to the Web

Awhile back I noted some ways to copy syntax-highlighted text from TextMate to other applications like VoodooPad and MarsEdit. In some cases it was a simple procedure of two or three steps. But getting syntax-highlighted text into MarsEdit was comparatively tedious.

In all cases the procedure started with the Experimental -> View Document as HTML bundle. This morning I finally got around to browsing that bundle's definition and lo! it's just a simple Perl script invocation.

Better yet, it can act on either a complete document or just the text you've selected within that document. So if you want to post a code snippet? No problem.

It's also easy to make a copy of the bundle which, instead of creating a new HTML document, creates a plaintext document containing the HTML mark-up. You can copy the contents of this document and paste it directly into MarsEdit. (With a few caveats, i.e. you need to modify the stylesheet to avoid affecting the appearance of your entire post.)

The steps are simple:


  1. Select Bundles->Bundle Editor->Show Bundle Editor...

    Picture 4.png

  2. Browse into Experimental and select the View Document as HTML command

    Picture 5.png

  3. Click the "double-plus" button at the bottom of the window to make a copy of the command

    Picture 6.png

  4. Drag the command to some other bundle. I like to keep custom snippets, commands and templates in an @My Stuff bundle, which won't get overwritten when I upgrade TextMate

  5. Select the copied command. Rename it as you see fit, e.g. Format as Raw HTML

  6. Change the Output popup menu's value from Show as HTML to Create New Document

    Picture 8.png



That's it! Now you can select some code which you want to post, select your new command from the Bundles menu, and get a window with (almost) ready-to-post HTML markup.

Next Steps


Keyboard Navigation


If you come from (X)Emacs and wish you could invoke the bundle without having to navigate through a menu hierarchy, you can. Just use Control-Command-T to bring up the Select Bundle Item command window. Then type in the name of your new command, and hit return.

Picture 11.png

If you want to feel even more at home you can give your bundle a name which "feels like" an Emacs command. I've been trying single-word "command name" prefixes, like "rawhtml - Format as Raw HTML". The idea is to give your command both a quick-to-type "command" name, so you can get to it quickly in the command window, and a human-readable name so you can remember what it does :)

Limiting the Scope of the Styling


I haven't had time to do further customizations to the command. The next thing to tackle will be the stylesheet which it generates -- it's written to address an entire document, so it applies styles to e.g. the body element. I'd like to customize the generated HTML so it puts everything into a <div> with a unique timestamp for its id, and to modify the CSS so it applies only to that div. That'll make it easier to create markup that can be dumped directly into a blog regardless of what else might be on the blog page.


Update:
Turns out it was easy to modify the generated styesheet, and to wrap the output in a timestamped div. I'm not sure how righteous it is to include a <style> block inside the body of a blog post, rather than the head, but it renders okay in WebKit and Firefox 2.



Here's the source code for the command, as rendered by itself :)



#!/bin/sh
now=`date +'%Y%m%d%H%M%S'`

cat <<HTML
<style type="text/css">
#source_${now} {
font-family: "Bitstream Vera Sans Mono", "Monaco", monospace;
font-size: 12px;
width: 400px;
overflow: auto;
margins: auto;
padding: 4px;
background-color: #ffffff;
border: 1px solid #777788;
}

#source_${now} .comment {
font-style: italic;
color: #888;
}

#source_${now} .keyword {
font-weight: bold;
}

#source_${now} .string {
color: #00F;
}

#source_${now} .entity {
text-decoration: underline;
}

#source_${now} .storage {
color: #888;
}

#source_${now} .support {
color: #0b0;
}

#source_${now} .constant, #source_${now} .variable {
color: #F0F;
}

</style>
<div id="source_${now}">
<div style="white-space: pre; -khtml-line-break: after-white-space;">
HTML


perl -pe 's/<\/[^>]+>/<\/span>/g' \
| perl -pe 's/<([^\/.>]+)[^>]*>/<span class="$1">/g' \
| perl -pe 's/\t/&nbsp;&nbsp;&nbsp;/g'

echo "</div></div>"

2007/07/18

Firefox 2.x / Linux image scaling

Why does image scaling seem to be so bad in Firefox 2 on Linux?

For one of our web apps we want to show static pixmap images of chemical depictions. Depending on the context we want to show those depictions at different sizes, and we don't want to create and cache too many renderings. We'd rather create one fairly large rendering and have the browser scale it down as needed.

For users who are running Firefox/Win or Firefox/Mac this works fairly well, if the images aren't scaled down too much. (Otherwise lines get too thin, as you'd expect.) But for Firefox/Linux users, the results look horrible.

ff_mac.pngff_linux.png
Firefox/MacFirefox/Linux

What's up with that? Is there any way to control how Firefox downscales images, to get better quality?

Perhaps not. Or not yet, at least. Acts of Volition has an entry comparing image resizing in Firefox 2.x and Firefox 3. Paraphrasing:
The Cairo graphics library will power Firefox 3.
In Firefox 2, if you tell the browser to resize an image it will do so, but not with any of the smoothness that you would see if you had resized the image in an application like Photoshop or the Gimp.

Now, in Firefox 3.0 Alpha 1, resizing an image like this actually produces a smoothly sized image.

2007/07/14

changelog: Parallels 3.0: breaking the network

changelog: Parallels 3.0: breaking the network:

Parallels Desktop for Mac installs a startup item, llipd, which delays network traffic of some forms as much as 5 seconds.


According to /Library/StartupItems/ParallelsTransporter/StartupParameters.plist llipd is a "Parallels Link-local IPv4 deamon" (sic).

I don't need Parallels Transporter, so it's outta there.