Archive

Archive for the ‘ruby’ Category

autotest keeps running continuosly even without changing any files?

December 21st, 2007 Dante Regis No comments

So, your autotest also keeps running over and over when your Rails code fails? Well, I had this issue here and found that the problem was that, when the tests were run, Ferret updated the index. So, autotest believed that files where changed when they weren’t. Googling a bit I found this code that you should put on your ~/.autotest :

Autotest.add_hook :run do |at|
  at.exceptions = /^(?:\.\/)?(?:db|index|doc|log|public|script|tmp|filestore|vendor\/rails)|\.svn|(?:.*_flymake\.rb$)/
end

If it does not work, try running autotest with “-v” option, to see which files have changed on autotest concern, and include the relevant directory on the list above.

Hope this helps you! :)

Categories: rails, ruby Tags:

Console input on Ruby: Masking passwords on the command line

November 19th, 2007 Dante Regis 2 comments

I like plain old console applications. They are fast (to program, compile and use) and, of course, add a cool factor, like people saying they have absolutely no idea of what you are doing!

Ruby, of course, can do console apps, but it’s not trivial to read user input. And what if you want the user to type a password? You would like, of course, to show them asteriks ‘*’ or nothing at all instead of the plain text being typed.

Well, “highline” gem covers this and much more. What about writing:

ask("Enter your password:  " ) { |q| q.echo = "x" }

And that’s all! That’s quite cool, man. It can even check if the answer matches some regex, or split it by commas, or anything you want
Take a look at it: http://highline.rubyforge.org/

Categories: programming, ruby Tags:

Getting notifications of autotest results on Linux (Gnome)

August 22nd, 2007 Dante Regis 4 comments

If you watched the PeepCode episode about RSpec (the first of the trilogy), you may want something like growl on linux to get informed about the results of autotest. Well, there is such thing, but it is quite complicated.

You can use libnotify on Gnome, though. Those little alerts Ubuntu shows you (3 new updates, It’s time to restart your computer, Connected to Wireless Network etc), all uses libnotify. Let’s move on!

1) Install the libnotify-bin package via apt-get

2) Go to a terminal and type, remembering to change ZenTest-3.6.0 to your current version.

sudo gedit /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest/gnomenotify.rb

3) Paste the following on the new file

# -*- ruby -*-
# Adapted from PeepCode RSpec screencast no 1,
# who got it from someone else!
# Adapted with tip from http://ph7spot.com/articles/getting_started_with_autotest
# by DitoCujo (http://ditoinfo.wordpress.com)
module Autotest::GnomeNotify
  EXPIRATION_IN_SECONDS = 5
  ERROR_ICON = "gtk-dialog-error"
  SUCCESS_ICON = "gtk-dialog-info"
  def self.notify(title, msg, icon)
    options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{icon}"
    system "notify-send #{options} '#{title}' '#{msg}'"
  end
  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
    if output
      if $~[2].to_i > 0
        notify "FAIL", "#{output}", ERROR_ICON
      else
        notify "Success!", "#{output}", SUCCESS_ICON
      end
    end
  end
end

4) Now save the file and open your .autotest file (/home/_____/.autotest – Create one if it does not exist) and require the file you just created by placing this line on the top:

require ‘autotest/gnomenotify’

Done! You should now get beautiful notifications on your screen like this one here

Gnome Notify for Autotest

Categories: ruby Tags:

Formatting dates nicely in Rails

August 16th, 2007 Dante Regis No comments

I always thought those “today”, “yesterday”, “4 days ago” date references on some websites way cool. On a small system I’m working on I did some code to do something alike, though in portuguese. But if you want it in english, there’s a small plugin called relative_time_helpers that you can install by typing:

 script/plugin install http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/

Then, you can do things like

<%= relative_time(Time.now) %>
# today

<%= relative_time(1.day.ago) %><
# yesterday

<%= relative_time(1.day.from_now) %>
# tomorrow

<%= relative_time_span([Time.now, 5.days.from_now]) %># May 17th - 22nd

This tip was taken from Active Reload Blog!

Categories: programming, rails, ruby Tags:

ruby on rails reference cheat sheet

March 7th, 2007 Dante Regis No comments

This website has an excelent Ruby on Rails resource for those in need (like most of us). It features lot’s of command line options, code snippets, and stuff like that. Very handfull! This is the link to the blog entry, and this one points to the text itself. Take a look!

Categories: programming, rails, ruby Tags:

ruby on rails ide comparison

March 7th, 2007 Dante Regis No comments

Sébastien from The Nameless One, did a very impressive job comparing three of the main Ruby on Rails IDE avaiable. His extensive post includes a feature chart with each IDE’s most important features side-by-side, using colors to show how good or bad implemented that feature is on a particular IDE. It’s more than worth looking, and the link is here.

BTW, I’ll stay with Netbeans Development Edition. Even being unstable (I believe it’s not even Alpha yet) it’s quite usable, and I’m doing most of my work on it. Just missing a few test features. But that should come on the next milestones!

Thanks Sébastien, for the great job!

Categories: netbeans, programming, rails, ruby Tags:

how to install ruby on rails and lighttpd on ubuntu

March 6th, 2007 Dante Regis 4 comments

Hey folks. It’s interesting how difficult it was for me to get Rails up and running on Lighttpd. I’ve tried lot’s and lot’s of tutorials, but none of them seemed fit to me. I came up with this solution, wich is actually a merge of lot’s tips. Feel free to contribute, and I hope that this helps you out.

1) First, include UNIVERSE on your sources.list. It is located on /etc/apt/sources.list. If you are unsure, take a look at this web-site. It may help you out. Remember to sudo, or be root to do everything Read more…

Categories: howto, rails, ruby, ubuntu Tags:

netbeans and UTF8 encoding

February 26th, 2007 Dante Regis 11 comments

[digg=http://www.digg.com/programming/Netbeans_and_UTF8_encoding]
When I started using Netbeans as my Ruby on Rails IDE, I noticed that, at least on my build, it did not use UTF 8 on files by default. If you speak english that usually is not a problem, but for me, who write software in portuguese, it is very important.
But, Mr. Google gave me a tip, and I’ll place it here so you don’t have to bother him again with this same question.
Theres a file, inside the /etc folder of netbeans directory, called netbeans.conf. I don’t know if it stays elsewhere in Linux, I’ll only know later today, but anyway, you should place this option inside the quotes of netbeans_default_options:
-J-Dfile.encoding=UTF-8
That’s it. Worked perfectly for me.
Best

Categories: netbeans, programming, rails, ruby Tags: