2014-07-31

How to set Komodo Edit as Go IDE with komodo-go

LiteIDE 23.1 is the quite good enough IDE for Go in my opinion, the autocomplete and method hint works fine. All we need after installing is just configure the Environment file (View > Edit Environment) such as this:

GOROOT=/usr/lib/go
GOBIN=/home/kyz/Dropbox/go/bin

Don't forget to change the ownership or you won't able to save:

sudo chown `whoami` /usr/share/liteide/liteenv/*

Also don't forget to add custom GOPATH (View > Manage GOPATH..) if necessary


But sometimes the jump to declaration feature doesn't work at all.
There are another alternative that is komodo-edit, you can install it using:

pacman -Sy komodo-edit

Then you could clone the komodo-go repository:

cd /tmp
git clone https://github.com/Komodo/komodo-go
cd komodo-go

Make sure that you have installed Python 2.x, and then just built the extension

/opt/komodo-edit/lib/sdk/bin/koext build

Then drag the .xpi file into Komodo Extension Manager.
Now, install godef to make it support jump to declaration command:

go get -u -v code.google.com/p/rog-go/exp/cmd/godef

Now your komodo-edit with Go integration will work as expected.



2014-07-30

Tracking or auditing Linux configuration changes

As a paranoid user, we sometimes want to know what configuration changed since we install something or upgrading using apt-get upgrade or pacman -Syu. We can use git to track changes in our filesystem, for example:

cd /
sudo git init .

create .gitignore file containing, for example:

/bin
/boot
/dev
/lib
/lib64
/media
/proc
/root
/run
/sbin
/sys
/tmp
/usr

/opt
/var

/etc/ld.so.cache

/home/whoami/.cache
/home/whoami/.xsession-errors
/home/whoami/.viminfo
/home/whoami/.bash_history
/home/whoami/.wine
/home/whoami/.config/pulse
/home/whoami/.gstreamer-0.10
/home/whoami/.local/share/recently-used.xbel
/home/whoami/.local/share/gvfs-metadata


and then just add it to our repository:

git add .
git commit -m 'initial filesystem'

After that, just run the package manager's upgrade system command. When there are changes, we could see which files/folders that changed, by typing:

git status




And see the changes for one file:

git diff /path/to/file



This trick also can be used to track history or backup your system's configuration, just use private repository on bitbucket.


Easier ArchLinux-based Distribution

So, maybe you're a newbie who wants to use ArchLinux, but scared with it's installation, well well, we have some ArchLinux-based distribution for you from:
Honorable mention was Manjaro Linux, I've used this before for my netbooks, and it works really fine, easy installation, xfce4 and yaourt installed by default. Next time I probably will try Antergos or BlackArch. I will not try Chakra since its uses KDE as default desktop environment, from my experince using KDE-based distribution (and KDE apps), most of them are slow and crashes a lot.

Maybe some poeple ask, why ArchLinux or Arch-based distribution? well.. because it's easy to install almost anything, easy (automated) to build programs from source via AUR. Why I chose ArchLinux? Umm.. because I'm hipster XD (Ubuntu, Mint, Debian, Fedora, Zorin, PCLinuxOS, CentOS are too mainstream). Things to read or consider before migrating or decide using ArchLinux:
Here's my current desktop using Manjaro:


2014-07-28

Xfce4 CPU, RAM, Network and Disk Monitoring Applet

When using Gnome or Xfce4, I always have the urge to monitor CPU, RAM, network and disk usage/throughput. This is the screenshot of my xfce4 panel:


To make it happened, I modified Ciriaco's source code to suit my need:

curl -L http://goo.gl/MO3lx5 > netmon.cpp
g++ -O3 -lrt netmon.cpp -o netmon
sudo mv netmon /usr/bin/

So when netmon program executed, it would give an XML ouput (note that enp1s0 is my network interface name):

netmon enp1s0 
<txt>D:   312 KB/s  | U:    15 KB/s  | CPU:  12% | RAM:  7008 MB | sdc:   .   . | sda:   .   . | sdb:   .   1 | sdf:   .   . | sde:   .   . | sdd:   .   . | sdg:   .   .</txt><tool> enp1s0:
    3102.07 MB received 
    261.08 MB sent 
 CPU usage:
     15.6% since boot 
 RAM usage:
     45.4% of 15436 MB</tool>

The next step is installing Generic Monitor Applet:

yaourt -Sy xfce4-genmon-plugin

Add it to your panel (right click on panel > Panel > Add New Item..), and configure it:

And your CPU, RAM, network and disk is now appeared on the panel ^_^)b

Disk monitoring notes:

  • dot means idle
  • zero means <1MB/s read/write
  • others in MB/s

ArchLinux Installation Tutorial

ArchLinux is top 10 major Linux binary-based distribution, but in my opinion, it has the easiest source-based installation process. Here's my past experience of minimal installation process:

First, download latest .iso from https://www.archlinux.org/download/
You may want to burn it or dump to USB flashdrive using this command:

dd bs=4M if=/path/to/archlinux-yyyy.mm.dd-dual.iso of=/dev/your_usb_disk

the /dev/your_usb_disk could be found using dmesg or lsblk or gparted command, for example /dev/sdg

Things to do after preparing the boot CD/USB:

1. Boot your PC using that USB or CD/DVD.

2. Find out which partition or disk to be the installation target, normally I only create 1 or 2 partition that is / (root) for software and /home.

lsblk # find disk name
disk=/dev/vda

Create partition using cfdisk command, set bootable, set partition type (83), write and quit.

cfdisk $disk 

Format partitions and mount it:

part=/dev/vda1
mkfs.ext4 $part
mount $part /mnt

3. Update repository, bootstrap and chroot, this process requires internet, make sure you're connected to the internet using DHCP cable connection.

pacman -Syy
pacstrap -i /mnt base base-devel vim bash openssh curl
genfstab -U -p /mnt >> /mnt/etc/fstab
arch-chroot /mnt

4. Configure language, I always prefer Canada and Indonesia, not US.

bash
loadkeys us

Uncomment en_CA.UTF-8 and id_ID.UTF-8, using vim or nano

vim /etc/locale.gem 
locale-gen
export LANG=en_CA.UTF-8

5. Configure time, for example: Jakarta, Indonesia

location=/usr/share/zoneinfo/Asia/Jakarta
ln -s $location /etc/localtime
hwclock --systohc --utc

Clock correction:

current="2014-07-28 21:15:00"
date -s "$current"

6. Change name, use Google DNS, configure network and enable SSH

echo 'your_hostname' > /etc/hostname
echo nameserver 8.8.8.8 > /etc/resolv.conf
systemctl enable sshd

Uncomment PermitRootLogin yes:

vim /etc/ssh/sshd_config 

Check your network device name, could be eno11, eth0, enp1s0, wlp2s1, or anything else.

ip link
dev=eno1

6a. For permanent DHCP

systemctl enable dhcpcd@$dev

6b. For static address

addr=192.168.20.41
nmask=24
bcast=192.168.20.255
gw=192.168.20.1

6b1. for permanent static address

echo "address=$ipaddr
netmask=$nmask
broadcast=$bcast
gateway=$gw
" > /etc/conf.d/network@interface
curl -L 'http://goo.gl/X8d8k9' > /etc/systemd/system/network@.service
systemctl enable network@$dev

6b2. For temporary static address (gone when reboot)

ip link set dev $dev up
ip addr add $addr/$nmask broadcast $bcast dev $dev
ip route add default via $gw

7. Enable 32-bit repository and set password

vim /etc/pacman.conf # uncomment multilib section
pacman -Sy
passwd # remember!

8. Install and configure bootloader, this part really complicated when you're using UEFI BIOS

pacman -S grub-bios os-prober
grub-install --recheck /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg

9. reboot

exit
exit
reboot


Things to do after reboot:

1. Install yaourt, one of the easiest way to use AUR

echo '
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
' >> /etc/pacman.conf
pacman -Syy
pacman -Sy yaourt

2. Install desktop environment, one of the lightest DE is Xfce4

pacman -S xfce4 xfce4-goodies gvim gnome-tweak-tool xfwm4 metacity firefox yakuake

3. Install graphic card drivers, this part not required when using intel

# for Nvidia
pacman -Sy xf86-video-nouveau nouveau-dri lib32-nouveau-dri
modprobe nouveau 

# for AMD/ATI
yaourt -Sy catalyst-hook catalyst-libgl catalyst-utils lib32-catalyst-utils lib32-opencl-catalyst opencl-catalyst 

Then reboot or try to start Xserver, see the /var/log/Xorg.0.log file when error

echo exec startxfce4 > ~/.xinitrc
startx

4. Add another admin user

usrnm=your_username
useradd -m -g users -G wheel -s /usr/bin/bash $usrnm
passwd your_username
echo "
%wheel ALL=(ALL) ALL
Defaults:$usrnm timestamp_timeout=86400
" >> /etc/sudoers

5. Install browsers, tools, etc

yaourt --needed --noconfirm -S --force google-chrome chromium traceroute net-tools vlc smplayer sshfs meld gedit bash-completion htop

And so on~ :3

Installing HHVM on Ubuntu or ArchLinux

As we already know, HHVM is the fastest PHP interpreter/JIT-compiler for 64-bit systems. To install HHVM on Ubuntu, the easiest way is use the PPA using these commands:

# install HHVM repos' public key
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -

# add HHVM repos
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list

# update list of available software
sudo apt-get update

# install hhvm
sudo apt-get install hhvm

Or when using archlinux, use yaourt command (warning: this would compile the hhvm package, that requires about ~1 hour and more than 2GB of RAM, so add a virtual memory if your RAM not big enough)

sudo yaourt --needed --noconfirm -S --force hhvm

As we already know, since PHP 5.4, PHP can be used without installing any webserver (Apache, Nginx, IIS), use this command to run built-in web server on localhost:8083:

hhvm -m server -p 8083
mapping self...
mapping self took 0'00" (18015 us) wall time
loading static content...
loading static content took 0'00" (0 us) wall time
page server started
all servers started

or when using standard PHP:

php -S localhost:8083
PHP 5.5.15 Development Server started at Mon Jul 28 20:48:06 2014
Listening on http://localhost:80803
Document root is /tmp
Press Ctrl-C to quit.

Create swap file or virtual memory without partition

In my experience, Linux is an OS that quite require much RAM, especially for running software that was should be executed using Virtual Machines. When our programs using more than available memory, the OS will be unresponsive, to solve those problem, we could virtually add more RAM using disk. Here's some example to add 8GB swapfile to our system:

# create new file on "/swapfile" with size 1MB * 8192 = 8GB
sudo dd if=/dev/zero of=/swapfile bs=1048576 count=8192

# format the newly created file as swap and give correct permissions
sudo mkswap /swapfile
sudo chmod 0600 /swapfile

# enable swap temporarily (swap will be gone when computer restart)
sudo swapon /swapfile

# add configuration on fstab to enable swap on boot
sudo echo /etc/fstab | sudo tee -a /swapfile swap swap defaults 0 0

to check swap usage, use free -m command. 

Installing Ruby 2.1+ on Ubuntu (via RVM)

On some distro, Ruby interpreter was out of date

apt-cache show ruby2.0 | grep Version
Version: 2.0.0.484-1ubuntu2

And we want the latest version, we could use Brightbox's PPA:

# install add-apt-repository command
sudo apt-get install software-properties-common python-software-properties

# add brightbox's repository
sudo apt-add-repository ppa:brightbox/ruby-ng

# update list of available software
sudo apt-get update

# install ruby
sudo apt-get install ruby2.1

Or use RVM, the Ruby Version Manager, that could be installed using these commands:

# install rvm
curl -sSL https://get.rvm.io | bash

# use rvm (or relogin/restart bash, since it's inserted into .bashrc)
source /etc/profile.d/rvm.sh

to see the list of available version, we could use:

rvm list known

to install the latest version, run this command:

rvm install ruby-2.1.2
ruby-2.1.2 - #removing src/ruby-2.1.2..
ruby-2.1.2 - #removing rubies/ruby-2.1.2..
Searching for binary rubies, this might take some time.
Found remote file https://rvm.io/binaries/ubuntu/14.04/x86_64/ruby-2.1.2.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.1.2 - #configure
ruby-2.1.2 - #download
######################################################################## 100.0%
ruby-2.1.2 - #validate archive
ruby-2.1.2 - #extract
ruby-2.1.2 - #validate binary
ruby-2.1.2 - #setup
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2@global
ruby-2.1.2 - #importing gemset /usr/local/rvm/gemsets/global.gems....................................
ruby-2.1.2 - #generating global wrappers........
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2
ruby-2.1.2 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.1.2 - #generating default wrappers........
Making gemset ruby-2.1.2 pristine.............................................................
Making gemset ruby-2.1.2@global pristine..............................................................


Voila, done! now we could use it using this command:

rvm use ruby-2.1.2 

ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

gem install pry
Fetching: coderay-1.1.0.gem ( 52%)
Fetching: coderay-1.1.0.gem (100%)
Successfully installed coderay-1.1.0
Fetching: slop-3.6.0.gem (100%)
Successfully installed slop-3.6.0
Fetching: method_source-0.8.2.gem (100%)
Successfully installed method_source-0.8.2
Fetching: pry-0.10.0.gem (100%)
Successfully installed pry-0.10.0
invalid options: -SNw2
(invalid options are ignored)
Parsing documentation for coderay-1.1.0
Installing ri documentation for coderay-1.1.0
Parsing documentation for method_source-0.8.2
Installing ri documentation for method_source-0.8.2
Parsing documentation for pry-0.10.0
Installing ri documentation for pry-0.10.0
Parsing documentation for slop-3.6.0
Installing ri documentation for slop-3.6.0
Done installing documentation for coderay, method_source, pry, slop after 4 seconds
4 gems installed




Installing Go 1.3+ on Ubuntu via GVM (Go Version Manager)

Sometimes on some Linux distribution, the Go package are out of date, for example:

apt-cache show golang | grep Version
Version: 2:1.2.1-2ubuntu1

and we look for the PPA (user repository) but failed to see the latest version!
One solution that we could use is using GVM that could be installed using this command:

# install dependencies
sudo apt-get install curl git mercurial make binutils bison gcc

# install gvm
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

# use gvm (or relogin/restart bash, since it's inserted into .bashrc)
source ~/.gvm/scripts/gvm

to see the list of available version, we could use:

gvm listall

to install Go 1.3, we could use this command:

gvm install go1.3
Installing go1.3...
 * Compiling...

Voila, done! now we could use it using this command:

gvm use go1.3
Now using version go1.3
go version
go version go1.3 linux/amd64


Keep commands even when SSH disconnected (byobu)

Sometimes we need to run a command over SSH, but when SSH session disconnected that command will be also terminated. There are some solution to overcome this, that is create a service, nohup or use terminal multiplexer such as screen or byobu. Using Byobu, you can run multiple commands using single SSH session, the terminal that shown will be appear exactly the same over multiple computer that connected as the same user. To install byobu you can run this command on Ubuntu:

sudo apt-get install byobu

or when using ArchLinux:

sudo pacman -Sy byobu

There are some important shortcut to remember:

  • F2 to create tab (or subsession)
  • F3 to switch to previous tab
  • F4 to switch to next tab
  • F6 to exit from byobu, but the commands would keep running, type byobu on shell to get back to last session
  • shift+F2 to split horizontally
  • ctrl+F2 to split vertically
  • shift+F3/F4 to switch between split region
  • ctrl+F3/F4 to swap between split region
  • alt+PgUp/PgDn to enter scrollback mode (not shift+PgUp/PgDn like normal terminal)
Here's some screenshot about Byobu in action: