Search

8/29/2011

送給新鮮人的 7 項建議 – MMDays

送給新鮮人的 7 項建議 – MMDays


擁有正確的理財觀念
我一直很喜歡 Tim O’Reilly 的一句話: “Money is like gasoline during a road trip. You have to pay attention to money, but it shouldn’t be about the money. (金錢就像旅程中開車時的汽油一般,你需要注意金錢的狀況,但是整個旅程的意義本身跟金錢無關)”。擁有好的金錢價值觀可以讓你生活更舒適一點,這裡說的舒適不是說,你要住豪宅,開名車,而是指心靈跟生活上的輕鬆。也就是說你生活不需要特別憂慮明天有欠誰錢? 下一餐的著落在哪邊? 因此可以有時可以恣意地輕鬆地喝個下午茶,做做自己感興趣的東西。所以,你得學會控制住自己的慾望,並且瞭解到自己真正的渴望是什麼。如果不瞭解自己,那麼你可以先從記帳開始,透過每天的開銷來認識你自己。理財並不複雜,你只要記得最基本的原則: 永遠讓你的淨收入大於你的淨支出。其他的都是次要的。

當個怪人
在一個群體當中,最困難的事情就是維持獨立思考。因為你永遠不想當個團體中的異類,當大家要去唱 KTV 時,你也遷就著;當大家要去夜衝時,你也遷就著。於是你的時間就這麼蹉跎了,重點是,這個蹉跎的時間還不是為了你自己想要達成的夢想。當然,你會這麼做,正是因為你還沒搞清楚你想要做什麼。所以,常常會有這個狀況: 人家說你數學不好,你就拼命補數學;人家說你體育差,你是不是也跟人家一起去練習跑步? 不過,你可以選擇每天悠閒地慢跑,但是你知道你的目標不是為了田徑競賽,而是你喜歡那種有節奏的步伐,乘著微風的感覺;你知道你要學習數學,是因為你至少每天得用到基本的加減乘除,來解決生活上面所遇到的基本計算,這跟你的考試一點關係也沒有。瞭解到自己是多麼地與眾不同,總比盲目地跟隨著群體運動來得好多。

人生是一段單向道的旅程
你要理解這個樣子的事實,人生無論如何怎麼樣都不可能重來。你可能會犯錯,你可能會跌倒,不過那又怎麼樣? 重點是,你從你之前的人生中到底悟到了什麼! 多一步或是少一步,你都不可能是現在的你。所以,好好地接受你的過去,就代表你能好好地接受現在的你;這也代表著,你將能夠從你之前的經驗挖掘出寶貴的東西。如果你無法接受,甚至正視你自己,那麼寶箱在你前面,沒有開啟也是徒然。世界,是在你的腦裡面,不是在你的腦外面;瞭解到這一點,你的世界就很容易改變了。除此之外,為了讓你的人生不要可惜了、遺憾了,該做什麼的時候,就做什麼。緣分是很難得的,可以跟父母開開心心地聊上一個下午或晚上的時光會在單向道上消失的;可以跟好友一起瘋狂、一起努力的時光會在單向道上消失的;可以跟戀人一起擁抱、一起牽手的時光會在單向道上消失的。重點不是你失去了什麼、得到了什麼,重點是你怎麼樣經歷了這些什麼。人生難得,人生中最重要的事情就是人生,其它的,都是次要的。最後,如果可以的話,儘量讓你的單行道長一點,因為精彩的總是在後邊。

8/25/2011

scroll and fixed

網頁上常見的特效: 捲動到某個地方後, 頁面的 element 就會dock 在頁面的上方, 可以用在比較長的表單, 作法就是去算doucment.scrollTop 到了預設的地方之後把 element 設成 {poistion:fixed, top:0}
ex: less.org

知得過、不及處,就是中和。


王陽明-->傳習錄-->門人黃省曾錄

 【304】問:“良知原是中和的,如何卻有過、不及?”先生曰:“知得過、不及處,就是中和。”

8/22/2011

三個演講

1. 史帝夫.賈伯斯2005年史丹佛大学畢業演講 http://t.cn/anHwH8

2. J.K.羅琳2008年哈佛大學畢業演講 http://t.cn/aE4zuW

3. 蘭迪.鮑許教授的最後一次演講 http://t.cn/anHwke

How GitHub Works

How GitHub Works

Hours are bullshit
Hours are great ways to determine productivity in many industries, but not ours. Working in a startup is a much different experience than working in a factory. You can’t throw more time at a problem and expect it to get solved. Code is a creative endeavor. You need to be in the right mindset to create high-quality code.

Think back to the last time you were depressed or angry. How productive were you? Now think back to the last time you were truly productive. Code flying from your fingertips. Not just the sheer quantity- the sheer quality of that code. When you’re in the right mindset, your best day of coding can trump weeks of frustrated keyboard-tapping.

We want employees to be in the zone as often as possible. Mandating specific times they need to be in the office hurts the chances of that. Forcing me in the office at 9am will never, ever get me in the zone, but half of GitHub may very well work best in the morning.

By allowing for a more flexible work schedule, you create an atmosphere where employees can be excited about their work. Ultimately it should lead to more hours of work, with those hours being even more productive. Working weekends blur into working nights into working weekdays, since none of the work feels like work.

Be Asynchronous
GitHub didn’t have an office for the first two years. Chat rooms (in our case, Campfire) is where things got done. Today we’ve moved into our second office, and Campfire is still where we get things done.

NodeJS – The what, why, how and when | Xebia Blog

NodeJS – The what, why, how and when | Xebia Blog

What is NodeJS?

The NodeJS five-word sales pitch from their own website is “Evented I/O for V8 Javascript”. We’ll get to what that means exactly in the How. NodeJS, in a few more words, is a server-side application framework with a focus on high concurrent performance. Applications written for Node run in a single-threaded, event-based process.

Event-based programming approaches this in a different matter. When calling the blocking operation, you pass it an additional argument: a block of code to execute when the operation has completed. Instead of waiting for a reply from the user or the database, the application continues its execution.


Why
Why evented I/O? The short answer: Latency.

What does this mean? Effectively, it means that classic, blocking processes twiddle their thumbs for 41,000,000 CPU cycles while waiting for something from disk to load. Those processes can’t do anything else while they twiddle their thumbs, so in the case of a webserver, other requests get paused until the application has received its data.

The classic solution for this problem: Add moar processes. When one process twiddles its thumbs waiting for data, the other process can take over and handle the next request. With 200 processes available for handling requests, consumers never have to wait long in the queue for their request to be handled by the next freed process.

But it has its limits. Hard limits, even, which have been the source of many outages in the past. What if there’s a big delay on the network for whatever reason? What if there’s more new requests coming in per second than the database can process? The 200 processes each block once they reach the point where they retrieve data from the network, and once they’re all occupied, the webserver simply stops serving requests, users time out, and Twitter trends with messages like “IS #SOMESITE.COM DOWN? #FML”.

How does Node solve this? Well, to put it simply, it doesnt’t twiddle its thumbs. It goes ‘Alright underlying system, give me this information from the network. I’ll go do something useful, lemme know when you’re done aight? Aight.’ And then it proceeds to do something useful, like handle the next request.

It’s the ‘lemme know when you’re done’ that contains the core of NodeJS’s performance. Instead of waiting for something to be retrieved (blocking), it continues to run (non-blocking). No precious CPU cycles get wasted that way waiting.

Because it doesn’t block, there’s also a greatly reduced need for running multiple processes. It just keeps going, regardless of how many requests it has to handle. When it receives a bazillion requests, it doesn’t run out of processes or some other arbitrary limit, it just handles each one, one by one. It handles each event as it’s triggered, one at a time, and it does so very rapidly.

It’s like ordering food. You step up to the counter of your local fast food store, and order a hamburger. Classically, you stand there and wait until the chef is done and the person serving gives you your order, while others queue up neatly behind you. In the multi-threaded approach, the store hires more serving personnel and chefs that can each handle one customer at a time.

In the non-blocking approach, the servant smiles, says “Alright sir, please pick a seat, your order will be brought to you when it’s done. Next!”. And so it continues. The servant passes the order to the kitchen, the kitchen prepares your burger, and a pretty serving girl brings you your hamburger when it’s done. The queue passes the counter quickly, because everything the servant does is take the people’s order and pass it along.

If only fast food stores actually worked like this.

Why Javascript?

First, event handling, callbacks and asynchronous behavior are at its core. It’s been used in this fashion for years in its natural habitat, the browser. Opening a file or network resource and passing that method a callback isn’t that different from triggering an AJAX-call with a callback – in fact, it’s exactly the same. The browser is inherently asynchronous, as pretty much every piece of logic relies on user input, network I/O, or something simpler as a timed event – each of those would block the execution of the script if it was done with blocking operations, and that’s the last thing you want in a user-experience heavy application like a webbrowser.

Event handling is at the core of both Javascript as a language and as a way of thinking for Javascript developers, which is another important reasoning behind using Javascript: It’s familiar to many developers. Javascript is a bit of a ninja amongst programming languages – most people don realize it’s one of the most-used programming languages out there. Its popularity has boosted significantly over the last decade, with the rise of AJAX, highly interactive and responsive web applications, streaming updates, and big companies like Google pushing web applications as a primary platform for all kinds of applications.

Why single-threaded?
The advantages of a single-threaded application is that the processor doesn’t have the overhead of context switching (when one thread gets CPU time while the other’s paused). There’s no heap allocations or forks or startup sequences that need to be done when creating a new thread. Besides that, there’s of course the obvious advantage of not needing to program with concurrency in the back of your head. Less headache, less hard-to-track bugs, less specific knowledge and understanding needed, etc.

But what about modern-day hardware? The mainstream CPU builders don’t build single-core processors anymore, it’s all fancy dual-, quad-, hexa- and octacores these days, with even more cores and special-purpose components to be added in the nearby future.

Well, that’s not a problem. Whilst a Node program is single-threaded, there’s nothing stopping you from creating multiple Node processes and running them side-by-side, each using a single core. Put a loadbalancer or reverse proxy like nginx in front of it , either on the same server or externally, and you’re done. You could even use another Node process as a loadbalancer. Of course, you’d have to be using a back-end storage system that can handle concurrent requests (i.e. from multiple Node processes) in order to be able to do that.

But V8 can also run outside of the browser, and, being an open source project, has been extended to create NodeJS. Node adds a thread pool (using libeio), event loop (libevent), and fancy things like DNS resolving and cryptography.

On top of that are a bunch of Node bindings for I/O (sockets, HTTP, etc).

Finally, a standard library to do pretty much everything you need written in pure Javascript is built on top of that. Have a picture:


when
With that out of the way, here’s a few use cases Node can be used for and can excel at:

Generic web framework. It’s got all the things you need – server-side logic, connectors for back-end systems (like databases), file serving, template parsing (with a wide variety of template languages), authentication, you name it.
Highly concurrent websites – high-volume webservices, varying loads, etc.
Highly concurrent connections – for example, websockets with many clients sending and receiving data.
Back-end systems dealing with files. Example: GitHub’s Nodeload, which prepares Git repositories for download by compressing them into tarballs. It calls git archive, waits, then streams the result back to the user using Node’s stream API’s. (output I/O is also I/O and can benefit from evented I/O). See https://github.com/blog/900-nodeload2-downloads-reloaded

8/17/2011

tar

tar -zpcv -f /root/etc.tar.gz /etc

or

tar zcv etc > foo.tar.gz

8/15/2011

Targeting Screens from Web Apps | Android Developers

Targeting Screens from Web Apps | Android Developers
That's an example of just two viewport properties. The following syntax shows all of the supported viewport properties and the general types of values accepted by each one:


<meta name="viewport"
content="
height = [pixel_value | device-height] ,
width = [pixel_value | device-width ] ,
initial-scale = float_value ,
minimum-scale = float_value ,
maximum-scale = float_value ,
user-scalable = [yes | no] ,
target-densitydpi = [dpi_value | device-dpi |
high-dpi | medium-dpi | low-dpi]
" />

