JavaScript References

JavaScript Objects:

http://blog.pluralsight.com/understanding-javascript-objects-2

https://www.nczonline.net/blog/2012/10/16/does-javascript-need-classes/

JavaScript Prototypes explained :

http://blog.pluralsight.com/understanding-javascript-prototypes

http://sporto.github.io/blog/2013/02/22/a-plain-english-guide-to-javascript-prototypes/

https://javascriptweblog.wordpress.com/2010/06/07/understanding-javascript-prototypes/

http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/

Confusion with NULL values in SQL

Today I was working on a SQL query, and it took me a while before I figured out an issue.

A query goes something like this –  SELECT * FROM Table t1 where t1.UserId NOT IN ( SELECT UserId FROM Table t2 WHERE t2.Status = 1) WHERE Status = 2

Lets assume Status 1 = Active and Status 2 = Terminated and UserId can be NULL. There are few records in Table with UserIds Null for Status = 1. When i ran the query I was expecting few records to output but for some reason there are 0 records. After looking at the query carefully, i noticed that the inner query was returning NULL values and that ends being as below. It return NULL

SELECT * FROM Table t1 where t1.UserId NOT IN ( 1, 2, NULL) — Return 0 records although there are matching records with 1, 2

NULL can be dangerous enough to mess up the whole query and result set. So better handle NULL values properly.

 

Quotes –

“Often the answer is baked into the question you ask, so, if you don’t question the questions you’re asking you’re not going to come up with really innovative solutions.”

Glimpse – An Awesome tool to get a quick performance glimpse of your application

WebSite: http://getglimpse.com/

It is very easy to setup, there are different NuGet Packages of Glimpse. Depends on what your application is you can download MVC, Web Forms etc pacakges.

In Nutshell, just follow the below steps to get an glimpse for WebForms

1. Search for a NuGet Pkg – “Glimpse ASP .Net”

2. Select you web sites to get Glimpse downloaded. This is place your web.config would reside in and that’ s all Glimpse cares about.

3. Once you hit okay and download completes, you would notice that Glimpse would have modified your WebConfig to have its HTTP Handlers.

4. Go to your WebSite/Glimpse.axd (ex: http://Localhost/Glimpse.axd) to turn on the Glimpse profiling, and to turn off if it was turned on. This is it, by now your Glimpse would have setup to run.

5. Go to your web page, now you see a little grey icon with Glimpse symbol, just click on it so that it launches Browser tool bar like window with detailed information.

The cool thing about this tool is that it is available at your disposal right during the development of a particular page without making any context switch. How awesome is that 🙂

Puzzle #1

Puzzle: There are three boxes, first box contains Apples,  second box contains Oranges and the third box contains mix of both Apples and Oranges. Each box is wrongly labeled. You have got only once chance to open any box and pick up only one fruit without looking inside the box. The question is that which box would you choose to open and pick a single fruit so that you can tell what each box contains.

Answer: It is the boxed labeled with “Mixed Fruits”. The simple reason for this is when you pick up the box labeled with “Mixed Fruit”, either you could pick up Orange or Apple, and for sure this box would not have mixed fruits since the label must be wrong. So using these two facts we can conclude content of all the three boxes. If you happen to pick Apple, all the fruits must be apple in that box, and same thing for Orange, and the remaining two boxes must not contain what it is labeled, so the second box contains fruits labeled on third box and vice-versa.

I hope you liked the puzzle and the above answer is clear enough for you to understand.

How to return multiple values from a method in C#

As a developer how many times you may have wondered that wish I could return at least two values, instead of creating a object, from a method just the way we could return a single value.

Before, we jump into the solution, we can look at different ways we can return multiple values as we know currently.

  1. Create a class, and return the object of that class type.
  2. Pass the out parameters, and assign those variables in the method.
  3. Pass a ref object and assign the values in the method.
  4. Declare the Global variables (class level variables), and can be access anywhere.

Now the curiosity poses to know that what is the another way beside above options.

We can use Tuple keyword to achieve returning multiple values from the method as we see in the below example.

public static void Main(string[] args)
{
    int userId = 0;
    Tuple<string, string> userData = GetUserData(userId);
}

public static Tuple<string, string> GetUserData(int userId)
{
    return new Tuple<string, string>("Hello", "World");
}

The first question comes to our mind that we can as well create a class or struct and return it, but sometimes it is inconvenient to create class or struct all the time.

Link to Further reading