Tuesday 26 July 2016

remove untracked files in git

Remove untracked files from the working tree

Step 1 is to show what will be deleted by using the -n option:
git clean -f -n
Clean Step - beware: this will delete files:
git clean -f
  • To remove directories, run git clean -f -d or git clean -fd
  • To remove ignored files, run git clean -f -X or git clean -fX
  • To remove ignored and non-ignored files, run git clean -f -x or git clean -fx
Note the case difference on the X for the two latter commands.
If clean.requireForce is set to "true" (the default) in your configuration, one needs to specify -fotherwise nothing will actually happen.
Again see the git-clean docs for more information.



------------------------------------------------------------------------------

Monday 25 July 2016

Ruby small programs

File Inquiries:



--------------------------------------------------------------------------------------
if (File.file?("inputt.txt"))
puts "yes"

else
puts "no"
end

--------------------------------------------------------------------------------------------

if (File.file?("input.txt"))
puts "File exist"

else
puts "File not exist"
end


 size=File.size?("input.txt")
 puts "File size is #{size}"


--------------------------------------------------------------------------------------------
print "present directory is: " 
 puts Dir.pwd


  
print "files in directory"
 puts Dir.entries("C:/Users/mobigesture/rubyscript")



--------------------------------------------------------------------------------------------
 #puts Dir.entries("C:/Users/mobigesture/rubyscript")
 
 puts "Files in the directory"
 Dir.foreach("C:/Users/mobigesture/rubyscript") do |fname|
 puts fname
 end

--------------------------------------------------------------------------------------------





--------------------------------------------------------------------------------------------



--------------------------------------------------------------------------------------------

Friday 22 July 2016

The Hosts File and its uses

