The C# yield

Leave a comment

I don’t use yields often, but one place where they can be handy is when you want to return a collection of objects Just-In-Time.

One way to do this would be with a list (rather clumsy).

        public static IEnumerable<GasDay> GetEnumerator(GasDay inclusiveStart, GasDay inclusiveEnd)
        {
            List<GasDay> gasDays = new List<GasDay>();
            for (GasDay gasDay = inclusiveStart; gasDay.IsBeforeOrSame(inclusiveEnd); gasDay = gasDay.NextGasDay())
            {
                gasDays.Add(gasDay);
            }
        }

A more elegant way would be o use a yield.

        public static IEnumerable<GasDay> GetEnumerator(GasDay inclusiveStart, GasDay inclusiveEnd)
        {
            for (GasDay gasDay = inclusiveStart; gasDay.IsBeforeOrSame(inclusiveEnd); gasDay = gasDay.NextGasDay())
            {
                yield return gasDay;
            }
        }
Advertisements

How to create alias in ms dos

1 Comment

https://windowsoptimized.wordpress.com/2011/04/25/creating-aliases-in-doscommand-prompt/

Follow the instructions here.

How to setup slickrun for windows

1 Comment

https://bayden.com/slickrun/

Capture.PNG

/k "cd /d c:\dev\xxx & color 07"

1.pmg.PNG

c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe

How to setup Git Credential store in Windows

1 Comment

This how to is for people who want to work with git from the command line but are struggling because of Windows 10.

Note: For these notes to work, you need to install Windows Git WITHOUT the Credential Manager enabled. If you do you will get a sequence error.

The way this works is we are going to use this line:

$ git config --global credential.helper "store --file ~/.gitcredential"

to create a local .gitconfig file on your machine with is going to locally store your credentials. If you do this as admin (recommended) your credentials will be stored here C:\Users.

Open command prompt as adminstrator

$ git config --global user.name "John Doe"
$ git config --global user.email john_doe@xx.com
$ git config --global credential.helper "store --file ~/.gitcredential"

This will create a .gitconfig in your C:\Users\ directory and configure git to store your credentias in the same directory.

$ git config --list --show-origin

Show three entries:

file:C:/Users//.gitconfig user.name=
file:C:/Users//.gitconfig user.email=@xxx.com
file:C:/Users//.gitconfig credential.helper=store --file ~/.gitcredential

You are now ready to try your credentials out. Clone the repos, cd into it, and then do a git fetch. The first time you will be asked for your credentials. The second time you shouldn’t. You will now also see a new file (.gitcredential) appear in your user directory.

%d bloggers like this: