Bio::Graphics and rails

Posted about 7 years back at Saaien Tist

As a follow up to my post on Bio::Graphics, I tried integrating this library in a rails application. After all, you'd get your data either from a file (like GFF) or a database. And let me tell you: it took me just 30 minutes or so to get a proof-of-concept running. This included installing rails itself, creating the rails app, creating the database, loading dummy data, and doing the coding itself. That 30 minutes was interrupted for a couple of hours, because I needed some advice from Kouhei Sutou, the author of rcairo, on how to write PNG images in memory instead of to a file.

So how do you do it? The proof-of-concept little database I created contained 3 tables:

  • chromosomes (columns: id, name, length)
  • tracks (columns: id, name, glyph, colour)
  • features (columns: id, chromosome_id, track_id, name, location, url)
Create some features for a couple of different tracks for a particular chromosome.

In views/chromosomes/show.rhtml, add the following line:

<%= @chromosome.to_png %>


My models/chromosome.rb looks like this:

require 'stringio'
require 'base64'
require_gem 'bio-graphics'

class Chromosome < through =""> :features

def to_png(width = 800, start = 1, stop = self.length)
return %{}
end

def draw(width, start, stop)
panel = Bio::Graphics::Panel.new(self.length, width, false, start, stop)
track_container = Hash.new
self.tracks.each do |track|
if ! track_container.has_key?(track.name)
track_container[track.name] = panel.add_track(track.name, track.colour.split(',').collect{|i| i.to_i}, track.glyph)
end
end

self.features.each do |feature|
track_container[feature.track.name].add_feature(feature.name, feature.location)
end

output = StringIO.new
panel.draw(output)
return output.string
end
end


UPDATE: Apparently, Blogger does not allow me to paste the correct code above. In the to_png method, replace the following ascii codes:

  • %7B with {

  • %28 with (

  • %29 with )

  • %7D with }



And that's it. I leave the integration of my ensembl-api, bio-graphics and rails as an exercise for the reader. We could make a ruby version of the Ensembl browser... and then: world domination. Mwahaha.

"script/generate undo" plugin released

Posted about 7 years back at Beyond The Type - Home

Grab it while it’s hot:

 script/plugin install svn://rubyforge.org/var/svn/beyondthetype/undo_generator_plugin/trunk

Key Features

  • Undo any generator command
  • Keeps a log of all generator history in log/generator.log
  • Prompts before undo’ing any commands
  • Even works when you bail out of a generator command part way through

Christian Neukirchen - Ruby on Rails Podcast

Posted about 7 years back at Ruby on Rails Podcast

Christian Neukirchen, Ruby veteran and inventor of the tumblelog.

November is docs month

Posted about 7 years back at The Hobo Blog

So after highlighting the fact that documentation is now soooo important, you must all be thinking “OK, so…?”. The current situation is this. The Hobo team is getting towards the end of a large development project, and all going well we should have a decent chunk of time to give Hobo some TLC in November. So, no guarantees, but you can look forward to a much higher level of docs, and maybe even some shiny new screencasts towards the end of November.

November is docs month

Posted about 7 years back at The Hobo Blog

So after highlighting the fact that documentation is now soooo important, you must all be thinking “OK, so…?”. The current situation is this. The Hobo team is getting towards the end of a large development project, and all going well we should have a decent chunk of time to give Hobo some TLC in November. So, no guarantees, but you can look forward to a much higher level of docs, and maybe even some shiny new screencasts towards the end of November.

Slides from Railsconf presentaion

Posted about 7 years back at The Hobo Blog

OK the slides are online. Unfortunately I haven’t added any notes as yet, so some of it will be a bit obscure. The theme of the talk was that while being very good for beginners wanting to create a web-app quickly and easily, Hobo is also well suited to more serious projects.

Enjoy!

Slides from Railsconf presentaion

Posted about 7 years back at The Hobo Blog

OK the slides are online. Unfortunately I haven’t added any notes as yet, so some of it will be a bit obscure. The theme of the talk was that while being very good for beginners wanting to create a web-app quickly and easily, Hobo is also well suited to more serious projects.

Enjoy!

After Railsconf

Posted about 7 years back at The Hobo Blog

So that was Railsconf. By far the biggest takeaway for me was very simple: Hobo needs docs! Of course we knew that already, but it was really hammered home by meeting a bunch of people who have tried Hobo and are now waiting in the wings for it to become easier to use.

The Hobo talk was fairly well attended, which was great – many thanks to everyone that showed up.

I really enjoyed Dave Thomas’ keynote – engineering is art. His quote from the famous “Mythical Man Month” by Fred Brooks is so wonderful I think I’ll add it here in more than full.

The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. Yet the program construct, unlike the poet’s words, is real in the sense that it moves and works, producing visible outputs separate from the construct itself. It prints results, draws pictures, produces sounds, moves arms. The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be.

After Railsconf

Posted about 7 years back at The Hobo Blog

So that was Railsconf. By far the biggest takeaway for me was very simple: Hobo needs docs! Of course we knew that already, but it was really hammered home by meeting a bunch of people who have tried Hobo and are now waiting in the wings for it to become easier to use.

The Hobo talk was fairly well attended, which was great – many thanks to everyone that showed up.

I really enjoyed Dave Thomas’ keynote – engineering is art. His quote from the famous “Mythical Man Month” by Fred Brooks is so wonderful I think I’ll add it here in more than full.

The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. Yet the program construct, unlike the poet’s words, is real in the sense that it moves and works, producing visible outputs separate from the construct itself. It prints results, draws pictures, produces sounds, moves arms. The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be.

Episode 72: Adding an Environment

Posted about 7 years back at Railscasts

Rails comes with three environments: development, test, and production. But, you aren't restricted to just these. You can add your own! See how in this episode.

RailsConf Europe 2007 Retrospective

Posted about 7 years back at poocs.net - Home

As some of you might or might not now (depending on whether or not you’ve been following my Twitter stream), I’ve spent the past week touring Berlin for RailsConf Europe.

Foreword

It’s always a difficult undertaking who you’re trying to attract with such a specialized conference like RailsConf, being about a specific framework in a specific area of development (The Web). Go too technical and lose the beginners. Stay too broad or basic and lose those who have been following for years. With RailsConf Europe 2007, I think the balance was basically pretty much spot on.

But: The same holds true for the audience, too. I occasionally had a hard time figuring out the “level of sophistication” of some of the talks beforehand, so I could decide which of the 4 tracks in parallel was worth attending. And sometimes I picked wrong and let go of a presentation for one that turned out to be much too broad and lacking depth.

I’m sure attempts to solve this issue have come up before. Everything from including a short passage of “recommended skills to attend” or a simplified, numeric “sophistication index” that goes on the schedule with the title and description of the talk might help. Or create additional confusion. There you have one of the reasons why I’m not putting together conferences.

Tutorials

RailsConf Europe 2007 kicked off on Monday, September 17 with a day of (mostly) half-day tutorial sessions in parallel tracks. (One of the morning tutorials then had to be cancelled at short notice, though.)

I had opted for the BDD tutorial from the RSpec guys. I’ve been using RSpec in a couple projects now so I was well prepared for not getting too much out of it, but still hoped that some best practice would be dealt with.

The guys were indeed having a good time on stage and the presentation was okay. (Actually, it was fairly uncommon practice to use a mind-map instead of presentation slides, but let’s save that story for next time.)

The tutorial got messy when the audience was asked to download the code for a sample application from the RSpec Subversion repository and no-one was actually able to get more than a few bytes down the pipe due to the massively overwhelmed Wi-Fi (more on that in a later section). This then exaggerated into a wild USB-stick trading scene and in the end we didn’t even get around looking at the code at all. That was a tad disappointing.


In the afternoon I then attended the Scaling Rails tutorial of Jason Hoffman of Joyent (I have that scaling thing going, as some of you might remember).

Jason spent quite an amount of time talking about some of their preferred hard- and software setups as well as some of the specifics of being the host for Twitter, which was nice.

Scaling talks can only be so far applicable to your own itches since this is one of the topics that is so tightly bound to the application specifics that it’s simply impossible to state more than a handful best practices and then spend a great amount of time with case studies.

Keynotes

The actual conference was then kicked off later Monday night by program chair David Black and the opening keynote by Dave Thomas, “The Art in Rails”.

I truly enjoyed Dave’s speech, being the first of his I saw in-person. Rather than giving a tech-heavy presentation (that he had, from his own words, gotten several beating for), Dave went down the philosophical path of contrasting software development with art. His speech is covered sufficiently by Casper Fabricius and Stuart Eccles - I have little (if anything) to add there.


Tuesday morning was then started by The Man Himself, David Heinemeier Hansson talking about the upcoming release of Rails 2.0.

DHH presented smaller increments of progress the core team has made during the past several months and stated that at this point they’re focussing on evolutions rather than revolutions since Rails has successfully had enough of the latter since it was first released.

Rails 2.0 will see a preview release in the short term, so David presented the old (way before Rails 1.0) and upcoming (past 2.0) way of developing a sample application (the now infamous weblog application that starred the very first Rails introductory screencast).

Additional notes and code samples are, again, available from Casper Fabricius.


Another keynote worth mentioning was Dr. Roy T. Fielding’s talk “The Rest of REST”, dealing with, as the name suggest, REST as an architecture of developing modern web applications.

Over the course of his talk, Roy Fielding for several times returned to a graph of how many web sites the World Wide Web had at a certain time while he iterated over major milestones in WWW and HTTP history as well as his involvement sculpting the protocols and specifications that drive major parts of the internet today.

Fielding even looked at Rails’ REST implementation (looking from the outside in, as he hasn’t really developed applications in Rails so far) and offered suggestions on how to improve it. His slides are available.

Sessions

The schedule of RailsConf Europe 2007 was packed. 50+ sessions were scheduled to take place in 4 parallel tracks. Of positive note should be that the track locations were so close together that almost no time was lost traveling around. But, as indicated in the foreword, there were time slots in the schedule that had me want to split in quarters to be able to attend all 4 tracks at once.

Another negative aspect was that only the keynotes were actually recorded. Having missed out on a couple sessions for the reasons above, I’m not even able to watch a recording of a session I missed.


From the sessions I went to I really liked Evan Phoenix’ presentation about the state of Rubinius, his alternative Ruby implementation.

Evan is now working full-time on Rubinius (financed by EngineYard) and has made really good progress during the past months. He’s anticipating a preview release of Rubinius 1.0 as early as November (yes, of 2007).

Apart from the interestingness the Rubinius project brings with it, Evan sure had the best made up stats graphs of the entire conference. Not to mention his awesome tie.


In a fill-in effort for Jamis Buck (who just released Child 3.0), Marcel Molina Jr. joined Michael Koziarski in a Rails Best Practices session along the lines of what they do over at The Rails Way.

Using several (supposedly bad) code samples the duo explained how one could improve readability, modularity, and maintainability all at once by following several simple guidelines such as ”Skinny Controller, Fat Model”, as first introduced on Jamis Buck’s blog in 2006.

Make sure all of these suggestions go straight into your “common sense” bin.

The Venue

RailsConf Europe 2007 took place in the Maritim proArte Berlin. As soon as your brain adjusted for the fact that the street-address-facing side of the hotel is actually a mall that doesn’t look at all like a hotel, the hotel worked fairly well as a venue for a 800+ attendee conference.

Being located in downtown Berlin on Friedrichstrasse, the hotel was both in little distance to most travel places (3km to the central station, 15 minutes cab ride to the next airport) and around lots of decent food places.

Speaking of food, lunch was a disaster. And I’m not talking about the food per-se (which was good), but the organization around getting 800+ attendees to their food (or rather, vice versa). If the session you attended happened to end a few minutes late, you’d have to expect to be stuck in lines for the next 20-30 minutes, risking either your cigarette break or your siesta (or both).

The breaks between the sessions as well as the lunch and intermediate breaks were nicely laid out and enough time for both participants and the venue staff to re-arrange the conference rooms going from keynote-mode into split-tracks mode.

From a technical standpoint, two things got in the way of the conference being a full win. First of all, as mentioned in the tutorials section above, the Wi-Fi was unusable most of the time. Luckily, the Wi-Fi at Starbucks right next door would accept the conference credentials for access and provided much better connectivity.

Additionally, the lights on stage and in the session rooms were really bad if you happen to have a passion for photography. Even Mr. Conference Photography himself twittered that. So for the next event, I’ll have to bring my flashes and PocketWizards and mess with Duncan’s lighting.

Summary

It was indeed a good conference where I’ve finally met several people I had only been having electronic conversations with. (So that part of the “networking” actually worked out well.)

Now I’m looking forward to RailsConf US 2008 in Portland (May 29-Jun 01), although I’m not yet certain that I will be able to attend. The next RailsConf Europe will be in Berlin again, but the dates aren’t set yet. As David Black put it: “Block out the entire fall.”

