<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bee0l@ on Medium]]></title>
        <description><![CDATA[Stories by Bee0l@ on Medium]]></description>
        <link>https://medium.com/@Beee_sama?source=rss-3dd4065ab8be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OJyp1D3aA3sCz-hY.jpeg</url>
            <title>Stories by Bee0l@ on Medium</title>
            <link>https://medium.com/@Beee_sama?source=rss-3dd4065ab8be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:14:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Beee_sama/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Traefik to the rescue]]></title>
            <link>https://awstip.com/traefik-to-the-rescue-c69b066cef05?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/c69b066cef05</guid>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Fri, 20 May 2022 08:17:02 GMT</pubDate>
            <atom:updated>2022-05-25T06:42:08.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3pGnCMdIC9kYd91Mz7e9A.png" /><figcaption>how traefik (pronounced traffic) works</figcaption></figure><p>There was a NextJS application I wrote, which I needed to be available on the path /classes from an existing Django application in production. I needed to ensure that all routes matching /classes are forwarded down to the NextJS application (including all the static assets provided by NextJS).</p><p>I was initially able to solve this using the following Nginx config</p><pre>upstream app {</pre><pre>  server app-lb:8000 weight=3;</pre><pre>}</pre><pre>upstream next-app{</pre><pre>  server next-app:3000;</pre><pre>}</pre><pre>server{<br>  ...<br>   location / {</pre><pre>      try_files $uri $uri.html @proxy_to_next;</pre><pre>   }</pre><pre>   location @proxy_to_next{</pre><pre>      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</pre><pre>      proxy_set_header Host $http_host;</pre><pre>      proxy_redirect off;</pre><pre>      proxy_pass   http://next-app;</pre><pre>      proxy_intercept_errors on;</pre><pre>      recursive_error_pages on;</pre><pre>      error_page 404 = @proxy_to_app;</pre><pre>   }<br>   location @proxy_to_app {</pre><pre>      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</pre><pre>      proxy_set_header Host $http_host;</pre><pre>      proxy_redirect off;</pre><pre>      proxy_pass   http://app;</pre><pre>   }</pre><pre>}</pre><p>From the above config, all routes are initially forwarded down to the NextJS proxy and whichever throws a 404 error, is further proxied down to the Django nginx block.<br>This approach worked for versions of NextJS earlier than 9.5 but became an issue from version 9.6 when <a href="https://nextjs.org/docs/api-reference/next.config.js/trailing-slash">NextJS began adding trailing / on each urls.</a></p><p>After a number of attempts to get the above config working, I initially gave up and made use of a custom sub-domain in handling all traffic for the NextJS application and then created a redirect route in Django from /classes to the subdomain classes.example.com/classes until I stumbled upon <a href="https://doc.traefik.io/traefik/">Traefik</a>.</p><p>After glancing through the documentation, I was able to easily come up with a solution that just worked.</p><pre>entryPoints:</pre><pre>  web:</pre><pre>  # http</pre><pre>    address: &quot;:80&quot;</pre><pre>    http:</pre><pre>      redirections:</pre><pre>        entryPoint:</pre><pre>          to: web-secure</pre><pre>  web-secure:</pre><pre>  # https</pre><pre>    address: &quot;:443&quot;</pre><pre>certificatesResolvers:</pre><pre>  letsencrypt:</pre><pre>    acme:</pre><pre>      email: &quot;biola@example.com&quot;</pre><pre>     storage: /etc/traefik/acme/acme.json</pre><pre>     httpChallenge:</pre><pre>       entryPoint: web</pre><pre>http:</pre><pre>  routers:</pre><pre>    next-new-router:</pre><pre>      rule: &quot;(Host(`example.com`) || Host(`www.example.com`)) &amp;&amp; (PathPrefix(`/classes`) || PathPrefix(`/api/groups`) || PathPrefix(`/_next`) )&quot;</pre><pre>      entryPoints:</pre><pre>        - web-secure</pre><pre>     service: next-app</pre><pre>     tls:</pre><pre>       certResolver: letsencrypt</pre><pre>    web-secure-router:</pre><pre>      rule: &quot;Host(`example.com`) || Host(`www.example.com`)&quot;</pre><pre>      entryPoints:</pre><pre>        - web-secure</pre><pre>      service: django</pre><pre>      tls:</pre><pre>        certResolver: letsencrypt</pre><pre>  services:</pre><pre>    django:</pre><pre>      loadBalancer:</pre><pre>        servers:</pre><pre>          - url: http://app-lb:8000</pre><pre>   next-app:<br>     loadBalancer:<br>       servers:<br>          - url: http://next-app:3000</pre><p>I needed to ensure all the paths <strong>(including the API paths used by nextjs) </strong>required to get the NextJS application functional where all intercepted by next-new-router and forwarded down to the next-app service.</p><p>Traefik does a lot more but for now, it solves my problem in the most elegant way I could possible think of.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c69b066cef05" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/traefik-to-the-rescue-c69b066cef05">Traefik to the rescue</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving Frontend deployment workflow in a legacy Django application.]]></title>
            <link>https://medium.com/@Beee_sama/improving-frontend-deployment-workflow-in-a-legacy-django-application-1000cfc76771?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/1000cfc76771</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[cra]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[vercel]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Thu, 19 May 2022 10:21:00 GMT</pubDate>
            <atom:updated>2022-05-19T10:21:00.033Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tFa2V1gcNtd1tuhnDQLnw.png" /></figure><p><a href="https://vercel.com/">Vercel</a> can act as a Content Delivery Network to existing web applications. it is relatively easy to deploy all frontend application assets and a unique URL is provided. With this, I decided to leverage this behavior for a Django web application I have been working on for a while.</p><p>Create React App provides a file asset-manifest.json after every build. This file consist of the list of frontend assets used. So on deployment to Vercel, accessing this file is as easy as referencing &lt;vercel-deploymen-url&gt;/asset-manifest.json</p><p>A sample asset-manifest.json consist of the following</p><pre>{<br>  files: {<br>     main.css: &quot;/static/css/main.b3b94338.chunk.css&quot;,<br>     main.js: &quot;/static/js/main.6cde10bf.chunk.js&quot;,<br>     static/media/katex.min.css: &quot;/static/media/KaTeX_Typewriter-Regular.c5c02d76.ttf&quot;<br>},<br>entrypoints: [<br>    &quot;static/js/runtime-main.2ad4f5b9.js&quot;,<br>    &quot;static/css/2.4a8ef3f6.chunk.css&quot;,<br>    &quot;static/js/2.d019133c.chunk.js&quot;,<br>    &quot;static/css/main.b3b94338.chunk.css&quot;,<br>    &quot;static/js/main.6cde10bf.chunk.js&quot;<br>  ]<br>}</pre><p>From the above, it is relatively easy to write a function in python that fetches this file and parses out the JavaScript and CSS which would then be populated in the Django templates.</p><p>A sample Django template partial, handling the assets rendering looks like this</p><pre>{% if debug %}<br>   &lt;script src=&quot;http://localhost:3000/static/js/bundle.js&quot;&gt;&lt;/script&gt;</pre><pre>   &lt;script src=&quot;http://localhost:3000/static/js/vendors~main.chunk.js&quot;&gt;&lt;/script&gt;</pre><pre>   &lt;script src=&quot;http://localhost:3000/static/js/main.chunk.js&quot;&gt;&lt;/script&gt;</pre><pre>{% else %}<br>  {% for js_file in static_assets.css %}</pre><pre>     &lt;link href=&quot;{{s_host}}/{{js_file}}&quot; rel=&quot;stylesheet&quot;&gt;&lt;/link&gt;</pre><pre>  {% endfor %}<br>  {% for js_file in static_assets.js %}</pre><pre>      &lt;script src=&quot;{{s_host}}/{{js_file}}&quot;&gt;&lt;/script&gt;</pre><pre>  {% endfor %}</pre><pre>{% endif %}</pre><p>An entry for the required variables, shost and static_assets can be provided in a django context_processor.py file</p><pre>from django.settings import vercel_cdn,DEBUG</pre><pre><br>def get_static_assets():</pre><pre>   result = {&quot;css&quot;: [], &quot;js&quot;: []}</pre><pre>    response = requests.get(f&quot;{vercel_cdn}/asset-manifest.json&quot;)</pre><pre>    if response.status_code &lt; 400:</pre><pre>        data = response.json()</pre><pre>        result[&quot;css&quot;] = [x for x in data[&quot;entrypoints&quot;] if x.endswith(&quot;.css&quot;)]</pre><pre>        result[&quot;js&quot;] = [x for x in data[&quot;entrypoints&quot;] if x.endswith(&quot;.js&quot;)]</pre><pre>     return result</pre><pre><br>static_assets = get_static_assets() </pre><pre># context processor dictionary</pre><pre>def context_processor(request):<br>   ....<br>   return {<br>      &quot;static_assets&quot;:static_assets,<br>      &quot;s_host&quot;:vercel_cdn,<br>      &quot;debug&quot;:DEBUG</pre><pre>   }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1000cfc76771" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scaling Frontend codebase (without sacrificing DX).]]></title>
            <link>https://medium.com/@Beee_sama/scaling-frontend-codebase-without-sacrificing-dx-ed6630d372bf?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed6630d372bf</guid>
            <category><![CDATA[gitsubmodule]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[netlify]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 09:28:04 GMT</pubDate>
            <atom:updated>2019-03-20T09:28:04.992Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine a frontend codebase as a single repository consisting of 3 sub applications,</p><ol><li>the marketing pages application built with <a href="https://nextjs.org/">NextJS</a>,</li><li>the UI library, which houses the design system used by all apps</li><li>the product/main app built with <a href="https://facebook.github.io/create-react-app/">Creact React App</a>.</li><li>An internal shared library used across applications. We would call this shared-lib</li></ol><p><a href="https://yarnpkg.com/lang/en/docs/workspaces/">Yarn workspace</a> was used in wiring up these applications, so that a single yarn install pulls all the necessary dependencies required by all the different applications and libraries. Each application is a NodeJS package and has its own internal script commands for deployment.</p><p>These scripts are then aggregated in the root package.json</p><p><strong>repo/packages/ui-lib</strong></p><pre>{ <br>    &quot;name&quot;: &quot;ui-lib&quot;, <br>    ..., <br>    &quot;scripts&quot;:{ <br>        &quot;build&quot;: &quot;build-storybook -s public&quot; <br>    }, <br>    ... <br>}</pre><p><strong>repo/package.json</strong></p><pre>{ <br>    &quot;private&quot;: true, <br>    &quot;workspaces&quot;: [ &quot;packages/*&quot; ], <br>    &quot;scripts&quot;: { <br>        &quot;build:ui_lib&quot;: &quot;yarn workspace ui_lib build&quot;, <br>     ... <br>    } <br>}</pre><h3>The development build process</h3><p>The UI library, built with <a href="https://storybook.js.org/">Storybook</a>, is supposed to be shared with both the marketing-pages app as well as the main-app application. All visual elements/pages used by sub applications are housed and developed in this package.</p><p>Getting this library to be used as a dependency, in both the marketing-pages app and the main-app application, wasn’t straight forward because, the main-app was built with Create React App and the marketing app was built with NextJS, both of which by default have a pre-defined way of finding dependencies.</p><blockquote><em>Create React App is a zero-config approach to building ReactJS applications. By default, the only way you can get a dependency into a react application, is by installing it from npm. This was what </em><em>main-app was built with.</em></blockquote><p>Getting main-app to detect ui-lib as a dependency could be achieved, but requires a lot of overhead. At development time, changes are often made to both UI Library as well as main-app, so near instant feedback was very essential.</p><p>Using Yarn workspaces, all application packages i.e (ui-lib, marketing-pages, main-app) were automatically symlinked in the root node_modules. This means they can be referenced easily across packages.</p><p>The issue was getting the Create React App setup for main-app, to compile the React components provided by ui-lib, without having to eject. <a href="https://github.com/timarney/react-app-rewired">React App Rewired</a> made this possible. It provides an extension to the internal Webpack config used by Create React App so that it can be extended.</p><blockquote><a href="https://github.com/timarney/react-app-rewired"><em>React App Rewired</em></a><em> allows for simple extensions while still defaulting to Create React App for all the heavy lifting. While there are other options, it is the least invasive approach in my opinion.</em></blockquote><p>Create React App needs to know where to look, to find all the the directories that needs to be compiled. <em>(The default is the </em><em>src directory of the app)</em></p><p>Since the folder structure of the root repository looks somewhat like this</p><pre>├── node_modules <br>├── .git <br>├── packages <br>| ├── ui-lib <br>| | └── node_modules <br>| | └── src <br>| | └── package.json <br>| └── main-app <br>| | └── node_modules <br>| | └── public <br>| | └── src <br>| | └── config-overrides.js <br>| | └── package.json <br>| └── marketing-app <br>| | └── node_modules <br>| | └── pages <br>| | └── next.config.js <br>| | └── package.json <br>| └── shared-app <br>| | └── src <br>| | └── package.json <br>├── .gitignore <br>└── package.json</pre><p><strong>main app </strong><strong>config-overrides.js implementation.</strong></p><pre>const path = require(&#39;path&#39;); <br>... <br>function compileLinkNodeModules(config, env) { <br>  config.module.rules[2].oneOf[1].include = [     <br>     path.resolve(__dirname, &quot;src&quot;), <br>     path.resolve(__dirname, &quot;../shared-lib&quot;),  <br>     path.resolve(__dirname, &quot;../ui-lib&quot;) <br>  ]; <br>  return config; <br>} </pre><pre>module.exports = function(config, env){ <br>    ... <br>    config = compileLinkNodeModules(config, env); <br>    ... <br>    return config <br>}</pre><p>It becomes obvious where the paths to ui-lib and shared-app are and so are accounted appropriately in the config-overrides.js file.</p><p>With this, running yarn start in the main-app directory works without any issue. Also, components from in the ui-lib codebase can be accessed in main-app as follows</p><pre>import React from &#39;react&#39;; <br>import AccountingPage from &#39;ui-lib/src/pages/AccountingPage&#39;; <br>...</pre><p>As for the marketing-app, NextJS also had similar issues. This required using some of NextJS plugins in resolving the issue</p><p><strong>repo/packages/marketing-pages/next.config.json</strong></p><pre>const withTM = require(&quot;next-plugin-transpile-modules&quot;); <br>const withFonts = require(&quot;next-fonts&quot;); <br>const path = require(&quot;path&quot;); </pre><pre>module.exports = withFonts( <br>   withTM({ <br>      transpileModules: [ <br>         &quot;ui-lib&quot;, &quot;shared-lib&quot;, <br>         path.resolve(__dirname, &quot;../ui-lib&quot;) <br>      ], <br>      ... <br>      webpack(config, options) { <br>         return config; <br>      } <br>   }) <br>);</pre><h3>The Production Build Problem:</h3><p>The above project setup makes it very easy to setup a development environment in a matter of minutes. The only command required, for setup, is yarn install.</p><p>But when thinking about deploying to production, The following problems occurred.</p><ol><li>Inconsistency in build during development and on production platforms like <a href="https://www.netlify.com/">Netlify</a>.</li><li>The time to build all the apps took over 17 minutes. This made deploying small changes very painful and increased the time required to resolve bug fixes</li></ol><p><em>An initial solution to the first problem was to use Gitlab Pipelines and build the applications in a Docker container. The resulting build, grouped by folders, was then committed to a deploy repo which is then picked up by </em><a href="https://www.netlify.com/"><em>Netlify</em></a><em>.</em></p><h3>The solution.</h3><p>Irrespective of what solution was proposed, one thing was certain, it shouldn’t affect the development setup process. The only command required to setup after cloning the base repository was yarn install.</p><p>The proposed solution was to get all sub applications as <a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules">Git submodules</a>. This meant, each sub application was a git repository and could be deployed in isolation. As problems occurred in a particular application, it was immediately addressed in isolation and deployed.</p><p><strong>But then both </strong><strong>marketing pages app and </strong><strong>main-app failed to build in isolation</strong></p><p>The problem is interesting. In the case of marketing-pages, Both the shared-lib and ui-lib packages weren’t linked anymore in the node_modules. This was what Yarn Workspaces solved by default.</p><p>Both ui-lib and shared-lib also needed to be git sub modules. Since <a href="https://docs.npmjs.com/files/package.json#git-urls-as-dependencies">git repository can be installed as dependencies</a>, the package.json for marketing-app was updated.</p><p><strong>repo/packages/marketing-app</strong></p><pre>{ <br>    &quot;name&quot;: &quot;marketing-app&quot;, <br>    ..., <br>    &quot;dependencies&quot;:{ <br>       &quot;ui-lib&quot;: &quot;&lt;the repository link of the ui lib&gt;#&lt;the last git tag&gt;&quot;, <br>       &quot;shared-lib&quot;: &quot;&lt;the repository link of the shared lib&gt;#&lt;the last git tag&gt;&quot; <br>     } <br>}</pre><p>By ensuring using specific git tag instead of a particular branch, <strong>deployment becomes an explicit action</strong>. To get the latest changes from the ui-lib codebase, <strong>the git tag had to be bumped to a new version</strong>. This ensures experimentation without having to worry about regressions or breaking changes, in both marketing-pages and main-app, as a result of new commits introduced in either the ui-lib or the shared-lib codebases.</p><p>These changes were made directly on the master branch of both the marketing app as well as main_app. The develop branch for both marketing-pages and main-app, is what is then referenced by the root <strong>mono repo</strong> codebase housing all the submodules.</p><p>An intermediate branch staging for both marketing-pages and main-app is required, to get changes from the develop branch to the master branch, and also ensuring that the dependencies in the master branch never creep over to the develop branch and vice versa.</p><p>Also since, in the master branch that houses the main-app, Lookups to the actual location of jsx components needs to be updated in the config-overrides.js</p><p><strong>repo/packages/main-app(master)</strong></p><pre>const path = require(&#39;path&#39;); ... function compileLinkNodeModules(config, env) { config.module.rules[2].oneOf[1].include = [ path.resolve(__dirname, &quot;src&quot;), path.resolve(__dirname, &quot;node_modules/shared-lib&quot;) path.resolve(__dirname, &quot;node_modules/ui-lib&quot;) ]; return config; } ...</pre><p><strong>NB: The name should match the package names in the </strong><strong>packge.json file.</strong></p><p>The package.json for the main-app codebase would take the following look for both the develop branch as well as the master branch</p><p><strong>repo/packages/main-app/package.json(develop)</strong></p><pre>{ <br>    &quot;name&quot;: &quot;main-app&quot;, <br>    ..., <br>    &quot;dependencies&quot;:{ <br>        &quot;ui-lib&quot;: &quot;*&quot;, <br>        &quot;shared-lib&quot;: &quot;*&quot; <br>    } <br>}</pre><p>The reason for this is simple. In the develop branch, work would most likely happen in the root repository that houses the sub_modules. Since this repository has Yarn Workspace handling all the dependencies, whatsoever was resolved is what is needed, hence the need to explicitly use * for both the ui-lib as well as the shared-lib</p><p><strong>repo/packages/main-app/package.json(master)</strong></p><pre>{ <br>    &quot;name&quot;: &quot;main-app&quot;, <br>    ..., <br>    &quot;dependencies&quot;:{ <br>        &quot;ui-lib&quot;: &quot;&lt;the repository link of the ui lib&gt;#&lt;the last git tag&gt;&quot;, <br>        &quot;shared-lib&quot;: &quot;&lt;the repository link of the shared lib&gt;#&lt;the last git tag&gt;&quot; <br>    } <br>}</pre><p><em>Originally published at </em><a href="https://beeola.me/scaling-frontend-codebase/"><em>beeola.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed6630d372bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Django]]></title>
            <link>https://medium.com/@Beee_sama/micro-django-e8b838b0f6a4?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8b838b0f6a4</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[batteries-included]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-framework]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Sun, 18 Mar 2018 10:52:45 GMT</pubDate>
            <atom:updated>2018-03-18T10:52:45.387Z</atom:updated>
            <content:encoded><![CDATA[<p>When building microservices, the tendency to use a micro framework is kinda the norm. Batteries-included web frameworks have been deemed overkill for such kind of projects because of the tendency to use only a fraction of what the framework supports.</p><p>In Python web development, the advantage of Flask over Django is its lightweight nature and specially it being more suitable for building micro-services. But it doesn&#39;t have to be so. Django is more than capable to be used as a framework for building micro-services.</p><p>Often times when I look at the tutorial page prescribed in the Django documentation site, I feel it isn&#39;t doing much to introduce Django in a less ceremonious manner.</p><p>Django is a great fit for micro-service application. Its batteries included approach is particularly useful because you never know when you need a feature that is already part of the framework.</p><p>One of the lesser known feature in Django is the ability to scaffold a project using a predefined template hosted locally or on Github. While there are more ambitious projects in the python ecosystem that are useful for scaffolding projects e.g cookie-cutter, The default set-up provided by django is especially useful when building micro-services.</p><p>To that end, I created a template with the bare minimum configuration to get Django up and running as a microservice.</p><p>It removes most of the default apps provided by Django out of the box as well as middlewares since most micro-services end up being implemented as a web api.</p><p>It also provides separate settings for both development and production environments which can be configured through the use of an environment variable. A dockerfile is also included to make it easy to deploy the app in a docker container.</p><p>Bootstrapping a Django micro-service assuming django is already installed is as easy as doing the following</p><p>django-admin startproject --template=https://github.com/gbozee/django-micro/archive/master.zip --name=Dockerfile &lt;project_name&gt;`</p><p>The scaffold works by making the following assumptions.<br>1. Until absolutely necessary, there is no need for a `views.py`. The `urls.py` should be used to house the urls and the views of the app till it grows out of bounds.</p><p>2. A simple models.py is created. Since the whole point of the application is to act as a micro-service, there really isn&#39;t any need for multiple apps. Of course, there is nothing stopping you as a user from doing so. A solution that seems to work well when the models keep increasing is to convert the models.py module to a models package and in the __init__.py in the package, import all the modules.</p><p>__init__.py</p><p>from .user import User</p><p>3. The settings for the project is provided as a package by default which consist of modules for base, local as well as production. Also, all the default installed apps as well as middlewares are removed. Also no static file or template setting is to be expected since we are building a web service.</p><p>4. A requirements folder is also provided which consist of dependencies for base, local and production</p><p>This setup is particularly useful when you know there is a tendency for the project to grow but you want to start with something simple and lightweight.</p><p>The template is hosted at <a href="https://github.com/gbozee/django-micro">https://github.com/gbozee/django-micro</a>.</p><p>Please do give it a try. thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8b838b0f6a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging in Python]]></title>
            <link>https://medium.com/@Beee_sama/debugging-in-python-49b843a9ec92?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/49b843a9ec92</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Wed, 27 Sep 2017 23:11:41 GMT</pubDate>
            <atom:updated>2017-09-28T08:11:21.937Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the reasons why I love the Python programming language is because of how easy debugging is. You don’t need a full blown IDE to be able to debug your Python application. We will go through the process of debugging a simple Python script using the pdb module from the Python standard library, which comes with most installation of Python.</p><p>Let’s take a look at the following simple snippet:</p><pre>def funcA(first_val, second_val): <br>    result = (first_val*2) - (second_val/4) <br>    return result </pre><pre>def functionB(first_val=23, last_val=72): <br>    response = funcA(first_val, last_vale) <br>    result = response * first_val / 7 <br>    return result </pre><pre>functionB(33,88) # we are evaluating the function.</pre><p>If we try running the snippet above, we would get an error:</p><pre>Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; File &quot;&lt;stdin&gt;&quot;, line 2, in functionB NameError: global name &#39;last_vale&#39; is not defined</pre><p>To find out what is wrong with this snippet, we need to know where we should place our breakpoint. A breakpoint tells the Python interpreter to pause execution at a particular point in our application.</p><p>From the error message above, we can infer that the problem is coming from the functionB function. But depending on our expertise, we might not be sure what is causing the error.</p><p>To <strong>debug</strong> the problem, we would add a breakpoint to the start of our functionB implementation</p><pre># we would place our break point here <br>import pdb pdb.set_trace() <br>response = funcA(first_val, last_vale) <br>result = response * first_val / 7 <br>return result</pre><p>The breakpoint in this case is the two line import pdb; and pdb.set_trace(). With these two lines in place, if we try running our application again, we would get an output like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*0sDGK_eLdp_MCWHyhsRRAg.png" /></figure><p>The interface looks similar to that of the interactive shell that Python provides. We can test out the values passed into the function by typing them out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*1U_pxBFJoFnzh9LsxSqq4A.png" /></figure><p>To step to the next line, we use the key n, which means next, to step down the code line by line</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*NDW4uXxT6ZPscgu78MBbPw.png" /></figure><p>We can see from the above that as we moved to the next line, the error we encountered earlier on, came up again. So we are certain that the problem in our code happens on the line which we just ran.</p><p>To get python to continue execution of the program, we type c which means continue and the program executes as usual.</p><p>Now assuming we fixed our implementation by ensuring that the correct name of the variable is used and removed the breakpoint because we don’t want the program to pause</p><pre>def funcA(first_val, second_val): <br>    result = (first_val * 2) - (second_val / 0) <br>    return result </pre><pre>def functionB(first_val=23, last_val=72): <br>    # we would place our break point here <br>    response = funcA(first_val, last_val) <br>    result = response * first_val / 7 <br>    return result </pre><pre>functionB(33, 88)</pre><p>We would run into a different kind of error this time</p><pre>$ python sample.py Traceback (most recent call last): File &quot;sample.py&quot;, line 13, in &lt;module&gt; functionB(33, 88) File &quot;sample.py&quot;, line 8, in functionB response = funcA(first_val, last_val) File &quot;sample.py&quot;, line 2, in funcA result = (first_val * 2) - (second_val / 0) ZeroDivisionError: integer division or modulo by zero</pre><p>We might not be sure where the error is coming from if we are just getting familar with python but with pdb we can progress incrementally to where the error occurs.<br> We know that the starting point of our application is in functionB function so we would place our breakpoint there and step through the application line by line</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*WCWcCKY_dTneVX681dnCSw.png" /></figure><p>We are already familiar with n moving to the next line. But now we are seeing s. This means step which moves the flow of control into the functionA. In functionA we keep on pressing n line by line till we get to the part of our code that throws the error.</p><p>There are actually more commands, all of which can be explored at <a href="https://docs.python.org/2/library/pdb.html.">https://docs.python.org/2/library/pdb.html.</a> But For your day to day debugging needs, n, s and c is all you need.</p><p>One thing we should keep in mind should we choose to debug our application this way is to ensure that we don’t use single word values as variable names in our application.<br> Take for instance</p><pre>import pdb <br>pdb.set_trace() </pre><pre>n= 84 <br>s = 45 <br>c = 23</pre><p>If we wanted to navigate to the next line and we typed n, we would run into a conflict because n has special meaning in pdb and our variable is also named n.</p><p>Happy Debugging.</p><p><em>Originally published at </em><a href="https://www.codementor.io/gbozee/9ia7lof32"><em>www.codementor.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49b843a9ec92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding is the easy part, the missing perspective]]></title>
            <link>https://medium.com/@Beee_sama/coding-is-the-easy-part-the-missing-perspective-94e58337570a?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/94e58337570a</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Wed, 10 May 2017 19:18:27 GMT</pubDate>
            <atom:updated>2017-05-18T05:21:07.785Z</atom:updated>
            <content:encoded><![CDATA[<p>I was scrolling through twitter and found this tweet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhvgE7-opJNvUUkbIC-FBw.png" /><figcaption><a href="https://twitter.com/sehurlburt/status/862118493474275329">https://twitter.com/sehurlburt/status/862118493474275329</a></figcaption></figure><p>I understood the point that was been passed but couldn’t help but think that most if not all the other skills is what makes it possible to write any code in the first place. Its like saying learning to speak is the easy part but understanding sentence construction, parts of speech, auxiliary verbs etc is the hard part.</p><p>In the speaking case, a basic understanding of the rudiments is assumed when you speak. Using the following sentence</p><blockquote>I am going to the park</blockquote><p>as an example, the person speaking had to think about what to say before saying it. He/she didn’t just blurt out the sentence.</p><p>Just as there are bad ways to communicate in the English language, same can be said for a poorly written code. But the point still remains that to even blurt out code whether written well or not, you must have consciously or unconsciously</p><ol><li>Planned about it (instantaneously/during the coding process or thoughtfully before writing the first line of code.)</li><li>Designed how it would work. Most beginners do not realize this when they write code but whatever was built from the code they wrote was a result of some form of design.</li><li>Learning. You can’t write any code without learning the syntax in the first place. For every snippet of code written, there is a learning process happening.</li><li>Communication. A beginner writing code for the first time, using strange variables or function name, is actually still communicating his/her intent even though poorly. The basic act of writing code is to communicate intent to the computer.</li><li>Prioritizing. Very similar to planning. In the mind of the coder, he/she thinks what is being done at that point is the most important thing.</li></ol><p>The point I am trying to drive here is all these other skills, which are assumed as separate from coding, are actually part of the coding process and can not be thought of as different. As one codes more, he/she learns about all these other skills.</p><p>So if all these auxiliary skills are hard, then coding is also hard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94e58337570a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Create React App tests in Visual studio code.]]></title>
            <link>https://medium.com/@Beee_sama/debugging-create-react-app-tests-in-visual-studio-code-afe8de4238ff?source=rss-3dd4065ab8be------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe8de4238ff</guid>
            <category><![CDATA[visual-studio-code]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Bee0l@]]></dc:creator>
            <pubDate>Thu, 02 Mar 2017 10:05:06 GMT</pubDate>
            <atom:updated>2017-12-28T07:35:47.499Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever run into the situation where you just need to debug your <a href="https://github.com/facebookincubator/create-react-app">Create-react-app</a> tests which make use of the <a href="https://facebook.github.io/jest/">Jest test runner</a> in <a href="https://code.visualstudio.com/">Visual studio code</a> but end up running into all sorts of issues? I have and eventually have found a step by step process to set up debugging of jest tests for create-react-app with visual studio code.</p><ol><li>Ensure you have a <em>.babelrc</em> file on the root of your project with the following content <strong>This step is important and was what was missing in blogs and articles i found online</strong></li></ol><pre>{<br>    &quot;presets&quot;: [&quot;react-app&quot;]<br>}</pre><p><strong><em>NB: for recent versions of create-react-app, please look below for the latest info on extra dependencies to install.</em></strong></p><p>2. Visual studio code has a launch.json . You would need to set a configuration for jest like what is shown below</p><pre>{</pre><pre>// Use IntelliSense to learn about possible Node.js debug attributes.</pre><pre>// Hover to view descriptions of existing attributes.</pre><pre>// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387</pre><pre>  &quot;version&quot;: &quot;0.2.0&quot;,</pre><pre>  &quot;configurations&quot;: [</pre><pre>    {</pre><pre>       &quot;name&quot;: &quot;Jest tests&quot;,</pre><pre>       &quot;type&quot;: &quot;node&quot;,</pre><pre>       &quot;request&quot;: &quot;launch&quot;,</pre><pre>       &quot;program&quot;: &quot;${workspaceRoot}/node_modules/jest-cli/bin/jest.js&quot;,</pre><pre>       &quot;stopOnEntry&quot;: false,</pre><pre>       &quot;args&quot;: [&quot;--runInBand&quot;],</pre><pre>       &quot;cwd&quot;: &quot;${workspaceRoot}&quot;,</pre><pre>       &quot;preLaunchTask&quot;: null,</pre><pre>       &quot;runtimeExecutable&quot;: null,</pre><pre>       &quot;runtimeArgs&quot;: [&quot;--nolazy&quot;],</pre><pre>       &quot;env&quot;: {</pre><pre>          &quot;NODE_ENV&quot;: &quot;development&quot;<br>       },</pre><pre>       &quot;console&quot;: &quot;internalConsole&quot;,</pre><pre>       &quot;sourceMaps&quot;: true,</pre><pre>       // &quot;outFiles&quot;: []</pre><pre>    },</pre><pre>  ]</pre><pre>}</pre><p>3. And finally, select the Debug Task option and run by clicking the green arrow button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*8E0vwJslscsQOh-N3sLhkA.png" /></figure><p>Now you can add breakpoints when running your jest tests in order to debug any issues you might have with your code.</p><p>Hopefully, this is useful to others who run into similar problems fighting with visual studio code to set up simple debugging for jest tests.</p><p><strong><em>Update: December 2017</em></strong></p><p>I tried replicating this setup with a create react app project using react-scripts 1.0.17 but it failed.<br>I was able to solve this by installing the following dev-dependencies</p><pre>yarn add --dev babel-preset-es2015 babel-preset-react babel-plugin-transform-object-rest-spread babel-jest@20.0.3</pre><p>Then update the .babelrc file to use this instead</p><pre>{</pre><pre>   &quot;presets&quot;: [ &quot;es2015&quot;,&quot;react&quot;],</pre><pre>   &quot;plugins&quot;: [&quot;transform-object-rest-spread&quot;]</pre><pre>}</pre><p>Since the development of jest and visual studio code move at an amazing fast pace, information from the jest docs were much more useful.</p><p>Happy debugging.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe8de4238ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>