頭家爐主 Local chiefs and incense heads

頭家爐主 Local chiefs and incense heads

民間信仰中一種祭祀組織的形式。爐主代表地方社區居民負責一年當中的祭祀事宜,頭家則協助爐主分擔祭祀工作。通常是在神前擲茭(卜杯)的方式決定,聖杯最多者為下一年爐主。頭家人數不等,視社區人數多寡或地方慣例而定。頭家爐主通常是男性的戶長擔任,不過也有女性擔任爐主的情況。
爐主是因神明旨意而卜選出來,早期擔任爐主是莫大的榮譽,人們會認為是得到神明庇佑,才會被卜選成為爐主,因此通常都會用心服務。
爐主要負責收取祭祀費用,稱為「收丁口錢」,頭家則分攤收費的工作。爐主在神誕日要請戲團來表演,稱為「請戲」。在交通不便的年代,頭家還要「擔戲籠」,幫忙挑戲班的樂器與戲服等。近年來,由於收丁口錢的習俗逐漸淡薄,頭家爐主的需要性就沒有那麼高了。
現代廟宇有管理委員會或財團法人等組織負責廟務的經營與管理,但早期許多廟宇是以爐主制的方式進行管理;利用「爐主簿」記載歷年爐主與頭家的姓名、每年的收支明細、廟產記錄等。有些地方是有神無廟的情況,通常以每年由爐主輪流祭祀的方式維持神明的信奉,因此爐主可以把神明請到家中奉祀一整年,例如臺中縣新社鄉由九庄聯合祭祀媽祖,九庄媽堅持不立廟,是希望每年可以澤被爐主,親臨爐主家中受奉祀。
有神明便有香爐,有香爐便有爐主,所以神明的信眾便稱為「爐腳弟子」。廟宇祀神有爐主,神明會也有爐主。每年神誕新舊爐主頭家交接時,會舉行「新交舊」,新、舊任爐主頭家一起共宴。

8/12/2011

Daring Fireball Linked List: Android's 'Density-Independent Pixel'

Daring Fireball Linked List: Android's 'Density-Independent Pixel'

Android devices have wildly-varying pixel-per-inch resolutions. To aid developers, the OS offers a “density-independent pixel” unit of measurement:

A virtual pixel unit that applications can use in defining their UI, to express layout dimensions or position in a density-independent way.

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dip units needed, based on the actual density of the screen in use. The conversion of dip units to screen pixels is simple: pixels = dips * (density / 160). For example, on 240 dpi screen, 1 dip would equal 1.5 physical pixels. Using dip units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

I suspect Apple will do something similar, except that by going straight from 480 × 320 to 960 × 640, everything just doubles in terms of pixels and nothing works out to a non-integer scaling factor.

Philosophical Games: Customize Android Browser Scaling with target-densityDpi

Philosophical Games: Customize Android Browser Scaling with target-densityDpi

Add dpi support for WebView.

In the "viewport" meta tag, you can specify "target-densityDpi".
If it is not specified, it uses the default, 160dpi as of today.
Then the 1.0 scale factor specified in the viewport tag means 100%
on G1 and 150% on Sholes. If you set "target-densityDpi" to
"device-dpi", then the 1.0 scale factor means 100% on both G1 and Sholes.

Implemented Safari's window.devicePixelRatio and css media query
device-pixel-ratio.

So if you use "device-dpi" and modify the css for font-size and image
src depending on window.devicePixelRatio, you can get a better page on
Sholes/Passion.

Here is a list of options for "target-densityDpi".

device-dpi: Use the device's native dpi as target dpi.
low-dpi: 120dpi
medium-dpi: 160dpi, which is also the default as of today
high-dpi: 240dpi
: We take any number between 70 and 400 as a valid target dpi.

Fix http://b/issue?id=2071943



A pixel is not a pixel is not a pixel - QuirksBlog

node-optimist /

node-optimist

