Archive | Development RSS for this section

Why Coldfusion / CFML has its place and is worth to learn it

I actually never indulge in conversations why one programming language is better then another, because what is right to you, does not automatically mean, it is right for someone else. So, for me ColdFusion, or as we call the language itself – CFML, works very well.

Nevertheless, in this post I like to clear up some confusion that has been around. I can see where the confusion comes from as Coldfusion has gone from Allaire to Macromedia and is now “in the hands” of Adobe.

In any case, here are some reasons why CFML is still worth for you to learn.

  • CFML is open source and yes you can use it for free. I guess, many people are put off by the fact that Coldfusion has had a big price tag on it in the past. True, given the nature of PHP, Java, Phyton, Ruby, etc. being free, there was actually no reason to shell out your hard earned buck for some application server and on top of it even learn the language. Thanks to the short sighted business decisions of Macromedia and now Adobe or shall we say with the greedy money making mentality of its management, Coldfusion has been faced with a drainage of developers.
    Fortunately, this has all changed with the advent of OpenBD – the first real open source CFML server, followed shortly by Railo, another popular open source CFML server. In other words, to learn CFML and to deploy your applications, is now free and free to be.
  • Write less code. Compared to PHP, Java, C++, even Ruby and Python – CFML allows you to write the same program with much much fewer lines of code. Why would you want spend your precious time writing more code when you can do it for less? As a matter of fact, you can write your application in CFML so efficiently, that the same application written by you alone would probably need a team with Java, Ruby, etc. This is a proven fact.
  • Well designed. The CFML language is well designed and many required functions already exists for you to use. There is no need to write a wrapper for a email sending function. I mean, you don’t even need a framework, to achieve a simple tag like “<cfmail…>”. There is no obnoxious, framework to learn or write functions for this. Compare this to Java, PHP, Ruby, etc. you are very well off with CFML. (again all without a framework)
  • Build web applications fast. Due to the nature of writing less code with CFML and with the built in function, you will be writing your next web application in weeks, instead of months. On top of that, you will have a full scalable enterprise model on your hand to scale when your startup takes off. Heard about the stories of PHP web apps, that had to be converted to xyz language just to scope with the traffic. Again, if you would deploy your web application with CFML and OpenBD, you can deploy on any Java application server (Tomcat, JBoss, Websphere, etc.), connect to any database (MongoDB, H2, Oracle, MySQL, MS SQL, DB2, you name it…) and have your cluster, load balancing, caching setup done.

If you are in for writing less code and building your next web application the fast way, then I simply urge you to give CFML a try. I’m certain that you will get your project done in half the time then in another language. There is simply nothing to loose for you!

 

CFML and Cannot run program “chmod”: java.io.IOException: error=24, Too many open files

Migrating one of my customers the other day, bought up an ugly error when I had to create 2000 directories on one go. The error was:

Cannot run program "chmod": java.io.IOException: error=24, Too many open files

While, “too many open files” usually means one can raise the limit of open files under Linux (check out ulimit -a) it unfortunately did not help in this situation. I even rebooted the whole server and made sure that no other service was running, except Java that is. Still no success.

I then looked at my code in the CFML (Coldfusion) template. In order to create the directories I used a simply:

&lt; cfinclude action="create" directory="..." mode="775" &gt;

Normal code, right? Well, as it turns out, I simply had to remove the “mode” part in order to overcome this error. Not sure, why this caused a “too many open files” error, but it worked in my situation. I can only imagine that the server tried to put all 2000 directories into memory and then write them in one go (I have a high value for the open files limit set and 12GB RAM).

In any case, hope this helps someone out here.

Javascript and encoding

As a developer of web applications you (should) know that your users will not always enter the data you expect in a form field. When you post the form with a normal submit, then the browser will take care of the encoding for you, but what about AJAX calls? Say, you need to grab a form value and need to pass it on in a AJAX call, then you need to take care of the encoding.

Javascript gives you 3 functions to encode your values. These are escape(), escapeURI() and encodeURIComponent(). Now, probably like a lot of others, I have only known about the escape() function and used to use that function to encode my URL values. Until the other day, when I had to preserve a “+” and a “/” in a value. Apparently, there is a fundamental difference between them.

escape:

In all browsers that support JavaScript, you can use the escape function. This function works as follows: digits, Latin letters and the characters + – * / . _ @ remain unchanged; all other characters in the original string are replaced by escape-sequences %XX, where XX is the ASCII code of the original character.

escapeURI & encodeURIComponent

In addition to escape, modern browsers support two more functions for URL-encoding: encodeURI and encodeURIComponent. These functions are similar to escape, except that they leave intact some characters that escape encodes (e.g. apostrophe, tilde, parentheses); moreover, encodeURIComponent encodes some characters (+ / @) that escape leaves intact. Unlike escape, that produces %uXXXX, encodeURI and encodeURIComponent will encode the capital Cyrillic letter A as %D0%90, and the euro sign (€) as %E2%82%AC.

 

Actions of a entrepreneur

I’ve found this and simply had to share it. This outlines a lot what an entrepreneur has to do. Have fun building businesses, I sure have :-)

How to search & replace in MySQL

Thinking of a way to quickly search & replace data in a MySQL column got me to this solution:

update table
set 
column = replace(column,'thistext','thattext')

With this method I was quickly able to change millions of records today. Quick and easy.

Prevent BBedit to open last documents

Since MacOS X Lion (10.7.x) we are “blessed” by the general option that documents we have worked on the last time are automatically opened the next time we start up an application.

While we can argue if that is a boon or not, I personally don’t like this “feature”. Especially, when the last opened document has had errors or crashed the application.

Today, I was not able to open a document in BBedit and it crashed completely. But sure enough, the next time I opened BBedit again it tried to open the same file again, resulting in crashing again.

After some trial and error I figured that holding down the shift key during the startup of BBedit it will disable loading of previous documents. I hope this helps someone else out there.

Yes, I know there are ways to disable this globally. But in case one does not want to disable this feature globally.

How to wait until a file is downloaded or why cfthread is a bad idea within a cfloop

I just run into an issue where one of our servers was totally bogged down when users started to download 100 or more files. See, the problem is that we had to check that each file was downloaded successfully before processing with the rest of the code. In other words;

1) Query for files that need to be downloaded
2) Loop over the records
3) Within loop download the file
4) check if file has been downloaded successfully
5) continue with the code.

In Coldfusion (or CFML to be general) your code would look like:

<cfloop query…>
<cfthread…>
<cfhttp…>
<cfthread action=”join”…>

As I mentioned above, we need to check if the file has been downloaded successfully before continuing with the next download. That’s why  there is a cfthread in this code.  Now, while this might be a good idea with small download, it has a hazardous effect if you will trigger 1000 downloads, which again would create 1000 threads!!!

So, there are actually 2 things I’ve learned from this:

  1. There is no need for the cfthread. Since cfhttp will halt the code process until the file has been downloaded, creating the thread is not needed.
  2. Creating a thread within the iteration of your resultset (cfloop) is a VERY  bad idea!

Ubuntu 10.04 LTS server always selecting older kernel despite updates

I hit a really strange issue for some time now with one of my Ubuntu 10.04 LTS servers where, despite doing recent kernel updates (the latest is 2.6.32-33) it always booted into the kernel 2.6.32-28. No matter what I did (update-grub, etc.), the server was sticked to 2.6.32-28.

After searching and reading a lot of posts and wiki pages I still couldn’t find a solution for it (most blogs and wiki pages talk about compiling a new kernel or installing a new one, but none talked about selecting the proper kernel or fixing it manually).

But since I had some other server, that booted into the correct kernel issue, I luckily had some config files to compare. The one that I was after is the “menu.lst” which is a GRUB file and is located at “/boot/grub”. Looking at the menu.lst from the working server and comparing it to the “not working” one, revealed that the “non working” one had UUID’s declared for each server while the working one not UUID but “root (hd0,0)” and hard coded root paths of “/dev/sda3″.

Working config:

title   Ubuntu 10.04.2 LTS, kernel 2.6.32-33-server
root    (hd0,0)
kernel  /vmlinuz-2.6.32-33-server root=/dev/sda3 ro quiet splash
initrd  /initrd.img-2.6.32-33-server
quiet

Not-Working config:

title   Ubuntu 10.04.2 LTS, kernel 2.6.32-33-server
uuid  9823d540-6bf0-467a-8640-39d33c7544fb
kernel  /vmlinuz-2.6.32-33-server root=UUID=d9e79ad9-6d53-4cb5-85d6-e9f1eea712f2 ro quiet splash 
initrd  /initrd.img-2.6.32-33-server
quiet

As you can see from the this, the UUID and the root are quite different. I can’t actually explain why this configuration took place on this particular server. This is even more surprising since both servers are being “kept in sync” (with updates and such).

In any case, the resolution (for me at least) was to copy certain parameters over to the “not-working” menu.lst. Those were, the root path (/devsda3), the “root (hd0,0)”, the “groot=(hd0,0)” plus the “kopt=root=/dev/sda3 ro” lines.

It took a long time to fix this issue and and I hope this helps someone else.

svn: warning: cannot set LC_CTYPE locale

Somehow with the recent Ubuntu 10.04 LTS updates or maybe with a subversion update, I received some errors message of the type “locale…”. To be more precise the errors are;

svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LC_CTYPE is UTF-8
svn: warning: please check that your locale name is correct

While all SVN commands still worked, it was something I didn’t tackle with immediately. But today, I set out to fix it. Well, it only took a minute or so :)

So, if you want to fix this all you have to do is to set the “LC_ALL” variable manually. To make it permanent just edit the file “/etc/environment” and add the line:

LC_ALL=C

Save the file and exit the editor. In order for it to apply you have to logout of the current shell session. The next time you log in, the issue with SVN will be gone.