text:
FROM alpine:3.8
RUN apk add --no-cache bash gettext
COPY entrypoint.bash /builder/entrypoint.bash
ENTRYPOINT ["/builder/entrypoint.bash"]

redpajama_set_name: RedPajamaGithub


text:
/* @flow */
export default function removeUnitPlugin(): Object {
  return ({ types }) => {
    function isZero(node) {
      return (
        (types.isInteger(node.value) && node.value.value === 0) ||
        (types.isFloat(node.value) &&
          node.value.integer === 0 &&
          node.value.fractional === 0)
      )
    }

    return {
      Dimension({ node, replaceNode }) {
        if (isZero(node)) {
          replaceNode(types.integer(0))
        }
      },
    }
  }
}


text:
var expect = require('chai').expect,
  sinon = require('sinon'),
  inherits = require('util').inherits,
  AdminRPC = require('../../../../lib/daemon/rpc/AdminRPC'),
  EventEmitter = require('events').EventEmitter

describe('AdminRPC', function () {

  it('should expose admin methods', function () {
    var rpc = new AdminRPC()
    rpc._config = {
      guvnor: {}
    }
    rpc._processFactory = {
      connect: sinon.stub()
    }
    rpc._guvnor = {
      kill: sinon.stub(),
      remoteHostConfig: sinon.stub(),
      addRemoteUser: sinon.stub(),
      removeRemoteUser: sinon.stub(),
      listRemoteUsers: sinon.stub(),
      rotateRemoteUserKeys: sinon.stub(),
      generateRemoteRpcCertificates: sinon.stub(),
      startProcessAsUser: sinon.stub(),
      dumpProcesses: sinon.stub(),
      restoreProcesses: sinon.stub()
    }
    rpc._dnode = sinon.stub()
    rpc._fileSystem = {
      getRunDir: sinon.stub()
    }
    rpc._fs = {
      existsSync: sinon.stub(),
      unlinkSync: sinon.stub(),
      chown: sinon.stub(),
      exists: sinon.stub()
    }
    rpc._logger = {
      info: sinon.stub(),
      warn: sinon.stub(),
      error: sinon.stub(),
      debug: sinon.stub()
    }

    var socket = new EventEmitter()
    var dnode = new EventEmitter()
    dnode.listen = sinon.stub()
    dnode.listen.returns(socket)
    rpc._dnode.returns(dnode)

    rpc.afterPropertiesSet()

    expect(rpc.kill).to.be.a('function')
    expect(rpc.remoteHostConfig).to.be.a('function')
    expect(rpc.addRemoteUser).to.be.a('function')
    expect(rpc.removeRemoteUser).to.be.a('function')
    expect(rpc.listRemoteUsers).to.be.a('function')
    expect(rpc.rotateRemoteUserKeys).to.be.a('function')
    expect(rpc.dumpProcesses).to.be.a('function')
    expect(rpc.restoreProcesses).to.be.a('function')
  })
})


text:
"""
The :mod:`sklearn.utils` module includes various utilities.
"""
from collections.abc import Sequence
from contextlib import contextmanager
from itertools import islice
import numbers
import platform
import struct
import timeit

import warnings
import numpy as np
from scipy.sparse import issparse

from .murmurhash import murmurhash3_32
from .class_weight import compute_class_weight, compute_sample_weight
from . import _joblib
from ..exceptions import DataConversionWarning
from .deprecation import deprecated
from .validation import (as_float_array,
                         assert_all_finite,
                         check_random_state, column_or_1d, check_array,
                         check_consistent_length, check_X_y, indexable,
                         check_symmetric, check_scalar)
from .. import get_config

# Do not deprecate parallel_backend and register_parallel_backend as they are
# needed to tune `scikit-learn` behavior and have different effect if called
# from the vendored version or or the site-package version. The other are
# utilities that are independent of scikit-learn so they are not part of
# scikit-learn public API.
parallel_backend = _joblib.parallel_backend
register_parallel_backend = _joblib.register_parallel_backend

# deprecate the joblib API in sklearn in favor of using directly joblib
msg = ("deprecated in version 0.20.1 to be removed in version 0.23. "
       "Please import this functionality directly from joblib, which can "
       "be installed with: pip install joblib.")
deprecate = deprecated(msg)

delayed = deprecate(_joblib.delayed)
cpu_count = deprecate(_joblib.cpu_count)
hash = deprecate(_joblib.hash)
effective_n_jobs = deprecate(_joblib.effective_n_jobs)

# for classes, deprecated will change the object in _joblib module so we need
# to subclass them.
@deprecate
class Memory(_joblib.Memory):
    pass

@deprecate
class Parallel(_joblib.Parallel):
    pass

__all__ = ["murmurhash3_32", "as_float_array",
           "assert_all_finite", "check_array",
           "check_random_state",
           "compute_class_weight", "compute_sample_weight",
           "column_or_1d", "safe_indexing",
           "check_consistent_length", "check_X_y", "check_scalar", 'indexable',
           "check_symmetric", "indices_to_mask", "deprecated",
           "cpu_count", "Parallel", "Memory", "delayed", "parallel_backend",
           "register_parallel_backend", "hash", "effective_n_jobs",
           "resample", "shuffle", "check_matplotlib_support"]

IS_PYPY = platform.python_implementation() == 'PyPy'
_IS_32BIT = 8 * struct.calcsize("P") == 32

class Bunch(dict):
    """Container object for datasets

    Dictionary-like object that exposes its keys as attributes.

    >>> b = Bunch(a=1, b=2)
    >>> b['b']
    2
    >>> b.b
    2
    >>> b.a = 3
    >>> b['a']
    3
    >>> b.c = 6
    >>> b['c']
    6

    """

    def __init__(self, **kwargs):
        super().__init__(kwargs)

    def __setattr__(self, key, value):
        self[key] = value

    def __dir__(self):
        return self.keys()

    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError:
            raise AttributeError(key)

    def __setstate__(self, state):
        # Bunch pickles generated with scikit-learn 0.16.* have an non
        # empty __dict__. This causes a surprising behaviour when
        # loading these pickles scikit-learn 0.17: reading bunch.key
        # uses __dict__ but assigning to bunch.key use __setattr__ and
        # only changes bunch['key']. More details can be found at:
        # https://github.com/scikit-learn/scikit-learn/issues/6196.
        # Overriding __setstate__ to be a noop has the effect of
        # ignoring the pickled __dict__
        pass

def safe_mask(X, mask):
    """Return a mask which is safe to use on X.

    Parameters
    ----------
    X : {array-like, sparse matrix}
        Data on which to apply mask.

    mask : array
        Mask to be used on X.

    Returns
    -------
        mask
    """
    mask = np.asarray(mask)
    if np.issubdtype(mask.dtype, np.signedinteger):
        return mask

    if hasattr(X, "toarray"):
        ind = np.arange(mask.shape[0])
        mask = ind[mask]
    return mask

def axis0_safe_slice(X, mask, len_mask):
    """
    This mask is safer than safe_mask since it returns an
    empty array, when a sparse matrix is sliced with a boolean mask
    with all False, instead of raising an unhelpful error in older
    versions of SciPy.

    See: https://github.com/scipy/scipy/issues/5361

    Also note that we can avoid doing the dot product by checking if
    the len_mask is not zero in _huber_loss_and_gradient but this
    is not going to be the bottleneck, since the number of outliers
    and non_outliers are typically non-zero and it makes the code
    tougher to follow.

    Parameters
    ----------
    X : {array-like, sparse matrix}
        Data on which to apply mask.

    mask : array
        Mask to be used on X.

    len_mask : int
        The length of the mask.

    Returns
    -------
        mask
    """
    if len_mask != 0:
        return X[safe_mask(X, mask), :]
    return np.zeros(shape=(0, X.shape[1]))

def safe_indexing(X, indices, axis=0):
    """Return rows, items or columns of X using indices.

    Parameters
    ----------
    X : array-like, sparse-matrix, list, pandas.DataFrame, pandas.Series
        Data from which to sample rows, items or columns.
    indices : array-like
        - When ``axis=0``, indices need to be an array of integer.
        - When ``axis=1``, indices can be one of:
            - scalar: output is 1D, unless `X` is sparse.
              Supported data types for scalars:
                - integer: supported for arrays, sparse matrices and
                  dataframes.
                - string (key-based): only supported for dataframes.
            - container: lists, slices, boolean masks: output is 2D.
              Supported data types for containers:
                - integer or boolean (positional): supported for
                  arrays, sparse matrices and dataframes
                - string (key-based): only supported for dataframes. No keys
                  other than strings are allowed.
    axis : int, default=0
        The axis along which `X` will be subsampled. ``axis=0`` will select
        rows while ``axis=1`` will select columns.

    Returns
    -------
    subset
        Subset of X on axis 0 or 1.

    Notes
    -----
    CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
    not supported.
    """
    if axis == 0:
        return _safe_indexing_row(X, indices)
    elif axis == 1:
        return _safe_indexing_column(X, indices)
    else:
        raise ValueError(
            "'axis' should be either 0 (to index rows) or 1 (to index "
            " column). Got {} instead.".format(axis)
        )

def _safe_indexing_row(X, indices):
    """Return items or rows from X using indices.

    Allows simple indexing of lists or arrays.

    Parameters
    ----------
    X : array-like, sparse-matrix, list, pandas.DataFrame, pandas.Series
        Data from which to sample rows or items.
    indices : array-like of int
        Indices according to which X will be subsampled.

    Returns
    -------
    subset
        Subset of X on first axis.

    Notes
    -----
    CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
    not supported.
    """
    if hasattr(X, "iloc"):
        # Work-around for indexing with read-only indices in pandas
        indices = np.asarray(indices)
        indices = indices if indices.flags.writeable else indices.copy()
        # Pandas Dataframes and Series
        try:
            return X.iloc[indices]
        except ValueError:
            # Cython typed memoryviews internally used in pandas do not support
            # readonly buffers.
            warnings.warn("Copying input dataframe for slicing.",
                          DataConversionWarning)
            return X.copy().iloc[indices]
    elif hasattr(X, "shape"):
        if hasattr(X, 'take') and (hasattr(indices, 'dtype') and
                                   indices.dtype.kind == 'i'):
            # This is often substantially faster than X[indices]
            return X.take(indices, axis=0)
        else:
            return X[indices]
    else:
        return [X[idx] for idx in indices]

def _check_key_type(key, superclass):
    """Check that scalar, list or slice is of a certain type.

    This is only used in _safe_indexing_column and _get_column_indices to check
    if the ``key`` (column specification) is fully integer or fully
    string-like.

    Parameters
    ----------
    key : scalar, list, slice, array-like
        The column specification to check.
    superclass : int or str
        The type for which to check the `key`.
    """
    if isinstance(key, superclass):
        return True
    if isinstance(key, slice):
        return (isinstance(key.start, (superclass, type(None))) and
                isinstance(key.stop, (superclass, type(None))))
    if isinstance(key, list):
        return all(isinstance(x, superclass) for x in key)
    if hasattr(key, 'dtype'):
        if superclass is int:
            return key.dtype.kind == 'i'
        elif superclass is bool:
            return key.dtype.kind == 'b'
        else:
            # superclass = str
            return key.dtype.kind in ('O', 'U', 'S')
    return False

def _safe_indexing_column(X, key):
    """Get feature column(s) from input data X.

    Supported input types (X): numpy arrays, sparse arrays and DataFrames.

    Supported key types (key):
    - scalar: output is 1D;
    - lists, slices, boolean masks: output is 2D.

    Supported key data types:
    - integer or boolean mask (positional):
        - supported for arrays, sparse matrices and dataframes.
    - string (key-based):
        - only supported for dataframes;
        - So no keys other than strings are allowed (while in principle you
          can use any hashable object as key).
    """
    # check that X is a 2D structure
    if X.ndim != 2:
        raise ValueError(
            "'X' should be a 2D NumPy array, 2D sparse matrix or pandas "
            "dataframe when indexing the columns (i.e. 'axis=1'). "
            "Got {} instead with {} dimension(s).".format(type(X), X.ndim)
        )
    # check whether we have string column names or integers
    if _check_key_type(key, int):
        column_names = False
    elif _check_key_type(key, str):
        column_names = True
    elif hasattr(key, 'dtype') and np.issubdtype(key.dtype, np.bool_):
        # boolean mask
        column_names = False
        if hasattr(X, 'loc'):
            # pandas boolean masks don't work with iloc, so take loc path
            column_names = True
    else:
        raise ValueError("No valid specification of the columns. Only a "
                         "scalar, list or slice of all integers or all "
                         "strings, or boolean mask is allowed")

    if column_names:
        if hasattr(X, 'loc'):
            # pandas dataframes
            return X.loc[:, key]
        else:
            raise ValueError("Specifying the columns using strings is only "
                             "supported for pandas DataFrames")
    else:
        if hasattr(X, 'iloc'):
            # pandas dataframes
            return X.iloc[:, key]
        else:
            # numpy arrays, sparse arrays
            return X[:, key]

def _get_column_indices(X, key):
    """Get feature column indices for input data X and key.

    For accepted values of `key`, see the docstring of
    :func:`_safe_indexing_column`.
    """
    n_columns = X.shape[1]

    if (_check_key_type(key, int)
            or hasattr(key, 'dtype') and np.issubdtype(key.dtype, np.bool_)):
        # Convert key into positive indexes
        try:
            idx = np.arange(n_columns)[key]
        except IndexError as e:
            raise ValueError(
                'all features must be in [0, %d]' % (n_columns - 1)
            ) from e
        return np.atleast_1d(idx).tolist()
    elif _check_key_type(key, str):
        try:
            all_columns = list(X.columns)
        except AttributeError:
            raise ValueError("Specifying the columns using strings is only "
                             "supported for pandas DataFrames")
        if isinstance(key, str):
            columns = [key]
        elif isinstance(key, slice):
            start, stop = key.start, key.stop
            if start is not None:
                start = all_columns.index(start)
            if stop is not None:
                # pandas indexing with strings is endpoint included
                stop = all_columns.index(stop) + 1
            else:
                stop = n_columns + 1
            return list(range(n_columns)[slice(start, stop)])
        else:
            columns = list(key)

        try:
            column_indices = [all_columns.index(col) for col in columns]
        except ValueError as e:
            if 'not in list' in str(e):
                raise ValueError(
                    "A given column is not a column of the dataframe"
                ) from e
            raise

        return column_indices
    else:
        raise ValueError("No valid specification of the columns. Only a "
                         "scalar, list or slice of all integers or all "
                         "strings, or boolean mask is allowed")

def resample(*arrays, **options):
    """Resample arrays or sparse matrices in a consistent way

    The default strategy implements one step of the bootstrapping
    procedure.

    Parameters
    ----------
    *arrays : sequence of indexable data-structures
        Indexable data-structures can be arrays, lists, dataframes or scipy
        sparse matrices with consistent first dimension.

    Other Parameters
    ----------------
    replace : boolean, True by default
        Implements resampling with replacement. If False, this will implement
        (sliced) random permutations.

    n_samples : int, None by default
        Number of samples to generate. If left to None this is
        automatically set to the first dimension of the arrays.
        If replace is False it should not be larger than the length of
        arrays.

    random_state : int, RandomState instance or None, optional (default=None)
        The seed of the pseudo random number generator to use when shuffling
        the data.  If int, random_state is the seed used by the random number
        generator; If RandomState instance, random_state is the random number
        generator; If None, the random number generator is the RandomState
        instance used by `np.random`.

    stratify : array-like or None (default=None)
        If not None, data is split in a stratified fashion, using this as
        the class labels.

    Returns
    -------
    resampled_arrays : sequence of indexable data-structures
        Sequence of resampled copies of the collections. The original arrays
        are not impacted.

    Examples
    --------
    It is possible to mix sparse and dense arrays in the same run::

      >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])
      >>> y = np.array([0, 1, 2])

      >>> from scipy.sparse import coo_matrix
      >>> X_sparse = coo_matrix(X)

      >>> from sklearn.utils import resample
      >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)
      >>> X
      array([[1., 0.],
             [2., 1.],
             [1., 0.]])

      >>> X_sparse
      <3x2 sparse matrix of type '<... 'numpy.float64'>'
          with 4 stored elements in Compressed Sparse Row format>

      >>> X_sparse.toarray()
      array([[1., 0.],
             [2., 1.],
             [1., 0.]])

      >>> y
      array([0, 1, 0])

      >>> resample(y, n_samples=2, random_state=0)
      array([0, 1])

    Example using stratification::

      >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]
      >>> resample(y, n_samples=5, replace=False, stratify=y,
      ...          random_state=0)
      [1, 1, 1, 0, 1]

    See also
    --------
    :func:`sklearn.utils.shuffle`
    """

    random_state = check_random_state(options.pop('random_state', None))
    replace = options.pop('replace', True)
    max_n_samples = options.pop('n_samples', None)
    stratify = options.pop('stratify', None)
    if options:
        raise ValueError("Unexpected kw arguments: %r" % options.keys())

    if len(arrays) == 0:
        return None

    first = arrays[0]
    n_samples = first.shape[0] if hasattr(first, 'shape') else len(first)

    if max_n_samples is None:
        max_n_samples = n_samples
    elif (max_n_samples > n_samples) and (not replace):
        raise ValueError("Cannot sample %d out of arrays with dim %d "
                         "when replace is False" % (max_n_samples,
                                                    n_samples))

    check_consistent_length(*arrays)

    if stratify is None:
        if replace:
            indices = random_state.randint(0, n_samples, size=(max_n_samples,))
        else:
            indices = np.arange(n_samples)
            random_state.shuffle(indices)
            indices = indices[:max_n_samples]
    else:
        # Code adapted from StratifiedShuffleSplit()
        y = check_array(stratify, ensure_2d=False, dtype=None)
        if y.ndim == 2:
            # for multi-label y, map each distinct row to a string repr
            # using join because str(row) uses an ellipsis if len(row) > 1000
            y = np.array([' '.join(row.astype('str')) for row in y])

        classes, y_indices = np.unique(y, return_inverse=True)
        n_classes = classes.shape[0]

        class_counts = np.bincount(y_indices)

        # Find the sorted list of instances for each class:
        # (np.unique above performs a sort, so code is O(n logn) already)
        class_indices = np.split(np.argsort(y_indices, kind='mergesort'),
                                 np.cumsum(class_counts)[:-1])

        n_i = _approximate_mode(class_counts, max_n_samples, random_state)

        indices = []

        for i in range(n_classes):
            indices_i = random_state.choice(class_indices[i], n_i[i],
                                            replace=replace)
            indices.extend(indices_i)

        indices = random_state.permutation(indices)

    # convert sparse matrices to CSR for row-based indexing
    arrays = [a.tocsr() if issparse(a) else a for a in arrays]
    resampled_arrays = [safe_indexing(a, indices) for a in arrays]
    if len(resampled_arrays) == 1:
        # syntactic sugar for the unit argument case
        return resampled_arrays[0]
    else:
        return resampled_arrays

def shuffle(*arrays, **options):
    """Shuffle arrays or sparse matrices in a consistent way

    This is a convenience alias to ``resample(*arrays, replace=False)`` to do
    random permutations of the collections.

    Parameters
    ----------
    *arrays : sequence of indexable data-structures
        Indexable data-structures can be arrays, lists, dataframes or scipy
        sparse matrices with consistent first dimension.

    Other Parameters
    ----------------
    random_state : int, RandomState instance or None, optional (default=None)
        The seed of the pseudo random number generator to use when shuffling
        the data.  If int, random_state is the seed used by the random number
        generator; If RandomState instance, random_state is the random number
        generator; If None, the random number generator is the RandomState
        instance used by `np.random`.

    n_samples : int, None by default
        Number of samples to generate. If left to None this is
        automatically set to the first dimension of the arrays.

    Returns
    -------
    shuffled_arrays : sequence of indexable data-structures
        Sequence of shuffled copies of the collections. The original arrays
        are not impacted.

    Examples
    --------
    It is possible to mix sparse and dense arrays in the same run::

      >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])
      >>> y = np.array([0, 1, 2])

      >>> from scipy.sparse import coo_matrix
      >>> X_sparse = coo_matrix(X)

      >>> from sklearn.utils import shuffle
      >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)
      >>> X
      array([[0., 0.],
             [2., 1.],
             [1., 0.]])

      >>> X_sparse
      <3x2 sparse matrix of type '<... 'numpy.float64'>'
          with 3 stored elements in Compressed Sparse Row format>

      >>> X_sparse.toarray()
      array([[0., 0.],
             [2., 1.],
             [1., 0.]])

      >>> y
      array([2, 1, 0])

      >>> shuffle(y, n_samples=2, random_state=0)
      array([0, 1])

    See also
    --------
    :func:`sklearn.utils.resample`
    """
    options['replace'] = False
    return resample(*arrays, **options)

def safe_sqr(X, copy=True):
    """Element wise squaring of array-likes and sparse matrices.

    Parameters
    ----------
    X : array like, matrix, sparse matrix

    copy : boolean, optional, default True
        Whether to create a copy of X and operate on it or to perform
        inplace computation (default behaviour).

    Returns
    -------
    X ** 2 : element wise square
    """
    X = check_array(X, accept_sparse=['csr', 'csc', 'coo'], ensure_2d=False)
    if issparse(X):
        if copy:
            X = X.copy()
        X.data **= 2
    else:
        if copy:
            X = X ** 2
        else:
            X **= 2
    return X

def _chunk_generator(gen, chunksize):
    """Chunk generator, ``gen`` into lists of length ``chunksize``. The last
    chunk may have a length less than ``chunksize``."""
    while True:
        chunk = list(islice(gen, chunksize))
        if chunk:
            yield chunk
        else:
            return

def gen_batches(n, batch_size, min_batch_size=0):
    """Generator to create slices containing batch_size elements, from 0 to n.

    The last slice may contain less than batch_size elements, when batch_size
    does not divide n.

    Parameters
    ----------
    n : int
    batch_size : int
        Number of element in each batch
    min_batch_size : int, default=0
        Minimum batch size to produce.

    Yields
    ------
    slice of batch_size elements

    Examples
    --------
    >>> from sklearn.utils import gen_batches
    >>> list(gen_batches(7, 3))
    [slice(0, 3, None), slice(3, 6, None), slice(6, 7, None)]
    >>> list(gen_batches(6, 3))
    [slice(0, 3, None), slice(3, 6, None)]
    >>> list(gen_batches(2, 3))
    [slice(0, 2, None)]
    >>> list(gen_batches(7, 3, min_batch_size=0))
    [slice(0, 3, None), slice(3, 6, None), slice(6, 7, None)]
    >>> list(gen_batches(7, 3, min_batch_size=2))
    [slice(0, 3, None), slice(3, 7, None)]
    """
    start = 0
    for _ in range(int(n // batch_size)):
        end = start + batch_size
        if end + min_batch_size > n:
            continue
        yield slice(start, end)
        start = end
    if start < n:
        yield slice(start, n)

def gen_even_slices(n, n_packs, n_samples=None):
    """Generator to create n_packs slices going up to n.

    Parameters
    ----------
    n : int
    n_packs : int
        Number of slices to generate.
    n_samples : int or None (default = None)
        Number of samples. Pass n_samples when the slices are to be used for
        sparse matrix indexing; slicing off-the-end raises an exception, while
        it works for NumPy arrays.

    Yields
    ------
    slice

    Examples
    --------
    >>> from sklearn.utils import gen_even_slices
    >>> list(gen_even_slices(10, 1))
    [slice(0, 10, None)]
    >>> list(gen_even_slices(10, 10))
    [slice(0, 1, None), slice(1, 2, None), ..., slice(9, 10, None)]
    >>> list(gen_even_slices(10, 5))
    [slice(0, 2, None), slice(2, 4, None), ..., slice(8, 10, None)]
    >>> list(gen_even_slices(10, 3))
    [slice(0, 4, None), slice(4, 7, None), slice(7, 10, None)]
    """
    start = 0
    if n_packs < 1:
        raise ValueError("gen_even_slices got n_packs=%s, must be >=1"
                         % n_packs)
    for pack_num in range(n_packs):
        this_n = n // n_packs
        if pack_num < n % n_packs:
            this_n += 1
        if this_n > 0:
            end = start + this_n
            if n_samples is not None:
                end = min(n_samples, end)
            yield slice(start, end, None)
            start = end

def tosequence(x):
    """Cast iterable x to a Sequence, avoiding a copy if possible.

    Parameters
    ----------
    x : iterable
    """
    if isinstance(x, np.ndarray):
        return np.asarray(x)
    elif isinstance(x, Sequence):
        return x
    else:
        return list(x)

def indices_to_mask(indices, mask_length):
    """Convert list of indices to boolean mask.

    Parameters
    ----------
    indices : list-like
        List of integers treated as indices.
    mask_length : int
        Length of boolean mask to be generated.
        This parameter must be greater than max(indices)

    Returns
    -------
    mask : 1d boolean nd-array
        Boolean array that is True where indices are present, else False.

    Examples
    --------
    >>> from sklearn.utils import indices_to_mask
    >>> indices = [1, 2 , 3, 4]
    >>> indices_to_mask(indices, 5)
    array([False,  True,  True,  True,  True])
    """
    if mask_length <= np.max(indices):
        raise ValueError("mask_length must be greater than max(indices)")

    mask = np.zeros(mask_length, dtype=np.bool)
    mask[indices] = True

    return mask

def _message_with_time(source, message, time):
    """Create one line message for logging purposes

    Parameters
    ----------
    source : str
        String indicating the source or the reference of the message

    message : str
        Short message

    time : int
        Time in seconds
    """
    start_message = "[%s] " % source

    # adapted from joblib.logger.short_format_time without the Windows -.1s
    # adjustment
    if time > 60:
        time_str = "%4.1fmin" % (time / 60)
    else:
        time_str = " %5.1fs" % time
    end_message = " %s, total=%s" % (message, time_str)
    dots_len = (70 - len(start_message) - len(end_message))
    return "%s%s%s" % (start_message, dots_len * '.', end_message)

@contextmanager
def _print_elapsed_time(source, message=None):
    """Log elapsed time to stdout when the context is exited

    Parameters
    ----------
    source : str
        String indicating the source or the reference of the message

    message : str or None
        Short message. If None, nothing will be printed

    Returns
    -------
    context_manager
        Prints elapsed time upon exit if verbose
    """
    if message is None:
        yield
    else:
        start = timeit.default_timer()
        yield
        print(
            _message_with_time(source, message,
                               timeit.default_timer() - start))

def get_chunk_n_rows(row_bytes, max_n_rows=None,
                     working_memory=None):
    """Calculates how many rows can be processed within working_memory

    Parameters
    ----------
    row_bytes : int
        The expected number of bytes of memory that will be consumed
        during the processing of each row.
    max_n_rows : int, optional
        The maximum return value.
    working_memory : int or float, optional
        The number of rows to fit inside this number of MiB will be returned.
        When None (default), the value of
        ``sklearn.get_config()['working_memory']`` is used.

    Returns
    -------
    int or the value of n_samples

    Warns
    -----
    Issues a UserWarning if ``row_bytes`` exceeds ``working_memory`` MiB.
    """

    if working_memory is None:
        working_memory = get_config()['working_memory']

    chunk_n_rows = int(working_memory * (2 ** 20) // row_bytes)
    if max_n_rows is not None:
        chunk_n_rows = min(chunk_n_rows, max_n_rows)
    if chunk_n_rows < 1:
        warnings.warn('Could not adhere to working_memory config. '
                      'Currently %.0fMiB, %.0fMiB required.' %
                      (working_memory, np.ceil(row_bytes * 2 ** -20)))
        chunk_n_rows = 1
    return chunk_n_rows

def is_scalar_nan(x):
    """Tests if x is NaN

    This function is meant to overcome the issue that np.isnan does not allow
    non-numerical types as input, and that np.nan is not np.float('nan').

    Parameters
    ----------
    x : any type

    Returns
    -------
    boolean

    Examples
    --------
    >>> is_scalar_nan(np.nan)
    True
    >>> is_scalar_nan(float("nan"))
    True
    >>> is_scalar_nan(None)
    False
    >>> is_scalar_nan("")
    False
    >>> is_scalar_nan([np.nan])
    False
    """
    # convert from numpy.bool_ to python bool to ensure that testing
    # is_scalar_nan(x) is True does not fail.
    return bool(isinstance(x, numbers.Real) and np.isnan(x))

def _approximate_mode(class_counts, n_draws, rng):
    """Computes approximate mode of multivariate hypergeometric.

    This is an approximation to the mode of the multivariate
    hypergeometric given by class_counts and n_draws.
    It shouldn't be off by more than one.

    It is the mostly likely outcome of drawing n_draws many
    samples from the population given by class_counts.

    Parameters
    ----------
    class_counts : ndarray of int
        Population per class.
    n_draws : int
        Number of draws (samples to draw) from the overall population.
    rng : random state
        Used to break ties.

    Returns
    -------
    sampled_classes : ndarray of int
        Number of samples drawn from each class.
        np.sum(sampled_classes) == n_draws

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.utils import _approximate_mode
    >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)
    array([2, 1])
    >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)
    array([3, 1])
    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
    ...                   n_draws=2, rng=0)
    array([0, 1, 1, 0])
    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
    ...                   n_draws=2, rng=42)
    array([1, 1, 0, 0])
    """
    rng = check_random_state(rng)
    # this computes a bad approximation to the mode of the
    # multivariate hypergeometric given by class_counts and n_draws
    continuous = n_draws * class_counts / class_counts.sum()
    # floored means we don't overshoot n_samples, but probably undershoot
    floored = np.floor(continuous)
    # we add samples according to how much "left over" probability
    # they had, until we arrive at n_samples
    need_to_add = int(n_draws - floored.sum())
    if need_to_add > 0:
        remainder = continuous - floored
        values = np.sort(np.unique(remainder))[::-1]
        # add according to remainder, but break ties
        # randomly to avoid biases
        for value in values:
            inds, = np.where(remainder == value)
            # if we need_to_add less than what's in inds
            # we draw randomly from them.
            # if we need to add more, we add them all and
            # go to the next value
            add_now = min(len(inds), need_to_add)
            inds = rng.choice(inds, size=add_now, replace=False)
            floored[inds] += 1
            need_to_add -= add_now
            if need_to_add == 0:
                break
    return floored.astype(np.int)

def check_matplotlib_support(caller_name):
    """Raise ImportError with detailed error message if mpl is not installed.

    Plot utilities like :func:`plot_partial_dependence` should lazily import
    matplotlib and call this helper before any computation.

    Parameters
    ----------
    caller_name : str
        The name of the caller that requires matplotlib.
    """
    try:
        import matplotlib  # noqa
    except ImportError as e:
        raise ImportError(
            "{} requires matplotlib. You can install matplotlib with "
            "`pip install matplotlib`".format(caller_name)
        ) from e

def check_pandas_support(caller_name):
    """Raise ImportError with detailed error message if pandsa is not
    installed.

    Plot utilities like :func:`fetch_openml` should lazily import
    pandas and call this helper before any computation.

    Parameters
    ----------
    caller_name : str
        The name of the caller that requires pandas.
    """
    try:
        import pandas  # noqa
        return pandas
    except ImportError as e:
        raise ImportError(
            "{} requires pandas.".format(caller_name)
        ) from e


text:
package io.katharsis.meta;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.katharsis.core.internal.utils.MultivaluedMap;
import io.katharsis.core.internal.utils.PreconditionUtil;
import io.katharsis.meta.model.MetaArrayType;
import io.katharsis.meta.model.MetaElement;
import io.katharsis.meta.model.MetaEnumType;
import io.katharsis.meta.model.MetaListType;
import io.katharsis.meta.model.MetaLiteral;
import io.katharsis.meta.model.MetaMapType;
import io.katharsis.meta.model.MetaPrimitiveType;
import io.katharsis.meta.model.MetaSetType;
import io.katharsis.meta.model.MetaType;
import io.katharsis.meta.provider.MetaProvider;
import io.katharsis.meta.provider.MetaProviderContext;

public class MetaLookup {

	private static final Logger LOGGER = LoggerFactory.getLogger(MetaLookup.class);

	private static final String BASE_ID_PREFIX = "base.";

	private MultivaluedMap<Type, MetaElement> typeElementsMap = new MultivaluedMap<>();

	private ConcurrentHashMap<String, MetaElement> idElementMap = new ConcurrentHashMap<>();

	private Set<Class<?>> primitiveTypes = Collections.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>());

	private List<MetaProvider> providers = new CopyOnWriteArrayList<>();

	private LinkedList<MetaElement> initializationQueue = new LinkedList<>();

	private boolean adding = false;

	private MetaProviderContext context;

	private Map<String, String> packageIdMapping = new HashMap<>();

	private boolean discovered;

	public MetaLookup() {
		registerPrimitiveType(String.class);
		registerPrimitiveType(Number.class);
		registerPrimitiveType(Boolean.class);
		registerPrimitiveType(UUID.class);
		registerPrimitiveType(Date.class);
		registerPrimitiveType(Timestamp.class);
		registerPrimitiveType(byte[].class);
		registerPrimitiveType(boolean[].class);
		registerPrimitiveType(int[].class);
		registerPrimitiveType(short[].class);
		registerPrimitiveType(long[].class);
		registerPrimitiveType(double[].class);
		registerPrimitiveType(float[].class);

		context = new MetaProviderContext() {

			@Override
			public void add(MetaElement element) {
				MetaLookup.this.add(element);
			}

			@Override
			public void addAll(Collection<? extends MetaElement> elements) {
				MetaLookup.this.addAll(elements);
			}

			@Override
			public MetaLookup getLookup() {
				return MetaLookup.this;
			}
		};

		putIdMapping("io.katharsis.jpa.meta", "io.katharsis.jpa");
		putIdMapping("io.katharsis.meta.model", "io.katharsis.meta");
		putIdMapping("io.katharsis.meta.model.resource", "io.katharsis.meta.resource");
	}

	public Map<String, MetaElement> getMetaById() {
		return Collections.unmodifiableMap(idElementMap);
	}

	public void registerPrimitiveType(Class<?> clazz) {
		primitiveTypes.add(clazz);
	}

	public void addProvider(MetaProvider provider) {
		if (!providers.contains(provider)) {
			providers.add(provider);
			for (MetaProvider dependency : provider.getDependencies()) {
				addProvider(dependency);
			}
		}
	}

	public MetaElement getMeta(Type type) {
		return getMeta(type, MetaElement.class);
	}

	public <T extends MetaElement> T getMeta(Type type, Class<T> metaClass) {
		return (T) getMetaInternal(type, metaClass, false);
	}

	public <T extends MetaElement> T getMeta(Type type, Class<T> metaClass, boolean nullable) {
		return (T) getMetaInternal(type, metaClass, nullable);
	}

	public MetaArrayType getArrayMeta(Type type, Class<? extends MetaElement> elementMetaClass) {
		return (MetaArrayType) getMetaInternal(type, elementMetaClass, false);
	}

	private MetaElement getMetaInternal(Type type, Class<? extends MetaElement> elementMetaClass, boolean nullable) {
		PreconditionUtil.assertNotNull("type must not be null", type);

		checkInitialized();

		MetaElement meta = getUniqueElementByType(type, elementMetaClass);
		if (meta == null) {
			synchronized (this) {
				meta = getUniqueElementByType(type, elementMetaClass);
				if (meta == null) {

					boolean wasInitializing = adding;
					if (!wasInitializing) {
						adding = true;
					}

					meta = allocateMeta(type, elementMetaClass, nullable);
					if (meta != null) {
						add(meta);
					}

					if (!wasInitializing) {
						initialize();
					}
				}
			}
		}
		return meta;
	}

	private MetaElement getUniqueElementByType(Type type, Class<? extends MetaElement> elementMetaClass) {
		if (!typeElementsMap.containsKey(type)) {
			return null;
		}
		List<MetaElement> elements = typeElementsMap.getList(type);
		MetaElement result = null;
		for (MetaElement element : elements) {
			MetaElement meta = element;
			if (meta instanceof MetaType) {
				meta = ((MetaType) meta).getElementType();
			}

			if (elementMetaClass.isInstance(meta)) {
				if (result != null) {
					throw new IllegalStateException(
							"multiple elements found of type " + elementMetaClass + ": " + result + " vs " + element);
				}
				result = element;
			}
		}
		return result;
	}

	private MetaElement allocateMeta(Type type, Class<? extends MetaElement> metaClass, boolean nullable) {
		LOGGER.debug("allocate {}", type);

		if (type instanceof Class) {
			MetaElement meta = allocateMetaFromClass(type, metaClass);
			if (meta != null) {
				return meta;
			}
		}

		if (type instanceof ParameterizedType) {
			ParameterizedType paramType = (ParameterizedType) type;
			return allocateMetaFromParamerizedType(paramType, metaClass);
		}

		MetaElement meta = allocateMetaFromFactory(type, metaClass);
		if (meta != null) {
			return meta;
		}

		if (nullable) {
			return null;
		}
		throw new UnsupportedOperationException("unknown type " + type);
	}

	private MetaElement allocateMetaFromClass(Type type, Class<? extends MetaElement> metaClass) {
		Class<?> clazz = (Class<?>) type;
		if (clazz.isEnum()) {
			MetaEnumType enumType = new MetaEnumType();
			enumType.setImplementationType(type);
			enumType.setName(clazz.getSimpleName());
			for (Object literalObj : clazz.getEnumConstants()) {
				MetaLiteral literal = new MetaLiteral();
				literal.setName(literalObj.toString());
				literal.setParent(enumType);
			}
			return enumType;
		}
		if (isPrimitiveType(clazz)) {
			// FIXME should long + Long really be merged???
			String id = BASE_ID_PREFIX + clazz.getSimpleName().toLowerCase();

			MetaPrimitiveType primitiveType = (MetaPrimitiveType) idElementMap.get(id);
			if (primitiveType == null) {
				primitiveType = new MetaPrimitiveType();
				primitiveType.setImplementationType(type);
				primitiveType.setName(clazz.getSimpleName().toLowerCase());
				primitiveType.setId(id);
			}
			return primitiveType;
		}
		else if (clazz.isArray()) {
			Class<?> elementClass = ((Class<?>) type).getComponentType();

			MetaType elementType = getMeta(elementClass, metaClass).asType();
			MetaArrayType arrayType = new MetaArrayType();
			arrayType.setName(elementType.getName() + "[]");
			arrayType.setImplementationType(type);
			arrayType.setElementType(elementType);
			return arrayType;
		}
		return null;
	}

	private <T extends MetaElement> T allocateMetaFromFactory(Type type, Class<? extends MetaElement> metaClass) {
		for (MetaProvider factory : providers) {
			if (factory.accept(type, metaClass)) {
				return (T) factory.createElement(type, context);
			}
		}
		return null;
	}

	private MetaElement allocateMetaFromParamerizedType(ParameterizedType paramType,
			Class<? extends MetaElement> elementMetaClass) {
		if (paramType.getRawType() instanceof Class && Map.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
			PreconditionUtil.assertEquals("expected 2 type arguments", 2, paramType.getActualTypeArguments().length);
			MetaType keyType = getMeta(paramType.getActualTypeArguments()[0]).asType();
			MetaType valueType = getMeta(paramType.getActualTypeArguments()[1], elementMetaClass).asType();
			MetaMapType mapMeta = new MetaMapType();

			boolean primitiveKey = keyType instanceof MetaPrimitiveType;
			boolean primitiveValue = valueType instanceof MetaPrimitiveType;
			if (primitiveKey || !primitiveValue) {
				mapMeta.setName(valueType.getName() + "$MappedBy$" + keyType.getName());
				mapMeta.setId(valueType.getId() + "$MappedBy$" + keyType.getName());
			}
			else {
				mapMeta.setName(keyType.getName() + "$Map$" + valueType.getName());
				mapMeta.setId(keyType.getId() + "$Map$" + valueType.getName());
			}

			mapMeta.setImplementationType(paramType);
			mapMeta.setKeyType(keyType);
			mapMeta.setValueType(valueType);
			return mapMeta;
		}
		else if (paramType.getRawType() instanceof Class
				&& Collection.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
			return allocateMetaFromCollectionType(paramType, elementMetaClass);
		}
		else {
			throw new UnsupportedOperationException("unknown type " + paramType);
		}
	}

	private MetaElement allocateMetaFromCollectionType(ParameterizedType paramType,
			Class<? extends MetaElement> elementMetaClass) {
		PreconditionUtil.assertEquals("expected single type argument", 1, paramType.getActualTypeArguments().length);
		MetaType elementType = getMeta(paramType.getActualTypeArguments()[0], elementMetaClass).asType();

		boolean isSet = Set.class.isAssignableFrom((Class<?>) paramType.getRawType());
		boolean isList = List.class.isAssignableFrom((Class<?>) paramType.getRawType());
		if (isSet) {
			MetaSetType metaSet = new MetaSetType();
			metaSet.setId(elementType.getId() + "$Set");
			metaSet.setName(elementType.getName() + "$Set");
			metaSet.setImplementationType(paramType);
			metaSet.setElementType(elementType);
			return metaSet;
		}
		else if (isList) {
			MetaListType metaList = new MetaListType();
			metaList.setId(elementType.getId() + "$List");
			metaList.setName(elementType.getName() + "$List");
			metaList.setImplementationType(paramType);
			metaList.setElementType(elementType);
			return metaList;
		}
		else {
			throw new IllegalStateException("expected list or set type: " + paramType.toString());
		}
	}

	private boolean isPrimitiveType(Class<?> clazz) {
		if (clazz == Object.class) {
			return true;
		}

		if(clazz.getPackage() != null && clazz.getPackage().getName().equals("java.time")){
			return true;
		}

		if (clazz.isPrimitive() || primitiveTypes.contains(clazz))
			return true;

		for (Class<?> primitiveType : primitiveTypes) {
			if (primitiveType.isAssignableFrom(clazz)) {
				return true;
			}
		}
		return false;
	}

	public static Class<?> getRawType(Type type) {
		if (type instanceof Class) {
			return (Class<?>) type;
		}
		else if (type instanceof ParameterizedType) {
			ParameterizedType paramType = (ParameterizedType) type;
			return getRawType(paramType.getRawType());
		}
		else {
			throw new IllegalArgumentException("unable to obtain raw type for " + type);
		}
	}

	public void addAll(Collection<? extends MetaElement> elements) {
		for (MetaElement element : elements) {
			add(element);
		}
	}

	public void add(MetaElement element) {
		PreconditionUtil.assertNotNull("no name provided", element.getName());
		if (element instanceof MetaType) {
			MetaType typeElement = element.asType();
			Class<?> implClass = typeElement.getImplementationClass();
			if (!element.hasId()) {
				element.setId(computeIdPrefixFromPackage(implClass, element) + element.getName());
			}
		}

		if (!element.hasId() && element.getParent() != null) {
			element.setId(element.getParent().getId() + "." + element.getName());
		}

		if (idElementMap.get(element.getId()) != element) {
			LOGGER.debug("add {} of type {}", element.getId(), element.getClass().getSimpleName());

			// queue for initialization
			initializationQueue.add(element);

			// add to data structures
			if (element instanceof MetaType) {
				MetaType typeElement = element.asType();

				// check not alreay exists
				if (typeElementsMap.containsKey(typeElement.getImplementationType())) {
					List<MetaElement> existingElements = typeElementsMap.getList(typeElement.getImplementationType());
					for (MetaElement existingElement : existingElements) {
						if( existingElement.getId().equals(element.getId())){
							throw new IllegalStateException(element.getId() + " already available: " + existingElement + " vs " + element );
						}
					}
				}

				typeElementsMap.add(typeElement.getImplementationType(), element);
			}
			MetaElement currentElement = idElementMap.get(element.getId());
			PreconditionUtil.assertNull(element.getId(), currentElement);
			idElementMap.put(element.getId(), element);

			// add children recursively
			for (MetaElement child : element.getChildren()) {
				add(child);
			}
		}
	}

	private String computeIdPrefixFromPackage(Class<?> implClass, MetaElement element) {
		Package implPackage = implClass.getPackage();
		if (implPackage == null && implClass.isArray()) {
			implPackage = implClass.getComponentType().getPackage();
		}
		if (implPackage == null) {
			throw new IllegalStateException(implClass.getName() + " does not belong to a package");
		}
		String packageName = implPackage.getName();
		StringBuilder idInfix = new StringBuilder(".");
		while (true) {

			String idMappingKey1 = toIdMappingKey(packageName, element.getClass());
			String idMappingKey2 = toIdMappingKey(packageName, null);

			String idPrefix = packageIdMapping.get(idMappingKey1);
			if (idPrefix == null) {
				idPrefix = packageIdMapping.get(idMappingKey2);
			}
			if (idPrefix != null) {
				return idPrefix + idInfix;
			}
			int sep = packageName.lastIndexOf('.');
			if (sep == -1) {
				break;
			}
			idInfix.append(packageName.substring(sep + 1));
			idInfix.append(".");
			packageName = packageName.substring(0, sep);
		}
		return implPackage.getName() + ".";
	}

	private void checkInitialized() {
		if (!discovered && !adding) {
			initialize();
		}
	}

	public void initialize() {
		LOGGER.debug("adding");
		adding = true;
		try {
			if (!discovered) {
				for (MetaProvider provider : providers) {
					provider.discoverElements(context);
				}
				discovered = true;
			}

			while (!initializationQueue.isEmpty()) {
				MetaElement element = initializationQueue.pollFirst();
				// initialize from roots down to decendants.
				if (element.getParent() == null) {
					initialize(element);
				}
			}
		}
		finally {
			LOGGER.debug("added");
			adding = false;
		}
	}

	private void initialize(MetaElement element) {
		LOGGER.debug("adding {}", element.getId());
		for (MetaProvider initializer : providers) {
			packageIdMapping.putAll(initializer.getIdMappings());
		}

		for (MetaProvider initializer : providers) {
			initializer.onInitializing(context, element);
		}

		for (MetaElement child : element.getChildren()) {
			initialize(child);
		}

		for (MetaProvider initializer : providers) {
			initializer.onInitialized(context, element);
		}
		LOGGER.debug("added {}", element.getId());
	}

	public List<MetaProvider> getProviders() {
		return providers;
	}

	public void putIdMapping(String packageName, String idPrefix) {
		packageIdMapping.put(packageName, idPrefix);
	}

	public void putIdMapping(String packageName, Class<? extends MetaElement> type, String idPrefix) {
		packageIdMapping.put(toIdMappingKey(packageName, type), idPrefix);
	}

	private String toIdMappingKey(String packageName, Class<? extends MetaElement> type) {
		if (type != null) {
			return packageName + "#" + type.getName();
		}
		else {
			return packageName;
		}
	}
}


text:
package com.trevore.rpn;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;
import java.util.logging.Logger;

public class RpnCalculator {

    private final static Logger LOGGER = Logger.getLogger(RpnCalculator.class.getName());

    private Deque<ValueToken> tokenStack;
    private int currentTokenIndex = 0;

    public double calculate(String input) {
        if (input == null) {
            throw new NullPointerException("Input cannot be null.");
        }

        tokenStack = new ArrayDeque<ValueToken>(input.length());
        currentTokenIndex = 0;

        StringTokenizer tokenizer = new StringTokenizer(input, " ");
        while (tokenizer.hasMoreTokens()) {
            processToken(tokenizer.nextToken());
            currentTokenIndex++;
        }

        if (tokenStack.size() != 1) {
            throw new IllegalArgumentException("Invalid result size of " + tokenStack.size());
        }

        return tokenStack.pop().getValue();
    }

    private void processToken(String token) {
        ValueToken value = token.length() == 1 && MathOperator.contains(token.charAt(0))
                ? new ValueToken(processOperator(token))
                : new ValueToken(token);
        tokenStack.push(value);
        LOGGER.info("Pushing token" + token);
    }

    private double processOperator(String operand) {
        if (tokenStack.size() < 2) {
            throw new IllegalArgumentException("Does not have two operands for operation " + operand + " at position " + currentTokenIndex + ".");
        }

        double first = tokenStack.pop().getValue();
        double second = tokenStack.pop().getValue();
        LOGGER.info("Popping " + first + " and " + second);

        MathOperator mathOperator = MathOperator.fromString(operand.charAt(0));
        return mathOperator.calculate(first, second);
    }

}


text:
r"""
ES-PIM (:mod:`meshless.espim`)
===============================

Edge-based Smoothed Point Interpolation Method.

.. currentmodule:: meshless.espim

.. automodule:: meshless.espim.read_mesh
    :members:

.. automodule:: meshless.espim.read_mesh
    :members:

.. automodule:: meshless.espim.plate2d_calc_k0
    :members:

.. automodule:: meshless.espim.plate2d_calc_kG
    :members:

.. automodule:: meshless.espim.plate2d_add_k0s
    :members:

"""
pass


text:
/**
 * Created by andrew on 29/3/17.
 */
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var models_1 = require("../models");
var actions_1 = require("../actions");
var initialState = new models_1.User();
function default_1(state, action) {
    if (state === void 0) { state = initialState; }
    switch (action.type) {
        case actions_1.UserActions.RESET_USER: {
            return initialState;
        }
        case actions_1.UserActions.GET_USER_SUCCESS: {
            return action.payload;
        }
        default: {
            return state;
        }
    }
}
exports.default = default_1;


text:
#ifndef STATSWINDOW_INCLUDED
#define STATSWINDOW_INCLUDED

class StatsWindow : public wxWindow
{
    bool m_visible;
    wxGrid *m_grid1;
    wxGrid *m_grid2;
    int m_length;
    OptionsButton *m_pLengthButton;
    wxTimer m_coolerTimer;

    void OnButtonLength(wxCommandEvent&);
    void OnMenuLength(wxCommandEvent&);
    void OnButtonClear(wxCommandEvent&);
    void OnTimerCooler(wxTimerEvent&);

public:
    StatsWindow(wxWindow *parent);
    ~StatsWindow();

    void UpdateStats();
    void UpdateScopePointing();
    void UpdateCooler();
    void SetState(bool is_active);

    DECLARE_EVENT_TABLE()
};

#endif


text:
using System;
using System.Linq;
using CalculatorsLibrary.Enumeration;

namespace CalculatorsLibrary.Formulas
{
    public class Formulas
    {
        /// <summary>
        /// Returns the sine of <paramref name="angle"/> in degrees. By default, <paramref name="decimals"/> is rounded to three decimal places.
        /// </summary>
        /// <param name="angle">Angle in degrees</param>
        /// <returns></returns>
        public static double Sinus(double angle, int decimals = 3)
        {
            var sinValue = Math.Sin(angle * Math.PI / 180.0);
            return Math.Round(sinValue, decimals);
        }

		/// <summary>
		/// Returns the cosinus of <paramref name="angle"/> in degrees. By default, <paramref name="decimals"/> is rounded to three decimal places.
		/// </summary>
		/// <param name="angle"></param>
		/// <returns></returns>
		public static double Cosinus(double angle, int decimals = 3)
        {
            var cosValue = Math.Cos(angle * Math.PI / 180.0);
            return Math.Round(cosValue, decimals);
        }

		/// <summary>
		/// Returns the inverse cosinus of <paramref name="angle"/> in radians. By default, <paramref name="decimals"/> is rounded to zero decimal places.
		/// </summary>
		/// <returns>The cosinus.</returns>
		/// <param name="radians">Radians.</param>
		public static double InverseCosinus(double radians, int decimals = 0)
		{
			var inverseCosValue = Math.Acos(radians) * 180.0 / Math.PI;
			return Math.Round(inverseCosValue, decimals);
		}

		/// <summary>
		/// Returns the tangent of <paramref name="angle"/> in degrees. By default, <paramref name="decimals"/> is rounded to three decimal places.
		/// </summary>
		/// <param name="angle"></param>
		/// <returns></returns>
		public static double Tangent(double angle, int decimals = 3)
        {
            var exceptionsTangent = new[] { 90.0, 270.0, 450.0 };
            if (exceptionsTangent.Contains(angle))
                return 0;

            var tanValue = Math.Tan(angle * Math.PI / 180.0);
            return Math.Round(tanValue, decimals);
        }

        /// <summary>
        /// Returns a boolean when the value of <paramref name="parameter"/> parameter equals zero
        /// </summary>
        public static bool IsEqualToZero(double parameter)
        {
            return (Math.Abs(parameter) < double.Epsilon);
        }

        /// <summary>
        /// Returns the cuttingspeed based on the <paramref name="unit"/>, <paramref name="spindleSpeed"/> and the <paramref name="diameter"/>. [Coromant Technical Guide, p. I4]
        /// </summary>
        public virtual double CuttingSpeed(Unit unit, double spindleSpeed, double diameter)
        {
            return (unit == Unit.Metric) ? (Math.PI * diameter * spindleSpeed) / 1000 : (Math.PI * diameter * spindleSpeed) / 12;
        }

        /// <summary>
        /// Returns the spindlespeed based on the <paramref name="unit"/>, <paramref name="cuttingSpeed"/> and the <paramref name="diameter"/>. [Coromant Technical Guide, p. I4]
        /// </summary>
        public virtual double SpindleSpeed(Unit unit, double cuttingSpeed, double diameter)
        {
            return (unit == Unit.Metric) ? (cuttingSpeed * 1000) / (Math.PI * diameter) : (cuttingSpeed * 12) / (Math.PI * diameter);
        }
    }
}


text:
#include "EfiSpec.h"
#include EFI_GUID_DEFINITION (SmBios)

EFI_GUID  gEfiSmbiosTableGuid = EFI_SMBIOS_TABLE_GUID;

EFI_GUID_STRING(&gEfiSmbiosTableGuid, "SMBIOS Table", "SMBIOS Table GUID in EFI System Table");


text:
package Inheritance.Exercise.P05Restaurant.restaurant;

import java.math.BigDecimal;

public class Coffee extends HotBeverage{
    final static double COFFEE_MILLILITERS = 50.0;
    final static BigDecimal COFFEE_PRICE = BigDecimal.valueOf(3.50);
    private double caffeine;

    public Coffee(String name, double caffeine) {
        super(name, COFFEE_PRICE, COFFEE_MILLILITERS);
        this.caffeine = caffeine;
    }

    public double getCaffeine() {
        return caffeine;
    }
}


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE23_Relative_Path_Traversal__wchar_t_environment_open_12.cpp
Label Definition File: CWE23_Relative_Path_Traversal.label.xml
Template File: sources-sink-12.tmpl.cpp
*/
/*
 * @description
 * CWE: 23 Relative Path Traversal
 * BadSource: environment Read input from an environment variable
 * GoodSource: Use a fixed file name
 * Sink: open
 *    BadSink : Open the file named in data using open()
 * Flow Variant: 12 Control flow: if(globalReturnsTrueOrFalse())
 *
 * */

#include "std_testcase.h"

#ifdef _WIN32
#define BASEPATH L"c:\\temp\\"
#else
#include <wchar.h>
#define BASEPATH L"/tmp/"
#endif

#define ENV_VARIABLE L"ADD"

#ifdef _WIN32
#define GETENV _wgetenv
#else
#define GETENV getenv
#endif

#ifdef _WIN32
#define OPEN _wopen
#define CLOSE _close
#else
#include <unistd.h>
#define OPEN open
#define CLOSE close
#endif

namespace CWE23_Relative_Path_Traversal__wchar_t_environment_open_12
{

#ifndef OMITBAD

void bad()
{
    wchar_t * data;
    wchar_t dataBuffer[FILENAME_MAX] = BASEPATH;
    data = dataBuffer;
    if(globalReturnsTrueOrFalse())
    {
        {
            /* Append input from an environment variable to data */
            size_t dataLen = wcslen(data);
            wchar_t * environment = GETENV(ENV_VARIABLE);
            /* If there is data in the environment variable */
            if (environment != NULL)
            {
                /* POTENTIAL FLAW: Read data from an environment variable */
                wcsncat(data+dataLen, environment, FILENAME_MAX-dataLen-1);
            }
        }
    }
    else
    {
        /* FIX: Use a fixed file name */
        wcscat(data, L"file.txt");
    }
    {
        int fileDesc;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        fileDesc = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
        if (fileDesc != -1)
        {
            CLOSE(fileDesc);
        }
    }
}

#endif /* OMITBAD */

#ifndef OMITGOOD

/* goodG2B() - use goodsource and badsink by changing the "if" so that
   both branches use the GoodSource */
static void goodG2B()
{
    wchar_t * data;
    wchar_t dataBuffer[FILENAME_MAX] = BASEPATH;
    data = dataBuffer;
    if(globalReturnsTrueOrFalse())
    {
        /* FIX: Use a fixed file name */
        wcscat(data, L"file.txt");
    }
    else
    {
        /* FIX: Use a fixed file name */
        wcscat(data, L"file.txt");
    }
    {
        int fileDesc;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        fileDesc = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
        if (fileDesc != -1)
        {
            CLOSE(fileDesc);
        }
    }
}

void good()
{
    goodG2B();
}

#endif /* OMITGOOD */

} /* close namespace */

/* Below is the main(). It is only used when building this testcase on
   its own for testing or for building a binary to use in testing binary
   analysis tools. It is not used when compiling all the testcases as one
   application, which is how source code analysis tools are tested. */

#ifdef INCLUDEMAIN

using namespace CWE23_Relative_Path_Traversal__wchar_t_environment_open_12; /* so that we can use good and bad easily */

int main(int argc, char * argv[])
{
    /* seed randomness */
    srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
    printLine("Calling good()...");
    good();
    printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
    printLine("Calling bad()...");
    bad();
    printLine("Finished bad()");
#endif /* OMITBAD */
    return 0;
}

#endif


text:
module Azure::ApiManagement::Mgmt::V2018_06_01_preview
  module Models
    #
    # Http message diagnostic settings.
    #
    class HttpMessageDiagnostic

      include MsRestAzure

      # @return [Array<String>] Array of HTTP Headers to log.
      attr_accessor :headers

      # @return [BodyDiagnosticSettings] Body logging settings.
      attr_accessor :body

      #
      # Mapper for HttpMessageDiagnostic class as Ruby Hash.
      # This will be used for serialization/deserialization.
      #
      def self.mapper()
        {
          client_side_validation: true,
          required: false,
          serialized_name: 'HttpMessageDiagnostic',
          type: {
            name: 'Composite',
            class_name: 'HttpMessageDiagnostic',
            model_properties: {
              headers: {
                client_side_validation: true,
                required: false,
                serialized_name: 'headers',
                type: {
                  name: 'Sequence',
                  element: {
                      client_side_validation: true,
                      required: false,
                      serialized_name: 'StringElementType',
                      type: {
                        name: 'String'
                      }
                  }
                }
              },
              body: {
                client_side_validation: true,
                required: false,
                serialized_name: 'body',
                type: {
                  name: 'Composite',
                  class_name: 'BodyDiagnosticSettings'
                }
              }
            }
          }
        }
      end
    end
  end
end


text:
  {% if paginator.previous_page %}

        <svg class="w1" data-icon="chevronLeft" viewBox="0 0 32 32" style="fill:currentcolor">
          <title>chevronLeft icon</title>
          <path d="M20 1 L24 5 L14 16 L24 27 L20 31 L6 16 z"></path>
        </svg>
      Previous

  {% else %}

      Previous

  {% endif %}
  {% if paginator.next_page %}

      Next
      <svg class="w1" data-icon="chevronRight" viewBox="0 0 32 32" style="fill:currentcolor">
        <title>chevronRight icon</title>
        <path d="M12 1 L26 16 L12 31 L8 27 L18 16 L8 5 z"></path>
      </svg>

  {% else %}

      Next

  {% endif %}


text:
package com.aarnam.softwares.spotifystreamer.android.common.interfaces;

/**
 * Created by gaurang on 7/5/15.
 */
public interface SpotifyServiceAgreement {

    void onPostExecute(Object returnObject);

}


text:
using System;

class NTthBit
{
    static void Main()
    {
        long numberP = long.Parse(Console.ReadLine());
        byte numberN = byte.Parse(Console.ReadLine());
        long mask = 1 << numberN;
        long result;
        result = (numberP & mask) >> numberN;
        Console.WriteLine(result);
    }}


text:
{% extends "diary/base_diary.html" %}

{% block content %}

{{ username|capfirst }}, you have successfully logged into simply good!

 Update your profile

{% endblock content %}


text:
/*
 * Created on Feb 23, 2003
 */
package org.apache.roller.business.hibernate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.business.RollerImpl;
import org.apache.roller.model.BookmarkManager;
import org.apache.roller.model.ConfigManager;
import org.apache.roller.model.AutoPingManager;
import org.apache.roller.model.PingQueueManager;
import org.apache.roller.model.PingTargetManager;
import org.apache.roller.model.PlanetManager;
import org.apache.roller.model.PropertiesManager;
import org.apache.roller.model.RefererManager;
import org.apache.roller.model.Roller;
import org.apache.roller.model.UserManager;
import org.apache.roller.model.WeblogManager;

/**
 * A Hibernate specific implementation of the Roller business layer.
 */
public class HibernateRollerImpl extends RollerImpl {

    static final long serialVersionUID = 5256135928578074652L;

    private static Log mLogger = LogFactory.getLog(HibernateRollerImpl.class);

    // our singleton instance
    private static HibernateRollerImpl me = null;

    // a persistence utility class
    private HibernatePersistenceStrategy strategy = null;

    // references to the managers we maintain
    private BookmarkManager bookmarkManager = null;
    private ConfigManager configManager = null;
    private PropertiesManager propertiesManager = null;
    private PlanetManager planetManager = null;
    private RefererManager refererManager = null;
    private UserManager userManager = null;
    private WeblogManager weblogManager = null;
    private PingQueueManager pingQueueManager = null;
    private AutoPingManager autoPingManager = null;
    private PingTargetManager pingTargetManager = null;

    protected HibernateRollerImpl() throws RollerException {
        try {
            strategy = new HibernatePersistenceStrategy();
        } catch(Throwable t) {
            // if this happens then we are screwed
            mLogger.fatal("Error initializing Hibernate", t);
            throw new RollerException(t);
        }
    }

    /**
     * Instantiates and returns an instance of HibernateRollerImpl.
     */
    public static Roller instantiate() throws RollerException {
        if (me == null) {
            mLogger.debug("Instantiating HibernateRollerImpl");
            me = new HibernateRollerImpl();
        }

        return me;
    }

    public void flush() throws RollerException {
        this.strategy.flush();
    }

    public void release() {

        // release our own stuff first
        if (bookmarkManager != null) bookmarkManager.release();
        if (configManager != null) configManager.release();
        if (refererManager != null) refererManager.release();
        if (userManager != null) userManager.release();
        if (weblogManager != null) weblogManager.release();
        if (pingTargetManager != null) pingTargetManager.release();
        if (pingQueueManager != null) pingQueueManager.release();
        if (autoPingManager != null) autoPingManager.release();

        // tell Hibernate to close down
        this.strategy.release();

        // then let parent do its thing
        super.release();
    }

    public void shutdown() {

        // do our own shutdown first
        this.release();

        // then let parent do its thing
        super.shutdown();
    }

    /**
     * @see org.apache.roller.model.Roller#getUserManager()
     */
    public UserManager getUserManager() throws RollerException {
        if ( userManager == null ) {
            userManager = new HibernateUserManagerImpl(strategy);
        }
        return userManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getBookmarkManager()
     */
    public BookmarkManager getBookmarkManager() throws RollerException {
        if ( bookmarkManager == null ) {
            bookmarkManager = new HibernateBookmarkManagerImpl(strategy);
        }
        return bookmarkManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getWeblogManager()
     */
    public WeblogManager getWeblogManager() throws RollerException {
        if ( weblogManager == null ) {
            weblogManager = new HibernateWeblogManagerImpl(strategy);
        }
        return weblogManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getRefererManager()
     */
    public RefererManager getRefererManager() throws RollerException {
        if ( refererManager == null ) {
            refererManager = new HibernateRefererManagerImpl(strategy);
        }
        return refererManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getConfigManager()
     */
    public ConfigManager getConfigManager() throws RollerException {
        if (configManager == null) {
            configManager = new HibernateConfigManagerImpl(strategy);
        }
        return configManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getPropertiesManager()
     */
    public PropertiesManager getPropertiesManager() throws RollerException {
        if (propertiesManager == null) {
            propertiesManager = new HibernatePropertiesManagerImpl(strategy);
        }
        return propertiesManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getPingTargetManager()
     */
    public PingQueueManager getPingQueueManager() throws RollerException {
        if (pingQueueManager == null) {
            pingQueueManager = new HibernatePingQueueManagerImpl(strategy);
        }
        return pingQueueManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getPlanetManager()
     */
    public PlanetManager getPlanetManager() throws RollerException {
        if ( planetManager == null ) {
            planetManager = new HibernateRollerPlanetManagerImpl(strategy);
        }
        return planetManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getPingTargetManager()
     */
    public AutoPingManager getAutopingManager() throws RollerException {
        if (autoPingManager == null) {
            autoPingManager = new HibernateAutoPingManagerImpl(strategy);
        }
        return autoPingManager;
    }

    /**
     * @see org.apache.roller.model.Roller#getPingTargetManager()
     */
    public PingTargetManager getPingTargetManager() throws RollerException {
        if (pingTargetManager == null) {
            pingTargetManager = new HibernatePingTargetManagerImpl(strategy);
        }
        return pingTargetManager;
    }

}


text:
package net.dv8tion.jda.core.entities;

import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.managers.WebhookManager;
import net.dv8tion.jda.core.managers.WebhookManagerUpdatable;
import net.dv8tion.jda.core.requests.RestAction;

/**
 * An object representing Webhooks in Discord
 *
 * @since  3.0
 * @author Florian Spieß
 */
public interface Webhook extends ISnowflake
{

    /**
     * The JDA instance of this Webhook.
     *
     * @return The current JDA instance of this Webhook
     */
    JDA getJDA();

    /**
     * The {@link net.dv8tion.jda.core.entities.Guild Guild} instance
     * for this Webhook.
     *
This is a shortcut for {@link #getChannel()}.getGuild().
     *
     * @return The current Guild of this Webhook
     */
    Guild getGuild();

    /**
     * The {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} instance
     * this Webhook is attached to.
     *
     * @return The current TextChannel of this Webhook
     */
    TextChannel getChannel();

    /**
     * The owner of this Webhook.
     *
     * @return A {@link net.dv8tion.jda.core.entities.Member Member} instance
     *         representing the owner of this Webhook
     */
    Member getOwner();

    /**
     * The default User for this Webhook.
     *
     *
The {@link net.dv8tion.jda.core.entities.User User} returned is always {@code fake}.
     *
This User is used for all messages posted to the Webhook route (found in {@link #getUrl()}),
     * it holds the default references for the message authors of messages by this Webhook.
     *
     *
When {@code POST}ing to a Webhook route the name/avatar of this default user
     * can be overridden.
     *
     * @return A fake {@link net.dv8tion.jda.core.entities.User User} instance
     *         representing the default webhook user.
     *
     * @see    Execute Webhook Docs
     */
    User getDefaultUser();

    /**
     * The name of this Webhook.
     *
This will be displayed by default as the author name
     * of every message by this Webhook.
     *
     *
This is a shortcut for {@link #getDefaultUser()}.getName().
     *
     * @return The name of this Webhook
     */
    String getName();

    /**
     * The execute token for this Webhook.
     *
This can be used to modify/delete/execute
     * this Webhook.
     *
     * @return The execute token for this Webhook
     */
    String getToken();

    /**
     * The {@code POST} route for this Webhook.
     *
This contains the {@link #getToken() token} and {@link #getId() id}
     * of this Webhook.
     *
     *
The route returned by this method does not need permission checks
     * to be executed.
     *
It is implied that Webhook messages always have all permissions
     * including {@link net.dv8tion.jda.core.Permission#MESSAGE_MENTION_EVERYONE mentioning everyone}.
     *
     *
Webhook executions are limited with 5 requests per second.
     * The response contains rate limit headers that should be handled
     * by execution frameworks. (Learn More)
     *
     * @return The execution route for this Webhook.
     */
    String getUrl();

    /**
     * Deletes this Webhook.
     *
     * @return {@link net.dv8tion.jda.core.requests.RestAction} - Type: Void
     *
The rest action to delete this Webhook.
     */
    RestAction<Void> delete();

    /**
     * The {@link net.dv8tion.jda.core.managers.WebhookManager Manager}
     * for this Webhook.
     *
This Manager does not require to update, it provides set methods
     * to atomically modify fields of this Webhook.
     *
     * @return An instance of {@link net.dv8tion.jda.core.managers.WebhookManager WebhookManager}
     *         for this Webhook
     */
    WebhookManager getManager();

    /**
     * The {@link net.dv8tion.jda.core.managers.WebhookManager Manager}
     * for this Webhook.
     *
This Manager does require to update, it provides get methods
     * to retrieve {@link net.dv8tion.jda.core.managers.fields.WebhookField fields} of this Webhook which can be modified and updated.
     *
     * @return An instance of {@link net.dv8tion.jda.core.managers.WebhookManagerUpdatable WebhookManagerUpdatable}
     *         for this Webhook
     */
    WebhookManagerUpdatable getManagerUpdatable();
}


text:
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}

-- | An API for the Online Etymology Dictionary at http://etymonline.com/.
--   The encoding is ISO-8859-1/latin1 so needs to use uconv.

module Language.English.EtymologyOnline where

import           Control.Exception
import           Control.Monad
import           Data.ByteString       (ByteString)
import qualified Data.ByteString       as Bytes
import           Data.ByteString.UTF8  (toString)
import           Data.Maybe
import           Data.Text.ICU.Convert
import           Data.Typeable
import           Network.Curl
import           System.Random
import           Text.XML.Light

-- | An EO exception.
data EOException
  = CannotParsePageCountForLetter Char
  | CannotDownloadPageCountForLetter Char
  | CannotParsePageEntries Char Int (Maybe Element)
  | CannotDownloadPageEntries Char Int
  | NoEntryInPage Char Int
  deriving (Typeable,Show)
instance Exception EOException

-- | Get a random Etymology Online entry.
getRandomEntry :: IO (String,String)
getRandomEntry = do
  converter <- open "utf-8" Nothing
  letter <- randomRIO ('a','z')
  pages <- getletterpages converter letter
  pagenumber <- randomRIO (1,pages)
  entries <- getletterentries converter letter pagenumber
  index <- randomRIO (1,length entries)
  maybe (throw (NoEntryInPage letter pagenumber))
        return
        (lookup index (zip [1..] entries))

-- | Get the number of pages for a letter.
getletterpages :: Converter -> Char -> IO Int
getletterpages converter l = withCurlDo $ do
  (code,bytes) <- curlGetString_ url []
  case code of
    CurlOK -> do
      let doc = parseEOXML converter (bytes :: ByteString)
      maybe (return 1) -- Some pages don't have pagination at all.
            (return . length)
            (getlinks doc)
    _ -> throw (CannotDownloadPageCountForLetter l)
  where url = "http://www.etymonline.com/index.php?l=" ++ [l]

-- | Get the entries for a letter and page number.
getletterentries :: Converter -> Char -> Int -> IO [(String,String)]
getletterentries converter l pn = withCurlDo $ do
  (code,bytes) <- curlGetString_ url []
  case code of
    CurlOK -> do
      let doc = parseEOXML converter (bytes :: ByteString)
      maybe (throw (CannotParsePageEntries l pn doc)) return (getentries doc)
    _ -> throw (CannotDownloadPageEntries l pn)
  where url = "http://www.etymonline.com/index.php?l=" ++ [l] ++ "&p=" ++ show (pn - 1)

-- Get the entries given the page.
getentries :: Maybe Element -> Maybe [(String, String)]
getentries doc = do
  el <- doc
  let dts = grab "dt" el
      dds = grab "dd" el
  return (zip dts dds)

  where grab key = map (trim . allContent)
                 . findElements (qname key xhtml)

-- Get the pagination links from the page.
getlinks :: Maybe Element -> Maybe [String]
getlinks doc = do
  el <- doc
  paging <- filterElement paginglist el
  ul <- findChild (qname "ul" xhtml) paging
  return (paginglinks ul)

-- Find the element with the pagination.
paginglist :: Element -> Bool
paginglist el = findAttr (qname "class" Nothing) el == Just "paging"

-- Get the pagination links.
paginglinks :: Element -> [String]
paginglinks = mapMaybe (findAttr (qname "href" Nothing))
            . getels "a"

  where getels key = findElements (qname key xhtml)

-- Get all text content of an element.
allContent :: Element -> String
allContent (Element _ _ contents _) = concatMap switch contents where
  switch el =
    case el of
      Elem e -> allContent e
      CRef _  -> ""
      Text (CData _ d _) -> d

-- Parse an ISO-8859-1 document to an XML tree.
parseEOXML :: Converter -> ByteString -> Maybe Element
parseEOXML converter =
  parseXMLDoc . toUnicode converter

-- Some utils.

xhtml :: Maybe String
xhtml = Just "http://www.w3.org/1999/xhtml"

qname :: String -> Maybe String -> QName
qname q uri = blank_name { qName = q, qURI = uri }

trim :: String -> String
trim = unwords . words


text:
require 'mongo/operation/commands/command'
require 'mongo/operation/commands/find'
require 'mongo/operation/commands/get_more'
require 'mongo/operation/commands/parallel_scan'
require 'mongo/operation/commands/aggregate'
require 'mongo/operation/commands/map_reduce'
require 'mongo/operation/commands/collections_info'
require 'mongo/operation/commands/create'
require 'mongo/operation/commands/drop'
require 'mongo/operation/commands/drop_database'
require 'mongo/operation/commands/indexes'
require 'mongo/operation/commands/list_collections'
require 'mongo/operation/commands/list_indexes'
require 'mongo/operation/commands/user_query'
require 'mongo/operation/commands/users_info'


text:
<resources>
    <string name="settings">Nastavenia</string>
    <string name="more_options">Viac možností</string>

    <string name="title_configure">Nastavenia DashClock</string>
    <string name="section_extensions">Rozšírenia</string>
    <string name="section_appearance">Vzhľad</string>
    <string name="section_daydream">Šetrič obrazovky</string>
    <string name="section_advanced">Pokročilé</string>

    <string name="title_apps">Aplikácie</string>
    <string name="title_shortcuts">Odkazy</string>

    <string name="get_more_extensions">Získať viac rozšírení</string>
    <string name="add_another_extension">Pridať ďalšie rozšírenie</string>
    <string name="more_extensions">Viac rozšírení</string>
    <string name="done">Hotovo</string>
    <string name="add_extension">Pridať rozšírenie</string>
    <string name="cancel">Zrušiť</string>
    <string name="remove">Odstrániť</string>

    <string name="undo">Naspäť</string>
    <string name="extension_removed_template">Rozšírenie \'%1$s\' bolo odstránené.</string>
    <string name="extensions_removed_template">Počet odstránených rozšírení: %1%d.</string>

    <string name="send_logs">Poslať záznam ladenia</string>
    <string name="send_logs_chooser_title">Poslať záznamy pomocou</string>

    <string name="prev_date_style">Predchádzajúci formát dátumu</string>
    <string name="prev_time_style">Predchádzajúci formát času</string>
    <string name="next_date_style">Nasledujúci formát dátumu</string>
    <string name="next_time_style">Nasledujúci formát času</string>

    <string name="incompatible_extension_menu_template">%1$s (Nekompatibilné)</string>
    <string name="incompatible_extension_title">Nekompatibilné rozšírenie</string>
    <string name="incompatible_extension_message_search_play_template"><![CDATA[Rozšírenie
        %1$s nie je kompatibilné s touto verziou DashClocku.
        Vyhľadať aktualizáciu rozšírenia v Google Play?]]></string>
    <string name="search_play">Vyhľadať v Google Play</string>

    <string name="close">Zavrieť</string>
    <string name="about">O aplikácii</string>

    <string name="about_body"><![CDATA[
        Autorské práva 2012–2016 Google Inc. Všetky práva vyhradené.

        Podmienky služby
          ·
        Ochrana osobných údajov

        Veľká vďaka za tieto nástroje:

        Android Developer Icons

        od Günther Beyer z Opoloo

        DragSortListView

        od Carl A. Bauer
    ]]></string>

    <string name="weather_extension_title">Počasie</string>
    <string name="weather_extension_description">
        Zobrazí najnovšie informácie okolo vás a to vrátane aktuálnej teploty,
		podmienok a predpovedi počasia. Dáta sú získavané zo služby Yahoo! Weather.
    </string>
    <string name="title_weather_settings">Nastavenia rozšírenia: Počasie</string>
    <string name="temperature_template">%1$s°</string>
    <string name="later_forecast_template">Neskôr: %1$s</string>
    <string name="no_weather_data">Žiadne údaje o počasí k dispozícii</string>
    <string name="no_location_data">Vaša poloha sa nedá určiť</string>

    <string name="gmail_extension_title">Gmail</string>
    <string name="gmail_extension_description">
        Zobrazí počet neprečítaných e-mailov prioritnej alebo doručenej pošty v službe Gmail.
    </string>
    <string name="title_gmail_settings">Nastavenia rozšírenia: Gmail</string>
    <plurals name="gmail_title_template">
        <item quantity="one">%1$s neprečítaný e-mail</item>
        <item quantity="few">%1$s neprečítané e-maily</item>
        <item quantity="other">%1$d neprečítaných e-mailov</item>
    </plurals>

    <string name="next_alarm_extension_title">Nasledujúci budík</string>
    <string name="next_alarm_extension_description">
        Zobrazí informácie o nasledujúcom budíku, ak je nastavený.
    </string>
    <string name="next_alarm">Nasledujúci budík</string>
    <string name="title_next_alarm_settings">Nastavenia rozšírenia: Nasledujúci budík</string>

    <string name="calendar_extension_title">Schôdzka v kalendári</string>
    <string name="calendar_extension_description">
        Zobrazí informácie o nasledujúcej schôdzke v kalendári, ak je
		naplánovaná v najbližších hodinách/týždni.
    </string>
    <string name="title_calendar_settings">Nastavenia rozšírenia: Kalendár</string>
    <plurals name="calendar_template_days">
        <item quantity="one">%1$s deň</item>
        <item quantity="few">%1$s dni</item>
        <item quantity="other">%1$s dní</item>
    </plurals>
    <plurals name="calendar_template_hours">
        <item quantity="one">%1$s hodina</item>
        <item quantity="few">%1$s hodiny</item>
        <item quantity="other">%1$s hodín</item>
    </plurals>
    <plurals name="calendar_template_mins">
        <item quantity="one">%1$s minúta</item>
        <item quantity="few">%1$s minúty</item>
        <item quantity="other">%1$s minút</item>
    </plurals>
    <string name="today">Dnes</string>
    <string name="now">Teraz</string>

    <string name="missed_calls_extension_title">Zmeškané hovory</string>
    <string name="missed_calls_extension_description">
        Zobrazí počet zmeškaných hovorov a mená volajúcich.
    </string>
    <plurals name="missed_calls_title_template">
        <item quantity="one">%1$s zmeškaný hovor</item>
        <item quantity="few">%1$s zmeškané hovory</item>
        <item quantity="other">%1$s zmeškaných hovorov</item>
    </plurals>
    <string name="missed_calls_body_template">Od: %1$s</string>
    <string name="missed_calls_unknown">Neznámy</string>

    <string name="sms_extension_title">Textové správy</string>
    <string name="sms_extension_description">
        Zobrazí počet neprečítaných SMS a MMS konverzácií a mená odosielateľov.
    </string>
    <plurals name="sms_title_template">
        <item quantity="one">%1$s neprečítaná konverzácia</item>
        <item quantity="few">%1$s neprečítané konverzácie</item>
        <item quantity="other">%1$s neprečítaných konverzácií</item>
    </plurals>
    <string name="sms_body_template">Od: %1$s</string>
    <string name="sms_body_all_participants_template">S: %1$s</string>

    <string name="welcome_title">Prispôsobenie DashClocku</string>
    <string name="welcome_description">Chcete len vidieť aktuálny dátum a čas?
	    Potom stlačte zaškrtávacie tlačidlo hore a hotovo! Ale prečo si neprispôsobiť
		DashClock s niekoľkými rozšíreniami?
        \n\nRozšírenia zobrazujú relevantné a včasné informácie v DashClocku!
		Vyskúšajte ich pridaním niekoľkých rozšírení nižšie.
    </string>

    <string name="permission_desc_read_extension_data">Umožňuje požadovanie dát DashClock rozšírenia</string>
    <string name="permission_label_read_extension_data">Požadovať dáta DashClock rozšírenia</string>
    <string name="permission_desc_bind_data_consumer">Umožňuje aplikácií používať dáta zverejnené DashClock rozšíreniami</string>
    <string name="permission_label_bind_data_consumer">Požadovať používanie dát DashClock rozšírení</string>

</resources>


text:
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
   public static partial class File
   {
      #region Replace

      /// <summary>
      ///   Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of
      ///   the replaced file.
      /// </summary>
      /// <remarks>
      ///   The Replace method replaces the contents of a specified file with the contents of another file. It also creates a backup of the
      ///   file that was replaced.
      /// </remarks>
      /// <remarks>
      ///   If the <paramref name="sourceFileName"/> and <paramref name="destinationFileName"/> are on different volumes, this method will
      ///   raise an exception. If the <paramref name="destinationBackupFileName"/> is on a different volume from the source file, the backup
      ///   file will be deleted.
      /// </remarks>
      /// <remarks>
      ///   Pass null to the <paramref name="destinationBackupFileName"/> parameter if you do not want to create a backup of the file being
      ///   replaced.
      /// </remarks>
      /// <param name="sourceFileName">The name of a file that replaces the file specified by <paramref name="destinationFileName"/>.</param>
      /// <param name="destinationFileName">The name of the file being replaced.</param>
      /// <param name="destinationBackupFileName">The name of the backup file.</param>
      [SecurityCritical]
      public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName)
      {
         ReplaceCore(sourceFileName, destinationFileName, destinationBackupFileName, false, PathFormat.RelativePath);
      }

      /// <summary>
      ///   Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of
      ///   the replaced file and optionally ignores merge errors.
      /// </summary>
      /// <remarks>
      ///   The Replace method replaces the contents of a specified file with the contents of another file. It also creates a backup of the
      ///   file that was replaced.
      /// </remarks>
      /// <remarks>
      ///   If the <paramref name="sourceFileName"/> and <paramref name="destinationFileName"/> are on different volumes, this method will
      ///   raise an exception. If the <paramref name="destinationBackupFileName"/> is on a different volume from the source file, the backup
      ///   file will be deleted.
      /// </remarks>
      /// <remarks>
      ///   Pass null to the <paramref name="destinationBackupFileName"/> parameter if you do not want to create a backup of the file being
      ///   replaced.
      /// </remarks>
      /// <param name="sourceFileName">The name of a file that replaces the file specified by <paramref name="destinationFileName"/>.</param>
      /// <param name="destinationFileName">The name of the file being replaced.</param>
      /// <param name="destinationBackupFileName">The name of the backup file.</param>
      /// <param name="ignoreMetadataErrors">
      ///   <see langword="true"/> to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the
      ///   replacement file; otherwise, <see langword="false"/>.
      /// </param>
      [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "dest")]
      [SecurityCritical]
      public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
      {
         ReplaceCore(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors, PathFormat.RelativePath);
      }

      /// <summary>
      ///   [AlphaFS] Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a
      ///   backup of the replaced file and optionally ignores merge errors.
      /// </summary>
      /// <remarks>
      ///   The Replace method replaces the contents of a specified file with the contents of another file. It also creates a backup of the
      ///   file that was replaced.
      /// </remarks>
      /// <remarks>
      ///   If the <paramref name="sourceFileName"/> and <paramref name="destinationFileName"/> are on different volumes, this method will
      ///   raise an exception. If the <paramref name="destinationBackupFileName"/> is on a different volume from the source file, the backup
      ///   file will be deleted.
      /// </remarks>
      /// <remarks>
      ///   Pass null to the <paramref name="destinationBackupFileName"/> parameter if you do not want to create a backup of the file being
      ///   replaced.
      /// </remarks>
      /// <param name="sourceFileName">The name of a file that replaces the file specified by <paramref name="destinationFileName"/>.</param>
      /// <param name="destinationFileName">The name of the file being replaced.</param>
      /// <param name="destinationBackupFileName">The name of the backup file.</param>
      /// <param name="ignoreMetadataErrors">
      ///   <see langword="true"/> to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the
      ///   replacement file; otherwise, <see langword="false"/>.
      /// </param>
      /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
      [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "dest")]
      [SecurityCritical]
      public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors, PathFormat pathFormat)
      {
         ReplaceCore(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors, pathFormat);
      }

      #endregion // Replace

      #region ReplaceCore

      /// <summary>Replaces the contents of a specified file with the contents of another file, deleting
      ///   the original file, and creating a backup of the replaced file and optionally ignores merge errors.
      /// </summary>
      /// <remarks>
      ///   The Replace method replaces the contents of a specified file with the contents of another file. It also creates a backup of the
      ///   file that was replaced.
      /// </remarks>
      /// <remarks>
      ///   If the <paramref name="sourceFileName"/> and <paramref name="destinationFileName"/> are on different volumes, this method will
      ///   raise an exception. If the <paramref name="destinationBackupFileName"/> is on a different volume from the source file, the backup
      ///   file will be deleted.
      /// </remarks>
      /// <remarks>
      ///   Pass null to the <paramref name="destinationBackupFileName"/> parameter if you do not want to create a backup of the file being
      ///   replaced.
      /// </remarks>
      /// <param name="sourceFileName">The name of a file that replaces the file specified by <paramref name="destinationFileName"/>.</param>
      /// <param name="destinationFileName">The name of the file being replaced.</param>
      /// <param name="destinationBackupFileName">The name of the backup file.</param>
      /// <param name="ignoreMetadataErrors">
      ///   <see langword="true"/> to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the
      ///   replacement file; otherwise, <see langword="false"/>.
      /// </param>
      /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
      [SecurityCritical]
      internal static void ReplaceCore(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors, PathFormat pathFormat)
      {
         var options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;

         string sourceFileNameLp = Path.GetExtendedLengthPathCore(null, sourceFileName, pathFormat, options);
         string destinationFileNameLp = Path.GetExtendedLengthPathCore(null, destinationFileName, pathFormat, options);

         // Pass null to the destinationBackupFileName parameter if you do not want to create a backup of the file being replaced.
         string destinationBackupFileNameLp = Path.GetExtendedLengthPathCore(null, destinationBackupFileName, pathFormat, options);

         const int replacefileWriteThrough = 1;
         const int replacefileIgnoreMergeErrors = 2;

         FileSystemRights dwReplaceFlags = (FileSystemRights)replacefileWriteThrough;
         if (ignoreMetadataErrors)
            dwReplaceFlags |= (FileSystemRights)replacefileIgnoreMergeErrors;

         // ReplaceFile()
         // In the ANSI version of this function, the name is limited to MAX_PATH characters.
         // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
         // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

         if (!NativeMethods.ReplaceFile(destinationFileNameLp, sourceFileNameLp, destinationBackupFileNameLp, dwReplaceFlags, IntPtr.Zero, IntPtr.Zero))
            NativeError.ThrowException(Marshal.GetLastWin32Error(), sourceFileNameLp, destinationFileNameLp);
      }

      #endregion // ReplaceCore
   }
}


text:
package com.intellij.openapi.editor.ex.util;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.psi.tree.IElementType;

/**
 * @author gregsh
 */
public class HighlighterIteratorWrapper implements HighlighterIterator {
  private final HighlighterIterator myOriginal;

  public HighlighterIteratorWrapper(HighlighterIterator original) {
    myOriginal = original;
  }

  @Override
  public TextAttributes getTextAttributes() {
    return myOriginal.getTextAttributes();
  }

  @Override
  public int getStart() {
    return myOriginal.getStart();
  }

  @Override
  public int getEnd() {
    return myOriginal.getEnd();
  }

  @Override
  public IElementType getTokenType() {
    return myOriginal.getTokenType();
  }

  @Override
  public void advance() {
    myOriginal.advance();
  }

  @Override
  public void retreat() {
    myOriginal.retreat();
  }

  @Override
  public boolean atEnd() {
    return myOriginal.atEnd();
  }

  @Override
  public Document getDocument() {
    return myOriginal.getDocument();
  }
}


text:
package gudusoft.gsqlparser.sql2xml.model;

public class user_defined_representation
{

}


text:
<?php

global $CONFIG;

/**
 * Enable the search plugin
 */
enable_plugin('search', $CONFIG->site->guid);


text:
<title>Happy New Year!</title>
Dear Sergei!

New Year's here, dear friend,

I wish you – meet amazing man,

With handsome face and awesome car,

To make you feel like superstar.

And let your beauty stay this way –

So hot and glowing every day.

You are my friend, I am with you,

Ask anything – and I will do!


text: """The orvibo component."""