software engineering

List all files changed in last commit

By Adam K Dean on

List all files changed in the last commit by using git diff-tree on HEAD.

git diff-tree --no-commit-id --name-only -r HEAD

For example, if you changed in your last commit:

adam@macbook:project (master) $ git diff-tree --no-commit-id --name-only -r HEAD

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.