<?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 akm on Medium]]></title>
        <description><![CDATA[Stories by akm on Medium]]></description>
        <link>https://medium.com/@andkamau?source=rss-58cd6e6e063f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kYk9iHtxjMZrHwLMgIF6Cw.png</url>
            <title>Stories by akm on Medium</title>
            <link>https://medium.com/@andkamau?source=rss-58cd6e6e063f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 10:26:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andkamau/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[The chat bots are coming… to stay!]]></title>
            <link>https://medium.com/pia-blog/chat-bots-pia-c02a8f9fb668?source=rss-58cd6e6e063f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c02a8f9fb668</guid>
            <category><![CDATA[convcomm]]></category>
            <category><![CDATA[messaging]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[conversational-commerce]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[akm]]></dc:creator>
            <pubDate>Wed, 14 Dec 2016 08:21:03 GMT</pubDate>
            <atom:updated>2016-12-16T01:37:00.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjnyofyxyRO8mYUnFfZZiQ.png" /><figcaption>Conversational service delivery on <a href="http://pia.chat/">Pia</a>.</figcaption></figure><p>In 2015, an important milestone was reached. For the first time, the number of active users of messaging services worldwide surpassed that of social networking apps. This is a big deal. It’s a reflection of how we spend our time on the social web. Numbers from <a href="https://www.statista.com/">Statista</a> show that over 65% of social web usage is on messaging apps.</p><p>For users in Africa, it gets even more interesting. In 2016, for the first time, the number of smartphone users has surpassed that of feature phone users on the continent and continues to grow 52% annually and is expected to hit 1 billion by the end of the decade.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7b433zIhy38Num6WZ4dC_w.png" /><figcaption>Rise of smartphone messaging (Sources: BI Intelligence &amp; Atlas / Jefferies &amp; Co.)</figcaption></figure><h4>Going messaging first</h4><p>After an incredibly successful Web 2.0 revolution, came the mobile-first approach, where technology products were optimised for smartphones and feature phones.</p><p>We are now at the sunrise of an even more incredible, powerful shift to “the unified web”, where mobile messaging, artificial intelligence and APIs will play a fundamental role in providing a platform to access digital content and services: a platform where services are interwoven; and not stand-alone. Where products are interoperable and collectively aware of each other. Where you can securely complete a bank transaction on your watch; access utility services on mobile messaging; quantify your business impact on social media; and express yourself online without barriers and service restrictions</p><h4><strong>Human Computer Interaction</strong></h4><p>Communication is an essential component of human interaction. The primary enabler of human communication is language — which enables us to effectively communicate our thoughts, feelings, and ideas.</p><p>Web and mobile technology has presented us with more channels of communication than we have ever had. This growth of technology has brought with it a variety of evolutions in the way we work, interact with each other, play, and do business.</p><p>For a long time, interaction with software has been skewed towards humans structuring their interaction to what computers can understand. Think of the last time you used M-Pesa, the mobile money service, or the last time you accessed your mobile banking service. It was probably a structured menu of items with deep, static navigation options.</p><p>The shift to messaging as a platform means we can finally interact with software in the most natural, intuitive way we know how: language. “Send 500 bob to Mum” or “Request uber from home”.</p><h4>Pia</h4><p>For us, <a href="http://pia.chat/">Pia</a> is the first step into this connected world of digital services accessible on a conversational interface. <a href="http://pia.chat/">Pia is the first messaging-first service</a> that allows you to access a range of services and content directly from the messaging apps that you already use.</p><p>We currently support financial transactions via M-Pesa in Kenya, Uber ride requests, news and a variety of localised content — all delivered on messaging as a platform. We are now on Facebook Messenger and will soon activate the service on multiple messaging platforms.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNR8Thm82BWQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNR8Thm82BWQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FNR8Thm82BWQ%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f38066199fafff6b63d7d964682bd2cb/href">https://medium.com/media/f38066199fafff6b63d7d964682bd2cb/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=facebook&amp;url=https%3A//www.facebook.com/permalink.php%3Fstory_fbid%3D312729269127225%26id%3D304973886569430&amp;image=" width="600" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/ede4d88c24fc43dde5da61f68f6e9509/href">https://medium.com/media/ede4d88c24fc43dde5da61f68f6e9509/href</a></iframe><p>With Pia, we are betting on messaging as a platform for service delivery and aiming towards democratisation of AI to a point where it’s useful enough for day-to-day consumer and business usage.</p><p><em>About Pia: </em><a href="http://pia.chat/"><em>Pia</em></a><em> is the first messaging-first service delivery platform made for the Kenyan market. </em><a href="https://m.me/304973886569430"><em>Try PIA today</em></a><em>!</em></p><p><em>Pia for Business: We build chat bots for businesses to deliver services and support to their users. </em><a href="/service/mailto:andrew@pythias.io"><em>Contact us</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c02a8f9fb668" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pia-blog/chat-bots-pia-c02a8f9fb668">The chat bots are coming… to stay!</a> was originally published in <a href="https://medium.com/pia-blog">Pia Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sentiment Analysis and Entity Extraction (Dev-Craft 2016 session recap)]]></title>
            <link>https://medium.com/@andkamau/sentiment-analysis-and-entity-extraction-dev-craft-2016-session-recap-3c1a6dbc8d37?source=rss-58cd6e6e063f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c1a6dbc8d37</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <dc:creator><![CDATA[akm]]></dc:creator>
            <pubDate>Mon, 03 Oct 2016 07:45:12 GMT</pubDate>
            <atom:updated>2016-10-03T09:39:53.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93yyKRH_UK8zV71AUZdT_g.jpeg" /><figcaption>Eve leading a hands-on code lab session on Sentiment Analysis using AlchemiAPI</figcaption></figure><p>At <a href="http://codeforafrica.org/">Code For Africa</a>, we frequently find ourselves in situations where we need to work with unstructured data: PDF documents, news articles, and social media posts. We use a slew of techniques, tools, and APIs to quantify this data and extract entities from it.</p><p>Eve and I were invited to <a href="http://dev-craft.co.ke/">Dev-Craft 2016</a> to lead a session on language processing tools that developers can tap into. We decided to cover IBM’s <a href="http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/">AlchemyAPI</a> and <a href="http://polyglot.readthedocs.io/en/latest/">Polyglot</a> for sentiment analysis and entity extraction. We ran through a hands-on session where we built simple working tools that tap into the power of natural language processing. Here’s what was covered:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Uphl_UOTj2OnPrJ30sdSw.png" /></figure><h3>AlchemyAPI with Javascript</h3><p>API documentation: <a href="http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/">http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/</a></p><p>1) Navigate to <a href="http://www.alchemyapi.com/">http://www.alchemyapi.com/</a> and obtain an API key</p><p>2) Workspace: <a href="http://jsfiddle.net/mevey/wgL0vmy4/43/">http://jsfiddle.net/mevey/wgL0vmy4/43/</a></p><ul><li>Pre-filled HTML and CSS on top left and right</li><li>Edit Javascript on bottom left</li><li>Results on bottom right</li></ul><p>3) On the Javascript section on JS-Fiddle, enter the Alchemy API key</p><pre>key = &#39;xxxx1112223333&#39;</pre><p>4) Fill in the API URLs for each end-point. Reference: <a href="http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/#sentiment">http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/#sentiment</a></p><pre>sentiment_api = &#39;https://gateway-a.watsonplatform.net/calls/url/URLGetTextSentiment?outputMode=json&amp;apikey=&#39; + key<br>entities_api = &#39;https://gateway-a.watsonplatform.net/calls/url/URLGetRankedNamedEntities?outputMode=json&amp;sentiment=1&amp;apikey=&#39; + key</pre><p>5) On your terminal, use curl to test the URLs and view the response format.</p><pre>curl -X POST \<br>-d &quot;outputMode=json&quot; \<br>-d &quot;url=http://www.huffingtonpost.com/2010/06/22/iphone-4-review-the-worst_n_620714.html&quot; \<br>&quot;https://gateway-a.watsonplatform.net/calls/url/URLGetTextSentiment?apikey=xxx111222333&quot;</pre><pre>curl -X POST \<br>-d &quot;outputMode=json&quot; \<br>-d &quot;maxRetrieve=3&quot; \<br>-d &quot;url=http://www-03.ibm.com/press/us/en/pressrelease/49384.wss&quot; \<br>&quot;https://gateway-a.watsonplatform.net/calls/url/URLGetRankedNamedEntities?apikey=xxx111222333&quot;</pre><p>6) Response format example:</p><pre>{<br>    &quot;status&quot;: &quot;OK&quot;,<br>    &quot;usage&quot;: &quot;By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html&quot;,<br>    &quot;totalTransactions&quot;: &quot;1&quot;,<br>    &quot;language&quot;: &quot;english&quot;,<br>    &quot;docSentiment&quot;: {<br>        &quot;score&quot;: &quot;0.603233&quot;,<br>        &quot;type&quot;: &quot;positive&quot;<br>    }<br>}</pre><p>7) Back on JS-Fiddle, write Javascript code to make a request to the API</p><pre>$.ajax({<br>        method: &quot;POST&quot;,<br>        url: sentiment_api + outputMode,<br>        data: $(&#39;#form&#39;).serialize(),<br>        contentType: &#39;application/x-www-form-urlencoded&#39;,<br>        success: function(msg) {</pre><pre>        // Write your response handling code here</pre><pre>        }<br>      });</pre><p>8) Go ahead and display your result (no. 6 above) on the HTML page.</p><p>9) An example of response handling for sentiment analysis:</p><pre>//Sentiment Analysis<br>       $.ajax({<br>        method: &quot;POST&quot;,<br>        url: sentiment_api + outputMode,<br>        data: $(&#39;#form&#39;).serialize(),<br>        contentType: &#39;application/x-www-form-urlencoded&#39;,<br>        success: function(msg) {<br></pre><pre>          $(&#39;#sentiment-results&#39;).html(&#39;&lt;span&gt;&#39; + msg.docSentiment.type + &#39;&lt;/span&gt; with a score of &lt;span&gt;&#39; + msg.docSentiment.score + &#39;&lt;/span&gt;&#39;)<br></pre><pre>        }<br>      });</pre><pre>      //Entity extraction<br>      $.ajax({<br>        method: &quot;POST&quot;,<br>        url: entities_api + outputMode,<br>        data: $(&#39;#form&#39;).serialize(),<br>        contentType: &#39;application/x-www-form-urlencoded&#39;,<br>        success: function(msg) {<br></pre><pre>            markup = &#39;&#39;<br>            for (k in msg.entities) {<br>                v = msg.entities[k]<br>                markup += &#39;&lt;span&gt;Text: &#39; + v.text + &#39;&lt;/span&gt;  &lt;span&gt;count: &#39; + v.count + &#39;&lt;/span&gt;  &lt;span&gt;Type: &#39; + v.type + &#39;&lt;/span&gt;  Relevance: &lt;span&gt;&#39; + v.relevance + &#39;&lt;/span&gt;  Sentiment: &lt;span&gt;&#39; + v.sentiment.type + &#39;&lt;/span&gt;&lt;br&gt;&#39;<br>            }<br>            $(&#39;#entities-results&#39;).html(markup)<br></pre><pre>        }<br>      });</pre><p>10) Add another response handler for entity extraction.</p><p>11) Test.</p><h3>Polyglot (with Python)</h3><p>1) Clone the github repo: <a href="https://github.com/CodeForAfricaLabs/sentiment_icebreaker">https://github.com/CodeForAfricaLabs/sentiment_icebreaker</a></p><pre>git clone <a href="https://github.com/CodeForAfricaLabs/sentiment_icebreaker">https://github.com/CodeForAfricaLabs/sentiment_icebreaker</a></pre><p>1) Obtain Twitter API keys.</p><ul><li>Create a new Twitter app here: <a href="https://apps.twitter.com/">https://apps.twitter.com/</a></li><li>Obtain Consumer Key, Consumer secret from the “Keys and Access Tokens” tab.</li><li>Update permissions to allow for “Read, Write and Access direct messages”</li><li>Generate access tokens and obtain the “Access Token” and “Access Token Secret”</li></ul><p>2) Copy twitter API credentials into the configuration file: twitter_/config.py.</p><pre>TW_AUTH_CREDENTIALS[&#39;consumer_key&#39;] = &quot;&quot;   # Consumer Key (API Key)<br>TW_AUTH_CREDENTIALS[&#39;consumer_secret&#39;] = &quot;&quot;   # Consumer Secret (API Secret)<br>TW_AUTH_CREDENTIALS[&#39;access_token_key&#39;] = &quot;&quot;  # Access Token<br>TW_AUTH_CREDENTIALS[&#39;access_token_secret&#39;] = &quot;&quot;  # Access Token Secret</pre><p>3) [OPTIONAL] Create a python virtualenv</p><pre>pip install virtualenv<br>virualenv /path/to/your/env</pre><p>4) Open the root directory sentiment_icebreaker</p><pre>cd sentiment_icebreaker</pre><p>5) Install python dependencies</p><pre>pip install -r requirements.txt</pre><p>⚠️ OSX dependencies:</p><pre>CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu</pre><p>⚠️ Ubuntu dependencies:</p><pre>sudo apt-get install libicu-dev</pre><p>6) Install polyglot language packs</p><pre>make install-language-packs</pre><p>7) Open twitter_/listener.py: Run through language detection</p><pre>msg_text = payload[&quot;message&quot;]<br>language_detector = Detector(msg_text)<br>language = language_detector.language.name</pre><p>8) Run through sentiment analysis</p><pre>try:<br>    msg_polarity = Text(msg_text).polarity<br>except ZeroDivisionError:<br>    msg_polarity = 0</pre><p>9) Run through entity extraction</p><pre>msg_entities = []<br>for entity in Text(msg_text).entities:<br>    msg_entities.append(entity)</pre><p>10) Change the question on HTML: web/app/templates/index.html</p><pre>&lt;center&gt;&lt;h1 class=&quot;question&quot;&gt;Tell us what you think about this session.&lt;/h1&gt;&lt;/center&gt;</pre><p>11) Start the Twitter Direct Messages stream listener:</p><pre>make start</pre><p>12) Start the Flask web server:</p><pre>make webserver</pre><p>⚠️ If you encounter an issue with imports,</p><pre>export PYTHONPATH=/location/of/your/project/</pre><p>⚠️ If you encounter an issue with log file location</p><pre>mkdir -p /location/of/your/project/sentiment_icebreaker/logs</pre><p>💡 Tail logs to see app activity:</p><pre>tail -f logs/twitter-stream.log</pre><h3>Useful Resources</h3><ul><li>JS Fiddle: <a href="http://jsfiddle.net/mevey/wgL0vmy4/24/">http://jsfiddle.net/mevey/wgL0vmy4/24/</a></li><li>Code: <a href="https://github.com/CodeForAfricaLabs/sentiment_icebreaker">https://github.com/CodeForAfricaLabs/sentiment_icebreaker</a></li><li>UG election sentiment analysis: <a href="https://goo.gl/jcuJjC">https://goo.gl/jcuJjC</a></li><li>Aleph: <a href="https://data.investigativecenters.org/">https://data.investigativecenters.org/</a></li><li>Alchemy API: <a href="http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/">http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/</a></li><li>Polyglot: <a href="http://polyglot.readthedocs.io/">http://polyglot.readthedocs.io</a></li><li>Semantria: <a href="https://www.lexalytics.com/semantria">https://www.lexalytics.com/semantria</a></li><li>Google Language APIs: <a href="https://cloud.google.com/natural-language">https://cloud.google.com/natural-language</a></li><li>Slide deck: <a href="https://docs.google.com/presentation/d/1efYr_K-Na-T5DkGEUpXDELVpv2esiuGKvsxOG_OSyxQ/edit?usp=sharing">https://docs.google.com/presentation/d/1efYr_K-Na-T5DkGEUpXDELVpv2esiuGKvsxOG_OSyxQ/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0yMExXUcOusbsgOXnEV-TA.jpeg" /><figcaption>Session participants getting hands-on</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-d5BOo-JH0k307HEPHzPw.jpeg" /><figcaption>Andrew leading the python code-lab</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c1a6dbc8d37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimising RabbitMQ for Security and Scale]]></title>
            <link>https://medium.com/@andkamau/https-codeforafrica-tech-optimising-rabbitmq-for-security-and-scale-by-andkamau-116aff5061aa?source=rss-58cd6e6e063f------2</link>
            <guid isPermaLink="false">https://medium.com/p/116aff5061aa</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[soa]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[akm]]></dc:creator>
            <pubDate>Wed, 27 Jul 2016 15:50:12 GMT</pubDate>
            <atom:updated>2016-07-27T15:50:12.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ztpya5Z-pLR8SR3axWOFw.jpeg" /></figure><p>Cross service messaging is an integral part of our technology stack — as it is for most SOA architectures. Having played around with <a href="https://aws.amazon.com/sqs/">Amazon’s SQS</a> and <a href="http://redis.io/topics/pubsub">Reids PubSub</a>, we mostly revert to <a href="http://www.rabbitmq.com/features.html">RabbitMQ</a> for our queuing and messaging needs on production workloads, for several reasons.</p><p>One of the factors that draws us to RabbitMQ is the strong <a href="http://www.rabbitmq.com/configure.html">configuration latitude</a> that it offers. This post is a description of one of our RabbitMQ instances, that’s optimised for scale and security.</p><h4>Setup</h4><p>We have a dedicated memory-optimised medium EC2 instance for the AMQP server so each service that requires RabbitMQ uses a dedicated vhost associated with a unique user configured with read, write and configure permissions for only its vhost. This way, each service is responsible only for its vhost, thus distributing the possible points of failure or misconfiguration.</p><p>From our experience, the default RabbitMQ configuration is good enough for development and staging workloads for most use cases, but doesn’t scale in production. Below are the configurations that we’ve implemented to easily handle ever increasing workloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xok6rB2uZkGuKFzVdfQZ7A.png" /></figure><h4>Memory Optimisation</h4><p>Arguably the biggest pain point with RabbitMQ is the memory alarm, typically triggered when the server uses over 40% of the host’s RAM. The first step to proper memory management is of course provisioning sufficient RAM on the host, and enabling <a href="https://en.wikipedia.org/wiki/Paging">swap storage</a>. Equally important is smart memory management on the rabbitmq server using the <em>vm_memory_high_watermark</em> config variable. This is the cap at which point the AMQP server throttles new publishes until garbage collectors kick in or more messages are consumed.</p><p>We set an absolute limit of 1.6GB as our cap, primarily because no other memory hungry processes run on the same host. However, on a shared box, it’s probably a better idea to use a relative (expressed as a percentage) cap (e.g. the default 40%). It’s worth reading <a href="http://www.rabbitmq.com/memory-use.html">this guide on how RabbitMQ allocates memory</a>.</p><pre>[{rabbit, [{vm_memory_high_watermark, {absolute, “1638MiB”}}]}]</pre><h4>Security and Access Control</h4><p>The first steps we took to secure our server was the textbook <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html">EC2 security policies</a>, only allowing inbound traffic from a finite number of IP addresses. On top of this, a customised OS level firewall, using <em>iptables</em> on Ubuntu. For the extra paranoid (<a href="https://rhinosecuritylabs.com/2016/02/aws-security-vulnerabilities-and-the-attackers-perspective/">which you should be if you’re on a public cloud</a>), it’s worth restricting <em>ssh</em> access and only managing RabbitMQ via the <a href="https://www.rabbitmq.com/management.html">management web interface</a>, as well as removing the default vhost “/” and default user “guest”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8C1dmzHUwoeEdSQwzvygQ.png" /><figcaption>Management interface — using the native management plugin</figcaption></figure><p>On the application level, we have only one admin user. We then create regular users for each application talking to rabbitmq, each with a corresponding vhost. This way, if one user messes up, damage is contained within one vhost.</p><h4>Network level</h4><p>RabbitMQ clients talk to the server via TCP based protocols. The obvious steps in securing the network channels is implementing SSL — which is <a href="http://www.rabbitmq.com/ssl.html">well described here</a>.</p><p>Using the configuration directive - <em>tcp_listen_options</em> — we’ve bumped up the TCP buffer size to 200KiB, just about double the default allocated by the operating system.</p><pre>{tcp_listen_options, [<br>                        {backlog,   128},<br>                        {nodelay,   true},<br>                        {sndbuf,    204800},<br>                        {recbuf,    204800}<br>                       ]}</pre><h4>Load Test</h4><p>With these optimisations, we are able to handle over 1,000 messages published in a second, and over 300 deliveries per second to a consumer with a single thread.</p><p>To test the configuration, I hammered the server (using an over-zealous publisher) to breaking point — which was at just under a million un-delivered messages, at which point the high watermark memory limit was hit. Seems impressive for relatively modest system resources. This has proved to be more than sufficient for most of our use cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fs85H_zZXQcPQ7gp7qC6NQ.png" /><figcaption>Load test message rates</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzGhxNL2G-0p1jIw6NWrng.png" /><figcaption>823K messages when memory alarm was triggered</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0H5xTsHf3rA78Bm0lj13bw.png" /><figcaption>High memory cap of 1.6 GB — triggering memory alarm</figcaption></figure><p>To learn more about the work <a href="http://codeforafrica.org/">Code For Africa</a> does, scan the <a href="https://medium.com/code-for-africa">blog</a>, and follow us on <a href="https://twitter.com/code4africa">Twitter</a>.</p><p>For more tech posts, keep checking out <a href="https://codeforafrica.tech/latest">https://codeforafrica.tech/</a> and <a href="https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fcodeforafrica.tech&amp;ref_src=twsrc%5Etfw&amp;tw_p=tweetbutton&amp;text=.@MuthoniEve%20we%20will%20burn%20effigies,%20go%20on%20hunger%20strike,%20and%20match%20with%20placards%20-%20until%20you%20write%20a%20blog%20post%20on%20codeforafrica.tech">nudge others to write</a>.</p><p>Photography: Railway line near Madaraka, in Nairobi. By <a href="https://goo.gl/photos/KqNP6tKHiPoSWPUo8">Andrew Kamau</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=116aff5061aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The #KOT business classifieds site — powered by a single tweet!]]></title>
            <link>https://medium.com/@andkamau/the-kot-business-classifieds-site-powered-by-a-single-tweet-bd378fc9a73a?source=rss-58cd6e6e063f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd378fc9a73a</guid>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[kenya]]></category>
            <dc:creator><![CDATA[akm]]></dc:creator>
            <pubDate>Sun, 03 Jul 2016 20:52:53 GMT</pubDate>
            <atom:updated>2016-07-03T20:52:53.394Z</atom:updated>
            <content:encoded><![CDATA[<p>Every once in a while, there’s a story of someone doing a regular thing in an unconventional way, causing a dent of positive or negative impact.</p><p>One such thing happened last week on <a href="https://twitter.com/hashtag/kot">Kenyan Twitter</a>. It all began with one tweet…</p><h3>Shosho Light on Twitter</h3><p>It&#39;s good to promote eachother&#39;s businesses, ka uko na biz reply this tweet.. tell us about it, I&#39;ll retweet you never know</p><h4>The result?</h4><p>Some sort of viral magic! Hundreds of responses; thousands of retweets; and tens of thousands of impressions for people’s businesses and side-hustles. This translated to sales, business deals struck, partnerships, and lots and lots of engagement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcea7MXhNOE-Q0Dzz7DTmA.png" /><figcaption>Sales and business enquiries made on the TL</figcaption></figure><p>Everything from <a href="https://twitter.com/reema_farm/status/748604501892993024?replies_view=true&amp;cursor=AGCW3pJKZgo">farm produce</a>, to <a href="https://twitter.com/stakri_gi/status/748579188429496321">apparel</a> and <a href="https://twitter.com/_Wanjiru_/status/748745998827003906">cosmetics</a>, to <a href="https://twitter.com/Robbbby_G/status/748611670826684416">drone photography services</a>, <a href="https://twitter.com/Nymahsemoh_/status/748835842806939648">food</a>, <a href="https://twitter.com/DrKanyuira/status/748732067135889408">car parts</a>, and my personal favourite, <a href="https://twitter.com/rnjogu/status/748727289936916480">emoji pillows</a>!! Kenyans are an an enterprising lot! Hats off to @<a href="https://twitter.com/carolinespencer">CarolineSpencer</a> who constantly retweeted to her over 20K followers, instantly creating leads for people’s businesses.</p><h3>#TheBOB on Twitter</h3><p>@carolinespencer I sell emoji pillows, ideal birthday gifts, baby showers, interior decor our page @atlalamspic.twitter.com/vNUvM9nYvg</p><h4>Aggregation: <a href="http://kotbiz.site/">kotbiz.site</a></h4><p>I was so enthralled by all this, I made <a href="http://kotbiz.site/">a site</a> to aggregate all these Kenyan businesses and side-hustles to one free, twoud-sourced** business classifieds site — with content solely from responses to a <a href="https://twitter.com/carolinespencer/status/748567826907136000">single tweet</a>.</p><p><a href="http://kotbiz.site/">The website</a> (which is far from polished), quickly hacked up as my weekend project, is basically all responses to the original tweet — with a slight twist. They are ranked by engagement (i.e. retweets + likes). Tweets with higher engagement will rank higher.</p><p>I hope to soon make them categorised and search-able.</p><h4>Rough edges</h4><p>Most responses to the tweet are actually valid business plugs, but of course there’s <a href="https://twitter.com/_wangwe/status/748591537441763328">some</a> <a href="https://twitter.com/ki_bet/status/748633554117087233">gibberish</a> that needs to be filtered out.</p><p>The site only aggregates responses that came from replies (which is most of them), but misses out on other forms of engagement like quoted retweets.</p><p>There currently isn’t a way to update an existing entry. I might just add that soon.</p><p>Also, the UI is a bit clunky. Sorry. But it works.</p><h4>The small print</h4><ul><li>If you like any of this stuff, you should probably buy <a href="https://twitter.com/carolinespencer">her</a> a drink.</li><li>This is not a commercial project. The site (<a href="http://kotbiz.site/">kotbiz.site</a>) is free for all.</li><li><strong>Content:</strong> All content is automatically pulled from a public Twitter feed.</li><li><strong>Tech:</strong> The entire project is <a href="https://github.com/andkamau/twitter-biz-ke">open source</a> and contributions are welcome. No, they’re encouraged!</li><li>Like most people, the maker of <a href="http://kotbiz.site/">this site</a> is a big fan of food and coffee. Especially the unsolicited kind. <a href="http://andkamau.xyz/">Feel free to offer them some of yours</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd378fc9a73a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When all else fails: Web scraping against a large list of names]]></title>
            <link>https://medium.com/@andkamau/when-all-else-fails-web-scraping-against-a-large-list-of-names-c738b3552cf7?source=rss-58cd6e6e063f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c738b3552cf7</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[africa]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[akm]]></dc:creator>
            <pubDate>Wed, 29 Jun 2016 18:51:19 GMT</pubDate>
            <atom:updated>2016-06-29T19:06:45.626Z</atom:updated>
            <content:encoded><![CDATA[<p>At Code For Africa, we work a lot with data. All sorts of data.</p><p>A lot of it is structured and in easy to use formats (such as CSVs, databases, and REST APIs). This is fun and easy to work with.</p><p>Some of the data is semi-structured (e.g. Word and PDF documents, HTML, and emails). This is semi-fun and moderately easy to manipulate and work with.</p><p>Some of the data is completely unstructured. This type of data is annoying to work with and is frankly, a pain in the ass. This type of data inspired this blog post.</p><p>One of our <a href="http://health.the-star.co.ke/">health tech tools</a> — which lets you to check if your doctor is a quack — is powered by a structured dataset of registered doctors. Our current enhancement on this is including all details on registered nurses in Kenya as well. Because nobody wants quack nurses!</p><h4>Problem</h4><p>Off the bat, we were faced with a hurdle. The data. The Nursing Council of Kenya (NCK), the industry regulator has the list of registered nurses and it’s <a href="http://nckenya.com/online-services/retention/">available on their website</a>, but there’s a catch. It’s only available via a basic search interface that queries their data store and returns only results that fully match the search query. This means: no search operators, no empty search to return all, no index, and no way to know the size of the data set.</p><p>Naturally, I sent a request for the data via email — and they obviously didn’t reply, so I got thinking….</p><h4>Getting hands dirty</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9rohd5SCueKYMKYvRuoIw.png" /><figcaption>Inspection of the network calls on Chrome</figcaption></figure><p>On an inspection of the network calls invoked by the site, I found that a search query calls a php web service and passes two query string parameters: ‘p’ and ‘s’, where ‘s’ is the search query. This in turn returns a simple HTML table with the names, license numbers, and validity dates of each nurse whose name matches the search query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3rxjh6gQftwDQ8FAmfx5Q.png" /><figcaption>HTML table returned by the PHP</figcaption></figure><p>With that, we had the necessary ingredients to do a direct search that will give us some structured HTML which we can parse. Except one thing was missing: the query parameters. The nurses’ names.</p><p>Because there is a finite number of names, we decided to run searches on all names possible. Inefficient? Yes. Absolutely. But there really wasn’t any other option, as the search on <a href="http://nckenya.com/">nckenya.com</a> only returns results for exact matches. For example searching for “ngela” will return no results; while “angela” will yield many.</p><p>To get the list of names, we started off with <a href="http://www.nrscotland.gov.uk/files/statistics/pop-names-07-t4.csv">this CSV</a> — that contains a list of over 6,000 common male and female English names, wrote a <a href="https://github.com/CodeForAfricaLabs/nurses_ke/blob/master/scrape.py">simple script</a> that queries the php, passing ‘s’ as the name, then scrapes the resulting HTML to extract name, license number, and date, and finally saves the values in a <a href="http://redis.io/">redis</a> store.</p><p>This gave us 9,160 unique nurses. Not bad, considering we made 6,481 calls. Turns out most people’s names aren’t unique! This was only the beginning though. We still didn’t have the bulk of the names on the list — and a glaring omission in our initial list was the lack of Kenyan names. For this, we added a hook on the script that captures the middle name and surname for each successful search query. This simple enhancement gave us about 90,000 more names. Of course, many were duplicates. After running it through our <a href="http://twitter.com/callmealien">resident data wrangler, spreadsheet guru, and extraterrestrial being</a>, the list came down to 7,458 unique names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dSa1dbmVlCs76yQxDJbwVg.png" /><figcaption>Capture surnames on each iteration</figcaption></figure><p>And with that, ran the script again — this time against the list of 7,458 names. Surprisingly, this second run gave us 19,068 results! Turns out there are 48% more people without the “common English names” in our first CSV.</p><p>Finally, we ended up with a list of 28,228 registered nurses. Unfortunately, there isn’t a fool proof way to independently verify the coverage of our dataset vis-a-vis the NCK data, but this was much better than nothing!</p><h4>Assumptions and Errors</h4><p>Some <a href="http://www.health.go.ke/wp-content/uploads/2015/09/Kenya%20Nursing%20Workforce%20Report.pdf">government records</a> seem to indicate that there are 103 nurses for every 100,000 people in the country — which means that we may still be off by about 10K (assuming a population of 40M).</p><p>As expected, there were a number of runtime errors (2.1% of total to be precise) which I’m yet to revisit. They mostly look like web scraping output exceptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3sP5dmcTNPhXbcu7lAG_g.png" /><figcaption>Runtime errors</figcaption></figure><p>We are refining our scraping tools to be able to work better and more efficiently with unstructured content, and I look forward to enhancing this, <a href="https://github.com/CodeForAfricaLabs/nurses_ke">open sourcing</a> it and sharing more on this at a later date.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c738b3552cf7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>