3 Dec 2008

Insert Polygon into Postgis

I was trying to insert a polygon (I think it's the same as a bbox but not sure yet) into a postgis table. But I only found scaterred examples where the columns declaration was missing... So here's a concret example.
The SQL:

SELECT AddGeometryColumn( 'my_table', 'geo_bbox', 4326, 'POLYGON', 2);
UPDATE my_table
SET geo_bbox=GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))',4326)
WHERE id='my_pk';

Where '4326' is the standard/normal/usual coordinnates system: longitude/latitude. You can do the following to get more info about '4326':
select * from spatial_ref_sys where SRID=4326;

To check if everything is working you can do:

SELECT ST_Contains(geo_bbox, GeomFromText('POINT(2 2)',4326))
FROM my_table
WHERE clef='my_pk';

It should return 't' for 'true'.

Errors I've bumped into and their "gotchas":
  • parse error - invalid geometry
    UPDATE my_table 
    SET geo_bbox=GeomFromText('POLYGON(0 0,4 0,4 4,0 4,0 0)',4326)
    WHERE clef='my_pk';
    ERROR: parse error - invalid geometry
    CONTEXT: SQL function "geomfromtext" statement 1

    You forget the double '((' and '))'. There is a double '((' because Polygon can be describe like this: POLYGON((first_shape), (second_shape))
  • geometry contains non-closed rings
    UPDATE my_table 
    SET geo_bbox=GeomFromText('POLYGON((0 0,4 0,4 4,0 4))',4326)
    WHERE clef='my_pk';
    ERROR: geometry contains non-closed rings
    CONTEXT: SQL function "geomfromtext" statement 1
    You forget the last coordinates, you need to repeate the first point twice:
    POLYGON((down_left, down_right, up_right, up_left, down_left))
  • geometry contains non-closed rings
    UPDATE my_table 
    SET geo_bbox=GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 10))',4326)
    WHERE clef='my_pk';
    ERROR: geometry contains non-closed rings
    CONTEXT: SQL function "geomfromtext" statement 1
    That's because the finishing point (0,10) is not the same as the starting point (0,0)
  • other: invalid geometry
    I also got an other way to get an "invalid geometry" but I don't remember how to reproduce it... postgis does some validation if your coordinates are not valid.

Postgis official documentation: Creating object syntaxe

Technorati tags:

2 Dec 2008

ohloh la!

I just discovered ohloh.net after reading Marting Fowler latest post.

Ohloh display informations about open source projects: commits, timelines, contributors, languages etc...

Amazing how they managed to extract valuable informations for internet/svn/projects and how they presented it in a meaningful way!

I had lots of fun finding people I know:

Or project I've worked with:

This can help see if a project is under active development or not and who is really working on, not just claiming to be a contributor ;)

27 Nov 2008

Insert big data chunk into MySQL

Inserting 370 000 records in a mysql table was taking ages!
Found this little trick:
LOAD DATA CONCURRENT LOCAL INFILE 'C:\\my\\path\\to\\folder\\records.sql' INTO TABLE FOO;

Useful under Windows and MySQLQueryBrowser ;)

MySQL funny command line option

While searching for help for mysql ubuntu command line tool:

$ mysql --help
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.

19 Nov 2008

Flag a blog post as deprecated

While looking for some info on capistrano I stumbled on this post: "Ant sucks for FTP deployment - What alternatives do we have?".

The funny thing is the deprecated notice:

I often use @deprecated for the code but I never though of using it for my old blog posts... good idea :)

And it's also a good way to always keep url even if they display wrong or inaccurate info, just like describe in this w3c document "Cool URIs don't change."

Simple Jdbc

I wanted to use spring JdbcTemplate to simplify my jdbc code but I had to add 3 jars just to use it !
  • spring-jdbc.jar
  • spring-tx.jar
  • spring-core.jar

spring-tx.jar because I got this error:
The type org.springframework.dao.DataAccessException cannot be resolved. 
It is indirectly referenced from required .class files

spring-core.jar because I got this error:
The type org.springframework.core.NestedRuntimeException 
cannot be resolved. It is indirectly referenced from required .class files

And I wasn't even sure about the transaction part, did I need to include spring-beans.jar and spring-context.jar; start to use a TransactionTemplate and configure a PlatformTransactionManager with tons of xml configuration, services and dao(s) :(

So I decided to make a small but simple project doing exactly what I wanted: jdbcTemplate and I made it public on sourceforge.

Don't expect any documentation or support for this, it's just that I don't want to redo this code on my next jdbc project (if that ever happens).

You can also take a look at DbUtils at http://commons.apache.org that does just the same ;)


12 Nov 2008

Why you should use JUnit4

I've been using JUnit 4 from time to time but never really understood the benefit moving from version 3 to version 4.

