Posterous theme by Cory Watilo

Installing theRubyRacer on OSX Lion w/Xcode 4.2.1

Struggled with this one quite a while last night. Turns out the solution is quite simple Everytime I would run

gem install therubyracer

I would get back an error like so:

Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
ERROR: Failed to build gem native extension.

/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for main() in -lobjc... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  --with-objclib
  --without-objclib
/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
  from /Users/marlon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0'
  from /Users/marlon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:440:in `try_link'
  from /Users/marlon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:552:in `try_func'

This is what the mkmf.log file had in it. Wasn’t much.

"/usr/bin/gcc-4.2 -o conftest -I/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-darwin11.0.0 -I/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe conftest.c  -L. -L/Users/marlon/.rvm/rubies/ruby-1.9.2-p290/lib -L. -L/usr/local/lib     -lruby.1.9.1-static  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

Finally got the idea to try the command in the mkmf.log and figured out that I didn’t have a gcc-4.2 on my file system anywhere, only a ‘gcc’ that happend to be version 4.2.1. A quick symlink later and theRubyRacer compiled perfectly.

nifty config tip for nginx and rails apps

If you’ve got a rails site running on nginx, you’ve more than likely seen your nginx access logs & production log polluted with calls to favicon.ico and phpinfo.php and all sorts of other stuff.  Here’s a quick and easy way for nginx to drop all those requests:   In the folder that houses the nginx.conf file, create a drop.conf file with the following:

location = /robots.txt         { access_log off; log_not_found off; }
location = /favicon.ico        { access_log off; log_not_found off; }
location ~ \.(php|asp|cfm|jsp) { access_log off; log_not_found off; return 204; }
location ~ /\.                 { access_log off; log_not_found off; deny all; }

Then at the end of your server declaration block:

server {         
  ....
  include drop.conf;
}

This will quit the logging of favicon.ico along with robots.txt.  It will drop all requests for languages not used in you app and will deny access to any dot file in your apps folders   Thanks to this site for giving me some great examples: https://calomel.org/nginx.html  

Gnome 3 and crashing

I've really been liking Gnome3, but there's this nagging crashing issue that's been driving me buggy.  In my error logs, I get stuff like "widget outside GTKWindow" and other odd GTK errors. 

After googling for a while and getting nowhere, I did stumble upon a hint where somebody had replaced gdm with kdm.  I tried it and lo and behold, I can run git-cola without it crashing my session. 

I do get errors still, like: Gtk-Message: Failed to load module "canberra-gtk-moduleanberra-gtk-module", but hey, as long as it doesn't crash, I'm fine!

Using RVM Gemsets for deploying

Recently I’ve switched to using RVM Gemsets in my deployment vs using Bundler’s deployment option. I started having issues with compiling native extensions with the bundler capistrano tasks. Since an error in that causes a rollback of the deployment, it’s not easy to troubleshoot.

That’s why I started using gemsets for each application I deploy. When I deploy, the first thing capistrano does is create the gemset. After the code updates, the bundle command will run and install all the required gems into the application’s gemset. If you do have an issue with compiled gem, it’s as easy as ssh'ing to the machine and:

rvm 1.9.2@myGemSet

gem install myProblematicGem

Below are the two tasks that I use in my deploy.rb:

# add these to your deploy.rb
before "deploy", "deploy:create_gemset"

after "deploy:finalize_update", "deploy:bundle"

namespace :deploy do
  desc "Create the gemset"
  task :create_gemset do
    run "rvm #{rvm_ruby_string} --create"
  end

  desc "Install the bundle"
  task :bundle do
    run "bundle install --gemfile #{release_path}/Gemfile --without development test"
  end
end

Moving sites from windows to linux

I’m helping a friend in his move from windows based hosting to linux based hosting.  One of the big issues so far has been case sensitivity in the linux file system.  After using the tried and true method of clicking until you find a broken link, I came up with a better idea.  Just run this ruby script inside the root directory of your site and it will show you filenames and which files have case issues with it.

#!/usr/bin/ruby
files = Dir['**/**'].sort

files.each do |file|
  #do a case insensitve search first
  all_matches = `ack -lic "#{file}"`.split("\n")
  puts "found #{all_matches.length} matches for #{file}"
  exact_matches = `ack -lc "#{file}"`.split("\n")

  difference = all_matches - exact_matches

  unless difference.empty?
    puts "#{difference.join("\n")}\n\n-----------------------------------------"
  end
end

My Mac Development Setup

From powering on a new mac to ready to develop, here's my setup:

Install Dropbox and make symbolic links to all my dot files, .vim,  .vimrc, .zshrc, etc

Install SIMBL

Install a nice, easy to read terminal theme such as this one:

Install XCode

Install Homebrew

    brew install git

    brew install macvim

    brew install mysql

    brew install ack

    brew install imagemagick

install rvm with:

install Ruby Enterprise Edition with 

    rvm install ree

    rvm use default

    sudo gem install livereload # this uses some rubycocoa libraries that aren't in Ruby Enterprise Edition
    sudo gem install compass

    rvm use ree

    gem install rails
    gem install mysqlplus
    gem install compass
    gem install activerecord-sqlserver-adapter
    gem install unicorn

Moving from a case-sensitive fs to a case ignorant one

I'm moving to a new mbp. I've got a time machine backup disk, but it's a case sensitive fs and my new mb is not. I've got a few music files that don't match up perfectly like "Lady Gaga" and "Lady GaGa"....hey, you gotta admit, she's got some catchy tunes.

Anyway, in order to find these and manually copy them over, I drop into the command line and run this:

 
find ./ | tr 'A-Z' 'a-z' | sort -rn | uniq -d 

This will give you a list of all the directories/files that are duplicates of each other in everything but their case. It's up to you after that to move the files to one directory or another.