Saturday, August 27, 2011

Syntax-highlight pager in windows 7 command line

If you are like me, programming under windows command line a lot, you will miss a handy syntax-highlight pager to quickly display beautiful codes under windows command line.

I know, there are a lot of source code editors in windows, like notepad++, source insight, notepad2, editplus, etc.
However, none of them will work under command line.
We both know that pop-up windows will interrupt your work and force you using mouse.
vim for windows might be a nice choice, but it is too "big" and boo complex for simply reading some code snippets.
Yes what we really need is "less" + "syntax highlight", and that's all.

There are many tools (GNU Source-highlight , highlight) on Linux are able to translate source code into some kinds of formatted text.
If we use "GNU Source-highlight" to highlight source code with escaped ANSI code, and pipe them into "less" command, it should do the job.

Under Linux, that is the complete solution (please refer to this article).
But it won't work under windows 7 command line, even with ported version of "Srouce-highlight" and "less".
The point is that windows 7 command line does not support escaped code!
It's tricky, but finally we overcome this by using a patched version of CMD.
Thanks to Jason Hood, we get ansicon, a escaped code enabled CMD for both 32-bit and 64-bit windows.
you can use it to replace system CMD, or call it after you entering CMD; both of them will work.

Okay, now it comes the whole solution for enabling syntax-highlight pager in windows 7.

1. You need to download and install windows ports of
Source-Highlight
,
unix-util (for less command) and
ansicon.
Please to be noted that all these excusables should be added into system PATH.

2. Add a BAT file called "cless.bat" in your system folder,
@ECHO OFF
source-highlight --out-format=esc --style-file=texinfo.style -i %1 -o STDOUT | less -R -N
This file will call source-highlight with your given file, and pipe the escaped code
into "less" command. The option "--style-file=texinfo.style" sets the style of
your syntax-highlight.
For windows command line, I personally prefer "texinfo" simple white-black style (As the picture bellow).

3. when you need to use it, open an "ansicon" command line window and type
"cless your-source-code-file", then enjoy the nice syntax-highlight pager!


This is sample for "texinfo" style syntax-highlight pager.

P.S. If you are using cygwin or MSYS in windows, this solution will not be needed.

Saturday, February 26, 2011

长大,老去

先来一首 来自 希小包 翻唱的 越长大越孤单,我个人很喜欢她翻唱的歌曲。



到了我们这个年纪,与其说长大,不如说老去。很多以前不明白的东西,现在开始明白了。
比如说,以前我不明白为什么要结婚生子,在以前,我一直不能深刻地了解,现在逐渐感觉到,生命是如此短暂,只有你的子女才能延续你的 DNA,延续你的存在。

再比如说关于写技术文章和书籍吧,这也是我之前一直没动力做的事情(现在刚刚开始反思而已)。现在想想逐渐开始明白了,也许你平时自己有过很多思考,有过很多想法,但是如果你不把他们分享出来的话,带进棺材是没有用的。知识也只是生不带来死不带去的东西,为了让你的毕生所学百年之后没有白费,写书写paper是最好的方式。

我不是怕死,其实想通了死也就是那么回事,死了之后什么都没有了,也不会难过,也不会伤心。所以本不应该对自己的老去担心,那我们是在担心什么呢?对,老去便意味着无能,便意味着你不中用了……我们怕的是被淘汰,被冷落。 这种担心对于IT行业来说尤为厉害。 看着IT行业中的小辈们,“后生可畏”便常常在我脑中响起。这种担心每个人都会遇到,时间问题。 不过仔细想想,这也还是自己看不开了。所谓知足乃是最大的快乐,输了又如何?为了这些生不带来死不带去的东西,何必呢?

最后想说的是,还是多多锻炼身体吧,这样在老去的时候也不会那么痛苦,虽然死了是没什么了,但是半死不活时候也不好过。

Thursday, February 24, 2011

Summer, 2008 (2)

This is a blog copied from my Live Space, published on  8/25/2009 6:44:37 PM

It’s time to continue my story.

Since someone mentioned George in the comments, I would like to say something about him first. Though I didn’t talk with him very much, most of time he began the dialogue for correcting my English spelling or grammar errors… A little embarrassing, but I enjoy it more ;-) His first impressive criticism to me is, I still remember, one day when we were chatting about the delay of project, he pointed me out that “how could you (a intern) have such thought!!!” By the way, his driving skill is also very impressive: comparing with Tianchi driving super slowly, George can let you feel the speed and acceleration.

Someone may wonder why I post this blog at this time. The answer is simple: it’s time to leave. Today, is Aug. 26th, a month after my birthday. I always hate this date, because it means the ending of Summer holiday in last decade years. But in 2008, I would just end my intern and leave STB (I remember I still didn’t get the ID card then); this year, I will set off to UCLA in few days.

In that days, we dine out together time to time, and usually we will chose a small restaurant close to Jiaotong University(I forget its name), or “把角川菜馆”. I didn’t eat spicy food before those days, nevertheless, I gradually adapted to those food (even liked them) under the “encourage” and “force” of guys in my team. Honestly, I still miss that delicious food today. Sometimes, we will eat in some big restaurants, which especially likely to happen after team meeting and some big guy (like George, Jun, …) will pay the bill. So I was longing for team meeting at that time.



Oh, team meeting…. It’s really unforgettable. I think it’s first time I realize how poor my expression is. I didn’t organize the speech structure well, let alone the content. The coolest words on the meeting, I think, are from Jun Su: “let’s stop this topic here” or ” Never consider it!”.

Jun Su, our tech-leader and my direct reporter. The truth is he knew me very much, but I knew him a little. He always smile when we took conversation, however, I was in awe of that most time(I don’t know why, maybe it’s because he know me toooooooo well, even better than myself). Every time think of him, I just can’t help to associate him with “small chatting room”. Because most of time he will make a conversation with us in a “small chatting room”, and I used felt curious when I saw someone entering the room with him and getting out a hour later like nothing has happened, until one day, I was asked to chat with him in that room. A word, I think which could change all my life, describing my character and weakness, learned from him: “un-mature”. Yes, it just like a stone hit the surface of water, I began to pour all ideas or problems in my mind to him, including problem with girlfriend. Yes, he is far more than a tech-leader, but a doctor, a doctor for your heart. Jun, thank you again.


At last, I have to mention Renqi Zhu. He is the close friend of Qing Zhi (work together, eat together (even eat same noodle), walk together and chat together …). However, this two-guys’ world was destroyed after my join – I became the third person. It’s OK, it’s ok … they usually still unite together against me. I remember he was working on the low lever communication protocol before I left, about which we should have a discussion … but it never happened.

To be continued,

Mian Qin,

Mingqing Wei,

Yan Huang,

Mingyu Wang

Yiding Zhou,

Qiufang Shi, Yutong Sun,
Keshuang Shen,
Violet Cong...

Summer, 2008 (1)

This is a blog copied from my Live Space, published on  8/14/2009 5:00:37 PM
I have a very poor memory, most of people in my college life are fading out after two month of my graduation. However, some names or some memory fragments just keep bubbling up recently, and they even become more and more clear ... I know that, I will never forget the days I was in MS STB, and the colleagues there, the summer of 2008.

Please, please let me record part of my memory, some lovely people in the MS STB, one by one...

Zhen Wei, he is the first one I know in the MS; yes, he gave me the tel-interview. I still remember the telephone he gave me that afternoon: a very young voice came from the other end of the line, which even make me think he just graduate too. Later I knew that he is one of the most senior Dev in our teem. Though he is very kind in the phone, I still can't help to be nerves. Lucky for me, he still give me a chance to take the interview...... In fact I find we have a lot of common points: He like working at night, so do I; he like play Terran in the SC, so do I; He is not very tall, so do I...  But there is one big difference : He like spicy food very much, I don't.

Qing Zhi, my mentor, a very kind and patient guy. I think at this time(when I writing this Blog), he will feel very happy, because he has just become a father. Congratulations for you, Qing. Could you tell me is it a girl or a boy ?
Yes, he is much more than just my mentor, also is one of my best work partner, and friends. Because we have totally different characters: I like adventure and look forward, be impatient sometime, while he always thinks very carefully and looks around in the work...So we are born to be best partners ( thanks to the arrangement of Jun Su, our tech leader) . Every time when I have some new but un-mature ideas, I will discuss them with him first, and ask for his opinions. He always give me help and courage, even sometime I did really bad. At that time, we always take meals together: some days we will argue some topics on the table and other days we talk about life, future... The happy time with him, I will never forget.

Tianchi Ma, Oh, he used studied in my university, Zhejiang Univeristy. Yes he really is a genius in our team. The first contact of us is on my camper, after the MS college teach-In. We have a long talk that day, and we also exchanged opinions about my career, about the Microsoft. He gave me my first task in MS, to implement the Map-Reduce framework prototype. We were coding, seeking bugs together, and he always keep saying "对不对啦" after having an idea.  In my memory, there is never a problem could stuck him; every time when I have troubles in the work, he always could help me solve them. More than that, not only his work, he also be good at music, classic literature, .... I still remember we recite archaic poems together on the way back from KTV, he can remember much more than me ...


to be continued...

Jun Su,
Yiding Zhou,
George Yan,
Yutong Sun,
Keshuang Shen,
Violet Cong...

Sunday, February 13, 2011

牵手,For Valentine's Day


This is a very old Chinese song, and occasionally picked up by me tonight. I still remember when I was a child, my Mom would sing this song time to time. On those days, I could not fully understand what does it mean, but feel the smooth melody.

Yes, it is a love story, for a girl with strong mind on her love. After sharing happy, sorrow, worry and frustration of love, she stopped struggling. There was a time she felt upset and doubting about her love: whether it is the kind of life she want, or his hand would be the only support in her life. The truth is that life will always be tough no matter what you chose, so why not just put your hearts together, and feel each other. yes, let it go; follow your feeling and let your dream fly.


没有风雨躲得过,没有坎坷躲得过,所以安心地牵你的手,不必想该不该回头。
也许牵了手的手,前生不一定好走;也许牵了手的手,今生还要更忙碌。

For foreign students, we used to face the same doubting. Is it really worth to risk our whole youth to pursuit a better tomorrow. Now the answer is clear : "因为爱着你的爱,因为梦着你的梦,所以悲伤这你的悲伤,幸福着你的幸福;因为路过你的路,因为苦过你的苦,所以快乐着你的快乐,追逐着你的追逐“ Because of love, just let it fly, we do not regret for what we lose (or gain)!

Thursday, January 27, 2011

其实我很在乎你/车静子



我求求你了,不要这么纠结好不好,
你纠结了,我就想分享,
其实这个歌很俗的,很俗很俗很俗的;

但是可能是里面的那么多的无奈打动了我,

世界上最遥远的距离,不是生与死,不是天涯和海角~
而是两颗相爱,相视,却不能相依的心~

/////////////////////////////////////////////////////

好吧,换个角度: 是不是到手的东西永远都不重要呢?
不珍惜现在拥有的,永远都不会有得到。

/////////////////////////////////////////////////////
好吧,其实刚才我理解错了,只是这个女孩不懂拒绝;
其实,我很能理解这种感受,因为我也只是一个不懂拒绝的可怜虫罢了,sigh~

Sunday, January 16, 2011

張衛健 - 身體健康 Keep Healthy

For the one you love, please live healthy.



It's such a touching mtv, delivering a simple truth that not everyone can understand.
Death actually is not that bad for yourself, but it's fatal for the ones who loved you.
Please carefully watch this MV; You don't need to actually understand what he was singing, but you can feel it.

For her / him,
please don't work too hard,
please don't stay up too late,
please don't be lazy to prepare food,
please don't be lazy to do exercises,
please .....

  我不怕为你吃亏
  多苦的工作也愿意奉陪
  我只怕熬夜太累
  错过了我们明天的约会
  我不怕满脸汗水
  盖一个属于我们的堡垒
  我只怕感冒的我
  尝不到你为我做的菜
  有多浪费
......

下面是国语版的曲子,虽然没有画面,但是一样的感动。
这首曲子,让我们明白,作为男人,只有健康,才能撑起一个家,才能对你的爱负责;否则就是耍流氓。

Friday, January 14, 2011

川子 幸福里

我想有个家,一个不需要太大的地方;
辛苦了大半辈子,我却买不起她。




买不起房,可以租房;
但是买不起的幸福呢,也可以租么?

租来的幸福,会幸福么?

是用我的一生去挣一个摸不着的幸福,还是租一个幸福过一辈子……
其实,幸福在你心里,退一步,海阔天空。