2007年3月18日 星期日

快失業了

今天考完清大資工所,總算我的大學考試到了一個段落,至於會不會有學校可念,說真的我不敢期望!昨兒考完交大資工所後,心情很失落,實在是我最想進的學校還是宅宅大學,畢竟論起網路或學習資源來說,交大是首選,只是,似乎老天不怎眷顧?或許更該說,我的努力還不夠吧?反正若有機會備上任何一間學校,我會更加珍惜。 昨天考完後,心情幾番失落,有了很深刻的體悟,在此就稍微列下幾筆:

大四末,深感學校之資源與機會的廣闊,深深體會,原來我大學的小小成就,都是因為環境跟資源所付予的成果,若沒了環境,就沒了我!明瞭此事,開始看重研究所,畢竟在這之前,我對研究所的生活覺得只是像不斷地做專題的行為,隨後有學長稍微點到,還有學習新知識。

大五末,將進入第二十四個夏天,我驚覺自己人生的五分之一竟然是在大學渡過!當研究所考試不順之後,我發覺我的學習可能因此而停頓!或許去年某個人還差我一大截,但現在的他,在研究所少說也混了半年,而我在這年卻沒有進步!最深的體會,是對於硬體課程的學習,「沒有一間企業,會像學校那樣地教導!」最重要的是,有些課程所需的資源,不是一個人、一個普通的家庭可以負擔的!

因此!我打算利用所剩的幾個月的學生生活,好好地地將過去大學課程,覺得有意義但學習混水摸魚的課程,紮實地重新復習!儘管未來我可能從事的不是資訊業,但至少,我會保留對大學學習之路的感謝。

[Java] Socket



public class SocketServerTest implements java.lang.Runnable{
private int PORT = 52288;
private java.net.ServerSocket server = null;
private boolean shutdown = false;
public void run(){
try{
server = new java.net.ServerSocket(PORT);
try{
while(!shutdown){
java.net.Socket socket = server.accept();
try{
//非 140.113 就關掉
if( (( ((socket.getInetAddress()).getHostAddress()).substring(0,8)).compareTo("140.113.") != 0 ) ){
socket.close();
continue;
}

String datain = null;
java.io.BufferedReader in = new java.io.BufferedReader( new java.io.InputStreamReader( socket.getInputStream(),"UTF-8" ) );
datain = in.readLine();
}catch(java.net.SocketException e){
//socket關掉
}catch(java.lang.NullPointerException e){
//in.readLine()
}finally{
socket.close();
}
}
}catch(java.net.SocketException e){
//socket關掉
}finally{
server.close();
}
}catch(java.net.SocketException e){
//socket關掉
}catch(Exception e){
e.printStackTrace();
}
}
}

[Java] 與 MySQL 溝通




class dbMySQL{

final private String dbDriver = "com.mysql.jdbc.Driver";

public String dbAddress = null;

public String dbName = null;

public String dbUrl = null;

public String dbUser = null;

public String dbPasswd = null;

dbMySQL(String db_url,String db_name,String db_user,String db_passwd){

setupDB(db_url,db_name,db_user,db_passwd);

}

public void setupDB(String url,String dbname,String dbuser,String dbpasswd){

dbAddress = url;

setupDBUser(dbuser,dbpasswd);

setupDBName(dbname);

}

private void setupDBName(String dbname){

dbName = dbname;

//dbUrl = "jdbc:mysql://"+dbAddress+":3306/"+dbName+"?useUnicode=true&characterEncoding=Big5";

dbUrl = "jdbc:mysql://"+dbAddress+":3306/"+dbName+"?useUnicode=true&characterEncoding=utf-8";

}

private void setupDBUser(String dbuser,String dbpasswd){

dbUser = dbuser;dbPasswd = dbpasswd;

}

public java.sql.ResultSet SQLquery(String cmd){

try{

Class.forName(dbDriver);

java.sql.Connection con = java.sql.DriverManager.getConnection(dbUrl, dbUser, dbPasswd);

if(!con.isClosed()){

java.sql.PreparedStatement pstmt = con.prepareStatement(cmd);

java.sql.ResultSet rs = pstmt.executeQuery();

con.close();

return rs;

}

}catch(java.lang.ClassNotFoundException e){

e.printStackTrace();//Can't find: "+dbDriver+"

}catch(java.sql.SQLException e){

e.printStackTrace();

}

return null;

}

public String SQLupdate(String cmd){

try{

Class.forName(dbDriver);

java.sql.Connection con = java.sql.DriverManager.getConnection(dbUrl, dbUser, dbPasswd);

if(!con.isClosed()){

java.sql.PreparedStatement pstmt = con.prepareStatement(cmd);

pstmt.executeUpdate();

con.close();

return "OK";

}

}catch(java.lang.ClassNotFoundException e){

e.printStackTrace();

}catch(java.sql.SQLException e){

e.printStackTrace();

}

return "NO";

}

}



/* 使用方式
class Test{
private dbMySQL DB = null;
public Test(String db_url,String db_name,String db_user,String db_passwd){
DB = new dbMySQL(db_url,db_name,db_user,db_passwd);
DB.SQLupdate("DELETE From `MySQL_Table_Name`");

java.sql.ResultSet SQLrs =null;
SQLrs = DB.SQLquery("SELECT * FROM `MySQL_Table_Name`");
if(SQLrs != null){
while(SQLrs.next()){
//因為是用 UTF-8 存的, 所以讀出來要轉成 Big5
String data = new String( SQLrs.getString("欄位名字").getBytes(), "Big5");
}
}
}
}
*/


[Perl] 跟MySQL溝通




use DBI;



$dbh = DBI->connect('dbi:mysql:database=DM;host=140.113.55.66','5566','7788');

$sql = "select count(*) from `Games` Where `GameID`='55667788'";

$sth = $dbh->prepare($sql);

$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";

#output database results

#while (@row=$sth->fetchrow_array){ print "@row\n" }

@row=$sth->fetchrow_array;

print "@row[1]\n";


[Perl] 檔案處理與簡單的判斷例子





# 檔案位置


$wwwshow="/home/user/public_html/test.htm";





# 開檔失敗,則會換成執行後面那段話


open(FD_In,$wwwshow) || die "Can't open file: $!" ;





while( defined($LineIn = ) ){


# 若有出現溫度跟F的符號,進行切字的笨手段


if($LineIn =~ /°F/){


# get thermometer F;


@tmp01Line = split($splittoken01_a,$LineIn);


@tmp02Line = split($splittoken01_b,$tmp01Line[1]);


$thermometerF{$location[$i]} = $tmp02Line[0];


$thermometerC{$location[$i]} = ($thermometerF{$location[$i]} - 32) * 5 / 9;


# get thermometer Feel Like F;


@tmp01Line = split($splittoken02_a,$LineIn);


@tmp02Line = split($splittoken02_b,$tmp01Line[1]);


$thermometerFeelLikeF{$location[$i]} = $tmp02Line[0];


$thermometerFeelLikeC{$location[$i]} = ($thermometerFeelLikeF{$location[$i]} - 32) * 5 / 9;


# get weather


@tmp01Line = split($splittoken03_a,$beLine);


@tmp02Line = split($splittoken03_b,$tmp01Line[1]);


$weather{$location[$i]} = $tmp02Line[0];


}elsif($LineIn =~ /$splittoken04/){


@tmp01Line = split($splittoken04_a,$LineIn);


@tmp02Line = split($splittoken04_b,$tmp01Line[1]);


$updatetime{$location[$i]} = $tmp02Line[0];


# last 指的就是 C/C++ 中的 break


last;


}


$beLine = $LineIn;


}


close(FD_In);


# 把檔案刪掉


unlink($wwwshow);





# 開檔準備寫入


open(WEATHER,">$wwwshow") || die "Can't open file: $!" ;


print WEATHER "Weather Information\n";


close(WEATHER);