Using hosts file to block Online Ads

Online ads are annoying but they make a lot of content free on web. At times I feel like I am browsing just the ads though.

There are plug-ins for Firefox and IE to block ads but I use Opera. Opera has inbuilt content blocking but that is too much to do as there are a zillion ad servers out there. At times I have to use FF or IE too and this leaves me managing three different applications to block ads. On top of that, putting a plug-in in the pipeline is again adding one more step before you can see the content. And then you have to keep updating them for new releases. Not a good idea, I’d say.

Another way is to use hosts file. Description of hosts file from wikipedia:

The hosts file is a computer file used to store information on where to find a node on a computer network. This file maps hostnames to IP addresses. The hosts file is used as a supplement to (or instead of) the domain name system on networks of varying sizes. This file is (unlike DNS) under the control of the user who is using the computer.

There is a lot of information available on internet which you can use to make it work. In a nutshell, here is what you need to do:

  1. Download a hosts file which has updated lists of ad servers. I’m using one from here and added few missing servers. Can you believe this list has around 6000 entries already? And if you follow the link, please don’t try those shock sites. 😦 More hosts files can be found here.
  2. Create a backup of your existing hosts file. (just give it an extn say .old.) On Vista, hosts file can be found in [System Drive]:\Windows\System32\drivers\etc. See this to locate on other systems.
  3. Copy the downloaded hosts file in the etc folder. If you are using the site which I did then create another hosts file in etc folder and paste the contents from browser. See this if you are trying to edit the hosts file on Vista when UAC is enabled.
  4. And that’s pretty much it. Try some ad plagued site like engadget and you should see blank space instead of ads.
  5. Also, don’t forget to update the hosts file as frequently as you can as more and more servers will be popping out every now and then.

Here are few links to learn more:

Enjoy!

PS: The hosts file I am using and gave the link above has entries for known malware, trojans and user tracking sites too. It also has entries for ad servers like yahoo, msn and others which can make some sites behave unexpectedly. Please see inline comments on the site.

Advertisement

Juggler : Automatic Wallpaper Changer for Windows

If you have followed previous posts, you should already have a huge collection of wallpapers. If you don’t, go to previous posts to get details on how to download high quality wallpapers.

Spectacular Wallpapers from InterfaceLIFT, Tool to download them all

Next step is to automate changing wallpapers. Going back to “Personalization” settings every time is really not something I’d prefer. So again, I coded up a small and handy app which can do this for us.

  • It runs in background and can be controlled from System Tray.
  • It can be configured to
      • start with Windows.
      • look for wallpapers in a specific directory. Best way to use this is to dump all wallpapers matching your resolution in one folder and configure to use that folder.
      • change wallpaper once in half, one or two hrs.
  • You can also manually change wallpaper by using Juggle menu or double clicking the icon.
  • You’ve got the source. So, change it if you want more features. 🙂

And that’s pretty much it. I’m using it on Vista. It will NOT work on XP (or anything other than Vista for that matter) as XP doesn’t support JPEG images as wallpapers and that’s what I am using. I may update it later if I could spare some time. You can get a tool which may work with XP at Coding4Fun. And if you want you can always change the code [link below]. Updated to work with Vista and XP.

Remember, it’s not fully tested or final app. I just coded and left it when it started doing what I wanted so possible some edge cases are broken. 🙂

Juggler.exe.zip [Independent Executable]

Juggler.source.zip [Source Code, VS 2005]

Links disabled for outdated app. Follow the link below for updated links.

Enjoy!

UPDATE: I’ve updated this app with fixes and more features. Please navigate to the detailed post for description and download.

Spectacular Wallpapers from InterfaceLIFT, Tool to download them all

InterfaceLIFT is one of the best source for high resolution wallpapers out there. A lot of artists post their work on this site. Thousands of wallpapers are available to browse and download but it’s annoying to click on each one of them and save manually.

I though it would be good if I can automate this or some kind of tool that can do this for me. So yesterday night, without wasting anymore time, I decided to code one up.

Its simple. Choose the resolution you want, choose the location to want to save images to and hit “Search and Download Wallpapers”. You may also want to change the sorting to Ratings or Downloads to get community rated wallpapers first.

And here is how it works: On the website, interfacelift uses javascript to prepare the links for actual images. I checked the HTML source and thought I could exploit that approach.

  • It gets the HTML markup for first page.
  • Search for javascript method calls and get the unique identifiers for wallpapers on current page and prepare a list of actual image names.
  • Loop through all images on current page.
  • Download one at a time and save to local disk.
  • Get markup for the the next page.
  • Go to step 2.
  • Keep doing this until user hits Stop or we run out of pages.

And that’s it. Its pretty simple. I ran it on Vista and XP against .Net 2.0. You can download the independent executable and/or source (C#). See update below to download.

WallpaperCrawler.exe.zip [Independent Executable]

WallpaperCrawler.source.zip [Complete Source Code, VS 2005]

I know it can be enhanced or made more robust. But hey I just coded it in couple of hours for the functionality I needed. I haven’t even tested it properly but it did what I was looking for.

Enjoy!

PS. By no means its a tested and final app. I don’t take any responsibilities for the issues you may run into by using this.

Update: This program is now part of Juggler (another app I created for changing wallpapers). Please navigate to the description page to download the latest version.

TFS : The Real Picture

For every technology, there is the theory you learn and then you have to implement it in real world. You can find books for theory but for real implementation, there are hardly any. For TFS though, there is a guide on CodePlex which describes how TFS should be used in real projects. Excerpts from the site:

This guide shows you how to make the most of Team Foundation Server. It starts with the end in mind, but shows you how to incrementally adopt TFS for your organization. It’s a collaborative effort between patterns & practices, Team System team members, and industry experts

patterns & practices: Team Development with Visual Studio Team Foundation Server

Trigger Gotchas

While working with triggers, I noticed a couple of unexpected behaviors in SQL Server.

1. Let’s say you have an INSERT statement something like this:

INSERT INTO SomeTable VALUES (Col1, Col2)
SELECT Val1, Val2 FROM SourceTable WHERE 1=0

The select statement is never going to return any rows due to the where clause (always false) and nothing would be inserted into SomeTable. So, if there is an AFTER INSERT trigger on SomeTable, what do you think about it. Should it fire? Remember, there is not going to be any insert.  If your answer is NO ( as it was mine and few others too), think again. Because it DOES fire.

2. Another situation. Lets have the same INSERT statement but without any WHERE clause. So the query will be something like this:

INSERT INTO SomeTable VALUES (Col1, Col2)
SELECT Val1, Val2 FROM SourceTable

In this case if SourceTable has 100 records and there is an AFTER INSERT trigger on SomeTable, how many times that trigger should fire. Remember, there are going to be 100 new rows in SomeTable. If you answer is 100 (as it was mine too, again), check Books Online once more. The trigger is going to fire ONLY once.

One thing to note in both situations is that the LOGICAL tables have the correct information. That said, INSERTED logical table is going to be empty in first example and it will have 100 rows in second one. So, these logical table are your best bet. This behavior is same for DELETE and UPDATE after trigger too. Means, if you execute a delete or update statement which will not affect any row, triggers will fire regardless and it will fire once per statement NOT per affected row.

Hope this will helps. Enjoy!