Thursday, 28 June 2012
Latte art
Yet another failure for my latte art today. I think this time the problem was not enough foam. This is indicated by liquid and runny milk which creates a homogeneous, light-brown coffee with no patterns. So to get more foam, I need to introduce more air during the frothing (stretching) phase. Today I was a little bit conservative in doing this because I was afraid of getting too many bubbles. I think my problem before may not be too many bubbles, but is not mixing the bubbles well enough with the milk during the second phase (mixing, texturing). During the frothing phase, the key is listening for a slight hissing sound and the milk should expand to two thirds of the pitcher. The holes of the steamer is about 1cm below the surface of the milk to introduce air into the milk.
Labels:
latte art
Friday, 15 June 2012
Common shell scripts
if
statementThe most compact syntax of the
if
command is:
if TEST-COMMANDS; then CONSEQUENT-COMMANDS; fiThe TEST-COMMAND list is executed, and if its return status is zero, the CONSEQUENT-COMMANDS list is executed. The return status is the exit status of the last command executed, or zero if no condition tested true. Expression used with
if
[-s FILE]
: True if FILE exists and has a size greater than zero.
Labels:
shell
Tuesday, 12 June 2012
Ruby: regex
The Ruby operator
Regular expression also defines
Regular expression options
=~
matches a string against a pattern. It returns character offset into the string at which the match occurred, or returns nil
if match fails. Your can put the regex first or the string first. Either way is ok. Because nit
is equivalent to false
in a boolean context, you can use the result as a condition in if
or while
statements.Regular expression also defines
===
as a simple pattern match:
case line when /title=(.*)/ puts "Title is #$1" when /track=(.*)/ puts "Track is #$1" when /artist=(.*)/ puts "Artist is #$1" end
Regular expression options
i
Case insensitive.o
Substitute once. Any#{...}
substitutions in a particular regular expression literal will be performed just once, the first time it is evaluated. Otherwise, the substitutions will be performed every time the literal generates aRegex
object.m
Multiline mode. Normally, "." matches any character except a newline. With the/m
option, "." matches any character.x
Extended mode. Complex regular expression can be difficult to read. Thex
option allows you to insert spaces and newlines in the pattern to make it more readable. You can also use#
to introduce comments.
Monday, 11 June 2012
Sunday, 10 June 2012
少食多餐有助减肥的理论依据
Saw a very nice article about dieting and weight loss recently. It talks about the importance of self-control and how successful weight-loss reflects strong character. It also mentions the term ego-depletion which is very interesting. Ego is one of the three parts (id, ego and super-ego) of the psychic apparatus defined by Sigmund Freud. The id is the set of uncoordinated instinctual trends; the ego is the organized, realistic part; and the super-ego plays the critical and moralizing role. The id acts according to the "pleasure principle", seeking to avoid pain or displeasure aroused by increases in instinctual tension. The super-ego works in contradiction to the id. It strives to act in a socially appropriate manner, whereas the id just wants instant self-gratification. The ego seeks to please the id's drive in realistic ways. It serves three severe masters...the external world (reality), the super-ego and the id, trying to bring harmony among the three. In doing so, the ego (self-control or willpower) can be exhausted because the super-ego's demands often oppose the id's, so the ego sometimes has a hard time in reconciling the two. Dieting is an example of this conflict. Our super-ego demands us to refrain from eating to have nice body, while our id wants to quench the hunger. Low blood sugar level can cause ego-depletion and this is why we often find ourselves eating a lot after a period of dieting, i.e. when the sugar level goes down when you are hungry. So maintaining a constant sugar level, not letting it to go dow to low is important to control your appetite and your willpower.
Here are some of the highlights.
漫漫减肥路,决定成败的关键因素是什么?是意志力,是自我控制的能力。控制自己对食物和美味的本能需求,拒绝香喷喷的高热量食物,减少进食量;控制自己在懒得抽筋儿的时候,翻身而起,滚去健身房一路狂奔。
自我消耗理论对减肥有何指导意义呢?减肥需要毅力,毅力和血糖密切相关。那么,保证血糖水平不处在过低的状态,就可以有效防止意志力崩溃,从而理智的控制进食量。不仅如此,血糖水平稳定,还有利于我们在完成其他工作的时候意志力增强,决策正确率提高哦。
综上,节食的最好方法就是让体内葡萄糖水平始终稳定在较正常的状态,不要过低,也就是说,不能过度饥饿。不挨饿,面对食物时就会做出更明智的选择,不会出现无理智的暴饮暴食现象。
笔者最近每日5餐,除3餐外,在每天上午10点和下午3点各加一顿,内容可以是点心或是坚果,当然,量都不能太大哈。正餐吃到八成饱就可以了,加餐热量控制在100或200卡以内。这样,可以保证全天不饿,血糖水平始终稳定,自控能力较强,从而能够减少正餐、加餐进食量,且学习、工作效率也很ok。
My resolution for the summer:
- Leave the apartment around 7:20am to catch the 7:30am bus. Start work latest at 10am in order to finish 4 pomodoros in the morning.
- Use a small plate for food and only get food from one stall. Only get vegetarian food plus fish and shrimp (with green or orange labels).
- Can have chicken (orange label) at most twice a week and red meat (red label) at most once a week if they look good.
- Only eat until 80% full. Chew more and eat slowly will make you feel more full. Savor the taste of food. (Or full for breakfast, 70% full for lunch, and 50% full for dinner)
- Drink a cup of water before the meal
- Eat some fruit at 10am and a pack of almonds at 4pm.
- Eat only green or orange label snacks. One green and one orange per day.
- Have balanced meals: starch (whole grain or whole wheat food), protein (tofu, diary, fish, shrimp, crab)
Labels:
diet
,
weight-loss
Saturday, 9 June 2012
C++ pointers
#include<stdlib.h> #include<iostream> using namespace std; int * foo (int a) { int i; int* p; i = a *p = i; return p; } int main(void) { int* q; int b = 10; q = foo(&b); return 0; }The problem with this code is that the pointer
p
is not initialized before it is dereferenced. This will cause a segmentation fault. So if we change *p = i
to p = &i
, the segmentation fault will be gone. A pointer should always be initialized with an address first.
However, there are other problems with the code, depending on the purpose of the function. If the intended outcome is that the returned pointer points to the same value as the input parameter, the code won't work either. After eliminating the segmentation fault, the code is like this:
int * foo (int a) { int i; int* p; i = a; p = &i; return p; }The returned pointer points to the local variable
i
which will be out of the scope once the function returns. Even if we set p = &a
, it won't work, because a
is also a local variable in the scope of function foo
only.
So in main
, q
will not point to b
because when we call foo(b)
, the value of b
is copied to the local variable a
which has a different address than b
.
To get the intended behavior, we need to have something like this:
#include<stdlib.h> #include<iostream> using namespace std; int * foo (int* a) { int* p; cout << "p = " << p << endl; p = a; cout << "p = " << p << endl; return p; } int main(void) { int* q;it should work int b = 10; q = foo(&b); cout << "&b = " << &b << endl; cout << "q = " << q << endl; cout << "b = " << b << endl; cout << "*q = " << *q << endl; return 0; }
Labels:
c++
Subscribe to:
Posts
(
Atom
)