Posted by Tom Moertel
Fri, 13 Aug 2010 04:38:00 GMT
For those of you who use Emacs, Git, and Fedora Linux, I have just pushed emacs-magit-0.8.2 to updates-testing. (This package brings the wonderful Magit mode for Emacs to Fedora). For now, you can install it with yum by enabling the updates-testing repo:
sudo yum install emacs-magit --enablerepo=updates-testing
Posted in programming
Tags emacs, fedora, git, magit
no comments
no trackbacks

Posted by Tom Moertel
Fri, 16 Jul 2010 14:56:00 GMT
Text documents come in two basic flavors: text editor and word processor. In the text-editor flavor, a document is represented by lines of text, each ending with a line break. Paragraphs are separated by two breaks. In the word-processor flavor, there are no line breaks, only paragraphs (because word processors will “wrap” lines of text as you edit them).
If you need to convert from text-editor flavor (lines) to word-processor flavor (paragraphs), here’s a handy Perl one-liner that will do it:
perl -lp00e's/\n/ /g' input.txt > output.txt
If you’re editing in Emacs, you can convert a selected region of text using the same one-liner via shell-command-on-region:
C-u M-| perl -lp00e's/\n/ /g' RET
To go the other way, from word-processor flavor to text-editor flavor, the Unix command-line tools fold(1) and fmt(1) do the job.
Tags emacs, perl, text
3 comments
no trackbacks

Posted by Tom Moertel
Thu, 24 Jun 2010 19:59:00 GMT
Recently, I discovered an interesting flaw – or is it a feature? – in
Amazon.com’s marketplace.
It all started when I bought economist Albert O. Hirschman’s Exit, Voice, and Loyalty. I had been reading an old printing from
the library, but it was riddled with highlighting; now I wanted a
clean copy to read without distractions.
On Amazon.com, I found exactly what I wanted. A third-party seller
had listed a new copy for just $6.50. I bought it.
Shortly after the order, Amazon sent me an email confirming that my
book had been shipped. In the email, the book was described as
follows:
Exit, Voice, and Loyalty: Responses to Decline in Firms, Organizations, and States
Sold by: XXXXXXX
Condition: new
Quantity: 1
$6.50 each
Here’s where things get interesting. Around the time I received the shipment notice, I also received a cryptic communication from the seller:
I wish I had a pristine copy to send you but, while this
book has wear at its front, I am confident it will serve you well, as
it served me.
I didn’t think much of it until I received the book a
week later. The book was, of course, riddled with highlighting.
Confused, I went back to Amazon.com to figure out what went wrong. I
logged in, clicked on the order listing, and was shown the following
summary of my order:
1 of: Exit, Voice, and Loyalty: Responses to Decline in Firms, Organizations, and States [Paperback]
By: Albert O. Hirschman
Condition: Used – Good
Sold by: XXXXXXX (seller profile)
Note that the condition is now listed as “Used – Good”, not new as it
had been when I placed the order. Amazon allowed the item I
had ordered to be changed after I had ordered it! What’s
worse, Amazon now lists the changed item on the final invoice for the
purchase.
In effect, Amazon has rewritten the history of my order. It’s as if I
had ordered a used copy of the book in the first place. I’m lucky I
kept that original email! Without it, how could I document what I
had actually ordered?
Like most people, when I order something online, I expect that
clicking the order button forms an implicit agreement between buyer
and seller: in exchange for my money, the seller will deliver the
product that I ordered, as it was represented to me when I placed the order.
That Amazon allows this agreement to be rewritten – behind the
buyer’s back – seems like a huge flaw in its marketplace. It’s such
an obvious flaw that I have a hard time believing it exists. Amazon
is very good at the buyer-experience game; if it allows this “flaw” to
exist, my hunch is that there must be a good reason for it. The
trouble is, I can’t think of what that reason might be.
But my hunch is made more plausible by Amazon’s A-to-z
Guarantee. Knowing
that the guarantee will protect customers affected by the flaw gives
Amazon the option of not fixing it. My guess, then, is that Amazon’s
engineers thought about fixing the “flaw,” discovered a good reason
not to, and decided to leave it alone.
Which raises the question, what is a compelling reason to allow a
buyer-seller agreement to be changed after the fact and behind the
buyer’s back?
Posted in books
Tags amazon, buyer, contract, marketplace, seller
4 comments
no trackbacks

