Archive for January, 2011

Comparing structs using CFCUnit testing framework

Tuesday, January 25th, 2011

A while back I wrote an entry describing how to use the Java Equal() method to compare two structs. I had looked this up because I was writing some unit tests and (obviously) needed to assert that one struct was equal to another struct.

As usual I probably should have referenced the CFC Unit docs before referencing the Java docs. Nonetheless, I did recently take a look at the assert methods provided in CFC Unit. In case your interested they can be viewed here. So there is an assert method assertEqualsStruct() that from what I can tell compares the data and structure of two structs. As such if you’re writing unit tests using CFCUnit you can also use this assert to perform the same check. Again from what I can tell they both do the same thing. So just wanted to post the update.

Python permission denied error when executing a CGI script

Friday, January 21st, 2011

I’ve just started playing with python with the intent of building android apps. As such this may be obvious to the seasoned python programmer, but nonetheless was not too terribly obvious to me at first.

After creating a CGI script to run I noticed that when the browser would execute the script I would get a 200 OK response from the browser, but the page was empty. Upon checking the terminal I received the following error:

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/http/server.py”, line 1059, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 13] Permission denied

The solution here is to give the script permission to be executed. To do this run the following line in the terminal (obviously I’m on a mac here):

chmod +x [name of you CGI script]

So just to keep things simple, assume you have a script in your Documents directory named ‘myScript.py’. You would execute the following in the terminal:

Documents myComputer$ chmod +x myScript.py

Essentially, this changes the mode of the specified script to be executable.

One thing to keep in mind, that dumbly wasted a few minutes of my time, is that if you have a terminal window open running the python server you cannot perform the above execution in that window. Make sure you open a new terminal window and execute on the command line.

Blackberry Playbook App Development

Monday, January 17th, 2011

I spent the bulk of last night and early this morning trying to set up an environment for building an AIR app for the Blackberry Playbook using Flash Builder, the AIR SDK 2.5, the Blackberry Playbook plugin SDK, and the Blackberry Playbook simulator. While the Blackberry website had a lot of excellent documentation concerning setup and getting started, I ran into an error when deploying an application to the simulator. I receive error: ‘Username or password is invalid or not specified or time on the device is out of sync’. Apparently, according to google, I’m not the only one getting this error. It appears that some were able to keep playing with the time until it finally worked, while others gave up and could not find a solution. Each time I installed the simulator it would get my current time, determine that I’m on the East Coast, and then subtract five hours off my time. I’m pretty sure this is the root of the error. I unfortunately, do not know how to resolve it. Setting the time to match my computer’s time does not work. The simulator only gives me five timezones to choose from, and none of which is the appropriate time zone to offset the five hours needed to have the appropriate time.

So I fall into the ‘I give up’ category. After spending a couple hours troubleshooting the issue with zero results to show for it I’m moving on. While the installation of all the necessary components is a little excessive in my opinion (especially compared to setting up for Android app development), the guidelines presented by Blackberry are thorough and well-written. Also note, that running the simulator requires VMWare Fusion if running on a mac. While, I’m not completely sure why this is required, it is a pretty sharp piece of software that I’m glad I was introduced to.

It’s unfortunate that what is most likely a minor bug creates so much havoc, but perhaps I’ll try again in a month or two and hope Blackberry has had a chance to resolve the simulator issue.

Using cfqueryparam list attribute when using ‘IN’ operator

Wednesday, January 12th, 2011

When writing SQL in Coldfusion where the ‘IN’ operator is used you will have to use the list attribute of the cfqueryparam tag, and if using a delimiter other than a comma will need to include the ‘separator’ attribute to indicate the delimiting character.  This, of course, only applies if the list of available values are stored externally in a variable.  Let’s take a look at how to use the ‘IN’ operator in Coldfusion and some varying scenarios that either will or will not work.

First: Using actual values (works)

<cfset variables.dsn = "cfartgallery" />

<cfquery name="variables.selectArt" datasource="#variables.dsn#">
	SELECT *
	FROM art
	WHERE artName IN ('Morph','Things','Ideas')
</cfquery>

(more…)

Just Finished Reading: Object-Oriented Programming in ColdFusion

Thursday, January 6th, 2011

I’m really glad to see this book (by Matt Gifford) mostly because it’s a book with a somewhat narrow focus around Coldfusion.  When I say ‘narrow’ I’m certainly not implying that CF or OOP is a narrow topic, but more or less that this is a book about Coldfusion programming that focuses its scope giving it more depth than a comprehensive study of how to program using CF.  You know, it’s not often that a new CF book rolls through my ‘Just Released’ column on my Safari library account.  So I was very pleased to see this one slide up the list.  On the other side of the token however, CF has an incredible blogging community that almost single-handedly serves as the gold mine of CF knowledge.

I’ll just quickly throw out first the negative critique to get it out of the way so no one dwells on it.  Minor at best, I noticed a number of editorial mistakes around grammar and spelling, especially towards the end of the book.  Nonetheless, as stated, trivial at best.

To be a book on programming, I found it to be an easy read with simple and cleanly explained concepts that can be pretty difficult to explain.  I particularly loved the focus on the use of components.  I myself am a 99% fan of CFCs and a 1% fan of a few custom tag wrappers that I’ve really liked.  The flow and organization of the book really worked for me.  The first three chapters are critical in that you should be able to formulate a stable self-documenting CFC that fully encapsulates its logic before learning how to use a set of CFCs in the larger scheme of an application.  Hence, the focus of the remaining four chapters.

Overall, I’m glad I took the time to read it and I definitely feel I have a more stable grounding in not only implementing an OO application, but more so understanding what it is I’m doing and why.

How would you like to work with me!

Thursday, January 6th, 2011

The company I work for (Andera, Inc) has some big plans and some big new investments.  As such it’s looking for a variety of talent to get there.  I’m pretty sure there are a couple engineering positions open, as well as a number of other types of positions.  I can attest that it is a cool place to work where you will be surrounded by awesome smart people, company provided beverages, and hackathons to name a few of the most important benefits.  There are also the more traditional benefits like 401k’s, health, and so on.

So if you’re in, or want to work in the Providence, RI area check out the Careers page of our site (I think you can fill out the application and everything there).  Also, if you get called in, make sure you let them know you were referred by Matt Cook, or the pukkared blog.  Oh, did I mention there are also awesome benefits for referrals? (Mwu haa haa)!

Setting up a read-only DSN in Coldfusion

Monday, January 3rd, 2011

In the case that you may be worried about database availability due to heavy stress on reporting queries, you may be considering data replication/streaming, if your specific database provider offers such a service (like Oracle’s Data Replication capabilities), to use for read-only reporting. This method helps ensure the availability of the database when data manipulation needs to occur. However, trying to write to a read-only database will, of course, bomb out.

Fortunately, Coldfusion offers a very easy way to guarantee that the read-only database is only used for SELECT statements. To begin with, both the writable database and the read-only database will need their own datasources set up in the CF Administrator.

(more…)

Writing recursive functions in Coldfusion

Sunday, January 2nd, 2011

A recursive function is a function that references itself. It allows a single function to use itself to continue processing. Let’s take a simple example of a struct with a nested struct as one of its values. The goal is to create a very simple function that will grab all values from the parent struct and convert them into an array. Our struct looks like the following.

Data Struct

Data struct

And in case you need it the code to create the above struct.

(more…)