<commit_before>var redis      = require("redis"),
    client     = redis.createClient(),
    listname   = process.argv[2];
    itemsToAdd = process.argv.splice(3),
    validLists = ["watchlist", "emaillist", "slackloglist", "slackalertlist"];

client.on("error", function (err) {
	console.log("Error " + err);
});

// taken from http://stackoverflow.com/questions/784012/javascript-equivalent-of-phps-in-array on 20150518 @ 19:50 EST
function inArray (needle, haystack) {
	var length = haystack.length;
	for(var i = 0; i < length; i++) {
		if(haystack[i] == needle) return true;
	}
	return false;
};

function addToList (listname, rawArgs, verbose) {
	rawArgs.forEach(function (val, index, array) {
		// skip the first two element ['node', 'add-to-list']
		if (index >= 2)
			itemsToAdd.push (val);
	});

	client.get (listname, function (err, reply) {
		if (reply != null) {
			var hasChanged = false;
			list = JSON.parse(reply.toString());

			itemsToAdd.forEach (function (val, index, array) {
				if (!inArray (val, list)) {
					if (verbose) console.log ("pushing " + val + " to array");<commit_msg>add comment about common function in 2 files, update copy<commit_after>var redis      = require("redis"),
    client     = redis.createClient(),
    listname   = process.argv[2];
    itemsToAdd = process.argv.splice(3),
    validLists = ["watchlist", "emaillist", "slackloglist", "slackalertlist"];

client.on("error", function (err) {
	console.log("Error " + err);
});

// TODO: add/remove both use this same function, need to abstract out
// taken from http://stackoverflow.com/questions/784012/javascript-equivalent-of-phps-in-array on 20150518 @ 19:50 EST
function inArray (needle, haystack) {
	var length = haystack.length;
	for(var i = 0; i < length; i++) {
		if(haystack[i] == needle) return true;
	}
	return false;
};

function addToList (listname, rawArgs, verbose) {
	rawArgs.forEach(function (val, index, array) {
		// skip the first two element ['node', 'add-to-list']
		if (index >= 2)
			itemsToAdd.push (val);
	});

	client.get (listname, function (err, reply) {
		if (reply != null) {
			var hasChanged = false;
			list = JSON.parse(reply.toString());

			itemsToAdd.forEach (function (val, index, array) {
				if (!inArray (val, list)) {
					if (verbose) console.log ("pushing '" + val + "' to " + listname);
{'fraction_non_alphanumeric': 0.1609442060085837, 'fraction_numerical': 0.019313304721030045, 'mean_word_length': 3.806185567010309, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5223602', 'n_tokens_mistral': 864, 'n_tokens_neox': 780, 'n_words': 209}