# Wednesday, August 26, 2009

So, it didn’t occur to me until today that I was creating a trilogy here.

If I had thought about it ahead of time, I would’ve given my titles more creative names like “devLink”, “devLink Strikes Back” and “the Return of devLink.” The true test will be to see if the second post is everyone’s favorite.

Obligatory Ewoks for the 3rd movie... errr post.

Oh well. Maybe next year.

Managed Rootkits

The first session I went to on Saturday was an Open Spaces session on Managed Rootkits convened by Bill Sempf.

Before I continue, read that sentence again. Didn’t see it yet? Here’s a hint: Managed Rootkits. You know, managed… as in managed langauges… like .NET. Get your attention yet? It did mine, which is why I showed up! Of course, I expected to be completely lost because, in my mind, rootkits are hard stuff that take a computer genius to find and fix. Surprisingly though, the concept behind managed rootkits is easy.

But first, some background. Bill had attended Defcon which is where he had originally heard about managed rootkits in the first place (note that his post links to a page that includes a demonstration). That’s how the entire session came to be.

So, wanna know how to hack the framework?

First, take mscorlib. (that’s the primary .NET assembly by the way)

Next, take ildasm. (that’s the MSIL Disassembler – the built-in Reflector if you will)

Disassemble mscorlib into IL.

Write your own IL and paste it in the IL you got from disassembling mscorlib.

Find ilasm on your machine. (you guessed it, that’s the .NET Assembler)

Assemble your modified IL into a new mscorlib.

Drop it in the GAC.

You L33T hacker you.

The entire reason this works is because, once an assembly has been installed into the GAC, the framework doesn’t run additional checks to verify that the assembly matches the hash in its strong name. So yeah, strong naming doesn’t protect assemblies.

Once we were all up to speed on the logistics, we discussed if this was, in fact, a zero day exploit. It’s not. Why? Because you still have to have administrative privileges to modify any files in the GAC. As Raymond Chen points out, “if you have full trust, then you can do anything.”

Anyway, it was a very interesting conversation. I made the point that, even if it isn’t a security vulnerability, there is the whole user perception issue. For example, if an assembly that your application uses is modified so that it posts your credit card information out on the internet, network trace tools are going to show that it is your application that is connecting to the internet. If your computer were already infiltrated to the point that someone could modify mscorlib on your machine, though, managed rootkits likely aren’t your biggest concern. Oh well, it sounded like a good argument at the time.

Domain Driven Design

The next session I attended was on Domain Driven Design with Craig Berntson. Here’s the synopsis from his blog:

Domain Driven Design is a way to design and develop enterprise applications so that they are easier to maintain, enhance, and extend. DDD is overkill for many of the applications we develop today, but still has principles that can be applied to most of the apps we write. In this session, you will learn to apply these concepts.

My personal feelings regarding this talk was that he did an excellent job at actually communicating DDD. He contrasted the typical data-driven design for applications to driving the design of the system from the business domain. He also did a good job of explaining it in terms that everyone could understand. It was a very good talk.

Lunch over Open Spaces

Over lunch, I went back to the Open Spaces area to see if there were any sessions going on then. A group of people were all sitting in one area so I assumed it was going to be a great conversation. It certainly was, but it wasn’t a planned session. It wasn’t even technical in nature at times… I remember discussing favorite Family Guy episodes at one point…

Architecting Architectural Stuff

My last session was on Architecting Modern Distributed Applications with Clint Edmonson. He has posted his slides and thoughts on the conference on his blog. He shared a diagram that he had seen at an internal Microsoft presentation that showed the various architectural layers in typical applications and showed how you could use the diagram to help make decisions like self-hosting versus hosted solutions versus moving entirely to the cloud. A comment he made in passing but that I thought had a lot of merit was adding in a ping operation to all of your services so that you can quickly and easily determine the state of what is working and what isn’t. I know hardware almost always has this, but I hadn’t really considered putting it in software. I know, you’ve probably been doing it for years.

Closing Circle

At the end of the day, I went to the Open Spaces closing circle where we went over the week, discussed how we could more effectively publicize Open Spaces to the rest of the conference attendees, and other things related to the conference. I was a jerk and had to leave early, but it was all positive while I was in the room. I’m pretty sure it didn’t erupt or anything after I left :-)