Introduction
When using the Internet most people connect to web sites, ftp servers or other Internet servers by connecting to a domain name, as in www.google.com. Internet applications, though, do not communicate via domain names, but rather using IP addresses, such as 192.168.1.1. Therefore when you type a domain name in your program that you wish to connect to, your application must first convert it to an IP address that it will use to connect to.
The way these hostnames are resolved to their mapped IP address is called Domain Name Resolution. On almost all operating systems whether they be Apple, Linux, Unix, Netware, or Windows the majority of resolutions from domain names to IP addresses are done through a procedure called DNS.
What is DNS
DNS stands for Domain Name System and is the standard domain name resolution service used on the Internet. Whenever a device connects to another device on the Internet it needs to connect to it via the IP address of the remote device. In order to get that IP address, DNS is used to resolve that domain name to its mapped IP address. This is done by the device querying its configured DNS Servers and asking that server what the IP address is for that particular domain name. The DNS server will then query other servers on the Internet that know the correct information for that domain name, and then return to the device the IP address. The device will then open a connection directly to the IP address and perform the desired operation.
If you would like a more detailed explanation of the Domain Name System you can find it here: The Domain Name System
Enter the Hosts File
There is another way to resolve domain names without using the Domain Name System, and that is by using your HOSTS file. Almost every operating system that communicates via TCP/IP, the standard of communication on the Internet, has a file called the HOSTS file. This file allows you to create mappings between domain names and IP addresses.
The HOSTS file is a text file that contains IP addresses separated by at least once space and then a domain name, with each entry on its own line. For example, imaging that we wanted to make it so that if you typed in www.google.com, instead of going to Google we would go to www.yahoo.com. In order to do this you would need to find out one of the IP addresses of Yahoo and map www.google.com to that IP address.
One of the IP addresses for Yahoo is 216.109.118.69. If we wanted to map Google to that IP address we would add an entry into our HOSTS file as follows:
216.109.118.69 www.google.com
NOTE: When inputting entries in the hosts file there must be at least one space between the IP address and the domain name. You should not use any web notations such as \, /, or http://. You can disable a specific entry by putting a # sign in front of it.
You may be wondering why this would work as we said previously that when you need to resolve a domain name to an IP address the device will use its configured DNS servers. Normally this is true, but on most operating system the default configuration is that any mappings contained in the Hosts file overrides any information that would be retrieved from a DNS server. In fact, if there is a mapping for a domain name in a hosts file, then your computer will not even bother querying the DNS servers that are authoritative for that domain, but instead read the IP address directly from the HOSTS file. It is also important to note that when you add entries to your HOSTS file they automatically start working. There is no need to reboot or enter another command to start using the entries in the HOSTS file.
An example HOSTS file can be found here: HOSTS
Please note that there are ways to change the order that your computer performs Domain Name Resolution. If there are problems with HOSTS file not working you may want to read this article that goes into much greater detail on Domain Name Resolution on various operating systems:
For reference the HOSTS file is located in the following locations for the listed operating systems:
Operating System
Location on Hard Drive
Linux/Unix/etc/hosts
Windows 3.1/95/98/MEc:\windows\hosts
Windows NT/2000/XP Proc:\winnt\system32\drivers\etc\hosts or c:\windows\system32\drivers\etc\hosts
Windows XP Homec:\windows\system32\drivers\etc\hosts
NetwareSYS:ETC/HOSTS
AppleSystem Folder:Preferences and in the System Folder itself.
In Windows machines you may not already have a hosts file. If this is the case there will most likely be a sample hosts file called hosts.sam that you can rename to hosts and use as you wish. You can edit this file either from the cmd prompt using Edit or Notepad on windows or VI on Unix/Linux. Really any text editor can open and modify the HOSTS file. It is also recommended that if you use this file that you make periodic backups of it by copying it to another name. Some people recommend that you make this file read only so that it will be harder to modify by a malicious program, which there are Hijackers that are known to do this, but there are Hijackers such as CoolWebSearch that add entries to the file regardless of whether or not its read only. Therefore you should not think that having your HOSTS as read only will make it safe from modification.
Why would I want to use a HOSTS file
There are a variety reasons as to why you would want to use a HOSTS file and we will discuss a few examples of them so you can see the versatility of the little file called the HOSTS file.
Network Testing - I manage a large Internet Data center and many times we need to set up test machines or set up development servers for our customers applications. When connecting to these development or test machines, you can use the HOSTS file to test these machines as if they were the real thing and not a development server. As an example, lets say that you had a domain name for a development computer called development.mydomain.com. When testing this server you want to make sure it operates correctly if people reference it as the true web server domain name, www.mydomain.com. Since if you change www.mydomain.com in the DNS Server to point to the development server everyone on the Internet would connect to that server, instead of the real production server. This is where the HOSTS file comes in. You just need to add an entry into your HOSTS file that maps www.mydomain.com to the IP address of the development server on the computers that you will be testing with, so that the change is local to the testing machines and not the entire Internet. Now when you connect to www.mydomain.com from your computer with the modified HOSTS file you are really connecting to the development machine, but it appears to the applications that you are using that you are connecting to www.mydomain.com.
Potentially Increase Browsing Speed - By adding IP address mappings to sites you use a lot into your HOSTS file you can potentially increase the speed of your browsing. This is because your computer no longer has to ask a DNS server for the IP address and wait to receive it's response, but instead can quickly query a local file. Keep in mind that this method is not advised as there is no guarantee that the IP address you have for that domain name will always stay the same. Therefore if the web site owner decides to change their IP address you will no longer be able to connect.
Block Spyware/Ad Networks - This reason is becoming a very popular reason to use the HOSTS file. By adding large lists of known ad network and Spyware sites into your hosts file and mapping the domain names to the 127.0.0.1, which is an IP address that always points back to your own machine, you will block these sites from being able to be reached. This has two benefits; one being that it can make your browsing speed up as you no longer have to wait while you download ads from ad network sites and because your browsing will be more secure as you will not be able to reach known malicious sites.
NOTE: It is important to note that there have been complaints of system slowdowns when using a large hosts file. This is usually fixed by turning off and disabling the DNS Client in your Services control panel under Administrative Tools. The DNS client caches previous DNS requests in memory to supposedly speed this process up, but it also reads the entire HOSTS file into that cache as well which can cause a slowdown. This service is unnecessary and can be disabled.
There are HOSTs file that are already made that you can download which contain a large list of known ads servers, banner sites, sites that give tracking cookies, contain web bugs, or infect you with hijackers. Listed below are web sites that produce these types of hosts files:
hpguru's HOSTS File can be found here: http://www.hosts-file.net/
The MVPS Host File can be found at: http://www.mvps.org.
Hosts File Project can be found here : http://remember.mine.nu/
If you choose to download these files, please backup your original by renaming it to hosts.orig and saving the downloaded HOSTS file in its place. Using a HOSTS file such as these is highly recommended to protect your computer.
Utilities for your HOSTS file
If you do not plan on modifying your HOSTS file much and plan on using it occasionally for testing purposes, then the basic text editors like VI, Notepad, and Edit are more than adequate for managing your HOSTS file. If on the other hand you plan on using the HOSTS file extensively to block ads/spyware or for other reasons, then there are two tools that may be of use to you.
eDexter - When you block ads on web sites using a HOSTS file, there tends to be empty boxes on the web site you are visiting where the ad would normally have appeared. If this bothers you, you can use the program eDexter to fill in the image with one on your local machine such as a clear image or any other one for that matter. This removes the empty boxes and is quick because the replacement image is loaded off of your hard drive.
Hostess - Hostess is an application that is used to maintain and organize your HOSTS file. This program will read your HOSTS file and organize the entries contained in it into a database. You can then use this database to scan for duplicates and to manage the entries. It is a program that is definitely worth checking out if you plan on using the HOSTS file extensively.
Conclusion
As you can see the HOSTS file is a powerful tool if you understand how to use it. You should now know how to use the HOSTS file to manipulate Domain Name Resolution to suit your needs. It is also important that you use its ability to block malicious programs as discussed above to make your computing environment more secure.
As always if you have any comments, questions or suggestions about this tutorial please do not hesitate to tell us in the computer help forums.
--
Lawrence Abrams
Bleeping Computer Basic Internet Concepts Series
BleepingComputer.com: Computer Support & Tutorials for the beginning computer user.
Revision History
04/09/04 : Added information about hpguru's host file and http://remember.mine.nu/. Warned about potential slow downs caused by large hosts files and how to fix that. Updated information that changing the hosts file to read only may not stop hijackers from changing information. Added info about hostess host file manager and - Thanks to CalamityKen

