April 10, 2012

Install MIT/Scheme with Vim

    
After wondering around for a while, I finally found this was quite foolproof...

It could be divided into five steps:
1. $ brew install mit-scheme. (Its version is usually a little bit older than the latest MIT/GNU Scheme)
2. Install GNU screen if it was not installed before.
3. Install Screen Vim plug-in according the steps in that webpage.
4. $ vim ~/.vimrc
"For screen.vim send block
"to SendScreen function
"(eg Scheme interpreter)
vmap :ScreenSend
nmap vip

5. Launch Vim and write ":ScreenShell mit-scheme". It is all set for the fun:)

References: [1], [2]

cheers,

March 16, 2012

Reading digest 03/16/12

Smart and Gets things done
What should you look for during the open-ended questions?
One: look for passion. Smart people are passionate about the projects they work on. They get very excited talking about the subject. They talk quickly and get animated. There are far too many people around who can work on something and not really care one way or the other. It’s hard to get people like this motivated about anything.
Two: good candidates are careful to explain things well, at whatever level. You don’t want to hire some one, basically, because he is not smart enough to comprehend what it takes to make other people understand their ideas.

No Designer's Design Book
When several items are in close proximity to each other, they become one visual unit rather than several separate units. As in life, the proximity, or the closeness, implies a relationship.
By grouping similar elements into one unit, several things instantly happen: The page becomes more organized. You understand where to begin reading the message, and you know when you are finished. And the “white space” (the space around the letters) automatically becomes more organized as well.

January 24, 2012

Reading digest 01/24/2012

    
My plan for 2012: do things that children do
Learn things
Play sports
Sing and play instruments
Draw and paint
Write stories
-- I have to say it is a better "next year resolution" than what I have made. The explanation is clear and straightforward. So, I should add them to my resolutions!

Life Tastes Best When You Eat What You Kill
Don’t depend on one boss, buyer for your company, product, service you offer, etc. Diversify everything you can.
Become an expert.
Connect people.
Give ideas for free.
Always work on your exit. No matter where you are: a job, a startup, your startup, writing a column, working at Mcdonalds, always diversify your possible exits and begin immediately working on them. You don’t have to exit tomorrow, but never forget that you can get that email tomorrow that says you have to clean out your desk by Saturday.
Never say a bad word about anyone.
Don’t care what people think.
Create your luck.
Take responsibility for all failures.
Honesty. If you don’t ask for what you want, chances are you won’t get it. If you don’t say what you believe, you’ll never stand out from the 99% of people out there who hide the truth about themselves and their desires. If you don’t stand up and say or show how special you are, nobody will ever think you are special. Nobody is out there advocating for you. Honesty about what you feel, believe, know, think, want, will make you a multi-dimensional being in a flatland world.
Patience.让子弹飞一会儿。
-- The general guidelines might be too vague to follow or helpful to summarize some vague thoughts in mind. This one is much closer to the latter category.

January 14, 2012

Summary of 2011 and Resolution of 2012

               
这是一篇想了很久的日志。过去的一年,发生了很多叵测的事情,我学到了很多,也付出了不小的代价。接下来的这一年,也许会有很多重要的事情发生。无论如何,对于经历的2011,把感想趁着鲜活的时候写下来,也算是对自己的一个交代。

@implementation 2011_Summary

1. 诚实。这是上一年最大的教训。无论是在学习、研究上,或是与陌生人的交往,还是对待自己最亲密的人,诚实永远是唯一正确的选择。我了解,它的反面是一个多么贬义的行为。但总会有一些时候,要么是觉得自己已经付出了很多努力,所以取些捷径也没什么大过错;要么就是压根儿的应激反应,连自己都无法解释。事后回头看的时候,才会感叹自己的价值观有多么脆弱。但自打意识到之后,再这样任由其发展下去,就太说不过去了。上一年我已经得到了足够多的教训,能够让我在每次自省的时候都深深训诫自己,去努力做到这个简单的品质。

2. 编程。这是上一年最大的收获。再往之前岁月里寻找,所有的技能、知识都是和学业紧紧连成一体的,于是,就都是些必须去做却又苦逼的差事。也许是从一零年开始的,编程的乐趣逐渐让和它相关的知识自成体系,从其它知识里分离了出来。首先,编程和学习语言一样,可以清晰感觉到点滴的积累。昨天又会了一个新的框架,今天又学了一个新的trick,于是重写代码的程序效率提高了500%。其次,网络上丰富的社区,把全世界有相同爱好的聪明头脑都集中在了一起,类似于之前小学初中,我到了一个足球传统学校,和一群踢球牛逼的人一起,于是也开始爱上了足球。两者的区别在于,踢球好的人往往不爱带踢球不好的,但技术社区里,包容性强了很多。当然,根本差别是,这里没有任何地域限制。和聪明人交流,总是一件愉快的事情。提问、回答,各种限时或不限时的项目,奇怪的题目集锦,可以玩儿的不亦乐乎。当然,最重要的原因是,这件事情,可以让自己不断提高,并且帮助别人获得些便利,若是足够努力,还能让世界变得更好。这是一个多么牛逼的事情啊!

之前我的编程经验都是和硬件相关的,一个程序两条线索推进,其间的区别是浮点计算和定点计算⋯⋯我并非说之前的C代码都不值得一提。相反,从算法的浮点实现,到定点应用限制,其间的各种考量,甚至是算法重新设计,所需知识和工作量都是巨大的。并且,我也基本同意 Joel Spolsky 的观点,学习这种底层代码对于程序员的基本功至关重要。但毕竟,C太原始了。几乎所有的模块都需要自己来搭,就算考虑到reusability这仍然是一件很蛋疼的事情。有语义更人性化的Python,有模块化更好的Java,有更有趣的Obj-C,若是想挑战一下理解力,还可以用Lisp。有句话已经忘记了出处,大意是讲,没有最好的编程语言,只有对于某项工作最合适的语言。这是没错的。打开自己的眼界,学习更多的语言,也就有了更多的乐趣。⋯⋯当然,若是回答问题“你最喜欢哪种编程语言?”我还是会说C,我喜欢那种掌控所有细节的感觉,是为了最大限度的榨取硬件计算能力,也是因为程序没有任何的暗箱,似乎心里能安然很多。

3. 阅读。算上各种教材,去年总共读了大约20本书,其中精读的十本左右,都是大部头。收获还是不错的。还有另一个阅读源就是google reader,订阅的东西从一零年的google group,换到了hacker news,吵架还是有,只是方式方法更加多元化了。比如C语言该换还是不该换,Java好还是不好,Node.js是不是癌细胞,以及.Net程序员到底是不是傻逼⋯⋯各种大坑,于是各路英豪就各种姿势往里面跳。

今年效率最高的时候是读man-month,因为课程演讲需要,所以总共花了一天的时间就看完了,再加上摘抄笔记和整理的幻灯片,一整天下来感觉学到了不少。而收获最多的两本书是,K&R C 和 CLRS。两本书很多章节都看了两遍。所谓经典教材大概就是如此了,好像每字每句都经过了斟酌,复杂的理念都能表述的很有条理;而因为所涉及的基础知识涵盖太广但书籍篇幅有限,作者只好把一些次重点的东西用小字写下来,或者一笔带过,这也就是需要反复翻看的原因了。此外,阅读积累的质变似乎是在一零年末开始的,不在抵触大部头的英文著作了。而且读下来再翻回头看译著,发现译文里漏洞百出,而且很多晦涩的中文名词,反正也是生僻词,还不如原来英文解释的顺畅。

4. 水果。乔布斯去世是一一年的一件大事情,而五月份我买了MBP,算是正式成为一名水果消费者了。之前,有不同的人和我讲过各种苹果的坏话,总之两个词,就是装逼和不兼容。前者我倒是无所谓,所谓装逼或者牛逼,冷暖自知,而且在努力牛逼的过程中,装装也未尝不可^_^。而之前不同人讲的不兼容倒是真的唬过我一段时间。之后用了很久的ubuntu,想来这个linux都用的欢喜,来个unix加小清晰界面的Mac OS也没啥。然后就买了。现在来看,未来很长的一段时间里,除非苹果倒闭了,否则我几乎没有可能把主要工作平台换回windows。所有的工作都可以顺利完成,没有任何兼容问题,方便的购买正版软件,程序可以方便的迭代升级,加之这个平台的软件用起来大都十分顺手,而且自己最近还在鼓捣Obj-C。这个操纵系统的转换是成功的。PS. 这个系统是否安全,似乎是另一个永恒的争论话题。而对于所有惧怕这个系统不安全的人们,可以自修一下计算机操作系统这门课,或者Google一下win和unix的差别,以及如何保护系统安全,或者读一下这篇不错的文章

而至于乔布斯,使用了他创造的产品和平台之后,他去世的消息也更让我感到悲伤。从产品线到操作系统到平台,所有的一切就好像一盘缜密围棋,在他去世之后回溯的审视,所能感受的除了惊叹也就只有悲伤了。有关他的文章很多,但最好的一篇,没有之一,是他亲生姐姐写的悼词。每当自己想倦怠的时候,看一看,总会或激励或愧疚,重新开始好好做自己的事情。

5. Instapaper。Marco Arment写的牛逼应用。我是他博客的忠实读者,也喜爱这个应用。其实我决定使用水果系统,他博客里一系列文章也是功不可没。他还是Tumblr的创始人,以及苹果的超级粉丝。所以当他提到Android以及Windows Phone时候那种戏谑的语气,很是有趣。而更令我着迷的,是他所处的状态,专职做一件自己喜爱的事情,如同一个艺术家一样不断更新完善自己的创作,这个创作受到很多人的喜爱、帮助别人更好的获取资讯,并且自己依靠这个创作获得收入,活的还不错。很多时候我会想,就算自己的爱好不能达到“专职”以及”依靠创作获得收入“,但起码可以努力做到其余的部分。换句话讲,我找到了自己的爱好,尽管不确定能不能用它获得博士学位,或是以它营生,但我确定这是件有意义的事情,所以我也会一直坚持坐下去的。

6. 10000小时。之前似乎在别的地方也看到过,但已经找不到出处了,也没想过太多,直到读了阮一峰的日志,我才认真思考这个数字的意义。当然,也有其他人计算自己的工作时间,算出来每年能工作2160小时,这样五年能有超过一万小时的积累。但具体看看计算方法,似乎从坐在写字台前开始,连回复工作邮件的时间都算上了,而且取样一天,然后乘以360天/年。这个就有点儿扯了。想要成为乔丹、盖茨或者类似的人,应该要更困难些地吧?比如莫扎特成名前有超过10000的训练,不能把他擦钢琴的时间算在内,乔丹的训练时间应该也不包括他在球场边和拉拉队员们扯淡的时间。训练就是训练,可以包括冥想、包括查找资料、包括 trail and error,包括一切和提高与之相关能力的活动时间。但也仅限于此。我一直在跟着这个家伙的网站,现在他已经领先我将近200小时了,希望我能在不久的将来追回来。

6. 读库以及独立书店。这个和我自己似乎没有什么关系,但有些想法,也记在这里好了。光合作用和第三极,独立书店的倒闭引得一篇哀鸣。也许我只是以站着说话不腰疼的态度审视,可我真是觉得它们只是市场运转的一个结果而已。第三极书籍分类十分混乱,光合作用开店布局不合理,内设咖啡馆不伦不类,书籍既不全又没有特色⋯⋯总之,作为消费者,很难看出来它们的拥有者在真正用心的经营。等到被淘汰的时候在对着媒体感叹生态圈的恶劣?也成,算是对投资方的一个交代。

和它们对比的,是读库,店小六的用心给我很深刻的印象。嗯,我觉得似乎应该叫六哥或者六叔了⋯⋯订阅读库的一年里,精美的书签,或是特别的环保袋,或者几本赠阅的香港杂志,随时可能随着书籍一同收到。如果有疑问,发邮件有问必答,短信也回复。想想读库的订阅群体数量,而编者只有一人,这样的效率着实令人钦佩。另外,读库和连锁的光合作用或是曾经占有一座大楼的第三极,应该是生活在一个生态圈里,唯一的差别在于读库因为小众,所以少些博弈筹码。当当曾经(或者现在仍然)拖欠了读库几十万的书款,投放到新华书店等传统渠道的书款也总是收不回来,但读库的结果是,偶尔困难时候化险为夷,正常时候生活的有滋有味。全心全意去完成这项工作,应该是其中很重要的一个原因吧。

@end

---

@protocol 2012_Resolution

1. 训练时间追上并且不再落后与Dan
2. 发布至少一个app
3. 精读至少15本专业书籍
4. 写一篇研究论文
5. 可以熟练使用Lisp

[UPDATE: five more general guidelines
Learn things
Play sports
Sing and play instruments
Draw and paint
Write stories
]

@end



cheers,

December 22, 2011

Excerpt from "the netscape dorm"

   
All of the paragraphs below are excerpted from "the netscape dorm". It is a joyful experience reading the diary. But maybe this is just as what Jamie Zawinski said: "This is the time period that is traditionally referred to as "the good old days,'' but time always softens the pain and makes things look like more fun than they really were. But who said everything has to be fun? Pain builds character. (Sometimes it builds products, too.) ".

======================

But it was no big deal, we just had the meeting later. It's hard for someone to hold it against you when you miss a meeting because you've been at work so long that you've passed out from exhaustion.

Wow, I must be tired -- I just turned on the television, and MTV is actually moving too fast for me to understand it.

I saw Ian today, for the first time in months. His first words were, ``Wow, you look like shit.'' He says I seem really strung-out and twitchy. I thought I had been doing ok! I got a full night's sleep last night and everything. I have no life. I never see any of my non-work friends, and I'm wasting away my one and only youth. I ought to be out doing fun things and active things, the kind of things I won't be able to do when my mind and body finally decay. But instead I'm stuck inside under fluorescent lights, pushing bits around inside a computer in ways that are only interesting to other nerds. I glanced at a movie listing and there are movies out that I haven't even heard of. How did that happen? That freaks me out.

I've just read over some of my diary for the last few months, and man, a lot of it is completely incoherent! It's full of incomplete sentences, made up words, random surreal imagery that I can't even understand let alone remember typing. Have I been typing in my sleep? I hope I don't sound like that in person. I wonder what my code must look like! Oh well, it seems to work.

Well today has been more than a little bit frustrating. The details don't really matter (what does!), but I've spent most of the day so stressed out that my skull is rattling from the pressure of my teeth grinding together. I feel like I have finally exceeded my stress limits and am about blow a gasket. But I can't go home, because if I do, the world will end, right? I'm trying to work, but every few minutes I have to stop typing and make fists so tightly that my whole body shakes.

Coots know how to live. I wish I were a coot. Mr. Wizard, I think I'd rather be a coot than a hacker. Yeah, sure, every now and then a giant pink-haired ape would come running after me and chase me into the lake, but really, could it be that much worse? I'd have a tiny little brain and wouldn't be expected to worry about anything.

The power came back on, and we put the damnable program on the FTP server, and two million people all started attempting to download it at once, before we had even posted the announcement message, and we're done done done and I suppose now we can all live happily ever after…… We sat in the conference room and hooked up the big TV to one of the Indys, so that we could sit around in the dark and watch the FTP download logs scroll by. jg hacked up an impromptu script that played the sound of a cannon shot each time a download successfully completed. We sat in the dark and cheered, listening to the explosions.

I've just noticed that there's still purple ink on the inside of my right wrist spelling the word VOID: the hand-stamp from a concert that I went to last week. I left work, went to the show, and came back to work immediately afterwards. I've been here since.

December 19, 2011

Memory Management in Obj C

                                
I just complete my 2nd iOS homework, which took me cumulative 40 hours. The part that impressed (or... baffled...) me most is about dealing with memory management. In one scree, I opened the Xcode IDE, and in another screen, I just cross-referenced StackOverflow, Developer Library, and Google searching over and over again. There was no one-stop solution for all of the problems I met. But it only made me feel more enjoyable when I finally found the path to solution:) In case that I might forget the key points all I have collected, I record them here with references.

1. Declaration of object.
MyObject* myObject;
WRONG! This means myObject points to a chunk of garbage memory, which would not correctly work at all. Basically, there are two ways to do this correctly:
MyObject* myObject=nil;
MyObject* myObject=[[MyObject alloc] init]; 

The former one makes myObject to point to nothing. Now it at least consistently does nothing, or I could use this pointer points to some useful object later on. But this will also lends to another issue about the life-cycle of a object which I will talk about in detail later. The latter one is to allocate a MyObject object in the memory, initialize it, and then make myObject point to the chunk of memory correctly allocated and initialized. Now, if the MyObject has the interface
@interface MyObject:NSObject{
    NSString* string;
}

@end

@implementation MyObject
-(id) init {
      if(self=[super init]){
           ...do something ...
     }
      return self;
}

after [super init] is successfully performed, Objective-C guarantees that the ivar string is set to nil, i.e. string points to nothing. But it is not that an NSString is allocated or initialized.

2. Basic rules about ownership  and memory management:
  • Any object returned by alloc, copy, copyWithZone, or new has a retain count of 1.
  • retain increases the receiving object's retain count.
  • release decreases the receiving object's retain count.
  • autorelease tells the current autorelease pool to send the receiving object the release message “later”.
  • Any factory method that doesn't have “new” or “copy” in the name (e.g., stringWithString:) returns an object that it has autoreleased on your behalf.
  • Conversely, if you are not the creator of an object and have not expressed an ownership interest, you must not release it.
Or, digested a bit:
  • Any method whose name contains copy, alloc, retain, or new returns an object that you own.
  • Any method that doesn't, returns an object that you don't own.
  • To own an object, retain it.

Reference: StackOverflow, Developer Library. An example about retain and release, and another deeper discussion.

3. copy versus retain

There are lots of discussions about the subtle differences between these two operations, though they both intend to take the ownership from the acquired objects. "(Almost) every time you use retain in Objective-C/Cocoa, you really should be using copy. Using retain can introduce some subtle bugs, and copy is faster then you think…" The problem with using retain to “take ownership” of an object is that someone else has a pointer to the same object, and if they change it, you will be affected.

There are some other discussions concerning the same kind of problem in StackOverflow and post in a blog. Besides, I also made to rookie mistakes that took me quite a while to find out and correct.

4. Has a @synthesize property already init & alloc-ed?

The answer is NO. It needs to populate the property manually. The exception is if you have an IBOutlet property that you've connected in a nib file; that will get populated automatically when the nib is loaded.

For view controllers, the vast majority of properties are IBOutlets and properties that describe what the view will show, and the latter case is usually set by the object that creates the view controller. That will usually be the case for a view controller that shows a detail view for some object.

If you do have properties that are completely local to the view controller, a common pattern is to write your own getter and setter (rather than using @synthesize) and create the object in the getter if it doesn't exist. This lazy-loading behavior means you can easily free up resources in low-memory conditions, and that you only pay the cost of loading an object when you need it.
// simple lazy-loading getter
- (MyPropertyClass*) propertyName {
    if(propertyIvarName == nil) {
        propertyIvarName = [[MyPropertyClass alloc] init];
        ......  // ... other setup here
    }
    return propertyIvarName;
}


5. Pitfall about the use of getter/setter:
@interface MyObject:NSObject{
    NSString *aString;
}
@property (nonatomic, copy) NSString *aString;
- (void) someMethod;
@end

@ implementation MyObject {
@synthesize aString;
- (id) init {
    ......
}
- (void) someMethod {
    ......
    aString = [NSString stringWithString: @"blah, blah, blah."];
    aString = [[NSString stringWithString: @"blah, blah, blah."] retain];
    aString = [[NSString stringWithString: @"blah, blah, blah."] copy];
    self.aString = [NSString stringWithString: @"blah, blah, blah."];
    ......
}

The compiler would not pop up any warning or error about the code above. But the 1st line in the method is extremely dangerous as well as a bug hard to find: the aString does not own the returned object, which will be released at some time after the method is completed. Corresponding to the second factor that I write above, it is obvious that this sentence has no keywords about ownership. Worse still, although the ownership is considered in the @property, this sentence does not call the setter method. The right way to activate the setter is the 4th sentence. Besides, the 2nd and 3rd sentence request the ownership of the new object in another form. They are legal, of course.

[ UPDATE:

6. viewDidUnload vs. dealloc

Unless the program needs to break a retain cycle, it should generally only be releasing objects in the dealloc method. viewDidUnload is an exception; it is invoked in low memory situations and should be used to release anything useless. Then, a preferable way to do this is to write another releaseMemory function where takes most or all of the used objects into consideration and sets them into nil, and then to call this function both in viewDidUnload and dealloc.

The general principle is just as mentioned above: if you do need to release them anywhere else, then always set the reference to nil after the release. That will protect the app from blowing up later (likely in dealloc).

References: StackOverFlow-1, StackOverFlow-2.
]

It is glad that I have gone this far. And, I will move on,  and dig deeper.

cheers.

December 7, 2011

Winter vacation resolution

1. Study at least one online theoretical course;
2. Complete implementation of personal website and the Cal app in iOS;
3. Write blogs frequently documenting the progress;
4. Find a nice com to do the Spring intern;
5. Update info with Dr. Barber every other week about Identity threats;
6. Contact with professors on a daily basis;
7. Cumulate the training hours surpass 2400.

Days of our lives

Daisypath Anniversary tickers