Josh Thompson     about     archive     tags

Recommended Reading

I like to read, and I often recommend books to others.

The recommendations below are entirely non-fiction, but have provided great value to me in very specific ways.

I’ve got ~30 book recommendations grouped into following categories:

I mention some books “pair well” with other books, just as certain wines pair well with a certain foods. The ideas contained within certain books may compliment (or contrast) the ideas listed in the “pairs with” book.

>> Read more

Pry Tips and Tricks

the following is cross-posted from I wrote about some handy extra features I’ve found using Pry much of my day.

I joined the Wombat team a few months ago, and have been working on the threatsim product. We had a bit of a bug backlog, and myself and others have been rapidly whipping it into shape.

ThreatSim is a Ruby on Rails application; any developer out there who works with Rails has probably used Pry extensively in debugging their application. Pry “pauses” your application’s execution and lets you observe and manipulate state, wherever the pry happens to be.

Most pry usage is pretty simple - put a pry in your code, cause that line of code to be executed, and then poke around in the session in your terminal.

For me, this can feel unwieldy when I am trying to do a broad examination of the application. Pry is great at showing me the state of the variables contained within the method that the Pry was placed at, but I don’t always want to see just this code and its variables, I want to skip around the application and peek into different components.

Looking at methods

You can use show-method to reveal pretty much any code in your application. If you use show-method with no arguments, it will show all of the code in the method that you’ve placed the pry.

For example:

show-method (with no arguments, shows current class/method location, can be similar to whereami (look at prompt) (I usually append -l to show-method, to add line numbers

>> Read more

Keyboard Shortcut to Toggle Bookmarks Bar in Firefox

A few weeks ago, after Firefox Quantum came out, I decided to give it a go.

Turns out, Firefox is great! It was a near-seamless transition, and Firefox has a much lower memory footprint, as well as features Chrome does not have, like Tracking Protection and Reader View

But something was bothering me to no end. I could not find a keyboard shortcut to toggle the visibility of the bookmarks toolbar.

I take a lot of screenshots throughout the day, and share them within my company. I don’t really want my bookmarks bar taking up space in the screenshot, but I do sometimes need it to find actual bookmarks.

In Chrome, Cmd-Shift-B toggles the bookmarks bar visibility. In Firefox, that combo shows your history.

>> Read more

Testing Rake Tasks in Rails

I recently wrote a rake task to update some values we’ve got stored in the database. The rake task itself isn’t important in this post, but testing it is.

We’ve got many untested rake tasks in the database, so when our senior dev suggested adding a test, I had to build ours from scratch.

I did a bit more whack-a-moling with error messages than I’d hoped, so here’s a template of that test, along with some details that might save you some time, next time you are writing tests for your rake tasks.

We’re in a not-new version of Rails, and using Minitest. I’ve anonymized it. Hope it’s useful!

# test/tasks/rake_task_file_test.rb

require 'test_helper'
require 'rake'

class RakeTaskFileTaskTest < ActiveSupport::TestCase

  describe 'namespace:task_name' do

    def setup
      @tt = Fabricate(:object_with_attributes_i_need_to_change)

    it "should change 'thing I don't want'" do
      values = @tt.attribute_i_changed
      refute_includes values, "thing I don't want"
      assert_includes values, "thing I do want"

>> Read more

Array divergence in Ruby

Lets say you have a list of valid items, and you want to run another array against it, and pull out the items that don’t match.

You don’t want to iterate through all of the items in one array, calling other_array.include?(item). (That’s computationally expensive)

valid_people = ["Sarah Connor", "John Connor"]

visitor_logs = ["Sarah Connor", "John Connor", "Terminator Robot"]

You want to find any item in visitor_logs that isn’t on the approved list. How to do that?

in Ruby, you can just “subtract” one array from another:

unwanted_visitors = visitor_logs - valid_people
=> ["Terminator Robot"]
>> Read more