WebDevelopment, ColdFusion, Railo, JS, Database and Tech-related by the Co-Founder and CEO of tunesBag.com

Friday 3 September 2010

Native hashchange event - Good bye polling

I just discovered that there is a native HashChange event in the latest version of several browsers (FF, Webkit, IE) - this way navigation solutions working with the hash at the end of a URL work without nasty timers.


To add the event, simply use:


if ( window.addEventListener ) {

window.addEventListener( 'hashchange', function () { checkHashChange(location.hash) }, false );

} else if ( window.attachEvent ) {

window.attachEvent( 'onhashchange' , function () { checkHashChange(location.hash) } );

}


Take a look at these samples as well. In real world applications you still will need to use a combination of both methods (polling + events).


Concerning the support of the feature in various browsers, please click here for a comparison chart.

Tuesday 13 July 2010

Int( boolean) will return 0 or 1

Nothing special, but that's cute ... Int( boolean ) will return 0 or 1.

This comes in very handy especially for arguments with the type boolean where the corresponding field in the database is a tinyint.


Tuesday 25 May 2010

CFIMAGE: Compile great looking artist images

I am really excited about the features CFIMAGE provides in railo/ColdFusion. In recent times, I've started doing advanced stuff (read: more than resizing images) and one of the thing I've really enjoyed was compiling acool artist background images from several images - below you can find three samples (Kayne West, Evanescence and Goldfrapp). Basically, it's just a simple combination of ImageRotate, ImagePaste and ImageRead ;-)


Sources: http://www.flickr.com/photos/96679304@N00/176295962, http://www.flickr.com/photos/11671827@N00/522201514, http://www.flickr.com/photos/87258901@N00/2951288353, http://www.flickr.com/photos/44124348109@N01/2834953166

Thursday 13 May 2010

Facebook Like Button will double your page hits

Nothing to be afraid of - while implementing the Facebook Like Button for tunesBag, I found out that every hit to a page with the "Like" - Button will be responsible for a second hit by the Facebook bot (facebookexternalhit/1.0)

Tuesday 4 May 2010

UrlEncodedFormat: Encoding space characters - plus (+) vs %20

I came across an issue with UrlEncodedFormat() today - signatures calculated by an CF9-based system always appeared to be invalid and as it seems ColdFusion is ignoring the standards when it comes to encoding of form posts (application/x-www-form-urlencoded).

The document describing the standard on W3 clearly states:

application/x-www-form-urlencoded

This is the default content type. Forms submitted with this content type must be encoded as follows:

  1. Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
  2. The control names/values are listed in the order they appear in the document. The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.

When you perform an UrlEncodedFormat( ' ' ) on CF, it will return %20, the same call on railo will return "+" as described in the article above.

I solved the issue by simply replacing %20 with +.

Sunday 28 February 2010

Fixing "An invalid XML character (Unicode: 0x0) was found in the element content of the document."

I had some issues recently with storing data in a database as WDDX package and later reading from database again ... as you know WDDX is XML based so CF/railo are using the built-in XML parser to read the data.
In this case special characters in the original content can lead to an error message like "An invalid XML character (Unicode: 0x0) was found in the element content of the document." - the solution is to escape the control chars in the string before calling CFWDDX, e.g. by calling

"REReplace(thisXML,'[\x0]','','ALL')"

I found this tip in the Adobe Forums.

Tuesday 26 January 2010

Silent Setup of Sun JDK (Linux, Debian)

I was looking for a way to install the latest Java Runtime Environment without any user interaction and came across this posting

Here's a tips I found trying to do the same as you :
1. Create an answers.txt file with the word yes inside
2. Launch fhe following command (assuming you want to install jdk-xx.bin)
./jdk-xx.bin <>/dev/null
Works like a charm!

Wednesday 20 January 2010

Ant & SCP on Mac

Just spend a few minutes involuntarily on fixing the SCP support for ANT on Mac ... a library is missing ("Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found.") and you have to copy a second file from the binary distribution, check out the howto I found on the web!

Important hint: Don't download the latest binary distribution, check which one you're running (ant -version) before doing that! Otherwise you'll likely receive error messages again.