Git config file tips

These commands work on /.git/config file
git config --system--unset credential.helper
git config --global--unset credential.helper
git config --global credential.helper wincred
git config --global credential.helper osxkeychain

To update your credentials, go to Control Panel → Credential Manager → Generic Credentials. Find the credentials related to your Git account and edit them to use the updated password.

Reference: How to update your Git credentials on Windows

Note that to use the Windows Credential Manager for Git you need to configure the credential helper like so:

git config --global credential.helper wincred

If you have multiple GitHub accounts that you use for different repositories, then you should configure credentials to use the full repository path (rather than just the domain, which is the default):

git config --global credential.useHttpPath true

The only thing that worked for me was navigating to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree and removing the passwd file.

Once this file is removed, restart SourceTree and execute a fetch or something else that requires access to the repo in question. SourceTree will then prompt you for your password, rewriting the cached credentials.

I hope this helps. Shoutout to my buddy Nick for the assist.

If you’re a macOS user, Auke states below that “you can find the password files per repo it in ~/Library/Application Support/SourceTree”

Git branches and tags

git branch
git branch -av
git checkout
git checkout -b
git checkout -b destination-BranchName sourceBranchName

How to keep a feature branch in sync with it’s parent branch

git checkout develop
git pull
git checkout feature/foo
git merge develop
git push

or
git checkout feature/foo
git pull --all
git rebase develop

Git Azure DevOps on Mac

Reference:
https://docs.microsoft.com/en-us/azure/devops/repos/git/set-up-credential-managers?view=vsts
https://github.com/Microsoft/Git-Credential-Manager-for-Mac-and-Linux/blob/master/Install.md

Update the Homebrew/Linuxbrew formulae to make sure you have the latest versions:
brew update

Install the GCM4ML formula:
brew install git-credential-manager

Run the GCM4ML in install mode, which will check its requirements and then update the “global” Git configuration file (the one in your home folder):
git-credential-manager install

Create local repo
git init

Add Azure DevOps remote
git remote add origin https://

Pull from master branch
git pull origin master

Pull from Develop branch (if it exists)
git pull origin Develop

Docker commands

Pull down the SQL Server Docker Image from DockerHub
docker pull microsoft/mssql-server-linux:2017-latest

Create a Docker container using the microsoft/mssql-server-linux:2017-latest
Automatically accept the EULA, set the password to for the sa user, and map port container port 1433 to host port 1433
docker run --name sql \
-e 'ACCEPT_EULA=Y' \
-e 'SA_PASSWORD=' \
-p 1433:1433 \
-d microsoft/mssql-server-linux:2017-latest

Check if the container is up (running) – in STATUS column
sudo docker ps -a

To stop the container (assuming its name is “sql”) just type
docker stop sql
Now, typing sudo docker ps -a the container STATUS is Exited

To restart the container just type
docker start sql

Test the connection with Azure Data Studio or SQLPro for MSSQL

Here there is a Microsoft Reference Guide on Docker

Deletes pulled images with IMAGE ID 810001cb03af
docker images | grep 810001cb03af | awk '{print $1 ":" $2}' | xargs docker rmi

Existing SQL Server

Generating a model from an existing database .Net Core 2.0

In a folder that will contain your demo project type the following command:
dotnet new console for a console application or dotnet new mvc for a MVC or Web API application

Add the Entity Framework Core and Tools packages to the project:
This is the EF Core provider for SQL Server.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

This package contains the Entity Framework Core commands. Both of these packages are required for any Entity Framework Core application that targets SQL Server.
dotnet add package Microsoft.EntityFrameworkCore.Tools

The final package is required for supporting the scaffolding of the model.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer.Design

Test if Entity Framework is available
dotnet ef -h

Now use the DbContext Scaffold command to generate the model passing two arguments:

  • a connection string
  • a provider

dotnet ef dbcontext scaffold "Server=.\;Database=AdventureWorks;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models

dotnet ef dbcontext scaffold "Server=localhost,1433\\Catalog=AdventureWorks;Database=AdventureWorks;User=SA;Password=;" Microsoft.EntityFrameworkCore.SqlServer -o Models

