Nodeunit and Proxies

With ES6 in javascript we get a lot of cool things to make it a proper programming language, fun stuff like Proxy.

Recently I found a nice use for Proxies when writing tests however the nodeunit runner doesn't support the --harmony-proxies parameter a small runner was created to allow us to run tests with working Proxy support. Just create a small script that looks something like this.

const reporter = require('nodeunit').reporters.minimal;
let args = process.argv;

And invoke it using:
node --harmony-proxies runtests.js $(find ./tests -name \*.js)

Yubikey & KeePass cross platform

A while back i got a Yubikey Neo and a Neo-n they are cool little devices that can work as the second part of a 2 factor authentication. The Neo apart from usb also supports Nfc so it can be used with most modern Android phones. So here's a short summary of how to get it all working. To get everything to work you need to install the KeeChallenge plugin in KeePass, I used the latest version (2.29) when setting everything up. The trick is to put the password file on something shared that everything can read usb stick, Dropbox or similar.

KeePass on windows

For windows follow this guide. Don't forget to copy the files from the YubiKey-Personalization release.

KeePass on OSX

On OSX the use following guide. A bit more hands on work but just follow the steps. Currently it seems like mono 4.0.2 doesn't work so go with 4.0.1.

KeePass on Android

On android you need the Keepass2Android Password Safe and YubiChallenge and a phone that supports Nfc, most modern Android phones do.


Nope, return in a couple of years when iOS has working nfc support

Home monitoring and sensors

I like dashboards

everything So I built one using InfluxDB, Grafana, Nginx, Tellstick Net and a bunch of scripts. Here's a breakdown of the parts and what feeds them.


At home i have a Tellstick Net and a bunch of remotecontrolled power switches connected to this i also have a bunch of temperature sensors (this model) places around the house, outside and in my shed.

Logging to InfluxDB

Data is fed into InfluxDB using a couple of different scripts.

  • Temperatures are read from Telldus Live using a modified version of their script every 10 minutes
  • To log status for my home server running ubuntu I modified my status script, this is logged every 5 minutes.
  • Ping & packet loss is logged with a simple ping script, right now it only pings googles public dns but is should be extended to ping multiple things (isp dns server etc) currently this script runs every minute


I plan to add more fun sensors that work with Tellstick, things like rain and wind sensors. Something that logs how bright the sun is would be cool to. At some point when I have more info it will be fun to do some 'big data' stuff using the data set I have, right now it's been running for about 6 months so next year it's possible to graph current vs last year for many values.

AutoMapper & AutoFac


So I tend to develop things in the way of

  1. Make it work
  2. Make it pretty

Make it work

So when using AutoMapper after step one I ended up with something like this

.ForMember(d => d.SomeSource, 
     o => o.MapFrom(
          s => new Serializer().Deserialize<SomeViewModel>(s.Serialized)))

Some background, for the destination SomeSource I needed to Deserialize the value as it was currently stored as Json in my database.

Make it pretty

While it works it looks rather horrible, so I started looking into something that allowed me to get a ISerializer from AutoFac (my IoC of choice) instead.

So, first I added a custom ValueResolver that looked like this

public class SomeViewModelResolver 
    : ValueResolver<OrderRow, ScheduleViewModel>
        private readonly ISerializer _serializer;

        public ScheduleViewModelResolver(ISerializer serializer)
            _serializer = serializer;

        protected override SomeViewModel ResolveCore(Source source)
            return _serializer.Deserialize<SomeViewModel>(source.Serialized);

Next was to connect AutoMapper with AutoFac and to register the ValueResolver:

// Register my new valueresolver

// Connect AutoMapper to AutoFac
Mapper.Initialize(x => x.ConstructServicesUsing(container.Resolve));

Once that is done the last thing to change is to modify the ForMember call to use the new ValueResolver instead

.ForMember(d => d.SomeSource, o => o.ResolveUsing<SomeViewModelResolver>())

Looks a lot cleaner and follows the flow that you would expect when using a IoC container.


If you don't want to have calls to the static Mapper.Map<> all over your code, it is possible to register the IMappingEngine in AutoMapper in you IoC container and have that as an dependency for you class too. For AutoFac the registration looks like this

builder.Register(c => Mapper.Engine).As<IMappingEngine>().SingleInstance();

The important thing is to register it as a singelton. Once that is done just add IMappingEngine mappingEngine to the constructors of those classes that use AutomMapper.