Jquery Image Preload

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery.preLoadImages("image1.gif", "/path/to/image2.png");

source : http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript

How to SWAP values of two variables without using a third variable?

1. Arithmetic operation
2. Bitwise operation.

Arithmetic Operation:

Bitwise operation:
x = x XOR y
y = x XOR y
x = x XOR y
if we write them in computer language using caret (^) then it will look like

x = x ^ y
y = x ^ y
x = x ^ y

in shorter version:

x ^= y
y ^= x
x ^= y

in one line

x ^= y ^= x ^= y

so here is the command in php:

$x ^= $y ^= $x ^= $y

This is collected from http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable. You can get more details about these operation on his blog.

parseUri 1.2: Split URLs in JavaScript

This code was originally posted by Steve in ‘http://blog.stevenlevithan.com/archives/parseuri’. I just copied from his blog. You can get details about this function to above url. This is very efficient and useful function for url parsing.

// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

Javascript manipulate contents by class name like ID

Most of us use ID to access or manipulate html DOM, But it can be done with class name which is little bit tricky. I have done it on one of my firefox plugin project.


var target_class = document.getElementsByClassName("div_content")[0];// Search the class
clearChildNodes(target_class);//Remove Child nodes of the class

var div1 = document.createElement("div");//create a new element
div1.setAttribute('class', 'child_div1');// Add class name to the newly created element

target_class .appendChild(div1);// Append the new element to the target div


function clearChildNodes(node) {
    if (node.childNodes.length &gt; 0) {
        while(node.hasChildNodes()) {
            node.removeChild(node.firstChild);
        }
    }
    return node;
}

Money Format(us currency)

    
formatCurrency:function (num) {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
            if(cents==00) return (((sign)?'':'-') + num );
            else
            return (((sign)?'':'-') + num + '.' + cents);
    }
 

How to edit windows hosts file(C:\Windows\System32\drivers\etc\hosts)

  1. Click Start
     Start button click All Programs, click Accessories, right-click Notepad, and then click Run as administrator.
     User Account Control permission If you are prompted for an administrator password or for a confirmation, type the password, or click Allow or Yes.
  2. Open the Hosts file or the Lmhosts file, make the necessary changes, and then click Save on the Edit menu. If using Windows 7, you will need to click Save on the File menu.

mysqldump —Database Backup Program

Windows command promt:

To go a drive, just need to write the drive name such as > D:
To access directory D:\>cd directory_name such as  D:\>cd test_directory
To access file D:\>cd directory_name\file_name such as D:\>cd test_directory\test.php

To access upper directory [D:\users\devel2\test>cd..] the output will be  [D:\users\devel2>]

To dump mysql db table: F:\xampp\mysql\bin\mysqldump -h localhost -u root -p dxlogin users > users.sql

F =  is the drive name where xampp is installed,
-h localhost = mysql host name
-u root = mysql user name
-p = mysql password
dxlogin = database name
users = table name
users.sql = the sql file that will be dumpped.

reference site url for mysql dump http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html