Showing posts from 2008

My Notes on Safari Nightly Build

To install safari nightly build

1. Go down to : and
2. Extract the file and run-nightly-webkit.cmd

You might need to run FindSafari.exe to seek out where Safari is installed in your machine

Writting a SQL Profiler

In case you're wondering how to write a SQL Profiler to automate some of your task, here are some code that you might want to try out :)

Add reference to Microsoft.SqlServer.ConnectionInfo in your project and you are good to go!

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

using Microsoft.SqlServer.Management.Trace;
using Microsoft.SqlServer.Management.Common;

using System.IO;
using System.Configuration;

namespace MSSQLProfiler

public class MSSqlTracer

ConnectionInfoBase conninfo = null;

public string TemplateTraceFile { get; set; }
public string TraceOutputFile { get; set; }

public void StartTrace(string TemplateFileSource, string OutputFileName)

TemplateTraceFile = TemplateFileSource;
TraceOutputFile = OutputFileName;


/// Perform Database Tracing ////



private void RunTracing()


Back to Serial

Wen-Mei Hwu suggest that we might be going back to sequential/serial as compare to parallel processing in the advent of multi-core processor.

This might be a step back as argue by many.

Reason for this?

# Developing a non-trivial explicitly parallel application is an expensive proposition.

# Verification and support of a hand-parallelized program is even more expensive.

# Programs developed in an explicitly parallel form are unlikely to scale with Moore's Law.

# Tools must have in-depth knowledge of the apps regardless of programming models being used anyways.

# Evolution of tools takes place at much faster pace than that of human race.

Taken from Berkeley EECS's blog.

This is kind of surprising.

Some interesting link that i find it useful are:

Click MIT - Programming Language for Multithread Programming

Clustering by Passing Messages Between Data Points

Linq Expression Tree

Linq Expression : Switching between data Structure and code

             /////////////////////////////////////////////             /// Linq Expression Tree for (x,y ) => x * y;             /// Directly build the lambda expression ///              /////////////////////////////////////////////
            Expression lambdaExpression1 = (x, y) => x * y;             Func lamba1Delegate = lambdaExpression1.Compile();             int resultLamda1 = lamba1Delegate(100, 100);

     Or you can do the following 

     Expression Func int int int  AddOperation = (x, y) => x + y;       int result = AddOperation.Compile()(10, 10);

            /////////////////////////////////////////////             ///// Rebuilding and Executing Linq Expression              ////  Manually              /////////////////////////////////////////////             ParameterExpression p1 = Expression.Parameter(ty…

SaaS Map

Something i found long long time ago....... Kinda like it. 

Biztalk : Pipeline Stamping Receive Message

This code allows you to stamp your incoming message with a XML element called SequenceNo. This sequence number gives you the ability to sequence without making changes to your existing application.  It is unique in the sense that it does not create a new part for you and there shouldn't be too much modification to your existing codes in order to implement it. 

Creating a pipeline in Biztalk Server is relatively easy. It requires you to

1) Implement specific Interface

2) Create a Biztalk Project that uses a pipeline Item type with extension Btp. Drag the assembly that you have created above into [validate] section.

3) Deploy and move it to the right application. You need to configure properly after this.

