July 2006

Cutting essay

Wed 26 July 2006, , ,

Here, an other piece of C# software I’m managing to solve : a 2D cutting optimizer. It’s a bit hard to explain, so a picture is worth a thousand words.

The cutting organisation in live
the source (tgz - 16kB)

Each red block (labelled number (width, height)) is a piece of wood, glass the client want to obtain. The aim is to minimize the cutting operations, the pieces the aren’t used and to fit the master piece.

The idea is to use a genetic algorithm to find the best cutting way. An simple heuristic a possible but it’s quite to easy and cannot find the realy best solution. Oh, I’ve not writed the fitness function at the moment.

I use Cairo (-r:Mono.Cairo) for drawing, it’s very powerful and easy (if you know how OpenGL works).

Encore un peu de C# (avec Mono évidemment). Ça concerne un petit logiciel que j’essaie de réaliser. Il s’agit d’un logiciel permettant d’optimiser la coupe d’éléments rectangulaires et leur agencement pour par exemple : un vitrier, un menuisier, ... L’image ci-dessus présente l’état actuel des choses, il génère un diagramme de découpe de manière aléatoire (ce qui est déjà pas mal).

La suite est d’utiliser un algorithme génétique afin de trouver la meilleure solution. Je n’ai pas encore commencer cette étape.

Sinon, ce joli dessin est réalisé avec Cairo, un outil très efficace en matière de dessin 2D et assez simple (si on a déjà des connaissances d’OpenGL par exemple).

Related entries

Digg it!, so del.icio.us, blogmarks, reddit.

DNS with C#

Mon 24 July 2006, , ,

A friend of mine asked me : “How to get the default mail server of a company (with C#)”. He tried with nslookup but without any success. So I decided to try.

Some google searchs gives me the excellent tool called dig.

$ dig he-arc.ch MX
[...]
;; ANSWER SECTION:
he-arc.ch.              180     IN      MX      10 smtpgw1.he-arc.ch.
[...]

Using dig from C# isn’t really nice. It’s a big and ugly hack.

Another try with dnsJava. First step, convert the .jar into a library or executable for Mono via IKVM. It doesn’t work because of GNU Classpath isn’t fully complete and, probably, dnsJava uses too specific classes from the JRE/JDK of Sun.

Keep googling... And this article, the paradize on earth : C# .NET DNS query component. I downloaded the sources, removed the key.snk file, compiled the library and try this sample code :

using System;
using System.Net;
using Bdev.Net.Dns;

public class DnsTest {
   public static void Main(string[] argv) {
      // Shameful hardcoding of my DNS server (CableCom DNS server)
      IPAddress dnsServerAddress = IPAddress.Parse("62.2.17.60");
      
      // Retrieve the MX records for the domain dosimple.ch
      MXRecord[] records = Resolver.MXLookup("dosimple.ch", dnsServerAddress);
      
	   // iterate through all the records and display the output
      foreach (MXRecord record in records) {
          Console.WriteLine("{0}, preference {1}", record.DomainName, record.Preference);
      }
   }
}

It works. System.Net.Dns doesn’t need to specify the DNS server so, it’s a weird behaviour. There is a bug with these classes when a domain name contains a dash '-'.

Un collègue, camarade, poteau m’a interrogé concernant la possibilité de connaître le serveur de mails d’une entreprise via C# (.Net). Il avait apparemment essayé avec nslookup, l’outil fournit par Microsoft, mais bon ce n’était pas concluant. Voici les détails de mes recherches (avec ci-dessus un développement plus fin).

L’objet intégré dans le framework System.Net.Dns ne permet pas de faire une requête avec le type de serveur.

Un autre outil, nommé dig est bien plus sympa que nslookup, mais appelé un exécutable depuis C# me semble être un gros hack.

Un nouvel essai avec le prometteur dnsJava qui une fois converti en bibliothèque pour le CLR devrait aller nickel. Le problème est qu’IKVM (ou plutôt GNU.ClassPath) n’a pas tous les outils pour faire ça. Sun is evil !.

Et pour terminé, un code déniché dans cet article : C# .NET DNS query component qui offre les outils adéquats pour obtenir le nom du serveur mail d’un domaine, avec quelques bogues toutefois.

Digg it!, so del.icio.us, blogmarks, reddit.

Monthly archives

Sun 23 July 2006, , ,

Some enhancement for this weblog with the archives pages for the months of July and June. A future step’ll be to make un page for each tag. Now it’s only for Technorati. I should probably use the redirect extension. Here a little example :

The source file (source.xml):

<?xml version="1.0"?>
<feed>
   <entry>A</entry>
   <entry>B</entry>
   <entry>C</entry>
   <entry>D</entry>
</feed>

The template (chunk.xsl):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
   extension-element-prefixes="redirect">

<xsl:output method="xml" indent="yes"
   doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

<xsl:template match="/">
   <xsl:choose>
      <xsl:when test="element-available('redirect:write')">
         <xsl:for-each select="//entry">
            <redirect:write select="concat(., '.html')">
               <!-- The page of the entry -->
               <html>
                  <head>
                     <title><xsl:value-of select="." /></title>
                  </head>
                  <body>
                     <h1><xsl:value-of select="." /></h1>
                     <a href=".">Back</a>
                  </body>
               </html>
            </redirect:write>
         </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
         <xsl:message>Redirect extension isn't available</xsl:message>
      </xsl:otherwise>
   </xsl:choose>
   <!-- Output the main page -->
   <html>
      <head>
         <title>Main page</title>
      </head>
      <body>
         <h1>Main page</h1>
         <ol>
            <xsl:for-each select="//entry">
               <li>
                  <a href="{concat(., '.html')}">
                     <xsl:value-of select="." />
                  </a>
               </li>
            </xsl:for-each>
         </ol>
      </body>
   </html>
</xsl:template>

</xsl:stylesheet>

After a transformation (here using xsltproc): xsltproc chunk.xsl input.xml > index.html. You’ve got 5 files :

  • index.html
  • A.html
  • B.html
  • C.html
  • D.html

This kind of way of working enable you to work more globally. In the case of this blog, it should enable me to generate, with only one transformation, all the blog. It’ very useful for archives, entries or feeds where I only need to give to the XSL template a list of the entries. But I need more work to generate the page for each tags. It’s probably a two passes way.

Afin d’améliorer un peu ce blog, j’ai ajouté les archives mensuelles. Il me resterait à faire les pages selon les tags utilisés. Pour l’instant, je fais confiance à Technorati.

Sinon, je pense qu’il va me falloir utiliser l’extension redirect (voir l’exemple ci-dessus) afin d’améliorer la génération de ce blog et peut-être (dans un futur proche) la génération des pages par tags.

Digg it!, so del.icio.us, blogmarks, reddit.

Finished !

Fri 21 July 2006,

My service civil is over. I’m so, so, so happy. Now I’m free

For my future employment, I can’t go to Lausanne (UNIL) anymore, but Dublin seems to be the solution (it should be so great, I still cannot believe it). And on Monday, I’ll do a technical test for Barcelona (so that still open). Moûtier should be the solution if all the others collapse.

Le service civil c'est terminé !! Trop, trop, trop de bonheur.

Quant à la suite, je sais d'ore et déjà que je n’irai pas à Lausanne (UNIL), mais les portes de Dublin sont plus ouvertes que jamais. Sinon, Barcelone va occuper une partie de mon lundi et tristement Moûtier se profil de plus en plus comme une solution de remplacement.

Related entries

Digg it!, so del.icio.us, blogmarks, reddit.

One week more

Sat 15 July 2006, ,

Today another pieces of my life. The elderflower syrup rested for the entire week and now it’s so delicious. If you’ve some Elderberries in your countryside your should try. The season is probably over (I’m living at an elevation of 1,000m (approx. 3,280 ft)).

My service civil (in German zivil Dienst) is over in one week. I’m so happy about that. Working 5 months with disabled people was the greatest experience in my life. I know that it’s not a job for me even if I loved to do it.

I still unemployed but I’ve some promising opportunities in nice areas like : Moutier (CH), Lausanne (CH), Barcelona (ES) or Dublin (IE). I cross the fingers that I’ll find a big challenge for my first job in the real life.

Le sirop de sureau, qui a passé la semaine à tremper, est sombtueux, que dis-je, divin. Et pourtant, je n’ai pas mis d’acide citrique (E330) (produit que l’on trouve en pharmacie).

Du côté professionnel, je suis toujours sans-emploi, mais ai des ouvertures prometteuses du côté de Moutier, Lausanne, Barcelone voire même Dublin. À savoir qui sera le plus rapide et le plus convainquant.

Sinon, dans une semaine prend fin mon affectation au service civil. J’aurai passé 22 semaines à travailler dans le milieu des personnes ayant un handicap mental. Un expérience très très riche, et même si j’ai un plaisir énorme à travailler pour eux, je sais que ce n’est pas mon milieu, j’ai besoin de challenge.

Related entries

Digg it!, so del.icio.us, blogmarks, reddit.

Elderflower syrup

Sat 08 July 2006,

The Elders are in flowers for a couple of days so I decided to make some Elderflower syrup.

At the moment, the mixture is still hot and needs to rest for some days. But I’ll taste it and put it in my old bottles of beer from the BFM.

Avant que la saison ne se termine, je suis allé cueillir des fleurs de sureau afin de m’essayer à la fabrication de sirops.

Actuellement, le tout est encore dans la casserole et le tout devrait être prêt dans quelques jours. Voici donc quelques liens plus ou moins intéressant sur le sujet.

Quant aux bouteilles, j’ai pensé que de réutiliser de vieilles bouteilles de bière de la Brasserie des Franches-Montagnes (BFM) sera parfait. À voir.

Digg it!, so del.icio.us, blogmarks, reddit.