Hardscrabble 🍫

By Max Jacobson

reverse polish notation

17 Mar 2015

Earlier tonight Carlos tweeted this:

Nowhere in there does he specifically ask me to provide my take on that problem, but I did anyway. I don’t know why.

The problem is, I think, to write a reverse polish notation calculator in Ruby. Carlos used TDD to drive his solution. I looked at it and thought it was cool, and then I wanted to do the same thing, and I made a video, because I am a ham.

Here it is:

It is very long. There are a few moments where I removed sound to take away coughs. I might have missed some. I probably did!

You’ll hear every thought that passes through my mind as I arrive at a solution, which I pushed here: https://github.com/maxjacobson/calculator. A lot of it is me struggling to understand the very premise of the notation, which confused me perhaps too much?

Using tests helped me get this working because when it wasn’t working, I wasn’t sure which part wasn’t working, and I was able to add more tests to describe the parts, until I knew which parts were behaving how I expected and which weren’t. That’s really helpful. Accomplishing that meant extracting some of the responsibilities into a separate, small, testable class, which I think is a good example of lettings tests drive the design of your code. Ultimately the implementation of that class is kind of awkward and not great, but it’s also really contained and could be easily rewritten because there are tests to catch mistakes in the refactoring.


git fib, a helpful little script for git commit squashers

08 Mar 2015

Sometimes I squash git commits. Generally I do this when I’m making a pull request which takes some time, and it accumulates a lot of commits, many of which were just kind of trying things out. The sum of all the commits adds up to one valuable addition, but each one is kind of garbage. Here’s a good post from Thoughtbot: Git Interactive Rebase, Squash, Amend and Other Ways of Rewriting History.

Here’s what it generally looks like when I do it:

squashing a commit

And this works pretty well for me.


Sometimes I do a really big squash, where 35 commits become one, which brings me to one behavioral detail of squashes that I’ve always found counter-intuitive: squashes always go up. When you’re in that interactive list of commits, and you’re telling each commit what to do, it’s relative to the previous chronological commit. When you tell a commit to squash, you’re telling it to squash itself into the previous commit. When you tell this to the 34 newest commits, you’re making your very first commit absorb all of the changes. That’s probably fine, but imagine if those commits took place over the course of 3 days, or 3 weeks. Each commit has a timestamp of when the work was done, and your big, squashed commit has a timestamp of… 3 weeks ago.

That sort of feels wrong to me. When the pull request is merged, the commit will sink down in the commit log below all the work that came before it.

Sooo sometimes I find myself taking things into my own hands to fix that. How? Well, it’s kind of weird. Changing the last commit’s message is pretty easy: git commit --amend; changing the last commit’s author is pretty easy too: git commit --amend --author="Kimmy Schmidt <kimmy.schmidt@example.com>". But changing the last commit’s timestamp is kind of tricky. As far as I know, it’s not built in to git itself, so it takes a few commands to achieve. Here’s what I’ve been doing:

  • squash all the commits
  • use my mouse to copy and paste the last commit message to the clipboard
  • uncommit the last commit (git reset HEAD~1)
  • re-stage all the changes (git add -A)
  • make a fresh commit, pasting in the old commit message (and probably having to fix some formatting issues because pasting into vim never works)
  • sometimes I’ll amend the last commit’s author to give someone else credit if they did the lion’s share of the work, because this strategy automatically uses my git name and email even if the commit we’re trying to time shift was created by someone else

Here’s what I do now:

  • git fib

Here’s a gif (ignore the part when I got stuck in a dquote confusion please):

git fibbing a commit

Get it here: https://github.com/maxjacobson/dotfiles/blob/master/bin/git-fib

I learned with git-sleep that scripts whose filename begins with git- can be referenced without the hyphen, making git a nicely extensible tool. I still think that’s so cool.

I’m pretty proud of this because it’s a kind of gnarly shell script and it works a lot better than I expected.

Some things I might do:

  • rename it to something that makes more sense
  • put it on homebrew so it’s easier to install
  • suppress more of the git output (not sure, maybe it’s nice to have it?)


EDIT 2019: At some point in the intervening few years, I noticed someone run git commit --amend --date, and I made a note in my to do list to update this script and this post, and today I did.

playing with emacs for the first time

01 Mar 2015

Today I’m playing with emacs. There has been a confluence of events which have led me to this moment:

  1. First, the other night I bumped into Harry Schwartz at a programming meetup, and he gave me a sticker from his meetup group, New York Emacs. I put it in my wallet.
  2. Second, yesterday I bumped into Andrew Leung, and somehow we got to talking about Emacs. He’s been using it for many, many years. I gave him the sticker from my wallet because I thought he would have more use for it than I would.
  3. Today I’m kind of bored.

To my non-surprise, the version of Emacs which came installed on my Mac is a few major versions behind. To my surprise, the version of emacs on Homebrew is also a bit old. Neither version has syntax highlighting for Ruby, which was provided by default in the newest version. Installing the newer version wasn’t that bad. I downloaded the code from their ftp server (emacs-24.4.tar.gz), unarchived it, and followed the instructions in the INSTALL file. Then, sweet, ruby files were colorful. That makes a huge difference for me.

I really don’t know what I’m doing, but I feel like I should learn more about emacs if I’m going to recommend people learn Vim, which I generally use and recommend, so today I took a little while to play with it and I’ve learned enough to do the super basic things. Here’s everything I know how to do:

  • emacs . from the command line to open emacs in a file browser
  • arrow keys and return to browse and open files
  • C-x C-s to save
  • C-x C-f <enter> to return to the file browser from a file
  • C-a to go to the beginning of a line
  • C-e to go to the end of a line
  • C-n to go to the next line
  • C-p to go to the previous line
  • C-_ to undo a change
  • C-s to search within a file
  • C-x C-c to quit (it prompts you to save any unsaved changes at this point)


something like C-x can be read as “press the control key, and then press the x key while still holding down the control key”

something like C-x C-f can be read as “press the control key, and then press the x key while still holding down the control key; then keep holding down the control key, and press the f key, and then feel free to go get a coffee, you’re done”)

And that’s it. Things I’d like to learn:

  • More commands to navigate the text within a file (deleting lines, copying, cutting, pasting)
  • How to do some simple configuration (I want line numbers)
  • How to more efficiently open files (I want a fuzzy file opener like ctrlp.vim)

That’s really all that’s blocking me from actually using it to do work. I’m using it to write this post, and I’m totally surviving.

If I were to go down the rabbit hole, I’d probably want to learn the whole Emacs Lisp thing. Richard Stallman, the creator of Emacs, says this:

The most powerful programming language is Lisp. If you don’t know Lisp (or its variant, Scheme), you don’t know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will understand what is lacking in most other languages.

It’s hard to read that and not get some programming FOMO.

I attended this talk from Harry called “An Introduction to Emacs Lisp”, which I may need to rewatch.