Christian Heilmann

Author Archive

Video of my talk at the University of Ankara

Tuesday, June 24th, 2008

Kivanc Erten has shot a video of my talk at the Open Source Event in the University of Economics and Technology in Ankara, Turkey explaining what free open resources Yahoo has for developers:

[slideshare-presentation:http://www.slideshare.net/cheilmann/yahoo-is-open-to-developers]

Part 1: Yahoo is Open

Part 2: Yahoo is Open

Easy SlideShare (my hack entry for mashed08)

Sunday, June 22nd, 2008

I am just sitting at Mashed 08 and just released my hack for the event – an easier interface to SlideShare.

Easy SlideShare

SlideShare is a great place to publish your presentations on the web. Uploaded Powerpoints and PDFs get converted to Flash movies you can embed in your blogs and web sites.

SlideShare also automatically creates a transcript of the presentation in HTML format, which is quite cool, but hidden far down the page and hard to reach in a screen reader. Easy SlideShare retrieves this information and shows it in an easier accessible manner.

As with EasyFlickr and Easy YouTube all you need to do to show a SlideShare presentation in Easy SlideShare is to add the URL at the end of the Easy SlideShare URL:

http://www.slideshare.net/cheilmann/purple-hack-fodder
http://icant.co.uk/easy-slideshare/?slides=http://www.slideshare.net/cheilmann/purple-hack-fodder

You can try it out with my mashed08 presentation

Easy SlideShare is Open Source, licensed with BSD, and you can download it here:

Currency conversion API on a shoestring

Saturday, June 21st, 2008

Someone just came to our table at Mashed08 and asked if Yahoo! offers a currency conversion API. We don’t, but a few lines of PHP allows you to get the information from the Yahoo finance site:


function convert($from,$to){
$url= 'http://finance.yahoo.com/currency/convert?amt=1&from='.$from.'&to='.$to.'&submit=Convert';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$feed = curl_exec($ch);
curl_close($ch);
preg_match_all("/tabledata1">([^<]+)/",$feed,$cells);
return $cells[1][1];
}
echo convert('USD','GBP');

There’s a whole list of currency codes available on oanda.

A few more lines turns this into a JSON API:


header('Content-type:text/javascript');
$from = $_GET['from'];
$to = $_GET['to'];
$callback = $_GET['callback'];
if(preg_match("/[A-Z|a-z]{3}/",$to) && preg_match("/[A-Z|a-z]{3}/",$from)){
$to = strToUpper($to);
$from = strToUpper($from);
$url= 'http://finance.yahoo.com/currency/convert?' .
'amt=1&from='.$from.'&to='.$to.'&submit=Convert';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$feed = curl_exec($ch);
curl_close($ch);
preg_match_all("/tabledata1">([^<]+)/",$feed,$cells);
if(is_numeric($cells[1][1])){
$out = '{"from":"'.$from.'","to":"'.$to.'","factor":"'.$cells[1][1].'"}';
} else {
$out = '{error not convert currencies, are you sure about the names?"}';
}
} else {
$out = '{error Currency format, must be three letters"}';
}
if(isset($callback)){
if(preg_match("/[a-z|A-Z|_|-|$|0-9|.]/",$callback)){
$out = $callback.'('.$out.')';
} else {
$out = '{error callback method name"}';
}
}
echo $out;

You have several parameters:

  • from (mandatory): three letter currency code (upper or lower case)
  • to (mandatory): three letter currency code (upper or lower case)
  • callback (optional): the name of the callback method that should be wrapped around the resulting object

If something goes wrong, the API will return an object with an error property, otherwise you’ll get an object with three properties:

  • from: the original currency
  • to: the target currency
  • factor: the conversion factor

Say you store this as convert.php somewhere, then you could do the following:




This is a terrible dirty hack and if Yahoo finance ever changes their HTML (and they will), this will cease to work.

Big companies are like marching bands

Friday, June 20th, 2008

I just read another amazing novel by Douglas Coupland on my 5 hour flight to Ankara called “Eleanor Rigby”. This is a quote I really enjoyed:


Jeremy asked if I liked my job.
“I think big companies are like marching bands. You know the big secret about marching bands, don’t you?”
“No, what is it?”
“Even if half the band is playing random notes, it still sounds kind of like music. The concealment of failure is built right into them. It’s like the piano – as long as you play only the black keys, not the white ones, it’ll sound okay, but on the other hand it’ll never sound like real music either.

Now this sounds negative, but I also like the idea that big companies can have failure without totally vanishing. That’s where research departments and incubators come in.

Building Easy Flickr – Step by Step

Monday, June 16th, 2008

As several people asked how I did the easier Flickr interface, I wrote up some step-by-step instructions, analyzing the issues and then taking the API to work around them.

An easier interface to Flickr

Check out How to create an alternative Flickr interface – step by step.

This is one example where providing a good API can empower developers to remove barriers you might not be aware of for you. I hope to be able to show you more of those in the future.

The code examples are available and are licensed with BSD, so feel free to re-use them.