Preparing Your Pull Request For Code Review

Anyone that is working in a team and is collaborating with others on writing applications is using some form of version control system (VCS). The word collaborating is the important one and to achieve a good level of collaboration, people usually create pull requests in their software development tool of choice, be it GitHub, Bitbucket, GitLab or one of many other out there.

Pull requests are containers for commits that you have done, communication around those commits and changes therein, a code review entry point as well as some other things.

Continue reading “Preparing Your Pull Request For Code Review” »

Caching Part 1: Intro

What Is Caching And Why Should You Use It?

Anyone that has ever worked with high volume sites has at some point had to optimize one or more parts of the application. The most common ways to go about that are profiling the application code and database queries. Once you know where the bottlenecks are, you have a couple of options, depending on the use case:

  • refactoring the code so it runs faster, such as extracting code from foreach loops or optimizing the SQL,
  • offloading the process to the background (I wrote about that in another post),
  • cache the results

Continue reading “Caching Part 1: Intro” »

SaltStack HowTo: Installing, Setting up and Provisioning

The problem and the solution

I work at a company that creates web sites and applications. I joined them in 2008 when there were 2 front-end developers and 3 back-end, including me. Company slowly grew to 7 back-end and 6 front-end developers. The following problem started to get in our way more and more: we were working on one single development server, which means that from time to time we would step on each other toes. What happened is, one guy would open a file, the other guy would open the same file and whoever saves and closes first, is a loser. Also, that server had to have every possible service, program and PHP extension imaginable because it needed to support a lot of diverse projects.

Continue reading “SaltStack HowTo: Installing, Setting up and Provisioning” »

Using Google API to get Google Analytics data with PHP

You might have a need to display data from Google Analytics on your website like number of product page views in your webshop CMS. To achieve that, you would request the page views and maybe sessions (unique visits) for a certain URL from Google Analytics. If you’re using PHP, Google created Google API PHP client to help you do that. In this tutorial we’re going to use Server to Server Application authentication mechanism called two-legged OAuth.

Continue reading “Using Google API to get Google Analytics data with PHP” »

Importing Amazon Kindle Paperwhite to Croatia

Every year I try to surprise my wife with some extraordinary birthday gift. Last year I bought her a nice looking designer dress, an e-book and ordered the Kindle so she can read the Ender’s Game once more. I opted for the newest Kindle, the Paperwhite one. So, ordering this kind of stuff to Croatia is not that easy. We did enter the EU, but for some reason I couldn’t have ordered it from UK, Germany or Italy. Go figure.

As I was a bit late with organizing the delivery, I didn’t have the time to go through 4 people to deliver Kindle like it is a reactor-grade plutonium. So it had to be the States. I placed the order on Wednesday, got charged $160 + $20 shipping. Amazon said that it would take five days to deliver. Two days later, I got an email from local DHL that the package arrived and that I should reply to them with my EORI number.

What is an EORI number?

An EORI number is a unique number throughout the European Community, assigned by a Customs Authority in a Member State to operators (businesses) or persons Economic Operator (EO). By registering for Customs Purposes in one Member State, an EO is able to obtain an EORI number which is valid throughout the European Community. The EO will then use this number in all communications with any EC Customs Authorities for appropriate customs declarations.

Ok, time to find a customs office and request the number. Things in Croatia work a bit different than in more western parts of the world. Namely, to request the EORI number you have to fill a form. And send it via mail. Snail mail. The mail that travels three days from the post office to its destination 6 km away. The mail that my Kindle, which is freezing in some cargo area, derides, having traveled from Nevada over Frankfurt to Zagreb in only two days.

Customs receive my request next Wednesday, and I wait a day to get my EORI number. Needless to say, it is Thursday, my wifes birthday, and all she got was an e-book she can’t read :). Now, EORI requests usually return the same way, via snail mail, but I decide to be assertive and hurry the procedure. Later on I realize that the EORI number is just your PIN prefixed with the country code, and all they needed to do is an INSERT statement to The Great Database Of People That Import Stuff™. Great. Now to pay the cargo “handling”.

DHL, after receiving my EORI number, charges me with $57 (ouch) and delivers Kindle on Friday.

Reading Kindle is great, wife and I share it, buying books is fun and less expensive (money- and space-wise) and I don’t regret one buck spent! Just, what sould I do with this EORI now :)

Quick File Opening in NetBeans

NetBeans is an irreplaceable tool for my every day use. Yes, it’s written in boring, slow Java, but the feature set is great and it helps me to get my tasks done without getting in my way. There are some things that could be better or more responsive. One of those things are code scanning and opening files. I like how Sublime Text 2 does the file open (Go to Anything), and this is how to achieve this in NetBeans.

First, without any plugins, you can type ALT + SHIFT + O which brings up the Go to File dialogue. It is ok, but it doesn’t provide the fuzzy search (you can emulate it by putting * between letters). To achieve fuzzy searching, we need the help of a plug-in called Open File Fast. Plug-in is last reported to run with NetBeans 6.9, but I’m running it with latest, 7.2. To install and configure it, follow these steps:

  • Go to and download for the latest version
  • In NetBeans, go to Tools → Plugins → Downloaded → Add Plugins, select the downloaded file and click Install (
  • Restart NetBeans (although it is not needed to run the plug-in, I found that I couldn’t set key short cut for Open File Fast)
  • Now for the short cut. Go to Tools → Options → Keymap, search for “open file fast” → Assign short cut
I’ve assigned it CTRL + P. It still isn’t near as fast as Sublime Text, but it gets the job done.

Doctrine2 CLI under Silex application

I got it running with Doctrine 2.3.1-DEV. Get doctrine provider using composer:

    "minimum-stability": "dev",
    "require": {
        "silex/silex": "1.0.*",
        "taluu/doctrine-orm-provider" : "*",
    "autoload": {
        "psr-0": { "Entity": "app/" }

Create doctrine.php and put the following content inside. I like to put it in bin/doctrine.php:

#!/usr/bin/env php5
// Load your bootstrap or instantiate application and setup your config here
require_once APP_ROOT .'/vendor/autoload.php';
$app        = new Silex\Application();
// Doctrine DBAL
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'db.options' => $config['db']
// Doctrine ORM, I like the defaults, so I've only modified the proxies dir and entities path / namespace
$app->register(new Nutwerk\Provider\DoctrineORMServiceProvider(), array(
    'db.orm.entities'              => array(array(
        'type'      => 'annotation',
        'path'      => APP_PATH .'/Entity',
        'namespace' => 'Entity',
    'db.orm.proxies_dir'           => APP_ROOT .'/var/cache/doctrine/Proxy',
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
$helperSet = new HelperSet(array(
    'db' => new ConnectionHelper($app['db.orm.em']->getConnection()),
    'em' => new EntityManagerHelper($app['db.orm.em'])

And that’s it :)

Pretty HTML5 multiple file upload with Bootstrap, jQuery, Twig and Silex

There are a number of ways to achieve multiple file upload functionality, but I like HTML5 way of doing it, and it will be supported across all major browsers when IE10 ships. Also, Twitters’ Bootstrap helped me achieve the look without problems. I used a bit of jQuery for help with events. Alongside vanilla html, I will put Twig form syntax to achieve this, together with Symfony2 Form component, for server side.

Continue reading “Pretty HTML5 multiple file upload with Bootstrap, jQuery, Twig and Silex” »