Once again, kudos to John Kellar and team for planning another amazing devLink. If you’re interested in seeing more and better pictures than I’ll ever be able to take, David Giard has posted a link to his pictures on his blog. If you weren’t able to attend this year, go next year.

posted on Wednesday, August 26, 2009 1:24:17 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Tuesday, August 25, 2009

Yesterday, I blogged about the first day of devLink – today, I’ll continue the recap with, you guessed it, day 2.

The Open Spaces side of devLink started on day two, so that’s where I went. Like last year, Alan Stevens kicked everything off with the opening circle. (if you’re unclear on the Open Spaces concept, I gave it more time in my post from last year)

Convening my first open space session

Last year, I didn’t have the guts to jump out there and provide a topic that I wanted to convene. This year, though, I thought I’d give it a try. So, I threw out Event Driven Architecture using tools like MassTransit or nServiceBus. Of course, when I brought it forward, I only said MassTransit and a few people came up to ask if I was referring to “mass transit” as in buses or trains. I guess I could’ve been more clear in my explanation. My primary purpose in picking this topic was entirely selfish – I hoped that someone would show up who knew more about it and they could do most of the talking!

Let’s just say it didn’t quite work out that way :-)

I still think it went well. I ended up going over the very basics of EDA and MassTransit and having a discussion about how EDA can vastly decrease coupling in applications as well as how it also completely changes the way a system is architected over all. Interestingly enough, Maggie Longshore mentioned that, in embedded software development, messaging was the norm instead of the typical “call a webservice and wait” that is typical of .NET code. I also spoke about the similarities between EDA and UI patterns like the event aggregator. I mentioned Udi Dahan’s domain events post as well. During our discussion, Jim Wooley mentioned Linq to Events (or the Rx Framework) and pointed everyone to an introductory article on the Rx Framework. I’m still trying to wrap my head around that post!

Towards the end, the conversation drifted off into… just about everything else. We spoke about adding scripting functionality to applications (using tools like PowerShell, IronRuby or IronPython). As the convener, it was my role to ensure the conversation stayed on topic, but I was having fun just jumping around to different topics at the end. I think it went well.

jQuery Plugins are cool

Next, I went to an “eyes front” session from Elijah Manor on writing jQuery plugins. He has posted the slides from his presentation on his blog. Having read “the world’s most misunderstood programming language” from Douglas Crockford, I now consider myself somewhat of a JavaScript fanboy so I really enjoyed the talk. My hands-on experience with jQuery has been fairly limited up to this point and really only included using the Lightbox plugin and a few other tools, so the session was an eye opener. Probably one of my favorite parts of the talk was when Elijah shared some must have developer bookmarklets. I had heard of Firebug Lite before, but the jQuery specific bookmarklets were new to me.

Mono is cool, too

After Elijah’s talk, I went to Sarah Dutkiewicz’s talk on cross platform C# using Mono. I’ve been following Mono from a distance for a few years, so it was good to hear Sarah’s talk. After her presentation, we spoke about things like MonoDevelop, Banshee and other open source things. I wasn’t able to keep up entirely because my Mono experience thus far includes opening MonoDevelop and building Hello World, reading Miguel de Icaza’s blog, and listening to the Hanselminutes episode on Mono and Banshee.

// TODO: Add Mono to the list of cool things to look at some day!

Learning Rails in the hallway

On the way back to the Open Spaces room, I ran into a group of people learning Rails from Leon in the hallway. Note that this wasn’t a planned session - it just happened. Two or three people were sitting on a bench in the hall while everyone else was sitting in the floor. Most had laptops, but a few were looking over shoulders. If I can find a picture, I’ll post it – a picture would communicate this a lot better than I can.

Impromptu Rails Session

UPDATE: thanks to Matt Brewer for providing a link to the above picture of the impromptu Rails learning session with Leon – and thanks to John Kellar for posting it to his Facebook photo album!

Final Open Spaces Session on… I’m not entirely sure

I was convinced that the final session of the day was on distributed source control. Later, I think I heard it was on DSLs (domain specific languages). In either case, it turned into another fun and random conversation.

I’ll finish up the devLink review covering day 3 soon!

posted on Tuesday, August 25, 2009 1:35:57 PM (Central Daylight Time, UTC-05:00)  #    Comments [4]
# Monday, August 24, 2009

