Tristan Penman's Blog

Roll Your Own Ruby Type Checking: Part 3

20 May 2023

In parts one and two of this series, we built a basic runtime type checker for Ruby. The design of our type checker is heavily inspired by Sorbet. So much so that we run up against some of the same limitations as Sorbet. This post focuses on one of those limitations - the inability to perform type checks on parameters with default values. To better understand this, we’ll look at several examples in both Ruby and Python.


Roll Your Own Ruby Type Checking: Part 2

13 May 2023

In my last post on Ruby Type Checking, we looked at how metaprogramming could be used to implement an annotation-style syntax in Ruby. We then leveraged these techniques to build a simple runtime type checker, heaviliy inspired by Sorbet. Unfortunately, our type checker is woefully incomplete. In this post, we take another step towards making it useful.


Porting Asteroids to the Nintendo 64

31 December 2022

It was during Melbourne’s record-breaking 2020 lockdown that I rediscovered my interest in retro console development. While I had previously dabbled in homebrew for consoles from the 16-bit era, it was now the later generation consoles, such as the Nintendo 64 and SEGA Dreamcast, that caught my interest. These consoles represented the earliest days of the 3D era, each with their own quirks.


Roll Your Own Ruby Type Checking: Part 1

26 December 2022

Earlier this year, I was talking with a colleague about Sorbet and other type checking features that are available for Ruby. Although we were with familiar with usage of gradual typing in other languages such as TypeScript and Python, neither of us really knew how this would work under the hood.


Preprocessing JSON... using JSON

15 November 2020

Many years ago, I was faced with the problem of constructing CloudFormation templates as part of an automated build pipeline. One of the requirements was that these JSON-formatted templates had to reference AWS resources that belonged to existing CFN stacks. There are many ways to do this, but one of the ideas I experimented with was a JSON templating system, based on simple ‘directives’, inspired by the JSON Reference specification. I’ve recently published the code as a Python package, and thought it would be interesting to write a post about what it can do. The posts finishes up with some thoughts about what it could do…


Getting started with CUDA on AWS

05 October 2019

I’m currently in the middle of preparing a presentation on CUDA for C and C++ programmers. Given that not everyone has access to an NVIDIA GPU, I was planning to include some instructions for getting started with CUDA on AWS. But instead of cramming it into an already over-crowded slide deck, I’ve decided to post the instructions here, with some additional information about EC2 instances with GPU support. Assuming that you’ve already set up an AWS account and know how to start an EC2 instance, these instructions will get you an EC2 instance that can compile and run examples from the CUDA Toolkit.


Parsing mathematical expressions

31 March 2019

Ever wondered how you can implement a simple calculator in C++? You probably haven’t, but it is interesting to look at how the problem can be solved very elegantly using code generation. This post looks at how we can use two code generation tools, Ragel and Lemon, to generate a parser for simple mathematical expressions like ‘(1.2 + 1) * 2.5’.


Reading list progress report

19 February 2019

Seeing as we are past the middle of February, I thought it would be a good idea to write a quick progress report on my reading goals for 2019. While progress has been slow, and on numerous occasions I have given in to temptation and found myself reading things other than the books on this list, I hope that writing this post will keep me on track!


A reading list for the year ahead...

10 January 2019

Like many book lovers, I am guilty of something that is common enough that there is even a Japanese word for it: Tsundoku. That is, the habit of acquiring reading materials but letting them pile up in one’s home without reading them. In an attempt to combat this (and to improve my reading habits) this post takes a different approach to the typical reading list blog post…


Tail Call Optimisation and C / C++

08 December 2018

At a recent Melbourne C++ meetup, the topic of tail call optimisation was raised. Tail call optimisation (or TCO) is a fascinating optimisation technique that is commonly discussed in the functional programming community, because of it’s importance in the implementation of efficient recursive algorithms. However, it is often overlooked when discussing other programming languages. This post gives brief overview of TCO, and looks at its use in C and C++ compilers.


Extending Ruby with C++

16 September 2018

In my previous post, I covered the basics of writing a Ruby gem with native extensions. We saw how C can be used to enhance the functionality of the Ruby language. This post takes the idea a step further, and looks at how to extend Ruby with C++.


Writing a Gem with native extensions

29 August 2018

There are many reasons you might want to write a Gem using native extensions. Performance is perhaps the most obvious. CPU heavy tasks, such as number crunching, can be re-written in C, to be many times faster than the equivalent Ruby code. For the daring among us, you can use multiple threads, GPUs, etc.


Build your own workstation

17 April 2018

A recent endeavour of mine has been to build a Linux workstation, for my work in the Data Science and Machine Learning space. The primary technical requirement for this machine is full support for two GTX 1080 Ti graphics cards.


Porting an Asteroids clone to JavaScript

08 January 2018

This post shares my experience porting an SDL-based Asteroids clone to the web, using Emscripten, an LLVM-to-JavaScript compiler.


Sparsehash Internals

11 October 2017

One of the C++ topics that have I wanted to write about is Google’s Sparsehash library. Sparsehash provides several hash-map and hash-set implementations, in particular sparse_hash_map and sparse_hash_set, which have been optimised to have a very low memory footprint. This post dives into the details of how this is achieved.


Fixing the authorship of a Git commit

11 December 2015

When working on code across multiple organisations, one problem that I have run into more often than I would like, is correcting the authorship of Git commits. You know the scenario - you create a new Git repository, but forget to set the appropriate user name and email address before a flurry of commits. This post covers one strategy that I have found useful for fixing incorrect Git commits.


WordPress and Docker

01 December 2015

With so much of my recent work involving WordPress, it made sense to re-evaluate my workflow and figure out how it might be improved. This post shares some of the things I have found useful in setting up a Docker-based environment for WordPress.


Implementing a Distributed Hash Table with Scala and Akka

26 November 2015

After diving into Scala and Akka earlier this year, I had been looking for an opportunity to apply what I had learnt to a non-trivial problem. The Chord Protocol seemed like a good place to start, and the project ultimately resulted in a talk at the Melbourne Scala User Group. Slides for my presentation, Implementing a Distributed Hash Table with Scala and Akka, are now available on Slideshare.


Installing R and RStudio on Mac OS X

20 October 2015

Although installing R and RStudio on Mac OS X wasn’t particularly difficult, I thought I would make some notes here, in case they’re useful to someone else. These instructions make use of Homebrew, a convenient command line package manager for Mac OS X.