月度归档:2012年07月

禁止cos_slug_translator将全英文标题url翻译为中文

cos_slug_translator是一个很好用的插件,会自动将带有中文的标题翻译为英文,作为永久链接,英文比中文更好。
cos_slug_translator采用了有道的翻译api,目前版本是1.1,这个api会将中文翻译为英文,同时,也会将英文翻译为中文。没有参数可以指定是 中->英 还是 英->中。这样就造成了如果标题是全英文的,那么最终的固定连接会自动被替换为翻译过来的中文,反倒不美。
进行如下修改,如果表里中不含有中文,就不进行翻译

修改 function CosSlugTrans($postID){
    $tableposts = $wpdb->posts ;
        $sql = "SELECT post_title,post_name FROM $tableposts WHERE ID=$postID";
        $res = $wpdb->get_results($sql);    
        $post_title = $res[0]->post_title;
        $tran_title = cos_tranlate($post_title);
        $slug = $tran_title;
        if(function_exists("sanitize_title") ) {
            if( sanitize_title( $res[0]->post_title ) != $res[0]->post_name  ){
                if( !substr_count($path, '%') ) 
....
修改为
    $tableposts = $wpdb->posts ;
        $sql = "SELECT post_title,post_name FROM $tableposts WHERE ID=$postID";
        $res = $wpdb->get_results($sql);    
        $post_title = $res[0]->post_title;

        if (preg_match("/[\x7f-\xff]/", $post_title)) {
            $tran_title = cos_tranlate($post_title);
            $slug = $tran_title;
        } else {
            $slug = $post_title;
        }

        if(function_exists("sanitize_title") ) {
            if( sanitize_title( $res[0]->post_title ) != $res[0]->post_name  ){
                if( !substr_count($path, '%') ) 
....

 

How to determine bind variable value and type from trace file

from
http://oradbatips.blogspot.jp/2007/11/tip-64-how-to-determine-bind-variable.html
For finding more information about bind variable, user should be able to locate BINDS keyword in trace file.
This part is something like this :

BINDS #2:
bind 0: dty=1 mxl=32(30) mal=00 scl=00 pre=00 oacflg=13 oacfl2=1 size=32 offset=0
bfp=030a79ec bln=32 avl=01 flg=05
value="A"

dty determines bind variable type and value shows bind variable value at the time of execution.
Different values can be assigned to dty which presents different data type.

Typical dty value is :

1 VARCHAR2 or NVARCHAR2
2 NUMBER
8 LONG
11 ROWID
12 DATE
23 RAW
24 LONG RAW
96 CHAR
112 CLOB or NCLOB
113 BLOB
114 BFILE

To demosnstrate, I ran some queries.

SQL> alter session set statistics_level=ALL;

Session altered.

SQL> alter session set max_dump_file_size=UNLIMITED;

Session altered.

SQL> alter session set events '10046 trace name context forever, level 12';

Session altered.

SQL> variable b number;
SQL> declare
2 cnt number;
3 begin
4 :b:=1;
5 select count(*) into cnt from dba_objects where object_id=:b;
6 end;
7 /

PL/SQL procedure successfully completed.

SQL> alter session set events '10046 trace name context off';

Session altered.

Checking trace file ……

PARSING IN CURSOR #2 len=52 dep=1 uid=0 oct=3 lid=0 tim=2797155817 hv=1220784193 ad='130a9d4c'
SELECT count(*) from dba_objects where object_id=:b1
END OF STMT
PARSE #2:c=15625,e=24270,p=0,cr=5,cu=0,mis=1,r=0,dep=1,og=0,tim=2797155809
BINDS #2:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=13 oacfl2=1 size=24 offset=0
bfp=030a7b2c bln=22 avl=02 flg=05
value=1
EXEC #2:c=0,e=2062,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=2797159524
FETCH #2:c=0,e=37,p=0,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=2797159885

 

—— Query #2 : Varhchar2 Bind variable

SQL> alter session set events '10046 trace name context forever, level 12';

Session altered.

SQL> variable b varchar2(30);
SQL> declare
2 cnt number;
3 begin
4 :b:='A';
5 select count(*) into cnt from dba_objects where object_name=:b;
6 end;
7 /

PL/SQL procedure successfully completed.

SQL> alter session set events '10046 trace name context off';

Checking trace file .....

PARSING IN CURSOR #2 len=54 dep=1 uid=0 oct=3 lid=0 tim=3007778755 hv=2029951970 ad='12ff2c80'
SELECT count(*) from dba_objects where object_name=:b1
END OF STMT
PARSE #2:c=15625,e=12991,p=0,cr=2,cu=0,mis=1,r=0,dep=1,og=0,tim=3007778748
BINDS #2:
bind 0: dty=1 mxl=32(30) mal=00 scl=00 pre=00 oacflg=13 oacfl2=1 size=32 offset=0
bfp=030a79ec bln=32 avl=01 flg=05
value="A"
EXEC #2:c=0,e=2167,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=3007782524
WAIT #2: nam='db file sequential read' ela= 9458 p1=1 p2=89 p3=1
WAIT #2: nam='db file sequential read' ela= 6606 p1=1 p2=26791 p3=1

 

 

code highlighter test 2

set pagesize 0
set linesize 125
set serveroutput on size 10000
col plan_table_output format a125
undefine hash_value
set verify off feedback off
var hash_value varchar2(20)
begin
:hash_value := '&hash_value';
end;
/
insert into plan_table
(statement_id,timestamp,operation,options,object_node,object_owner,object_name,
optimizer,search_columns,id,parent_id,position,cost,cardinality,bytes,other_tag,
partition_start,partition_stop,partition_id,other,distribution,
cpu_cost,io_cost,temp_space,access_predicates,filter_predicates,
plan_id,OBJECT_ALIAS,DEPTH,PROJECTION,TIME,QBLOCK_NAME
)
select distinct hash_value,sysdate,operation,options,object_node,object_owner,object_name,
optimizer,search_columns,id,parent_id,position,cost,cardinality,bytes,other_tag,
partition_start,partition_stop,partition_id,other,distribution,
cpu_cost,io_cost,temp_space,access_predicates,filter_predicates,
:hash_value,OBJECT_ALIAS,DEPTH,PROJECTION,TIME,QBLOCK_NAME
from v$sql_plan
where hash_value = :hash_value
/
col piece noprint
select distinct 'sql_id:'||sql_id, ' hash_value:'||hash_value, 'plan_hash_value:'||plan_hash_value from v$sql_plan where hash_value=:hash_value
/
select distinct piece,sql_text from v$sqltext where hash_value = :hash_value order by piece
/
@?/rdbms/admin/utlxplp.sql
set linesize 80
set verify on feedback on pagesize 1000

set pagesize 0
set linesize 125
set serveroutput on size 10000
col plan_table_output format a125
undefine hash_value
set verify off feedback off
var hash_value varchar2(20)
begin
:hash_value := '&hash_value';
end;
/
insert into plan_table
(statement_id,timestamp,operation,options,object_node,object_owner,object_name,
optimizer,search_columns,id,parent_id,position,cost,cardinality,bytes,other_tag,
partition_start,partition_stop,partition_id,other,distribution,
cpu_cost,io_cost,temp_space,access_predicates,filter_predicates,
plan_id,OBJECT_ALIAS,DEPTH,PROJECTION,TIME,QBLOCK_NAME
)
select distinct hash_value,sysdate,operation,options,object_node,object_owner,object_name,
optimizer,search_columns,id,parent_id,position,cost,cardinality,bytes,other_tag,
partition_start,partition_stop,partition_id,other,distribution,
cpu_cost,io_cost,temp_space,access_predicates,filter_predicates,
:hash_value,OBJECT_ALIAS,DEPTH,PROJECTION,TIME,QBLOCK_NAME
from v$sql_plan
where hash_value = :hash_value
/
col piece noprint
select distinct 'sql_id:'||sql_id, ' hash_value:'||hash_value, 'plan_hash_value:'||plan_hash_value from v$sql_plan where hash_value=:hash_value
/
select distinct piece,sql_text from v$sqltext where hash_value = :hash_value order by piece
/
@?/rdbms/admin/utlxplp.sql
set linesize 80
set verify on feedback on pagesize 1000

public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

#!/usr/bin/perl
use Txu::Util;
use Data::Dumper;

#SetDebug;

unless (@ARGV >= 2){
print "Usage: ./diff_hd.pl file1 file2\n";exit;
}

open $rpt, '<', $ARGV[0]; my $r = &FileToArray($rpt,'\s*,\s*'); close $rpt; open $rpt, '<', $ARGV[1]; my $s = &FileToArray($rpt,'\s*,\s*'); close $rpt; my $c = &NewDiffCfg($r->[0], $s->[0], [0], 2);

my $d = &GetDiffArray(
$c
);

 

 

 

test code highlighter

<pre lang="php"> <div id="foo"> <?php   function foo() {     echo "Hello World!\\n";   } ?> </div> </pre>

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end

how to debug nginx rewrite rule.

2 method

1.
error_log /srv/www/example.com/log/error.log debug;

2.
rewrite_log on;
error_log /srv/www/example.com/log/error.log notice;

if you want to check a variable’s value , you can direct use following script
rewrite ^ $var_you_want_check break;

then you can find something like following in error.log , the strings in RED , is the value of $var_you_want_check
2012/07/03 14:15:24 [notice] 25289#0: *30519 "^" matches "/2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html", client: 116.24.4.227, server: 6658.net, request: "GET /2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html HTTP/1.1", host: "6658.net", referrer: "http://6658.net/wp-content/cache/supercache/6658.net/2012/01/31/gnc-more-than-one-hundred-products-less-than-10-dollar-free-shipping.html/index.html"
2012/07/03 14:15:24 [notice] 25289#0: *30519 rewritten data: "/example.com/public_html/wp-content/cache/supercache/6658.net/2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.htmlindex.html", args: "", client: 116.24.4.227, server: 6658.net, request: "GET /2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html HTTP/1.1", host: "6658.net", referrer: "http://6658.net/wp-content/cache/supercache/6658.net/2012/01/31/gnc-more-than-one-hundred-products-less-than-10-dollar-free-shipping.html/index.html"