I officially hate WordPress

9 septembre 2014

I have some text that I want to paste verbatim (excerpt from a manpage, and some code) and it’s apparently impossible to get that into this blog. I pasted the content, clicked on « b-quote » (for the manpage) and « code » (for the code) and what I get is below. A huge messed.

Libre office can convert documents from one format to another from command line. Quoting the manpage :

–convert-to output_file_extension[:output_filter_name] [–outdir output_dir] file…
Batch converts files. If –outdir is not specified then the current working directory is used as the output directory for the converted files.


–convert-to pdf *.doc

Converts all .doc files to PDFs.

–convert-to pdf:writer_pdf_Export –outdir /home/user *.doc

Converts all .doc files to PDFs using the settings in the Writer PDF export dialog and saving them in /home/user.

The problem is that the list of these filters does not seem to be easily available. However, on http://permalink.gmane.org/gmane.comp.documentfoundation.libreoffice.user/15226 there is a script which does exactly that : list all filters available in your Libre Office.

For convenience, and because the formatting of the macro on the mailing list was a little damaged, here it is :

Sub Main
oFF = createUnoService( "com.sun.star.document.FilterFactory" )
oFilterNames = oFF.getElementNames()

' Now print the filter names.
' For i = LBound( oFilterNames ) To UBound( oFilterNames )
' Print oFilterNames(i)
' Next

' Create a Writer doc and save the filter names to it.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, Array() )
oText = oDoc.getText()
oCursor = oText.createTextCursor()
oCursor.gotoEnd( False )

oText.insertString( oCursor, "Filter Names", False )
oCursor.ParaStyleName = "Heading 1"
InsertParaBreak( oText, oCursor )
' oCursor.ParaStyleName = "Default"
InsertParaBreak( oText, oCursor )

' Print the filter names into a Writer document.
For i = LBound( oFilterNames ) To UBound( oFilterNames )
oText.insertString( oCursor, oFilterNames(i), False )
InsertLineBreak( oText, oCursor )
InsertParaBreak( oText, oCursor )

InsertParaBreak( oText, oCursor )
oText.insertString( oCursor, "Filter Names and their Properties", False )
oCursor.ParaStyleName = "Heading 1"
InsertParaBreak( oText, oCursor )
' oCursor.ParaStyleName = "Default"

' Tab stops at:
' 0.25 inch (2.54 cm x 0.25)
' 0.50 inch (2.54 cm x 0.50)
' 2.00 inch (2.54 cm x 2.00)
oCursor.ParaTabStops = Array(_
MakeTabStop( 2540 * 0.25 ),_
MakeTabStop( 2540 * 0.50 ),_
MakeTabStop( 2540 * 2.00 ) )

' Print the filter names and their parameters.
For i = LBound( oFilterNames ) To UBound( oFilterNames )
InsertParaBreak( oText, oCursor )

cFilterName = oFilterNames(i)
aFilterProps = oFF.getByName( cFilterName )

oText.insertString( oCursor, cFilterName, False )

For j = LBound( aFilterProps ) To UBound( aFilterProps )
oFilterProp = aFilterProps(j)

InsertLineBreak( oText, oCursor )
oText.insertString( oCursor, CHR(9)+oFilterProp.Name, False )

nFilterPropValueVarType = VarType( oFilterProp.Value )
If nFilterPropValueVarType = 8201 Then
' VarType 8201 means a sequence of PropertyValue's.
oFilterPropNames = oFilterProp.Value
For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
InsertLineBreak( oText, oCursor )
oText.insertString( oCursor,CHR(9)+CHR(9)+oFilterPropNames(k).Name+CHR(9)+CSTR(oFilterPropNames(k).Value),False )
Next k
ElseIf nFilterPropValueVarType = 8200 Then
' VarType 8200 means a sequence of Strings.
oFilterPropNames = oFilterProp.Value
For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
InsertLineBreak( oText, oCursor )
oText.insertString( oCursor,CHR(9)+CHR(9)+oFilterPropNames(k), False )
Next k
ElseIf nFilterPropValueVarType > 1 And nFilterPropValueVarType <= 12 Then
oText.insertString( oCursor,CHR(9)+CSTR(oFilterProp.Value), False )
oText.insertString( oCursor, CHR(9)+"?? unknown type ?? - "+CSTR(nFilterPropValueVarType), False )
Next j

InsertParaBreak( oText, oCursor )
Next i

InsertParaBreak( oText, oCursor )
End Sub

Sub InsertLineBreak( oText, oCursor )
oText.insertControlCharacter( oCursor,com.sun.star.text.ControlCharacter.LINE_BREAK, False )
End Sub

Sub InsertParaBreak( oText, oCursor )
oText.insertControlCharacter( oCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
End Sub

' Create and return a tab stop.
' An array of what this function returns, is used
' to set the tab stops of a paragraph.
' Parameters....
' nPosition - position in tab stop, in 1000'th of cm.
' nAlign - optional, if specified, must be one of...
' com.sun.star.style.TabAlign.LEFT = 0
' com.sun.star.style.TabAlign.CENTER = 1
' com.sun.star.style.TabAlign.RIGHT = 2
' com.sun.star.style.TabAlign.DECIMAL = 3
' com.sun.star.style.TabAlign.DEFAULT = 4
' cDecimalChar - optional, if specified, only applies to a DECIMAL tab stop,
' and specified the character which is recognized as
' the decimal point separator.
' cFillChar - optional, if specified, specifies the char that fills the space
' between tab stops.
Function MakeTabStop( ByVal nPosition As Long,_
Optional nAlign,_
Optional cDecimalChar,_
Optional cFillChar _
) As com.sun.star.style.TabStop
If IsMissing( nAlign ) Then
nAlign = com.sun.star.style.TabAlign.LEFT

oTabStop = createUnoStruct( "com.sun.star.style.TabStop" )

oTabStop.Position = nPosition
oTabStop.Alignment = nAlign

If Not IsMissing( cDecimalChar ) Then
oTabStop.DecimalChar = cDecimalChar
If Not IsMissing( cFillChar ) Then
oTabStop.FillChar = cFillChar

MakeTabStop() = oTabStop
End Function


« Nouveaux remèdes et maladies d’actualité »

28 avril 2014

En lisant l’entrée du TLFi concernant l’énurésie, je lis :

Le docteur Vincendeau, de Bordeaux, nous parle de « l’action remarquable de la vitamine E » (…) L’énurésie infantile peut aussi être un succès de ce traitement (R. Schwartz, Nouv. remèdes et mal. act.,1965, p. 67).

Citant ce passage, je me tourne vers ma pharmacienne qui hausse virtuellement des épaules sans sourciller. Curieux, je vais alors pour en savoir plus sur la source. Je veux d’abord savoir à quoi correspond « Nouv. remèdes et mal. act. » qui semble être un journal puisqu’il est sourcé en abrégé (les noms de journaux sont toujours abrégés).

En fait, c’est simplement un livre dont l’auteur est un certain Robert Schwartz : http://www.worldcat.org/search?q=no:14485884. Ce livre ne semble pas très souvent référencé, mais il apparait dans un nombre invraisemblable d’entrées du TLFi. L’auteur, quant à lui, ne semble pas être souvent référencé par Google non plus.

La recherche

« nouv. remèdes et mal. act » site:cnrtl.fr

retourne pourtant « Page 2 sur environ 14 200 résultats (0,15 secondes) »

La question est donc : Comment en est il venu à être la source pour tant d’entrées du TLFi ?

View split on right/left : tile without compiz

10 janvier 2014

My aim was to have keybinding to split the view of my desktop into right/left without Compiz (which is how I discovered this behaviour, but I don’t have that on my desktop computer). Searching on the net for this, I came accross this: http://unix.stackexchange.com/a/17983

While trying to understand it, I rewrote part of it and simplified a bit (it parses the output of xprop to get the active window, which is useless at least for my version of wmctrl):

#!/usr/bin/env bash
# $1 ... top | bottom | left | right

xprop -root |
    sed -rne 's/^_NET_WORKAREA\(CARDINAL\) = ([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+).*/\1 \2 \3 \4/p' |
        # (x,y) is topleft corner, (w,h) is space (width, height)
        # available. for me x = 0 but y = 25 because of the gnome
        # menubar which sticks to the top.
        read x y w h
        # Now decide where you want your active window:
        case "$1" in
            top    ) ((h=h/2));;
            bottom ) ((h=h/2));((y=y+h));;
            left   ) ((w=w/2));;
            right  ) ((w=w/2));((x=x+w));;
        # unmaximize, otherwise nothing happens.
        wmctrl -r ':ACTIVE:' -b remove,maximized_vert,maximized_horz
        # change geometry:
        wmctrl -r ':ACTIVE:' -e 0,$x,$y,$w,$h

Downloading full resolution images from Wikipedia

3 janvier 2014

Here’s a snippet I used to download some images from wikipedia.

perl younameit.pl WikipediaFilePage LocalName

where WikipediaFilePage is an url like « https://en.wikipedia.org/wiki/File:Bournemouth,_The_Square.jpg &raquo;
which describes an image that you want to download at full res, and LocalName is the name you want to give it on your harddisk. You can give as many « WikipediaFilePage LocalName » pairs as you like.

– Any error will stop everything (in case there are multiples pairs on the command line).
– There’s a huge memory leak (thanks to feldspath for deeply analyzing my code :D)
– This list is very much incomplete.

#!/usr/bin/perl -w
use WWW::Mechanize;
use strict;
use HTML::TreeBuilder;
binmode STDOUT, ":utf8"; # spit utf8 to terminal
use utf8; # allow for utf8 inside the code.

my $url;
 while (defined($url = shift)) {
 my $mech = WWW::Mechanize->new;
 my $tree = HTML::TreeBuilder->new;
 my $tempfile = shift; ## user supplied

print "Downloading $url...";
 $mech->get($url) and print "done !\n" or die;
 # real image:
 $url = $tree->look_down(class=>'fullImageLink')->look_down(_tag => "a")->attr('href');

print "Downloading $url to $tempfile...";
 $mech->get($url, ':content_file' => $tempfile) and print "done !\n" or die;


Firefox 4 : Ctrl+Q ne produit pas d’avertissement.

23 mai 2011

Quand on ferme une fenêtre de Firefox 4 (Alt+F4 ou via l’interface graphique avec la petite croix), on est averti si on s’apprête à fermer plein de choses. Mais si on ferme l’application (Ctrl+Q ou Fichier => Quitter), il n’y a plus d’avertissement demandant si on veut « sauver la session ». La raison est simple : quand on ferme l’application, Firefox 4 la sauve automatiquement (et on peut la récupérer via Historique => Restaurer la session précédente).

Pour rétablir l’avertissement, fort simple :

  • Aller dans about:config (lire l’avertissement et confirmer)
  • Taper showquit dans la barre « Filtre », et double-cliquer sur browser.showQuitWarning pour que sa valeur devienne « true ».