Ampersands and XHTML

A regular expression to replace all ampersands (&) in a text that are not part of an entity:

t = t.gsub(/&(?!#?\w+;)/, '&')

Language is ruby. The regexp feature used is called a negative lookahead.

| Comments (0) »

25-May-08


SCJP, finally!

More than a year ago i decided to do the Sun Certified Java Programmer. Shortly after i bought this book, the projects at work and at home were somewhat overwhelming and after all, i realized that a big part of the SCJP is about some weird, crazy and sometimes wrong design decisions of the Java language. Some of them i mentioned under this tag.

Last month i realized i had some spare time, signed up at Prometric and had a 2nd look at the book and on my good Java experience from the last 6 years.

First thing: The “Java 5 Study Guide” isn’t a bad book but the “MasterExam” software on the enclosed cd is a master piece of crap. Not only the gui is as shitty as it gets but some of the answers are just plain wrong.

Second thing: I bought the preparation kit from Whizlabs for 50€. This thing isn’t bad at all and helps you get prepared for the craziness thrown at you.

Third: Being good at something is always great 😀 It rocks, really. Like single trail riding or music with electric guitars while driving open. It’s like drugs but not that unhealthy.

After about 2 weeks of preparing, I arrived 30 minutes early at “New Horizons” in Cologne, took the test certainly in english as i prepared with english material and finished somewhat 50 minutes later (you have officially around 3 hours to take the test). The nice proctor asked me if i wanted to use the toilet as she saw my report being printed: 90%, pass! Wooot!

I thought about this post at Jans. I really like the guy who wins a million dollars at Who wants to be a Millionaire and has the guts to call his dad but not ask for help and instead tells him he is going to win a million dollars. I can totally relate to that as i always had fun taking test and scoring at the upper limit 😀

So today i’m gonna eat an extra portion of Cookies & Cream and leave you with the following piece of Java madness:

Read the complete article »

| Comments (2) »

06-May-08


Tired of all the powerpoint presentations…

Right now i’m in Wiesbaden, attending the JAX 2008 conference.

The mood is somewhat different compared to the DOAG i used to visit the last years. The people are more open minded, partially much younger and generally try to be much cooler. And for the sake of it, some are even more interesting and after all, there isn’t that ongoing whining about Oracle not engaging in Forms 6i Client Server any more (although, i must admit, i somewhat like Oracle Forms 6i, maybe it’s a love/hate relationship, trust me, i know both worlds, Java and Forms).

The sessions suffer from one big problem: Many of them just seem to play powerpoint karaoke: Throw in a bunch of crappy slides with a handfull code snippets and sing-a-long to that stuff which means basically: Hind behind the slides.

Let me tell you: This is so boring and pointless. In the past i tried to be polite and always stayed to the end of a session but the last 2 or 3 conferences i can’t stand it any more. I can read myself, thanks. If you haven’t got anything additionally to say, just pass me the slide and i’m fine.

The 3 most interesting sessions where the sessions spoken freely with the slides just illustrating the speech. I especially liked Brian Chans presentation of Liferay Portal, Rod Johnsons keynote on the future of J2EE and the most witty one, Ted Newards talk about the renaissance of languages. It was funny, included the audience, was well prepared and freely hold, not to forget the topic: It wasn’t about the nth framework around the corner but about the nearly philosophy topic about the “perfect programming language”.

I really wish that i’d be creative and intelligent enough to design a language that is not predestined to die an early death, but i ain’t. But i can distinguish a sharp tool from a spoon if i see one and i can adopt to it very easily. And in that sense i share Teds opinion that a discussion about abstracting things and about the tool itself is of much more value than implementing some arbitrary pattern (i.e. one be the GOF) in just another framework. For example, many implementations of some patterns in frameworks have been rendered obsolete by more powerful and more expressive languages and i’d like to see this trend go on.

| Comments (0) »

23-Apr-08


Beyond all evil: Javas definition of an object

Some days i ago, i decided to revamp my ambitions to get the scjp thingy done. What exactly for, i don’t know. But working to the self tests, i found the following:

class Ring {
  final static int x2 = 7;
  final static Integer x4 = 8;
  public static void main(String[] args) {
    Integer x1 = 5;
    String s = "a";
    if(x1 < 9) s += "b";
    switch(x1) {
      case 5: s += "c";
      case x2: s += "d";
      case x4: s += "e";
    }
    System.out.println(s);
  }
}

Questions is: Some arbitrary output or a compilation error and if, on which line.

Answer: Compilation fails due an error on line 11. What the frag? The obviously totally retarded switch statement can only handle constant values in its branches. So what? x4 is declared final static, as constant as it can be in Java. But no… Because its a big difference between int and Integer and due to the auto boxing and unboxing in Java 5 and up, the object Integer isn’t constant opposed to the scalar int.

Summary: A big deal with the SCJP is to teach the contestants how to work around some brain dead things in Java. Don’t get me wrong, i actually like Java, but the more i do in Ruby and the likes, the more some concepts in Java seem and are just wrong, like the for example not being all things equally objects.

| Comments (0) »

09-Apr-08


Patching wp-cache for more security

I use wp-cache on all my blogs all the time. No need waiting for being slashdotted or heised.

But wp-cache comes with a security flaw. It requires the webserver to have write access on $WP_HOME/wp-content/cache and $WP_HOME/wp-content. The first part is perfectly reasonable, the second not.

wp-cache creates it’s wp-cache-config.php in that place and edits this file consequently while being configured.

wp-cache comes with a sample config you can put in place. After that, chmod this file to 660 or something else that allows your webserver to edit it. Please don’t give your webserver write access to $WP_HOME/wp-content, especially not facing the current attacks on wordpress bloggers as described here.

I assume you know what your doing in the next step. All recommendations are tested and working with wp-cache 2.1.2. Open the file file wp-cache.php in your favorite editor, navigate to line 471 in function wp_cache_verify_config_file and change the following code

if ( !is_writable($dir)) {
    echo "<b>Error:</b> wp-content directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
    return false;
}

to

/*
if ( !is_writable($dir)) {
    echo "<b>Error:</b> wp-content directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
    return false;
}
*/

Alternatively, you can use the file i prepared: wp-cache.php. Rename it from *.php.txt to *.php and replace the old file with it.

Read more about the attack on wp blogs here. It’s shown that the attackers create a subfolder in your wp-contents. So it’s essential to chmod this folder to 0755 or even better to 0555 if you’re paranoid and only change it if you upload updates.

| Comments (0) »

04-Apr-08