Friday, June 15, 2012

Debian: "perl: warning: Setting locale failed."

On my freshly installed Debian system, I kept getting this error message when using apt-get or perl:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = "en_US:en",
 LC_ALL = (unset),
 LC_CTYPE = "UTF-8",
 LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
If you have the same problem, well, the solution is quite easy. See that LC_ALL is unset ? All you have to do is add the following line to you bash profile (/etc/profile or ~/.bash_profile):
export LC_ALL="en_US.UTF8" # Put the adequate language and encoding here
Now open a new shell or source your profile in the current shell. Problem solved :)

Sunday, May 29, 2011

Spell checking with VIM

Vim is known to be a powerful text editor, and it's true. With this simple command, you can enable spell checking (replace "fr" with your language code):

:setlocal spell spelllang=fr

If this locale is not installed for VIM, it will offer you to download and install it.
Once the spelling is activated, the misspelled words are displayed in red. Now you can use the spelling commands:

]s -> move to the next (probably) misspelled word
z= -> suggest corrections
zg -> add this word to the dictionary

Interrestingly, if a couple of words are valid only together, you may select them in visual mode and then hit zg.

Happy writing!

More about spelling in VIM

Saturday, May 28, 2011

Blogger "dynamic view"

Hi there :)

As I was playing around with the settings of my blog, I discovered a nice new feature. Try out this new dynamic view.

Friday, May 27, 2011

EEE 1015pem & Ubuntu: fix headphones

Hi there :)

I recently acquired a nice little Asus EEE pc 1015pem, and installed Ubuntu besides Windows. The linux runs very smoothly and this netbook has an absolutely huge battery life (I would not lie if I told you it lasts for about 9 hours).

I had a few troubles however. First, I could not get the highest brightness on the screen, but this seems to be fixed magically by now.

Second problem was that headphones would not work at all. Simple fix (run as root):

echo "options snd-hda-intel model=auto" >> \
  /etc/modprobe.d/alsa-base.conf

Now reboot, and there you go :) Have fun !

Friday, November 20, 2009

Accounting for Developers

Hey, you know SQL and want a simple but powerful tool to track your incomes and expenses ? Then maybe you'll be interested by A4D. It's totally free, as it belongs to the public domain. Don't miss it ;)

Monday, August 17, 2009

OOP: Three reasons to use interfaces

I’ve been long wondering why I should use interfaces. Hold on, this post is going to be somewhat long ;)

Of course, there is the most commonly known fact: you can specify one interface for several implementations. A good example of this is the Java List interface, with its subclasses: ArrayList, LinkedList, Vector…

But I recently discovered two other reasons. Consider these classes I wrote a few days ago in PHP:

class Statement {
    public function __construct($query);
    public function execute(array $args);
    public function fetch();
}

class ResultSet {
    public function __construct(Statement $stmt);
    public function hasNext();
    public function next();
}

A ResultSet is created from a freshly executed Statement, taking its data from the Statement::fetch() method. But don’t you see a little design flaw here ? Doesn’t something bother you a little bit ?

Yes, you got it! We just gave the ResultSet class the right to execute a Statement, and that’s really bad!

Now guess what… we are going to use an interface to correct this design error. (changes are in bold)

interface Fetchable {
    function fetch();
}

class Statement implements Fetchable {
    public function __construct($query);
    public function execute(array $args);
    public function fetch();
}

class ResultSet {
    public function __construct(Fetchable $ftch);
    public function hasNext();
    public function next();
}

Now, our ResultSet class doesn’t have the ability to execute a Statement anymore.

This is called “Defensive Programming”, or at least it’s a bit of it. Defensive Programming is a kind of coding mindset, aiming to reduce the risk that other people, or even you, make mistake while coding. With the above example, this is done by restraining the actions your code is allowed to do.

The last reason to use I found (but I bet there are lot more), it that it will help you to perform Test Driven Development (TDD). Let’s take the above example once again. I want to test this ResultSet class. One way to test it would be to create a select statement, execute it and create a ResultSet object with it.

Ow, wow, poor database, poor testers, who will have to ensure the db is not empty, poor developer who will have less quality tests, poor…

With interfaces, however, I can create some stupid class, let’s say DummyFetchable, that would implement this interface. And simply give this class to my ResultSet: I swear, this good guy will see nothing!

class DummyFetchable implements Fetchable {
    public function fetch();
}

class ResultSetTester {
    public function testResultSet() {
        $source = new DummyFetchable();
        $rs = new ResultSet($source);
        
        … and test this out, without killing your db :)
    }
}

Hope this post has been of some use to some people :) Let’s summarize it all:

  1. one external behavior, several implementations;
  2. Defensive Programming;
  3. Unit Testing;
  4. and certainly more, please let me know :)