Let’s clarify what stable matching means with an example. Imagine we have two men and two women: Bob, Peter, Alice and Kate. Based on preference list we will try to match those couples.

Matching 1 is stable as Alice is Bob’s first choice and vice versa. Alice is also Peter’s first choice but Alice won’t leave Bob for Peter because she prefers Bob to Peter. Kate prefers Bob to Peter as well but Bob won’t leave Alice for Kate as he prefers Alice to Kate.

Matching 2 is not stable as Bob prefers Alice and Alice prefers Bob, so they will defect and chose each other so that Peter and Kate will remain stranded.

A stable matching is one that avoids such defects, this is called stability. In stable matching none of the matched candidate pairs wants to make a deal with each other and leave their assigned partners stranded.

This small scale of example shows that when we have equal number of candidates on each side with equal number of preferences the algorithm will generate a stable matching between all candidates and nobody will be left stranded. Lets’ explain how the algorithm works step by step, imagine we have the following couples each with their own preference list.

The men in the left side start to propose to women on the right side based on their preference list. Women on their side will either accept the proposal or reject it if they already have a better proposal from their preference list.

We complete the first iteration after all men try to make proposals to their first candidates in their lists. In the second iteration the men that don’ have any match and they still have left candidates on their lists try to propose to remaining candidates based on their priority.

After the second iteration we repeat the same step again.

At the end of third iteration we are on a situation where every man has a current match and no man can make a proposal to any women. The algorithm terminates either when every man has a match or the list of men’s candidates is exhausted.

Take into account that it is possible to have more than one stable matching and it is not guaranteed which one the algorithm will find.

One drawback of the algorithm is related to who benefits from the situation. Although the above example doesn’t show this case, the sides that make the proposals get their best candidates as possible from their preference list. On the other side the sides which are being proposed get their worst candidates as possible. So it matters who makes the proposals.

We will show a slightly different implementation which is object orientated. We will create a Candidate class with several methods required to implement the algorithm.

```
public class Candidate
{
private readonly List<Candidate> preferences;
private readonly string name;
public Candidate CurrentMatch { get; set; }
public Candidate(string name)
{
this.preferences = new List<Candidate>();
this.name = name;
}
public bool HasAnyPreferencesLeft()
{
return this.preferences.Any();
}
//Gets the first candidate from a not proposed candidates yet
public Candidate GetCandidateToPropose()
{
return preferences.FirstOrDefault();
}
public void AddPreferences(List<Candidate> preferenceList)
{
this.preferences.AddRange(preferenceList);
}
// Propose a match to a candidate
public void Propose(Candidate toCandidate)
{
// We can only propose if we haven't got a match already
if (CurrentMatch == null)
{
//Call receive proposal on the other candidate
toCandidate?.ReceiveProposal(this);
}
}
// Implement the logic for receiving proposal
public void ReceiveProposal(Candidate fromCandidate)
{
// I we don't have a match already accept the proposal
if (CurrentMatch == null)
{
this.AcceptProposal(fromCandidate);
}
else
{ // Check if the candidate sending the current proposal
// is not with higher priority in out preference list
if (preferences.IndexOf(fromCandidate) < preferences.IndexOf(this.CurrentMatch))
{
// So we have a better match then break the current match
CurrentMatch.BreakMatch(this);
// Accept the new proposal
this.AcceptProposal(fromCandidate);
}
else
{
// Reject the current proposal as we already have a better match
fromCandidate.BreakMatch(this);
}
}
}
public void AcceptProposal(Candidate fromCandidate)
{
// When a proposal is accepted link both candidates to each other
this.CurrentMatch = fromCandidate;
fromCandidate.CurrentMatch = this;
}
public void BreakMatch(Candidate fromCandidate)
{
// When breaking or rejecting a proposal then remove the candidate
// that broke or rejected the offer from list of preferences
this.preferences.Remove(fromCandidate);
this.CurrentMatch = null;
}
public override string ToString()
{
return this.name;
}
}
```

In the next step we will implement the algorithm and call it to find a stable matching for the example explained above.

