2014-11-26

How to start Martini Golang Project

Martini is another Golang web framework, that the design similar to Sinatra, to install it, just type this command:

go get -u -v github.com/go-martini/martini

Then, just create new source code, for example main.go:

package main
import "github.com/go-martini/martini"
func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"
  })
  m.Run()
}

To run the website, just type:

go run main.go

Then visit http://localhost:3000/

We must recompile the source everytime the source code changed, that quite annoying and time consuming, to overcome that problem we could use a tool called gin, this program automatically run a program everytime there are code changed. To install this tool, type:

go get -u -v github.com/codegangsta/gin

Then run it using this command:

gin go run main.go

That command would create a proxy, if there are compilation errors, it would also show on the page.

How to install Goclipse and Golang IDEA plugin

Warning: current master version of these plugins (2014-11-25) are not good enough for daily coding, don't bother to try them for now.
Edit: latest alpha version of Golang IDEA plugin for IntelliJ are the best plugin for now.

Goclipse is another IDE for golang, that based on the infamous Eclipse platform. To install Eclipse, just type:

pacman -S eclipse

To install Goclipse, you must first clone the repository, for example using this command:

git clone --depth 1 https://github.com/GoClipse/goclipse.git

Then you must download all dependencies and start building:

cd goclipse
mvn clean integration-test
ant -f releng/ CreateProjectSite
ant -f releng/ PublishProjectSite

Last command would fail when not supplied with correct DprojectSiteGitURL parameter, but the required jars still resides in bin-maven/projectSite/, just use any webserver to serve the files as Eclipse update site, for example using php:

cd bin-maven/projectSite/
php -S localhost:9009

To install Goclipse, open Eclipse, Help > Install New Software..,  just add http://localhost:9009/releases

Then select Goclipse, next, accept the license, and finish.

Now the bad parts: bad coloring (for example, the operator color is not configurable), gocode doesn't work (even when GOPATH and GOROOT already configured on settings page and restarted), and autocomplete doesn't work at all.

Next we'll try IntelliJ with Golang IDEA plugin, first you must clone the repository:

git clone --depth 1 https://github.com/go-lang-plugin-org/go-lang-idea-plugin.git

Then place (or symlink) the IntelliJ program directory inside that folder that created by git, with name idea-IC, then just run:

ant -f build-package.xml

That command would produce a file named: google-go-language.jar, just install that plugin normally using on IntelliJ.

Now the bad parts: member autocomplete doesn't work at all (even when GOROOT and GOPATH configured on settings page and restarted).



2014-11-25

Wide: Web-based IDE for Go

Wide is one new web-based IDE, it has a lot of potential, for now, it has autocomplete and one that have working "go to definition".

To install Wide, type:

go get -u -v github.com/88250/ide_stub
go get -u -v github.com/nsf/gocode
go get -u -v github.com/b3log/wide

To start the program, type:

cd $GOPATH/src/github.com/b3log/wide/
wide

Then visit using your browser on http://your_ip_address:7070


There are some other web-based IDE such as GoDev (lags when showing godoc), LimeText, Carpo, Atom (aur/atom-editor-bin), Brackets.io, and Conception-go (this one not a web-based :3 it's OpenGL)
Btw, I make a list on GoogleDocs to list all Go IDEs, you can contribute/edit it if you want..

2014-11-24

Database GUI for MongoDB

There are many database GUI for MongoDB, today I will review about GenghisApp, Humongous, and RoboMongo.

You could install the Ruby-based one using this command:

gem install humongous
gem install genghisapp bson_ext

to start it, use this command:

humongous # visit http://localhost:9000
genghisapp # visit http://localhost:8000
php -S localhost:8000 genghis.php # php version

to stop it, use this command:

humongous -K
genghisapp --kill

I don't know why but when I tried both, they are not running at all, just stopped after showing "trying port xxxx", those programs closes immediately after that, the program doesn't show up on ps and netstat.

The next in line is RoboMongo, first, you must download using this command:

wget -c http://robomongo.org/files/linux/robomongo-0.8.4-x86_64.tar.gz

Extract it, then run the robomongo.sh shell script on the bin/ folder, set the connection, then it would show up something like this:


This one quote good, it shows the command line when doing any action, but as usual, Java-based app doesn't work well with dark GTK+ theme.

There are some other GUI for MongoDB that support live-monitoring, for example MongoBird and MongOwl, but don't forget, there are also built-in web monitoring on port 28017.

2014-11-15

How to Prevent ISP's DNS Poisoning

The case was, my fourth ISP redirect every DNS request to their own DNS servers, and the poison certain domain names (for example: Manga sites) to their own server (114.127.223.16). How to prevent this? first of all you'll need to install dnscrypt, this program could encrypt DNS requests, so it's become harder to poison.

pacman -Sy dnscrpyt-proxy

then you'll need to start the service:

sudo systemctl enable dnscrypt-proxy
sudo systemctl start dnscrypt-proxy

then, change your /etc/resolv.conf to localhost:

nameserver 127.0.0.1

voila, now your DNS resolving not poisoned anymore :3 yayy~

2014-11-04

How to start Revel, GORM with PostgreSQL project on Archlinux

Revel is one of many Go Web Application Framework that uses Go programming language. After installing Archlinux, first of all you'll need to install yaourt, the easiest way to install AUR packages. After that you'll need to run this command:

yaourt -Sy --noconfirm go postgresql postgresql-libs liteide chromium google-chrome-stable

Then setup your GOPATH and GOROOT environment variables on your .bashrc

export GOROOT=/usr/lib/go
export GOPATH=$HOME/Dropbox/go
export PATH="$PATH:$GOPATH/bin"


Change the permission of this folder:

sudo chmod -Rv a+rwx /usr/share/liteide/liteenv

Then open LiteIDE, select menu View > Edit Environment, then add this line and save:

GOROOT=/usr/lib/go

Add also a GOPATH directory on menu View > Manage GOPATH...
That is ~/Dropbox/go on my computer.

To test if your Go and LiteIDE working correctly, create a new .go file and press Build > FileRun to run, for example:

package main
import "fmt"
func main() {
  fmt.Println("Hello my PC <3")
}

The code above should give an output on Build output window.

To install revel, type this on shell:

go get -u -v github.com/revel/cmd/revel
go get -u -v github.com/revel/revel


To create a new project (for example, the name would be "puis"), type:

cd $GOPATH
revel new puis

Then you could start the app using this command:

revel run puis

And visit http://localhost:9000 to view your app.

Next, we should install PostgreSQL driver and GORM, type:

go get -u -v github.com/lib/pq
go get -u -v github.com/jinzhu/gorm

Then initialize and start your database server:

sudo su - postgres
initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
exit
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo su - postgres
createuser puis
createdb puis
psql 
GRANT ALL PRIVILEGES ON DATABASE puis TO puis;
\q
exit

Then create a model, for example in app/models/user.go

package models
import "time"
type User struct {
  Id                int64
  Name              string
  Gmail             string
  PuMail            string
  Password          string
  CreatedAt         time.Time
  UpdatedAt         time.Time
  DeletedAt         time.Time
  LastLoginAt       time.Time
  PasswordUpdatedAt time.Time
}

And create a controller for GORM in app/controllers/gorm.go

package controllers
import (
  "database/sql"
  "github.com/jinzhu/gorm"
  _ "github.com/lib/pq"
  "github.com/revel/revel"
  "puis/app/models"
)
type GormController struct {
  *revel.Controller
  Tx *gorm.DB
}
var Db gorm.DB
func InitDB() {
  var err error
  Db, err = gorm.Open("postgres", "user=puis sslmode=disable")
  if err != nil {
    revel.ERROR.Println("FATAL", err)
    panic(err)
  }
  tab := &models.User{}
  Db.AutoMigrate(tab)
  Db.Model(tab).AddUniqueIndex("idx_user__gmail", "gmail")
  Db.Model(tab).AddUniqueIndex("idx_user__pu_mail", "pu_mail")
}
func (c *GormController) Begin() revel.Result {
  txn := Db.Begin()
  if txn.Error != nil {
    panic(txn.Error)
  }
  c.Tx = txn
  revel.INFO.Println("c.Tx init", c.Tx)
  return nil
}
func (c *GormController) Commit() revel.Result {
  if c.Tx == nil {
    return nil
  }
  c.Tx.Commit()
  if err := c.Tx.Error; err != nil && err != sql.ErrTxDone {
    panic(err)
  }
  c.Tx = nil
  revel.INFO.Println("c.Tx commited (nil)")
  return nil
}

func (c *GormController) Rollback() revel.Result {
  if c.Tx == nil {
    return nil
  }
  c.Tx.Rollback()
  if err := c.Tx.Error; err != nil && err != sql.ErrTxDone {
    panic(err)
  }
  c.Tx = nil
  return nil
}

Also call those functions when application starts also before and after controller calling, add these lines in app/init.go on func init()

revel.OnAppStart(controllers.InitDB)
revel.InterceptMethod((*controllers.GormController).Begin, revel.BEFORE)
revel.InterceptMethod((*controllers.GormController).Commit, revel.AFTER)
revel.InterceptMethod((*controllers.GormController).Rollback, revel.FINALLY)

Two more things, add a testing code, for example in app/controllers/app.go on func Index()

user := &models.User{Name: "Kiswono Prayogo"}
c.Tx.NewRecord(user)
c.Tx.Create(user)
return c.Render(user) 

Last thing, just add one more line anywhere on Index.html

{{.user.Name}}

That's it, this is how to connect Revel to PostgreSQL using GORM. This tutorial adapted from Ivan Black's stackoverflow answer.

To solve slow Revel hot-reload or Go build/install, just use this command:

go get -u -v github.com/mattn/go-sqlite3

2014-08-23

How to change resolution that doesn't exists on display settings on Linux

Sometimes we need to change the resolution of our monitor, but the resolution doesn't show up on the xfce4-display-settings, what should we do? First you'll need a terminal or command prompt, then type cvt or gtf command with your desired resolution, for example:

cvt 1920 1080 

it would show something like this:

# 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

now, you should add it using xrandr command:

xrandr --newmode "1920x1080"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

now, assign it the desired display port from the graphics card, first let see our graphic card available ports, type xrandr again without parameter, it would show something like this:

Screen 0: minimum 8 x 8, current 1600 x 1200, maximum 32767 x 32767
VGA1 connected primary 1600x1200+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768      70.07 +  85.00    75.08    60.00 
   1600x1200     60.00* 
   1280x1024     85.02    75.02 
   1440x900      59.89
   1280x960      85.00
   1280x800      59.81
   1152x864      75.00 
   1024x768      86.96 
   832x624       74.55
   800x600       85.06    72.19    75.00    60.32    56.25 
   640x480       85.01    75.00    72.81    66.67    60.00
   720x400       87.85    70.08
HDMI1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
  1920x1080 (0x2ee) 173.000MHz
    h: width  1920 start 2048 end 2248 total 2576 skew 0 clock  67.16KHz
    v: height 1080 start 1083 end 1088 total 1120 clock  59.96Hz

Now we know that we have 3 ports: VGA1, HDMI1 and VIRTUAL1, of course the current monitor was plugged into VGA1 because it shows "connected", now we could assign using this command:

xrandr --addmode VGA1 1920x1080 

and set the display resolution using this command:

xrandr --output VGA1 --mode 1920x1080

Voila, now your resolution changed!

Note: if you're using VGA Video Splitter, make sure that the monitor plugged into the first port, so it would send correct EDID.

SLock simplest screen locker ever!

SLock is the simplest screen locker ever, it works without hassle or configuration. If you havent isntall any of screensaver (gnome-screensaver, xscreensaver), you could use it as the default screensaver. B-b-b-but how to unlock the screen? there's no password box to type '____' ?

You just need to type your password (screen would change color as you type first letter) and press enter to unlock the screen.

What if I have inputted wrong password? just press backspace or enter to restart inputting the password.

How to lock the screen? just type slock on terminal or run-dialog.

Well.. that's all for now~

Where to put fonts on Linux

To install fonts on Linux (especially Arch Linux), you must copy the fonts on the ~/.local/share/fonts folder (for old distribution, use ~/.fonts directory). To view fonts, install gnome-font-viewer, that program could also be used to install fonts locally. I have selected some fonts that good for programming imho. Contact me (if you can ^^ myahahah!) if the server is down or expired, or just google for these fonts:

BPmono.ttf BPmonoBold.ttf BPmonoItalics.ttf DejaVuSans-Bold.ttf DejaVuSans-BoldOblique.ttf
DejaVuSans-ExtraLight.ttf DejaVuSans-Oblique.ttf DejaVuSans.ttf DejaVuSansCondensed-Bold.ttf DejaVuSansCondensed-BoldOblique.ttf
DejaVuSansCondensed-Oblique.ttf DejaVuSansCondensed.ttf DejaVuSansMono-Bold.ttf DejaVuSansMono-BoldOblique.ttf DejaVuSansMono-Oblique.ttf
DejaVuSansMono.ttf DejaVuSerif-Bold.ttf DejaVuSerif-BoldItalic.ttf DejaVuSerif-Italic.ttf DejaVuSerif.ttf
DejaVuSerifCondensed-Bold.ttf DejaVuSerifCondensed-BoldItalic.ttf DejaVuSerifCondensed-Italic.ttf DejaVuSerifCondensed.ttf DroidSansMono.ttf
Envy Code B 10pt.ttf Envy Code R Bold.ttf Envy Code R Italic.ttf Envy Code R VS Italic-as-bold.ttf Envy Code R VS.ttf
Envy Code R.ttf FantasqueSansMono-Bold.ttf FantasqueSansMono-BoldItalic.ttf FantasqueSansMono-RegItalic.ttf FantasqueSansMono-Regular.ttf
FiraMono-Bold.ttf FiraMono-Medium.ttf FiraMono-Regular.ttf FiraSans-Bold.ttf FiraSans-BoldItalic.ttf
FiraSans-Book.ttf FiraSans-BookItalic.ttf FiraSans-Eight.ttf FiraSans-EightItalic.ttf FiraSans-ExtraBold.ttf
FiraSans-ExtraBoldItalic.ttf FiraSans-ExtraLight.ttf FiraSans-ExtraLightItalic.ttf FiraSans-Four.ttf FiraSans-FourItalic.ttf
FiraSans-Hair.ttf FiraSans-HairItalic.ttf FiraSans-Heavy.ttf FiraSans-HeavyItalic.ttf FiraSans-Italic.ttf
FiraSans-Light.ttf FiraSans-LightItalic.ttf FiraSans-Medium.ttf FiraSans-MediumItalic.ttf FiraSans-Regular.ttf
FiraSans-SemiBold.ttf FiraSans-SemiBoldItalic.ttf FiraSans-Thin.ttf FiraSans-ThinItalic.ttf FiraSans-Two.ttf
FiraSans-TwoItalic.ttf FiraSans-Ultra.ttf FiraSans-UltraItalic.ttf FiraSans-UltraLight.ttf FiraSans-UltraLightItalic.ttf
LiberationMono-Bold.ttf LiberationMono-BoldItalic.ttf LiberationMono-Italic.ttf LiberationMono-Regular.ttf LiberationSans-Bold.ttf
LiberationSans-BoldItalic.ttf LiberationSans-Italic.ttf LiberationSans-Regular.ttf LiberationSerif-Bold.ttf LiberationSerif-BoldItalic.ttf
LiberationSerif-Italic.ttf LiberationSerif-Regular.ttf MesloLGLDZ-Bold.ttf MesloLGLDZ-BoldItalic.ttf MesloLGLDZ-Italic.ttf
MesloLGLDZ-Regular.ttf MesloLGMDZ-Bold.ttf MesloLGMDZ-BoldItalic.ttf MesloLGMDZ-Italic.ttf MesloLGMDZ-Regular.ttf
MesloLGSDZ-Bold.ttf MesloLGSDZ-BoldItalic.ttf MesloLGSDZ-Italic.ttf MesloLGSDZ-Regular.ttf Monaco.ttf
PTM55F.ttf PTM75F.ttf VeraMono-Bold-Italic.ttf VeraMono-Bold.ttf VeraMono-Italic.ttf
VeraMono.ttf drucifer_0.ttf drucifer_i.ttf edlo.ttf mplus-1c-black.ttf
mplus-1c-bold.ttf mplus-1c-heavy.ttf mplus-1c-light.ttf mplus-1c-medium.ttf mplus-1c-regular.ttf
mplus-1c-thin.ttf mplus-1m-bold.ttf mplus-1m-light.ttf mplus-1m-medium.ttf mplus-1m-regular.ttf
mplus-1m-thin.ttf mplus-1mn-bold.ttf mplus-1mn-light.ttf mplus-1mn-medium.ttf mplus-1mn-regular.ttf
mplus-1mn-thin.ttf mplus-1p-black.ttf mplus-1p-bold.ttf mplus-1p-heavy.ttf mplus-1p-light.ttf
mplus-1p-medium.ttf mplus-1p-regular.ttf mplus-1p-thin.ttf mplus-2c-black.ttf mplus-2c-bold.ttf
mplus-2c-heavy.ttf mplus-2c-light.ttf mplus-2c-medium.ttf mplus-2c-regular.ttf mplus-2c-thin.ttf
mplus-2m-bold.ttf mplus-2m-light.ttf mplus-2m-medium.ttf mplus-2m-regular.ttf mplus-2m-thin.ttf
mplus-2p-black.ttf mplus-2p-bold.ttf mplus-2p-heavy.ttf mplus-2p-light.ttf mplus-2p-medium.ttf
mplus-2p-regular.ttf mplus-2p-thin.ttf

How to Install VirtualBox 4.3.14 on ArchLinux

VirtualBox is one of many virtualization software that could be run on Linux, one with slowest cpu performance according to this article. Installing VirtualBox is quite simple, but to make it run you must also install certain package. To install VirtualBox, type:

yaourt --needed --noconfirm -S --force virtualbox virtualbox-host-modules linux-headers

To make it able to run, you must create the kernel module first, the easiest way is using dkms:

sudo dkms autoinstall

or

sudo dkms vboxhost/4.3.14

then enable it using:

sudo modprobe vboxdrv

Now you can start and run VirtualBox images without error.
if you want to auto-recompile when installing new kernel, use this command:

sudo systemctl enable dkms


Installing Go 1.3.1 with LiteIDE x23.2 on Arch Linux

So I installing new computer on my company, using Arch Linux as usual.

How to install Go? it's really easy when using yaourt, just type:

yaourt --needed --noconfirm -S --force go mercurial git bzr subversion liteide gdb

Go took about 40.76 MB
Mercurial, Git, Bzr and Subversion requires about 13.12 MB
LiteIDE took about 13.14 MB
Gdb took about 3.06 MB

Set your working directory:

mkdir ~/go
export GOPATH=~/go
export PATH=$PATH:~/go/bin


I suggest that you should put those environment variables on .bashrc

Then you can test the installation, create a file named test1.go

package main
import "fmt"
func main() {
  fmt.Println("Hello my lovely PC :3")
}


Run it using:

go run test1.go 

or

go build test1.go && ./test1

or press Ctrl+R on LiteIDE.

2014-08-21

Which program that uses the bandwidth the most?

So, my boarding house internet connection has been down for 4 days now, and I decided to find alternate internet connection. On Indonesia it's really hard to find mobile internet provider that has unlimited bandwidth without FUP. I decided to use one with limited quota (8GB/month) T__T seriously.. 8GB it's my daily usage, not monthly. So I buy a router with modem support (TP-Link Wireless N Router TL-MR3420) a modem (Huawei E173) and GSM card for internet (Three). Long story short, I want to know which program that uses so much bandwidth since the beginning, so I install nethogs). That program should be used as root, and the first argument is default to eth0. Nethogs will show the list of process that uses most bandwith.




2014-08-11

How to make git ignore changes on commited files?

Sometimes there are some file that we want to ignore some file on git, of course we could use .gitignore, but that only take effect on untracked files. When the files already tracked/commited, we could make that file changes ignored using git update-index command, for example:

git update-index --assume-unchanged file-to-be-ignored

From now on, that file would not appear on git status or git diff when changed. When you want to track back the changes, use --no-assume-unchanged flag.

What to do when git pull conflict before commit?

Sometimes we want to pull from git without committing current changes, and yes, the correct way is to commit our changes first before pulling, so we could merge the conflict. But if you doesn't want to do that, there are some trick that you could use, that is git stash, the usage example:

# to store all changes on the stash
git stash
# this should no longer conflict
git pull
# to overwrite from previous stash
git stash pop
# you could see the difference using
git diff

2014-08-05

How to setup SSH Tunneling (SOCKS) Proxy

Sometimes we need to connect to some site via a very secure way without our nearby computers able to see (or sniff) which sites we are visiting, or to prevent any blocking from our LAN's firewall. One easy solution to solve this, but you'll need a VPS (Virtual Private Server) with public IP address of course, all you have to do is start a SSH connection to your VPS, for example:

sudo ssh -D my_local_port my_vps_user@my_vps_public_ip

for example:

ssh -D 8081 aurora@w.x.y.z

Then, setup your browser to use SOCKS to localhost:my_local_port, for example:


Voila, now everything that you browse will encrypted through to w.x.y.z.

2014-08-04

Open Source Desktop Database GUI

When developing database apps sometimes we need easier user interface to query the database, instead of using command line (mysql for MySQL, psql for PostgreSQL), or using MySQL Workbench or the default pgAdmin. When you're using any of IDE from JetBrains you could use their Database Explorer.

DBeaver is one open source and cross platform database explorer, but it doesn't really work well with dark theme.
SQL Workbench also open source java-based database explorer, works fine with dark theme, but failed to display invalid Date.
Execute Query quite fine, I have no rants about this one.
Oh well I'll find and try another later on.

2014-07-31

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

LiteIDE 23.1 is 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.gen 
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, easy 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 

For intel graphic cards mostly you don't need to install additional things other than xorg.
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 /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:8083
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
echo /swapfile swap swap defaults 0 0 | sudo tee -a /etc/fstab

to check swap usage, use free -m command.