Archive

Archive for the ‘Open Source’ Category

about:config trick for window.close() In Firefox

July 7th, 2010 kumarasamy No comments
This article is from my exp. on turning on the configuration in FF after each release.The script window.close() won’t work after every release from mozilla. The reason i found was “dom.allow_scripts_to_close_windows” in all.js will be set to false by default. I was trying to do it in the hard way,i.e Go to the location of all.js and change it manually. But i found a another easy method we can call the about:config page in FireFox, we can toggle it easier. The following shows how to do it.
Enter about:config in location bar
Openingabtcnfg
Shows all the options available
options
Search for dom.allow_script
allow_scripts
Highlight the entry dom.allow_scripts_to_close_windows and double click to toggle to true
Then write a simple script to check window.close()
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Categories: General, Open Source Tags: , ,

Simple File Upload Script in PHP

June 30th, 2010 kumarasamy No comments
Here goes my file upload component in PHP. It just uploads the file into the specified directory.Other thing i have added as of now is it’ll upload the files into the folder on the current month and checks for the file exists already or not, if it already exists then it’ll prefix the time in milliseconds in the file name.
	<?php

		/*
		*		Copyright 2010 - Kumarasamy
		*		kumarasamy@techmaddy.com
		*/

		class DocumentHandler {

			var $uploadDir;// Directory where the documents to be uploaded

			function prepateForUpload() {
				$this->uploadDir = '/var/www/uploads';
				$this->uploadDir = $this->uploadDir . "/" . date("Y_m");

				//Check the month folder is available, if not then create it.
				if(!is_dir($this->uploadDir))
					mkdir($this->uploadDir);

			} //End of setDetails

			function copyFile($_FILES,$fileCntrlName) {
				$resultArray = array();
				$uploadfile = $this->uploadDir . "/" . basename($_FILES[$fileCntrlName]['name']);

				//If the file exists already in the folder, append the millisecond in the file name.
				if(is_file($uploadfile)) {
					list($msec, $sec) = explode(".", microtime(true));
					$uploadfile = $this->uploadDir . "/" . $msec . $sec . basename($_FILES[$fileCntrlName]['name']);
				}

				if (move_uploaded_file($_FILES[$fileCntrlName]['tmp_name'], $uploadfile)) {
					$resultArray['error'] = '';
					$resultArray['displayMessage'] = 'File Uploaded Successfully!!!';
				}

				return $resultArray;
			} //End of copyFile

		} //End of DocumentHandler
	?>
	
The following things can be added,

  • Check for the file type
  • Check for the file Size
  • Scan the document using the shell commands
  • Check for the special chars in the file name
  • File name length check also can be added
Idea’s are accepted!!!
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Logging in J2EE Applications

June 1st, 2010 kumarasamy No comments
Logging is the one of the most important quality a software developer should have as a practice while coding for their applications. Logging serves as many purpose from debugging the application when a developer encounters an issue, trouble shooting the users issue, when it’s in production mode and can be used to fine tune our application with some performance measures. So logging becomes so important in a Web Application. So what are the ways we can add logging to our application which is developed in J2EE platform, there are many ways to do, they are,
  • Using Logging Framework - Log4J, SL4J, Java Logging API and Apache Commons Logging. These logging framework provides lots of functionality built-in. These frameworks defines three different processors for logging. They are Loggers, Formaters and Appenders. And these frameworks provides many levels for logging also. These frameworks provides many means of organizing your logs like Storing into Files, Database tables and some times these framework will help us in sending the email alerts also. There are many open source loggers can be found here.
  • Custom Developed Loggers - This mayn’t be complete logging solution. Sometimes we may need to code our own way of logging, this depends on our requirement to log. For example We may wanted to just to record only the user actions in all of the screens in an application and the admin needs the screen to see all the action done by that particular user with some more criteria like date etc… This time instead me adding one more framework and cluttering the application configuration, we can simply make use of the existing JDBC connection and store all the actions on the same database where we do store our application data. The other scenario i can think off here is, say for example i’m planning to log many details from each and every request of the user, in this case logging becomes heavier to maintain for the containers, this time we can try use our own loggers with pooling of objects on the user basis.
What are the things should be logged?
There are some categories of information which always has to be logged, they are Error(s) and Exception(s). Apart from these login and logout information, SQL queries and their execution times, parameters if we have any for prepared statement(including Stored Procedures), if we have any interfacing application then the request and response information, basically all the domain objects(internal data structures in the application), each and every user actions like button clicks, session time out for the user session also can be logged for better troubleshooting and debugging purposes. But it’s completely developers duty that they log the IP Address for the Client, Browser Agent, TimeStamp and the user id/information are getting captured in the log information this will make a real big impact on the debugging for web applications.
In my previous experience i have come across some logging mechanisms where they’ve used their own logging tools(basically this made me to write about the custom logging frameworks). Little more details about it.
Using JDBC with DB tables - The basic idea here is have a dB table for user history, store the important actions from the user(s) like button clicks, important queries. But we have to make sure that we are making use of the connection pool, otherwise this becomes costly inside our application and the number of connections shoots up always. The advantage of this approach is easy way of accessing the logs, i.e. a screen inside the same application show this log. Admin of the application can look into these details and can identify few issues of the users. The user’s action sequence can be identified easily. The major drawbacks of this approach is when there is an huge data available as history, then the admin page loading time will become more, the only option to have an archive mechanism to solve this issue.
Using File System -  This approach is like Log4j where we’ll make use of files to write our logs and this can be rotated on daily basis. And this can be divided further more saying the application logs and the DB logs can be separated into two different files. And further more this can be used for each and every module in the application can have two files like application log and database logs. But this approach can be used to log each and every action/request from the user with data. And the naming convention can be on the unique user id. Each user session contains the pool of these objects so that the number of I/O operations are not exceeding the limits. This would be very good approach in logging for a web application since each and every request for the server will be logged for that particular user.
The final important thing here is, what ever the method we follow to log the details we should be able to troubleshoot/debug the applications easily/fastly, even it’s going to be in production. The logging is an very important factor that we should be considering when we think of designing/developing an web application.
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Get Adobe Flash playerPlugin by wpburn.com wordpress themes