2014年1月22日 星期三

[SQL] MySQL: Insert or update @ Ubuntu 12.04

最近把玩 MySQL 了一下,想要做一些 daily result snapshot 的部分,想說就把結果存到一張表中使用,這樣下去就真的變成純玩 SQL 的生活了 XD

此時就會碰到把新增及更新的需求,好家在 MySQL 真威,筆記一下:

http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html

mysql> INSERT INTO TableName ( Filed1, Filed2 ) VALUES ( 'Value1', 'Value2' ) ON DUPLICATE KEY UPDATE Field1=VALUES(Field1);

不過這次玩的比較多一點:

mysql> INSERT INTO TableName ( Filed1, Filed2 ) 

 SELECT Field1, Field2 FROM TableName2 

 ON DUPLICATE KEY UPDATE Field1=VALUES(Field1);

2014年1月21日 星期二

[Linux] CodeIgniter on Nginx : site_url, base_url use https @ Ubuntu 12.04

在 nginx 上跑 CodeIgniter 時,使用 site_url 、 base_url 卻會產生 https 的連結出來,此現象是因為 CodeIgniter 是透過 $_SERVER['HTTPS'] 判斷所造成的,解法就是設定 Nginx PHP 的環境參數(fastcgi_param  HTTPS  off),在 /etc/nginx/fastcgi_params 可看到這樣的定義:

fastcgi_param  HTTPS  $https;

暫時偷懶解法 (/etc/nginx/sites-available/default):

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param  HTTPS off;
}


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

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

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