Let PowerShell to summarize your IM history

(March 25, 2007) Update: Thanks to James Manning for the -passthru parameter to simply the command.

Windows PowerShell, also known as “Monad”, is a cool shell environment to replace old CMD shell under Windows. It is an object oriented shell and it allow easy manipulation of different types of objects interactively. Another advantage is the support of various data structures and formats, such as XML. Just like other good old shells, it also supports piping. The difference is that, instead of text stream, it sends objects through the pipes.

I always want to find out some information about my Live Messenger history. Now let’s see what PowerShell can do with it. In most cases, Live Messenger history is saved under “My Received Files\<Live ID with some numbers>\History” in your Document folder. Now let’s boot into PowerShell and “Set-Location” or ”cd” to this folder. If you type “Get-ChildItem” or “dir” you will see a bunch of .xml files listed.

Alright, let’s first try to find the top 10 friends with most letters:

Get-ChildItem | Sort-Object Length -descending | Select-Object -first 10

At this point, I assume you are already familiar with the concept of piping. Here it gets a list of files, sort it and display the first 10. That’s not too difficult to understand.

Actually those files are in XML format. That’s why it ends with .xml extension. One important XML element in these files is the message. Each message element corresponds to a sentence sent between me and my friend. Let’s see how PowerShell deals with XML files in this case. The following command lists the top 10 friends with most messages:

Get-ChildItem |
ForEach-Object {
    $_ |
    Add-Member noteproperty -name count -value ([XML] (Get-Content $_ -Encoding UTF8)).Log.Message.Count -passthru
} |
Sort-Object -property count -descending |
Select-Object -first 10 |
Format-Table count,Name

It first gets a list of files. For each file, it creates a new object $o. Then it adds the count of messages from the XML file as a property of $o, as well as the name of each file. Finally, it sorts the object based on number of messages and displays the top 10.

Another interesting XML element of Live Messenger history file is LastSessionID. I guess It is the number of chat sessions established by either me or my friend. With a little modification to the previous command, I can know the top 10 friends with most sessions:

Get-ChildItem |
ForEach-Object {
    $_ |
    Add-Member noteproperty -name count -value ([Int32] ([XML] (Get-Content $_ -Encoding UTF8)).Log.LastSessionID) -passthru
} |
Sort-Object -property count -descending |
Select-Object -first 10 |
Format-Table count,Name

A small change is that LastSessionsID is read as a string. So we have to convert it to a integer number using [Int32].

Other XML elements, such as Date, Time and even text in each message, are very informative too, as long as you can explorer them in a good way. Right now, there are other more information I can think of out of my head, e.g. the top 10 longest message you received, the first 10 person talked with you, the longest 10 chat sessions in your IM history and so on.

For updated information and tricks on PowerShell, here is a good resource. If you have used Live Messenger on two or more computers, you might also want to consider this history merger.

Guess who sends the most smiles to me? 🙂

Be confident

This is either a big or a small problem. But it is no problem to understand that confidence is important for one to survive in its group, its industry and even in its life. Some people finds itself lack of confidence but others are not. I am for sure not the latter case. So I want to put myself a little note here to summarize what I brainstormed. and get ready for other suggestions.

So, it all comes to 3 simple questions as follows.

  • What is confidence?

Without directly looking into my good old Oxford dictionary, the first interpretation of confidence that comes out of my head is that you believe in yourself when you speak and behave. You know what you are doing is right and what you are saying is correct. Lacking of confidence, in this case, is that you are afraid to talk and act because the uncertainty exists in your mind. It can be that you are involved in a challenging workplace and everyone seems to be smarter than you. So you are more convinced by others instead of convincing others. I guess this is my current situation.

  • Why need confidence?

You want to grow. Growing needs confidence. With confidence you can ask questions in depth, do certain give-it-a-try works and eventually gain knowledge on what you have heard and seen. Meanwhile, growing means getting familiar with the area you are in, so you will be convincing others more often. The biggest side effect of this is that you get to be even more confident, so the question becomes an answer to itself. It’s like investment that you invest your current amount of money to earn more.

  • How to establish confidence?

One often finds itself confidence in particular area after some milestone it reached in its past. Such milestone can be a diplomas, a certificate or any remarkable award. It proves the skills the holder had in some ways. But that’s not always really true. I just had my road test for driving license last month, but now I am still not sure if I can take a car and give a ride on the express way. It seems like experience plays a more important role in establishing the confidence. Alrite, you take a deep breath and get your feet wet. That’s where experience starts from. Once you are comfortable with it, which means you have a minimum confidence, then invest it. Keep growing it until someone tells you you are over confident. Well, that’s another issue.

Quick and Dirty

How do you solve the problem that a single page cannot display two sets of information in different character encodings under IE? I had this problem in the counterize plugin for WordPress, since the default page is in UTF-8 but the IP location information retrieved from somewhere else is in GB2312. So everytime I have to switch back and forth in IE -> View -> Encoding. Apparently Firefox does not have this problem. I don’t know how does it detects the GB2312 text and displays it correctly. But I do have a work around for this.

It is fairly simple. Create a separete page with its default encoding set to GB2312 and retrieves whatever information in GB2312 it wants. Then in the UTF-8 page that used to be problematic, replace the original script calls with iframe calls to the new GB2312 page. That’s it!

Example: Replace something like

<script src=”a.php?some=parameters”></script>

with something like

<iframe src=”b.php?some=parameters”></iframe>

where in b.php it passes some=parameters to a.php directly by using the script tag.

One more advantage is that when browser creates iframe objects, it creates a separate thread for loading the framed page. It allows constant information in the UTF-8 page to be displayed first while GB2312 page is loading, instead of waiting long for the GB2312 text to be retrieved and the displays the rest of the main page.

It is quick and dirty, but as long as it works, I’m fine with it. Remember to set the iframe to be borderless and transparent.

Zhengzhou Noodles

OK, most of you have heard of Shanghai Noodles. It is very popular in Chinese-like food courts and cafeterias in North America. I guess it pretty much because it is low cost and its recipe is simple to follow. Sometime it is called Lo Mein (捞面), means “noodles out of soup” in Chinese, to differentiate from soup noodles. In Chinese foods, Lo Mein from various cities can be very different. The differences take places in preparation and ingredients.

Zhengzhou Noodles

This evening, I made myself my favorite Lo Mein. It is called Zhengzhou Noodles with Pork and Spinach, where Zhengzhou is the capital city of Henan Province, and it is my town where I was born. Just like Shanghai Noodles, its recipe is very simple too.

Ingredients: Any kinds of noodles (e.g. wheat noodles), Any kind of grounded meat (e.g. pork), any kind of green leaf vegetable (e.g. spinach), raw garlic (4 slices, grounded), oil, soy sauce and salt.

I never find out how much some item in the ingredients is required, because I hate to remember the numbers and units. Take a look at the above picture and figure it out yourself. Actually the ingredients are not important here. It is the preparation identifies Zhengzhou Noodles.

Preparation:

  1. Prepare the noodles in the normal way. Take away the water and cool down in a plate.
  2. Put 2 spoons of oil in a frying pan and turn on the stove.
  3. When it is hot enough, put the grounded pork and 4 spoons of soy sauce in.
  4. Stir frying for a minute, then put spinach in.
  5. Keep stirring until spinach is soften.
  6. Add some water and wait until it boils.
  7. Turn off the stove. Add grounded garlic and salt according to your taste.
  8. Mix with noodles and enjoy it.

My father taught me how to make it on phone when I first learned cooking in Canada. Before I learned cooking other foods, I made myself Zhengzhou noodles almost every week. I tried different noodles, meat and vegetables but this one is my favorite. My mother loves to add some vinegar and that sometimes makes my mouth running too.

已不是我(上)

在办公室的时候,又一次在 MSN 上被请教如何去 emerge 某个 ebuild。那个朋友说他每次到最后都会得到一个 Segmentation Fault,应该怎么办?我说,我已不是我。关于这个朋友的问题,我发了几个网页给他,然后就解决了。他对此很感谢,说他现在已经迷上了他所接触的东西。我心里于是不知道有什么东西“碰“了一下。很久以前,我曾经坐在同样的命令行前。眼睛没有离开过屏幕整整 22 个小时,我却根本不辛苦。相反,那是一件很享受的事情。最后要结束的几个小时里,我甚至会异想天开自己就是 Neo,看到的就是一行行滑落的 Matrix。我也曾经陈不住气地向所有的朋友宣布,这就是我的梦想。现在看来,那样的水平也想出来混。呵,幼稚。

很久没有对那时候的爱好再那么歇斯底里了。我并没有忘记,只是更愿意完全抛弃过去的所学、所想。因为那些只是技术,并不是宗教。既然是技术,掌握就好。无谓的说教和争论,和我无关。这各阶段的进化,正式终止。我把过去若干年来对电脑的兴趣规划成三个阶段。我管每各阶段都叫做一次进化。对这个世界来说,每个阶段只是又多了一个 Geek;而对这个 Geek 来说,每次进化就是多了一个世界。虽然没有太大的成绩,但是从最早的兴趣开始到现在,也有一段时间了。有些东西很想记录下来,所以就写在这里,留给未来的我看。

我和计算机的接触开始于 7、8 岁时在母亲所在的单位地上捡起来的很奇怪的纸条。我会在上面画画,或者把纸条撕个粉碎,然后幸灾乐祸地看着母亲去收拾。现在想起来,上面那些密密麻麻的小孔竟然就是我们现在众所周知的 Software。那些打孔机器就像科幻电影那样兹兹地响着,我不知道那是什么。当时的我做梦都不会想到,若干年后我竟要以这些小孔所代表的 1 和 0 赖以为生。那时候的记忆我留存的不多了,但可以算是冥冥之中带我走向之后三次进化的宿命吧。

在我小学五年级的时候,也就是在 93 年的暑假,我辍学了。我和父亲、母亲,还有孪生的哥哥离开了老家,去了一个叫做深圳的小村庄。母亲因此离开了之前的单位,我也以为与那些打孔机器从此无缘。深圳离另外一个稍微大一点叫做香港的村庄很近,因此生活……不,电视也更加多彩。很快,家人就发现这样的多彩并不生活。看着别人家的孩子都参加各种培训班,我也被列入了一个之后让我父亲十分后悔的计划中,那就是把我和哥哥送去一个位于深圳市青少年宫的电脑班。之前还非常担心我们没有求知欲,能不能在里面呆上两天还是跟问题。那时候学的东西很先进,比如 DOS 和 Turbo BASIC。而且是在当时最快的 386 上运行的。也就是那短短的几天,让我进入了一个从来没有体验过的世界。

很快,一个星期过去了,一个月过去了。我把每天的生活都放在了电脑班、旁边图书馆的电脑书籍区里。很幼稚地把某个教材里的代码抄下来,然后写在家里的电脑上运行。然后修修改改,乐在其中。时间因此过得飞快,我也在深圳的一个小学百无聊赖地混完了六年级,然后混到了小学对面的中学。但是每天的生活还是没有变,放学回家就坐在电脑前,一直到睡觉。理所当然地,我的学习成绩一落千丈,因为我不务正业的时间实在太多了。甚至有几次父亲都想把那些电脑都砸了。哥哥也好不到哪里去,跟我为了争坐在电脑前面的时间吵得不可开交是经常的事情。因为理科成绩不理想,高中的时候我就读于文科班。那时候的成绩排名,好几次在全年级竟然是倒数一二。虽然都是成绩单上写的,没有公开,我也会不知廉耻地拿着到处炫耀。那些好学生、奥数尖子、老师的重点培养对象们避之不得。(一直到现在还在炫耀,借光鄙视一下自己。)再那样下去,我可能连大学都考不上。家里面开始重新思考我的出路,在我不知情的情况下,密谋了一个改变我一生的计划……(上、

&ldquo;我等着你回来,我等着你回来&rdquo;

想象一下将要结束的假期,还有不见许久的同事,很多刚刚结束春节长假的上班族可能都会期待从新回到离别已久的办公室。当然,前提是你超级喜欢自己的这份工作。期待之后是什么?很多人都会说不上来。但是,我们马上就要结束产假,明天就要回来上班的 Andy 肯定会疯掉。(木哈哈,想起他明天那个时候的表情我就想笑。)在微软,有一个传统跟闹洞房很像,只不过闹得目标不是人,而是——办公室。每当一个同事放假即将归来的时候,所有人就会提前去把这个员工的办公室“收拾”一番。没听懂么?这有个例子:

好吧,反正他不懂中文,我就放心大胆地说出来吧。这次我们的计划是,把所有人的照片都打印成大头贴,然后贴在他办公室里面所有能贴的地方。请不要局限你的思维,这里说的是所有物理条件、化学条件都允许的地方——想象一下那个每一个按键都被贴上头像的102键键盘 :)大家虽然都是做办公室搞脑力活动的,但是在整人方面动作也很快。大概半个小时就让 Andy 的办公室基本上除了每个人的大头贴其它什么也看不到。一位仁兄大概算了一下,如果每天花一个小时去十张大头贴的话(工作任务第一),少说都得三、四个月才得让办公室恢复原样吧,木哈哈哈……康桑巴米达,Music!“我们等着你回来,我们等着你回来。”

Transportation in Great Seattle Area

If you go to previous post, you will see the pictures I took during my visit to Seattle downtown with her. I like not only this city very much, but also the surrounding areas. There are many great places to take a look. The Lake Washington divides the whole area into two parts, the Seattle city and the eastside, where the eastside is where I work and live. Although I don’t have a vehicle so far, it is not difficult for me to travel among all these cities, because there are resources and flexible commute combinations to access and use.

Most of the time, I take bus. Before I go to some place, the first thing I do is to visit the Online Trip Planner. It is a great tool and it really helped me a lot for my settlement in last month. In the page, you enter the starting point and the destination, the date of the trip (schedules for most routes are different in weekdays and weekend), how far you want to walk and other preferences. I usually choose Fewest Transfers since I am really lazy :P. Then after a click on [Plan Trip] button, it shows several itineraries according to your need. Another neat feature I like, is the Plan Return Trip in the result page, so I don’t have to re-enter everything again for my return.

Another useful tool for taking a bus on time, is Seattle Bus Tracker. Simple enter the route number at the upper left corner, it then shows the locations of the buses for a specific route in real time. It is a great replacement to the bus schedule lookup table. Need to mention that this nice tool is based on Microsoft Virtual Earth.

In some cases, the place I want to go cannot be reached by a bus, such as trails at Redmond. That’s one of the reasons why I bought a bike. Bike is a convenient tool for traveling, but it doesn’t help much if you are thinking about going to Pike Place Market from Redmond and come back. Fortunately, there is a solution to that if you prefer to ride your bike at both ends. Both of the transit companies, Sound Transit and Metro Bus, have bicycle racks installed on their buses that allows passengers travel with their bikes. I was surprised about it when I first came and it strongly supports my decision to get a bike. More resources for biking in this area are here.

If you drive, there are other commute choices such as carpool, vanpool and Park-n-Ride. All these different methods of traveling can also be combined, for instance having a bicycle rack installed on the vanpool vehicles. So, where do you want to go today?