The Dark Roast

By Sean Lunsford

Arabica 1.1 and GitHub

So I haven't done a whole lot of programming lately. I've been doing other stuff at work recently, and I hadn't given any free time to it in a good while. But I've been wanting to dip my toes back in those waters again.

Last summer, I read up on git and GitHub, and set up a repository for Arabica, the theme for this site. There were some updates I'd been wanting to make, and it seemed like an easy project to get my feet wet on. But then it sat, untouched on GitHub, for nine months. (So says my commit history.)

So this week, I sat down and spent a few hours staging commits, merging branches, figuring out how best to use repositories and branches on my test server and production server to edit code and then push it live. A really nice thing about using git is that I can keep a branch with my bespoke version for The Dark Roast, which is separate from the master branch intended for the public, and merge changes to the master into it.

Anyways, so I've now released version 1.1, with some of the features I've been wanting to add for a while. The big one is popover footnotes.[1] I've also added support for post images and for tag pages that include the tag name, description, and image.[2]

It feels good to code some again. I have some more updates on the agenda for Arabica, but I have greater aspirations for getting back into iOS development, this time making use of GitHub and all that version control has to offer.


  1. I've been seeing these increasingly on the sites I follow, and I really wanted to ship them on my own. It seems a lot of them use the same jQuery framework, which was easy enough to include in Arabica. Isn't this so much better than the old way? ↩︎

  2. Ghost themes automatically support tag pages, but use the index template if no tag template exists, meaning they show a list of tagged posts, but otherwise look no different. ↩︎

Breadcrumbs

I'm back after a couple years of not writing to announce I started a podcast. My friend EJ and I have known each other since before high school, after which we both studied engineering—he in Germany, I here in the States—and we discovered last year that we have both become avid podcast listeners in the last couple years. A number of months ago we started kicking around the idea of recording a show together. From that discussion, and many hours of recording and editing,[1] was born our first episode, which just went up today.

It'll take some number of days for the first episode to appear on iTunes, but it's embedded below and over at libsyn. And you can subscribe via RSS in your podcast app of choice.

We describe the show as our "weekly chat about things past, present, and future," and we're both excited and interested to see where this experiment goes. In this first episode—in a somewhat appropriate, if unintentional, nod to our name[2]—we talked about food and eating habits, starting all the way back in our childhoods.

So, without any further ado:

Update: Breadcrumbs has made it through review and is now available on iTunes.


  1. Including several recording sessions' worth of content that will probably never see the light of day ↩︎

  2. I didn't even think about this until today while posting it. ↩︎

Tic Tac Toe

So I've been working on my first legit app. It started as an exercise in the online iOS/Swift course I've been working through. The exercise was to create a basic tic tac toe game for two players. That was easy enough, but afterwards I thought I'd see if I could get the program to play one side—to see if I could get it to think like a human, at least well enough to play and win (or tie) against a human.

It's actually been a really good exercise. Tic tac toe is a simple enough game with a fairly straightforward strategy that can be distilled down to an algorithm. I played through my app against myself a bunch, trying to take every approach and play out every scenario I could think of, looking for patterns. I also looked at strategy section of the tic tac toe Wikipedia page and compared notes with what I'd come up with. It was actually pretty close to what I'd determined myself, but it was helpful to have it spelled out, and there were things I hadn't thought of. My own experience had more nuance in certain areas, as well.

Actually coding the strategy has been really interesting, too. This is well beyond the stuff in the tutorials so far. I've created a bunch of functions that analyze the grid of nine cells to determine the best next move. I've created a GridCell class with several different properties and methods to help analyze and manipulate the cells. I've read up about classes like UIAlertController and UISegmentedControl to include interface elements that haven't come up in the course yet.

As I've gone, I've added more and more complexity to the algorithm. It's gone from just reacting to the board, blocking when necessary and winning when possible, to playing more aggressively, looking for opportunities to force the player's hand or create forks that guarantee a win—and even anticipating forks by the player and stopping them before they happen. I've introduced easy, medium, and hard modes. Hard mode may be a bit of a misnomer—unbeatable is more accurate. It's the strategy played out perfectly, so that it will tie another perfect player every time. (An interesting and unexpected result was that, by coding it to compete with an experienced player and testing it that way, I accidentally left gaps in the early stages of the hard mode. An inexperienced player would do something unexpected and could actually beat it. I've plugged those holes now, so it should be actually unbeatable now. I've also improved the algorithm so that it should be better at handling scenarios that I haven't anticipated.)

One of the app's more interesting features (at least in my opinion) started life as a debugging tool—at least the concept did. Testing and debugging the program has involved playing it over and over, trying every possible scenario against every AI mode. Sometimes I'd find a bug in one specific case, but once I tweaked the code, it would take playing through multiple times to try and get that specific scenario to play out again. I found myself wishing there was an easier way to set the game up at a specific midgame state and then trigger the algorithm. To start in two-player mode and then switch to one-player on demand. At first I thought it would be a switch that I would include in the prerelease version, but then I thought that this might be a better interaction for game settings than the series of action alerts that let you choose the mode and starting player. Now there is a segmented control to set the AI to easy, medium, hard, or off. As always, the AI will play in response to a move by the human, but now there is a button to trigger the AI player on demand. This can be used to tell it to start the game, but also to trigger it at any point during the game. These two controls together are great debugging tools, but I think they're a much more interesting approach to the game settings, as well.

This is the best part of learning to code—the course is a great starting point, but what I love is going above and beyond what I've been taught, and figuring things out for myself.

I also have to mention in passing that it's really great that stark, flat, minimalism is in, because that's exactly what my app is. A couple years ago you had to have fancy graphics to be taken seriously, but now a grid and a couple of controls on a white background fits right in.

So I've submitted my first app to Beta Review. It'll be cool to get this thing live on the App Store at some point. Not that I expect it to bring much in, if anything (the release version will probably be ad-supported), but it's a baby step towards someday having apps that might actually make money. And just having an app on the App Store will be cool.