Dates and nothingness

Sounds like a metaphysical post, but it isn't. In working with an object for which I needed a last change date, I set the DateTime variable value to Nothing in the constructor.

Dim lastReset as DateTime = Nothing 

But when I check for IsNothing() later in the code the check always fails due to the fact that the Nothing value for the DateTime (a value type in .NET) is actually MinValue. To make sure that it wasn't Nothing I would avtually have to compare to MinValue:

If lastReset <> Date.Minvalue Then DoSomething() 

Well, I was sure that .NET 2.0 fixed this with Generics and I was right. This is what happens when you do to much designing and not enough coding, I guess. The new Nullable object type can be Of DateTime, so that this now works:

Dim lastReset as Nullable(Of DateTime) = Nothing 
If IsNothing(LastReset) Then DoSomething() 

From a pragmatic programming perspective, this isn't a big deal. From a solid code perspective it is a rather large deal. If I say Nothing, I want NOTHING in there. I don't want the MinValue in there. I want Nothing in there. Then I want to see if the value is still nothing later.

Generate a managed class for WMI instrumentation

So,I need a list of services from a remote machine for an application I am building for Wendys.  I wrote a boatload of System.Management code to do it, liike something like this:

   1:  Public Function ListServices() As Dictionary(Of String, String)
   2:    co = New ConnectionOptions()
   3:    co.Username = My.Settings.Username
   4:    co.Password = My.Settings.Password
   5:    co.Impersonation = ImpersonationLevel.Impersonate
   6:    scope = New ManagementScope("\\" + IPNumber + "\root\cimv2", co)
   7:    Dim result As New Dictionary(Of String, String)
   8:    Dim mc As New ManagementClass("Win32_Service")
   9:    Dim oc As ManagementObjectCollection
  10:    Dim query As New ObjectQuery
  11:    query.QueryString = "SELECT * FROM Win32_Service"
  12:    Dim mos As New ManagementObjectSearcher(scope, query)
  13:    oc = mos.Get
  14:    For Each item As ManagementObject In oc
  15:      result.Add(item.Item("DisplayName"), item.Item("State"))
  16:    Next
  17:    Return result
  18:  End Function 


Then what did I learn?  Lo and behold, there is a Tool To Do This.  I hate it when that happens!  Just pass in the WMI namespace and it will generate all the class code you can eat.  (Win32_Battery made me 2800 lines of code).  Check it out here on MSDN.

Coding for Patterns

With the deployment of the gold release of ASP.NET MVC, the topic of patterns are hot and heavy again, and I am getting reader emails about “What pattern do I use for this or that”.  I answer when I can, but it needs to be understood that The Gang Of Four were writing for a pretty broad kind of software development, and a lot of their thoughts only peripherally apply to the world of business programming.

Most of us write programs that accept data from some source – usually a user – and then deliver it to some source – usually a report.  This is not what The GoF had in mind when they wrote Design Patterns.  In fact, you’ll notice that even Model View Controller – the pattern behind the ASP.NET MVC – is Martin Fowler’s; it isn’t even in Design Patterns.

Speaking of Fowler, he is a great author to check out when making decisions about a pattern for the data-driven applications usually built by VB.NET programmers.  I strongly recommend his Patterns of Enterprise Application Architecture.  The Object-relational structural patterns, especially, define a lot of the thought that needs to go into object-oriented applications persisting to a relational database.

What patterns do I use?  I believe in single abstraction of the domain.  I think that you need significant separation between the database and the domain and application layer, but to wrap ever single little thing in interfaces is a waste of time for 80% of stovepipe applications.  In general, using Fowler’s terminology, I use a lazy mapper model.  The domain objects (like person or organization) call data objects that relate directly to tables in order to gather or persist information.  If it is a really big application, I will go ahead and go to that next level of abstraction and implement that separated interface that I generally do not like.

A final note – design patterns are not ‘philosophical constructs of programming.’  They are real, important, significant and weighty contributors to software design.  If you are not designing your software, you should be and it is tough if not impossible to design without an approach and the approach is defined by the pattern.  Please don’t allow the hackers on a team to direct the flow away from a sensible approach.

Downloading a file from a remote server with network credentials

