Author Archives: paulrichards19

Firefox 3 – The best bits

Firefox logoThe latest version of Mozilla Firefox is due to be released later early next week on the 17th June 2008. I’ve been participating in the pre-release testing and cant say enough good points about it. If it wasn’t for incompatibility for certain addons I use (namely firebug) I would of switched to it weeks ago. Now RC3 has been released compatibility for popular addons such as foxmarks and firebug are now available.

So why should I bother downloading (7 Mb) and installing FF3?

As you’ve all probably already read on the web site FF3 has major security, performance, improved password management, anti virus integration & a download manager just to name a few.

What interest me is features that ultimately change the way we surf the web and interact with our web browser. FF3 takes two classic old web browsing features; bookmarks (favourites) and history and gives them a new lease of life. If you like me i’ve really used the history because its always been pretty inaccessible to search. I use bookmarks but can never find anything in them and normally just re-search it on Google.

FF3 provides loads of new tools and features to sort, search and tag bookmarks. The best feature is what they call ‘Location bar & auto-complete’. This is a Google suggest inspired search tool that help you to quickly locate that missing bookmark or that pages you know you were once on.

Autocomplete

As you can see its clear and indicates if its a current bookmark or not by the star on the right. It has a sort of Facebook search look about it that highlights the matched letter(s) in bold.

There are massive improvements that make upgrading more then worth you while. Firefox RC3.

Nike plus data API access

As Nike + wristband user and a web developer i thought it would interesting if i was able to access the raw data of my runs.

Nike provide various ‘widgets’ that can be embedded into web pages which is convenient and fun. But i find them a little clunky in flash. You can see an example of one I added to this site here. So i decided to see what I could find on the net to access the run data.

It turns out the everyone’s run data is accessible via a URL linking to a XML document. All that is required is your user ID. Simply go to the following URL and insert your user ID at the end of the string.

http://nikeplus.nike.com/nikeplus/v1/services/widget/get_public_run_list.jsp?userID=<YOUR ID HERE>

All my data can be accessed here for example. Please take note about the XML document

  • Distances are in kilometres (despite having all my settings in miles).
  • Time locals appear to be correct.
  • Time is measured in millseconds

Now your probably wondering how do i find out my user ID. Do this:

  1. Sign into Nike Plus.
  2. Click ‘My Runs’.
  3. Click the ‘Share’ button on the top right of your runs.
  4. Click ‘Add to a Web page’.
  5. Click ‘Grab the Code’. Now it copied the code to your clip board.
  6. Open up a text editor and paste it in (ctrl v). You should have something like this below. The ID is highlighted, just copy it out

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=”http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0″ width=”198″ height=”145″ id=”Nike+ Runs” align=”middle”><param name=”allowScriptAccess” value=”sameDomain” /><param name=”wmode” value=”transparent” /><param name=”movie” value=”http://nikeplus.nike.com/nikeplus/v1/swf/scrapablewidget/rundetail.swf” /><param name=”quality” value=”high” /><param name=”bgcolor” value=”#ffffff” /><param name=”FlashVars” value=”type=last5Runs&userDefaultUnit=mi&screenName=paulrichards&dateFormat=DD/MM/YY

&id=1759895612&region=emea&language=en&locale=en_gb”/><embed src=”http://nikeplus.nike.com/nikeplus/v1/swf/scrapablewidget/rundetail.swf” quality=”high” wmode=”transparent” bgcolor=”#ffffff” width=”198″ height=”145″ name=”Nike+ Runs” align=”middle” allowScriptAccess=”sameDomain” FlashVars=”type=last5Runs&userDefaultUnit=mi&screenName=paulrichards&dateFormat=DD/MM/YY&id=1759895612&region=emea&language=en&locale=en_gb” type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/getflashplayer”></embed></object>

Ajax Notice Board 1.1 Released

Just like a notice board but an on-line version! Feel free to move notices around and the new position is automatically saved in the backend database. When other are people interacting with the notice board notices move automatically into their new position, refreshed via Ajax every 15 seconds. It was inspired to do it after using the magnetic board and need a little more functionality!

Go to its own page for a demo and download.

Dates functions with MySQL and unix timestamp

MySQL has powerful functions built in to manipulate data with dates. These functions only work within MySQL providing your using their own date/time stamp. If your like me, your much rather use the PHP function time() to get the Unix timestamp and store that in the database. It seems a shame to miss out on these features because we use Unix time. Never fear, the following examples shows how to get round this using FROM_UNIXTIME(). So what happens now if we want to SELECT or GROUP data by periods, such as by week, month or year. Take one look in the MySQL manual and there are few practical examples on how this can be done using only the Unix timestamp. Below I run through a practical example and how this can easily be achieved. If you want a mock up table to try it out, run the following SQL. This table is a vastly simplified version of a e-commerce system order table, but the logic here could be applied to any type of database driven web site.

CREATE TABLE `orders` (
`order_ID` int(11) NOT NULL auto_increment,
`timeordered` int(11) NOT NULL default '0',
`grandtotal` double(10,2) NOT NULL default '0.00'
PRIMARY KEY  (`order_ID`)) ;

This table contains the Unix timestamp in `timeordered` and `grandtotal` contains a decimal number. We are going to construct a SQL query that will list the number of orders in a month, the total amount of all those orders and the average value of those orders. Lines 1, 2, 4 are standard functions used to calculate our values. The interesting lines are 5 and 6. If I was using the normal MySQL timstamp and could simply write GROUP BY MONTH(), YEAR() to achieve the results we want. You may ask why are we using both MONTH() and YEAR() when we just need it to group by MONTH(). Well the answer is you could just use MONTH(), but that would only ever return 12 rows (1 for each month) no matter over how many years. So for example it would group January 2004, January 2005 or any other January. For some systems this would be undesirable. Using YEAR() ensure only one month and one year is in one return row.

SELECT COUNT(order_ID) as `number`,
SUM(grandtotal) as `cgrandtotal`,
FROM_UNIXTIME(timeordered, '%M %Y') as `fdate`,
AVG(grandtotal) AS `averagegrand`
FROM `orders`
GROUP BY MONTH(FROM_UNIXTIME(timeordered,'%Y-%m-%d %H.%i.%s')),
YEAR(FROM_UNIXTIME(timeordered,'%Y-%m-%d %H.%i.%s'))
ORDER BY timeordered DESC

Normally we put the column name in the brackets of the function of the MySQL date (ie YEAR(column-name)). But because we are using Unix time we must use the function FROM_UNIXTIME(column-name-of-unixtime, format). The format parameter simply specifies how to turn the Unix time to a understandable timestamp for MySQL, the ones shown on lines 7 and 8 seem to work fine, I believe there may be shorter ones that can be used.

So the query above will return something like this (after adding your own dummy data!):

number cgrandtotal fdate averagegrand
8 532.00 January 2008 66.50
21 1201.20 December 2007 57.20
17 1041.25 November 2007 61.25

The example below assumes you have some basic knowledge of SQL and has been tested on MySQL 4.1.