Archive for March, 2011

Algorithm for Optimal Scaling on a Chart Axis

UPDATE: Seems the fellow (Han Solo? hehe) over at Harmonic Code developed some nice examples of this algorithm in action.

I’ve been working on an Android charting application for an assignment and ran into a bit of an issue when it came to presenting the chart in a nicely scaled format. I spent a some time trying to create this algorithm on my own and came awfully close, but in the end I found a pseudo-code example in a book called “Graphics Gems, Volume 1” by Andrew S. Glassner. An excellent description of the problem is given in the chapter on “Nice Numbers for Graph Labels“:

When creating a graph by computer, it is desirable to label the x and y axes with “nice” numbers: simple decimal numbers. For example, if the data range is 105 to 543, we’d probably want to plot the range from 100 to 600 and put tick marks every 100 units. Or if the data range is 2.04 to 2.16, we’d probably plot a range from 2.00 to 2.20 with a tick spacing of 0.05. Humans are good at choosing such “nice” numbers, but simplistic algorithms are not. The naïve label-selection algorithm takes the data range and divides it into n equal intervals, but this usually results in ugly tick labels. We here describe a simple method for generating nice graph labels.

The primary observation is that the “nicest” numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers. We will use only such numbers for the tick spacing, and place tick marks at multiples of the tick spacing…

Read more

Safari 5.1 in OS X 10.7 Lion & Self-Signed Certificates

I recently installed the developer preview of Mac OS X 10.7 Lion and have been quite pleased with the update. However, apart from the AFP issue, which was quickly fixed, and the Time Machine issue, which remains unsolved, it appears that Safari 5.1 does not like self-signed certificates!

Safari can’t open the page. Safari can’t open the page “https://example.org/”. The error is: “The certificate for this server is invalid. You might be connecting to a server that is pretending to be “example.org” which could put your confidential information at risk.” (NSURLErrorDomain:-1202) Please choose Safari > Report Bugs to Apple, note the error number, and describe what you did before you saw this message.

The certificate for this server is invalid. (NSURLErrorDomain:-1202)

Fortunately, there is a way to force Safari 5.1 to accept self-signed certificates. Now I know one could dump the certificate via openssl and the command line, but this method did not work for me since I am accessing my sites on an internal network and it would always dump the certificate for my default Apache virtual host. As such, the instructions below use a sort of round about method to import these certificates, but it works.

Basically these instructions show you how to use Firefox to export a self-signed SSL certificate and import it into Keychain Access. Hopefully it helps a few people out.

Read more

Netatalk AFP & Mac OS X 10.7 Lion

Upon installing Mac OS X 10.7 Lion I discovered one niggling issue. I was unable to connect to my Gentoo Netatalk AFP server. Any connection attempts would result in the following error:

AFP error when connecting to a Netatalk AFP server on Gentoo Linux

After some Googling, I discovered a quick fix to the problem. Basically, if you haven’t updated your Netatalk config file for some time, you wouldn’t have UAMS DHX2 enabled by default. To enable UAMS DHX2 support, do the following:

Edit afpd.conf:

# vi /etc/netatalk/afpd.conf

Make sure “uams_dhx2.so” is in the “-uamlist” options at the end of the file. For instance, mine looks like this:

- -noddp -transall -uamlist uams_randnum.so,uams_dhx.so,uams_dhx2.so -nosavepassword -advertise_ssh -udp

Then restart the Netatalk server. Please note that the init script may be different depending on your distribution.

# /etc/init.d/atalk restart

Now you should be able to connect your OS X 10.7 Lion installation to a Linux AFP server. It should be noted, however, that despite AFP working in this setup, I have been unable to get Time Machine to work with these settings. If you’ve managed to get Time Machine to work with Netatalk, post a comment!

Return top

Contact Information

Steffen L. Norgren
Bio: Lonely Gay Geek

+1 778 889 4498
email | AIM | MSN | Yahoo | Twitter