Sunday, 25 August 2013

Most Useful Eclipse Shortcuts for Java


1)  Ctrl + Shift + R.  -->Open any file quickly

2) Open a type (e.g.: a class, an interface) without clicking through interminable list of packages: Ctrl + Shift + T

3) Go directly to a member (method, variable) of a huge class file,     Ctrl + OCtrl + Shift + ↓ or Ctrl + Shift + ↑,  ==>to move up & down

4) Ctrl + L, enter line number.  

5) Go to a supertype/subtype: Ctrl + T.
6) Help ⇒  Help → Help Contents → Java Development User Guide → Reference → Menus and Actions

Wednesday, 24 July 2013

Some useful Linux commands on Ubuntu

Some useful Linux commands on ubuntu: 

-r  (Recursive , it applies to all directory & sub directories )
Changing the Permission of the file .
chmod -r 777  /var/www/chicagoKid



Configuring Automatic DHCP when it is not configured by default when internet is not working :

ifconfig  - a  //Check IP  is shown or not

In order to configure DHCP address you will need to edit the 'interfaces' file /etc/network/interfaces .

auto eth0
iface eth0 inet dhcp

ctrl+c => cancel
ctrl+o ==>writer out //in terminal
Ctrl+x ⇒   Exit or quit .


Go to /etc/init.d/networking restart   // To restart network services

1)  you can use editor vi or gedit  to open any file.
2) User sudo whenever you need permission.

if you are required to be owner for all time, just open terminal and type
sudo nautilus

search test.com


Check the ubuntu wheter 32 bit or 64 bit:
uname -a
Result for 32-bit Ubuntu:
           i386 GNU/Linux
whereas the 64-bit Ubuntu will show:
                        x86_64 x86_64 GNU/Linux

file /sbin/init

Creating Directory:

sudo mkdir -p /usr/local/java

Some useful commands:
--help 
info
pwd  :  print working directory
ls ~  → Shows file in your home directory
CD (Change Directory)
"cd /"     ⇒ Naviagate to root.
cd ~  ⇒ Navigate to home
cd .. ⇒  one level up
cd -  ⇒ Previous directory

cd ~/Desktop   ⇒ will move you to desktop directory


CP(Copy):
1) cp file foo  ==>Copy file & name it foo
2) cp -r directory foo == >Copy recursively the directory & paste into foo directory.

MV(Move):
Ex-
mv foo ~/Desktop   ==>Moves file  foo to desktop

RM(Remove): 
rm: Use this command to remove or delete a file in your directory.

rmdir: The removes empty directory. To delete all directroy & its content use -r (recursive options)

mkdir ⇒ Make directory
man : ⇒ Lists Manual of other commands
eg : man mv ⇒ Will bring mv manual
sudo: The sudo command is used to perform file operations on files that the Root User would only be allowed to change.
df : File system disk spaces  usages  -h(human readable ) -s means "Summary"
free: tells amount of free and used space  -m(using megabytes)
 top ('table of processes')  : Displays running processes and system resources.
whatis
tab  : Auto completes any command


Paste  into terminal:
ctrl+v does not work  ⇒ User ctrl+Shift+v

History  : Lists command that you already typed

Add new user:
adduser newuserName
passwd  yourNewPassword

Sunday, 23 June 2013

PHPUnit - Unit Testing in PHP



Guys, How many of you are familiar with unit testing in PHP? Well coming to PHP, every would say Yeah every one does it, through echo or die and exit; testing individual modules or functions. Many of us has perception that my code works well so there is no need to test it.

Well, if  you are inline across with same idea, it's what we are not been addicted of the advantages of unit testing frameworks. Instead of testing manually each and every case all time, why not we do it through automation in unit tests right? Further more , When you are under going for a product development, it really comes handy when you are required to know, how much resource a particular module is taking up. Will this module be influencing the other modules performance too? All these things has to be analyzed carefully for a successful product development at each at every stage.

The one which am I talking here is about PHPUnit testing framework which was initially inspired JUnit testing framework for Java. Well if you are PHP Geek, or amateur , you would not take much time to learn this framework and use it .  Here  I'm going to write basics about PHPUnit and simple example  to demonstrate  its usage. Without further ado lets dive into it.

PHPUnit should be installed using the PEAR installer. You need to bother about all those. I would suggest you to download XAMPP  with latest version with PHP version 5.4+ . Below 5.3.3 the PHPUnit does not work. 



