Monday, May 19, 2008

全国哀悼日

全国哀悼日

为表达全国各族人民对四川汶川大地震遇难同胞的深切哀悼,国务院决定,2008年5月19日至21日为全国哀悼日。在此期间,全国和各驻外机构下半旗志哀,停止公共娱乐活动,外交部和我国驻外使领馆设立吊唁簿。

根据这项宣布,5月19日14时28分起,四川大地震发生整整一周时,全国人民默哀3分钟,届时汽车、火车、舰船鸣笛,防空警报鸣响。

Tuesday, May 13, 2008

捐款

第一次拿出自己赚钱,分成两笔,捐给了香港红十字会,用做国内地震和缅甸风灾的振灾款。

以前在小学、中学时虽然也有过类似的捐款行为,但那时都是拿着父母的钱去捐。因此,现在可以靠着自己捐出一笔钱来,也算是有所进步吧。

至于为什么通过香港红十字会——一来,他们接受信用卡;二来,相对比较放心吧。

相应的,最近买咖啡机的计划只能推迟了。事有轻重缓急啊……

Wednesday, May 07, 2008

成绩险中求

期末考试的 Timetable 出来了,从 6 月 12 日考到 6 月 18 日。一个礼拜之内,考掉 4 门科目……而且最郁闷的是 6 月 16 日需要考两门,第一门 COMP9321:e-Commerce Implement Infrastructure 是从早上 8:45 到 12:00;而第二门 COMP9201:Operating Systems 则要从下午 13:45 到 16:00。

富贵险中求啊……哦,不,是成绩险中求。

晒晒考试时间表……

DayDateS.TimeE.TimeCourse
Thu12/06/200808:4512:00COMP9414:Artificial Intelligence
Mon16/06/200808:4512:00COMP9321:e-Commerce Impl. Infrastruct.
Mon16/06/200813:4516:00COMP9201:Operating Systems
Wed18/06/200808:4511:00COMP9331:Computer Networks&Applications

Saturday, May 03, 2008

Java 代码行数统计程序

用 Java 完成了一个 DNS Resolver 的作业程序。自我感觉结构写得还不错,便拿着到处和同学比测试速度和测试用例。到最后,实在是比无可比,便想到了比代码行数……

计算代码行数需要去除代码中多余的空白行和注释行。所幸 Cure 有用 Python 写过一个代码行数统计程序,便取过来,配合 Java 语法规则,做了些小修改。便完成了这个 Java 代码行数统计程序

使用该程序需要 Python 运行库支持,使用命令行,

python LineCount.py

在网上还找到一个代码语法高亮着色器,着色一下修改后的代码,贴出来看看效果。

import sys;
import os;

class LineCount:
    def trim(self, docstring):
        if not docstring:
            return ''
        lines = docstring.expandtabs().splitlines()
        
        indent = sys.maxint
        for line in lines[1:]:
            stripped = line.lstrip()
            if stripped:
                indent = min(indent, len(line) - len(stripped))
        
        trimmed = [lines[0].strip()]
        if indent < sys.maxint:
            for line in lines[1:]:
                trimmed.append(line[indent:].rstrip())
        
        while trimmed and not trimmed[-1]:
            trimmed.pop()
        while trimmed and not trimmed[0]:
            trimmed.pop(0)
        
        return '\n'.join(trimmed)
    
    def FileLineCount(self, filename):
        (filepath,tempfilename) = os.path.split(filename);
        (shotname,extension) = os.path.splitext(tempfilename);
        if extension == '.java':                            # file type 
            file = open(filename,'r');
            self.sourceFileCount += 1;
            allLines = file.readlines();
            file.close();
                
            lineCount    = 0;
            commentCount = 0;
            blankCount   = 0;
            codeCount    = 0;
            for eachLine in allLines:
                if eachLine != " " :
                    eachLine = eachLine.replace(" ", "");       # remove space
                    eachLine = self.trim(eachLine);             # remove tabIndent
                    if (eachLine.startswith("//")       == 1
                        or eachLine.startswith("*")     == 1
                        or eachLine.startswith("/*")    == 1
                        or eachLine.startswith("*/")    == 1):  # LINECOMMENT 
                        commentCount += 1;
                    else :
                        if eachLine == "":
                            blankCount += 1;
                        else :
                            codeCount += 1;
                lineCount = lineCount + 1;
            self.all        += lineCount;
            self.allComment += commentCount;
            self.allBlank   += blankCount;
            self.allSource  += codeCount;
            print filename;
            print '           Total      :',lineCount;
            print '           Comment    :',commentCount;
            print '           Blank      :',blankCount;
            print '           Source     :',codeCount;                        

    def CalulateCodeCount(self,filename):
        if os.path.isdir(filename) :
            if not filename.endswith('\\'):
                filename += '\\'; 
            for file in os.listdir(filename):
                if os.path.isdir(filename + file):
                    self.CalulateCodeCount(filename + file);
                else:
                    self.FileLineCount(filename + file);
        else:
            self.FileLineCount(filename);

    # Open File
    def __init__(self):
        self.all            = 0;
        self.allComment     = 0;
        self.allBlank       = 0;
        self.allSource      = 0;
        self.sourceFileCount= 0;
        filename = raw_input('Enter file name: ');
        self.CalulateCodeCount(filename);
        if self.sourceFileCount == 0 :
            print 'No Code File';
            pass;
        print '\n';
        print '*****************  All Files  **********************';
        print '    Files      :',self.sourceFileCount;
        print '    Total      :',self.all;
        print '    Comment    :',self.allComment;
        print '    Blank      :',self.allBlank;
        print '    Source     :',self.allSource;
        print '****************************************************';

myLineCount = LineCount();

Recommends

Douban Lists

I have READed, LISTENed, or WATCHed these...