Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.


Perl Source Compressor for JavaScript

I created this script in the middle of the last project - Blogger Post Calendar. I wanted to speed up the loading of the external javascript file - so I created a script that would automatically compress javascript code. And perl was the obvious choice as its language.

The code can be downloaded from the JavaScript Source Compressor page.


  • Removes Comments - both //... and /* ... */ style comments.
  • Removes Whitespaces - newlines, spaces and tabs.
  • Replaces all varable names with a shorter version(a,b,...,z,aa,ab,...). This feature is optional

perl --help

SourceCompressor is a perl script that can be used to compress the Javascript source file to a much smaller file. Replaces large variable names with smaller, generic names and removes unwanted white spaces.


perl <js_file.js> [options]
Example :
perl settings.js -display -verbose -change-name

Command Line Options

The first argument MUST be the file name of the JavaScript file.
-verbose           Show details of what is going on.
-readable          Use \\n instead of ';' as the command seperator.
-change-name  Rename the variables to a shorter version. Enabled by default.
-remove-vars   Remove the 'var' keyword - this is asking for trouble.
-print                 Outputs the compressed data instead of writing it to a file.

To Do

  • BUG: Changes the text if the variable name appears in the coments/strings/other places.
  • The variables appearing more times must have shorter number of chars.
  • Change the variables that don't use the 'var' decleration method. - Is this possible?
  • Implement Unremoveable comments - needed for copyright statements.
  • Change the names of the functions/classes too?

Similar Projects


The day I got Hanged

Yes, I know that the title is grammatically wrong - I have used those words on purpose. If I was a spirit blogging from beyond the grave about my death day brought about by the noose, I would have used the title 'The day I was Hung'. But as you are probably aware, I am not a spirit blogging from beyond the grave. But today I got close to that description.

Today we had another bus strike. Barely two week after from the last bus strike, we have another bus strike. And as it happened in the last strike, the enterprising vehicle owners got their show on the road - sorry about the pun. As luck would have it, I did not see any of these vehicles - when I waited for the bus, all the vehicles I saw were overflowing with humanity. After waiting for a long time, I lost my patience and boarded a already full jeep. Now you are probably wondering - how do you board a vehicle that is already filled. The answer is - you can't - no sane person would even try. But I would - not because I am insane - but because that is the only way I could get to work.

So what I did was get on the back of the jeep. As it was already full, I could not get inside. I had to stand on a small bit of metal that is (normally) used as the step while getting off the jeep. Then I hung on to the railing on the top of the jeep. Now I know that this is a little hard to imagine if you have never seen it done. Let me assure you - it ain't fun.

So this is the day I got Hanged - with a capital H. A small slip and it would be the end of the road for me(again, sorry about the pun). I would become road kill in less than half a microsecond.

So the easy part is over - I got on the jeep. Now the hard part. If you think that standing on a bit of metal a quarter of a meter wide, hanging on for dear life on a moving vehicle is not difficult enough, add four more people to this equation. Other people who also want to get to their work as desperately as I do also got on the jeep. Now there is five people standing on a bit of metal a quarter of a meter wide hanging on for dear life. After five minutes of this, your hands start to ache. After ten minutes, you start to feel extreme pain in all your extremities.

To cut a long story of misery and suffering short, I got to the office sure that my fingers will never type again. But the pain started to fade after some time - as the existence of this blog post will testify.

Now here I am, gratefully typing away at the keyboard hoping that I would not see another day like that again - knowing well that it is an empty hope. More Bus Strikes are on their way - and with that more suffering for us.

Let me finish with the words I use to finish the post about the last bus strike...

If you think that this is bad, let me assure you that you 'ain't seen nothing yet'. There is an even worse time - hartals. But more about that when one comes and I have the time to blog it.


Calendar Navigation System for Blogger

Serious bloggers will tell you that calendar navigation is pretty useless as a form of navigation. But I still wanted to have that option available to me. And since blogger did not have it, I decided to create one myself.

The result of the system is shown at the top right corner of this blog - not a great script, but serves it perpose well. I created this script - not as a navigation aid but as a way of forcing myself to write more blog entries. This calender only shows the blog of the current month - and no one would like to see a post free month - especally not me. It is my firm belief that this visual aid would force me to increase my post freqency. If not atleast it is a 'customisable visual navigation aid'.

As always the script is open and under the BSD license - you are free to edit it, use it, give it to others and so on. I would be extreamly grateful if you link to my site from your page - but that is an option - not a rule.

The code is given below - copy it and save it to a file.

Script  : Post Calendar
Version : 1.00.A Beta
Author  : Binny V A
E-Mail  : binnyva (at.) hotmail (dot.) com
Website :
This will implement a calendar navigation for your blogs. The
     blogs made with WordPress, LiveJournal, MoveableType etc
     already has this feature - but not the Blogger. So I made
     this script to be used with Blogger.

var  month_names = new Array("January","February","March","April","May","June","July","Augest","September","October","November","December");
var month_days  = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var marked_days = new Array();
var data = "";
var post_index = 0;

//Get today's date - year, month, day and date
var today = new Date();
var year = today.getYear();
year = (year > 2000) ? year : year + 1900;
var date = today.getDate();
var month = today.getMonth();
var day = today.getDay();

//date_string must be in the format of - YYYY-MM-DD or just the date.
function addPost(date_string,link,desc) {
  if(isNaN(date_string)) {
      var day_parts = date_string.split(/\b/);
  } else { //If only the date_string is given, it is valid
      var day_parts = new Array(year,"",(month+1),"",date_string);
  if(day_parts[0] == year && day_parts[2] == (month+1)) {    //Make sure that only the posts of this month will get in -
      marked_days[post_index] = new Post(day_parts[4],link,desc);

function Post(day,link,desc) { = Number(day);
  this.text = "<a class='post-link' href='"+link+"' title='"+desc+"'>"+Number(day)+"</a>";

function wrt(txt) {
  data += txt;

function makeCalendar() {
//Display the table
wrt("<table class='calendar-nav'>");
wrt("<tr><th colspan='7'>"+month_names[month]+" "+year+"</th></tr>");
wrt("<tr class='header'><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>");

//Get the first day of this month
var first_day = today;
var start_day = first_day.getDay();

var d = 1;
var flag = 0;
var w = "";
//Create the calender
for(var i=0;i<=5;i++) {
  for(var j=0;j<7;j++) {
      if(d > month_days[month]) flag=0;//If the days has overshooted the number of days in this month, stop writing
      else if(j>=start_day &&amp;amp; !flag) flag=1;//If the first day of this month has come, start the date writing

      wrt("<td class='days'>");
      if(flag) {
          w = d;

          //See if there is any posts on that day
          for(var k=0;k<marked_days.length;k++) {
              if(marked_days[k].day == d) { //There is a post
                  w = marked_days[k].text;

document.getElementById("calendar-navigation").innerHTML = data;
window.onload = makeCalendar;

//All posts
//Add your posts data here - in the format
addPost("2005-08-09","","And now in Firefox - XML parsing.");
addPost("2005-08-10","","Bus Strike in Kerala");
addPost("2005-08-13","","Finished 'The DaVinci Code'");

Then upload your script to any site - I hope that you got a site to which you can upload this script - if not, I am extreamly sorry - it basically kills the idea.

Then add this line to your blog template in the <head> section.

<script language="javascript" type="text/javascript" src="http://URL-TO-THE-SCRIPT.js"></script>
Then add the below line in the template where you want the calendar to appear.
<div id="calendar-navigation"></div>
The appearence can be altered using the CSS section in your template.

Now here is the hard part. When ever you make a new post, you must one line at the end of the external Javascript file - like this...

addPost("2005-08-23","","Calendar Navigation System for Blogger");

I am sorry that it is not a very user friendly to install - I created this for my own use. If a lot of people want to use it, I could make a small system to automate the post adding and script hosting.

Some points before I leave...

This script if for people who know JavaScript - if you don't know javascript, it would be better to give it a pass for now. Another thing is that the script is in Beta - so expect bugs if you are going to use it. The last thing is that this script will show only the post of this month - so only the most recent posts will be shown.

Hope you like it.

UPDATE: I have removed the calender when I redesigned this site. So, in this post, I have included a sample of how it will appear...


Finished 'The DaVinci Code'

Just finished reading the book 'The DaVinci Code' by Dan Brown. A very good book - I read the whole book in a single sitting - just could not put it down. A good read - even though the underlying theories are quite hollow and far-fetched.

Traditionally I am very much against conspiracy theories - yes, man did land on the moon - and no, the government is not covering up alien landings. And this theory is just like any other conspiracy to me. I generally don't argue with people who want to believe in a particular conspiracy - but let me just make a few points.

The secrets hidden in Leonardo da Vinci's works


Many 'secrets' were not actually there - they were the results of imaginative minds. A good example for this is 42. Don't know what 42 is? Shame on you! 42 is the ultimate inside joke of this generation. Douglas Adams introduced 42 in his book 'Hitch-hiker's guide to the Galaxy'. In this book a computer was asked to find the answer to life, the universe and everything. After a million year of processing by the computer it gave out the answer - 42. Most of the readers of this book thought there was a reason why the author chose the number 42 - there are a lot of theories floating around on the net about this. Some are very convincing. But Douglas Adams himself said that he had chosen a random number - no special meanings for it. The point of this story is that if a person is looking for something believing that there is something there, he will find something even if there is nothing there in the first place.

Even if there are secrets in the works of da Vinci, it don't mean anything. We all like to include small secrets in our works - some call it secrets, other call it inside jokes and we programmers call it easter eggs. I have encoded a lot of secrets into my site's logo...

To get a detailed explanation of them, click here.

That said, let me say that I believe in a theory that some might consider to be a conspiracy theory - Creationism or Intelligent Design as it is known now. But as far as I am concerned, this is not conspiracy theory - but rather an alternative scientific theory. Conspiracy theory involves secrets, government cover ups, murders and what not - non of these are are a part of the Intelligent Design theory. But still some think of it as a conspiracy theory. I have no idea why that is so.

About the book - this is a very good book. I found the authors style of jumping around a bit distracting. For example, this main character is taking about an idea of his and suddenly the book goes into a flash back to the incident when the character got that idea. Stream of consciousness, I believe it is called. I found this to be a little distracting - but others may not think so.

The only thing I really disliked about the book was the author's method of misleading the reader. Misleading is an art perfected by Agatha Christie. Her methods were very subtle and undetectable. But Dan Brown was nothing of that sort. What he did was take some conversations out of context and presented it in another context - thereby giving the reader a wrong impression. I think this will qualify as an instance of the author 'cheating the reader'.

But all in all, it is a good read.


Bus Strike in Kerala

Today there was an all out bus strike through out Kerala. A small description of the term 'Bus Strike' - for those who are not in Kerala. The people here are very dependent on the public transport system we have - that is buses. If the owners of these buses have to make a demand to the Govt., bus strikes are their weapon of choice. Basically they just prevent the buses from running. The public who depends on these buses to get to their workplace/home/wherever are stuck. This simple method has been used time and again to bring this land to a virtual standstill.

Our only hope in such situations are some enterprising vehicle owners - when ever there is a strike, these people will go from one point to another in their vans/jeeps - letting in the stranded public - and taking an inflated amount as the ticket charge.

Due to the small amount of such vehicles(or parallel transport, as we call them) and the large number of people depending on them, these vehicles will be packed beyond belief. Such situations are so common here that they have evolved into a metaphor...

The canned sardines were packed as tight as people in a van at the time of a bus strike.

I kid not.

If you think that this is bad, let me assure you that you 'ain't seen nothing yet'. There is an even worse time - hartals. But more about that when one comes and I have the time to blog it.


And now in Firefox - XML parsing.

So far I have created two apps that will parse a given XML file in javascript - Binny's Software DataBase and JASFER. Both these programs had the same crippling problem - neither worked in Firefox. The work very well in IE - but in firefox, they have this burning desire to crash and burn.

But not anymore - now both are working in both IE and Firefox. I don't know about the other browsers - but generally, if any page works on the above two browsers it passes my minimum requirements.

Some links that helped me solve the problem...

XML DOM parser Javascript RSS reader

The problem was that I was using absolute item reference - like this...

nodes = data.documentElement.childNodes.item(0).childNodes
alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes.item(0).nodeName
  + "\nFirst Item Value : " + nodes.item(0).childNodes[0].text);
What I should have used is the getElementsByTagName() function - like this...
nodes = xmlDoc.getElementsByTagName("item"); //Get all the 'item's
alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes[0].firstChild.nodeName
  + "\nFirst Item Value : " + nodes[0].firstChild.nodeValue);

I have created a small cross browser framework for loading XML file while creating these softwares. The code is given below. If you have any use for it, feel free to use it - release in GPL licence.

////////////////////////////// XML File Loading ///////////////////////////////
//Firefox only function - happens when a XML file is loaded
function loadHandler () {
  xmlProcessor(this); //Call the Commen function with 'this' data.

//Load the xml file - using different method for different browsers
function xmlLoad(xml_file) {
  feed_id = 0;
  feed_total = 0;

  var xmlDocument = "";
  feed_file = xml_file;
  if(document.implementation.createDocument) {//Firefox
      xmlDocument = document.implementation.createDocument('', '', null);
 //This function will happen when the file is loaded
 xmlDocument.addEventListener('load', loadHandler, false);
  else { //IE
      var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
      xmlDocument.async = false;
      var loadResult = xmlDocument.load(xml_file);
      if (loadResult) {
          // process xml document with DOM methods e.g.
      } else {
          return false;
  return true;

function xmlError() {
  alert("Some error has occurred!")

//Process the xml data
function xmlProcessor(xmlDoc) {
  if(!xmlDoc) {

  //Do whatever you want with the XML data...
  nodes = xmlDoc.getElementsByTagName("item"); //Get all the 'item's
  alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes[0].firstChild.nodeName
  + "\nFirst Item Value : " + nodes[0].firstChild.nodeValue);


xmlLoad("file.xml"); // Load the XML file.

Subscribe to : Posts