Archive for the 'Apple' Category

How ClickToFlash works

Thursday, January 29th, 2009

Speaking of everybody’s favorite WebKit plug-in, here’s how it works. This should help you understand how it fails on some sites, and maybe aid you in contributing to its development.

First off, it is a WebKit plug-in; it’s written in Cocoa and uses WebKit’s own plug-in API. It does not use the Netscape plug-in API.

A WebKit plug-in declares a list of MIME media types in its Info.plist bundle. It does this by way of a dictionary of dictionaries:

<key>WebPluginMIMETypes</key>
<dict>
    <key>application/x-shockwave-flash</key>
    <dict>
        <key>WebPluginTypeDescription</key>
        <string>ClickToFlash</string>
    </dict>
</dict>

WebKit only loads a WebKit plug-in when it first encounters some content that it needs the plug-in for. It uses these Info.plist dictionaries to know which plug-in it needs to load. So, in the case of ClickToFlash, it only loads ClickToFlash when it encounters something that is of type application/x-shockwave-flash.

Here’s the brilliant part. Adobe’s Flash Player plug-in actually declares* two MIME media types: application/x-shockwave-flash and application/futuresplash.

You will notice that ClickToFlash only declares one of these.

As it turns out, everybody only uses application/x-shockwave-flash. ClickToFlash exploits this.

When you click on the ClickToFlash view, it modifies the object or embed element that the view represents, changing its type attribute to the other type—the one ClickToFlash doesn’t declare; the one no webpages actually use. WebKit notices this change and looks again for a plug-in to handle the movie. This time, it comes up with only one handler: the real Flash Player plug-in.

There are several reasons why a site may not work with ClickToFlash. I suspect one reason is that they try to interact with the movie via JavaScript; ClickToFlash doesn’t export a script object and wouldn’t be able to communicate with the real Flash Player anyway. The script finds itself talking to a wall, and breakage happens.

So now that you know how ClickToFlash works, maybe you can help fix its bugs?


* Flash Player doesn’t declare its MIME types in its Info.plist; it declares them in a resource file, in ‘STR#’ resource 128. Thanks to WebKit developer Mark Rowe for reminding me to look for a resource.

Free stuff on iTunes: Death Cab for Cutie inside an iPhone app

Thursday, January 29th, 2009

I normally hate the advertisement apps that several companies have created for the iPhone, but in this case, I’ll make an exception.

The newest advertisement app is the one for Death Cab for Cutie. As you can guess, it’s free.

The reason I like this one is because it actually includes ten (as of 1.0—eight as of 1.1) DCfC songs at medium quality (AAC, 96 kbps). Good enough for me—certainly good enough for free.

You don’t need an iPhone to use this app. You can easily extract the music from the app bundle and then dispose of what’s left.

After downloading the app, here’s what you have to do.

  1. Switch to the Applications section of iTunes.

  2. Right-click on the DCfC app and click Show in Finder.

    Screenshot of the contextual menu hanging open, with the mouse cursor over the “Show in Finder” command.

  3. You’ll see the .ipa file. Open this in an unzipper application such as Archive Utility, StuffIt Expander, or BetterZip. (BetterZip will let you go straight to the .app bundle, so you should use that if you have it.)

    Screenshot of a Finder window showing the contents of the Mobile Applications folder in the iTunes library folder, with the “DCfC 1.0.ipa” file selected.

  4. In the unzipped folder, find the actual app bundle. (It’ll have a prohibitory sign on it because it’s an iPhone app.)

    Screenshot of a Finder window showing the contents of the Payload folder in the unzipped .ipa folder, with the “DCFC.app” bundle selected.

    Right-click on it, then choose Show Package Contents.

  5. You haven’t far to look, since iPhone apps are old-style flat bundles, not new-style hierarchical bundles.

    In version 1.0, the m4a files were right there. Since version 1.1, they’re not; the app streams them on demand. Open the media.stream.xml file in your favorite text editor, copy each http://[…].m4a URL, and paste it into your browser’s Downloads window.

  6. If you don’t want any of the other features of the app (e.g., its discography or tour dates), delete the app in iTunes.

