<?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: Philip Mutua</title>
    <description>The latest articles on DEV Community by Philip Mutua (@pmutua).</description>
    <link>https://dev.to/pmutua</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%2F117803%2F98f809b7-8e29-44be-83f8-5bf82b2bd098.jpeg</url>
      <title>DEV Community: Philip Mutua</title>
      <link>https://dev.to/pmutua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pmutua"/>
    <language>en</language>
    <item>
      <title>How to target desktop, tablet and mobile using Media Query ?</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Tue, 06 Sep 2022 06:22:26 +0000</pubDate>
      <link>https://dev.to/pmutua/how-to-target-desktop-tablet-and-mobile-using-media-query--15n7</link>
      <guid>https://dev.to/pmutua/how-to-target-desktop-tablet-and-mobile-using-media-query--15n7</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb0bjcx3uptk969hf8yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb0bjcx3uptk969hf8yd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
Media Query is a popular way for delivering a style sheet to different devices with different screen sizes and resolutions. They are used to alter the look of a website across numerous devices. A media query is made up of a media type and one or more expressions that can be true or false. If the supplied media matches the type of device on which the content is viewed, the query returns true. If the media query returns true, the style sheet is used.&lt;/p&gt;

&lt;p&gt;The screen resolutions of different devices are listed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile (Smartphone) max-width: 480px&lt;/li&gt;
&lt;li&gt;Low Resolution Tablets and ipads max-width: 767px&lt;/li&gt;
&lt;li&gt;Tablets Ipads portrait mode max-width:1024px&lt;/li&gt;
&lt;li&gt;Desktops max-width:1280px&lt;/li&gt;
&lt;li&gt;Huge size (Larger screen) max-width: 1281px and greater&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="k"&gt;@media&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="n"&gt;feature&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;CSS&lt;/span&gt; &lt;span class="nt"&gt;Property&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Assuming that you have a css file &lt;code&gt;style.css&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;


        &lt;span class="c"&gt;/* Media Query for Mobile Devices */&lt;/span&gt;
        &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;480px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;/* Media Query for low resolution  Tablets, Ipads */&lt;/span&gt;
        &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;481px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;767px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;/* Media Query for Tablets Ipads portrait mode */&lt;/span&gt;
        &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1024px&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;/* Media Query for Laptops and Desktops */&lt;/span&gt;
        &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1025px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1280px&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c"&gt;/* Media Query for Large screens */&lt;/span&gt;
        &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1281px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

</description>
      <category>media</category>
      <category>queries</category>
      <category>css</category>
      <category>responsive</category>
    </item>
    <item>
      <title>What is the difference between Promises and Observables?</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Fri, 29 Jul 2022 07:36:29 +0000</pubDate>
      <link>https://dev.to/pmutua/what-is-the-difference-between-promises-and-observables-323m</link>
      <guid>https://dev.to/pmutua/what-is-the-difference-between-promises-and-observables-323m</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9j3ap0ve508qzkyt9i9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9j3ap0ve508qzkyt9i9e.png" alt="rxjs logo"&gt;&lt;/a&gt;&lt;br&gt;
Both observables and promises help us work with &lt;strong&gt;asynchronous&lt;/strong&gt; functionality in JavaScript. Promises deal with one asynchronous event at a time, while observables handle a sequence of asynchronous events over a period of time.&lt;/p&gt;

