software engineering

Change keyboard layout on Ubuntu + Xrdp

By Adam K Dean on

If you're using Ubuntu with Xrdp, and you find the keyboard to be infuriatingly inaccurate, you should probably change it. To do this, you need to have the ability to open the System Settings window, which you can't always do over RDP. In there, go to Text Entry, and click the little plus at the bottom. Now select the keyboard layout that applies to you, and test it works.

Now, finally, to make these settings apply to Xrdp, run the following command:

sudo xrdp-genkeymap /etc/xrdp/km-0409.ini

Logout, log back in with Xrdp and it should now work.

Available devtools for webpack

By Adam K Dean on

In case the webpack docs ever lose this, here is a list of available devtools. Choose a developer tool to enhance debugging.

eval - Each module is executed with eval and //@ sourceURL.
source-map - A SourceMap is emitted. See also output.sourceMapFilename.
hidden-source-map - Same as source-map, but doesn't add a reference comment to the bundle.
inline-source-map - A SourceMap is added as DataUrl to the JavaScript file.
eval-source-map - Each module is executed with eval and a SourceMap is added as DataUrl to the eval.
cheap-source-map - A SourceMap without column-mappings. SourceMaps from loaders are not used.
cheap-module-source-map - A SourceMap without column-mappings. SourceMaps from loaders are simplified to a single mapping per line.

Prefixing @, # or #@ will enforce a pragma style. (Defaults to #, recommended)

Combinations are possible. hidden, inline, eval and pragma style are exclusive.
i. e. cheap-module-inline-source-map, cheap-eval-source-map, #@source-map

Encapsulating console.log with spread operator

By Adam K Dean on

ES6 or ES2015 contains lots of goodies. One of them, my favourite, is the spread operator. It "allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected."

For example, you can combine two arrays like so:

var start = ['a', 'b', 'c'],
    end = ['d', 'e', 'f'];

var combined = [...start, ...end];


// => ['a', 'b', 'c', 'd', 'e', 'f']

What I like even more, is that you can do this with function arguments. Let's say we wanted to wrap console.log so we can do something funky with it. This can easily be done using the spread operator.

var log = function (format, ...args) {
    if (args.length > 0) console.log(format, args);
    else console.log(format);

log('this is an %s test', 'interpolation');

// => test
// => this is an interpolation test

This changes things. Read more at MDN.

ES7 should also bring object spread operators, so you can do { ...initial, ...change }.

Speed up OS X terminal startup

By Adam K Dean on

Following on from my tweet the other day, I thought I'd publish this 'trick' here.

I have found my terminal gets really slow after about six months of use, and the trick to clear it up is to remove a shedload of log files which OS X seems to hoard. Now, if you're particular precious about your terminal history then don't do this, but if you'd prefer not to wait a second for your terminal to log in, then you can clean up the logs like so:

sudo rm -rf /private/var/log/asl/*.asl

Disclaimer: using sudo rm -rf without understanding what you're doing can be dangerous. If you don't understand it, don't mess with it. If you do, it's not my fault you broke your machine. Please read more about rm first.

Determine volume location on Docker host

By Adam K Dean on

Yesterday I was having an issue that I've had before. It stumped me last time and it stumped me again. I just didn't think and it cost me too much time.

The problem I was having, a problem I'd had before, is that I run Jenkins in a container with the Docker host socket passed through, so when Jenkins creates containers, they actually run on the host alongside it. This is great, but when you need to directly map files from the workspace to the container, things don't act the way you may expect.

This is because the host is running the docker commands, Jenkins simply talks to the host via the socket. So those files that are in /jenkins/jobs/yourjob/workspace/... won't be in that location on the host.

The way I run Jenkins is that I have a data volume container called jenkins_data which as you've guessed, holds the data. In order to use a -v src:dest volume map, I'm going to need to locate these files on the host. Docker inspect helps here.

docker inspect --format '{{ range .Mounts }}{{ if eq .Destination "/jenkins" }}{{ .Source }}{{ end }}{{ end }}' jenkins

Once I have the location, I need to do a search and replace on the $WORKSPACE variables which Jenkins exposes. After that, I have the location of the /jenkins volume on the host.

JENKINS_ROOT=$(docker inspect --format '{{ range .Mounts }}{{ if eq .Destination "/jenkins" }}{{ .Source }}{{ end }}{{ end }}' jenkins)
JENKINS_PATH=$(echo $WORKSPACE | sed "s|^\/jenkins|$JENKINS_ROOT|g")

Now I have $JENKINS_PATH I can directly map files or directories in from within my container.

docker run d \
    -v $JENKINS_PATH/some/file.js:/var/lib/app/file.js \
    -v $JENKINS_PATH/dir:/var/lib/app/dir \