Sunday, July 25, 2010

VS 2010 Keyboard Shortcuts

VS 2010 Keyboard Shortcuts for C#, VB, C++, F# Now Available in Letter (8.5x11in) and A4 (210×297mm) Print-Ready Sizes [Download]

Recursion

2 types of recursion exist:


Tail

Non-Tail

void Tail(int i)
{
if(i > 0)
{
Console.WriteLine(i);
Tail(i-1);
}
}
void NonTail(int i)
{
if(i > 0)
{
NonTail(i-1);
Console.WriteLine(i);
NonTail(i-1);
}
}


Tail Recursion



  • The simplest case. A glorified loop.
  • Can simply be replace by iterative method.
  • The basic idea behind Tail Recursion is to eliminate the storage of any state information across the recursive steps. All information that would ever be needed at any single step is passed as a parameter to the function instead of being stored at some higher level in the recursion stack.
  • In tail recursion, the recursive call should be the ONLY last statement, and there should be no earlier recursive calls whether direct or indirect.
  • Used to implement loops in languages that do not support loop structures explicitly (e.g. prolog).

Example convert Tail recursion to iterative:


for loop syntax

for(init; condition; increment)
statement;










Tail


Iterative

void Tail(int i)
{
if(i > 0)
{
Console.WriteLine(i);
Tail(i-1);
}
}
void Tail(int i)
{
for(; i>0; i--)
Console.WriteLine(i);
}


Tail Recursion Examples:

public static void f1(int n)
{
Console.WriteLine(n);

if(n > 0)
f1(n - 1); //last statement with recursive call
}
public static void f3(int n)
{
if(n > 6)
{
Console.WriteLine(2*n);
f3(n – 2); //last statement with recursive call

} else if(n > 0)
{
Console.WriteLine(n);
f3(n – 1); //last statement with recursive call
}
}

Non - Tail recursion













Non Tail


Iterative

double Power(double x, int n)
{
if(n == 0)
return 1.0; //condition
else
return x * Power(x, n-1);

}

double Power(double x, int n)
{
double result = 1.0; //stack

for(result = x; n > 1 ; n--)
result = result * x;

}

string Reverse(string s)
{
if (s.Length == 1)
return s;

return Reverse(s.Substring(1)) + s[0].ToString();
}
string Reverse(string s)
{
string result = string.Empty;

for (int i = s.Length - 1; i >= 0; i--)
{
result = result + s[i].ToString();
}

return result;
}

Converting Non – Tail Recursion  to Tail Recursion



  • A non-tail recursive method can often be converted to a tail-recursive method by means of an "auxiliary" parameter. This parameter (A.K.A Accumulator) is used to form the result.
  • The idea is to attempt to incorporate the pending operation into the auxiliary parameter in such a way that the recursive call no longer has a pending operation.
  • The technique is usually used in conjunction with an "auxiliary" method. This is simply to keep the syntax clean and to hide the fact that auxiliary parameters are needed.












Non Tail


Tail

long Factorial (int n) 
{
if (n == 0)
return 1;
else
return n * Factorial (n – 1);
}

long Factorial(int n) 
{
return FactAux(n, 1);
}

long FactAux(int n, int result)
{
if (n == 0)
return result;
else
return FactAux(n-1, n * result); //using result as accumulator
}

int Fib(int n){
if (n == 0 || n == 1)
return n;
else
return Fib(n – 1) + Fib(n – 2);
}

int Fib (int n) {           
return FibAux(n, 1, 0);
}

int FibAux (int n, int next, int result) {
if (n == 0)
return result;
else
return FibAux(n – 1, next + result, next);
}


Common errors



  • Post increment and decrement operators must not be used since the update will not occur until AFTER the method call - infinite recursion.
public static int SumArray (int[ ] x, int index) 
{
if (index == x.length)return 0;
else
return x[index] + SumArray (x, index++);
}



  • Local variables must not be used to accumulate the result of a recursive method. Each recursive call has its own copy of local variables.
