CodeIgniter 2.0.2 Released

CodeIgniter
很高興看到

CodeIgniter 又推出新版 2.0.2 Released,這次升級最主要是針對**安全性的漏洞**,以及一些 bug 修正,升級步驟也非常簡單,可以參考 Upgrading from 2.0.1 to 2.0.2,只要把 Core 核心檔案換掉,還有如果在程式碼有載入 Security Library 的地方全部取消,看底下: 舉例 Example:

$this->load->library("security");
如果程式碼有用到上面部份,請將其拿掉,因為現在系統已經將 Security Library 加入核心一部分提高整個網站安全性。如果要想知道 2.0.2 做了哪些修正,可以參考

Change log

用 cpanm 安裝 Perl 相依性模組

最近在寫 Perl 爬蟲程式,需要用到短網址 Bitly 的 API,所以找了 WWW::Shorten::Bitly,本篇紀錄安裝使用 cpanm 這 Perl 的小工具,此工具不需要任何設定,只要下載到 bin 目錄就可以正成使用了。由於 Ubuntu 沒有包好的 dpkg 可以用,所以才想到用 cpanm。

安裝 cpanm

mkdir ~/bin
wget --no-check-certificate http://bit.ly/cpanm -O ~/bin/cpanm
chmod +x ~/bin/cpanm
或者可以直接安裝到

/usr/local/bin/ 底下,這樣不用在重新把 PATH 改寫

sudo cp ~/bin/cpanm /usr/local/bin/

使用 cpanm

# 安裝 WWW::Shorten::Bitly
cpanm WWW::Shorten::Bitly
# 安裝 distribution path
cpanm MIYAGAWA/Plack-0.99_05.tar.gz
# 從 URL 安裝
cpanm http://example.org/LDS/CGI.pm-3.20.tar.gz
# 安裝本機檔案
cpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz
另外介紹幾個 option --sudo 直接用 sudo 方式安裝,也就是 root 啦 --verbose 檢查安裝過程 --notest 不需要測試 --force 強制安裝 --reinstall 重新安裝,假如已經有安裝過的軟體,一樣會 reinstall --installdeps 只安裝相依性軟體 非常簡單吧,這是懶人做法,如果在

FreeBSD 直接安裝 ports 就好。

CSS 3 圓角 border-radius 介紹

目前各家瀏覽器分別開始支援 CSS3,現在 MS 瀏覽器系列只有 IE 9 開始支援 CSS3,所以大家還是趕快升級到 IE 9.0,或者是使用 Google ChromeFireFox 4.0 吧,以前還沒有 CSS 3 的時候,圓角功能都是靠 jQuery Plugin: Corner,有了 CSS3 大家就不用這麼麻煩了,一行就可以搞定喔。

CSS Border Radius Generator 大家可以參考

CSS Border Radius Generator 這網站,只要輸入4個角所需要的圓角半徑,就會自動產生 CSS 3 的語法喔

/* support Safari, Chrome */
-webkit-border-radius: 5px;
/* support firefox */
-moz-border-radius: 5px;
border-radius: 5px;
也可以個別設定角度 右上圓角:
border-topright-radius: 5px; 
-moz-border-topright-radius: 5px; 
-webkit-border-topright-radius: 5px;
左上圓角:
border-topleft-radius: 5px; 
-moz-border-topleft-radius: 5px; 
-webkit-border-topleft-radius: 5px;
右下圓角:
border-bottomright-radius: 5px; 
-moz-border-bottomright-radius: 5px; 
-webkit-border-bottomright-radius: 5px;
左下圓角:
border-bottomleft-radius: 5px; 
-moz-border-bottomleft-radius: 5px; 
-webkit-border-bottomleft-radius: 5px;
非常簡單,大家以後不用再自己做圓角的圖,CSS3 一行搞定啦 Ref:

css圓角(border-radius)介紹 螞蟻的 CSS border-radius developer mozilla border-radius

[網站] 好站連結 (八) Android, javascript, CSS, PHP, Perl, FreeBSD, Linux

PHP 9 Useful PHP Functions and Features You Need to Know CSS Tips to Code Better CSS in your Projects Html5 A ROCK-SOLID DEFAULT FOR HTML5 AWESOME( Html5 模板) The Official Guide to HTML5 Boilerplate Create a Sticky Note Effect in 5 Easy Steps with CSS3 and HTML5 Git: git-server-的兩三事 Pro Git - Table of Contents 簡體中文版 Git 初學筆記 - 實作測試 | Tsung’s Blog Javascript: Learning JavaScript and DOM with Console 淺談 JavaScript 編程語言的編碼規範 Creating photo gallery using jQuery and VisualLightBox Importing multiple RSS feeds – using newsWidget (jQuery) Evolution of Script Loading Global eval. [Read More]

2011 OSDC Day 1 筆記

Update: 補上 OSDC 紀錄影片 2011.06.26 今年很高興可以北上參加 OSDC 2011 (Open Source Developers Conference),由於之前都在南部唸書及工作,沒有機會北上參加聚會,現在人在新竹,終於有機會可以參加了,雖然早上六點就要起床趕電車了,不過到現場聽課感覺就是不同,也可以認識很多新朋友,底下來紀錄上課筆記 微軟與 jQuery 社群的親密接觸 講者: Eric Shangkuan (Microsoft) Slide: 微軟與 jQuery 社群的親密接觸 這是 OSDC 第一場演講,早上九點就開始了,雖然人不多,但是蠻多人還是為了講者而來,首先介紹什麼是 jQuery,以及 jQuery 一些基本用法,像是 CSS selector,如何在 Windows Visual Studio 上面開發 jQuery 及撰寫 plugin 整合進去 ASP.Net,最後介紹三個不錯用的 jQuery Plugin: Templeate, Datalink, Globalzation。 Templeate: 這搭配 Facebook api 可以直接做個人頁面,請參考這裡 Globalzation: 前端多國語系實做 Datalink: 可以快速處理 form,利用 object 跟 jQuery 搭配 如果要研究上述三個 jQuery Plugin 可以參考底下: jQuery Datalink: https://github.com/jquery/jquery-datalink jQuery Templeate: https://github.com/jquery/jquery-tmpl jQuery Globalzation: https://github. [Read More]

如何使用 PPA 升級 Ubunut Firefox 瀏覽器到 4.0

FireFox_4_about 作者目前使用 Ubuntu 10.10 (maverick) 桌面環境,也是台灣 MozTW 成員之一,這次 FireFox 4.0 Release 介面有些改變,使用上來也非常順手,記憶體好像吃的比較少了?(有待商榷),現在就來升級 FireFox 吧,兩種升級方式,如果不熟悉 Command Line 就用 GUI 升級,另一種升級方式就是用 apt-get upgrade 啦。 如果用 Windows 請到這裡下載

利用 GUI 介面升級 (Install firefox 4 using GUI) 我的環境是英文,所以底下寫的是英文安裝方式: 按照底下步驟進行

Applications > Ubuntu Software Center > Edit > Software Sources 
之後點選 "Other Software" 選擇左下角 "Add" 按鈕,接著把底下文字輸入
ppa:mozillateam/firefox-stable
最後到底下升級,就可以開始使用 FireFox 4 了
System > Administration > Update Manager

文字介面升級 (Install firefox 4 using terminal) 只要鍵入三行指令即可

$ sudo add-apt-repository ppa:mozillateam/firefox-stable
$ sudo apt-get update
$ sudo apt-get upgrade
沒圖沒真相啦,底下附上桌面截圖

firefox_4 Reference: How to install firefox 4 in ubuntu using PPA Firefox 4 正式版現已推出,帶給您更棒的網路體驗

CodeIgniter 2.0.1 Release 發佈了

CodeIgniter
很高興可以聽到這消息,那就是

CodeIgniter Release 2.0.1 版本了,原本大家都很擔心為什麼 CodeIgniter 每發佈 Release 版本都要等個好幾個月甚至到半年以上,現在不用這麼久了,因為自從官方新增了 CodeIgniter Reactor 加速版本開發及修正,所以更多人貢獻了自己的程式碼及回報問題,我相信 CodeIgniter 會越來越好,希望有更多台灣的朋友來使用。 2.0.1 版本新增了 ENVIRONMENT 這環境變數,讓程式開發者可以任意調整環境狀況,最主要是改變 PHP error reporting 狀態:

/*
 * production => error_reporting(0)
 * development => error_reporting(E_ALL)
 */
define('ENVIRONMENT', 'production');
當您設定為 production,表示網站不需要任意輸出錯誤訊息,如果調整成 development,系統就會打開全部錯誤訊息,這對開發者相當重要。如果想瞭解更多,請參考

Handling Multiple Environments。 歡迎大家下載最新版本: http://www.codeigniter.org.tw/downloads 如果想加入翻譯團隊,可以參考這裡: https://github.com/appleboy/PHP-CodeIgniter-Framework-Taiwan

Ubuntu (Debian) 架設 apache mpm worker mod_fcgid 筆記

最近想架設 RedmineUbuntu 伺服器上面,架設之前要先搞定 apache 搭配 mpm worker 及 mod_fcgi module,安裝步驟其實不難,就搭配懶人指令 apt 就可以了。

安裝 apache mpm worker 由於怕安裝過程會叫你把 apache2-mpm-worker 移除,改裝 apache2-mpm-prefork,所以安裝順序上面有些變化,請參考底下:

