Monday, October 31, 2011

Fix IE 5.5 and IE 6 PNG transparency problem

 This code not written by me. Thanks for unknown author.

<!--[if lt IE 7]>
<script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }   
}
window.attachEvent("onload", correctPNG);
</script>
<![endif]-->

Upgrading Ubuntu Using the Alternate CD/DVD (Offline Upgrade)

Download the alternate installation CD from http://releases.ubuntu.com/oneiric/
Burn the ISO to a CD and insert it into the CD-ROM drive.
If the ISO file is on the computer to be upgraded, you could avoid wasting a CD by mounting the ISO as a drive with a command like:

sudo mkdir -p /media/cdrom
sudo mount -o loop ~/Desktop/ubuntu-11.10-alternate-i386.iso /media/cdrom

A dialog will be displayed offering upgrade using that CD then follow the on-screen instructions.

If the upgrade dialog is not displayed, run the following command using Alt+F2:

gksu "sh /media/cdrom/cdromupgrade"

Or in Kubuntu

kdesudo "sh /media/cdrom/cdromupgrade"

Saturday, October 22, 2011

Jar file is over max size - Solved

The reason for this error is because the default value for a jar file in some phones are 400 or 500 KB. So when installation file is more than above size limit, you cann't install it.

To solve this:

  1. In your keypad, type this code: *#52828378#
  2. You will get the JAVA Test Menu after typing the above code, select the OTA Test menu and open it.
  3. Then you will see the value 400/500 in Maximum JAR size field, change the value to a number higher than 400/500, i.e. 2048.
  4. Save  and try to install jar files.

Monday, October 17, 2011

Install and Uninstall IPv6 in Windows

To install and uninstall IPv6:

Click Start > Run > cmd

At the command prompt, type "netsh int ipv6 install" and press the Enter.

Close the Command Prompt window.

To uninstall IPv6:

Click Start > Run > cmd

At the command prompt, type  "netsh int ipv6 uninstall" and press the Enter key on your keyboard.

Close the Command Prompt window and restart the computer.

or
  
Open Network Connections

Right-click local area connection, and then click Properties.

Click Microsoft TCP/IP version 6 , and then click Uninstall, click Yes.

Click Close to save changes to your network connection.

Sunday, October 16, 2011

Table row hover effect - CSS

CSS

table tbody tr:hover {
    background-color: #ffccbb;
    color: white;
}


Saturday, October 15, 2011

Get current file name - PHP

$currentPath = $_SERVER['PHP_SELF'];
$parts = explode('/', $currentPath);
$pagename = $parts[count($parts) - 1];

Get underlying sql query of a view - Oracle, MySQL and SQL Server

View name is `book_info`

Oracle
SELECT text FROM all_views WHERE view_name = '%book_info%';
MySQL
SHOW CREATE VIEW book_info;
SQL Server
SELECT View_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE Table_Name='book_info';

Join different tables based on field value - MySQL

Sometimes we need to join tables based on a field value of parent table. Here we have one parent table `tbluser` and two child table `tblstudent` and `tblstaff`. We need to join this and find full details of user. i don't interested to send two separate queries by checking field value of parent table first and then send second queries for fetch remaining details. I found a trick for achieve this using only one query.

select tu.username as username ,tu.user_email, tu.user_Type, ts.stud_adm_id as col1, tc.course_name as col2 from tbluser tu join
tblstudent ts on tu.username = ts.stud_id
join tblcourse tc on tc.Course_ID =ts.stud_course
union all
select tu.username as username ,tu.user_name as name, tu.user_Type,
tss.staff_id as col1, tj.job_title as col2 from tbluser tu join
tblstaff tss on tu.username = tss.staff_id
join tbljob tj on tj.job_ID =tss.staff_job

Friday, October 14, 2011

Ethernet cable Connection. Direct & Crossover.

Here explaining T-568B Standard. To establish a LAN,you need UTP (Unshielded Twisted Pair) ethernet cable of at least Category 5 (Cat 5). Cat 5 is required for basic 10/100 functionality, you will want Cat 5e for gigabit (1000BaseT). The total length of wire segments between a PC and a hub or between two PC's cannot exceed 100 Meters (100BASE-TX). A straight-thru cable has identical ends. A crossover cable has different ends. A crossover is used to connect two Ethernet devices without a hub or for connecting two hubs.Odd numbered pins are always striped, even numbered pins are always solid colored. A crossover has one end with the Orange set of wires switched with the Green set.

Straight-Through Ethernet Cable
















Crossover Ethernet Cable



Joining Three or More Tables - SQL

Normally join specification joins only two tables. We can use FROM clauses can contain multiple join specifications.

The tblbookauthor table is a good example of a situation in which joining more than two tables is needed. This SQL query finds the titles of all books title and the names of their authors:


SELECT tb.book_id,  tb.book_title, tb.Book_type, ta.Aut_Name FROM `tblbook` tb inner join `tblbookauthor` tba on tb.book_id = tba.book_id join `tblauthor` ta on tba.Aut_ID = ta.Aut_ID;

The middle table of the join `tblbookauthor` can be called the intermediate table, because tblbookauthor is an intermediate point of connection between the other tables involved in the join.

Tuesday, October 11, 2011

Two - way MySQL database replication

MySQL database server has a master-slave replication feature, which makes it possible to have a complete copy of a master database on a slave server. When the master server fail, you have a copy of database available immediately, so you can switch your applications to the slave-server while bringing back up the master server. One drawback of this master-slave replication is that it is a one-way backup. The slave server is a complete copy of the master server. All changes that are done on the master server are applied to the slave server, but changes to the slave database server aren't applied to the master server.

I found these two articles are best for two way replication

