Archives de la catégorie Trucs & Astuces

Panic moments: Ubuntu wouldn’t boot properly after upgrade to Xenial

Xenial being released for quite some time now, I decided on a sunny Friday afternoon to do the big jump from Trusty to the latest greatest release. Used to the command line, I launch the "do-release-upgrade" command. 1500+ MB of packets to be downloaded, thousands to be upgraded, some new to be installed and about […]

,

Pas de commentaire

Untabify from the Linux command line

Every now and then, we get some source file that has those nasty relics from a distant path, namely tabs instead of spaces to make indentation. Of course, you can load the affected files one by one in your favorite editor and provided that you can specify some kind of regular expression in a global […]

Pas de commentaire

boost goodie to clamp numbers

How do you clamp a number in a given range in C++ ? Classical way to do it is: double clamped = std::min(maxValue, std::max(minValue, value))double clamped = std::min(maxValue, std::max(minValue, value)) But why repeat this magic formula when boost has clamp() for you ? From now on, do: #include <boost/algorithm/clamp.hpp> double clamped = boost::algorithm::clamp(value, minValue, maxValue)#include […]

,

Pas de commentaire

Namespace, template typedef and operator overloads – The Evil trio

What an unconfortable situation ? I had the following code which would not compile. // Range.h #include &lt;boost/numeric/interval.hpp&gt; #include &lt;iostream&gt; namespace App { template &lt;typename T&gt; using Range = boost::numeric::interval&lt;T&gt;; template &lt;typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const Range&lt;T&gt; &amp;r) { … } } // namespace App     // Filter.cpp #include &quot;Range.h&quot; #include &lt;iostream&gt; namespace […]

Pas de commentaire

Correctly handling attached files with Poco::Net::HTMLForm

I recently had to develop an visualisation application. To make it easier to deploy, I chose to make it a C++ application with embedded web server. In that application, there is a need for the user to submit some data to be analyzed. Users have the choice to submit text directly (filling in a textarea) […]

, , , ,

Pas de commentaire

Moving an object that wraps a vector and an iterator on that vector

I recently stumbled upon code that looked very suspicious to me. Basically, it was a class which amongst other things held a vector and some iterators from that vector. Something like this: struct Wrapper {     typedef std::vector&lt;int&gt; Data;     Data data;     Data::iterator active;     Wrapper() :         data(),         active(data.end())     { } […]

, ,

Pas de commentaire

C++ Thread synchronization pitfall: using a barrier to synchronize a thread start

The context: You want to create a worker thread. Before the main thread goes on, you want to ensure that the worker thread starts. Using a boost::barrier seems like a good idea.

,

Pas de commentaire

Installing Google Play enabled firmware on Arnova 7b G3

Some time ago, our daughter bought an Arnova 7b G3 tablet. Although the device is very well done, its primary disadvantage is that it does not include Google Play. As a consequence, it is only possible to install new applications from the rather limited AppsLib. What she wanted was to be able to install applications […]

, , , , ,

Pas de commentaire

std::unique_ptr, virtual and missing virtual destructor = major pitfall

In our company, the build infrastructure runs unit tests in a valgrind shell, trying to detect memory leaks at the time the unit tests are executed. And every now and then, although our memory allocations are mostly handled through std::unique_ptr or std::shared_ptr, a leak pops up on the radar. And usually with the most useless […]

, ,

Pas de commentaire

Installing Skype 4 on a 64b Linux

It’s so easy they say on the website… Download the .deb and install. But problem: the .deb won’t install since it is meant for i386, not for x64.

, ,

Pas de commentaire