An Obsession with Everything Else

http://www.derrickschneider.com/atom.xml

Monday, April 07, 2008

Dashcode/Spore Countdown Widget

For obvious reasons, I’ve been reading all the press about Spore. At one point, I decided to do the cheesy, geeky thing and find a Dashboard widget that counts down to Spore’s release. Only I couldn’t find one that I liked. So I did the even geekier thing and wrote my own.



Melissa made noises about Kool-Aid and cults, but if you’ve ever played with DashCode, you’ll realize that my widget is a barely-modified version of the default countdown template. I fiddled with some colors, set some attributes, and added a graphic from the fansite kit. Other than downloading the fansite kit, which took eons on our slow connection, the whole widget probably took 30 minutes of my time.



I’ve played with DashCode before, but always with ambitious projects in mind that demanded more than the Dashboard infrastructure would allow. I was impressed with the application at the time, but ultimately my widget ideas didn’t go anywhere. Having a project go from start to finish in a short time made me appreciate just how easy DashCode is. I didn’t need to do any coding for the widget; any moderately technical person could have set it up.

Labels:

Friday, March 21, 2008

AppleScript: Open A Bunch Of Links In Safari

I recently judged the American Wine Blog Awards. My list of nominees came as a spreadsheet with the URLs of the blogs and their names, grouped by category. Because there were 30 or more nominations in some categories, I didn’t want to open each link individually in Safari. I turned to my old friend and nemesis: AppleScript.

It took a bit of online sleuthing to figure out the quirks in Safari’s dictionary, but I eventually got a script that opens a set of URLs, each in its own tab, in a new window. I’ve included it below for anyone who might find it useful. It works well enough, given that I only needed to run it 8 times. It’s pretty brain dead as it is: There is no error checking and you have to have the URLs in a return-delimited list, which is what you get when you copy URLs out of a column in Excel. If you run it, you’ll also notice that it opens an extra tab at the “beginning” of the new window. If it bothered me, I would figure out how to remove the tab, but for 8 runs I could just click the close box. I only tested it on Mac OS X 10.5 and Safari 3.0.




set clipText to the clipboard

set AppleScript's text item delimiters to {"
"}
set urlList to text items of clipText
set AppleScript's text item delimiters to {""}
tell application "Safari"
set newDoc to make new document
set currWindow to front window
repeat with currentURL in urlList
make new tab at the end of tabs in currWindow with properties {URL:currentURL}
end repeat
end tell

Labels:

Friday, January 11, 2008

Randomness

When Pim and I looked at the prizes for Menu For Hope, we were surprised to see that a number of people had won more than one prize. I know, theoretically, that an even distribution among prize winners is one possible outcome while lists with duplicates are much more likely. But it's one thing to know it, and another thing to accept it. An iPod's shuffle feature is truly random, but it often seems as if the shuffle is favoring one artist or album. (That's why iTunes now offers a "smart" shuffle that diminishes randomness in favor of distributing artists/albums.) And in the TV show Numb3rs, an evenly distributed set of points is a clue that someone has tried to make something look random. True random numbers aren't spread out equally.

Just to convince myself, I wrote some code to demonstrate this unintuitive aspect of randomness.

First, draw 1 number from a set of 10. The probability for each number is 1/10th. Do this 10,000 times to get a bunch of results to chart, and you end up with an almost even distribution across those 10 numbers, demonstrating the fairness of the random draw:
1 1024
2 1042
3 992
4 952
5 974
6 1034
7 995
8 993
9 1001
10 993

In that run, each "turn" was a single draw. Now make each turn 10 draws. In Menu For Hope, many contributors entered multiple raffles, and drawing more than once from the same pool simulates this. We expect each number to come up once, because that's what probability tells us. But it doesn't work that way, at least not necessarily. On one run, I got this set of results:
2
5
6
7
2
10
2
6
8
3

Even though the probability of each number is 1/10, you end up with single numbers repeated. There are three 2s and 2 6s.

When I ran the 10-draw turn 10,000 times, I got these results:

1 unique numbers 0
2 unique numbers 0
3 unique numbers 6
4 unique numbers 187
5 unique numbers 1274
6 unique numbers 3457
7 unique numbers 3528
8 unique numbers 1373
9 unique numbers 169
10 unique numbers 6

Here I counted the unique numbers in each set. 10 unique numbers means a perfect distribution. 1 unique number means that every random draw hit the same number. I didn't implement the logic to separate duplicates (the 6 in the previous example) from the triples (the 2 in the prior example). Or quadruples, for that matter. This was a simple simulation.

The odds of randomly getting an even distribution are pretty low. You are roughly 600 times more likely to have 6 or 7 unique numbers, meaning that some of those numbers are duplicated (or tripled or whatever). You’re 200 times more likely to have a scenario where half the numbers are missing. You’re 30 times more likely to have just 4 unique numbers: a whole host of repeats. The numbers looked similar on multiple runs.

This makes sense if you think about it. In the second draw of the 10-draw turn, you have a 10 percent chance of drawing a duplicate. If you don’t, you have two unique numbers, and on the third draw you have a 20 percent chance of duplicating one of the existing values. By the time you get to the tenth draw, there’s a 90 percent chance that you’ll draw a number that’s already been drawn, assuming all the others were unique.

Menu For Hope, of course, is much more complicated. Raffle ticket purchasers can stack the odds in their favor by buying more tickets for a given raffle. Prizes with fewer bidders have different odds than those with more bidders. And it was about 100 draws across 9,000 raffle tickets. But even the simple version in this post, where each of just 10 numbers has an equal probability, shows that duplicates and triplicates should be commonplace. So it's not surprising that some people won multiple prizes: It would have been more surprising if none had.

Labels: