BrunoMiranda.com

Personal Blog about Software Engineering, Design, Travel & More

I’ve been looking for a way to limit the number of options under minute on timeselect and datetimeselect. You can set the :minute_step to 15 which will give you: 00, 15, 30 and 45.

<%= datetime_select 'game', 'game_date_time', {:minute_step => 15} %>

Hope that helps!

If you need to display a a float/string formatted as money (with two decimal points), simply add a helper method to your application_helper.rb.

module ApplicationHelper
  def two_dec(n)
    sprintf("%.2f", n)
  end
end

Now every time you need to display you value, just pass it into the two_dec method.

  $<%= two_dec(@repair.cost) %>

Will produce: $150.00.

I couldn’t count how many times per day I have to reference the Rails API. RailsBrain makes it easy to quickly find what you are looking for.

If you are not yet using source control for your projects you ought to. Subversion is by far my favorite one. Below you will find easy to follow instructions on how to add your project to a subversion source repository.

Create a folder called temp, browse into temp and create your rails application. You will also create tags, branches and trunk folders:

mkdir temp
cd temp
mkdir trunk
mkdir tags
mkdir branches
cd trunk
rails my_app

Now you have to exclude a couple of files from the repository like the files inside tmp/ and log/ as well as the database.yml file.

rm -r log/*
rm -r tmp/* 
mv config/database.yml config/database_example.yml

Your local app is ready to be imported into your subversion repository. Browse to your temp folder and run the import command.

svn import . http://path/to/your/repos/my_app -m "Initial Import"

You have successfully created a subversion repository on the server, now you need to checkout a copy onto you local computer so that you can start working with it.

svn co http://path/to/your/repos/my_app/trunk

You must create a config/database.yml and that is easily accomplished by making a copy of config/database_example.yml. You will also need to tell subversion to ignore that file as well as any new files inside tmp/ and log/.

cp config/database_example.yml config/database.yml
svn propset svn:ignore database.yml config/
svn propset svn:ignore "*" tmp/
svn propset svn:ignore "*" log/

Almost done. All that’s left to do is to commit the above changes.

svn ci -m "Ignoring files."

You are done, just remember that you must add new files to your repository when you create them on your local machine using:

svn add filename.ext
svn ci filename.ext -m "Committing new file."

For more advanced techniques using subversion make sure to check out the free online Subversion Book.

If you are wondering about a great source for learning Ruby on Rails and have not yet heard of PeepCodes, look no further.

PeepCodes are instructional screen casts of Ruby on Rails techniques recorded by Geoffrey Grosenbach from topfunky. They are generally 60-90 minutes long and contain an immense amount of useful information for $9 a piece.

With your purchase will receive the source code, video and any cheat sheets that may be included.

Now get to work and start peeping

Have you ever wondered how to quickly implement captcha functionality?

Captchator is a hosted free service that lets you embed an image tag on your site. You then submit the session id and the user input which is verified and the result is returned to you. You can use the result to either allow or disallow the user to continue on.

  1. Display the captcha image on your website.

  2. Create or modify an existing form with a text field to send the captcha answer to your script.

  3. Your script needs to check the submitted captcha answer for correctness. To do so, it loads the following URL from the Captchator server: http://captchator.com/captcha/check_answer/$yoursessionid/$answer

  4. If the answer is correct, the result is “1”, if not, it is “0”.

And you are done.

For more information visit Captchator.com

Comments: 0 (view/add your own) Tags: (none)

Posted on May 24, 2007 at 07:15 PM

If you use Textmate, you know that it automatically rescans every folder inside an open project to see if anything has changed.

If you have a folder with an extensive number of images for example, you can prevent Textmate from scanning and searching within that folder by right clicking on the folder and deleting the reference.

Please note, this folder will no longer be included in project searches. In order to save this settings you will have to click on File and Save Project As.

I am glad to finally be home and back at work. Railsconf was great. I met up with a lots of friends, and met many new ones. Times like these remind me how nice it is to be part of such tight community.

The sessions where mostly good. I have to say some could’ve been better. The BOF (birds of a feather) sessions where great. There, I got to talk to the people behind, JRuby, JQuery and even NetBeans.

If you were not able to make it this year. Start thinking about next year’s now. Start saving and reserve the time. You will not regret.

If you’ve ever wondered how you can access an XMLRPC resource using ruby, the code below displays how to do it.

The snippet returns a hash containing information corresponding to the UPC code we performed the lookup on.

require 'xmlrpc/client'
server = XMLRPC::Client.new2('http://www.upcdatabase.com/rpc')
@resp = server.call('lookupUPC', '099482409463')
puts @resp['description']
puts @resp['upc']

The return value from the above will be:

  • Whole Foods Market 365 Italian Still Mineral Water
  • 099482409463

Visit the Archives →