Night Working Computer Setup

Although I wrote about how automatically turn the internet off at night, sometimes my schedule shifts later or I am trying to get some side project work done and want to burn the midnight oil. In this post I’ll cover what I consider the best tools for an evening computer work environment.1 So what can you do besides changing your text editor colors?

Chrome

I use Chrome for my browser since it has many extensions and doesn’t seem to eat up memory at this point. For the nighttime setup I’m using one extension to make the new tab page black, and another to make most other pages dark.2

Dark Reader

To make most pages inverted and dampened, I highly recommend the Dark Reader Chrome extension.3 It is excellent. Sites look as good or better than their brighter counterparts. Github diffs in particular look really good. Here’s a screenshot of it in action:

Github with Dark Reader
Dark Reader Settings

Dark Reader has several hue and brightness settings that you can change (see right image), and you can toggle it globally or for a particular website. Generally I just turn it on globally with alt+shift+d at night and turn it off in the morning with the same shortcut.

It also handles images well. Unlike other plugins, it does not invert the colors, it just mutes them. Not inverting avoids blinding you with what are normally dark images.

I like using Dark Reader and it always makes me nostalgic for a dark theme that I set up on a personal wiki back in the day. I encourage you to install it and try it out on this page. I think it looks pretty cool!

Blank tab plugin

Dark Blank New Tab Page Extension

Generally when you open a new tab, Chrome presents you with your bookmarks or sites you have visited. I prefer to have a more minimal new tab page to avoid distracting me and to load more quickly. Generally I opt for Empty New Tab Page to simplify the new tab page down to just a blank page. However this plugin produces a blinding white background so it is less desirable for evening working. Fortunately, there is a similar and well-named plugin called Empty New Tab Page - Black which solves this problem by making the new tab black. So I generally have both installed and can disable whichever one I am not using at the moment.

Dark console

You can also change the default Chrome DevTools window from the default light background to a dark background. This makes web app debugging at night a bit more palatable.

Chrome DevTools Dark Theme

To change yours:

  • open the DevTools window
  • click on the dots in the upper right corner of the window
  • select “Settings”
  • choose the dark theme from the list of themes

PDF - MuPDF

I was reading Programming Elixir and Programming Phoenix for a side project that I am working on. The key features that I wanted in a night-time Preview (native OS X PDF viewer) replacement were:

  • Vim-like navigation (j/k to move up/down, etc.)
  • inverted viewing mode

I looked for a bit and found MuPDF. It is open source and available on Homebrew (mupdf package.) It gives Vim-like navigation and its inverted mode is quite good. Here is a side-by-side view of normal and inverted mode:

MuPDF normal mode MuPDF inverted mode

Actually running it is a bit tricky since it is normally a Linux program. The invocation that I found useful is:

mupdf-x11 <filename> &

This opens the file in the X11 version of the program and gives you back shell control (& launches it as a daemon). So not entirely easy to get running, but I have found it useful.

Monitor setup

There are a few considerations to make with your displays.

Generally turning down the brightness is useful. The built-in laptop display has keyboard shortcuts so is easy to change. Most external monitors are a little trickier, but some have modes that you can configure so you can more easily toggle between day and night modes.

If your external monitor flashes you with a full screen of blue pixels whenever it is unplugged like mine does, then I would advise turning it off before unplugging to avoid this. Blue light is most harmful to melatonin production, which aids sleep and is a powerful antioxidant.

f.lux

Since we are on the topic of blue light, I will mention f.lux. This program shifts the color palette of the monitors to a more red tint automatically based on the time of the day. I am guessing that most people reading this have heard of f.lux, so I won’t cover this much further.

Any other tools?

Do you have a night-time setup for your computer? What tools have you found useful? Thanks!


  1. I use a Macbook Pro, but similar strategies would apply to other computers. 

  2. There is still a flash of white when opening a new tab, when conducting the first URL change (generally a search), or when navigating to a tab that was previously loaded before it applies the dark styles. But overall, they are a great improvement. 

  3. Some pages that are actually Chrome-specific windows won’t be inverted. For example, the Chrome settings tab or any Chrome store pages. This made testing dark plugins a bit trickier because at first I tried testing on the dark plugin’s page instead of a normal browser page. 

Writing Composable Shell Functions for Better Workflows

Recently I finished up some shell functions that help me with some common git and testing workflows. They are up on Github, but I wanted to call them out since they might be helpful to others and just making something open source does not mean that it is discoverable. I think the philosophies are pretty solid even if you use different tools. You could use similar functions if you are using Bash or ZSH.

