<?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 William Okafor on Medium]]></title>
        <description><![CDATA[Stories by William Okafor on Medium]]></description>
        <link>https://medium.com/@wilpat456?source=rss-ed2229f62f3e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k3p4qG4eaL8ehV52X_DuqQ.png</url>
            <title>Stories by William Okafor on Medium</title>
            <link>https://medium.com/@wilpat456?source=rss-ed2229f62f3e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:12:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wilpat456/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[Fixing VoyagerServiceProvider not Found error in Laravel 7]]></title>
            <link>https://medium.com/@wilpat456/fixing-voyagerserviceprovider-not-found-error-in-laravel-7-8a8f1bb0cd50?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a8f1bb0cd50</guid>
            <category><![CDATA[voyager]]></category>
            <category><![CDATA[bug-fixes]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 04:06:00 GMT</pubDate>
            <atom:updated>2020-04-05T04:06:00.455Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>At the time of writing this article, voyager is at version 1.4</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*IGLR084R1zdQvKWL.png" /></figure><p>If you’re like me, you just finished pulling in voyager with composer and now you tried running php artisan voyager:install but you keep getting an error that a VoyagerServiceProvider.php file is missing.</p><p>All your artisan commands are also throwing this error too.</p><p>Checking the vendor folder, I found that the tcg/voyager folder was empty and after hours of research I found a solution:</p><h4>Step 1:</h4><p>Go to <a href="https://github.com/the-control-group/voyager">https://github.com/the-control-group/voyager</a> and clone this repo .</p><h4>Step 2:</h4><p>Unzip this repo and copy the content of the src folder into your vendor/tcg/voyager folder.</p><h4>Step 3:</h4><p>Run composer dump-autoload and php artisan cache:clear to be sure nothing is being cached.</p><h4>Step 4:</h4><p>Run your php artisan voyager:install command again.</p><p>I hope this saves you time and solves your issue like it did for me.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a8f1bb0cd50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Laravel with Hubspot]]></title>
            <link>https://medium.com/@wilpat456/integrating-laravel-with-hubspot-b8d8bcb6efbc?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8d8bcb6efbc</guid>
            <category><![CDATA[hubspot-api]]></category>
            <category><![CDATA[hubspot]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 11:37:09 GMT</pubDate>
            <atom:updated>2020-03-27T11:37:09.151Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I will be using the Hubspot contacts API to create a new contact from our Laravel app to break this down.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWiWEr0qw6FkBPbXQbiX-A.png" /><figcaption>Hubspot and Laravel</figcaption></figure><p>Before delving into the actual integration, I would like to go over two scenarios where a possibility of this integration would make easier.</p><ol><li>You have used Hubspot to save your leads(contacts) for a while and now you have an in-house application who’s data you would like to be synced with that of Hubspot.</li><li>Since Hubspot does a great job at data presentation especially with finances, If you use a billing service, you might want to update the Hubspot deals of a contact whenever they make a purchase in your app as this would give you an out-of-the-box overview of how your application is doing financially.</li></ol><p>If you have a scenario like the ones above or something similar, this article would help give you a fundamental understanding on how this integration typically works.</p><h3>Let’s begin</h3><p>This process requires setting some things up in Hubspot first before proceeding to the Laravel part of things but make sure you have your Laravel app ready.</p><h3>Hubspot Setup</h3><p>First of all, to access the features of Hubspot we need for our goal, we will need a Hubspot developer account. Go ahead and <a href="https://developers.hubspot.com/get-started">create one here</a>.</p><p>You will find some options like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZpWL59DbLuEpDLo4z9piQ.png" /><figcaption>Developer Account Creation Options</figcaption></figure><p>Follow the steps and fill the prompts after which you should be redirected to your dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnu27bE3Rb5c1RO9NfOMYw.png" /><figcaption>Developer Account Dashboard</figcaption></figure><p>Next, we’ll need a test Hubspot account as this enables us freely access the features we would typically encounter when working with accounts of premium Hubspot users.</p><p>Let’s create one using this new developer account we just made:</p><p>Go to the developer account dashboard &gt; <strong>Manage test accounts </strong>&gt; <strong>Create account </strong>&gt; type in the account name in the popup that you see &gt; <strong>save</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMRNbEq5OnXkD8S71_5dOg.png" /><figcaption>Hubspot test account creation popup</figcaption></figure><p>At the moment, if you navigate to the contacts tab of this new account, you should find only dummy contacts added automatically by Hubspot when the account was created like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rva-L-ujWDpF74AFSinomA.png" /><figcaption>Initial contacts of a fresh test account</figcaption></figure><h4>Hubspot API</h4><p>This is the next piece of the puzzle and it’s basically a set of urls that exposes parts of a user’s Hubspot account — like contacts, hubdb, etc — to the public for interaction.</p><p>Hubspot also secures API access by mandating either of these two:</p><ul><li>The Hubspot API key of the account we intend to interact with is sent as a query string with the http request using the hubspot API.</li><li>An Authorisation token gotten from <a href="https://developers.hubspot.com/docs/methods/oauth2/oauth2-overview">OAuth</a> is attached to the header of the http request to the API.</li></ul><blockquote>To keep things simple, I am going to use the Hubspot API key option but for production, you’ll need to follow the steps in <a href="https://github.com/HubSpot/oauth-quickstart-nodejs">this repo</a> to generate an access token for your authentication.</blockquote><p>Next step is:</p><h4>Hubspot Api Key:</h4><p>As mentioned before, this is needed to authenticate requests, using the Hubspot API on a user’s account.</p><p>Let’s proceed to get ours:</p><ul><li>Click on the <strong>Testing</strong> tab of your developer account</li><li>Select the new test account we created previously and let it load up</li><li>Click on the settings icon at the top right of the New account’s dashboard.</li><li>Locate and select the <strong>API key</strong> option under the <strong>Integration</strong> dropdown menu in the list of setting options on the left side of the page:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7VaZ-TIX8RkmRDBWBfqcxg.png" /><figcaption>API key settings</figcaption></figure><ul><li>Click the <strong>Create key </strong>button to generate an API key for this account</li><li>Copy and save this key in the .env file of our Laravel app as <strong>HUBSPOT_API_KEY</strong></li></ul><h3>The Laravel Part</h3><blockquote>Remember, our goal is to add a new contact into the contacts list of our Hubspot test account</blockquote><p>We will be using <a href="https://guzzle.readthedocs.io/en/latest/overview.html#installation">Guzzle</a> to make http requests in our Laravel app so please install it by running composer require guzzlehttp/guzzle in the terminal inside the Laravel app.</p><p><em>To avoid some bugs I encountered when using guzzle for this, I needed to install some additional symfony components with composer by running:</em></p><pre>composer require symfony/psr-http-message-bridge<br>composer require nyholm/psr7</pre><p>Now we will create a simple form to take the <strong>firstname, lastname, email, phone number </strong>of the contact we intend sending over to Hubspot.</p><p>I created mine inside my welcome.blade.php file like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KgU2lB1Aa0f_mszJvf242A.png" /><figcaption>Contact creation form</figcaption></figure><p>Now add this route Route::post(‘/create-contact’, ‘HubspotApiController@create’); to the web.php file to direct our form submissions</p><p>Then run php artisan make:controller HubspotApiController to create a new controller in your Laravel application called <strong>HubspotApiController</strong></p><p>In this controller, add the guzzle client namespaces by writing these code anywhere before the controller class begins:</p><p>use GuzzleHttp\Exception\GuzzleException;</p><p>use GuzzleHttp\Client;</p><p>Next, we will add the following code into the controller’s class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/760be5ca7ea064ee145283a627eadcb4/href">https://medium.com/media/760be5ca7ea064ee145283a627eadcb4/href</a></iframe><p>And that’s it. Now you can navigate to the contact creation form, submit the details and it would get sent over to Hubspot.</p><p>The points discussed here give you a fundamental understanding of one way Hubspot can be integrated with a local application and this understanding can be extended to work with other Hubspot <a href="https://developers.hubspot.com/docs/overview">APIs</a>, using <a href="https://developers.hubspot.com/docs/methods/webhooks/webhooks-overview">webhooks</a> to subscribe and listen for events happening inside a hubspot account and so much more.</p><blockquote>PS: After understanding how to authenticate your API calls using the API key, you should look into the second and recommended authentication method for doing this in a production environment which I highlighted above.</blockquote><blockquote>After getting your OAuth access token for the user’s account, check the Hubspot API documentation on how the API request should be structured in order to successfully use them.</blockquote><p>I hope this was helpful.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8d8bcb6efbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[9 Steps for building a CI/CD pipeline with Travis-CI, Docker and AWS]]></title>
            <link>https://medium.com/@wilpat456/my-first-go-at-travis-ci-d0e63ccdc4d0?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0e63ccdc4d0</guid>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Sat, 15 Feb 2020 22:50:14 GMT</pubDate>
            <atom:updated>2020-02-20T13:12:02.520Z</atom:updated>
            <content:encoded><![CDATA[<h3>9 Steps for building a CI/CD pipeline with Travis-CI, Docker and AWS.</h3><blockquote>I would be using a simple React app for the frontend, docker for containerisation and AWS for deployment</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJ1nJ1G2u5l9tzQyZVejCQ.png" /></figure><p>Requirements:</p><ul><li>A <a href="https://github.com/">Github</a> account</li><li>A minimum of a free tier <a href="https://aws.amazon.com/">AWS</a> account.</li><li>A basic knowledge of Docker</li></ul><p><strong>Travis-CI </strong>is a hosted continuous integration(CI) service used to build and test software projects hosted at GitHub.</p><p>It basically helps developers automate the process of deploying their code from it’s repository onto the live environment while ensuring all the set tests of the application are passing before it’s allowed unto production.</p><h3>Step 1: React —</h3><p>I used an npm package called <a href="https://www.npmjs.com/package/create-react-app"><em>create-react-app</em></a><em> </em>to quickly spin up a react application by running create-react-app sample-app</p><p>After this is done, you should see a folder structure like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Ru1ktULHw1E4y1nQvM6ugQ.png" /><figcaption>New react app</figcaption></figure><h3>Step 2: Docker —</h3><p>If you’re at this point, we would need to create a docker image of this application and for this, we would be adding two files named below to the root of our application:</p><ul><li><strong>Dockerfile</strong> — Used for building the image that contains the optimized version of this application</li><li><strong>Dockerfile.dev</strong> — Used for building the image that contains the development version which would be used to run tests</li></ul><blockquote>A Dockerfile file contains instructions that docker uses to build an image of an application</blockquote><p>To keep things short, I’d just show you the actual code:</p><ul><li><strong>Dockerfile:</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ac37d3cc79a22d0a64f938c36ac2fbe/href">https://medium.com/media/3ac37d3cc79a22d0a64f938c36ac2fbe/href</a></iframe><ul><li><strong>Dockerfile.dev:</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e4a5cca5d3e4c58054933a77228873/href">https://medium.com/media/c6e4a5cca5d3e4c58054933a77228873/href</a></iframe><p>At this point, you should create a new github repository (<em>You can name it sample-docker-react like I did for consistency) </em>and push the simple-app to it.</p><p>Your repository should look something like this:</p><p>Now we need to connect our repository to travis-ci and for this, we’d move on to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4MaqfY29FyjRdgcGs8MAQ.png" /><figcaption>New repository for our sample app</figcaption></figure><h3>Step 3: Travis-CI!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*2DjMHc0QKT_-pi1B.png" /></figure><p>I’m assuming you already have an account with travis-ci using your Github account. This gives travis the access it needs to your repositories.</p><p>Next, click on your profile icon &gt; settings then toggle on the sample-docker-react repository we just pushed to Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-1GIfqL2o-qFesUtoWfZQ.png" /><figcaption>Activating a repo for monitoring.</figcaption></figure><p>This tells travis-ci to start monitoring the repository. but for this we need a <strong>YAML </strong>file called .travis.yml to be added to the application as this would contain the instructions on what you want travis-ci to do with your code when a build is triggered.</p><p>Here are some instructions you should add to your .travis.yml file:</p><pre>sudo: required </pre><pre>language: node_js<br>node_js:<br>    - &quot;stable&quot;<br>    <br>services: <br>    - docker<br><br>before_install: <br>    - docker build -t wilpat/sample-app -f Dockerfile.dev .</pre><pre>script:     <br>    - docker run -e CI=true wilpat/sample-app npm run test -- --coverage</pre><ul><li><strong>sudo: required- </strong>Travis ci requires the user to be with elevated permission</li><li><strong>language: node_js- </strong>A way to specify the language that should be used in building the app</li><li><strong>services- </strong>Used to tell travis-ci that we need an instance of docker running for this build</li><li><strong>before_install- </strong>An array of things to do with your code before running tests or deploying your code(<em>The instruction here builds the docker image using our Dockerfile.dev file and tags it with the name </em><strong><em>wilpat/sample-app</em></strong><em>)</em></li><li><strong>scripts: </strong>An array of scripts to run before deploying your code.(Tests typically go here (<em>The instruction here runs the our test by running image named </em><strong><em>wilpat/sample-app </em></strong><em>and overriding the command specified in the Dockerfile.dev)</em></li></ul><p>We’d be needing one more instruction to tell travis-ci how and where to deploy our application, but we first need to setup AWS to receive our code.</p><h3>Step 4: AWS Elastic Beanstalk—</h3><blockquote>Disclaimer: Nothing prepares you enough for the maze called AWS</blockquote><p><strong>AWS Elastic Beanstalk</strong> is an easy-to-use service for deploying and scaling web applications and services developed with Java, . NET, PHP, Node. js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.</p><p>We need to sign into <a href="https://aws.amazon.com/">AWS</a>, hover on services and select Elastic Beanstalk then select Create New Application by the top right as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYBXq1MTytWQqP04f7j3kA.png" /><figcaption>Elastic Beanstalk</figcaption></figure><p>Enter the application name sample-docker-react, enter a description (optional) and then submit.</p><p>You should be redirected to the application itself and you’d notice a screen like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kib74OhPQPMU1q1MEwPKRg.png" /><figcaption>New Application On ELB</figcaption></figure><p>We need to create an environment for our application to run in so click the <strong>Create one now</strong> link.</p><p>On the next page, select a <strong>Web server environment </strong>and you should get directed to a page like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCP47wtSwwggt9Rb1GHXZQ.png" /><figcaption>Web server environment setup</figcaption></figure><p>Choose docker as the platform for this environment. Then leave the application code at <strong>Sample application </strong>then submit it and wait for the environment to be built up.</p><blockquote>PS: You might need to refresh the page to show the finished environment</blockquote><p>If everything went as planned, you should see something like this when it’s finished:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7JNX4ERL-nfoJBTAabcMdA.png" /><figcaption>New Docker Environment</figcaption></figure><h3>Step 5: AWS IAM —</h3><p><strong>Identity and Access Management (IAM) </strong>provides a way for external platforms to access elastic beanstalk apps in our AWS account.</p><p>For this to be possible, we need to create an IAM user and grant the user the appropriate privileges.</p><p>Go to <strong>Services</strong>(at the top left) &gt; <strong>IAM</strong> &gt; <strong>users</strong> &gt; <strong>Add user</strong> on the page.</p><p>You should be directed to a page where you’re asked to enter the user name and the access type. I used sample-docker-react as the username and selected <strong>Programmatic access </strong>as that’s what this app needs.</p><p>The next page asks you to add the set permissions for this user, all you need here is:</p><ul><li>Select <strong>Attach existing policies directly</strong></li><li>Search for “<strong>elasticbeanstalk” </strong>in the table that shows up</li><li>Tick all the options that shows up</li><li>Click next till you create the user.</li></ul><p>On success, you’d see a table showing you your <strong>AccessKeyID </strong>and<strong> SecretAccessKey </strong>as see below.</p><blockquote>PS: You need to store these somewhere as we would be using them in Travis-CI for deploying our app and you’re only able to see the secret key visible once.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3Bu1oVgE0k40bNCwRgJ5Q.png" /><figcaption>Successfully created IAM user</figcaption></figure><h3>Step 6: AWS S3 Buckets—</h3><p><strong><em>Amazon S3</em></strong><em> or </em><strong><em>Amazon Simple Storage Service</em></strong><em> is a service offered by </em><a href="https://en.wikipedia.org/wiki/Amazon_Web_Services"><em>Amazon Web Services</em></a><em> (AWS) that provides </em><a href="https://en.wikipedia.org/wiki/Object_storage"><em>object storage</em></a><em> through a </em><a href="https://en.wikipedia.org/wiki/Web_service"><em>web service</em></a><em> interface.</em></p><p>Also, while creating an elastic beanstalk environment, AWS selects a server location closest to you for hosting it(You can select a different location too).</p><p>Also, after the environment is created, an S3 bucket is also created bearing a name that’s contains an identifier of this server location (e.g us-east-1, us-west-1) and it is used to store applications that you deployed in environments existing in this same server location.</p><p>Secondly, you need to specify a folder(aka <strong>bucket path </strong>in travis) that would be used by travis-ci for deployment</p><p>Goto Services &gt; Storage &gt; S3</p><p>Select the bucket with a name that has the identifier of the server location of your environment in it’s name.</p><p>Create a folder and you can name it the same name with your application( sample-docker-react `) this name choice is optional and I do it to help me remember what app it’s for.</p><h3>Step 7: Back to Travis-CI</h3><p>You’d need to save the <strong>AccessKeyID </strong>and<strong> SecretAccessKey </strong>as an environment variable in Travis-CI.</p><p>Go to your dashboard and select the <strong>sample-docker-react</strong> repository &gt; click on the options by the top right &gt; click on settings.</p><p>On this settings page you should add <strong>AWS_ACCESS_KEY</strong> and <strong>AWS_SECRET_KEY </strong>like I have done:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dI3HXXSwKMeMKkma0WuZTw.png" /><figcaption>Environment variables for travis</figcaption></figure><h3><strong>Step 8: Back to React —</strong></h3><p>We need to update our .travis-yml file with the instructions for deploying our code and then push to github.</p><p>Update yours with the following:</p><pre>deploy:</pre><pre>  provider: elasticbeanstalk</pre><pre>  region: &quot;your-server-location&quot;<br>  app: &quot;sample-docker-react&quot;</pre><pre>  env: &quot;SampleDockerReact-env&quot;</pre><pre>  bucket_name: &quot;elasticbeanstalk-us-east-2-XXXXXXXXXXXX&quot;</pre><pre>  bucket_path: &quot;sample-app&quot;</pre><pre>  on:</pre><pre>    branch: master</pre><pre>  access_key_id: $AWS_ACCESS_KEY</pre><pre>  secret_access_key:</pre><pre>    secure: &quot;$AWS_SECRET_KEY&quot;</pre><ul><li><strong>deploy:</strong> Tells Travis-ci how to deploy your app</li><li><strong>provider: </strong>Platform to be used</li><li><strong>region: </strong>Where the server of your elastic beanstalk app environment exists(Update the file with yours)</li><li><strong>app: </strong>Then name you gave your application</li><li><strong>bucket_name:</strong> The s3 bucket generated for the server location used for your environment</li><li><strong>bucket_path: </strong>The folder we created on aws to receive the app sent from travis-ci</li><li><strong>on: </strong>Tells travis-ci which github branch update should trigger a build</li><li><strong>access_key_id:</strong> IAM access key generated in AWS but stored in travis ci</li><li><strong>secret_access_key: </strong>IAM secret key generated in IAM of AWS but stored in travis ci</li></ul><p>Now our .travis.yml file should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ddf6d58c99df013d5b15a1b9116460c/href">https://medium.com/media/6ddf6d58c99df013d5b15a1b9116460c/href</a></iframe><h3>Step 9: Push to git —</h3><p>Cross check your files and setup to ensure you did all I talked about in this walkthrough then Add, commit and push your updates to the repo on github.</p><p>Since we’ve added a .travis.yml file, travis-ci would pick up the update in few seconds and trigger a build.</p><p>After a successful build, Go to your application on AWS and you should see it get updated with the new code from travis, build the docker image, and start up the application which can be access when you click the link provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2LULUYVb7AhJnC-nVe9njQ.png" /><figcaption>Fin!</figcaption></figure><p>Now anytime we update the master branch of our application, travis-ci picks up the changes and updates our application that lives in AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*eO1fYazygVtZ1xg3.png" /><figcaption>:-D</figcaption></figure><p>If you made it here, thanks a lot for reading through! Here are little hints that you deserve ;)</p><ul><li>Using the after_success instruction in the .travis.yml, we could separate concerns by letting travis-ci handle all the docker builds and then push the docker image to <a href="https://hub.docker.com/">docker hub</a> and setup AWS to only pull the new image instead of having to send the whole app to AWS and get it to build it there.</li><li>All code for this can be gotten here: <a href="https://github.com/wilpat/sample-docker-react">https://github.com/wilpat/sample-docker-react</a></li><li>If you don’t want to get charged for using AWS, please delete the elastic beanstalk application.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0e63ccdc4d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing the EISGIT npm appears to be a git repo or submodule Error.]]></title>
            <link>https://medium.com/@wilpat456/fixing-the-eisgit-npm-appears-to-be-a-git-repo-or-submodule-error-e358c55e5e60?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e358c55e5e60</guid>
            <category><![CDATA[node-modules]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Sat, 23 Mar 2019 07:12:56 GMT</pubDate>
            <atom:updated>2019-03-23T07:12:56.021Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This happened when i was deploying an app to heroku.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*79VhGg7KG0cLWNtP.jpg" /><figcaption>Code debugging is a special skill.</figcaption></figure><p>So i’d start by explaining my scenario to help you understand if yours is similar.</p><p>A module in the node_modules folder had a .git folder and after I deleted one, I ended up finding other folders having the same .git folder, and even after Icrawled down that rabbit hole to carefully delete all the problematice .git folders, every time Itried pushing to heroku, the error popped up again.</p><p>So I had to delete the entire node_module and allow heroku rebuild the project with the following steps</p><h3>The Fix</h3><p>Run heroku run bash to get into a bash terminal where you would have access to your project’s files</p><p>Then rm -rf node_modules to completely delete the node_modules directory</p><p>Exit bash.</p><p>Run heroku config:set NODE_MODULES_CACHE=false to ensure heroku doesn’t try to use a cache in rebuilding your node_modules</p><p>Push the project again to heroku.</p><p>That solved the problem for me.</p><blockquote>Also you should set node_modules_cache back to true once the previous steps have been completed.</blockquote><p>And that’s it. I hope this helps you out and saves you some good debugging time. If it did, please play with the clap button 50 times to help this guide reach other people in a similar bind.</p><p>Thanks for reading, Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e358c55e5e60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My blockchain learning journey- Pt. 2]]></title>
            <link>https://medium.com/good-audience/my-blockchain-learning-journey-pt-2-dc0e57209975?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc0e57209975</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[ropsten]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[infura]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 07:01:00 GMT</pubDate>
            <atom:updated>2019-03-12T11:53:09.751Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>How I deployed my smart contract to ropsten using truffle and infura</blockquote><p>Well I never jump right into the meat of an article without giving a little background on how I wandered the streets of ignorance, so here goes nothing.</p><p>I had just finished writing my smart contract as well as the front end and both parts interacted properly when I used ganache-cli. I opted for ganache-cli because I needed to be able to simulate certain behaviors of a private network like the ability to interact with methods in the personal module of web3.</p><p>I was ready to take things to the next level so I researched about how to deploy my smart contract to test networks and my initial findings pointed me to using the rinkeby test net.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/0*Eenh9cfUMGNhXZFl.jpg" /><figcaption>Yup! I was that pumped.</figcaption></figure><h4>Rinkeby</h4><p>They basically resounded that I needed to make my pc a node on the network and for this I would be using something they called geth to synchronize my pc with the rinkeby blockchain. This meant that I would need to download the whole blockchain from it’s genesis block to the current block and unbeknownst to me, that meant tons of data.</p><p>I use a 4G LTE ISP so I felt confident in my network’s ability to pull everything I needed in no time. So I began the download…</p><p>My PC kept trying to catch up to the recent block but each time the gap closed in, more blocks kept getting added to widen it some more. I remained positive and kept telling myself “<strong><em>Nahh it’s gonna be any minute now</em></strong>”.</p><p>Minutes turned hours and then few hours later I got an email from my internet service provider that I had less than 1GB left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*miYuOWJmyrkpbxBN.jpg" /><figcaption>The patient dog eats the fattest bone… They said.</figcaption></figure><p>Anyway, something was still nudging me to wait a little more so I researched on why my pc was not getting synced with the network and I found out that syncing your pc with the network isn’t just dependent on your network alone rather it also requires your storage device to be fast enough at recording the new blocks. Faster than what my regular hard disk drive (HDD) was able to provide meaning I needed a solid state drive (SSD).</p><p>Needless to say, I instantly shut down everything and went back into research for alternatives after which I found <strong>ROPSTEN.</strong></p><h3>Ropsten</h3><blockquote>I would assume you already have your truffle based app ready for deployment</blockquote><p>Now ropsten is also an ethereum testnet but in this case I didn’t need to synchronize my pc with the network, I could just use a platform called <a href="https://infura.io/">infura</a> to instantly deploy my smart contracts onto the testnet.</p><h4>Getting a wallet</h4><p>To deploy your contract, you would need to create a ropsten ether wallet on <a href="https://myetherwallet.com/">MyEtherWallet</a>. This would give you an address that would be used as the coinbase for deploying you smart contracts</p><p>They would also generate for you a mnemonic which consists of 12 words that would be used to unlock your wallet. Please save this mnemonic somewhere safe as we would be needing this soon.</p><h4>Getting test ethers</h4><p>You would need ethers to actually deploy your smart contract and I found two websites that are still reliable as at the time of writing this article.</p><ul><li><a href="https://faucet.ropsten.be/">https://faucet.ropsten.be</a> — They give one test ether per day</li><li><a href="https://faucet.kyber.network/">https://faucet.kyber.network</a> — They give one <a href="https://github.com/">github </a>account one test ether for a life time <em>(Like wth?)</em></li></ul><p>Use the address you just got from the wallet that <a href="https://www.myetherwallet.com/">MyEtherWallet</a> gave you to get these test ethers.</p><h4>Getting your infura endpoint</h4><p>Head onto <a href="https://infura.io/">Infura</a> and signup.</p><p>After this, create a new project on infura.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-7_Mptr2PpzKY5ZiNx_7w.jpeg" /><figcaption>Creating a new project on infura</figcaption></figure><p>This would give you a project id, project secret and project endpoint. We are interested in the <strong>endpoint</strong>.</p><blockquote>The endpoint is largely referred to as infura key in many articles I read and that confused me.</blockquote><p>In the endpoint dropdown menu, select ropsten and then copy this endpoint somewhere, we would also be needing this.</p><h4>Deployment</h4><p>First I ran npm i truffle-hdwallet-provider to pull in truffle-hdwallet-provider as that would help connect my wallet to my contract upon deployment.</p><p>Next, in your truffle.js or truffle-config.js file import the following</p><pre>const HDWalletProvider = require(&quot;truffle-hdwallet-provider&quot;);<br>const fs = require(&#39;fs&#39;);<br>const Web3 = require(&#39;web3&#39;);</pre><blockquote>I already gave a guide on how to install web3 in the <a href="https://medium.com/altcoin-magazine/my-blockchain-learning-journey-416f01eaae1b">first part of this series</a></blockquote><p>Now use the mnemonics and the infura endpoint that you saved previously in the next lines of code inside your truffle.js or truffle-config.js file</p><pre>...</pre><pre>const mnemonics = *your mnemonic*<br>const endpoint = *your infura ropsten endpoint*</pre><pre>module.exports = {<br>  networks: {<br>    ...<br>    ropsten:{<br>     provider: () =&gt; new HDWalletProvider(mnemonics, endpoint),<br>     network_id: 3,<br>     gas: 5000000,<br>     confirmation: 2, <br>     timeoutBlocks: 200,<br>     skipDryRun: true<br>    },<br>    ...<br>  }<br>}</pre><p>Here’s the meaning of the options you see above:</p><p>provider — This is you pointing to the network to deploy your contract</p><p>network_id — The id of the network (in this case, rospten)</p><p>gas — The gas limit to spend in deploying the contracts</p><p>confirmation — Number of confs to wait between deployments. (default: 0)</p><p>timoutBlocks — Number of blocks before a deployment times out (minimum/default: 50)</p><p>skipDryRun — Skip dry run before migrations? (default: false for public nets )</p><p>If you for one minute think I don’t understand any part of what I just wrote, lol. You’re Right!</p><p>Now you can run truffle migrate --compile-all --reset --network ropsten to deploy you smart contract, and if all goes well, you should see something like this:</p><pre>Running migration: 1_initial_migration.js<br>Deploying Migrations…<br>… 0xd01dd7...<br>Migrations: 0xf741...<br>Saving successful migration to network…<br>… 0x78ed...<br>Saving artifacts…<br>Running migration: 2_deploy_contracts.js<br>Deploying YourContract…<br>… 0x0aa9...<br>YourContract: [...]<br>Saving successful migration to network…<br>… 0xee95...<br>Saving artifacts…</pre><p>And that’s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*9hkkwiOL95eaj8gr.gif" /><figcaption>If you made it here, you’re a brave one and deserve some heads up.</figcaption></figure><h3>Heads Up</h3><p>Infura actually provides an endpoint for rinkeby as well and I’ve seen a lot of people favor rinkeby over ropsten which I didn’t know at the time I was building the dapp but if you’re interested in that, you can read up on the differences between both test nets to make a more informed decision.</p><p>Also, at the time of writing this article, it was not possible to interact with the web3.eth.personals from the front end like I was able to with my local private network and this was because I used the ropsten infura endpoint as my httpProvider but either ropsten, infura, web3 or all of them didn’t support this anymore but this was a major functionality of my application as I needed to be able to register new users and give them new addresses upon signup.</p><p>I hope I just saved you the headache of trying and failing at this, I would also be giving a guide on how I solved this problem in my next article.</p><p>If this article has been of help to you, go ahead and play with the clap button 50 times to help others find it too.</p><p>Till next time, Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc0e57209975" width="1" height="1" alt=""><hr><p><a href="https://medium.com/good-audience/my-blockchain-learning-journey-pt-2-dc0e57209975">My blockchain learning journey- Pt. 2</a> was originally published in <a href="https://medium.com/good-audience">Good Audience</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My blockchain learning journey]]></title>
            <link>https://medium.com/thecapital/my-blockchain-learning-journey-416f01eaae1b?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/416f01eaae1b</guid>
            <category><![CDATA[ethereum-blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ropsten]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 08:01:00 GMT</pubDate>
            <atom:updated>2020-04-08T20:34:43.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iG-XW0bV2I0xziSZL-SvEQ.png" /></figure><h4>By <a href="https://medium.com/@wilpat456">William Okafor</a> on <a href="https://medium.com/altcoin-magazine">ALTCOIN MAGAZINE</a></h4><blockquote>How i was able to install the latest stable version of web3 on my windows machine</blockquote><p>Allow me to start by giving you a little glimpse into my journey into this field.</p><p>As a software engineer who has had a major focus in web development for years, i expected things with this new field of decentralized applications and the immutable ledger system called blockchains to be as stable as I have been used to especially with backward compatibility but little did I know.</p><p>So I recently studied up on blockchains, the cryptocurrency, after which I couldn’t wait to start writing my own smart contracts which I eventually did start and all was great until I got to the point where I wanted to push my code online to be used by actual people other than me.</p><p>Now did I mention that I learnt majorly by using Udemy tutorials but the latest ones I found was released in early 2018? And I consumed as much of these resource as I could find on the internet?</p><p>Well i did and when the time came for me to go live, that was when I got to find out that a lot of resources I had been studying as well as others I was still stumbling upon for building on the Ethereum blockchain were really outdated and by outdated, I mean that applying their methods/codes verbatim broke your code every time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2IDIJ026Ov3SwOu6PQA9Q.png" /><figcaption>Ethereum blockchain promises to be at the center of the new web</figcaption></figure><p>But then this was not really the fault of the creators of these content but largely because the technologies in this space is in a lot of flux hence it has been faced with several upgrades with many of them having terrible backward compatibility with each other.</p><p>Therefore I decided to give walk-throughs on how I solved some of the bugs I encountered in this journey and today, I would be talking about how i deployed my Dapp to ropsten test net and started interacting with it from the client side all using truffle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*cPhNo9DmP4k_wiIeBPQvnA.jpeg" /><figcaption>They must love this guy.</figcaption></figure><h3>Let’s get started</h3><p>Before I was able to deploy/connect the ropsten testnet with <a href="https://www.infura.io/">infura</a>, I needed a much more recent version of web3 than what was provided out of the box by the <a href="https://truffleframework.com/boxes/truffle-vue">truffle-vue</a> box I was using so I needed to install the latest one and I had troubles doing that on my machine till I did these</p><blockquote>It’s totally fine if the previous sentence makes little or no sense to you right now.</blockquote><h4>Node.js</h4><p>I had to upgrade to the latest version of Node. You can download it <a href="https://www.nodejs.org/">here</a></p><blockquote>NB: To keep things short, i would be using the <a href="https://truffleframework.com/boxes/truffle-vue">truffle-vue</a> box as that would give us a head start.</blockquote><h4>Node-Gyp</h4><p>Node-gyp compiles native addons (Linux, Mac, Windows) into node.js packages and we would be needing it here.</p><p>Run npm i -g node-gyp</p><h4>Python 2.7</h4><p>I already had python 3 on my pc but Node-gyp isn’t compatible with that so i had to install 2.7 and then I ran npm config set python python2.7 to set it to be the version used by npm and npm will in turn pass this option to node-gyp when needed.</p><h4>Windows Build Tool</h4><p>I initially ran `<strong>npm install -g windows-build-tools` </strong>but it broke everything but after hours of research, I found that the most stable version is version 4.0.0 hence I ran ` <strong>npm install -g windows-build-tools@4.0.0</strong>`</p><blockquote>NB: Please run the above in your terminal having admin rights</blockquote><p>Then i set the environment variable VCTargetsPath to the directory location where Microsoft.Cpp.Defaults.props is installed. Mine was in c:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\v140</p><p>I restarted my pc</p><h3>Web3 installation</h3><p>Subsequent attempts to pull in web3 still threw a ton of errors over and over again :’(.</p><p>I went into even more research to find out what I was doing wrong and after long hours <em>(days maybe) </em>of debugging I realised I was missing a package that web3 was dependent on called scrypt</p><p>Okay pull in scrypt and everyone would be happy, I said to myself. I ran npm i scrypt and guess what happened?…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hKVlM6Yl5ZjB5LWD.jpg" /><figcaption>I legit questioned everything I knew about software engineering at this point</figcaption></figure><p>After feeling shitty for a while I perused through the error logs and found nothing then I research on some keyword and I found that scrypt was in turn dependent on a package called nan (short for Native Abstraction for Node.js) but this package wasn’t installed so I did the following:</p><p>npm i nan scrypt</p><p>After this, pulling in web3 worked like a charm.</p><blockquote>From my research at the time of writing this post, version 1.0.0-beta.36 of web3 was the most stable to use</blockquote><p>The hard parts of starting out is done and since I prefer short and precise articles I would like to keep mine that way too so in my next article, I would be talking about how to I deployed my smart contract to the ropsten test net with infura and if it’s not too long already, I would talk about how I made my client side interact with my smart contract on the ropsten test net in my <a href="https://medium.com/@wilpat456/my-blockchain-learning-journey-pt-2-dc0e57209975">next article</a>.</p><p>And that’s it! I hope this helped you and I’d see you next time, Cheers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7faPAwQ92KPl911N9VHBUw.jpeg" /></figure><p>Follow us on <a href="https://twitter.com/Alt__Magazine">Twitter</a>, <a href="https://www.investfeed.com/Altcoinmagazine?rec=90e98ef">InvestFeed</a>, <a href="https://www.facebook.com/Altcoin-Magazine-302454903822750/">Facebook</a>, <a href="https://www.instagram.com/altcoin_magazine/">Instagram</a>, <a href="https://www.linkedin.com/company/altcoin-magazine/">LinkedIn</a>, and join our <a href="https://discord.gg/DkwPvH5">Discord</a> and <a href="https://t.me/AltcoinMagazine">Telegram</a>.</p><p>Read about our upcoming Altcoin Magazine Mastermind Event <a href="https://altcoinmagazinemastermindevent.eventbrite.com/">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3c1144%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3c1144%2F&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b37fd61c8660dc2cbfe8232dfa683e2/href">https://medium.com/media/4b37fd61c8660dc2cbfe8232dfa683e2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=416f01eaae1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thecapital/my-blockchain-learning-journey-416f01eaae1b">My blockchain learning journey</a> was originally published in <a href="https://medium.com/thecapital">The Capital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thompson Sampling with Django — Part2]]></title>
            <link>https://medium.com/@wilpat456/thompson-sampling-with-django-part2-4c56e6b3fd71?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c56e6b3fd71</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 14:23:51 GMT</pubDate>
            <atom:updated>2019-01-03T15:13:33.790Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*z7CxL5_nZJHl1JZ19L6g3w.jpeg" /><figcaption>Image Credit: Instapages</figcaption></figure><h3>Thompson Sampling with Django — Part2</h3><p>Welcome back! In this second part, I will show you how to display the ad selected by your algorithm on a page, how to add buttons to enable users ‘Like’ or ‘Dislike’ images thereby helping the program get better and i’d throw some bonuses in the mix.</p><p>In case you missed the previous part, you really should have a look at it <a href="https://medium.com/@wilpat456/thompson-sampling-with-django-ce13548dc2a4">here </a>before proceeding</p><h4>Let’s Begin</h4><p>In the home function of the ads/views file add the following code:</p><pre>ads = Ad.objects.all()<br> context = {<br>     &#39;clicks&#39; : ads_rewards,<br>     &#39;numb1&#39; : numbers_of_rewards_1,<br>     &#39;numb0&#39; : numbers_of_rewards_0,<br>     &#39;selected&#39; : ads_selected,#The ads displayed to all users<br>        &#39;ad&#39; : ads[ad]#The last ad selected by the algorithm<br>    }<br> return render(request,&#39;ads/home.html&#39;, context)</pre><p>Let’s create the page that would receive these variables</p><p>Create a templatesfolder inside the ads folder then create another folder called ads then create ahome.html page inside it</p><blockquote>I know, Django can be annoying</blockquote><p>Now add the following code into your home.html page</p><pre>{% load static %} <br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br> &lt;link rel=&quot;stylesheet&quot; href=&quot;<a href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css</a>&quot; integrity=&quot;sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO&quot; crossorigin=&quot;anonymous&quot;&gt;<br> &lt;title&gt;Adverts&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br> &lt;h1&gt;Thomas Sampling Ads&lt;/h1&gt;<br> &lt;div class=&quot;container&quot;&gt;<br>  &lt;div class=&quot;row&quot;&gt;<br>   &lt;div class=&quot;col-4&quot;&gt;<br>    &lt;img src=&quot;{{ad.image.url}}&quot; alt=&quot;&quot; class=&quot;img-fluid&quot;&gt;<br>   &lt;/div&gt;</pre><pre>&lt;div class=&quot;col-4&quot;&gt;<br>     &lt;a class=&quot;btn btn-small btn-primary&quot; href=&quot;{% url &#39;like-ad&#39; ad.id %}&quot;&gt;Like&lt;/a&gt;<br>     &lt;a class=&quot;btn btn-small btn-danger&quot; href=&quot;{% url &#39;dislike-ad&#39; ad.id %}&quot;&gt;Dislike&lt;/a&gt;<br>     &lt;br/&gt;Indexes of ads that has been shown to different users - {{ selected }}<br>     &lt;br&gt; Reward 1 : {{ numb1 }}<br>     &lt;br&gt; Reward 0 : {{ numb0 }}<br>     &lt;br&gt; Clicks as seen in db : {{ clicks }}<br>   &lt;/div&gt;<br>  &lt;/div&gt;<br> &lt;/div&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>I didn’t spend time on design as this isn’t a design tutorial</p><blockquote>Pfft! I’m terrible with designs</blockquote><p>I added buttons for liking and disliking the ad image shown to the user so let’s create the route for that as well as it’s respective methods.</p><h4>Liking and disliking an ad:</h4><p>Add the following items to your the urlspattern list of youadd/urls.py file</p><pre>path(&#39;like/&lt;int:ad&gt;&#39;, views.like, name =&#39;like-ad&#39;),<br>path(&#39;dislike/&lt;int:ad&gt;&#39;, views.dislike, name =&#39;dislike-ad&#39;)</pre><p>Now we would create a like and dislike function in the ad/views.py file to handle each button click</p><pre>def like(request, ad):<br>    inter_id = 0<br>    cell = f&quot;ad_{ad}&quot;<br>    inter_id = request.session[&#39;user_interaction_id&#39;]<br>    Interaction.objects.filter(pk=inter_id).update(**{cell :    1})</pre><pre>    return redirect( reverse_lazy(&#39;ads-home&#39;) )</pre><pre>def dislike(request, ad):<br>    inter_id = 0<br>    cell = f&quot;ad_{ad}&quot;<br>    inter_id = request.session[&#39;user_interaction_id&#39;]<br>    Interaction.objects.filter(pk=inter_id).update(**{cell : 0})</pre><pre>    return redirect( reverse_lazy(&#39;ads-home&#39;) )</pre><p>And we’re done.</p><p>You can start the server and navigate to localhost:8000 to view your new application running. Each reload or interaction (Like or Dislike) gives a new ad which was selected by our algorithm which uses the previous interactions with the ads to select which ad is shown to us.</p><h4>Extra:</h4><p>If you’re like me, you don’t have the luxury of 100s of users to test our app so as to give us the convergence we are hoping to find, so i did these:</p><p>Randomly create X number of users where they make random ‘clicks’ on the ads by adding this at the top of the home function:</p><pre>X = 500<br>for n in range(500):<br>    cell = f&quot;ad_{random.randint(1,10)}&quot;<br>    new = Interaction_Thomas(**{cell : 1}) <br>    new.save()</pre><blockquote>Run this only once, after which you should comment or it out to prevent yourself from creating 500 new user interactions each time you load this page.</blockquote><p>To further quicken this convergence, i created a session to store number_of_rewards_0 and number_of_rewards_1 like so:</p><p>After the Loop through the users, i added the following code:</p><pre>request.session[&#39;thomas_rewards_0&#39;] = numbers_of_rewards_0<br>request.session[&#39;thomas_rewards_1&#39;] = numbers_of_rewards_1</pre><p>Then before the loop, i added the following code:</p><pre>if not request.session.get(&#39;thomas_rewards_0&#39;, None):<br>   numbers_of_rewards_1 = [0] * d<br>   numbers_of_rewards_0 = [0] * d<br> else:<br>   numbers_of_rewards_0 = request.session[&#39;thomas_rewards_0&#39;]<br>   numbers_of_rewards_1 = request.session[&#39;thomas_rewards_1&#39;]</pre><p>With this, the number_of_rewards used in the algorithm becomes persistent and we’d be able to see the convergence in just 3–5 reloads instead of waiting for say 1,500 user’s interaction on our ad.</p><p>I hope this was helpful to you and I want to thank you for reading this post. Hit clap in case it was helpful so that others may find it too. You can also give suggestions in the comment section.</p><blockquote>Finally, you can access the full source code of this program on this <a href="https://github.com/wilpat/ad-optimization">Github Repo</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c56e6b3fd71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thompson Sampling with Django]]></title>
            <link>https://medium.com/@wilpat456/thompson-sampling-with-django-ce13548dc2a4?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce13548dc2a4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 11:30:14 GMT</pubDate>
            <atom:updated>2019-03-24T19:03:55.597Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*z7CxL5_nZJHl1JZ19L6g3w.jpeg" /><figcaption>Image Credit : Instapage</figcaption></figure><p>I just finished studying up on Reinforcement Learning using Thomspon sampling algorithm but i felt the urge to implement this in a real world scenario so i came up with this problem.</p><h4>Problem statement:</h4><p>A company has 10 versions of an image they intend using to run an advert to the users of their website and the projection of the cost of doing A | B testing is quite high so they need to find a way to explore these ads while at the same time exploiting the one with the most user click (i.e they need a program that displays the ads to users and at the same time is calculating which one is having the most impact thereby converging the particular ad being shown to the ones with highest user clicks).</p><p>In this first part, i would be showing you how to setup your environment and the core of the Reinforcement Learning algorithm itself. It’s basically meant to wet your appetite and let you get a feel of implementing your Machine Learning Algorithm on a web application.</p><h4>Prerequisites</h4><p>To make this tutorial as direct as possible, i would assume you have python and django installed, you’re familiar with python, django, and setting up virtual environments(I used anaconda for my environments but whatever way you choose should work too.</p><h4>Let’s get started:</h4><p>We would activate our environment(i named mine django) and then create a new django project</p><pre>activate django<br>django-admin.py startproject optimizer<br>cd optimizer</pre><p>Then create the django app:</p><pre>python manage.py startapp ads</pre><p>At this point, the directory should look like this:</p><pre>optimizer/<br>   ads/<br>        migrations/<br>            __init__.py<br>        __init__.py<br>        admin.py<br>        apps.py<br>        models.py<br>        tests.py<br>        views.py<br>   optimizer/<br>        __pycache__/<br>        __init__.py<br>        settings.py<br>        urls.py<br>        wsgi.py<br>    manage.py</pre><p>Let’s test our project to see if it works.</p><pre>python manage.py runserver</pre><p>You would get some migration soft warnings, don’t worry about that for now. Just open your browser and navigate to localhost:8000</p><p><strong>Voila!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*akX4rnAr2Tg4pwKaG6IeIw.png" /><figcaption>If you get this page then we’re on track.</figcaption></figure><p>With the project and app created, we need to sync our database for the first time(This would fix those warnings we saw earlier) and create an initial user and set a password for that user when prompted</p><blockquote>Please take note of these credentials</blockquote><pre>python manage.py migrate<br>python manage.py createsuperuser</pre><p>Now, open the optimizer/settings.py file and add the adsapp to the list of INSTALLED_APPS</p><pre>INSTALLED_APPS = [<br>    &#39;ads.apps.AdsConfig&#39;,<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br>]</pre><p>Furthermore, open the optimizer/urls.py file and add include to the imports from the urls module, then add urls for the ads app in the urlpatterns list:</p><pre>...</pre><pre>from django.contrib import admin<br>from django.urls import path, include</pre><pre>urlpatterns = [<br>    path(&#39;admin/&#39;, admin.site.urls),<br>    path(&#39;&#39;, include(&#39;ads.urls&#39;))<br>]<br></pre><h4>Adding links to pages</h4><p>We need to create a urls.py file in our ads folder. Then add the following code to it.</p><pre>from django.urls import path<br>from . import views</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, views.home, name =&#39;ads-home&#39;),<br>]</pre><p>Let’s add the home function to the ads/views folder. It doesn’t need to do anything fancy at the moment but this is actually where our algorithm would go</p><pre>from django.shortcuts import render</pre><pre>def home(request):<br>    pass</pre><p>For this tutorial, I am using the default sqlite that comes with django as my <a href="https://www.sqlite.org/index.html">Relational DataBase Management System</a>. You can use postgres or any other RDBMS you prefer.</p><p>With that you now have your project setup and ready to code the ads optimizer.</p><h4><strong>Creating the models for the 10 ads and then user interactions</strong></h4><p>Open your ads/models.py and add the following code</p><pre>class Ad(models.Model):<br> image = models.ImageField(default = &#39;default.jpg&#39;, upload_to = &#39;advert_images&#39;)<br> def __str__(self):<br>  return f&quot;Ad_id - {self.id} &quot;#Determines how these images are named when queried or in the backend</pre><pre>class Interaction(models.Model):<br> ad_1 = models.PositiveSmallIntegerField(default = 0)<br> ad_2 = models.PositiveSmallIntegerField(default = 0)<br> ad_3 = models.PositiveSmallIntegerField(default = 0)<br> ad_4 = models.PositiveSmallIntegerField(default = 0)<br> ad_5 = models.PositiveSmallIntegerField(default = 0)<br> ad_6 = models.PositiveSmallIntegerField(default = 0)<br> ad_7 = models.PositiveSmallIntegerField(default = 0)<br> ad_8 = models.PositiveSmallIntegerField(default = 0)<br> ad_9 = models.PositiveSmallIntegerField(default = 0)<br> ad_10 = models.PositiveSmallIntegerField(default = 0)</pre><p>Here we are specifying the column of each of the tables that our program would use.</p><p><strong>Ads</strong> table would have only one field to store the image name. We specified the folder where images would be uploaded to, and also a default image.</p><p><strong>Interactions </strong>contains a columns representing each ad and they can be 0 or 1 depending on whether a particular user clicked on the ad or not. A record here is a particular user’s interaction with all the ads</p><p>Since we are using django , we can also add our model to the admin. We shall see a little bit later how we can use the admin section to add images of each advert. Go ahead and add the following lines of code to the ads/admin.py file.</p><pre>from .models import Ad, Interaction</pre><pre>admin.site.register(Ad)<br>admin.site.register(Interaction)</pre><p>Thereafter, make your migrations and then migrate</p><pre>python manage.py makemigrations<br>python manage.py migrate</pre><h4>Adding images of our ads:</h4><p>Navigate to http://127.0.0.1:8000/admin in your browser and login with the super user credentials that you added during the setup phase of the project. Once logged in, you will have an interface before you that looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*N0HgtNC7FOUtDf2GSfpMww.png" /></figure><p>We need to tell Django where to look for and store our media files, so add the following code to the bottom of your optimizer/settings.py file</p><pre>...</pre><pre>MEDIA_ROOT = os.path.join(BASE_DIR, &#39;media&#39;)<br>MEDIA_URL = &#39;/media/&#39;</pre><p>Then add the following code to the bottom of your optimizer/urls.py file</p><pre>from django.conf import settings<br>from django.conf.urls.static import static</pre><pre>if settings.DEBUG: #If we are in development mode, access images this way<br>    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)</pre><p>Now we are ready so click on the Add button to ad images of your choice. For the purpose of this tutorial, we would be adding only 10 images.</p><h4>The algorithm</h4><p>We need a way to persist each user’s interaction on the app, so i used a session named user_interaction_id for this</p><p>Open your ads/views.py file and add the following code</p><pre>from .models import Ad, Interaction<br>from django.shortcuts import render, redirect<br>from django.urls import reverse_lazy<br>import math<br>import pandas as pd<br>import random</pre><pre>def home(request):<br> <br> if not request.session.get(&#39;user_interaction_id&#39;, None):<br>  new = Interaction()<br>  new.save()<br>  request.session[&#39;user_interaction_id&#39;] = new.id</pre><p>Let’s get the interaction of different users for our ads as seen in our database</p><pre>df = pd.DataFrame.from_records(Interaction.objects.all().values(), columns=[&#39;ad_1&#39;, &#39;ad_2&#39;, &#39;ad_3&#39;, &#39;ad_4&#39;, &#39;ad_5&#39;, &#39;ad_6&#39;, &#39;ad_7&#39;, &#39;ad_8&#39;, &#39;ad_9&#39;, &#39;ad_10&#39;]) <br> N = len(df)#Number of users<br> d = len(df.columns) #Number of ads<br> ads_selected = []<br> ads_rewards = [0] * d <br><br> numbers_of_rewards_1 = [0] * d<br> numbers_of_rewards_0 = [0] * d</pre><p>ads_selected == <em>The list of ads shown to each user in the system</em><br>ads_rewards == <em>This list would contain records of clicked ads as seen in the db</em><br>numbers_of_rewards_1 == <em>The times each ad was clicked</em><br>numbers_of_rewards_0 == <em>The times each ad was</em> <em>not clicked</em></p><p><strong>Next</strong></p><pre>for n in range(0, N):#For each user<br>   ad = 0<br>   max_random = 0<br>   for i in range(0, d):#for each add<br>      random_beta = random.betavariate(numbers_of_rewards_1[i] + 1, numbers_of_rewards_0[i] + 1)<br>   <br>      if random_beta &gt; max_random:<br>         max_random = random_beta <br>         ad = i<br>      ads_rewards[i] += df.values[n, i]#Accumulate this ad reward</pre><pre>   ads_selected.append(ad)<br>   reward = df.values[n, ad]<br>   if reward == 1:<br>      numbers_of_rewards_1[ad] += 1<br>   else:<br>      numbers_of_rewards_0[ad] += 1</pre><p><strong>The intuition behind this:</strong></p><p>For each ad of a particular user’s interaction, use the number of times the ad has been clicked and the number of times it hasnt been clicked to generate a random value between 0 and 1 using random.betavariate, now take the ad that got the highest of the randomly generated values and display it to the user</p><p><strong>Second step:</strong></p><p>Check if in the real world(i.e the db’s records), this selected ad was actually clicked by this user. If it was, increase the number_of_rewards_1 variable, else increase the number_of_rewards_0 variable of this particular ad.</p><p>This determines the magnitude of the value generated by the random.betavariate for that particular ad and this ultimately determines whether or not this ad would end up being selected</p><p>This loop uses reinforcement learning to keep adjusting itself and as user interaction of our web pages containing this app increases, the selected ad would start to converge on the one with the highest likes</p><h4>Take aways</h4><p>So far, we have seen how to setup a Django project that uses images, how Thomas sampling can be used to optimize ad selection, we also saw how i used sessions to create records for each user accessing our system. Finally, this algorithm uses reinforcement learning to keep adjusting itself and as user interaction of our web pages containing this app increases, the selected ad would start to converge on the one with the highest likes</p><p>In the <a href="https://medium.com/@wilpat456/thompson-sampling-with-django-part2-4c56e6b3fd71">second part</a>, i will be discussing how the ads gets displayed on a page, adding buttons to enable users ‘Like’ or ‘Dislike’ images thereby helping the program get better.</p><p>Wow that was a long one, so i’m glad you made it here. I hope this was helpful to you and I want to thank you for reading this post. Hit clap in case it was helpful so that others may find it too. You can also give suggestions in the comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce13548dc2a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix Broken Anaconda Environment Due To Recent Package Download]]></title>
            <link>https://medium.com/@wilpat456/fix-broken-anaconda-environment-due-to-recent-package-download-9094fb0f3a04?source=rss-ed2229f62f3e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9094fb0f3a04</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[anaconda]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[William Okafor]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 14:36:43 GMT</pubDate>
            <atom:updated>2019-03-23T08:41:36.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*eK_J7Wpn4RkSisCmZTtHzA.jpeg" /></figure><p>Fix Broken Anaconda Environment Due To Recent Package Download</p><p>So i installed tensorflow into my base anaconda environment and it practically broke everything.<br>Many important packages stopped working(Pandas, sklearn, matplotlib etc)<br>After much research and attempts to find quick fixes that didn’t really promise to solve the problem for all the affected packages, i found an overall solution and a best practice for installing packages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*1lVPe1BTHAmYy1NCyLXMKA.jpeg" /></figure><p>Run this command:conda list --revisions to view all the changes you’ve made in your environment.</p><p>Each revision would have a number attached to it (e.g rev 0)</p><p>Locate the revision number before your pulled in the package that broke things and run this command conda install --revision [revision number]</p><p>Note that if you wish to (re)install a later revision, you may have to sequentially reinstall all intermediate versions. This means that if you had been at revision 23, reinstalled revision 20 and wish to return, you may have to run each:</p><pre>conda install --revision 21<br>conda install --revision 22<br>conda install --revision 23</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*tvGSXxlY6rspf4EhKoJ7Rw.jpeg" /><figcaption>That works for me though</figcaption></figure><p>First, It’s best to separate concerns with environments when writing applications, so if your program has a dependency that’s not likely needed in other applications, create an environment for it.</p><p>Secondly, when installing a new package, if you get notified that it’s gonna make changes (upgrade or downgrade) to some packages you already have in that environment, please first create a new environment for this program before pulling in this package. At the end of the day, you might choose to leave the new package in this new environment, and any new program that has this dependency, can use that environment as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9094fb0f3a04" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>