Category Archives: Development

Event Sourcing Or, How I Learned to Stop Layering And Love the Event Log

Earlier this week, I had my first opportunity to present at a local conference, Prairie Dev Con. D’Arcy puts on a fantastic event, well organized, and full of great speakers. The hardest part is realizing you missed out on a great talk, because you were in another great talk. I met a lot of great people, learned some new things, grew my reading list of blogs and books, and came away with another great experience. I’m looking forward to the next one already (I just need to figure out a presentation topic).

For those who attended my talk, thank you. I look forward to reading the feedback that was left after the session. And for those of you who missed out, here is a slightly older recording of my talk, as well as a link to my slide deck.

TIP: Quickly purge SQL Server Data

I was working on writing some integration tests, and needed to quickly get the database to a clean state between them. Dropping and recreating the database would take too long, but, if I could easily delete all the data, then I could populate with what I needed for each test…with MS SQL Server, you can use the stored proc sp_MSForEachTable to run SQL against each table. The following code uses the proc, disabling triggers, and constraints so it can delete all data, then enables them again

public static void PurgeData()
	using (var conn = new SqlConnection(ConnectionString))
		var cmdText = new StringBuilder();
		cmdText.AppendLine("EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'DELETE FROM ?'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'");
		cmdText.AppendLine("EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?'");
		using (var sqlCmd = new SqlCommand(cmdText.ToString(), conn))

Hope this helps you out.

Getting started with Hybrid development with Ionic – Part 1: System Setup

So, let’s just dive in and get the dev machine setup. We are going to be using Apache Cordova, Ionic, and AngularJS frameworks. And we’ll get Jasmine and Karma setup for testing. We will also use npm (node package manager) to install these libraries, so let’s get that installed first.

Install nodejs using the install link at Then let’s ensure we have the latest version by running this as administrator.

npm install npm -g

We also need the Java JDK (not just JRE). That can be downloaded and installed from here. Just follow the instructions, and ensure it’s in your PATH when complete.

Now let’s get Apache ANT from here, and install it.

Also required is the Android SDK. Just follow the instructions, and run the Android SDK Manager to install the latest SDK Platform. Cordova requires the ANDROID_HOME environment variable. This should point to the android-sdk directory.

Now that we have npm, let’s install cordova and ionic as administrator.

npm install -g cordova
npm install -g ionic

Now, navigate to the location you want to create your application. And generate a blank ionic app with

cd c:\source\
ionic start helloworld blank

NOTE: I had a problem here, I received the following error: “Unable to add plugins. Perhaps your version of Cordova is too old. Try updating (npm install -g cordova), removing this project folder, and trying again. (CLI v1.3.2)”. However, nothing I did solved the problem. Turns out, for some reason, my helloworld/config.xml was blank. You can fetch a new config.xml here, replace the empty one, and things should start working.

Open the helloworld folder and let’s add the android platform, and run the blank app

cd helloworld 
ionic platform add android
ionic serve


Or connect your android device by usb, and load the application on it with

ionic run android

You can also run it in the Android emulator, but I don’t recommend it, as it’s slooooooow.

ionic build android
ionic emulate android

Next we’ll start adding some code and tests.

TIP: Always run Visual Studio as an Administrator

If you’re like me, you always want Visual Studio opening as Administrator, allowing it to install services, and do whatever you need it to do. But you often forget to right click and “Run as Administrator”. Or you just want to be able to use the pinned shortcuts on the task bar. It’s really amazingly simple to make it always run as an administrator, just follow these simple steps:

  1. Right Click on “devenv.exe” in Explorer
  2. ClickTroubleshoot compatibility
  3. ClickTroubleshoot program
  4. CheckThe program requires additional permissions
  5. ClickNext
  6. ClickTest the program…“. It should launch Visual Studio as Administrator
  7. ClickNext
  8. ClickYes, save these settings for this program
  9. ClickClose the troubleshooter

You can revert by following the same steps, but unchecking “The program requires additional permissions”

Yet another “Books you should read” list