If you enjoy filling out the Lyrics tab in iTunes and reading along in TuneTagger, you may also want to write a program to read the discography.xml file (also in the app bundle) and copy the lyrics into iTunes. If you write such a program, feel free to link to it in a comment.

UPDATE 2009-02-06: Updated instructions for version 1.1, wherein they stopped bundling the .m4a files in the application.

ClickToFlash: Visible edition

Tuesday, January 27th, 2009

The WebKit plug-in ClickToFlash has been an instant hit over the past 24 hours. The original version was on a Google Code project, but that project is now closed to the public. Before the Google Code project went 0600, Jonathan Rentzsch set up a fork on GitHub to gather changes submitted by Gus Mueller and Jean-François Roy.

Unfortunately, both the original and Rentzsch’s current version have one immediately-noticeable deficiency: In place of the Flash movie, the plug-in displays only a blank gray gradient background. It’s easy to think that there’s simply nothing there, or that the page is not done loading.

I decided to solve the problem myself. I forked the fork and posted my own version (along with a binary installer).

My interpretation of the plug-in adds three features:

  1. Swap in the Flash movie on mouse-up, not mouse-down. This gives you a chance to back out by moving the mouse out of the view.
  2. Invert the gradient when the mouse is down. This makes the view look (as well as act) more like a button.
  3. Fixes the blank-background problem. A number of people have done this in other forks, but I think my solution is best:

My click-to-play symbol is a play symbol (right-pointing triangle) with a florin (ƒ), emulating the Flash logo, cut out of it.

The symbol's gradient inverts along with the background gradient.

My solution has two advantages:

  • Its drawing is fully vector-based, which means that that it will scale to fit the would-be movie’s area and will look good no matter how big the would-be movie is.
  • I designed the implementation so that you can replace it with different drawing code if you’d prefer a different click-to-play symbol.

The original, Jonathan Rentzsch’s fork, and my fork are all under the MIT license. And, of course, he is welcome to pull my changes upstream.

finetune vs. Pandora

Tuesday, January 13th, 2009

The most popular mix-and-match-music app, according to the completely objective score of how often I hear its name, is Pandora.

Pandora's application icon.

Most of this popularity came with their release of an iPhone app back in July 2008. The iPhone app makes the site portable: previously, you could only listen to Pandora while chained to a browser (or a SSB), but now you can listen to it anywhere that’s in cell range.

Pandora now has competition.

finetune's application icon.

It first appeared in AppShopper’s free iPhone apps feed on 2008-11-08, but I didn’t see it then (I probably scrolled past it). I did see it when they released their 1.1.3 update back on 2008-11-31.

Its name is Finetune. Like Pandora, it’s free.

The differences:

  • Unlike Pandora, Finetune doesn’t require an account.
  • Pandora has an option to jump over to the iTunes Store to buy a song; Finetune has no such feature.
  • Finetune only creates stations based on artists; Pandora lets you name an artist, song, album, or composer.

I think Finetune does a slightly better job of selecting songs that are similar to the work of the requested artist. (Sometimes this is hard, as in the case of the Beatles, who produced very diverse work.)

One major drawback to Finetune is that, since it only lets you select based on artist (performer), not composer, it really sucks for classical music. (The service has it, but it’s little better than shuffle-play.) If you want a customized classical station, Pandora is currently your only option.

(Note: I wrote this before Pandora 2.0 came out, but it’s still accurate. If anything, Pandora 2.0 is even better for classical now, since you can now make stations by genre.)

Review: BurnBall

Tuesday, January 13th, 2009

On 2008-12-12, Tim Haines, the developer of BurnBall, contacted me on Twitter to offer me a free promo code. I accepted, and played the game on my first-generation iPod touch.

The game is basically Qix with a Sonic-the-Hedgehog-esque theme. Based on that, I give you this pull-quote:

If you like Qix, you’ll like BurnBall.

As it happens, I don’t like Qix. The main thing about Qix that frustrates me is that enemies can kill you just by touching your trail while you’re cutting off another piece of the level. This makes some sense for the Tron-based theme of some of the other Qix work-alike games, but it has the effect on gameplay that you can’t make any but incremental progress, especially after the first few levels, as the number of enemies goes above 2. Your only hope is that your enemies will see some shiny thing and leave you alone long enough to let you complete your wall; otherwise, you can only complete the level a little bit at a time.

One way in which somebody could improve Qix would be to let enemies go right through your wall, and compensate by making them more aggressively pursue you. Then, you’d stand a reasonable chance of completing the wall, if you can just dodge the enemies. Another way would be to have enemies bounce off the wall, which would provide you with a way to restrain them while you draw more wall—but that may make the game too easy.

BurnBall is graphically different enough from Qix that it could pull off either change, although it probably should be an alternate game mode.

So, basically, the only reason I dislike BurnBall is because I dislike Qix games in general.

That said, BurnBall is a very good Qix game, being both well-drawn and responsive to your control. (Since I originally drafted this post, there’s been an update that tweaked the tilt response; I haven’t tested it.)

BurnBall has an advantage over Qix work-alikes on other platforms, in that you can move in any direction—you’re not limited to up, down, left, and right. You move by tilting the iPhone.

Another advantage of BurnBall over other Qix work-alikes is that Haines holds high-score competitions with monetary prizes on the app’s Facebook page. He also posts a free promo code every time that page gets another 100 subscribers, so you may not even have to buy the game.

If you’d rather not wait for the next promo code, the app is 99¢ on iTunes.

iPhone app settings

Wednesday, January 7th, 2009

One of the ongoing debates among users of iPhone OS devices is whether an app’s settings belong in the app itself, or the Settings app.

I’m of the opinion that this wouldn’t even be a debate if it weren’t for Apple’s prescription in the iPhone HIG that every iPhone app’s settings should be in the Settings app. Mac apps don’t come with prefpanes for their preferences (with the exception of faceless background apps like Growl). Windows apps don’t, either, that I know of. GNOME and KDE apps don’t pollute Ubuntu’s Control Panel.

The iPhone is the only OS I know of whose developer recommends that app developers put their application settings in the system-wide Settings app.

As we’ve seen several times on every platform, it’s OK to break one of the local Human Interface Guidelines if and only if the violation makes the interface better.

I think this guideline is one that iPhone developers should violate flagrantly.

But there’s a problem. The iPhone doesn’t really have an icon for a Settings button. Most developers seem to use the Info icon that one of the frameworks apparently provides, but this isn’t the proper use of that icon. The Info icon means info, not application settings.

Another choice is the gear icon for Action buttons:

NSActionTemplate.

But, again, we have a conflation of functions. The button in question is not an Action button; it is a Settings button. This icon is not a Settings icon. (I suspect that most people who use the Action icon use it because it doesn’t have any particular association with “action”, either, other than Apple’s endorsement of it for that.)

The Iconfactory, wisely, chose differently in Twitterrific. I suspect that this was largely coincidence, as the Mac version of Twitterrific came first and already had a Settings icon; for the iPhone version, the developers simply used the same icon. It works well enough:

as seen in this screenshot of Twitterrific.

But it’s not perfect. A wrench does not say “settings”. (I offer myself as evidence: When I first saw it in the Mac version, I didn’t know it was the Preferences button.) Generally, a wrench means “edit this”, as in the context of a game.

What we need is an icon that says “settings”. Ideally, this icon should either convey the notion of a changeable state value (as the previously-favored light switch [Mac OS X through Tiger] and slider [Mac OS] did), or build on an existing association with the concept of settings.

Let’s go with the latter. I nominate the Settings app’s icon:

iPhone Settings icon

Familiar enough, wouldn’t you say?

That’s Apple’s version. Here’s my button-icon (a.k.a. template) version, in the 16-px size:

Settings button icon 16-px version.

I tried it out in the iPhone version of Twitterrific on my iPod touch. Before and a mock-up of after:

Before.
After.

After I created this icon, I wondered what it would look like in the Mac version of Twitterrific.

Here’s the original:

…with the wrench icon.

… And right away we have a problem. These buttons are already framed; my white frame will glare here.

Fortunately, that’s easy to solve. With ten seconds of work, I created a frameless version. Here’s what that looks like:

Twitterrific-Mac-newSettingsIcon.png

