mbg notes

Massive Brain Games developers notes

A DB admin interface written in Rails

Posted by Ivan Schneider on October 21, 2008 at 08:44 PM

The Rails Rumble 2008 took place last week end and we took this contest as an opportunity to bootstrap a project we had in mind for some time. I teamed up with Jessy Bernal, with whom I am developing at Massive Brain Games, and Sylvain Utard, the creator of Live On Bankiz. The said project is a DB interface written in Rails and meant as a replacement for the classic phpMyAdmin. Not an extremely original idea I must confess but we found nonetheless a few reasons that motivated this project.

First of all, it's kind of annoying to install a php application on an otherwise ruby only server. We also find that the phpMyAdmin is quite old and gray, not really up to date with the latest javascript tricks we are all now accustomed to. Finally we thought there was some room for innovation by taking advantage of the different conventions Rails has set up for DB schemas.

With these two days of rush we were able to develop an alpha version of the product. We're fully aware that there are quite a few bugs and that it's far from complete. However it still makes an acceptable proof of concept which demonstrates a bunch of interesting features. You can check out the Rails Rumble deployment or watch the screencast.


rbDB web-based mysql admin with conventions from Jessy Bernal on Vimeo

We named the application rbDB and will soon opensource it. We hope that we'll find people interested in this project and that the first step they will take in supporting us will be to vote for our application on Rails Rumble.

UPDATE: rbDB is on github

Keyboard navigation for TextMate stacktraces

Posted by Ivan Schneider on June 29, 2008 at 11:49 PM

I love the fact that in TextMate almost anything has a keyboard shortcut or can be assigned one. However there is still one action that requires me to resort to the mouse; clicking the links in a stacktrace to get to the incriminating file. This led me to write this JavaScript snippet:

document.addEventListener('keypress', function(e){
    var key = e.keyCode
    if (key != 63233 && key != 63232) return
    links = document.getElementsByTagName('a')
    for (var i = 1; i < links.length; i++)
        if (links[i].title == 'focused') break
    if (i == links.length) i = 0
    links[i].title = null
    if (key == 63233){
        if (i == (links.length - 1)) i = 1
        else i += 1
    }
    if (key == 63232){
        if (i <= 1) i = links.length - 1
        else i -= 1
    }
    links[i].title = 'focused'
    links[i].focus()
})

It allows to navigate through the links of the html output with the up and down arrows and then pressing enter opens the file. I don't need the mouse for that anymore, mission accomplished.

I put this script at the end of /Applications/TextMate.app/Contents/SharedSupport/Support/script/webpreview.js. There might be a cleaner place to put this, but I didn't find it right away so I settled for this though I might have to re-paste it at the next TextMate update.

A pl_analyze log viewer with Merb

Posted by Ivan Schneider on May 12, 2008 at 01:23 AM

If you don't know it already, production_log_analyzer is a nice gem which provides different tools to analyze log files of a Rails application. pl_analyze is one of those tools and produces text reports on the time spent in the different actions of your Rails app.

I find these reports already quite useful as they are but I thought they could be more usable if only I could easily change the order in which the actions are presented. So I wrote a tiny application to present my reports in a sortable table.

There's nothing really fancy technically speaking, and it really didn't take too much time to get it done, but I thought I could share the result as well as write down a few notes on the steps I took.

Some home brewed javascript and sorttable.js

I started by writing a bunch of javascript functions to parse the reports and build three html tables with the data.

A search for "javascript sort table" led me to sorttable.js which is unobtrusive and easy to use. I wanted alternate colors on my rows for better readability of my tables so I had to tweak it a little bit.

A taste of Merb

Given the fact that almost all of the action happens on the client side, all I really needed from the server side was a single action for the log upload. I thought it could be a good opportunity to take a first shot at Merb and take advantage of the flat app structure. Even though my Merb app was ridiculously small I still learned a few things along the way.

First I didn't know where to put my static files since creating a public directory didn't work for my flat app. I couldn't get google to help me so I looked through the source and found out quickly enough that I just had to put them in the root dir of my app since the server root was set to an empty string.

I also learned how to disable the sessions (I didn't need them and they were conflicting with the rails app serving this blog). It turned out to be really easy, just had to remove three lines config/init.rb which were configuring these sessions.

It's also worth mentioning that I encountered a few errors thus allowing me to see the Merb exception page which I think is quite neat; nice style, folded code for each line in the stacktrace plus links to open the files directly in TextMate.

I deployed this tiny app on a thin backend with nginx on the front and it's accessible right here. Maybe some people will find this a bit useful, i know i do. I'm looking forward to reading any comment you may have.