Woman frustrated with her laptop
Woman frustrated with her laptop

I’ve noticed when using tsc in watch mode that sometimes — especially if a file has been renamed — it doesn’t realise the file needs recompiling. This state persists across reboots, restarting the watcher, all the usual stuff.

The last time I hit this was when I needed to re-order the seed files I’m using for this project. A file that had been last needed to be first, everything had to move around as I use numbers in the filenames to ensure the seeding order is clear. Mostly it works really well.

Renaming the files wasn’t a problem, but suddenly…


Recently I’ve been working on integration with a subscription/payment gateway (It hasn’t been straightforward, but that’s a whole other post).

I wanted to be able to test my web-hook code without repeatedly triggering events from the gateway. I stored the incoming events in JSON format, which was fine — but then of course I needed to take the stored events and do something with them.

I thought it might be interesting to make a note of where I started from and how I got to the end. I’ve included the mistakes I made along the way, so if you read…


Title image — typewriter in background with title text overlayed.
Title image — typewriter in background with title text overlayed.

Looking at several different editors

Since I’ve started blogging I’ve naturally needed more from my editors, in terms of both writing and organisation.

For better or worse, blogging and static site systems seem to have settled on Markdown for formatting input. It has the advantage of being fairly simple to learn and using only normal text characters for formatting.

I’ve tried various different editors for writing text — iA Writer, MarkdownPad, StackEdit, and of course Vim/Emacs. Here’s why I’ve settled on Ulysses for my editing.

Ulysses

It has great Markdown support, but more than that:

  • it integrates with multiple blogging platforms…

I had a revelation the other day.

In the beginning…

I was of the idea that to make your UI pretty and reactive, you needed to be using Vue.js, Svelte, or some other web framework. Otherwise, the page just sat there until you clicked a button, and then reloaded. Silly, I know now.

Then I discovered Alpine.js and realized I was completely wrong.


Or, how to use Hapi pre-route handlers

The problem

As I added more methods to my latest project, I realised that there was an increasing amount of wasted effort.

In every endpoint dealing with an item, we had to fetch the item. That also meant that every endpoint also had to deal with checking the user had the right to access that item. When I started adding things belonging to things, and we then had to check the chain of ownership held, it started getting tedious.

I started to think — Express has middleware, I wonder what Hapi has? There’s bound to…


I’ve been lucky enough to discover some good new desktop and coding tools via Medium and dev.to lately. I thought I’d share some of the less common ones I use.

Insomnia

Insomnia is great for testing web APIs. The app is free; the company who make it do also offer paid plans for sharing the requests you’ve defined, useful if you’re in a team.

Image taken from Insomnia website

Postbird

This is a really useful app for connecting to PostgreSQL instances and examining them. It’s able to look at the schemas as well as the contents of the tables, and edit them. …


Example of a DNS lookup resolving to 127.0.0.1
Example of a DNS lookup resolving to 127.0.0.1

The technique we’re using is the one used by Google, Microsoft, and others to verify that you’ve got some authority over a domain. So while it’s not foolproof, at least we’re in good company!

The code in this article is TypeScript, but the same method would work in most languages.

Overview

All of the verification methods I’ve seen for these rely on the user being able to modify the site in some way — which makes sense, since you’re checking if they have control over the site they’re trying to use.

Most of them seem to have settled on using some…


Things to make the every-day better

These are all standalone tools — not Node modules, browser extensions, or VS Code extensions.

1. The Silver Searcher (ag)

Silver Searcher (ag for short) is a fantastically fast searcher, much faster than grep. It comes with defaults which work for the majority of cases. It understands .gitignore files, as well as ignore files for other tools, so it can avoid searching ‘uninteresting’ files.

It’s easy to use to search specific source formats, and it knows to ignore object files and other generated files by default.

Example of ag’s search output, searching rust files
Example of ag’s search output, searching rust files
Example of ag’s search output, searching rust files

I’m told ripgrep is also a good grep replacement, but I haven’t tried it.

2. fd

fd is like ag


Measure, then Act

Today I’ve been reminded of the importance of measuring first, rather than making assumptions.

I thought I’d write a post walking through it — that way at least something useful might come out of it, if it helps someone else.

Background

The last couple of days I’ve been trying to improve test running speed. It was fine to start with but the more tests I added, the longer the runs took. When it got to the point that in some sections each test was taking 600–1300ms, I got fed up enough to do something about it.

Starting point

I suspected it was probably…


‘Hello world’ in EJS template
‘Hello world’ in EJS template

In this post we’ll add to our application from the previous set of posts. We’ll be using Vision for template rendering and Joi for input validation.

Vision

Vision adds methods to the Server, Request, and ResponseToolkit interfaces so you can use view engines to render templates. It’s agnostic of the particular engine used; we’ll be using EJS in this post, simply because I’m familiar with it.

Setup

The usual deal with packages:

$ yarn add @hapi/vision ejs
$ yarn add -D @types/hapi__vision @types/ejs

We’ll also need somewhere to put the templates; it’s not very imaginative but I usually use a directory named…

Paul Walker

Software engineer in Bristol, UK. Playing around in my spare time with Nodejs, Typescript, Elixir and Phoenix, Vue and more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store