I’ve now attended devLink three times, with each time getting progressively better. This year marked the first time for devLink to be split across three days (from Thursday, August 13 through Saturday, August 15). Day one included preconference-like sessions that were longer in length with days two and three more closely resembling prior years. Like last year, this year also included Open Spaces, which ran over days two and three.

Ruby Enlightenment

My first session of devLink was with Leon Gersing covering Ruby-Koans: Path to Ruby Enlightenment. Let me start this way – I have never been to a session that was presented in quite the way that Leon gave this presentation. Let me give my alternate title for this presentation: “Learning Ruby through Pair Programming using Test Driven Development.” It was amazing. The guys at EdgeCase have created an open source library called Ruby Koans. From the project’s README:

The Ruby Koans walk you along the path to enlightenment in order to learn Ruby. The goal is to learn the Ruby language, syntax, structure, and some common functions and libraries. We also teach you culture. Testing is not just something we pay lip service to, but something we live. It is essential in your quest to learn and do great things in the language.

Leon helped everyone get Ruby othat was done, we broke up into pairs and went through the koans. Leon walked around the room and helped whenever someone ran into a question or a problem.

Let me share the first koan with you as an example. Pull up your favorite command prompt and go to the directory where you extracted ruby_koans. Once in that directory, run rake (rake is to ruby as make is to C or as nant/msbuild is to C#/VB.NET).

Running Ruby Koans

The rake file changes the directory to the koans directory and then executes the various ruby files in it, which are unit tests. The first test fails in the ./about_basics.rb file on line 10. Here is what that file looks like:

Ruby Koan 1

You don’t really even have to know programming to see what you should do here. Just change the false to be true to get your test to pass. Once that is done, move to the next test and so on.

The koans start at the simplest level and then move up to higher levels of complexity to expose you the Ruby language.

Thanks to Leon for sharing this with us and helping to bring us all closer to Ruby enlightenment!

Ruby Koans session

(thanks to the devLink site for the above picture of the Ruby Koans session)

Closures Explained

The next session was with Chris Smith on closures, lambda calculus, and functional programming with both C# and F#. I already had a basic understanding of closures, but I got a lot more from this talk. Surprisingly, lambda calculus’s name is far more complex than the actual concepts that it introduces. Unfortunately, I still can’t read more than half of the F# examples out there. I seriously need to try it out on some personal projects to understand it. Luckily, the ideas behind it are more solid now. Great job Chris!

The Lost Art of Simplicity

The opening keynote was presented by Josh Holmes on the Lost Art of Simplicity. He posted the slides from when he gave his presentation earlier in the year, so I won’t spend a lot of time speaking on it. I do want to share a few thoughts that I got from it, though.

Josh brought up the thinking that a lot of developers have when they see an application or other project: “I could build that in a weekend.” I saw this thinking a lot from people when stackoverflow.com was built. Josh pointed out the disconnect between this and then explaining to our users that a new feature will take eight months.

That sort of hit me in the gut :-)

He’s right, of course – we do this all the time, particularly in “enterprise” development.

Another comment he brought up that was both true and funny at the same time is that we as developers don’t speak human, we speak geek. How right he is.

 

And now for something completely different…

Lunch boxes do more than carry food

They carry code. Below is a picture that Micky McQuade took of me trying to explain closures of all things to Anthony Ford. My communication skills were lacking at the time, so I decided to try to communicate with code and, seeing as how the lunch box was the closest writing medium I could find, I used it.

Me writing on a lunch box

The code snippet below is approximately something like:

void Foo()
{
   var x = 5;
   var nums = new List { 1, 2, 3 };
   nums.ForEach(n => Console.WriteLine(x));
}

I wanted to show how, if the lambda were moved out to its own function, it wouldn’t be able to access the x variable.

Code on a lunch box

posted on Monday, August 24, 2009 10:35:17 AM (Central Daylight Time, UTC-05:00)  #    Comments [1]
# Sunday, July 12, 2009

If you seriously still haven’t heard or used PowerShell yet, come to my Little Rock DNUG presentation on the topic on Monday, July 13. Or, if you’re busy Monday night because you’re going to hear Keith Elder speak on Velocity to the Fort Smith DNUG, then come Tuesday night to hear me give my PowerShell presentation to the Conway DNUG instead!

I’ve never given a talk two days in a row, so this will be a new experience for me. If you’re interested in the content, I’m trying to keep my presentation notes and related files up on one of my github projects. I’m finding that the whole distributed source control works well for me for accessing and working on my presentation from all different areas and computers.

If you’re at the meeting, stop by and say hi!

posted on Sunday, July 12, 2009 2:28:28 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Friday, June 12, 2009

Never heard of ack? Well, by ack’s admission, it is “better than grep.” That’s up to you to decide, but it does make searching code easier than grep.

As a means of illustration, here is a grep example of a recursive search for StringBuilder across multiple C# files that I used back in my post on “finding stuff quickly.”

The output is pretty nice, but the addition of the find command to limit the searching to only C# files isn’t the easiest to type quickly.

ack makes this a little… well, a lot easier.

image

Nice! Even EASIER to read than the grep matching. And it is easier to type.

Well, of course, I had to add this functionality to Find-String. (Guess what, it runs faster than grep and ack both! At least on Windows…)

image

Now, this makes… the third post I’ve had on a Find-String PowerShell script I think. At some point, you’re going to get tired of this if you haven’t already.

“Is this guy seriously going to post every time he changes the way Find-String works?”

No, no, I guess I shouldn’t.

But for my own benefit, I do want this in source control. And I’d like to make it easier to use and find this. I’ve been using a local SVN repository for my changes to my scripts, but they included all of my scripts. Well, I moved just the Find-String source over to GitHub yesterday. I even started from the initial version of Find-String and committed my change history over from SVN :-)

image

For up to date versions of Find-String, they’ll be out there. The URL is http://github.com/drmohundro/Find-String/tree/master. If you don’t want to install git to check the source out, there is a big download button on the project page. It will package up the current version of Find-String for you which you can then download and use to your heart’s content.

If you improve upon the script, send me pull requests or a patch and I’d be happy to make it better.

 

Warning, upcoming tangent regarding GitHub adding PowerShell syntax support…

My other hope with posting this is that maybe GitHub will add the PowerShell syntax support to GitHub. If you view the source for Find-String on the GitHub website, you won’t see any syntax highlighting.

image

But… they have syntax highlighting for lots of other file types, as is evidenced by the gists I’ve already shared.

image

I already asked for this on the GitHub support site, but it was inexplicably closed with “no more actions from GitHub… are required” and that it is apparently “resolved.” Maybe I shouldn’t worry and the feature just hasn’t gone live yet. In which case, I’m just blabbing on and on for no reason and creating a long tangent to the rest of my post. If not, well, maybe they’ll add support if I complain some more!

posted on Friday, June 12, 2009 7:58:18 AM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Tuesday, May 19, 2009

I’ve been attempting to learn NHibernate lately. One of the big draws for me was the ability to write unit tests that did hit a database, but an in-memory one. Ayende recently posted on how to use SQLite to get in-memory unit tests. His example assumed standard hbm mappings and configuration.

I was curious how hard it would be port his example over to Fluent NHibernate. Not surprisingly, it was quite easy actually!

Here’s the Blog entity I used, which is based on the usage I saw from Ayende’s post:

And here is the mapping:

As you can see, it is pretty straight forward so far. The next piece of code is the Fluent NHibernate implementation of Ayende’s InMemoryDatabaseTest.

There aren’t too many differences really. We’re using the same SchemaExport, but we do need to call ExposeConfiguration so that we can store off a reference to the Configuration to be used by the SchemaExport instance.

The final piece, the actual test itself, is identical to Ayende’s example, except that I’m using MbUnit instead of xUnit:

Nice and easy! I like it!

As you can also tell, I’m experimenting with using github’s gist feature. I’ve been using github to store off my dot files and other environment-related settings as well as my presentations, but the gist feature seems pretty nice.

posted on Tuesday, May 19, 2009 12:34:06 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Tuesday, May 12, 2009

I blogged a while back about finding in files with PowerShell and I wanted to share an update on that.

The original post highlighted using a combination of Get-ChildItem and Select-String to quickly find things. It works fine, but the output isn’t the easiest to read, because the found text isn’t highlighted in any way.

Get-ChildItem –include *.cs –recurse | Select-String searchText

image

I really like the color output that grep provides. Check out the results of grep on the same search.

find –name *.cs | xargs grep StringBuilder

image

That is so much easier to read that it isn’t even funny. The match jumps out at you because of the color difference.

I did some searching and found Wes Haggard’s Find-String script. It had the additional benefit that it also displayed the line number, but it didn’t display the relative path.

find-string.ps1 StringBuilder *.cs -recurse

image

Wes’ script still served my purposes, though, so I used it for a long time until I learned about grep’s Context Line Control arguments. They would let grep print out additional lines before or after the display search result so that you could see the context of your search result. Like so:

find –name *.cs | xargs grep StringBuilder –A 3

image

Unfortunately for me, PowerShell’s Select-String didn’t support context… at least until version 2.

With the addition of the Context parameter, I could now build a nice grep replacement in PowerShell. I broke my version out into two separate scripts: one to actually format the MatchInfo object and one to do the finding. As you might imagine, the formatting script is a little more interesting. You can get Out-ColorMatchInfo at http://poshcode.org/1095 and you can get my version of Find-String at http://poshcode.org/1096.

Here’s sample output:

find-string StringBuilder *.cs –context 0,3

image 

I went with only displaying the relative path to the file on one line and then displaying the results on the following lines. It makes reading context easier for me.

Let me know what you think.

posted on Tuesday, May 12, 2009 2:55:25 PM (Central Daylight Time, UTC-05:00)  #    Comments [3]
# Friday, April 24, 2009

If you’ll be in the northwest Arkansas area tomorrow (April 25), be sure to come out for the NWA Code Camp. There will be presentations on everything ranging from LINQ and Silverlight to iPhone development. I’ll be presenting my PowerShell talk one more time as well. If I can count at all, it looks like there will be 15 different speakers total.

I’m looking forward to it!

image 

Technorati Tags:
posted on Friday, April 24, 2009 7:28:37 AM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Monday, March 30, 2009

This is just a quick post to share a very simple PowerShell script I wrote to extract files from a compressed file (zip, 7z, whatever). When downloading utilities that don’t have installers, like Sysinternals tools, I typically extract them to a Utils directory that is in my PATH. Previously, I would always do this by right-clicking, choosing the 7-Zip context menu option and then extracting to to c:\Utils. Another common option would be to extract to a folder of the same name.

image

I had tried in the past to use the 7-Zip command line tool, but the arguments were not very intuitive or consistent with other command line tools (Windows, Unix, PowerShell or otherwise). So, I got fed up and wrote a script to do it for me. It just shells out to the 7-Zip command line app, but it saves me some time.

The script assumes that you’ve aliased ‘zip’ to the 7z.exe command line executable.

[1] » ls alias:zip

CommandType     Name                                                  Definition
-----------     ----                                                  ----------
Alias           zip                                                   7z

[2] » get-command 7z

CommandType     Name                                                  Definition
-----------     ----                                                  ----------
Application     7z.exe                                                C:\Utils\7z.exe

Here’s the script:

param (
    [string]$file,
    [string]$outputDir = ''
)

if (-not (Test-Path $file)) {
    $file = Resolve-Path $file
}

if ($outputDir -eq '') {
    $outputDir = [System.IO.Path]::GetFileNameWithoutExtension($file)
}

zip e "-o$outputDir" $file

Like I said, pretty basic. If you don’t specify an output directory, it uses the name of the file.

Other people have written scripts that do this, too, but I needed an excuse to publish something on my blog for March :-)

posted on Monday, March 30, 2009 9:55:29 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Wednesday, February 25, 2009

I couldn’t resist borrowing my title from Christopher Bennage’s post entitled “An Essential Tip for Working with XAML.” My “essential tip” is identical to what he has already shown for WPF (and Fabrice originally) – it just applies to Windows Forms instead of WPF :-)

I’ll mix it up some and show with pictures instead of text, though.

Step 1. Right click on a Form, UserControl, or Component and select “Open With…”

image

Step 2. Select “CSharp Editor” and click “Set as Default” - (note that this setting only applies to C# code, though you can perform the identical setup for VB.NET as well)

image

Step 3. Enjoy your delicious, hot meal of faster Visual Studio!

In case you missed it, the real benefit that you get from this setting is that double clicking a file in the Solution Explorer will now go directly to the code instead of defaulting to the designer view. If you want to get to the designer view, just right click and select “View Designer.”

Thanks again to Christopher and Fabrice who did the real work here!

posted on Wednesday, February 25, 2009 10:32:12 AM (Central Standard Time, UTC-06:00)  #    Comments [0]