These lists are everywhere, every blogger at some point puts up there list of “must read” because … because they’re important. Some of the best books I’ve read have been off people’s lists. When you look at a few dozen lists, you notice the same books over and over and over…and you realize, “I should read this book!”. If all these people I respect and follow are recommending it, it must be worth reading. So here’s my list, with commentary, hopefully containing some suggestions that you haven’t already read, and enjoy when you do.

  1. Pragmatic Thinking and Learning: Refactor Your Wetware

    This book literally changed the way I think about my day. Lots of examples about how your mind works, tricks to help you let your mind solve problems for you in the background, and why. It generated a lot of interesting discussion at during our companies book club meeting.

  2. The Phoenix Project: A Novel About IT, DevOps, and Helping Your Business Win
  3. This is probably my favourite book on the list, it describes a fictional company that has horrible internal practices, and one employees attempt to change that. It feels so real, and I can relate so much of the story to places I have worked. It offered some insights into how we can affect change for the better in the companies we work for.

  4. Clean Code: A Handbook of Agile Software Craftsmanship

    A great book that changed how I write software. It really brought refactoring, and proper program structure to the front of my mind. Before reading this book, I didn’t realize how bad a programmer I really was. I got things done…but not as well as I could have.

  5. The Clean Coder: A Code of Conduct for Professional Programmers

    Along the same lines as Clean Code, but this book isn’t about writing code, it’s about how to be a professional in the workplace. How and when to say no. How to estimate, and when not to. It confirmed many of my practices, and caused me to understand better some of the mistakes I’ve made in the past.

  6. Dreaming in Code: Two Dozen Programmers, Three Years, 4,732 Bugs, and One Quest for Transcendent Software

    This was another great story, the author’s original intent, was to follow this company as they created a piece of softare and document how great people can write revolutionary software…however, that’s not quite what happened.

  7. Leaders eat Last: Why Some Teams Pull Together and Others Don’t

    This book isn’t about tech at all, it’s about what makes a good leader, and why. It goes into a lot of detail about the chemicals in your brain, when they are released, their short and long term effects, and why we’ve evolved to have them. It generated a LOT of fantastic converstaion in our book club meetings.

  8. The Drunkard’s Walk: How Randomness Rules Our Lives

    If you’re interested in math, and statistics, you’ll enjoy this book. Great stories and examples helping to understand how randomness works. And some history about statistics, and how we generally misinterpret so much of what we see because we don’t understand how to properly calculate the probability of something happening. The math is also, very easy to follow, it’s not big complicated formulas.

Now for a couple books that have nothing to do with IT, they are just so great that you should read them. They should appeal to the same crowd as the above books, as everyone I know who has read them, has LOVED them.

  • The Martian: A Novel

    I read this book in the span of 24 hours, I started one evening, was done the next. It’s gripping. The first lines of the book are “I’m pretty much fucked. That’s my considered opinion. Fucked.” It’s written as a journal, as a person keeps a log about being stranded on Mars. It’s about the struggle to stay alive after being left for dead when a sandstorm forces the rest of the crew to evacuate.

  • Ready Player One: A Novel

    If you grew up in the 80’s this is a must read. It’s page after page of 80’s movie, video game, and television references. Every paragraph takes you back to your childhood (or whenever you were alive in the 80s). And it’s all wrapped in a great story set in the real world in 2044 after a global energy crisis; and in a virtual world, the OASIS. Once I picked up this book, I could barely put it down, I think I’ve only read The Martian faster.

I hope you read or have read these books and enjoy them as much as I have. Let me know in the comments, if you have recommendations for further reading, I’d love to hear them! There’s so much out there it’s hard to find quality.

Have a great day!

It’s a great day to be a .Net developer

What more is there to say?  Microsoft opensourced Roslyn (.NET Compiler Platform), source is avaiable on CodePlex!!!

It’s fantastic news, to quote Eric Lippert

What astonished me was that its not just a “reference” license, but a full on liberal Apache 2.0 license. And then to have Miguel announce that Xamarin had already got Roslyn working on linux was gobsmacking.

It’s a huge step, and something I hope Microsoft does more of.  I can’t wait to find some time to dig into this code, and see how it all works.

Getting Started with Android Development

Last fall I purchased a Nexus 7 (2013) and have really enjoyed the pure Android experience.  I’ll be retiring my S3 and buying a Nexus phone to replace it in the near future.  Anyhow, one thing that’s always lacking is a way to develop on the tablet…or so I thought!  Enter AIDE, an Android IDE that allows you to develop and run applications right from your tablet!


