Archive for the 'ruby' Category

Manifest reader in Ruby

Manifest files are incorporated in jar files to help describe them.
In the OSGi world, they have a critical mission: describe the OSGi bundle that the jar becomes, giving its name, its transitive dependencies and its execution parameters.

I initiated some time ago a project named Manifest in Rubyforge, licensed under the Apache 2 License.
Assaf helped put some meat on the bones with his reader used in the Buildr tests (source, around line 41).
I added some more code to parse the OSGi attributes. For example, when you parse the org.eclipse.compare plugin, you can query it like this:

manifest.sections.first["Require-Bundle"]["org.eclipse.core.expressions"]["bundle-version"]

This returns "[3.3.0,4.0.0)".

The first release is tagged 0.0.1, and you can install it with rubygems:

gem install manifest

A word of caution when using the Capistrano multistage plugin

When using the multistage plugin, which is pretty much required for anything serious on Capistrano, do not use the word “stage” to describe one of the stages. It provokes a name conflict down the road.

Funnel 0.1

I worked some more on Funnel over the week-end to turn it into something usable. You can get it here.

The results look (In My Not So Humble Opinion) very good:

  • Funnel supports caching. It will register the feed if you ask it to, and will ping it back in case you update something. The data is stored in the database, maybe we can expose it if needed.
  • Funnel updates asynchronously. You run a script to update the feed data, and another one to generate the feed file
  • I made a nice website, that should be updated with more and more examples and documentation.

I still miss for now the background job that will trigger the update and generation scripts. It may be done using cron, which is fine for Unix-land.
I will probably add a rake task to force an update, and a script to run an update thread in background.

The admin interface is yet to be done. Once it is, I’ll shoot for 1.0. Stay tuned!

Scala syntax extension

Follow up with yesterday:
you can get my Scala syntax gem extension here, and read below for the instructions on how to install it.

First here is the result:


/**
 so much fun
*/
class Auction(seller: Actor, minBid: Int, closing: Date) extends Actor {
  val StringForFun = "hello"
  val timeToShutdown = 36000000 // msec
  val bidIncrement = 10
  def act() {
    var maxBid = minBid - bidIncrement
    var maxBidder: Actor = null
    var running = true
    while (running) {
      receiveWithin ((closing.getTime() - new Date().getTime())) {
        case Offer(bid, client) =>
          if (bid >= maxBid + bidIncrement) {
            if (maxBid >= minBid) maxBidder ! BeatenOffer(bid)
            maxBid = bid; maxBidder = client; client ! BestOffer
          } else {
            client ! BeatenOffer(maxBid)
          }
        case Inquire(client) =>
          client ! Status(maxBid, closing)
        case TIMEOUT =>
          if (maxBid >= minBid) {
            val reply = AuctionConcluded(seller, maxBidder)
            maxBidder ! reply; seller ! reply
          } else {
            seller ! AuctionFailed
          }
          receiveWithin(timeToShutdown) {
            case Offer(_, client) => client ! AuctionOver
            case TIMEOUT => running = false
          }
      }
    }
  }
}

You will need to add those CSS elements to display things correctly:

pre {
	background: #000000 repeat-x;
	color: #00FF00;
	font-family: arial, 'lucida console', sans-serif;
	line-height: 160%;
	font-size: 120%;
}

code {
	color: #00EE00;
	font-style: bold;
	font-family: arial, 'lucida console', sans-serif;
}	

.comment { color: #333; font-style: italic; }
.keyword { color: #eff; font-weight: bold; }
.punct { color: #444; font-weight: bold; }
.symbol { color: #0bb; }
.string { color: #6b4; }
.ident { color: #00b; }
.constant { color: #66f; }
.regex { color: #a82; }
.number { color: #a33; }
.expr { color: #227; }

Then on your machine, you will need ruby and rubygems installed, and install redcloth and syntax:

gem install syntax
gem install redcloth

Put your sample into a text file in the same folder as run.rb, then run:

ruby run.rb myscala.txt > output.html

That’s about it. It’d be great to develop the same things for Java and CSS. In the mean time, enjoy!

Testing svn2rss

So my latest cool app is asking Subversion the latest changes over the repository.

It pretty much does this:

svn log #{your_url} --limit #{when_you_d_like_to_stop}

Then, for every revision, it runs a diff:

svn diff #{rev1}:#{rev2}

After playing around for some time with all those commands, my advice is to run svn2rss with Subversion 1.4, as my tests were taking more than 2 minutes to complete.

Subversion commits

I did some hacking this week-end, and the result is called svn2rss.

It’s a simple lib to parse a subversion log and create a RSS 2.0 feed out of it.

Quick snippet to show you how it works:

# the module to include in your script.
self.include Svn2rss

# parse the svn log
entries = parseSvnLog("http://myfeed.com/rss")
# create your own feed
feed = createRSSFeed(entries,
        "http://myfeed.com/rss",
        "My very own title",
        "My description of the feed",
        "en",
        "managingEditor@myfeed.com",
        "webmaster@myfeed.com")
# Well, as you can see the API is clearly not optimized.
# Still working on that particular point, so expect your API to break often till 1.0.

The implementation is coming with some complete examples:
-create a WEBrick server that will serve your feed.
-create a file to hold your changes and send it through FTP to a server.

You can check out a live instance of svn2rss here, and below is a snippet generated with Feed2JS.

0.1 is out, so installing it is just a matter of muttering the magic works:

sudo gem install svn2rss

I hope you like it. It cuts the deal for me. It certainly isn’t a replacement for some great tools like Fisheye, but it helps showcasing my works. More on that very soon.