I thought finding some php code to parse a twitter feed would be fairly straightforward…
…although a search of Google returned code that ranged from elegant to incomprehensible, I still couldn’t find anything that quite fitted the bill. So with the help of php.net I wrote something from scratch that pretty much does what I want.

The code below uses the simplexml_load_file function to turn a twitter RSS feed into an object. From there it strips out some unwanted characters, adds a hyperlink (if one exists in the original post), strips down the date to DD MMM, adds some html and returns the three most recent posts.

There are plenty of notes in the code (probably too many for most people), but down the road I WILL forget what I was doing, so I need them:o)

You will obviously need to change the twitter RSS feed and probably change/strip out some of the html (namely the span tags). Please feel free to use the code, if you’re feeling generous maybe give me a mention:o)

<?php

$twitterRSS = simplexml_load_file ( ‘http://twitter.com/statuses/user_timeline/177618489.rss&#8217; ); //Noel’s twitter

$i = 0;

while ($i <= 4) {

$description = $twitterRSS->channel->item[$i]->description;

$pubDate = $twitterRSS->channel->item[$i]->pubDate;

$guid = $twitterRSS->channel->item[$i]->guid;

//remove username, colon, and single white space…

$colon = ‘:’;

$positionColon = strpos($description, $colon);

$description = substr_replace ($description, ” , 0 , ($positionColon +2) );

//find the position of ‘http://&#8217;

$http = ‘http://&#8217;;

$positionHttp = strpos  ( $description  , $http );

if ($positionHttp == !NULL) //i.e. there is a http:// link, then execute the code

{

//find the first white space after the ‘h’… (if there is one – links are often at the end!)

//we will use strpos again, but this time include the offset parameter to choose where to start our search…

$whiteSpaceAfterHttp = strpos  ( $description , ‘ ‘ , $positionHttp );

//the last character of the link is $whiteSpaceAfterHttp value minus 1

$linkLastChar = ($whiteSpaceAfterHttp – 1);

//now… if there was no white space after the link $linkLastChar will be -1 !

//if this is the case we can make $linkLastChar the string length!

//this will be the position of the last character… haha

if ($linkLastChar < 0) {

$linkLastChar = strlen ( $description );

}

//we now have the beginning and end positions of the http link

// $positionHttp and $linkLastChar

//let’s get the link length…

$linkLength = ($linkLastChar – $positionHttp);

//let’s grab the link that needs ‘fixing’…

$oldLink = substr ( $description , $positionHttp , $linkLength );

//let’s add html tags to the old link and call it $newLink

//$newLink = ‘<a href=”‘ . $oldLink . ‘”>’ . $oldLink . ‘</a>’;

$newLink = ‘<span><a href=”‘ . $oldLink . ‘”>’ . $oldLink . ‘</a></span>’;

//let’s swap the old link for the new link in the string…

$description = substr_replace  ( $description  , $newLink  , $positionHttp , $linkLength );

}

//ok, so the RSS date in a twitter tweet comes out something link this:

//Mon, 04 Oct 2010 11:37:43 +0000

//remove the first 5 characters…

$pubDate = substr_replace  ( $pubDate , ‘ ‘ , 0 , 5 );

//remove the remaining 21 characters from position 7 onwards…

$pubDate = substr_replace  ( $pubDate , ‘ ‘ , 7 , 21 );

//add the link to the date with html…

//$pubDate = ‘<a href=”‘ . $guid . ‘”>’ . $pubDate . ‘</a>’;

$pubDate = ‘<span><a href=”‘ . $guid . ‘”>’ . $pubDate . ‘</a></span>’;

echo ‘<p>’;

echo $description;

echo ‘</p>’;

echo ‘<h4>’;

echo $pubDate;

echo ‘</h4>’;

echo ‘<div class=”hr”>&nbsp;</div>’;

$i++;

}

?>

Advertisements

Before you lovingly craft a new icon for your iPhone, Android, or web app tool bar, take a look at glyphish.com  Joseph Wain has created over a 100 original png icons for you to download.

As much as I like to create my own, many of these are far better than I would have come up with. So unless you (or your client) have to have something unique you should really take a look. Here’s a sample…

png icons


Spring Term — 2008

>> Back to MSc Coursework Index

Brief: “Design a streaming media presentation using SMIL (Synchronized Multimedia Integration Language). The presentation should be between 10 and 15 minutes long. The streaming media must include the following assets: text, audio, video and flash animation. All these media files should be controlled and synchronized well. Your streaming media should be viewable remotely using RealPlayer or a web browser.”

“What is SMIL exactly?”

Good question… SMIL is an xml-compliant mark-up language that allows multimedia authors to create slide-show style presentations for the Internet – to be played in a browser or on supporting media players. SMIL makes it possible to define the position, timing and layering of different types of media.

I decided that the way forward was to take advantage of the native characteristics of the various media types and the rich SMIL language.  Rather than trying to “squeeze” the elements into a pre-conceived area, I have instead attempted to break up the screen space and take advantage of the timing, positioning and transitioning abilities of the SMIL language.

It would be fair to say that SMIL is not well supported when it comes to Internet browsers or media players – its only saving grace when I did this project was from its implementation on RealPlayer.

This is further complicated by the fact that different browsers and media players do not have universal support of all media types. A SMIL file can refer to any media type, but it will be the browser/media players support (or not) that will determine a) whether it is rendered and b) whether the SMIL file will even be launched.

As an example: a SMIL implementation in HTML for Internet Explorer could reference a video file in the format *.wmv  The file will play because IE supports it.  However, this file will not play in RealPlayer as RealPlayer does not support the *.wmv video format (at the time of this writing).  Another example is *.txt files; SMIL supports *.txt but RealPlayer does not. For a RealPlayer implementation you would have to use RealText (*.rt) files.

Video and disclaimer…

Ironically to upload the SMIL presentation to YouTube I had to convert it to a video format. The result is fairly poor quality… maybe it goes some way to make the point… SMIL is not unified video but synchronized media.

Hopefully you’ll take my word for it, when this is played in RealPlayer the text is sharp and the video and image transitions smooth. At least the video gives an idea of what’s possible as far as animation (yellow bars) and synchronization is concerned.

On the plus side SMIL gives authors the ability to manage and “design” for bandwidth usage – this is its real strength. By keeping individual assets separate and scheduling their delivery, higher quality at lower bit rates is possible.

For example a static image used in your SMIL presentation only has to be downloaded once (and not in a continuous video stream), text which can become unclear in low bandwidth or small screen video can be sent as a separate stream of text and rendered in the clients browser or media player, and will be as clear as text in a word processor. You can also schedule high resolution images and video, buffering them before they are needed.

As an example, here is a screen-shot from the presentation being played in RealPlayer – as you can see the text is sharp and the animation “pixel-perfect”.

If bandwidth is simply not an issue SMIL can be used to swap out different assets depending on your user. It would be fairly straightforward, for instance, to swap your default text for text in a different language. SMILs support of player controls also makes it possible for users to interact with a presentation.

SMIL is a powerful authoring language and will seem familiar to anyone that has used xml or HTML.

However, its proprietary implementation across browsers and media players make authoring for a wide audience problematic. This is not the fault of the SMIL language or W3C which made its first recommendation in 1998. If SMIL were to gain the popularity of say xml then everyone would benefit.


If you weren’t looking specifically to replace your iPod shuffle battery, you might ask: “why would you want to?” Good question…

According to my wife, dropping the 2nd Gen iPod Shuffle was something of an own goal for Apple, she maintains that it is simply the best iPod to take to the gym. I would have to agree (not because I spend much time in the gym) but because it is small, light, has an intuitive button layout and of course has a very strong clip which is as big as the player itself.

I persuaded her to try the 3rd Generation Shuffle, she did, we took it back to the Apple store exactly one week later. They issued a refund asking what was the problem, she explained the buttons were too small and inconveniently located on the headphone cable – the assistant drew our attention to some kind of adaptor that would turn the 3rd gen player into something like the previous model. (What?!) We took the refund.

Additionally, the clip is not sprung loaded like the previous model – more of a slide on/off – like a pen lid, and the headphone jack is smaller than the regular size, which means you are tied to the headphones that came with it or you have to get a (comparatively large) jack adaptor (Apple, come on!).