Once you have executed the command, you will see that a folder named Models has been created in the project folder, containing a collection of class files representing the entities.
You can find also a class file containing the DbContext class.
The DbContext class will take the name of the database plus “Context”.
You can override this using the -c or –context option e.g.
dotnet ef dbcontext scaffold "Server=.\;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models -c "AdventureContext"

Singleton

<p><code style="display:block;white-space:pre-wrap">
using System;

namespace SingletonPatternEx
{
    public sealed class Singleton
    {
        private static readonly Singleton instance=new Singleton();
        private int numberOfInstances = 0;
        //Private constructor is used to prevent
        //creation of instances with 'new' keyword outside this class
        private Singleton()
        {
         Console.WriteLine("Instantiating inside the private constructor.");
         numberOfInstances++;
         Console.WriteLine("Number of instances ={0}", numberOfInstances);
        }
        public static Singleton Instance
        {
            get
            {
                Console.WriteLine("We already have an instance now.Use it.");
               return instance;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)                                                                                              
        {
            Console.WriteLine("***Singleton Pattern Demo***\n");
            //Console.WriteLine(Singleton.MyInt);
            // Private Constructor.So,we cannot use 'new' keyword.            
            Console.WriteLine("Trying to create instance s1.");
            Singleton s1 = Singleton.Instance;
            Console.WriteLine("Trying to create instance s2.");
            Singleton s2 = Singleton.Instance;
            if (s1 == s2)
            {
                Console.WriteLine("Only one instance exists.");
            }
            else
            {
                Console.WriteLine("Different instances exist.");
            }
            Console.Read();
        }
    }
}
</code></p>

Prototype

<p><code style="display:block;white-space:pre-wrap">
//BasicCar.cs
using System;

namespace PrototypePattern
{
   public abstract class BasicCar
    {
        public string ModelName{get;set;}
        public int Price {get; set;}
        public static int SetPrice()
        {
            int price = 0;
            Random r = new Random();
            int p = r.Next(200000, 500000);
            price = p;
            return price;
        }
        public abstract BasicCar Clone();
    }
}
//Nano.cs
using System;

namespace PrototypePattern
{
    public class Nano:BasicCar
    {
        public Nano(string m)
        {
            ModelName = m;
        }

        public override BasicCar Clone()
        {
            return (Nano) this.MemberwiseClone();//shallow Clone
        }
    }
}
//Ford.cs

using System;

namespace PrototypePattern
{
    public class Ford:BasicCar
    {
        public Ford(string m)
        {
            ModelName = m;
        }

        public override BasicCar Clone()
        {
            return (Ford)this.MemberwiseClone();
        }
    }
}

//Client

using System;

namespace PrototypePattern
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");
            //Base or Original Copy
            BasicCar nano_base = new Nano("Green Nano") {Price = 100000};
            BasicCar ford_base = new Ford("Ford Yellow") {Price = 500000};
            BasicCar bc1;
            //Nano
            bc1 = nano_base.Clone();
            bc1.Price = nano_base.Price+BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1} ",bc1.ModelName,bc1.Price);

            //Ford            
            bc1 = ford_base.Clone();
            bc1.Price = ford_base.Price+BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1}", bc1.ModelName, bc1.Price);

            Console.ReadLine();
        }
    }
}
</code></p>

Generic method with reflection

Need to write some description and tags

                var collectionName = await _configurationFacade.GetConsumerCollectionArchive(observer.EsbConsumer);
                Type collectionType = Type.GetType($"TaxMs.Esb.Infrastructure.Models.{collectionName}");
                //_context.TryGetCollection<AccountingTax>().Find(x => x.);

                //_context.GetType()
                //    .GetMethod("TryGetCollection")
                //    .MakeGenericMethod(propertyInfo.PropertyType)
                //    .Invoke(mapper, new object[] { "bloggingabout" });

                MethodInfo method = _context.GetType().GetMethod(nameof(_context.TryGetCollection));
                MethodInfo generic = method.MakeGenericMethod(collectionType);
                var mongoCollection = generic.Invoke(this, null);