安裝CODE HighLine外掛

以前,要POST含有Soure code或是Command Line都直接用WordPress的”引言”,

也就是b-quote,雖然他也有code可用,但似乎是隨布景而生效的,但是要多樣化的

顏色並支援各種語言,如C、HTML、bash諸如等 還是得要開外掛才行,

找了一下: WP-Syntax, Highlight Source Pro, Pygments for WordPress

這幾套算是普遍推薦,先是裝了WP-Sytntax感覺不錯,但格線的樣式不是很討喜,

且崁入Line Number後區塊末行留有空白,不知道是否因為與目前的佈景:DailyPost

有衝突造成的.

Highlight Source Pro使用上與WP-Syntax大致相同,都是用< pre >語法

框起來,只差Line Number參數WP-Syntax用line而HSP用class.

在找HSP時看到了Pygments for WP的評比是滿星,且又有內建佈景,但實際安裝

後,無法運作.trace系統error_log,發現到我的python對unicode的支援有問題

只好作罷,所以最後採用了Highlight Source Pro來做效果,

以下為測試範例,大學時作業系統的作業,C語言:

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//NHU CSIE 93109055 鄭源宇
//南華大學 資訊工程
 
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <sys/wait.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
#define SIZE 100000000
 
void doit(char *, clock_t);//沿用資料的resusg1.cc部分
int proc(void);//Processes 部分
int thre(void);//Threads 部分
void* thread_xs(void* unused);//Thread 要跑的函式
 
int main(void)
{
    clock_t start, end;
    struct tms t_start, t_end;
    int n,status;
    pid_t child;
 
    puts("      -= NHU CSIE 93109055 =-");
    puts("The Processes &amp; Threads Runing Please Wait.....");
 
    //用fork把要測驗的process與thread當成兩隻程式去run
    if((child=fork())== -1){
        perror("fork");
        exit(EXIT_FAILURE);
        }else if(child==0){//子程序
 
        start = times(&amp;t_start);
//      n=proc();
        n=thre();//驗證用,排除child先執行的影響
        end = times(&amp;t_end);
        //不設結束點讓迴圈外可以共同去run
        }else{//父程序
 
        start = times(&amp;t_start);
//      n=thre();
        n=proc();//驗證用,排除parent後執行的影響
        end = times(&amp;t_end);
        }
 
    printf("\n");
 
    //判斷是誰結束
    if(n==0){
        puts(" [The Threads]:") ;
    }else{
        puts(" [The Processes]:");
    }
 
    doit("   elapsed", end - start);//時間差
 
    puts("   parent times");
    doit("\t   user CPU", t_end.tms_utime);
    doit("\t  sys  CPU", t_end.tms_stime);//幾乎沒使用到系統時間.
 
    puts("   child times");
    doit("\t   user CPU", t_end.tms_cutime);
    doit("\t  sys  CPU", t_end.tms_cstime);//幾乎沒使用到系統時間.
 
    wait(&amp;status);//如父程序先結束,等待子程序完成
    exit(EXIT_SUCCESS);
}
 
void doit(char *str, clock_t time)
{
    /* Get clock ticks/second */
    long tps = sysconf(_SC_CLK_TCK);
 
    printf("%s: %6.2f secs\n", str, (float)time/tps);
}
 
int proc(void){
 
    pid_t child[50];
    int n,i,child_status;
 
    for(n=0;n<50;n++){
        if((child[n] = fork()) == -1) {
            perror("fork");
            exit(EXIT_FAILURE);
        } else if(child[n] == 0) {
            for(i=0;i<SIZE;i++)
               3*7;            
	    //printf("%d.child pid = %d  ",n+1 ,getpid());//偵錯用,顯示child_pid與序號.
            exit(EXIT_SUCCESS);//子程序運算終結後一定要結束掉child process本身.不然會往下執行剩下的程式.
        }//拿掉迴圈裡的父程序,不然會重複重複,重重複複又重複.故讓迴圈外的父程序去執行.
 
    }
 
/*    for(i=0;i<100000000;i++)//驗證父程序回應時間的正確性.
	3*7;*/
 
    //wait()似乎只願意等到第一隻child結束,所以要改用waitpid()去等待最後一個child結束
    child_status=waitpid(child[49],NULL,0);
 
/*關閉查驗child是否正常結束
    if (WIFEXITED(child_status))//資料上這部分的判斷反了,查書的結果正確應該是傳回值(不為零以下)
	printf ("the child process exited abnormally\n");
    else
	printf ("the child process exited normally, with exit code %d\n",WEXITSTATUS(child_status));
*/
    return child_status;
 
}
 
int thre()
{
    int i;
    pthread_t thread_id[50];
 
    for(i=0;i<50;i++)
        pthread_create(&thread_id[i], NULL, &thread_xs, (void*)i);//將i傳入是偵錯用.
 
    //等待執行緒均結束.
    for(i=0;i<50;i++)
        pthread_join(thread_id[i], NULL);
 
    return 0;
}
 
void* thread_xs(void* unused)
{
    int n;
    for(n=0;n<SIZE;n++)
	3*7;
    //printf("%d.thread  ",unused+1);//偵錯用,顯示thread建立序號.
 
}

Linux bash shell script, sleep sort:

#!/bin/bash
        function f() {
                sleep "$1"
                echo "$1"
        }
 
        while [ -n "$1" ]
        do
            f "$1" &amp;
            shift
        done
 
        wait

refer:
http://jinchishuxue.iteye.com/blog/1141847
http://speckyboy.com/2009/02/19/12-wordpress-plugins-to-display-and-highlight-code-within-your-blog/
http://blog.kno.at/tools/highlight-source-pro/
http://www.yzznl.cn/archives/242.html
 

Facebook Comments
Scottj Written by:

史考特 喜歡3C 愛拍照