Monday, 23 July 2007

It's been a while since my last blog post, so now could be a good time for some updates. First; I'm back in Redmond this summer too, in a summer internship for Microsoft. I'm working on the SQL Server team this year too, but changed teams internally, from the Test Execution Team to the SQL Server Build Team, which is responsible for building (compile, optimize, sign etc.) SQL Server. This means that I design and write software we use to build SQL Server. Right now, I'm working on a system for Peer-to-Peer File Sharing in the build lab, in C#. Building SQL Server involves copying hundreds of GB of data over the lab network, so by doing this p2p instead of centralized, we can reduce the load on the network. This project is really challenging and fun to work on.SQLserver05Ent_web.jpg

So, what about the title of this blog post? This Thursday, all interns were invited to a lecture by J. Allard, and the e-mail said that they would be doing a raffle drawing for one Zune for all the interns after the lecture, but instead they gave away a free Zune for every single one of us! Pretty cool!

I haven't used it too much yet, but so far it looks very good. With it came a 14 day Zune subscription pass, which enables you to download most songs from the Zune on line store for free, which is pretty cool.

I plan to write a few blog posts about how you get an internship at Microsoft, and what it is like, so stay tuned :-)

Below is a picture of a part of the main campus with building 35, where I work, highlighted:

campus_aerial_3_web.jpg

posted on Monday, 23 July 2007 00:28:03 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Thursday, 17 May 2007

I am studying for my exam in Performance Engineering these days, and came across a nice way of estimating Pi in the chapter about Monte Carlo simulations (random number simulations) yesterday. The idea is that you use random numbers to estimate something, in this case the number Pi.

Let's take a look at the figure below. Here we have the unit circle (a circle with radius 1 and center in origo) drawn in a coordinate system. Up to the right, in the first quadrant, I have shaded a square area with sides of length 1.

circle.png

As you probably should remember from school, the area of a circle is A = Pi * r^2, and this circle therefore has an area of A = Pi * 1^2 = Pi. One fourth of the circle is in the shaded area, and this part of the circle therefore has the area Pi / 4. The shaded area itself has an area of 1 * 1 = 1. Then we define R to be the ratio between the area of the shaded part of the circle and the whole shaded area. This ratio is R = (Pi / 4) / 1 = Pi / 4.

Now, let's imagine throwing darts at the shaded area at random (we do not aim for any specific area). Of all the darts hitting the shaded area, a ratio of them, corresponding to R (since there is equal probability for hitting any part of the square), should hit inside the circle. For instance, if the ratio is 0.7, and 10 darts hit the shaded area, 7 should hit inside the shaded part of the circle.

If we throw a fair amount of darts, we should be able to calculate R using the formula R = DartsInsideGreyCircle / TotalDartsInsideGreyArea. As we have from the paragraph above, R = Pi / 4, which means that Pi = R * 4. We have estimated Pi!

The JavaScript simulation below illustrates this. Click start and watch what happens! If you let it run for a while, the result will actually get quite close to the actual value of Pi.

Coordinates: (x, y) = (0, 0)
Hits inside: 0, hits outside: 0
Ratio: R = HitsInside / (HitsInside + HitsOutside) = 0.
Estimated Pi value: π ≈ 4 * R = 0.
Speed: 1 /s.
Note: If you are reading this through an RSS feed, you may need to open the blog post in a browser to be able to run it.
posted on Wednesday, 16 May 2007 23:26:07 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Monday, 19 March 2007

As many others, I also have a voicemail message box for my cell phone number that the caller gets redirected to if I don't answer the phone in something like 15 seconds. What I've found is that 15 seconds is a pretty short time when the phone is ringing and you need to find out where it is. It is OK if you're sitting right next to it, but if it is in some jacket lying somewhere around you're very likely to miss the call.

Therefore I called my phone company (Telenor) today to find out if it is possible to increase this timeout. I got a rather interesting answer:
Dial **61*<Your Voicemail Number>**<Timeout in seconds># on your phone, and you're done.

I don't know if it works only for Telenor customers, but it's worth a try :-) I also found that on my Windows Mobile phone I can actually change this setting under Settings --> Phone --> Services --> Call Forwarding, so that's maybe a more general solution.

So now I've got 25 seconds to find my phone when it rings :-)

 

posted on Monday, 19 March 2007 01:19:15 (W. Europe Standard Time, UTC+01:00)  #    Comments [2]
 Wednesday, 07 February 2007

During Christmas I took two upgrade exams (70-431: MS SQL 2005 Imp&Maint, 70-553: MCSD to MCPD Part 1) to upgrade my Visual Studio 2003 and SQL Server 2000 certifications to .NET Framework 2.0 and SQL Server 2005. Those combined with two I took in Redmond last summer (70-447: MCDBA to MCITP:DBA, 70-554: MCSD to MCPD Part 2) gave me a bunch of new certifications all at once, more precisely 4 x MCTS, MCITP: DBA and MCPD: Ent.App.Dev.

Then the interesting part: All of those come with welcome kits with diplomas, some also with pins and wallet cards in separate envelopes. Therefore, I was wondering if they were going to put everything in one envelope when I ordered something like 9 welcome kits at once. But they didn't, and here the other day I found my mailbox full of welcome kits :-) Take a look at the picture below where I have spread them out on the bed.

welcomekits.jpg

posted on Wednesday, 07 February 2007 01:59:59 (W. Europe Standard Time, UTC+01:00)  #    Comments [8]
 Wednesday, 20 December 2006

School is out for Christmas (I had my last exam last Friday), so now I have time do fun things, like coding (surprise).

I think algorithmic programming and databases and SQL queries are cool things, so why not combine them? Yesterday I got an idea of implementing some well-known algorithm in SQL, and I figured out that Dijkstra's Shortest Path algorithm should be fun to implement.

Dijkstra's shortest path algorithm finds, well, the shortest path from one vertex to the other vertexes in a weighted graph. The edges have lengths (or costs or whatever), and the shortest path from one vertex to another is the path where the sum of these lengths are as small as possible. Take a look at the illustration below, showing a graph with some Norwegian cities. The shortest path from Trondheim to Fredrikstad has been highlighted (for those of you that know Norway, not very realistic, but let's pretend it is just for the fun of it).
djikstra.gif

The algorithm works like a breadth first search that takes the edge weights into account, starting at one vertex and traversing through the graph.

So, how do we implement this in Transact-SQL (MS SQL Server's SQL dialect)? Well, first we need some way to represent the graph. I've created two tables:

City
city.jpg
Road
road.jpg

The City table is pretty straightforward. The Road table contains one row for every road from one city to another, and the length of that road. Notice that we have two rows for every two cities we have a road between them, one each way. But, now to the real stuff: The implementation of the algorithm:

CREATE PROCEDURE [dbo].[Dijkstra]
    @StartCity Int
AS
BEGIN
    -- Automatically rollback the transaction if something goes wrong.    
    SET XACT_ABORT ON    
    BEGIN TRAN
    
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Create a temporary table for storing the estimates as the algorithm runs
    CREATE TABLE #CityList
    (
        CityId Int NOT NULL,    -- The City Id
        Estimate Int NOT NULL,    -- What is the distance to this city, so far?
        Predecessor Int NULL,    -- The city we came from to get to this city with this distance.
        Done bit NOT NULL        -- Are we done with this city yet (is the estimate the final distance)?
    )

    -- Fill the temporary table with initial data
    INSERT INTO #CityList (CityId, Estimate, Predecessor, Done)
    SELECT CityId, 2147483647, NULL, 0 FROM City
    
    -- Set the estimate for the city we start in to be 0.
    UPDATE #CityList SET Estimate = 0 WHERE CityID = @StartCity
    IF @@rowcount <> 1
    BEGIN
        RAISERROR ('Couldn''t set start city', 11, 1)
        ROLLBACK TRAN        
        RETURN
    END

    DECLARE @FromCity Int, @CurrentEstimate Int

    -- Run the algorithm until we decide that we are finished
    WHILE 1=1
    BEGIN
        -- Reset the variable, so we can detect getting no records in the next step.
        SELECT @FromCity = NULL

        -- Select the CityID and current estimate for a city not done, with the lowest estimate.
        SELECT TOP 1 @FromCity = CityId, @CurrentEstimate = Estimate
        FROM #CityList WHERE Done = 0 AND Estimate < 2147483647
        ORDER BY Estimate
        
        -- Stop if we have no more unvisited, reachable cities.
        IF @FromCity IS NULL BREAK

        -- We are now done with this city.
        UPDATE #CityList SET Done = 1 WHERE CityId = @FromCity

        -- Update the estimates to all neighbour cities of this one (all the cities
        -- there are roads to from this city). Only update the estimate if the new
        -- proposal (to go via the current city) is better (lower).
        UPDATE #CityList SET #CityList.Estimate = @CurrentEstimate + Road.Distance,
            #CityList.Predecessor = @FromCity
        FROM #CityList INNER JOIN Road ON #CityList.CityID = Road.ToCity
        WHERE Road.FromCity = @FromCity AND (@CurrentEstimate + Road.Distance) < #CityList.Estimate
        
    END
    
    -- Select the results.
    SELECT City1.Name AS ToCity, Estimate AS Distance, city2.Name AS Predecessor FROM #CityList
    INNER JOIN City city1 ON #CityList.CityId = City1.CityID
    LEFT OUTER JOIN City city2 ON #CityList.Predecessor = city2.CityID
    
    -- Drop the temp table.
    DROP TABLE #CityList
    
    COMMIT TRAN
END

If we run it with Trondheim as start city (@StartCity = 1), we get this result table:

result.jpg

This says that from Trondheim, we have a distance 0 to Trondheim, 2 to Bergen and so on, and 6 to Fredrikstad. The Predecessor column says what city we came from when we went to each city. We can see that to get to Fredrikstad, we came from Oslo, and to get to Oslo, we came from Bergen. To get to Bergen, we came from Trondheim. Therefore, to get to Fredrikstad, we took the path Trondheim, Bergen, Oslo, Fredrikstad.

I have included the SQL script to create the database:

Dijkstra.txt (8,03 KB)
TestScript.txt (1,26 KB)

posted on Wednesday, 20 December 2006 17:45:10 (W. Europe Standard Time, UTC+01:00)  #    Comments [12]
 Sunday, 05 November 2006

A couple of months ago my team from Imagine Cup (Team NTNU) got an invitation to TechEd 2006 in Barcelona from the organizers of Imagine Cup and Microsoft EMEA.

We are going to present our solution and talk a little about our experience in India to the students attending TechEd. We're maybe also going to have a booth with some posters and stuff where we can show our solution. TechEd starts on Monday, so now it's time to get to Barcelona.

It's also going to be exciting to see all the new stuff they are going to show at TechEd. I've never attended a developer conference at this scale, so this is going to be interesting!

posted on Sunday, 05 November 2006 01:28:35 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Friday, 03 November 2006

On Wednesday Gøran and I held the third lecture in the .NET course I mentioned in the last blog post. This time it was about Windows Workflow Foundation, which is a very cool product. I'm looking forward to testing it more. The lecture was recorded on video this time too, see links below (only in Norwegian this time too, unfortunately).

Part 1:
http://multimedie.adm.ntnu.no/mediasite/viewer/?peid=0c87d69b-90e1-4452-a264-3134b2c46970

Part 2:
http://multimedie.adm.ntnu.no/mediasite/viewer/?peid=2f71abd7-7d52-4e6d-a2ce-efd334d2c478

posted on Friday, 03 November 2006 23:57:47 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Friday, 13 October 2006

It has long irritated me that NTNU - The Norwegian University of Science and Technology - doesn't offer ANY courses on Microsoft Technology whatsoever, at least as far as I know. We're only learning Java and other stuff, and .NET and C# are lucky to be mentioned at the end of a sentence. The foremost university in the country should take a look at the figures for which technologies are really used by software companies today.

But, things are starting to change, but not exactly in the way I expected them to:

  1. It is not my department, the Department of Computer and Information Science (IDI) that is responsible for the change, but the Department of Engineering Design and Materials! The first .NET course at NTNU is not hosted by the computer science people, but by the engineering design and materials people! Come on, IDI, take the hint! Look outside your own little Java sandbox.
  2. Guess who is holding the lectures! It's Rune Zakariassen from Microsoft, me and a friend of mine, Gøran, from Microsoft Student Community NTNU. That's pretty cool!

The course is a preparation study for 5th year students starting on their diploma assignment, and consists of four seminars with lectures and hands-on labs. The first one was an introduction to .NET and C#. The second one, held this Wednesday was about Windows Communication Foundation (WCF), and the two next ones will be about Windows Workflow Foundation (WF) and real time communication. The idea behind the course is to give the students a superficial knowledge about these technologies so they can use them in their assignments.

The lectures were recorded on video. Here are the videos from the WCF lecture (in Norwegian, unfortunately):

Part 1: http://multimedie.adm.ntnu.no/mediasite/viewer/?peid=ac76f55b-9779-46d2-bc80-f789d3e1b469
Part 2: http://multimedie.adm.ntnu.no/mediasite/viewer/?peid=45f281b4-ae25-46d1-bfc9-d0d81ca6f140

posted on Friday, 13 October 2006 02:30:32 (W. Europe Standard Time, UTC+01:00)  #    Comments [7]