Fan's blog Rotating Header Image

在不安定中寻求安定

最近搬了新居,地方比原来的大,于是可以单独的劈出一个书房来,但是在选择哪个房间上想了很多。我们有两个小房间,稍大的准备做小卧室,小点的作书房。但是我对这个房间不甚满意:一则窗户比较小,这样光线不好;二则这个小房间的门的隔音效果比较差点,客厅里电视的声音容易传到里面来。但大点的房间比较潮湿… 诸如此类的原因搞的我很纠结。

办电话时也很纠结:要不要固话呢?选哪个套餐呢?

感觉自己比较容易纠结:我这个blog主机每年要交120$,感觉浪费,但是又有点不舍得。纠结。

后来我发现对于这类型的问题解决办法就是:不要急于追求正确答案,不要急于行而上。拿上面书房的事情来说,哪个房间好先适应一段时间再说,到时候也是可以换的。每年120$是有点小贵,但是先用个两三年再说,到时候再看值不值。

容易纠结的人多半都是关注小事,关注细节的人,也不大喜欢变化。但是须知关注细节就必须先舍弃旁枝末节,安定就要在不安定中寻找。

不要担心,真理自然会慢慢显现。

Android 2.2终于开放了推送的消息服务

内流满面阿,终于不用自己搞个长连接了。

2.2释放出来了,在其新特性中,有一点:Cloud to Device Messag(C2DM),这个跟gtalk类似,可以让web程序或者app engine向手机发送消息,不同的是gtalk是系统级别的,一般程序访问不了,这个则是标准的API。

在旧版本android上实现这个功能还是蛮麻烦的,我原来写过。主要的思路就是自己起一个gtalk的客户端,用xmpp协议,然后放在service保证长时间运行。缺点很明显:这个service消耗手机资源,功能跟系统本身服务重复。不过在消息服务没有开放时,自己的app是接收不到xmpp消息的。

google开放出来很直接,因为使用的还是老一套。下面是手机受到消息时的log,可以看出使用的还是smack,当然,协议还是xmpp了。

05-22 09:26:13.356: DEBUG/GTalkService(223): [ChatMgr] processPacket: not logged in! drop org.jivesoftware.smack.packet.DataMessage@43e929e8
05-22 09:26:13.576: INFO/JumpNote_SyncAdapter(298): Beginning full sync for account fkpwolf@gmail.com
05-22 09:26:16.316: INFO/JumpNote_SyncAdapter(298): Sync complete, setting last sync time to 1274491573563

那么web端或者云端如何发送消息呢?我看到代码里面是访问https://android.clients.google.com/c2dm/send,大概用的是rest吧。不过现在google要申请帐号才能访问这个服务。mobile收消息则使用标准的receiver模式。

Google给了个例子:JumpNote,可以看作双向同步功能的写字板。技术用android client + app engine + gwt(web client),使用了android新的sync API,还是一个蛮复杂的例子,因为这不单单是一个mobile app,而是一个完整的云服务实例,值得仔细研究研究。

device

More about get rid of toolbar at iPhone Safari

When you visit some web site like Google Reader or Delicious at iPhone Safari, maybe you will notice that after have loaded page, the browser will hide tool bar automatically. This feature can save phone’s valuable screen space. To implement it we can just use javascript: window.scrollTo(0,1). See here, and here.

<script type="application/x-javascript">

if (navigator.userAgent.indexOf('iPhone') != -1) {
 addEventListener("load", function() {
 setTimeout(hideURLbar, 0);
 }, false);
}

function hideURLbar() {
 window.scrollTo(0, 1);
}

</script>

In common sense, it works. But if it didn’t, this article will help you.

First if we want toolbar hidden, beside the above JavaScript, below two conditions should be true:

1) web page is long enough. If it is short, the browser will think it is not necessary to hide the bar. You can zoom the page to test this rule.

2) scrollTo after page updated. setTimeout is used for this. We often invoke an AJAX to get HTML text from server and then update some part of page. The updating action will reload page so window.scrollTo must be invoked after AJAX has gotten response and page has been updated. So the timeout of scrollTo should be bigger than timeout of Ajax. Or invoke scrollTo after had gotten response directly. Keep in mind that setTimeout and Ajax both are asynchronousI used jQuery and $(#id).html(“<div>…”); to update page, so for DRY, I override this function:

if (navigator.userAgent.indexOf('iPhone') != -1) {
 (function ($) {
 var originalVal = $.fn.html;
 var hideURLbar = function() {window.scrollTo(0,1);};
 $.fn.html = function(value) {
var ret = originalVal.call(this, value);
 if (typeof value != 'undefined') {
 // setter invoked, do processing
 setTimeout(hideURLbar, 100);
 }
 return ret;
 };
 })(jQuery);
};

I found this cool script from here. Mabye this approach impacts app much, for html method is used everywhere in app. So take care before apply it. There is another option: use $(document).trigger to sent event.
Screenshot 2010.05.08 14.39.26

I’M NOT TWENTY

Looking for paradise         去寻觅一方乐土,
Is always on my mind         总让我魂牵梦绕
Morning light shining right  当晨光轻抚大地,
Sing me a lullaby            请为我哼唱一首摇篮曲

Oh! Baby come to me          oh,宝贝,到我这来,
Bring back simplicity        带回天真与纯朴
I’m here, you see !          你知道我就在这!
So why hang on to me ?       为何紧握我不放?
Just write me poetry         只管给我写首诗。
If you’re okey dokey !       假如你感觉正好,
Get up and start to smile, guy   起来冲我笑笑,伙计
Do it for me                     不要迟疑
Wake up. I’ll come around man    醒来吧,让我看到男子汉的你
Let’s do ”boogie-woogie”         让我们来玩“boogie-woogie”

It’s not even a game             这并非一场游戏,
Get over your pain               战胜你的苦痛
I’m not twenty                   我已不是二十,
Not even ashamed                 甚至不再害羞
Could we celebrate               让我们一起庆祝
Cause’I'm not twenty             因为我已不是二十
And life goes on and on          时光渐渐流逝,
I go as I come                   而我还是我
Mélodie de vie                   这是生活的旋律
I fly all alone                  我一直独自飞翔
A light little stone             你这颗小却闪光的石子
You get old at twenty            快快长到二十岁,
And I want to be free !          我渴望能够自由飞

Oh! Baby baby mine               oh ,宝贝,我的宝贝
You’re always on my mind         让我一直牵挂的宝贝
Having fun is just fine          拥有快乐吧,它是如此美好
Your love, I shall deny          而你回报的爱,我会拒绝

Falling for me, indeed           情系于我,
Is diving in someone’s need      并乐于助人
Love is too strong !             这样的爱如此强烈
I’ve fallen into me              而此时我已深深陶醉
And freedom’s eestasy !          并获得自由的狂喜
You can never go wrong !         相信我,你必将永不迷失方向

copy from here.

上班路上又听到这首歌,内牛满面啊,虽然我一直听不清歌词。