22 November 2007

Petite enquête sur vos attentes de Paris on Rails

J'imagine que le site de Paris on Rails va rediriger pas mal de people sur mon blog alors j'en profite pour faire un petit sondage sur vos attentes:








Cela me permettra d'ajuster le contenu de ma présentation, qui n'est d'ailleurs que dans le stade d'une mindmap à l'heure oú j'ecris ce mot ...

Si vous avez des suggestions, merci de poster un commentaire, je ne manquerai pas de publier ceux qui me paraissent constructifs. C'est pas beau l'internet participatif? D'autre part, je publierai toutes mes sources (présentations sur RSpec en anglais et liens) dans ce blog.

19 November 2007

RSpec Resources

Subscribe to the RSS of my RSpec presentations:

(click on the RSS logo)



My bookmarks with the 'rspec' tag:

15 November 2007

21 croissants daily post 11/15/2007

nbarthelemy.com New Rails Plugin: local_auto_completer

  • Plugin of the day!
    How many billons the plugins are there around??? I am making a few changes to it because I also want the id so I can use it with belongs_to associations attributes.

09 November 2007

21 croissants daily post 11/09/2007

the { buckblogs :here }: Brevity vs. Clarity

  • Ruby on Rails code should be like a poem ;- )
    Code shoule be readable by humans, when I read code containing 2 ternary operators, it takes me 5 min to understand it ... What's the point? Apart from not wanting other to change it??? Fortunately, I have some tests and I am not scared to refactor ...

07 November 2007

RSpec at Paris on Rails 2007

Last year, I gave a talk about testing Rails at the first Spanish RailsConf in Madrid. It was quite a challenge because I am not fluent in Spanish and it was the first time since university I was talking in front of such a large public.
This year, I will have the honour to talk after DHH at Paris on Rails 2007 on the 10th of december 2007. I will attempt to evangelize the crowd about the beauty of BDD and show some demos with RSpec, Autotest, RCov, ....

You'll find all details at the conference page.


Here is the full details in French:

Les Tests avec Ruby on Rails

La nécessité d'écrire des tests automatisés fait l'unanimité auprès de la communauté Rails. Mais, par où commencer? On les écrit après avoir implémenté une nouvelle fonctionnalité ou encore avant, afin de spécifier le comportement de nos objets dans un langage naturel proche du jargon métier parlé par les utilisateurs.

Et quand on a terminé d'écrire ces fameux tests, comment en tirer le meilleur parti? Comment être certain que ce "commit" de 2 lignes de code ne va pas casser une fonctionnalité majeure d'un module développé par un autre collègue?
Quand peut-on considérer que l'on a écrit suffisamment de tests?
Faut-il aller jusqu'à automatiser les tests de l'IHM afin de garantir que les interfaces AJAX fonctionnent avec tous les navigateurs et OS du marché?

Pendant cette présentation, nous évoquerons le

et quelques autres outils tout en apportant les réponses à ces questions.

05 November 2007

21 croissants daily post 11/05/2007

device-mapper: table: 245:1: linear: dm-linear: device lookup failed - Ubuntu Forums

  • This "sudo aptitude remove evms" saved my life, after the upgrade to Ubuntu gutsy from Fesity, my computer went crazy and was displaying billons of lines "device-mapper: table: 245:1: linear: dm-linear: device lookup failed". I had to try to type this command line while the screen was continuously displaying these lines !!! Not sure I will keep with linux (I want a MAC)!

device-mapper: table: 245:1: linear: dm-linear: device lookup failed

    24 October 2007

    Output the rspec report to an html file

    rake spec

    Create a spec.opts with:

    --format
    html:doc/rspec_report.html
    --loadby
    mtime


    => It will generate a rspec_report.html file in your doc folder!!!

    The rspec documentation actually explains it but I missed an example to start using it ...

    04 October 2007

    Do not use an IDE to commit with svn your rails frozen gems!

    After having lost a couple of hours trying to commit my rails/vendor both with netbeans and subeclipse, I think it's time to come back to old school command line: it's 10 times faster and do no take 100% CPU!!!

    • Go to the vendor folder
    • svn add rails
    • svn commit -m "Added vendor/rails version 1.2.3"
    Done!

    28 September 2007

    Playing with float arithmetics with Ruby: how to truncate decimals

    I needed to truncate a float to 4 decimals because I am using geocoding in my app and Google map returns coordinates with a lot of decimals ...

    After reading this post in the ruby-talk mailing list, I decided to take a break in my development and write the following code :


    require 'benchmark'

    class Float
    def truncate_decimals_with_printf(number_of_decimals_after_dot)
    ("%.#{number_of_decimals_after_dot}f" % self).to_f
    end

    def truncate_decimals_with_regexp(number_of_decimals_after_dot)
    match = Regexp.compile("\\d*." + "\\d" * number_of_decimals_after_dot).match(self.to_s)
    match[0].to_f
    end

    def truncate_decimals_with_arithmetic(number_of_decimals_after_dot)
    x = 10 ** number_of_decimals_after_dot
    (self * x).round.to_f / x
    end
    end

    describe "Float.truncate_decimals" do

    it "could truncate decimals using printf" do
    1.12349.truncate_decimals_with_printf(4).should == 1.1234
    end

    it "could truncate decimals using a regexp" do
    1.12349.truncate_decimals_with_regexp(4).should == 1.1234
    end

    it "could truncate decimals using arithmetic" do
    1.12349.truncate_decimals_with_arithmetic(4).should == 1.1234
    end

    it "Benchmark:" do
    Benchmark.bm(10) do |timer|
    timer.report('arithmetic') { 1.12349.truncate_decimals_with_arithmetic(4) }
    timer.report('printf') { 1.12349.truncate_decimals_with_printf(4) }
    timer.report('regexp') { 1.12349.truncate_decimals_with_regexp(4) }
    end
    end

    end



    The result:

    Float.truncate_decimals
    - could truncate decimals using printf (FAILED - 1)
    - could truncate decimals using a regexp
    - could truncate decimalsusing arithmetic (FAILED - 2)
    user system total real
    arithmetic 0.000000 0.000000 0.000000 ( 0.000015)
    printf 0.000000 0.000000 0.000000 ( 0.000017)
    regexp 0.000000 0.000000 0.000000 ( 0.000028)
    - Benchmark:

    1)
    'Float.truncate_decimals could truncate decimals using printf' FAILED
    expected: 1.1234,
    got: 1.1235 (using ==)
    /home/jeanmichel/ruby/projects/iss2.0/spec/models/float_spec.rb:22:

    2)
    'Float.truncate_decimals could truncate using arithmetic' FAILED
    expected: 1.1234,
    got: 1.1235 (using ==)
    /home/jeanmichel/ruby/projects/iss2.0/spec/models/float_spec.rb:30:

    Finished in 0.008598 seconds

    4 examples, 2 failures

    The arithmetric solution is the fastest! Faster than printf ! Computers are good at division and multiplication ;-) The regexp is damned slow, however it's the only one which actually fullfill the specs ;-)

    Any idea how to change other implementations ?

    Today, I have lost a few hours because the arithmetic implementation was working on my dev box, a Linux 2.6.20-16-386 i686 GNU with a ruby 1.8.5 (2006-08-25) [i486-linux] and NOT at all on my production server, a
    Linux i686 i686 i386 GNU/Linux with a ruby 1.8.4 (2005-12-24) [i386-linux] ...

    At the end, I used the printf version, which is OK because I don't care about the rounding...

    Most important rule: you should always get a stage server IDENTICAL to your production server and run the tests / specs on it before deploying!

    17 September 2007

    Hola RailsConf Europa

    Escribo este mensaje para los que hayan visto mi mensaje en el message board, y que quieran saber un poco más sobre 21 croissants.

    Soy un programador Rails desde el 2006 y me encantan el "testing", BDD, RSpec, selenium, etc ... Echa un ojo a mi ponencia a Rails Hispana en el 2006

    Para resumir, después de 5 años de Java, en Paris, Londres y Barcelona, empiezo mi actividad de autónomo con eco-union, una asociación ecologista y estoy buscando clientes (ONGs / Asociaciones / Servicios públicos o PYMES.

    Me gustaría escribir tutoriales sobre RSpec y introducir este framework. Me gustaría saber que te parece el Rspec y el testing.

    Mándame un mensaje si quieres quedar en la RailsConf.

    Hasta pronto!

    Jean-Michel

    Bonjour RailsConf Europe

    J'écris ce post au cas oú tu sois tombé sur ma carte de visite dans le message board de la RailsConf et tu voudrais en savoir un peu plus sur 21croissants.

    En 1 ligne, je développe avec Rails depuis 1 an et des brouettes et je suis passionné par le "testing", BDD, RSpec, selenium, etc ...

    Pour résumer en quelque lignes, après 5 ans de java successivement à Paris, Londres puis Barcelone, je commence mon activité de freelancer dans le cadre de eco-union, association écologiste à Barcelone et je recherche des clients potentiels (ONGs/ associations / services publiques ou PMEs). Je n'ai pas encore décidé si j'allais rester en Espagne, et je suis donc intéressé par toutes les entreprises francophones (petite structures!) qui utilisent Rails et une méthode Agile.

    Je recherche également des partenaires freelancers intéressés par offrir des prestations de formation sur Ruby on Rails en français ou en anglais pour 2008.

    J'ai l'intention d'écrire des mini-tutoriels (screencasts) sur RSpec et présenter ce framework lors de la prochaine Paris On Rails. N'hésite pas à me donner ton point de vue sur ce framework et le testing en général.

    Envoie moi un email si tu as envie de me rencontrer en personne pendant la RailsConf.

    A bientôt j'espère!

    Jean-Michel

    03 September 2007

    Cheap Rails hosting

    I pay about 10$ / month for the hosting of my apps at site5
    So far, I haven't had any major problem but I wonder if it's not time to move to a more powerful configuration with a more qualified support.

    I am not saying site5 support is not competent but they are a bit slow. Most of the time, there are different people who reply to my questions. I suspect they only have a few rails experts and a lot of people in their support with no specific specialization...

    Moreover, they are still using ruby 1.8.4, rubygems 0.9.2 and rails 1.1.6, more than 6 months after the release of Rails 1.2.3!!!

    When asking about moving to mongrel instead of the quite unstable fcgi, they reply they have not planned it ...

    Any host to recommand apart from Railsmachine?

    I am going to try the startup at primetime, a norwegian company whose engineers are top-notch gurus in linux and Rails.

    It happens they are also friends of mine from Oslo ;-)

    31 August 2007

    Configuring Rails To Use Gmail’s SMTP Server

    Nothing original here I am afraid.
    I copied Google's cache from http://blog.pomozov.info/posts/how-to-send-actionmailer-mails-to-gmailcom.html


    1. Save the following code within your rails app in lib/smtp_tls.rb




    require "openssl"
    require "net/smtp"

    Net::SMTP.class_eval do
    private
    def do_start(helodomain, user, secret, authtype)
    raise IOError, 'SMTP session already started' if @started
    check_auth_args user, secret, authtype if user or secret

    sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
    @socket = Net::InternetMessageIO.new(sock)
    @socket.read_timeout = 60 #@read_timeout
    #@socket.debug_output = STDERR #@debug_output

    check_response(critical { recv_response() })
    do_helo(helodomain)

    if starttls
    raise 'openssl library not installed' unless defined?(OpenSSL)
    ssl = OpenSSL::SSL::SSLSocket.new(sock)
    ssl.sync_close = true
    ssl.connect
    @socket = Net::InternetMessageIO.new(ssl)
    @socket.read_timeout = 60 #@read_timeout
    #@socket.debug_output = STDERR #@debug_output
    do_helo(helodomain)
    end

    authenticate user, secret, authtype if user
    @started = true
    ensure
    unless @started
    # authentication failed, cancel connection.
    @socket.close if not @started and @socket and not @socket.closed?
    @socket = nil
    end
    end

    def do_helo(helodomain)
    begin
    if @esmtp
    ehlo helodomain
    else
    helo helodomain
    end
    rescue Net::ProtocolError
    if @esmtp
    @esmtp = false
    @error_occured = false
    retry
    end
    raise
    end
    end

    def starttls
    getok('STARTTLS') rescue return false
    return true
    end

    def quit
    begin
    getok('QUIT')
    rescue EOFError, OpenSSL::SSL::SSLError
    end
    end
    end



    1. Add this code to config/environment.rb

      require “smtp_tls”

      ActionMailer::Base.smtp_settings = {
      :address => “smtp.gmail.com”,
      :port => 587,
      :authentication => :plain,
      :user_name => “someone@openrain.com”,
      :password => ’someonesPassword’
      }

    2. Use ActionMailer as normal.


    30 August 2007

    Linux 101


    The (sad but real) truth is I am new to Linux, even if I have been using Unix systems (solaris based), back in 1995 at the university. My teachers were quite uncompetent and as my home pc was windows based, I did not learn as much as I could have done and forget little by little the few things I knew ...
    As I have decided to use this blog as a personal public knowledge database, I have decided to post about all the simple commands I learn.

    firefox, how to synchronise bookmarks

    I am using both Linux Ubuntu and Windows XP on my laptop (with dual boot), I am using the foxmarks extenstion to keep my "Bookmarks Tool folder" synchronised. I kepp all my personal bookmarks on my del.icio.us

    man

    To quit, type "q"

    vi

    to edit a file: vi file_name.rb, then type "i" to edit
    More commands on http://www.comptechdoc.org/os/linux/usersguide/linux_ugvi.html

    To quit:
    If you were editing the file, escape the edition mode with the escape key.

    :q

    To save:
    :wq

    sudo

    To do things that required "root" privileges.

    configuration : /etc directory


    To add a folder to the PATH variable, the "best" seems to edit the file ~/.bashrc
    gedit ~/.bashrc

    and append at the end of the file:
    PATH=$PATH:~/programs/scripts export PATH

    Taken from http://ubuntuforums.org/showthread.php?t=269793&highlight=PATH

    bash

    When I start my machine for work, I end up launching more or less the same application. I wanted to write a quick script which allows to launch all these applications in one-click!
    Reading http://www.mkssoftware.com/docs/man1/sh.1.asp, I found about the &

    &

    asynchronously executes the command that precedes it. This means that the shell just starts the command running and then immediately goes on to take new input, before the command finishes execution.


    creating alias

    gedit ~/.bashrc
    Append alias at the end of the file:
    alias ll='ls -l'

    Locking the screen with the "key menu" is not cool!

    I was looking for a software which would allow me to customize keyboard shortcuts and I came accross keytouch , which seems great but you have to configure your keyboard in order to use it.
    I thought I could do that later and then share my work to the community ...
    Oooops! There was a side effect, every time I hitted the "menu" key
    , it was locking my screen! After 1 day of clumsy locking and having lost 30 minutes searching into ubuntu forums what was happening, I decided to uninstall keytouch. Bingo!
    It was such an improductive hour! Next time, I won't spend more than 15 minutes on that kind of shits ...

    I didn't know the name of this *&$·%· key, this is how does it look like:


    The "menu key" or "application key" is on the right side

    Killing process which belong to a certain user


    ps -ef | grep process_name
    skill -9 -u 'username' -c process_name

    Deleting a directory (reccursively)


    rm -Rf directory_path

    Copying an entire directory

    The following command will copy "src" inside "dest"

    cp -R src/ dest/

    uses the backslash ( ) for directories whose name contain spaces o

    Example:
    cp -R /windows/Program Files/Macromedia/ ~/.wine/Program Files/

    Display hidden files (files starting with dot)

    ls -a

    Display the list of process running and ... KILL!

    ps -ef
    kill -9 id_process

    Display the list of process running and their memory footprint


    ps -eo pid,pmem,size,args --sort=-size

    It shows every process ID with the percentage of memory used, the actual KB of memory used and the full command w/ command line options. And sorts everything by used memory.

    Environements variables

    Display all env variables:
    env
    Display one env variable
    echo $LOGON
    Assign a value to an env variable
    export PATH=${PATH}:${ANT_HOME}/bin

    Chmod reccursively

    chmod -R ...
    Check out the informations in http://www.ss64.com/bash/chmod.html

    Copy files through ssh using scp

    scp username@server.com:/path_to/files path_to_local_destination_file

    Examples:-

    scp myfile you@remote.machine.org:/userdisk/yourdir

    Copy the file called ``myfile'' from the current directory to the directory called ``userdisk/yourdir'' belonging to the user ``you'' on the computer ``remote.machine.org''.

    scp "you@remote.machine.org:/userdisk/yourdir/*" ./

    Copy all files from the directory called ``userdisk/yourdir'' belonging to the user ``you'' on the computer ``remote.machine.org'' to the current directory. For further information see section 8.7.



    Console commands

    • CTRL + R : will search in all the commands typed not only in the current session
    • cd - : to come back to previous folder
    Process commands

    before the comand:

    nice

    A nice value of −20 is the highest priority and 19 is the lowest priority. The default nice value for processes is inherited by its parent process, usually 0
    nohup
    enabling the command to keep running after the user who issues the command has logged out

    'a command '&& notify-send 'Done'

    will pop up when the command has finnished

    Call another shell script:

    source ~/another_bash.sh



    Swap

    My system uses a lot of swap and I have no idea of how to tell it to use the RAM when it's available ...
    I've found this:

    cat /proc/sys/vm/swappiness
    60
    The value of 60 is often the default on SuSE Linux systems. This value ranges from 0 (less likely to swap) to 100 (very likely to swap). I notice that by setting it to 10, the system uses much less swap memory than before.
    /proc/sys/vm/swappiness
    The above code will set the value temporarily. To set it permanently so that it takes effect on each boot, edit the /etc/sysctl.conf file and add the line:

    vm.swappiness=10
    Changing the value contained into swappiness should help you tuning how your system swap.

    Setting up public key authentication over SSH


    Every time I want to setup public key authentication over SSH, I have to look it up, and I've never found a simple guide, so here's mine.

    Generate key on local machine

    ssh-keygen -t rsa

    It will ask you for a password but you can leave it blank.

    Note you could also pick -t dsa if you prefer.

    Ensure that the remote server has a .ssh directory

    Make sure the server your connecting to has a .ssh directory in your home directory. If it doesn't exist you can run the ssh-keygen command above, and it will create one with the correct permissions.

    Copy your local public key to the remote server

    If your remote server doesn't have a file called ~/.ssh/authorized_keys2 then we can create it. If that file already exists, you need to append to it instead of overwriting it, which the command below would do:

    scp ~/.ssh/id_rsa.pub remote.server.com:.ssh/authorized_keys2

    To copy to an existing .ssh/authorized_keys (99% of time):
    cat ~/.ssh/id_rsa.pub | ssh user_name@remote.machine.com 'cat >> .ssh/authorized_keys'

    You may also be able to remove the exact known host with the following command via ssh on your local machine. Remember to replace mt-example.com with your own domain.

    ssh-keygen -R mt-example.com 

    Finding a file


    Here's an example find command using a search criteria and the default action:
    find / -name foo
    will search the whole system for any files named foo and display them. More examples here.

    Finding a file containing a string



    For example search for a string called redeem reward in all text files located in /home/tom/*.txt directory, use
    $ grep "redeem reward" /home/tom/*.txt

    Task: Search all subdirectories recursively

    You can search for a text string all files under each directory, recursively with -roption:
    $ grep -r "redeem reward" /home/tom




    Recursively remove .svn directories

    find . -type d -name .svn | xargs rm -rf

    How to exit a process



    [18:29:18] … What about Ctrl + Z
    [18:29:26] … ?
    [18:29:39] Marco i: now write 'jobs
    [18:29:40] … '
    [18:29:41] … jobs
    [18:29:52] : Stopped telnet localhost 11211
    [18:30:01] : do: kill %1
    [18:30:11] … It kills the first stopped job.
    [18:30:18]: [1]+ Terminated telnet localhost 11211
    [18:30:23] Marco Lazzeri: ok
    [18:30:27] … now you're out
    [18:30:33] Jean-Michel Garnier: OK, I will add this trick to my linux trick. Thanks again
    [18:30:39] Marco i: but having ctrl + ] as font increaser is NOT good ; )
    [18:31:00] … You know that with CTRL + Z you can stop jobs.
    [18:31:21] … Then if you issue 'bg' you send it to background
    [18:31:36] … While if you issue 'fg' you take it back to your screen: foreground.
    [18:31:44] Jean-Michel Garnier: I have learned it today
    [18:31:57] Marco i: It can be uself.
    [18:31:59] … useful
    [18:32:05] … especially when working on remote systems.
    [18:32:16] … when you don't have graphical shell
    [18:32:29] … or when opening more terminals is a waste of time

    Remote control with vnc

    vncviewer -fullscreen 192.168.2.23:0

    If you want to quit vncviewer: Press 'F8' and select Quit viewer


    RFormat an external USB hard drive to ext2


    sudo umount /dev/sdb1
    [sudo] password for jeanmichel:
    jeanmichel@21x100:~$ mkfs.ext2 /dev/sdb1
    mke2fs 1.40.2 (12-Jul-2007)
    warning: 424 blocks unused.

    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    61166016 inodes, 122093568 blocks
    6104699 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    3726 block groups
    32768 blocks per group, 32768 fragments per group
    16416 inodes per group
    Superblock backups stored on blocks:

    Tar / Untar a file

    Tar:
    tar czf /path/to/output/folder/filename.tar.gz /path/to/folder
    Untar:
    tar xvf tsung-1.2.1.tar.gz && rm tsung-1.2.1.tar.gz


    CPU Usage

    top

    type "1" to see mutliple cups

    Hard drive Usage


    du -s * | sort -nr | head

    How to check if an IP is denied from ssh acces


    grep 88.6.173.50 /etc/hosts.deny

    How to make multiple folders

    You can make multiple folders in bash and other shells with {folder1,folder2} :

    mkdir /usr/local/src/bash/{old,new,dist,bugs}

    Which version of packages I have installed?

    dpkg -l | grep openssl


    Configure /etc/init.d

    sudo sysv-rc-conf

    provides a terminal GUI for managing "/etc/rc{runlevel}.d/"

    Free space on hard drive

    DF command reports how much free disk space is available for each mount you have. When executing DF, I like to use the -h option, which returns the output in a more readable format:

    wtn@wtn2:~$ df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda1 7.5G 2.1G 5.1G 30% /

    What time is it?

    $ date

    Thu Jul 17 08:30:46 GMT 2008

    See What Version of a Package Is Installed on Ubuntu

    dpkg -s

    Is drive mounted?

    if [ ! -d /backup/mydir ]; then
    echo "drive not mounted"
    fi

    List processes with ports they use

    netstat -nlp

    29 July 2007

    Propuesta Rails Hispana 2007

    Para la conferencia Rails Hispana en noviembre 2007, me gustaria presentar una ponencia sobre rspec.

    rspec on Rails
    El "Behaviour Driven Development" (BDD) fue inspirado por las teorías de Sapir Worhf. Según estas, las palabras que usamos cambian nuestra manera de pensar.

    rspec es un framework de BDD que permite usar el lenguaje natural para especificar el comportamiento del código Ruby con ejemplos ejecutables que ayudan en el proceso de diseño y se pueden usar como documentación y tests.


    describe "Charla sobre rspec" do

    it "debería explicar" do
    • Conceptos clave de rspec a través de un ejemplo práctico y analogías con Test::Unit
    • Ejemplos de especificaciones de Modelos, Controladores y Vistas (con Selenium)
    • rspec como especificaciones funcionales
    end


    it
    "debería presentar" do
    • GUIs
    • rcov y Heckle para mejorar la cobertura y la calidad de los specs
    • rspec + Autotest para automatizar la ejecución de los specs
    • rspec + jruby para especificar programas java
    end

    end

    06 July 2007

    Struggling with blogger

    I have been struggling for so many hours with the google blogger template system!!! So far, this has been quite a frustrative experience. So I thought I shared the source code of my template so people can benefit the hacks I have found:



    On the whole, the xml based template language used by google is a good anti-pattern of a very complex and unreadable view language. The only way to work with this "cr*p" is Trial and errors ... Very frustrating!

    Fortunately, there are still independant individuals who innovate in the open source world, check out the genius idead of Yuri Rashkovskii , a 25 years old nice ukranian geek (I have met him in Oslo). I will blog about lilu as soon as I have the chance to play with it.

    I wanted to include the code of my template so you could copy-paste it but once again Blogger f*cked up everything (sic) and did not display it properly ...So please download it here !!!

    28 June 2007

    Getting the latest netbeans ruby-ide automatically

    Update 12/11/2007: Blogger had completly destroyed the formatting of the code, I had a received a few emails telling me the script did not work. I have once again copy pasted it and it should work, I apologize if I have wasted your time, I should really move to a serious blogging system !!!

    Update 10/04/2008: THE SCRIPT DOES NOT WORK ANYMORE. The Netbeans changed their nightly build system, you can download the latest version and install netbeans manually from http://bits.netbeans.org/download/trunk/nightly/latest/

    I am using netbeans since april 2007 as my primary Rails editor on Linux ubuntu. I used to work with Radrails (now Aptana) because I used to be a java developper and work with Eclipse.

    When RadRails "dissapeared", I started looking for alternative IDEs and so far I am very happy with netbeans.

    Tor Norbye and his team are very active (and responsive!) and keep delivering new features all every week! The only way to use these features - as far as I am concerned - is to download the latest build from the Continuous Integration server at http://deadlock.netbeans.org/hudson/job/ruby/

    To save a bit of time, I have written a script to install the latest netbeans ruby-ide automatically. You need to install the mechanize gem first.

    This script will:
    • connect to the Continuous Integration server of sun (http://deadlock.netbeans.org/hudson/job/ruby/)
    • Guess what's the latest stable build file name and download it to a temp location (depending on your OS)
    • rename the old install
    • unzip the build to the netbeans installation folder
    • delete the downloaded zip from the tmp location
    Usage:

    You need to install mechanize:

    gem install mechanize

    Hten, copy the following code to a ruby file and adapt the last two lines to your configuration. The 1st paramater is the "netbeans installation folder" and the
    second one your tmp folder.

    Example:

    script = NetbeansUpdaterScript.new("/home/jeanmichel/ruby/programs", "/tmp")

    script.run



    require 'rubygems'
    require 'hpricot'
    require 'open-uri'
    require 'mechanize'
    require 'fileutils'

    class GenericScript
    def download_from(url, save_as)
    mechanize = WWW::Mechanize.new
    mechanize.get(url).save_as(save_as)
    puts "downloaded " + url + " and saved to " + save_as
    end

    def remove(file_or_directory)
    FileUtils.remove_dir(file_or_directory, true) if File.directory?(file_or_directory)
    FileUtils.rm file_or_directory if File.file?(file_or_directory)
    puts "remove " + file_or_directory
    end

    def unzip_file(file, target_dir)
    system(
    "unzip", "-q", file, "-d", target_dir
    ) or raise "Error extracting (#{$?}): unzip #{file.inspect} -d #{target_dir.inspect}"
    puts "unzip " + file + " to " + target_dir
    end

    def is_using_mac?
    RUBY_PLATFORM == /darwin/
    end

    end

    class NetbeansUpdaterScript < tmp_folder = "/tmp" netbeans_installation_folder =" netbeans_installation_folder" netbeans_folder_path =" @netbeans_installation_folder" tmp_folder =" tmp_folder" netbeans_installer_file =" @tmp_folder" doc =" Hpricot(open(" last_stable_build_number =" doc.inner_html" last_stable_build_number=" + @last_stable_build_number.to_s @last_stable_build_number end def url_latest_build get_last_stable_build_number if is_using_mac? " script =" NetbeansUpdaterScript.new(">


    I have used this script for a week and it seems to work alright but I'd be happy to hear some feedback about the code or any problem you might have.

    Upgrading to Ubuntu Feisty


    At last, I upgraded to the latest stable version of Ubuntu last week. So far, I am very pleased: my firefox, amarok, openoffice and netbeans were very unstable and now everything seems to worl like a charm! The network manager is also very cool: 30s to connecto to a WPA2 network!

    However, the 3D and funky effects (Berryl window manager) don't work perfectly so I had to uninstall them (I can live without!).

    Apart from the fact I could not find a good software for screencasting, I am very happy with Ubuntu even if I'll probably buy a mac in 2008 anyway

    Well done Ubuntu!

    08 June 2007

    L_Appel du 8 juin

    “Ici Paris, la Blogosphère parle aux francophones: Les pingouins qui, depuis de nombreuses années, sont à la tête des geeks francophones ont formé un projet de livrer des applications en retard avec du code non testé. Ces applications, alléguant la défaite de nos comités QA, se sont mis en rapport avec le GrandBugQuiNiqueTout pour cesser le combat. Certes, nous avons été, nous sommes, submergés par la tradition du cycle en cascade, la tradition du “Ca marche a 83%” et la loi de Murphy, de l'ennemi. Infiniment plus que leur nombre, ce sont l'absence de tests unitaires, une mauvaise communication et l'incompétence des personnes chargées du planning qui nous font reculer. Ce sont l'absence de reconnaissance de l'excellence technique des geeks qui aiment le travail bien fait, la horde de fichiers de configuration XML qui dupliquent sans fin les même informations et le manque d'”Agilité” des projets (Planning en continue, Itérations courtes, Tests Unitaires, Intégration Continue, Rétrospective) en générale qui ont surpris nos chefs au point de les amener là où ils en sont aujourd'hui. ....".


    J'ai un rêve: publier un e-book en français pour début 2008 d'une centaine de pages de recettes sur le BDD on Rails avec rspec. Le titre provisoire est T.G.V.: "Testing à Grande Vitesse", en honneur à l'excellent système de transport publique de la SNCF.
    Etant donné que je n'ai eu aucun contact avec la communauté Rails de France et de Navarre depuis 5 ans, je vais avoir besoin de sérieux coups de main pour me mettre à la page;-) Ecris-moi a jean tiret michel suivi d'un arobababase 21 croissant au PLURIEL petit point COM (j'ai tres peur des spammeurs) ou laisse un commentaire à ce post. Pour commencer, voici une petite idée de ce que j'ai derrrière la tête avec l'application web2.0 de mind mapping collaboratif mind42.com:

    07 June 2007

    Selenium reports with screenshots using RSpec and imagemagick on ubuntu


    After having read Aslak Hellesoy's post Watir reports with screenshots using RSpec and Win32::Screenshot, I got very excited because this was exactly the kind of thing I had been daydreaming while taking my morning shower (don't you?).
    Aslak's article explains how to use Watir and Internet Explorer on Windows to generate rspec reports with screenshots. Garps! I am working on linux (ubuntu Feisty) as I can't afford a mac (yet) and can't stand Windows. I got a bit frustrated because I wanted to do the same thing on my ubuntu.

    So, I decided to do a bit of researches and x*y*z hours later (sic), I got my selenium+rspec taking screenshots! My intention is to contribute to the RSpec sub-project spec_ui.


    How does it work?


    To get a 30s answer, please watch the flah screencast I have made of netbeans executing rake spec:selenium, running the selenium server, Webrick, lanching firefox and taking a screenshot after having maximized the screen.

    Here is the code in spec_helper.rb :



    config.before(:all, :behaviour_type => :view) do
    selenium_remote_control_manager = SeleniumRemoteControlManager.new
    selenium_remote_control_manager.start_webrick
    selenium_remote_control_manager.start_selenium_server
    @browser = selenium_remote_control_manager.get_firefox
    @browser.start
    end

    config.after(:each, :behaviour_type => :view) do
    Spec::Ui::ScreenshotFormatter.take_screenshot_of(@browser)
    end

    config.after(:all, :behaviour_type => :view) do
    @browser.kill! rescue nil
    end


    And the code of contact_list_spec.rb:



    describe "/contact/list", :behaviour_type => :view do
    include SeleniumSpecHelper

    it "should provide a description automatically (TODO extract)" do
    open "/contact/list"
    @browser.is_text_present("Frequently Texted").should be_true
    # This line will fail :-)
    @browser.is_text_present("All Contact Tak tak").should be_true
    end

    end




    I have used imagemagick to capture the screenshot.



    What's next?


    I have had the chance to meet Aslak at an irb meeting in the beautiful Oslo and we talked about rspec and selenium. He told me about the idea of generating screencast from the execution of a selenium rspec and I have started to implement it. I am really close to get a solution but I will publish it by the end of july.

    Here are a few features I'd like to have / implement for testing Rails Views:


    • a nice BNL compatible with watir and selenium
    • take a screenshot from the specs in order to generate nice documentation, not only when a spec fails
    • generate a good looking html doc with a sidebar - a la javadoc. And an AJAX search a la gotapi.com ;-) In a funky world, this would be connected to subversion and allow specs to be updated
    • to be completed ...

    To conclude, I hope that tools such as greenpepper and RSpec are announcing the beginning of the end of "Microsoft Word" and "PrintScreen" as tools for writing specifications. Obviously, there will be some serious Manager / Customer / Developper resistance before accepting that tests are part of the delivery and THE only accurate specifications but let's wait for 5-10 years and see in 2012 how people work ;-)

    05 June 2007

    RSpec Changes log RSS

    The excellent BDD framework RSpec has been very active these days, and the 1.0 version was immediatly followed by minor uptates. As their web site seems to not contain a blog or RSS feed, I have used the excellent idea and tool page2rss.com to generate a RSS feed on changes from the

    http://rspec.rubyforge.org/changes.html page.


    To receive updates for this page in RSS format copy-paste this link (http://page2rss.com/page/rss?url=rspec.rubyforge.org/changes.html) into your feed reader.

    If you use one of the following reader, just click to the link to subscribe to Feed:

    I have also shared my netvibes rspec tab which includes RSS on the mailing list archives (user & developper).
    If you are using netvibes, you can add it by cliking on Add to Netvibes

    Otherwise, here are 2 screenshots to give you a ruff idea:

    The different modules (RSS and links):


    If you want to suggest more, please contact me ;-)

    Netvibes has a new feature which allow to preview web sites without leaving the netvibes window. Just clik on the right hand corner button: "Show website". Doing this, I can skim first through the titles and then preview the web sites to read the details of each post: so cool!



    Don't wait, install netvibes now!

    The RSS for the user & developpers' list comes from nabble.com

    Before finding out about nabble, I have been trying for the first time Yahoo!pipes and I have to say I love it!!! I have a feeling it's going to be one of my favourite gadget. It is a very user friendly tool with a fantastic user interface, it took me 45 minutes to write the pipe which generates the url http://page2rss.com/page/atom?url=rubyforge.org/pipermail/rspec-devel/2007-June/thread.html
    from today's date. The only issue was that Yahoo!pipes truncated the post content because the RSS generated by the page2rss.com did not give a title to the posts ...

    Technorati Tags ,

    Set up rspec on Rails

    I have described the steps to install and configure rspec, the Autotest module from ZenTest and a notifier for Ubuntu.

    Make sure you have the latest rubygems (0.9.4)

    sudo gem update --system

    Installing  rspec

    At the time of this writing - 5th of June 2007 - latest version of rspec is 1.0.4, and we'll install it in the vendor/plugins:

    cd <your project home>
    ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
    ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rail
    Check out http://rspec.rubyforge.org/ for updates (I could not find a RSS) but I guess Aslak will be updates on his blog.

    Warning: if you had installed rspec before, run a "gem list" to check if you have a web_spec rogue gem, you must delete it before carrying on, more details in Zenspider's blog.

    Installing and configuring Zentest

    Latest version of ZenTest is 3.6.0, run
    sudo gem install ZenTest
    Thankfully due to the extensible nature of autotest, we'll be able to set up a notifier for ubuntu by adding the following to your <Rails project root>/.autotest file:







     

    #!/usr/bin/env ruby

    module Autotest::GnomeNotify

    # Time notification will be displayed before disappearing automatically
    EXPIRATION_IN_SECONDS = 4
    ERROR_STOCK_ICON = "gtk-dialog-error"
    SUCCESS_STOCK_ICON = "gtk-dialog-info"

    # Convenience method to send an error notification message
    #
    # [stock_icon] Stock icon name of icon to display
    # [title] Notification message title
    # [message] Core message for the notification
    def self.notify stock_icon, title, message
    options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
    system "notify-send #{options} '#{title}' '#{message}'"
    end

    Autotest.add_hook :red do |at|
    notify ERROR_STOCK_ICON, "Tests failed", "#{at.files_to_test.size} tests failed"
    end

    Autotest.add_hook :green do |at|
    notify SUCCESS_STOCK_ICON, "All tests passed, good job!", ""
    end

    end

    # a pop up window will appear to display the tests results
    # More examples in /usr/lib/ruby/gems/1.8/gems/zentest-3.5.0/example_dot_autotest.rb

    # see http://ph7spot.com/articles/getting_started_with_autotest

    The GnomeNotify was written by Philippe Hanrigou, a French Thoughtworker living in California, he has written the best "getting started" guide to Autotest. To install libnotify on ubuntu, run:
    sudo apt-get install libnotify-bin

    Finally, from the Rails project’s root, type:

    autotest


    Pressing Control-C twice in quick succession will exit Autotest back to the shell prompt.


    Integration with netbeans


    As far as I am concerned, netbeans ruby-ide is the first IDE to integrate autotest. Select your project root in the Projects windows, right click and then "Auto Test". This will open an output window and run Autotest. This is very cool, check out the screenshot:






    28 May 2007

    Checking out a svn project with netbeans

    I am using site5 for my rails hosting (for how long? The fcgi is just not stable ...) and I host the source code of my projects with subversion.

    The svn integration in Netbeans can be slightly improved, as I could not check out my project using the GUI, I ended up using the command line and then imported the rails project into Netbeans ...
    svn co svn+ssh://YOUR_USER_NAME_HERE@21croissants.com/home/YOUR_USER_NAME_HERE/rails/svn_repository/YOUR_PROJECT_HERE/trunk YOUR_PROJECT_NAME_IN_YR_LOCAL_MACHINE_HERE

    11 May 2007

    Do not forget to set up the routes when using the REST Controller generator

    NameError in Contact#index

    Showing app/views/contact/index.rhtml where line #18 raised:

    undefined local variable or method `new_contact_path' for #<#<Class:0xb768e1bc>:0xb768e194>

    Extracted source (around line #18):

    15: 
    16: <br />
    17:
    18: <%= link_to 'New contact', new_contact_path %>

    RAILS_ROOT: script/../config/..

    Application Trace | Framework Trace | Full Trace
    #{RAILS_ROOT}/app/views/contact/index.rhtml:18:in `_run_rhtml_47app47views47contact47index46rhtml'
    app/controllers/contact_controller.rb:6:in `index'
    app/controllers/contact_controller.rb:6:in `index'

    Don't forget to set up the routes.rb when using the REST Controller generator !

    Edit the routes.rb and:

    ActionController::Routing::Routes.draw do |map|
      # The priority is based upon order of creation: first created -> highest priority.
     
      # Sample of regular route:
      # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
      # Keep in mind you can assign values other than :controller and :action

      # Sample of named route:
      # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
      # This route can be invoked with purchase_url(:id => product.id)

      # You can have the root of your site routed by hooking up ''
      # -- just remember to delete public/index.html.
      map.connect '', :controller => "sms", :action => 'new'

      # Allow downloading Web Service WSDL as a file with an extension
      # instead of a file named 'wsdl'
      map.connect ':controller/service.wsdl', :action => 'wsdl'

      # Install the default route as the lowest priority.
      map.connect ':controller/:action/:id'
     
      map.resources :contact
    end

    (I can't stand Zoho writer horrible interface: it's the most UNuser
    friendly interface I have ever seen: you can't set the style of
    the text to "normal")

    Bitter Browser manual configuration sample script

    <!-- BITTY BROWSER : WWW.BITTY.COM : {BEGIN} --> <script type="text/javascript">
    <!--

    /* Bitty Browser tips & tricks: */
    /* http://www.bitty.com/manual/ */

    bitty = {contents: [{
    service: "bitty:browser",
    title: "Bitty Browser",
    width: "100%",
    height: "1000",
    titlebar: {display: "off"},
    buttonbar: {textlabels: "off"},
    searchbar: {display: "off"},
    homepage: {contents: [{website: ""}]}
    }]};

    // -->
    </script><script src="http://b1.bitty.com/b2script/" type="text/javascript"></script>
    <!-- BITTY BROWSER : WWW.BITTY.COM : {END} -->

    10 May 2007

    XP Day France 2007

    Last week I went to Paris in order to assist to the second XP Day France conference which was held in Paris. This was an excellent opportunity to catch up with the french speaking Agile & Rails communities. After all, I left Paris almost 5 years ago - in july 2002 ! Nethertheless, I am feeling deeply connected to my home country and I really can't stand bad croissants full of vegetable hydrogenated fat ;-) I have met and talked with passionate people, among others:

    • Laurent Bossavit, Paris, The organizer who did a very good job, the conference place rooms food & drinks were quite good. Laurent is an independant Agile consultant and offer training services about Agile practices
    • Richard Piacentini, Paris, who created RailsFrance, organized Paris on Rails and is a founder of nuxos.fr, a consulting company on open source and Rails projects.
    • Ludovic Blaas, Besançon (my home town!!!), Agile coach at Parkeon ex Schlumberger where people work with Pair Programming, unit testing, Continuous Integration and so on. Allez Besac!
    • Olivier Lafontan, UK, Agile consultant at exoftware. I attended 2 excellent session given by Olivier: "XP Game" perfect training session to re-learn how to do the planning and "Numbers which sell Agile methods" which focussed on ROI of Agile projects and how to give a business value to customer stories

    • Pascal Van Cauwenberghe, Brussels, nayima, gave a very good presentation on identifying bottlenecks on projects. Pascal is one of the inventor of the famous XP Game, he has also a looooot of experience in programming

    • Jacques Couvreur, Geneva, hortis.ch, gave a return on experience about Pair Programming
    • Jérôme Laurens, Paris, founder of ss2j, part of the "sustainable" and ethical consulting network ss2j
    • François Beauregard, Montreal gave a talk about GreenPepper, a product which is a mix of BDD / wiki and FIT
    If you read in French and want to join the hip crowd of happy Rails developers, BUY THIS BOOK! This is the second edition, updated for Rails 1.2.3, translated by Laurent Julliard and Richard Piacentini and published at "Editions Eyrolles". A Must Have !

    The image “http://www.editions-eyrolles.com/Scan/MaxiScan/9782212120790.jpg” cannot be displayed, because it contains errors.

    13 April 2007

    Procrastinating on Ubuntu

    Music plays an important role in my life: it makes me very happy ;-) Yesterday, I went out until 4am to listen to Dj set de Will Holland a.k.a Quantic. Good music is like sport or finding a tricky bug after a good night of sleep: a natural flash of pure serotonine. In a world where most people need to get drunk or take drugs (cigaret, skunk, cocaine, ...) to feel good, I am happy to have a clean brain still depending on natural stimulations ....

    I have been using ubuntu Edgy on my Toshiba SATELLITE M100-184 since September 2006 - 6 months at the time of this post - and I have to say I am not convinced yet it the best choice I have ver made. Yesterday, I spent 2 hours (including a 20 minutes for updating this blog) to have subversion worked with Netbeans. Today, I have spent 1 hour to have sound on my computer !!! It was working perfectly fine until I ran an automatic update and .... Pchhhhh!

    After some intensive googling, I came across a troubleshooting post about my sound card - the HDA Intell & Realtek ALC861 -
    The sound came back but it was very low volume!!! Arghh :-((((

    Fortunately, someone has had the same problem on Feisty and posted a solution ... Very lucky! I have no clue how these people find these solutions but I am very grateful to them!
    sudo gedit /etc/modprobe.d/alsa-base

    and append at the end of the file:
    options snd-hda-intel model=auto

    I am thinking to wait for another 6 months and then make the move to Apple if I am still spending my time procrastinating on configuration issued instead of doing real work!

    11 April 2007

    Set up subversion for Netbeans on Ubuntu Edgy

    The subversion support on Radrails was flawned and I have been loosing a few days before finding out that the subclipse needed to be updated. Now, history is repeating and I am fighting some configuration monsters to get the good looking netbeans subversion support to work!

    First issue: The SVN executables are not set by default!

    Open the options / Miscellaneous / Subversion and set the /usr/local/bin/ folder as in the following screenshot.



    Important, you have to input the svn executable folder, not the executable file. Unfortunately, there is no validation run by netbeans to check if your entry is valid!

    A sidenote to Netbeans developpers, this is typically the kind of things which should be automatic, like in RadRails and Eclipse ;-)

    Second issue: The subversion version installed on Ubuntu Edgy won't work with netbeans!

    Ubuntu Edgy comes with version subversion 1.3, we'll need to upgrade to 1.4.2 manually because the synaptic repository does not contain anything ...
    Here is a script inspired by Higepon which should make the whole thing easier, go to a tmp folder, copy & paste into a sh file and don't forget to make it executable with chmod +x install_svn_1.4.2.sh

    sudo apt-get -y remove libsvn0
    sudo apt-get -y remove subversion
    sudo apt-get -y install libneon25 libneon25-dev
    sudo apt-get -y install libapr1.0-dev
    sudo apt-get -y install libaprutil1.0-dev
    sudo apt-get -y install libdb4.2-dev
    sudo apt-get -y install libdb4.2
    sudo apt-get -y install libsqlite3-0
    sudo apt-get -y install libsqlite3-dev
    sudo apt-get -y install libldap-dev
    sudo apt-get -y install libpq-dev
    sudo apt-get -y install libexpat1-dev
    wget http://subversion.tigris.org/downloads/subversion-1.4.2.tar.bz2
    tar vxf subversion-1.4.2.tar.bz2
    cd subversion-1.4.2
    ./configure --with-ssl
    make
    sudo make install


    The official NetBeans Subversion Support F.A.Q. is also a good source of informations.

    05 April 2007

    TGV

    Premier post en français!

    Il y a quelque jours, j'ai décidé de commencer la rédaction d'un mini e-book en français qui devrait s'intituler TGV - Testing à Grande Vitesse - en honneur au nouveau record de vitesse battu par la SNCF le 3 avril 2007.


    Etant donné que je n'ai eu aucun contact avec la communauté Rails de France et de Navarre, j'ai pensé faire une petite enquête d'opinion sur ses attentes.

    Bon, la tout de suite, c'est un ptit post mais j'ajouterai des zoho surveys!

    03 April 2007

    30 March 2007

    A quick_dirty trick to set ENV[RAILS_ENV]

     I am using webbrick or Mongrel in development mode and Apache + fcgi in production mode on my site5 server (I'd recommand them, they are very reactive).

    I have read that you're supposed to set ENV['RAILS_ENV'] to 'production' in environment.rb
    As I am using capistrano de deploy my webapplication, I have tried to move that setting to dispatch.fcgi and it works! No need to get 2 versions of environment.rb (1 for developement & test and 1 for production)

    Maybe there is a more elegant solution, I'd love to hear about it!

    29 March 2007

    Firefox 2.0.3 keeps crashing on my Ubuntu Edgy Eft

    Since the lasted automatic update on the 25/03/2007, firefox has been very unstable. Every 20 minutes or so, it crashes with the following message:

    "The application 'Gecko' lost its connection to the display :0.0;
    most likely the X server was shut down or you killed/destroyed the application."


    I am investigating the problem following

    https://wiki.ubuntu.com/MozillaTeam/Bugs?action=show&redirect=DebuggingFirefox advices


    The same version of firefox running on Windows XP runs absolutely fine, I am looking forward to reporting to the ubuntu community!!! So far, I have no clue, could it be my installation of ubuntu???


    The sad truth was that before this update, firefox was more stable in Windows too ...

    27 February 2007

    Clearing Out Rails file-bases Sessions with cron

    Adapted from Agile Web Development on Rails:
    The session handler in Rails doesn’t do automated housekeeping. This means that once the data for a session is created, it isn’t automatically cleared out after the session expires. This can quickly spell trouble. The default file-based session handler will run into trouble long before the database-based session handler will, but both handlers will create an endless amount of data. Since Rails doesn’t clean up after itself, you’ll need to do it yourself. The easiest way is to run a script periodically, you could put the following command into a script
    that will delete files that haven’t been touched in the last 1 hour every morning at 4am.

    In the bash, run the command:
    crontab -e

    You'll enter a command line editor vi like, type "I" and copy-paste the following command:
    0 4 * * * cd ~/YOUR_RAILS_APPS_HOME_FOLDER_HERE/; find tmp/sessions -name 'ruby_sess.*' -amin +60 -exec rm -rf {} \;

    To save, type ESC, then wq in order to save the file and quit.

    As far as I am concerned, I can't stand these command line software which don't give a clue about how to use them. I am sooooo looking forward a rebirth of some Pao Alto 70 spirit in the domain of User Interface: I want to see 3D, vocal commands, predictive User Interfaces !!! Damn the Monopoles!!!!

    21 February 2007

    MySQL Database access problem in Ruby on Rails

    I was having the following problem repetitively when using rake to run the tests on my ubuntu Edgy Eft machine:
    rake aborted!
    Lost connection to MySQL server during query
    /config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:1127:in `write'

    As I am using Radrails since the beginning of my ruby career , I have never found out before!!! Indeed, Radrails must use another driver than my plain ruby to access the mysql database.

    It turned out that installing the libmysql-ruby solved the problem:
    sudo apt-get install libmysql-ruby

    14 February 2007

    Deploying a rails application on site5

    It took me a while - 2 days and a half ! - but I finnaly managed to deploy my application on site5 using capistrano!

    The toughest part was understanding this error message:

    error: directory is writable by others: (/home/xxxxxx/rails/webapps/xxxx/releases/20070213163348/public)
    [warn] FastCGI: (dynamic) server "/home/xxxxx/public_html/xxxxx/dispatch.fcgi"
    has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off
    to 600 seconds

    It turned out - as I found in the site5 forum - that site5 has CGI/FCGI configured to shut down scripts that are group- or world-writable. As of 1.3, Capistrano issues a "chmod g+w" command over the entire check-out branch.

    The solution was to change the permissions in a :after_update_code task.

    The thing is, site5 is cheap but it so sloooooooooow! not sure how long I am going to pay for such a service.





    # Capistrano deployment script on site 5
    # Jean-Michel Garnier
    # Tested with capistrano 1.40 14/02/2007
    #
    # Inspired by http://fluctisonous.com/2006/11/19/moving-home-with-capistrano-on-site5
    # And Kyle Daigle http://forums.asmallorange.com/index.php?showtopic=8892

    # Usage:
    # the first time: cap setup
    #
    # Then to initialize the db the first time- if you have a bootstrap task like in mephisto -
    # env BOOTSTRAP=true cap deploy
    #
    # otherwise: cap deploy


    # =============================================================================
    # Customize these variables
    # =============================================================================

    set :application, "bicinostrum"

    set :user, "your userlogin at site5" # defaults to the currently logged in user
    set :password, "your site5 password"
    set :domain, "21croissants.com" # your applications domain name
    #set :deploy_server, "you.server.name" # the url of your server


    set :public_html, "/home/#{user}/public_html/#{application}"
    set :svn_repositoty_home, "rails/svn_repository"
    set :rails_apps_home, "rails/webapps"

    # =============================================================================
    # Do not change these variables
    # =============================================================================
    set :use_sudo, false
    set :rails_env, "production"
    set :deploy_to, "/home/#{user}/#{rails_apps_home}/#{application}"
    set :repository, "svn+ssh://#{user}@#{domain}/home/#{user}/#{svn_repositoty_home}/#{application}/trunk"

    # =============================================================================
    # ROLES
    # =============================================================================
    # You can define any number of roles, each of which contains any number of
    # machines. Roles might include such things as :web, or :app, or :db, defining
    # what the purpose of each machine is. You can also specify options that can
    # be used to single out a specific subset of boxes in a particular role, like
    # :primary => true.

    role :web, domain
    role :app, domain
    role :db, domain

    # =============================================================================
    # SSH OPTIONS ?
    # =============================================================================

    set :svn_passphrase, ""
    # ssh_options[:port] = 25

    # =============================================================================
    # TASKS
    # =============================================================================
    # Define tasks that run on all (or only some) of the machines. You can specify
    # a role (or set of roles) that each task should be executed on. You can also
    # narrow the set of servers to a subset of a role by specifying options, which
    # must match the options given for the servers to select (like :primary => true)

    desc "Restart the web server. Overrides the default task for Site5 use"
    task :restart, :roles => :app do
    run "skill -9 -u#{user} -cdispatch.fcgi"
    end

    task :after_setup, :roles => :app do
    run <<-CMD
    ln -s /home/#{user}/#{rails_apps_home}/#{application}/current/public/ #{public_html}
    CMD

    end

    task :after_update_code, :roles => :app do
    run "find #{release_path}/public -type d -exec chmod 0755 {} \\;"
    run "find #{release_path}/public -type f -exec chmod 0644 {} \\;"
    run "chmod 0755 #{release_path}/public/dispatch.*"

    if ENV['BOOTSTRAP']
    run <<-EOF
    cd #{release_path} && rake db:bootstrap RAILS_ENV=production
    EOF
    else
    run <<-EOF
    cd #{release_path} && rake db:migrate RAILS_ENV=production
    EOF
    end
    end

    13 February 2007

    Unlocking an HTC S620 WIFI phone in 5 minutes / Resisting to telco thanks to voip

    http://www.pianetacellulare.it/Modelli/immagini/s620_htc.jpg


    In most of european countries, there are 3-5 operators who have agreed to maintain very expensive prices for mobile phone communications and text messaging. This is obviously an unofficially agreement and there will be some kind of justice one day, probably from the European Commission...

    But today is a great day, I have unlocked in 5 minutes the HTC S620 I bought on eBay in the US for 220€ using IMEI-Check services (20 pounds). This is still cheaper than the 489€ retail price in Europe! I did not want to buy any Microsoft based device but I was not convinced by what I read about symbian os smart-phones (correct me if I am wrong).

    The image “http://en.fon.com/lib/tools/fgf/home_images/en/en_logoFon.png” cannot be displayed, because it contains errors.

    Hopefully, there are a lot of open Wifi networks (still) + the fact the FON network is growing rapidly, I am confident I will be able to use Skype and call for free my relatives abroad, make voip phone calls at the rate of 12 centimes instead of 18 centimes (I am not sure about that, the price system of mobile phone communication was not not made to be readable) (plus the fact they always fucking charge the first minute even if the conversation lasted 1 second), and especially send text messages for 7 centimes instead of 20 centimes with my current pay-as-go contract!!!

    06 February 2007

    Freezing the gems of a specific version of Rails

    rake rails:freeze:gems VERSION=1.1.6

    01 February 2007

    Installing Java plugin for firefox 2.0 on Ubuntu Feisty

    Automatix won't work - the symlink to java plugin won't be copied - and you'll have to do it manually ... The next step would be to update the Automatix script ...

    sudo apt-get install sun-java6-plugin
    cd /opt/firefox/plugins
    sudo ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so ./libjavaplugin_oji.so

    27 January 2007

    Services

    I speak

    Agile Development on Rails

    I deliver software that matters, with very short delivery cycles and high quality.

    I work with the following methods and tools:

    Ruby on Rails experience

    See my "Working with Rails" profile

    Training on testing

    Using Yugma / ichat, Skype and screencasts, I can *conduct* some remote pair programming and teach you the art of testing.

    I can also come to your office to pair with you and give you some extensive training on testing a Rails application.

    Please contact me if you have any queries.

    10 January 2007

    Rails 1.2.1 duplicate lines Simian Report

    I have been evaluating the excellent and super fast Similarity Analyser by Red Hill Consulting to generate a duplicate lines reports from Rails 1.2.1 source code (excluding the tests) with a threshold of 5 lines.

    May I insist on the threshold parameter: this parameter must be >=5, hence identical blocks of lines whose length official features page of Simian.

    Update 23/01/2007: There was a bug in simian 2.2.12 which was considering lines containing the "end" keyword as duplicates. Hopefully, Simmon Harris fixed it in couple of days and released the version 2.2.13.

    I have written a bit of code to generate the following html report from simian text report, I will publish as soon as it I have put into a gem and document it.

    Here is the report generated on the 23th of January 2007:


    Similarity Analyser 2.2.13 - http://www.redhillconsulting.com.au/products/simian/index.html

    Copyright (c) 2003-07 RedHill Consulting Pty. Ltd. All rights reserved.

    Simian is not free unless used solely for non-commercial or evaluation purposes.

    {failOnDuplication=true, ignoreCharacterCase=true, ignoreCurlyBraces=true, ignoreIdentifierCase=true, ignoreModifiers=true, ignoreStringCase=true, threshold=5}

    Loading (recursively) *[^t][^e][^s][^t].rb from /home/jeanmichel/ruby/projects/duplicate-lines-report/tmp

    Found 5 duplicate lines in the following files:

       Between lines 745 and 751 in activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb

       Between lines 90 and 96 in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

    Found 5 duplicate lines in the following files:

       Between lines 688 and 692 in railties/lib/initializer.rb

       Between lines 37 and 41 in activesupport/lib/active_support/ordered_options.rb

    Found 5 duplicate lines in the following files:

       Between lines 218 and 224 in actionmailer/lib/action_mailer/vendor/tmail/encode.rb

       Between lines 147 and 153 in actionmailer/lib/action_mailer/vendor/tmail/encode.rb

    Found 5 duplicate lines in the following files:

       Between lines 418 and 424 in actionpack/lib/action_controller/assertions/selector_assertions.rb

       Between lines 293 and 301 in actionpack/lib/action_controller/assertions/selector_assertions.rb

    Found 5 duplicate lines in the following files:

       Between lines 2 and 7 in railties/lib/commands/servers/webrick.rb

       Between lines 9 and 14 in railties/lib/commands/servers/mongrel.rb

    Found 5 duplicate lines in the following files:

       Between lines 95 and 100 in activerecord/lib/active_record/deprecated_associations.rb

       Between lines 35 and 40 in activerecord/lib/active_record/deprecated_associations.rb

    Found 5 duplicate lines in the following files:

       Between lines 43 and 47 in actionwebservice/examples/metaWeblog/apis/blogger_api.rb

       Between lines 34 and 38 in actionwebservice/examples/metaWeblog/apis/blogger_api.rb

    Found 5 duplicate lines in the following files:

       Between lines 77 and 81 in actionwebservice/examples/googlesearch/delegated/google_search_service.rb

       Between lines 27 and 31 in actionwebservice/examples/googlesearch/direct/search_controller.rb

       Between lines 26 and 30 in actionwebservice/examples/googlesearch/autoloading/google_search_controller.rb

    Found 5 duplicate lines in the following files:

       Between lines 178 and 183 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

       Between lines 127 and 132 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

    Found 5 duplicate lines in the following files:

       Between lines 676 and 683 in railties/lib/initializer.rb

       Between lines 6 and 13 in activesupport/lib/active_support/ordered_options.rb

    Found 5 duplicate lines in the following files:

       Between lines 679 and 683 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

       Between lines 678 and 682 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

    Found 5 duplicate lines in the following files:

       Between lines 1375 and 1381 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

       Between lines 1359 and 1365 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

    Found 5 duplicate lines in the following files:

       Between lines 68 and 72 in activerecord/lib/active_record/connection_adapters/openbase_adapter.rb

       Between lines 117 and 121 in activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

    Found 5 duplicate lines in the following files:

       Between lines 25 and 31 in railties/lib/rails_generator.rb

       Between lines 29 and 33 in actionpack/lib/action_controller.rb

       Between lines 29 and 33 in activerecord/lib/active_record.rb

    Found 5 duplicate lines in the following files:

       Between lines 202 and 213 in activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

       Between lines 180 and 193 in activerecord/lib/active_record/connection_adapters/oracle_adapter.rb

    Found 5 duplicate lines in the following files:

       Between lines 831 and 837 in railties/lib/commands/plugin.rb

       Between lines 809 and 815 in railties/lib/commands/plugin.rb

       Between lines 774 and 780 in railties/lib/commands/plugin.rb

       Between lines 603 and 609 in railties/lib/commands/plugin.rb

       Between lines 573 and 579 in railties/lib/commands/plugin.rb

       Between lines 546 and 552 in railties/lib/commands/plugin.rb

    Found 5 duplicate lines in the following files:

       Between lines 5 and 16 in railties/lib/commands/server.rb

       Between lines 78 and 89 in railties/lib/commands/process/spawner.rb

    Found 5 duplicate lines in the following files:

       Between lines 226 and 235 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

       Between lines 208 and 218 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

    Found 5 duplicate lines in the following files:

       Between lines 2 and 7 in railties/lib/rails/version.rb

       Between lines 2 and 7 in actionwebservice/lib/action_web_service/version.rb

    Found 5 duplicate lines in the following files:

       Between lines 12 and 18 in activerecord/lib/active_record/connection_adapters/openbase_adapter.rb

       Between lines 70 and 75 in activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    Found 5 duplicate lines in the following files:

       Between lines 499 and 503 in activerecord/lib/active_record/connection_adapters/firebird_adapter.rb

       Between lines 478 and 482 in activerecord/lib/active_record/connection_adapters/firebird_adapter.rb

    Found 5 duplicate lines in the following files:

       Between lines 317 and 321 in actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb

       Between lines 296 and 300 in actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb

       Between lines 277 and 281 in actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb

    Found 5 duplicate lines in the following files:

       Between lines 1 and 7 in activerecord/test/fixtures/migrations/1_people_have_last_names.rb

       Between lines 1 and 7 in activerecord/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb

       Between lines 1 and 7 in activerecord/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb

    Found 5 duplicate lines in the following files:

       Between lines 680 and 685 in activerecord/lib/active_record/vendor/simple.rb

       Between lines 627 and 631 in activerecord/lib/active_record/vendor/simple.rb

    Found 6 duplicate lines in the following files:

       Between lines 16 and 25 in activesupport/lib/active_support/core_ext/time/conversions.rb

       Between lines 11 and 21 in activesupport/lib/active_support/core_ext/date/conversions.rb

    Found 6 duplicate lines in the following files:

       Between lines 197 and 202 in activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

       Between lines 134 and 139 in activerecord/lib/active_record/connection_adapters/sybase_adapter.rb

    Found 6 duplicate lines in the following files:

       Between lines 284 and 291 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

       Between lines 344 and 349 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

    Found 6 duplicate lines in the following files:

       Between lines 267 and 272 in activerecord/lib/active_record/validations.rb

       Between lines 825 and 830 in activerecord/lib/active_record/validations.rb

    Found 6 duplicate lines in the following files:

       Between lines 277 and 285 in actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb

       Between lines 296 and 304 in actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb

    Found 6 duplicate lines in the following files:

       Between lines 358 and 365 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

       Between lines 498 and 505 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

    Found 6 duplicate lines in the following files:

       Between lines 175 and 185 in activerecord/lib/active_record/connection_adapters/oracle_adapter.rb

       Between lines 108 and 118 in activerecord/lib/active_record/connection_adapters/openbase_adapter.rb

    Found 7 duplicate lines in the following files:

       Between lines 408 and 414 in actionwebservice/test/abstract_dispatcher.rb

       Between lines 398 and 404 in actionwebservice/test/abstract_dispatcher.rb

    Found 7 duplicate lines in the following files:

       Between lines 518 and 530 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

       Between lines 221 and 233 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

    Found 7 duplicate lines in the following files:

       Between lines 76 and 82 in actionmailer/lib/action_mailer/vendor/tmail/scanner_r.rb

       Between lines 68 and 74 in actionmailer/lib/action_mailer/vendor/tmail/scanner_r.rb

    Found 7 duplicate lines in the following files:

       Between lines 164 and 176 in activerecord/lib/active_record/connection_adapters/openbase_adapter.rb

       Between lines 264 and 276 in activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    Found 7 duplicate lines in the following files:

       Between lines 1 and 10 in activerecord/test/fixtures/migrations/3_innocent_jointable.rb

       Between lines 1 and 10 in activerecord/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb

       Between lines 1 and 10 in activerecord/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb

    Found 7 duplicate lines in the following files:

       Between lines 181 and 192 in actionpack/lib/action_controller/assertions/selector_assertions.rb

       Between lines 60 and 67 in actionpack/lib/action_controller/assertions/selector_assertions.rb

    Found 7 duplicate lines in the following files:

       Between lines 204 and 213 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

       Between lines 148 and 157 in actionmailer/lib/action_mailer/vendor/tmail/parser.rb

    Found 7 duplicate lines in the following files:

       Between lines 279 and 285 in activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb

       Between lines 94 and 100 in activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    Found 7 duplicate lines in the following files:

       Between lines 123 and 132 in actionpack/lib/action_controller/assertions/response_assertions.rb

       Between lines 69 and 78 in actionpack/lib/action_controller/assertions/routing_assertions.rb

    Found 7 duplicate lines in the following files:

       Between lines 18 and 25 in railties/lib/rails_generator/generators/components/web_service/web_service_generator.rb

       Between lines 14 and 21 in railties/lib/rails_generator/generators/components/controller/controller_generator.rb

    Found 7 duplicate lines in the following files:

       Between lines 506 and 512 in activerecord/lib/active_record/connection_adapters/sybase_adapter.rb

       Between lines 534 and 540 in activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

    Found 8 duplicate lines in the following files:

       Between lines 58 and 69 in railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb

       Between lines 18 and 29 in railties/lib/rails_generator/generators/components/resource/resource_generator.rb

       Between lines 18 and 29 in railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb

    Found 8 duplicate lines in the following files:

       Between lines 37 and 49 in actionmailer/lib/action_mailer/vendor/tmail/stringio.rb

       Between lines 178 and 190 in actionmailer/lib/action_mailer/vendor/tmail/stringio.rb

    Found 8 duplicate lines in the following files:

       Between lines 24 and 33 in activerecord/lib/active_record.rb

       Between lines 24 and 33 in actionpack/lib/action_controller.rb

    Found 8 duplicate lines in the following files:

       Between lines 366 and 374 in activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

       Between lines 219 and 227 in activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

    Found 8 duplicate lines in the following files:

       Between lines 5 and 18 in activesupport/lib/active_support/core_ext/module/attribute_accessors.rb

       Between lines 23 and 36 in activesupport/lib/active_support/core_ext/module/attribute_accessors.rb

    Found 8 duplicate lines in the following files:

       Between lines 5 and 18 in activesupport/lib/active_support/core_ext/class/attribute_accessors.rb

       Between lines 23 and 36 in activesupport/lib/active_support/core_ext/class/attribute_accessors.rb

    Found 9 duplicate lines in the following files:

       Between lines 6 and 14 in railties/lib/commands/process/spawner.rb

       Between lines 3 and 11 in railties/lib/commands/process/spinner.rb

       Between lines 4 and 12 in activesupport/lib/active_support/core_ext/kernel/daemonizing.rb

    Found 10 duplicate lines in the following files:

       Between lines 77 and 88 in actionpack/lib/action_controller/assertions/selector_assertions.rb

       Between lines 195 and 210 in actionpack/lib/action_controller/assertions/selector_assertions.rb

    Found 10 duplicate lines in the following files:

       Between lines 740 and 757 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

       Between lines 836 and 853 in actionmailer/lib/action_mailer/vendor/tmail/header.rb

    Found 10 duplicate lines in the following files:

       Between lines 458 and 469 in activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb

       Between lines 482 and 493 in activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb

    Found 11 duplicate lines in the following files:

       Between lines 64 and 75 in actionwebservice/examples/googlesearch/delegated/google_search_service.rb

       Between lines 14 and 25 in actionwebservice/examples/googlesearch/direct/search_controller.rb

       Between lines 13 and 24 in actionwebservice/examples/googlesearch/autoloading/google_search_controller.rb

    Found 12 duplicate lines in the following files:

       Between lines 40 and 52 in railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb

       Between lines 2 and 14 in railties/lib/rails_generator/generators/components/resource/resource_generator.rb

       Between lines 2 and 14 in railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb

    Found 12 duplicate lines in the following files:

       Between lines 84 and 106 in actionwebservice/examples/googlesearch/delegated/google_search_service.rb

       Between lines 33 and 55 in actionwebservice/examples/googlesearch/autoloading/google_search_controller.rb

       Between lines 34 and 56 in actionwebservice/examples/googlesearch/direct/search_controller.rb

    Found 19 duplicate lines in the following files:

       Between lines 53 and 81 in railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb

       Between lines 42 and 69 in railties/lib/rails_generator/generators/components/resource/resource_generator.rb

    Found 29 duplicate lines in the following files:

       Between lines 2 and 40 in railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb

       Between lines 2 and 40 in railties/lib/rails_generator/generators/components/resource/resource_generator.rb

    Found 37 duplicate lines in the following files:

       Between lines 3 and 56 in actionwebservice/examples/googlesearch/direct/search_controller.rb

       Between lines 2 and 55 in actionwebservice/examples/googlesearch/autoloading/google_search_controller.rb

    Found 38 duplicate lines in the following files:

       Between lines 2 and 81 in activesupport/lib/active_support/binding_of_caller.rb

       Between lines 2 and 82 in railties/lib/binding_of_caller.rb

    Found 41 duplicate lines in the following files:

       Between lines 1 and 49 in actionwebservice/examples/googlesearch/delegated/google_search_service.rb

       Between lines 1 and 49 in actionwebservice/examples/googlesearch/direct/google_search_api.rb

       Between lines 1 and 49 in actionwebservice/examples/googlesearch/autoloading/google_search_api.rb

    Found 1074 duplicate lines in 121 blocks in 60 files

    Processed a total of 23454 significant (46787 raw) lines in 375 files

    Processing time: 1.347sec



    Now the debate is opened about what to do with these reports !!!