It comes with the code for  Tetris, a Clock Widget, and a Hello World app.  I started hacking together my first native app.  And tried to run it.  Of course, it crashed. So, Google, and I download a few logcat readers.  None seem to work. I do some more research and learn that as of the Jelly Bean update, apps can no longer read each others logs. This was added for security reasons, as some applications (facebook) were logging passwords in the log file, meaning, a maliscous app could easily read your facebook password from it’s logfile. Which now means, you need to connect your tablet to a pc to read the logs, and determine why your application is crashing.  At first, this annoyed me.  It took a while to get that work, and I’ll show you how. But if you plan to deploy your app, you’re going to want to have log files sent to you anyway. After showing you how to read logcat from your PC, I’ll show you how to write your first app in AIDE, that will email (or change it to write to a file you can open) it’s logcat after it crashes. It will allow you to develop, without the need for a PC.

First, you need to enable developer mode on your tablet. It used to just be in the settings, but now it’s more complicated.  Open your settings and scroll down to “About tablet” (phone, or whatever).  Scroll down to the Build number, and click it 7 times.

about tablet

You’ll see a message that developer mode is now enabled. Success. Back in the Settings screen you’ll now see Developer Options.

dev options

In there, turn on USB Debugging

USB Debugging

Next we need to install drivers, you can get the latest Google USB Driver from Unzip them to a location your machine, I chose c:\Android Tools\Usb_Driver. Now, open Device Manager, and find your device under “Other devices”

Update Nexus 7 Driver

Choose “Browse my computer…” and navigate to the folder you extracted the drivers into. Make sure “Include Subfolders” is checked. And install them, you should now see the device installed correctly.


So, now that the drivers are installed, let’s get adb installed, you can download r19.0.1 for windows here which is currently the latest version. Just extract the files onto your computer, I stored them at “C:\Android Tools\platform-tools” on mine.

Open a command prompt, go to the directory you just extracted adb.exe into, and try issuing the command “adb devices“, you should see a result listing the attached device.

C:\Android Tools\platform-tools>adb devices
List of devices attached
06e96062 device

If nothing is attached, you many need to change the Connection type with your computer, on your Android device, go to Settings -> Storage, and click the elipses in the top right, you’ll come to this screen, try changing between the two modes, one should work. On mine it was Camera, others have reported differently.

USB Computer Connection

If all is working correctly, you should be able to dump the logcat contents with the command

adb logcat

Or to a file

adb logcat -d > logcat.txt

This logcat grows quickly, if you want to clear the logcat of your device, issue the command

adb logcat -c

And that’s all for now. My next article should be a walkthrough of using AIDE to get a simple app up and running, with logging, so you can do do your development without needing adb to view logs, and thus, remove the tether to your computer.

Now, back to coding!

TIL: The subtle difference between Keypress and Keydown (aside from the obvious)

The other day at work, an innocuous question was posed…

So, in javascript ‘ (apostrophe) and right arrow have the same event key code. What am I supposed to do with that?

This did not seem right to me, but, sure enough, a js fiddle showed this to be true…almost (go to result tab, and hit different keyboard keys, it will show the character code).

What appeared to be the same code (if you hit apostrophe then an arrow) was actually just that the arrow didn’t register as a keypress, and you were still seeing the last keys code. However, this was only true in some browsers, IE and Chrome, Firefox I believe worked as one would expect.

Changing to a keydown event works, and shows the right arrow as 39, like it should.

Quirksmode clears up a bit of the confusion, and has a nice little tester at the bottom of the page.

Visual Studio Tip #1: Ignoring Whitespace when Comparing

When comparing files, it’s frustrating when the default compare, doesn’t ignore whitespace, and many differences are caused by spaces vs tabs.

Solve it, by adjusting the parameters DiffMerge uses.

In Visual Studio:

  1. Tools->Options
  2. Source Control->Visual Studio Team Foundation Server
  3. Click the Configure User Tools button.

Now add an item with the following settings.

  • Extension : .*
  • Operation : Compare
  • Command : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
  • Or: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
  • Arguments : %1 %2 %6 %7 %5 /ignorespace