I think we could all get used to this icon. This wouldn’t have worked at all before Apple changed the icon of System Preferences to match the iPhone Settings app, but now it can.

I don’t think it’s perfect. Perhaps a real icon designer (I’m just a programmer) can refine it. But I think it’s a good first draft. I’m curious to hear your opinions; please post constructive feedback in the comments.

If you want to use this icon, go ahead. Here’s the original Opacity document , from which you can build all the many variations of the icon. (Click on Inspector, then Factories, then find the version you want in the list and click its Build button.)

Manpage Monday: notify(3)

Monday, December 8th, 2008

notify(3) is a simple API that allows processes to poke other processes, and to be poked.

The API is similar to NSDistributedNotificationCenter, except that it’s not object-oriented, it’s not based on Foundation or CF, and it doesn’t allow you to attach a property list to the notification.

You register in one of four ways:

notify_register_check
Sign up under a name, and get a registration token.
notify_register_signal
Have the system send your process a signal when another process posts a notification with a particular name. Also get a registration token.
notify_register_mach_port
Have the system send your process a message on a Mach port when another process posts a notification with a particular name. Also get a registration token.
notify_register_file_descriptor
Get a registration token, and have the system write that token to a file descriptor when another process posts a notification with a particular name.

Each of the last two functions will create the Mach port or file descriptor for you, unless you tell it to use one you already have. You do that by passing NOTIFY_REUSE.

All four functions give you a registration token (the first one does nothing else), which is simply a signed 32-bit integer. You can then use notify_check to poll that token to see whether any processes have posted a notification to it since the last time you checked. (I don’t know how the other notification methods affect this—e.g., whether notify_check will ever return true if you got the token from notify_register_signal.)

You free the token using notify_cancel. This also closes any Mach ports or file descriptors you have associated with it. There is no way to disassociate them from the token or to cancel the token without closing the associated resources.

On the sending side, the API provides one function: notify_post. It takes one argument, which is the notification name; this is the same name that any receiving processes passed to their chosen notify_register_whatever function.

Leopard adds a new feature: you can associate a shared 64-bit number with a name using notify_set_state, and retrieve that number using notify_get_state. I suggest that you only use notify_set_state in a single process, as I can imagine race conditions occurring if two processes try to set state under the same name. If you need bidirectional communication, use two notification names (or a different means of communication, such as sockets or Mach ports).

Apple introduced the rest of the notify(3) API in Panther.

Sources of free music

Tuesday, November 25th, 2008

By which I mean, sources that you can check periodically or subscribe to to receive a steady stream of free music.

For music podcasts, use a regular RSS reader (or a dedicated podcatcher, if you have one), not iTunes. I’ve had problems convincing iTunes to accept files into its Music library that I’d downloaded through its podcatcher.

These are some sites that I don’t personally subscribe to, but am aware of and occasionally benefit from indirectly (e.g., when Largehearted Boy posts a link to a Team Love track):

  • A site called RCRD LBL has a blog called RCRD SELECTOR, which provides a few free songs per day. The feed doesn’t use enclosure tags, which makes podcatching difficult, but I’m listing it anyway in case you’re OK with that.

  • You Ain’t No Picasso is primarily a music blog, although it has the occasional non-music-related post. Not every post has MP3s on it, but most do. Has a feed, but no enclosure tags. (Added 2008-12-17; thanks to Mike Krieger for linking to one of their posts on Twitter, and Colin for retweeting that link)

  • The Hype Machine aggregates a lot of MP3 blogs, including the aforementioned Stereogum. Has a feed, but no enclosure tags. (Added 2008-12-17; thanks to Colin for suggesting it on Twitter)

  • Team Love is a record label that gives away songs on their Library page. There’s no dedicated Library feed, so you’ll have to check back periodically (Tuesdays?).

    One thing you’ll notice is that the front page says in one paragraph that the Library is “open to the public 24/7”, and then in the next paragraph that you’ll need to open an account. There is some open-to-the-public access on the right side of the page (“Artists” and “Featured MP3s”); I don’t know what an account gets you.

    Added 2008-12-17. Thanks to Matt Morrell, who is a musician himself (with at least one song of his own available for free) and sent me the link on Twitter.

  • KRCW’s Today’s Top Tune podcast is another weekdaily rock-music podcast (with, of course, a a podcast feed). Note that not every episode is a song; for example, right now, the oldest of the three episodes in the feed is an interview with Tony Hawk. Note also that the song files have borked tags, with the artist in the title tag and the song title nowhere; you’ll have to fix these yourself.

    KCRW has other shows, but it looks like Today’s Top Tune is the only one you can stock your music library from. (Corrections welcome.)

    Thanks to Steven for linking to Today’s Top Tune in a comment.

If you know of other, similar sources, I invite you to link to them in the comments.

UPDATE 2009-03-26: Segregated sites I don’t subscribe to into their own list, and added Largehearted Boy, NME, and Spinner.
UPDATE 2009-04-06: Demoted KCRW to the sources-I-don’t-subscribe-to list. I get enough music from other sources now that I don’t care about it enough to deal with its broken tagging scheme.

Manpage Monday: afconvert(1)

Monday, November 24th, 2008

afconvert is a command-line utility that uses Core Audio to convert audio files from one format to another.

The manpage is actually pretty sparse (like the rest of the Core Audio documentation); you’re better off reading the command-line help:

% afconvert -h

A simple example is to convert an AIFF file to AAC in an MPEG-4 file:

% afconvert -f 'm4af' -d 'aac ' -b 98304 Recording.aiff

The resulting file is 96 kbps (98,304 bps) and is named “Recording.m4a”.

UPDATE 2008-11-26: Corrected permalink and title to include the section number.

iTunes smart playlist: Music only

Sunday, November 23rd, 2008

A smart playlist selecting items that are not podcasts, whose Kind does not contain “URL”, [v]“ideo”, or “movie”, that are not in the Audiobooks special playlist, and whose Genre does not contain “Comedy” or “Spoken Word”.

Some explanation:

  • Kind does not contain URL: Excludes streams
  • Kind does not contain ideo: Excludes music videos
  • Genre does not contain Comedy or Spoken Word: Excludes anything that isn’t actually music

Solved problems

Sunday, November 23rd, 2008

Here are some types of apps that I’m tired of seeing over and over again on the iPhone App Store. In some of these categories, I’ve picked a winner that completely solves the problem; you’re welcome to nominate winners for the others.

  • Flashlight (solution: myLite)
  • Tip calculator (solution: Calculator—seriously, is subtotal × 0.2 so damn hard?)
  • Any app with a checkmark icon, regardless of function: Think of a different icon, please. At this point, you might as well just make the word “app” your icon.
  • App to help you find your way back to your parked car: The main problem is that all of these use Core Location rather than just tracking movement through the accelerometer. That makes the app useless if you don’t have an iPhone 3G and you’re out of cell range or don’t have a cell antenna (iPod touch).
  • One-tap contact dialer (also includes 911/999 dialers)
  • Apps that fake receiving a phone call
  • Fortune-telling/decision-making apps
  • The Puzzle desk accessory
  • Sudoku (solution: ACTSudoku and its free light version)

There’s nothing wrong with competition, but these are saturated markets. If you’re not going to solve the problem in a completely different way (e.g., by not using Core Location to set the location of the parked car), then don’t waste your time—write something else.

If you have any suggestions for other categories that should go on the list, feel free to leave a comment.

Manpage Monday: backtrace(3)

Monday, October 27th, 2008

New series: Manpage FridayMonday. Every Fridayother Monday, I will post a link to one manpage that comes with Mac OS X. [See update below.]

Today, it’s backtrace(3), which tells you about three functions:

SYNOPSIS

#include <execinfo.h>

int
backtrace(void** array, int size);

char**
backtrace_symbols(void* const* array, int size);

void
backtrace_symbols_fd(void* const* array, int size, int fd);

DESCRIPTION

These routines provide a mechanism to examine the current thread’s call stack.

backtrace() writes the function return addresses of the current call stack to the array of pointers referenced by array. At most, size pointers are written. The number of pointers actually written to array is returned.

