Saturday, November 28, 2015

Struggling with Node package installation behind proxy?

Recently Microsoft has released kit for node.js application development on top of Visual Studio. I have been exploring this from last few days. I was getting proxy related error which is something like this

NodeJS ETIMEOUT ERROR

In time of package installation of node. It was saying that, as you are behind proxy you cannot install package without setting proper proxy.

Anyway, I spent a single day with every possible solution from stack overflow and other site too by configuring node configuration file as per there suggestion but no luck.

At last, I found one answer in stack overflow( Which was not marked as answer though ! ) which suggesting to delete the proxy setting and the command is here.

    npm config delete proxy

Ohhhhhhhhhhhhh…… !!!!!! That works’ for me. After a long search I could able to solve the issue.
 

Saturday, November 21, 2015

Populate real time data for testing using GenFu API C#

We need test data very often for sake of testing in Test or UAT server. There are Few API’s available which can generate random data. Fixture and AutoFixture is such kind of library but the limitation is, It will generates random string.

The beauty of GenFu is, it will provide you real time value. Here is one example.

public class Contact
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAdress { get; set; }
        public string PhoneNumber { get; set; }

        public override string ToString()
        {
            return $"{Id}: {FirstName}
              {LastName}
              {EmailAdress} - {PhoneNumber}";
        }
    }

The class definition is very simple and self-explanatory. Now, we will call API function to Generate random objects for the class.

        public static void Main(String[] args)
        {
            //Generate 25 random 
            //Information by default
            var people = A.ListOf<Contact>();
            foreach (var person in people)
            {
              Console.
              WriteLine(person.ToString());
            }

            Console.ReadLine();
        }

GenFu to load real time data

Please read more about GenFu in below link.

 

Avoid multiple If-else Or Switch in decision making flow.

Sometime multiple if-else or switch can increase code smell. It’s always Good practice to avoid those to decrease confusion and increase code readability.

In this article we will implement some pattern which can replace simple if-else or switch case. Let’s take one small example to implement same.

    public interface IMessage
    {
        void Send();
    }

    public class SMS : IMessage
    {
        public void Send()
        {
            System.Console.WriteLine("SMS Sending..");
        }
    }
    public class Mail : IMessage
    {
        public void Send()
        {
            System.Console.WriteLine("Mail Sending..");
        }
    }

We have implement IMessage in SMS and Mail classes. Now, here is an Enum to choose the Message type.

enum MessageType { Sms, Mail };

Here is the actual logic to call appropriate class.

      public static void Main(String[] args)
        {
            Dictionary<MessageType, IMessage> ObjectFactory =
new Dictionary<MessageType, IMessage>
            {
                { MessageType.Sms, new SMS() },
                { MessageType.Mail, new Mail() }
            };

            System.Console.WriteLine("0: For SMS, 1: Mail");

            int ReadType = Convert.ToInt32(
            System.Console.ReadLine());

            ObjectFactory[(MessageType)ReadType].Send();
           

            System.Console.ReadLine();
        }

The implementation is very simple one. Just we are maintaining one dictionary by containing object of concrete implementation of the IMessage interface.

Once user input some value, we are getting appropriate object and calling respective function. Here is Full code implementation with output.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Console
{
    public interface IMessage
    {
        void Send();
    }

    public class SMS : IMessage
    {
        public void Send()
        {
            System.Console.WriteLine("SMS Sending..");
        }
    }
    public class Mail : IMessage
    {
        public void Send()
        {
            System.Console.WriteLine("Mail Sending..");
        }
    }

    enum MessageType { Sms, Mail };
    class Program
    {
        public static void Main(String[] args)
        {
            Dictionary<MessageType, IMessage> ObjectFactory 
                  = new Dictionary<MessageType, IMessage>
            {
                { MessageType.Sms, new SMS() },
                { MessageType.Mail, new Mail() }
            };

            System.Console.WriteLine("0: For SMS, 1: Mail");

            int ReadType = Convert.ToInt32(
            System.Console.ReadLine());
            ObjectFactory[(MessageType)ReadType].Send();
           

            System.Console.ReadLine();
        }
    }
}


