Vincent Gable’s Blog

June 11, 2008

Bring an Extra Battery for WWDC

Filed under: Programming,Tips | , ,
― Vincent Gable on June 11, 2008

I was chatting with a saleswoman at the San Francisco Apple Store, a few blocks from where WWDC is being held this year. According to her, the top things people wearing WWDC badges bought from the Apple Store are (most popular to least popular):

Laptop Batteries. Specifically, 15″ MacBook Pro batteries. This is apparently #1 by a wide margin. It’s what I was in the store to buy. I don’t normally carry a brick spare battery with me, because in my experience you can’t rely on it being charged when you need it. But at WWDC, there are stations which charge your battery while you work, so you always have a fresh battery ready to swap in. You can go the whole day without plugging in!

Power Adapters. (I guess battery chargers are not a panacea)

Laptop bags/backpacks. This one is funny, because Apple gave out a laptop case to every WWDC attendant. I’ve always thought that giving out laptop carriers to people at a tech conference was a bad idea, because everyone there already has a laptop and a laptop carrier that fits them. Mass-produced swag is probably not going to be better quality then something a nerd picked out for their computer. More people purchased a backpack then a smaller brief-case-sized carrier (presumably so they could haul around extra gear).

So when you go to WWDC, bring an extra battery. It’s the number-one thing attendees (including me) regretted not bringing so much that they ran out to buy one.

June 8, 2008

Michigan Flyer

Filed under: Tips | ,
― Vincent Gable on June 8, 2008

I’m writing this on Michigan Flyer 344, in transit from East Lansing to the Detroit Airport (DTW). So far, I’m happy. Wireless internet is available on the bus, and there are maybe one or two power-outlets (125 volts @ 60Hz) if you look carefully. So far, it’s been a better experience then catching a connecting flight to DTW.

The verdict so far: recommended.

UPDATE: So on my return trip, there was no internet. I suspect this might have been because the lights and TVs were turned off, but I am not sure. Also, I had to wait around 3 hours for the bus to show, so I didn’t get home until 1 AM. Not good. On the other hand, no delays or rescheduling. The airline industry is in a crisis right now, and about one in four flights are delayed. Busses are more predictable.

UPDATE 2008-10-19 5:48 AM: No internet this time either; the driver said it went out last night and hasn’t been fixed yet. The power-outlets still work however. (And during a stop I was able to check my email over hotel-wifi that leaked into the bus.) This time the bus-schedule matched up very well to my flight schedule.

May 6, 2008

Do Your Dishes In The Tub

Filed under: Tips
― Vincent Gable on May 6, 2008

Most bath faucets move significantly more gallons per minute then sink-faucets. So if you need to rinse something out quickly, do it in the tub. I’ve been using the tub/shower to rinse out large blender carafes for years, and it’s worth the walk to/from the bathroom, because of how much more quickly I can fill a 2L container. More water/second usually means more force. So if you don’t like wasting your time, rise your dishes in the tub.

April 28, 2008

Hardware is a Commodity. Software is not.

Filed under: Design,Programming,Tips
― Vincent Gable on April 28, 2008

…it’s easy for software to commoditize hardware (you just write a little hardware abstraction layer, like Windows NT’s HAL, which is a tiny piece of code), but it’s incredibly hard for hardware to commoditize software. Software is not interchangeable, as the StarOffice marketing team is learning. Even when the price is zero, the cost of switching from Microsoft Office is non-zero. Until the switching cost becomes zero, desktop office software is not truly a commodity. And even the smallest differences can make two software packages a pain to switch between. Despite the fact that Mozilla has all the features I want and I’d love to use it if only to avoid the whack-a-mole pop-up-ad game, I’m too used to hitting Alt+D to go to the address bar. So sue me. One tiny difference and you lose your commodity status. But I’ve pulled hard drives out of IBM computers and slammed them into Dell computers and, boom, the system comes up perfectly and runs as if it were still in the old computer.

Joel on Software

April 25, 2008

Larger Displays are Better. More Displays are Better.

Filed under: Accessibility,Design,Research,Tips,Usability
― Vincent Gable on April 25, 2008

Here’s Jakob Nielsen’s economic justification for giving employees large screens,

Big monitors are the easiest way to increase white-collar productivity, and anyone who makes at least $50,000 per year ought to have at least 1600×1200 screen resolution. A flat-panel display with this resolution currently costs less than $500. So, as long as the bigger display increases productivity by at least 0.5%, you’ll recover the investment in less than a year. (The typical corporate overhead doubles the company’s per-employee cost; always remember to use loaded cost, not take-home salary, in any productivity calculation.)

