Wednesday, October 10, 2012

MySQL: Working with timestamp columns in table.

CREATE TABLE record (createdon TIMESTAMP, modifiedon TIMESTAMP);
INSERT INTO  record (createdon, modifiedon) VALUES ('2010-10-01 11:01:02', '2010-10-01 11:01:02');

SELECT * FROM record;
| createdon           | modifiedon          |
| 2010-10-01 11:01:02 | 2010-10-01 11:01:02 |

UPDATE record SET activeon=modifiedon;

SELECT * FROM record;
| createdon           | modifiedon          | activeon            |
| 2012-10-11 01:47:41 | 2010-10-01 11:01:02 | 2010-10-01 11:01:02 |

Why did createdon value change???


CREATE TABLE `record` (
  `modifiedon` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `activeon` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'

MySQL applies the default rule when timestamp data-type is specified during column creation.
The 1st column of table (without explicit rule) gets a rule for update CURRENT_TIMESTAMP

Which would mean, if during update of record a value is not provided for the column the
value will get updated automatically to current timestamp.

Which was the reason why createdon got changed when activeon was updated!

How to tackle this behavior?

If application is controlling the data value on timestamp columns, when creating the timestamp
column we should ensure to mention the default rule.


This helps in avoiding surprises!

Thursday, October 04, 2012

MySQL: Custom string sorting using CASE operator / FIELD function.

Encountered a "problem of sorting" today when attempting to display list of record
based on status values.

status value can be one of these (New, In Progress, Deferred, Closed)

ORDER BY status would result in (Closed, Deferred, In Progress, New)

It follows the alphabetical order. However, for our list New and In Progress carried more weight than Deferred and Closed.

MySQL provides CASE operator which can be handy in solving it.

ORDER BY CASE status WHEN 'New' THEN 1 WHEN 'In Progress' THEN 2 WHEN 'Deferred' THEN 3 ELSE 4 END;

MySQL also provides FIELD function that can be used to achieve the same:

ORDER BY FIELD (status, 'Closed', 'Deferred', 'In Progress', 'New') DESC;


* FIELD needed list of all values and DESC order in this case.
* CASE needed specific weight for each value and provided default handling (ELSE).
* CASE provides usage of LIKE and other operators on the target field.


Be sure to index the columns on which CASE / FIELD operates on to avoid performance penalty.
Avoiding LIKE comparison is also advised to take advantage of the indexing.

Saturday, February 25, 2012

Getting Express project ready with Coffee.

# Utility script to create express project and make it ready with coffee scripts
# Assumes the availability of (express, js2coffee) node modules on path.


if [ "$PROJECTDIR" = "" ]; then
        echo "Usage: $0 projectname";


echo "   converting js to coffee and installing dependencies"

js2coffee app.js >; rm app.js
js2coffee routes/index.js > routes/; rm routes/index.js
npm install

echo "   \n$PROJECTDIR is ready now."
echo "   \$ cd $PROJECTDIR"
echo "   \$ coffee"

Tuesday, February 21, 2012

PHPNohup - execute in background.

Finally got some breakthrough in executing the long-running stateless scripts on the server using PHP in background.

Checkout: phpnohup @github

Saturday, February 18, 2012

Cool markdown editors.

Markdown helps to get the quick documentation,
preview enabled editors makes it easy to get the formatted content ready to be used.

Thursday, February 16, 2012

Started with MacOSX Lion and got-off with setup hiccups

Following items came in handy:
Enjoying the full-screen mode feature - helps to stay away from too many window distractions!

Friday, January 27, 2012

Google Chrome: input type="search" & results HTML attribute!

Pulled my hair for a while as the search icon did not appear inside "input type='search'" on Chrome.

Took a while to realize that I had missed results=".." attribute (number of history item to drop-down) in the HTML tag!

<input type="search" placeholder="Search" results="3" ...>

Friday, January 20, 2012

Boilerplate template for apache ant build.xml

Pulled up the basic boilerplate template for Apache ant build.xml that was written year's back.
You might find it useful to extend it further. Find it here.

Tuesday, October 04, 2011

Filesearch in download directory

I found myself re-downloading files that was available in central-download-server (on internal LAN). The issue was primary the lack of web-enabled search application.

Developed a simple application using (PHP + jQuery + find command) that lets user to search for the files in the download server directory, if nothing found suggest for Google search.

Here is the download details.

Tuesday, June 28, 2011

Javascript Array Sort Custom Comparator

Javascript Array.sort() allows you to define custom comparators!

var numbers = [10, 20, 5, -10, 30];

// Sorting in ascending order.
numbers.sort(function(a, b){return a-b;});

// Sorting in descending order
numbers.sort(function(a, b){return b-a;});

Tuesday, June 14, 2011

i18n-translator: makes it easy to translate and verify

Translating strings using online-services for providing internalization support might be a fun job. However, you could end up with inconsistent translation. Verifying the translation across different services would helpful. i18n-translator could be handy tool for it.

Wednesday, June 01, 2011

PHP Performance Tuning: Watch out for notices, warnings, errors...

PHP error reporting like notices, warnings... adds performance overhead and would make it hard to trace. During development make sure to turn-on error_reporting (E_ALL) and fix the issues logged, it helps your code to reach production quality.

Thursday, March 10, 2011

Android 3.0 (Gingerbird) - Drains Battery!!!

Last week I upgraded to Gingerbird (Android 3.0) and noticed heavy battery draining! Turning off Wifi helped in retaining device run on battery for longer time :)

Friday, March 04, 2011

Working with Remote URL - BlackBerry Simulator

If you are getting started to work BlackBerry development and aim at fetching connect from remote URL, to test with Blackberry simulator review the following:

* Setup Wifi on the Blackberry Simulator.

* Blackberry MDS is running - without which Remote URL fetch attempt silently fails.

* Grant access in the app (config.xml)
<access subdomains="true" uri="http://targetdomain.tld"> or
<access subdomains="true" uri="*">

* Now launch the app and test the url fetch. (assuming it uses* classes)

NOTE: Blackberry MDS failed to work as expected on Windows Vista/Windows 7, I had to switch on Windows XP!

Friday, February 04, 2011

va_callback plugin for jQuery

Passing state information through variables for callback function is essential.
Although jQuery proxy API is available, it does not seem to accept more arguments to be tunneled for the callback.

jquery-vacallback plugin targets to achieve the same.

Click to download plugin. Look at the example.

TextMate - Themes

Following places could help you find themes for TextMate.

Tuesday, February 01, 2011

fileloader plugin for jquery 1.5

jquery 1.5 has introduced Deferred Object feature.

fileloader plugin
is developed taking advantage of the same.

This should help you to build classes, which loads the resources required ondemand and proceed with operation once the fetch is completed.

Click to download plugin. Look at the example.

Monday, January 10, 2011

Privilege - a Freedom factor

One who misuses privilege,
is not worthy for freedom.

Saturday, December 25, 2010

Ignorance - Courage - Wisdom

Ignorance is Past,
Courage is Present,
Wisdom is Future.

Tuesday, December 14, 2010

gnu-hylafax: scheduler NAK'd request ?

Working with gnu-hylafax library is a great, but if you don't pay careful attention it can blow your mind and keep you awake the whole night!

I kept wonder why sendfax command works fine but application built using gnu-hylafax library ends up with exception.

