Change Default Path for cmd.exe

Step 1 search on star menu, type ‘command’

click on ‘Open file location’.

Step 2 right click on command in opened folder

Now in ‘Start in’ field, put path you want.

Posted in Uncategorized | Comments Off on Change Default Path for cmd.exe

How to turn ‘Not Run Tests’ into normal test in Visual Studio

all unit tests in newly added Unit Test Project are not appeared in ‘Test Explorer’

or those unit tests are marked as “Not Run Tests” and never run it no matter how hard you pressure visual studio to run.

do following two steps to fix:

delete following two framework references

Microsoft.VisualStudio.TestPlatform.TestFramework、
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions

and add Microsoft.VisualStudio.QualityTools.UnitTestFramework

Posted in Uncategorized | Comments Off on How to turn ‘Not Run Tests’ into normal test in Visual Studio

TypeScript Define

process.env type define

add following code before `process.env.NODE_ENV`

1
2
3
4
5
6
7
declare var process : {
  env: {
    NODE_ENV: string
  }
}
 
process.env.NODE_ENV

define Array

1
2
3
4
5
6
7
8
9
10
11
export interface INinjaConfig {
    username: string;
    password: string;
    uris: {
      uri: string,
      pdfUri: string
    },
    mapping: {
      [key: string]: string;
    }
  }

define Array of Array Type

1
2
3
4
5
6
7
8
9
10
11
12
define [[string, number, number]...]
 
 
export interface IInfluxDBInfo {
    name: string,
    tags: {
      hostname: string,
      ifAlias: string
    },
    column: string[],
    values: Array<[string, number, number]>
}

nullable variable declare

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export interface QueryConfig {
    limit?: number;
    skip?: number;
    sort?: {
        [key: string]: string;
    };
    select?: string;
    populate?: any;
    state?: string;
    lean?: boolean;
    handleNotFound?: boolean;
    archived?: boolean;
    publishEvent?: boolean;
    dataType?: string;
    all?: boolean;
    fields?: string[];
    childrens: [{
      sys_id: string;
      name: string;
      company: string;
    }];
}
Posted in Javascript | Comments Off on TypeScript Define

C# @keyword as escape of keyword

it is very common to see that C# code use @keyword such as @this to escape ‘this’ as keyword to use it like a local variable.

1
2
3
4
5
6
7
8
9
class @class
{
   public static void @static(bool @bool) {
      if (@bool)
         System.Console.WriteLine("true");
      else
         System.Console.WriteLine("false");
   }   
}
Posted in C# | Comments Off on C# @keyword as escape of keyword

“corecrt.h”: No such file or directory

if %include% is lost, VS could not find header.

add sdk
C:\Program Files (x86)\Windows Kits\10\Include into %include% path to fix issue.

Posted in vc++ | Comments Off on “corecrt.h”: No such file or directory

Operation Failed An exception was thrown while initializing part “NuGet.PackageManagement.VisualStudio.VSSolutionManager”. GetFullVsVersionString must be called on the UI thread.

Visual Studio 2015 update 3 could throw this exception.

the way to fix it
1. open vs2015 and don’t open any project.
2. go to menu ‘Tools’ -> Nuget Package Manager -> Package Manager Setting
3. once you see dialog pop up successfully without error, click on ‘OK’ button to confirm.
4. open any project. now you could see that Nuget error is gone.

Posted in C# | Comments Off on Operation Failed An exception was thrown while initializing part “NuGet.PackageManagement.VisualStudio.VSSolutionManager”. GetFullVsVersionString must be called on the UI thread.

PriorityQueue in C#

PriorityQueue is a binary heap. Heap is commonly used algorithm. in some area such Graph shortest path and minimum spanning tree, it is very helpful.

both Java and C++ has PriorityQueue, but C# don’t have.

