Monday, January 19, 2009

Remove gmail Sponsored link in firefox3

under ubuntu8.10, goto user profile directory and create dir "chrome" if "chrome" is not exists.
$> cd ~/.mozilla/firefox/user*profile.default/chrome
$> vi userContent.css

* For remove gmail ad links
.eWTfhb div[class="XoqCub"][style="width: 225px;"]{
.tELAdc div[class="XoqCub"][style="width: 225px;"]{
div.qWFFaf {
restart firefox.
in other OS, userContent.css may in below path:
Windows 2000/XP
C:\Documents and Settings\[USER]\Application Data\Mozilla\Firefox\Profiles\*.default\chrome\
Mac OS X
~/Library/Application Support/Firefox/Profiles/[profile-name]/chrome/

Monday, January 12, 2009

open gbk encoing files in gedit

$> gconf-editor
It will open "Configuration Edition", and choose /apps/gedit-2/preferences/encoding, edit "auto_detected" key, add "GBK" before "ISO-8859-15".

Friday, January 09, 2009


header("Location: b.php");

Thursday, January 08, 2009

stack level too deep in will_paginate

After update rails from 1.2.5 to 2.2.2, get below exception:
stack level too deep
../vendor/plugins/will_paginate/lib/will_paginate/finder.rb:81:in `method_missing_without_paginate'
../vendor/plugins/will_paginate/lib/will_paginate/finder.rb:82:in `method_missing'

solution, update will_paginate:
$> script/plugin install git://

Tuesday, January 06, 2009

Difference of String.match and Regexp.exec

The match( ) method is the most general of the String regular-expression methods. It takes a regular expression as its only argument (or converts its argument to a regular expression by passing it to the RegExp( ) constructor) and returns an array that contains the results of the match. If the regular expression has the g flag set, the method returns an array of all matches that appear in the string. For example:

"1 plus 2 equals 3".match(/\d+/g) // returns ["1", "2", "3"]

If the regular expression does not have the g flag set, match( ) does not do a global search; it simply searches for the first match. However, match( ) returns an array even when it does not perform a global search. In this case, the first element of the array is the matching string, and any remaining elements are the parenthesized subexpressions of the regular expression. Thus, if match( ) returns an array a, a[0] contains the complete match, a[1] contains the substring that matched the first parenthesized expression, and so on. To draw a parallel with the replace( ) method, a[n] holds the contents of $n.
For example, consider parsing a URL with the following code:
var url = /(\w+):\/\/([\w.]+)\/(\S*)/;
var text = "Visit my blog at";
var result = text.match(url);
if (result != null) {
var fullurl = result[0]; // Contains ""
var protocol = result[1]; // Contains "http"
var host = result[2]; // Contains ""
var path = result[3]; // Contains "~david"
Finally, you should know about one more feature of the match( ) method. The array it returns has a length property, as all arrays do. When match( ) is invoked on a nonglobal regular expression, however, the returned array also has two other properties: the index property, which contains the character position within the string at which the match begins, and the input property, which is a copy of the target string. So in the previous code, the value of the result.index property would be 17 because the matched URL begins at character position 17 in the text. The result.input property holds the same string as the text variable. For a regular expression r and string s that does not have the g flag set, calling s.match(r) returns the same value as r.exec(s). The RegExp.exec( ) method is discussed a little later in this chapter.
var pattern = /\bJava\w*\b/g;
var text = "JavaScript is more fun than Java or JavaBeans!";
var result;
while((result = pattern.exec(text)) != null) {
alert("Matched '" + result[0] +
"' at position " + result.index +
" next search begins at position " + pattern.lastIndex);
When exec( ) is invoked on a nonglobal pattern, it performs the search and returns the result described earlier. When regexp is a global regular expression, however, exec( ) behaves in a slightly more complex way. It begins searching string at the character position specified by the lastIndex property of regexp. When it finds a match, it sets lastIndex to the position of the first character after the match. This means that you can invoke exec( ) repeatedly in order to loop through all matches in a string. When exec( ) cannot find any more matches, it returns null and resets lastIndex to zero. If you begin searching a new string immediately after successfully finding a match in another string, you must be careful to manually reset lastIndex to zero.
Note that exec( ) always includes full details of every match in the array it returns, whether or not regexp is a global pattern. This is where exec( ) differs from String.match( ), which returns much less information when used with global patterns. Calling the exec( ) method repeatedly in a loop is the only way to obtain complete pattern-matching information for a global pattern.

This article copy from OReilly's《JavaScript The Definitive Guide》5th Edition.

Rails module include way

# Rails module include way
# 以下方式的代码在rails中源码中的相当多见,其中的self.included(base)方法是一个回调方法,当此module被其他名为base的module(或者class)include的时候触发此方法。通过class_eval,include,extend加入了实例方法和类方法到base中,代码划分得很干净。

module ActionController
module Components
def self.included(base)
base.class_eval do
include InstanceMethods
extend ClassMethods
helper HelperMethods

module ClassMethods

module HelperMethods

module InstanceMethods

Saturday, January 03, 2009

trap of in_array in php

$array = array('testing',0,'name');
//this will return true
var_dump(in_array('foo', $array));
//this will return false
var_dump(in_array('foo', $array, TRUE));