text:
u"""
Functions to mask spatial coordinates.

    "Geographic masking is the process of altering the coordinates of point
    location data to limit the risk of reidentification upon release of the
    data.  In effect, the purpose of geographic masking is to make it much
    more difficult to accurately reverse geocode the released data."

    -- from `chapter 6 of Ensuring Confidentiality of Geocoded Health Data:
    Assessing Geographic Masking Strategies for Individual-Level Data
    <https://www.hindawi.com/journals/amed/2014/567049/#sec6>`_

Some implementations are inspired by `chapter 7 of Ensuring Confidentiality of
Geocoded Health Data: Assessing Geographic Masking Strategies for Individual-
Level Data <https://www.hindawi.com/journals/amed/2014/567049/#sec7>`_.
"""

from geopy.point import Point
import math
import random

def _random_angle_in_radians():
    # This implementation uses human readable degrees with reduced precision
    # random.uniform(0, 360) * math.pi / 180

    # We simplfy the implementation by calculating directly in radians
    return random.uniform(0, 2) * math.pi

def limit_precision(point, precisions=(None, None, None)):
    """
    Masked points have a limited precision, hence we cut decimal places.

    In the given `precisions` tupel positive integers simply cut decimal places
    after the comma.  Negative integers define the amount decimals to keep
    before the comma, while cutting all decimal places after the comma.  In
    both cases standard mathematical rounding is applied to the first digit
    which won't be cut, before cutting the other digits.  The first value is
    the longitude's precision, the second value is the latitude's precision and
    the third value is the altitude's precision.

    If we define a coordinate like ...

        >>> coordinate = Point(12.3456, 12.3456, 123.456)

    ... and call this function like ...

        >>> limit_precision(coordinate)
        Point(12.3456, 12.3456, 123.456)

        >>> limit_precision(coordinate, (0, 0, 0))
        Point(12.3456, 12.3456, 123.456)

        >>> limit_precision(coordinate, (None, None, None))
        Point(12.3456, 12.3456, 123.456)

    ... the given point returns unchanged.

    If we assign to the second parameter tuple some positive integers the given
    point will return with altered decimal places after the comma and rounding
    applied:

        >>> limit_precision(coordinate, (1, 1, 1))
        Point(12.3, 12.3, 123.5)

        >>> limit_precision(coordinate, (2, 2, 2))
        Point(12.35, 12.35, 123.46)

        >>> limit_precision(coordinate, (3, 3, 3))
        Point(12.346, 12.346, 123.456)

    Assigning negative integers to the second parameter tuple will return a
    point with altered decimal places before the comma and all decimal places
    cut after the comma:

        >>> limit_precision(coordinate, (-1, -1, -1))
        Point(10.0, 10.0, 120.0)

        >>> limit_precision(coordinate, (-2, -2, -2))
        Point(10.0, 10.0, 100.0)

    Mind that decimals with less digits than the given absolute precision, keep
    the last remaining digit intact.

        >>> limit_precision(coordinate, (-3, -3, -3))
        Point(10.0, 10.0, 100.0)

    The mathematical rounding can lead to unexpected results, if applied before
    the comma:

        >>> limit_precision(Point(65.4321, 65.4321, 654.321), (-1, -1, -1))
        Point(70.0, 70.0, 650.0)

        >>> limit_precision(Point(65.4321, 65.4321, 654.321), (-2, -2, -2))
        Point(70.0, 70.0, 700.0)

    """
    def _limit(value, precision):
        if 0 < precision:
            value = round(value, precision)
        elif 0 > precision:
            calculus = 10 ** (-1 * precision)
            if calculus < value:
                value = round(value / calculus) * calculus
            else:
                value = _limit(value, precision + 1)
        return value

    return Point(
        _limit(point[0], precisions[0] or 0),
        _limit(point[1], precisions[1] or 0),
        _limit(point[2], precisions[2] or 0)
    )

def add_vector(point, vector=(None, None, None)):
    """
    Masked points are displaced by a fixed vector, hence we move the point.

    If we define a coordinate like ...

        >>> coordinate = Point(12.3456, 12.3456, 12.3456)

    ... and call this function like ...

        >>> add_vector(coordinate)
        Point(12.3456, 12.3456, 12.3456)

        >>> add_vector(coordinate, (0, 0, 0))
        Point(12.3456, 12.3456, 12.3456)

        >>> add_vector(coordinate, (None, None, None))
        Point(12.3456, 12.3456, 12.3456)

    ... the given point returns unchanged.

    In all other cases the given point will be moved by the given values:

        >>> add_vector(coordinate, (1.0, 1.0, 1.0))
        Point(13.3456, 13.3456, 13.3456)

    Mind that geodesic points with latitude, longitude, and altitude are used.
    This results in points with limited value range, hence we rotate the points
    around the globe:

        >>> add_vector(coordinate, (100.0, 100.0, 100.0))
        Point(-67.65440000000001, 112.3456, 112.3456)

        >>> add_vector(coordinate, (-100.0, -100.0, -100.0))
        Point(-87.6544, -87.6544, -87.6544)

    """

    return Point(
        point[0] + (vector[0] or 0.0),
        point[1] + (vector[1] or 0.0),
        point[2] + (vector[2] or 0.0)
    )

def displace_on_a_circle(point, radius=0.0):
    """
    Masked points are placed on a random location on a circle around the
    original location.  Masked points are not placed inside the circle itself.

    If we define a coordinate like ...

        >>> coordinate = Point(0.0, 0.0, 0.0)

    ... and call this function without any radius ...

        >>> displace_on_a_circle(coordinate)
        Point(0.0, 0.0, 0.0)

        >>> displace_on_a_circle(coordinate, 0)
        Point(0.0, 0.0, 0.0)

        >>> displace_on_a_circle(coordinate, None)
        Point(0.0, 0.0, 0.0)

    ... the given point returns unchanged.

    With a given radius, a randomly circular displaced point will return.  That
    implies the altitude always remains untouched.  The given coodinates are
    the circle's center, the given radius is the distance between given and
    resulting coodinate:

        >>> displace_on_a_circle(coordinate, 1) # doctest: +ELLIPSIS
        Point(..., 0.0)

        >>> displace_on_a_circle(coordinate, -1) # doctest: +ELLIPSIS
        Point(..., 0.0)

        >>> random.seed(1)
        >>> displace_on_a_circle(coordinate, 1)
        Point(0.7474634341555553, 0.6643029539301958, 0.0)

    """

    if radius is None or radius is 0:
        return point
    elif 0 > radius:
        radius *= -1

    a = _random_angle_in_radians()
    x = math.cos(a) * radius
    y = math.sin(a) * radius

    # beware that longitude is x and latitude is y !
    return add_vector(point, (y, x, 0))

def displace_on_a_sphere(point, radius=0.0):
    """
    Masked points are placed on a random location on a sphere around the
    original location.  Masked points are not placed inside the sphere itself.

    If we define a coordinate like ...

        >>> coordinate = Point(0.0, 0.0, 0.0)

    ... and call this function without any radius ...

        >>> displace_on_a_sphere(coordinate)
        Point(0.0, 0.0, 0.0)

        >>> displace_on_a_sphere(coordinate, 0)
        Point(0.0, 0.0, 0.0)

        >>> displace_on_a_sphere(coordinate, None)
        Point(0.0, 0.0, 0.0)

    ... the given point returns unchanged.

    With a given radius, a randomly spherical displaced point will return.  The
    given coodinates are the sphere's center, the given radius is the distance
    between given and resulting coodinate:

        >>> displace_on_a_sphere(coordinate, 1) # doctest: +ELLIPSIS
        Point(...)

        >>> displace_on_a_sphere(coordinate, -1) # doctest: +ELLIPSIS
        Point(...)

        >>> random.seed(1)
        >>> displace_on_a_sphere(coordinate, 1)
        Point(-0.6117158867827159, -0.5436582607079324, 0.5746645712253897)

    """

    if radius is None or radius is 0:
        return point
    elif 0 > radius:
        radius *= -1

    a1 = _random_angle_in_radians()
    a2 = _random_angle_in_radians()
    x = math.cos(a1) * math.sin(a2) * radius
    y = math.sin(a1) * math.sin(a2) * radius
    z = math.cos(a2) * radius

    # beware that longitude is x and latitude is y !
    return add_vector(point, (y, x, z))

def displace_within_a_circle(point, radius=0.0):
    """
    Masked locations are placed anywhere within a circular area around the
    original location.  Since every location within the circle is equally
    likely, masked locations are more likely to be placed at larger distances
    compared to small distances.  A variation on this technique is the use of
    random direction and random radius.  In this technique, masked points are
    displaced using a vector with random direction and random radius.  The
    radius is constrained by a maximum value. This effectively results in a
    circular area where masked locations can be placed, but the masked
    locations are as likely to be at large distances compared to small
    distances.  These two techniques therefore only differ slightly in the
    probability of how close masked locations are placed to the original
    locations.

    If we define a coordinate like ...

        >>> coordinate = Point(0.0, 0.0, 0.0)

    ... and call this function without any radius ...

        >>> displace_within_a_circle(coordinate)
        Point(0.0, 0.0, 0.0)

        >>> displace_within_a_circle(coordinate, 0)
        Point(0.0, 0.0, 0.0)

        >>> displace_within_a_circle(coordinate, None)
        Point(0.0, 0.0, 0.0)

    ... the given point returns unchanged.

    With a given radius, a randomly circular displaced point will return.  That
    implies the altitude always remains untouched.  The given coodinates are
    the circle's center, the given radius is the maximum distance between given
    and resulting coodinate:

        >>> displace_within_a_circle(coordinate, 1) # doctest: +ELLIPSIS
        Point(..., 0.0)

        >>> displace_within_a_circle(coordinate, -1) # doctest: +ELLIPSIS
        Point(..., 0.0)

        >>> random.seed(1)
        >>> displace_within_a_circle(coordinate, 1)
        Point(-0.10996222555283103, 0.07721437073087664, 0.0)

    """

    if radius is None or radius is 0:
        return point
    elif 0 > radius:
        radius *= -1

    radius = random.uniform(0, radius)

    return displace_on_a_circle(point, radius)

def displace_within_a_sphere(point, radius=0.0):
    """
    Masked locations are placed anywhere within a spherical space around the
    original location.  Since every location within the sphere is equally
    likely, masked locations are more likely to be placed at larger distances
    compared to small distances.  A variation on this technique is the use of
    random direction and random radius.  In this technique, masked points are
    displaced using a vector with random direction and random radius.  The
    radius is constrained by a maximum value. This effectively results in a
    spherical space where masked locations can be placed, but the masked
    locations are as likely to be at large distances compared to small
    distances.  These two techniques therefore only differ slightly in the
    probability of how close masked locations are placed to the original
    locations.

    If we define a coordinate like ...

        >>> coordinate = Point(0.0, 0.0, 0.0)

    ... and call this function with any radius ...

        >>> displace_within_a_sphere(coordinate)
        Point(0.0, 0.0, 0.0)

        >>> displace_within_a_sphere(coordinate, 0)
        Point(0.0, 0.0, 0.0)

        >>> displace_within_a_sphere(coordinate, None)
        Point(0.0, 0.0, 0.0)

    ... the given point returns unchanged.

    With a given radius, a randomly spherical displaced point will return.  The
    given coodinates are the sphere's center, the given radius is the maximum
    distance between given and resulting coodinate:

        >>> displace_within_a_sphere(coordinate, 1) # doctest: +ELLIPSIS
        Point(...)

        >>> displace_within_a_sphere(coordinate, -1) # doctest: +ELLIPSIS
        Point(...)

        >>> random.seed(1)
        >>> displace_within_a_sphere(coordinate, 1)
        Point(0.10955063884671598, -0.07692535867829137, 0.011614508874230087)

    """

    if radius is None or radius is 0:
        return point
    elif 0 > radius:
        radius *= -1

    radius = random.uniform(0, radius)

    return displace_on_a_sphere(point, radius)

def displace_within_a_circular_donut(point,
                                     radius_inner=0.5,
                                     radius_outer=1.0):
    """
    This technique is similar to random displacement within a circle, but a
    smaller internal circle is utilized within which displacement is not
    allowed.  In effect, this sets a minimum and maximum level for the
    displacement.  Masked locations are placed anywhere within the allowable
    area.  A slightly different approach to donut masking is the use of a
    random direction and two random radii: one for maximum and one for minimum
    displacement.  These two techniques only differ slightly in the probability
    of how close masked locations are placed to the original locations.  Both
    approaches enforce a minimum amount of displacement.

    With a given radius, a randomly circular displaced point will return.  That
    implies the altitude always remains untouched.  The given coodinates are
    the circle's center, the given radii are the minimum and maximum distance
    between given and resulting coodinate:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> displace_within_a_circular_donut(coordinate)
        Point(-0.4641756357658914, 0.32593947097813314, 0.0)

        >>> random.seed(1)
        >>> displace_within_a_circular_donut(coordinate, 0.5, 1.0)
        Point(-0.4641756357658914, 0.32593947097813314, 0.0)

    """

    radius = random.uniform(radius_inner, radius_outer)

    return displace_on_a_circle(point, radius)

def displace_within_a_spherical_donut(point,
                                      radius_inner=0.5,
                                      radius_outer=1.0):
    """
    This technique is similar to random displacement within a sphere, but a
    smaller internal sphere is utilized within which displacement is not
    allowed.  In effect, this sets a minimum and maximum level for the
    displacement.  Masked locations are placed anywhere within the allowable
    space.  A slightly different approach to donut masking is the use of a
    random direction and two random radii: one for maximum and one for minimum
    displacement.  These two techniques only differ slightly in the probability
    of how close masked locations are placed to the original locations.  Both
    approaches enforce a minimum amount of displacement.

    With a given radius, a randomly spherical displaced point will return.  The
    given coodinates are the sphere's center, the given radii are the minimum
    and maximum distance between given and resulting coodinate:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> displace_within_a_spherical_donut(coordinate)
        Point(0.4624382343989833, -0.32471948518229893, 0.049027491156171304)

        >>> random.seed(1)
        >>> displace_within_a_spherical_donut(coordinate, 0.5, 1.0)
        Point(0.4624382343989833, -0.32471948518229893, 0.049027491156171304)

    """

    radius = random.uniform(radius_inner, radius_outer)

    return displace_on_a_sphere(point, radius)

def circular_gaussian_displacement(point, mu=1.0, sigma=1.0):
    """
    The direction of displacement is random, but the distance follows a
    Gaussian distribution, where `mu` is the mean and `sigma` is the standard
    deviation.  The dispersion of the distribution can be varied based on other
    parameters of interest, such as local population density.

    With a given radius, a randomly circular displaced point will return.  That
    implies the altitude always remains untouched.  The given coodinates are
    the circle's center:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> circular_gaussian_displacement(coordinate)
        Point(-2.279620117247094, 0.19779177337662887, 0.0)

        >>> random.seed(1)
        >>> circular_gaussian_displacement(coordinate, 1.0, 1.0)
        Point(-2.279620117247094, 0.19779177337662887, 0.0)

    """

    radius = random.gauss(mu, sigma)

    return displace_on_a_circle(point, radius)

def spherical_gaussian_displacement(point, mu=1.0, sigma=1.0):
    """
    The direction of displacement is random, but the distance follows a
    Gaussian distribution, where `mu` is the mean and `sigma` is the standard
    deviation.  The dispersion of the distribution can be varied based on other
    parameters of interest, such as local population density.

    With a given radius, a randomly spherical displaced point will return.  The
    given coodinates are the sphere's center:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> spherical_gaussian_displacement(coordinate)
        Point(-2.278463993019554, 0.19769146198725365, -0.07286551271936394)

        >>> random.seed(1)
        >>> spherical_gaussian_displacement(coordinate, 1.0, 1.0)
        Point(-2.278463993019554, 0.19769146198725365, -0.07286551271936394)

    """

    radius = random.gauss(mu, sigma)

    return displace_on_a_sphere(point, radius)

def circular_bimodal_gaussian_displacement(point,
                                           inner_mu=1.0,
                                           inner_sigma=1.0,
                                           outer_mu=2.0,
                                           outer_sigma=1.0):
    """
    This is a variation on the Gaussian masking technique, employing a bimodal
    Gaussian distribution for the random distance function.  In effect, this
    approximates donut masking, but with a less uniform probability of
    placement.

    With a given radius, a randomly circular displaced point will return.  That
    implies the altitude always remains untouched.  The given coodinates are
    the circle's center:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> circular_bimodal_gaussian_displacement(coordinate)
        Point(3.1735160345853632, -0.10110949606778825, 0.0)

        >>> random.seed(1)
        >>> circular_bimodal_gaussian_displacement(coordinate,
        ...                                        1.0, 1.0, 2.0, 1.0)
        Point(3.1735160345853632, -0.10110949606778825, 0.0)

    """

    inner_radius = random.gauss(inner_mu, inner_sigma)
    outer_radius = random.gauss(outer_mu, outer_sigma)

    return displace_within_a_circular_donut(point, inner_radius, outer_radius)

def spherical_bimodal_gaussian_displacement(point,
                                            inner_mu=1.0,
                                            inner_sigma=1.0,
                                            outer_mu=2.0,
                                            outer_sigma=1.0):
    """
    This is a variation on the Gaussian masking technique, employing a bimodal
    Gaussian distribution for the random distance function.  In effect, this
    approximates donut masking, but with a less uniform probability of
    placement.

    With a given radius, a randomly spherical displaced point will return.  The
    given coodinates are the sphere's center:

        >>> coordinate = Point(0.0, 0.0, 0.0)

        >>> random.seed(1)
        >>> spherical_bimodal_gaussian_displacement(coordinate)
        Point(0.09101092182341257, -0.002899644539981792, -3.173820372380246)

        >>> random.seed(1)
        >>> spherical_bimodal_gaussian_displacement(coordinate,
        ...                                         1.0, 1.0, 2.0, 1.0)
        Point(0.09101092182341257, -0.002899644539981792, -3.173820372380246)

    """

    inner_radius = random.gauss(inner_mu, inner_sigma)
    outer_radius = random.gauss(outer_mu, outer_sigma)

    return displace_within_a_spherical_donut(point, inner_radius, outer_radius)


text:
typedef struct _loopChunk {
    size_t startInclusive;
    size_t endExclusive;
} loopChunk;

static Realm::Processor aggregateCpu = Realm::Processor::NO_PROC;

enum {
    FLAT_TASK_ID = Realm::Processor::TASK_ID_FIRST_AVAILABLE + 0,
    RECURSIVE_TASK_ID
};

static void processLoopChunk(const size_t startInclusive,
        const size_t endExclusive) {
    size_t i;
    for (i = startInclusive; i < endExclusive; i++) {
        ;
    }
}

static void flatTask(const void *args, size_t arglen, const void *userdata,
        size_t userlen, Realm::Processor p) {
    assert(arglen == sizeof(loopChunk));
    loopChunk *chunk = (loopChunk *)args;
    processLoopChunk(chunk->startInclusive, chunk->endExclusive);
}

static void recursiveTask(const void *args, size_t arglen, const void *userdata,
        size_t userlen, Realm::Processor p) {
    assert(arglen == sizeof(loopChunk));
    loopChunk *chunk = (loopChunk *)args;
    size_t span = chunk->endExclusive - chunk->startInclusive;

    if (span <= LOOP_TILE) {
        processLoopChunk(chunk->startInclusive, chunk->endExclusive);
    } else {
        loopChunk lowChunk, highChunk;
        lowChunk.startInclusive = chunk->startInclusive;
        lowChunk.endExclusive = chunk->startInclusive + (span / 2);
        highChunk.startInclusive = lowChunk.endExclusive;
        highChunk.endExclusive = chunk->endExclusive;

        Realm::Event e1 = aggregateCpu.spawn(RECURSIVE_TASK_ID, &lowChunk,
                sizeof(lowChunk));
        Realm::Event e2 = aggregateCpu.spawn(RECURSIVE_TASK_ID, &highChunk,
                sizeof(highChunk));
        Realm::Event merged = Realm::Event::merge_events(e1, e2);
        merged.wait();
    }
}

static int collect_cpus(std::vector<Realm::Processor> &all_cpus) {
    std::set<Realm::Processor> all_procs;
    Realm::Machine::get_machine().get_all_processors(all_procs);

    int count_cpus = 0;
    for (std::set<Realm::Processor>::iterator i = all_procs.begin(),
            e = all_procs.end(); i != e; i++) {
        Realm::Processor curr = *i;
        if (curr.kind() == Realm::Processor::LOC_PROC) {
            all_cpus.push_back(curr);
            count_cpus++;
        }
    }

    return count_cpus;
}

