Yet Another Chris

London, UK

Recent Posts


Podcast of the month - Sept 2016

Friday September 9, 2016

A weekly favourite podcast doesn’t really work on this site, as I only end up adding them every month or two. So I’m switching to a monthly format to share my discoveries in the Podcast world.

This month is (another) Sam Harris one, talking about free will. Sam’s books argues for the case that we have no free will beyond very simple choices. For example speaking - the broka region of the brain is responsible for speech but how much of your speech is words you are willfully choosing? Or another example given is decisions that the subconscious brain makes for you almost a second before the action is performed (from recent fMRI scans showing this is the case).

Dennett (a philosopher) argues against this.

Running cron jobs inside a Docker container

Wednesday September 7, 2016

Probably the most basic use of a Docker image is to run it, and let it exist - like docker run hello-world. If you want to do this on a regular schedule, you have several options but the cron one is narrowed down to running cron on the Docker host or in the container.

I wanted to run a dotnet core console app that parses Reddit posts and posts itself, inside a Docker container, every 30 minutes on set days of the week.

Running the Docker image as a daemon with cron running inside it makes it a lot easier to update the Docker image and also bring up on other machines.

There’s quite a few gotchas to doing this however, which I discovered and spent hours Googling the answers for. Most of the answers were dredged from Github repositories which luckily Google managed to find the keywords for. This included:

  • Cron doesn’t run as an interactive shell - you don’t get any environmental variables  - a well known restriction but nobody seemed to know the answer. I found my solution in this repository.
  • I’m running a .NET Core console app. It writes a temp file to its folder on the filesystem, but you don’t have permission to do this without CHMOD’ing the app directory.
  • Cron inside a Docker container can’t write to a cron.log so you end up having to map a volume. Without this you get the error “tail: unrecognized file system type 0x794c7630 for ‘/var/log/cron.log’”. This makes the Docker image rely on the host volume for storage, but it’s only a log file. The fix came from here.

Below is the Docker file and the scripts are with the Gist.

Updated Unix Cheat Sheet

Monday September 5, 2016

My career as a web-centric software dev started with Unix (Linux and some Solaris/BSD) and thanks to .NET Core I’m now back in that world for some of my web development. I much prefer Unix for the server, particularly as it’s far cheaper than Windows to tinker with as a developer but also its simplicity. It is made for automation - something Windows is slowly catching up with but still performs in a clunky way.

Windows Server 2016 is likely to bring Windows closer to the bash and SSH world, but you are still stuck with some strange technology choices like WinRM using WCF, when SSH was already around and COM legacy everywhere and XML as the preference for configuration (versus YAML, TOML, JSON) for lots of systems like IIS and autoattend files.

Microsoft have performed a full U-turn with their Linux strategy and us C# developers are now free from our shackles and able to use Linux and Mac for things like Docker, .NET Core, Powershell on Linux, SQL Server on Linux and the Linux Subsystem on Windows.

It makes you wonder where Microsoft would be now if the decision to do this was done 10 years ago…anyway I’ve update the Unix cheat sheet I wrote about 11 years ago (put into a CMS in 2009) to include some new knowledge and the CHMOD calculator is able to go both ways. I few Docker commands will appear there shortly too.

Fixing .NET Core package restore problems

Monday August 29, 2016

I had this problem today where a dotnet restore was failing on a Linux CI server, but working on my Windows 10 dev machine. The error was:

Unable to resolve ‘System.Runtime.Serialization.Formatters (>= 4.0.0-rc4-24217-03)’ for ‘.NETCoreApp,Version=v1.0’.

It turns out I had this package in C:\Users\MyUsername\.nuget\packages so it restored locally, but on the internet the package isn’t at nuget.org. How did I get it originally? That was a mystery that luckily another project in the solution solved by accident.

A lot of the .NET Core nuget packages are hosted on myget.org until they’re ready to be fed over to nuget.org. The solution is to add a nuget.config file to your project, with this:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
  </packageSources>
</configuration>

One hour of my life wasted to save you 1 hour! The myget feed is currently on dotnet.myget.org

Continuous Integration cloud services

Friday August 26, 2016

I’ve probably missed a couple, but this is a list I’ve compiled of all the CI services I know about, geared towards cheapo devs on a budget. My area of expertise is Teamcity, Octopus, Bamboo, Gitlab and a bit of Jenkins and Travis, and limited to dot net core.

.NET Core and .NET Standard simplified and explained by Scott Hunter

Monday July 18, 2016

With all the changes to .NET that have happened this year, and the constantly evolving .NET core/standard (and the bombshell that project.json is going), it’s quite hard to decipher what Microsoft are doing to the frameworks besides the main marketing features of it running on Linux/MacOS with NPM style packages and ASP.NET getting Kestrel.

Probably the clearest explanation I’ve found is hidden away in this DotNetConf Keynote by Scott Hunter. The first 20 minutes gives the lowdown on the new architecture, or you can read the slides if you don’t have time.

.net today

Note: The usage of Core library in this slide is slightly confusing, Scott is referring to System.Core.dll and for Base Class Library (BCL) this is typically system.dll

And if you really don’t want to read the slides, my summary would be: .net standard is a versioned contract that the implementation has to adhere to (like the CLR and CLS standards). It’ll get more APIs over time, and each implementation will have to honor the contract to keep up. If you want to be re-confused, try reading this doc. Why is everything version 4? Probably because it came straight from the .NET 4.0 code base.

So .NET Core is an implementation of the .NET Standard (.NET Core is version 1.0 right now, .NET Standard is version 1.6). The version numbers really don’t help at all, they would’ve benefited from resetting them all to 1.0 and blown a big raspberry at anyone who was using the betas and RC1 and RC2.

.net core

Also worth checking out is the .NET roadmap up until the start of 2017

Podcast of the week

Sunday May 8, 2016

Not really a podcast, more of a vodcast, the discussion talks about fasting (Ray Cronise had just been on a 30 day water fast), hot/cold therapy and the Vim Hoff method and the concept of being satiated.

Do you write unit tests before code, or after?

Thursday May 5, 2016

One of the biggest omissions in the TDD literature is the concept of code first vs test first. The discussion doesn’t seem to surface very often, possibly because it’s a more advanced topic.

Both are valid ways of doing TDD, and after many years of doing both I think I’ve finally settled on a few good ways to decide which method to employ:

Test first:

  • You’re writing business or safety critical code
  • You are experimenting with an API etc. that you don’t know how to use.
  • You are pairing with someone
  • Like most of us, you find writing tests later very monotonous work
  • You’re doing a presentation on TDD

Code first

  • You’re writing a proof if concept, or small home project
  • You haven’t fleshed out the API you’re writing yet, or unsure of it’s design
  • You’re writing code that is so basic, such as de-serialization of a config file, or breaks the system in such an obvious way, tests can be added later
  • You’re on your own and demotivated

With the code first approach I’m not advocating lowering your test coverage - you would still have the tests in there before you ‘ship’.