1. cat /proc/asound/pcm
00-03: NVIDIA HDMI : NVIDIA HDMI : playback 1
01-00: WM8903 HiFi WM8903-0 : : playback 1 : capture 1
01-01: Tegra BT Voice tegra_generic_BT_codec-1 : : playback 1 : capture 1
01-02: Tegra BB Voice tegra_generic_BB_codec-2 : : playback 1 : capture 1
01-03: Tegra Spdif tegra_generic_spdif_codec-3 : : playback 1 : capture 1
2. cat /proc/asound/devices
0: [ 0] : control
19: [ 0- 3]: digital audio playback
32: [ 1] : control
33: : timer
48: [ 1- 0]: digital audio playback
49: [ 1- 1]: digital audio playback
50: [ 1- 2]: digital audio playback
51: [ 1- 3]: digital audio playback
56: [ 1- 0]: digital audio capture
57: [ 1- 1]: digital audio capture
58: [ 1- 2]: digital audio capture
59: [ 1- 3]: digital audio capture
3. cat /proc/asound/cards
0 [tegrahda ]: HDA-Tegra - tegra-hda
tegra-hda at 0x70038000 irq 113
1 [tegrawm8903 ]: WM8903 - tegra-wm8903
tegra-wm8903 (WM8903)
4. cat proc/asound/card1/pcm3p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 1024
buffer_size: 4096
4. cat proc/asound/card1/pcm3p/sub0/status
state: RUNNING
owner_pid : 129
trigger_time: 946685095.133345001
tstamp : 946685520.139324001
delay : 3576
avail : 520
avail_max : 1120
-----
hw_ptr : 18742800
appl_ptr : 18746376
2011年12月16日 星期五
2011年11月23日 星期三
2011年11月21日 星期一
mDNSResponder and dav service type setting
sudo mDNS -R "DAVServ" "_dav._tcp" "local" "80" ipaddr="127.0.0.1" path="uploads" u=admin
2011年11月18日 星期五
Shell script for string length, substring and index
Bash : string length ${#varname}
substring ${varname:begin:length}
${varname:begin}
index `expr index "$stringZ" C12`
substring ${varname:begin:length}
${varname:begin}
index `expr index "$stringZ" C12`
2011年11月8日 星期二
2011年11月4日 星期五
2011年11月1日 星期二
2011年10月25日 星期二
Backup all installed packages and move to another computer
Backup installed package list on current machine
dpkg --get-selections > selections.txt
move selections.txt to the new machine Set package list on new machine and install packages
dpkg --set-selections < selections.txt
apt-get update
apt-get upgrade
dpkg --get-selections > selections.txt
move selections.txt to the new machine Set package list on new machine and install packages
dpkg --set-selections < selections.txt
apt-get update
apt-get upgrade
2011年10月12日 星期三
viewWillDisappear
1. --------
ViewController : init with nib
* (internal) load nib
* (internal) init controller/view in nib
View : awakeFromNib
Controller : awakeFromNib ( if nib contain ViewController )
Controller : ViewDidLoad
Controller : ViewWillDisappear ------ 這部份很重要
Controller : dealloc
Controller : ViewDidUnload
if @property defined "retain", then any setXXX interface will increase reference count
這個東西很重要
2. -------- Category
語法:
@interface some_existed_class (my_extension)
@implement some_existed_class (my_extension)
This will "extends" some existing class to my usage
Without needing source code.
Categories 在建立 private methods 時十分有用。因為 Objective-C 並沒有像 Java 這種 private/protected/public methods 的概念,所以必須要使用 categories 來達成這種功能。作法是把 private method 從你的 class header (.h) 檔案移到 implementation (.m) 檔案。以下是此種作法一個簡短的範例。
ViewController : init with nib
* (internal) load nib
* (internal) init controller/view in nib
View : awakeFromNib
Controller : awakeFromNib ( if nib contain ViewController )
Controller : ViewDidLoad
Controller : ViewWillDisappear ------ 這部份很重要
Controller : dealloc
Controller : ViewDidUnload
if @property defined "retain", then any setXXX interface will increase reference count
這個東西很重要
2. -------- Category
語法:
@interface some_existed_class (my_extension)
@implement some_existed_class (my_extension)
This will "extends" some existing class to my usage
Without needing source code.
Categories 在建立 private methods 時十分有用。因為 Objective-C 並沒有像 Java 這種 private/protected/public methods 的概念,所以必須要使用 categories 來達成這種功能。作法是把 private method 從你的 class header (.h) 檔案移到 implementation (.m) 檔案。以下是此種作法一個簡短的範例。
2011年10月11日 星期二
iPhone development add button action
iOS set action
1. define IBAction functions in controller
2. Add buttons in xib
3. In file's owner's connection inspector, match each action function with each button. This part is critical, without it, the button press will do nothing.
1. define IBAction functions in controller
2. Add buttons in xib
3. In file's owner's connection inspector, match each action function with each button. This part is critical, without it, the button press will do nothing.
2011年9月23日 星期五
在 iPhone 裡面加入新的 Object library 和 include path
iPhone Development :
XCode add new library, framework and include
1. Add library object : in
Target -> Build phase (tab) -> Link Binary With Libraries (in page) -> add target library
2. Add own include path
Target -> Build setting (tab) -> Search Paths(in page) ->
Always search user paths : set enable
User Header Search Paths : add include path
XCode add new library, framework and include
1. Add library object : in
Target -> Build phase (tab) -> Link Binary With Libraries (in page) -> add target library
2. Add own include path
Target -> Build setting (tab) -> Search Paths(in page) ->
Always search user paths : set enable
User Header Search Paths : add include path
2011年9月21日 星期三
給壓縮檔加一個 password
先用
tar -cvf some_directory.tar some_directory
把目錄 tar 起來
然後用
zip -e some_directory.tar.zip some_directory.tar other_file1 other_file2 ...
加上 -e 的話, 壓之前會先問 password
解壓縮用
unzip -P password some_directory.tar.zip 來解
tar -cvf some_directory.tar some_directory
把目錄 tar 起來
然後用
zip -e some_directory.tar.zip some_directory.tar other_file1 other_file2 ...
加上 -e 的話, 壓之前會先問 password
解壓縮用
unzip -P password some_directory.tar.zip 來解
2011年8月27日 星期六
iPhone ObjC 的一些小用法
-----------------------------------------------------------------
一些 iPhone ObjC 的語法
因為用 C 用習慣了, 所以很需要 "formatter"
-----------------------------------------------------------------
[NSString stringWithFormat:@"%@ (%@)", [nameComponents objectAtIndex:2], [nameComponents objectAtIndex:1]];
-----------------------------------------------------------------
在 Table 裡面, 產生
+/- Item-Context >
這樣的效果的方式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator :可以放 ">" 在 table cell 的右邊
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath : 可以放 +/- 在 table cell 的左邊
-----------------------------------------------------------------
在加入 code data 的時候, 不要勾選 copy file/folder 的選項, 會造成 link fail
-----------------------------------------------------------------
在 obj c 裡面, 有一個隱含的語法, 當我們在 class 裡面有一個 attribute, 比如說, TypeA AttrA; 用 proprety 去宣告.
同時 implement 了一個 TypeA AttrA { .... } 的函數, 則在 reference 到 AttrA 的時後, 會主動連結到這個函數.
一些 iPhone ObjC 的語法
因為用 C 用習慣了, 所以很需要 "formatter"
-----------------------------------------------------------------
[NSString stringWithFormat:@"%@ (%@)", [nameComponents objectAtIndex:2], [nameComponents objectAtIndex:1]];
-----------------------------------------------------------------
在 Table 裡面, 產生
+/- Item-Context >
這樣的效果的方式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator :可以放 ">" 在 table cell 的右邊
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath : 可以放 +/- 在 table cell 的左邊
-----------------------------------------------------------------
在加入 code data 的時候, 不要勾選 copy file/folder 的選項, 會造成 link fail
-----------------------------------------------------------------
在 obj c 裡面, 有一個隱含的語法, 當我們在 class 裡面有一個 attribute, 比如說, TypeA AttrA; 用 proprety 去宣告.
同時 implement 了一個 TypeA AttrA { .... } 的函數, 則在 reference 到 AttrA 的時後, 會主動連結到這個函數.
Webdav first try
First, I have to setup a webdav server on my development mac, which just following the web guideline.
Second, I use litmus tool to test my webdav server.
Litmus is quite different. It uses "make" to run test, not compiles out a executive and runs test.
configure
make
make URL="http://my-webdav-server/my-upload-path" CREDS="admin admin" check
Second, I use litmus tool to test my webdav server.
Litmus is quite different. It uses "make" to run test, not compiles out a executive and runs test.
configure
make
make URL="http://my-webdav-server/my-upload-path" CREDS="admin admin" check
2011年8月12日 星期五
iPhone 的進入門檻(1) code sign
寫慣了Android apk, 轉來寫 iPhone APP, 第一個遇到的問題, 就是程式上傳. 在 Android 裡面, 只要 USB 插了, 就可以上傳, iPhone 需要的動作多很多.
1. 要有一個價值 $99 USD 的 development program ID. 這是最簡單了, 給了錢就有.
2. 用那個 ID 登錄上到 iOS Provisioning Portal
3. 瞭解一下 iPhone 程式上傳和模擬器的差別
a. 模擬器
a1. Build code
a2. Run APP
b. 手機
b1. Code sign
b2. Build code
b3. Upload code
b4. Run APP
最關鍵的就是 b2 : code sign
code sign 就是給 APP 加上開發簽署, 這個開發簽署又有分 developer 和 distributor, 我還沒使用過 distributor 簽署, 這邊先講一下 developer 開發簽署的過程
簽署的動作是把Apple 公司, 開發電腦, 開發 ID, 開發程式和手機綁在一起. 動作是 :
a. 安裝 Apple 開發簽章 apple worldwide developer relations certification
a1. 下載後面的 Worldwide Developer Relations 的 certification
a2. 執行該 certification, 這個動作會把 certification 安裝到鑰匙圈裡面
a3. 執行 應用程式 -> 工具程式 -> 鑰匙圈存取, 在鑰匙圈 - 登入, 類別 - 憑證 的 項目裡面, 會看到 Apple World Wide Relations Certification
b. 從電腦裡面產生 certification request, 以及其他準備工具
b1. 在 menu 裡面, 執行鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證, 產生一個 certification request. 這邊的憑證授權(機構)其實就是之後要上傳的 Provisioning Portal
b2. 在 provisioning portal 裡面的 certification 頁面, 上傳該 certification request. 因為是唯一的, 所以換電腦的話, 這整個動作要重作.(當然, 如果使用的是團隊開發的授權, 就可以增加很多個 team member.)
b3. reload page, 直到看到 download 選項出現, 選 download, 下載憑證, 然後執行該憑證
b4. 開啓鑰匙圈工具, 看看登入 -> 憑證類別, 裡面應該要有
b41. Apple Worldwide Relations Certification
b42. 剛剛產生的憑證
b43. 這些憑證都有一個綠色的勾, 旁邊顯示:此憑證是有效的
b44. Double click 每個憑證, 在"信任"的項目裡面, 選擇系統預設
b45. 到此為止, 每個憑證都要是有效的
c. 幫自己的 iPhone/iPad/iPod 建檔
c1. 開啓 Xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. 點一下 device 下的 iPhone, 右邊出現 iPhone 的一些內容, 其中有一個 Identifier : xxx
c3. 登入到 Provisioning Portal, 選擇 Add device, 把剛剛的 xxx 打進去, 然後 submit
c4. Reload Page, 應該看到自己的 iPhone 建檔了
d. 把 certification request 上傳到 Provisioning Portal, 加上簽章, 產生 certification. 這個動作把電腦和 Developer ID 綁在一起.
c1. 如果 a-c 都是正確的, 那在開啓 xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. Device 下的 iPhone, 下面有一個 Provision Profiles, 執行底下的 refresh
c3. c2 會產生一個 team provisioning profile: * 的 profile
c4. 在各個開發的 APP 裡面, 確認每個 APP -> Project -> build settings -> Code Signing -> 選 iPhone Developer
c5. Clean, rebuild
1. 要有一個價值 $99 USD 的 development program ID. 這是最簡單了, 給了錢就有.
2. 用那個 ID 登錄上到 iOS Provisioning Portal
3. 瞭解一下 iPhone 程式上傳和模擬器的差別
a. 模擬器
a1. Build code
a2. Run APP
b. 手機
b1. Code sign
b2. Build code
b3. Upload code
b4. Run APP
最關鍵的就是 b2 : code sign
code sign 就是給 APP 加上開發簽署, 這個開發簽署又有分 developer 和 distributor, 我還沒使用過 distributor 簽署, 這邊先講一下 developer 開發簽署的過程
簽署的動作是把Apple 公司, 開發電腦, 開發 ID, 開發程式和手機綁在一起. 動作是 :
a. 安裝 Apple 開發簽章 apple worldwide developer relations certification
a1. 下載後面的 Worldwide Developer Relations 的 certification
a2. 執行該 certification, 這個動作會把 certification 安裝到鑰匙圈裡面
a3. 執行 應用程式 -> 工具程式 -> 鑰匙圈存取, 在鑰匙圈 - 登入, 類別 - 憑證 的 項目裡面, 會看到 Apple World Wide Relations Certification
b. 從電腦裡面產生 certification request, 以及其他準備工具
b1. 在 menu 裡面, 執行鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證, 產生一個 certification request. 這邊的憑證授權(機構)其實就是之後要上傳的 Provisioning Portal
b2. 在 provisioning portal 裡面的 certification 頁面, 上傳該 certification request. 因為是唯一的, 所以換電腦的話, 這整個動作要重作.(當然, 如果使用的是團隊開發的授權, 就可以增加很多個 team member.)
b3. reload page, 直到看到 download 選項出現, 選 download, 下載憑證, 然後執行該憑證
b4. 開啓鑰匙圈工具, 看看登入 -> 憑證類別, 裡面應該要有
b41. Apple Worldwide Relations Certification
b42. 剛剛產生的憑證
b43. 這些憑證都有一個綠色的勾, 旁邊顯示:此憑證是有效的
b44. Double click 每個憑證, 在"信任"的項目裡面, 選擇系統預設
b45. 到此為止, 每個憑證都要是有效的
c. 幫自己的 iPhone/iPad/iPod 建檔
c1. 開啓 Xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. 點一下 device 下的 iPhone, 右邊出現 iPhone 的一些內容, 其中有一個 Identifier : xxx
c3. 登入到 Provisioning Portal, 選擇 Add device, 把剛剛的 xxx 打進去, 然後 submit
c4. Reload Page, 應該看到自己的 iPhone 建檔了
d. 把 certification request 上傳到 Provisioning Portal, 加上簽章, 產生 certification. 這個動作把電腦和 Developer ID 綁在一起.
c1. 如果 a-c 都是正確的, 那在開啓 xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. Device 下的 iPhone, 下面有一個 Provision Profiles, 執行底下的 refresh
c3. c2 會產生一個 team provisioning profile: * 的 profile
c4. 在各個開發的 APP 裡面, 確認每個 APP -> Project -> build settings -> Code Signing -> 選 iPhone Developer
c5. Clean, rebuild
2011年8月9日 星期二
See NIB identity
1.
When managing nib (.xib) file, we need to enable
View -> Utilities -> identity inspector
2.
Implement button event, we can
1. Layout a button on the NIB file with "Utilities -> attribute inspector"
2. On the button, hold "control" key on the keyboard and use the mouse to drag a "line" into assistant
3. It will appear a small window that helps adding an action
When managing nib (.xib) file, we need to enable
View -> Utilities -> identity inspector
2.
Implement button event, we can
1. Layout a button on the NIB file with "Utilities -> attribute inspector"
2. On the button, hold "control" key on the keyboard and use the mouse to drag a "line" into assistant
3. It will appear a small window that helps adding an action
Obj C notes
1. @interface
Used to declare a class. To declare a class MyClass inheriting MyParentClass, we can write
/* Code blocks begin */
@interface MyClass : MyParentClass {
}
+ ClassMethods:(type1)param1 :(type2)param2
- InstanceMethods:(type1)param1 :(type2)param2 SomeDescriptiveNotes:(type3)param3
// The word "SomeDescriptiveNotes" only stand for programmer read and will not influence any real behavior
/* Code blocks end */
2. @implementation : the body of a class
3. Instantiation :
1. MyClass *myCls = [[MyClass alloc] init];
2. MyClass *myCls = [[MyClass alloc] initWithSomeParameters];
3. MyClass *myCls = [MyClass new];
4. Protocol ==> C++ abstract class multiple inheritance or Java interface
5. Message forwarding
Implement a call passing behavior. When main send a message "Greeting" to ClassA, ClassA doesn't implement the message, and ClassB does, then ClassA can pass the "Greeting" message to ClassB without handling locally
6. Category
Behaving like inheritance, category adopt parent class's data, including private, and add/replace existing methods.
/* Code blocks begin */
@interface ParentClass (CategoryA) {
}
- CategoryA_method1;
- CategoryA_method2;
@end
/* Code blocks end */
The use of ParentClass with CategoryA can have CategoryA_method1 and CategoryA_method2 methods
7. Instance variable, property and synthesize
Use of property/synthesize ==> add special attribute(readonly/read-write/copy/assign/retain/atomic/nonatomic to instance variable
@interface ClassA : NSObject {
public:
int var1;
provate:
int var2;
}
@property (copy) int var1; // Declare var1 as "copy" attribute
@property (readonly) int var2; // Declare var2 as "readonly" attribute
/*** Note ***/
/* Copy, retain are reference to mutable subclass ? */
/* Copy : int x = 5; myClass.var1 = x; x = 10; var1 will be 5 */
/* Retain : int x = 5; myClass.var1 = x; x = 10; var1 will be 10 */
When synthesize a variable, it will generate "setter" and "getter" automatically
@synthesize var1;
/* Generate : void setVar1:(int)v1
int getVar1
*/
Used to declare a class. To declare a class MyClass inheriting MyParentClass, we can write
/* Code blocks begin */
@interface MyClass : MyParentClass {
}
+ ClassMethods:(type1)param1 :(type2)param2
- InstanceMethods:(type1)param1 :(type2)param2 SomeDescriptiveNotes:(type3)param3
// The word "SomeDescriptiveNotes" only stand for programmer read and will not influence any real behavior
/* Code blocks end */
2. @implementation : the body of a class
3. Instantiation :
1. MyClass *myCls = [[MyClass alloc] init];
2. MyClass *myCls = [[MyClass alloc] initWithSomeParameters];
3. MyClass *myCls = [MyClass new];
4. Protocol ==> C++ abstract class multiple inheritance or Java interface
5. Message forwarding
Implement a call passing behavior. When main send a message "Greeting" to ClassA, ClassA doesn't implement the message, and ClassB does, then ClassA can pass the "Greeting" message to ClassB without handling locally
6. Category
Behaving like inheritance, category adopt parent class's data, including private, and add/replace existing methods.
/* Code blocks begin */
@interface ParentClass (CategoryA) {
}
- CategoryA_method1;
- CategoryA_method2;
@end
/* Code blocks end */
The use of ParentClass with CategoryA can have CategoryA_method1 and CategoryA_method2 methods
7. Instance variable, property and synthesize
Use of property/synthesize ==> add special attribute(readonly/read-write/copy/assign/retain/atomic/nonatomic to instance variable
@interface ClassA : NSObject {
public:
int var1;
provate:
int var2;
}
@property (copy) int var1; // Declare var1 as "copy" attribute
@property (readonly) int var2; // Declare var2 as "readonly" attribute
/*** Note ***/
/* Copy, retain are reference to mutable subclass ? */
/* Copy : int x = 5; myClass.var1 = x; x = 10; var1 will be 5 */
/* Retain : int x = 5; myClass.var1 = x; x = 10; var1 will be 10 */
When synthesize a variable, it will generate "setter" and "getter" automatically
@synthesize var1;
/* Generate : void setVar1:(int)v1
int getVar1
*/
2011年8月8日 星期一
Android NDK 寫法和注意事項
1. 如果沒有做自定的 JNI export table, 預設的 export table 和 package name 以及 activity name 息息相關
package name : com.android.animal
activity name : DogActivity
native functions :
void funcA(void);
int funcB(int bin);
int[] funcC(int[] cin);
JNI export functions:
JNIEXPORT void JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj);
JNIEXPORT jint JNICALL
Java_com_android_animal_DogActivity_funcB
(JNIEnv * env, jobject obj, jint bin);
JNIEXPORT jintArray JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj, jintArray jarra);
2. array 可以轉換成 C pointer, 同時提供 array size
int *arra_ptr = (*env)->GetIntArrayElements(env, jarra, 0);
jsize sz = (*env)->GetArrayLength(env, jarra);
3. 重 build jni 之後, 必須要把 Android project clean & rebuild
package name : com.android.animal
activity name : DogActivity
native functions :
void funcA(void);
int funcB(int bin);
int[] funcC(int[] cin);
JNI export functions:
JNIEXPORT void JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj);
JNIEXPORT jint JNICALL
Java_com_android_animal_DogActivity_funcB
(JNIEnv * env, jobject obj, jint bin);
JNIEXPORT jintArray JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj, jintArray jarra);
2. array 可以轉換成 C pointer, 同時提供 array size
int *arra_ptr = (*env)->GetIntArrayElements(env, jarra, 0);
jsize sz = (*env)->GetArrayLength(env, jarra);
3. 重 build jni 之後, 必須要把 Android project clean & rebuild
Android Sensor
Android 手機上最特殊的, 就是無所不在的 sensors,透過這些 sensor, 我們可以創造和電腦不一樣的控制方式
Sensor基本的程式寫法
1. 支援 SensorEventListener
public class SensorTestActivity extends Activity implements SensorEventListener
2. 取得 sensor 的服務
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
這個服務, 會在 sensor 有資料的時候, 把資料傳給註冊的程式
**注意**
有些 sensor 會一直傳資料出來, 像是accelerator, magnetic, gyroscope
有些 sensor 會在有資料的時候才送, 像是 NFC
**不必再注意**
3. 註冊希望接受的 sensor event
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
4. 接收sensor event
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//Do what you need to do
}
}
Sensor基本的程式寫法
1. 支援 SensorEventListener
public class SensorTestActivity extends Activity implements SensorEventListener
2. 取得 sensor 的服務
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
這個服務, 會在 sensor 有資料的時候, 把資料傳給註冊的程式
**注意**
有些 sensor 會一直傳資料出來, 像是accelerator, magnetic, gyroscope
有些 sensor 會在有資料的時候才送, 像是 NFC
**不必再注意**
3. 註冊希望接受的 sensor event
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
4. 接收sensor event
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//Do what you need to do
}
}
2011年8月3日 星期三
Linux and tty terminal
Ubuntu 要怎樣跟 uart/com port 連呢
1. 用 moserial ---- under studying
2. 用 screen
screen /dev/ttyS0 115200,cs8,-ixon,-ixon,istrip
.screenrc
# kill startup message
startup_message off
# define a bigger scrollback, default is 100 lines
defscrollback 1024
# remap CTRL-A to CTRL-]
escape ^]]
# status bar
hardstatus on
hardstatus alwayslastline "%{rk}%H %{gk}%c %{yk}%M%d %{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw%?"
1. 用 moserial ---- under studying
2. 用 screen
screen /dev/ttyS0 115200,cs8,-ixon,-ixon,istrip
.screenrc
# kill startup message
startup_message off
# define a bigger scrollback, default is 100 lines
defscrollback 1024
# remap CTRL-A to CTRL-]
escape ^]]
# status bar
hardstatus on
hardstatus alwayslastline "%{rk}%H %{gk}%c %{yk}%M%d %{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw%?"
2011年8月2日 星期二
Handling multiple lines in shell script
Shell script is good to work with ASCII line contents. When considering multiple lines, it needs some techniques.
1. Use pipe and read
cat A_File_With_Lines.txt | {
while :; do
read line
work_with line
if [ line_condition_end ]; then
break
fi
done
}
** NITES **
Two issues :
a. line_condition_end is very very very important because the "EOF" read will cause the shell to exit running.
b. The variables inside the | { } scope can't be used outside the braces
2. Use for loop
for line_in_file in $(cat A_File_With_Lines.txt); do
work_with line
done
** NITES **
a. This method requires the "lines in the file" do not contain any white space, tab, and other special words which can't be directly processed in script.
b. Because of a, this method is specially good for handling "files list which generated by ls or find"
1. Use pipe and read
cat A_File_With_Lines.txt | {
while :; do
read line
work_with line
if [ line_condition_end ]; then
break
fi
done
}
** NITES **
Two issues :
a. line_condition_end is very very very important because the "EOF" read will cause the shell to exit running.
b. The variables inside the | { } scope can't be used outside the braces
2. Use for loop
for line_in_file in $(cat A_File_With_Lines.txt); do
work_with line
done
** NITES **
a. This method requires the "lines in the file" do not contain any white space, tab, and other special words which can't be directly processed in script.
b. Because of a, this method is specially good for handling "files list which generated by ls or find"
Notes to generate and apply patch files in Linux world
There are several types of generate/apply patches in linux world
1. basic diff/patch
generate : diff -Nur file1 file2 > file1_file2.patch
apply : under file1's folder, patch -p 0 < file1_file2.patch
************ NOTES ***********
a. patch -p n means ignore first n directory levels in file1_file2.patch file part.
b. patch can apply to svn/git patches
2. SVN diff/patch
generate : svn diff file1 > ~/file1_fixes.patch
apply : use 1(diff/patch) to apply patch
3. GIT diff/patch
generate : git diff file1
apply : git apply file1.patch
************ NOTES ***********
a. always do --stat and --check before applying a patch through git
git apply --stat file1.patch
git apply --check file1.patch
b. git am can use to replace git apply, with git am can give signoff option
git am --signoff < fix_empty_poster.patch
1. basic diff/patch
generate : diff -Nur file1 file2 > file1_file2.patch
apply : under file1's folder, patch -p 0 < file1_file2.patch
************ NOTES ***********
a. patch -p n means ignore first n directory levels in file1_file2.patch file part.
b. patch can apply to svn/git patches
2. SVN diff/patch
generate : svn diff file1 > ~/file1_fixes.patch
apply : use 1(diff/patch) to apply patch
3. GIT diff/patch
generate : git diff file1
apply : git apply file1.patch
************ NOTES ***********
a. always do --stat and --check before applying a patch through git
git apply --stat file1.patch
git apply --check file1.patch
b. git am can use to replace git apply, with git am can give signoff option
git am --signoff < fix_empty_poster.patch
2011年7月18日 星期一
initrd 怎麼做內容修改
解開 initrd.gz
gzip -dc /somepath/initrd.gz | cpio -id
產生 initrd.gz
find . | cpio --quiet --dereference -o -H newc | gzip -9 > /somepath/new-initrd.gz
gzip -dc /somepath/initrd.gz | cpio -id
產生 initrd.gz
find . | cpio --quiet --dereference -o -H newc | gzip -9 > /somepath/new-initrd.gz
2011年7月5日 星期二
Android SDK 1 - 在ubuntu 上安裝 java sdk
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6-jdk
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6-jdk
iPhone tethering package
sudo add-apt-repository ppa:pmcenery/ppa
sudo apt-get update
sudo apt-get install gvfs ipheth-utils usbmuxd
*** Added for Ubuntu 10.10 with iOS 5
sudo apt-get install ifuse
*** Added for x86-64 Ubuntu 11.10
sudo apt-get install libimobiledevice-utils
sudo apt-get update
sudo apt-get install gvfs ipheth-utils usbmuxd
*** Added for Ubuntu 10.10 with iOS 5
sudo apt-get install ifuse
*** Added for x86-64 Ubuntu 11.10
sudo apt-get install libimobiledevice-utils
Macbook pro triple boot , sec 1
After fighting for triple boot on Macbook pro, I found some small notes,
http://wiki.onmac.net/index.php/Triple_Boot_via_BootCamp
Reference to this document, we have 2 important parts to notice for
------------------------------------------------------------------------------------
1. Only allowed "3" partitions ( That is efi - OSX - Linux - Win, preciously )
2. Windows must be the "last" partition
------------------------------------------------------------------------------------
Such a strange setting..
http://wiki.onmac.net/index.php/Triple_Boot_via_BootCamp
Reference to this document, we have 2 important parts to notice for
------------------------------------------------------------------------------------
1. Only allowed "3" partitions ( That is efi - OSX - Linux - Win, preciously )
2. Windows must be the "last" partition
------------------------------------------------------------------------------------
Such a strange setting..
2011年7月4日 星期一
ubuntu 上的 dvd r/w/e 指令
Ubuntu 上的 DVD-RW 指令
1. 讀出 iso 檔
sudo dd if=/dev/cdrom of=cdrom.iso
sudo dd if=/dev/dvd of=dvd.iso
2. 燒錄 iso 檔
單一 session (DAO - disk at once)
wodim -v -dao speed=4 dev='/dev/cdrw' myimage.iso
多個 session (Multi-session TAO - track at once)
wodim -v -tao -multi speed=4 dev='/sda/scd0' myimage.iso
加上 -eject 可以做到燒完退出的動作
wodim -v -eject -dao speed=4 dev='/dev/cdrw' myimage.iso
3. 退出 cd
eject
1. 讀出 iso 檔
sudo dd if=/dev/cdrom of=cdrom.iso
sudo dd if=/dev/dvd of=dvd.iso
2. 燒錄 iso 檔
單一 session (DAO - disk at once)
wodim -v -dao speed=4 dev='/dev/cdrw' myimage.iso
多個 session (Multi-session TAO - track at once)
wodim -v -tao -multi speed=4 dev='/sda/scd0' myimage.iso
加上 -eject 可以做到燒完退出的動作
wodim -v -eject -dao speed=4 dev='/dev/cdrw' myimage.iso
3. 退出 cd
eject
訂閱:
意見 (Atom)