Sep
27
2012
C# // TDD // Kata // ReSharper // NCrunch

Test Driven Development Kata - String Calculator

The subject of this article is the String Calculator proposed by Roy Osherove. The Kata is done in C# uses Visual Studio 2012, JetBrains Resharper 7 and NCrunch.

But what is a TDD Kata? It is an implementation exercise starting with unit tests and leveraging refactoring that you practice daily for around 15 to 30 minutes.

The goal of this video is to present one of those session I did recently of this practice that I really find interesting.

The video was also published on Tech Head Brothers, my french portal about .NET.

Aug
28
2012

Microsoft Bluetooth Mobile Keyboard 6000 for developers

WP_000463_DxOI love my Microsoft Bluetooth Mobile Keyboard 6000. I have one at home and one at work.

But there is two things which I don’t really like as a developer:

  1. No contextual menu key
  2. Two keys combination for Home and End

So I searched for a solution and found one at least for the contextual menu key. The solution is named SharpKey.

SharpKeys is a utility that manages a Registry key that allows Windows to remap one key to any other key. Included in the application is a list of common keyboard keys and a Type Key feature to automatically recognize most keyboard keys.

This little tool let me remap the Caps Lock, which no one use right? to the the contextual menu key, which makes my developer life much easier as I don’t need to move my hand from the keyboard to the mouse to get to that menu.

Great improvement!

At the moment I don’t have found a better way for the Home and End key, but I am considering remapping the volume up and volume down.

Aug
24
2012

TeamCity and Gitlab working together with SSH Keys

CalzarelluOn February I posted about “Running your TeamCity builds from PowerShell for any Git branch” and now I have to configure a new ssh key so that TeamCity can connect to Gitlab.

I struggled a bit getting continuous error message from TeamCity that the connection failed because it was enable to load identity file. File rights were all ok on the key file and everything looked fine. But still the error message.

Then I remembered that I had the same issue in February while using PuTTYgen to generate my SSH key pair.

I forgot a minor details that I had to generate the key pair like this:

  1. Click Generate button and move your mouse
  2. Click Save public key
  3. Click Save private key (if you need it in this format)
  4. Click on the menu Conversions / Export OpenSSH key and save that key

Then upload the exported OpenSSH key on the TeamCity server. The one in the putty format isn’t working, and that was my problem!

Finally copy the public key generated to your clipboard

and use it in Gitlab

Now when you test the Git connection from TeamCity you should see the following

Jul
17
2012

Automate your Jabbr chat using Github Hubot all running on a Windows machine

I previously talked about “Running Github Hubot on a Windows machine”, “Using Github hubot and Appharbor service hook to get deployment status in Campfire/HipChat rooms” or even “Starting TeamCity builds from HipChat using Github Hubot”.

All those solution rely on an external chat service either Altassian HipChat or 37signals Campfire.

If you want to have your own all integrated experience with all your tools running on premise I propose to look how you might do that using Jabbr and Hubot on a windows machine.

Jabbr is a chat application built with ASP.NET and SignalR. It is open source, available on Github, and provided by David Fowler. Easy to install too as you will see.

To install it the only thing you will need to do is to clone it from Github. You might use Github for Windows then you are one click away from having the clone on your local machine, just visit Jabbr Github page and click Clone in Windows button.

Next step is to create a database named Jabbr, for example in Sql Express.

Finally run the build.cmd from the Jabbr cloned folder which will produce a site folder in the target folder of the Jabbr cloned folder.

Then leverage WebMatrix by right clicking ‘Open as a Web Site using WebMatrix’ and finally click Run.

You should end up with your own local installation of Jabbr, something like the following

Then create a user using /nick [user] [password]

Now let’s create a Jabbr room which will be joined by our Hubot later on.

You just need to use the Jabbr command: /create [room]

Let’s use Development as the name of our room.

Now we are ready to install the second part of our solution Hubot.

Hubot comes with the notion of adapters which makes it very flexible toward what system it can connect to. In our case we would like to have Hubot connecting to Jabbr so we need a Jabbr adapter. Thanks to Scott Moak for creating one which is available here.

But before we need to to install nodejs and Hubot, just follow my previous post “Running Github Hubot on a Windows machine” which is still working with nodejs v0.8.2.

Update: After a short discussion with Tom Bell (@thetombell) on Twitter it is clear that I made too complicated. Thanks Tom for pointing out the easiest way!

So here it is!

mkdir hubot-local

cd hubot-local

npm install hubot

cd node_modules\hubot

npm install https://github.com/smoak/hubot-jabbr/tarball/master

So now we need to integrate Scott Jabbr Hubot adapter. To achieve that from the same prompt your installed Hubot, you will need to install one dependency of the Jabbr adapter which is njabbr so go on and type

npm install njabbr

Now you would need to clone Hubot Jabbr adapter and get the file src/jabbr.coffee and copy it in the adapter /hubot/src/adapters folder of hubot.

Finally just adapt the /hubot/src/robot.coffee to add the new Jabbr adapter like this

HUBOT_DEFAULT_ADAPTERS = [ "campfire", "shell", "jabbr" ]

 

And the last step is to configure some environment variable used by the Jabbr adapter so that hubot connects to the Jabbr chat application and room.

In this example I used the excellent WebStorm from JetBrains but you could do it directly from your environment.

Update: if you don’t have WebStrom you might use PowerShell and

$env:HUBOT_JABBR_PASSWORD = ”HubotPwd”
$env:HUBOT_JABBR_ROOMS = ”Development”
$env:HUBOT_JABBR_HOST = ”http://localhost:17221”

Update: Settings the environment variables like shown previously uses a process-level environment variable (that is, an environment variable that is only visible to, and lasts only as long as, your current PowerShell session). To create more permanent environment variables (i.e., user-level or machine-level) you need to use the .NET Framework and the SetEnvironmentVariable method

[Environment]::SetEnvironmentVariable("HUBOT_JABBR_PASSWORD", "HubotPwd", "User")
[Environment]::SetEnvironmentVariable("HUBOT_JABBR_ROOMS", "Development", "User")
[Environment]::SetEnvironmentVariable("HUBOT_JABBR_HOST", "http://localhost:17221", "User")

Now the only differences from what we have seen in the previous article "“Running Github Hubot on a Windows machine” is that we need to run hubot with the following command line specifying that we want to use the Jabbr adapter:

node .\node_modules\coffee-script\bin\coffee .\bin\hubot –a jabbr

And again the magic starts

As you can see we have Hubot joining our Jabbr Development room and replying to our command. For sure all our Hubot scripts are working, so it lets me check and start builds on TeamCity, but also see AppHarbor deployment status. It is very really easily extendable with new hubot scripts written in CoffeeScript. So it let you customize and automatize most your daily processes. A big win!

Apr
30
2012

Using Github hubot and Appharbor service hook to get deployment status in Campfire/HipChat rooms

STA_0178Appharbor provides a service hook which let’s you get informed when a build is finished sending both succeeded and failed builds.

We wanted to use this to get informed in our Campfire / HipChat room so that our distributed team can be informed about builds status without having to go to AppHarbor web site.

The idea was to extend our GitHub Hubot hosted on Heroku.

From AppHarbor support here is the information we need about “Developing a service hook

We will send a POST request content-type "application/json" and the following body:

{
  "application": {
    "name": "Foo"
  }, 
  "build": {
    "commit": {
      "id": "77d991fe61187d205f329ddf9387d118a09fadcd", 
      "message": "Implement foo"
    }, 
    "status": "succeeded"
  }
}

We need to build a Hubot script; which are CoffeeScript, to have an HTTP endpoint listening to this Post payload. Then it needs to read the payload and format it to be able to send it in readable message to the Campfire / HipChat room.

With the release 2.1.3 of Hubot there is a new easy way to have an HTTP Listener:

HTTP Listener

Hubot has a HTTP listener which listens on the port specified by the PORT environment variable.

You can specify routes to listen on in your scripts by using the router property on robot.

module.exports = (robot) ->
  robot.router.get "/hubot/version", (req, res) ->
    res.end robot.version

There are functions for GET, POST, PUT and DELETE, which all take a route and callback function that accepts a request and a response.

We can use this easily in our Hubot script which is called appharbor-listener.coffee.

module.exports = (robot) ->
  robot.router.post "/hubot/appharbor", (req, res) ->
    robot.logger.info "Message received for appharbor"

Now that we are able to listen to POST payload on the url …/hubot/appharbor we need to send a message to the Campfire / HipChat room, which is a bit different from the other scripts. The http listener scripts doesn’t get msg which is normally used to send the response from our bot to the room. Here we have to do it differently and use robot.send which I found on the post ‘Hubot HTTP Daemon Support

user = robot.userForId 'broadcast'
user.room = 'Your Room Id'
user.type = 'groupchat'

message = "AppHarbor build '#{buildStatus}' for application: '#{builtApplicationName}'"

robot.logger.info "User: '#{user.room}','#{user.type}'"
robot.logger.info "Message: '#{message}'"

robot.send user, "#{message}"

Currently this is working only with the Campfire adapter, the HipChat one is crashing as described here.

Here is the whole script

And finally here is the result of posting a sample payload using fiddler

github hubot appharbor integration

Apr
28
2012

Running Github Hubot on a Windows machine

IMG_0063I finally managed to get Github Hubot running on my Windows 7 64 bits machine. Thanks to  Sean Copenhaver & Thomas Kahlow which pointed me to the correct direction on the ‘Run hubot on windows’ discussion.

So here is how I did it.

First of all download and install nodejs 0.6.15. This will also install npm 1.1.16 which is the node package manager.

Then start Powershell and create a new folder e.g. HubotWorking

mkdir HubotWorking

cd .\HubotWorking

npm install hubot

You should see the following output

npminstallhubot

Go on with the following

cd .\node_modules\hubot

node .\node_modules\coffee-script\bin\coffee .\bin\hubot

And the magic!

hubotonwindows

You might want also to run it through JetBrains WebStorm 4.0, so here is the configuration you will need

webstorm hubot

And here is the result in the WebStorm nodejs runner

runhubotfromwebstorm
Apr
13
2012

Sending your Git branch changes as an email attachment

IMG_1586The other day I wanted to send per email some code to a friend which doesn’t use Git. He is using Svn and I use Git Svn in front of this Svn repository. Why I do that? Don’t get me started…

So he couldn’t pull from my repo and we were kind of stuck. Really?!? For sure not, here was the goal I set as I am sure this will happen some other time: having the computer work for me. What a strange idea you would say! Yeah, the computer working for you. At the end aren’t we here to make the cool things and let the computer do the boring things?

Ok so I came up with a quick hack. I wanted to have a way to send all the new, or modified, files of my current Git branch per email as a zip attachment. Guess what it was quite easy even for a PowerShell beginner like me.

First of all I needed first to be able to determine on which Git branch I was curently. I googled and find the following

function Get-GitBranch {
    $symbolicref = git symbolic-ref HEAD
    $branch = $symbolicref.substring($symbolicref.LastIndexOf("/") +1)
    return $branch
}

Then I wanted to be able to Zip all the files, but to achieve I had to determine which were the files to Zip. this is done using the following

git diff --name-only HEAD..master

And making a Zip out of the list of files is done like this

function Zip-GitBranch([string]$zipFilename) {

    $branch = Get-GitBranch
   
    if (!$zipFilename) {
        $zipFilename = [string]::Format(".\{0}.zip", $branch)
    }

    $files = git diff --name-only HEAD..master

    foreach($file in $files) {
         & 'C:\Program Files\7-Zip\7z.exe' a $zipFilename $file
    }
   
    return $zipFilename
}

Finally I wanted to be able to send the zip as an attachment of an email using Outlook

function MailZip-GitBanch($Recipient) {
   
    if (!$Recipient) {
        Write-Host "You need to pass the email of the recipient as parameter"
        return
    }
   
    $branch = Get-GitBranch
    $zipFilename = [string]::Format(".\{0}.zip", $branch)
    $attachement = [IO.Path]::GetFullPath( $zipFilename )

    Zip-GitBranch($attachement)
       
    $ol = New-Object -comObject Outlook.Application
    $Mail = $ol.CreateItem(0)
    $Mail.Recipients.Add($Recipient)
    $Mail.Subject = "Changes for the branch: " + $branch
    $Mail.Body = "Check out the email attachement to see the changes made to the branch: " + $branch
    $Mail.Attachments.Add($attachement)
    $Mail.Send()
}

Now I can type the following command to send my changes to my friend

MailZip-GitBranch myemail@email.com

You can find the whole script on the following gist.

Mar
25
2012

Writing a first Node.js application on Windows

Plage de la Grande Anse du Diamant

I started some weeks ago to play with Github Hubot and hosted one version on Heroku to start learning about all those new technologies.

The next step was to go a bit onto Node.js and write a first small application.

First you need to download Node.js and install it on your machine. I downloaded the Windows version 0.6.14.

When Node.js is installed on your machine you should find it on the folder C:\Program Files (x86)\nodejs for 64 bits machines and on C:\Program Files\nodejs for the 32 bits.

Then start a PowerShell window and type “node -v” you should see v0.6.14.

Now start you preferred text editor and create a new file server.js and copy paste the code from the home page of Node.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Go back to your PowerShell window and type “node server.js” which should display “Server running at http://127.0.0.1:1337/

Now run your preferred browser and enter the url http://127.0.0.1:1337/

nodejs

I went a little further following the Node Beginner site and created a first module.
To do so I used JetBrains WebStorm 3 which you can easily configure to run and debug your Node.js application.

You need to configure it this way

nodejs2

Then you can add a Run/Debug configuration for Node.Js

nodejs3

Finally you can run your Node.js application in Debug mode

nodejs4

and for sure hit the breakpoints and watch the values of your variables

nodejs5

Which will help during my learning of this new technology!

Mar
22
2012

Installation and first experience with the Ergotron WorkFit-D

New Ergotron Workfit-D desk

In late 2010 I reworked my home office and installed a new Ergotron LX Dual Side-by-Side Arm, to gain some place on my desk.

Some months ago, after different discussions with my colleague Bojan I decided to go on and try to find an height adjustable desk, which he just installed in his home office. I didn’t quite like his one because it was with an electrical motor and I prefered to find a mechanical one. It started to be important for me to stand during the day/night that I spend in front of a computer. I have back pains since years, and it is really time that I do something about it. You might read more about the topic on “JustStand.org” or on “Sitting is killing you”.

I also wanted to have something which fits nicely with my LX Dual Side-by-Side Arm and finally I found what I was looking for; the WorkFit-D, Sit-Stand Desk from Ergotron.

Here is the impressive packaging I received

Ergotron WorkFit-D

And what was inside the box

Ergotron WorkFit-DErgotron WorkFit-DErgotron WorkFit-DErgotron WorkFit-DErgotron WorkFit-D mounting

The mounting documentation was really easy to follow and after almost an hour I had my new Ergotron WorkFit-D assembled and my LX Dual Side-by-Side Arm with it’s two 24 inches monitor mounted on it. As for the mounting of the arm there was really nothing that I disliked during the mounting, easy and clear.

Ergotron WorkFit-D mountingErgotron WorkFit-D mountingErgotron WorkFit-D mounting

So over the past month, I had the chance to use this new working environment while working from home.

