How to block online ads with the hosts file


Am I the only one who is skeptical clicking on ads I see online? Yes, I know it is the lifeblood of entrepreneurs, but I really don't care to view more than I have to. We all know the 7 +- 2 rule; we have a limit of the amount of information we can take in at a single time. It's a fact. We are not infinite in our abilities alone - let's just let the computers do the thinking for us. 
Google adsense ads
Inline Adsense ads
While I recently tried to set up a more elegant solution, I wanted to share with you how you have the power to block ads (in case you didn't know already) and regain [more] control of what you are looking at online.
This is the easy answer, just install Adblock Plus (Chrome).
Adblock plus (credit to https://chrome.google.com/webstore/detail/adblock-plus/cfhdojbkjhnklbpkdaibdccddilifddb?hl=en-US)
Adblock Plus on the Chrome web store
Adblock does it all for you. Ads? No more. It's really a golden bullet. However, if you want to grow as a developer, sometimes it pays to try and do things in a different way in order to learn how more things work under the hood.
Do you remember that little file you may have heard about in your networking class? Well, here it is again. The hosts file.
Fun fact, the hosts file was a precursor to DNS.
A simple file that maps IP addresses to host names, how can it help block ads online? Before we get into that, we need to briefly understand how ads appear on our websites in the first place.
Ugh. And no, I'm not talking about these pixels.
Pixel Mario (credit to https://medium.com/nepfin-engineering/quick-introduction-to-vue-js-super-mario-pixel-art-5ad01440663)
Pixel mario
I'm talking about this crap.
Chrome network screencap of marketing pixels
Marketing pixels
If you've read my other post, you'll understand more that marketers are profiting off selling your information (and how things should change so you should get paid for your information instead), but I digress. 
In a simple form, 1x1 <img> tags that are in the HTML of webpages send data to marketers. These tags are provided by marketers, who in turn of taking user behavior information, provide the website owner with $. 
The website owner also puts on their webpages a marketing script, along with some <div> tags to hold the ads themselves. When you visit the webpage, the marketing script loads, pulling information the marketer already has, and populates the <div> tags with ad content.
Of course, this is very simplified and does not apply to every party who interacts with marketers. Some parties only use the pixel, others just use the ads. There's a web of business here.
If we think what the hosts file can do, it can actually give us complete control over any ads. How? We can write in the hosts file that we want a particular host name to map to null. Null in a hosts file looks like this.
A sample hosts file
Writing entries in the hosts file
0.0.0.0 is the invalid, un-routable address. By using this for all the host names that load pixels, we can block marketers from tracking our user data, as well as prevent ads from loading on webpages.
Technically, you could also use 127.0.0.1 here in place of 0.0.0.0, but it's quicker to process 0.0.0.0 and it's easier to type as well!
Doesn't that mean we have to type out every single host in our hosts file? Yes and no. You can take the liberty upon yourself and get carpel tunnel (please don't), or - you can just get a curated list from the github repo. Copy the full list (raw list link here) and save it in your hosts file. 
A Powershell command prompt
Being cool and opening the hosts file up from Powershell
The hosts file is at C:\Windows\System32\drivers\etc\hosts. Save the entries in the file (be sure to run your text editor as an administrator in order to save the file!) and run this command in a cmd prompt or Powershell prompt to flush the DNS cache so your updates take effect right away. 
You should see happy errors in your web browser's console now.
Blocked pixels in Chrome's console tab
Google ad not loading
Sorry Google
Obviously, this only works on your local computer. We will explore in a future post how to block ads for your entire network (yes - this is possible).
It's important to improve your skills, but you can't neglect your health as a programmer. Here are four, very easy steps you can take to maintain your health at your desk job.

Protect your eyes You can read the full American Optometric Association paper, or you can simply wear eye protection. Bottom line, is UV light harms your eyes. That must be why I really enjoy looking at deep-blue Christmas lights...
I would recommend any pair of glasses while on your computer that have blue-light reflective coating, or a blue light filter. I personally have a pair of these, and I immediately noticed a difference at the end of the day - my eyes didn't feel sore or tired (that is what long exposure to UV light does to your eyes). This is also a good article on the subject.

You can also consider monitors that have built-in blue light filters, but they tend to be more on the expensive side of things.
Follow the 20-20-20 rule Every 20 minutes, look 20 feet away for 20 seconds; it's wha…

What gets me more excited than anything? Performance.

Its always exciting to me to perform at max efficiency, because why should you be performing any less? What's even better than efficiency than setting it and forgetting it? Nothing. Fact of the matter is while you may not be caring about efficiency, you should - because your business does. Lack of efficiency costs dollars and time.

You aren't off the hook even if you are doing programming as a hobby or are self-employed.



We are going to explore how to minify your .cshtml files in a .NET Core web application, and why you should care to do so.

Why you should careDo your reading;read this too.


Time is a limited resource, and we are tending to be more impatient nowadays, these people think so too. The bottom line is that if you want a chance for your web application to be successful, you can't skimp on quality and hope that you will be a success. Your applications need to deliver quality, and an "easy" way to conve…
This post isn't necessary advocating for dropping out of school to get your first programming job, but rather a list of things I wish I had a better understanding of before I started my first job as a programmer outside of school (college).

How you view your work We know you are working on homework all the time, but it is different in the real world. You can't approach working in a job the same way as you work on homework in school. At school, the assignments you do are against you; one on one. A duel.


In a real job, work isn't simply something to get done, it is means to an end. Other people are now counting on you to get your work done. You become a dependency to others, your team, and the organization as a whole. You become a necessary lynch pin in your job.

If this raises the stakes, good. That's how you need to begin thinking at a real job.
What you learned does not apply to workThis is the same qualm I have about early to mid-level education too.
Throw it all away…