John Bohn

My thoughts on software, tech, business, and more

Find Deleted Files in Git

Occasionally I’ll remove some files from a git repository that I need to get back for one reason or another. Specifically, recently I was working on a project where I was working with a bunch of audio files that I reorganized and moved to separate directories (a.k.a. organized a bunch of stuff that was all thrown into a big heap of files). One of the many things that I love about git is that you are able to easily recover these files or directories, do what you need to them, then move them around some more, commit the “undelete” or just “redelete” them.

To accomplish this, you use the plumbing command git rev-list (more info on plumbing vs. porcelain). Git’s rev-list command is extremely important and ultimately used by multiple porcelain commands. Here’s a great description of the basics from the man.

List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.

You can think of this as a set operation. Commits given on the command line form a set of commits that are reachable from any of them, and then commits reachable from any of the ones given with ^ in front are subtracted from that set. The remaining commits are what comes out in the command’s output. Various other options and paths parameters can be used to further limit the result.

So, if I have a file that I deleted a month or so ago called foo.rb but for some reason I need to bring it back into my local repo. I can easily bring it back by running the following:

1
git checkout `git rev-list -n 1 HEAD -- foo.rb`^ foo.rb

So, that’s obviously a bit of a long-winded shortcut. Let’s break it down.

It’s really two commands in one. Let’s start with inside the ticks.

1
git rev-list -n 1 HEAD -- foo.rb

The -n 1 says “give me one revision”. HEAD represents the tip of the current branch. The bare double dashes (or ) represents my current branch. When all put together we are saying, print the latest commit hash starting from the commit I am currently on, in the branch that I am currently on, that modified foo.rb. The caret (^) is a shortcut that represents the previous commit to whatever it appends.

Once you grok that, the next part is pretty easy. Once interperted by the shell, the command is just a normal checkout from an alternate commit.

If none of that makes sense, feel free to comment and I’ll try to clarify. When in doubt though, just trust me :).

Fixing Homebrew on Mac OS X Mavericks

I’ve had lots of problems with homebrew since upgrading to Mavericks. The same problems also existed when trying to rbenv install and really anything else that compiles. The root cause of the issue ended up being a conflict Mountain Lion Command Line Tools and the ones provided by Maverick.

There was an easy solution however. By running xcode-select (a tool provided to change the path to the current active developer directory) it will fix the issue.

Specifically, run this from your terminal:

1
xcode-select --install

This will bring up a dialog to install the Command Line Tools (which you will have to type in your password) and will fix the problem.

How to Take a Screenshot With Ruby’s Selenium Web Driver

Today I came across a new project called Huxley that is described as a test-like system for catching visual regressions in Web applications. Though I’ve seen many frameworks that either focus on the micro level unit testing or the macro level functional and integration tests, this is the first time I’ve seen a testing framework that focuses on catching visual regressions on the web. It’s written in python and under the hood, is using the Selenium WebDriver to handle browser automation and take screenshots.

To be honest, I didn’t even realize that Selenium WebDriver could take screenshots. That said, I realized I had more to learn about it. After looking through the api docs, I found that taking a screenshot, is very easy.

Check it out.

If you do not have Selenium Server installed, do it now. If you’re on a Mac, you can easily install it with homebrew.

1
brew install selenium-server-standalone

If you do not have the Selenium WebDriver gem installed, get that as well.

1
gem install selenium-webdriver

Now for the code to take the screenshot

1
2
3
4
5
6
7
8
9
require 'selenium-webdriver'

# Other drivers are available as well http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver.html#for-class_method
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://www.google.com'

driver.save_screenshot('screenshot.png')

driver.quit

Couldn’t be any easier. I love finding new bits of code that are this easy to use. Needless to say, I’m going to be delving a bit deeper into this and see if I can come up with any new tools.

Keep Your New Business on Track by Asking Why

“He who has a why to live can bear almost any how.” – Friedrich Nietzsche

TLDR; To ensure that you are doing things that matter, always ask why.

To do things that matter, always ask why. There was an brief article today on Lifehacker about not asking why. In all fairness, this article said not to ask why in existential circumstances. Things like, “Why are we here? What’s the meaning of life?”. Stuff like that. I wasn’t crazy about the post but it did get me thinking about the question of why.

If you ask anyone I’ve worked to tell you my favorite response to a proposal for a new feature or project, you’re almost sure to hear them say say, “Why”. I ask why to make sure we are doing things that matter. It might matter to the customer in the case of a new feature. It could be important for an employee in the case of a new workflow or set of processes. There are many reasons to justify a project, but when you ask why, you open yourself to really understanding your decisions at a deeper level.

Why is powerful. Why ensures that you are spending time on things that truly matter. This is really important when you are first starting your business. Too many businesses start with the a lot of hows. These implementation details are important down the road, but they are a waste of time until you figure out why you are doing what you are doing. For instance, I’ve seen too many new business owners who are trying to get customers to purchase their product or service, but end up on the wrong path. They spend hours, days, even months figuring out pricing for their product/service, signing up for social media accounts, figuring out tax implications, getting business licenses, coming up with business plans and more. These types of chores can be important later in your business, but when you take care of them this far upstream, you are just wasting time.

“It’s not enough to just give it a whirl; you’ve got to give it a whirl with purpose and direction.” – Eric Ries, The Lean Startup

It’s also important to say why more than once. If you accept the first answer, you may not be getting to the root of the problem. You may find yourself accepting a superficial reason to justify the time you are spending on a project. Take the following example. A young interior decorator is just starting out and booking a job or two a month. She’s setup homes for family, friends, and even some outside clients. At this point in her career, she has validated that she’s good enough to bring in more clients. Her challenge now is to go out there and and grow her business. Unfortunately, she’s getting wrapped up in all the wrong things. She’s thinking about business licenses, checking accounts, invoicing, insurance, and taxes. All the wrong things! When her business is in this stage and she wants to grow your business, these tasks are time wasting distractions from her real goal. She’s not focusing on bringing in new clients which would really take her business to the next level. If she were to start asking why before doing these tasks, she might second guess their value.

I’ve started using a method that I calling The Five Whys. The premise is that if ask yourself why five times, and you haven’t gotten to an answer that directly relates to your current business goals, then you are doing something that doesn’t matter. Let’s take the five whys to our designer friend. She’s interested in signing up for an EIN (employer ID number) because she knows it’s one of those things that new business owners “have” to do. Let’s see what happens when she applies the five whys to getting an EIN.

I am signing up for an EIN (employee identification number).
Why?
So I can get a business checking account
Why?
So I can keep my personal money separate from the business.
Why?
So I can have separate accounts for when taxes come due
Why?
So I can pay my business taxes from that account
Why?

(Usually this answer is just a long pause followed by, “Ummm…”)

If she did this exercise, she would realize that none of these answers have anything to do getting more clients and growing her business. She would stop here, pick something else of her todo list, and try the five whys again.

So next time you start a new task, before asking, “How am I going to do this?”, start with the five whys. At least very least, ask yourself “Why am I doing this” at least once. You may find that your time could be spent elsewhere.

How to Get Your Public IP Address From the Terminal

Came across this little command the other day. This does a simple GET request to http://ifconfig.me, which returns your IP address.

curl ifconfig.me

There are also a few other commands that can give you other information including your hostname, user agent, etc. You can get it return in json, xml or plain text. I encourage you to checkout http://ifconfig.me on the web to see them all.

There are a few services to retrieve your public facing IP address, but I think this one is the nicest/easiest to remember.

How to Disable Mac OS X Dashboard

For me, Dashboard is one of the worst features of Mac OS X. If Apple were to release it today, there would be all kinds of comments on how they are losing it and that it’s just not the same since Steve left. But, did you know you can remove it? After a little searching, I found out that it’s just another preference that can be set via the defaults command.

Turn it off

To turn off Dashboard, open your terminal and enter the following

defaults write com.apple.dashboard mcx-disabled -boolean YES

Then logout your user, and log back in. Dashboard should be gone.

Bring it back

If you decide that you want it back, it’s just a matter of flipping the boolean.

defaults write com.apple.dashboard mcx-disabled -boolean NO

As before, you’ll need to logout and login to see the difference.