Archive

Archive for August, 2007

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:

How to tell which Linux distro you are using?

August 21st, 2007 Dante Regis 2 comments

If you ever managed more than a few Linux servers, you may have found yourself in a situation where you don’t know which distro a particular server is using. I used to cat /proc/version to get a rough idea. But a friend of mine from work just gave me this tip:


cat /etc/issue

Simple, easy and objective!

Hope this help you out!

Categories: linux Tags:

New layout

August 16th, 2007 Dante Regis 2 comments

I’m starting to like this new layout. I believe it to be much more beautiful than the previous one. You should be proud of yourself of being part a small club of people who read this article. If you really want ( ;) ), you can leave a comment here and tell what’d you think.

Categories: Uncategorized 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: