星期三, 9月 18, 2013

2013IT鐵人賽-03-程式學習紀錄-git01-使用git與GitHub紀錄

2013IT鐵人賽-03-程式學習紀錄-git01-使用git與GitHub紀錄



今天的名稱很長, 所以我也趁機說明以下之後發表文章的命名方式


2013IT鐵人賽-03-程式學習紀錄-git01-使用git與GitHub紀錄
  • 2013IT鐵人賽 這個開頭是固定的.
  • -03 代表30天不中斷的第3篇.
  • 程式學習紀錄 這個部份應該只有前面在做學習準備才會出現的標題.
  • git01 這個部份就會代表學習的種類, git01 就是git 的第1篇, 也就是說有可能也會出現ruby01 或是 java01 這樣的命名.
  • 使用git與GitHub紀錄 則是此次文章的主要標題.



在有了隨時可以存取的開發作業環境 EasyCloud 之後, 接下來就會思考, 那自己撰寫的程式碼要如何儲存下來呢? 另外在學習git的時候如果不是自己的檔案, 一般來說在書上練習的都是建立 foo.txt 或是 bar.txt 這樣的練習檔案, 所以在實習上面是非常無感的.  所以這次在學習雜記的規劃上面就想把後續學習的程式碼都放在git上面.   之前有考慮dropbox, 可是dropbox 在client那邊都要裝程式. (咦? git 不是也要裝), 然後如果只是要練習程式, 在我們每使用一個VM就要同步 N個GB的檔案, 應該也受不了吧. ^—^


那如果要放在git上面, 接下來的考量點就是
  • 架設 git server
  • SSH with git
  • Dropbox with git
  • GitHub
  • 當然還有其他的方案......


這兩年都會聽到專案放在GitHub上面, 很多人在參考對方貢獻的時候也會看對方的GitHub, 所以這次的程式雜記就決定放在GitHub https://github.com/ 上面了.


記得在 2013IT鐵人賽-01-程式學習環境準備-EasyCloud 那篇我們有提到參考官方網站來建立虛擬機器 . (如果沒有記住..... 請往前翻吧 :p )


之後文章我所選用的都是 openSUSE 12.2 的版本.
請參考官方的說明(目前有VNC 或是 SSH 兩種模式連入) http://easycloud.nchc.org.tw/index.php/%E7%99%BB%E5%85%A5%E8%99%9B%E6%93%AC%E6%A9%9F%E5%99%A8 , 登入自己建立的VM.


請以 root 登入到主機, 或是透過 su - 來切換使用者身份.
以下的作法是使用command line 的方式來建立, 因為講求快速的關係, 使用圖形介面也可以達成同樣的效果.


Step 1: 安裝 git 套件


參考 GitHub 官方網頁的介紹


查詢是否有安裝 git 套件?  
命令提示字元前面的 # 代表是root 身份, 請協助確認, 另外只要輸入 # 之後的指令即可.


# zypper  search   git
正在載入套件庫資料...
讀取已安裝的套件...


S | 名稱                       | 摘要                                 | 類型    
--+----------------------------+--------------------------------------+---------
 | cgit                       | A web frontend for git repositories  | 套件    
 | cgit                       | A web frontend for git repositories  | src 套件
 | git                        | Fast, scalable, distributed revisi-> | 套件    


目前並沒有安裝 git 套件, 所以我們來安裝他.


# zypper   install  git
正在載入套件庫資料...
讀取已安裝的套件...
正在解決套件相依性...


將會安裝下列新的套件:
 cvs cvsps git git-core git-cvs git-email git-gui gitk git-svn git-web libapr1
 libapr-util1 libserf-1-0 perl-Authen-SASL perl-Clone perl-DBD-SQLite perl-DBI
 perl-Error perl-MLDBM perl-Net-Daemon perl-Net-SMTP-SSL perl-Params-Util
 perl-PlRPC perl-SQL-Statement subversion subversion-perl


