2008/10/24

Let Google do the syntax highlighting

Guido recently posted some sample code to his new blog. The first comment complained that the code was "really crappy", improperly indented and hard to read.

Surprisingly, something good came of the rude complaint. Subsequent commenters described how to make simple changes to the blog template which would delegate code syntax highlighting to a Javascript library, google-code-prettify, which is hosted on Google Code.

This looks a lot simpler than the procedure I've been using, which involves embedding a lengthy blog template stylesheet and, whenever I want to post highlighted code, a 2-3 step incantation from within TextMate.

Anyhoo, this post is a test to see if I can incorporate google-code-prettify into this blog.

def genURLs(station):
tmpl = ("ftp://ftp.ncdc.noaa.gov/pub/data/asos-fivemin/6401-"
"{year}/64010{station}{year}{month:02d}.dat")
today = datetime.date.today()
year = 2004
month = 6
while True:
d = datetime.date(year, month, 1)
if d > today:
return
yield tmpl.format(year=year, month=month, station=station)

month += 1
if month >= 13:
month = 1
year += 1

And another -- this time in C++
#include "test_qt_sample.h"

void TestQString::toUpper() {
QString str = "Hello";
QVERIFY(str.toUpper() == "HELLO");
}

QTEST_MAIN(TestQString)

One more, with long source lines.
#!/usr/bin/env python
# encoding: utf-8

msg = "Surprisingly, something good came of the rude complaint. Subsequent commenters described how to make simple changes to the blog template which would delegate code syntax highlighting to a Javascript library, google-code-prettify, which is hosted on Google Code."

print len(msg.split())

I love the Python community. It is filled with people who respond to every complaint and criticism with courteous, useful solutions. (Google Code ain't bad, either :)

2008/10/22

FRONTLINE: nuclear reaction: Why the French Like Nuclear Energy

FRONTLINE: nuclear reaction: Why the French Like Nuclear Energy:

"French technocrats had never thought that the waste issue would be much of a problem. From the beginning the French had been recycling their nuclear waste, reclaiming the plutonium and unused uranium and fabricating new fuel elements. This not only gave energy, it reduced the volume and longevity of French radioactive waste. The volume of the ultimate high-level waste was indeed very small: the contribution of a family of four using electricity for 20 years is a glass cylinder the size of a cigarette lighter."


The French seem to be leading the world in managing nuclear power and its waste products. So how big, in terms of volume, is their waste storage problem?

Let's assume all of France's electricity is generated by French nuclear plants (it's not -- Wikipedia says the number is about 88%) and that they use all of their generated electricity. (Wikipedia says they export a lot of it.) The population of France is about 64,473,140. So that's about 16 million family-of-four equivalents. In 20 years, they'll need to store 16 million cigarette lighters. What is that, about 7 million cubic feet?

Assuming that's in the ballpark, and assuming you can store that waste without having to space it out to avoid assembling a critical mass, that'd be a cube about 19 feet on a side, every twenty years. Pretty small. The Bat Cave could probably handle 20 years of waste...

2008/10/21

Another success for cancer immunotherapy

For cancer patients, personalized treatment offers a new range of options -- and hope - Los Angeles Times:

"Those words could serve as the new mantra in medicine. After having his tumor removed and undergoing chemotherapy and radiation, he received a novel treatment that was designed using his own white blood cells and proteins taken from his tumor to prod his immune system into recognizing and attacking more cancer in his body."


Many credit Dr. William B. Coley for pioneering cancer immunotherapy, in the late 1800s and early 1900s. Coley focused on triggering bacterial infections in cancer patients, because his review of case histories showed that these infections often caused tumors to shrink. He surmised that the infections stimulated patients' immune systems to attack the tumors as well as the bacteria.

2008/10/16

CMake

Last spring I evaluated waf as an alternative to SCons (and its 3rd party Qt4.py plugin) for Qt4 projects. I've finally settled on CMake.

waf's wscript files could be beautifully concise. Alas, support for Qt4 applications was unstable, and the support for building OS X application bundles was both rudimentary and unstable. (By "unstable" I mean that the qt4 and osx tools would break periodically, and/or that the internal APIs would change so much between releases that my own customizations would break.)

The final straw was that I could not control the library order when linking static Qt4 libraries. That made it impossible for me to build Qt4 apps which used QtSvg.

I wish I had time to document these problems properly -- no doubt waf's maintainer(s) would prefer bug reports to detail-free claims that "it doesn't work."

In any case, CMake seems to be doing the job. It can perform out-of-line builds, supports defining and running unit tests, and doesn't get in the way of writing integration tests in Python, to drive e.g. C++ programs. It knows how to build Qt4 applications and lets me control the link order for static libraries. And it works well on OS X and Linux.

Go Vote Now

I'm Bob Schieffer of CBS News, and I will leave you tonight with what my mother always said: Go vote now. It will make you feel big and strong.
:)

The New York Times (registration required?) has video, a transcript, and some fact-checking on last night's debate.

2008/10/15

PolitiFact | Beating a retreat on a lavish retreat

PolitiFact | Beating a retreat on a lavish retreat:

Obama's comments suggest a misunderstanding of the details behind AIG’s collapse, or a deliberate effort to skip over the realities of AIG's corporate structure in order to make a good point. Also, Obama slams AIG for two junkets at a time when the company had only held one. AIG might have had a tin ear when it came to organizing corporate events. But Obama’s wrong to lay blame for the financial meltdown on a highly regulated, profitable part of the business that sells life insurance. We rule the claim Barely True."


Turns out the AIG junket involved a business unit which dealt in insurance, not the unit which lost all that money on mortgage-backed securities. And many of the attendees were independent AIG insurance agents, not employees of AIG. And of course the cost of the junket was several orders of magnitude smaller than the cost of the AIG bailout.

Even in the financial crisis, there are few simple truths.

2008/10/11

Lake Peak

Last month I got to spend time in the mountains above Santa Fe. The resulting video is up at Vimeo now.


Lake Peak from Mitch Chapman on Vimeo.

The compression is bad. Then again, Vimeo is free :) And they provide hyperlinks to the original uploaded video.

2008/10/07

We Are Too Many: 1/4 of World's Mammals Face Extinction

One Quarter of World's Mammals Face Extinction: Scientific American:

" Deforestation, along with hunting or gathering food are the prime causes of the rapid declines in land mammals, such as elephants in Asia; most endangered marine mammals, like the vaquita in Mexico's Gulf of California, are killed by fishing nets, ship strikes or pollution."
"Vast tracts of tropical rainforest have been replaced by palm oil plantations for food and biofuels, satellite imagery reveals."