Wednesday, August 30, 2017

Difference between command substitution and 'while read' in bash

I just changed one of my scripts that, in principle, looked like this:
for i in `find . -type d`
do
     # do some processing on the found directory
done
The new format I use is:
find . -type d | while read i
do
    # do some processing on the found directory
done
While both versions will work in general, the second variant is better for the following reasons:
  1. It's faster. Namely, in the first case the find command has to finish before processing on directories starts. This isn't noticeable for small directory hierarchies, but it becomes very noticeable for large ones. In the second case the find command outputs results and in parallel while loop picks them up and does processing.
  2. In case you have spaces embedded in directory names, the second version will work, while the first won't.
Maybe there are some other advantages (or disadvantages) of the second version, but none I can remember at the moment. If you know any, please write it in the comments!

Tuesday, August 22, 2017

Viber and Fedora 26 SSL errors

I just downloaded and updated Viber on my Fedora. When I tied to start it, it seg faulted with the following errors:
QSqlDatabasePrivate::removeDatabase: connection 'ConfigureDBConnection' is still in use, all queries will cease to work.
Qt WebEngine ICU data not found at /opt/viber/resources. Trying parent directory...
Qt WebEngine resources not found at /opt/viber/resources. Trying parent directory...
Qt WebEngine ICU data not found at /opt/viber/resources. Trying parent directory...
Qt WebEngine resources not found at /opt/viber/resources. Trying parent directory...
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_num_locks
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_set_id_callback
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_set_locking_callback
qt.network.ssl: QSslSocket: cannot resolve ERR_free_strings
qt.network.ssl: QSslSocket: cannot resolve EVP_CIPHER_CTX_cleanup
qt.network.ssl: QSslSocket: cannot resolve EVP_CIPHER_CTX_init
qt.network.ssl: QSslSocket: cannot resolve sk_new_null
qt.network.ssl: QSslSocket: cannot resolve sk_push
qt.network.ssl: QSslSocket: cannot resolve sk_free
qt.network.ssl: QSslSocket: cannot resolve sk_num
qt.network.ssl: QSslSocket: cannot resolve sk_pop_free
qt.network.ssl: QSslSocket: cannot resolve sk_value
qt.network.ssl: QSslSocket: cannot resolve SSL_library_init
qt.network.ssl: QSslSocket: cannot resolve SSL_load_error_strings
qt.network.ssl: QSslSocket: cannot resolve SSL_get_ex_new_index
qt.network.ssl: QSslSocket: cannot resolve SSLv23_client_method
qt.network.ssl: QSslSocket: cannot resolve SSLv23_server_method
qt.network.ssl: QSslSocket: cannot resolve X509_STORE_CTX_get_chain
qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
qt.network.ssl: QSslSocket: cannot resolve SSLeay
qt.network.ssl: QSslSocket: cannot resolve SSLeay_version
qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_num_locks
qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function sk_num
Segmentation fault (core dumped)
After some digging the solution was simple, just execute the following command and it should work afterwards:
sudo ln -s /usr/lib64/libssl.so.10 /opt/viber/lib/libssl.so

Wednesday, July 19, 2017

When superstitious are good...

I just read the following paper:
Nunn, Nathan, and Raul Sanchez de la Sierra. Why Being Wrong can be Right: Magical Warfare Technologies and the Persistence of False Beliefs. No. w23207. National Bureau of Economic Research, 2017.
and I find it very interesting. Basically it is about why superstitions are good in certain cases. In this paper the author analyzes a case of a village in a Democratic Republic Congo. Namely, due to the unstable political situation there are lot of violence done  by different military groups that regularly attack villages. To protect themselves people in some villages believe they can be made resistant to bullets by strictly following a special magical procedure. It's obviously false but in case someone dies they prescribe the fault to not following this special magical procedure. This sounds crazy, but the effect is interesting. While it hurts individuals, it helps the collective since more people are willing to engage in defending villages with the end result of having 2 years of peace in this specific village that was brought as an example.

The key is that the utility of individual increases by everyone contributing to defense, but decreases when individual invests more. This, in effect, means that everyone will not invest the best he can and thus the collective will suffer! The superstition encourages everyone to give the best they can thus helping the collective. This is brilliant!

This result provokes some thinking as to whether some superstitions that I find annoying are actually beneficial, like religion for example. 

About Me

scientist, consultant, security specialist, networking guy, system administrator, philosopher ;)