```
class Program
{
static void Main(string[] args)
{
var bob = new Candidate("Bob");
var peter = new Candidate("Peter");
var alex = new Candidate("Alex");
var alice = new Candidate("Alice");
var kate = new Candidate("Kate");
var jane = new Candidate("Jane");
bob.AddPreferences(new List<Candidate> { alice, kate, jane });
peter.AddPreferences(new List<Candidate> { kate, alice, jane });
alex.AddPreferences(new List<Candidate> { alice, kate, jane });
kate.AddPreferences(new List<Candidate> { peter, bob, alex });
alice.AddPreferences(new List<Candidate> { bob, peter, alex });
jane.AddPreferences(new List<Candidate> { bob, peter, alex });
List<Candidate> men = new List<Candidate>
{
bob,
peter,
alex
};
List<Candidate> women = new List<Candidate>
{
alice,
kate,
jane
};
StableMatch(men);
PrintMatches(men);
}
private static void StableMatch(List<Candidate> candidates)
{
// execute the algorithm when there are candidates without matches
// and the candidate has items in his preference list
while (candidates.Any(c => c.HasAnyPreferencesLeft() && c.CurrentMatch == null))
{
foreach (var candidate in candidates)
{
candidate.Propose(candidate.GetCandidateToPropose());
}
}
}
private static void PrintMatches(List<Candidate> candidates)
{
foreach (var candidate in candidates)
{
Console.WriteLine($"{candidate} <---> {candidate.CurrentMatch}");
}
}
}
```

If we run the program above we will get the following result:

Bob <—> Alice

Peter <—> Kate

Alex <—> Jane

Time Complexity of Gale-Shapley Algorithm is O(n^{2})

You can read more about this algorithm here.

]]>- Take the input array and convert it to max heap by applying heapify operation on it.
- Take the root (first) element as it is the max element now and swap it with the last element in the array. Now the last element is the largest of all and it is in the correct place.
- Heapify the array again without already sorted elements at the end of the array because they are already in the correct position.
- Repeat steps 1 to 3 for all remaining elements in the unsorted imaginary sub array.

Let’s implement the steps explained above with a C# code.

First we will need a heapify method with which we are already familiar from our previous article.

```
private static void Heapify(int[] arr, int index, int length)
{
int largestInd = index;
int left = 2 * index + 1;
int right = 2 * index + 2;
if (left < length && arr[left] > arr[largestInd])
{
largestInd = left;
}
if (right < length && arr[right] > arr[largestInd])
{
largestInd = right;
}
if (largestInd != index)
{
var temp = arr[index];
arr[index] = arr[largestInd];
arr[largestInd] = temp;
Heapify(arr, largestInd, length);
}
}
```

With a help of this method we will implement HeapSort method

```
private static void HeapSort(int[] arr)
{
var n = arr.Length;
//First convert the array to max heap
for (int i = n / 2 - 1; i >= 0; i--)
{
Heapify(arr, i, n);
}
// Starting from the last element
// swap last and first element as the
// first element will be always the max element
// then reduce the index (array size)
for (int j = n-1; j >= 0; j--)
{
int temp = arr[j];
arr[j] = arr[0];
arr[0] = temp;
// Heapify the remaining elements
// pay attention to j index we pass to Hepify method
Heapify(arr, 0, j);
}
}
```

Let’s now test our heapsort method

```
static void Main(string[] args)
{
int[] arr = { 25, 10, 40, 1, 15 };
HeapSort(arr);
PrintArr(arr);
Console.ReadLine();
}
private static void PrintArr(int[] arr)
{
string space = "";
foreach (var i in arr)
{
Console.Write(space + i);
space = ",";
}
Console.WriteLine("\n");
}
```

And the output is:

1,10,15,25,40

HeapSort has a complexity of O(nlog n) in all cases and it has O(1) space complexity as it operates on the same array all the time.

]]>Dijkstra’s algorithm is a greedy algorithm which in each step finds the best solution and when we sum those solutions we find the best solution in general. The algorithm doesn’t work for edges with negative weights so in this case is used another algorithm which is called Bellman–Ford algorithm.

Let’s create an example weighted graph and explain how the algorithm works.

Let’s say we want to find the shortest path from vertex A to vertex F.

Initially we assign infinite value to all vertices as we don’t know the shortest distance to them. We assign 0 to starting vertex A as distance to self is 0.

We take the starting vertex A and we mark it as visited and then we observe all connected vertices and if the value of the visited vertex plus weight of the edge to the neighbor vertex is smaller than current value of the neighbor vertex then we update the neighbor vertex’s value with the weight of the edge plus value of the current visited vertex.