I am assuming this article for windows users, Linux users can have slightly different commands. After Installation of XAMPP, there are slight  updates required to be done  in the pear package. 



Go  command line installation directory of PHP, Run it as Administrator.

If you have installed your XAMMP in F drive: 
do the following:
1) Type: F:  then press Enter
 you will be directed to F drive , then type 
  CD F:\xampp\php> 
Here you will run the PEAR command to for updating and installing some dependent package of PHPUnit. 



First one is installing -   PHP_CodeCoverage" package that does not come with the xampp itself. So install it type :  

pear channel-discover pear.phpunit.de pear channel-discover components.ez.no pear install phpunit/PHP_CodeCoverage 
Press the enter , it will be installed automatically. 



If you face any problem, then you need to make sure that your pear package is up to date. To update the Pear package type: 

pear update-channels 
It will update your pear package, the repeat the same above command.



You might face some problems relating to update too. Update may be failed because of caching problems. If you find like so , clear the cache of pear as 

pear clear-cache



That's it you are done with the installation, now for testing your script all you need to do is 

Type the command 
phpunit "FullAbsolutePathOfYourFile"      
Example : F:\xam\php>phpunit "F:\xam\htdocs\test\PersonTest.php"  





Here i will show you how will you write the test script for you actual class being tested. 



Before you dive into details for testing, you need to understand basic idea about it.  The basic idea about  testing in a very nutshell is very simple. Take an example; you have a certain class having function to add 2 numbers that returns sum of it. Now, we need to ensure that the sum is correct ie. 2+3 should yield 5. So the sum = 5 is the result we expect from that function. That means in  our testing class we need to write our testing which compares our expected output with the real output of the function. If the expected out put comes equal with that, our test result passes. That's it, all about the testing. This is the very generalized concept in a nutshell.  



Lets understand it by our example: We have a class person, when  he talks, we should expect the result as Wecome guys or some thing else whatever may be , but we do not expect the sound like MEW as cat right?  



Person.php

<?php
class Person{
    protected $name;



    public function getName() {

        return $this->name;
    }



    public function setName($name) {

        $this->name = $name;
    }



    public function talk() {

        return "Welcome guys !";
    }
}



?>



So we would like to write  UnitTesting Class for this function, which ensures that only man has spoken and not an animal.  To do so,  we write a class PersonTest which must extend PHPUnit_Framework_TestCase class



PersonTest.php

<?php
class PersonTest extends PHPUnit_Framework_TestCase
{

      // test the talk method
     public function testTalk() {
         // make an instance of the person
        $person= new Person();
        // use assertEquals to ensure the greeting is what you
        $expected = "Welcome guys !";
        $actual = $person->talk();
        $this->assertEquals($expected, $actual);


    }
}

?>

assertEquals is a method built in PHPUnit testing framework class which will compare if both the output are equal. There are many methods.

Now run this PersonTest.php class through command line as  



F:\xam\php>phpunit "F:\xam\htdocs\test\PersonTest.php"  



you will see the output something similar to as below. 




That's it You are done with the unit testing with PHP. Wow. !! Congrats.


Couple of things to note.

If test is successful,  you will  see the little dot there.  For every test run there will be a character indicating the result. The characters are as follows:
  • . – Printed when a test succeeds.
  • F – Printed when an assertion fails.
  • E – Printed when an error occurs while running the test.
  • S – Printed when the test has been skipped.
  • I – Printed when the test is marked as being incomplete

This is just an introduction to PHPUnit testing, you need to dive more detail on it. Please do refer an official PHPUnit testing manual here for further detail

Don't forgot to send your feedback enjoy up. !!!




                                                               




  












Friday, 12 April 2013

CSS tricks on styling fonts

Styling CSS using External Fonts:

This might be simple thing  if you know the tricks on how to add desired fonts to the web server, but some times if you are new to this situation, it may stuck you for a while.

Take a simple example, the client want to have Helvetica font into his site. You may be smarter enough to add the helvetica font like 

.myClass{
         font-family: helvitica;
}

But it will not work, because Helvetica is not enlisted in default font list. Your browser will try to find the source for Helvetica font, when it does not find it , by default it will take Arial font which is some what similar to it but not exact.