Man, was this a pain in the butt.  Seems like downloading a file from a remote PC would be easy, but 'taint.  This worked great for me,  your mileage may vary.

   1:  'First we set up all of the filenames and locations, making heavy use of app.config.
   2:  Dim filename As String = String.Format("{0}-{1}-{2}.txt", CDate(checkDate).Year.ToString, CDate(checkDate).Month.ToString, CDate(checkDate).Day.ToString + 1)
   3:  Dim RemoteFile As String = String.Format("\\{0}\{1}\{2}", My.Settings.IpNumber, My.Settings.LogDirectory, filename)
   4:  Dim LocalDirectory As String = String.Format("{0}logs\", My.Settings.ReportLocation)
   5:  Dim LocalFile As String = String.Format("{0}{1}", LocalDirectory, filename)
   6:  'Hey, check for the localdirectory
   7:  If Not Directory.Exists(LocalDirectory) Then
   8:    Directory.CreateDirectory(LocalDirectory)
   9:  End If
  10:  'Then we set up a little security
  11:  Dim myClient As New System.Net.WebClient
  12:  Dim myCreds As New System.Net.NetworkCredential(My.Settings.Username, My.Settings.Password)
  13:  'Log the fact that we are starting.
  14:  My.Application.Log.WriteEntry(String.Format("Starting download of file {0}", fileName))
  15:  'Set up the securit
  16:  myClient.Credentials = myCreds
  17:  'Now we actually try and get the file.
  18:  Try
  19:    myClient.DownloadFile(RemoteFile, LocalFile)
  20:  Catch uae As System.UnauthorizedAccessException
  21:    My.Computer.FileSystem.WriteAllText(LocalFile, String.Format("The file path to file {0} was not available at the time of this posting.", file), True)
  22:  Catch ex As Exception
  23:    My.Application.Log.WriteException(ex)
  24:  End Try
  25:  My.Application.Log.WriteEntry(String.Format("Finished download of file {0}", fileName)) 


Did this as part of a project at Wendy's.  Part of the Classic Posts collection.  (heh)


In the world of taijutsu, legs are like pistons. You let the pressure out of them to lower yourself to the ground, and increase the pressure to lift yourself up. Take Morote Gari. You drop to a sprinters stance - releasing the pressure in your knees (performed by the calves and thighs) and position yourself at the knees of uke, then increase the pressure in your knees to take uke to the mat.

Hokojutsu is the same thing. The key to moving my bulk around silently is to not place my leg, but lower it, and then lower my weight onto it. If I just place it, I thump. If I lower it, I don't. It's a totally different way of thinking.

There are a bunch of examples. When I perform Oni Kudaki, for example (in the classical way) I slide into uke with my back foot and lower by center of gravity on my pistons to take balance. Then I raise myself after I get the lock on the elbow. The legs work just like hydraulics to lower and raise my body.


It's surprising how much preparation is a part of hensojutsu. I have been reading On Acting by Sanford Meisner, and his approach to preparation has me thinking a lot about hensojutsu and reality. Meisner says that 'acting is living truthfully under imaginary circumstances.' Admittedly, if you have one hell of an imagination you can just jump up and do what is required under the circumstances.

I don't.

So, Meisner has his students prepare. The difference is, he has them prepare for the emotion not the action. For instance, say you have a scene where your sister has died. But you are an only child. You don't know what it would feel like to lose a sibling. Well, let's get close, Meisner says. Ever lose a parent? Dear friend? Was it pretty miserable? Alright, THINK about that and say the lines.

For my 6th kyu test I have to perform hensoijutsu as Yado Nashi, or a homeless man. I originally thought to do research, and that is a good idea for the facts - where I live, how I got there, etc. For my actual preparation, though, I have to key in on emotion - hopelessness, or determination depending on my character. I have to call up something that harbors the emotion of the character as well as remember the facts. It isn't like the facts will be more true with the right emotion, but they sure will be more believable.

Going to the decision maker matters for the IT Pros and Developers too

When I was in sales, one of the tenants of making a close was driving to the decision maker.  Anyone who stands in the way is a "gatekeeper" and is just there to protect the decision maker, like the offensive line in football.  Jeke past the tackle!  Watch out for the tight end!

The reason for focusing on the decision maker is to reduce the number of times that you have to hear the organizational customer say "no".  You have to wait througn 7 nos to get a sale as it is, you don't want to hear "But now you have to talk with Mr. Manager."  You want a check written after you hear yes.  Therefore, get to the decision maker.  There are a bevy of methods to use to get past gatekeepers, and young sales trainees - such as myself years ago - learn them by heart.

What I am learning, as I delve deeper into the Software Architecture role, is that getting to the decision maker is just as important for the professional IT consultant.  There are just as many gatekeepers in the IT department of midsized companies as there are in the purchasing department.  These are even more subtle, too, if that is possible; they might even think (incorrectly) that they are the decision maker, but they are not.  Whe you are consulting for a company, and have the opportunity to garner additional project hours by solving a new problem, you are often the only person in the building who can bring the new sale to a close.

The problem is one of feifdoms.  Someone in IT designs a network, or manages a server, or writes a key piece of software, or configures some middleware, and they think that they own it.  They do all the work, they make all of the key decisions, so they must own it, right?  Well, no.  Especially when a decision impacts something else in the company.  Now, if they do something on company time and get overruled, it's not a big problem.  They grumble, turn it off or whatever, and all is forgotten.

But if you, as a consultant, do it on their OK and it gets overruled, you might not get paid.

Suddenly, getting to the decision maker seems like a really good idea, especially when pitching a new piece of work.  Here are a few tips from my experience to help you get past the IT Manager of the Fiefdom, and to the person who writes the checks.

  1. First, know who writes those checks.  It is tough to find the real decision maker in some firms.  Often, the functional decision maker is the IT manager, but they have a higher power in the CIO or CEO or owner who might know little about technology.  It is essential to get this person's buy in.
  2. Remember that gatekeepers are your friend.  Don't tick off the 'owner' of the target system just because they don't write the check.  Your case is so much better off if both you and the system manager go to the decision maker.
  3. Have an elevator message ready.  Often, you will find yourself at the coffee shop or wherever with the decision maker, and might be able to catch him or her for a minute before or after.  Have a compelling 30 second pitch ready that describes what you are trying to do.
  4. Remember to listen.  Don't just talk.  Sometimes no is no.  Sometimes you have a bad idea, and that is why you are being blown off.  Sometimes you are explaining it poorly, and that's why you can't make the close.  Listen to the feedback.

Finding continuing work as a consultant often requires sales measures.  You can depend on a recruiter to get you into a client, but you often have to keep yourself there.  Having a plan to get tot he decision maker will make that process smoother. 


By far, the easiest way to defeat me in randori is to wear me out. I am 36, 230 pounds, and don't work out enough. Lie on me and make me work - I'll be wiped in no time.

Recently though I have been training with the kuji-in. Funny, that. It seems to work. The Bansenshukai curriculum has one of the nine ninja mudra for each of the nine kyu. The first mudra, for ninth kyu, is Rin or Strength. Every day, during my meditation, I have been focusing on those times when I have found extraordinary inner strength. Once, I stayed up for a very long time when I had a project due and Adam was sick. In a less poignant example, I recently ran a long time on the treadmill, finding some inner endurance. I lasted a long time in one particular randori, and can recall that.

All of this is done while making the Rin mudru, which is hands together, fingers intertwined. The middle finders are raised and touching. what this allows me to do is use the unusual muscle memory to recall all of that hours of meditation in a moment's notice. Say, for instance, right before a long randori match.

It might sound dorky but it works. Just like sitting in Seiza might make you think about class, the mudra recalls the topic of the meditation. I was impressed. I am totally not into mystical stuff (ask anyone about me lack of respect for religion) but when something works it works. The tie between muscle memory and long term memory is well documented.

I like it a lot. This is where the 'magic' of the ninja comes in.

More at Wikipedia.

S. U. R. V. I. V. A. L

I have been reading The Special Forces Guide to Escape and Evasion by Will Fowler to kinda formulate a strategy for Intonjutsu in my mind. We study element driven styles of escape and evasion in the club (like Katonjutsu, using fire to mask scent or make a barrier) but I like the forest view once in a while, so I read overview books on contemporary Ninjutsu topics.

I learned something very cool in the Zanson area in the first chapter, though. I like acronyms in emergency situations - when you can't remember much else, you can often remember cool acronyms. Here is one for situations in which Zanson is important: SURVIVAL.

Size up...
... the situation
... the surroundings
... your physical condition
... your equipment

Use all senses
Remember your location
Vanquish fear
Value living
Act like the natives
Live by your wits

Now, I think that is good anywhere. If you are in the desert being chased by a band of roving Mujahideen or in the mall during a fire, this is a good set of steps to keep yourself on track. The first and most important thing that most people always forget to do in any emergency is to take a second and Size up the situation. Stop. Look around. What is REALLY happening? Where are you specifically AND in general. Can your environment help you? Are you hurt? Are any of your wards hurt? What do you have with you? Would it be better in your hand right now, or stowed?

A better part of Ninjutsu, as I have posted before, is preparedness. While at the time I was talking gear, it is important to be prepared mentally. None of us know how we will respond in an emergency until one happens, so it is a good idea to have a Contingency Plan of Action for most major types of emergencies, and starting with SURVIVAL isn't a bad bet.


I have been reading On Killing by Lt. Col. Dave Grossman, and it has me thinking about the reality of the martial arts. War is war, and defeating the enemy is just another word for killing them. Lt. Col. Grossman puts a lot of emphasis on the distance factor (it being a lot easier to kill with bomber than a knife) and it came to me that a lot of Ninjutsu is about killing at VERY close range.

Lets face facts. Ninjutsu is not a movement study. It is about completing an objective, no matter what the odds. If you are training any other way, you might want to ask yourself why you are into Ninjutsu and not Aikido or tai-chi if you like the movement, or judo or karate if you like competition aspect. Nonetheless I have to wonder how many of us could stab an adversary with a knife if the situation warranted. Many of my friends in the club are military and police - they are studying to improve their chances of survival. They might have to complete that thrust we all learn in tantojutsu.

Could you? I don't know if I could.

The psychological aspects of Ninjutsu are shrouded in a combination of the general fear of discussion of Ninjutsu and the "you'll learn that later' part of the art. Fact is, I think a decent psychoanalyst could have a field day with most of us, starting with Hatsumi himself. Studying a combat martial art in this day and age, when you aren't actually planning on any combat is, well, strange.

So why do we? Preparation? Are we getting ready for when martial law is declared? Is it really just self defense? I have no idea. But I have a sneaking suspicion that 1) there is a lot to learn form this art without being consumed with the concept of death and 2) not many of us are gonna find out and that is a good thing.

Read On Killing. It will get you thinking.

Bill Sempf

Husband. Father. Pentester. Secure software composer. Brewer. Lockpicker. Ninja. Insurrectionist. Lumberjack. All words that have been used to describe me recently. I help people write more secure software.


profile for Bill Sempf on Stack Exchange, a network of free, community-driven Q&A sites