Peter Mellett

Stylised cartoon of me with glasses on.

Having a Go at Go[lang]

I've been intrigued by Golang for a little while now. I used to enjoy concurrency and parallelism in Java many moons ago during my student days. I've never had enough motivation to pick up C++ or brush up on Java again, so those skills are something that had, until recently, fallen by the wayside.

Seeing that Go has a simple language specification and a powerful standard library made it a prime candidate for some 'C-like' programming.

Web development focuses on single-threaded request-response type interactions and all the languages I've used in the past few years have been dynamically typed. With this in mind, Go provides two things of interest:

  • Static typing
  • Concurrency

I like static typing, a lot. Type safety allows me to concentrate on the functional code I wish to write instead of the defensive programming and duck typing tactics that I don't. Even though contrary to that statement, duck typing is a very flexible and valid form of writing Go using interfaces to great effect. That aforementioned safety doesn't stop me from littering my code with log.Println calls though - I like verbose console output.

I also like that concurrency is baked in to the language. When I was writing Java a lot during University, multi-threaded code was my favourite to work with, it felt the most like 'proper programming'* in a way. Goroutines make for a very convenient and easy concurrency API, with channels providing safe communication between them. Channels are a first-class type in Go, which allows for even very simple programs to make full use of the powerful features on offer without resorting to standard or third-party libraries.

I've been somewhat hoovering up Go talks and resources, mostly introductory material and documentation, although I enjoyed Rob Pike's talk asserting that Concurrency is not Parallelism which has been a refresher for some of the terminology and approaches of concurrent programming. There's also an excellent episode of The Changelog with Rob and Andrew Gerran talking about a lot of the design choices and origins of the Go language.

I like to try out new languages and aspire to be a polyglot where I can. It's fun to have certain accepted standards challenged plus lessons learned from one language can strengthen the design decisions made during application development in any other.

So speaking of which, I wrote a little status monitor application in Go. It uses a dynamically-configured number of concurrent workers to test and update sets of services read from a JSON config file. The application serves a (totally unstyled) status page or a JSON response if the correct headers are sent. It features mostly the log.Println statements I alluded to earlier, but it was fun to write and taught me a lot about the language idioms along the way.

* Whatever that means.

Installing pg Gem on OS X Lion

After spending a frantic 20 minutes trying to find a way to install the pg gem on OS X Lion, I discovered this solution.

I had installed Postgres through homebrew and the instructions were not clear on where the pg_config file was installed. brew info postgresql recommends ensuring you set the correct architecture in an environment variable to build the x64 version with ARCHFLAGS='-arch x86_64' gem install pg which didn't work in my case.

Suggested elsewhere was to specify the pg_config file location to the postgres gem, but no mention of where this file may be found. After a not-so-quick search (the ridiculous find / pg_config | grep pg_config) I found it at /usr/local/bin/pg_config the file will be elsewhere if you installed from source.

Before you bundle install - to a terminal full of make errors - install the pg gem with:

1 gem install pg -- --with-pg-config=/usr/local/bin/pg_config

You may need to run sudo gem install [...] if you are not using a version manager like RVM or Rbenv.

Headache averted.

List a User's Distribution Group Membership in Exchange 2010 Using PowerShell

Recently I needed a simple way to get a list of all distribution lists a user belonged to. Since we use mail-enabled security groups it is not always obvious which groups have an associated email address at a glance.

I used PowerShell to write a simple script to print a list of a user's distribution groups to the console. The full code is below, but first let's break it down in to the components of the script.

About the script:

 1 # List-DistributionGroups.ps1
 2 # Peter Mellett 2012
 3 # 
 4 # Find all distribution groups of a user and list them to the console
 5 #
 6 # Example:
 7 # .\List-DistributionGroups.ps1
 8 #
 9 # belongs to:
10 # Name
11 # ====
12 # Marketing
13 # Managers
14 # 

The script requires one parameter, the user's email address. This should match the full smtp address for a user in your domain.

1 [CmdletBinding()]
2 Param(
3   [Parameter(Mandatory=$True,Position=1)]
4    [string]$email
5 )

Since this script uses some cmdlets only available in the Exchange Shell, we need to ensure that the exchange shell is available, if it is then we should import it.

Please note: Exchange Shell can have unintended behaviour if imported this way instead of being launched directly. Your mileage may vary, but it's worth noting if you have something weird happen.

First we test the install path of the Exchange 2010 shell. If we find it, import it and connect to the exchange server (using the -auto .flag, it can be configured for your specific environment- see Get-Help Connect-ExchangeServer). If not, we'll print an informational message and exit.

1 if (Test-Path 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1') {
2     . 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
3     Connect-ExchangeServer -auto
5     # rest of script omitted
6 } else {
7     Wite-Host "This script requires Exchange 2010 Shell to be installed. Either use this script on an Exchange server or install the EMC from the Exchange install media."
8 }

This is the important part of the script, the bit that actually does the work. Here we get all the distribution lists in the domain (warning: slow!) and then test against the members of each comparing it to our entered email address.

If the email is found in the group membership, we'll select the name of that group (which is printed to the console.) Note that the last line has been split across multiple to fit it on the page.

1 Write-Host "$email belongs to: "
2 $lists = Get-DistributionGroup -ResultSize unlimited
3 $lists | where { `
4   (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) `
5   -contains $email } | select Name

This is a simple script, but it has come in useful a couple of times recently. Definitely better than having to manually check each group.


New Additions

I've recently added a place to highlight my current and past projects. A project will also be highlighted on the right-hand side of the page, picked at random.

The first of these projects to be added is my first Rails project (which is not my first project to production; you're reading this post on it) R3TMS. It is a project I have developed on an informal basis to replace an existing piece of software in use at work.

So far, learning Rails has been a fun-filled process (in the Dwarf Fortress sense) with two major Rails versions since I started learning (3.1 had just been released when I picked up my first book but, unfortunately, my copy was for 3.0) which caused some head-scratching and a lot of post-it notes with advice for future me.

I will be adding more of my projects as and when I can but working on them is more fun than writing about them, as the space between posts here shows.


Post the First


Welcome to my personal website, where I will infrequently update based on my findings in Ruby (and other languages), Rails and my day-to-day troubleshooting with both desktop and server machines and their software.

I've built this website as a part of learning Rails for work-related projects. It forms the sort of instant gratification project that sometimes helps to build confidence when learning a new language and framework. My other projects include a stock-control system for printer consumables and an IP/Asset-tracking database. You can browse and follow my projects at Github.

Aside from work and Rails, I'm spending my time playing American Football for the Cornish Sharks, a UK team in Div 2 South West. I have played the sport for a number of years now, including 3 seasons with the South Wales Warriors. I'm also patiently waiting for the sea to warm up so I can go for a surf, or at least attempt to!

If you would like to contact me, feel free to visit the Contact page and for a more concise bio plus technical specs of the site please visit the About page.