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





Saturday, October 13, 2018

ASP History

1996 - ASP
2002 - ASP.NET Web forms
2008 - ASP.NET MVC
2016 - ASP.NET Core MVC

Saturday, April 7, 2018

NodeJS

Basic Setup :

1. NPM
2. Node
3. MongoDB

NVM (Node Version Manager) : used for keeping multiple versions of NodeJS


NPM : Node Package Manager: a javascript package manager.

MongoDB: Document database which stores data in JSON format.
mLabs is cloud service for free sandbox  of MongoDB upto 500MB

MongoDB GUI:
Compass can be used.


To check the version of node:
node -v
mongo -v
npm -v


To Start the server for MongoDB:
mongod

Express

Express is a lightweight web application framework for Node.js, which provides us with a robust set of features for writing web apps. These features include such things as route handling, template engine integration and a middleware framework, which allows us to perform additional tasks on request and response objects.
 There is nothing you can do in Express that you couldn’t do in plain Node.js, but using Express means we don’t have to re-invent the wheel and reduces boilerplate. 

Nodemon:

nodemon is a convenience tool. It will watch the les in the directory it was started in, and if it detects any changes, it will automatically restart your Node application (meaning you don’t have to). In contrast to Express, nodemon is not something the app requires to function properly (it just aids us with development), so install it using:
npm install --save-dev nodemon



Pug is a  templating engine. Pug (formerly known as Jade)  




Angular JS - An introduction


AngularJS is a client-side MVC framework written in JavaScript. 

It runs in a web browser and greatly helps us (developers) to write modern, single-page, AJAX-style web applications.


It is a general purpose framework, but it shines when used to write CRUD (Create Read Update Delete) type web applications. 


AngularJS is a recent addition to the client-side MVC frameworks list. 

1. Dependency Injection
2. Strong focus on testability


It is Open source project by developed by Google INC. 

ng-app
ng-init
ng-model


The AngularJS team takes a very pragmatic approach to the whole family of MVC patterns, and declares that the framework is based on the MVW (model-view- whatever) 


Resources:
1. Source code : https://github.com/angular/angular.js
2. Community blog: https://blog.angularjs.org
3. Docs: https://docs.angularjs.org/tutorial
4. Code Samples: https://builtwith.angularjs.org
5. Youtube channel: https://www.youtube.com/user/angularjs

Everything you want to know about GIT

Git was created by Linus Torvalds the maker of Linux.

Bitkeeper was used by Linux system from 2002 - 2005 but Linus decided to write their own DVCS and hence the GIT was invented written in Pearl and C.

Installing Git on Windows: 
using msysgit http://msysgit.github.com

Installing on Mac
using Home Brew
   brew install git

if not using home brew, you can also download DMG package
http://git-scm.com/download/mac


To verify once git is installed, type the following command in Terminal to check the git version

git --version

Installing on Linux:
apt-get install git-core (Debian/Ubuntu)
yum install git-core (Fidora)


Git provides 3 different configuration stores:
1. System Level configuration

   git config --system
2. User level

git config --global

stored in user home directory with filename  ~/.gitconfig or c:\users\\.gitConfig

3. Repo level
   git config

stored in .git/config in each repo


Setting the Configuration

git config --global user.name
git config --global user.email
git config --global core.editor
git config --global help.autocorrect 1
git config --global color.ui auto
git config -global core.autocrlf true | false | input


git init


git status

git add

git add -u

git add -A

git commit -m 

git log

git diff

git diff Head~1















Communicating Microservices with gRPC

Interprocess communication is done by two styles;

1. REST (Representational State Transfer) : we send the resources back and forth and manipulate objects.
It is Resource focused.
Loosely coupled as get put delete methods allow to send information to the server.
Messages are text based.

2. RPC :
It is Action Focused.
Messages are birary based.

Background :
Google's internal protocol Stubby.