GMail SSL problem fixed.

It looks like the SSL problem is fixed now.

What’s wrong with GMail’s SSL certificate?

gmail SSL Certificate problem?

I’ve been getting this error since yesterday on Firefox (1.0.4 on Linux and OS X). Is it my problem or a general one?

Overriding caching limitations with Javascript

I’ve mentioned some times monitor.vrypan.net, my greek blogs agregator (and search engine too now!). One of the problems I had was that page generation is very demanding in CPU cycles and memory (many SQL queries, and some recursive functions). The obvious solution is caching which is actualy a good one in this case since I know when I update data (fetch new feeds), and in between nothing changes.

However, I wanted to add some personalization by highlighting new posts for each visitor. This means that each visitor would see a different page, depending on when was his last visit. How can this be done on a cahced page? An elegant solution I found was to use a dynamicly generated Javascript do do some “ajustements” to the cached page, after it is loaded.

Here is how.

Firts of all, all posts, are inserted in a table named monitor_posts. This table has a unique id column. So what I would need to do was to set a cookie with the last ID shown, then next time highlite entries with a bigger id.

The generated (and cached) html has entries like <div id=”ITEM_xxxxx” ><div id=”TITLE_xxxxx”>post title</div> …more html here… </div> where xxxxx is monitor_posts.id. I wrote a PHP script that dynamicly generates a javascript file, mark_new.php, that looks like this:
&lt;?
if ($_COOKIE['lastID']) $lastID=$_COOKIE['lastID'] ;
else $lastID=0 ;

$db = DB::connect($DSN);
if (DB::isError( $db )) {
echo DB::errorMessage($db);
die() ;
}

$res = $db-&gt;query("SELECT MAX(id) AS M FROM monitor_posts") ;
$row=$res-&gt;fetchRow(DB_FETCHMODE_ASSOC) ;
$newID = $row['M'] ;

echo "
function mark_new_posts() {
var MaxID=" . $lastID . " ;
var main = document.getElementById('main') ;
var i ;
var j ;
var items ;
var feed ;
var title ;
for (i=0; i&lt;main.childNodes.length; i++) {
feed = main.childNodes[i] ;
for (j=0; j&lt;feed.childNodes.length; j++) {
if (feed.childNodes[j].id &amp;&amp; feed.childNodes[j].id.substring(0,5)=='IITEM') {
itemID = feed.childNodes[j].id.substring(6,38) ;
if (parseInt(itemID)&gt;MaxID) {
title=document.getElementById('TITLE_'+itemID) ;
title.style.color = '#aa0000' ;
}
}
}
}
SetCookie('lastID', '" . $newID . "') ;
}
" ;
?&gt;

Then I include the dynamicly generated js file in my “static” cached page:
&lt;script language="JavaScript" type="text/javascript" src="mark_new.php"&gt;&lt;/script&gt;

and I call it “onLoad”:
&lt;body onload="mark_new_posts();" &gt;

Obviously, the generation of the js file by PHP is not so demanding, the 2 queries performed are fast. And of course, you could have used the same technique based on a session that involves user authentication, etc.

Don’t stick to details as why do you traverse the whole DOM tree and not… This is a specific example for a specific application, with its own quirks and twists. What I find interesting in this solution is how you can use server-side caching to serve a “generic” HTML page and then use it as a canvas to draw on it with a dynamicaly generated Javascript that adds personalization or other features.

Interesting reading on folksonomy

David L. Sifry mentioned this very interesting article at the Technorati Developers mailin list.

Worth reading!

technorati Beta

beta.technorati.com: Try the new Technorati. I like it, especially the usability improvments.

Read more at Sifry’s blog.

greasemonkey

I had been reading about Greasemonkey for some time now, but I had not tried it. I did, a couple of days ago -hey this thing is so cool!

GreaseMonkey is a Firefox plugin that allows you use “user scripts” on a per-url basis. A “user script” is nothing more than a javascript file, but… hey! you can use javascript to completely change the way a web page looks, add links and functionality, rewrite links… Oh, I’m really into this dirty monkey!

Here are a couple of useful links:

I’m sure I’ll be back with my own user scripts soon!

Drag’n'Drop from javascript

Jeremy Zawodny’s linkblog is always a source of interesting things. Today I found this article on how to implement drag’n'drop in DHTML and Javascript. Supercool.

Google Sitemaps Launches

From code.google.com:

[...], Google launched Google Sitemaps, a new service designed for webmasters that enables them to automatically submit their web pages to Google. It is meant to provide Google with more information about web content so we can improve search results for users worldwide. As part of this launch, we’re releasing Sitemap Generator, an open source tool that generates an XML sitemap for a few simple use cases and thus shows developers how to create these files programmatically.

g-metrics is in “Google Hacks”!

It’s nice to see one’s little project getting attention and publicity! I just finished reading Google Hacks, and g-metrics.com, my pet project is Hack #3!

Interesting reading even for someone like me, who thought that knew a lot about Google, Gmail and AdSense… Recommended!

My Yahoo! + unicode

I just noticed that My Yahoo! works fine with unicode feeds (it did not some time ago). That’s good news for all of us blogging in languages other than english!