tag:blogger.com,1999:blog-207857502024-03-10T23:16:14.021-07:00Simple CodeSimpler is Betterhsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.comBlogger43125tag:blogger.com,1999:blog-20785750.post-87918720869218321612012-07-01T22:52:00.001-07:002012-07-01T22:52:56.878-07:00Blog moved to WordpressI have moved all my posts to Wordpress.com. The new home is
http://sunh11373.wordpress.com/hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com12tag:blogger.com,1999:blog-20785750.post-25491736598719981682012-04-25T09:27:00.004-07:002012-05-31T22:49:23.103-07:00Python multiprocessing configuration fix on CentosThe OS I am running is 2.6.27-chistyakov.1 #1 SMP Tue Dec 29 10:26:29 PST 2009 x86_64 x86_64 x86_64 GNU/Linux. The Python multiprocessing module reported follow errors
File "/usr/lib/python2.6/multiprocessing/synchronize.py", line 49, in __init__sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)OSError: [Errno 38] Function not implemented
Turned out that we need to enablehsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com4tag:blogger.com,1999:blog-20785750.post-67454652299919353332011-10-18T22:23:00.000-07:002011-10-18T22:57:46.711-07:00How to Write a Spelling Corrector - The Haskell VersionPeter Norvig has an essay on How to Write a Spelling Corrector. There are implementations in many languages. However, the link to the Haskell version is broken now. So I used this opportunity to practice my limited Haskell skill.File: SpellChecker/Core.hs<![CDATA[module SpellChecker.Core where import Char import Data.Char import Data.Maybe import Control.Applicative import qualified hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-14974145360362758342008-03-20T21:51:00.000-07:002008-03-20T21:53:35.197-07:00Export emails from Outlook"""Exports email address from MS Outlook from recent eemails"""from win32com.client import Dispatch, constantsimport os.pathclass Exporter(object): app = None emails = [] def __init__ (self): self.app = Dispatch("Outlook.Application") if self.app == None: raise Exception, "Unable to create an Outlook application object&hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com3tag:blogger.com,1999:blog-20785750.post-14349187365617036792008-02-29T12:11:00.000-08:002008-02-29T12:51:33.389-08:00A few lessons learned on prototype.js and RoRA few lessons learned from my recent work on prototype.js and Ruby on Rails1) "class" is a reserved word for IE"class" is a reserved word for IE. If you use "class" as variable name in your JavaScript such as this (example using prototype.js): var highlight_span= new Element('span', { margin: '0', class: 'highlight' }); It works in Firefox but gives you an error in IE. The work around is:var hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-59165317730570719892008-02-08T11:06:00.000-08:002008-02-08T15:44:39.743-08:00Web page smoke test script#!/usr/local/bin python"""This script is used to check urls with a pattern. The configuration file has following format protocol_name|url|additional_argsexample: simpleGET|http://www.google.com/|Google simpleGET|http://www.aol.com/|WhatWhatExample output: http://www.google/ -> True http://www.aol.com/ -> False"""import os.path, re, getopt, sys, hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com8tag:blogger.com,1999:blog-20785750.post-90774398833545161892008-02-05T19:22:00.000-08:002008-02-05T19:23:04.810-08:00Email forwarding script#!/usr/local/bin python"""This script is used to forward email"""import os, sys, poplib, getopt, getpass, email, smtplibfrom_email = '???'to_email = '???'pop3_server_url = '???'pop3_server_port = 110pop3_user = '???'pop3_pass = '???'delete_after = Truesubject_filter = '????'def match_filter(subject, sfilter): return hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com8tag:blogger.com,1999:blog-20785750.post-39353411195125543202008-02-02T09:28:00.000-08:002008-07-07T13:34:41.311-07:00Search text pattern in log files#!/usr/local/bin python"""This script is used to analyze log file"""import os.path, time, re, getopt, sys, fnmatchverbose = Falsedef say(s): if verbose: print sdef searchPattern(args, dirname, filenames): file_pattern, text_pattern, count = args say("Processing directory %s now" % (dirname)) say("File pattern: %s" % (file_pattern)) say("Text pattern: %s" % (text_pattern)) say("hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-53909321201967839762008-01-28T09:21:00.000-08:002008-01-29T20:52:26.398-08:00SlimFIX gets new lifeI just found that a project I developed a few years back SlimFIX has been adopted by an open source project called ActiveQuant. I am glad it finally gets a new life.hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-62829888125745739892007-04-11T09:13:00.000-07:002008-01-12T18:10:49.259-08:00ssl mutual authentication in perlHere is a perl script to invoke web service using SSL mutual authentication.use LWP::UserAgent;use HTTP::Request::Common;my $request = << REQ;# message hereREQ# client certificate support$ENV{HTTPS_CERT_FILE} = 'test.crt';$ENV{HTTPS_KEY_FILE} = 'test.key';# CA cert peer verification$ENV{HTTPS_CA_FILE} = 'ca.crt';my $ua = new LWP::UserAgent;my $res = $ua->request(hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com2tag:blogger.com,1999:blog-20785750.post-5328875611669135322007-04-10T22:50:00.000-07:002008-01-12T18:13:45.952-08:00Python utility for generating certificateHere is a Python script that generates a certificate with various formats, including JKS and PFX. It also requires JDK and OpenSSL being installed.-----------------------------#!/usr/local/bin python"""Create a certificate with Python."""import urllib, sys, getopt, os, shutilfrom M2Crypto import SSL, httpslibfrom M2Crypto import RSA, X509, EVP, m2, Rand, hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com9tag:blogger.com,1999:blog-20785750.post-18086182744627341082007-04-10T22:22:00.000-07:002008-01-12T18:20:58.989-08:00Cross Domain Ajax in IEI have recently had the opportunity to implement an AJAX solution for my project. The goal is to allow AJAX calls to our web service. The challenge is the call is cross-domain. After spending some hours in investigation, I realized that it is real hard if not possible to accomplish this in Firefox. Tricks, such as iframe and JSOD, won't work well because the web service interface (SOAP) is hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com83tag:blogger.com,1999:blog-20785750.post-6789657061329433392007-03-10T15:57:00.000-08:002007-03-10T16:40:04.174-08:00Building a web site with Google toolsIt has been a long long time since my last post. My current work project has kept me busy for almost a year without being able to do much other stuff.Recently I have to redesign our church web site (http://www.cbcsdwc.org). I need to find a way to complete it fast and more importantly, to keep the on-going maintenance work easy. The previous web site was created with PHP Nuke. I had also made a hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-1148430678739399432006-05-23T17:28:00.000-07:002008-01-12T18:21:54.909-08:00JBoss application configuration during deployment timeI was looking for a mechanism to configure my application during deployment time. We have our own configuration module but it does not handle the case for deployment descriptor. For example, the application needs to connect to different JMS queues in different environment. The JMS queue name is usually specified in the jboss.xml which is wrapped in the ear file. Our old approach is to use an Ant hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-1147102467444916802006-05-08T08:27:00.000-07:002008-01-12T18:20:13.134-08:00Setting SSL on Apache 2.0I have been working on Ajax and JSOD recently to prototype different ways to access a secure web service in a cross domain manner. As a result, I need to setup different SSL secure domains on my local box. I have used name based virtual host with Apache 2.0 before to setup mutiple hosts on my box. But setting SSL sites could be a challenge.Fortunately I found a execllent guide on the web and was hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-1147101690630473322006-05-08T08:20:00.000-07:002008-01-12T18:22:46.757-08:00Implementing web service on JBoss 4.0.3My recent project involves implementing web services on JBoss platform. The current implementation (4.0.3) is based on a modified Axis code base and does not provides a good support on top-down (starts from WSDL) development approach. I ended up have to integrate Axis 1.2 with JBoss 4.0.3. It works well so far.At the same time, I have been looking into the next generation of JBoss WS which looks hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-1147101577949747472006-05-08T08:19:00.000-07:002008-01-12T18:23:37.959-08:00A maven 1.x plug-in for AgitarI have been spending some time to create a Maven 1.x plug-in for Agitar . It was finally done last week and I have posted it on Agitar's forum .hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com2tag:blogger.com,1999:blog-20785750.post-1144281160773767922006-04-05T16:51:00.000-07:002008-01-12T18:24:31.307-08:00A Python script to sync. with PerforceI have been using Fitnesse for a while. But I am not happy with the file system based backup. There is no easy way to setup a SCM back end for the Fitnesse. So I end up have to write a Python script to periodically sync. my local page with a Perforce depot. It works quite convenient.hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-1144280896401869522006-04-05T16:46:00.000-07:002008-01-12T18:25:04.902-08:00Bitten by MavenI have been struggling with my Maven script for a few hours. Finally it turned out is because of a property name I used. After I changed the name from "someA-someB" to "someA.someB", the problem is gone. Maven just does not like '-'.hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-1141659605835307152006-03-06T07:38:00.000-08:002008-01-12T18:25:33.436-08:00Turn off caching for FirefoxI have a need to turn off the caching for a particular page. I suppose the correct way is to set the cache directive in my Http request:Cache-Control: no-cacheThe server correctly returns the new version. The Firefox, however, insists to return me the cached old version.So I have to turn the entire Firefox caching capability off through its about:config page network.http.use-cache = false.Too bad.hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com6tag:blogger.com,1999:blog-20785750.post-1141659459659800472006-03-06T07:36:00.000-08:002008-01-12T18:53:50.705-08:00My first grease monkey scriptI wrote my first grease monkey script today. It is to apply a XSLT style sheet on certain types of XML files. This is because usually the xml contains too much information and I just want ot view certain part of it and in more clean format such as a table. Here is the code:/*Title:xml transformerDescription:This is a Greasemonkey user script for Firefox.This script applies XSLT on plain XML fileshsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com1tag:blogger.com,1999:blog-20785750.post-1140198349254799282006-02-17T09:41:00.000-08:002008-01-12T22:01:48.072-08:00Mapping xml to Python objectsI need to process XML in my python code and prefer to deal with the data in the pythonic way. From a wide options available, I choose to play with 3 of them. * generateDS * gnosis.xml.objectify * amara Because I am a fan of XmlBeans, it seems that generateDS should be my favorite choice. However, when I tried to run the code-generating script on my schema file, it encountered some recursive hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-1140111144908396032006-02-16T09:29:00.000-08:002008-01-12T19:05:31.167-08:002 tips about JBoss* to retrieve the server name, such as "minimal", "default", "max", in your codeString serverName = System.getProperty( org.jboss.system.server.ServerConfig.SERVER_NAME); * to set an unique Xid for each JBoss instanceif you are running multiple JBoss instances on the same machine, you probably want to give each instance a unique Xid base name. To do it, you need to addthe following line in the hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-1140026288282144462006-02-15T09:56:00.000-08:002008-01-12T19:07:21.152-08:00Successfully installed TwistedI need to install the latest Twisted with Python 2.4. Unfortunately I don't have Visual Studio on my machine. Is there a way to do it. I find this excellent instruction on how to install Python extensions without VS. It works as advertised. I am happily running Twisted now!hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0tag:blogger.com,1999:blog-20785750.post-1139866023601662362006-02-13T13:25:00.000-08:002008-01-12T19:08:47.127-08:00Upgrade to CruiseControl 2.4.0Today I upgraded my CruiseControl to 2.4.0. The main reason is my project's SCM has been moved from Visual Source Safe to Perforce and I cannot get the CruiseControl 2.2.1 to work with Perforce. After the upgrade, everything comes back to normal.hsunhttp://www.blogger.com/profile/17732445074262240952noreply@blogger.com0