2012年9月26日 星期三

[MySQL] Manual

Download location

2012年9月21日 星期五

[PHP] primitive data structure--array


  1. 皆為 key-value pair, 預設 key仍為 0, 1, ...
  2. 可以用字串作為 key
  3. 利用 => assign key-value pair, e.g. $array= array("first"=>1, "second"=>2, "third"=>3);
  4. 利用 unset移除元素, 移除後 key(index)不變, e.g.本來是 [0]=> "iii", [1]=>"jjj", [2]=>"kkk", [3]=> "fff"經過 unset($array[2]) 會變成  [0]=> "iii", [1]=>"jjj", [3]=> "fff"
  5. 刪除整個陣列, unset($array)即可
  6. array中 index的順序與加入的順序有關. 先加 [1], [3], [5]再加[2], [4], [6], 則陣列中的順序即為 [1], [3], [5], [2], [4], [6](想成全部都是 key, not index就很好理解了)
  7. array中各元素可以是不同 type
  8. 可以用 array建立多維槽狀 array
  9. 常用 API
    1. bool in_array()
    2. array explode(string separator, string subject): 用 separator將 string 變成 array
    3. string implode(string glue, array pieces): 用 glue將 array中每個元素以 glue隔開形成一個 string

[PHP] PHP的類別與物件


  1. 宣告方式
    1. 關鍵字為 class, 尾端不用分號
    2. member data需加關鍵字 var, e.g. var $unit = 0;
    3. member function需加關鍵字 function, e.g. function add(){}
    4. function 不用寫 return type
  2. 建立物件
    1. 以 new建立, 但不需 (), e.g. $bottle = new UnitCounter; // UnitCounter為 class, 建立好 instance後, assign給 $bottle變數
  3. 存取物件
    1. class name沒有大小寫之分
    2. 以 -> 存取 member data與 member function, e.g. $bottle->unit, $bottle->add()其中 $unit為 class UnitCounter的 member data, 而 add()為其 member function
    3. member function中以 $this->unit, $this->add()呼叫其 member data or function
  4. 建構與解構
    1. 建構式為 function __construct() 或與 class同名的 function, 不過一般建議使用 __construct()以便於搬移類別 (P.S. 此為 PHP 5之後才支援的功能), 另外, __construct()可帶參數建構成員變數.
    2. 解構式為 function __destruct(), 不可帶參數. 通常用於關閉資料庫的連結. 另外, 有時候很好用, 例如:  擁有 static 變數為 static $nObj; 其在 construct就呼叫其 +1, 而 destruct則 -1, 則可以輕鬆維護該類所有 object個數
    3. 利用 unset()可摧毀物件
  5. 存取設定
    1. 預設皆為 public
    2. private: 
      1. 於變數或 function前加 private, 不能用 private: 來一次宣告一堆 private變數
    3. 同時也支援 protected
    4. static: 
      1. 與 C++相同, 同一類別共享 static變數.
      2. static function只能呼叫 static變數, 當然也不能呼叫 $this, 因為其並沒有建立物件
      3. static變數以類別參照方式呼叫, e.g. class Donation 擁有 static member $num, 則 member function 以 Donation::$num而非 $this->num來存取.
  6. 複製物件
    1. 建立新物件後, PHP 5回傳的是物件參照, 而不是物件本身(copy). 從下方可看出端倪. (假定 unitCounter擁有 $unit, 且 add($value)為 $unit=$unit+$value; 
    2. $a = new UnitCounter();
      
      $a->add(5);
      $b = $a;
      $b->add(5);
      
      print "number = {$a->$unit}"; //列出 number = 10
      
    3. 若要純粹複至某物件的副本, e.g. 就像複製資料庫一樣, 不止複製格式, 也複製目前的內容, 則使用 __clone()函數, 見下例
    4. $a = new UnitCounter();
      
      $a->add(5);
      $b = $a->__clone();
      $b->add(5);
      
      print "number = {$a->$unit}"; //列出 number = 5
      print "number = {$b->$unit}"; //列出 number = 10
      
  7. 繼承
    1. 關鍵字 extends
    2. 單一繼承
    3. 以 parent:: 呼叫父類別, e.g.  parent::__construct($parameter); 呼叫父建構子

2012年9月19日 星期三

[Mantis] 安裝與使用


  1. Requirements:
    1. Apache
    2. MySQL
    3. PHP: 5.3 up
    4. 前兩個沒寫主要是我用 Apache 2.2跟 MySQL 5.07並沒遇到啥問題, 反倒是 PHP 5.2.6被 argue了, 所以特別註明一下
  2. 基本安裝
    1. 下載
    2. 解壓縮並丟到 apache上執行該資料夾下 admin/install.php, 其快速安裝在其 doc/INSTALL, 詳細 document在 doc/lang中
    3. 過程中會幫你設定 MySQL, 若沒給定具有建 database權限的使用者, 將會有點 issue, 必須手動建立一下
    4. 安裝完執行 admin/check.php 看是否相容
      1. 一般就是 upload file的 size問題, 稍微改一下 php.ini的 upload_max_filesize應該就可以通過
    5. 移除 admin資料夾
  3. 更改預設帳號 (帳號: administrator/密碼: root)
    1. 以預設帳號登入後, 選擇 Manage-> Manage Users
    2. Create User並將其權限設為 Administrator
    3. 移除預設 administrator帳號
  4. 用 stmp發送信件(預設為 php.mail()), 底下以 gmail為例
    1. 開啟 mantis資料夾下\config_defaults_inc.php
    2. 修改參數
      1. $g_phpMailer_method= PHPMAILER_METHOD_SMTP;
      2. $g_smtp_host = 'smtp.gmail.com';
      3. $g_smtp_username = 'gmail帳號';
      4. $g_smtp_password = 'gmail密碼';
      5. $g_smtp_connection_mode = 'ssl';
      6. $g_smtp_port = 465;
    3. 搞定! (若還是不行, 可參考 Joomla Gmail設定中修改 php.ini)
  5. 開始使用
    1. 語言設定
      1. 若不習慣英文, 每個人可自行調整看到的介面
        1. My Profile->Preference->language調整即可
    2. 個人設定
      1. 我的帳號-> 基本資料->可以加入平常操作環境, 等回報 bug時選擇環境即可
    3. Manage Projects-> Create New Project
    4. 使用者管理
      1. 如果 config_defaults_inc.php設定 $g_enable_email_notification = ON (預設為 ON), 則使用者註冊需通過 email來建立帳號
    5. 回報問題

    6. Issue 生命週期與流程
      1. 建立 issue
      2. issue狀態
  6. Ref:
    1. 中文化問題
    2. Mantis操作說明
    3. Mantis安裝設定

[Software] 開發工具

其實開發輔助工具超級多的, 像是

  1. build chain 就有 configure工具、make工具
  2. IDE (Integrated Development environment) 就更不用說了, 萬萬種, e.g. Code Blocks, Visual Studio, XCode, etc.
  3. 版本控制: 有名的有 CVS, SVN, Git
  4. Bug Tracker: BugZilla, Mantis
  5. CI: jenkins
  6. Code review: gerrit
  7. Code formatter: AStyle (setting)

[PHP] 更新 PHP 5.2.6 到 5.3.5

以下為在 Windows底下更新 PHP 5.2.6到 5.3.5的過程記錄 (一開始 PHP 5.2.6以 Appserv安裝)
  1. download PHP VC6 x86 Thread Safe, Zip version (另有 Installer version, 可自行嘗試)--關於版本的問題, 下載頁面有詳細說明: Which version do I choose? 簡單說, 用 apache就是要用 VC6的版本...其實...5.3.5以後就找沒 VC6的版本了...完整 archive...若是用 apache的捧由...要碼就改用非官方版 Apache, 或是改用 IIS...
  2. 解壓縮假設到 C:\php
  3. 編輯 php.ini-development (或者直接 diff 原本 C:\Windows\php.ini 與 下載的package\php.ini-production)
    1. 更改 ; extension_dir ="ext" 為 extension_dir = "C:\php\ext"
    2. 比較一下 Windows\php.ini 已開啓的 extension(避免你以前哪些程式已經要求某些 extensions). e.g. extion=php_gd2.dll, ...
    3. timezone也可以設定一下
      1. data.timezone="Asia/Taipei"
    4. SMTP可自行設定, 若要利用 gmail發信的話, 可參考 利用 Gmail SMTP Server發信
    5. 設定 session存取位置
      1. session.save_path = "C:\php\SessionsTemp"
    6. upload path
      1. upload_tmp_dir = "C:\php\FIleuploadTemp"
    7. pear include path
      1. include_path=".;C:\php\pear", 如果還沒安裝, 可在安裝後再設定, 或是指向舊的 pear library, e.g. C:\AppServ\php\pear
    8. 可開啓 error log
      1. error_log = syslog改為 error_log = "C:\php\errorlog\error.log"
  4. 存檔後 copy到 C:\Windows\php.ini
  5. 讓 Apache server執行 php程式
    1. 修改 C:\AppServ\Apache2.2\conf\http.conf
    2. 加入
      1. LoadModule php5_module "C:/php/php5apache2_2.dll"
      2. 剩下應該原本 AppServ就設定好了
  6. Restart!
  7. Done! 記得 Windows7若是用 AppServ->Control Server by Service->Apache Restart要用管理者身份執行 (按右鍵)
  8. Ref: 在 Windows 7下安裝 PHP 5.3.5

2012年9月14日 星期五

[IE] 將 Windows 7上 IE 9降為 IE 8

最近因為當志工做翻譯, 需要測試網頁, 環境是 IE8, 不過在 Windows 7上若直接透過 Windows IE8安裝會失敗. 志工夥伴 Yi-Hsin提供了 Downgrade IE9 to IE 8的分享. 這邊就整理整理囉!

  1. 開啟控制台 
  2. 選擇 "程式和功能" 
  3. 選擇左手邊的 "檢視已安裝的更新" 
  4. 找到 Windows Internet Explorer 9 
  5. 解除安裝(需要重開機) 
  6. Done!

[Design] 好用的 Icon網站

NounProject

2012年9月12日 星期三

[Dropbox] Dropbox API


  1. 事前準備
    1. 必須申請 My apps的帳號
      1. 會給你一組 App name, key跟 secret
    2. 資料夾存取權限
      1. 某個與你 app同名的資料夾
      2. 完整 Dropbox資料夾
    3. 開發狀態
      1. 預設為 Development status
      2. 若要發佈為產品, 將其改為 Production status(在 My Apps頁面內), 則 Dropbox將會審核是否遵守規定
  2. SDK setup
    1. Development kits下載 SDK
    2. python
      1. 下載後 sudo python setup.py install
      2. example資料夾有許多 dropbox API範例, e.g. cli_client.py提供 command line interface (CLI)
      3. 要能跑的話, 主要就是設定 app_folder存取權限、app key跟 app secret
      4. 可以嘗試玩玩 cli_client, 試試撰寫後提供的界面, e.g. help, login, logout, ...
      5. SDK中的 dropbox資料夾為主要 library, 最主要可能可能用到的是 session.py (認證) 與 client.py (呼叫 API call)兩檔案, 若要自己實作 API call則更改 rest.py
    3. iOS
      1. run samples
        1. 下載 SDK後即擁有範例 project: DBRoulette, 可開啓 xcodeproj專案檔, 不過要更改 
          1. examples/DBRouletteAppDelegate.m中 application:didFinishLaunchingWithOptions方法中的 appKey, appSecret跟 root值, 注意, Root請參考其程式註解 kDBRootAppFolder或 kDBRootDropbox(整個 dropbox資料夾權限)
          2. DBRoulette-Info.plist的 APP_KEY這字串改為你的 app key
        2. 就可以看到完整範例程式啦~
      2. 加入自己的 project
        1. 將整個 DropboxSDK.framework資料夾 copy到自己的 project, 另外, 要加入 Security.framework與 QuartzCore.framework(在 target, Build Phases中的 Link Binary with Libraries用 + 來加入)
        2. 加入 Authentication

Ref: Dropbox for developers

2012年9月11日 星期二

[PHP] Regular Expression 正規表示法

Compiler 必學的 Regular Expression主要可以拿來比對 pattern。在網路爬蟲 (Crawler) 的世界就更不用說啦! 訓練好怎麼利用程式語言到茫茫大海找尋你要的東西, 這是必備的技能囉!

趁學 PHP複習一下!

  • 中介字元: . , 代表任何字元
  • 跳脫字元: \ , 用以跳脫指令, 也就是真的是用該符號, e.g. \. 真的要表示 . 那個符號
  • 字元類組: [] , e.g. came, come 可用 c[ao]me 來表示, 也可用 [0-9]表示 0到9的任一數字, 同理可使用 [a-z], [A-Z] 或混用 [a-zA-Z], 另外,  若在 [] 內第一字元加上 ^, 代表除這組以外, e.g. c[^ao]me, 代表除了 came, come以外, cxme的 x可被任何字元取代, 其餘時候 ^ 就代表該符號
  • 標位點: ^: 起始, $: 結束, e.g. '^to' 代表 to開始的字串, 'be$' 代表 be結束的字串. $var = "to be or not to be" 及滿足此兩表示法. 可一起用, 以比對整個字串. $match = ereg('^Yes$', "Yes sir"); // false, 此只比對 "Yes"
  • 比較 ^在字元類組與標位點的用法
    • $var = "1234567"
    • $match = ereg("^[0-9]", $var);  // true, 比對以數字為起始的字串
    • $match = ereg("[^0-9]", $var); // false, 比對時排除數字字元
  • 前面都只比較字元, 接著是字元的重覆性
    • ? : 0或 1次(optional)
    • +: 至少一次
    • *: 0或 1次以上
    • e.g. pe?p可以表示 pep, pp, 而 pe*p則表示 pp, pep, peep, peeep, peeeee...ep
    • {n}, n代表整數, 可用來指定樣式出現的次數
  • 集結 (group) : (), 用括號表示一個小群體, e.g. (abc)+ 代表可以 abc, abcabc, abcabcabc....
  • alternative: |, 其實就是 or, e.g. $pattern='(com$|net$|gov$)' 可識別 com或 net或 gov結尾的字串
  • 中介字元 (metacharacter): e.g. \t表示定位, \n: new line, \d: 任何數字, \s表示任何留白 (space), 還有一種特殊字元以 [: xxx :]包起來, 如: [:alnum:] 可用來檢查字母
注意事項:
  • 雙引號內用 \ , 必須用兩個。e.g. $found = ereg("\\.com", "www.google.com"); 代表找 .com 這個 pattern。第二個 \ 是因為表達實際的 . 要用 \. , 而第一個 \ 是在雙引號中表達 \ 要多加 \ , 若改用單引號可避免太混亂, e.g. ereg('\.com', "www.google.com");
實用 pattern:
  • YYYY-MM-DD => $pattern = '^([0-9]{4})-([0-9]{2})-([0-9]{2})$';
  • 以單格空白取代多於空白: ereg_replace("[[:space"]]+", " ", $source);
  • 用 DD/MM/YYYY取代 YYYY-MM-DD的時間格式: 
    • $pattern = '^([0-9]{4})-([0-9]{2})-([0-9]{2})$'; 
    • print ereg_replace($pattern, '\3/\2/\1', $value);    \i 代表參照的運算式

