2718.us blog » General http://2718.us/blog Miscellaneous Technological Geekery Tue, 18 May 2010 02:42:55 +0000 en hourly 1 http://wordpress.org/?v=3.0.4 Randomizing by Random-Comparison Sorting (Revisited) http://2718.us/blog/2010/02/24/randomizing-by-random-comparison-sorting-revisited/ http://2718.us/blog/2010/02/24/randomizing-by-random-comparison-sorting-revisited/#comments Wed, 24 Feb 2010 21:09:28 +0000 2718.us http://2718.us/blog/?p=215 Yesterday, I posted the results of my quick exploration of whether sorting the list {0,1,2,3,4} using a comparison function that randomly returns < or > (with equal probability).  My exploration was prompted by a report on the non-uniformity of the distribution of the random orderings of the browsers in Microsoft’s EU browser ballot.  I had said that it seemed likely that the distribution would vary based on the sorting algorithm used.

Today, I have data (and code) that confirms the distribution is sorting-algorithm-dependent.  For each sorting algorithm, 1,000,000 instances of the list {0,1,2,3,4} were sorted with a random comparison function and the relative frequencies (rounded to the nearest whole percent) of each number in each position were computed.

Mathematica’s Sort[]
position/number 0 1 2 3 4
first 18% 12% 12% 12% 46%
second 18% 24% 18% 18% 24%
third 20% 20% 26% 20% 12%
fourth 22% 22% 22% 28% 6%
fifth 22% 22% 22% 22% 12%
BubbleSort
position/number 0 1 2 3 4
first 36% 28% 20% 10% 6%
second 28% 32% 22% 12% 6%
third 20% 22% 32% 18% 10%
fourth 12% 12% 18% 38% 20%
fifth 6% 6% 10% 20% 60%
QuickSort (random pivot)
position/number 0 1 2 3 4
first 20% 20% 20% 20% 20%
second 20% 20% 20% 20% 20%
third 20% 20% 20% 20% 20%
fourth 20% 20% 20% 20% 20%
fifth 20% 20% 20% 20% 20%
MergeSort
position/number 0 1 2 3 4
first 24% 24% 26% 12% 12%
second 26% 24% 18% 16% 16%
third 18% 18% 22% 20% 20%
fourth 16% 16% 18% 26% 26%
fifth 16% 16% 18% 26% 26%
SelectionSort
position/number 0 1 2 3 4
first 6% 6% 12% 26% 50%
second 12% 12% 20% 32% 24%
third 20% 20% 26% 20% 12%
fourth 30% 30% 20% 12% 6%
fifth 30% 30% 20% 12% 6%

The distributions are significantly different among these sorts.  QuickSort appears to provide a uniform distribution.  I believe that this is because QuickSort will only compare a particular pair of elements once, whereas each of the other sorting algorithms may compare a given pair of elements more than once (and with a random comparison function, receive a different result from one time to the next).

Here is the Mathematica notebook I used to generate this data: Randomize by Sorting.nb.  As noted in the file, some of the code for the sorting algorithms was taken from other locations and may be/is subject to their copyrights and/or license terms (I reasonably believe that this use complies with their licenses and/or constitutes fair use.  Also, some algorithms exhibited improper behavior when trying to sort lists with duplicate entries using a normal comparison function as noted in the file, though this should have no effect on the data above.

]]>
http://2718.us/blog/2010/02/24/randomizing-by-random-comparison-sorting-revisited/feed/ 1
The EU Browser Ballot and Random Sorting http://2718.us/blog/2010/02/23/the-eu-browser-ballot-and-random-sorting/ http://2718.us/blog/2010/02/23/the-eu-browser-ballot-and-random-sorting/#comments Wed, 24 Feb 2010 02:09:44 +0000 2718.us http://2718.us/blog/?p=212 An Ars Technica “etc” post linked to a TechCrunch article (apparently based on a Slovakian article, but I didn’t look into the Slovakian article to be sure) that talks about the ordering of the browsers in Microsoft’s EU Browser Ballot not being uniformly distributed.  At a glance at the Javascript that does the randomizing of the browsers (randomly orders the top 5, and randomly orders the rest), it appears to randomize by calling the Javascript array sort with a comparison function that returns < half the time and > the other half of the time.  I believe that this is likely the underlying cause of the non-uniformity of the orderings.

