Loading...

Archive for February, 2008

    AD: 猛买 | 快递查询 | Jobsdigg | 很棒的男装店

如何在Rails中实现图片上传

早就想写的,不过今天才有点时间。最近多线繁忙,好不充实。

在Project Lucas中需要做图片上传的功能,参考了《应用rails进行敏捷web开发》这本书,果然就成功了。我写了一个详细的例子在这里:http://www.googlecto.com/2008/02/18/how-to-upload-pictures-in-rails/

Recent good news of blogkid

Just found I prefer to write in English now, but I’m afraid not all my reader can well understand. Several good things happened in the recent tens of days, so I decided to write them down, and share my happiness with you all.

Niupu’s traffic reached 7,000 ip/day. Niupu got online in April, 2007, however , there were too much trouble to walk through. The development of niupu’s system cost me 2 months, while the maintenance cost more. But before 2008, I got no more than RMB 1,000 profit. I know money is not that important, but still , I’d like to get more to feed myself. 7,000 ips is not very large, but for small websites , it’s hard to reach. When the traffic has increased, the income now has an average RMB 100/day.

Thanks to Niupu’s great growth, my Google Adsense account balance is to reach $100 in near future (maybe this afternoon). Right now, there’s US$99.77 in my account. I’ll get paid in the end of March, maybe the beginning of April.

blogkid.cn was indexed by DMOZ. I submitted my blog to DMOZ months ago, however, I got no response. But today I checked the traffic report of blogkid.cn, only to find someone came from DMOZ. Amazing! Yep, now my blog is listed here, with a brief introduction, together with Wang Jianshuo’s blog :) .

Why DMOZ? I can only say,  as many search engines use the data of DMOZ, for a website, indexed by DMOZ is a good way to get SEOed. Alexa now used the new data of my blog, check out here.

niupu.com was indexed by Google. For 8 months or even longer, Google refused to index niupu. That is, you cannot found even a single page of niupu.com in Google’s search result. But last night when I searched “site:niupu.com” in Google, it returned tens of results, which made me more than glad. I’ll later write another post on how to get back in Google’s search result.

With the help from Google, I believe niupu will be larger and larger. Thus, I published an ad block on 阿里妈妈 ,  if you’d like to advertise on niupu, you can kindly have a look.

I’ll be back in Hangzhou before Feb 24th to have a new term started. But I did not get a train ticket till now.

Update: My Adsense account balance exceeded $100 a moment ago. $100 isn’t much, but is a milestone.

Amazon.cn sucks

It’s Valentine’s Day, as no longer a single man, I bought some cute presents for my girl. I ordered on Feb 7th, right during the spring festival vacation. So amazon.cn promised to ship the stuff on Fen 12th. I though there would be enough time for the presents to reach my gf.

However, the order is still “on processing” and not yet shipped till now. I received 2 mails from amazon.cn which told me the estimated shipping date was changed to 15th, right after this important day.

It’s not the first time amazon.cn delayed my orders, plus not the worst. I used to order a DC with some books on amazon.cn last year, however, while the DC was sold out, the books were forced to wait together. After half a month, the DC was still unavailable, and consequently, I was out of anger.

amazon.cn is more and more like a international company, but only imitation is not enough.

Edison and the photos

I saw the earliest news on 163.com, which exposures the photos of Edison and Gillian Chang. While the key parts were mosaic, people doubted the authenticity of those photos. Before long, more photos got shown, then too many evidences proved the photos were true.

I didn’t see the extra photos before Feb 11th. On 11th, I searched by some English words and got the address of the original photo-exposure-post. Then I managed to download more than 400 pictures, which shocked me deeply.

Not only Gillian, Cecilia (张柏芝) and several other female stars are involved. I don’t think anyone is guilty, even the photographer Edison , I don’t think he’s guilty. Just because they are all adults. Never play games you cannot afford.

Besides, those photos are really hot, haha.

Without Chinese

My Firefox was upgraded to 2.0.12, as a result, I cannot type Chinese right now.

Zining was not happy last night. We fell out again. Without her forgiveness, I did not sleep well. It’s the 5th day of the new year, so the noise forced me to get up early in the morning.

I do not want to work, however, to my joy, Zining is fine at noon. I decided to set me free today, while niupu’s server was under a high load. No other way, I spent about an hour to rebuild niupu’s cache system, and the performance seems to be improved a lot. I wrote a short note about the rebuild process on my tech blog.

Several days ago, when our high school mates get-together, we all blamed the education of English we’d received in high school. I know I have to practice more, but too little chance to use English. (I heard those guys who go aboard also use Chinese in most time)

Lucas/Challenge Cup/Postgraduates Entrance Exam/Website with zining

GoogleAnalytics的网站覆盖图

一直想找个东西统计一下网页上每个链接被点击的情况,这样可以针对用户的点击情况进行优化,提高转化率。可是一直也没找到靠谱的统计提供方,自己写程序数据量太大,也做不了。

昨天心血来潮去了GoogleAnalytics,看着那些强大的功能们觉得有点不知所措——初级用户实在用不着,感觉51啦就足够了。可是在里面一通乱点让我找到个好东西,就是标题里这个“网站覆盖图”。

网站覆盖图的作用就是能展示出统计的一张网页里的链接被点击的情况,恰好就是我盼了好久的那个功能。得来全不费功夫啊,有了这个,就可以有针对性地对自己的网站进行调整了。Google用的展示数据的方式也很特别,我就不截图了,很推荐大家去Google统计中看看这个功能。

PS:从Google统计里看到的数据,结合阿里妈妈广告位的流量统计,感觉51啦漏计的流量不少啊。

不用MT的三个理由

我在更新的另一个blogE店评,当时用了MT而没用WP,主要是为了体验一下。可是一年下来,实在用着不舒服。想换到WP去了。今天就写写为啥不想用MT了。

  1. 模板复杂。其实我觉得MT很少有好看的中文模板,也许是我没发掘过。Fenng设计的模板被很多人(包括我)拿来用,也从一个侧面反映出模板的缺乏。不过好看与否不是我说了算的,但MT的模板实在很复杂——用WP时我可以随便修改模板,可是换了MT,一不小心,模板就被我搞坏了。E店评的模板,现在都没修复回来。
  2. 编辑器不好使。很多人可能写blog都直接用HTML的,这样更直接。我不是不会,今晚我还花了些时间给GF写了个简单网页呢。可是用HTML有时看起来也很繁琐,所以我在WP里还开着富文本编辑,用的MCEEditor很不错。MT里就实在不好了,给文字加链接时出来的居然是个模态的inputbox。话说回来,就是直接用HTML来撰写,MT里做得也没有WP好。
  3. 强制生成HTML并不科学。对于流量很大的网站,用静态页面可以很显著地降低服务器的压力,可是哪怕不用任何缓存的WP系统,在DH的Shared Server上,一天支持个数百IP还是没问题的。有多少人写blog有大规模流量呢?而用MT时,假如想把阿里妈妈广告位或是Adsense广告放在所有页面上,就只得重新生成一次所有页面;改了个页面上的东西,如果不重新生成,对以前那些文章就没用;改了一篇文章,会牵连很多页面一起重新生成。细节的东西就不说了,很麻烦。

别的也没了,这3个理由,也足够说服我以后都不用MT了。可能还是因为我不够厉害,所以才驾驭不了MT——我订阅的一些牛人,貌似都用着MT。

有道我很忙

恩,走的是娱乐路线。

Rails中查找记录的异常处理

下午又在折腾一个Rails项目,遇到一些莫名其妙的问题,不过好在后来都莫名其妙地被我搞定了。不过又有一些心得,觉得快可以为这个blog单独开一个分类了。

众所周知,在Rails中查找记录可以方便地使用find方法,而假如对应数据库中有一个name字段,也可以使用find_by_name来通过name值查到记录。但当记录查不到时,两者就有了不同行为。

在irb中这样尝试:

>> User.find(3) #id为3的用户是不存在的

ActiveRecord::RecordNotFound: Couldn’t find User with ID=3
from /var/www/Lucas/vendor/rails/activerecord/lib/active_record/base.rb:1031:in `find_one’
from /var/www/Lucas/vendor/rails/activerecord/lib/active_record/base.rb:1014:in `find_from_ids’
from /var/www/Lucas/vendor/rails/activerecord/lib/active_record/base.rb:419:in `find’
from (irb):13

我把第一行关键部分加粗了,可以看到,在没有找到对应记录时,Rails抛出了一个”ActiveRecord::RecordNotFound”的异常。在进行异常处理时,只要用rescue ActiveRecord::RecordNotFound 就可以捕获这个异常。

而再在irb中进行下面的尝试:

>> User.find_by_name(3)  #name为3的用户也不存在

=> nil

依然不会找到记录,却没有任何异常,返回了nil。自然,下面的处理也不能用刚才的方法,而要检查返回的对象是不是nil。今天下午,就被它困扰很久。关键时刻,还是irb能说明问题。

还有logger也是个好东西,它的用法比较简单,大家可以网上搜搜。

青花瓷

看春晚前的晚饭,喝了至少六两老白汾,于是看晚会时就晕晕乎乎。一边还有中国打伊拉克的比赛,和弟弟在电脑上看的直播。

章子怡也来献唱了,不觉得唱得多好听。可是人家是大牌,比那些小明星们牛气多了。不过让她做啥呢,现场表演武术?肯定不行,那就唱歌吧,反正观众只看美女不听歌。

我困得厉害,迷迷糊糊趴在自己屋里的床上,赵本山的小品,只听没看。快要12点时,突然听到弟弟说,周杰伦。我腾地就起来了,一起起来的还有鞭炮的声音。孤零零的周杰伦,唱了一首青花瓷,比当年第一次亮相春晚的阵仗差多了。不过我还是被青花瓷的歌词打动了,真叫一个美。

素胚勾勒出青花笔锋浓转淡
瓶身描绘的牡丹一如你初妆
冉冉檀香透过窗心事我了然
宣纸上 走笔至此搁一半

釉色渲染仕女图韵味被私藏
而你嫣然的一笑如含苞待放
你的美一缕飘散 去到我去不了的地方

天青色等烟雨 而我在等你
炊烟袅袅升起 隔江千万里
在瓶底书汉隶仿前朝的飘逸
就当我 为遇见你伏笔

天青色等烟雨 而我在等你
月色被打捞起 晕开了结局
如传世的青花瓷自顾自美丽 你眼带笑意

色白花青的锦鲤跃然於碗底
临摹宋体落款时却惦记著你
你隐藏在窑烧里千年的秘密
极细腻 犹如绣花针落地
帘外芭蕉惹骤雨 门环惹铜绿
而我路过那江南小镇惹了你
在泼墨山水画里 你从墨色深处被隐去

天青色等烟雨 而我在等你
炊烟袅袅升起 隔江千万里
在瓶底书汉隶仿前朝的飘逸
就当我 为遇见你伏笔

天青色等烟雨 而我在等你
月色被打捞起 晕开了结局
如传世的青花瓷自顾自美丽 你眼带笑意

后来想想,费玉清唱的千里之外,若不是周杰伦出专辑时请他合唱,这个过气老歌星估计上不了春晚了。

清醒不少,又在GT上遇到了一个Aseser,给他拜年,他居然在达拉斯了。

然后就是睡觉,喝的酒弄得胃难受,想念一个人。半睡半醒的时候在想,前些日子我在blog上骂那些人,是不是太刻薄了点。虽然我心里讨厌他们,也为一些事难过许久,但,总该告一段落了吧。和好多朋友说,驱走难过最好的方式就是别去想让你难过的事们。

恩,还梦到我买了一iphone,在学校里拿着显摆。轻薄帅气。大年初一托梦给我,难道真的得买iphone了?

早上穿了新衣服,在家里总像个孩子。朋友们,春节快乐。