Using SWT with JRuby

JRuby is a Java implementation of the Ruby programming language. One of the strengths of a Java implementation is that Java libraries can be used within Ruby code, the Ruby way (and that is cool, as we have seen!); the weaknesses are that this means that the code is a lot slower to execute, and similar to what happens with Jython (the Java implementation of Python) the Java implementation lags behind the “official” version. This is obviously to be expected, and in fairness to the JRuby guys, they are pretty reactive!

This post will describe how to use SWT with JRuby. It is written for Ubuntu, but more than likely very similar on other platforms.

Setup

First, get JRuby: I’ll be using 1.4.0 (which was released last month). Install it in a location that I’ll be calling $JRUBY_HOME. Add $JRUBY_HOME/bin into your $PATH so that you can run the jruby command:

sebastien@kilkenny:~$ jruby --version
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) 
(Java HotSpot(TM) Client VM 1.6.0_12) [i386-java]

Get SWT from here (this article will be using SWT 3.5.1 for Linux), and extract swt.jar into $JRUBY_HOME/lib: that’s a quick way of making the jar available to JRuby.

Once everything is set up, we can begin with a very simple example.

First Quick Example

(I have posted the following example as a snippet on dreamincode at the time of writing, it is still awaiting approval)

require 'java'

display = org.eclipse.swt.widgets.Display.new
shell = org.eclipse.swt.widgets.Shell.new(display)
shell.setSize(800, 600)
shell.setText("First Example")

shell.setLayout(org.eclipse.swt.layout.RowLayout.new)
org.eclipse.swt.widgets.Button.new(shell, \
             org.eclipse.swt.SWT::PUSH).setText("Click me!")

shell.open
# Classic SWT stuff
while (!shell.isDisposed) do
  display.sleep unless display.readAndDispatch
end
display.dispose

This opens a nice and simple window:

Typical to JRuby, the first thing we do here is require 'java' to be able to call Java classes from our ruby code. And then, from then on, it is all SWT code: create a Display class, and with this Display, create a new Shell (window), whose size is 800×600. Then set the layout as RowLayout, and add a Button. Make the window visible with open, and the rest of the code is pretty much common SWT code to keep the window open until the application is shut down, at which point, the display is cleared up.

As you can see from above, the only tricky things are:

  • the fully-qualified names of the Java classes have to be provided (we’ll see a way of avoiding this in the next example);
  • static variables have to be accessed with ::

And Now, For a More Advanced Example

The more advanced example will read the RSS feed from weblogism, and fill in some labels, and put items in a table. Ruby provides a neat rss package, and good example of how to use it can be found here.

One of the things you’ll want to look at is the repetition of the Java packages: this is a bit tedious, so we have to find a way of avoiding this. One way is to call include_class to include the Java classes by their name. One trick is to list all the classes of a given package in an array, and to include them with an iterator:

%w(Display Shell Label Table TableColumn TableItem).each do
  |c|
  include_class "org.eclipse.swt.widgets." + c 
end

With this knowledge, I can now give you the example:

require 'java'
require 'open-uri'
require 'rss'

include_class "org.eclipse.swt.SWT"
# Neat little trick to include several classes from the same package.
%w(Display Shell Label Table TableColumn TableItem).each do
    |c|
    include_class "org.eclipse.swt.widgets." + c 
end
%w(GridLayout GridData).each do
    |c|
    include_class "org.eclipse.swt.layout." + c
end

# uppercase variable is constant
FEED_URL = 'http://www.weblogism.com/rss/'

class RssViewer
  attr_reader :shell, :display

  def initialize
    rss = get_messages

    @display = Display.new
    @shell = Shell.new(display)
    @shell.setSize(800, 600)
    @shell.setText("Second Example")

    gridlayout = GridLayout.new
    gridlayout.numColumns = 2
    @shell.setLayout(gridlayout)
    name = Label.new(shell, SWT::NONE)
    name.setText("Name:")
    name.setLayoutData(GridData.new(GridData::VERTICAL_ALIGN_END))
    Label.new(shell, SWT::NONE).setText(rss.channel.title)

    Label.new(shell, SWT::NONE).setText("URL:")
    Label.new(shell, SWT::NONE).setText(rss.channel.link)

    table = Table.new(shell, SWT::MULTI | SWT::BORDER | SWT::FULL_SELECTION)
    table.setLinesVisible(true)
    table.setHeaderVisible(true)

    gridData = GridData.new(GridData::FILL_BOTH)
    gridData.horizontalSpan = 2
    table.setLayoutData(gridData)

    # Set the header of columns.
    columns = %w(Title Date Author)
    columns.each{ |h| TableColumn.new(table, SWT::NONE).setText(h) }
    rss.channel.items.each do 
      |i|
      item = TableItem.new(table, SWT::NONE) 
      item.setText(0, i.title)
      item.setText(1, i.dc_creator)
      item.setText(2, i.date.to_s)
      puts i
    end
    # Each column then needs to be packed to display properly
    for i in 0...columns.size
      table.getColumn(i).pack()
    end

  end

  def show
    @shell.open
    while (!@shell.isDisposed) do
      @display.sleep unless @display.readAndDispatch
    end
    @display.dispose
  end

  def get_messages
    rss_content = ''
    # Read URL
    open(FEED_URL) { |f| rss_content = f.read }
    # and parse.  "false" means "no validation"
    RSS::Parser.parse(rss_content, false)
  end
end

RssViewer.new.show

This simple snippet gives the following window:

Conclusion

The examples above are not that far away from the Java snippets proposed on the SWT web site. This shows how JRuby can be easy to learn if you are already familiar with Java – and you get to play with a few syntactic niceties like the iterators that ruby brings in.

However, it is true that performance can still be an issue on some big apps, but hopefully this will improve in the coming months.

Comment

 
---

That Whole Interfaces and Polymorphism Thing

This post is intended as a follow-up to this discussion in the dreamincode.net Java forum, and this follow-up. I don’t normally get drawn into these sterile debates, but the thing that ticked me off here was that it is all done under the cover of “educating people.” Being wrong is one thing, being wrong and wrapping falsities under layers of apparent knowledge to impart “wisdom” to others whilst being condescending towards other posters is another one.

The whole point of this post is to discuss the incorrect statement that “interfaces in Java cannot define a IS-A relationship.” And explain why this is incorrect.

I have indeed been told that the following is absurd and nonsensical:

// Payable is an interface, and Employee implements Payable
Payable employee = new Employee();

In normal cases, I would have laughed it off, and moved on (or in the case of an interview, I would have thanked the candidate, and parted ways). But there is a pedagogical dimension to all this, so here I am again.

I would certainly dislike being criticized for not giving references, so at the end of this post I have listed a few; however, I’ll be mostly speaking about my own experience as a Java developer, so yeah, this will be biased big time.

As said before, I truly believe that the statement “using Java interfaces for polymorphism is absurd” is symptomatic of 3 things:

  • The misunderstanding of what Java interfaces are all about,
  • The scorn the implements keyword is treated with,
  • The immoderate idolization some developers devote to inheritance.

Interfaces in Java

The Spec

Let’s look at the Java Language spec1 has to say about interfaces:

An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods. (…) A variable whose declared type is an interface type may have as its value a reference to any instance of a class which implements the specified interface.

This means that (i) an interface is a type (and we could actually stop this post here), and (ii) this is totally valid stuff:

Payable employee = new Employee();

if Employee implements Payable.

(This is also valid, mind you:

public interface Payable {
    long baseSalary = 10000;
    public void pay();
}
public class Employee implements Payable {
    public void pay() {
        System.out.println("pay Employee " + f);
    }

    public static void main(String[] args) {
        Payable p = new Employee();
        p.pay();
    }
}

but that’s irrelevant.)

However, the fact it is valid code has never been in doubt, but rather the intent was. Right so, let’s carry on.

Interface as a Type

To quote the Java Tutorial2, in the Using Interfaces as Types ([sarcasm]wow, how can these Sun people use such a nonsensical title?[/sarcasm]) section:

When they [“relatable” objects] implement Relatable, they can be of both their own class (or superclass) type and a Relatable type. This gives them some of the advantages of multiple inheritance, where they can have behavior from both a superclass and an interface.

The interesting thing here is the word “behaviour.” The interface brings behaviour to a class; we’ll see what this means in terms of object-oriented programming. We will also see that you can’t just go and remove an interface to prove a heavily-flawed demonstrative point.

instanceof

instanceof is the type comparison operator in Java. In the case of an interface, this is indeed valid:

new Employee() instanceof Payable

and returns true.

According to the Java Language spec1 (See here):

It is a compile-time error if the ReferenceType mentioned after the instanceof operator does not denote a reifiable type (§4.7).

Which does indicate, if there was any doubt about it, that interfaces are reifiable types.

The Serializable case

To finish with this Java interface analysis, let’s look at the Serializable interface. Wait. It’s empty, what is there to look at? Precisely. What is an empty interface supposed to bring to the table? What is the point of marking classes as Serializable when there is no method to implement? The point is to give an object the Serializable type to use polymorphism when invoking the serialization mechanisms. In practice, this is done through the instanceof keyword, but if the object is not of type Serializable, the code throws a NotSerializableException.

Interfaces and OOP

Apparently, it was not just a Java problem anymore. The big guns had to be taken out, and OOP was invoked in the grand pursuit of Java interfaces slurring.

First of all, let’s make something clear: Java interfaces are not a bijection to interfaces in the OOP sense. We have on one hand a programming language feature, and on the other hand an OOP concept. It is not just that the 2 sets mismatch: they are not on the same plane at all.

Interface vs. Implementation

When it comes to design, Design Pattern3 is the unavoidable reference. The section called Class versus Interface Inheritance discusses at length the importance of programming to an interface.

It’s important to understand the difference between an object’s class and its type.

An object’s class defines how the object is implemented. The class defines the object’s internal state and the implementation of its operations. In contrast, an object’s type only refers to its interface—the set of requests to which it can respond. An object can have many types, and objects of different classes can have the same type.

In this chapter appears the principle that any design-savvy developer knows: “Program to an interface, not an implementation“.

Don’t declare variables to be instances of particular concrete classes. Instead, commit only to an interface defined by an abstract class.

What do they mean by “programming to an interface”? It means that instead of programming around a specific implementation, it is preferable to pass around an interface (in the OOP sense, not necessarily Java interface) and make sure the behaviour is decided at runtime.

The reason is quite straightforward: you don’t want to be tied to a particular implementation. The classic textbook example of this is the Collection interface. Beginners usually code collections like this:

ArrayList words = new ArrayList();

All the subsequent method calls then would take an ArrayList<String> as a parameter.

The problem with this approach is that if one day, it is decided to switch to a different implementation (to get a synchronized collection, or to have the words sorted directly with TreeSet, or to switch to the kick-ass Google Collections library), you’ll have to go through lots of code and do the change. Ideally, you want to avoid this at all costs. But by tying your code to an implementation, you leave the door open to subsequent changes – and developers get annoyed with interface changes (interface as in API, obviously). “WTF? This method was requiring an ArrayList last week, and now it requires a TreeSet?!”

(Where I work, changing an interface potentially means that client jars to Web services have to be redeployed, and the 2 or 3 major in-house applications have to be re-released to include the change. That’s usually a messy affair, and always a bit risky, so you usually avoid changing the exposed services)

On the other hand, if you write:

Collection words = new ArrayList();

you can hide the actual implementation, and parse your elements with Iterator without worrying about potential changes.

The same way you want to program to interface to avoid tight coupling with a specific implementation, you also want to avoid inheriting implementation, as changes to the implementation can have adverse effect on all the subclasses.

Avoid coupling, favour composition over inheritance, program to interfaces, not implementations, that’s the OO principles that any developer would find when opening a decent OOP book. Interestingly enough, this has been discussed at length elsewhere.

Questions?

But if I remove the interface, it is working still. You’ve lost nothing.

My oh my. Again, any candidate stating this in an interview would be out of the door in the next minute.

For this one, we’ll need an example. Let’s say, hey, that Payable one.

public interface Payable {
  public void pay();
}

public class Employee implements Payable {
  public void pay() {
    System.out.println("pay Employee");
  }
}

public class Contractor implements Payable {
  public void pay() {
    System.out.println("pay Contractor");
  }
}

public static void main(String[] args) {
  Employee e1 = new Employee();
  e1.pay();

  Payable e2 = new Employee();
  e2.pay();

  Payable e3 = new Contractor();
  e3.pay();

  Contractor e4 = new Contractor();
  e4.pay();
}

This prints out:

pay Employee
pay Employee
pay Contractor
pay Contractor

Now remove Payable. Not only they did lose something, but they lost something huge: they lost their type! All these methods relying on the interface would fail:

public void hire(Payable p) {
// ...
}

Contractor and Employee also lost their relationship to each other. You just can’t go removing stuff from your design without removing the precious information it was bringing in the first place. That would be just as bad as removing Payable from below:

public class Payable {
  public void pay() {
    System.out.println("pay Payable");
  }
}

public class Employee extends Payable {
  public void pay() {
    System.out.println("pay Employee");
  }
}

public class Contractor extends Payable {
  public void pay() {
    System.out.println("pay Contractor");
  }
}

Similar to Payable as an interface, Payable as a class “doesn’t do anything”, so let’s go and remove it; but again here, you lose a vital thing: the fact that Employee and Contractor are Payable. Everyone can see this is silly, and yet this is exactly the same thing with interfaces.

One could argue that Payable could have defined other behaviour not overridden by the subclasses, but here it is not the case: it happens in real life too. Usually, you’d make this class abstract, but it’s not always in your control: Payable could be a third-party class you’re trying to adapt (as in, the Adapter design pattern) into your own application.

The confirmation to this is the Serializable example mentioned earlier which must be the epitome of the “useless” interface (it doesn’t define any method): remove it, and it makes a world of difference.

Hey, but Payable is an interface name, it wouldn’t be a class name

This is just a naming convention. Some people suffix their interfaces with -able, some prefix it with I (like IComponent). The problem with this naming convention is that it has contributed to the under-component status interfaces are suffering from. More and more you see this trend being reversed to put the onus back onto the interface (especially with the coming of Spring), and interfaces have the component name, and implementations have suffixed with Impl:

public interface Employee {
  public void pay();
}

public class EmployeeImpl implements Employee {
  public void pay() {
    System.out.println("pay EmployeeImpl");
  }
}

This is quite some psychological leap! What this means is that the focus is now on the interface, and that the implementation comes second. Just like it should.

You seem to be confusing abstract classes and interfaces. Are you?

No. I put them in the same bag because they both are useful to define an interface in the OOP sense. From a technical point of view, they are not the same, and they have their own pros and cons. Depending on the situation, you’ll want to favour one or the other, bearing in mind that if you inherit an abstract class, you cannot inherit anything else, but you can provide a default implementation, whereas you can implement lots of different interfaces with their own hierarchy, but face to change all implementing classes if you change anything. Choosing an abstract class over an interface makes also a strong design point (since indeed you cannot inherit anything else); however, this doesn’t mean the type provided by the interfaces is not also important, or should be discarded.

Conclusion

Interfaces have not been defined in the Java language just to “ensure some methods are implemented in the class that implements them”, or as a “CAN-DO” relationship. This view is far too simplistic as we have seen above, and there is no doubt (at least in my mind) that Java interfaces do provide a “IS-A” relationship, and that it is actually their whole raison d‘être. Unfortunately, failing to understand this means you cannot possible leverage technologies such as Spring, mocking, Java proxies, etc. but also shows a fairly questionable knowledge of Java itself, as everything in the language is based around this: serialization, collections, sorting, listeners, EJBs, etc.

1 The Java Language Specification, http://java.sun.com/docs/books/jls/

2 Learning the Java Language, http://java.sun.com/docs/books/tutorial/java/IandI/interfaceAsType.html

3 Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma et al.

4 Code Complete, Steve McConnell.

Comment [3]

 
---

Mocking Static Method Calls

When working with legacy code, my pet hate is to come across a Singleton, or a static method call that not only pulls out tons of dependencies, but also assumes that resources are out there, running.

The typical case I have been struggling with these past few months is “unit tests” assuming the application server is running to retrieve some EJBs. Yes, that’s right: unit tests that require the application server to run, with the database connections and all available. Not only you’re dragging the whole application to run to simply test one method, but it also takes far far too long. As it also requires the data sources to be available, you may also end up playing with test data in an unknown state and therefore get unpredictable results. In short, far from ideal from a unit testing point of view.

So you’re thinking, ok, I’ll mock the singleton/static method call, everything will be hunky-dory. But a singleton cannot be subclassed (the default constructor is private), and you cannot use polymorphism to mock a static method call. I had tried PowerMock to overcome this issue, but I have run into issues with JUnit 3, and couldn’t get it to work.

And today, after some search came the light at the end of the tunnel: jmockit.

Say you have a class BigUglyHelper which provides services as static methods:
notextile.

public class BigUglyHelper {
  public static String doStuff() {
    // Call an EJB session that calls an Entity bean, or Hibernate,
    // do fun stuff like paging or sorting, and return a String.
   return "BigUglyHelper";
  }
}

You are writing the class ClassUnderTest which, unfortunately, uses BigUglyHelper:

public class ClassUnderTest {
  public String getMyStuff() {
     String text = BigUglyHelper.doStuff();
     // do fancy things with text
     return text;
  }
}

Now, the unit test would be straightforward:

public class TestClassUnderTest extends TestCase {
  public void testGetMyStuff() {
    ClassUnderTest c = new ClassUnderTest();
    assertNotNull(c);
    // do other interesting asserts with c
  }
}

Straightforward? Nah. Remember, you need to have Weblogic (or WebSphere, or JBoss or…) running, you have to have your app deployed, you have to have proper data in your database, etc. Tsss.

So jmockit comes to the rescue, and that’s cool stuff. First, the mock for our class with the static methods:

public class SweetLittleMock {
        // Same signature as static method in real class
        public static String doStuff() {
            return "SweetLittleMock";
    }
}
And then, the test case.
public class TestClassUnderTest extends TestCase {

   @Override
    public void setUp() {
        Mockit.redefineMethods(BigUglyHelper.class, SweetLittleMock.class);
    }

   public void testGetMyStuff() {
        ClassUnderTest c = new ClassUnderTest();
        assertNotNull(c);
        assertEquals("SweetLittleMock", c.getMyStuff());
    }
}
 

The astounding thing is that I only have jmockit and JUnit in the classpath, so there is no jar dependency headache, and that’s for me a big big plus.

Singleton Testing

For testing singletons, it is not as simple, as getInstance() returns a reference to the Singleton. You have to use expectations and the cool thing about them is that they behave just the way you’d want a mocking framework to.

So, here is our nasty Singleton:

public class Singleton {
    private static Singleton instance;

   private Singleton() {
    }

   public static Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }

   public String superService() {
        return "Singleton";
    }
}

with its superService() (so super it can only be provided by a single instance!!). This singleton is used by MyNeatClass that we’re trying to unit test:

public class MyNeatClass {

   public String doStuff() {
        return Singleton.getInstance().superService();
    }
}

There’s not much to it, but the key thing is that the Singleton is drawing unwanted resources into the unit test, and we don’t want that. So here is out test class (note that it extends JMockitTestCase since we are using JUnit 3. Annotations are the way to go if you’re on JUnit 4):

public class TestMyNeatClass extends JMockitTestCase {

    public void testDoStuff() {
        new Expectations() {

            Singleton singleton;

            {
                Singleton.getInstance();
                returns(singleton);
                singleton.superService();
                returns(“MockSingleton”);
            }
        };
        MyNeatClass neatClass = new MyNeatClass();
        assertNotNull(neatClass.doStuff());
        assertEquals(“MockSingleton”, neatClass.doStuff());
    }
}

The important bit is the Expectations: it is defined as an anonymous inner class. It defines a mock field (singleton), and an initialization block that records the method calls, and indicates what these method calls should return. For example, Singleton.getInstance(); will return singleton (return(singleton);).

jmockit definitely becomes a weapon of choice when dealing with legacy code where you are trying to bring in unit tests.

Comment [1]

 
---

Vaccination grippale forcée

Ça doit être comme la grippe, ça doit être de saison : ces jours-ci je reçois moultes électromissives d’un goût plutôt douteux m’invectivant de m’alarmer prestement quant à l’imminence d’une campagne de vaccination grippale forcée, sous l‘égide de l’OMS qui est bien entendu de mêche avec les Gouvernements et l’industrie pharmaceutique.

D’une part, j’abhorre les chaînes de mail : ce ne sont jamais les bonnes et elles sont toujours polluées par une quantité de fautes d’orthographe astronomique. Avez-vous déjà vu une chaîne de mail manicoréenne qui exhorterait à réduire ses émissions de CO2 et surtout à faire suivre à 10 contacts, sinon vous serez maudits sur 13 générations (ce que vous serez de toute façon si vous ne faites rien, ah ah, l’ironie) ? Ensuite, les théories du complot m’amusent, mais quand elles se répètent ad nauseam, elles deviennent… nauséeuses et nauséabondes. Enfin, quand on sait qu’elle est destinée à un public vivant en France, ça me soupèse la gauche sans toucher la droite.

Donc, disais-je, on me dit qu’il faut que je me soulève, « malgré qu’il (sic) nous manque beaucoup de pages à ce dossier », ci-joint un joli ppt des familles avec tout ce qu’il faut d‘éléments béton pour étayer sans l’ombre d’un poil fessier la perspective d’une conspiration templière. Alors, décidai-je, je vais m’informer dans la plus pure tradition éolassienne. La réponse est rapidement venue, sous la forme d’une question/réponse du SNPI. Tout d’abord, rien n’oblige quelqu’un à se vacciner, cf. Article L3111-4 du Code de la santé publique :

“Une personne qui, dans un établissement ou organisme public ou privé de prévention de soins ou hébergeant des personnes âgées, exerce une activité professionnelle l’exposant à des risques de contamination doit être immunisée contre l’hépatite B, la diphtérie, le tétanos, la poliomyélite et la grippe.”

Décret n° 2006-1260 du 14 octobre 2006, art. 1 :
“L’obligation vaccinale contre la grippe prévue à l’article L. 3111-4 du code de la santé publique est suspendue.”

(C’est signé Dominique de Villepin, donc les conspiratistes pourront aller le bisouiller). Ensuite, si quelqu’un vous force à vous vacciner, cela relève apparemment du Code pénal (Article 432-4) :

Le fait, par une personne dépositaire de l’autorité publique ou chargée d’une mission de service public, agissant dans l’exercice ou à l’occasion de l’exercice de ses fonctions ou de sa mission, d’ordonner ou d’accomplir arbitrairement un acte attentatoire à la liberté individuelle est puni de sept ans d’emprisonnement et de 100 000 euros d’amende.

IANAL, mais apparemment, ça veut dire qu’en l‘état, non seulement, on ne peut pas vous forcer à vous vacciner, mais qu’en plus, on risque gros à essayer de le faire. Voilà une réponse à une chaîne de mails comme je les aime.

Bien entendu, on me répondra qu‘« ils » vont changer la loi pour satisfaire leurs desseins et vous inoculer le mal, et je rétorquerai que vous devriez tout de même avoir confiance en le législateur que vous vous êtes choisi, non ? Non ?

Comment [1]

 
---

Éric et Ramzy sont les plus grands comiques français de tous les temps

Et voici, sans doute, un de leur meilleur sketch :

Je recommande aussi leur passage à « Vis ma vie », émission débile au possible, mais à laquelle ils sont su donner tout le crédit possible et imaginable ; c’est de la grande télé (d’ailleurs, si vous me le trouvez en vidéo, j’achète).

Comment

 
---

Campagne pour le référendum visant à ratifier le Traité de Lisbonne

La campagne bat son plein, ici, en la verte Irlande, et c’est une nouvelle fois une bien belle foire d’empoigne, avec à l’appui moultes affiches du meilleur goût.

La dernière fois, c’est Libertas qui nous avait gratifié des plus beaux échantillons, mais il semble que Ganley ait un peu perdu de sa verve (et quelques milliers d’euros après la campagne européenne désastreuse qui a vu un unique MEP élu), mais rien à voir avec la campagne que Cóir est en train de mener tambour battant. Ça a commencé très « sobre » :

Et maintenant, c’est plutôt ça :

Vous pouvez vous régaler avec la liste complète sur le site de Cóir.

Bien entendu, une telle prolixité dans la connerie ne pouvait qu’apporter son lot de pastiches : vous pouvez en trouver quelques-uns .

Pour éviter les déconvenues de la dernière fois, pourtant, le Gouvernement et autres associations pro-européennes ont mis les petits plats dans les grands pour informer le public, pour répondre aux critiques originales, à savoir que les gens ne comprenaient pas ce qu’ils votaient. Ils ont également obtenu la « promesse » de conserver le commissaire irlandais, et celle, moins évidente, de ne pas voler les enfants ou de les marquer avec une puce électronique.

Les choses ont pris une nouvelle tournure depuis que Michael O’Leary a pris le parti du oui, et hier, un grand débat a opposé Michael O’Leary, Marian Harkin et Micheal Martin, et Declan Ganley, Joe Higgins et Patricia McKenna. Le débat a été accueilli diversement. Ça a été le grand show de Mick qui s’est régalé face à Ganley.

Pour l’heure, le oui est crédité de 48 %, le non 19 % et 33 % des votants sont encore indécis : ce sont eux qui ont fait basculer la balance la dernière fois. Le vote est la semaine prochaine, le 2 octobre.

Comment

 
---

Ruby in Emacs, Multi-line Strings and Git for Subversion Users

Ruby in Emacs

Ruby syntax highlighting in Emacs

Multi-line Strings

Different ways:

lorem = "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Sed vehicula tempor mauris at convallis. Maecenas feugiat libero 
et mi dignissim facilisis ut vel lacus. Sed tempus risus sit amet tellus 
facilisis fermentum. Maecenas orci massa, consectetur non mattis 
ornare.
"

or

def doStuff str
  print str.upcase
end
doStuff(<<PIECE_OF_STR)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Sed vehicula tempor mauris at convallis. Maecenas feugiat libero 
et mi dignissim facilisis ut vel lacus. Sed tempus risus sit amet tellus 
facilisis fermentum. Maecenas orci massa, consectetur non mattis 
ornare.
PIECE_OF_STR

Git for SVN Users

Hard to go a day without stumbling on a git project. I have rarely dealt with git projects, so very often I have to look up the commands to be used… This page, Git for Subversion users (not quite its name, but it should be) is deadly: it makes the parallel between git commands and subversion ones.

Comment

 
---

EuroBasket 2009 — Day 13

The least I can say is that the final of the EuroBasket 2009 will have been a bit of an anti-climax (as I said somewhere else before the match, “now it’s turtles all the way down, and Spain on top”): at no point Serbia threatened to even come close to tickling Gasol’s stubble. With a very comfortable +15–+20, Spain could sit down and relax, and watch Serbia try interesting attempts beyond the 3-point line. In fairness, it was mainly because Spain’s defence inside was just impenetrable (I guess when you have 2 pairs of arms sticking out of 2.14m lads towering above you, you kind of think twice before attempting a lay-up). So, anyway, the story goes, the game ended 85–63 (yes, 22 points in a final of the EuroBasket). The only interesting thing coming out of this game (for me) is that Rubio answered the question I was asking a few days ago. He was good last night, quite present in defence, scored a couple of 3-pointers – so he justified the hype around him.


Spain have been holding a firm grip on this final. A very very firm grip.

France was playing Croatia for the 5th-6th place, but both teams were leaving the stars on the bench (Tony Parker was being rested, Boris Diaw twisted his ankle), and it has been a great opportunity for Antoine Diot and Nando de Colo to shine! 18 points (4/7 at 3 pts) for the former, 15 for the latter, they showed that they had not been selected in this French team for nothing. France win 69–62 and therefore finish 5th of this tournament.


Come on lads, let me help you build the toy, that’s not fair!!

Russia managed to beat Turkey for the 7th (66–89), meaning Turkey finish 8th, a bit of a disappointing result, given the EuroBasket Turkey accomplished.

All in all, the most exciting game of the day was between Greece and Slovenia, with yet another crazy finish for Slovenia, despite being led for the most of the game. Quarter 4 showed once again that Lakovic was the man of the money-time, dragging his team back to -1 with 9 seconds to go in an incredible last minute. Unfortunately, with the last possession, they didn’t manage to put themselves in a great shooting position, and Nachbar had to resort to a lousy mid-court shoot which he missed… Slovenia lost 57–56, but can leave with many regrets: they were one foul away to get at least silver, and they’re leaving with nothing.

So EuroBasket 2009 finished with a clear winner, Spain, who doubtless will cause some troubles to Team USA next year in Turkey. The “qualified teams” for Turkey 2010 are: Croatia, Spain, France, Greece, Slovenia and Serbia, the biggest surprise being Lithuania missing, but chances are they will be awarded a wild card by FIBA.

And that’s it for me!

Comment

 
---

EuroBasket 2009 — Day 12

Spain are through, and it almost looked like it was no effort. Ok, Greece did well, but Pau Gasol was just too far to reach, Fernandez made the right points, and Spain was at some point leading by more that 20 points. So Spain are in final, with a severe score: 82–64

The Serbia–Slovenia was another classic match, a fantastic match that Slovenia looked bond to win, with a lead of up to 10 points, and then at the end of qtr 3, they seemed to crack a bit. And in qtr 4 , they let Serbia get back, Lorbek got his 5th foul, and (still don’t get that one), let Serbia shoot a 3-pointer in the last seconds rather than fouling to bring them to the FT line… Teodosic on fire in this Q4 scored the 3-pointer, bringing Slovenia to extra-time. And then, it’s all downhill for the men in green: Teodosic carries on his show, Lakovic tries to keep his team level, but it won’t be enough. Slovenia lose 96 –92.

The final is therefore Spain vs. Serbia. The 3rd place match will oppose Greece to Slovenia.

Comment

 
---

EuroBasket 2009 — The Pom-Pom Girls

As Spain is currently thrashing Greece and kind of ruining the whole show, I thought you might enjoy l’Équipe‘s pictures of the pom-pom girls of the EuroBasket. Enjoy!

Comment

 
---

EuroBasket 2009 — Day 11

Day 11 was the second day of the semi-finals, and it wasn’t a night for the faint-hearted.

Greece started strongly, but did not manage to get rid of Turkey. In the second half, Turkoglu and Ilyasova did the dirty work, and Turkey managed to get back, and a last lay-up by Arslan at the end of an extremely tense qtr 4 forced the 2 teams to extra-time. The extra-time was just as stressful, Greece managed to get 5 points ahead, only to let Turkey come back, and Arslan shoot a 3-pointer at the last second. Unfortunately, Arlsan missed this one, and Greece could finally celebrate their victory, 76–74. What an amazing match. Greece are qualified for the semi-finals, and also got their ticket for Turkey 2010.

Turkey was playing France a few minutes ago for a position match, and despite thrashing France in the first half (they were leading 32–43 at half-time), they completely collapsed in the second half, with 29–16 in qtr 3 and 19–9 in the 4th. The game’s score was 80–68. France will therefore play for 5th or 6th place. And they get to go to Turkey next year, and to Lithuania in 2011 for the next EuroBasket!

