2010年12月31日星期五

WORD表格数据填充的宏(VBA)

Sub PasteToCells()
'
' PasteToCells 宏
'
    Dim TargetRange As Range
    Dim oTargCell As Cell

    If Selection.Cells.Count = 0 Then
        'Quit if no cells in selection
        MsgBox "No cells selected", vbCritical
        Exit Sub
    End If
    On Error Resume Next
    Set TargetRange = Selection.Range
    For Each oTargCell In Selection.Cells
        oTargCell.Range.Paste
    Next oTargCell
    TargetRange.Select

    Selection.EscapeKey
    Selection.EscapeKey
   
End Sub

Sub PasteToCellsStart()
    Dim TargetRange As Range
    Dim oTargCell As Cell
    Dim PasteRange As Range

    If Selection.Cells.Count = 0 Then
        'Quit if no cells in selection
        MsgBox "No cells selected", vbCritical
        Exit Sub
    End If
    On Error Resume Next
    Set TargetRange = Selection.Range
    For Each oTargCell In Selection.Cells
        Set PasteRange = oTargCell.Range
        PasteRange.Collapse wdCollapseStart
        PasteRange.Paste
    Next oTargCell
    TargetRange.Select
End Sub

Sub PasteToCellsEnd()
    Dim TargetRange As Range
    Dim oTargCell As Cell
    Dim PasteRange As Range

    If Selection.Cells.Count = 0 Then
        'Quit if no cells in selection
        MsgBox "No cells selected", vbCritical
        Exit Sub
    End If
    On Error Resume Next
    Set TargetRange = Selection.Range
    For Each oTargCell In Selection.Cells
        Set PasteRange = oTargCell.Range.Characters.Last
        PasteRange.Collapse wdCollapseStart
        PasteRange.Paste
    Next oTargCell
    TargetRange.Select
End Sub

两个Excel宏,方便统计数据

第一个,将选中的单元格中的数据合并到第一个单元格中,并清除其他单元格

第二个,将选中的单元格中的数据相加,结果到第一个单元格中,并清除其他单元格

Sub LinkCells()
    Dim cell As Object
    Dim count As Long
    Dim str As String
    str = ""
    count = 0
    For Each cell In Selection
        If str = "" Then
            str = str & cell.Value
        Else
            str = str & "," & cell.Value
        End If
        cell.Value = ""
    Next cell
    
    Cells(Selection.Row, Selection.Column).Value = str
End Sub


Sub AddCells()
    Dim cell As Object
    Dim count As Long
    Dim str As Integer
    str = 0
    count = 0
    For Each cell In Selection
       str = str + CInt(cell.Value)
       cell.Value = ""
    Next cell
    
    Cells(Selection.Row, Selection.Column).Value = str
End Sub

2010年12月22日星期三

mysql支持多表联合更新,真是方便

 

update student,statistic set student.score1=statistic.score1 where student.paperid=statistic.paperid and student.score1 is NULL

用存储过程检查用户登录

BEGIN
    DECLARE studentName,iip VARCHAR(16);
    DECLARE iContestId,LoginFlag,iPaperId,iMinutes INT;
    DECLARE stime datetime;
    DECLARE ntime datetime DEFAULT NOW();
    DECLARE bGameOver bit;

    select starttime,minutes into stime,iMinutes from contests where current=1;
    if stime-ntime>300 THEN
        SELECT '离考试开始时间超过5分钟,不允许用户登录!' as msg;
    else
        select stuname,contests.testid,student.login,student.starttime,paperid,gameover,ipadd into studentName,iContestId,LoginFlag,stime,iPaperId,bGameOver,iip from student,contests where student.stuid=studentid and student.password=passwd and student.contestid=contests.testid and contests.current=1;
        if (iContestId is null) THEN
            select '用户不存在或者密码错误!' as msg;
        ELSEIF bGameOver THEN
            SELECT '您已结束考试,不能再次进入考试!' as msg;
        ELSEIF LoginFlag=1 and ip<>iip THEN
            SELECT '用户已经登录考试,不能重复登录!' as msg;
        ELSEIF iPaperId is null THEN
            SELECT '试卷不存在!' as msg;
        ELSEIF stime is null THEN
            #改变用户登录标志为已登录
            #记录该用户的考试开始时间
            update student set login=1,starttime=ntime,ipadd=ip where student.stuid=studentid and contestid=iContestId;
            #返回登录成功信息,学生姓名,考试编号,试卷编号,考试开始时间,考试时长等信息
            select 'success' as msg,studentName as sname,iContestId as testid,iPaperId as paperid,ntime as starttime,iMinutes as minutes;
        ELSE
            #改变用户登录标志为已登录
            #考生换机,扣除已使用时间,开始考试时间不变
            update student set login=1,ipadd=ip where student.stuid=studentid and contestid=iContestId;
            #返回登录成功信息,学生姓名,考试编号,试卷编号,考试开始时间,剩余考试时长等信息
            select 'success' as msg,studentName as sname,iContestId as testid,iPaperId as paperid,stime as starttime,iMinutes as minutes;
        END IF;
    END IF;
END

 

小插曲:

一开始的时候存储过程写错了,红色部分写成了student.stuid=stuid ,结果记录的总是最后一个人的登录IP和登录时间,然后当用户重新登录时,因为IP不一样,总是登录不到考试系统中去

计算考试剩余时间

        String start = (String) session.getAttribute("StartTime");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(start);
        } catch (ParseException e) {
            throw new ServletException(e);
        }

        Calendar c = Calendar.getInstance();

        long escape = (c.getTimeInMillis() - date.getTime()) / (1000 * 60);
        long remain = (Integer) session.getAttribute("Minutes") - escape;

mysql存储过程中的一些问题

 

1、必须给数据库用户super权限,否则无法执行存储过程。用root用户创建的存储过程,其他用户在调用时必须在数据库url上加上参数,比较完整的url如下:

jdbc:mysql://10.28.79.2:3306/cbbt?noAccessToProcedureBodies=true

2、在存储过程中的select中使用in子句,以及select返回多条记录的时候的处理方法

BEGIN
    DEClare qid,qtype,qscore int;
    DECLARE stopFlag int DEFAULT 0;
    DECLARE qtitle,qoa,qob,qoc,qod,qans varchar(1000);
    DECLARE qnum int DEFAULT 1;
   

#定义游标

    DECLARE Que_ResultSet CURSOR FOR select tid,title,optiona,optionb,optionc,optiond,type,answer,score,type from problems WHERE FIND_IN_SET(tid,ids) ORDER BY tid;
    DECLARE CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;

    set stopFlag=0;

    OPEN Que_ResultSet;

    REPEAT
        FETCH Que_ResultSet INTO qid,qtitle,qoa,qob,qoc,qod,qtype,qans,qscore,qtype;
        IF NOT stopFlag then  #没有这行的话,最后一条记录会重复两次
            BEGIN
                if qtype=1 or qtype=2 THEN
                    insert into panswer(paperid,problemid,answer,score,type) values(pid,qnum,qans,qscore,qtype);
                ELSE
                    insert into panswer(paperid,problemid,answer,score,type) values(pid,qnum,qoa,qscore,qtype);
                end IF;
                set qnum=qnum+1;
            END;   
        end if;
    UNTIL stopFlag = 1 END REPEAT;

    CLOSE Que_ResultSet;

    select tid,title,optiona,optionb,optionc,optiond,type from problems WHERE FIND_IN_SET(tid,ids) ORDER BY tid;
END

在线考试系统

最近做了一个非常简单的在线考试系统:JSP+Servlet+mysql+ajax+存储过程,把一些遇到的问题发到这里记录一下

2010年12月16日星期四

java中调用mysql存储过程

 

有参数的情况

CallableStatement cstmt=conn.prepareCall("{call hasContest(?)}");
cstmt.registerOutParameter(1, Types.BOOLEAN);
cstmt.execute();
boolean b=cstmt.getBoolean(1);

 

无参数的情况

CallableStatement cstmt=conn.prepareCall("{call hasContest}");
ResultSet rs=cstmt.executeQuery();
rs.next();
return rs.getBoolean(1);

 

给定的数据库用户必须具有执行的权限,同时在数据的url中要添加参数,如下所示

jdbc:mysql://10.28.79.2:3306/cbbt?noAccessToProcedureBodies=true

2010年7月5日星期一

0day标题中的含义及DVDScr, Screener,TS, TC等常见术语

 

    NFO文件名常识:

    Incl.Keygen—>包含有注册器
    keygen only—>只含注册器
    WinALL—>适用于所有版本Windows操作系统(一般是指95 98 ME 2000 XP 2003)
    Trainer—>密技
    Cracked—>破解版本(对原文件进行了修改)
    MAC OSX—>Macintosh平台上的软件
    NUKED—>发布的内容违犯规则或存在问题因而被取消,别的小组可重新发布。
    Ebook—>电子书
    Repack /Proper—>重新打包/正确的(对上一个不成功的破解的修正)
    Plug in—>插件
    regged—>已阶⒉崃说能件
    retail—>零售版
    READ.NFO—>一般表示有某种特别说明
    DIRFIX nfo—>说明文件修正,一般只有一个nfo文件
    BiLiNGUAL—>双语版本
    MutilLiNGUAL—>多语言版本
    PHP.NULL—>PHP完整脚本程序
    ASP.NULL—>ASP完整脚本程序
    Incl.Patch—>带有破解补丁
    WORKING—>先前已有组织释放,但是不能完整工作,当前的释放是完整工作的。
    Licensed—>带有许可文件
    FiXED—>重新修正版
    Unlocker—>解锁补丁
    Cheats—>作弊修改器
    ALL.ACCESS.CHEAT—>通关秘籍

    电影文件名常识:

    PROPER—> 完美版
    DUPE—>与别的组织Release有重复
    UNRATE—>未删节(好)
    R-RATE—>有删节(不好)
    WS —>宽银幕版本的影片
    FS—>4:3
    全荧幕版本的影片(有些影片DVD中同时有WS和FS两种版本,Rip出来就要有两种Release)
    Bad IVTC —>画面有不可去处的拉丝(不好的版本)
    Bad Aspt —>画面比例不正常(不好的版本)
    LIMITED —>指在美国有限上映的片子,很多外国片都这样
    WITH EXTRAS—>带花絮
    INTERLACED—>隔行(可看见横的扫瞄线)
    NUKED—> 画质太差,被FTP的管理员废掉
    SUBED —>内嵌硬字幕(画面内不能消去)
    CAM—> 摄影机拍影院银幕,带有影院音响(夹带观众笑声,不好)
    Telesync, TS—>摄像机拍影院银幕,从影院放映机直接接线输出
    Telecine, TC—> 胶版,直接转电影拷贝,转电影拷贝
    DVD SCREENER —>用于观摩或展示的DVD
    SCREENER, SCR —>用于观摩或展示录影带
    WORKPRINT,WP—>工作录影带(导演剪接版,与发行版不同 )
    Director Cut —>导演剪接版
    TDX—> 传统DivX制作规则,不符合规则就不会被接受或被NUKE
    INTERNAL—>不太符合TDX标准的作品,一些是自己做着玩,还有一些是那组织认为依照TDX无法做到满意的质量,但不依照TDX做又会被 NUKE,所以只好INTERNAL,有些比较值得收藏。

    STV—>指没有也不会有美国影院公映这部片,或者是在影院放映前已经在电视上放过
    OST—> 原声大碟
    PDA文件名常识

    其特定含义篇

    PPC2002 – –> 该软件所适用的操作系统,Pocket PC2002
    WM2003 —> 该软件所适用的操作系统,Windows Mobile 2003等同于Pocket
    PC2003

    ALL.PPC—> 适用于所有的Pocket PC系统,包括Pocket PC2000/Pocket
    PC2002/Pocket PC2003(Windows Mobile 2003)

    ARM、MIPS、SH3分别代表该软件只适用于基于ARM、MIPS、SH3处理器的Pocket PC

    PalmOS—> 该软件是为PalmOS系统开发的,

    其中PalmOS5 是代表该软件只适用于PalmOS 5.0系统及以上

    CLIE为Sony Clie设备专用版

    Treo 180/270/600分别为Handspring Treo机型专用版

    HIRES为专为拥有高分辨率屏幕(320*320)的机型设计

    SymbianOS 6/6.1/7 是代表该软件只适用于SymbianOS 6.0/6.1/7.0系统

    UIQ 是代表该软件适用于symbian7.0系统UIQ界面的机型,如Sony
    Ericsson的P800/P900和Motorola A920等

    JAVA 该软件为Java软件,需要支持Java的机型才能正常使用

    S60.Java 专为Nokia S60系列机型设计的Java软件(Nokia7650, Nokia3650,
    Nokia3310等)

    S40.Java 专为Nokia
    S40列机型设计的Java软件(Nokia6100,Nokia6610,Nokia6108,Nokia7210,Nokia7250等)

    其中如特指明N3650、N6600等则又为该机型所优化

    Smartphone 代表该软件适用于Windows Mobile Smartphone系统

    关于DVDScr, Screener,TS, TC等常见术语[转]

    从文件名"12.29.02.Lord.Of.The.Rings.The.Two.Towers.*SVCD*.*TS*.FTF"中可以知道什么信息呢?

    12.29.02表示发布的日期。
    Lord.Of.The.Rings.The.Two.Towers是电影的名字。
    *SVCD*表示发布的格式是SVCD
    *TS*表示影片的来源是TELESYNC (TS)。
    有很多网友问及SCREENER,TS,TC,PDVD是什么意思,以及质量如何。也看见有网友发表关于电影发布版本术语的解释,我觉得有不确切的地方。比如PROPER并不代表质量完美,TS或Telesync并非指从放影机转制。其实Telesync和CAM都是用digital
    camera或camcorder在影院录制(俗称枪版),质量起伏很大。
    下面是我从VCDQuality.com转摘的关于这些术语的解释。本人现在翻译了关于片源部分。中英文对照,因为错误总是难免的。

    翻译者:huaye at TLF BBS
    Source
    来源

    CAM –
    A cam is a theater rip usually done with a digital video
    camera. A mini tripod is sometimes used, but a lot of
    the time this wont be possible, so the camera make
    shake. Also seating placement isn’t always idle, and it
    might be filmed from an angle. If cropped properly, this
    is hard to tell unless there’s text on the screen, but a
    lot of times these are left with triangular borders on
    the top and bottom of the screen. Sound is taken from
    the onboard microphone of the camera, and especially in
    comedies, laughter can often be heard during the film.
    Due to these factors picture and sound quality are
    usually quite poor, but sometimes we’re lucky, and the
    theater will be fairly empty and a fairly clear signal
    will be heard.

    CAM通常是用数码摄像机从电影院盗录。有时会使用小三角架,但大多数时候不可能使用,所以摄像机会抖动。同时由于放摄像机的座位并非总是空的,使得有时拍摄不是水平的。如果后期剪裁很好,这很难看出,除非屏幕下方有字幕。由

    于声音是从摄像机自带的话筒录制,所以经常会录到观众的笑声等声音,尤其是喜剧片。因为这些因素,图象和声音质量通常都很差。但有时很幸运电影院相当空,这样会录到好一些的声音。

    TELESYNC (TS) –
    A telesync is the same spec as a CAM except it uses an
    external audio source (most likely an audio jack in the
    chair for hard of hearing people). A direct audio source
    does not ensure a good quality audio source, as a lot of
    background noise can interfere. A lot of the times a
    telesync is filmed in an empty cinema or from the
    projection booth with a professional camera, giving a
    better picture quality. Quality ranges drastically,
    check the sample before downloading the full release. A
    high percentage of Telesyncs are CAMs that have been
    mislabeled.

    除了使用外置的音源(一般是影院座椅上为听力不好的人设的耳机孔),TELESYSNC(TS)
    和CAM的标准是相同的。这个直接的音源并不能保证是好的音源,这是它因为受到很多背景噪音的干扰。很多时候TS是在空的影院录制,或是用专业摄像机在投影室录制,所以图象质量可能比CAM好。质量的起伏可能很大,在下载前最好查看SAMPLE。很大比例的TS是从CAM错误标记成。

    TELECINE (TC) –
    A telecine machine copies the film digitally from the
    reels. Sound and picture should be very good, but due to
    the equipment involved and cost telecines are fairly
    uncommon. Generally the film will be in
    correct aspect ratio, although 4:3 telecines have
    existed. A great example is the JURASSIC PARK 3 TC done
    last year. TC should not be confused with TimeCode ,
    which is a visible counter on screen throughout the
    film.

    TELECINE (TC)
    使用电视电影机从胶片直接数字拷贝,其图象和声音质量应该很好。但由于使用的设备和费用很高,TC很少见。通常会使用正确的高宽比,但有时也有4:3的 TC。去年的侏罗纪公园III是一个很好的例子。不应将TC和TimeCode(时间码)混淆,时间码是一个在屏幕上可见的计数器。

    SCREENER (SCR) –
    A pre VHS tape, sent to rental stores, and various other
    places for promotional use. A screener is supplied on a
    VHS tape, and is usually in a 4:3 (full screen) a/r,
    although letterboxed screeners are sometimes found. The
    main draw back is a "ticker" (a message that scrolls
    past at the bottom of the screen, with the copyright and
    anti-copy telephone number). Also, if the tape contains
    any serial numbers, or any other markings that could
    lead to the source of the tape, these will have to be
    blocked, usually with a black mark over the section.
    This is sometimes only for a few seconds, but
    unfortunately on some copies this will last for the
    entire film, and some can be quite big. Depending on the
    equipment used, screener quality can range from
    excellent if done from a MASTER copy, to very poor if
    done on an old VHS recorder thru poor capture equipment
    on a copied tape. Most screeners are transferred to VCD,
    but a few attempts at SVCD have occurred, some looking
    better than others.

    SCREENER(SCR)是在电影发行VHS录象带之前送到录象出租店及其他地方用做促销目的。SCREENER使用VHS录象带,通常使用4:3(全屏)的高宽比,但有时也会有LETTERBOXED(1.85:1宽银幕)
    SCREENER. 主要的缺点是有“TICKER”(在屏幕下
    方滚动的消息,包含版权和反盗版电话号码)。同时,如果录象带包含任何序列号或可以导致查出录象带来源的记号,这些记号必须被遮掉,通常使用一个黑斑遮住上述部位。有时这些记号只出现几秒钟,有时也可能不幸在怎个电影中出现,而且有时会很大。根据使用的设备,SCREENER的质量可能是极好,如果是从原版拷贝;也可能很差,如果是从翻录的拷贝录制,同时又使用很烂的捕捉设备和录象机。大多数的SCREENER被转制成VCD,现在也出现了SVCD;有些看起来比

    另一些好。

    DVD-SCREENER (DVDscr) –
    Same premise as a screener, but transferred off a DVD.
    Usually letterbox , but without the extras that a DVD
    retail would contain. The ticker is not usually in the
    black bars, and will disrupt the viewing. If the ripper
    has any skill, a DVDscr should be very good. Usually
    transferred to SVCD or DivX/XviD.

    DVD-SCREENER(DVDscr)和SCREENER相似,但是从DVD转制。通常是1.85:1宽银幕,但是不包括零售版会有的花絮。 TICKER经常不在黑边里,所以会影响观看。如果转制者稍有技术,DVDScr应该很好。通常被转制成SVCD或DivX/XviD。

    DVDRip –
    A copy of the final released DVD. If possible this is
    released PRE retail (for example, Star Wars episode 2)
    again, should be excellent quality. DVDrips are released
    in SVCD and DivX/XviD.

    DVDRip是从最终版的DVD转制。如果可能,应该是使用预售版(比如,星球大战2)。质量应该很好。通常被发布成SVCD或DivX/XviD

    VHSRip –
    Transferred off a retail VHS, mainly skating/sports
    videos and XXX releases.

    VHSRip是从零售版VHS录象带转制,主要是滑冰/体育内容和XXX发布。

    TVRip –
    TV episode that is either from Network (capped using
    digital cable/satellite boxes are preferable) or PRE-AIR
    from satellite feeds sending the program around to
    networks a few days earlier (do not contain "dogs" but
    sometimes have flickers etc) Some programs such as WWF
    Raw Is War contain extra parts, and the "dark matches"
    and camera/commentary tests are included on the rips.
    PDTV is capped from a digital TV PCI card, generally
    giving the best results, and groups tend to release in
    SVCD for these. VCD/SVCD/DivX/XviD rips are all
    supported by the TV scene.

    从电视(最好是从数码有线电视/卫星电视捕捉)转制的电视剧,或接收由卫星提前几天向电视网传送的预播节目(不包含加密但有时有雪花)。有些节目,比如 WWF
    RAW IS WAR包含多余的部分;"DARK
    MATCHES"和CAMERA/COMMENTARY测试被包含在TVRip里。PDTV是从PCI数码电视卡捕捉,通常效果最好;破解组织倾向于使用 SVCD来发布。VCD/SVCD/DivX/XviD
    rips也都被用于发布TVRip。

    WORKPRINT (WP) –
    A workprint is a copy of the film that has not been
    finished. It can be missing scenes, music, and quality
    can range from excellent to very poor. Some WPs are very
    different from the final print (Men In Black is missing
    all the aliens, and has actors in their places) and
    others can contain extra scenes (Jay and Silent Bob) .
    WPs can be nice additions to the collection once a good
    quality final has been obtained.

    WORKPRITN
    (WP)是从未完成的电影拷贝转制而成,可能会缺失镜头和音乐。质量可能从最好到很差。有些WP可能和最终版本相差很远。(MEN
    IN BLACK的WP丢失了所有的外星人,代之以演员);另一些则包括多余的镜头(Jay and Silent
    Bob). WPs可以作为有了好质量的最终版本后的附加收藏。

    DivX Re-Enc –
    A DivX re-enc is a film that has been taken from its
    original VCD source, and re-encoded into a small DivX
    file. Most commonly found on file sharers, these are
    usually labeled something like Film.Name.Group(1of2)
    etc. Common groups are SMR and TND. These aren’t really
    worth downloading, unless you’re that unsure about a
    film u only want a 200mb copy of it. Generally avoid.

    DivXRe-Enc是从原始VCD发布用DivX编码成的小一些的文件。通常可在文件共享网络找到。它们通常以 Film.Name.Group(1of2)等形式命名。常见的发布组织有SMR和TND。这些版本通常不值得下载,除非你不清楚某部电影,只想要 200MB的版本。一般应避免。

    Watermarks –
    A lot of films come from Asian Silvers/PDVD (see below)
    and these are tagged by the people responsible. Usually
    with a letter/initials or a little logo, generally in
    one of the corners. Most famous are the "Z" "A" and
    "Globe" watermarks.

    很多从Asian Silvers/PDVD
    (参看下面)来的电影带有制作人的标记。通常是一个字母,名字缩写或图标,位于屏幕一角。最有名的是"Z","A"和"Globe".

    Asian Silvers / PDVD –
    These are films put out by eastern bootleggers, and
    these are usually bought by some groups to put out as
    their own. Silvers are very cheap and easily available
    in a lot of countries, and its easy to put out a
    release, which is why there are so many in the scene at
    the moment, mainly from smaller groups who don’t last
    more than a few releases. PDVDs are the same thing
    pressed onto a DVD. They have removable subtitles, and
    the quality is usually better than the silvers. These
    are ripped like a normal DVD, but usually released as
    VCD.

    Asian Silvers /
    PDVD是亚洲盗版商发行影片的,通常被一些发布组织购买来当做他们自己的发布。Silvers很便宜,在很多国家都很容易找到。发布Silvers很容易,所以现在有很多发布,主要是由一些小的组织发布;这些组织通常发布几个RELEASE后就不见了。PDVD和Silver一样,不过是压在DVD上。 PDVD通常有外挂字幕,质量也比Silver好。PDVD象普通的DVD一样转制,但通常用VCD的格式发布。

    Scene Tags
    发布文件的标志

    PROPER –
    Due to scene rules, whoever releases the first Telesync
    has won that race (for example). But if the quality of
    that release is fairly poor, if another group has
    another telesync (or the same source in higher quality)
    then the tag PROPER is added to the folder to avoid
    being duped. PROPER is the most subjective tag in the
    scene, and a lot of people will generally argue whether
    the PROPER is better than the original release. A lot of
    groups release PROPERS just out of desperation due to
    losing the race. A reason for the PROPER should always
    be included in the NFO.

    根据发布规则,最先发布Telesync
    (TS)的组织赢得(TS发布的)比赛。但是,如果这个发布版本质量很差,同时另一组织有另一TS版本(或质量更好的同一片源),那么标记PROPER被加到目录上以避免重复。PROPER是一个最主观的标记,很多人会争论是否PROPER比原始发布版本好。很多发布组织只不过因为输掉了发布比赛而发布 PROPER。发布PROPER的原因因该总是包含在NFO文件里。

    SUBBED –
    In the case of a VCD, if a release is subbed, it usually
    means it has hard encoded subtitles burnt throughout the
    movie. These are generally in malaysian/chinese/thai
    etc, and sometimes there are two different languages,
    which can take up quite a large amount of the screen.
    SVCD supports switch able subtitles, so some DVDRips are
    released with switch able subs. This will be mentioned
    in the NFO file if included.

    对于VCD发布而言,SUBBED通常表示字幕被压进了电影。它们通常是马来语/中文/泰文等,有时有两种语言。它们可能占据了很大一部分屏幕。SVCD 支持外挂字幕,所以DVDRip用外挂字幕发布。这些信息可以在NFO文件中找到。

    UNSUBBED –
    When a film has had a subbed release in the past, an
    Unsubbed release may be released

    当一部电影曾经发布过有字幕的SUBBED版本,没字幕的UNSUBBED版本也可能发布。

    LIMITED –
    A limited movie means it has had a limited theater run,
    generally opening in less than 250 theaters, generally
    smaller films (such as art house films) are released as
    limited.

    LIMITED电影指该电影只在有限的电影院放映,通常少于250家。通常较小的电影(比如艺术电影)的发行是LIMETED。

    INTERNAL –
    An internal release is done for several reasons. Classic
    DVD groups do a lot of .INTERNAL. releases, as they wont
    be dupe’d on it. Also lower quality theater rips are
    done INTERNAL so not to lower the reputation of the
    group, or due to the amount of rips done already. An
    INTERNAL release is available as normal on the groups
    affiliate sites, but they can’t be traded to other sites
    without request from the site ops. Some INTERNAL
    releases still trickle down to IRC/Newsgroups, it
    usually depends on the title and the popularity. Earlier
    in the year people referred to Centropy going
    "internal". This meant the group were only releasing the
    movies to their members and site ops. This is in a
    different context to the usual definition.

    INTERNAL发布有几个原因。经典的DVD组织有很多.INTERNAL.发布版本,这样不会引起混淆。同时,低质量的发布会加以INTERNAL标记,这样不会降低发布组织的声誉,或由于已经发布的数量。INTERNAL发布可以正常的在组织的会员网站上获取,但没有其他网站管理员的要求它们不可以被交换到其他网站。一些TERNAL发布仍然流到IRC/NEWSGROUP,这通常取决于电影及其流行度。今年早些时候,人们把CENTROPY做为 INTERNAL。这表示发布组织只向其会员和网站管理员发布。这和其通常意思不同。

    STV –
    Straight To Video. Was never released in theaters, and
    therefore a lot of sites do not allow these.

    STV表示电影从未在电影院放映过就被发布,因此很多望网站不允许STV。

    ASPECT RATIO TAGS –
    These are *WS* for widescreen (letterbox) and *FS* for
    Fullscreen.

    *ws*表示宽银幕,*FS*表示全屏幕。

    RECODE –
    A recode is a previously released version, usually
    filtered through TMPGenc to remove subtitles, fix color
    etc. Whilst they can look better, its not looked upon
    highly as groups are expected to obtain their own
    sources.

    RECODE是以前已经发布过的版本,通常用TMPGenc编码过滤以去除字幕,纠正颜色等。虽然它们看起来好一些,但通常不认为这是好的行为因为发布组织应该去找他们自己的片源。

    REPACK –
    If a group releases a bad rip, they will release a
    Repack which will fix the problems.

    如果发布组织发布了一个坏的版本,他们会发布REPACK来解决这些问题。

    NUKED –
    A film can be nuked for various reasons. Individual
    sites will nuke for breaking their rules (such as "No
    Telesyncs") but if the film has something extremely
    wrong with it (no soundtrack for 20mins, CD2 is
    incorrect film/game etc) then a global nuke will occur,
    and people trading it across sites will lose their
    credits. Nuked films can still reach other sources such
    as p2p/usenet, but its a good idea to check why it was
    nuked first in case. If a group realise there is
    something wrong, they can request a nuke.

    一个发布可能因为多种原因被NUKE掉。有些网站会因为违犯他们的规则而NUKE发布(比如不允许发布TS版本)。但如果发布的版本有很大的问题(如20 分钟没有声音,CD2是错误的电影或游戏),那么所有的网站都会NUKE这个发布。在这些网站上交换NUKED版本的人会失掉他们的信誉。但NUKED发布仍然可以通过P2P/USENET传播,所以应该总是首先找到其被NUKE的原因以防万一。如果发布组织发觉他们的发布有问题,他们可以要求NUKE。

    NUKE REASONS :: this is a list of common reasons a film
    can be nuked for (generally DVDRip)
    常见的NUKE原因(通常是DVDRIP):

    ** BAD A/R ** :: bad aspect ratio, ie people appear too
    fat/thin
    错误的高宽比,即画面太胖或太瘦。
    ** BAD IVTC ** :: bad inverse telecine. process of
    converting framerates was incorrect.
    错误的反转电视电影TC。转换祯频不对。
    ** INTERLACED ** :: black lines on movement as the field
    order is incorrect.
    移动的黑线,由于field order不正确。

    DUPE –
    Dupe is quite simply, if something exists already, then
    theres no reason for it to exist again without proper
    reason.

    DUPE很简单。如果某个电影发布已有,那么没有合适的理由就不因该允许它的存在。

2010年6月5日星期六

[转]那个叫鲁迅的终于从教科书里滚蛋了

近来,由于人民教育出版社在新版语文教材中逐步剔除鲁迅的文章,引来一片争议,赞者有之,阻者有之。而笔者认为,在近年来对鲁迅话题经历了沉默、回避、冷淡的过程后,现在让其滚蛋,已经是时候了。
鲁迅之所以滚蛋,是因为那些曾经被其攻击、痛斥、讥讽、怜悯的人物又一次复活了,鲁迅的存在,让他们感到恐惧、惊慌、卑怯,甚至无地自容。
看看:
孔乙己们复活了。并且以一篇《‘茴’字有四种写法》的论文,晋级为教授、学者、国学大师;也不再提心吊胆地“窃书”了,而是平心静气地在网络上“窃文”了;不仅可以舒坦地“温一碗洒”,而且还能以其博导的诱惑力对“伊”来一把潜规则了,他岂能让鲁迅揭了他前世的底?!
“资本家的乏走狗”们复活了。尽管它们披上了精英、专家的外衣,但依然“看到所有的富人都驯良,看到所有的穷人都狂吠”,他们或装神弄鬼地玩弄数字游戏,鼓吹物价与美国接轨、工资与非洲接轨的必然性与合理性;或干脆作了外国人欺诈中国的“乏走狗”,与其里应外合、巧取豪夺。它们岂容鲁迅再一次把它打入水中?!
赵贵翁、赵七爷、康大叔、红眼阿义、王胡、小D们复活了。有的混入警察队伍,有的当上了联防队员、城管。披上制服兴奋得他们脸上“横肉块块饱绽”,手执“无形的丈八蛇矛”,合理合法地干起了敲诈勒索,逼良为娼的勾当。如果姓夏那小子在牢里不规矩,不用再“给他两个嘴巴”,令其“躲猫猫”足矣。想想,这些下做的勾当儿怎能让鲁迅这种尖刻的小人评说?!
阿Q们复活了。从土古祠搬到了网吧,但其振臂一呼的口号已经不是“老子革命了!”而是“老子民主了!”每天做梦都盼着“白盔白甲”的美国海军陆战队早一天杀过来,在中国建立民主。因为只要美国的“民主”一到,赵七爷家的钱财、吴妈、秀才老婆乃至未庄的所有女人就都是我的了!哼!而鲁迅却偏偏要我做个被世人嘲讽了数十年的冤死鬼,我岂能容你?!
假洋鬼子们复活了。这回干脆入了外籍,成了真洋鬼子。并且人模狗样儿地一窝锋地钻进“爱国大片”的剧组,演起了凛然正气、忧国忧民的仁人志士,让人好生不舒服。此种一边哽咽着颂扬祖国母亲,一边往向征中华文明的青铜大鼎里撒尿的举动,岂不是鲁迅杂文中的绝好素材?!
祥林嫂、华老栓、润土们复活了。他们依然逆来顺受,情绪稳定。因为“这人肉的筵宴现在还排着,有许多人还想一直排下去”,这样,必须要备足了餐料。而那些准备做餐料的人,本来可以闷在铁屋子里,一边听着小沈阳的笑话,一边麻木地死去,岂容鲁迅把他们唤醒,再一次经历烈火焚身的苦痛?!
那些“体格茁壮的看客们”复活了。他们兴致勃勃地围观那些“拳打弱女”、“棒杀老翁”、“少年溺水”、“飞身坠楼”的精彩瞬间,依旧“颈项都伸得很长,仿佛许多鸭,被无形的手捏住了的,向上提着”。哈哈,仅看客一类,被你伤害的人就太多了,因为中国人几乎都愿做看客!
鲁迅之所以滚蛋,是因为当今的社会不需要“投枪和匕首”,而需要赞歌、脂粉、麻药。正如陈丹青先生讲的“假如鲁迅精神指的是怀疑、批评和抗争,那么,这种精神不但丝毫没有被继承,而且被空前成功地铲除了。我不主张继承这种精神,因为谁也继承不了、继承不起,除非你有两条以上性命,或者,除非你是鲁迅同时代的人。最稳妥的办法是取鲁迅精神的反面:沉默、归顺、奴化,以至奴化得珠圆玉润”。
如果鲁迅赶上这个时代,对于“开胸验肺”、“以身试药”、“周公拍虎”、“黑窑奴工”、“处女卖淫”、“官员嫖幼”等一系列奇闻,又会写出多少辛辣犀利、锥骨入髓、令人拍案叫绝的杂文来,想想,真是让人后怕,所幸这个尖酸刻薄的小人已不在人世了。
让我们彻底赶走鲁迅,欢迎“小沈阳”,让人们在开心笑声中忘却现实的不公和苦痛,在笑声中渐渐地麻木、渐渐地变傻......

2010年5月7日星期五

Tomcat 5.5改变默认主目录

在server.xml中找到<Host name=”localhost” …>

添加 <Context path=”” docBase=”myprj” debug=”0” reloadable=”true” priviledged=”true />

如果要添加JDBC数据源,可以加入到Context中

2010年5月6日星期四

文本链接标签打开URL

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
            try { System.Diagnostics.Process.Start("http://antigw.blogspot.com"); }
            catch (Exception exp)
            {
                MessageBox.Show(String.Format("程序运行期间发生错误,错误信息:{0}", exp.Message));
            }
}

禁止C# TabControl中的某些标签页

 

private void ProgTab_Selecting(object sender, TabControlCancelEventArgs e)
{
                if (e.TabPageIndex == 1 || e.TabPageIndex == 2) e.Cancel = true;
}

 

第二种方法:

private void DisablePages()
{
    ProgTab.TabPages.Remove(tabPage2);
    ProgTab.TabPages.Remove(tabPage3);
    ProgTab.TabPages.Remove(tabPage4);
}

private void EnablePages()
{
    ProgTab.TabPages.Add(tabPage2);
    ProgTab.TabPages.Add(tabPage3);
    ProgTab.TabPages.Add(tabPage4);
}

将数据表的内容放到DataGridView中

 

DataTable dt = new DataTable();
string sql = String.Format("select [msgid],[teacher],[msgdate] from inbox where [msgdate] like '{0}%' and [userid]='{1}'",  date,   username);
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
da.Fill(dt);
dgvInbox.DataSource = dt;

c#获取数据库元数据

DataTable schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
foreach (DataRow dr in schemaTable.Rows)
{
      String tableName = dr["TABLE_NAME"].ToString();
      MessageBox.Show(tableName);
}

使用WebClient提交中文数据

 

            try
            {
                String url = "http://school.jxllt.com/family/famsmssend_action_new.asp";
                String data = "sel_recelist=" + teacher + "&txta_memo=" + msg;
                byte[] postData = Encoding.GetEncoding("GB2312").GetBytes(data);
                wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                byte[] res = wc.UploadData(url, "POST", postData);
            }
            catch (Exception exp)
            {
                MessageBox.Show(String.Format("程序运行期间发生错误,错误信息:{0}", exp.Message));
            }

