Μηνιαία αρχεία: Ιανουάριος 2018


Fedora Configure Hardware Acceleration for the Android Emulator 1

While setting up Android Studio on a Fedora 27 x64, we got the following message from the Android Studio Setup Wizard:

We have detected that your system can run the Android emulator in an accelerated performance mode.
Linux-based systems support virtual machine acceleration through the KVM (Kernel-mode Virtual Machine) software package.

Search for install instructions for your particular Linux configuration (Android KVM Linux Installation) that KVM is enabled for faster Android emulator performance.

After going through the website mentioned in the message we noticed that there were no instructions for Fedora so we decided to write our own.

Below are the steps we followed to enable hardware acceleration for the Android emulator.

Step 1: Verify that your CPU has virtualization extensions.

Execute the following in a terminal:


egrep '^flags.*(vmx|svm)' /proc/cpuinfo;

if you get ANY output then it would mean that your CPU supports either VMX or SVM which is good.
If it does not print anything then the emulator will fall back to software virtualization, which is extremely slow.

Step 2: Install the virtualization packages


sudo dnf group install --with-optional virtualization;

Step 3: Start the service


sudo systemctl start libvirtd;

Step 4: Automatically start the service on boot:


sudo systemctl enable libvirtd;

Step 5: Verify that the kvm kernel modules were loaded


lsmod | grep kvm

If the above command does not print kvm_intel or kvm_amd, it would mean that KVM is not properly configured.


Compiling openbts-umts on Ubuntu 15.04

Below are the steps we followed to compile OpenBTS-UMTS on Ubuntu 15.04.
There could be a chance that we installed a couple of extra system packages while troubleshooting the installation but it works and we did not include some heavy system service as well so it should be OK.


sudo apt-get install build-essential libuhd autoconf libtool libdevel libzmq-dev libzmq libzmq-dev libzmq-dev libosip2-dev libortp-dev libusb-dev libusb-1.0 libtool-bin libsqlite3-dev libboost-dev libreadline-dev;
git clone https://github.com/RangeNetworks/OpenBTS-UMTS;
cd OpenBTS-UMTS/;
git submodule init;
git submodule update;
#First we need to setup ASN1C compiler
tar -xf asn1c-0.9.23.tar.gz;
cd vlm-asn1c-0959ffb/;
./configure;
make;
make check;
sudo make install;
cd ..;
#Finally, we can proceed with compiling openbts-umts
./autogen.sh;
./configure;
make;
sudo make install;


Perform diff on two folders

To perform a recursive diff on all the files of two folders we just need to add the -r (or --recursive) parameter that recursively compares any subdirectories found.

To avoid needless messages from the tool, we can also use the -q (or --brief) parameter that reports only when files differ.

Example of performing diff on two folders recursively while preventing needless messages.


diff -rq aFolder someOtherFolder;


Count how many submissions per score

Recently, we had access to a database that contained the scores of a programming competitions system.
The database contained several contests, each contest contained several challenges and any competitor could make multiple submissions.
We wanted to extract a couple of charts showing

  • how many submissions we had per score and
  • how many submissions we had per score while filtering out the best submission (max score) per contestant per challenge per contest

The following code will return the number of submissions per score per challenge per contest.


SELECT contest_id, challenge_id, TRUNCATE(score, 1), COUNT(*)
FROM submissions
GROUP BY contest_id, challenge_id, TRUNCATE(score, 1)
ORDER BY contest_id, challenge_id, TRUNCATE(score, 1);

The next one will return the number of submissions per score per challenge per contest while filtering out the best submission (max score) per contestant per challenge per contest:


SELECT contest_id, challenge_id, TRUNCATE(max_score, 1), COUNT(*)
FROM
(
  SELECT contest_id, challenge_id, competitor_id, MAX(score) AS max_score
  FROM submissions
  GROUP BY contest_id, challenge_id, competitor_id
) AS max_scores
GROUP BY contest_id, challenge_id, TRUNCATE(max_score, 1)
ORDER BY contest_id, challenge_id, TRUNCATE(max_score, 1);