go to:

Monday, May 18, 2009

A New Home…And Me

To all subscribers (I think there’s 2 of you), I am now at:


Thank you,


Submit this story to DotNetKicks

Friday, May 08, 2009

My Foot Surgery, Pooping, and Me…End of Week 3


So my last, long post was a detailed recap of that first week: the surgery process, some minor tidbits about home, having cast put on, etc.  A whole lot of nothing has happened during the following two weeks.  And yet, so much has happened.

For anyone who may stumble upon these pages doing some personal research before their own surgery, I can assure you that pooping can be an extraordinarily painful and exhausting event.  I need an analogy or some other tool to proceed…

I never knew what heartburn was.  I didn’t even know I didn’t know what heartburn was until I had a bunch of stress-related indigestion going on – lots of belching and farting and basically uncomfortable gas in my stomach that eventually became intolerable.  When it started getting to that point, I assumed that I had heartburn or acid reflux or something, and began popping the Tums.

Then came the moment when, in the peak of the glory of my stress at that time (another story for another day), my sternum and anything underneath would occasionally suddenly become awash in a hot, fiery pain.  Ergo, heartburn.  I now know what heartburn is.

I still am not sure what constipation is.  But if it is anything like what began at the tail end of week 1 through to today (so far), I’d rather have heartburn, daily, several times a day, for 10 minutes each time.

For lack of a better phrase, after surgery I did not shit for the first week.  Apparently that’s normal, as the anesthesia leaves your system (I guess).  My wife got some Colace stool softener tablets, that you can take up to 3 a day.  By the end of week 1, I was well into my 3-a-day.  Then it came.  After 5 minutes of using my walker and toilet seat riser and various other equipment to get me situated in my bathroom, I finally initiated the event.

And man oh man, it was an event.  A grip-the-walls, sweat-pouring-down-forehead, vein-popping, horrible event.  I guess it was painful.  I don’t exactly remember.  My mind has blocked out that memory.  And the several memories since.  Out of maybe 10 shits since then (including that one), I think 2 were “ok”, even typical-relief fulfilling.  The rest of them, and absolutely that first one…ugh.  Not fun, folks.  In any way, shape, or form.

Speaking of pain, when I had my cast put on, the resident basically wrapped my calf and foot – all of that – first with a soft, thick cotton wrapping, then this colored gauze (you can pick your color) that hardened pretty quickly after.  Quick, convenient, done.  Problem was, my money-shot wound on the outside of my foot (see pics below, or from here) hadn’t finished bleeding / seeping, and that seepage was partly absorbed by the cotton padding, where it dried and connected to whatever was “drying” at the seepage point on my wound.

Now, I’ve been applying cold-packs behind my knee pretty much the entire time to help with the swelling.  And help with the swelling it did.  In fact, my calf / foot de-swelled in my cast enough to allow fairly good movement to happen in there.  Ergo, the cast-to-wound-seepage-bridge would move and tug on the wound.

This was an interesting pain, interesting in that I “knew” exactly how to describe it when it first introduced itself to me in all its glory.  For some reason, immediately I just knew what it would be like to have a clump of maybe 10 to 20 yellowjackets gnawing and stinging a particular area of one’s foot, and just sitting there letting them do that.  The vicodin was quickly replaced by the oxycodone, and the oxycodone, I am almost positive, helped pooping become difficult again.  Even though I had only some 10 days until the cast would be removed to have the sutures out, we made an appointment to have the cast “changed”, as this cycle was becoming unbearable.

And so, some FRESH PICS!  You’ll have to forgive me – my wife and I forgot our good camera, and she ran off with Liam while I dealt with the wait, etc.  These are me trying to get decent shots with my Palm Centro camera.

The Clump

Ok, this one’s pretty good.  They just removed the cast with this strange saw device.  Here’s the gauze-seepage-clump.  They poured cold water over it to get it to loosen.  That felt so good, it just, it was just indescribable.  Here’s a close up of that clump:

The Clump Up Close

inside scar

So here’s the scar on the inside of my foot.  These pictures, I can assure you, don’t do this any justice.  Very delicious.  Fairly bruised / purplish, but still very little pain from this area.

Here’s a zoom up for you (click to get it large!)

