<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Устрой дестрой 😈</title>
    <description>Соу мета дескрипшен моего космо-блога 😎
</description>
    <link>http://vivkin.com/</link>
    <atom:link href="http://vivkin.com/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Tue, 14 Jul 2015 14:34:49 +0000</pubDate>
    <lastBuildDate>Tue, 14 Jul 2015 14:34:49 +0000</lastBuildDate>
    <generator>Jekyll v2.4.0</generator>
    
      <item>
        <title>Макросы, которые вызывают макросы</title>
        <description>&lt;h2 id=&quot;section&quot;&gt;интро&lt;/h2&gt;
&lt;p&gt;Отнсительно недавно, примерно с год назад, изучая libuv, наткнулся на отличный прием работы с препроцессором. Уже позже выяснилось что называется он X-macro и позволяет в макросах вызывать другие макросы. С его помошью очень легко избежать дублирования и ошибок в задачах где перечисления надо конвертировать в строки, давать строковые имена битовым флагам, рефлексии, сериализации и т.п.&lt;/p&gt;

&lt;h2 id=&quot;section-1&quot;&gt;пример&lt;/h2&gt;
&lt;p&gt;Перечисление с кодами ошибок и строкой с описанием:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#define JSON_ERRNO_MAP(XX)                           \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(OK, &amp;quot;ok&amp;quot;)                                     \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(BAD_NUMBER, &amp;quot;bad number&amp;quot;)                     \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(BAD_STRING, &amp;quot;bad string&amp;quot;)                     \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(BAD_IDENTIFIER, &amp;quot;bad identifier&amp;quot;)             \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(STACK_OVERFLOW, &amp;quot;stack overflow&amp;quot;)             \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(STACK_UNDERFLOW, &amp;quot;stack underflow&amp;quot;)           \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(MISMATCH_BRACKET, &amp;quot;mismatch bracket&amp;quot;)         \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(UNEXPECTED_CHARACTER, &amp;quot;unexpected character&amp;quot;) \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(UNQUOTED_KEY, &amp;quot;unquoted key&amp;quot;)                 \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(BREAKING_BAD, &amp;quot;breaking bad&amp;quot;)                 \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    XX(ALLOCATION_FAILURE, &amp;quot;allocation failure&amp;quot;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonErrno&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define XX(no, str) JSON_##no,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_ERRNO_MAP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;XX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#undef XX&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;jsonStrError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#define XX(no, str) \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    case JSON_##no: \&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;        return str;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;JSON_ERRNO_MAP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;XX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#undef XX&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;unknown&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;После препроцессора первращается в:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonErrno&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_OK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_BAD_NUMBER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_BAD_STRING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_BAD_IDENTIFIER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_STACK_OVERFLOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_STACK_UNDERFLOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_MISMATCH_BRACKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_UNEXPECTED_CHARACTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_UNQUOTED_KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_BREAKING_BAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;JSON_ALLOCATION_FAILURE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;jsonStrError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_OK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;ok&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_BAD_NUMBER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;bad number&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_BAD_STRING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;bad string&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_BAD_IDENTIFIER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;bad identifier&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_STACK_OVERFLOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;stack overflow&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_STACK_UNDERFLOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;stack underflow&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_MISMATCH_BRACKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;mismatch bracket&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_UNEXPECTED_CHARACTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;unexpected character&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_UNQUOTED_KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;unquoted key&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_BREAKING_BAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;breaking bad&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;JSON_ALLOCATION_FAILURE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;allocation failure&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;unknown&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
        <pubDate>Wed, 15 Jul 2015 00:00:00 +0000</pubDate>
        <link>http://vivkin.com/2015/07/15/x-macro.html</link>
        <guid isPermaLink="true">http://vivkin.com/2015/07/15/x-macro.html</guid>
        
        <category>c</category>
        
        <category>c++</category>
        
        <category>programming</category>
        
        <category>preprocessor</category>
        
        <category>x-macro</category>
        
        <category>си</category>
        
        <category>препроцессор</category>
        
        <category>программирование</category>
        
        
      </item>
    
      <item>
        <title>vi, vi everywhere</title>
        <description>&lt;h2 id=&quot;vi---&quot;&gt;Vi шорткаты в шелле&lt;/h2&gt;
&lt;p&gt;Многие vi-юзеры не знают, что в баше можно также использовать привычные сочетания клавиш, вместо emacs’овых. Лечится добавлением в &lt;code&gt;.bashrc&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span class=&quot;nb&quot;&gt;set&lt;/span&gt; -o vi&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Также работает в zsh. Для OS X юзеров, лучше поставить bash 4 из homebrew, тогда если добавить в &lt;code&gt;.inputrc&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;editing-mode vi
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;show-mode-in-prompt on&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Перед приглашением командной строки будет стоят &lt;code&gt;+&lt;/code&gt; в insert режиме и &lt;code&gt;:&lt;/code&gt; в коммандном, и все что использует &lt;code&gt;readline&lt;/code&gt; также будет с vi биндами.&lt;/p&gt;
</description>
        <pubDate>Wed, 15 Jul 2015 00:00:00 +0000</pubDate>
        <link>http://vivkin.com/2015/07/15/bash-vi.html</link>
        <guid isPermaLink="true">http://vivkin.com/2015/07/15/bash-vi.html</guid>
        
        <category>vi</category>
        
        <category>vim</category>
        
        <category>bash</category>
        
        <category>shell</category>
        
        
      </item>
    
      <item>
        <title>Переключать локализацию как хакер</title>
        <description>&lt;h2 id=&quot;section&quot;&gt;интро&lt;/h2&gt;
&lt;p&gt;Так уж повелось, что весь софт я использую с английской локализацией. Исторически. Но! Всегда может произойти, какая нибудь беда, например, уроки музыки :)
И тут начинаются проблемы с конвертацией русских терминов (которые наполовину калька с итальянского) в англоязычные. И так информации такое огромное количество, что голова болит, а еще переводом заниматся брр.&lt;/p&gt;

&lt;h2 id=&quot;section-1&quot;&gt;брейкдаун&lt;/h2&gt;
&lt;p&gt;На маке большинство программ берут локаль из глобальных настроек системы и переключить ее можно только глобально :(
То есть не только. И чинится это так.&lt;/p&gt;

&lt;h2 id=&quot;section-2&quot;&gt;дроп&lt;/h2&gt;
&lt;p&gt;Запуск программы с другой локализацией:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;/Applications/GarageBand.app/Contents/MacOS/GarageBand -AppleLanguages &lt;span class=&quot;s1&quot;&gt;&amp;#39;(ru-RU)&amp;#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Прописать навсегда русский:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;viv@Ivans-MBP:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;defaults write com.apple.garageband10 AppleLanguages &lt;span class=&quot;s1&quot;&gt;&amp;#39;(ru-RU)&amp;#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Теперь можно мыслить нормально в тактах, долях и т.д. не ломая мозг собачими band’ами и другим мусором&lt;/p&gt;
</description>
        <pubDate>Fri, 10 Apr 2015 00:00:00 +0000</pubDate>
        <link>http://vivkin.com/2015/04/10/apple-language.html</link>
        <guid isPermaLink="true">http://vivkin.com/2015/04/10/apple-language.html</guid>
        
        <category>osx</category>
        
        <category>garageband</category>
        
        <category>magic</category>
        
        
      </item>
    
  </channel>
</rss>
