hardscrabble 🍫

By Max Jacobson

Psst. Check out my RubyConf 2017 talk, There are no rules in Ruby.

blog posts

film snob 0.4.0

06 Dec 2014

Today I’m happy to release film snob v0.4.0.

I first wrote about film snob in April, when I extracted it from my old web app Layabout.

None of the changes add new functionality, so maybe it was wrong to call this a minor release. They also don’t fix any bugs. They’re all to do with making small stylistic changes that make the code easier to read or more consistent. I haven’t been releasing those changes because I haven’t been sure what the point is – why release an update that doesn’t change anything?

If someone is using film snob, and it’s not behaving how they expect, they might check the source code to help them understand and debug their problem. With that scenario in mind, I definitely want to release these changes.

Also, today I merged an awesome pull request which renames a method and emits a deprecation warning for the old method name. Thanks to Wil Chandler for making that change.

Ever since Anton Davydov added support for embedding photos and videos from Instagram, it’s been kind of weird that one of the main public interfaces for film snob has been the watchable? method. Instagram photos aren’t really watchable, right? They’re look-at-able, I suppose, but not watchable. Soon we’ll be adding support for embedding Rdio playlists & songs too, and it’ll be even more semantically unsettling.

The experience now looks something like this:

15:22:33 tralfamadore-5 hardscrabble.net:master
⇥ irb
>> require 'film_snob'
=> true
>> FilmSnob.new('http://instagram.com/p/sw4RThIctq/').watchable?
WARNING: #watchable? is deprecated and will be removed in v1.0.0. Please use #embeddable? instead.
=> true
>> FilmSnob.new('http://instagram.com/p/sw4RThIctq/').embeddable?
=> true

Embeddable feels more right to me.

So even though there’s no new functionality, there is more clarity, and maybe clarity counts as a feature? :leaves:

git repl

30 Nov 2014

The other day I mentioned coming upon a neat set of git extensions called ‘git extras’ by TJ Holowaychuk. Since then I’ve become slightly obsessed with it. It’s so useful, including as a terrific learning tool. Take ‘git repl’ as an example.

First of all, what is it?

allow me to answer with a GIF:

vim auto indent gif

In short: if you’re gonna be doing a bunch of git operations in a row, why keep typing git over and over when you can go into a git repl and just let it assume that everything you’re doing is going to be a git command?

It plays well with vim, too – the commit message editor seamlessly pops into vim and then back into the git repl on quit.

So how does it work? I looked at it and assumed that it must be so much code and way beyond my understanding. But that’s totally wrong! It’s just 43 lines of bash and it’s fairly readable.

The really interesting part is read, which has a comment indicating that it’s powered by Readline, which is one of those words that I’ve seen fly around while existing in the world of software, but have never heard defined. Well, here’s the wikipedia page for it: GNU Readline. It was originally written by Brian Fox, who also created bash. Ruby’s various REPLs (eg rails console, irb, pry) are probably using it under the hood via Ruby’s standard Readline library, which makes writing a REPL super simple, while maintaining the behaviors you may be used to. For example, I compulsively press control+l to clear the screen; this works in a readline REPL but not in something like this:

loop do
  print "> "
  input = gets.chomp
  puts input
end

Filename tab completion works as well! Whoa!

Here’s my first readline program, inspired by the git repl code:

function extensions {
  read -e -r -p "find files with extension: " extension
  find . -name "*.$extension"
}

Try pasting that into your terminal then entering extensions to run it and to explore your projects. It should prompt you for a file extension (try entering rb in a Ruby project, for example) and then spit out the list of files with that extension in the current directory (and its subdirectories).

Not a particularly great program! I’m mostly just happy to see how simple and demonstrative the git extras code was.