2011年7月22日 星期五

延遲執行-block版

在ios中如果要延遲執行某些程式碼,通常是使用performSelector:withObject:afterDelay的方式來做

但是如果只是想執行一兩行程式,又不想新增一個method的話,

可以參考Delayed Blocks in Objective-C這篇文章,

以我本身的例子,我想在xxx.m中使用的話,就在.m檔最上方直接加入:

@interface NSObject (PWObject)

- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay;

@end

@implementation NSObject (PWObject)

- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay
{
    int64_t delta = (int64_t)(1.0e9 * delay);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block);
}

@end

然後再想用的地方用performBlock:afterDelay即可。

2011年2月18日 星期五

在ubuntu上用ddclient更新你的dyndns Host

首先安裝ddclient,然後檢查/dev/default/ddclient,我的config如下:

# Set to "true" if ddclient should be run every time a new ppp connection is
# established. This might be useful, if you are using dial-on-demand.
run_ipup="false"

# Set to "true" if ddclient should run in daemon mode
# If this is changed to true, run_ipup must be set to false.
run_daemon="true"

# Set the time interval between the updates of the dynamic DNS name in seconds.
# This option only takes effect if the ddclient runs in daemon mode.
daemon_interval="3000"

最後一個參數設定你要多久檢查一次。

然後編輯/etc/ddclient.conf,我的config如下:

protocol=dyndns2
use=web, web=checkip.dyndns.com, web-skip='IP Address'
server=members.dyndns.com
login=帳號
password='你的密碼'
DNS代稱.selfip.org

以上只有斜體字要視情況修改,另外之前安裝ddclient的時候也有問一些問題,

基本上就是記錄在這裡,不過我覺得很奇怪的是,原本server的部份是叫做

members.dyndns.org,可是這個位址我怎麼找都找不到、也連不上。

後來突發奇想,把org改成com就可以了...這...

如果改完以後想馬上知道結果,就把/etc/default/ddclient的時間改短一點,最短好像也是一分鐘。

然後先關閉ddclient:sudo /etc/init.d/ddclient stop,這時候記得去把快取檔案刪除:

sudo rm -rf /var/cache/ddclient/ddclient.cache

再把ddclient打開即可:sudo /etc/init.d/ddclient restart

或者先用ddclient -daemon=0 -verbose來檢查一下是否正常。

為了避免以後重灌又忘記,特此一留。

2011年1月28日 星期五

URL上特殊字元的對應

 Dollar ("$")
 Ampersand ("&")
 Plus ("+")
 Comma (",")
 Forward slash/Virgule ("/")
 Colon (":")
 Semi-colon (";")
 Equals ("=")
 Question mark ("?")
 'At' symbol ("@")
24
26
2B
2C
2F
3A
3B
3D
3F
40
36
38
43
44
47
58
59
61
63
64


來源在此:URL Encoding

在判斷YouTube的get_video_info時會有幫助,先記在這裡,以免要找忘記。

另外取得資訊的網址格式為http://www.youtube.com/get_video_info?video_id=,後面加上影片ID即可。