2011年11月2日

XCode: set breakpoint before exception got thrown

有時候 app crash 的點不是在我們自己 code 的範圍,這樣程式停住的點會在 main 裡面
而且還沒有 dump / stack 可以看,這樣很難 debug。

其實可以在 exception 被丟出造成程式結束之前就把它攔下來,這樣就有 stack 可以看。

2011年10月28日

parrentViewController, presentingViewController

又遇到一個 5.0 的改變......

參考官方網頁對 parrentViewController 的說明

Prior to iOS 5.0, if a view did not have a parent view controller and was being presented modally, the view controller that was presenting it would be returned. This is no longer the case. You can get the presenting view controller using the presentingViewController property.

嗯,這又怎樣呢?

2011年10月21日

Crash while calling deleteRowAtIndexPaths:withRowAnimation on UITableView

喔耶又踩一個洞 -_-

deleteRowAtIndexPaths 砍完好像是會 call 一次 row count 做檢查
所以一定要先把 data source 的東西砍了再去 call deleteRowAtIndexPaths
不然就等著接 exception -_-

Calling sequence of presenting a UIViewController on iOS


哈哈哈中鏢了
iOS5 改了 calling sequence
反正都查了就記一下......

當一個  UIViewController 要出現的時候
iOS 4.3  會按順序 call 這些東西
shouldRotate
didLoad
shouldRotate
didRotate
willAppear
didAppear

啊 5.0 改成這樣
shouldRotate
didLoad
shouldRotate
willAppear
shouldRotate
didAppear

我覺得 4.3 看起來比較有道理耶 -.-a

2011年9月22日

Objective-C 遇到 method 撞名會發生什麼事....

這東西果然會這樣.....
A big weakness in Objective-C's weak typing

簡單的說,對一個 id 傳 method 很可能不是傳到你想要的那一個,
而是所有能見的 method 中找一個名字一樣的出來傳進去。
這個「所有能見」當然包含了你自己寫的、你 import 進來的,還有整個 foundation。

self...Why I can change self?

Just because self is merely a hidden variable but not "this".

here is a clear reference: What does it mean when you assign [super init] to self?


標題絕對不是什麼哲學問題wwwwwww

2011年9月19日

Apple open source

原來 apple 有 open source @@
http://www.opensource.apple.com/

上篇提到的 CFArray 在這
http://www.opensource.apple.com/source/CF/CF-368.18/Collections.subproj/

NSArray (CFArray)

要做一些事情,有點在意這東西的 performace
所以就找了一下....發現這篇
傑克這真是太神奇了 -_-
有空我一定要來看一下他的 code .....

另外在這邊看到有人說把要砍的東西先通通放到一個array再一起傳給NSArray叫他砍會比較快
hmm...滿有趣的,可能是 iterator 跑的範圍會越來越小?

2011年9月9日

settings on mac

這幾天在用 mac,這東西還真是什麼都跟別人不一樣...
記一下 terminal setting

首先沒有 .bashrc!這邊叫做 .profile -_-
再來預設 terminal 是沒有顏色的....
要在 .profile 裡面設 alias ls='ls -vG'
-G 是讓他有顏色, -v 是可以看中文
然後要打中文的話,再新增一個 ~/.inputrc 檔,內容如下:
set convert-meta off
set meta-flag on
set output-meta on

另外 vimrc 在 /usr/share/vim!
難怪我改 ~/.vimrc 跟 /etc/vimrc 都沒用 -_-

2011年4月20日

daemonize in python

看到一個不錯的範例:
A simple unix/linux daemon in Python

有裝 django 的話,在 $PYTHON_ROOT/lib/site-packages/django/utils/daemonize.py
也有個 become_daemon 可以用,
不過這個就如其名只管 become daemon,想停掉自己去 kill :p

2011年1月22日

python 讀檔

讀檔當然就 open 就好啦,超簡單的有什麼好寫?
不過如果檔案不是 ascii 就....

所以還是要花點功

2011年1月21日

django ModelAdmin form submit

記錄一下 django 裡面處理有 inline formset 的 form 時,
它的 calling sequence

2011年1月12日

python timestamp

python 要做 linux 的 time_t 格式的話

>>> import datetime, calendar
>>> now = datetime.datetime.now()
>>> type(now)
<type 'datetime.datetime'>
>>> calendar.timegm(now.timetuple())
1294833875

django models 與 sql database 的對應

ref: http://www.djangoproject.com/documentation/models/custom_columns/

django 預設在建立 db schema 的時候
會把 table name 設成 {app_label}_{model_name},
然後 foreign key 的那個 column name 會幫你 append 一個 "_id",
另外如果你沒有指定 primary key,它也會幫你加一筆 "id"

django admin site model url

有時候會想 link 到 model 的 change_form 那一頁,
自己兜 url 的話是這樣

class SiteInfo(models.Model):
    CategoryId = models.ForeignKey('SiteCategory', db_column='CategoryId', db_index=True)
    def show_category_in_list(self):
        return u'{3}'\
                 .format(self.CategoryId._meta.app_label,
                         self.CategoryId._meta.object_name.lower(),
                         self.CategoryId.Id,
                         self.CategoryId.__unicode__())
    show_category_in_list.allow_tags = True

順便注意要傳 html content 的話要設一下 allow_tags