Archive forMay, 2006

delicious greasemonkey js

修改一下 delicious页面,在新窗口中打开收藏的链接.
 delicious.user.js
// ==UserScript==
// @name           User script template
// @namespace      http://mywebsite.com/myscripts
// @description    A template for creating new user scripts from
// @include        http://del.icio.us/*
// ==/UserScript==
var nodes = document.getElementsByTagName("h4");
for(var i=nodes.length-1;i>=0;i--) {
    var node = nodes[i];
    if (node.className=="desc") {
	var children = node.childNodes;
	for( var x = 0;x<children.length; x++ ) {
	    var child = children[x];
	    if (child.tagName=="A") {
		child.setAttribute("target","_blank");
	    }
	}
    }
}

 

technorati tags: , ,

Comments

vim

dd 删除当前行

ndd删除n行

dw删除当前word

yy复制当前行

nyy复制n行

y^复制到行首

y$复制到行尾

yG复制到文档尾

y1G 复制到文档首

“ayy复制当前行当a缓冲区,a可为a-z

p粘贴到光标所在行下

P粘贴到光标所在行前

“ap粘贴a缓冲区的内容到光标所在行下

.重复前一次编辑动作

ma设置书签,a可为a-z

`a回到书签a

‘a回到书签a的行首

设置用4个空格代替一个tab
set softtabstop=4
set shiftwidth=4

替换

:[range]s/pattern/string/[c,e,g,i]

:!外部命令 执行外部命令

:r 外部命令 在光标所在行下插入外部命令执行结果

:!! 执行前一次的命令

参考:http://www.study-area.org/tips/vim/

technorati tags: ,

Comments

apache ssl

安装openssl,apache.


创建密钥

 openssl genrsa -des3 -out test.key 1024


创建证书请求

openssl req -new -key test.key -out test.csr

自签名证书
openssl x509 -req -days 30 -in test.csr -signkey test.key -out test.cert

配置virtualhost

<VirtualHost *:443>
        ServerName test.com
        DocumentRoot "/home/web/"
        SSLEngine on
        SSLCertificateFile conf/test.cert
        SSLCertificateKeyFile conf/test.key
</VirtualHost>

Comments

apache乱码

系统中的页面有的是utf-8编码,有的是gb2312的.

使用默认安装的apache2.0.55时一切正常,搬到另一个修改过配置的apache上后发现utf-8编码的都成乱码了,需要在浏览器里指定编码才能显示.

比较一下两个配置文件,发现后者多了一句AddDefaultCharset GB2312,把这一句注释掉应该就没问题了.正式系统重启麻烦事比较多,只好一个个把那些utf-8编码的文件都改成gb2312,还好文件数量不多.

当初要都用一种编码就好了:-(

technorati tags: ,

Comments

apache2 php5

os:xp sp2

apache:2.0.55

php: 5.1.4-Win32

将php5apache2.dll复制到apache的modules目录下,在http.conf中增加

LoadModule php5_module modules/php5apache2.dll
AddType application/x-httpd-php .php
PHPIniDir "F:/php/php-5.1.4-Win32"

 用ApacheMonitor启动不了,直接运行Apache.exe却可以.

改了几次http.conf,发现只要有LoadModule php5_module modules/php5apache2.dll这一行,在monitor中就启动不了.

最后改成LoadModule php5_module "F:/php/php-5.1.4-Win32/php5apache2.dll",又可以了.

同样是dll,fastcgi没有问题,加入LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll可以启动. 

变态的毛病. 

technorati tags: , ,

Comments

变态的validation

在struts的validation 中如果用mask作验证,.,\d之类的都不能用,只能用[.],[0-9]之类的代替.

technorati tags: , , ,

Comments

去掉csdn 新闻广告

 受不了csdn的那些flash广告,写了一段js来去掉它们.

只在 flock0.5.15.0+Greasemonkey 0.6.4上测过

 csdnnews.user.js

// ==UserScript==
// @name          csdnnews
// @namespace      http://zzzhc.net/csdnnews
// @description    A template for creating new user scripts from
// @include        http://*.csdn.net/*
// ==/UserScript==

function removeNodes(name) {
    var nodes = document.getElementsByTagName(name);
    if (nodes) {
        for(var i=nodes.length-1;i>=0;i–) {
            var node = nodes[i];
            node.parentNode.removeChild(node);
        }
    }
};

function removeNodeById(id) {
    var node = document.getElementById(id);
    if (node) {
        node.parentNode.removeChild(node);
    }
};

function removeNodeByClass(tag,clazz) {
    var nodes = document.getElementsByTagName(tag);
    if (nodes) {
        for(var i=nodes.length-1;i>=0;i–) {
            var node = nodes[i];
            if (node.className==clazz) {
                node.parentNode.removeChild(node);
            }
        }
    }
}

removeNodes("script");
removeNodes("object");

removeNodeById("topad");
removeNodeById("paladin_top");
removeNodeById("paladin_nav");
removeNodeById("logo");
removeNodeByClass("div","banner");

 

technorati tags: , , ,

Comments

hmacmd5

管理系统登录中使用飞天诚信的usbkey,服务器端做验证用到hmac-md5,java里有现成的实现,但一直没找着怎么指定key,只好照着rfc实现了一个.

package com.pay365.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * <pre>
 *         Definition of HMAC
 *       
 *         The definition of HMAC requires a cryptographic hash function, which
 *         we denote by H, and a secret key K. We assume H to be a cryptographic
 *         hash function where data is hashed by iterating a basic compression
 *         function on blocks of data.   We denote by B the byte-length of such
 *         blocks (B=64 for all the above mentioned examples of hash functions),
 *         and by L the byte-length of hash outputs (L=16 for MD5, L=20 for
 *         SHA-1).  The authentication key K can be of any length up to B, the
 *         block length of the hash function.  Applications that use keys longer
 *         than B bytes will first hash the key using H and then use the
 *         resultant L byte string as the actual key to HMAC. In any case the
 *         minimal recommended length for K is L bytes (as the hash output
 *         length). See section 3 for more information on keys.
 *       
 *         We define two fixed and different strings ipad and opad as follows
 *         (the ‘i’ and ‘o’ are mnemonics for inner and outer):
 *       
 *         ipad = the byte 0×36 repeated B times
 *         opad = the byte 0×5C repeated B times.
 *       
 *         To compute HMAC over the data `text’ we perform
 *       
 *         H(K XOR opad, H(K XOR ipad, text))
 *       
 *         Namely,
 *       
 *         (1) append zeros to the end of K to create a B byte string
 *         (e.g., if K is of length 20 bytes and B=64, then K will be
 *         appended with 44 zero bytes 0×00)
 *         (2) XOR (bitwise exclusive-OR) the B byte string computed in step
 *         (1) with ipad
 *         (3) append the stream of data ‘text’ to the B byte string resulting
 *         from step (2)
 *         (4) apply H to the stream generated in step (3)
 *         (5) XOR (bitwise exclusive-OR) the B byte string computed in
 *         step (1) with opad
 *         (6) append the H result from step (4) to the B byte string
 *         resulting from step (5)
 *         (7) apply H to the stream generated in step (6) and output
 *         the result
 * </pre>
 *
 * @author <a xhref="mailto:zzzhc.starfire@gmail.com">zzzhc</a>
 */
public class HmacMd5 {
    /**
     * Used building output as Hex
     */
    private static final char[] DIGITS = { ‘0′, ‘1′, ‘2′, ‘3′, ‘4′, ‘5′, ‘6′,
            ‘7′, ‘8′, ‘9′, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’ };

    private byte[] ipod;

    private byte[] opod;

    public HmacMd5() {
        this(64);
    }

    public HmacMd5(int b) {
        ipod = new byte[b];
        opod = new byte[b];
        for (int i = 0; i < 64; i++) {
            ipod[i] = 0×36;
            opod[i] = 0×5c;
        }
    }

    private char[] encodeHex(byte[] data) {

        int l = data.length;

        char[] out = new char[l << 1];

        // two characters form the hex value.
        for (int i = 0, j = 0; i < l; i++) {
            out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
            out[j++] = DIGITS[0x0F & data[i] ];
        }

        return out;
    }

    private MessageDigest getMD5Digest() {
        try {
            MessageDigest md5MessageDigest = MessageDigest.getInstance("MD5");
            md5MessageDigest.reset();
            return md5MessageDigest;
        } catch (NoSuchAlgorithmException nsaex) {
            throw new RuntimeException(
                    "Could not access MD5 algorithm, fatal error");
        }
    }

    public byte[] md5(byte[] content) {
        byte[] data = getMD5Digest().digest(content);
        return data;
    }

