<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Val Markovic</title>
    <link href="http://val.markovic.io/articles/atom.xml" rel="self" />
    <link href="http://val.markovic.io" />
    <id>http://val.markovic.io/articles/atom.xml</id>
    <updated>2015-08-03T15:52:25Z</updated>

            <entry>
        <title type="html">Picture Commander: Choose Images for Remote Screens</title>
        <author><name>Val Markovic</name></author>
        <link href="http://val.markovic.io/articles/picture-commander-choose-images-for-remote-screens"/>
        <updated>2014-11-08T22:00:00Z</updated>
        <published>2014-11-08T22:00:00Z</published>
        <summary>Choose an image from a gallery on one device and have it automatically pushed to a remote device screen.</summary>>

        <id>http://val.markovic.io/articles/picture-commander-choose-images-for-remote-screens</id>

        <content type="html">
<![CDATA[
<p><a href="https://github.com/Valloric/picture-commander">Picture Commander</a> provides a way to select an image from a gallery
on one device and have that image automatically displayed on the screen of a
remote device. No fancy apps are necessary, this is completely implemented with
modern web technology (hooray for <a href="http://dev.w3.org/html5/eventsource/">Server-Sent Events</a>). All you need is a&nbsp;browser.</p>
<p><a href="//i.imgur.com/VHwKSt0.png"><img alt="Picture Commander screenshot" src="//i.imgur.com/VHwKSt0l.png" /></a></p>
<p>The way it works is the following: there&#8217;s one &#8220;admin&#8221; view (<code class="None"><span class="o">/</span><span class="n">gallery</span></code> handler)
and one &#8220;display&#8221; view (<code class="None"><span class="o">/</span><span class="n">viewer</span></code> handler). Clicking on images in the gallery
automatically replaces the displayed image on viewer screens (no page refresh
needed). You provide a path to an image folder on server startup. The server
will recursively collect all images in that folder hierarchy and present them in
the&nbsp;gallery.</p>
<p>This is super-useful when projecting one browser tab to a different screen with
say a <a href="http://www.google.com/chrome/devices/chromecast/">Chromecast</a> since the gallery tab can then control the projected one. You
can also have multiple viewer devices/browsers connected at the same time and
they&#8217;ll all be&nbsp;updated.</p>
<p>Example of running the&nbsp;server:</p>
<pre><code class="bash">./server.py --images_folder<span class="o">=</span>./test_images --port<span class="o">=</span>8080 --host<span class="o">=</span>localhost</code></pre>

<p>Then go to <a href="http://localhost:8080/gallery"><code class="None"><span class="nl">http:</span><span class="c1">//localhost:8080/gallery</span></code></a> for
the admin view and to
<a href="http://localhost:8080/viewer"><code class="None"><span class="nl">http:</span><span class="c1">//localhost:8080/viewer</span></code></a> for the viewer
page. Tested with latest Chrome, Firefox and Safari across desktop, Nexus 5/7/9
and&nbsp;iPad.</p>
<p>I need this for running my local <em>Dungeons <span class="amp">&amp;</span> Dragons</em> game; as a <span class="caps">DM</span>, I want to
show the players pictures of maps, characters and other stuff without exposing
filenames or thumbnails of pictures that they aren&#8217;t supposed to see yet. I was
surprised to find that there was no simple and easy way to do this so I wrote
Picture&nbsp;Commander.</p>
<p>Picture Commander is free and open-source under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache v2
License</a>.&nbsp;Enjoy!</p>
]]>
        </content>
    </entry>
                <entry>
        <title type="html">YouCompleteMe as a Server</title>
        <author><name>Val Markovic</name></author>
        <link href="http://val.markovic.io/articles/youcompleteme-as-a-server"/>
        <updated>2014-08-04T17:00:00Z</updated>
        <published>2014-08-04T17:00:00Z</published>
        <summary>Why tie down YCM to Vim? Everyone deserves good code-completion, no matter which editor they use.</summary>>

        <id>http://val.markovic.io/articles/youcompleteme-as-a-server</id>

        <content type="html">
<![CDATA[
<p>The <a href="http://valloric.github.io/YouCompleteMe/">YouCompleteMe</a> (<span class="caps">YCM</span>) code-completion plugin for Vim has been a resounding
success. It&#8217;s one of the most popular Vim plugins, if not <em>the</em> most popular
one.<sup id="fnref:popular"><a class="footnote-ref" href="#fn:popular" rel="footnote">1</a></sup> The main <span class="caps">YCM</span> logic is now available as <a href="https://github.com/Valloric/ycmd">ycmd</a>, an independent
<span class="caps">HTTP</span>+<span class="caps">JSON</span> server. Client plugins for different editors can easily be&nbsp;written.</p>
<p>Work on splitting <span class="caps">YCM</span> into a client-server model started about a year ago. <a href="https://plus.google.com/u/1/+StrahinjaMarkovi%C4%87/posts/Zmr5uf2jCHm">I&#8217;ve
written on this topic before</a>; suffice it to say that the new
architecture brought extra performance, stability and fixes for long-standing&nbsp;problems.</p>
<p><span class="caps">YCM</span> switched to this new implementation back in October 2013. Ever since then
I&#8217;ve been tweaking ycmd to remove Vim-specific cruftiness so that it&#8217;s more
generic. I&#8217;ve also added some docs and written the <a href="https://github.com/Valloric/ycmd/tree/master/examples/example_client.py">example
client</a> which demonstrates how to talk to&nbsp;ycmd.</p>
<h2>Why make the server&nbsp;generic?</h2>
<p>I&#8217;ve learned a lot over the last two years since <span class="caps">YCM</span> came out. I&#8217;ve integrated
several different semantic engines into <span class="caps">YCM</span>, from libclang for C/C++/Objective-C
to Jedi for Python and OmniSharp for C# (more will be added with time). There&#8217;s
a pretty simple ycmd-internal <span class="caps">API</span> for adding semantic support for other
languages. <span class="caps">YCM</span> has also moved past code-completion and is now targeting
code-comprehension features like GoTo and integrated diagnostic&nbsp;errors.</p>
<p>Of the things I&#8217;ve learned, an important lesson is that there&#8217;s a <em>lot</em> of
common ground between languages when it comes to tools that provide semantic
understanding of code. Much infrastructure is built over and over again for no&nbsp;benefit.</p>
<p>For instance, there are many Vim plugins that provide semantic code-completion
for a specific language (like jedi-vim for Python, OmniSharp for C#, gocode for
Go etc). They <em>all</em> need to have the following, even though some&nbsp;don&#8217;t:</p>
<ol>
<li>A semantic engine that can provide a list of available function/class names
   for a given location in a source code&nbsp;file.</li>
<li>A filtering system that can intelligently remove completion strings that
   aren&#8217;t&nbsp;relevant.</li>
<li>A ranking system that will (hopefully) put the most useful completion
   at the top of the completion&nbsp;menu.</li>
<li>Process-level separation between the semantic engines and the editor so that
   engine crashes don&#8217;t take down everything. Also makes it much harder to block
   the editor&#8217;s <span class="caps">GUI</span>&nbsp;thread.</li>
<li>Vim integration that will provide a <span class="caps">UI</span> that auto-shows the relevant&nbsp;completions.</li>
<li>Vim integration for showing diagnostic messages (errors and warnings) that
   undoubtedly arise from their semantic&nbsp;engines.</li>
<li>Tons of other stuff too annoying to&nbsp;enumerate.</li>
</ol>
<p>And then we repeat all of it not just across languages but also across editors
like Emacs and Sublime Text which have entirely different plugins that implement
(or fail to implement) all of the above as&nbsp;well.</p>
<p>This doesn&#8217;t scale and is a <em>massive</em> waste of&nbsp;effort.</p>
<p>In the above list, <em>everything but the first point is common infrastructure</em>.
This isn&#8217;t a theoretical notion, this is how <span class="caps">YCM</span> already works. Integrating a
new semantic engine into ycmd is borderline <em>trivial</em>; don&#8217;t take my word
for it, <a href="https://github.com/Valloric/ycmd/blob/master/ycmd/completers/python/jedi_completer.py">take a look at how the Jedi engine for Python is integrated</a>.
It&#8217;s ~120 lines of code and provides both semantic code-completion and GoTo.
<em>Everything</em> else is provided on top of that and is common to all the&nbsp;engines.</p>
<p>With ycmd now a server independent of Vim, a simple client can be written for
any editor; as soon as a new semantic engine is plugged into ycmd, the old
clients <em>Just Work™</em> with&nbsp;it.</p>
<p>This is the point of ycmd: to <strong>sit between the clients written for a specific
editor and the semantic engines written for a specific language</strong> while
providing a simple <span class="caps">API</span> on both ends. The semantic engines don&#8217;t have to worry
about anything beyond &#8220;which names are available at this line <span class="amp">&amp;</span> column location
in this file,&#8221; all the common plumbing is built on top of that. The clients on
the other hands don&#8217;t have to worry about anything beyond &#8220;this is the line <span class="amp">&amp;</span>
column location in the buffer the user is&nbsp;editing.&#8221;</p>
<h2>So what&#8217;s ycmd&#8217;s&nbsp;value-add?</h2>
<p>It all comes from the shared infrastructure. Other than simplifying APIs for the
semantic engines and the editor clients, ycmd for instance also has an
identifier-based completion engine that&#8217;s language-agnostic; it&#8217;s triggered when
semantic engines aren&#8217;t needed (more details in <a href="https://github.com/Valloric/ycmd/blob/master/README.md">ycmd docs</a>). There&#8217;s
also smart caching so that the engines aren&#8217;t queried too often (they can be
slow), a filepath completer, integration with snippet engines like UltiSnips and
the aforementioned completion filtering and ranking (which is neither simple nor
easy to implement&nbsp;right).</p>
<p>In case anyone is worried about the overhead of the client-server architecture,
<a href="https://plus.google.com/u/1/+StrahinjaMarkovi%C4%87/posts/Zmr5uf2jCHm">I&#8217;ve debunked that myth quite throughly</a> (with benchmarks, no less).
Even better than benchmarks, this has been implemented for <span class="caps">YCM</span> and has been
battle-tested over the last 10 months. For a server running on localhost, the
communication overhead is effectively <em>zilch</em>.</p>
<h2>Conclusion</h2>
<p>Let&#8217;s stop reinventing the&nbsp;wheel.</p>
<p><strong>For semantic engine writers:</strong> expose your engine as a server that talks
<span class="caps">HTTP</span>+<span class="caps">JSON</span> if at all possible; don&#8217;t worry about anything beyond listing
completions at a specific location in the file. Plug the server into ycmd (it&#8217;s
easy). All ycmd clients instantly work with your&nbsp;engine.</p>
<p><strong>For editor plugin developers:</strong> implement a client for ycmd. Most code is
already written for you in the <a href="https://github.com/Valloric/ycmd/tree/master/examples/example_client.py">example client</a>, you just need
to write the editor-specific parts. Hell, since the example code is all licensed
under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License v2</a>, you can copy-paste most of it.<sup id="fnref:copy"><a class="footnote-ref" href="#fn:copy" rel="footnote">2</a></sup>
Enjoy good code-completion and code-comprehension&nbsp;features.</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:popular">
<p>At the time of writing, <span class="caps">YCM</span> has ~5300 stars on GitHub. We can search GitHub
for <a href="https://github.com/search?q=stars%3A%3E1&amp;type=Repositories&amp;ref=advsearch&amp;l=VimL">all VimScript repositories sorted by stars</a>. <span class="caps">YCM</span> is not in
that list because GitHub classifies it as a Python project (most <span class="caps">YCM</span> code is
Python). The only two Vim plugins that can be considered popular enough to
be in the top 20 and are not mainly written in VimScript are <span class="caps">YCM</span> and
<a href="https://github.com/SirVer/ultisnips">UltiSnips</a> (great plugin!) which has ~1000&nbsp;stars.</p>
<p>The other items in the search results are (at the time of writing at&nbsp;least):</p>
<ol>
<li>Neovim, which is a new Vim build, so not a Vim&nbsp;plugin.</li>
<li>Some dotfiles, so not a Vim&nbsp;plugin.</li>
<li>Vundle, which is a plugin <em>manager</em>. <span class="caps">IMO</span> it shouldn&#8217;t count since
   installed by itself it&#8217;s pretty&nbsp;useless.</li>
<li>Solarized, which is a color scheme for many different editors (including
   Vim), so not a&nbsp;plugin.</li>
<li>Janus, which is a Vim plugin distribution, so not a Vim plugin&nbsp;itself.</li>
<li>This is where <span class="caps">YCM</span> would be if it were categorized as a VimScript&nbsp;repository.</li>
</ol>
<p>Not that GitHub stars are some great ranking mechanism by any stretch of the
imagination, but I don&#8217;t have a better one.&#160;<a class="footnote-backref" href="#fnref:popular" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:copy">
<p>If your editor can be extended with Python. If not, it can certainly
  send <span class="caps">HTTP</span> requests. The example client even pretty-prints (and
  syntax-highlights!) the full <span class="caps">HTTP</span> chatter between it and ycmd so figuring out
  what&#8217;s going on should be a piece of cake.&#160;<a class="footnote-backref" href="#fnref:copy" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
</ol>
</div>
]]>
        </content>
    </entry>
                <entry>
        <title type="html">YouCompleteMe, a Fast, As-You-Type, Fuzzy-Search Code Completion Engine for Vim</title>
        <author><name>Val Markovic</name></author>
        <link href="http://val.markovic.io/articles/youcompleteme-a-fast-as-you-type-fuzzy-search-code-completion-engine-for-vim"/>
        <updated>2013-02-04T10:00:00Z</updated>
        <published>2013-02-04T10:00:00Z</published>
        <summary>It has an identifier-based engine that works with every programming language and a Clang-based engine that provides semantic code completion for C and C++.</summary>>

        <id>http://val.markovic.io/articles/youcompleteme-a-fast-as-you-type-fuzzy-search-code-completion-engine-for-vim</id>

        <content type="html">
<![CDATA[
<p><a href="http://valloric.github.com/YouCompleteMe/">YouCompleteMe</a> is a fast, as-you-type, fuzzy-search code completion engine
for <a href="http://www.vim.org/">Vim</a>. It has two completion engines: an identifier-based engine that
works with every programming language and a semantic, <a href="http://clang.llvm.org/">Clang</a>-based engine
that provides semantic code completion for C/C++/Objective-C/Objective-C++ (from
now on referred to as &#8220;the C-family&nbsp;languages&#8221;).</p>
<p><img alt="YouCompleteMe GIF demo" src="//i.imgur.com/0OP4ood.gif" /></p>
<p>Here&#8217;s an explanation of what happens in the short <span class="caps">GIF</span> demo&nbsp;above.</p>
<p>First, realize that <strong>no keyboard shortcuts had to be pressed</strong> to get the list
of completion candidates at any point in the demo. The user just types and the
suggestions pop up by themselves. If the user doesn&#8217;t find the completion
suggestions relevant and/or just wants to type, he can do so; the completion
engine will not&nbsp;interfere.</p>
<p>When the user sees a useful completion string being offered, he presses the <span class="caps">TAB</span>
key to accept it. This inserts the completion string. Repeated presses of the
<span class="caps">TAB</span> key cycle through the offered&nbsp;completions.</p>
<p>If the offered completions are not relevant enough, the user can continue typing
to further filter out unwanted&nbsp;completions.</p>
<p>A critical thing to notice is that the completion <strong>filtering is <span class="caps">NOT</span> based on
the input being a string prefix of the completion</strong> (but that works too). The
input needs to be a <em><a href="http://en.wikipedia.org/wiki/Subsequence">subsequence</a> match</em> of a completion. This is a fancy way
of saying that any input characters need to be present in a completion string in
the order in which they appear in the input. So <code class="None"><span class="n">abc</span></code> is a subsequence of
<code class="None"><span class="n">xaybgc</span></code>, but not of <code class="None"><span class="n">xbyxaxxc</span></code>. After the filter, a complicated sorting system
ranks the completion strings so that the most relevant ones rise to the top of
the menu (so you usually need to press <span class="caps">TAB</span> just&nbsp;once).</p>
<p><strong>All of the above works with any programming language</strong> because of the
identifier-based completion engine. It collects all of the identifiers in the
current file and other files you visit and searches them when you type
(identifiers are put into per-filetype&nbsp;groups).</p>
<p>The demo also shows the semantic engine in use. The current semantic engine
supports only C-family languages. When the user presses <code class="None"><span class="p">.</span></code>, <code class="None"><span class="o">-&gt;</span></code> or <code class="None"><span class="o">::</span></code> while
typing in insert mode, the semantic engine is triggered (it can also be
triggered with a keyboard shortcut; see the&nbsp;docs).</p>
<p>The last thing that you can see in the demo is <span class="caps">YCM</span>&#8217;s integration with
<a href="https://github.com/scrooloose/syntastic">Syntastic</a> (the little red X that shows up in the left gutter) if you are
editing a file with semantic engine support. As Clang compiles your file and
detects warnings or errors, they will be piped to Syntastic for display. You
don&#8217;t need to save your file or press any keyboard shortcut to trigger this, it
&#8220;just happens&#8221; in the&nbsp;background.</p>
<p>In essence, <span class="caps">YCM</span> obsoletes the following Vim plugins because it has all of their
features plus&nbsp;extra:</p>
<ul>
<li>clang_complete</li>
<li>AutoComplPop</li>
<li>Supertab</li>
<li>neocomplcache</li>
</ul>
<h2>Why Did You Build&nbsp;This?</h2>
<p>Several reasons, but mostly because a long time ago, in a galaxy far, far away I
used to write C# code in Visual Studio. Its IntelliSense engine is a wonder to
behold, and I missed it in Vim. Don&#8217;t get me wrong, Vim is a much better editor
than <span class="caps">VS</span> (that&#8217;s why I switched to it), but Vim&#8217;s various built-in code
completion systems are an absolute joke. As in, not-even-funny bad. I&#8217;m not
going to press some complicated keyboard shortcut every single time I&#8217;m typing
an identifier; no, screw that, the system should trigger <em>itself</em> and
(unobtrusively) <em>offer</em> me completions that I can then either use or&nbsp;ignore.</p>
<p>The awesome Vim community valiantly tries to make the best it can out of the
built-in &#8220;omni-completion&#8221;, but these efforts boil down to putting lipstick on a&nbsp;pig.</p>
<p>You could say that AutoComplPop (<span class="caps">ACP</span>) already offered us this type of completion
auto-triggering as the user types. Fair point, but there are several issues with
that plugin. First, it&#8217;s dead. Last update was in 2009. Even worse, it&#8217;s slow.
Last, there&#8217;s no fuzzy search. I really, <em>really</em> like fuzzy search. Oh, and
there&#8217;s no semantic completion with&nbsp;<span class="caps">ACP</span>.</p>
<p>The plugin that really made me see the viability of the subsequence match
approach was the truly magnificent <a href="https://wincent.com/products/command-t">Command-T</a> plugin. It does
subsequence-based matching on file paths for easy file opening. This is probably
my favorite Vim plugin, right up there with <a href="https://github.com/Lokaltog/vim-easymotion">EasyMotion</a>. I couldn&#8217;t (and
wouldn&#8217;t want to) imagine writing code without&nbsp;them.</p>
<p>We also want our completion system to be smart about ranking whatever completion
candidates survive the filtering step. In a perfect world, the candidate you
want is exactly at the top of the menu so you need to press <span class="caps">TAB</span> only once. The
whole point of a code completion system is to save you keystrokes and if you
have to cycle through the menu to get to your candidate the point is&nbsp;lost.</p>
<p>Usually, you know exactly <em>what</em> string you want to type, but its long and you
don&#8217;t want to type 10 characters if 3 plus a <span class="caps">TAB</span> will do the same&nbsp;job.</p>
<p>Well, that&#8217;s <em>one</em> use case for a code completion system. There&#8217;s another.
That&#8217;s if you <em>don&#8217;t</em> actually know what string you want to use. This is the
&#8220;<span class="caps">API</span> exploration&#8221; use case. You might have a vague idea of a function you want
to call, maybe you even called it a few times before, but you can&#8217;t remember the
full&nbsp;name.</p>
<p>This is where semantic completion comes into play. It allows you to explore what
methods are available on the object you&#8217;re handling, what functions are
accessible from the scope you&#8217;re in etc. A really good semantic completion
engine will even help you with the function&#8217;s&nbsp;parameters.</p>
<p>Oh and we also want our completion system to be lightning-fast. If we&#8217;re waiting
for it to return a response&#8230; well it&#8217;s hardly doing its job of speeding us up
then, is&nbsp;it?</p>
<p>So, let&#8217;s see where we are now with requirements for a completion&nbsp;system:</p>
<ol>
<li>Auto-triggers as you&nbsp;type.</li>
<li>Uses subsequence-based completion&nbsp;filtering.</li>
<li>Uses smart heuristics to intelligently rank whatever candidates survive the
   filtering&nbsp;step.</li>
<li>Offers semantic&nbsp;completions.</li>
<li>Fast, fast, <em>fast</em>!</li>
</ol>
<p>clang_complete fails everything except #4 (for C-family languages), which it
excels at (it uses libclang, much like <span class="caps">YCM</span>). <span class="caps">IMO</span> it also fails #5 pretty badly
because it&#8217;s both slow (lots of Python logic, whereas <span class="caps">YCM</span> only uses Python as
glue code) <em>and</em> it blocks the <span class="caps">GUI</span> thread (something <span class="caps">YCM</span> does its best to
avoid<sup id="fnref:gui-block"><a class="footnote-ref" href="#fn:gui-block" rel="footnote">1</a></sup>).</p>
<p><span class="caps">ACP</span> as mentioned fails everything except #1. Neocomplcache can be configured to
provide #1 and it kinda sorta sometimes does a half-decent job at #4. I&#8217;ve used
neocomplcache for over eight months and my frustrations with it directly led to
the decision to build&nbsp;<span class="caps">YCM</span>.</p>
<p>SuperTab I have limited experience with, but from what I understand, it does a
half-decent job at #4, much like&nbsp;neocomplcache.</p>
<p><span class="caps">YCM</span> fulfills all of these requirements. #4 is currently only fulfilled for
C-family languages, but <span class="caps">YCM</span> has an internal Completer <span class="caps">API</span> that is designed so
that completers for other filetypes can easily be implemented and hooked-up to
the rest of the system. A Python semantic completer will probably be built some
time in the future,<sup id="fnref:rope"><a class="footnote-ref" href="#fn:rope" rel="footnote">2</a></sup> and others can help out with completers for other
languages. In the mean time, there will probably be a &#8220;generic&#8221; filetype
completer that queries Vim&#8217;s omni-completion system for completions if a
specific completer has not yet been written. <span class="caps">YCM</span> would provide the other
components on top of the results coming from omni-complete. The &#8220;generic&#8221;
completer hasn&#8217;t been built yet but it&#8217;s on the&nbsp;roadmap.</p>
<h2>Things We Can&#8217;t Build in Vim yet but Would Like&nbsp;to</h2>
<p>I can&#8217;t show a box with help text related to the function right next to the
completion menu in Vim. There&#8217;s just no <span class="caps">API</span> for that. libclang can actually
extract doxygen information from function comment blocks, but there&#8217;s no way to
spawn such a &#8220;sub-window&#8221; arbitrarily on the screen in&nbsp;Vim.</p>
<p>The best Vim offers is the &#8220;preview&#8221; window that can show up at the top of the
file.<sup id="fnref:preview"><a class="footnote-ref" href="#fn:preview" rel="footnote">3</a></sup> <span class="caps">YCM</span> supports this, but it&#8217;s just not the same. Your eyes have to
leave the small area of the screen where you&#8217;re currently typing and on a 30
inch monitor this is&nbsp;annoying.</p>
<p>So no, we can&#8217;t build the full <span class="caps">VS</span> experience. I&#8217;ll take what I&#8217;ve built so far&nbsp;though.</p>
<h2>Closing&nbsp;Words</h2>
<p>I&#8217;ve been building <span class="caps">YCM</span> on-and-off for a year now in my spare time; I&#8217;d guess
about 4 months of work went into it. It&#8217;s not a terribly complicated system to
build, the main causes of slowdowns were bugs in Vim I encountered while
building this. Those were incredibly annoying and put me off the whole thing for&nbsp;months.</p>
<p>But it&#8217;s reached a very releasable state. I&#8217;ve been using the identifier
completer for roughly eight months now and the semantic completer for about two
months (with C++ code). In my experience, they&#8217;re both rock-solid. I&#8217;ve had
co-workers bang on <span class="caps">YCM</span> and lots of bugs were fixed as a result; hopefully it
will be pretty stable for a wider audience as&nbsp;well.</p>
<p>Enjoy the plugin and feel free to <a href="https://github.com/Valloric/YouCompleteMe/issues?state=open">report any issues</a> you&nbsp;encounter!</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:gui-block">
<p>But sometimes <span class="caps">YCM</span> fails at this because Vim is profoundly
single-threaded and also does not provide an <span class="caps">API</span> for plugins to temporarily
return control to Vim&#8217;s event loop. If such an <span class="caps">API</span> existed, plugins could make
sure to return control to the event loop every now and then while something slow
and complicated was being done in the background. But no such <span class="caps">API</span> exists. Also,
there&#8217;s no way to perform a task asynchronously in VimScript. This limitation
forces <span class="caps">YCM</span> to block the <span class="caps">GUI</span> thread on occasion. But I try really hard to avoid
this whenever possible.&#160;<a class="footnote-backref" href="#fnref:gui-block" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:rope">
<p>Probably with <a href="http://rope.sourceforge.net/">Rope</a>.&#160;<a class="footnote-backref" href="#fnref:rope" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:preview">
<p>To enable this, add <code class="None"><span class="n">preview</span></code> to <code class="None"><span class="n">completeopt</span></code> in your vimrc, like
so: <code class="None"><span class="n">set</span> <span class="n">completeopt</span><span class="o">+=</span><span class="n">preview</span></code>.&#160;<a class="footnote-backref" href="#fnref:preview" rev="footnote" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
</ol>
</div>
]]>
        </content>
    </entry>
                <entry>
        <title type="html">Recommended Books on Modern Investing and Personal Finance</title>
        <author><name>Val Markovic</name></author>
        <link href="http://val.markovic.io/articles/recommended-books-on-modern-investing-and-personal-finance"/>
        <updated>2012-12-29T10:00:00Z</updated>
        <published>2012-12-29T10:00:00Z</published>
        <summary>A list of books for optimizing one&#39;s financial success and happiness that everyone should read.</summary>>

        <id>http://val.markovic.io/articles/recommended-books-on-modern-investing-and-personal-finance</id>

        <content type="html">
<![CDATA[
<p>We should all know more about prudent investing. You&#8217;re saving for retirement,
right? If you are (and if you aren&#8217;t, you should be), then you&#8217;re investing in
something. You&#8217;re not just letting that money sit in a checking/savings account.
Here are some books you should read to optimize your financial success and&nbsp;happiness.</p>
<p><em>[<span class="caps">TL</span>;<span class="caps">DR</span>: For the impatient crowd, go read <a href="//amzn.com/0071747052">The Four Pillars of
Investing</a> right now. For the super-impatient, here&#8217;s a grossly
inadequate four-word summary of modern personal investment advice: low-cost
index funds. Don&#8217;t have a clue what I&#8217;m talking about? Read&nbsp;on.]</em></p>
<p>I&#8217;ve been fascinated with Financial Mathematics ever since I took a (gruelingly
difficult) class in it in graduate school. Since then, I&#8217;ve read a few more
books on the topic. It remains the only field of Mathematics other than Discreet
Math that truly interests me.<sup id="fnref:interest"><a class="footnote-ref" href="#fn:interest" rel="footnote">1</a></sup> But these are merely hobbies; I hold no
delusions of grandeur in my abilities in these&nbsp;areas.</p>
<p>Knowledge of Financial Mathematics prepares one for investing in much the
same way that Computer Science prepares one for Software Engineering. In other
words, not at all. There are many, many reasons why investing is an altogether
different beast. Those of you who have read more than one Financial Math
university textbook, quick, how many references did those books make to taxes
and investment costs?<sup id="fnref:cs"><a class="footnote-ref" href="#fn:cs" rel="footnote">2</a></sup></p>
<p>So <span class="caps">FM</span> textbooks are naturally out. There&#8217;s a ridiculous number of investment
books out there, most of which are less than stellar. Some of the good ones are
also out of date, and a lot of them are tailored to institutional investors.
I&#8217;ve picked out a nice selection of sage advice for the personal investor in the
following list; I&#8217;ve read all of the listed books and quite a few I&#8217;m not
listing. None of the books I&#8217;m recommending should be controversial and I&#8217;m not
affiliated with any of them; there are no referral links here and I have no skin
in this&nbsp;game.</p>
<p>There&#8217;s a very good reason why I&#8217;m giving you a list of books to read instead of
just summarizing the great advice that&#8217;s in them: never take investment advice
you don&#8217;t understand. You <em>need</em> to understand <em>why</em> portfolio X makes sense,
why investment Y doesn&#8217;t, why actively managed funds underperform etc. You need
<em>depth</em> here, not superficial &#8220;I think I get it&#8221; understanding. Your financial
future depends upon you fully grasping these&nbsp;concepts.</p>
<h2>The&nbsp;Basics</h2>
<p>These are must-read books. I&#8217;m presenting them in a sensible reading order that
will slowly teach you more and more, building on what you have previously read.
None of them are difficult reads; in fact, all of them are surprisingly well
written and&nbsp;entertaining.</p>
<ul>
<li>
<p><a href="//amzn.com/0547447256"><em>The Only Investment Guide You&#8217;ll Ever Need</em></a> by Andrew Tobias: Yes,
    I know, the title is terrible (and patently false). To the author&#8217;s credit,
    he apologizes for it in the preface and says it was the publisher&#8217;s idea.
    But no matter; it&#8217;s a really good&nbsp;book.</p>
<p>It covers a <em>very</em> wide area and spends a considerable amount of time on
Personal Finance. If you&#8217;re young and just out of college (or soon to be),
this is where you should start. If you think you have a firm grasp of
Personal Finance, then you should <em>definitely</em> start here. This book also
describes in detail many different investment vehicles (with pros <span class="amp">&amp;</span> cons of
each); it also covers planning for retirement, differences between the
various retirement accounts (401k/Roth 401k/<span class="caps">IRA</span>/Roth <span class="caps">IRA</span>), annuities,
insurance, tax laws, estate planning, <span class="caps">ESA</span>&#8217;s, 529s, <span class="caps">SEP</span>&#8217;s, <span class="caps">SIMPLE</span>&#8217;s and the
kitchen sink, too. Seriously, start&nbsp;here.</p>
<p>The book is also well written and remarkably funny. You will enjoy reading&nbsp;it.</p>
<p>Make sure you get the latest edition of the book. It&#8217;s been out for nearly
thirty years now, but the author updates it every three or four years as the
tax and investment landscape changes. The latest editions have little in
common with the earlier&nbsp;ones.</p>
</li>
<li>
<p><a href="//amzn.com/0071747052"><em>The Four Pillars of Investing</em></a> by William Bernstein: This is a
    brilliant book and the one I recommend the most out of this bunch. It does
    require the reader to be comfortable with math to a minute&nbsp;extent.</p>
<p>It will teach you how to think about investment returns and it will provide
a brief history of investment folly. It will provide mountains of data on
how (and why) actively managed funds fail to beat low-cost index funds and
why individual stock-picking is a loser&#8217;s game. It will teach you how to
tailor an investment portfolio that matches your financial situation (and
personal risk disposition) and why you should avoid investment banks,
brokers and preferably the entire investment industry, lest it eat up
considerable portions of your&nbsp;returns.</p>
<p>If you come away from this articles with one book in mind, <em>let it be this
one</em>. It&#8217;s the best and the most important one I can think&nbsp;of.</p>
<p>I <em>cannot</em> recommend this book highly enough. Instead of peddling vague and
anecdotal advice based on some random guy&#8217;s experience (which is what most
investment books do), Bernstein approaches personal investing as a science.
He backs up everything he says with sound data and references to modern
investment research. All of his advice is practical and actionable. <em>Read
this now</em>.</p>
</li>
<li>
<p><a href="//amzn.com/0393340740"><em>A Random Walk Down Wall Street</em></a> by Burton Malkiel: This book will
    teach you how to &#8220;think&#8221; about the market. It will cover pretty much all the
    stock market bubbles throughout history and what caused them. This will help
    you recognize similar craziness in the future. It&#8217;s also chock-full of more
    proof on why actively managed funds underperform index funds and why
    stock-picking is something only monkeys with darts do. It will teach you
    about the Efficient Market Hypothesis and why it still makes sense after all
    these years (well, the semi-strong variety at least&#8230; and it makes sense
    <em>the vast majority</em> of the time, except when it doesn&#8217;t, for reasons that I
    will not go into right now).  This book is absolutely worth your&nbsp;time.</p>
</li>
</ul>
<p>After reading the <em>Guide</em>, the <em>Pillars</em> and the <em>Walk</em>, you can confidently
stop. This is my three-book list for investment newcomers. After completing
this book bundle you&#8217;ll know more about investing than most &#8220;professional&#8221; money
managers. If you implement the advice in these books, your returns will also beat
the returns of ~80% of actively managed funds, <em>over the long term</em>
(20+ years).<sup id="fnref:returns"><a class="footnote-ref" href="#fn:returns" rel="footnote">3</a></sup></p>
<p>If you can read only two, go with the <em>Guide</em> and the <em>Pillars</em>. If just one,
then the <em>Pillars</em>. But preferably all of them. That&#8217;s it, you can stop reading
this article if you&nbsp;wish.</p>
<h2>Greater&nbsp;Appetite</h2>
<p>If you want to know even more about sound investing, here are some other books
I&#8217;d&nbsp;recommend:</p>
<ul>
<li>
<p><a href="//amzn.com/0071362363"><em>The Intelligent Asset Allocator</em></a> by William Bernstein: This
    was Bernstein&#8217;s first book. It&#8217;s very good, but <em>Pillars</em> covers everything
    that <em>Allocator</em> does and much more. This book goes into more detail about
    asset allocation, but frankly <em>Pillars</em> gives you all of the really meaty
    parts.  <em>Allocator</em> will go into more data, graphs, proof and math on why
    the things Bernstein recommends in <em>Pillars</em> make sense. A worthwhile read,
    certainly, but if you&#8217;ve read his second tome you&#8217;re not going to get that
    much from it. Read it if you want some extra in-depth data on asset class
    behavior, otherwise skip&nbsp;it.</p>
<p>Some people will tell you that understanding this book requires knowledge of
advanced mathematics. Nonsense. It&#8217;s certainly more math-heavy than
<em>Pillars</em>, but if knowledge to understand it passes for &#8220;advanced math&#8221;,
someone please shoot me&nbsp;now.</p>
</li>
<li>
<p><a href="//amzn.com/0470138130"><em>Common Sense on Mutual Funds</em></a> by John C. Bogle: Mountains
    upon mountains of data on why index funds beat active funds in the long
    term. Truly, <em>mountains</em>. The biggest complaint is that the book is
    extremely repetitive; the same message is repeated over and over again. And
    then some more. And did you know that index funds beat active funds? They
    do. You didn&#8217;t know that? Fine, here&#8217;s evidence item&nbsp;#892374984.</p>
<p>After a time, it tends to grate a bit. But convince you of its message it&nbsp;will.</p>
<p>Also, Bogle famously shares some disdain for foreign market diversification.
He&#8217;s an absolute giant of finance and this is his only major flaw. The book
is still a worthwhile&nbsp;read.</p>
</li>
<li>
<p><a href="//amzn.com/0060555661"><em>The Intelligent Investor</em></a> by Benjamin Graham: This is Warren
    Buffett&#8217;s mentor. If you want to know more about the stock market and what
    makes certain companies better stocks than others, read this. But keep in
    mind that you <em>shouldn&#8217;t be buying individual stocks at all</em>. Index funds
    were invented after Graham died; had they been around when he was, he would
    have probably been all over them. But this book will broaden your horizons
    if you read it, so it&#8217;s not a bad read, even if you don&#8217;t end up using the
    knowledge in it.<sup id="fnref:lisp"><a class="footnote-ref" href="#fn:lisp" rel="footnote">4</a></sup></p>
</li>
</ul>
<h2>Uncommonly&nbsp;Recommended</h2>
<p>Here are some other good books on investing I <strong>don&#8217;t</strong> usually recommend (they
make sense, but the alternatives are better and cover the same&nbsp;areas):</p>
<ul>
<li>
<p><a href="//amzn.com/1118073762"><em>The Investor&#8217;s Manifesto</em></a> by William Bernstein: This book is a
    dumbed-down version of <em>Pillars</em>. If you&#8217;ve read that book, ignore this one.
    It offers virtually nothing new, merely a rehashing of Bernstein&#8217;s old
    (still perfectly valid) advice without the data backing it up.  Read this
    book if you&#8217;re scared of graphs, charts and tables. I recommend it only to
    people who can&#8217;t handle <em>Pillars</em> because they&#8217;re frightened of the most
    basic high-school level&nbsp;math.</p>
</li>
<li>
<p><a href="//amzn.com/0470067365"><em>The Bogleheads&#8217; Guide to Investing</em></a> by Taylor Larimore, Mel
    Lindauer and Michael LeBoeuf: This is a pretty good all-around book on
    investing and retirement planning, but <em>Pillars</em> + <em>Guide</em> is a better
    option. There&#8217;s no bad advice&nbsp;here.</p>
</li>
</ul>
<h2>Investing and Finance,&nbsp;Broadly</h2>
<p>And now that we&#8217;ve reached the end, here are some books that may not teach you
much about investing, but will teach you plenty about the specific areas of
finance that they&nbsp;cover:</p>
<ul>
<li>
<p><a href="//amzn.com/039333869X"><em>Liar&#8217;s Poker</em></a> by Michael Lewis: If you ever wanted to know why
    brokers and investment banks are the biggest enemies of their customers,
    read this book.  It chronicles Lewis&#8217;s life as a broker for Salomon Brothers
    in the &#8216;80s. It&#8217;s not pretty (but it is a fun read). Little has changed
    since then; the finance industry may have become just a shade<sup id="fnref:shade"><a class="footnote-ref" href="#fn:shade" rel="footnote">5</a></sup> more
    unethical. Keep in mind, the book starts out a bit&nbsp;slow.</p>
</li>
<li>
<p><a href="//amzn.com/0393338827"><em>The Big Short</em></a> by Michael Lewis: Another great book from Lewis,
    this time about how and why the 2007 recession started. You get to learn
    just how bat-shit crazy with greed Wall Street can become. If you ever
    wanted to know &#8220;the real deal&#8221; behind the Great Recession, read this. It&#8217;s a
    peculiar mix of laugh-out-loud funny and blow-your-brains-out&nbsp;depressing.</p>
</li>
<li>
<p><a href="//amzn.com/0375758259"><em>When Genius Failed</em></a> by Roger Lowenstein: Covers the fall of the
    Long Term Capital Management hedge fund in 1998. You may have heard of this
    event, it damn-nigh brought the financial industry to its knees (much like
    the recent recession in fact did). The fund had derivative positions with a
    notional value of ~$1.25 <em>trillion</em>, and had to be bailed out by the Fed of
    New York.  Does this perhaps sound familiar? We never&nbsp;learn.</p>
</li>
<li>
<p><a href="//amzn.com/0812979273"><em>Buffett: The Making of an American Capitalist</em></a> by Roger
    Lowenstein: A biography covering Warren Buffett. Very well written. It&#8217;s an
    entertaining read with sensible investment advice sprinkled&nbsp;throughout.</p>
</li>
</ul>
<h2>Parting&nbsp;Advice</h2>
<p>If you&#8217;re confused about personal investing even after reading the books in the
Basics list, a great place to ask questions is the <a href="//www.bogleheads.org/forum/index.php">Bogleheads online
forum</a>. It&#8217;s a collection of some of the nicest and most
investment-savvy people you can meet. Their <a href="//www.bogleheads.org/wiki/Main_Page">wiki</a> is also filled
with great&nbsp;advice.</p>
<p>Happy&nbsp;investing!</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:interest">
<p>By &#8220;interest&#8221;, I mean &#8220;I could conceivably see myself doing this
for a living.&#8221; Not that I have any intention to, of course; I love Software
Engineering far more.&#160;<a class="footnote-backref" href="#fnref:interest" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:cs">
<p>If you have a <span class="caps">CS</span> background, compare this with the number of references to
version control systems, software testing, code style guidelines and code
readability (among other things) in all of the <span class="caps">CS</span> books you have read.&#160;<a class="footnote-backref" href="#fnref:cs" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:returns">
<p>We&#8217;re talking <em>real</em> returns here, not <em>nominal</em> returns (you &#8220;eat&#8221;
real returns). Also, after-tax (again, you don&#8217;t &#8220;eat&#8221; pre-tax money). In other
words, we&#8217;re talking about money <em>you end up caring about</em>.&#160;<a class="footnote-backref" href="#fnref:returns" rev="footnote" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
<li id="fn:lisp">
<p>It&#8217;s a lot like reading <em>Structure and Interpretation of Computer
Programs</em> for programmers who will never write a line of Scheme in their
professional life. Still worthwhile, gives you depths of understanding. This is
the <span class="caps">SICP</span> of investing.&#160;<a class="footnote-backref" href="#fnref:lisp" rev="footnote" title="Jump back to footnote 4 in the text">&#8617;</a></p>
</li>
<li id="fn:shade">
<p>Did I say &#8220;just a shade&#8221;? I meant &#8220;you couldn&#8217;t possibly imagine how
much more.&#8221; See <em>The Big Short</em>.&#160;<a class="footnote-backref" href="#fnref:shade" rev="footnote" title="Jump back to footnote 5 in the text">&#8617;</a></p>
</li>
</ol>
</div>
]]>
        </content>
    </entry>
                <entry>
        <title type="html">A Vim Plugin That Always Highlights the Enclosing Tags</title>
        <author><name>Val Markovic</name></author>
        <link href="http://val.markovic.io/articles/a-vim-plugin-that-always-highlights-the-enclosing-tags"/>
        <updated>2012-09-12T10:00:00Z</updated>
        <published>2012-09-12T10:00:00Z</published>
        <summary>Always knowing what element you are in when editing HTML or XML is very useful. Other Vim plugins highlight the other tag only when the cursor is inside the angle brackets.</summary>>

        <id>http://val.markovic.io/articles/a-vim-plugin-that-always-highlights-the-enclosing-tags</id>

        <content type="html">
<![CDATA[
<p>Just recently I started editing <span class="caps">HTML</span> much more than I usually do<sup id="fnref:html"><a class="footnote-ref" href="#fn:html" rel="footnote">1</a></sup> and I
noticed Vim was missing an awesome feature Notepad++ had. The last time I used
Notepad++ was many years ago, but I still remember it used to highlight the
other tag in the pair when your cursor was inside one of&nbsp;them.</p>
<p><em>[For those who want to skip to the end, the plugin I built is called
<a href="http://valloric.github.com/MatchTagAlways">MatchTagAlways</a>.]</em></p>
<p>Sure enough, I wasn&#8217;t <a href="http://stackoverflow.com/questions/8168320/can-vim-highlight-matching-html-tags-like-notepad">the only one</a> who noticed that Vim was missing this
awesome feature. <a href="http://www.gregsexton.org/">A kind soul</a> even took it upon himself to implement said
missing functionality as <a href="https://github.com/gregsexton/MatchTag#readme">a Vim plugin</a> that does exactly what it says on
the tin, and does it&nbsp;well.</p>
<p>But you know what? I want <em>more</em> than&nbsp;that.</p>
<p>I don&#8217;t want Vim to &#8220;just&#8221; highlight the other tag in the pair when my cursor is
inside the tag, I want it to <em>always</em> highlight the tags that enclose the
cursor. I&#8217;ve seen Sublime Text 2 trying to point out the enclosing tags with a
dotted line, but I&#8217;ve also seen it fail in the face of unclosed tags common in
<span class="caps">HTML5</span> syntax.<sup id="fnref:tags"><a class="footnote-ref" href="#fn:tags" rel="footnote">2</a></sup></p>
<p>Here&#8217;s an animated <span class="caps">GIF</span> of what I&#8217;m talking&nbsp;about:</p>
<p><img alt="MatchTagAlways screen shot" src="//i.imgur.com/qAf0N.gif" /></p>
<p>Do you see how the enclosing tags are always highlighted, even when you are
inside the element&#8217;s content? That&#8217;s what I&nbsp;wanted.</p>
<p>So I wrote a plugin that does it. The <span class="caps">GIF</span> you just saw is <a href="http://valloric.github.com/MatchTagAlways">MatchTagAlways</a>
in action. It&#8217;s plug <span class="amp">&amp;</span> play, comes with sane defaults and should require no
configuration (although there are knobs to tweak if you want to do&nbsp;that).</p>
<p>Implementing this is actually surprisingly tricky to get right if you want to
support use-cases like templating languages and the aforementioned <span class="caps">HTML5</span> syntax.
There&#8217;s a ridiculous number of corner cases to handle, and <span class="caps">MTA</span> implements far
too much of an <span class="caps">HTML</span> parser for my liking.<sup id="fnref:regex"><a class="footnote-ref" href="#fn:regex" rel="footnote">3</a></sup></p>
<p>Anyway, use it if you edit <span class="caps">HTML</span> or <span class="caps">XML</span> if this looks like a feature you&#8217;d like
to have. Note that your copy of Vim needs to come with Python support. More
details can be found in the plugin&#8217;s&nbsp;docs.</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:html">
<p>I write it in bursts, but day-to-day I mostly write C++ or Python.&#160;<a class="footnote-backref" href="#fnref:html" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:tags">
<p>Not that I&#8217;m saying that you should actually write code like this. I
always close my tags (even in <span class="caps">HTML5</span>), but not everyone does and sometimes I need
to edit that code.&#160;<a class="footnote-backref" href="#fnref:tags" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:regex">
<p>Quite a bit of it with regular expressions. Yes, I know, <a href="http://stackoverflow.com/a/1732454/146752">I&#8217;m going to
hell</a>. But it still works in 99.99% of the use-cases and fuck me if I&#8217;m
going to write an <em>actual</em> <span class="caps">HTML</span> parser that works from the &#8220;inside out&#8221;<sup id="fnref:inout"><a class="footnote-ref" href="#fn:inout" rel="footnote">4</a></sup>
just for this, because that&#8217;s what I need and it doesn&#8217;t exist.&#160;<a class="footnote-backref" href="#fnref:regex" rev="footnote" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
<li id="fn:inout">
<p>By &#8220;inside out&#8221; I mean it starts from a specific line and column
number and parses up and down. No, you can&#8217;t use a &#8220;normal&#8221; parser. <span class="caps">MTA</span> only
looks at the <span class="caps">HTML</span> code that is on the screen for the sake of performance and
that won&#8217;t parse sensibly with a normal parser, especially when you throw in the
&#8220;has to work with templates&#8221; requirement. No, not even Beautiful Soup.  Yes,
I&#8217;ve tried. The current solution is pretty damn robust.&#160;<a class="footnote-backref" href="#fnref:inout" rev="footnote" title="Jump back to footnote 4 in the text">&#8617;</a></p>
</li>
</ol>
</div>
]]>
        </content>
    </entry>
        </feed>