Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Monday, 14 July 2014
( Resharper | Xunit )

Resharper Manage Extensions

image

| | # 
# Thursday, 24 April 2014

Ctrl+Shift+/ - block comment html

| | # 
# Thursday, 09 May 2013

Need latest build of r# http://download.jetbrains.com/resharper/ReSharperSetup.7.1.3000.1964.msi

To get test runner working in vs2012.2 update

| | # 
# Friday, 04 January 2013

Favourites

Ctrl+Tab – move between open tabs (VS)

Ctrl+Shift+B or F6 – build (or Alt+B+U to build unit).. or Shift+F6 for Build.BuildSelection

Alt+V+P – solution explorer (VS)

Ctrl+\ + M – Team Explorer

Ctrl+W+E – Compile Error window

 

Ctrl+U+D – Run unit tests in debug mode

Ctrl+U+R – Run unit tests

Ctrl+Alt+T – View Unit Test sessions window

F12 – Go to definition

F5 – compile and run in debug

Ctrl+Shift+Alt Up  - moves a line / method up

image
Alt+Enter – show suggestion

Ctrl+M+M – collapse/expand method (VS)

Ctrl+M+O – collapse all methods (VS)

Ctrl+M+P – expand all methods(VS)

Ctrl+K+D – reformat code (VS)… related is Tools, Options, Text Editor, C#, Formatting… untick top 2 to get rid of annoying linq formatting

Ctrl+Shift+/  - block comment – can then block comment around other line comments in XAML

Ctrl+, – recently opened files

Ctrl+Shift+, – View recent edits

image
Ctrl+Space – Symbol Code completion.. eg FirstOr   then it fills in Default

 image
Ctrl+Shift+Space – show parameters of method

Ctrl+K+C – comment

Ctrl+K+U – uncomment

Ctrl+R+R – rename

 

Ctrl+H – replace (VS) then Alt+R to replace 1 by 1

Shift+Alt+Enter – Full screen (VS)

 

Ctrl+- - Go to last cursor position (VS)

Alt+E+I+O+A – Remove and sort unused usings (VS)

Ctrl+T – search for type

Shift+Alt+C – create class (VS)

Alt+L – delete line (VS)

Playing

Ctrl+K+K – bookmark

Ctrl+K+N – next bookmark

Ctrl+K+P – previous

Ctrl+K+L – clear bookmarks

Ctrl+W+B – View bookmark window

 

Alt + PgDn – Go to next highlight eg error

Ctrl+Alt+D – TODO explore/warning

Ctrl+Alt+U – Unit test explorer

Ctrl+Alt-T – Unit test sessions

Ctrl+Alt+F – File structure (same as Alt+V+P)

TFS

Ctrl+0+P – Pending changes

Ctrl+0+W – Work items

Ctrl+0+H – Home

 

 

Show stuff

 image
Ctrl+Shift+R – Refactor this

image
Alt-Ins – Generate code

 

image
Ctrl+Alt+Space – Smart Code completion…shows only the important methods..not inherited?

Commenting

Ctrl+Alt+/ – line comment

 

Moving and moving in Code

 

Ctrl+D – duplicate a line or selected text

Ctrl+Shift+Backspace – back to last point where were editing (same as ctrl –)

Ctrl+Shift+[  - Select Containing declaration.. ie selects whole method really easily

Expanding / Collapsing

Ctrl+M+O – Collapse all

Ctrl+M+L – Expand all

Ctrl+M+M – current section

Searching

Ctrl+T – go to Type

Ctrl+Shift+T -  go to File

Shift+Alt+F11 – Highlight occurrences

Ctrl+Alt+PgUp / PgDn – navigate between highlighted occurrences

Alt+PgUp – Resharper warnings go between

* Alt-H – replace.. then Alt+R to replace next

image
Ctrl+, – Recent Files

Running Tests

Ctrl+R+T – run tests in debug (VS) – much prefer R# test runner as faster

Ctrl+R+T – MS Test runner in debug mode

Deleting

Ctrl L – Delete a line

Selecting

Ctrl+Shift+Right Arrow – highlight block of code

PlugIns

http://gjxaml.codeplex.com/

Code Cleanup

Ctrl+E+C – Code cleanup

| | # 
# Tuesday, 05 June 2012
( Euler | Git | Resharper )

Am trying out using git now on every project - mainly so I can easily revert if I mess things up.  Good practice.

git init

git add .

git commit -m "first commit of Euler 15"

git checkout -b firsttry

git branch (to see branches)

gitgui

image

R# – Move to another file with same name

Forumla

http://locationcube.blogspot.co.uk/2010/12/project-eulerproblem-15.html

The formula is n! / r! (n-r)!

Where n is 40 and r is 20…  so 40!/(20! * 20!)

Which gives us:    137846528820 ways to get there!

In fact Google’s online calculator can do this for you….

Just type 40 choose 20 into Google!!

image

Discrete Mathematics

– on a 2*2 square it takes 4 steps to reach the end. So on a 20*20 square it takes 40 steps.

20 increases in x and 20 increases in y

how many different ways can you choose 20 elements out of a set of 40 elements.

We can use a formula to solve this. “n choose r formula”: N!/r!(n-r)

40!/((20!)(40-20)!)

N = number of elements (40)

r = how many we want to choose

137,846,528,820

Dynamic Programming

How many routes are there through a 20×20 grid? or.. total number of ways to arrive at a node?

dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems

We find the total number of ways to arrive at a node:

“Sum of the count from above and to the left”

[TestFixture]
public class DynamicProgrammingTests
{
    private DynamicProgramming dynamicProgramming;

    [SetUp]
    public void DoFirst()
    {
        this.dynamicProgramming = new DynamicProgramming();
    }

    [Test]
    public void Four_DynamicProgrammingSolver_GivesAnswerOf70()
    {
        var result = dynamicProgramming.Solve(4);
        Assert.AreEqual(70, result);
    }

    [Test]
    public void Five_DynamicProgrammingSolver_GivesAnswerOf252()
    {
        var result = dynamicProgramming.Solve(5);
        Assert.AreEqual(252, result);
    }

    [Test]
    public void Twenty_DynamicProgrammingSolver_GivesAnswerOf252()
    {
        var result = dynamicProgramming.Solve(20);
        //137,846,528,820
        Assert.AreEqual(137846528820, result);
    }
}

//using property of problem that
//total number of ways to arrive at a node
//is count from left and above
//so we build an array with total number of ways to arrive at a node
public class DynamicProgramming
{
    public double Solve(int sizeOfGrid)
    {
        var array = new double[sizeOfGrid+2, sizeOfGrid+2];

        int i, j;
        array[1, 1] = 1;
        for (i = 1; i <= sizeOfGrid+1; i++)
        {
            for (j = 1; j <= sizeOfGrid+1; j++)
            {
                //count from left, then count from above
                array[i, j] += array[i - 1, j] + array[i, j - 1];
            }
        }
        double result = array[sizeOfGrid+1, sizeOfGrid+1];
        return result;
    }
}

put in photo here of array with answers in it.

Brute Force – Recursive

[TestFixture]
public class SolverTests
{
    private BruteForceRecursionSolver bruteForceRecursionSolver;
    [SetUp]
    public void DoThisAtStart()
    {
        this.bruteForceRecursionSolver = new BruteForceRecursionSolver();
    }
    [Test]
    public void TwoGivesAnswerOf6()
    {
        bruteForceRecursionSolver.gridSize = 2;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(6, result);
    }

    [Test]
    public void ThreeGivesAnswerOf20()
    {
        bruteForceRecursionSolver.gridSize = 3;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(20, result);
    }

    [Test]
    public void FourGivesAnswerOf70()
    {
        bruteForceRecursionSolver.gridSize = 4;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(70, result);
    }

    [Test]
    public void FiveGivesAnswerOf252()
    {
        bruteForceRecursionSolver.gridSize = 5;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(252, result);
    }

    [Test]
    public void TenGivesAnswerOf184756()
    {
        bruteForceRecursionSolver.gridSize = 10;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(184756, result);
    }

    [Test]
    public void ElevenGivesAnswerOf705432()
    {
        bruteForceRecursionSolver.gridSize = 11;
        var result = bruteForceRecursionSolver.Progress(0, 0);
        Assert.AreEqual(705432, result);
    }
}

//http://stackoverflow.com/questions/2200236/project-euler-15
public class BruteForceRecursionSolver
{
    public int gridSize;

    // top left is 0,0
    public int Progress(int x, int y)
    {
        int i = 0;

        if (x < gridSize)
            //favours going right
            i += Progress(x + 1, y);
        if (y < gridSize)
            i += Progress(x, y + 1);

        //reached bottom right
        if (x == gridSize && y == gridSize)
            return 1;
        return i;
    }
}

This is very much brute force..

This took about 1.5 hours:

public class SolveRecursion
    {
        public long Combination = 0;
        public int GridSize;

        public void CalculateCombination(int x = 0, int y = 0)
        {
            if (x < GridSize)
            {
                CalculateCombination(x + 1, y);
            }
            if (y < GridSize)
            {
                CalculateCombination(x, y + 1);
            }
            if (x == GridSize && y == GridSize)
                Combination++;
        }
    }
static void Main(string[] args)
        {
            //gives correct answer: 137,846,528,820
            Console.WriteLine("starting");
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            var solveRecursion2 = new SolveRecursion { GridSize = 20 };
            solveRecursion2.CalculateCombination();
            var result = solveRecursion2.Combination;
            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;
            Console.WriteLine("Result is: {0}, time was {1} seconds", result, ts.ToString());
        }

and non recursive thoughts on:

http://stackoverflow.com/questions/10890516/rewrite-recursive-algorithm-more-simply-euler-15

| | # 
# Sunday, 15 April 2012

Ctrl T – Type..eg HomeController (hc)

Ctrl Shift T – Navigate to File

Ctrl Alt T – method.. eg hc.index

image

Ctrl R, Ctrl M – Extract method

Ctrl Shift Alt – Move a method up and down.

type method eg MakeCalculator… then ctrl enter… introduce variable

Alt Shift Space – brings up help

Also Keith Braithwaite at NDC 2011 video

WHEN creating a method in TDD which doesn’t exist yet.

Inspect Next Error/Previous error - shift Alt Page Up

REFACTOR

Ctrl Shift R – Refactor menu

Ctrl Shift Backspace –go back to last place was editing

Ctrl , – recent files viewed

Ctrl Shift W – smart select eg word, line etc

Ctrl E C – Code Cleanup.

Ctrl E U – Surround with eg Try Catch

| | # 
# Tuesday, 27 December 2011

Alt Enter – get rid of usings, introduce variable

Ctrl R Ctrl R – Rename

Ctrl Alt Space – If have a reference but don’t have a using yet

Naming convention warning:  Alt Enter, Inspection Options, Hint (gets rid of blue squiggly) eg for   Add_TwoNumbers_ReturnsTheSum()

Introduce var.. turn off.

Ctrl R, Ctrl M  - Extract Method   eg MyCalculator c = new MyCalculator();  highlight green bit, then Ctrl R, Ctrl M.  extract as a static method.  Factory.

Resharper Snippets

image

test tab will then do this.  $xxx$ are dynamic, and $END$ is where cursor will end up.

Ctrl E, Ctrl U – Surround with eg Try Catch

Ctrl E, Ctrl C – Cleanup code.. VS is Ctrl K, Ctrl D

image

Ctrl R, Ctrl P – Introduce parameter

Ctrl D – Duplicate

Ctrl R O – Move to Folder

Ctrl x – without highlighting will cut a line

Ctrl E Ctrl U – Surround with

| | #