Posted by Tom Moertel
Thu, 10 Jun 2010 15:20:00 GMT
I recently started using two handy variants of top, the standard Unix tool for monitoring what’s going on with processes on a system.
The first, htop, uses ncurses to provide a more interactive process-viewing experience. You can surf through running processes, scrolling horizontally and vertically to reveal information that would otherwise have been clipped, information such as full command lines. Further, you can drive a cursor to select processes for commands like kill and lsof to act upon. Yes, you can see what files a process has open; you can even trace processes using strace. There’s also a handy tree view for understanding process ancestry.
The second top alternative, atop, offers more accurate accounting of processes and resource usage. It tracks all processes, even those that have lived out their brief lives between atop’s screen updates. This comprehensive accounting is helpful for understanding problems caused by herds of individually short-lived processes. With the old top, you might catch only a few of the processes in the act, but with atop, you can see the herd for what it is.
Two handy tools – check them out.
Posted in sysadmin
Tags atop, htop, sysadmin, top
1 comment
no trackbacks

Posted by Tom Moertel
Fri, 08 Jan 2010 05:15:00 GMT
One of the projects I’ve had
in the back of my mind for a few years is a formal language for
recipes. Professional bakers have long used
formulas
to express the core of their recipes. And with Michael Ruhlman’s
Ratio:
The Simple Codes Behind the Craft of Everyday Cooking
being so well received by geeky home
cooks, it seems the time may be right to start hacking away.
As a brain dump, here are some syntax ideas I’m playing with. (BTW, if you want to learn how to make a pie from scratch, here you go. Use butter or lard for the fat if you’re serious about pie.)
-- classic recipe for 3-2-1 pie pastry
pie_crust:
3 flour
2 fat, cold
1 water, ice cold
yields 1 dough -- (optional: default result is final item)
flour_fat_mix:
flour
fat
"cut fat into walnut-sized pieces"
"combine in chilled bowl"
"mix until fat is pea sized"
dough:
flour_fat_mix
water
"add water while mixing gently"
"stop when shaggy dough begins to form"
"gently shape dough into portioned rounds by hand"
"wrap portions with film-wrap"
"refrigerate"
-- pie, which uses the crust recipe above
pie_9_inch:
24 oz pie_crust, chilled
1 pie_tin, 9 inch, chilled
1 filling, enough for 9-inch pie
yields 1 pie, 9 inch
bottom_shell:
pie_crust
pie_tin
filling
take pie_crust, 13 oz, "portion dough"
"roll into 11-inch round"
"line pie tin with dough"
"add filling"
top_shell:
pie_crust
take pie_crust, remainder
"roll into 10-inch round"
pie:
bottom_shell
top_shell
"top the pie, sealing edges well"
"trim excess dough from edges, decorating if desired"
"cut vent hole(s) in top"
"refrigerate for at least 30 minutes to set dough"
"bake at 425 degrees F for 15 minutes"
"reduce oven to 350 degrees F"
"bake until done, about an hour"
Posted in programming languages
Tags baking, cooking, languages, pie, recipes
13 comments
no trackbacks

Posted by Tom Moertel
Thu, 23 Jul 2009 19:50:00 GMT
Recently there has been a lot of talk about “magic” in software. Most of the people doing the talking, however, seem to be talking past one another, primarily because they do not share a common understanding of what “magic” means. The few definitions of the term I have seen seem to miss something essential, so I will provide the definition that I think makes the most sense:
In a software system, magic is any behavior whose semantics are poorly defined and unduly expensive to figure out.
Some notes:
- The “unduly expensive” part means that people with different background knowledge are going to find different things magical. If you use certain techniques every day, you will probably find behaviors that make use of those techniques easier to figure out and thus less magical than other programmers might.
- One way, then, to make things less magical is to exhort programmers to get more knowledge. A more practical approach, however, appears in the next point.
- Most “magic” can be de-magicked simply by defining its semantics.
So when I complain about magic in a software system, I am complaining about code whose behavior is not readily discernible. When I did a lot of Rails programming, for example, I always gnashed my teeth when I encountered a function in the Rails API that took a string but did not make clear what that string was supposed to represent. Was it text? Was it HTML? There was only one way to find out: trace through layers of Rails code to figure out what the framework actually did with the string. That is unduly expensive, so I considered such functions to be magic – annoying, waste-my-time magic.
I do a lot more Python programming these days, and while I encounter less magic, I am mystified by the part of Python culture that turns its back on code that is perceived as being overly clever or, to use the popular phrase, not explicit. What is wrong with cleverness, as long as the result is clearly understood? Cleverness, by itself, is not magic. For real magic, you need fuzzy semantics, too.
That is why, when I hear that code is “magical” or “too clever,” I think “poorly defined.” If you define and document the semantics of such code, you dispel its magic. And if you cannot define the semantics, then the code is magical and too clever, and probably ought to be rewritten.
Thus the test for whether something is magical is the clarity of its semantics. Code having clear semantics is not magical. Code having unfathomable semantics is.
Posted in programming
Tags clarity, cleverness, definitions, magic, programming, semantics
10 comments
no trackbacks

