2006/11/28

Copying Syntax-Highlighted Text from TextMate

TextMate has great syntax highlighting skills. Sometimes I'd like to copy code snippets from TextMate to VoodooPad, and I'd like to bring along the text highlighting. A simple copy-and-paste from the TextMate edit window doesn't do the job -- after all, it's a text editor.

Fortunately it is possible to copy with syntax highlighting. The procedure is pretty simple, if a bit obscure.


  1. Select the text of interest in TextMate.
  2. Select Bundles->Experimental->View Document as HTML
  3. A new "View Document as HTML" window should appear.
  4. Select the text in the window and copy it to the clipboard (Command-C).
  5. Switch to Voodoopad and paste (Command-V).

What About MarsEdit?


With a little more work you can paste syntax-highlighted snippets into MarsEdit.

Start out as above. Once the "View Document as HTML" window appears, select View->View Source. Another new window should appear which contains raw HTML.

Select it all (Command-A), copy it (Command-C), switch to your MarsEdit window and paste (Command-V). But first you'll need to re-work the content a bit, since it includes a <style> section which applies to your entire post.

Be sure to collapse the entire style section onto a single line, lest Blogger should insert a bunch of <br/> tags.


Here's an existence proof:



def geoMean(x, y):
"""Get the geometric mean of x and y."""
return math.sqrt(abs(x * y))



2006/11/26

Changing Mac OS X File Icons

I thought that, if you wanted to set the icon for a non-application file in OS X, you had to go through a convoluted process that involved copying the icon from another document. But it turns out you can just compose your icon with your favorite graphics tools, then copy and paste it into place.

For example, I wanted to change the icon on a QuickTime movie file. Here's what I had to do:


  1. Draw the icon graphics in OmniGraffle.

  2. Select the icon graphics.

  3. Edit->Copy (Command-C).

  4. Switch to the Finder.

  5. Select the QuickTime movie file.

  6. File->Get Info (Command-I).

  7. Select the document icon in the top left of the info window.


  8. Paste in the new imagery (Command-V).



Sweet!

2006/11/21

Lonely Planet finally discovers Kazakhstan

When we were preparing for Bobi's first adoption trip to Karaganda, we were surprised at the dearth of travel information for Kazakhstan. Even Lonely Planet seemed to know nothing of the world's ninth largest country.

Thanks in part to Sacha Cohen they're finally catching up.
Lonely Planet | On the Road.

2006/11/12

Midterms

Many of my friends are downright gleeful about the outcome of the mid-term elections. Some are registered Democrats who vote a straight party line (how can thinking people do that?), so of course they're happy. But even those of independent persuasion act as if they've steered our country onto a new course. I'm betting we've just jumped out of a Ford and into a Chevy, and have resumed driving down the same road.

Lemme try to persuade myself otherwise.

Good leaders can emerge from the two-party system. Harry Truman was a devoted Democrat who came to national politics by way of the Missouri political machine. Ironically, he was a student of world history who revered democracy. By most accounts he did good things for our country and for the world.

The two parties can effect change. In 1994 the Republicans took control of the House of Representatives. They had made a list of specific things they'd accomplish in the bargain. They delivered on one promise which most people could agree was good: they balanced the Federal budget.

(Granted, the budget didn't stay in balance long enough to make a dent in the national debt, and we're still going to be in a world of hurt when the baby boomers retire. But as a frustrated member of the Concord Coalition I was encouraged.)

It is still possible to choose representatives, not brands. From Doc Searls:

"Some of the best evidence of voter independence comes from the Lieberman election in Connecticut. Forget how you feel about the candidate. Look at what the voters did. They elected an independent candidate who had lost the primary of the party that 'won' the national race for seats in Congress. Something independent was happening there. It was bigger, and deeper, than partisanship. As Dave puts it, we've never had so much power."

Hm. Feeling a little better... Still, I'm going to set my expectations low. If this congress can weaken the Military Commissions Act of 2006 I'll call the midterms a success.

2006/11/10

Welcome to Mountain Standard Time

For her first 11 days in New Mexico little Aigerim had a really hard time getting to sleep. If somebody was awake and in the room with her she would squirm and play through the middle of the night, just as if it were mid-day. (Which, of course, it was, in Kazakhstan.) And if she were put in her crib? She would howl like a wounded beast. Didn't matter whether the lights were on or not. Of course she'd sleep soundly during the day.

This week we tried something different. I'd come over every morning at 8 to bring hot coffee to Mom and warm formula to Aigerim. Bobi would sneak in a quick shower while Aigerim topped off her belly. Throughout the day Bobi's mantra was, "Keep the baby awake," (except for one short nap).

It worked. Aigerim has slept through the night for four nights in a row. And she has been getting sleepy earlier and earlier. Last night she was lights-out by 8:30, which puts her almost on her Malutka schedule.

It helps enormously that she's bonding so well with Bobi. Before, unless she was totally exhausted, she would start crying the instant she touched the crib. Now she knows everything is okay. Mom is there for her, to sing lullabies and rock her to sleep, and again to greet her with hugs and kisses (and a bottle) in the morning.

The baby loves hanging out with us in the living room in the evenings, playing and grunting and making little babbling sounds. She gets so happy at our noises that she has to stand up, big tongue-lolling smile, and bounce vigorously for a few seconds. We know she's getting sleepy when her head suddenly plops down on the back of the couch, or on Mom or me. A few rounds of bouncing and plopping and she's ready to snooze.

It's pretty wonderful to see her happy again, just like the baby we met in Kazakhstan.

2006/11/09

Kazakhstan: Rules of the Road

Bobi and I live in Santa Fe, where many drivers seem to be either oblivious to their surroundings or just plain incompetent. But after a few weeks in Karaganda we realized how dull Santa Fe's driving is. Here are some rules of the road for Kazakhstan, as deduced from the back seat of an Audi.

Rules

Seat belts look stupid. Do not wear them.[1]

Horns are communications devices, not just blame throwers. A short "toot toot" means "I'm behind you / just to the left of you," or (when addressing a pedestrian) "I've just arrived to drive you somewhere". A short but full honk means "I don't care if there's oncoming traffic. Turn already." A long blast means "Thank you for stalling your vehicle on the road. Even though you cannot move, get out of my way!"

All vehicles have the right of way over pedestrians. Always.

A pedestrian within a cross-walk, if she or he will impede your motion, is a fair target for honking. If you can possibly squeeze through in front of the pedestrian, e.g. while turning right through a cross-walk, do so. Use short horn toots to further intimidate the pedestrian.

Almaty Amendment: If a pedestrian is within a cross-walk which has no dedicated traffic light, stomp on the accelerator and see if you can tap his or her kneecaps with your bumper.

If a pedestrian is walking away from you in an apartment courtyard, and if she or he veers within five feet of your intended lane of travel, honk at him or her.

Painted lane markers are for making the road pretty. Put the car any place that will give you the biggest advantage. If another driver might interfere with your plans, honk at him or her.

If you are at a red light but can see that the light may turn green within the next minute, start creeping into the intersection. If the light will turn green within the next 15 seconds, get a move on.[2]

Other Observations

Some cross-walks are displaced about 30 feet from the nearest intersection, and are equipped with their own traffic lights. This can be a blessing for pedestrians, as it means they need to expect danger from only two main directions.

There are lots of collisions on multi-lane freeways. We saw five or six accidents on the stretch of Gogol which runs past the Afghan war memorial. I'm not sure if they all involved left turns or not.

The preceding may imply that Karaganda roads are full of reckless drivers. But the situation is more complex. For example our driver, Vladimir, obeyed most of the rules noted above. But he also shifted gears much more smoothly than I ever will. And no matter how abrupt his initial braking needed to be in order to avoid a collision, he always modulated the brake pressure so that we came to a stop with no forward/backward bobbing of the head. In short, he was aggressive and good.



[1] Actually, I admire this "rule". Despite my exaggeration, seat belts are a personal choice in Kazakhstan.

I remember when seat belt laws were passed in Ohio, by then-governor Richard Celeste (D). He spoke at my university shortly afterwards and took questions from the audience. When asked why he had chipped away yet another personal freedom, the Governor explained that he had passed the weakest law possible. ("You can't be pulled over for not wearing a seatbelt, but you can be cited for not wearing one if you are pulled over for another reason.") And he explained that, if he had not passed some form of seat belt law, the Reagan administration would have denied highway funds to the state of Ohio.

[2] This is almost the exact opposite of the rule in Santa Fe. There, if the light has turned red any time within the past 15 seconds you should just keep going, la lala lala.

