Moncef Belyamani

Coding, productivity, and Mac automation tutorials for beginners and beyond.

How to Upgrade PostgreSQL With Homebrew

TL;DR If you’ve just upgraded Postgres with Homebrew and Postgres won’t start, as long as you don’t care about any data stored locally, remove all versions of Postgres (brew remove --force postgresql), delete the /usr/local/var/postgres/ folder, then reinstall Postgres.

I’m currently doing some Rails consulting for a company that uses Postgres in their app. After cloning the app to my computer, I wanted to make sure I had the latest version of Postgres.

RSpec & Capybara: How to Fix Undefined Method `feature’ for main:Object (NoMethodError)

While working on the Ohana API during the Code for America fellowship, I came across a strange situation. My feature specs didn’t include require "spec_helper" at the top of each file, yet I was able to run all of the specs like so:

1
$ rspec

Or just all of the feature specs:

1
$ rspec spec/features

And individual ones as well:

1
$ rspec spec/features/signin_spec.rb

Then when I cloned the repo to a new directory (to test the installation instructions in the README), I noticed that I could no longer run specific tests. If I tried to run rspec spec/features/signin_spec.rb for example, I would get this error:

1
2
3
4
5
6
7
8
/Users/monfresh/Desktop/ohana-api/spec/features/signin_spec.rb:1:in `<top (required)>': undefined method `feature' for main:Object (NoMethodError)
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
  from /Users/monfresh/.rvm/gems/ruby-2.0.0-p353@ohana-api/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

The solution was to add require "spec_helper" to the top of each feature spec, but what I still haven’t been able to figure out, is why I was able to get by for months without that require statement. If you know why, please send me a Tweet to enlighten me!

Why I’m Coding for America

May 23, 2012. I’m attending TechCrunch Disrupt NYC with several AOL colleagues to celebrate the release of the TechCrunch iPad app. We’d been given the opportunity to attend the last day of the conference in recognition of our hard work.

Todd Park (the CTO of the United States) and Steven VanRoekel (the US CIO) happened to be speakers that day, and their passionate and spirited talk on innovation in the government blew me away. I started following Todd Park on Twitter, and that same day, he mentioned Code for America in a tweet. I had not heard of them before, and the name sounded intriguing, so I proceeded to follow them as well. Shortly thereafter, I found out about the open application for their Fellowship program.

How to Install PostgreSQL on a Mac With Homebrew and Lunchy

This is a quick guide for installing PostgreSQL (Postgres for short) on a Mac with Homebrew, and starting and stopping it with Lunchy. If you’ve just forked a Ruby on Rails project that requires Postgres, this tutorial will get you up and running in no time.

If you’re working on a brand new Rails app and need to create a new Postgres user and database for your app, I recommend Will Jessop’s tutorial or Peter Cooper’s screencast.

List the Largest Folders on Your Mac in One Keystroke With Keyboard Maestro or Quicksilver

In preparation for backing up my large Dance Music library to Dropbox (in order to sync it between my iMac and MacBook Air), I wanted to start by deleting all the songs I won’t miss. Finding individual files over a certain size is easy via the Finder, but I wanted to find out which folders (i.e. albums) were over 500MB so I could tackle them first.

There is no Folder size option in Finder’s search (afaik), so I did some Unix command research and found the wonderful du (short for disk usage). By default, du lists the folder sizes as multiples of 512 bytes, but you can easily change that to 1024 bytes with the -k flag. So, if you wanted to see the size of all your Dropbox folders, you would run the following command in Terminal:

Email the URL and Title of the Current Web Page in One Keystroke With Keyboard Maestro

I’m a big fan of efficiency, and this is one of many timesaving macros you can create with Keyboard Maestro. If you’re already familiar with Keyboard Maestro variables and tokens, you can skip the tutorial and download email URL and title of current web page.kmmacros from my Keyboard-Maestro-Macros repo on GitHub, then import it via File -> Import Macros....

Once imported, it will be placed in a “Browsers” Group that defines the applications in which the keyboard shortcut (aka Hot Key Trigger) for the macro is enabled. I added Safari, Chrome and Firefox to the Group. Before you run the macro, you should at least edit the email address in the Insert Text action. You might also want to change the Hot Key Trigger and/or the email client launched by the macro. Once you’ve tested the macro on your machine, you should add an action at the end that actually sends the email.

For those of you who are new to Keyboard Maestro, let me walk you through the process step by step.