Feb 06

Firefox 3: A reason why it is fast

Tech, Web Browsing with tags: , 6 Comments »

Firefox 3

I have talked a few times about how much I am liking Firefox 3b2 on the Mac. I had given up on Firefox 2, as it was too slow and ate too much memory. Firefox 3 is a different beast. It also barely ever reminds me that it is in beta. It has been very stable indeed; the only issue coming when I am on flaky wireless.

Of course, only a few plugins are working on Firefox 3 (or maybe most work but they don’t update their file / I don’t force update it). This means that I am not loading a bunch of plugin code that slows down Firefox. Thus, I do wonder how it will fare when Firefox 3 is out in full force and so are the plugins.

If FF3 can continue to match Webkit (well, almost) AND give me the plugins I love? Good luck to ‘em.

Feb 05

The @third Wheel

Comic, Tech with tags: , 3 Comments »

The @third Wheel

There is that strange feeling when you get in the middle of a @conversation on Twitter. Often you get to only see one side of a conversation that is a huge time waster:

@bob Ok
@harry I totally agree with what you said!

If you are frustrated you may click on @harry just to see what the bloke said, but you will normally regret it. On the other hand, in rare circumstances you will find someone you really want to follow. Riiiiight.

Feb 05

Google Gears Database API on the Server

Gears, Google, JavaScript, Tech with tags: , , 2 Comments »

As soon as I started to play with Aptana Jaxer, I saw an interesting opportunity to port the Google Gears Database API (note the Gears in the logo!)

If I could use the same API for both client and server side database access, then I can be enabled to do things like:

  • Use one API, and have the system do a sync from local to remote databases
  • If the user has JavaScript, use a local database, else do the work remotely
  • Share higher level database libraries and ORMs such as Gears DBLib for use on server side data too

I quickly built a prototype to see if this would all work.

The Jaxer shim of the Gears API was born, and to test it out I took the database example from Gears itself and made it work.

To do so, I only had to make a few changes:

Run code on the server

I changed the main library to run on the server via:

<script type="text/javascript" src="gears_init.js" runat="server"></script>

I wrapped database access in proxy objects, such as:

function addPhrase(phrase, currTime) {
  getDB().execute('insert into Demo values (?, ?)', [phrase, currTime]);
}
addPhrase.proxy = true;

This now allows me to run the addPhrase code from the browser, and it will be proxied up to the server to actually execute that INSERT statement.

This forced me to separate the server side code from the client side code, which is a better practice anyway, but it does make you think about what goes where. In a pure Gears solution I can put everything in one place since it all runs on the client.

Create the new gears_init.js

A new gears_init.js acts as the shim itself. Instead of doing the typical Gears logic, it implements the Gears database contract. This wasn’t that tough, although there are differences between the Gears way, and the Jaxer.DB way. The main difference is to do with the ResultSet implementation, where Gears goes for a rs.next()/rs.field(1) type model versus the Jaxer.DB rs.rows[x] model.

I actually much prefer Gears DBLib as it hides all of that, and just gives the programmer what he wants… the rows to work on.

oncallback magic

In the current Jaxer beta, I ran into an issue where I wanted the Gears library to just “be there” for any proxy requests.

You have to think about the lifecycle of a Jaxer application, and the documentation tells you what you need to know to work around the issue.

In this case, I wrapped the code in:

function oncallback() {
  // create the wrapper here
}

This is less than idea, and Aptana is playing with nice scoping which would enable you to just say “hey, load this library once and keep it around for the lifetime of the server | application | session | page”. That will be very nice indeed.

You can do a little bit of this by opening up your jaxer_prefs file and adding the resource for your file:

// This option sets up an html document that will be loaded
// everytime a callback is processed.  This has to be a local file.
// If not specified, an empty document will be loaded.
// pref("Jaxer.dev.LoadDocForCallback", "resource:///framework/callback.html");

Future…

This is just the beginning. As I mentioned at the beginning, I am interested to see where you can take this to handle clients who do not support JavaScript, and also to deal with synchronization with minimal code (sync from local to remote with exactly the same SQL API).

Feb 04

Gimme My Social Graph!

Comic, Tech with tags: , No Comments »

Gimme My Social Graph

It is interesting to hear the word on the Social Foo. I wish I had been in town to go, whatever happened… there were a lot of smart people in the same room.

