Aug 032010
 

Hopefully gone are the days when programmers work was measured in the number of lines of code they produced!  Any programmer knows this is in fact entirely the worst possible measurement of a programmers skill, the same result in half the code almost invariably means better, more easily maintained code.

Every so often howevert it’s useful to know the size of a code base you are working on so it gives you some idea of the scale of work that may be required, at this stage you need a free source code line counter,  and having looked recently the best one I found was one called CLOC – short for Count Lines of Code.

Amazingly fast, great language coverage, and awesome reporting.  With a single line of code I get a break down of all the programming languages in use, and how many lines of source code exist for each.

On Windows it’s as simple as:

cloc-1.51 --by-file-by-lang "C:\path-to-folder-requiring-count" --out="C:\path-to-ouput\count.txt"

Check it out: http://cloc.sourceforge.net

Enjoy!

Nov 262009
 

Going through some testing as part of our upgrade to Coldfusion 9 I encountered a compatibility issue that is worth knowing about. In Coldfusion 9 there is now a variable status “undefined”, that is the variable can exist (and appear in cfdump for example) but is not usable, it is explicitly undefined. This is a problem because if you try and use cfparam later for example it doesn’t override the “undefined” variable. So far the only place I’ve seen this is when using components, and then to be fair the condition arose because of some inconsistent defaulting so it’s not completely the fault of the new process but it’s worth being aware of if you are getting unexplained “undefined” errors when moving up to Coldfusion 9.

Ok so consider the following:

<CFFUNCTION name=”getByCriteria” access=”public” returntype=”query” output=”false” displayname=”” hint=””>
<CFARGUMENT name=”child_ocl_id” required=”false” >

This will result in an explicitly set variable that is set to “undefined” – the cfdump is thus:

cfdump_with_undefined_variable

Note the explicitly “undefined” status as well as (what my code was expecting) the “[empty string]” status

This stays the same whether you add a cfparam later or not, thus:

<CFFUNCTION name=”getByCriteria” access=”public” returntype=”query” output=”false” displayname=”” hint=””>
<CFARGUMENT name=”child_ocl_id” required=”false” >
<CFPARAM name=”arguments.child_ocl_id” default=”my new default” >

Note the above example isn’t what was in my code! It’s just a simple explanation of the behaviour I noticed. So just something to be aware of if you get unexplained “undefined” errors in your migration to Coldfusion 9.

Nov 162009
 

The Coldfusion open source community just keeps getting stronger. Whenever I talk to other cf programmers who are thinking of moving to another platform (there still seems to be a deep seated belief that CF is not a “real” programming language) I point them to great projects like RIAForge or a host of open source tags and components that I have used recently to remind them that the community is alive and well.

The latest of these that I have implemented successfully is an excellent implementation of DaisyDiff by Daniel Mackey.  Though he has put together a direct Java jar implementation I have opted for his CFX_CompareHTML implementation because of it’s support for UTF-8 characters, he sent it on to me directly the last time I checked it wasn’t available on line (thanks Dan).

The free CFX_compareHTML does a DIFF analyses on formatted html, and then displays it as a combined diff output, this is useful for comparing before and after content for example and is comparable to tools such as (the very expensive) diffdoc.  Diffdoc costs about $4000 for a server license, and while it has more applications (i.e. as a desktop tool) for web based html comparison CFX_CompareHTML is more than adequate.

Once installed (the one downside of CFX tags is of course the need to install them and set their path in CF admin) it’s as simple as:

<cfx_CompareHTML left=“Some HTML content” right=“Some more HTML Content”>

Produces the following (nicked from CFDan.com – hope that’s ok Dan?!)

compareHTML

As I mentioned there are a couple of great tags/components in the CF open source world that I’ve used lately, and inspired by this excellent work I’ll be documenting them over the coming days.

Oct 122009
 

Something I have to continually remind myself about for some reason is how to define and use shortcut keys for snippets in CFEclipse.   I’ve written about how to use snippets in cfeclipse before but failed to mention that an additional powerful feature is the ability to have them operate using keyboard shortcuts.

So, here it is in all it’s glory:

Firstly I’ve assumed you have set up a snippet in cfeclipse as described here.

Now, you will notice there is an attribute int eh snippet description called “trigger text”, this is the the text that is used to specify your shortcut, it is however not used as the short cut itself but rather in combination with the actual snippet shortcut which at time of writing was CTRL + J.

So, having saved a snippet with a trigger text for example of “rk” you can cause the snippet to appear by typing anywhere on the page:

rk+CTRL+J

And your text should magically be replaced by the new snippet.

Jun 062009
 

Something I had to do a while back, but have had to repeat recently when setting up new servers is setting IIS to run robots.txt files as if they were a dynamic page.  This is because I run a single code base that shows different languages depending on the domain being called.  The process for doing this is, in theory, quite straight forward but it got a little fiddly as I worked on it late in the evening so I thought I’d log the standard process as well as the problem I encountered.

NB: I’ve included Coldfusion in the title because that’s the language I was using on the site in question, it’s not actually a Coldfusion process, but it should work fine on any IIS based CF system.

Firstly set up the IIS server so that it will run your robots.txt dynamically:

By default IIS will treat .txt files as non dynamic and will simply render the text in them if they are called.  We want to tell IIS to parse them in the same way they would parse .asp files.  Note there’s a handy example of how to parse robots.txt files with ASP.net here.

Get the path to the ASPX engine

This bit is adapted from ASP.net article mentioned above.

  1. Open IIS and right click on your website and bring up the properties screen
  2. Go to Home Directory > Configuration. You will be on the Mappings Tab.
  3. Locate the .asp item and click Edit – Copy the path in the Executable Field and cancel out of that window. Make no changes here, you just need the path to the executable.
  4. Now, check to see that .txt extension has not been defined (if it has you should check to see who has made this change and why before changing).
  5. If it has not been defined then click ‘Add’, paste the path into the ‘Executable’ field, and ‘.txt’ into the ‘Extension’ field.  In the ‘Verbs’ field you should limit the verbs to ‘POST,GET’ – I haven’t investigated security implications for this, but limiting by default is a good idea IMO.  Both ‘Script engine’ and ‘Verify that file exists’ should be checked.
  6. If it has been defined and you don’t mind changing it, obviously skip the add bit, click on the extension then click ‘Edit’ and make changes as above. 
  7. Once you’ve saved, ‘OK out’ of the configuration section

Double check that Active Server Pages are enabled 

This is the bit that got me the other night, working on a new install there was no reason for Active Server Pages to be enabled, so when I was testing nothing happened.

In IIS again, this time click on Web Service Extensions (below the Web Sites folder), on the right there should appear a list of extensions.  Active Server Pages should be one of them, and it should be set to ‘Allowed’.  If not make it so!

Now, restart IIS and test it all works

Assuming you have done nothing yet to your old robots.txt (and it had something in it), when you now try to browse to it in the browser you should get a an unformatted dump of the text you had in it. This means IIS is now using Active Server Pages to parse the request, but there is no .asp code to parse so it just renders text.

From here you need to put some .asp logic in place so that it loads the appropriate information.

If you get a 404 error

It probably means you have not allowed ASP pages to execute, refer to instructions above. Remember to restart IIS again after doing this.

Reblog this post [with Zemanta]