Installing Coldfusion 10 on Ubuntu!

This keeps tripping me up, it’s caused me problems when upgrading production servers… you need to export the installation directory when installing Coldfusion on a Redhat or Ubuntu server.

mkdir /root/cf_install
export IATEMPDIR=/root/cf_install

Otherwise the installer completes but fails silently on loads of stuff and Coldfusion don’t work proper!

Here’s an Adobe Forum post about the last time I made this mistake:

Merge sort in Coldfusion

For far too long I’ve been using Bubble sorts, they’re very basic and very slow but mainly I’ve been sorting tiny little arrays or lists and the server just don’t care about it.

But that’s not the proper way of doing things. Now I don’t really understand sorting algorithms all that much so I use this site to work out which one I want to use, plus a little bit of wiki:

I’ve decided to use merge sort from now on mainly because it’s quite fast and although it generally seems to be a tiny bit slower than a shell or heap sort, it is stable which shell and heap are not. I don’t really know what that means but it sounds safe! Also it works much better on large sets than any of the simple algorithms.

The algorithm is more complex than a Bubble sort and although I understand the gist of it I decided to find someone elses code and use that. So I did.

Simon Horwith’s blog entry on search algorithms

This guy has made a fantastic little demo app, very comprehensive, with 6 different sortin algorithms in it. You can download the zip and drop it into a server and test the speeds of each algorithm. Then the code is there for you to play with, or as Simon put it: I look forward to hearing how people put them to use as well as any other findings with them.

I’ve tweaked his code a bit, so it will take an array of structures/objects, and sort by any publically accessible field of the that structure. Here’s how I’ve used it in the test page:

sort = new mergesort();

a = {}; = 'Pete';
a.age = 27;

b = {}; = 'Holly';
b.age = 22;

c = {}; = 'Jesus';
c.age = 2012;

peeps = [a,b,c];


Original array


// sort peeps array, by into Descending (default) order
peeps = sort.sortArrayByFieldAscending(peeps,'name');


Sorted by name in descending (default) order


// sort peeps array, by oject.age into Ascencing order
peeps = sort.sortArrayByFieldAscending(peeps,'age',true);


Sorted by age in ascending order


You can view the live demo of it working here and I’ve also attached a .zip of the .cfm and .cfc.

The ZIP link above doesn’t work at the moment, I’ll have it fixed shortly!

Thanks to Simon Horwith, and hopefully someone else will find this useful!

Precisely the same Railo mistake as last time

In the past I’ve had problems with my blog working on mobiles. Something to do with the way it’s set up for Coldfusion but I’m running Railo.

I blogged about it here: My very few BlogCFC woes

So when I switched across to my new server recently, I forgot to make the changes to get it running on my new server. I have in fact done something slightly differently this time though, I’ve changed the /railo/tomcat/conf/web.xml file instead of the one in the instance of, so the changes are global.


/index.cfm/ *
/default.cfm/ *
/post.cfm/ *
/archive.cfm/ *
/blog.cfm/ *
/page.cfm/ *

/mobile/index.cfm/ *
/rewrite.cfm/ *

Note: once again, the white space between the slash, /, and the star, *, is just
to stop the blog trying to use it as a comment.

So thanks Sparky for pointing out the error, and no thanks to you Pete, for being an idiot and not correcting the problem that you’ve had before so you should have known! Dumb ass.

Editing all the links in a page

I’m not sure if this is a duplicate post of not… I couldn’t find the original one, so here goes anyway.

We had the situation at work where we wanted to find all the links in a news article, in the back end editing system, and send them all to something like to shorten them, so make it less likely that the article hit the maximum word count.

This might have been a forum post actually, anyway, that’s besides the point.

So I came up with a quick example to work out how to do it. Instead of using a URL shortening API for the demo I’ve just reversed the hrefs. But it would be easy to swap them that code out for or something similar.

Edit HREF's demo

This is totally copied from Ben Nadel's blog, an idea which he got in turn from A Book Apart: Mobile First, but I thought it was worth mentioning again.


// find the a tags
arrHref = reMatchNoCase(']*>',longText);

// get the array length and loop over
cntHref = arrayLen(arrHref);
for(h = 1; h LTE cntHref; h++) {

// get the individual href,
thisHref = arrHref[h];
thisHref = reReplaceNoCase(thisHref,'

// reverse it, it, whatever takes you're fancy
reverseHref = reverse(thisHref);

// replace the original href with the new one
longText = replaceNoCase(longText,thisHref,reverseHref);


You can see the live sample here:

It might not be completely robust, it might need updating for production use but the concept is there and it works.

Railo and MySQL column alias

This seems like a very odd situation, but Railo has stopped supporting column aliases by default – well it’s the JDBC database driver I think… I’m not too good at all this back end java/database stuff.

But basically it all worked fine, now I’ve upgraded Railo, and things like this will throw an error.

SELECT col1 AS colOne FROM table

I don’t see why, this is such a common thing to do… Anyway, some one else has had the exact same problem not that long ago, and Google very kindly found me their blog post so I could fix it.

You just have to set “Alias Handling” to “true” for your datasources in the Railo Server Administrator. Then every thing works fine again.

I think the point of it is something to do with being able to grab the true column name and get hold of better metadata, but at the moment that’s no use to me!

I really hope Adobe don’t start doing this with Coldfusion!

Credit has to go to Anuj Gakhar for this fix:

MySQL update/insert/delete rows affected in CFScript

There’s a way of getting the rows affected by an update, insert or delete MySQL query in CFScript.

I didn’t realise this until yesterday, and I’ve been doing this for a while now. I really should read more release notes.

I’ll update my page to show this, but I thought it was worth posting about anyway

// create query string
strSelectRows = 'DELETE FROM table WHERE col = "potato"';

// create query, assign datasource, assign query string, execute and capture returned result
qrySelectRows= new Query();
qrySelectRows= qrySelectRows.Execute().getResult();

// dump results out

Check the demo here to see the tasty results. I’ve also shown the whole prefix component in the demo.

Automatically URLS in a text block

Gosh, what a long title. I don’t like writing blog post titles, but that one seems to make sense.

I wrote this code the other day as a kind of demo for an idea at work.

We allow some HTML in forum posts at work, but if a user puts in loads of long URLs then they hit the post limit quickly. So we wanted to write some code that would scan through a post, find the URLs, shorten them, and then cap the post to it’s limit.

Instead of using a API here (other URL shortening services are available) I’ve just reversed the href, so becomes moc.etis.//:ptth… which was quite a lot of fun in itself.

Edit HREF's demo

This is totally copied from Ben Nadel's blog, an idea which he got in turn from A Book Apart: Mobile First, but I thought it was worth mentioning again.

arrHref = reMatchNoCase(']*>',longText);


cntHref = arrayLen(arrHref);

for(h = 1; h <= cntHref; h++) {
thisHref = arrHref[h];
thisHref = reReplaceNoCase(thisHref,'
reverseHref = reverse(thisHref);

longText = replaceNoCase(longText,thisHref,reverseHref);


Installing a local Railo site on MAMP

I’ve just set up my local development environment on my Mac… something I’ve never done before.

I’ve done it many times on Ubuntu and Windows, and most of it’s the same, but I thought I’d record the process, mainly for my own future reference.

Installing MAMP is easy, you just download the installer/zip thing from their site:

After that, I installed Railo, which was a fairly similar process, it only took a few minutes using their installer:

Then after that it gets a bit awkward. I’m building my sites using Coldfusion Builder, and they’re hosted on github as well. So first thing you’ve got to do is make your local directory, it doesn’t really matter where you put it but I used the default htdocs folder of the MAMP install: /Applications/MAMP/htdocs/SiteName

I used git to clone down my repo, and that made the folder structure for me:

cd /Applications/MAMP/htdocs/
git clone

In order to do that you’ve got to have you .ssh keys setup, but you don’t need to use git, you just have to have your local website files somewhere on your hard drive.

Once you’ve got some site files to use you’ve got to do 3 things:

  • Tell the Railo install where they are
  • Create a VirtualHost element in your apache config files
  • Tell Mac OS X that you have a local site

To get railo working, you need to edit the /Library/Railo/tomcat/conf/server.xml file. At the bottom there will be some commented out code telling you how to add a new railo context. Basically you just have to give it the path to your site files, and the name of your local domain… you have to make this up now. It can be anything, like localDevSite, or fatPigsSmell, anything at all.



You should see it down at the end of the server.xml file.

Once you’ve done that, you need to restart railo. You can do this by simply going to the administrator and clicking the restart link on the left hand side, under the services category in the menu.

When railo has restarted you should see a WEB-INF folder in your local site files that railo has created, and you’ll also see your site files listed as a context at the bottom of the page when the administrator loads.

If you’re not with me at this point… then sorry. Email me I might be able to help.

If you’ve got the WEB-INF file, then woohoo. Almost there.

Next you have to tell apache that you’re running a whole new website on your server. So you edit /Applications/MAMP/conf/apache/httpd.conf and add lines similar to the following at the very end:

DocumentRoot "/Applications/MAMP/htdocs/SiteName"
ServerName localSite

You basically telling apache exactly the same things you told railo. I don’t know why railo can’t just copy apace, it’s annoying.

The last thing to do is tell mac os x that when you type http://localSite you want to look at your local development website, you don’t want to go hunting for it on the internet.

So you edit /etc/hosts and simply add the new local host name to the end of the list after, so it looks something like this

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## localhost localNPT

And that’s all I did. Now when I visit http://localSite, I get a copy of my website, pulled down from github.

If this doesn’t work for you, or it breaks anything, well sorry but web servers are a pain in the arse. Restart everything. That usually fixes it.

I have to give credit to these 2 blog posts that helped me out:

On that second one it was the replies from keesiemeijer that really helped

Scotch on the Rocks is on!

If I had to guess, I’d say there were about 5 people that read this blog that make websites and probably only 1 that do Coldfusion coding (and Tom already knows about SOTR).

But just in case there is someone else that find this blog and does Coldfusion, I’d like to point out that SCOTCH ON THE ROCKS 2012 IS GOING AHEAD!

I’ve only been to one SOTR before (2011), I found out about it just after the 2010 event and was very gutted, as many amazing Coldfusion developers and other internet/web/computer/geek type celebrities were going to be there as well.

Anyway I managed to get along to the 2011 event and found it incredibly useful. I’ve actually changed a huge amount of my working style since going there, as I learnt about new technologies and gathered advice from other developers.

I also got to see about 5 seconds of porn…due to a slight error of one of the presenters.

Breasts aside though, it’s an excellent conference, sponsored last year by Adobe themselves, as well as Railo (free open source Coldfusion server), and hosted/organised mostly by Fuzzy Orange.

Last year there were talks on HTML 5, CSS 3, Regex, various database technologies, increasing your efficiency as a developer and many many other things.
So even if you don’t do Coldfusion it’s worth going, because there are other beneficial talks, it’s backed by Adobe, and it’ll help teach you how incorrect you are by not using Coldfusion (or Railo).

So basically, go to Scotch on the Rocks 2012.

There are no details about it yet… it might be in Edinburgh, it might be in Amsterdam. Either way I’m going, surely that’s reason enough for you to go?