Thursday, January 31, 2008

doc2pdf

We all know that there are lots and lots of reasons to use the command line. But sometimes, believe it or not, there's a GUI program that does something that's not available as a command line utility.

Yet you want a command line utility, because you've got to do this thing 20-30 times, and sitting there clicking with the mouse is just boring.

So what'dya do? You hack the GUI program to do what you want it to do from the command line.

Let's back up a bit: Baen Books, the SF publishing house, has a long history of giving away its books. There's the online Baen Free Library, and every once in a while they'll put a CD full of old titles in the back of a book. You can copy this, give it to friends, use the copies for Frisbees at a warez convention, whatever, just so long as you don't sell them. The disks have several recent books, and, though I'll never claim that Baen's writers are in the class of Lois McMaster Bujold (well, she does have one book in the library) or Terry Pratchett, there's a satisfying bunch of science fiction and fantasy mind-candy that can be downloaded onto a computer and read on the plane or in one of those cheap hotel rooms that physicists crash in when we're at a meeting.

Baen puts the books out in all sorts of formats: HTML, DOC, RTF, Palm, Kindle, etc.

Everything except PDF.

Why, I don't know. PDF is compact, can be read on every computer of every kind, leaves the text exactly the way you want it. It just makes sense to distribute electronic books that include images in PDF format.* Yet Baen doesn't.

So last week I got hold of the disk in the back of Eric Flint and David Weber's% 1634-The Baltic War (the online version is only the first few chapters, alas). The disk has maybe 30 novels, some of which I actually want to read, some of which I'll read in a pinch, and all of them in the aforementioned everything-except-pdf formats.

The question before the house is how to convert all this mind-numbing SF into PDF files. The obvious way is to take the Word (.doc) or RTF version of the file, load it into OpenOffice.org, and hit the Export PDF button. A GUI solution, no doubt.

Given that it takes a few minutes to convert each novel, that's a really boring task. So let's look around for a command line solution. A look at the web shows that there aren't too many — make that there aren't any, in the sense that there is no open source, standalone, Linux command line program which takes a Word file and converts it into PDF.

There is, however, a way to do it. OpenOffice.org has a powerful Macro/scripting program included, and ways to call the scripts from the command line. All you need is the script.

Hey, don't look at me. I borrow, mostly, and point you to where I've done the borrowing. In this case, it's Convert MS/Word to PDF, posted by Graham Williams. He gives complete instructions for setting up the Macros and writing a short shell program to call them.

The only caveat is to heed Williams when he tells you that doc2pdf calls OpenOffice.org and then quits: it takes 5-10 minutes to convert one of Baen's novels to PDF, so if you want to do a batch job you need to put a long sleep time between calls of the shell command. Best to start the thing off at night and check it in the morning — just what you want a batch job to do, anyway.

So add one more command line tool into your kit, and good reading.

* It makes sense to distribute text without pictures as an ASCII file, but Baen doesn't do that, either. Well, I wasn't expecting the Moon, you know.

% I'm not a big fan of Weber's style of writing. Here's why. For some reason I keep going back to check the books out of the library, though. If I found myself paying for them I'd be really upset with me.

The RTF and DOC files are bitwise identical. This says something about someone. I'm not sure what, or who, though.

Capturing Sound – or – a Case of Daemonic Possession

The long-time reader will remember that occasionally I record onto the computer. Usually using Audacity, but for many purposes gnome-sound-recorder does well enough.

Except when it doesn't. So I've been sitting here for the last two hours trying to figure out why, when I plug the tape deck into the line-in jack, start the tape, and press record, I don't get anything to record, even though I can hear the sound coming out of the computer's speakers, and even though things have worked in the past.

So after much searching, playing with JACK, tearing out my hair, yelling at the cats, etc., I finally found an appropriate post in Ubuntu forums. Note particularly the phrase “I had the Capture volume down.” Turns out I haven't done any sound recording since I upgraded to 7.10. Does Ubuntu automagically reset defaults when you upgrade? Anyway, following this post, I opened up the gnome-volume-control, clicked on Edit=>Preferences, clicked on line-in capture, and hit record.

Nothing.

OK, go back to the preferences menu. Look down. See an unchecked box labeled Capture. Click that.

Nada.

Sigh. But now the main gnome-volume-control panel has a tab on it that says “Recording.” Click on that. Up pops a panel that says “Capture,” with the Microphone symbol muted. Click that. Bring the capture volume up to full. Record.

It works.

HOW DID THIS HAPPEN? I had it all working before, you know, which meant that all those appropriate boxes were checked and buttons were pushed. AGGGH! Are there little elves running around my computer arbitrarily turning things on and off?

Well, anyway, I got it working, and this here post will remind me of it the next time it happens.

Tuesday, January 29, 2008

Economic Theory

So the House, at least, has agreed with the President to give each and every one of us a big gob of money.

When I heard this, for some reason I was compelled to look up the following (thanks, Google Books) and type it in:

“Since we decided a few weeks ago to adopt the leaf as legal tender, we have, of course, all become immensely rich.”

Ford stared in disbelief at the crowd who were murmuring appreciatively at this and greedily fingering the wads of leaves with which their track suits were stuffed.

“But we have also,” continued the Management Consultant, “run into a small inflation problem on account of the high level of leaf availability, which means that, I gather, the current going rate has something like three deciduous forests buying one ship's peanut.”

Murmurs of alarm came from the crowd. The Management Consultant waved them down.

“So in order to obviate this problem,” he continued, “and effectively revaluate the leaf, we are about to embark on a massive defoliation campaign, and ... er, burn down the forests. I think you'll all agree that's a sensible move under the circumstances.”

— Douglas Adams, The Restaurant at the end of the Universe

Sunday, January 27, 2008

The Changing Tag Line

By now all three of you have probably realized that I like things to change every once in a while: random wallpaper in GNOME or FVWM, random quotations in the Blog, etc. Heck, if I can figure out how to do it, eventually this blog will have a rotating template as well.

The latest bout with randomness is the tagline at the top of the blog. It was inspired by this hack from Stéphane Hamel. I couldn't get that version to run here, possibly because Blogger has changed a bit since the beta version, but I was able to lift Blog U's random quote generator to get the same effect.

So here's the final version of the hack:

  • Log onto the Blogger Dashboard
  • Select Layout => Template => Edit HTML
  • Download the full template: Because you will frak it up.
  • Click the box that says “Expand Widget Templates”
  • Look for the second invocation of the string <data:description> — at least that's what I had to do.
  • Replace the line
    <p class='description'><span><data:description/></span></p>
    by the following
    <p class='description'>
    <script language='JavaScript'>
    //store the quotations in arrays
    quotes = new Array(5);
    quotes[0] = &quot;First Quote&quot;;
    quotes[1] = &quot;Second Quote&quot;;
    quotes[2] = &quot;And So On&quot;;
    quotes[3] = &quot;Changing the number in Array to match the number of quotes&quot;;
    quotes[4] = &quot;and noticing that the array starts with [0]&quot;;
    //calculate a random index
    index = Math.floor(Math.random() * quotes.length);
    //display the quotation
    document.write(&quot;\n&quot;);
    document.write(quotes[index]);
    //done
    </script>
    <noscript><data:description/></noscript>
    </p>
  • Save everything

Note that I've never been able to get this script to accept more that 10 quotations. If someone can tell me why, or how to get around that, I'd be grateful.

Wednesday, January 23, 2008

Heißen Sie Mehl?
Want People to Know That?

At work there's a picture of Robert Franklin Mehl hanging in the conference room. Since my office is right across the hall, with my name prominently displayed, I'm often asked “are you any relation?”

The answer is, regrettably, no. There are currently 2,461 people in the U.S. with the last name Mehl. As far as I can tell, about two hundred of them are descended my great-great grandfather, whose children came here around 1880 and settled in Kansas (didn't you guess?) and Indiana (surprised the heck out of me).

That leaves 2,261 or so unrelated Mehls. That's not too surprising. The literal translation of Mehl is “flour.” I suspect the Mehls were just people who worked with wheat or bread and didn't want to be called Mueller. Thus the various groups of Mehls came from all over the German-speaking part of Europe, and are mostly unrelated.

After being asked so many times about my relationship to Robert, I decided to make a little list. It's a list of people named Mehl, and I'm not related to most of them.

You'll notice the list is a bit old. I haven't updated it in some years. Now that I have the new website, I'd like to put up some new names.

So: If

  1. Your last name is Mehl,
  2. You have some web presence I can link,
  3. You aren't on the list, and
  4. You'd like to be on the list,

Send me an email at the address on the right. I'll put your name up in weblights forever, or a reasonable approximation thereof.

Note: Though labeled as such, this isn't a really genealogy post. If you last name is Mehl, it's possible, but unlikely, that we're related. It's just for fun.


HowManyOfMe.com
LogoThere are
32
people with my name
in the U.S.A.

How many have your name?

Monday, January 21, 2008

Ranking Science Fiction Characters

A colleague recently introduced me to Google Fight, which let's you stage bouts between your favorite web celebrities based on the number of hits Google gives them.

Well, sort of. For example, if you take the two predominate figures of the longest-running science fiction franchises on US television, Google Fight gives you:

James T Kirk: 296,000 results
Jack O'Neill:      24 results

which is obviously screwy. Going to Google its own self gives you:

James T Kirk: 389,000 results
Jack O'Neill: 573,000 results

which is in some ways even screwier: is the Star Trek franchise so dead that its leading hero gets beat out by MacGyver? (4,870,000 hits, though “Angus MacGyver” gets 29,400)

Anyway, this led me to the task of ranking leading science fiction characters by real Google hits, not Google fight hits. Below are my results, feel free to add to them. The rules are:

  1. The Google search string must include the common name of the character, along with a name that distinguishes the work in which the character appears. Thus we'll search for “James Kirk Star Trek“ to distinguish Tiberius from the actor of that name.
  2. There are no quotation marks in the search string.
  3. Yes, I did search Harry Potter Harry Potter
  4. The rank will be the number that appears after the string “Results 1-10 of” on Google, i.e., we'll use the first count Google gives us.
  5. If you don't recognize the characters here, don't whine about it, just Google them. The choice of characters says more about me than you anyway.
  6. Don't give me any grief about using “Benjamin Sisko” rather than “Ben Sisko” either.
  7. If you don't like my definition of Science Fiction, well, frak.
  8. No, I don't know why the Kirk searches above and below disagree so strongly. Ask Google.

And the results:

Character Work Hits Comments
Harry Potter Harry Potter 10,400,000 You expected different?
Luke Skywalker Star Wars 2,870,000 The Force is strong in this one.
Han Solo Star Wars 2,370,000 Not bad here, either.
Hermione Granger Harry Potter 2,150,000 Even Ron likes Harry better than you, Hermione
Albus Dumbledore Harry Potter 1,260,000 Wonder how many hits are from this fall?
James Kirk Star Trek 916,000 The Captain Supreme
Death Discworld 792,000 HOW INTERESTING
Gil Hamilton Known Space 769,000 A very long arm
Lazarus Long Future History 730,000 Still read Heinlein, I see
Teal'c Stargate 539,000 Kree!
Spock Star Trek 452,000 That I am behind a gold-tattooed alien is not logical.
Daniel Jackson Stargate 368,000 Needs to Ascend again
Lucas Garner Known Space 337,000 Old codgers do all right here
Neo Matrix 335,000 Young twerps, too.
Jean Luc Picard Star Trek 280,000 Was ahead of Teal'c until the latter stopped shaving is head.
Jack O'Neill Stargate 257,000 It's a lot worse with only one L.
Trinity Matrix 257,000 Apparently chicks in leather don't do as well as you'd think
Kathryn Janeway Star Trek 238,000 Well, better than this, thank God.
R2D2 Star Wars 209,000 The highest-rated robot
Samantha Carter Stargate 168,000 Should have done nude scenes when they were on Showtime
Adama Battlestar Galactica 149,000 About half-and-half.
Benjamin Sisko Star Trek 132,000 Deep in your heart, you know he was the best Captain
Miles Vokosigan Vokosigan 103,000 Short smart punks apparently don't score as well as tall dumb Colonels.
Rincewind Discworld 67,700 Wizzards are soon forgotten, especially if they don't get any new book deals.
Samuel Vimes Discworld 39,900 Cops, too.
The Luggage Discworld 37,100 But it does iron your shirts.
Granny Weatherwax Discworld 33,800 Apparently being Good and Right doesn't make you popular, either.
Corwin Amber 37,800 Obviously in the wrong shadow.
Hari Seldon Foundation 35,400 Don't worry, his name is all over this one Encyclopedia.
Fafhrd Lankhmar 15,000 I guess swords aren't all that popular these days.
John Falkenberg Falkenberg's Legion 10,100 Johnny Christian, we hardly knew ye.
Dominic Flandry Flandry 9,580 Maybe I'm showing my age.
John Grimes Rim Worlds 9,200 You think?
Gray Mouser Lankhmar 8,960 Undoubtedly.
Louis Wu Ringworld 6,130 Boosterspice, Louis baby, Boosterspice
Kimball Kinnison Lensmen 1,020 Mentor might not like this.
R. Daniel Olivaw Robot 1,010 Robots of Doom, indeed.
Nessus Ringworld 548 Two brainless heads are apparently not better than one.
Tela Brown Ringworld 73 Heading this list must be unlucky.

And, as I said before, add your contributions below.

Sunday, January 20, 2008

The New Design

The three column template used here comes from Webtalks. (The link is repeated at the very bottom of the page as well.) I've wanted a three column design for some time, but hadn't bitten the bullet because when you go to an externally designed template Blogger deletes most of your widgets. I've restored some of the widgets, added an almanac/weather feature, and made minor changes to the Blogroll. Now that I've got my own domain/webspace, perhaps I'll consider moving to whole thing to WordPress or some such. Time will tell, I guess.

Saturday, January 19, 2008

New Home on the Web

I've pretty much completed the move of my files from my defunct Comcast account* to my new, mostly free domain, www.rcjhawk.us. Links in the sidebar that pointed to Comcast now point to the new domain. I've changed all the links in the body of the blog that I've found, but there may be some I've missed. If you find one, please email.

Letting Awardspace host my account for free puts a few quirks into the system that I didn't expect. They aren't too onerous, but if you're tempted to sign up with them, don't say I didn't warn you:

  • First, they wanted to call me up and have a conversation before they'd unlock the website. I expected they would try to set me up with one of their higher-price services, but they didn't. In fact, the conversation was quite pleasant. I guess they just wanted to be sure that I wasn't a spam-bot.
  • You can use ftp to transfer files, but you need to be in passive mode. The easiest way to do this from the command line is to invoke the ftp client with:
    $ pftp
    Also, they timeout after 60 seconds, which is annoying, because:
  • You never know whether or not your web page is going to display until you test it. Awardspace has a list of “forbidden words,” which are, of course, unposted. If your file doesn't pass the guidelines then trying to view it takes you to the Awardspace homepage. (It also gives you a 403 error, but you don't see that unless you use a browser such as lynx.) Looking at their forums I see that p o r n is forbidden. OK, I see the point. It's a free web account, and the company doesn't want to get into trouble. But why do they censor something like a link to

    Google Mail (http://gmail.google.com)?

    Yeah, it's not technically the correct site, but it redirects to a rather well-known address.

    And it similarly rejects

    http://www.amazon.com/gp/product/159327064X/qid=1134831000/sr=2-1/ref=pd_bbs_b_2_1/104-0433773-2563904?s=books&v=glance&n=283155, which is a link to the book Just Say No to Microsoft.

    What's really annoying is that they don't tell you what part of your page is offensive, you have to do a bunch of trial uploads to find it yourself.
  • Oh, yes, they also block mp3 files. Even innocent ones. Well, again I can see why, but ten-second or less snippets shouldn't bother anyone, and, as you can see, they allow the sounds in ogg format.
  • If I were a conspiracy theorist I could give you a hundred reasons for this behavior. However, I realize that they're giving me the web-space for free. If I wanted to remove the limitations, I could pay for the site. Even their $5/month plan has fewer restrictions, and I could use scp to copy files over. But at the moment I don't need that, and $60/year buys a half-dozen paperbacks. So I'll put up with it, at least for now.

So would I recommend Awardspace to anyone else? Well, for now it works for me. Next month it might not. I'll keep you up to date, but in any case your mileage may vary.

* You had to try it, didn't you?

$19.95 per year for the domain registration, “but wait — there's more!”

Sunday, January 13, 2008

Under Construction

Comcast finally pulled the plug on our account this week. They were actually pretty nice about it, giving us about a month of email forwarding and web space after our defection to Verizon. Heck, I may switch back to them when our contract is up in two years (hey, folks, we've got competition in the cable TV and high-speed Internet market — enjoy it while you can).

With the account turned off, some of the links on the right-hand side of the blog will be invalid, and some of the pictures in the blog will probably disappear. (I moved as many as I found onto Blogger its own self, but I probably missed a few.) I'm working to restore the links. I even have my own domain, now: http://www.rcjhawk.us. You'll note the home page is pretty much like the Comcast one, but not all of the links are live as yet. I'll try to get everything pretty much back the way it was during the upcoming three-day weekend.

I should say that the Verizon FIOS service has been pretty good so far. Only two glitches. One, the wireless connection has gone down three-four times, sometimes for an hour or more. This might be neighborhood interference. Two, for some reason I can't play streaming audio of Prairie Home Companion via mplayer, even though I can play it using Real Player. This might be a bug in my mplayer setup, but it started immediately after we switched. Something to be tracked down ...

Wednesday, January 09, 2008

Another Stupid Ubuntu Trick

I could write a post that mentioned that at least three teams in the Big 12 could have played as well as Ohio State did in Monday's game.

But that would be whining. It's not whining to note that KU has the best record among all the BCS football schools.

But I digress. Following the last post, here's another oddity in Ubuntu's implementation of vim. In most modern versions, when you open a file your editor immediately transports you to the last line you edited — great if you're doing a series of computer runs where only a few lines of input change. By default this trick doesn't work in Ubuntu. To change this behavior, go to /usr/share/vim/vimrc and uncomment the lines that read

if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif

If you don't want to do this globally, or don't have administrative access, add the lines to your ~/.vimrc file.

Monday, January 07, 2008

Stupid Ubuntu Tricks

One of the reason d’etre for a blog like this is to record hacks that make software work the way I want, rather than the way some software developer thinks is best. If I was a Windows drone I'd be doing the same kind of thing, except that the blog would have a lot more posts and a ton more whining.

Anyway, one of the irritations of Ubuntu, as opposed to other Linux distributions I've used, is the lack of file-name completion in the vim editor and in gnuplot. If you don't know, file-name completion allows you to start typing the name of the file, and then hit tab to complete the file-name, or to cycle through a list of file names. It's extremely useful, and in most Linux distributions is based on calls to the GNU readline library.

The default Ubuntu distribution has a vim editor and gnuplot with the file completion mode disabled. This annoyed me, but not so much that I was prompted to do something about it until we started installing Ubuntu at work. So today I did a little web searching and found that the lack of support has different causes for the two programs:

  • vim: Ubuntu installs vim-tiny by default. That's fine, if you want to save space, but all of the neat features of vim are in vim-full, which has all the bells and whistles.
  • gnuplot: I've tried to fix this before by compling gnuplot from source, but the problem is in Ubuntu's implementation of the readline library. We need a work-around, a program called rlwrap, which force-feeds file-name completion to gnuplot or other misbehaving programs.

So to fix both problems at once, install the appropriate files:

$ sudo apt-get install vim-full rlwrap

vim is fixed, as vim-tiny has been replaced by vim-full. For gnuplot, we need one more step. Add

alias gnuplot "rlwrap -a -c /usr/bin/gnuplot"

to your ~/.cshrc file, or

alias gnuplot='rlwrap -a -c /usr/bin/gnuplot'

to your ~/.bashrc or ~/.bash_aliases file.

And two programs, at least, work the way I want.