The "ctrl + alt + delete" of RVM

When ever you are trying to install a Ruby, package or anything else with RVM it is not that uncommon to run into strange issues. Just like when you first go to smashing the Ctrl + Alt + Delete keys on Windows, I have found through experience that the first port of call should be to take the following simple steps.

For an example, imagine you are trying to install Ruby 1.9.2. I recently had to use this approach to get version 1.9.2 installed on OSX Lion.

Note: On OSX, Make sure you have either the GCC libraries or XCode 4.2+ installed to work best with RVM

Steps

  1. rvm get head
  2. rvm reload
  3. rvm remove 1.9.2
  4. rvm install 1.9.2

First we update RVM, reload the environment (important) remove whatever broken ruby/package you are trying to get working. Finally, Install it fresh. 

You would be suprised how often this resolves issues. Give it a try next time you are having issues.

Show git branch and directory in your shell

It's really handy to be able to see the current git branch in your shell prompt along with the directory name. This for a start removes many "git branch" commands from your history.

To enable this feature, you have to edit your .bashrc file on Linux or the .bash_profile on Mac. These files usually exist in your home directory (The default directory when you open a shell) and are executed when the shell logs in. You can edit this file with any text editor such as Gedit or Textmate.

Add the following 2 lines after any existing SP1 variables and then save your file. Open a new shell to see the changes.

GIT_PS1_SHOWDIRTYSTATE=false
export PS1='\[\033[1;36m\]\u at\[\033[00m\] \[\033[34m\]\W\[\033[31m\]$("__git_ps1")\[\033[00m\]  >  '


SP1 colour example

Changing colours

If you would like to update the colours of the prompt, then visit this article to get a grasp of the basics and you can find much more on Google from there.

Correct HTML Entity for Twitter Bootstrap close link

I was recently implementing a Ruby on Rails method that creates flash messages with the beautiful Twitter Bootstrap styled alert message. I did however notice that although the flash messages looked almost correct, the "close" link on the right hand side was no longer correctly styled.

There are no images in the Twitter Bootstrap, so this icon must only be the English letter "x", or so I assumed.

After looking at the CSS comparison from the examples to my code and finding no help, I eventually noticed a slight difference in the "x" character I was using. It turns out that the Twitter Bootstrap is designed to use the HTML entity "&#215" (times symbol) instead of the keyboard letter "x".

Hopefully this can help out anyone else facing a similar confusing issue.

Activating Apache/PHP on Mac alongside Pow server

Instead of rewriting a step-by-step guide on how to do this, I can recommend two great articles that will get you setup in no time.

First read this article on how to setup Apache and PHP on your Mac:
http://superfancy.net/coding/php-mysql-apache-in-mac-osx-leopard/

Next, follow the instructions from 37signals on using Pow alongside Apache. Make sure to pay attention to the troubleshooting section if you had any trouble.
https://github.com/37signals/pow/wiki/Running-Pow-with-Apache

Stub RSpec cookies to set them in your tests

I have recently been in the situation where I was testing a controller that looked up the value of a cookie in a before_filter to validate the user.

I had trouble setting the cookie from within the controller spec so that it was available to the before_filter. The solution that I want to share is

controller.stubs(:cookies).returns({:user_session => 'xxxx'})

The reason I could not get this working earlier was that I was mistakenly trying to stub the cookies method directly. Instead I have to stub the controller cookies, even if it is a private method.

© Blake Simpson, 2012 – 2018