optimist is a node.js library for option parsing for people who hate option parsing. More specifically, this module is for people who like all the --bells and -whistlz of program usage but think optstrings are a waste of time.

With optimist, option parsing doesn't have to suck (as much).


var argv = require('optimist').argv;

if (argv.rif - 5 * argv.xup > 7.138) {
console.log('Buy more riffiwobbles');
}
else {
console.log('Sell the xupptumblers');
}


$ ./xup.js --rif=55 --xup=9.52
Buy more riffiwobbles

$ ./xup.js --rif 12 --xup 8.1
Sell the xupptumblers


And non-hypenated options too! Just use argv._!

var argv = require('optimist').argv;
console.log('(%d,%d)', argv.x, argv.y);
console.log(argv._);


$ ./nonopt.js -x 6.82 -y 3.35 moo
(6.82,3.35)
[ 'moo' ]

$ ./nonopt.js foo -x 0.54 bar -y 1.12 baz
(0.54,1.12)
[ 'foo', 'bar', 'baz' ]


example: https://github.com/substack/node-browserify/blob/master/bin/cli.js


var argv = require('optimist').usage('Usage: $0 [entry files] {OPTIONS}').wrap(80).option('outfile', {
alias: 'o',
desc: 'Write the browserify bundle to this file.\n' + 'If unspecified, browserify prints to stdout.',
}).option('require', {
alias: 'r',
desc: 'A module name or file to bundle.require()\n' + 'Optionally use a colon separator to set the target.',
}).option('entry', {
alias: 'e',
desc: 'An entry point of your app'
}).option('alias', {
alias: 'a',
desc: 'Register an alias with a colon separator: "to:from"\n' + "Example: --alias 'jquery:jquery-browserify'",
}).option('plugin', {
alias: 'p',
desc: 'Use a plugin. Use a colon separator to specify additional ' + 'plugin arguments as a JSON string.\n' + 'Example: --plugin \'fileify:["files","."]\''
}).option('help', {
alias: 'h',
desc: 'Show this message'
}).check(function (argv) {
if (argv.help) throw ''
if (process.argv.length <= 2) throw 'Specify a parameter.'
}).argv;

8/05/2011

http://vimgolf.com/

http://vimgolf.com/

Real Vim ninjas count every keystroke - do you?
Pick a challenge, fire up Vim, and show us what you got.

http://vimgolf.com/

http://vimgolf.com/

Real Vim ninjas count every keystroke - do you?
Pick a challenge, fire up Vim, and show us what you got.

簡繁轉換 - Linux Wiki

簡繁轉換 - Linux Wiki
cconv - php extension


使用cconv轉換
http://code.google.com/p/cconv/
ubuntu用戶可以用命令“sudo apt-get install cconv”安裝。
cconv是建立在iconv之上,增加了詞語轉換能力,效果分析見後面。
使用cconv進行簡繁轉換的方法為:
cconv -f UTF8-CN -t UTF8-HK jian.txt -o fan.txt


不難發現,對於多解的字,OpenOffice.Org未轉換,iconv按單一規則轉換,而cconv與google翻譯則能正確轉換。
但是google翻譯未能保持原格式,而OpenOffice.Org、iconv和cconv則很好地保留了原格式。
另外,iconv不能處理混合編碼的文件。
使用cconv轉換20M含部分亂碼的文本文件耗時僅數秒,且效果非常理想,不會像iconv一樣遇到“ә”等非常規字符或亂碼字符時報錯停止轉換。(推薦使用)

8/04/2011

curl

linux curl
curl
-A 'my user agent string' // customize user agent string
-e 'http://example.com' // customize refereral

