Friday, November 17, 2006

JQuery Inplace editing with autocomplete option

Two common Ajax features that go hand-in-hand are "In-place editing" and "autocomplete". Although, many "Javascript" or "Ajax" frameworks provide functions or plugins for "in-place editing" and "autocomplete", pulling them together can be messy and difficult. Hence, I have modified and extended two such JQuery plugins (Inplace editing and autocomplete) to support both in one function call. By using this single function, you can get set an editable input box to show autocomplete options. Further, I have extended autocomplete script to have provision for specifying input separator.

Check - demo

Saturday, September 23, 2006

The Framework War

In the midst of thousands of competing and evolving PHP frameworks, finding a suitable rapid web application development framework can be as arduous as finding a perfect bride. Nevertheless, the quest for a perfect framework is an interesting process of excitement and frustration, learning new things and abandoning previously held mental concepts. For long, I have wandered the maze of internet, open source projects and online forums, looking for a perfect web application development framework. I was looking for a framework that is easy-to-learn, has a vast resource of tutorial and an active user forum, and does only things that I want it to do. In precise, I wanted a framework that takes care of rudimentary database connections and query handling. In my quest, I experimented Drupal, Qcodo, Ruby on rails, and finally settled for CakePHP. Drupal is a PHP based content based management system. An excellent framework that provides pre-built website templates, modules, and extensive set of functionalities that takes care of rudimentary work. Nevertheless, it has a very long learning curve. Even after playing with Drupal for more than three months, Drupal remained as a black hole to me. In a way, Drupal was doing much more than I wanted to him to do. Drupal was more meant to provide a prebuilt content management website and less for handling database interactions. After abandoning Drupal, I experimented Qcodo. Qcodo is again a PHP based rapid application development framework. There motto is "Code less. Do More". I found that motto interesting. Intial experiment with Qcodo, showed interesting results. Neverthless, Qcodo creates individual classes for each database table and, thereby, exposes lot of code that is especially frustrating for me. Definitely many developer's will argue that this provides flexibility; but I believe there is no necessity to have individual classes for each table. Theoretically, select, delete, and update should are handled the same way for each table and thus there is no need to implement individual classes for each table.

After looking for another framework, I stumbled into Ruby on Rails. Although, Ruby on rails is not based on PHP, it is easy to setup and get basic web application running within 5-10 minutes. It’s scaffold techniques provides all the necessary element to get website running within minutes. The ease with which I was able to build my website made me to think to abandon PHP and start learning ruby on rails. But, luckily, before I made a move, I found about CakePHP. CakePHP is replication of "Ruby on Rails" but in PHP. It provides the same functionalities as in "Ruby on rails", but has an added advantage of being in written in PHP.

After a long and tiring search and experiments with many different frameworks, I finally found a perfect framework. In the process I learnt many lessons. Some of my key lessons are
1. The most important thing when selecting a suitable framework is to know functionalities you desire to have in your web applications. Having a list in hand is always useful as it allows you to evaluate functionalities and compare frameworks. In my search for a framework I made a mistake that I kept losing focus of things that I want to have in my browsers.
2. Pick a framework that is easy to learn, has many tutorials, and an active developers and users community.
3. Finally use google, blogger, and forums to know about frameworks and what other people talk about it.

Thursday, August 17, 2006

Word Document management using SVN

Seeting Microsoft Word Document Management System
using SVN and TortoiseSVN

Any form of writing is an iterative refinement of thoughts, language, and vocabulary. But, Microsoft Word, one of the most popular editors in the Windows world, does little to facilitate this iterative refinement of the document. Although Microsoft word provides "review" functionality that keeps track of changes in the document, using reviewing functionality makes the document cluttered and messy. Further, Microsoft Word does not provide common functionalities such as comparing, merging, or identifying differences between different versions of the document.

Managing multiple versions of a software code (written in java, C, etc) is a well established technology in the software development world. One such tool that facilitate managing multiple version of the software code is SVN. Yesterday, after getting frustrated with the limited capability of the Microsoft word in managing multiple version of the document, I thought of using SVN. After Googling and searching on blogs, I found that SVN along with TortoiseSVN can be used to setup a free home-made document management system for maintaining word documents. To get you an idea of the power of this free document management system, below is the image of the Microsoft Word (2007) that shows different version of the same document. Notice "new addition" in the title.

