Kindle: First Impressions

Posted: March 21st, 2011 | Author: | Filed under: Computers, Opinions (Uninformed) | 2 Comments »

I decided to buy a Kindle last week, for a few reasons. I really wanted to start getting into e-books; they’re cheaper than hardcover for new releases now, I don’t have to wait for them to get delivered and they don’t take up space. Although I probably would have preferred an iPad if money were no object, I’m not really willing to spend $500 on a tablet when I already have a laptop.

I bought the WiFi-only model (didn’t really see myself needing the 3G version) and have been fiddling around with it for a couple of days now. My first impressions are pretty favorable.

I’m really surprised at how fast the e-ink display refreshes. I’d played around with an earlier-generation Kindle and a Sony e-book reader for all of about a minute years ago, and was really turned off by the refresh speed on the display. No such problems with the latest-gen Kindle, at least when it comes to reading and menu navigation; there are times when I find myself getting ahead of it, but most of that is off of my typical operating path.

The Amazon marketing hype on the display isn’t too far off; it really does look a lot like paper and is pretty easy to read without a light on (although I’m trying to save my eyes by not reading in dim light these days). I haven’t tried it in direct sunlight yet.

The quality of e-books on the Kindle varies depending on what you’re reading. Some publishers didn’t really put a lot of effort annotating things like chapters in their books, which makes navigation a challenge; Kindle’s navigation works by jumping to “locations” rather than pages, so you often have to search for the location corresponding to a page rather than the page itself if you don’t have a bookmark handy. I’ve only had this problem for the freebies on the Kindle store; the books I’ve actually paid for have pretty well-groomed metadata.

The fact that the Kindle doesn’t support the EPUB standard and instead uses its own DRMed format is irritating, certainly, but I feel like I can live with it, especially since converting EPUB to their proprietary format is supposed to be fairly straightforward. I’m pretty confident that eventually they’ll do the same thing the iTunes Music Store did and drop DRM entirely, or at least support EPUB natively with a software update.

I’m pretty happy with the Kindle so far. Does anyone else out there have one of these things? Any tips and tricks I should know about?


Pi

Posted: March 14th, 2011 | Author: | Filed under: Random | Comments Off

Today is the 14th of March, which some of the dorkier among us call Pi Day because the date (3/14) corresponds to the first three digits of pi.

Recall that pi (\pi ) is the ratio of the circumference of a circle to its diameter. There are a number of surprising things about pi, perhaps the most well-known of which is that it is an irrational number. Irrational numbers can’t be expressed as the ratio of two integers; that is to say, there are no two integers m and n such that \pi = \frac{m}{n}. A side-effect of this is that the decimal digits of pi never end and never repeat. Humans with a lot of free time are capable of memorizing a few tens of thousands of digits of pi, and computers have calculated pi to about 5 trillion digits.

The thing that interests me most about pi is that it shows up everywhere, even in places where it’s not immediately apparent that it should be involved. Whether the ancient Egyptians knew it or not, the ratio of the perimeter of the Great Pyramid of Giza to its height is approximately 2\pi. The ratio of the length of a river to the straight-line distance from its source to its mouth has been shown to approach pi. So many things in the natural world seem to involve circles (or spheres) that maybe it’s no surprise that pi is so ubiquitous.

One of pi’s most elegant appearances relates to complex numbers. Complex numbers are numbers of the form z = a + b i, where a and b are real numbers and i is \sqrt{-1}. They show up all over the place in physics and mathematics.

You can think of each complex number as a point (a,b) on a two-dimensional plane called the complex plane, where a and b denote the real and imaginary parts of the number. Since you’ve got a point in a two-dimensional plane, you can form a circle based on it – just draw a radius from (a,b) to the origin (0,0), sweep that line around 360 degrees and boom, circle.

You can even use this radial line to re-define the point (a,b) in polar coordinates, so that rather than being defined by its real and imaginary parts, each complex number is represented by the angle that its radial line to the origin makes with the x-axis and the length of its radial line (see picture). So now instead of defining the point as (a,b), you define it as (r,\varphi ) such that

z = a + b i = r (\cos(\varphi) + i \sin(\varphi))

Now it turns out that Euler’s Formula states that any point on that circle in the complex plane can be described as Euler’s number – e \approx 2.71 – raised to a complex power. In particular,

