2013年11月13日 星期三

[Linux] Ubuntu 12.04的下載來源

若是預設的下載來源會讓平時apt-get install下載時找不到檔案
那麼可以將下載來源換成以下
修改/etc/apt/source.list
#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ dists/precise/main/binary-i386/

#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ dists/precise/restricted/binary-i386/
#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ precise main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise universe
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise multiverse
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu precise-security main restricted
deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe
deb http://security.ubuntu.com/ubuntu precise-security multiverse
deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu precise partner
# deb-src http://archive.canonical.com/ubuntu precise partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu precise main
deb-src http://extras.ubuntu.com/ubuntu precise main


2013年11月1日 星期五

[Android][Example] 用SoundPool控制左右聲道

如果需要控制左右聲道的音量,SoundPool有提供這個功能
SoundPool的優點是可以同時撥好幾個音檔
但卻對音檔的大小有限制
因此只適合撥較短的音檔

以下範例UI會有左右聲道的播放及停止按鈕





activity_main.xml


    

        

        

    

        

        



MainActivity.java
package com.qn.leftrightsound;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private String TAG = "leftrightsound";
    private SoundPool soundPool;
    private Button button_left_play, button_left_pause, button_right_play, button_right_pause;
    private int music_left, music_right;
    private int music_left_temp, music_right_temp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
        music_left = soundPool.load(this, R.raw.left_sound, 1);
        music_right = soundPool.load(this, R.raw.right_sound, 1);
        // 音樂檔案放在res/raw底下,預設沒有raw資料夾,要自己建

        button_left_play = (Button) findViewById(R.id.button_left_play);
        button_left_pause = (Button) findViewById(R.id.button_left_pause);
        button_right_play = (Button) findViewById(R.id.button_right_play);
        button_right_pause = (Button) findViewById(R.id.button_right_pause);

        button_left_play.setOnClickListener(ButtonListner);
        button_left_pause.setOnClickListener(ButtonListner);
        button_right_play.setOnClickListener(ButtonListner);
        button_right_pause.setOnClickListener(ButtonListner);
    }

    private Button.OnClickListener ButtonListner = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.button_left_play:
                Log.i(TAG, "press left play");
                music_left_temp = soundPool.play(music_left, 1, 1, 0, 0, 1);
                // 由於每次播放的id會不同,為考慮到按下暫停是要暫停剛剛播放的,因此將每次播放的id存起來
                // play()
                // 第一參數為音檔id
                // 第二.三參數為左右聲道的音量,range = 0.0 to 1.0
                // 第四參數為優先權,若不需設定可都設為0,0為最小優先權
                // 第五參數為loop,0 = no loop, -1 = loop forever
                // 第六參數為速度,1.0 = normal playback, range 0.5 to 2.0
                break;
            case R.id.button_left_pause:
                Log.i(TAG, "press left pause");
                soundPool.stop(music_left_temp);
                 break;
            case R.id.button_right_play:
                Log.i(TAG, "press right play");
                music_right_temp = soundPool.play(music_right, 0, 1, 0, 0, 1);
                break;
            case R.id.button_right_pause:
                Log.i(TAG, "press right pause");
                soundPool.stop(music_right_temp);
                break;
            }
        }
    };

    @Override
    protected void onDestroy() {
        this.soundPool.release();
         super.onPause();
    }

}

2013年10月21日 星期一

[Batch] call的用法,call與goto的差別

call可用在執行其他batch檔
也可以執行寫好的function(在batch稱為label)

Ex1:
ECHO CALL example1
CALL test1.bat

Ex2:
ECHO CALL example2
CALL :test2

:test2
ECHO This is test2


goto也可以執行寫好的function
但call與goto兩者最大差別為
call跳到label後,執行完label中的程式碼,會跳回call之後的程式碼
但goto跳到label後,並不會跳回來

此外
call後面可接傳入function的參數

Ex3:
ECHO CALL example3
CALL :test3 100

:test3
ECHO This is test3
ECHO %1%



refs: http://ccd9527.blogspot.tw/2010/11/bat-call-06.html

2013年10月4日 星期五

[Linux] 製作patch;打patch

1. 製作patch
使用linux的diff指令,diff舊檔案及新檔案的差別,並輸出成.patch
$ diff -Naur [old_file] [new_file] > [patch_name].patch

2. 打patch
使用linux的patch指令,將patch內容更新舊檔案
$ patch -p0 < [patch_name].patch
將檔案復原
$ patch -R -p0 < [patch_name].patch

2013年10月3日 星期四

[Linux] 計算資料夾或檔案大小

計算資料夾或檔案大小
後面可以接資料夾或檔案,否則則為當下資料夾
$ du -h

[Android] 檢查apk sign的key

與sign key一樣使用java的指令 -- jarsigner

$ jarsigner -verify -verbose -certs [apk_name]

會列出來像是以下的資訊
sm      3512 Mon Apr 15 00:13:32 CST 2013 AndroidManifest.xml

      X.509, CN=Android Debug, O=Android, C=US
      [certificate is valid from 2013/4/14 下午 3:10 to 2043/4/7 下午 3:10]

sm      5937 Sun Apr 14 15:09:46 CST 2013 res/drawable-xhdpi/ic_launcher.png

      X.509, CN=Android Debug, O=Android, C=US
      [certificate is valid from 2013/4/14 下午 3:10 to 2043/4/7 下午 3:10]

如果用Android test key sign過的apk結果會長這樣
sm      3875 Wed Apr 16 07:40:50 CST 2008 res/drawable-hdpi/rbt_icon.png

      X.509, EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
      [certificate is valid from 2008/4/16 上午 6:40 to 2035/9/2 上午 6:40]

sm      1765 Wed Apr 16 07:40:50 CST 2008 res/drawable-ldpi/rbt_icon.png

      X.509, EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
      [certificate is valid from 2008/4/16 上午 6:40 to 2035/9/2 上午 6:40]

可以藉此得知apk是用哪一把key sign的

refs:http://www.cnblogs.com/not-code/archive/2011/05/15/2047057.html

2013年9月23日 星期一

2013年9月13日 星期五

[Gerrit][Git] 新增/刪除Branch

1). 在local端新增branch並切換

1.1). 新增branch,再切換到該branch
$ git branch [branch_name]
$ git checkout [branch_name]

1.2). 新增branch並直接切換到該branch
$ git checkout -b [branch_name]

1.2). 以某個tag為基準,新增branch並直接切換到該branch
$ git checkout [tag_name] -b [branch_name]


2). 在remote端新增branch
$ git push origin [local_branch_name]:[remote_branch_name]

3). 在local端刪除branch (-D為強制)
$ git branch -d [branch_name]
$ git branch -D [branch_name]

4). 在remote端刪除branch
$ git push origin :[branch_name]

※在Gerrit要刪除remote端的branch
在push的權限中,必須增加force push才能夠刪除

※新增branch
git branch [branch_name] [base_on_which_branch]
若是[base_on_which_branch]沒有寫,預設是master
若是此git沒有master branch,則後面沒寫會無法新增branch

2013年9月4日 星期三

[Gerrit] [Git] [Repo] 新增/刪除tag

1). 在local端新增tag
$ git tag -a [tag_name] [commit_id]

2). 在remote端新增tag
$ git push origin [tag_name]
$ git push origin --tag (一次將所有tag push上去)

3). 在local端刪除tag
 $ git tag -d [tag_name]

4). 在remote端刪除tag
$ git push origin :refs/tags/[tag_name]

//======================================

9/4新增repo的部份
在repo codebase之下的用法

1). 在local端新增tag
$ repo forall -c 'git tag [tag_name]'

2). 在remote端新增tag
$ repo forall -c 'git push --tags'

3). 在local端刪除tag
$ repo forall -c 'git tag -d [tag_name]'

4). 在remote端刪除tag(需取得gerrit權限,目前沒嘗試過)
$ repo forall -c 'git push origin :refs/tags/[tag_name]'

[Gerrit] 在Gerrit網頁上加客製化修改

Gerrit網頁上方有能夠讓使用者客製化的區域
可藉由修改html檔,加上想要客製化的內容
請在放置gerrit的目錄底下的etc中增加GerritSiteHeader.html檔案
/home/gerrit/review_site/etc/GerritSiteHeader.html

內容請用<pre></pre>夾起來
example:
<pre>
Hello
World
</pre>

區域為底下圖片底色紅色的部份