Big plus for Belgium railways

I was travelling last weekend to Belgium and I have to say big thank you to Belgium Railways. I was really surprised how clean the trains were and also how helpful the personal was.

They answered all our questions – even helped us to find correct connection. Everything with smile on their faces without a look like – why are you bothering us. It might seem a little, but comparing to Berlin situation, it was like day and night.

I’m looking forward to use your service again. Thank you one more time.

Book: Database Design for mere mortals


Yesterday I got a new book to read: Michael J. Hernandez / Database Design for mere mortals. I believe it will be a good mate during my travels to and from job. It has about 610 pages, so I have a lot of to read :).

From first glance, it will be much more readable than my previous book, which I haven’t finished and I’m afraid whether I will ever find the courage to at least try to finish it.

I will keep you updated about the content with my notes.

Enable XDebug on MAMP step by step

I had to enable XDebug on my MAMP installation. And as my common practice, I decided to make a step by step visual manual how to do it.

1. Backup your php.ini file

I always recommend to make a backup version of your current php.ini file, so you can revert easily in case something goes wrong.

$ cd /Applications/MAMP/bin/php/php5.6.10/conf
$ cp php.ini php.ini.bck

Please check version of PHP you are using on your MAMP installation. It might be different than mine.

2. Edit php.ini

Edit php.ini file and find section [xdebug]

$ vim php.ini

By default it looks somehow like following


The only thing you have to do is to change it to following


and save it.

3. Restart your apache and enjoy xdebug

$ sudo /Applications/MAMP/bin/ && sudo /Applications/MAMP/bin/ 

Mac OS X – Fix broken .bash_profile

Murphy law says:

If things can go wrong, they will surely go :).

I was trying to add PATH to my .bash_profile and I made mistake. This is not something you’d like to do because this will break all your command line commands. Not even vim will be working to fix .bash_profile file.

So what to do next?

Thanks to the help on there’s an easy solution.

Open your terminal and run:

export PATH=/bin:/usr/bin:/usr/local/bin

When you restart the terminal, all your commands will be working again as expected.

vim ~/.bash_profile

So now we can keep breaking our PATH as often as we want since we know how to repair it easily ;).

Mac OS X – Enable memcached on MAMP

I had to install memcached on Mac OSX El Captain and MAMP and it was quite tricky. Let’s do it together to make your life more easier.

0. Preparation

The easiest way is to use homebrew to install it. If you do not have brew already, run command in your terminal.

ruby -e "$(curl -fsSL"

1. Install memcached

To install memcached, run this command in your terminal.

brew install memcached

Most of the time, everything goes well and that’s the reason why a lot of articles finishes here. I had an issue yesterday with libevent package. But I have removed and install it again and the issue was solved.

brew remove --force libevent
brew install libevent

2. Install memcached as PHP extension

This quite depends on the PHP version you are using with the MAMP. To find all the supported php memcached version, run this command in the terminal:

brew search memcached

I use PHP 7.0 on localhost, so I have to install php70-memcached. But as I said, this depends on the PHP version, you are running on localhost.

brew install homebrew/php/php70-memcached

For some reason I was force to run this command, so maybe you will need to run it as well. But it’s also part of the message / help written in terminal, so it’s good idea to read them 😉

brew install --HEAD homebrew/php/php70-memcached

Btw, this command takes a while to finish, but now we should have memcached installed on Mac OS X.

php -i | grep memcached
memcached support => enabled
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php

3. Create and update php.ini
Now the memcached is installed for our PHP Cli version (command line version of PHP), but it might not be accessible for PHP running in browser. If you didn’t know there’re 2 version of PHP, it’s fine ;). You learned another new thing.

3a. Download from Github
I found a lot of articles describing how to build from source codes of PHP, but actually it never worked for me. Most probably I was doing some silly mistakes, but at the end, I found Github repository with already done files which are ready to be downloaded and used.

I would recommend you to do the same – download it and use it. It will save you a lot of time 😉

3b. Copy to proper extension folder
As I said earlier, I use PHP 7.0 on my localhost, so the folder with extension for me is


So move the file to the proper folder.

3c. Edit php.ini and add info about new extension to be loaded

Edit proper php.ini file

vim /Applications/MAMP/bin/php/php7.0.0/conf/php.ini

And add

Somewhere in this file. It’s good idea to find where extension= are and add it as the last one.

3c. Restart MAMP

The last thing to be done is to restart MAMP and check whether everything is working as expected.

If you run http://localhost:8888/MAMP/index.php?language=English&page=phpinfo in your browser, you should find memcached section on this page. If yes, congratulation – memcached is installed on your MAMP and you can take advantage of it.

4. Congratulation

I do not know better feeling than when the things are finally working as expected. So CONGRATULATION, memcached is up and running on our Mac OS X El Captain and also in MAMP.

Please let me know if you had any other issues while installing mamcached on your Mac OS X using MAMP, so we can solve them together.

MySQL – How to find out hour difference between two dates

My challenge for yesterday was to find out, how many hours a user is registered. So in other words, what’s hour difference between the date/time an user register and now.

And believe or not, it’s pretty easy.

# Created is saved as unixtime, e.g. 1455251945
  FLOOR((now() - u.created) / 3600) hours
  users u
  uid = 1;

If you save created as datetime, you can still do it.

# Created is saved as datetime, e.g. 2016-02-11 11:00:12
  FLOOR((now() - UNIX_TIMESTAMP(u.created)) / 3600) hours
  users u
  uid = 1;

So challenge done, job done and smile kept 😉

Mac OS X – Set up autocomplete hotkey in MySQLWorkbench

I use MySQLWorkbench everyday and the autocomplete hotkey is not enabled by default. I can’t figure out why, but luckily, there is a way how to enable it.

1. Edit /Applications/…/main_menu.xml

vim /Applications/

2. Find section Auto-complete

You can use /Auto-complete in vim to find the string

3. Remove comments

<value type="object" struct-name="app.MenuItem" id="">
  <link type="object" key="owner" struct-name="app.MenuItem"></link>
  <value type="string" key="caption">Code Completion</value>
  <value type="string" key="name">cc-menu</value>
  <value type="string" key="itemType">cascade</value>
  <value type="string" key="context">*query</value>

  <value type="list" content-type="object" content-struct-name="app.MenuItem" key="subItems">
    <value type="object" struct-name="app.MenuItem" id="">
      <link type="object" key="owner" struct-name="app.MenuItem"></link>
      <value type="string" key="caption">Auto-complete</value>
      <value type="string" key="name">list-members</value>
      <value type="string" key="command">builtin:list-members</value>
      <value type="string" key="itemType">action</value>
      <value type="string" key="shortcut">Modifier+Space</value>
      <value type="string" key="platform">windows,linux</value>
      <value type="string" key="context">*query</value>
    <value type="object" struct-name="app.MenuItem" id="">
      <link type="object" key="owner" struct-name="app.MenuItem"></link>
      <value type="string" key="caption">Auto-complete</value>
      <value type="string" key="name">list-members</value>
      <value type="string" key="command">builtin:list-members</value>
      <value type="string" key="itemType">action</value>
      <value type="string" key="shortcut">Command+Escape</value>
      <value type="string" key="platform">macosx</value>
      <value type="string" key="context">*query</value>

4. Change hot-key in case you like another one.

<value type="string" key="shortcut">Command+Escape</value>
<value type="string" key="platform">macosx</value>

5. Restart MySQL Workbench

Restart MySQL Workbench and enjoy your Code completion / Autocomplete feature.

Regular expression – exclude string from the url

My friend Hubert came to me yesterday to find solution for his issue:

Write a regular expression for all the urls from a specific domain, but skip those which contain /admin-web/ string.

It took me some time, as I do not like negation in regular expression, but we found out the correct regular expression:


You can test it in one of the greatest Regular expression tool out there

Let me know if you have any other solution how to achieve this.

MySQL – How to convert string into date data type

I’ve been working on the project after someone and the programmer didn’t like the different data types in the database. That’s only explanation for me because he saved everything into the VARCHAR data type – also dates. So instead of using DATE, DATETIME or TIMESTAMP data types, he just put everything into VARCHAR and it was done. So any SQL query using DATE functions are quite difficult. Also instead of saving dates in YYYY-mm-dd HH:ii:ss format (at least), he preferred to save it in mm-dd-YY-HH-ii format.

Please, if you can think of why he would do so, please let me know.

Fortunately MySQL comes with STR_TO_DATE function, which is very helpful in this case.

SELECT created FROM users WHERE uid = 10; // Result: 1-8-2015-11-20

Let’s use STR_TO_DATE function of MySQL

SELECT STR_TO_DATE(created, '%Y-%m-%d %H:%i:%s') FROM users WHERE uid = 10; // Result: 2015-08-01 11:20:00

And because the string was converted into date format, we can start using all DATE functions the MySQL offers to us.

It’s not clever to use public transport in Berlin without ticket

Yes that’s right – it’s not clever to use public transport in Berlin without ticket. The people responsible for checking it are very active here in Berlin and the chance they will check you is quite high.

I remember back home in Czech Republic – it was pretty rare and I used it pretty much, but it doesn’t apply to Berlin at all. I’ve been here for little bit more a month and I’ve got checked 3 times already and saw another 2 checking before I entered the vehicle.

And with the information that a fine is 60 euro I would not recommend to anyone to try his/her luck. I know that 80 euro per month is pretty much, but you will be able to travel in peace.

© 2016 Tomas Pavlatka

Theme by Anders NorenUp ↑