[Classic ASP] Improving split function

Coming from the JavaScript world, I’m used to split function working as follow :

"".split(",")
> Array [ "" ]

It’s basic JavaScript. Take an empty string, try to split it on a delimiter, it will return an array containing just one element : an empty string. It’s exactly what you expect from the function, always return an array. Like it should be in every programming language.

A few weeks ago, I had to deal with split function in ASP Classic. Calling the function is a bit different, but that’s not a big deal :

split("foo,bar", ",")

The function works fine in almost every cases. But it has an unexpected behaviour when you use it on an empty string. Let’s try it :

Dim array
array = split("", ",")
'-- Expect array to contain one element
UBound(array) '-- Returns -1. Wait! What?
array(0)      '-- Guess what: Internal server error

That’s a problem. The split function does not return an array containing an empty string when you try to split an empty string, it just returns an array with nothing in it – hence UBound returning -1.

When you are aware of this particularity, it’s easier to write your code. Since I personally prefer a JavaScript-like split function, I decided to write a betterSplit function doing the job as I wanted :

'-- Improve Split to work as expected
Function betterSplit(str, delimiter)
  Dim ar
  ar = Split(str, delimiter)

  '-- UBound
  '-- < 0 if empty string
  '-- = 0 if no delimiter in string
  If UBound(ar) <= 0 Then
    ReDim ar(0)
    ar(0) = str
  End If

  betterSplit = ar
End Function

As a matter of fact, I find this function much better than the original split function as it always returns an array even when using an empty string as a parameter.

24H du Mans Roller 2015

Fin juin, je suis parti avec un petit groupe d’aventuriers vers l’ouest de la France, afin de relever un défi d’envergure. Chacun de nous avait prévu son matériel : roues, chaussons, platines, roulements, … Les esprits étaient plus ou moins reposés, les corps prêts à en découdre.

C’est donc bien chargé que nous sommes arrivés au camping du circuit des 24h du Mans, dans la ville du Mans comme vous l’aurez compris. Comme nous, de nombreuses équipes de niveaux variés ont fait le déplacement; une partie en bus, d’autres en camping car, certains en mini-bus, les derniers en voiture et les plus courageux en train. Une bonne ambiance règne dans le camping, occupé par une multitude de nationalités, français bien sûr, mais aussi : allemands, anglais, espagnols et danois.

Partis à quatre de Strasbourg, notre cinquième coéquipier nous rejoint en début de soirée. L’équipe est au complet; le sixième s’étant blessé peu avant la date de la compétition; sans que nous lui trouvions un remplaçant.

Après une nuit quelque peu agitée – à cause de gens s’essayant à la slackline une bière à la main à 1h du matin – le début d’une longue journée s’annonce. Bien que la compétition ne commence qu’à 16h, il y a bien des choses à faire avant le coup d’envoi de ces 24h du Mans roller 2015. Récupération des dossards et des puces, petit-déjeuner et c’est déjà l’heure de la parade et de découvrir pour la première fois le circuit ainsi que sa montée du Dunlop dont j’ai tant entendu parlé. Une majorité d’équipe sont présentes pour cet événement d’avant course, c’est une véritable explosion de couleurs qui envahit l’asphalte noir du circuit.

Continuer la lecture de « 24H du Mans Roller 2015 »

[Vidéo] Internet, censure, libertés, …

Une discussion très intéressante avec Jérémie Zimmermann, Korben, Tristan Nitot. Des points nouveaux, d’autres plus connus lorsqu’on est sensible à toutes ces questions, mais toujours pertinent.

Lien vers « Terrorisme/Internet : Liberté d’expression menacée en France ? »

Enabling code coverage : in Sonar, from Jenkins, with Maven, using Jacoco.

Let’s assume a few think before we begin.

  • SonarQube is installed somewhere and works.
  • The task « Invoke Standalone Sonar Analysis » is available in Jenkins.
  • Your project is using Maven so it has a pom.xml.

To begin, we’ll add configuration in our pom.xml.

<properties>
  <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
  <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
  <sonar.language>java</sonar.language>
</properties>

We’re using JUnit to run tests.

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Continuer la lecture de « Enabling code coverage : in Sonar, from Jenkins, with Maven, using Jacoco. »

[NPM] Wrong python executable at install

In case you get an error similar to this when trying to npm install :

Error: Python executable "python" is v3.4.2, which is not supported by gyp.

You should tell npm which executable to use with the following command:

npm config set python python2

If you are on ArchLinux, you’re likely to encounter this problem since the default python is python3. Fortunately, it’s easy to fix.