backtrace_symbols() attempts to transform a call stack obtained by backtrace() into an array of human-readable strings using dladdr(). The array of strings returned has size elements. It is allocated using malloc() and should be released using free(). There is no need to free the individual strings in the array.

backtrace_symbols_fd() performs the same operation as backtrace_symbols(), but the resulting strings are immediately written to the file descriptor fd, and are not returned.

Added 2008-10-25: Here’s a test app to show the output.

File: print_backtrace.tbz

Output:

0   print_backtrace                     0x00001fc9 print_backtrace + 31
1   print_backtrace                     0x00001ff6 main + 11
2   print_backtrace                     0x00001f7e start + 54

In order:

  1. Index in the array of addresses
  2. Executable name
  3. Address
  4. Name + offset

UPDATE 2008-10-24 21:19 PDT: I’ve decided to change the schedule on this. Instead of Manpage Friday, I’ll do Manpage Monday, and it will be every two weeks. In between will be Framework Friday.

So this is now the first Manpage Monday post, and I will update its post date on Monday, the 27th. (I can’t update it now because WordPress won’t let me publish a post from the future—only schedule it. Grrr.) The week after that, November 7th will be the first Framework Friday. And in the week after that, November 10th will be the second Manpage Monday.

New website: Are the iPhone APIs public yet?

Thursday, October 23rd, 2008

As of this writing,

No.

But if Apple ever changes that, I’ll be sure to update that page.

iTunes’ new worst alert box?

Sunday, October 19th, 2008

I believe Apple added this alert box in version 8:

“Applications cannot be purchased with Shopping Cart. Your Preferences are currently set to buy using Shopping Cart. Application purchases cannot be placed in Shopping Cart; they must be purchased by 1-Click. Select Buy if you'd like to purchase Virtual Zippo® Lighter by using 1-Click and your credit card will be charged immediately.

Let’s enumerate the fail, shall we?

  • Applications cannot be purchased with Shopping Cart.

    Yes, they can. You just won’t let me.

  • Your preferences are currently set to buy using Shopping Cart.

    Because that’s what I want to do.

  • Application purchases cannot be placed in Shopping Cart; they must be purchased by 1-Click.

    Passive voice is great, isn’t it? It allows the subject to not take responsibility for their own actions.

    This is not some law of nature, like gravity meaning that you cannot fly. Apple prevents you from buying applications using a Shopping Cart. The message should just say that.

  • Select Buy if you’d like to purchase application by using 1-Click …

    I wouldn’t, but since iTunes won’t let me do what I really want, I have to either buy it the way iTunes wants me to, or not buy it at all.

  • … and your credit card will be charged immediately.

    No, it won’t, because I don’t have a credit card on my iTunes account. If it did charge my credit card, I would be alarmed.

Now, let’s rewrite the alert’s message to be more accurate.

You may not purchase applications with Shopping Cart.

Regardless of the fact that you have chosen to buy from iTunes using a Shopping Cart, we have chosen to not allow you to buy applications using a Shopping Cart. Instead, we require you to buy using 1-Click. Select Buy if you accept this limitation, and we will deduct the money from your store credit immediately.

I have filed two bugs:

Happy vs. Unhappy: The New MacBooks

Wednesday, October 15th, 2008

Happy:

  • Glass trackpad is intriguing. And they finally killed the button, which had long been unnecessary. Now I just want an external USB one of these, for my Mac Pro.

  • Unification of the MacBook and MacBook Pro lines. The new MacBook is just the 13.3″ MacBook Pro. (But only a partial unification: the low-end plastic MacBook is still available.)

  • Finally, a new Cinema Display with its own camera.

  • And, on the same display, a built-in MacBook power adapter!

Unhappy:

  • Still no 12″ MacBook Pro. (Actually, considering the lines’ convergence, a 12″ MacBook would be OK now.)

    Remember the 12″ PowerBook G4? I want an Intel version. That’s all.

  • The glass screen could be heavy. Then again, LCDs are glass anyway. So, did they remove the plastic protection in front of the LCD, or did they replace it so that there’s now glass in front of glass? (Regardless of the reason, the new 15″ MBP weighs 0.04 kg more than the previous 15″ MBP.)

  • No more anti-glare screens. I’m sure somebody will come out with an anti-glare stick-on (I have one on my iPod touch), and that it will be a popular accessory.

  • Not sure about this new entire-trackpad-is-a-button thing. Tap-to-click was nice and quiet. I hope the new trackpads will still allow it as an option.

  • Adapting between DVI and DisplayPort may be a pain.

