Meteor™ Learning Note

Dependency Tracking in Meteor: Computations
While Meteor is a real-time, reactive framework, not all of the code inside a Meteor app is reactive. If this were the case, your whole app would re-run every time anything changed. Instead, reactivity is limited to specific areas of your code, and we call these areas computations.
/client
Any files here are only served to the client. This is a good place to keep your HTML, CSS, and UI-related JavaScript code.

When Should We Use observe()?
Using the above pattern is sometimes necessary, especially when dealing with third-party widgets. For example, let’s imagine we want to add or remove pins on a map in real time based on Collection data (say, to show the locations of currently logged in users).
In such cases, you’ll need to use observe() callbacks in order to get the map to “talk” with the Meteor collection and know how to react to data changes. For example, you would rely on the added and removed callbacks to call the map API’s own dropPin() or removePin() methods.

/server
Any files in this directory are only used on the server, and are never sent to the client. Use /server to store source files with sensitive logic or data that should not be visible to the client.

/public
Files in /public are served to the client as-is. Use this to store assets such as images. For example, if you have an image located at /public/background.png, you can include it in your HTML with or in your CSS with background-image:
url(/background.png). Note that /public is not part of the image URL.

/private
These files can only be accessed by server code through Assets API and are not accessible to the client.

http://docs.meteor.com/

Have a cup of coffee

From an outside look of it, I think it’s like a mixture of Python and Ruby. —Nango

1
2
greet = (message) ->
alert message

Advantages

  • Least amount of code to solve problems
  • Readable and Understandable
  • Easy to Maintain
1
2
message = "Ready for some Coffee?"
alert(message)

=>

1
2
3
var message;
message = "Ready for some Coffee?";
alert(message);

All the code is wrapped up in a closure to prevent variable pollution

Use a default value of ‘Stranger’ for the name parameter

1
greet = (name='Stranger') -> alert name

=>

1
2
3
4
5
6
7
var greet;
greet = function(name) {
if (name == null) {
name = 'Stranger';
}
return "Hello, " + name;
};

Kind of Like Ruby ha, But In this field, it is called CoffeeScript-style string interpolation.

1
2
greet = (name='Stranger') ->
"Hello, #{name}"
1
2
sum = (a, b) ->
a + b

One thing I like it is, you can be 任性 like this:

1
2
3
4
5
coffee()
coffee("Yo")
coffee "Yo"
coffee("Yo", 2)
coffee "Yo", 2

Array

1
2
3
4
5
6
7
8
9
storeLocations = ['Orlando', 'Winter Park', 'Sanford']
Can use new lines instead of commas
storeLocations = [
'Orlando'
'Winter Park'
'Sanford'
]

Loop

1
2
3
4
5
6
storeLocations.forEach (location, index) ->
alert "Location: #{location}
alert "Location: #{location}" for location in storeLocations
for location in storeLocations
alert "Location: #{location}"

Indent

There are things I don’t like like this.

1
2
3
coffee =
name: 'French'
strength: 1

=>

1
2
3
4
5
6
coffee = {
name: 'French'
};
({
strength: 1
})

一行流 (one line combo)

If u do python, you familiar with this.

1
2
3
filteredFlights =
(flight for flight in currentFlights when stops is '2+' or
flight.routing is 0)

OOP

the great extend keyword
My friend Teddy has a great post about this.

1
2
3
class Animal
class Snake extends Animal

= >

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Generated by CoffeeScript 1.8.0
(function() {
var Animal, Snake,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Animal = (function() {
function Animal() {}
return Animal;
})();
Snake = (function(_super) {
__extends(Snake, _super);
function Snake() {
return Snake.__super__.constructor.apply(this, arguments);
}
return Snake;
})(Animal);
}).call(this);

TODO

Others

With the character ->, it can lower the possibility of missing braces or brackets.

There’re lots of other stuff, like automatically hoisting for u to check out.

Install

1
2
3
1. Install Node.js http://nodejs.org/
2. Install npm http://npmjs.org/
3. $ npm install -g coffee-script
1
2
3
4
5
6
7
coffee -c test.coffee Creates test.js
coffee -cw test.coffee Every time test.coffee is
updated re-compile.
coffee -c src -o js Compile all .coffee files in the
src dir into the js dir.
coffee -wc src -o js Every time a file is updated
re-compile

Link:
http://teddy1004.github.io/2014/12/04/class-inheritance-in-JavaScript/
http://coffeescript.codeschool.com/levels/1/challenges/1
http://courseware.codeschool.com/coffeescript_slides.pdf

Instapaper™ VS Pocket™

I’ve been migrating from Instapaper to Pocket recently.

Instapaper Pocket
stackoverflow nope support
code viewing better Content in the second column
SNS find your friend(although I don’t think this is useful) your friend(although I don’t think this is useful)
PDF probably not support support

我是怎么堕落的

人在一个群体 容易被同化
我小学初中 一直是个high爆全场的人,周围的人也high爆全场,所以成绩包括我们班的成绩特别好
到了高中,逐渐所有人变得不再开放 你再high爆全场就会被当成脑残,所以我就也变得不再那么开放,所以成绩就垃圾了

这篇博客用来喷GFW

这个世界没有什么对与错 但是有最佳实践 —男哥
用类比的方法 我们可以更清晰地看清这个世界 甚至这个宇宙 —男哥

2015-01-24更新:
年会的时候跟网络组的同事周天一聊了下,他说GFW是一个在特定时期的特定产物,当我们这样的人成为社会的中坚力量的时候,就没有GFW了。方滨兴其实是一个很不错的教授。
觉得很有道理。

之前跟朋友聊,朋友说GFW不会真正影响我们,说因为翻墙太容易了,只要你想根本不是问题。
他说的的确也是。但是如果翻墙说到底还是会花时间的,如果你一时想要搜一个东西比较急(其实大多数你要搜东西的时候都应该是比较心切想要知道答案的),你一般就会选择百度了,百度没有错,但是如果你因为这个而丧失了接触更好东西的机会,那就得不偿失了。

因为互联网有棒棒的东西叫做超链接,当你得到了优质的搜索结果后,想象力是不可低估的,搜索结果不同造成的影响可以到次方级别。

为什么中国有GFW(我的观点

其实一个国家很多程度上跟一个人类似的,中国之所以对网络那么敏感,就是想限制人们知道有些黑历史。我觉得中国人还是很爱面子的,所以类比的来说,我们中国公民就类似与一个家庭的孩子,因为身家不太清白,家里的大人就限制你去了解世界,因为他怕你知道了黑历史后就觉得自己家原来并不是那么神圣了。
所以我们每个中国公民就像是一个,被内闭的家庭教育所坑害了的孩子

不过既然有害处就一定有好处
GFW的好处:

  • 在墙外我认识了不少墙内优秀的人
  • 有妹子找我学翻墙
  • 麦迪在twitter上回复了我
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
附上跟Yugo的讨论
Your雪人 21:59:01
我同事认识方滨兴
张绍宇 21:59:12
and
Your雪人 21:59:19
中国人素质低 容易被煽动
张绍宇 21:59:25
。。。
张绍宇 22:01:01
这种论调是阴谋
张绍宇 22:01:23
初听之下可能有道理,但经不住推敲
Your雪人 22:01:31
你不觉得他促进了就业么
张绍宇 22:01:40
没有
Your雪人 22:01:49
人们都用洋人的产品 结果是怎样呢
张绍宇 22:02:03
不要有狭隘的民族主义
张绍宇 22:02:21
什么洋人的产品,国人的产品
Your雪人 22:03:54
这只是我现阶段的想法 没有什么对错
我当年也是恨GFW入骨
张绍宇 22:03:59
以前闭关锁国是不是也拉动了就业?
张绍宇 22:04:25
阻止了西方国家倾销大规模工业生产出来的廉价商品?
Your雪人 22:04:40
good call, 历史的结果是怎样的呢
张绍宇 22:04:53
闭关锁国终究会被人暴力打开
张绍宇 22:05:59
你想想程序员都去用百度了,几十年以后国内外技术差异会有多大?
张绍宇 22:07:23
你不知道这些什么意识形态其实都是幌子,只是利益集团为了维护自己利益
Your雪人 22:07:51
http://about.me/zzz6519003
我同事的观点是:这是一个必然产物,等我们这代人成为社会的中坚力量 自然就没有GFW了 我觉得很有道理
你的观点也很有道理
Your雪人 22:08:02
不知道 历史的答案是怎样的
张绍宇 22:08:48
想太多,社会阶层固化,能够成为中间力量的大部分都是利益集团的人
张绍宇 22:09:50
推荐两部小说,动物农场和1984,很有意思的
张绍宇 22:11:40
当然,世界上所有国家其实都是掌握在利益集团手里,只是他们吃相各不一样
Your雪人 22:13:09
你觉得没有GFW我们能听这么多盗版音乐么 pdf
张绍宇 22:13:34
这些是违法行为
张绍宇 22:14:00
而且这和 GFW 没哟一毛钱关系
Your雪人 22:14:03
如果没有GFW 还是可以的吧
张绍宇 22:14:11
只是我国在这方面法制还不健全
张绍宇 22:14:39
现在不是已经有好转迹象了么?
张绍宇 22:15:12
盗版软件害人啊,中国的桌面软件产业就是毁在盗版上了
张绍宇 22:15:42
Office 盗版相当于低价倾销
张绍宇 22:16:28
表面上用盗版 Office 好像赚到了,实际上坑大了
张绍宇 22:16:37
盗版音乐也是一样
Your雪人 22:17:16
乌鲁木齐貌似出现过 政治动乱 结果断网一年 不知道跟网络有关系么
张绍宇 22:18:05
通过网络来联络的
张绍宇 22:19:08
这种特殊情况断网和 GFW 性质完全不同
张绍宇 22:19:42
就像打仗的时候军事管制一样,是在保护大家
Your雪人 22:19:46
good call
Your雪人 22:21:22
我比较好奇中国当年闭关锁国怎么解决的
张绍宇 22:21:41
各种不平等条约,强制通商
Your雪人 22:22:10
Fuck。。。。 china is fucked up
Your雪人 22:22:13
will be
张绍宇 22:22:44
这道不至于被侵略啥的。。。
张绍宇 22:25:04
日本以前不也是闭关锁国么,美国海军跑到江户,开了几炮,把他们都吓尿了
Your雪人 22:27:36
美国能救中国么
张绍宇 22:27:43
才不会
Your雪人 22:28:03
2. 以前 闭关锁国 促进国内就业?
张绍宇 22:28:19
那时候我想是的
Your雪人 22:28:23
3. 强者愈强 弱者愈弱 怎么打破
张绍宇 22:29:43
因为以前中国是农业和手工业,生产力底下,成本高,国外是机械化生产,成本低效率高,很多产品比如纺织品,国外的价格很便宜,如果大量涌入肯定会导致很多人失业
张绍宇 22:30:28
短期来说是可以维持就业的,长期呵呵
Your雪人 22:31:06
下次继续
张绍宇 22:31:35
http://www.zhihu.com/question/19805892
张绍宇 22:32:26
事实是所谓的“闭关锁国”是中国几千年来的基本国策。其目的是维护官方贸易的垄断性,国家权力强占民间权益,国进民退而已。
张绍宇 22:32:42
其中一个回答的主旨
Your雪人 22:33:36
if it were u what would u do
张绍宇 22:33:50
it 是?
Your雪人 22:34:02
国家政府
张绍宇 22:34:39
对什么事情?
Your雪人 22:34:52
维护官方贸易的垄断性
张绍宇 22:35:19
可以看我玩 文明 的时候所选的政策
张绍宇 22:35:34
为啥要维护官方垄断?

The Art of Unix Programming-Book Note

题记 似乎所有的领域 发展到最后 都会变成哲学 —男哥

Rule 1. You can’t tell where a program is going to spend its time. Bottlenecks
occur in surprising places, so don’t try to second guess and put in a speed hack
until you’ve proven that’s where the bottleneck is.
Rule 2. Measure. Don’t tune for speed until you’ve measured, and even then
don’t unless one part of the code overwhelms the rest.
Rule 3. Fancy algorithms are slow when n is small, and n is usually small.
Fancy algorithms have big constants. Until you know that n is frequently going
to be big, don’t get fancy. (Even if n does get big, use Rule 2 first.)
Rule 4. Fancy algorithms are buggier than simple ones, and they’re much
harder to implement. Use simple algorithms as well as simple data structures.
Rule 5. Data dominates. If you’ve chosen the right data structures and
organized things well, the algorithms will almost always be self-evident. Data
structures, not algorithms, are central to programming. [3]
Rule 6. There is no Rule 6

design-defect

I’m gonna use this post to continuesly show all those design defection that I’ve been through.
The God Design is like this:
I think maybe I do this, it can have some effect in my mind, and i tried it, and yay! it works!

Switching input method in OSX
in

Sougou iOS custom input method

In iOS, u can register some quick input combo.
like me, if i type “zzzg”, it should have “zhengzhongzhao###gmail”

in the Sougou custom input method, we don’t have it.

iOS, Wechat, Renren sharing

It’s been a long time since iOS8 releases, but wechat(the most likely one to be the FB in CHINA) haven’t come with the extension of sharing.

不写代码的产品经理/QA很难察觉到的东西

关于微信

  • 微信朋友圈内的分享
    打开朋友圈,点击一个Link,那个favicon图片的获取是通过图片的URL,在分享的时候,通过这个URL来获取图片,这就造成有的时候这个URL并不能即时显示。
    这一点我想可能不写代码的产品经理很难察觉到。
  • 微信的播放媒体后出现的BUG
    场景: 我在听音乐,微信里播放一小段朋友分享的歌曲。我再按线控上的播放按钮,就没有声音了。