That's because I never took time to take a look at new features :o

Don't be like me ;) Just take a look at this article: "Junit 4 in 60 seconds"

You will discover annotations like:
  • Better Exception Handling with @Test(expected = ArithmeticException.class)
  • @Ignore("Not Ready to Run")
  • @Test(timeout = 1000)

Small enhancements making testing easier and clearer!

5 Nov 2008

New Java Date Time Api

This is a good news: Date and Time API: Round 3. Date and Time parsing is always a mess... if they could just remove the old api (and not be backward compatible) that would be even better but it takes courage.

Come on almost all java.util.Date methods are deprecated since Jdk version 1.1... It's time to change!

27 Oct 2008

Fixing log4j email notification under ubuntu

I had a problem under ubuntu to use log4j email notification through SMTPAppender.

The problem:

java.lang.NoClassDefFoundError: gnu/inet/util/GetSystemPropertyAction
at javax.mail.internet.ParameterList.(ParameterList.java:72)
at javax.mail.internet.ContentType.(ContentType.java:104)
at gnu.mail.handler.Text.getJavaCharset(Text.java:160)
at gnu.mail.handler.Text.writeTo(Text.java:140)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:868)


I think :
apt-get remove libgnuinet-java

is enough but this is the exact command I had to run:
apt-get remove libgnuinet-java libgnujaf-java libgnumail-java-doc

Jetty 6, java 6, log4j 1.2.15 + commons-logging 1.1

Log4j conf:

log4j.rootLogger=INFO, CONSOLE, FILE, EMAIL
# log4j.appender.EMAIL.SMTPUsername=xxx
# log4j.appender.EMAIL.SMTPPassword=xxx
log4j.appender.EMAIL.Subject=[MyApp] Application Error
log4j.appender.EMAIL.layout.ConversionPattern=[%d] [%t] %-5p %c %x - %m%n
# log4j.appender.EMAIL.SMTPDebug=true

I'm also using sun jvm using this command:
update-java-alternatives --set java-6-sun

29 Sep 2008

Gmail Ads doesn't filter content

While reading a mail in gmail about technical webapp stuff, I find this sponsored link quite surprising ?!

Translated in english, it says:
Fed up with GWT? Try ZK
Understand why GWT is the root of all evil for your project

Gmail doesn't filter the content of it's ads ;)

Technorati tags:

12 Sep 2008

Is node order important in xml ?

"Is node order important in xml ?"

This has always been a pending question, I wanted to answer.

The quick answer:
  • No dtd, xml schema(xsd) validation, node order doesn't matter
  • Any type of xml validation, order does matter (unless using a special notation in the schema)
The long answer:

For a long time I was pretty sure the order wasn't important, you could write:




It was the same...

But when using eclipse and validating an xml document, the validator kept complaning if the node were not in the same order as describe in the xsd.

I didn't know if it was an eclipse validator limitation (the validator wasn't able to cop with node order) or a w3c xml requirement.

Untill I found this IBM page describing the same exact issue ;)
Principles of XML design: When the order of XML elements matters

Apparently you can specify in an relax ng schema that order doesn't matter (using ampersand "&") (see: chapter "Schema constraints of element order") but I suspect many people (me included) to use the easiest path and use the comma notation.
As a side effect that means the order does matter, but people writing schema usually don't do this on purpose...

Technorati tags:

[Eclipse] No more Ctrl+O Ctrl+F

I'm pretty sure many eclipse "guru" already noticed it but in eclipse ganymede you can now auto-format and auto-organize import on save.

But now it's available by default in eclipse :)

Just go to "Windows > Preferences" and find the "Save Actions" menu:

Technorati tags:

4 Sep 2008

How to disable Windows Language Keyboard Switch

From time to time my keyboard goes from french to english (from azerty to qwerty). And that's quite annoying !

The faulty shortcut under windows is: "Alt+Shift"

To avoid such a thing, you need to remove the english keyboard from the localization status bar. 

Here's some screenshots explaining how to do it:

Select the english keyboard and hit "delete" (supprimer).

23 Jul 2008

A sense of "déjà vu"

While looking at some movies informations on imdb, I stumbled on this:

Lack of imagination or coincidence ?

22 Jul 2008

Eclipse, classpath and subversion

