Archive for August, 2008

Massive mail import in GMail

Monday, August 25th, 2008

Recently I had to archive a consequent number of mails into GMail. I don’t want to keep those mails in my Mail User Agent (Mail.app), yet I want to be able to search and retrieve any single mail. Of course I’m keeping an mbox version of those mails but once it’s in an mbox, it’s kind of dead because you cannot easily read one mail or search the mbox.

I considered several solutions and the simplest I could find is to dedicate one GMail account for that purpose. The only drawback is to have internet access but I’m fine with that. In addition the IMAP support provided by GMail allows to do that without any hacks.

Once my special GMail account was created, I started to use my mail client to copy the messages in dedicated folders in the archive account. It was working fine for a small number of messages like 5000. Some of my mailboxes have way more messages, like 60,000. Above 5000 messsages, it becomes a nightmare for two reasons:

  • The mail client synchronizes with the archive account which slows down the whole process.
  • Network failures are more likely to happen and make the whole process very fragile. When you have a network failure you don’t know how your mail client will hold the resume.
I started to look around for solutions but I did not find something that would work out well for me. So I started to create my own solution, that would just do the job. Obviously I used Java as it offers all the low level API and frameworks to build the solution:
Then I wrote a few classes using the above frameworks to perform the massive import. It turns out to work very well and deals with network failures when it happens. I won’t make an open source project because I don’t have extra time to invest in that, however if someone is interested in getting the source code, I would give it as it is.

The footprint of the Air Ajax runtime

Thursday, August 21st, 2008

When I started to use Spaz, I naturally twitted about it and of one my friends tried it. He recognized that the application was better than Twitterific but did not adopt Spaz because of the OS resources consumed by the application. I know a bit the heart of Spaz as I developped a few of its features, I know that it does not waste resources and I concluded that perhaps the runtime could be the cause of this overhead.

This morning, I downloaded one of the simplest applications written in Air Ajax, the classic Hello World application. I simply executed the application adl -nodebug application.xml and used the Activity Monitor utility provided by Apple to measure the memory and CPU footprint. The question is simple: what is the overhead of an application that nearly does nothing and have nearly zero state ? Note that I use the -nodebug switch which optimizes the runtime, thanks to Ed Finkler that gave me the hint. It helps to reduce the CPU used by the application by a factor of 2. The first version of this entry did not take it in account.

Disclaimer: this test is very subjective and if someone else performs the same test, he will likely find a different result.

The answer is pretty big for me. My machine is a MacBook Pro 2ghz with 2 gigs of RAM (I can’t have more because it’s one of the early models). The application uses constantly around 2% of CPU and 20 megs

It is way too much for desktops. I wondered then how does it scale if I run 10 times the same application ? Perhaps that Air has a smart runtime that can collocate resources ?

Ten Hello World Footprint

Ten Hello World Footprint

According to my results, running 10 Hello World application consumes around 200 megs of RAM and around 20% of my CPU. Clearly I see a problem here, how can the end user really uses several Air applications at the same time without consuming too much OS resources ?

That reminds me the story of the Java virtual machine. Back in 2000, the early versions of the Java virtual machine were slow and gradually they improved the performance of their virtual machine. If I remember correctly the JDK 1.4 was the first release to provide decent CPU performances and then each major release had seen decent performance boosts. BTW: Sun’s VM also uses lot of memory but the CPU footprint is nearly zero. Reducing memory overhead is not achieved yet, I know they have plans to collocate if you execute several virtual machine though, I am not an expert.

I hope that Air will follow the same path and that Adobe will invest in the optimisation of the runtime. In my opinion it is a key factor to increase the adoption of the platform.

Adobe Air for Ajax Developers review

Monday, August 18th, 2008

I have been playing recently quite often with the Adobe Air SDK for Ajax developers. For more than 10 years my focus has been mainly the Java Platform and I did not have to use anything else so far. Don’t misunderstand me,  I won’t probably use much the Air in my job activities. My interest for it comes from the involvement in the Spaz project. Spaz is an open source Twitter client written for the Air runtime with the Ajax kit, the story is a very classic one, I was looking for a good Twitter application and after using Twitterific for a few days, finally I switched to Spaz. Spaz answered most of my needs and I was able to easily provide patches to add new features that I was considering as important to me.

The first thing I did was to install the Air SDK for Ajax development. Adobe provides several development runtimes and one of those is based on Web standards: HTML, CSS and Javascript. Once you have downloaded the kit, you need to set the AIR_HOME variable and add to your path the $AIR_HOME/bin expression.

After that you have access to the adl command that allows you to start an Air application. In the case of Spaz, I downloaded the source tree from the SVN and used adl application.xml et voilà! The application just start.

The main advantage of the Ajax runtime is to reduce the entry level for developers. I was already quite familiar with Web and Ajax technologies and Adobe had a great idea to create such a platform. (It helped me to understand better Sun strategy with the heavy promotion of the Java FX platform). Most of the objects you will use are wrappers of Actionscript 3.0 objects, if you look at the documentation you will find for instance that the air.desktop.Icon is an alias for the window.runtime.flash.desktop.Icon. Does the developer cares about that ? I would say yes, because the default wrapper set is partial and does not cover the full platform, therefore sometime you need to use window.runtime.flash.* when you want to access advanced features. It happened to me when I added a feature that display the number of unread message in the dock icon, pretty similar to what Mail.app does.

The platform seems powerful enough. However compared to the Java platform it’s very poor, but the main focus of the platform is to build RIAs and therefore it does not matter much. The integration with the desktop lets you leverage native menus, the dock icon on OS X and the system tray icon on Windows.

The documentation is the weak points of Air. The online API documentation is similar to Javadocs, so you will feel comfortable with it. The main issue comes from the main documentation that does not cover everything. The documentation for the embedded local SQL database is just minimal. When I developed the badge feature for the dock icon, I felt it was possible to leverage the powerful vector capabilities of Air to create nice shapes and indeed I was able to achieve it but as the cost of looking at the Actionscript 3.0 documentation which in my opinion is an issue (well even the Actionscript documentation was not enough) and I was left by myself.

Finally I find the platform powerful and simple, the main issue being the documentation. If you have good Web and Ajax skills you can leverage them to build quickly an application. The main advantage over traditional Ajax application is that you won’t be annoyed when doing cross domain Ajax, won’t have to deal with browser quirks and will create more powerful RIAs. If your Web and Ajax skills are poor, you should consider twice using that platform, *but* the learning cost in time and resource is not lost as you can reuse your knowledge for building classic Ajax application.

JSON support for WordPress

Thursday, August 14th, 2008

I find quite strange that nobody ever provided support for that. Googling about JSON support for WordPress did not return anything relevant. At all.

I use the JSON support in my home page. It is used to display the last 5 blog entries of this blog in the side bar. It does not appear at first as I did not want to clutter the page, so you need to hover the mouse over the blog section and you will see it appear using a nice fading (thanks to jquery).

Anyway here is the php code for WordPress. It is not a plugin because it does not interract with the heart of the system and WordPress does not seem to have an architecture for adding that kind of feature. I believe it should rather be a core feature of the product rather than an extension.

First step, create a file called wp-json.php at the root of WordPress:

<?php
if (empty($wp)) {
	require_once('./wp-load.php');
	wp('feed=json');
}

require (ABSPATH . WPINC . '/feed-json.php');

?>

Then create a file named feed-json.php in the wp-includes folder:

<?php
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
$more = 1;

$items = array();
query_posts("");
while (have_posts()) :
the_post();
$item = array(
	"title" => get_the_title_rss(),
	"link" => apply_filters('the_permalink_rss', get_permalink()),
	"description" => apply_filters('the_excerpt_rss', get_the_excerpt()));
$items[] = $item;
endwhile;

$arr = array(
'title' => get_bloginfo_rss('name'),
'link' => get_bloginfo_rss('url'),
'description' => get_bloginfo_rss('description'),
'language' => get_option('rss_language'),
'item' => $items);

echo "".$HTTP_GET_VARS["callback"]."(".json_encode($arr).");";
?>

Then the URL to use it is http://yourdomain/yourpath/wp-json.php?callback=myfunction. The callback is mandatory (if you don’t want it, modify the php script above) in order to make the feed mashable directly in a web page. It will return data like:

myfunction({"title":"It is what it is","link":"http:\/\/blog.julienviet.com","description":"A pure technical trip","language":"en", ..... });

I’ll explain later in another post how I consume it in my home page.

Syntax highlight support

Thursday, August 14th, 2008

I’ve just added support for the syntax highlight using the very good project SyntaxHighlighter.

I used the WordPress plugin Google Syntax Highlighter for WordPress but not without pain.

Indeed there is a CSS conflict between SyntaxHighlighter and Wordpress at the list level that makes the highlighted code to be displayed with additional margins. If you want to see what I mean, download the plugin for WordPress and look at the screenshot. The plugin on my blog is fixed.

So now the fix: modify the file Styles/SyntaxHighlighter.css in the plugin (which originally comes from the SyntaxHighlighter project). Add the following at the bottom:

html > body .entry div.dp-highlighter li
{
	margin:0px 0pt 0px 0px;
}

Syntax highligher test

Wednesday, August 13th, 2008

Testing syntax highlighter plugin

public class Hello
{
   public static main(String[] args)
   {
      System.out.println("Hello");
   }
}
function hello()
{
   alert('hello');
}

Unofficial launch

Wednesday, August 13th, 2008

This is the unofficial launch of my blog.

My home page went alive a few days ago and after that I’ve managed to install wordpress and customize it for my needs. Well almost, I still need to add the syntax highlighter plugin and do a couple of other things.

Working on my home page and the blog was a rich experience, actually I never really managed to do so called client side mashups and now I understand better what it is about. Thanks to javascript and JSON, I’ve been able to integrate Twitter and my blog feed into my home page without requiring any server side code. I did it that way for the sake of simplicity in term of development, as I’ve been able to work directly on the page without the need of any server. There’s a trade off though, doing that kind of mashup is not an easy task and requires considerable skills.

I still have a few things to tune in order to officially launch the blog/site and drink Champagne. For instance I may consider to change the default theme of the blog although it is quite nice, it obviously has a taste of déjà vu. Actually I am considering to pay someone to create a custom theme, but I would need to find the right person first.

I hope to open next Monday, see you next week!