Thursday, September 27, 2007
No, not PowerShell.
I have been having fun measuring how much electricity our house uses, and which appliances are the worst offenders (Oil column heaters = bad, heat pump = good).
The tool I have been using is a Centameter, which is a clever little gadget that you clip onto your mains feed into your house (www.centameter.co.nz). You can also get one for a single power point from Jaycar.
A good idea if you want to reduce the impact your consumption has on the world (and your wallet!)

Kirk

posted on Thursday, September 27, 2007 9:16:32 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [2]
 Friday, September 21, 2007
James Newkirk and Brad Wilson have cooked up a new testing framework for .NET development: xUnit.net.

In his blog post announcing xUnit.net, James outlined the reasons why they have created a new framework -- primarily to bake best practice techniques into the test framework, and leverage some of the newer .NET features.

The Comparison between Nunit, MSTest and xUnit.net page on the site lists some of the differences between xUnit.net and Nunit / MSTest. Removing setup and teardown, and providing aspect-like functionality are both interesting angles which I want to spend some time with.

Here's a couple of examples from the samples download. First, an example of usage of BeforeAfterTestAttributes, which let you add behaviour before and after the execution of a test (ala AOP):

[Test, TracingSplicer]
public void TestThis()
{
}

...

public class TracingSplicerAttribute : BeforeAfterTestAttribute
{
    public override void Before(MethodInfo methodUnderTest)
    {
        Console.WriteLine("Before : {0}.{1}",
            methodUnderTest.DeclaringType.FullName, methodUnderTest.Name);
    }

    public override void After(MethodInfo methodUnderTest)
    {
        Console.WriteLine("After : {0}.{1}",
            methodUnderTest.DeclaringType.FullName, methodUnderTest.Name);
    }
}


Here's an example of test method extensibility:

[RepeatTest(5, Timeout=500)]
public void RepeatingTestMethod()

You can create your own attributes that inherit from the TestAttribute base class, and define what will happen when the test runs (in this example, the test will run 5 times).


Good work guys, looks useful!

Kirk
posted on Friday, September 21, 2007 10:03:26 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Thursday, September 20, 2007
If you've been a Perl programmer, you've probably used File::Temp occasionally, to generate unique filenames for temporary files and clean up afterwards. In other lanuages you may have used a variation of the standard POSIX tmpnam or tmpfile.

In PowerShell, you'll often need to generate temporary files, especially if you're working with import-csv or import-clixml -- as they don't support data on the pipeline.

There's not (yet) anything I could find that is quite as nice as File::Temp, but if you want to generate a unique filename or directory name, or create a temp file on disk ready to be used, you can use these methods on System.IO.Path:

System.IO.Path.GetRandomFileName() [msdn]
Returns a random folder name or file name. The filename generated is cryptographically secure, meaning that no malicious script should be able to guess what filename you've just been given.

To use from PowerShell:
53> $filename = [System.IO.Path]::GetRandomFileName()
54> $filename
lbhrurye.uhp
55> Get-ChildItem > $filename


System.IO.Path.GetTempFileName() [msdn]
This method will actually create a temporary file on disk, in your temp directory (returned by System.IO.Path.GetTempPath). The file is 0 bytes, and ready for you to clobber with your own content. You can be sure that no other process has generated the same filename, but it's not exactly a secret what filename you've got -- you should use the GetRandomFileName method if you need a bit of security.

To use from PowerShell:
59> $filename = [System.IO.Path]::GetTempFileName()
60> get-childitem | export-csv $filename

The other thing to remember with GetTempFileName is that you need to remember to delete the temp file after you're finished (something that File::Temp does quite nicely for Perl'ers). Some day I might write a wrapper that deletes the file when the variable goes out of scope.

posted on Thursday, September 20, 2007 9:08:25 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Monday, September 17, 2007
Darryl Burling has been posting a series on starting and running a user group for the new site mscommunities.net.nz. He asked me to write a post on "Speakers, topics, costs, refreshments", which he has now posted:

"Continuity, speakers and good running"

The most interesting part for me was adding up how many user group events we have had in Wellington (about 45), and how many pizzas I have ordered (approx 800!). If anyone from Pizza Hut or Dominos is reading this, they should get in touch with a discount offer!

Details of all our previous meetings are available on the Wellington .NET user group site, and on the old website.

As I posted earlier, this week Andrew Tokeley is presenting Dynamic Data Controls - come along.

posted on Monday, September 17, 2007 8:09:15 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [1]
 Sunday, September 16, 2007
Joe Duffy links to a new MSDN Magazine article on PLINQ: "Parallel LINQ - Running Queries on Multiple Processors".

We have been hearing little bits about PLINQ, and a CTP is on the way. PLINQ redefines the query operators from standard LINQ and makes them split the work across multiple processors.

One of the big challenges that we will have as software developers over the coming years is developing for multiple cores. As extra processors and cores are added to our PC's, the clock speed of the machine isn't increasing as rapidly as in the past, so single-threaded applications may actually run slower than on a high-end single processor machine.

PLINQ takes an interesting approach, and redefines the standard LINQ operators that are used for in-memory queries (such as OrderBy, Join, Where etc), and spreads the work over the available CPUs. As LINQ uses a declarative "Tell me what to do, not how to do it" query syntax, there are hardly any changes to the programming model:
  • Reference the System.Concurrency.dll assembly during compilation.
  • Wrap your data source in an IParallelEnumerable<T> with a call to the System.Linq.ParallelEnumerable.AsParallel extension method.
    • i.e. var q = from x in data.AsParallel() ...
  • Optional: choose your pipelining model: pipelined, stop and go, inverted enumeration. You choose this when processing the results.
  • Don't rely on LINQ's default ordering of results. Explicitly order results if it's important to your program.
  • Change the way you handle exceptions. Multiple exceptions may be thrown in the course of one query, and with PLINQ will be wrapped into a MultipleFailuresException.
  • Avoid modifying data in your where clause, or otherwise mutating shared state during the course of your LINQ query. You may open yourself to race conditions.
All of these steps are covered in depth in the article, but on the surface of it, it looks like Joe and the PLINQ team have made the transition from single to parallel LINQ require as little work as possible. I can't wait to try it out when the CTP drops!

Note that PLINQ only applies to LINQ to Objects and LINQ to Xml queries -- SQL Server still does it's own parallel processing. PLINQ parallelises the query execution that occurs within the .NET program.

posted on Sunday, September 16, 2007 6:56:32 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Thursday, September 13, 2007
I really enjoy organising the Wellington user group sessions.

Last week, Matti Seikula did an interesting session on spatial software development and Virtual Earth. I've seen a bit of mapping stuff over the past few years, but Matti did a really good job of explaining the various coordinate systems, and how you can layer different information over (and under) the data displayed in two and three dimensions in Virtual Earth.

Next week on Wednesday 19th, Andrew Tokeley is going to be presenting the Dynamic Data Controls (from ASP.NET futures), which are useful for making data-driven web apps.

Have a look at the Wellington user group page, and RSVP now :)

posted on Thursday, September 13, 2007 9:22:07 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Monday, September 10, 2007
Scott Adams hits the nail on the head:
http://www.dilbert.com/comics/dilbert/archive/dilbert-20070909.html

Scott's Dilbert Blog is recommended daily reading...

posted on Monday, September 10, 2007 8:43:19 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]

Okay, so I'm a sucker for these internet quizes:

NerdTests.com says I'm a Highly Dorky Nerd King.  What are you?  Click here!

The fun facts displayed after you take the test were amusing (and no, I wasn't one of the 28.3%):


Quick Fun Facts:

96616 unique people have taken this test.

Based on these unique user's answers...

44.8% of test takers are gals,
53.1% are guys,
...the rest (2.1%) are confused.

17.1% of test takers get aroused by "iPhone," while
40.6% get utterly ill.

34.6% of all test takers would choose the Internet over sex, and
28.3% of married test takers prefer the Internet over sex.

Only 3.6% of test takers own a Jar Jar Binks t-shirt, though
56.0% of them don't own a lightsaber (priorities == messed up).

posted on Monday, September 10, 2007 8:37:58 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Saturday, September 08, 2007

Want to transfer your cheezburger skillz to the command prompt? Navigate your files using lolshell.

Download lolshell.ps1 [Requires PowerShell 1.0]

To give you a taste of the awesome powers of lolshell, here's a transcript. My favourite function is WTF.

1> . ./lolshell.ps1

 |\_/|
 (. .)
  =w= (\
 / ^ \//
(|| ||)
,""_""_ .

IM IN UR SHEL FIDLNG UR BITS

2> IM IN UR C DRIVE
KTHX

3> IM WATCHN YR VIDEOS
VIDEOS WATCHN U

4> WARE AM I?
LOL. I CAN SEEZ U HRE: C:\Users\kirk\Videos

5> GIMMEH ALL MI FILZ


    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\kirk\Vi
    deos


Mode           LastWriteTime       Length Name                       
----           -------------       ------ ----                       
-a---  28/02/2007 12:40 a.m.     14882401 Vista_0001.wmv             
-a---  28/02/2007 11:10 p.m.     14816631 Vista_0002.wmv             


6> IM WATCHN YR Vista_0001.wmv
                                [Video opens in Media Player]

7> WARE AM I?
LOL. I CAN SEEZ U HRE: C:\Users\kirk\Videos

8> IM WATCHN YR MOMMA
U GO 'WAY

9> WARE AM I?
LOL. I CAN SEEZ U HRE: C:\Users\kirk

10> IM IN UR Z DRIVE
OMGWTF?!

11> WTF JUST HAPND?
WTF?
LOL. HAPND JUST lolshell :)
Cannot find drive. A drive with name 'Z' does not exist.


12> HOW DUZ I PRINT?

NAME
    Out-Printer

SYNOPSIS
    Sends output to a printer.
...                             [More help prints here]

13> OKTHXBYE

lolshell.ps1 (3.5 KB)
posted on Saturday, September 08, 2007 11:05:13 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Wednesday, September 05, 2007
Well this was interesting - Microsoft have embraced Mono's Moonlight as their official Linux version of Silverlight. From Scott's blog post:

Over the last few months we've been working to enable Silverlight support on Linux, and today we are announcing a formal partnership with Novell to provide a great Silverlight implementation for Linux.  Microsoft will be delivering Silverlight Media Codecs for Linux, and Novell will be building a 100% compatible Silverlight runtime implementation called "Moonlight".
I think it's interesting for several reasons -- Microsoft partnering with Novell to release an open-source version of Silverlight, when the Windows / Mac one is closed; and that they are planning to make Moonlight "100% compatible".

100% compatability is a pretty strong statement. I know that the Mono project has been aiming for that for a while, but has had to work around bugs or inconsistencies in the CLR to achieve it. I wonder how Microsoft is helping Novell achieve that?

Miguel has some details on who was involved from within Microsoft, and how the test suite will be shared between the two companies.

posted on Wednesday, September 05, 2007 10:21:16 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]