Posts

Showing posts from 2008

My Notes on Safari Nightly Build

To install safari nightly build 1. Go down to : http://webkit.org/ 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; Initialization(); /// Perform Database Tracing //// RunTracing(); } 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

Image
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);             Console.WriteLine(resultLamda1.ToString());             /////////////////////////////////////////////      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              /////////////////////////////////////////////                            

SaaS Map

Image
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.events.Event; import flash.events.MouseEvent; import flash.events.TimerEvent; 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); super(); } 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 //// [InjectionConstructor] 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"); config.Containers.Default.Configure(mycontainer); MyInterface proxy = mycontainer.Resolve (); proxy.SayHello(); } } } ////// 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";

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" { #include #include #include #include } int _tmain(int argc, _TCHAR* argv[]) { //// Just to load the codes /// av_register_all(); } 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,

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 "); _il.Emit(OpCodes.Ret); _typeBuilder.CreateType(); _modBuilder.CreateGlobalFunctions(); _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.Stloc_0); _il.Emit(OpCodes.Ldloc_0); _il.Emit(OpCodes.Ld