2006/11/08

Firefox 2.0 and display:inline-block

If you want to use <span> markup to define CSS-styled buttons with background gradients, and if you want to control the heights of those buttons, and if you are using Firefox 2.0, you have to jump through some non-standard hoops.

Firefox 2.0 doesn't support display:inline-block. If you have the Web Developer extension installed, it will report "Error in parsing value for property 'display'. Declaration dropped." And instead of getting a button with the right height for your background image, you'll get something silly looking, like this:



(I know, the colors look silly too. But that's not important right now.)

Yahoo! search turned up some background information, and a workaround for those who want to make links (<a href="...">) look like buttons:

NCZOnline - Pain with inline-block

Basically, you need to do this in your CSS:


.BtnClass {
display: inline-block; /* Firefox 2.0 ignores this */
display: -moz-inline-stack; /* Firefox picks this up */
}

The comments say that this bug has been logged in Bugzilla, and there's hope it will be fixed in Firefox 3.0.

Works for me with Firefox 2.0 and Safari 2.0.4, both on Mac OS X 10.4.8. Almost:



I'd like the span's text to be centered vertically on a background image.

Here's the cleanest solution so far. Suppose the background image is 24 pixels high and the font size is 14 pixels. Then, doing the vertical centering manually, the y offset is (24 - 14)/2 = 5px. So pad the top of the span by 5 pixels, and set its height to the total height minus the padding.

.BtnClass {
...
background-image: url(some_image.png); /* 24 pixels high */
font-size: 14px;
height: 19px;
padding-top: 5px;
}

In other words, add vertical padding to push the text down from the top of the span, then subtract that padding from the overall span height; apparently the final height of the span is height + padding-top + padding-bottom.

This works reasonably well for both Firefox and Safari.

2006/11/05

Fevers Help the Immune System

(Pardon the "duh" headline.)

Helpful fevers come in from the cold - health - 05 November 2006 - New Scientist

I found this article interesting mainly because I like to let my fevers run -- "bake out the infection". Works for me, but then I've never had a really high, convulsion-inducing fever.

Anyway, interesting tidbits from the article:

It has been found that fevers help the body’s immune system identify an infection and raise an army of white blood cells (lymphocytes) against it.

...[Researchers] artificially created a fever-like state in a group of mice... This had the effect of doubling the number of lymphocytes visiting lymph nodes...

Lymphocytes arriving at the nodes are screened for "killer efficiency" using fragments of potentially infectious material. Lymphocytes that respond to the fragments are found, are then selectively multiplied, and then swarm into the bloodstream to seek out and destroy the invader.


Apparently the extra heat of a fever activates high endothelial venule cells ("gatekeeper" cells, as the article calls them) in lymph nodes. They produce extra surface proteins that capture passing lymphocytes and draw them into the lymph nodes.

Evans says that although it fell out of fashion with the development of modern medicine, the idea of treating disease with heat has a long history: "Hippocrates used to heat patients with cancer," she says. And a century ago the physician William Coley discovered a cocktail of bacteria, dubbed "Coley's toxins", which appeared to combat cancer by producing a fever.

2006/11/04

Six Things Americans Should Know About Kazakhstan

From The Roberts Report on Central Asia and Kazakhstan comes a mini-lesson for geography class:


  1. Kazakhstan is a major oil producer and is assisted by U.S.-based companies in producing 1.5 million barrels of oil a day, with ambitions to raise this production to as much as 3.5 million barrels a day by 2015

  2. In its fifteen years of independence, Kazakhstan has not held one election that European observers could reasonably call “free and fair”

  3. Since 2000, Kazakhstan’s economy has grown at an average of 9% a year, and the U.S. trade volume with the country has doubled since 2004

  4. Kazakhstan continues to arrest opposition figures for political reasons, and two of its most vocal opposition politicians were found dead within the last twelve months under suspect circumstances

  5. Kazakhstan has a majority Muslim population with pro-western orientation, and its well-financed and sophisticated banking sector has the potential to be a critical foreign investor in such fragile states as Afghanistan, Kyrgyzstan, and Georgia

  6. The Kazakhstan government regularly violates the rights to free speech and assembly by strictly controlling its media sector and by continually harassing and curtailing the activities of opposition political parties.