How to setup Textmate to use RVM

by Irish on June 28, 2010

Alright, so you’ve switched to using rvm but when you run cmd+r on a Ruby file in TextMate you’re still using your old system install of Ruby… Luckily it only takes a few easy steps to setup TextMate to use your rvm environment.

1) First make sure your install of TextMate if updated
Textmate -> Preferences -> Software Update -> Check Now

2) Next make sure all your bundles are up to date. The creator of rvm, Waynee Seguin, provides a small bash script to automate this process. You can check it out at this GitHub gist

3) Now get the rvm name of the Ruby version you want to use in TextMate. In my case I’m going to use my currently selected version “ruby-1.8.7-tv1_8_7_174″

$ rvm list
rvm rubies

   jruby-1.5.1 [ i386-java ]
   ruby-1.8.7-tv1_8_7_173 [ i386 ]
=> ruby-1.8.7-tv1_8_7_174 [ i386 ]
   ruby-1.9.1-tv1_9_1_378 [ i386 ]
   ruby-1.9.2-head [ i386 ]

4) Then run the rvm command to wrap this ruby version for TextMate

$ rvm wrapper ruby-1.8.7-tv1_8_7_174 textmate

5) Now set a TM_RUBY variable in your TextMate Preferences
Textmate -> Preferences -> Advanced -> Shell Variables

To the wrapper command generated by rvm for you, in my case it was found here:

/Users/cirish/.rvm/bin/textmate_ruby

6) Since TextMate will use it’s own builder, by removing it, we can use TM_RUBY as described above.

$ cd /Applications/TextMate.app/Contents/SharedSupport/Support/lib/
mv Builder.rb Builder.rb.backup

7) Last but not least, quit TextMate and re-open it to load these settings. You should now be all good :)

{ 9 comments }

OS X “Safe Sleep” Mode

by Irish on June 22, 2010

I seem to continually have the problem of my laptop waking up on its own in my backpack. I’m not sure what exactly is the cause, but I’m gonna assume it’s from the screen not staying completely locked/closed. However, I found this OS X command on Andrew Dupont’s blog, which puts OS X into a “safe sleep” mode. This causes OS X to write memory state to a hibernation image at sleep time. Now for me to awaken my Macbook Pro, opening the lid is not enough. Now it takes a press of the power button, and a few more seconds than before, but no more accidental awakening, or half-dead battery upon arriving at my destination.

$ sudo pmset -a hibernatemode 1

Now just put your computer to sleep like you normally would. I for one prefer to use the quick keys (cmd + option + eject). Check the man page for more options.

$ man pmset

{ 0 comments }

Ruby 1.8.7 openssl Bus Error

by Irish on June 21, 2010

Recently I switched from using my local ruby install to using RVM for managing all my ruby installations. RVM is pretty awesome and I highly recommend it. I went ahead and installed a few versions of ruby that I’d like to use including, ruby 1.8.7 (for work projects) and 1.9.2 (for playing with rails 3).

I came across an issue though with my 1.8.7 install when trying to run a rake db:migrate:reset command with my current work project. It was along the lines of this:

$ rake db:migrate:reset
(in /Users/cirish/Projects/so-ch)
/Users/cirish/.rvm/rubies/ruby-1.8.7-tv1_8_7_173/lib/ruby/1.8/openssl/ssl.rb:31: [BUG] Bus Error
ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9.8.0]

Abort trap
$

Well that’s no bueno. It turns out that this is happening because, I have two openssl installations. A system one and other that I installed through macports. The reason the bus error is being thrown is that my eventmachine gem wasn’t compiled with the same openssl lib as my ruby 1.8.7 install. We can confirm this by running the following:

$ ruby -rubygems -e" require 'openssl' "; echo $? 0
0 0

