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:

mplayer – capturing screenshots

July 11th, 2007 Dante Regis 3 comments

Sometimes, you will want to save a picture of a movie scene. Say, you are watching a screencast, and want to save a picture of the piece of code on screen now. You then find out that PrintScreen has no use for videos. Or you may be watching a fast scene, with lot’s of information and you would like to see each frame carefully.

You can save each frame of a video to a series of PNG or JPEG files using mplayer. It’s quite simple.

First, create a directory for the pngs to be saved on. Say, /home/<you>/pngs

Get into that directory

type this command:
mplayer -vo png -ss 00:02:37 -endpos 67 /path/to/movie.avi

The -ss and -endpos parameters tell mplayer where to start playing inside a movie, and when to stop. you see, it’s quite unlikely you would want to convert an ENTIRE screencast to png. So, just take a note of the time the scene shows up (2 minutes and 37 seconds after start of movie on my example) and how long do you want to record (67 seconds for me). Every frame on this interval will be saved to 0000001.png, 0000002.png on your current folder.

Hope this helps someone.

Best

Powered by ScribeFire.

Categories: Uncategorized Tags:

Browser autocompletion – how to delete specific item

June 30th, 2007 Dante Regis 1 comment

Well, I have to share this one:

It’s damn simple, so of course I couldn’t find it. It was my girlfriend, Lívia, who doesn’t use computers more than the strictly necessary. She was on a Cyber Cafe and had to type her CPF (Something like USA Social Security Number) on a form. Then she found that her number was saved on the autocompletion “feature” of IE. She did the first thing she thought of: select the number and pressed DELETE. Yes, delete on the keyboard, or DEL in some.

Just too simple for someone who works with computers find out. I was wondering things like check the registry or clear all items through the Options Dialog. But no. Just press DELETE.

Thanks, Livia! :)

Powered by ScribeFire.

Categories: Uncategorized Tags:

Trasform Gedit in Textmate to develop in Ruby/Rails

June 26th, 2007 Dante Regis No comments

This guy has made a fine selection of plugins for gedit (yes, gedit) to make it look like TextMate, the dream of every Rails developer not working on a Mac. So, take a look. I have installed everything and will try out today.

read more | digg story

Categories: Uncategorized Tags:

Measuring Password Strength

June 11th, 2007 Dante Regis 1 comment

Everyone who build software (like me) hates this, but every system is going to be used by people. By humans. So, we have to deal with the human factor. I came upon Phira’s Blog, where phiras presents us with a great algorithm to measure password strength. He gives points to certains characteristics of the password. Here’s the link. Worth a look.

Categories: Uncategorized Tags:

Send GMail messages using VIM

June 11th, 2007 Dante Regis No comments

OK, no flame wars, please, but fact is: I like VIM. So, I wanted one of these days, to send e-mails through it, since I read on Richard Stallman’s website that he uses e-macs to read and send e-mails. Well, can’t vim do that?

In fact it can. But I don’t use normal e-mail providers, so no POP3 or IMAP for me (you can use this plugin if you have a SMTP, IMAP/POP3 account).

For GMail, I came upon this wonderfull piece of code on DJCraven blog. It allows me to send the content of the current buffer as an e-mail to the person you specify on the GMSend vim command. The first line is treated as the Subject. So, you type your message, :GMSend someone@somewhere.com and voilá!

That’s what the e-mail was ment to be!

Powered by ScribeFire.

Categories: Uncategorized Tags:

howto use rtorrent to download torrents

June 5th, 2007 Dante Regis 1 comment

So, you are on our lovely (GNU/)Linux OS right? And, you, being a smart guy (or girl), uses the best ever made torrent client: Azureus, right? Well, I was just like you, untill I found (well, I didn’t find it, actually, I was told of it’s existence on a  web-forum…) RTORRENT!

I don’t know why, but I like to keep things light. rtorrent is just that: a bit torrent client that runs on the command line. But it’s not like a wget, that you run, and watch the output. It is ncurses bases, so you will have a user interface, just not graphic. On Ubuntu, it is on the repositories, so you can apt-get install rtorrent and you’re ready to go!

Here are some tips on how to use it:

First of all, you WILL, some time, want to exit rtorrent. Don’t try vi-style here. To exit, just type CTRL + Q. Simple right?

Opening a torrent for download:

  1. type “rtorrent  my_torrent_file.torrent” if you are not already inside the app OR
  2. type ENTER on the main interface to  get the open “dialog”: it has TAB completion, so you don’t have to remember the hole path.

Starting the Download

  • If you openned the torrent using the first option, it will start STOPPED. To start it, select it using your keyboard arrows. A few asterisks will be shown to indicate wich torrent is currently selected.  Type Ctrl+S to start the download.

Information about the download:

  • You can see more detailed info about each running torrent by selecting it (with the up and down arrows) and pressing the RIGHT arrow. It will show you a new screen, where you can, again, use the arrows to move. To return to the main screen, just keep pressing the LEFT arrow till you are there.

These are some basic usage tips. If you want to became the rtorrent guru (I just want to download a few files), I suggest you visit this website, a great blog from K Mandla, where I learned these things I’m passing to you. Or you can go straight to the RTorrent user guide.

Categories: howto Tags: