Talk Follow-up

Continuous Delivery @ DDD East Anglia

Talk Follow-up

Continuous Delivery @ Aberdeen Developers .NET User Group

Software Development

Debugging a process that cannot be invoked through Visual Studio.

Sometimes it is rather difficult to debug through Visual Studio directly even although the project is right there in front of you. In my case I have an assembly that is invoked from a wrapper that is itself invoked from an MSBuild script. I could potentially get VS to invoke the whole pipeline but it seemed to me a less convoluted process to try and attach the debugger to the running process and debug from there.

But what if the process is something quite ephemeral. If the process starts up, does its thing, then shuts down you might not have time to attach a debugger to it before the process has completed. Or the thing you are debugging is in the start up code and there is no way to attach a debugger in time for that.

However there is something that can be done (if you have access to the source code and can rebuild).

for (int i = 30; i >= 0; i--)
{
    Console.WriteLine("Waiting for debugger to attach... {0}", i);
    if (Debugger.IsAttached)
        break;
    Thread.Sleep(1000);
}

if (Debugger.IsAttached)
{
    Console.WriteLine("A debugger has attached to the process.");
    Debugger.Break();
}
else
{
    Console.WriteLine("A debugger was not detected... Continuing with process anyway.");
}

You could get away with less code, but I like this because is is reasonably flexible and I get to see what’s happening.

First up, I set a loop to count down thirty seconds to give me time to attach the debugger. On each loop it checks to see if the debugger is attached already and exits early if it has (This is important as otherwise you could attach the debugger then get frustrated waiting for the process to continue.)

After the loop (regardless of whether it simply timed-out or a debugger was detected) it does a final check and breaks the execution if a debugger is detected.

Each step of the way it outputs to the console what it is doing so you can see when to attach the debugger and you can see when the debugger got attached, or not.

My recommendation, if you want to use this code, is to put it in a utility class somewhere that you can call when needed, then take the call out afterwards.

In the workplace

At the top of your game

Having recently changed jobs I read a fair number of job specs and a phrase that stuck out for me was a desire for companies to hire someone “at the top of their game”.

I can understand the sentiment behind that. You want to hire someone that is very good at what they do. However that turn of phrase is off-putting for one big glaring reason. If you are at the top of your game now, where do you expect to be in the future?

I will be quite honest and say that I am not at the top of my game. I don’t expect to be at the top of my game for decades to come. And when I do get to the top of my game it will be the day I retire.

What I do expect of myself is to continually learn and improve. Each day I improve “my game”. I take the mistakes I’ve made in the past and commit to not repeating them. I take the successes and find out what made them successful and apply them to appropriate situations in the future. I learn new technologies as that broadens my horizons and makes me more valuable. Through my blog, at conferences, or mentoring colleagues I teach others what I have learned as that helps everyone improve and it solidifies in my mind the knowledge I have.

The interesting thing is that I didn’t used to think that way.

When I left university I had the arrogance to think that I knew it all and for a few years I worked on that principle. But that attitude eventually caught up with me and I spent some time unemployed partly as a result of that attitude. I am determined not to let that happen again. These days I am acutely aware of what I don’t know. I think that now I am more aware of my limitations I am a better developer. Because I’m more aware of what I don’t know I strive to fill those gaps by ensuring my own education – I don’t let an employer dictate what I should be learning. I am pro-active and go out there and ensure I’m educated. Of course, if my employer wants to put me on a specific training course I’ll accept it.

Training Developers 10/Nov/2008.

 

Eventually, one day, I will finally be “at the top of my game”.

Software Development

Two Factor Authentication with GitHub and Visual Studio 2013

New job, new tools, new processes. In my new job we’re using GitHub for source control, and because the data is sensitive we’re also using two factor authentication. Because I develop with Visual Studio that presents and interesting issue if you are using Visual Studio 2013’s build in Git Source Control provider.

After turning on Two Factor Authentication, the next time you have to communicate with GitHub (e.g. pull/push/sync’ing, etc.) it will pop up a dialog asking for your credentials, even if you already entered them previously before turning on 2FA.

You get an error message that looks like this:

An error occurred. Detailed message: An error was raised by libgit2. Category = Net (Error).
Response status code does not indicate success: 401 (Authorization Required).