inside scar 2

Oh yeah…And now, the Clump uncovered!  You are all very lucky, because this was really the only good picture I got of this horrid place, otherwise you’d be plagued by many gross close-ups.  You can see “The Lips” there at the heel.  I have no idea what that puncture-looking hole thing is farther up.  Some of the seepage had dried on my foot, which is the brown “staining” at the bottom.  They were kind enough to wipe it off a little.


This area blows.  It hurts, it’s gross, it’s still swollen, it can’t get comfortable, ever. However, it will all be awesome with sandals on!

You can also see, barely, the small entry point on the heel for what I presumed is the screw they put in.  This area is a consistent, annoying throb of pain.  If one true factoid can be said: bones don’t like having screws put in or through them.

I’m excited, though.  The picture of the scar on the inside of my foot clearly shows my new arch.  And my whining of the pain is most of the time just being a bit over dramatic.  That stupid outside, money-shot area (in particular the dark spot / hole place) stings relentlessly, but you do get used to it.  The heel / screw as well, just not as easy to ignore I think, but it is less frequent than the other stuff.  Newly, though, is a general ankle-bones pain.  As things are hurting less, I am a little more liberal when doing what I can.  Just climbing into bed to do this post, I put weight on the ankle area of the cast or something, and my ankle screamed out in pain.

So, May 14 (only 6 days!) I get my sutures out.  I have been working from home these last two weeks (ideal for a software developer!), which was a fresh change from massive hours of Fallout 3.  This has kept me good and busy, but I’m very ready to be physically back this Monday.  I will say that it is probably different for everyone, but being up in this bedroom for a good 3 weeks…I am going slightly mad.



Submit this story to DotNetKicks

Sunday, April 26, 2009

Foot Surgery and Me…Week 1 finale, and week 2 begins!


Greetings!  Now that I’m much more coherent, I’m going to start off week 2 with a recap of week 1.  This will be a rather long post, and is meant for people like me who searched out blogs for information on having surgery done, in general, and having foot surgery done, in particular.  I know I’ve made a few posts, but they most certainly were done while on super loopy drugs.  Here’s a full recounting of last week for your reading pleasure.

We went in to Same Day Surgery on Monday April 20 at 5:00am.  A few people were already in the waiting room, but more would arrive in the following 30 to 45 minutes.  Nothing special about the room; just a typical hospital / clinic waiting room.

I, like everyone else there, eventually had my name called out to get me registered with my wrist strap and sign consent to treatment forms.  This took a few minutes, and I returned to the waiting room.  After only maybe 10 more minutes, I was called out again, this time to go to a curtained off “room” much like the ones they’ll put you in for an Emergency check-in.  Here I changed into my gown and had some initial tests done: blood taken, vitals, etc.  Then, it gets trippy…

ZagNut on his walker

So, finally I am wheeled to a pre-surgery staging area.  To this point, my wife had been with me, and I cannot tell you how good that is on the psyche until it’s taken away.  I end up being the first into this pre-surgery triage area place.  Slowly, over the next hour, everyone I’d seen in the Same Day Surgery room eventually gets wheeled into here.  We’re lined up, two rows facing each other, on the rolling gurney bed things in our gowns and stretch caps.  A woman about to have back surgery gets a fair amount of attention from a very attractive blonde doctor or resident.  An anesthesiologist comes in and asks me a few questions.  He’s quite arrogant so he brushes off my questions quickly.  More and more doctors, residents, and nurses show up.  Everyone’s bullshitting, having coffee, all around these two lines of people in gowns scared shitless.

My surgeon shows up, talking to the arrogant anesthesiologist about how some clinic or whatever performed 25 heart surgeries in one day.  He breaks from the story long enough to say hi, shake my hand, and, after asking me which foot we were doing, draws his initials on my ankle above my left foot.  Up to this point, I had been asked repeatedly which foot we were operating on; so much so that I was beginning to wonder myself.  I was told later why, but cannot remember.

Another anesthesiologist shows up: an attractive, cheery but soft-spoken woman, and begins getting my IV’s hooked up.  Apparently her father had passed away a week or so earlier.  I expressed my condolences, and she was thankful, eager to have another ear to talk about it with.  I didn’t give a shit either way, I was just scared shitless and in a surreal awe of the “casualness” of these doctors starting their day down here.  I’m not sure how long the woman and I talked, as she apparently administered the actual goods.