I always have the same problem over and over to make eclipse, the project classpath and subversion work perfectly together :(
And I'm pretty sure thousand of other guys have the same problem.

The problem is that you need to do 2 things to avoid the output dir to appears as a folder under source control:
  • add the output dir to the ignore list
  • AND
  • add an exclusion filter in the src dir to avoid eclipse to copy the .svn folder in the output dir
1- When you start a new eclipse project, you have that folder structure:

2- You add it to subversion but you don't want the output dir to be added so you just add the src folder:

3- You add the bin dir to the ignore list:

But you are not over yet! At this stage subversion doesn't complain anymore about uncommited changes in bin BUT you still have the .svn folder in bin.

This is specially anoying with tortoise svn since it displays svn icons on the bin folder.

4- Now you need to exclude the .svn from the src folder to prevent eclipse to copy them:

Does anybody knows how this can be achieve under Maven when using "mvn eclipse:eclipse" ?
I suppose one need to use the filters as describe in the pom reference...

Playing with wordle

Just a quick post to a tag soup generator: wordle
It seems I have a lot of ruby and rails tag in my del.icio.us account :D

This blog tag soup (I don't know where it picked those tags btw)

My del.icio.us account: no comment ;)

6 Jun 2008

Vimeo: Nice HD player

May be you already heard about vimeo a youtube like website, famous because of the Office Lip Dub.

I just discovered they have a HD version of there player and I have to say it's quite impressive: quality is excellent, simple to use, no extra fancy widget everywhere.

You can see it in action with this Christina Aguilera Video Live at David Letterman.

Technorati tags:

4 Jun 2008

New Job at Sqli

3 years and a half later, I'm leaving Anyware Technologies to go to SQLI still in Toulouse.

This time it's: "Thank you julien" :)

New projects, more responsabilities as a project manager, new people, cmmi level 5 quality requirements... lots of changes. But I like changes ;)

So! Let's get started!

ps: Reminds me of that road in Terminator 2 ending (at 4:40) when a new futur lies ahead ...

ps 2: For the film enthusiast(s), David Lynch made a more freaky version (at 1:25) of it in Lost Highway few years later... but I'm get out of topic here :)

29 Apr 2008

Feeling Good :)

Kt Tunstall - Hold On lyrics

I was tired of January
I was tired of June
I felt a change a-comin'
Oh, I was tired of January
Tired of June
I felt a change a-comin'
Oh, I felt a change a-comin
I felt a change a-comin
Felt a change a-comin, soon

Muse - Feeling Good Lyrics

It's a new dawn
It's a new day
It's a new life
For me
And I'm feeling good

11 Apr 2008

Blog Posts you don't want to read

Most of the time, I read my blog posts in the morning.

Every once in a while I have posts that give me a headacke just by reading the title :D

I only took the latest posts ;)
The reasons I find them funny is because:
  • They use and combine "enterprisey" buzzword
  • The title alone is so complex you need to read it twice
  • There is few chances that you'll ever have to use what they talk about because it narrows to such a limited field
  • Even if you have the courage to click on the link, you will read less than 10 words out of it
  • As soon as you'll leave the page you will forgot about it
  • When you encounter one, you know it's time for another coffee :)

ps1: It's not about a technology (microsft, java, ruby...) every community does this kind of posts ;)

ps2: InfoQ is a good source of information, I remove theserverside feed because it was getting so much worst than InfoQ in the buzzword competition ;)

18 Mar 2008

Adobe Air/Flash/Flex Redux

Looking and playing a bit with Adobe AIR is on my Todo list for a few months now but I wasn't getting the "big picture".
Just found this "technomap" in an Adobe devnet article: "Adobe technology platform ActionScript reference for RIA development", it helps a little :)

There is also a pdf with what seems to be methods references...

Technorati tags:

3 Mar 2008

Cedric Beust on TDD

Disclaimer: If you've never done TDD you shouldn't watch this ;)
Why ? Because I think you can't understand those arguments until you have already experienced it.
Don't say "I won't do TDD because Cedric said so!" Try it for 2-3 months and then watch the talk...

For those who have already done TDD (Test Driven Development), Cedric Beust (From TestNG) gives an interesting, balanced talk about TDD (starts at 33 min).

Some of TDD drawbacks according to Cedric (extracted from one of the slides):
  • Promotes micro-design over macro-design
  • Hard to apply in pratice
  • No clear evidence that it produces better designs than "tests last"

The talk is actually much more balanced (and in favor of TDD) than this except my suggest... You should really take a look at it.

Technorati tags:

12 Feb 2008

A better way to use Java Enum than switch

I think java enum are a nice addition to the language. I used to combine them with switch/case statements. But lately François, a colleague, shown we a better way :)

You can embedded behavior in each enumeration case, reducing client code and making it more elegant :)

Let's take a simple example: Every day of the week you need to do something: take out the garbage, go to the laundry etc. ...

Using switch here's how I would have done it:
    private enum Week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}

