Lock your computer when you go away

If you are like me, your colleagues like to pown you when you leave your laptop unlocked. Here is a super easy solution to lock your Mac automatically when you leave it: if your cellphone is out of bluetooth range, lock your computer. Easy, efficient.

Here is how to do it:

  • Download Proximity: this application does detect bluetooth devices and lets you launch scripts upon detection or absence of detection (download page here).
  • Copy Proximity.app in /Applications
  • Start the Proximity.app and open its preference panel (the application adds itself to the menu bar next to your clock)
  • Reduce the device monitoring to 30s or so (less time for your colleagues to mess around)
  • Add the device (the device needs to be linked with your computer bluetooth, you can do that in System Preference)
  • Add an AppleScript that will be run when your cellphone goes out of range (see below)
  • Optionally add an AppleScript that will be run when your cellphone goes back in range

The AppleScript to lock your computer is pretty simple. Create a file name out-of-range.scpt and add:

-- out-of-range.scpt

tell application "ScreenSaverEngine" to activate

You can do many more things in these AppleScripts like:

  • change your Adium and Skype status
  • unlock your screen when you come back in range

This other blog entry has a fairly compete setting example. I personally purposely do not unlock the screen when I come back in range. It’s safer to ask for the password explicitly incase someone… borrows your cellphone.

Unlike some more complex apps, Proximity is pretty simple and does not let you decide at which range a bluetooth device is considered out-of-range. The good thing is that it is pretty soft on your cellphone battery.

Book review: JBoss AS 5 Development by Francesco Marchioni

I’ve been reading JBoss AS 5 Development by Francesco Marchioni published by Packt Publishing. I must say that I quite enjoyed the book because it is complementing my knowledge perfectly.

I know Java EE 5 and 6 quite well, I’ve been working on it, promoting it, yada yada yada. But when it comes to details on how to configure JBoss AS beyond the standard and the EE programmatic model, my knowledge leaves a lot to be desired.

Good for:

If you want to know how to:

  • change the HTTP port
  • create two independent clusters on a single network
  • customize the thead pools of your HTTP requests, EJB 3 components etc
  • tweak the transaction manager
  • secure your JBoss AS installation
  • etc

This book is a gold mine. Using the index or the table of content, you will reach the information in a minute.

If you want to know how the JBoss Tools can help you:

  • create an application
  • deploy / undeploy apps
  • add new components, pages
  • etc

This book will give you nice how-tos that will hold your hands from tooling installation to configuration and wizard usage.

Francesco also explains the basics of the EE programmatic model. This is quite handy as it helps you to kink a configuration trick to an application behavior: all configurations are described with how they impact your application behavior and what it means if you change them.

Not good for:

If you are looking for a book that explain the Java EE programmatic model and development practice in detail, this is not the book for you. You’re better off looking at Seam in Action or any other EE targeted book.

I will keep the book next to me when I develop and deploy on JBoss AS. Finding the right config or tuning will be much faster than a reckless Google search :) Reading this book, you feel that Francesco uses every bits of JBoss AS, loves it and wants to share his knowledge. Keep going :)

Disclosure: Swati from Packt Publishing sent me the book for free. I stand by what I said in this blog though.

Getter / Setter generation in Java

Eclipse or IntelliJ typically generate getters and setters this way:

public class Month {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

And we all complain because that consumes a lot of screen space (9 lines). Provided that the trio attribute / getter / setter really represents a unique property, why not generate it that way?

public class Month {

    public String getName() { return this.name; }
    public void setName(String name) { this.name = name; }
    private String name;

}

That’s much more compact (3 lines, ie a third of what we had) and put all related constructs as a single block. You can also mutualize the JavaDoc for free :)
What do you think?

Oh and please don’t tell me about Scala, Groovy or Fantom, we all know Java should have had first-class properties. But that’s life.

Podcast part I: recording

I have been producing podcasts for almost a year now, primarily at Les Cast Codeurs (a French podcast on Java) but also helped a bit on JBoss Community Asylum Podcast.

I have been wanting to share my knowledge and experience for a little while now. I’ll split that in three parts:

  • recording
  • mixing
  • publishing

First things first then, for today the recording.

The material

Microphone

I use the Snowball from Blue Microphones and am very very happy with it. The sound is great, I can also carry it with me to do interviews as it has an option for 360° recording. It plugs into my USB port, is self powered and looks gorgeous on my desk ;)

But in all reality, any USB microphone will do. For a long time I have been using the Plantronics 470 USB. The nice thing about this model is that it’s foldable and fits nicely in a traveler’s bag. Note that my version has a small bug: sometimes, after an hour or so of recording, the sound gets mangled. What I need to do is to unplug and replug the USB dongle. Hopefully, this annoying bug is no more in recent versions.

Skype

If you can, all meet in the same room to record your podcast. First, it’s nice to see people but more importantly, it will make the mixing work much much easier (see next post).

If you cannot, no problem, Skype is indeed surprisingly good to produce podcast. Just make sure everyone is on a decent connection and preferably on ethernet rather than WiFi. Oh and do not start the video, that will save some bandwidth and audio quality.

Recording

Recording strategy

There are two schools here.

  • Record the sound on one computer: basically the sound coming out of Skype
  • Record each podcast speaker locally (while speaking on skype) and mix the tracks together down the road.

The former is good in that it reduces the amount of mixing you have to do down the road. But it has a few drawbacks:

  • the sound quality won’t be as good as the second approach as you are dependent on Skype’s instant quality. While it’s easy to recover missing words from a conversation while *into* it, it’s quite tedious when you are listening to a podcast.
  • people tend to speak at the same time on skype. Since you don’t have instant visual feedback, it’s quite common to speak at the same time create a lovely cacophony.

You can record the Skype flux with tools like Audio Hijack Pro (on Mac, $32). There are free alternatives but simplicity is key for me and avoid mistakes (like not recording).

The second approach (ie. recording each local voice while speaking on skype) is pretty easy to set up but requires everyone to record locally. The easiest solution is to download Audacity (free and open source) and ask everyone to click on the record button.

Right before starting the podcast, make sure to have a common signal to sync the various tracks. I usually count down (3, 2, 1) and everybody say zero at the same time. And voilà, I’ve got my mark. Also ask everybody to stay silent for a couple of seconds: that will come handy during the mixing phase.

I personally ask everyone to record locally. I also record my Skype flux as a backup. It’s quite painful to have to re-record a podcast, so better avoid it.

PS: if someone can record the sound coming from Skype AND the local sound from my mic in the same file via Audio Hijack Pro, let me know. I know it’s possible but for some reason it does not work for me (not a huge problem as it’s not my workflow).

Recording format

Make sure to record in a non destructive format like WAV or AIFF. The reason is that you will apply a bunch of mixing tricks down the road and getting the real bits are going to help. The size is going to be roughly 700 MB per hour and per person.

What you can do to cut down the hard drive and bandwidth bill is to use the FLAC format that is a non-descructive compressed audio format. I personally use Max a free audio converter tool for Mac OS to convert my WAV or AIIF into FLAC. One hour of recording then goes down to 200 MB (around 4 times the MP3 equivalent). Audacity also can record in FLAC nateively in the latest beta version.

Backup

If you use the local recording approach, do yourself a favor, create a Dropbox account. It’s free for up to 2 GB, it’s a breeze to share files with others even my mother can do it: Dropbox materialized itself as a local directory synchronized in the cloud and subdirectories are sharable. The link I gave is a referral link and you get an extra 250 MB free if you use it.

Anyway, all the podcast participants must send you their audio file. Make sure to back them up right away (yes I know I’m paranoid). One solution is to leave them on Dropbox while you are mixing them on a different copy.

Other

That’s pretty much it for the technical side of it. Make sure to have fun when doing your podcast. You’ll be happier, people will notice the more natural tone and you will be more popular.

Another trick is regularity: record your podcast regularly. It could be once a week, once every two weeks, once a month. That will set your listeners expectations. Make sure not to overestimate your commitment: one a month is big enough. As you will see in the mixing blog post, it’s a lot of work especially when you are a beginner. It’s not unheard of to spend 6 or 7 times the final podcast length to record and publish it.

The second part will be about Mixing your podcast.

JSF Days 2010 Tomorrow and Wednesday

If the gods of French and German strikes allow me, I will be speaking at the JSF Days conference organized by Irian.

I will first talk about Hibernate Search and how the magic of approximation works in Full-text search and the next day I will cover Bean Validation and how it integrates in the Java ecosystem and JBoss AS 6 Milestone 2.

Come and say hi if you are in the Vienna area.

Migrating from Blogger (esp FTP) to Wordpress

I am one of the “few” that have been let down by Blogger. They no longer support FTP export which makes it a no go for me.

I’ve decided to move over to a self hosted WordPress. It was a very easy process overall, this blog summarizes the few steps needed.

1. Install WordPress

The first step is to install WordPress. My provider offers a very easy install via SimpleScript.

I have personally installed WordPress in a subdirectory of my blog site to avoid messing with the existing files.

2. Find a theme you like

Moving along, nothing to see here. Pick and chose from the theme explorer in the admin console of WordPress.

3. Move your Blogger blog from FTP publishing to myrandomblog.blogspot.com publishing

For the import to work, you need to expose your Blogger blog as a blogger hosted website. Don’t worry, since your blog is already published, your users will still be able to access it while you are messing around.

4. Create a user (optionally)

By default, the user is admin but you can create a dedicated user (in my case emmanuel).

5. Import your posts and comments

In the WordPress admin console, go to Tools, select import, Blogger, the specific blog you want to import (in this case myrandomblog), and click. You can optionally associate your posts to a user in WordPress ( hence step 4. :) )

6. Adjust the .htaccess (if in a subdirectory)

In the root directory of your website create an .htaccess file if you don’t have one already and add the following rule.

DirectoryIndex index.php wordpress/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#point to the wordpress directory
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^atom.xml$
RewriteCond %{REQUEST_FILENAME} !^feed$
RewriteRule . /wordpress/index.php [L]
</IfModule>

7. Adjust your feed to point to Feedburner (optional)

If you use feedburner and want your feeds to point to the feedburner feed, install FD Feedburner Plugin (from the WordPress admin console, select Plugins-> add new

Then burn your feed in feedburner (or reburn it if you already have a feedburner feed). The URL to burn is typically blog.mywebsite.com/feed

Copy your feedburner feed URL in the Feedburner plugin configuration (you can reach it form the Plugins menu).

Note, you can also burn your comments feed using the same solution.

8. Redirect your old feed to the WordPress feed

Blogger publishes your feed in atom.xml by default (unless you have overridden that in the publishing panel). Let’s redirect the old feed to the new feed, you don’t want to lose your existing followers, do you?

In your .htaccess file, add the following line

Redirect permanent /atom.xml /feed

You might have noticed that one of the RewriteCond rules is about the atom.xml file. If your feed is publicly available to a different file, change that as well.

9. Do not delete your old .html files (optional)

I’ve decided not to delete the old .html files that were pushed by Blogger. My reason was to let old references to still work. It’s up to you.

And you are done. Happy blogging :)

Le ParisJUG deux ans après

For people who either don’t speak French or are not in Paris tomorrow, skip this post, it’s useless to you :)

Le ParisJUG a maintenant deux ans. Difficile de se rappeler Paris sans un JUG vivant et actif. Difficile de se rappeler la France sans ses 437.654 JUGs. Merci à Antonio et toute l’équipe pour avoir initié cette aventure.

La soirée d’anniversaire est aujourd’hui mardi 9 février 2010 à 18:45. Venez nous rejoindre pour une soirée qui célébrera l’open source français avec Sacha Labourey (voir plus ;) ) en guest star. On est déjà au moins 348, donc un de plus, un de moins ;) Inscription gratuite mais nécessaire ici.

Hit the road Jack

Now that I am done with my what took a lot of my time recently, I will be on the road for pretty much the whole month of november all over Europe to spread the word.

First and foremost, I will inaugurate the new MarsJUG (in Marseille) on October 15th. I will be talking about Hibernate Search and how to implement clever full-text search engines using approximations (phonetic approximation etc).

I will also be speaking in Munich at the W-JAX conference on November 10th and 11th. This time I will cover:

  • Bean Validation (JSR-303) and Hibernate Validator 4 (just released)
  • What’s new in Java Persistence 2.0. I will spend a good chunk of it to explain the new type-safe Criteria API
  • Hibernate Search and how to do full-text searches with Hibernate-based applications

Next in line is Devoxx where I will give a university talk on Hibernate Search. If you want to know everything about Hibernate Search, this is the time! This is November 17th in the afternoon. This is an interesting format (3 hours), where i will cover a bunch of what is in my book Hibernate Search in Action and do a handful of demonstrations.

Last but not least, I will be speaking at JavaEdge ’09 on November 16th in Israel. This time about Bean Validation and Hibernate 4.

If you come by these cities at the right time, come and join me! Between one of these conferences is my birthday :o )

Edit: I forgot that I will be speaking at the ParisJUG on December 8th about Bean Validation. Right after a healthy debate on Spring vs EE 6 (I heard that extra medics and blood supply have been planned)

JBoss Community Asylum – a new podcast with bits of me in it

Remember my French podcast Les Cast Codeurs? (Doing well, thank you for asking) Well apparently, I did not have enough and started a new one. In English this time.

JBoss Community Asylum. A podcast on, by and about the JBoss Community and its gazilllllllion projects and ideas. It’s available here and the iTunes link is here. Basically, instead of blaming people about the lack of podcasts on the great tech at jboss.org, Max R. Andersen (JBoss Tools), Michael Neale (Drools + cloud thingies) and me have decided to give it a shot. You will get the latest news on from the JBoss sphere and we will likely interview folks about their projects.

Let us know what you think and how you would like it to evolve. It’s a low-key bottom-up approach so anything’s possible.

PS: I made progress, I am not the sound engineer this time, yeah!

Book review: Dependency Injection by Dhanji Prasanna

Over the last few days, I have been reading Dependency Injection by Dhanji Prasanna published by Manning. I must admit, this is a much easier task than writing Hibernate Search in Action ;)

Summary first: very easy to read, a gold mine of knowledge and tips on a subject that is essential to the life of today’s Java developers. Go buy it and keep it around your desk.

Let’s quickly talk about the book structure. The book walks you gently through the DI (Dependency Injection) subject:

  • why do you need DI, what does it solves concretely in application developments
  • what is injection, what are the main concepts
  • using DI to improve application modularity
  • object scoping and how to approach that with DI solutions
  • best practices learnt with tears and blood
  • and a small concrete application showing how to use Guice as your DI container

If you are a beginner, this book will explain to you how and why using DI. If you are an expert and use DI on a daily basis, this book will help you rethink what you have taken for granted in DI-land and learn a handful of new tricks and design patterns.

I consider DI and the notion of scope (aka context) to be an essential knowledge to any Java developers. This will become even more pressing with the soon arrival of JSR-330 (Dependency Injection for Java) and JSR-299 (Context and Dependency Injection for the EE platform aka Web Beans) and their inclusion in Java EE 6.

Just like you had to learn polymorphism, you need to learn DI and context management as this is an essential tool for proper component design and application modularization.

The only gotcha is that this book comes right before the finalization of the two JSRs and hence does not cover them. Don’t be too afraid though, all the core concepts covered by these specifications are thoroughly explained in this book. The problem / solution approach used by Dhanji will perfectly complement your knowledge of the DI JSRs.

My advice is to keep this book on your desk when you develop (next to Hibernate Search in Action mine of course ;) ), you will save yourself the burden of learning the best design approaches the hard way.