PowerShell to the rescue!

Share:        

I encountered a situation today at work that lent itself to PowerShell. One of the developers asked for some information about the PowerShell line I wrote to diagnose this problem, and I thought it might make a good blog post.

There was a pipe-delimited file that was failing to import into a database via our program, and the QA person was having trouble figuring out why. The process yielded a stack trace, which pointed to a certain stored procedure and a SQL error:

System.Data.SqlClient.SqlException: Error during [stored procedure]: [stored procedure]; 4;
String or binary data would be truncated. at System.Data.SqlClient.SqlConnection.OnError
(SqlException exception, Boolean breakConnection)

The stack trace clearly suggests that an input is exceeding a field length. Question was which one. As it turned out, there was only one column being inserted by this procedure. I did a quick schema lookup and found out that the column in question allows 50 characters.

So, I wrote:

    gc failing_input_file.txt | % {$_.split("|")[4] } `
      | ? { $_.Length -gt 50 } | select unique | measure line

The query yielded 255 offending rows, and led to an alteration of the INSERT stored procedure to truncate the value from the flat file.

The rest of this post is copied wholesale from that email.

Let me restate it a command at a time, and expand the aliases.

Most common PowerShell commands have an alias, which you can look at via Get-Alias. In general, if you want to know about a command, you type “Get-Help command-name”. I put a backtick after each line to continue the line, as is the PowerShell custom.

Many cmdlets (read: “command-lets”) do pipeline processing, which if you haven’t seen it means that the previous command’s output is handed to the next piece as input. The special variable $_ is the current whatever — in this case, the current line. With most commands like with select and measure, $_ is inferred.

PowerShell offers full access to .NET. The strings it returns are .NET strings, which is why Split() just works.

    Get-Content failing_input_file.txt `      
    | ForEach-Object {$_.split("|")[4] } `    
    | Where-Object { $_.Length -gt 50 } `     
    | Select-Object unique `                 
    | Measure-Object line                    

The first line with Get-Content reads in the contents of the file.
For each line of the file, the second part with the Foreach-Object splits that line by “|” and grabs the 5th item.
The Select-Object command omits duplicates.
The Measure-Object command counts the number of lines.

If you want the contract names themselves, leave off the Measure-Object call:

    gc failing_input_file.txt `
    | % {$_.split("|")[4] } `
    | ? { $_.Length -gt 50 } `                                                       
    | select unique

Ubiquitous Capture

Share:        

The idea behind ubiquitous capture is that you can dump things on your mind into a storage medium (notebook, what have you) so that you don’t have to tie up attention re-remembering things to keep them fresh in your mind. I have David Allen and Merlin Mann to thank for convincing me this is a good idea.

Today, after listening to Brett Terpstra on Mac Power Users, I’m trying a new (to me) ubiquitous capture workflow. It’s slightly different than what’s discussed on the show.

The lingua franca is Markdown. The more I use it, the more I like it.

Software

  • nvALT 2.1, Brett Terpstra’s fork of Notational Velocity
  • Byword 1.4, a minimalist and sexy Markdown-friendly text editor ($9.99)
  • Dropbox
  • Nocs for iPhone, a Markdown-friendly editor with Dropbox support

Setup

  • Change the note storage location for nvALT to a Dropbox folder
  • Add .md as a text extension in nvALT (see this Skitch)
  • Tell nvALT to store and read notes on disk as Plain Text Files

Let me know what you think.


Punch It!

Share:        

Having met with the president elect of the company and several higher-ups, I’m nervous that I signed myself up for one of those “maximum warp till the engines can’t take it any more” projects.

I’m hoping that when the team gels and starts delivering, more resources may be in the cards. Looking toward the endgame, there could be more lines of code to write than our timeframe will permit.

However, I have a 3-day weekend ahead, so I plan to punch it towards the Shore Leave planet.


Ahead, 1/4 Impulse

Share:        

The new job is going well, which is to say we are failing fast. Just last night, we decided to revert four days of work because we didn’t like where an architectural choice was going.

I’m working on some software for the pharmaceutical industry, and I’m beginning to learn that drug management is a lot more complicated than picking cereal off the shelf!

We have a design document, which in some areas is really strong and in other areas is more like a problem statement than a proposed solution.

We have a prototype, but it’s more style than substance. For example, right now, the app structure is pretty flat. Flat is fine for a prototype, but not for the real thing.

(For the record, if you are working with WCF services, do not make one service per entity! We started trying to bring the responsibility of coordinating entity operations out of the UI into the domain services, and found it a morass of incompatible DTO namespaces. Whose Product object do you use: the product service’s, the stock shelf’s or receiving’s?)

So, until I get up to speed on the domain, my greatest value to the team is wearing my CSM hat. The team is new and there are a lot of agile practices that are new to these folks. There is a dedicated scrum master on the project (a first for me), and it makes more difference than I had predicted from what I’d read. But, he’s a project manager who’s a scrum enthusiast, whereas I have more field experience with scrum and three letters after my name, so I’m in a position to play the expert.

The main deviations from scrum are in the area of release planning. I was able to persuade the team not to do a 3-hour planning poker session for every user story we know. They only want an estimate accurate to the quarter, so who wants to be stuck with a moldy estimate by greenhorns on a story that will be tackled early next year, if at all? The analogy I used is it’s like a car repair estimate given in terms of unscrewing the oil cap, sticking in the dip stick, and so on. Given a do-over, I’d use the metaphor of prefab furniture assembly, but car repair got the job done.

Tasks have been a problem too. The technical lead of the project worries about things many people from traditional projects worry about. The vagueness of how tasks are selected or how detailed user stories are worry him. He’s worried about how code reviews will happen in an agile process, so I introduced the concept of the definition of done. I’m looking forward to defining done, because opinions range the gamut between “if it complies, it’s good” to a heavy process complete with gated check-ins, code reviews, code coverage, and so on.

Since I’m told this project has at least 16 months, I was told to resist “running up technical debt on the credit card”. I love that analogy. I have time to help the team develop strong TDD discipline, since they said they wanted it in one of their early retrospectives.

I love the team I’m on, I think we have the right people on the bus. And, I think we have a great product concept and the business and technical acumen to make it something special.


Potential Nothin' But .NET course, Denver, mid-September 2010

Share:        

Friends,

My employer, Graebel, is looking to bring JP Boodhoo’s fantastic Nothin’ But .NET course back to Denver this year! We plan to host the course at our headquarters in Aurora, Colorado sometime in mid-September. Many of the seats have already been reserved, but there are still a few available. Once we get enough participants, we can finalize the details.

The course costs $3000 per person. It is conducted over five 12-hour days – Monday through Friday, 9am-9pm – and combines top-notch .NET training with inspiration. The course is taught in a lecture-lab format and covers advanced uses of C# features like generics, delegates, and LINQ, as well as illustrating OO best practices and behavior-driven development.

The course evolves each time it’s taught. When I took it last year, JP tasked us with building a fictitious front-controller e-commerce site from scratch. JP explained each concept in detail with examples, then we would pair in groups of 3 or 4 to design and complete features using what we had just learned, with JP providing expert guidance as needed. The best of breed would be used by the rest of the class going forward.

JP himself is well regarded in the industry, and he combines his blindingly fast programming and amazing craftsmanship with humor, humility and grace. He makes very difficult material seem easy and accessible to a wide range of audiences and learning styles. Nothin’ But .NET is an excellent opportunity for senior and intermediate developers to take their game to the next level.

Here are some informative links about NBDN:

  • Link to course information: http://www.jpboodhoo.com/training.oo, main site: http://blog.developwithpassion.com
  • A course retrospective by JP: http://blog.jpboodhoo.com/NothinButNetEdmonton2010NdashRetrospective.aspx
  • Feedback from participants over the years: http://blog.jpboodhoo.com/SoWhatDoPastStudentsReallyThinkAboutNothinButNet.aspx

I took this course last year at a time when my professional life was flagging and I was approaching burnout. NBDN strengthened my conviction that I am a solid programmer. Yet, it also taught me that after several years of .NET programming, there were still many wonders to explore within features I thought I knew or that I hadn’t encountered before. Combined with the motivational material JP sprinkles throughout the course, I found myself boldly ready to climb new mountains with renewed zeal! If my story describes you too, you owe it to yourself to consider joining us!

Please contact me if you are interesting in signing up, or if you have any questions or want to learn more. I look forward to hearing from you!