Making clang default compiler in Ubuntu

I recently upgraded my Ubuntu 16.04 LTS to a pre-release of Ubuntu 17.10 since it comes with recent compilers. The clang compilers currently create faster binaries than gcc does. Also I wanted to use latest C++ features since I started playing around with libint (electronic integrals library) again.

With a new compiler, I want to be able to easily switch back. Here’s what worked for me:


sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-5.0 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-5.0 100

C#: Finding consecutive list items violating an upper or lower limit

Here’s some code I have written today to find segments of a list that violate upper or lower limits. The minimum size is given as a parameter.

I know there are more elegant ways to do this, but the scripting language that I used features only a subset of C#, that is why I had to keep it simple, e.g. without Predicate.

[code]
var sequence = [0.25,0.5,0.5,0.5,0.7,0.8,0.7,0.9,0.5,0.5,0.8,0.8,0.5,0.5,0.65,0.65,0.65,0.65,0.65,0.65,0.65];
double lowerLimit = 0.1;
double upperLimit = 0.6;
int minWindowLength = 3;

// return type is a list of lists
var windows = [[0.0]];
windows.Clear();

int consec = 0;
int index = 0;

while (index < sequence.Count){

// store segments here
var window = new System.Collections.Generic.List<double>();

while ((index < sequence.Count) && (sequence[index] > upperLimit || sequence[index] < lowerLimit)) {
window.Add(sequence[index]);
consec = consec + 1;
index = index +1;
}

if (consec > minWindowLength) {
windows.Add(window);
}

window = new System.Collections.Generic.List<double>();
consec = 0;

index = index+1;
}

return windows;
[/code]

Converting Microsoft Word Files (doc, docx) to reStructuredText (rst)

This article describes how to convert Microsoft Word documents to reStructuredText. Everything should be done within a temporary directory with simplified filenames. So let’s assume you want to convert ‘am.docx’ to reStructuredText. The Word document can contain images.
You need:
A few simple steps:
  1. On the command line (either the old cmd or the PowerShell) go to the temporary directory that contains the Word document (e.g. C:\temp):
    cd c:\temp
  2. Convert ‘am.docx’ to ‘am.rst’ using pandoc
    pandoc.exe -f docx am.docx -t rst -o am.rst
  3. Extract the media files (e.g. images) from the Word document
    unzip .\am.docx

    and move it to current working directory

    mv .\word\media .
  4. All image files should be in the same file format, so convert eml and gif files to png.
    cd media

    to jump into the directory

    dir (to list all files)

    a) Either by hand:

    convert .\image2.gif .\image2.png
    convert .\image1.emf .\image1.png

    b) Or automatically by using mogrify (also part of ImageMagick):

    mogrify.exe -format png *.emf
    mogrify.exe -format png *.gif

    And clean up:

  5. rm *.gif
    rm *.emf
  6. Do not forget to search and replace .emf and .gif with .png in the .rst file with the editor of your choice (gvim or notepad++)
  7. Check the build by creating a quick Sphinx:
    run sphinx-quickstart (and follow the instructions)
    copy the file over the main doc in the source dir
    copy the media folder to source
    run “make.bat html” to create the a website and check the result.