www.20thingsilearned.com/
its also from google's product :)
Tuesday, February 28, 2012
Thursday, February 23, 2012
Google map pointed to current location
<pre>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: geolocation</title>
<link rel="stylesheet" href="css/html5demos.css">
<script src="js/h5utils.js"></script></head>
<body>
<section id="wrapper">
<header>
</header>
<meta name="viewport" content="width=620" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<article>
<p>Finding your location: <span id="status">checking...</span></p>
</article>
<script>
function success(position) {
var s = document.querySelector('#status');
if (s.className == 'success') {
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
return;
}
s.innerHTML = "";
s.className = 'success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"You are here!"
});
}
function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
</script>
</section>
<script src="js/prettify.packed.js"></script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
</pre>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: geolocation</title>
<link rel="stylesheet" href="css/html5demos.css">
<script src="js/h5utils.js"></script></head>
<body>
<section id="wrapper">
<header>
</header>
<meta name="viewport" content="width=620" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<article>
<p>Finding your location: <span id="status">checking...</span></p>
</article>
<script>
function success(position) {
var s = document.querySelector('#status');
if (s.className == 'success') {
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
return;
}
s.innerHTML = "";
s.className = 'success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"You are here!"
});
}
function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
</script>
</section>
<script src="js/prettify.packed.js"></script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
</pre>
Wednesday, February 22, 2012
Unzip a file using java
______________________________________________
Here i am giving the code to unzip a zip file
______________________________________________
import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class Unzipfl {
public static void main(String[] args) throws Exception {
String zipname = "wavw.zip"; //File name of zip archieve
File f = new File(zipname.split("\\.")[0]);
f.mkdir();
ZipFile zipFile = new ZipFile(zipname);
Enumeration enumeration = zipFile.entries();
while (enumeration.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
System.out.println("Unzipping: " + zipEntry.getName());
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
int size;
byte[] buffer = new byte[2048];
System.out.println("name ="+zipEntry.getName()+"zip file name "+zipname);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream((zipname.split("\\.")[0])+"\\"+zipEntry.getName()), buffer.length);
while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
bis.close();
}
}
}
Here i am giving the code to unzip a zip file
______________________________________________
import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class Unzipfl {
public static void main(String[] args) throws Exception {
String zipname = "wavw.zip"; //File name of zip archieve
File f = new File(zipname.split("\\.")[0]);
f.mkdir();
ZipFile zipFile = new ZipFile(zipname);
Enumeration enumeration = zipFile.entries();
while (enumeration.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
System.out.println("Unzipping: " + zipEntry.getName());
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
int size;
byte[] buffer = new byte[2048];
System.out.println("name ="+zipEntry.getName()+"zip file name "+zipname);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream((zipname.split("\\.")[0])+"\\"+zipEntry.getName()), buffer.length);
while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
bis.close();
}
}
}
Monday, February 20, 2012
Consume Json from url using jquery
This is my json structure
__________________________________________________________
{
"Data": [
{ "CurrentDistance": 8,
"Id": "78faf314-3a13-4496-b9d0-73f6737de6c5",
"IsOpen": false,
], "ErrorMessage": null, "Success": true
}
__________________________________________________________
Here is the html file to consume json using jquery
____________________________________________________________
____________________________________________________________
__________________________________________________________
{
"Data": [
{ "CurrentDistance": 8,
"Id": "78faf314-3a13-4496-b9d0-73f6737de6c5",
"IsOpen": false,
"Location":
{
"Address": "103 Dominion Road",
"Latitude": -36.871656,
"Longitude": 174.752011
},
"Name": "Champion Bakehouse"
}
], "ErrorMessage": null, "Success": true
}
__________________________________________________________
Here is the html file to consume json using jquery
____________________________________________________________
<!DOCTYPE html>
<html>
<head>
<style>img{ height: 100px; float: left; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="images">
</div>
<script>
function sn()
{
alert('@ sn() ');
$.getJSON("http://mYweBsite/Location.svc/GetNear?callback=?",
{
//parametres for json
format: 'jsonp',
latitude:-36.871641,
longitude:174.752108,
keyword:'Champion',
onlywithspecials:true
},
function(data) {
alert('heloo @ Function '+data);
$.each(data.Data, function(i,Data){
content = '<br/>Current Distance :' + Data.CurrentDistance + '';
content=content+'<br/> ID : '+Data.Id+'<br/>Address :'+Data.Location.Address;
content=content+'<br/>Name :'+Data.Name+'';
$(content).appendTo("#product_list");
});
});
}</script>
<div id="product_list"></div>
<input type="button" value="call fn " onClick="sn();"/>
</body>
</html>
____________________________________________________________
sample code for Upload file to Apache Jackrabbit
package rabbit;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.jcr.Repository;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.core.TransientRepository;
public class upload_rule
{
public static void main(String[] args) throws Exception
{
Repository repository = new TransientRepository();
// Code For Creating workspace in jackrabbit
//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("MyWorkSpace");
Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()),"MyWorkSpace");
try
{
//take the file as inputstream here i fetch from "E"drive and file name rules.xls from directory arunpaul
InputStream fileStream = new FileInputStream("E:\\arunpaulk\\rules.xls");
//creating a node to save file data here i create node named "test_data"
Node root = session.getRootNode().addNode("test_data");
// Store content
Node traffic = root.addNode("traffic_data");
Node info = traffic.addNode("trafficInfo_compulsory_rules");
info.addMixin(JcrConstants.MIX_VERSIONABLE); //to set versions
info.setProperty("jcr:content", fileStream);
System.out.println("DataSaved");
session.save();
String user = session.getUserID();
System.out.println("Your in WorkSpace : "+session.getWorkspace().getName());
System.out.println("You Logd in as "+user);
System.out.println("Data out :"+info.getProperty("jcr:content").getStream().read());
//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("eFerns");
/* String name = repository.getDescriptor(Repository.REP_NAME_DESC);
System.out.println("Logged in as " + user + " to a " + name + " repository.");
System.out.println(node.getPath());
*/
// System.out.println(info.getProperty("trafficInfo").getString());
System.out.println(info.getBaseVersion().getName()+": version Name");
System.out.println(info.getBaseVersion().getPath()+": path");
}
finally
{
session.logout();
}
}
}
import java.io.FileInputStream;
import java.io.InputStream;
import javax.jcr.Repository;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.core.TransientRepository;
public class upload_rule
{
public static void main(String[] args) throws Exception
{
Repository repository = new TransientRepository();
// Code For Creating workspace in jackrabbit
//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("MyWorkSpace");
Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()),"MyWorkSpace");
try
{
//take the file as inputstream here i fetch from "E"drive and file name rules.xls from directory arunpaul
InputStream fileStream = new FileInputStream("E:\\arunpaulk\\rules.xls");
//creating a node to save file data here i create node named "test_data"
Node root = session.getRootNode().addNode("test_data");
// Store content
Node traffic = root.addNode("traffic_data");
Node info = traffic.addNode("trafficInfo_compulsory_rules");
info.addMixin(JcrConstants.MIX_VERSIONABLE); //to set versions
info.setProperty("jcr:content", fileStream);
System.out.println("DataSaved");
session.save();
String user = session.getUserID();
System.out.println("Your in WorkSpace : "+session.getWorkspace().getName());
System.out.println("You Logd in as "+user);
System.out.println("Data out :"+info.getProperty("jcr:content").getStream().read());
//((org.apache.jackrabbit.core.WorkspaceImpl)workspace).createWorkspace("eFerns");
/* String name = repository.getDescriptor(Repository.REP_NAME_DESC);
System.out.println("Logged in as " + user + " to a " + name + " repository.");
System.out.println(node.getPath());
*/
// System.out.println(info.getProperty("trafficInfo").getString());
System.out.println(info.getBaseVersion().getName()+": version Name");
System.out.println(info.getBaseVersion().getPath()+": path");
}
finally
{
session.logout();
}
}
}
Convert GWT application to GXT sencha application
1.download eclipse helios form corresponding sites
2.go to help and choose install new software
3.go to code.google.com and select getting started check the prerequisites (Strict to the instruction manual)
4. then select setup for eclipse and copy paste the link to install software's http textbox
5.tick the hide box
6.press next button
7. next ----> accept the terms FINISH
8. check any prerequisites for gxt[ eclipse 6 and jdk 6 ( oct-2011 ) ].
9.Download the latest Ext GWT release (currently2.2.0).
http://www.sencha.com/products/gwt/download.php
10. wait for to complete the installing process in eclipse.
11.install the designer
12. Make userlib by using the downloaded gxt[ in that rename the file gxt2.22 as gxt and add that gxt jar file to user lib]
13.create a java project with gwt support. (Specify the path of Extracted(already downloaded file will extract to specific path in my case its c:\))
CREATE A PROJECT WITH GWT SUPPORT 2ND BUTTON BELOW THE FILE
GIVE PROJECT NAME------>NEXT--------->TICK THE CREATE TIC BOX ON TOP AND CHANGE THE NAME OF IMAGEVIEWER IF NECESSARY DONT FORGET CHOOSE GXT(EXT GWT)
14.copy all the files from [C:\gxt-2.2.5\resources] resources and paste it into war file of your project
15.Open the html file in war and add the following line in tag
16.OPen the xml file from client check this file is exsisting else add theis file
2.go to help and choose install new software
3.go to code.google.com and select getting started check the prerequisites (Strict to the instruction manual)
4. then select setup for eclipse and copy paste the link to install software's http textbox
5.tick the hide box
6.press next button
7. next ----> accept the terms FINISH
8. check any prerequisites for gxt[ eclipse 6 and jdk 6 ( oct-2011 ) ].
9.Download the latest Ext GWT release (currently2.2.0).
http://www.sencha.com/products/gwt/download.php
10. wait for to complete the installing process in eclipse.
11.install the designer
12. Make userlib by using the downloaded gxt[ in that rename the file gxt2.22 as gxt and add that gxt jar file to user lib]
13.create a java project with gwt support. (Specify the path of Extracted(already downloaded file will extract to specific path in my case its c:\))
CREATE A PROJECT WITH GWT SUPPORT 2ND BUTTON BELOW THE FILE
GIVE PROJECT NAME------>NEXT--------->TICK THE CREATE TIC BOX ON TOP AND CHANGE THE NAME OF IMAGEVIEWER IF NECESSARY DONT FORGET CHOOSE GXT(EXT GWT)
14.copy all the files from [C:\gxt-2.2.5\resources] resources and paste it into war file of your project
15.Open the html file in war and add the following line in tag
16.OPen the xml file from client check
Subscribe to:
Posts (Atom)