a bunch of this code is borrowed from Qwery so NW is a drop-in replacement
515575
function (selector, _root) {
        var root = normalizeRoot(_root)
        if (!root || !selector) return []
        if (selector === window || isNode(selector)) {
          return !_root || (selector !== window && isNode(root) && nw.contains(root, container)) ? [selector] : []
        }
        if (selector && arrayLike(selector)) return flatten(selector)
        return nw.select(selector, root)
      }
444567
private Tuple2<List<KeyedStateHandle>, List<KeyedStateHandle>> reAssignSubKeyedStates(
			OperatorState operatorState,
			List<KeyGroupRange> keyGroupPartitions,
			int subTaskIndex,
			int newParallelism,
			int oldParallelism) {

		List<KeyedStateHandle> subManagedKeyedState;
		List<KeyedStateHandle> subRawKeyedState;

		if (newParallelism == oldParallelism) {
			if (operatorState.getState(subTaskIndex) != null) {
				subManagedKeyedState = operatorState.getState(subTaskIndex).getManagedKeyedState().asList();
				subRawKeyedState = operatorState.getState(subTaskIndex).getRawKeyedState().asList();
			} else {
				subManagedKeyedState = Collections.emptyList();
				subRawKeyedState = Collections.emptyList();
			}
		} else {
			subManagedKeyedState = getManagedKeyedStateHandles(operatorState, keyGroupPartitions.get(subTaskIndex));
			subRawKeyedState = getRawKeyedStateHandles(operatorState, keyGroupPartitions.get(subTaskIndex));
		}

		if (subManagedKeyedState.isEmpty() && subRawKeyedState.isEmpty()) {
			return new Tuple2<>(Collections.emptyList(), Collections.emptyList());
		} else {
			return new Tuple2<>(subManagedKeyedState, subRawKeyedState);
		}
	}
841160
def _get_same_codes(self):
        """"""
        same = {}
        url = '''http://www.nws.noaa.gov/nwr/data/SameCode.txt'''
        # pylint: disable=E1103
        raw = requests.get(url).content.decode('utf-8')  # py3 compatibility
        for row in raw.split('\n'):
            try:
                code, local, state = str(row).strip().split(',')
                location = {'code': code, 'local': local, 'state': state.strip()}
                # when I contacted the nws to add a missing same code
                # they added a space before the state in the samecodes file
                # stripping it out
                same[code] = location
            finally:
                pass
        cache = open(self._same_cache_file, 'wb')
        cPickle.dump(same, cache)
        cache.close()
        return same
393977
function replaceTildes(comp, loose) {
  return comp.trim().split(/\s+/).map(function(comp) {
    return replaceTilde(comp, loose);
  }).join(' ');
}
736148
function(fn) {
  var code = fn.toString();
  var match = code.match(/^(?:(?:function)?[\s]*\(([^)]*)\)|([^\=\(]+))/);
  var args = (match[1] || match[2]);
  if (typeof args === 'undefined') {
    return [];
  }
  return args.split(',').map(function(item) {
    return item.trim();
  }).filter(function(item) {
    return item;
  });
}
1044542
function prune(code) {
  var ast = esprima.parse(code);

  estraverse.replace(ast, {
    leave: function leave(node, parent) {
      var ret;

      if ('IfStatement' === node.type) {
        if ('BinaryExpression' !== node.test.type) return;

        if ('self' === node.test.left.argument.name) {
          node.alternate = null;
        } else if ('global' === node.test.left.argument.name) {
          ret = node.alternate;
        }

        return ret;
      }

      if (
          'BlockStatement' === node.type
        && 'FunctionExpression' === parent.type
      ) {
        return node.body[0].alternate.alternate;
      }
    }
  });

  return escodegen.generate(ast, {
    format: {
      indent: { style: '  ' },
      semicolons: false,
      compact: true
    }
  });
}
911804
function MarcSubfield(code, data) {
  if (!(this instanceof MarcSubfield)) {
    return new MarcSubfield(code, data);
  }

  if (code instanceof MarcSubfield) {
    // Copy the source subfield.
    var srcSubfield = code;
    this.code = srcSubfield.code;

    if (srcSubfield.data instanceof MarcControlField) {
      this.data = new MarcControlField(srcSubfield.data);
    } else if (srcSubfield.data instanceof MarcDataField) {
      this.data = new MarcDataField(srcSubfield.data);
    } else {
      this.data = srcSubfield.data;
    }
  } else {
    // Initialize subfield.
    this.code = code || '?';
    this.data = data || '';
  }
}
419765
function updateSourceCode(code, changes) {
  // Summary:
  //  This must be called before code is changed some places else rather than ast

  changes.sort((c1, c2) => c2.start - c1.start);
  // Remove same or overlapped changes
  const newChanges = _.reduce(
    changes,
    (cleanChanges, curr) => {
      const last = _.last(cleanChanges);

      if (!cleanChanges.length || last.start > curr.end) {
        cleanChanges.push(curr);
      } else if (last.start === last.end && last.end === curr.start && curr.start === curr.end) {
        // insert code at the same position, merge them
        last.replacement += curr.replacement;
      }
      return cleanChanges;
    },
    [],
  );

  const chars = code.split('');
  newChanges.forEach(c => {
    // Special case: after the change, two empty lines occurs, should delete one line
    if (
      c.replacement === '' &&
      (c.start === 0 || chars[c.start - 1] === '\n') &&
      chars[c.end] === '\n'
    ) {
      c.end += 1;
    }
    chars.splice(c.start, c.end - c.start, c.replacement);
  });
  return chars.join('');
}
518446
def _isomorphism_rewrite_to_NECtree(q_s, qgraph):
    
    qadj = qgraph.adj
    adjsets = lambda x: set(chain.from_iterable(qadj[x].values()))
    t = ([q_s], [])  # (NEC_set, children)
    visited = {q_s}
    vcur, vnext = [t], []
    while vcur:
        for (nec, children) in vcur:
            c = defaultdict(list)
            for u in nec:
                for sig, adjlist in qadj[u].items():
                    c[sig].extend(x for x, _, _ in adjlist if x not in visited)
            for sig, c_adjlist in c.items():
                visited.update(c_adjlist)
                # these are already grouped by label; now group by adjacents
                for key, grp in groupby(c_adjlist, key=adjsets):
                    grp = list(grp)
                    if len(grp) > 1:
                        children.append((list(grp), []))
                    else:
                        # NOTE: the paper says to look for mergeable things,
                        # but I don't know what else to merge by.
                        children.append((list(grp), []))
            vnext.extend(children)
        vcur, vnext = vnext, []
    return t
491448
def keysym_to_keycodes(self, keysym):
        """"""
        try:
            # Copy the map list, reversing the arguments
            return map(lambda x: (x[1], x[0]), self._keymap_syms[keysym])
        except KeyError:
            return []
285844
function replaceRequired(fns, brstars, replacer) {
    var keys = Object.keys(fns)
    if (!keys.length) return

    keys.forEach(function(name) {
      var source = fns[name]

      source = resolve.sync(source, {
        basedir: dirname
      })

      if (!source) return
      var index = brstars.indexOf(source)
      if (index === -1) return

      replacer([name], function(node) {
        if (!node.arguments.length) return
        var value = evaluate(node.arguments[0])
        if (!value) return

        value = require(source)(value)
        debug('replacing for: %s = %s', name, source)
        replaceCount += 1
        hijack(node, value)
      })
    })
  }
