May 04

Converting Unix timestamp values in ColdFusion

Posted by James Netherton | Sunday 04 May 2008 4:58 PM | In ColdFusion

I've been working on an application that integrates with a third party payment gateway solution. The payment service sends back a transaction timestamp after a purchase is successfully completed in the unix time format.

I spent some time trying to figure out how to covert this into a 'normal' date format with ColdFusion. The solution is pretty simple as the following code sample demonstrates.

<!--- Unix Timestamp representing 4th May 2008 00:00:00 AM --->
<cfset variables.unixTimeStamp = "1209859200"/>

<cfoutput>#dateAdd("s", variables.unixTimeStamp, "01/01/1970")#</cfoutput>

Apr 19

A piece of ZX Spectrum nostalgia

Posted by James Netherton | Saturday 19 April 2008 9:35 AM | In Funny

Those of you lucky enough to own a Sinclair Spectrum will remember the joys of popping your favourite game into the cassette player and then sitting back to watch the stripy colours flashing while the game loads. Sometimes after waiting 5 - 10 minutes you'd be presented with the words....

R Tape loading error, (0:1)

You can now relive this experience online over at http://www.rtapeloadingerror.com/, albeit without tape loading and 5 - 10 minutes waiting time.

Don't have a clue what I'm talking about? Shame on you! Head over to these links to find out more:

http://en.wikipedia.org/wiki/ZX_Spectrum

http://www.worldofspectrum.org/

Apr 15

Run ColdFusion on GlassFish

Posted by James Netherton | Tuesday 15 April 2008 8:10 PM | In ColdFusion

I thought this was worthy of blogging seeing as it's not often that ColdFusion gets mentioned on The Server Side.

Damon Gentry has posted an article on how to get ColdFusion running on Sun's open source JEE application server, GlassFish.

As JRun is no longer being actively developed, maybe it's time to start looking at some of the alternative application servers to deploy ColdFusion onto.....

Mar 31

Disabling hard drive optimisation on Windows

Posted by James Netherton | Monday 31 March 2008 6:52 PM | In Windows

When Windows detects that the user has been inactive for a certain time period, it will execute certain optimisation tasks whilst there is plenty of spare processing power available. One of these tasks is to create a background process that will defragment and optimise hard disk drives. Depending on the drive partition type, Windows will spawn either dfrgntfs or dfrgfat to handle the optimisation.

I've decided to disable this process for Windows under my OS X Parallels bootcamp installation. Every now and then I'll hear the hard drive spinning up and have a fair chunk of CPU get eaten away as the hard drive defragmentation process runs. It's a real pain when I'm in the middle of coding, web browsing or anything else. So I've decided to disable the optimisation process altogether, as I don't really care about my bootcamp install all that much. If it starts running really, really slowly, I'm happy to reinstall Windows.

How to disable drive optimisation:

1. Head over to the Microsoft Power Toys to download and install Tweak UI

2. Fire up Tweak UI and select the 'General' tree item from list of options

3. Uncheck 'Optimize hard disk when idle'

4. Apply the settings

Mar 29

Enabling PHP on Leopard

Posted by James Netherton | Saturday 29 March 2008 12:32 PM | In PHP,Mac

This post refers to the default Apache HTTP server that ships with Leopard. By default it doesn't load PHP5 which also comes pre-installed with Leopard. Here's how to enable the PHP module.

Open up a terminal session and run through the following steps:

1. sudo vi /private/etc/apache2/httpd.conf
2. Search for the string "php" by typing /php [return]
3. Hopefully you'll have found the line starting, #LoadModule php5_module
4. Remove the # symbol before the LoadModule statement
5. Exit vi and save the file, :wq!

That should be all there is to it. You can start the mac web server and you'll be able to start serving up PHP templates. You will probably also want to do some customisation of PHP.ini. Here's how I did this:

cd /private/etc/
sudo mv php.ini.default php.ini

You're then free to start editing the ini file.

This isn't the greatest solution to get PHP running on Mac. It appears the compiled PHP version shipped with the Mac is missing some useful modules such as SOAP.

Feb 17

ColdFusion 8 - Custommenu.xml

