Posts

Writing a zip file on Google App engine

package com.lin.web.servlet; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.http.ByteArrayContent; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestFactory; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.cl...

Send POST request with JSON data on Google App Engine

Tag: Fusion Table Rest API, Send POST request with JSON data on Google App Engine 1) Create fusion table using post request on Google App Engine // postURL= "https://www.googleapis.com/fusiontables/v1/tables?access_token=**********" // access_token - Use Oauth2 for this public static String sendPostRequest(String postURL) throws Exception{         String responseStr=null;         //make POST request         String jsonContent = "{'name': 'newIndia','columns': [{'name': 'Species','type': 'STRING'}],'description': 'Insect Tracking Information.','isExportable': true}";         //String data = "{\"document\" : {\"_id\": \"" + id+ "\", \"context\":" + context +"}}";         URL url = new URL(postURL);         HttpURLConnection connection = (HttpURLConnection) url.openConnection();  ...

Best way to Format a Double value to nth Decimal places in Java

Best way to Format a Double value to nth Decimal places in Java ------------------------------------------------------------------ public static double getDoubleValue(String value,int digit){         if(value==null){             value="0";          }         double i=0;          try {              DecimalFormat digitformat = new DecimalFormat("#.##");              digitformat.setMaximumFractionDigits(digit);             return Double.valueOf(digitformat.format(Double.parseDouble(value)));                     } catch (NumberFormatException numberFormatExp) {         ...

Append option into a select using jquery

You can use jquery to append data from select from a array of data. See the java script function where you can pass the dataArray like dataArray=["A","B"] and elementId , means the id attribute of your select element; function appendDataToSelectDropDown(dataArray, elementId ){       if(dataArray !=null && dataArray.length>0){           $('#'+ elementId ).find('option').remove().end()             .append('<option value="-1">Select Creative Size</option>');           $.each(dataArray, function( index, value ) {                    $('#'+ elementId ).append(new Option(value, value));           });       }   }

Fusion table layer: data may be still loading

On hitting fusion table layer on Maps, it says data may be still loading Answer : Check your query syntex, new query syntex is as given below with an example (Non numeric fields must be enclosed with '' quotes) function fetchDataFromFusionTable(){    try{                            var fusionOptions = {                             query: {                 select: 'Geometry',                 //from: "1QTnVfSO-agR4ueOAVa-uUzYrmNwE4DQ6l0e22EA",                 from: "1Fhnl0uOC3Ol3rMHI5FQIiTDIP3gw7QbRjldvFgY",                 where: " 'Start_Da...

CSC Interview Question: how to find common elements between two collections

Solution: retainAll method do this.   public boolean retainAll (Collection<?> c) Example: public class Test {        public static void main(String [] args){          LinkedHashSet hs = new LinkedHashSet();           // add elements to the hash set           hs.add("B");           hs.add("A");           hs.add("D");           hs.add("E");           hs.add("C");           hs.add("F");           System.out.println(hs);                     LinkedHashSet hs2 = new LinkedHashSet();       ...

nth Highest salary

Find the Nth highest salary Solution: Common logic for all database is as... select t.name,t.salary from employee t   where N= (               select count(u.salary) from                   (select distinct salary from employee ) as u                   where t.salary<= u.salary        )