# Monday, November 30, 2009

Almost 2 years ago a few guys in the Fort Smith area decided we needed a .NET User Group here. We’ve fairly consistently had a good 20 to 30 people show up to every meeting since then. Michael Paladino has done a great job serving as FSDNUG’s president since that time… but earlier this year he moved up to the Northwest Arkansas area. As you might imagine, it’s pretty tough to be the user group president when the group you’re presiding over meets a good 45+ minute drive away. Well, he finally stepped down this month which means someone else has to take the reins.

For good or bad, I’m his replacement :-)

I just wanted to publicly thank Michael for the hard work he’s put into FSDNUG. I’m still pretty intimidated by the responsibility, but I’m also looking forward to it.

If you haven’t attended a meeting yet, stop by some time. The meetings serve as an excellent way to supplement the training and knowledge that we as developers have to have in order to stay afloat.

If you’re already attending the meetings but you’ve got some suggestions on ways we can improve, let me know.

Thanks to all the members - I’m looking forward to starting the meetings back up in January!

posted on Monday, November 30, 2009 12:48:39 PM (Central Standard Time, UTC-06:00)  #    Comments [2]
# Wednesday, October 21, 2009

I just wanted to share a quick tip on something that had been tripping me up. I’ve happily been running Windows 7 x64 for around a month now. At work, our VPN hardware doesn’t support 64-bit (different topic, don’t ask), so I wanted to use the VPN client from within Windows XP Mode. Sounds good, right?

One problem. The VPN client couldn’t see outside networks. In fact, I couldn’t even ping.

Attempting to ping  from XPM

The default networking adapter seems to be “Shared Networking (NAT)” – just change it to your actual network adapter.

Networking adapter settings

Success!

Successful ping!

posted on Wednesday, October 21, 2009 9:15:16 PM (Central Daylight Time, UTC-05:00)  #    Comments [2]
# Friday, October 09, 2009

My first Ruby application recently went live a month or two back. I’ve been meaning to get some experience with Ruby for quite a while now, but it took a real project to actually get a chance to really do something with it. Of course, “real project” in this case is a project that just as easily could have been coded in static HTML :-).

The project turned out to building a website for Arkansas Pediatric Therapy, which is the company that my wife does speech therapy for. The initial requirements for the site were to just get some static content out there, but it still gave me an opportunity to use some Ruby to build the site.

Because the site really has no database needs of any kind yet, I ended up choosing to use Sinatra instead of Rails. For deployment, I used Heroku. I was also able to incorporate some basic integration with the Google Maps API. For my JavaScript framework, I used jQuery. For the web design, I ended up asking one of my coworkers, Tim Franklin, to help me out. His web design skill far exceed mine, so that was definitely the right choice.

So, basically, I took the initial requirements to build an easy static HTML site and ran! Was it overkill? I don’t think so – I ended up learning a lot and I don’t have duplication of HTML all over the place. It should be pretty easy to add dynamic content later if I wish to. It really didn’t take a lot more time either. (NOTE: I did use webgen at first to build a static HTML version of the site. If you really just want static content, I can definitely recommend using it to take advantage of templates.)

But… the post title is about IronRuby… did I use IronRuby for this site? Actually, I didn’t. I might’ve tried it, but I’m pretty sure that Heroku doesn’t support IronRuby currently. Maybe some future site can take advantage of IronRuby. What I want to do is share some of this cool Ruby knowledge with my predominantly .NET readership using IronRuby.

So, here are the steps you can take to build your first Sinatra application using IronRuby!

Downloading, Installing IronRuby, and Adding it Your Path

First, you’ll have to download IronRuby. At the time of this post, it looks like the most current version is 0.9.1 though I used 0.9.0 for the post. The release is just a ZIP file, so all you have to do is extract it and go. I would recommend extracting the zip to your C:\ drive (or root somewhere) as opposed to somewhere under Program Files. Why? Well, I initially dropped mine under Program Files and received an error when trying to install the sinatra gem. I ended up finding this post to fix it – the problem is that the one of the paths is too long (check out all the information about the infamous MAX_PATH constant).

