Thursday, November 29, 2018

What I learned today

1. MBA in 32 minutes :
https://www.youtube.com/watch?v=12eD3K5Peu8

2.
Born Renu Kujur, she was raised in a simple family in Delhi. Her father was a clerk in a government office and her mother worked as a domestic help.

3. Paresh Gupta
https://www.youtube.com/watch?v=GBkLzYZ1ZQM

Saturday, November 24, 2018

MVC 5

Questions/Answers:



1. MVC stands for : model view controller

2. Why you chose WebAPI?

3. What is the base class for creating a WebApi?

4. Can you do routing in WebApi like MVC?

5. Is it right that ASP.NET Web API has replaced WCF?

6. what is odata?

7. What are route constraints in MVC?

8. How to define a custom route constraint?

9. If you have Default route and a custom constraint in MVC RegisterRoutes, which one will override?
10. What is the role of IControllerFactory?
11.  What is the default routing format in MVC?
12. What is the default IHttpHandler in MVC?
13. 


MVC Routing:

Routing is a great feature of MVC, it provides a REST-based URL that is very easy to remember and improves page ranking in search engines. 
Routing table is stored in Global.asax.
Default routing pattern is {controller}/{action}/{id}

Route Constraints:

These are additional filters on the route that can restrict/limit the searches on the route handler. The best example to consider the usage of RouteConstraint is to allow route to only recognize integer parameters for actions. 








Thursday, November 15, 2018

Tips and Tricks for modern C# - Efficient coding

Tip 1. using Enumerable.Range - generate a sequence


Flavor 1:
var list = Enmerable.Range(1,10) .ToList();

This is equivalent to the following code:


List list = new List();
for(int i=1; i<=10; i++)
{
     list.Add(i);
}

Rather than writing 4 lines of code to generate a list of integers from 1 to 10, you can use Enumerable. Range.

Flavor 2
Another flavor of it is used in a situation when you need to iterate something for a fixed number of times:

for(int i=1; i<=10; i++)
{
    Print("My name is printed " +  i + " times");
}

This code can be replaced with following LINQ:

var list = Enumerable.Range(1,10).Select(item => "My name is printed " + item + " times").ToList();

AWESOME, isn't it?

Flavor 3:

Printing a table of 5:

var list = Enumerable.Range(1,10).Select(item =>  Console.WriteLn( (item*5).ToString()).ToList();

Flavour 4

In the following class House, there are rooms. Sat the situation is we want to print the room number against each room for all houses. 

Here is the class structure: 


class House
{
    public string Name { get; set; }
    public int Rooms;
}

    var houses = new List<House>
    {
        new House{Name = "Condo", Rooms = 3},
        new House{Name = "Villa", Rooms = 10}
    };


In simple words, For each house, iterate to all rooms of this house and print room number.
So the algorithm is something like :

For each house in Houses
    For j = 1 to house.Rooms.Count
          print house.Name + "room numer " + j
    EndFor
EndFor

Hence the simplest form of traditional code is :


var roomsIterate = new List();
    foreach (var h in houses)
    {
        for (int i = 1; i < h.Rooms + 1; i++)
        {
            roomsIterate.Add(h.Name + " room number " + i);
        }
    }
But we can also reduce these lines of code using LINQ and Lambda:

 var roomsLinq = houses.SelectMany(h => Enumerable.Range(1, h.Rooms).Select(i => h.Name + " room number " + i));

Flavor 5:

Enumerable.Range can be used to initialize the data class in a collection. For example:

List<House> houses = new List<House>();
for(int i = 0 i<=9 ; i++)
{
  houses.Add( new House());
}


This code can be boiled in LINQ as :

List<House> houses = new List<House>(Enumerable.Range(1, 10).Select(item => new House());
      



You can think about likeEnumerable.Range a tool of retrieving a subset of a collection.


Sunday, November 4, 2018

IOT fundamentals using Raspberry PI

IOT is a group of objects connected together through the internet. These objects are physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, actuators.

IOT enables dumb objects which are used in everyday life to interact over the internet. The term IoT is mainly used for devices that wouldn't usually be generally expected to have an internet connection, and that can communicate with the network independently of human action. For this reason, a PC isn't generally considered an IoT device and neither is a smartphone.

Kevin Ashton is the person behind the Internet of Things (IoT)

Ashton's latest project is a book which develops his ideas about innovation called How to Fly a Horse: the Secret History of Creation, Invention, and Discovery.



Hardware I purchased recently:
Raspberry pi 3 model B+
SenseHat