e^{i\varphi} = \cos(\varphi) + i \sin(\varphi)

So any complex number can be written as z = r \cdot e^{i \varphi} for some values of r and \varphi. The really amazing thing here comes when we make \varphi = \pi. Since \cos(\pi) = -1 and \sin(\pi) = 0, Euler’s formula yields

e^{i\pi} = -1

or

e^{i \pi} + 1 = 0

which relates – in a single, extremely elegant equation – five of the most important constants in all of mathematics.

Happy Pi Day, everybody.


Why isn’t Istanbul called Constantinople?

Posted: March 7th, 2011 | Author: | Filed under: Random | Comments Off

One of life’s great mysteries, explored by some of the greatest scholars of our time. So why, in fact, did Constantinople get the works?

With Wikipedia as my primary source and the confidence of an armchair historian, here’s (very, very roughly) why Istanbul isn’t Constantinople. Most of this is ripped off wholesale from Wikipedia – my thanks to the authors of those articles. I summarize Wikipedia entries so you don’t have to.

First we should note that before it was called Constantinople, it was called Byzantium. The city was founded by the city-state of Megara back around 660 BC and was named after the king of Megara, Byzas. It was part of various empires and consortiums until it gained independence in 355 BC. Byzantium had been friends with the Roman Republic for a long time, and so when the Roman Republic dropped the republic bit and became the Roman Empire, Byzantium joined the party in AD 73 by becoming part of the massive bulk that was imperial Rome, where it would stay to some extent for roughly the next 1400 years.

Cut to 251 years later when, in September 324, Constantine I became emperor of the whole Roman empire. I say “the whole empire” because until recently, the Roman empire had been divided into western and eastern portions, each administered by an augustus (the emperor of that half of the empire) and a caesar (a sort of junior emperor who was assumed to succeed the augustus of that region upon the augustus’ retirement or death). This Tetrarchy, as we currently know it, was supposed to help eliminate the chaos that had plagued the empire throughout the third century AD. This chaos was caused mainly by issues with succession (there were 25 emperors in 49 years during this period, with most of them having gained the post by killing their predecessor) and military and economic mismanagement. Unfortunately for the empire, the success of the Tetrarchy was pretty short-lived and it wasn’t long before Rome’s rulers were at each other’s throats again.

In 306, one of the augusti died and two different people were elevated to succeed him. By 308, there were four people jockeying for the position of augustus and claimants to the position spent the next little while killing each other off. By 313, a man named Constantine had secured the title of augustus of the west, and a man named Licinius had secured the title of augustus of the east. Constantine, however, decided that he wanted the whole pie and waged war against Licinius to re-unite the Roman empire under one ruler. In September 324 Constantine was successful, becoming the first man to hold the title of sole emperor in nearly 40 years.

As sole emperor, Constantine was ready to make some big changes. Constantine was the first Christian emperor of Rome, and he wanted to build a new Christian city at Byzantium to replace Nicomedia as the eastern capitol of the empire. He called the city New Rome, but most people just called it Constantinople, or The City of Constantine.

By the 390s, most of the emperors of the western empire were puppets controlled by the military. The western empire held on by its fingernails until, in 476, Odoacer deposed the last emperor of the western empire and that was that for the Roman empire as we know it. The eastern Roman empire, or the Byzantine empire as we usually refer to them today, emerged largely unscathed from the chaos that ravaged the western empire and its capitol, Constantinople, was the largest and most wealthy city in the western world for much of the Middle Ages.  In the 1200s, though, things started going downhill for them too.

Constantinople was sacked during the Fourth Crusade in 1204, during which the Byzantine empire was briefly usurped in favor of the Latin Empire established by the crusaders. The Byzantine empire was restored in 1261, but the empire and Constantinople itself were both badly damaged. The Byzantine empire would never fully recover. In May 1453, Sultan Mehmed II’s forces seized Constantinople and declared it the new capitol of the Ottoman Empire.

Constantinople had been referred to in normal conversation by the Turks as Istanbul since before the sack of 1453. The name Istanbul derives from the Greek istimbolin (I’m so sorry for butchering this, Greek scholars!), which means both “in the city” and “to the city”, and it and various Greek words like it had leaked their way into some Turkish place names over the centuries. By 1453, many people within the Ottoman empire referred to Constantinople simply as “The City”, or Istanbul, although it was still referred to on official documents as Kostantiniyye (the Arabic derivation of Constantinople). By the 19th century, much of the western world still referred to Constantinople as Constantinople, but the Ottomans were officially calling it Istanbul.

The Ottoman empire ended in 1922 with the exile of the last sultan, Mehmed VI, and the Republic of Turkey was formed in the following year with Ankara, and not Istanbul, as its capitol. The Turkish Postal Service Law of 1930 finally made the name change to Istanbul official; it declared that all packages and letters referring to the city as anything other than Istanbul would no longer be delivered by the Turkish postal service, forcing the rest of the world to comply with the name change. So if you sent a package to Constantinople, it would not be received in Istanbul, at least after 1930.

So long story short, I guess people did just like it better that way.


On the End of the Space Shuttle

Posted: February 27th, 2011 | Author: | Filed under: Opinions (Uninformed), Ranting | Comments Off

Image from National Geographic

Earlier this week, the shuttle Discovery’s lifted off for the last time. Hopefully it will return safely to Earth on March 7th, and after that it will probably end up in a museum somewhere. The end of its flight will mark the effective end of the space shuttle program, and we don’t really have anything lined up to replace it.

Some people seem to think that this is a tragic loss for the United States. Personally, I don’t think the end of the shuttle program is such a horrible thing.

I’ll admit, I’m biased; my dad works for JPL, and JPL doesn’t really do any manned missions. That said, my opinions here are my own and should not be construed as his or anyone else’s but mine.

In order to ask why it’s bad that we’re losing the shuttles, we must first ask why we had the shuttles in the first place. Mainly, they’re for moving things from the ground into low-Earth orbit. Those things might be people, or satellites like the Hubble Space Telescope, or pieces of the International Space Station (ISS). People are usually along for the ride to help deploy the equipment aboard, or to put it together once they’re in microgravity, or do experiments and run tests either in the shuttle or aboard the ISS.

In my opinion, those satellites, that space station, those experiments and tests, are in the service of one overarching goal – to do good science. I don’t think that necessarily requires putting people in space, though.

This isn’t to discount the contributions of the manned space program; the fact that we’ve been able to keep people in space for long periods of time mere decades after first sending anyone into orbit is a remarkable testament to human achievement. We also know that, eventually, we’re going to have to leave the planet (if we wait long enough, after all, the sun is going to eventually burn out), and seeing how people react to time in space helps to figure out what challenges we’re going to face in our eventual exodus.

That said, it’s unclear how much of our unanswered questions can’t be answered on the ground. Suppose that the goal of the manned space program is to put a man on Mars. A successful manned mission to Mars depends on advances in materials science, propulsion technology, and the production of clean, plentiful energy, as well as studies of the psychological and physical effects of months of isolation with only your flight-mates for company. None of these things require shooting people into space. Asking what the loss of the shuttle fleet will do to our chances of getting to Mars first is like asking how your child’s first word will affect their chances of getting into college. It’s not even clear how we’ll get there yet, let alone when that’s going to happen. In all likelihood, any mission to Mars will have to be multi-national; it will simply be too expensive in terms of money and resources for any one country to handle alone.

If you’re worried about America’s supremacy in space, you shouldn’t worry all that much just yet. NASA remains the most advanced space program in the world. We paid for most of the ISS. We’ve got ground- and space-based telescopes and imagers and orbiters that have traveled to the outer edges of the solar system and explored the planets. We’ve got probes running around the surface of Mars. If the goal is to do good science, all these things are doing good science right now and in that respect, the US is second to none.

Next, let’s look at relative cost. According to nasa.gov, it costs about $450 million to launch a single space shuttle mission. The total budget for the shuttle program over its lifetime exceeds $160 billion. By contrast, the entire cost of the Mars Exploration Rovers – building, launching, landing and performing the primary mission – was $820 million (at least according to Wikipedia). The Cassini-Huygens mission to Saturn cost the US about $2.6 billion for the whole package (again, Wikipedia). These missions have been doing good science for years for the cost of shooting humans into space for a matter of weeks.

Another criticism of the shuttle fleet’s retirement is that it will discourage young people in the United States from becoming scientists and engineers. I have an admittedly cynical view here.

