question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide the variants only?

See original GitHub issue

Hi!

This repo is great but, what if we want to block only porn sites? or only gambling sites? ❓

All of the files have Unified hosts + Variant

I solved this by overengineering a NodeJS solution 😂 and then realized there’s a very simple way of doing it… 🤦‍♂️

Simple way:

diff --unchanged-group-format='' hosts porn > output_file

My NodeJS script: (downloads the hosts file then porn and then goes through all lines and displays the ones that are in the second file but not first.)

const fs = require("fs");
const wget = require("wget-improved");

try {
	let download = wget.download(
		"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
		"hosts",
		{}
	);
	let download2 = wget.download(
		"https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts",
		"porn",
		{}
	);

	const events = [download, download2];
	const promises = events.map((event) => {
		return new Promise((resolve) => {
			event.on("end", (paths) => {
				resolve(paths);
			});
		});
	});

	Promise.all(promises).then((result) => {
		// console.log("both finished", result);

		// read contents of the file
		const data = fs.readFileSync("hosts", "UTF-8");
		const data2 = fs.readFileSync("porn", "UTF-8");

		// split the contents by new line
		const lines = new Set(data.split(/\r?\n/));
		const lines2 = new Set(data2.split(/\r?\n/));

		let count = 0;

		// usint Sets avoids O(n^2)
		lines2.forEach((line2) => {
			if (!lines.has(line2)) {
				console.log(line2);
				count++;
			}
		});

		console.log("# Size diff: ", lines2.size - lines.size);
		console.log("# Diff count: ", count);
	});
} catch (err) {
	console.error(err);
}

Run it: node diff.js > output_file

P.S. Don’t forget to: npm i wget-improved

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dnmTXcommented, Oct 20, 2021

I know…old post and all that,but it’s still open so… Linux to the rescue(no need of such a complicated JavaScripts) 😉 : wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts -O porn_only.txt sed -i '0,/^# End yoyo/d; /^#/d; s/ #.*//g; /^$/d' porn_only.txt And Voila…you have yourself one healthy porn only list. Enjoy 👍

1reaction
TeleRocker22commented, Sep 25, 2022

I just want to throw my support for this in as well. This is a wonderful project, and having the categories only would be good for situations where blocking all the ads isn’t necessarily the goal. I worked in a small library before where this would be handy. This could be used in PiHole or pfBlockerNG as a quick way to help prevent adult content being viewed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Variants of the Virus - COVID-19 - CDC
Viruses constantly change through mutation and sometimes these mutations result in a new variant of the virus. Some variations allow the virus to...
Read more >
Tracking SARS-CoV-2 variants
Updates on SARS-CoV-2 classifications, the geographic distribution of VOCs, and summaries of their phenotypic characteristics (transmissibility, disease ...
Read more >
Omicron, Delta, Alpha, and More: What To Know About the ...
Omicron's subvariants are considered to be especially efficient spreaders of the disease, and the BQ strains appear to be better than other ...
Read more >
COVID Variants: What You Should Know
The new variants (originally called strains) raise questions: Are these coronaviruses more contagious? Will the vaccines still work?
Read more >
A Guide to the COVID-19 Variants: What You Need ... - Labcorp
Additionally, these mutations can allow the virus to evade protective antibodies induced by previous infection and/or vaccination and detection by testing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found