Christian Heilmann

Author Archive

Inviting UK companies to build an app for the Yahoo homepage. Come around next Thursday

Tuesday, November 17th, 2009

There is no rest for the wicked. Coming back from Japan and preparing for Friday’s Full Frontal conference I just spent an hour in one of the final meetings for the Yahoo Application Platform event next Thursday. As you might know, you can build applications that run on the Yahoo platform and can be installed by any of our users. We now run a competition for UK companies to build a cool branded app with the main prize being a guaranteed slot in the Yahoo UK homepage.

Sounds good? Come around next Thursday and see what it is all about. Here’s the official invite:

Technical Workshop for the Yahoo! Application Platform
The Yahoo! Application Platform allows developers to reach Yahoo!’s millions of users and improve the Yahoo! user experience by building and deploying sophisticated new applications for Yahoo! pages.
We’d like to invite you to a technical workshop about YAP led by Yahoo! developer evangelist Christian Heilmann.
It will give an overview of the technology, including some examples of applications that have already been developed, followed by a deep dive into the YAP platform. Please bring your laptop (and a 3g dongle if you have one just in case the venue wifi lets us down).
After some refreshments, there will also be an opportunity to get hands-on with YAP, as Chris steps you through creating a sample application.
The event will be held at Century (61-63 Shaftesbury Avenue, London, W1D 6LQ) on 26th November with registration starting at 6:30pm.
We’ll also be announcing a competition for the best apps, with the opportunity for a placement on the Yahoo! homepage (as well as a prize you can take home!) – more details on the night! We’re looking to you to help us build the next big thing on Yahoo!

If you want to be part of this and your company is located in the UK, send an email to yap-london@yahoo-inc.com and we’ll be in touch with you if there is still space.

Using YQL to read HTML from a document that requires POST data

Monday, November 16th, 2009

YQL is a very cool tool to extract data from HTML documents on the web. Let’s face facts: HTML is a terrible data format as far too many documents out there are either broken, have a wrong encoding or simply are not structured the way they should be. Therefore it can be quite a mess to try to read a HTML document and then find what you were looking for using regular expressions or tools that expect XML compatible HTML documents. Python fans will know about beautiful soup for example that does quite a good job working around most of these issues.

Using YQL you can however use a simple web service to extract data from HTML documents. As an added bonus, the YQL engine will remove falsely encoded characters and run the data retrieved through HTML Tidy to get valid HTML back. For example to get the body content of CNN.com all you’d need to do is a:

select * from HTML where url="http://cnn.com"

The really cool thing about YQL is that it allows you to XPATH to filter down the data you want to extract. For example to get all the links from cnn.com you can use:

select * from html where xpath="//a" and url="http://cnn.com"

If you only want to have the text content of the links you can do the following:

select content from html where xpath="//a" and url="http://cnn.com"

You could use this for example to translate links using the Google translation API:

select * from google.translate where q in (
  select content from html where url="http://cnn.com" and xpath="//a"
) and target="fr"

Now, the other day my esteemed colleague Dirk Ginader came up with a bit of a brain teaser for me. His question was what to do when the HTML document you try to get needs POST data sent to it for it to render properly? You can append GET parameters to the URL, but not POST so the normal HTML document is not enough.

The good news is that YQL allows you to extend it in many ways, one of them is using an execute block in an open table to convert data with JavaScript on the server. The JavaScript has full e4x support and allows you to do any HTTP request. So the first step to solve Dirk’s dilemma was to write a demo page (the form was added to test it out):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <title>Test for HTML POST table</title>
 
<body>
  <p>Below this should be a "yay!" when 
    the right POST data was submitted.</p>
<?php if(isset($_POST['foo']) && isset($_POST['bar'])){
  echo "<p>yay!</p>";
}?>
<form action="index.php" method="post" accept-charset="utf-8">
  <input type="text" name="foo" value="is">
  <input type="text" name="bar" value="set">
  <input type="submit" value="Continue &rarr;">
</form>
  </body>
</html>

The next step was to write an open table for YQL that does the necessary request and transformations.

<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  <meta>
  <author>Christian Heilmann</author>
  <description>HTML pages that need post data</description>
  <sampleQuery><![CDATA[
select * from {table} where
url='http://isithackday.com/hacks/htmlpost/index.php' 
and postdata="foo=foo&bar=bar" and xpath="//p"]]></sampleQuery>
  <documentationURL></documentationURL>
  </meta>
  <bindings>
    <select itemPath="" produces="XML">
    <urls>
      <url>{url}</url>
    </urls>
    <inputs>
      <key id="url" type="xs:string" required="true" paramType="variable"/>
      <key id="postdata" type="xs:string" required="true" paramType="variable"/>
      <key id="xpath" type="xs:string" required="true" paramType="variable"/>
    </inputs>
    <execute>
    <![CDATA[
      var myRequest = y.rest(url);  
      var data = myRequest.accept('text/html').
                 contentType("application/x-www-form-urlencoded").
                 post(postdata).response;
      var xdata = y.xpath(data,xpath);
      response.object = <postresult>{xdata}</postresult>;
    ]]>
    </execute>
  </select> 
  </bindings>
</table>

Using this, you can now send POST data to any HTML document (unless its robots.txt blocks the YQL server or it needs authentication) and get the HTML content back. To make it work, you define the table using the “use” command:

use "http://isithackday.com/hacks/htmlpost/htmlpost.xml" as htmlpost;
select * from htmlpost where
url='http://isithackday.com/hacks/htmlpost/index.php'
and postdata="foo=foo&bar=bar" and xpath="//p"

You can try this example in the console.

I’ve also added the table to the open YQL tables repository on github so it should show up sooner or later in the console.

Here’s a quick explanation what is going on:

<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  <meta>
  <author>Christian Heilmann</author>
  <description>HTML pages that need post data</description>
  <sampleQuery><![CDATA[
select * from {table} where
url='http://isithackday.com/hacks/htmlpost/index.php' 
and postdata="foo=foo&bar=bar" and xpath="//p"]]></sampleQuery>
  <documentationURL></documentationURL>
  </meta>

You define the schema and add meta data like the author, a description and a sample query. The latter is really important as that will show up in the YQL console when people click the table. You should normally also provide a documentation URL, but this post wasn’t written when I wrote the table so I kept it empty.

  <bindings>
    <select itemPath="" produces="XML">
    <urls>
      <url>{url}</url>
    </urls>

The bindings of the table describe the real API data endpoints the table points to. You have select, insert, update and delete – much like any other database. You provide an itemPath to cut down on the data returned and tell YQL if the data returned is XML or JSON.

    <inputs>
      <key id="url" type="xs:string" required="true" paramType="variable"/>
      <key id="postdata" type="xs:string" required="true" paramType="variable"/>
      <key id="xpath" type="xs:string" required="true" paramType="variable"/>
    </inputs>

The inputs section defines what variables are expected, if they are required and what their IDs are. These IDs will be available for you as variables in the embedded JavaScript block and are normally defined by the API your table points to.

    <execute>
    <![CDATA[
      var myRequest = y.rest(url);  
      var data = myRequest.accept('text/html').
                 contentType("application/x-www-form-urlencoded").
                 post(postdata).response;
      var xdata = y.xpath(data,xpath);
      response.object = <postresult>{xdata}</postresult>;
    ]]>
    </execute>

Here comes the JavaScript magic inside the execute block. The y.rest(url) command sends a REST query to the URL. in the easiest form this would just mean to get the data back but in our case we need to define a few more things. We expect html back so we set the request accept header to text/html. This also ensures that the result is run through HTML Tidy before it is returned. The content type has to be like a form submission and we need to send the string postdata as a post request. The response then contains whatever our request brings back.

As we want to have the handy functionality of the original HTML table, we also need to do an xpath transformation which is done with the method of the same name.

Any JavaScript in the execute block needs to define a response.object which will become the result of the YQL query. As you can see, the E4X support of YQL allows you to simply write XML blocks without any DOM pains and you can embed any JavaScript variables inside curly braces.

  </select> 
  </bindings>
</table>

And we’re done. Using YQL execute you can move a lot of JavaScript that does complex transformations to the Yahoo server farm without slowing down your end user’s computers. And you have a secure environment to boot as there are no DOM vulnerabilities.

Chris’ travel tips – Tokyo, Japan

Saturday, November 14th, 2009

Some time ago I asked people on twitter if I should start writing about my travel experiences here in addition to the technical info I am giving. As my job right now consists mostly of traveling it would be fun to give some very personal insights about what you can do where. So here goes.

I went to Tokyo on a quick trip to meet with Yahoo Japan office and be a booth babe for us at the Web Directions East conference. I also ended up giving a presentation at a Pecha Kucha night.

All in all my experience is a bit tainted as I was sick and couldn’t do much, but here are some things that might be of interest for you if you ever go here.

high tech toilet flushSuper Lemon SodaTokyo by  you.Tokyo by  you.P1090790 by  you.P1090783 by  you.P1090770 by  you.P1090752 by  you.Tokyo by  you.

  • There are no flying cars – sorry, but my Bladerunner inspired impression of Tokyo is off. No flying cars, no robot dogs. The area we stayed in (Asaka, the Ana Intercontinental Hotel in between the US and the Russian embassy) actually reminded me a lot of Hong Kong.
  • You are off the grid in terms of mobiles – neither my personal T-Mobile HTC did a beep nor the company Vodafone 3G Blackberry. American colleagues have working iPhones though but I shudder to think how much the roaming costs.
  • Japanese mobiles are totally different – for starters, a lot of people watch TV on their phones.
  • There is no way to pay with credit card or cash machines – you can get money in the hotel though and it is totally normal to carry a month’s UK rent in cash Yen with you all the time – nothing gets stolen here.
  • Connectivity is good – In the hotel you have to pay for internets (but that is like in America – to my mind it should always be free) but cafes have free wireless. Wireless on the other hand seems to be not that common in offices and hotels.
  • Public transport is ace – we arrived in Narita airport and there is a good train connection to the city. The undergrounds is pretty easy to navigate and not too expensive. Still, Hong Kong beats it :) Taxis are ubiquitous but pricy – they start at 710 Yen and then go up quickly. Taxi doors in the back are opened by the driver, so wait for it. Marvel at the awesome GPS they have – like an animated Google street view.
  • Everything is ridiculously expensive – deal with it. It is like coming to London for the first time, just more painful.
  • There are coffee vending machines everywhere – hot and cold canned coffee and soft drinks are available on almost every street corner.
  • You can get along with English, but some Japanese sentences will help you a lot – taxi drivers for starters will not speak any English, bring a Japanese print out of the map you want to go.
  • The food rocks – you can eat anything and your body will not hate you for it.
  • Opening hours are odd – whilst you would expect the hotel to be the safe haven for the end of the evening you are sadly mistaken. Ours had no bar and after 9 the small shop and bakery inside it was already closed. You come back to the hotel to sleep, not to party (or if you got lucky, both).
  • Don’t blow your nose in public – which was a bitch with me having a bad cold. You do see a lot of people with face masks. This is not as we expect to stop the bearer from getting germs but is actually something people do when they have a cold to prevent others from getting infected. OK, whoever knows a bit about the efficiency of these masks can dispute the whole idea, but it shows just how much Japanese people care about not bothering others with their respiratory problems.
  • People are terribly helpful – even if they don’t understand you they consider it a flaw on their part and won’t ask for more details. This can be very confusing and I myself feel very uncomfortable with this.
  • The streets and public places are safe – you see a lot of cops hanging around and I for example saw people falling asleep in cafes with their money and their mobiles on the table. In the UK they’d have woken up naked as people would’ve nicked the lot.
  • Chopstick skills are needed – you’ll hardly find forks and knives outside of hotels. Eating sushi with your hands is expected though. You will get a hot towel before every meal.
  • Toilets are high tech – you have heated seats (very much loved by every woman I talked to about this) and spraying facilities in almost every toilet. With spraying facilities I mean bidet-style fountains that wash your bum. They can be adjusted both in angle and strength and don’t stop automatically – you need to press the stop button. I was confused by this the first time and waited for quite a while for the flood to stop which it didn’t. Not all are labeled in English, so some experimentation is necessary. Some toilets even have fake flushing noise generators to cover any flatulence. Again, this is a hint what not to do in public.
  • Finding an English speaking doctor can be hard – I just came back from a trek to 3 hospitals as the international SOS centre gave me the address of a nearby hospital but there was no English speaking doctor present. As professionals, they won’t touch you without being able to give a proper examination (you know half of the job is asking the patient what the issue is). In the end I found a service that provides translation on the phone for you. Any hospital knows that number so ask them to talk to the doc and you over the phone to work out. An examination plus medication was 4800 Yen, so not too bad.
  • There are a lot of all-night shops – offering drinks, pretty decent prepacked food, magazines, toiletries, magazines and even medication. Seven Elevens are the most common ones.
  • You do stand out – no matter what you do. Whilst people don’t stare (as I found to be a very common thing on my travels in India) you can try as you might but you will always be a Gaijin which used to be a rude word about foreigners but has become quite normal by now.
  • Hotels are very comfortable and high quality – like anywhere in Asia (at least I have been) US and especially UK hotels could learn from the stuff you get here in your rooms. Great beds, good TV set, mini bar, dry cleaning, iron, towels, pajamas, good shampoo+conditioner+body wash – all of these are normal.
  • Bring business cards – I collected them by the bundle here and managed not to bring mine which was quite a boo boo.
  • Public transport and lifts can be very packed – but don’t worry, even if you feel that you might crush people around you it will not happen.
  • People are beautiful – Japanese people have a very high standard of clothing and personal grooming. It is very easy to look scruffy here. Having said that, club-gear and young folk might dress in things that confuse you but just you wait – sooner or later all of that will come to the west, too. Then again the T-Shirts with random English or German sentences you see on engrish.com can be found, too.

That’s it for my first impressions. Check my flickr photos for some impressions and hopefully this is of use for you. Also feel free to comment with things I have done wrong if you are a local :).

Love what you do and they will listen – my Pecha Kucha talk for Webdirections East in Tokyo

Wednesday, November 11th, 2009

In a few hours Web Directions East in Tokyo will kick off with a Pecha Kucha presentation night. This means that every speaker gets to show 20 slides in 20 seconds each (I first thought the whole presentation was 20 seconds) and it is all good fun and speedy. Here are my slides that I will show as I am not speaking at the conference – I will be just a booth babe. Eye candy, so to say.

Notes

  1. I am Chris and my job is to make developers happy.
  2. I travel the world talking to people about simple solutions to big problems.
  3. And I love my job.
  4. To me, the web is not about sites and code.
  5. It is about information – data.
  6. The web is full of great information and tools that help us deal with information.
  7. All we need is a simple way to reach that information.
  8. And remix it.
  9. Once we have the data we can build great interfaces that help everyone to consume that data.
  10. All this needs passion.
  11. And collaboration.
  12. When we all – world-wide – work together towards the same goals, our job is easy.
  13. This means re-using what other people have done.
  14. This is not cheating – on the contrary, it is a cleverer way of dealing with a problem that we all have.
  15. Using systems that have proven to work means they can be constantly upgraded and secured.
  16. Working together on systems that by make it easier and more secure to use our products protects our users.
  17. So before you build something, look around what was already done and can be re-used.
  18. If you build something, give it out for free.
  19. You will reach more people like you and get feedback on improvements that you had no idea about.
  20. Together we can build the future, each on our own can create a nice present.

A Speakerrate comments badge or another reason to love Twitter

Tuesday, November 10th, 2009

Another reason to love Twitter: You ask for APIs and you get them. As requested in my Tweet, speaker rate acted very quickly and build an API
for latest comments – and here is my thank you. Using a bit of YQL magic and some JavaScript I put together a badge to show off the latest speakerrate comments on your page:

Speakerrate Badge Test by  you.

Check out the demo page of the badge and get the source and read the docs on GitHub.

Usage:

Simply add a DIV with a link to your speaker page on speakerrate:

Then add the script and call the init() method:


You can also provide a few options to the init() method to change the look and features of the badge:


If you need different styles, just use styled:false or override the ones applied.