Tuesday, November 24, 2015

Log into a website using a IP address from another country



Today we are going to talk about very interesting topic and that is how we fake our real IP address and log into a web site.

First let me briefly explain how this happen.

Normally when we surfing the web what we do is we send our HTTP or HTTPS requests to a particular server. In that case server can know our real IP and someone in our path can block requests goes to a particular server if that person want.

In this approach we send our request to a special type of server called proxy servers. After that that proxy server sends our request and send the response to us. What end server notice is request coming from proxy server and some one on the way to proxy server will think that we are going to proxy server, but actually we are going to proxy server to ask that server to do some thing for us  that is go to website we want.. :)



That is how it happens lets get into work,

  1. Type "http free proxy" and search in google
  2. you will find many site that give free proxy server addresses.
  3. Choose a good proxy server according to your needs.
    • different servers are in different countries.
    • some servers does't allow HTTPS connections.
  4. Change your proxy settings in your browser using proxy server IP and port obtain from a site
That's it and now you can use a proxy server from another country to get web sites for you.

NOTE:  Be careful If you are going to use proxy servers for login Facebook, G mail or other sites which you have to provide your secret credentials. Those servers will direct you to wrong pages and steal your credentials.

Sunday, November 22, 2015

Shutdown computers running Linux using Terminal




Some times you might want to shutdown your computer which runs linux using terminal because of several reasons. GUI of your operating system might not work or you just want to be a smart user of linux. what ever it is, lets see how we can shutdown our computer using linux command line.

It is easy,

  1.    Press Ctrl+Alt+T for get in to the terminal.
  2.    Enter the code sudo shutdown -h now and press Enter.
  3.   Type in your password (if prompted) press Enter again.
There are some other methods to do the same task and mainly two commands.
  1. Shutdown command
    • this command will bring the system down with a warning message
  2. Poweroff command
    • this command will stop the system
So you can use these two commands as well,

  • poweroff
  • shutdown -h +0


Friday, May 1, 2015

Install apps in your android virtual device

Some times we want to install built apps (apk files) in our virtual device.
It is simple we just have to copy that apk file in to platform-tools folder in Android sdk directory.
Then execute this command in command prompt in platform-tools directory.

            adb install appName.apk

"appName.apk" should replaced by name of the app that you want to replace.

see the following example screen shot.


Thursday, February 12, 2015

importing .sql file into a database using wamp



















when you have a sql file you can easily import it in to a database Using wamp.

1. left click wamp -> phpmyadmin
2. select database then click import (top right)
3. locate the database and click go.
You can use the command prompt as well. For that,

1. Run the cmd (DOS) and get into the mysql folder, which in my case works like this
C:\>cd C:\wamp\bin\mysql\mysql5.0.51b\bin
2. Then use this command to fire up MySQL

C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql.exe -use databasename -u username -p

you should provide a password if you have one.
After that copy .sql file to directory where mysql.exe is located and run the command ,
mysql> source myfilename.sql;

Sunday, February 8, 2015

Use java Comparable interface to sort objects

In previous tutorial we looked at how to sort int, double and String arrays using java Arrays.sort() method. That is not all that we can do with that method. We can sort Objects as well.
But when we come to Objects there is a small problem. Lets see that problem and solution for that using java Comparable Interface.

This is the code for Student class
public class Student {

 private String name;
 private int marks; 

 public Student(String name,int marks){
  this.name=name;
  this.marks=marks;
 } 

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

 public String getName() {
  return name;
 }

 public void setMarks(int marks) {
  this.marks = marks;
 }

 public int getMarks() {
  return marks;
 }
}


If we create few objects of Student class and try to sort them using Arrays.sort() method,
  
public class ObjSort {

 public static void main(String args[]){ 

  Student[] students = new Student[4];

  Student pineappale = new Student("nimal", 70);
  Student apple = new Student("Anuradha", 95);
  Student orange = new Student("Tharaka", 82); 
  Student banana = new Student("Isuru", 90); 

  students[0]=pineappale;
  students[1]=apple;
  students[2]=orange;
  students[3]=banana; 

  //sort with student's marks 
  Arrays.sort(students); 

  int i=0;
  for(Student temp: students){
   System.out.println("Students " + ++i + " : " + temp.getName() +
   ", Marks : " + temp.getMarks());
  }
    }
}

It will give an error because to sort there should be something to compare. But in Student objects there are multiple attributes to compare. To sort objects on particular attribute we have to implement Comparable class and override the  compareTo() method in Student class.
After making those differences it will look like this.
 
public class Student implements Comparable<Student> { 

 private String name;
 private int marks; 

 public Student(String name,int marks){
  this.name=name;
  this.marks=marks;
 }  

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

 public void setMarks(int marks) {
  this.marks = marks;
 }

 public int getMarks() {
  return marks;
 } 

 public int compareTo(Student compStudent) { 
  int comparemark = compStudent.getMarks(); 

  //if we want to sort in ascending order
  return this.marks - comparemark; 
 } 
}

Now we can use Arrays.sort() method on array of Student objects because now it compares objects on marks attribute.

Sort an array using java Arrays class

There are lot of sorting algorithms to use. but if we are in a hurry or we just want to sort a small set of data using sort() method of java Arrays class is the best thing you can do.
So lets see how to sort an array using java Arrays class.
here is the coding example.

import java.util.Arrays;

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

  String[] names = { "Nimal", "Sunil", "Tharaka", "Isuru","Anuradha"};
  int[] intNumbers = { 3, 5, 12, 7, 1, 9};
  double[] doubleNumbers = { 2.34, 45.213, 4.76, 4.23, 8.32};  

  //sorting String array 'names'
  Arrays.sort(names);  

  int i=1;
  System.out.println("After sorting String array");
  for(String name:names)
   System.out.println("item"+i+++" - "+name);  

  //sorting int array 'intNumbers'
  Arrays.sort(intNumbers);    

  i=1;
  System.out.println("After sorting int array");
  for(int num:intNumbers)
   System.out.println("item"+i+++" - "+num);   

  //sorting double array 'doubleNumbers'
  Arrays.sort(doubleNumbers);    

  i=1;
  System.out.println("After sorting double array");
  for(double num:doubleNumbers)
   System.out.println("item"+i+++" - "+num);  

 }
}

Output for this code will be like this.

After sorting String array
item1 - Anuradha
item2 - Isuru
item3 - Nimal
item4 - Sunil
item5 - Tharaka
After sorting int array
item1 - 1
item2 - 3
item3 - 5
item4 - 7
item5 - 9
item6 - 12
After sorting double array
item1 - 2.34
item2 - 4.23
item3 - 4.76
item4 - 8.32
item5 - 45.213

This Arrays.sort() method support not only for String, int and double arrays but also for byte, char, long, float and object arrays

Sorting strings using java Collections

In this tutorial Lets see how to sort collection of Strings in alphabetical order in a very simple way. We use java Collections for that.

Here is the coding example.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

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

  List<String> names = new ArrayList<String>();  

  names.add("Nimal");
  names.add("Sunil");
  names.add("Tharaka");
  names.add("Isuru");
  names.add("Suresh");
  names.add("Anuradha");
  names.add("Thilak");  

  Collections.sort(names);  

  int i=1;
  for(String name:names)
   System.out.println("item "+i+++" "+name);
 }
}

Output for this code will be like this.


item 1 Anuradha
item 2 Isuru
item 3 Nimal
item 4 Sunil
item 5 Suresh
item 6 Tharaka
item 7 Thilak


Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...