WCF Tracing basics

Pretty old but still handy configuration.

IIS + ASP.NET only.


            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
               <add name="traceListener"
                   initializeData= "c:\log\Traces.svclog" />

Recovered from disk io error

Sometime earlier (several hours ago), there’s a really high disk io then all services are down.
I found the file system was remount in RO mode. Something weird.
Anyway, fixed now.
feuvan@wonderland:~$ sudo fsck
fsck from util-linux-ng 2.17.2
e2fsck 1.41.11 (14-Mar-2010)
/dev/xvda contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Inodes that were part of a corrupted orphan linked list found. Fix? yes

Inode 114702 was part of the orphaned inode list. FIXED.
Inode 303107 was part of the orphaned inode list. FIXED.
Deleted inode 958465 has zero dtime. Fix? yes

Inode 958466 was part of the orphaned inode list. FIXED.
Inode 958467 was part of the orphaned inode list. FIXED.
Inode 958468 was part of the orphaned inode list. FIXED.
Inode 958470 was part of the orphaned inode list. FIXED.
Deleted inode 961482 has zero dtime. Fix? yes

Inode 961483 was part of the orphaned inode list. FIXED.
Inode 961484 was part of the orphaned inode list. FIXED.
Inode 961485 was part of the orphaned inode list. FIXED.
Inode 961486 was part of the orphaned inode list. FIXED.
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences: -583804 -(583806–583815) -(1232332–1232666)
Fix? yes

Free blocks count wrong for group #17 (4, counted=15).
Fix? yes

Free blocks count wrong for group #37 (13654, counted=13989).
Fix? yes

Free blocks count wrong (2522826, counted=2523172).
Fix? yes

Inode bitmap differences: -114702 -303107 -(958465–958468) -958470 -(961482–961486)
Fix? yes

Free inodes count wrong for group #14 (8130, counted=8131).
Fix? yes

Free inodes count wrong for group #37 (6348, counted=6349).
Fix? yes

Free inodes count wrong for group #117 (5170, counted=5180).
Fix? yes

Free inodes count wrong (910912, counted=910924).
Fix? yes

/dev/xvda: * REBOOT LINUX *
/dev/xvda: 121268/1032192 files (2.6% non-contiguous), 1605596/4128768 blocks
feuvan@wonderland:~$ sudo reboot

Broadcast message from feuvan@wonderland
(/dev/pts/0) at 3:58 …

The system is going down for reboot NOW!

Install IE9 preview 4 on server SKU

For users who are interested in HTML5/CSS3/SVG supported browser IE9, please refer to http://ie.microsoft.com/testdrive/.

If you are blocked to install IE9 preview 4 on server 2008 or R2 (see error msg below), you can use Orca to modify the msi package.

[caption id=”attachment_10058” align=”alignnone” width=”376” caption=”IE9 Preview 4 install blocked on server SKU”]IE9 Preview 4 install blocked on server SKU[/caption]

You may find Orca.msi on your hard disk “C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\”.
Or download it, refer to KB255905.

Once Orca is installed, follow the steps to modify the MSI to allow installation on server SKU:

  1. Use Orca to open iepreview.msi, Ctrl-F to search string “iepreview_no_server”, you will find it in table “CustomAction” and “InstallExecuteSequence”.
  1. Right click on the action and choose “Drop Row” to delete the row in “InstallExecuteSequence”.
  1. Save the MSI.
  1. Double click to install.

[caption id=”attachment_10064” align=”alignnone” width=”640” caption=”Find iepreview_no_server in Orca”]Find iepreview_no_server in Orca[/caption]

If you would like to know how to find the action “iepreview_no_server” to be deleted, you can try install the original MSI in command line:

msiexec /i iepreview.msi /l*vx ie9p4.log

and analyze the log by yourself. Notice where error occurs.

New desktop computer

i5-750 + OCZ3G1333LV4G * 2 + MSI P55-CD53 +
EVGA GTX465 + WD20EARS 2TB + Antec EA650 +
Sony AD-7240S-0B
Rosewill CHALLENGER Black Gaming ATX Mid Tower
with Microsoft Natural Ergonomic Desktop 7000

from newegg.

Microsoft desktop from company store.

Dell U2410 will arrive on Friday.

The new desktop computer is the 3rd desktop in my life. It will be used for SharePoint Server farm, home storage server and also WOW game box.

Enable Touchpad Scroll for iTunes, VirtualBox

Open C:\Program Files\Synaptics\SynTP*TP4scroll.dat and TP4table.dat* with Administrator privilege.

Add these lines after mstsc.exe

; iTunes

; VirtualBox

Kill all processes started with “SynTP…exe”. (Should be “SynTPEnh.exe”, “SynTPHelper.exe” and “SynTPLpr.exe”). Then run SynTPEnh.exe.

Or simply logoff and login again.

Restore VirtualBox VMs after reinstall OS

Simply use vboxmanage.exe utility.

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe registervm “E:\Machines\7 Lite\7 Lite.xml”
Oracle VM VirtualBox Command Line Management Interface Version 3.2.4
(C) 2005-2010 Oracle Corporation
All rights reserved.

Then 7 Lite will appear in your VirtualBox GUI.

Peak at C# 4.0: optional parameter, named parameter and method resolution

Optional and named parameter is an awesome feature introduced in C# 4.0. Now C# combines some fancy features from dynamic languages like Python again (var knows why I say again. And the more dynamic dynamic is another topic, LOL).

