<articleclass="post"><header><h1class="post-title"><ahref="blog/2016/4/2/blog-migrated/"class="u-url">How I migrated to a static blog</a></h1>
</header><div>
<spanclass="post-date">02 April 2016</span>
</div>
<br><divclass="e-content entry-content">
<div>
<p>Until one week ago my blog was hosted at my house, on a raspberrypi with debian + wordpress. I was not satisfied by my setup because given the minimal size of my blog and the really scarce content I post every now and then, a full LLMP stack was overblown.
I decided to change distribution (my server now runs <ahref="http://www.voidlinux.eu/">Void</a>) and to migrate to a static blog without CMS nor PHP.</p>
<h2>Welcome to Jekyll and Hyde</h2>
<p>The process of migration was rather painless.
First of all I installed ruby on my desktop computer, then via ruby gems I installed jekyll:</p>
<p><code>gem install jekyll</code></p>
<p><code>gem install jekyll-gist</code></p>
<p><code>gem install jekyll-paginate</code></p>
<p>I used a <ahref="https://wordpress.org/plugins/jekyll-exporter/">wordpress plugin</a> to copy all my old posts.
Then I cloned from <ahref="https://github.com/poole/hyde">git</a> the Hyde theme which you can see a demo <ahref="http://hyde.getpoole.com/">here</a> and corrected a pair of warning that jekyll printed on my terminal. Actually the <ahref="http://jekyllrb.com/docs">jekyll docs</a> are quite complete and covered all the errors that I encountered.</p>
<p>Jekyll structure is quite simple to understand: in the folder _post/ there are your post in markdown format (remember to delete the examples in that folder);
in the root the are some files that should be modified: the about.md file, the 404 page and index.html that is the frontpage of the blog;
finally _config.yml contains the general configuration for the website and should be adjusted to your own likings.
When Jekyll builds a website it parses all the markdown files and stores them in _site folder. Jekyll uses the html files in _layouts and _includes to render the markdown files.A</p>
<p>I added a simple <ahref="http://francescomecca.eu/archive/">archive page</a> following the little piece of code in <ahref="http://joshualande.com/jekyll-github-pages-poole/">this page</a>
{% raw %}
---
layout: page
title: Archive
---</p>
<preclass="code literal-block"><span></span><spanclass="x">## Blog Posts</span>
<p>so I proceed to remove it because is not needed for my blog.
Finally I put a link to the archive, my github page and the atom feed on the sidebar by simple adding a href on _includes/sidebar.html.</p>
<p>I did not proceed with further modifications but there are tons of possibilities with jekyll. I think that the main advantages are the fact that you don't have to manage html code when writing a new post and that everything can be done via cli.</p>
<p>Francesco Mecca</p>
</div>
</div>
</article><br><hr>
<br><articleclass="post"><header><h1class="post-title"><ahref="blog/2016/4/2/buridan_donkey/"class="u-url">The Buridan's donkey in python</a></h1>
</header><div>
<spanclass="post-date">02 April 2016</span>
</div>
<br><divclass="e-content entry-content">
<div>
<p>During the final weeks of my exam session I started reading a bit about python 3 using an excellent book: <ahref="http://www.diveintopython.net/">Dive into Python</a>.
When I noted that python uses the <ahref="https://en.wikipedia.org/wiki/Mersenne_Twister">Mersenne Twister PRNG</a> as well I decided to write another version of my <ahref="http://francescomecca.eu/index.php/archives/207">Buridan's donkey program</a>.</p>
<p>This script works in a different way than the one in c++.
Rather than shuffling a list made by the entries in the arguments, it pops randomly one entry from the list till the list is empty.</p>
<p>Not satisfied enough, I wrote also a telegram bot using the <ahref="https://github.com/eternnoir/pyTelegramBotAPI">telebot library</a> that works as the script above but inside the telegram app.
The bot can be added to your contact list by simply searching for <ahref="http://telegram.me/duridan_donkey_bot">@duridan_donkey_bot</a> (yes, a typo!)</p>
<p>All the code is opensource and can be found on my github page.</p>
The Buridan’s donkey is an illustration of a paradox regarding the philosophy of moral determinism and free will.
</p>
<pstyle="text-align: left;">
The paradox shows an hypothetical situation in which a donkey searching for food is caught in the middle of two equally appealing stacks of hay located at the same distance from the donkey. Because the donkey has no real reason to choose one over the other he dies of starvation.
</p>
<p><ahref="https://en.wikipedia.org/wiki/Buridan's_ass"><imgclass="aligncenter size-full wp-image-209"src="http://francescomecca.eu/wp-content/uploads/2015/09/Deliberations_of_Congress.jpg"alt="Deliberations_of_Congress"width="431"height="425"srcset="http://francescomecca.eu/wp-content/uploads/2015/09/Deliberations_of_Congress-300x296.jpg 300w, http://francescomecca.eu/wp-content/uploads/2015/09/Deliberations_of_Congress.jpg 431w"sizes="(max-width: 431px) 100vw, 431px"></a>I have decided to write a cli program that chooses for me when I can’t make up my mind.</p>
<p>The program is written in C++ and when invoked along with two or more arguments it puts them in a vector and then changes the order randomly.</p>
<p>I have used the <ahref="http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine"target="_blank">Mersenne Twister PRNG</a> just to give it a try.</p>
<pstyle="text-align: left;">
One of the challenges was to read from stdin instead of arguments when the program is piped after another program in the shell:
<p>So I have used poll() that checks for a specified amount of time if the selected device (/dev/stdin in my case) can perform I/O operations; in my code:</p>
<p>I selected the POLLIN as event so poll() only checks if there is data to read, 1 as the number of items in the fds array, 0 milliseconds of timeout because when the program is invoked /dev/stdin may already contain input.</p>
<p>You are free to reuse this little piece of code as you wish.</p>
<p>EDIT: 02-04-2016
The original idea for the Buridan's donkey came from my mentor <ahref="https://twitter.com/bassosimone">Simone Basso</a> who wrote the original one in haskell.</p>