<?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 Ekojoka Chris Idakwo on Medium]]></title>
        <description><![CDATA[Stories by Ekojoka Chris Idakwo on Medium]]></description>
        <link>https://medium.com/@chrisidakwo?source=rss-6a28dd141fb9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*W7krkxlRB3dyTa3MZEAevw.jpeg</url>
            <title>Stories by Ekojoka Chris Idakwo on Medium</title>
            <link>https://medium.com/@chrisidakwo?source=rss-6a28dd141fb9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:51:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chrisidakwo/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 Time & Time Zone Fallacies Believed By Programmers]]></title>
            <link>https://medium.com/@chrisidakwo/the-time-time-zone-fallacies-believed-by-programmers-21c53c629db9?source=rss-6a28dd141fb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/21c53c629db9</guid>
            <category><![CDATA[fallacy]]></category>
            <category><![CDATA[date]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[timezone]]></category>
            <dc:creator><![CDATA[Ekojoka Chris Idakwo]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 13:44:19 GMT</pubDate>
            <atom:updated>2018-08-08T13:44:19.494Z</atom:updated>
            <content:encoded><![CDATA[<p>Not until recently, I unknowingly believed and worked by these falsehoods.</p><ul><li><strong>Every day has 24 hours</strong></li></ul><p>Counter example: Because of daylight saving time (DST) some days could have 23 hours and some could have 25 hours. Or some other amount of hours — whole or not.</p><ul><li><strong>Every day without DST changes is 86400 (60 * 60 * 24) seconds long</strong></li></ul><p>Well, sometimes the UTC offset for a timezone is changed.</p><ul><li><strong>… at least in UTC</strong></li></ul><p><a href="http://www.nextleapsecond.com/">Leap seconds</a> cause some days to have an extra second. And theoretically there could be negative leap seconds. Although negative leap seconds have not happened yet because the rotation of the earth so far has been slower than UTC, as it were, and not faster.</p><ul><li><strong>Week one of a year starts in January every year</strong></li></ul><p>January 1st is not always a monday so some days of an ISO week will be in different years. Example: 2014 December 28th belongs to week 1 of 2015.</p><ul><li><strong>If I know what time zone someone is in and they just tell me the date and local time, I can always use software to find out what time that is in UTC</strong></li></ul><p>If they are in the middle of changing from summertime to wintertime, the clock will be set back one hour. This means that an hour exists twice, so to speak. If the clock is set back to 2:00 and someone tells you that the local time was 2:17 for instance, you do not know if he is talking about 2:17 before the clocks were set back or 2:17 after the clocks were set back.</p><ul><li><strong>DST always sets the clock back and forth by exactly one hour</strong></li></ul><p>Throughout history there are examples of DST rules that set the clocks back and forth 2 hours or 30 minutes. A current example (h/t <a href="https://twitter.com/derickr/status/560551074701275136">Derick Rethans</a>) is Australia/Lord_Howe which advances the clocks by 30 minutes for DST.</p><ul><li><strong>Countries that observe DST begin observing DST in the first half of the year and end observing DST in the last half of the year</strong></li></ul><p>Not in the southern hemisphere, where summer time might begin in October and end in March.</p><ul><li><strong>OK, but DST always starts around spring and continues until fall</strong></li></ul><p>Except for Morocco, where in the middle of summer, DST is suspended for a month during Ramadan (depending on which year it is).</p><ul><li><strong>If I have a timestamp for a future event, I can convert it to UTC, store it as UTC along with the time zone and be sure that I can reliably convert it back to the correct “wall time” in the future</strong></li></ul><p>If time zone rules change in the mean time for the time zone in question, converting back from UTC to “local time” might produce a different result. <a href="http://www.creativedeletion.com/2015/03/19/persisting_future_datetimes.html">Follow this link for a solution</a>.</p><ul><li><strong>Time zone rules do not change</strong></li></ul><p>In 2014 there were 10 updates to the <a href="https://www.iana.org/time-zones">Olson database</a> released during the year.</p><ul><li><strong>If I keep my operating system up to date by installing updates, my operating system will have all the newest time zone updates</strong></li></ul><p>As of January 2015 the newest tzdata package for Ubuntu 14 has data from June 2014 and not the latest 2014j release from November 2014.</p><ul><li><strong>CST is a unique identifier for a time zone (Central Standard Time in the USA)</strong></li></ul><p>CST is also used for: Cuba Summer Time, China Time, Central Standard Time (Australia). PST is used for Pakistan Standard Time and Pacific Standard Time. If you want a unique identifier for the time zone in the Pacific West of the USA it looks like this: “America/Los Angeles”.</p><ul><li><strong>If you have two UTC timestamps it is possible to calculate how many seconds will be between them even if one of the timestamps is a year into the future</strong></li></ul><p>There might be <a href="http://www.nextleapsecond.com/">leap seconds</a> introduced, but you cannot be sure when or how many. However they are announced at least 6 months in advance, so if none of the two times are more than 6 months in the future and you keep up with news about leap seconds you can calculate it.</p><ul><li><strong>The date-time combination 2014 March 30th 2:20:42 is always valid</strong></li></ul><p>In central European time zones such as Europe/Copenhagen, that time does not exist in local time because of DST making the clocks being advanced by an hour from 2:00 to 3:00. This causes an hour to be skipped.</p><ul><li><strong>The time 23:59:60 is always invalid</strong></li></ul><p>When leap seconds are inserted, a minute will be 61 seconds long.</p><ul><li><strong>I can trust that if someone has written a library to handle date and time, it will work reasonably well</strong></li></ul><p>Many people write libraries without knowing much about the domain. And developers who also do not know much about the domain will use those libraries. Often things will work fine for a long time if for instance you only deal with timezones in a few countries where the time zone rules do not change a lot. It works fine — until it does not. It can become a case of the blind library developers leading the blind library users.</p><p>This piece was gotten from the creator of the <a href="https://github.com/lau/calendar">Elixir tzdata parser and datetime library</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21c53c629db9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple is better than complex: Python Challenge]]></title>
            <link>https://medium.com/@chrisidakwo/simple-is-better-than-complex-python-challenge-9374d905ef3b?source=rss-6a28dd141fb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9374d905ef3b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[challenge]]></category>
            <dc:creator><![CDATA[Ekojoka Chris Idakwo]]></dc:creator>
            <pubDate>Sat, 01 Jul 2017 06:40:26 GMT</pubDate>
            <atom:updated>2017-07-01T06:40:57.502Z</atom:updated>
            <content:encoded><![CDATA[<p>If the implementation is easy to explain, it may be a good idea.</p><p>…</p><p>I came across this challenge, old but gold. I shared it with a couple folks, but also decided to share it, probably someone might it a try and come up with a better solution.</p><p>I’ve been trying to hack a solution better than the ones currently provided here: <a href="https://gist.github.com/mjhea0/0a6b0bb6cc7557776ab8">Some Available Solutions</a></p><h3>The Challenge</h3><ol><li>There are two players.</li><li>Each player writes a number, hidden from the other player. It can be any integer 1 or greater.</li><li>The players reveal their numbers.</li><li>Whoever chose the lower number gets 1 point, unless the lower number is lower by only 1, then the player with the higher number gets 2 points.</li><li>If they both chose the same number, neither player gets a point.</li><li>This repeats, and the game ends when one player has 5 points.</li></ol><p>The challenge is to write a script to play this game. Knowing the rules and all your opponent’s previous numbers, can you program a strategy?</p><p>By the way, return random.randint(1, 3) is not a strategy!</p><p>It went further to say:</p><p>To make the strategy a bit more interesting, add an additional constraint to the challenge so that players can only use each number once.</p><p>And don’t try to google the challenge and copy the solution.</p><p>Grading your code is quite easy, just run your strategy through the random number generator 100 times as a first screen — return random.randrange(1, 10) If it beats the generator then you’re up to something. Use this: <a href="https://gist.github.com/mjhea0/0a6b0bb6cc7557776ab8"><em>game runner</em></a><em> to test our your code.</em></p><p>Worked on a possible solution for this? You can mail a gist to: chrisatgmaildotcom. I’d love to see different approaches to the problem. Got some already.</p><p>Btw, the Part 2 for Data Visualisation Made Easy With Python is on its way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9374d905ef3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Visualization Made Easy with Python (Part 1)]]></title>
            <link>https://medium.com/@chrisidakwo/data-visualization-made-easy-with-python-part-1-19c18c95331b?source=rss-6a28dd141fb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c18c95331b</guid>
            <category><![CDATA[pygal]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-visualisation]]></category>
            <dc:creator><![CDATA[Ekojoka Chris Idakwo]]></dc:creator>
            <pubDate>Sat, 03 Jun 2017 16:12:06 GMT</pubDate>
            <atom:updated>2017-06-07T17:29:54.467Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Summary: Visualising weather data with pygal</p><p>Gone are the days you needed to be a programming expert to be able to make meaning of basic data.</p><p>Nowadays, just about any python beginner could pull off some stunning visualisation of <strong><em>basic</em></strong> data with the help of simple-to-use modules such as pygal, matplotlib and a few others. No intense technical knowledge required. No need to have an extensive knowledge of Javascript. In fact, you do not need Javascript.</p><p>Although, of course, there will always be a difference between the final product of a beginner and an expert, that’s why I ensure to stress on the word — <strong><em>basic</em></strong>. Once you’ve gotten a hang of the basic, you can then move on to the not-so-basic.</p><p>Here is a small bit of what I mean when I say “Data Visualization Made Easy with Python”.</p><blockquote>Note: As from this point, I assume you already have some basic knowledge of working with Python and you understand what I mean when I say JSON and Web API. If you don’t, then read this for <a href="https://en.wikipedia.org/wiki/JSON">JSON</a>, and this for <a href="http://www.makeuseof.com/tag/api-good-technology-explained/">Web API</a>. Continue after your reading.</blockquote><p>I’ll demonstrate how to write a self-contained program that will make some API calls, retrieve data from that call in JSON format, and use the received data for simple visualisation with a bar chart.</p><blockquote>Note: Because APIs always generate current data, the data set I will be using for this demonstration might be different from the one you get; depending on when you’re reading this. No need to fear. The technique and code base for reading the data you get is entirely the same, at least for Python 3 — which is what I’m using for this demonstration.</blockquote><h3>We Begin</h3><ol><li>Using a Web API</li></ol><p>A web API is a service designed to allow anyone interact with a program using specific URLs to request for specific or generic information. That request is what I’ve been calling an API call. The request would most often return data in formats such as JSON, CSV or XML.</p><h4>Requesting Data with an API Call</h4><p>We’ll base our demonstration on some weather data we’ll be retrieving from <a href="https://openweathermap.org/current">OpenWeatherMap</a> and we’ll be using this url to make the API call:</p><pre><a href="http://samples.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&amp;appid=b1b15e88fa797225412429c1c50c122a1">http://samples.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&amp;appid=b1b15e88fa797225412429c1c50c122a1</a></pre><p>It returns weather data (in JSON) for cities within the defined rectangle specified by the geographic coordinates. Taking a look at the data it returned, I think it’s weather data for cities in Libya. But we’ll figure as we go on.</p><h4>Install requests</h4><p><strong><em>requests</em></strong> is a module that allows you to easily query a url to a web resource and examine the response that is returned from the query.</p><pre>$ pip install requests</pre><p>Having issues installing? Go here: <a href="http://docs.python-requests.org/en/master/user/install/">Installing requests</a></p><pre><strong>import </strong>requests <strong>as </strong>rq<br><br># URL to OpenWeatherWap API<br>URL = &quot;http://samples.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&amp;appid=b1b15e88fa797225412429c1c50c122a1&quot;<br>r = rq.get(URL)  # make an API call to URL to retrieve data<br>response = r.json()  # Store the json-encoded content in the retrieved data<br>print(response.keys())  # Because response is a dictionary<br>print(response.values())<br>print(response)</pre><p>The last three lines in the code block above lets us know a little bit more about the content of the data we’ll be working with and how it’s structured. I always prefer to write them out in that order so I can see the keys, the values and then keys and values together.</p><p>To prettify the json data:</p><pre><strong>import </strong>requests <strong>as </strong>rq<br><strong>import </strong>json<br><br># URL to OpenWeatherWap API<br>URL = &quot;http://samples.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&amp;appid=b1b15e88fa797225412429c1c50c122a1&quot;<br>r = rq.get(URL)  # Make an API call to URL to retrieve data<br>response = r.json()  # Store the json-encoded content in the retrieved data<br># print(response.keys())  # Because response is a dictionary<br># print(response.values())<br># print(response)<br>print(json.dumps(response, indent=4))  # Prettify our print() output</pre><h4>Working with the response dictionary</h4><p>Now, let’s try count the number of cities represented in the data set.</p><pre>cities = []<br>[cities.append(city) <strong>for </strong>city <strong>in </strong>response[&quot;list&quot;]]<br>print(&quot;Number of cities represented: %s&quot; % (len(cities)))</pre><p>Time to add a face to our seemingly faceless data. This line of code does a good job:</p><pre>[print(format(&quot;%s:&quot; % (city[&quot;name&quot;]), &quot;&lt;14&quot;), city) <strong>for </strong>city <strong>in </strong>cities]</pre><p>Closely examining the first city, you’ll then see how we could work our way through retrieving the max and min temperature for a given city.</p><pre>city = cities[0]<br>print(city)  # Let&#39;s see from the print out, what keys we need<br>print(city[&quot;main&quot;])  # Contains temperature readings and that&#39;s what we need</pre><p>Using the knowledge of the result we get from the printout above, we can write a program to display the minimum and maximum temperature reading for all cities.</p><pre>cities = []<br>[cities.append(city) <strong>for </strong>city <strong>in </strong>response[&quot;list&quot;]]<br><br># Retrieve city names<br>city = []<br>[city.append(sity[&quot;name&quot;]) <strong>for </strong>sity <strong>in </strong>cities]<br><br>readings = []<br>[readings.append(sity[&quot;main&quot;]) <strong>for </strong>sity <strong>in </strong>cities]<br><br># Retrieve temperature readings<br>min_temp, max_temp = [], []<br><strong>for </strong>reading <strong>in </strong>readings:<br>    min_temp.append(reading[&quot;temp_min&quot;])<br>    max_temp.append(reading[&quot;temp_max&quot;])</pre><h4>Visualising with Pygal</h4><p>Install pygal.</p><pre>$ pip install pygal</pre><p>Pygal is a sexy graph-plotting module written in Python. It basically makes your life easy! No need for <a href="http://morrisjs.github.io/morris.js/">morris.js</a> and the likes.</p><p>Having issues installing? Go here: <a href="http://pygal.org/en/stable/installing.html">Installing Pygal</a></p><p>Next, we write our code to plot a bar chart. It shows the min and max temperature for each city</p><pre># Time to make some cool visualisation<br># Let&#39;s define some simple style so we added a pygal.style import<br>style = LS(&quot;#333666&quot;, base_style=DS)<br>bar_chart = pygal.Bar(style=style, x_label_rotation=45, show_legend=<strong>False</strong>)<br># To know more about what **kwargs you can use, read the Pygal documentation<br>bar_chart.title = &quot;Minimum and Maximum Temperatures for %s Cities&quot; % \<br>                  (len(cities))<br>bar_chart.x_labels = city<br>bar_chart.add(&quot;Minimum Temperature&quot;, min_temp)<br>bar_chart.add(&quot;Maximum Temperature&quot;, max_temp)<br>bar_chart.render_in_browser() # You can either view in browser<br># bar_chart.render_to_file(&quot;populationviz.svg&quot;)  # or view as an svg file<br># bar_chart.render_to_png(&quot;populationviz.png&quot;)  # or as a png file<br># Several other output options exists, check them out Pygal&#39;s documentation</pre><p>You can output your chart in several formats. <a href="http://pygal.org/en/stable/">See Pygal’s documentation</a>.</p><p>Your chart should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*lwVum1GxnT3MfqgYn9MCMA.png" /><figcaption>Browser Display of Cities and Associated Min and Max temperature Data</figcaption></figure><p>Having issues? Ensure your code looks like this:</p><pre><strong>import </strong>requests <strong>as </strong>rq<br><strong>import </strong>pygal<br><strong>from </strong>pygal.style <strong>import </strong>DefaultStyle <strong>as </strong>DS, LightenStyle <strong>as </strong>LS<br><br># URL to OpenWeatherWap API<br>URL = &quot;http://samples.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,&quot; \<br>      &quot;10&amp;appid=b1b15e88fa797225412429c1c50c122a1&quot;<br>r = rq.get(URL)  # make an API call to URL to retrieve data<br>response = r.json()  # Store the json-encoded content in the retrieved data<br><br>cities = []<br>[cities.append(city) <strong>for </strong>city <strong>in </strong>response[&quot;list&quot;]]<br><br># Retrieve city names<br>city = []<br>[city.append(sity[&quot;name&quot;]) <strong>for </strong>sity <strong>in </strong>cities]<br><br>readings = []<br>[readings.append(city[&quot;main&quot;]) <strong>for </strong>city <strong>in </strong>cities]<br><br># Retrieve temperature readings<br>min_temp, max_temp = [], []<br><strong>for </strong>reading <strong>in </strong>readings:<br>    min_temp.append(reading[&quot;temp_min&quot;])<br>    max_temp.append(reading[&quot;temp_max&quot;])<br><br># Time to make some cool visualisation<br># Let&#39;s define some simple style so we added a pygal.style import<br>style = LS(&quot;#333666&quot;, base_style=DS)<br>bar_chart = pygal.Bar(style=style, x_label_rotation=45, show_legend=<strong>False</strong>)<br># To know more about what **kwargs you can use, read the Pygal documentation<br>bar_chart.title = &quot;Minimum and Maximum Temperatures for %s Cities&quot; % \<br>                  (len(cities))<br>bar_chart.x_labels = city<br>bar_chart.add(&quot;Minimum Temperature&quot;, min_temp)<br>bar_chart.add(&quot;Maximum Temperature&quot;, max_temp)<br>bar_chart.render_in_browser()  # You can either view in browser<br>bar_chart.render_to_file(&quot;populationviz.svg&quot;)  # or view as an svg file<br># bar_chart.render_to_png(&quot;populationviz.png&quot;)  # or as a png file<br># Several other output options exists, check them out Pygal&#39;s documentation</pre><p>Sweet and cool. Pure python code!</p><p>Imagine the possibilities. Imagine the ease of integrating this into a Django or Flask project. Maybe to help an admin visualise product sales data for an online store, or make stunning pptx or HTML5 presentations at work or school or wherever.</p><p>Go ahead and try playing around the code, read up Pygal’s documentation, try restyling the chart. Maybe even try using a line chart, it also works great for weather data.</p><p>Thanks for the read.</p><p>Other great Python data visualisation libraries:</p><ul><li><a href="http://python-nvd3.readthedocs.io/en/latest/index.html">Nvd3</a></li><li><a href="https://github.com/altair-viz/altair">Altair</a></li><li><a href="https://matplotlib.org/">matplotlib</a></li><li>and many others</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c18c95331b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>