When I was a kid, the shuttle program didn’t make me want to be an engineer. It made me want to be an astronaut. If you see a fighter jet streak by overhead and you’re 10, you don’t think “I want to build jet engines!”, you think “I want to fly jets!”  What cultivates a desire to become an engineer is an innate fascination with how things work and a strong desire to either understand why things work, or build things that work, or both. What got me excited about engineering as a kid was my dad showing me up-close pictures of Jupiter and Saturn and knowing that he helped build the thing that was out there, really far away, taking those pictures.

People who weren’t as fortunate as I was to grow up in an environment where interest in science and engineering is cultivated can face the cold hard truth – that so-called STEM (science, technology, engineering and math) disciplines are where the money is and where the jobs are. In the current economic environment, that’s as much motivation as they’ll need if they’re even a little bit interested. Not that they should be solely motivated by money, but it’s a pretty good incentive.

If we’re only in the business of putting people into space for the sake of saying “America puts people into space all by ourselves, look how mighty we are”, without regard to why precisely we’re putting them there or what they expect to accomplish, we’re wasting our time and energy on a vanity project. In short, chill out – America is still doing stuff in space and we’re still doing good science. As long as our representatives in Washington understand that the space program isn’t just the space shuttle and don’t completely strip NASA of funding, that’s unlikely to change in the near term.


Backups Revisited Part 2

Posted: February 21st, 2011 | Author: | Filed under: Advice (Unsolicited), Computers | Comments Off

In this post, I’ll focus on the practical side of backups.

Last time, I asserted that in order for a backup to really be a backup, your data has to be automatically replicated on two different drives using two separate filesystems on two different computers that are geographically separated, and one of those backups needs to be able to go back in time by at least 24 hours.

Satisfying all of these criteria at once usually isn’t free, but it doesn’t have to be hard, and you’re probably closer to a workable solution than you think.

In this post, I’ll examine a few possible solutions and point out some non-obvious ones. This isn’t meant to be comprehensive, but rather serves to give a general flavor of the state of backup solutions.

Built-In Solutions

OS X’s Time Machine fits some of our criteria for backups, but falls short in others. You can back up to two different drives,  the filesystems are distinct, and you’re able to move the Time Machine drive back in time if needed. Backing up to other computers with Time Machine is possible, but it’s unsupported and not very reliable (at least in my experience).

Using a network-enabled USB drive or a Time Capsule is essentially equivalent to backing up to another computer (they’re practically little computers themselves), but that costs a good deal of additional money. Unless you really know what you’re doing and are willing to take the time to make it work (and keep it working), making remote backups work with the Time Capsule is not really feasible.

Although I’ve never used it personally, Windows 7′s Backup and Restore feature appears to be feature-for-feature equivalent to Time Machine, but without Apple’s high-gloss glittery front-end. If you have a Professional or above license, it can backup to network shares, which is an improvement over Time Machine but requires you to pay more for the OS itself, which is kind of a drag.

You can use rsync by itself on pretty much any platform or with any one of a plethora of (usually OS-specific) front-ends. rsync can push files to pretty much anywhere and it supports incremental backups, so you could definitely satisfy all your backup demands with rsync, although it would take a little bit of work to get everything set up.

Sneakernet

If you’ve got a USB drive and are willing to lug it back and forth, there’s a relatively inexpensive way to come pretty close to an optimal backup solution. If you leave your USB drive at work, take it home and do backups every Monday night and bring the drive back to work on Tuesday, you’ve got your bases mostly covered. The problem here, of course, is that you have to remember to take the drive home with you, your backup granularity is kind of coarse (if your drive dies, you lose at most a week’s worth of stuff), and there’s a small window of vulnerability when your USB drive is at home. You get geographic distance for free, though.

Enter the Cloud

There are several companies that have recently started to offer so-called “cloud backup” services that provide you with some amount of storage space to which you can back up. Notable companies in this space include Mozy, Backblaze and CrashPlan. With cloud backup services, you easily satisfy all of our desirable backup properties simultaneously (unless you happen to live next to one of their data centers, of course), but it will usually cost you and doing the initial backup over the wide-area Internet may take weeks or months. Most services will ship you an external hard drive to which you can do your initial backup, but you have to eat the cost of a hard drive (~$100-150) for the privilege of writing to the drive and mailing it right back.