http://www.neocodesoftware.com/replication/
http://onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html

Monday, October 10, 2011

File upload using php

Create an Upload Html Form

<form action="uploadfile.php" method="post" enctype="multipart/form-data">
<label for="title">Title</label> <input id="title" name="title" type="text" size="50">
<label for="file">Filename:</label> <input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>

The enctype attribute of the 'form' tag specifies which content-type to use when submitting a form. "multipart/form-data" is used when a form requires binary data (the contents of a file), to be uploaded
The type="file" attribute of the 'input' tag specifies that the input should be processed as a file. there will be a browse-button near the input field.

Create PHP file 

<?php
if (($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 1048576))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] ;
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] ;
    echo "Type: " . $_FILES["file"]["type"] ;
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " KB";
    echo "Temporary file: " . $_FILES["file"]["tmp_name"] ;

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "File error.";
  }
?>



$_FILES array contain file information.

$_FILES["file"]["name"] - the name of the uploaded file
$_FILES["file"]["type"] - the type of the uploaded file
$_FILES["file"]["size"] - the size in bytes of the uploaded file
$_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server
$_FILES["file"]["error"] - the error code resulting from the file upload.

Saturday, October 8, 2011

Reset a form using javascript

In JavaScript there are two ways to reset the a form :

  • By using Reset button of HTML
          <input type="reset" value="Reset" />
  • By using reset() method of JavaScript      
  document.getElementById('formname').reset();

Setting the Background Image on JFrame.

This is a sample program to set background image on JFrame.

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class BgImage {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        try {
                frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("image.jpg")))));
        }
        catch (IOException e) {
                e.printStackTrace();
        }
        frame.pack();
        frame.setVisible(true);
    }

}

Create new user account from command line in windows 2000, windows XP and windows 7

Some times we want to add new users from command line instead of using the GUI. Windows provides net user command for this purpose.

To add a new user account to the local computer from command line:

net user username userpassword /ADD /DOMAIN

Few more Advanced uses of net use command. 

To specify user full name while creating the user account

net user username userpasswd /ADD /FULLNAME:"User_Fullname"

To specify that the user is allowed to change the password:

net user username userpasswd /ADD /PASSWORDCHG:Yes

Add a user to administrators group from command line.

net localgroup group_name username /add

To add a domain user to local users group from command line:

net localgroup users domainname\username /add

To delete a user

net user username /DELETE

or
net user username /DELETE /DOMAIN


Tuesday, October 4, 2011

Set custom 404 Error page in apache

The .htaccess file is what Apache web servers use to allow you to fine-tune your web server configurations at a directory level. Other types of web servers may handle the customization of 404 error pages differently.

The first thing you need to do is to add the following line to a file named ".htaccess" (note the preceding period). In most instances, no such file will exist, and you can simply create one with a text editor.

ErrorDocument 404 /errorpage.html

You will need to put a "errorpage.html" file in the main web directory for the above directive to work.

The "ErrorDocument 404" directive essentially tells the Apache web server that whenever it cannot find the file it needs in that directory and its subdirectories, it is to use the document specified in the URL that follows if you want a certain subdirectory to show a different 404 Error message, you can always put a different ".htaccess" file into that directory. This will override any ".htaccess" files you have in the parent directories..



Monday, October 3, 2011

Finding the MAC Address of Remote Computer

Every device on a TCP/IP network has a unique number assigned to it called the MAC address. The MAC address is used by the network hardware such as routers, switches etc. to send data from one device to another.

System uses a service called ARP (Address Resolution Protocol) to resolve and track the TCP/IP and MAC address of the remote devices that you are communicating.


To determine the MAC address of a remote device:
  • Open the command prompt
  • Ping a remote machine that you want to find the MAC address (for eg: ping 192.168.0.1).
  • Type arp -a, and press Enter.

Sample result is given below:
 
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Computer>arp -a

Interface: 192.168.0.149 --- 0x2
  Internet Address      Physical Address      Type
  192.168.0.1           00-14-2a-70-a5-d2     dynamic

Sunday, October 2, 2011

Solution to AJAX Cache problem with IE


Few days ago, I was working on a project where in a webpage one field was getting populated through AJAX.

To my surprise, the response from the server that I was getting was not the one that I expected. Page doesn't display new data. Then i searched the problem on internet and came to know that Internet Explorer (IE) caches the AJAX request. So if I make ajax queries with same URL, it tends to give me same old output as IE caches the data that it gets from previous query.

To solve  this problem,  I appended a counter or random number with my url. it worked.

.
.
var count =Math.random();
 if (httpObject != null)
{
 httpObject.open("GET", "getinfo.php?request=" + request + "&val=" + val + "&count=" + count++, true);
 httpObject.send(null);
.
.
.



Saturday, October 1, 2011

Check website in different resolution

Sometimes we need to check how our website looks in different resolution. But we don't have any high resoltion monitor or display cards. then visit http://www.screen-resolution.com/
this will help you in checking website in different resolution.

Create file list from folder using java

This source code shall help you to generate list of files (including sub folder) in a folder.
Source code can download using following link.

Convert number to words in excel.

I sharing a simple solution to convert number to words in excel.

For this download the zip file from following link and extract it After this you will get a file with name  'module'.

Next step: open excel and press alt + F11. now you will get a new window with title like "Microsoft Visual basic". then click 'File' menu and choose 'import file' and then choose 'module' file (extracted from zip file).
then close new window and return to excel.

Type a number in cell.then click on other cell and type =spellcurr(#cellid)

this will show your number in words.
Eg:
 =spellcurr(A4)

Hope this help you...

 File download

First one.

Blog to share some tricks to everyone.