<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.5.0">Jekyll</generator><link href="https://venis.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://venis.github.io/" rel="alternate" type="text/html" /><updated>2017-07-19T02:27:24+03:00</updated><id>https://venis.github.io/</id><title type="html">My Blog</title><subtitle>This is my site</subtitle><author><name>Vyacheslav Enis</name><email>venis@difane.com</email></author><entry><title type="html">How To Atomically Update A Counter Shared Between Docker Instances</title><link href="https://venis.github.io/2017/07/18/how-to-atomically-update-a-counter-shared-between-docker-instances.html" rel="alternate" type="text/html" title="How To Atomically Update A Counter Shared Between Docker Instances" /><published>2017-07-18T00:00:00+03:00</published><updated>2017-07-18T00:00:00+03:00</updated><id>https://venis.github.io/2017/07/18/how-to-atomically-update-a-counter-shared-between-docker-instances</id><content type="html" xml:base="https://venis.github.io/2017/07/18/how-to-atomically-update-a-counter-shared-between-docker-instances.html">&lt;h2 id=&quot;problem&quot;&gt;Problem&lt;/h2&gt;
&lt;p&gt;There are some multiple API endpoints (REST services for example) that increased some counter every time API is called.
The counter value must be shared between endpoints. They are often dockerized and different containers can be run on 
different hosts.&lt;/p&gt;

&lt;h2 id=&quot;solution&quot;&gt;Solution&lt;/h2&gt;

&lt;p&gt;To solve given problem using for example database is overhead. Everything needed is just some distributed lightweight 
key-value storage with shared lock support. Here are some candidates:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://coreos.com/etcd&quot;&gt;etcd&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.consul.io&quot;&gt;consul&lt;/a&gt;, especially &lt;a href=&quot;https://www.consul.io/docs/commands/lock.html&quot;&gt;consul-lock&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://redis.io&quot;&gt;redis&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Vyacheslav Enis</name><email>venis@difane.com</email></author><category term="[&quot;HowTo&quot;, &quot;Enterprise integration&quot;]" /><category term="docker" /><category term="etcd" /><category term="consul" /><category term="redis" /><category term="enterprise-integration" /><summary type="html">Problem There are some multiple API endpoints (REST services for example) that increased some counter every time API is called. The counter value must be shared between endpoints. They are often dockerized and different containers can be run on different hosts.</summary></entry><entry><title type="html">How To Save Files Right</title><link href="https://venis.github.io/2013/01/20/how-to-save-files-right.html" rel="alternate" type="text/html" title="How To Save Files Right" /><published>2013-01-20T00:00:00+02:00</published><updated>2013-01-20T00:00:00+02:00</updated><id>https://venis.github.io/2013/01/20/how-to-save-files-right</id><content type="html" xml:base="https://venis.github.io/2013/01/20/how-to-save-files-right.html">&lt;ol&gt;
  &lt;li&gt;Create temporary file. Handle all possible exceptions.&lt;/li&gt;
  &lt;li&gt;Write data to that temporary file. Handle all possible exceptions.&lt;/li&gt;
  &lt;li&gt;Close temporary file. During that exceptions are also possible.&lt;/li&gt;
  &lt;li&gt;If all previous steps completes successfully, rename temporary file to existing file and handle all possible exceptions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Steps 1-3 can be combined together if there is a function available that creates file with given content.&lt;/p&gt;

&lt;p&gt;Following those steps prevents a lot of failures like insufficient disk space or reset during file saving.&lt;/p&gt;</content><author><name>Vyacheslav Enis</name><email>venis@difane.com</email></author><category term="Software Development" /><summary type="html">Create temporary file. Handle all possible exceptions. Write data to that temporary file. Handle all possible exceptions. Close temporary file. During that exceptions are also possible. If all previous steps completes successfully, rename temporary file to existing file and handle all possible exceptions.</summary></entry><entry><title type="html">Static Pages In Symfony</title><link href="https://venis.github.io/2012/12/11/static-pages-in-symfony.html" rel="alternate" type="text/html" title="Static Pages In Symfony" /><published>2012-12-11T00:00:00+02:00</published><updated>2012-12-11T00:00:00+02:00</updated><id>https://venis.github.io/2012/12/11/static-pages-in-symfony</id><content type="html" xml:base="https://venis.github.io/2012/12/11/static-pages-in-symfony.html">&lt;p&gt;Almost all websites have some kind of static pages that does not need any logic.
Usually they have empty controller that looks like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;aboutAction&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;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AcmeBundle:Pages:about.html.twig'&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;/figure&gt;

&lt;p&gt;You also need to reference them in the routing configuration:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;s&quot;&gt;about&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;pattern&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/about&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;defaults&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;_controller&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;AcmeBundle:Pages:about'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Annotations usage simplifies things but it still too much work:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;/**
 * @Route(&quot;/about&quot;, name=&quot;about&quot;)
 * @Template
 */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;aboutAction&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;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;array&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;/figure&gt;

&lt;p&gt;Instead that you can use built-in symfony’s controller &lt;strong&gt;FrameworkBundle:Template:template&lt;/strong&gt; and configure
everything right in the routing configuration file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;s&quot;&gt;about&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;pattern&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/about&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;defaults&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;_controller&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;FrameworkBundle:Template:template&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;AcmeBundle:Pages:about.html.twig'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If You look at the controllers source You will see that it simply renders passed template using &lt;strong&gt;templating&lt;/strong&gt; service:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TemplateController&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ContainerAware&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;templateAction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$template&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;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'templating'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;renderResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$template&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;/figure&gt;</content><author><name>Vyacheslav Enis</name><email>venis@difane.com</email></author><category term="Software Development" /><category term="symfony" /><summary type="html">Almost all websites have some kind of static pages that does not need any logic. Usually they have empty controller that looks like:</summary></entry><entry><title type="html">Initial Git Configuration</title><link href="https://venis.github.io/2012/11/11/initial-git-configuration.html" rel="alternate" type="text/html" title="Initial Git Configuration" /><published>2012-11-11T00:00:00+02:00</published><updated>2012-11-11T00:00:00+02:00</updated><id>https://venis.github.io/2012/11/11/initial-git-configuration</id><content type="html" xml:base="https://venis.github.io/2012/11/11/initial-git-configuration.html">&lt;p&gt;After Git is set up it is good idea to customize it.&lt;/p&gt;

&lt;h2 id=&quot;information-to-identify-yourself&quot;&gt;Information to identify Yourself&lt;/h2&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global user.name &lt;span class=&quot;s2&quot;&gt;&quot;John Doe&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global user.email johndoe@example.com&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;preferred-editor&quot;&gt;Preferred editor&lt;/h2&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global core.editor nano&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;diffmerge-tool&quot;&gt;Diff/Merge tool&lt;/h2&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global merge.tool kdiff3&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;prevent-some-possible-problems&quot;&gt;Prevent some possible problems&lt;/h2&gt;

&lt;p&gt;Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the
remote, and no refspec is implied by any of the options given on the command line. “Current” means push the current
branch to a branch of the same name.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global push.default current&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;useful-configuration&quot;&gt;Useful configuration&lt;/h2&gt;

&lt;p&gt;Here are some useful configuration values described.&lt;/p&gt;

&lt;p&gt;In addition to .gitignore (per-directory) and .git/info/exclude, git looks into this file for patterns of files which
are not meant to be tracked. “~/” is expanded to the value of $HOME and “~user/” to the specified user’s home directory&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global core.excludesfile &amp;lt;path to file&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Specify a file to use as the template for new commit messages. “~/” is expanded to the value of $HOME and “~user/”
to the specified user’s home directory.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git config --global commit.template &amp;lt;path to file&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;useful-commands&quot;&gt;Useful commands&lt;/h2&gt;

&lt;p&gt;Here are some useful commands described&lt;/p&gt;

&lt;p&gt;Displaying console graph log&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git log --oneline --graph --decorate&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Show a word diff highlighting changed words using only colors&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;&lt;span class=&quot;gp&quot;&gt;me@host$ &lt;/span&gt;git diff --word-diff&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;color&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;</content><author><name>Vyacheslav Enis</name><email>venis@difane.com</email></author><category term="Source Control" /><category term="git" /><category term="scm" /><summary type="html">After Git is set up it is good idea to customize it.</summary></entry></feed>