Jeff Atwood has written a “one-stop-shop for research data supporting the idea that, yes, having more display space would in fact make you more productive”. But he warns us that “Having all that space can make you less productive due to all the window manipulation excise you have to deal with to make effective use of it.”He calls this the Large Display Paradox. But, there are solutions to this problem. Using software to divide the large single-display into a “grid” of virtual “monitors” is the one he proposes.

A recent and widely publicized University of Utah study concluded that people were less productive on a 26″ screen then an 18″ screen. (Unfortunately I haven’t found a better link to their actual data then this crappy PDF brochure.) However, they also found that people were more productive with two 20″ screens. Their 26″ monitor was 1920×1200 pixels = 2.3 MP, their 20″ was 1600×1200 pixels = 1.92MP, so two 20″ screens = 3.84 MP, quite a bit bigger then the 26″ screen, and with greater productivity. This supports the theory with the right windowing system, productivity increases as the number of usable pixels increases.

I’ve only found one exception to the “bigger is better” rule of workspaces. Portability (Availability) can be worth more then pure productivity. There’s an old gunslinger saying that “The best gun in the world is the the one I’ve got in my hand right now”. Similarly, having a “big iron” on your office isn’t much use if you are flying somewhere over the atlantic. There’s no substitute for having a computer in-hand. Even if you would be more productive using a 17″ laptop, it’s better to get a 13″ ultra-portable, if it means you are more likely to actually have it around when you need it.

Business travelers, and creative professionals who work better in eclectic settings, are examples of people who are better served by the smallest sufficiently-powerful laptop they can find. But for most people bigger is better. Fortunately, small laptops can be connected to large displays.

April 23, 2008

Printing a FourCharCode

Filed under: Bug Bite,C++,Cocoa,MacOSX,Programming,Sample Code,Tips | , , , ,
― Vincent Gable on April 23, 2008

A lot of Macintosh APIs take or return a 32-bit value that is supposed to be interpreted as a four character long string. (Anything using one of the types FourCharCode, OSStatus, OSType, ResType, ScriptCode, UInt32, CodecType probably does this.) The idea is that the value 1952999795 tells you less, and is harder to remember, then 'this'.

It’s a good idea, unfortunately there isn’t a simple way to print integers as character strings. So you have to write your own code to print them out correctly, and since it has to print correctly on both big endian and little endian machines this is tricker then it should be. I’ve done it incorrectly before, but more importantly so has Apple’s own sample code!

Here are the best solutions I’ve found. Please let me know if you have a better way, or if you find any bugs. (The code is public-domain, so use it any way you please.)

FourCharCode to NSString:
use NSString *NSFileTypeForHFSTypeCode(OSType code);
Results are developer-readable and look like: @"'this'", but Apple says “The format of the string is a private implementation detail”, so don’t write code that depends on the format.

FourCharCode to a C-string (char*):
use the C-macro

#define FourCC2Str(code) (char[5]){(code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, code & 0xFF, 0}
(requires -std=c99; credit to Joachim Bengtsson). Note that the resulting C-string is statically allocated on the stack, not dynamically allocated on the heap; do not return it from a function.
If you want a value on the heap, try:


void fourByteCodeString (UInt32 code, char* str){
  sprintf(str, "'%c%c%c%c'",
    (code >> 24) & 0xFF, (code >> 16) & 0xFF,
    (code >> 8) & 0xFF, code & 0xFF);
}

In GDB, you can print a number as characters like so:

(gdb) print/T 1936746868
$4 = 'spit'

(via Borkware’s GDB tips)

If you do end up rolling your own FourCharCode printer (and I don’t recommend it!), then be sure to use arithmetic/shifting to extract character values from the integer. You can not rely on the layout of the integer in memory, because it will change on different machines. Even if you are certain that you’re code will only run on an x86 machine, it’s still a bad idea. It limits the robustness and reusability of your code. It sets you up for an unexpected bug if you ever do port your code. And things change unexpectedly in this business.

Printing a FourCharCode is harder then it should be. Experienced developers who should know better have been bitten by it (and so have I). The best solution is probably a %format for printf/NSLog that prints integers as character strings. Unfortunately, it doesn’t look like we’ll be seeing that anytime soon.

April 18, 2008

Shifflett Happens

Filed under: Design,Programming,Tips
― Vincent Gable on April 18, 2008

To show that nonuniform distributions occur in real life, consider Americans with the uncommon last name of Shifflett. The 1997 Manhattan telephone directory, with over one million names, contains exactly five Shiffletts. So how many Shiffletts should there be in a small city of 50,000 people? Figure 2-4 shows a small portion of the two and a half pages of Shiffletts in Charlottesville, Virginia telephone book.

