Run offical Go language tutorial (A Tour of Go) on a server

Recently I am learning Go language for the distributed system course. Basically, golang is a programming language developed by Google – it has a C-like code style and an enhanced support for concurrency, which means writing a server with golang is a good idea.

Golang has an online version tutorial here. It has a server-based compiler and allow you to run some script. Since it is on a public server, its speed is somewhat slow. In this case, I planned to run the gotour on my own VPS.

I downloaded and started gotour on my VPS. However, when I saw an message told me to open a browser and type, I realized that things could not be that easy. As expected, directly visit 3999 port will receive an instant HTTP error.

Leaving in China behind firewall for years, I instantly remind the SSH tunnel. By using SSH tunnel, you don’t need any extra software and you can access 3999 port as if you were localhost. By experiment, it did work but it was quite slow, which reminded me the days in China. After all, SSH is not designed for proxy.

I searched on Google but it seems that no one cares about that, and I had to figure out myself. By searching the source code, I find two places was related to localhost. Both in client.go, like:

var (
	httpListen  = flag.String("http", "", "host:port to listen on")
	openBrowser = flag.Bool("openbrowser", true, "open browser automatically")

(The other one is to display an warning message. I didn’t attempt to modified it)

Ah-hah! httpListen, a really easy-understanding name, right? Now change it to Don’t forget to type go install to compile. Now, I got an warning message:


I appear to be listening on an address that is not localhost.
Anyone with access to this address and port will have access
to this machine as the user running gotour.

If you don't understand this message, hit Control-C to terminate this process.

Really look like an important notice, right? Okay, I admit that allowing others to run program on my server is not a good idea.

I opened my local web browser, successfully received the tutorial page. However, to my suppress, I couldn’t run any code, and got an error message like:

2016/01/** **:**:** bad websocket origin: http://****.***:3999 read more

Thinking in Java Chapter 1&2: Object

After one year of programing with Java, I am gradually familiar with OOP. Learning java for me, whose first programming language is C, was much more than change the name system, like field, method, reference, etc. It is almost a renewal of concept. Although so, my knowledge of Java was founded from all kinds of sources, and a book like Thinking in Java seems useful for me to introduce systematically introduce the thought behind Java.

It is important to design classes appropriately. For people who is not familiar with OOP, it can easily happen that use classes as structs and designs methods as “functions” in the outer classes. Abusing inheritance may also be a popular mistake. When the relationship between classes is “have-a”, one should use composition(or aggregation when dynamically). We should also think about it whether the relationship is “is-a” or “is-like-a”. For the former one, we may only override methods of base class, while the latter one may involves implicating new methods. When we upcasting objects to their base classes types, only methods we use substitution can be called. Otherwise, we will have to downcast the reference to call the unique methods. Although so, both the two models are useful, and the choice will be obvious for certain problems. read more

CSAPP chapter 2 : Representation of Data

During the undergraduate studying process, students are familiar with the representation of integers and fractional numbers inside the machine. As a result, this chapter may be kind of basic. However, some interesting facts do exists, which I never think about before.

For instance, we all know that when computing with int and float data, all the data will be cast to float to make sure the loss of data being deduced. To get a result of 0.4, use read more