2005年12月14日星期三

google china jam 等等

google china jam
我满怀希望和信心参加了google china jam,
资格赛没通过,500名没进去。
题目很简单,但是一开始没想到那么简单,浪费了时间,最后几分钟很镇定的
作了“生死时速”般的编码,然后提交。因为题目真的简单,所以系统测试
通过了。但是分数是看时间的,我倒数几秒提交的,所以除了0分和多次提交的,
我是最低的。就这样失败了。有些不甘心啊。
source.
看一些开源的source,头上都是好长的copyright信息。而注释倒不一定有这么长。
我想这些信息要浪费多少带宽和容量啊。这个习惯真不好。
素质
接触一些南京本地人,素质怎么这么差,尤其是女的,凶啊。
-----

2005年12月9日星期五

想不通的几个基本的社会问题

1。 私有制
原始社会没有法律但是可以平均分配,
现在社会法律用来保护私有制。
为什么没有法律来保护平均分配?
2。 物质生活发达了,但是福利不到位。
既然人都要吃饭,都要住房。为什么这两项不是免费的呢?
为什么不消除饿死人的可能性呢?
-----

2005年11月30日星期三

Online Storage

最近发送大文件(如照片包)的时候发现了这个应用,
那就是Online storage,中文是网络硬盘。
传统的email往往附件的容量有限。
其实我是自编了一个的。但是我在网上相关的资料时,
发现这个业务已经方兴未艾了。
中国的有一些做的不错,有的价格我觉得还可以接受。
而国外的则更推出了一些免费的。
当然,收费方式,速度,用户体验等方面都不尽相同。
其实我也想开个公司来提供这项服务。(但是不知道费用和手续)

-----

2005年11月25日星期五

瓜子时间

晚上回到家,磕起来瓜子来。
瓜子啊,是美事啊。以前看到小猴子都喜欢吃。
现在的一两块钱一包的煮瓜子,可以说把瓜子的
美味发挥到了极值.
吃瓜子的时候什么都不能做了,连电脑也不能看,
就是专一的吃瓜子,是难得的休息啊.
不过脑子还是能入神的想点东西.
我在想自己的生活状况.有的时候决的很满足,
有的时候觉的空虚.到了星期天,到会把时间全部
浪费掉.比如用来玩游戏,玩的无聊的时候会回忆
起大学里的心境.放任的浪费青春但实在又没什么
事要去做.悔恨和怨恨同存.只怪自己不是在聪明
人聚集的场所,热烈的研究着改变世界的技术.
而是被遗弃在大众中,做国家最低层的奴隶.
有的时候发现"本不是池中物""本不是蓬蒿人"
但是却有力无处使.
最近看到google的招人.只狠自己不是美国人.
虽然北京也有研究所,但在北京这种地方能
搞出什么明堂来,应该在珠海,深圳啊.那里
才是能让程序员穿着沙滩裤放任的发挥创造
的地方.而且我不相信google来中国解放
天才的程序员啊.看到google网页上说google
的员工可以有20%的时间用来搞自己的兴趣
爱好.我觉得不应该啊.应该是80%的时间.
如果不是,那我已经很幸福了.虽然没有明朗化,
但是我的自我兴趣时间20%总是超过的.嗨嗨,
暗喜一下.但是如果得出google不如我现在
的公司的环境,那也是说明证明的方法有问题.
如果写一分求职信,我应该这样写,而且应该
发布在我的blog上,因为效果我觉得是差不多的:
简历:
名牌大学计算机系本科.
在计算机比赛中得奖的履历:
(省,国家,国际的加起来至少有二三十条)
然后工作以来的自编软件,小程序:
(也能写上十几个)
然后说自己很喜欢编程,很喜欢创造.
(完)
最近兴趣在操作系统,自编语言等底层的方面.
说起来,没有什么"价值".但是如果些一些
信息方面的应用,来服务于任何一个行业那还是
得心应手的.有生有色的.但是没有客户来源.
当然如果以后有自己的ip和服务器,那么搞个
网络公司还是可以的.
现实还得在公司工作,不能太任性了.人总得
吃饭啊.
但是我现在觉得如果失业了什么的,那么
人活着的意义可能有会变了.
如果在武士的时代,我可能会去做个用刀的
武士,不但具有杀人的权利,而且活的也一定
很潇洒.还有什么小市民一样的阿姨敢在我
面前晃,老子就是一刀,让你知道做人要厚道,
而且要懂礼貌.还是比我强的男人,我要躲起来.
但是一旦忍不住了,就会去割下他们的头.挂在
自己的腰带上.当然树敌太多就会死得很早.
扯远了.睡觉.看官辛苦了.
--此文是用我编的输入法neoeime在jedit上写成.
-----

2005年11月17日星期四

autodetect encoding for html file (jedit patch)

it find text like "content="text/html; charset=xxxxxx"" at the begin of the html.
BufferIORequest.java
/**
* Tries to detect if the stream is gzipped, and if it has an encoding
* specified with an XML PI.
*/
private Reader autodetect(InputStream in) throws IOException {
in = new BufferedInputStream(in);
String encoding = buffer.getStringProperty(Buffer.ENCODING);
if (!in.markSupported())
Log.log(Log.WARNING, this, "Mark not supported: " + in);
else if (buffer.getBooleanProperty(Buffer.ENCODING_AUTODETECT)) {

{// neoe: detect html's encoding
String enc = getHtmlEncoding(in);
if (enc != null && MiscUtilities.isSupportedEncoding(enc)) {
buffer.setProperty(Buffer.ENCODING, enc);
return new InputStreamReader(in, enc);
}
}
....
(original lines)
/**add by neoedmund*/
private String getHtmlEncoding(InputStream in) throws IOException {
String enc = null;
String key = "charset=";
int bufSize=1000;
byte[] buf = new byte[bufSize];
in.mark(bufSize);
int len;
if ((len = in.read(buf,0,bufSize)) >0) {
String line=new String(buf,0,len);
int p1 = line.indexOf(key);
if (p1 >= 0) {
int p2 = p1 + key.length();
p1 += key.length();
if (line.charAt(p1) == '\\'' || line.charAt(p1) == '"') {
p1++;
}
while (p2 < line.length()
&& "'\\" >;,.".indexOf(line.charAt(p2)) < 0) {
p2++;
}
if (p2 <= line.length()) {
enc = line.substring(p1, p2);
}
}
}
in.reset();
return enc;
}

-----

2005年11月14日星期一

rotate tomcat stdout log

[2005-11-14]
I use System.out for webapp's log, but catalina seems lack of rotate features
and grows large.
So i use linux logrotate do the job.
/etc/cron.daily calls /usr/sbin/logrotate /etc/logrotate.conf
and logrotate use the config file:
# /etc/logrotate.d/tomcat
/opt/tomcat/logs/catalina.out {
daily
rotate 30
create 0664 tomcatUser tomcatUser
nocompress
}
i think it should work.
[2005-11-17]
不行,可能是logrotate使用的机制不同.(也许只是rename)
tomcat会仍然写道catalina.out.1中。
于是我写了一个脚本,来完成任务:
 logroll.sh
#!/bin/sh
cd logs
i=30
while [ $i -gt 0 ]; do
let i2=i+1
cp -f catalina.out.$i catalina.out.$i2
let i=i-1
done
cp -f catalina.out catalina.out.1
echo ""> catalina.out

还是第一次写bash的循环语句,不太会写。
[2005-11-22]
how fool am i. this maybe better script:
TODAY=`date +'%Y-%m-%d'`
fn=catalina.out.${TODAY}
cp -f catalina.out ${fn}
echo ""> catalina.out
虽然不能控制个数,但是能标上日期,而且拷贝量原来要10次,现在只要1次。

-----

2005年11月6日星期日

calculation speed comparison of C,Java,Python

platform) windows xp
version)
C: gcc version 3.3.1 (mingw special 20030804-1)
Java: JDK1.5.0
Python: Python 2.4.2
program)
C:

#include
#include
#include
void printPrime(int start, int count);
int isPrime(int x);
int main(){
DWORD t1,t2;
t1=timeGetTime();
printPrime(10,2000);
t2=timeGetTime();
printf("%d\
", (t2-t1));
}

void printPrime(int start, int count){
while(1){
if (isPrime(start)){
count--;
printf("%i\
",start);
}
start++;
if (count<=0){
return;
}
}
}
int isPrime(int x){
int i;
for (i=2; i if (x%i==0){
return 0;
}
}
return 1;
}

Java:

public class Test {
public static void main(String[] args){
run();
}
static void run(){
long t1=System.currentTimeMillis();
printPrime(10,2000);
System.out.println((System.currentTimeMillis()-t1)+" ms");
}

static void printPrime(int start, int count){
while(true){
if (isPrime(start)){
count--;
System.out.println(start);
}
start++;
if (count<=0){
return;
}
}
}
static boolean isPrime(int x){
for (int i=2; i if (x%i==0){
return false;
}
}
return true;
}
}

Python:

def printPrime(start, count):
while True:
if isPrime(start):
count-=1
print start
start+=1
if count <= 0:
return
def isPrime(x):
for i in range(2,x/2):
if x % i==0:
return False
return True

from time import time
t1=time()
printPrime(10, 2000)
print time()-t1

excution)
redirect stdout to a file

Result)
C: 230 ms
Java: 460 ms
Python: 7800 ms

Date) 2005/11/05


-----

2005年11月3日星期四

我和python有个约会

python,php,perl,ruby,我一直都接触了,但是一直没有钻研。
最近我在写jsp,看了tapestry,jsp2.0,都看不入眼,还是写我的jsp.
但是开发用tomcat, jar,class变了以后还得重启,虽然用了上传脚本,
压缩上传重启也要10秒左右,重起了还得重新登陆。
要是不用重起就快多了。
于是我看了一下python,发现还是挺喜欢的。
至少是'''long string ''',utf8支持的也不错。
# -*- coding: utf-8 -*-
import getpass, poplib
M = poplib.POP3('mailhost')
M.user('myname')
M.pass_('password')
numMessages = len(M.list()[1])
print numMessages
for i in range(numMessages):
for j in M.retr(i+1)[1] :
if j.startswith("Subject") :
print j

写了一个程序,用来随时查看有没有email.
这样可以关掉thunderbird,可以节约16MB内存,要知道我的512MB常常是不够用的。
虽然还没有钻研,但是已经解决了一个实际问题,我的程序员直觉告诉我,python不错!

-----

2005年11月2日星期三

乱题一首

强者男人梦,
此梦不可失。
难免不及人,
躲避免灾祸。
临险尽人力,
得失全在命。

-----

2005年10月17日星期一

我惊奇,别人的成就。

我发现了JNode, Classpath, JDistro, Greenbrowser, 讯雷等。
有那么多好东西,有的是我想做但是无力无时间做的,
有的是我没想到的但是想法很不错的。
后面两个还是国人过的。
向他们致敬啊。
这两天鼻子塞,晚上一定被闷醒。
是鼻炎吧,不健康的感觉,想起人有一天会死,要提前做好心理准备了,
到时一了百了,决不让医院赚我的钱,我要把钱转给我的直属或者其他亲戚。
今天中午去邮局取包裹,差1秒没有赶上一趟车,司机根本没看我,我也没跑,
于是再花了4分钟等下一班车。坐了三站到了邮局。
邮局的人的服务态度还是冷冰冰的爱理不理。
人也不排队,总算拿到了。
回来吃了鸭血粉丝汤,不想多吃。但是还买了12个小的老婆饼。
做得看上去不错,吃起来也不错。
路上一个要饭的小女孩拦截了我,我只能给她两个老婆饼。
我问她要不要吃,虽然嘴里塞了老婆饼讲得不清楚,但是她很聪明,她点点头。
她和她妈妈每人一个吧。
吃了一个不过瘾,可是没有第二个了。
但是我也不知道要饭人的生活。
回来买了三种鼻炎药,千柏鼻炎片,鼻炎康片,辛夷鼻炎丸,三个混合吃。
每种计量都取三分之一。还有其他种类的鼻炎片,因为相对比较贵就没买。
-----

2005年10月10日星期一

job 2005

有的时候我真不清楚,如何选择.
工作三年多了.工作对我的人生很有意义.
它给了我钱.
给了我新的精神.
我学到了新的技能.
懂得了更多人类社会的情况.
其中出现过危机,比如无法承受加班之苦.
比如出差到一个小公司做的不爽被赶回来.
但总得来说,目前状况是好的.
社会上普遍存在不尊重,但在公司里似乎得到大家的尊重,
有时是预期之外的尊重.
工作内容也不错,以自己的兴趣为工作,这是人生的渴望.我几乎已经实现了.
我喜欢编程,工作就是编程.还可以随便上上网,学习感兴趣的编程机能.
还能开发大家日常使用的系统,让编程得到实际的使用.
我几乎可以忘记失去工作的潜在忧虑.
这是预期之外的爽.
现在三年合同满了,我如果原意,应该可以续签上三到五年.
三年里可以学习锻炼到更多的技能.
每天生活的比较轻松.
薪水也能比较满意,因为我要求不高.
应该说工资的性价比很高.
当然唯一不太舒服的是也许没有直接为公司创造可见的效益,会使我心里有些不安.
是的,公司在培养我做骨干之一,即使没有明说,但是我相信.
某些人,虽然我不能明确指出是哪些人,似乎对我有着期望.给我委任了一些不可以
马上被替代的工作.比如系统维护.
现在有个10倍的薪水的工作等着我.我有些难以选择.
如果放弃现在的工作,有种半途而废的感觉.
就象渐渐加速的汽车,我是司机,现在想跳上另一辆火车.
比如我继续干上10年,技术会更好,薪水会是现在的三倍.
10年里平均薪水是现在的2倍.
如果跳槽,2年可以赚回来,或者是4年,剩下的时间用来提高我的技术.
当然生活不仅仅是为了提高技术.
然后剩下的8到6年,我也许还能回到现在工作的地方,也许也有类似现在的位子.
如果这样想的话,似乎很好选择.
可能工作的不如现在爽了.
难怪有句话说,一个人不可能两次踏入相同的河流.
现在我在想理论上一个公司不会在乎一个具体的人,尽管会在乎抽象的人才.
以前大学兼职过,经历了不少.
比如不要试图和一个不讲道理的上司理论.
做事要有恒心.
兼职的boss也曾挽留我,但是一旦想走了,除非自己想通,任何人也无法挽留.
唯一让自己坚持下去的方法就是不要去想跳槽这档子事.
一旦动了念头,它就会象恶魔一样不停的召唤,让你一步一步走向它.

-----

2005年9月30日星期五

neoeime

开发了一个输入法,推广了两天,觉得自己用最重要,
不要太频繁的发布版本,每个版本都要自己好好体验.
觉得自己突然也能写输入法了,而且用着自己的输入法,而且注册了
sf.net的项目,neoeime.sf.net.而且编程只用了两天,当然维护
是需要更多的时间.
-----

2005年9月21日星期三

我相信有永动机

我相信有永动机,比如宇宙不就是个永动机吗?
我考,那些白痴。我不否认什么热力学第一第二定理,但是这定理和永动机有什么关系?
不能说明不存在永动机。而且“近似”永动机也很有价值阿。比如不用管他它就行输出电能,
也许几百年或几百万年后会失效,但是对于人类的应用就很有价值了阿。
客观存在于我的大脑。
-----

讨厌啊,oracle

oracle安装就是麻烦,
建立database(命令行下)更是麻烦,
搞了我一上午,午饭都没吃好,头昏昏,
按网上的方法总是显示
CREATE DATABASE test
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
也看不出什么原因,
投降了,我再也不想搞oracle了,从来就不喜欢它,喜欢mysql之类的,安装使用都简单。
前段时间还有黑客通过oracle tns入侵系统。。。
数据库都做出来了,使用界面就不能友好一点吗?如果是我做的,绝对不会那么难用!
-----

2005年9月9日星期五

ObjectOutputStream 使用的注意 reset() 否则会OutOfMemory

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4363937
根据这个bug, 虽然我不知道Object序列化的具体机制,为什么会导致这个现象。
(可能是由于要保存写过的Object以便使用reference(Object之间的互相引用)).
但是out.writeObject(o)后加上一个out.reset(),就能解决问题。
ObjectInputStream端不用作任何修改。
否则out.writeObject(o),写了64MB(=Heap size)左右就会OutOfMemory。
这和序列化和垃圾回收有关。

-----

2005年9月5日星期一

《自己动手写操作系统》好书!

昨天毫不犹豫地买了一本《自己动手写操作系统》。这是我看到的最让人兴奋的书之一。
读此书胜过自己摸索十年。这么好的书到现在才出现。真是后来人的幸福啊。我比较佩服作者,自己没有这样的毅力来研究出这些。

-----

2005年8月31日星期三

神奇的张家界