Curl是Linux下一個很強大的http命令行工具,其功能十分強大。
1) 二話不說,先從這裏開始吧!
$ curl http://www.linuxidc.com
回車之後,www.linuxidc.com 的html就稀里嘩啦地顯示在屏幕上了 ~
2) 嗯,要想把讀過來頁面存下來,是不是要這樣呢?
$ curl http://www.linuxidc.com > page.html
當然可以,但不用這麼麻煩的!
用curl的內置option就好,存下http的結果,用這個option: -o
$ curl -o page.html http://www.linuxidc.com
這樣,你就可以看到屏幕上出現一個下載頁面進度指示。等進展到100%,自然就 OK咯
3) 什麼什麼?!訪問不到?肯定是你的proxy沒有設定了。
使用curl的時候,用這個option可以指定http訪問所使用的proxy伺服器及其埠: -x
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com
4) 訪問有些網站的時候比較討厭,他使用cookie來記錄session信息。
像IE/NN這樣的瀏覽器,當然可以輕易處理cookie信息,但我們的curl呢?.....
我們來學習這個option: -D <— 這個是把http的response裏面的cookie信息存到一個特別的文件中去
$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com
這樣,當頁面被存到page.html的同時,cookie信息也被存到了cookie0001.txt裏面了
5)那麼,下一次訪問的時候,如何繼續使用上次留下的cookie信息呢?要知道,很多網站都是靠監視你的cookie信息,來判斷你是不是不按規矩訪問他們的網站的。
這次我們使用這個option來把上次的cookie信息追加到http request裏面去: -b
$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com
這樣,我們就可以幾乎模擬所有的IE操作,去訪問網頁了!
6)稍微等等 ~我好像忘記什麼了 ~
對了!是瀏覽器信息
有些討厭的網站總要我們使用某些特定的瀏覽器去訪問他們,有時候更過分的是,還要使用某些特定的版本 NND,哪裡有時間為了它去找這些怪異的瀏覽器呢!?
好在curl給我們提供了一個有用的option,可以讓我們隨意指定自己這次訪問所宣稱的自己的瀏覽器信息: -A
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com
這樣,伺服器端接到訪問的要求,會認為你是一個運行在Windows 2000上的 IE6.0,嘿嘿嘿,其實也許你用的是蘋果機呢!
而"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"則可以告訴對方你是一台 PC上跑著的Linux,用的是Netscape 4.73,呵呵呵
7)另外一個伺服器端常用的限制方法,就是檢查http訪問的referer。比如你先訪問首頁,再訪問裏面所指定的下載頁,這第二次訪問的 referer地址就是第一次訪問成功后的頁面地址。這樣,伺服器端只要發現對下載頁面某次訪問的referer地址不是首頁的地址,就可以斷定那是個盜連了 ~
討厭討厭 ~我就是要盜連 ~!!
幸好curl給我們提供了設定referer的option: -e
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com
這樣,就可以騙對方的伺服器,你是從mail.linuxidc.com點擊某個鏈接過來的了,呵呵呵
8)寫著寫著發現漏掉什麼重要的東西了!——- 利用curl 下載文件
剛才講過了,下載頁面到一個文件里,可以使用 -o ,下載文件也是一樣。比如,
$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
這裏教大家一個新的option: -O 大寫的O,這麼用:
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
這樣,就可以按照伺服器上的文件名,自動存在本地了!
再來一個更好用的。
如果screen1.JPG以外還有screen2.JPG、screen3.JPG、....、screen10.JPG需要下載,難不成還要讓我們寫一個script來完成這些操作?
不幹!
在curl裏面,這麼寫就可以了:
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
呵呵呵,厲害吧?! ~
9)再來,我們繼續講解下載!
$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
這樣產生的下載,就是
~zzh/001.JPG
~zzh/002.JPG
...
~zzh/201.JPG
~nick/001.JPG
~nick/002.JPG
...
~nick/201.JPG
夠方便的了吧?哈哈哈
咦?高興得太早了。
由於zzh/nick下的文件名都是001,002...,201,下載下來的文件重名,後面的把前面的文件都給覆蓋掉了 ~
沒關係,我們還有更狠的!
$ curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
—這是.....自定義文件名的下載? —對頭,呵呵!
這樣,自定義出來下載下來的文件名,就變成了這樣:原來: ~zzh/001.JPG —-> 下載后: 001-zzh.JPG 原來: ~nick/001.JPG —-> 下載后: 001-nick.JPG
這樣一來,就不怕文件重名啦,呵呵

9)繼續講下載
我們平時在windows平台上,flashget這樣的工具可以幫我們分塊并行下載,還可以斷線續傳。curl在這些方面也不輸給誰,嘿嘿
比如我們下載screen1.JPG中,突然掉線了,我們就可以這樣開始續傳
$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG
當然,你不要拿個flashget下載了一半的文件來糊弄我 別的下載軟體的半截文件可不一定能用哦 ~
分塊下載,我們使用這個option就可以了: -r
舉例說明
比如我們有一個http://cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 要下載(趙老師的電話朗誦 :D )我們就可以用這樣的命令:
$ curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3
這樣就可以分塊下載啦。不過你需要自己把這些破碎的文件合併起來如果你用UNIX或蘋果,用 cat zhao.part* > zhao.MP3就可以如果用的是Windows,用copy /b 來解決吧,呵呵
上面講的都是http協議的下載,其實ftp也一樣可以用。用法嘛,
$ curl -u name:passwd ftp://ip:port/path/file
或者大家熟悉的
$ curl ftp://name:passwd@ip:port/path/file
10) 說完了下載,接下來自然該講上傳咯上傳的option是 -T
比如我們向ftp傳一個文件:
$ curl -T localfile -u name:passwd ftp://upload_site:port/path/
當然,向http伺服器上傳文件也可以比如
$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
注意,這時候,使用的協議是HTTP的PUT method
剛才說到PUT,嘿嘿,自然讓老服想起來了其他幾種methos還沒講呢! GET和POST都不能忘哦。
http提交一個表單,比較常用的是POST模式和GET模式
GET模式什麼option都不用,只需要把變數寫在url裏面就可以了比如:
$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345
而POST模式的option則是 -d
比如,
$ curl -d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi
就相當於向這個站點發出一次登陸申請 ~
到底該用GET模式還是POST模式,要看對面伺服器的程序設定。
一點需要注意的是,POST模式下的文件上的文件上傳,比如




這樣一個HTTP表單,我們要用curl進行模擬,就該是這樣的語法:
$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
羅羅嗦嗦講了這麼多,其實curl還有很多很多技巧和用法比如 https的時候使用本地證書,就可以這樣
$ curl -E localcert.pem https://remote_server
再比如,你還可以用curl通過dict協議去查字典 ~
$ curl dict://dict.org/d:computer

8/03/2011

img to CSS

img to CSS
原理就是用很多1x1的element (td) 的 background-color, 有做到 colspan 如果相鄰色是一樣的, 在某些mail client會阻擋image下載的場合會有用

通过绘制格子来计算的可视化乘法

通过绘制格子来计算的可视化乘法
グリッドを使ってかけ算を解く方法








8/02/2011

有趣的夜釣活動-家舜號生手夜釣~推推推

有趣的夜釣活動-家舜號生手夜釣~推推推
船長之家~基隆家舜號海釣船-~夜釣小管~深海船釣~基隆碧沙港

船長的電話0910168000

Goston's Blog » [MAC] 快速關閉 iMac 螢幕的方法

Goston's Blog » [MAC] 快速關閉 iMac 螢幕的方法

下次有這方面需求時,「Leopard」的使用者可按下「control + shift + eject」; 至於 Tiger 的使用者則可試試「Sleep Display Widget」及「Sleep Display Application」。

PhantomJS: Headless WebKit with JavaScript API

PhantomJS: Headless WebKit with JavaScript API

QuickStart - phantomjs - 5-Minute Guide - headless WebKit with JavaScript API - Google Project Hosting


var page = new WebPage();

page.open('http://www.google.com/m/local?site=local&q=pizza+in+new+york', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var results = page.evaluate(function() {
var list = document.querySelectorAll('div.bf'), pizza = [], i;
for (i = 0; i < list.length; i++) {
pizza.push(list[i].innerText);
}
return pizza;
});
console.log(results.join('\n'));
}
phantom.exit();
});

Apple's iCloud.com Error Pages Have Personality

Apple's iCloud.com Error Pages Have Personality