胡说八道
百度空间 | 百度首页 
 
文章列表
 
2009-06-01 18:28

25岁啦。25年前的今天,我从妈妈肚子里跑出来了,要感谢妈妈为我做的一切,受的一切苦。贴一个歌词,希望妈妈永远开心快乐,儿子会给你争气的。回头放这个歌给你听。

《听妈妈的话》 by周杰伦

小朋友你是否有很多问号 
为什么 别人在那看漫画 我却在学画画 对着钢琴说话 
别人在玩游戏 我却靠在墙壁背我的ABC 

我说我要一个大大的飞机 但却得到一台旧旧录音机 
为什么要听妈妈的话 长大后你就会开始懂了这段话 

长大后我开始明白 
为什么我跑得比别人快 飞得比别人高 
将来大家看的都是我画的漫画 大家唱的都是我写的歌 
妈妈的辛苦不让你看见 温暖的食谱在她心里面 
有空就多多握握她的手 把手牵着一起梦游 

听妈妈的话 别让她受伤 想快快长大 才能保护她 
美丽的白发 幸福中发芽 天使的魔法 温暖中慈祥 

在你的未来 音乐是你的王牌 拿王牌谈个恋爱 
唉!我不想把你教坏 还是听妈妈的话吧 晚点再恋爱吧 
我知道你未来的路 但妈比我更清楚 

你会开始学其他同学在书包写东写西 
但我建议最好写妈妈我会用功读书 
用功读书 怎么会从我嘴巴说出 
不想你输 所以要叫你用功读书 
妈妈织给你的毛衣 你要好好的收着 
因为母亲节到时 我要告诉她我还留着 
对了 我会遇到周润发 
所以你可以跟同学炫耀赌神未来是你爸爸 

我找不到童年写的情书 你写完不要送人 
因为过两天你会在操场上捡到 
你会开始喜欢上流行歌 因为张学友开始准备唱吻别 

听妈妈的话 别让她受伤 想快快长大 才能保护她 
美丽的白发 幸福中发芽 天使的魔法 温暖中慈祥 
听妈妈的话 别让她受伤 想快快长大 才能保护她
 
======
另,最近在听周杰伦……这首是最喜欢的之一。之前一直不怎么喜欢听流行乐,甚至有时候比较不屑。其实很多还是很不错的。现在听死亡听烦躁了就开始听周杰伦。周至少是个受过系统音乐教育的,且很有才华。虽然我很不喜欢他演的片子……不过我喜欢他的歌。有很多宣传一些向上的生活态度,有很多宣传一些中国传统的文化,这些都很好。相比之下,满文军之流就显得非常恶心了。
 
2009-04-13 16:39

庆历四年春,滕子京谪守巴陵郡。越明年,政通人和,百废俱兴,乃重修岳阳楼, 增其旧制,刻唐贤今人诗赋于其上,属予作文以记之。

予观夫巴陵胜状,在洞庭一湖。衔远山,吞长江,浩浩汤汤,横无际涯;朝晖夕阴,气象万千;此则岳阳楼之大观也,前人之述备矣。然则北通巫峡,南极潇湘,迁客骚人,多会于此,览物之情,得无异乎?

若夫霪雨霏霏,连月不开;阴风怒号,浊浪排空;日星隐耀,山岳潜形;商旅不行,樯倾楫摧;薄暮冥冥,虎啸猿啼;登斯楼也,则有去国怀乡,忧谗畏讥,满目萧然,感极而悲者矣。

至若春和景明,波澜不惊,上下天光,一碧万顷;沙鸥翔集,锦鳞游泳,岸芷汀兰,郁郁青青。而或长烟一空,皓月千里,浮光跃金,静影沉璧,渔歌互答,此乐何极!登斯楼也,则有心旷神怡,宠辱皆忘,把酒临风,其喜洋洋者矣。

嗟夫!予尝求古仁人之心,或异二者之为,何哉?不以物喜,不以己悲,居庙堂之高,则忧其民;处江湖之远,则忧其君。是进亦忧,退亦忧;然则何时而乐耶?其必曰:先天下之忧而忧,后天下之乐而乐欤。噫!微斯人,吾谁与归!

------------------

很久不背,有些地方已然忘记了。温习一下,以后要背熟。

还有一个背得一直很熟的,叫《弈喻》,作者清代钱大昕。

予观弈于友人所。一客数败,嗤其失算,辄欲易置之,以为不逮己也。顷之,客请与予对局,予颇易之。甫下数子,客已得先手。局将半,予思益苦,而客之智尚有余。竟局数之,客胜予十三子。予郝甚,不能出一言。后有招予观弈者,终日默坐而已。

  今之学者读古人书,多訾古人之失;与今人居,亦乐称人失。人固不能无失,然试易地以处,平心而度之,吾果无一失乎?吾能知人之失而不能见吾之失,吾能指人之小失而不能见吾之大失,吾求吾失且不暇,何暇论人哉!

  弈之优劣,有定也,一着之失,人皆见之,虽护前者不能讳也。理之所在,各是其所是,各非其所非,世无孔子,谁能定是非之真?然则人之失者未必非得也,吾之无失者未必非大失也,而彼此相嗤,无有已时,曾观弈者之不若矣。

 
2009-04-08 00:39

“对酒当歌,人生几何?
譬如朝露,去日苦多。”

                                                         -------《短歌行》

曹操是我非常喜欢的一个文学家。这种四字一句的诗,写过几首,都非常的棒。文字中透着古朴,有一种大巧不工的磅礴气势。他似乎经常会有对人生、对生命的思考。有时候会说,“何以解忧,唯有杜康”,有时候则话锋一转,说道:“老骥伏枥,志在千里。烈士暮年,壮心不已”。曹操虽然雄才大略,在生命面前,有的时候可能也是非常的无奈吧。想不开的时候,就喝一些酒;喝得高兴了,就又开始积极的看待生命了。我觉得这样非常的潇洒。

我时不时的会对各种事情都看得很轻,因为过几十年,就都没有区别了。生老病死,我们都不能改变。这个不是一个看待生活的正确的态度。现在我明白了,虽然我们时间很少,但是我们要过得精彩。要有开心,有刻骨铭心的感情,也会有痛彻心肺的悲伤,会有成功,也会有失败。什么都要经历,任何时候都要努力。过程往往是最重要的,因为再多的或许我们都不能把握。这样以后回过头来,有人问我们,what have you been doing? 我们可以笑一笑,然后告诉他:

I have been living my life.

生命就算是朝露,也要做最剔透的那一颗。

 
2009-03-29 16:54

今天早上爬起来,洗漱完毕去处理杂事,包括吃饭买电池还款洗车等。路过一个民生银行的ATM,于是取钱。取了2000,后面多了一个女的。我一看,旁边几个ATM都没人,不理解她为什么排我后面,回头用余光看了她一眼,也没觉得有啥问题。不过还是多加了小心,又取了2000,然后大步流星的就走了。

走出去好远了,听后面有高跟鞋gadergader跑步的声音,有一个女的喊,先生,先生!我觉得好像是喊我,于是就回头。一看是刚才那个女的。冲上来给我一张卡,说,你忘记拿卡了。霎那间,我老泪纵横,嘴唇翕动着,不知道该说什么好。过了两秒才反应过来,赶忙连声道谢。她转身就走了。

我把采购的东西往后备箱里一扔,就冲到旁边中信银行的ATM去查余额,一看,一分没少。这才放心。还是好人多啊。

另外卧佛最近一直在保佑我。回头要去还愿。心诚则灵。感谢无名mm,感谢卧佛,感谢生活。

 
2009-03-26 00:21

最近在听Faceless,很好听。现在很喜欢这种tech流的死亡,另如Necrophagist。另外在整理一个youtube的playlist,里面是我喜欢的曲子。

Youtube is banned again for no obvious reason. 我不知道国内这样成天封这个封那个到底有些什么用。在大_陆外呆了一年,明白了什么叫自_由以后,整个人反而变得很平和,可以看惯各种各样的事情,而不成天骂街了。现在回来半年多了,好像整个人又变愤青了,看见很多东西都非常的想骂街。比如一帮代表开会讨论他们这套大会制度是“唯一正确”的啦,什么某代表55年没投过反对票啦之类的。那要你有啥用啊?谁让你代表我们的?一天到晚这个不让看,那个不让说,看一看,说一说能怎么了?河_蟹就是把所有不河_蟹的声音都消除了,不河_蟹的东西都不让看了,就河_蟹社会了吗?这就是彻头彻尾的强盗逻辑。越不让说越不让看,就越憋得慌,心里就越撮火儿,就越不河_蟹。防民之口,甚于防川,这点儿简单的道理都不明白么。其实不是我自己愿意当愤青,实在是有些事情完全他妈的没有道理。我交了这么些税,就为让你们想法子不让我上youtube?就为让你去大会投55年赞成票?

时间玻璃以前说过,你知道slipknot为什么好听?因为他们有愤怒感。其实确实是如此。我愤怒的时候听这些东西,就觉得尤其的好听。没道理的事情太多了。我一愤青,就文采全无,凑合着看。。其实他妈的我已经够顺民的了。

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

工欲善其事,必先利其器。这个成语是某年我表哥暑假来我家的时候,我爸每天给我们布置背成语的任务的时候背下来的。很多古话说得都有道理之极。好比刚才那个防民之口,甚于防川。我很怀念那个时代。有文化的人可以随便两句话就说出很牛逼的道理,然后流传后世,十八代灰孙子都口口相传,佩服得不行。行为怪异点儿,就是狂士。比如我这样儿的。听个死亡金属边耕地边甩头,一个偶然的机会被一个庄稼汉看到了,就传开了。然后一帮其他的名士就来拜访我,跟我扯淡。扯出来的东西继续流传后世。大家互相都特别景仰。

好像跑题了。我以前一直觉得软件开发流程这个东西没有必要弄得太复杂。以前上班的地方就搞得很厉害,很费劲,大家还都挺乐此不疲,美其名曰CMMI。但是现在回想起来,好像事故是不多,只有一次好像完蛋了,我去加了个班搞定了。其他都还满顺利。当然工作效率也不高,我呆的一年好像总共没上线几个模块,所以本没有那么多东西可以出错。现在我发现该有的就是要有,不然很多东西都浪费在沟通的错误上了。没有文档,写什么东西都要去问别人。然后沟通不对,就会错。错了以后说不清责任,因为没有东西留在文字上。其实写个文档没有那么难的,封装一个好的api给别人用也没有那么难的,总共花不了自己俩小时的时间,却可以省别人好几天。一个混乱的软件开发流程是一定会导致一个混乱buggy的产品的。所以现在我花很多时间把自己的代码写得再好看一些(谢谢eclipse教了我很多),封装得再易用一些,文档详细一些。偶尔改改之前的代码。我终于明白为什么有人喜欢推了重写,尤其是推别人的。原来很有快感。

 
2009-01-02 22:11

2008颇有收获。认真的学了门硬手艺,做得还不错,虽然和小神童们有一定差距,但是可以安身立命。每天都在多多少少学到一些新的东西,因为犇犇的光芒照耀着我。英语听力更上一层楼。因为坚持每天晚上看discovery和top gear,好看得不行。熟练了驾驶。挣了一些钱,然后全花掉了。养成了每天和妈妈通电话的好习惯。克服了在blog骂街的毛病。吃了一些苦,学会了知足和感谢生活。

克服了骂街还是很好的一件事情,因为我发现骂来骂去的也没什么用。如果压根儿不骂,则不那么生气。也或许是又长大了一岁,对于弱智也见怪不怪,更宽容了。

我调查了一下,我同龄人与家人通电话的频率大概都是一周一次。而我是一天一次。这个习惯是在香港养成的。因为我妈认为香港到处都是古惑仔和黑社会,是一个很危险的地方。所以我只要24小时还没有电话,她就抓个狂。后来我习惯了也就习惯了,有时候一天不打还有点儿不爽。后来我想了一下,这是个好事情,不要等的没得说了才后悔以前没有多说两句。

前半年基本都在看discovery,每天看好几集,同一频道的不同节目,都是从emule上拿下来的。mythbuster有一阵看得挺入迷的,后来看多了觉得他们有点儿黔驴技穷了,基本每集就是用炸药做点儿爆炸效果就草草了事了,有些事情也根本没有必要去验证,比如生气的时候开车的油耗比平时高。验证的方法也不科学。不过总的来说还是比较好看的。discovery基本都是美音,看了半年,基本就可以完全扔掉字幕也不会有哪句听不懂了。后来改看topgear,基本完全听不懂。有些人声称我们从小接受的是纯正的英音的英语教学,而其实我早就发现根本不是这么回事儿。包括四杆大烟枪,我就基本没有一句可以直接听懂。看了几个月,比较熟悉那仨主持人的发音了,就渐渐的能听懂不少了。最好懂的应该还是James May的发音。其他两个人差不多。topgear绝对是我目前看过的所有电视节目里制作最精美的一个了,喜欢车或者英式发音的同学都应该看看。某些集是有字幕的。目前更新到12季08集了。

祝各位新年快乐,来年发财!

 
2008-10-24 19:54

In the previous posts I've explained how to set up the development environment and how to create a blog editting page as well as save the post. Now it's time to view the blog we have just created. So we need a page where we can see all the blogs.

Let's make this page the default page of our site. To do this, we create a function called 'index':

@expose(template="blog.templates.index")
    def index(self,cid=None,**kw):
        if cid: #category id is provided, return all posts belonging to this category
            category = Category.get(int(cid))
            blogs = list(Blog.selectBy(category=category).orderBy(DESC('time')))
        else:   #all posts
            category = None
            blogs = list(Blog.select().orderBy(DESC('time')))
        return dict(blogs=blogs,category=category,categories=list(Category.select()))

I don't think I need to explain anything here because it's very similar to the functions we have already created in previous tutorials. And also, the index.kid template file is similar too:

<body>
<h1 py:if="category">Posts under ${category.name}</h1>
<h1 py:if="not category">All posts</h1>
<div id="blogs">
    <div py:for="b in blogs" class="blog" id="b${b.id}">
        <div class="subject"><a href="/viewpost?bid=${b.id}">${b.subject}</a></div>
        <div class="author">${b.author}</div>
        <div class="time">${b.time}</div>
        <div class="content">${b.content}</div>
        <div class="etc">
        Category: <a href="/?cid=${b.category.id}">${b.category.name}</a> |
        <a href="/viewpost?bid=${b.id}#comments">Comments(${len(b.comments)})</a> |
        Views(${b.views}) |
        <a href="editblog?bid=${b.id}">Edit</a> |
        <a href="#" onclick="deleteblog(${b.id});return false;">Delete</a>
        </div>
    </div>
</div>
</body>

As you can see, to get the category a post belongs to, all we need to write is blog.category. This is much easier than writing sql expressions.

After we've got these modifications done, we should be able to see a page similar to the following one:

I tuned the css a little bit so that it will not look too ugly.

The tricky part is the Delete link. This time I'll use AJAX to do the deleting job.

<a href="#" onclick="deleteblog(${b.id});return false;">Delete</a>

