Sunday, April 30, 2017

Changing Ubuntu full Screen Resolution in a Hyper-V VM

Changing Ubuntu full Screen Resolution in a Hyper-V VM

# vi /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1920×1080"

# update-grub
# sync; reboot

Reference:

https://blogs.msdn.microsoft.com/virtual_pc_guy/2014/09/19/changing-ubuntu-screen-resolution-in-a-hyper-v-vm/

Friday, April 14, 2017

Save the selected lines to a file

To save the selected lines to a file, select a region using visual mode and then enter:

:w /tmp/filename

To insert/paste text from a file:

:r /tmp/filename

Set up Xdebug

Set up Xdebug

https://github.com/joonty/vdebug

SELinux does not allow httpd to connect to other network resources by default. Turn it on:

# setsebool -P httpd_can_network_connect 1
# getsebool -a | grep httpd_can
or
# chcon -v -t httpd_sys_content_t /usr/lib64/php/modules/xdebug.so

Note: http://stackoverflow.com/questions/2207489/apache-not-loading-xdebug-but-does-when-started-from-the-command-line

Edit ~/.vimrc:

# vim ~/.vimrc

let g:vdebug_options = {}
let g:vdebug_options["port"] = 9009

Edit xdebug configuration:

# vim /etc/php.d/15-xdebug.ini

; Enable xdebug extension module
zend_extension=xdebug.so
;zend_extension=/usr/lib64/php/modules/xdebug.so

xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9009
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_connect_back=0
xdebug.remote_autostart=0
xdebug.remote_mode=req

xdebug.max_nesting_level=1000

Sample script:

# vim test.php

<?php
here();

function here() {
    xdebug_break();
    echo name('Jun');
}

function name($name) {
    $name .= '1';
    return 'Hello ' . $name . ' ' . date('Y-m-d H:i:s');
}

Once in debugging mode, the following default mappings are available:

<F5>: start/run (to next breakpoint/end of script)
<F2>: step over
<F3>: step into
<F4>: step out
<F6>: stop debugging (kills script)
<F7>: detach script from debugger
<F9>: run to cursor
<F10>: toggle line breakpoint
<F11>: show context variables (e.g. after "eval")
<F12>: evaluate variable under cursor
:Breakpoint <type> <args>: set a breakpoint of any type (see :help VdebugBreakpoints)
:VdebugEval <code>: evaluate some code and display the result
<Leader>e: evaluate the expression under visual highlight and display the result

To stop debugging, press <F6>. Press it again to close the debugger interface.

If you can't get a connection, then chances are you need to spend a bit of time setting up your environment. Type :help Vdebug for more information.

Browser:

http://dru8.local/hello?XDEBUG_SESSION_START=1

Note: Append XDEBUG_SESSION_START=1 to the end of the URL.

Tuesday, April 11, 2017

Compile the latest Vim 8.0 on CentOS 7

Compile the latest Vim 8.0 on CentOS 7

Remove the existing vim if you have already installed it:

# yum list installed | grep -i vim

vim-common.x86_64                    2:7.4.160-1.el7                @base
vim-enhanced.x86_64                  2:7.4.160-1.el7                @base
vim-filesystem.x86_64                2:7.4.160-1.el7                @base
vim-minimal.x86_64                   2:7.4.160-1.el7                @anaconda

# yum remove vim-enhanced vim-common vim-filesystem

Note: You do not need to remove vim-minimal because sudo depends on it.

For Red Hat/CentOS users:

# yum install gcc make ncurses ncurses-devel
# yum git
# yum install ruby ruby-devel lua lua-devel luajit \
luajit-devel ctags python python-devel \
python3 python3-devel tcl-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed

or

# yum clean all
# yum grouplist
# yum groupinfo "Development Tools"
# yum groupinstall "Development tools"
# yum install ncurses ncurses-devel

For debian/Ubuntu users:

# apt-get remove vim vim-runtime vim-tiny vim-common

# apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
python3-dev ruby-dev git

# apt-get install libncurses5-dev python-dev libperl-dev ruby-dev liblua5.2-dev

// Fix liblua paths
# ln -s /usr/include/lua5.2 /usr/include/lua
# ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/local/lib/liblua.so

If you want to install the optional packages With yum groupinstall command:

# vim /etc/yum.conf

group_package_types=default, mandatory, optional

Note: the default setting is default, mandatory.

Install ctags and cscope:

# yum install ctags cscope

Build vim:

# cd /usr/local/src

Download vim source (it is better to get it from GitHub because you can get all the latest patches from there):

# git clone https://github.com/vim/vim.git
# cd vim
or
# wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
# tar -xjf vim-7.4.tar.bz2
# cd vim74

Show the configuration options:

# ./configure --help

Configure:

# ./configure --prefix=/usr --with-features=huge --enable-multibyte --enable-rubyinterp --enable-pythoninterp --enable-perlinterp --enable-luainterp --enable-cscope

Build:

# make
or
# make VIMRUNTIMEDIR=/usr/share/vim/vim74

# make install

re-hash the environment:

# hash -r

Check vim version:

# vim --version | less

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 24 2016 14:27:26)
Included patches: 1-2102
...
+lua +multi_byte +perl +python +ruby

Check vim patches:

# vim

:echo has("patch-7.4-2102")

1

Reference:

https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source

https://gist.github.com/holguinj/11064609

http://www.fullybaked.co.uk/articles/installing-latest-vim-on-centos-from-source

http://www.vim.org/git.php

Wednesday, April 5, 2017

PHPUnit did not output the result in color

PHPUnit did not output the result in color when colors=true in phpunit.xml. It's because it was missing the posix extension, which is provided by the php-process package.

# yum install php71u-process

Tuesday, April 4, 2017

ReflectionException: Class PHPUnit_Framework_Error does not exist

ReflectionException: Class PHPUnit_Framework_Error does not exist

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFailingInclude()
    {
        include 'not_existing_file.php';
    }

Solution 1:

/**
 * @expectedException \PHPUnit\Framework\Error\Warning
 */
public function testFailingInclude()
{
    include 'not_existing_file.php';
}

Solution 2:

public function testFailingInclude()
{
    $this->expectException(\PHPUnit\Framework\Error\Error::class);

    include 'not_existing_file.php';
}