[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] 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.