Monday, October 3, 2011

Comparing TFS source branch with destination branch

When a TFS branch is not "enhanced" with visualisations, it can be tricky to determine the version of the source branch.

I recently wanted to find all the changes that had been made in a branch, including some tweaks that had been made when the branch action was initially checked in. The most reliable way to do this is to compare the source branch at the revision that the branch was made with the latest code in the branch. To do this, I wanted to use the following command line:

tf folderdiff "$/SourceBranch;RevisionThatBranchWasTakenFrom" $/DestinationBranch

However, I needed a way to determine RevisionThatBranchWasTakenFrom. Since branching in TFS is essentially copying (the metadata of) each file in the source branch to the destination, there is no single concept of the 'revision' of the source branch at the point when the branch was made (in contrast to Subversion). The best I could come up with was to find the most recent changeset in the source branch before the branch was made. To do this, I used the tf merges command on the destination branch, which lists all the files that have been merged into the destination branch. I have made several assumptions, including that there was a single branch into the destination and no subsequent merges:

tf merges $/SourceBranch /r /showall /format:detailed | % {$_ -match '(\d+) ->' | out-null; $Matches[1]} | sort -Descending | select -first 1

This PowerShell one-liner will return the highest revision number of all the branched files, assuming that nothing untoward happens and it can parse the output of tf merges. In our case, I knew that all the changesets in question had four digits, so the string based sort would work fine.

Now that I had the most recent changeset, I could run the command to get the changes:
tf folderdiff "$/SourceBranch;C12345" $/DestinationBranch

Sunday, September 25, 2011

Test-Website

The following function might be useful for checking whether a web page is up or down in PowerShell:

function Test-Website([string][parameter(mandatory=$true)]$Url, [string]$Content)
{
    $webRequest = [System.Net.WebRequest]::Create($Url) 
    $webRequest.CookieContainer = New-Object System.Net.CookieContainer;
    
    try {
        $response = $webRequest.GetResponse() 
    }
    catch {
        return $false
    }
    
    if($response.StatusCode -ne 200) {
        return $false
    }
    
    $responseStream = $response.GetResponseStream()
    $sr = New-Object IO.StreamReader($responseStream)
    $result = $sr.ReadToEnd()

    return $result -match $Content
}

Wednesday, September 21, 2011

Dump all properties of an object to a string in C#

It is often useful to dump all the properties of an object for debugging. This trivial implementation is good, although it only dumps the top level properties:

static string DumpAllProperties(object obj)
{
    return string.Join(", ", 
        TypeDescriptor.GetProperties(obj)
            .Cast()
            .Select(p => string.Format(CultureInfo.CurrentCulture, "{0} = {1}", p.Name, p.GetValue(obj))));
}

Sunday, August 21, 2011

Publishing to Arvixe via Visual Studio Publish in two steps

For non-mission critical sites, it is sometimes convenient to deploy directly through Visual Studio 2010's Publish feature. I use this for a couple of simple sites hosted on the very cost effective Arvixe shared hosting.

  1. Create a remote management password on the Arvixe control panel by opening the control panel, drilling down into your website configuration, and clicking on the Management tab. Enter a password for remote management and accept the change.
  2. In Visual Studio, right click on the web project and click Publish. Then fill out the publish dialog as below, and click Publish:


Thursday, August 11, 2011

Sound for Ubuntu 10.04 on the Compaq Presario CQ56

After installing Ubuntu 10.04, and then every time the kernel updated, I had no sound. The operating system seems to detect the card, and I can set the volume, but no sound is played through the speaker.

I hope the next point release gets a fix for this, but in the meantime, this page has the solution for next time I need to update the kernel:

InstallingLinuxAlsaDriverModules.

The technique I use is to execute the following three lines at the command line, and then reboot:

sudo add-apt-repository ppa:ubuntu-audio-dev/ppa
sudo apt-get update
sudo apt-get install linux-alsa-driver-modules-$(uname -r)

Don't forget to reboot!


Note that you may hit the following error, which means that the package has not been created for the newer version of the kernel. The solution is usually to wait a few weeks for the package to be created and try again.

Couldn't find package linux-alsa-driver-modules-2.6.32-37-generic

Tuesday, August 9, 2011

Which browsers should I test in?

I needed to answer the question "Which browsers should I test in?", but was frustrated by how difficult this was to answer in Google Analytics. After months of frustration and not being able to easily give solid figures from our websites, I knocked up a one-page site that aggregates the Analytics data of the logged in user and allows them to play around with various scenarios to decide which browsers to test in. Most importantly, this uses data from the target market, not from a generic or randomised sites.

Please note that this site uses the Google GData JavaScript API, so none of your Analytics data is sent to my servers.

The site is here:
browsertest.info

Friday, August 5, 2011

One day sales site - example of jQuery widgets and QUnit unit tests

I have made a small site that uses some Javascript features such as drag and drop so that I could try writing QUnit unit tests. The tests were refreshingly easy to write, including testing things such as dragging and dropping by simulating mouse clicks.

The site allows users to view popular one-day sale sites in New Zealand, and the tests can be found here.