int main(int argc, char **argv) {
    Realm::Runtime runtime;
    std::vector<Realm::Processor> all_cpus;
    runtime.init(&argc, &argv);
    runtime.register_task(FLAT_TASK_ID, flatTask);
    runtime.register_task(RECURSIVE_TASK_ID, recursiveTask);

    int count_cpus = collect_cpus(all_cpus);
    printf("Using %d Realm threads\n", count_cpus);
    aggregateCpu = Realm::Processor::create_group(all_cpus);

    const unsigned long long flat_start_time = current_time_ns();
    std::set<Realm::Event> flatEvents;
    size_t i;
    for (i = 0; i < PARALLEL_LOOP_RANGE; i += LOOP_TILE) {
        loopChunk chunk;
        chunk.startInclusive = i;
        chunk.endExclusive = i + LOOP_TILE;
        if (chunk.endExclusive > PARALLEL_LOOP_RANGE) {
            chunk.endExclusive = PARALLEL_LOOP_RANGE;
        }
        flatEvents.insert(aggregateCpu.spawn(FLAT_TASK_ID, &chunk, sizeof(chunk)));
    }
    Realm::Event flatMerged = Realm::Event::merge_events(flatEvents);
    flatMerged.external_wait();
    const unsigned long long flat_end_time = current_time_ns();
    printf("METRIC flat_parallel_iters %d %.20f\n", PARALLEL_LOOP_RANGE,
            (double)PARALLEL_LOOP_RANGE / ((double)(flat_end_time -
                    flat_start_time) / 1000.0));

    const unsigned long long recursive_start_time = current_time_ns();
    loopChunk recursiveChunk;
    recursiveChunk.startInclusive = 0;
    recursiveChunk.endExclusive = PARALLEL_LOOP_RANGE;
    Realm::Event e = aggregateCpu.spawn(RECURSIVE_TASK_ID, &recursiveChunk,
            sizeof(recursiveChunk));
    e.external_wait();
    const unsigned long long recursive_end_time = current_time_ns();
    printf("METRIC recursive_parallel_iters %d %.20f\n", PARALLEL_LOOP_RANGE,
            (double)PARALLEL_LOOP_RANGE / ((double)(recursive_end_time -
                    recursive_start_time) / 1000.0));

    runtime.shutdown();
    runtime.wait_for_shutdown();

    return 0;
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.activemq.openwire.v6;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.activemq.openwire.*;
import org.apache.activemq.command.*;

/**
 * Test case for the OpenWire marshalling for ControlCommand
 *
 *
 * NOTE!: This file is auto generated - do not modify!
 *        if you need to make a change, please see the modify the groovy scripts in the
 *        under src/gram/script and then use maven openwire:generate to regenerate
 *        this file.
 *
 *
 */
public class ControlCommandTest extends BaseCommandTestSupport {

    public static ControlCommandTest SINGLETON = new ControlCommandTest();

    public Object createObject() throws Exception {
        ControlCommand info = new ControlCommand();
        populateObject(info);
        return info;
    }

    protected void populateObject(Object object) throws Exception {
        super.populateObject(object);
        ControlCommand info = (ControlCommand) object;

        info.setCommand("Command:1");
    }
}


text:
package org.apache.commons.collections4;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections4.bag.HashBag;
import org.apache.commons.collections4.multimap.MultiValuedHashMap;
import org.apache.commons.collections4.multimap.TransformedMultiValuedMap;
import org.apache.commons.collections4.multimap.UnmodifiableMultiValuedMap;

/**
 * Provides utility methods and decorators for {@link MultiValuedMap} instances.
 *

 * It contains various type safe and null safe methods.
 *

 * It also provides the following decorators:
 *
 *

 *
{@link #unmodifiableMultiValuedMap(MultiValuedMap)}

 *
{@link #transformedMultiValuedMap(MultiValuedMap, Transformer, Transformer)}

 *

 *
 * @since 4.1
 * @version $Id$
 */
public class MultiMapUtils {

    /**
     * MultiMapUtils should not normally be instantiated.
     */
    private MultiMapUtils() {
    }

    /**
     * An empty {@link UnmodifiableMultiValuedMap}.
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static final MultiValuedMap EMPTY_MULTI_VALUED_MAP =
            UnmodifiableMultiValuedMap.unmodifiableMultiValuedMap(new MultiValuedHashMap());

    /**
     * Returns immutable EMPTY_MULTI_VALUED_MAP with generic type safety.
     *
     * @param <K> the type of key in the map
     * @param <V> the type of value in the map
     * @return immutable and empty MultiValuedMap
     */
    @SuppressWarnings("unchecked")
    public static <K, V> MultiValuedMap<K, V> emptyMultiValuedMap() {
        return EMPTY_MULTI_VALUED_MAP;
    }

    // Null safe methods

    /**
     * Returns an immutable empty MultiValuedMap if the argument is
     * null, or the argument itself otherwise.
     *
     * @param <K> the type of key in the map
     * @param <V> the type of value in the map
     * @param map the map, possibly null
     * @return an empty MultiValuedMap if the argument is null
     */
    @SuppressWarnings("unchecked")
    public static <K, V> MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map) {
        return map == null ? EMPTY_MULTI_VALUED_MAP : map;
    }

    /**
     * Null-safe check if the specified MultiValuedMap is empty.
     *

     * Null returns true.
     *
     * @param map the map to check, may be null
     * @return true if empty or null
     */
    public static boolean isEmpty(final MultiValuedMap<?, ?> map) {
        return map == null || map.isEmpty();
    }

    // Null safe getters
    // -------------------------------------------------------------------------

    /**
     * Gets a Collection from MultiValuedMap in a null-safe manner.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to use
     * @param key the key to look up
     * @return the Collection in the MultiValuedMap, null if map input is null
     */
    public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) {
        if (map != null) {
            return map.get(key);
        }
        return null;
    }

    /**
     * Gets a List from MultiValuedMap in a null-safe manner.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to use
     * @param key the key to look up
     * @return the Collection in the MultiValuedMap as List,
     *         null if map input is null
     */
    public static <K, V> List<V> getList(MultiValuedMap<K, V> map, K key) {
        if (map != null) {
            Collection<V> col = map.get(key);
            if (col instanceof List) {
                return (List<V>) col;
            }
            return new ArrayList<V>(col);
        }
        return null;
    }

    /**
     * Gets a Set from MultiValuedMap in a null-safe manner.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to use
     * @param key the key to look up
     * @return the Collection in the MultiValuedMap as Set,
     *         null if map input is null
     */
    public static <K, V> Set<V> getSet(MultiValuedMap<K, V> map, K key) {
        if (map != null) {
            Collection<V> col = map.get(key);
            if (col instanceof Set) {
                return (Set<V>) col;
            }
            return new HashSet<V>(col);
        }
        return null;
    }

    /**
     * Gets a Bag from MultiValuedMap in a null-safe manner.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to use
     * @param key the key to look up
     * @return the Collection in the MultiValuedMap as Bag,
     *         null if map input is null
     */
    public static <K, V> Bag<V> getBag(MultiValuedMap<K, V> map, K key) {
        if (map != null) {
            Collection<V> col = map.get(key);
            if (col instanceof Bag) {
                return (Bag<V>) col;
            }
            return new HashBag<V>(col);
        }
        return null;
    }

    // Factory Methods
    // -----------------------------------------------------------------------

    /**
     * Creates a {@link ListValuedMap} with a {@link java.util.HashMap HashMap} as its internal storage.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @return a new ListValuedMap
     */
    public static <K, V> ListValuedMap<K, V> createListValuedHashMap() {
        return MultiValuedHashMap.<K, V>listValuedHashMap();
    }

    /**
     * Creates a {@link ListValuedMap} with a {@link java.util.HashMap HashMap} as its internal
     * storage which maps the keys to list of type listClass.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param <C> the List class type
     * @param listClass the class of the list
     * @return a new ListValuedMap
     */
    public static <K, V, C extends List<V>> ListValuedMap<K, V> createListValuedHashMap(final Class<C> listClass) {
        return MultiValuedHashMap.<K, V, C>listValuedHashMap(listClass);
    }

    /**
     * Creates a {@link SetValuedMap} with a {@link java.util.HashMap HashMap} as its internal
     * storage
     *
     * @param <K> the key type
     * @param <V> the value type
     * @return a new SetValuedMap
     */
    public static <K, V> SetValuedMap<K, V> createSetValuedHashMap() {
        return MultiValuedHashMap.<K, V>setValuedHashMap();
    }

    /**
     * Creates a {@link SetValuedMap} with a {@link java.util.HashMap HashMap} as its internal
     * storage which maps the keys to a set of type setClass
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param <C> the Set class type
     * @param setClass the class of the set
     * @return a new SetValuedMap
     */
    public static <K, V, C extends Set<V>> SetValuedMap<K, V> createSetValuedHashMap(final Class<C> setClass) {
        return MultiValuedHashMap.<K, V, C>setValuedHashMap(setClass);
    }

    // MultiValuedMap Decorators
    // -----------------------------------------------------------------------

    /**
     * Returns an UnmodifiableMultiValuedMap backed by the given
     * map.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to make unmodifiable, must not
     *        be null
     * @return an UnmodifiableMultiValuedMap backed by the given
     *         map
     * @throws IllegalArgumentException if the map is null
     */
    public static <K, V> MultiValuedMap<K, V> unmodifiableMultiValuedMap(
            final MultiValuedMap<? extends K, ? extends V> map) {
        return UnmodifiableMultiValuedMap.<K, V>unmodifiableMultiValuedMap(map);
    }

    /**
     * Returns a TransformedMultiValuedMap backed by the given map.
     *

     * This method returns a new MultiValuedMap (decorating the
     * specified map) that will transform any new entries added to it. Existing
     * entries in the specified map will not be transformed. If you want that
     * behaviour, see {@link TransformedMultiValuedMap#transformedMap}.
     *

     * Each object is passed through the transformers as it is added to the Map.
     * It is important not to use the original map after invoking this method,
     * as it is a back door for adding untransformed objects.
     *

     * If there are any elements already in the map being decorated, they are
     * NOT transformed.
     *
     * @param <K> the key type
     * @param <V> the value type
     * @param map the MultiValuedMap to transform, must not be
     *        null, typically empty
     * @param keyTransformer the transformer for the map keys, null means no
     *        transformation
     * @param valueTransformer the transformer for the map values, null means no
     *        transformation
     * @return a transformed MultiValuedMap backed by the given map
     * @throws IllegalArgumentException if the MultiValuedMap is
     *         null
     */
    public static <K, V> MultiValuedMap<K, V> transformedMultiValuedMap(final MultiValuedMap<K, V> map,
            final Transformer<? super K, ? extends K> keyTransformer,
            final Transformer<? super V, ? extends V> valueTransformer) {
        return TransformedMultiValuedMap.transformingMap(map, keyTransformer, valueTransformer);
    }

}


text:
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEveCharacterMailingLists extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('character_mailinglists', function(Blueprint $table)
		{
		  $table->increments('id');

		  $table->integer('characterID');
		  $table->integer('listID');
		  $table->string('displayName');

		  // Indexes
		  $table->index('characterID');
		  $table->index('listID');

		  $table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists('character_mailinglists');
	}

}


text:
Ext.define("adnat.view.Contact", {
    extend: 'Ext.form.Panel',
    xtype: 'contact',
    requires: [
        'Ext.TitleBar',
        'adnat.model.ContactRequest'
    ],
    config: {
        id: 'contact',
        title: 'Contact',
        iconCls: 'reply',
        styleHtmlContent: true,
        scrollable: true,
        defaults: {
            required: true
        },
        layout: {
            type: 'vbox',
            pack: 'top'
        },
        items: [
            {
                docked: 'top',
                xtype: 'titlebar',
                title: 'Contact ADNAT'
            },
            {
                xtype: 'fieldset',
                title: 'Contact ADNAT Support',
                items: [
                    {
                        xtype: 'textfield',
                        label: 'Name',
                        name: 'name'
                    },
                    {
                        xtype: 'emailfield',
                        label: 'Email',
                        name: 'email'

                    },
                    {
                        xtype: 'textareafield',
                        label: 'Message',
                        name: 'message'
                    }
                ]
            },
            {
                xtype: 'button',
                text: 'Send',
                ui: 'action',
                handler: function() {
                    var contactRequest = Ext.ModelMgr.create(this.up('panel').getValues(), 'adnat.model.ContactRequest');
                    var errors = contactRequest.validate();
                    if (errors.isValid()) {
                        if (window.navigator.onLine) {
                            contactRequest.set('userToken', AppAuth.getToken());
                            contactRequest.save();
                            this.up('panel').reset();
                            Ext.Msg.alert("Thank You", "Thank you, we will contact you within 24 hours.
If you are having an emergency, please contact your doctor or the emergency room.");
                        } else {
                            Ext.Msg.alert(
                                    "Internet Connection Required",
                                    "You are not online, please get an internet connection working and try to send your message again"
                                    );
                        }
                    } else {
                        log(errors);
                        var data = "";
                        errors.each(function(item, index, length) {
                            data = data + item.getMessage() + '
';
                        });
                        Ext.Msg.alert("Please check your information", data);
                    }
                }
            }
        ]
    }
});


text:
module VagrantPlugins
  module CookbookFetcher
    class Config < Vagrant.plugin("2", :config)
      attr_accessor :url
      attr_accessor :disable

      def initialize
        super
        @url     = UNSET_VALUE
        @disable = UNSET_VALUE
      end

      def finalize!
        if Vagrant.has_plugin?('vagrant-berkshelf')
          # TODO: would ideally detect whether berkshelf is actually enabled
          # TODO: this ui call seems to alkways get swallowed
          ui.info('vagrant-berkshelf detected, disabling vagrant-cookbook-fetcher')
          @disable = true
        else
          @disable = false if @disable == UNSET_VALUE
        end
      end

      def validate(machine)
        errors = []
        if @url == UNSET_VALUE
          # Disable vagrant cookbook fetcher if we don't specify a URL
          @disable = true
        end

        { 'Cookbook Fetcher' => errors }
      end

    end
  end
end


text: Answers to leetcode.com


text:
<!doctype html>

    <meta charset="utf-8">
    <title>React React-router Redux Webpack App</title>


text:
// Missing functions for using hwcrypto.js library

function checkEstIdPlugin(cb) {
  hwcrypto.use("chrome").then(function(result) {
    if (!result) {
      return tryNpapi();
    }
    hwcrypto.debug().then(function(result) {
      if (-1 !== result.indexOf('failing')) {
        return tryNpapi();
      }
      cb(true);
    });
  });
  function checkNavigatorPlugin(mimeType) {
    if (!navigator || !navigator.plugins) {
      return false;
    }
    for (var i = 0; i < navigator.plugins.length; i++) {
      if (navigator.plugins[i]['0'] && navigator.plugins[i]['0'].type === mimeType) {
        return true;
      }
    }
    return false;
  }
  function tryNpapi() {
    var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    if (!isChrome || checkNavigatorPlugin('application/x-digidoc')) {
      hwcrypto.use("npapi").then(cb);
    } else {
      cb(false);
    }
  }
}

function _hex2array(str) {
  if (typeof str == "string") {
    var ret = new Uint8Array(Math.floor(str.length / 2));
    var i = 0;
    str.replace(/(..)/g, function(str) {
      ret[i++] = parseInt(str, 16);
    });
    return ret;
  }
}

function _array2hex(args) {
  var ret = "";
  for (var i = 0; i < args.length; i++) ret += (args[i] < 16 ? "0" : "") + args[i].toString(16);
  return ret;
}

function hex2char(hex) {
  hex = hex.match(/[0-9a-f]{2}/igm);
  if (!hex) { return ""; }

  hex = hex.map(function(el){
    return String.fromCharCode(parseInt(el,16));
  });
  return hex.join("");
}

function hex2b64(hex) {
  return btoa(hex2char(hex));
}

function toCertFormat(data) {
  data = hex2b64(data);
  var lineLength = 64;
  var result = "-----BEGIN CERTIFICATE-----\n";
  for (var i = 0; i < data.length; i += lineLength) {
    result += i >= data.length - lineLength ? data.substring(i) : data.substring(i, i + lineLength) + "\n";
  }
  result += "\n-----END CERTIFICATE-----";
  return result;
}


text:
package com.tle.common.scripting.types;

/** A collection type for use in scripts */
public interface CollectionScriptType extends BaseEntityScriptType {
  /**
   * @return The number of item views this collection has had, proided the current user has
   *     permissions. Otherwise will return null.
   */
  Integer getItemViewCount();

  /**
   * @return The number of attachment views this collection has had, proided the current user has
   *     permissions. Otherwise will return null.
   */
  Integer getAttachmentViewCount();
}


text:
package mskubilov.notifywait;

/**
 * //курс Петра Арсентьева job4j.ru.
 *
 * @author Maksim Skubilov skubilov89@yandex.ru
 * @version 1.0
 * @since 05.06.17
 */

public class MyReentrantLock {

    /**
     * Lock's condition.
     */
    private boolean isLocked = false;
    /**
     * Count of locks by same thread.
     */
    private int lockCount = 0;
    /**
     * Thread trying to lock the Lock.
     */
    private Thread lockThread;

    /**
     * Method locks the Lock.
     */
    public synchronized void lock() {
        while (isLocked && Thread.currentThread() != lockThread) {
            try {
                System.out.printf("%s awaits for unlock\n", Thread.currentThread().getName());
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        isLocked = true;
        lockCount++;
        lockThread = Thread.currentThread();
    }

    /**
     * Method unlocks the Lock.
     */
    public synchronized void unlock() {
        lockCount--;
        if (lockCount == 0) {
            isLocked = false;
            System.out.printf("Lock is unlocked by %s\n", Thread.currentThread().getName());
            notify();
        }
    }
}


text:
angular.module('carlpad')
	.directive('cpComportConfiguration', ['$rootScope', 'serialService', 'gamepadService',
	function ($rootScope, serialService, gamepadService) {
		return {
			templateUrl: 'script/comport/comport-configuration.html',
			link: function (scope) {
				scope.comPorts = [];
				scope.bitRates = [110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200];

				scope.selectedComPort = null;
				scope.selectedBitRate = 9600;

				var outputBufferSize = 1000;

				scope.getConnectClass = function () {
					if (!!scope.selectedBitRate && !!scope.selectedComPort && serialService.getConnectionState() === 'disconnected') {
						return 'btn-success';
					} else return 'disabled';
				};

				scope.getDisconnectClass = function () {
					if (serialService.getConnectionState() === 'connected') {
						return 'btn-danger';
					} else return 'disabled';
				};

				scope.getPanelClass = function () {
					var currentState = serialService.getConnectionState();
					if (currentState === 'connected' || currentState === 'disconnecting') {
						return 'panel-success';
					}
					return 'panel-danger';
				};

				scope.connect = function () {
					serialService.connect(scope.selectedComPort.path, scope.selectedBitRate);
				};

				scope.disconnect = function () {
					serialService.disconnect();
				};

				scope.getState = function () {
					return serialService.getConnectionState();
				};

				serialService.getDevices().then(function (devices) {
					scope.comPorts.length = 0;
					devices.forEach(function (device) {
						scope.comPorts.push(device);
					});
				});
			}
		};
	}
]);


text:
 <title>Ruby</title>

 <para>
  There currently is support to bundle applications that are packaged as Ruby
  gems. The utility "bundix" allows you to write a
  <filename>Gemfile</filename>, let bundler create a
  <filename>Gemfile.lock</filename>, and then convert this into a nix
  expression that contains all Gem dependencies automatically.
 </para>

 <para>
  For example, to package sensu, we did:
 </para>

<screen>
<![CDATA[$ cd pkgs/servers/monitoring
$ mkdir sensu
$ cd sensu
$ cat > Gemfile
source 'https://rubygems.org'
gem 'sensu'
$ $(nix-build '<nixpkgs>' -A bundix --no-out-link)/bin/bundix --magic
$ cat > default.nix
{ lib, bundlerEnv, ruby }:

bundlerEnv rec {
  name = "sensu-${version}";

  version = (import gemset).sensu.version;
  inherit ruby;
  # expects Gemfile, Gemfile.lock and gemset.nix in the same directory
  gemdir = ./.;

  meta = with lib; {
    description = "A monitoring framework that aims to be simple, malleable, and scalable";
    homepage    = http://sensuapp.org/;
    license     = with licenses; mit;
    maintainers = with maintainers; [ theuni ];
    platforms   = platforms.unix;
  };
}]]>
</screen>

 <para>
  Please check in the <filename>Gemfile</filename>,
  <filename>Gemfile.lock</filename> and the <filename>gemset.nix</filename> so
  future updates can be run easily.
 </para>

 <para>
  Updating Ruby packages can then be done like this:
 </para>

<screen>
<![CDATA[$ cd pkgs/servers/monitoring/sensu
$ nix-shell -p bundler --run 'bundle lock --update'
$ nix-shell -p bundix --run 'bundix'
]]>
</screen>

 <para>
  For tools written in Ruby - i.e. where the desire is to install a package and
  then execute e.g. <command>rake</command> at the command line, there is an
  alternative builder called <literal>bundlerApp</literal>. Set up the
  <filename>gemset.nix</filename> the same way, and then, for example:
 </para>

<screen>
<![CDATA[{ lib, bundlerApp }:

bundlerApp {
  pname = "corundum";
  gemdir = ./.;
  exes = [ "corundum-skel" ];

  meta = with lib; {
    description = "Tool and libraries for maintaining Ruby gems.";
    homepage    = https://github.com/nyarly/corundum;
    license     = licenses.mit;
    maintainers = [ maintainers.nyarly ];
    platforms   = platforms.unix;
  };
}]]>
</screen>

 <para>
  The chief advantage of <literal>bundlerApp</literal> over
  <literal>bundlerEnv</literal> is the executables introduced in the
  environment are precisely those selected in the <literal>exes</literal> list,
  as opposed to <literal>bundlerEnv</literal> which adds all the executables
  made available by gems in the gemset, which can mean e.g.
  <command>rspec</command> or <command>rake</command> in unpredictable versions
  available from various packages.
 </para>

 <para>
  Resulting derivations for both builders also have two helpful attributes,
  <literal>env</literal> and <literal>wrappedRuby</literal>. The first one
  allows one to quickly drop into <command>nix-shell</command> with the
  specified environment present. E.g. <command>nix-shell -A sensu.env</command>
  would give you an environment with Ruby preset so it has all the libraries
  necessary for <literal>sensu</literal> in its paths. The second one can be
  used to make derivations from custom Ruby scripts which have
  <filename>Gemfile</filename>s with their dependencies specified. It is a
  derivation with <command>ruby</command> wrapped so it can find all the needed
  dependencies. For example, to make a derivation <literal>my-script</literal>
  for a <filename>my-script.rb</filename> (which should be placed in
  <filename>bin</filename>) you should run <command>bundix</command> as
  specified above and then use <literal>bundlerEnv</literal> like this:
 </para>

<programlisting>
<![CDATA[let env = bundlerEnv {
  name = "my-script-env";

  inherit ruby;
  gemfile = ./Gemfile;
  lockfile = ./Gemfile.lock;
  gemset = ./gemset.nix;
};

in stdenv.mkDerivation {
  name = "my-script";
  buildInputs = [ env.wrappedRuby ];
  script = ./my-script.rb;
  buildCommand = ''
    install -D -m755 $script $out/bin/my-script
    patchShebangs $out/bin/my-script
  '';
}]]>
</programlisting>


text:
Remove custom allocation function overrides from core surface API
----
* Author(s): veblush
* Approver: mark
* Status: Approved
* Implemented in: https://github.com/grpc/grpc/pull/20462
* Last updated: 2019-10-09
* Discussion at: https://groups.google.com/forum/#!topic/grpc-io/kDswzg-cEZU

## Abstract

Remove `gpr_get_allocation_functions` and `gpr_set_allocation_functions`
from the core surface API.

## Background

Since gRPC Core was allowed to use the C++ standard library, it's getting
harder to keep using the gRPC allocator which can be overriden by users.
Previously, it was fairly straightforward to use a family of gpr memory
allocation functions such as `gpr_malloc` and `gpr_free` because most of
the code was written in C language.
Once C++ started being used heavily, however, using it makes code harder to
read and sometimes impossible to do it.
Instead of maintaining these functions, this proposes to remove them.

### Related Proposals:

N/A

## Proposal

Following functions managing custom memory allocator will be removed.

- `gpr_get_allocation_functions`
- `gpr_set_allocation_functions`

gRPC memory allocation functions such as `gpr_malloc` and `gpr_free` will
remain with this change because they have been used when data allocated in
user applications is passed into gRPC Core such as `metadata`.

## Rationale

C++ provides a way to use a custom memory allocator but it usually requires to
enter more code and makes it harder to read.

This is an example of how this looks like with an allocator.

```
// New<T> allocates memory with custom allocator and calls constructor of T.
auto a = New<SomeClass>(obj);

// Delete<T> calls destructor of T and frees the memory associated with it.
Delete<SomeClass>(a)

// All container classes should be instantiated with a custom allocator.
std::map<int, std::string, Allocator<std::pair<const int, std::string>>> m;

// unique_ptr should carry special Delete function to use an allocator.
grpc_core::UniquePtr<char> a = grpc_core::MakeUnique<char>("a");
```

This can be simplified by not supporting a custom allocator. Note that the
standard way of using`delete` doesn't mandate to specify the type of instance
 unlike `gprc_core::Delete`.

```
// plain new
auto a = new SomeClass(obj);

// plain delete
delete a;

// plain map
std::map<int, std::string>

// plain unique_ptr
std::unique_ptr<char> p = std::make_unique<char>("a");
```

In addition to this, some of C++ libraries cannot use custom allocators.
For example, `std::function` doesn't support an allocator. Moreover,
none of gRPC wrapped libraries including gRPC C++ doesn't support this.
As a result, memory allocation can be done either in a built-in allocator
or a custom allocator. This can be misleading to developers.

## Implementation

Core: https://github.com/grpc/grpc/pull/20462

## Open issues (if applicable)

N/A


text:
<?php

/**
 * Texy! modules base class.
 *
 * @author     David Grudl
 * @copyright  Copyright (c) 2004, 2009 David Grudl
 * @package    Texy
 */
abstract class TexyModule extends TexyObject
{
	/** @var Texy */
	protected $texy;

}


text:
sudo yum install -y mysql mysql-server mysql-devel
sudo chkconfig --add mysqld
sudo chkconfig mysqld on

sudo service mysqld start


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<title>/5776$10</title>

TACC HPC Python  October 30, 2014 9:00am - 12:00pm

Welcome!
Please submit questions at the bottom of this page.
loud and clear

'cp:missing destination file operand after '/home1/..../python-hpc.tar.gz
Can you tell what I'm doing wrong?
Nevermind. No . after command

Hello. Someone there?
Hello.
I'm not able to submit an interactive job to the TACC-HPC-PYTHON account:
User dssussx is not associated with project TACC-HPC-PYTHON (in accounting_check_prod.pl).
Online users may use a regular idev session.
The TACC-HPC-PYTHON account is reserved for local users only.

What do we do after we log in?
module load intel/14.0.1.106
module load python/2.7.6
and "cp ~train00/python-hpc.tar.gz ."

With idev command:
Please report this problem:
what problem?
U. of TX users contact (https://portal.tacc.utexas.edu/consulting)
XSEDE    users contact (https://portal.xsede.org/group/xup/help-desk).
FAILED
What command are you attempting? Just "idev"?

What do we do after "cp ~train00/python-hpc.tar.gz"?
tar -xzf python-hpc.tar.gz
I got this error:
login4.stampede(7)$ tar -fxz python-hpc.tar.gz
try "tar -xzf python-hpc.tar.gz"
(I'm quite surprised that the sequence of options makes a difference)
tar: You must specify one of the `-Acdtrux' or `--test-label'  options
Try `tar --help' or `tar --usage' for more information.
login4.stampede(8)$
Are we just trying to untar this file?
Yes.
Okay. I will look online for how to do this.

I used srun instead of idev to get a compute node. Is that okay?
That should be okay.

Can the speaker move his terminal window down? I want to see the top of the current slide. I believe it shows us how to run the job. Is this correct? Are we running profiling.py?
python -m cProfile profiling.py

The slides should be available online:
https://www.tacc.utexas.edu/user-services/training/hpc-python
I found them!!

I get a ERROR: Cell magic `%%cython` not found.
How did you start your ipython session?
did you do the "%load_ext"?
(and on what machine are you?)
let me try again
yeah load_ext solved ti

Not sure what to do here:
login4.stampede(38)$ icc -shared -fPIC -03 myfunc -o myfun1.so -I$TACC_PYTHON_INC/python2.7/
icc: command line warning #10006: ignoring unknown option '-03'
That's a letter Oh, not digit zero
icc: error #10236: File not found:  'myfunc'
you forgot the ".c" extension
icc: command line error: no files specified; for help type "icc -help"
login4.stampede(39)$
Same error. Where did myfunc1.c come from?
from the command "cython myfunc1.pyx" (thankyou) (I missed that)
I retried it b/c I had a typo. Here's what I got:
login4.stampede(40)$ icc -shared -fPIC -03 myfunc1.c -o myfun1.so -I$TACC_PYTHON_INC/python2.7/
icc: command line warning #10006: ignoring unknown option '-03'
letter Oh, not digit zero: -03 vs -O3

whats inside $TACC_PYTHON_INC/python2.7/
just "ls" it.
my times are greater than what you get
on stampede? do you at least get an improvement in the same way as the teacher?
By how much?
almost twice
let me check on the improvement
I should compare test_python vs test_cython right?

Thanks for the link to the tutorial!

Okay I can do the cython myfunc3.pyx and the icc line without error. I generate an executable "myfunc3", but when I do "python test_cython3.py" I get an error:
"Import error: no module named myfunc3"
Any idea?
I guess the .so files are not being generated
I might have missed the part where he said how to do that
Are you compiling the way that Antonio shows on the slides?
I do the line starting with cython then the line starting with icc verbatim. Then python test_whatever
Hmm. So the .so is being generated, but then the function call in test_cython3.py cannot find it?
are you getting any errors? do a cut/paste of your terminal session.
here's how it works for me:
1. run cython:
cython myfunc3.pyx
login4.stampede(29)$ ls
myfunc1.pyx  myfunc2.pyx  myfunc3.c  myfunc3.pyx
2. compile:
icc -fPIC -shared myfunc3.c -o myfunc3.so -I$TACC_PYTHON_INC/python2.7
login4.stampede(33)$ python test_cython3.py
7.4535600368e+13

So if I want to do this using my own python installation what would I give for TACC_PYTHON_INC/python2.7/
hm. do "find / -name cellobject.h"
that's the directory you need.
This is the include directory for your particular version of Python.
thanks

What is mean by broadcasting again?
This is referring to sending/receiving variables within an MPI enabled code.
Different MPI tasks each have unique values for variables within an MPI code.
Broadcast is a way to send to each task a value(s) to other tasks.
More about this later in Antonio's presentation.
Thanks.

What is meant by MIC? Using the MIC?
Many Integrated Cores
That's another name fr the Intel Xeon Phi co-processor
on the stampede nodes
Thanks for explaining that.

Since we can't use the MIC on the Login node, how do we get off the login node, or can we?
start an idev session: that puts you on a compute node, and they all have a MIC
(idev usually starts in the development queue; you can also use the normal-mic queue)
Okay then. Thanks!

How do you decide on 240 as a number for MIC_OMP_NUM_THREADS
60 cores times 4 threads
But a node has only 16 cores ?
The node has 2 sandybridges of 8 cores, correct.
The MIC is a separate co-processor; it has 60 cores
note the variable name MIC_OMP_NUM_THREADS, as opposed to OMP_NUM_THREADS

My time did not improve on that last example. I don't know why?
what is the output of "hostname -a"?
login4.stampede(77)$ hostname -a
login4
You need to be on a compute node in order to use a MIC.
Please refrain from running this code on the login node -- it will affect performance for other users.
same here no improvement hostname c559-101
Try turning on the offload report environment variable to see if you are actually offloading.
export OFFLOAD_REPORT=2
If you are offloading while running your code, you will receive extra output telling you.
Do you see this when you run?
No I donot see extra output
Can you double check your environment variables and their values?
sure
export MKL_MIC_ENABLE=1
export OMP_NUM_THREADS=16
export MIC_OMP_NUM_THREADS=240
export OFFLOAD_REPORT=2
echo $OMP_NUM_THREADS $MKL_MIC_ENABLE $MIC_OMP_NUM_THREADS $OFFLOAD_REPORT
16 1 240 2
Yeah they are all there
Would please output which modules you are using with "module list"?
Currently Loaded Modules:
  1) TACC-paths   3) cluster-paths   5) cluster   7) intel/13.0.2.146   9) fftw3/3.3.2
  2) Linux        4) xalt/0.4.6      6) TACC      8) mvapich2/1.9a2