Thursday 21 July 2016

Install and Configure Apache 2.4.x on Windows

http://localhost/



1)  Go to

http://www.anindya.com/apache-http-server-2-4-2-x86-and-x64-windows-installers/

download the windows  msi installer


A web server is software that continuously runs on a computer and allows other computers to download documents from it. This text that you're reading right travelled over a network connection from Lifehacker's hosting web server to your browser. Web servers are usually loud, scary, headless machines in cold windowless rooms, but you can run one under your desk at home.
Why would you want to run a home web server? Maybe you want to download files on your home computer from anywhere. Like, say, your digital music collection. In this how-to, we'll set up a home web server that lets anyone (with the right password!) connect to your computer and download your MP3's from it, for a nice way to share your music collection with friends, or play a song from your home machine at the office for co-workers.
Please note: Running a server on your home computer is a risky undertaking, and before you start, make sure your computer has all the latest patches and security updates, and that you've done a thorough spyware and virus scan. This tutorial is for advanced users who feel comfortable editing textual configuration files and exposing port 80 on their home computer to the internet. As always, a strong firewall with explicit user-set rules is recommended. Still game? Carry on.
Let's get started.
What you'll need:
  1. A Windows PC [1]
  2. An always-on broadband (DSL or cable) internet connection
Step 1. Install Apache HTTP server. [2]
First and foremost, disable and stop any other firewall or server software you may have running, including Windows Firewall, Skype, Trillian or any other instant messaging applications. This is extremely important, and if it's not done, can cause the server installation and startup to fail miserably. These programs and services can be started and used again as usual once we're done setting up the web server.
Download Apache HTTP Server from here, using the link next to "Win32 Binary (MSI Installer)." Start the installation wizard. Accept the license agreement and use the default location for the Apache files, in C:\Program Files\Apache Software Foundation\Apache2.2\. When you reach the screen prompting for server information, enter your own email address and homeip.net [3] as the domain information, like so:
Geek to Live: How to set up a personal home web server
Complete the installation wizard using the "Typical installation" setting.
When it's done, open your web browser and go to http://localhost/. If the page you see reads, "If you can see this, it means that the installation of the Apache web server software on this system was successful," you're golden. [4]
Step 2. Configure Apache to share documents from the right folder.
Say you want to make your music collection downloadable using your new web server [5], and all your music files are located in C:\Gina\My Music. Using a plain text editor like Notepad, open the C:\Program Files\Apache Group\Apache2\conf\httpd.conf file. This is Apache's configuration file, which looks long and scary, but most of the defaults will work just fine for us. We just have to change a few things.
In this httpd.conf file, comment out the line that starts with DocumentRoot and add another with your directory, like this:
#DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
DocumentRoot "C:/Gina/My Music"
Then, comment out the line that starts with <Directory "C:/Program... and add another with your directory, like this:
#<Directory "C:/Program Files/Apache Group/Apache2/htdocs">
<Directory "C:/Gina/My Music">
Last, about 20 lines below that
AllowOverride None
Change it to:
AllowOverride All
When you're done, save httpd.conf. Then, click on the Apache icon in your taskbar and choose "Restart." If Apache restarts successfully [6], you edited your the file correctly. Visit http://localhost/ in your web browser. This time you should see a listing of your music files. Woo-hoo!
Step 3. Password your web site documents.
But we don't want just anyone to be able to download your music. Your bandwidth is precious, and we want to secure things a bit. Let's create a password prompt.
First, open a command prompt (go to the Start menu, choose Run, then type cmd.) Change to the Apache bin directory by typing:
cd "C:\Program Files\Apache Software Foundation\Apache2.2\bin"
Then create a password file by typing:
htpasswd -c "C:\Documents and Settings\Gina\my_password_file.txt" gina
Replace the path with the path of your new password file (which should in any folder EXCEPT the web server's document root.) Replace gina with the username you want to use. When prompted, enter the password you want to set up. Once you've done that, a password file will be created.
Now we want to apply that login to your music directory. Open up a new file in a plain text editor like Notepad. Copy and paste the following into it:
AuthType Basic
AuthName "This is a private area, please log in" 

AuthUserFile "c:\Documents and Settings\Gina\my_password_file.txt"
AuthGroupFile /dev/null 


require valid-user

Make sure you replace "C:\Documents and Settings\Gina\my_password_file.txt"in the text with your own password file created above. Save this new file IN YOUR WEB SERVER DOCUMENT ROOT (in this case, C:\Gina\My Music) and name it .htaccess. Don't forget the dot in the beginning, before .htaccess. So, in this case, we're saving the file as C:\Gina\My Music\ .htaccess.
Note: If you're using Notepad to create your .htaccess file, when you save the file, put quotes around the filename - ".htaccess" - so that Notepad doesn't automatically put a .txt extension on the file. If there's a .txt file extension, your password won't work!
Now, using your web browser, go to http://localhost/. You should be prompted to log in. Enter your username and password you set up in your password file. Rock!
Step 4. Congratulate yourself. You've got a home webserver running.
If you are NOT behind a firewall, you can access your web server from other computers by typing your computer's IP address into a web browser's address bar. If you're not sure what your IP is, visit What Is My IP to find out. If your IP is 12.34.567.890, then type http://12.34.567.890 into a browser's address bar. [7]
If you ARE behind a firewall (like a wireless router), you'll need to open up port 80 on the firewall and forward it to your computer. This part is beyond the scope of this article, but
will be covered in a future Lifehacker feature is covered in Lifehacker feature How to access a home server behind a firewall.

Monday 11 July 2016

Present copy




















1)
package com.saavn;