    public String hmac(String key, String text) {
        byte[] keyData = key.getBytes();
        byte[] ki = new byte[64];
        byte[] ko = new byte[64];

        int keyLen = keyData.length;
        for (int i = 0; i < 64; i++) {
            if (i < keyLen) {
                ki[i] = (byte) (keyData[i] ^ ipod[i]);
                ko[i] = (byte) (keyData[i] ^ opod[i]);
            } else {
                ki[i] = ipod[i];
                ko[i] = opod[i];
            }
        }

        byte[] textData = text.getBytes();
        byte[] h1Data = new byte[64 + textData.length];
        System.arraycopy(ki, 0, h1Data, 0, 64);
        System.arraycopy(textData, 0, h1Data, 64, textData.length);
        byte[] h1Result = md5(h1Data);

        byte[] h2Data = new byte[64 + h1Result.length];
        System.arraycopy(ko, 0, h2Data, 0, 64);
        System.arraycopy(h1Result, 0, h2Data, 64, h1Result.length);

        byte[] result = md5(h2Data);

        return new String(encodeHex(result));
    }

    public static void main(String[] args) {
        HmacMd5 hm = new HmacMd5();
        String result = hm.hmac("2howek8523jsi", "ort.com.cn");
        System.out.println(result);
    }

}
 

 参考:

 RFC 2104 – HMAC: Keyed-Hashing for Message Authentication

 

technorati tags: , , , ,

Comments

java dns cache

在将一个子系统从一台机器搬到另一台时,将dns指向作了一下修改,但其它子系统没有重启.运行一段时间后发现其它子系统仍然在用原来的IP在访问搬迁过的子系统. 直接修改hosts文件也不生效,不得不重启.

找了一下,是java的dns cache的毛病. 启动server时加一个-Dnetworkaddress.cache.ttl=0可以抑制缓存,设置为其它大于0的值可以指定缓存时间,默认是-1,永远有效.

参考:

 

technorati tags: , ,

Comments

windows下配置apache+svn+perl+tomcat

环境:windows xp sp2

apache 2.0.55

svn 1. 3.0

perl v5.8.8 built for MSWin32-x86-multi-thread

tomcat 5.5.17

分别安装.

配置svn 

  1.  将svn安装目录/bin下的mod_dav_svn.so复制到apache的modules目录下
  2. 修改apache的httpd.conf,将LoadModule dav_module modules/mod_dav.so这一行前的注释去掉,增加LoadModule dav_svn_module     modules/mod_dav_svn.so
  3. 配置svn工作目录,#directory for svn
    <Location /svn>
        DAV svn
        SVNParentPath g:/svn/repository
        AuthType Basic
        AuthName "Subversion repository"
        AuthUserFile g:/svn/etc/auth_file
        # For any operations other than these, require an authenticated user.
        <LimitExcept GET PROPFIND OPTIONS REPORT>
            Require valid-user
        </LimitExcept>
    </Location>

    <Directory "/svn">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    auth_file可以使用apache bin目录下的htpasswd.exe生成.

  4. 使用svnadmin创建项目目录,切换到g:/svn/repository,svnadmin create 项目名

配置perl以cgi形式运行

  1.  将DocumentRoot目录的Options修改为 Options Indexes FollowSymLinks MultiViews ExecCGI Includes,允许执行cgi程序
  2. 增加AddHandler cgi-script .cgi .pl
  3. 增加ScriptInterpreterSource registry ,从注册表中查找执行cgi脚本的程序
  4. 资源管理器->工具->文件夹选项->文件类型,新建.pl,.cgi的扩展名,将打开方式都设置成perl

 配置tomcat

  1.  以系统服务方式运行,切换到tomcat bin目录,在cmd下运行service.bat intall tomcat5,如果是用可执行程序安装的tomcat可能不需要这一步
  2. 下载tcnative-1.dll,openssl.exe放到tomcat bin目录下,下载地址
  3. 下载jk module(mod_jk-apache-2.0.55.so)放到apache的modules目录下
  4. 修改httpd.conf

    LoadModule jk_module     modules/mod_jk-apache-2.0.55.so

    #config jk
    JkWorkersFile conf/workers.properties
    JkLogFile     logs/mod_jk.log
    JkLogLevel    info
    JkOptions     +ForwardDirectories
    JkAutoAlias   F:/apache-tomcat-5.5.17/webapps
    JkMountFile   conf/jkmap.properties

    <Location /jkstatus/>
        JkMount jkstatus
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>

  5. workers.properties 内容

    worker.list=local8009,jkstatus
    worker.local8009.type=ajp13
    worker.local8009.host=localhost
    worker.local8009.port=8009

    worker.jkstatus.type=status

  6. jkmap.properties 内容

    /*.jsp=local8009
    /manager/*=local8009
    /admin*=local8009
    /*.do=local8009
    JkUnMount /*.gif local8009
    JkUnMount /*.jpg local8009
    JkUnMount /*.ico local8009
    JkUnMount /*.GIF local8009
    JkUnMount /*.JPG local8009

参考:

technorati tags: , , , ,

Comments

« Previous entries