GCC extension

The following example will use typeof to build generic macro.
(void) (&_min2 == &_min2); // create compile warning when type is not match.

#define min(x, y) ({				\
	typeof(x) _min1 = (x);			\
	typeof(y) _min2 = (y);			\
	(void) (&_min1 == &_min2);		\
	_min1 < _min2 ? _min1 : _min2; })

Branch prediction hints

Branch prediction:

likely
macro!!

There are many optimization extensions in the article!

Reference:

GCC hacks in the Linux kernel

[linux] copy files to other machine

You want to copy the whole directory in machine 1 to machine 2.
And there are a lot of files under the folder.

machine 1:
tar -cpf – srl | nc 192.168.1.230 1234

machine 2:
nc -l -p 1234 | tar -xf –

nc is a good command :)

2009/10/09 ~ 10/11 雪山主東峰+翠池

本來因為颱風的擾亂, 原本以為不會成行的雪山之行, 在最後一天國家公園開放中, 我們成功成行!

一開始在到達登山口的路上, 顛簸的山路當中, 不時還發現一旁坍方的道路, 害我心裡毛毛的, 希望上山的路不會太困難~

第一天我們是睡在七卡山莊, 看樣子大家因為颱風 所以都沒人進山, 所以整個山莊幾乎沒什麼人XD, 我們就在一個人睡兩個人床位中睡著, 中間發生一件插曲, 有個白目為了找他的登山杖, 把所有人都吵了起來…當下真想扁他阿!

第一天白天的路程不算難走, 4km到達369山莊, 哭坡走起來也不會想哭, 只是會哭夭吧XDD, 而且天氣還算不錯, 沒什麼下雨, 不過應該是太久沒運動, 體力的確是變差了…走起來有點小累

第二天一大早起來就準備登頂, 經過了黑森林, 最後一段上坡, 真是走到快吐血, 速度太慢了, 走起來很辛苦~ 而且陰雨綿綿, 風又大, 覺得相當的冷! 在這種情形下, 大家的士氣也落到了谷底>”<

幸好最後到了主峰, 不過也是相當的冷, 本來以為不要攻翠池了, 沒想到仁哥要go, 那我當然就go了阿! 下翠池真的是相當辛苦, 一開始走稜線走的相當快, 而且霧很大, 視線不好, 從碎石坡下去, 更是相當耗費腳力, 從大石頭, 中石頭, 小石頭, 到碎石頭, 有夠難走, 就在我腳快沒力發抖的時候, 幸好下降結束了! 開始進入比較緩的路~

翠池旁邊的大碎石坡真的蠻壯觀的~ 吃著爽快的泡麵~ 可惜要趕著回去, 沒機會躺著休息太久~ 上坡的路途更累, 而且視線不良, 就連仁哥都有時會走錯路, 這種路實在是需要有經驗的人帶才行, 而且走在稜線上, 要注意風~ 不過一路上我們都沒什麼休息, 所以其實走的速度相當的快, 比預定時間還稍快我們就回到369山莊了~ (OS: 去之前就聽大哥說, 去北稜角比較好, 去了翠池雖然覺得不錯, 但是可能是去的人少加上天氣不好, 就覺得還好…)

晚上大家當狗仔慶生~ 讓她享受一下給男士們服務, 小魚乾特別服務~

隔天我們大家睡的比較晚, 因為今天就只要下山就好~ 一開始天氣還很霧, 不過後來陽光露臉, 看到369山莊後面一整片的樹林, 如果在冷一點就會整片都是楓葉!

下山的路大家走的很輕鬆, 後來我們還去泡了一下溫泉, 感覺真是爽快! 全身放鬆休息一下~ 雖然洗的有點趕, 不過洗完真的是全身軟趴趴>///<

相簿

2009/12/20 富邦馬拉松

