Pages

Saturday, January 18, 2014

[VirtualBox] Make SSH connections among the cluster of guest OS

To build up a distributed system, we need the network to connect the nodes.  However, sometimes I cannot have internet access, so I decided to build a local cluster in my laptop.  The first thing is to create a local network among the cluster.  I will list the minimum steps and briefly explain how it works.


Host OS: OSX 10.7
Guest OS: Ubuntu server 12.04

How to build up in-cluster network?

The spirit:
Create a network interface for in-cluster network

On every guest OS panel
Setting -> Network
Besides the first network card with NAT, add second network card with Bridged Adapter.
This will create a new network interface on your GUEST, say eth2

Edit the network interface configuration
Assume the interface is eth2, and we want to set the ip as 192.168.56.100

Add these
/etc/network/interfaces
auto eth2 #automatically activate this interface iface eth2 inet static #this is a static ip, not dhcp, nor loopback address 192.168.56.100#change the number 100 to whatever you want (less than 255) netmask 255.255.255.0

Restart the network process to read the new configuration.
sudo /etc/init.d/networking restart

You can also manually activate the interface by
sudo ifconfig eth2 inet 192.168.56.100

What to communicate with the host?

The spirit: Create another network interface on host, also create new network interface on guest.

Create new network interface on host
On the VirtualBox main panel
Preference -> Network -> Create a new adapter (e.g. vboxnet0)
This will create a new network interface on your HOST, say vboxnet
type ifconfig to check it
In this case, we have vboxnet (doesn't matter), and 192.168.56.1 as the ip

Create new network interface on guest
Similar to in-cluster network, but we choose 'Host-Only' here.

Conclusion

Use different types of network adapter (interface) for different types of communication.
guest-to-guest: Bridge-Adapter
guest-public (outside of the host): NAT
guest-host: Host-Only Adapter

Now, you supposed to be able to connect the host via 192.168. 56.1; You can also connect to the other node via 192.168.56.100

Friday, January 17, 2014

[Linux] Customize shell prompt


To change the shell prompt, change the variable $PS1 the .bashrc (depends on the shell you use)

\u    : user name
\h    : hostname
\w    : the current absolute path (use /W if you only want to relative path)
\n    : new line

To add color to the prompt

\e[   : start to add color
x;ym  : set the color to x;y
\e[m  : end to add color

another format to add color

For example, green string 'HelloWorld'






.bashrc
# the color code for green is 01;32m PS1='\e[01;32mHelloWorld\e[m'
Another example:
Green user name (spencer)
purple directory (~) in a pair of bracket ([XXXX])
ending up with a dollar sign ($) and leave a space.




.bashrc
PS1='\e[01;32m\u:\e[m\e[11;35m[\w]$\e[m ' # 01;32m = green, 11;35m = purple # use one pair of declaration for one color

Update Jan. 24, 2014:
It seems that using the purple color (11;35m) may result in a bug, choose another color, for example blue (01:34).

Friday, December 6, 2013

什麼都忘了

這幾天來一直處在行屍走肉的狀態,我指的不是渾渾噩噩、無所事事的心理消極;我是發現我的腦袋運作又開始秀逗了,中英文的文法跟字詞常常想不起來,閱讀也是如此,語文能力直接歸零,即使母語也是。

更甚者,我連自己的名字都有點記不起來了,我今天把自己的名字寫錯好幾次,而且不是筆誤所照成的,是我對這名字開始有陌生的感覺,就像在寫別人的名字一樣。天啊!壓力有這麼大嗎?有事嗎你!

張三豐說只要能把老爸姓啥都忘記,就是練成太極拳了!阿我想問:連自己的名字都沒記住,是不是代表我快成仙了?


Friday, November 15, 2013

[Ubuntu] SSH without password

The spirit is: Put your public key, say id_rsa.pub, into the target machine’s list, say authorized_key.  Please node that this is one-way function, if you want mutual password-free ssh connections, do it again in opposite direction!

Example:
server_node
client_node

server_node to client_node

Generate private and public keys from server
server_node$: ssh-keygen
Leave all the setting default by pressing enter (you can also enter a strong passphrase for security)
Send the key to the client
ssh-copy-id client_node
This is a shortcut to 
1. copy the the public key (id_rsa.pub) to the client_node 
server_node$: scp ~/.ssh/id_rsa.pub client_node/.ssh
2. copy the contend of id_rsa.pub from server_node to the list (authorized_key) in the client_node
client_node$: cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Test whether it works
server_node$: ssh client_node

If you are required to enter password/passphrase, do the following
server_node$:  sudo apt-get install keychain

Add the following to your ~/.bashrc (depend on your shell)
if type keychain >/dev/null 2>/dev/null; then      keychain --nogui -q id_rsa      [ -f ~/.keychain/${HOSTNAME}-sh ] && . ~/.keychain/${HOSTNAME}-sh      [ -f ~/.keychain/${HOSTNAME}-sh-gpg ] && . ~/.keychain/${HOSTNAME}-sh-gpg
If you encounter syntax problems, please check the indent, make sure the indent are 4 spaces.


This is just one way process, if you want to mutual password-free, do it again on the client_node.  OR copy your .ssh files file server_node to client_node.

NOTE: If you manually copy id_rsa.pub, be aware of not overriding the key, rename the name before transmitting.

Thursday, October 31, 2013

The use of 'learned' and 'learnt'

Today, when I was revising my statement of purpose (SOP), I felt confused how to use the word 'learnt' correctly, and I think the information in this post is more convincing.

http://answers.yahoo.com/question/index?qid=20070317112122AATO9XB

In short, 'learnt' is the past tense of the verb 'learn' in British/European English, whereas 'learned' is the past participle of the verb 'learn' and (sometimes) can regarded as the past tense verb in American English.

BTW, you cannot use 'learnt' as an adjective neither.  Use 'learned'.

For example:
I want to learn French. (correct)
I learnt French last summer. (correct, more British)
I learned French last summer. (ok in American English)
I have learned French since last summer. (correct)
I have learnt French since last summer. (INCORRECT)

To sum up:
learned: past tense verb (American), past participle, adjective.
learnt: past tense verb (British/European).

I would like to use them in this way:
simple present verb - learn
simple past verb - learnt
past particle - learned
adjective - learned

Feel free to correct me if there is any misunderstanding, thanks!

Monday, October 28, 2013

身體若不好,人生和學習都會是黑白的

在連續暴肝以後,我的身體終於在大抗議了,今天曠課了一天,有一堂課還是要報告的...


我是個身體越差就會越胖的人,這兩個月來我的體脂已經從16暴增到接近19了,這還是在每週至少有運動兩天的情況下喔!我也知道我太勞累(特別是熬夜)的話,會有心悸的情況,心臟會痛,這我也知道。而今天是第一次遇到這種情況:除了左胸以外,連右胸也有感覺了,我甚至沒有辦法坐起來看書。於是只好果斷的翹掉早上的機器學習課程,好讓身體休息。

幸好,補眠了幾個小時以後,心痛的情況紓緩很多,但是勒...
在硬是起床把下午要用的簡報處理了一下之後,去小歇一下的結果就是...


哈囉!吃晚餐了喔~~


囧大了,我的學習、我的身體。

Saturday, October 19, 2013

[食譜] 麻油雞 black sesame oil chicken soup

麻油雞(或稱燒酒雞、雞酒),簡單來說就是使用胡麻油(和老薑)提香的雞湯,主要是用來冬令進補、或是婦女坐月子(胡麻油可幫助子宮收縮)。
Black seasame oil chicken soup is a famous, traditional Chinese cuisine, very popular in Winter days (to warm up body).  It is also recommended for women after menstruation or childbirth.

我一樣是寫比較道地口味的作法,然後會在後面FAQ補充可調整的部份。
In this post, I will make it more authentic, you can also make some changes to fit your preference, I will put some suggestions in the FAQ section.
I strongly recommend you to read the FAQ before start if you have no idea about this dish (do not waste food).

食材Ingredients

2013-10-19 19.25.03
雞肉
Chicken
老薑
Ginger
胡麻油(胡麻油大多是黑芝麻,香油大多是白芝麻,為了怕有人搞混,所以我特別寫胡麻油而不是簡稱麻油)
Black sesame oil
米酒
Rice wine(widely used in many Chinese cuisines)
其他的油,如沙拉油或橄欖油(不要用胡麻或初榨橄欖油)
another kind of oil e.g. oliver oil (never use "Extra virgin", it is for cool dishes)
糖,可有可無
Sugar(optional)


步驟Steps

1. 把老薑外皮刷洗乾淨,切薄片;或是把它拍碎(越薄會越入味)
Clean and slice (or squash) the ginger (the thiner ginger, then stronger flavor of it)


2. 熱鍋以後,單下雞皮逼出雞油,或是直接下沙拉油(如果你雞皮的量不夠或懶得皮肉分離的話)
Fry the chicken skin to get some oil from it. Or just use your oliver oil
2013-10-19 19.43.52
3. 煸炒薑片,炒出香味,此時火不要太大
Fry the ginger with medium temperature.
2013-10-19 19.46.01

4. 下雞肉炒至變色(半生熟)
Fry the chicken quickly, do not make it done.

Before
2013-10-19 19.53.02
After
2013-10-19 19.55.20


換個大的鍋子(嗯,因為我這邊只有平底鍋,如果你是圓的那種就不用),加入胡麻油跟米酒。不要加水!!!
Use your pot, add black seasame oil and LOTS of rice wine. NO WATER!!!
2013-10-19 19.59.31
6. 大火煮滾後轉小火悶雞肉
Boil the soup, then lower the temperature to make the chicken more soft.

2013-10-19 20.05.49
7. 放點糖據說可以讓口味溫和一點,不要放鹽!
Add some sugar, NO SALT!

8. 單吃太燥或太無趣的話也可以加點高麗菜、菇類、麵線、枸杞之類的(推薦可加麵線、因為裡面有內建鹽巴)
You can also add other ingredients such as mushrooms, vegetables, etc.
2013-10-19 20.24.00

FAQ

Q1:
我不喜歡這麼辣的味道耶?不加水不加鹽?你是喝醉了嗎??
Excuse me, I think it is bland and too hot.  Did I make it wrong? Can I add some salt or spice, or water?

Ans:
傳統補品是沒在加鹽的,而且正統麻油雞如果加水的話應該會被我們這種酒鬼大聲問候喔。不過呢!料理當然是吃的高興最重要,不夠味的話就在起鍋前加鹽,太辣或不喜歡酒味就加點水也是很ok的!
Yes! It is hot! Because it is the authentic one (remember? we eat it to warm up body).  However, you are more than welcome to add salt, reduce the wine, add some water etc.  Just make it tasty and enjoy it!

Q2:
為什麼不是直接用麻油去炒?要用另一種油?
Why you use two kinds of oil?

Ans:
胡麻油不耐高溫,所以要換一種油去炒,不然會苦
Black sesame oil will become bitter in high temperature (as well as the extra virgin oliver oil).