public static int sumArray (int[ ] x, int index)
{
int sum = 0;
if (index == x.length)return sum;
else {
sum += x[index];
return sumArray(x,index + 1);
}
}



  • Wrong placement of return statement.
incorrect version (always return initial pass in result)
public static int Sum(int n, int result) 
{
if (n >= 0)
Sum(n - 1, n + result);
return result;
}


correct version:

public static int Sum(int n, int result)
{
if (n == 0)
return result;
else
return Sum(n-1, n + result);
}

3 Days Rule


3 DAYS RULE
Uploaded by tehiiv. - Watch more comedy videos and sitcoms.

Sayz Biiiiinnnnnnng!

iPhone 4 Ads Parody

Saturday, July 24, 2010

iPhone 4 vs HTC EVO 4G

Crying Baby - Best Actor

Social Media Revolution 2 (Refresh)

Did You Know 4.0

Revenge of the Fallen

I’m always a big fans of tower defense style action game.

Recently found some that worth to try out:

Autobot Strong Hold [Play at here]

This game has free 50 stages to play with and the audio and graphics are awesome.

image

image

Canyon Defense [Play at here]

For this one, the graphic is so so. But it is a good time pass. You can also download this in iphone app store for free.

image

Robo Defense

For android lover, you can download this in the market. Very addictive game.

image

image

Optimus Prime: Sam, fate rarely calls upon us at a moment of our choosing.

Fate is in our hands, autobots transform …. and roll out!

Thursday, July 22, 2010

Color My World – Syntax highlighter

crayon

Finally found a syntax highlighter for my blogger site. It's called Syntax Highlighter [Official Site]. Duh!

Steps to enable syntax highlighter into your blog site:

1.  Go to Design > Edit Html  image

2. Find the syntax </head>.

3. Copy and Paste below statements BEFORE syntax </head> 

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeRDark.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode=true;
SyntaxHighlighter.config.clipboardSwf=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
</script>
 
&nsbp;

4. If you’re using windows live writer, you can integrate syntax highlighter using Precode Code Snippet Manager plug-in [Download here].


image


5. Here is example of Syntax Highlighter in action:

         public void ConvertStringDecimal(string stringVal) {
decimal decimalVal = 0;

try {
decimalVal = System.Convert.ToDecimal(stringVal);
System.Console.WriteLine(
"The string as a decimal is {0}.", decimalVal);
}
catch (System.OverflowException){
System.Console.WriteLine(
"The conversion from string to decimal overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string is not formatted as a decimal.");
}
catch (System.ArgumentNullException) {
System.Console.WriteLine(
"The string is null.");
}

// Decimal to string conversion will not overflow.
stringVal = System.Convert.ToString(decimalVal);
System.Console.WriteLine(
"The decimal as a string is {0}.", stringVal);
}


If you don’t like to use the plug-in, you can directly surrounding your code snippet with <pre> </pre>, example:

<pre class="brush: js">     
/** * SyntaxHighlighter */
function foo()
{
if (counter <= 10)
return; // it works!
}
</pre>

Last, Welcome to my colorful world!

Saturday, July 10, 2010

Anders Hejlsberg

Visual Studio 2010 Professional , Premium and Ultimate features comparison

image

image

image

Source: Microsoft Visual Studio 2010

天使的祝福

child-angel-field-625a

一。传说,
一个女孩的诞生,也意味着一个天使的诞生。
天使的使命是守护着女孩。

二。蜕变
女孩也长大了,变成少女。
天使还是继续默默守护着少女。

三。情愫
天使由守护,变成了爱慕。
天使已经爱上了少女。

四。心蚀
少女恋爱了。
少女已不需要天使的守护与祝福。
少女已经找到了自己的幸福。

五。诅咒
伤心的天使不再守护,不再祝福少女。
天使发现自己已经不能守护少女了。
失去了守护能力的天使,是一种诅咒。

六。幻灭
天堂是没有眼泪的。
天使的眼泪,代表着天使的终结。
流泪的天使,注定要消失。
消失前,天使献上了最后的祝福,愿少女永远幸福。

