Learning Chinese in Berlin

So I recently startet learning Chinese. My primary motivation was to learn an Asian language. The choice was between Japanese and Chinese. While both cultures are extremely interesting Japanese would have helped me to dive into the Japanese culture (especially comics and anime in its original language) and its people. However the Chinese language seemed like the more reasonable choice for what’s to come in the future. With China on the rise in every sector it feels like having a (basic) way of communicating and understanding in Chinese is the better strategic choice. Even though English will probably still be the world language #1 for the next centuries, having a second option for presenting oneself felt like a good idea.
If you happen to think about learning Chinese in Berlin, you could check out this teacher: http://www.chinesisch-lehrerin.de

If you’re looking for an app to support your studies have a look at https://www.pleco.com. That app literally offers everything you need to improve your learnings additionally to the courses.

August 28th, 2019

jQuery/Slick slider: Uncaught TypeError: Cannot read property ‚add‘ of null

When using slick.js for creating awesome sliders, it might happen that you encounter the following error message:

Uncaught TypeError: Cannot read property 'add' of null

Chances are that you tried to initialize the slider twice (eg by switching within a responsive design or by working with an Angular App and reinitiating the slider).

The simplest solution in this case would be to add the „.not(‚.slick-initialized‘)“ method call to the chain when initiating the slider in the first place:

jQuery('.slick-slider').not('.slick-initialized').slick({
    slidesToScroll: 4,
    rows: 0,
    slidesToShow: 4,
    ...
  });

 

 

 

Juni 18th, 2019

Run Symfony 4 with Docker

If you want to run your next Symfony 4 project within Docker the guys of medium have a great instruction for you.

However I had to additionally install the php zip extension (for docker). You can do this by adding the command

docker-php-ext-install zip

in

.docker/php/Dockerfile

My first RUN command in .docker/php/DOCKERFILE looks as the following:

RUN apt-get update \ apt-get install -y --no-install-recommends vim curl debconf subversion git apt-transport-https apt-utils \ build-essential locales acl mailutils wget zip unzip libz-dev \ gnupg gnupg1 gnupg2 \ && docker-php-ext-install zip

Without the additional command the package for facebook/webdriver would have thrown a dependency error

If you have performance issues running your application locally on docker, you can follow the blog post of DracoBlue for more insights.

tldr;
You get a better performance if you add the „:cached“ flag to your mounted php volume:

php:
  build: .docker/php
  container_name: php_container
  volumes:
    - .:/home/wwwroot/app:cached
  depends_on:
    - mysql

 

Mai 5th, 2019

ORDER BY clause is not in SELECT list

Just like problems with a old passwords you also might encounter the following SQL error when updating your MySQL version:

ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'piwigo.piwigo_images.file' which is not in SELECT list; this is incompatible with DISTINCT

The main reasons is: „As of MySQL 5.7.5, the default SQL mode includes ONLY_FULL_GROUP_BY. (Before 5.7.5, MySQL does not detect functional dependency and ONLY_FULL_GROUP_BY is not enabled by default. For a description of pre-5.7.5 behavior, see the MySQL 5.6 Reference Manual.)“ Source: MySQL docs

You have two options to solve this message: start your mysql server with –sql-mode=““ or set sql-mode=““ in /etc/my.cnf

November 24th, 2018

Fatal error: Uncaught PDOException: PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

If you happen to update your MySQL it might happen that afterwards you get the following error message:

Fatal error: Uncaught PDOException: PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

One (of a couple) possible solution could be to start your mysql server with the option „default-authentication-plugin“ and the „mysql_native_password“ value:

mysql.server start --default-authentication-plugin=mysql_native_password

It might also be necessary to alter your password as following:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

(But don’t forget to flush your privileges with FLUSH PRIVILEGES tho)

November 24th, 2018

Monitor changes on cli live

If you want to watch or monitor a certain process on the cli (to check if changes happen) you can use the „watch“ command. For example if you want to check if a ffmpeg process is going to start or quit use the following command:

watch -n 3 „ps afx | grep ffmpeg“

In this example the command „ps afx | grep ffmpeg“ will be refreshed every 3 seconds on the cli.

Juli 6th, 2018

Javascript: onclick and onblur priority issues

Imagine you have search input field which also opens a suggest container as soon as you begin to type. Also imagine you want the suggest container to vanish as soon as you leave the search input field. You put an onblur() event on your search input field. Now you also want to click on a value of the suggest container to execute a search. The problem now is, if you use an onclick() event for triggering the search via suggest container, the onclick() event will never be triggered. The onblur() of the search input is executed before the onclick() of the suggest container. To solve this issue just swap your onclick() with a onmousedown() event.  That solution let’s the browser automatically re-order the priorities of these event handlers.

Juni 15th, 2018

Query elasticsearch with uri and get parameters

If you want to query elastic search directly via uri you can use the source parameter. This parameter helps you to fire requests like this:

curl -XGET "http://localhost:9200/employee/_search?search_type=count&pretty" -d '{
  "aggregations": {
    "profile": {
      "terms": {
        "field": "_type"
      },
      "aggs": {
        "hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}'

 

directly via URL/GET:

curl -XGET 'http://localhost:9200/employee/_search?search_type=count&pretty&source={"aggregations":{"profile":{"terms":{"field":"_type"},"aggs":{"hits":{"top_hits":{"size":1}}}}}}'

 

Source: stackoverflow

Juni 14th, 2018

How to replace master branch in git from another branch

If you happen to come into the situation that your master branch is screwed (e.g. by falsely merging and reverting other/old branches into the master) you might need to replace your master with another branch (like your develop branch). That is actually pretty easy, all you need to do is executing the following git commands:

git checkout develop
git merge -s ours master
git checkout master
git merge develop

 

After you executed the commands your master branch is completely up-to-date with your develop branch.

Source: stackoverflow

April 7th, 2018

„insert ignore on duplicate entries“ in Doctrine / Symfony

As it’s not possible to do insert or update ignore in doctrine, those who still want to ignore entities when they are already in the database might find this snippet useful:

$doctrine = $this->getContainer()->get('doctrine');
  foreach ($entities as $entity) {
    try {
      $em = $doctrine->getManager();
      $entity->setUniqueValueThatCausesAUniqueConstraintViolation(42);
      $em->persist($entity)
      $em->flush();
    } catch (UniqueConstraintViolationException $e) {
      $doctrine->resetManager();
    }
}

 

Calling $doctrine->resetManager(); is necessary as the entity manager will be closed otherwise and you will not be able to use it anymore.

Please be aware that the disadvantage of that solution is a huge performance decrease as we are flushing the entity manager every round.

Februar 16th, 2018