Monday, March 30

It's the "Aaargh! Facebook!" Post

I really don't know whether I should just totally delete my account -

and spit vehemontly every time someone says the word, or -

continue using it as an incredibly useful communication tool; everyone I know is on it, therefore, it's remarkably universal.

I joined facebook "back in the good old days", and back then, it was a fairly simple business. It's great that it's become such a phenomena - but with the increased pressure from the media, marketing groups, affiliate programs, yadiyada.. I'm inclined to say I'm losing faith - slowly but surely.

Currently I'm trying to teach the damn advertising bar that I don't like Hot Dates! or Twatty Mobile Phones! whereas Joni Mitchell tee-shirts and cheap flights to weird places are actually okay in my book, and I'm happy for them to appear in my space. It doesn't seem willing to co-operate.

And that should be the whole point behind social marketing. There are things I'm interested in, for god's sake - just take the hint!

Look Facebook - this is all like.. "Hmm! Super interesting!"

Whereas this is all like "Fuck off Facebook!"
I'm off to hear Paul Cusick's debut CD. Sorry girls..

Friday, March 20

Don't ask questions you already know the answer to - REST apis part 3

Okay, let's have a look at something else.

You probably don't want to go trawling for data every time you need to process some, so let's look at saving some data.

State your REST source as usual, but instead of a simplexml load, do:


Which loads your resource, saves it to the server as xml (or whatever), then closes the connection. That's all you need to put it this file - end with ?> as usual and save as whatever - fetchdata.php

Then, whenever you need to refresh your source: include("fetchdata.php");

Whenever you want to use the data that's already there:

$sxmlobject = simplexml_load_file("somedata.xml");

if it's XML. If you have to deal with JSON you can still loop if you use an array, instead of a simplexml load.

Here's one last trick. On your main page, you can make it refresh the data in time intervals. Or specifically, you tell it to refresh if it's been at least X mins/hours/days since the last refresh.

//This function refreshes the data and records the time it does it.
function refreshData()
$t = time();

//This is now
$timenow = time();

//If you can't find that record, refresh anyway. This is so it works first time!

//Find out the last time you refreshed - might have been just a few lines above though!
$timeload = file_get_contents("lastupdate.txt");

//If it's been 10 hours - 36000 seconds - since refresh, refresh!
if ($timenow > $timeload + 36000)

$sxmlobject = simplexml_load_file("somedata.xml");
//and do something with it!


Sunday, March 15

Particularily Happy Place - REST apis part 2

Okay, if you want to start querying, you'll need a server to run your PHP code. I recommend giving XAMPP a look - you'll get Apache, MySQL and PHP support all ready to go out of the box (okay, almost - I think all I had to do was initialise openssl in apache/bin/ini.php - google it) for free!

Ready to go? I'm a big fan of PHP for it's pretty open typing - I hate having to declare everything, I find this language makes it relatively easy to juggle resources without actively having to keep track of everything and worrying about type conversions etc. Let's just jump in.

The first thing to do is define your source. Most apis will have a token system to stop malicious users abusing the system, so I'm going to add that string in here too. Something like this:

$call = "";

creates a variable called "$call" and inserts your resource address as the value. Note the dollar sign denotes a variable. You'll then want to insert some other query strings:

$call = $call."&country=uk";
$call = $call."&city=london";

Note we could have lumped all three of these together in one declaration, but we'll want to come back later to change these, as it'd be useful to actually change their values. I'll come back to this.

$xml = simplexml_load_file($call);

Keeping this really simple, in one line we've: contacted the server ( here, at, retrived the response and loaded it into a simplexml object called "$xml". If you look back to the last post, we had a response which contained one level of hierarchy - so we need to drill inside the "response" tag to get to the tags we want e.g. "temp"...

We can do this easily using a foreach statement, which looks at each child of the $xml variable (calling it $xmlchild). We then call the name of the tag $xmlname - and the print $xmlname and $xmlchild, with a hyphen between them, and a break at the end.

foreach($xml->children() as $xmlchild)
$xmlname = $xmlchild->getName();
echo $xmlname."-".$xmlchild."<br />";

Once the server executes this PHP page, it would output the following to the browser:


Of course, you'd also want to build in controls to alter the query, do calculations with the data, display it in a meaningful way etc. but this is the basic technique I've been using - use PHP to send a request to a third party server, process and parse the response on a local sever, and serve the results back to the browser.

Give It a Rest: REST apis part 1

So, first off I'm going to talk about one of the simplest ways to get a web service to send you data - it's called REST.

REST stands for representational state transfer and is an architecture, a way of laying out resources on a server. The idea is that the information you want to get at (the "resource") can be asked for by describing a "representation" of that data using HTTP calls. Services which do this are "RESTful".

For example, say you have a service which provides you with details of the weather in a specific location. One way to query this service might be:


Which is to say, what's it like in London, UK right now?
Another equally valid way to ask for this information might be:


Which refers to exactly the same place (resource), but in a different way. As long as the server accepts all of these query parameters, they're both fine to use.

The key here is that you don't have to send a HTTP header, you don't need any funny protocols, you just ask for a page with well defined query parameters saying what you need, and bing! that page contains the appropriate data.

The response itself can be in pretty much any format, indeed - you'd often use one query parameter for the response format, if you have a choice. Suppose it was XML, it might look like this:


Which I've just made up, but you get the idea. If you ask for the weather info for the city of "Gropiertegbun", you might instead get this:

<error>city not recognised</error>

With the possible exception that "recognised" would probably end up getting spelt the American way. That's because I made that city up, and even if I didn't, perhaps asking for a city without a country ID returns an error too. REST apis generally have fairly simple rules about which parameters you can use with which, and generally have defaults for when specific parameters are missing.

Part 2 will deal with how to use a server scripting language, in this case PHP, to make these calls and parse (read out) the results. I'll then probably follow on with details of how to build a user inteface to modify the queries, and how you can feed the results into other apis to display and use your data.

Tuesday, March 10

My First Ajax

As an analyst, I often see things which aren't "joined up", systems that don't talk to each other properly, tasks that people complete which are frustratingly manual (data entry sucks!) but the worst of all...

Things that people could do, but don't, because they're too tedious/complicated/etc..

With that in mind, I've been developing with an API published by a third party I work with. Don't get me wrong, they have a good system, but it tends to be a bit on the slooooowww side (they could do with some ajax upside their faces..) Not to mention the hastle of remembering your username and password, logging in, navigating menus... So I'm on a mission to create an easily usable interface to their API which we can use locally.

I'm relatively new to the techniques I'm using - but that was the main motivation in the first place! So, I've been learning all the HTML, XML, PHP, JavaScript needed to put together my own little ajax powered web app.

I'll be posting a few little stories about this as it develops, as well as hopefully providing some insight into what is needed for anyone that perhaps wants to try themselves!

Many companies (Google, Amazon, spring to mind) have open APIs which you can play with - so why not have a look?

Saturday, March 7

Kepler Mission is GO

In other news:
Kepler, a sophisticated space telescope, blasted off from Cape Canaveral, Florida, in the early hours of the morning, and separated from its carrier, a Delta II rocket, nearly 450 miles above the earth.
Kepler's job is to scrutinise the area of the part of the Milky Way near the Cygnus and Lyra constellations, looking for planets around the stars there. Specifically, it's hoped that it'll find a rocky Earth like planet - providing some solid evidence to back up speculations of exactly how common a solar system like ours is.. are we unique - or do similar systems, with similarly composed planets (with conditions suitable for life!) crop up all over the place?

All Fluxed Up

Flexy Frederick's been over, last night we recorded a few acoustic songs and this morning, I had the fortune of a tutorial of his OpenFlux value object model he's been working with, which provides easy integration with a client/server model like Cairngorm.

The value object (LinkVO) contains a few variables for holding necessary information about the views of the component, such as the user's name, location of his pic etc...

The link object inherits the properties of a List Item, with the get and set methods overriden to talk to the value object. In the same directory there's a Flux content variable for each view of the component, in this example it's a user name and a photo [degrafa handles the "brand" formatting for the photo, and both look at].

The controller sends the request to the client/server model - I'll have to read Part 2 to find out what happens next... Did I get that roughly right, Freddy? :)

Friday, March 6

Talk Talk

Tom Taylor makes things talk

This guy's responsible for the twitter account which tells you when Tower Bridge is raising and lowering, and has built a "feed printer" from an old receipt printer and an ethernet shield.


Thursday, March 5

Blinded by Greed and Religious Delusions

If there's a grand global warming conspiracy, this is it.

Watch some amusing but slightly terrifying videos

Also check out Ignorance Corner, and bask in the power of greed and stupidity.