On clicking this link, a javascript function deleteblog is called:

<script type="text/javascript">
//<![CDATA[
function deleteblog(bid){
    if (confirm('All the comments will be deleted too. This operation cannot be undone. Are you sure you want to delete this blog? ')){
        new Json.Remote('deleteblog',{onComplete: function(result){
                if (result['deleted']==0){
                    blogid = 'b'+bid
                    $('blogs').removeChild($(blogid));   //remove the blog from this page
                    return;
                }
                else{
                    alert('Failed to delete this blog, try again later.');
                    return;
                }
            }}).send({'bid':bid});
    }
}
//]]>
</script>

this script tag should be added into <head></head>. I'm using mootools instead of Turbogears' official javascript lib MochiKit to do the AJAX call here(to me, mootools is a way better js lib than MochiKit). To include mootools, first download mootools.js from their website and copy it to /static/javascript, and then add <script type="text/javascript" src="/static/javascript/mootools.js"></script> into the <head> tag.

This function makes an AJAX call to http://localhost:8080/deleteblog, and send the id of the post('bid') as the parameter. The response is returned in JSON format.

server side function:

@expose(format="json")
    def deleteblog(self,bid=None,**kw):
        if not bid: return dict(deleted=1) #bid not provided, delete failed
        else:
            blog = Blog.get(int(bid))   #get the blog
            for c in blog.comments: c.destroySelf()     #delete all the comments
            blog.destroySelf() #delete the post itself
            return dict(deleted=0) #deleted, 0 indicates success

As you can see, to get all the comments of a blog, you just have to write blog.comments; similarly, category.blogs will get you all the blogs belonging to this category.

the response is passed to the parameter 'result' of function which will be called when the AJAX call is completed. If result['deleted'] is 0, which means we have successfully deleted this post, we remove the post from this page. Pretty simple, isn't it?

Now you should be able to delete a post without refreshing the page.

Are we forgetting anything? Yes, the viewpost page and the comment part. I think by far you have learned enough to create a page all by yourself. I have put all we've got here so far in an archive, which can be downloaded here.

If you have any questions, please drop me a comment. My name is Stone and I'm the web developer of PapayaMobile.com.

 
2008-10-24 17:11

In the previous post I've showed you how to create the development environment, and this time we'll create an editting page for our blog.

This page can either create a new post or edit an existing post. Let's name it "compose".

To make life easier, I will not focus on the styling of our blog, so I'll just use the default master template that quickstart has generated for us. First, go to templates folder, and open master.kid. Turbogrears uses a templating system called kid, which is very well designed and easy to use. The master.kid acts like a framework of all the pages(of course you can choose not to inherit from it too), which includes a common header and a common footer, etc. We'll keep the header, content and footer, and remove all the unnecessary parts in the body tag like this(you can skip this part if you are happy with them):

<body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'" py:attrs="item.items()">
    <div id="header">&#160;</div>
    <div id="main_content">
        <div py:replace="[item.text]+item[:]">page content</div>
    </div>
    <div id="footer">
        <img src="${tg.url('/static/images/under_the_hood_blue.png')}"
            alt="TurboGears under the hood" />
        <p>TurboGears is a open source front-to-back web development framework
            written in Python</p>
        <p>Copyright &#169; 2007 Kevin Dangoor</p>
    </div>
</body>

Much better. The next step is to create a compose page of our own. In the templates directory, rename welcome.kid to compose.kid, then open it. First, delete the unnecessary parts like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
    py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
<title>New post - Stone's Blog</title>
</head>
<body>
</body>
</html>

Notice 'py:extends="'master.kid'"' indicates this page inherits from the master.kid, which means the header and footer and other stuff will be carried on to our compose page.

Then open controller.py, delete the unnecessary parts like this:

import turbogears as tg
from turbogears import controllers, expose, redirect, paginate
from blog.model import *

class Root(controllers.RootController):

then we are ready to write the server side code for our compose page, which is defined in a function called compose. This function will be called when we visit http://localhost:8080/compose.

@expose(template="blog.templates.compose")
    def compose(self, bid=None, **kw):
        if bid:
            blog = Blog.get(int(bid))
        else:
            blog = None
        return dict(blog=blog,categories=list(Category.select()))

@expose is a special kind of function in python called the decorator. In this decorator, we specified a parameter called templates, indicates the template we are going to use. compose takes 1 or no parameter. bid is the id of the post we'll edit, and if it is not provided, we are creating a new one. We have to assign a category to our post when editing, so we need all the categories too. Finally, we return this blog object and all the categories back to our template file - compose.kid.

<body>
<h1 py:if="blog">Edit Post</h1>
<h1 py:if="not blog">Compose</h1>
<form action="/saveblog" method="post">
    <input py:if="blog" type="hidden" name="bid" value="${blog.id}"/>
    <div>Subject: <input name="subject" value="${blog.subject if blog else None}"/></div>
    <div>Author: <input name="author" value="${blog.author if blog else None}"/></div>
    <div>Category:
        <select name="category">
            <option py:for="c in categories" value="${c.id}" selected="${'selected' if blog and blog.category==c else None}">${c.name}</option>
        </select>
    </div>
    <div>Content:</div>
    <div><textarea name="content" cols="50" rows="10">${blog.content if blog else None}</textarea></div>
    <div><input type="submit" value="Submit"/></div>
</form>
</body>

Let's walk through this line by line.

<h1 py:if="blog">Edit Post</h1>
<h1 py:if="not blog">Compose</h1>

this indicates, if the blog is None, then the page title will be Compose, meaning that we are creating a new post; else page name will be edit post, meaning that we are editing an existing post. The whole tag will not be created if the expression in py:if is not true.

<input py:if="blog" type="hidden" name="bid" value="${blog.id}"/>

if we are editing a post, we need to carry the id of our post on or there's no way we'll should update the changes to an existing post instead of creating a new one when we save it.

Subject: <input name="subject" value="${blog.subject if blog else None}"/>

this indicates the subject textbox will show the blog's subject if we are editing it, or will show nothing if we are creating a new post. Notice that if None is the value in ${}, then the whole value attribute will not be created. This is a very neat design because it won't leave a 'value=""' or 'value=' in the html generated, which could cause some trouble if we are dealing with attributes like 'selected' and 'checked', because if something like 'selected=""' is generated, the browser will regard it as the selected item just like any other items with 'selected="selected"' in their attributes, and this is not what is desired.

<select name="category">
     <option py:for="c in categories" value="${c.id}" selected="${'selected' if blog and blog.category==c else None}">${c.name}</option>
</select>

notice the py:for in the option. This means the kid template will generate len(categories) option tags, each with its category's id assigned to the value attribute, and a display text of the category's name. The generated code may be something like this:

<select name="category">
      <option value="0"> Default </option>
      <option value="1" selected="selected"> Web development </option>
      <option value="2"> Funny </option>
</select>

Look how simple it is to generate a dropdown list with the kid template. Be ware that the kid template is a xml document so we cannot offer to generate code like: <option selected>Funny</option>.

And now we are ready to see what we've got here. Save the files and start the web server. Navigate to http://localhost:8080/compose, we should be able to see the compose page now:

Cool! Now we'll have to define a function that can save the post. Remember the action attribute of our form in the compose page? Yes, we are going to create a function called 'saveblog'.

@expose()
    def saveblog(self,bid=None,subject=None,author=None,category=None,content=None,**kw):
        if category:    #category is selected
            cate = Category.get(int(category))
        else:   #category is not provided
            if Category.selectBy(name="Default").count()==0:    #if Default category does not exist
                cate = Category(name="Default")     #then create it
            else:   #Default category exists
                cate = Category.selectBy(name="Default").getOne()   #get the Default category
        if bid: #editing an existing post
            blog = Blog.get(int(bid))   #get the post
            blog.set(subject=tostr(subject),author=tostr(author),category=cate,content=tostr(content)) #update
        else:
            blog = Blog(subject=tostr(subject),author=tostr(author),category=cate,content=tostr(content)) #create a new post
        raise redirect('/viewpost',bid=blog.id)

notice that we have a "tostr" function here(defined outside the Root class):

def tostr(s):
    if type(s)==unicode:
        return s.encode('utf8','ignore')
    else:
        return s

This function is designed to handle unicode characters.

I've left a comment behind every line of saveblog, which I think is already very self-explanatory. The only thing I want to point out is that we did not pass any parameters to the expose decorator, because there's no page to show. What this function does is to save the blog and then guide you the page where you can read it. After adding these 2 functions to your controllers.py, and hit the submit button on the compose page, you'll probably get a 404 error. That is because we haven't got the viewpost funcion ready yet. We'll create this page later.

 
2008-10-24 15:12

Turbogears is a rapid web development frame work, which I've been using for a while now. Unlike Django, which is pretty buggy, Turbogears offers a more stable environment. And it truly makes web development easier.

In this tutorial I'll show you how to build your own blog with turbogears in 2 hours. First thing first, you have to make sure python and turbogears are all properly installed and configured on your computer. There is a very detailed installation guide here so I'm not gonna explain this in details this time.

The next step is to create the project using turbogears' administration tool - quickstart. It will create the project template for us. Let's just name our project 'blog'. To create the project folder, open your cmd window or terminal window, and type:

         "tg-admin quickstart blog"

You'll be asked to enter the package name, which is 'blog' of course, and whether you need Identity control in this project. Turbogears offers a well-written identity control package, which have saved you a lot of time. But we'll not use it at this time.

The quickstart command generates a bunch of folders and files like this:

To start your website, enter the blog folder, and type "python start-blog.py". By default, the server listens to the 8080 port of the localhost. Open a browser and navigate to http://localhost:8080/ and you should be able to see the default welcome page of turbogears telling you that "your application is now running":

Next, we'll probably have to determine the data structure of our blog. By default, Turbogears uses SQLObject to handle the database objects, which saves you from writing complicated sql commands. And the database models are defined in model.py.

First, every blog is belonged to a category, for example, 'Funny','IT', etc. So we'll add a table called Category first:

class Category(SQLObject):
    name = StringCol(length=50)
    blogs = MultipleJoin('Blog')

MutipleJoin indicates that there could be a number of blogs belonging to one category.

then Blog:

class Blog(SQLObject):
    author = StringCol(length=50)
    subject = StringCol(length=200)
    content = BLOBCol(sqlType='blob', default=None)
    category = ForeignKey('Category')
    views = IntCol(default=0)
    comments = MultipleJoin('Comment')
    time = DateTimeCol(default=DateTimeCol.now)

ForeignKey('Category') indicates that this blog belongs to a category.

Comments:

class Comment(SQLObject):
    blog = ForeignKey('Blog')
    author = StringCol(length=50)
    email = StringCol(length=100)
    content = StringCol(length=1000)
    time = DateTimeCol(default=DateTimeCol.now)

Please refer to the SQLObject doc for grammar details. I think the grammar is pretty self-explonatory.

After we've created these 3 database object, the next step is to actually create it in our local database. Take mysql for example. First, find dev.cfg in our project directory and open it. Comment 'sqlobject.dburi="sqlite://%(current_dir_uri)s/devdata.sqlite"' by adding a '# '(a blank space is needed after the #), and then uncomment line 11 (or the line with 'mysql:' in), modify it to your mysql setting, e.g.:

sqlobject.dburi="mysql://root:@127.0.0.1:3306/blog"

this means that we are using the mysql server at localhost, port 3306, with the user root and no password, and the database named 'blog'.

Then add the following lines to the very beginning of model.py:

from sqlobject import *
from turbogears import config

con = "mysql://root:@127.0.0.1:3306/blog"
sqlhub.processConnection = connectionForURI(con)

Now we are ready to create the tables in our database. Stop the server(by hitting Ctrl+C in the previous cmd window where we started the web server) and type:

tg-admin sql create

and the tables are created.

Notice that MultipleJoin does not actually create a column in the table, while ForeignKey creates the blog_id and category_id columns.

By far we have successfully set up the evironment and are ready to rock. If the evironment is already set up for use, creating the project folder / configure the config file / creating tables in the database wouldn't take us more than 5 minutes. In the next post I'll show you how to create pages for our blog.

(I'm not a native English speaker so forgive me if there's any grammar mistakes.)

 
2008-10-19 21:08

http://www.apptism.com/apps/papaya-game-edition

直接下载链接:http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294014416

Requirements: Compatible with iPhone and iPod touch Requires iPhone 2.0 Software Update

各位iphone,麻烦帮忙广告给你用iphone的朋友们!给大家鞠躬啦!

 
2008-10-11 16:22

前两天联系到了初中的语文老师周老师,不由得惭愧万分,还是周老师通过别的同学要了我的手机号才联系到的。周老师是我学习生涯中对我影响最大的老师。初中毕业以后,伴随着搬家、升学,以及周老师的跳槽,渐渐的就失去联系了。每年教师节也少了问候。曾经打听过一个电话,打了几次都没有人接,后来去了香港,就作罢了。

今天和周老师打电话,要约见一面,时间还没有订好。电话里他问,你现在还写一些东西吗?有博客吗?我脸就红了,说,以前还写一些,现在不怎么想写了。也不写正经东西。自己想了一想,博客上都是啥?无非就是些不登大雅之堂的无聊玩意,粗口、器官、寒谜语,另外就没有了,见不得人啊。以前我写作文什么的还相当有水平,高考完了以后就没写过几篇正经的东西了,转述个故事还要烂尾,然后被人骂没有xjj,都不敢还嘴的。

周老师是绍兴人,如果我没有记错。普通话不是很标准,所以以前老是诬陷我“砸砸盒(砸闸盒)”的时候,我就老听不懂。当时好多人都被周老师扣帽子、安标签儿,比如我是砸闸盒,就是破坏电灯开关儿;caoshuai是趴沙坑旁边看小孩儿玩儿沙子;songwei是筛糠式的跑步法之类的,现在想起来都很有意思,我就观察不到这样的事情。我上初中的时候也不好好学习,但是周老师总是对我很有信心,我中考考得砸了以后,他还要专门约我出来跟我聊天。现在想起来,这样全心全意对待学生的老师实在是很少。我当时还感动得写了篇作文,称他为良师益友,不过估计他是没有看到,那已经是高中时候的事情了。

他对我的影响,一半在语文上,一半在生活和做人上。

先说说语文上的影响吧。周老师有很多口诀,像念咒儿一样,老是重复,不由得你记不住。当时他很少留作业的,而统考的时候,我们的语文成绩总是全市数一数二。很多很容易弄错的东西,他老念叨,就记得特别牢。写文章上,周老师也有好多咒儿。比如“人以事显”,我就一直记得。要描写一个人或者说一件什么事情,必须言之有物。要写你妈妈有多好,得说明白怎么个好法儿,不能就是妈妈好啊妈妈好啊这样的写一篇。包括议论文,我们要反对北京限行,就要说清楚理由,比如限行会刺激有钱人再买车,对于缓解交通压力其实没有帮助之类的。所以我从高中起,写文章就很多人喜欢看,因为里面总是有具体的事情,看着就不会太难过。

还有一个,叫开门见山。周老师举过最多的例子就是,有人一写作文,比如《我的好妈妈》,第一句话先是:每个人都有妈妈,我也不例外。这就是一句废话,根本没必要说的。不过我国有优良的八股文传统,很多人还是喜欢写这样的套话。周老师教出来的学生就没有这样写的。

另外是标点,一直到现在,我还总是说。有很多人根本不知道什么时候用什么标点,比如那种全篇都是惊叹号的,就特别刺激人。周老师的学生也没有这样用标点的。

还有就是人称。有些人写文章,喜欢用“你”,这样就不礼貌,虽然他的本意可能并非如此。举个例子,我前面写了这么一句话:“包括议论文,我们要反对北京限行,就要说清楚理由,比如限行会刺激有钱人再买车,对于缓解交通压力其实没有帮助之类的”。我就没有写成“你要反对北京限行,就要说清楚理由”之类的。这两句话,表意是完全一样的,而第一人称就显得委婉、谦虚,第二人称就显得有些居高临下。虽然我们平时说话可以这么说。

再一句话,叫“不管学问有多高,先把字写好”。这个说的是很对的。这里的写好,不是说要像书法家一样写得多么好看,而是说要写清楚,让别人能看懂。草一点儿可以,但是要可以识别;写不好草书的,就老老实实的一笔一画的写,这是对要看你字的人的一种尊重。我的硬笔字还是写得不错的,不是说特别特别好看,但是比一般没练过的还是要强一些,而且可识别。周老师自己写一种有趣的字体,比较圆,但是间架结构很不错,有的字大些有的字小些,摆在一起看呢,也很舒服。我的字就硬一些了,不会那么圆。我父亲的字就特别硬,特别有棱角,也很好看。我妈妈筛简历的时候,就很不喜欢看到那种难看还潦草的字,那种一看就觉得这人稀里糊涂的,就不想录取。还有些人则是不知道什么样的字是好看的。他写的也很认真,就是很认真的把字都写得一样丑,这儿拐一下那弯一下的。像我小时候,有一阵流行签花里胡哨的名字,比如本来一个好好的横,一定要写成nike标志那样,从上面拐一下。这样就很丑了,而有些人不知道。我是因为名字里不是横就是竖,连个撇和捺也没有,加起来才15画,还没别人一个字笔画多,想跩也没法跩,所以直到现在,我还是规规矩矩的签自己的名字,让人一看都知道我叫什么名字。一个人的字其实就是自己的名片,是要给别人看的。

生活上周老师对我的影响也很多。比如环保,就是他大力提倡的。而我上初中的时候,大概还没有这个词,不像现在铺天盖地的。他去买菜,就拿一个布兜子;他也叫我们回家跟家长说,买菜的时候自己拿一个布兜子。后来我妈妈果然就拿一个布兜子去买菜。当然有时候也会忘记。

还有就是做事情要有计划之类的。这个我到底也没学会,后来我干什么事情还是想起一着儿是一着儿。可能是因为我妈就这样,这叫一傅众咻,我妈的影响盖过了他的影响,不过毕竟还是教了的,虽然我没有学会。可能有人学会了。

大概也就是因为周老师,我一直到现在还是很想去当老师。不过当老师要奉献精神,也要学历。我呢,都没有。想当大学老师吧,学历不够;想当初中高中老师吧,又嫌小孩儿烦人,或者薪水低。不过一般和现实距离很远的东西,都可以叫理想。那么当老师就可以说是我的一个理想吧。初中高中老师呢,教的学生有升学压力,教他一些别的东西,家长就不干了;大学呢,很多人都定型儿了,再想拧回来,就很难了。我在清华上学的时候,就见过很多次上着上着课就随地吐痰的,啪的一声儿,还挺响。然后就继续上课,毫无知觉。这就是从小没有人教他的结果。都老大不小了,也爱面子了,就没有人愿意说他了。但是其实自己丢了很大的脸,只是自己不知道罢了。我就很想和周老师一样,有机会在小孩成长的过程中就告诉他这些事情,免得他长大了丢人现眼。

想了一想,上面说的这些事情,无外乎都是两个字:素质。素质教育也是新名词儿了,不过我们在初中就已经实践过了。我觉得我们非常幸运,可以遇到一个身体力行、有责任心的素质教育先行者。要不我现在,没准也会丢了人而自己浑然不觉。

祝我们的周老师身体健康。

 
2008-08-17 13:27
某君,不知道从哪里搞来三个T的毛片儿(1T=1024G,3T大概比我下载过的所有电影加起来还多),无从筛选。遂看paper若干,写程序一个,利用音频将毛片分类汇总,并具有相当的准确率。“这都是我利用业余时间搞的”,某君说。目前国外某些大学的分类准确率还要略高一些,不过某君仍在不懈的调优。太伟大了,太暴强了,不得不记录一下。
 
2008-07-03 22:59

恩斯特警长眉头紧锁。在过去的一个月中,奥地利的不同地区又有四名性工作者神秘失踪,其中有两人的尸体已经被发现。最让警方难堪的是,他们直到读了报纸,才意识到奥地利出现了一个连环杀人犯。作为世界上犯罪率最低的国家之一,奥地利每年大概只有90到120人死于凶杀;连环杀手更是闻所未闻。奥地利警方第一次接触这样的案件,显然有些摸不着头脑。犯罪现场除了一些红色纤维,没有采集到任何证据;而没有犯罪嫌疑人供比对,这样的证据显然没有任何的用处。退一万步讲,就算有了犯罪嫌疑人,而且证实红色纤维确实来自他的衣物,也顶多只能是个间接证据,只能证明他与被害人接触过。由于职业的特殊性,一个性工作者一天可能要接待数十位顾客,所以还是什么都说明不了。

过去的一个月里,警方不断的走访被害人的亲朋好友,试图从中找出有嫌疑的对象,但是没有任何收获。消息在媒体的帮助下,在奥地利铺天盖地的传播开来。两个月过去了,案件的侦破依然没有任何进展,警方倍感压力。与此同时,对于连环杀人犯的恐惧和对警方无能的批评也在舆论中传播开来。舆论要求警方透露案情进展,面对媒体,开诚布公。要求采访的记者越来越多,警方无奈之下,负责此案的恩斯特警长决定接受奥地利知名作家昂格维格的采访。

昂格维格是一位有着传奇经历的高调作家兼电台记者。他曾因谋杀的罪名入狱。在狱中,他写过自传和剧本,出人意料的大获成功,从而成名。服刑期满后,他继续着自己的创作,并参加电台、电视台的访谈节目,或是在公共场合朗读自己的自传。他常常在访谈节目中,以自己亲身的经历,参与罪犯服刑完毕之后重归社会的讨论。他严谨的思维和谈吐、精干的外表和危险的历史,和他一年四季都戴的围巾一起成为了他的标志,而且吸引了很多女性的注意。昂格维格在杂志上读到有关连环杀人案的消息以后非常感兴趣,并希望在电台采访负责此案的警长恩斯特。

采访如约举行。采访的主题是,维也纳地区性工作者的恐惧程度有多高,以及案件的侦破进度。恩斯特警长一一作答。整个采访仅仅持续了20分钟,因为警方知道的并不比媒体多多少。恩斯特用一连串的“无可奉告”和“没有进展”匆匆的结束了这次采访。

案件的侦破的确毫无进展。4名失踪的性工作者里,两人的尸体已经被找到,另外两人下落不明。正在警方毫无头绪的时候,其中一名下落不明的性工作者蕾吉娜的丈夫突然找到警方,说他昨夜凌晨3点接到了一个很奇怪的电话,怀疑是凶手打来的。凶手声称他在蕾吉娜的钱包中找到了他的联系方式,并在电话里详细的描述了蕾吉娜的遇害过程。凶手笑着说,她脖子被勒住的时候,一边哭叫,一边扭动着她的长腿死命的挣扎。警方做了详细的记录,然而依然束手无策。

就在案件陷入僵局的时候,一位已经退休了的老警官偶然在报纸上看到了关于这个连环杀人案的报导。一个名字突然飞快的闪过他的脑海。他匆匆的抓上报纸赶往警局。

他认为他已经知道谁是凶手了。

 
2008-06-30 22:22

1990年。奥地利西部,福拉尔贝格。

一个女子的尸体被人在公路旁边的树林中发现。死者被面朝下放在离公路不远的地方,脖子上缠绕着一条粉色的丝袜。警方封锁了现场并展开调查。很明显,死者死于窒息,而凶器正是自己的丝袜。

现场的调查让警方大失所望。从周围的环境和现场的情况来看,案发现场应该不在这里,而是女子死后被弃尸于此。一个细心的女警官在女子的衣服上发现了一些非常细小的红色纤维,而被害人并没有任何衣物可以留下这些纤维;除此之外,警方一无所获。死者为31岁的海蒂汉玛洛,是一个职业性工作者,两周前被家人报告失踪。

几乎于此同时,200英里外的格拉兹警方也在展开对一个类似案件的调查。死者同样为性工作者,被人用自己的胸罩勒死。犯罪现场没有采集到任何有用的证据,甚至连死者的名字都没有查到。由于死者职业的特殊性,死者可能会接触到很多人,使得调查取证的困难倍增。

而警方还不知道的是,一个月后,还会有四名性工作者相继从街头消失。

 
2008-06-30 21:50

讲个故事凑个数吧。昨天看了一个discovery讲的案子,相当不错,我转述的话,大概还讲不了那么好。不过可以试一试。

我好像一直对各种案件、黑手党什么的都很有兴趣。这大概是我一贯的作风,喜欢一些叶公好龙类型的刺激事物,比如吃辣,比如极端金属,比如各种讲黑手党、抢银行、凶杀的故事,因为都不会对自己造成啥伤害,也不用真的去做,除了吃辣,其他都是看看听听,爽一下就完了,没什么代价。

 
     
 
 
最新照片
 
   
 
日历
 
     
 
个人档案
 
goddamner
男, 25岁
北京 海淀区 
上次登录:
16天前
加为好友
 
   
 
订阅我的空间
 
已有人次访问本空间
 
订阅RSS  什么是RSS?

您也想拥有这样的空间?请点此申请。
     


©2009 Baidu