x This domain is for sale. If you intrested, Please contact : webspeckle@gmail.com

Sticky Footer Template for Bootstrap

Sticky footer is a fixed-height footer to the bottom of the viewport in desktop browsers. The purpose of a sticky footer is that it "sticks" to the bottom of the browser window. But not always, if there is enough content on the page to push the footer lower, it still does that. But if the content on the page is short, a sticky footer will still hang to the bottom of the browser window.

Sample code and demo is here

Demo

Add new properties to an object constructor in JavaScript

Add new properties to an object constructor in JavaScript

Suppose we have a function WebsiteData() and it has two parameters(title,description).

function WebsiteData(pageTitle, pageDescription) {
    this.title = pageTitle;
    this.description = pageDescription;
}
Add a new property 'keywords' to this function WebsiteData().
WebsiteData.prototype.keywords = "my website keywords";

Sample code and demo is here

Demo

Convert Array to string in Java

By using Arrays.toString() this method to covert Array to string in Java.

public static String toString(boolean[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(boolean). Returns "null" if a is null.

Parameters: a - the array whose string representation to return
Returns: a string representation of a

Search and get the postion of an element in jquery

index() is used for search for a given element from among the matched elements.

If no argument is passed to the .index() method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements.

If .index() is called on a collection of elements and a DOM element or jQuery object is passed in, .index() returns an integer indicating the position of the passed element relative to the original collection.

If a selector string is passed as an argument, .index() returns an integer indicating the position of the first element within the jQuery object relative to the elements matched by the selector. If the element is not found, .index() will return -1.

Eg:
<ul>
  <li id="foo">foo</li>
  <li id="bar">bar</li>
  <li id="baz">baz</li>
</ul>
var listItem = document.getElementById( "bar" );
console.log( "Index: " + $( "li" ).index( listItem ) );
We get back the zero-based position of the list item:

Index: 1

Sample code and demo is here

Demo

Load a JavaScript file dynamically

Load a JavaScript file dynamically using jQuery

jQuery.getScript()
Load a JavaScript file from the server using a GET HTTP request, then execute it.

Eg:
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});
By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():

$.ajaxSetup({
  cache: true
});
Sample code and demo

Demo

How to send HTTP request in spring boot?

If you need to call remote REST services from your application, you can use Spring Framework’s RestTemplate class. Since RestTemplate instances often need to be customized before being used, Spring Boot does not provide any single auto-configured RestTemplate bean. It does, however, auto-configure a RestTemplateBuilder which can be used to create RestTemplate instances when needed. The auto-configured RestTemplateBuilder will ensure that sensible HttpMessageConverters are applied to RestTemplate instances.

RestTemplateBuilder includes a number of useful methods that can be used to quickly configure a RestTemplate. For example, to add BASIC auth support you can use builder.basicAuthorization("user", "password").build().


Eg:
HttpResponse httpResponse;
HttpRequest httpRequest = new HttpRequest();
HttpRequest.setName("webspeckle.com");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<HttpRequest> entity = new HttpEntity<>(httpRequest,headers);

RestTemplate restTemplate = new RestTemplate();

try
{
    ResponseEntity<HttpResponse> responseEntity = restTemplate.exchange("REST_URL", HttpMethod.POST, entity, HttpResponse.class);
    httpResponse = responseEntity.getBody();
    //Success
}
catch(HttpStatusCodeException ex)
{
    //Error in REST request
}

Http status code quick reference

Status codes in the 100x range (from 100-199) are informational, and describe the processing for the request.

Status codes in the 200x range (from 200-299) indicate the action requested by the client was received, understood, accepted and processed successfully

Status codes in the 300x range (from 300-399) indicate that the client must take additional action to complete the request, such as following a redirect

Status codes in the 400x range (from 400-499) is intended for cases in which the client seems to have erred and must correct the request before continuing. The aforementioned 404 is an example of this.

Status codes in the 500x range (from 500-599) is intended for cases where the server failed to fulfill an apparently valid request.