Related Reading

Tumbling

Posted about 7 years back at Luke Redpath - Home

Since I started blogging again a few months ago, I thought it would be a good idea to set up a tumblelog (courtesy of tumblr) to encourage me to post more frequently without having to spend time writing full-length blog entries.

In case you missed new navigation bar along the top of this blog (or you are reading this in your newsreader), then you can access my tumblelog here.

Besides the obligatory tumblelog fare (quotes, chat excerpts and so on) I tend to post any useful, interesting or plain esoteric code snippets that I have written or come across, so please do check it out. You can also subscribe to the feed.

Here are some recent snippets:

* Timeout on any Ruby method * More sneaky #to_proc tricks

On an unrelated note, I did attend RailsConf Europe last week but have yet to finish my write-up. To everybody I got the chance to talk to while I was out in Berlin, it was good catching up and enjoy numerous beers. I have to say thanks to my employers, Reevoo for financing the trip. There were some interesting talks and I enjoyed myself overall but unfortunately were also some disappointments – more on that in my full write-up.

Making Rails More (Artificially) Intelligent slides & source code

Posted about 7 years back at Spejman On Rails

I have just posted the session slides and source code of the RailsConf Europe talk Making Rails More (Artificially) Intelligent that Santiago Bel and me did last Tuesday. You can download them all at bee.com.es

We hope you find them useful. Please note that the ones that are at the railsconfeurope.com web are out of date, now I will send the updated slides to o'reilly.

Apple Wireless Keyboard: First impressions

Posted about 7 years back at poocs.net - Home

Apple announced new keyboards alongside its new iMacs in early August, but the bluetooth variant wasn’t shipping until mid-September. As you can see, mine just shipped (I’ve been using Apple bluetooth keyboards since they first came out).

When you initially open the package, these things really seem tiny. But in the end, they’re exactly the size as the thicker older model minus the numeric keypad and cursor keys moved over.

With regards to the touch feel (and I’m typing this on the keyboard you see above), they feel different but I can type quick and fast easily. The keyboard of my MacBook Pro still feels a little softer and typing on the old whitish Apple keyboards is a different deal altogether. The lowered height of the device is definitely a welcome change.

So far I don’t miss the numeric keypad (and I’m far from being an accountant). The only thing I have to mentally adjust for is the lack of an enter key right next to where I keep the mouse. Due to the smaller size, my mouse currently lives quite a bit to the right and I tended to hit that extra enter key with my right hand occasionally when reaching over from the mouse. This hits solid table ground for the time being. But I’ll live.

Keyboard Update 1.2 popped up when checking with Software Update after pairing the keyboard, installed and rebooted, the new keys for Dashboard and iTunes (play/pause/skip) worked immediately. So no issues to report there.

Update: Here’s a shot of the front edge with a (metric) ruler attached to it, as some commenters indicated interest in it.

script/generate undo

Posted about 7 years back at Beyond The Type - Home

Here is small idea I’ve had for sometime that I quickly knocked up yesterday.

Generators are great but we have all had those “Oops!” moments where you realised that what you created was not quite what you wanted to do. Enter script/generate undo….

script/generate model WrongName
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/wrong_name.rb
      create  test/unit/wrong_name_test.rb
      create  test/fixtures/wrong_names.yml
      exists  db/migrate
      create  db/migrate/001_create_wrong_names.rb

.. ….

oops.. didn’t want to do that.

script/generate undo
Undo'ing: model WrongName
    notempty  db/migrate
    notempty  db
          rm  db/migrate/001_create_wrong_names.rb
          rm  test/fixtures/wrong_names.yml
          rm  test/unit/wrong_name_test.rb
          rm  app/models/wrong_name.rb
    notempty  test/fixtures
    notempty  test
    notempty  test/unit
    notempty  test
    notempty  app/models
    notempty  app

Under the hood all it is doing is keeping a log of your generator history (see /log/generator.log). When undo is called it looks at the last log entry and passes it onto script/destroy. Pretty simple stuff but it saves you having to remember what it was that you typed previously.

The patch as it stands is pretty rough and ready. I’m posting this here to get some feedback to gauge whether it’s worth pursuing further.

UPDATE Plugin on the way. I’ve created a new project on Rubyforge for any plugins I make - it should be setup soon. (just waiting for approval)

UPDATE 2: Plugin now released. See this post