Category Archives: Uncategorized

If there was anything that could be called a ‘champagne moment’ from the developers at Adobe it was when they came up with the idea of that excellent tag – CFDUMP.
I am sure when this piece of brilliance was brought to life there were many cheers and congratulatory back slapping amongst the developers not to mention the week long party and holiday bonus in the Bahamas (well maybe not that much celebration).

No other language has an easier, more elegant and quicker debugging utility that gives as much detail and information as CFDUMP. It is one of my favorite things about developing in Coldfusion, if only there was some way of getting the same sort of information in a similar manner in Javascript…. well it turns out that there is!

I was wandering around the web when I stumbled across John Bartletts Coldfusion tips n tricks. He has taken some code that essentially dumps a javascript array and given it Coldfusion like formatting. I have often wanted something just like this to save me the hours of developing ways to debug large arrays of javascript data and now here it is –

http://johnwbartlett.com/cf_tipsntricks/index.cfm?TopicID=85

Give it a shot and I am sure you will agree it is a beautiful thing.

I discovered this a bit by accident. I was wondering if it was possible to query 2 MYSQL databases in the one CFQUERY as I had 2 tables that I wanted to join in 2 separate databases and instead of moving the tables in question into the same database I thought I’d have a play… here are the results:

Lets make things nice and simple and call the databases database1 and database2… it’s easier. I should also mention that the 2 databases are located on the same MYSQL server and are accessed with the same user account. I have a Coldfusion datasource connected to database1 called database1connector. Here is the query and the syntax, it’s all about aliases people!

<cfquery name="q" datasource="database1connector">
	SELECT tb1.name,tb2.address
	FROM table1 tb1
	INNER JOIN database2.table2 tb2
		ON tb2.id  = tb1.id
</cfquery>

Note that I include the second database by name in the join clause, simply referring to it by ‘databasename.’ then the table name. Note that I don’t use the ‘databasename.’ notation for the database being accessed via the CF datasource (the first database, ie database1 in the above example) as it will error.

I haven’t tried it but I am guessing that it would be possible to essentially join multiple databases using this same setup, give it a go!

Ever have a lower case string and needed the initial letter of each word to be in capital? well I did and luckily found a nice regular expression via google.

rereplace(“this string is all lowercase”, “(\b\w)”, “\u\1″, “all”) would produce ‘This String Is All Lowercase’

problem solved.

Ever wonder how great it would be if you can edit the content of an object that you have selected in the library? Well now you can! By adding a form tool attribute ‘ftAllowLibraryEdit’ into your CF property such as below, it allows you to individually edit each object.

<cfproperty ftSeq="15" ftwizardStep="Body" ftFieldset="Relationships" name="aRelatedIDs" type="array" required="no" default="" ftJoin="dmNavigation,dmHTML,dmNews,dmEvent,dmFacts,dmLink" ftLabel="Associated Content" ftAllowLibraryEdit="true" />

Once you have included the new attribute, update the application. You should see a new button named ‘Edit Item’ appearing next to the ‘Remove Item’ button.

At the moment jQuery is our javascript framework of choice – it is straight forward to use and you can create complex effects/functions with only the basic of knowledge. Although like many coding languages your source can quickly become bloated and start affecting the performance of your application. Luckily while reading my daily new feeds I found a great post written by Samer Kamel Draidi (originally by Jon Hobbs-Smith) which details 25 excellent tips to improve the use of jQuery.

The article ‘Improve your jQuery – 25 excellent tips‘ has many great tips to increase speed and generally improve how you code using jQuery and I feel it is a must read… so check it out.

Recently, I’ve discovered that some of the Firefox version 2 (in particular 2.0.0.20 on Window Vista) has an error in the mime type settings. Reasons for this is because when I uploaded a PDF document (using cffile tag) via the Firefox browser the mime type returns from the browser was ‘text/html’ instead of ‘application/pdf’. Patrick van Bergen wrote a detailed article about this issue and has concluded that this occurs due to the incorrectly configured mimetype.rdf file located in the Firefox profile folder. There’s no common solution for this issue so far and the best we can do is to perform checks for both the mime type and the file extension to determine the content of the file.

The other day i was having an issue with a button which had a movie clip layered on top of it. I assumed that the movieclip on top of the button would disable the button mouse events but after running my application, the button was still firing an onRelease event (even though you could not see it on stage). After a bit of research, i discovered that setting the ‘visible’ property to false on a button/movieclip completely disables the mouse events for the button/movieclip, as well as hiding it from the stage. I’m finding this very useful for situations where i would like to dynamically enable or disable the mouse events of a button/movieclip.

I had to make another bunch of updates to a large website this week… took about 5 days and changes were made to about 50+ files in different parts of the code base. As usual I was committing the changes as I went and along came the day when I needed to upload all the change to the live site. So I right click on my project in Eclipse, go to team and show history. Here is a list of all the commits and below all the files affected by each commit and need to upload. In this case 50 files in different parts of the website where multiple changes have occurred over multiple commits, going through this list one by one and ftp’ing them into place is nothing short of a torture and just plain expensive from a development point of view, who has half an hour or more to spare uploading and checking a list let alone any issues resulting from files that were missed by this process??

So I thought buggar this, time to code up something quickly to help achieve a much needed but missing feature for SVN. Below is a coldfusion template. Simply run it and fill in the details and voof! you have created a nice export pack to simply upload over the top of the existing files in a site. You just need to get a copy of the SVN change log from Eclipse by simply:

  1. Right click on the project
  2. Select team>show history
  3. Select the revisions to include in your export from the list
  4. Right click on the list and select ‘generate change log’
  5. From the Generate Change menu select ’svn log with affected paths’ and ‘clipboard’
  6. Run the script and paste the clipboard into the ‘SVN History Log’ text area’
  7. Fill in the rest of the details in the form
  8. Submit and let the script create the export pack for you into the selected export folder
  9. Upload changes to site! – Congrats, you have just saved your company some big $ and you deserve an early minute, go and tell your boss!

Good luck!

<cfoutput>
	<html>
		<head>
			<title>SVN Revisions Exporter</title>
			<style type="text/css">
				body{
					font-family: verdana;
				}
			</style>
		</head>
		<body>
<h2>SVN Revisions Exporter</h2>
<cfif isDefined("form.filePathToProject")>
				<cfset filePathToProject = form.filePathToProject />
				<cfset filePathToExportFolder = form.filePathToExportFolder />
				<cfset svnPathToFiles = form.svnPathToFiles />
				<cfset svnHistoryLog = form.svnHistoryLog />

				<cfset aSVNData = listToArray(svnHistoryLog,chr(13)) />
				<cfloop from="1" to="#arrayLen(aSVNData)#" index="i">
					<cfset sData = trim(aSVNData[i]) />
					<cfif left(sData,2) IS "M " OR left(sData,2) IS "A ">
						<cfset filePath = replaceNoCase(sData,"M #svnPathToFiles#","","ALL") />
						<cfset filePath = replaceNoCase(filePath,"A #svnPathToFiles#","","ALL") />
						<cfset filePath = replaceNoCase(filePath,"/","\","ALL") />
						<cfset dirPath = replaceNoCase(filePath,listLast(filePath,"\"),"","ALL") />

						</cfif><cfif len(dirPath) AND directoryExists("#filePathToExportFolder##dirpath#") IS 0>
							<cfdirectory action="create" directory="#filePathToExportFolder##dirpath#" />
						</cfif>
						<cfif fileExists("#filePathToProject##filePath#")>
							<cffile action="copy" source="#filePathToProject##filePath#" destination="#filePathToExportFolder##filePath#" />
						</cfif>
						<cfoutput>#filePath#
</cfoutput>
					</cfloop></cfif>

			<cfelse>
				<form name="svn" method="POST">
					<label for="filePathToProject">
						File Path To Project:
						<input type="text" name="filePathToProject" value="C:\websites\" />
					</label>
					<label for="filePathToExportFolder">
						File Path To Export Folder:
						<input type="text" name="filePathToExportFolder" value="C:\temp\" />
					</label>
					<label for="svnPathToFiles">
						SVN Path To Files:
						<input type="text" name="svnPathToFiles" value="/trunk/website/" />
					</label>
					<label for="svnHistoryLog">
						SVN History Log:
						<textarea name="svnHistoryLog" cols="120" rows="20"></textarea>
					</label>
					<input type="submit" />
				</form>

		</cfelse></body>
	</html>
</cfoutput>

This is just a quick post…

For years I thought that the body of a html page was always 100%. Well, in most cases this is true UNLESS you apply a background colour to the html tag through your style sheet, give it a shot and see what happens!

Try this:

html{
background:#ff0000;
}
body{
background:#ffffff;
}

Make sure that you have one line of text in between the body tags and you will see a vast background of red with a small strip of white containing your text. Remove the background colour from the html tag and VOOF! the body resumes 100% and becomes all white once again.

The work around is obvious – don’t apply a background to the html.
You might ask why on earth I did that in the first place, the answer – I am not sure.

So imagine you have worked hard on a new file (all day for instance) and then just before you commit it to the repos, you accidentally delete it and go to the toilet or whatever and forget about things forĀ  a while… then when you go to run the file a few hours later it doesn’t exist and so you panic for a while until you realise that you are using Eclipse and you have a wonderful little tool called ‘Restore From Local History’.

localhistory

Right click on the folder you not so intelligently removed the file from, select ‘Restore from Local History…’, then simply select the file you want to restore and hey presto, you are back in business! phew!