Ubuntu 16.04 restart Sogou and fcitx

Original post

In short, run the bash script to restart

 

  #!/bin/sh
  pidof fcitx | xargs kill
  pidof sogou-qimpanel | xargs kill
  nohup fcitx  1>/dev/null 2>/dev/null &
  nohup sogou-qimpanel  1>/dev/null 2>/dev/null &

Save this script and run, the Sogou Pinyin and fcitx can be restarted smoothly.

2015 in review

The WordPress.com stats helper monkeys prepared a 2015 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 2,200 times in 2015. If it were a cable car, it would take about 37 trips to carry that many people.

Click here to see the complete report.

Setup a Ubuntu server as a Gateway

This is a guide for setting up a Ubuntu server with two nic interfaces as a gateway of a private network without DHCP.

 

At the very beginning. Let’s say we have a Ubuntu server(14.04) with two nic interface eth0 and eth1.

 

The topology is

Internet <> eth0 –server– eth1 <> private clients

eth0 is a DHCP client or a client with a static IP address which connects the outside internet.
The setup process are same between these two circumstances.

Here is the step-by-step guide.

Continue reading

My Vim with Vundle and YouCompleteMe

I tried Vundle and YouCompleteMe on Vim these days. It takes me a lot of time to make it work.
But these two plugins are really awesome!

At first, you should download Vundle to manage your plugins of Vim.

You can find a very specific guide of Vundle Here

After that, add

	Bundle 'Valloric/YouCompleteMe'

under

	call vundle#begin()

Now you are going to install YouCompleteMe

  1. Open your vim and run
    			:BundleInstall
    		
  2. 			cd ~/.vim/bundle/YouCompleteMe
    		

    and run

    			./install.sh --clang-completer
    		

    FYI, this compile command is for c language, you can find more details Here

  3. Add
    			let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
    		

    so that you don’t have to add .ycm_extra_conf.py in every directory where you run vim.
    The location of .ycm_extra_conf.py can be everywhere you want.

That’s all. Hope you enjoy the awesome plugins.

You can find my .vimrc and ..ycm_extra_conf.py on my attachments

Continue reading

Define a non-integer static const variable in a class in C++

There are always enough tricks in C++ which are going to astonish and confuse me.

 

This time is the something about a static const string variable in a class as a private member.

Let’s look at the vary first version of my code

class Parser {

private:
    /*
    file name of configure file
     */
    string fileName;

    /*
    Error tag
     */
    static const string TAG = &amp;quot;PARSER&amp;quot;;

    //something else
}

It seems straight forward, since you can do it in Java. But in C++, it’s wrong since you CANNOT initialize a non-integer variable here.

So I change it to

class Parser {

private:
    /*
    file name of configure file
     */
    string fileName;

    /*
    Error tag
     */
    static string TAG;

    //something else
}

//in the file of implementation
Parser::Parser() {
	//...
	this->TAG = PARSER;
}

The compile of *.o goes well, but an Error occurs when the g++ tries to link some *.o
It says

parser.o: In function `Parser::Parser(std::string)':
parser.cpp:(.text+0x36): undefined reference to `Parser::TAG'

Finally I got the answer here

You have to define your static member outside the class definition

And at last, my code become

class Parser {

private:
    /*
    file name of configure file
     */
    string fileName;

    /*
    Error tag
     */
    static const string TAG;

    //something else
}
//in the file of implementation
const string Parser::TAG = PARSER;

Now it can be compiled correctly!

In a word, u can never say that u know how to write C++ 🙂

Install Hadoop-2.6.0 on Ubuntu Server 14.04

I was stuck on a weird bug on install Hadoop-2.5.2 on Ubuntu Server 14.04. After several days working, I decided to give up and turn to Hadoop-2.6.0. I download the Hadoop-2.6.0 source this time instead of the compiled version.

You can find a very specific guide HERE

The first step is building the whole project on my machine.

Look at the BUILDING.txt in the source directory, the instruction is very clear.

  1. Download requirement package and for building.
    	sudo apt-get update
    	sudo apt-get install cmake
    	sudo apt-get install gcc 
    	sudo apt-get install g++
    	sudo apt-get install libssl-dev
    	sudo apt-get install zlib1g-dev
    	sudo apt-get install pkg-config
    	

    You also need to install Maven, Ant, Findbugs, ProtocolBuffer and Java of course

  2. Download source package from Apache
  3. Set environment viarable
    	vi .bashrc
    	

    and add

    	#JAVA
            export JAVA_HOME=/usr/lib/jvm/java-7-oracle
            export JRE_HOME=/usr/lib/jvm/java-7-oracle/jre
            export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH:.
            export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
     
            #MVAEN
            export MAVEN_HOME=/usr/local/apache-maven-3.2.5
            export PATH=$PATH:$MAVEN_HOME/bin
     
            #FINDBUGS
            export FINDBUGS_HOME=/usr/local/findbugs-3.0.0
            export PATH=$PATH:$FINDBUGS_HOME/bin
            #ANT
            export ANT_HOME=/usr/local/apache-ant-1.9.4
            export PATH=$PATH:$ANT_HOME/bin
     
            #PROTOBUF
            export PROTOC_HOME=/usr/local/protoc
            export PATH=$PATH:$PROTOC_HOME/bin
            export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PROTOC_HOME/lib
            

    to the file
    and

            source .bashrc
            
  4. Build it under the source directory
            mvn package -Pdist,native,docs -DskipTests -Dtar
            

    This instruction will create binary distribution with native code and with documentataion.
    You can find more option in BUILDING.txt

  5. There maybe some ERROR in building process beacuse of missing dependency. You can read the log carefully and find the corresponding instruction. And redo it manually, than you will find out which one is missing.
  6. Now you can find the target folder and tar.gz under hadoop-2.6.0-src/hadoop-dist/target
  7. Optional: Move the compiled folder to /usr/local for convenience
  8. Add more environment viarable into .bashrc
            #HADOOP
            export HADOOP_HOME=/usr/local/hadoop-2.6.0
            export HADOOP_PREFIX=$HADOOP_HOME
            export HADOOP_COMMON_HOME=$HADOOP_PREFIX
            export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_PREFIX/lib/native
            export HADOOP_CONF_DIR=$HADOOP_PREFIX/etc/hadoop
            export HADOOP_HDFS_HOME=$HADOOP_PREFIX
            export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
            export HADOOP_YARN_HOME=$HADOOP_PREFIX
            export LD_LIBRARY_PATH=$HADOOP_PREFIX/lib/native:$LD_LIBRARY_PATH
            export PATH=$HADOOP_HOME/bin:$PATH
            

    and run

            source .bashrc
            

    And export JAVA_HOME and HADOOP_PREFIX in etc/hadoop/hadoop-env.sh

  9. Run hadoop
            $hadoop version
            Hadoop 2.6.0
            Subversion Unknown -r Unknown
            Compiled by hduser on 2015-01-21T02:46Z
            Compiled with protoc 2.5.0
            From source with checksum 18e43357c8f927c0695f1e9522859d6a
            This command was run using /usr/local/hadoop-2.6.0/share/hadoop/common/hadoop-common-2.6.0.jar
            

After all these steps, I modify the xmls to adapt a three-machine-cluster which are as same as my 2.5.2 version and the hadoop and yarn works well !
I don’t know why, but it just works !

Here are my configurations of the cluster

Continue reading

How To Recovery from Deepin Desktop to Unity

I tried to install Deepin Desktop Environment on my Ubuntu 14.04.1 LTS because it look so fascinating. But unfortunately I failed. The worse thing is that when I restarted my PC and logged in again, the default desktop Unity failed ! And here is my solution to make it work again

I start with undoing everything that I did when tried to install Deepin.

Use Ctrl + Alt + F1 to enter the tty console, you will find out the system version become Deepin. I will explain it later.

  1. Remove the deb source of Deepin in source.list
            sudo vi /etc/apt/souces.list
            
            deb http://packages.linuxdeepin.com/deepin trusty main non-free universe
            deb-src http://packages.linuxdeepin.com/deepin trusty main non-free universe
            
  2. Delete GPG key of Deepin
            sudo apt-key list | grep 209088E7  #this is the id of the key which was imported when I install Deepin
            #make sure the result of grep is not empty
            #or you don't have to do the removing
            sudo apt-key del 209088E7
            
  3. Reinstall Unity
            sudo apt-get update
            sudo apt-get install --reinstall ubuntu-desktop
            sudo apt-get install unity
            

Reboot. Then the unity is recovered.

But there is another problem, I cannot open my software-center !!

I tried to reinstall it but saw something like this

Traceback (most recent call last):
File &amp;quot;/usr/bin/software-center&amp;quot;, line 149, in &amp;lt;module&amp;gt;
from softwarecenter.ui.gtk3.app import SoftwareCenterAppGtk3
File &amp;quot;/usr/share/software-center/softwarecenter/ui/gtk3/app.py&amp;quot;, line 49, in &amp;lt;module&amp;gt;
from softwarecenter.db.application import Application
File &amp;quot;/usr/share/software-center/softwarecenter/db/application.py&amp;quot;, line 25, in &amp;lt;module&amp;gt;
from softwarecenter.backend.channel import is_channel_available
File &amp;quot;/usr/share/software-center/softwarecenter/backend/channel.py&amp;quot;, line 25, in &amp;lt;module&amp;gt;
from softwarecenter.distro import get_distro
File &amp;quot;/usr/share/software-center/softwarecenter/distro/__init__.py&amp;quot;, line 165, in &amp;lt;module&amp;gt;
distro_instance=_get_distro()
File &amp;quot;/usr/share/software-center/softwarecenter/distro/__init__.py&amp;quot;, line 148, in _get_distro
module = __import__(distro_id, globals(), locals(), [], -1)
ImportError: No module named Deepin

Think about the weird system version I saw on tty terminal. The release version of the System was changed while installing the Deepin

Open lsb-release

sudo vi /etc/lsb-release

I found out that the DISTRIB_ID and other things was become Deepin associative

Change it to the default of Ubuntu 14.04.1 LTS which is listed below

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

Change the /etc/issue to correct the system version prefix on tty ternimal

sudo vi /etc/issue

to

Ubuntu 14.04.1 LTS \n \l

Now reinstall the software-center

sudo apt-get autoremove software-center
sudo apt-get install software-center

And reboot

Now the software-center is recovered.

At last, let’s clean the annoying “System program problem detected” popup window

sudo rm /var/carsh/*

Done !!

BTW, I would appreciate if anyone could tell me how to install the Deepin Desktop on Ubuntu 14.04.

How To Fix: Android Studio Cannot Run app after Moving the Project Directory

At first, I created a project under one directory, but I move it to a different directory which is a git directory.

But the when I opened it again, a red cross come out on the “app” which is beside the button of “run” on my Android Studio.

When I push the “run”, I got this

which was caused by wrong configuration of Project Directory of IntelliJ or Gradle.

So just click the Gradle Sync icon and it will work again.

You can also use this Sync button to resolve many other unsync problems such as Project name modification and etc.

Thx to this question on stackoverflow to help me out

BTW, Wish our team have good luck on tomorrow and day after tomorrow !!

Migrate Ubuntu 14.04 from HDD to SSD

I hate to reinstall OS and set up the environment again and again. So it would be awesome if I could migrate my entire Ubuntu from an old HDD to my new SSD.

After googling a find a very specific guide to tell you how to do it.
Migrate from a HDD to a SSD hard disk

The general steps are listed below

  1. Plug SSD to the running system through a USB-SATA or SATA
  2. Find the device name
    $ dmesg | grep sd[a-z]
    
  3. Use gparted to format the SSD
    $ sudo gparted /dev/sdX
    

    The partition of ex4 for / and swap is recommanded

  4. Mount the SSD

    $ sudo mkdir /mnt/ssd
    $ sudo mount /dev/sdc1 /mnt/ssd/

  5. Use rsync to sync the file.
    $ rsync --exclude="mnt" --exclude="lost+found" --exclude="sys" --exclude="proc" --exclude="cdrom" --exclude="media" -aP / /mnt/ssd/
    $ mkdir /mnt/ssd/{mnt,proc,sys}
    
  6. Change the /mnt/ssd/etc/fstab to set the UUID to the SSD partition
    You can find the UUIDs of the partition of SSD by

    $ sudo blkid /dev/sdX1
    $ sudo blkid /dev/sdX2	
    

    Your fsatb should look likt this:

            # file system		mount point	type  	options						dump	pass
            proc			/proc           proc    nodev,noexec,nosuid				0       0
    	UUID=5d8[...]abe	/               ext4    discard,noatime,nodiratime,errors=remount-ro	0       1
    	UUID=a01[...]4cc	none            swap    sw
    
  7. Install grub
            
            $ sudo mount -o bind /dev	/mnt/ssd/dev 
    	$ sudo mount -o bind /sys 	/mnt/ssd/sys 
    	$ sudo mount -t proc /proc	/mnt/ssd/proc
    	$ sudo cp /proc/mounts /media/SSD/etc/mtab
    	$ sudo chroot /media/SSD /bin/bash
    	$ grub-install /dev/sdc
    	$ grub-install --recheck /dev/sdc		# only in case of errors in the step before
    	$ update-grub 
    
  8. Reboot your PC and enjoy!

I installed the Ubuntu 14.04 with Windows 8 on my original HDD booted by grub. And after the migration, I have the exactly same Ubuntu on SSD and the Windows 8 on HDD can be booted gracefully too!!

Create and Save the resolution mode on Ubuntu 14.04

When I plugged in another monitor on my PC these days, I couldn’t find the correct resolution mode in “System Settings” of my Ubuntu 14.04. It shows that it’s an unknown display device.

So I tried to set the resolution mode manually.

  1. Get the device name of monitor
    Type

                    sudo xrandr
                    

    in the shell
    And you will get something like

                    Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 16384 x 16384
                    HDMI-0 disconnected (normal left inverted right x axis y axis)
                    DVI-0 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 510mm x 290mm
                       1920x1080      60.0*+
                       1680x1050      59.9  
                       1280x1024      75.0     60.0  
                       1280x960       60.0  
                       1152x864       75.0  
                       1024x768       75.1     60.0  
                       832x624        74.6  
                       800x600        75.0     60.3     56.2  
                       640x480        75.0     60.0  
                       720x400        70.1  
                    VGA-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
                       1024x768       60.0*  
                       800x600        60.3     56.2  
                       848x480        60.0  
                       640x480        59.9  
                    

    The phrase in capital letter is your devices name.
    For example VGA-0
    The list of numbers below it is the resolution mode the device supports.
    A * means the device is working under this mode.
    A + means the device prefers to working under this mode.
    As you can see, there is no 1920×1080 mode in my VGA-0 list.

  2. Find out what the resolution mode you want. Then you can type

    	        cvt 1920 1080   #I will take 1920*1080 as an example here
    	        

    in shell. And you will get something like

    	        # 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
                    Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
    	        

    Write down the Modeline

  3. Tpye

                    sudo xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync #Here is the Modeline you get from cvt
                    sudo xrandr --addmode VGA-0 "1920x1080_60.00"   #I will take the VGA-0 for example
                    
  4. After these steps, you can find the “1920×1080” Option in your System Setting
    Choose this one to preview the result.

Now it’s time to make these change permanently

  1. Create a shell script and save

                    sudo xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync #Here is the Modeline you get from cvt
                    sudo xrandr --addmode VGA-0 "1920x1080_60.00"   #I will take the VGA-0 for example
                    

    in it.
    Make it runnable !

  2. Add this line to /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf

                    session-setup-script=/your/runnable/script.sh   #Filled with the script location you created above
                    

Now you can reboot and the Unity will remeber what you want!