Inactive Modules:
  1) python/2.7.6
Ahhh
:-) You need to load intel/14 to get the MIC enabled python/2.7.6.
Let me know if that works out.
Yeah worked out
Great!

I did not get output here.
login4.stampede(75)$ python basic_1.py
[....]
_tkinter.TclError: no display name and no $DISPLAY environment variable
login4.stampede(76)$
when you connected to stampede, did you use ssh -X ? And do you have a X11 manager on your local computer?
I did not use ssh -X. I used ssh username@login.xsede.org I don't know if I have an X11 manager. I'm using a laptop with Ubuntu. If you have Ubuntu using ssx -X .... should fix the problem.
ssh -X user@host or ssh -Y user@host for Stampede should be sufficient for X11 tunneling and opening up X-windows.

What does hostname -a output if I am on a compute node?
How do I make sure I am using a compute node?
What are you getting (it varies for all of them)?
If you see login.... then it's a login, if you see c###-### it's a compute node.
Got it.

Could you tell me how to compute $MIC_OMP_NUM_THREADS  for a node with 16 cores
Do you mean show the value of the environment variable $MIC_OMP_NUM_THREADS?
echo $MIC_OMP_NUM_THREADS
NO how did you come up with 240 number
Or is it default per node
If I am specifying it in a job script how will I doit