2012年9月10日 星期一

[Links] Fabrice Bellard

QEMU FFMPEG project創始人 Fabrice Bellard. 其個人網站(project頁面)相當簡潔明膫阿! 強者! 目前計算 PI的紀錄保持人!

其他關於 Fabrice Bellard的介紹: 計算的威力, 智慧的傳奇

[DirectDraw] Notes

參考資料: MSDN DirectDraw

定義

DirectDraw為一個特殊的記憶體管理員,提供 2-D存取 Windows Graphics Device Interface (GDI)的硬體加速, 個人覺得定義最好的是下面這段
DirectDraw is a low-level application programming interface (API) for graphics. It controls memory, the hardware blitter, and surface flipping operations. DirectDraw is a software interface that provides direct access to display devices while maintaining compatibility with the Windows Embedded CE graphics device interface (GDI).
何時該用 DirectDraw? 主要是以效能考量的時候, 為了提升 GDI速度的不足。
DirectDraw主要任務:
  1. 直接存取影像記憶體(video meory), 而不是系統記憶體(system memory)
  2. Page flipping
  3. Back buffering
  4. Clipping
相關專有名詞可參考 Graphics Concept. 架構圖如下:

介面

  1. Graphics Devices
    1. 定義: The device context is a structure containing information about the device.
  2. DirectDraw Objects: IDirectDraw
    1. 互動介面: Cooperative Level
    2. 一個 DirectDraw application可區分為兩類, 一種是視窗式 (windowed), 另一種為全螢幕式 (full-screen或 exclusive), 最大的差別在前者無法實現 page flipping, 後者則能避免其他應用程式存取 surfaces與畫圖於 primary display之上。
    3. Display Mode
      1. Primary Surfaces給 monitor的硬體設定值
      2. 主要為 dimension與 depth, e.g. 800*600 pixels and 8-bit/pixel
      3. 分為兩種: palettized與 non-palettized, 調色盤每個顏色是對應到一個 index value
      4. 重要 WinCE特性:
        1. DirectDraw cannot change the display mode.
      5. 呼叫  IDirectDraw::EnumDisplayModes 可查看硬體支援的 Display mode
    4. Singleton for process
      1. 對於每個 process, directdraw 是 singleton的, 若已經存在 instance, 則 call DirectDrawCreate 仍會回原本那個 instance.
  3. DirectDraw Surfaces: IDirectDrawSurface
    1. 定義: The DirectDrawSurface object represents a surface that usually resides in the display memory, but can exist in system memory if display memory is exhausted or if it is explicitly requested.
    2. 所有 surfaces都由 DirectDraw object來 create
    3. Blt
      1. 從 source 的 surface貼到 destination
      2. Blt會自動 scale且支援內插 (interpolation)
  4. DirectDraw Clippers: IDirectDrawClipper

程式

初始化程式, 其實就宣告 DirectDraw, DirectDraw的 Surface而已, 注意 Caps代表的是 capabilities, 也就是此實作 HAL (Hardware Abstract Layer)的 chip廠提供哪些 DirectDraw的功能。

#include <ddraw.h>

HRESULT hr;
IDirectDraw * pDD = NULL;
IDirectDrawSurface * pDDSPrimary = NULL;
DDSURFACEDESC ddsd;

hr = DirectDrawCreate(NULL, &pDD, NULL);
hr = pDD->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN);
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = pDD->CreateSurface(&ddsd, &pDDSPrimary, NULL);

細節:

  1. HEL (Hardware Emulation Layer) 僅提供 8, 16, 24, 32 bpp(bit per pixel)的 Surfaces。為了避免混用 HAL, HEL反而使效能降低,建議若有使用到硬體不支援的功能時,另外建立 system memory的 Surfaces來實作 (參考: Software Emulation)

2012年9月9日 星期日

[Graphic] Graphics Concepts

Blitting

Bit Block Transfer的縮寫。簡單說,blitting就是記憶體 copy的動作。把某塊 copy到另一塊去。

Flipping

flipping 在圖學的角度, 指的是畫面中部分簡單的變換, 藉由翻頁(個人覺得翻頁比翻轉好理解)來達成. 請想像漫畫快速翻頁形成動畫的效果。而 flipping就是這動作。由於翻頁的需求,常常會有 back buffer的機制,也就是準備好兩塊頁面, 在這兩塊間切換以形成動畫。

可參考 MSDN DirectDraw附的 Graphics Concepts, 其中還有 DIB, Surfaces與 rounding rectangle

[PHP] PHP特性

主要列出一些與 C或 C++較大的不同點, 以供參考
  1. 變數不用先宣告即可定義使用
  2. 參數傳遞的型別於傳遞時才決定
  3. 變數皆以 $開頭.
  4. isset()可以判別變數是否曾經定義
  5. 應該用 ===來檢查所有回傳值的比較 (既比較值也比較型別, 否則很容易有 false == 0的情形)
  6. include檔案或資料可使用 include or require, 差別在於錯誤的回報, require找不到會回報 fatal error

2012年9月8日 星期六

[TOEFL] 口說練習題

新托福 iBT口語黃金 80題

節錄前 5 題, 有興趣自行從上方連結參考吧!

  1. Describe a book that you believe is the most useful to you. Please explain the reason and include specific examples and details in your explanation. 
  2. Which of the following statements do your agree with? Please give specific reasons for your opinion. Some believe that TV programs have a positive influence on modern society. Others, however, think that the influence of TV programs is negative. 
  3. Describe the most important decision that you have made in your life. Why was it important to you? Use specific examples and details to support your explanation. 
  4. Some people believe that the high school should teach music and art as other basic science. Some people think that providing music and art education for high school students is not necessary. What is your opinion and why? 
  5. What do you do in your spare time? Please include specific details in your statement.

