Search

9/26/2011

hello world

hello world says:

blah blah

Andrzej on Software: Rails is not MVC

Andrzej on Software: Rails is not MVC

OK, so what's the difference?

In short, we're talking about MVC when a model can notify (through the Observer pattern) the views about the changes. It's not possible in a classical Rails app (it's possible when you use WebSockets, Pusher or a similar technology, but it's not so popular yet.). MVC was popular in desktop apps.

On the other hand, Model2 is exactly what we do with Rails. We don't notify the views from the model, the controller simply passes the model data to the views and handles the html generation which is then sent to the browser.


There's an interesting pattern evolving recently that a Rails app simply serves as a backend for a mobile app and all it does is exposing a JSON/REST API. It's similar to Model2, but instead of generating HTML it generates JSON. Still, it's not MVC.

You can read more about UI architectures in this article by Martin Fowler



Model 2 - Wikipedia, the free encyclopedia

9/25/2011

On The Importance Of Playing

On The Importance Of Playing

But when it came time to do some research. I couldn't get to work. I was a little tired; I was not interested; I couldn't do research! ...

And then I thought to myself, "You know, what they think of you is so fantastic, it's impossible to live up to it. You have no responsibility to live up to it!"...

Then I had another thought; Physics disgusts me a little bit now, but I used to enjoy doing physics. Why did I enjoy it? I used to play with it. I used to do whatever I felt like doing - it didn't have to do with whether it was important for the development of nuclear physics...

So I get this new attitude ... I'm going to play with physics, whenever I want to, without worrying about any importance whatsoever.
Within a week I was in the cafeteria and some guy, fooling around, throws a plate in the air. ...

I had nothing to do, so I start to figure out the motion of the rotating plate...
And before I knew it (it was a very short time) I was "playing" - working, really - with the same old problem that I loved so much, that I had stopped working on when I went to Los Alamos; my thesis-type problems; all those old-fashioned wonderful things.
It was effortless. It was easy to play with these things. It was like uncorking a bottle: Everything flowed out effortlessly. ...

There was no importance to what I was doing, but ultimately there was. The diagrams and the whole business that I got the Nobel Prize for came from that piddling around with the wobbling plate.

MVC Architecture for JavaScript Applications

MVC Architecture for JavaScript Applications

Real MVC

In a nutshell the classic MVC architecture work like this. There is a model that is at the heart of the whole thing. If the model changes, it notifies its observers that a change occurred. The view is the stuff you can see and the view observes the model. When the view is notified that the model has changed, the view changes its appearance. The user can interact with the view (e.g. clicking stuff) but the view doesn’t know what to do. So the view tells the controller what the user did and assumes the controller knows what to do. The controller appropriately changes the model. And around and around it goes.

This description is probably a nice summary for those who already understand the MVC architecture but it is way too short for someone who doesn’t know it already. Describing all the ins and outs of MVC is a task I’m not going to attempt in full. I will do three things:

Recommend the books I found that explain MVC well.
Describe some tips about MVC for JavaScript web applications in particular that I have found helpful.
Provide a complete example.

9/17/2011

Changing the transparency of terminal in Mac OS Leopard

Changing the transparency of terminal in Mac OS Leopard

Go to Terminal -> Preferences, Window tab, Background Color and change the opacity to whatever you like. The window will change as you change the percentage of opacity.

9/14/2011

卡牌屋

[閒聊]第一屆卡牌屋桌遊教學王評審心得

最後推薦一下卡牌屋台北店的新店面,在Kmall 25樓,很舒適
有兩個四人桌和兩個可容納6人左右的沙發區,還有眾多遊戲可供選購



如果你坐在沙發區這邊,還可以順便遠眺台北的風景
聽說夜景很美,只是我沒等到晚上就先離開了
還有人起鬨說現在就要先把跨年的場地包起來了(因為看得到101煙火)XD

7 wonders (2.2)
Santiago (2.5)
Puerto Rico (3.3)
Caylus (3.8)
Small World (2.3)
Nuns on the run (2.1)
Power grid (3.3)
Dream Factory (2.1)
RA (2.4)
Cargo Noir (2.0) 這遊戲我沒聽過,是今年出的新遊戲......
Betrayal at the house on the hill (2.2)
Endeavor (2.9)
Factory Manager (3.0)
Ticket to Ride Europe (2.0)
Race for the Galaxy (2.9)
Tigers & Euphrates (3.6)
星杯傳說 (?)