&lt;p&gt;Here are the differences in concept between &lt;code&gt;Observables&lt;/code&gt; and &lt;code&gt;Promises&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observables&lt;/th&gt;
&lt;th&gt;Promises&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Emit multiple values over a period of time.&lt;/td&gt;
&lt;td&gt;Emit a single value at a time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Are lazy: they’re not executed until we subscribe to them using the subscribe() method.&lt;/td&gt;
&lt;td&gt;Are not lazy: execute immediately after creation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Have subscriptions that are cancellable using the unsubscribe() method, which stops the listener from receiving further values.&lt;/td&gt;
&lt;td&gt;Are not cancellable.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Provide the map, filter, reduce, retry, retryWhen, and so many other RxJS operators, that makes it easy to deal with Observables.&lt;/td&gt;
&lt;td&gt;Don’t provide any operations.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deliver errors to the subscribers.&lt;/td&gt;
&lt;td&gt;Push errors to the child promises.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;code snippets/examples of a few operations defined by observables and promises.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2to5pza0c5jsv8b0fp2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2to5pza0c5jsv8b0fp2.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rxjs</category>
    </item>
    <item>
      <title>I've completely replaced the need for Postman with this one extension in VS Code!</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Sat, 24 Apr 2021 23:10:51 +0000</pubDate>
      <link>https://dev.to/pmutua/i-ve-completely-replaced-the-need-for-postman-with-this-one-extension-in-vs-code-1oa9</link>
      <guid>https://dev.to/pmutua/i-ve-completely-replaced-the-need-for-postman-with-this-one-extension-in-vs-code-1oa9</guid>
      <description>&lt;p&gt;I've completely replaced the need for Postman with this one extension in VS Code! The &lt;a href="https://www.thunderclient.io/"&gt;Thunder Client extension&lt;/a&gt; for &lt;a href="https://code.visualstudio.com/"&gt;VS Code&lt;/a&gt;&lt;br&gt;
created by &lt;a href="https://mobile.twitter.com/ranga_vadhineni"&gt;@ranga_vadhineni&lt;/a&gt; can do everything I need to when testing HTTP Requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;create and send requests&lt;/li&gt;
&lt;li&gt;group requests into collections&lt;/li&gt;
&lt;li&gt;use variables&lt;/li&gt;
&lt;li&gt;much more!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.thunderclient.io/"&gt;Thunder Client&lt;/a&gt; &lt;/p&gt;

</description>
      <category>thunder</category>
      <category>client</category>
      <category>vscode</category>
      <category>extensions</category>
    </item>
    <item>
      <title>Aligning content in columns &amp; adding custom width with Angular</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Tue, 22 Sep 2020 18:17:07 +0000</pubDate>
      <link>https://dev.to/pmutua/align-left-and-right-in-mat-card-title-588g</link>
      <guid>https://dev.to/pmutua/align-left-and-right-in-mat-card-title-588g</guid>
      <description>&lt;p&gt;To apply custom width to columns we can create helper classes with width provided in pixels as shown below.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.w-75&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;75px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.w-100&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add any number of these custom width classes according to your requirements.&lt;/p&gt;

&lt;p&gt;After that just add them to the &lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt; element in the the table you created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matcolumnDef=&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-75"&lt;/span&gt; &lt;span class="na"&gt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; id &lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.id}} &lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ng-container&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Align Text in columns of data-table
&lt;/h3&gt;

&lt;p&gt;In your CSS file just create classes as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.th-center&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.th-left&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.th-right&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Which we can add to &lt;code&gt;th&lt;/code&gt; elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-75 th-center"&lt;/span&gt; &lt;span class="na"&gt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; id &lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.id}} &lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Data-Tables using Component Elements as shown below:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;mat-table&lt;/span&gt; &lt;span class="na"&gt;[dataSource]=&lt;/span&gt;&lt;span class="s"&gt;"dataList"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"mat-elevation-z8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt; &lt;span class="na"&gt;[ngClass]=&lt;/span&gt;&lt;span class="s"&gt;"'w-75'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; id &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt; &lt;span class="na"&gt;[ngClass]=&lt;/span&gt;&lt;span class="s"&gt;"'w-75'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.id}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; name &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.name}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; username &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.username}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; email &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.email}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"phone"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; phone &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.phone}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;matColumnDef=&lt;/span&gt;&lt;span class="s"&gt;"website"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-header-cell&lt;/span&gt; &lt;span class="na"&gt;*matHeaderCellDef&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; website &lt;span class="nt"&gt;&amp;lt;/mat-header-cell&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-cell&lt;/span&gt; &lt;span class="na"&gt;*matCellDef=&lt;/span&gt;&lt;span class="s"&gt;"let element"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{element.website}} &lt;span class="nt"&gt;&amp;lt;/mat-cell&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;mat-header-row&lt;/span&gt; &lt;span class="na"&gt;*matHeaderRowDef=&lt;/span&gt;&lt;span class="s"&gt;"displayedColumns"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/mat-header-row&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-row&lt;/span&gt; &lt;span class="na"&gt;*matRowDef=&lt;/span&gt;&lt;span class="s"&gt;"let row; columns: displayedColumns;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/mat-row&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-table&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We can use &lt;code&gt;[ngClass]&lt;/code&gt; directive to add classes to Column and Cells but instead of width, we need to use &lt;code&gt;max-width&lt;/code&gt; to columns as well as to cells because components use &lt;strong&gt;FLEX&lt;/strong&gt; layout to define widths.&lt;/p&gt;

&lt;p&gt;You can then update CSS classes to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
&lt;span class="nc"&gt;.w-75&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;75px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.w-100&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>angular</category>
      <category>css</category>
    </item>
    <item>
      <title>Run MySQL on Port 3307 Using Docker Compose</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Thu, 17 Sep 2020 09:57:01 +0000</pubDate>
      <link>https://dev.to/pmutua/run-mysql-on-port-3307-using-docker-compose-gf8</link>
      <guid>https://dev.to/pmutua/run-mysql-on-port-3307-using-docker-compose-gf8</guid>
      <description>&lt;p&gt;Sometimes you would like to run MySQL image on different port other than the default one &lt;strong&gt;3306&lt;/strong&gt;. Suppose you have deployed your back-end application on a server and you find out that there is another service running on port &lt;strong&gt;3306&lt;/strong&gt;. That was my situation a while back and to solve this I just added the variable &lt;code&gt;MYSQL_TCP_PORT: 3307&lt;/code&gt; under the MYSQL image &lt;code&gt;environments:&lt;/code&gt; section as shown below on docker-compose.yml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
  &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql:5.7&lt;/span&gt;

    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;--default-authentication-plugin=mysql_native_password&lt;/span&gt;

    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test#$!&lt;/span&gt;
      &lt;span class="na"&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default_schema&lt;/span&gt;
      &lt;span class="na"&gt;MYSQL_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;
      &lt;span class="na"&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;
      &lt;span class="na"&gt;MYSQL_TCP_PORT&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3307&lt;/span&gt;

    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3307:3307"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Make sure in your application's DB settings you change the database port settings in my case I was developing the back-end service with Django framework here are the settings below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;DATABASES = {&lt;/span&gt;
    &lt;span class="s"&gt;'default'&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENGINE'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.db.backends.mysql'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; 
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NAME'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default_schema'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;USER'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;root'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PASSWORD'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;test#$!'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;HOST'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;db'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PORT'&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3307'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Working with Multiple Containers Using Docker Compose on Linux with Django and NGINX</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Fri, 11 Sep 2020 13:54:51 +0000</pubDate>
      <link>https://dev.to/pmutua/working-with-multiple-containers-using-docker-compose-on-linux-2299</link>
      <guid>https://dev.to/pmutua/working-with-multiple-containers-using-docker-compose-on-linux-2299</guid>
      <description>&lt;p&gt;In this article we’re going to explore how to segment our app into a small network of multiple Docker containers, each with their own images.&lt;/p&gt;

&lt;p&gt;Single containers are easy enough to build imperatively in the command line, but doing anything more complicated can quickly get out of hand. Instead we’re going to use a new special type of config file called &lt;code&gt;docker-compose.yml&lt;/code&gt;. This declarative approach will allow us to quickly define our images in each container and setup the networking between them.&lt;/p&gt;

&lt;p&gt;In this example we’re going to be setting up an &lt;strong&gt;NGINX&lt;/strong&gt; server, a &lt;strong&gt;Django&lt;/strong&gt; server.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;It would be helpful to know how to build images with &lt;strong&gt;Dockerfile&lt;/strong&gt;, which you can &lt;a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/"&gt;brush up on here&lt;/a&gt;, but that will mostly be taken care of in the starter.&lt;/p&gt;

&lt;p&gt;Make sure the following are installed in your local machine&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://pypi.org/project/virtualenv/1.6.4/"&gt;virtualenv&lt;/a&gt;  - for Python local environment&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/compose/install/"&gt;Docker Compose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.python.org/"&gt;Python&lt;/a&gt; - Should be installed in your system to run virtualenv.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Project Structure
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── botservice/
├── core
|   ├── core/
│   │    ├── __init__.py
│   │    ├── asgi.py
│   │    ├── settings.py
│   │    ├── urls.py
│   │    ├── wsgi.py
│   │ 
│   └── Dockerfile
│   │ 
│   └── db.sqlite3
│   ├── manage.py
│   └── requirements.txt
├── nginx
│   ├── default.conf
│   └── Dockerfile
├── env/
├──docker-compose.yml

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Starter Setup
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a directory in your workspace eg. &lt;code&gt;botserver&lt;/code&gt; navigate to your directory &lt;code&gt;cd botserver&lt;/code&gt; using the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Activate virtual environment&lt;/strong&gt; - run &lt;code&gt;virtualenv -p python env&lt;/code&gt;. Then to activate virtual environment run &lt;br&gt;
&lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install &lt;strong&gt;Django&lt;/strong&gt; into the virtual environment by running &lt;code&gt;pip install Django&lt;/code&gt; it will install the latest version of Django framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create Django project run &lt;code&gt;django-admin startproject core&lt;/code&gt; &lt;strong&gt;core&lt;/strong&gt; is the name of our project. Inside the core folder where &lt;code&gt;manage.py&lt;/code&gt; is located create a file called &lt;code&gt;requirements.txt&lt;/code&gt; this is where we add our Python dependencies they will be installed when docker runs builds, in the requirements.txt file add the dependencies as shown below:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Django==3.1.1
gunicorn==20.0.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gunicorn 'Green Unicorn' is a Python &lt;code&gt;WSGI&lt;/code&gt; HTTP Server for UNIX.&lt;/p&gt;

&lt;h1&gt;
  
  
  NGINX Setup
&lt;/h1&gt;

&lt;p&gt;The NGINX server is different than the other containers. NGINX will act as the router for the server, directing requests to the server container.&lt;/p&gt;

&lt;p&gt;In a special configuration file, &lt;code&gt;default.conf&lt;/code&gt;, we’ll use &lt;code&gt;upstream&lt;/code&gt; to tell NGINX on what server port each the container is running. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a folder called &lt;code&gt;nginx&lt;/code&gt; in the &lt;code&gt;botservice&lt;/code&gt; folder, inside &lt;code&gt;botservice&lt;/code&gt; folder in the terminal run &lt;code&gt;mkdir nginx&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate inside the newly created folder &lt;code&gt;nginx&lt;/code&gt; and create a file called &lt;code&gt;default.conf&lt;/code&gt; and add the following code.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;upstream&lt;/span&gt; &lt;span class="s"&gt;botservice&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="nf"&gt;botservice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;7000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_pass&lt;/span&gt; &lt;span class="s"&gt;http://botservice/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;X-Forwarded-For&lt;/span&gt; &lt;span class="nv"&gt;$proxy_add_x_forwarded_for&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Host&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_redirect&lt;/span&gt; &lt;span class="no"&gt;off&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_connect_timeout&lt;/span&gt;       &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_send_timeout&lt;/span&gt;          &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;proxy_read_timeout&lt;/span&gt;          &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;send_timeout&lt;/span&gt;                &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we just need docker to put this configuration somewhere more useful. The NGINX container will already have an empty &lt;code&gt;default.conf&lt;/code&gt; file, so copying ours to its location will override the old one.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;Dockerfile&lt;/code&gt; inside the nginx folder add the following to the &lt;code&gt;Dockerfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; nginx&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /usr/share/nginx/html/&lt;span class="k"&gt;*&lt;/span&gt;