In my opinion, the standout favorite contender in this space is CrashPlan for one simple reason – they allow two computers running CrashPlan to back up an unlimited amount of data to each other for free. So if you and your friend both want to run backups, you can back up to each other.

Unexpected Surprises

If you care about your photos, you’ll want them backed up. If you share your photos on a site like Facebook or Flickr, you’re most of the way to an ideal backup of those photos. The only major drawbacks here is that restoring your photos isn’t trivial (you have to re-download them, although there are applications that will help automate that process) and you might incur a loss in quality when the site scales your image down. If you don’t mind those things though, these are great inexpensive ways to backup.

“But what about our time travel requirement” you might ask? If you’re editing photos, you might care about reverting to a previous edit. Most of the time though, you take pictures, upload them and never modify them again. Static data like pictures or music, where individual items never change but the set of items is expected to grow larger, is easier to back up because as long as you never delete anything the time travel requirement isn’t necessary.

My Setup

I have three computers that I care about – my desktop, my laptop and my home theatre PC. My desktop has an OS X partition and a Windows 7 partition and my laptop runs Debian in a VM, so I need to back up five filesystems in total. The HTPC has external storage drives that hold movies and music.

I admit that I break my own rules a bit – the external media drive on the HTPC is a RAID 1 with no other backups. I know, scary right?

Every system runs CrashPlan, even the Linux VM on my laptop. All systems backup to two places. The first is an old external drive attached to the HTPC. The second is a workstation under my desk at UCSD. Since I had an extra drive lying around, my desktop’s OS X partition also runs a Time Machine backup on a second internal drive.

That about covers it. Next week, something not related to backups!


Backups Revisited

Posted: February 12th, 2011 | Author: | Filed under: Advice (Unsolicited) | Comments Off

I can’t overstate the importance of doing backups. Your data is important, and it should be protected. For the next couple of posts, I’m going to do a deep dive into backup strategy and how the changing face of computing is changing the way we have to think – or in some cases not think – about backups.

Why bother with backups?

Simple: someday, your hard drive will die. Backups are not like insurance; what you are preparing for is not a hypothetical situation. This is where I start to sound like a jabbering paranoid, but trust me, it really sucks to lose data.

I wrote a post a couple of years ago that examined a couple of different ways to do backups. I’ve changed my opinions somewhat since then, so hopefully this adds something to the points raised in that post.

What is a backup, really?

It’s easier to define what a backup is by defining what a backup isn’t.

I should preface this by saying that anything is better than nothing.  You may not be able to feasibly satisfy a backup by my definition for all of your data, but the more of these points you’re able to hit, the better off you’ll be. With every layer of protection you put in place, the probability of losing data goes down. It never quite goes to zero, but it gets pretty close.

Your data is not truly backed up if:

  • Your data isn’t stored on two different drives.
  • Your data isn’t stored on two different file systems.
  • Your data isn’t stored in two different computers.
  • Your data isn’t stored in two geographically distant locations.
  • Your data isn’t duplicated automatically.
  • You can’t make at least one of the copies go back in time.

Two different drives is a no-brainer: if a hard drive fails, the data on that drive is probably gone forever. Putting your data on two different drives allows your data to survive the failure of one of them.

I say “probably gone forever” because I’m purposefully ignoring filesystem-level recovery systems like Norton Ghost and drive-level recovery services like Disk Doctors. I’m doing this because they cost lots of money and time and are not necessarily guaranteed to work.

Storing your data on two different file systems protects again stupid mistakes and computer compromise. If someone logs into your computer and deletes your data or a software bug hoses your file system, even if that data was stored on a RAID 1 array, it’s gone. It’s better to treat a RAID 1 array as a really robust single drive rather than as a complete backup solution by itself.

Storing your data on two different computers is an extension of the same protective strategy. If someone logs in to one computer and deletes data on all the drives on that computer, that data is gone unless it was stored somewhere else. Similarly (and somewhat more commonly) if your power supply goes kaboom and melts your computer and all the copies of that data are inside that one computer, that data is gone.

If you only go this far, you’re pretty well-protected against the loss of a single drive or a single machine. The next layer of protection, backing up in multiple places that are separated by distance, protects you against catastrophe, i.e. your house is destroyed or you get robbed.

If you’ve gotten this far and are diligent, the only things that are likely to kill your data are a major natural disaster or lots of different things failing at once.

The next point, automatic backup, is really a question of convenience. Personally, I don’t want to spend all day babysitting different copies of my data. You should find a backup solution that works automatically and reliably in the background and, more importantly, tells you quickly when it’s not working. The whole situation falls apart if you think you’re doing backups but you’re not.

The last point, time travel, is something that I think a lot of people overlook. If you do something stupid like delete data that you didn’t want to delete accidentally, it’s possible that the automatic backup system you’ve got in place will back up your mistakes and delete the backed-up copies of the data as well. Going back to an arbitrary past copy of your data isn’t really all that necessary in my opinion, but you should at least be able to go back in time 24 hours. Most backup systems allow you to do this, at least to some degree.

Paranoia In Action

Next time, I’ll give some practical examples, differentiate static data from dynamic data, and show how your data is probably easier to back up than you think.


Getting Rid of Old Tech

Posted: February 4th, 2011 | Author: | Filed under: Random | Comments Off

Lately, I have become the middleman for my parents’ old technology. They took their recent remodel as an opportunity to get rid of some things that they didn’t use anymore. Cameras (both still and video), DVD players, stereo equipment, iPods and computers – most of it between 5 and 15 years old – came to rest on the floor of my apartment. Some of it, I ended up using myself; speakers, for example, don’t ever really become obsolete. The rest of it couldn’t just sit in my apartment forever, so it had to go.

One of the big ways that I’ve been able to sell some of this old tech without a lot of hassle is by using tech resellers like Gazelle and BuyMyTronics. Sites like these will buy your old tech for a price based on their estimates of its resale value, its condition, how many accessories you still have, and so on. They then turn around and sell these products, either for parts or as a whole unit depending on its condition, to third parties. Sometimes they’ll send you a box to ship your stuff in, but they’ll always provide a pre-paid shipping label so you don’t have to pay to ship it. This cuts out much of the hassle associated with sites like eBay; just fill out a form, print a packing slip, put your stuff in a box and ship it. A week or two later, you’ve got a check in the mail.

One drawback with sites like Gazelle is that they won’t always take older items and you’ll probably get a little less for it than you would had you sold it on eBay or Craigslist. For stuff that resellers won’t take, I usually turn to friends and co-workers next. If Gazelle deems an item worthless, I’ll either give it to a friend who wants it or sell it for a few bucks to someone I work with. I really prefer staying within my immediate social graph this way to turning to something like Craigslist or eBay because, frankly, it filters out the crazy people.

I once had a winning bidder on eBay ask that I pack her item in a box and pack that box in a larger box “because the mailman steps on our boxes and that’s the only way it will arrive intact”. Seriously? If this is true, your mailman is a jerk. The facts that most of these e-mails WERE WRITTEN WITH THE CAPS-LOCK KEY ON did not help my confidence at all.

I’ve had multiple Craigslist ads yield nothing but phishing e-mails and missed “I’ll pick it up tomorrow at X” appointments. I’d much rather handle getting rid of this stuff on my timetable, and am always kind of apprehensive about giving my address and phone number to a total stranger. I could exchange money with these people in neutral locations but that somehow seems even weirder; I’m selling an iPod, not making a drug deal. When given the choice between eBay (and its cut of my profits) and Craigslist, I’ll almost always choose eBay for reasons like those.

My final avenue for getting rid of old electronics is donating them. Usually, this happens to really old, but still usable, computers. Sometimes (like if you’re trying to get rid of CRT monitors) donation sites simply won’t take them. At that point, I usually bring stuff to the local e-waste recycling center. I think it’s important that old electronics are responsibly recycled, so I try to use reputable e-waste recyclers whenever possible.

Bottom line: if you’ve got old tech to get rid of, your friends might be able to get more life out of it. If not, you can probably make more money from it than you think. If you can’t, please don’t just throw it away.


Esoteric Tip #4: Custom ANSI colors in Terminal.app

Posted: January 27th, 2011 | Author: | Filed under: Esoteric Tips | 1 Comment »

