<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Todor Todorov</title>
    <description>The latest articles on DEV Community by Todor Todorov (@tttfifo).</description>
    <link>https://dev.to/tttfifo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F208101%2F1ee0b4e9-11fd-42b7-b1f1-5aa62922e177.png</url>
      <title>DEV Community: Todor Todorov</title>
      <link>https://dev.to/tttfifo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tttfifo"/>
    <language>en</language>
    <item>
      <title>Which Python Version is Your Live Project Using?</title>
      <dc:creator>Todor Todorov</dc:creator>
      <pubDate>Tue, 27 Aug 2019 05:41:46 +0000</pubDate>
      <link>https://dev.to/tttfifo/which-python-version-is-your-live-project-using-5d35</link>
      <guid>https://dev.to/tttfifo/which-python-version-is-your-live-project-using-5d35</guid>
      <description>&lt;p&gt;Not long ago - about &lt;strong&gt;three years ago&lt;/strong&gt;, whenever someone asked me which Python version should be used for our new project? - I would replay: we start Python 2.7 and later on maybe move to Python 3.x.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One year ago&lt;/strong&gt; I received similar question: should we start our new project with version 2? - I was very confident in my reply: Nope, we start 3.6 as the proven stable 3 version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Today&lt;/strong&gt;, believe me or not, for starting a project I would already recommend Python 3.7.&lt;/p&gt;

&lt;p&gt;My current thoughts on Python versioning are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;2.7&lt;/strong&gt; is &lt;strong&gt;very stable&lt;/strong&gt; and &lt;strong&gt;performant&lt;/strong&gt;, but will &lt;strong&gt;not be supported&lt;/strong&gt; after 2020.&lt;/li&gt;
&lt;li&gt;I have the feeling &lt;strong&gt;3.6&lt;/strong&gt; is used in &lt;strong&gt;most new projects&lt;/strong&gt; today. Is my feeling right?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3.7&lt;/strong&gt; has many standard &lt;strong&gt;library improvements&lt;/strong&gt; and the &lt;strong&gt;performance is competitive with 2.7&lt;/strong&gt; - see &lt;a href="https://hackernoon.com/which-is-the-fastest-version-of-python-2ae7c61a6b2b"&gt;here&lt;/a&gt;. These I know also from experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python &amp;gt;= 3.8&lt;/strong&gt;: After &lt;a href="https://mail.python.org/pipermail/python-committers/2018-July/005664.html"&gt;the BDFL proudly left the building&lt;/a&gt;, and I say this with really high respect to &lt;a href="https://gvanrossum.github.io/"&gt;Mr.Rossum&lt;/a&gt;, a new &lt;a href="https://www.python.org/dev/peps/pep-8016/"&gt;governance model&lt;/a&gt; was introduced. I am looking forward to see if this will have negative / positive effect or no effect at all. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My questions for you are:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Which Python version is your current live project using?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Which version would you recommend for starting a new project?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Simplicity to the Rescue (My New Personal Site)</title>
      <dc:creator>Todor Todorov</dc:creator>
      <pubDate>Thu, 22 Aug 2019 16:16:02 +0000</pubDate>
      <link>https://dev.to/tttfifo/simplicity-to-the-rescue-my-new-personal-site-2ipj</link>
      <guid>https://dev.to/tttfifo/simplicity-to-the-rescue-my-new-personal-site-2ipj</guid>
      <description>&lt;p&gt;Bored with the complexity in our life... No, let me start over:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;...our super high technologically smart fast pacing enormously artificially intelligent algorithmic innovative life...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Long story short: I decided to make my &lt;a href="https://ttt-fifo.github.io/"&gt;new personal site&lt;/a&gt; simple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do you think? Simple, no?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S:&lt;/strong&gt; For the creation I used the cutting edge newest versions of these enormously almost artificially intelligent tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;vim (the latest cutting edge version)&lt;/li&gt;
&lt;li&gt;an unknown to me until now command line tool, called 'boxes' (unknown version)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here you can see a &lt;a href="https://dev.to/tttfifo/comment/eaf4"&gt;screenshot of my high-tech development IDE&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would love to hear from you what do you think about my site, also about the simplicity or complexity in our life, the universe and everything.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>discuss</category>
      <category>jokes</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Configuration Templating Language</title>
      <dc:creator>Todor Todorov</dc:creator>
      <pubDate>Mon, 19 Aug 2019 19:52:04 +0000</pubDate>
      <link>https://dev.to/tttfifo/configuration-templating-language-51m6</link>
      <guid>https://dev.to/tttfifo/configuration-templating-language-51m6</guid>
      <description>&lt;p&gt;Have you ever been in a situation where you need to write multiple configuration files manually? I have been managing multiple router configurations. The routers were following the same pattern, but each one of them had to have different opened / filtered ports, Network Address Translation rules, different routes, etc.&lt;/p&gt;

&lt;p&gt;This could be resolved by using a configuration file template and some scripting to push variable data into the template. While jinja templates and python scripts may be a fairly good solution, I was still struggling with two questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does a simpler and more powerful templating language for re-writing configurations exist out there?&lt;/li&gt;
&lt;li&gt;Is there a simple command line tool for templating?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As I could not find satisfactory answers to my questions, I decided to start this project called &lt;a href="https://github.com/ttt-fifo/conftl"&gt;conftl - Configuration Templating Language&lt;/a&gt;. Let me give some examples how to use conftl.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 1: Open Network Ports on Firewall
&lt;/h2&gt;

&lt;p&gt;I do not want to bother you with all the router details, so I will show only simple Linux iptables firewall example.&lt;br&gt;
The template file firewall.tmpl is created with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ... other iptables rules ...

{{for dport in dports:}}
-A INPUT -i eth0 -p tcp --dport {{=dport}} -m state --state NEW,ESTABLISHED -j ACCEPT
{{pass}}

# ... other iptables rules ...

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What do we have in this template? We see that we can embed python code, wrapped with&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{{...}}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 So what this means? - everyone who has some idea of the Python syntax (and the Python syntax is a really clean one), could embed Python constructs into the template. Possibilities are endless: conditional expressions if - else, while and for loops, assigning values to variables, even function definitions are possible in template.&lt;/p&gt;

&lt;p&gt;What else we see in there? The construct&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{{=dport}}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 is somehow weird. This is how we print a variable value to the output configuration file.&lt;/p&gt;

&lt;p&gt;The other funny thing is the special keyword&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{{pass}}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 which indicates where our for loop block ends.&lt;/p&gt;

&lt;p&gt;Generally we just templated one Python for loop, which prints to the output config file one iptables rule per each port in dports. Now we need a way to render the template and specify which network ports to open. This can be done using the command line utility 'render':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ render -i firewall.tmpl -c "dports=[22, 80, 8080, 443]"

-i firewall.tmpl where to get the template from
-c "dports=[...]" gives the list with the ports to open
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The output will be printed to the screen for debug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ... other iptables rules ...

-A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT

# ... other iptables rules ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In real situation you would want to give an output file also:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ render -i firewall.tmpl -o firewall.conf -c "dports=[22, 80, 8080, 443]"

-o firewall.conf where to write the configuration file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Example 2: Nginx Proxy
&lt;/h2&gt;

&lt;p&gt;Imagine you need to dynamically configure your reverse proxy. The example template would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ... other nginx configurations

&amp;lt;%for loc in locations:%&amp;gt;
&amp;lt;%server_port = locations[loc]%&amp;gt;
        location /&amp;lt;%=loc%&amp;gt; {
            rewrite ^/&amp;lt;%=loc%&amp;gt;(.*) /$1 break;
            proxy_pass http://&amp;lt;%=server_port%&amp;gt;;
        }
&amp;lt;%pass%&amp;gt;

# ... other nginx configurations
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here you do not see the&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{{...}}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 pattern. Nginx configuration file uses&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 brackets for opening/closing the blocks, so we may use different delimiters&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;"&amp;lt;% %&amp;gt;"&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 for better visibility.&lt;/p&gt;

&lt;p&gt;In this example we will not give the values of the 'locations' variable at the command line. I will create another text file containing the json context. Context means assigning values to the template variables. Lets create the file 'nginx.ctx':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"locations": {"blog": "192.168.43.15:8081",
               "mail": "192.168.43.15:8082"}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After running the command line tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ render -i nginx.tmpl -j nginx.ctx -d "&amp;lt;% %&amp;gt;"

-j tells render where to get json context from
-d "&amp;lt;% %&amp;gt;" instructs render for the delimiters we are currently using
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;we will receive the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ... other nginx configurations

        location /blog {
            rewrite ^/blog(.*) /$1 break;
            proxy_pass http://192.168.43.15:8081;
        }
        location /mail {
            rewrite ^/mail(.*) /$1 break;
            proxy_pass http://192.168.43.15:8082;
        }

# ... other nginx configurations
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Installation, Advanced Usage, More Examples
&lt;/h2&gt;

&lt;p&gt;I presented two examples just for taste what conftl is. More information and advanced usage cases may be found at the project repository:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ttt-fifo/conftl"&gt;https://github.com/ttt-fifo/conftl&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I was searching for a simple, but powerful solution to template my configuration files. I find delightful the possibility to embed Python code into the template. I also find it convenient to have a command line tool for rendering templates. I would be happy if other people also like this approach and start using &lt;a href="https://github.com/ttt-fifo/conftl"&gt;conftl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Love to hear your opinion and comments.&lt;/p&gt;

</description>
      <category>python</category>
      <category>devops</category>
      <category>showdev</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