[PHP] debug 重複變數

由於 PHP就像 Matlab一樣, 在使用變數時, 是不需要事先宣告的. 所以有可能造成不小心重複使用了變數的情形. 在程式中的判斷其實可以簡單透過 isset($var)來確定是否曾經定義過變數, 另外, 也可以利用 var_dump($var) 來查看變數, 會 dump出資料結構及其值. 另外, 也可以用 print_r 來印出 array的內容.

[PHP] 筆記--php include path

PHP 使用關鍵字 include與 require來載入其他函式或相關程式碼. 功能皆為讀取外部檔案, 而差異的地方, 在於 include讀不到檔時會有 warning, 而 require則是 fatal error.

就像 C++會用 #ifndef 來避免 header file被重複 include, 而 PHP則有 include_once與 require_once兩種機制.

另外, 應該自己注意 php.ini中的 include path設定


;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

請依據自己的系統做調整, 注意 UNIX跟 Windows在路徑斜線的方向不同, 分隔符號也不同, 一個是分號一個是冒號.

2012年9月5日 星期三

[Entrepreneurs] 創業資源

青輔會線上課程

[Software] 軟體開發推薦書目


  1. Effective C++
  2. 軟體建構之道 Code Complete

[Stocks] 推薦書目


  1. 快攻類型:
    1. 3天搞懂股票買賣

[TOEFL] 推薦書目


  1. Cracking the TOEFL iBT
  2. 最重要的100個英文字首字根 許章真編

[Arduino] 簡介


[iOS] 中國的 iOS代碼庫

iOS代碼庫

[iOS] 遊戲開發引擎


  1. cocos2D
  2. Unity