Olivier Mengué – Code & rando

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

Code

Informatique : développement, administration, logiciels...

Fil des billets - Fil des commentaires

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)

mercredi 7 mars 2007

Installer Python, SQLObject et Cheetah sous Windows

Voici un micro tutoriel pour installer le langage Python et quelques modules de base qui seront bien utiles au RIF.

Lire la suite...

jeudi 22 février 2007

Cheap podcast download using cmd.exe and wget

Why use huge and intrusive software such as iTunes when a small script is just enough?

I own a NDEO Equinox² OGG/MP3/FM player/recorder which appears in the PC as a simple 512 Mb flash drive. Besides listening to music and radio it is very convenient to move files to/from work and it recharge itself from the USB. It works on any operating system which support USB storage without a special driver and help to stay away from DRM.

I'm also using the storage feature for scripts directly useful for the main usage of this particular flash drive: retrieving podcasts. I have installed GNU wget on all my Windows PCs (this is an invaluable tool that is particularly useful to download big files (see --continue and --limit-rate options) and for mirroring of web sites) so with the following 10 lines cmd.exe script I can download the latest Radio France podcats of the broadcast I missed.

Here is the generic Windows script for any Radio France MP3:

@echo off
setlocal
:: Le numero de podcast est soit sur la ligne de commande
:: soit dans le nom de ce script get-<numero>.cmd
if not "%1"=="" (set n=%1) else (
    for /F "delims=-_ tokens=2" %%i in ("%~n0") do set n=%%i
)
set rss=rss_%n%.xml
wget -O %rss% http://radiofrance-podcast.net/podcast/%rss% || goto :EOF
for /F "tokens=2" %%f in ('findstr "enclosure" %rss%') do set URL=%%f
set URL=%URL:~5,-1%
echo %URL%
wget -c %URL% && del %rss%

It fetches the RSS file, extracts the URL of the MP3 file and downloads it. The podcast number must be either given file as a command line argument or in the name of the file itself. For example to retrieve "France Info - Chronique Jeux Vidéo, just save the script as radiofrance-18963.cmd. Run it today and it will download 18963-18.02.2007-ITEMA_20059064-0.mp3.

Note: I you are behind an HTTP proxy, you have to set the http{,s}_proxy environment variables. For example:

set http_proxy=http://myproxy:3128
set https_proxy=http://myproxy:3128

You can define them once for all in the Windows Control Panel.

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:.

jeudi 11 janvier 2007

Compte-rendu du FOSDEM 2006

Pour vous inciter à aller au FOSDEM 2007, voici un compte-rendu détaillé du FOSDEM 2006 que j'avais écrit en mars dernier.

Lire la suite...

vendredi 22 décembre 2006

Encodage BER et Perl

Une réponse à une question sur la liste de diffusion des Mongueurs de Perl m'a amené à explorer l'encodage 'w' (BER : Binary Encoded Representation) de la fonction pack() de Perl 5 (voir perlpacktut dans la doc).

La chaîne de caractères obtenue est de longueur variable car découpée par paquets de 7 bits. Voici quelques lignes de Perl pour trouver les bornes des changements de longueur :

my @a = map { ((2**(7*$_))-1, 2**(7*$_)) } 0 .. 5;
print map { "$_: ".unpack('H*', pack('w', $_))."\n" } @a;

On obtient ceci (à gauche, le nombre en décimal et à droite encodé en BER puis en hexa) :

0: 00
1: 01
127: 7f
128: 8100
16383: ff7f
16384: 818000
2097151: ffff7f
2097152: 81808000
268435455: ffffff7f
268435456: 8180808000
34359738367: ffffffff7f
34359738368: 818080808000

samedi 25 novembre 2006

Django aux Journées Perl 2006

Hé oui, Django c'est du Python, et pourtant on j'en parlerais aux Journées Perl 2006 ce week-end à la Cité des Sciences et de l'Industrie.

J'ai deux présentations au programme :

  • 14h00 Introduction aux ORM : un introduction générale sur les ORM et une présentation du modèle de données utilisé en commun dans plusieurs des présentations : un mini modèle représentant une association de randonneurs.
  • 14h10 Les modèles de Django : une petite introduction générale sur Django puis l'accent sera mis sur la définition des modèles Django, l'API de requêtes et comment les spécificités de Python sont utilisées. L'objectif est de montrer un modèle de conception d'ORM et comment le sucre syntaxique du langage peut être mis à profit.

Je vous invite à aller voir les autres présentations sur les ORMs qui ont lieu le samedi après-midi.

lundi 20 novembre 2006

Dotclear et le spam

À peine quelques semaines d'existence de ce blog, et déjà du spam. C'est la fonction trackback de Dotclear qui est ciblée.

Voici quelques requêtes que j'utilise pour les éliminer :

SELECT * FROM dc_comment WHERE comment_trackback = 1
AND (comment_site LIKE '%sitesfree%' OR comment_auteur LIKE '%viagra%' OR comment_auteur LIKE '%pills%' OR comment_site LIKE '%hydrocone%')

DELETE FROM dc_comment WHERE comment_trackback = 1
AND (comment_site LIKE '%sitesfree%' OR comment_auteur LIKE '%viagra%' OR comment_auteur LIKE '%pills%' OR comment_site LIKE '%hydrocone%')

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.

page 2 de 2 -