2012年10月1日 星期一

Emacs for objective-c development

Emacs for obj-C development.md

To develop GNUStep program under Debian, we need 2 handy tools:

1. Auto complete for obj-c.
2. Source browsing.

For the first one, emacs has auto complete package support for after Emacs24. If you are using Debian wheezy, you have to build from source. Before compile, the pre-requisite packages are:

 $ sudo aptitude install build-essential libxpm-dev libgif-dev libtiff-dev libjpeg-dev libgtk2.0-dev libdbus-1-dev texinfo

Build with these pre-requisite packages can let your emacs customise the X fonts easily. And the build commands are :

$ ./configure --with-x-toolkit --with-xft
$ make
$ sudo make install

ps.: It seems that the default configuration does the same work.

The default install directory is /usr/local/bin.

Since Emacs24, in emacs package provides a convient way to install e-lisp plug-ins, add the following lines in your .emacs :

(require 'package)
(add-to-list 'package-archives 
    '("marmalade" .
    "http://marmalade-repo.org/packages/"))
(package-initialize)
(add-to-list 'load-path "~/.emacs.d")    ; This may not be appeared if you have already added.

Now open emacs, install the auto-complete package by :

M-x package-install [RET] auto-complete [RET]

After that, append the following lines in your .emacs

(require 'auto-complete-config)
(ac-config-default)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.4/dict")
(add-to-list 'ac-modes 'objc-mode) ;;here load the objc-mode

Note : Here the version is 1.4, modify the version if necessary.

OK, now we should have the emacs support auto-complete for obj-c.

For the second one: Source browsing, can be done with Gnu Global (gtags).

Since the Debian/Ubuntu currently provide Global-5.7.1, which does not support '--encode-path' option, the option will be used in the plug-in. We have to build Global-6.2.4 from source then "configure" "make install", and complete the setup by copying gtags.el to ~/.emacs.d and append :

(add-to-list 'load-path "~/.emacs.d")    ; This may not be appeared if you have already added.
(autoload 'gtags-mode "gtags" "" t)

After that, the gtags command will be setup correctly. #

2012年9月29日 星期六

git-diff between branches

git-diff on different branches.md

Before we diff, we have 4 branches :

tomteki-Mac-Pro:HearingLite tom$ git branch

TestUSB
* master
multiLanguage
testKbd

tomteki-Mac-Pro:HearingLite tom$

We want to diff the EditProfileViewController.m, to get the idea of where it is :

tomteki-Mac-Pro:HearingLite tom$ git diff --name-only master testKbd | grep EditProfileViewController

Classes/EditProfileViewController.h
Classes/EditProfileViewController.m
HearingLite/EditProfileViewController.h
HearingLite/EditProfileViewController.m

tomteki-Mac-Pro:HearingLite tom$

The above command will diff between two branches (testKbd and master).

Assume it is restructured from HearingLite/ path to Classes/ path (if doesn't , git ls-files can help ), the next thing to do is really diff them :

 git diff master:Classes/EditProfileViewController.m testKbd:HearingLite/EditProfileViewController.m

In this note, we use the 'git diff --name-only' to get the path of our target file. And use 'git diff [branch] : [file path]' to diff the file in various branches.

2012年8月16日 星期四

Check members belonging to a group

Under Mac OS, sometimes we want to know whether we belongs to the 'admin' group :

dscacheutil -q group -a name admin
and we get the responses :
name: admin
password: *
gid: 80
users: root tom 

More details about this command are in man pages.

2012年7月23日 星期一

Linux USB to Ethernet 與 driver 驗證




App 如何指定可支援的機子?

上架時,遇到一個問題:若是想讓自己的 App 避開某些機子,如『不適合在 3gs 或其規格以下的機子執行』,該怎麼辦呢?

這裡提供了一個方法,搭配 Apple 所訂的 Device Compatibility Matrix,就能用規格來卡位。

例如:『不適合在 3gs 執行』這個條件,就根據 Matrix 來找出 3gs 不支援的功能,像是 "front-facing-camera" or "gyroscope" 都可以,把它設定到你的 App Plist 的 "required device capabilities",將來就可以在你的 iTunes App 黃頁,巨大 Icon 的下方,看到 3gs 沒有被列入了!

參考文件: App related resources.

2012年6月1日 星期五

統計程式碼

想要統計程式行數,又是 bash 新手等級,查到好心網友的指令:
 find . \( -name *.h -or -name *.c \) -print

拿 linux source 來試試,沒問題。但是在我的 project 下,出現 error:
find: paths must precede expression: CADebugMacros.h

修正後可以了:
 find . \( -name '*.h' -or -name '*.c' \) -print

最後加上 wc :
 find . \( -name '*.h' -or -name '*.c' \) -exec cat "{}" ";" | wc -l 


2012年5月31日 星期四

XCode 4.3 Extended Modules

從開發環境 XCode 4.2 migrate to XCode 4.3 以後,原本可以 compile 的程式碼出現問題:"CADebugMacros.h" 找不到。
原來這是以前放在 /Developer/Extras/CoreAudio/PublicUtility/** 下面的 header file. 隨著 XCode 4.3 推出,/Developer/** 目錄已經不復存在,一些 Cocoa FrameWork相關的模組內定為不安裝,必須請開發者自己搞定(Apple 內心獨白:呵呵,要付錢才給你用!)
解決這類問題,首先由 XCode 4.3 選單連到 Apple developer 網站:


當然,這時出現登入 iOS developer 的畫面,有繳保護費才能繼續玩喔
登入後,看到 Extended modules:


下載後,可以自行指定要安裝在那兒,以我自己的環境為例, 整包 CoreAudio 目錄安裝於 /Users/tom/Documents/XCodeExtraLibrary/CoreAudio/* :




如上圖,在 XCode 的 Targets -> Build Settings 標籤內,輸入安裝的路徑,就可以解決問題!


Private Method in Objective-C

Objective-C 的呼叫是 message passing 方式,只要有 implement method 可以呼叫,就會成功。這種情形下,沒有像 C++ 的 private method,只能靠 Compiler 警告. 實作方法 這裡

Now in 2013 things changed:
Apple 提供的 IDE : XCode 4.5 支援 objective-C 2.0 (大概是這個版本) catetgory,可以提供私有 iVars 與 methods 的宣告了!

2012年4月17日 星期二

iOS project 添加 Three20 支援 (XCode >= 4.0)

Three20 Screencast 指令節錄 網址: http://www.youtube.com/watch?v=-0-E-Z0fihg

Clone project:

git clone git://github.com/facebook/three20.git

Create your own project e.g. TestThree20, paralleled to the git downloads, then you have directories like this:

Documents
    |
    three20
    |
    TestThree20

Then, use one python scrip to automatically import three20 to your project:

python three20/src/scripts/ttmodule.py -p \
 TestThree20/TestThree20.xcodeproj Three20 --xcode-version=4

Now, open your project in XCode, all things were done.

2012年4月1日 星期日

How to create project with Cocos2d and ARC support

Reference from this site :
Tiny tim
Often we want to write our APP under iOS5 with ARC support. But the developers of Cocos2d are still working for transfering the framework to the ARC.
How should we do ? Disable ARC for all Cocos2d files one by one ? Tiny tim has proposed a cleaner way --- managed by sub-project. Here it is :

1. Get cocos2d sources:
    Go to https://github.com/cocos2d/cocos2d-iphone
    git://github.com/cocos2d/cocos2d-iphone.git
   
2. Checkout the gles20 branch
    git checkout gles20
3. Creating your own project with ARC enabled, by default, it is enabled by the XCode4 templates.



4. Drag and drop cocos2d-ios.xcodeproj to your project, and link cocos2d as a static library to your project.


5. Configure the user header search for YOUR PROJECT (not cocos2d-ios).



6. Configure the recursive searches.



7. Build the project. Note : If you exam "Build settings" of your project , the setting of "Objective-C Automatic Reference Counting" is "Yes". In cocos2d-ios sub-project, the same setting is "No".

2012年2月7日 星期二

Shadow Matrix 筆記

尋找如何做出 Shadow matrix 的過程中,發現 HOTBALL'S HIVE 介紹得很好。但是
有些推導過程,中間的步驟很簡明,對於新手的我來說,還是得拿紙筆來演練,
才能順利接上,在此作個筆記。為了一致性,這裡的符號標示,也是沿用該網頁。

目的:給定光源,在已知平面上 (以 normal vector \( \vec P \) 表示)找出平面以外某一點 \( \vec V \),
在平面上的投影點,然後導出其 Matrix Operation。


如圖,沿著射線,存在ㄧ k 值,使得 \( \vec V \) + k\( \vec L \) 為平面上的交點:
\[ (\vec V + k \vec L) \cdot \vec P = 0 \] \[ k = -\frac{\vec V \cdot \vec P}{\vec L \cdot \vec P} \] 所以投影點為: \[ \begin{align} \vec V + k \vec L &= \vec V - \frac{\vec V \cdot \vec P}{\vec L \cdot \vec P} \vec L \cr &= \frac{\vec V (\vec L \cdot \vec P) - (\vec V \cdot \vec P) \vec L}{\vec L \cdot \vec P} &(\ddagger) \end{align} \] 令 \[ \begin{align} \vec L &= \langle L_x,L_y,L_z,0 \rangle \cr \vec V &= \langle V_x,V_y,V_z,1 \rangle \cr \vec P &= \langle a,b,c,d \rangle \end{align} \] 對於 homogeneous coordinate \( \langle x,y,z,w \rangle \) 而言,w 是分母之意, 亦即對應的 3D coordinate 為 \( \langle x/w, y/w, z/w \rangle \), 也就是 \( \vec L \cdot \vec P \) 在 homogeneous coordinate 表示下恰為 \( w \) 之值。 展開 \((\ddagger)\) 式子的分子為: \[ \langle V_x,V_y,V_z,1 \rangle (aL_x + bL_y + cL_z) - (aV_x + bV_y + cV_z + d) \langle L_x,L_y,L_z,0 \rangle \] 其中 \(x\) 分量為: \[ V_x(bL_y + cL_z) - V_y(bL_x) - V_z(cL_x) - dL_x \] 同法可得 \(y,z\) 分量,整理得到 shadow matrix: \[ \begin{bmatrix} bL_y + cL_z & -bL_x & -cL_x & -dL_x \cr -aL_y & aL_x + cL_z & -cL_y & -dL_y \cr -aL_z & -bL_z & aL_x + bL_y & -dL_z \cr 0 & 0 & 0 & aL_x + bL_y + cL_z \end{bmatrix} \] 內心獨白: \(\LaTeX\) 打了會上癮!

MathJax Test

This is a test of using MathJax in Blogger   Note that enclosing math in single $'s does not work in the default setting for MathJax.  However, you may use "\(\backslash(\)" and "\(\backslash)\)" for inline math and double dollar signs or "\(\backslash[\)" and "\(\backslash]\)" for displayed math.  Examples for inline is:  \( (y+\sqrt z)^{-1} \) and  \( \sin^2 x^2 \).  And, a displayed equation is: $$\frac 2 3$$
Another displayed equation is here:
\[
\forall x \exists y (x\le y \land y\le x \leftrightarrow x=y) .
\]
\[
\vec \Phi ( \vec r) = -\frac{G M_1}{| \vec{r}-\vec r_1 |} \]

To setup the MathJax capability, I added the following line to the HTML code, after the <head> command (as a single line, no line break):

<script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>

You can find more information from the MathJax website about this at http://www.mathjax.org/docs/1.1/start.html.