Sunday, October 03, 2010

Simple Java to make sure a directory exists before doing a cffile upload

Simple Java to make sure that a directory exists before doing a cffile upload:

<cfset CreateObject("java", "").init("C:\Inetpub\wwwroot\myNewDirectory\images").mkdirs() />

So, for example, you might do something like this:

<cfset CreateObject("java",").init("c:\uploads\#dateformat(now(), 'yyyymmdd')#") />

You can just do the above before every upload.&nbsp; The first time it will create the directory, and every time after that it will just do nothing.

Thanks to cfgears for reminding me how to do this:

Thursday, September 30, 2010

listFind vs. listContains

ColdFusion has two functions for finding things in comma-delimited lists, but they behave very differently, and I can never which is which.  Today I needed one of them, and so I did a test to figure out which I needed.  If figured I would document their usages here, so that I wouldn't have to go thru this testing process next time.  Here are the functions:

listContainsNoCase(list, substring)
This function just finds the substring, and tells you which item contains that sub string.  It is important to understand that this item is not searching for a list item, just for a sub string.  Consider the following example:
listContainsNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Text")=5
Notice how it found that item number 5 has the word "Text" in it, even though "Text" is not the complete item.

listFindNoCase(list, value)
This function finds a value in a list, and tells you which item matches the value.  It compares the value to the list item, and only accepts complete matches.  So, consider the following examples:
listFindNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Text")=0
listFindNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Simple Text")=7
Notice how in the first example above, no item was found.  This is because there is no single item with value = "Text".  However, it did find "Simple Text" in the second example above.

Of course the same is true for listFind, and listContains, but those are case-sensitive.

Incidentally, I put this one in the "duh" category, because I think that the names are reversed.  The first usage should be named listFind, and the second should be named listContains.

Hope this helps.

Monday, September 13, 2010

Resolving Samsung Captivate Windows 7 (64 bit) connection problem

------ NOTE ------

See the updates at the end of this post. Although many people have reported in comments that this fix worked for them, it actually stopped working for me after a few days. Consequently I have actually returned my Captivate in favor of a different phone that actually works.

------ END NOTE ------

On Friday I purchased a new Samsung Captivate from Costco. Before I get into the USB connectivity issues, let me just say that this is a great phone. Great speaker, great microphone, great ambient-noise management, great processor speed, great camera, outstanding screen, tons of memory, the list goes on. However, I encountered some serious problems getting it to connect to my computer. It took two days to get the problems resolved. Amazingly, neither this problem nor the solution is documented online. So, here is what I learned. I don't make any recommendations that you should try this, or any guarantees whatsoever that any of this will work for you, or that it will not damage your phone, etc, etc. Try it at your own risk, you have been warned. However, I did eventually get it to work for me, and am now much happier with my phone. Here's what I did.

First, the computer is a newish, capable, reliable laptop running Windows 7 Home Premium (64 bit). It is a pretty new install of Windows, and there are no known hardware problems. When I complained to the guy at the AT&amp;T store, he admitted that other customers have complained about the same problem. So I don't think that the problem was with my computer.

When I first attempted to connect my phone to my computer, Windows quickly reported that the driver install failed. I made several attempts, all of which failed. Next I tried on a Vista (32 bit) box. The driver install seemed to work OK, but it kept reinstalling over, and over, and over again. Like every 3 minutes, over and over again, times infinity. Weird.

So, after two days of research, and trial and error, and visiting 2 AT&amp;T stores, here is what I learned.

Samsung Captivate (and I believe other Galaxy class phones) use a software package called Kies to manage your phone's connection to your computer. By default, when you connect the Captivate (and probably most Galaxy class phones) to a USB port on Windows, it is only willing to talk to Kies. If you don't have Kies on the computer, then the connection will fail.

The bad news is that Kies is not available in the U.S. (!?). I had to download it from Samsung's Singapore website. Worse, Kies is kind of lame. It looks nice, is user friendly, and is a good effort, but isn't very useful and just got kind of got in the way.

The good news is that installing Kies also installs the drivers. After installing Kies, Windows immediately recognized my phone. So that's good.

The better news is that it turns out you may not actually have to install Kies at all. You can change the default USB setting on the device (which I have done). If you go to settings &gt; Applications &gt; USB settings, you will see that the default USB behavior is set to "Samsung Kies". I changed mine to "Mass Storage". Now when I connect my Captivate to my computer, it doesn't try to talk to Kies. Instead, it just pretends to be an "External Mass Storage" device which Windows has no problem recognizing (think external hard drive, or thumb drive).

Next, when I connect my Captivate to the computer, Windows makes that happy little two-tone chime that means something has successfully connected. Then on the Captivate, I just have to tell it to mount on my computer. There is a little status bar along the top of the screen. If you touch that bar and drag it down, there are some useful toggle buttons and a section called "Ongoing". Under ongoing there is a "USB connected" entry. When I click "USB connected", it asks me if I want to mount my phone on Windows. If I click "Mount", then I can access my phone just like an external hard-drive. I can copy music or pictures directly onto or off of the phone. Easy-peasy.

So, at least now I have a way to get stuff onto and off of my phone, and I don't have to use Kies. This is good. Also, I reformatted the internal SD card (read somewhere online that this helps).

Again, I don't promise or guarantee or warranty or say that any of this will work for you. Just that it worked for me. Good luck!

Now I would just like to take a moment to talk directly to Samsung.

Samsung, listen, you are a big company. You are a respected brand. You make good products. You spend millions of dollars advertising them. But even though your phone is widely available for purchase across the U.S., it cannot connect to Windows 7 without your users going to extensive lengths to research and troubleshoot, and the software for your phone isn't even available in the U.S. This is a problem. It's not like this is a special advance order phone direct from Japan. This is a widely advertised, commercially available phone that consumers can buy at any AT&amp;T store, Costco, Sam's Club, Best But, etc. Yet they cannot connect their phone to their computers, unless they download software from Singapore, or change unfamiliar settings.

Please fix this. Either release your software in the U.S., or include instructions in the packaging or on your website on how to change the USB settings. Better yet, on your phones sold in the U.S., just default them to "Mass Storage" mode, and include a quick-start paper on how to mount the phone as an external hard drive.

Ok, that's all for now. Will report if the situation changes.

------ UPDATE 10/3/2010 ------

Unfortunately, the fix described below stopped working for me a few days ago. That was the last straw. Although I liked the Samsung Captivate, I decided that I wasn't going to keep a phone that lacks basic driver support and can't even figure out how to connect to a computer. So, I returned my Captivate to Costco, and bought an iPhone instead.

------ UPDATE 10/4/2010 ------

On 10/2/2010 Anonymous commented: "I cannot believe this phone has been out for now over 3 months and no fix. Shame on Samsung; this is why people turn to macs and iPhones, lazy companies."

I agree. Putting the time, effort, and R&amp;D money into building a fabulous phone, and then failing to deliver basic USB drivers (even just simple Mass Storage drivers) is absurd in the extreme. That's like spending months building a fabulous house, and then failing to include something simple like a door. Eventually no matter how great the house is, the owner will get tired of climbing into the house through a window, and just buy a house--any house--with a door.

------ END UPDATES ------

Thursday, September 09, 2010

ORM is not configured for the current application

Working on a little app in ColdFusion 9.  Was consistently getting a phantom ColdFusion error (especially containers loaded by the built-in ColdFusion.navigate function):
ORM is not configured for the current application

Very mysterious, and took a while to troubleshoot.  In my Application.cfc, in the onRequestStart method, there was a <cfset ormreload()> .  I had put it there thinking that while I was doing some development it would be nice to have the ORM reloading all of time as I make changes.  However, it looks like it was interfering with the ORM's sequencing, and on Ajax page loads it was causing ColdFusion to erroneously report back that the ORM was not loaded.  I simply moved the ormReload to onApplicationStart, and the problem seems fixed.

Wednesday, March 24, 2010

Knowing What To Do In An Emergency

So, I attended a political caucus meeting last night (in my state, this is the step before a primary election), and ended up getting briefly sucked into a medical emergency. It reinforced the notion that it is important to know what to do in a medical crisis.

As the various nominees were talking about their background and qualifications, a man in the audience near me suddenly collapsed. His knees buckled and he simply sprawled backwards (luckily a half filled box of papers cushioned his fall). He was completely inert and unresponsive.

This was so unexpected. Most of us in the room knew the man from our neighborhood, one of nature's authentic nice guys. There was a collective gasp from the 30-40 people in the room. Everyone just stood there for a beat or two; it took a few moments to compute what was happening.

I asked his wife if he is diabetic, she said no. I got out my phone, dialed 911, and asked if he was breathing. He wasn't, so I hit the call button. As I started talking to the 911 dispatcher, somebody began administering chest compressions.

Fortunately, a friend had been talking recently about what to say when you call 911. As soon as the dispatcher answered, I knew exactly what to say:

Me: I am at ----- ----- Junior High School in [city]. A 50 year old man has just collapsed and is not breathing. He is not diabetic. Someone has started administering CPR.

Dispatcher: You say he is not breathing. Is he having a seizure?

Me: He does not appear to be having a seizure, although his eyes appear to have rolled up into his head.

Dispatcher: Stay on the line. I am going to put you on hold while I get an ambulance. Could you have someone go to the front of the school to meet the ambulance?

The good news is the man started to revive while I was on hold. He seemed surprised to be on the floor, and was totally unaware of the drama that had occured around him. He assured everyone that he was alright, and left the room to get some fresh air. His wife declined the ambulance (they are expensive) and everyone went home safely.

Some takeaways from last night's drama:

1) When you call 911, stay calm. Clearly express where you are (give the address if you know it, especially if you are on a cell phone), what happened, how old the person is, and any important / relevant details (e.g. "They are performing CPR", or "The person is bleeding a lot from [this] area"). Try to give correct information. Answer questions clearly.

2) When the person started administering CPR, he didn't seem like he was sure what to do. I don't know how they determined that the man wasn't breathing. I didn't see anyone feel under his nose, so I am guessing that they just looked at his chest. Nobody felt for a pulse. Nobody tried slapping him on the cheek or speaking loudly into his ear. Someone probably should have done these things before starting CPR.

(Disclaimer: I am not a doctor of medical expert in any way. This is simply my untrained opinion. Any EMTs out there, please feel free to correct me if I am wrong)

It is my understanding that administering CPR to someone whose heart is still beating can cause harm. Don't get me wrong; I am glad that somebody was willing to try to step up and help, and I know that hindsight is 20/20. So, this leads to my third point:

3) Know what to do in an emergency. Even basic knowledge of what to do in an emergency will save lives. Take basic CPR / First Aid classes. The American Red Cross offers them on a regular basis for a moderate fee. Hospitals, colleges, and many large workplaces will occasionally offer the classes for free or for a small fee. Take advantage of these opportunities to learn. My workplace is going to offer a 3 hour CPR-AED-First Aid class in a couple of weeks. I plan on being there.

Although it can seem unlikely that you will ever need to know this stuff, imagine what it would be like to watch somebody die because you don't know basic stuff that you could have learned at a couple of evening classes. Now imaging taking a couple of 2-3 hour classes, and knowing what to do in an emergency, and saving someone's life. Less than 10 years ago, I had to give my infant daughter mouth-to-mouth resuscitation after she stopped breathing. Because I had taken first aid as a 14 year old Boy Scout, I knew how to resuscitate an infant (you cover mouth and nose with your mouth), and possibly saved her life. I am sure glad that I had a basic understanding of what to do--at least enough to keep her alive until the ambulance got there. Sign up for a class. Give up an evening or afternoon (or two) to learn these basic skills. You may just save a life. And it may be someone you love.

Wednesday, March 03, 2010


Over the last few months, I have been upgrading some of our websites' login systems. Today I updated the login system of old internal site that some users still use to update stuff. The login system that worked great on our newer web apps, wouldn't load the login screen on the old system. Here is the order of operations:

  • Main Page starts with style sheets, javascript & ajax library, starting body tag, etc.
  • Login Management Custom Tag occurs in middle of page, between begin and end body tags.
  • Login Management Custom Tag launches login cfwindow, navigates window to login form.
  • End of page winds things down, includes closing body tag.
Everything here works great in Firefox (of course), and on our newer Ajax-driven apps it works in IE. However, on this old, not-very-ajaxy website, IE 8 shows the cfwindow appears, and then breaks on the navigate saying: "HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917); Line: 0; Char: 0; Code: 0". Pretty mysterious.

So, lots of searching, and I found this helpful post:

and additionally this helpful post:

So, I tried moving my custom tag to the end of the page, outside of the body tag, and that worked great. From what I can tell, the cfwindow, or maybe the ColdFusion.navigate was trying to add elements to the body of the page, before the body had closed.

Whether or not the reason provided above is exactly correct, it makes some sense. After all, our new, ajaxy websites launch the cfwindow from within a container (usually cfdiv), meaning that the main-page's body tag has closed before the cfwindow ever tries to load.

In any case, whether my diagnosis is right or wrong, the medicine worked. This one was a tricky one, so I thought that I would share it with the world.