Archive for October, 2007

Compress PHP Output from .htaccess

Compress all PHP output by adding this line to .htaccess file


php_value output_handler ob_gzhandler 

A Simple Logging Function for JavaScript

Prints all the arguments of the function. This function uses console.log if firebug is available - else, uses alert.


function p() {
                for(var i=0; i<<arguments.length; i++) {
			if(window.console) console.log(arguments[i]);
			else alert(arguments[i]);
		}
}

Chainable interface in JavaScript

Creating Chainable interfaces in javascript…


(function() {
	function _init() {
		return this;
	}

	_init.prototype = {
		"myFunction": function() {
			return this;
		}

		// Put all the functions here - make sure all 'return this;'
	}

	chainer = function() {
		return new _init();
	}
})();

Roll out your own JavaScript Interfaces

[tags][/tags]

Create a Permanent Alias in Fish Shell

This is how you create a permanent alias is fish


alias x='exit'
save_function x

Date Command

Create the MySQL format date(YYYY-MM-DD) using the date command


date +%Y-%m-%d

Some File Operation in SVN

Moving, Coping and Deletion


svn mv file.php to_folder/        #Move
svn cp file.php to_folder/         #Copy
svn rm file.php                          #Deletion

Using Ant to Concatenate files

The build.xml file to concatenate files using ant. This can be executed using the command ‘ant “ConcatAll”‘


<?xml version="1.0" encoding="UTF-8"?>
<project name = "MyProj" basedir = "." >

	<target name = "ConcatAll" >
		<concat destfile = "final.txt" fixlastline = "yes" >
			<filelist dir = "."
						files = "first_file.txt
								second_file.txt
								third_file.txt"/>
		</concat>
	</target>

</project>

Clears the yum cache

Clears the yum cache


yum clean all

Linux Command to get the Sensex

Another method to get the sensex. This method is more realiable in working - but the data might be a bit old. Data supplied by Yahoo Finances.


curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=%5EBSESN&f=sl1d1t1c1ohgv&e=.csv'| awk -F ',' '{print $2}'

Sensex Figure using a Linux Command

This one command will fetch and display the latest sensex figure in Linux. This command basically downloads a page, locates a specific line, and then extract just the necessary portion from it. I am sure you could find other uses for this method.


curl -s "http://money.rediff.com/money/jsp/markets_home.jsp" |grep ''|head -n1|perl -pe 's/^.+\">([\d\,\.]+)<\/TD>.+$/\1/i;'