I am personally hoping to hear some solid things that come out of it. Things like “Twitter and Jaiku now federate” or “MySpace and Facebook share their graphs” (heh :).

One friend told me that it was fairly high level, and more like product managers getting together to chat than engineers. Time will tell!

Feb 04

Worst, no best superbowl!

Personal, Sport with tags: No Comments »

Best worst superbowl

I have to admit it. I was bored in the superbowl until the last 5 minutes or so. I was enjoying chatting with friends, but the game was going right over my head. Of Eli had been intercepted there, this would have gone down as a boring sloppy game, but instead….

Feb 04

Bill Burke wants to get rid of Java!

Java, Tech 12 Comments »

Bill Burke jumped onto the computer after a painful last few minutes of the superbowl to tell us how he could be done with Java:

I also do not believe that Java is the end all, be all of existence.

He thinks that a new Java needs to come around and it must have the following features:

  • Be typesafe, statically typed
  • Have an IDE that supports the same features as modern Java IDEs
  • Have a rich set apis and libraries to build my applications from
  • Have a viable commercial ecosystem
  • Have a vibrant open source community.

If Java is to stay around it “needs elegant, typesafe closures to complement annotations as a way to implement DSL. It needs a standard, non-code generating way of adding behavior to annotations. It needs a structural syntax to make initialization easier. AOP support might be nice too, or at least JVM support to make it easier to implement AOP-like features. Better zero-turnaround development features in both the JVM and APIs like Java EE, Seam, Hibernate, Spring, and JBoss AS would help out tremendously as well.”

BEEP BEEP BEEP

Ok, ok, what am I doing here?

After listening to the political commentary this “season” for what seems like an eternity, I decided to see how I could turn around something that someone said and make the opposite point.

Bill was actually ranting against dynamic languages and FOR Java. Just like certain benchmarks, it is easy to take things out of context and paint a different picture.

Bill, the result must have been hard to take, but you did have a fantastic season.

Feb 03

Checking the network to handle offline applications

Gears, Tech with tags: 1 Comment »

One of the common questions we here in Gears land is, how to handle checking if an application is online or offline. This is a trickier problem that you may think at first. What does it mean to be offline?

The Autodesk guys talked about this a little in their interview. They have the notion of online and offline, which is just a flag. They then have the notion of connected or disconnected, which they test at regular intervals.

Mathew Foster recently posted the code that he uses to handle this situation. He basically ported the Dojo Offline work to Prototype, and you end up with a library that you can use like this:

var netCheck = new NetworkDetection("blank.php");
 
netCheck.addEventListener("online", function(eAja) {
  $("display").innerHTML = "online";
});
netCheck.addEventListener("offline", function(eAja){                                          
  $("display").innerHTML = "offline";                                      
});

Some other folks also put their thoughts out there.

Firstly, Dimitri Glazkov (who is on fire recently btw) posted his monitor script:

    // provides connection monitoring
    // controller
    function Monitor() {
 
        var me = this;
 
        //  triggered when connection changes
        //  sends as parameter:
        //      online : Boolean, true if connection became available,
        //          false if connection is broken
        this.onconnectionchange = nil;
 
        // starts the monitoring
        this.start = function() {
            try {
                wp = google.gears.factory.create('beta.workerpool', '1.0');
            }
            catch(e) {
                return false;
            }
            wp.onmessage = function(a, b, message) {
                if (message.sender == id) {
                    // only two messages: 
                    // first [f]ailure to connect 
                    // or back [o]nline
                    var text = message.text;
                    if (text == 'f') {
                        me.onconnectionchange(false);
                    }
                    else if (text == 'o') {
                        me.onconnectionchange(true);
                    }
                }
            }
            id = wp.createWorker(String(worker) + ';worker()');
            // send a message to the worker, identifying owner's id
            wp.sendMessage(window.location + '?poll', id);
            return true;
        }
 
        function worker() {
            var POLLING_INTERVAL = 2000;
 
            var wp = google.gears.workerPool;
            var url;
            var parentId;
 
            var first = true;
            var online;
 
            var timer = google.gears.factory.create('beta.timer', '1.0');
 
            wp.onmessage = function(a, b, message) {
                url = message.text;
                parentId = message.sender;
                poll();
            }
 
            function poll() {
                var request = google.gears.factory.create('beta.httprequest', '1.0');
                request.open('HEAD', url);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        try {
                            if (request.status == 200) {
                                if (!online) {
                                    online = true;
                                    wp.sendMessage('o', parentId);
                                }
                            }
                        }
                        catch(e) {
                            if (online || first) {
                                online = false;
                                first = false;
                                wp.sendMessage('f', parentId);
                            }
                        }
                        wp.sendMessage('d', parentId);
                        timer.setTimeout(poll, POLLING_INTERVAL);
                    }
                }
                try {
                    request.send();
                }
                catch(e) {
                    if (online) {
                        online = false;
                        wp.sendMessage('f', parentId);
                    }
                }
            }
 
        }
 
        function nil() {}
    }

