Archive for March, 2008

Put a pause in your code

So the other day I needed to put a pause in my code.  This is something I seem to run into every so often, but this time I decided to put the solution into a custom tag, making it much easier to include in my code.  I had previously looked around quite a lot and there are many ways to skin this particular cat, but in this case I turned to Java now that we have CFMX.  In particular the threed.sleep() method.  It is a method of the Thread class that can create a pause measured in milliseconds.  The raw Java code looks like this:

 try {
Thread.sleep ( 1000 );
}
catch ( InterruptedException e ) {
}

Now I need to get a quick implementation in the form of a custom tag that I could easily include in my code, providing a way to pass an argument in seconds rather than milliseconds.  The resulting code was my new custom tag:

<cfparam name=”seconds” default=”1″>
<cfset seconds = attributes.seconds>
<cfif not(isnumeric(seconds))>
<cfset seconds = 1>
</cfif>

<cfscript>
thread = createObject(“java”, “java.lang.Thread”);
thread.sleep(javaCast(“long”, 1000*#seconds#));
</cfscript>

Notice I do check to see if the value passed is actually numeric and if not, I just force the tag to default to one second.  Now I just call my tag like so:

<cf_pause seconds = 1>

There you have it, a nice pause for your code provided you can keep the tag (pause.cfm in this case) in your CustomTags folder OR in the current working directory.

Hello World…

After many hours, days and possibly weeks of evaluation, I’ve decided to start my professional and coding blog with WordPress.  I’m primarily a Coldfusion developer so I really wanted to eat my own food so to speak, but in the end, I couldn’t turn away from the ease of use and vast support of WordPress.  I tried BlogCFC, CFBloggy and a couple other CFML based blogs and CMS systems (FarCRY) but I continued to run into obstacles. 

Some of my problems were to do with my host, Godaddy.  Though cheap, you give up some depth with the very restrictive nature of their Coldfusion setup.  CFObject is blocked and pretty much all the blogs and cms systems are using that.  I read some articles about manually switching things over to CFInvoke, however that proved time consuming and what was one to do when a new release of the software came out?  No, I needed to work with something that would require little effort to update from one version to the next. 

By the time I decided to go with WordPress, I had setup a second hosting account with Hostek which supported CFObject and CF8 to name a few key pionts, but just the same, I ended up with WordPress because it just plain worked everywhere I used it.  So now that I can actually run all these other great CFML based apps just fine, I still choose to use WordPress after all was said and done.  Hopefully the Coldfusion Gods won’t hold it against me.  ;-)

That all being said, I look forward to documenting some of my work related pitfalls surrounding CFML and system administration.  I’m dying to share my experiences regarding whether or not shared hosting is better than running your own server so maybe that will be next.