Find the closest in a list of numbers

April 26th, 2014

For a while now I’ve been working on a core set of functionality that I include with every application. In fact, my applications extend a core app that contains a whole bunch of commonly used functionality – but that’s a whole other post.

I’d intended to blog about some of the components I’ve been writing as I go along, but as is so often the case I find myself moving onto new work before I’ve sat down to write about the last.

Today, I needed to pass a number to a function and return the closest number in a given list.
So for example, a list of ’10,20,50,100,200,1000′ and a value of 42, should return 50.

It’s a simple requirement, but Google returned nothing & the mighty Ben Nadel hadn’t written a comprehensive post on how to do it along with speed tests and examples involving hot girls; so I wrote a function and added it to my ever increasing library.

As it’s small, I thought I’d share… in doing so, I realised I’ve not updated this site in way too long – so for this I apologise.

Here’s what I came up with – hopefully it’ll save someone a bit of time:

Posted in CFKrypton, ColdFusion, Railo | No Comments »

Lock wait timeout exceeded with ColdFusion & MySQL – Checked yer logs?

March 31st, 2013

I just spent some time diagnosing an issue with inserting records into a MySQL database and I eventually tracked it down to a gotcha I think a lot of other people may run into.

The code in question does some fairly simple things – inside a <cftransaction> it’ll insert a record into a table, read the record back and insert a record into a second table with contents from the first record.

Easy, right? Except every time I tried it, I’d get a timeout with the following error:
Lock wait timeout exceeded; try restarting transaction
Inserting the records manually worked fine, but not from CF.

After searching through the MySQL logs, I noticed that a second connection was made half way through the transaction – the remaining query would then time out and the transaction would roll back.
What I discovered is this:

<cfquery datasource="yourDatasource">

is treated as a different connection to

<cfquery datasource="yourDatasource" username="" password="">

Generally I won’t include usernames and passwords in my cfquery statements, but I’m connecting to a library that does by default. I’ve found that leaving the authentication fields blank will connect fine using those specified in the datasource, however it seems that MySQL considers it a different connection which will cause a problem in a transaction.
I’m running Railo 4 – the behaviour may differ on ACF.

So there you have it. A great argument for encapsulation and a nicely configured datasource object.

Posted in ColdFusion, Railo | No Comments »

Opinion: The evolution of Affiliate Marketing

November 5th, 2012

I often describe web development as an industry that’s inventing itself on a daily basis. One of the things I find fascinating is the evolution of an idea over time. When a system, model or process is invented online, it’s exposed to the entire world. The world inevitably has influence on it. The world changes it to fit new needs and desires often far beyond the scope of its original design.

There are many examples of this, and most are far more interesting than the one I’m going to talk about; but I got to thinking recently about the evolution of affiliate marketing.

Read the rest of this entry »

Posted in E-Commerce | No Comments »

Dynamically resize images with ColdThumbs

March 12th, 2012

A few days ago I was coding up a WordPress theme for a client who intended to move away from WordPress.com.
One thing I noticed is that on the WordPress.com installation, images were dynamically resized by adding a parameter after the image file extension.
i.e. http://domain.com/images/an-image.jpg?w=400
Since many of the posts linked to images in this way, I had to find a way to replicate it into the WordPress installation on the local server. A quick Google search and I discovered ‘TimThumb‘, a php script for dynamically resizing images, very popular amongst WordPress theme developers.

Within a few minutes, I had the functionality I was looking for.
‘Very cool’, I thought to myself… So why can’t I do this in ColdFusion?

Enter: ColdThumbs!

Inspired by TimThumb, ColdThumbs is allows you to dynamically resize an image (local or external) to your desired dimensions.
The script will automatically create a cached version of your resized image and return the image as content.

I developed this as a bit of fun one Sunday (yeah, that’s how I roll) and have put it up as my first project on RIAForge. It’s working great for me, but I’d love to hear feedback or feature requests from anyone using it.

Check out the ColdThumbs page for full details.

Posted in ColdFusion | No Comments »

Integrate WordPress into your ColdFusion app

January 13th, 2011

Lately I’ve been working on a few ColdFusion apps that require a comprehensive blog system. While I could easily install Mango Blog or Blog CFC, nothing really rivals the functionality of WordPress when it comes to blog apps – but of course, WordPress is a PHP based system.

Installing WordPress alongside a ColdFusion app isn’t too difficult, but I need to customise the blog so that it looks identical to the rest of the site, and allow the user to switch seamlessly between the two.

This level of integration requires two main bits of functionality. Firstly I need to use ColdFusion to connect to the WordPress database and pull out articles and comments for use in summary blocks around the rest of the site, and secondly I need to be able to embed CFML templates directly into the WordPress blog to generate headers and footers whilst keeping any session based information such as login status, cart contents etc. – Essentially I need a CFINCLUDE equivalent for PHP.

Read the rest of this entry »

Tags: , ,
Posted in ColdFusion, Railo, Website Development | 18 Comments »

Cache and display multiple Twitter feeds in ColdFusion – CFC

November 19th, 2010

I’ve worked on a few sites recently that have required Twitter feeds to be pulled in and displayed on the homepage.
Thanks to the awesome <cffeed> tag this is a relatively easy task, but I’ve noticed a bit of an overhead when pulling the data in from Twitter’s servers.

