Recent Posts

Change your Powershell prompt to look like bash

Thursday February 23, 2017

The script below changes your Powershell prompt to look a bit more like a Bash one. Update your ~Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 file to add the code below. If you aren’t using poshgit then remove the Import-Module and Write-VcsStatus lines.

Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-7d93c81\src\posh-git.psd1'
function prompt {
    # Shorten the path
    $path = $ExecutionContext.SessionState.Path.CurrentLocation.Path
    $path = $path.Replace($HOME, "~") 

    Write-Host "$path" -ForegroundColor Green -NoNewline
    Write-Host ""
    "$('$' * ($nestedPromptLevel + 1)) "

Your Powershell command prompt will now look something like this:

~\Documents\Code\Github\\_posts [master ≡]
$ echo "hello world"

.NET Core continous integration and deployment with Gitlab, Docker, Kubernetes and Google Cloud

Wednesday February 1, 2017

Over the past few months I’ve put Roadkill on hold in my free time, to get some .NET core projects working inside Docker. They’re mostly sandbox websites for exploring the tech stack, and are hosted privately in Gitlab. Gitlab gives you a decent CI server for free, which works really well with CI and deployment of .NET core apps (both websites and console apps).

Podcast of the Month Oct 2016

Sunday October 16, 2016

The first 30 minutes of this podcast are worth a listen alone, Chris Kresser discusses how your stomach biome is linked to depression, your brain and cravings. After that they discuss the role of meat in providing nutrition to humans, and how we don’t consider ourselves animals anymore.

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.

Some relevant Stackoverflow posts that helped:


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.