The node has 2 sandybridges of 8 cores, correct.
The MIC is a separate co-processor; it has 60 cores
note the variable name MIC_OMP_NUM_THREADS, as opposed to OMP_NUM_THREADS
It's part of the hardware of the Intel Xeon Phi Coprocessor (i.e. MIC).
Oh ok so does all nodes on stamped have MICs with 60 cores
Essentially all compute nodes. Not the login nodes. All our MICs are "the same" in the sense they have 60 cores.
Why multiply by 4 so
Because the MIC has 4 hardware threads
Thanks I will look this up
https://software.intel.com/en-us/articles/optimization-and-performance-tuning-for-intel-xeon-phi-coprocessors-part-2-understanding

So is this available for any code that is compiled using MKL
With the intel compilers, yes.
Offload will be supported via OpenMP 4.0 in upcoming GCC compiler implementations as well.
Currently I have code compiled with Intel compilers an MKL in stampede. So If I specify MIC variables it will automatically offload to MIC right?
It depends on which MKL calls you are using, how big your matrices are.
Mainly tha LAPACK routines are used with pretty large matrices
Many routines are supported. I'm not sure which specific ones are but many of the 'popular' ones, as Antonio pointed out in the tutorial.

How do I get on a compute node? I want to run these examples.
I was on a compute node at one point but not anymore.

idev -t 2:00:00
The account for TACC-HPC-PYTHON is reserved for local participants.

Thank you for that great presentation. The last part on mpi4py was difficutl for me to follow. However, overall, I learned a lot.


text:
package org.apache.rya.export.accumulo.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.client.admin.SecurityOperations;
import org.apache.accumulo.core.client.mock.MockInstance;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.Filter;
import org.apache.accumulo.core.iterators.user.RegExFilter;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.log4j.Logger;
import org.apache.rya.accumulo.AccumuloRdfConfiguration;
import org.apache.rya.accumulo.AccumuloRyaDAO;
import org.apache.rya.accumulo.mr.MRUtils;
import org.apache.rya.api.RdfCloudTripleStoreConstants;
import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT;
import org.apache.rya.api.domain.RyaStatement;
import org.apache.rya.api.domain.RyaURI;
import org.apache.rya.api.persist.RyaDAOException;
import org.apache.rya.api.resolver.RdfToRyaConversions;
import org.apache.rya.api.resolver.RyaTripleContext;
import org.apache.rya.api.resolver.triple.TripleRow;
import org.apache.rya.api.resolver.triple.TripleRowResolverException;
import org.apache.rya.indexing.accumulo.ConfigUtils;
import org.openrdf.model.ValueFactory;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;

/**
 * Utility methods for an Accumulo Rya instance.
 */
public final class AccumuloRyaUtils {
    private static final Logger log = Logger.getLogger(AccumuloRyaUtils.class);

    private static final String NAMESPACE = RdfCloudTripleStoreConstants.NAMESPACE;
    private static final ValueFactory VALUE_FACTORY = RdfCloudTripleStoreConstants.VALUE_FACTORY;

    /**
     * Ignore the meta statements indicating the Rya version and copy time values.
     */
    public static final ImmutableSet<IteratorSetting> COMMON_REG_EX_FILTER_SETTINGS = ImmutableSet.of(
        getVersionRegExFilterSetting()
    );

    /**
     * Private constructor to prevent instantiation.
     */
    private AccumuloRyaUtils() {
    }

    /**
     * Creates a {@link RyaURI} for the specified local name.
     * @param localName the URI's local name.
     * @return the {@link RyaURI}.
     */
    public static RyaURI createRyaUri(final String localName) {
        return createRyaUri(NAMESPACE, localName);
    }

    /**
     * Creates a {@link RyaURI} for the specified local name.
     * @param namespace the namespace.
     * @param localName the URI's local name.
     * @return the {@link RyaURI}.
     */
    public static RyaURI createRyaUri(final String namespace, final String localName) {
        return RdfToRyaConversions.convertURI(VALUE_FACTORY.createURI(namespace, localName));
    }

    /**
     * Converts a {@link RyaURI} to the contained data string.
     * @param the {@link RyaURI} to convert.
     * @return the data value without the namespace.
     */
    public static String convertRyaUriToString(final RyaURI ryaUri) {
        return convertRyaUriToString(NAMESPACE, ryaUri);
    }

    /**
     * Converts a {@link RyaURI} to the contained data string.
     * @param namespace the namespace.
     * @param the {@link RyaURI} to convert.
     * @return the data value without the namespace.
     */
    public static String convertRyaUriToString(final String namespace, final RyaURI ryaUri) {
        return StringUtils.replaceOnce(ryaUri.getData(), namespace, "");
    }

