[Script] SSH connect shortcut

Par défaut

With dozens of ssh connections each days, you better need a shortcut way to make it faster. Frustation comes to a end with this script:

Put this ruby script in your bin directory, make it executable, add your servers info hash in the array, and eventually copy your ssh public key in the various servers to never be asked for password.

When executing it, you can give it the ‘id‘ as an argument, and it will connect automatically to the server with the corresponding id!

[Jabber] Delicious Bot

Par défaut

Because when I see a good link, my main pleasure is to send it to as many friends as possible on IM, here is a simple jabber bot I could use to also save these links to my delicious account:

Download from github.com

It uses jabber-bot and rdelicious gem for ruby, you just need to configure the config.yml with your jabber and delicious login information and maje it run with:

ruby delicious-bot.rb

The bot will connect to the master jabber you’ve configured in the config.yml, and you just need to send him the bookmark command:

bookmark url description

You can add your commands easily inside the bot, and fork the project from Github.com:

Delicious-bot project on github.com

[Ruby] Behaviour Driven Development with RSpec

Par défaut

During the rewritting of Feevy.com with Merb, I’m discovering RSpec, a framework to be sure your code behave nicely.

Follow and join Feevy rewrite on Gitorious

Instead of normal test-units, you describe how your app/model should behave, which give a more-human conversation when you read your test:

  it "should create a feed from website http://blog.feevy.com" do

    feed = Feed.new :website => "http://blog.feevy.com"

    feed.valid?(:save).should == true

    feed.link.should == "http://blog.feevy.com/feed/"
    feed.website.should == "http://blog.feevy.com"
    feed.title.should == "Feevy Blog"

  end

To re-initialize your database between each test:

  before(:each) do
      Feed.delete_all
  end

Next step: writing Feevy stories

[Ruby] TwittLine

Par défaut

There’s always a nice thing to do during insomnia: close all the open ideas you’ve got in mind!

So I wanted to have something working about yesterday Twitter Timezone idea, here is the result after using Twitter4R and Sparklines gems:

TwittLine

The sparkline is only created from my friends last 20 twitts. With so few samples, we can’t really see any ‘timezone‘ effect, but some social behaviors appear:

  • Rush hours: some people twitts mostly during the evening;
  • Exclusives: others have only one or two big peaks, it would mean most of their 20 twitts were written in the same period of the day;
  • Flat twitting: twitts seems equally reparted all along the day.

This experience might be extend in the next days, opening it more to public test, and it’s still looking for your suggestions to improve by itself.

[Ruby] rFeedReader 1.0

Par défaut

rFeedReader is finally ready for its first major release. After a lot of bugs correction, and a big testing cleaning today thank to Pere‘s Google Reader OPML, 99% of feeds should be readable now.

rFeedReader is a feed parser to read feed and return first posts of this feed. Special parsing from sources like Flickr, Jumcut, Google video, …

I invite you to download and test it in your Rails application, all new bug reports are welcomed!

sudo gem install rfeedreader

[Ruby] Delicious gem to play with bookmarks

Par défaut

One of my favorite tool is Del.icio.us, simply adding list of bookmarks to be shared with anybody, it’s easy enough to scrap a big list of HTML links to quickly make something more shareable, like Freeduino.org becoming http://del.icio.us/freeduino

So here is a quick ruby gem to play even more, just install it:

sudo gem install rdelicious

Then play with it:

require 'rubygems'
require 'rdelicious'

@delicious = Rdelicious.new("delicious_login", "delicious_password")

print "Correct login" if @delicious.is_connected?

@delicious.add("http://rdelicious.rubyforge.net/", "Rdelicious Gem")

if @delicious.url_exists?("http://rdelicious.rubyforge.net/")
	print "Url inserted into delicious"
end

@delicious.delete("http://rdelicious.rubyforge.net")

unless @delicious.url_exists?("http://rdelicious.rubyforge.net/")
	print "Url deleted from delicious"
end

[Ruby] One line to save God

Par défaut

We’ve had unexpecting interruptions in our Feevy updaters last weeks, and the error (which is still strange) came from inside God, it was unable to decide if a process was still running.

If you’ve the same kind of problem, with your god logging showing « kill: 1: No such process« , then change the exists? method in /usr/local/lib/ruby/gems/1.8/gems/god-0.5.0/lib/god/system/process.rb file, gem path might not be the same on your system.

# Return true if this process is running, false otherwise
def exists?
    # system("kill -0 #{@pid} &> /dev/null")
    ps_int('rss') != 0
end

Here is our configuration if some people can find where this line is causing problem: Ubuntu Gutsy, Ruby 1.8.6, God 0.5

[Ruby] God monitor

Par défaut

Update: this script, from September 2007, is a bit out-dated, you can get more info on official God gem website.

Looking for a ruby programmer? Contact me

After many ways to monitor Feevy updaters, we’re finally using God gem today to manage everything with Ruby on many platforms.

Documentation is really clear, and it’s easy to adapt it to your own code. The nicest point was to be able to control our non-daemonized updaters, and monitor them all in the same tool.

Here is our script:

require 'rubygems'
require 'god'

ROOT = File.dirname(__FILE__)

God.init do |god|
  god.pid_file_directory = "#{ROOT}/pids"
end

[*0...20].each do |updater|
  God.watch do |w|
    # watch with no pid_file attribute set
    w.name = "updater_#{updater}"
    w.interval = 30.seconds # default
    w.start = "ruby #{ROOT}/updater.rb"
    w.grace = 10.seconds

    w.behavior(:clean_pid_file)

    w.start_if do |start|
      start.condition(:process_running) do |c|
        c.interval = 5.seconds
        c.running = false
      end
    end

    w.restart_if do |restart|
      restart.condition(:memory_usage) do |c|
        c.above = 150.megabytes
        c.times = [3, 5] # 3 out of 5 intervals
      end

      restart.condition(:cpu_usage) do |c|
        c.above = 50.percent
        c.times = 5
      end
    end
  end
end

[updated]: thanks to apeiros on irc://#ruby@irc.freenode.net for quick array initialization tips!

[Ruby] RFeedFinder and RFeedReader

Par défaut

In the refactoring process of Feevy.com (mostly to remove dirty spaghetti code), I’ve write my first 2 ruby gems, with some time to learn and practice with new toys for ruby.

Rubyforge

http://www.rubyforge.org

That’s the place that hosted most of rubygems and is the most useful to deploy your own, it comes with all you need to start and deploy a project: svn, webspace, bug tracker, forum…
But it would be a pain to deploy everything by hand, a gem is available to do it quicker.

New Gem

http://newgem.rubyforge.org/

It’s a simple gem that would generate for you an environment where to build your gem, with a few rake tasks to easily deploy it locally and on rubyforge.

Configuration is simple, just replace ‘FIXME‘ in code with what is needed and start coding your new gem.

To deploy on Rubyforge, don’t forget to setup your access on your local machine.

RFeedFinder

http://rfeedfinder.rubyforge.org/

Main purpose of RFeedFinder is to locate the feed url inside a webpage. It can be really tricky, sometimes using recursion or lucky guesses, but it should work 95% of the time.

RFeedReader

http://rfeedreader.rubyforge.org/

Once we’ve got a feed to parse on Feevy, we want to read its first item. That the purpose of this gem.

Another purpose is to use this gem to update Feevy posts from external clients. Feevy server was doing all the job when a feed was updated, now updater clients can parse the feeds too, and return the complete info to Feevy server, so we’ve another performance boost on the central server.