Published at: 10:01 pm - Wednesday January 27 2010
recaptcha的验证码新增了alpha composite的新机制取代干扰线,今天用了一些时间在YAN上也实现了这种绘图机制。 使用Java2D的AlphaComposite实现,选用的Rule为alpha 1.0的SrcOut,即通过公式 Ar = As * (1 – Ad ) Cr = Cs * (1 – Ad ) 用语言描述就是叠加区域的透明度为0. 使用这种机制必须采用BufferedImage.TYPE_INT_ARGB的图像,并且输出支持alpha通道的格式。
Published at: 10:12 pm - Wednesday December 30 2009
This is a feature introduced in NetBeans 6.7. Set environment variables for specified life-cycle phases: Open project properties dialog, select action category. Select actions which depend on the variable, click add button to add such an environment variable. However, this method doesn’t work with Glassfish spawned the IDE. If you want use environment variables in [...]
Published at: 10:12 pm - Tuesday December 29 2009
After you test and build your application in NetBeans, you deploy it to Glassfish, but the environment variables are invalid again. In such situation, you should set these variable in glassfish configuration file which is supposed to located at: $GLASSFISH_HOME/glassfish/config/asenv.conf Append your variables to the file, and restart the server. It works.
Published at: 10:12 pm - Monday December 28 2009
If you use NetBeans IDE to build an application which reads environment variable, you will have to do these settings in your IDE. There is no GUI to set such variables in NetBeans while Eclipse provides you a “Run Configuration Dialog”. So just add the declaration in your netbeans.conf. It is highly recommended to copy [...]
Published at: 04:12 pm - Thursday December 24 2009
Yan的APIKEY一直是用嵌入式的数据库存储的,最初使用的是hsqldb,最近又添加了H2和Derby的支持,基本上囊括了所有开源的Java嵌入式数据库。实现多了自然需要挑选、比较一下。 数据库特性的比较,H2的网站上有很好的Matrix,一目了然 http://www.h2database.com/html/features.html#comparison 关于速度的比较,今天做了一个简单的测试。 分别从derby / H2 / hsqldb中取出10 、100、1000条数据,循环100000次,比较耗时,如下: 三者的速度差距非常明显,hsqldb远快于其他两个。 而在10、100、1000条记录的索引上查询,并取出指定记录呢,同样是100000次,如下: 再索引上查询,速度受记录数量的影响非常微弱了。但是hsqldb还是远快于其他二者,有趣的是derby的速度要略微快于H2. 根据这样的结果,在Yan的应用中,hsqldb还是最理想的实现。
Published at: 10:12 pm - Sunday December 20 2009
经过一周的重构和开发,我的开源项目,验证码服务,打上了0.3的tag,算是一个release吧。 This release has been focusing on support for different types captcha generators. Now Yan is not only able to provide image/jpeg captcha, but also text/plain and any others. Changeset: Internal API Changes: Cache API improved: new CacheItemIdentity and CacheIdStrategy were introduced in to provide convertion between cache item name and captcha info model; Captcha [...]
Published at: 02:11 pm - Friday November 20 2009
最近用Groovy的HttpBuilder模块开发RESTful服务的客户端,遇到不少问题,浪费不少时间 网上的例子都是从Grape开始的,但是按照例子上运行,无论是通过grape install还是在代码里@Grab都没有办法把http builder加到classpath里,甚至依赖关系已经下载到~/.groovy/grapes里了,但是还是在import的时候报错。用Grails的时候也是一样,如果通过ivy定义依赖,通过ant下载到lib目录中,在grails shell里还是没有办法引用。不理解了,难道还需要手动再指定path吗。最后用grails的rest插件(grails install-plugin rest)总算是下载到了path中了。 第二是http builder的报错太智能了,它会把服务器端50x的报错输出在客户端。在查看错误的时候一定要分清楚。 第三是net.sf.json-lib这个库在转json的时候有一点问题,比如这样的js对象 {“result”:”success”} 会因为key上有引号而无法解析,必须是这样的格式: {result: “success”} 至于那种是正确的json我也没有兴趣了解了,只是非常遗憾的是couchdb返回的都是前一种形式。 当然了,瑕不掩瑜,http builder还是提供了非常方便的封装,比直接用HttpURLConnection或是HttpClient更加Groovy
Published at: 11:10 pm - Monday October 05 2009
废话不说了,直接上code吧: import com.drew.imaging.jpeg.*; import com.drew.metadata.*; import com.drew.metadata.exif.*; file = new File(“sample.jpg”); meta = JpegMetadataReader.readMetadata(file); gpsdir = meta.getDirectory(GpsDirectory.class); lat = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE); lon = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE); lats = lat[0].doubleValue() + lat[1].doubleValue()/60 + lat[2].doubleValue()/3600; lons = lon[0].doubleValue() + lon[1].doubleValue()/60 + lon[2].doubleValue()/3600; println(lats); println(lons); metadata-extractor似乎是现在惟一的读取exif信息的java库。在ivy中可以添加这样一个依赖: <dependency org="com.drewnoakes" name="metadata-extractor" rev="2.4.0-beta-1" conf="runtime"/>
Published at: 09:09 pm - Thursday September 10 2009
JConsole 下午给验证码做压力测试,用JMX监控Tomcat性能情况,200并发。Tomcat的配置,initial memory pool是512M,Max是768M。在15:30时我手动执行了一次GC。 Netpanzer 跨平台的联机坦克游戏,今天才知道可以和Bot玩,来看看这种寂寞的玩法。 开一个terminal(或者用screen也可以): netpanzer -d 再开一个terminal,添加两个bot netpanzer -b localhost & netpanzer -b localhost & 自己进游戏 netpanzer -c localhost 之前一直不知道,也怪自己,不知道打游戏也可以–help VirtualBox VirtualBox 3.0.6 今天发布了,fix了从3.0.2开始与archLinux 2.6.30内核的冲突,阔别已久的arch在VirtualBox上终于又可以运行了,但是: Two Screenshots
Published at: 08:08 pm - Thursday August 27 2009
在ArchLinux上使用ActiveMQ,执行bin/activemq,报错UnknownHostException,Transport Connection无法建立,可以取到/etc/ec.conf中设置的hostname(默认myhost) 解决方法,编辑/etc/hosts,添加127.0.0.1 myhost myhost。再次启动即可。Ubuntu上hosts自动把计算机名解析到127.0.0.1,ArchLinux上需要你手动做这件事了。