Posts

  • Sort blocks of text in files

    Ever had to sort a file alphabetically, only to realize that you'd have to do it manually because every item that needs to be sorted is spread over more than one line? This just happened when I exported my Gmail contacts to vCard, which it turned out were sorted by formatted name (FN) instead of name (N). The result was the following script, which takes two pattern and some input, and returns the sorted output. The example returned by ./sort_blocks.py --help is exactly the code to re-sort Gmail contacts. I'd love to know if you find any bugs or possible improvements to this script. Enjoy:

  • Range arithmetic in Python

    The XML 1.0 and 1.1 standards define some ranges of Unicode code points which are valid, and some "compatibility characters" which should not be used. CDS Invenio (a FOSS CMS; update: sorry, the link is dead) already has some code to clean up text to remove invalid characters, but it doesn't remove the compatibility characters. Using the existing code for HTML 4.01 made the W3C Markup Validation Service complain, so I wanted to exclude the compatibility character ranges from the valid ranges, and get the most concise hexadecimal ranges corresponding to the resulting set to plug into a Python regular expression. Here's the resultingsloppy and ugly code (I'll post updated code and/or a link to the source repository if this is included at some point):

  • Firefox profile folder cleanup script

    Here's a simple script which can be useful if you want to version control the Firefox profile folder, or just to keep it slim. Please see the embedded documentation for more information.

  • LHC beam again

    From the LHC operations web site, pages "LHC1" and "LHC3", taken as soon as the beam completed a round in the accelerator. See also the log book (Update: sorry, the link is dead) and the CMS e-commentary (Update: sorry, the link is dead).LHC beam 1st round

  • N-way Git synchronization with extra cheese

  • CERN logo in SVG

    Just putting out my attempt to create a minimal SVG image for the CERN logo:

  • Unit testing Python + MySQLdb warnings

    There seems to be several methods out there, based on elevating warnings to errors using warnings.simplefilter (Update: sorry, the link is dead). Here's another method, based on recording warnings in a variable (Update: sorry, the link is dead), and checking that the last one is a MySQLdb.Warning. Hopefully to be integrated in INSPIRE.

  • Graphviz dot mode for Emacs patch

    This just modifies the code to support paths with spaces when compiling the dot files.

  • Add namespace prefix to XML tags in Vim

    It's not perfect, but it works with tags that contain just a-z and dashes (the \([a-z-]*\) part):

    :%s/<\(\/\?\)\([a-z-]*\)\(\s\|>\)/<\1namespace:\2\3/gc
  • Moving from France to Switzerland

    There's quite a bit of paperwork involved when moving from France to Switzerland. This is a rough account of what happened after the housing agent called to say we had been selected to get an apartment. It might be useful to anyone considering, or in the process of, moving to Switzerland from abroad. However, it's by no means a complete account, and you should always check with authorities or others who have done the same if in doubt.