穷人真的比富人更慷慨吗?

今天听了最新一期的 Freakomics: Are the Rich Really Less Generous than the Poor? 里面讲了一个很有趣的经济实验(注1,经济学的实验都是很难的)。

往常大家的共识是认为有钱人往往更加自私,穷苦的人家的孩子相比会慷慨一些。比如在这个实验里,穷人家的孩子会比富人家的孩子捐助得多。这点在穷人和富人在慈善的投入中也有所体现

但和以往更多的实验室里的实验不同的是,这次的经济学家把实验放到了更加真实环境里:他们在荷兰的一个城市中找了160家有钱人的住宅和160家贫穷人的家,分别投递了一封收件人并不是他们的信,信里面有5欧或20欧的现金或者支票。当那320户人家收到信的时候,他们会知道这个信并不是给他们的,但又能看到信里的钱。这个实验就想看看是有钱人家还是穷人家更会把这个钱还给真正的收件人呢?

实验的结果却大跌眼镜,不管是5块还是20块,不管是现金还是支票,富人里有~80%的人会退还信封,是穷人相应比例的两倍。穷人只有不到 40% 的人会还回那封信。他们还发现,往往在发工资之前的几天,穷人是越不会送还这封信的,等到发完工资之后,这个比例才会最高。实验结果有很多种解释,比如20欧的钱对穷人的吸引力远比对富人的多,又比如,穷人的执行力比起富人往往更差,或者他们一般会更忙,他们很有可能本来想要归还的却一直没有做。

所以作者最后的结论是,穷人不比富人更加慷慨,但反之也不一定成立。

13 Reasons Why 观后

花了大半天的时间看完了Netflix的新剧 <13 Reasons Why>,很推荐。

这是一个很沉重的片子,是一个校园欺凌和青少年抑郁的故事:一个高中女孩自杀之后留下了十三章卡带,讲述了她如何一步一步走向死亡的过程,很灰暗,却很真实。

十三个人物里,真正意义上的坏人只有一个,他是个体育好的富二代,学校里的明星学生,一次次的把魔爪伸向无辜的女孩们。这样的人,每个校园都会出现。其他的十二个角色,则更是我们身边的人,或者我们自己。有时候开着一些无谓的玩笑,搞一些很无聊的恶作剧,出了事情以后若无其事的再把脏水泼给别人,自己都没有意识到在无意之中对别人的伤害。

雪崩的时候,没有一片雪花是无辜的。

同时,青少年的心理问题也值得关注,片子里的父母似乎也都没有一个够好的亲子关系,正如后面的花絮里说的,那个年龄的孩子们,肚子有一大堆的问题,却无从表达。要培养一个坚强勇敢的孩子,似乎也不是那么容易的事情,更何况,抑郁的时候,一根稻草就足以压倒那头骆驼。

找老师的那段无比可惜,她可是寻求帮助了啊,就差了那么一点点。

最后的最后,看了这么多集,在为一个生命惋惜的时候,谁曾想到,还有一个生命,也走上了自杀的道路?!

真是难过。

How to Access Host machine via SSH in Virtualbox

There are sufficient articles teaching ppl how to access guest machine via ssh in virtualbox, while it takes me time to figure out the reverse way. It is very important since i dont that trust virtual machine and i hope to do the one-way backup of my work in the host.

Well, here is the answer. If using NAT, the ip address 10.0.2.2 is the host machine.

Note: remember to add “sshd: 127.0.0.1” in /etc/hosts.allow otherwise the sshd gives u “ssh_exchange_identification: connection closed by remote host” error.

Google GO (5) – "Effective Go" Notes

Effective GO link

“gofmt” could do the code formatting for you.

Underscore (_), is the blank identifier, provides a way to ignore values returned by a multi-valued expression.

x, _ = f() // ignore second value returned by f()

use range to help for loop

for _, value := range m { // key is unused
sum += value
}

In switch, cases can be presented in comma-seperated lists

switch c {
case ‘ ‘, ‘?’, ‘&’, ‘=’, ‘#’, ‘+’, ‘%’:
return true
}

Switch can be used to discover the dynamic type of an interface variable.

switch t := interfaceValue.(type) {
default:
fmt.Printf(“unexpected type %T”, type); // %T prints type
case bool:
fmt.Printf(“boolean %t\n”, t);
case int:
fmt.Printf(“integer %d\n”, t);
case *bool:
fmt.Printf(“pointer to boolean %t\n”, *t);
case *int:
fmt.Printf(“pointer to integer %d\n”, *t);
}

Functions support multiple returns, such as

func nextInt(b []byte, i int) (int, int)

Named return parameter is initialized by zero, and return by current value if return with no arguments.

Composite literal, could use

return &File{fd, name, nil, 0};

or labels inside

return &File{fd: fd, name: name}

new() returns the pointer with all zeroed memory.

make(T, args) creates slices, maps and channels.

Arrays, when it is passed to a function, it is a copy of the array, not just the pointer.

The size of an array is part of its type, which means [10]int and [20]int are distinct.

len(slice) -> length, cap(slice) -> capacity

In if statement, the expression may be preceded by a simple statement, which executes before the expression is evaluated.

if x := f(); x < y {

Go’s memory sharing design:

Do not communicate by sharing memory; instead, share memory by communicating.

Buffered channel & Unbuffered channel

ci := make(chan int); // unbuffered channel of integers
cj := make(chan int, 0); // unbuffered channel of integers
cs := make(chan *os.File, 100); // buffered channel of pointers to Files

Channels could be used as semaphore

var sem = make(chan int, MaxOutstanding)

func handle(r *Request) {
sem <- 1; // Wait for active queue to drain.
process(r); // May take a long time.
<-sem; // Done; enable next request to run.
}

Google GO (4) – Tutorial Notes

Tutorial Notes

Three ways of declaration:

var s string = “”;
var s = “”;
s := “”;

For Loop(parentheses no needed, braces mandatory):

for i := 0; i < flag.NArg(); i++ {

To signal an erroneous return, call

os.Exit(1)

Falling off main.main means “success”

Types are different even they are using the same bits. int and int32 are distinct, int and uint are distinct.

Strings are kinda const strings in C++, couldnt be changed.

Arrays

var arrayOfInt [10]int;

Slice variable reference a segment of an array

a[low : high]

function func sum(a []int) int {} could be called in multiple ways

s := sum(&[3]int{1,2,3}); // a slice of the array is passed to sum
s := sum(&[…]int{1,2,3}); // want compiler to count the elements
s := sum([]int{1,2,3});

Maps

m := map[string]int{“one”:1 , “two”:2}

Allocation

type T struct { a, b int }
var t *T = new(T);

or

t := new(T);

For maps, slices and channels which have reference semantics, using make() instead

m := make(map[string]int);

If a name (of a top-level type, function, method, constant or variable, or of a structure field or method) is capitalized, it is visible to the public, users of the package may see it. Otherwise, the name and hence the thing being named is visible only inside the package in which it is declared.

Open files

func Open(name string, mode int, perm int) (file *File, err os.Error)

Note there is a multi-value return here. err is nil if no error. Similarly, there are other methods for I/O

func (file *File) Close() os.Error
func (file *File) Read(b []byte) (ret int, err os.Error)
func (file *File) Write(b []byte) (ret int, err os.Error)
func (file *File) String() string

os.Error has a method called os.Error.String() could convert to a printing description.

Switch

switch nr, er := f.Read(&buf); true {
case nr < 0:

case nr == 0:

case nr > 0:

}

Interface is declared like

26 type reader interface {
27 Read(b []byte) (ret int, err os.Error);
28 String() string;
29 }

It is implemented by a type if the type implement *all* the methods declared in the interface. This means following empty interface is by default implemented by any type.

type Empty interface {}

Printf(), %v will print in a simple appropirate style by default. Print() and Println() would do the print fromatting automatically.

Type assertion, e.g. v.(Stringer) while Stringer is an interface, to see if v satisfies the Stringer interface.

s, ok := v.(Stringer); // Test whether v implements “String()”

Channel, a communications channel that connect two concurrent computations, using make() to create new channel.

09 // Send the sequence 2, 3, 4, … to channel ‘ch’.
10 func generate(ch chan int) {
11 for i := 2; ; i++ {
12 ch <- i // Send ‘i’ to channel ‘ch’.
13 }
14 }
15
16 // Copy the values from channel ‘in’ to channel ‘out’,
17 // removing those divisible by ‘prime’.
18 func filter(in, out chan int, prime int) {
19 for {
20 i := <-in; // Receive value of new variable ‘i’ from ‘in’.
21 if i % prime != 0 {
22 out <- i // Send ‘i’ to channel ‘out’.
23 }
24 }
25 }

Go routines, starting the function running in parallel in the same address space

go sum(hugeArray); // calculate sum in the background

Then check the result by passing channel

ch := make(chan int);
go sum(hugeArray, ch);
// … do something else for a while
result := <-ch; // wait for, and retrieve, result

select statement choose which of the multiple communications listed can proceed

21 func server(op binOp, service chan *request, quit chan bool) {
22 for {
23 select {
24 case req := <-service:
25 go run(op, req); // don’t wait for it
26 case <-quit:
27 return;
28 }
29 }
30 }