Enough complaining… I decided to change the battery on the old one, in an attempt to bring it back to life – it was fully functional in the dock but had no power when unplugged.

You will need…
o Your second gen iPod Shuffle
o A new battery (assuming that’s the problem)
o A precision screwdriver
o A soldering iron
o A detailed repair manual
o Patience

I picked up a new replacement battery on eBay for £4.99 (Nice!). It came with a pointed tool and what appeared to be the correct size screwdriver. However, after one turn of this I thought it was going to strip the screw head so I pulled out my own set. The Shuffle has four screws, all the same size – Phillips #00 I believe.

You can get an excellent “teardown” guide here: http://www.ifixit.com/Teardown/iPod-Shuffle-2nd-Generation-Teardown/437/1

Here is the Shuffle mid-repair. You can see the old battery above, with the new battery soldered in, waiting to be flipped back into place.

A few tips…
The teardown guide on www.ifixit.com says to heat the plastic caps with a hairdryer before removing them. They’re not joking, you have to get those plastic ends nice and hot otherwise the glue (!) that holds them on won’t soften and you will struggle to prize them off.

The battery has two short wires that are soldered directly to the logic board. The solder points are coated with a blob of hard, transparent plastic. I thought it unlikely that I could get this off without damaging the printed circuit board. However, those same two wires are soldered to terminals on the battery itself, you will find it easier to remove/replace the battery at this point.

Getting the logic board back inside with the new battery was also quite a squeeze.

On reflection, it really is quite amazing how much Apple have packed into this little player. Equally amazing is that it can be taken apart and sustain a repair. Oh, I almost forgot you will need good eyesight; the stuff in there is super small!


Spring Term — 2008

>> Back to MSc Coursework Index

Brief: “Develop an application to showcase modules that comprise the Internet Applications Development MSc. The application must integrate web services and allow prospective or current students to view information via either an HTTP browser or WAP browser. Create two platforms (Web and WAP) that access resources in a shared database via a set of shared web services.”

“Additionally you are required to write a report detailing the development of the application – this report is to be presented as a web page.”

This module challenged me in several areas, particularly the area of web services and to a lesser degree WML.

Although moving data from a database to a web page and back again is familiar territory, doing it via a web service was something of an abstract concept. In addition to this, using PHP and WML in conjunction was also something of a challenge even though I have often used PHP to output HTML.

Success came for me when I realized that in the real world the web services files would be on different servers! In class the files were on the same web-server, even in the same directory, which kept me wondering for a long time what exactly was the point of having one script sending data to another script in the same place.

The value of sending and receiving data across networks independent of platforms and browsers is now very clear. The concept of programming one language to output valid code in another language has also finally landed with me, particularly while creating the WAP application.

Below are screen shots of the applications home page and WAP emulator.

The mobile sites home page…

Mobile and Evolving Services Home Page

 

The same site viewed in the WAP emulator…


This should have been my entry to the 2010 Doritos “King of Ads” competition. Sadly with just an hour and a half to the deadline and just the music track to add my Mac Mini corrupted the iMovie file:O( This was after about 3 weeks of my spare time and the last 12 hours editing.

Being fairly new to the Apple Mac, I thought this kind of catastrophe was near impossible, apparently not. A desperate Google of “corrupt iMovie file” gave plenty of results with very few fixes. Alas my Ad dream came to an end.

Anyway… after all that work I thought it a shame not to finish off the project. Enjoy:o) Please feel free to leave your comments re: the ad or your own iMovie disasters/fixes/workarounds.


YouTube today sent me another invitation to apply for revenue sharing for one of my videos – Iced Espresso. Interestingly this just passed the 20k views mark compared with my first invitation, which came for a 100k views video. This is not a new video either; it was posted way back in July 2007 (the same month as the 100k one).

The only thing I’m doing differently at the moment is trying to keep up with my commitment of posting one new video a month, apart from that things are pretty much the same. My “March” video: Bee Keeping UK is climbing quite sharply with 167 views in just under two months, “racing” past six of my other offerings:O)