Free source code line counter for Coldfusion (and most other languages)

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!

Copy Vs. Design for conversion rate optimisation

Great post on Search Engine Land on the relative value of meaningful copy Vs fancy design.
http://searchengineland.com/copy-vs-design-which-is-most-important-to-conversion-42983

Boobquake: Social networks shining a light on the world’s idiots!

I’m really getting into Social Media at the moment.  OK that’s not original and yes it’s a bit behind the 8 ball, but I have of course used it a lot before; I just haven’t really dug into it to try and understand the dynamic, what people are thinking when they use it, why they put such dumb stuff on it and also more importantly how it can be used constructively to really build links between disparate communities and expose those who would seek to maintain the artificial inequalities and misunderstandings that exist in the world.

In step Boobquake!

http://www.facebook.com/#!/pages/Boobquake/115608248460905

Blag Hag: And the Boobquake results are in!.

In response to the absurd claim by Iranian Cleric Hojatoleslam Kazem Sedigh that claimed that:

“Many women who do not dress modestly … lead young men astray, corrupt their chastity and spread adultery in society, which increases earthquakes,” (ref http://www.guardian.co.uk/world/2010/apr/19/women-blame-earthquakes-iran-cleric)

Jen McCreight decided to put it to the test and Boobquake was born.  At a time when the Iranian people need all the support they can get to stand up to the increasingly outrageous antics of their leaders this not only holds a light up to the ludicrous individual it provides valuable social proof to those within the country that their “noble leaders” aren’t the font of all knowledge.

Check it out, this sort of leverage is gold!

Convert adjacency list model to a modified preorder tree traversal (MPTT) model hierarchy

This us more a note to self than anything else, as I trawled the internet trying to find a definitive answer to this.  Modified preorder tree traversal (MPTT) is an efficient way to store and query hierarchical data in a database.  This article on the MySQL site explains why this is the case with a neat comparison between MPTT and a more “old school” approach which relies on a parent-child recursive relationship in the database (known as the Adjacency List Model).  I wont repeat what it says but suffice to say I’ve been experimenting with MPTT for a while and like the way it does things.

I use cakephp a lot and I have recently created a hierarchy of some 120,000 items, all neatly mapped with parent-child relationships but no MPTT data.  Cake’s inbuilt mechanism for converting adjacency list model to a modified preorder tree traversal (MPTT) model hierarchy was far to slow: on my PC and with this much data it was taking about a second per row, which adds up to an awfully long time to process the whole tree!

Given the need for this type of conversion I found it surprisingly difficult to find a script that the the Agency list to MPTT conversion, so I thought I’d document what I found here, and add to it if I find any further.

So, using the CakePHP naming conventions here is a script to convert Agency List to MPTT using MySQL and PHP.  This is much faster than the native CakePHP model->recover() method (which rebuilds your hierarchy) which is important on big datasets obviously.  This script is based on the function in this excellent article on MPTT.

//Make sure it doesn't time out
        set_time_limit (0);

	$con = mysql_connect("localhost","user","password");
	if (!$con){die('Could not connect: ' . mysql_error());}
	mysql_select_db("your_db", $con);

	function rebuild_tree($parent_id, $left) {
	   // the right value of this node is the left value + 1
	   $right = $left+1;   

	   // get all children of this node
	   $result = mysql_query('SELECT id FROM categories '.
	                          'WHERE parent_id="'.$parent_id.'";');   

	   while ($row = mysql_fetch_array($result)) {
	       // recursive execution of this function for each
	       // child of this node
	       // $right is the current right value, which is
	       // incremented by the rebuild_tree function
	       $right = rebuild_tree($row['id'], $right);
	   }   

	   // we've got the left value, and now that we've processed
	   // the children of this node we also know the right value
	   mysql_query('UPDATE categories SET lft='.$left.', rght='.
	                $right.' WHERE id="'.$parent_id.'";');   

	   // return the right value of this node + 1
	   return $right+1;
	}   

rebuild_tree('1',1);

mysql_close($con);

Using pure traditional SQL you can use the following script apparently, but I didn’t have time to make it work in MySQL and the above processed things quickly enough. The source of the script below is here http://data.bangtech.com/sql/nested_set_treeview.htm

-- Tree holds the adjacency model
CREATE TABLE Tree
(emp CHAR(10) NOT NULL,
 boss CHAR(10));

INSERT INTO Tree
SELECT emp, boss FROM Personnel;

-- Stack starts empty, will holds the nested set model
CREATE TABLE Stack
(stack_top INTEGER NOT NULL,
 emp CHAR(10) NOT NULL,
 lft INTEGER,
 rgt INTEGER);

BEGIN ATOMIC
DECLARE counter INTEGER;
DECLARE max_counter INTEGER;
DECLARE current_top INTEGER;

SET counter = 2;
SET max_counter = 2 * (SELECT COUNT(*) FROM Tree);
SET current_top = 1;

INSERT INTO Stack
SELECT 1, emp, 1, NULL
 FROM Tree
 WHERE boss IS NULL;

DELETE FROM Tree
 WHERE boss IS NULL;

WHILE counter <= (max_counter - 2)
LOOP IF EXISTS (SELECT *
 FROM Stack AS S1, Tree AS T1
 WHERE S1.emp = T1.boss
 AND S1.stack_top = current_top)
 THEN
 BEGIN -- push when top has subordinates, set lft value
 INSERT INTO Stack
 SELECT (current_top + 1), MIN(T1.emp), counter, NULL
 FROM Stack AS S1, Tree AS T1
 WHERE S1.emp = T1.boss
 AND S1.stack_top = current_top;

 DELETE FROM Tree
 WHERE emp = (SELECT emp
 FROM Stack
 WHERE stack_top = current_top + 1);

 SET counter = counter + 1;
 SET current_top = current_top + 1;
 END
 ELSE
 BEGIN -- pop the stack and set rgt value
 UPDATE Stack
 SET rgt = counter,
 stack_top = -stack_top -- pops the stack
 WHERE stack_top = current_top
 SET counter = counter + 1;
 SET current_top = current_top - 1;
 END IF;
 END LOOP;
END;

Anatomy of a Facebook Application – required viewing for architecture, FBML and FQL

While doing some research on Facebook Apps today I came across these excellent (albeit a little old) videos on TheChickenTest on the anatomy of a Facebook application.  I’ve played around with Facebook Apss before, but to be frank have never really taken the time to get to grips with them as a whole, only ever really focussing on spot tasks and specific requirements.

Check out the below, they’re required viewing as far as I’m concerned for potential Facebook App developers.

Anatomy of a Facebook Application (JayGoldman, Radiant Core)

FBML Overview (Sunil Boodram, Trapeze Media)

FQL Overview (Craig Saila)

Best free disk defragmenter for windows

Anyone who’s had a PC for more than a few months knows that it will begin to slow down over time, they probably also know about disk de-fragmentation which basically reorders your disk drive to perform more quickly.  The free one that comes with Windows is better than nothing, but the other day I came across MyDefrag which is easily the best free disk defragmenter for Windows I’ve found.

As a defragmenter it looks great, but one of the things it also does is segment your drive (not partition just organise in segments) based on the file type to ensure the most commonly used files are near the beginning of the drive which in itself can see a major improvement in performance.

If you’re looking for the best free disk defragmenter for Windows, check it out.

NB: not sure if “defragmenter” is actually a word!

The best site for colour/colour scheme inspiration I have seen so far :: COLOURlovers

While preparing a design brief I cam across the best site for colour inspiration I have seen so far.  COLOURlovers is a desing community all about demonstrating colour both on and off line.  Colour schemes are definitely not my strength so this resource is invaluable, the sites they use to demonstrate themes are well vetted for quality, easily laid out and often not only provide examples of best colour practice but also general design.

As I’m working on  a web design project I was most into the web design trends:

Trends / Browse :: COLOURlovers.

but there is so much else to the site it’s amazing.

http://www.colourlovers.com/

Thoroughly recommended viewing for colour inspiration

10 Golden Principles Of Successful Web Apps

The most usefully succinct summary of what makes a successful web app I’ve seen for a while.  Anyone looking for investment, or just looking for a Joel On Software ‘esque list of what to do watch this and then watch it again.


Tips for learning a language

Ok, so it’s a bit of self promotion, but I feel I have to point out the new language learning blog at Bitesized Languages, another project I have been working on with my good friend Gareth.  Gareth is an uber language nerd and all around smart guy, and while I bluff my way through a few things and like to think I have a few interesting points to make, he has really done the research and has got some invaluable tips to share with language learners.

Check out out the language learning blog here, otherwise try Bitesized for free word of the day emails in Spanish, French, Portuguese, Italian and German.

Excel 2007 values not updating automatically on change

In all the years I have used excel I have never once encountered this problem so hopefully this helps anyone else in the situation.  I have been used to Excel automatically updating its values (say in a sum() column) whenever I change values above, but somehow today it stopped working.  fortunately my better half happens to be an Excel nerd, so with her help I worked out what it was.

If you find that the values in Excel are not updating automatically it is probably because you have not got the (succinctly named) “calculation options” switched to automatic.  Apparently back in the day you were required to press F9 to do calculations at any stage, and indeed this still works, but if you want a more permanent solution in Excel 2007 at least goto:

Formulas > Calculation > Calculation options

Then check the “Automatic” selection.  This should rectify the problem immediately.