Tuesday, 12 November 2013

Links From My SmartDevsUG PowerShell Talk

Here are some links I referred to in my "Spinning Plates and Slaying Vampires With PowerShell" Talk the other night at SmartDevsUG, Hereford on 11/11/2013




Here are a couple of links regarding Dynamic Creation of  ValidateSet Paramters



The module we discussed can be viewed and downloaded from http://pastebin.com/jBfFhreK

Sunday, 16 June 2013

A 32bit Alternative To Invoke-SqlCmd

I'd had been using the "Invoke-Sqlcmd" cmdlet that ships with the SqlServer Management modules, to  run scripts against my local sql server db.

Everything was fine calling this cmdlet from within the normal PS console but recently I want to do this from the Package Manager Console in Visual Studio (the ps console that ships with the library package manager plugin and sits in the IDE).
Visual Studio is still (at the time of writing this) a 32 bit app but the SqlServer Management modules are 64 bit, and as such you cant invoke them from a 32 bit app. Splendid!

The following function gives me the functionality I needed from Invoke-SqlCmd but can be called in a 32bit environment:

function Invoke-SqlClientCommand(){
   Param(
   [Parameter(Mandatory=$true)]
   [string]$InputFile,
   [Parameter(Mandatory=$true)]
   [string]$ServerInstance,
   [Parameter(Mandatory=$true)]
   [string]$Database)
  
 $connStr = [System.String]::Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI", $ServerInstance, $Database)
 $conn = New-Object System.Data.SqlClient.SqlConnection($connStr);
 $action = { Write-Host $event.sourceEventArgs.Message } 
 Register-ObjectEvent  -InputObject $conn -EventName InfoMessage -Action $action | Out-Null
  
 $conn.Open();
 $cmdTxt = Get-Content $InputFile  
 $cmd = New-Object System.Data.SqlClient.SqlCommand($cmdTxt, $conn);
 $cmd.ExecuteReader();
 $cmd.Dispose();
 $conn.Close();
 $conn.Dispose();
}

This is the first time I've had to use the Register-ObjectEvent cmdlet. I used it to hook into the InfoMessage event on the SqlConnection object so any warnings or info messages are written to the host console.

Now I can stay in my IDE longer and keep focused on the task at hand. Feel free to take it and extend it as needed ;-)



Tuesday, 8 January 2013

Brain Dump of Keyboard Shortcuts

I need to get these keyboard shortcuts written down before I forget them. I'll update this page whenever I come across a new one:

Start PowerShell from an explorer window.

  1. Type Alt-D to set the context in the explorer windows address bar.
  2. Type powershell and hit Enter

You can also open a command prompt using this method by typing cmd instead of PowerShell.

Likewise, if you're in PowerShell and wish to open an explorer window at your current location:
Type ii . and hit enter (don't forget the space between the i and full stop)

ii is the alias for the Invoke-Item Cmdlet [http://technet.microsoft.com/en-us/library/ee176882.aspx]

Wednesday, 2 January 2013

The 12TDDS of Christmas - The Times Crossword For Programmers

 

John Cleary launched a TDD Kata challenge over the Christmas Break entitled the 12 TDDs of Christmas. A different challenge code kata is posted daily and participants are encouraged to use TDD to help complete each challenge.

In some respects it's been like the Times Crossword for programmers over the festive period and has provided ample distraction over the break. I've managed a couple so far as apparently(!) I've got to balance coding over the Christmas break with family life but I'll keep pushing my solutions up here and tweet when I've added a new one.

AFTER I've pushed my solution for a kata, I've found really useful to see other devs have approached it, both in how the solution was approached but also in how they put their tests together.

Here's a couple I've found:

(Feel free to ping me the 12TDDs url of your repo and I'll add it to the list)

One thing I do think is important to say at this point is that a code kata is something that should be repeated regularly to get maximum benefit from it. As developers, when we're coding for money, we rarely get the opportunity to rip up our work and start again. The sandboxed, non-live environment of a kata allows us to do just that. It enables us to practice writing code to improve in many ways, most importantly in how you let TDD guide you to a maintainable solution to a problem.

With that in mind, I think the 12TDDs series is something I’ll refer back to throughout the year. Towards the end of 2012 I practiced Roy Osheroves String Kata daily for a month and I felt like my TDD approach improved quite drastically. With that in mind, each month this year, I'm going to try and pick a one of the katas John has chosen for us in this series and practice it regularly and see how I progress.

Wednesday, 19 December 2012

TDD Code Kata Notes

I've been lucky enough to run Roy Osheroves String Calculator Kata at a couple of user groups recently. Here is a brain dump of everything I've mentioned during the events.

Books


The Art of Unit Testing - Roy Osherove

Test Driven Development By Example - Kent Beck

Pragmatic Programmer - Andrew Hunt & David Thomas

Frameworks & Plugins

Here's a link to the String Calculator Kata page I used so you may practice it yourselves : www.shropshiredev.net/kata

Last but not least, here’s a link to an effort I made while learning the kata : http://pastebin.com/0CjJQEVt  it may change over time as I reconsider my approach ;-)

Wednesday, 4 July 2012

Keeping Focus With Pomodoros and Multiple Desktops

Working from home has it's benefits but one thing you need to be able to do is motivate yourself  to focus and concentrate to get the most out of each day... with no-one else around, it’s all to easy for your mind to drift then before you know it, the day is over and you've not accomplished anything you set out to.

I heard about the Pomodoro technique a while ago but never got round to trying it TBH. Its a time management system designed to focus your effort and maximise your work time, advising you to work in relatively short units of work. Quoting the official web site, the basic unit of work consists of:

      1. Choose a task to be accomplished
      2. Set the Pomodoro to 25 minutes (the Pomodoro is the timer)
      3. Work on the task until the Pomodoro rings, then put a check on your sheet of paper
      4. Take a short break (5 minutes is OK)
      5. Every 4 Pomodoros take a longer break

imageI've downloaded an app called Pomodairo which I use to time myself. It also allows you to log all your tasks so you can actually plan your daily task list up front, estimating of how many pomodoros each task is likely to take. (see pic)

I've also started using virtual desktops to manage what's on the screen during a pomodoro and what's on my screen during a rest period. I installed an app called Dexpot and have gone with the default setting of 4 screens although I'm only using 2 at the moment:
   
Work - anything I need open to complete the current task I'm working on. It normally only contains Visual Studio instances and a browser(!)
   
Rest - All the “noise” that work life brings that can interrupt you while working on the task at hand, including Outlook, Skype, Yammer and Twitter and another browser instance for aimlessly surfing the interwebs!

Using Dexpot I can quickly utilise a spare desktop if a work issue arises that I need to deal with immediately, without disrupting my "Work" desktop
   
I've configured Dexpot so that when my current pomodoro ends, I can immediately switch from “Work” to the "Rest" desktop, allowing me to figuratively “stick my head up out of my cubicle” to see what’s happening , again, without disrupting my work desk.

I've only been using this method for a couple of days but I'm already feeling the benefit of focused work cycles and feel a lot more organised in my working practices. I would advise anyone to at least give this a try!

The next step for me is to read the Pomodoro manual and work on refining the process.

Links

Tuesday, 1 May 2012

So Who Stepped Up?

Within an hour of posting "I Need A Recruitement Agent" I had two willing volunteers reaching out to be heard!

Gill Twist from Circle Recruitment runs the Guerilla IT events in Manchester and appears to be no  stranger to dealing with divas developers in events such as these.

Aaron Gartside from  Greenfield IT Recruitment in Shrewsbury also offered and as they are based locally, I've asked Aaron to come and give us all the lowdown at the Recruiting Developers evening at Shrposhire Dev Net the 9th May.

Hats off to both of them! I don't know how many I expected to respond but I think this should lead to a good event and hopefully Aaron and his firm will get as much out of it as the audience will.