Wednesday, November 19, 2014

"Learn IT, Girl!" mentorship program just started!

This week is official beginning of "Learn IT, Girl!" program [1]. It's international program for woman, started by a few girls from Poland and Romania, invented at the Google Anita Borg Scholarship [2] retreat in 2014. A main aim is to learn by women particular programming language. Every scholar is guided by her own mentor, who helps her. Girls learn language by doing selected earlier project (which must be open-source project ofc).

I take a part in this program as a mentor, and my my mentee is Corina Teodorescu. She's from Romania and studies Marketing. Corina has decided to learn C#, and she's going to write an mobile app for phones with Android OS. Because of a lot really great ideas, she doesn't finally choose her project. She's choosing between RSS reader and application for downloading/uploading/hash-tagging images - she didn't make a decision, but I think, both are quite useful, and Corina can learn a lot by making one of them(what's the most important during this program :)

Program takes 3 months, and I believe, that would be great time for Corina and for me as well. I hope, Corina will learn a lot, and I'm going to improve my teaching skills too. We will have fun for sure :)

 Wish me and Corina luck!

Learn IT, Girl!


Links
[1] https://sites.google.com/site/learnitgirl/
[2] http://www.google.com/anitaborg/

Tuesday, November 4, 2014

Simple macro for measuring algorithm's running time

Recently I'm spending a lot of time on my master's thesis. I'm working on algorithm for automatic number plates recognition using image segmentation. I'm trying to achieve high performance, so I need to measure execution time of my algorithms.
A few weeks ago I've written about google benchmark [1]. It's quite powerful library, and it's easy to use even in simple case, but sometimes we don't want to depend on an external library. So is it in my case too.
I've created simple macro for measuring running time:
#include <chrono>

#define MEASURE_TIME(unit, ...)    \
  [&] {         \
    using namespace std::chrono;     \
    auto start = high_resolution_clock::now ();    \
    __VA_ARGS__;       \
    auto time = high_resolution_clock::now () - start;   \
    return duration_cast<unit> (time).count ();    \
  } ();


Arguments:
  • unit - std::chrono::duration time interval. You can simply pass defined in standard library types, e.g. predefined types:
    • std::chrono::nanoseconds
    • std::chrono::microseconds
    • std::chrono::milliseconds
    • std::chrono::seconds
    • std::chrono::minutes
    • std::chrono::hours
  • ... - code for measurement
And example usage:
  int value = 0;

  auto duration = MEASURE_TIME(std::chrono::milliseconds, 
    int arg0, arg1;
    arg0 = run_time_consuming_algorithm ();
    arg1 = run_another_one(arg0);
    value = run_third_algorithm(arg1);
  );

  cout << "Execution time: " << duration << std::endl
       << "Computed value: " << value;

Note, that you can use earlier declared values (value variable, in my case), because all the values are captured by reference in lambda.

Feel free to use it ;)

Links
[1] http://cookandcommit.blogspot.com/2014/09/tiny-c-benchmark-framework_29.html 

Wednesday, October 29, 2014

Useful (to me) post-commit hook script for checking commit message

A lot of projects are managed using bug-tracking tool (e.g. JIRA [1], Bugzilla [2], Redmine [3]), and most commits refer to a specified ticket. It's good to enter ticket number in a commit message - it allows other developers find a bug report, read more about a problem, which concern a commit.
I don't know about you, but I often forget about put it in a commit message. So I've prepared simple script, which reminds me about enter ticket message in a message. I'm using this script as a post-commit hook both at work and in my private projects.
I've pushed it to my github repository [4] (I've added also simple instruction - you can find it in a README.md file). Feel free to use and improve it (I'm not a bash and git expert) - patches are welcome ;)

REPO_REGEX parameter

Some of my friends have asked me about REPO_REGEX parameter. So let me clarify; e.g. at work I'm using mostly company's repositories, where should I enter ticket number. But I've got also a few open source repositories, where I don't need to (sometimes even I can't, because it doesn't strongly connected with bug-reporting service) pass this number. To make my life easier, I've added this script as a global. REPO_REGEX allows me define company repositories pattern, so I don't see warning message during committing to a non-company repositories.

Links
[1] https://www.atlassian.com/software/jira
[2] http://www.bugzilla.org/
[3] http://www.redmine.org/
[4] https://github.com/loganek/postcommit-checker

Monday, September 29, 2014

Tiny C++ Benchmark Framework

Lately I had to improve a little some of my algorithms. I wanted to check, how changes affect to time of algorithms execution. So I started to search benchmark framework for C++. After a while, I have found quite small, but powerful framework - google benchmark [1].

Simple usage

The simplest usage of google benchmark is shown below:
#include <benchmark/benchmark.h>
#include <algorithm>

int complex_computation(int n)
{
  if (n == 0) 
    return 0;

  unsigned int a = 1, b = 1;

  for (unsigned int i=0; i < n-1; i++) 
    {
      std::swap(a, b);
      b += a;
    }

  return b;
}

static void BM_Fibonacci(benchmark::State& state)
{
  int ret;

  while (state.KeepRunning())
    ret |= complex_computation(500);

  CHECK(ret != 0);
}

BENCHMARK(BM_Fibonacci);

int main(int argc, const char* argv[]) 
{
  benchmark::Initialize(&argc, argv);
  benchmark::RunSpecifiedBenchmarks();

  return 0;
}
At the beginning, we have to define function, which will be measured (complex_computation, in my case). Next, we're defining benchmark method - BM_Fibonacci. It has one argument - state (I will talk about it later). In while loop we call our method, until benchmark's working. ret variable is used only because of compiler optimizations (we'd like to avoid removing dummy code). Benchmark method should be later registered (using BENCHMARK macro). In main function, framework should be initialized, and after that, we can run all our benchmark methods.
loganek@hf-gcs-computer:~/Documents/blog-benchmark$ g++ benchmark.cpp -std=c++11 -lbenchmark -lpthread -O2 -o benchmark
loganek@hf-gcs-computer:~/Documents/blog-benchmark$ ./benchmark 
Reading /proc/self/cputime_ns failed. Using getrusage().
Benchmarking on 4 X 2701 MHz CPUs
2014/09/29-00:49:29
CPU scaling is enabled: Benchmark timings may be noisy.
DEBUG: Benchmark      Time(ns)    CPU(ns) Iterations
----------------------------------------------------
DEBUG: BM_Fibonacci        208        225    2222788                                  
loganek@hf-gcs-computer:~/Documents/blog-benchmark$ 

As you can see, there is computation time, cpu and iterations count - everything what we need :) Moreover, we can also get a few informations about machine.

Arguments, range of arguments

Snippet shown above is very simple, but this framework offers users much more. We can define a set of arguments for benchmark. Let's remind previous example. We tried to measure fibonacci implementation. But I hardcoded an argument. Sometimes we'd like to measure one method with different arguments. We don't have to define BM_Fibonacci_5, BM_Fibonacci_42, BM_Fibonacci_87 functions for different arguments. Let's look at the improvement of previous code:
static void BM_Fibonacci(benchmark::State& state)
{
  int ret;
  while (state.KeepRunning())
    ret |= complex_computation(state.range_x());
  CHECK(ret != 0);
}

BENCHMARK(BM_Fibonacci)->Arg(5)->Arg(42)->Arg(87);
and the output is also quite different:
loganek@hf-gcs-computer:~/Documents/blog-benchmark$ ./benchmark 
Reading /proc/self/cputime_ns failed. Using getrusage().
Benchmarking on 4 X 2701 MHz CPUs
2014/09/29-01:20:03
CPU scaling is enabled: Benchmark timings may be noisy.
DEBUG: Benchmark         Time(ns)    CPU(ns) Iterations
-------------------------------------------------------
DEBUG: BM_Fibonacci/5           3         19   25832109                                  
DEBUG: BM_Fibonacci/42         18         35   14398500                                  
DEBUG: BM_Fibonacci/87         44         61    8224413   
We've access for results of every argument, which I passed to a benchmark method.
It is also possible to pass range of arguments to our benchmark method.
BENCHMARK(BM_Fibonacci)->Range(0, 1024);
Defined range runs benchmark for min, max in this range, and every power of 8 from this range. So in my case: 0, 1, 8, 64, 512 and 1024.

Multithreading, other features

Google Benchmark framework gives a few other features for developers:
  • multithreading
  • benchmark templates
  • pair of arguments
  • custom reporter class
You may see usage of other features in google benchmark example code [2] or on README page[3].

Summary

That's one of first test framework, which I used for now. Previously I wrote simple methods for measurements, but it wasn't so convenient, and in the long run, it's just waste of time. Moreover, benchmark helps me keep in order my tests, so my code is much cleaner than before.
In the future, I'd like to check also other frameworks; I heard about Celero [4] and hayai [5]. But for now, google benchmark fits my needs.



Links
[1] https://github.com/google/benchmark
[2] https://github.com/google/benchmark/blob/master/test/benchmark_test.cc
[3] https://github.com/google/benchmark/blob/master/README.md
[4] https://github.com/DigitalInBlue/Celero
[5] https://github.com/nickbruun/hayai

Friday, August 29, 2014

gstreamermm on Windows & Visual Studio

Hi everyone!
Recently me and my friends have ported quite big project from Linux to Windows, and had to build it in Visual Studio environment. (Un)fortunatelly, we're strongly dependent on gstreamermm project, so I had to prepare .vcxproj files, which allows us to compile gstreamermm in Microsoft's IDE.
I spent one evening on that, and that's it! I've commited Visual Studio project file for building gstreamermm project, and also property sheet (.props), which contains all necessary dependencies for gstreamermm-based projects.
I've tested it in Debug/Release configuration, both platforms (Win32 and x64), and have used Visual Studio 2010 (project file probably can be upgraded to VS2013, but I didn't test it yet).
You can find it in the nearest gstreamermm release (currently I'm working on 1.2.4 version, it should be finished in a next month), but I've already prepared unofficial release for you [1].
Go ahead, download, use, and file  a bugs on a bugzilla [2] ;)

Installer
If I have a time, I will prepare windows installer for sure, and upload it with official v1.2.4 release. If not, maybe someone else will pick up the gauntlet, and do one-click installer for gstreamermm community - if you'd like to help, just let me know, I'll help you so far as it is possible.

Dependencies
gstreamermm depends on many other libraries, so you need to install gtkmm package (can be found here [3]), or build necessary yourself from sources (that's way which I have chosen).

Links
[1] https://dl.dropboxusercontent.com/u/14229925/gstreamermm-1.0.10-msvc-support.tar.gz
[2] https://bugzilla.gnome.org/enter_bug.cgi?product=gstreamermm
[3] http://ftp.gnome.org/pub/gnome/binaries/

Monday, August 18, 2014

Week with drones - IMAV 2014 report

Last week I spent far away of my homely hacker zone, I was in Netherlands, and took part in IMAV - International Micro Air Vehicle Conference and Competition [1], as a member of High Flyers - Academic Scientific Association from Silesian University of Technology [2].

Briefly about IMAV
IMAV is an annual competition for UAV aficionado, combined with conference concerning micro air vehicles. Last year, IMAV was organized by ENAC University, from Toulouse [3]. That was my first time, when I participated in IMAV, and I really enjoyed. Me and my friends (from High Flyers also) decided to attend in both the conference and the competition. We did our best, and we won two silver medals in indoor category (autonomy and operation) [4]!!! The atmosphere on the conference was amazing - everyone was very friendly, you could talk about UAV technologies with people from another universities, countries, and even continents. Moreover, organizers invited us to Airbus factory [5], and we could see, how one of the biggest airliners are made.
HF-4X - our last year platform, and awards :)
https://www.facebook.com/high.flyers.polsl


IMAV 2014
This year, IMAV was organized by University of Technology in Delf, in Netherlands. Organizers made every effort, to prepare conference as good as in France. And this is it! Guys from Delf have organized conference very well.

Rules
This year there was no division into outdoor and indoor category. Whole mission, which should be done, took place in both inside the buildings, and also outside. So participants have to prepare platform, which can fly in various conditions, or just made two kind of platforms - for indoor and outdoor operations. Most of (or maybe all) teams have chosen later variant (including High Flyers).
Competition has took place in the village of Oostdorp. Participants had to make a map of Oostdorp, find obstacles on the roads, read numbers on the buildings, precisely scan one of them, observe digits shown on seven-segment display. And the most important - every mission should be performed fully autonomous. If an operator interfere during a mission, a team will get less points. Competition rules might be found on an official IMAV 2014 website [6].

Me and my team on IMAV 2014
High Flyers has participated with three platforms. Two of them was designed for outdoor conditions, and one - for flying inside a building. Unfortunately, one of outdoor platforms has broken down on competition's day (one day earlier, during a tests, everything has worked fine...:), and we used only two platforms. Even so, we have won very good, 4th place. Gold medal for team from Singapore, silver - Germany, and bronze - for previous organizers - France. Final competition results might be found on the IMAV 2014 website [7].

High Flyers with UAVs before...
https://www.facebook.com/high.flyers.polsl

...and during competition
https://www.facebook.com/high.flyers.polsl



Future
Next year - Achen, Germany. I'm looking forward to the rules. If it is possible, I definitely will go there. I think, every one interested in UAV, should be on IMAV, meet people crazy about drones.

IMAV's disadvantages
IMAV was really amazing, but when I backed home, I get to know the only one disadvantage of this conference. I wasn't at home whole week, and I totally forgot about my plants :/ Rosemary looks quite ok, but basil probably can't be rescued. I'll do my best, but I'm afraid, I have to buy a new one.
Almost dead basil



Links
[1] http://www.imavs.org/2014/
[2] http://uav.polsl.pl/
[3] http://www.imav2013.org/
[4] http://www.imav2013.org/index.php/final-results.html
[5] http://www.airbus.com/
[6] http://www.imavs.org/2014/documents/IMAV2014CompetitionRules_V1_4.pdf
[7] http://www.imavs.org/2014/competition.html

Wednesday, August 6, 2014

GSoC Report #4


Last stage of my Google Summer of Code 2014 project was to implement mechanism for sending metadata to AcoustID service.
Me and my mentor decided, that metadata will be sent automatically in a background. There is no need for user interaction. Data is sent on adding new audio file to a music library, or on a change metadata of existing track.
AcoustID requires API key for acceptance new metadata, so user has to enter his key into a preferences window.

Metadata Fixer preferences window

Key might be obtained on a acoust id website [1]. While user doesn't enter api key, in plugin window, "AcoustID Settings" button will be displayed.

Plugin info with button referring to an AcoustID preferences window





Links
[1] https://acoustid.org/api-key