Site Moved

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


IGNOU Assigments Over

I have finally finished the assignments of this semester for collage. I had time for very little other than that for the last week - now that it is over, I got some time to do other stuff. And two holidays are coming up the next week - I finally have some free time finish up some work that I want to do for some time now.

I had to code some C++ and Java programs for the assignments. Coding in C++ after such long time sure brought some memories - I have not touched C++ for some time now. The only problems I noticed was that I could not write a function declaration properly - I was always going void getValue(sting1,string2) instead of void getValue(char string1[],char string2[]). I guess too much scripting languages can do that to a man.

Filed Under... Categories : Technorati Tags:

Calendar In Java

Just finished coding a Calender in Java. Yes, you heard me right - in Java - not in JavaScript. This was an assignment for my BCA course in IGNOU. I just ripped the code from my JavaScript Calendar program. That was JavaScript, this is Java - some small changes here and there, and vola - Calendar ready. The code is given below - feel free to rip it if you find any use for it.

Program : Calendar
Version : 1.00.A
Displays a calender for a specified month - recives the month and year from the 
command line.
import java.util.Date;

public class Calendar {
 public static void main(String[] Args) {
  int year = Integer.parseInt(Args[0]);
  int month= Integer.parseInt(Args[1]) - 1;
  String month_names[] = {"January","February","March","April","May","June","July","Augest","September","October","November","December"};
  int month_days[]  = {31,28,31,30,31,30,31,31,30,31,30,31};

  //Get today's date - year, month, day and date
  Date today = new Date();

  //Display the table
  System.out.println(month_names[month] + " " + year);
  System.out.println("|| Su || Mo || Tu || We || Th || Fr || Sa ||");
  //Get the first day of this month
  Date first_day = today;
  int start_day = first_day.getDay();
  int d = 1;
  boolean flag = false;

  //Create the calender
  for(int i=0;i<=5;i++) {
   for(int j=0;j<7;j++) {
    if(d > month_days[month]) flag=false;//If the days has overshooted the number of days in this month, stop writing
    else if(j>=start_day && !flag) flag=true;//If the first day of this month has come, start the date writing
    System.out.print("| ");
    if(flag) {
     if(d<10) System.out.print("0");
     System.out.print(d + " ");
    } else {
     System.out.print("   ");

If you know how I can improve the above script, please let me know. I don't know much about java. I never liked Java - the only program that I made in Java was the Enigma Machine encryption algorithm - after doing that, I hated java so much that I never used it again.

Technorati Tags: Tags :

Optimizing JavaScript for Speed

One of the most often heard complaints about javascript is that it is very slow. The arrival of very complex but extremely cool web programming methods like ajax, javascript has become a sharp weapon in a web developers tool box - but the extreme amount of processing required for ajax and the slow execution of javascript has dulled this tool very much. I have seen computers crash when gmail is opened in the browser - lower end computers just cannot handle that much processing. But still javascript cannot be ignored - this is where javascript optimization comes in.

Andy King have written an excellent article on Optimizing JavaScript For Execution Speed. I would highly recommend it if you are serious about javascript programming.

From the article...
Unlike other programming languages, JavaScript manipulates web pages through a relatively sluggish API, the DOM. Interacting with the DOM is almost always more expensive than straight computations. After choosing the right algorithm and data structure and refactoring, your next consideration should be minimizing DOM interaction and I/O operations.
There are other articles on this subject, but I like this one the best.
Technorati Tags: Tags :

Alertbox's article on Blog Usability

Jakob Nielsen, the author of Alertbox has publish an article about the usability of Blogs. This contains some solid advice on how to make your blog much more 'visitor-friendly'.

I have one point of disagreement with him - Calendar navigation. Even though I agree that it should not be the only mode of navigation, I will not say that it is useless. If I visit a new blog and is thinking about subscribing its RSS feed, I take a look at the calendar before doing so. If a lot of days have posts in them, the blog is an active one. This is the reason why I created my own calender even though blogger did not give that option. Read the article...
Technorati Tags: Tags :

Dump() Function - Javascript equivalent of PHP's print_r()

The moment I saw the print_r() function of PHP, I fell in love with it. It is a very necessary function and I cant understand why no other language supports it. Perl does - if you are using the Data::Dumper module. I have created a function in PHP that will call print_r() function. It will put the code generated by the print_r function inside <pre> tags. That will make the data readable from the browser.

Latest Version of Dump() Function - Javascript equivalent of PHP's print_r() available at OpenJS

/** Function : dump()
* Arguments  : $data - the variable that must be displayed
* Version    : 1.01.B
* Author     : Binny V A(binnyva (at) hotmail (dot) com :
* Date       : June 3, 2005
* Last Update: Wednesday, July 13 2005
* Prints a array, an object or a scalar variable in an easy to view format.
function dump($data) {
if(is_array($data)) { //If the given variable is an array, print using the print_r function.
 print "<pre>-----------------------\n";
 print "-----------------------</pre>";
} elseif (is_object($data)) {
 print "<pre>==========================\n";
 print "===========================</pre>";
else {
 print "=========&gt; ";
 print " <=========";
I have ported the print_r function to javascript - hope that you will find this useful.
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
return dumped_text;
This is how the function is called. In this example we will give a complex array as the argument.
//Calling the function...
function init() {
var arra = new Array("Hloo",'s',23,23.1,"Hello World");
var assoc = {
 "val"  : "New",
 "number" : 14,
 "theting" : arra

The result will be shown in the following format.
'val' => "New"
'number' => "14"
'theting' ...
   '0' => "Hloo"
   '1' => "s"
   '2' => "23"
   '3' => "23.1"
   '4' => "Hello World"
Technorati Tags: Tags :

PHP Security

A few days ago I read an article on PHP Security on I could not even begin to stress the importance of the concepts said there. Some of the major points said there are...

Don't give any files the extension '.inc'.

Some people will give the files that are included this extension - as in...
include('./');//Connect to the database.
and include this line in every file of the page. The programmer must use the username amd password of the database connection in this file. The problem is that if any user will type the direct address to file in the browser, he can see the username and password. Like this - But if the extension is '.php' this big security threat can avoided - as the server will parse the file before showing it. If you make a small search in google to find how many people are affected by this, you will be surprised - as I was.

SQL Injection

Please do a 'addslashes()' on the data comming from the user. If you ignore this you will be vulnurable to a hack attempt called SQL Injection. This happens when the visitor inputs a SQL query as the form data and you code executes it.

For example, consider the authentication code

mysql_query("SELECT * FROM table WHERE username='$_REQUEST[user]' AND password='$_REQUEST[pass]'");
Any person can run an sql query on this code. Just input the following as the username...
' OR 1=1;#
This will cause the query to by
mysql_query("SELECT * FROM table WHERE username='' OR 1=1;#' AND password=''");
See what happens? The query gets executed! Now if this a malacious guy, he will not stop there. He will try something like...
'; DROP * FROM table;#

Many more...

There are a lot more things to watch out for - read the article to know more about them. It is a three part article and read atleast the first two sections. I would recommend that you read all three sections - if you are really serious about PHP programming.


A point that the author has missed is the threat by the phpInfo() function. I often make a file with this funtion at the begining of the project to see the server info. Some time I neglect to delete this file. I don't have to say what kind of damage a hacker can do with the kind of data given in the phpInfo() function. So, if you make a phpInfo() file, please don't forget to delete it.

SciTE - A Simple Yet Powerful Editor

I just discovered this small but very cool text editor. It came with the installation of Ruby. At first I only used it for editing ruby scripts. But latter I noticed that it had a lot of advanced features like auto-completion and code folding - stuff I really need.

Currently I am using Crimson Editor and Kwrite as my primary text editor. Crimson Editor I use at home - where I am stuck with windows. At work I use Kwrite in a Fedora Core 3 Linux system. Kwrite has the auto-completion feature. And I have got addicted to it. The sad thing is that Crimson Editor don't support this feature - yet. So I am planning to make it my primary text editor. Another good thing about it is that SciTE is supported on both Windows and Linux - so I can use the same editor at work and at home.

SciTE is a very small and simple editor configurable through text files. It have a very small memory footprint - making it blazing fast even on my very slow system. The only minus point I have noticed is that the syntax highlighting is not very easy to change. Kwrite is a much better editor there. But then again, I have just started using SciTE - a few more months down the road I may discover that it is very easy to edit the syntax highlighting.

OK. Enough taking. For those interested in learning more about SciTE... SciTE Documentation Screenshots And last but not the least SciTE Download Page
Technorati Tags: Tags :

XUL-ing Around

I am trying to study XUL. For those who are not familiar with XUL, or (XML User-interface Language is a cross-platform language for describing user interfaces of applications. Currently it is used for creating extensions for Firefox and Mozilla browsers.

The GUI is created in a language similar to HTML and the coding is done in JavaScript. So learning it was very easy for me. The only problem is the file organization and some other complex operations. Nothing to worry about - I will get the hang of it after I code two or three extensions.

I am making a small extension as a training exercise. It is not over yet but will be over any time now - will let you know once a download able version is complete.

For those interested to know more, head over to


Subscribe to : Posts