Sunday, January 30, 2011

Error Installing Phusion Passenger on OSX Leopard - Ruby 1.9.2

As I began to play more and more with RoR on my mac today I decided to do a few things.

  • Install Ruby 1.9.2
  • Install Phusion Passenger

By default Snow Leopard has Ruby 1.8.7 installed but I wanted to begin using the latest 1.9.2, so with a little help from Pragmatic Studio I got it done. For more read - http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac.

Shortly after that I decided to install passenger so I can deploy apps on Apache an by using their instructions I kept getting the following error:

/Library/Ruby/Site/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)

Basically the steps where as follows:

  • sudo gem install passenger
  • sudo passenger-install-apache2-module

The problem was due to me trying to install on the 1.9.2 build which I installed and manage using rvm and for that you need to do the following:

  • rvmsudo passenger-install-apache2-module

I can't take full credit as I found the answer here: Article on stackoverflow

Up next - applying changes to my httpd.conf and seeing if it works :-)

Wednesday, January 26, 2011

SSL on Apache

Today I needed to install an SSL certificate on my local test machine (Mac/Apache) and it was my first time ever. I've been an IIS guy way too long and I love to develop on my Mac without having to bring up a Virtual Machine and little by little pulling away from my local dev server (the only windows box in my house after the switch back in 2003). BTW, the box will soon be a Mac Mini server as I am tired of that Dell Jet Engine in my living room.

Anyways, with a little help from Google I came up with this entry at O'Reilly's onLamp.com.

http://onlamp.com/pub/a/onlamp/2008/03/04/step-by-step-configuring-ssl-under-apache.html

With that and comparing my local httpd-ssl.conf to my user.conf file I was able to do effortlessly.

The reason I had to do a compare was because I didn't read the comments and the first comment spoke about the error I had which I figured out myself by copying over the local config.


Coldbox Plugin - FormatUtils - useful UDF's by me and others (some inspired by RoR)

Over the years, I have used and created many UDF's in my applications. So when I decided to start using ColdBox, I wanted to start grouping them into plugins. One of the first ones, is my FormatUtils Plugin that has several functions that allow you to work with strings. Below is a list of functions included, credits and what they return.

Before we begin let's assume we assigned the Plugin to rc.FormatUtils in our handler as follows:

  • brFormat(theString)
    Converts every carriage return and/or line feed into a compliant line break <br />

    Example
    Will return:
    Hello World<br />How Are You?
  • pFormat(theString)
    Creates compliant paragraphs and line breaks from carriage returns and/or line feeds, I created this because ColdFusion's built-in paragraphFormat() does not close out paragraphs.

    Example
    Will return:
    <p>Hello World</p></p>How Are You?<br />I am good</p>
  • formatPhone(phone,mask)
    Original Author: Derrick Rapley
    This I grabbed from cflib.org and it has come pretty handy. Basically you can pass a string and a mask and it will return it back in the format you requested.

    Example
    Will return:
    Line 1: (305) 555-1234
    Line 2: 3055551234
  • abbreviate(string,len,append)
    Original Author: Gyrus
    Also from cflib.org and it has come pretty handy. Basically you can pass a string a length and it will truncated to your specified lenght without breaking a word.

    Example
    Will return:
    Line 1: A string like this can go ...
    Line 2: A string like this can go fo
  • urlCrypt(mode,string,closer,key)
    This one I actually have to thank my local CFUG for. In one of our little quizes we use to do before the meeting, a question was asked how to encrypt a string that can be safely passed as a URL and the answer was 2 undocummented functions cfusion_encrypt and cfusion_decrypt. I also saw another way using a mixture of toBase64() and toBinary() in case these functions would no longer work (the alternate method is commented out).

    Example
    Will return:
    Line 1: 1911204E0D130415540F001C6B081C4D10364E241B081E17081D0224453E02142014CB3
    Line 2: the name for me is Giancarlo Gomez
  • pluralize() - singularize() and $singularizeOrPluralize
    The credit to this one goes to 2 other frameworks. The first is of course Ruby on Rails. I went to a presentation to learn more about this language and I fell in love. A simple function called pluralize was introduced to me and I though it was great. Basically pass it a word and a number and get back the plural version of it. So at first I wanted to create it from scratch but I decided to do a little bith of research and found out CF Wheels already had almost the equivalent, so I started from there. The only thing I added which they did not have is for an alternate plural or singular word if one was not found in the predefined rules.

    Example
    Will return:
    20 houses

To close out you should know that it is not necessary to have Coldbox to use this, simply use the CFC as any other and you can take advantage of all these functions.

I created a new git repo where I will begin to add all my code to share. Click on the following link to see this CFC on gitHub:
FormatUtils.cfc on gitHub