The second result in a google search for “javascript sort” says:

To randomize the order of the elements within an array, what we need is the body of our sortfunction to return a number that is randomly <0, 0, or >0, irrespective to the relationship between “a” and “b”. The below will do the trick:

//Randomize the order of the array:
var myarray=[25, 8, "George", "John"]
myarray.sort(function() {return 0.5 - Math.random()}) //Array elements now scrambled

This is almost exactly the method of randomization used in the browser ballot javascript.

To test the results of this randomization technique, I applied it 1,000,000 times to the list {0,1,2,3,4} in Mathematica and tabulated the relative frequencies of each number in each position. (Rounded to the nearest whole %).

position/number 0 1 2 3 4
first 18% 12% 12% 12% 47%
second 18% 24% 18% 18% 24%
third 20% 21% 27% 20% 12%
fourth 22% 22% 22% 28% 6%
fifth 22% 22% 22% 22% 12%

At a glance, it appears that the distribution is far from uniform.  My quick attempt at re-learning how to use the Χ2 test gave a probability less than 1×10-100000 that this data matched a uniform distribution (if someone can confirm/fix that, please comment).

I used the Mathematica Sort[] command to do the sorting.  I don’t know what algorithm that uses.  It appears that the algorithm used by Javascript’s sort() varies from browser to browser, though the browser ballot would be displayed in IE8 by default.  I suspect that the distribution is highly dependent on the sorting algorithm used, though I cannot readily verify it [edit: I verified it].  Regardless, this seems to be a very poor way to generate a random ordering.

]]>
http://2718.us/blog/2010/02/23/the-eu-browser-ballot-and-random-sorting/feed/ 1
A URL to Crash IE6 http://2718.us/blog/2010/02/05/a-url-to-crash-ie6/ http://2718.us/blog/2010/02/05/a-url-to-crash-ie6/#comments Fri, 05 Feb 2010 10:11:23 +0000 2718.us http://2718.us/blog/?p=210 I haven’t tested it myself, but an “etc” posting on Ars Technica says:

Want to get someone off IE6? Put these 11 characters into the address bar and hit enter: ms-its:%F0:. The browser will instantly crash. Better yet, set it as their homepage.

]]>
http://2718.us/blog/2010/02/05/a-url-to-crash-ie6/feed/ 0
Apple Magic Mouse: First Hour Review http://2718.us/blog/2009/12/01/apple-magic-mouse-first-hour-review/ http://2718.us/blog/2009/12/01/apple-magic-mouse-first-hour-review/#comments Wed, 02 Dec 2009 02:53:01 +0000 2718.us http://2718.us/blog/?p=203 On the first day the Magic Mouse was available—well, not so much available as it was shipping with new iMacs, so available to play with in the Apple Store—I went to try it out.  While I didn’t think it was the best thing since sliced bread (or any other such amazing invention), I did think it was solid enough to be worth buying, especially since I’ve been having to unstick the scrollball on my bluetooth Mighty Mouse just about weekly of late.  On about half a dozen occasions since then, I’ve been close enough to an Apple Store to wander in and see if they had any Magic Mice for sale, but had no luck until tonight.

The packaging is simple and elegant, a clear plastic shell, though it would have been more elegant without the huge white label added by the Apple Store along one long side, which covered the seam in the box and made it much harder to open than intended and left all sorts of sticky gunk behind.  Batteries are included and pre-installed.  Swapping it in for my bluetooth Mighty Mouse was as simple as turning it on, asking my Mac to set up a bluetooth device, clicking a few times, and turning off the old mouse.  The Magic Mouse is lighter and flatter than the Mighty Mouse (though heavier than the USB version).