I Wonder If He's For Sale?

Second Life vs Kingdom of Loathing

This isn't really a competition. SL is a nice fat download, which then proceeds to burn processor if you venture into a remotely complex environment. KoL is a PHP based browser game with hand drawn stick figure graphics. SL is boring as tits, because it's not exactly clear what you're supposed to be doing, and most places seem empty, unfinished and depressed. In KoL you have clearly defined quests, with ingenious solutions, and plenty of ironic monsters to beat on. SL has desperate marketing schemes, KoL has pop culture references, eating, drinking, gambling, stealing and sabre toothed limes.

I know where I'm off to tonight.

Wednesday, March 4

Eat, Live and Breathe in Real Time

I discovered this today.

Comet allows you to send data directly to your browser without having to ask for it.
You heard of AJAX? It's a combination of web technologies - which lets you change bits of web pages without having to reload a brand new page. It's been all the rage - though Google apparantly have declared the AJAX revolution complete.

So what's next? Comet's not dissimilar to AJAX - it's not really one thing, it's just various bits of technology used together in a fairly organised manner - the aim: reduce unneccessary processing and data transfer on the net. Simple!

The problem is, how do you know when there's new data available? The user can ask for it, but he'd rather have it appear automatically as soon as it becomes available. AJAX polling helps, because your machine (client side) will ask the website (server side) every now again whether anything's new. But if the answer is "no", it's basically a wasted trip.

Instead, a Comet framework allows the server to send the new data as soon as the event occurs, and have it AJAXed into the browser without you having to do anything, and with the minimim amount of effort.

So the web is going real time!

PS. This popped up on my tweetdeck. I've had a twitter revolution after intially discarding it, when I discovered the beauty of it's ability for memetic transfer, rather than something to do with "friends" (as intended). Ideas propogate, trends ebb and flow. I suspect meme growth in the twittersphere behaves much like fields in paramagnetic substances (incidently, the phenomena of clapping in crowds spreading and dying away is very similar too). So, if anything - it's the closest thing we've got at the moment to "the pulse".

Tuesday, March 3

The Spirograph of Everything

I've added this pic of an E8 Lie Group. Isn't is neat?

This is a mathematical symmetry - and the highest order (read: "most beautifully complex and simple at the same time") of it's type that can be constructed. I think it's really pretty, and what's more, it's a usable gauge group (read: "something that behaves nicely enough to use in hardcore physics") into which the Standard Model of Matter fits nicely. There's plenty of gaps left to fill - so do any of them really exist as symmetries of particles in our universe?

Bring the LHC, let's find out!

Garret Lisi discusses the implementations of this symmetry in his "theory of everything" on - check it out. The rotating visuals go a long way to showing you how it works.

ps. yeah, so the LHC needs a bit of tweaking before it can work properly. This was pretty much expected, if not hoped for. If only the journalists would pay attention.
On that note, no-one in physics calls the Higgs boson the "God Particle". Only sensationalist journalists do.
And thirdly, it was a chemist who started the whole "black hole" media frenzy. I use the following parallel:
Imagine you have a mole. You're a bit worried about it. You go to a gynocologist, he tells you it's dangerous melanoma - you go to an oncologist, he tells you "it's a spot, mate". Who are you going to believe? In other words, there is nothing wrong. The LHC won't create black holes which could somehow escape and swallow the world. It can't. Trust us.

Monday, March 2

Keep On Crunchin'

Layoffs.. sigh.

Gladly I'm not affected but still, it's generally causing commotion and I'm finding it hard to find the right position to take in these dark times...

Part of me just wants to shout "This is judgement day, this is what gross capitalisation does to a nation! Don't pretend you haven't seen the good times, now the chips are down - you can't just whine about it! Fight!

But then again, I'm speaking somewhat from the ivory tower, as usual. It seems the major burn is the fact that people run the risk of axing those whose departments they just don't understand - business is still basically an old boys club, and those of us whose roles fall outside of the classic dinosaur hierarchy unfortunately have the problem that the fat cat's literally don't realise what we do for them. Easy meat.

I'd like to think that if mass corporate culture managed to sort it's smeg out and actually let the people who knows what's going on run the show, we wouldn't have to deal with this kind of stuff. Everything would just function in a perfect natural equilibrium.

Although, maybe this is the equilibrium? Maybe we have to suffer now, in order for the next phase of humanity to flourish?