Entering your credentials won’t do you any good. It won’t work. It will just request them again, ad infinitum.

There is no where to enterthe 2FA code, so you can’t authenticate yourself here.

However, you can go to GitHub and create a personal access token in order that Visual Studio 2013 can access your repositories.

You can either drop down the menu on your avatar and go to “Settings”, then go to “Personal Access Tokens” (link in the side bar) or you can just go here https://github.com/settings/tokens.

Then click on “Generate New Token”. You’ll be asked for your credentials again just to be sure you are still you.

Once you’ve done that you’ll be taken to the page to create your credentials

For what Visual Studio wants the default permissions are fine. Also, give the token an appropriate name so it can be identified easily.

Then press “Generate token”.

You will then be taken back to the “Personal access tokens” page. This time there is a new token which you can use in Visual Studio. Be careful here, this is the one and only time you will be able to access this token so copy it and keep it safe.

Back in Visual Studio try and sync the commits to GitHub. It will pop up the credentials dialog again. This time you are going to enter the token in the username box and leave the password box blank.

Then press OK.

Finally, your changes will sync with GitHub and you’ll get a success message.

Tip of the Day

Tip of the day: Default project location in Visual Studio

When rebuilding a machine I always end up hunting this setting down just after installing Visual Studio because I keep forgetting where it is. I never put my projects in my documents directory. Ever.

In Visual Studio go to Tools –> Options... then navigate to “Projects and Solutions” and in the “General” section change the “Projects location” to the one you want.

Visual Studio Options dialog

In the workplace

How not to interview a candidate

I recently started a new job. I interviewed for a few companies and got a few offers on the table. However, one interview stuck out for me because, well, let me tell you the story…

I interviewed for a company and the first interview went really well. I liked the guys that were interviewing me and everything went really positively. They also liked me and invited me back for a second interview. They explained at the end of the first interview that the second interview was going to involve some technical competency questions, whiteboarding and so on. I was looking forward to it.

A few days later the recruitment agent called to confirm the time for the second interview and I duly turned up at the appropriate time. The second interview had a different panel to the first which isn’t unusual. However, the format was very similar to the first interview.

Towards the end of the interview one of the interviewers asked me about Scottish Developers, the user group I help run. This is not unusual. Companies are often keen to see such passion for the job that they see this as a positive. Not this chap. I was subjected to several minutes of questions about how my involvement could negatively impact the company and what I’d be doing to mitigate that.

I have found that negative leaning questions fail to understand the implications of running a user group. I run Scottish Developers as part of my own personal training and skills improvement programme, it also benefits many people around me also. To ask how that might negatively affect the company and to seek further assurances that any activities that are organised in my own time, which they are, and are done so well in advance displays a level of control that would be unacceptable, not to mention detrimental to them as I would not be able to keep my skills as up-to-date as I’d like. Something that benefits them more than it does me. I do this because I enjoy software development and I want to continually improve, the side effect of this is that they get a employee that is highly skilled and highly motivated. To cause demotivation in that way would be detrimental to both of us.

Suffice to say that line of questioning left a bitter taste in my mouth.

Then they asked me what I thought of the interview process, so I mentioned in my answer that I thought that the second interview was going to be the more technical and there would be some whiteboarding, problem-solving, and technical questions.

“Where did you hear that from?” was the unexpected, almost barked, response.

“Well, I was told…” was as far as I got in a reply.

“Was it the [name-of-recruitment-agent] at [recruitment-agents-firm]?”

“N…” again I didn’t get a chance to respond.

“I’m going to have to have words with her. That’s not acceptable”

And that was when a previously very positive impression of the company turned into a very firm definite rejection.

He refused to listen to my answer. In fact, he refused to let me speak. He made a wild assumption, which was wrong, and wouldn’t let me correct it. Finally he set out a course of action he was going to take based on that incorrect assumption which was to chastise the recruitment agent for something that was clearly not her fault.

Some interviewers forget that an interview is a two way process. The company want to see what the candidate is like and the candidate want to see what the company is like. For an interviewer to act in such a way was quite revealing.

In one respect I was glad that he did react this way at the interview stage, it saved me finding out once I actually started with the job.