&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt;  ./default.conf  /etc/nginx/conf.d/default.conf&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We also need to add a Dockerfile for the Django server &lt;br&gt;
inside the core directory where &lt;code&gt;manage.py&lt;/code&gt; file is located add a file called &lt;code&gt;Dockerfile&lt;/code&gt; then add the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.8-slim-buster&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PYTHONDONTWRITEBYTECODE 1&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PYTHONUNBUFFERED 1&lt;/span&gt;


&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /src&lt;/span&gt;


&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt /src/&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt


&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Docker Compose
&lt;/h1&gt;

&lt;p&gt;Create a file called &lt;code&gt;docker-compose.yml&lt;/code&gt; inside the &lt;strong&gt;botservice&lt;/strong&gt; folder and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3'&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;botservice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;botservice&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./core&lt;/span&gt;

    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sh -c "gunicorn --bind 0.0.0.0:7000 core.wsgi:application"&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./core/:/src/"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;static_volume:/src/static&lt;/span&gt;

    &lt;span class="na"&gt;expose&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;7000"&lt;/span&gt;


  &lt;span class="na"&gt;nginx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./nginx&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;80:80"&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;static_volume:/src/static&lt;/span&gt; 

    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;botservice&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;static_volume&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Let’s go over exactly what this is trying to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;service&lt;/code&gt; - Declares each container with its particular configuration, which we can name however we like.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build&lt;/code&gt; - Tells how we want our container built, in this case which file to use and where it is with dockerfile and context.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;restart&lt;/code&gt; - Tells Docker what to do if a container fails during runtime, in this case we always want it to attempt to restart.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ports&lt;/code&gt; - Remaps whatever port we want to the default port, just like the -p flag when working in the terminal.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;volumes&lt;/code&gt; - Are the persistent data connected to each container. We’re duplicating parts of our container and its dependencies in a way that when we throw the container away and start a new one it’ll have that cache to avoid the time of reinstalling everything.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;depends_on&lt;/code&gt; - Express dependency between services, which has two effects:&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;container_name&lt;/code&gt; - Specify a custom container name, rather than a generated default name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expose&lt;/code&gt; - Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;command&lt;/code&gt; - Override the default command.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://docs.docker.com/compose/compose-file/"&gt;More info about Docker Compose file.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we can create our services and attach our containers together using the &lt;code&gt;docker-compose up&lt;/code&gt; command and the &lt;code&gt;--build&lt;/code&gt; flag to build out our Dockerfiles.&lt;/p&gt;

&lt;p&gt;Navigate to where the &lt;code&gt;docker-compose.yml&lt;/code&gt; file is located via terminal and run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose up --build&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Closing Thoughts
&lt;/h1&gt;

&lt;p&gt;This may have been a very simple use case, but Docker Compose is definitely one of the major tools you’ll be using with almost all of your Docker projects. &lt;a href="https://github.com/pmutua/botserver.git"&gt;You can check out a demo here to see how I did it when developing some chatbot.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>nginx</category>
      <category>docker</category>
      <category>django</category>
    </item>
    <item>
      <title>Pushing a Docker container image to Docker Hub🔗</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Fri, 11 Sep 2020 10:13:50 +0000</pubDate>
      <link>https://dev.to/pmutua/pushing-a-docker-container-image-to-docker-hub-m3p</link>
      <guid>https://dev.to/pmutua/pushing-a-docker-container-image-to-docker-hub-m3p</guid>
      <description>&lt;p&gt;To push an image to Docker Hub, you must first name your local image using your Docker Hub username and the repository name that you created through Docker Hub on the web.&lt;/p&gt;

&lt;p&gt;You can add multiple images to a repository by adding a specific :&lt;code&gt;&amp;lt;tag&amp;gt;&lt;/code&gt; to them (for example &lt;code&gt;docs/base:testing&lt;/code&gt;). If it’s not specified, the tag defaults to latest.&lt;/p&gt;

&lt;p&gt;Name your local images using one of these methods:&lt;/p&gt;

&lt;p&gt;When you build them, using &lt;code&gt;docker build -t &amp;lt;hub-user&amp;gt;/&amp;lt;repo-name&amp;gt;[:&amp;lt;tag&amp;gt;]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By re-tagging an existing local image &lt;code&gt;docker tag &amp;lt;existing-image&amp;gt; &amp;lt;hub-user&amp;gt;/&amp;lt;repo-name&amp;gt;[:&amp;lt;tag&amp;gt;]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By using &lt;code&gt;docker commit &amp;lt;existing-container&amp;gt; &amp;lt;hub-user&amp;gt;/&amp;lt;repo-name&amp;gt;[:&amp;lt;tag&amp;gt;]&lt;/code&gt; to commit changes&lt;/p&gt;

&lt;p&gt;Now you can push this repository to the registry designated by its name or tag.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker push &amp;lt;hub-user&amp;gt;/&amp;lt;repo-name&amp;gt;:&amp;lt;tag&amp;gt;&lt;/code&gt;&lt;br&gt;
The image is then uploaded and available for use by your teammates and/or the community.&lt;/p&gt;

</description>
      <category>docker</category>
    </item>
    <item>
      <title>Regex for Kenyan Phone Number format 07XXXXXXXX in Python</title>
      <dc:creator>Philip Mutua</dc:creator>
      <pubDate>Thu, 10 Sep 2020 06:08:51 +0000</pubDate>
      <link>https://dev.to/pmutua/regex-for-kenyan-phone-number-format-07xxxxxxxx-4c6f</link>
      <guid>https://dev.to/pmutua/regex-for-kenyan-phone-number-format-07xxxxxxxx-4c6f</guid>
      <description>&lt;h1&gt;
  
  
  Regex for Kenyan Phone Number format
&lt;/h1&gt;

&lt;p&gt;The common formats that people use to represent mobile phone numbers: &lt;code&gt;07xxxxxxxx&lt;/code&gt;, &lt;code&gt;+2547xxxxxxxx&lt;/code&gt; or &lt;code&gt;+2547xxxxxxxx&lt;/code&gt; or &lt;code&gt;7xxxxxxxx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this tutorial I will show you how to check a phone number matches in the following format &lt;code&gt;07xxxxxxxx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are going to import &lt;code&gt;re&lt;/code&gt; Python module to achieve this. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;import re&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The we define the regular expression pattern that will check if the phone number matches. The Pattern is normally a string.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pattern = "^0(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's it we have the pattern defined.&lt;/p&gt;

&lt;p&gt;Then we are going to define our matched variable. &lt;code&gt;phone_number&lt;/code&gt; variable is the number we want to check if it matches.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;phone_number = "0700000000"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are using the &lt;code&gt;re.match()&lt;/code&gt;  function which checks if zero or more characters at the beginning of string match the regular expression pattern, returns a corresponding match object. Then returns &lt;code&gt;None&lt;/code&gt; if the string does not match the pattern.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;matched = re.match(pattern,phone_number)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's check &lt;/p&gt;

&lt;p&gt;&lt;code&gt;is_match = bool(matched)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will return a boolean &lt;code&gt;True&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;And there you go  ;)&lt;/p&gt;

</description>
      <category>regex</category>
      <category>python</category>
    </item>
  </channel>
</rss>