因為不想跟去年參加一樣的9km競賽組後,  為了挑戰一下自己, 就跑去報了21km的半程馬拉松~ 但是其實只有練習一個月左右…加上自己又有點懶, 每星期大概就跑個兩次, 每次大概也8km而已~ (OS: 繞圈圈真的很無聊…)。

今天五點起床, 真的是冷到暴…實在很不想起床>”<, 不過最後還是硬著頭皮上, 沒想到到了捷運站還遇到阿里巴跟嘉琪(可惜跟你們不同組XD), 可是沒遇到Carl & Jianang, 所以我就跟Yukoh自己跑了, 一路上我們一直以比較慢的速度再跑, 畢竟我跟他都沒跑過21km…所以想保留體力到後半部, 中途還看到超人裝, 忍者裝, 蜜蜂裝XDD, 跑餓了就去拿香蕉吃~~ 整體而言跑起來不會太累, 除了我忘了帶毛巾包頭, 所以會冷以外…

Anyway, 今年又完成了一項目標! 休息個一星期後, 明年要先挑戰一下半程的鐵人三項!

要好好鍛鍊我的游泳

memcached info

Introduction:
http://blog.xdite.net/?p=1029

http://ihower.idv.tw/blog/archives/1768

 

Internal implementation:
http://tech.idv2.com/2008/07/10/memcached-001/

 

update data in DB:
If we delete data in memcached when we update data in DB, it will cause “cache stampedes”. It is if there are many clients find out the entry isn’t in memcached at the same time, all of they will try to query from DB, then it will cause performance issue. So we need to create a lock in memcached, every client will try to check whether the lock is exist. If it is not exist, it can query and delete it after finish, other clients will wait a period time to wait cache.

 

data fragment and for each item:
We need to make experienment for choosing cache data!

Now for this simple application, coding something like this is simply overkill, so let’s look at a more practical example: a photo sharing site that contains lists of photographs with links to detail pages.
Many such sites display paged lists, so 100 pictures in a list might be displayed as thumbnails with basic information, ten per page. Based on all of the coding we’ve done, it might seem reasonable to go get a list of one page of data from the database, cache the resulting list and then get the second page and cache that list and so on. But there’s another way to handle that.

Start by getting the list of all 100 items that make up the list and cache that. Build the paged lists from that information, rather than going back to the database for every page. Now the same list serves someone who only wants to see 5 items per page as well as some-one who wants to see 20, which is better than having to query the
database 20 times for one person and another 5 times for the other, when all we’re doing is showing the same data paged differently.

The most important thing to remember is that this is not an all-or-nothing approach. You may have data that lends itself to stor-ing nothing except lists of pointers, and then store the individual data items separately. But you might just as easily have data where it makes more sense to store lists that contain data. This is one of those things you need to experiment with and see which makes more sense for your application.

From Using Memcached

Advance:
http://blog.gslin.org/archives/2008/12/13/1884/

http://highscalability.com/blog/2009/10/26/facebooks-memcached-multiget-hole-more-machines-more-capacit.html

 

multiget hole:
Adding new memcached server didn’t help when it’s CPU bound. What it can happens is when you add more servers is that the number of requests is not reduced, only the number of keys in each request is reduced.
Ex: If you have send 50 requests to 2 memcached servers, and each request use multi_get to get 100 entries. So each memcached server will contain 50 entries. After you add one memcached server, the requests are still 50, but only each memcached contain 33 entries. Requests are not reduced. As a result we’ve done absolutely nothing to reduce the usage of our scarce resource which is CPU!
http://highscalability.com/blog/2009/10/26/facebooks-memcached-multiget-hole-more-machines-more-capacit.html

[]

Now I just don’t have that mood for birthday…I just don’t know what’s the birthday meaning for me now. As a result, I don’t expect a birthday party or something. But I will remember whatever you do for me, thanks forever

Perception change the solution!

今天看到一個有趣的演講, 是這樣子的, 現在想要縮短倫敦到巴黎的時間, 這時候工程師就開始想solution, 最後終於想出來了一個好方法, 這個solution花了60億, 也就是再蓋一條新的鐵路, 縮短了40分鐘的車程, 但是其實我們可以往另一個方向去想,  我們用30億的錢把全世界最頂尖的model都請來站在鐵軌上, 這樣我相信大家還會要求把列車速度降下來呢! The same problem, but different solution!

還有一個故事, 有一個國王想要他的子民能夠推廣多種馬鈴薯, 但是那個時候沒有人想種這種看起來髒髒的作物, 但是他又不能強迫大家種, 也不能把不種的人處決掉, 所以他就散佈假消息出去, 說馬鈴薯是貴族愛用的食物, 然後再把如何栽種的方法寫下來, 再想辦法讓別人把方法偷走~ 果不其然, 後來大家就開始種植馬鈴薯!

其實很多時候很多東西都只是認知上的差異, 這也是為什麼安慰劑(placebo)的存在, 如果我們能給予舊的東西新的象徵, 也會有不一樣的結果~

如果不告訴你喝的酒很貴, 你真的分的出來嗎??

曾經再書上看過一個例子, 你覺得一瓶水應該賣多少錢呢??

在問一下, 你覺得一瓶水對於一個在沙漠的人, 又應該賣多少錢呢?

怎麼樣充分利用你所有的東西, 這可真是一門學問阿~

[work] working about 3 months

不知不覺中, 我已經工作三個月了, 三個月說長不長說短不短, 或許也是該來回顧一下自己過去三個月做了甚麼!

其實大部分我的朋友都會覺得我實在是過太爽XD, 其實我們公司很自由, 完全是讓你自己操控(你看PDD不是忙的甚麼鬼似的)~ , 所以過太爽是因為我在還沒有完全定下心工作, 希望慢慢的我可以把自己的心態調整好, 至少上班時間不要打混…(OS: 不然就對不起我的老闆了XD)

我很慶幸就目前為止, 我當初的選擇似乎沒有錯?!

過去三個月, 雖然沒有像camel隨便就3,4千行的python code, 但是還是有寫了一些東西~

python:
寫了個簡單的server, about 500行, 加上extend c lib加速, 還有寫了類似壓力測試的程式來測試, 學了一點點unit test

erlang:
這部分不得不推, 在台灣大概肯讓我自己玩這個東西的公司應該是沒有吧XD, 花了點時間把O”Relly的Erlang Programming翻完, 而且我最近終於開始動工, 目前是寫了一千多行(加上測試), 還trace了網路上的一個light http server source code, 學會了別人是怎麼寫類似的東西! 這些東西書上都不會提到…

twiki:
幫公司架了一個wiki, 現在大家好像比較有把東西往那邊丟, 不錯不錯!

git:
雖然公司現在全面使用SVN, 但是我自己無聊架了一個git, 翻了前幾章的pro git這本電子書, 了解了一點distribute version control system~

還有大概了解公司某部分最核心的source code~

接下來要把我之前自己寫的東西串起來加上開始測試別人的東西, 還有另一個案子過陣子應該也要動工@@”

不過不知道為什麼, 雖然說還是蠻喜歡寫程式的, 但是好像沒有高中那種衝勁, 有點甚麼都可以的感覺, 希望能慢慢找到自己最愛的領域, 好好鑽研~

不過小公司還是有點壞處, 就是沒有像PDD他們那樣多采多姿的社團生活>”<

p.s 耶?! 才剛說不要偷懶, 結果我就在上班時間打了這篇文章XDD

[movie] P.S 我愛你

這真是一部好看的電影!! 強力推薦

老實說看到一開始, 讓我想起了一些事情, 我完全掉進回憶的漩渦中…至今我還沒有走出來, 所以我一直都是逃避, 不想去想它, 沒什麼勇氣

因為我越想就越想哭, 很多話都還沒說呢…

什麼時候我才有勇氣面對呢

This is a test!

Just a test!!!