Friday, April 28, 2006

TDD Last night

Normally I don't post about life stuff but this is code related. Last night I went to the first edmonton .NET user group meeting and had a great time. Jean-Paul Boodhoo was the presenter and did a great talk about test driven development amongst other things.

I have read about TDD and all sorts of patterns books but found them hard to know when to apply them in the real world. JP's presentation was a begging to middle (we ran out of time unfortunately) coding sesssion using TDD to build an application. The cool thing was that we built the application from the presentation tier down pretending that other teams were doing the data / domain / service layer work.

Here were some of the cool things covered:
Rhino Mock - A cool framework to build mock objects
Resharper - A great time saver when doing TDD
Interface driven development - I have to admit that this presentation made this concept so crystal clear I might make a full post about it.
Model View Presenter - This changed my life. Check JP's blog for his videos on this.

I see know what TDD is and how powerfull it is for keeping your code clean and simple (if you have not heard it before TDD is not a testing model, it is a design model).

My only complaint about the presentation is that it was not long enough. The presentation was 2 hours but I would have loved to see the project be finished. But beer, food, and hockey were calling! :)

JP's blog -
Edmonton .NET user group -

Monday, April 17, 2006

Globalization Link

Here is an interesting article about number grouping in different countries.

Monday, April 03, 2006

Canadian Law And The Web Part 3: Peer 2 Peer

Now this is not really a development talk but there is a lot of concern about the legalities of downloading music in Canada and I thought I would set the record straight on it. Part of Canadian copyright grants a fair use for copying things for personal enjoyment as long as it is not shared or sold publically.

We actually pay a levy on all media (i.e. blank cassette tapes, blank cds and dvds). This levy is a tax to compensate artists for revenue lost to the copying of their works. So technically we already pay to make copies of music. Unfortunately from what I have read is that this money is not making it to the artists at all. The levy has generated about $120 million in the past 5 years. About 25 percent of that has been distributed to the artists.

This still does not mean that it is right for us to download music in my opinion. I had heard of an ISP that included access to a music download service as part of its fee which I really liked the idea of (I can't remember the name of the ISP though). I am very against buying a CD from the store now as it is too expensive and too crappy. I like the idea of only getting the 2 songs from a CD that are good. It encourages the artist to make better music and the labels to reduce prices. Unfortunately instead of seeing this trend these record labels are suing the people downloading music.

In 2004 BMG Canada Inc. Attempted to learn the identities of users who have infringed copyright by trading music on the internet in the case BMG Canada Inc. v. John Doe. This case had a few issues with the evidence they presented (i.e. how a kazaa user was tied to an IP address, not contacting the software manufacturer to see if they could find the identities of the users of the software, along with the time gap between gathering the evidence and bringing it to court).

When BMG Canada Inc. requested the identities they must compensate the ISPs for the expenses arising out of discovering the account holder. The ISPs responded that this was a very intensive process and hard to determine who was using a certain IP at a given time. These records are not held indefinately and might be purged at any time. They also stated that all they could find out was who the account holder was. Not who did the actuall downloading in the home.

The act of downloading is interesting also. Under Section 80 of the Copyright Act it is allowable for a person to make a copy of a musical work for private use of the person who makes the copy. Thus downloading a song for personal use is not an infringement under Canadian Copyright Law.

The act of distribution is key in this case also. Under Candian Copyright a person must authorize the copying of files. Simply placing a file in a shared folder does not count as authorization. It is akin to placing a photocopyer in a public library. If you were to send out copies or advertise the copies (i.e. chat rooms, websites, etc.) you would be infringing on copyright.

In the end this case was thrown out for many reasons.
The main ones were:
1. Downloading the song is not an infringement
2. Placing the song in a shared folder is not an infringement

Things that weakened the case even further:
1. The company who found the Kazaa and iMesh users did not present enough evidence on how this information was gathered.
2. The time between the information gathering and the court case was long with no explination.
3. Due to the time length and difficulty of finding who was using an IP at a given time innocent people could have been wrongly accused.
4. The actuall person using the computer at that time could not be identified based on the IP address.

One interesting technicallity arrises out of this. If I were to lend you a CD and you made a copy that would be legal under the copyright act. If I took my CD, copied it, and gave it to you that would tecnically be distribution and would be a copyright infringement.

I am unsure how this would apply with me emailing you an mp3. In this case when is copying occurring? I would think it happens on my computer as when it leaves my computer a duplicate is made and sent to you. I think I would have to make it available to you via a P2P application or an FTP server to make it legal.

As you can see the industry does not like this and copyright reform is on the way right now.
-World Intellectual Propery Organization Performances and Phonograms Treaty has some items about making a work publically available but is not currently in a Canadian copyright law. This would probablly make it an infringement to share music to the public
-Bill C-60 is waiting to be passed that ammends Candaian copyright law. I have not had a chance to look this over yet but I am sure there are some interesting changed.

Saturday, April 01, 2006

Setting JPEG image quality

I have many applications that create thumbnails or manipulate images. When I save these as jpegs the quality kind of sucks though. Took me a while but found a way to set it by way of using one of the overloads to pass the encoder to use (in this case the jpeg encoder) and parameters to that encoder.

Here is the method taht finds the right encoder based on mime type:

1 private static ImageCodecInfo GetEncoderInfo(String MimeType)

2 {

3 ImageCodecInfo Result = null;

4 ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();

5 for(int i = 0; Result == null && i <>

6 {

7 if (Encoders[i].MimeType == MimeType)

8 {

9 Result = Encoders[i];

10 }

11 }

12 return Result;

13 }

Here is the code that actually saves the file:

30 EncoderParameters encoderParameters;

31 encoderParameters = new EncoderParameters(1);

32 encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);

33 img.Save(ms, GetEncoderInfo("image/jpeg"), encoderParameters );

The thing that tripped me up for a while was the 100L for the quality. If I left the L off then the quality would not be changed strangely enough.

~ = friend

One of those nice little things not many people know about is the use of a ~ character in relative URLS. The ~ allows you to access the document root.

i.e. Show the log

If this was in a virtual directory called sampleapp the url would render to be


but when deployed to a production and not in a sample app it would be

if we just had a link without the tilde like this:
i.e. Show the log

then it would work in production but in development it would render to the root of the server
i.e. http://localhost/showlog.aspx
instead of the vdir like we want :)

Just a little trick. I am not sure if this works on apache or not or if IIS is finding those ~'s and replacing them for the user.