Caught in the Net

The Buridan’s donkey paradox

The Buridan’s donkey is an illustration of a paradox regarding the philosophy of moral determinism and free will.

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.

Deliberations_of_CongressI have decided to write a cli program that chooses for me when I can’t make up my mind.

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.

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <sys/poll.h>
using namespace std;

struct pollfd stdin_poll = {
    .fd = fileno (stdin), .events = POLLIN
};

void read_from_piped_input (vector<string>& lst)
{
    string x;
    while (getline (cin, x)) {
        lst.push_back (x);
    }
}

void read_from_arguments (const int& argc, char* argv[], vector<string>& lst)
{
    if (argc  == 1) {
        cout << "Usage: asino [string] [string] ..." << endl;
        exit;
    }
    for (vector<string>::size_type i = 1; i < argc; ++i) {
        lst.push_back (argv[i]);
    }
}

int main (int argc, char* argv[])
{
    vector<string> lst;
    int poll_ret = poll (&stdin_poll, 1, 0);
    if (poll_ret > 0) {
        read_from_piped_input (lst);
    }
    else {
    read_from_arguments (argc, argv, lst);
    }

    random_device rd;
    mt19937 m(rd());
    shuffle (lst.begin (), lst.end (), m);
    
    int i = 1;
    for (vector<string>::iterator it = lst.begin (); it != lst.end (); ++it) {
        cout << i++ << ". " << *it << endl;
    }
}

I have used the Mersenne Twister PRNG just to give it a try.

One of the challenges was to read from stdin instead of arguments when the program is piped after another program in the shell:

ls /media/my_movies/ | buridan

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:

poll (&stdin_poll, 1, 0)

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.

The program should be compiled this way:

g++ -std=c++11 ./program.cpp -o output

You are free to reuse this little piece of code as you wish.

EDIT: 02-04-2016 The original idea for the Buridan's donkey came from my mentor Simone Basso who wrote the original one in haskell.

Francesco Mecca

About Perl packages in Gentoo

In this post I wish to explain a bit about Perl related ebuilds in Gentoo and how to update from perl-core to virtual/perl without conflicts.

First of all the core distribution of Perl is included in dev-lang/Perl along with modules.

The perl-core category in portage contains ebuilds for perl modules, some of which are included in the core perl distibution. The perl-core ebuilds overrides the perl-core modules such that you can update them without recompiling dev-lang/Perl.

Each perl-core module has a corrensponding virtual/perl-* package. The virtual category is used by portage when emerging to take into account that a module can be either provided by dev-lang/perl package or found in perl-core category.

So, what to do in case of blocks when upgrading your Gentoo machine?

Perl-cleaner is a package provided to get rid of these blocks and to migrate from perl-core to virtual/perl-*.

emerge perl-cleaner
emerge dev-lang/perl
perl-cleaner --all

if you still have problems when upgrading @world you add a backtrack option

emerge -uDN --backtrack=30 @world

or you can unmerge all perl-core packages and then finally upgrade world

emerge --unmerge perl-core/*

This will remove all perl-core packages that virtual/perl-* packages will bring back if needed.

Francesco Mecca

56 secondi di celebrita`

Dura 56 secondi il video di Vester Lee Flanagan che testimonia l’omicidio in prima persona di due giornalisti in Virginia durante un live broadcast televisivo. Durante l’inseguimento nel quale si e` tolto la vita Flanagan ha caricato su Twitter e Facebook il video dell’uccisione in prima persona.

Twitter e Facebook hanno tempestivamente censurato il video e rimosso l’account dell’omicida ed alcune emittenti televisive (come SkyTg24) hanno scelto allo stesso modo di non pubblicare il video in diretta.

To publish or not to publish?

E` quindi una decisione giusta quella di non pubblicare il video?

Steve Buttry sul suo blog si esprime in questo modo:

1) Someone who attacks during a live telecast is seeking attention. Obviously you need to report the attack, but I would not broadcast the attack or make it available online.

[…]

4) I see no ethical justification for publishing videos shot by the killer. That is the ultimate in attention-seeking behavior.

5) You can report the mental health issues, gun access issues and other issues that a story presents without publicizing or profiling the killer.

6) My focus would be on the people who were killed or injured. They warrant media attention, not the person who was seeking it.

1)Una persona che attacca durante una trasmissione in diretta e` alla ricerca di attenzione. Naturalmente si deve rendere noto l’atto, ma io non lo trasmetterei ne lo pubblicherei online.

[…]

4) Non vedo giustificazioni etiche per pubblicare il video: e` l’esempio piu` eclatante di ricerca di attenzioni.

5) Puoi discutere sui problemi mentali, la questione relativa al facile accesso alle armi e tutti gli altri problemi di questa storia senza mostrare o pubblicizzare il killer.

6) Io mi concentrerei sulle persone ferite o uccise. Loro meritano l’attenzione dei media, non la persona che la cercava.

Famoso in un istante

E` ovvio che Flanagan stesse cercando i suoi 15 minuti di fama con questo atto, ma a mio parere non ci sarebbe riuscito se non sfruttando nuovi strumenti quali lo smartphone e i social network. Molto difficilmente sarebbe riuscito 20 anni fa utilizzando i media tradizionali a filmarsi in prima persona in una situazione del genere e a rendere cosi` tante persone testimoni del suo gesto.

Per questo non mi trovo d’accordo con Steve Buttry che afferma che il video non andrebbe reso disponibile online. i nuovi media hanno un ruolo diverso nella condivisione dei contenuti e soprattutto nel mantenimento della memoria storica. Un video del genere non aggiunge alcun valore investigativo o giornalistico al caso ma puo` ritenersi utile per analisi differenti, in primis psicologiche, ed ha sicuramente un valore storico (da quanto conosco e` il primo video in prima persona di un omicidio con queste dinamiche).

Lo specchio nero

Chi come me e` un grande fan della serie TV Black Mirror avra` sicuramente ricordato il primo episodio della serie: National Anthem.

Questo episodio e` un’analisi sottile e dettagliata della natura umana, che di fronte ad eventi che suscitano un cosi` grande clamore sospendono ogni giudizio morale e dimenticano il motivo per cui si trovano a guardare cio` che hanno di fronte.

Allo stesso modo trovo miserevole poter assistere a giornalisti ed emittenti televisive che per attirare spettatori nelle proprie reti mostrano il video integrale.

Come in National Anthem chi ha perpetrato il crimine non ci ha costretto ad essere complici del suo gesto.

Francesco Mecca

Addio Blogspot

Ho deciso di abbandonare Blogspot per le stesse ragioni per cui ho smesso di utilizzare i servizi Google due anni fa: privacy e controllo.

Ora il blog e` disponibile a questo indirizzo ed e` fisicamente sul mio Raspberry PI che utilizza Raspbian + WordPress.

 

 

 

A pochi metri da Stallman

Il 25 giugno sono stato alla presentazione del master di primo livello in “Management del Software Libero”, che si e` tenuto nella sala della palazzo della Regione Piemonte. 


Non mento dicendo che a questo incontro ci sono andato principalmente per ascoltare il professor Angelo Meo (che ha aiutato a curare parte del programma del master) e Richard Stallman

foto originale distribuita in CC-by-nd-nc

 Il master, ha spiegato Meo, si occupa di fornire le competenze necessarie per permettere un’analisi precisa costi / benefici nel momento della transizione verso il free software all’interno di un’azienda, transizione che deve essere priva di attriti e semplice per i dipendenti.

Per questo si compie un percorso di studi che tratta gli aspetti giuridici ed economici, oltre che tecnologici.

Infine Meo ha ricordato di come Internet sia tanto madre quanto figlia del software libero e ci ha brevemente ricordato di come Torino ha risparmiato 6 milioni di euro.

Il keynote di Stallman invece e` stato una piacevole introduzione al software libero per i neofiti, in particolare: 

  •  Microsoft, Apple e i DRM
  •  4 liberta` fondamentali del software libero; 
  •  open source != FOSS;
  •  limiti del software proprietario per l’utente finale.
Saint IGNUcius della chiesa di Emacs, foto originale

Sono state indimenticabili le espressioni dei 2 relatori quando Stallman ha indossato la veste di Saint IGNUcius e quando ha aperto l’asta per un peluche di gnu, mascotte della FSF. 

Francesco Mecca