    /**
     * Creates a {@link RyaStatement} from a {@link Key}/{@link Value} pair.
     * @param key the {@link Key}.
     * @param value the {@link Value}.
     * @param ryaTripleContext the {@link RyaTripleContext}.
     * @return the converted {@link RyaStatement}.
     * @throws TripleRowResolverException
     */
    public static RyaStatement createRyaStatement(final Key key, final Value value, final RyaTripleContext ryaTripleContext) throws TripleRowResolverException {
        final byte[] row = key.getRowData() != null  && key.getRowData().toArray().length > 0 ? key.getRowData().toArray() : null;
        final byte[] columnFamily = key.getColumnFamilyData() != null  && key.getColumnFamilyData().toArray().length > 0 ? key.getColumnFamilyData().toArray() : null;
        final byte[] columnQualifier = key.getColumnQualifierData() != null  && key.getColumnQualifierData().toArray().length > 0 ? key.getColumnQualifierData().toArray() : null;
        final Long timestamp = key.getTimestamp();
        final byte[] columnVisibility = key.getColumnVisibilityData() != null && key.getColumnVisibilityData().toArray().length > 0 ? key.getColumnVisibilityData().toArray() : null;
        final byte[] valueBytes = value != null && value.get().length > 0 ? value.get() : null;
        final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier, timestamp, columnVisibility, valueBytes);
        final RyaStatement ryaStatement = ryaTripleContext.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow);

        return ryaStatement;
    }

    /**
     * Creates a {@link RegExFilter} setting to ignore the version row in a table.
     * @return the {@link RegExFilter} {@link IteratorSetting}.
     */
    public static IteratorSetting getVersionRegExFilterSetting() {
        final IteratorSetting regex = new IteratorSetting(30, "version_regex", RegExFilter.class);
        RegExFilter.setRegexs(regex, "(.*)urn:(.*)#version[\u0000|\u0001](.*)", null, null, null, false);
        Filter.setNegate(regex, true);
        return regex;
    }

    /**
     * Adds all the common regex filter {@link IteratorSetting}s to the provided {@link Scanner} so
     * certain metadata keys in a table are ignored.
     * @param scanner the {@link Scanner} to add the regex filter {@link IteratorSetting}s to.
     */
    public static void addCommonScannerIteratorsTo(final Scanner scanner) {
        for (final IteratorSetting iteratorSetting : COMMON_REG_EX_FILTER_SETTINGS) {
            scanner.addScanIterator(iteratorSetting);
        }
    }

    /**
     * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}.
     * This applies common iterator settings to the table scanner that ignore internal metadata keys.
     * @param tablename the name of the table to scan.
     * @param config the {@link Configuration}.
     * @return the {@link Scanner} for the table.
     * @throws IOException
     */
    public static Scanner getScanner(final String tableName, final Configuration config) throws IOException {
        return getScanner(tableName, config, true);
    }

    /**
     * Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}.
     * @param tablename the name of the table to scan.
     * @param config the {@link Configuration}.
     * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
     * {@code false} otherwise.
     * @return the {@link Scanner} for the table.
     * @throws IOException
     */
    public static Scanner getScanner(final String tableName, final Configuration config, final boolean shouldAddCommonIterators) throws IOException {
        try {
            final String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE);
            final String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS);
            Instance instance;
            if (ConfigUtils.useMockInstance(config)) {
                instance = new MockInstance(instanceName);
            } else {
                instance = new ZooKeeperInstance(new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
            }
            final String username = ConfigUtils.getUsername(config);
            final String password = ConfigUtils.getPassword(config);
            final Connector connector = instance.getConnector(username, new PasswordToken(password));
            final Authorizations auths = ConfigUtils.getAuthorizations(config);

            final Scanner scanner = connector.createScanner(tableName, auths);
            if (shouldAddCommonIterators) {
                AccumuloRyaUtils.addCommonScannerIteratorsTo(scanner);
            }
            return scanner;
        } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
            log.error("Error connecting to " + tableName);
            throw new IOException(e);
        }
    }

    /**
     * Prints the table with the specified config and additional settings.
     * This applies common iterator settings to the table scanner that ignore internal metadata keys.
     * @param tableName the name of the table to print.
     * @param config the {@link AccumuloRdfConfiguration}.
     * @param settings the additional {@link IteratorSetting}s to add besides the common ones.
     * @throws IOException
     */
    public static void printTable(final String tableName, final AccumuloRdfConfiguration config, final IteratorSetting... settings) throws IOException {
        printTable(tableName, config, true, settings);
    }

    /**
     * Prints the table with the specified config and additional settings.
     * @param tableName the name of the table to print.
     * @param config the {@link AccumuloRdfConfiguration}.
     * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
     * {@code false} otherwise.
     * @param settings the additional {@link IteratorSetting}s to add besides the common ones.
     * @throws IOException
     */
    public static void printTable(final String tableName, final AccumuloRdfConfiguration config, final boolean shouldAddCommonIterators, final IteratorSetting... settings) throws IOException {
        final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators);
        for (final IteratorSetting setting : settings) {
            scanner.addScanIterator(setting);
        }

        final Iterator<Entry<Key, Value>> iterator = scanner.iterator();

        final String instance = config.get(MRUtils.AC_INSTANCE_PROP);
        log.info("==================");
        log.info("TABLE: " + tableName + " INSTANCE: " + instance);
        log.info("------------------");
        while (iterator.hasNext()) {
            final Entry<Key, Value> entry = iterator.next();
            final Key key = entry.getKey();
            final Value value = entry.getValue();
            final String keyString = getFormattedKeyString(key);
            log.info(keyString + " - " + value);
        }
        log.info("==================");
    }

    private static String getFormattedKeyString(final Key key) {
        final StringBuilder sb = new StringBuilder();
        final byte[] row = key.getRow().getBytes();
        final byte[] colFamily = key.getColumnFamily().getBytes();
        final byte[] colQualifier = key.getColumnQualifier().getBytes();
        final byte[] colVisibility = key.getColumnVisibility().getBytes();
        final int maxRowDataToPrint = 256;
        Key.appendPrintableString(row, 0, row.length, maxRowDataToPrint, sb);
        sb.append(" ");
        Key.appendPrintableString(colFamily, 0, colFamily.length, maxRowDataToPrint, sb);
        sb.append(":");
        Key.appendPrintableString(colQualifier, 0, colQualifier.length, maxRowDataToPrint, sb);
        sb.append(" [");
        Key.appendPrintableString(colVisibility, 0, colVisibility.length, maxRowDataToPrint, sb);
        sb.append("]");
        sb.append(" ");
        sb.append(new Date(key.getTimestamp()));
        //sb.append(Long.toString(key.getTimestamp()));
        //sb.append(" ");
        //sb.append(key.isDeleted());
        return sb.toString();
    }

    /**
     * Prints the table with pretty formatting using the specified config and additional settings.
     * This applies common iterator settings to the table scanner that ignore internal metadata keys.
     * @param tableName the name of the table to print.
     * @param config the {@link AccumuloRdfConfiguration}.
     * @param settings the additional {@link IteratorSetting}s to add besides the common ones.
     * @throws IOException
     */
    public static void printTablePretty(final String tableName, final Configuration config, final IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
        printTablePretty(tableName, config, true, settings);
    }

    /**
     * Prints the table with pretty formatting using the specified config and additional settings.
     * @param tableName the name of the table to print.
     * @param config the {@link AccumuloRdfConfiguration}.
     * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
     * {@code false} otherwise.
     * @param settings the additional {@link IteratorSetting}s to add besides the common ones.
     * @throws IOException
     */
    public static void printTablePretty(final String tableName, final Configuration config, final boolean shouldAddCommonIterators, final IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
        final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators);
        for (final IteratorSetting setting : settings) {
            scanner.addScanIterator(setting);
        }

        final String format = "| %-64s | %-24s | %-28s | %-20s | %-20s | %-10s |";
        final int totalFormatLength = String.format(format, 1, 2, 3, 4, 5, 6).length();
        final String instance = config.get(MRUtils.AC_INSTANCE_PROP);
        log.info(StringUtils.rightPad("==================", totalFormatLength, "="));
        log.info(StringUtils.rightPad("| TABLE: " + tableName + " INSTANCE: " + instance, totalFormatLength - 1) + "|");
        log.info(StringUtils.rightPad("------------------", totalFormatLength, "-"));
        log.info(String.format(format, "--Row--", "--ColumnVisibility--", "--Timestamp--", "--ColumnFamily--", "--ColumnQualifier--", "--Value--"));
        log.info(StringUtils.rightPad("|-----------------", totalFormatLength - 1, "-") + "|");
        for (final Entry<Key, Value> entry : scanner) {
            final Key k = entry.getKey();
            final String rowString = Key.appendPrintableString(k.getRow().getBytes(), 0, k.getRow().getLength(), Constants.MAX_DATA_TO_PRINT, new StringBuilder()).toString();
            log.info(String.format(format, rowString, k.getColumnVisibility(), new Date(k.getTimestamp()), k.getColumnFamily(), k.getColumnQualifier(), entry.getValue()));
        }
        log.info(StringUtils.rightPad("==================", totalFormatLength, "="));
    }

    /**
     * Adds authorizations to a user's authorizations list.
     * @param user the name of the user to add authorizations for.
     * @param secOps the {@link SecurityOperations}.
     * @param auths the {@link Authorizations} to add
     * @return the {@link Authorizations}.
     * @throws AccumuloException
     * @throws AccumuloSecurityException
     */
    public static Authorizations addUserAuths(final String user, final SecurityOperations secOps, final Authorizations auths) throws AccumuloException, AccumuloSecurityException {
        final List<String> authList = new ArrayList<>();
        for (final byte[] authBytes : auths.getAuthorizations()) {
            final String auth = new String(authBytes);
            authList.add(auth);
        }
        return addUserAuths(user, secOps, authList.toArray(new String[0]));
    }

    /**
     * Adds authorizations to a user's authorizations list.
     * @param user the name of the user to add authorizations for.
     * @param secOps the {@link SecurityOperations}.
     * @param auths the list of authorizations to add
     * @return the {@link Authorizations}.
     * @throws AccumuloException
     * @throws AccumuloSecurityException
     */
    public static Authorizations addUserAuths(final String user, final SecurityOperations secOps, final String... auths) throws AccumuloException, AccumuloSecurityException {
        final Authorizations currentUserAuths = secOps.getUserAuthorizations(user);
        final List<byte[]> authList = new ArrayList<>();
        for (final byte[] currentAuth : currentUserAuths.getAuthorizations()) {
            authList.add(currentAuth);
        }
        for (final String newAuth : auths) {
            authList.add(newAuth.getBytes());
        }
        final Authorizations result = new Authorizations(authList);
        return result;
    }

    /**
     * Removes the specified authorizations from the user.
     * @param userName the name of the user to change authorizations for.
     * @param secOps the {@link SecurityOperations} to change.
     * @param authsToRemove the comma-separated string of authorizations to remove.
     * @throws AccumuloSecurityException
     * @throws AccumuloException
     */
    public static void removeUserAuths(final String userName, final SecurityOperations secOps, final String authsToRemove) throws AccumuloException, AccumuloSecurityException {
        final Authorizations currentUserAuths = secOps.getUserAuthorizations(userName);
        final List<String> authList = convertAuthStringToList(currentUserAuths.toString());

        final List<String> authsToRemoveList = convertAuthStringToList(authsToRemove);
        authList.removeAll(authsToRemoveList);

        final String authString = Joiner.on(",").join(authList);
        final Authorizations newAuths = new Authorizations(authString);

        secOps.changeUserAuthorizations(userName, newAuths);
    }

    /**
     * Convert the comma-separated string of authorizations into a list of authorizations.
     * @param authString the comma-separated string of authorizations.
     * @return a {@link List} of authorization strings.
     */
    public static List<String> convertAuthStringToList(final String authString) {
        final List<String> authList = new ArrayList<>();
        if (authString != null) {
            final String[] authSplit = authString.split(",");
            authList.addAll(Arrays.asList(authSplit));
        }
        return authList;
    }

    /**
     * Sets up a {@link Connector} with the specified config.
     * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}.
     * @return the {@link Connector}.
     */
    public static Connector setupConnector(final AccumuloRdfConfiguration accumuloRdfConfiguration) {
        Connector connector = null;
        try {
            connector = ConfigUtils.getConnector(accumuloRdfConfiguration);
        } catch (AccumuloException | AccumuloSecurityException e) {
            log.error("Error creating connector", e);
        }

        return connector;
    }

    /**
     * Sets up a {@link AccumuloRyaDAO} with the specified connector.
     * @param connector the {@link Connector}.
     * @return the {@link AccumuloRyaDAO}.
     */
    public static AccumuloRyaDAO setupDao(final AccumuloRdfConfiguration accumuloRdfConfiguration) {
        final Connector connector = setupConnector(accumuloRdfConfiguration);
        return setupDao(connector, accumuloRdfConfiguration);
    }

    /**
     * Sets up a {@link AccumuloRyaDAO} with the specified connector and config.
     * @param connector the {@link Connector}.
     * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}.
     * @return the {@link AccumuloRyaDAO}.
     */
    public static AccumuloRyaDAO setupDao(final Connector connector, final AccumuloRdfConfiguration accumuloRdfConfiguration) {
        final AccumuloRyaDAO accumuloRyaDao = new AccumuloRyaDAO();
        accumuloRyaDao.setConnector(connector);
        accumuloRyaDao.setConf(accumuloRdfConfiguration);

        try {
            accumuloRyaDao.init();
        } catch (final RyaDAOException e) {
            log.error("Error initializing DAO", e);
        }

        return accumuloRyaDao;
    }
}


text:
package com.alibaba.fastjson.parser.deserializer;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONLexer;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.ParseContext;
import com.alibaba.fastjson.util.TypeUtils;