张家界位于湖南,湖南简称湘。湖南雨水多,是鱼米之乡,古有“湖广熟,天下足”的说法。
由于湿气大,所以湖南人用吃辣来除湿,是很能吃辣的。女子有“辣妹子”的称呼。张家界
特产葛根、蕨根、杜仲、高山云雾茶等。当然还有很多的元帅,毛泽东,贺龙,等等都是
湖南人。毛泽东说过“不吃辣椒不革命”,看来吃辣椒让湖南人有火烈的性格。我玩了几天
也吃了很多辣椒,结果火气太大流鼻血了:)。
神奇的传说,赶尸人。把客死他乡的人的尸体运回故乡,于是有了赶尸人的职业。沿途的狗
看到行走的尸体会叫,这可不好,所以赶尸人还会“哑狗术”。现在据说还有这个行业,
只是不营业了。西方也有walking dead的说法。宁可信其有。
缥缈的山,张家界的喀斯特地貌的山不输桂岭啊。这些山还拟人拟物,有的外形还颇像呢。
黄龙洞,是我见过的最大的溶洞。石钟乳很多,还有一颗“定海神针”投保了一个亿呢。
开放的区域目前只有五分之二,不过已经给人很震撼的感觉。一条长长的阴河,泛着死亡的
涟漪,不知有多深。其中还有娃娃鱼也说不定。给人一种阴间、地狱的感觉。又让人不得不
赞叹大自然的造物能力。
宝峰湖,在山间的一个大湖,深约100多米,湖水清澈而深邃。其中也有很多鱼。峭壁上还
漏水,水流不大,但是很有灵气,所到之处都长了深绿色的青苔。整个山都泡在清凉的水气
之中。
凤凰古城,感觉是一个久经兵战的要塞。那里的烤鸡腿辣到了骨头里,值得一尝。猕猴桃很
便宜,八毛一斤。姜糖也是一个特产就是稍有点贵。

-----

2005年8月19日星期五

Google Earth 大开眼界

听别人说起的,看了一下真实Cool.
信息技术就是很方便。
这个技术很了不起。

-----

2005年8月16日星期二

OCR(Optical Character Recognization)

实际上我认为OCR又是一个体现计算机惊人能力的地方。
我初步做了一下。算法很简单,在设定合适的字体的大小的情况下识别率还可以。
主要用来识别印刷体,特别是从屏幕上拷贝下来的图片。(当然规则一点的认证码
的识别也是应该没有问题的)。可以改进的地方还有很多。
对于无法切割的方块的几乎没有办法,不如斜体字。
世界上似乎已经有不错的这种算法了,但是不推广。我用简单的算法实现一点,
希望能像普罗米修斯盗取火种一样。不过很难。

-----

2005年8月9日星期二

数据库检索和程序的效率

在做一个小小的实用的系统的时候我发现了一些效率的问题。
比如一个操作,web页面上用户发出一个查询,希望的时间当然是最多1到两秒。
一开始设计、编程的时候并不太清楚执行的效率问题。尤其是实用的时候
的数据量突然会比较大。编写的时候一般没有“兴趣”去做那么多,那么复杂的测试数据。
所以在试用的时候,发现某几个页面的效率比较低。几乎要半分钟到5分钟。要看数据量了。
不能用“我是菜鸟”来解释这个现象,因为我不是菜鸟。最后问题都被我解决了。
不管什么页面,什么操作,响应时间都大约在1秒一下。当然如果服务器如果不是双CPU的
而是几年前的386。那么怎么办?估计再优化优化也是有可能的。也许只能用别的方法
来绕过去。这是效率的相对性。但是优化中我发现了一些提高效率的方法。
1。就是“少发行sql”。如果发行n次查询,就优化成发行1次查询。最佳状况是一个页面
关于一个表的查询只有一次。这样说可能有时不太对。但是如果性能的确有问题,那么
就用这个方法吧。
2。Java端不是瓶颈。我很久没有编出运行时间很长的程序了。主要是查询页面的
逻辑一般都比较简单。除非我写的搜索最优值用搜索算法而不是动态规划之类的算法
时才遇到了天文数字的运行时间。我在这个项目中作了Java端的Group by。是的,代替sql的
group by.当然这是出于某种原因。不知道各种奇思妙想为我节约了多少开发时间。
group by用的时间是0,而open了个jdbc connection典型时间为20ms-80ms。
综上所述,使用数据库,为了效率,应该要改变一种思路。
他不是有一个查询就写一个sql.当然这样比较直接。
他是数据的来源。一开始你就用尽量少的sql取得所以你需要的数据。然后你再做你的
查询业务。
说了那么多,要是有个实际的例子就好了。那样就接近于一篇论文了。但是我没有
时间,懒的写了。所以就到此为止了,希望读者能体会一下。
-----

2005年8月4日星期四

全排列非递归递增的Java算法

全排列非递归算法记得以前有更"好"的算法(在李立新老师的书或讲义上看到过),但是当时我勉强理解了,现在又不论如何记不起来了。
所以想了很久(。。。)以后,决定用这个“全排列非递归递增的Java算法”。由于是递增的,思路比较简单。
public class OrderIterator implements Iterator {
private int[] buf;
private int size;
private boolean end=false;
public OrderIterator(int size) {
this.size = size;
buf = new int[size];
for (int i = 0; i < size; i++) {
buf[i] = i;
}
}
public boolean hasNext() {
return !end;
}
public Object next() {
int res[] = new int[size];
System.arraycopy(buf, 0, res, 0, size);
goNext();
return res;
}
/**next most min value that max than current value*/
private void goNext() {
int p= findHill();
if (p==0){
end=true;
return;
}
adjust(p-1);
}
/** adjust within this area*/
private void adjust(int p) {
int v = buf[p];
Arrays.sort(buf,p,size);
// find p's new position
int i;
for (i=p;i<size;i++){
if (buf[i]==v){
break;
}
}
move(i+1,p);
}

/**move q to p, q should lt p*/
private void move(int q, int p) {
int t=buf[q];
for (int i=q;i>p;i--){
buf[i]=buf[i-1];
}
buf[p]=t;
}
/** increase seq from tail to head*/
private int findHill() {
int p=size-1;
while(p>0 && buf[p-1]>buf[p]){
p--;
}
return p;
}
public void remove() { // not support
}
public static void main(String[] args) {
OrderIterator order = new OrderIterator(4);
int count=0;
while (order.hasNext()) {
count++;
int[] arr = (int[]) order.next();
for (int i = 0; i < arr.length; i++) {
System.out.print((arr[i]+1) + ",");
}
System.out.println();
}
System.out.println("count="+count);
}
}

-----

2005年8月2日星期二

和谐 社会