public static void main(String[] args) {
final Week today = getToday();
Action action;
switch (today) {
case Sunday:
action = new FamillyDiner();
case Monday:
case Friday:
action = new Garbage();
case Tuesday:
action = new Laundry();
case Wednesday:
action = new ChillOut();
case Thursday:
action = new Grocery();
case Saturday:
action = new SoccerGame();
throw new RuntimeException("Impossible day!");

  • You can see the number of lines in main() is quite important
  • The client code (the switch/case code) is likely to be duplicate
  • There is an unnecessary case "default" that can never happen (even null case would result in a NullPointerException in the switch)
  • But it still much better than a if/elseif/else using int

Adding behavior to the enum:
    private enum Week {
Sunday {
public void execute() {
System.out.println("Mom and Dad diner.");
}, Monday {
public void execute() {
System.out.println("Take the garbage out.");
}, Tuesday {
public void execute() {
System.out.println("Do the laundry.");
}, Wednesday {
public void execute() {
System.out.println("Have a beer. Just Chill out!");
}, Thursday {
public void execute() {
System.out.println("Go out to the local store for Grocery with shoping list.");
}, Friday {
public void execute() {
System.out.println("Take the garbage out.");
}, Saturday {
public void execute() {
System.out.println("Manchester vs Arsenal! Can't miss that!");

public abstract void execute();

public static void main(String[] args) {
final Week today = getToday();

  • Less lines of code and still readable
  • main() code is soooo easy
  • No unnecessary case "default"
  • If you don't want this behavior and still use the enum you are free to use the switch/case way

Clearly I think this approach is far better and much more elegant unless someone show me otherwise...

Download the complete code sample.

7 Feb 2008

Comparison: java.util.logging vs org.apache.commons.logging

Here's a comparison between the java logging system and apache commons logging system.

For the lazy ones here's the conclusion:
  • Commons Logging Rocks!
  • Java Logging Sucks!

Why ? Well because:
  • Commons Logging api is better
  • Commons Logging let you choose your logging implementation
  • Commons Logging is bulletproof, production ready, heavily use everywhere
  • Everybody knows Commons Logging

Not convince yet ? Good I like people that don't take things for granted easily ;)

Let's compare the 2 frameworks api:
Java LoggingCommons Logging
Unclear log level: SEVERE > WARNING > INFO > CONFIG (wtf?) > FINE > FINER > FINEST (missing some imagination here ?!)Clear log level using different names: FATAL > ERROR > WARN > INFO > DEBUG > TRACE
No ERROR level! I find it really disturbing especialy since there is a System.err stream for so many yearsThere is an ERROR level
To log an exception:
logger.log(Level.SEVERE, e.getMessage(), e);
or may be
logger.log(Level.WARNING, e.getMessage(), e);.
Unclear what Level to use and why do I need to do e.getMessage() it could have been done in the log() method.
Missing simple methods: logger.warning(Throwable t) and logger.severe(Throwable t)
To log an exception: logger.error(e);
To configure either modify the logging.properties in your JRE/lib folder or set -Djava.util.logging.config.file=/my/folder/logging.properties
No way to put a conf in the classpath to be automaticaly pick up by the logging framework
Possibility to put an already configured conf file
Create a logger:
private static Logger logger = Logger.getLogger(MyCLass.class.getName());
Missing method: Logger.getLogger(class)
Create a logger:
private Logger logger = Logger.getLogger(getClass());

The good things about Java Logging:
  • Classloader: About the configuration part the way java logging does the configuration is less flexible but might reduce classloader problems that you encounter with commons logging (see: Commons_Logging_FUD)

  • No jars to add, No additional dependency

Working with Commons Logging api is some much better, simple and easier that I will continue to put those 2 jars in the classpath whenever possible if that's what it takes to use it.

Now try both and make your own opinion ;)

30 Jan 2008

Firefox - Free your memory

Firefox consume lots of memory.

You can free it by using this little program call "Freefox" [fr] (direct download link).

I went form 300 Mo to 20Mo :o

It's windows only.

Is there such a thing for eclipse? :p

from sebzen

8 Jan 2008

Jakarta Slide is Retired

Just discovered that Jakarta Slide the Java WebDAV open source server is now officially a dead project.

From the website:
As of 2007-11-03, the Slide project is retired. This site is kept online for archiving purposes.

Due to the lack of a developer community, the codebase was no longer actively maintained and security issues could not be addressed by bugfix releases. The Jakarta PMC therefore had no other choice but to retire Slide.

If you are looking for a WebDAV client or a server-side Content Repository, please consider the Apache Jackrabbit project as an alternative.

This site is kept online for archiving purposes.
Not really surprising since last time I checked the project already seemed in a zombie state. But now it is clear...

4 Jan 2008

Don't Make Me Think: A Common Sense Approach to Web Usability

I'm currently reading "Don't Make Me Think: A Common Sense Approach to Web Usability" excellent book btw.

This little comic strip about "Religious debates" is so funny and so true that I couldn't wait to share it with you :D

You can replace "pulldowns" by whatever term: emacs, vim, java, .net, ruby, python, css, pdf etc...

Technorati tags: