Ok, so the title is misleading. CF doesn't really have a concept of null, but it does have the concept of "not exists."
If you need to differentiate between when an argument of a function has been supplied or not, set the required attribute to true and leave the default attribute off. If the argument is not supplied to the function, then a against structKeyExists(arguments, "argumentName") will return false. If a value has been supplied, the function will return true.
Here's an example:
The other day I had the need to unzip the contents of a zip file. However, I did not want to unzip the file to disk, I really wanted to grab the binary data in memory so I could write it to MS SQL as an image data type.
As I normally do, I first did a quick Google and CFLib.org search to see if I could find anything that did exactly what I wanted. The only examples I could find were of writing the zip contents to disk. While I could have written to disk and then read the file from disk, I know I could do what I wanted by just creating a ByteArrayOutputStream. So I took the unzipFile UDF I found (written by Samuel Neff) and basically re-wrote it.
I decided I actually wanted to return a complete query object of all the zip file information. I thought this would be useful for other projects (in case I ever need to "browse" a zip file.)
Damon Cooper has blog Rupesh Kumar's latest CFTHREAD Proof of Concept (POC).
Rupesh is an Adobe "scientist" (a cool word for CF Developer Engineer.) He was very active in listening to feedback from the original version of the code that was released. I, along with a few other developers, were in active discussions with him over issues with the first release. Thanks to Rupesh's hard work, he's addressed the issues that were discussed.
The biggest changes are the addition of being able to pass attributes to the CFTHREAD tag (which allows you to pass in variables who's values can't change,) threads having their own unique scope (so that variables outside the thread aren't negative affective,) and the addition of the thread.OUTPUT and thread.ERROR variables.
Sorry I haven't blogged in a while, but I've been very busy working on a project. Part of the project requires that I convert HTML to formatted plain text. On the very surface, this may seem simple (just use a RegEx to remove the HTML,) but the key word in that first sentence was "formatted."
One of the many issues I've run into, is that none of the built-in ColdFusion string manipulation functions account for the "visual" length of a string. Since one of the things I needed to do was wrap text after XX number of visual characters; I needed a function that, unlike the standard len() function, would return the length of a string as it would appear on the screen. This means I have to take into account how many "spaces" a tab would occupy on the screen.
My first attempt was simply to count every tab character (chr(9)) as 8 spaces. While this number assured I would never go past the right edge of the content, it wasn't very accurate (as a tab can very between 1 space to 8 spaces in Windows.) I quickly started running into problems when I realized that for some functionality (like centering text,) I'd really need an accurate account of the total number of visual spaces a string was occupying.
I downloaded the ColdFusion v7.0.2 Updater this morning. Since I've had some problems recently with downloading CF updates from Adobe.com, I decided I'd verify the MD5 checksum. This made me realize I didn't have a good Windows application for verify the MD5 checksum. After searching Google for a few minutes, I came across a very small (97k) application called MD Checker v2.20.
Using the program is very straightforward—just unzip to a directory and run the md5.exe executable. No installation required. To compare a checksum against a file's checksum, select the "Verify an MD5 checksum" (which is the default option.) Next, copy the MD5 checksum into your clipboard and click the "Paste" button—this will put the MD5 checksum value to verify against in an uneditable control. To verify the checksum of a file, click the "Browse" button and find the file on your hard drive and click the "Open" button. The application will then report the checksum found in either a green (if the values match) or red (if the values differ) box.
This program is very straightforward and best of all, it's free.
I've been working on modifying some ColdFusion based web services for XStandard originally written by Ben Nadel. One of the things the original code didn't support was the Spell Checker support feature built-in to XStandard.
After doing some searching, it appeared the Jazzy Spell Checker Java API would fill my needs nicely. It's based on the algorithms in aspell and it can use both dictionary and phonetic files to help with spelling suggestions and it returns all the information required by XStandard (position of word and suggested spellings.) The only "disadvantage" of Jazzy is that it does come "ready-to-use" with CFMX—you need to write a wrapper class for easy use w/ColdFusion. (More on that to come in a later post.)
Ok, I've been working on trying to optimize some code recently. One of the huge bottlenecks in the application is the conversion of date/times to local user times. All date/times are stored in GMT in the database and are converted to user local when displayed.
We've been using a database table to do lookups/conversions of the date/times to make sure they display correctly depending on the user's region and whether or not they are in a daylight savings time. We're using custom data tables—which we have to maintain—not to mention it runs pretty slow on large recordsets.
In order to speed things up, I've been looking at using IBM's ICU4J's TimeZone class. Paul Hastings has written some nice little ColdFusion wrapper CFCs for this class. So far in my testing, under load the Java class performs about 10x more efficient that the db lookup code.
There's a new Web in town—Web v2.1! A new article over at Something Awful gives a humorous, yet insightful, look at the buzz phrase "Web 2.0".
Web 2.1 is the new standard for web sites and applications in the blogosphere collective information age. It is scaleable and easy to use, as well as being user friendly and designed with the end user in mind. In order to be Web 2.1 compliant, you must follow these guidelines:
- If it comes to a rest on the floor for less than five seconds, you can eat it
- No means no
- Don't expose it to bright lights, get it wet, or feed it after midnight
- Data is the next Intel Inside
- If the kick returner signals for a fair catch but drops the ball, the other team can attempt to recover it
I've been having a lot of weird performance issues lately. For some reason today my CPU was just getting maxed out within minutes of booting. My first thought was a virus or spyware, but after some digging around with the excellent application Process Explorer, I was able to find a thread in the system process that was eating all my CPU cycles. It was a DLL named "ssrtln.sys".
Troubleshooting this was a real pain. This DLL was eating so many CPU cycles, that it was actually preventing many applications from even loading (including Internet Explorer, the Control Panel and Windows Explorer.) Turns out this DLL belongs to the Sonic Solutions, which was part of the IBM DLA drivers which were loaded on my IBM ThinkPad R50p.
Since the driver is not loaded in Safe Mode, I tried booting to Safe Mode to remove the driver. Turns out, you can't uninstall this particular piece of software in Safe Mode.
Tonight I finally got sick of Windows XP's native support for Zip files in Windows Explorer. It really slows down Explorer and I really have never even liked the fact that it treats Zip files as folders. I want compressed archives to be what they are—files. If I want to view the contents of compressed archives, I'll use an archive applications like WinRAR.
To prevent Windows XP from treating compressed Zip files as a folder,
go to "Start > Run" and type the following:
regsvr32 /u zipfldr
If you wish to restore native Zip support in Windows, just go
back to "Start > Run" and type the following:
regsvr32 zipfldr
Ever need a snippet to read in the active sessions running on your server? This code was recently posted to the CF-Talk list and I thought it was worth blogging for future reference. (Thanks to Raymond Camden and Dave Carabetta for the information.)
NOTE:This code relies on using internal undocumented ColdFusion factories. This means the code could potentially stop working if Adobe ever changes the internal factories.
Doug Hughes has been kind enough to share the code he wrote to get the dimensions of a Flash (swf) file using ColdFusion. This could prove to be very handy to anyone running a CF-based CMS or if you're serving up random Flash files.
If you ever do any heavy JavaScript development, you know how large cross browser libraries. The file sizes of these libraries get very large, very quickly. Usually JavaScript files contain a lot of whitespacing and (hopefully) commenting, which can drastically increase the file size—which means for longer download times.
There are many solutions to this problem, but most involve the basic idea of stripping out commenting and taking out the unneccesary whitespacing. While these simple steps can reduce you files nicely, there are better ways.
Alex Russell, the project lead for the Dojo JavaScript Toolkit, has written an open source compression tool called SourceSafe. SourceSafe is based on Rhino, the JavaScript engine used in the Mozilla projects.
Matt Inman has released a little AJAX application that uses the Google Map Javascript API to visually display the location of an IP address.
Creating a visual IP address map isn't a perfect location, so don't expect to see your home address show up. Instead, they usually do a pretty good job of tracking the IP address back to your local ISP. Interesting product none the less.
With the release of Thunderbird v1.5, I also found that I needed to update my version of Thunderbird-Tray from v1.1 to v1.2.
TB-Tray is a launcher for Thunderbird, which stays in memory and will "hide" Thunderbird to the systray instead of the taskbar. It actually has a lot of configurable options for a launcher. I've been using it in one form or another for almost a year. I really hate having my E-mail client show up in the taskbar. It's one of those applications that I almost always leave running and just don't see a need for it eating up a spot on my taskbar.
If you use Thunderbird, I'd highly recommend this application.