jump to navigation

MySQL: Custom string sorting using CASE operator / FIELD function. October 5, 2012

Posted by prasada in Uncategorized.
1 comment so far

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.


Getting Express project ready with Coffee. February 25, 2012

Posted by prasada in Uncategorized.
add a comment
# 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 > app.coffee; rm app.js
js2coffee routes/index.js > routes/index.coffee; rm routes/index.js
npm install

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

PHPNohup – execute in background. February 22, 2012

Posted by prasada in Uncategorized.
add a comment

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

Checkout: phpnohup @github

Cool markdown editors. February 18, 2012

Posted by prasada in Uncategorized.
1 comment so far

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

Started with MacOSX Lion and got-off with setup hiccups February 16, 2012

Posted by prasada in Uncategorized.
1 comment so far

Following items came in handy:

Enjoying the full-screen mode feature – helps to stay away from too many window distractions!

Google Chrome: input type=”search” & results HTML attribute! January 27, 2012

Posted by prasada in Uncategorized.
add a comment

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″ …>

Boilerplate template for apache ant build.xml January 20, 2012

Posted by prasada in Uncategorized.
add a comment

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.

Filesearch in download directory October 4, 2011

Posted by prasada in Uncategorized.
add a comment

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.

Javascript Array Sort Custom Comparator June 28, 2011

Posted by prasada in javascript, programming.
add a comment

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;});

i18n-translator: makes it easy to translate and verify June 14, 2011

Posted by prasada in Uncategorized.

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.