$ ruby -rubygems -e" require 'eventmachine'; require 'openssl' "; echo $?
/Users/cirish/.rvm/rubies/ruby-1.8.7-tv1_8_7_173/lib/ruby/1.8/openssl/ssl.rb:31: [BUG] Bus Error
ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-darwin9.8.0]

Abort trap
134

At this point you could either recompile ruby and point it to the correct openssl lib or recompile eventmachine to use the system’s openssl. Since this was a new ruby install anyways, I chose to just recompile ruby.

$ rvm install ruby-1.8.7-tv1_8_7_174 --configure --enable-shared=true,--with-openssl-dir=/opt/local --debug

Now let’s check the install again

$ ruby -rubygems -e" require 'eventmachine'; require 'openssl' "; echo $?
0

Fixed :-)

{ 1 comment }

This is more of a reminder to myself than anything. To install the mysql gem on OS X Leopard and use a macports MySQL install.

First remove any previously installed mysql gem

$ gem uninstall mysql

Then install, giving the correct Leopard archflag and macports mysql_config directory

$ env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

{ 0 comments }

Installing RMagick on OS X has at times been really smooth for me, and other times, a royal pain in the ass. The issues usually come from having to get ImageMagick installed, but I’ve also had problems with the RMagick gem not being able to build the native extensions. I’ve successfully installed ImageMagick by using MacPorts and by compiling the sources by hand. Hopefully, some of these tips will help you with your installation if a problem occurs.

Tip #1: Keep MacPorts and your installed packages up to date!

MacPorts allows for easy installation of packages. But beware, MacPort’s packages are a bit of a dependency nightmare at times. If your installed packages are old and you use them to compile new packages, things can get messed up in the linking/compiling process, or simply just be completely incompatible. Be sure to run these commands often and always before you trying installing/upgrading anything.

$ sudo port selfupdate
$ sudo port upgrade outdated

Tip #2: MacPorts isn’t your only option

There are other’s out there that have felt the install pain. I came across this installer script that’s well maintained and as of this writing has been updated to work with ImageMagick-6.6.1-5

http://github.com/maddox/magick-installer/blob/master/magick-installer.sh

Simply grab it with Git

$ git clone http://github.com/maddox/magick-installer.git
$ cd magick-installer
$ ./magick-installer.sh

I’ve also heard good things about the OS X homebrew package management system, but have no personal experience in using it. Check it out here, and give it a go if it sounds up your alley.

http://mxcl.github.com/homebrew/

Tip #3: Ask for help

Check the Installation FAQS
They have solutions for some of the more common issues that tend to happen
http://rmagick.rubyforge.org/install-faq.html#loaderror

Search Online
Take any error messages you receive and try googling for answers to them. You can usually find blog posts from other people that have run into the same issues as you. Hit up the mailing lists or you can even send an email to the project maintainers at rmagick@rubyforge.org

Tip #4: Use the verbose flag when building the gem

This will show you what’s going on as far as the gem building making external requests for libs, what’s building/being written, and that can give you more details than just what the simple stacktrace will show you, when things go wrong.

$ sudo gem install rmagick -V

Tip #5: Be sure to test it after successful install

As noted on the RMagick site, the “Successfully installed” message does not mean that RMagick was successfully installed. The RMagick installation can encounter error conditions that gem can’t detect. The following irb session is a better indicator of a successful install.

$ irb -rubygems -r RMagick
irb(main):001:0> puts Magick::Long_version
This is RMagick 2.13.1 Copyright (C) 2009 by Timothy P. Hunter
Built with ImageMagick 6.6.1-5 2010-05-11 Q8 http://www.imagemagick.org
Built for ruby 1.8.7
Web page: http://rmagick.rubyforge.org
Email: rmagick@rubyforge.org
=> nil

{ 1 comment }

Git garbage collect bash script

by Irish on May 3, 2010

The following shell command will crawl your hard drive, from your current directory, looking for any git repositories. When it finds them it will garbage collect, prune, and pack them, regaining your disk space and make your repositories operate faster.

1
2
#!/bin/sh
find . -type d -name .git | while read dir; do pushd "$dir"; git gc --prune; popd; done

You can run this directly from the terminal or just turn this snippet into a lil bash script file for easy executing later, i.e.

$ touch git_garbage_collect.sh
$ nano git_garbage_collect.sh
$ # copy & paste the script into the file
$ ctrl+o # to save the file
$ ctrl+x # to exit nano

Then just run it like any other bash script

$ ./git_garbage_collect.sh

{ 0 comments }

Refactor: Ruby Array#joins for delimiting

by Irish on April 30, 2010

The other day I was reviewing a collegue’s code, who shall remain nameless to protect their innocense, and came across this lil gem:

    1 <h4>Tags</h4>
    2 <p>
    3   <% @entry.tags.each_with_index do |tag, i| %>
    4     <%= tag.name %> <% if @entry.tags.length - 1 != i %>, <% end %>
    5   <% end %>
    6 </p>

Now while it does work, it’s definately not the Ruby way, as we can rewrite it more elegantly like:

    1 <h4>Tags</h4>
    2 <p>
    3   <%= @entry.tags.join(', ') %>
    4 </p>

The ‘tags’ association here returns an array, so we can just call the join method on it. This will delimit the array contents with whatever string we like, in this case just a comma. Ah much better and concise.

{ 0 comments }

Post image for Easy Slicehost setup with Sliceapp.com

Easy Slicehost setup with Sliceapp.com

by Irish on April 20, 2010

For the last 2 years or so I’ve been using server slices from Slicehost.com. When you’re first learning to flex your system admin skills, setting up a server slice from scratch is fun and exciting. You don’t mind installing an OS (go Ubuntu!), locking down the server for security, adding users, installing libraries and setting up a development environment. However, once you’ve done it a bunch of times it gets repetitive, old, and boring. Even if you’re really good and can do it fast, why bother? There are now easier and faster ways to get up and running.

About six months ago my co-worker Clayton Lengel-Zigich found Sliceapp.com. Thanks to the work of the guys at Clever Collie setting up a server can now be super fast, fully automated, and it’s a free service. Though they also have a “premium” option for installing services like WordPress, Drupal, Redis, and more.

After purchasing a new slice, all Slicepp needs from you is an email address they can contact you at after the setup is complete, the IP of your slice, and your slice’s root username/password. You get to select from a few popular frameworks, web servers, database, and monitoring options. Rails, Django, Apache, Nginx, Lighttpd, and monit to name a few.

Once you’ve chosen your options and press the big “Deploy” button, a in-browser terminal console pops up allowing you to watch the server be setup. Or if you’re like me you can completely leave the site and wait for the job to finish, while doing other things. You’ll get your build complete confirmation email in about ten minutes. I really like this service as you know you’ll always get the same environment setup. When working on a team it can be rather annoying when different team members are setting up servers and installing things in different locations in each instance.

Powered by Rackspace Cloud Computing

I should also mention that the other day I decided to try out Rackspace’s cloud services. Sliceapp worked great setting up an Ubuntu Karmic environment over there too. Saweet! :D

{ 2 comments }

The authme, ssh key, bash function

by Irish on April 19, 2010

Often it can be a pain to remember all the username/password combinations for all the different servers we touch in our day to day development.  I’ve come to really like this lil’ bash function given to me by my co-worker Anthony DiGirolamo.

1
2
3
function authme {
  ssh $@ 'cat >>.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
}

Just put it in your ~/.bash_profile file or one of the other bash settings files you may be using.

Usage is like so

$ authme deploy@www.somedomain.com

You’ll be prompted for your password then returned to the local terminal prompt. This will ssh onto the given server and concatenate your ssh public key to the authorized_keys file. Allowing you from there on out, not having to supply a password to get on the server through ssh. Good stuff

{ 4 comments }