Friday, October 15, 2010

Blog Action Day 2010 - Clean Water

When u brush your teeth, do u ever think of the amount of clean water u used?

Let me introduce my "philosophy" :P

Here is a little green cup that i use to contain the water when i brush my teeth. I started using it since my childhood. It's around 2x years old :)



When u compare it to some normal sized container ... the red one in the photo ... u will know how little is my green cup.



Someone asked me why i keep using such a little cup? Don't u need to fill the cup more times than a bigger one.

My philosophy is that ... when u used a bigger cup, u may waste MUCH MORE clean water. This is the same as the plate or bowl that holds food. If u get a big plate, u may fill much more food with it. This is because our habit is to fill something "full". So, the smaller the container, the less you can fill with it. Most of the time when u fill something ... u will fill more than u need. If u agree ... try look for a smaller container :)

support Blog Action Day!

Sunday, October 10, 2010

學習 、工作

好耐無寫自己"內心"o既野 (小弟語文能力唔好, 唔識形容乜野係"野" ... 寫下寫下, 可能係內心獨白吧) ... 襯今日10.10.10, 又咁岩同一位朋友傾過一d認真話題... 有感而發... 雖然好眼訓, 但都要寫.... 因為.. 曾經在友人看過一篇 blog post (沒記錯的話是友人的 "森路歷程", 錯了勿插 :P), 開場白大概是 "曾經聽友人說過, 回家了, 累了. 若是有 blog "要" post, 再累也要先 post 後休息. 不然, 過了那興致, 之後想再 post 都不可能了"... 可能怕是失去靈感了吧.

今次, 小弟想講下, 小弟 常常常常 聽到的一句話. "工作的時候,好多時會學到新野". 我想問: 什麼是工作? 什麼是學習?

如果你曾經簽過一份工作合同, 上面應該會有.. 如 "You are expected to put your best effort on accomplishing the tasks assigned to you" 咁o既說話. 那... 在我心中點睇乜野係工作? 如果我是 interviewer, 又如果有一位求職者跟我說: "我進這公司, 接這工作, 是希望學到新野..." 我一定好串咁問佢: "你來學野? 想學乜野? 我呢到無乜教材".

係我心目中, 學習 跟 工作 完完全全是兩回事...

工作, 你老闆肯定想你將最好o既野做出黎. 如果你認為岩岩學完o既野, 做出黎可以交差, 那還是不是最好的? "best effort" 了? 其實這沒有答題, 因為每個人追求的 best 都不一樣. 而我想係到表達o既係... 好多時, 工作是有時限的. 做得黎又要學, 學得黎又要做.. 你學得又有幾深入呢? 工作上, 遇到一些從沒遇過的東西, 給你遇上了, 是你多了一點這東西的 經驗, 是你 "認識" 多了一樣東西. You "know" something new. 那是真正的"學習"嗎?

學習, 到底係我心目中又是什麼??

不知是好運還是惡夢... 小弟畢業作 (即 fyp) 遇上了 e-Learning. 那時看了一本書.. 大概是講 adult learning... 什麼是最好的學習?? What is the BEST LEARNING? 最好的學習是來自內心的 渴求 (難聽d叫 慾望, 即desire) .. 自發的, 有興趣的, 渴求得到的. (如果你睇番小弟所寫 ... 有關在 barcamp 2010 裡, 小弟有幸聽了 有關Consciousness 的 session... 要想知自己在做什麼, 那便要分清楚是 your desire, need, fear, or joy 哦) 工作上 所謂的學習 ??? Is it desire? Is it fear?? Or is it a NEED??? Perhaps, it may be joyful :P (someone LOVES works all day, right?) 如果你工作上所"學習"的是你所"渴求"的, Congratulation! 但是, 又有幾可, 你工作上遇到的新事物, 是你所渴求認識的那東西?? 工作好多時會有d框架 bound 住你... 請不要退而求其次的說: "那東西不能用到工作上嗎? 沒打緊, 我也想學這東西"... 那到底什麼是你 desire 的?? 又或者, 你又真係好鬼想學這 "2nd Priority" 吧 ... 嘿嘿... anyway.. 不要太貪心... "吾生也有涯,而知也無涯,以有涯隨無涯,殆矣". (在拋拋書包麼!? Remember.. my blog's name is "Emptiness Blogging"... somehow Taoism... lol)

你要學習你所 desire 的東西, 你將會付出很多, 但不一定有相對應的回報. 但係, 你又會戇戇居居咁走去完成佢... (小弟就咁戇戇居居左個 year4 + 1年 cs master degree, 諗番都好鬼戇居-.- 浪費咁多時間同精神, 仲要 put 多左 effort... but, so what? i did that. XD )

Hope you get what is Learning.

其實, 我認為互聯網是比避孕套更偉大o既發明, 因為你可以透過 超連結 (都幾超下架..) 去將有關係o既野 "連埋". 對學習來說帶來極大方便. (回想起.. 寫paper時, 找 reference 中的 reference 來看看, 沒有 hyperlink , 可以找死你)

到最後, 我想講.. 其實我寫呢篇野果時已經係 10月 11號 零晨時份 :P 改改 post date 而已. 上述只是個人見解, 如有得罪, 多多包容.

Sunday, September 19, 2010

barcamp: Consciousness

Simply speaking, Consciousness is the study about the relation between our mind and our body. Sometimes, we physically situated at somewhere but our minds go to somewhere eles... A PolyU professor shared about Consciousness in barcamphk 2010!

One key point to understand why we do something is to differentiate the following four:
- fear
- desire
- need
- joy

For example, we went to the student canteen of PolyU for lunch yesterday... Why?
From my point of view, we need to lunch and that's our need but we can lunch anywhere instead of the student canteen. So, this is not caused by need. Is it joyful? Yup, pretty joyful when chatting with other barcampers... but we can chat anywhere. Is it the desire? or is it fear? Desire to have free lunch? or fear of paying for a lunch? em... 50/50 in this case :P but I think it should be my desire of free lunch :P

Monday, September 13, 2010

tour to planet pandora

actually ... not going to planet Pandora but 张家界 and 凤凰城 :P

just wanna post some shots here :)






indeed, you can find out more shots in my facebook album ... (yep, i dont pay flickr as i'm poor :P)

http://www.facebook.com/album.php?aid=247441&id=508149973&l=93f5e6b411
http://www.facebook.com/album.php?aid=247438&id=508149973&l=839a5bea37
http://www.facebook.com/album.php?aid=247428&id=508149973&l=83e7bf4e09

PLus ... wanna post 2 pictures of the 军声砂石画 (being introduced during the tour)... that's pretty new to me.



This kind of art gives EXTREMELY HIGH "dpi". Yes, dot per inch.... Since it uses raw materials like woods, sands and rocks as the painting materials, the texture of the objects in the painting is pretty close to the texture of real objects. The following is a close-up of the bottom right corner of the painting above and you can find that there are many sands.

Thursday, August 26, 2010

GoF State Pattern implemented in Javascript UI component

In these recent weeks, i'm writing a javascript UI component that can shrink/expand and hide/show. I call it "browser" in later paragraphs.

It's a pretty easy-to-write component where it only has 3 different states as shown below.

The first state is a hidden state which the "browser" hides itself somewhere in the page.


When clicking on those boxes shown, the "browser" shows itself and presents an abstract view of data.


When selecting a little box of the list on the right, the "browser" enters a state that displays detail view of data.


Whenever in either the abstract or detail state, once the grey-out area or the little close button [x] got a click on it, the browser goes back to hidden state. And, the browser can switch between the abstract state and the detail state by clicking on some buttons.

So, it sounds strict forward and thus my very first naive attempt was to implement it by just using the event-driven approach which i explicitly controlled the hide/show and shrink/expand line-by-line with the help of some if-else statements.

But after doing that for 2-3 days... the mess becomes not-that-easy to manage and little UI bugs come out from those event handler blocks. I had to trace those handler blocks and to find out where the UI effect went wrong. So, i decided to rewrite the entire mess with the GoF State Pattern (spending half an hour or so in implementing that) and post it here :P

As i wrote, the "browser" has some states {hidden, abstract, detail} and each state will transit to each another triggered by some events. It is pretty nice that the situation aligns to the state pattern perfectly. So, what i need to do with javascript is to implement a browser object that holds a state object where the state object references to either a hidden or abstract or detail state object.



The above class diagram shows some of the details of my implementation. The enter() function of HiddenState is to hide the browser while the paint() function of it is to show the browser and transits the browser state from hidden to abstract. When AbstractState is set, it's enter() function displays the abstract content. Upon some events like button click, browser's roll() function is called and delegated to AbstractState roll() function where DetailState is going to be entered.

The full implementation of this "browser" is available at github (line 323-559). Although it's pretty long (i already skipped implementing the inheritance :P), the "browser" now is simply mixing the State pattern and UI event handlers for ui transition, effects, and content displaying. If you trace further down the source, you will find my naive strict forward implementation of the "browser" where i believe it's pretty a mess to manage :P

Tuesday, August 24, 2010

hacker...

in these few days, i was packing my desktop in school as i'm leaving it very soon. From the desktop, i found something which is GREAT and got my focus.

flying back to 2009 autumn, there was a zeuux summit held in CityU. It was my pleasure to see Richard Stallman and Akira Urushibata there.

And, what i found in my desktop is Akira's excellent presentation "slide". Enjoy it :D



























Tuesday, August 03, 2010

python decorator for input validation

I was reading how decorator in python can be used to state machine... And, wonder, can this also apply to input validation for web framework like web.py.

I tried the following:
def getInput():
    ''' simulate web.input() for web.py framework '''
    return {
        'x': 'banananaa',
        'y': None,
        'z': 'zz',
    }

def validate_required(rules):
    ''' validation decorator '''
    def wrapper(method):
        ''' wrapping the actual handler '''
        def validate(*args, **kwargs):
            ''' validation take places according to rules '''
            inputs = getInput()
            for k in inputs.keys():
                if k in rules: f = rules[k]
                else: continue
                input = inputs[k]
                if not f(input):
                    out = 'Invalid input %s - %s' % (k, input)
                    print out # or raise Exception here to stop execution
            return method(*args, **kwargs)
        return validate
    return wrapper

class Handler:
    rules = {
        'x': lambda(x): len(x) > 0,
        'y': lambda(y): y is not None,
        'z': lambda(z): z is not None and len(z) > 3,
    }

    @validate_required(rules)
    def POST(self):
        print 'do something'

# simulate request handling
h = Handler()
h.POST()
 
© 2009 Emptiness Blogging. All Rights Reserved | Powered by Blogger
Design by psdvibe | Bloggerized By LawnyDesignz