29 August 2016


"Date class however has numerous flaws: (...)
  • It does not represent... date. Seriously, officially date is "[...] the day of the month or year as specified by a number [...]"  whereas in Java it represents point in time without any specific calendar (day/month/year).
  • It has 20+ deprecated methods, including getYear(), parse(String), and many constructors. These methods are deprecated for a reason, because they lead you to believe Date represents, you know, date."
Tomasz Nurkiewicz

22 August 2016

Lesson learnt:000 - Introduction

When I read Henrik Warne's blog about his way to  lesson learnt from bugs (https://henrikwarne.com/2016/04/28/learning-from-your-bugs/)  , I decided to do the same thing,  because I believe it will help me to be a better developer over time.

Each blog entry will contains:

Date - when this happen.
Story - what happen
How was discovered - describes how this was found it.
How many times happen - is it first time or is it a mistake a made few times.
Fix - how I fix it.
Caused by me  yes or no
Could be avoided: yes or no ,
Time taken to resolve bug:
Lesson learnt - what  I learnt from mistake and what i can do to not make this mistake in the future.

18 August 2016

How to get difference between 2 dates ( LocalDate ) in years , months or days ?

Solution for :
Java 8 and above


August in my month of Java 8 where I try practice various things that are new in Java 8 and I should know already. At some point , I tried to create person  with  birthday stored as LocalDate and get age in years , but I found it that there is no method on Duration to check that. I was wonder can I do it this using only Java 8 . As it turns out yes.

You need use ChronoUnit class that has a nice method to do this.
LocalDate birthday = LocalDate.of(1980,4,4);

EXAMPLE: (To run this example you need copy these 2 classes and add junit and assertJ libraries )

Person class:
package dms.pastor.kb.java8.example;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

 * Author Dominik Symonowicz
 * Created 18/08/2016
 * WWW:    http://pastor.ovh.org
 * Github: https://github.com/pastorcmentarny
 * Google Play:    https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
 * LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
public class Person {
    String name;
    LocalDate birthday;

    public Person(String name, LocalDate birthday) {
        this.name = name;
        this.birthday = birthday;

    public String getName() {
        return name;

    public int getAge(){
       return Math.toIntExact(ChronoUnit.YEARS.between(birthday,LocalDate.now()));

    public int getAgeInMonths(){
        return Math.toIntExact(ChronoUnit.MONTHS.between(birthday,LocalDate.now()));

    public int getAgeInDays(){
        return Math.toIntExact(ChronoUnit.DAYS.between(birthday,LocalDate.now()));

PersonTest class:
package dms.pastor.kb.java8.example;

import org.junit.Before;
import org.junit.Test;

import java.time.LocalDate;

import static org.assertj.core.api.Assertions.assertThat;

 * Author Dominik Symonowicz
 * Created 18/08/2016
 * WWW:    http://pastor.ovh.org
 * Github: https://github.com/pastorcmentarny
 * Google Play:    https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
 * LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
public class PersonTest {
    Person person;

    public void setup() {
        person = new Person("Dominik", LocalDate.now().minusYears(18).minusMonths(1).minusDays(1));

    public void shouldReturn18YearsTest() throws Exception {
        final int age = person.getAge();


    public void shouldReturn217MonthsTest() throws Exception {
        final int age = person.getAgeInMonths();


    public void shouldReturn28DaysTest() throws Exception {
        Person toddler = new Person("Toddler",LocalDate.now().minusDays(28));

        final int age = toddler.getAgeInDays();


:) I hope, you found this useful

23 July 2016

How to fix android.view.WindowManager$BadTokenException: Unable to add window -- token null

If your app crash with this error:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
.. while while it tries to display dialog ,then it mean you provide wrong context

AlertDialog.Builder alertBox = new AlertDialog.Builder(getApplicationContext());
AlertDialog.Builder alertBox = new AlertDialog.Builder(AppLauncher.this);

28 June 2016


As a human being, you're multithreaded. You can type with multiple fingers, you can drive and hold a conversation at the same time. The only blocking function we have to deal with is sneezing, where all current activity must be suspended for the duration of the sneeze. That's pretty annoying, especially when you're driving and trying to hold a conversation. You don't want to write code that's sneezy.
Author: Jake Archibald

How to re-apply redis properties?

Sometimes ago I had a problem where software stopped to work and error looks like it was problem with some redis properties .However, It was very mysterious ,because all known settings  that could affect software was setup correctly   (as I did it few times already ). 

I didn't have other option but to re-apply redis properties .As it turns out it is not straightforward to just delete and add key/values . You need do a bit do some commands combos to make this work.

Run your favourite command line (for example git bash)
  1. type: redis-cli DEL _cfgset
  2. type: redis-cli KEYS "namespace:*" | xargs redis-cli DEL (for example for ufo: redis-cli KEYS "ufo:*" | xargs redis-cli DEL)

Problem solved :)

16 June 2016

How to replace command line with git bash in IntelliJ ?

IntelliJ  has an ability to run terminal inside ,but it uses cmd.exe but most of us ,specially these people who use git ,use git bash instead . So you ask yourself; can I replace it ?

Yes, you can!

You just need do few simple steps:
  • Press Ctrl+Alt+S (Open settings)  (anywhere on main screen)
  • Search for terminal in search-box (top left)
  • change path to : C:\Program Files (x86)\Git\bin\sh.exe" --login -i [change path to yours, this is default one for 32 bit version of git bash on Windows)
  • Done :)
  • Open terminal and ... ta daam Git bash is there instead of cmd.exe :)

    9 June 2016

    How looks process of finding job as software developer part 5 : Do I need LinkedIn?

    This is a NOT a professional advice.
    It based on my personal experience only and resources that I read on internet.
    It will contains many  grammar mistakes.
    Please drink double espresso and energy drink as article is long and boring.

    Do I need LinkedIn ?

    It is an optional thing. LinkedIn sounds like great idea,but ...

     It is worth to have, because:
    • Due lack of alternatives . LinkedIn is a only option for social network for professional (although Google+  can be offer better user experience,but it is not designed for professional social network.).
    • It is good source to gain intelligence about company and people ,who will interviewing you.
    • It is good extension to your CV.
    • It is a useful replacement for your personal website and blog.
    In general.I have very bad and annoying experience. 

    • It has many phirshing issues. For example: If you install on Android application, it will stole your contact and spam you with add these people to LinkedIn and etc.
    • It is famous for most evil UX design in industry, because LinkedIn's UX focus on marketing first not user . It uses many phirshing and spamming tricks to buy premium account. As result don't be surprised to receive/send many empty invitation or messages from many people. This is due poor design by LinkedIn. You can found many blog entries complaining about this.
    • It looks nice, but usability can be painful.
    • No ability to block recruiters .

    • Do NOT add  recruiters ,head hunters and other spammers. They will pollute your account with lots of useless job offer that in 99% is irrelevant to you. They will call and send email you and call to you anyway. Add only these who were very helpful in the past.
    it happens to me few times that i got this message .. 

    Hi Dominik,I hope all is well.I have a permanent London based role for a leading finance company. They are looking for a Java Developer to work on a range of greenfield projects. If you interested , let me know and I'll send through further details. Regards
    .. on my e-mail as text and as LinkedIn message.


    • It is not mandatory to have account on LinkedIn.
    • LinkedIn is great alternative if you don't want waste your time on personal website and blog.
    • If your job require constant contact with other people ,then LinkedIn is very useful.
    • Avoid add recruiters , head hunters and other spammers. They will pollute your account with lots of useless job offer that in 99% is irrelevant to you. They will call and send email to you anyway.
    • LinkedIn is very  valuable for company research (gathering information about company that you want work for and for job hunting) .
    • Using LinkedIn can be pain in the ass as you cannot block recruiters and annoying poor user experience design.

    6 June 2016

    it'funq: 029

    " In the last years I’ve developed pretty large Single Page Applications with various frameworks or, when in a rush, mostly a mess of badly organized Javascript code that vomits jQuery calls here and there. "