So first you have to come up with an assembly that overrides the Execute method as shown below. It returns a new IBaseMessage: 
 public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)         {             int seq = 0;
            /// new message structure ///           …

Accelerating Scrollable Flex Control

The general concept of creating this control is using a Timer to control, scroll through your control before slowing down after it is being triggered by Mouse_Wheel.
So you need to listen to two events.

package com.controls.controls
import flash.utils.Timer;

import mx.controls.List;

public class CtlList extends List

public var sliderSpeed:Number=5;
public var sliderSlowSpeed:Number=1;
private var sliderAlreadyScrolling:Boolean=false;
private var QtyBeforeSlowDown:Number=5;
private var slideTimeCounter:Number=20;
private var currentSlideCounter:Number=slideTimeCounter;

private var DownDirection:Boolean=true;

public function CtlList()
this.addEventListener(MouseEvent.MOUSE_WHEEL, MouseWheel_Scrolling);

private function MouseWheel_Scrolling(evt:MouseEvent):void

if (!sliderAlreadyScrolling)
/// do scrolling ///


Exception Do and Don'ts

From Microsoft MSDN.

1.Do not return error codes. Exceptions are the primary means of reporting errors in frameworks.

2.Do report execution failures by throwing exceptions. Consider terminating the process by calling System.Environment.FailFast. Do not use exceptions for normal flow of control, if possible. Except for system failures and operations with potential race conditions

3. onsider the performance implications of throwing exceptions.

4.Consider using exception builder methods. It is common to throw the same exception from different places. To avoid code bloat, use helper methods that create exceptions and initialize their properties.

5.Do not throw exceptions from exception filter blocks. If you're C# programmer ; you can ignore this.

6.Avoid explicitly throwing exceptions from finally blocks. Implicitly thrown exceptions resulting from calling methods that throw are acceptable.

Example Microsoft Unity Block Configuration : Passing Value to Constructor

This is a sample of our configuration file that allows us to initialize value to our constructor.

/// Our Constructor ////

public MyClass(string myParam, string myParam2)
string p1 = myParam;
string p2 = myParam2;

Example : Using Microsoft Unity Block from Configuration File

/// Client code ///

using Microsoft.Practices.Unity.Configuration;
using System.Configuration;
using Microsoft.Practices.Unity;

namespace unityman
class Program
static void Main(string[] args)
IUnityContainer mycontainer = new UnityContainer();
UnityConfigurationSection config = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
MyInterface proxy = mycontainer.Resolve();


////// App.config Configuration File ////

Optionally you can change MyClass from FriendClass to see it's effects.

//// MyInterface, MyClass and FriendClass codes

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Unity;

namespace myunityclass
public class MyClass : MyInterface
public MyClass(MyParam myParam)
myParam.UserAddress = "1111";
myParam.userName = "Jeremy"…

FFMpeg on MSVC++

Instead of building FFMPEG using Cygwin and Msys you can get the libraries from here.

Next goto you need to extract this into a folder.

Once you have extracted you need to create a simple Win32 console application in Visual Studio and configure its properties.

Under Configuration Properties

C/C++->Additional Include Directories = C:\del\ffmpeg\include\libavcodec;C:\del\ffmpeg\include\libavutil;C:\del\ffmpeg\include\libavformat; C:\del\ffmpeg\include\libswscale

Linker->General->Additional Libraries Directory = C:\del\ffmpeg\lib

Linker->Input->swscale-0.lib avdevice-52.lib avformat-52.lib avcodec-51.lib avutil-49.lib

To test your project out, use to following codes and see if you can compile it .

extern "C"



int _tmain(int argc, _TCHAR* argv[])

//// Just to load the codes ///

Next please make sure you copy the required *.dll (from the distribution above) to your project folder;

ILCode for newobj by creating a new custom Type

AssemblyName _assemblyName = new AssemblyName();
_assemblyName.Name = "newObj";
AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name + ".exe");
TypeBuilder _typeBuilder = _modBuilder.DefineType(" ILCode.Program");

TypeBuilder _customType = _modBuilder.DefineType("ILCode.myCustomType", TypeAttributes.Public);

Type[] arg = { typeof(string) };
ConstructorBuilder _customTypeConstructor = _customType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, arg);
PropertyBuilder _prop1 = _customType.DefineProperty("MyId", PropertyAttributes.None, typeof(int), new Type[0]);
PropertyBuilder _prop2 = _customType.DefineProperty("MyName", PropertyAttributes.None, typeof(…

MSIL Hello World

AssemblyName _assemblyName = new AssemblyName();
_assemblyName.Name = "helloWorld";
AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);

ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name+ ".exe");

TypeBuilder _typeBuilder = _modBuilder.DefineType("Foo");

MethodBuilder _methodBuilder = _typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);
ILGenerator _il = _methodBuilder.GetILGenerator();

_il.EmitWriteLine("hello World ");

_assemblyBuilder.SetEntryPoint(_methodBuilder, PEFileKinds.ConsoleApplication);
_assemblyBuilder.Save(_assemblyName.Name + ".exe");
_il = null;

MSIL IF Statement

This example shows you how to generate IL for a simple IF statement

Code in C#

int x = 1000;
if (x > 2000)
Console.WriteLine("Hey There");

Using Reflection Emit

AssemblyName _assemblyName = new AssemblyName();
_assemblyName.Name = "ifS";
AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);

ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name + ".exe", true);
TypeBuilder _typeBuilder = _modBuilder.DefineType("IfType");

MethodBuilder _methodBuilder = _typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);

ILGenerator _il = _methodBuilder.GetILGenerator();

LocalBuilder _intName = _il.DeclareLocal(typeof(int));
Label body = _il.DefineLabel();

_il.Emit(OpCodes.Ldc_I4, 1000);
_il.Emit(OpCodes.Ldc_I4, 2000);
_il.Emit(OpCodes.Blt, body);