Microformats extension to SimpleXML

Oliver Brown
— This upcoming video may not be available to view yet.

I’m writing a PHP5 object that extends SimpleXML to automatically add various microformats. So you could do, for instance, the following:

$xml = SimpleXML\_load\_file('test.xml');
foreach ($xml->hEvent as $event) {
    print $event->original();
}

This would print the original HTML of every hEvent found in the HTML document. XML, PHP, PHP5, microformats, hCard, hReview, hCalendar

Code generation in PHP

Oliver Brown
— This upcoming video may not be available to view yet.

I’ve started working on a class-based code generation utility for PHP (in PHP). Like the scripting engine it’s working out simpler than I expected. Quite how powerful or indeed useful it could be is yet to be seen. The way it works is by allowing you to define fragments of classes. For example the Singleton fragment is:


class !className {
    static private $instance;

    private function \_\_construct() {
        // Code Start
        // Code End
    }

    static public function Init() {
        if (!self::$instance) {
            self::$instance = new !className();
        }
        return self::$instance;
    }
}

You create a class with some number of fragments. Each successive fragment adds specified method and properties to the class. If two (or more) fragments define the same method (probably common with constructors for instance) the the code for the second fragment get’s added in the //Code Start ... //Code End sections. Ultimately you will be able to change your model (defined in XML and it will update your code accordingly, maintaining all the code within the //Code Start ... //Code End sections.

DOM foolery

Oliver Brown
— This upcoming video may not be available to view yet.

Since I’ve been making random DOM and JavaScript posts recently I thought I’d share a clever bog post I found cleverly called DOM-foolery. It describes a relatively simple way to make images in web pages have curved corners.

Overpopulation as a cure for healthcare

Oliver Brown
— This upcoming video may not be available to view yet.

Something interesting occured to me recently. Evolution of the human species has been basically halted by healthcare. Since the weak no longer die before reproducing, the makeup of the genes of subsequent generations is random. The good news is the cure needs no effort as such. If we let the population grow until we no longer have enough food then people will start dying more. The people who manage to survive will pass on their genes and evolution will begin again. The only question remains is whether the survivors are the sort of people we want continuing the species. They will predominantly be the rich and although many rich people get that way by being smart or more productive somehow, some of them definitely don’t.

starvation, evolution, over population

How about Cash City Wars

Oliver Brown
— This upcoming video may not be available to view yet.

That’s the name I’ve come up with for the game since it’s vaguley based on Cash Wars. Or at least will be. I’ve started adding descriptions to towns. There are a few issues still though, most notably the existence of multiple towns with the same name which I am eliminating (I’m only intending to have the largest 100 towns).

Cash City Wars

Online Poker

Oliver Brown
— This upcoming video may not be available to view yet.

I decided on a whim to try PartyPoker.com (for free) and ended up having far more fun than I expected.

Unfortunately the minimum deposit to play for money is $50 which is far more than I’m willing to spend…

Cash City Wars

Oliver Brown
— This upcoming video may not be available to view yet.

Here’s a demo of what may become a game: Cash City Wars.

There are various reasons for the title I won’t go into right now… Basically the game will involve you moving from city to city in some way (quite exactly what the mechanics of the game will be I don’t know yet). The cool thing is that it will use real geographic data. At the moment there is only data for the UK but depending on availability I could add the whole world.

Although they don’t like it, the town names are in fact clickable.

Reading style info with JavaScript

Oliver Brown
— This upcoming video may not be available to view yet.

Part of the online game I’m now developing (which needs a name - I was thinking of “Cash City Wars”) requires some Javascript that alters the style of a DIV and then puts it back as it was. Changing the style is easy. For example to make the text green:

// Some code to get the DIV object and  store it in obj.

obj.style.color = "green";

Storing the old style information is a little difficult. I tried:

obj.oStyle = obj.style;
obj.style.color = "green";

But that didn’t work for two reasons: firstly objects are passed by reference so oStyle always contained the same thing as style. And secondly style (when used for reading) only contains explicitly set properties. So if you set width and left you’d still have to work out right yourself.

I found out there is another property you can use, getComputedStyle. This has it’s own little quirks however. Firstly it isn’t an method of the object, but used more like a function and secondly it doesn’t seem to work in IE6.

Firefox (W3 DOM):

temp = document.defaultView.getComputedStyle(obj, "");
temp.getPropertyValue(prop);

IE6

obj.currentStyle[prop];

I personally think the IE way makes more sense in this case but we have to cope wtih both. One thing that is slightly awkward is that one is a function the other is an array. So to make a simple to use interface to the correct function, we can use Javascript’s ability to use functions as first class objects (which means you can assign them to variables):

if (document.defaultView) {
    var cStyle = function(obj, prop) {
        var temp = document.defaultView.getComputedStyle(obj, "");
        return temp.getPropertyValue(prop);
    }
} else if (document.body.currentStyle) {
    var cStyle = function(obj, prop) {
        return obj.currentStyle[prop];
    }
}

You can now call cStyle like a normal function to get the computed value of any style property of any object.

Make money from links people don’t click on

Oliver Brown
— This upcoming video may not be available to view yet.

I found a site a while ago that was willing to pay for text links on your site. The wanted them not because they thought they’d get more direct traffic but because they’d get an increase in PageRank.

It’s quite a popular idea these days with a few sites offering text link brokering services. You pay them and they get several high PR sites to link to you. Doesn’t matter if the sites content don’t match, just that Google finds the link. I never had a site with a high enough PageRank until now to actually join. Now I do, I thought I’d give it a spin; I joined Text Link Brokers.

A quick search on Google revealed little information (lots of question on forums with no answers). There was one negative comment but it was apparently about one of the competitors instead that has a very similar name. Anyway a couple of days after signing up I was told I need to reduce the number of external links since they only allow 20 in total and want to be responsible for five of them (that’s why I now have a bit at the bottom of the page counting external links). After sorting that out they sent an email for the rates they are willing to pay. And they’re pretty good. Not marvelous but they don’t actually require people to click like Adsense ads do.

The one problem is I now have to wait for someone to actually buy links.

Adsense section targeting

Oliver Brown
— This upcoming video may not be available to view yet.

I spend a couple of days away from the internet and things happen!

Google now allow you to split a page into sections with the idea that Adsense ads are only targetted to the text in that section. A couple of comments is all you need: <! -- google_ad_section_start --> <! -- google_ad_section_end -->

Apparently Google only take this as a suggestion but in some situations it could help. Of course sticking to one topic per page is better nearly all the time anyway.