Wednesday 6 July 2016

Object Pooling in Csharp


What is Object Pooling in Csharp ?

Object Pooling is Technique for Efficient Resource Allocation.A Performance Optimization Technique that is based on using Pool of Pre-Allocated Resources Such of Objects For Efficient Resource Allocation . It refers to Reusing of Allocated Memory again and again instead of demanding for more memory as there are chances that more required  memory may be not available at runtime (In Running Application) 

Why We Need Object Pooling & How It Works?

Have you Heard about Car Pooling ? Let me tell you about that . Car Pooling and Object Pooling is based on Same Concept . 

Both are based on Re-using / Proper Utilization of Resource . Instead of Having or using new Resource Each Time We Require . 

In Car Pooling We Use Same Resource Car for Multiple Person Instead of Using Car for Each Person . If 4 Person are going to office instead of going from their own car . Car Pooling Tells to Use one car For all 4 People That will save various Natural Resource and money .

Similarly In Object Pooling Memory is assigned to Program Execution and When more objects are required to initialized then instead of demanding and getting more memory resources it waits for previous memory block to get free to be used .

Didn't Got it Don't Worry See Below  


Real Time Example of Object Pooling  ?

Problem :
Let’s assume we are running an application which needs allocation of memory for its execution and this application is using Multithreading. This means more than one threads can allocate the same amount of memory simultaneously . 

Consider that the application needs 100K memory for its execution and there are 50 threads running simultaneously. All 50 threads will call a method of the application simultaneously.

All the threads will try to allocate 100000 bytes in the heap simultaneously. The OS may not get enough time to swap pages. Thus the application will be under heavy concurrent access, and the application may fail due to misleading memory management!

Solution :

WE can also create a pool of large Memory Block as much we can according to how much memory we require, at startup. That way, say we create 100 times 100K bytes in memory at startup. If it fails, well enough - we know that right at startup! So there is no surprise at runtime, when the application is live! So we can reduce that number to 75 (from 100) and try again to start our application. Once up and running, we know that there will be barely a need for it to allocate more memory at runtime, as we already have the memory for 75 or 100 arrays allocated. It just uses that as "an object pool", pulls from it, and when done, returns the byte arrays for subsequent use. Chances are that unless truly "concurrent", the already allocated byte arrays will be re-used over and over again, and at runtime, no extra memory will be allocated. If all 75 or 100 arrays are in use, and a 101st request comes in, it will need to allocate an additional memory of only one array - which is easy for the OS to manipulate in RAM.

Still Din't Got Don't Worry Feel Free! To Comment  

Tuesday 5 July 2016

Amazon : Buy Products With Amazon Echo



What Is Amazon Echo 


Amazon Echo is a voice-enabled wireless speaker developed by Ecommerce Giant Amazon (www.Amazon.com) . Echo is a  9.25-inch Device Structure is something looks like cylinder that contains speaker with a seven-piece microphone array. Amazon Echo Can also be called as "Alexa" . As It Responds to Words "Alexa" . We can also change this word to Amazon or Echo But Default One is Alexa .



Amazon Echo was initially limited to Use For aAmazon Prime members or by invitation, but became widely available in the USA on June 23, 2015

ORDER PRODUCTS WITH AMAZON ECHO 



We Can Order Products Like - 
User : Alexa , Show Me Levis Jeans

Amazon Echo is on the way to be best approach For Voice Driven Website In which websites will function by voice driven commands .

Amazon Echo Can also do voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic etc

At last Amazon has featured the Order from Amazon Echo it was most awaited thing expected from Amazon Echo . Amazon Has taken some time to implement this very useful feature, you know, Amazon.

How Amazon Echo Works

You Need to Say alexa the type of item you want to buy or name / brand of item . Example -

YouSay: Alexa order Sandisk Pendrive

Then Alexa with respond with Options for available brands and cost
Alexa : We Have 8GB Pendrive for $10 , 16 GB Pendrive for $18

You Say: Alexa Get Me 8GB Pendrive
Alexa : Thank you ! You Order is in Process



Monday 4 July 2016

Google Will Now Show Recent Earthquake Magnitude In Google Search



Google Is Expanding Like Amazon ( Amazon River ) . Its increasing its features like Water in Amazon River . One more Gold Star on Google Milestones is Now Google Will Give Information About Recent EarthQuake in your City / Area . It will give you information about When Earthquake occured and What was the Magnitude of Earthquiake Occured .

How To Search For Recent Earth Quake Information on Google Search


  • Open Google Search ( www..gogole.com )
  • Seach For "earthquakes near me"
  • Then the magic come and show you Shake Map showing Affected Areas of Recent Earthquake Near your Location .
  • That's not all It will also give you information about what you should do in this situation

Google Maps Road Trips Upgraded




Make Your Trips Navigable With Google Maps Now . Google Upgraded Google Maps . Upgrade Google Maps Now on Your Android Smartphones To Taste The latest Upgraded Road View for Google Maps .

New Update to Google Maps Will Now Allow you to Add Multi-Stop Directions Directions for All Your Trip Stoppages . You Can Easily Add Small Stoppages Between Source and Destinations of Trip

Latest Update also Allows you to Rearrange your Marked Stops , You Can drag & Drop Stops To Different Locations easily to rearrange your stops

Statement  By Sanket Gupta , Product Manager ( Google Maps ) -

“No matter where your travel plans take you this monsoon season and beyond, the new Google Maps features will get you there and help keep track of all the memories you make along the way,”


Updated Features are not Finished still , One more feature in this update is "TimeLine"

"Timeline" Allows You To Preserve Travel Memories . This This update comes right after hints of multi-destination navigation found in the Google Maps APK.

Saturday 2 July 2016

Google Changed Standard Plans for Using Google Maps .



