MohamedG's Log


WCF Service Throttling

Throttling, generally speaking, is tricky. Get the limits low and you may be prone to DoS and clients timing out trying to connect to your service in vain; Get them high and you may end up with an overloaded service that’s eating up machine resources until it crashes. There’s a sweet spot in between that… Read more

VSTS 2010 and .Net 4.0 Beta 2

Beta 2 is here, give it a try and let us know what do you think. div#widget { position: relative; width: 250px; height: 155px; } body ul#cntdwn { width: 250px; height: 80px; background: transparent url( no-repeat scroll left top; list-style-type: none; text-align: center; padding: 74px 0 0 0; margin: 0; font-family: “Helvetica Neue”, helvetica, arial,… Read more

C++: Calling a Virtual Function From a Constructor is not Polymorphic

In C++, if you call a virtual function form a constructor, it won’t be polymorphic, meaning that the following code won’t behave as you may have expected: class Foo { public:     Foo() {         whoAmI();     }     virtual void whoAmI() {         cout << “Foo::whoAmI()” << endl;     } }; class Bar : public Foo { public:     Bar() {         whoAmI();     }     virtual void whoAmI() {        … Read more

Selection of Majority in O(n)

Selection algorithms are very useful in many instances, like finding the majority. Given an array of size n that contains a majority item (an item that’s repeated more than n/2 times), we can find that item in O(n). Basically, we can consider it as a voting process, each occurrence is a vote and each item… Read more

Passing C++ Arrays by Value

Just in case you needed to, you can wrap an array into a struct/class and pass it by value to a function:template<typename T, int N>struct array {    T value[N];    T & operator[](int i) { return value[i]; }};template<typename T, int N>void passByValue(array<T, N> a) {    cout << “Value in function:” << endl;    for (int i =… Read more

Proxy Design Pattern

One of the useful design patterns is the proxy design pattern, it allows you to control access to an object via a proxy and also saves you the startup and cleanup overheads as you instantiate only what you use upon request (lazy initialization). Take a look at the following example: #include<iostream> #include<string>   using namespace… Read more

Test Patterns

Just like design patterns, the use of test patterns will make your life easier. A lot of the common testing methods can be reused. Along with the benefits of reuse, using patterns makes it easier to explain to others what you are going to do in a word or a two instead of telling the… Read more

How to: Query All Labels on a Folder Recursively?

To do this, you can’t call query labels with a wildcard character, you need to do the following:   – Get all items blow $/Dir1 using GetItems – Loop through them calling QueryLabels on each one.   Here’s a code snippet: VersionControlServer sc = tfs.GetService<VersionControlServer>();List<VersionControlLabel> labels = new List<VersionControlLabel>();  foreach (Item i in sc.GetItems(“$/Proj”, RecursionType.Full).Items){   labels.AddRange(sc.QueryLabels(null, null, null, false, i.ServerItem, null));}… Read more

How to: Move a Shelveset to Another Branch?

A very handy power tool is tfpt unshelve. It’s capable of migrating a shelveset from a branch to another, it does that by performing a baseless merge, so you will need to resolve the conflicts produced. The syntax of the command looks like the following: tfpt unshelve shelvsetName /migrate /source:$/SourceBranch /target:$/TargetBranch… Read more