Sunday, October 20, 2013

Who's your daddy?

While helping to review a co-worker's code trying to track down a defect we believed to be related to be a thread related problem we came across a piece of code that made me scratch my head.  I have distilled the classes down to its relevant parts.

Suppose we have the following class:

public class FooClass
{
 private DateTime _timeStamp = DateTime.Now;

 public DateTime CreateTimeStamp
 {
  get
  {
   return _timeStamp;
  }
 }

 public void PerformBarCalculations(BarClass bar)
 {
  bar.DoSuff(this);
 }
}

The FooClass has a method called PerformBarCalculations that takes a reference to BarClass object. This function calls a method on the BarClass called DoStuff that takes a reference to a FooClass object, in this case, the FooClass is a reference to this or the current object.

The BarClass has the following definition:

public class BarClass
{
 public FooClass _parent;
 private int expiration;

 public BarClass(FooClass parent, int expiration)
 {
  this._parent = parent;
 }

 public void DoSuff(FooClass newFoo)
 {
  this._parent = newFoo;

  //...do stuff
 }
 public bool IsExpired()
 {
  return DateTime.Now.Subtract(_parent.CreateTimeStamp).Minutes > expiration;
 }
}

The BarClass has a reference to its parent and a expiration time.  Both of these values are injected on construction.  Nothing tricky yet, but lets look at the DoSuff() function.  It takes as its argument a reference to a FooClass object.  The first line of this function promptly sets the parent reference to the newFoo reference being passed into this function.

"So far so good!" you say?  Call the IsExpired() function.  What does it return, can you tell me?  What if I threw 10 threads at this code. What will IsExpired() return now?

Is this where the issue is coming from or is it coming from some place else.  Who knows, maybe.  The defect cannot be reliably reproduced.  This wasn't even the smelliest part of the code.

Maybe the BarClass should also implement a Maurry Povich function to find out who the baby daddy is?

"To lose one parent may be regarded as a misfortune; to lose both looks like carelessness."
-Oscar Wilde, The Importance of Being Earnest


Windows 8.1 auto login - checkbox missing

So today I updated to Windows 8.1.  After the install process was complete, Windows asked me to log in with a live account.  This is not a huge issue because I do have an account, I just don't use it.  The irk here is that apparently this is a required step.  There is no skip, ask me later or die in a fire button.  So what is my live.com password? The password is 12 random characters long and I need access to LastPass to figure out my password.  But, remember there is no skip button :(

After getting all logged in and doing the first restart, guess what Windows wants me to do, again.  Back to the same issue, so after digging up the password again (which I promptly make insecure by writing down on a note card in big black permanent ink) I log back in again.

So I figure I can just turn this option off right?  A quick search on Google tells me exactly what a I need to do, just uncheck a checkbox and provide credentials.  Problem solved right?  WRONG!!!

So what im looking for is the checkbox here:
But, my screen looks like this:


What the hell where is it?  Google is of no help, I keep ending up on the same thing that tells me to check the checkbox.

Long story short fix this issue and make the checkbox show up by doing the following:
  1. Enable the Administrator account by running net user Administrator /active:yes from an elevated command prompt.
  2. Login with the Administrator account.
  3. Run control userpasswords2 from the run command
  4. Bam! The chceckbox shows up.  Uncheck the "Users must enter a user name and password to use this computer" checkbox.
  5. Press apply and enter credentials for the user you want to automatically be logged in.
  6. Restart and you should be logged in without the need to provide credentials.