Overview

The general problem that I am trying to solve is that different tools like RSpec, git, or RuboCop produce output in a certain format, and I often want to do things with that output. For example, I might want to re-run the RSpec tests that just failed so I can verify fixes more easily.1 However, RSpec outputs in a certain format that is not easily consumable. For example:

...
Failed examples:

rspec ./code/fail_spec.rb:2 # something failed
rspec ./code/fail_spec.rb:8 # yet another failure
...

If I want to re-run these two tests, I could copy the two lines and paste into my terminal. This would have a couple of downsides though. One is that I would need to spin up one RSpec process for each test that failed. This is time-prohibitive if the project loads the Rails environment. It also prevents me from getting a reliable list of the tests that failed so I can repeat this process. Last, I’d like to ideally use a faster test runner like Zeus or Spring. So my real goal is to re-run the failing tests as quickly as possible.

One approach that I took for a few years was to copy the output, paste it into an editor (Vim), and then do some macros or other commands to munge it into the format that I want. However, this is time-consuming and potentially error-prone. It is also usually wasteful since I need to do it each time that I want to transform the output to a particular format, and often I don’t have the editor macros saved. It can be nice to have the list of tests to retry in an external editor to be able to check them off, but I prefer to not need the intermediate step.

Solution

The specific solution I made to solve this problem was to create a shell function that I called respec:

# copy the rspec failures, and this will rerun them as one command
function respec() {
  pbpaste | \
    cut -d ' ' -f 2 | \
    sort | \
    xargs rspec
}

First, I manually copy the tests that I want to run again. Using iTerm2, it is as simple as selecting the failure summary text since selections are automatically copied to the clipboard. pbpaste then echos the contents of the system clipboard. From there, we want a list of the tests that failed so we can run them again. The format of failing tests are:

rspec ./code/fail_spec.rb:2 # something failed
...

To be able to run any test that failed, we want:

./code/fail_spec.rb:2

One approach to solving this problem is to split the line by spaces and take the second item. We could do this with the cut command (saying the delimiter is space and we want the second field) or with awk (awk '{print $2}').2 From there, we just sort the files since they might have not been sorted depending on our test strategy, and we pipe the resultant tests to rspec using xargs.

Expanding on this

Something else we might want to do with the RSpec output is to edit the files that have failing tests. It could be that the tests need to be updated, or that it gives us faster access to the application files if we are using something like vim-projectionist. We don’t want to get all of the test failures, just the files that failed. So we could create a similar function that would edit the files that have failing tests:

# after copying the rspec failures, this will edit the files that had failures
function espec() {
  pbpaste | \
    cut -d ' ' -f 2 | \
    cut -d ':' -f 1 | \
    sort | \
    uniq | \
    xargs $EDITOR

Extracting common functions

There is some duplication in the current code. We’re always pulling the test failures from the clipboard, then getting the actual file and line numbers, and then sorting the tests. To DRY up the functions, we can create an intermediate function to take care of getting the test failures:

# returns the list of filenames from rspec output format
function rspec_paste() {
  pbpaste | cut -d ' ' -f 2 | sort
}

Then we can call this function inside of our existing functions:

function respec() {
  rspec_paste | xargs rspec
}
function espec() {
  rspec_paste | cut -d ':' -f 1 | uniq | xargs $EDITOR
}

Much simpler and easier to read.

Running commands on modified files

Another common workflow that I have is to run any tests that have changed in source control. Back in the day I would have done a git status, copied the test files that I want to retest, and added them after an rspec command on the command-line. Again, this is suboptimal.

Since I’ve shown function extraction above, let’s skip to the chase:

# return all files that are changed but not deleted in git
# needs to handle
# R  spec/1_spec.rb -> features/2_spec.rb
function modified_files() {
  git status --porcelain | \
    grep -v -e '^[ ]*D' | \
    awk 'match($1, ""){print $2}' | \
    sort | \
    uniq
}

This function will print out any files that were modified but not deleted. This is relevant because if we deleted a test file, we don’t want to try to run it since RSpec will immediately fail if test files are not recognized. For more information on the output format of git-porcelain, check out the git docs.

On its own, modified_files is useless. But now we can make functions that work with it. From there, we can run RSpec on any spec files that were changed:

function gspec() {
  modified_files | \
    grep -e "_spec\.rb$" | \
    xargs best_rspec
}

So basically we want to take any modified files, remove any that aren’t spec files, and then we run them through the best_rspec script. What’s that, you ask?

best_rspec

This is a small script that I put on my path to figure out what the fastest RSpec binary is and to use that to run tests. I’ve also aliased it to r, for faster typing of the command and to avoid needing to think about what environment I am running the tests in.

#!/bin/sh

if [ -f bin/rspec ]; then
  # use spring rspec if it is around
  ./bin/rspec $@
elif [ -S .zeus.sock ]; then
  echo "Running tests with Zeus"
  zeus test $@
else
  echo 'Running with naked `rspec`'
  rspec $@
fi

If we have Spring configured for the project, use that since it will be no slower than using the normal RSpec binary. If we have a Zeus socket open, then use that. Otherwise, just use the default rspec command.

I updated respec and gspec and any other commands that run RSpec tests use this to give the same behavior for free. Considering which binary to use is something I previously would have spent a brain cycle or two on that now just happens automatically regardless of what project I am working on. I consider it a win.

Putting it all together

Let’s discuss a common flow that uses these different operations. First, I check out a new branch and want to add a feature. I write some tests and watch them fail, then make them pass. I can make sure that all of the test files that I’ve added or modified pass before committing them with gspec.3 When I think I’m done with my feature, I run the test suite and there are some test failures. After copying the test failure lines which are at the bottom of the RSpec output, I can run respec to quickly confirm that they aren’t intermittent tests. Then I can run espec to open the files up and fix the issues. I run respec each time I think I’ve fixed some of the tests, and the failure output will hopefully reduce each time so I am running fewer tests the next time. Finally, I run gspec again to make sure that the tests are indeed passing. Each time, we are using the Spring test runner to avoid needing to spend seconds reloading the Rails environment.

Food for thought

Consider what workflows you have after seeing a program’s output and how you might create small, composable, functions or programs to help automate them. In addition to RSpec or other testing tools, you might consider the output of code linters or static analyzers, code deployment tools, and so forth.

My configuration is up on Github, check it out for some additional helpers that I use to re-run cucumber tests and to work with RuboCop output for re-running that tool.


  1. I realize that there are some plugins that will re-run the last failed tests, but I wanted a more general solution to this problem. 

  2. If there are spaces in your filenames, I’m not sure that either approach will work well. Also, you should probably reconsider your naming conventions! :) 

  3. I’d like to extend the gspec command to also run tests for application files that changed. For example, if git believes app/controllers/foo_controller.rb has been modified, I’d like to run spec/controllers/foo_controller_spec.rb even if it wasn’t changed. This should be fairly straightforward to do since Rails has a consistent directory format. This change would likely result in less manual effort on my part, since I often want to run the tests for any application files that changed. 

I Gave a Presentation About Redux to Indy.js

After completing a project at work that used the Redux state container, I gave a presentation to the local JavaScript meetup group about my understanding of Redux and showing how it works in the app that we built.

Link to the slides.

Link to a video of the presentation.

Overall, I’d say that Redux was a useful tool and we’d like to use it on new projects going forward. I think there are some good patterns there that we didn’t fully realize the benefit of because the app is so simple (basically a form wizard signup application.) Obviously I said more in the presentation, so if you are interested in hearing more of my thoughts the subject, check out the video of the presentation above.

Turning Down the Volume on Social Media

I am generally a fan of creating small challenges for myself. Sometimes they are to grow in a specific area, sometimes they are just to see if I can do something for a prolonged period of time. Some of the challenges I have done in the past few years:

The Social Media Challenge

Last year, I realized that I was spending more time than I wanted to on Twitter, Facebook, and the like. These sites would often link to posts that I would also read, and ended up being a huge time sink.

Certainly there is value in finding new articles that I wouldn’t have normally read, but on the whole the time was not very well spent. How many of the random articles that I read had something of substance or that I could later recite even a single noteworthy fact from? I found myself trapped in a self-inflicted filter bubble / echo chamber.

The Origins

Miles tweeted this post:

I figured this was a good of a time as any, and emailed him with a slightly formalized challenge. It was partially based on the fitness challenge experience and some previous attempts to do something like this:

If you want, I’d be up for a $10 April Social Media ban contest.

Parameters: You get one ten minute block per week for essentials (facebook event checking for social events, twitter responses that are important.) Ten minutes is use it or lose it, ending Sunday at midnight local time. If you check Facebook, Twitter, Reddit, HN, Google News(?) for more than ten minutes total during the week, you lose the bet for the month.

If we both lose or neither lose, nothing exchanged. Square cash any difference. :)

Your call if you want to do this or not, just let me know. We can recruit others if you want.

Anthony “/etc/hosts willpower” Panozzo

(Spirit of the game / honor clause / Rescuetime for whether you succeeded during the week or not.)

Miles was interested, and we clarified various parameters of the challenge over email as time progressed. Mostly which sites were in play or not, and so forth. But overall the point was to limit these as much as possible.

Challenge design considerations

One of the things that I thought was useful with this experiment was having a small time budget for social media. I think cutting it out entirely would be a little too extreme, since I often post things (via asocial media) and have responses or I want to check Facebook events for directions.

The fitness challenge had the concept of a “skip day” once per week for the daily exercises. I think when creating habits that if you give yourself a flexible cheat period that it really helps with overall compliance. Allowing you to pick when to use it also helps. Do I want to skip this day, or save it for the future when I might be feeling even worse or have no time?

While I think the financial incentive was useful, I think that having a $10 bet per week would have been better. If you lose one of the weeks early, you had no incentive to continue doing the challenge. So that is something I would probably try to change if I did it again. We ended up making it ten minutes average over the weeks instead of ten minutes each week to compensate for this design issue.

The early days

We both noted that we had a habit to semi-consciously navigate to distracting things when we got stuck or found our minds wandering.

Miles: “I have found that, when I find my mind wandering, my fingers will CMD+Tab and type reddi-Tab Enter. Thankfully I have that redirected to localhost for now.”

Me: “I am in the exact same boat w/ being in the browser, getting stumped, and then command-t and start typing . It is just a muscle memory / deep brain habit. That is one of the reasons I like vacations, you lose some of these habits. I think that might be a portion of the productivity I get after vacation.”

I’d say the first few days were the hardest, after that the muscle memory seems to fade.

No foolin’

One advantage was that we started the challenge in April, so we missed most of the April Fools jokes that consume a lot of time.

RescueTime recaps

Miles suggested using RescueTime screenshots as an accountability measure, and I thought this was useful. We sent each other these at the end of each week. Here is my summary from the month before we did the challenge:

RescueTime March 2015

Not terrible, but not great either. Then for the month that we did the challenge:

RescueTime April 2015

Fantastic! The next month I was very productive again, although in that month I suffered a back injury that affected my sleeping and sent me into a pretty negative spiral. :( But overall I feel that doing this challenge was useful.

I felt like the urgency of checking various websites was greatly reduced. It was like turning down the volume.

Paying up

I went a bit over some of my guidelines, and I think Miles hit all of his. So I sent him $10. I consider it money well spent considering how much more work I was able to get done.

When’s the next one?

If we did something like this, would you be interested? Email me at (this domain minus the com)@gmail.com and if we do it again I will notify you. Or just comment on this post!

Commuting Probably Costs More Than You Think

My wife and I currently live on the northeast side of Indianapolis and work near downtown Indianapolis. We have been discussing whether we would like to move, and if so, where. For the past year or so, these talks really haven’t had much energy. We’d decide to look into moving, and then not really do anything about it. Currently we’re in a month-to-month rental with some nice landlords. However, it’s pretty far from where we work.

Last weekend I decided to quantify the costs of commuting. I figured this would give us something to work with and if it was surprising, would motivate us to take action. In typical fashion, I made a spreadsheet.

The spreadsheet shows what we are currently paying per month in total housing costs (rent, utilities) and commuting expenses. By extension, it also shows what we should be rationally willing to spend per month in total housing costs (based on our current costs of housing and work transportation.) For example, if every month of commuting costs us $300 and we are spending $1000 in rent each month, spending $1300 on a place with zero commute would be theoretically equivalent.

Here is the commuting breakdown spreadsheet that I came up with.

What surprised me

Overall, I was surprised by the amount that we should be willing to pay. I expected it to be high, but not 50% more than we are currently paying. Part of the surprise was probably due to the fact that two people’s commutes would be lowered.

After doing this analysis, I would definitely question any commute to see how it could be reduced. All things being equal, we would prefer to pay less than more, but this figure gives a nice bounds considering we think our current rent is acceptable.

General breakdown

I thought that there would generally be two quantities to figure out. First, what is the mileage that we would save by commuting less? Second, what is the time that we would save by commuting less?

Valuing mileage

Mileage covers fuel costs and vehicle maintenance. I calculated this by taking the average of the 2016 IRS standard mileage rates for business expenses (54 cents) and the lowest cost per mile that seemed reasonable (17 cents). Since both of our ten-year-old cars are paid off, have decent gas mileage (around 30 MPG) and have routine maintenance done to them, I figured this seemed reasonable.

Then I took what Google Maps says as the miles one way to our places of work from home. I took the very best case (not adding on detours.) From there:

  • multiplying by two to get round-trip miles per day
  • multiplying by how many days per week we go into work
  • multiplying by how many weeks we work each year

We have roughly $5100 in car and fuel costs per year as a result solely of our commutes.

How do you value your time?

The other factor that I thought was relevant was how much time we were spending in the car. If you drive an hour each day, how much is that costing you in terms of other things that you could be doing like leisure, working, or learning?

Calculating the time spent was fairly straightforward. I took what Google Maps said was the time during the evening and said that it was the one-way time trip. This was the most optimistic I could be, since generally traffic at other times is worse. Increases of 25%-50% can happen during rush hour, and who knows, you might get stuck in traffic for days. But still, best case I am spending the equivalent of about four working weeks in the car just driving to and from work!

Appropriately valuing our time was the most difficult part of this exercise. Initially I put $20 for value of time since I thought that was conservative. I figured if I could spend $20 to save an hour of driving in a potentially dangerous, potentially stressful environment, that would be worth it to me. I would without hesitation pay someone $20 to mow the lawn, even if I could do it myself and listen to educational material at the same time. So I figured that was in the right ballpark.

Monica felt that figure was too high. She wanted to put $0, because (paraphrasing):

Since you are working at a salaried job, it is unlikely that you would be earning more as a result of having that extra time. You can’t just spend that money on rent since it is not really coming from anywhere (just opportunity cost.)

I could see the rationale of this argument, but I wanted some way of capturing the fact that living much closer to work would be a significant quality of life difference. Basically, I wanted to take time and money and compress them both into money for analysis purposes. We ended up compromising by choosing $5, although I could see $10 being even better. I figured that some of the time I was listening to podcasts or the radio otherwise making good use of the time. There is definitely value in being free from needing to be in the car.

I found an interesting site for exploring valuing your time, although it was kind of hard to reason through. You can tell it was made by academic people with questions about things like how much would someone need to pay you for an hour of “neutral” work (work you neither like nor dislike.) It was hard to think of things that I neither liked nor disliked. I ended up getting a super-high number for how I valued my time, which might have been unreasonable. However, I really liked a lot of the things that they tried to capture.

Anyway, even with the low value of time ($5 / hour), we should rationally be willing to spend up to $1700 more per year just to live closer to work.1

Takeaways

First, move closer to where you commonly go. If it’s not possible to change your work, change lodging. If it’s not possible to change lodging, change where you work or work remotely. When you add up the costs over years or decades (with interest!), they certainly add up.

Second, we are lucky that we can consider moving and that we have careers that are in demand and flexible enough to consider remote work.

Last, valuing time is hard. We often pay people to do things for us, but it’s hard to know when it is worth it. I think establishing a decent value for your time is something worth doing. It lets you stop doing things that aren’t worth doing, lets you delegate things that are, and lets you focus more on your core economic values.

If anyone has good ways of valuing their time (or is willing to give a number with justification), I would love to hear it. I think that I have generally underdelegated in the past and it is something that I would like to get better at.2

If you liked this post and want more math applications to financial things, I wrote a post about how I saved $1400 by using a prepaid phone plan. This was before unlocked / no contract plans were in vogue, but some of the concepts still apply (especially when thinking about breaking a contract with a price to break it.)


  1. I did take into account that we would not be right next to work, since our offices are some distance apart from each other. I figured that I could walk or bike to work since my office is closer to nicer areas. So I didn’t take that mileage at all. However, I calculate Monica’s new cost as the cost of my work to her work, since the housing should be somewhere in the middle. 

  2. It certainly seems like having a good value / justification for what you would be doing with the time saved would help. If I outsource something and spend the time writing, working, socializing, or other high value activities, then outsourcing something is probably worth it. If I spend it looking at cat pictures online, probably should have just done it myself. Likewise, a factor is how much you want to do the work. But maybe this is a digression that should be split into its own post.