隱藏版美食 ~榆小舖@景美

隱藏版美食 ~榆小舖@景美

16台北市文山區羅斯福路六段269號
02-2932-6377

9/12/2011

Master the Linux bash command line with these 10 shortcuts | TechRepublic

Master the Linux bash command line with these 10 shortcuts | TechRepublic

4. Use key shortcuts to efficiently edit the command line
bash supports anumber of keyboard shortcuts for command-line navigation and editing. The Ctrl-A key shortcutmoves the cursor to the beginning of the command line, while the Ctrl-E shortcutmoves the cursor to the end of the command line. The Ctrl-W shortcutdeletes the word immediately before the cursor, while the Ctrl-K shortcutdeletes everything immediately after the cursor. You can undo a deletion with Ctrl-Y.

8. Perform calculations
bash can performsimple arithmetic operations at the command prompt. To use this feature, simplytype in the arithmetic expression you wish to evaluate at the prompt withindouble parentheses, as illustrated below. bash will attemptto perform the calculation and return the answer.

bash> echo $((16/2))
8

Ask HN: I am wasting so much of time, what can I do?

StayFocusd - Chrome plugin


1. There's also a StayFocusd[1] plugin for Chrome which will block sites for you.
2. Also try Crackbook [1] for Chrome which delays pages instead of banning them. Works much better for me that Stayfocusd, which I just disable after a while. (Disclaimer: I am the author.)
3. Soundtracks from RTS games (ex: starcraft) can create a sort of Pavlovian Response, telling your brain "You are sitting at a computer carrying out a difficult task which takes a good deal of focus and mental exertion. This activity is fun and rewarding, and it is urgent that you do it as well and as quickly as possible."
4. ust use the headphones without music to only get the wins from this. It's not like anyone except you can tell the difference
5. Get a second device, like a tablet, which you use for surfing, reading, and leisure. Your laptop is no longer for that. It's exclusively for producing and for serious work.
6. Get rid of your TV if you have it. Completely. That's really just a senseless time-sucker and you won't miss it within a week.
7. Babysteps, babysteps, babysteps. Taken from today's Hacker News: "I can not emphasize how important baby steps are. They are the key to avoiding fatal frustration. I have a law that helps define the size of subtasks: DO NOT EVER LEAVE THE COMPUTER IF YOUR PROGRAM DOES NOT RUN." http://all-things-andy-gavin.com/2011/09/11/video-game-progr...


- Fighting your urge to "procrastinate" all day long leads to lots of decision fatigue that will make everything just worse: http://www.nytimes.com/2011/08/21/magazine/do-you-suffer-fro... . The best way around this is to create habits, as they will get you on autopilot through difficult procrastination situations within a month. Some great thoughts on this from Leo Babauta: http://zenhabits.net/will/ My personal take on this: The key is starting out VERY slow (one habit a month at the most) and keeping your expectations really low. The habit itself needs to survive through all times and is more important than the actual outcome. Example from me: I do exercises right before showering, but the least I do is 5 pushups. That sounds like nothing, and actually it isn't but I do them no matter what - drunk, late, sad, happy. Habits will eventually carry you through everything, but you just stick to them. Suggestions for you: Not reading e-mail after or before a certain time, turning of the computer completely at a certain time. Stuff like that.
- Building on that, affirmations and meditation are extremely powerful as a habit too. I've written an article on this if you're interested: http://www.growinup.org/?p=5
- Gym and sports definitely helps your willpower, as long as you don't discover another way of procrastination in there. It can happen ;-)
- Knowing what you really want. Maybe you know already (I certainly did), but you're too scared and unfocused to really take action. If you're too scared, watch this: http://www.youtube.com/watch?v=Lk0hSeQ5s_k If you're too unfocused, read this: http://focusmanifesto.com/ Anyway, know what you wanna do and where you're going.
- All these things helped me in a way, but the final piece for me comes here as promised. I've had a huge fight with my wife for all kinds of reasons related to my procrastination, and she told me something I've never forgot. I've distilled the essence of what she told me on a paper and I read it every night. Here it is, for you all to read:
"Every time I pray, I feel you falling down this black hole, but I cannot help you. Only YOU can do it. No amount of reading or games or [insert your timesucker here] can fill that emptiness inside of you. So don't do stuff out of an impulse. Do it conciously. Whatever you do, choose to do it and accept the consequences. Don't be guilty about anything anymore - just accept that you made your choice and be responsible. There's no need to lie to yourself. It's just ok. Live, breathe, be gentle. There is one and one way only out of the frustration, anger and depression: Accept your choices. Love yourself. Leave the guild behind and FOLLOW YOUR HEART".


Pomodoro Technique
1. Choose a task to be accomplished
2. Set the Pomodoro to 25 minutes (the Pomodoro is the timer)
3. Work on the task until the Pomodoro rings, then put a check on your sheet of paper
4. Take a short break (5 minutes is OK)
5. Every 4 Pomodoros take a longer break
Pomodoro Technique book


Org - an Emacs Mode for Notes, Project Planning, and Authoring


via: Ask HN: I am wasting so much of time, what can I do?

「好文分享」蔣勳:過得像個人,才能看到美 - 點石成金 文創志業 自費出版的領航者 - udn部落格

「好文分享」蔣勳:過得像個人,才能看到美 - 點石成金 文創志業 自費出版的領航者 - udn部落格

幾年來,幾乎所有的竹科企業我都去過了,和企業的人有所接觸後,我才知道我過去有「知識偏執」的狀況,但我並沒有真正認識30歲上下的職場工作人員。

竹科有一家上市公司的員工平均年齡是31.8歲,他們都是最優秀大學畢業的菁英。

在開始工作的前10年,是人生很重要的階段,但他們卻通常是11點以後才下班。要戀愛,可能沒有時間戀愛;要買房子,就用世俗的固定模式買房子,找一個大家認為有名的設計師;要結婚,但用很草率的方式結婚。我知道很多工程師經由輔導去娶烏克蘭新娘,他們可能連戀愛的時間、耐心都沒有。

真正的美,作假不得

我原來希望的藝術是能恢復人的品味和人的感覺,但他們接觸了這些東西卻沒有感覺,像有些企業會固定舉辦一些音樂會,但他們卻沒有辦法進入那個世界。所以我現在希望向大家說的是「人的原點」,當我們失去了人的原點,談所有的美都是假的。

我有一個朋友,住在信義路上億元的豪宅,找了日本最有名的設計師來裝潢,但有一次我去他家,發現他住了2年,可是廚房裡所有進口廚具的膠膜都沒撕掉。

他的房子只是一個showroom。可是家不是showroom,家是讓你可以放鬆自在、活得像人的地方,家是因為住在裡面的人有自己的渴望、自己的感覺,才會有自己的風格。

如果主人對這個家沒有意見、對自己的生活沒有看法,只想告訴別人買的是義大利最貴的床,那只是作假給別人看。

你可以在家裡放很多明式家具,很美;你喜歡家裡很空,也很美,但這裡面的難度是你到底要什麼,如果你不知道,你找再有名的建築師設計都是假的,你怎麼樣回來做自己,才是最難的功課。

我自己是住在淡水河邊,當時會在那裡買房子,是因為覺得淡水河口好漂亮,但是我房子的建商卻不知道善用那裡的美景,窗戶建得很小,我在房間裡就覺得好難過。

所以我找了一個學建築的學生,他幫我開了12個窗,而且全部是往外推的推窗,比拉窗更有靠近河邊的感覺,還架出一個小陽台,所以我可以坐在小欄杆上看河,和淡水河只有2公尺的距離。

我也不喜歡隔間,所以設計師幫我用高度界定出3個不同的區域。我家最高的地方是客廳,朋友來的時候坐在最高的地方喝茶;次高的地方是書房,我在那邊看書;再次高的地方是我的餐廳。我覺得這是我的房子、我的家,我是主人,我知道我要什麼。

在穿著上,我喜歡純棉、純麻,因為我覺得它們很溫暖,材料本身有觸覺上的記憶,在排汗、吸汗的過程也非常舒服。加上我喜歡爬山、喜歡躺在草地上、喜歡在海灘捲起褲腳踩水,我喜歡這樣的生活,所以我就有我服裝的特徵,名牌就不適合我,因為我喜歡自在。

找回人與人之間的感覺

我現在不問工程師有沒有去聽音樂、看展覽,反而是問他們:「你們在這裡工作5年了,有沒有人可以告訴我公司門口那一排是什麼樹?」但很少人能夠回答的出來。

事實上,他們公司門口那排小葉欖仁的葉子漂亮得不得了,綠色會在陽光裡發亮。後來我再去,就有一個員工和我說,「謝謝你告訴我這件事,我現在下班時會先看看小葉欖仁再回家,所以比較不會和太太吵架了。」

他也問我現在5歲的女兒將來該學鋼琴、還是小提琴,但我建議11點下班的他多抱抱女兒,比較重要。因為所有的藝術講的都是人的故事,一個孩子如果不記得父親的體溫,她將來看畫、聽音樂都沒有感動。如果沒有人的記憶,所有藝術對她而言都只是賣弄而已。

我們從年輕開始,就因為工作忙碌,忽略了人與人的感覺,但工作忙碌之餘,你還是一個人,你必須每分每秒提醒自己回來做人的部份。你看到了美,才會覺得這個世界是值得活下去的。如果你看到的只是品牌、只是假的美,你不見得快樂,那反而可能會是你憂鬱症的原因。

找回美的感覺其實很簡單,去觸摸一片葉子,去聞一下在很熱很熱的夏天、下完午後暴雨的氣味,那是都我們有記憶的感覺,那都會引發我們的感觸和感動。

現在美常常成為新的知識、新的壓力,博士可能毫無美感,但一個不識字的美濃農夫卻可以很美,他看得到月光的美、看得到稻浪翻飛的美。美是最大的財富,它不會因為你的學歷而不同,而是因為你人的部份完不完整而不同。

週休二日,回來做自己

現在台灣過週休二日,好像非要全家去吃一個餐廳、到哪裡去看薰衣草、喝咖啡,全部整套,然後全部的人塞車塞到一肚子氣。我們對休閒的定義是滿僵化的,好像一定要別人服務我們才算是休閒。

我自己假日的時候喜歡自己一個人做4菜1湯,因為我覺得做菜好快樂。我也很喜歡在週休二日洗我自己最喜歡的純棉的、純麻的襯衫,絕不丟給洗衣機,因為我覺得觸感好極了。看到它們晾在陽光裡、在風裡飄,白的好漂亮,我的週休二日就很快樂,因為我回來做自己。


在7、8月,民生東路六段有全台北最漂亮的大花紫薇,即使有車可開,那時候我也絕對要走路,這些是讓我最快樂的事,這才是人。如果我們吃得不像人,穿得不像人,生活都失去了人的意義,那談藝術太遙遠。

我談我的生活,並不希望別人學我。每個人是不一樣的,不要隨便相信價格、人云亦云,生活中的美學,應該是不按照別人安排的。每個人應該用自己的生命,去創造自己的生活美學出來。

蔣勳,60歲。學歷:文化大學史學系、文化大學藝術研究所、法國巴黎大學藝術研究所。經歷:曾任《雄獅美術》月刊主編,並先後執教於文化大學、輔仁大學與東海大學美術系,著有小說、散文、藝術史、美學論述作品數十種。現任:新竹IC之音電台《美的沈思》節目主持人



出處: 「好文分享」蔣勳:過得像個人,才能看到美 - 點石成金 文創志業 自費出版的領航者 - udn部落格 http://blog.udn.com/eastolga/5493256#ixzz1XjyMB4x1

9/05/2011

tl;dr

tl;dr

Said whenever a nerd makes a post that is too long to bother reading.
"omg you postwench. i can only say one thing in response - tl;dr"
"tl;dr...why dont you give up on your unabridged edition of War and Peace or at least stop posting it here?"


Too Long; Didn't Read

Literally translates to: That was too long to read.
Really translates to: I'm too lazy to read the entirety of what you said, but I still want to say something.

Now, instead of just dropping capitals the modern internet communicator

curl网站开发指南 - 阮一峰的网络日志

curl网站开发指南 - 阮一峰的网络日志


我一向以为,curl只是一个编程用的函数库。
最近才发现,这个命令本身,就是一个无比有用的网站开发工具,请看我整理的它的用法。
===================================
curl网站开发指南
阮一峰 整理

curl是一种命令行工具,作用是发出网络请求,然后得到和提取数据,显示在"标准输出"(stdout)上面。
它支持多种协议,下面举例讲解如何将它用于网站开发。
一、查看网页源码
直接在curl命令后加上网址,就可以看到网页源码。我们以网址www.sina.com为例(选择该网址,主要因为它的网页代码较短):
  curl www.sina.com
  
  
  301 Moved Permanently
  
  

Moved Permanently


  

The document has moved here.


  
如果要把这个网页保存下来,可以使用-o参数,这就相当于使用wget命令了。
  curl -o [文件名] www.sina.com
二、自动跳转
有的网址是自动跳转的。使用-L参数,curl就会跳转到新的网址。
  curl -L www.sina.com
键入上面的命令,结果就自动跳转为www.sina.com.cn。
三、显示头信息
-i参数可以显示http response的头信息,连同网页代码一起。
  curl -i www.sina.com
  HTTP/1.0 301 Moved Permanently
  Date: Sat, 03 Sep 2011 23:44:10 GMT
  Server: Apache/2.0.54 (Unix)
  Location: http://www.sina.com.cn/
  Cache-Control: max-age=3600
  Expires: Sun, 04 Sep 2011 00:44:10 GMT
  Vary: Accept-Encoding
  Content-Length: 231
  Content-Type: text/html; charset=iso-8859-1
  Age: 3239
  X-Cache: HIT from sh201-9.sina.com.cn
  Connection: close
  
  
  301 Moved Permanently
  
  

Moved Permanently


  

The document has moved here.


  
-I参数则是只显示http response的头信息。
四、显示通信过程
-v参数可以显示一次http通信的整个过程,包括端口连接和http request头信息。
  curl -v www.sina.com
  * About to connect() to www.sina.com port 80 (#0)
  * Trying 61.172.201.195... connected
  * Connected to www.sina.com (61.172.201.195) port 80 (#0)
  > GET / HTTP/1.1
  > User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
  > Host: www.sina.com
  > Accept: */*
  >
  * HTTP 1.0, assume close after body
  < HTTP/1.0 301 Moved Permanently
  < Date: Sun, 04 Sep 2011 00:42:39 GMT
  < Server: Apache/2.0.54 (Unix)
  < Location: http://www.sina.com.cn/
  < Cache-Control: max-age=3600
  < Expires: Sun, 04 Sep 2011 01:42:39 GMT
  < Vary: Accept-Encoding
  < Content-Length: 231
  < Content-Type: text/html; charset=iso-8859-1
  < X-Cache: MISS from sh201-19.sina.com.cn
  < Connection: close
  <
  
  
  301 Moved Permanently
  
  

Moved Permanently


  

The document has moved here.


  
  * Closing connection #0
如果你觉得上面的信息还不够,那么下面的命令可以查看更详细的通信过程。
  curl --trace output.txt www.sina.com
或者
  curl --trace-ascii output.txt www.sina.com
运行后,请打开output.txt文件查看。
五、发送表单信息
发送表单信息有GET和POST两种方法。GET方法相对简单,只要把数据附在网址后面就行。
  curl example.com/form.cgi?data=xxx
POST方法必须把数据和网址分开,curl就要用到--data参数。
  curl --data "data=xxx" example.com/form.cgi
如果你的数据没有经过表单编码,还可以让curl为你编码,参数是--data-urlencode。
  curl --data-urlencode "date=April 1" example.com/form.cgi
六、文件上传
假定文件上传的表单是下面这样:
  

    
    
  

你可以用curl这样上传文件:
  curl --form upload=@localfilename --form press=OK [URL]
七、Referer字段
有时你需要在http request头信息中,提供一个referer字段,表示你是从哪里跳转过来的。
  curl --referer http://www.example.com http://www.example.com
八、User Agent字段
这个字段是用来表示客户端的设备信息。服务器有时会根据这个字段,针对不同设备,返回不同格式的网页,比如手机版和桌面版。
iPhone4的User Agent是
  Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
curl可以这样模拟:
  curl --user-agent "[User Agent]" [URL]
九、cookie
使用--cookie参数,可以让curl发送cookie。
  curl --cookie "name=xxx" www.example.com
至于具体的cookie的值,可以从http response头信息的Set-Cookie字段中得到。
十、增加头信息
有时需要在http request之中,自行增加一个头信息。--header参数就可以起到这个作用。
  curl --header "xxx: xxxxxx" http://example.com
十一、HTTP认证
有些网域需要HTTP认证,这时curl需要用到--user参数。
  curl --user name:password example.com
【参考资料】
  * Using cURL to automate HTTP jobs
  * 教你学用CURL