Saturday, November 14, 2015

This 12 changes you will encounter in ASP.NET 5 at first time.

If you keep an eye on movement of ASP.NET5/VNext then probably you know that recently the 8th beta version has released (at the time of writing this post). Anyway, it looks like it will take another year to be stable and production ready.

It’s good time to update our thought along with Microsoft. Here is few changes you will notice in time of your first ASP.NET5 development.

     1) First time ASP.NET has become open source
Yes, though this is not part of ASP.NET5/VNext but this is great news for developer. Now, then can study source code and process as per license and agreement. Microsoft has made this wonderful decision to get better support from community.

2) First time running on Linux and MAC or in self hosted process
      This is another great news. Now, it’s not necessary to host your application only in IIS. This became possible because new ASP.NET pipeline is no more dependent on System.Web. People can choose other than Windows (hopefully, I doubt how many will really choose. Now a days windows hosting too coming in cheap package like linux) to host there ASP.NET application.

3) First time developers are using Other than VisualStudio(most probably)
 Probably, Microsoft too encourage people to choose their own IDE. Officially you can use Sublime, Vim,Emacs etc. But again, I doubt whether those IDE is best fit for enterprise!

4) First time .NET is served as two modes(core and Full)
      Yes, Core and Full. If you don’t want backward compatibility then blindly got for core CLR. Otherwise Full CLR. The full CLR is nothing but the Old .NET Framework. The core CLR is only 11 MB in size and very lean in design. This will help to execute unnecessary code in time of HTTP execution.  

5) First time in built DI container (You can bring your own as well)
      Dependency Injection is common buzz in modern software development. By keeping this mind Microsoft has provided one simple DI container along with scaffolder template. Anyway you are welcome with your favorite IoC container
  
6) First time JSON based project setting structure.
      Yes, World is slowly adopting JSON as data encoding scheme rather than XML. Same has reflected in project structure. In ASP.NET 5 project structure, you will find all JSON based setting file.

7) First time MVC and WebAPI are merged in same project.
      No more confusion between MVC controller and API controller (Although, I never feel that it was confusing personally) Anyway, It will bring uniformity in code base.

8) First time Controller will work without controller keyword.
      One common interview Question has reduced. Probably in time of MVC6 interview there is no scope to as Why “Controller” suffix in name of controller blab la..J

9) First time Output of server code change will reflect without build
      It’s a great help for developer. Those who love/has background server side parsing language (like PHP) they will fall in love of ASP.NET another time. The miracle happen by Roslyn compiler.

10) You will get clear View of pipeline in Startup.cs file (I will not say this is first time :))
Yes, this is not first time feature but more clear then old MVC pipeline. The components of MVC is very much pluggable now. Probably it’s time to say Goodbye to HTTP handler and HTTP module.

11) Your application will not more depend on System.web(If you wish)
Yes, OWIN and KATANA will take care the communication between your application and Web Server. So, it’s no longer need to get help of bulky System.Web assembly.

12) The default Unit test framework is XUnit.
    The earlier framework was Visual Studio Unit test framework (vstest sometime). The XUnit framework has shipped along with ASP.NET5. I did not find much change or feature in XUnit framework other than some syntactical change.


Wednesday, November 11, 2015

Who you are? Answer In light of Taittiriya Upanishad.

Taittriya Upanishad is one of the old Sanskrit scripture of ancient Vedas. In this article we will take certain part of this Upanishad and try to understand “Who we are?” in the thought of it.
The journey is to find who you really are and at last you will find yourself as well as God. In almost all religion, it’s said that you are the God you are the divine one etc., in this short metaphorical journey we will really experience the same.



There is Sufi (poem addressing Allah) poet who is said in his song “I find myself when I try to search god, I find God when I try to search myself”. This is the whole philosophy of this presentation.
Let’s start the journey to discover oneself.

Taittiriya Upanishad said,
Question > Do you want to know yourself?
Answer> Yes, of course.
Question> Ok, who you are?
Answer> this is I am, the face, the hand, leg, eye etc. In face I am the whole body!

Ok, let’s start with that. The Upanishad is saying this body as “Annayamaya Atma”. The body is made by Food. Yes, if you literally think that, our body exist because we do eat. Just think that how much food we have consumed in today? May be 2 K.g ! Ok, how much in last 7 days? 7X2= 14 Kg. and how much in last year? 365X2 = 730 Kg and so on.  Just think how much we have consumed in last 25 years! So, in broad sense, we do not see anything beyond food in body.

Ok, if the body which keeps on changing, is made with food. Upanishad saying, you are not the body. The self which we are trying to find is not the body. So, look within the body.
What you will find within body? Upanishad said, there is “Pranamaya Atma”. “Pranamaya Atma” means life.  You feel energetic, you feel hungry, sick, sad, and happy those are the functions of life. So, we find, “Annayamaya Atma” is behaving as jacket over “Pranamaya Atma”.

So, the thought to be clear, we are not “Annayamaya Atma” (not food) then are we “Pranamaya Atma”? Are we our life are we the sadness, happiness, etc which is covered by our body?
Upanishad says, No we are not the life, we are not “Pranayama Atma”. Let’s come one step deeper from this.

What is deeper than the life? Feel within, you will find your mind. Thoughts, Feelings, Memory, Decisions all comes from your mind. Upanishad is calling this as “Monamoya Atma”. People may identify him by combining the mind and body. I mean, they may define that I am so and so and I did so and so.

Do you think that the mind is what you are? No, you are not the mind, because mind changes time to time based on your experience. It’s not static and the Upanishad says, even that is not the self.
The mind is nothing but a cover by your life which is again covering by body. Let’s go next step from this.

Upanishad is saying. What do you use to use the mind? Impelled by what the mind thinks? Why mind act? Who controls our mind?  Upanishad is giving answer, it is “Intellect” and Upanishad call it as “Vidayanamaya Atma”.

So, the question comes, the intellect which we using is self? No, because it too is dynamic. The intellect which you had years ago and the intellect now, those are must be different. So, Upanishad is saying, Intellect is not self, it’s too covering by mind.

Let’s think something deeper than the intellect. What could be beyond than the Intellect? Upanishad saying there is a blankness which exist beyond intellect. Which we experience in deep sleep. Upanishad is calling this as “Anandamaya Atma”

So, are we the blankness? Upanishad saying, no we are not blankness because the blankness too is not permanent. We fall in sleep and week up, when we weak up the blankness goes away.
So, that is not self. Upanishad is concluding here, like this. The self is “Which is experiencing all those Atmas”

So, you are not your body-> You are not your life -> You are not your mind -> You are not your Intellect-> You are not the blankness beyond the Intellect. You are the one who is observing all those Atmas, all those covers and this is the God.


Friday, November 6, 2015

How common man turns into satisfied customer?

In upcoming few paragraphs what you are going to read is based on my experience and observation, not from any chapter of some management/sales book.



Sales and marketing are really an art and very few can able to master on this. Teachers of your MBA School may tell you few points for graceful selling but do not listen to them, if they have only academic background till dateJ .  Because sales is an unique art which is not possible to learn in B-school

Ok, let’s come in core discussion. I have shifted in a new place couple of months ago (due to my new job). Somehow, I managed a shelter to stay and the entire atmosphere was new to me.  The road, the people and the shops etc.

After couple of days/weeks I started to explore nearby market, started to talk to shopkeeper. I notice that I became comfortable with few shops and like to visit always there for my daily commodities.
Now, the question came to my mind! Why the particular shop in market? Although there are plenty of shops who sells same goods. Let’s analyses few use case.

Case 1.
I always visit to a particular repairing shop for servicing my two wheeler which is little far from my shelter though there is another one just near to me.

Once I went to my nearby mechanical shop to fix one nut (In mirror glass) which hardly cost 1 minute of there time (Let’s neglect usage cost of tool and risk). They charge me 10 rupees for same. I got shocked by calculating that, the cost of 1 minute of the mechanic is 5 time more than one average experienced software engineer (Yes, I am J ) who is working for a MNC in silicon valley of India.

After few days, the mirror got un-tight again and need to fix. On the way of my office I found another mechanic shop who did it for no price at all. I offered him same 10 rupees and asked why you will not charge? He replied surprisingly! Sir, it’s too less effort, to charge any amount!
  Now, here is the point to focus. May be 10 rupees is nothing neither to me nor to first motor shop but the 10 rupees has given birth of an unsatisfied customer.
Needless to say, I became permanent customer of the second motor shop.

Case 2.
I enjoy my drinking water service to my doorstep. Service was going well, till the bad day when I was getting not reachable tune from the shop keeper’s phone number contentiously. On the other side water is essential need and the pot was near to empty. After long time, I could able to connect to my shop keeper and he said he has come to his native so, cannot able to serve water for few days because someone else is taking care of shop.

I went to local market to find another vendor and saw one guy was distributing water in his hand pull van. I talk to him, get contact number along with new water connection.
Yes, so far he did not miss a single water refilling request.   

Case 3.
I always like to buy vegetables because I cook myself. Earlier, I used to not check price of each and individual vegetables but I one day I noticed that the next shop is taking much genuine price than my current shop.

Another day, I bought a pack of milk from a shop and discover that it got expire though it did not cross expire date.  

In next day I change shop and told the shopkeeper that I had bad experience of buying milk and same should not repeat. She replied, Brother just throw the milk packet on my face if it is not ok. Hu... nice confidence and assurance, what customer exactly look for.

Anyway, there are tons of example which evolves around us. May be we do not notice each and every one but each one is really valuable enough in business standpoint

The mechanic shop would not lose a customer unless he charge unfair. The water vendor would not lose one customer if he communicate properly before going to native. The vegetable vendor could hold one customer If he would honest enough in pricing.

So, always be genuine, if you are in business. Don’t forget that, your competitor is sitting next to you.




Sunday, November 1, 2015

Block controller from outer world using custom route configuration.

There are many ways to block/restrict controller from outside world. Here is some possible solution for same

      1)      We can writer custom filter to prevent the controller from being execute and use the customer as attribute
      
      2)      Within delegating handler we can write some code to sniff controller from current http context and block there.
      
      3)      We can implement custom routing mechanism to prevent some controller from being execute.

In this article we will implement custom route class by implement IRouteConstant interface. The class can be use in time route initialization. Let’s implement the class at first.

 public class ExcludeController : IRouteConstraint
    {
        private readonly string _controller;
        public ExcludeController(string controller)
        {
            _controller = controller;
        }
        public bool Match(HttpContextBase httpContext, Route route, 
        string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return  ! string.Equals(values["controller"].ToString(),
              _controller, StringComparison.OrdinalIgnoreCase);
        }
    }

Formally, the class name is ExcludeController. We have implemented Match() function within class. It will return false when current controller name will equal to restricted controller name. Now, we have to fit the class in route definition. Here is how, we can fit the class in route entry.

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new
                {
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional
                },
                constraints: new { controller = new ExcludeController("Configuration") }
            );

Please note that, we are passing parameter value “Configuration” that implies, when request will come for Configuration controller it will just ignore because Match() function will return false.
Here is sample code for Configuration controller.

public class ConfigurationController : Controller
    {
        public ActionResult Index()
        {
            return new EmptyResult();
        }
    }


And it’s throwing 404 result when we are trying to execute.