Hardscrabble šŸ«

By Max Jacobson

See also: the archives and an RSS feed

inhumanity

March 22, 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

March 17, 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

March 8, 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?)

šŸƒ


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

March 1, 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)

(Note:

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.

another cookie crumb

February 21, 2015

In Wednesdayā€™s post about building Firefox from source the other day, I mentioned one thing I really liked about the experience of first looking at this code base: it kept dropping little hints about what I might need to do next in a way that was actually insightful and helpful. For example, after running their script which installs dependencies, there was some helpful output pointing me to where I could get the code base.

Today I checked in with the project and pulled the change from the last few days. There has been a flurry of activity, none of which means much of anything to me as an outside observer.

I was curious if I would be able to run ./mach build, and if it would take as long on the second run. Instead I got this interesting output:

0:00.35 /usr/bin/make -f client.mk -s
0:01.33
0:01.33 The CLOBBER file has been updated, indicating that an incremental
0:01.33 build since your last build will probably not work. A full/clobber
0:01.33 build is required.
0:01.33
0:01.33 The reason for the clobber is:
0:01.33
0:01.33  Bug 1119335 - (DOMString or sequence<DOMString> or ConstrainDOMStringParameters)
0:01.33  needs binding flush (Bug 1103153).
0:01.33
0:01.33 Clobbering can be performed automatically. However, we didn't
0:01.33 automatically clobber this time because:
0:01.33
0:01.33   Automatic clobbering is not enabled
0:01.33   (add "mk_add_options AUTOCLOBBER=1" to your mozconfig).
0:01.33
0:01.33 The easiest and fastest way to clobber is to run:
0:01.33
0:01.33  $ mach clobber
0:01.33
0:01.33 If you know this clobber doesn't apply to you or you're feeling lucky
0:01.33 -- Well, are ya? -- you can ignore this clobber requirement by
0:01.33 running:
0:01.33
0:01.33  $ touch /Users/maxjacobson/src/gecko-dev/obj-x86_64-apple-darwin14.3.0/CLOBBER
0:01.33 make: *** [/Users/maxjacobson/src/gecko-dev/obj-x86_64-apple-darwin14.3.0/CLOBBER] Error 1
0:01.36 78 compiler warnings present.

Thatā€™s super interesting! Things I learned from this:

  • Thereā€™s something called ā€œThe CLOBBER fileā€ which is some kind of place to leave little messages about why someone else will need to do a full build after pulling in a change
  • Sometimes itā€™s possible for mach to do an ā€œincremental buildā€, which I assume wouldnā€™t take very long
  • Thereā€™s a tool for clobbering, which I guess clears away stuff from earlier builds, requiring mach build to do a full, non-incremental build
  • Mozilla people make nerdy movie references

I took a look at The CLOBBER file by using my fuzzy file opener to look for a file called CLOBBER and found it, in the root-level of the project. It contains more details about how to use it:

# To trigger a clobber replace ALL of the textual description below,
# giving a bug number and a one line description of why a clobber is
# required. Modifying this file will make configure check that a
# clobber has been performed before the build can continue.
#
# MERGE NOTE: When merging two branches that require a CLOBBER, you should
#             merge both CLOBBER descriptions, to ensure that users on
#             both branches correctly see the clobber warning.
#
#                  O   <-- Users coming from both parents need to Clobber
#               /     \
#          O               O
#          |               |
#          O <-- Clobber   O  <-- Clobber
#
# Note: The description below will be part of the error message shown to users.
#
# Modifying this file will now automatically clobber the buildbot machines \o/
#

# Are you updating CLOBBER because you think it's needed for your WebIDL
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.

Bug 1119335 - (DOMString or sequence<DOMString> or ConstrainDOMStringParameters)
needs binding flush (Bug 1103153).

Itā€™s probably gratuitous to just copy this whole thing in here, especially when the last few lines are designed to change, but itā€™s pretty interesting, and I have a weird superstition about linking to files on GitHub, for example, because what if that file gets moved and my link goes dead?

This file is like a cache. As long as it stays the same, you can keep building. As soon as it changes, you need to clobber before you can build. It seems like a clever solution to me (I especially like the detail about combining clobber notes so when two people insist on a clobber, they each get the benefit of the otherā€™s). You just need to remember when to expire the cache, which leaves a little cookie crumb for the next developer to work on the project.

building firefox for the first time

February 18, 2015

recently I came across two blog posts:

They kind of tell similar stories. Both Firefox and Chromium1 are open source and welcome contributions from the general public, but both of them are probably developed primarily by the companies behind them. These posts are sort of encouraging people to consider contributing back to the app they spend most of their computer time in and hoping to make it sound more doable and less terrifying.

I came away from the Chromium post with a lot of clear and friendly knowledge about how I might make a contribution but actually more convinced that Iā€™m not qualified to do so, because I donā€™t know any of the languages she mentioned in the post and donā€™t currently plan to learn them. If I did, Iā€™d know exactly where to start and how to proceed.

The firefox blog post was an offer to help mentor a select few through getting up and running and making a first few contributions. I thought about it for a few minutes while I read the blog post and filed it away in the back of my mind, but I was too slow, and the offer has now closed. I thought maybe I could do it because having a mentor helps a lot and, from the sounds of it, the front-end of Firefox is built using the tools of the web, which I already kind of know and work with. From the post:

We will use JavaScript, CSS, and XUL (similar to HTML).

Sure.

Also, Firefox is my day-to-day browser, so selfishly I like the idea of submitting something that would benefit me. I first got excited about the internet in Firefox. Iā€™ve occasionally switched to Chrome and Safari but I always come back to Firefox. I donā€™t know. And I kind of think itā€™s having a moment? Well just someone wrote one blog post about it recently:

I like dhhā€™s perspective there; sometimes I feel like a browser hipster and like Iā€™m the only web developer not using Chrome (I know Iā€™m not) but I do think heā€™s right that itā€™s important that any one company doesnā€™t have too strong a hold on how the internet works.

So tonight I took the first step and built Firefox locally. It was surprisingly easy but also surprisingly time-consuming. If you want to do the same I recommend following the Simple Firefox build instructions but Iā€™m going to share here anyway the steps I took.

  • Visited that guide
  • Followed that link to Linux and MacOS build preparation which recommended I paste the following into my terminal to install the prerequisite dependencies:
wget -q https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py && python bootstrap.py
  • That asked me if I was interested in building Firefox for Desktop or Android. I answered Desktop, and it started doing stuff, and outputting what it was doing, and ultimately (actually this was pretty fast) it said it worked and made this suggestion:
Your system should be ready to build Firefox for Desktop! If you have not already,
obtain a copy of the source code by running:

    hg clone https://hg.mozilla.org/mozilla-central

Or, if you prefer Git:

    git clone https://git.mozilla.org/integration/gecko-dev.git
  • So I ran the second command, because I prefer git (well, because I know git)
  • And then I waited for like ten minutes? More? I donā€™t know. I had never cloned a 7 gigabyte git repo before. It felt new and strange. The .git directory is nearly 6 gigabytes, suggesting the sheer history of the project weighs significantly more than the current state of it. The repository has 407088 commits going back 17 years, 8 years before git existed.
  • After the project finished cloning, I ran cd gecko-dev and no magical incantation appeared giving me the next bread crumb to follow, so I returned to the guide.
  • It suggested using Firefoxā€™s ./mach script to build and run the app. This felt kind of familiar, kind of like Rubyā€™s rake. I tried running just ./mach without any arguments and saw that it has a shitload of commands including google, so I ran ./mach google jake and amir (because I was just watching Jake and Amir episodes before this flight of fancy overtook me) and it opened Firefox to https://www.google.com/search?q=jake%20and%20amir, which, alright, sure.
  • I ran ./mach build and watched it do a shitload of stuff to build Firefox from the source Iā€™d downloaded. I donā€™t have to estimate how long this took, because it output a running timestamp as it did everything. It took 37 minutes and 56.85 seconds. I guess thatā€™s not bad? I hope I donā€™t need to wait that long every time I make a change (if I even figure out how to make a change). And when it was finished, I saw this output:
37:56.85 We know it took a while, but your build finally finished successfully!
To take your build for a test drive, run: |mach run|
For more information on what to do now, see https://developer.mozilla.org/docs/Developer_Guide/So_You_Just_Built_Firefox
  • I ran ./mach run and like lightning a bluish moonish earth appears in my Macā€™s dock and Firefox Nightly opened.
  • I visited hardscrabble.net just kind of vainly to see what my site looks like in my freshly baked browser
  • I visited the URL from that last output (sidenote: I really love the trail of breadcrumbs this process has been) and found a kind of hilariously brief web page which mainly includes notes on how it should be succinct but also a tag indicating it needs more content?
  • I followed the first listed interesting link about how to run Firefoxā€™s tests, and before I could overthink whatā€™s about to happen I ran ./mach xpcshell-test and the most delightful thing happened, and I think it needs to be captured in a video:

Iā€™m sorry this blog post became a bullet point list halfway through. That wasnā€™t really fair.

Probably in the morning Iā€™ll forget I ever wanted to contribute to Firefox but hopefully not. Iā€™m on the record now.

  1. Chromium is basically Chrome, but open source.Ā 

discovering a problem

January 21, 2015

view source on a recent post

Thatā€™s the ā€œView Sourceā€ on a recent post here on the blog.

Do you ever discover a problem weeks or months or years after it was introduced? How did you discover it?

The HTML markup on my website has been broken for a while, but I only just noticed today, and then I noticed twice, the way you learn a new word and then hear it again right away.

Iā€™ve looked at that view source several times while poking around on this site, and I can vaguely recall being concerned that some of those tags are highlighted in red, but never taking much notice of it, because the site works more or less fine.

Today while bored I took a look at a very neat iOS app called View Source, which provides an iOS 8 extension for viewing the source of any website right in Safari. When I tried to run it on my own blog (as you do), I saw this:

view source on a recent post in iOS

Thatā€¦ looks kind of wrong? Whyā€™s all the head stuff in the body? Huh?

So just a few minutes ago I opened up my text editor and opened the relevant file to make a fix, and I saw this:

HTML in vim with syntastic

Hell yeah! Where was that error message when I first introduced the problem?

Well, it was nowhere, because I only started using that plugin like last week, and I introduced the problem a full 615 days ago while sloppily porting my layout from haml to Jekyll.

Probably my moral is: be careful out there! And pay attention to your inklings.

Hereā€™s my second moral: even after making the fix, there are still some errors reported by the plugin because itā€™s confused by the Liquid tags, which arenā€™t valid HTML! Iā€™m going to push the fix and use the online validator instead. Sooooo tools arenā€™t a panacea.

Ambiguous use of user-defined command

January 18, 2015

I wish Vim plugin authors would stop exposing commands that start with E. Is that a reasonable thing to feel? I do feel it.

I use netrw to browse files in vim, and I enter netrw by writing :E. I do this all the time. :E is short for :Explore. I could type :Ex, :Exp, :Expl, :Explo, :Explor as well, but I type :E. This is what my fingers remember.

Sometimes I install a plugin, and that plugin exposes another command which starts with :E, and suddenly I get this vim error message:

Ambiguous use of user-defined command

What! Iā€™m the user, and I didnā€™t even define these commands! I just installed a plugin. This is bull! Recently I installed a plugin which, very sensibly, exposes a command called :Errors. Except, like, now I canā€™t type :E because thatā€™s ambiguous, I could just as easily mean either of those commands, so vim does neither. Now I need to type :Ex to disambiguate. I could cry.

So anyway, I was about to uninstall the plugin, but then I realized I can just edit my local copy of it and comment out the line that exposes the :Errors command, which I didnā€™t particularly want to use anyway, and now Iā€™m kind of happy. I would prefer if I could un-register the command in my .vimrc (is it possible? I couldnā€™t find how in my few minutes of searching), because this solution is kind of fragile; next time I install the plugin on some other computer, it wonā€™t include my fix.

Edit April 2015: Iā€™ve sort of solved this problem by no longer typing :E, and instead adding this line to my vimrc:

nmap <silent> <Leader>e :Explore<CR>

Which lets me type ,e to jump right to netrw (, is my Leader character. By default, the Leader character is \.)`

unpairing bluetooth devices is annoying

January 18, 2015

I donā€™t use that many bluetooth products. Bluetooth kind of confuses me, to be honest.

Five months ago I bought this:

a red speaker

Itā€™s the AmazonBasics Ultra-Portable Mini Bluetooth Speaker - Red. Itā€™s like one of those cool Jawbone speakers but cheaper and probably not as good.

I love it. I use it to listen to podcasts in the shower or while doing dishes. Itā€™s louder than my phoneā€™s speakers and lets me keep my phone away from water. Itā€™s perfect.

The other bluetooth product I use regularly is the Apple Magic Trackpad, which I also love (I love swiping around to do things). Sometimes, though, I find myself wanting to unpair the trackpad with one computer so I can pair it with a different one and this is so unnecessarily hard.

Before I can use the trackpad with the second computer, I need to open the Bluetooth preferences in system preferences, find the device, and tell the computer to forget about this device (so dramatic!) before it will show up as pairable to the other computer. Honestly this isnā€™t that hard, but it takes a few seconds, and I almost always forget to do it before Iā€™ve already put away or turned off the first computer.

Amazonā€™s cheap little speakers do it so much better. See that middle button? If you hold it down for a few seconds, it unpairs from whatever, and becomes available to whatever. Thatā€™s great! Because what if it was paired to something and you left that something at home? I could be wrong, but with most Bluetooth devices I think you just wouldnā€™t be able to use it.

Having this extra button feels to me like a correct design, with the responsibilities where they belong.

enterprising

January 17, 2015

Steven Soderbergh re-edited some famous movies. Jason Kottke linked to them and, among other things, mentioned this (emphasis mine):

Iā€™ve seen some comments on Twitter and elsewhere about the legality of Soderbergh posting the 2001 and Raiders edits. The videos are hosted on Vimeo, but are private and canā€™t be embedded on any site other than Soderberghā€™s. But any enterprising person can easily figure out how to download either video. The Raiders video has been up since September, which means either that Paramount doesnā€™t care (most likely in my mind) or their lawyers somehow havenā€™t caught wind of it, even though it was all over the internet a few months ago (less likely). Weā€™ll see if whoever owns the rights to 2001 (Time Warner?) feels similarly.

I read that and was kind of surprised because at first blush I had absolutely no clue at all how I might download the video. Sooooo I had to try: