Allan & Steve are the chubby founders of LessEverything. This is their blog, hear them rant, praise, give advice and talk about Just Stuff, Less Accounting, Lovd by Less, More Honey, Less Memories, Code, Business, Design, Marketing
Chat with Us
September 27th, 2007

Rails RESTful Url Guide

written by Steven Bristol

Erine Prabhakar just put up a short guide to RESTful url formats in Rails. Anyone just getting into RESTful Rails, and that should be all of you not currently doing RESTful Rails, might enjoy this overview.

September 26th, 2007

Installing ImageMagick and RMagick on Mac OS X

written by Steven Bristol

I have found a new way of doing this that is so good I can’t believe I haven’t heard about this before. It turns out, there is a one click (command) installer for ImageMagick and RMagick and nobody is talking about it. If you go to the RMagick home page and look though the FAQ you will see the first choice is to use the installer script. Choices two and three both revolve around Ports, so we can all ignore those from now on.

Here is how to do it:

  1. If you already have ports installed with a version of ImageMagick, but not RMagick, you may have to remove the opt entries from your ~/.bash_profile or ~/.bash_login file.
  2. Go here and download the “rmagick-osx-installer.”
  3. You probably already have XCode installed, but do you have the X11 SDK installed? Probably not, because it is not installed by default.
    1. Go back to the XCode installer, either the one you downloaded or the one on the Mac OS X install disk.
    2. Rerun the installer, but this time when you are on the “Choose your installation type” (or something) screen of the install wizard, click the little “Customize” button on the lower left. I know, I missed it too the first time through.
    3. Make sure X11 SDK is select in one of the sub-folders (I can’t recall which one).
  4. UPDATE: Ignore this step if you are on Leopard. Make sure you have X11 also installed. Yes, this is different from the SDK. This page will tell you how easy it is to do that.
  5. Did the “rmagick-osx-installer” finish downloading and automatically unzip to a folder on your desktop called “rm_install-1.0.2 Folder?”
  6. Using (i)Term navigate to that folder and run: “ruby rm_install.rb”
  7. Did you get an error that says something like “The installation directory ‘xxx’ contains blanks. Some of the install scripts for the dependent libraries can’t handle directory names with embedded blanks. Please choose another directory.”
  8. I think this is probably the biggest reason why this installer is not more popular, I had no idea what this error meant. I had to look in the source code to figure out that the path to the rm_install.rb is not allowed to contain spaces (blanks). Then why did it unzip to a folder whose name has a space in it?
  9. OK, cd ../ && mv rm_install-1.0.2\ Folder rm_install-1.0.2 && cd – (Or: rename the directory so it has no spaces.)
  10. Run the installer again and it should automagickally install RMagick, ImageMagick, and all dependencies.

Now I know what you are thinking, “Steve, if you’re installing RMagick did you get a brand new computer?!” And the answer is sorrowfully no. But what I did have is my SECOND hard drive failure in six weeks. That means that this is my third hard drive on a computer that is less than one year old. And I am excited because I am sure I will have to reinstall all of my gems (including RMagick) and ImageMagick next month when Leopard comes out. Happy, happy, joy, joy. But at least I finally found the right way to do it!

September 14th, 2007

Regex Sensei is Here!

written by Steven Bristol

Chris has finally started his series on Regex.

September 7th, 2007

Please Read This Post In It's Entirety Before You Send Me Your Resume

written by Steven Bristol

A few days ago I posted an ad to hire a few more excellent “the Guys.”

Please notice I specifically state:

Please do not apply if:

1. You are compelled to send a resume.

Amazingly people keep sending me resumes. Let me ask you all a question: If someone can’t even follow that simple instruction, how in the world would they expect me to trust them with my code?

P.S. Allan suggested I post their resumes here, but I resisted.

August 30th, 2007

Hackilious

written by Steven Bristol

This is a righteous hack:

http://larrytheliquid.com/2007/03/18/validating-positive-with-infinity/

Until you realize that there is a hard limit to number size in the database. That attribute is stored in a particular number of bytes. And this hack does not take that into consideration.

So then you look in the database to see how many bytes make up the column and you start thinking that maybe this is the wrong direction? You’re not checking maximum number values anywhere else (except string lengths). So then you consider that maybe that is why rails makes an integer column 11 bytes by default, that is a really big number.

So then you start writing something like this (because you really need to make sure it is a positive number):

def validate
  errors.add(:price, 'must be positive') if self.price < 0
end

And then you think, maybe I should just use the hack….....