Here is a version of PriorityQueue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PriorityQueue<T> where T : IComparable<T>
    {
        private List<T> data;
        private bool isMaxHeap = false; 
        /// <summary>
        /// 
        /// </summary>
        public PriorityQueue()
        {
            this.data = new List<T>();
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="isMaxHeap"></param>
        public PriorityQueue(bool isMaxHeap)
        {
            this.data = new List<T>();
            this.isMaxHeap = isMaxHeap;
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public void Enqueue(T item)
        {
            data.Add(item);
            int ci = data.Count - 1; // child index; start at end
            while (ci > 0)
            {
                int pi = (ci - 1) / 2; // parent index
                if(isMaxHeap)
                {
                    if (data[ci].CompareTo(data[pi]) <= 0) break;
                } else if (data[ci].CompareTo(data[pi]) >= 0)
                    break; // child item is larger than (or equal) parent so we're done
                T tmp = data[ci]; data[ci] = data[pi]; data[pi] = tmp;
                ci = pi;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public T Dequeue()
        {
            // assumes pq is not empty; up to calling code
            int li = data.Count - 1; // last index (before removal)
            T frontItem = data[0];   // fetch the front
            data[0] = data[li];
            data.RemoveAt(li);
 
            --li; // last index (after removal)
            int pi = 0; // parent index. start at front of pq
            while (true)
            {
                int ci = pi * 2 + 1; // left child index of parent
                if (ci > li) break;  // no children so done
                int rc = ci + 1;     // right child
                if (isMaxHeap)
                {
                    if (rc <= li && data[rc].CompareTo(data[ci]) >= 0) // if there is a rc (ci + 1), and it is smaller than left child, use the rc instead
                        ci = rc;
                    if (data[pi].CompareTo(data[ci]) >= 0) break; // parent is smaller than (or equal to) smallest child so done
                }
                else
                {
 
                    if (rc <= li && data[rc].CompareTo(data[ci]) < 0) // if there is a rc (ci + 1), and it is smaller than left child, use the rc instead
                        ci = rc;
                    if (data[pi].CompareTo(data[ci]) <= 0) break; // parent is smaller than (or equal to) smallest child so done
                }
 
                T tmp = data[pi]; data[pi] = data[ci]; data[ci] = tmp; // swap parent and child
                pi = ci;
            }
            return frontItem;
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public T Peek()
        {
            T frontItem = data[0];
            return frontItem;
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public int Count()
        {
            return data.Count;
        }
 
        public override string ToString()
        {
            string s = "";
            for (int i = 0; i < data.Count; ++i)
                s += data[i].ToString() + " ";
            s += "count = " + data.Count;
            return s;
        }
 
        public bool IsConsistent()
        {
            // is the heap property true for all data?
            if (data.Count == 0) return true;
            int li = data.Count - 1; // last index
            for (int pi = 0; pi < data.Count; ++pi) // each parent index
            {
                int lci = 2 * pi + 1; // left child index
                int rci = 2 * pi + 2; // right child index
 
                if (lci <= li && data[pi].CompareTo(data[lci]) > 0) return false; // if lc exists and it's greater than parent then bad.
                if (rci <= li && data[pi].CompareTo(data[rci]) > 0) return false; // check the right child too.
            }
            return true; // passed all checks
        } // IsConsistent
    }
Posted in Algorithm | Comments Off on PriorityQueue in C#

WCF – How to publish WCF into IIS

1. copy web.config
2. copy service.svc
3. copy dll and pdb file into bin folder
4. in iis, setup a new web instance, and point physical folder address into published folder
setup .net support version correctly for web instance.
5. try http://ip-address:port/service.svc/js or http://ip-address:port/service.svc/jsdebug

Posted in Uncategorized | Comments Off on WCF – How to publish WCF into IIS

Interface out T vs T

The out keyword in generics is used to denote that the type T in the interface is covariant.

check following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
        class Fruit { }
 
        class Banana : Fruit { }
 
        interface ICovariantSkinned<out T> { }
 
        interface ISkinned<T> { }
 
        class A<T> : ISkinned<T> { }
        class B<T> : ICovariantSkinned<T> { }
 
        public static void Main()
        {
            ISkinned<Banana> a1 = new A<Banana>();
            ISkinned<Fruit> a = a1;    // compiling error happens here
 
            ICovariantSkinned<Banana> b1 = new B<Banana>();
            ICovariantSkinned<Fruit> b = b1; // compiling passed
        }
Posted in Uncategorized | Comments Off on Interface out T vs T

How to set Visual Studio support C# 7 features.

  • open visual studio and click on project and choose ‘Properties’
  • in ‘Build’ tab, choose ‘Advanced…’, check screen dump
  • in language version, in dropdown list showing in screen dump, there is not ‘C#7’ and ‘C# 7.2’ for visual studio 2015
  • in visual studio 2017, same dropdown list has ‘C# 7.x’ options

Although some ways could update visual studio 2015 to support C# 7, I higly recommand to use visual studio 2017.

wp_check C# version number

wp_language_version_vs2017

Posted in Uncategorized | Comments Off on How to set Visual Studio support C# 7 features.