My Sites


Wednesday, June 17, 2015

Everyday jQuery

http://api.jquery.com/val/
$( document ).ready(function() {

});


$( "#myDiv" ).css( "border", "3px solid red" );

$("#txtEmail").val()

$("#txtEmail").val("something")


$('#some_id').on('change', function() {

  alert( this.value ); // or $(this).val()

});


var thisvalue = $(this).find("option:selected").text();

$("input[type='checkbox']").val();  or $('#check_id').val();


$( "#target" ).click(function() {
      alert( "Handler for .click() called." );
});

https://www.youtube.com/watch?v=G-POtu9J-m4&index=12&list=PLoYCgNOIyGAB_8_iq1cL8MVeun7cB6eNc
http://api.jquery.com/on/

$( "#dataTable tbody tr" ).on( "click", function() {
console.log( $( this ).text() );
});

$( "li" ).each(function( index ) {

  console.log( index + ": " + $( this ).text() );

});

Date object has list of dates
$.each(data.dates, function(index, element) {
    alert(element.timeStamp);
});


var markers = [{ "position": "128.3657142857143", "markerPosition": "7" },

               { "position": "235.1944023323615", "markerPosition": "19" },

               { "position": "42.5978231292517", "markerPosition": "-3" }];


$.ajax({

    type: "POST",

    url: "/webservices/PodcastService.asmx/CreateMarkers",

    // The key needs to match your method's input parameter (case-sensitive).

    data: JSON.stringify({ Markers: markers }),

    contentType: "application/json; charset=utf-8",

    dataType: "json",

    success: function(data){

           alert(data);

           $('#target').html(data.msg);

},

    failure: function(errMsg) {

        alert(errMsg);

    }

});


var  formData = "name=ravi&age=31";  //Name value Pair    or

var formData = {name:"ravi",age:"31"}; //Array



$.ajax({

    url : "AJAX_POST_URL",

    type: "POST",

    data : formData,

    success: function(data, textStatus, jqXHR)

    {  },

    error: function (jqXHR, textStatus, errorThrown)    {}

});


http://hayageek.com/jquery-ajax-post/


<input type="checkbox" name="checkboxname" value="check2"> check2
<input type="radio" name="r" value="radio1"> radio1


$(".tdBody").html(" ");
$( ".tdBody" ).append( "<input type=\"text\"/>" );
$('#editBtn').hide();






Tuesday, June 9, 2015

Android Material Design | User Delight | ViewPage slide

https://github.com/florent37/MaterialViewPager

http://stackoverflow.com/questions/18298590/first-time-user-guide-through-android-library

https://github.com/ongakuer/CircleIndicator

https://github.com/TaurusXi/GuideBackgroundColorAnimation

http://developer.android.com/training/animation/screen-slide.html

http://stackoverflow.com/questions/26954217/how-to-implement-first-launch-tutorial-like-android-lollipop-apps-like-sheets

https://android-arsenal.com/tag/111

Monday, June 8, 2015

Run a Junit Test suite with maven and Jenkins - Notes

maven project hierarchy
----------------------------------------
src/main/java
src/test/java

PortelloTestSuite.java

@RunWith(Suite.class)
@Suite.SuiteClasses({
   AuthenticateControllerTest.class,
   ClientControllerTest.class  })
public class PortelloTestSuite {}

AuthenticateControllerTest.java
    @Test
    public void authenticateTest() {
       assertEquals(200, response);  }

pom.xml
----------- 
<profiles>
        <profile>
            <id>Unit Test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/*PortelloTestSuite.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <type>jar</type>
            <scope>test</scope>
            <optional>true</optional>
</dependency>

Maven Run / Build Shell Command on Jenkins
------------------------------------------------------------
mvn test
 



Wednesday, June 3, 2015

Encode Decode fix

    String decodedURL= URLDecoder.decode(uri.toString());

How to extract word from string?

String str = "blabla http://www.mywebsite.com blabla";
String regex = "((https?:\\/\\/)?(www.)?(([a-zA-Z0-9-]){2,}\\.){1,4}([a-zA-Z]){2,6}(\\/([a-zA-Z-_/.0-9#:+?%=&;,]*)?)?)";
Matcher m = Pattern.compile(regex).matcher(str);
if (m.find()) {
    String url = m.group(); //value "http://www.mywebsite.com"
}
 
  try {
 sc2 = new Scanner(new File("src/main/resources/text.txt"));
                   while (sc2.hasNextLine()) {
            String line = sc2.nextLine();
            String clientString = StringUtils.substringBetween(line, "(", ")");
            System.out.println( i+ " "+clientString);
            i++;
      }      
} catch (FileNotFoundException e) {
 } 
 
 <dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-lang3</artifactId>
   <version>3.4</version>
 </dependency>
 

Thursday, May 28, 2015

Apache Http HttpClient

GET

 HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.dvd-shop.com/getDvd");
HttpResponse response = client.execute(request);

// Get the response
BufferedReader rd = new BufferedReader
  (new InputStreamReader(response.getEntity().getContent()));
   
String line = "";
while ((line = rd.readLine()) != null) {
  textView.append(line);
}

URI uri = new URIBuilder(ConfigurationTest.ADMIN_TOOLS_URL)
                    .addParameter("userID", ConfigurationTest.MLPUser.USERID)
                    .addParameter("time", "5")
                    .addParameter("type", ConfigurationTest.SYNC.ACTIVE_SYNC)
                    .addParameter("semisterId", "")
                    .addParameter("clientId",
                            ConfigurationTest.MLPUser.CLIENTID)
                    .addParameter("clientString",
                            ConfigurationTest.MLPUser.CLIENTSTRING).build();

HttpResponse response = client.execute(post);
ResponseHandler<String> handler = new BasicResponseHandler();
String body = handler.handleResponse(response);
JSONObject object = new JSONObject(body);

object.get("authValue").toString();

POST
 HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.dvd-shop.com/login");
    try {
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
      nameValuePairs.add(new BasicNameValuePair("registrationid",
          "20122"));
      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      HttpResponse response = client.execute(post);
      BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
      String line = "";
      while ((line = rd.readLine()) != null) {
        System.out.println(line);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

Wednesday, May 27, 2015

Basic HttpURLConnection /JSON parsing tutorial

http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
 (org.json-20120521.jar)
            String result = "";
            String url1 = "http://localhost:8080/getDVDList";
             URL url = new URL(url1);
          
            URL obj = url;
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // optional default is GET
            con.setRequestMethod("GET");

            //add request header
            con.setRequestProperty("User-Agent", "Mozilla/5.0");

            int responseCode = con.getResponseCode();
            System.out.println("\nSending 'GET' request to URL : " + url);
            System.out.println("Response Code : " + responseCode);

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            //print result
            result = response.toString();
            // Parse to get translated text



            JSONObject jsonObject = new JSONObject(result);
           JSONArray dvdList = jsonObject.getJSONArray("body");

                        List<Dvd> list = null;
                      
                        if(dvdList != null){
                                 list = new ArrayList<>();
                                 for(int i = 0; i < dvdList.length(); i++){
                                    JSONObject c = dvdList.getJSONObject(i);
                                    Dvd d = new Dvd(c.getInt("code"), c.getString("title"), c.getString("actors"), c.getInt("rating"),c.getString("definiiton"), c.getString("year"));
                                    list.add(d);
                             }

                        }
                       

 2.)

                JSONObject jsonObject = new JSONObject(result);
                int code = jsonObject.getJSONObject("responseCode").getInt("code");

                if (code == 201) {
                    errorLabel.setForeground(Color.BLACK);
                    errorLabel.setText("DVD Successfully Added.");
                } else {
                    errorLabel.setForeground(Color.RED);
                    errorLabel.setText("Adding DVD failed");
                }



3.)      String url1 = "http://localhost:8080/addDVD?title=" + URLEncoder.encode(title, "UTF-8").replace("+", "%20") + "&year=" + year + "&actors=" + URLEncoder.encode(actors, "UTF-8").replace("+", "%20") + "&ratings=" + ratings + "&definitions=" + definitions;
 

   con.setRequestProperty("Content-Type",
                        "application/x-www-form-urlencoded");
                con.setRequestProperty("Content-Language", "en-US");
                // optional default is GET
                con.setRequestMethod("POST");



 

 URLDecoder.decode (title);