Another thing to notice is , Helvetica is not a free font , you need to pay ($30- $50) for it. Wow, now what to do !!! 
Often every  one loves Google, so hit the search for Helvetica font. When you find it , download . This  might be in the form of fontName.ttf extension, again  you can not use this font for the web purpose  because it is not web compatible format . So you need to convert this into web compatible formats like - .eot, .svg, .woff, & .ttf too. For achieving this task, you can get some online web sites where you can submit your font & get the converted file attachment back with the compatible fonts.


Obviously, you don't want to loose money for just a font, if you are freelance. So hold down, take a glass of water & long breathe. Here is the way.

You can use this site- http://www.fontsquirrel.com/tools/webfont-generator   , Add the font here & Convert.


After converting & getting all the useful web fonts , you can add these fonts to your web server in some directory or create your own directory & name if fonts/ .

Now After doing this task, all you need is, to add below script to the top of your css file as below.


@font-face {
font-family: 'Helvetica';
src: url('fonts/helvetica.eot');
src: url('fonts/helvetica.eot?#iefix') format('embedded-opentype'),
url('fonts/helvetica.woff') format('woff'),
url('fonts/helvetica.ttf') format('truetype'),
url('fonts/helvetica.svg#helvetica') format('svg');
font-weight: normal;
font-style: normal;
}

A simple example of using  Helvetica Neue CE35 Thin font 

















       Now your helvetica font has become fully functional . Include this css file & style your document with the font name give at the top. 

Note: you can give any name of your desire,  to the font you have newly added, But don't forget to give the same name while styling the document with classes or IDS. 



I hope this document will be surely helpful ,when you get drown into styling the fonts. Any feed backs, & suggestions are hearty welcomed. Enjoy up..!!!








Wednesday, 20 March 2013

Dynamic Data with Modal Pop Using Jquery


You might be interested in getting Pop up window with dynamic data from the Database. One of the common usage you may come up with is:
Suppose you have a student record table, where you are storing detail information about the student. Then you will be obviously having the View student functionality in your application. Here you want to display all the detailed information about student. It's good choice to display all the information about the student, but unfortunately your window size is fixed, so you need to display only important fields of the student record such as Student Name, Address, Contact Number, & Faculty.

Displaying only necessary information has two advantages - One when you look at the student display page, you should not feel like it is too complex, & second important thing: the lesser you display the content , the more faster will be the students records executed.
So, When  you wanted to view the complete details of student, Just give a link to a student name or Id. When it is clicked  display the modal pop up with complete detailed information about the student. Couldn't this quite interesting?

Okey, Diving deep into coding, it pretty easier. Lets check it out.

Say you have list of names & when click on any name, you want to display pop up with his complete details.








So here you have queried through DB & inside loop you have some thing like-
 <td>
   <a href="#" onclick="pop_up('<?php echo $customer['user_id']; ?>')" >
           <?php echo $customer['first_name']." ".$customer['last_name'];?>
  </a>
</td>

When you click on any name, we are passing an Id inside a    java script function  pop_up() .
So the pop up function will receive an Id & through where , I  will Post the id to Php Script using Jquery.
The Php will  select the required data & return back to the same page.  

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"> </script>


<script type="text/javascript">


function pop_up(id){

var url = "customer_complete_datail.php?id="+id

$.post(url, function(data) {
 
 
 $('#overlay_form').html(data);  //Setting the content of html 
  
});
//open popup
$("#overlay_form").fadeIn(1000);
positionPopup();

}

             function positionPopup(){

if(!$("#overlay_form").is(':visible')){
return;
}
$("#overlay_form").css({
left:263,
top:145,
position:'absolute'
});
}
               function close_cd()
{
$("#overlay_form").fadeOut(500); //Closing the opened window
}
</script>

Just create the space using DIV for holding you dynamic data 


<div id="overlay_form" style="display:none;">
 </div>

Give some styles in html head section for Pop up Model:

<style>
#overlay_form{
position: absolute;
border: 5px solid gray;
padding: 2px 24px 2px 2px;
background: white;
left:263px;
top:145px;
/*width: 321px;*/
/*height: 400px;*/

}
#pop{
display: block;
border: 1px solid gray;
width: 65px;
text-align: center;
padding: 6px;
border-radius: 5px;
text-decoration: none;
margin: 0 auto;
}
</style>

Here is the Page (customer_complete_detail.php) that we are referencing & getting the whole content:



