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
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.
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:
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!
Chris has finally started his series on Regex.
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.
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?)
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.
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:#>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-
We posted an advert for some rails help for a project we have coming up. Here is what we are looking for:
Do you wash your hands after visiting the restroom?
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.
Personality is as important as technical skills.
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 ;)
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.
array.push(thing to push)
array << thing to push
(I just spent 45 minutes debugging this ;)
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.
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.
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.
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 = ''
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