text:
import base64
import collections
import contextlib
import logging
import pkgutil
import random
import socket
import struct
import subprocess
import sys
import time
import unittest
import types
import os
import tempfile
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO
import gzip

import six

from argus import log as argus_log
from argus import exceptions

LOG = argus_log.LOG

CMD = "cmd"
BAT_SCRIPT = "bat"
POWERSHELL = "powershell"
POWERSHELL_SCRIPT = "powershell_script"
POWERSHELL_SCRIPT_RESTRICTED = "powershell_script_restricted"
POWERSHELL_SCRIPT_ALLSIGNED = "powershell_script_allsigned"
POWERSHELL_SCRIPT_REMOTESIGNED = "powershell_script_remotesigned"
POWERSHELL_SCRIPT_UNRESTRICTED = "powershell_script_unrestricted"
POWERSHELL_SCRIPT_BYPASS = "powershell_script_bypass"
POWERSHELL_SCRIPT_UNDEFINED = "powershell_script_undefined"

SERVICES_PREFIX = "cloudbaseinit.metadata.services"
HTTP_SERVICE = 'http'
CONFIG_DRIVE_SERVICE = 'configdrive'
EC2_SERVICE = 'ec2'
OPEN_NEBULA_SERVICE = 'opennebula'
CLOUD_STACK_SERVICE = 'cloudstack'
MAAS_SERVICE = 'maas'
NO_SERVICE = 'noservice'
PACKET_SERVICE = 'packet'

DEFAULT_METADATA_URL = {
    HTTP_SERVICE: "http://169.254.169.254/",
    EC2_SERVICE: "http://169.254.169.254/",
    CLOUD_STACK_SERVICE: "http://10.1.1.1/",

    OPEN_NEBULA_SERVICE: "",
    MAAS_SERVICE: "",
}

SAN_POLICY_ONLINE_STR = 'OnlineAll'
SAN_POLICY_OFFLINE_STR = 'OfflineAll'
SAN_POLICY_OFFLINE_SHARED_STR = 'OfflineShared'

_FUNCTION_EQUALITY_PROPERTIES = ["co_code", "co_names",
                                 "co_nlocals", "co_stacksize",
                                 "co_varnames"]
_FUNCTION_EQUALITY_METHODS = [six.get_function_globals,
                              six.get_function_defaults,
                              six.get_function_closure]

__all__ = (
    'decrypt_password',
    'get_logger',
    'get_resource',
    'cached_property',
    'run_once',
    'rand_name',
    'get_public_keys',
    'get_certificate',
)

def build_new_function(func, name):
    code = six.get_function_code(func)
    func_globals = six.get_function_globals(func)
    func_defaults = six.get_function_defaults(func)
    func_closure = six.get_function_closure(func)
    return types.FunctionType(code, func_globals,
                              name, func_defaults,
                              func_closure)

def check_function_eq(func_a, func_b):
    """Check if two functions have the same bytecode."""
    code_a = six.get_function_code(func_a)
    code_b = six.get_function_code(func_b)

    # check the equality of the bytecode
    code_equality = all([getattr(code_a, prop) == getattr(code_b, prop) for
                         prop in _FUNCTION_EQUALITY_PROPERTIES])

    # check the equality of the function
    function_equality = all([func(func_b) == func(func_b) for func
                             in _FUNCTION_EQUALITY_METHODS])

    return all([code_equality, function_equality])

DEFAULT_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
DEFAULT_LOG_FILE = 'argus.log'

NETWORK_KEYS = [
    "mac",
    "address",
    "address6",
    "gateway",
    "gateway6",
    "netmask",
    "netmask6",
    "dns",
    "dns6",
    "dhcp"
]

def exec_with_retry(action, retry_count, retry_count_interval):
    i = 0
    while True:
        try:
            return action()
        except Exception:
            if i < retry_count:
                i += 1
                time.sleep(retry_count_interval)
            else:
                raise exceptions.ArgusTimeoutError(
                    "{!r} failed too many times."
                    .format(action))

def get_int_from_str(content):
    """Returns only the digits from a given string.

    :type content: str
    """
    return int(''.join(element for element in content if element.isdigit()))

def sanitize_command_output(content):
    """Sanitizes the output got from underlying instances.

    Sanitizes the output by only returning unicode characters,
    any other characters will be ignored, and will also strip
    down the content of unrequired spaces and newlines.
    """
    return six.text_type(content, errors='ignore').strip()

def get_local_ip():
    """Get the current machine's IP."""
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.connect(("google.com", 0))
    return sock.getsockname()[0]

def next_ip(ip, step=1):
    """Return the next IP address of the given one.

    :type step: int
    :param step: offset adjustment value
    """
    # Convert IP address to unsigned long.
    data_type = "!L"
    number = struct.unpack(data_type, socket.inet_aton(ip))[0]
    # Get the next one.
    number += step
    # Convert it back and return the ASCII value.
    return socket.inet_ntoa(struct.pack(data_type, number))

def cidr2netmask(cidr):
    """Return the net mask deduced from the CIDR format network address."""
    mask_length = int(cidr.split("/")[1])
    mask_bits = "1" * mask_length + "0" * (32 - mask_length)
    mask_number = int(mask_bits, 2)
    mask_bytes = struct.pack("!L", mask_number)
    return socket.inet_ntoa(mask_bytes)

def decrypt_password(private_key, password):
    """Decode password and decrypts it with private key.

    Requires openssl binary available in the path.
    """
    unencoded = base64.b64decode(password)
    cmd = ['openssl', 'rsautl', '-decrypt', '-inkey', private_key]
    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    out, err = proc.communicate(unencoded)
    proc.stdin.close()
    if proc.returncode:
        raise Exception("Failed calling openssl with error: {!r}."
                        .format(err))
    return out

# pylint: disable=dangerous-default-value
def run_once(func, state={}, errors={}):
    """A memoization decorator, whose purpose is to cache calls."""
    @six.wraps(func)
    def wrapper(*args, **kwargs):
        if func in errors:
            # Deliberate use of LBYL.
            six.reraise(*errors[func])

        try:
            return state[func]
        except KeyError:
            try:
                state[func] = result = func(*args, **kwargs)
                return result
            except Exception:
                errors[func] = sys.exc_info()
                raise
    return wrapper

def get_resource(resource):
    """Get the given resource from the list of known resources."""
    return pkgutil.get_data('argus.resources', resource)

def gzip_data(data):
    """Get a string and return gzipped bytes of that data.

    :param data: The data we want to compress.
    """
    buff = StringIO()
    with gzip.GzipFile(fileobj=buff, mode="w") as fd:
        fd.write(data)
    return buff.getvalue()

class cached_property(object):  # pylint: disable=invalid-name
    """A property which caches the result on access."""

    def __init__(self, func, name=None):
        self.func = func
        self.name = name or func.__name__

    def __get__(self, instance, klass=None):
        if instance is None:
            return self
        instance.__dict__[self.name] = result = self.func(instance)
        return result

def rand_name(name=''):
    """Generate a random name

    If *name* is given, then it will be prepended to
    the generated string, separated by a minus sign.
    """
    randbits = str(random.randint(1, 0x7fffffff))
    if name:
        return name + '-' + randbits
    else:
        return randbits

@contextlib.contextmanager
def restore_excepthook():
    """Context manager used to preserve the original except hook.

    *tempest* sets its own except hook, which will log the error
    using the tempest logger. Unfortunately, we are not using
    the tempest logger, so any uncaught error goes into nothingness.
    So just reset the excepthook to the original.
    """
    # pylint: disable=redefined-outer-name,reimported
    import sys
    original = sys.excepthook
    try:
        yield
    finally:
        sys.excepthook = original

def get_logger(name="argus",
               format_string=DEFAULT_FORMAT,
               logging_file=DEFAULT_LOG_FILE):
    """Obtain a new logger object.

    The `name` parameter will be the name of the logger and `format_string`
    will be the format it will use for logging. `logging_file` is a file
    where the messages will be written.
    """
    logger = logging.getLogger(name)
    formatter = logging.Formatter(format_string)

    if not logger.handlers:
        # If the logger wasn't obtained another time,
        # then it shouldn't have any loggers

        if logging_file:
            file_handler = logging.FileHandler(logging_file, delay=True)
            file_handler.setFormatter(formatter)
            logger.addHandler(file_handler)

    logger.setLevel(logging.DEBUG)
    return logger

def get_namedtuple(name, members, values):
    nt_class = collections.namedtuple(name, members)
    return nt_class(*values)

def get_public_keys():
    """Get the *public_keys* resource.

    Used by the Cloudbase-Init tests.
    """
    return get_resource("public_keys").splitlines()

def get_certificate():
    """Get the *certificate* resource.

    Used by the Cloudbase-Init tests.
    """
    return get_resource("certificate")

def _get_command_powershell(command):
    """Return the CMD command that runs the specific powershell command."""
    encoded = base64.b64encode(command.encode("UTF-16LE"))
    if six.PY3:
        encoded = encoded.decode()

    command = ("powershell -NonInteractive -NoLogo"
               " -EncodedCommand {}").format(encoded)

    return command

def _get_command_powershell_script(command):
    """Return a valid CMD command that runs a powershell script."""
    return "powershell -NonInteractive -NoLogo -File {}".format(command)

def _get_cmd_with_privileges(policy="RemoteSigned"):
    """Factory function that runs powershell scripts with a specific Policy."""

    def _get_cmd(command):
        return ("powershell -NonInteractive -NoLogo -ExecutionPolicy "
                "{} -File {}".format(policy, command))
    return _get_cmd

COMMAND_MODIFIERS = {
    POWERSHELL: _get_command_powershell,
    POWERSHELL_SCRIPT: _get_command_powershell_script,
    POWERSHELL_SCRIPT_ALLSIGNED: _get_cmd_with_privileges("AllSigned"),
    POWERSHELL_SCRIPT_REMOTESIGNED: _get_cmd_with_privileges("RemoteSigned"),
    POWERSHELL_SCRIPT_UNRESTRICTED: _get_cmd_with_privileges("Unrestricted"),
    POWERSHELL_SCRIPT_BYPASS: _get_cmd_with_privileges("Bypass"),
    POWERSHELL_SCRIPT_UNDEFINED: _get_cmd_with_privileges("Undefined"),
}

def get_command(command, command_type=None):
    """Returns the command decorated according to the command_type """
    modifier = COMMAND_MODIFIERS.get(command_type, lambda command: command)
    return modifier(command)