public class MapDeserializer implements ObjectDeserializer {
    public static MapDeserializer instance = new MapDeserializer();

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        if (type == JSONObject.class && parser.getFieldTypeResolver() == null) {
            return (T) parser.parseObject();
        }

        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken(JSONToken.COMMA);
            return null;
        }

        Map<Object, Object> map = createMap(type);

        ParseContext context = parser.getContext();

        try {
            parser.setContext(context, map, fieldName);
            return (T) deserialze(parser, type, fieldName, map);
        } finally {
            parser.setContext(context);
        }
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map) {
        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type keyType = parameterizedType.getActualTypeArguments()[0];
            Type valueType = parameterizedType.getActualTypeArguments()[1];

            if (String.class == keyType) {
                return parseMap(parser, (Map<String, Object>) map, valueType, fieldName);
            } else {
                return parseMap(parser, map, keyType, valueType, fieldName);
            }
        } else {
            return parser.parseObject(map, fieldName);
        }
    }

    @SuppressWarnings("rawtypes")
    public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName) {
        JSONLexer lexer = parser.lexer;

        if (lexer.token() != JSONToken.LBRACE) {
            throw new JSONException("syntax error, expect {, actual " + lexer.token());
        }

        ParseContext context = parser.getContext();
        try {
            for (int i = 0;;++i) {
                lexer.skipWhitespace();
                char ch = lexer.getCurrent();
                if (lexer.isEnabled(Feature.AllowArbitraryCommas)) {
                    while (ch == ',') {
                        lexer.next();
                        lexer.skipWhitespace();
                        ch = lexer.getCurrent();
                    }
                }

                String key;
                if (ch == '"') {
                    key = lexer.scanSymbol(parser.getSymbolTable(), '"');
                    lexer.skipWhitespace();
                    ch = lexer.getCurrent();
                    if (ch != ':') {
                        throw new JSONException("expect ':' at " + lexer.pos());
                    }
                } else if (ch == '}') {
                    lexer.next();
                    lexer.resetStringPosition();
                    lexer.nextToken(JSONToken.COMMA);
                    return map;
                } else if (ch == '\'') {
                    if (!lexer.isEnabled(Feature.AllowSingleQuotes)) {
                        throw new JSONException("syntax error");
                    }

                    key = lexer.scanSymbol(parser.getSymbolTable(), '\'');
                    lexer.skipWhitespace();
                    ch = lexer.getCurrent();
                    if (ch != ':') {
                        throw new JSONException("expect ':' at " + lexer.pos());
                    }
                } else {
                    if (!lexer.isEnabled(Feature.AllowUnQuotedFieldNames)) {
                        throw new JSONException("syntax error");
                    }

                    key = lexer.scanSymbolUnQuoted(parser.getSymbolTable());
                    lexer.skipWhitespace();
                    ch = lexer.getCurrent();
                    if (ch != ':') {
                        throw new JSONException("expect ':' at " + lexer.pos() + ", actual " + ch);
                    }
                }

                lexer.next();
                lexer.skipWhitespace();
                ch = lexer.getCurrent();

                lexer.resetStringPosition();

                if (key == JSON.DEFAULT_TYPE_KEY && !lexer.isEnabled(Feature.DisableSpecialKeyDetect)) {
                    String typeName = lexer.scanSymbol(parser.getSymbolTable(), '"');
                    Class<?> clazz = TypeUtils.loadClass(typeName, parser.getConfig().getDefaultClassLoader());

                    if (Map.class.isAssignableFrom(clazz) ) {
                        lexer.nextToken(JSONToken.COMMA);
                        if (lexer.token() == JSONToken.RBRACE) {
                            lexer.nextToken(JSONToken.COMMA);
                            return map;
                        }
                        continue;
                    }

                    ObjectDeserializer deserializer = parser.getConfig().getDeserializer(clazz);

                    lexer.nextToken(JSONToken.COMMA);

                    parser.setResolveStatus(DefaultJSONParser.TypeNameRedirect);

                    if (context != null && !(fieldName instanceof Integer)) {
                        parser.popContext();
                    }

                    return (Map) deserializer.deserialze(parser, clazz, fieldName);
                }

                Object value;
                lexer.nextToken();

                if (i != 0) {
                    parser.setContext(context);
                }

                if (lexer.token() == JSONToken.NULL) {
                    value = null;
                    lexer.nextToken();
                } else {
                    value = parser.parseObject(valueType, key);
                }

                map.put(key, value);
                parser.checkMapResolve(map, key);

                parser.setContext(context, value, key);
                parser.setContext(context);

                final int tok = lexer.token();
                if (tok == JSONToken.EOF || tok == JSONToken.RBRACKET) {
                    return map;
                }

                if (tok == JSONToken.RBRACE) {
                    lexer.nextToken();
                    return map;
                }
            }
        } finally {
            parser.setContext(context);
        }

    }

    public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map, Type keyType, Type valueType,
                                  Object fieldName) {
        JSONLexer lexer = parser.lexer;

        if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
            throw new JSONException("syntax error, expect {, actual " + lexer.tokenName());
        }

        ObjectDeserializer keyDeserializer = parser.getConfig().getDeserializer(keyType);
        ObjectDeserializer valueDeserializer = parser.getConfig().getDeserializer(valueType);
        lexer.nextToken(keyDeserializer.getFastMatchToken());

        ParseContext context = parser.getContext();
        try {
            for (;;) {
                if (lexer.token() == JSONToken.RBRACE) {
                    lexer.nextToken(JSONToken.COMMA);
                    break;
                }

                if (lexer.token() == JSONToken.LITERAL_STRING //
                    && lexer.isRef() //
                    && !lexer.isEnabled(Feature.DisableSpecialKeyDetect) //
                ) {
                    Object object = null;

                    lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
                    if (lexer.token() == JSONToken.LITERAL_STRING) {
                        String ref = lexer.stringVal();
                        if ("..".equals(ref)) {
                            ParseContext parentContext = context.parent;
                            object = parentContext.object;
                        } else if ("$".equals(ref)) {
                            ParseContext rootContext = context;
                            while (rootContext.parent != null) {
                                rootContext = rootContext.parent;
                            }

                            object = rootContext.object;
                        } else {
                            parser.addResolveTask(new ResolveTask(context, ref));
                            parser.setResolveStatus(DefaultJSONParser.NeedToResolve);
                        }
                    } else {
                        throw new JSONException("illegal ref, " + JSONToken.name(lexer.token()));
                    }

                    lexer.nextToken(JSONToken.RBRACE);
                    if (lexer.token() != JSONToken.RBRACE) {
                        throw new JSONException("illegal ref");
                    }
                    lexer.nextToken(JSONToken.COMMA);

                    // parser.setContext(context, map, fieldName);
                    // parser.setContext(context);

                    return object;
                }

                if (map.size() == 0 //
                    && lexer.token() == JSONToken.LITERAL_STRING //
                    && JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal()) //
                    && !lexer.isEnabled(Feature.DisableSpecialKeyDetect)) {
                    lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
                    lexer.nextToken(JSONToken.COMMA);
                    if (lexer.token() == JSONToken.RBRACE) {
                        lexer.nextToken();
                        return map;
                    }
                    lexer.nextToken(keyDeserializer.getFastMatchToken());
                }

                Object key = keyDeserializer.deserialze(parser, keyType, null);

                if (lexer.token() != JSONToken.COLON) {
                    throw new JSONException("syntax error, expect :, actual " + lexer.token());
                }

                lexer.nextToken(valueDeserializer.getFastMatchToken());

                Object value = valueDeserializer.deserialze(parser, valueType, key);
                parser.checkMapResolve(map, key);

                map.put(key, value);

                if (lexer.token() == JSONToken.COMMA) {
                    lexer.nextToken(keyDeserializer.getFastMatchToken());
                }
            }
        } finally {
            parser.setContext(context);
        }

        return map;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected Map<Object, Object> createMap(Type type) {
        if (type == Properties.class) {
            return new Properties();
        }

        if (type == Hashtable.class) {
            return new Hashtable();
        }

        if (type == IdentityHashMap.class) {
            return new IdentityHashMap();
        }

        if (type == SortedMap.class || type == TreeMap.class) {
            return new TreeMap();
        }

        if (type == ConcurrentMap.class || type == ConcurrentHashMap.class) {
            return new ConcurrentHashMap();
        }

        if (type == Map.class || type == HashMap.class) {
            return new HashMap();
        }

        if (type == LinkedHashMap.class) {
            return new LinkedHashMap();
        }

        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;

            return createMap(parameterizedType.getRawType());
        }

        Class<?> clazz = (Class<?>) type;
        if (clazz.isInterface()) {
            throw new JSONException("unsupport type " + type);
        }

        try {
            return (Map<Object, Object>) clazz.newInstance();
        } catch (Exception e) {
            throw new JSONException("unsupport type " + type, e);
        }
    }

    public int getFastMatchToken() {
        return JSONToken.LBRACE;
    }
}


text:
dc::dcClass<InteractiveNPCLifeformAI>::Implements<LifeformAI> InteractiveNPCLifeformAI::implementsLifeformAI;

InteractiveNPCLifeformAI::InteractiveNPCLifeformAI() {
  member("Name", &name_);
  member("Actor Type", &actor_type_);
  member("Interaction Type", &interaction_type_);
  member("Wander?", &wander_);

  for (int i = 0; i < Evidyon::ACTORATTACHMENTPOINT_COUNT; ++i) {
    const char* point = dc::dcEnum<Evidyon::ActorAttachmentPoint>::getString((Evidyon::ActorAttachmentPoint)i);
    std::string name = "";
    name.append(point);
    member(name, &equipped_items_[i]);
  }

  interaction_type_.setValue(Evidyon::NPCINTERACTION_STORAGE);
}

const std::string& InteractiveNPCLifeformAI::getLifeformName() const {
  return name_.getValue();
}

bool InteractiveNPCLifeformAI::compileForServer(Evidyon::LifeformAIDescription* description) const {
  description->type = Evidyon::LifeformAIDescription::INTERACTIVE_NPC;
  description->interactive_npc.interaction = interaction_type_.getValue();
  description->interactive_npc.actor_template_index = compiled_actor_template_index_;

  return true;
}

bool InteractiveNPCLifeformAI::compileActorTemplates(ActorDescriptionTemplateCompiler* compiler) {
  compiled_actor_template_index_ = compiler->getNextTemplateIndex();
  Evidyon::ClientActorDescriptionTemplate client_description;
  Evidyon::ServerActorDescriptionTemplate server_description;

  for (int i = 0; i < Evidyon::ACTORACTION_VARIABLE_SPEED_COUNT; ++i) {
    client_description.action_speeds[i] = 1.0f;
  }

  client_description.enchantments = 0;
  client_description.description_can_change = false;
  client_description.actor_type = actor_type_.getReferencedResourceIndex();
  strncpy_s(client_description.name, MAX_ACTOR_NAME_LENGTH, name_.getValue().c_str(), MAX_ACTOR_NAME_LENGTH);
  switch (interaction_type_.getValue()) {
    case Evidyon::NPCINTERACTION_STORAGE:  client_description.template_type = ACTORTEMPLATETYPE_NPC_STORAGE; break;
    case Evidyon::NPCINTERACTION_BAZAAR:   client_description.template_type = ACTORTEMPLATETYPE_NPC_BAZAAR; break;
    case Evidyon::NPCINTERACTION_GEOSID:   client_description.template_type = ACTORTEMPLATETYPE_NPC_GEOSID; break;
    case Evidyon::NPCINTERACTION_QUEST:    client_description.template_type = ACTORTEMPLATETYPE_NPC_QUESTGIVER; break;
    case Evidyon::NPCINTERACTION_MERCHANT: client_description.template_type = ACTORTEMPLATETYPE_NPC_MERCHANT; break;
  }

  for (int i = 0; i < Evidyon::ACTORATTACHMENTPOINT_COUNT; ++i) {
    dcList<Item>::Element* item_element = equipped_items_[i].getReferencedResource();
    size_t scenery_index = 0xFFFFFFFF;
    if (item_element) {
      scenery_index = item_element->getSceneryReference()->getReferencedResourceIndex();
    }
    client_description.equipped_item_scenery[i] = scenery_index;
  }

  server_description.actor_type = client_description.actor_type;

  compiler->addActorDescriptionTemplate(&client_description, &server_description);

  return true;
}

std::string InteractiveNPCLifeformAI::staticTypeName() {
  return "InteractiveNPCLifeformAI";
}