In this second Esoteric Tip, I focus on a way to improve the way that Terminal.app handles ANSI colors.

There are a set of standard escape sequences that most terminals support and that correspond to the same actions. If you’re really interested in all the gruesome history of the standard, I encourage you to read the Wikipedia page on the subject. Of particular interest in this post are commands of the form “color the text a certain color starting now”. A program can issue these commands to the terminal as it prints; this is what commands like the ridiculously useful colordiff use to output to the terminal in color and emphasize things that it thinks need emphasizing. Unfortunately, while Terminal.app understands these color commands, there’s no way of customizing the colors used, even though there is support for customizing background and text color. This is particularly annoying if you have a custom Terminal color scheme (which I do, more on that in a minute) and your background is, say, gray; dark green on gray looks terrible.

The only way to fix this at the moment is to use SIMBL and essentially hack Terminal.app to do what you want. There’s a lovely little SIMBL plugin call TerminalColours that enables changing what colors map to what color strings.

I like color schemes that are easy on the eyes (understand, I spend a lot of time looking at terminals and text editors) and I’ve grown particularly fond of the Zenburn color scheme. I use it in Emacs all the time, and now I can use it in Terminal.app as well. I found a Zenburn Terminal.app theme, but it didn’t customize ANSI colors and thus looked pretty awful on color terminals.

Blech.

After installing SIMBL and the TerminalColours plug-in, I rooted around in the Zenburn color scheme file that I use for Emacs to determine the right colors to use. Here they are for convenience, in the form “Color: Red, Green, Blue”

Normal Colors Light Colors
Black: 0, 0, 0
Red: 204, 147, 147
Green: 127, 159, 127
Yellow: 224, 207, 159
Blue: 140, 208, 211
Magenta: 220, 140, 195
Cyan: 147, 224, 227
White: 220, 220, 204
Black: 112, 144, 128
Red: 220, 163, 163
Green: 143, 178, 143
Yellow: 240, 223, 175
Blue: 148, 191, 243
Magenta: 236, 147, 211
Cyan: 147, 224, 227
White: 255, 255, 255

After modifying the colors with the handy menu provided by TerminalColour, the terminal is actually readable:

Update: You can download my modified Zenburn terminal theme here (right-click + Save As works best).


Esoteric Tip #3: Fixing Terminal.app’s Arrow Keys

Posted: January 27th, 2011 | Author: | Filed under: Esoteric Tips | Comments Off

I spend a lot of time on the command-line, mostly for running experiments and running various scripts over log files. OS X’s Terminal.app has gotten a lot better in the last few years, but there are a couple of things that don’t quite work out of the box. The next two tips in the Esoteric Tips series focus on fixing some of those quirks and making Terminal.app a little more usable.

Ctrl+Arrow Keys

I spent a couple years working on a Linux box during the day, so I got used to a common feature of Gnome’s terminals: if I held down the Ctrl key and pressed the arrow keys, I would go forward and backward by a word. This is especially useful, for example, if you just executed ./foo.py dir1 var2 var3 and want to execute ./foo.py dir2 var2 var3; just hit the up arrow to go to the previous command in your history (I’m assuming bash here), hit Ctrl + left arrow a couple times to go back two words, change dir2 to dir1. Fewer keystrokes, takes less time, and your hands hurt less. Key combinations like this send an escape sequence to the terminal, typically octal 33 (the Escape key, or from the terminal’s point of view “treat the next character(s) as a command”) followed by a character or two indicating what action to perform. The terminal looks up the character in a table and performs the appropriate action (in our case, move the terminal’s cursor left or right one word).

If you are used to this working, switching to Terminal.app will be a bit of a shock because the escape sequence sent when Ctrl+arrow keys are pressed doesn’t do the right thing; instead, it inserts a capital C or a capital D wherever your cursor happens to be at the time. So that previous example would leave my command line looking like this:

./foo.py dir1 var2 var3CDCDCD

This is pretty irritating. Fortunately, there’s an easy fix.

In Terminal, go to Preferences. In the Settings tab, there’s a sub-tab called Keyboard that contains a mapping of key combinations to the control characters they output. Here’s what that window looks like:

The two keyboard combinations you care about are “control cursor left” (highlighted in the above picture) and “control cursor right”. First, select “control cursor left” and click “Edit”. You’ll get a dialog box that looks like this:

