Google autocomplete suggestion give you popular searches for your typed word. Here I search about different programming languages and frameworks. See what Google suggested me.
Some suggestion are really nice but some are.... see.
public Singleton
{
private Singleton()
{
}
}
public Singleton
{
private Singleton()
{
}
public static Singleton GetSingletonInstance()
{
return new Singleton();
}
}
public Singleton
{
//private static variable to hold the instance
private static Singleton _uniqueInstance = null;
//private constructor can only be call within class
private Singleton(){}
//static function to get same instance always
public static Singleton GetSingletonInstance()
{
if(_uniqueInstance == null)
{
_uniqueInstance = new Singleton();
}
return _uniqueInstance ;
}
//other required class methods
}
public Singleton
{
//private static variable to hold the instance
private static Singleton _uniqueInstance = null;
private static readonly object lockObject = new object();
//private constructor can only be call within class
private Singleton(){}
//static function to get same instance always
public static Singleton GetSingletonInstance()
{
lock(lockObject)
{
if(_uniqueInstance == null)
{
_uniqueInstance = new Singleton();
}
return _uniqueInstance ;
}
}
//other required class methods
}
public Singleton
{
//private static variable with initialize instance
private static Singleton _uniqueInstance = new Singleton();
//private constructor can only be call within class
private Singleton(){}
//static function to get same instance always
public static Singleton GetSingletonInstance()
{
//as we already initialize the static instance so just return it
return _uniqueInstance;
}
//other required class methods
}
public Singleton
{
//private static variable to hold the instance
private static Singleton _uniqueInstance = null;
private static readonly object lockObject = new object();
//private constructor can only be call within class
private Singleton(){}
//static function to get same instance always
public static Singleton GetSingletonInstance()
{
if(_uniqueInstance == null)
{
//if _uniqueInstance is null then lock
lock(lockObject)
{
//recheck here bcos if second thread is in queue it will get it false
if(_uniqueInstance == null)
{
_uniqueInstance = new Singleton();
}
}
}
return _uniqueInstance ;
}
//other required class methods
}
Dashboard
$scope.redirectToDraftPage= function () {
$location.path('/draft');
};
(function(){
'use strict';
function ngRedirectTo($window) {
return {
restrict: 'A',
link: function(scope, element, attributes) {
element.bind('click', function (event) {
//assign ng-Redirect-To attribute value to location
$window.location.href = attributes.ngRedirectTo;
});
}
};
}
angular.module('app').directive('ngRedirectTo', ngRedirectTo);
//inject $window service for redirection
redirectTo.$inject = ['$window'];
}());
Dashboard
// Simple GET request example
$http.get('/api/url').
success(function(data, status, headers, config) {
// asynchronous callback event will be trigger
// when the call to URL is successful.
}).
error(function(data, status, headers, config) {
// asynchronous callback event will be trigger
// when en error occurred calling URL or server returns
// response with error status.
});
post call using $http service:// Simple POST request example
$http.post('/api/url', {data:'hello! Its post call data!'}).
success(function(data, status, headers, config) {
// asynchronous callback event will be trigger
// when the call to URL is successful.
}).
error(function(data, status, headers, config) {
// asynchronous callback event will be trigger
// when en error occurred calling URL or server returns
// response with error status.
});
// Interceptor example for angularJs.
angular.module('app').factory('customInterceptor', ['$q', function($q) {
var myInterceptor = {
request : request,
requestError : requestError,
response : response,
responseError : responseError
};
// On request success
request: function (config) {
// Contains the data about the request before it is sent.
console.log(config);
// Return the config or wrap it in a promise if blank.
return config || $q.when(config);
};
// On request failure
requestError: function (rejection) {
// Contains the data about the error on the request.
console.log(rejection);
// Return the promise rejection.
return $q.reject(rejection);
};
// On response success
response: function (response) {
// Contains the data from the response.
console.log(response);
// Return the response or promise.
return response || $q.when(response);
};
// On response failture
responseError: function (rejection) {
// Contains the data about the error.
console.log(rejection);
// Return the promise rejection.
return $q.reject(rejection);
};
return myInterceptor;
}]);
and then register it to $httpProvider interceptor array.angular.module('app').config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('customInterceptor');
}]);
angular.module('app').factory('authTokenInjector', ['authenticationService', function(AuthenticationService) {
var authTokenInjector = {
request: function(config) {
if (!AuthenticationService.isAnonymus) {
config.headers['x-session-token'] = AuthenticationService.securityToken;
}
return config;
}
};
return authTokenInjector;
}]);
and html:
// Interceptor example for angularJs.
angular.module('app').factory('overlay', ['$q', function($q) {
//initialize counter
var requestCounter=0;
var myInterceptor = {
request : request,
requestError : requestError,
response : response,
responseError : responseError
};
// On request success
request: function (config) {
//will be incremented on each request
requestCounter++;
//show loader if not visible already
if(!$('#preloader').is(':visible')){
$('#preloader').show();
}
// Return the config or wrap it in a promise if blank.
//it is required to return else call will not work
return config || $q.when(config);
};
// On request failure
requestError: function (rejection) {
//decrement counter as request is failed
requestCounter--;
hideLoaderIfNoCall();
// Return the promise rejection.
return $q.reject(rejection);
};
// On response success
response: function (response) {
//decrement counter as request is failed
requestCounter--;
hideLoaderIfNoCall();
// Return the response or promise.
return response || $q.when(response);
};
// On response failture
responseError: function (rejection) {
//decrement counter as request is failed
requestCounter--;
hideLoaderIfNoCall();
// Return the promise rejection.
return $q.reject(rejection);
};
function hideLoaderIfNoCall(){
// check if counter is zero means
// no request is in process
// use triple equals see why http://goo.gl/2K4oTX
if(requestCounter === 0)
$('#preloader').hide();
}
return myInterceptor;
}]);
Please turn off the ad blocker. This is only way that we can earn some penny. Please support us by trun off the ad blocker.
Thank you!!