You should have a directory that looks something like c:\ironruby-0.9.1 with the rest of the files underneath it. Next, you’ll need to add the bin directory to your path. For now, I’m just going to add it to my PowerShell profile instead of adding it for the entire system. Here’s all you have to do:

$env:path += ';C:\ironruby-0.9.0\bin'

Once this is done, the IronRuby commands should all be in scope. You can verify this by running “Get-Command ir*” which should return all of the commands under the IronRuby bin directory.

Installing the Sinatra Gem

.NET developers share code by sharing their assemblies. Ruby developers share code by using gems. If you wish to use a .NET library, you usually have to pull up a browser, download a zip file, extract it and then add a reference to the assembly. If you wish to use a gem, you use the gem command and ask it to install it for you. Like so:

gem install sinatra

Then, to actually “reference” the gem in your code, you just “require” the dependencies you have.

require 'rubygems'
require 'sinatra'

Of course, we’re using IronRuby, so the commands are slightly different.

igem install sinatra

If you wish to see all of the gems installed locally, just run:

igem list –local

After installing Sinatra, you should see at least the following gems installed:

igem list --local

NOTE: If you happen to be at work and are behind a proxy, you might have trouble with the gem install command. Ruby and RubyGems take the Unix/Linux approach to proxies. That is, they’re expecting you to have an environment variable set up named HTTP_PROXY. I have a PowerShell script that I run to initialize this for me, but it basically just does this (assuming you have populated the required PowerShell variables):

$env:http_proxy = "http://$username:$password@$proxy:$proxyPort"

I use the Get-Credential cmdlet so that I don’t have to hardcode my username and password anywhere.

Patching Sinatra to run with IronRuby First

Now… you’re not done with installing Sinatra yet. Sinatra doesn’t yet support IronRuby out of the box (as of sinatra 0.9.4 anyway). Check out the IronRuby documentation on patching Sinatra to get it to run under IronRuby. Basically, you can open the base.rb code file (mine was under C:\ironruby-0.9.0\lib\IronRuby\gems\1.8\gems\sinatra-0.9.4\lib\sinatra) and paste in the patched code. Comment on the post if you’re unsure how to read and apply a patch.

Your First Sinatra Application in IronRuby

Now, we’re ready to create the first IronRuby code file. Below is the code:

require 'rubygems'
require 'sinatra' 

get '/' do
  "My machine name is #{System::Environment::machine_name}"
end

Pretty easy, huh? I’ve already pointed out the require statements further up the post. The next three lines illustrate the magic and simplicity of sinatra (and of Ruby). Sinatra bills itself as a “DSL for quickly creating web applications in Ruby with minimal effort.”

What those lines say is, when the ‘/’ path (the root of the site) receives an HTTP GET, respond with the string “My machine name is” and then the evaluated machine name that sinatra is running on. Note that I’m using System.Environment.MachineName from the .NET Framework. Note also that I reference the MachineName property using machine_name instead. This illustrates IronRuby’s name mangling feature which maps CLR property and method names to use Ruby’s naming standards.

Running It!

To run your code in sinatra, you use the ir command (ir = IronRuby) against your Ruby source file. You should see something like the following when you run it:

ir .\myironrubyapp.rb

In case you missed it from the screenshot, sinatra outputs that it “has taken the stage on 4567 for development.” 4567 is the port that sinatra is listening on. This means you can browse to http://localhost:4567.

You should see something like the following when you browse to this address.

Sinatra Running!

So, there you go. Your first Sinatra app with IronRuby. If there is interest, I’ll share more about how you can use Sinatra including how to use ERB to have templates with Sinatra.

posted on Friday, October 09, 2009 9:41:10 AM (Central Daylight Time, UTC-05:00)  #    Comments [1]
# 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]