657286
def make_python_patterns(additional_keywords=[], additional_builtins=[]):
    ""
    kwlist = keyword.kwlist + additional_keywords
    builtinlist = [str(name) for name in dir(builtins)
                   if not name.startswith('_')] + additional_builtins
    repeated = set(kwlist) & set(builtinlist)
    for repeated_element in repeated:
        kwlist.remove(repeated_element)
    kw = r"\b" + any("keyword", kwlist) + r"\b"
    builtin = r"([^.'\"\\#]\b|^)" + any("builtin", builtinlist) + r"\b"
    comment = any("comment", [r"#[^\n]*"])
    instance = any("instance", [r"\bself\b",
                                r"\bcls\b",
                                (r"^\s*@([a-zA-Z_][a-zA-Z0-9_]*)"
                                     r"(\.[a-zA-Z_][a-zA-Z0-9_]*)*")])
    number_regex = [r"\b[+-]?[0-9]+[lLjJ]?\b",
                    r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b",
                    r"\b[+-]?0[oO][0-7]+[lL]?\b",
                    r"\b[+-]?0[bB][01]+[lL]?\b",
                    r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?[jJ]?\b"]
    if PY3:
        prefix = "r|u|R|U|f|F|fr|Fr|fR|FR|rf|rF|Rf|RF|b|B|br|Br|bR|BR|rb|rB|Rb|RB"
    else:
        prefix = "r|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR"
    sqstring =     r"(\b(%s))?'[^'\\\n]*(\\.[^'\\\n]*)*'?" % prefix
    dqstring =     r'(\b(%s))?"[^"\\\n]*(\\.[^"\\\n]*)*"?' % prefix
    uf_sqstring =  r"(\b(%s))?'[^'\\\n]*(\\.[^'\\\n]*)*(\\)$(?!')$" % prefix
    uf_dqstring =  r'(\b(%s))?"[^"\\\n]*(\\.[^"\\\n]*)*(\\)$(?!")$' % prefix
    sq3string =    r"(\b(%s))?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" % prefix
    dq3string =    r'(\b(%s))?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' % prefix
    uf_sq3string = r"(\b(%s))?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(\\)?(?!''')$" \
                   % prefix
    uf_dq3string = r'(\b(%s))?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(\\)?(?!""")$' \
                   % prefix
    # Needed to achieve correct highlighting in Python 3.6+
    # See issue 7324
    if PY36_OR_MORE:
        # Based on
        # https://github.com/python/cpython/blob/
        # 81950495ba2c36056e0ce48fd37d514816c26747/Lib/tokenize.py#L117
        # In order: Hexnumber, Binnumber, Octnumber, Decnumber,
        # Pointfloat + Exponent, Expfloat, Imagnumber
        number_regex = [
                r"\b[+-]?0[xX](?:_?[0-9A-Fa-f])+[lL]?\b",
                r"\b[+-]?0[bB](?:_?[01])+[lL]?\b",
                r"\b[+-]?0[oO](?:_?[0-7])+[lL]?\b",
                r"\b[+-]?(?:0(?:_?0)*|[1-9](?:_?[0-9])*)[lL]?\b",
                r"\b((\.[0-9](?:_?[0-9])*')|\.[0-9](?:_?[0-9])*)"
                "([eE][+-]?[0-9](?:_?[0-9])*)?[jJ]?\b",
                r"\b[0-9](?:_?[0-9])*([eE][+-]?[0-9](?:_?[0-9])*)?[jJ]?\b",
                r"\b[0-9](?:_?[0-9])*[jJ]\b"]
    number = any("number", number_regex)

    string = any("string", [sq3string, dq3string, sqstring, dqstring])
    ufstring1 = any("uf_sqstring", [uf_sqstring])
    ufstring2 = any("uf_dqstring", [uf_dqstring])
    ufstring3 = any("uf_sq3string", [uf_sq3string])
    ufstring4 = any("uf_dq3string", [uf_dq3string])
    return "|".join([instance, kw, builtin, comment,
                     ufstring1, ufstring2, ufstring3, ufstring4, string,
                     number, any("SYNC", [r"\n"])])
776059
function transformCode(transformFn, code, url) {
  let source;
  if (url != null) {
    source = url;
  } else {
    source = 'Inline Babel script';
    inlineScriptCount++;
    if (inlineScriptCount > 1) {
      source += ' (' + inlineScriptCount + ')';
    }
  }

  return transformFn(
    code,
    {
      filename: source,
      ...babelOpts
    }
  ).code;
}
1128248
def raw_input_replacement(self, prompt=''):
        """"""
        self.widget_proxy.wait_input(prompt)
        self.input_condition.acquire()
        while not self.widget_proxy.data_available():
            self.input_condition.wait()
        inp = self.widget_proxy.input_data
        self.input_condition.release()
        return inp
958838
@Override
    public void sawOpcode(int seen) {
        try {
            if ((seen == Const.ATHROW) && (stack.getStackDepth() > 0)) {
                OpcodeStack.Item item = stack.getStackItem(0);
                if ("Ljava/lang/CloneNotSupportedException;".equals(item.getSignature())) {
                    throwsCNFE = true;
                }
            }
        } finally {
            stack.sawOpcode(this, seen);
        }
    }
343715
private boolean substitute() {
		boolean madeChange = false;

		for (String key : backing.keySet()) {
			madeChange = madeChange || substitute(key);
		}

		return madeChange;
	}
359486
def replace(code, pattern, goal):
    """"""
    finder = similarfinder.RawSimilarFinder(code)
    matches = list(finder.get_matches(pattern))
    ast = patchedast.get_patched_ast(code)
    lines = codeanalyze.SourceLinesAdapter(code)
    template = similarfinder.CodeTemplate(goal)
    computer = _ChangeComputer(code, ast, lines, template, matches)
    result = computer.get_changed()
    if result is None:
        return code
    return result