Randomise This

Summary

Recently I stumbled across an interesting blog called usesthis. Since it has a rather extensive backlog of articles I wrote a simple script in Scala to pick out a random category and a random interview within the category.

There may be a possibility to augment this script and create a more full-featured App.

Context

Last year I discovered the usesthis blog. It’s a tools blog consisting of interviews with professionals from a variety of industries. The author Daniel (can’t find his surname) asks every interviewee the same four questions:

  1. Who are you, and what do you do?
  2. What hardware do you use?
  3. And what software?
  4. What would be your dream setup?

Given my interest in professional tools (I have actually appeared on a long-running podcast called Cool Tools) I was surprised to learn that this blog had in fact been going since 2009 and in that time had amassed several hundreds of interviews. Since there was no way I would go all the way back to the start and read from the beginning I thought perhaps there would be a better way to find articles.

I’d noticed that Daniel had organised the interviews into categories based on the interviewees’ professions and he’d made an API available so anyone could query the interviews. With my previous interest in generating NFTs from random starting points, I started to wonder… Could I use this API to pull random categories and then random interviews from those categories…?

Technical aspects

As I’ve been investigating Functional Programming for some time now I decided to code this project up in Scala. It’s not a particularly complex programme, it uses a JSON module read usesthis’s API from there I create two URLs corresponding to a randomly selected category and a randomly selected interview within that category.

Probably the most interesting aspect is that the JSON object needs some processing to create the URLs. This involves using a map to create a list of categories:

val categoryNames = categories.map(category => (category \ "name").values.toString)

val categoryList: List[String] = categoryNames.toList

Check out my GitHub for the basic Scala code. You can run this on your own machine if you put the files in a Giter8 template and run this on Scala’s sbt.

Script in action

Apologies for the poor image quality here, I’m working on a better solution

Thoughts on expanding the code

Much more could be done to make this code useful. I had thought about attempting to implement the code in this post as a button you could click to generate the links. However, this blog is a static site that I generate manually on my home PC and deploy to Firebase. I’m not clear on how I could implement a dynamic button that could generate a new link each time you click on it.

I do think it might be possible to create a simple Vue App based on the URLs the Scala generates. While looking into this I also discovered a Scala framework called play.

Ultimately though I think I will apply it in Vue, once I get around to learning that…

Randomise This by William Samuel McDonald is licensed under CC BY 4.0

education

Scala

programming