I wanted to post my presentation files for the demo I'll be giving at Spring <br /> Conference 2007 tomorrow morning. This file contains the Powerpoint Presentation, plus all the example file (plus some that I probably won't have a time to get to!)
I probably went overboard on the examples—I seriously doubt I can get through them all in 60 minutes, but hopefully you'll find the source code commented well enough that even if you don't set through my presentation, you can still follow what's going on.
One of the many projects I'm currently working on is some code to delay sending of e-mails until a specified window of time. We're generating some report data for clients during the offhours, but the clients want the results e-mailed no earlier than 8am.
Our reports often contain images or other attachments that need to be included e-mails. One issue I really don't like about the implementation of CFMAIL in CFMX is that it requires attachments to be written to disk before you can send the mail. This means if I want to use the CFMAIL tag to deliver delayed e-mails, I would to manage attachments until I'm sure the message is delivered. I don't like that solution, so I set out to see if there might be other ways of generating attachments from binary data in memory. This lead me to researching the JavaMail API—which is the API that CFMAIL uses behind the scenes.
I quickly learned that even CFMX v7.02 still uses JavaMail v1.3.1—which is an older version of the API. One of the issues in v1.3.1 is that it does not include any classes for taking a binary stream from memory and converting to an attachment. It comes with a FileDataSource class—which will read in a file and convert it to the correct data source. This might be the reason that Macromedia/Adobe requires the file to be written to disk.
On a recent project I was working on, I needed an "autocomplete" form field that could do both local data array and AJAX lookups. After doing some searching, I came across Dylan Verheul's jQuery Autcomplete plug-in.
This plug-in did a lot of what I needed, but was still missing some of the functionality I required. So, I just modified the library so it worked the way I needed it to. Here's a list of the changes/enhancements I made:
Mark Drew posted a question on his blog wondering how you might pass data to a custom tag that acts as a loop. In his post, he's trying to get the following code:
Reading blogs the other day, I came across the Dina Programming Font. I've been testing it out for the past couple of days in Eclipse and so far I really like it.
Over the years I've tried a number of different fonts for my IDE, but I always end up back with Courier New—mainly because it's familiar. However, I've been able to use the Dina font at 8pt and it retains it's readability very well at 1028x768. Lowering the point size while not adding strain for my eyes, allows me to see more code on the page w/less scrolling. Since I have carpal tunnel, anything that reduces mouse movement is a welcome change.
I recently upgraded a few of my installation of TortoiseSVN to the latest revision. Every since doing this, I've been unable to use Subclipse v1.0.3 (in Eclipse v3.1) to change repositories that have been touched with TortoiseSVN. This is because the newest version of TortoiseSVN using the v1.4 of the client libraries and Subclipse v1.0.3 is based on the old v1.3 client files.
Since one of my development boxes only has Eclipse w/Subclipse, it's been a pain to deal w/this compatibility issue. So, this morning I set out to find a solution to this issue.
Fortunately, I was able to find a post by Mark Phippard that addresses solving this issue (while for Subclipse v1.1.6 anyway.) I did run into an issue that apparently doesn't affect the newer version of Subclipse, but since I'm still using Eclipse v3.1 at the moment, I'm stuck using Subclipse v1.0.3.
Ever needed to parse a qualified URI to examine a URL for specific information? I'm working on some code that needs to examine links in a document and extract information about the links.
To make sure I was doing things by the spec, I made sure to check out RFC2396. Fortunately, the RFC has a nice little regular expression for breaking a URI into it's core pieces: scheme, authority, path, query and fragment.
However, those core portions are still pretty broad. The authority can include user info, domain and port information. The path can include embedded parameters inside each segment. So, I took the core regular expression to break up a URI and then I do further parsing on the authority and path portions of the URI.
For those of you using Fiddler HTTP Debugger (which is a great tool I've blogged about many times in the past,) there appears to be an issue when using IP addresses. This is especially noticable when using private subnet IP addresses (such as 192.168.1.*.)
The problem I was seeing was that requests to my developer server came to a crawl when using Fiddler. Speed to external domains was working fine. If I turned off capturing, speed resumed. I finally was able to figure out that by setting up a DNS entry, speed would resume.
Since this was slowing me down, I sent Eric Law, the developer of Fiddler, an e-mail message reporting the problem. He was very quick in researching the problem.
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'm working on a project that requires state to be passed via form fields (i.e. a multi-step wizard.) This means that I end up needing to pass hidden form fields from page to page. This normally requires a funky series of if/elses to determine which values to include on each form. Also, as things change from one form to another, you'd need to update each page in the process to include the hidden form field required, otherwise the value gets lost.
Anyway, I started thinking it would be nice if I didn't have to write any if/else statements and just have the necessary fields required automatically passed. Well, if you're thinking "Why not just loop over the form scope?" Well, that's only part of the solution. You really need to exclude fields that are already on the page.
Fortunately, several years ago I had written some code that was part of a much bigger project, that could parse a string and find form fields and extra information about about the fields. Harvesting the code I had already written, I was able to whip out a tag that would parse the content between the start/end tags, look for any form fields in the content and exclude those fields from being copied as hidden form fields.
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.)
A while back I found a stored procedure that someone was using to create pagination resultsets in SQL Server 2000. While the stored procedure was nice, it didn't allow for the "DISTINCT" keyword—which is necessary for some of my queries. There were also a few other issues I didn't like about the stored procedure, so I re-wrote the stored procedure pretty much from scratch.
In order to support the "DISTINCT" keyword, I had to change the inner query to use a derived table. Since this provides a little more overhead, I added a bit parameter "@Distinct" which inserts the "DISTINCT" keyword into the query and uses the derived table.
Also, on the initial page of results, I simply use the TOP keyword. The previous stored proc used an inner query, which did a TOP 0—which means the code did nothing.