Friday, August 29, 2008

Friendfeed custom display

A while back i changed my homepage to be a custom view of my friendfeed activity so you could see what i was doing all day long. The only thing i don't like is that it puts my most recent items up which is great, but it means i have lots of twitter posts as i'm very active in there. You don't see my most recent images, videos and so on. I should have posted this ages ago, but i didn't, so apologies.

Here you go if you find it useful...

1. Put in the head element ...


function ParseFriend(feedid)
var prefeed = document.getElementById("prefriendfeed"+feedid); = 'none';

var feeditem = document.getElementById("feed"+feedid);
var divs = feeditem.getElementsByTagName("div");
for(var i=0;i<divs.length;i++)
if (divs[i].className == "header") divs[i].style.display='none';

if (divs[i].className == "friendfeed")
var subdivs = divs[i].getElementsByTagName("div");
for(var j=0;j<subdivs.length;j++)
if (subdivs[j].className == "feed")
subdivs[j] = '';


2. Place on your page and customize ...

<div id="friendfeed" style="float:left;width:600px;">
<a href=""><img src="images/friendfeed.gif" style="vertical-align:top;" border="0" /></a>
<a href="#feed101">location</a>
| <a href="#feed1">blog</a>
| <a href="#feed2">twitter</a>
| <a href="#feed6">favourites</a>
| <a href="#feed5">videos</a>
| <a href="#feed3">photos</a>
| <a href="#feed4">music</a>
| <a href="#feed7">books</a>
<br />
<div name="feed101" id="feed101" style="float:left;margin-left:20px;"><img src="images/plazes.jpg" border="0" alt="" /> </div><div style="margin-left:40px;"><object type="application/x-shockwave-flash" data="" width="316" height="146"><param name="movie" value="" /><param name="allowScriptAccess" value="sameDomain" /><param name="swLiveConnect" value="true" /><param name="wmode" value="transparent" /><param name="FlashVars" value="key=fcffc504b834fcd539f4310515a31d5e&amp;dark=7cd9f7&amp;light=ff9900&amp;text=000000&amp;link=ffffff" /><p><strong><a class="external" href="">Download Flash plugin</a></strong></p></object></div>
<div id="prefriendfeed2" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream tweets ...</div>
<div name="feed2" id="feed2" style="display:none;"><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed1" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream blogs ...</div>
<div name="feed1" id="feed1" style="display:none;"><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed6" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream favourites ...</div>
<div name="feed6" id="feed6" style="display:none;"><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed3" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream photos ...</div>
<div name="feed3" id="feed3" style="display:none;"><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed5" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream videos ...</div>
<div name="feed5" id="feed5" style="display:none;"><script type="text/javascript" src=""></script><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed4" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream music ...</div>
<div name="feed4" id="feed4" style="display:none;"><script type="text/javascript" src=""></script></div>
<div id="prefriendfeed7" style="float:left;width:600px;"><img src="images/loading.gif" style="vertical-align:middle;" /> loading livzstream books ...</div>
<div name="feed7" id="feed7" style="display:none;"><script type="text/javascript" src=""></script></div>

3. Put at the end of your web page the following ...


Saturday, August 23, 2008

Make your API's easy to play with

I'm looking at advertising API's and i've got a headache. Got a nice list from here, but ALL i want to do right now is test them out. I'm sitting here with my code calling some Amazon Web Services (excellent) and other simpler services but the Ad one is driving me nuts. Google's was way complex and involved signing up all over the place. Yahoo required me to be processed. Again Microsoft's looks fairly involved. (Update) Didn't realize that i need to use AdSense and not AdWords to actually get suggestions ! Never saw any pointers at the top of the AdWords. Anyway AdSense is a little better but it seems to return only HTML which kinds defeats the purpose of an API. I want to embed it my own way!

I want to pass some data and get some ads - maybe do something more in the future. More importantly i just want to test this just now. I don't want to commit to anything but things need to be simpler. I don't wanna spend hours registering, being verified and then coding against something far more complex than i need. I don't mind the complexity, but when i can't immediately see (and play with) what i need to do then, to me, it's complex.

Please - all - provide a sandbox for hacking. Make it open with an API key easy to get which allows X number of requests. Make the API simple - most could be RESTful gets for that. Make the reponse simple, but customizable.

I know from personal experience these things get complex quickly, but we need API's we can quickly run with.

Thursday, August 21, 2008

Needz twitter

As an experiment i've created an account on Twitter when you can add and request things ou need, such as positions to be filled, a job, directions and so on.

If you need something, send a message to @needz at

Tuesday, August 19, 2008

Reading from Freebase using C#

Update : Seems Freebase no longer requires the cookie authentication - comment out that line and it works fine. Cool.

Freebase is one of my favourite things EVER on the web.

I'm working on a project just now and need to read from FreeBase. Alas I couldn't find any C# examples (if you know of any please let me know). As FreeBase is in early stages it required Cookie authentication - they say they will open up in the future.

Anyway, here is the code that does the same thing as the Perl, PHP and JavaScript code on this Freebase page. Enjoy :)

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Security.Authentication;

namespace FreebaseSample
public class FreeFind
private static string server = "";
private static string queryurl = "/api/service/mqlread";
private static string path = "/api/account/login";
private static string username = "";
private static string password = "";
private static CookieContainer authCookies = null;

public void Ask(string band)
// This is our MQL query
// Find a band
// With the specified name
// We want to know about albums
// Return album names
// And release dates
// Order by release date
string query = "{\"type\": \"/music/artist\",\"name\": \"" + band + "\",\"album\": [{\"name\":null,\"sort\": \"release_date\", \"release_date\":null}]}";

string envelope = "{\"a0\":{\"query\":"+query+"}}";
string url = server + queryurl + "?queries=" + System.Web.HttpUtility.UrlDecode(envelope);

HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = authCookies;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());


/// <summary>
/// Authentication.
/// </summary>
public void Authenticate()
string authURI = server + path;

// Create the web request body:

string body = string.Format("username={0}&password={1}", username, password);
byte[] bytes = Encoding.UTF8.GetBytes( body );

// Create the web request:

HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create( authURI );
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = new CookieContainer();
request.ContentLength = bytes.Length;

// Create the web request content stream:
using ( Stream stream = request.GetRequestStream() )
stream.Write( bytes, 0, bytes.Length );

// Get the response & store the authentication cookies:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if ( response.Cookies.Count < 2 )
throw new AuthenticationException( "Login failed. Is the login / password correct?" );

authCookies = new CookieContainer();
foreach ( Cookie myCookie in response.Cookies )


You can call it as so ...

using System;

namespace FreebaseSample
class Program

static void Main(string[] args)
FreeFind f = new FreeFind();


You get something like the following JSON response ...

"status": "200 OK",
"a0": {
"code": "/api/status/ok",
"result": {
"album": [
"Another Day",
"11 O'Clock Tick Tock",
"A Day Without Me",
"U2 Popmart - Miss Sarajevo (disc 2)",
"Zoo TV Tour (disc 2: Live Transmission)",
"The Complete U2",
"Wide Awake in America"
"type": "/music/artist",
"name": "U2"
"code": "/api/status/ok"

Saturday, August 2, 2008

Large Hadron Collider Nightmare scenario

The pictures of the large hadron collider look amazing. Other than pulling us all into a black hole, surely scientists who wrote the software dread the following ....

c:\>run large hadron collider.exe

Error at line 4. The 'Higgs Boson' is not a recognized particle. Please try again.