BaroqueW

BaroqueW

and his sidekick nikkitaa

BaroqueW RSS Feed
 
 
 
 

Archive for Tech

Customisation de WordPress - Alt to Legend

Puisque je viens de migrer de Spip à WordPress, il y a pas mal de choses à refaire. Heureusement de nombreux plugins sont là pour me simplifier la tâche. Alt to Legend est un de ceux-là. Il permet en un tour de main de faire apparaître la légende des photos que vous ajoutez à vos articles. Il permet notamment de ne pas avoir à se salir les mains ou à plonger dans le code de vos thèmes pour tout faire vous-même.

J’ai dû légérement le modifier pour arriver à mes fins cela dit.

  • D’abord, le centrage des légendes ou des images ne marchaient pas. float : center ne passe pas : remplacé par margin-left : auto; margin-right : auto; pour le cadre et par <center></center> pour le texte
  • La reconnaissance du centrage ne se fait plus sur align=”left/right/center” mais sur class=”alignleft/right/center” pour refléter mon thème
  • Lorsqu’une image n’a pas de légende, elle est désormais zappée (attention, cela zappe aussi le cadre autour de l’image.
  1. if (strcmp($al_settings['text_align'], "center") == 0) {
  2.  
  3.                 $text_style = ‘<span><center>’;
  4.  
  5.                 $text_style_close = ‘</center></span>’;
  6.  
  7.         }
  8.  
  9.         else {
  10.  
  11.                 $text_style = ‘<span style="text-align:’.$al_settings['text_align'].’; ">’;
  12.  
  13.                 $text_style_close = ‘</span>’;
  14.  
  15.         }
  16.  
  17.         $counter = 0;
  1. // Set the apperarance of the borders and the image according to user settings
  2.  
  3.         if ( $al_settings['use_border'] == false ) { $al_settings['border_style'] = ‘none’ ;}
  4.  
  5.         $div_open = ‘<div id="img_lgnd" style="position: relative; font-size: ‘.$al_settings['font_size'].’; border: ‘.$al_settings['border_size'].’px ‘.$al_settings['border_style'].’ ‘.$al_settings['border_color'].’; margin: ‘.$al_settings['margin'].’; padding: ‘.$al_settings['padding'].’; max-width: ‘.$img_width.’px;  height:auto !important;’;
  6.  
  7. if (strcmp($image_align, "right") == 0 ){
  8.  
  9.                 $div_open .= ‘ float : right’;
  10.  
  11.         } else if (strcmp($image_align, "left") == 0 ){
  12.  
  13.                         $div_open .= ‘ float : left’;
  14.  
  15.         } else if (strcmp($image_align, "center") == 0){
  16.  
  17.                 $div_open .= ‘ margin-left : auto; margin-right : auto’;
  18.  
  19.         }
  20.  
  21. $div_open .= ‘">’;
  22.  
  23. $img_true_end = $img_start + strlen($img_text);
  24.  
  25.         $img_text = str_replace ($img_open, $img_incipit, $img_text);
  26.  
  27. $lgnd_start = strpos($img_text, $lgnd_open);
  28.  
  29.         if ($lgnd_start) { // if the alt or title description exists
  30.  
  31.         $img_text2 = substr($img_text, $lgnd_start + $lgnd_open_len + 1);
  32.  
  33.         $lgnd_end = strpos($img_text2, $lgnd_close);
  34.  
  35.         $lgnd_text = substr($img_text2, 0, $lgnd_end);
  36.  
  37.         $before = substr($data, 0, $img_start);
  38.  
  39.         $after = substr($data, $img_true_end);
  40.  
  41. $data_chunck[$counter] = $before.$div_open.$img_text.$text_style.$lgnd_text.
  42.                                          $text_style_close.$div_close;
  43.  
  44.         $data = $after;
  45.  
  46.         $counter++;
  47.  
  48.         } else {
  49.  
  50.          $before = substr($data, 0, $img_true_end);
  51.  
  52.          $after = substr($data, $img_true_end);
  53.  
  54. $data_chunck[$counter] = $before;
  55.  
  56.          $data = $after;
  57.  
  58.          $counter++;
  59.  
  60.         }
  61.  
  62. }
  63.  
  64. $data =”;
  65.  
  66.       for ( $c = 0; $c < $counter; $c++) {
  67.  
  68.        $data = $data.$data_chunck[$c];
  69.  
  70.              }
  71.  
  72.       $data = $data.$after;
  73.  
  74.        }
  75.  
  76.     return $data;
  77.  
  78. }
Category: Articles en français, Blog, Tech >> Computer | Leave a comment

