Lachlan B's Blog

World Cup Of Programming Languages 2018

Update #2 - Round #2 can be voted on here. Winners from each group:

Group A
Assembly, Java, PHP, D

Group B
C, Go, Perl, Fortran

Group C
C++, Groovy, R, Haskell

Group D
Bash/Shell, Basic, Objective C, TypeScript

Group E
Kotlin, Matlab, Swift, F#

Group F
Python, Dart, Rust, Haskell

Group G
Ruby, Delphi, Javascript, SQL

Group H
C#, Lisp, Scala, Smalltalk

Update #1 - Round #1 voting has begun: Group 1, Group 2, Group 3, Group 4, Group 5, Group 6, Group 7, Read More ->

Using Seq and Asp Dot Net Core

I am unabashed in how awesome I think Seq is. For troubleshooting stuff in production, this thing is a goldmine. Let's say I have some code:

public int Divide(int x, int y)
    int z = x / y;
    return z;

int result = Divide(10, 5);

With Seq it's extremely easy to add some logging that gives you all the information you need to troubleshoot this function when it's running in production:

I won't go into any more detail about Seq, you can read about it yourself, so here's how I set it up.

Setting up Serilog and Seq for Logging

We are going to use ASP.NET Core's standard logging, Serilog as the implementation, and Seq as a serilog sink. This gives us the most flexibility!

First off you only nee...

Throttling your API in ASP.NET

Can someone DOS attack your API and bring down your webservice? Could I hit your API at 100 requests a second and bring down your server? Or can you throttle your users like this?

Homer throttling Bart

Sorry, I couldn't resist. How about like this?

If the answer is no, the good news is that it's quite easy to do in ASP.NET. You can use the fully featured WebApiThrottle, or if you don't need something fancy you can build it yourself.


Deployments with Zero Downtime in ASP.NET

Did you know that you can have zero downtime deployments with your ASP.NET application?

You don't even need to be using AWS or Azure, or have a fancy load balancer or anything else clever and expensive! So how does this thing work?

The basic idea is that you have two instances of your app running in production. At any point in time your users are using only one of these instances, and when you do a deploy you update the instance that isn't being used. Then you switch the users over to the new instance. See that blue line? That's a reverse proxy.

Martin Fowler (genius) calls this Blue-green deployments.

So how do I do this?

Well, before we can proceed, perhaps there should be a few pre-requisites listed:


Setting up CI to setup your success

Build servers

Does your build save you time and effort? Or does everyone emit a collective groan whenever you hear the dreaded "Someone broke the build" ? A great build setup you will love, a bad setup you will hate. How do you get started and where do you want to end up?


Which one?

Well, a lot of it depends on your circumstances. If you're a Microsoft shop, you might already have TFS. If you're using Github you've got access to Travis. If you want to set up your own, Jenkins is free and fully featured. If you have a budget you can buy Team City. Or you could check out BuildBot. My recommendation is not to agonise over the decision, just pick one and get stuck in. If you don't have a server and you're not using a hosted source control solution, you could always install Jenkins on your local box in a VM. Remember, you don't need permission to be awesome.

So, what are the basics that your build server should do and in what order should you set them up?

Check out your code

Get this working!


Electron App vs native Winforms App

Like many other software developers I have a bunch of CI jobs that I need to monitor. If any of these jobs are failing I don't want to update my code and break everything. Recently I've been using an app named Catlight. It works great, it's simple, it looks nice:

But the CPU and memory usage?? For just a simple app (all it does is poll a JSON service every minute and displays some basic stats) check out the memory usage:

Yes, that's THREE processes running, and it's using, in total, 94 meg of memory!

Is this a problem? Perhaps not to you. Is it an affront to everything we believe in as software developers? Yes.

It's also worth noting that I'm running a Dell Latitude E6540, which is a great laptop, but it has a notorious fan problem. If you tax the CPU a little bit for longer than a few seconds, the incredibly annoying fan kicks in, whirrs for a second and then stops. Then repeats. It drives you mental.

As a little exercise I wanted to see what would happen if I wrote the equivalent program in a boring Winforms c# app. I came up with this:

and the ...

Twenty Two Nerdy Things I Learnt This Week

You learn a lot when writing code.

Automated build with Gitlab and Jenkins

With open source tools Jenkins and Gitlab you can automate your builds, track bugs, do code reviews and work in feature branches for .NET development. Here's how to get it all working.

  1. Your first step is to download and install the (free) community edition of Gitlab. If you don't have a linux server available, you can always run one within Virtual Box on your windows server.

    After installation, you should be able to log in and see the home page: For this example we are going to assume that Gitlab is available at the following address:
  2. On your windows server, you need to install the following:
    Once installed, your Jenkins ser...

I suck, you suck, we all suck at coding

Programming is hard, but us programmers never like to admit it. Except for the wonderful Scott Hansleman who wrote this fantastic article. And on a similar note. And a good explanation on why we are all so grumpy.

Oh and did you know that programming sucks?

And here's a better explanation why.

Oh and the code for Toyota 2005 Camry is TERRIBLE.

I write this post to assure fellow devs that you are a REAL programmer. Don't stress about not knowing everything or not knowing enough. There's too much to learn. The time it takes to get good at a language or framework is the time it takes for it to become obsolete! Programming sucks but is great fun. Just don't let it get you down :)


Midi patch changer schematic

Here's the schematic for my MIDI patch changer.