Hardscrabble 🍫

By Max Jacobson

the cop and the hound

28 Sep 2014

As a rails developer I keep hearing about Thoughtbot’s cool projects. A fairly recent one is Hound, a tool that comments on your GitHub pull requests and points out code style violations. I think consistent style is a nice ideal to strive for, so I want something like this.

Setting up Hound is easy, but it only reviews the code that is added in a pull request, not the existing code base. Which, in theory, is fine. Except, if you’re the kind of obsessive compulsive who wants a style guide, it’s probably not.

So I managed to make Hound review the full code base but it took some tricky git branching and pull requesting. So I made a screeny1 to share:

Setting up Hound CI to comment on my full code base from Max Jacobson on Vimeo.

I didn’t want this video to be too long, so I stopped when I managed to get the full codebase analyzed. But here’s my plan to continue:

  1. I’ll need to learn how to configure Hound to more accurately reflect my tastes. Under the hood it uses rubocop, pre-configured with Thoughtbot’s style rules. I’ll add my own configuration and push again, which will hopefully refresh the comments.
  2. Then I’ll fix all the code style violations and keep pushing them up until all of the comments go away. Then I’ll merge the second pull request. At that point my first pull request will (hopefully) have a diff that shows exactly what I want: new configuration and style fixes.
  3. I’ll squash that branch to have just one commit and merge it.
  4. Then I’ll merge that pull request into master and be nicely set up for a future of consistent style.

1. configuring rubocop

These are the default “cops” for rubocop. If I were starting fresh with rubocop (and not using Hound), I would start with this configuration file and start disabling specific cops. In fact, this is exactly what Hound does. Their tweaks are available because Hound is open source.

Here’s what I came up with: https://github.com/maxjacobson/film_snob/blob/hound-it-up/.rubocop.yml (if that link is dead, it’s probably because I merged the PR and deleted the branch, in which case the file can be access here).

Maybe I’ll change it over time but it seems good right now.

2. fixing all the violations

Done: https://github.com/maxjacobson/film_snob/pull/46

Being consistent feels good :smile:.

It’s actually not that hard to use rubocop directly without Hound. I also added rubocop to my Travis CI configuration, so even if I didn’t have Hound, pull requests would consider style guide violations, because the build would fail. There’s no commenting, which decreases the visibility. But it’s OK because Hound double-comments if you push the same problem twice, so maybe the comments aren’t that great? It’s also much more strict. If you have an 81 character line, it’s a complete no go, the build fails, you can’t merge that.

I’ll try that.

  1. I call them screenies because the app I use to make screenies is called Screeny 

sleep timers

07 Sep 2014

Falling asleep is one of the weirdest things that everyone does every day. Many people struggle to do it all. They experiment and develop workflows that help cope with this necessary evil. Here’s mine.

If I’m very exhausted I simply lie down, close my eyes, and shortly thereafter I fall asleep. This isn’t very often due to my sedentary lifestyle, so I’m often lying in bed wondering what I’m supposed to be doing with my arms and/or mind. The recourse I usually take to is to play a podcast. Many would argue that listening to a podcast is counter-productive to the goal of falling asleep. I don’t completely disagree, but I like to do something to fill that time, even if doing nothing would mean less time falling asleep, podcasts make the longer time pass quicker, so it evens out.

One problem is that podcast clients often autoplay, such that when one episode ends, the next begins. If you combine this feature with the auto-download feature, this creates the risk that I will go into an infinite loop of listening to podcasts literally forever.

If I could somehow fall asleep while people were talking, I would wake up to hear them still talking, potentially about anything at all, which I imagine to be extremely disorienting.

To mitigate these risks, I’ll apply a sleep timer, which means that I’ll tell the podcast to stop playing after a specified number of minutes has passed. Here are the steps I take:

  1. I press play on a podcast
  2. I apply a sleep timer of 5-15 minutes depending on how sleepy I feel
  3. I listen to the podcast while relaxing my body and mind
  4. I sense the impending timer running out and a curious tension fills me
  5. The podcast fades out and stops and I immediately fall asleep

If I don’t fall asleep, I start over, maybe with a shorter timer. I never fall asleep before the sleep timer runs out. If I do that, I’ll miss part of the podcast, which I would hate.

It’s essential to my bedtime workflow that I have fine control over how many minutes the sleep timer will run, because I believe that I can predict how long it will take me to fall asleep based on my current level of sleepiness. It’s also important that the audio fades away because that signals my internal systems to prepare to do that last, most important step (falling asleep).

This is my main complaint about the otherwise terrific new podcast app Overcast which does offer a sleep timer, but one that can only be set in crude chunks of 5 minute increments, and which stops with no fade out at all. I won’t be switching back to Downcast, which set the standard for sleep timers for me, but I suspect my sleep will suffer.

How do you fall asleep?

vim will fix indentation mistakes

07 Sep 2014

Today I learned a neat vim trick (via the Aaron Paterson Play by Play interview):

vim auto indent gif

You can highlight some lines with visual mode and then press = and it will fix all of the indentation mistakes therein. If you’re in normal mode, you can press == to fix just the line you’re currently on.

Paterson cites this trick as an argument in favor of not indenting private methods an extra level, because vim doesn’t do that. For example:

# do this:
class Dog
  def bark
    barks.sample
  end

  private

  def barks
    ["woof", "yap", "ruff"]
  end
end

# NOT this:

class Cat
  def meow
    meows.sample
  end

  private

    def meows
      ["meow", "purr", "idk what else, cats are weird"]
    end
end

I generally do that extra indent but I might stop now :leaves:.