Left and right clicking (once enabled) work just like on the Mighty Mouse.  Scrolling is nice and the momentum is a nice add-on.  Forward/backward swipes for navigation work, though I find the gestures a bit awkward (I played with these in the store when I first laid hand on the mouse).  I’d long ago disabled the side buttons on my Mighty Mouse, so I don’t miss those one bit.  As for middle-clicking (clicking on top of the scrollball), had the Magic Mouse hit about 3 months earlier, I wouldn’t have cared at all, but somewhere in the past few months I’ve gotten in the habit of using the middle click to open links in new tabs and close tabs, both in Firefox and in Chrome, so I wasn’t looking forward to losing it.  A quick search led me to this program (actually, this version, as the other one doesn’t seem to work as consistently) which works like a charm—once set up, physically click with 3 fingers on the surface to middle-click (the program defaults to a 3-finger tap, rather than physical click, and is supposed to work on multitouch trackpads as well).

So, my first-hour opinion: worth it to me, may or may not be worth it to you.

]]>
http://2718.us/blog/2009/12/01/apple-magic-mouse-first-hour-review/feed/ 0
Apache’s MultiViews Option http://2718.us/blog/2009/11/04/apaches-multiviews-option/ http://2718.us/blog/2009/11/04/apaches-multiviews-option/#comments Wed, 04 Nov 2009 15:38:59 +0000 2718.us http://2718.us/blog/?p=200 … or “how to serve different image types at one URL.”

… or “why I let myself get carried away reading from one blog post to another.”

After discovering free and cheap SSL certificates, I was playing with some sites over HTTPS to see what different browsers would show for the security.  Very quickly, I noticed that having any elements on the page that aren’t loaded over HTTPS causes the whole page to be marked as not secured.  One element in particular on one page was this “valid” icon from w3.org.  Note that the URL, http://www.w3.org/Icons/valid-xhtml10-blue,  doesn’t have any file-type extension on it.  Since w3.org doesn’t provide the icon over HTTPS (though they are fine with hotlinking the HTTP version), I needed to move it to my own server.  I went to look for the image file and didn’t find a “valid-xhtml10-blue” file with no extension.  What I found were several files with that base name and different extensions.  I couldn’t find any information in the w3.org docs or in the source for the validator, which includes all the validation icons, as to how this was achieved.  I googled to no avail.

Not long after that, I noticed an update for Bad Behavior was available and went to read the release notes.  After reading the release notes, a post about the future major version of Bad Behavior caught my eye.  In that post–no, actually in the comments on that post–there was a mention of getting rid of Apache for performance reasons.  In reading that post, in the discussions of the pros and cons of nginx versus Apache, “content negotiation” was described, and suddenly I understood how to serve the multiple image file types at one type-extension-less URL, like w3.org did.  A quick googling led me to MultiViews.

One line in an .htaccess file and it’s done:
Options +MultiViews

]]>
http://2718.us/blog/2009/11/04/apaches-multiviews-option/feed/ 1
OpenID Works! http://2718.us/blog/2009/10/19/openid-works/ http://2718.us/blog/2009/10/19/openid-works/#comments Tue, 20 Oct 2009 00:53:12 +0000 2718.us http://2718.us/blog/?p=189 Several weeks ago, I attempted to enable OpenID logins on this blog.  It didn’t work well.  It didn’t work at all.  Bad Behavior, which I consider absolutely critical in cutting down the impact of spambots, also broke the chain of redirects/reposts that enable OpenID logins.  Now, however, with Bad Behavior 2.0.30 (and 2.0.31), the RPX plugin from JanRain works!

It is now possible to log in with OpenID, automatically creating an account, and to associate an existing account with an OpenID for future logins.

Personally, I suggest MyOpenID (from JanRain) because it gives the option of using PhoneFactor’s phone-call-based 2-factor authentication.

]]>
http://2718.us/blog/2009/10/19/openid-works/feed/ 0
Converting from Maildir to mbox Files http://2718.us/blog/2009/09/28/converting-from-maildir-to-mbox-files/ http://2718.us/blog/2009/09/28/converting-from-maildir-to-mbox-files/#comments Tue, 29 Sep 2009 02:20:40 +0000 2718.us http://2718.us/blog/?p=186 A slight misconfiguration had SpamAssassin dropping spam into ~/Maildir/.spam/ while Dovecot was looking for mbox files in ~/mail/.  From my initial bit of Googling, I was expecting to have to download some program to do the heavy lifting.  Luckily, I came across a very simple blog post with a very simple answer that worked like a charm.

Need to generate an mbox out of a Maildir mailbox? Formail helps:

cd $MAILDIR/cur
for i in * ; do cat $i | formail -c >> $MBOXFILE ; done
]]>
http://2718.us/blog/2009/09/28/converting-from-maildir-to-mbox-files/feed/ 0
Graph Paper Generator http://2718.us/blog/2009/07/02/graph-paper-generator/ http://2718.us/blog/2009/07/02/graph-paper-generator/#comments Thu, 02 Jul 2009 21:13:20 +0000 2718.us http://2718.us/blog/?p=159 IncompeTech has a variety of styles of graph paper and other specialty paper formats that you can tweak a bit (e.g. set the number of boxes per inch, the stroke width, etc.) and download as PDFs to print.  It’s very useful.

]]>
http://2718.us/blog/2009/07/02/graph-paper-generator/feed/ 0
BlackBerry: App World and Pandora http://2718.us/blog/2009/04/03/blackberry-app-world-and-pandora/ http://2718.us/blog/2009/04/03/blackberry-app-world-and-pandora/#comments Fri, 03 Apr 2009 20:42:10 +0000 2718.us http://2718.us/blog/?p=137 BlackBerry App World is here and it’s nice.  Really nice.  What did I find in the top dowloads section that became the first thing I downloaded from App World?  Pandora.  Yes, Pandora for BlackBerry.  I have a feeling that this will result in my getting in trouble with my carrier for improper/over-use of my somewhat-unlimited data plan…  This is, however, the best non-productivity use for my BlackBerry so far.

]]>
http://2718.us/blog/2009/04/03/blackberry-app-world-and-pandora/feed/ 0
The Ups and Downs of Cheap VPSs http://2718.us/blog/2008/08/31/the-ups-and-downs-of-cheap-vpss/ http://2718.us/blog/2008/08/31/the-ups-and-downs-of-cheap-vpss/#comments Sun, 31 Aug 2008 06:49:30 +0000 2718.us http://2718.us/blog/?p=103 I’d written before about a really good VPS deal and how I was using it for additional secondary DNS.  Not entirely surprisingly, that provider seems to have entirely vanished shortly after sending me an email at the end of my 1-month account asking me to renew (hard to renew when their web site doesn’t exist anymore).  This has sent me looking for another deal, since I still think the premise is good.  The two providers I landed on are PTXL and Budget VPS Hosting/Web Wide Hosting.  While both seem decent on the face of it and while I don’t yet have enough experience with either to give a proper review, I can safely say that I’m becoming even more appreciative of RapidVPS, with whom I have my primary VPSs that do all my substantive serving.

My experience thusfar with PTXL is that while they sent me login info almost immediately upon registration yesterday, they didn’t actually activate that info until about 20 hours later, so I couldn’t even *buy* the thing until today.  Now, I go to buy it and find that I have to add the money to my account, then use it to buy and that I can only add money through PayPal and that they charge a fee to add money through PayPal.  This makes their advertised price deceptive, though their quarterly pricing, even with the PayPal fees, is still quite reasonable.  Once I navigated the payment mechanics, the VPS turnup was almost instant.

My experience with Budget VPS/Web Wide is a bit different.  While the Web Wide site refers you to the Budget VPS site, the Budget VPS site kicks you back to Web Wide to actually transact business.  Strange.  Account creation was essentially instant, payment via PayPal was simple (no extra fees), and almost immediately yesterday, a VPS appeared in my account panel with status “pending.”  After a few minutes of this, I went digging through their knowledge base and it was suggested that while turnup is generally quick, it may take up to 24 hours or longer and that if it’d be over 24 hours, they’d email.  I was not thrilled with this, but I’d already paid and I’m not in all that much of a rush.  I came home tonight, about 30 hours after creation, to find it still “pending” and no email from them, so I’ve filed a support ticket.

Just for comparison, RapidVPS charges what they say they charge, no extra fees, deals directly with payment, no PayPal, and account creation and turnup are both really instant, no messing around.  I’ve also been using them for a while and they don’t seem to be vanishing into the mist anytime soon.  Oh, and when I was just starting out and had a few total n00b questions, they were really nice and helpful (at no extra charge!).

]]>
http://2718.us/blog/2008/08/31/the-ups-and-downs-of-cheap-vpss/feed/ 2