聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

十一月 8, 2012
» Go vs node.js vs PHP vs Python, Loop benchmark.

剛好跟lloyd大大聊到node.js V8的效能. 試寫了幾行發現速度還真是非常的快.

隨手用四種語言寫個forloop. 時間消耗依序是這樣的 Go < node.js < PHP < Python
其中 node.js 直譯器的需要編譯時間最長. 所以如果loop的max=100時.
其時間消耗變成這樣 Go < PHP < Python < node.js

這個實驗告訴我們 benchmark 是可以做到人人都滿意的。:P

package main
func main() {
    max := 1000000000
    var a,b,c int
    for i:=0;i<max;i++ {
        a = 1234 + 5678 + i
        b = 1234 * 5678 + i
        c = 1234 / 2 + i
    }
    _=a+b+c
}
var i, a, b, c, max;
max = 1000000000;
for (i = 0; i < max; i++) {
        a = 1234 + 5678 + i;
        b = 1234 * 5678 + i;
        c = 1234 / 2 + i;
}
<?
$max = 10000000;
for ($i = 0; $i < $max; $i++) {
    $a = 1234 + 5678 + $i;
    $b = 1234 * 5678 + $i;
    $c = 1234 / 2 + $i;
}
?>
max = 10000000;
for i in range(max):
    a = 1234 + 5678 + i
    b = 1234 * 5678 + i
    c = 1234 / 2 + i

仔細看code. Go & node.js 的for loop都比PHP & Python大了100倍.
因為nodejs的效能好到不能跟後兩者放在同一個量級比賽. 所以加了100倍之後拿來跟Go比.

在這邊Go很明顯多做一些事, 那是因為Go不能宣告了變數又不用.

time ./b;time node b.js;time php b.php; time python3 b.py
real  0m1.422s
user  0m1.417s
sys  0m0.004s

real  0m2.941s
user  0m2.967s
sys  0m0.018s

real  0m2.901s
user  0m2.875s
sys  0m0.025s

real  0m4.769s
user  0m4.746s
sys  0m0.022s

嘿嘿.

至於Go如果做假宣告的話那會是這樣.

package main
func main() {
    max := 1000000000
    for i:=0;i<max;i++ {
        _ = 1234 + 5678 + i
        _ = 1234 * 5678 + i
        _ = 1234 / 2 + i
    }
}

real  0m0.944s
user  0m0.938s
sys  0m0.005s

The post Go vs node.js vs PHP vs Python, Loop benchmark. appeared first on Kevinwatt's Blog.

十月 1, 2012
» Cassandra install on Ubuntu 1204

Add to /etc/apt/sources.list

deb http://www.apache.org/dist/cassandra/debian 11x main
deb-src http://www.apache.org/dist/cassandra/debian 11x main

Install command

gpg --keyserver pgp.mit.edu --recv-keys 4BD736A82B5C1B00
gpg --export --armor 4BD736A82B5C1B00|sudo apt-key add -
sudo apt-get update
sudo apt-get install cassandra

Install pycassa:

sudo apt-get install gcc python-dev python-pip # for thrift.protocol.fastbinary
sudo pip install pycassa

Also CQL: http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/

九月 28, 2012
» Cassandra is Glow Up: C* 2012: The State of Cassandra, 2012

太久沒注意了,看來這兩年來 Cassandra 成長的相當好…Cassandra Users

宜搜, ebay 大量的Service用到 Cassandra. reddit blog也用Cassandra.
連 godaddy 都使用 Cassandra 做服務移轉紀錄跟Distributed Session Store.

而且很歡樂的是 Cassandra 居然還發展出了 "Cassandra Query Language",這NoSQL的SQL化是怎麼一回事?XDD
http://cassandra.apache.org/doc/cql/CQL.html

九月 26, 2012
» Malware 惡意程式的軟體開發者開始使用 Go

Symantec最近回報了一些由Go撰寫的惡意程式(Malware),這個惡意程式在一個名為GalaxyNxRoot.exe 的 android rooting tool上被發現。在這個tool 中分別有兩個檔案由Go所撰寫 PPSAP.exe adbtool.exe。


GalaxyNxRoot.exe properties

Once executed, the GalaxyNxRoot.exe file drops and launches two executable files, both written in Go:

%Temp%PPSAP.exe
%Temp%adbtool.exe
The dropped PPSAP.exe file is an information-stealing Trojan. It collects system information such as current running processes, user name, MAC address, etc., and posts it to the following remote location:
[http://]golang.iwebs.ws/about/step1.php

The dropped adbtool.exe file downloads an encrypted file from the following remote location:
[http://]sourceslang.iwebs.ws/downs/zdx.tgz

This file is decrypted as a Dynamic-link library (DLL) file and then loaded. It attempts to encrypt various file formats on the compromised computer. The targeted file formats include:

Source code files (.c, .cpp, .cs, .php, .java, .pas, .vb, .frm, .bas, .go, .asp, .aspx, .jsp, .pl, .py, .rb)
Image files (.jpg, .png, .psd)
Audio files (.wav, .wma, .amr, .awb)
Archive files (.rar, .zip, .iso, .gz, .7z)
Document files (file extensions containing the following strings: doc, xls, ppt, mdb, pdf)
Other types of files (file extensions containing the following strings: dw, dx, sh, pic, 111, win, wvw, drw, grp, rpl, mce, mcg, pag)

全文:http://www.symantec.com/connect/blogs/malware-uses-google-go-language

九月 23, 2012
» A python example for send a message from xmlrpc to irc-bot.

This is python-irclib example.
If you use debian or ubuntu, you can install python-irclib by below command.

apt-get install python-irclib

#!/usr/bin/env python
import socket, signal
from SimpleXMLRPCServer import *
from thread import start_new_thread
from ircbot import SingleServerIRCBot

class AltXMLRPCServer(SimpleXMLRPCServer):

    finished=False

    def register_signal(self, signum):
        signal.signal(signum, self.signal_handler)

    def signal_handler(self, signum, frame):
        print "Caught signal", signum
	self.abot.shutdown()
        self.shutdown()

    def sendmsg(self, s):
	#print(s.encode('utf8'))
	for chrang in self.abot.chans:
		self.abot.connection.privmsg(chrang, s.encode('utf-8'))
	return 1

    def shutdown(self):
        self.finished=True
        return 1

    def ircbot(self, bot):
	self.abot = bot

    def serve_forever(self):
        while not self.finished: server.handle_request()

class EchoBot(SingleServerIRCBot):
    def __init__(self, chans, nickname, server):
        print "*** Connecting to IRC server %s..." % server
        SingleServerIRCBot.__init__(self, [(server, 6667)], nickname, "IRC echo bot")
        self.chans = chans

    def on_nicknameinuse(self, c, e):
        c.nick(c.get_nickname() + "_")

    def on_welcome(self, c, e):
        print "*** Connected"
        for chan in self.chans:
            c.join(chan)

    def shutdown(self):
        self.disconnect()
        self.die()

hostname=socket.gethostname()
port=8000

server = AltXMLRPCServer(("10.8.0.1", port))
print "Serving on %s:%d" %("10.8.0.1", port)

chlist=[]
bot = EchoBot(["test123"], "lovemeloveme","irc.freenode.net");
server.ircbot(bot)
server.register_function(server.shutdown)
server.register_signal(signal.SIGHUP)
server.register_signal(signal.SIGINT)
server.register_function(server.sendmsg)
start_new_thread(bot.start, ())
server.serve_forever()
print "Closed"

九月 20, 2012
» python4kids 一個老爸教8歲的兒子寫python所用的blog

python4kids已經為時兩年了
是一個每天10~15分鐘的python教學計劃.

九月 14, 2012
» 一直沒注意到ubuntu package的更新…

原來不用在build go了. 因為go都被包進ubuntu了. XD


golang - Go programming language compiler - metapackage
golang-dbg - Go programming language compiler - debug files
golang-doc - Go programming language compiler - documentation
golang-go - Go programming language compiler
golang-mode - Go programming language - mode for GNU Emacs
golang-src - Go programming language compiler - source files
gccgo - Go compiler, based on the GCC backend
gccgo-4.7 - GNU Go compiler
gccgo-4.7-multilib - GNU Go compiler (multilib files)
gccgo-multilib - Go compiler, based on the GCC backend (multilib files)

現在安裝go的動作如下…
sudo apt-get update
sudo apt-get install golang
export GOROOT=/usr/lib/go

好簡單啊!!!!

五月 10, 2011
» Debian golang Package

description Packaging for Google Go
owner Ondrej Sury
last change Sat, 7 May 2011 18:27:37 +0000
URL https://alioth.debian.org/anonscm/git/pkg-google/golang.git
Debian

http://packages.debian.org/zh-tw/source/sid/golang

二月 3, 2011
» Go, significant changes in this week.

http://groups.google.com/group/golang-nuts/browse_thread/thread/b877e34723b543a7
Non-blocking channel operations have been removed from the language.
The equivalent operations have always been possible using a select statement with a default clause. If a default clause is present in a select, that clause
will execute (only) if no other is ready, which allows one to avoid blocking on a communication.

For example, the old non-blocking send operation,

if ch <- v {
// sent
} else {
// not sent
}

should be rewritten as,

select {
case ch <- v:
// sent
default:
// not sent
}

Similarly, this receive,

v, ok := <-ch
if ok {
// received
} else {
// not received
}

should be rewritten as,

select {
case v := <-ch:
// received
default:
// not received
}

四月 29, 2010
» 最近很熱門的資料庫 cassandra

雖然go目前還沒有cassandra的connection library,不過已經有相關討論了。
(不管寫什麼都要置入性行銷一下go)

http://cassandra.apache.org/

cassandra 是Apache Top level Project之一,facebook,Digg 跟 Twitter 都有採用它作為一部分的資料庫.
cassandra 是一個cluster database 就像 BigTable 一樣,但他們還是不同的。
從CAP理論(http://devblog.streamy.com/2009/08/24/cap-theorem/)的角度來看
一致性(Consistency): “Is the data I’m looking at now the same if I look at it somewhere else?”
系統可用性(Availability): “What happens if my database goes down?”
分散容錯(Partition tolerance): “What if my data is on different networks?”

BigTable偏向於CA, 而cassandra則是AP。

Cassandra的API應用也相當廣泛. php, perl, python, ruby 甚至連haskell都有支援.

目前我只試過兩套python的api, lazyboy跟pycassa

簡單執行

git clone http://giturl
sudo python setup.py install

就可以安裝這兩套library了.

以下是lazyboy的example code.

from lazyboy import *
from lazyboy.key import Key

import time;

# Define your cluster(s)
begin = 0;
btime = time.time();
connection.add_pool('Keyspace1', ['192.168.23.168:9160', '192.168.23.169:9160','192.168.23.172:9160'])

for i in xrange(begin, begin + 500000):
if i!=begin and (i % 10000) == 0:
print time.time() - btime;
btime = time.time();

rc = record.Record({'value': i, 'text': "ruslan text"})
rc.key = Key("Keyspace1", "Standard1", str(i));
rc.save(0);

print time.time() - btime;

pycassa也是很nice

import pycassa
client = pycassa.connect(['192.168.23.168:9160', '192.168.23.169:9160'])

cf = pycassa.ColumnFamily(client, 'Keyspace1', 'Standard1')
cf.insert('foo', {'column1': 'val1'})
cf.get('foo')
print(cf.get('foo')['column1'])

nodetool

kevin@Office:~$ nodetool -host 192.168.23.168 -port 8080 ring
Address Status Load Range Ring
103440706267102512524414743070503313038
192.168.23.169Up 143.96 MB 10179247206633247959723284233859042110 |<--|
192.168.23.172Up 143.97 MB 24715272519024223240814048623324812800 | |
192.168.23.168Up 144.02 MB 103440706267102512524414743070503313038 |-->|
kevin@Office:~$ nodetool -host 192.168.23.168 -port 8080 info
103440706267102512524414743070503313038
Load : 144.02 MB
Generation No : 1272273320
Uptime (seconds) : 72795
Heap Memory (MB) : 128.90 / 1016.13

個人還是比較喜歡劍魂中的遊戲人物 cassandra :D

三月 23, 2010
» Go blog新上線

golang-logo
official Go blog
Go官方的Blog跟這星期的Go一起正式Release囉。

Go主要是希望透過這個Blog將最新的訊息帶給使用Go的開發者們,在Go Blog的第一篇文章中 Go: What’s New in March 2010 ( Btw: 這標題都超沒誠意的 "Go: 2010年三月的新消息" )
將介紹從去年11月一直到現在Go的世界發生了什麼事。

三月 17, 2010
» new command: goinstall

golang
http://golang.org/cmd/goinstall/

各位太太小姐,您是否每次安裝library都要下10行command呢?還記不清是先pull還是先up?

upgrade 時老忘記這個library是在下git還是hg?還是前面兩種都試完才發現是svn?

體貼各位開發者的辛苦,美國加力佛尼亞的g公司最新科技登場…
每次裝library要手動一步一步來的時代已經過去了。

現在裝Go-MySQL-Client-Library就是這麼簡單
goinstall -dashboard=true github.com/thoj/Go-MySQL-Client-Library

程式中要使用它,直接import library在goroot/pkg/$arch/下的路徑即可。
import (mysql "github.com/thoj/Go-MySQL-Client-Library")

這個cmd是Russ Cox上個月底加的
主要是簡單安裝第三方library. 目前goinstall支援git, hg, svn 三種。

» Go Wiki!

http://code.google.com/p/go/wiki/WikiIndex
其實這一兩天已經從golang-dev嗅到一點wiki的味道了,go wiki正式上線。

不過要參與編輯的話必須要成為contributer,需照以下方法確保你的貢獻會採用Google版的BSD Style License。
Contributor License Agreement: http://golang.org/doc/contribute.html#copyright

我個人不是很喜歡這種作法。

三月 15, 2010
» 上課囉,Go語言在羅徹斯特理工學院(RIT)開課了。

http://www.cs.rit.edu/~ats/

null

Go, Concurrent and Systems Programming (in mycourses)
4003-561-70, 4005-714-70 MW 6:00-7:50 pm, 70-3560

這堂課從2010年春季開始講授。

相關資料跟note可以參考

http://www.cs.rit.edu/~ats/go-2009-3/index.xml

三月 11, 2010
» Go出書了?Go for Dummies

golang

還差的遠呢… Go每週Release一次,平均每兩到三個星期就會有一次語言上的修正。
這種書怎麼寫啊?

不過現在 Toni Mikael Korpela 整理了一份給笨蛋的Go入門資料(Go for Dummies)。
如果你還沒入門,可以參考看看。

http://docs.google.com/Doc?docid=0Abeqw3xBUqsUZGY2YnM5Z2tfN3NzNWJ0NGdk&hl=en

» Go in Google AI Challenge

Go在Google AI Challenge貪吃蛇大賽中表現亮眼。

http://csclub.uwaterloo.ca/contest/index.php



其中使用Go語言的shinobi贏得整個賽事第29名,排名他在之前的程式都是由 C++, Common Lisp, 和 C# 所撰寫的。

http://csclub.uwaterloo.ca/contest/language_profile.php?lang=Go

http://csclub.uwaterloo.ca/contest/rankings.php?page=1

RANK USERNAME COUNTRY ORGANIZATION LANGUAGE ELO SCORE
1 (29) shinobi Other Go 2570

» new package: websocket

http://golang.org/pkg/websocket/

websocket

websocket是html5中WebServer跟Browser交換資料的新方法。

http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-74

不仰賴 XMLHttpRequest or iframe s 這些傳統的作法,也不用開啟多個HTTP connections就可以進行資料交換。

是一個很有趣的東西。

一月 18, 2010
» Petar Maymounkov加入golang的開發?

今天看到r新增了這個討論串,才想起這個名子好像再哪聽過…

Google了一下才發現是Bittorrent DHT(Distributed Hash Table)網路所使用的Kademlia演算法的發明人之一。

目前他主要的貢獻是在golang中改良http package。go的http package還在初期規劃階段,一般遇到最大的問題是他把http.send列為私有的function。

Russ cox認為如果在沒有規劃好http package就開放http.send的話,會導致之後的很多相容性問題。所以目前部份軟體(ex. ed2kcrawler)是另外實做http.send的,在Petar Maymounkov加入後或許會有更讚的http package吧。

» Package Document鬼打牆

在irc討論function時發現Document裡的一件趣事。

11:44 < happy> anyone know what function converts a string to an int?
11:48 < kevinwatt> happy: http://golang.org/pkg/strconv/#Atof64
11:49 < happy> ty
11:49 < happy> lol
11:51 < happy> Atoi is like Atoi64 but returns its result as an int; Atoi64 is
like Atoui64 but allows signed numbers and returns its result in
an int64.; Atoui is like Atoui64 but returns its result as a
uint.
11:51 < happy> does it go on forever? They are in reverse order :-\
11:51 < happy> the one at the top says refer to the next one which says refer to the next one…

文件中一直請你參照別的function,就像鬼打牆一樣繞不出去。
Atoi這種其實只要簡單的一行說明就好了,沒有說明卻一直附上參考實在是頗有趣…

Package Link
Screenshot-2

十二月 11, 2009
» 一個關於Ken Thompson的小故事

Go 的建立者之一,也是UNIX的建立者 Kenneth Thompson Kenneth Thompson
他在1960年發明了 B 語言,然後和 C 語言的建立者之一 Dennis Ritchie 一起用 C 語言寫了 UNIX 作業系統。
Anyway,他一直有一個遺憾。

http://en.wikiquote.org/wiki/Kenneth_Thompson

Ken Thompson was once asked what he would do differently if he were redesigning the UNIX system. His reply: 『I’d spell creat with an e.』
Ken Thompson有一次被問到,如果你有機會重新設計UNIX系統,你最想改的是甚麼?他回答:我會讓creat這個拼寫加上e。

就是 UNIX 的系統呼叫建立檔案都是用 O_CREAT。
他一直想要把它改成 O_CREATE ,但是 O_CREAT 已經被 IEEE 已經加到 POSIX 裡作為規範了。

因為Go,他終於辦到了…

Ken Thompson的Log message


// Flags to Open wrapping those of the underlying system. Not all flags
// may be implemented on a given system.
const (
O_RDONLY = syscall.O_RDONLY; // open the file read-only.
O_WRONLY = syscall.O_WRONLY; // open the file write-only.
O_RDWR = syscall.O_RDWR; // open the file read-write.
O_APPEND = syscall.O_APPEND; // open the file append-only.
O_ASYNC = syscall.O_ASYNC; // generate a signal when I/O is available.
O_CREAT = syscall.O_CREAT; // create a new file if none exists.
O_EXCL = syscall.O_EXCL; // used with O_CREAT, file must not exist
O_NOCTTY = syscall.O_NOCTTY; // do not make file the controlling tty.
O_NONBLOCK = syscall.O_NONBLOCK; // open in non-blocking mode.
O_NDELAY = O_NONBLOCK; // synonym for O_NONBLOCK
O_SYNC = syscall.O_SYNC; // open for synchronous I/O.
O_TRUNC = syscall.O_TRUNC; // if possible, truncate file when opened.
O_CREATE = O_CREAT; // create a new file if none exists.
)

………………..花了40年啊~

聽完這個故事有沒有很感動? 要不要好好學 go?
http://golangd.com/

A Feedjack powered Planet
A Django site.