Saturday, April 30, 2011

Rediscover the power of Ant

My last post talks about using groovy template to generate a text file, but I did not realize it can be done in Ant until reading the book- "Ant in action".
Recently when I refactored the ant build script of our comany's build system, I realize I need to learn ant systematically to improve my skills in Ant, so I choose this famous book.
When I learned the "filterset" datatype, I realize I can use that to generate the text file from a template, for example the last example can be written in Ant:
<copy file="test2.template" toFile="test2.txt" overwrite="true">
   <filterset begintoken="%" endtoken="%">
     <filter token="firstname" value="Steve"/>
     <filter token="lastname" value="Zhang"/>
     <filter token="city" value="Toronto"/>
It is even simpler than Groovy in this case, right?
This example exposes my ignorance level of Ant, I realize that there a still lots of Gems in Ant. As Douglas Crockford said most language contains good parts and bad parts, we need to use only good parts and avoid bad parts, I think what he said also can apply to Ant. So don't easily discard a tool or a language, right now in my case, I love Groovy, I love Gant, they look so cool, but I am not 100% precent for sure Groovy/Gant can fully replace our build script. I have to rely on Ant now.
I start understand the reason why our build script is a kind of ugly: probably we did not fully use the good parts of ant and too much bad parts instead.
So my next step is start reading Ant in Action!

Friday, April 22, 2011

Invoke Groovy script from Ant or Gant

Recently I tried to use groovy script to improve our build system. I found Groovy TemplateEngine is so powerful and very easy to use, quite similar to erb in Ruby. I want to use it to generate a text file. The following example shows how to generate a text file based on a template.

file test.template
Dear "$firstname $lastname",
So nice to meet you in <% out << (city == "New York" ? "\"The Big Apple\"" : city) %>.

file test.groovy
import groovy.text.SimpleTemplateEngine
import groovy.text.GStringTemplateEngine

def f = new File(this.args[0])
def binding = ["firstname":args[1], "lastname":args[2], "city":args[3]]
engine = new GStringTemplateEngine()
template = engine.createTemplate(f).make(binding)
println template.toString()

If in a terminal if I type:  groovy test.groovy Steve Zhang Toronto, and I will get output

Dear "Steve Zhang",
So nice to meet you in Toronto.

Invoke Groovy from Ant
I followed this article from Groovy site
Following is the ant script:
 <taskdef name="groovy"
 <target name="helloGroovy">
     println "hello world"
    <target name="testTemplate">
   <groovy src="test.groovy">
    <arg line="test.template"/>
    <arg line="Steve" />
    <arg line="Zhang"/>
    <arg line="Toronto"/>
It pretty straight forward, first declare <taskdef>, you need to put groovy-all-version.jar in the class path, but it took me a while to figure out where the groovy-all-xxx.jar is, finally I got it: when you download the binary zip file, unzip it, find embeddable folder, inside this folder you will find the groovy-all-1.7.x.jar!
Then you can put any kind of groovy code inside <groovy>.

Invoke Groovy Script from Gant
Gant is a great tool to replace Ant, I can definitely convert the above build.xml to build.gant, but I realize it is a kind of weird, since Gant is already based on Groovy, it already depends on Groovy jars, why we still need to declare the dependency in groovy-all-xxx.jar? There must be a better solution. Through my exploration, I found two ways to call Groovy script from Gant:

A) Use GroovyShell
target( runGroovy:"run a groovy script") {
 def shell = new GroovyShell() File("test.groovy"),
               ["test.template","Steve","Zhang","Toronto"] as String[])

The above gant script also tells you how to invoke a groovy script from another Groovy script file. GroovyShell can do this for us.

B) Embed the groovy source code directly in the Gant script file
During the exploration, I have some feeling that Gant script might can be thought of Groovy code, what if we add the groovy source code directly into the Gant script, so I did this:
import groovy.text.GStringTemplateEngine

target( hello: "hello") {
  println "hello"

target( runGroovy:"run a groovy script") {
 def shell = new GroovyShell() File("test.groovy"),
               ["test.template","Steve","Zhang","Toronto"] as String[])

target(runTemplate :"run a groovy template") {
 def f = new File('test.template')
 def binding = ["firstname":"Steve", "lastname":"Zhang", "city":"Toronto"]
 engine = new GStringTemplateEngine()
 template = engine.createTemplate(f).make(binding)
    println template.toString()
The target runTemplate will have the same result output, when you look at the import statement at the top, and the groovy code inside the target, I realize that Gant script is actually Groovy code!, the Gant target can be regarded as Groovy method. This conclusion is so important, because it means you can easily integrate the Groovy(or Java) code in the build script, I am sure it will definitely improve developer's productivity.

Sunday, April 17, 2011

Foscam FI8918W wireless IP camera review

I am looking for a video camera as baby monitor for a while. Currently all the baby video cameras in the market are too expensive, over $200 - $300, even that the features are quite limited. So I start looking for the replacement: the IP camera, and finally in Amazon I found FOSCAM FI8918W, it has almost all the features I need: pan/tilt remote control, wireless-IP, info-red, built-in micro phone and speaker. The most feature attract me is the wireless-IP, you can watch your camera anywhere over the internet through your browser or iPhone!

Yesterday I finally got my Foscam wireless IP camera from I can't wait to unpack it start setting up. I just followed the manual step by step, it did not take me any longer to watch the video over the IE browser; but the hard part is making it work from the internet:
 - At first I choose UPnP, but it did not work, this took me a while;
 - Then I choose forward port as the manual suggested, configure the camera address and port number in my router, tried several times, finally get it working;
 - Last I went to to create an free domain, then configure the parameters in the camera. finally I got it working.

There is another issue: as the manual mentioned, the camera only support IE to get the audio working, but there is no audio on my windows 7, after I followed this article, finally I got it working. Since the camera relies on ActiveX to make audio working, so currently audio does not support on other browsers: Firefox, Chrome, Safari.

Overall the camera does exactly what it mentioned. I like this camera:
- info-red feature is awesome, I can see the picture clearly at night when I turned on the info-red;
- remote control is very handy, you can control the camera in 8 direction via browser or iPhone application.
- I just found the motion detection feature, when it detects the motion, the computer will beep and automatically record the video.

- No audio output on non IE browser or iPhone application, I heard it due to the video output is Microsoft ASF format.
- No Zoom support
- Only support Wireless b/g, not support wireless-N network
- Picture quality is OK, you can see the pause, quite similar to the web cam

Comparing its feature and the price $100 in, less than the half of the regular video monitor, I think it is a good choice for a baby monitor.

The iPhone application
I downloaded the foscam surveillance pro application in my iPhone, iPod touch and iPad, it costs me $5, the app is really good, except no audio output. And at first I found the left/right control is reversed, after searching the support forum, the solution is choose FI8918W-reversed, then every thing is perfect.

Other resources
watch video with audio (works in vlc player):
 http://[your ip]/videostream.asf?user=[your_user]d&pwd=[your_pass]

watch video without audio(works in the browser):
 http://[your ip]/videostream.cgi?user=[your_user]&pwd=[your_pass]

watch video with camera in vertical stroll mode:
 http://[your ip]/decoder_control.cgi?user=[your_user]&pwd=[your_pass]&command=25

Foscam surveillance application support forum:

foscam in gadget victims

Sunday, April 3, 2011

Deming's philosophy - the root of Lean

In the Agile community, almost every one talking about Toyota's Lean technology. When we talking about lean, we can not ignore Deming, since Japanese learned a lot from Deming and goes further and have today's Lean.
Yesterday I spent some time watch Deming's videos on youtube:
W. Edwards Deming - Part 1,  Part 2,  Part 3
Dr. Deming - The 5 Deadly Diseases 1984

From these videos, you will easily find some of the lean principles do get from Deming, like: continuous improvement, eliminate wast, build quality in, respect people, optimize whole, focus on long-term goal, etc.I realize that the core of his philosophy is: respecting people, people first.

Here I copied his 14 points and 5 deadly diseases about management.
Deming's 14 points:
  1. Create constancy of purpose.
  2. Adopt the new philosophy.
  3. Cease dependence on mass inspection.Eliminate the need for massive inspection by building quality into the product in the first place.
  4. Minimize total cost when dealing with suppliers.
  5. Improve continuously products, services, and processes.
  6. Institute training on the job.
  7. Adopt and institute leadership.
  8. Drive out fear.
  9. Break down barriers between departments.
  10. Eliminate management by slogan and exhortation.
  11. Eliminate numerical quotas and goals.
  12. Eliminate barriers to joy in work.
  13. Institute a program of education and self-improvement for everyone.
  14. Put everyone to work on the transformation of the organization.

Deming's Five Deadly Diseases

1) Lack of Constancy of Purpose
- No planning for the future
- Lack of short term definition and goals

2) Emphasis on Short Term Profits
- Worship of the quarterly dividends
- Sacrificing long term growth of the organization
3) Annual Rating of Performance

- Arbitrary and unjust system
- Demoralizing to employees
- Nourishes short term performance
- Annihilates team work, encourages fear
4) Mobility of Management

- No roots in the company
- No Knowledge of the company
- No understanding of problems of company
5) Use of Visible Figures Only

- No use of figures that are unknown or unknowable, i.e., customer or employee satisfaction
- Encouraged by business schools

From the above, you will find these problems are quite common today, we need a long time to go to adopted his philosophy, this is why I am pessimistic about lean, because I feel the largest problem for lean is coming from managers, not from software developers.

Why learning philosophy is so important?
Some one might ask: we can just follow the practices or process, why we need to learn the philosophy?
I think if technology is good and worth doing, it must have some good principles or philosophy behind the concrete technologies. Once you understand the behind philosophy, you can master the technology, you will not be confused by the different variation or context. And also the detailed technologies or practices are context based, they are easily changed or deprecated with the time and context change; but principle/philosophy is different, they are abstract and can transcend the detailed context, the philosophy can be so powerful that they can apply to different context without change. That is why the art of war and the book of five ring is still useful today, because their principles are general and timeless. This is the meaning of Tao, that is why I am so obsessed by the principle and philosophy. The philosophy is hard to mastered, I remembered the author of The Toyota Way once mentioned, many companies adopted the Toyota production System, but Toyota find few companies really understand the behind philosophy. That is my suggestion, when you learn lean, you still need to understand the behind philosophy. If you just do the lean practices without knowing the philosophy, I am sure you will not do Lean correctly; you can do lean correctly only if you fully understand the lean philosophy.
Here I would like Quote What Deming said:(from his wiki)
"Once the individual understands the system of profound knowledge, he will apply its principles in every kind of relationship with other people. He will have a basis for judgment of his own decisions and for transformation of the organizations that he belongs to. The individual, once transformed, will:
  • Set an example;
  • Be a good listener, but will not compromise;
  • Continually teach other people; and
Help people to pull away from their current practices and beliefs and move into the new philosophy without a feeling of guilt about the past."