Peter's profilepMouse嘅個性空間PhotosBlogListsMore Tools Help

Peter Qian

Occupation
Location
Photo 1 of 10
Thanks for visiting!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
jUnE LeRwrote:
hey there, how are u?
need to inform u, bcos u've the pictures of where my memories is - MCMASTER
I've jes grabbed a few of them, hope that u don't mind, much thanks!
Aug. 10
dorawrote:
其实我也是查Escalation of commitment到这的,倒不是想知道,是有人查这个查到我space
所以我也随手翻翻。很多技术的东西啊,不错。
Dec. 30
HOU Rebeccawrote:
查Escalation竟然查到你这里了,呵呵,我在思考发生这种事情的原因,怎样避免Escalation呢?
头疼ing
Oct. 27
Dora Youngwrote:
眼前白茫茫一片
闲置的留言板么...
终于可以爬上来了
不过...发现你写的那些高端的东西完全看不懂...
还是不要插嘴了吧
踩一脚,想必你也不会有意见
Oct. 14
Lists

pMouse嘅個性空間

Life is dull by itself, those who live it make it shines
December 18

Redmond的雪

早就听说西雅图冬天不怎么下雪,城市里没有对付雪天的铲雪撒盐车服务,而且普通民众的雪地开车技术也几乎为零,所以一旦飘几片雪花,地上有几个厘米的积雪,便是不得了的大事儿。更何况像今天这种在多伦多也算的危险冬季气候的超过10厘米的降雪,这样的天气在西雅图,应该算是雪灾了吧。
 
从昨儿晚上开始老天就像发了疯一样,先是冰雨,然后大雪下了一夜。早上起来隔着窗户看外面白皑皑的一片,感觉像是又回到了加拿大。凭借着自己在加拿大冬天雪上混出来的经验,以及小A4的四轮驱动,我草草吃过早饭后就开始驱车往公司进发。本来嘛,10厘米的降雪在寒民屯(Hamilton)算是家常便饭,大家的生活还是一切照常的。
 
一出小区我就立刻发现大雪对西雅图来说是多么的不正常。本来的马路已经看不到了,和行人道一起被雪埋在了下面,路上几步就有一辆被抛弃在路上的车,车主估计放弃在雪地里继续前进,要么去搬救兵,要么回家睡觉去了。开到高速口上发现加速道上歪歪扭扭的停了两部巴士,估计都被卡在那里了,高速入口有看起来像电视台的记者对着一台摄影机,拿着话筒在说些什么,看来高速路是被封闭了。于是我沿着小路往前开,没走一公里就发现前面堵了几辆车,开到跟前一看才知道是一部红色的两门小Civic爬不动了,被卡在雪里。后面几部车的司机都在帮忙推车。
 
我于是也下车走上前去帮忙。一下车才发现地上不但有雪,还积了一层冰。人在路上走都能冷不丁的滑个跟头。帮忙推车的人因为自己也站不稳,所以车自然也推不出去。看来美国人是完全没有雪地经验的。我走上去问小CIVIC的车主人要了他车上的垫脚地毯,铺在车前卡在轮胎下,这才算是把车开了出去。
 
继续往前走,一路上碰到各式各样的车被卡在雪里或冰上。我也自然是每开几百米就下车一次帮忙推车,并以地毯或者路边的泥土辅助。平时10分钟的车程,开了足足1个半小时才到了公司。进了办公室发现,我们组的人只有我来上班了。
 
唉,瞎忙一场,转身往下班的路上进发。
November 24

Seeking with XmlReader and Linq to XML

The usage of XmlReader in the .net framework provides a sequencial way to access XML data in a stream. Simple FSM parsers can be easily built on top of this tool. However, sometimes users would want to seek ahead in the stream, and then back track to a previous point. For example, you may want to verify the existence of a particular tag, and read its value ahead of everything else. Right now there is no good way to seek in the reader object, especially if the underlying stream is a ConnectedStream across the network. However, Linq to XML's XElement gives us a nice "cache" to allow peek ahead and resetting in the XmlReader based parsers, even if the underlying stream does not support seeking.
 
What you need to do is to create an XElement object from the reader, close the reader, and then use the XElement instead:
 
XElement element = XElement.Load(reader);
reader.Close();
reader = element.CreateReader();
 
// Here you can peek ahead
 
// and here the reader gets reset to the beginning
reader.Close();
reader = element.CreateReader();
For Example, the following code uses XmlReader to read the feed from Live Space. It reads the XmlDocument to see how many "items" entries there is, and then asks the user whether to continue or not. If the user selects Y, then the entire document is displayed in an indented view.

private int CountEntries(ref XmlReader reader)
{
    XElement element = XElement.Load(reader);

    reader.Close();
    reader = element.CreateReader();

    int count = 0;
   
    while (reader.Read())
    {
        switch (reader.NodeType)
        {
            case XmlNodeType.Element:
                if (reader.LocalName == "item")
                {
                    count++;
                }
                break;
        }
    }

    reader.Close();
    reader = element.CreateReader();

    return count;
}

private void SimpleFSMParser(XmlReader reader)
{
    int indentLevel = 0;
    while (reader.Read())
    {
        for (int i = 0; i < indentLevel; ++i)
        {
            Console.Write("-");
        }

        switch (reader.NodeType)
        {
            case XmlNodeType.Element:
                Console.Write("Found Element {0} in namespace {1}",
                    reader.LocalName,
                    reader.NamespaceURI);
                indentLevel++;
                break;
            case XmlNodeType.EndElement:
                indentLevel--;
                break;
            case XmlNodeType.Text:
                Console.WriteLine("Element Content {0}", reader.Value);
                break;
        }
        Console.Write("\n");

    }
}

To invoke the code:
XmlReader r = new XmlTextReader("http://pmouse.spaces.live.com/feed.rss");
int count = CountEntries( ref r );
Console.WriteLine("Found {0} Entries, continue? [Y/N]", count);
string input = Console.ReadLine();
if (input.Equals("y", StringComparison.CurrentCultureIgnoreCase))
{
    SimpleFSMParser(r);
}

Note that after the XElement is created, the entire feed exist in memory rather than as a ConnectedStream. The extra memory usage is the cost of seeking, and the performance gain for not enumerating over sockets twice.

October 25

Redmond的阴谋

早就听说Redmond很闷。我来Interview之前,有个在微软做INTERN的朋友跟我说他再也不想回来,虽然工资很高,但是无法弥补无聊的生活所带来的创伤。我没当回事,在那时的我看来,没有地方比HAMILTON还要闷。

来到这里才发现原来一个城市可以死气沉沉到这么有水平。来了后所认识的一大帮朋友几乎每个周末都会一起发愁干些什么。我想他们一定已经习惯了这种无结果的讨论,每当大家最后决定各回各家的时候,最扫兴的那个大概应该是我。怎么就来到这样一个地方呢?

究竟有多闷,可以举个例子来说明。本周末的活动是去吃一顿像样的中餐,这已经是几天前安排好的,一大帮人需要驱车40分钟就为了吃一顿饭。这让我想起了90年代初深圳人为了吃海鲜顺着泥路开一个小时到“沙尾”海边的情景。My God,我曾经以为在Hamilton开车到Saga去吃正宗川菜已经算是我的极限了。真是无限怀念在北京下楼就有的各种好吃的。

每当一个人在家对着四面墙的时候就在想,到底有些什么可以做的。慢慢的在公司做事闲暇的时候也开始想有什么可以做的。最后发展为干脆直接去公司呆着。既然来到公司了,那就干点活儿吧。就这样,微软又多了一个七天上班的员工。某一天我突然醒悟了,为什么当初那个Intern朋友再也不想回来微软,恐怕等他跳出这个城市,才发现这是一种多么不正常的生活。或许Redmond的环境是由微软,也就是这地盘的老大说了算的,它故意的把周围营造出一片死气沉沉的气氛,然后让其员工不得以的自愿加班。真是一个高明的“阴谋”。

好吧,既然看穿了公司的诡计,我决定将计就计。我要趁周末加班的时候使劲的喝公司的各种饮料,牛奶咖啡,可乐橙汁……

Wait…这难道就是为什么在公司10年以上的Lead们一个个都是大胖子的原因吗?

October 18

买车了

咬咬牙,把心一横,哥们儿也是有车族了。虽然只是个二手的小奥迪,但是六速手档和博士音响绝对是我梦幻车的必备装备。既然遇到这个机会,就把它拿下吧。

$19909, 2005 AUDI A4 Quattro 1.8T Sports Edition, 33700miles :)

终于又开上了手动车,时隔6年完全的不适应了,半路死火是必然的,不过华盛顿州的居民们貌似很理解这种情况,换作要是在北京,已经被人DI死了。

Redmond 013

更多图片

October 07

Redmond的阳光

Redmond 036

(更多图片见Album)

都说西雅图是个雨城,一年里有三分二的时间在下雨。在这样的一个雨城里生活,能见到阳光的日子自然是不可多得的。今天少有的艳阳天让我体验了一下雨过天晴的清爽,一洗“淫雨霏霏”的晦气。这样的天气不出去转转真是浪费了。这不,趁下午工作的空闲跑出来拍拍四周的花草树木,和蓝天里漂浮着的一缕缕轻云。

阳光下这样的一个城市,还是蛮可爱的。