Google no longer support keyless access (any request that doesn't include an API key). Now You must include API Key in your googleMap API Request .It includes all API Request like GoogleMaps Places , Autopicker , Google Maps Javascript API , Location Picker API .You can't Use Google Maps API without API Key generated for Google Maps . API keys allow us to contact developers when required and help us identify misbehaving implementations.

The new policies will apply immediately to all Maps API implementations created on or after June 22nd, 2016. 

There is one Restriction Came with This Update From Google .

Your Application Using GoogleMaps Can have 25,000 map loads per day free  to new Google Maps ( Updated As Per 22 June ) JavaScript API , Static Maps API, and Street View Image API implementations. 

So For very Large Websites You Need a Premium Plan License In order to Use Google Maps , Places , Google Maps Javascript API etc . 

Google have also reduced the daily map load maximum limit you can purchase for Google Maps JavaScript API, Static Maps API, and Street View Image API from 1,000,000 to 100,000 requests per API.

In order to gofor More Request than Standard Plan you need to go for a Premium Plan license, which includes technical support and a Service Level Agreement

Google now count Google Maps JavaScript API client-side requests towards the daily limit of the associated web service API.

Google Maps Standard Plan Policy Updates Summary


Google Announcement For changes to the Google Maps APIs authentication and usage limits:
http://googlegeodevelopers.blogspot.com.au/2016/06/building-for-scale-updates-to-google.html



Friday 3 June 2016

Difference Between MVC and webforms


The main advantages of The Official Microsoft ASP.NET Site MVC are:
  • Enables the full control over the rendered HTML.
  • Provides clean separation of concerns(SoC).
  • Enables Test Driven Development (TDD).
  • Easy integration with JavaScript frameworks.
  • Following the design of stateless nature of the web.
  • RESTful urls that enables SEO.
  • No ViewState and PostBack events
  • SEO friendly URL by design
  • No ViewState (this may seem a bit of moving backward to some), but overall a good design
    decision
  • Clean View Markup (no additional HTML emitted)
  • 100% extensible. You can add your own controller with IOC, switch view engines at will, control model binding at wish etc
  • Rich UI support (possible through client side JS libraries like jQuery UI and others)
  • Pluggable architecture
  • Out of the box minimal IOC support
  • Out of the box support for mitigating antiforgery attacks and XSS vulnerability
  • MVC is Faster by default because of lack of viewstate and clean markup. But performance is subject and MVC by design is more performant that traditional The Official Microsoft AspDotNet webforms
Limitation of MVC 
  • There is little Bit Long Learning Curve as compared to Asp.Net webforms 
The main advantage of Aspdotnet Web Form are:
  • It provides RAD development
  • Easy development model for developers those coming from winform development.

Difference Between MVC and webforms

Monday 23 May 2016

Abstract Class vs interface in Csharp


Abstract Class
Abstract Class is a class that is used as a base class and contains common methods that can be defined by class that inherits from this Base Class .  We can only inherit abstract class But We cannot instantiate Abstract Class . Abstrac classes contains both incomplete & complete methods . Means it can contains functions with definitions as well as abstract methods with only declarations . It can also contains Data Members along with subs , propreties and methods .

Interface :
Interfaces Contains only Declaration / Signature of Functions and does not contains definition of functions . Unlike Abstract classes Interfaces cannot contain complete methods or methods with definition it only contains signature of methods means only declarations
Interface also supports multiple inheritance that is not supported by Abstract classes

Difference Between Abstract Class and Interface -


Abstract Class
1. Abstract Class Can Contain Complete (functions with definitions) or Incomplete(Abstract) Members
2. Abstract Class cannot be instantiated
3. Abstract Class Can contain Data members
4. Abstract Class Can have Constructors . We Can Have Parameterized Constructors also in Abstract Class

Example :-
public abstract class ABC
{

int _a;
   
  //Parameterized Abstract Class Constructor
  public ABC(int a)
  {
    _a = a;

   }

  //Default Constructor
  public ABC()
  {
   // Code Logic

   }
public abstract void computeA(); };
public class Foo : ABC
{
    // Always pass 123 to the base class constructor
    public Foo() : base(123)
    {
    }
}
5. Incomplete members of Abstract class Means Abstract Members are Virtual Means it can be overridden by Derived Members
6. Abstract Members Cannot be Static
7. Complete Members Can be Static
8. Abstract Members can use Access Specifiers

All Private , Protected and Public Access Specifiers can be used with Abstract Class Methods . Purpose of Create Private Methods in Abstract Class is similar to normal class . These methods are used by other public methods of Abstract class as we know we can also define methods in abstract class.

Interface
1. Interface Can only Contain only Incomplete Methods that means methods with only Declaration without any definition
2. Interface cannot be Instantiated
3. Interface cannot contain data members
4. Interface cannot have constructors
5. there is no virtual member in interface as we cannot provide definition of member function in interface only inheriting class can define that function
6. Interace Cannot have Static Members
7. Complete Member does not exist in Interface
8. Interface member are public and we cannot set any access modifier to interface members

Sunday 22 May 2016

Difference Between Generic and Collections in C#


Difference Between Array - Generic - Collections in Csharp

Array :

An Array is Fixed Size Data Type . For Storing data in Array you need to define the size of array and Also Type of Array ( int, string , float etc )

Depending on Memory Allocation Data Types are of Two Types -

  • Value Type 
  • Reference Type 

See Difference Between Value Type and Reference Type in Link Below - 
http://geeksprogrammings.blogspot.in/2015/09/value-types-vs-reference-types-dotnet.html

Array is a Value Type that needs to define its size in order to allocate space to it in memory . This is little problem with array as sometimes we need Dynamic Size to store large number of values

Collections :
Collections are Defined in System.Collections Namespace . Collections Are Variable Sized . We Can add / remove items from collection with any restriction of defining size and type of data

Example :- Arraylist are Collections .

Logically Collections are Referency Types . Now Question is Why Collections are Referencec Types ?

Collections are of Variables Sized So Whenever Some Type is Variable Sized It needs to be stored in head instead of Memory Stack give to application . and poiter to that heap is set in the top of stack . it is stored in heap because main memory is valuable and we don't exactly know that How much size variable sized Collection will take so it is allocated disk space as heap instead of storing it directly in main memory Pointer to heap location is set to top of stack so whenever we require it we can use that pointer to get / set that value .

See Difference Between Value Type and Reference Type ( Stack & Heap ) in Link Below - 
http://geeksprogrammings.blogspot.in/2015/09/value-types-vs-reference-types-dotnet.html

Example of Collections - 

ArrayList arrList = new ArrayList();
arrList.Add(007);
arrList.Add("Heemanshu Bhalla");
arrList.Add(DateTime.Now);

If we want to loop that arrList then we can do it as below -

foreach (object o in arrList)
{

}

But there is one problem we always need to parse each element in collection using object as we don't know the type of data that it contains and that could create problem on runtime

Problem With Collections & Evolution of Generics

Generic Types Solves This problem check Generic Types Below  -

Generic Types :
Generic Types Contained in System.Collections.Generic Namespace . It removes the problem of Unknown Data types exist in Collections

Generic List ( List <T> ) , Here T means datatype that could be Int , String , DateTime etc . So We can define the type of data that we want to store and we can also parse the data simple as type is already known . SO it is Type Safe . If you Create Int Generic List or Generic Type and try to store some different type then it will give compilation Error and does not allow you to store data of Another Type that is not allowed .

Example of Generic List below - 

List<string> lstString = new List<string>();
lstString.Add("Heemanshu Bhalla");
lstString.Add("I am A Geek");

List<int> lstInt = new List<int>();
lstInt.Add(007);
lstInt.Add(786);

Saturday 21 May 2016

Convert Date Format To dd/mm/yy in Sql Server


If you Mssql Server is Using Some Other Date Format For Insert Date in Date Column Then Possibly Default Date format is set to US Date Format ( mm/dd/yy ) and if you want to insert date in dd/mm/yy . In order to insert date in this format you need to set Date Format to French / British ( dd/mm/yy )

So first I recommend you to Use any of Jquery Date Picker and pass the selected date / datetime as below to Insert Query as Below -

insert Table_Name (Date_Column)  values (convert(datetime,'18-06-12 10:34:09 PM',103));

Here second parameter 103 is For French Date Format dd/mm/yyyy .If you want to have dd/mm/yy then use 3 in that parameter

Different Types of Date Format Code as As Below - 

Without century (yy) (1)With century (yyyy)StandardInput/Output (3)
-0 or 100 (1,2)Default for datetime and smalldatetimemon dd yyyy hh:miAM (or PM)
1101U.S.1 = mm/dd/yy

101 = mm/dd/yyyy
2102ANSI2 = yy.mm.dd

102 = yyyy.mm.dd
3103British/French3 = dd/mm/yy

103 = dd/mm/yyyy
4104German4 = dd.mm.yy

104 = dd.mm.yyyy
5105Italian5 = dd-mm-yy

105 = dd-mm-yyyy
6106 (1)-6 = dd mon yy

106 = dd mon yyyy
7107 (1)-7 = Mon dd, yy

107 = Mon dd, yyyy
8108-hh:mi:ss
-9 or 109 (1,2)Default + millisecondsmon dd yyyy hh:mi:ss:mmmAM (or PM)
10110USA10 = mm-dd-yy

110 = mm-dd-yyyy
11111JAPAN11 = yy/mm/dd

111 = yyyy/mm/dd
12112ISO12 = yymmdd

112 = yyyymmdd
-13 or 113(1,2)Europe default + millisecondsdd mon yyyy hh:mi:ss:mmm(24h)
14114-hh:mi:ss:mmm(24h)
-20 or 120 (2)ODBC canonicalyyyy-mm-dd hh:mi:ss(24h)
-21 or 121 (2)ODBC canonical (with milliseconds) default for time, date, datetime2, and datetimeoffsetyyyy-mm-dd hh:mi:ss.mmm(24h)
-126 (4)ISO8601yyyy-mm-ddThh:mi:ss.mmm (no spaces)

Note: When the value for milliseconds (mmm) is 0, the millisecond value is not displayed. For example, the value '2012-11-07T18:26:20.000 is displayed as '2012-11-07T18:26:20'.
-127(6, 7)ISO8601 with time zone Z.yyyy-mm-ddThh:mi:ss.mmmZ (no spaces)

Note: When the value for milliseconds (mmm) is 0, the milliseconds value is not displayed. For example, the value '2012-11-07T18:26:20.000 is displayed as '2012-11-07T18:26:20'.
-130 (1,2)Hijri (5)dd mon yyyy hh:mi:ss:mmmAM

In this style, mon represents a multi-token Hijri unicode representation of the full month's name. This value will not render correctly on a default US installation of SSMS.
-131 (2)Hijri (5)dd/mm/yyyy hh:mi:ss:mmmAM

Evolution of Javascript To Jquery To AngularJS


Today’s starting programmers mostly directly dive into Jquery / angularjs , Programmers of last decade started with javascript . and Now Angularjs is on hike .

See whenever a WebPage is opened , JS / Jquery / AngularJS Code is on Client Side So Amount of Code is adds to Page will Increase Request Time .

We Use Javascript Before Jquery , Different types of Sliders , Dom Manipulations were done with lot of Javascript code like using But After Jquery We took a Relief for many things as below
Lines of Code Decides Lifeline of App as below -

Javascript -
Function changeBachground(color) {
  Document.body.style.background = color;
}
Onload=”changeBackground (‘red’);”

Jquery 
$ (‘body’) .css (‘background’, ‘#ccc’);

So Simple if we can achieve something easily with less code why we will not adopt it 
Then AngularJS Came that is a complete MVC Framework . It is also Javascript Framework . So whatever you do with AngularJS you can also achieve with Javascript . But Why you need to it start it from scratch you can join angularjs repository to propose some solid changes to it and extend it if you strongly need as doing everything you need to do in a website using javascript doesn’t look good idea .

JAVASCRIPT CODE

Characters: 700

Lines of JavaScript: 13
<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World with pure JavaScript</h1>
    Write some text in textbox:
    <input id="hello-input" type="text" />
    <h2 id="hello-output">Hello </h2>

    <script>
      var inputField = document.getElementById('hello-input');
      var label = document.getElementById('hello-output');

      var handleKeyup = function() {
        var value = inputField.value;
        label.innerHTML = 'Hello ' + value;
      }

      if (document.addEventListener) {
        document.addEventListener('keyup', handleKeyup);
      } else if (document.attachEvent) {
        document.attachEvent('keyup', handleKeyup);
      }
    </script>
  </body>
</html>

JQUERY

Characters: 529
Lines of JavaScript: 7
<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World with jQuery</h1>
    Write some text in textbox:
    <input id="hello-input" type="text" />
    <h2 id="hello-output">Hello </h2>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script>
      var inputField = $('#hello-input');
      var label = $('#hello-output');

      inputField.on('keyup', function() {
        var value = inputField.val();
        label.html('Hello ' + value);
      });
    </script>
  </body>
</html>

ANGULARJS

Characters: 325
Lines of JavaScript: 0
<!DOCTYPE html>
<html ng-app>
  <body>
    <h1>Hello World with AngularJS</h1>
    Write some text in textbox:
    <input type="text" ng-model="sometext" />
    <h2>Hello {{sometext}}</h2>

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
  </body>
</html>

Wednesday 18 May 2016

Namotel : Make In India Failed Again


The Story of Freedom 251 is not so old and Now Again Make In India Came With a New Crappy Thing "Namotel"  . We know Namo is rocking these days in Indian Politics But that does not mean its name works everywhere . If you are doing Shit then It will not come in different way if you say NAMO .

Namo + tel  = Website Crash

Namotel is another attempt of "Make In India" To Lauch & Offer Chepest SmartPhone . The Crappy game started by Freedom 251 gave to birth to another one . This Time SmartPhone is offered at Price of "Rs 99" It is claimed to be India's Most Affordable Smartphone

In Press Conference Company's Promoter Madhav Reddy Said Smartphone will be available to be booked at Price of Rs99 from 17 May,2016 To 25 may, 2016 On Company's Official Website Namotel . Smart Phone Will Be Available on Cash On Delivery

But I think they Don't Know How To Launch A Product To 1.252 Billion Indians . This Also Doubt About the Quality of Make In India Products That they are planning To launch and also Some That they launched .

Instead of Launching Cheap SmartPhone they should Use Their Talendted People To Make Valuable , Creative and Better Quality Product Atleast Better Than Freedom 251 or Nametel

Message By Comapany That Didn't Stood Up For Even 1 Day

 'Joy and freedom represents the logo! The same joy will flourish in billion Indians in the form of smart Connect with (3 different looks and shapes) Android Smart powerful Phone at 99. We make this product to show love for India it is a 'MAKE IN INDIA' Initiative. This model is limited and it is applicable only for India and who holds Aadhar Identity.'

Namotel Rs. 99 SmartPhone Product Specification


  • 4-inch display with 480x800 pixels WVGA resolution.
  • Android 5.1 Lollipop OS 
  • 1GB RAM. 
  • 4GB of internal storage which is expandable up to 32GB via microSD card.
  • 2MP camera at the back and a VGA selfie camera
  • Connectivity options include 3G and dual-SIM.
Different Namotel Products







COMPANY WEBSITE BELOW




Tuesday 17 May 2016

Tempdata vs Session in Asp.net MVC


Why Sessions are Not Recommended to use in MVC

One of the Fundamental Principal of Asp.Net MVC Framework is  Web is Stateless And AspDotNet MVC is Stateless AspDotnet WebForms is a try to make Stateful Modal But Its difficult to main it as this modal does not exist . Sessions Create lot of load on Cache that was biggest problem .

Using Session in AspDotNet MVC is like Putting APPLE Logo on Asus Laptop and Calling it Apple Laptop . Reality does not change .

What Is Alternative To Session in MVC

You can use TempData in place of Session . Tempdata is limited form of Session . Don’t Use Session in MVC as you are already having Tempdata and one benefit of Using Tempdata is They will automatically deleted no need to clear or remove them as we do with session

How To Use TempData In MVC

When Data is TempData is read it is immediately market for deletion at the end of request . That means you can use Value Tempdata In Tempdata Only at the Next Request . See Example Below - 

TempData is Filled With Data

TempData["SomeTemp"]= "Hey! This is MVC" ;

Tempdata Accessed in Second Request 

Object value = TempData["SomeTemp"] ;

Value in Tempdata will be Cleared After Above Line of Code . If you access in after that line of code after above line you will not found it there it will be deleted


Keep And Peek Methods 

Peek And keep methods are used to read value without marking it for deletion after reading its value . So it is acutally helping us to retain its after its first read instead of deleting tempdata

With Peek Method We get the value of Tempdata Without Marking it For Deletion . In this method we access the Tempdata value using Peek Method That tells it to Hold Value and does not mark it for deletion

With Keep Method we hold the Value of Tempdata that was marked for Deletion after its  first read . so it is using two different calls . First one is getting Tempdata Value then Second call is To Save Tempdata From Deletion