Showing posts with label tip. Show all posts
Showing posts with label tip. Show all posts

Friday, May 15, 2009

Tip: Compiling the Postgres Gem for Ruby 1.9.1

[EDIT (2010-JAN-16): The original postgres gem has been replaced by ruby-pg. If you are having the problem below, try installing the pg gem via sudo gem pg install.]

Crash!

I compiled a fresh copy of Ruby 1.9.1 onto my MacBook Pro and proceeded to install Ramaze, Sequel, Thin. Things went well and I was happy... that is, until I tried to install the postgres gem. I'm talking the C-extension one, which runs so much faster than the native one that it isn't even funny.

$ sudo gem install postgres

That's when it happened: bam! exception!

/usr/local/bin/ruby extconf.rb install postgres
extconf.rb:4:in `<main>': uninitialized constant PLATFORM (NameError)

No good. How am I supposed to develop enterprise Ruby software when I cannot connect to the database?!

What Happened

After poking around on the internet, I discovered two things about Ruby 1.9.1:

  1. The PLATFORM environment variable is now RUBY_PLATFORM, and
  2. The C macros for working with a Ruby Array changed.

The Solution

To solve this problem, one could learn what to do and hand-change all the code. This is a waste of time. I set-up a couple sed filters instead. Thus, to get your postgres adapter working, just do the following:

$ cd /usr/local/lib/ruby/gems/1.9.1/gems/postgres-0.7.9.2008.01.28/ext
$ sudo sed "s/PLATFORM/RUBY_PLATFORM/" extconf.rb > ./extconf.rb
$ sudo ruby extconf.rb
$ sudo sed "s/RARRAY(\([_a-zA-Z0-9]*\))->ptr/RARRAY_PTR(\1)/; s/RARRAY(\([_a-zA-Z0-9]*\))->len/RARRAY_LEN(\1)/; s/row->len/RARRAY_LEN(row)/; s/row->ptr/RARRAY_PTR(row)/" postgres.c > ./postgres.c
$ sudo make
$ sudo make install

Disclaimer

While I have been successfully using this patch, I have not tested it in a production environment. Therefore, you should put this patch through its paces before using it on anything critical.

Lastly, but definitely most importantly, I am NOT liable for anything bad that may happen as a result of using this patch. It is up to you to thoroughly test it for any problems, which may include (but are not limited to) loss of data on your system, loss of data on your database, corruption of your Ruby installation, self destruction of your hard drive, spontaneous combustion of your printer, Swine flu infection, SARS transmission, broken lawn mowers, and rancid ice cream.

Tip: Ruby 1.9.1 RDocs in HTML

That's A Big Process!

I like my HTML RDocs. They are easy to browse and search. Unfortunately, unlike ruby 1.8.x, which made compiling the HTML RDocs trivial, ruby 1.9.1 seems to only make ri documentation trivial... and I soon found out why.

It turns out that on my old MacBook Pro (maxed out with only 2 GB of RAM), I didn't have enough RAM to build the process. Somewhere around 3/4 of the way done, the thing would jump into swap and crawl to a halt. I aborted and decided I'd have to live with online and ri documentation.

Recently, however, I upgraded to a new MacBook Pro with 4 GB of RAM on board and decided to try compiling the RDocs again. After 25 minutes and around 2 GB of RAM for the single ruby process, it worked! (Why it takes so much RAM is beyond me... they need to rethink how RDoc is written).

Where Do I Get It?

Considering that I've gone through all the work, there is no reason why I can't share, so I've published the directory to my GitHub account in the ruby-rdoc project.

While other GitHub users will probably just clone the repository to keep up on the latest updates, most people will want to download a tarball or zip archive. To do this, simply go to the downloads page and pick the documentation that goes with the ruby version you want.

Thursday, November 29, 2007

Tip: Bug in Ruby 1.8.5 on 10.5 Leopard

When I first got Mac OS X 10.5 Leopard, one of the first things I had to do with compile and install ruby 1.8.5 in order to facilitate my job as a Ruby on Rails developer (as we are just getting around to upgrading our thousands of lines of enterprise code to work in rails 1.2.x).

I downloaded, compiled, and installed, ruby 1.8.5 p114, and for the most part things went smoothly.

However I would intermittently get the weirdest error:

NoMemoryError (negative allocation size (or too big))

I still don't know what the root cause of this error is, but as of this morning it seems that downgrading to p52 fixed my problem.

Hopefully this will pan out in the long run, but so far this error (which I'd see several times an hour during active development) has disappeared.

Tuesday, October 2, 2007

Tip: Time Scroller

With my co-worker working remotely the Philippines for the next 6 weeks, I have been finding that I'm often interested in two things:

  1. What time is it there right now?
  2. When is a good time to talk to him?

The first of these issues is handled easily enough with Apple's World Clock widget, which everyone has with their shiny copy of Tiger.

But to solve the second one of these issues, I was finding myself wanting a Little Orphan Annie decoder ring style thing--with color coded section--to let me quickly scan over times and see how things line up.

TimeScroller to the rescue!

After a quick search in Apple's downloads area, and a run around the block looking at the various widgets available, I found TimeScroller to be the best for what I wanted.

With a quick press of F12, I'm whisked to a place where I can quickly see the time in as many (or as few) cities as I please, and with a flick of a scroll-bug, I can cycle through the times, checking to see how things line-up without doing any mental arithmetic. And the best part: the customizable colored orbs that allow me to quickly tell when business hours align.

Indeed, the only thing I would like to have out of this is a way to define different hours for the different cities (as my co-worker currently works from 4am to noon Manila time while I work 10am to 6pm Spokane Time).

To download TimeScroller, visit the TimeScroller webpage at http://www.timescroller.com/Home.html

Wednesday, September 26, 2007

Tip: Emacs and Vim Suck; JOE to the rescue!

Being a software architect and developer at RedPine Services, I often find myself working from the command line for a variety of purposes and on a variety of hardware. Unfortunately, I find the standard compliment of command line text editors to be lackluster.

I've found that most systems come bundled with three major editors: Emacs, Vi/Vim, and Pico. Although I use vim as my primary editor, I wish I didn't have to. All thee of these editors have major drawbacks:

  • Emacs is very large, complex, and cumbersome. Sure, it is very powerful, but it takes a lot of time and a good memory to learn all the unnecissarily long, funky key combinations, and until you've learned them, using Emacs from the CLI is impossible. This kills its approachability and leads me to wonder how it ever gained popularity in the first place.
  • Vi/Vim is also very powerful, but its unique and strange input mode vs. command mode paradigm makes it hard to pick-up, and its non-standard key commands make it difficult to learn as well.
  • Pico is sort of the opposite. It is very easy to pick-up and learn, with the most important key commands being shown as help right on the screen. This is very helpful for any novice, as you don't have to go fishing for the key command to bring up help or to save or to quit like you do with Emacs and Vim. The downside, though, is that Pico was made for e-mail composition purposes (being the bundled text editor for PINE) and thus lacks many features (and wraps and destroys your carefully made code and config files if you don't provide the right option on the command line!)

Now I admit that I use Vim in my everyday life because it is on all the systems and servers I have to work with in my professional career, and because Emacs is the complete opposite of what I value in a text editor. But no matter how much I use it, I can't shake my wish that people would always bundle the text editor that I used in my younger years: JOE.

I came across JOE as a teenager when my family first signed up for internet access with the ISP Sonic.net. It has much of the simplicity and accessibility as Pico, while having most of the power features people actually want.

The key to JOE is its accessibility. When you first open it, you are presented with a screen that is intuitive to use and navigate, and which has a prominent message displaying how to get to the inline help screens, which can be toggled on and off at any time during use.

Thus you can just jump right in and go with JOE!

Then, as you use JOE more and more, you can start moving deeper and deeper into the help screens to learn how to use functionality such as buffers and simultaneous multi-buffer display.

I recommend that everyone that programs, who is unhappy with emacs and vim, give joe a look. It is easily downloaded, compiled, and install with the standard ./configure && make && sudo make install routine on Linux and Mac OS X.

Check-out JOE on SourceForge to get your copy now.