May 24, 2008

here-documents in Perl

Drew Stephens @ 10:10 am — Tags: , ,

Here-documents are something that, once you know about them, you wonder how you ever got along without. I first learned about here-docs in Python many years ago, but didn’t know their proper name. In Python, you define a here document with three single or double quotes:

foo = """
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
mollit anim id est laborum.
"""

One day, when I wanted to put some large blocks of text amongst code, I searched for a way to do this in Perl and found the syntax:

my $foo =<< "EOF";
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
mollit anim id est laborum.
EOF

Note the use of quotes for the string-terminating sentinel (EOF, in this case, though it can be anything), which affects how the sting is interpreted. Just like with other strings in Perl, double-quotes mean that variables and escapes will be interpreted whereas they are ignored in single-quoted strings.

May 21, 2008

Gas v. Diesel and Energy Content

Drew Stephens @ 2:05 am — Tags:

Anyone who pays attention to the car world from an efficiency perspective has no doubt heard of the popularity that diesel engines have in Europe, but lack in the United States. Diesels post significantly better distance per volume of fuel (miles per gallon, furlongs per peck) than their gasoline counterparts. I’ve always wondered how much of this disparity can be accounted for by diesel fuel’s higher energy content. A quick search turned up some statistics (See table B-4) produced by Oak Ridge National Laboratory’s Center for Transportation Analysis which lists a gallon of diesel as containing 38.6 MJ per liter and gasoline as posesing 34.8 MJ/L. Not that big of a difference; gasoline has 90% the energy content of diesel.

How is this reflected in the mileage of a real car? Well, let’s look at a Volkswagen Jetta which, until recently in the US, could be had with a 1.8 liter gasoline engine or a 1.9 liter diesel. The gas engine gives 19 MPG city, 27 MPG highway for an EPA combined cycle of 22 MPG (VW Jetta 1.8L gas). The diesel gets 28 MPG city, 39 MPG highway and 32 MPG combined (VW Jetta 1.9L diesel). Working from the combined numbers, the diesel powerplant achieves 45% better mileage with fuel that contains just over 11% more energy content. Not a bad deal at all.

The next question is how this all works out for the environment. Historically, diesels have produced much more environmentally destructive exhaust containing more NOx and particulates. Recently, however, diesel fuel in the United States has been switched to an ultra-low sulfur variety which, in turn, allows for particulate emission control technologies to be employed, reducing the airborne matter released by diesel engines. Do the changes mean significantly cleaner emissions? I’m not sure, because the stats are difficult to find. Perhaps I’ll find them later.

May 16, 2008

A Failure of Logistics

Drew Stephens @ 11:07 pm — Tags: , , , , ,

Wiper blades from Amazon

Wiper blades from Amazon

My roommate ordered some wiper blades that Amazon had on sale. He did a single order and yet the blades came in two boxes, each easily large enough to fit both blades, even though the boxes shipped from the same warehouse.

May 13, 2008

Inventions

Drew Stephens @ 9:06 pm — Tags: , ,

If I had this kind of cash, I would be of the same opinion:

Myhrvold’s friends, like Myhrvold, seemed to be of the opinion that there is no downside to having a CAT scanner, especially if you can get it for twenty-nine hundred dollars.

The New Yorker has a very interesting article by Malcolm Gladwell, author of The Tipping Point about Intellectual Ventures, a company that does nothing but think up inventions. They occasionally call sessions to which smart people are invited to talk and come up with patentable ideas, hand them to lawyers and then sell the patents.

May 6, 2008

Installing Proggy Fonts in Ubuntu

Drew Stephens @ 3:56 pm — Tags: , ,

I don’t recall how I came across the free Proggy font family but I wanted to try them out on my Ubuntu workstation for use in Eclipse. After some searching, I figured out how to install TrueType (.ttf) fonts and the process is pretty straightforward. I downloaded and unpacked the fonts into ~/.fonts, created a fonts.dir metadata file, added them to the font cache and when I restarted Eclipse, they were available.

~$ mkdir .fonts
~$ cd .fonts
~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggyCl
ean.ttf.zip
~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggySq
uare.ttf.zip
~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggyS
mall.ttf.zip
~/.fonts$ ttmkfdir -o fonts.dir
~/.fonts$ fc-cache -f -v

Powered by WordPress