Monday 30 July 2012

Finding disk space in Linux

Problem: Finding disk space in Linux.
Solution:  We can use command df to find the disk space.
 
[root@dragon ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vg_root          29G   11G  17G   38%  /
tmpfs                 504M  88K  504M  1%   /dev/shm
/dev/sda1             485M  44M  416M  10%  /boot
/dev/lv_home          29G   448M 27G   2%   /home
 

Tuesday 24 July 2012

Finding files in linux

Problem: Finding or Searching files in Linux
Solution: In Linux or Unix you can use find command to find files. Find command will search for the files in current working directory and its subdirectories as well.


  1. To find a file named install.log
     
    [root@dragon ~]# find -name install.log
    ./install.log
    
  2.  To find all files that starts with ins (i.e) ins*
     
    [root@dragon ~]# find -name ins\*
    ./install.log
    ./install.log.syslog
    ./vmware-tools-distrib/installer
    ./vmware-tools-distrib/etc/installer.sh
    

Sunday 22 July 2012

Finding java version

Problem: How to find java version.
Solution: If you have java installed on your machine and it is in system path. -version option gives you the information about Java running on your machine.

 
[root@myworkstation ~]# java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (rhel-1.39.1.9.7.el6-i386)
OpenJDK Client VM (build 19.0-b09, mixed mode)
 

Monday 16 July 2012

Finding MySQL Server version

Problem: How to find version of MySQL server.
Solution: You can find out version information using version variables. 

Login to mysql server and fire the below statement
 
 
mysql> SHOW VARIABLES LIKE "%version%";

Sample Result:
 
+-------------------------+---------------------+
| Variable_name           | Value               |
+-------------------------+---------------------+
| protocol_version        | 10                  |
| version                 | 5.1.52              |
| version_comment         | Source distribution |
| version_compile_machine | x86_64              |
| version_compile_os      | redhat-linux-gnu    |
+-------------------------+---------------------+

Thursday 12 July 2012

Using beyond compare script to generate difference report

Beyond Compare has support for command line script options.

Step1: Create a Script file.
          Type the below contents and save it into file "BCScript.txt"
 
file-report layout:side-by-side  options:display-all,line-numbers   output-options:html-color output-to:%3 %1 %2


Step2 : Run the script file.
 
bc2.exe @BCScript.txt a.java b.java diffreport.html

Thursday 5 July 2012

Knowing Red Hat Linux release details

Problem: Find Red Hat Linux version details
Solution:   /etc/redhat-release contains version details of Red Hat Linux

#cat /etc/redhat-release

#uname -a

Monday 2 July 2012

Couldn’t connect to liferay HSQL database

Problem: When I am trying to connect to default database used by Liferay. I am getting an exception “HSQLDB-In memory: The database is already in use by another process: lockFile: org.hsqldb.persist.LockFile@ca3f17a1”

Solution:
  • Open the properties file C:\demo\liferay-portal-6.0.6\data\hsql\lportal.properties
  • Change the value of “hsqldb.lock_file” to “false
  • Restart the liferay tomcat server

Info:
  • JDBC URL = jdbc:hsqldb:file:/C:/demo/liferay-portal-6.0.6/data/hsql/lportal
  • UserName=sa
  • Password=
  • Password is empty

Remove duplicate element in list - Java

Problem: Remove duplicate element in the list
Solution: Use set as flag to remove duplicate elements in the list
 
package com.lac;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Employee bean
 */
class Employee {
 private int id;
 private String name;

 public Employee(int id, String name) {
  super();
  this.id = id;
  this.name = name;
 }

 public int getId() {
  return id;
 }

 public void setId(int id) {
  this.id = id;
 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

}

/**
 * Remove Duplicates in list
 * 
 */
public class RemoveDuplicates {
 public static void main(String[] args) {
  //Create Employee objects
  Employee a= new Employee(1, "Jhon");
  Employee b= new Employee(2, "Jane");
  Employee c= new Employee(3, "King");
  
  List list= new ArrayList();
  list.add(a);list.add(b);list.add(c); //add employees
  list.add(b);//add duplicate employee
  
  final Set empIds= new HashSet();//flag that keeps employee ids
  
  for(Iterator it=list.listIterator();it.hasNext();){
   Employee emp=it.next();
   if(empIds.add(emp.getId())==false){//if found duplicate remove from the list
    it.remove();
   }
  }
  
  for(Employee emp:list){
   System.out.println(emp.getId());
   System.out.println(emp.getName());
  }
  
 }

}