Add GIT branch information to Bash prompt

I’ve seen such as fancy Bash prompts on various tutorials and Linux examples over the Internet and I’ve always wondered how is achieved. I never really had a enough free time to learn more about it and explore the options. But being jobless for a month gave me opportunity to play with the thinks I like 🙂

My solution is pretty simple: when you navigate to git controlled folder, the bash prompt will show “@ branch” after the directory name. Nothing fancy.

Just open your ~/.bashrc configuration file with your favorite editor and add the following:

get_git_branch () {
git name-rev HEAD 2> /dev/null | sed "s/[a-zA-Z0-9]\+\ \(.*\)/ @ \1/"

than put this into your PS1 string:


so it become something like that

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w$(parse_git_branch) \n\$\[\033[00m\] '

Restart your terminal or type bash to start new bash session. Navigate to git controlled folder to test. It should look like this:


VBoxManage.exe: error: Failed to open/create the internal network ‘HostInterfaceNetworking-VirtualBox’

If you use Vagrant on Windows 10, there is big chance of getting error like this when you try to start the machine.

vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Clearing any previously set forwarded ports...
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
        default: Adapter 2: hostonly
    ==> default: Forwarding ports...
        default: 19021 (guest) => 19021 (host) (adapter 1)
        default: 4567 (guest) => 4567 (host) (adapter 1)
        default: 3000 (guest) => 3000 (host) (adapter 1)
        default: 3003 (guest) => 3003 (host) (adapter 1)
        default: 6379 (guest) => 6379 (host) (adapter 1)
        default: 9000 (guest) => 9000 (host) (adapter 1)
        default: 27017 (guest) => 37017 (host) (adapter 1)
        default: 22 (guest) => 2222 (host) (adapter 1)
    ==> default: Running 'pre-boot' VM customizations...
    ==> default: Booting VM...
    There was an error while executing `VBoxManage`, a CLI used by Vagrant
    for controlling VirtualBox. The command and stderr is shown below.

    Command: ["startvm", "8dd3dbf3-efe3-4183-98d6-7679f9e83238", "--type", "headless"]

    Stderr: VBoxManage.exe: error: Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #9' (VERR_INTNET_FLT_IF_NOT_FOUND).
    VBoxManage.exe: error: Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND)
    VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole

The problem appears only when Vagrant is configured to use private_network (i.e. Host-Only Ethernet Adapter). If you change your Vagrantfile configuration so that bridged network is used instead of private one, the machine will boot up without any problem. But how to fix the issue with the private network?
It’s more easy than you can imagine!

1. Go to start menu -> Control Panel -> Network and Internet -> Network and Sharing Center -> click on “Change adapter settings” form the menu on the left sidebar. List of available network adapters will show up.
2. Double-click the “VirtualBox Host-Only Ethernet Adapter” from which the error is comming. Please note that you may have multiple VirtualBox ethernet adapters and so you should read more carefully the error message you get to determine the problematic one.
3. Click the “Properties” button
4. Tick the checkbox for “VirtualBox NDIS6 Bridged Networking driver”
5. Press the OK button.
6. Try vagrant up command now. The machine should boot normally.


Mock Yii2 components

The well written code is also testable code – it is loosely coupled to the other components, it follows the single responsibility principle, there are no explicit dependencies and so on. We all know the rules, but there is always an exception.

It’s pretty common situation to unit test component or controller that depends on another core Yii component – for example using \yii\web\Request to get query string or $_GET variable.

Rewriting your library in order to remove the explicit dependencies is not always option, because it may lead to massive refactoring and actually break more things than benefits.

In such as case a what I really want to do is to assign temporarily \Yii::$app->request PHPUnit Mock Class, so I can override the return values e.g.

$request = $this->getMock('\yii\web\Request', ['getUserIP', 'getUserAgent', 'getBodyParams']);


 ->will($this->returnValue('Dummy User Agent'));


\Yii::$app->set('request', $request);


Disabling graphical login in Raspbian

If you are using Raspberry PI as headless machine, you do not need to start the graphical server at all. It is useless when Rasbian is used as server OS and disabling it will free ~40MB of RAM.
To do so, you need to edit the /etc/X11/default-display-manager file using your favorite text editor.

$ sudo vim /etc/X11/default-display-manager

Then comment out the line


and add a new one


Save the file and reboot the machine. Voila!


There is a easier way of doing it…
Just run the Rasbian configuration utility

$ sudo raspi-config

In boot option menu choose:

  1. Enable Boot to Desktop/Scratch and enable Console Text.
  2. Also check SSH by going in ssh and selecting Enable or disable ssh server.
  3. After you quit, you’ll be asked to reboot, choose Yes.


Symfony 2 : Redirect to Referer

There are few methods of redirecting to referer.
Inside your controller action you can use:

return $this->redirect(

Alternatively you can write it like this:

 $request = $this->getRequest();
 return $this->redirect($request->server->get('HTTP_REFERER'));

How to create user without useradd command in OpenWRT

There is no useradd command in OpenWRT. Instead, shadow user package is available but I found it overkill. Anyway, if you are interested in using it – check out this tutorial,
Follow these steps to create a user without using useradd command in OpenWRT. Continue reading “How to create user without useradd command in OpenWRT” »

Generate huge JSON files with custom PHP >5.3 class

Lately, I’ve been working on transitioning XML feeds to JSON format on big video site.  We generate these feeds in order to feed external search service with results. It’s similar to sitemap, but it provides more detailed information about the pages.

This task is challenging because of the following problems that need to be resolved:

  1. The feed need to represent over 500 000 database entries i.e. videos. It’s just not possible to generate huge PHP multidimensional array with more than 500 000 elements and pass it to json_encode(). Obviously, you need to generate small JSON objects (chunks) concatenated with hand-coded strings and so build the full feed.
  2. The development and production servers we use are equipped with outdated PHP version 5.3.27. That means:
    – No meaningful error messages because json_last_error_msg() function it’s not available prior PHP 5.5
  3. The code should be easy to test and maintain, so it should provide meaningful debug information and error handling.

Continue reading “Generate huge JSON files with custom PHP >5.3 class” »

Format microtime() to provide better feedback on the time elapsed

As a PHP developer you know that it’s common task to check how long a particular class, function or procedure performs. Usually this involves measuring of the time particular code snippet takes to execute. There are lots of PHP code benchmark scripts out there, but the simplest method remains to check the difference between the start and end time. Continue reading “Format microtime() to provide better feedback on the time elapsed” »

VLC does not support the audio or video format “hevc”. Unfortunately there is no way for you to fix this.

Just you have chosen a good mоvie to watch, you are seated comfortably in an armchair with pack of popcorn, clicked on your favorite media player VideoLAN and… bang! Error!

VLC does not support the audio or video format “hevc”. Unfortunately there is no way for you to fix this.

The error message above is not really correct. There is a way to fix it! All you need is libde265  – an open source implementation of the h.265 video codec. The easiest way to install it on your computer is to add the corresponding PPA that contains Ubuntu packages of the libde265 library, plugins for the GStreamer framework, VLC and required dependencies. Just open the terminal (Ctrl + Alt + T) and type the following commands:

This will add the PPA repository:

sudo apt-add-repository ppa:strukturag/libde265</code>
sudo apt-get update

…and this will install VLC plugin:

sudo apt-get install vlc-plugin-libde265

If you use Gstreamer based player as Totem, install this plugin:

sudo apt-get install gstreamer0.10-libde265

For GStreamer 1.0 software install this

sudo apt-get install gstreamer1.0-libde265

The solution described above to open mkv file with H.265 HEVC codec is working perfectly for me on Ubuntu 14.04. If you have troubles with it, you can try to disable the Universe repository and add the PPA djcj/vlc-stable in order to install the latest stable VLC version.

In a terminal run this command

sudo add-apt-repository ppa:djcj/vlc-stable

Then open Synaptic as Administrator:

sudo synaptic

Go to Settings -> Repositories and uncheck the Universe repo.

Restart your player and enjoy the movie!