Posted by James Netherton | Sunday 17 February 2008 12:56 PM | In ColdFusion

In previous versions of ColdFusion you were able to add custom menu items to the ColdFusion administrator by creating a template named extensionscustom.cfm and placing this within the cfadministrator directory.

Peek within the cfadministrator directory under CFIDE within ColdFusion 8 and you should see a file named custommenu.xml. By adding entries into this file you can replicate the behaviour offered by extensionscustom.cfm.

The XML file has the following structure:

<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
   <submenu label="My Custom Menu">
      <menuitem href="href" target="content">Custom Resource</menuitem>
   </submenu>
</menu>

You can have as many submenu or menuitem elements as you wish. Once you have made your changes, head over to the ColdFusion administrator and you should see your custom menu items appended to the end of the main navigation menu.

Feb 15

Issues with Flex DataGrid and custom ItemRenderers

Posted by James Netherton | Friday 15 February 2008 6:48 PM | In Flex

I've just finished implementing a work around for some problematic behaviour I came across within the Flex DataGrid. I have a user interface which has a DataGrid with custom item renderers so that combo boxes can be rendered within DataGrid cells. In order to set the combo box selected index to it's appropriate value, I was invoking some custom code on the combo creationComplete event.

Some freaky things were happening when data within the grid was being refreshed. Some of the combo selected values were not in the order I expected them to be in.

After doing some digging, it seems that DataGrid ItemRenderers are reused for performance reasons. This is a problem if using the creationComplete event.

The solution is to override the container 'data' setter property method, with an implementation like the following:

public override function set data(value:Object):void{

super.data = value;

if(value == null){
return;
}

//Further custom logic here....
}

There's a great overview of the problem over at Steve Kamerman's Blog. There's also a nice working example here.

Some other blog posts that helped are:

Flex DataGrid ItemRenderers Explained

Item Renderers in DataGrids - A Primer for Predictable Behavior

Feb 05

MySQL: STOPPING server from pid file

Posted by James Netherton | Tuesday 05 February 2008 10:11 PM | In MySQL

If like me you're lazy and you don't want to compile the MySQL source to get it running on your Mac, you may have downloaded the package installer from the MySQL website.

I just spent the last hour or so trying to overcome an error that occurred whenever I tried to start the MySQL server:

Starting mysqld daemon with databases from /usr/local/mysql/data
STOPPING server from pid file /usr/local/mysql/data/mysql.pid
080205 mysqld ended

After digging through a few MySQL forum posts, the problem was related to permissions. MySQL files and directories need to be given ownership under the MySQL user account. The fix is quite simple:

cd /usr/local/mysql
sudo chown -R mysql data
sudo chgrp -R mysql .

Feb 04

ColdFusion webservice debugging

Posted by James Netherton | Monday 04 February 2008 11:31 PM | In ColdFusion

Debugging webservices can sometimes be a painful experience. ColdFusion provides some help via the getSoapRequest and getSoapResponse functions, which enable you to view the SOAP request / response XML.

Suppose you want to see all SOAP requests and responses sent to the ColdFusion server. This can be achieved by making a simple change to the client-config.wsdd file. On my multi server ColdFusion 8 installation, the file is located in:

[Installationdrive]\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF

The beginning of the file has the following declarations:

<globalConfiguration>
<!-- Give ColdFusion the ability to log the request and the response SOAP message -->
<!-- Not recommended for production -->
<!--
<requestFlow>
<handler type="log"/>
</requestFlow>
<responseFlow>
<handler type="log"/>
</responseFlow>
-->


<!-- Change for CFMX 7: Turn off multirefs -->
<parameter name="sendMultiRefs" value="false"/>
</globalConfiguration>

Uncomment the lines around the requestFlow and responseFlow tags. Save the file and restart ColdFusion. You should then see SOAP requests and responses being written out to the cfusion-out.log file.

Note the warning in the snippet above about not enabling SOAP logging in a production environment. For obvious reasons it makes sense not to leave logging enabled for long periods in production.

Jan 30

Create your own O'Reilly cover

Posted by James Netherton | Wednesday 30 January 2008 1:20 PM | In Funny

This is very cool....

http://www.oreillymaker.com/

Originally discovered over at Ajaxian.