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.

Voila!

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']);

$request->expects($this->any())
 ->method('getUserIP')
 ->will($this->returnValue('127.0.0.1'));

$request->expects($this->any())
 ->method('getUserAgent')
 ->will($this->returnValue('Dummy User Agent'));

$request->expects($this->any())
 ->method('getBodyParams')
 ->will($this->returnValue([]));


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

Enjoy!

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

#/usr/sbin/lightdm

and add a new one

/bin/false

Save the file and reboot the machine. Voila!

Update

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(
              $this->getRequest()
                   ->headers
                   ->get('referer')
           );

Alternatively you can write it like this:

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

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
    – No JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and JSON_UNESCAPED_UNICODE
  3. The code should be easy to test and maintain, so it should provide meaningful debug information and error handling.

Continue reading

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

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!

 

How To Configure a Mail Server Using Postfix and Dovecot on Ubuntu 14.04 LTS

This tutorial explains how to setup mail server on Ubuntu 14.04 using Postfix and Dovecot. It’s based on few other tutorials and does not pretend to show you all the best practices. I am writing this tutorial because it’s 99.9% sure that I will forget how I configured my own mail server very very soon and I have to write down all the info while it’s still fresh in my head.

Ok, let’s start to work!

Continue reading