Visual Studio, C++ & Google Test

Using Visual Studio for C++ and Google Test seems like it should be absolutely straightforward. I’m trying to do everything in Visual Studio, so it should just set it up automatically right at the start when I create a project. Perhaps I am spoilt from working primarily with Java for many years, but here I was, trying to set it up and it took an inordinate amount of time.

First things first, the way it works in C++, at least in Visual Studio, unlike in Java is that the tests are set up in a separate project, but within the same solution. I will try and remember all the steps I had to undertake to set this up.

This, however, is not the only requirement. When testing, since we can have only one main function in the final executable, it also makes sense to put all of your code, apart from the main function for your application in another project.

In summary, you end up with three projects

  • Your Solution
    • Static Library with all your code *except* the main function
    • Executable project with your main function (linked with your static library above)
    • Tests project (again, linked with your static library above.

Once you have this set up, you will want to add a reference to the static library from both the executable project and the tests project

Finally, you will also have to update the linker to link with the library project. I am sure there is a better way of doing this, but I did it by right clicking the project -> Properties -> Linker -> General:

Additional Library Directories -> and adding in something like “$(SolutionDir)<lib-folder>\$(IntermediateOutputPath)*.obj

You may have to add the same into Linker -> Input -> Additional Dependencies.

Hope that helps

How to fix terminal title after disconnecting from ssh

For some reason, ssh does not clean up after itself in terms of updating the terminal title when you disconnect.

Here is a simple solution, a combination of https://unix.stackexchange.com/a/341277/25975 and https://unix.stackexchange.com/a/28520/25975

Add the following functions into your ~/.bashrc It will push the current title and icon into a stack and pop it afterwards.

function ssh()
{
    # push current title and icon to stack
    echo -ne '\e[22t'
    # Execute ssh as expected
    /usr/bin/ssh "$@"
    # revert the window title after the ssh command
    echo -ne '\e[23t'
}

Restart bash / log out and back in, and it should work.

For security reasons, it is not possible to query the current title of the terminal. However, with the following command, you can push the current one on to a stack

echo -ne '\e[22t'

The title can then be set to anything, by ssh for example. You can then pop that back from the stack using

echo -ne '\e[23t'

Getting Docker Desktop Working with WSL2 on Windows

I ran into several issues while trying to get this to work. Here are the steps I had to complete to get it working. Hopefully this will save some hair on your head 😉

The main step is to go into the settings in Docker Desktop -> Resources and make sure that your distribution is enabled for docker.

  1. Make sure that you have no docker packages installed on your WSL distribution. Docker Desktop will deploy its own binaries, and any pre-existing binaries will confuse it. This issue exhibited itself for me with errors related to missing files around credentials.
  2. Remove any DOCKER_HOST environment variables. Docker Desktop will sort it out. Docker kept hanging for me until I fixed this.
  3. If you want to use docker as non-root user, add yourself to the docker group.

Errors / Issues I ran into:

docker.credentials.errors.InitializationError: docker-credential-desktop.exe not installed or not available in PATH – Fixed by 1 above.

docker-compose from WSL2 errors out – Again, fixed by 1

Unable to run docker as non-root user – fixed by 3.

Docker hangs when run as non-root user – fixed by 2.

How do you access a specific version of a parameter from AWS Systems Manager Parameter Store

This was a bit tricky to find and doesn’t seem to be well documented.


    // version number below can be a number, i.e. 3 or a label
    let params = {
      Name: "/path/to/parameter:<version-number>",
      WithDecryption: false
    };

    ssm.getParameter(params, function (err, data) {
      if (err) console.error(err, err.stack);
      else console.log(data)
    });

Getting vuex-module-decorators to work in nuxt

There are a few caveats to integrating vuex-module-decorators with nuxt. The first steps are described in the README (although I missed it because it nuxt was in the small text).

In addition to this, according to issue #179, there are a few other caveats

List of Installed Programs on Windows from java

I was recently in need of a way to pick up the list of installed software on a windows computer from Java. It was shrouded in a veil a mystery. There did not seem to be a functional call that I could make, which makes sense since Java is cross-platform and there is not universal way to pick up all the installed packages on an OS.

In fact, picking up all the installed packages on Windows seems be a bit cryptic. There are API calls you can make and I considered JNI. I suspect this might be a superior solution, but I haven’t tried it and I read that it may be slow.

After much research, I came across ListPrograms. My initial thought was to link to it using JNI. However, it seemed simple enough to warrant a rewrite in Java if I could access the registry somehow.

This is where JNA and the Advapi32Util class came in handy.

It didn’t take me long to put together a quick replica of behaviour. I skipped out the part about user installed programs because it isn’t relevant for me (yet).

I also missed out issues which will be around when running it as part of a 32bit VM within a 64bit OS.

You can find JavaListApps at GitHub

What I learnt developing a small JavaFX App [WIP]

Introduction

This is a collection of the things I learnt developing a simple JavaFX app over the last month or two. My background is very much in Java EE with decades of experience building high end, high-performance ticketing systems. This means that my expectation from a development environment is relatively high. There are many optional components in here that I find worthwhile setting up at the start, but are not necessary

Tools

Maven

One of the most useful tools I have found while working with Java is maven. If maven isn’t a part of your build, have a look at it and re-evaluate that. I have no doubt that maven has saved me hundreds, if not thousands of hours over the last few years.

JavaFX Scene Builder

While this one has a bunch of issues and serious limitations, it can still be a helpful tool. It helped me get a handle on the components available and placing items.

Libraries

Testing

I use junit5, but there are other options like test-ng which are equally good. I use Mockito for mocking, but there are many other options like PowerMock, JMockit, EasyMock, etc.

For UI Testing, you can use TestFX. I don’t like UI work, so haven’t done much work with this.

    org.junit.platform
    junit-platform-launcher
    1.2.0
    test


    org.junit.jupiter
    junit-jupiter-engine
    5.2.0
    test


    org.junit.vintage
    junit-vintage-engine
    5.2.0
    test



    org.mockito
    mockito-core
    2.18.3
    test

Logging

I can’t live without logging in any application. It can make troubleshooting much easier, particularly when you’ve deployed your app. log4j2 is the main logging framework out there. You can choose another one if you like, but I strongly recommend having and using one.

    org.apache.logging.log4j	
    log4j-slf4j-impl
    2.11.0


    org.apache.logging.log4j
    log4j-api
    2.11.0


    org.apache.logging.log4j
    log4j-core
    2.11.0

Dependency Injection

If you have working the Java EE Environment, you have almost certainly come across Inversion of Control,  particularly in the form of Dependency Injection. I love dependency injection. It helps with decoupling components and with testing. I looked at various frameworks including Dagger 2, Spring, Guice.

Dagger

The fully static (compile time) nature of Dagger 2 means that it doesn’t gel well with JavaFX which is very dynamic.

Spring

I had worked with Spring many years ago and didn’t want to tangle with a behemoth for a small project. There are many components and loads of functionality in spring and if you building a large and complex project, it might be worth it.

Google Guice

Google Guice is the framework that I ended up going with. It does have some dependencies like Guava, but as it turned out, I Guava comes in handy for JavaFX anyway. We don’t need an entry in the pom.xml for this because of the following dependency.

Gluon Ignite

Gluon Ignite was released by gluon labs to integrate Dependency Injection frameworks with JavaFX. In other words, it ties in the DI framework with the FXMLLoader so that it will load the correct controller instances. Since I am using Guice, I needed the ignore-guice module. If you add this into your pom.xml, it will also pull in google guice. Easy eh? 😉

	com.gluonhq
	ignite-guice
	1.0.2

If you don’t want to add another dependency, you could take a look at the code in this module. It’s fairly straightforward to integrate that manually into your app. It’s just easier to add in the dependency and let it do the magic

Event / Publisher / Subscriber Framework

It is likely that you will need an event framework or a publisher/subscriber framework. The nature of GUI design and work is that it is an easy and simple solution for a number of problems you will come across. Fortunately, we already have an event framework in place within Guava which is a dependency of Google Guice.

Project Lombok

Don’t you love adding in a getter and a setter for each field? When you change your fields, don’t you love going in and updating all the getters and setters? How about defining the long, pita to type types with generics of variables that you are assigning from a method call? I mean the compiler can’t possibly figure that out by itself, right? How about writing out the toString, equals and hashCode for each class? What do you mean no, you don’t? You don’t love these tedious repetitive tasks of development? Good! You will love Lombok. Unfortunately, with Lombok, it’s not as simple as adding it into your pom.xml. Check out the install instructions on their website for you IDE etc. You also need it in your pom.xml.

	org.projectlombok
	lombok
	1.18.0
	provided

There is some controversy around Lombok. There is a good post on stackoverflow that covers some of these things in a reasonable fashion.

Apache Commons

Last but certainly not least, we have apache commons. This is a collection of libraries rather than a single one. You know all those bits of code you write over and over. Chances are that there is something in here that does it better and in a simpler way.

Persistence

TBC

Packaging

TBC

Shipwrecked | Let’s Play The Azure Isle

I stumbled across this game on gamejolt.com and tried it out. It sucked me in and I was smitten. See what happened.

#01 – Shipwrecked

 

We find ourselves shipwrecked on an island we don’t recognise. Let’s explore

#02 – Heading East

 

What’s over there in the east of the island? I get stuck, and think it’s all over, but there is more.

Daily Meditation | Let’s Meditate with Playne

I am involved in the beta testing for playne, a meditation game. While I had meditated many many times in my life, I had never done it consistently. That is, until Playne.

I got curious about doing it as a series, and here it is

This episodes talks about getting started with Playne

#01 – Getting Started

 

Let’s get started with Playne

#02 – Settling in

 

Settling into meditating daily

#03 – Time for meditation

 

Making time for meditation is important

#04 – Layers of the mind

 

The mind is like an onion – so many layers and it makes you cry.

#05 – Level 2

 

We get to level 2

#06 – Positive Changes

 

Have you started seeing positive changes?

#07 – One Week in

 

That’s one week of meditating daily. How do you feel?

#08 – Stick with it

 

There are definitely benefits to sticking to meditating daily

#09 –

Unfolding the Story | Let’s Play Epistory

The other day I stumbled across Origin All Access and saw that it had a bunch of games I wanted to play. One of these was Epistory, which had been in my wishlist for a long time. When trying the game out, I fell in love with it. It is absolutely a treat, so I decided to go through it as part of a let’s play.

#01 – Signal Fires

 

A meteor falls from the sky, and everything changes.

#02 – Forgotten Forest

 

We find a dark forest, forgotten and resistant.

#03 – Cold Shoulder

 

We witness another calamity, which once again changes everything.

#04 – Drowning Halls

 

Ice and water in these halls. Do we learn another language?

#05 – Spark

 

We stumble across Chapter 3 and another language

#06 – Creation City

 

Explore the rest of Creation City

#07 – Ice Mausoleum

 

We come across the Ice Mausoleum while exploring and delve into it.

#08 – Winds of Change

 

We run across Chapter 4 while exploring.

#09 – Shattered Isles

 

We go into the shattered isles and discover the fourth language.