Archive for the ‘Programming’ Category


September 21, 2010

I came across a really handy tool to validate JSON strings. Kudos to the authors of this tool. Nice job!

How to add revision id to SVN controlled files

July 19, 2009

First register the file with subversion for keyword substitution. For example, you may need to add the actual revision number to the source code.

$ svn propset svn:keywords "Revision" source_file.c
property 'svn:keywords' set on 'source_file.c'

Next, edit your source code and add the keywords that you wish to be replaced, e.g.

#define VERSION "V 1.0 $Rev$"

Finally, from now on each time you commit the file to subversion, e.g., after you commit the file:

$ svn commit source_file.c -m "file with rev. id"
Sending        source_file.c
Transmitting file data .
Committed revision 190.

Now if you view your source code, it will have the revision number in the code, e.g.

#define VERSION "V 1.0 $Rev 190 $"

and each time you edit and commit the changes the revision number will be updated.

Combine PDFs with Python on Mac

June 21, 2009

I was looking for a way to combine PDFs (without using Acrobat) and came across this note.

$ python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/' -o '/path/to/output.pdf' '/path/to/input1.pdf' '/path/to/input2.pdf'

This command will generate the PDF and it will echo the following warning (date and name of your computer will vary, of course) which apparently you can safely ignore.

Sun Jun 21 14:58:34 sj.local Python [16000] : The function `CGPDFDocumentGetMediaBox' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGPDFPageGetBoxRect' instead.

Better yet, use the Mac Automator. You can use the Automator to combine multiple image files, or PDFs into a single PDF. You can then use the Previewer to re-arrange the pages and delete some of the pages if needed.

Physical Prototypes

September 24, 2008

So you’ve been writing software for ever but never build a system that interfaces with a physical world. Well here comes Processing and Arduino. I’ve not been this excited about building a prototype since … well a long time ago. The book that sparked my imagination is O’Reilly’s Making Things Talk. Well it all seems pretty easy. Order a pre-built microcontroller such as Arduino USB Board from Sparkfun, connect its input to a sensor, its output to the physical object that you wish to control, program what you want in Java (using Arduino based on Processing IDE right from your MAC laptop), dust off your soldering iron and voila you got yourself a real prototype. I cant wait to receive my Arduino board.

Mac OS X, Perl and SSL

August 30, 2008

Perl on MAC does not support SSL out of the box. So you must install SSL support:

sudo perl -MCPAN -e "install Crypt::SSLeay"

Rails 2 and broken render_text

February 24, 2008

Looks like that in Rails 2, in addition to changing the default database, default sessions store, now some of the oldies such as render_text method no longer work as expected. If you’ve used render_text "some text" in a controller, then you’ll need to replace it with render :text => "some text".

Rails 2 and broken sessions

February 24, 2008

My hosting company ( updates their system software now and then without any e-mail notifications to their users. Unfortunately, if you host a Ruby on Rails application (in my case each time they upgrade Ruby on Rails, there is a good chance that something will break. Recently, they upgraded to the latest version of Rails (2.0.2) and needless to say, my Rails application stopped working. It turns out that the latest version of Rails has changed the default sessions store from a file store to a cookie store. The problem is that if you stored anything other than a simple data in your session, then to get your application to work, you have to spend a few days porting your application. The fact that Rails upgrade is not backwardly compatible is really annoying. But that is a separate issue.

So what is the easiest way to port your file backed sessions application to Rails 2? The answer is to use the database for your sessions. But keep in mind that Rails 2 no longer uses MySQL as its default database. Here is how I ported my application to Rails 2.0.2:

  1. Create a brand new rails application using the command rails -d mysql appname
  2. Edit environment.rb file and explicity state that you wish to use database for sessions: simply uncomment this line:
    config.action_controller.session_store = :active_record_store.
  3. Use the command rake db:sessions:create to create the database definition for the sessions.
  4. Use the command rake db:migrate to actually create the database tables (I’m assuming that you have updated the database.yml with correct user name and password and have create the database in MySQL). The rake command will then create the sessions database table.
  5. Copy your controllers, models, views, … from the your current Rails application to this one.
  6. You should be good to go!

How to install MySQL on fedora

January 21, 2008

  1. Use yum to install both mysql command line tool and the server:yum -y install mysql mysql-server
  2. Enable the MySQL service:/sbin/chkconfig mysqld on
  3. Start the MySQL server:/sbin/service mysqld start
  4. Set the MySQL root password:mysqladmin -u root password 'new-password'The quotes around the new password are required.

How to tail log file on a SSH site

January 14, 2008

Quite often I need to tail a server log file on a site that I need to login to using SSH. The task of opening a terminal, creating a SSH session, login, and then tail does get tedious. So here comes ssh with the -t option. Here is an example, where you CD to the appropriate folder and then tail the log:

ssh -t 'cd /var/log/tomcat/myserver; tail -f catalina.out; $SHELL -i'

How to add a Flex control to Google Maps

November 27, 2007

Overlay Flex ControlYou can add a Flex control to a Google Map by taking advantage of DHTML DIVs and z-order tags. Here I’ve defined a Flex control to display the elevation chart associated with a route. In Flex, I specify the opacity of to be 0.5, this means that the chart will be partially transparent. The z-order of the Flex div ought to be higher than the z-order of the Google Map DIV.

Here are a few example of the Flex elevation chart control in action: Sheldon Road Trail, Kennedy/Shannon Trail, Pebble Beach bike route, & Los Gatos to San Jose bike route.

Adding the power of Flex to Google Map gives you to option of selecting the best tools for designing a rich user experience.