Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Wednesday, June 30, 2010

Installing Postgres gem on Snow Leopard

I had to jump through a small hoop to install the postgres gem on Snow Leopard so I'm putting it here to help others out. Hopefully it saves you some time.


Basic System


  • Ruby 1.8.7
  • Macports
  • OSX 10.6 (Snow Leopard)

Install Postgresql


# sudo port install postgresql84-server

Install the Postgres Gem


# sudo env ARCHFLAGS="-arch x86_64" gem install postgres -- --with-pgsql-lib=/opt/local/lib/postgresql84 --with-pgsql-include=/opt/local/include/postgresql84

Monday, January 18, 2010

Howto Install Ruby 1.8 and RubyGems from source on Debian

In the latest addition to the, "Howto Install stuff from Source on Debian", series, this post shows how to install Ruby 1.8 and RubyGems from source on Debian.

This installation has been tested out successfully on Debian Lenny, and Debian Etch. It should also work on Ubuntu.

Permissions

As noted in my last post, my user has write permissions to /usr/local/src so I don'thave to run everything under sudo. This was accomplished by allowing the staff group to write to /usr/local/src , giving write access to the staff group, and adding my user to the "staff" group.

If you would like to set this up...

# sudo chown root:staff /usr/local/src
# sudo chmod 775 /usr/local/src
# sudo usermod -a -G staff your_username

If you were not previously a member of the staff group you will need to logout and login again, or just open a new shell, for the changes to take effect.

Install

A browser friendly version of the script can be seen at http://gist.github.com/271029.

Once again, I've leveraged gist as a tool to store my installation scripts.

The script is just a wrapper to install the necessary Debian packages. This script then downloads a second script which actually downloads, configures, and install Ruby 1.8 and RubGems.

Not only is gist a very useful tool, but I've also found GitHub to be an excellent online git repository.

The scripts use the "Raw" versions of the gists.

To install, run these commands...

# wget http://gist.github.com/raw/271029/d16c8acf620047b88e509ccab205959681fd443d/install_ruby18_on_debian.sh
# chmod a+x ./install_ruby18_on_debian.sh
# ./install_ruby18_on_debian.sh

If all goes well, Ruby and RubyGems will have been installed.

# which ruby
/usr/local/bin/ruby

# ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]

# which gem
/usr/local/bin/gem

# gem -v
1.3.5

Enjoy Ruby!

Other Posts in this Series

Thursday, December 10, 2009

Fix POST for Ruby 1.9.1 and Passenger

How exciting! A new Ruby release to play with.

I figured it was time to migrate this particular app to 1.9.1 on the integration server. We've been developing this app with 1.9 and all looks good.

So I...

  • Upgraded Nginx to version 0.7.64
  • Installed Ruby 1.9.1-p376
  • Installed Passenger 2.2.7
  • Configured Nginx to use the new versions of Ruby and Passenger
  • ... and restarted Nginx

I hit the home page of the app.... Sweet, it works! Yay!

At this point I did a minor happy dance. Nothing over the top, you know... just a little wiggle :)

Then I tried to login to the app... "500 Internal Server Error"

Oh. :(

I stopped dancing right there.

It turns out that POST requests fail for Ruby 1.9.1 and Passenger.

Fortunately, there is a patch.

Patching tempfile.rb did the trick. On that particular machine, tempfile.rb was located at /usr/local/lib/ruby19/1.9.1/tempfile.rb

Thanks to Ryan Bigg for confirming the fix is good.

Sunday, March 8, 2009

scottbarr-number_to_text RubyGem

I was playing around with a bit of Ruby to convert numbers to text a few weeks ago but never finished it and forgot all about it. Today Guest11057 (thats an extremely boring nick!) on the #rubyonrails IRC channel asked if something like this existed, and apparently it doesn't. That reminded me about the mothballed code, and motivated me to finish it off and package it up as a RubyGem. To convert a number to text:
n = Number.new(119)
puts n.to_text # => "one-hundred-and-nineteen"
I'm not happy with how the implementation came, but it does the job. I'll clean it up to work a bit nicer sometime :) If you need to convert numbers to text in Ruby, take a look at http://github.com/scottbarr/number_to_text/tree/master

Sunday, February 15, 2009

YahooCurrency Gem

I recently created the YahooCurrency Ruby gem that gets currency exchange rates from Yahoo! Finance. Originally the code was part of a working Ruby on Rails demo I created about 12 months ago. A project we are currently working on needed exchange rates, so i created a Gem from the original code so we could easily reuse it across any of our future Ruby projects. We discussed making the project open source, and agreed that it would probably be useful for others, and also great for Global IT Creations to contribute something back to the open source. It is only a small contribution, but you have to start somewhere. Here is some example code...
exchange_rate = YahooCurrency.get_rate!("JPY", "USD")
exchange_rate.from #=> "JPY"
exchange_rate.to #=> "USD"
exchange_rate.rate #=> 0.0111
exchange_rate.timestamp #=> Wed Feb 11 22:20:00 +0800 2009
Get the source or the gem from http://github.com/scottbarr/yahoo_currency/tree/master Hopefully this will be the first of many projects that GITC releases as Open Source.

Monday, September 22, 2008

Rails with NO Fixtures?

I have a Rails project, and I created a Country model. I added the basic details of Norway to the countries.yml fixture.
norway:
 code: NO
 name: Norway
I added a unit test to make sure I could get Norway by it's country code, which is NO
def test_find_by_code
 assert_equal countries(:norway), Country.find_by_code('NO')
end
Agreed, I probably don't need a unit test for this, but this should have worked, but it was failing with the following message.
Country id: 318845244, code: "1", name: "Norway" expected but was
nil
Apparently NO in the yaml file is interpreted as a 0 (zero). To prove the theory I changed the code of norway to YES. The unit test failed, and indicated that the model it expected should have had code: "1". Changing countries.yml to be...
norway:
 code: "NO"
 name: Norway
I personally really like fixtures and the nice features they bring in, but sometimes they can catch you out. I'm sure it's not a bug, I've just never encountered this before. Ever found anything strange in your fixtures?

Thursday, August 14, 2008

Ruby on Rails doesn't scale you say?

You might want to read this how this Bumer Sticker, a Linked-In application, that is serving 1 billion page views per month. From the article... "Ruby on Rails is frequently criticized for lacking the ability to scale. While the road to a billion page views per month has certainly had some potholes, Bumper Sticker has clearly demonstrated that the Rails platform can scale quite well, so as long as the team behind it understands that many of the bottlenecks are exactly those faced by developers on any other database-driven web platform." Joyent also blogged about this. How many Rails application have you developed, then found scaling the app was fast, relatively simple... not to mention cheap? How many Java web applications have you developed, then found scaling the app was difficult, slower, and expensive? You probably aren't even aware of the extra work you're going through here if you've never tried to scale a Rails app. You can take your pick of frameworks, I'm not citing any specific Java web application frameworks here. I'm not directly comparing Rails to Java, but Rails to insert-your-java-framework-here. I've been working with Java for a long time, and it still has it's place. But I think Rails is eating Java's lunch in a lot of areas these days, particularly in the web application and web services area.