Gears co-lead Aaron Boodman also put his hat in the ring with a solution that uses the Gears HttpRequest object, and a clean use of onerror:

function monitorOnlineness(url, onlinenessChanged) {
 var interval = 1000; // check network once a second
 var onlineness = null;
 var timer = google.gears.factory.create('beta.timer');
 var timerId = null;
 
 function check() {
   timerId = timer.setTimeout(function() {
     var req = google.gears.factory.create('beta.httprequest');
     req.onload = function() { onlinenessChanged(true); }
     req.onerror = function() { onlinenessChanged(false); }
     req.open("HEAD", url);
     req.send(null);
   }, interval);
 }
 
 function updateOnlineness(val) {
   if (onlineness !== val) {
     onlineness = val;
     onlinenessChanged(val);
   }
   check();
 }
 
 function cancel() {
   if (timerId) {
     timer.clearTimeout(timerId);
   }
 }
 
 return cancel;
}

You quickly find that there are many solutions, and that they depend on what you really need to do for your application use case. I am still personally hopeful that an 80% solution is placed into Gears itself as a starting point….

Feb 02

Silveryahoo: Don’t you want to see Yahoo! Silverlight Mail?

Comic, Tech with tags: , No Comments »

SilverYahoo!

Everyone and their mother has said something about the Microsoft Yahoo! deal. I actually don’t have much of an opinion, and whatever I do say certainly has nothing to do with my employer.

As a developer, I am curious how the infrastructure merging would occur. I have been a definite fan of Yahoo! and although some people try to make out a Y! vs. G thing, I think that is stupid. There are micro competitions of course, but at a macro level, Yahoo! is an Open Web, Open Source company. I really want them to succeed, and I believe that if they do well, it will be good for the Web and good for Google.

Whatever happens, it was good to see the stocks go up a little on the news :)

Feb 01

Finally use of my XFN and FOAF

Comic, Tech with tags: , , No Comments »

Social Graph Cartoon

I don’t know about you, but I did this. I went through my site and added a bunch of XFN. I had run rel‘ing away. It didn’t really do much for me though, it was always a promise of an open format. I played with a few tools, but I largely forgot about it. When I add a friend in Facebook, or Twitter, or …. I see immediate effect.

I am really hopeful that the Google Social Graph API and other efforts change the equation though. This is only the beginning, so who knows where it will go!

Feb 01

Google Social Graph API Released

Google, Tech with tags: , 2 Comments »

Would you like to be able to make a quick call to get a JSON response that ties together a social graph made up of resources available on the Web?

Social Graph API

Brad Fitzpatrick, Kevin Marks, and others at Google have released a new Social Graph API that does just that:

The new Social Graph API makes information about the public connections between people on the Web easily available and useful. You can make it easy for users to bring their existing social connections into a new website and as a result, users will spend less time rebuilding their social networks and more time giving your app the love it deserves.

Here’s how it works: we crawl the Web to find publicly declared relationships between people’s accounts, just like Google crawls the Web for links between pages. But instead of returning links to HTML documents, the API returns JSON data structures representing the social relationships we discovered from all the XFN and FOAF. When a user signs up for your app, you can use the API to remind them who they’ve said they’re friends with on other sites and ask them if they want to be friends on your new site.

This is exciting to me as:

I gave it a quick test drive, and when I say quick, I mean 5 minutes :)

I built a tiny JavaScript library that takes a base URL, and it graphs out the relationships using Canvas.

You get to call loadGraph(URL, { width: w, height: h }) and the graph will be injected away.

It needs to be nicely abstracted and isolated so you can call it willy-nilly, but it works.

Watch the introduction video: