Olivier Mengué – Code & rando

Aller au contenu | Aller au menu | Aller à la recherche

vendredi 12 août 2011

GitHub feature request: Fast-forward my fork

Note: I'm posting this on my blog because since May 2011 GitHub is gone in submarine mode: the Google group is closed, support requests are not public anymore and users can't keep track of their past support requests. And I got no response to the last feature request I submitted.

When my repo is a fork, I would like to be able to fast-forward all the branches that exist in my repo to the latest commit on that branch in the parent repo.
The user inteface would be a single button at the left of "Pull request".
Of course, the process should fail for branches where fast-forward (as defined by git merge) is not possible. For example if I committed directly in a branch of the parent repo (instead of branching before committing) of if the parent has done dirty things with his repo. This is a merge conflict.
The process should also warn me about branches that have been added/removed in the parent repo compared to mine and give me the option to do the same (a list of branches with checkboxes to select the ones to pull/keep/delete). The default action must be conservative (not remove the local branches if they have not been merged into another branch of the parent repo ; not add branch from the remote repo which are locally missing but have been merged into another branch of the parent repo).

Github should also warn me when I'm submitting a pull request but the local branch from which I branched for my patch is not fast-forwarded. This probably means either I missed recent commits of the parent (so my patch may not be relevant anymore) or that I did the fast-forward (on a working repo not on Github) but did not push it to GitHub.

samedi 27 septembre 2008

Playing with timezones and building my own XSLT test framework

I'm currently playing with XSLT to improve my XMLTV grabbing solution. Much fun playing with a functionnal language available in most web browsers.

