tag:blogger.com,1999:blog-101238152024-03-08T05:08:49.907-08:00Tech EruditionI welcome you to My Web Log.
Enjoy reading it, comment on topics you want to.
Thank you.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.comBlogger107125tag:blogger.com,1999:blog-10123815.post-51182605683304567412012-10-10T13:30:00.002-07:002012-10-10T13:30:37.024-07:00MySQL: Working with timestamp columns in table.<div dir="ltr" style="text-align: left;" trbidi="on">
CREATE TABLE record (createdon TIMESTAMP, modifiedon TIMESTAMP);<br />INSERT INTO record (createdon, modifiedon) VALUES ('2010-10-01 11:01:02', '2010-10-01 11:01:02');<br /><br />SELECT * FROM record;<br /><span style="font-family: "Courier New",Courier,monospace;">+---------------------+---------------------+<br />| createdon | modifiedon |<br />+---------------------+---------------------+<br />| 2010-10-01 11:01:02 | 2010-10-01 11:01:02 | <br />+---------------------+---------------------+</span><br /><br />ALTER TABLE record ADD COLUMN activeon TIMESTAMP;<br />UPDATE record SET activeon=modifiedon;<br /><br />SELECT * FROM record;<br /><span style="font-family: "Courier New",Courier,monospace;">+---------------------+---------------------+---------------------+<br />| createdon | modifiedon | activeon |<br />+---------------------+---------------------+---------------------+<br />| 2012-10-11 01:47:41 | 2010-10-01 11:01:02 | 2010-10-01 11:01:02 | <br />+---------------------+---------------------+---------------------+</span><br /><br />Why did createdon value change???<br /><br />SHOW CREATE TABLE record;<br /><br />CREATE TABLE `record` (<br /> `createdon` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,<br /> `modifiedon` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',<br /> `activeon` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'<br />)<br /><br />MySQL applies the default rule when timestamp data-type is specified during column creation.<br />The 1st column of table (without explicit rule) gets a rule for update CURRENT_TIMESTAMP <br />
<br />Which would mean, if during update of record a value is not provided for the column the<br />value will get updated automatically to current timestamp.<br />
<br />
Which was the reason why createdon got changed when activeon was updated!<br /><br /><b>How to tackle this behavior?</b><br /><br />If application is controlling the data value on timestamp columns, when creating the timestamp<br />column we should ensure to mention the default rule.<br /><br />CREATE TABLE record (createdon TIMESTAMP NULL DEFAULT NULL, modifiedon TIMESTAMP NULL DEFAULT NULL);<br />ALTER TABLE record ADD COLUMN activeon TIMESTAMP NULL DEFAULT NULL;<br /><br />This helps in avoiding surprises!<br /><br /></div>
Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-75892680770749105592012-10-04T22:48:00.001-07:002012-10-04T22:49:12.230-07:00MySQL: Custom string sorting using CASE operator / FIELD function.<div dir="ltr" style="text-align: left;" trbidi="on">
Encountered a "problem of sorting" today when attempting to display list of record<br />
based on status values.<br />
<br />
status value can be one of these (New, In Progress, Deferred, Closed)<br />
<br />
ORDER BY status would result in (Closed, Deferred, In Progress, New)<br />
<br />
It follows the alphabetical order. However, for our list New and In Progress carried more weight than Deferred and Closed.<br />
<br />
MySQL provides CASE operator which can be handy in solving it.<br />
<br />
ORDER BY CASE status WHEN 'New' THEN 1 WHEN 'In Progress' THEN 2 WHEN 'Deferred' THEN 3 ELSE 4 END;<br />
<br />
MySQL also provides FIELD function that can be used to achieve the same:<br />
<br />
ORDER BY FIELD (status, 'Closed', 'Deferred', 'In Progress', 'New') DESC;<br />
<br />
<b>CASE vs FIELD</b><br />
<br />
* FIELD needed list of all values and DESC order in this case. <br />
* CASE needed specific weight for each value and provided default handling (ELSE).<br />
* CASE provides usage of LIKE and other operators on the target field.<br />
http://stackoverflow.com/questions/3579760/mysql-case-in-select-statement-with-like-operator<br />
<i><br />NOTE: </i><br />
Be sure to index the columns on which CASE / FIELD operates on to avoid performance penalty.<br />
Avoiding LIKE comparison is also advised to take advantage of the indexing.</div>
Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-1469983357559809042012-02-25T10:17:00.002-08:002012-02-25T10:17:44.138-08:00Getting Express project ready with Coffee.<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: "Courier New",Courier,monospace;">
#!/bin/sh<br />
# Utility script to create express project and make it ready with coffee scripts<br />
# Assumes the availability of (express, js2coffee) node modules on path.<br />
<br />
PROJECTDIR="$1"<br />
<br />
if [ "$PROJECTDIR" = "" ]; then<br />
echo "Usage: $0 projectname";<br />
fi<br />
<br />
express $PROJECTDIR<br />
<br />
echo " converting js to coffee and installing dependencies"<br />
<br />
cd $PROJECTDIR<br />
js2coffee app.js > app.coffee; rm app.js<br />
js2coffee routes/index.js > routes/index.coffee; rm routes/index.js<br />
npm install<br />
<br />
echo " \n$PROJECTDIR is ready now."<br />
echo " \$ cd $PROJECTDIR"<br />
echo " \$ coffee app.coffee"</div>
</div>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-25915800132891139482012-02-21T23:04:00.000-08:002012-02-21T23:04:05.901-08:00PHPNohup - execute in background.<div dir="ltr" style="text-align: left;" trbidi="on">
Finally got some breakthrough in executing the long-running stateless scripts on the server using PHP in background.<br />
<br />
Checkout: <a href="https://github.com/prasad83/phpnohup">phpnohup @github</a></div>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-25085926736752621882012-02-18T12:06:00.000-08:002012-02-18T12:06:52.186-08:00Cool markdown editors.<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> helps to get the quick documentation,<br />
preview enabled editors makes it easy to get the formatted content ready to be used.<br />
<ul style="text-align: left;">
<li><a href="http://mouapp.com/">http://mouapp.com</a></li>
<li><a href="http://markdownpad.com/">http://markdownpad.com</a></li>
</ul>
</div>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-49769948302185869512012-02-16T06:17:00.001-08:002012-02-16T06:17:57.624-08:00Started with MacOSX Lion and got-off with setup hiccups<div dir="ltr" style="text-align: left;" trbidi="on">
Following items came in handy:<br />
<ul style="text-align: left;">
<li>http://code.google.com/p/qlcolorcode/</li>
<li>http://stackoverflow.com/a/4115544</li>
</ul>
<div style="text-align: left;">
Enjoying the full-screen mode feature - helps to stay away from too many window distractions!<br /></div>
</div>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-87431434024315591202012-01-27T10:58:00.000-08:002012-01-27T11:03:17.333-08:00Google Chrome: input type="search" & results HTML attribute!<div dir="ltr" style="text-align: left;" trbidi="on">
Pulled my hair for a while as the search icon did not appear inside "input type='search'" on Chrome.<br />
<br />
Took a while to realize that I had missed results=".." attribute (number of history item to drop-down) in the HTML tag!<br />
<br />
<input type="search" placeholder="Search" results="3" ...></div>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-11007924130170461002012-01-20T00:13:00.000-08:002012-01-20T00:32:21.123-08:00Boilerplate template for apache ant build.xmlPulled up the basic boilerplate template for Apache ant build.xml that was written year's back. <br />You might find it useful to extend it further. Find it <a href="http://code.google.com/p/boilerplate-apps/wiki/AntBuildFileTeamplate">here</a>.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-20205447361473687612011-10-04T04:28:00.000-07:002011-10-04T04:34:11.669-07:00Filesearch in download directoryI 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.<br /><br />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.<br /><br />Here is the <a href="http://code.google.com/p/onweb/downloads/detail?name=filesearch.zip">download details</a>.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-68974908969467836462011-06-28T05:50:00.001-07:002011-06-28T05:52:33.541-07:00Javascript Array Sort Custom ComparatorJavascript Array.sort() allows you to define custom comparators! <br /><br />var numbers = [10, 20, 5, -10, 30];<br /><br />// Sorting in ascending order.<br /><code>numbers.sort(function(a, b){return a-b;});</code><br /><br />// Sorting in descending order<br /><code>numbers.sort(function(a, b){return b-a;});</code>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-59881492166596199462011-06-14T05:03:00.000-07:002011-06-14T05:08:28.306-07:00i18n-translator: makes it easy to translate and verifyTranslating 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. <a href="http://code.google.com/p/i18n-translator">i18n-translator</a> could be handy tool for it.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-22928267049528706652011-06-01T13:51:00.000-07:002011-06-01T13:55:53.893-07:00PHP 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.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-90486241332311934332011-03-10T22:39:00.000-08:002011-03-10T22:43:18.417-08:00Android 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 :)Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-48148248600687412482011-03-04T02:20:00.001-08:002011-03-04T02:24:25.062-08:00Working with Remote URL - BlackBerry SimulatorIf you are getting started to work BlackBerry development and aim at fetching connect from remote URL, to test with Blackberry simulator review the following:<br /><br />* Setup Wifi on the Blackberry Simulator.<br /><br />* Blackberry MDS is running - without which Remote URL fetch attempt silently fails.<br /><br />* Grant access in the app (config.xml)<br /> <access subdomains="true" uri="http://targetdomain.tld"> or <br /> <access subdomains="true" uri="*"> <br /> <br />* Now launch the app and test the url fetch. (assuming it uses javax.microedition.io.* classes) <br /><br />NOTE: Blackberry MDS failed to work as expected on Windows Vista/Windows 7, I had to switch on Windows XP!Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-67466074101299552662011-02-04T04:52:00.000-08:002011-02-04T09:14:24.465-08:00va_callback plugin for jQueryPassing state information through variables for callback function is essential.<br />Although <a href="http://api.jquery.com/jQuery.proxy/">jQuery proxy</a> API is available, it does not seem to accept more arguments to be tunneled for the callback.<br /><br />jquery-vacallback plugin targets to achieve the same. <br /><br />Click to <a href="http://jquery-vacallback.googlecode.com/files/jquery.vacallback.js">download</a> plugin. Look at the <a href="http://code.google.com/p/jquery-vacallback/wiki/Example">example</a>.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-82563903558236923142011-02-04T03:18:00.000-08:002011-02-04T03:23:43.267-08:00TextMate - ThemesFollowing places could help you find <a href="http://wiki.macromates.com/Themes/UserSubmittedThemes">themes</a> for <a href="http://macromates.com/">TextMate</a>.<br /><br /><a href="http://wiki.macromates.com/Themes/UserSubmittedThemes">http://wiki.macromates.com/Themes/UserSubmittedThemes</a><br /><a href="https://github.com/filmgirl/TextMate-Themes">https://github.com/filmgirl/TextMate-Themes</a><br /><a href="http://textmatetheme.com/themes">http://textmatetheme.com/themes</a>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-60262076158513608072011-02-01T13:34:00.000-08:002011-02-02T03:48:49.279-08:00fileloader plugin for jquery 1.5jquery 1.5 has introduced <a href="http://api.jquery.com/category/deferred-object">Deferred Object</a> feature.<br /><a href="http://code.google.com/p/jquery-fileloader"><br />fileloader plugin</a> is developed taking advantage of the same.<br /><br />This should help you to build classes, which loads the resources required ondemand and proceed with operation once the fetch is completed. <br /><br />Click to <a href="http://jquery-fileloader.googlecode.com/files/jquery.fileloader.js">download</a> plugin. Look at the <a href="http://code.google.com/p/jquery-fileloader/wiki/Example">example</a>.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-50015287440586695162011-01-10T01:10:00.000-08:002011-01-10T01:11:34.264-08:00Privilege - a Freedom factorOne who misuses privilege,<br />is not worthy for freedom.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-46890637829805131182010-12-25T09:48:00.000-08:002010-12-25T09:52:17.290-08:00Ignorance - Courage - WisdomIgnorance is Past,<br />Courage is Present,<br />Wisdom is Future.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-36317338318606449992010-12-14T04:14:00.000-08:002010-12-14T04:28:45.533-08:00gnu-hylafax: scheduler NAK'd request ?Working with <a href="gnu-hylafax.sourceforge.net/">gnu-hylafax library</a> is a great, but if you don't pay careful attention it can blow your mind and keep you awake the whole night!<br /><br />I kept wonder why sendfax command works fine but application built using gnu-hylafax library ends up with exception.<br /><br /><code>460 Failed to submit job *: Unspecified reason (scheduler NAK'd request).<br /> at gnu.hylafax.HylaFAXClientProtocol.jsubm(HylaFAXClientProtocol.java:702)<br /> at gnu.hylafax.HylaFAXClient.submit(HylaFAXClient.java:632)<br /> ...</code><br /><br />On reason for this was missing call to <i>job.<a href="http://gnu-hylafax.sourceforge.net/gnu-hylafax-core/apidocs/index.html">setKillTime</a>("value"); </i><small>(preferable to set value as 00259)</small> This translates to <u>JPARAM LASTTIME value</u> command. <br /><br />How to trace the issue? <br /><br />Enable <a href="http://prasadblog.blogspot.com/2010/12/commons-logging-log4j-configuration.html">Log4JLogger for the application</a>, you should be able to get the trace of all the TELNET commands executed. Verify the same with (sendfax -vv ...)<br /><br />Sample log4j.properties file with gnu.hylafax.ClientProtocol logger:<br /><br /><code>#set the level of the root logger to DEBUG and set its appender as an appender named X<br />log4j.rootLogger = DEBUG, X<br /><br />log4j.logger.X = DEBUG, X<br />log4j.logger.gnu.hylafax.ClientProtocol = DEBUG, X<br /><br />#set the appender named X to be a console appender<br />log4j.appender.X=org.apache.log4j.ConsoleAppender<br /><br />#set the layout for appender named X to be a pattern layout <br />log4j.appender.X.layout=org.apache.log4j.PatternLayout</code>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-16969799587755202782010-12-14T02:40:00.001-08:002010-12-14T02:47:09.058-08:00Commons Logging - Log4J ConfigurationIf you use <a href="http://commons.apache.org/logging/">commons-logging</a> in your java application, make sure to have <a href="http://logging.apache.org/log4j/1.2/download.html">log4j library (jar)</a> and log4j.properties file on the class path. You really don't need much tweaking to get started :)<br /><br />Simple log4j.properties file:<br /><br /># Set root logger level to DEBUG and its only appender to A1.<br />log4j.rootLogger=DEBUG, A1<br /><br /># A1 is set to be a ConsoleAppender.<br />log4j.appender.A1=org.apache.log4j.ConsoleAppender<br /><br /># A1 uses PatternLayout.<br />log4j.appender.A1.layout=org.apache.log4j.PatternLayout<br /><br />To learn more on jump to <a href="http://logging.apache.org/log4j/1.2/manual.html">log4j manual</a>Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-43754240592733685742010-10-21T10:57:00.000-07:002010-10-21T11:11:19.865-07:00Boilerplate app for PHPGetting a quick start on application development adds a lot to subsequent progress. <br /><a href="http://boilerplate-apps.googlecode.com/svn/trunk/php"><br />Boilerplate app for PHP</a> 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 <a href="http://www.smarty.net">Smarty</a>, <a href="http://pear.php.net/package/MDB2/">MDB2</a> libraries. <br /><br />You will need to update config.php with database details and<br />start adding the logic to install.php, index.php, administrator.php<br /><br />Repository location: <a href="http://boilerplate-apps.googlecode.com/svn/trunk/php">http://boilerplate-apps.googlecode.com/svn/trunk/php</a><br /><br />Get a copy to start: svn export http://boilerplate-apps.googlecode.com/svn/trunk/php boilerplate-php<br /><br />Hope you will find it useful.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-9120878472549986432010-09-17T21:39:00.000-07:002010-09-17T21:43:18.613-07:00What makes a team poor?Having right ones at wrong place,<br />and Wrong ones at right place!Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-75966683611211845922010-09-15T03:15:00.000-07:002010-09-15T03:21:39.572-07:00GWT on Netbeans?Follow the post: <a href="http://blog.jdevelop.eu/2009/11/11/create-a-gwt-application-from-scratch/">Create a GWT Application from Scratch</a> to get started with <a href="http://code.google.com/webtoolkit/">GWT</a> on Netbeans!<br /><br />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<br /><a href="http://forums.netbeans.org/topic21379.html">Missing "javaee-endorsed-api-6.0" Class Library</a> it should help.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0tag:blogger.com,1999:blog-10123815.post-82099870621090217032010-01-28T00:09:00.000-08:002010-08-27T11:56:38.525-07:00Programmer's Notepad - pnotepadIf you are looking around for a light-memory footprint editor for quick coding with highlight and add-on support give <a href="http://code.google.com/p/pnotepad">Programmer's Notepad</a> a try.<br /><br />For coloring scheme you visit, <a href="http://code.google.com/p/pnotepad/downloads/list?can=2&q=type:Scheme&colspec=Filename%20Summary#">downloads section</a><br /><br />UPDATE: With Default Preset, 'Consolas', 10px Font configuration this editor works pretty much like TextMate. Learn about <a href='http://www.pnotepad.org/docs/projects/introduction'>Projects, Project Groups and Magic folder</a> for organizing your code.Prasad.Ahttp://www.blogger.com/profile/13643870081980612246noreply@blogger.com0