<?php
session_start();
include_once '../config/connect.php';
include_once 'helper.php';
$Helper_admin = new Helper_admin();

$id = $_REQUEST['id'];

$customerDetail = $Helper_admin->getCustomerDetailById($id);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Customer Details</title>
    <style type="text/css">
    .formLayout
    {
        background-color: #f3f3f3;
        border: solid 1px #a1a1a1;
        padding: 10px;
        width: 300px;
    }
    
    .formLayout label, .formLayout input
    {
        display: block;
        width: 120px;
        float: left;
        margin-bottom: 10px;
    }

    .formLayout label
    {
        text-align: right;
        padding-right: 20px;
    }
    .pop_up_form{clear:both;}

    br
    {
        clear: left;
    }
    </style>
</head>
<body>
    <div class="formLayout">
        <h4 class="h4_account">Customer Details</h4>
        <div class="pop_up_form">
       <label>First Name:</label>
       <label><?php echo $customerDetail->first_name; ?></label>
       <br>
       <label>Last Name:</label>
       <label><?php echo $customerDetail->last_name; ?></label><br>
       
       <label>Contact No.:</label>
       <label><?php echo $customerDetail->contact_no; ?></label><br>
       
       <label>Email:</label>
       <label><?php echo $customerDetail->user_email; ?></label><br>
       
       <label>Current Location:</label>
       <label><?php echo $customerDetail->current_location; ?></label><br>
       
       <label>City:</label>
       <label><?php echo $customerDetail->city ; ?></label><br>
       
       <label>State:</label>
       <label><?php echo $customerDetail->state ; ?></label><br>
       
       <label>Country:</label>
       <label><?php echo $customerDetail->country ; ?></label><br>
       
       <label>Zip:</label>
       <label><?php echo $customerDetail->zip  ; ?></label><br>
        </div>
        <div>
           <a href= 'javascript:void(0)' onclick="close_cd()" id='close_cd'>Close</a>
        </div>   
                 
    </div>
   
</body>
</html>

So you are almost done.  !!! Hurray ..

Here is the output when you click on one of the name :




Any Questions.. Queries.. Don't forget write out  !!!
Rock up.. :) !













Sunday, 9 December 2012

Resume Writing

Resume writing is one of the major challenging task. Whether you are an experienced person or a fresher, your profile plays an important role in hunting the good job. There may be thousands of resumes listed in front of desk with company HR. Among them, they will shortlist only few. In this context, an effective resume plays a significant role. Now the question is what makes the resume to be an effective one? Are there any specific criteria for a resume to become distinguished. Yes, of course, we will discuss about the same here.

I would like to focus this topic of resume, specially for freshers, though it might be help for experienced users too. There are different names given for this title - some of them call it as CV(Curriculum Vitae) or Profile or Resume. Profile is the common term used for CV as well as Resume.  Lets us first differentiate between the
CV and Resume.
CV : - This is the common term used in case of experienced person.
Resume :- The freshers profile or a person having experience less than  2-3 years of work experience, we call it as Resume.

Some Common Rules while writing Resume:
1) If you are a fresher, don't complicate your resume more. Make it as simple as possible with some of effective points to be highlighted  that differentiates you from others.
2) Do not decorate your resumes by putting underlines, stylish fonts etc.
3) Use common font at all places like; Times New Roman, Calibri etc with font size 10-12. You can highlight  the most important keywords of your Resume by making it Bold.
4) The freshers resume should not go beyond two pages.
5) If you are good at technical side though, if you feel that you have less marks in comparison to others , do not show the marks percentage in resume. Some times it works, there may come a situation when less expert people than you may bring higher marks. While shortlisting, your resume might not be shortlisted because of the same.
6) Keep the most important part of your resume in your first page of resume.

Though there are various methods & styles of writing Resumes , The very common can have the following format.

1) Put your name & contact details at top of the page, like below:
Name:                   ...........................................
Contact Number:   ...........................................
Email:                    ...........................................

Remember that, always provide  only one Email Id. As your email id should look professional, like yourname.cast@domain.com. you should not provide an email id that looks an informal like punk14@rockstar.com etc. While giving the contact number, you can give alternative contact numbers too. Do not place address details & other details here.

2)  Next most important part of your resume is your Objective. This is the one entity, which distinguishes you from others. Objective may be different for different platforms & working domains. However, if you are unsure about on which specific platform you are going to work, you can write general objective.
For example your general objective might be: Seeking a position to utilize my skills & abilities in an organization that offers professional growth by being resourceful, innovate,& flexible.
This does not gone to help you if your applying for only specific platform, in this case your specific objective will be helpful. For example - if you are applying for a position of .Net programmer , you objective can be - "To become an excellent .Net expert in an IT Industry ".

3) In next section you can show your most distinguished expertise, Strength ,& important events that you have handled during your college life or till the your carrier as below.
a) Strength: "Self confident, Accept & believe that nothing is impossible if done with full dedication & hard labor".
b) Important Events : 
c) Technical Skills :
d) Educational Details:
While writing your educational degrees, write your highest qualification at the top & then follow sequentially.
two degrees are enough to be shown in resume. Masters , Bachelors // Or Bachelors //Intermediate.

4) Next you can have your final project & other external project summaries.

This all contents must be present in  first page.Most of the time, HR does not have the time too look for your second or last page. S/He will sort our your resume based on first page summary only.

5) In Second page you can show the following details :

a) Hobbies
b) Personal Details:
Do not repeat you name again here.if it is previously mentioned, it may contain -
       Date of Birth:
       Gender:
       Language Known:
       Nationality:
       Marital Status:
     
c)   Address Details: Temporary & Permanent
d)  Declaration:This is also an important thing. It ensure that the mentioned details in the resume are correct. You can write the declaration as:
I hereby declare that the information above provided is true to the best of my knowledge. If the information provided is appeared to be false, the concerned authorities are liable to take any action.

e)  Place of resume written, Date ,& Signature at the right side has to be written. Note that some companies do not accept your resume until & unless it is signed.  For ex -

Place: XYZ( Bangalore)
Date:   09 ,Dec,2012                                                                                                     Signature:

I have attached my resume demo sample. Download It.

This completes the resume. Though there are so many things that needs to be considered, I hope you will really get some idea & clue regarding the resume writing. I shared the things, what ever I knew & experience d from my company & Institute where I learned.
Your comments, suggestions ,& any improvements to this topic are hearty welcomed.




































Monday, 26 November 2012

Printing content of specific div using Javascript


Problem:

Guys you came across a situation, where you need to print a specific part of a Html or Php Page. When you try to execute this command in javascript :


"window.print();"

It will print your whole page. It gives a lot problem if you do not know how to print the specific content.
For ex - In your Html page , say there is a coupon banner which needs to printed by user. Now How to do that ?

You can do it by 2 ways :
Solution 1)
Using CSS to display only the content which is under print & hiding rest of others.

  <style type="text/css" media="print" >
           .nonPrintable{display:none;} /*class for the div or any element we do not want to print*/
</style>

==>Here , while you specify ----media="print"---- inside  <style> tag, it indicates that , this css will be applied only when you are printing some content.

Solution 2)

 The next method that can be commonly applied with most of the browser is using "Javascript".

The idea behind this is :
           While you Hit the print command, Just dynamically create a new pop up page from the existing page content(the content you need to print) & then print the page. Very simple.. Just check it out.

<script type="text/javascript"><!--
function print_specific_div_content()
{
 //alert("Hello world");
 var content = "<html>";
 content += document.getElementById("coupon_deal_id").innerHTML ;
 content += "</body>";
 content += "</html>";


 var printWin = window.open('','','left=0,top=0,width=1000,height=500,toolbar=0,scrollbars=0,status =0');

 printWin.document.write(content);
 printWin.document.close();
 printWin.focus();
 printWin.print();
 printWin.close();


}


</script>


<body>
     <div>Here comes your dummy other content </div>
     <div id= "coupon_deal_id">
                Only this content you want to print.......


     </div>
     <button type="button" onclick="print_specific_div_content()" >Print Coupon    </button> 



</body>

------Just check out the flow-----------------
1) When you click on Print coupon button , the control will go into  print_specific_div_content() function.
Then in content variable you are writing entire new html page, there you can add any content or items that you want to display with printed item. For ex - You can add the current Date inside that.

2)  After creating a content, just you are creating an instance of window using
    var printWin = window.open(.......).
 
==>Then you are setting some required parameters of window such as Height & width.
==>Then you write the content to that window using printWin.document.write(content);
==>then execute the print command printWin.print();
==>& finally , close the window.

Simple...

Just Rock on .. Use this function where ever you want the function to print the part of the page.