Relatively Ignorant A blog on things about which I may or may not know stuff069ce0f8b975b6fce829d95e17bc1765bfc32407

Careful what you promise

|

Background

I was working recently on a JavaScript front-end project using ES6 async / await syntax. We created a client to back-end services hosted on AWS Lambda via AWS API Gateway.

The client is successful at fetching temporary auth tokens and credentials from specified endpoints, using the credentials to call signed services, and automatically refreshing tokens or credentials when they are about to expire.

Our code calls services using the Axios library, which returns promises. A simple example method is:

const getData = async (url, config) => {
  const { data } = await axios.get(url, config);
  return data;
}

A refactoring mistake

I was refactoring the function’s code to add AWS signing headers to the config argument before passing it to Axios. (That task was previously done elsewhere.) Given a function addAwsHeaders that adds the headers, I wrote something like this:

const getData = async (url, config) => {
  const { data } = await axios.get(url, addAwsHeaders(url, config));
  return data;
}

But my tests failed with unresolved promises. This is because the addAwsHeaders function is asynchronous (the auth tokens or credentials may be stale and new ones requested) and returns a promise that my code was not resolving.

A correct versions is:

const getData = async (url, config) => {
  const awsHeaders = await addAwsHeaders(url, config);
  const { data } = await axios.get(url, awsHeaders);
  return data;
}

It is important to pass the resolved value from the promise, not the promise itself, to the function.

I voted Yes for marriage equality

|

Today I voted Yes in the Australian postal survey for marriage equality. It was an easy decision. Quite simply, love is love, this is a matter of fundamental human equality, and the details of other people’s love for each other is none of my business.

I voted yes

Is it OK to vote “no” as the naysayers’ slogan goes? Of course, because everybody is free to vote as they choose.

But it is not OK to base your decision on misleading allegations about the ill-effects on children of same-sex parenting, curbs on religious freedoms, or fears about the follow-on effects (to name a few). All of these claims have been refuted in a number of places, if you care to look. Many countries have already accepted marriage equality and those fears have not materialised there.

Do the people making dire claims about the effects of marriage equality really believe the things they say, given their dubious veracity, or is there some underlying, unexpressed reason? I think they actually find ‘non-standard’ sexuality at least unsettling and probably repulsive.

I think there is a spectrum of views from dislike (I won’t do that) to disgust (I don’t like to think about that) to disapproval (I don’t want you do that). Disapproval is a moral judgement about other people’s behaviour. And moral judgement invites people to extend their views about what is, and is not, their own business.

Some handy Git aliases

|

I got some useful Git aliases a while ago and was starting with a new client where I needed to recreate them so I decided the document them here.

git s is useful for short status display, defined like this:

git config --global alias.s 'status --short'

git lg is a short, graphical log display, defined like this:

git config --global alias.lg 'log --oneline --decorate --graph'

Example output is:

Git log output with --decorate

Then I decided to augment it with useful extra information, including colouring.

git config --global alias.lg 'log --graph --format="%C(auto)%h %C(cyan)%cn%C(auto)%d %s %C(magenta)%cr"'

Git log output with --format

The %C(auto) specification does not colour committer name or date, so I coloured those explicitly.

Documentation is here:

iCloud one-way synchronisation issue

|

I was finally able to resolve an iCloud synchronisation issue between my iPhone and Mac.

Calendar entries created on my Mac were immediately copied to my iPhone and iPad but entries created or edited on my iPhone were never synchronised back to the other devices. This was inconvenient because I carry my phone everywhere and needed events created there to be available on all my devices.

The solution was simple: sign out from iCloud on the phone and sign back in again.

Putting tags into HTML meta keywords

|

I wanted to include a page’s tags in an HTML meta tag as keywords.

Given a page with these tags:

I want the HTML header to contain:

<meta name="keywords" content="gradle,spring-boot"> 

I achieved that simply by adding this into the head.html include file:


  {% if page.tags %}
  <meta name="keywords" content="{{ page.tags | join: ',' }}">
  {% endif %}