近来常看到“和谐社会”的宣传横幅。不明白,网上一查才知道是“两会”上“主席”提出的。于是全国上下就一致说起了这个词。像“三”字经一样。
以前听得最多的有性生活的和谐,现在这个和谐是什么意思?看了相关文章还说不太明确。都是官话,以前看政治书看怕了,现在一看到这种文体的东西就犯晕。
只是性生活的和谐我是知道一点的。和谐就是要大家愿意,大家快乐,而不是只满足一方,否则就是强奸社会。
当然这不是考政治试卷,没有人可以评判我的观点。

-----

2005年7月28日星期四

活下去,网游和知足

我写的一片关于网游和现实的文章一直没有放上来。大意就是网游练级(打怪升级)只是
为了自己在网游中活下去,而现实中也有很多我们不想干却一直干着的事,为了也只是自己活下去。
今天看到一句话:二狗子他妈,到县上别忘了捎几个鸡蛋。
让我想起物质贫乏和丰富之间的相对性,人如果学会满足就好了。
-----

2005年6月22日星期三

软件开发无形流

今天用java作了一个网页,数据比较多,层次也有3,4层,莫名其妙的用的xml+xslt,这样开发效率算是高的吧,所谓的mvc也符合了吧。
做完以后回头看看觉得第一次使用xml+xslt,这个知识是3年前学的,而这个使用它是始料未及的。也就是如果什么都计划好,然后开发,那么我是不会用到这么有灵感比较贴切的技术的。
当然关于我的无形流还远远不止是这些。。。

-----

2005年6月17日星期五

漂亮的牡马


-----

2005年5月30日星期一

moto c381 usb 使用心得

c381的usb可以用来管理手机上的文件,如图片音乐还有上传java应用程序游戏。
usb线,是通用的小型usb接口,由于买的时候没送,我用的就是数码相机的线。
usb连接到xp2的电脑上,识别出的状态有两种,一种是usb modem,另一种是usb composite device.
这两种只能选择其中之一,互不兼容。要变换模式需要重启手机,默认的是modem方式,
用于java loader. 启动motokit后,会进入composite模式,用于文件管理,上传。
winsp1的composite方式有问题,需要打个patch.
上传java游戏时,先用手机选择java加载器,手机显示:接上电缆。重插一下usb线,于是
显示进入加载模式,屏幕返回。然后启动midway. 选择一个jad,然后选择com口,一般是com3
(可以通过在硬件管理里察看usb modem设备的com号取得),
然后上传。手机上选择下载,运行。就可以了。
手机资源和工具开发软件可以从www.e968.net motocoder.com上取得。
以后我会自己开发手机的java应用。
-----

2005年5月24日星期二

初装系统被黑

一个初装的系统由于root密码太简单被黑了。
syslogd 的system log 启动失败。用rpm升级了一下sysklogd就好了。
还有top无法使用。top: error while loading shared libraries: libncurses.so.4: cannot open shared object file: No such file or directory
还未解决。
用pam验证密码还是不太肯定是否被黑了,pam的rpm已经升级过了、
gcc还没装上

-----

我进入linux世界了。

昨天我的精神上已经进入linux编程的世界。
jedit is programmer's editor, and linux is programmer's os.
从来没太多试过linux下c编程的我。
yesterday, i build gcc4.0 successfully on my fc2.(spend anout 3 hours on my pc)
i even successfully write a PAM auth application and get cpu use rate using glibtop.
当你对linux一无所知的情况下,借助opensource的力量,可以做很多事。
昨天取得cpu使用率的程序就是一个例子。
1. find a existing program has the prefer function.
2. find the source of the program.
3. copy the source implements the function into your own program and modify it.
4. gcc it and test.
就是这么简单。
以后会更加精通的吧。
-----

2005年5月17日星期二

おれ、linuxでcをできますかも

おれ、linuxでcをできますかも。昨日timeとsyslogをhelloworldプログラムを作成できた。その前vsftpのソース
をヘックしています。「これも出来なのか。発見することなっかた。」
cとJavaの違い点はありますが、語法でのみではない、OOPの利用方法はあります。
-----

2005年5月9日星期一

看了jrpg

运行了jrpg,的demo,一个很亲切的prg
-----

2005年5月8日星期日

假期后有上班了

今天看了jdesktop,不错,和windows结合的途径。比如Tray,但是同样发现中文乱码问题。
-----

2005年4月1日星期五

emule体验

emule不错。下了不少有用的东西。
下载:速度1-200kb,平均50KB
上传:速度1-200kb,平均50KB

有成就感的是自己也作了一次信息发布者。
我把jdk5.exe jdk5-doc.zip等编程工具放在共享目录,一个下午下来jdk5.exe 竟然已有96人下了完全版本(这个本身有44MB,我上传了64MB,还有44*100=4.4GB的内容是大家之间互相传播的)。许多人还是日本,欧洲的。他们用的都是我发行的版本(当然我也是直接从sun.com下载的,没有改动过。不过是不是黑客软件传播也快,所以下载后检查一下md5也是很必要的。)
感到网络的威力了。人多力量就是大。

-----

2005年3月29日星期二

为JEdit设置墙纸(add wallpaper for jedit)

1). 前提(condition)
+ jedit4.2final
+ jdk 1.4
2). 步骤(steps)
1. add this at org.gjt.sp.jedit.textarea.TextAreaPainter
in method paintComponent(...)
after:
extensionMgr.paintScreenLineRange(textArea, gfx, firstInvalid,
lastInvalid, y, height);
add:
{ // paint wallpaper after all that should be paint
Rectangle rect = this.getVisibleRect();
Wallpaper.paintWallpaper(gfx, rect.x, rect.y, rect.width,
rect.width, this);
}

2. add in org.gjt.sp.jedit.textarea.JEditTextArea
// {{{ changeWallpaperDialog() method
// for change the wallpaper
/**
* Displays the 'changeWallpaperDialog' dialog box.
* @author neoedmund
*/
public void changeWallpaperDialog()
{
if (Wallpaper.changeWallpaper(this)){
repaint();
}
} //}}}
3. add new class org.gjt.sp.jedit.textarea.Wallpaper
/*
* Created on 2005-3-26
*/
package org.gjt.sp.jedit.textarea;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
/**
* @author neoe
*/
public class Wallpaper {

static BufferedImage pic;
private static final String DEFALUT_IMG = "org/gjt/sp/jedit/icons/wallpaper.jpg";
static{
System.out.println("hello Wallpaper");
loadPic(ClassLoader
.getSystemResourceAsStream(DEFALUT_IMG));
}
static AlphaComposite alpha = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 0.2f);
/**
* @param gfx
* @param width
* @param height
*/
public static void paintWallpaper(Graphics2D g, int cx, int cy, int width, int height, JComponent view) {
if (pic==null){
return;
}
int y = 0;
int w = pic.getWidth();
int h = pic.getHeight();
Composite old = g.getComposite();
g.setComposite(alpha);
while (true) {
int x = 0;
while (true) {
g.drawImage(pic, cx+x, cy+y, view);
x += w;
if (w <= 0 || x >= width) {
break;
}
}
y += h;
if (h <= 0 || y >= height) {
break;
}
}
g.setComposite(old);
}
/**
* @param in
*/
private static void loadPic(InputStream in) {
try {
pic = ImageIO.read(in);
} catch (IOException e) {
e.printStackTrace();
}

}
static File f;
/**
*
*/
public static boolean changeWallpaper(JComponent parent) {
JFileChooser jfc = new JFileChooser(f);
int returnVal = jfc.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
f = jfc.getSelectedFile();
try {
loadPic(new FileInputStream(f));
return true;
} catch (IOException e1) {
e1.printStackTrace();
}
}
return false;
}
}
4. copy default wallpaper whatever you like into org/gjt/sp/jedit/icons/wallpaper.jpg
5. add this into org\gjt\sp\jedit\actions.xml
<ACTION NAME="change-wallpaper">
<CODE>
textArea.changeWallpaperDialog();
</CODE>
</ACTION>
6. change org\gjt\sp\jedit\jedit_gui.props, add "change-wallpaper" in tool bar
#{{{ Tool bar
view.toolbar=new-file open-file close-buffer save - print page-setup - \
undo redo cut copy paste - find find-next - new-view unsplit \
split-horizontal split-vertical - buffer-options global-options - \
plugin-manager - help - change-wallpaper
...
...
...
change-wallpaper.icon=Help.png
....
....
change-wallpaper.label=Change $Wallpaper
7. last step, rebuild source, restart jedit, have fun.
notes: I don`t know if it is something slowdown, but I like it :)

-----

2005年3月21日星期一

回合制

啊,连玩了两遍《霹雳奇侠传》
总算不想玩了。就像仙剑一样的游戏吧。
是什么有那么大的魅力呢,这些游戏?研究出来,就是研究出了人的兴趣啊。
说起回合制,想应该是象棋之类的更有"技术"含量吧?比起选择招式什么的。
人不时被欲望所驱使的吗?欲望分世俗的好坏,也分能不能实现。
后来试玩了《圣石传奇》同样也是霹雳小说题材的。从外表看和暗黑破坏神有
70%的接近。但是可玩性太差了。打敌人老是达不到,如隔靴搔痒,经验值又都被
后面的电脑控制的青阳子拿去了。还容易死。
又想起现在的网游,不知道什么东西。可以模拟一个世界,世界和法则和现实
世界不同。但是除去了好奇之外,有那么多可玩性吗?由于条件局限,还没涉足。
-----

2005年2月23日星期三

mp3与固件简单了解

mp3的"固件升级",说明mp3就像单片机一样可以编程。

比如SIGMATEL芯片,他支持了很多功能比如mp3的解码,usb,充电,按钮,等等。
但是上网站看了看,好像指令集是不公开的。否则也许我自己可以编写一个固件。当然有SDK更好。
-----

2005年1月4日星期二

用PHP实现Proxy

我根据 PHP Proxy, Dean 1.6, 小改了一下.
实现了php proxy, 增加了Post数据的功能(但对中文支持不好).


// ==== classWebPage.php ======
<?
/*
This program is free software; you can redistribute it and/or modify
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*Class WebPage**********************************\
* Come along with me into the world of ooPHP. *
* *
* WebPage is the main class in this script. It *
* controls getting pages as well as headers and *
* processing those pages. *
\************************************************/
class WebPage {
/*Var Descriptions*******************************\
* $URL The url we are proxying for *
* $pageData The raw data from the file *
* $headers Array containing the headers sent *
* $static Boolean if we are working on only rel *
* links *
* $currentServer String with the script's server *
* $scriptName Name of the main script *
* $varName Name of the var for passed in file *
* $updatedPageData The processed page data *
* $relDir The directory we're in for rel links *
* $fp The file pointer for reading the file *
\************************************************/
var $URL;
var $pageData;
var $headers;
var $static;
var $currentServer;
var $scriptName;
var $varName;
var $updatedPageData;
var $relDir;
var $fp;

/*Class Constructor******************************\
* The main constructor, pass in varible are *
* listed below. *
* *
* $URL The url we are proxying for *
* $static Boolean if we are working on only rel *
* links *
* $currentServer String with the script's server *
* $scriptName Name of the main script *
* $varName Name of the var for passed in file *
* $relDir The directory we're in for rel links *
\************************************************/

function WebPage($URL, $static, $currentServer, $scriptName, $varName, $relDir){
$this->URL = $URL;
$this->currentServer = $currentServer;
$this->static = $static;
$this->relDir = $relDir;
$this->pageData = "";
$this->varName = $varName;
$this->scriptName = $scriptName;
}
/*openLink***************************************\
* Function for connecting to the URL and getting *
* the headers. *
* *
* Note: The connection is closed by *
* getRawPageData or processPage, whichever comes *
* first. *
\************************************************/
function openLink(){
// echo "[".$this->URL."]";
/**********neo**************/
if(eregi("\?",$this->URL)){
$param="&";
}else{
$param="?";
}

foreach ($_POST as $key => $value) {
$param = $param.urlencode($key)."=".urlencode($value)."&";
}

$this->fp = fopen($this->URL.$param, "rb");
array_shift($http_response_header);
$this->headers = $http_response_header;
}
/*getHeaders*************************************\
* Function returns an array containing the *
* headers that resulted from the page. *
\************************************************/
function getHeaders(){
return $this->headers;
}
/*getRawPageData*********************************\
* Prints out the $fp as a stream without *
* processing (for images/such) *
\************************************************/
function getRawPageData(){
fpassthru($this->fp);
// fclose($this->fp);
return;
}
/*getPageData************************************\
* Function returns a string containing the *
* page data. processPageData must be used *
* before this function is called. *
\************************************************/
function getPageData(){
return $this->updatedPageData;
}
/*processPageData********************************\
* Function process the page, fixing links and *
* images to use the proxy as specified by the *
* class. *
* *
* Note: Add items here if you want to add extra *
* prefixes or delims. *
\************************************************/
function processPageData(){
$this->pageData = "";
while( !feof( $this->fp)){
$this->pageData .= fgets($this->fp, 4096);
}
fclose($this->fp);
$delim[]='"';
$delim[]="'";
$delim[]="";
$pre[]="src=";
$pre[]="background=";
$pre[]="href=";
$pre[]="url\(";
$pre[]="codebase=";
$pre[]="url=";
$pre[]="archive=";
$pre[]="action=";
$this->redirect($pre,$delim);
}
/*fileName***************************************\
* Function returns the name of the file that the *
* URL specifies. *
\************************************************/
function fileName(){
return eregi_replace("[#?].*$", "",
eregi_replace("^.*/", "", $this->URL));
}
/*encodeHTML*************************************\
* Fix Me: *
* This is not done yet but the idea is to change *
* all the html charcters to their special char *
* information (to keep people from stealing your *
* source and using it) *
\************************************************/
function encodeHTML(){
// Not Done Yet
}
/*encryptPage************************************\
* Function changes updatedPageData so that the *
* file is encrypted while sending. *
\************************************************/
function encryptPage(){
$data2 = "";
foreach (split("\n",eregi_replace("\r","",$this->updatedPageData)) as $a){
$data = $this->encrypt(chop($a));
$data = str_replace( "\\", "\\\\", $data);
$data = str_replace( "\"", "\\\"", $data);
$data2 .= "document.write( c(\"".$data."\") );\n";
}
$this->updatedPageData = ""
. "<!-- URL Proxy Server\n"
. "Javascript by Bob Matcuk\n"
. "BMatcuk@Users.SourceForge.Net -->\n"
. "<script language=\"Javascript\">\n"
. " function c(s){\n"
. " var fi = \"\";\n"
. " for( var i = 0; i < s.length-1; i += 2 ){\n"
. " fi = fi + s.charAt(i+1) + s.charAt(i);\n"
. " }\n"
. " if( i < s.length ){\n"
. " fi = fi + s.charAt(i);\n"
. " }\n"
. " fi = fi + \"\\n\";\n"
. " return fi;\n"
. " }\n" . " document.open();\n"
. $data2
. " document.close();\n"
. "</script>\n";
}

/*redirect***************************************\
* Private Function, DO NOT USE FROM PUBLIC SCOPE *
* Basically converts the prefixes in *
* $prefixArray and the delim in $delimArray to a *
* string and uses it to fix links within the *
* page. *
\************************************************/
function redirect($prefixArray,$delimArray){
// echo "redirect!";
$a = $this->pageData;
$name = $this->currentServer;
$fileDir = $this->relDir;
foreach($prefixArray as $prefix){
$start2 = stripslashes($prefix);
$start = $prefix . "[ ]*";
foreach($delimArray as $delim){
if(eregi($prefix . "[ ]*" . $delim, $a) && ($delim == "" ? eregi($prefix . "[ ]*" . "[a-z,A-Z,/,0-9]", $a) : 1)){
$a = eregi_replace($start . $delim . "//",
$start2 . '\a' . "//",
$a);
$a = eregi_replace($start . $delim . "/",
$start2 . $delim . $name . "/" . $this->scriptName . "?" . $this->varName . "=/",
$a);
$a = eregi_replace($start . $delim . "http://",
$start2 . '\a' . "http://",
$a);
$a = eregi_replace($start . $delim . "mailto:",
$start2 . '\a' . "mailto:",
$a);
$a = eregi_replace($start . $delim . "#",
$start2 . '\a' . "#",
$a);
$a = eregi_replace($start . $delim . "javascript:",
$start2 . '\a' . "javascript:",
$a);
$a = eregi_replace($start . $delim,
$start2 . $delim . $name . "/" . $this->scriptName . "?" . $this->varName . "=" . $fileDir ,
$a);
$a = eregi_replace($start . '[\]a',
$start2 . $delim,
$a);
}
}
}
$this->updatedPageData = $a;
}
/*encrypt****************************************\
* This function encrypts the page before it is *
* sent out. *
* Returns the file as a string, encrypted *
\************************************************/
function encrypt( $string ){
for( $i = 0; $i < strlen( $string ) - 1; $i += 2 ){
$temp = $string[$i];
$string[$i] = $string[$i+1];
$string[$i+1] = $temp;
}
return $string;
}
}
?>

// ==== URLproxyServer.php ======
<?
/*
This program is free software; you can redistribute it and/or modify
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/************************************************\
* URL proxy v1.3 Pre-Alpha *
* a co-authored script *
* by Scott Atkins <atkinssc@engr.orst.edu> *
* Bob Matcuk <bmatcuk@users.sourceforge.net> *
* Copyright (C) 2002 All rights reserved *
* Released under the GPL, see the README *
* *
* Edit config.php instead of this file please *
* If you change this file and break your proxy *
* don't ask for help, as you were warned *
\************************************************/
// User should not have to edit this file
include("config.php");
include("classWebPage.php");
// Constants
$STATIC = 1;
$DYNAMIC = 2;
// Mode of the script
$proxyMode = ((isset($server) AND isset($redirectIP)) ? $STATIC : $DYNAMIC);

// Version Number
$phase = "pre-alpha-neo-remake";
$version = "1.3 " . $phase;
/*Flags******************************************\
* $isHTML; true if mimetype is html *
* $isImage; true if mimetype is an image *
* $isDown; true if specified mimetype is to be *
* downloaded *
* $isAuth; true if the page is protected by *
* .htaccess *
* $isForm; true if the page contains a form *
\************************************************/
$isHTML = true;
$isImage = false;
$isDown = true;
$isAuth = true;
$isForm = true;
$isError = true;
/*getContentType*********************************\
* Function for finding the mime type of the file *
* Returns the content type *
\************************************************/
function getContentType($headers){
foreach($headers as $h){
if(eregi("^Content-Type: (.*)$",$h,$A1))
return $A1[1];
}
}
/*processHeaders*********************************\
* Function for handling the headers that apache *
* sends out. *
* Returns an array with the headers that should *
* be sent out *
\************************************************/
function processHeaders($headers, $fileName, $mime_dl, &$type,
&$isDown, &$isHTML, &$isImage){
array_shift($headers);
$type = getContentType($headers);
$isDown = (isset($mime_dl[$type]) ? $mime_dl[$type] : true);
if(eregi("image",$type))
$isImage = true;
elseif(eregi("text/html",$type))
$isHTML = true;
if($isDown)
$headers[] = "Content-Disposition: attachment;" .
" filename=$fileName";
return $headers;
}
/************************************************\
* This block of code gets the directory we are *
* currently in, for rel links. *
\************************************************/
if(eregi("http://",$_GET[$fileVar])){
$relDir = eregi_replace("^http://[^/]*", "", $_GET[$fileVar]);
}else{
$relDir = $_GET[$fileVar];
}
//echo "[".$_GET[$fileVar]."]";
$relDir = eregi_replace("/[^/]*$","/",$relDir);
//echo "[reldir=".$relDir."]";

/************************************************\
* We create a new object of type WebPage and *
* pass it the url we are being a proxy for and *
* other information about the current state. *
\************************************************/
$page = new WebPage($redirectIP."/".$_GET[$fileVar],true,$server,"URLproxyServer.php",$fileVar,$relDir);
/************************************************\
* This tells the WebPage object to open up a *
* connection to the URL. *
* *
* Note: *
* This does not actually get the web page, just *
* opens the connection for the headers. *
\************************************************/
$page->openLink();
/************************************************\
* Process the headers so we know what kind of *
* data we have (html/other) *
\************************************************/
$head = processHeaders($page->getHeaders(),$file,$mime_dl,$type,$isDown,$isHtml,$isImage);
/************************************************\
* This code replicates the headers that were *
* sent when the class connected to the url. *
* *
* FIXME: extra headers need to be sent if we are *
* downloading the file. *
* *
* GOTCHA?: need to check if http 1.1 will work *
* correctly *
\************************************************/
//foreach($head as $h) header($h);
/************************************************\
* This block of code displays the page to the *
* user. *
* *
* Note: Both processPageData and getRawPageData *
* close the connection to the URL when they *
* return. You must re-open a connection with *
* openLink to use them again. *
\************************************************/
//if($isHtml){
if($isImage) {
$page->getRawPageData();
} else{
$page->processPageData();
if($encryptPage)
$page->encryptPage();
echo $page->getPageData();
}
//}else{
// if($isImage)
// $page->getRawPageData();
//}
?>

// ==== config.php ======
<?
/*
This program is free software; you can redistribute it and/or modify
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**********************************\
* filename: config.php *
* date: 5/6/2002 *
* Notes: Edit this file, rather *
* than the server script *
\**********************************/
global $mime_dl;
global $server;
global $redirectIP;
global $fileVar;
global $encryptPage;
/*Mime Types***********************\
* These are mime types you don't *
* want to have downloaded by *
* default (false is required) *
\**********************************/
$mime_dl["text/html"]=false;
$mime_dl["application/pdf"]=false;
$mime_dl["application/x-javascript"]=false;
$mime_dl["application/x-shockwave-flash"]=false;
$mime_dl["image/bmp"]=false;
$mime_dl["image/gif"]=false;
$mime_dl["image/jpeg"]=false;
$mime_dl["image/tiff"]=false;
$mime_dl["text/css"]=false;
$mime_dl["text/directory"]=false;
$mime_dl["text/plain"]=false;
/*Server Vars***********************\
* Change these to match your server *
* Comment out redirectIP to have *
* the proxy work on all ips (by *
* absolute URLs) *
\***********************************/
$server = "http://xxx.yyy.com.cn/~xxx/gate";
$redirectIP = "http://172.16.x.xx:8080";
$fileVar="file";
?>

-----

eclipse plugin开发中的感觉

如果没有建设性意见请不要和我辩论
我常常想,Eclipse真是一个了不起的软件,尤其是他的插件,更使他生命力旺盛。
我得感谢IBM的开发者。


但是写Eclipse的人真是个接口狂人。他达到了滥用接口的地步。多少次我以为自己
懂了代码。但是最后实现自己的插件的时候却遇到了困难。
你别指望getLocation或者toOSString可以得到地址。他们要么就是没用的路径要么就是
null。和从javadoc看出来的含义永远是不同的。
像IProgressMonitor这样的接口会在函数调用的时候传下去好多层。很难把功能分开。
相同的接口,对同一操作会有不同的操作方法。你的视情况多次试探才行。
但是一旦搞定了还挺有意思的,好像一个RPG游戏通过了一关。
-----

博客归档

neoedmund's shared items

我的简介

ZIP Code File