切換 Ubuntu apt 的 mirror site
Posted on February 22, 2011
| 1 minutes
| 31 words
| appleboy
Update: 國網內部員工建議用 http://ftp.twaren.net 這台
最近常常會發生 apt-get update 指令失敗,台大這台 tw.archive.ubuntu.com 似乎常常掛點,所以網路上找一下其他的 mirror site,看到似乎很多人都在用國網的 Server ( http://free.nchc.org.tw ),要換的話,請更改 /etc/apt/sources.list
,將全部 tw.archive.ubuntu.com 都取代成 free.nchc.org.tw,其實還有另一個 domain 就是 opensource.nchc.org.tw,這些都可以用,沒有 apt 的 Ubuntu 或 Debian 簡直就不是 Server 了…XD
WordPress plugin 加強網址 SEO
Posted on February 21, 2011
| 3 minutes
| 450 words
| appleboy
由於網站 SEO 在大家心中都是非常重要,現在製作網站也都考慮了很多 SEO 的問題,其中一個功能就是可不可以自訂網址,Wordpress 很早之前就支援了此功能,站長我呢,在創站的時候使用 blog.wu-boy.com/2011/02/17/2542,為了使搜尋引擎更可以快速找到本站,所以打算將網址改成 blog.wu-boy.com/2011/02/php-codeigniter-google-url-shortener-api-library/,在後台 Permalink Settings 可以自訂部落格網址,將網址格式改成 /%year%/%monthnum%/%postname%/,可是改了之後,之前搜尋引擎及別人引用的網址就會變成 404 NOT Found,為瞭解決此問題,必須寫一支 Mapping Url 程式,讓之前的舊網址轉到新網址,剛好在 Roga Blog 找到一篇 加強部落格的 SEO,提供了轉換的 plugin,底下是該程式碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| <?php
/*
Plugin Name: roga's url hotfix
Plugin URI: http://blog.roga.tw/2011/02/%E5%8A%A0%E5%BC%B7%E9%83%A8%E8%90%BD%E6%A0%BC%E7%9A%84-seo/
Description: redirect http requests.
Version: 0.1
Author: roga
Author URI: http://blog.roga.tw
License: GPL v2
*/
function roga_wrap()
{
GLOBAL $wpdb;
$request_uri = getenv('REQUEST_URI');
$array = explode('/', $request_uri);
$status = TRUE;
foreach($array as $row)
{
if( ! is_numeric($row) && ! empty($row)) $status = FALSE;
}
if(count($array) != 5 || $status != TRUE)
return NULL;
$post_id = (int) $array[4]; // http://blog.roga.tw/2011/02/16/2484
$wp_result = $wpdb->get_row("SELECT `post_type`, `post_name`, `post_date` FROM `$wpdb->posts` WHERE `ID` = $post_id ");
if( ! isset($wp_result))
return NULL;
$post_type = $wp_result->post_type;
$post_name = $wp_result->post_name;
$post_date = $wp_result->post_date;
if($post_type == 'revision')
return NULL;
$time = strtotime($post_date);
$year = date('Y', $time);
$month = date('m', $time);
// old: /%year%/%monthnum%/%day%/%post_id%
// new: /%year%/%monthnum%/%postname%/
$new_request_uri = "/$year/$month/$post_name";
$http_host = getenv('HTTP_HOST');
$logfile = WP_CONTENT_DIR . "/cache/wp-roga-redirect.log";
if(file_exists($logfile))
file_put_contents($logfile, sprintf("[%s] %s -> %s / %s " . PHP_EOL, date_i18n("Y-m-d H:i:s"), $request_uri, urldecode($new_request_uri), getenv('HTTP_USER_AGENT')), FILE_APPEND);
header("Status: 301 Moved Permanently");
header("Location: http:/$http_host$new_request_uri");
exit();
}
add_action('init', 'roga_wrap');
|
[Read More]PHP CodeIgniter Google URL Shortener API Library
Posted on February 17, 2011
| 1 minutes
| 192 words
| appleboy
原由 由於 bbs 的盛行,從最早的
0rz.tw 短網址出現,陸陸續續出來很多更好用的網址: tinyurl.com, bit.ly,後來 Google 也推出 goo.gl 服務,讓大家可以使用,提供了 Google URL Shortener API 讓程式開發者可以順利使用此 API,當然在使用 API 之前一定要跟 Google 申請一組 API Key,先到 Google API Console 申請,Shortener API 的規定每天可以存取 1,000,000 次(100萬),我想這樣也足夠個人或者是公司使用了,除非真的比這個大量,可以跟 Google 再提出額外申請。
系統需求
下載檔案 我已經將檔案都放在
github 上面,為了保持程式最新版本,請大家到底下連結進行下載
系統文件
安裝 此安裝檔案共有三個:
- application/config/google_url_api.php
- application/controllers/google_url.php
- application/libraries/Google_url_api.php 請將檔案放入到相對應的 application 目錄即可
設定 打開
application/config/google_url_api.php 檔案,將申請好的 API Key 填入即可
第一次執行 請在網址列打入
http://your_host/index.php/google_url/ 即可,如果有任何問題,可以在 Controller 部份將 debug mode 打開
$this->google_url_api->enable_debug(TRUE);
[Read More][Linux] 打造 Ubuntu 10.10 嵌入式系統 Embedded System 開發環境
Posted on February 10, 2011
| 1 minutes
| 152 words
| appleboy
作者於公司內部擔任嵌入式系統(Embedded System)工程師,由於嵌入式系統開發環境,本 Team 大多是用於 Fedora 作業系統,個人覺得 Fedora 太肥了,所以打造了 Ubuntu 的環境,針對於各家不同晶片廠商所提供的 ToolChain 及 Code base 進行編譯,其實也不會很難,修改 Makefile 檔案大致上都可以完成,安裝各種不同版本的 gcc 來搭配各家 Vendor 所提供的環境,底下是剛安裝好 Ubuntu 10.10 版本所需要的一些軟體套件,利用 apt-get 指令就可以安裝完成:
#!/bin/sh
apt-get update
apt-get -y install openssh-server
apt-get -y install vim
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git
apt-get -y install subversion
apt-get -y install bison
apt-get -y install flex
apt-get -y install gettext
apt-get -y install g++
apt-get -y install libncurses5-dev
apt-get -y install libncursesw5-dev
apt-get -y install exuberant-ctags
apt-get -y install sharutils
apt-get -y install help2man
apt-get -y install zlib1g-dev libssl-dev
# for samba 3.0.2
apt-get -y install gawk
# for Ralink
apt-get -y install libid3tag0-dev
apt-get -y install libgdbm-dev
[Read More][新聞] CodeIgniter 發佈 2.0.0 版 Release
Posted on February 1, 2011
| 1 minutes
| 191 words
| appleboy
繼上次
[新聞] PHP Framework Codeigniter 1.7.3 釋出 Release 之後,官方終於釋出 2.0 的版本,消息來源: http://codeigniter.com/news/codeigniter_2.0.0_released/。 CodeIgniter 發展其實還蠻慢的,所以很多工程師都跳去其他 PHP Framework 了,然而我始終認為 CI 是一套非常好學習的初階 Framework,希望更多人來使用,底下是 2.0 發佈相關新聞,大家可以參考看看到底做了哪些改變以及 Fix Bug list:
[Read More][FreeBSD] 利用 fsck 指令修復不正常斷電關機
Posted on January 26, 2011
| 1 minutes
| 158 words
| appleboy
由於人不在機器前面,所以都請學弟妹幫忙直接拔電在插電,現在問題出來了,完全不能開機了,現在就只能進去單人模式修復,其實修復也非常容易,進入開機選單,選擇 Single user mode 模式,進入之後會直接看到底下訊息提示:
enter full pathname of shell or return for :/bin/sh: 沒意外就直接按下 Enter 鍵就可以了,由於 fsck 指令在修復過程不可以先 mount 磁區,所以先利用 mount -a 來掛上所有磁區 # 掛上所有磁區
mount -a
# 顯示硬碟磁區
df -h Console 會看到 Filesystem Size Used Avail Capacity Mounted on
/dev/da0s1a 496M 341M 115M 75% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/da0s1e 496M 16M 440M 4% /tmp
/dev/da0s1f 24G 15G 6.4G 71% /usr
/dev/da1s1d 33G 22G 8.4G 73% /usr/home
/dev/da0s1d 4.
[Read More][Linux] 將 iperf 導入嵌入式系統 Router
Posted on January 6, 2011
| 1 minutes
| 81 words
| appleboy
iperf 是一套測試網路效能工具,對於網通廠各工程師們不可或缺的啦,分享如何將 iperf 裝到嵌入式板子,其實在 Porting 每一個工具到板子上的方式差不多,步驟大概是利用 configure file 產生 Makefile,修改 gcc tool chain 路徑,將編譯好的程式放到 root file system,基本上就是如此,目前 iperf 到 2.0.5 版,大家快去下載吧。 直接修改 user space 的 Makefile:
cd ./user/apps/iperf-2.0.5; \
./configure --host=mips-linux CC=$(TOOLPREFIX)gcc CXX=$(TOOLPREFIX)g++ --disable-ipv6 \
--prefix=$(shell (pwd -P))/user/apps/iperf-2.0.5/romfs;\
$(MAKE) && $(MAKE) install ;\ --host, CC, CXX 請換上 Tool Chain 對應路徑,大致上就可以了,更多設定可以參考 ./configure --help 編譯過程如果出現底下錯誤 undefined reference to malloc 就將 config.h.in 這檔案,底下整段 mark 起來,就可以編譯過了 /* Define to rpl_malloc if the replacement function should be used.
[Read More][Linux] 釋放虛擬記憶體 (cache)
Posted on December 27, 2010
| 1 minutes
| 44 words
| appleboy
Linux Kernel 2.6.16 之後加入了 drop caches 的機制,可以讓系統清出多餘的記憶體,這對於搞嵌入式系統相當重要阿,Memory 不夠就不能 upgrade firmware,我們只要利用讀寫 proc 檔案就可以清除 cache 記憶體檔案,底下是操作步驟:
釋放 pagecache:捨棄一般沒使用的 cache
echo 1 > /proc/sys/vm/drop_caches
釋放 dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
釋放 pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
Reference: Drop Caches 觀察 Linux 的虛擬記憶體
[Linux] 嵌入式系統不可或缺的工具 – busybox 分析 ifconfig command
Posted on December 26, 2010
| 5 minutes
| 879 words
| appleboy

玩過嵌入式系統的使用者,一定都會知道 Busybox,它提供一些小型 Linux command,方便在 console 端使用,以及一些 C 語言或者是 shell script 裡面,大家都知道 ifconfig 這指令,為了從 Kernel 2.6.15 轉換到 2.6.34.7 版本,原本的 Busybox 版本只有 1.0.1,現在已經到 1.18.1,轉換過程改了 Kernel netfilter 部份,以及 user space 部份 iptables extension。ifconfig 是 Busybox 其中一個指令用來查看目前有多少網路介面(network interface),來看看他是如何得到這些 interface 資訊,包含介面名稱、type、IP Adress、IP network mask、HW address 等….。
要讀取 interface 相關資訊可以透過兩種方式,一種是讀取 (IPv6 是 /proc/net/if_inet6),另一種透過 Socket 連接SOCK_DGRAM,最後用 iotcl 方式讀取 interface 相關資料,busybox 會先偵測檔案 /proc/net/dev 是否存在,如果 Kernel 有支援,就會讀取此檔案,如果不存在,則利用 socket 讀取資料。
if_readlist_proc 函式裡面:
1
2
3
4
| fh = fopen_or_warn(_PATH_PROCNET_DEV, "r");
if (!fh) {
return if_readconf();
}
|
看一下 /proc/net/dev 內容
1
2
3
4
| Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 104 1 0 0 0 0 0 0 104 1 0 0 0 0 0 0
eth0:21798505 51360 0 0 0 0 0 0 7693686 46844 0 0 0 0 0 0
|
[Read More][虛擬主機] VPS Linode 贈送 $100,000 美元給新註冊會員
Posted on December 18, 2010
| 1 minutes
| 114 words
| appleboy
昨天在下班前看到 Linode VPS 送出這個訊息: Linode $100,000 Giveaway!,只要在美國時間2010年12月17日早上九點開放名額1000名購買 VPS Linode 任何一種,就可以獨享 100 元美金的優惠,原本我已經有買一台 Linode 512 方案,我現在又加購一台,省下不少錢呢,到月底就不續約,然後再用新帳號繼續使用 Linode 512 服務,沒圖沒證據,底下附上我購買相關圖片 另外 VPS Linode 也提供了香港主機的服務,以及新的 Ubuntu OS 也上線了
Arch Linux 2010.05 (i386 and x86_64) CentOS 5.5 (i386 and x86_64) Debian 5.0 (i386 and x86_64) Fedora 14 (i386 and x86_64) Slackware 13.1 (i386 and x86_64) Ubuntu 10.04 LTS (i386 and x86_64) Ubuntu 10.10 (i386 and x86_64) OpenSUSE 11.0 Gentoo 2008.0 (i386 and x86_64) 參考主機放在哪裡比較適合: Datacenter Availability,您可以測試一下每個區域的連線速度 download speed test,我利用學網測試了國外的速度,發現速度比較如下: 單檔都是 100 MB:
[Read More]