Using Mockito With Scala Value Classes

2 mins

tl;dr: When mocking functions that have value classes as arguments, use Mockito matchers on the wrapped value instead of on the value class (i.e. MyId(any[Int]) instead of any[MyId]) or else NullPointerExceptions will be thrown at runtime.

How (Not) To Thread State Through a JavaScript Promise Chain

6 mins

Last weekend I created a GitHub Action and submitted it to the GitHub Hackathon. It was a relatively simple workflow that brings up a WireMock API for tests to run against.

It was pretty cool as I hadn’t had a chance to write a Node application before. (The other way to write an Action is to build a Docker image, in which case any language can be used.)

In this post, I’m going to share my thought process bemoan my follies as I went about writing the Action.

Action repository:

Tl;dr In JavaScript, use async await to deal with intermediate state, much simpler. Also, just having documentation from types make TypeScript awesome, even if you don’t write your application in TypeScript.

Data Processing with Bash

7 mins

Inspired by this post, I built a pipeline to extract facilities from ~700K hotels, combine all repeated facilities and rank by number of occurences, all in Bash.

TL;DR commands:

echo "supplier_id,supplier_value,mapping_type" > header.csv

cat hotel-facility-dump | \                 #read from file
rg "facility:" | \                          #find relevant logs
awk -F'facility: ' '{print $2}' | \         #extract content in the form of 'facility name,facility code'
sort | \                                    #sort for the next step
uniq -c | \                                 #get all unique entries with count
sort --numeric-sort --reverse | \           #get entries with count in descending order
head -n 500 | \                             #take top 500 entries
awk -F ' "' '{print 12345",""\42"$2}' > \   #remove count and put back double quote
hotel-processed                             #write to output file

cat header.txt hotel-processed > hotel-facilites.csv

Everything I Know About Development in 2019

13 mins

I’m starting this series so that I can track how far I’ve gone in my career as an engineer.

In true Dan Abramov style I’ll be listing what I don’t know as well, so that I can concentrate on learning those things in the future.

SBT Tricks

3 mins

I was recently upgrading a library at work from using Scala 2.11 to 2.12. Here are some sbt tricks that I picked up while trying to perform the migration.