The next thing I knew, my wife and someone (a nurse?) were looking down at me asking how I felt.  As I recall, pretty fucking good.  I slept on and off over the evening there, and towards the following day, my foot began to make it’s slight rage known.  I’d hit a button, and my foot calmed down quickly (as did the rest of me).

So the next morning, I was pretty cocky and “ready to go home,” since I was managing the pain so well.  Here is one place I fucked up pretty badly: if you have the opportunity to stay an extra night, do it.  Everyone, including my doctor, seemed psyched that I seemed to be doing so well (notice how much the word “seemed” is showing up).  A physical therapist showed up with a walker (I think I was asked which I wanted to use: the walker is definitely the right choice) had me go down the hall, go up and down a few steps on my butt, then back to my bed.  I was soaked in sweat by the time we got back, and my foot was beginning to foreshadow to me that I haven’t felt anything yet.  Perhaps a set of pictures will show better than I can explain why my foot was fairly pissed off (plus, a quick break from the book being written here):

The Lips

These pictures were taken on a follow-up appointment some four days after the surgery.  This delicious first entry to our set of pictures my wife has given the lovely name “The Lips.”  I almost vomited hearing that name, because damn that’s gross.  Anyway, not sure what they were doing from this side, possibly the fusion of my metatarsal, who knows.  I do know that I my “heel” was broken in two places, so maybe this was one of the points to get at that heel.  I am also 90% sure I never once “felt” this one.

Cadaverous looking heel shot

Speaking of my heel, I’m guessing this is where the screw(s) were put in.  This picture is weird to me also, since it’s the only one that show’s the yellow dye of their surgery-prep stuff.  For some reason you can’t see that coloring on any of the other pictures.  I did feel this one – a frequent, droning ache that I did not enjoy.  I’d give this maybe 30% to 40% of my discomfort, if not more.  Note The Lips <gag>…

But now, without further ado, the real money shot:

Oh yeah...

“Oh whatever, that’s not that gross!”  Yeah okay.  I went ahead and made sure my wife got a good close up of this one.  If I had to guess, I’d say this is the entry point for a vast majority of the work he did.

The Real Lips

Oh yeah.  That’s just delicious.  And actually, I screwed up.  This is what Joey referred to as The Lips.  Apparently, this lovely spot had quite a bit of discharge, that seeped through my initial padding / cast onto my pillows at the hospital.  This guy definitely contained all the rest of my discomfort.

Liam on my walker

Shameless inclusion of my fat little man, Liam!  He definitely likes to play with poppa’s walker, which blows when poppa is at the other end of the room and needs to get it.

So anyway, we get me home.  I’m skipping dealing with the extraordinarily douche bag escort who didn’t know how to use a wheelchair, and the absolutely extraordinary amount of pain that flashed through my body when I accidentally put some weight down on that foot.  All happened just getting me into the car to get me home.  My recommendation here: whoever’s helping you needs to be patient.  In hindsight, we should have just found the front entrance, gotten wheeled down to there, and waited there for Joey to get her car.  We instead tried to be practical and wheel me to the garage, where Joey would get her car and pick me up.  It’s not that the garage was inconvenient, just obviously foreign territory to our “escort”.  Also, some woman parked her minivan in front of the ramps, and so forth.  Whatever.  We get me home.

The pain decides now to make itself fully known.  And boy, does it hurt.  We get me up into the bed upstairs and throw two oxycodones down my throat.  Didn’t really help.  Three hours later, threw two more oxys down my throat.  This, combined with shear exhaustion from the newfound pain and effort to just move around, much less go upstairs, finally did something.  I passed out.

Weird, WEIRD dreams on that oxycodone.  I also took the opportunities this surgery afforded me to quit smoking.  I definitely didn’t consciously give a shit about smoking throughout the week, but occasionally a super-mega-realistic oxycodone day dream would come along and make me wonder why I’d be smoking in the house when Joey wouldn’t allow it.  I’d get in a big fight with myself about how I really screwed up and was gonna use this time to quit finally, and now here I am smoking in our bedroom without a care in the world.  What a douche I am.  Then I’d wake up to take a few sips of water and formally think through my counter-arguments to my smoking self-berating.  I’d be all fully prepped, pop a few oxys and, just before passing out again, suddenly become very, very confused with what the hell was going on.  Kind of fun, I guess.  I’ve since switched to Vicodin, being a little leery of oxycodone’s wonderous powers.  For the first week, the oxy was needed for sure, though, don’t get me wrong there.

So my super media center lasted one day.  I decided, in an oxy-haze that I wanted to work on my laptop on my big, comfy recliner.  So Joey did the best she could disassembling my super setup so I could work for maybe 10 minutes on my laptop before falling asleep.  I streamed two episodes of Harvey Birdman through it.  That’s all.

The Playstation 3 is a godsend, and Fallout 3 was made for inert surgery times.  And that’s really where I’m at now.  PS3, Fallout 3, and in a solid cast until May 14 or so.  The posts should be way shorter now.  Just trying to get as detailed as possible, should anyone else be researching having the same or similar surgery done to their feet.

Now, back to Fallout 3.  Cheers…


Submit this story to DotNetKicks

Thursday, April 23, 2009

Finally, a clue, and Me…

So these past three days have been something else, I’ll tell you!  First of all, I quit smoking, so I was going through some sort of withdrawals there.  The pain at times was extraordinary, leaving me incredibly exhausted pretty much all day.  We’d counter this with two oxycodone about every four hours.  Basically with all this simultaneously going on, doing anything other than sleeping was a waste of time.  I’d try to play PS3 and simply forget what I was playing.  My super media setup went kaput once or twice and my oxy-mind only made it worse.

Today, though, I feel more on top of it, even with the oxycodone.  I think the quitting smoking was really making life weird there, not that I was jonesing or anything, but I could tell a great cloudy-headed confusion was permeating all other aspects of my suffering.  Still doing fine on that, btw.

I know my typing etc is quite poor right now.  I’m having a hard time still concentrating even on this dumb post.  I see Dr. Wukich at around 2:00 today.  I’m gonna see if I can score some xray images.


Submit this story to DotNetKicks

Wednesday, April 22, 2009

My Left Foot, Extreme Pain, and Me…

So I believe in my last entry I said I couldn’t wait for my surgery, cause I had such a bad ass media center setup and games and and and…


First of all, if they suggest you stay an extra night, stay the extra night.  Most likely it’s because your anesthesia is about to wear off and they can help control the pain better.  This is my hunch, anyways.  It’s a hunch based on being up all night moaning in retardedly bad pain.


The oxycodin wasn’t doing shit.  I couldn’t get comfortable to sleep (I decided to quit smoking too with all this).  They say to elevate your foot to lessen pain.  I am finding that every time I do that, I get a good massive 10+ minutes of ouch.  A nice hard steady surface seems to be what the doctor ordered.  I’ll have my foot up on like 6 pillows, and it starts screaming at me as if I’m squeezing it or something.  Soon as I take it off and just lie it on the bed, everybody seems calm for awhile.


I’ve tried playing some games and other stuff today.  I think I’m so exhausted from the pain and oxycodin that I just can’t keep it all in order.

Hey, a walker is a good thing to have.


PS:  I’m making no sense….we’ll see about tomorrow…

Submit this story to DotNetKicks

Saturday, April 18, 2009

Proper Preparation for Surgery, and Me…

Well folks, I am perhaps a little over a day away from major surgery.  And I can’t wait...


setup_1 setup_2

That’s why…

With my wife’s full blessings, I have, at the foot of my bed:

  • a 32” HDTV
  • PlayStation 3
      • Fresh, unopened copy of Fallout 3
      • Unfinished Dead Space
      • Unfinished GTA IV
      • Unfinished Bioshock
  • Dell Studio 1535 laptop
      • Myst I, II, and III (never played them)
  • 500 GB MyBook drive
      • all of the Jonny Quests
      • all of the Star Blazers
      • all of the Battle of the Planets
      • all of the Space Ghost Coast-to-Coasts
      • all of the Harvey Birdmans
      • all of the SeaLab 2021s
      • all of the Action Teen Hunger Forces

Additionally, my laptop already has VS 2005 and 2008 on it, as well as SQL 2005 and 2008 (this is noted primarily for my employers who sometimes peruse my blog to assure them of the volumes of work I will accomplish).

So now combine above setup with some oxycodone and/or vicodin and you have probably the most fantastic vacation lined up ever.

I have very, very flat feet, and have had to go through all the money-gobbling circles of orthotics and lousy podiatrists to get here, here being a “reconstruction of flat foot with double osteotomy calcaneus, gastrocnemius lengthening, and fusion of 1st tarsometatarsal joint” by an orthopedic surgeon.  Left foot Monday, right foot sometime maybe in November / December.

I hope to have some delicious pictures of my mangled left foot for everyone here in the near future, plus some x-ray images.  I’m scheduled to go in at 5:00am Monday morning.


ADDENDUM (Sunday, April 19 @ 4:02pm)

Ok, I’m 13 hours away from the chopping block.  I figure I would give the guest of honor his due.  Here’s my feet right now, and in particular the left flipper:



Ugh.  It just…I’m glad I’m having this done.  Huge massive scars around it all will look better than this mutation.

Also, had to update my super-media-computing center.  Here’s a hint if you want headphones for your PS3: make sure bluetooth or USB set works before purchasing.  I have a set of Motorola s805 DJ ones that are fantastic, but no workie.  So, I brought up the DENON receiver, hooked the optical audio up, and threw some old-school stereo headphones on.  Very, very sweet.  I put PS3 Mediaserver on my laptop and am streaming video to my PS3, as well.  Here ‘tis:


Gives me wood just looking at it…



Ok so I was getting some stuttering on the playback through the PS3 from ps3mediaserver, due to going over wifi.  I found a crossover cable and downloaded pfSense (m0n0wall with UPnP support).  Using Virtual PC, I created a router with my laptop’s wifi and ethernet cards, making the wifi the WAN and ethernet the LAN.  No more stutter, and the PS3 has access to whatever it needs.


Submit this story to DotNetKicks

Wednesday, March 25, 2009

A Stupid Anonymous Thread Trick, and Me…

Ok, the storyline:  A web site creates a temporary file to work with, then is supposed to delete it, because maybe space is low on the drive or whatever.  There are times where the file will still be locked from our work when we try to delete it.  Perhaps we did something like:

File.WriteAllBytes("newFile", File.ReadAllBytes("oldFile"));

And it hasn’t released the lock on “oldFile” when we get to the next statement.  Oh man, that’s a problem.  A BIG problem.  A HUGE problem.

Not anymore!  Introducing a stupid anonymous thread method pause trick we can do:

bool deleted = false;

int tries = 3;

while ((!deleted) && (tries > 0))





        deleted = true;




        Thread pauser = new Thread(

            new ParameterizedThreadStart(

                delegate(object o)





        while (pauser.IsAlive) ;




Oh god yeah…

Ok, a quick run-through.  We try to delete our file.  An exception is caught, so to allow the current thread to finish any IO operations, we create a temporary thread (pauser), which we wait for to finish.  Once it’s done, we try again until either we succeed or just give up.

My sandbox for playing around with this idea is here.  I have a question, though, that needs answering desperately:

              Is this useful anywhere?

If so, please provide an example of where this would be great to use.  I just need to know I didn’t fully waste my time.


Submit this story to DotNetKicks

Tuesday, March 17, 2009

Copying tables from one database to another, and me…

So, lately I had the dilemma of having done a bunch of preliminary SQL work in 2008 Express, then needing to port my results over to a staging SQL 2005 server at work.  I casually backed up the 2008 database and lo and behold, couldn’t restore it!  SSIS wasn’t set up, and I had to gets stuff done ASAP!  I searched on Google, and all I got were either “use SSIS” or “it can’t be done.”  In other words, those who’ve done this before haven’t shared with the rest of us.

So a proc I wrote came in handy…

I threw together this stored procedure, linked to the remote 2005 server, and used this proc to move all my data.  It’s very simple and WYSIWYG-ish right now, as it:

  • doesn’t copy over indexes
  • doesn’t copy over table schemas
  • just copies the tables into a new database with the same table names and data

A Quick Sample Run-Through

So, first let’s create a database named SimpleSample.  We’ll create two tables, one with prime numbers and one with the beginning of the Fibonacci sequence.

For our primes:




declare@table table




declare@counter int

set@counter = 1


while (@counter< 1000)


      insert into @table(primes) values(@counter)

      set @counter =@counter + 1



set@counter = 2

while ((selectcount(1) from @table where primes >@counter) >0)


      delete from @table

      where (((primes % @counter) = 0) and (primes > @counter))


      select top 1 @counter= primes from@table where primes >@counter order byprimes







Now for Fibonacci:




setnocount on

declare@fibo table




while (((selectmax(nacci) from @fibo) < 1000) or ((select COUNT(1) from @fibo) = 0))


      if ((select count(1) from @fibo) > 1)


            insert into @fibo(nacci)

            select sum(i) as nacci from (

                  select top 2 nacci as i from @fibo order by nacci desc

            ) tops



            insert into @fibo(nacci) values(1)





from @fibo

Now that we have two sample tables we’re going to copy, create a second database named SimpleSample2.  Our routine will be simple: get a list of the names of our source tables, and for each name in the list, SELECT from the table with that name in our source database INTO a new table with that same name in our destination database.

There are many ways to get the list of tables.  I ended up using the sys.sp_tables proc:

declare@temp table



      , TABLE_OWNER nvarchar(200)

      , TABLE_NAME nvarchar(200)

      , TABLE_TYPE nvarchar(200)

      , REMARKS nvarchar(max)




declare@sourceDatabase varchar(100)

set@sourceDatabase = 'SimpleSample'


declare@spTables varchar(1000)

set@spTables = 'exec '+ @sourceDatabase +'.sys.sp_tables'


insertinto @temp

execsp_sqlexec @spTables


select* from @temp



After that, I cleaned out the data to just dbo created tables:





declare@ourTables table


      idxint identity(1,1)

      , name nvarchar(200)



insertinto @ourTables

select TABLE_NAME from @temp

Finally, throw those tables into the destination database:

declare@name nvarchar(200)

declare@query varchar(2000)

declare@idx int

while ((selectCOUNT(1) from @ourTables) > 0)


      select top 1 @idx = idx, @name = name from@ourTables


      set @query = 'SELECT * INTO ' +@toDb + '.dbo.['+ @name + '] FROM ' + @name

      exec sp_sqlexec @query


      delete from@ourTables where idx =@idx


The SQL sources are here.  I’m sure it can be spruced up to do many more great things, such as those I initially listed.  If you decide to add anything, please post in the comments or try to get your additions / changes to me and I’ll update the SQL.  You’ll even have the extra bonus of being credited on this immensely popular blog!


Submit this story to DotNetKicks

Saturday, March 07, 2009

Duplicate Files, Hash Codes, SQLite, and Me…

My wife’s been getting on my case about having a gazillion different hard drives with everything and our mothers on them all around the house.  I mean, come on everybody, she just wants her pictures in one @%$!# spot!  She also “misused” Picasa, and now has a bunch of duplicates on her laptop (she doesn’t read my blog, so I ain’t worried she’ll read that).

So, out shopping for Little Liam last weekend, and we decide to pop into Circuit City’s closing-its-doors blowout sale.  I grabbed her a 500 GB Western Digital external drive and, when we got home, proceeded immediately on a simple solution to shut her pie hole.

The result: MyPicturesConsolidator!  It is a WYSIWYG image grabber, duplicate detector, and file-copier-consolidator all in one, gorgeous package!

Ok, this program is NOT a work of art, but may contain some good stuff you can use, and it works pretty solidly, so…


How it works:

First, you select where you want any pictures it finds to get copied to:


Second, select the logical drive you want to scan for pictures.  I included a Refresh Drive List button for changing between USB drives:


Third, click Find My Pictures!  And you’re good!

Behind the scenes:

I wanted a “list” to be maintained that kept track of files we’ve gone through.  I decided to use a SQLite database that would hold MD5 and SHA1 hashes of the pictures.  A good side effect of this is, just take it with the exe and SQLite dll to another computer along with your destination drive (or network share path, etc.), and the duplicates list maintained in the SQLite db should work golden for you.

MD5 and SHA1 generation is, for lack of a better phrase, retardedly easy via .NET.  An MD5 hash of a file, for instance, can be had in one line of code:

byte[] md5Hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.IO.File.ReadAllBytes(filename));

The code is here.  Go ahead and take a look.  There’s some dumb things I’m doing in there that deal with my wife’s needs (i.e. Picasa uses file creation dates, ergo I try to find the earliest for her when I can, etc.).


Submit this story to DotNetKicks

Tuesday, February 24, 2009

Binary Data Transforms, Hex Editing, Design Patterns, and Me…

Lately for work I have been responsible for developing a .NET layer to read from and write to an existing application's binary data files.  The task has proven tedious, but not necessarily boring, as I've discovered some invaluable tools and development principles from this.

First off, the HxD hex editor, and, more importantly, comparison tool is simply perfect for the job.


Many minute differences in my binary output were discovered with this tool.  By using the comparison feature:


I could determine the first instance of a difference in output and, if unexpected, use the location from HxD to quickly narrow down the area of code responsible.


In my code, a Stream is passed to a method that will populate a struct representing the file.  This Stream is put into a BinaryReader for sequential type-based reading of the file.   By simply adding conditional breakpoints at various places in the code, locating the problem was easy.  The condition of the breakpoint would be something like:

myBinReader.BaseStream.Position > 10000

where 10000 would be just below the difference location given by HxD.


So this greatly, greatly, very much helped speed up the process of making sure I was reading and writing the native binary file format out correctly.  Next, I was to transform some of this data to XML for use by another application.  I already had the struct of native data, and wanted to make the transformation to and from XML as stupidly simple as possible.  To do this, I threw down a bunch of different classes, each representing the XML element I was to turn out, and had the elements inherit a base interface with a ToXML() contract method.  Some of the “element” classes contained List<>s of the other “element” classes, so when churning out the XML, it was as simple as doing a foreach and callling ToXML() from each of those to produce my child nodes correctly.

I very much realize this solution is neither new nor ingenious.  I am using it, in fact, as a tangent off into a discussion on this patterns-war stemming from the Spolsky comment on the SOLID method.  Quite frankly, I’m not sure what pattern or patterns I implemented above.  The Proxy or Facade?  I would like to know, as I’ve used this technique of a sort of “translation class” a bazillion times, except my bosses really don’t provide me much time to learn about it, much less, say, spend time with my family (I know you gobblers are reading this).  However, I have an opinion on this patterns-war that I would love some feedback on.  It centers around hiring:  if your team is hiring a new developer / engineer, and you or your team are big into design patterns, don't make knowledge of design patterns a requisite for hiring.

I have been programming most of my life, but only somewhat recently have been able to make it my career.  Already I've met a good range of coders: the hardcore enthusiast, the day-job-only coder, the serious professional.  They seem to come in all types, but all have the same common denominator:  they enjoy writing code.  Some more than others, but ultimately, there is a certain gene-pool that simply enjoys writing code.  It actually has little to do with being a computer enthusiast.  A good majority of systems administrators I've worked with or under don't like programming, period.  But there are those of us who are addicted to "realizing" our thoughts right there on the screen.

Until maybe two or three years ago, I knew little to nothing about design patterns.  As I became familiar with and researched them, I've discovered that I've been using many of them for a long, long time.  And that's exactly what they are:  patterns that have been "recognized" in the programming trade.  As such, they are most valuable as a means of communicating an approach to a task or problem at hand.  They are not, however, a requirement to attack a programming task, nor are they any indication of the competency of the prospective engineer / developer.

If your programming shop or R&D department or whatever group you work in is a pattern-heavy group, then make the applicant aware of this, but don't dismiss them if they simply don't know design patterns.  Most likely the applicant would be more than eager to learn them, and will discover they’ve already used many of them anyways.  Ergo, it's a subset of a lexicon we, as coders, may or may not need to know, depending only on how to be most efficient in our team.

I've noticed that a majority of the programmers I've worked with thus far who are heavy into patterns arrogantly criticize and judge their colleagues when they find out they don't know what a singleton is or the proxy pattern or whatever.  So far, from what I've seen, neither camp has shown to be better programmers than the other.  The real thing that quickly separates an experienced programmer from a truly great programmer, though, is ego.  I personally love everything from learning new tricks and techniques from my colleagues to having them point out where I was really dumb in my code.  It only makes me ultimately a better programmer (hopefully).  What I don’t want to do, and I think this is a pretty unanimous feeling, is converse with an asshole.

When you really think about it, the literal sense of “conversing with an asshole” is identical to it’s figurative sense: an asshole really never listens, and only barks out useless foulness you’ll want to stay away from.  Plus, your friends, family, and colleagues all may very well think less of you if they see you regularly conversing with assholes, even if it’s the same asshole.

So really, whether you’re big into design patterns or not, don’t be an asshole, because it just means you don’t listen and no one wants to be near you anyways.  And if you’re hiring, replace “do they know what a flyweight pattern is?” with “are they an asshole?” on your checklist.  You’ll always build a better team that way.


Submit this story to DotNetKicks

Tuesday, February 10, 2009

Baby Toys, Potty Words, SQL, and Me...

So little Liam just had his first birthday last Thursday.  Among the plethora of toys dumped on him is an incredibly annoying, er, wonderful alphabet speaking caterpillar:

My fat son!

There’s a small yellow bow switch just below the head with three settings, plus off (dear God): letter pronouncing, alternate letter pronouncing, and color word.  These obviously coincide with the feet, so if you press the A foot, the caterpillar will speak “A” on the letter pronunciation, “ah” on the alternate pronunciation, and “red” on the color one.


I had the setting on alternate pronunciation, and was lying back letting Liam play and climb on me.  While smashing the caterpillar, he hit a bunch of keys, seemingly at once.  The F key said “fuh” first, then the caterpillar giggled and said “that tickles!”, and then “kh” for the K key.

This immediately caught my attention, and I had to make the evil caterpillar curse violently so mom would toss it in the closet.  With Liam’s full attention, I hit the F, then K keys.  Again, “he he he, that tickles!” between the two keys.  I took the caterpillar from Liam.  This was now science!  I tried K, O, “he he he, that tickles!”, K.  FASCINATING!  They built in anti-potty-wording!  It blocked T-I-“he he he, that tickles!”-T, F then C, K-O-“he he he, that tickles!”-C, C-O-“he he he, that tickles!”-C, C-U-“he he he, that tickles!”-M, and P-I-S (latin for to pee).  J-I-Z worked, as well as B-U-T.  The word for buttocks or donkey (A-“he he he, that tickles!”-S) did not.

This makes me wonder about other alphabet toys and whether they were as thoroughly scrutinized or not.  Needless to say, I had been working on some SQL for work and decided to see how well it tells the SOUNDEX difference between various spellings of rather naughty words using DIFFERENCE.  Using SQL 2005, the results were startlingly poor.  In a few instances, SQL was smart in its comparisons, however in many cases a comparison between, say, a naughty reference to a woman’s genitals and a man’s returns a DIFFERENCE value of 3.  For those who don’t know, the value returned ranges from 0 to 4, 0 being completely dissimilar to 4 being extremely similar if not identical.  The values in the above case should have been a 0.  The SQL and source for the simple tests are here.  Basically, I’d at least look at additional resources for filtering potty language from user input.

I guess really the only useful thing that came out of this arguably utterly useless exercise is some quick C# I threw together to de-Cartesian-ize my SQL result set:

using System;

using System.Collections.Generic;

using System.Text;


using System.IO;


namespace ConsoleApplication1


    class Program


        static void Main(string[] args)


            List<string> csv = new List<string>(File.ReadAllLines("potty.csv"));

            List<string> csvmod = new List<string>();

            csv.FindAll(delegate(string s)


                string[] l = s.Split(new char[] { ',' });

                if (csvmod.FindIndex(delegate(string s2)


                    return (s2.Contains(l[0] + ",") && s2.Contains(l[1] + ",") && (s2.IndexOf(l[0] + ",") != s2.IndexOf(l[1] + ",")));

                }) < 0)


                return false;


            File.WriteAllLines("potty-less.csv", csvmod.ToArray());




Just an example of hot anonymous delegate action for ya.



Submit this story to DotNetKicks