_BUILDS = ["Beta", "Stable", "test"]
_ARCHES = ["x64", "x86"]
BUILDS = get_namedtuple("BUILDS", _BUILDS, _BUILDS)
ARCHES = get_namedtuple("ARCHES", _ARCHES, _ARCHES)

WINDOWS = "windows"

WINDOWS7 = "windows_7"
WINDOWS8 = "windows_8"
WINDOWS10 = "windows_10"

WINDOWS_SERVER_2008 = "windows_server_2008"
WINDOWS_SERVER_2008_R2 = "windows_server_2008r2"

WINDOWS_SERVER_2012 = "windows_sever_2012"
WINDOWS_SERVER_2012_R2 = "windows_server_2012r2"

WINDOWS_SERVER_2016 = "windows_server_2016"
WINDOWS_NANO = "windows_nano"

# The key has this format:
# (Major version number, Minor version number, Product Type)
# Version number according to this page:
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833%28v=vs.85%29.aspx
# Product Type according to this:
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
# For the Major Version 10 Server edition we have two possibilities:
# 1. is Windows Nano Server
# 2. is not Windows Nano Server (so it's Windows Server 2016)
# IsNanoserver False/True based on this code: https://goo.gl/UD27SK

WINDOWS_VERSION = {
    (6, 2, 1): WINDOWS8,
    (10, 0, 1): WINDOWS10,
    (6, 0, 3): WINDOWS_SERVER_2008,
    (6, 1, 3): WINDOWS_SERVER_2008_R2,
    (6, 1, 1): WINDOWS7,
    (6, 2, 3): WINDOWS_SERVER_2012,
    (6, 3, 3): WINDOWS_SERVER_2012_R2,
    (10, 0, 3): {
        False: WINDOWS_SERVER_2016,
        True: WINDOWS_NANO
    }
}

@contextlib.contextmanager
def create_tempfile(content):
    fd, path = tempfile.mkstemp()
    os.write(fd, content.encode())
    os.close(fd)
    try:
        yield path
    finally:
        os.remove(path)

class skip_on_os(object):
    """Decorator to skip a method on a specific OS."""

    def __init__(self, target_os_list, reason=""):
        """Skip the method decorated if we are using the `os_type`.

        :param target_os_list: A list with OS version on which
                               the decorator will take effect
        """
        self._target_os_list = target_os_list
        self._reason = reason

    def __call__(self, function):
        """Return the `function` decorated."""
        @six.wraps(function)
        def wrapper(*args, **kwargs):
            try:
                target_self = args[0]
            except IndexError:
                raise exceptions.ArgusInvalidDecoratorError(
                    "Incompatible use of decorator %s on %s",
                    "skip_on_os", function.__name__)

            try:
                instance_os_type = target_self.get_os_type()
            except AttributeError as ex:
                raise exceptions.ArgusInvalidDecoratorError(
                    ("The OS type has not been determined yet in %s,"
                     " error message %s"), function.__name__, ex)

            if instance_os_type in self._target_os_list:
                LOG.info("Skip %s on OS type %s : %s",
                         function.__name__, instance_os_type, self._reason)

                if isinstance(target_self, unittest.TestCase):
                    raise unittest.SkipTest(
                        "Skip on OS type {} : {}".format(instance_os_type,
                                                         self._reason))

            else:
                return function(*args, **kwargs)
        return wrapper


text:
package org.apache.flink.runtime.rest.handler.legacy.metrics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Executor;

/**
 * Request handler that returns, aggregated across all jobs, a list of all available metrics or the values
 * for a set of metrics.
 *
 * <p>Specific jobs can be selected for aggregation by specifying a comma-separated list of job IDs.
 * {@code /metrics?get=X,Y&jobs=A,B}
 */
public class AggregatingJobsMetricsHandler extends AbstractAggregatingMetricsHandler {
	public AggregatingJobsMetricsHandler(Executor executor, MetricFetcher fetcher) {
		super(executor, fetcher);
	}

	@Override
	protected Collection<? extends MetricStore.ComponentMetricStore> getStores(MetricStore store, Map<String, String> pathParameters, Map<String, String> queryParameters) {
		String jobsList = queryParameters.get("jobs");
		if (jobsList == null || jobsList.isEmpty()) {
			return store.getJobs().values();
		} else {
			String[] jobs = jobsList.split(",");
			Collection<MetricStore.ComponentMetricStore> jobStores = new ArrayList<>();
			for (String job : jobs) {
				jobStores.add(store.getJobMetricStore(job));
			}
			return jobStores;
		}
	}

	@Override
	public String[] getPaths() {
		return new String[]{"/jobs/metrics"};
	}
}

redpajama_set_name: RedPajamaGithub


text:
package org.cometd.server;

import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.cometd.bayeux.server.BayeuxServer;
import org.cometd.bayeux.server.ServerMessage;
import org.cometd.bayeux.server.ServerSession;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.servlet.FilterHolder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class BayeuxContextTest extends AbstractBayeuxClientServerTest {
    @ParameterizedTest
    @MethodSource("transports")
    public void testAddresses(String serverTransport) throws Exception {
        startServer(serverTransport, null);

        CountDownLatch latch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener() {
            @Override
            public void sessionAdded(ServerSession session, ServerMessage message) {
                Assertions.assertNotNull(message.getBayeuxContext().getLocalAddress());
                Assertions.assertNotNull(message.getBayeuxContext().getRemoteAddress());
                latch.countDown();
            }
        });

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
                "\"supportedConnectionTypes\": [\"long-polling\"]" +
                "}]");
        ContentResponse response = handshake.send();
        Assertions.assertEquals(200, response.getStatus());

        Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }

    @ParameterizedTest
    @MethodSource("transports")
    public void testRequestHeader(String serverTransport) throws Exception {
        startServer(serverTransport, null);

        String name = "test";
        String value1 = "foo";
        String value2 = "bar";
        CountDownLatch latch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener() {
            @Override
            public void sessionAdded(ServerSession session, ServerMessage message) {
                Assertions.assertEquals(value1, message.getBayeuxContext().getHeader(name));
                Assertions.assertEquals(List.of(value1, value2), message.getBayeuxContext().getHeaderValues(name));
                latch.countDown();
            }
        });

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
                "\"supportedConnectionTypes\": [\"long-polling\"]" +
                "}]");
        handshake.headers(headers -> headers.put(name, value1));
        handshake.headers(headers -> headers.add(name, value2));
        ContentResponse response = handshake.send();
        Assertions.assertEquals(200, response.getStatus());

        Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }

    @ParameterizedTest
    @MethodSource("transports")
    public void testRequestAttribute(String serverTransport) throws Exception {
        startServer(serverTransport, null);

        String name = "test";
        String value = "foo";

        context.stop();
        context.addFilter(new FilterHolder(new Filter() {
            @Override
            public void init(FilterConfig filterConfig) {
            }

            @Override
            public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
                servletRequest.setAttribute(name, value);
                filterChain.doFilter(servletRequest, servletResponse);
            }

            @Override
            public void destroy() {
            }
        }), "/*", EnumSet.of(DispatcherType.REQUEST));
        context.start();
        bayeux = cometdServlet.getBayeux();

        CountDownLatch latch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener() {
            @Override
            public void sessionAdded(ServerSession session, ServerMessage message) {
                Assertions.assertEquals(value, message.getBayeuxContext().getRequestAttribute(name));
                latch.countDown();
            }
        });

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
                "\"supportedConnectionTypes\": [\"long-polling\"]" +
                "}]");
        ContentResponse response = handshake.send();
        Assertions.assertEquals(200, response.getStatus());

        Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }

    @ParameterizedTest
    @MethodSource("transports")
    public void testSessionAttribute(String serverTransport) throws Exception {
        startServer(serverTransport, null);

        String name = "test";
        String value = "foo";

        context.stop();
        context.addFilter(new FilterHolder(new Filter() {
            @Override
            public void init(FilterConfig filterConfig) {
            }

            @Override
            public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
                HttpServletRequest request = (HttpServletRequest)servletRequest;
                request.getSession(true).setAttribute(name, value);
                filterChain.doFilter(servletRequest, servletResponse);
            }

            @Override
            public void destroy() {
            }
        }), "/*", EnumSet.of(DispatcherType.REQUEST));
        context.start();
        bayeux = cometdServlet.getBayeux();

        CountDownLatch latch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener() {
            @Override
            public void sessionAdded(ServerSession session, ServerMessage message) {
                Assertions.assertNotNull(message.getBayeuxContext().getHttpSessionId());
                Assertions.assertEquals(value, message.getBayeuxContext().getHttpSessionAttribute(name));
                latch.countDown();
            }
        });

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
                "\"supportedConnectionTypes\": [\"long-polling\"]" +
                "}]");
        ContentResponse response = handshake.send();
        Assertions.assertEquals(200, response.getStatus());

        Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }

    @ParameterizedTest
    @MethodSource("transports")
    public void testContextAttribute(String serverTransport) throws Exception {
        startServer(serverTransport, null);

        CountDownLatch latch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener() {
            @Override
            public void sessionAdded(ServerSession session, ServerMessage message) {
                Assertions.assertSame(bayeux, message.getBayeuxContext().getContextAttribute(BayeuxServer.ATTRIBUTE));
                latch.countDown();
            }
        });

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
                "\"supportedConnectionTypes\": [\"long-polling\"]" +
                "}]");
        ContentResponse response = handshake.send();
        Assertions.assertEquals(200, response.getStatus());

        Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }
}


text:
set -o errexit -o nounset -o pipefail

function _rm {
  rm -rf "$@" 2>/dev/null || true
}

RELEASE=${RELEASE:-`grep -1 -A 0 -B 0 '<version>' pom.xml | head -n 1 | awk '{print $1}' | sed -e 's/.*<version>//' | sed -e 's/<\/version>.*//'`}

STORM_RELEASE=${STORM_RELEASE:-`grep -1 -A 0 -B 0 '<storm.default.version>' pom.xml | head -n 1 | awk '{print $1}' | sed -e 's/.*<storm.default.version>//' | sed -e 's/<\/storm.default.version>.*//'`}

if [[ $STORM_RELEASE == "0.10"* ]]; then
  PROFILE=storm10
else
  PROFILE=storm9
fi

MESOS_RELEASE=${MESOS_RELEASE:-`grep -1 -A 0 -B 0 '<mesos.default.version>' pom.xml | head -n 1 | awk '{print $1}' | sed -e 's/.*<mesos.default.version>//' | sed -e 's/<\/mesos.default.version>.*//'`}

STORM_URL=${STORM_URL:-''}

MIRROR=${MIRROR:-"http://www.gtlib.gatech.edu/pub"}

function help {
  cat <<USAGE
Usage: bin/build-release.sh [<storm.tar.gz>]
  clean                     Cleans working files and directories created when
                              building.
  mvnPackage                Runs the maven targets necessary to build the Storm
                              Mesos framework.
  prePackage <storm.tar.gz> Prepares the working directories to be able to
                              package the Storm Mesos framework.
  package                   Packages the Storm Mesos Framework.
  downloadStormRelease      A utility function to download the Storm release zip
                              for the targeted storm release.
  dockerImage               Build a dockerImage from the current code. Not
                              part of the standard steps from a raw invocation of
                              bin/build-release.sh.

  ENV
    MIRROR          Specify Apache Storm Mirror to download from
                      Default: ${MIRROR}
    STORM_RELEASE   The targeted release version of Storm
                      Default: ${STORM_RELEASE}
    MESOS_RELEASE   The targeted release version of MESOS
                      Default: ${MESOS_RELEASE}
    STORM_URL       Override the URL for downloading the storm binary
                      NOTE: ensure version matches with STORM_RELEASE

USAGE
}; function --help { help ;}; function -h { help ;}

function downloadStormRelease {
  if [ ! -f apache-storm-${STORM_RELEASE}.tar.gz ]; then
    if [ -z ${STORM_URL} ]; then
      curl -L -O ${MIRROR}/apache/storm/apache-storm-${STORM_RELEASE}/apache-storm-${STORM_RELEASE}.tar.gz
    else
      curl -L -O ${STORM_URL}
    fi
  fi
}

function clean {
  _rm _release
  _rm lib/ classes/
  _rm target
  _rm *mesos*.tgz
  _rm *storm*tar.gz
}

function mvnPackage {
  mvn clean package -P$PROFILE -Dstorm.version=$STORM_RELEASE -Dmesos.version=$MESOS_RELEASE
}

function prePackage {(
  _rm _release
  mkdir -p _release
  cp $1 _release/.
  cd _release
  tar xvf $1
  _rm $1
)}

