2014年1月18日 星期六

iOS 開發筆記 - The app references non-public selectors in Payload/.app/: id

這次碰到的問題是使用 Facebook SDK 造成的 Orz 但很妙的事,一樣的 code 再 10 天前並沒有這個現象。

追了一下可能的問題是在於 Facebook SDK 的設計:

id<FBGraphUser> friend
id<FBGraphUserExtraFields> user


然後範例都教人使用:

user.id 或 [user id]

解法:

[user objectForKey:@"id"]

只要透過存取方式的修改,即可避開。

2014年1月12日 星期日

[Linux] Nginx + Auth + PHP + CodeIgniter @ Ubuntu 12.04

Nginx Authentication 可以參考官網 HttpAuthBasicModule / ngx_http_auth_basic_module 設定:

location ~^ /ci/  {
  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;
}


由於 nginx 用 apt-get 安裝,此例 htpasswd 則是位於 /etc/nginx/htpasswd ,若不確定的話,翻一下 nginx access/error logs 來看。

比較特別,如果保護的是一個 location 包含要運行 PHP 程式的話,裡頭需要把完整的 PHP 處理也定義好,據說是因為 nginx auth_basic module 不會繼續往下讀起 nginx.conf。

解法:

location ~^ /ci/  {
  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;

  # for codeigniter
  index  index.html index.htm index.php;
  try_files $uri $uri/ /ci/index.php;

  # for 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;
}

2014年1月11日 星期六

[電影] 真愛每一天 (About Time)



來源:About Time wiki

今日在二輪電影院看了這部電影,寓意滿深的小品,喜歡這般的呈述故事。

讓我想到在工程師總常講的 "過度最佳化" 或 "太早最佳化" 的含義,有興趣可以看這部片放鬆一下腳步,體驗、享受生命。人生不要一直都用數字、錢、考績衡量步伐,走錯路時,仍可看到另一片天空。


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 。