All posts by caffgeek

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.

TIP: Obliterate a file from GIT Repository (including history)

I did something stupid, and accidentally pushed some .pubxml files to a public GitHub repo that contained passwords.

I fixed up my .gitignore file, which took care of part of it, but if you viewed the history, the password were still exposed.

After much mucking about, this magical line, obliterated any trace of the file in my repo.

git filter-branch --index-filter "git rm --cached --ignore-unmatch *.pubxml" --prune-empty --tag-name-filter cat -- --all

Then this line, forced an update of the entire repo to GitHub, history and all.

git push origin --force --all

…that was a close call.

TIP: Partial screenshots made easy

I have to take partial screenshots when creating emails or documentation almost every day. I’m not a fan of installing extra tools unless they’re simple, and truly save me time. A few seconds isn’t enough. This is one of those cases, typically I’ll just take the screenshot with PrintScreen, or Alt-PrintScreen, paste it into mspaint, select and copy the part I need, and move on.

However, windows already has a tool for taking partial snapshots of the screen, it’s called “Snipping Tool“. It works for most cases, and that’s enough for me.

We just need a quick way to open it. So, hit the windows key to open the start menu and type Snipping Tool, right click on it, and select properties. Focus in Shortcut key, and hit a key combination to open it. Mac has a similar tool already bound to Cmd-Shift-4, so I bound the snippet tool to Ctrl-Shift-4.


Now, I just hit Ctrl-Shift-4, and the screen goes partially opaque. I highlight a section of the screen, and it’s automatically put in my clipboard. It’s also opened in the snipping tool, but I just close it without saving changes (Alt-F4). Then paste the partial screenshot in my email or document.


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.

Completely remove Printer Driver

I recently had to keep retesting an installer, part of it’s actions were to install a print driver, but to be able to keep testing, I had to remove the driver from the computer, not just the printer. So, here’s how it’s done, in case someone else needs to do this.

  1. Find your driver name. (ex.“Brother MFC-J6520DW Printer”)
  2. In “Devices and Printers” remove all printers using the driver from step 1
  3. Open Regedit.
  4. Navigate to (on 32 bit(x86) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3”
  5. Or (on 64 bit(x64) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3”
  6. And then remove the folder that matches the printer driver name.
  7. Open Services, and restart the print spooler service

That’s it.

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!