April 2007

Thanks, Oracle

We’re using Oracle at my current project. I wanted to run some reporting scripts on the database to do some nice graphs with Graphviz and yEd. “Well, that’s been done before, should be pretty easy to hook up ActiveRecord to Oracle”, I thought.

It turns out that’s nearly impossible to do on an Intel Mac running the x86 version of Ruby, since the Oracle Instant Client SDK only ships with PowerPC binaries so far (hence the title). Unless you recompile your whole Ruby install to PPC, something that to me sits somewhere between unspeakable and atrocious, you can’t link to its libraries, as far as I can tell.

But you can get SQLPlus to run on Rosetta. And you can get SQLPlus to spit out reasonably parseable HTML. And it’ll run slow - but for a quick-n-dirty report that you want to generate once every couple of months or so, it’s… ok.

def select_all(sql)
  html = `echo “#{sql};” | sqlplus -r 3 -l -s -m “html on entmap on” #{@user}/#{@password}@#{@host}`
  doc = Hpricot(html)
  (doc/’tr’).collect do |tr| 
    (tr/’td’).collect do |td|
      td.innerText.strip if td.innerText 
    end if (tr/’td’).size == (doc/’tr/th’).collect do |th|
      th.innerText.strip if th.innerText
    end.uniq.size
  end.compact
end

Look what you made me do, Oracle. You should be ashamed. As you can see, though, I’m not that easily embarrassed. Some people wouldn’t ever show this code to anyone, and deny its existence at all possible cost. I think it’s worth the shock value, though. :)

Geek
General
Work

Comments (8)

Permalink

I love the OSA

Inspired by Nat Pryce’s recent scrapheap challenge idea for a Name That Tune style game, and given I’ve been having so much fun with the Ruby OSA lately, I decided to implement my own solution using it to drive iTunes and I had a lot of fun in the process.

I started by grabbing a reference to iTunes:

%w(rubygems rbosa).each {|lib| require lib }

itunes = OSA.app(”iTunes”)

And then playing about with it until I found the right properties to look at and methods to call. As the game requires a constant stream of random tracks, I thought using the Party Shuffle feature of iTunes to would fit just right. The Party Shuffle is a special playlist that sits inside your library:

library = itunes.sources.find {|s| s.kind == OSA::ITunes::ESRC::LIBRARY }
party_shuffle = library.playlists.find {|p| p.special_kind == OSA::ITunes::ESPK::PARTY_SHUFFLE }

With that party_shuffle (an OSA::ITunes::Playlist object) at hand, it’s pretty easy to do the rest: playing, changing tracks and figuring out how to score each guess.

If you can grab the complete solution and make it into a nice little dashboard widget, I’ll be forever in debt!


BONUS UPDATE: I just finished refactoring a couple of things (namely, moving the monkey patching of OSA::ITunes away - it’s now in itunes.rb) and, in the process of doing so, Tune Fight was born!

Geek
General

Comments (2)

Permalink