Thursday, January 21, 2016

Very Useful jQuery code examples

zoom element text on Mouse over 

Javascript Code:

<script type="text/javascript">
        $(document).ready(function () {
            var oldSize = parseFloat($("#ZOOM").css('font-size'));
            var newSize = oldSize * 2;
            $("#ZOOM").hover(
              function () {
                  $("#ZOOM").animate({ fontSizenewSize }, 200);
              },
              function () {
                  $("#ZOOM").animate({ fontSizeoldSize }, 200);
              }
           );
        });
    </script>
    <style type="text/css">
        #ZOOM
        {
        font-size:10pt;
        font-family:'Times New Roman';
        }
    </style>


Design.aspx:




Output:



zoom Image




Output:

disable spacebar


output:

to find out which key was pressed


Design:



Output:


Monday, December 14, 2015

More Information About Git.


If you want to find out the branches which you have created. Please follow the below steps
Go to Visual Studio (Git  ->Git Bash)






Type the below command as

git branch





Find out by author Name:
git log --author="AuthorName"
Example: git log --author="Uday Kumar"
Output: It will display all your commit id and branches which you created from beginning.
 


You can also use regular expressions to create more complex searches. For example, the following command searches for commits by either 
Vijay Bhasker or Krishna Chaitanya

git log --author="
Vijay Bhasker \| Krishna Chaitanya"
Note that the author’s email is also included with the author’s name, so you can use this option to search by email, too.
git branch -a    (shows both remote and local branches.)
git branch -r      shows remote branches



TO DELETE A COMMIT


If you commited one file in commit by mistake and want to delete that commit id (Assume GlobalDataConfiguration.config)
I have modified the GlobalDataConfiguration.config 

 
Now I click on save to commit this File.

Now I have commited the file.

 

Now I want to delete that Commit Id.
You can use the below command
 
git reset --hard HEAD~1
 
The HEAD~1 means the commit before head.
Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this:
git reset --hard <sha1-commit-id>
 
After deleting the commit id you can see that page is getting loaded.
 


Saturday, October 31, 2015

New Features of C sharp 6.0

 
1 Auto Property Initializer

Auto property is not the new feature but this was there from C sharp 3.0 onwards.

Drawbacks

We cannot initialize the backing field during object initialization, But you can initialize explicitly in constructors.

Example:

Description: Description: Description: Description: cid:image001.png@01D10EED.C4E40190

Output:

Description: Description: Description: Description: cid:image002.png@01D10EED.C4E40190

In the above example you can see FirstName and LastName were Auto - Implemented properties, and the values  initialized during constructor call.

But with C sharp 6.0


public class AutoPropertyInitializer
    {
        public string FirstName { get; set; } =  "Uday";
        public string LastName { get; } = "Kumar";
        //public string FullName { get; } = this.FirstName + this.LastName;
        public string FullName { get; }
        public AutoPropertyInitializer()
        {
            this.FullName = this.FirstName + " " + this.LastName;
        }
    }



The FirstName and LastName were initialized directly after the declaration. You can notice the LastName were made readonly by not mentioning the setter. The backing field produced for a readonly property is also a readonly variable.

The FullName though it is  initialized inside constructor as the object initialization works before the constructor call, and hence initialization cannot evaluate "this".


2 Static Class Uses:

If we want to print something we use Console.WriteLine. Why can I use only WriteLine ?  instead of Console.WriteLine. Static class uses does the same thing. Static class uses also recognize extension methods, hence if say a static class defines extension methods, if you add it, it will automatically recognize the extension methods as well.

But with C sharp 6.0

using static System.Console;
using static System.Linq.Enumerable;

    public class UseStatic
    {
        public void CallMe()
        {

            WriteLine("Hi");  //Console.WriteLine

            var range = Range(10, 10);   //From the namespace Linq.Enumerable
            var check = range.Where(e => e > 13);
            // Static extension method can
            // only be called with fulll representation
        }
    }


In the above code the WriteLine is automatically detected as we added the head using static statement. The static uses automatically recognized the extension methods as well.

If you look at the internals of the static uses, the compiler rewrites the static type calls on every occurrences of its method call.
Description: Description: Description: Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjviGjF3J34D3VZoA9qGx3mBb_YdJTkWecqY1MHPoHfZIiqZ9smJlCYkTxb0o6N9RmvQGX3IaMmvgxUxr-hqcsI7xY0QKUYsmq4VrKzH_vYy1C9tT_fRPVTUUTUlTVH65jLsakUKkv9pAg/s1600/08-03-2015+18-42-46.jpg
In the actual IL, you can see, the WriteLine is padded with its appropriate type Console and Range is also associated with Enumerable. The re-writing is done by the compiler.


3 Null conditional operators

For developers Enemy exception are NullReferenceException or "Object reference not set to instance of an object" is one of the most common exception. For this developer need to check the null value before calling any member functions. Null for compiler is unknown, and hence if you call a method on null, it will point nowhere and hence throws NullReferenceException and exists the stack.
Microsoft already introducted Null coalesce operator (??) or Conditional operators.
string name = (student == null? null : student.name);
In the first statement the student is checked with null and when it has student, it will only then evaluate the name.
 
string postalcode = (student == null? null : (student.address == null ? null : student.address.postalcode))
On the second statement, the student object is checked with null, then its address and then finally the postalcode is evaluated.

But with C sharp 6.0

string name = student?.name;
 
string postalcode = student?.address?. postalcode;

Here code is reduced but the actual logic remains the same. The ? mark is used for null conditioning. Null conditional operators does not exists as well, it is the same representation as that of the previous conditional operators.

Note: You can see the null conditional operators are replaced by the compiler with normal conditional statements.

4 Exception Filters

In C# the exception block contains try/catch/finally with multiple catch blocks supported. Based on type of the exception that has been encountered during runtime, the runtime chooses the appropriate catch block to execute.
But with C sharp 6.0
Exception filters it allows  you to filter out the catch blocks to ensure which catch block can handle the exception. With exception filters in place, there could be multiple catch blocks with same type where the type determines which filter it will call first.

Let us take a look at the code :
public class ExceptionFilters
    {
        public static bool LogException(Exception ex)
        {
            //Log
            return false;
        }
        public static bool LogAgainException(Exception ex)
        {
            //Log
            return true;
        }
        public void CallMe()
        {
            try
            {
                throw new ArgumentException("Exception");
            }
            catch (Exception ex) when (LogException(ex))
            {
                //Keep exception stack intact
            }
            catch(Exception ex) when (LogAgainException(ex))
            {
                // Calling the catch
            }
            
        }
    }

Here the ArgumentException is thrown when CallMe is invoked. So the execution is like, it will call LogException method, executes the code and see whether the return statement is true or false. If it is true, it executes the catch block and exit, or otherwise it move and call LogAgainException method.

The exception filter expects a boolean value, hence the call to LogException should be a method returning bool.

5 nameof Operator
But with C sharp 6.0


Here the compiler determines the name of a Property, Function or an Extension method and writes it directly in compiled output. For instance,
string name1 = nameof(this.MyProp); // evaluates MyProp
string name2 = nameof(DateTime.Now);//evaluates Now
string name3 = nameof(Console.WriteLine); //evaluates WriteLine
string name4 = nameof(new List<string>().FirstOrDefault); // Evaluates FirstOrDefault
string name5 = nameof(name4); //Evaluates name4
 
The nameof operator works on any type where the type has a name. In case you specify a variable, the nameof operator will evaluate to the name of the variable.
6 Dictionary initializers
var dict = new Dictionary<int,string>();
dict.Add(0, "Uday");
dict.Add(1, "Kumar");
 
//Access
var first = dict[0];
var second = dict[1];

In C# 6.0, you can define dictionary using the following syntax :

var dict = new Dictionary<int,string>
{
   [10] = "Uday",
   [20] = "Kumar"
};
 
//Access
var first = dict[10];
var second = dict[20];

Or even if the key is declared as string, you can also use like:
var dict = new Dictionary<string,string>
{
   ["first"] = "uday",
   ["second"] = "Kumar"
};
 
//Access
var first = dict["first"];
var second = dict["second"];

This way it is very easier to declare and use dictionaries. The last two syntaxes were introduced in C# 6.0.


Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...