function package {(
  local stormDir=`find _release -maxdepth 1 -type d -name "*storm*"`
  _rm $stormDir/*.jar

  # copies storm-mesos jar over
  # We only want the shaded jar. Its important to remove the original
  # jar so we dont have both shaded as well as original jar in the classpath
  # for mesos nimbus
  cp storm/target/storm-mesos-${RELEASE}-storm${STORM_RELEASE}-mesos${MESOS_RELEASE}.jar $stormDir/lib
  cp bin/storm-mesos $stormDir/bin/
  cp bin/run-with-marathon.sh $stormDir/bin/
  chmod +x $stormDir/bin/*
  mkdir -p $stormDir/native
  cp storm.yaml $stormDir/conf/storm.yaml

  local dirName="storm-mesos-${RELEASE}-storm${STORM_RELEASE}-mesos${MESOS_RELEASE}"
  local tarName="${dirName}.tgz"
  cd _release
  # When supervisor starts up it looks for storm-mesos not apache-storm.
  mv apache-storm-${STORM_RELEASE} ${dirName}
  tar cvzf ${tarName} --numeric-owner --owner 0 --group 0 ${dirName}
  echo "Copying ${tarName} to $(cd .. && pwd)/${tarName}"
  cp ${tarName} ../

  # create logs dir for MesosNimbus to use -- when you rebuild this package and are using the
  # vagrant setup in this repo, the virtualbox shared-file driver gets confused about whether
  # the logs dir is really there or not, since it is being deleted when we rebuild.
  mkdir ${dirName}/logs

  cd ..
)}

function dockerImage {(
  cmd="docker build \
       --build-arg MESOS_RELEASE=$MESOS_RELEASE \
       --build-arg STORM_RELEASE=$STORM_RELEASE \
       --build-arg MIRROR=$MIRROR \
       --build-arg STORM_URL=$STORM_URL \
        -t mesos/storm:git-`git rev-parse --short HEAD` ."
  echo $cmd
  $cmd
)}

# Ensure we have GNU tar so that we can use options such as --owner, etc.
function ensureCorrectTar {(
  if ! tar --version | grep -q 'GNU tar'; then
    echo "ERROR: 'tar' command is not from GNU.
         Assuming you are on Mac OS X please use homebrew to install gnu-tar and ensure that 'tar' resolves to the
         tar binary from that package.  Please see this page for more info:
           https://apple.stackexchange.com/questions/69223/how-to-replace-mac-os-x-utilities-with-gnu-core-utilities
         The following steps *may* work for you, assuming you have homebrew:
           brew uninstall gnu-tar   # in case you've previously installed gnu-tar but the binary is named 'gtar' instead of 'tar'
           brew install --with-default-names gnu-tar  # install gnu-tar as 'tar'
           hash -r  # resets shell's recorded command paths"
    exit 1
  fi
)}

function main {
  clean
  downloadStormRelease
  mvnPackage
  prePackage apache-storm-${STORM_RELEASE}.tar.gz
  package
}

ensureCorrectTar

######################### Delegates to subcommands or runs main, as appropriate
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | fgrep -qx -- "${1:-}"
then "$@"
else main "$@"
fi


text: select * from j1 where c_double = (select avg(c_integer)*1.2 from j2);


text:
                <button type="button" class="btn btn-default btn-sm" data-ng-click="menuBack()"
                        data-ng-disabled="!currentEventTypeObj">Back
                </button>

                <input type="text" data-ng-model="pathFilter" class="form-control input-sm" placeholder="Filter">

               {{type.label}}

                {{service}}

                {{path}}

                     1"  data-ng-click="setEventList(currentPathObj.name, verb, eventList)" ng-class="{ highlighted: eventList.$$isHighlighted }">{{currentPathObj.name}}{{verb}}

                    <a data-ng-if="eventList.length <= 1" data-ng-click="setScript(event)" data-ng-repeat="event in eventList">{{event}}
                        {{verb}}
                        {{verb}}

                    {{event}}{{currentPathObj.verb}}

                {{service}}

                {{path}}

                     1" data-ng-click="setEventList(currentPathObj.name, verb, eventList)" ng-class="{ highlighted: isHighlightedItem(currentPathObj.name) }">{{currentPathObj.name}}{{verb}}

                    <a data-ng-if="eventList.length <= 1" data-ng-click="setScript(event)" data-ng-repeat="event in eventList">{{event}}
                        {{verb}}
                        {{verb}}

                    {{event}}{{currentPathObj.verb}}

                Script Name
                <input class="form-control" type="text" data-ng-disabled="true"
                       data-ng-model="currentScriptObj.name"/>

                Script Type/Language
                <select class="form-control input-sm"
                        data-ng-model="currentScriptObj.type"
                        data-ng-options="scriptType.name as scriptType.label for scriptType in scriptTypes">
                </select>

                        <input type="checkbox" data-ng-model="currentScriptObj.is_active"/>

                        Active


text:
// Copyright 2018 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Constants for the classroom domain.
 */

export const ClassroomDomainConstants = {
  CLASSROOOM_DATA_URL_TEMPLATE:
    '/classroom_data_handler/<classroom_url_fragment>',
  TOPIC_VIEWER_URL_TEMPLATE: (
    '/learn/<classroom_url_fragment>/<topic_url_fragment>'),
  TOPIC_VIEWER_REVISION_URL_TEMPLATE: (
    '/learn/<classroom_url_fragment>/<topic_url_fragment>/revision'),
  TOPIC_VIEWER_STORY_URL_TEMPLATE: (
    '/learn/<classroom_url_fragment>/<topic_url_fragment>/story')
} as const;


text:
package com.android.camera.ui;

import android.content.Context;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * A manager which notifies the event of a new popup in order to dismiss the
 * old popup if exists.
 */
public class PopupManager {
    private static HashMap<Context, PopupManager> sMap =
            new HashMap<Context, PopupManager>();

    public interface OnOtherPopupShowedListener {
        public void onOtherPopupShowed();
    }

    private PopupManager() {}

    private ArrayList<OnOtherPopupShowedListener> mListeners = new ArrayList();

    public void notifyShowPopup(View view) {
        for (OnOtherPopupShowedListener listener : mListeners) {
            if ((View) listener != view) {
                listener.onOtherPopupShowed();
            }
        }
    }

    public void setOnOtherPopupShowedListener(OnOtherPopupShowedListener listener) {
        mListeners.add(listener);
    }

    public static PopupManager getInstance(Context context) {
        PopupManager instance = sMap.get(context);
        if (instance == null) {
            instance = new PopupManager();
            sMap.put(context, instance);
        }
        return instance;
    }

    public static void removeInstance(Context context) {
        PopupManager instance = sMap.get(context);
        sMap.remove(context);
    }
}


text:
The enumeration that specifies the waiting condition of the component/element.

#### Values

{% include enumvalue.html enum="Until" value="Missing" %}

Waits until the component/element will be missing.

{% include enumvalue.html enum="Until" value="Hidden" %}

Waits until the component/element will be hidden.

{% include enumvalue.html enum="Until" value="MissingOrHidden" %}

Waits until the component/element will be missing or hidden.

{% include enumvalue.html enum="Until" value="Visible" %}

Waits until the component/element will be visible.

{% include enumvalue.html enum="Until" value="VisibleOrHidden" %}

Waits until the component/element will be visible or hidden.

{% include enumvalue.html enum="Until" value="VisibleThenHidden" %}

Waits until the component/element will be visible and then until it will be hidden.

{% include enumvalue.html enum="Until" value="VisibleThenMissing" %}

Waits until the component/element will be visible and then until it will be missing.

{% include enumvalue.html enum="Until" value="VisibleThenMissingOrHidden" %}

Waits until the component/element will be visible and then until it will be missing or hidden.

{% include enumvalue.html enum="Until" value="MissingThenVisible" %}

Waits until the component/element will be missing and then until it will be visible.

{% include enumvalue.html enum="Until" value="HiddenThenVisible" %}

Waits until the component/element will be hidden and then until it will be visible.

{% include enumvalue.html enum="Until" value="MissingOrHiddenThenVisible" %}

Waits until the component/element will be missing or hidden and then until it will be visible.


text:
<?php

namespace Stfalcon\Bundle\PortfolioBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;

/**
 * Project Translation entity.
 *
 * @ORM\Entity()
 * @ORM\Table(name="project_translations",
 *     uniqueConstraints={@ORM\UniqueConstraint(name="project_lookup_unique_idx", columns={
 *         "locale", "object_id", "field"
 *     })}
 * )
 */
class ProjectTranslation extends AbstractPersonalTranslation
{
    /**
     * @ORM\ManyToOne(targetEntity="Project", inversedBy="translations")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $object;

    /**
     * Convenient constructor
     *
     * @param string $locale  locale
     * @param string $field   field
     * @param string $content content
     */
    public function __construct($locale = null, $field = null, $content = null)
    {
        $this->setLocale($locale);
        $this->setField($field);
        $this->setContent($content);
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->getLocale();
    }
}


text:
package storage

import (
	"bytes"
	"context"
	"math"

	"github.com/deepfabric/elasticell/pkg/pb/raftcmdpb"
	"github.com/deepfabric/elasticell/pkg/util"
	gonemo "github.com/deepfabric/go-nemo"
	"github.com/fagongzi/util/format"
	"github.com/fagongzi/util/hack"
)

type nemoZSetEngine struct {
	limiter *util.Limiter
	db      *gonemo.NEMO
}

func newNemoZSetEngine(db *gonemo.NEMO, cfg *NemoCfg) ZSetEngine {
	return &nemoZSetEngine{
		limiter: util.NewLimiter(cfg.LimitConcurrencyWrite),
		db:      db,
	}
}

func (e *nemoZSetEngine) ZAdd(key []byte, score float64, member []byte) (int64, error) {
	e.limiter.Wait(context.TODO())
	n, err := e.db.ZAdd(key, score, member)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZCard(key []byte) (int64, error) {
	e.limiter.Wait(context.TODO())
	n, err := e.db.ZCard(key)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZCount(key []byte, min []byte, max []byte) (int64, error) {
	minF, includeMin, err := parseInclude(min)
	if err != nil {
		return 0, err
	}

	maxF, includeMax, err := parseInclude(max)
	if err != nil {
		return 0, err
	}

	return e.db.ZCount(key, minF, maxF, includeMin, includeMax)
}

func (e *nemoZSetEngine) ZIncrBy(key []byte, member []byte, by float64) ([]byte, error) {
	e.limiter.Wait(context.TODO())
	value, err := e.db.ZIncrby(key, member, by)
	e.limiter.Release()

	return value, err

}

func (e *nemoZSetEngine) ZLexCount(key []byte, min []byte, max []byte) (int64, error) {
	min, includeMin := isInclude(min)
	max, includeMax := isInclude(max)

	return e.db.ZLexcount(key, min, max, includeMin, includeMax)
}

func (e *nemoZSetEngine) ZRange(key []byte, start int64, stop int64) ([]*raftcmdpb.ScorePair, error) {
	scores, values, err := e.db.ZRange(key, start, stop)
	if err != nil {
		return nil, err
	}

	l := len(scores)
	pairs := make([]*raftcmdpb.ScorePair, l)
	for i := 0; i < l; i++ {
		pairs[i] = &raftcmdpb.ScorePair{
			Score:  scores[i],
			Member: values[i],
		}
	}

	return pairs, nil
}

func (e *nemoZSetEngine) ZRangeByLex(key []byte, min []byte, max []byte) ([][]byte, error) {
	min, includeMin := isInclude(min)
	max, includeMax := isInclude(max)

	if len(max) == 1 && max[0] == '+' {
		max[0] = byte('z' + 1)
	}

	return e.db.ZRangebylex(key, min, max, includeMin, includeMax)
}

func (e *nemoZSetEngine) ZRangeByScore(key []byte, min []byte, max []byte) ([]*raftcmdpb.ScorePair, error) {
	minF, includeMin, err := parseInclude(min)
	if err != nil {
		return nil, err
	}

	maxF, includeMax, err := parseInclude(max)
	if err != nil {
		return nil, err
	}

	scores, values, err := e.db.ZRangebyScore(key, minF, maxF, includeMin, includeMax)
	if err != nil {
		return nil, err
	}

	l := len(scores)
	pairs := make([]*raftcmdpb.ScorePair, l)
	for i := 0; i < l; i++ {
		pairs[i] = &raftcmdpb.ScorePair{
			Score:  scores[i],
			Member: values[i],
		}
	}

	return pairs, nil
}

func (e *nemoZSetEngine) ZRank(key []byte, member []byte) (int64, error) {
	return e.db.ZRank(key, member)
}

func (e *nemoZSetEngine) ZRem(key []byte, members ...[]byte) (int64, error) {
	e.limiter.Wait(context.TODO())
	n, err := e.db.ZRem(key, members...)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZRemRangeByLex(key []byte, min []byte, max []byte) (int64, error) {
	min, includeMin := isInclude(min)
	max, includeMax := isInclude(max)

	e.limiter.Wait(context.TODO())
	n, err := e.db.ZRemrangebylex(key, min, max, includeMin, includeMax)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZRemRangeByRank(key []byte, start int64, stop int64) (int64, error) {
	e.limiter.Wait(context.TODO())
	n, err := e.db.ZRemrangebyrank(key, start, stop)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZRemRangeByScore(key []byte, min []byte, max []byte) (int64, error) {
	minF, includeMin, err := parseInclude(min)
	if err != nil {
		return 0, err
	}

	maxF, includeMax, err := parseInclude(max)
	if err != nil {
		return 0, err
	}

	e.limiter.Wait(context.TODO())
	n, err := e.db.ZRemrangebyscore(key, minF, maxF, includeMin, includeMax)
	e.limiter.Release()

	return n, err
}

func (e *nemoZSetEngine) ZScore(key []byte, member []byte) ([]byte, error) {
	exists, value, err := e.db.ZScore(key, member)
	if !exists {
		return nil, err
	}

	return format.Float64ToString(value), err
}

func isInclude(value []byte) ([]byte, bool) {
	include := value[0] != '('
	if value[0] == '(' || value[0] == '[' {
		value = value[1:]
	}

	return value, !include
}

var (
	max = []byte("+inf")
	min = []byte("-inf")
)

func parseInclude(value []byte) (float64, bool, error) {
	value, include := isInclude(value)
	if bytes.Compare(value, max) == 0 {
		return math.MaxFloat64, include, nil
	} else if bytes.Compare(value, min) == 0 {
		return math.SmallestNonzeroFloat64, include, nil
	}

	valueF, err := format.ParseStrFloat64(hack.SliceToString(value))
	return valueF, include, err
}


text:
class Article < ActiveRecord::Base
  validates :title, :excerpt, :content, presence: true
  validates :title, :excerpt, :content, uniqueness: true

  has_many :images
end


text:
To install, use `go get`:

```bash
$ go get -d github.com/Yoshiki Aoki/todo
```

## Contribution

1. Fork ([https://github.com/Yoshiki Aoki/todo/fork](https://github.com/Yoshiki Aoki/todo/fork))
1. Create a feature branch
1. Commit your changes
1. Rebase your local changes against the master branch
1. Run test suite with the `go test ./...` command and confirm that it passes
1. Run `gofmt -s`
1. Create a new Pull Request

## Author

[Yoshiki Aoki](https://github.com/Yoshiki Aoki)


text:
package org.hibernate.test.annotations.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

@TypeDef(
	typeClass = PhoneNumberType.class
)

/**
 * @author Sharath Reddy
 *
 */
@Entity
public class LocalContactDetails {

	@Id
	@GeneratedValue
	private int id;

	private PhoneNumber localPhoneNumber;
	@Type(type="phoneNumber")
	private OverseasPhoneNumber overseasPhoneNumber;

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public PhoneNumber getLocalPhoneNumber() {
		return localPhoneNumber;
	}
	public void setLocalPhoneNumber(PhoneNumber localPhoneNumber) {
		this.localPhoneNumber = localPhoneNumber;
	}
	public OverseasPhoneNumber getOverseasPhoneNumber() {
		return overseasPhoneNumber;
	}
	public void setOverseasPhoneNumber(OverseasPhoneNumber overseasPhoneNumber) {
		this.overseasPhoneNumber = overseasPhoneNumber;
	}

}


text:
package com.greenbird.configuration.properties;

import org.constretto.resolver.ConfigurationContextResolver;
import org.springframework.core.env.Environment;

import java.util.Arrays;
import java.util.List;

public class GreenbirdConfigurationContextResolver implements ConfigurationContextResolver {
    private Environment environment;

    public GreenbirdConfigurationContextResolver(Environment environment) {
        this.environment = environment;
    }

    public List<String> getTags() {
        return Arrays.asList(environment.getActiveProfiles());
    }
}


text:
comments: true
date: 2009-09-21 04:40:00
layout: post
slug: mission-control-we-have-lift-off-well-kind-of
title: Mission Control...we have lift off!!! well...kind of
wordpress_id: 22
categories:
- Banshee
- Summer of Code
tags:
- Banshee
- GNOME
- SoC
- Telepathy
---

Well, well. The [Telepathy](http://telepathy.freedesktop.org/wiki/) folks have successfully migrated [Empathy to Mission Control 5.](http://www.mail-archive.com/telepathy@lists.freedesktop.org/msg03386.html) While they were probably plugging away, trying to get this migration completed, I was secretly (and sometimes openly) hoping the migration would not get done until after I was done [GSoC](http://code.google.com/soc/).

What do you know. Dreams do come true. GSoC is over.  I survived without having to port to MC5. But, that doesn't mean I don't have anymore work to do. I've already started [porting my Telepathy extension](http://github.com/nloko/banshee/tree/mc5) to the new Mission Control interfaces.

So far, there's nothing exciting to brag about. I've done enough work to prevent the extension from crashing. By using various bits of the new [AccountManager](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.AccountManager.html) and [Account](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Account.html) interfaces, it can find connections and load up who else is online and running the Telepathy extension. What's left? LOTS!

Instead of using the [ContactCapabilities](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Connection.Interface.ContactCapabilities.html) interface to advertise what channels Banshee is going to handle, I need to start using the new method of exporting a DBus object that implements [org.freedesktop.Telepathy.](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Client.html)

[Client](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Client.html) and [org.freedesktop.Telepathy.](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Client.Handler.html)[Client.Handler](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Client.Handler.html). And, I will need to re-work my existing stuff in the extension to manage creating and handling new channels (ie. tubes, file transfers, etc.) using these new interfaces and the [org.freedesktop.Telepathy.](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.ChannelDispatcher.html)

[ChannelDispatcher](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.ChannelDispatcher.html) interface instead of the [Requests](http://telepathy.freedesktop.org/spec/org.freedesktop.Telepathy.Connection.Interface.Requests.html) interface. I'm not even sure if I know what all of this means yet. But, I guess figuring it out is part of the fun.

In addition to depending on Mission Control 5, the extension will also have a dependancy on Mono 2.4. Thanks to [packages from directhex](https://launchpad.net/%7Edirecthex/+archive/monoxide), upgrading from 2.0 was a piece of cake. The need for 2.4 is to get around a [bug](https://bugzilla.novell.com/show_bug.cgi?id=481687) that can no longer be avoided.

I wanted to get some more work done this weekend, but I was too busy playing tennis and eating Dim Sum. However, I will devote some more time to this soon. I am setting a goal for myself to get this done before Ubuntu Karmic is released on October 29th. I have two weddings, one in NY and another in Toronto, in October. So, hopefully, I will be sober enough in between to get some things accomplished.


text:
PROJECT = cowboy_livereload

# dependencies

DEPS = privdir fast_key jsxn jsx

dep_privdir = git https://github.com/camshaft/privdir
dep_fast_key = git https://github.com/camshaft/fast_key
dep_jsx = git https://github.com/camshaft/jsx develop
dep_jsxn = git https://github.com/talentdeficit/jsxn

include erlang.mk


text:
layout: home
---
# About Me

I like to do things like things, you know.

Also blah.

Yee.


text:
{% load i18n %}
{% if object_list %}
    {% if is_searching %}

        {% blocktrans count counter=object_list.count %}
            There is one match
        {% plural %}
            There are {{ counter }} matches
        {% endblocktrans %}

    {% else %}

{% trans 'Components' %}

    {% endif %}
    {% include 'wagtailaddresses/component-chooser/list.html' with choosing=1 %}
    {% include 'wagtailadmin/shared/pagination_nav.html' with items=page is_ajax=1 %}
{% else %}

{% blocktrans %}Sorry, no items match "{{ query_string }}"{% endblocktrans %}

{% endif %}


text:
{-# LANGUAGE BangPatterns  #-}
{-# LANGUAGE MagicHash, UnboxedTuples, PatternGuards, ScopedTypeVariables, RankNTypes #-}
-- | Concurrent queue for single reader, single writer
module Control.Distributed.Process.Internal.CQueue
  ( CQueue
  , BlockSpec(..)
  , MatchOn(..)
  , newCQueue
  , enqueue
  , enqueueSTM
  , dequeue
  , mkWeakCQueue
  , queueSize
  ) where

import Prelude hiding (length, reverse)
import Control.Concurrent.STM
  ( atomically
  , STM
  , TChan
  , TVar
  , modifyTVar'
  , tryReadTChan
  , newTChan
  , newTVarIO
  , writeTChan
  , readTChan
  , readTVarIO
  , orElse
  , retry
  )
import Control.Applicative ((<$>), (<*>))
import Control.Exception (mask_, onException)
import System.Timeout (timeout)
import Control.Distributed.Process.Internal.StrictMVar
  ( StrictMVar(StrictMVar)
  , newMVar
  , takeMVar
  , putMVar
  )
import Control.Distributed.Process.Internal.StrictList
  ( StrictList(..)
  , append
  )
import Data.Maybe (fromJust)
import Data.Traversable (traverse)
import GHC.MVar (MVar(MVar))
import GHC.IO (IO(IO))
import GHC.Prim (mkWeak#)
import GHC.Weak (Weak(Weak))

-- We use a TCHan rather than a Chan so that we have a non-blocking read
data CQueue a = CQueue (StrictMVar (StrictList a)) -- Arrived
                       (TChan a)                   -- Incoming
                       (TVar Int)                 -- Queue size

newCQueue :: IO (CQueue a)
newCQueue = CQueue <$> newMVar Nil <*> atomically newTChan <*> newTVarIO 0

-- | Enqueue an element
--
-- Enqueue is strict.
enqueue :: CQueue a -> a -> IO ()
enqueue c !a = atomically (enqueueSTM c a)

-- | Variant of enqueue for use in the STM monad.
enqueueSTM :: CQueue a -> a -> STM ()
enqueueSTM (CQueue _arrived incoming size) !a = do
   writeTChan incoming a
   modifyTVar' size succ

data BlockSpec =
    NonBlocking
  | Blocking
  | Timeout Int

data MatchOn m a
 = MatchMsg  (m -> Maybe a)
 | MatchChan (STM a)

type MatchChunks m a = [Either [m -> Maybe a] [STM a]]

chunkMatches :: [MatchOn m a] -> MatchChunks m a
chunkMatches [] = []
chunkMatches (MatchMsg m : ms) = Left (m : chk) : chunkMatches rest
   where (chk, rest) = spanMatchMsg ms
chunkMatches (MatchChan r : ms) = Right (r : chk) : chunkMatches rest
   where (chk, rest) = spanMatchChan ms

spanMatchMsg :: [MatchOn m a] -> ([m -> Maybe a], [MatchOn m a])
spanMatchMsg [] = ([],[])
spanMatchMsg (m : ms)
    | MatchMsg msg <- m = (msg:msgs, rest)
    | otherwise         = ([], m:ms)
    where !(msgs,rest) = spanMatchMsg ms

spanMatchChan :: [MatchOn m a] -> ([STM a], [MatchOn m a])
spanMatchChan [] = ([],[])
spanMatchChan (m : ms)
    | MatchChan stm <- m = (stm:stms, rest)
    | otherwise          = ([], m:ms)
    where !(stms,rest)  = spanMatchChan ms

-- | Dequeue an element
--
-- The timeout (if any) is applied only to waiting for incoming messages, not
-- to checking messages that have already arrived
dequeue :: forall m a.
           CQueue m          -- ^ Queue
        -> BlockSpec         -- ^ Blocking behaviour
        -> [MatchOn m a]     -- ^ List of matches
        -> IO (Maybe a)      -- ^ 'Nothing' only on timeout
dequeue (CQueue arrived incoming size) blockSpec matchons = mask_ $ decrementJust $
  case blockSpec of
    Timeout n -> timeout n $ fmap fromJust run
    _other    ->
       case chunks of
         [Right ports] -> -- channels only, this is easy:
           case blockSpec of
             NonBlocking -> atomically $ waitChans ports (return Nothing)
             _           -> atomically $ waitChans ports retry
                              -- no onException needed
         _other -> run
  where
    -- Decrement counter is smth is returned from the queue,
    -- this is safe to use as method is called under a mask
    -- and there is no 'unmasked' operation inside
    decrementJust f =
       traverse (either return (\x -> decrement >> return x)) =<< f
    decrement = atomically $ modifyTVar' size pred

    chunks = chunkMatches matchons

    run = do
           arr <- takeMVar arrived
           let grabNew xs = do
                 r <- atomically $ tryReadTChan incoming
                 case r of
                   Nothing -> return xs
                   Just x  -> grabNew (Snoc xs x)
           arr' <- grabNew arr
           goCheck chunks arr'

    waitChans ports on_block =
        foldr orElse on_block (map (fmap (Just . Left)) ports)

    --
    -- First check the MatchChunks against the messages already in the
    -- mailbox.  For channel matches, we do a non-blocking check at
    -- this point.
    --
    goCheck :: MatchChunks m a
            -> StrictList m  -- messages to check, in this order
            -> IO (Maybe (Either a a))

    goCheck [] old = goWait old

    goCheck (Right ports : rest) old = do
      r <- atomically $ waitChans ports (return Nothing) -- does not block
      case r of
        Just _  -> returnOld old r
        Nothing -> goCheck rest old

    goCheck (Left matches : rest) old = do
           -- checkArrived might in principle take arbitrary time, so
           -- we ought to call restore and use an exception handler.  However,
           -- the check is usually fast (just a comparison), and the overhead
           -- of passing around restore and setting up exception handlers is
           -- high.  So just don't use expensive matchIfs!
      case checkArrived matches old of
        (old', Just r)  -> returnOld old' (Just (Right r))
        (old', Nothing) -> goCheck rest old'
          -- use the result list, which is now left-biased

    --
    -- Construct an STM transaction that looks at the relevant channels
    -- in the correct order.
    --
    mkSTM :: MatchChunks m a -> STM (Either m a)
    mkSTM [] = retry
    mkSTM (Left _ : rest)
      = fmap Left (readTChan incoming) `orElse` mkSTM rest
    mkSTM (Right ports : rest)
      = foldr orElse (mkSTM rest) (map (fmap Right) ports)

    waitIncoming :: IO (Maybe (Either m a))
    waitIncoming = case blockSpec of
      NonBlocking -> atomically $ fmap Just stm `orElse` return Nothing
      _           -> atomically $ fmap Just stm
     where
      stm = mkSTM chunks

    --
    -- The initial pass didn't find a message, so now we go into blocking
    -- mode.
    --
    -- Contents of 'arrived' from now on is (old ++ new), and
    -- messages that arrive are snocced onto new.
    --
    goWait :: StrictList m -> IO (Maybe (Either a a))
    goWait old = do
      r <- waitIncoming `onException` putMVar arrived old
      case r of
        --  Nothing => non-blocking and no message
        Nothing -> returnOld old Nothing
        Just e  -> case e of
          --
          -- Left => message arrived in the process mailbox.  We now have to
          -- run through the MatchChunks checking each one, because we might
          -- have a situation where the first chunk fails to match and the
          -- second chunk is a channel match and there *is* a message in the
          -- channel.  In that case the channel wins.
          --
          Left m -> goCheck1 chunks m old
          --
          -- Right => message arrived on a channel first
          --
          Right a -> returnOld old (Just (Left a))

    --
    -- A message arrived in the process inbox; check the MatchChunks for
    -- a valid match.
    --
    goCheck1 :: MatchChunks m a
             -> m               -- single message to check
             -> StrictList m    -- old messages we have already checked
             -> IO (Maybe (Either a a))

    goCheck1 [] m old = goWait (Snoc old m)

    goCheck1 (Right ports : rest) m old = do
      r <- atomically $ waitChans ports (return Nothing) -- does not block
      case r of
        Nothing -> goCheck1 rest m old
        Just _  -> returnOld (Snoc old m) r

    goCheck1 (Left matches : rest) m old = do
      case checkMatches matches m of
        Nothing -> goCheck1 rest m old
        Just p  -> returnOld old (Just (Right p))

    -- a common pattern for putting back the arrived queue at the end
    returnOld :: StrictList m -> Maybe (Either a a) -> IO (Maybe (Either a a))
    returnOld old r = do putMVar arrived old; return r

    -- as a side-effect, this left-biases the list
    checkArrived :: [m -> Maybe a] -> StrictList m -> (StrictList m, Maybe a)
    checkArrived matches list = go list Nil
      where
        go Nil Nil           = (Nil, Nothing)
        go Nil r             = go r Nil
        go (Append xs ys) tl = go xs (append ys tl)
        go (Snoc xs x)    tl = go xs (Cons x tl)
        go (Cons x xs)    tl
          | Just y <- checkMatches matches x = (append xs tl, Just y)
          | otherwise = let !(rest,r) = go xs tl in (Cons x rest, r)

    checkMatches :: [m -> Maybe a] -> m -> Maybe a
    checkMatches []     _ = Nothing
    checkMatches (m:ms) a = case m a of Nothing -> checkMatches ms a
                                        Just b  -> Just b

-- | Weak reference to a CQueue
mkWeakCQueue :: CQueue a -> IO () -> IO (Weak (CQueue a))
mkWeakCQueue m@(CQueue (StrictMVar (MVar m#)) _ _) f = IO $ \s ->
  case mkWeak# m# m f s of (# s1, w #) -> (# s1, Weak w #)

queueSize :: CQueue a -> IO Int
queueSize (CQueue _ _ size) = readTVarIO size


text:
<!DOCTYPE html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Introduction to VPBank package • VPBank</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<link href="../pkgdown.css" rel="stylesheet">
<meta property="og:title" content="Introduction to VPBank package">
<meta property="og:description" content="">
<meta name="twitter:card" content="summary">

      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">

      </button>

        VPBank
        1.1

  Get started

  Reference

    Articles

      Automate DEA analysis with `compare_group` & `map`

  Changelog

Introduction to VPBank package

Anh Hoang Duc (anhhd3@vpbank.com.vn)

2018-12-13

VPBank.Rmd

When working in BICC - VPBank, there are some common questions that a data analyst has to solve:

How could I find potential customers for a given product?

What does it look like the frequent patterns of customers?

What is the retention rate/ cohort behaviour of customers?

What does the customer behavior flows look like?

How does one variable differ among various group?

So, this package was created to solve such problems so as to release time for data analysts within BICC - VPBank. There are 4 main functionalities of the package:

Finding customers' behaviours using apriori algrorithm and shiny app, thereby finding potential customers for a given product with propensity (or lift) score. With very little knowled of R code, one can easily find potential customers and overall behaviours.

Automate building cohort model/ dataframe structure for retention analysis, including both traditional approach and the new one proposed by Anh Hoang Duc, BICC.

Automate converting a dataframe to a new one for drawing sankey chart.

Automate comparison analysis among groups, including descriptive analysis, anova analyis and drawing box plots among groups

Each section below decribes all functions that support each part of above functionalities.

#Customer behaviours

There are 5 functions:

convert_dummy: Convert a dataframe with factors, numeric variables into dummy dataframe. See more detail ?convert_dummy

transaction_convert: Convert a dataframe to transaction data. See more detail ?transaction_convert

customer_behavior: Shiny app that automatically finds frequent patterns. See more detail ?customer_behavior

customer_behavior_targetted: Shiny app that automatically finds frequent patterns with a given product as the target product. It also supports exporting a list of potential customers with full statistics for cross selling. See more detail ?customer_behavior

customer_behavior: Shiny app that automatically finds frequent patterns with a given product as the rooted product. See more detail ?customer_behavior

#Cohort analysis

calculate_retention_ordinary: Convert a dataframe to a cohort dataframe as typical cohort model. Each cohort does not contain a customer from other cohorts. See more detail ?calculate_retention_ordinary

calculate_retention: Automatically convert a dataframe to a cohort data frame, allowing cutomers to exist in many cohorts. See more detail ?calculate_retention

Example: Taking all functions above

data <- iris %>%
  mutate(id = seq(1:nrow(iris))) %>%
  select(ncol(.), 1:(ncol(.)-1))
data <- convert_dummy(data, no.category = 2)
trans <- data %>% transaction_convert()
customer_behavior_targetted(trans, data)

#Customer flow analysis

sankey_convert: Convert a dataframe to a new structure for sankey chart. See more detail ?sankey_convert

sankey_convert_first_product: Convert a dataframe to a new structure for sankey chart with a given product as the first product. See more detail ?sankey_convert_first_product

#Compare a variable in two group

compare_2var: Automatically compare one variable with another factor variable. See more detail ?compare_2var

Developed by Anh Hoang Duc.

Site built with pkgdown.


text:
package EDU.purdue.jtb.parser;

import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * This package contains data created as a result of parsing and semanticizing a JavaCC input file.
 * This data is what is used by the back-ends of JavaCC as well as any other back-end of JavaCC
 * related tools such as JJTree.
 *
 * @author Marc Mazas
 * @version 1.4.0 : 05/2009 : MMa : adapted to JavaCC v4.2 grammar
 * @version 1.4.8 : 12/2014 : MMa : improved javadoc
 */
public class JavaCCGlobals {

  /**
   * String that identifies the JavaCC generated files.
   */
  protected static final String toolName = "JavaCC";

  /**
   * The name of the grammar file being processed.
   */
  static public String          fileName;

  /**
   * The name of the original file (before processing by JJTree). Currently this is the same as
   * fileName.
   */
  static public String          origFileName;

  /**
   * Set to true if this file has been processed by JJTree.
   */
  static public boolean         jjtreeGenerated;

  /**
   * The list of tools that have participated in generating the input grammar file.
   */
  static public List<String>    toolNames;

  /**
   * This prints the banner line when the various tools are invoked.
   *
   * @param fullName - the tool full name
   * @param ver - the tool version
   */
  static public void bannerLine(final String fullName, final String ver) {
    System.out.print("Java Compiler Compiler Version " + Version.version + " (" + fullName);
    if (!ver.equals("")) {
      System.out.print(" Version " + ver);
    }
    System.out.println(")");
  }

  /**
   * The name of the parser class (what appears in PARSER_BEGIN and PARSER_END).
   */
  static public String                                                                cu_name;

  /**
   * This is a list of tokens that appear after "PARSER_BEGIN(name)" all the way until (but not
   * including) the opening brace "{" of the class "name".
   */
  static public List<Token>                                                           cu_to_insertion_point_1   = new ArrayList<Token>();

  /**
   * This is the list of all tokens that appear after the tokens in "cu_to_insertion_point_1" and
   * until (but not including) the closing brace "}" of the class "name".
   */
  static public List<Token>                                                           cu_to_insertion_point_2   = new ArrayList<Token>();

  /**
   * This is the list of all tokens that appear after the tokens in "cu_to_insertion_point_2" and
   * until "PARSER_END(name)".
   */
  static public List<Token>                                                           cu_from_insertion_point_2 = new ArrayList<Token>();

  /**
   * A list of all grammar productions - normal and JAVACODE - in the order they appear in the input
   * file. Each entry here will be a subclass of "NormalProduction".
   */
  static public List<NormalProduction>                                                bnfproductions            = new ArrayList<NormalProduction>();

  /**
   * A symbol table of all grammar productions - normal and JAVACODE. The symbol table is indexed by
   * the name of the left hand side non-terminal. Its contents are of type "NormalProduction".
   */
  static public Map<String, NormalProduction>                                         production_table          = new HashMap<String, NormalProduction>();

  /**
   * A mapping of lexical state strings to their integer internal representation. Integers are
   * stored as java.lang.Integer's.
   */
  static public Map<String, Integer>                                                  lexstate_S2I              = new Hashtable<String, Integer>();

  /**
   * A mapping of the internal integer representations of lexical states to their strings. Integers
   * are stored as java.lang.Integer's.
   */
  static public Hashtable<Integer, String>                                            lexstate_I2S              = new Hashtable<Integer, String>();

  /**
   * The declarations to be inserted into the TokenManager class.
   */
  static public List<Token>                                                           token_mgr_decls;

  /**
   * The list of all TokenProductions from the input file. This list includes implicit
   * TokenProductions that are created for uses of regular expressions within BNF productions.
   */
  static public List<TokenProduction>                                                 rexprlist                 = new ArrayList<TokenProduction>();

  /**
   * The total number of distinct tokens. This is therefore one more than the largest assigned token
   * ordinal.
   */
  static public int                                                                   tokenCount;

  /**
   * This is a symbol table that contains all named tokens (those that are defined with a label).
   * The index to the table is the image of the label and the contents of the table are of type
   * "RegularExpression_".
   */
  static public Map<String, RegularExpression_>                                       named_tokens_table        = new HashMap<String, RegularExpression_>();

  /**
   * Contains the same entries as "named_tokens_table", but this is an ordered list which is ordered
   * by the order of appearance in the input file.
   */
  static public List<RegularExpression_>                                              ordered_named_tokens      = new ArrayList<RegularExpression_>();

  /**
   * A mapping of ordinal values (represented as objects of type "Integer") to the corresponding
   * labels (of type "String"). An entry exists for an ordinal value only if there is a labeled
   * token corresponding to this entry. If there are multiple labels representing the same ordinal
   * value, then only one label is stored.
   */
  static public Map<Integer, String>                                                  names_of_tokens           = new HashMap<Integer, String>();

  /**
   * A mapping of ordinal values (represented as objects of type "Integer") to the corresponding
   * RegularExpression_'s.
   */
  static public Map<Integer, RegularExpression_>                                      rexps_of_tokens           = new HashMap<Integer, RegularExpression_>();

  /**
   * This is a three-level symbol table that contains all simple tokens (those that are defined
   * using a single string (with or without a label). The index to the first level table is a
   * lexical state which maps to a second level hashtable. The index to the second level hashtable
   * is the string of the simple token converted to upper case, and this maps to a third level
   * hashtable. This third level hashtable contains the actual string of the simple token and maps
   * it to its RegularExpression_.
   */
  static public Map<String, Hashtable<String, Hashtable<String, RegularExpression_>>> simple_tokens_table       = new Hashtable<String, Hashtable<String, Hashtable<String, RegularExpression_>>>();

  /** Mask index shared between ParseEngine and ParseGen */
  static protected int                                                                maskindex                 = 0;
  /** jj2 methods calls index shared between ParseEngine and ParseGen */
  static protected int                                                                jj2index                  = 0;
  /** True if lookahead needed, false otherwise */
  public static boolean                                                               lookaheadNeeded;
  /** Mask values shared between ParseEngine and ParseGen */
  static protected List<int[]>                                                        maskVals                  = new ArrayList<int[]>();

  /** The {@link Action} on end of file */
  static Action                                                                       actForEof;
  /** The next state for end of file */
  static String                                                                       nextStateForEof;

  // Some general purpose utilities follow.

  /**
   * @param tn - a toolname
   * @param fn - a file name
   * @return the identifying string for the file name, given a toolname used to generate it
   */
  public static String getIdString(final String tn, final String fn) {
    final List<String> tns = new ArrayList<String>();
    tns.add(tn);
    return getIdString(tns, fn);
  }

  /**
   * @param tns - a list of toolnames
   * @param fn - a file name
   * @return the identifying string for the file name, given a set of tool names that are used to
   *         generate it
   */
  public static String getIdString(final List<String> tns, final String fn) {
    int i;
    String toolNamePrefix = "Generated By:";

    for (i = 0; i < tns.size() - 1; i++)
      toolNamePrefix += tns.get(i) + "&";
    toolNamePrefix += tns.get(i) + ":";

    if (toolNamePrefix.length() > 200) {
      System.out.println("Tool names too long.");
      throw new Error();
    }

    return toolNamePrefix + " Do not edit this line. " + addUnicodeEscapes(fn);
  }

  /**
   * @param tn - a toolname
   * @param fn - a file name
   * @return true if tool name passed is one of the tool names returned by
   *         {@link #getToolNames(String)}getToolNames
   */
  public static boolean isGeneratedBy(final String tn, final String fn) {
    final List<String> v = getToolNames(fn);

    for (int i = 0; i < v.size(); i++)
      if (tn.equals(v.get(i)))
        return true;

    return false;
  }

  /**
   * @param str - a string containing toolnames
   * @return - a list of toolnames from the string splitted around ':' and '&'
   */
  private static List<String> makeToolNameList(final String str) {
    final List<String> retVal = new ArrayList<String>();

    int limit1 = str.indexOf('\n');
    if (limit1 == -1)
      limit1 = 1000;
    int limit2 = str.indexOf('\r');
    if (limit2 == -1)
      limit2 = 1000;
    final int limit = (limit1 < limit2) ? limit1 : limit2;

    String tmp;
    if (limit == 1000) {
      tmp = str;
    } else {
      tmp = str.substring(0, limit);
    }

    if (tmp.indexOf(':') == -1)
      return retVal;

    tmp = tmp.substring(tmp.indexOf(':') + 1);

    if (tmp.indexOf(':') == -1)
      return retVal;

    tmp = tmp.substring(0, tmp.indexOf(':'));

    int i = 0, j = 0;

    while (j < tmp.length() && (i = tmp.indexOf('&', j)) != -1) {
      retVal.add(tmp.substring(j, i));
      j = i + 1;
    }

    if (j < tmp.length())
      retVal.add(tmp.substring(j));

    return retVal;
  }

  /**
   * @param fn - a file name
   * @return the list of names of the tools that have been used to generate the given file
   */
  public static List<String> getToolNames(final String fn) {
    final char[] buf = new char[256];
    java.io.FileReader stream = null;
    int read, total = 0;

    try {
      stream = new java.io.FileReader(fn);

      for (;;)
        if ((read = stream.read(buf, total, buf.length - total)) != -1) {
          if ((total += read) == buf.length)
            break;
        } else
          break;

      return makeToolNameList(new String(buf, 0, total));
    }
    catch (final java.io.FileNotFoundException e1) {
    }
    catch (final java.io.IOException e2) {
      if (total > 0)
        return makeToolNameList(new String(buf, 0, total));
    }
    finally {
      if (stream != null)
        try {
          stream.close();
        }
        catch (final Exception e3) {
        }
    }

    return new ArrayList<String>();
  }

  /**
   * Creates an output directory.
   *
   * @param outputDir - the output directory to be created
   */
  public static void createOutputDir(final File outputDir) {
    if (!outputDir.exists()) {
      JavaCCErrors.warning("Output directory \"" + outputDir +
                           "\" does not exist. Creating the directory.");

      if (!outputDir.mkdirs()) {
        JavaCCErrors.semantic_error("Cannot create the output directory : " + outputDir);
        return;
      }
    }

    if (!outputDir.isDirectory()) {
      JavaCCErrors.semantic_error("\"" + outputDir + " is not a valid output directory.");
      return;
    }

    if (!outputDir.canWrite()) {
      JavaCCErrors.semantic_error("Cannot write to the output output directory : \"" + outputDir +
                                  "\"");
      return;
    }
  }

  /**
   * @return the "static " string if the static option is set, otherwise the empty string
   */
  static public String staticOpt() {
    if (Options.getStatic()) {
      return "static ";
    } else {
      return "";
    }
  }

  /**
   * @param str - a string
   * @return the escaped string for common characters
   */
  static public String add_escapes(final String str) {
    String retval = "";
    char ch;
    for (int i = 0; i < str.length(); i++) {
      ch = str.charAt(i);
      if (ch == '\b') {
        retval += "\\b";
      } else if (ch == '\t') {
        retval += "\\t";
      } else if (ch == '\n') {
        retval += "\\n";
      } else if (ch == '\f') {
        retval += "\\f";
      } else if (ch == '\r') {
        retval += "\\r";
      } else if (ch == '\"') {
        retval += "\\\"";
      } else if (ch == '\'') {
        retval += "\\\'";
      } else if (ch == '\\') {
        retval += "\\\\";
      } else if (ch < 0x20 || ch > 0x7e) {
        final String s = "0000" + Integer.toString(ch, 16);
        retval += "\\u" + s.substring(s.length() - 4, s.length());
      } else {
        retval += ch;
      }
    }
    return retval;
  }

  /**
   * @param str - a string
   * @return the escaped string for unicode characters
   */
  static public String addUnicodeEscapes(final String str) {
    final int strlen = str.length();
    final StringBuilder retval = new StringBuilder(2 * strlen);
    char ch;
    for (int i = 0; i < strlen; i++) {
      ch = str.charAt(i);
      if (ch < 0x20 || ch > 0x7e || ch == '\\') {
        final String s = "0000" + Integer.toString(ch, 16);
        retval.append("\\u").append(s.substring(s.length() - 4, s.length()));
      } else {
        retval.append(ch);
      }
    }
    return retval.toString();
  }

  /** The character's line */
  static protected int cline;
  /** The character's column */
  static protected int ccol;

  /**
   * Sets up line and column information for a given token.
   *
   * @param t - a token
   */
  static protected void printTokenSetup(final Token t) {
    Token tt = t;
    while (tt.specialToken != null)
      tt = tt.specialToken;
    cline = tt.beginLine;
    ccol = tt.beginColumn;
  }

  /**
   * Prints a token on a {@link PrintWriter} without the specials.
   *
   * @param t - a token
   * @param out - a {@link PrintWriter}
   */
  static protected void printTokenOnly(final Token t, final PrintWriter out) {
    for (; cline < t.beginLine; cline++) {
      out.println();
      ccol = 1;
    }
    for (; ccol < t.beginColumn; ccol++) {
      out.print(" ");
    }
    if (t.kind == JavaCCParserConstants.STRING_LITERAL ||
        t.kind == JavaCCParserConstants.CHARACTER_LITERAL)
      out.print(addUnicodeEscapes(t.image));
    else
      out.print(t.image);
    cline = t.endLine;
    ccol = t.endColumn + 1;
    final char last = t.image.charAt(t.image.length() - 1);
    if (last == '\n' || last == '\r') {
      cline++;
      ccol = 1;
    }
  }

  /**
   * Prints a token on a {@link PrintWriter} including the specials.
   *
   * @param t - a token
   * @param out - a {@link PrintWriter}
   */
  static protected void printToken(final Token t, final PrintWriter out) {
    Token tt = t.specialToken;
    if (tt != null) {
      while (tt.specialToken != null)
        tt = tt.specialToken;
      while (tt != null) {
        printTokenOnly(tt, out);
        tt = tt.next;
      }
    }
    printTokenOnly(t, out);
  }

  /**
   * Prints a list of tokens on a {@link PrintWriter} without the specials.
   *
   * @param list - a tokens list
   * @param out - a {@link PrintWriter}
   */
  static protected void printTokenList(final List<Token> list, final PrintWriter out) {
    Token t = null;
    for (final Iterator<Token> it = list.iterator(); it.hasNext();) {
      t = it.next();
      printToken(t, out);
    }

    if (t != null)
      printTrailingComments(t, out);
  }

  /**
   * Prints the leading specials of a token on a {@link PrintWriter}.
   *
   * @param t - a token
   * @param out - a {@link PrintWriter}
   */
  static protected void printLeadingComments(final Token t, final PrintWriter out) {
    if (t.specialToken == null)
      return;
    Token tt = t.specialToken;
    while (tt.specialToken != null)
      tt = tt.specialToken;
    while (tt != null) {
      printTokenOnly(tt, out);
      tt = tt.next;
    }
    if (ccol != 1 && cline != t.beginLine) {
      out.println("");
      cline++;
      ccol = 1;
    }
  }

  /**
   * Prints the trailing specials of a token on a {@link PrintWriter}.
   *
   * @param t - a token
   * @param out - a {@link PrintWriter}
   */
  static protected void printTrailingComments(final Token t, final PrintWriter out) {
    if (t.next == null)
      return;
    // printLeadingComments(t.next);
    printLeadingComments(t.next, out);
  }

  /**
   * @param t - a token
   * @return a printing of a token without the specials
   */
  static protected String printTokenOnly(final Token t) {
    String retval = "";
    for (; cline < t.beginLine; cline++) {
      retval += "\n";
      ccol = 1;
    }
    for (; ccol < t.beginColumn; ccol++) {
      retval += " ";
    }
    if (t.kind == JavaCCParserConstants.STRING_LITERAL ||
        t.kind == JavaCCParserConstants.CHARACTER_LITERAL)
      retval += addUnicodeEscapes(t.image);
    else
      retval += t.image;
    cline = t.endLine;
    ccol = t.endColumn + 1;
    final char last = t.image.charAt(t.image.length() - 1);
    if (last == '\n' || last == '\r') {
      cline++;
      ccol = 1;
    }
    return retval;
  }

  /**
   * @param t - a token
   * @return a printing of a token including the specials
   */
  static protected String printToken(final Token t) {
    String retval = "";
    Token tt = t.specialToken;
    if (tt != null) {
      while (tt.specialToken != null)
        tt = tt.specialToken;
      while (tt != null) {
        retval += printTokenOnly(tt);
        tt = tt.next;
      }
    }
    retval += printTokenOnly(t);
    return retval;
  }

  /**
   * @param t - a token
   * @return a printing of the leading specials of a token
   */
  static protected String printLeadingComments(final Token t) {
    String retval = "";
    if (t.specialToken == null)
      return retval;
    Token tt = t.specialToken;
    while (tt.specialToken != null)
      tt = tt.specialToken;
    while (tt != null) {
      retval += printTokenOnly(tt);
      tt = tt.next;
    }
    if (ccol != 1 && cline != t.beginLine) {
      retval += "\n";
      cline++;
      ccol = 1;
    }
    return retval;
  }

  /**
   * @param t - a token
   * @return a printing of the trailing specials of a token
   */
  static protected String printTrailingComments(final Token t) {
    if (t.next == null)
      return "";
    return printLeadingComments(t.next);
  }

  /** Reinitializes */
  public static void reInit() {
    fileName = null;
    origFileName = null;
    jjtreeGenerated = false;
    toolNames = null;
    cu_name = null;
    cu_to_insertion_point_1 = new ArrayList<Token>();
    cu_to_insertion_point_2 = new ArrayList<Token>();
    cu_from_insertion_point_2 = new ArrayList<Token>();
    bnfproductions = new ArrayList<NormalProduction>();
    production_table = new HashMap<String, NormalProduction>();
    lexstate_S2I = new Hashtable<String, Integer>();
    lexstate_I2S = new Hashtable<Integer, String>();
    token_mgr_decls = null;
    rexprlist = new ArrayList<TokenProduction>();
    tokenCount = 0;
    named_tokens_table = new HashMap<String, RegularExpression_>();
    ordered_named_tokens = new ArrayList<RegularExpression_>();
    names_of_tokens = new HashMap<Integer, String>();
    rexps_of_tokens = new HashMap<Integer, RegularExpression_>();
    simple_tokens_table = new Hashtable<String, Hashtable<String, Hashtable<String, RegularExpression_>>>();
    maskindex = 0;
    jj2index = 0;
    maskVals = new ArrayList<int[]>();
    cline = 0;
    ccol = 0;
    actForEof = null;
    nextStateForEof = null;
  }

}


text:
Update feature attributes in an online feature service.

![](screenshot.png)

## Use case

Online feature services can be updated with new data. This is useful for updating existing data in real time while working in the field.

## How to use the sample

To change the feature's damage property, tap the feature to select it, and update the damage type using the drop down.

Features in the map represent damage inspection points and are symbolized based on an attribute specifying the type of damage. Selecting an inspection point displays a callout. The callout contains information about the type of damage. To change the type of damage, select the `information` button in the callout. An editing window appears, allowing you to choose new attribute values. Selecting the `update` button will update the inspection point with the new value.

This is done by first obtaining the inspection point feature after it is selected. Once the feature is obtained, the feature's attribute is updated by calling `setAttributeValue`. To update the feature in the feature table, call `updateFeature` and pass in the edited feature. Finally, to update the service, call `applyEdits` to apply the edits to the service.

## How it works

1. Create a `ServiceFeatureTable` object from a URL.
    * When the table loads, you can get the domain to determine which options to present in your UI.
2. Create a `FeatureLayer` object from the `ServiceFeatureTable`.
3. Select features from the `FeatureLayer`.
4. To update the feature's attribute, first load it, then use the `attributeValue`.
5. Update the table with `updateFeature`.
6. After a change, apply the changes on the server using `applyEdits`.

## Relevant API

* ArcGISFeature
* FeatureLayer
* ServiceFeatureTable

## Tags

amend, attribute, details, edit, editing, information, value


text:
<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\ContactForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;

$this->title = 'Bocconcini';
$PT = 'Contáctenos';
$this->params['breadcrumbs'][] = $PT;
?>

<?= Html::encode($PT) ?>

                <?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>

                        Gracias por contactarnos. Responderemos lo más pronto posible.

                <?php else: ?>

                    Si tiene preguntas de negocio u otras preguntas, por favor llene el siguiente formulario para contactarnos.
                    Gracias.

                <?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>

                    <?= $form->field($model, 'name')->input('text', ['autofocus' => true, 'value'=> isset(Yii::$app->user->identity->name) ? Yii::$app->user->identity->name : '']) ?>

                    <?= $form->field($model, 'email')->input('email', ['value'=> isset(Yii::$app->user->identity->email) ? Yii::$app->user->identity->email : '']) ?>

                    <?= $form->field($model, 'subject') ?>

                    <?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>

                    <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
                        'template' => '

{image}

{input}

',
                    ]) ?>

                        <?= Html::submitButton('Enviar', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>

                <?php ActiveForm::end(); ?>

    <?php endif; ?>


text:
package jp.co.yahoo.dataplatform.mds.hadoop.hive.io;

public interface IJobReporter{

  void incrCounter( final String group , final String counter , final long number );

  void setStatus( final String status );

}


text:
PEERS=$1

CLUSTERSTRING=""
DINV_ASSERT_PEERS=""

#TERMINAL=gnome-terminal -x
TERMINAL=""

#Bulild port and ip number for etcd and dinv assertions
for i in $(seq 1 $PEERS)
do
    #port and ip for etcd
    CLUSTERSTRING=$CLUSTERSTRING"infra"`expr $i - 1`"=http://127.0.0."$i":2380,"
    #port ip for dinv assert default 12000
    DINV_ASSERT_PEERS=$DINV_ASSERT_PEERS"127.0.0."$i":12000,"

done

echo $CLUSTERSTRING

#kill any old clusters
fuser -k 2380/tcp
#remove old databases
rm -r *[0-9].etcd
#install etcd
sudo -E go install ../

#hard coded enviornment variables for testing dinv assertions
#they type of assert to be made
ASSERTTYPE="STRONGLEADER"
#if true only leader asserts
LEADER="false"
#assert with probability 1/SAMPLE
SAMPLE="0"
#true if bugs should be run
DINVBUG="false"
#export assert macros
export LEADER
export ASSERTTYPE
export SAMPLE
export DINVBUG

#itterativly launch the cluster
for i in $(seq 1 $PEERS)
do
    infra="infra"`expr $i - 1`
    #Setup assert names, each node is given an ip port 127.0.0.(id):12000
    DINV_HOSTNAME="NODE"$i
    DINV_ASSERT_LISTEN="127.0.0."$i":12000"
    #export each of the names before launching a node
    export DINV_HOSTNAME
    export DINV_ASSERT_PEERS
    export DINV_ASSERT_LISTEN
    #launch the nodes
    $TERMINAL etcd --name $infra --initial-advertise-peer-urls http://127.0.0.$i:2380 \
      --listen-peer-urls http://127.0.0.$i:2380 \
      --listen-client-urls http://127.0.0.$i:2379,http://127.0.0.$i:2379 \
      --advertise-client-urls http://127.0.0.$i:2379 \
      --initial-cluster-token etcd-cluster-1 \
      --initial-cluster $CLUSTERSTRING \
      --initial-cluster-state new &
done


text:
//#define DEVELOP
//#define DISABLE

using System;
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class Draggable : MonoBehaviour
{
	public InputField InputField;
	public Scratch Scratch;

	public const int DragLimit = 200;

	public void Start()
	{
		Scratch = GetComponent<Scratch>();
	}

#if ((UNITY_STANDALONE_WIN && !UNITY_EDITOR) || DEVELOP) && !DISABLE

	[DllImport("user32.dll")]
	public static extern IntPtr FindWindow(string className, string windowName);

	[DllImport("user32.dll")]
	private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int W, int H, uint uFlags);

	[DllImport("user32.dll")]
	[return: MarshalAs(UnmanagedType.Bool)]
	static extern bool GetCursorPos(out POINT lpPoint);

	[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
	public static extern int GetSystemMetrics(int nIndex);

	[StructLayout(LayoutKind.Sequential)]
	public struct POINT
	{
		public int X;
		public int Y;
		public static implicit operator Vector2(POINT p)
		{
			return new Vector2(p.X, p.Y);
		}
	}

	static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
	const uint SWP_NOSIZE = 0x0001;

	const int SM_CXSCREEN = 0;

	POINT DragStart;
	bool Dragging = true;

	void WndOnMouseDown()
	{
		var hwnd = FindWindow(null, "CooldogAssistant");

		if (hwnd != IntPtr.Zero)
		{
			POINT p;
			GetCursorPos(out p);
			p.X -= Screen.width / 2;
			p.Y -= Screen.width / 4;

			DragStart = p;
			Dragging = false;
		}
	}

	void OnMouseDrag()
	{
		if (Scratch.Scratching) return;

		var hwnd = FindWindow(null, "CooldogAssistant");

		if (hwnd != IntPtr.Zero)
		{
			POINT p;
			GetCursorPos(out p);
			p.X -= Screen.width / 2;
			p.Y -= Screen.width / 4;

			if (Dragging || (new Vector2(p.X, p.Y) - new Vector2(DragStart.X, DragStart.Y)).magnitude > DragLimit)
			{
				Dragging = true;

				SetWindowPos(hwnd, HWND_TOPMOST, p.X, p.Y, 0, 0, SWP_NOSIZE);
				bool flipX = p.X < GetSystemMetrics(SM_CXSCREEN) / 2;
				transform.parent.GetComponent<Cooldog>().Flipped = flipX;
			}
		}
	}
#endif

	void OnMouseDown()
	{
		InputField.interactable = true;
		InputField.ActivateInputField();
		InputField.Select();

		#if ((UNITY_STANDALONE_WIN && !UNITY_EDITOR) || DEVELOP) && !DISABLE
		WndOnMouseDown ();
		#endif
	}
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>com.box.restclientv2.requestsbase Class Hierarchy</title>
<meta name="date" content="2014-03-17">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Hierarchy For Package com.box.restclientv2.requestsbase

Package Hierarchies:

All Packages

Class Hierarchy

java.lang.Object

com.box.restclientv2.requestsbase.BoxDefaultRequestObject (implements com.box.restclientv2.requestsbase.IBoxRequestObject)

com.box.restclientv2.requestsbase.BoxFileUploadRequestObject

com.box.restclientv2.requestsbase.BoxOAuthRequestObject

com.box.restclientv2.requestsbase.DefaultBoxRequest (implements com.box.restclientv2.requestsbase.IBoxRequest)

com.box.restclientv2.requestsbase.DefaultBoxRequestTest

Interface Hierarchy

com.box.restclientv2.requestsbase.IBoxRequest

com.box.restclientv2.requestsbase.IBoxRequestObject

com.box.restclientv2.requestsbase.ICookie

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes