2009年10月26日 星期一

[2009-10-26-1] Git - download AOSP on Linux ( Ubuntu 9.04 Desktop )

因著Android才慢慢發現GNU的世界真的和Windows的不太一樣,該這麼說呢! 或許就是新鮮吧!抱著這樣求知及冒險的態度,慢慢的也就習慣Linux的野性。

Git(System): 是一個version conrol的系統,方便local端做branching, commints(上傳修改), diffs(比對修改)以及 edits(編寫)。
Repo(Tool): 是一個可以讓你更容易下載/上傳AOSP的工具, repo的指令是用Python script寫成。所以,抓AOSP我們會用repo 來完成。

Step1: 環境套件安裝(32-bit x86)
$ sudo apt-get install git-core gnupg sun-java5-jdk\
flex bison gperf libsdl1.2-dev libesd0-dev zip curl\
libwxgtk2.6-dev build-essential gawk expect gettext\
zlib1g-dev valgrind libreadline5-dev libncurses5-dev

Step2: 安裝Repo
$ cd ~  #到home目錄
$ mkdir bin  #產生bin目錄
$ echo $PATH #確定bin有在PATH中
$ curl http://android.git.kernel.org/repo >~/bin/repo  #抓檔案並存到repo file
$ chmod a+x ~/bin/repo #設成可執行權限

Step3: 初始Repo
$ mkdir mydroid   #產生mydroid目錄
$ cd mydroid #到mydroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git
在初始成功"repo initialized in /mydroid"之前,會要求填入真實姓名/email(若要和Google溝通則填寫,一般是不用寫的)。另外若有改寫manifest.xml, 發現是不會覆寫舊的manifest.xml

Step3: 下載AOSP
$ repo sync

Step4: 建code
$ cd ~/mydroid
$ make  

[參考]
[1] AOSP - get source

2009年10月25日 星期日

[2009-10-25-7] Git - download AOSP on Windows

嘗試把在linux下抓到的AOSP放到windows,看來有些檔案(權限)無法copy。真不方便,還好有[1]的方法,才可以在winodws一窺AOSP的秘密。
下列是我的方法:
Step1: 下載 msysGit-netinstall-1.6.4-preview20090730.exe
Step2: 執行/安裝後,選Git Bash,如[1]提到的會出現git shell
Step3:
$mkdir raydroid
Step4: 下載getcode.bat到raydroid, 其中裡面所有的repository(程式下載點)來自於[3]
Step5:
$ getcode.bat
如果是第一次,就靜靜等待把code 抓完吧!若不是就判斷一下要不要保留or刪除重抓囉!!

[參考]
[1] ysl的程式天堂 - 如何在Windows平台上下載Android的原始碼?
[2] msysgit - Git on Windows
[3] anDROID open source project

2009年10月23日 星期五

Download - source code

2009-10-23-5

本想說把source code 放到[1], 若是想要用的時候把它剪下/貼上就可以。事與願違,網頁的"空白"及"tab"鍵也就是文檔的縮排不同設定,導致程式無法正常執行如Python,所以就只好把source code 放到這兒。方便使用~

DOWNLOAD Here
檔案包括lottery, lottery.c, lottery.o, Mackfile

DOWNLOAD Here
檔案包括.vimrc, broadcast.sh, ray.env.sh, ray.py, ray.sh, ray.vim-em

$ tar -jcv -f notes.tar.bz2  notes  #壓縮打包
$ tar -jtv -f notes.tar.bz2  #查詢內容物
$ tar -jxv -f notes.tar.bz2 -C notes  #解壓到notes這個目錄

[參考]
[1] 高登工作室 - 在Blogger文章中插入程式
[2] 鳥哥 - 打包指令

2009年10月22日 星期四

[2009-10-22-4] Python - 6/49大樂透

#!/usr/bin/env python
# -*- coding: UTF-8 -*-


#file name: ray.py
#2009-10-16, RayZ, demo cases/notes using python
#第二行是用來寫中文註解

#this file can be execution if the first row has #!/usr/bin/env python. usage is 
#chomd 770 ray.py
#./ray.py
# or using $ python ray.py in command line (it is txt file)

# look for Python's built in functions using Python command line
# >>> import __builtin__
# >>> dir(__builtin__)

def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while 1:
        ok = raw_input(prompt) 
        if ok in ('y', 'ye', 'yes'): return 1
        if ok in ('n', 'no', 'nop', 'nope'): return 0
        retries = retries - 1
        if retries < 0: raise IOError, 'refusenik user'
        print complaint    
    
def f91(a, l = []):
    l.append(a)
    return l
def f92(a, l = None):
    if l is None:
        l = []
    l.append(a)
    return l


while 1: 
    Title = "\n\
    Example 10: 避開共用值\n\
    Example 9: 6/49大樂透\n\
    Example 8: function repeat\n\
    Example 7: 質數for loop's else\n\
    Example 6: range\n\
    Example 5: 費氏數列\n\
    Example 4: 字串\n\
    Example 3: if\n\
    Example 2: if\n\
    Example 1: Hello\n\
    0:Quit\n\
    Please enter a number: "
    setNo = int(raw_input(Title))
    print "\n"

    if setNo == 10:
        print "function point", f91, f92
        print "第一次呼叫 f91(5)=", f91(5), ",f92(1)=", f92(1)
        print "第二次呼叫 f91(6)=", f91(6), ",f92(2)=", f92(2)
        print "第三次呼叫 f91(7)=", f91(7), ",f92(3)=", f92(3)
        
    elif setNo == 9:
        import random
        l = []
        for n in range(-1,5):  # 5 - (-1) 個
            l.append(random.randint(1,49))
        print l
    
    elif setNo == 8:
        ask_ok('Do you really want to quit?')
        ask_ok('Ok, to overwrite the file?', 10)
       
    elif setNo == 7:
        for n in range(2, 10):
            for x in range(2, n):
                if n % x == 0:
        print n, 'equals', x, '*', n/x
        break
     else: # for's else, # special usage
         print n, 'is a prime number'

    elif setNo == 6:
        a = ['Mary', 'had', 'a', 'little', 'lamb']
        for i in range(0, len(a), 2):
            print i, a[i]
    elif setNo == 5:
        a, b = 0, 1
        while b < 10:
            print b, 
            a, b = b, a + b
        print "\n"
        
    elif setNo == 4:
        x = y = z = 0 
        print "x =";x
        print "x =",x
        word='Hel'+'p '
        print word*5

    elif setNo == 3:
        x = int(raw_input("Please enter a number: "))
        if x<0:
            x = 0
            print "Negative changed to zero"
        elif x==0:
            print "Zero"
        elif x==1:
            print "Single"
        else:
            print "More"

    elif setNo == 2:
        a = 5
        b = 5.5
        if b > a:
            print "b is more than a !\n"
        else:
            print "b is less than a !\n"

    elif setNo == 1:
        print "This is Python -- Hello.world!"
        print ("Hello.world!\n")

    elif setNo == 0:
        print "Quit Example"
        break

    else:
        print "Please enter a number(0~8)\n"

[參考]
[1] Python 教學文件
[2] 隨機數與隨機字符串
[3] PythonDOC

[2009-10-22-4] Shell scripts - 6/49大樂透

#!/bin/bash
#file name: ray.sh
#2009-10-09, RayZ, demo cases/notes using bash

#第一行可以讓這個file變成執行檔,方法是
#chomd 770 ray.sh
#./ray.sh 
# or 是一般文字檔就必須sh ray.sh

#--------------以下是手動在 bash 下執行

#0 若發生奇怪的錯誤可能是bash 被換成 dash
#$    sudo dpkg-reconfigure dash  (answer no)
       # or sudo rm /bin/sh   sudo ln -s /bin/bash /bin/sh
       # see more information: wiki.ubuntu.com/DashAsBinSh

#1 變數
#$   ws=~/Desktop/test_shell_script
#$   cd $ws

#2 化名/取消化名
#$   alias lm='ls -al |more'
#$   lm
#$   unalias lm
#$   alias cls='clear'
#$   alias dir='ls -l'
#$   alias gogogo='sudo apt-get install'
#$   alias raywork='~/Desktop/test_shell_script'

#3 直接看
#$   cat ray.sh

#4 指令搜尋的順序
#$   type -a ls

#5 壓縮/解壓縮, 打包
#$   bzip2 -k-z ray.sh   #保留原檔並壓成ray.sh.bz2
#$   bzip2 -k-d ray.sh.bz2    #保留原檔並解壓成ray.sh
#$   unzip NERD_tree.zip  #解壓
#$   unzip -l NERD_tree.zip #看壓縮檔案內容
#$   unzip -c NERD_tree.zip #看壓縮說明檔
#$   tar -jcv -f filename.tar.bz2  dirname  #壓縮打包
#$   tar -jtv -f filename.tar.bz2  #查詢內容物
#$   tar -jxv -f filename.tar.bz2  -C  dirname   #解壓到dirname

#6 斷字元的改變
#$   dos2unix -k ray_dos.sh  # ^M$ 改成$
#$   unix2dos -k ray_unix.sh # $ 改成 ^M$
#$   dos2unix -kn ray_dos.sh ray_unix.sh  #保留原檔,新檔為ray_unix.sh

#7 歷史記錄
#$   history
#$   !22   #選第22個

#8 用source 來執行檔案/腳本,就可以執行於父程序中
#$   source ray.env.sh


#9 找檔案,建議是先換成root來找. 
#$   find / -name "ray.sh" | less
#$   fine / -type d -name ".vim" | less # 找目錄
#$   su

#10 改變user登入
#    su

#11 改變檔案權限
#    chmod 770 ray.sh   


#--------------以下是bash file
#需要在 bash 下執行
#ex: vadmin@vadmin:~$ sh ray.sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
#把自定變數轉成環境變數
export PATH    

 
s1='demo case No. (1~10)'
echo -e "\n\n1) 在bash中輸入名字並印出全名 \
         \n2) 6/49大樂透 \
         \nq/Q) Exit \
         \n"
read -p "Select $s1: " democase


function exitfun(){
if [ "$democase" == "q" ] || [ "$democase" == "Q" ]; then
        echo -e "\nExit OK"
        exit 0
else
        echo " Error!! choose $s1 "
fi
}

case $democase in
     "1")
 #在bash中輸入名字並印出全名
 read -p "Please input your first name:  " firstname
 read -p "Please input your last name:   " lastname
 echo -e "\nYour full name is: $firstname $lastname "
 ;;
     "2")
        #RANDOM: 0~32767
        #6/49大樂透
        i=0
        while [ "$i" != "7" ]
        do
          i=$(($i+1))
          declare -i nu=$RANDOM*49/32768+1
          echo -n "$nu "          
        done                     
 ;;     
     *)
        exitfun;        
 ;;
esac

sh ray.sh


[參考]
[1] 鳥哥 - 學習Shell Scripts
[2] 鳥哥 - 如何改變檔案屬性與權限

[2009-10-22-4] Emacs - 常用指令


M-x switch-to-buffer #1 切換buffer
M-x rename-buffer #2 改變buffer name
M-x shell #3 開啟一個shell

Vim - 常用指令


:set nu #1 顯示行號
:open [filename] #2 打開檔案
:files #3 看開了那些檔案
:n #4 編下個檔
:N #5 編上個檔
:sp [filename] #6 分割視窗
ctrl+w+(up-key) #7 切換到上視窗
:w! #8 強制寫入
:wq #9 寫入離開
yy #10 複製行
dd #11 刪除行
p #12 貼上
gg #13 到首行
G #14 到最後一行


[參考]
[1] vi指令說明完整版
[2] 鳥哥的Linux私房菜