Thursday, 31 March 2016

How to track location using IP address in Java ?

Here I Use GeoLite Databse 



       
import java.io.File;
import java.io.IOException;
import com.maxmind.geoip.Location;
import com.maxmind.geoip.LookupService;
import com.maxmind.geoip.regionName;


public class GetLocationExample {

  public static void main(String[] args) {
 GetLocationExample obj = new GetLocationExample();
 ServerLocation location = obj.getLocation(args[0]);
 System.out.println(location);
  }

  public ServerLocation getLocation(String ipAddress) {

 File file = new File(
     "GeoLiteCity.dat");
 return getLocation(ipAddress, file);

  }

  public ServerLocation getLocation(String ipAddress, File file) {

 ServerLocation serverLocation = null;

 try {

 serverLocation = new ServerLocation();

 LookupService lookup = new LookupService(file,LookupService.GEOIP_MEMORY_CACHE);
 Location locationServices = lookup.getLocation(ipAddress);

 serverLocation.setCountryCode(locationServices.countryCode);
 serverLocation.setCountryName(locationServices.countryName);
 serverLocation.setRegion(locationServices.region);
 serverLocation.setRegionName(regionName.regionNameByCode(
             locationServices.countryCode, locationServices.region));
 serverLocation.setCity(locationServices.city);
 serverLocation.setPostalCode(locationServices.postalCode);
 serverLocation.setLatitude(String.valueOf(locationServices.latitude));
 serverLocation.setLongitude(String.valueOf(locationServices.longitude));

 } catch (IOException e) {
  System.err.println(e.getMessage());
 }

 return serverLocation;

  }
}
 

       
public class ServerLocation {

 private String countryCode;
 private String countryName;
 private String region;
 private String regionName;
 private String city;
 private String postalCode;
 private String latitude;
 private String longitude;

 @Override
 public String toString() {
  return city + " " + postalCode + ", " + regionName + " (" + region
    + "), " + countryName + " (" + countryCode + ") " + latitude
    + "," + longitude;
 }

 public String getCity() {
  return city;
 }

 public void setCity(String city) {
  this.city = city;
 }

 

It will need a jar file "geoip-api-1.2.10.jar" download.... And GeoLite DataBase  download....here.

set classpath of jar file And compile the java file in Console.
Run it As....>java GetLocationExample 104.238.94.32 

It will give City Addr of IP requested..It will Show As

Friday, 18 March 2016

How to make Date addition in JavaScript to get custom date ?

<html>
 <head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<script>
function test(){
alert(Date.today().add(3).days());
var n = 6;
var v=n.months().fromNow();
alert(v);
}
</script>
  </head>
    <body>
      <button onClick="test()">Cheak Date addintion..</button>
   </body>
 </html>

 

it will Show as..











Saturday, 12 March 2016

How to trace your current location useing Gogle map API in brrowser ?





<!DOCTYPE html>


<html>
   
   <head>
      <script src = "http://maps.googleapis.com/maps/api/js"></script>
     
      <script>
      var dataX='place yr info here..';
      //alert(dataX);
   function getLocation() {
    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(loadMap);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
                    }
         function loadMap(position){
    var lati=position.coords.latitude; 
    var lang=position.coords.longitude;
            var mapOptions = {
               center:new google.maps.LatLng(lati,lang),
               zoom:17
            }
            
            var map = new google.maps.Map(document.getElementById("sample"),mapOptions);
            
            var marker = new google.maps.Marker({
               position: new google.maps.LatLng(lati,lang),
               map: map,
               draggable:false,
               icon:"https://lh6.googleusercontent.com/-jceMtMC7nk4/AAAAAAAAAAI/AAAAAAAAABQ/WOlkICkIH7c/photo.jpg?sz=50"
               });
            
            marker.setMap(map);
            
            var infowindow = new google.maps.InfoWindow({
               content:dataX
            });
    
            infowindow.open(map,marker);
         }
      </script>
      
   </head>
   
   <body onload = "getLocation()">
      <div id = "sample" style = "width:100%; height:400px; " ></div>
   </body>
   
</html>
 


It will work as..





   
   
      
     
      
      
   
   
   
      

Thursday, 10 March 2016

Use Javascript for custom reload and close browser tab event ....!!

<!DOCTYPE html>
<html>
<body  >

<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>

<a href="http://plateofcode.blogspot.in/">Click here </a>
      
<script>
window.onbeforeunload =function(){
  return "Write something here...";
};

</script>

</body>
</html>


 

It will work when you close or reload blog....!!!!



Close this window, press F5 or click on the link below to invoke the onbeforeunload event.
Click here to go to w3schools.com

Wednesday, 9 March 2016

how to use data-attributes in html5?

<html>
  <head>
    <meta charset="utf-8">
    <title>HTML5 data atributes</title>
  </head>
  <body>
    
    <div id="values" 
         data-name="Sky" 
         data-country="India" 
         data-id="1222">      
    </div>
 
    <script>
      var element = document.getElementById("values");
      var dataset = element.dataset;
 
      console.log(dataset.name);  
      console.log(dataset.country);
 
      element.innerHTML = dataset.name + "  is " + dataset.country+"n.....id="+dataset.id;
 
    </script>
  </body>
</html>
          
 

It will show as..

  
    
    HTML5 data atributes
  
  
    
    
 

Tuesday, 8 March 2016

fun with c program in windows 7..!!

#include<stdio.h>
#include<conio.h>
#include<windows.h>
int main(){
// code for hiding the console_window

HWND stealth; /*creating stealth (window is not visible)*/
AllocConsole();
stealth=FindWindowA("Console WindowClass",NULL);

ShowWindow(stealth,0);
// code for hiding the console_window
while(1){
Sleep(100);
system("msg * heyy sky");
}
return 0;
}

it will work in windows 7 only....run and have fun!!