So in our example the value of A is 0 and the distance to B is 1.0. The current value of B is infinity.

**(0 + 1.0) < infinity, then we update the value of B to 1.0**

The value of A is 0 and the distance to C is 2.0. The current value of C is infinity.

**(0 + 2.0) < infinity, then we update the value of C to 2.0**

The next step is to chose which vertex to visit. The key point here is to take vertex with minimum value from unvisited vertices. In our case this is vertex B which has value 1.0 and it is less than the value of vertex C which is 2.0. From implementation point of view this is the point where we use priority queue. We enqueue vertices in a priority queue and then when we need the vertex with min value we just call dequeue and we get the minimum vertex.

So now we are on vertex B. We repeat the same operations here. We need to check the values of all **unvisited** neighbor vertices and update them if the current value + edge weight to neighbor vertex is smaller than neighbor vertex’s value. Be careful not to perform this operation to the visited neighbors.

So in our case B is connected to A and D. As A is already visited we will observe only D.

D’s current value is infinity, B’s current value is 1.0 and distance to D is 6.5.

**(1.0 + 6.5) < infinity, then we update the value of D to 7.5**

In the next step we take the vertex with min value from unvisited vertices. In our case this is vertex C

C (2.0) < D (7.5)

C has the following neighbors: A, E, D. From those neighbors only D and E are unvisited so we only observe them.

D has a value of 7.5. C has value of 2.0 and distance to D is 0.5.

**(2.0 + 0.5) < 7.5, then we update the value of D to 2.5**

E has value of infinity. C has value of 2.0 and the distance to E is 10.5

**(2.0 + 10.5) < infinity, then we update the value of E to 12.5**

In the next step we take the unvisited vertex with minimum value which is D.

D(2.5) < E(12.5)

D has the following neighbors: C, E, F. From those neighbors only E and F are unvisited so we only observe them.

E has value of 12.5. D has value of 2.5 and the distance to E is 2.0

**(2.5 + 2.0) < 12.5, then we update the value of E to 4.5**

F has value of infinity, D has value of 2.5 and the distance to F is 0.5

**(2.5 + 0.5) < infinity, then we update the value of F to 3.0**

Next we take the vertex with minimum value from unvisited vertices which is F.

F(3.0) < E(4.5)

F has two neighbors: D and E. From those neighbors only E is unvisited so we observe only E.

E has value of 4.5. D has value of 3.0 and the distance to E is 1.0

**(3.0 + 1.0) < 4.5, then we update the value of E to 4.0**

We have only one vertex which is unvisited, we visit vertex E. As all neighbors of E are already visited we are done with the algorithm at this stage. All vertices are visited and they have assigned values.

Note that in this graph example we had to always update the values of neighbor vertices but take into account if:

**(current vertex’s value + distance from current to neighbor) > neighbor’s value **

we don’t update the neighbor vertex’s value.

So looking into the initial graph where we applied Dijkstra’s algorithm we can say that the shortest path from A to F is: A–> C–> D–> F and the total distance is 3.0.

Let’s have a look how we can implement Dijkstra’s algorithm with C# code. We we will use a priority queue which we explained in one of the previous articles here https://paircoders.com/2021/04/19/heap-priority-queue/

First we will create a Vertex class which will represent our vertices in the graph described above

```
public class Vertex : IComparable<Vertex>
{
// We could have defined Vertex<T>
// as generic to store any data inside
// it, as you would probably do in
// real world, here we miss it for
// simplicity
//public T Value { get; set; }
public string Name { get; set; }
public decimal Weight { get; set; }
public bool IsVisited { get; set; }
public Vertex Parent { get; set; }
public Vertex(string name)
{
this.Name = name;
}
public int CompareTo(Vertex other)
{
if (this.Weight < other.Weight)
return -1;
else if (this.Weight > other.Weight)
return 1;
else return 0;
}
}
```

We will keep a reference to the parent which last updated the current vertex’s value in order to be able to backtrack the shortest path for any given vertex.

Next we will create class Dijkstra

```
public class Dijkstra
{
private List<Vertex> vertices;
private decimal[][] adjMatrix;
public Dijkstra(decimal[][] graph, List<Vertex> vertices)
{
if (graph.Length != vertices.Count)
{
throw new InvalidOperationException("Mismatch between graph and vertices");
}
this.adjMatrix = graph;
this.vertices = vertices;
}
}
```