The Algorithm Design Manual, page 39.

April 5, 2008

A Better Left and Right

Filed under: Accessibility,Tips,Usability
― Vincent Gable on April 5, 2008

Some people get very confused with right and left when driving (“Turn left here. No, the other left!”) I knew a girl who wrote “left” and “right” on the ends of her windshield with a sharpie, and it worked well for her.

Another solution is to use concrete terms, instead of abstract terms:
“Turn left” is “Driver-side turn”
“Turn right” is “Passenger-side turn”

Sailors have been using the concrete terms “port” and “starboard” for centuries, for the same reasons.

March 18, 2008

Finding your laptop’s location with a shell command

Filed under: MacOSX,Programming,Sample Code,Tips,UNIX | ,
― Vincent Gable on March 18, 2008

Every wireless access point has a MAC address — a 48 bit number that uniquely identifies it. By checking the MAC address of the wireless access point your computer is connected to, you can figure out if it is being used at home, in your office, etc.

You can read this value from the shell with the command:
arp `ipconfig getoption en1 router`
Here’s how it works. The command ipconfig getoption en1 router gets the IP address of the router for the interface en1, which is the name of the Airport interface. If you want to get the router connected to the ethernet port use en0. The output of the command looks like:
128.62.96.1

arp prints information about the IP address, including the MAC address. arp is a little tricky in that it needs to take the address as an argument, you can’t pipe the output from ipconfig into it — that’s why ipconfig getoption en1 router is surrounded in “. Output from arp 128.62.96.1 looks like:
cisco-128-62-96-1.public.utexas.edu (128.62.96.1) at 0:12:44:f:5f:0 on en1 [ethernet]

The MAC address is in there, but you may need to use a regular expression to get at it. Here is an example of a perl script which prints just the MAC address of the wireless access point, or an error message.

if (qx{arp `ipconfig getoption en1 router`} =~ /([0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2})/){
   print "$1\n";
} else {
   print "Error; wireless internet is most likely unavailable\n";
}

This is essentially how IMLocation determines location.

In summary: Using the shell commands: arp `ipconfig getoption en1 router`, and the regular expression ([0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{1,2}) on it’s output, you can get the MAC-address of the wireless access point your computer is using. This gives you the computer’s location in about a 150 foot radius.

EDITED TO ADD: Another way to get this information is to use the private tool: /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport
-s gives a list of surrounding networks; -I gives information about the current network.
Try /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --help for more information.

You can even get the MAC address of all visible base-stations this way. Unfortunately, any system update could change the Apple80211.framework enough to break your code.

March 13, 2008

Useful Mac OS X Text-Editing Shortcuts

Filed under: MacOSX,Tips,UNIX,Usability | , , ,
― Vincent Gable on March 13, 2008

Here is a handful of lesser-known Mac OS X keyboard shortcuts that I’ve found to be very useful for working with text. They work in all standard text-fields, which means they work in most programs. Sadly, they don’t work in Microsoft products, and a few other apps that use non-standard text fields.

option = you will see the mouse cursor into a + , and you can now select columns of text! Unfortunately it only seems to work in editable text-fields, which is a great shame.

ctrl + d = forward delete, even if you don’t have it on your MacBook’s keyboard.

ctrl + a = Go to the beginning of the line the insertion-point is on.

ctrl + e = Go to the beginning end of the line line the insertion-point is on.

ctrl + k = “kill the current line”, deletes everything from the right of the insertion point to the next newline. This is very useful in Terminal, because you can delete the tail of a long command

command + delete = “Delete To Beginning Of Line”. Just like ctrl+k, but backwards, not forwards. (It even puts the killed text on the yank-pasteboard — don’t worry if that makes no sense, it’s an emacs-ism I don’t find useful.)

And yes, that’s ctrl, not command, because these are shortcuts inherited from the old UNIX text-editor emacs. There are more emacs “key bindings” that are available, but I have never found them useful. This long list of Mac OS X keyboard shortcuts includes them.

command + ctrl + d = look up the word under the mouse in the dictionary. I can’t believe that other operating systems haven’t done this for decades, it’s that useful.

It is unfortunate when programs use text-fields that do not support commands the operating system should give to every application. It’s always a mistake. Fundamentally, not supporting ctrl+a (go to beginning) is no different then not supporting command+c (copy).

If you find these commands useful, please teach them, and let developers know it’s a problem when you can’t use them. That will improve computing for everyone.

« Newer PostsOlder Posts »

Powered by WordPress