Slovenia–Croatia was the second match, and a few minutes into the game, it was clear that Croatia was there, and willing to qualify. Leading Slovenia for most of the first half (with up to 9 points), Croatia started the second half just as well, but quickly let Slovenia come back and take the lead at the end of qtr 3, thanks to Lorbek in particular. The Croatians fought really hard in qtr 4, and threatened to come back just like Turkey had done in the previous game, but a precious by Nachbar 5 seconds to the end just sealed the fate of the game (67–62). The game ends 67–65, and Slovenia goes through.

The semi-finals are therefore:

Spain–Greece (a classic)
Serbia–Slovenia (which should be quite good too!)

In the U18 All Star Game (the first one organised by FIBA as far as I know), the Blue team beat the White team 77–75.

Comment

 
---

The 5 Best Slow Claps

Le slow clap, c’est ce vieux cliché hollywoodien : un des héros lose, généralement vers la fin du film, mais il a losé avec deux coucougnettes d’un fort beau gabarit. Devant l’ampleur de la lose, il y a un terrible silence : la foule est outrée. Et alors y’a un gars qui est quand même subjugué par les coucougnettes utilisées, plutôt que par la lose engendrée, et il commence à applaudir.

Et dans une fort belle leçon d’amour plavovien, un autre le suit (généralement bouche bée, encore surpris d’oser applaudir). Et puis un autre, et encore un autre, jusqu‘à ce que la foule en délire célèbre à l’unisson les coucougnettes, le bonheur d‘être ensemble et la joie de garder la tête haute dans la lose. Et là, le mec qui a losé, il est un peu moins triste, et il contemple avec fierté ses coucougnettes parce que, n’est-ce pas, c‘était bien là le fin mot de l’histoire, êtes-vous bête, vous y avez cru. God Bless America.

Alors voilà, quelqu’un a recensé les 5 meilleurs slow claps pour vous, et c’est d’la bombe bébé.

Celui de Rasta Rocket reste tout de même une bien belle référence, God Bless Jamaica ! Par contre, un truc qui me chiffonne, c’est qu’il me semble bien avoir vu le #1, et je n’arrive pas à comprendre dans quel continuum espace-temps une telle chose ait pu se produire…

Comment [1]

 
---

EuroBasket 2009 — Day 10

France got eliminated, and there was no debate about it. They have been absolutely outplayed by a very strong Spanish team, especially Pau Gasol back with a revenge. 28 points and 9 rebounds, he killed single-handedly Turiaf and Traoré. The French came back to a promising -11 in qtr 4, but then their momentum was killed in the bud by a turnover by Diaw. The Spanish defence was too strong, Navarro put in the right 3-pointers, and Tony Parker didn’t score the healing points that would have brought France on the right trck. Not really a surprise, but still a bit disappointed… It looks like the predictions of the experts might be right: all the teams of Group F will go through.

In the other quarter final of the day, Serbia got rid of Russia quite easily (surprisingly, but hey not so much given Russia’s output in the previous games, but hey, you could also say that of Spain): 68–79.

So there you go. I’m really disappointed, even though I could feel France was really up not to the other good team standards (I wouldn’t have given France a chance against Slovenia for example), but having Spain playing tonight, Great Britain is forgotten, and we might very well have a winner here.

Last question: is Rubio the most overrated player of this tournament?
And a remark: I can’t help but like Nando de Colo. He looks a bit inexperienced at times, a bit clumsy, but he comes up with these fantastic passes or shoots: so, I can’t decide if he deserves it, but I really wish him all the best!!

Comment

 
---

Luas vs. Bus

Fierce competition between the tram and the bus, these days, in Dublin…

Comment

 
---

A New Mindset to Save Beer Taste

The 2 latest posts on the Guardian Environment blog are worth reading. The first one, What we urgently need is a new mindset on climate change, is actually the editorial published simultaneously by two prestigious medical journals, The Lancet and The British Medical Journal, calling for a new mindset on climate change ahead of the Copenhagen conference, as it poses the serious threat of “a global health catastrophe.” Not only it describes the dramatic consequences for health if nothing is done, it also highlights that this new mindset could be a positive turning point for human well-being:

Crucially for winning hearts and minds in richer countries, what’s good for the climate is good for health. The measures needed to combat climate change coincide with those needed to ensure a healthier population and reduce the burden on health services. A low-carbon economy will mean less pollution. A low-carbon diet (especially eating less meat) and more exercise will mean less cancer, obesity, diabetes, and heart disease. Opportunity, surely, not cost.

The second post warns that if nothing is done to tackle global warming, your beer will taste like pish too.

Comment

 
---

← Older Newer →