Posted by Tom Moertel
Sun, 05 Jul 2009 16:42:00 GMT
It seems that every time I upgrade Fedora on one of my workstations,
anaconda somehow manages to screw up the bootloader configuration,
and when the upgrade is “complete” and the system reboots, I’m
left starting at a GRUB prompt. So this is a little note to myself
for how to fix the broken configuration. (If you find my note helpful, great, but if you try anything in it, you do so at your own risk.)
First, find out where GRUB thinks the /boot partition is:
grub> find /grub/grub.conf
find /grub/grub.conf
(hd0,0)
(hd1,0)
Here, GRUB found two potential /boot partitions, which is actually
correct because I keep /boot on a RAID-1 md device and GRUB is
finding the device’s underlying partitions.
Next, tell GRUB to use the desired /boot partition as its root device:
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
Finally, tell GRUB to set itself up on the hard drive that contains the partition (which, for my workstations, is the correct place):
grub> setup (hd0)
That’s it, all done.
At this point, you can tell GRUB to “boot” using the configuration or “reboot” from scratch to test the configuration from a system restart.
Posted in linux
Tags fedora, grub, linux, note, self, sysadmin, to
1 comment
no trackbacks

Posted by Tom Moertel
Tue, 30 Jun 2009 02:57:00 GMT
I recently purchased a Kindle DX, mainly to read PDF documents that contain math and comp-sci formulas. Still, I couldn’t resist the temptation to try out the instant gratification of purchasing a “Kindle edition” ebook, so I ordered a sci-fi novel I had read as a child, Alan Dean Foster’s The Tar-aiym Krang.
The Good
The purchase and download via the ever-so-branded “Whispernet” wireless network went without a hitch. The Kindle DX, itself, was great and made reading easy. The text looked good, the navigation seemed intuitive. There was just one problem.
The Bad
The production standards of the content destroyed any chance of convincing me that I was reading something akin to a real book. I found numerous typographical errors, something that just doesn’t occur in real mass-market books, which have been subjected to professional review after typesetting. By far, the most common error was the substitution of a left open single quote for what should have been an apostrophe, an error that I don’t think Amazon missed an opportunity to make. For example, when shortening computer to ’puter:
The brilliant fix (no need to thank me, Mr. Bezos)
So, if you’re Jeff Bezos, you’re probably wondering what you can do to improve the quality of Kindle edition books. After all, you spent all that time, effort, and money on the Kindle itself, getting the look and feel just right, crafting the perfect book-reading experience, even insisting upon seamless “Whispernet” downloads to encourage impulse purchases of Kindle editions. You certainly wouldn’t want the content owners, the lovely folks who supply you with typo-ridden source documents, to undo all that you have worked so hard to achieve with the Kindle, to destroy the immersive, luxurious reading experience that you are so close to delivering, to unweave the spell that convinces readers that the Kindle is just as good as – if not better than! – a real book. Somehow, you must fix the content problem, but you know, you just know, the content owners are going to screw it up for you.
So, here’s what you do, Jeff. Let the content owners screw it up – you know that’s what they’re going to do, anyway – and fix the errors yourself. How? With an army of focused, motivated proofreaders: your customers!
Seriously, this idea would work miracles for you, Jeff. You know how the Kindle lets you make annotations to the Kindle editions you read? Just extend those annotations to include corrections. Then when those annotations are saved to Amazon’s servers, extract the corrections, combine them with the corrections from other readers, maybe verify them with a quick third-party review (a perfect job for the Mechanical Turk, wouldn’t you say?), and then automagically distribute the relevant, approved corrections to every Kindle reader who could benefit from them. Further, to make your readers happy that they found mistakes in the Kindle editions that they purchased, offer them a bounty, say 25 cents, for the first report of each correction found.
In one fell swoop, all your problems with production quality are fixed:
- customers who find errors are no longer angry but happy
- most Kindle editions will be corrected quickly, ensuring a blemish-free reading experience for the bulk of your customers
- even if the content owners give you garbage for source documents, and even if they won’t allow you to change those documents one iota (they are pretty controlling, after all), you can still deliver perfection to your customers: apply corrections on the “client side,” correcting the pristine, yet error-filled source material, on the fly, right in the Kindle itself
And there’s one big bonus I didn’t mention. This capability would make Kindle editions better than real books. Not just marketing-copy, in-theory better, but really better. As in, now we have a compelling reason to switch from paper: to get the benefits of collaborative, peer-augmented reading and correction, in which each reader’s contributions enrich the reading experience for all who follow. Think about it, Jeff, it’s a big deal.
No need to thank me.
Posted in reviews
Tags amazon, bezos, books, kindle, peer, reading, review
4 comments
no trackbacks