七。新生
原来天使并没有消失。
天使的终结,代表一个男人的诞生。
男人会找到他所爱的女孩。
男人会永远守护着女孩,让女孩幸福。

The Road Not Taken

decision

Robert Frost (1874–1963).  Mountain Interval.  1920.

The Road Not Taken

TWO roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;     

Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,  

And both that morning equally lay
In leaves no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.   

I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference.

Friday, July 9, 2010

Breathe new life into your laptop: Windows Server 2008 R2 as workstation

image

Forget about Windows 7 and Windows Vista, Windows Server 2008 R2 is the new bad boy for your laptop.

It runs blazing fast ,uses less hardware resources and more robust. It also equips with lots of server features such as Hyper-V, IIS 7.5, PowerShell 2.0, etc.

Best of all, it is x64 bits OS (Don’t worry, your old faithful x86 apps will still run as normal).

To run Windows Server 2008 R2 as workstation on your laptop, some customizations are needed:

  1. Install graphics and sounds drivers after installation.
  2. Enable Wireless networking
    • Click on Server Manager image besides your windows start button.
    • Inside Server Manager window, click on ‘Features’ at left panel image .
    • After that click on ‘Add Features’ at right panel image .
    • Inside Add Features Wizard window, checked ‘Wireless LAN Service’ if it is not installed. image
  3. Enable Windows Audio, Windows Media Player and Windows Photo Viewer.
    • Inside Add Features window (same as above), checked ‘Desktop Experience’ if it is not installed. image
    • After that, at Administrative Tools menu, click on ‘Services’ image .
    • Inside Services window, start ‘’Windows Audio’ service if it is not started. image
  4. Disable Internet Explorer enhanced security
    • Inside Server Manager windows (refer above step 2), click ‘Configure IE ESC’ at Security Information right panelimage
    • Click ‘Off’ radio button image
  5. Enable hibernation
    • Open a command window by typing ‘cmd’ in Run menu.
    • Inside command window, type ‘powercfg.exe –h  on’    image
    • Click on power icon at lower right of your desktop (A.K.A systray) image . Click on More power options.
    • Inside Power Options window, click on ‘Choose what closing the lid does’ image
    • Choose ‘Hibernate’ from drop down for ‘When I close the lid’ image
  6. Disable Shutdown Event Tracker
    • At Run menu, type ‘gpedit.msc’.
    • Inside Local Group Policy Editor, navigate to Computer Configuration>Administrative Templates>System image
    • Click on ‘Display Shutdown Event Tracker’ at right panel  image
    • Inside Display Shutdown Event Tracker window, click ‘disable’ radio button image
  7. Enable image thumbnails preview in windows explorer
    • At Run menu, type ‘SystemPropertiesPerformance’.
    • Inside Performance Options window, checked ‘Show thumbnails instead of icons’ image
    • Open windows explorer, then at menu bar choose Tools>Folder Options
    • Inside Folder Options window, unchecked ‘Always show icons, never thumbnails’ image

 

Now, stop drooling and start take action to give your old laptop a second life!

ServerUnleashed

Alicia Keys - Empire State of Mind, No one (South Africa 2010 FIFA World Cup)

Shakira - Waka Waka (South Africa 2010 FIFA World Cup)

Wednesday, July 7, 2010

Kick Ass - Time to go home scene

Kick Ass - Big Daddy warehouse shootout scene

Kick Ass - Hit Girl Rescue Scene

Ryan Dan - Tears of an Angel

Kaci Brown - Make you love me

Kaci Brown - Unbelievable

Bonnie Mckee - To Find You

DramaMC - Ice Ice Baby Mash Up

Bonnie McKee - Somebody

Egu-Splosion

Hamutsun Serve

U-Min

Baek Ji Young - Sarang An He

Jit Teun - Kyotte

Texas - Put Your Arms Around Me

Natalie Imbruglia - Shiver

Natalie Imbruglia - Counting Down The Days

Natalie Imbruglia - Beauty On The Fire