import java.util.Scanner;

public class Book {

  int bookPrice;
  String bookName;
 
 
   void bookTitle()
  {
  System.out.print("enter book titile: ");
  Scanner scanner=new Scanner(System.in);
  bookName=scanner.next();
  System.out.print("enter the price of the book: ");
  Scanner scan=new Scanner(System.in);
 bookPrice=scan.nextInt();
 
  }
 
  void display()
  {
  System.out.println("Name of the book is "+bookName +" and price is : "+bookPrice);
 
  }


public static void main(String[] args) {

   Book a=new Book();
   a.bookTitle();
   a.display();

}



}
===========================================================

public class Calculations {


public static void main(String args[])
{
int a,b;
char ch;
System.out.println("1. Addition 2.subtraction 3.multiplication ");
System.out.print("enter your choice: ");
Scanner scan = new Scanner(System.in);
ch= scan.next().charAt(0);
//System.out.println("char is :"+ch);
System.out.println("enter a & b: ");
a=scan.nextInt();
b=scan.nextInt();
//System.out.println("a & b is : "+a +" ,"+b);


switch(ch)
{
case '1':
  System.out.println("Addition of "+a +"& "+b +"is :"+(a+b));
  break;
case '2':
  System.out.println("Subtraction of "+a +"& "+b +"is :"+(a-b));
  break;
case '3':
  System.out.println("Multiplication of "+a +"& "+b +"is :"+(a*b));
  break;
 
     default:
      System.out.println("Invalid choice");



}


}


}

==============================================================

public class Array {


public static void main(String[] args) {




 System.out.print("enter length of array: ");

 Scanner scan = new Scanner(System.in);
 int x= scan.nextInt();
 int[] arr = new int[x];

 for(int i=0;i<x;i++)
 {
 System.out.print("enter arr[ "+i+"] :");
 int y=scan.nextInt();
 arr[i]=y;


 }

 System.out.print("The array is : {");
 for(int i=0;i<arr.length;i++)
 {
 System.out.print(arr[i]+",");

}
 System.out.print("}");

}

}
==================================================================


package com.saavn;

import java.util.Scanner;

class Squ
{
       int squaring(int i)
       {
        return i*i;
       }

}

  class Square {

public static void main(String args[])
{
     int x;
     System.out.println("enter x value");
     Scanner scan=new Scanner(System.in);
     x=scan.nextInt();
Squ s1=new Squ();
System.out.println("the square of no is : " + s1.squaring(x));
}
 
}


======================================================================
Call by Ref




package com.google;


class Change
{
int a,b;

Change(int a,int b)
{
this.a=a;
this.b=b;
}

void method(Change obj1)
{
obj1.a=1;
obj1.b=2;
}
void display()
{
System.out.println("a & b are : "+a +" , "+b);
}


}




class CallByRef {

public static void main(String[] args) {
Change obj=new Change(3,5);
  obj.display();
         obj.method(obj);
         obj.display();
}

}


====================================================================

package com.google;

class Priv
{
     int a ;
     public int b;
     private int c;
     
     
     void setc(int x)
     {
      c=x;
      
     }

    
     int getc(){
      return c;
      
     }
   
}

    class Test {
public static void main(String[] args) {

       Priv obj=new Priv();
       
       obj.a=2;
       obj.b=3;
       obj.setc(4);
     
       System.out.println("a & b : "+obj.a+" ,"+obj.b);
       
       System.out.println("c : "+obj.getc());

}
}

===========================================================

package com.google;


class sample
{
static int m=4;

}
class TestStatic {
  static int a=3;
  static int b;
  
  static
  {
  b=4;
  
  }
  
  static void method(int x)
  {
  System.out.println("x : "+x);
  }
  
  
  public static void main(String args[])
  {
  System.out.println("a& b : "+a+" ,"+b);
  
  method(6);
  
  System.out.println("m : "+sample.m);
  /*Outside of the class in which they are defined, static methods and variables can be used
  independently of any object. To do so, you need only specify the name of their class followed
  by the dot operator.*/
  
  }
}
===========================================================
package com.sree;


class Sample
{
     static int a=3;
     
     static void display()
     {
      System.out.println("a : "+a);
      
     }

}


class StaticDemo{


public static void main(String args[])
{

 System.out.println("a in sample class: "+Sample.a);
 System.out.println("static method :");
Sample.display();

}

}




===========================================================
Passing Command line Arguments in Eclipse



  1. Click on Run -> Run Configurations
  2. Click on Arguments tab
  3. In Program Arguments section , Enter your arguments.
  4. Click Apply


=====================================================================

package com.google;



class Command {

public static void main(String args[])

{
 System.out.println("in main");
for(int i=0;i<args.length;i++)
System.out.println("arg["+i+"] : "+args[i]);

}


}




===========================================================

package com.google;

 class VarArgs {
 static void Test(int arr[])
 {
 System.out.print("no of argments: "+arr.length+" contents are:  ");
 for(int x: arr)
 {
 System.out.print(x+ " ");
 }
 
 System.out.println();
 }
 
 
 public static void main(String args[])
 {
 int a[]={1};
 int b[]={2,3};
 int c[]={};
 
 Test(a);
 Test(b);
 Test(c);
 
 
 }


}
------------------------------------------------------------------------------------------------------------------------------------


package com.google;

 class VarArgs {
  
 static void Test(int ... arr)
 {
 System.out.print("no of argments: "+arr.length+" contents are:  ");
 for(int x: arr)
 {
 System.out.print(x+ " ");
 }
 
 System.out.println();
 }
 
 
 public static void main(String args[])
 {
 
 Test(1);
 Test(2,3);
 Test();
 
 
 }

}



===========================================================
package com.google;

 class VarArgs {
  
 static void Test(String msg,int ... arr)
 {
 System.out.print(msg +" :");
 System.out.print("no of argments: "+arr.length+" contents are:  ");
 for(int x: arr)
 {
 System.out.print(x+ " ");
 }
 
 System.out.println();
 }
 
 
 public static void main(String args[])
 {
 
 Test("one",1);
 Test("two three",2,3);
 Test("no varags");
 
 
 }

}


===========================================================




===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================



===========================================================

===========================================================
===========================================================

===========================================================


===========================================================





===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

===========================================================


===========================================================

===========================================================
===========================================================

This keyword

  • this keyword can only be the first statement in Constructor.
  • A constructor can have either this or super keyword but not both.

========================================================