P.S. Consider your self a hard core hacker if at any time while readying this post you found yourself thinking “One man’s brilliant hack is another man’s language feature.” ;)
P.P.S. If you don’t know what the P.S. means, you should immediately start reading 2600 and go back and enjoy the original episodes of The Broken (wasn’t Kevin Rose a cute kid?)

August 28th, 2007

John Resig Talks About Building a (Javascript) API

written by Steven Bristol

Here is John Resig, the creator of jQuery, giving a talk about how to build an API (specifically a Javascript API).

Besides being a really good talk it is nice to see our hero in action! Check it out, even if you only watch a few minutes, you will get to see the man who has brought us so much joy.

August 23rd, 2007

TextMate Tip of the Day

written by Steven Bristol

My friend and jQuery Core team member, Yehuda Katz, brings us a great TextMate helper today. Basically Henrik Nye made a grep in projects command for TextMate. Really awesome. Then Yehuda took that and modified it to do a grep in directory. Super awesome.

Here’s how to make it work:
  1. Go to Yehuda’s blog post and download the TextMate Bundle (the link is at the end of the post).
  2. Double click it from the desktop.
  3. Which should open TextMate’s Bundle Editor.
  4. Feel free to reassign the keystroke (I chose ↑⌘D so I can keep the standard Find/Replace in Project).
  5. Open a project.
  6. Select a directory.
  7. Invoke the keystroke (↑⌘F by default).
  8. Send Yehuda and Henrik a note of thanks.
August 16th, 2007

Apache not starting on boot OS X? Here's how to fix:

written by Steven Bristol

#>sudo vi /etc/hostconfig

(or your favorite editor)

Should look something like this:

AUTHSERVER=-NO-
AUTOMOUNT=-YES-
CUPS=-AUTOMATIC-
NFSLOCKS=-AUTOMATIC-
NISDOMAIN=-NO-
TIMESYNC=-YES-
QTSSERVER=-NO-
WEBSERVER=-NO-
SMBSERVER=-NO-
SNMPSERVER=-NO-
SPOTLIGHT=-YES-
ARDAGENT=-YES-
CRASHREPORTER=-YES-
MYSQLCOM=-YES-

Change the line

WEBSERVER=-NO-

to

WEBSERVER=-YES-
August 15th, 2007

Install ImageMagick & RMagick on Mac OS X

written by Steven Bristol

  1. Install mac ports
  2. sudo port install imagemagick
  3. sudo port install rb-rmagick
July 18th, 2007

Rails help

written by Steven Bristol

We posted an advert for some rails help for a project we have coming up. Here is what we are looking for:

Title:

Do you wash your hands after visiting the restroom?

Description:

We have a significant rails project starting in August and are need some experienced help.

Two positions available.

You must wash your hands before touching the code.

Skills:

  • Javascript (for UI)
  • Restful Rails (for your health)
  • MySQL (database)
  • Linux (sudo required)
  • OS X (windows advocates need not apply)
  • Capistrano (to come home to)
  • Coffee (to drink)
  • Jokes (to tell)
  • TextMate (for everything else)
  • Allan says “svn up, biatch.”

Personality is as important as technical skills.

June 26th, 2007

Today's Textmate Tip

written by Steven Bristol

Here is a snippet all of you jQuery on Rails people can use:

Here’s how to make a snippet that will output:


jq(function(){

})
# Control-Option-Command-b to open the Bundle Editor. # Go to either the HTML or Javascript bundle (or jQuery bundle (you did know there was a jQuery bundle right?)). # Click on the Plus at the bottom left of the editor to create a new snippet. # Name the snippet “jq” or something. # Paste the following in the Editor window and close the window.

jq(function(){
  $1
})

Now you can jq->tab to get the snippet.

In an rhtml file the cool [obtrusive javascript] kids go: script->tab->jq->tab ;)

June 25th, 2007

Today's TextMate Tip

written by Steven Bristol

Option-Command-.

Insert closing tag.

In the HTML bundle.

Now, does anybody know how to view/find/highlight the matching tag from the one I’m on? So if the html is this:


<div>
<a href="#">blah</a>
</div>

And your cursor is on the closing div, the opening div would flash, change color or something.

June 24th, 2007

Setting up ImageMagick & rmagick on Redhat (CentOS)

written by Steven Bristol

  1. sudo yum install libjpeg-devel libpng-devel glib2-devel fontconfig-devel zlib-devel libwmf-devel freetype-devel libtiff-devel
  2. wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.3.2-9.tar.gz
  3. tar zxzvf ImageMagick-6.3.2-9.tar.gz
  4. cd ImageMagick-6.3.2-9
  5. ./configure
  6. make
  7. sudo make install
  8. sudo gem install rmagick
June 21st, 2007

Steve's Array Cheatsheet for JavaScript & Ruby

written by Steven Bristol

JavaScript

array.push(thing to push)

Ruby

array << thing to push

Notes

  1. Although Array#push works in ruby, array#<< does not work in javascript.

(I just spent 45 minutes debugging this ;)

June 6th, 2007

Paypal on Rails...ActiveMerchant tips

written by Steven Bristol

Anyone who has looked into using ActiveMerchant and PayPal together knows it is quite a challenge. ActiveMerchant is great, but there is no documentation for using it with Paypal. Here are some tips to help you get it working:

Here is a page with some good references.

Setting up Paypal

The paypal website is a bit tough to navigate and they don’t make it obvious to figure out what are all the things you need to do to get it all setup.

  1. You will need a sandbox (developer) paypal account to test your set up. Sign up here
  2. The sandbox does not send emails, so you will have to use the Sandbox Email Tab to validate your sandbox account email address.
  3. Launch the sandbox
  4. Create a sandbox business account. and go through the normal paypal verification stuff. (It does not use your real bank account.)
  5. Go to the Merchant Services tab and signup for a Website Payments Pro Account.
  6. Verify your merchant account. You will be asked to enter you SSN number, use 111 + six random numbers. If you get an error message, try a different six numbers, the fake ssn must be unique in the sand box.
  7. Under the My Account tab and the Profile subtab and the Billing Agreements link, make sure you accept the Agreement.
  8. Same for the PayPal Monthly Billing link.
  9. Follow these instructions to create your API Certificate. Do not make the API Signature. You only need to do the “Step 1. Generate Certificate” part.
  10. Make sure you save the username & password given and download and save the pem file.

Paypal should now be set up. You will have to go through and do all the same stuff for your real paypal account, once your development is done and working.

Setting up ActiveMerchant

  1. Install ActiveMerchant by following the instructions, you will need to install the money gem, which ActiveMerchant requires.
  2. Rename the pem file to cert_key_pem_dev.txt and put it in your config dir.
  3. Add the following code to your environments/development.rb:
  4. 
    config.after_initialize do
      ActiveMerchant::Billing::Base.gateway_mode = :test
      ActiveMerchant::Billing::PaypalGateway.pem_file = File.read(RAILS_ROOT + '/config/cert_key_pem_dev.txt')
    end
    $PAYPAL_LOGIN = ''
    $PAYPAL_PASSWORD = ''
    
  5. Use the actual username and password in the previous code (don’t use the empty strings :)
  6. Do the same for the environments/test.rb
  7. Do the same for the environments/production.rb, except remove the line: ActiveMerchant::Billing::Base.gateway_mode = :test and use the cert_key_pem_prod.txt file (which you can get through your real paypal account (renaming to cert_key_pem_prod.txt ).
  8. Do something like this in your code:
  9. 
    
    amount = 1000 #$10.00
    credit_card = ActiveMerchant::Billing::CreditCard.new(
        :type       => 'visa',
        :number     => '4242424242424242',
        :month      => 8,
        :year       => 2009,
        :first_name => 'Bob',
        :last_name  => 'Bobsen',
        :verification_value=> '123'
    )
    
    flash[:error] = credit_card.errors and return unless credit_card.valid?
    
    billing_address = { 
        :name     => "John Smith",
        :address1 => '123 First St.',
        :address2 => '',
        :city     => 'Los Angeles',
        :state    => 'CA',
        :country  => 'US',
        :zip      => '90068',
        :phone    => '310-555-1234'
    }
    
    gateway = ActiveMerchant::Billing::PaypalGateway.new(:login=>$PAYPAL_LOGIN, :password=>$PAYPAL_PASSWORD)
    
    res = gateway.authorize(amount, credit_card, :ip=>request.remote_ip, :billing_address=>billing_address)
    
    if res.success?
        gateway.capture(amount, res.authorization)
        flash[:notice] = "Authorized" 
        redirect_to somewhere_url
    else
        flash[:error] = "Failure: " + res.message.to_s
    end
    
  10. Make sure State and Country are two character code.
  11. The credit card errors is actually a hash, not an array (like AR.errors), so you will need a helper to display the error.

Last Tip

  1. When testing with paypal, you must use port 80: ./script/server -p 80