Skip to content

Two VIM Tips

1. Add something at the end of each line
:%norm A*

2. replace all occurrences in the current line


Use Seleninum with Powershell For Web Testing

Get and extract it to a local folder.

Now, a simple example:

cd d:\selenium-dotnet-2.0rc3
ls -Name *.dll | 
foreach { (pwd).path + '\' + $_ } | 
foreach { Add-Type -Path $_ }
$driver = New-Object OpenQA.Selenium.Firefox.FirefoxDriver

Scheme Programming Resources

Some userful Scheme programming resources.

Structured and Interpretation of Computer Programs (SICP) – Teach you Scheme and how to think in programming.  You can watch or download SICP videos from

You can also get it from iTunes U.

Solutions for exercises in SICP. They may help you while you are reading through SICP.

Little Schemer – Q & A Style writing. Definitely a joy to read. Just make sure you cover the answers while reading it.

How to Design Programs – A beginner friendly Scheme  book.

Computer Science 61a from UC Berkerly – a Scheme programing subject. You can get its videos from iTunes U.

Programming Praxis – Programming exercises web site. Answers are provided in Scheme.

Automate ASP.NET Deployment with Powershell: Install and Update

ASP.Net Deployment is not easy a task. It has to deal with different operating systems, web servers, databases, and etc… It often involves manual process. All these things make deployment a error prone and slow process.  It is a task you have to do it again and again. Let’s automate the whole process and relieve us of deployment hell.

1. Identify the tasks in deployment

Install, Update, Remove, Backup and Rollback. Among these tasks, Install and Update are used more frequently than others. Let’s focus on these two tasks now.

2. Deployment Tools

Let’s look at the tools available on windows platform: Windows installer, capistrano, msdeploy.

  • Windows installer – I used WIX to create installer for my web application. It’s sufficient for simple web site. There two obvious drawbacks:
    (1) WIX uses xml to create installer, but writing in XML is just pain and slow; (2) There is no easy way to handle multiple instances installation.
  • Capistrano – a popular deployment tool for rails, but it doesn’t play well with windows.
  • MS Deploy – I’ve been scared away by its complexity.

All I want is an easy and flexible solution with minimum requirements. None of them above satisfies my requirements.
Finally, I narrowed down my choices to powershell and psake. Powershell is a scripting  language for windows platform, similar to bash script in Linux. If you have used make, rake, nant, msbuild, you will find psake is quite similar. Psake is a build automation tool written in powershell.

3. Demo

Here I will create small powershell script to deploy mvc application in IIS7.

Create deployment package stucture.

\PSCommon – all our powershell modules used for deployment are in this folder

\WebApp – web application files

\default.ps1 – powershell script file contains all psake tasks

\run.bat – start a powerhell console with required modules for deployment

Create Install and Update task. To make it simple, here are install and update tasks to get started.

task Install {
	"task install"
task Update {
	"update install"

To execute the two tasks, click run.bat. Type

ipsake install


ipsake update

What’s in run.bat?

  • Start powershell console
  • Load required powershell modules
  • Set alias ipsake
powershell.exe -noexit -ExecutionPolicy unrestricted -command import-module .\PScommon\psake\psake.psm1;import-module .\PSCommon\WebAdministration;Set-Alias -Name ipsake -Value Invoke-psake

Time to add more stuff into tasks.

Install task – Create and configure web site

task Install {
    New-WebAppPool demo_pool
    $pool = Get-Item "IIS:\AppPools\demo_pool"
    $pool.managedRuntimeVersion = "v4.0"
    $pool.processModel.identityType = 2 #NetworkService
    $pool | Set-Item
    if (-not (Test-Path "c:\inetpub\demo")) {
        mkdir "c:\inetpub\demo"
    cp .\WebApp\* c:\inetpub\demo -Force -Recurse
    New-Website -Name "demo" -PhysicalPath c:\inetpub\demo -ApplicationPool "demo_pool" -Port 8686

Update task – Stop current web site; remove old files; copy new files.

task Update {
    $webSite = Get-Item "IIS:\Sites\demo"
    $filesToDelete = $webSite.physicalPath + "\*"
    if ((Get-WebsiteState -Name "demo").Value -ne "Stopped") {
    $poolName = $webSite.applicationPool
    $pool = Get-Item "IIS:\AppPools\$poolName"
    if ((Get-WebAppPoolState -Name $poolName).Value -ne "Stopped") {
    rm $filesToDelete -Recurse -Force
    cp .\WebApp\* $webSite.physicalPath -Force -Recurse

Remove task – Remove installed web application.

task Remove {
    $webSite = Get-Item "IIS:\Sites\demo"
    if ((Get-WebsiteState -Name "demo").Value -ne "Stopped") {
    $poolName = $webSite.applicationPool
    $pool = Get-Item "IIS:\AppPools\$poolName"
    if ((Get-WebAppPoolState -Name $poolName).Value -ne "Stopped") {
    Remove-Website -Name "demo"
	Remove-WebAppPool -Name $poolName
    rm $webSite.physicalPath -Recurse -Force

Download demo. To test the demo, install IIS7, powershell 2.0, IIS 7 Web Administration Module and mvc3 framework.

Use powershell to automate deployment is easy and flexible with minimum requirements on the server. You can script your own logic for deployment. This is just a simple example to get started.

Further reading:



Get Started with Scheme

I’ve been learning Scheme recently, here’re the steps to get started with Scheme quickly in Linux.

Install emacs.

If you don’t know how to use emacs, you have a look at a tutorial at

Install mit scheme. There are lot of scheme implementations. To get started quickly, we don’t want to spend too much time on choosing which implementation to use.

With emacs and mit scheme installed, it’s time launch emacs and start coding.

Use M-x run-scheme in emacs to start a scheme interactive console.

Now type (+ 1 2 3)

the result will be 6 and you should see it immediatly.

Great, we just write our first line of scheme code.