Install bumblebee Ubuntu 16.04.1

Update and install latest driver
sudo apt-add-repository ppa:graphics-drivers/ppa
sudo apt-get update && sudo apt-get dist-upgrade
sudo apt install nvidia-prime nvidia-370

Switch to intel card
sudo prime-select intel
Install bumblebee testing with primus
sudo add-apt-repository ppa:bumblebee/testing
sudo apt update
sudo apt-get install bumblebee bumblebee-nvidia primus nvidia-settings nvidia-370

Add kernel modules to load at boot time
sudo gedit /etc/modules

Blacklist nvidia
sudo gedit /etc/modprobe.d/bumblebee.conf
# 370
blacklist nvidia-370
blacklist nvidia-370-updates
blacklist nvidia-experimental-370

Configure bumblebee

sudo gedit /etc/bumblebee/bumblebee.conf
nvidia-current -> nvidia-370

Add user to bumblebee group, enable bumblebeed daemon service.
sudo gpasswd -a $USER bumblebee
sudo systemctl enable bumblebeed

Add boot flags (depend on each machine, my laptop is):
sudo gedit /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nouveau.modeset=0 acpi_osi=! acpi_osi=\"Windows 2009\" acpi_backlight=native idle=nomwait"
sudo update grub2

Check if bumblebee working

sudo apt-get install mesa-utils
primusrun glxinfo | grep OpenGL
lsmod | grep bbswitch
cat /proc/acpi/bbswitch
primusrun glxgears
cat /proc/acpi/bbswitch

There is a bug that prevent to run steam’s games using bumblebee, here is how to fix:

sudo apt-get install lib32stdc++6
cd ~/.steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu
mv ~/backup/32
ln -fs /usr/lib32/
cd ~/.steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu
mv ~/backup/64
ln -fs /usr/lib32/

Open games in steam: open steam -> libraries -> right click a game -> properties -> set launch options
primusrun %command%

Useful commands:

lspci | egrep 'VGA|3D'
lsmod | grep bbswitch
dmesg | grep bbswitch
dpkg -l | grep bumblebee
lsmod | grep nvidia
optirun -b none /usr/bin/nvidia-settings -c :8


Use fcitx in hipchat on ubuntu

In my company, we use Hipchat to communicate while we work. But on my machine (Ubuntu 16.04.1) I can not type my native language (Vietnamese).  That is because I switch from ibus to fcitx (there are lot of bug in ibus these days), and unfortunately, Hipchat only support ibus. I used to use Hipchat web as an alternative. But recently I find out I can make Hipchat work with fcitx, with a simple command:
sudo ln -s /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/ /opt/HipChat4/lib/plugins/platforminputcontexts
Hope this help some one.

phpenv, drupalcs in fish shell

To add phpenv and other command to fish shell, run this command:
vim ~/.config/fish/

set PATH $HOME/.phpenv/bin $PATH
set cmd phpenv init -
eval $cmd

alias drupal8cs "$HOME/.composer/vendor/bin/phpcs --standard=$HOME/.composer/vendor/drupal/coder/coder_sniffer/Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"

alias drupal8pr "$HOME/.composer/vendor/bin/phpcs --standard=$HOME/.composer/vendor/drupal/coder/coder_sniffer/DrupalPractice --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'"

To reload the configuration, run this command:
exec fish

Install phpdbg on ubuntu 14.04

  1. Install phpenv
  2. Download bison 2.7 and install it
  3. cd ~/.phpenv
    cd libexec
    vim phpenv-install
  4. Here is the most important part, we need to add more options to CONFIGURE_OPTIONS
    CONFIGURE_OPTIONS=”…….. –with-readline \ –enable-phpdbg\ ……………………..”
  5. phpenv install php-5.6.2
    At the time this post is published, the latest version of PHP is 5.6.2, you can change that.
  6. cd /path/to/your/index.php
    phpenv local 5.6.2
  7. Remember to restore configure options if you want to install other version of php via phpenv