We use adjacency matrix to represent the graph, basically the two most popular approaches to represent a graph are adjacency matrix and adjacency list, you can learn more about this topic here https://www.geeksforgeeks.org/graph-and-its-representations/

Next we will add a method to Dijkstra class called ApplyDijkstra which will apply the algorithm.

```
private void ApplyDijkstra(int source)
{
PriorityQueue<Vertex> pq =
new PriorityQueue<Vertex>(PriroityQueueType.Min);
// Initialize all vertices with infinite value
foreach (var v in this.vertices)
{
v.Weight = decimal.MaxValue;
}
// Source vertex's distance to self is zero
this.vertices[source].Weight = 0.0m;
pq.Enqueue(this.vertices[source]);
while (pq.Count() > 0)
{
// get the vertex with minimum wight
// from unvisited vertices to process
var minVertex = pq.Dequeue();
minVertex.IsVisited = true;
var minVIndex = vertices.IndexOf(minVertex);
// Go trough all unvisited neighbors
// and try to update their weight
for (var i = 0; i < adjMatrix[minVIndex].Length; i++)
{
// if weight is zero no connection between two vertices
if (this.adjMatrix[minVIndex][i] == 0.0m) continue;
// we are interested only in unvisited vertices
if (this.vertices[i].IsVisited) continue;
// calculate neighbor's weight by
// adding current weight and distance to the neighbor
// from current vertex
var calculatedWeight = adjMatrix[minVIndex][i] + minVertex.Weight;
// if calculated distance/weight is less then
// we found better path so update the neighbor's weight
if (calculatedWeight < this.vertices[i].Weight)
{
this.vertices[i].Weight = calculatedWeight;
this.vertices[i].Parent = minVertex;
// Add neighbor to the queue to process it later
pq.Enqueue(this.vertices[i]);
}
}
}
}
```

With this method we traverse all vertices in vertices list and looking at the graph matrix we update the values of each vertex. Next we will add public method which takes source and destination parameters, applies the algorithm and then backtracks the shortest path from distance to source and last it returns an information about the shortest path and total distance.

```
public string PrintShortestPath(string sourceName, string destinationName)
{
// We miss guard clauses for simplicity
var sVert =
vertices.First(v => v.Name == sourceName);
int source =
vertices.IndexOf(sVert);
var dVert =
vertices.First(v => v.Name == destinationName);
int destination =
vertices.IndexOf(dVert);
// Calculate all vertices' weights
ApplyDijkstra(source);
var destinationVertex = vertices[destination];
// Using stack to backtrack the path from
// destination to source by iterating parents
Stack<Vertex> backTrackShortestPath = new Stack<Vertex>();
bool pathExists = false;
while (destinationVertex != null)
{
if (destinationVertex.Name == sourceName)
{
backTrackShortestPath.Push(destinationVertex);
pathExists = true;
break;
}
backTrackShortestPath.Push(destinationVertex);
destinationVertex = destinationVertex.Parent;
}
if (!pathExists)
{
return $"No path exists from vertex:{source} to vertex:{destination}";
}
StringBuilder shortestPath = new StringBuilder();
var currentWeightArrow = "";
while (backTrackShortestPath.Count > 0)
{
var currentVertex = backTrackShortestPath.Pop();
shortestPath.Append($"{currentWeightArrow}({currentVertex.Name})");
currentWeightArrow = "--->";
}
shortestPath.AppendLine("\nTotal " +
$"distance from vertex:{sourceName} " +
$"to vertex:{destinationName} is " +
$"{vertices[destination].Weight}");
return shortestPath.ToString();
}
```

Next let’s construct the graph we explained above and use the code above to find the shortest path

```
static void Main(string[] args)
{
List<Vertex> vertices = new List<Vertex>
{
new Vertex("A"),
new Vertex("B"),
new Vertex("C"),
new Vertex("D"),
new Vertex("E"),
new Vertex("F")
};
decimal[][] graph = {
new[] { 0.0m, 1.0m, 2.0m, 0.0m, 0.0m, 0.0m },
new[] { 1.0m, 0.0m, 0.0m, 6.5m, 0.0m, 0.0m },
new[] { 2.0m, 0.0m, 0.0m, 0.5m, 10.5m, 0.0m },
new[] { 0.0m, 6.5m, 0.5m, 0.0m, 2.0m, 0.5m },
new[] { 0.0m, 0.0m, 10.5m, 2.0m, 0.0m, 1.0m },
new[] { 0.0m, 0.0m, 0.0m, 0.5m, 1.0m, 0.0m }
};
var dijkstra = new Dijkstra(graph, vertices);
var shortestPath =
dijkstra.PrintShortestPath("A", "F");
Console.WriteLine("The shortest path:");
Console.WriteLine(shortestPath);
Console.ReadLine();
}
```