Analyse des logs de MediaProxy

Voici une brève astuce pour analyser les logs de MediaProxy. Plus précisément, ce script affiche le nombre moyen de paquets perdus par MediaProxy lorsqu’on le teste avec des sessions RTP ayant un nombre de paquets constant et connu (i.e. lorsqu’on rejoue une session RTP pré-enregistrée, avec SIPp par exemple).

  1. tail -1000 /var/log/messages | grep relayed | awk ‘{print $8}’ > myresults
  2. sed ’s/^…………//’ myresults | awk ‘BEGIN{s=0;}{s=s+$0;}END {print 400-s/NR;}’

Petite explication

  1. tail -1000 /var/log/messages | grep relayed | awk ‘{print $8}’ > myresults

Première ligne, on prend la fin des logs systèmes (adaptez à votre configuration, notamment si les logs de MediaProxy sont dans un fichier séparé), on sélectionne ensuite uniquement les lignes indiquant la fin d’une connection, et sur ces lignes, on ne prend que le 8ème champ (qui contient le nombre de paquets reçus et renvoyés) et on sauvegarde le résultat dans un fichier temporaire.

  1. sed ’s/^…………//’ myresults | awk ‘BEGIN{s=0;}{s=s+$0;}END {print 400-s/NR;}’

Seconde ligne, on ne convserve que le nombre de paquets renvoyés par MediaProxy, on additionne toutes les valeurs et on en fait la moyenne avant de la soustraire du nombre de paquets attendus (ici 400 par session RTP) ce qui donne le nombre moyen de paquets perdus par session RTP.

Category: Articles en français, Tech >> Computer | Leave a comment

A GPS on your Mac

I just bought a no-name USB GPS receiver in the Swedish store Teknikmagasinet and it’s up and running on my Mac (Leopard 10.5.1 or Ubuntu via Parallels). Story of an installation.

The device is just a small box, the size of a matchbox, that you can connect using the built-in PS2 cable or using the USB cable extension provided in the package (convenient to place the receiver outside or by the window). The package also contains a CD, note really useful (especially the test application) but it gives a very exhaustive list of the NMEA commands the receiver understands. The GPS chip is a Nemerix (not a Garmin, not a SiRF). For $40 to $60, you can find on Amazon similar USB GPS receivers with various chips and features (waterproof, number of channels, etc.).

Ubuntu
Ubuntu
First of all, Ubuntu with Parallels. My install is the installation that can be found on the website of Parallels. Remember to connect the USB port to Parallels (Devices>USB>USB-Serial controller) before going any further. Next, go in System>Administration>Synaptics Package Manager under Ubuntu. You can do a search on the string “GPS” and install the packages you feel interested in. At least, you need to install the GPS daemon gpsd and a client: xgps or gpsdrive. Then, start gpsd with ‘gpsd -n -D 3 -p /dev/ttyUSB0‘. If you want to push the envelope any further, go and visit the gpsd web site, otherwise, I provide all the basic informations here. To check your GPS receiver is working, start xgps or gpsdrive. If you see a sort of constellation in xgps representing the various satellites of the GPS system, or if your position shows up properly in gpsdrive, you’re good. If you have a display in xgps but not coordinates on the left side of the screen, it means the signal is too weak. Get the receiver outside or closer to a window, or try to get a clear horizon. To do some debugging, stop gpsd and start it again with ‘gpsd -n -N -D 3 -p /dev/ttyUSB0} to check the messages exchanged between the receiver and the computer. If you see a message saying “satellite data no good”, it means there is no proper reception. See below to screenshots: first, a screen of xgps with a poor reception (”n/a” on the left of the screen) and a screen of gpsdrive with a proper signal (I removed the bottom of the screen that included my coordinates). I didn’t test but this whole setup should be compatible with Kismet.

MacOSX
MacOSX
Now, let’s have a look at MacOSX. The easiest is to start installing the driver for PL2303 (the USB controller for many GPS receivers) on Prolific’s website. Then, install gpsdX, the OSX version of gpsd. Then start the start the application called ‘gpsdX Config’ and choose ‘/dev/tty.usbserial’, the peripheral created by the driver downloaded on Prolific (obviously if you GPS receiver is bluetooth-enabled, just select one of the /dev/tty.Bluetooth devices from the list). Apply the new settings and you now have a gpsd server running under MacOSX! Next step, finding a client. You have two options: gps2geX that interfaces gpsd with Google Earth (even in its free version), or the MacOSX port of GpsDrive developed by VASS-Softwareentwicklung. The first one obviously needs to have Google Earth installed on your computer. To use gps2geX, start GE, then start gps2geX, next click on “Start gps2geX” and here you are: Google Earth is kept updated regularly with your position! On the other hand, GpsDrive requires the installation of X11 from your copy of the DVD of MacOSX Leopard (or Tiger). Note that Gpsdrive is a PPC binary (but runs on Intel computers via Rosetta). The rest is just like under Ubuntu. Last precision, the use of gpsX is compatible (tested) with KisMAC (Kismet and KisMAC are two tools for wireless networks).

Category: Articles in English, Tech >> Computer | Leave a comment

Un GPS sur votre Mac

Je viens récemment d’acquérir un récepteur GPS USB d’entrée de gamme (comprendre, no-name) chez les Suédois de Teknikmagasinet et il tourne sur mon Mac (Leopard 10.5.1 ou Ubuntu via Parallels). Récit d’une installation.

L’appareil se présente sous la forme d’une petite boîte (taille boîte d’allumettes) qui peut se connecter avec un cable PS2 ou USB via la rallonge fournie (pratique pour laisser le recepteur a la fenetre ou dehors dans le jardin). Il y a aussi un CD d’install, anecdotique au niveau des applications mais avec plusieurs guides qui renseignent sur les commandes NMEA que le récepteur reconnaît. Au passage, la puce GPS est une puce Nemerix (pas Garmin ni SiRF).

Ubuntu
Ubuntu
Tout d’abord, sous Ubuntu avec Parallels. Mon installation est celle qu’on trouve à télécharger sur le site de Parallels. Rappelez-vous de connecter le port USB à Parallels (Devices>USB>USB-Serial controller) avant de commencer. Ensuite, allez dans System>Administration>Synaptics Package Manager sous Ubuntu. Faites une recherche sur GPS et installez les packages qui vous intéressent (au moins gpsd pour le daemon GPS indispensable et probablement un client: xgps ou gpsdrive sont une bonne idée). Lancez ensuite gpsd avec ‘gpsd -n -D 3 -p /dev/ttyUSB0‘. Si vous voulez pousser plus loin, regardez sur le site de gpsd, pour une utilisation normale, vous avez toutes les explications ici. Pour vérifier que votre GPS marche, lancez xgps ou gpsdrive. Si vous voyez une espece de constellation dans xgps représentant les satellites du système GPS ou bien si votre position s’affiche sur la carte de gpsdrive, c’est gagné. Si vous avez un affichage dans xgps mais pas de coordonnées (partie gauche de l’écran), cela signifie que le signal est trop faible. Rapprochez-vous d’une fenêtre ou tâchez d’obtenir une ligne d’horizon plus dégagée. Si vraiment vous n’obtenez rien, lancez gpsd avec ‘gpsd -n -N -D 3 -p /dev/ttyUSB0‘ pour avoir l’affichage des messages reçus et échangés par le récepteur et l’ordinateur, ça peut aider (notamment “satellite data no good” qui signifie que la réception est mauvaise). Ci-dessous, un aperçu de xgps avec une mauvaise réception (”n/a” à gauche de l’écran) et un aperçu de gpsdrive en fonctionnement (moins le bas de l’écran qui indique les coordonnées précises du récepteur). Dernière précision, a priori ce montage est compatible avec Kismet mais je ne l’ai pas testé.


gpsdrive
gpsdrive

MacOSX
MacOSX
Pour MacOSX maintenant. Le plus simple est d’installer le driver pour PL2303 (controleur USB de nombreux récepteurs GPS) depuis le site de Prolific. Ensuite, installez gpsdX, version OSX de gpsd. Lancez le programme appelé ‘gpsdX Config’ et choisissez ‘/dev/tty.usbserial‘, périphérique créé par le driver de Prolific (si votre récepteur USB est bluetooth, pas besoin d’installer le driver de Prolific, sélectionnez juste un des /dev/tty.Bluetooth). Appliquez ce changement et vous avez un serveur gpsd qui tourne sur votre Mac ! Maintenant, pour l’utiliser, deux options : soit gps2geX qui interface gpsd avec Google Earth (même en version gratuite), ou le port pour MacOSX de GpsDrive réalisé par VASS-Softwareentwicklung. Le premier nécessite l’installation de Google Earth au préalable. Ensuite il ne reste plus qu’à installer gps2geX, lancer GE puis gps2geX, cliquer sur “Start gps2geX” et vous voilà avec votre position actuelle (et mise-à-jour régulièrement) dans Google Earth ! L’installation de GpsDrive nécessite l’installation de X11 depuis votre DVD de MacOSX Leopard (ou pas Leopard d’ailleurs). À noter que GpsDrive tourne sur PPC (et donc sur Intel via Rosetta). Le reste se déroule comme sous Ubuntu. Dernière précision, l’utilisation de gpsX est compatible (testé) avec KisMAC (Kismet et KisMAC sont deux outils de visualisation de réseaux WiFi).

P.S. : Pour aller plus loin, OpenStreetMap qui fournira à terme les cartes de gpsdrive et qui réunit une communauté d’utilisateurs façon Wikipedia autour de l’édition d’une carte du monde.

Category: Articles en français, Tech >> Computer | Comments (2)

Latex - How to create a glossary?

To ease the reading of your technical reports, that usually end up being crowded with abbreviations, it’s good to add a glossary to them. Here is an example of how to add a glossary to a LaTeX file. In this case, the glossary chapter is not numbered (\chapter*) but is listed in the table of contents (\addcontentsline{toc}{chapter}{Glossary}).

  1. \makeglossary
  2. \begin{document}
  3.  
  4. This website is done in PHP\glossary{[PHP] PHP Hypertext Preprocessor}.
  5.  
  6. %%%%%%%%%%%
  7. %debut du glossaire%
  8. %%%%%%%%%%%
  9.  
  10. \chapter*{Glossary}\label{glossary}\addcontentsline{toc}{chapter}{Glossary}
  11.  
  12. \begin{itemize}
  13. \input{Glossary}
  14. \end{itemize}
  15. \end{document}

Next is a script you can add in TexShop (MacOSX) to generate the glossary files properly. Click on Macros>Open Macros Editor. Chose “New Item” and copy the script below. You can also associate it to a keyboard shortcut to run it easily after every compilation. To get the glossary in your pdf file, compile your LaTeX files, compile the glossary and recompile your LaTeX files.

  1. –AppleScript direct
  2.  
  3. set fileName to #NAMEPATH#
  4. set n to (number of characters of contents of fileName)
  5. set fileNamequoted to quoted form of fileName
  6. set baseName to do shell script "basename " &amp; fileNamequoted
  7. set m to (number of characters of contents of baseName)
  8. set dirName to quoted form of (characters 1 thru (n-m-1) of fileName as string)
  9.  
  10. set shellScript to "cd " &amp; dirName &amp; ";"
  11. set shellScript to shellScript &amp; "./script.sh;"
  12. do shell script shellScript

Note that the script above requires a file named “script.sh” in the folder containing your .tex files. This file uses a PERL script named “writeglossary.prl” (cf. the end of this post) to create an item list from the glossary data. The entries are then sorted in alphabetical order and deletes the duplicates. Remember to replace “Paper.glo” in the script with ‘Your file’.glo.

  1. #!/bin/tcsh
  2. perl writeglossary.prl Paper.glo > Glossary.tmp
  3. #perl script.pl
  4. perl -e ‘while(<>) {push @lines, $_;}warn "\nSorted $. lines in ascending alphabetical order, ignoring case\n\n";print sort {lc($a) cmp lc($b)}@lines’ Glossary.tmp > Glossary.tex

And here is the file “writeglossary.prl”:

  1. # Simple perl script for converting glossary data (*.glo) files produced by
  2. # Latex and converting them to a form suitable for including
  3. # as a Glossary.tex file in a report.
  4. #
  5. # To use:   perl writeglossary.prl filename.glo > Glossary.tex
  6. # Then, in your Latex report file, set up a "description" environment using \begin{description}
  7. # and use \input{Glossary} to import the formatted glossary items.
  8. # (See me310report.tex for example.)
  9. #
  10. # Started 2 August 2006 -mrc
  11. # Note: Macs and Linux usually have perl installed by default. On Windows you might need
  12. # to install it or else use Visual Basic or simply use find/replace in MS Word to
  13. # accomplish the same string replacements as done by this perl script.
  14.  
  15. ############
  16. # Main loop: keep reading new lines until end of file.
  17. # Next line always goes into $_ and pattern matching is done
  18. # on $_ by default.
  19. line: while (<>) {
  20.  
  21. # Replace any instance of "glossaryentry{" with "item " on every line.
  22. # /g is for global matching (as many times as applies)
  23. s/glossaryentry{/item /g;
  24.  
  25. #Then take what comes before "}" and throw away the rest.
  26. if(/}/){
  27. $_ = $`;
  28. }
  29.  
  30. #Append a newline and print to the output.
  31. print($_,"\n");
  32.  
  33. } # end while(<>)
Category: Articles in English, Tech >> Computer | Leave a comment