Showing posts with label rubyonrails. Show all posts
Showing posts with label rubyonrails. Show all posts

13 July 2009

Fixing Bus Error BUG in ruby entreprise edition

If you want to use ruby enterprise edition (ree) for your project, it's very important to install all the dependencies with the ree gem command, especially if the gems rely on native code such as imagemagick, or ... bluecloth.

I bumped into the following bug when I tried to run my specs with ree:

$ /opt/ruby-enterprise-1.8.6-20090610/bin/ruby spec/models/advocacy_spec.rb
/.gem/ruby/1.8/gems/bluecloth-2.0.0/lib/bluecloth_ext.bundle: [BUG] Bus Error
ruby 1.8.6 (2008-08-11) [i686-darwin9.7.0]

Abort trap

The solution was to install the bluecloth gem again, with reee gem:

:trunk$ /opt/ruby-enterprise-1.8.6-20090610/bin/gem install bluecloth
WARNING: Installing to ~/.gem since /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8 and
/opt/ruby-enterprise-1.8.6-20090610/bin aren't both writable.
Building native extensions. This could take a while...
Successfully installed bluecloth-2.0.4
1 gem installed
Installing ri documentation for bluecloth-2.0.4...
Installing RDoc documentation for bluecloth-2.0.4...
jm-macbook:trunk jeanmichel$ /opt/ruby-enterprise-1.8.6-20090610/bin/ruby spec/models/advocacy_spec.rb
...

Finished in 0.349809 seconds

The recent versions of rubygems use the ~/.gem/ruby/1.8/ folder so it make sense to install gems in your home folder so standard ruby and ree can share them.

On a sidenote, running the specs with ree worked without any problem. memory consumption was lower but it did not improve the speed.

04 June 2009

Before | After

Before:



def self.find_expiring_soon(date_time = Time.now)
@@expiring_soon ||= find(:all, :conditions => ["type_id = 1 AND completed = 0 AND created_at < :date", { :date => (4.months + 14.days).ago(date_time) }])
end

def self.find_expiring_soon_with_donations(date_time = Time.now)
@@expiring_soon_with_donations ||= find(:all, :conditions => ["type_id = 1 AND completed = 0 AND donated_amount > 0 AND created_at < :date", { :date => (4.months + 14.days).ago(date_time) }])
end

def self.find_expiring_soon_without_donations(date_time = Time.now)
@@expiring_soon_with_donations ||= find(:all, :conditions => ["type_id = 1 AND completed = 0 AND donated_amount = 0 AND created_at < :date", { :date => (4.months + 14.days).ago(date_time) }])
end

def self.find_expiring_very_soon(date_time = Time.now)
@@expiring_very_soon ||= find(:all, :conditions => ["type_id = 1 AND completed = 0 AND created_at < :date", { :date => (6.months - 3.days).ago(date_time) }])
end



After:



def self.find_expiring_soon_with_donations
find(:all,
:include => :donations,
:conditions => [
"expires_soon = 0
#{with_expiring_criterias}
AND donated_amount > 0", { :date => four_months_and_a_half_ago }])
end

def self.find_expiring_soon_without_donations
find(:all,
:conditions => [
"expires_soon = 0
#{with_expiring_criterias}
AND donated_amount = 0", { :date => four_months_and_a_half_ago }])
end

def self.find_expiring_very_soon
find(:all,
:conditions => [
"expires_very_soon = 0
#{with_expiring_criterias}
", { :date => (6.months - 3.days).ago(date_time) }])
end

def self.find_expiring_now
find(:all,
:conditions => [
"expired = 0
#{with_expiring_criterias}", { :date => 6.months.ago }])
end

def self.with_expiring_criterias # DRY
"AND type_id = #{ElementType::MONEY}
AND completed = 0
AND activated_at < :date" end

private_class_method :with_expiring_criterias

def self.four_months_and_a_half_ago
@@FOUR_MONTHS_AND_A_HALF_AGO ||= (6.months - 6.weeks).ago(Time.now)
end

private_class_method :four_months_and_a_half_ago


  • Much more lines of code (LOC), does it improve readability and understading?
  • hardcoded values replaced by objects (ElementType::MONEY), does it make easier to understand the meaning of numbers without knowing the DB model
  • duplicate SQL DRyed in a private method
Which version do you prefer?

29 April 2009

Setting up logrotate with capitate

How many Rails projects "forget" to set up a log rotation of their production logs and end up filling the hard disk with gigabytes of log ...

Lots ;-) And mine before I found out about logrotate.

Fortunately, there is one tool which help you to no to reinvent the wheel and set up a log rotation within minutes: capitate ;-)

Install it:

sudo gem install capitate
Add the following snippet to your conf/deploy.rb:

# See http://capitate.rubyforge.org
require 'capitate'
require 'capitate/recipes'

# Add this line but remove it afterinstalling 'cap rails:logrotate:install'
set :use_sudo, true
Run cap -T to see how many recipes you have now!

Run
cap logrotated:install_conf

It should install a new /etc/logrotate.d/rails_yourwebsite.com

/home/youruser/public_html/yourwebsite.com/shared/log/production.log {
size 10M
rotate 7
daily
missingok
notifempty
copytruncate
}


That's it!

23 March 2009

Netbeans usability

UPDATE:
The netbeans community solved my problem in 24 hours!!! It was a bug due to a problem of deserialization ... Deleting the ~/.netbeans folder solved the problem. Check out http://www.netbeans.org/issues/show_bug.cgi?id=161070

One of thing I enjoy the most in life is cooking. I distrust most of the products processed by the food industry - gm, transfat, the list is too long... - and try to cook with local, raw and organics ingredient (when available at a fair price). The kitchen utensils I use must be of very good quality: the knifes must cut without effort, the pan must not contain carcinogen material, etc... As the whole cooking experience becomes slightly stressful if I have to cook with other utensils, I tend to bring my best knifes with me on holidays ;-)

To stick with the cooking metaphor, I see the code as the ingredients, the IDE being the kitchen utensils and the working and tested software the resulting meal.
A lot of my productivity and the joy I feel crafting a beautiful software depends on my interaction with an IDE.

I have been using Netbeans since february 2007, following its long path to become a mature IDE for Ruby on Rails. Most of the time, I have used the latest build, reported some issues and it has been a fun and productive experience.

However, I am feeling a bit frustrated now, because of some recent changes in the behavior of the Output Window(CTRL+4) . I rely highly on Autospec to run my unit tests. With Netbeans 6.5, I have the code on one widow and I use an undocked Output window on the right side in order to check out the tests results and open classes in 1 click. This is very handy because Netbeans opens the guilty class in the main window, at the exact location of the guilty line of the backtrace. This makes the whole development cycle "super" productive!



Since Netbeans latest build 23rd of March 2009 (7.0?), this behavior has changed. It seems that the Output window behaves like any other window. By default, it opens in a normal tab, forcing you to constantly CTRL+TAB to switch between classes and output. If you undock it and you click on a backtrace, it will open it in the same undocked window as the Output!!!

So unless you move theses windows to the main IDE, there is no way you can compare the tests output and the class itself. As far as I am concerned, this is a serious usability issue and I'd like to discuss it with other netbeans users and netbeans IDE developers. In the following screenshot, you can see that every time I click on a backtrace, it opens the window in a tab next to the Output window ....


Please, please rollback the Output Window to its previous behavior!

A last tip about running autospec. The netbeans Autospec implementation is flawed: output is polluted by zillions of %RSPEC_SUITE_FINISHED% and the constant scroll bar at the bottom is very distracting. The solution is to run autospec with a simple "Run File" (shit +F6) of the script/autospec. This is much more productive and faster than the RSpec runner built into Netbeans and always works!

In the future, I'd love to see a feature which would allow us to split the IDE in 3 vertical windows.
If you look at Jon and Sandro on Pair Programming hashrocket video, you'll see that they have split their screen in 3: a class, the test class and autotest. Always take inspiration from the best!

04 February 2009

Install rmagick on ruby entreprise edition

I was trying to install rmagick on an ubuntu 7.04 and

"ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension."

I found the solution in google cache: install the 1.15.12 version !
Link
sudo /opt/ruby-enterprise-1.8.6-20090113/bin/gem install rmagick -v 1.15.12

27 January 2009

n-dash VS m-dash

The good thing with software engineering is that you learn a new thing every day. Computer programs depend on so many different layers, libraries, hardware that it should be no surprise that things go wrong all the time.

One of the Agile practice to fight this entropy is unit testing and especially Test Driven Development (TDD). Since 2005, I work with TDD, writing the specs (tests) before the code and this is the best design method I have used so far! No more dead code :-) Moreover, the final code looks really clean and the tests are the best up to date documentation with examples I will ever write.

I am implementing a Schedule class which encapsulate event times such as in the flavorpill.com. Following TDD and being lazy(!), I wrote the spec first so I copy pasted directly the "When" text from the event page in flavorpill to my editor:


it "should output in a pretty format such as Tuesdays–Sundays (10am–5pm)" do
@schedule.starts_at = 10.am
@schedule.ends_at = 5.pm
@schedule.from_tuesday.to_sunday
@schedule.pretty_format.should equal("Tuesdays–Sundays (10am–5pm)")
end

=>expected "Tuesdays–Sundays (10am–5pm)", got "Tuesdays-Sundays (10am-5pm)" (using .equal?)

Don't you see the difference? Me neither, and it took me at least 5 minutes to understand what was going wrong.

After increasing the size of the font, it's a bit easier to spot:

expected "Tuesdays–Sundays (10am–5pm)", got "Tuesdays-Sundays (10am-5pm)"

Olala! A colleague of mine who works as an editor introduced me to the wonderful world of n-dash and m-dash.

The hyphen is used to hyphenate compound words and between non-continuing numbers, e.g., phone numbers.

The en dash - is used to "connect continuing, or inclusive, numbers -- dates, time, or reference numbers." [Chicago Manual of Style, sec. 5.115]

The em dash is used "to denote a sudden break in thought that causes an abrupt change in sentence structure." [Chicago Manual of Style, sec. 5.106]

Morality: copy-paste is evil!

But be honest, who knows about these characters, did you learn it in english classes? As far as I am concerned, there is no key in the keyboard to type the m-dash...

03 December 2008

Paris on Rails 2008

Paris on Rails 2008 was my 3rd conference this year, after XP Days France and citcon europe in Amsterdam . I talked about User Acceptance Testing with cucumber at webrat and selenium. Apologize to my non-french speaking readers, I will write the rest of this post in french.

Je suis de retour de Paris on Rails 2008! Richard et Laurent de nuxos ont vraiment assuré l'organisation de la conf: merci messieurs, ce fut très pro!
Ce que je retiendrais, en vrac:

  • Russ Olsen, en direct skype des US s'est levé à 5h du mat pour philosopher sur les langages de programmation. Son speech était comme du miel, c'est définitivement un"story teller": impressionant!
  • Philippe Hanrigou nous a servi sur un plateau une présentation très intéressante sur les Tests d'acceptance web à forte valeur ajoutée. Son utilisation de vidéos et de photos pour illustrer son propos m'a paru une excellente idée. Sur le plan technique, j'ai retenu 2-3 patterns que je vais implémenter ASAP
  • DHH est cool mais finalement, je ne sais pas si il apporte autre chose qu'un "icing on the cake" à une conférence plutot dense.
  • Les autres présentations étaient également enrichissantes, sauf peut-être liquid dont je n'ai pas compris la valeur ajoutée
  • Par rapport aux autres conf, le temps pour "socializer" était encore 1 fois trop limité. Il nous manque un apéro, un petit déjeuner, un goûter d'1 heure pour que l'on puisse échanger des cartes de visites et débattre. C'était un peu la course pour la pause déjeuner ... Quel contraste avec XP Days ou citcon où j'ai eu le temps de tisser de nombreux liens d'amitié lors de soirées d'anthologie et quelque peu éthyliques!
  • une autre suggestion afin de motiver la communauté: faire un "call for participants" avec un site web 2.0 qui permet de voter pour les propositions. La conférence espagnole est un exemple à suivre.
Quant à ma présentation, ce fut quelque peu épique car je me suis trompé de fichier et j'ai découvert en live une version beta ! J'avoue avoir pas mal bosser pour préparer la conf et voir tous ces slides mal foutues alors que j'avais passé une partie du dimanche à les fignoler m'a filé un coup (aïe!) . L'année prochaine, j'aurais un script pour automatiser le backup sur memory stick et je vais lire les bouquins américains que Phillippe m'a conseillé pour les mettre en pratique.
Link
Pour ceux que ça intéresse, voici la denière version de ma présentation, avec quelque photos censurées ;-)


Vos questions sont les bienvenues, sachez que je compte démarrer un projet sur github avec des exemples de features pour selenium et de specs pour RSpec.
Malheureusement, je n'ai pas pu me rendre à la Rails Party organisé par Jean-François Trân et rubyfrance.org. Mais le programme avait l'air prometteur et j'avoue que je suis très fan de ces rencontres informelles. Si l'année prochaine, ils la refont et previennent un peu plus en avance, je me ferai tout mon possible pour être présent!

Pour conclure ce long post, cette conférence m'a conforté dans ma décision de tenter ma chance de l'autre côté de l'Atlantique afin d'aquérir de nouvelles compétences. Il me reste tellement de choses à apprendre avant de devenir peut-être un jour un "master" en Rails (From Journeyman to Master) !

Donc, si tout va bien, je devrai être à San Francisco à partir de mars 2009. Si vous avez des contacts ou connaissez une start up on Rails, merci de le faire savoir ...

17 November 2008

Invalid Google Maps API key

Today, it took me 1 hour to find the reason why my google map was not showing in production env whereas everything was fine in development env. Needless to say I have a "view" spec + a selenium acceptance test which pass.

Google Maps API has only one error message for this kind of problem: "The Google Maps API key used on this web site was registered for a different web site. You can generate a new key for this web site at http://code.google.com/apis/maps/. "

Therefore, I started looking at the wrong place and changed the key set up for the "production" environment in the RAILS_ROOT + '/config/gmaps_api_key.yml many times without any success ...

Finally, I ended up looking at the source of the page and it appeared that the key parameter was empty!

  <script src="http://maps.google.com/maps?file=api&v=2.x&key=&hl=" type="text/javascript">
View Jean-Michel Garnier"s profile on LinkedIn
        
  • Services
  • Contact
  • Recommend Me

    Speaker at:
    Amsterdam 2008
    2008
    2007 & 2008

    Tags

    Powered By Blogger