I think ... - codinghttps://blog.kmonsoor.com/2018-07-07T00:00:00+06:00Install latest Python 3 on Linux CentOS 72018-07-07T00:00:00+06:002018-07-07T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2018-07-07:/install-latest-python3-on-centos-7/<p>Install the latest and greatest Python 3 on CentOS 7&nbsp;systems</p><h2 id="why">Why<a class="headerlink" href="#why" title="Permanent link">&para;</a></h2> <p>Not all distro created equal. <br> Some are created to join the space race, some are to hold unto the leagcy, some are cutting-edge, some are cutting edge. Some are born to boot-up IoT devices some are to push out heavy&nbsp;graphics.</p> <p>That&rsquo;s the fun (albeit, power) of&nbsp;Linux.</p> <p><img alt="CentOS 7 logo" class="noZoom" src="https://i.imgur.com/6ZFCdoM.jpg"></p> <p>CentOS 7 is a powerful and stable distro that runs on thousands (probably, millions) production-grade servers.<br> In the matter of stability, it&rsquo;s a beast. However, it doesn&rsquo;t ship with Python 3, by default. You can install it via <span class="caps">EPEL</span> repository, or the below simple&nbsp;steps.</p> <p>Also, take a note. The Python <strong>2</strong> comes with the system, which is probably 2.7.5, do <strong><span class="caps">NOT</span></strong> mess with it. Many system components rely on that specific version. If you need the latest versions of 2, use <code>virtualenv</code> or <code>pipenv</code>.</p> <h3 id="prepare-your-system">Prepare your system<a class="headerlink" href="#prepare-your-system" title="Permanent link">&para;</a></h3> <p>Start with installing pre-requisite utilities for compilation and development&nbsp;support.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ sudo yum update <span class="o">&amp;&amp;</span> sudo yum groupinstall -y <span class="s2">&quot;development tools&quot;</span> <span class="linenos" data-linenos="2 "></span>$ sudo yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel <span class="se">\</span> <span class="linenos" data-linenos="3 "></span> sqlite-devel readline-devel tk-devel gdbm-devel <span class="se">\</span> <span class="linenos" data-linenos="4 "></span> db4-devel libpcap-devel xz-devel expat-devel </code></pre></div> <h3 id="download-latest-python-source-code-from-pythonorg">Download latest Python source code from Python.org<a class="headerlink" href="#download-latest-python-source-code-from-pythonorg" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz <span class="linenos" data-linenos="2 "></span>$ tar xf Python-3.6.6.tar.xz <span class="linenos" data-linenos="3 "></span>$ <span class="nb">cd</span> Python-3.6.6 </code></pre></div> <h3 id="enable-performance-optimizations-optional-but-highly-recommended">Enable performance optimizations (optional, but highly recommended)<a class="headerlink" href="#enable-performance-optimizations-optional-but-highly-recommended" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ ./configure --prefix<span class="o">=</span>/usr/local --enable-shared <span class="nv">LDFLAGS</span><span class="o">=</span><span class="s2">&quot;-Wl,-rpath /usr/local/lib&quot;</span> <span class="linenos" data-linenos="2 "></span>$ ./configure --enable-optimizations </code></pre></div> <h3 id="build-and-install">Build and install<a class="headerlink" href="#build-and-install" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ make <span class="linenos" data-linenos="2 "></span>$ sudo make altinstall </code></pre></div> <p>Now, Python 3.6.6 is ready to be used in your system; located in <code>/usr/local/bin/python3.6</code> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ which python3.6 <span class="linenos" data-linenos="2 "></span>/usr/local/bin/python3.6 <span class="linenos" data-linenos="3 "></span> <span class="linenos" data-linenos="4 "></span>$ python3.6 <span class="linenos" data-linenos="5 "></span>Python <span class="m">3</span>.6.6 <span class="o">(</span>default, Jul <span class="m">10</span> <span class="m">2018</span>, <span class="m">14</span>:04:26<span class="o">)</span> <span class="linenos" data-linenos="6 "></span><span class="o">[</span>GCC <span class="m">4</span>.8.5 <span class="m">20150623</span> <span class="o">(</span>Red Hat <span class="m">4</span>.8.5-28<span class="o">)]</span> on linux <span class="linenos" data-linenos="7 "></span>Type <span class="s2">&quot;help&quot;</span>, <span class="s2">&quot;copyright&quot;</span>, <span class="s2">&quot;credits&quot;</span> or <span class="s2">&quot;license&quot;</span> <span class="k">for</span> more information. <span class="linenos" data-linenos="8 "></span>&gt;&gt;&gt; </code></pre></div></p> <p>For convenience, you can create a symbolic-link with a shorter name. If you had system-installed Python3 (unlikely), <strong>don&rsquo;t</strong> do this, as some system-components may depend on that specific older version of Python 3. <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ sudo ln -s /usr/local/bin/python3.6 /usr/local/bin/python3 <span class="linenos" data-linenos="2 "></span>$ python3 <span class="linenos" data-linenos="3 "></span>Python <span class="m">3</span>.6.6 <span class="o">(</span>default, Jul <span class="m">10</span> <span class="m">2018</span>, <span class="m">14</span>:04:26<span class="o">)</span> <span class="linenos" data-linenos="4 "></span><span class="o">[</span>GCC <span class="m">4</span>.8.5 <span class="m">20150623</span> <span class="o">(</span>Red Hat <span class="m">4</span>.8.5-28<span class="o">)]</span> on linux <span class="linenos" data-linenos="5 "></span>Type <span class="s2">&quot;help&quot;</span>, <span class="s2">&quot;copyright&quot;</span>, <span class="s2">&quot;credits&quot;</span> or <span class="s2">&quot;license&quot;</span> <span class="k">for</span> more information. <span class="linenos" data-linenos="6 "></span>&gt;&gt;&gt; </code></pre></div></p> <h2 id="install-wheel-and-pip"><del>Install wheel and pip</del><a class="headerlink" href="#install-wheel-and-pip" title="Permanent link">&para;</a></h2> <p>You don&rsquo;t need to, because <code>Python 3.6.6</code> includes these necessary tools included. <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>$ pip3.6 -V <span class="linenos" data-linenos="2 "></span>pip <span class="m">10</span>.0.1 from /usr/local/lib/python3.6/site-packages/pip <span class="o">(</span>python <span class="m">3</span>.6<span class="o">)</span> <span class="linenos" data-linenos="3 "></span>$ wheel version <span class="linenos" data-linenos="4 "></span>wheel <span class="m">0</span>.29.0 </code></pre></div></p>R vs Python — A Summary Comparison2016-02-08T08:02:00+06:002016-02-08T08:02:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2016-02-08:/R-vs-Python/<p>A tabular, objective, comparative summary view between R and Python programming languages. Facts&nbsp;matters.</p><table> <thead> <tr> <th>..</th> <th>R</th> <th>Python</th> </tr> </thead> <tbody> <tr> <td>Home</td> <td><a href="http://r-project.org">http://r-project.org</a></td> <td><a href="http://python.org">http://python.org</a></td> </tr> <tr> <td><a href="http://githut.info/">Birth</a></td> <td>1993</td> <td>1991</td> </tr> <tr> <td>Designer</td> <td>Ross Ihaka, Robert Gentleman</td> <td>Guido van Rossum</td> </tr> <tr> <td>Package count</td> <td>7,798 (<span class="caps">CRAN</span>)</td> <td>73,402 (PyPI)</td> </tr> <tr> <td>Purpose</td> <td>statistical computing</td> <td>General purpose</td> </tr> <tr> <td>Paradigm</td> <td>array, object-oriented, imperative, functional, procedural, reflective</td> <td>object-oriented, imperative, functional, procedural, reflective</td> </tr> <tr> <td>License</td> <td><span class="caps">GPL</span></td> <td><span class="caps">MIT</span></td> </tr> <tr> <td>Platform</td> <td>cross-platform</td> <td>cross-platform</td> </tr> <tr> <td>Implementations</td> <td>Main, <a href="https://github.com/bedatadriven/renjin">Rejnin</a>, <a href="https://bitbucket.org/allr/fastr">FastR</a></td> <td><a href="https://github.com/python/cpython">cPython</a>, <a href="https://bitbucket.org/pypy/pypy">PyPy</a>, <a href="http://www.jython.org">Jython</a>, <a href="https://github.com/IronLanguages/main/wiki">IronPython</a></td> </tr> <tr> <td><a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html"><span class="caps">TIOBE</span><sup><span class="caps">TM</span></sup> index</a></td> <td>19</td> <td>5</td> </tr> <tr> <td>Dev. <span class="caps">IDE</span></td> <td>R Studio, Tinn-R, Architect</td> <td>PyCharm, IPython/Jupyter, Spyder, Komodo <span class="caps">IDE</span></td> </tr> <tr> <td>Graphics support</td> <td>built-in, ggplot2, lattice, Vistat, googleVis</td> <td>matplotlib, Seaborn, Plotly, Bokeh</td> </tr> <tr> <td>Machine-learning</td> <td>e1071, rpart, igraph, nnet, kernlab, caret</td> <td>scikit-learn, PyML, PyMC, Shogun</td> </tr> <tr> <td>Deep-Learning</td> <td>H<sub>2</sub>O, Darch</td> <td>TensorFlow, Theano, Decaf, <span class="caps">PDNN</span>, Keras, Caffe</td> </tr> <tr> <td>Image-Analysis</td> <td>Raster, EBImage, imager</td> <td>scikit-image, OpenCV, scipy.ndimage</td> </tr> <tr> <td><a href="http://githut.info/">Github project count</a></td> <td>34,268</td> <td>164,852</td> </tr> <tr> <td>Latest release</td> <td>2015-12-10 (Main: R-3.2.3)</td> <td>2015-12-21 (cPython: Python 3.4.4)</td> </tr> </tbody> </table> <p><strong><span class="caps">N.B.</span></strong> * Time-dependent data are up-to-date as of: <strong>2016-02-08</strong>&nbsp;* </p> <p>&hellip;</p>Open Source as-if You Gonna Die Tonight2015-12-22T00:00:00+06:002015-12-23T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2015-12-22:/open-source-as-if-you-gonna-die-tonight/<p>You should open-source as-if you gonna die tonight.&nbsp;Literally.</p><p><strong><em>[ To keep the spirit of this post honest, I am going to publish this blog, immidiately. No <strong>draft</strong>-ing. This post will be, I hope, under continuous improvement.<br> This post is <a href="https://github.com/kmonsoor/blog.kmonsoor.com/edit/live/content/articles/open-your-source-as-if-you-gonna-die-tonight.md">available for edit on GitHub</a>, currently in its version 0.0.6&nbsp;]</em></strong></p> <p><strong>Yes, I mean it.&nbsp;Literally.</strong></p> <p>I see too many post/comments/blogs, in different meeting-places for techies e.g. hackernews, reddit, etc., which say the same&nbsp;thing: </p> <blockquote> <p><span class="dquo">&ldquo;</span>I am working on <strong><em>something</em></strong> which I will open-source/publish <strong><em>someday</em></strong> after taking it <strong><em>somewhere</em></strong>.&rdquo;</p> </blockquote> <p>See the ambiguous sense in the&nbsp;words? </p> <p>Unless the code/script/blog you are working on is something sensitive which will make a mess published a &ldquo;draft&rdquo; form, you should not wait for &ldquo;someday&rdquo;. Or if you have thousands of subscribers to your blog&nbsp;;)</p> <p>Or if you decided that you will <strong><em>never</em></strong> publish it in public - that&rsquo;s an entirely different&nbsp;story.</p> <p>If it is something of your company&rsquo;s code-base, commit it in your remote branch, so that your last 19 days of work isn&rsquo;t just gone just because you are&nbsp;&ldquo;gone&rdquo;.</p> <p><strong>As human, we are far more fragile than we&nbsp;think.</strong></p> <p>I am not talking about publishing a physical book using a printing press. In that scenario, writers were supposed to write the perfect words, then type it using type-writer to avoid any handwriting-related gotchas. Then it went to the reviewer, then proofreader, then the typesetter makes a block character-by-character. Then comes printing on the paper. The writer had to be sure what he is writing about, <span class="caps">ABSOLUTELY</span>. Else, each of the <em>2000</em> copies of the <em>first-edition</em> would have the same&nbsp;mistakes.</p> <p>I am also not talking about pushing the critical code in the <code>production</code> server. That stuff should go through rigorous coding practices, code-reviews, testing&nbsp;etc.</p> <p>Aside from those cases, <strong>this is 2015</strong> - How much does each <code>git push origin gh-pages</code> cost? How much each WordPress post update cost? Or, a single GitHub&nbsp;gist?</p> <p>Publishing your stuff is free, no matter how many times you update&nbsp;it.</p> <p><strong>So, why do we think about the paradigm of the printing press when we think of&nbsp;&ldquo;publishing&rdquo;?</strong></p> <h2 id="frequently-shared-confusions-fsq">Frequently shared confusions (<span class="caps">FSQ</span>)<a class="headerlink" href="#frequently-shared-confusions-fsq" title="Permanent link">&para;</a></h2> <ul> <li> <p><strong>What if this, my thing, is just plain crap ?</strong><br> <strong>A.</strong> Are you sure? You never know for sure. Throw it in the wild. If it is really crap, nobody will remember or hold you responsible for it. How many crappy DaVinci paintings you know? I guess, <strong><em>none.</em></strong> But the <a href="https://en.wikipedia.org/wiki/Mona_Lisa">Mona Lisa</a> didn&rsquo;t just appear from thin air. Did&nbsp;it?</p> </li> <li> <p><strong>This is my toy(or pet) project.</strong><br> <strong>A.</strong> Don&rsquo;t be that selfish kid from the school who don&rsquo;t let others touch it just because. If you are having fun building something why not let others join in the&nbsp;fun?</p> </li> <li> <p><strong>This is a one-off script on this ancient <em><span class="caps">COBOL</span></em> platform, no one is going to need it. Ever.</strong><br> <strong>A.</strong> You never know. You are a human. You can&rsquo;t imagine what people gonna need. Throw it in a <a href="https://gist.github.com/">gist</a>, just include a suitable title. Add in some comments if you please. May be couple of years later, your script will save someone&rsquo;s job, and he can still put food on the table. You never&nbsp;know. </p> </li> <li> <p><strong>If I publish this now some genius with free time will steal my idea and make it something grand without me.</strong><br> <strong>A.</strong> Unless you are a big hot-shot with a ground-breaking idea, no one will even notice it. Most <em>genius&rsquo;</em> mind is already filled with their own to-do list. Even if they take your idea, let them. Move on. Don&rsquo;t be a muddy pond, rather be like a river. Rivers don&rsquo;t dry off due to peasants &ldquo;stealing&rdquo; some&nbsp;water. </p> </li> <li> <p><strong>I haven&rsquo;t collected my thoughts enough to make this post a grand one yet.</strong><br> <strong>A.</strong> Don&rsquo;t think too high yourself. Let others do that for you.<br> No project is born grand, and no great man born great. Your contributions is what goes ahead. You the person? Not so much. Time passed along &ldquo;Romeo <span class="amp">&amp;</span> Juliet&rdquo;, but Shakespeare is dead and&nbsp;gone. </p> </li> <li> <p><strong>I am special. My words/code should be special, perfect, coherent like a pearl-necklace.</strong> <em>(yes, we all feel like that, we just don&rsquo;t acknowledge it publicly.)</em><br> <strong>A.</strong> No, you are not. You are not a special unique snowflake. See the previous&nbsp;answer.</p> </li> <li> <p><strong>Who the ***k are you to tell me what to do?</strong><br> <strong>A.</strong> It&rsquo;s not about me, I am nobody. Just a open-source enthusiast who wants to see more and more open-source projects, scripts, blog-posts which haven&rsquo;t gone to grave with their mortal creators. I&rsquo;m just sharing my own thoughts about it. <strong>It is your code on your own personal-pc, after&nbsp;all.</strong></p> </li> </ul> <h2 id="why-should-i-open-my-sourcepostthoughtsetc-tonight">Why should I open my source(post/thoughts/etc) tonight?<a class="headerlink" href="#why-should-i-open-my-sourcepostthoughtsetc-tonight" title="Permanent link">&para;</a></h2> <ul> <li> <p>You can literally die tonight. Then all of your pet-projects are just gone. &lsquo;Cause probably none in your family is in coding business or they aren&rsquo;t sure about your&nbsp;intention. </p> </li> <li> <p>Tomorrow morning, your mind will just drift-away.<br> What is a vivid idea tonight that could impact thousands of people&rsquo;s lives, tomorrow morning will become a faded, will-do-it-someday idea. One month after tonight, you probably will probably be oblivious about your own idea, draft, script,&nbsp;code.</p> </li> <li> <p>It&rsquo;s a mind-trick to force ourselves to work on something to avoid public shame. We feel obliged to correct errata that is in public, but something hidden away in a private, hidden, local folder we don&rsquo;t have to feel bad&nbsp;about. </p> </li> </ul> <h2 id="to-avoid-embarrassment">To avoid embarrassment<a class="headerlink" href="#to-avoid-embarrassment" title="Permanent link">&para;</a></h2> <ul> <li> <p>Make sure your audience (or colleagues for that matter) know the content&rsquo;s status. Put a &ldquo;prelude&rdquo; section mentioning the half-done condition. Better yet, use some <a href="http://semver.org/">version number</a>.</p> </li> <li> <p>Make your genereal idea clear. For code, point out what it is and what it is supposed to do. For a blog, present the basic idea at least, even if it is not with perfect&nbsp;grammer.</p> </li> </ul> <h2 id="how-infrastructure-can-improve">How infrastructure can improve<a class="headerlink" href="#how-infrastructure-can-improve" title="Permanent link">&para;</a></h2> <p>Open-source mainstream hosting platforms e.g. Github, Bitbucket, GitLab etc. could have a <strong>&ldquo;Open the source&rdquo;</strong> trigger-switch for individual projects where a software developer can enable the trigger with some condition&nbsp;like:</p> <ul> <li><span class="dquo">&ldquo;</span><strong>Open the source</strong>&rdquo; if I don&rsquo;t login GitHub for <code>1 year</code> (which means I am dead or I&rsquo;ve gone crazy trying to remember&nbsp;GitHub)</li> <li><span class="dquo">&ldquo;</span><strong>Open the source</strong>&rdquo; on a pre-set date e.g. <code>2020-02-20</code></li> </ul> <p><em>[dear reader, thanks a lot for reading up to here. I am sure there are many points missing on this post. Also, as English is not my first language, hence there must some misused words or phrase. But you get the idea. Please comment/criticise/point out the missing stuff. I will try to discuss, update, correct&nbsp;that.]</em></p> <hr> <h2 id="contributors">Contributors<a class="headerlink" href="#contributors" title="Permanent link">&para;</a></h2> <table> <thead> <tr> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td><a href="https://github.com/kmonsoor">Khaled Monsoor</a></td> <td>initial author, maintainer</td> </tr> <tr> <td><a href="https://github.com/waynew">Wayne Werner</a></td> <td>editor (v.0.0.3 &rarr; v.0.0.4)</td> </tr> </tbody> </table> <h2 id="some-related-inspirations-from-some-open-source-jedis">Some related inspirations from some open-source jedis<a class="headerlink" href="#some-related-inspirations-from-some-open-source-jedis" title="Permanent link">&para;</a></h2> <ul> <li><a href="https://rhettinger.wordpress.com/2011/01/28/open-your-source-more/">Raymond Hettinger :: Open Source Challenge: Open Your Source,&nbsp;More</a></li> <li><a href="https://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/">Jeff Knupp :: Open Sourcing a Python Project the Right&nbsp;Way</a></li> <li><a href="https://archive.org/stream/GuerillaOpenAccessManifesto/Goamjuly2008_djvu.txt">Aaron Swartz :: Guerilla Open Access&nbsp;Manifesto</a></li> </ul>Python - How to Create All Possible Combinations (a.k.a Permutations)2014-01-31T00:00:00+06:002014-01-31T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2014-01-31:/python-how-to-generate-all-possible-combinations-or-permutations/<p>Let&rsquo;s say we have a string, or number. And, we want to generate all the combinations of all the characters of the string or the&nbsp;number</p><p>Let&rsquo;s say the number is&nbsp;123.</p> <p>Then the statement: <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">permutations</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="mi">123</span><span class="p">)))]</span> </code></pre></div> will create a sorted list of all possible numbers using &lsquo;1&rsquo;,&lsquo;2&rsquo; and &lsquo;3&rsquo;. which is, [123, 132, 213, 231, 312,&nbsp;321]</p> <h3 id="what-it-is-doing">What it is doing<a class="headerlink" href="#what-it-is-doing" title="Permanent link">&para;</a></h3> <p>The part, <code>permutations(list(str('123'</code> is creating a <a href="https://en.wikipedia.org/wiki/Permutation">permutated</a> <a href="https://en.wikipedia.org/wiki/Tuple">tuples&rsquo;</a> list of splitted string &lsquo;123&rsquo;. And the <code>int(''.join(x))</code> is converting each tuple to&nbsp;Integer.</p> <p>However, of course, you need to <code>import permutations from itertools</code>.</p> <p>so, the generalized version would&nbsp;be:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">permutations</span> <span class="linenos" data-linenos="2 "></span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">permutations</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))))]</span> </code></pre></div> <p>Python is fun. Isn&rsquo;t&nbsp;it?</p>