Posted by Tom Moertel
Fri, 22 May 2009 05:59:00 GMT
I know, the economy sucks, and everything is expensive these days. It’s even worse for you, a polyglot programmer with a serious programming-language obsession. You prowl Proggit, lounge at LtU, and occasionally step on over to Stack Overflow. But it’s just not enough. You need more. You need to hang out in meatspace with other fascinating programmers, diving into modern object systems, getting mechanical with crazy VMs, hacking on code like the wild code-hacking beast that you are.
Sure, it’s a nice dream and all, but how are you going to make it happen? And even if you could in theory make it happen, how could you afford to do it now, in this down economy?
Well, my friend, let me share a secret: You can make it happen. And you can afford it. Here’s how: Just be at the 10th Anniversary Yet Another Perl Conference. It’s day upon day upon day of jam-packed programming-language goodness of all sorts, not “just” Perl – and this year it’s the one conference you can afford.
Seriously, I did a little price-checking, and YAPC is about the most underpriced programming-fest on the planet:
| Conference |
Price |
| JavaOne |
$1,995 |
| RailsConf |
895 |
| PyCon |
450 |
| RubyConf |
200 |
| YAPC |
125 |
Wait, you’re not into Perl? No problem. The Perl community has always embraced diversity, and there’s a lot more than just Perl at YAPC. Check out the tag cloud for talks and you’ll see what I’m saying. At YAPC, the good stuff comes in enormous buckets, plenty for programming aficionados of all stripes. Here’s a taste:
- There’s the Parrot Virtual Machine Workshop. That’s right, YAPC comes front-loaded with a thunderous, 2-day, under-the-hood hackfest, all devoted to a modern VM – Parrot – that’s optimized for your favorite dynamic languages.
- You’re serious about keeping track of your code, right? Well, YAPC’s got talks about Git, too.
- Into objects? Then consider a barrel of talks about the Moose object system, which builds upon great ideas from Perl 6, CLOS (of LISP fame), Smalltalk, Java, BETA, OCaml, and Ruby – and sports roles, delegation, and a meta-object protocol.
- Are you into testing? Well, Perl culture is positively infected with testing. At YAPC|10, there are half a dozen talks about it. (Also: find out why you ought to be harnessing the power of TAP, even if you never program in Perl.)
- And, of course, there’s a little Haskell love, too: What Haskell did to my brain.
See, YAPC is for you.
Am I trying to persuade you to join us at YAPC? Yes. But I’m only doing it because I care about you. YAPC is a fascinating conference, packed with hackers from around the world, all eager to share interesting things, things many you would find delightful, if only you knew about them. So I’m letting you know about them, right now, so you don’t miss out.
Do yourself a favor. If you can figure out how to get your brain to Pittsburgh in the 4th week of June 2009 – yes, only 4 weeks away – then by all means register now for YAPC|10. It’s a great conference at a great price, and it’s something no discriminating hacker ought to be denied.
I hope to see you at YAPC|10.
Update: If any Haskellers are reading this and want to meet up at
YAPC, let me know. I’m trying to put together a
BOF session.
Posted in perl
Tags conferences, haskell, moose, parrot, perl, pittsburgh, programming, tap, yapc
14 comments
no trackbacks

Posted by Tom Moertel
Thu, 07 May 2009 17:55:00 GMT
I confess: I like puns. So I was delighted to discover that Twitter’s 140-character limit offers an interesting new opportunity for pun writers: the abbreviation pun. A recent attempt:
Chairs kill? Bad news for coders. “These data demonstrate a dose-response ass’n between sitting time and mortality.” http://bit.ly/19RR6R
(Does tweeting stuff like that make me a reprobate?)
Posted in humor
Tags humor, puns, twitter, writing
4 comments
no trackbacks