I had the need to handle timezone with daylight savings to display date/times in my timezone, Europe/Paris (same as most of western Europe), which has currently the following definition (I'm not interested in history for this project):

  • Winter is UTC + 01:00
  • Summer is UTC + 02:00
  • Transition from winter to summer occurs on the last sunday of March at 01:00 UTC
  • Transition from summer to winter occurs on the last sunday of October at 01:00 UTC

So I wrote the following template date-time-Paris which is very specialized as it handles only one specific timezone, but it is very fast. I'm using only two extensions from EXSLT: date:day-in-week() and date:add().

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tap="test:tap"
  xmlns:date="http://exslt.org/dates-and-times"
  extension-element-prefixes="date"
  >

  <!-- Transformation de l'heure UTC en heure de Paris -->
  <!-- Copyright (c) 2008 Olivier Mengué -->
  <xsl:template name="date-time-Paris">
    <!--
      Daylight savings transitions:
      - last sunday of March at 1:00 UTC
      - last sunday of October at 1:00 UTC
      Time offsets:
      - winter: +01:00
      - summer: +02:00
    -->
    <xsl:param name="date-time-Z"/><!-- UTC -->
    <xsl:variable name="len" select="string-length($date-time-Z)"/>
    <xsl:variable name="seps" select="translate($date-time-Z, '0123456789', '')"/>
    <xsl:if test="$len &lt; 11 or substring($date-time-Z, $len, 1) != 'Z' or ($seps != '--T::Z' and $seps != '--T::.Z' and $seps != '--Z' and $seps != '--TZ' and $seps != '--T:Z')">
      <xsl:message terminate="yes">date-time-Paris: date '<xsl:value-of select="$date-time-Z"/>' invalide.</xsl:message>
    </xsl:if>
    <xsl:variable name="month" select="number(substring($date-time-Z, 6, 2))"/>
    <xsl:variable name="offset">
      <xsl:choose>
        <xsl:when test="$month &lt; 3 or $month &gt; 10">1</xsl:when>
        <xsl:when test="$month &gt; 3 and $month &lt; 10">2</xsl:when>
        <xsl:otherwise>
          <xsl:variable name="transition-day" select="32 - date:day-in-week(concat(substring($date-time-Z, 1, 7), '-31Z'))"/>
          <xsl:variable name="less" select="translate(substring($date-time-Z, 8), '-T:Z', '') &lt; $transition-day*1000000+10000"/>
          <xsl:value-of select="1+number(($less and $month = 10) or (not($less) and $month = 3))"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="concat(translate(date:add($date-time-Z, concat('PT', $offset, 'H')), 'Z', ''), '+0', $offset, ':00')"/>
  </xsl:template>

The implementation is really short, however it is quite complex as XSLT 1.0 requires to uses many tricks to workaround languages limitations (no native date type, no string order, no xor operator). Here are some tips to follow the code:

  • (a xor b) is equivalent to ((a and not(b) ) and (not(a) and b)).
  • number(true()) is 1, number(false()) is 0.
  • March and October have the same number of days: 31.
  • $transition-day*10000000+10000 for october 2008 (26010000) is an number representation of 2008-10-26T01:00:00Z.
  • the second argument to date:add() is a ISO 8601 duration. Ex: PT2H (2 hours).

In fact I present here the fourth version of the code, the first one was much longer (5x) as I was using intermediate templates for computations (last-sunday-of-month, previous-sunday). Of course the key to debug, and then optimise and refactor the implementation was to start with a good test suite. The test suite is of course written in XML and embedded in the stylesheet so it can evolve with the code.



  <tap:suite name="date-time-Paris" xmlns:t="test:date-time-Paris">
    <t:t dt="2008-09-24T21:37:52Z"     r="2008-09-24T23:37:52+02:00"/>
    <t:t dt="2008-09-24T23:37:52Z"     r="2008-09-25T01:37:52+02:00"/>
    <t:t dt="2008-09-24T23:37:52.325Z" r="2008-09-25T01:37:52.325+02:00"/>
    <t:t dt="2008-10-01T00:00:00Z"     r="2008-10-01T02:00:00+02:00"/>
    <t:t dt="2008-10-26T00:59:59Z"     r="2008-10-26T02:59:59+02:00"/>
    <t:t dt="2008-10-26T01:00:00Z"     r="2008-10-26T02:00:00+01:00"/>
    <t:t dt="2008-10-31T12:00:00Z"     r="2008-10-31T13:00:00+01:00"/>
    <t:t dt="2008-11-24T21:37:52Z"     r="2008-11-24T22:37:52+01:00"/>
    <t:t dt="2008-12-31T23:30:00Z"     r="2009-01-01T00:30:00+01:00"/>
    <t:t dt="2009-01-01T00:00:00Z"     r="2009-01-01T01:00:00+01:00"/>
    <t:t dt="2009-03-01T12:00:00Z"     r="2009-03-01T13:00:00+01:00"/>
    <t:t dt="2009-03-29T00:59:59Z"     r="2009-03-29T01:59:59+01:00"/>
    <t:t dt="2009-03-29T01:00:00Z"     r="2009-03-29T03:00:00+02:00"/>
    <t:t dt="2009-03-30T12:00:00Z"     r="2009-03-30T14:00:00+02:00"/>
    <t:t dt="2009-07-01T00:00:00Z"     r="2009-07-01T02:00:00+02:00"/>
  </tap:suite>

A more complete testsuite can be generated from a local dump of the zoneinfo database (directly works on Ubuntu Hardy, however the zdump tool is missing on RHEL/CentOS):

zdump -v Europe/Paris | perl -ne 'm/ (Mar|Oct) (\d{2}) (\d{2}:\d{2}:\d{2}) (20[0-5]\d) UTC = ... (?:Oct|Mar) (\d{2}) (\d{2}:\d{2}:\d{2}) / && do { my $mm = sprintf "%02d", 3+7*($1 eq 'Oct'); print "    <t:t dt=\"$4-$mm-$2T$3\" r=\"$4-$mm-$5T$6\"/>\n"; }'

Now, we need is a way to run the test suite. In XSLT terms, we say: "to apply a template to the test data". This template will just apply a date-time-Paris call to each of the tests.

  <xsl:template match="t:t" xmlns:t="test:date-time-Paris">
    <xsl:call-template name="tap:is">
      <xsl:with-param name="got">
        <xsl:call-template name="date-time-Paris">
          <xsl:with-param name="date-time-Z" select="@dt"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expected" select="@r"/>
      <xsl:with-param name="name" select="@dt"/>
    </xsl:call-template>
  </xsl:template>

</xsl:stylesheet>

We now have a complete stylesheet that can be used as a library in other stylesheet. But we have not yet run the tests. Also you probably wonder what are this XML namespace test:tap and the template called tap:is.

test:tap is just a small XSLT test framework that I wrote and the report test results following the Test Anything Protocol that is well known by Perl programmers. tap:is is part of the test:tap API and just check for equality and reports in the TAP format.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tap="test:tap"
  >

  <!-- Run all the tests in the test suite -->
  <xsl:template match="tap:suite">
    <xsl:message>1..<xsl:value-of select="count(node()[name()!=''])"/></xsl:message>
    <xsl:message># Suite: <xsl:value-of select="@name"/></xsl:message>
    <!-- TODO fix this expression -->
    <xsl:apply-templates select="node()[name()!='']"/>
  </xsl:template>

  <!-- Test Anything Protocol style reporting of tests -->
  <xsl:template name="tap:is">
    <xsl:param name="got"/>
    <xsl:param name="expected"/>
    <xsl:param name="name"/>
    <xsl:choose>
      <xsl:when test="$got = $expected">
        <xsl:message>ok <xsl:value-of select="position()"/> - <xsl:value-of select="concat($name, ' -&gt; ', $got)"/></xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>not ok <xsl:value-of select="position()"/> - <xsl:value-of select="$name"/></xsl:message>
        <xsl:message>#          got: <xsl:value-of select="$got"/></xsl:message>
        <xsl:message>#     expected: <xsl:value-of select="$expected"/></xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

We now have two libraries. Let's add a bit more XSLT to glue them together. The main stylesheet applies tap:suite templates to all tap:suite from all imported stylesheets.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  >

  <!-- Test framework -->
  <xsl:import href="tap.xslt"/>

  <!-- All stylesheets to test -->
  <xsl:import href="date-time-Paris.xslt"/>

  <!-- Launch the tests embedded in libraires, whatever the input is -->
  <xsl:template match="/">
    <xsl:for-each select="document('')/xsl:transform/xsl:import/@href">
      <xsl:apply-templates select="document(.)//tap:suite" xmlns:tap="test:tap"/>
    </xsl:for-each>
  </xsl:template>

</xsl:transform>

We now have everything to run the test suite:

$ echo '<x/>' | xsltproc tap-run.xslt -
1..15
# Suite: date-time-Paris
ok 1 - 2008-09-24T21:37:52Z -> 2008-09-24T23:37:52+02:00
ok 2 - 2008-09-24T23:37:52Z -> 2008-09-25T01:37:52+02:00
not ok 3 - 2008-09-24T23:37:52.325Z
#          got: 2008-09-25T01:37:52.3249999999998+02:00
#     expected: 2008-09-25T01:37:52.325+02:00
ok 4 - 2008-10-01T00:00:00Z -> 2008-10-01T02:00:00+02:00
ok 5 - 2008-10-26T00:59:59Z -> 2008-10-26T02:59:59+02:00
ok 6 - 2008-10-26T01:00:00Z -> 2008-10-26T02:00:00+01:00
ok 7 - 2008-10-31T12:00:00Z -> 2008-10-31T13:00:00+01:00
ok 8 - 2008-11-24T21:37:52Z -> 2008-11-24T22:37:52+01:00
ok 9 - 2008-12-31T23:30:00Z -> 2009-01-01T00:30:00+01:00
ok 10 - 2009-01-01T00:00:00Z -> 2009-01-01T01:00:00+01:00
ok 11 - 2009-03-01T12:00:00Z -> 2009-03-01T13:00:00+01:00
ok 12 - 2009-03-29T00:59:59Z -> 2009-03-29T01:59:59+01:00
ok 13 - 2009-03-29T01:00:00Z -> 2009-03-29T03:00:00+02:00
ok 14 - 2009-03-30T12:00:00Z -> 2009-03-30T14:00:00+02:00
ok 15 - 2009-07-01T00:00:00Z -> 2009-07-01T02:00:00+02:00

So now I know that I have a failing test due to rounding occuring. For my XMLTV project it is not important as I will not have to handle decimal seconds.

lundi 5 novembre 2007

A simple ksh framework prototype

Nothing is as good as a old Unix shell for running and monitoring batchs. Here is a proposition for a simple framework that will improve readabilty of the code while increasing error reporting in the output.

Lire la suite...

mardi 28 août 2007

TiddlyWiki and favicon

TiddlyWiki is a standalone wiki that is fully interactive and fully contained in a single HTML file. Here is a tip to add a favicon to your wiki.

To enable saving you have to give to the browser some special permissions allowing the JavaScript code to write to your disk. When using it with Microsoft Internet Explorer, the easy way to enable saving is to just rename your wiki as .hta to transform it into an "HTML Application", as Microsoft calls it.

But you can do better with HTML Applications than just decreasing the security level. I was particularly interested in a better integration with Windows. I wanted in particular to change the icon of the window that appears in the taskbar (I commonly have about 30-40 windows opened on my desktop). This is quite easy: you just have to add an <HTA:APPLICATION ICON="myfile.ico"> tag the <head> section of the HTML file.

Here is how to do it the TiddlyWiki way:

  1. Get an icon and save it as tiddlywiki.ico in the same directory as your wiki.hta file. For example: http://www.tiddlywiki.org/favicon.ico. You can also create you own icon here or here.
  2. Edit the built-in tiddler MarkupPreHead
  3. Insert the following text just after <!--{{{-->:
    <!--[if IE]>
    <HTA:APPLICATION ID="oHTA" APPLICATIONNAME="My wiki" ICON='tiddlywiki.ico'/>
    <![endif]-->
    <link rel='shortcut icon' href='tiddlywiki.ico' type='image/vnd.microsoft.icon '/>
    
  4. Reload your wiki.hta. That's it!

I now have to explore how to convert this to a plugin...

samedi 25 août 2007

Syntax highlighting on this blog using semantic tags and Vim

The regular readers of the HTML view of this blog (if they exist) may have noticed some changes in the syntax highlighting of the source code in my posts. I've tweaked the CSS style sheet to use the RubyBlue Vim theme instead of the Blue Vim theme. This is the occasion to explain you my process to format source code samples in HTML.

I'm a Vim addict, using it on Linux, AIX and Windows. Vim has a powerful and extensible syntax highlighting engine that can format almost any existing text file format. And most importantly, it has a plugin that can export the highlighted code as HTML.

There is many advantages in using Vim and storing statically highlighted code:

  • I can use the huge set of languages supported by Vim highlighting ;
  • I can use the huge set of themes built for Vim and easily convert to a CSS for the web ;
  • if a language is not supported, I can define highlighting myself (I already did it for 4 languages) and it will be done once for use both in Vim and on my blog ;
  • as I store only pure HTML as data in the blog engine (no special wiki code, no plugin), I am not dependent on the engine I'm currently using ;
  • no charge on the server (as with PHP formatting engines such as GeSHi) or on the client (such as with syntaxhighlighter) ;
  • as we are using simple <pre> tags, there is no characters/tags pollution: the reader can simply select and copy the text to the clipboard ;
  • last but not least, I can tweak the output to improve it and fix the highlighting bugs (some languages are very hard to parse).

In Vim you can invoke the conversion to HTML from the "Syntax" menu or that way:

:runtime syntax/2html.vim

To get the best XHTML code, I'm using the following settings in $HOME/.vimrc:

syntax on
" Conversion HTML (:help 2html.vim)
let g:html_use_css = 1
let g:html_use_encoding = "utf8"
let g:use_xhtml = 1

For example, here is the HTML I extract (I remove anything around the <pre> tag) from what is generated by 2html.vim from the code above:

<pre>
<span class="Comment">&quot; Conversion HTML (:help 2html.vim)</span>
<span class="Statement">let</span> g:html_use_css <span class="Operator">=</span> <span class="Constant">1</span>
<span class="Statement">let</span> g:html_use_encoding <span class="Operator">=</span> <span class="Constant">&quot;utf8&quot;</span>
<span class="Statement">let</span> g:use_xhtml <span class="Operator">=</span> <span class="Constant">1</span>
</pre>

I just have to add my own set of classes to enable highlighting:

<pre class="code vim vimft-vim">...</pre>

Here is the semantic associated to the classes:

  • code is my generic class for source code blocks 
  • vim is for source code formatted using the Vim classes for highlighting 
  • vimft-html is the class for the specific kind of source code: Vim's filetype option, displayed with ":set ft?".

For terminal output samples, I'm using my own highlighting using semantic XHTML tags :

  • <pre class="terminal">, the enclosing tag, with an optional class :
    • unix for Unix/Linux samples ;
    • cmd for Windows cmd.exe shell code.
  • <kbd> for what is typed in the terminal, with the following optional classes:
    • shell for any Unix shell samples ;
    • bash or ksh (in addition to shell) for Unix shell samples that uses features which are not in the standard POSIX shell ;
    • cmd for Windows cmd.exe shell code.
  • <samp> for programs output:
    • prompt for shell or interactive programs prompts ;
    • shell, bash, ksh or cmd for shell prompts (in addition to prompt) ;
    • sqlite, sqlite3 for SQLite client samples...
  • <var> for variable input/output. Everything except the <var> content should exactly match if you repproduce it yourself. The title can indicate what the variable represent, and on which data it depends. The tag is always a direct child of either <kbd> or <samp>.

Here is an example:

<pre class="terminal unix">
<samp class="prompt shell">$ </samp><kbd class="shell">echo Hello, world!</kbd>
<samp>Hello, world!</samp>
<samp class="prompt shell">$ </samp><kbd class="shell">date</kbd>
<samp><var>samedi 25 août 2007, 18:51:00 (UTC+0200)</var></samp>
</pre>

And the final result:

$ echo Hello, world!
Hello, world!
$ date
samedi 25 août 2007, 18:51:00 (UTC+0200)

This semantic tags will allow me to provide later additional feature using JavaScript code. I'm thinking to a button that would hide any <samp> tags and keep only <kbd> tags to ease copy of the commands to a terminal to run the commands.

With these tags in place, the CSS stylesheet is quite short and simple. More importantly it is easily replaceable in case I change the theme of the blog.

pre.code.vim,
pre.terminal { margin-left: 1pt; padding: 5pt; }

/* Text not embedded in samp or kbd will be in red, to easily detect errors */
pre.terminal { background: #000; color: #f00; }
pre.terminal samp.prompt { color: #888; }
pre.terminal samp { color: #eee; }
pre.terminal kbd { color: #fff; font-weight: bold; }
pre.terminal var { color: #55f; font-style: italic; }

/* colorscheme rubyblue */
pre.code.vim { color: #c7d4e2; background-color: #162433; }
pre.code.vim a[href] { color: #0f0; }
pre.code.vim .Constant { color: #0c0; }
pre.code.vim .Comment { color: #428bdd; }
pre.code.vim .Identifier { color: #fff; }
pre.code.vim .Label { color: #ff0; }
pre.code.vim .Operator { color: #ff0; font-weight: bold; }
pre.code.vim .PreProc { color: #f9bb00; }
pre.code.vim .Special { color: #0c0; }
pre.code.vim .Statement { color: #f9bb00; }
pre.code.vim .Title { color: #fff; font-weight: bold; }
pre.code.vim .Type { color: #fff; text-decoration: underline; }
pre.code.vim .Underlined { color: #208aff; text-decoration: underline; }

I had to tweak a bit the blog engine I use (DotClear) to add this style sheet: modifying the template.php in the theme directory is not enough because the theme is used only on the public part of the blog. So I added an @import rule in ecrire/style/default.css to enable the CSS in the private area of the blog.

 

I would be glad to read your experiences about source code formatting on your own blog or CMS.

Update 2007-09-06: added missing information about the usage of <var> tags.

samedi 4 août 2007

Using OpenStreetMap with Maemo Mapper

I found in the svn source code of Maemo Mapper that the new default map provider for Maemo Mapper is now OpenStreetMap, a free map database that you can contribute to. You can already manually add the OpenStreetMap repository with the following URI: http://tile.openstreetmap.org/%0d/%d/%d.png

jeudi 12 avril 2007

Simple Perl wrapper for non-Perl TAP programs

TAP (Test Anything Protocol) is a simple protocol to report the result of a testsuite. It was initially designed for test suites of Perl modules, but developers of the Test::Harness modules have seen the potential for a more generic usage of the protocol outside of the Perl ecosystem and libraries are in development for other programming languages.

I'm writing C code and contrary to most programming langages today, there is no library to build test suites in a standard way. Java has JUnit, Perl has Test::Simple and Test::More...

Someone has developped libtap, but no one uses it (except FreeBSD developers as advertised on the site). Also, I do not like the library interface because it exports functions such as ok() or diag() which could conflict with existing code. So, I wrote my own library that I will publish one day. But that is not the point of this post.

When you have written a program conforming to the TAP, you want tools to analyse the result of the tests. And the main advantage of using a standardized protocol is to be able to use generic tools and avoid to implement/test/debug them yourself. The problem with TAP is that the only tool that is available is prove and it suffers of a major flaw: it is designed to run only Perl tests.

Here is a simple TAP-compliant C program that outputs the result of a static testsuite:

#include <stdio.h>

int main(int argc, char *argv[])
{
  puts("1..1\nok 1");
  return 0;
}

And the output:

$ gcc a.c
$ ./a.out
1..1
ok 1

When trying to run it with prove, perl complains it did not found Perl code:

$ prove a.out
a....Unrecognized character \x7F at a.out line 1.
a....dubious
        Test returned status 9 (wstat 2304, 0x900)
FAILED--1 test script could be run, alas--no output ever seen

So I wrote the following generic Perl wrapper a.out.t that just runs a.out:

# vim:set ft=perl:

use strict;
use File::Spec;
my $exe = File::Spec->rel2abs($0);
$exe =~ s/\.t$//;

exec $exe $exe or die "$exe: $!";

And now, success is achieved:

$ prove a.out.t
a.out....ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.01 cusr +  0.01 csys =  0.02 CPU)

vendredi 16 février 2007

Vim & Polyhedra : added polycfg.vim

I uploaded two Vim syntax scripts for Polyhedra :

See my post about the previous release.

dimanche 28 janvier 2007

I'm a cmd.exe master

A few months ago, Paul Bissex posted this on his blog: Let’s play a game: BASIC vs. Ruby vs. Python vs. PHP. Just a small exercise at implementing a simple algorithmic problem in diverse programming languages.

I replied with an implementation in an old and widespread but still much unknown, language: the Microsoft Command Processor (cmd.exe). Old because it inherits from the command.com present in 80's {PC,MS}-DOS. Widespread because it is available on every Windows machine in the world. Unknown because few use it.

Lire la suite...

samedi 27 janvier 2007

Vim & Polyhedra

I uploaded this afternoon on vim.org a syntax highlighting script for Polyhedra CL.

Polyhedra is a memory based database engine. It can be used in for embedded development, but also in high performance application where more classiscal disk-based engines are too slow. CL is the programming language used for stored procedures.

dimanche 21 janvier 2007

Why use REST, CRUD (and avoid SOAP) ?

Ruby on Rails 1.2 has been released. In the announcement, David writes about the new features he announced at the RailsConf in July. Don't miss the video of his talk (the slides are here).

The main points of the talk:

  • what is REST and why it is good,
  • how implementing REST is available in Rails,
  • what is CRUD, how CRUD helps in designing your model (in a MVC application),
  • using mimes types, and content negociation, a powerful feature of HTTP, in Rails for an unified set of set of URLs,
  • how to access to REST web services using ActiveResource

I'm just glad that development tools improve to simplify REST-enabled and content negociation-enabled applications.

I'm already using theese HTTP features in my Météo Mobile application developed in PHP :

  • /meteo/bna/06 uses content negociation (examinates Accept header) to serve the most appropriate content type
  • /meteo/bna/06.html serves XHTML as text/html
  • /meteo/bna/06.xhtml serves XHTML as application/xhtml+xml
  • /meteo/bna/06.wml serves WML as text/vnd.wap.wml for mobile devices

For those that would like to implement content negociation in PHP, the main tip is to capture 406 errors to be able to serve content to (mobile) browsers that do not accept */* in Accept:.

samedi 11 novembre 2006

DailyMotion's poor HTML code

For my post of this morning that included a video I did use DailyMotion services. When you upload a video, they provide HTML code to embed it on your site. OK, that seems fine. But it's not. Here is the code:

<div>
  <object width="425" height="335">
    <param name="movie" value="http://www.dailymotion.com/swf/2JarEXHqOuOxZ4psf"></param>
    <param name="allowfullscreen" value="true"></param>
    <embed src="http://www.dailymotion.com/swf/2JarEXHqOuOxZ4psf" type="application/x-shockwave-flash" width="425" height="334" allowfullscreen="true"></embed>
  </object><br />
  <b><a href="http://www.dailymotion.com/video/xmj2z_rallye-de-vence-2006-speciale-3-96">Rallye de Vence 2006 - Spéciale 3 - 96</a></b>
</div>

Here are my grievances:

  • This code uses <embed> tags, which have never been part of any W3C HTML specifications. <embed> is, AFAIK, a Netscape-only tag. Firefox/Mozilla now recognizes the standard <object> tag, so <embed> is only required for compatiblity with Netscape 4.x which, at web2.0 time, nobody uses anymore.
  • They do not provide alternative strictly validating XHTML code. Most blog and CMS software are now XHTML strict compliant. Embedding this code breaks strict validation and could cause the page to not display at all.
  • The code is not working with old Flash versions and does not tells why or proposes to upgrade. My parents have Flashplayer 6, and the display is weired. Even worse, when clicking on the link below the video to go to DailyMotion site, it crashes IE6 (with latest security patches).

So, here is my own code:

<div class="video dailymotion">
  <object width="425" height="335" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">
    <param name="movie" value="http://www.dailymotion.com/swf/2JarEXHqOuOxZ4psf"></param>
    <param name="FlashVars" value="playerMode=embedded"></param>
    <!--[if !IE]>-->
      <object width="425" height="335" data="http://www.dailymotion.com/swf/2JarEXHqOuOxZ4psf" type="application/x-shockwave-flash"></object>
    <!--<![endif]-->
  </object><br />
  <b><a href="http://www.dailymotion.com/video/xmj2z_rallye-de-vence-2006-speciale-3-96">Rallye de Vence 2006 - Spéciale 3 - 96</a></b>
</div>

Tested with Firefox 1.5.0.8 and Internet Explorer 6. I just hope it works with Opera/Safari/Konqueror…

Some reference documentation from Netscape/Mozilla and Ado be were useful.