亂貼小站公告欄
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>

int ia=10;

int main()
{
    int ib=10;
    pid_t new_pid;
    printf("pid=%d, ppid=%d, global=%d, local=%d\n",getpid(),getppid(),ia,ib);
    new_pid = fork();
    switch(new_pid)
    {
      case -1:
        printf("fork error!\n");
        break;
      case 0:
        printf("pid=%d, ppid=%d, global=%d, local=%d\n",getpid(),getppid(),ia,ib);
        ia++;
        ib++;
        printf("pid=%d, ppid=%d, global=%d, local=%d\n",getpid(),getppid(),ia,ib);
        break;
      default:
        wait(NULL);
        printf("pid=%d, ppid=%d, global=%d, local=%d\n",getpid(),getppid(),ia,ib);
        break;
    }
}

 

#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>

int main()
{
    if(fork()==0)
    {
      if(fork()==0)
      {
        printf("I'm child process C.\n");
        printf("C) PID: %d\tParent PID: %d\n",getpid(),getppid());
        return 0;
      }
      wait(NULL);
      printf("I'm child process B.\n");
      printf("B) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    if(fork()==0)
    {
      printf("I'm child process D.\n");
      printf("D) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    if(fork()==0)
    {
      printf("I'm child process E.\n");
      printf("E) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    wait(NULL);
    wait(NULL);
    wait(NULL);
    printf("I'm child process A.\n");
    printf("A) PID: %d\tParent PID: %d\n",getpid(),getppid());
}

 

#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>

int main()
{
    if(fork()==0)
    {
      if(fork()==0)
      {
        printf("I'm child process C.\n");
        printf("C) PID: %d\tParent PID: %d\n",getpid(),getppid());
        return 0;
      }
      wait(NULL);
      printf("I'm child process B.\n");
      printf("B) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    usleep(50);
    if(fork()==0)
    {
      printf("I'm child process D.\n");
      usleep(50);
      printf("D) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    if(fork()==0)
    {
      printf("I'm child process E.\n");
      usleep(50);
      printf("E) PID: %d\tParent PID: %d\n",getpid(),getppid());
      return 0;
    }
    wait(NULL);
    wait(NULL);
    wait(NULL);
    printf("I'm child process A.\n");
    printf("A) PID: %d\tParent PID: %d\n",getpid(),getppid());
}

文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()

jquery在google的一些在線資源

jquery是一個不錯的Js庫,相信也用得比較多,但是大家不可能在每一台自己用的電腦都本地下載一個jquery文件,而且jquery更新也比較多,版本之間多少有一些偏差。所以這就讓我們有點頭痛了,但是其實我們可以藉用GOOGLECODE的在線資料。

加載在線jquery最新版本:

如果你想使用jquery的最新版本,那麼你在文件中加載:

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js”></script>

就OK了,這是jquery的最新版本。如果你想用特定的版本那就用:

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>

上面是1.4.2版本的,如果你想用其它版本就把上面紅色的1.4.2換成你要的版本號就OK了。

在線查看jquery中文手冊:

http://jquery-api-zh-cn.googlecode.com/svn/trunk/xml/jqueryapi.xml

下載jquery中文手冊:

http://code.google.com/p/jquery-api-zh-cn/downloads/list


文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()

這個PHP程式是幫我弟寫的

主要用途,就是從給予的成大公告網頁上,分析演講的訊息

然後跳轉到 Google 日曆的新增行程畫面

以方便進行修改及新增

<?php
        ob_start();
    header('Content-type: text/html; charset=utf8');
        set_time_limit(1000);
        function tai_noEndl($html)
        {
                return str_replace(array("\n","\r","\t"),array("","",""),$html);
        }
        function tai_getHtml($url)
        {
        $html = tai_noEndl(file_get_contents($url));
        if(empty($html))tai_show('錯誤:網頁抓取失敗,請檢查網路。('.$url.')。');
                return $html;
        }
        if(isset($_POST['url']) && preg_match('`^http://[^/]+?ncku\.edu\.tw/`',$_POST['url']))
        {
                /* 原公告
                        http://cge.ncku.edu.tw/files/13-1024-83826.php
                */
                /* 目標網址
                https://www.google.com/calendar/b/0/render?
                        action=TEMPLATE
                        &text=講題:『熱度★夢想』--無樂不作的咖啡魂
                        &dates=20111102T193000/20111102T213000
                        &location=國際會議廳第一演講室
                        &details=主講人:王宏榮(紅龍)
                        &pli=1
                        &sf=true
                        &output=xml
                */
                $html = tai_getHtml($_POST['url']);
                //echo htmlspecialchars($html);
                unset($httpQueryArray);
                
                $httpQueryArray['action']='TEMPLATE';
                
                preg_match('`講題.*?(?:</div>|<br />|<br>)`i',$html,$text);
                $httpQueryArray['text']=preg_replace('`<[^>]*>`','',$text[0]);
                
                preg_match('`時間.*?(?:</div>|<br />|<br>)`i',$html,$dates);
                $dates=preg_replace('`<[^>]*>`','',$dates[0]);
                preg_match('`(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+)`',$dates,$dates);
                $dates[4]=(($dates[4]<8)?($dates[4]+12):$dates[4]);
                $dates[6]=(($dates[6]<8)?($dates[6]+12):$dates[6]);
                $httpQueryArray['dates'] = sprintf("%04d%02d%02dT%02d%02d00",$dates[1]+1911,$dates[2],$dates[3],$dates[4],$dates[5]).'/'.
                                                                   sprintf("%04d%02d%02dT%02d%02d00",$dates[1]+1911,$dates[2],$dates[3],$dates[6],$dates[7]);
                
                preg_match('`地點.*?(?:</div>|<br />|<br>)`i',$html,$location);
                $httpQueryArray['location']=preg_replace('`<[^>]*>`','',substr($location[0],9));
                
                preg_match('`主講人.*?(?:</div>|<br />|<br>)`i',$html,$details);
                $httpQueryArray['details']=preg_replace('`<[^>]*>`','',$details[0]);
                
                //echo '<a href="https://www.google.com/calendar/b/0/render?'.http_build_query($httpQueryArray).'">連結</a>';
                header('location:https://www.google.com/calendar/b/0/render?'.http_build_query($httpQueryArray));
                exit(0);
        }
?>
<h1>成功大學「通識教育生活實踐」認證講座網址輸入</h1>
<form action="" method="post">
        <input type="text" size="100" name="url" />
        <input type="submit" value="submit" />
</form>
        

文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()

轉載自:Google API 1.7.7

<?php
        function getCurrentUrl() 
        {
          global $_SERVER;

          /**
           * Filter php_self to avoid a security vulnerability.
           */
          $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);

          if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
                $protocol = 'https://';
          } else {
                $protocol = 'http://';
          }
          $host = $_SERVER['HTTP_HOST'];
          if ($_SERVER['SERVER_PORT'] != '' &&
                 (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
                 ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
                $port = ':' . $_SERVER['SERVER_PORT'];
          } else {
                $port = '';
          }
          return $protocol . $host . $port . $php_request_uri;
        }
?>

和風信使 發表在 痞客邦 留言(0) 人氣()

// WA
// BY taichunmin
// NCPC 2011 pb
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
int va[1000000];
int va_c;
int main()
{
        //freopen("pb.in","r",stdin);
        int ta;
        cin>>ta;
        string sa;
        while(ta--)
        {
                int ia,ib;
                cin>>ia;
                cin.get();
                getline(fin,sa);
                va_c=0;
                istringstream ssin(sa);
                while(ssin>>ib)
                {
                        bool ba=true;
                        for(int k=0;k<va_c;k++)
                                if(va[k]>=ib)
                                {
                                        va[k]=ib;
                                        ba=false;
                                        break;
                                }
                        if(ba)va[va_c++]=ib;
                }
                cout<<va_c<<endl;
        }
        return 0;
}

 

// WA
// BY taichunmin
// NCPC 2011 pd
#include<iostream>
#include<sstream>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int ia,ib;
struct ta_t
{
        string n;
        int v;
}attr[10];
int fa(string sa)
{
        bool is_num=true;
        for(int i=0;i<sa.size() && is_num;i++)
                if(!('0'<=sa[i] && sa[i]<='9')is_num=false;
        if(is_num)
        {
                istringstream ssin(sa);
                int temp;
                ssin>>temp;
                return temp;
        }
        else
        {
                for(int i=0;i<ia;i++)
                        if(attr[i].n==sa)return attr[i].v;
        }
        return 2147483647;
}
int main()
{
        //freopen("pd.in","r",stdin);
        int ta;
        cin>>ta;
        while(ta--)
        {
                cin>>ia>>ib;
                string sa,sname,sx,sy;
                for(int i=0;i<ia;i++)
                        cin>>attr[i].n>>attr[i].v;
                cin.get();
                bool ba=true;
                for(int i=0;i<ib;i++)
                {
                        getline(cin,sa);
                        if(!ba)continue;
                        istringstream ssin(sa);
                        ssin>>sname;
                        bool bb=true;
                        while(getline(ssin,sa,'('))
                        {
                                ssin>>sx;
                                getline(ssin,sy,')');
                                sy.erase(0,3);
                                //cout<<"sy = "<<sy<<endl;
                                if(fa(sx)<=fa(sy))
                                {
                                        bb=false;
                                        break;
                                }
                        }
                        if(bb)
                        {
                                ba=false;
                                cout<<sname<<endl;
                        }
                }
        }
}

 

// AC
// BY morris1028
// NCPC 2011 ph
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int A[100000],HASH[1000000],size;
struct Node{
        int v,s;
        int next;
}Node[200000];
int insHash(int v,int index)
{
        int m = v%1000000;
        if(HASH[m]==0) {
                size++;
                HASH[m]=size;
                Node[size].v=v, Node[size].s=index;
                Node[size].next=0;
                return -1;
        }
        int now=HSAH[m],pre=0;
        while(now)
        {
                if(Node[now].v>v || (Node[now].v==v && Node[now].s>index))
                        break;
                else pre=now, now=Node[now].next;
        }
        size++;
        if(pre == 0) HASH[m]=size;
        else Node[pre].next=size;
        Node[size].v=v,Node[size].s=index;
        Node[size].next=now;
        return -1;
}
int find(int v,int index)
{
        int m=v%1000000;
        int now=HASH[m], pre=0;
        while(now)
        {
                if(Node[now].v==v && Node[now].s>index)
                        return Node[now].s;
                else pre=now, now=Node[now].next;
        }
        return -1;
}
int Print(){
        int now, pre, i=0;
        for(int i=0;i<10;i++)
        {
                now=HASH[i];
                while(now)
                {
                        printf("(%d,%d)->",Node[now].v,Node[now].s);
                        pre=now, now=Node[now].next;
                }
                puts("===");
        }
        return 0;
}
int main(){
        //freopen("ph.in","r",stdin);
        int n,k,i;
        while(scanf("%d", &n)==1 && n) {
                for(i=0;i<n;i++)
                        scanf("%d",&A[i];
                memset(HASH, 0, sizeof(HASH));
                scanf("%d", &k);
                int sum=0,tmp;
                size=1;
                for(i=0;i<n;i++)
                {
                        A[i]%=k;
                        sum+=A[i];
                        sum%=k;
                        if(sum<0) sum+=k;
                        insHash(sum,i);
                }
                /* Print();*/
                sum=0;
                int flag=0;
                tmp=find(0,-1);
                if(tmp!=-1)
                {
                        printf("%d %d\n",1,tmp+1);
                        flag=1;
                }
                for(i=0;i<n;i++){
                        A[i]%=k;
                        sum+=A[i];
                        sum%=k;
                        if(sum<0) sum+=k;
                        tmp=find(sum,i);
                        /* printf("%d\n",tmp);*/
                        if(tmp!=-1 && flag==0)
                        {
                                printf("%d %d\n",i+2,tmp+1);
                                flag=1;
                                break;
                        }
                }
                if(flag==0)
                        printf("no solutions.\n");
        }
        return 0;
}
/*
7
2 5 1 -4 5 9 3
10
11 -3 1 13 -5 6 1 -8 -4 5
10
*/

 

// AC
// BY morris1028
// NCPC 2011 pk
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#define oo 2147483647
int map[1000][1000],Mt[1000];
int gcd(int x,int y)
{
        int t;
        while(y)
                t=x, x=y, y=t%y;
        return x;
}
int Used[1000], Time[1000], Ans;
int DFS(int T,int now,int start) {
        int last= oo,i,tmp,flag=0,ttry=0;
        Time[now] = T;
        /*printf("%d %d\n",now,T);*/
        for(i=0;i<Mt[now];i++){
                if(Used[map[now][i]]==0) {
                        used[map[now][i]]=1;
                        tmp=DFS(T+1, map[now][i],0);
                        if(tmp>=T) flag=1;
                        last=tmp<last?tmp:last;
                        ttry++;
                } else {
                        tmp=Time[map[now][i]];
                        last=tmp<last?tmp:last;
                }
        }
        if(start==1) {
                if(ttry>1)
                        Ans++;
        } else {
                Ans += flag;
        }
        /*printf("key : %d %d\nn", now,flag);*/
        return last;
}
int main() {
        //freopen("pk.in","r",stdin);
        int T,i,j,A[1001],n;
        scanf("%d",&T);
        while(T--)
        {
                scanf("%d",&n);
                for(i=0;i<n;i++)
                        scanf("%d",&A[i]);
                memset(map, 0, sizeof(map));
                memset(Mt, 0, sizeof(Mt));
                memset(Used, 0, sizeof(Used));
                memset(Time, 0, sizeof(Time));
                Ans=0;
                for(i=0;i<n;i++) {
                        for(j=i+1;j<n;j++) {
                                int tmp=gcd(A[i],A[j]);
                                if(tmp!=1) {
                                        map[i][Mt[i]++]=j;
                                        map[j][Mt[j]++]=i;
                                }
                        }
                }
                for(i=0;i<n;i++)
                        if(Used[i]==0) {
                                Used[i] =1,Time[i] = 1;
                                DFS(1,i,1);
                        }
                printf("%d\n",Ans);
        }
        return 0;
}

和風信使 發表在 痞客邦 留言(0) 人氣()

資料來源:http://php.net/manual/en/function.preg-match.php

<?php
$pattern = '`^((?P<protocol>[^:/?#]+):)?(//(?P<host>[^/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<label>.*))?`i';
$subject = 'http://example.com/defg/abcd/index.php?m=1&b=2#taichunmin';
preg_match($pattern,$subject,$match);
//可取用的資料如下
echo 'protocol = '  .$match['protocol']. '<br />';
echo 'host = '      .$match['host'    ]. '<br />';
echo 'path = '      .$match['path'    ]. '<br />';
echo 'query = '     .$match['query'   ]. '<br />';
echo 'label = '     .$match['label'   ]. '<br />';
?>

文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()

引用自:http://blog.miniasp.com/post/2008/11/17/Using-Netsh-Command-Line-Utility-to-switch-TCP-IP-settings.aspx


有時後帶著筆記型電腦(Notebook)到處跑時,時常都要切換網路卡的 TCP/IP 設定,每次都透過介面切換也實在很煩。例如說上週人在機房安裝主機時,因為網路切了 vLan 導致 Notebook 要搬來搬去的,每次都要改 IP 很麻煩,還好我寫了個批次檔幫我快速切換 IP 位址,果然省時、省力、又方便。

首先,我先介紹如何設定網路介面到 DHCP 模式

1. 先查到你的網路卡介面名稱,如下圖示,你的名稱就是【區域連線】四個字。

2. 再利用記事本(Notepad)開啟一份新文件,並且命名為 SwitchToDHCP.bat

3. 輸入以下指令碼(由於 Windows XP 與 Windows Vista 的指令有些差異,因此分開列表)

  • Windows 2000 / XP / 2003

netsh interface ip set address "區域連線" source=dhcp
netsh interface ip set dns     "區域連線" source=dhcp

  • Windows Vista / 2008

netsh interface ip set address   "區域連線" source=dhcp
netsh interface ip set dnsserver "區域連線" source=dhcp

再來,介紹如何設定網路介面到靜態 IP 模式

1. 先查到你的網路卡介面名稱,如上圖示。

2. 再利用記事本(Notepad)開啟一份新文件,並且命名為 SwitchTo公司內部IP.bat

3. 輸入以下指令碼(由於 Windows XP 與 Windows Vista 的指令有些差異,因此分開列表)

  • Windows 2000 / XP / 2003

netsh interface ip set address "區域連線" static 10.10.1.168 255.255.255.0 10.10.1.254 1
netsh interface ip set dns     "區域連線" static 10.10.1.1 primary

  • Windows Vista / 2008

netsh interface ip set address   "區域連線" static 10.10.1.168 255.255.255.0 10.10.1.254 1
netsh interface ip set dnsserver "區域連線" static 10.10.1.254 primary

和風信使 發表在 痞客邦 留言(0) 人氣()

%SystemRoot%\system32;

%SystemRoot%;

%SystemRoot%\System32\Wbem;

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\


和風信使 發表在 痞客邦 留言(0) 人氣()

需先安裝外掛模組 NppExec

第一次使用先按 F6

把下面的程式碼貼上

並自行更改 JSP_www 和 JSP_url

以後就只需要按 Ctrl + F6 即可直接看到結果

 

NPP_CONSOLE ?
npp_save
set JSP_www = C:\Tomcat 7.0\webapps\ROOT\
set JSP_url = http://localhost:8080/
cmd.exe /c copy /Y "$(FULL_CURRENT_PATH)" "$(JSP_www)$(FILE_NAME)"
cmd.exe /c start "" "$(JSP_url)$(FILE_NAME)"


文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()

下載網址:http://dl.dropbox.com/u/12113131/Install_Easy_run_class.msi

2011/10/05 v1.0.3更新:

 

  1. 將 .java 改為編譯並執行。
  2. 修改掉自動新增環境變數的 BUG。

 

2011/10/05 v1.0.3已知 BUG:

 

  1. 安裝程式在安裝前不會刪除舊版資料,使用者須先手動刪除,以免檔案仍為舊版。

 

 

其實,這個版本主要只是修bug而已...

感謝 SyneArt 幫忙,終於成功找到無法穩定找出 JDK 安裝路徑的問題所在。

另外,這個程式還額外使用了 Rapid Environment Editor 來做環境變數新增的工具。

目前這個程式只有在我自己的電腦試過...

希望徵求自願者阿XDD

不然我就只好對學弟下手了...

 

這個程式是為了 JAVA 的初學者寫的

希望能有很多人給我【我做得到的】意見阿~

好累喔~睡覺去


文章標籤

和風信使 發表在 痞客邦 留言(0) 人氣()