Thursday, June 14, 2012

开始用 GitHub


现在免费的代码托管最出名的非Github莫属,但是我一直没有用Github,原因是因为Github没有免费的Private Repo。我之前一直是使用bitbucket的服务,可以有无限的私有Repo。最近因为学习目的,要fork一个Repo来看看,就开始使用Github。

Github有很详细的说明,我这里只是记录下来不让自己忘。
在做下面步骤之前,一定是要先安装git的。

$ git config --global user.name "myname"
$ git config --global user.email "myname@T420_Win"

make the git cache username and password for 1 hour (default is 15 mins), so you
don't need to type username and password everytime talk to remote server.

$ git config --global credential.helper 'cache --timeout=3600'

fork a repo

clone the forked repo
$ git clone git@github.com:username/Spoon-Knife.git

$ cd Spoon-Knife

Assigns the original repo to a remote called "upstream"
$ git remote add upstream git://github.com/octocat/Spoon-Knife.git

Pull the changes not present in your local repository, without modify your files
$ git fetch upstream

Pushes commits to your remote repo stored on GitHub
$ git push origin master

Fetches any new changes from the original repo and Merges any changes fetched into your working files
$ git fetch upstream

$ git merge upstream/master

Wednesday, June 13, 2012

在VirtualBox里面安装Plan 9

因为在学习Go,看到Go历史追溯到Plan9,就心血来潮要试着安装一个玩一玩。
下载plan9.iso。在VirtualBox里面创建一个新的VM,2G的IDE硬盘就够了,我给分配了512M的内存。把iso当中第二个IDE,然后从CD启动。

安装步骤蛮简单的,按照提示一步一步的安装,基本上就是一路点【Enter】键。在选择安装到哪个硬盘的时候,要手动输入。

安装完,把ISO从VM里面去掉,然后重启。

提示重那里启动 root is from ... : (按回车键)


提示用户名,输入glenda
user[none]: glenda
等待一阵子,就会看到rio图形界面了。

Plan9默认的图形分辨率太低,可以自己更改配置调高。


在图形界面上按住右键,选“new”
按住右键拉一个窗口
在窗口里面输入:

9fat:
sam /n/9fat/plan9.ini

在窗口里面按住右键,选“plan9.ini"
修改下面两行
monitor=xga
vgasize=640x480x8

替换内容
monitor=vesa
vgasize=1024x768x24

按住右键,选”write“
右键点击刚刚编辑的地方
按住右键,选”close“,再点右键
输入”q回车“退出

然后重启VM,就可以看到比较大的显示了。


下面的文档是plan9的一个入门文档,介绍了plan9下面一些常用软件和操作。
http://www.quanstro.net/newbie-guide.pdf

Tuesday, June 12, 2012

Golang conditional compilation

In C language, we use #if, #else, #endif for conditional compilation.

For Go, the conditional compilation can be achieved by include different files in certain build configuration.

At begin of source file, put // +build XXX then followed by a blank line.

main1.go
// +build main1

package main

import (
    "fmt"
)

func main() {
    fmt.Println("This is main 1")
}
main2.go
// +build main2

package main

import (
    "fmt"
)

func main() {
    fmt.Println("This is main 2")
}
when running "go build", I still got compile error
$ go build -tags 'main1'

Saturday, June 2, 2012

Setup emacs + gocode for golang editing with auto completion


from Go Source repository http://code.google.com/p/go/source/browse/misc/emacs/
download go-mode-load.el and go-mode.el, put both file into ~/.emacs.d

edit ~/.emacs to add
(add-to-list 'load-path "~/.emacs.d" t)
(require 'go-mode-load)

Go to ~/.emacs.d to compile go-mode.el
$emacs -batch -f batch-byte-compile go-mode.el

Install Autocomplete for emacs from http://cx4a.org/software/auto-complete/
Follow the user manual for instllation.

Copy emacs/go-autocomplete.el file from the gocode source distribution to ~/.emacs.d

edit ~/.emacs to add
(require 'go-autocomplete)
(require 'auto-complete-config)

Install gocode
$go get github.com/nsf/gocode
$go install github.com/nsf/gocode

All instllation is done. To test of gocode auto completion
$gocode -s 

then run emacs with a go file, test and enjoy it.

Using Juniper Network Connect on Lubuntu 12.04 64bit

All ideas are from http://mad-scientist.us/juniper.html.

Below is my preparation on my Lubuntu 12.04 64bit. Rest just follow the origin website.

Install ia32-libs

$sudo apt-get install ia32-libs

Download 64bit and 32bit Java installation files
jre-6u32-linux-i586.bin  for 32bit linux
jre-6u32-linux-x64.bin for 64bit linux

ia32-libs and jre 32bit is only needed if you want to run gui version of juniper vpn.

I will install both JAVA in /opt/java/
$sudo mkdir -p /opt/java/x86 /opt/java/x64
$cd /opt/java/x86
$sudo sh ~/Download/jre-6u32-linux-i586.bin

$cd /opt/java/x64
$sudo sh ~/Download/jre-6u32-linux-x64.bin

Create JAVA plugin for firefox.
$cd /usr/lib/firefox/plugins
$sudo ln -s /opt/java/x64/jre1.6.0_32/lib/amd64/libnpjp2.so .

Start Firefox, use "about:plugins" to check Java installed.

Install xterm by
$sudo apt-get install xterm


Setup Sublime Text 2 + gocode for GoLang coding on Ubuntu 12.04


Step to setup on Ubuntu 12.04


Install Golang
$sudo apt-get install golang


Install gocode and dependency packages
$ sudo go get github.com/nsf/gocode
$ sudo go install github.com/nsf/gocode
$ sudo go get github.com/DisposaBoy/MarGo
$ sudo go install github.com/DisposaBoy/MarGo

add /usr/lib/go/bin to your $PATH by edit ~/.bashrc
export PATH=$PATH:/usr/lib/go/bin

Install Sublime Text 2 from http://http://www.sublimetext.com/2
$ tar vxjf Sublime Text 2 Build 2181 x64.tar.bz2
$ sudo mv Sublime\ Text\ 2 /opt/sublime2
$ sudo sudo ln -s /opt/sublime2/sublime_text /usr/bin/subl

Installation for Sublime Text 2 OK. Can run using symbol link "subl"
$ subl  &

Install Package Control for Sublime Text 2.
press Ctrl + ` to view the python consol, paste following line

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

Reset Sublime Text 2

Ctrl + Shift + P, then select "Package Control: Install Package", type "gosublime" and install

Reset Sublime Text 2, now you have a very nice go editor. Enjoy it.

Friday, June 1, 2012

读书 Learning Go

Learning Go - a free E-Book for learning the Go language, 这个是一本不错的Go语言入门的书,免费的,书本身是用Latex写的,放在github上( https://github.com/miekg/gobook ), 也可以直接下载PDF版本(http://miek.nl/files/go/),中文翻译版本(http://www.mikespook.com/learning-go/

昨晚10点多开始读,刚刚读完,没有做里面的练习题,算是对Go有了一个初步也比较全面的了解,感觉Go设计的的确很不错,毕竟是大牛们经过了好多年思考的结果。语法简介,清晰,功能强大。以后工作中如果要写一些小工具,可以考虑用Go来代替Python。