Tuesday, November 30, 2010

Generate HashSet of Prime numbers, check if Prime. Basic

public static HashSet<int> GetPrimes(int max)
  HashSet<int> primes = new HashSet<int>();
  for (int i = 2; i < max; i++)
   if (IsPrime(i))
  return primes;

private static bool IsPrime(int candidate)
  bool prime = true;
  double sqr = Math.Sqrt(candidate);
  for (int i = 2; i <= sqr; i++)
   if (candidate % i == 0)
    prime = false;
  return prime;

Thursday, November 18, 2010

How to block advertisements in Windows Live Messenger

A friend asked me how I managed to get rid of the advertisements in Windows Live Messenger so I thought that I'd share it here.
I found this little trick some years ago when I got annoyed by the mouse over adverts that expanded outside the initial box that they appear in. I honestly do not remember where I found it and when I try to Google for the fix now it only finds some downloadable applications that should 'fix the ads'. They seem a little suspicious thou so I'll just share my fix here.

It seems that Windows Live Messenger gets all its advertisements from various feeds from msn.com, msads.net and live.com. Lucky us the feeds originate from subdomains to these addresses so we don't have to block the whole domains.

1. Open your "hosts" file that is located in one of the system folders.
  XP : C:\WINDOWS\system32\drivers\etc

Note that the file may be read-only so you should open it with administrative privileges. Right click and select "Run as Administrator".

2. Add the following lines to the end of the hosts file below the reference to localhost. rad.msn.com global.msads.net rss.video.msn.com ads1.msn.com rad.live.com specials.uk.msn.com

3. Save the file.


windows_live_messenger_after_no_advertisements_fixThe advertisements may still show for a little while after the fix has been applied. The next time Windows Live Messenger tries to download new advertisements it will only show a non clickable logo as seen in the picture to the right.
To speed up the process just restart Windows Live Messenger and the fix should be applied immediately.