Maybe you're interested About this site or in some of my Projects or Articles. You might even be interested About me or My Friends. If all else fails head back Home.

Morethanseven is where plays with the web

Projects

Working example of Microformats as an API

Saturday, April 7th, 2007

Drew posted a while ago asking can-your-website-be-your-api. The simple idea is that you just might be able to live without a dedicated API in favour of good use of microformats.

It also turns out Tantek has also been on the case with his presentation Can your website be your API? – Using semantic XHTML to show what you mean and

Glenn has spoken on the subject too at WebDD and BarCamp.

This has interested me for a while and I’ve finally gotten around to writing some code, in fact I wrote the bulk of it during The Highand Fling and then the rest before the Refresh event after I got to te venue an hour early.

I used Drew’s hKit for the microformat parsing so everything that follows is PHP5 only I’m afraid. The also means I dont have a working example on this server at the moment but you can grab the code and try it out yourself. It also makes use of a couple of PEAR modules; PEAR Validate and PEAR HTTP_Request.

At the moment I’ve worked on a simple hCard example. It demonstrates the idea of a website exposing methods based on the presense of microformats, plus using that exposed method to extract the information we’re looking for.

First we create objects for the parser and the website:

$parser = new hKit;
$website = new Website('http://morethanseven.net',$parser);

Then we’ll ask what methods the website exposes:

$website->expose();

In this example we get back an array of the available methods, in this case getContacts. Then just as an example lets print out some contact details:

foreach ($website->getContacts() as $contact) {
   echo $contact->getFN();
}

This is a very early release, more of a proof of concept and as such their is no documentation and only a portion of hCard is supported. Hell, their’s not even a name beginning with h! Having said that I have a plan for a little project to kick the tyres and so I’l l be adding to it and hopfully have a proper release at some point.

The plan is to introduce methods like getReviews, getEvents, etc. which allow for the extraction of the relevant details. The part I find most interesting however is the idea of the expose method – asking a web page if it has an API, and if it does then what information you can extract automagically. If you’re interested let me know what you think.

Download example

Popularity: 9%

Tagged , ,

Fluidflash

Sunday, January 7th, 2007

Their is nothing wrong with a nice header graphic. Clients, designers and customers alike love them. But I often see them used as an excuse for fixed width designs. Well no more I say (unless, of course you have a perfectly good reason for a fixed width design in which case you dont really need this technique.)

The plan was simple. Find a way of incorporating flash headers into sites using liquid or elastic designs in much the same way you might use lots of sliding doors background-image goodness.

And all it takes is a snippet of actionscript goodness:

Stage.scaleMode = "noScale" 
Stage.align = "TL" 
var width
var height
function resizeEvent ( ) {
    width = Stage.width
    height = Stage.height
    dimensions.text    = 
       'width : ' + width+ '
        height : ' + height
    topRight._x = width
    bottomLeft._y = height
    bottomRight._y = height
    bottomRight._x = width
}
resizeEvent ( )
var stageListener = new Object ( );
stageListener.onResize = resizeEvent
Stage.addListener ( stageListener );

Download example

Popularity: 16%

PyGunFog

Wednesday, January 3rd, 2007

My first real foray into writing some simple Python scripts was a few scripts to establish the Gunning-Fog index of some given text. I wont go into lots of details about the uses of such a script; if you’re interested read Gez Lemons writeup over on Juicy Studio.

I took quite a bit of inspiration, and some code, from a similar script, PyFlesch, for establising the Flesch reading score of text.

I expanded things a little, using the Feedparser module to parse content from RSS and Atom feeds and give a Flesch or Gunning-Fog score of the summaries.

Download all scripts

Popularity: 8%

Web.php

Wednesday, January 3rd, 2007

Web.py is a really nice lightweight web framework written in Python. It’s not trying to be Rails or Django, it’s trying to be as simple as possible. Web.php is my homage to Web.py. I’ve unashamedly copied the ideas and build a very simple web framework in PHP. It’s not a complete port, nor does it do everything in the same way.

The code example from the project home page was what originally piqued my interest:

import web
urls = (
   '/(.*)', 'hello'
)
class hello:        
   def GET(self, name):
       i = web.input(times=1)
       if not name: name = 'world'
       for c in xrange(int(i.times)): print 'Hello,', name+'!'
if <i>name</i> == "<i>main</i>": web.run(urls, globals())

My PHP versions goes something like this, I’m sure you can see the similarities:

<?php
require('webphp/web.php');
$urls = array(
   '/' => 'hello',
);
class hello {
   function GET($path) {
      echo 'hello world';
   }
}
web::run($urls);
?>

I’ve used it so far on a couple of projects, but it’s never been properly tested as such nor do I have lots of time to develop it. It’s purposely feature and code light (the core file is only 80 odd lines of code, includig comments).

Download Zip

Popularity: 9%

TXP2Radiant

Wednesday, January 3rd, 2007

Having just moved from a couple of year old Textpattern site to Radiant I didn’t feel much like copy and pasting lots of articles. The script simply copies all your posts from textpattern into the relevant place in Radiant.

Download PHP

At the moment this is undocumented and pretty rough but it saved me time and works. I’ll try and work up and potentially rewrite in Ruby for possible inclusion in the Radiant core if time permits.

Popularity: 8%