I've spent some time updating my firefox extensions so that all of them work with Firefox 3 Beta 3. At present they can only be downloaded from this site as it takes the Mozilla Addons team a few days to approve updates. My extensions page is now back up and running though and contains details on all 3 of my Firefox Extensions (Font Finder, Stop! Hammertime!, and STOP in the name of love) as well as download links for the new releases.
I won't be making any further updates to the stop buttons (apart from making them work with future version of Firefox) but I will be continuing development on Font Finder which could benefit from a visual overhaul as well as a clipboard function! I'll be updating on here when it happens so sign up to the RSS feed for the latest news!
I've been having a play around with Google Charts recently but came across a problem with the range of values that can be used. With simple encoding, you can only have values between 0 and 64, and with text encoding only values between 0 to 100. This is annoying when dealing with things such as tracking website hits or weight when values are typically much higher.
I played around with some functions to try and factorise the numbers so that they would be in the range of 0 to 100 but this didn't go so well so I decided to tackle Google's extended encoding.
This is a system of encoding that basically takes a pair of alphanumeric characters and translates them into a number between 0 and 4095 (much better!). So for example, B9 translates to 125 and .a would translate to 4058. However, although this has a much larger range, it's a bit harder to get your head around and so what is needed is a simple function (or two) to convert to and from the extended encoding. Predictably, I have said PHP functions here:
They work fairly simply by taking advantage of PHP's casting methods in that a string can be interpreted as an array.
In the first function, array_to_extended_encoding(), an array of numbers should be passed e.g. array(250,39,400,1904,2). The function first lists all of the extended encoding characters in order as one string named $characters. It then loops through our array of numbers, and creates two variables; $first and $second. In $first, we store the number from our array divided by 64 and rounded down using the floor() function. For $second, we use the modulus operator (%) to find the remainder once the number from the array is divided by 64. We then take both $first and $second and work out the encoding by looking up the numbers from within the $characters cast as an array. This gives us 2 characters which make up the extended encoding for the number. We keep extending the value of $encoding until we end up with a string representing the full extended encoding of the array passed to the function.
The second function, extended_encoding_to_array(), is slightly more advanced. It accepts a string as its only parameter which should be an extended encoding (e.g. $encoding = 'AA..B9aC'). We first list all of the characters in a string as we did for our previous function, but then we create two arrays which will contain all of the numbers we need to decode the extended encoding. In $first, we create an array of each character in the $characters string as a number multiplied by 64 (so the letter b would be 64 as it is signified by number 1 in the array multiplied by 64). Within $second we perform a similar operation but instead just assign the number of the character rather than multiplying it by 64. This gives us two arrays, with keys relating to each character that can be used as an encoding and values as the numerical equivalent. It is now a simple case of splitting the string that was passed to the function into chunks of 2 characters using str_split() and looping through the returned array setting the value of each character within the pair from the arrays we created. We then add the two returned numbers together to give us the decoded figure and add it to an array which will be returned by the function.
Simple? It has certainly made things a lot easier for the functions I'm writing for a PHP wrapper for Google Charts and hopefully it will help somebody else as well. If you have any questions or comments, please get in touch.
As some of you may have noticed, the new site design has caused the Firefox Extensions page to go awry. This will return shortly (along with a few new extensions) but for the time being you are better to go the Mozilla Addons site to download the extensions.