The image below shows the
1. The current document on which I am working (lower right panel)
2. The previous version of the same document (upper right panel)
3. Changes in the document. New additions are shown in Red Color (middle panel)
4. Only changes (left panel)

Step by Step instructions to setup Microsoft word document management system
1. download latest SVN
2. Install SVN with default setting
3. Download TortoiseSVN
4. Install TortoiseSVN with default settings
5. After restarting the computer, create a folder, title SVN, on C:\ drive i.e. C:\SVN
6. Right click on the "SVN" folder and select TortoiseSVN > Create Repository here (see fig 2) Select default Native filesystem (FSFS) and click OK. This creates a repository where SVN stores all versions.

7. Now import the files. For this select the folder that contains the files and right click and select TortoiseSVN > Import. In the popup box, select c:\svn for the "url of the repository" and click OK
8. Now create another folder "svn_doc" where ever you want. In this folder we will checkout a copy of all files. For this right click on the folder and select "SVN Checkout" from the context menu.
9. All the files that were imported now should be available in this folder.
10. Now always use files from this new folder. Whenever you edit any file, commit changes to SVN by right click on the file and selecting "SVN commit". To see difference between two versions, select the file and right click and select TortoiseSVN> diff. Mircorsoft word should start and show current file, last saved version, and the differences, as shown in the fig 1.

This setp is required only for Microsoft Office 2007
1. To be able to see the differences in the *.docx file, right click on any file and select TortoiseSVN > setting. In the tree view select Diff Viewer and click on the "Advanced" Button. Select extension .doc and click on edit. Change "doc" to "docs". Alternatively you can create a new extension "docs" and copy the diff viewer location from "doc".

Enjoy free document management system.

Monday, July 03, 2006

PHP Shell_exec problems

For a week, I struggled to execute a Perl script and grab it’s output, all to be done within a PHP program. Finally, after an exhaustive search, I found my savior – “Shell_exec” command in PHP. Although, the “shell_exec” command does exactly what I wanted, the road ahead was full of thorny issues. To help developers in the similar situation as of mine, here I present a structured document on the problems that one might encounter while trying to run “shell_exec” command.

Problem 1: Shell_exec() []: Cannot execute….. in Safe Mode:

Solution: In this case, the potential problem might be that your php is running in safe mode. Open php.ini file in a text editor and search for “safe_mode”. Make sure that it is turned off i.e

safe_mode = Off

Restart your webserver and try to run the php program again. "Shell_exec" command should be working now.

Problem 2: Able to execute simple commands such as “cmd”, “cd”, etc., but not perl script

Problem 3: Able to run perl script via command prompt but not using shell_exec

Solution: Problem 2 and 3 are related and, in most cases, are caused by the same problem. In both cases, probably, including the full path of perl.exe might solve the problem of running a perl script. For example

Shell_exec(“perl”) // originally I was trying this

Shell_exec(“c:\usr\perl\bin\perl.exe”); // by providing full path to perl.exe, my problem 2 and 3 got solved.

Another useful function that might was to consider is runExternal. It was contributed by one of the developers and is available on A copy of the runExternal function is below.

function runExternal($cmd,&$code) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to

$pipes= array();
$process = proc_open($cmd, $descriptorspec, $pipes);

$output= "";

if (!is_resource($process)) return false;

#close child's input imidiately


$todo= array($pipes[1],$pipes[2]);

while( true ) {
$read= array();
if( !feof($pipes[1]) ) $read[]= $pipes[1];
if( !feof($pipes[2]) ) $read[]= $pipes[2];

if (!$read) break;

$ready= stream_select($read, $write=NULL, $ex= NULL, 2);

if ($ready === false) {
break; #should never happen - something died

foreach ($read as $r) {
$s= fread($r,1024);
$output.= $s;


$code= proc_close($process);

return $output;

here is how to use it:

$result= runExternal("ls -l some-file.txt",$code);

print "

print $result;
print "

print "code: $code\n";

As you might already noticed, runExternal command replaces shell_exec. While shell_exec only returns output and no errors, runExternal returns output as well as errors. Thus runExternal is a useful during debugging process.