New utility: rehash_services

Friday, September 19th, 2008

This is one that I’ve had kicking around for awhile. A tweet by Augie Fackler prompted me to post it.

rehash_services is a simple command-line tool that does exactly one thing: It updates the contents of your Services menu. You’d use this after installing or updating an app that provides services, in order to update the Services menu without logging out.

Note: You don’t need to use this when creating services with ThisService, as those services automatically refresh the Services menu on launch.

In case you’re wondering: It works by calling NSUpdateDynamicServices. That’s all. The program is really short.

How to make a RAM disk larger than 2 GiB

Wednesday, August 6th, 2008

UPDATE 2009-09-23: This procedure is no longer necessary since Snow Leopard.


The most frequent question I get about Make RAM Disk is “How do I create a RAM disk larger than 2 GiB?”.

Make RAM Disk uses Mac OS X’s disk images system to do its work. Unfortunately, as of Leopard, the command to create a single RAM disk refuses to create one that is larger than 2 GiB in size, even if you have the RAM to do it.

However, there is a solution.

Jennek Geels, a user who asked the aforementioned question, worked with Jean-Sébastien Rousseau to figure out a solution using Mac OS X’s software-RAID feature. Here’s a refined version of their solution:

  1. dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  2. Repeat step 1 as many times as necessary, changing the variable number each time (dev1, dev2, dev3, and so on).
  3. diskutil createraid stripe $VOLUMENAME HFS+ $dev1 $dev2 .. $devN

So, for example, to create an 8 GiB RAM disk:

  1. NUMSECTORS=4194304
  2. dev1=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  3. dev2=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  4. dev3=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  5. dev4=$(basename $(hdiutil attach -nomount ram://$NUMSECTORS))
  6. diskutil createRAID stripe $VOLUMENAME HFS+ $dev1 $dev2 $dev3 $dev4

diskutil createRAID will format and mount the RAID device automatically; you don’t need to run newfs_hfs and diskutil mount like you do when creating a single-device RAM disk.

I tested the speed briefly (just one run each, not averaged over several runs). Copying 2,000 MiB from /dev/zero to an 8 GiB RAIDed RAM disk was about one second faster (~5 seconds) than copying it to a 2 GiB single RAM disk (~6 seconds). Your results may vary.

When you’re done, you’ll need to eject all of the devices separately, starting with the RAID:

  1. diskutil eject $RAIDDEVICE
  2. hdiutil detach $dev1
  3. hdiutil detach $dev2
  4. ..
  5. hdiutil detach $devN

If you don’t remember the device name of the RAID device, you can look it up in the output of diskutil listRAID. Look for the line labeled “Device Node:”.

I have no immediate plans to add this RAID feature to Make RAM Disk, because I’d also need to write an app to handle the full clean-up procedure. For now, if you really need a RAM disk that big, you can probably handle creating it and tearing it down yourself.

iPhone sudoku follow-up: ACTSudoku

Tuesday, July 29th, 2008

A couple of weeks ago, I posted a list of requirements for an iPhone sudoku app. At the time, no app satisfied all of the requirements, but one did come close.

Pierre Bernard of Houdah Software posted a comment that his sudoku app, ACTSudoku, satisfied all but one of the requirements I listed. The only one remaining was rotational symmetry, which he asked about.

In response to our dialog on that post, he added rotational symmetry in ACTSudoku 1.1, which Apple has now approved. You can download it now for $2.99 USD (or free if you bought one of the earlier versions).

UPDATE 2008-08-01: As of yesterday, there’s now a free version of ACTSudoku, which only generates easy puzzles. This is good if you’d like to try it for yourself, but you don’t want to spend $3 just yet.

The interface is simple enough:

ACTSudoku's interface is a sudoku grid on a wooden background, with the difficulty below it on the left and the timer below it on the right. At the bottom is a toolbar with three items: A + button, an Info button, and an X button.

Notice that there’s no row of numbers for input. The obvious thing to try is tap on a cell, and it works:

Tapping on a cell brings up a square pop-up containing nine numerals, possibly colored by pencil-marks.

In other words, the interface is obviously postfix. The key word there is “obviously”: One of my requirements was that it must be obvious how to input numbers.

The input method is not perfectly obvious, however. One thing that stumps a lot of people (going by Bernard’s response to some iTunes reviews) is the fact that simply tapping on a number in the pop-up enters a pencil-mark, rather than locking in the number. You must hold down briefly to set a number in the cell. In the comments on the previous post, I suggested swapping these behaviors; I maintain that suggestion. (UPDATE 2008-10-29: ACTSudoku 1.5 added a preference to do this. It does, indeed, make a tremendous difference in the app’s usability.)

You may be wondering what all the green dots are. Those are pencil-marks, filled in automatically by the game. This is optional; you can turn it off in the settings, if you want to be completely free to make mistakes.

ACTSudoku's settings are in the Settings app; the only control there, as of 1.1, is a light-switch controlling the automatic pencil-marks.

With the automatic pencil-marks turned on, the game will not let you enter a wrong number. With them turned off, the game will let you enter a wrong number. Either way, you can clear the cell by tapping again on the cell and holding down on the giant number.

If you tap on a cell with a number filled in, the pop-up has only that number, and it fills the entire size of the pop-up. Holding down on it clears the cell (and, if automatic pencil-marks are turned on, restores the marks). In this screenshot, the cell has a 4 filled in.
Hold down on that giant 4 to clear it from the cell.

Of course, ACTSudoku is not perfect. It has some minor problems:

  • The interface confusion that I noted above. A long tap sets the number, whereas a short tap sets a pencil-mark. This arrangement makes no sense with automatic pencil-marks turned on—and they’re on by default. It would make much more sense to have the tap lengths the other way around.
  • The northern, eastern, southern, and western blocks are have dimmed-looking gray backgrounds, for no apparent reason. This is slightly distracting (but not enough to qualify as “garish”). I would prefer if all the blocks were uniform white.
  • I’d like to be able to turn off the timer. Again, I find this distracting.

However, it satisfies all of my requirements, so I declare ACTSudoku the winner of the iPhone sudoku race. Congratulations to Houdah Software!

Requirements for a proper iPhone sudoku app

Saturday, July 12th, 2008
  • A sudoku generator. The game should not cap me at x-hundred or x-thousand puzzles. Give me all the sudoku the iPhone OS’ PRNG can create for me.

  • Proper sudoku puzzles, not Number Place puzzles. The difference is that a sudoku puzzle is rotationally symmetric: if you turn the puzzle 180°, it still looks the same.

    Starting with a proper sudoku puzzle, → 180° → rotation gets you the same layout of starting numbers.

    Many sudoku generators actually generate Number Place puzzles, which don’t have this constraint. (In particular, all the Will Shortz puzzles are like this.)

  • Obvious input method. A row of numbers at the bottom doesn’t work because I can’t tell whether the game is prefix (tap number first, then cell) or postfix (tap cell first, then number). I could get used to either way, but a good interface doesn’t make me guess.

    • Ambrosia’s Mr. Sudoku uses handwriting recognition.

    • Platinum Sudoku is clearly postfix, because its input method is a ring of numbers around whatever cell you tap on.

  • The ability to set pencilmarks, to keep track of what numbers are viable for a cell (helping to avoid wrong numbers, especially at higher difficulty levels).

  • Simple, usable interface. This means two things:

    • No excessive artwork like Big Bang Sudoku has. I only have 16 GB of flash memory—don’t waste it!

    • No garish colors. If your sudoku game is in CGA, then I don’t want to look at it, which means I don’t want to play it, which means I don’t want to buy it.

Free stuff on iTunes: Cable TV

Tuesday, June 17th, 2008

From the podcast directory, some free cable TV talk shows. All of these carry (what appear to be) full episodes:

Note: I don’t endorse any of these shows, and purposefully listed them in alphabetical order.