2010年5月2日星期日

C#中的SqlBulkCopy将批量数据写入数据库

注意:ACCESS数据库不支持此操作

DataSet ds = new DataSet();
ds.ReadXml(new StringReader(sbuf.ToString())); //从字符串装载XML

DataTable mytable = ds.Tables[0];

//MessageBox.Show(mytable.Rows[1]["msgid"].ToString()); //将XML装载到DataSet后,可通过行和列来进行访问

SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(connStr, SqlBulkCopyOptions.UseInternalTransaction);
sqlbulkcopy.DestinationTableName = "inbox";
sqlbulkcopy.WriteToServer(ds.Tables[0]);

C#将XML中的数据存储到ACCESS数据库

using (OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=msg.mdb"))
            {
                cn.Open();
                using (OleDbCommand cmd = new OleDbCommand())
                {
                    cmd.Connection = cn;
                    cmd.CommandType = CommandType.Text;

                    XmlDocument xml = new XmlDocument(); //装载XML数据
                    xml.InnerXml = sbuf.ToString();

                    XmlNodeList xn = xml.GetElementsByTagName("message");

                    foreach (XmlElement xe in xn)
                    {
                        cmd.CommandText = string.Format(
                            "INSERT INTO inbox([msgid],[teacher],[content],[msgdate],[userid]) VALUES ('{0}', '{1}', '{2}', '{3}','{4}')",
                            xe.ChildNodes[0].InnerText.Trim(),
                            xe.ChildNodes[1].InnerText.Trim(),
                            xe.ChildNodes[2].InnerText.Trim(),
                            xe.ChildNodes[3].InnerText.Trim(),
                            username
                        );

                        cmd.ExecuteNonQuery();
                    }
                }
                cn.Close();
            }

C#将XLST转换的结果用字符串表示

StringBuilder sbuf = new StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new StringWriter(sbuf));
xslt.Transform(xdoc, null, writer);
writer.Close();