The result in the console is:

The algorithm’s time complexity is

`O(E Log V)`

E – number of edges

V – number of vertices.

With this we conclude our explanation about Dijkstra’s algorithm. You can read more about the topic here:

https://www.programiz.com/dsa/dijkstra-algorithm

https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/

]]>The properties of heap described above makes it easy to be implemented with an array data structure and most commonly the heap is implemented with an array data structure. Let’s see how we would show a min heap with an array.

Based on the above representation we can define several formulas in order to detect parent or child nodes of a given node based on the index of an array. Given n is the index of an array then:

**Parent node index = (n – 1) / 2**

Example: Take 5th index which is 32, so (5 – 1) / 2 = 2 which is 30 the parent node.

**Left child index = (2 * n) + 1**

Example: Take 2nd index which is 30, so (2 * 2) + 1 = 5 which is 32 the left child.

**Right child index = (2 * n) + 2**

Example: Take 2nd index which is 30, so (2 * 2) + 2 = 6 which is 52 the right child.

Heapifying is an operation which rearranges the elements of the heap so it satisfies the conditions of min or max heap based on the heap type. This operation is performed after adding or removing a node from the heap or/and priority queue although in priority queue we have only enqueue and dequeue based on the priority of the elements compared to regular queue.

This operation starts from first index of non-leaf node whose index is given by n / 2 – 1 where n is the size of the array. Each root, left child and right child is compared and if they don’t satisfy the heap property the nodes are swapped. The operation is repeated until we reach the root node with index 0. Let’s see with example how we will heapify a tree which does not satisfy min heap properties.

When we add item to the heap/priority queue we add it as last item to the tree and then we heapify the tree as described above.

When we dequeue / remove item from the tree we swap the item to be removed with the last item in the tree, the rightmost node. Then we remove the last item which became the item we wanted to remove after we made a swap in previous step. Finally we heapify the tree in order to satisfy the heap properties.

Let’s see how we can implement priority queue in C#. First we will define an enum which will define the queue type.

```
public enum PriroityQueueType
{
Min,
Max
}
```

Then we will define a PriorityQueue class and implement it’s methods.

```
public class PriorityQueue<T> where T : IComparable<T>
{
private List<T> items;
private PriroityQueueType PriroityQueueType;
public PriorityQueue(PriroityQueueType priroityQueueType)
{
this.items = new List<T>();
this.PriroityQueueType = priroityQueueType;
}
}
```

We use generic class where the type should implement IComparable in order to compare the items when we implement priority queue operations. Next let’s implement heapify method.

```
private void Heapify(int index)
{
int count = items.Count;
int largestOrSmallest = index;
int leftIndex = 2 * index + 1;
int rightIndex = 2 * index + 2;
//check if current node is larger or smaller than left child based on the queue type
//if true then assign left child index to variable largestOrSmallest in order to track it
if (leftIndex < count &&
((PriroityQueueType == PriroityQueueType.Min
&& items[largestOrSmallest].CompareTo(items[leftIndex]) > 0)
|| (PriroityQueueType == PriroityQueueType.Max
&& items[largestOrSmallest].CompareTo(items[leftIndex]) < 0)))
{
largestOrSmallest = leftIndex;
}
//check if largestOrSmallest node is larger or smaller than right child based on the queue type
//if true then assign right child index to variable largestOrSmallest in order to track it
if (rightIndex < count &&
((PriroityQueueType == PriroityQueueType.Min
&& items[largestOrSmallest].CompareTo(items[rightIndex]) > 0)
|| (PriroityQueueType == PriroityQueueType.Max
&& items[largestOrSmallest].CompareTo(items[rightIndex]) < 0)))
{
largestOrSmallest = rightIndex;
}
//if one of the child is larger or smaller than the root then we need to swap them
if (largestOrSmallest != index)
{
T temp = items[largestOrSmallest];
items[largestOrSmallest] = items[index];
items[index] = temp;
//As we swapped the root item with one of the children we need to recrsively heapify the subtrees
Heapify(largestOrSmallest);
}
}
```

Heapify method is the code representation of the heapify operation visually described above.

Next we will implement enqueue method where we add an item to the end of the queue and then we start heapifying the tree starting from index n/2-1 where n is the count of the elements in the queue.

```
public void Enqueue(T item)
{
if (items.Count == 0)
{
items.Add(item);
}
else
{
items.Add(item);
for (int i = items.Count / 2 - 1; i >= 0; i--)
{
Heapify(i);
}
}
}
```

We will implement helper method DeleteNode which will delete a node from the heap by given index of the element. We will afterwards use this method to easily implement Dequeue operation of priority queue. Delete method follows the visual steps described earlier in this article.

```
private void DeleteNode(int index)
{
if(index > items.Count-1) throw new IndexOutOfRangeException();
T temp = items[index];
items[index] = items[items.Count - 1];
items[items.Count - 1] = temp;
items.RemoveAt(items.Count - 1);
for (int i = items.Count / 2 - 1; i >= 0; i--)
{
Heapify(i);
}
}
```

Using this method to implement dequeue operation is really easy we just call it with index 0 which is the top item of the queue.

```
public T Dequeue()
{
if (items.Count == 0)
throw new InvalidOperationException("The priority queue is empty");
T topItem = items[0];
DeleteNode(0);
return topItem;
}
```

Finally we implement Peek which is just returning the top item.

```
public T Peek()
{
T topItem = items[0];
return topItem;
}
```

It is worth mentioning the algorithm complexity of binary heap and priority queue.

Peek – O(1)

Enqueue – O(log n)

Dequeue – O(log n)

With this we conclude the explanation of heap and priority queue.

You can read more about this topic here:

https://www.geeksforgeeks.org/priority-queue-set-1-introduction/

https://www.programiz.com/dsa/priority-queue

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

Do you prefer listening to music while working?

If so – what kind of music?

Let me share my preferences on that topic.

I’ve felt that there are **two **working ** mood types**.

is when we have to come up with a solution for some complex problem, or when we have to think of a design problem, or we need to decide on the correct architectural approach, or solve a tricky puzzle, or find out an appropriate algorithm.

Basically – we have to involve a high level of concentration and a fair amount of thinking.

Let’s call that mood type – **Le Penseur** (*in French*),

or **The Thinker**.

is when we know what needs to be done, the approach has been discovered, we’ve already done the thinking work and now we need to implement it.

Let’s call that – **The Worker** mood type.

I pick my music based on the mood type I am currently at.

The most productive I am in **The Thinker** mood while I listen to more * calm *and

During this mood, I prefer to keep the volume at lower levels!

On the other hand, when I am in **The Worker** area I find it most appropriate and boosting my velocity when I play more dynamic, more… fast, and sometimes kind of aggressive music, which energizes me and pushes me to do the work and to enjoy it!

In those moments I play some **metal **songs with a fast rhythm, for example, “*Pantera*“, “*Sepultura*“, “*Soulfly*“, often I listen to death metal bands like “*In Flames*“, “*Edge Of Sanity*“, etc.

I also often play something more electronic like “*The Prodigy*” or even some psytrance – my favorite here is “*Infected Mushroom*“.

And on some occasions, the classical music helps here as well – like *Vagner *or *Beethoven*, or even something more modern like *Yann Tiersen*.

Often the volume is in higher levels on that mood.

Here is actual research on the topic, which kind of syncs with my feelings and conclusions:

“Kellogg reviews a vast body of research to extract a few notable findings. Among them is the role of background noise, which seems to fall on a bell curve of fecundity: High-intensity noise that exceeds 95 decibels disrupts performance on complex tasks but improves it on simple, boring tasks — noise tends to raise arousal level, which can be useful when trying to stay alert during mindless and monotonous work, but can agitate you out of creative flow when immersed in the kind of work that requires deliberate, reflective thought.”

https://www.brainpickings.org/2014/08/25/the-psychology-of-writing-daily-routine/

Of course, the music picks depend on your personal preferences, but the main connection is that:

**The Thinker** needs something **calm and harmonious**.**The Worker** wants **dynamics and energy**.

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

