Tuesday, February 27, 2007

I could have died...

That's right, I could have died last weekend.  I had a high blood pressure attack on Friday night which caused tingling in my extremeties and pain in my left arm.  Now, when many people experience these kinds of symptoms, their life flashes before their eyes.  I, on the other hand, began to worry about my current level of term life insurance and how I can increase my coverage.   I'm lucky to have a brother that works in a doctor's office and he had me check my blood pressure.

I also suffer from white-coat syndrome.  Its a pre-existing condition.  That means that if I see someone in a white lab coat coming at me, my blood pressure skyrockets.  So you can only imagine what it did when I felt under-insured.  When I got to the doctor the next day, I told her what my bp was the night before and she stuck her pen in her pocket and took three steps back.  Apparently, I was lucky.  The slightest knick could have caused an explosion so violent that we would never be able to sell the house. 

On a side note, I think that I have passed the white coat syndrome to my son.  He freaks out when he sees the pharmacist at Publix, not to mention his pediatrician.

So here's the really funny part.  I had to have a Venus Dopplar scan on my arm.  Sounds impressive, doesn't it.  Well actually... no.  Its the same machine that they use to perform ultrasounds on pregnant women, goop and all.  Ask any woman whose been pregnant in the last 20 years and she'll tell you about the goop. 

I was escorted back to this little room in the back of radiology by a seemingly pleasant woman named Maria.  The name took me by surprise as I tend to think of it as having a mostly latin descent.  Maria, however, looked like she came from Khazakhstan and her dialect seemed to match.  I had to lay down and get gooped from my next down to my wrist.  My wife found this very amusing and considered it some sort of karmic payback for all the ultrasounds that she had to go through.

So then Maria says, "I poke you now,  okaaay.", in her Khazakhstanny idiom.  At the time I couldn't fathom a response.  Seriously, what are you supposed to say in these situations?  "Oh, a poking?  That sounds nice.  Thanks Maria!"  And so the poking commensed.  After about the third poke, I got up enough courage to ask, "Why are you poking me?"  Maria came back with a "I collapse your veins."  My first thought was, "What!?!", but then I thought "What?!?"  Maria went on to explain that her seemingly desctructive poking was merely a test to verify that my veins would pop back.  Of course they did, and it filled me with a sense of resiliency.  On the other hand, if they had not popped back, I could have died.  Good thing I was already in a hospital.  Of all the places to have a near death experience, I think that the hospital is at least in my top 5.

And so I made it through ok with no obvious issues and without having to use the "wand".  Once again, ask a pregnant woman. :)

Friday, February 23, 2007

IEEE defined Code of Ethics for Software Engineers

After listening to Steve McConnell's talk on the last dotNetRocks, I decided to quickly look into the IEEE Software Engineer Certification Program.  Its a little more indepth than I have time for right now and I'm not sure that I meet all the requirements for application.  However, I did stumble their Software Engineering Code of Ethics and Professional Practice.  It is aimed at making the software develop a respected profession.  I, of course, am lacking in several areas.  Here is the short version:

Software engineers shall commit themselves to making the analysis, specification, design, development, testing and maintenance of software a beneficial and respected profession. In accordance with their commitment to the health, safety and welfare of the public, software engineers shall adhere to the following Eight Principles:

1. PUBLIC - Software engineers shall act consistently with the public interest.

2. CLIENT AND EMPLOYER - Software engineers shall act in a manner that is in the best interests of their client and employer consistent with the public interest.

3. PRODUCT - Software engineers shall ensure that their products and related modifications meet the highest professional standards possible.

4. JUDGMENT - Software engineers shall maintain integrity and independence in their professional judgment.

5. MANAGEMENT - Software engineering managers and leaders shall subscribe to and promote an ethical approach to the management of software development and maintenance.

6. PROFESSION - Software engineers shall advance the integrity and reputation of the profession consistent with the public interest.

7. COLLEAGUES - Software engineers shall be fair to and supportive of their colleagues.

8. SELF - Software engineers shall participate in lifelong learning regarding the practice of their profession and shall promote an ethical approach to the practice of the profession.

I think that this is a great document that a lot of software development teams could adopt and reap some benefits.  I'm lucky to be on a team that already embraces most of these principals.  We are fair to and supportive of each other.  We all participate in lifelong learning and are constantly challenging ourselves.  Some of us even care about the safety and welfare of the general public.   However, like most us, I've also worked in groups where it seemed no one seemed to embody these principles.  All it generated was crappy code, shouting matches and the general weeping and gnashing of teeth. 

Friday, February 09, 2007

Interesting Text Parsing

At work this week we were getting a lot of SQL timeout errors.  We went to the DBA and he sends us a log file and explains that many of our sprocs are blocking resources.  He gave us this monster log file and left it up to us to get what we needed out of it.

Here is the basic syntax of the log file.

2006-11-17 19:03:20,733 WARNING BLOCKER -- MYDBSERVER SPID: 120, hostname MYWEBSERVER, prg .Net SqlClient Data Provider, ntlogin
2006-11-17 19:03:20,733 WARNING Blocking Buffer info: sp_executesql;1
--

This pattern was repeated ~600 times.  The log file reported on all the databases on the server, not just ours.  So, I came up with this PowerShell script to give me a list of unique stored procedures that caused a block on the SQL server.

$a = gc "blocks.txt"; 0..$a.count | % { if($a[[int]$_] -match "MYWEBSERVER") { ([regex]"ap\w*").match($a[([int]$_ + 1)]) } } | % { $_.Value } | sort -uniq

Yes, that is one line.  Thank you, PowerShell team, for giving us the ";" character.  ;-) 

The first line loads all the lines in the file into an array.

$a = gc "blocks.txt";

Then we loop through all the rows and pick out the lines that reference MYWEBSERVER.    NOTE: calling $a[$_] didn't work for me.  I had to cast $_ to an int, like so $a[[int]$_].

If the line contains the name of MYWEBSERVER, then I look at the next line and return everything that matches my regex expression, "ap\w*".  All of our sprocs have been prefixed with "ap" so this was pretty easy. 

0..$a.count | % { if($a[[int]$_] -match "MYWEBSERVER") { ([regex]"ap\w*").match($a[([int]$_ + 1)]) } }

The last step is to filter our result set to only pass through unique values.

sort -uniq

It took me about 15 minutes to write and test this.  However, next time we get a log like this, I'll be ready!

Wednesday, February 07, 2007

The death of a television giant

It has been a rough week for me, technology wise. I've had a lot of frustrating issues with my laptop. But even worse, my beloved televsion died. That's right, my 62" Panasonic CinemaView 1080i projection televsion left me to go to the great sports bar in the sky. And right in the middle of Seinfeld too. First the image flickered, then the image went away, then came the most horrible stench of burning electronics that I have ever smelled. Even now, a week later, you can still smell the subtle aroma of fried wire. Of course, this made watching the Superbowl fun. I had to bring down my kid's 20" tv/vcr combo to watch it on.

I have a demonstration image to convey the seriousness of the situation.



Clark Howard says to wait until March to buy a new tv. The prices will go down by then. So, I'm unofficially declaring the month of February as a month of mourning. On the bright side, I no longer have the warm, engulfing glow of my large screen tv to lull me into a semi-vegetative state. So I'll have more time to blog. ;)

Monday, February 05, 2007

Expand/Collapse PowerShell Commands

I was listening the Bruce Payette interview on Hanselminutes and my interest really piqued when they were discussing aliases and being able to write really terse scripts.  It got me to thinking.  Wouldn't it be cool to be able to expand all the aliased command names in a script long enough for you to work on the script.  Then, when you are ready to put it back out there, you could collapse all the command names to short aliases.

Here is my first attempt:

   1:  function Expand-Command($Text)
   2:  {
   3:      $a = (alias $Text).Definition
   4:      if( $a.length -gt 0)
   5:      {
   6:          return $a
   7:      }
   8:      else
   9:      {
  10:          return $Text
  11:      }
  12:  }
  13:   
  14:  function Collapse-Command($Text)
  15:  {
  16:      $a = [string](alias | Where-Object { $_.Definition -eq $Text } | Sort-Object { Name.length })
  17:      if( $a.length -gt 0)
  18:      {
  19:          return $a.split(" ")[0]
  20:      }
  21:      else
  22:      {
  23:          return $Text
  24:      }
  25:  }
  26:   
  27:  function Expand-Script($script)
  28:  {    
  29:      $s = ""
  30:      Get-Content $script | ForEach-Object { ([string]$_).Split(" ") | ForEach-Object { $s += (Expand-Command($_) + " ") } }
  31:      return $s
  32:  }
  33:   
  34:  function Collapse-Script($script)
  35:  {
  36:      [string]$s = Get-Content $script
  37:        
  38:      Get-Command | ForEach-Object { $s = ($s -replace $_.Name, [string](Collapse-Command($_.Name))) }
  39:      return $s
  40:  }
  41:   
  42:  Collapse-Script("c:\\Dummy.ps1")
  43:  Expand-Script("c:\\Dummy.ps1")
 



So, what's going on? Let's start with the Collapse functions. The Collapse-Command function(lines 14-25) basically goes through all the aliases looking for the ones that match the command name that was passed in. Then it sorts them by their length and splits out the first available.  This way it will always pass back the shortest  command name.  In the Collapse-Script function(line 34-40), we loop through all the commands and then replace their names with the collapsed names.


The Expand-Command function(lines 1-12) acts pretty much the same as the Collapse-Command function.  The only difference is instead of searching on the alias definition, we search on the alias name.  The Expand-Script function(lines 27-32) acts a little differently than its counterpart.  It loops through all the individual lines and then through all the words, calling the Expand-Command function as it goes.


I tried to think like a PowerShell developer, not a C# developer for this one.  However, I don't think that it turned out very PowerShelly.  It is also ungodly slow.  I welcome any constructive ideas to make it better.