利用StringBuilder对象和StringWriter对象即可。

sbuf.ToString()可得到XML的字符串表示

2010年5月1日星期六

C#中的XSLT转换

StringReader txtReader;
txtReader = new StringReader(cleanedMarkUp);
XPathDocument xdoc = new XPathDocument(txtReader);

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("msg.xsl");
XmlTextWriter writer = new XmlTextWriter(new StreamWriter("d:/r.xml"));
xslt.Transform(xdoc, null, writer);
writer.Close();

XSLT中for-each的select语法问题

在一个程序中,要用到如下的XSL用于XSLT转换

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8"/>
<xsl:template match="/">
<messages>
    <xsl:for-each select="//tr[@bgcolor='#f3f2f1' and position()>=3 and position()<last()]">
        <message>
            <msgid>
                <xsl:value-of select="td[1]/div/input/@value"/>
            </msgid>
            <teacher>
                <xsl:value-of select="td[3]/div"/>
            </teacher>
            <content>
                <xsl:value-of select="td[4]/div"/>
            </content>
            <timestamp>
                <xsl:value-of select="td[6]/div"/>
            </timestamp>
        </message>
    </xsl:for-each>
</messages>
</xsl:template>
</xsl:stylesheet>

在.NET中报错,出错信息为:

未处理 System.Xml.Xsl.XslLoadException
  Message="XSLT 编译错误。"
  Source="System.Data.SqlXml"
  LineNumber=6
  LinePosition=81
  SourceUri="file:///D:/myprog/C%23/jxlltEasy/jxlltEasy/bin/Debug/msg.xsl"
  StackTrace:
       在 System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
       在 System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
       在 System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
       在 System.Xml.Xsl.XslCompiledTransform.CompileXsltToQil(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
       在 System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
       在 System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri)
       在 jxlltEasy.jxlltForm.btnRefresh_Click(Object sender, EventArgs e) 位置 D:\myprog\C#\jxlltEasy\jxlltEasy\jxlltForm.cs:行号 120
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 jxlltEasy.Program.Main() 位置 D:\myprog\C#\jxlltEasy\jxlltEasy\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Xml.XmlException
       Message="“<”(十六进制值 0x3C)是无效的属性字符。 行 6,位置 81。"

       Source="System.Xml"
       LineNumber=6
       LinePosition=81
       SourceUri="file:///D:/myprog/C%23/jxlltEasy/jxlltEasy/bin/Debug/msg.xsl"
       StackTrace:
            在 System.Xml.XmlTextReaderImpl.Throw(Exception e)
            在 System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
            在 System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
            在 System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
            在 System.Xml.XmlTextReaderImpl.ParseAttributes()
            在 System.Xml.XmlTextReaderImpl.ParseElement()
            在 System.Xml.XmlTextReaderImpl.ParseElementContent()
            在 System.Xml.XmlTextReaderImpl.Read()
            在 System.Xml.Xsl.Xslt.XsltInput.ReadNextSiblingHelper()
            在 System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
            在 System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChildAny()
            在 System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChild()
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadLiteralResultElement(Boolean asStylesheet)
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadTemplate(NsDecl stylesheetNsList)
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet()
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
            在 System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
       InnerException:

在Java中,出错信息为:

Fatal Error] :6:80: The value of attribute "select" associated with an element type "xsl:for-each" must not contain the '<' character.
Exception in thread "main" org.xml.sax.SAXParseException: The value of attribute "select" associated with an element type "xsl:for-each" must not contain the '<' character.
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at cn.ldsoft.xpath.XMLHelper.parseXMLFromInputSource(XMLHelper.java:70)
    at cn.ldsoft.xpath.XMLHelper.parseXMLFromFile(XMLHelper.java:62)
    at cn.ldsoft.simple.Test.main(Test.java:22)

通过查阅资料得知,

合法的过滤运算符:
  • =  (等于)
  • != (不等于)
  • &lt; (小于)
  • &gt; (大于)

将position()<last()改为position() &lt; last(), 问题解决

使用C#、XML和XPATH从HTML中提取特定标记的值

StringReader txtReader;
txtReader = new StringReader(cleanedMarkUp);
XPathDocument xdoc = new XPathDocument(txtReader);

XPathNavigator nav = xdoc.CreateNavigator();

nav.MoveToRoot();

XPathExpression expr = nav.Compile("//tr[@bgcolor='#f3f2f1']");

XPathNodeIterator node = nav.Select(expr);

while (node.MoveNext())
    MessageBox.Show(node.Current.Value);

使用TidyNET清理和转换HTML为XHTML

TidyNet(http://sourceforge.net/projects/tidynet/)是用c#编写的Tidy API,对字符支持比较好,不会出现像NTidy那样的乱码。

Tidy doc = new Tidy();
TidyMessageCollection tmc = new TidyMessageCollection();

            MemoryStream input = new MemoryStream();
            MemoryStream output = new MemoryStream();

            //Set some Tidy options, refer to the HTML Tidy docs for more info
            doc.Options.DocType = DocType.Strict;
            doc.Options.Xhtml = false;
            doc.Options.LogicalEmphasis = true;
            doc.Options.DropFontTags = true;
            doc.Options.DropEmptyParas = true;
            doc.Options.QuoteAmpersand = true;
            doc.Options.TidyMark = true;
            doc.Options.MakeClean = true;
            doc.Options.IndentContent = true;
            doc.Options.SmartIndent = true;
            doc.Options.Spaces = 4;
            doc.Options.WrapLen = 100;
            doc.Options.CharEncoding = CharEncoding.UTF8;
            doc.Options.XmlOut = true;

            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(restext);
            input.Write(byteArray, 0, byteArray.Length);
            input.Position = 0;
            doc.Parse(input, output, tmc);
            foreach (TidyMessage message in tmc)
            {
                if (message.Level == MessageLevel.Error)
                {
                    throw new ApplicationException(String.Format("{0} at line {1} column {2}",
                    message.Message, message.Line,
                    message.Column));
                }
            }

            string cleanedMarkUp = System.Text.Encoding.UTF8.GetString(output.ToArray());

使用NTidy工具清理和规范HTML为XHTML

 

NTidy(http://sourceforge.net/projects/ntidy/)是一个用C++编写的供.NET使用的tidy api. 将NTidy.dll添加到项目引用,并添加

using NTidy; 后即可使用

TidyDocument tdoc = new TidyDocument();
tdoc.LoadConfig("tidy.cfg");
tdoc.SetCharEncoding("gb2312");
TidyStatus status = tdoc.LoadString(restext);
tdoc.CleanAndRepair();

XmlDocument xmldoc = new XmlDocument();
xmldoc.InnerXml = tdoc.Root.Value;

问题:没有考虑编码的问题,中文会被自动转换为类似#C2C8;这样的Unicode编码。

tidy.cfg工具可通过TidyGUI工具(http://pagesperso-orange.fr/ablavier/TidyGUI/)生成。

// HTML Tidy configuration file created by TidyGUI
new-inline-tags: o:p
char-encoding: utf-8
doctype: strict
tidy-mark: no
word-2000: yes
output-xml: yes
output-xhtml: yes
add-xml-decl: yes
assume-xml-procins: yes

参考资料:

http://jeebook.com/blog/?p=606

让WebClient支持cookie和session

.NET中的WebClient组件,通过向网站发送登录请求成功后不能保持session。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace jxlltEasy
{
    class HttpClient : WebClient
    {
        // Cookie 容器
        private CookieContainer cookieContainer;

        /**/
        /// <summary>
        /// 创建一个新的 WebClient 实例。
        /// </summary>
        public HttpClient()
        {
            this.cookieContainer = new CookieContainer();
        }

        /**/
        /// <summary>
        /// 创建一个新的 WebClient 实例。
        /// </summary>
        /// <param name="cookie">Cookie 容器</param>
        public HttpClient(CookieContainer cookies)
        {
            this.cookieContainer = cookies;
        }

        /**/
        /// <summary>
        /// Cookie 容器
        /// </summary>
        public CookieContainer Cookies
        {
            get { return this.cookieContainer; }
            set { this.cookieContainer = value; }
        }

        /**/
        /// <summary>
        /// 返回带有 Cookie 的 HttpWebRequest
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                HttpWebRequest httpRequest = request as HttpWebRequest;
                httpRequest.CookieContainer = cookieContainer;
            }
            return request;
        }
    }
}

2010年4月18日星期日

[Microsoft SQL Server 2000]安装程序配置服务器失败,参考服务器错误日志和sqlstp.log了解更多信息

 

遇到了这个问题,解决的方法:

1、把原有的数据库文件备份,安装时不要指定原来的数据库数据目录。待安装完成后再附加数据库

2、再次安装时会遇到“以前进行的程序创建了挂起的文件操作,运行安装程序前,必须重新启动  ”,其实可以不重启动的:

  • 在开始->运行中输入regedit  
  • 到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session   Manager   位置  
  • 在右边窗口右击PendingFileRenameOperations,选择删除,然后确认  

2010年4月17日星期六

新版090论坛广告过滤脚本

 

// ==UserScript==
// @name           090广告过滤器 greasemonkey脚本
// @namespace      Filter::GM
// @include        http://bbs.wm090.com/*
// ==/UserScript==
(function(){
    var xpath = "//div[contains(@id,'ad_') or contains(@id,'Adv')]";
    remove(xpath);

    function remove(xpath){
        var el;
        var els = document.evaluate(xpath, document, null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        for (var i = 0; i < els.snapshotLength; i++) {
          el = els.snapshotItem(i);
          el.parentNode.removeChild(el);
        }
    }
}) ();

今天很囧很郁闷

 

一、囧事

囧,为了控制小孩上网,在宽带路由器中设置了MAC地址白名单,自己笔记本一直无线上网,今天想起用网线上网了,结果插上后网络不通,思考良久,才发现了原因所在。

这已经是第二次发生了,上次是一个iphone上wifi上网,结果死活上不了。。。

 

二、郁闷事

客户说系统用不了很慢。于是我今天去了,原来是他们换过主板但是没重新安装系统,结果新主板没win2000的驱动,又换回旧主板就出问题了。只好重新安装操作系统,好不容易把那块烂主板的网卡、声卡驱动程序全部找齐安装上。

发现没有SQL Server 2000的光盘,从网上下载了一个,花了一个小时,结果不能用。然后再下载,要3小时才行。明天还得去重新来过。

真是郁闷!

2010年4月16日星期五

线程安全的数据库连接管理器

package cn.cslg.xk.util;
/**
* @author 李庆
*@Email Kingstarforever@gmail.com
*@dtaeTime 2010-4-2
*/
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

public class ConnectionManger {

    private static ThreadLocal<Connection> connectionHoder = new ThreadLocal<Connection>();

    public static Connection getConnection() {
        Connection conn = connectionHoder.get();
        if (conn == null) {
            try {
                conn = JndiBean.getConnection();
                connectionHoder.set(conn);
                System.out.println(conn);
            } catch (Exception e) {
            e.printStackTrace();
                //throw new AppException("系统出现故障,请联系管理员!");
            }
        }
        return conn;
    }

    public static void closeConnection() {
        Connection conn = connectionHoder.get();
        if (conn != null) {
            try {
                conn.close();
                connectionHoder.remove();
            } catch (SQLException e) {
            }

        }
    }

    public static void rollback() {
        try {
            Connection conn = connectionHoder.get();
            if (conn != null) {
                conn.rollback();
            }
        } catch (SQLException e) {
        }
    }

    public static void setCommit(boolean b) {
        try {
            Connection conn = connectionHoder.get();
            if (conn != null) {
                conn.setAutoCommit(b);
            }
        } catch (SQLException e) {
        }

    }

    public static void Commit() {
        try {
            Connection conn = connectionHoder.get();
            if (conn != null) {
                conn.commit();
            }
        } catch (SQLException e) {
        }

    }

    public static void closePs(PreparedStatement ps) {

        try {
            if (ps != null) {
                ps.close();
            }
        } catch (SQLException e) {
        }
    }

    public static void closeRs(ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (SQLException e) {
        }
    }

    public static void closeStatment(Statement s) {

        try {
            if (s != null) {
                s.close();
            }
        } catch (SQLException e) {
        }
    }
}

2010年4月15日星期四

昨天帮忙解决的网络问题

Untitled-1

使用mysql++对mysql数据库表进行增删改查操作

和mysql connector/c++相比,只要在开始时设置好字符集,之后不需要进行转码操作。
conn.set_option(new mysqlpp::SetCharsetNameOption("gbk"));

//查询方法1
vector<mysqlpp::Row> v;
        query.storein(v);

        cout.setf(ios::left);
        cout<<setw(10)<<"username"<<setw(10)<<"password"<<endl;

        for (vector<mysqlpp::Row>::iterator it = v.begin(); it != v.end(); ++it) {
            cout<<setw(10)<<it->at(0)<<setw(10)<<it->at(1)<< endl;
        }

//查询方法2
mysqlpp::StoreQueryResult res = query.store();
        if(res){
            cout.setf(ios::left);
            cout<<setw(10)<<"username"<<setw(10)<<"password"<<endl;
            for (size_t i = 0; i < res.num_rows(); ++i)
                cout << setw(10) << res[i]["username"] << setw(10) << res[i]["password"] << endl;
        }else {
            cerr << "Failed to get stock table: " << query.error() << endl;
            return 1;
        }

//修改记录
query<<"update users set password='hello' where username='沈健'";
query.execute();

//插入
query<<"insert into users(username,password) values('飞翔','123456')";
query.execute();

//删除记录
query<<"delete from users where username='遨游'";
query.execute();

2010年4月13日星期二

使用mysql connector/c++对mysql进行增删改查操作

 

//查询
result = stmt->executeQuery("select * from users"); 
while(result->next()) 

    string username = result->getString("username"); 
    string password = result->getString("password"); 
    cout << utf2ansi(username) << " : " << password << endl;

//插入
string sql="insert into users(username,password) values('" + ansi2utf8(string("飞翔"))+ "','asdfgh')";
stmt->executeUpdate(sql);

//删除
sql="delete from users where id=4";
stmt->executeUpdate(sql);

//修改
sql="update users set password='hello' where username='" + ansi2utf8(string("沈健")) +"'";;
stmt->executeUpdate(sql);

查出来的数据需要转换成ANSI编码,传给mysql服务器的数据需要转换为unicode编码(mysql数据库中所建的数据库、表和字段采用utf-8编码)

下面是相应的转换函数

//将标准string(unicode)转换为string(ansi)
string utf2ansi(const string &src){
    int nLen = MultiByteToWideChar( CP_UTF8, 0, src.data(), -1, NULL, NULL );
    LPWSTR lpwsz = new WCHAR[nLen];
    MultiByteToWideChar( CP_UTF8, 0, src.data(), -1, lpwsz, nLen );

    int nLen1 = WideCharToMultiByte( CP_ACP, 0, lpwsz, nLen, NULL, NULL, NULL, NULL );
    LPSTR lpsz = new CHAR[nLen1];
    WideCharToMultiByte( CP_ACP, 0, lpwsz, nLen, lpsz, nLen1, NULL, NULL );
    string str(lpsz);
    delete []lpsz;
    return str;
}

//将标准string(ansi)转换为string(unicode)
string ansi2utf8(const string &src){
    int nLen = MultiByteToWideChar( CP_ACP, 0, src.data(), -1, NULL, NULL );
    LPWSTR lpwsz = new WCHAR[nLen];
    MultiByteToWideChar( CP_ACP, 0, src.data(), -1, lpwsz, nLen );

    int nLen1 = WideCharToMultiByte( CP_UTF8, 0, lpwsz, nLen, NULL, NULL, NULL, NULL );
    LPSTR lpsz = new CHAR[nLen1];
    WideCharToMultiByte( CP_UTF8, 0, lpwsz, nLen, lpsz, nLen1, NULL, NULL );
    string str(lpsz);
    delete []lpsz;
    return str;
}

2010年4月12日星期一

使用mysql connector/C++进行数据库编程的几个注意点

 

1、环境准备

下载mysql connector/c++并解压

2、在项目设置中

(1)项目属性,配置属性,C/C++,常规,附加包含目录:将第一步解压出来的目录中的include和include/cppconn添加进去

(2)项目属性,配置属性,链接器,输入,附加依赖项:mysqlcppconn.lib mysqlcppconn-static.lib libmysql.lib

(3)项目属性,配置属性,链接器,常规,附加库目录:将第一步解压出来的目录中的lib目录添加进去

(4)编译项目

(5)运行时,需要将mysqlcppconn.dll libmysql.dll复制到生成可执行文件的目录下

使用mysql++进行数据库编程时的几个注意点

 

1、mysql++的准备

http://tangentsoft.net/mysql++/releases/mysql++-3.0.9.tar.gz下载源代码,解压缩后,用VS2008打开VS2008文件夹中的解决方案文件(sln),注意此时要用到mysql的include目录和libmysql.lib,如果你在本机上安装了mysql数据库,则可以从安装目录中找到,将include和libmysql.lib添加到项目的额外的包含文件目录和库文件目录中,并在链接选项的输入中键入 libmysql.lib。如果不想安装mysql服务器,也可以下载mysql connector C driver,其中也包含了相应的文件。

设置好之后编译mysql++,如果无误。双击运行其中的install.hta完成安装过程。

2、使用mysql++的项目的相关设置

(1)添加额外的包含文件目录:

  • mysql++的include目录
  • mysql server的include目录

(2)添加额外的库文件目录,并将 libmysql.lib mysqlpp_d.lib 加入到 链接器|输入|附加依赖项中

(3)编译代码

(4)运行时要将libmysql.dll和mysqlpp_d.dll放到生成的可执行文件的文件夹下

使用mysql++连接mysql数据库进行数据查询

#include <iostream>
#include <iomanip>
#include <mysql++.h>
#include <stdio.h>
#include <Windows.h>

using namespace std;
using namespace mysqlpp;

int main(){

    //在取得连接之前首先设置字符编码
    mysqlpp::Connection conn(false);
    conn.set_option(new mysqlpp::SetCharsetNameOption("GBK"));
    conn.connect("mydb","127.0.0.1","user","password",3306);

    mysqlpp::Query query=conn.query();
    vector<mysqlpp::Row> v;
    query<<"select * from nations";
    query.storein(v);

    cout.setf(ios::left);
    cout<<setw(10)<<"Nation"<<setw(10)<<"Notation"<<endl;
    for (vector<mysqlpp::Row>::iterator it = v.begin(); it != v.end(); ++it) {
        cout<<setw(10)<<it->at(0)<<setw(10)<<it->at(1)<< endl;
    }
    getchar();
    return 0;
}

2010年4月9日星期五

使用mysql connector/C++查询mysql数据库

#include <iomanip>
#include <mysql_connection.h> 
#include <mysql_driver.h>
#include <cppconn/driver.h> 
#include <cppconn/statement.h> 
#include <cppconn/exception.h>
#include <cppconn/resultset.h>

using namespace std;

void RunConnectMySQL()  

    try{
        //sql::Driver *driver;
        sql::mysql::MySQL_Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt; 
        sql::ResultSet *result; 

        //driver = get_driver_instance();
        driver=sql::mysql::get_mysql_driver_instance();

        con = driver->connect("tcp://127.0.0.1:3306", "user", "password"); 

        stmt = con->createStatement(); 
        stmt->execute("use doclibexp"); 

        result = stmt->executeQuery("select * from nations"); 

        while(result->next()) 
        { 
            string nation = result->getString("Nation"); 
            string notation = result->getString("Notation"); 
            cout << nation << " : " << notation << endl;
        } 
        delete stmt; 
        delete con;

    }catch (sql::SQLException &e) {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
    }

int main(int argc, char **argv) 

    RunConnectMySQL(); 
    getchar(); 
    return 0; 

C++中的标准string由unicode转换为ansi[windows环境]

#include <windows.h>

string utf2ansi(const string &src){
    int nLen = MultiByteToWideChar( CP_UTF8, 0, src.data(), -1, NULL, NULL );
    //得到UTF8编码的字符串长度
    LPWSTR lpwsz = new WCHAR[nLen];
    MultiByteToWideChar( CP_UTF8, 0, src.data(), -1, lpwsz, nLen ); 

    int nLen1 = WideCharToMultiByte( CP_ACP, 0, lpwsz, nLen, NULL, NULL, NULL, NULL );
    LPSTR lpsz = new CHAR[nLen1];
    WideCharToMultiByte( CP_ACP, 0, lpwsz, nLen, lpsz, nLen1, NULL, NULL );
    string str(lpsz);
    delete []lpsz;
    return str;
}

2010年4月7日星期三

win7+vs2008编译openssl

转自:http://chang.baidu.com/mycbg/snap/84d42ff18c21541db037b42b.html

==================================================================================

在编译OpenSSL前,需要正确安装Perl,因为在编译OpenSSL时需要使用到该程序。

下载最新版本的Perl:http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.822-MSWin32-x86-280952.zip。然后安装之。

下载最新版本的OpenSSL:http://www.openssl.org/source/openssl-0.9.8g.tar.gz

然后将源码释放的c:\openssl-0.9.8g目录中。

进入openssl源码目录。
cd c:\openssl-0.9.8.g

以下为参照该目录下的文件INSTALL.W32的执行过程:

在命令行下先执行一次一遍设置nmake,ml,cl等命令的路径:
C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat

运行configure:
perl Configure VC-WIN32 –prefix=c:/openssl

创建Makefile文件:
ms\do_ms

编译动态库:
nmake -f ms\ntdll.mak
编译静态库:
nmake -f ms\nt.mak

测试动态库:
nmake -f ms\ntdll.mak test
测试静态库:
nmake -f ms\nt.mak test

安装动态库:
nmake -f ms\ntdll.mak install
安装静态库:
nmake -f ms\nt.mak install

清除上次动态库的编译,以便重新编译:
nmake -f ms\ntdll.mak clean
清除上次静态库的编译,以便重新编译:
nmake -f ms\nt.mak clean

error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWCH'

 

在VC6中可以编译成功的代码在VS2005,VS2008中编译出错。

原因:LPWCH是指long pointer to wide char,VS2005和2008默认使用unicode编码,而vc6默认使用多字节编码。

解决方法:

(1)将char改为wchar_t,但是会引起很多问题(在既有代码中)

(2)在项目的属性>配置属性>常规中,将“字符集”由“使用Unicode字符集”改为“使用多字节字符集”

2010年3月30日星期二

博客迁移完成

今天,2010.3.30,yo2.cn终于不再502,503了。但现在已经失望了,抓紧时间将博客迁移到了这里。yo2就作为备份吧,也算一段无奈的回忆。

转换程序 http://wordpress2blogger.appspot.com 真是好东西

杯具的是,我朋友现在访问yo2的时候又502,503了。

批量建立作业提交目录

@echo off
for /L %%i in (1,1,41) do (
    if %%i leq 9 ( mkdir 09040710%%i
    ) else ( mkdir 0904071%%i)
)
for /L %%i in (1,1,40) do (
    if %%i leq 9 ( mkdir 09040720%%i
    ) else ( mkdir 0904072%%i)
)
pause

2010年3月23日星期二

IVT BlueSoleil SysPanel很费电

为了充分利用蓝牙的功能,给笔记本、台式机都安装了IVT BlueSoleil。在连接N73手机时按照软件的要求自动安装了SysPanel,结果从第二天开始手机电池只能用一天不到。关闭SysPanel和蓝牙,结果依旧。无奈之下将之卸载,现在电池又能用3天了。

这个小程序怎么就这么费电呢?

g.cn关闭了

2010.3.23日零时,g.cn终于被关闭了。转到了google hk,“欢迎您来到谷歌搜索在中国的新家”。

2010年3月22日星期一

yo2.cn 503服务器错误

又杯具了,好像yo2的服务器就没怎么稳定过。只能找出前段时间的备份慢慢往上贴了。

Blogger的悲哀

 

因为喜欢WordPress,因为喜欢用MS Live Writer写博客,所以选择了yo2.cn.

可是命运多舛,一段时间后yo2无法访问。偶尔发现翻墙能访问自己的博客,后来终于在yo2官方网站看到了如下的声明:

目前Yo2已恢复免费用户与绑定域名用的博客访问服务,服务器均已迁移香港,确保数据的安全性。但因众所周知的墙存在,目前Yo2的香港服务器IP是被盾状态,用户需要翻墙(代理,最好VPN方式)访问和管理博客,或者备份下载博客内容。国内服务器的恢复还需再观察形势发展,给大家带来的不便深表抱歉!~现在的处境,我们最大的努力是保证数据安全和国外的正常访问,并尽可能快的恢复国内服务。希望大家可以谅解,谢谢!

然而却再也无法发布新的日志。

直到今日,从twitter上得知:

刚才得知国内BSP yo2被撤销备案,意味着完全无法在国内经营.现在不是狼来了,而是狼已经在吃羊了.

顿时感觉十分地悲哀与失望。P民是没有办法的,这个日志主要也是记录一些东西防止遗忘。不管选择yo2还是blogspot,翻墙还是免不了的,所以还是用稳定一点的,至少能发布日志的博客。

后面慢慢把以前的东西搬上来吧,真是不习惯Live writer不支持的博客,因为我写的里边可能有很多图。

再次无语中……

2010年3月15日星期一

Windows 7常用热键

* 窗口快捷键
win+↑ 最大化窗口
win+↓ 还原/最小化窗口
win+← 使窗口占领左侧的一半屏幕
win+→ 使窗口占领右侧的一半屏幕
win+shift+← 使窗口在左边的显示器显示
win+shift+→ 使窗口在右边的显示器显示
win+home 还原/最小化所有的其他窗口

* 任务栏快捷键
win+T 预览第一个任务栏项, 按住win键连续按T从左向右预览
win+shift+T 预览最后一个任务栏项, 按住win+shift键连续按T从右向左预览
松开以后, 也可以按←或→键来按顺序预览.
win+数字键 1~9 启动当前钉在任务栏上的快速启动项, 按win+1启动左起第一个快捷方式, 依次类推.

* 桌面快捷键
win+空格键 预览桌面(不同于显示桌面, 松开以后会恢复原状.)
win+G 按排列次序把桌面小工具送到屏幕最前端
win+P 切换连接到投影仪的方式
win+X 打开windows移动中心

* 辅助工具快捷键
win+加号”+” 按比例放大整个屏幕
win+减号”-” 按比例缩小整个屏幕

* 资源管理器快捷键
Alt+P 快速打开/关闭预览窗格

* 鼠标动作
Shift+左键单击任务栏图标 打开一个新的实例(例如Shift+左键单击”库”图标会打开一个新的资源管理器窗口)
鼠标中键单击任务栏图标 作用同上.
Ctrl+Shift+左键单击任务栏图标 以管理员权限打开一个新的实例
Shift+右键单击任务栏图标 打开像XP/Vista那样的窗口控制菜单(即最大化, 最小化, 关闭等); 对于未打开的快捷方式, 则弹出针对快捷方式的右键菜单.
shift+ 右键单击任务栏分组 打开像XP/Vista那样的窗口控制菜单(即最大化组, 最小化组, 关闭组)
ctrl+在任务栏分组上滚动滚轮 在本组中的不同窗口/标签之间切换.