Please note the “NEW:” comment for optional parameter declaration and named parameter assignment.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp
class Program
static void Main(string[] args)
var top = new TestOptionalParameter();
double d = top.Demo(0); // #1

// int d = top.Demo(0, s: “test”); // NEW: named parameter.

class TestOptionalParameter
public int Demo(int i, string s = “demo purpose”) // #2 NEW: optional parameter declaration
Console.WriteLine(“int Demo(int i, string s = \”demo purpose\”)”);
return 0;

public double Demo(int i) // #3
Console.WriteLine(“double Demo(int i)”);
return 0;

But when combined with method name resolution, unconsidered condition may occur.

Try these changes and you will realize what you’ll pay for fancy new features: (Play it with VS2010. I don’t want to copy and paste several times and just modify one place of return type or variable value.)

Change #1
Change #2
Change #3

Works as expected. Matches 2nd Demo method.

change double to int

Easy to understand, the 1st Demo matches better. (Fully match in/out/return parameter, though there’s an optional parameter not specified when invoking the method)

add named parameter. change it to
double d = top.Demo(0, s: “test”);

still the 1st Demo matches better. Now named parameter takes place.

change int to double
Match 1st. No implicit conversion required for parameter.

change 0 to 0.0

Compile error. Explicit conversion required.

change 0 to 0.0
change int to double

Match 1st. No implicit conversion required for parameter.

Whenever add 2nd string parameter, named with “s” or unnamed.

Match 1st.

Some looks-hard-but-actually-straightforward-and-ideal conclusion:

  1. Whenever named or unnamed parameter used, method don’t accept these parameters will be out.
  1. If implicit conversion is NOT required, traditional method resolution goes first, then goes to match methods with optional parameter. (please note there’s some a-bit-evil details to be discussed.)
  1. If implicit conversion is required for parameter or return type, match method with matched implicit parameter first.
  1. When explicit conversion is required or specified error parameter name or value type, compile time error will be triggered.

memcached practice: A weird twitter gadget

memcached is widely used in modern websites like flickr, wikipedia, twitter, youtube, digg, WordPress and a long hot continuing list. In the past years, everyone is talking about XXX 2.0, and recently, yes, you got it, NoSQL….

Here’s a weird twitter gadget, to be used by other pages as gadget. You may notice some bad practice on variable naming, function organizing, but ignore them.
The main purpose is to demonstrate a memcached usage, when combined with HTTP cache control.

source generated by “php -s”

define(‘SECRETSTRING’, ‘===’); // base64_encode(‘user:password’)
define(‘USERTIMELINEURL’, ‘https://api.twitter.com/1/statuses/user_timeline.json?count=20‘);
define(‘EXPIRESECONDS’, 300);

function gettweets()
“”, //localhost
$keyname = ‘fvn:tweets’;

$mc = new Memcache();
foreach($MEMCACHE_SERVERS as $server){
$mc->addServer ( $server );
$ret = FALSE;
if( !(isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’]))) {// force refresh
$tweets = gettweetsdirectly();
if ($mc->get($keyname) === FALSE) {
$ret = $mc->set($keyname, $tweets, MEMCACHE_COMPRESSED, EXPIRESECONDS);
} else {
$ret = $mc->replace($keyname, $tweets, MEMCACHE_COMPRESSED, EXPIRESECONDS);
} else {
$tweets = $mc->get($keyname);
if ($tweets === FALSE)
$tweets = gettweetsdirectly();
// cache for 10 minutes
$mc->set($keyname, $tweets, MEMCACHE_COMPRESSED, EXPIRESECONDS);
return $tweets;

function gettweetsdirectly()
$context = stream_context_create(array(
‘http’ => array(
‘header’ => “Authorization: Basic “ . SECRETSTRING)
$data = file_get_contents(USERTIMELINEURL, false, $context);
$tweets = json_decode($data, true);
if ($tweets == NULL)
return FALSE;
return $tweets;

// from http://github.com/dizzytree/PHP-Twitter-Client/blob/master/config.php
function format_tweet($str)
$formatted_text = preg_replace(‘/(\b(www.|http\:\/\/|https\:\/\/)\S+\b)/‘, “$1“, $str);
$formatted_text = preg_replace(‘/#(\w+)/‘, “#$1“, $formatted_text);
$formatted_text = preg_replace(‘/\@(\w+)/‘, “@$1“, $formatted_text);
return $formatted_text;

$t = gettweets();
if ($t == FALSE)
header (‘Failed to get tweets.’, 500);

//cache control
$lasttime = strtotime($t[0][‘created_at’]);
if (isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’]) && (strtotime($_SERVER[‘HTTP_IF_MODIFIED_SINCE’]) == $lasttime)) {
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’, $lasttime).’ GMT’, true, 304);
} else {
header(‘Last-Modified: ‘ . gmdate(“D, d M Y H:i:s”, $lasttime) . ‘ GMT’);
header(‘Expires: ‘ . gmdate(“D, d M Y H:i:s”, $lasttime + EXPIRESECONDS) . ‘ GMT’);

//echo tweets
echo ‘

    $len = count($t);
    for ($i = 0; $i < $len; $i++)
    echo ‘

  • ‘;
    echo format_tweet($t[$i][‘text’]);
  • echo ‘

    echo ‘‘;