2012年3月26日 星期一

FreeBSD 利用 Xvfb (xorg-vfbserver) 執行 X Window 程式

Xvfb 在 FreeBSD 的 ports 裡面叫 xorg-vfbserver。

安裝 ports:
/usr/ports/x11-servers/xorg-vfbserver
/usr/ports/x11/xkeyboard-config

啟用 Xvfb,並指定 顯示 的 X server。

啟用 Xvfb 於 server 1 並指定第 0 個 screen 為 1920x1080x16

# Xvfb :1 -screen 0 1920x1080x16 &
# setenv DISPLAY :1.0


2012年3月22日 星期四

FreeBSD 中 MySQL InnoDB 檔案損毀無法卸除問題解決

當 MySQL InnoDB 的資料庫檔案損毀造成無法載入,且無法下 Query 時,可以使用參數強制 InnoDB 跳過錯誤處理流程,讓我們可以將資料盡量 Dump 出來,或卸載資料庫。

my.cnf

[mysqld]
innodb_force_recovery = 4


MySQL 官方網站參數說明:

1 (SRV_FORCE_IGNORE_CORRUPT)

Let the server run even if it detects a corrupt page. Try to make SELECT * FROM tbl_name jump over corrupt index records and pages, which helps in dumping tables.

2 (SRV_FORCE_NO_BACKGROUND)

Prevent the main thread from running. If a crash would occur during the purge operation, this recovery value prevents it.

3 (SRV_FORCE_NO_TRX_UNDO)

Do not run transaction rollbacks after recovery.

4 (SRV_FORCE_NO_IBUF_MERGE)

Prevent insert buffer merge operations. If they would cause a crash, do not do them. Do not calculate table statistics.

5 (SRV_FORCE_NO_UNDO_LOG_SCAN)

Do not look at undo logs when starting the database: InnoDB treats even incomplete transactions as committed.

6 (SRV_FORCE_NO_LOG_REDO)

Do not do the log roll-forward in connection with recovery.


2012年3月14日 星期三

FreeBSD xargs 無法處理一個以上參數之替代方案

1.將資料 pipe 給 sed
2.於 sed 中使用 regular expression 切割字串
3.重組字串成 指令 輸出
4.pipe 給 tcsh

example:

# ls */*road | xargs -I @ -n 1 realpath @ | sed 's/\(.*\)\/\(.*\)\/\([0-9]*\)\(.*\)/mv \1\/\2\/\3\4 \1\/\2\/\3_\2_\4/' | tcsh


FreeBSD ls 搭配 realpath 取得對路徑


# ls *.txt | xargs -I @ -n 1 realpath @


FreeBSD xargs 中使用 | pipe

使用 xargs 時,若組合出的指令中需要使用到 | pipe,則會發指令無法執行,因為 pipe 後面的東西會被當成一個新的指令。

可使用 tcsh -c 來執行組合出來的指令,以避免此問題。

# echo 'abcdef' | xargs -I @ -n 1 tcsh -c "echo @ | grep 'abc' "


2012年3月13日 星期二

FreeBSD 新增硬碟

*於機器上安裝新硬碟
*檢視 /var/run/dmesg.boot 確認有抓到新硬碟

*以 root 執行 sysinstall
*選 Configure > Fdisk 分割硬碟 (記得 Q 之前要用 W 寫入)

*重開機

*以 root 執行 sysinstall
*選 Configure > Lable 指定分割區名稱 (記得 Q 之前要用 W 寫入) (若非第一次安裝系統,則 Label mount point 不重要)

*編輯 /etc/fstab, 加入新增的分割區資訊

*重開機


2012年2月8日 星期三

FreeBSD 設定 ports 抓取檔案 Server

修改 /etc/make.conf

加入以下設定:

# Port master sites.
#
# If you want your port fetches to go somewhere else than the default
# (specified below) in case the distfile/patchfile was not found,
# uncomment this and change it to a location nearest you. (Don't
# remove the "/${DIST_SUBDIR}/" part.)
#

MASTER_SITE_BACKUP?= \
ftp://ftp.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp5.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp10.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp2.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp3.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp4.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp7.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp8.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp9.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp11.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp12.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/

#
# If you want your port fetches to check the above site first (before
# the MASTER_SITES specified in the port Makefiles), uncomment the
# line below. You can also change the right side to point to wherever
# you want.
#
MASTER_SITE_OVERRIDE?= ${MASTER_SITE_BACKUP}


2011年12月29日 星期四

Javascript 與 PHP 傳遞跳脫 URL

前提:Magic Quotes OFF

encodeURIComponent (Javascript)
rawurldecode (PHP)


2011年12月23日 星期五

jQuery Plugin flog - Formatted Log

flog 意思為 Formatted Log

由此篇文章得到靈感。
http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/12/31/jquery-logging-plugin.aspx

沒有 Firebug 時,會自動忽略此功能。
並導入了 Console.log 的 Format 字串 與 無限參數個數。
外加判斷,若第一個參數為 Format 字串 且 選擇對象為 使用者選擇之目標,則將 Format 字串後加入 ": %o" 以顯示 使用者選擇目標。

原始碼:

/*
* jQuery Formatted Log Plugin v1.0.0 @ 20111223
*
* Print formatted log to console.log with smart object display.
*
* Copyright (c) 2011 Firch Tsai
*
* Licensed under the GPL v2 licenses.
*/
jQuery.flog = jQuery.fn.flog = function(msg) {

if (typeof console != "undefined")
{
var arguments_array = [];

for (var i in arguments)
{
arguments_array[i] = arguments[i];
}

var first_arg = arguments_array.shift();

if(typeof first_arg == "string" && this.selector != $.selector)
{
first_arg += ': %o';
arguments_array.push(this);
}

arguments_array.unshift(first_arg);


var logfn = console.log;
logfn.apply(this, arguments_array);
}

return this;
};


使用範例:

item = "Book";
$.flog("This is a %s !", item);

將輸出:
This is a Book !


使用範例:

tag_name = "Links";
$('a').flog("These %s are Formatted", tag_name );

將輸出:
These Links are Formatted: +[a... , a...]


2011年11月11日 星期五