460 Failed to submit job *: Unspecified reason (scheduler NAK'd request).
at gnu.hylafax.HylaFAXClientProtocol.jsubm(
at gnu.hylafax.HylaFAXClient.submit(

On reason for this was missing call to job.setKillTime("value"); (preferable to set value as 00259) This translates to JPARAM LASTTIME value command.

How to trace the issue?

Enable Log4JLogger for the application, you should be able to get the trace of all the TELNET commands executed. Verify the same with (sendfax -vv ...)

Sample file with gnu.hylafax.ClientProtocol logger:

#set the level of the root logger to DEBUG and set its appender as an appender named X
log4j.rootLogger = DEBUG, X

log4j.logger.X = DEBUG, X
log4j.logger.gnu.hylafax.ClientProtocol = DEBUG, X

#set the appender named X to be a console appender

#set the layout for appender named X to be a pattern layout

Commons Logging - Log4J Configuration

If you use commons-logging in your java application, make sure to have log4j library (jar) and file on the class path. You really don't need much tweaking to get started :)

Simple file:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.

# A1 uses PatternLayout.

To learn more on jump to log4j manual

Thursday, October 21, 2010

Boilerplate app for PHP

Getting a quick start on application development adds a lot to subsequent progress.

Boilerplate app for PHP
is once such attempt where the skeleton structure is ready to give you the quick start. The application is developed using the MVC architecture. It is integrated with Smarty, MDB2 libraries.

You will need to update config.php with database details and
start adding the logic to install.php, index.php, administrator.php

Repository location:

Get a copy to start: svn export boilerplate-php

Hope you will find it useful.

Friday, September 17, 2010

What makes a team poor?

Having right ones at wrong place,
and Wrong ones at right place!

Wednesday, September 15, 2010

GWT on Netbeans?

Follow the post: Create a GWT Application from Scratch to get started with GWT on Netbeans!

If try to install GlassFish server and end up with reference problems to library (javaee-endorse-api) try installing 'EJB and EAR' plugin as pointed out at
Missing "javaee-endorsed-api-6.0" Class Library it should help.

Thursday, January 28, 2010

Programmer's Notepad - pnotepad

If you are looking around for a light-memory footprint editor for quick coding with highlight and add-on support give Programmer's Notepad a try.

For coloring scheme you visit, downloads section

UPDATE: With Default Preset, 'Consolas', 10px Font configuration this editor works pretty much like TextMate. Learn about Projects, Project Groups and Magic folder for organizing your code.

Monday, January 11, 2010

Installing GNUStep on Fedora Core

In the journey of installing GNUStep on my Fedora Core machine, I noted couple of useful pointers
that could help you save sometime.

* Install GNUStep Make from yum repository (yum install gnustep-make)

* make (compile source) and install GNUStep Base

You will need the following:
export GNUSTEP_MAKEFILES=/usr/lib/GNUstep/Makefiles/

* make (compile source) and install GNUStep GUI

You need to update ldconfig.

vim /etc/

Add the content below and save:


* make (compile source) and install GNUstep Backend

You will need the following:
export PATH=$PATH:/usr/local/bin/ix86/linux-gnu/gnu-gnu-gnu

Check out complete documentation on steps followed at How to install GNUStep on Fedora Core

Friday, January 01, 2010

serialize/unserialize php API - an observation

On first request, I was saving the object into session.
$userInstance = new Users_Model();
$_SESSION['__key'] = $userInstance;
Make sure the class Users_Model definition is available.

On second request, I retrieve the object from session for re-use.
$retrievedUserInstance = $_SESSION['__key'];
public '__PHP_Incomplete_Class_Name' => string 'Users_Model' (length=11)
private 'id' => string '1' (length=1)
// ...
I noticed the $retrieveUserInstance object missed several methods!!

I realized that on second request, the class Users_Model definition
is not available on the page load and unserialize API is not working as expected.

$_SESSION values are saved using serialize API (as session.save_handler was set to files)

On making the class definition available before session_start() call,
the $retrieveUserInstance worked fine.
private 'id' => string '1' (length=1)
// ...
Hope it saves sometime for you.

Sunday, December 20, 2009

pedit - simple text editor

I'm happy to make available to source-code of my memorable text editor (pedit)
that was developed as part of my Graduation (semester) project.

pedit is written using ncurses library and C++ language, with Object Oriented Programming concepts.

Give a try and feel free to extend it. If you have any feedback do keep me posted.

Thursday, November 12, 2009

Prototypejs 1.6 clash with JSON !!

Prototypejs 1.6 could break your JSON API usage, be careful !

This article could be a time-saver, prototype.js breaks Firefox 3.5 native JSON

Monday, November 02, 2009

Prototype - exception to be handled for IE

Prototype 1.6 has introduced API that works pretty well in Firefox but experienced a problem in IE (7).

Exception was being thrown in API that needed a special treat.

The highlighted workaround worked for me:
fire: function(element, eventName, memo) {
// ...
if (document.createEvent) {
} else {
element.fireEvent(event.eventType, event);
} catch(error) {
// Error: No such interface supported (IE)
return event;
Example:'myhidden_element_id', 'custom:change');

Saturday, October 31, 2009

mysql-java-connector: ResultSet getObject failure on Timestamp column if null

I had strange situation working with ResultSet when fetching Timestamp column from MyTable.

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

Connection connection = DriverManager.getConnection(
"username", "password");

Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT timestamp_column FROM mytable");

while( {

The cause of the failure was due to null value in timestamp_column !

The solution suggested about (zeroDateTimeBehavior=convertToNull) in the article, helped me overcome the failure.

All you need to do is:
Connection connection = DriverManager.getConnection(
"username", "password");

Wednesday, October 28, 2009

Eclipse Editor - Setting Line Delimiter Style

Was going crazy with my eclipse as line delimiter was different than other editors. This was causing issue with SVN commits (mixed line delimiters!)

Finally, found the way of setting the line preferences for Eclipse.

It is located under: Windows > Preferences > General > Workspace

Tuesday, September 15, 2009

Lynx - Text Only Browser for Windows!

Text only browser could speed up your work specially if you are on a low-speed internet connection and getting distracted with graphics on the web applications :)

Got hold of Lynx on windows, which is a cool text browser I have been using on remote servers!

Well, its easy to get started, download and configure the lynx.bat and lynx.cfg files.

Friday, September 11, 2009

PHPTAL - Template Attribute Language for PHP

It was fun to work with PHPTAL and walk team with a basic introduction today :). [Download here]

Thursday, August 27, 2009

Doc Comment could be a source of data!!!

While discussing ways of using PHP as data storage file, we passed over this interesting possibility.

PHP data file: CommentDataClass.php
Doc Comment could be a SOURCE OF DATA
This could be your data in string format!!
class CommentDataClass { }

Retrieving data: Data.php
include_once 'CommentDataClass.php';

// Taking advantage of PHP 5.x Reflection,
// Refer:

$reflectedClass = new ReflectionClass('CommentDataClass');

$reflectedClass->getDocComment(), $matches)) {
$data = $matches[1];
$data = trim($data);

var_dump(explode("\n", $data));
Well, this is just for fun, we don't recommend it for serious use :)

Friday, July 31, 2009

Apache 2.0 with PHP 5.3.0 on Windows

It took me sometime today to get my Apache 2.0 to run with PHP 5.3.0.

The builds for windows is available at

Download the VC6 x86 Build of PHP 5.3.0 build and unzip.

NOTE: VC9 x86 Build of PHP 5.3.0 build might not work with Apache 2.0 !!

You will need to make the following changes in your httpd.conf
LoadModule php5_module "c:/path_to_your/5.3.0/php5apache2.dll"
PhpIniDir "c:/path_to_your/5.3.0"
ScriptAlias /php/ "c:/path_to_your/5.3.0"

Tuesday, July 21, 2009

Gmail survey message - inconsistent !!!

I noticed the survey message flash on my Gmail account today marked as (last chance!)

Clicked on it to participate and was disappointed to get this message...

How did inconsistent behavior creep in??

Thursday, July 02, 2009

Playing with Camtasia project file

I had created a video using Camtasia last night using screenshot and planned to upload in the morning.
Before turning off the system, I moved the images into another drive.

In the morning, I opened the .camproj (Camtasia project) file and to my surprise all the images in it gone missing :(

A dialog box was presented to search and point location for each image. I had almost 50+ images!

With curiosity I opened (Introduction.camproj) in text editor it was a simple XML file :)

The imported images were looking like:

To keep things simple, I copied (Introduction.camproj) to the folder where all screenshots were present under directory images/

Opened Introduction.camproj in gvim and triggered the following command


It reflected as:

Finally I got the video to the original state.

Wednesday, March 18, 2009

Scrolling with row Headings Fixed - in Spreadsheet

Was quite happy to learn this tonight :)

Select cell in Excel sheet (OpenOffice calc) and Click on Window > Freeze,
this way you can make the rows below the selected cell scroll beneath it.

1. For Horizontal Freeze - Select only first cell

2. For Horizontal & Vertical Freeze - Select any other cell.

For Reference:

Friday, January 09, 2009

Turning On Mysql Query Logging

Edit mysql configuration file (my.cnf, like /etc/my.cnf) and the add an entry under mysqld section

log = /var/log/mysqld-all.log

Follow the steps given below:

1. chown mysql:mysql /var/log/mysqld-all.log

2. chmod o-r /var/log/mysqld-all.log

3. /etc/init.d/mysqld restart

Now when you execute sql you should see the log :)

Friday, January 02, 2009

Happy New Year 2009

Wish you a

Created this 3D Text Image from Inkscape
(Reference Article)

Sunday, November 04, 2007

VMware on Fedora Core 7

I have put up documentation on getting VMware Setup on Fedora Core 7, you can get it download it from here.

Monday, October 29, 2007

SVN - Trac - Apache Setup

I have put up a small documentation on achieving the SVN - Trac setup with Apache,
you can download it from here.

Update: Added information of setting up read-writer permission for SVN through Access file version2 here.

Wednesday, September 12, 2007

diffdir - compute diff between directory

Use this application if you want to compute difference between two directories
and create filter out files that has modifications or newer in the source directory.

It is available on subversion

You can download the application here.

Sunday, September 09, 2007

Useful Windows Tools

Sticky Notes For Windows:
* Add a note and right on it to find more options!
* You can customize each note.
* Set Alarm
* Load and Save Notes from File.
* And Many More... see documentation

Alarm Clock:
by Cinnamon Software

*nix utilities
Commonly used *nix commands for windows:
UnxUtils @sourceforge or UnxUtils

Check out most popular tools here:
Open Source For Mac and Windows

Learn more about Equivalent Linux Software on Windows

Thursday, September 06, 2007

Skype doesn't let Apache Start!

We found any issue with Apache startup when Skype is up.

Skype by default uses port 80 and port 443 for incoming connections,

unfortunately we want the same ports used for Apache in general.

You can change the preferences of Skype to work on different port in the preferences,
(Tools -> Options)

and keep your Apache running on port 80 or 443.

Some references:

[Thanks for Puneeth to figure out about changing skype preference on port]

Wednesday, September 05, 2007

Lanuchy - Keystoke launcher for windows

Launchy is a very cool tool for windows.

ALT+SPACE any where will bring up the launchy.

Right Click on Launchy window,
* You can configure Directory to index for searching and
also set the extensions to look for!
* Hotkey - configure it if you want Launchy to appear other than ALT+SPACE

ESC will push back Launchy.

Learn more on using launchy here.

[Are you on linux? Then have a look at katapult.

Tuesday, August 21, 2007

Database Comparsion - dbdiff

If you are looking for database comparision tool, try this dbdiff from RubyForge.

Monday, July 23, 2007

Setting up Repository


Steps to follow to setup CVS:

1. mkdir /home/cvsfolder
2. export CVSROOT=/home/cvsfolder
3. cvs init
Initialize your cvs folder

4. chown -R ownername:groupname /home/cvsfolder
5. chmod -R g+rwxs /home/cvsfolder
This is a important step. Here we are making the directory sticky.
When a user commits a file to cvs, the username might change but the
groupname still remains the same.

If you don't follow this step, you might end up in a situation where a developer
checks in the file and other developer can't commit the same file.

Import Project to CVS

1. mkdir /project/TestProject
2. touch /project/TestProject/README.txt
3. export CVSROOT=/home/cvsfolder
4. cd /project/TestProject
5. cvs import -m "Some initial comment on the project" TestProject youcompany release_tag

Your TestProject is in CVS now.

Checking out the from CVS

1. export CVSROOT=/home/cvsfolder
2. cvs checkout TestProject

Checking out from Remote Server CVS

1. export CVS_RSH=ssh
2. cvs checkout TestProject

Monday, July 02, 2007

Flash Object and z-index.

If you are working with Flash and HTML you will sooner or later run in to problems of overlay.
Find more details on


Flash content and z-index.

Experimenting with Flash content and z-index.

This page is powered by Blogger. Isn't yours?