Select the text in the text box under Action (that currently contains “\033[5D”) and press the Escape key followed by the ‘b’ key. The dialog box should look like this:

Click OK.

What you’ve just done is told Terminal.app to send the Escape key (octal 33) followed by the character ‘b’ whenever you press Ctrl+left arrow, which has the effect of moving the terminal cursor to the left one word.

Do a similar sequence of steps for control cursor right, except enter Escape + f instead of Escape + b. Your preferences window should look like this:

Now, Ctrl+left/right arrow should do what you (well, at least what I) expect them to do.


The Arcade Machine

Posted: January 20th, 2011 | Author: | Filed under: Fun and Games | 3 Comments »

The Arcade MachineMy friend Kevin and I built an arcade machine between October and December of last year. It’s currently sitting in UCSD’s CSE department in the graduate student lounge. You should check out the arcade machine’s homepage for more information about the machine itself and how we built it.

You can get kits similar to this one that are somewhat more professionally done, but they typically cost thousands of dollars and pretty much consist of the same thing this does: a specially-shaped wooden box with a computer inside running special software. The total out-of-pocket materials cost for this cabinet was about $300 (one third of which went to the logic board interfacing the buttons to the computer) and it looks pretty good. So the lesson here is, if you’ve got the time and the materials you might as well do it yourself. Luckily, Kevin has a garage and a table saw, both of which were pretty crucial to success here.

Some lessons from this that aren’t in the homepage linked above (that’s right, you get special behind-the-scenes commentary, you lucky dogs):

Cutting plexiglass is a giant pain. The guys on YouTube make it look so easy! We spent a lot of time and went through a lot of plexiglass getting those cuts right. Specialized “acrylic cutting” tools are a total waste of money, just use a razor-blade. After multiple failed attempts at cutting it ourselves, we went to Lowe’s to get a sheet of plexiglass cut for the large piece in front that masks the edges of the monitor.  They have a special plexiglass cutting machine (essentially a giant razor-blade on a track) that went right through it. Unfortunately, when we got back from Lowe’s we found that the piece we’d had cut was 1/8″ too short (d’oh!). Measure twice, cut once kids!

The front piece we used is actually a scrap piece of plexiglass left over from our “experiments” (read: a lot of sharp, broken pieces of plexi and swearing) that happened to be just long enough. At one time or another, shards of plexi took on various uses throughout the project including a straight edge and a putty knife.

Don’t use untracked international air mail, even if it’s cheaper. The guys that made the controller board for our arcade buttons are in the UK, and we’re in California. To save $20 (because we’re graduate students and poor, or cheap, or both), I had them ship it by free, untracked air mail. After waiting over a month for it to arrive, we complained and they shipped us another one, this time with tracking, and it was there in 48 hours. We still don’t know what happened to the first one. Maybe customs thought it was a bomb. Or “free air mail” is DHL throwing the package west and seeing how far it goes. Who knows.

Quick-Disconnect TerminalQuick-disconnect terminals are great. I was dreading having to solder wires to arcade buttons to make this thing work. I may have a degree in electrical engineering, and I’ve got some theoretical grounding in electronics, but not a lot of hands-on experience. Unless you count that time I shorted a power supply across the ground plate on a breadboard and burned my hand. That was an experience.

Thankfully, all the micro-switches on the buttons have quick-disconnect terminals, a.k.a. “wire connection for dummies”. Crimp the connector onto one end of a wire and slide it onto the terminal and boom, instant connection, no soldering required. This means that if we ever have to replace buttons, one of us won’t have to crawl underneath it with a hot soldering iron.

Django is pretty cool. Every time someone plays a game on the arcade machine, we log what game they played and how long they played it. We wanted a quick-and-dirty way to see what games were popular, and also to see remotely if the machine was being used or not – mainly because we didn’t want to have to walk down the hall to see if anyone was using the machine. The arcade machine’s user interface pushes this information out by copying a JSON file over SSH to my workstation whenever its state changes. We’re thinking about using Django as part of another project, so I decided that this would be a good excuse to do a really simple Django app. I went from starting to read the tutorial to having a working website in 90 minutes. And I went through two different designs. Hot damn.

There you have it. If you end up building your own machine based on what we did, please let me know!