Upgrade your working environment by surrounding yourself with easily accessible **helpers**. **Print **out some useful (*for you*) **content **that can be used as a quick reference.

Of course, you can store all of those **cheat sheets** in electronic format somewhere on your hard drive (or URL bookmarks).

However, I would advise you to have some **on paper.**

That way you will not search for the file and disturb your inertion.

The physical version has a *psychological aspect *as well. You know that a piece of particular knowledge is exactly somewhere in the space around you and you can have a look at it for a second. So you are going to make references to those “* extensions of your brain*” in an absolutely natural and even semi-unconscious way.

Let me share with you some **example **resources:

- https://www.bigocheatsheet.com/ –
**Algorithms complexities**cheat sheet. - https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet – Basic
**GIT**commands. **SQL Server:**

– https://cheatography.com/davechild/cheat-sheets/sql-server/ : Basics.

– https://tableplus.com/blog/2018/08/ms-sql-server-data-types-cheatsheet.html : Data types

– https://www.guru99.com/sql-cheat-sheet.html : More complete list.- https://cheatography.com/kstep/cheat-sheets/http-status-codes/ –
**HTTP status codes**. - https://docs.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio?view=vs-2019 –
**Visual Studi**keyboard shortcuts. - https://cheatography.com/davechild/cheat-sheets/regular-expressions/ –
**Regular expressions**.

The purpose is to share little pieces of helpful practices and tricks that will make your work better and more pleasant.

You know the feeling when your machine needs to be restarted and then you have lo run all your programs again.

Or when you come back from a holiday. Or some updates that needs to happen. Or something else which needs reset of the current state of your environment.

You can actually do something about that annoying process and automatically run everything you need.**First**, create a ** batch file **(.bat for Windows or shell script (.sh) for MAC OX and Linux) on some easily accessible place.

**Then** include in the** script** all of the programs you want to run at once, like so:

```
@echo off
:: Open a particular solution
start C:\Projects\Other\Playground\Playground.sln
:: Open other programs like Outlook, Notepad, etc.
start outlook
start notepad++
:: SQL Server Management Studio
start ssms
:: Open Chrome and browse some useful pages
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://stackoverflow.com/
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://paircoders.com/
:: You can even update your local Git repo with the latest changes
cd C:\Projects\GIT\KOCreate && git.exe pull
@echo on
```

**Finally*** run the batch* and let it do the job.

So the best thing you can do is to read their thoughts and advices.

Here is a sample list of *my *top 10 blogs to follow. Pick whatever is applicable for your preferences.

*URL*: http://blog.cleancoder.com/*About*: Coding good practices, rules, standards, guidance, clean coding.

*URL*: https://martinfowler.com/*About*: Architecture, design, methodologies.

*URL*: https://www.hanselman.com/blog/*About*: Microsoft technologies – .NET, .NET Core, geeky stuff, software development and IT stuff.

*URL*: https://davidwalsh.name/*About*: Scripting – JavaScript, PowerShell, etc.

*URL*: https://hackernoon.com/tagged/software-development*About*: Wide variety of software development topics.

*URL*: https://gunnarpeipman.com/*About*: Microsoft – .NET/.NET Core, Azure.

*URL*: https://davidwalsh.name/*About*: .NET latest news and tips.

*URL*: https://cloudblogs.microsoft.com/sqlserver/*About*: SQL Server latest news.

*URL*: https://particular.net/blog*About*: Vries topics in the software development world.

*URL*: https://www.geeksforgeeks.org/featured-articles*About*: Algorithms, data structures, scripts, etc.

This is a workshop organized by “*Software University*” / aka *SoftUni */ (Sofia, Bulgaria) which took place on 21-st of Jan, 2021.

The content which I covered here is about some good practices for software developers, a time management technique, the root OOP principles, SOLID, Composition over Inheritance, Design Patterns and Software Architecture Patterns overview.

It is in Bulgarian language, but I promise to write separate blog posts in English for those topics… and more

]]>I always google it when I setup a new Dev environment.

If you are also working with Visual Studio and its built in GIT integration, then you have noticed that the remote branches shown under the Branches tree in the Team Explorer, are only increasing. Even some of the branches have been deleted from the remote server that have not been reflected to the tree.

This can be fixed by an easy configuration.

Open Team Explorer, then go to Home -> Settings -> Repository Settings and set the “Prune remote branches during fetch” to

Then press