2014年1月8日 星期三

[Linux] 簡易的測試機 - Nginx + Codeigniter + PHP + MySQL + PhpMyAdmin @ Linode Ubuntu 12.04 TLS

有點久沒在 Linode 打滾了,記得...我的信用卡還因為 Linode 的事件花錢換了一張新的 Orz 這次著重在測試機,所以先偷懶不裝防火牆

更新系統:

$ apt-get update && apt-get upgrade && apt-get dist-upgrade

簡易管理員:

$ adduser userid
$ vim /etc/group
sudo:userid


更新 hostname (建議不要有 "-",過去的經驗是 Hadoop 會找不到機器):

$ vim /etc/hostname
$ hostname -F /etc/hostname
$ vim /etc/hosts
127.0.1.1 YourName


簡易資安管理:

$ apt-get install denyhosts
$ vim /etc/hosts.allow
# whilelist
sshd: MyIP : allow


設定開發環境:

$ apt-get install nginx php5-cli php5-fpm mysql-server phpmyadmin

$ nginx -v
nginx version: nginx/1.1.19
$ php -v
PHP 5.3.10-1ubuntu3.9 with Suhosin-Patch (cli) (built: Dec 12 2013 04:27:25)
$ php5-fpm -v
PHP 5.3.10-1ubuntu3.9 (fpm-fcgi) (built: Dec 12 2013 04:31:25)


設定 nginx + PHP + Codeigniter:

$ vim /etc/nginx/sites-available/default
server {
# …
index index.html index.htm index.php;
# …
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
 
                # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
        # http://wiki.nginx.org/Codeigniter
        location /ci_proj/ {
               index index.html index.htm index.php;
               try_files $uri $uri/ /ci_proj/index.php;
        }
# …
}
$ service nginx restart


設定 nginx + PHPMyAdmin:

$ ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www/phpmyadmin
$ sudo service php5-fpm restart


其中 /etc/phpmyadmin/config-db.php 有標記預設登入的帳蜜,當然,也可以用當初設定 mysql 的 root 登入,建議新增帳號後,把 root 登入關掉, 共有兩處:

$ vim /etc/phpmyadmin/config.inc.php
/* Authentication type */
$cfg['Servers'][$i]['AllowRoot'] = FALSE;


其他資料庫匯入:

$ mysql -u db_account -p -D db_name < db_backup.sql 

2014年1月1日 星期三

iOS 開發筆記 - 設定 UIButton 發動 Storyboard Segue 事件(performSegueWithIdentifier)

使用 Storyboard 處理多個 UIViewController 進行切換時,可以很簡單地透過按住 ctrl + 元件(如 UIButton),拖拉到指定的 UIViewController ,完成 UIViewController 切換工作。然而,有時希望按了元件後,做完一堆事才切換到指定的 UIViewController ,這時候就要稍微更改 Segue 發動的流程。

例如,目前共有 AUIViewController 跟 BUIViewController ,其中 AUIViewController 上頭有一個 AUIButton ,當點選完 AUIButton 時,做完一些要事,再切換到 BUIViewController。

開發上,在 Storyboard 上,先在 AUIViewController 點一下,並按住 AUIViewController + Ctrl 後(並非點 AUIButton),拉條線到 BUIViewController 上,以此建立一個 Storyboard Segue 叫做 "ChangeViewController",接著把 AUIButton 拉條線到 AUIViewController.m ,做個  IBAction ,代表點選 AUIButton 將發動的動作,剩下的程式碼:

AUIViewController:

- (IBAction)AUIButtonEvent:(id)sender {
// Step 1 : doing …

// Step N : fire a segue event
[self performSegueWithIdentifier:@"ChangeViewController" sender:sender];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"ChangeViewController"]) {
        UIViewController *target = segue.destinationViewController;
        if ([target isKindOfClass:[UINavigationController class]]) {
            target = [[(UINavigationController *)target viewControllers] lastObject];
        }
        if([target isKindOfClass:[BUIViewController class]]) {
            BUIViewController *v = (BUIViewController *)target;
            // … other setting …
        }
    }
}


如此一來,當點選 UIButton 時,可以先做完事再切過去指定的 UIViewController 了,當然,也可以讓一個 UIButton 依照事件條件,切換到多個 UIViewController 。

2013年12月15日 星期日

iOS 開發筆記 - UITableViewController Editing Mode 隱藏 Delete 按鈕(Move Only)

UITableViewControllerEditMode

開始把玩 UITableViewController Editing mode,由於不想讓使用者刪資料,所以就需要把 Delete 相關的操作介面給關掉。

簡言之:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //if (self.editing)
    //    return UITableViewCellEditingStyleDelete;
 
    return UITableViewCellEditingStyleNone;
}


如此一來即可:

UITableViewControllerEditModeWithoutDeletition

2013年12月14日 星期六

免費導航王 - 台灣版小米機可免費使用勤崴導航王 android app 一整年

導航王小米版

半年前幫家人添購一台小米2S,最近我自己也用了一台,然後莫名又有一台紅米。當我徜徉於紅米的高 CP 時,看到台灣小米機又可以免費用「導航王」!有更賺到的感覺!(台灣版小米2S或紅米都可以使用)

紅米機的性能的確已經非常夠用,特別適用那些常用來打電話,但偶爾又想透過手持裝置獲得瀏覽網頁資訊的人。有了免費的導航王後,紅米又可以變身為導航車機啦!

詳情請參閱:歡慶【導航王】成為小米台灣獨家導航軟體合作夥伴!

用法:

  1. 從 勤崴官網 下載專屬於台版小米機的 導航王 app (NaviKing_Android_XiaoMi_WXGA_2.134.0.116.apk)
  2. 透過 USB 傳輸線,把下載好的 NaviKing_Android_XiaoMi_WXGA_2.134.0.116.apk 擺在小米機上,如 Download 資料夾
  3. 使用小米機內建檔案管理,開啓 NaviKing_Android_XiaoMi_WXGA_2.134.0.116.apk 即可進行安裝
  4. 安裝完導航王後,啟動後再下載圖資
  5. 一切安裝完後,重新啟動導航王即可

此外,試用了導航王後,發現他已經把一些常用的旅遊、生活類功能都做進去了!不見得要把它當行車導航的 app :

導航王小米版1

導航王小米版2

導航王小米版3

導航王小米版4

導航王小米版5

2013年12月11日 星期三

紅米機開箱文

紅米開箱

不知不覺手邊就多了這隻,預計要拿來送給長輩使用的 XD 其次是當開發機。

用紅米玩一下 Candy Crush 時,發現寶石落下時會 lag ?! 有擔心一下,但是改玩 Angry Birds 倒還好,其他拍照的顏色也還滿鮮豔的。整體上品質還挺不錯的,螢幕尺寸大也挺顧眼睛的,紅米顯而易見的缺點是內建儲存容量僅4GB,可以用的可能只有2GB,還好可以加microSD來使用。

剛好手邊有小米2S就順便比一下吧!(左邊小米2S,右邊紅米)


紅米與小米2s大小差異2

紅米與小米2s大小差異

小米2s和紅米

紅米與小米2s大小差異3

試用完紅米後,我還是喜歡小米2S的尺寸 XDD 但如果是愛帶包包的人,或許就沒差別了。