下列推薦的套件已自動被選取:
 git-cvs git-email git-gui gitk git-svn git-web perl-Authen-SASL perl-Clone
 perl-MLDBM perl-Net-Daemon perl-Net-SMTP-SSL perl-PlRPC perl-SQL-Statement


下列套件是建議的,但將不會被安裝:
 git-daemon


26  新套件將被安裝.
全部下載大小: 8.3 MiB。 完成操作後,將增加 33.8 MiB 的使用。
要繼續嗎? [y/n/?] (y): y (請輸入y同意安裝)


確認是否有安裝


# zypper  search git
正在載入套件庫資料...
讀取已安裝的套件...


S | 名稱                       | 摘要                                 | 類型    
--+----------------------------+--------------------------------------+---------
 | cgit                       | A web frontend for git repositories  | 套件    
 | cgit                       | A web frontend for git repositories  | src 套件
i | git                        | Fast, scalable, distributed revisi-> | 套件    


接下來在安裝  git-daemon 套件, 如果以後要使用 Password Cache 機制, 避免出現以下錯誤
(error: cannot run git-credential-cache--daemon: No such file or directory  
fatal: unable to start cache daemon: No such file or directory)


# zypper  install  git-daemon
正在載入套件庫資料...
讀取已安裝的套件...
正在解決套件相依性...


將會安裝下列新的套件:
 git-daemon


1  新套件將被安裝.
全部下載大小: 358.1 KiB。 完成操作後,將增加 1.2 MiB 的使用。
要繼續嗎? [y/n/?] (y):  y


確認已經安裝 git 套件.接下來進行git的初始化動作.
首先可以先切換到要儲存 git 的目錄, 但是由於我是使用 VM 來進行練習, 我就直接放在家目錄底下了(使用 git 不一定要使用 root 身份).
還沒有初始化之前, 先觀察目前的目錄底下的物件.


# ls   -a
.              Desktop    .gstreamer-0.10   Music          Videos
..             Documents  .gtk-bookmarks    Pictures       .viminfo
.bash_history  Downloads  .ICEauthority     Public         .xauthJjBAGT
bin            .esd_auth  inst-sys          .pulse         .xsession-errors
.cache         .gconf     .kbd              .pulse-cookie  .xsession-errors.old
.config        .gnome2    .local            .rcc
.dbus          .gnupg     .mission-control  Templates


接下來我們來初始化 git (建立初始容器)
# git  init
Initialized empty Git repository in /root/.git/


再次觀察目錄下的物件, 會發現多了 .git 目錄
# ls   -a
.              Downloads        inst-sys          .rcc
..             .esd_auth        .kbd              Templates
.bash_history  .gconf           .local            Videos
bin            .git             .mission-control  .viminfo
.cache         .gnome2          Music             .xauthJjBAGT
.config        .gnupg           Pictures          .xsession-errors
.dbus          .gstreamer-0.10  Public            .xsession-errors.old
Desktop        .gtk-bookmarks   .pulse
Documents      .ICEauthority    .pulse-cookie


觀察 .git 目錄下的內容 (這個以後的章節在慢慢介紹以及研究)
# ls  -a  .git/
.  ..  branches  config  description  HEAD  hooks  info  objects  refs


目前先觀察 .git 目錄下的 config 檔案


# cat  .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true


在官方網頁的說明
Username
First you need to tell git your name, so that it can properly label the commits you make.


$git  config  --global   user.name   "Your Name Here"


這邊要注意的是在設定 git  config 的時候有下 --global 參數(這個部份後續再來討論)
  • 會存入 ~/.gitconfig 檔案
  • 以使用者為影響範圍


所以就進行以下的指令來設定(名字的部份請用英文, 避免用中文)
# git  config   --global   user.name  "你的名字"
觀察一下目錄以及相關的設定檔 (多了 ~/.gitconfig 但是 .git/config 沒有變動)


# ls -a
.              .config    .esd_auth   .gnupg           .kbd              Public         Videos
..             .dbus      .gconf      .gstreamer-0.10  .local            .pulse         .viminfo
.bash_history  Desktop    .git        .gtk-bookmarks   .mission-control  .pulse-cookie  .xauthJjBAGT
bin            Documents  .gitconfig  .ICEauthority    Music             .rcc           .xsession-errors
.cache         Downloads  .gnome2     inst-sys         Pictures          Templates      .xsession-errors.old


# cat   .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true


# cat  ~/.gitconfig
[user]
name = Max Huang


Email


Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.


$git  config --global  user.email  "your_email@example.com"


看了說明, 也就是這邊設定的e-mail 要跟 GitHub 上面的e-mail 相關連.


# git  config  --global  user.email  "你的電子郵件"


觀察相關設定
# cat  ~/.gitconfig
[user]
name = Max Huang
email = sakana@cycu.org.tw


Password caching


The last option we need to set will tell git that you don't want to type your username and password every time you talk to a remote server.
To use this option, you need to turn on the credential helper so that git will save your password in memory for some time:


$git   config --global   credential.helper   cache


這個部份就是如果不想每次使用的時候都輸入密碼就可以使用快取的機制


# git  config  --global  credential.helper  cache


# cat   ~/.gitconfig
[user]
name = Max Huang
email = sakana@cycu.org.tw
[credential]
helper = cache


也可以進一步設定快取的時間
By default git will cache your password for 15 minutes. You can change this if you like.


$git  config  --global credential.helper 'cache --timeout=3600'


那就來設定看看, 將快取時間調整為 1 小時
# git  config  --global  credential.helper  'cache  --timeout=3600'


# cat  ~/.gitconfig
[user]
name = Max Huang
email = sakana@cycu.org.tw
[credential]
helper = cache  --timeout=3600




Step 2: 註冊GitHub帳號


請上 GitHub 官方網站註冊帳號 https://github.com/
只要在網頁上面輸入
使用者帳號(會檢查是否有跟其他人重複)
E-mail
密碼
點選 Sign up for GitHub
就申請完成.....(甚至沒有 E-mail 驗證 XD )


Step 3: 建立 repo


接下來就可以按右上角的 Sign in 進行登入.
登入之後可以點選右上角或是畫面中間右邊的 New repository 按鈕



接下來輸入 Repository 的名稱, 在GitHub 內Public repo 是免費的, 我們就選public.
點選 Create repository 建立repository.



接下來就會產生一個自己的git
https://github.com/[帳號名稱]/[repo名稱]




依造相關指示建立 repo (之前我們已經先建立過 git  init 了)


建立  README.md
# touch  README.md


觀察相關目錄
# ls
bin  Desktop  Documents  Downloads  inst-sys  Music  Pictures  Public  README.md  Templates  Videos


將 README.md 加入 git
# git  add   README.md


執行 git commit (送交檔案)
# git  commit  -m  'first commit'
[master (root-commit) ecf4424] first  commit
0 files changed
create mode 100644 README.md


加入遠端GitHub
# git  remote  add  origin  https://github.com/sakanamax/2013ironman.git (這邊請用自己的 git 路徑)


