MacBook Pro and the SMC cure

2017-07-11  |   |  apple   Mac OS X  

The physical parts of your MacBook (fans, ports etc) behaves erratically? I might have a cure.

A story of crashes

My MacBook Pro was getting on my nerves lately. When plugged to my Thunderbolt dock and thus my external monitor, my laptop would crash randomly. Sometimes, once every 2 weeks, sometimes several times a day. I tried many things, like not starting all of the utilities one usually uses to verify that they were not involved but I could not find a culprit.

Then one day, I saw that one of my Thunderbolt port would not accept my Thunderbolt-Ethernet adaptor while the other did (the connection did not show up). I was convinced my laptop had a faulty hardware and needed repair.

System Management Controller to the rescue

So I called Apple and the support person told me to try something first: reset the SMC (System Management Controller) by pressing Shift+Control+Option on the left side and the power button for 10 seconds while starting the computer (after a full shutdown) - full procedure here.

And voila, all my problems are gone.

What is SMC anyways?

It turns out that there is a chip that manages a lot of hardware inside your laptop: fans, LEDs, IO ports, external displays, battery, etc. So slapping that chip on the face (figuratively) might make a lot of things go better.

Using vim and Evernote

2017-03-28  |   |  tool  

I like Evernote because all my notes are in a single place and I can access it from everywhere (desktop, phone). I use it very much as my GTD reference material. But the editor is subpar compared to vim though - what isn't?


I found a way to edit my Evernote notes in vim. I use Geeknote and specifically this fork.

git clone
python2 build
pip2 install --upgrade .

(I forgot to do the last line and it created a lot of pains. I also tried the brew formulae but did not work for me.)

You need to log in and select vim as your editor

geeknote login
geeknote settings --editor vim

And from there, you're good to go to edit notes

geeknote edit --note "Moon project meeting"

And boom. I personally can now edit my notes in Asciidoc markup and be happy :)


There is a more advanced integration with vim: vim-geeknote. I am not sure I like it but I'm exploring it. It gives a navigation panel inside vim.

Make sure to set it to use the plain format and not the markdown one. Otherwise, all your notes will look weird back in Evernote.

" in your vim.rc
" Geeknote options
let g:GeeknoteFormat="plain"
" filter the relevent notebooks
let g:GeeknoteNotebookFilters=[ "my notebook" ]
" do syntax highlighting with asciidoc syntax
autocmd FileType geeknote set syntax=asciidoc

Perfect solution / future

I initially thought about keeping all my notes in sync in a directory with each note exported as Asciidoc, but I found geeknote before going in development tunnel.

I don't think I really need the directory sync but I would like to be able to have the note as a file that I can render via Asciidoctor (e.g. asciidoctor.js).

Embedding Vim options in Markdown

2017-03-06  |   |  tool  

I've been wrestling with an issue for quite a while: embed vim options into a Markdown file. I finally found a solution.


You can customize the options set when opening a specific file in Vim. This is pretty handy when you want to customize things like tab vs spaces or the language to spellcheck with.

This is typically done by adding some vim incantation as a comment in the file.

// vim: set softtabstop=2 shiftwidth=2 expandtab:
public class JavaClassExample {
  public String name;

Vim options in Markdown

I've been really struggling to get this working on Markdown because unfortunately Markdown does not have a comment syntax. That's until I remembered that Markdown defaults to HTML the minutes it does not know how to express things. <!-- --> to the rescue! Without further due, an example:

# Un exemple en Markdown

<!-- ask vim to use French to spellcheck -->
<!-- vim:set spelllang=fr : -->

<!-- ask vim to use 2 spaces for indent
     (a blog does not have lots of space) -->
<!-- vim: set softtabstop=2 shiftwidth=2 expandtab: -->

Ceci est un test montrant la validation orthographique en Français.

## Et ça marche ?

Carrément !

    public class JavaClassExample {
      public String name;


Start IntelliJ IDEA from the command line

2017-02-27  |   |  java   ide   tool  

You can start IntelliJ IDEA from the command line which is handy when you live in a terminal like me. But you need to enable that feature.

Open IntelliJ IDEA, go to Tools->Create Command-Line Launcher... and optionally adjust the location and name of the script that will start IntelliJ IDEA. Voilà! Now from your command line, you can type:

  • idea . to open the project in the current directory
  • idea pom.xml to import the Maven project
  • idea diff <left> <right> to launch the diff tool.

The generated script has an annoying flaw though, it does reference your preference and cache directories in a hard coded fashion. And for some reason the IntelliJ folks embed the version number in these directories (e.g. IdeaIC2016.2) That's annoying as it will likely break the minute you move to another (major?) version.

Antonio has a solution for that which is a simpler and more forgiving script in good anti-fragile fashion. The script is not generic and only runs for macOS.


# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`

# were we given a directory?
if [ -d "$1" ]; then
#  echo "checking for things in the working dir given"
  wd=`ls -1d "$1" | head -n1`

# were we given a file?
if [ -f "$1" ]; then
#  echo "opening '$1'"
  open -a "$IDEA" "$1"
    # let's check for stuff in our working directory.
    pushd $wd > /dev/null

    # does our working dir have an .idea directory?
    if [ -d ".idea" ]; then
#      echo "opening via the .idea dir"
      open -a "$IDEA" .

    # is there an IDEA project file?
    elif [ -f *.ipr ]; then
#      echo "opening via the project file"
      open -a "$IDEA" `ls -1d *.ipr | head -n1`

    # Is there a pom.xml?
    elif [ -f pom.xml ]; then
#      echo "importing from pom"
      open -a "$IDEA" "pom.xml"

    # can't do anything smart; just open IDEA
#      echo 'cbf'
      open "$IDEA"

    popd > /dev/null

The GitHub gist version of this script. It does not offer the call to IDEA's diff though. I'm from an era where we did resolve > based diff conflicts in Notepad so that does not bother me much.

I think I'll go for Antonio's solution, that will avoid some nasty WTF moments when the preference directory moves and I will have forgotten all of this.

Retraite, baby boomers et pyramide des ages

2017-01-18  |   |  economy   francais  

Je n'avais jamais bien compris pourquoi les baby boomers étaient un tel problème pour les retraites des plus jeunes. Mon hypothèse était que la retraite des baby boomers est payée par des actifs dans un système à répartition comme en France. Donc le moment difficile c'est le moment de vie active où la pression de paiement est la plus forte. Mais ces baby boomers, ils vont bien finir par mourir, et donc le système reviendra à la normale. Ce raisonnement est correct mais il y a plusieurs facteurs aggravants.

Premièrement, le phénomène de baby boom est plus long que ce que je pensais. Il correspond aux naissances de 1945 à 1975 et à un surplus de naissance de ~ 20-25% par an par rapport à la moyenne des naissances post 1975 (à la louche). Donc c'est un gros morceau à la fois dans le temps et dans le volume supplémentaire par an. Les baby boomers ont commencé à entrer en retraite il y à 5 ans et cela va se poursuivre quasi jusqu'à ce que moi je rentre en retraite (je ne suis pas né au meilleur moment apparemment).

Pyramide des ages et baby boomers

Deuxièmement, ce phénomène n'est pas compensé (ni aggravé d'ailleurs) par les naissances et l'immigration. Pour faire simple, les 1,95 enfants par femme et la légère immigration que l'on a devrait suffire à garder les tranches d'age stables. Cela donne une base rectangulaire à la pyramide des ages. Cela dit si on faisait un peu plus de bébés ou si on accueillait un peu plus d'immigration, ma retraite se porterait mieux, CQFD.

Et évidemment, les gens meurent plus tard. Merci aux progrès de médecine et de nutrition.

Donc on se retrouvera avec une pyramide en forme de gros rectangle avec un petit chapeau au dessus (appelé cylindre pour une raison qui m'échappe).

La pyramide des ages du futur

La part des personnes agées dans la population va passer de 20% à 30-32% en 2035 pour se stabiliser ensuite d'après l'INSEE. Elle devrait baisser légèrement une fois les baby boomers tous partis remplir la pyramide inversée du ciel (c'est beau non ?). Le chapeau devrait se réduire un peu en largeur donc. Mais ça c'est pour après 2060.

Vu que je suis né juste après le baby boom, j'ai globalement tout perdu (je paye et je ne serai pas payé). Sauf si la France se met à faire beaucoup de bébés (l'immigration n'étant pas très tendance en ce moment). Il fait froid, lancez vous !

Course on inverted index

2017-01-17  |   |  computer science   conference  

I gave a three hours course on inverted index to students from Telecom SudParis an engineering school here in... Paris :) It was fun to refresh my knowledge on all the fundamental structures that make Lucene what it is.

I covered quite some ground for this three hours course (a bit to much to be honest). Amongst other things: b-tree, inverted index, how analyzers and filters do most of the magic (synonym, n-gram, phonetic approximation, stemming, etc.), how fuzzy search work in Lucene (state machine based), scoring, log-structured merge and the actual physical representation of a Lucene index and a few of the tricks the Lucene developers came up with. My list of reference link is pretty rich too.

Without further ado, here is the presentation. I tend to be sparse on my slides so make sure to press s to see the speaker notes. The presentation is released under Creative Commons and sources are on GitHub.

It is a first revision and can definitely benefit from a few improvements but there is only so much time per day :)

Log-Structured Merge Tree with level-based compaction

2017-01-10  |   |  computer science  

It is surprisingly hard to find a good explanation to level-based compaction of a Log-Structured Merge Tree. It turns out that it is best explained in LevelDB's documentation. You can find the (html) details here.

This blog post is a collection of key concepts I did not grasp initially. Sort of a mental note for me. It should bring you nicely from standard size-based compaction LSM to level-based compaction.

Levelled LSM structures are useful as they limit greatly the number of files to access when reading a given key. nbrOfLevel0Files + (n-1) where n is the number of levels.

You still have levels but level 1 and above have different behaviors:

  • there is the in memory level + append only log (non ordered)
  • there is level 0 which behaves like a normal LSM level (each file is ordered but has overlapping keys)
  • level 1 and above have files containing non overlapping keys

I call segment, a given file at a LSM level (containing ordered keys), it is called sstable usually. Why do I call it segment? I come from Lucene and I have read Dune and know of sandworms. Plus segment is a much nicer word than sstable :)

The non-overlapping ranges for a given level L are not fixed in stone and are recomputed each time a compaction from level L to level L+1 occurs. Big ahah moment for me.

When a level L is merged into level L+1 (for L >= 1), one segment of L and all overlapping segments of L+1 are read. New segments are created at level L+1 from this data and a new level L+1 is created from these new segments and the existing non-overlapping ones. When compaction is done, the manifest (reference of segments) is updated and old segments are deleted. From that data, new segments at a given level are created based on:

  • size (e.g. every 2 MB)
  • as soon as the key range of a given segment overlaps with more than 10 segments at L+2

Tombstones are kept around until the last level (to make sure we hide the possibly older values in higher levels). They claim that they remove tombstones for a given key if no higher level has a segment with whose range overlaps the current key but that looks like a minor optimisation.

In LevelDB, the max size of a level is 10^L MB (e.g. 10 MB for 1, 100MB for 2 etc). Levels do increase in size exponentially though each segment is of fixed size (at least not exploding).

All this compaction only involves sequential reads and sequential writes (when done right).

I'm well aware that many improvements have been built atop this initial approach but they all rely on you understanding this first cornerstone improvement :)

Cool stuff.

Devoxx CfP - the art of tricking yourself

2017-01-05  |   |  conference  

I noticed that the Devoxx France call for paper (CfP) application was influencing my votes. Sneaky one!

Jeff Atwood's tweet made me rethink about something I noticed

When we designed Stack Overflow I intentionally put author at bottom: you should read the actual content before "deciding" credibility

In the CfP, you review a proposal, you first see:

  • the title and type of proposal (conference, Tools in Action etc)
  • then the abstract
  • then the private message to the committee

At this stage, you will have to scroll down to see more, especially if you are reviewing on a tablet like I do. Your brain will make a pre-judgement based on the title and abstract like any attendee. It will later absorb the private message but things are already too late (kind of).

It's only after scrolling that you will see who the person is and what qualification he or she has.

I don't know if Nicolas did it on purpose but it has brilliant side effects:

  • You will value good titles and good abstracts over good back channel info
  • You will alter your judgment based on the person qualification and fame last. Congnitive research seems to indicate that your reptilian judgement favors the first data much more.
  • This is a nice trick to favor subjects over rock stars

What's even more brilliant is that even if I'm concious of this, the trick still works :)

A good presentation is a mix of good subject, good content and good presenter. I do think good presenters are key but besides fame or first hand experience, it is the hardest to judge. What I love about the way the CfP app does it, is that it is a harder process for me to either:

  • overcome a just ok proposal from a famous speaker
  • overcome a good proposal from a unknown quantity speaker

I still do alter my note of course based on who proposes: that's part of the magic equation. But certainly less than if the name was first.

Now I get how Devoxx France "encourages" new speakers.

Why do we have corporate income tax anyways?

2016-08-30  |   |  economy  

There is a lot being written about corporate tax optimisation/evasion these days both in Europe and in the US. This begs for a more general question, why do we tax corporate profits? I had the debate with a friend this summer and led me to research the topic.

There is a very interesting paper on this subject as well as an analysis of the distortion of corporate tax. Here is my summary.

Why (not) a corporate income tax

The main arguments - to me - in favor or against corporate income tax are summarized in the following paragraphs.

A corporation benefits from common infrastructures (highways, social security etc) and thus must pay its due to Society.

However a corporation is (in the end) always owned by individuals which themselves do pay taxes to finance common infrastructures. This is argued by some as leading to a double taxation.

A corporation can be owned by foreign investors: better tax these guys via corporate taxes rather than the folks that actually vote for us.

A corporate tax leads to some sort of pre-tax of the foreign investor by virtue of lesser dividends.

Individuals would feel it to be unfair if they were to pay for all taxes while corporations are making plenty. Of course, individuals do indeed pay it all in the end whether they see it or not but it looks like it's a hard notion to grasp for most.

A corporation bringing the benefits from a foreign subsidiary can deduct from its dividend tax the actual income tax it paid in the subsidiary's country. This essentially erase the foreign income tax assuming the rate is lower than the domestic dividend tax rate. These treaties are here to avoid double taxation and lessen the burden of an income tax.

Without corporate income tax, personal income tax diminishes as individuals find ways to "incorporate" their revenues to avoid taxation.

And of course the cynical view is that governments are addicted to spending and they need more fresh cash than a junkie needs dope (this argument is not in the paper for obvious reasons).

What distortions does it cause

Again this is a personal cherry picking from the paper. What is interesting is that this paper is based mostly on studies of the EU, not the US as it is often the case.

Small companies are often offered lower tax rates, to compensate for market failures. It would be better to use a separate explicit mechanism (e.g. direct aids) to compensate for them. As it is, different tax rate brackets create a disincentive to grow.

A European study shows that the more corporate income tax, the lesser wages are: for every additional euro of corporate income tax, wages are reduced by 0,92 in the long run. Income tax is not good for your salary apparently :)

As explained in the previous section, a corporate income tax lower than the personal income tax leads to a shift from personal to corporate taxes. People (e.g. entrepreneurs) optimise and "incorporate" their income. This is one of the few arguments that encourages a higher income tax.

Income tax influences where an international company opens foreign subsidiaries (a 1% point income tax increase, decreases the change of the subsidiary being opened by 3,96%). Ouch!

Same for foreign investment: a 1% point tax increase, decreases foreign investment by 2.9%.

And finally profit shifting. Profit shifting is what big international companies are accused of these days (Apple, Google, Starbucks, Ikea etc). One study estimates that due to this phenomenon, a 1% point increase in tax rate leads to a loss of 17,2% of the planned extra tax collection. I'm personally skeptical of the averages. We cannot consider this phenomenon by mean nor median: I imagine a company engaging in such activity would do it in an all or nothing fashion.

What's the take away?

Tax is hard, you touch one button and unexpected things move all over the place. Be careful of tax that go to 11, you might become deaf... and sterile ;) More seriously, this paper has been hard to find but knowing about all this will make you a better citizen.

Read the paper, there is a lot more to it

I had to summarize, cherry pick and cut corners to keep this entry short. Go read the paper which is easy to read (except in some specific areas), goes in greater details and cite all of its sources. And above all it is very interesting !

I put a copy of this paper here since it disappeared from its original location. This paper is copyright the European Commission and written by the staff of the European Commission's Directorate-General for Taxation and Customs Union (Gaëtan Nicodème in particular).

Homebrew formulae for Mutt with sidebar and trash patches

2016-03-15  |   |  Mac OS X   tool  

Homebrew's Mutt formulae is in a bit of a disarray. I can't blame them as Mutt has a bunch of not quite maintained patches not quite fully compatible with one another.

The problem is that some of these patches are very very useful. I have created a tap to maintain Mutt with the two key patches I use:

  • sidebar
  • trash

At the time of writing, it uses Mutt 1.5.24 but I might update it. To use the formulae, do:

brew tap emmanuelbernard/mutt
brew install emmanuelbernard/mutt/mutt

// or alternatively

brew install

I personally build them with the following options

brew install emmanuelbernard/mutt/mutt --with-sidebar-patch --with-trash-patch --with-gpgme --with-s-lang

s-lang supposedly has better support for color schemes like Solarized.

You can find the code at

Name: Emmanuel Bernard
Bio tags: French, Open Source actor, Hibernate, (No)SQL, JCP, JBoss, Snowboard, Economy
Employer: JBoss by Red Hat
Resume: LinkedIn
Team blog:
Personal blog: No relation to
Microblog: Twitter, Google+
Geoloc: Paris, France