# 先安裝
$ apt-get install apache2.2-bin apache2.2-common apache2-mpm-worker libapache2-mod-fcgid php5-cli php5-cgi php5-common
#後安裝
$ apt-get install apache2 php5 php5-gd php5-curl
至於 PHP 5 套件就看你需要什麼就裝什麼吧,搜尋一下 php5-* 看看,apache 裝好預設看不到 PHP 網頁,也就是認不得 php type,請在 apache config 檔案加入底下 [Read More]

[Linux Kernel] 讀取 /proc 底下資料最佳方法: seq_file interface

前言 最近在整合公司內部

Atheros(被高通買下) 晶片的 Router,從原本 2.6.15 升級到 2.6.34.7,升級過程遇到很多困難,其中一項升級 Wireless Driver 部份,發現在 Kernel Socket 與 User Space 溝通之間出了問題,利用 Ioctl 來取得目前在 AP 上面所有 Client 資料(包含 mac address, 處於 N or G mode…等),在 User Space 上會掉資料,後來利用 /proc 底下檔案來跟 User 之間溝通,才沒有發生任何問題,由於輸出的檔案比較多,就偏向用 2.6 Kernel 提供的 seq_file 介面( interface )建立虛擬檔案 (virtual file) 與 User Space 溝通(此方法為 Alexander Viro 所設計),此功能其實在 2.4.15 已經實做了,只是在 2.6 版本才被大量使用。 程式設計師可以透過引入 <linux/seq_file.h> 來實做 seq_file interface,seq_file 最大優勢就是讀取完全沒有4k boundry 的限制,也就是不用管會不會超出 output buffer。

The iterator interface 為了能夠讓 iterator 正常運作,我們必須實做 4 個 function (start, next, stop, show),跑得過程為 start -> show -> next -> show -> next -> stop,為了方便講解,參考

Linux Kernel(4)- seq_file 裡面範例如下:

#include 
#include 
#include  /* Necessary because we use proc fs */
#include  /* for seq_file */
#include 

MODULE_LICENSE("GPL");

#define MAX_LINE 1000
static uint32_t *lines;

/**
 * seq_start() takes a position as an argument and returns an iterator which
 * will start reading at that position.
 */
static void* seq_start(struct seq_file *s, loff_t *pos)
{
    uint32_t *lines;

    if (*pos >= MAX_LINE) {
        return NULL; // no more data to read
    }

    lines = kzalloc(sizeof(uint32_t), GFP_KERNEL);
    if (!lines) {
        return NULL;
    }

    *lines = *pos + 1;

    return lines;
}

/**
 * move the iterator forward to the next position in the sequence
 */
static void* seq_next(struct seq_file *s, void *v, loff_t *pos)
{
    uint32_t *lines = v;
    *pos = ++(*lines);
    if (*pos >= MAX_LINE) {
        return NULL; // no more data to read
    }
    return lines;
}

/**
 * stop() is called when iteration is complete (clean up)
 */
static void seq_stop(struct seq_file *s, void *v)
{
    kfree(v);
}

/**
 * success return 0, otherwise return error code
 */
static int seq_show(struct seq_file *s, void *v)
{
    seq_printf(s, "Line #%d: This is Brook's demo\n", *((uint32_t*)v));
    return 0;
}

static struct seq_operations seq_ops = {
    .start = seq_start,
    .next  = seq_next,
    .stop  = seq_stop,
    .show  = seq_show
};

static int proc_open(struct inode *inode, struct file *file)
{
    return seq_open(file, &seq_ops);
}

static struct file_operations proc_ops = {
    .owner   = THIS_MODULE, // system
    .open    = proc_open,
    .read    = seq_read,    // system
    .llseek  = seq_lseek,   // system
    .release = seq_release  // system
};

static int __init init_modules(void)
{
    struct proc_dir_entry *ent;

    ent = create_proc_entry("brook", 0, NULL);
    if (ent) {
        ent->proc_fops = &proc_ops;
    }
    return 0;
}

static void __exit exit_modules(void)
{
    if (lines) {
        kfree(lines);
    }
    remove_proc_entry("brook", NULL);
}

module_init(init_modules);
module_exit(exit_modules);
[Read More]

用 js 或 php 判斷 Android 手機上網

之前寫了一篇 jQuery 偵測瀏覽器版本, 作業系統(OS detection),這次可以來加上 Android 手機版本,其實就是分析瀏覽器 User Agent 來達到目的,底下分享 PHP 跟 Javascript 作法

PHP 方法

if(stripos($_SERVER['HTTP_USER_AGENT'],'Android') !== false) 
{
	header('Location: http://android.xxx.com');
	exit();
}

Javascript 方法

if(navigator.userAgent.match(/Android/i))
{
	window.location = 'http://android.xxx.com';
}

Apache .htaccess 方法 用

Apache mod rewrite 方法

RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.xxx.com [R=301]