I had a look around and came across this post by Simon Bingham, showing how to cache the results of a Twitter feed in the Application scope.

This worked well, but I needed to be able to pull in both outgoing tweets (using the Twitter ID) and incoming tweets (using a search string). This meant not only updating the CFC to take both types of argument and act accordingly, but also to allow mutiple feeds to be cached.
Building on Simon’s original, I’ve created a new CFC that does just that, and even has a bit of error handling for good measure.

Read the rest of this entry »

Tags:
Posted in ColdFusion, Railo | 2 Comments »

If ColdFusion is dead, it’s Adobe that killed it.

September 15th, 2010

(Or, ‘Controvertial ColdFusion post #34124′)

I’ve been using ColdFusion happily for the last 6 years. I can honestly say that if it weren’t for the ease of learning ColdFusion, and the instant gratification to be gained from rapidly developing apps that interact with databases, I’d have never found my way into backend development.

Like any language however, ColdFusion is not without its problems. We can compare functionality until the proverbial cattle return to their domiciles, but what I’d like to talk about is the culture of elitism that surrounds ColdFusion.

‘Elitism?!’ I hear you cry, ‘But ColdFusion is so easy to pick up, and the community is so friendly and welcoming! That’s hardly elitist, is it?’.

Yes. You’re right… but what I’m concerned with is the difficulty ColdFusion developers face in the environment in which they work. Adobe have done a very good job of making ColdFusion inaccessible to the masses by focussing on enterprise clients, inadvertently turning ColdFusion into quite an exclusive club.
Don’t believe me? Reel off the names of some well known ColdFusion celebrities… Ray Camden, Ben Nadel, Ben Forta, Et al. I’ll bet if you’re a ColdFusion developer, you’ll know who those people are. You’ll have read their blog posts, be aware of projects they’ve done. You’ll probably be able to list 10 more without too much trouble…
Well, you shouldn’t be able to do that – because the list should be huge. If we were talking about PHP, there’d be maybe 5,000 people in that list. In ColdFusion there’s maybe 20.

Let me explain… Read the rest of this entry »

Posted in ColdFusion, Railo, Servers, Website Development | 15 Comments »

Tutorial: Setting up a production Windows 2008 server with IIS7 & Railo

June 29th, 2010

Prologue:

In which Gary explains his new found appreciation for anyone who calls themselves a sysadmin.

I’m not a sysadmin. I like to make websites. It’s what I do, what I’ve always done.
Dealing with servers is the un-planned love child of my long term affair with website development. A horrid child that demands constant attention and gives nothing back in return.

In the past, I would point clients in the direction of a decent web host and let them get on with it, but as it turns out these clients would still phone me as the first point of contact when their servers went down, making me a mediator between them and their hosts. Frankly, I figured if I’m spending my time doing this anyway, I may as well get paid into the bargain.

Well, after four years of hosting client’s websites I can quite categorically state that sysadmins have one of the most difficult jobs imaginable. Anything can go wrong, at any time. Running a tight system involves research, dedication, and genuine enjoyment of high level tinkering.

If I’m ever in a position to employ a sysadmin, they will be treated well. I will make them tea. And cake. And give them sympathy.
Recently, after a long and gruelling battle with the most unreliable hosting company I’ve ever used, I finally took the plunge and set up my own Windows VPS using IIS7 & Railo. Read the rest of this entry »

Tags: , , ,
Posted in ColdFusion, Railo, Servers | 4 Comments »

Mercurial tool to export changed files

April 27th, 2010

Recently, my friend Chris Brown convinced me to move my source control from SVN to Mercurial (or more specifically, Kiln).
I found Mercurial to be infinitely better than SVN in almost all resepects, but there was one thing missing that I could do with Tortoise SVN but not Tortoise HG, and that was to export any changed files from one revision to the next – something which as a web developer, I have to do very often.

Well, Chris came to the rescue and created a simple program to do exactly that. So here’s Chris to explain the program and how it works:
Download links are at the bottom of the page.
Read the rest of this entry »

Posted in General, Source Control, Website Development | 5 Comments »

Combatting misinformation in web design

March 11th, 2010

I received an email from a client recently, informing me that they have hired someone to redevelop their entire website in php, as they have been informed by their SEO company that ColdFusion is ‘bad for search engines’.

Frankly, I think it’s astounding that any SEO company could make such an assertion, anyone in the industry would immediately understand just how ridiculous this statement is – but unfortunaty our clients are not experts and can only make their decisions based on the advice they receive from the people who claim to be. My clients in this case have made an informed choice, based on patently false information…

So I’d like to state definitively: ColdFusion has nothing whatsoever to do with SEO… Neither does php, asp, ruby, python, perl, or in fact any back end language at all…
Read the rest of this entry »

Tags: , ,
Posted in ColdFusion, General, SEO, Website Development | 6 Comments »

About

Simian Enterprises is the trading name of Gary Stanton, a freelance web developer working by the sea in Brighton, UK. Gary's been creating websites since 1996 and still loves it. Read more

Contact

Gary Stanton

Email:

Tel:
01273 775522

Twitter

No public Twitter messages.

Delicious Feed

Website Design & Development