First of all I tend to use more the LX Dual Side-by-Side Arm to adjust my monitors when I change from standing up to sitting or the opposite. Before on the fixed desk with the chair, the arm saved quite some place on the desk, so I didn’t had really to move them when I needed to do something else then being on the PC. This is really easy and fast with the arm.

Going from the sitting position to the standing is really fast, smooth and easy. I just have to deal better with the cables behind which sometime cause problem, but I think I have a solution which I will try by end of this week. I was quite surprise that it was that easy, because the two monitors aren’t that light weight.

I used at the beginning the Neo-Flex® Underdesk Keyboard Arm to have my wireless keyboard and mouse. But I stopped at the moment because the whole set was shaking too much when I was typing. I still need to fine tune the foots of the WorkFit-D, which I think will improve the stability and reduce the shaking.

What was a surprise to me was the speed at which I went from a whole day sitting to almost a whole day standing. It took me less than a month. For example today I worked the whole day standing. I still have some pain in my legs after a full day but I think it improves slowly.

During Christmas I worked with my brother Mathieu on our new personal project and we found that it was a fantastic setup for pair programming.

So, I like very much my new Ergotron WorkFit-D and the LX Dual Side-by-Side every day and night I am working home.

Here are some more pictures

I still have some work to do to have my home office the way I want it, but this is work in progress.

Disclaimer: I was provided these materials free, so my opinion might be biased.

Feb
7
2012

Starting TeamCity builds from HipChat using Github Hubot

La table du diable depuis la Savane des Pétrifications

After writing about “Running your TeamCity builds from PowerShell for any Git branch” I’d like to talk about another integration which is using Github Hubot so that the build could be started directly form a chat room.

So using the same idea, which is to extend our development environment, we implemented a way to start TeamCity builds directly from our HipChat room. You could do the same from Campfire for sure.

The main idea of this is to have our daily tools right at our disposal where we spend a good part of our days, chat rooms.

First we had to install Github Hubot and we have chosen to use Heroku which offer free hosting for one of their web dyno. They even offer what they call Hubot Factory which is a way to allow people to easily and quickly deploy new instances of Hubot to Heroku. In fact we went with a manual installation described on this page “Hubot for HipChat on Heroku”.

The idea is still the same we need to run TeamCity builds by “Accessing the Server by HTTP”.

This time we want to have Hubot calling the TeamCity server so we need to add a new CoffeeScript to the scripts of Hubot which will launch the HTTP request needed.

Our script is heavily inspired from the TeamCity.coffee script, and here is a first version:

# Starts a build on TeamCity.
#
# You need to set the following variables:
# HUBOT_TEAMCITY_USERNAME = 
# HUBOT_TEAMCITY_PASSWORD = 
# HUBOT_TEAMCITY_HOSTNAME = 
#
# start build buildId -- Starts TeamCiyt build using buildId
module.exports = (robot) ->
  robot.respond /start build (.*)/i, (msg) ->
    username = process.env.HUBOT_TEAMCITY_USERNAME
    password = process.env.HUBOT_TEAMCITY_PASSWORD
    hostname = process.env.HUBOT_TEAMCITY_HOSTNAME
    buildName = msg.match[1]

    msg.http("http://#{hostname}/httpAuth/action.html?add2Queue=#{buildName}")
      .headers(Authorization: "Basic #{new Buffer("#{username}:#{password}").toString("base64")}",
               Accept: "application/json")
      .get() (err, res, body) ->
        if err
          msg.send "Team city says: #{err}"
          return

By the way I started to learn CoffeeScript so this is more hacking then something really productive.

And here is the result in our HipChat room asking hubot to start a build with the command:

hubot start build bt21

TeamCity, GitHub Hubot and HipChat

I will talk in another post about the last part which shows the status of the build in the chat room.

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect, certified Scrum Master and Founding Member.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent was awarded Most Valuable Professional (MVP) by Microsoft from April 2002 to April 2012.

JetBrains Academy Member
Certified ScrumMaster
My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List