Hardscrabble 🍫

By Max Jacobson

inhumanity

22 Mar 2015

Yesterday morning I grabbed my pants off the floor and a mouse scurried away. I shouted, “ahh!”, ran to my bedroom, and jumped on my bed, pants still in hand.

I had my Improv 201 graduation class performance and I was running late, so I didn’t have time to worry about it. I just got dressed and left with my eyes closed.

On my way to the show, I tried to remember the things we’d been taught over the last 8 weeks, but my mind kept going back to the mouse. It was small and brown; not a startling creature. And yet, very startling!

The show went well, I think. It was fun for me anyway. Afterward we had some food and drinks and then I went home and fell asleep and slept for 15 hours. I wake up around 10am without thinking about the mouse. I’m trying to keep my mind clear, because I’m having a surgery tomorrow, and I want to feel mentally and emotionally prepared so I can be the best patient I can be. And then I start seeing the mouse out of the corner of my eye.

At first it’s to my right, flitting from behind my radiator to behind my couch. I tense up. I pause The Mindy Project. I think it could tell I was occupied.

I resume The Mindy Project. I need to take the last of my antibiotics so I step into the kitchen to take a swig of rice milk. There I see the brown mouse again, by the oven, which is precisely on the other side of the wall from the radiator. I say out loud, “I don’t like this”.

The next time I see the mouse, I’m back at my desktop, and it’s walking back into my living room via the hallway. I say, “hey!” and it turns around and walks back around the corner. I look away and see that he’s walking toward me again. I say “hey, buddy!” and he goes back. So I look away again, and now he’s straight up sprinting past me toward the couch again.

I grab my wallet, keys, and a hoodie, and I leave my apartment and call my mother. She advises me to trap the thing with a glue trap and feel nothing. She says I’ll feel satisfied, like a hunter.

From a nearby cafe I order some humane mouse traps on Amazon.

My grandma calls me and says she’s had good experiences with spring-loaded mouse traps, and that I’ll feel satisfied.

I check a nearby general store. They have glue traps for mice and spring traps for rats. With my grandma still on the phone, I buy the glue trap.

  • 13:15 – I set the traps, one in my hallway and one near the couch, and go sit in bed and watch another sitcom, Undateable, on Hulu. In my field of vision, I can see the first trap.
  • 14:00 – I notice I can see something in the trap and go check on it. It’s just the dab of peanut butter I’d put there earlier.
  • 15:11 – I see the mouse walk right past the trap and into my living room
  • 15:16 – I hear what sounds like panicked squeaking

My mom suggested the mouse would die as soon as it got stuck, of a panic attack, but it just kept squeaking for several minutes while I listened in horror. I feel no satisfaction until later, when I’m sitting in my living room again and nothing scampers through my periphery.

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.

:leaves:

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.

Usually.

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?)

:leaves:


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.