Golang Quick Start

Quick Start ubuntu Install golang: sudo apt-get install golang mkdir -p $HOME/go_work/src/github.com/username/hello export GOPATH=$HOME/work For convenience, add the workspace’s bin subdirectory to your .bashrc: export GOPATH=$HOME/go_work export PATH=$PATH:$GOPATH/bin Save following to $GOPATH/src/github.com/username/hello/hello.go: package main import "fmt" func main() { fmt.Printf("hello, world\n") } compile and run: go install github.com/username/hello $GOPATH/bin/hello Done! My first golang programe package main import "fmt" // fibonacci // fibonacci 函数会返回一个返回 int 的函数。 func fibonacci() func() int { count := 0 a := 1 b := 1 return func() int { count++ if count <= 2 { a = 1 b = 1 return 1 } c := b b = a + b a = c return b } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt....

January 18, 2017 · 1 min · Me

Linux Note

搜索 Apt 已安装的软件 ubuntu 下 apt-get install 完一个软件,想知道它装到哪里了用这个命令 dpkg -L python-qt4 Install chrome date: 2016-05-27 wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo gdebi google-chrome-stable_current_amd64.deb Install new font date: 2015-04-29 How-to For system wide installation, copy the fonts to /usr/share/fonts and run sudo fc-cache to rebuild the font cache, or for user local installation, make sure ~/.fonts exists, copy them into there, then rebuild the font cache. Example Install adobe-fonts/source-code-pro in Ubuntu 14.04: [ -d /usr/share/fonts/opentype ] || sudo mkdir /usr/share/fonts/opentype sudo git clone https://github....

May 27, 2016 · 2 min · Me

Haskell 笔记

入门 安装: sudo apt-get install ghc 终端命令: ghci 可以用ghci的 :set prompt 来进行修改: Prelude> :set prompt "ghci>" ghci> 导入模块: ghci> :module + Data.Ratio 我们探索类型世界的第一步是修改 ghci,让它在返回表达式的求值结果时,打印出这个结果的类型。使用 ghci 的 :set命令可以做到: Prelude> :set +t 取消: Prelude Data.Ratio> :unset +t 列表 加: Prelude> [1,2] ++ [3,4] [1,2,3,4] 第一个: Prelude> head [1, 2, 3, 4] 1 除第一个以外: Prelude> tail [1, 2, 3, 4] [2,3,4] 前 N 个: Prelude> take 2 [1, 2, 3, 4, 5] [1,2] 前 N 个以外:...

May 18, 2015 · 1 min · Me

Sqlite Note

常用查询函数 def query_db(self, sql, args=(), one=False): cur = self.cx.execute(sql, args) rv = [dict((cur.description[idx][0], value) for idx, value in enumerate(row)) for row in cur.fetchall()] return (rv[0] if rv else None) if one else rv 清空表的内容,并重置自增字段 delete from your_table; delete from sqlite_sequence where name='your_table'; 如何将两个字段字符串合并 使用 || 符号。 内置函数 核心函数 An application may define additional functions written in C and added to the database engine using the sqlite3_create_function() API. abs(X) 该函数返回数值参数 X 的绝对值。如果 X 为 NULL ,则返回 NULL。如果 X 是无法转换 为数值的字符串或 blob ,则返回 0....

April 24, 2015 · 20 min · Me

Build Static Blog With Pelican

Setup environment and install software: $ mkdir pelican_blog $ cd pelican_blog $ mkvirtualenv pelican_blog $ pip install pelican markdown beautifulsoup4 Pelican quickstart: $ pelican-quickstart You will see blow: Welcome to pelican-quickstart v3.5.0. This script will help you create a new Pelican-based website. Please answer the following questions so this script can generate the files needed by Pelican. > Where do you want to create your new web site? [.] > What will be the title of this web site?...

March 10, 2015 · 4 min · Me