In this tutorial, we are going to build 2 CRA projects and share components between them. The solution is to have a mono repository or monorepo built with Lerna and Yarn workspace.

Lerna and Yarn workspace are complementary tools to build monorepo. Lerna allows to execute npm scripts in package.json for all sub-projects. Yarn workspace allows to manage dependencies and reference types from other sub-projects.…

Read More

Mac optimises the scrolling experience based on system preferences.

Scroll setting to always

The default setting is “Automatically based on mouse or trackpad”. With the default setting, only when the user scrolls, he sees the scrollbar. Let’s say, the user has the “Always” setting turned out, he sees an ugly scrollbar like this.

Ugly scrollbar

Some CSS which used to work before don’t work well.…

Read More

I took a formal Mongo course by Stephen Grider on Udemy. I am very happy with the way Stephen teaches. It is slow. Very relevant and practical. I feel accomplished and satisfied after the course. I prepared a few interview questions on Mongo and Mongoose which are quite useful.

  1. How do you create a model with Mongoose?
  2. What is the difference between an embedded document and an associated document?
Read More

ASP.NET MVC is a presentation framework. MVC stands for Model-View-Controller. Model gives a notion that it is related to data access. However, it is just a data abstraction for the view. It can be thought of a ViewModel.

Apart from MVC, a large ASP.NET application deals with services. It also deals with data access. We need a good project structure. In the post, we build a simple Hello world project.…

Read More

Today, I had a chance to use Fisher Yates algorithm. Fisher Yates algorithm shuffles the items in a list.

Here is the problem statement:

Out of an array of N items, randomly pick K items where 0 < K < N.

My first naive solution of the problem was as follows:

IEnumerable<int> RandomSelect(int n, int k)
{
    var random = new Random();
    var set = new HashSet<int>();
    while(set.Count
Read More

Cross cutting concerns (wiki) are common architectural elements such as logging, instrumentation, caching and transactions. In this article, we will explain how we integrate these into our projects. The functional classes in our project may use logging or caching within their method. Or they may not know that these other classes exist. We will cover both scenarios.

Decorator pattern

Decorator pattern is an elegant solution to implement cross-cutting concerns.…

Read More

Dijkstra’s algorithm computes the shortest distance between two vertices in a graph. Vertices in a graph are connected by an edge with a positive length.

static int SingleSourceShortestPathForNonNegativeEdgeLength(Vertex v)
{
    int min = short.MaxValue;
    var crossingEdges = new MinHeap<short, short>(N);
    var minVertices = new bool[N]; 
    minVertices[v.Id - 1] = true;
    
    foreach (var outgoingEdge in v.OutgoingEdges)
    {
        // Use a Heapify operation!
Read More