觀察相關設定
# cat   .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/sakanamax/2013ironman.git
fetch = +refs/heads/*:refs/remotes/origin/*


將檔案 push  到遠端
# git  push  origin  master
Username for 'https://github.com': 請輸入你的帳號
Password for 'https://sakanamax@github.com': 請輸入你的密碼
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/sakanamax/2013ironman.git
* [new branch]      master -> master


再次觀察 GitHub 上面的repo


到這邊 git 以及 GitHub 上面的設定也暫時告一段落 :-)


Fun with Day 3 ~




星期二, 9月 17, 2013

2013IT鐵人賽-02-程式學習書籍選擇


2013IT鐵人賽-02-程式學習書籍選擇




準備了相關的程式學習環境, 接下來就是書籍的選用了.
有本容易入門的好書, 可以讓自己的學習事半功倍. :-)
就此次的學習列出自己的書單以及個人考量.

Java

Android

Ruby

Git

Raspberry Pi

Scratch

看完上面的書單, 就可以知道接下來每天應該都會有甜美的睡眠了.

Fun with Day 2 ~




星期一, 9月 16, 2013

2013IT鐵人賽-01-程式學習環境準備-EasyCloud

2013IT鐵人賽-01-程式學習環境準備-EasyCloud





這次的 2013 IT鐵人賽 http://ithelp.ithome.com.tw/ironman6/earlybird 報名了開發技術組
題目: “程式學習雜記
內容: 第一次挑戰鐵人賽, 希望可以紀錄30天學習程式的歷程. 預計學習 Java 以及 Android, 另外有可能把Ruby 也紀錄進來. 額外也想要紀錄自己開始學習 git 的相關過程. 以及使用 Raspberry PiScratch學習過程.


既然是要進行程式的學習, 首先就會想到程式學習環境的準備, 以及如何可以在不同的地方都可以隨時實習與學習.


程式學習的環境上面, 我選擇了國家高速網路中心的
EasyCloud 雲端簡單龍服務 ( http://easycloud.nchc.org.tw/ )
選擇原因為
  • 目前可以免費申請服務, 可以提出自己的需求申請VM.
  • 建立Linux 虛擬機器只要 1-2 分鐘. 不用擔心環境還原的問題.
  • 目前有提供 openSUSE / Ubuntu / CentOS 等常用的作業系統使用.
  • 以瀏覽器就可以使用 VNC 存取, 並支援 ssh 連線.


所以之後 Java 以及 Ruby 還有 git 的練習環境, 都會使用這個機制來進行, 至於Android 的開發環境, 由於要使用到虛擬裝置AVD, 會在本機來執行, 或是搭配手機來運作.   Raspberry PiScratch學習過程目前是考慮會放在一起.


所以今天這篇文章就是要進行 EasyCloud 雲端簡單龍的申請教學.


首先先連線到 EasyCloud 的首頁 http://easycloud.nchc.org.tw/




點選 用戶註冊




在看完詳細的條款內容之後, 點選 “同意” → 點選 Continue




接下來閱讀完個人資料蒐集同意書條款內容後, 點選 “同意” → 點選 Continue




在用戶申請的部份, 填入申請的電子郵件E-mail 以及申請人的姓名




並填入性別, 服務單位, 部門, 以及職稱. (如果是個人申請就填入個人即可)




接下來填入聯絡的手機以及地址, 這個部份比較重要的是EasyCloud使用期限, 因為要連續30天不中斷發文, 所以這個部份點選Other其他這個選項.



接下來在申請用途上面可以敘述為何要申請EasyCloud 雲端簡單龍的服務, 可以填入 2013IT鐵人賽參賽環境或是個人研究開發用途等申請的理由, 主辦單位會視申請的理由核發不同的虛擬主機數量. 並點選 Submit 送出申請.




接下來就是等待幾個工作天, 等待國網中心的E-mail通知, 即可以當初申請的電子郵件帳號以及國網中心設定的預設密碼. 登入到 http://capri.nchc.org.tw/ 雲端簡單龍 服務.



至於 如何登入以及如何建立虛擬機器則可以參考官方的教學文件




這樣開發的程式學習環境就先有個基底了 :-)


Fun with Day 1 ~


星期六, 8月 31, 2013

20130831學習 git 小記

20130831學習 git 小記

(也許有人會問, 為何要拍這張照片? 單純的是晚上寫blog 想拍照, 讓自己開心 :p )

慢慢覺得要學習 git 來進行一些相關運用, 目前很多的專案都是採取git 來進行.

google 搜尋到的官方網站
http://git-scm.com/

書籍的選用



之前有做一些學習, 也有參考google 上面的教學心得, 但是如果不是實際參與專案, 或是去上課(話說這方面會開課真的比較少)我想是不會真的撥出時間來學習的.

所以之後這方面的文章要紀錄自己如何學習 git 來讓自己以後複習方便 :-)

線上學習


想法上是搭配書籍練習, 效果應該不錯.


enjoy learning ~



20130829 Android 先修旁聽小記


20130829

張庭禎老師

上課檔案
  • Android 專案程式基本組成(2 Day).pdf
  • jdk-7u21-windows-x64.exe
    • 確認機器內有 java 環境, 如果沒有就裝 jdk
  • adt-bundle-windows-x86_64-20130717.zip

執行解開資料夾內的 adt-bundle-windows-x86_64-20130717\eclipse.exe

* 新增模擬裝置
在 eclipse 內
點選 Window → Android Virtual Device Manager



點選 New
輸入相關資訊 (AVD Name / 選取 Device / 輸入SD Card 大小)
點選 OK





選取剛剛建立的裝置
點選 Start → 點選 Lanuch


Notes:
  • package 在 java 以及 Android 代表的不同
    • java: folder
    • Android: 程式安裝進去的名稱(主索引)
  • uses-sdk: 使用的 Android 版本
    • 18: 4.3
    • 17: 4.2
    • 15: 4.0.3
    • 8:  2.2

* 建立 一個新的專案
File → New → Android Application Project


並輸入相關資訊
開啟專案資料夾下 src/com.example.app20130829/MainActivity.java




刪除以下區段
@Override
   public boolean onCreateOptionsMenu(Menu menu) {
       // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.main, menu);
       return true;
   }


觀察 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.app20130829"
   android:versionCode="1"
   android:versionName="1.0" >

   <uses-sdk
       android:minSdkVersion="8"
       android:targetSdkVersion="17" />

   <application
       android:allowBackup="true"
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@style/AppTheme" >
       <activity
           android:name="com.example.app20130829.MainActivity"
           android:label="@string/app_name" >
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>

</manifest>

有關於 @string/app_name
可以觀察 res/values/strings.xml


Resource Files
  • 檔案名稱必須使用英文小寫字, 不然會產生錯誤
  • drawalbe-hdpi 高解析圖片
  • drawalbe-ldpi 低解析圖片
  • drawalbe-mdpi 中解析圖片



嘗試執行程式
在專案上面按滑鼠右鍵  →  RunAs → Run Configurations
輸入名稱, 選取專案



Target 標籤點選 Always prompt to pick device


點選 Apply →  點選 Run
選取裝置 →  點選 OKLab: 修改App 的圖示

可以修改 AndroidManifest.xml 內的設定
在 Application 標籤內修改 Icon 的相關設定(可以點選 Browse, 然後 Create New Icon)


介紹三種程式的撰寫方式


-- Class End --

星期五, 8月 09, 2013

GUADEC 2013 小記 - 遇見 Andrea Veri


今年很開心可以參加 GUADEC 2013, open source 以及 freeware  的小圈圈是很小很美妙的(笑).

在還沒有參加GUADEC 之前, 我並不認識 Andrea Veri, 倒是常常在 mail list 上面看到他.  第一次看到他名字的時候是因為 nagios 的 jabber (google talk)整合
(http://www.dragonsreach.it/2012/02/18/nagios-xmpp-notifications-for-gtalk/), 他有一篇 blog 有提到這方面的實作. 我們跟自由軟體鑄造廠 OSSF 有很多工作坊的合作, 其中有部分是結合 openSUSE 以及 nagios 的實作.

實做筆記可以參考這篇 blog 其實也有寫了英文版的實作筆記

但是真的非常開心遇到Andrea Veri本人, 還讓他幫我很多的問題

能夠參加GUADEC 真是太好了

:-)



星期日, 8月 04, 2013

GNOME.Asia 報告於 GNOME基金會年度會議 AGM

這次很開心可以參加 GUADEC 2013
看這個照片應該是很開心吧(雖然讓我聯想到鬼太郎裡面的妖怪)


但是覺得很興奮, 因為可以代表 GNOME.Asia 在年度會議中報告 5分鐘

下面是我的簡報

還有影片檔


再次謝謝來參與的所有人
也謝謝GNOME 還有所有GNOME.Asia團隊還有韓國的團隊

:-)