text:
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('members', '0013_auto_20161008_2020'),
    ]

    operations = [
        migrations.AlterField(
            model_name='structure',
            name='type',
            field=models.IntegerField(choices=[(1, 'Cercle'), (2, 'Clan Ainé'), (3, 'Comité directeur'), (4, 'Département'), (5, 'Pôle'), (6, 'Région'), (7, 'Ronde'), (8, 'Siège'), (9, 'Sommet'), (10, "Structure locale d'activité"), (11, 'Structure locale rattachée'), (12, 'Unité Défi'), (13, 'Unité Eclé'), (14, 'Unité Nomade'), (15, 'Centre permanent national')], verbose_name='Type'),
        ),
    ]


text:
<?php

class Ess_M2ePro_Block_Adminhtml_Walmart_Listing_Variation_Product_Manage_Tabs_Settings
    extends Ess_M2ePro_Block_Adminhtml_Widget_Container
{
    const MESSAGE_TYPE_ERROR = 'error';
    const MESSAGE_TYPE_WARNING = 'warning';

    protected $_warningsCalculated = false;

    protected $_childListingProducts;
    protected $_currentProductVariations;

    protected $_messages = array();

    // ---------------------------------------

    protected $_listingProductId;

    /** @var Ess_M2ePro_Model_Listing_Product $_listingProduct */
    protected $_listingProduct;

    /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
    protected $_listingProductTypeModel;

    //########################################

    public function __construct()
    {
        parent::__construct();

        $this->setTemplate('M2ePro/walmart/listing/variation/product/manage/tabs/settings.phtml');
    }

    //########################################

    /**
     * @param mixed $listingProductId
     * @return $this
     */
    public function setListingProductId($listingProductId)
    {
        $this->_listingProductId = $listingProductId;

        return $this;
    }
    /**
     * @return mixed
     */
    public function getListingProductId()
    {
        return $this->_listingProductId;
    }

    // ---------------------------------------

    /**
     * @param array $message
     */
    public function addMessage($message, $type = self::MESSAGE_TYPE_ERROR)
    {
        $this->_messages[] = array(
            'type' => $type,
            'msg' => $message
        );
    }
    /**
     * @param array $messages
     */
    public function setMessages($messages)
    {
        $this->_messages = $messages;
    }
    /**
     * @return array
     */
    public function getMessages()
    {
        return $this->_messages;
    }

    public function getMessagesType()
    {
        $type = self::MESSAGE_TYPE_WARNING;
        foreach ($this->_messages as $message) {
            if ($message['type'] === self::MESSAGE_TYPE_ERROR)     {
                $type = $message['type'];
                break;
            }
        }

        return $type;
    }

    // ---------------------------------------

    /**
     * @return Ess_M2ePro_Model_Listing_Product|null
     */
    public function getListingProduct()
    {
        if ($this->_listingProduct === null) {
            $this->_listingProduct = Mage::helper('M2ePro/Component_Walmart')
                                         ->getObject('Listing_Product', $this->getListingProductId());
        }

        return $this->_listingProduct;
    }

    // ---------------------------------------

    /**
     * @return Ess_M2ePro_Model_Walmart_Listing_Product_Variation_Manager_Type_Relation_Parent|null
     */
    public function getListingProductTypeModel()
    {
        if ($this->_listingProductTypeModel === null) {
            /** @var Ess_M2ePro_Model_Walmart_Listing_Product $walmartListingProduct */
            $walmartListingProduct = $this->getListingProduct()->getChildObject();
            /** @var Ess_M2ePro_Model_Walmart_Listing_Product_Variation_Manager_Type_Relation_Parent $typeModel */
            $this->_listingProductTypeModel = $walmartListingProduct->getVariationManager()->getTypeModel();
        }

        return $this->_listingProductTypeModel;
    }

    // ---------------------------------------

    /** @var Ess_M2ePro_Model_Walmart_Listing_Product_Variation_Matcher_Attribute $matcherAttribute */
    protected $matcherAttributes;

    /**
     * @return Ess_M2ePro_Model_Walmart_Listing_Product_Variation_Matcher_Attribute
     */
    public function getMatcherAttributes()
    {
        if (empty($this->matcherAttributes)) {
            $this->matcherAttributes = Mage::getModel('M2ePro/Walmart_Listing_Product_Variation_Matcher_Attribute');
            $this->matcherAttributes->setMagentoProduct($this->getListingProduct()->getMagentoProduct());
            $this->matcherAttributes->setDestinationAttributes($this->getDestinationAttributes());
        }

        return $this->matcherAttributes;
    }

    // ---------------------------------------

    public function getWarnings()
    {
        $warnings = '';
        foreach ($this->getMessages() as $message) {
            $warnings .= <<_warningsCalculated) {
            $this->_warningsCalculated = true;

            if (!$this->getListingProductTypeModel()->hasChannelAttributes()) {
                $this->addMessage(
                    Mage::helper('M2ePro')->__(
                        'Walmart Item Variations are not defined. To start configurations, click Set Attributes.'
                    ),
                    self::MESSAGE_TYPE_ERROR
                );
            } else if (!$this->hasMatchedAttributes()) {
                $this->addMessage(
                    Mage::helper('M2ePro')->__(
                        'Item Variations cannot be added/updated on the Channel. The correspondence between Magento
                        Variational Attribute(s) and Walmart Variant Attribute(s) is not set.
                        Please complete the configurations.'
                    ),
                    self::MESSAGE_TYPE_ERROR
                );
            }
        }
    }

    // ---------------------------------------

    protected function _beforeToHtml()
    {
        $this->calculateWarnings();

        return parent::_beforeToHtml();
    }

    protected function _toHtml()
    {
        $vocabularyAttributesBlock = $this->getLayout()->createBlock(
            'M2ePro/adminhtml_walmart_listing_variation_product_vocabularyAttributesPopup'
        );

        $vocabularyOptionsBlock = $this->getLayout()->createBlock(
            'M2ePro/adminhtml_walmart_listing_variation_product_vocabularyOptionsPopup'
        );

        return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
    }

    //########################################

    public function isInAction()
    {
        $processingLocks = $this->getListingProduct()->getProcessingLocks();
        return !empty($processingLocks);
    }

    // ---------------------------------------

    public function getProductAttributes()
    {
        return $this->getListingProductTypeModel()->getProductAttributes();
    }

    // ---------------------------------------

    public function getDescriptionTemplateLink()
    {
        $url = $this->getUrl(
            '*/adminhtml_walmart_template_description/edit', array(
            'id' => $this->getListingProduct()->getChildObject()->getTemplateDescriptionId()
            )
        );

        $templateTitle = $this->getListingProduct()->getChildObject()->getDescriptionTemplate()->getTitle();

        return <<<HTML
{$templateTitle}
HTML;
    }

    // ---------------------------------------

    public function getPossibleAttributes()
    {
        $possibleAttributes = Mage::getModel('M2ePro/Walmart_Marketplace_Details')
            ->setMarketplaceId($this->getListingProduct()->getMarketplace()->getId())
            ->getVariationAttributes(
                $this->getListingProduct()->getChildObject()->getCategoryTemplate()->getProductDataNick()
            );

        return $possibleAttributes;
    }

    // ---------------------------------------

    public function getSwatchImagesAttribute()
    {
        return $this->getListingProduct()
                    ->getSetting('additional_data', 'variation_swatch_images_attribute');
    }

    // ---------------------------------------

    public function hasMatchedAttributes()
    {
        return $this->getListingProductTypeModel()->hasMatchedAttributes();
    }

    public function getMatchedAttributes()
    {
        if ($this->hasMatchedAttributes()) {
            return $this->getListingProductTypeModel()->getMatchedAttributes();
        }

        return $this->getMatcherAttributes()->getMatchedAttributes();
    }

    public function getDestinationAttributes()
    {
        return $this->getListingProductTypeModel()->getChannelAttributes();
    }

    // ---------------------------------------

    public function getVirtualAttributes()
    {
        $typeModel = $this->getListingProductTypeModel();

        if ($virtualProductAttributes = $typeModel->getVirtualProductAttributes()) {
            return $virtualProductAttributes;
        }

        if ($virtualChannelAttributes = $typeModel->getVirtualChannelAttributes()) {
            return $virtualChannelAttributes;
        }

        return array();
    }

    public function getVirtualProductAttributes()
    {
        $typeModel = $this->getListingProductTypeModel();

        if ($virtualProductAttributes = $typeModel->getVirtualProductAttributes()) {
            return $virtualProductAttributes;
        }

        return array();
    }

    public function getVirtualChannelAttributes()
    {
        $typeModel = $this->getListingProductTypeModel();

        if ($virtualChannelAttributes = $typeModel->getVirtualChannelAttributes()) {
            return $virtualChannelAttributes;
        }

        return array();
    }

    // ---------------------------------------

    public function isChangeMatchedAttributesAllowed()
    {
        if ($this->isInAction() ) {
            return false;
        }

        if ($this->hasMatchedAttributes()) {
            $typeModel = $this->getListingProductTypeModel();

            $realMatchedAttributes = $typeModel->getRealMatchedAttributes();

            if (count($realMatchedAttributes) === 1) {
                return false;
            }
        }

        return true;
    }

    //########################################

    public function getChildListingProducts()
    {
        if ($this->_childListingProducts !== null) {
            return $this->_childListingProducts;
        }

        return $this->_childListingProducts = $this->getListingProductTypeModel()->getChildListingsProducts();
    }

    public function getCurrentProductVariations()
    {
        if ($this->_currentProductVariations !== null) {
            return $this->_currentProductVariations;
        }

        $magentoProductVariations = $this->getListingProduct()
            ->getMagentoProduct()
            ->getVariationInstance()
            ->getVariationsTypeStandard();

        $productVariations = array();

        foreach ($magentoProductVariations['variations'] as $option) {
            $productOption = array();

            foreach ($option as $attribute) {
                $productOption[$attribute['attribute']] = $attribute['option'];
            }

            $productVariations[] = $productOption;
        }

        return $this->_currentProductVariations = $productVariations;
    }

    public function getCurrentChannelVariations()
    {
        return $this->getListingProductTypeModel()->getChannelVariations();
    }

    // ---------------------------------------

    public function getWalmartVariationsSet()
    {
        $variations = $this->getCurrentChannelVariations();

        if (empty($variations)) {
            return false;
        }

        $attributesOptions = array();

        foreach ($variations as $variation) {
            foreach ($variation as $attr => $option) {
                if (!isset($attributesOptions[$attr])) {
                    $attributesOptions[$attr] = array();
                }

                if (!in_array($option, $attributesOptions[$attr])) {
                    $attributesOptions[$attr][] = $option;
                }
            }
        }

        ksort($attributesOptions);

        return $attributesOptions;
    }

    // ---------------------------------------

    public function getUsedChannelVariations()
    {
        return $this->getListingProductTypeModel()->getUsedChannelOptions();
    }

    public function getUsedProductVariations()
    {
        return $this->getListingProductTypeModel()->getUsedProductOptions();
    }

    // ---------------------------------------

    public function getUnusedProductVariations()
    {
        return $this->getListingProductTypeModel()->getUnusedProductOptions();
    }

    // ---------------------------------------

    public function hasUnusedProductVariation()
    {
        return (bool)$this->getUnusedProductVariations();
    }

    // ---------------------------------------

    public function hasChildWithEmptyProductOptions()
    {
        foreach ($this->getChildListingProducts() as $childListingProduct) {
            /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */

            /** @var Ess_M2ePro_Model_Walmart_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
            $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();

            if (!$childTypeModel->isVariationProductMatched()) {
                return true;
            }
        }

        return false;
    }

    //########################################
}

redpajama_set_name: RedPajamaGithub


text:
package org.uma.jmetal.problem.multiobjective.cdtlz;

import org.uma.jmetal.problem.multiobjective.dtlz.DTLZ2;
import org.uma.jmetal.solution.doublesolution.DoubleSolution;

/**
 * Problem C2-DTLZ2, defined in:
 * Jain, H. and K. Deb.  "An Evolutionary Many-Objective Optimization Algorithm Using Reference-Point-Based
 * Nondominated Sorting Approach, Part II: Handling Constraints and Extending to an Adaptive Approach."
 * EEE Transactions on Evolutionary Computation, 18(4):602-622, 2014.
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 */
@SuppressWarnings("serial")
public class C2_DTLZ2 extends DTLZ2 {
  private double rValue ;
  /**
   * Constructor
   * @param numberOfVariables
   * @param numberOfObjectives
   */
  public C2_DTLZ2(int numberOfVariables, int numberOfObjectives) {
    super(numberOfVariables, numberOfObjectives) ;

    setNumberOfConstraints(1);

    if (getNumberOfObjectives() == 3) {
      rValue = 0.4 ;
    } else {
      rValue = 0.5 ;
    }
  }

  @Override
  public void evaluate(DoubleSolution solution) {
    super.evaluate(solution);
    evaluateConstraints(solution);
  }

  public void evaluateConstraints(DoubleSolution solution) {
    double sum2 = 0 ;
    double maxSum1 = Double.MIN_VALUE ;
    for (int i = 0; i < getNumberOfObjectives(); i++) {
      double sum1 = Math.pow(solution.getObjective(i)-1.0, 2.0) - Math.pow(rValue, 2.0) ;
      for (int j = 0; j < getNumberOfObjectives(); j++) {
        if (i != j) {
          sum1 += Math.pow(solution.getObjective(j), 2.0) ;
        }
      }

      maxSum1 = Math.max(maxSum1, sum1) ;

      sum2 += Math.pow((solution.getObjective(i) -
          1.0/Math.sqrt(getNumberOfObjectives())), 2.0)  ;

    }

    sum2 -= Math.pow(rValue, 2.0) ;

    solution.setConstraint(0, Math.max(maxSum1, sum2)) ;
  }
}


text:
  ########################################
  # SCRIPT HELPER FUNCTIONS
  ########################################
  get_args() {
    # Get Control pipes
    controlCMDpipe=$1
    controlRESULTpipe=$2
    shift 2

    # Get CMD pipes
    CMDpipes=()
    numPipesCMD=$1
    shift 1
    local i=0
    while [ $i -lt "$numPipesCMD" ]; do
      local arg_pos=$((i+1))
      CMDpipes[$i]=${!arg_pos}
      i=$((i+1))
    done
    shift "${numPipesCMD}"

    # Get RESULT pipes
    RESULTpipes=()
    numPipesRESULT=$1
    shift 1
    i=0
    while [ $i -lt "$numPipesRESULT" ]; do
      local arg_pos=$((i+1))
      RESULTpipes[$i]=${!arg_pos}
      i=$((i+1))
    done
    shift "${numPipesRESULT}"

    tracing=${1}
    shift 1

    # Get binding
    binding=$1
    shift 1

    # Get tracing and virtual environment if python
    if [ "$binding" == "PYTHON" ]; then
        # Get virtual environment parameters
        virtualEnvironment=$1
        propagateVirtualEnvironment=$2
        # Get Information for the mpi worker
        mpiWorker=$3
        numThreads=$4
        pythonInterpreter=$5
        shift 5
    fi
  }

  create_pipe() {
    rm -f "$1"
    mkfifo "$1"
  }

  ########################################
  # MAIN
  ########################################
  echo "[BINDINGS PIPER] STARTING BINDINGS PIPER"
  # Actual script dir
  SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

  # Arguments
  get_args $@

  # Clean and Create control pipes
  echo "[BINDINGS PIPER] Control CMD Pipe: $controlCMDpipe"
  create_pipe "$controlCMDpipe"

  echo "[BINDINGS PIPER] Control RESULT Pipe: $controlRESULTpipe"
  create_pipe "$controlRESULTpipe"

  # Clean and Create CMD Pipes
  for i in "${CMDpipes[@]}"; do
    echo "[BINDINGS PIPER] CMD Pipe: $i"
    create_pipe $i
  done

  # Clean and Create RESULT Pipes
  for i in "${RESULTpipes[@]}"; do
    echo "[BINDINGS PIPER] RESULT Pipe: $i"
    create_pipe $i
  done

  # Activating virtual environment if needed
  if [ "$virtualEnvironment" != "null" ] && [ "$propagateVirtualEnvironment" == "true" ]; then
    echo "[BINDINGS PIPER] Activating virtual environment $virtualEnvironment"
    source ${virtualEnvironment}/bin/activate
  fi

  # If MPI worker override SLURM variable to allow process 0 + N workers:
  # NOTE: The MPI worker only works in local and in SCs with SLURM
  if [ "$mpiWorker" == "true" ]; then
    export SLURM_TASKS_PER_NODE=${numThreads}
    # Force to spawn the MPI processes in the same node
    export SLURM_NODELIST=${SLURM_STEP_NODELIST}
  fi

  # Export tracing
  if [ "$tracing" -gt "0" ]; then
    echo "Initializing python tracing with extrae..."
    configPath="${SCRIPT_DIR}/../../../../../configuration/xml/tracing"
    escapedConfigPath=$(echo "$configPath" | sed 's_/_\\/_g')
    baseConfigFile="${configPath}/extrae_python_worker.xml"
    workerConfigFile="$(pwd)/extrae_python_worker.xml"

    echo $(sed s/{{PATH}}/"${escapedConfigPath}"/g <<< $(cat "${baseConfigFile}")) > "${workerConfigFile}"

    export EXTRAE_CONFIG_FILE=${workerConfigFile}
    if [ "$mpiWorker" == "true" ]; then
      # Exporting libmpitrace.so in the LD_PRELOAD is needed to enable tracing with extrae and the MPI worker
      dependencies_path="${SCRIPT_DIR}/../../../../../../Dependencies"
      libmpitrace="lib/libmpitrace.so"
      if [ -f "${dependencies_path}/extrae/${libmpitrace}" ]; then
        # If the normal installation contains libmpitrace.so
        export EXTRAE_HOME=${dependencies_path}/extrae
      elif [ -f "${dependencies_path}/extrae-openmpi/${libmpitrace}" ]; then
        # If openmpi extrae installation exists
        export EXTRAE_HOME=${dependencies_path}/extrae-openmpi
      elif [ -f "${dependencies_path}/extrae-impi/${libmpitrace}" ]; then
        # If impi extrae installation exists
        export EXTRAE_HOME=${dependencies_path}/extrae-impi
      else
        # Tracing with extrae with mpi worker requires extrae to be compiled with mpi
        echo "ERROR: Extrae is not compiled with mpi support."
        echo "QUIT" >> "${controlRESULTpipe}"
        exit 1
      fi
      export PYTHONPATH=${EXTRAE_HOME}/libexec/:${EXTRAE_HOME}/lib/:${PYTHONPATH}
      export LD_PRELOAD="${EXTRAE_HOME}/${libmpitrace}"
    else
      export PYTHONPATH=${SCRIPT_DIR}/../../../../../../Dependencies/extrae/libexec/:${SCRIPT_DIR}/../../../../../../Dependencies/extrae/lib/:${PYTHONPATH}
    fi

  elif [ "$tracing" -lt "-1" ]; then
    # exporting variables required by any other tracing option (map/ddt/scorep)
    if [ "$binding" == "PYTHON" ]; then
      export ALLINEA_MPI_INIT=MPI_Init_thread
      export ALLINEA_MPI_INIT_PENDING=1
    else
      # Only tracing with extrae is supported for other bindings
      echo "ERROR: Unsupported tracing mode for this binding."
      echo "QUIT" >> "${controlRESULTpipe}"
      exit 1
    fi
  fi

  stop_received=false
  while [ "${stop_received}" = false ]; do
    read cmd_tag line
    echo "[BINDINGS PIPER] READ COMMAND --${cmd_tag}--"
    case "${cmd_tag}" in
      "PING")
        echo "PONG" >> "${controlRESULTpipe}"
        ;;

      "CREATE_CHANNEL")
        reply="CHANNEL_CREATED"
        for pipe_name in $(echo "${line}" | tr " " "\t"); do
          create_pipe "${pipe_name}"
          reply="${reply} ${pipe_name}"
        done
        echo "${reply}" >> "${controlRESULTpipe}"
        ;;

      "START_WORKER")
        workerCMDpipe=$(echo "$line" | tr " " "\t" | awk '{ print $1 }')
        create_pipe ${workerCMDpipe}
        workerRESULTpipe=$(echo "$line" | tr " " "\t" | awk '{ print $2 }')
        create_pipe ${workerRESULTpipe}

        workerCMD=$(echo ${line} | cut -d' ' -f3-)

        if [ "$binding" == "PYTHON" ] && [ "$mpiWorker" == "true" ]; then
          # delimiter example: "python -u"
          delimiter="${pythonInterpreter} -u"
          bindingExecutable="${workerCMD%%"$delimiter"*}"
          bindingArgs=${workerCMD#*"$delimiter"}

          # Get full path of the binary
          pythonInterpreter=$(which ${pythonInterpreter})

          if [ "$tracing" -eq "-1" ]; then # scorep
            echo "[BINDINGS PIPER] Making preload call in folder $(pwd)"
            TRACE_SCRIPTS_PATH=${SCRIPT_DIR}/../../../../../scripts/system/trace
            python_version=$( ${pythonInterpreter} -c "import sys; print(sys.version_info[:][0])" )
            source ${TRACE_SCRIPTS_PATH}/scorep.sh $python_version
            # Set path to the application - this even better because the submission is independent of the current working directory
            app_path=$(pwd)
            app_name=piper_worker.py
            rm -rf $app_path/.scorep_preload
            ld_preload=$(scorep-preload-init --value-only --user --nocompiler --mpp=mpi --thread=pthread --io=runtime:posix ${app_path}/${app_name})
            bindingArgs=" -x LD_PRELOAD=$ld_preload ${pythonInterpreter} -u -m scorep $bindingArgs"
            echo "[BINDINGS PIPER] ScoreP setup done"

          elif [ "$tracing" -eq "-2" ]; then # arm-map
            echo "[BINDINGS PIPER] Setting up arm-map tracing in folder $(pwd)"
            TRACE_SCRIPTS_PATH=${SCRIPT_DIR}/../../../../../scripts/system/trace
            source ${TRACE_SCRIPTS_PATH}/arm-forge.sh
            # Set path to the application - this even better because the submission is independent of the current working directory
            bindingExecutable="map"
            bindingArgs=" --profile -o $(pwd)/$(hostname).map --mpi=generic -n ${numThreads} ${pythonInterpreter} $bindingArgs"
            echo "[BINDINGS PIPER] Arm setup for MAP done"

          elif [ "$tracing" -eq "-3" ]; then # arm-ddt
            echo "[BINDINGS PIPER] Setting up arm-ddt tracing in folder $(pwd)"
            TRACE_SCRIPTS_PATH=${SCRIPT_DIR}/../../../../../scripts/system/trace
            source ${TRACE_SCRIPTS_PATH}/arm-forge.sh
            # Set path to the application - this even better because the submission is independent of the current working directory
            bindingExecutable="ddt"
            bindingArgs=" --connect --mpi=generic -n ${numThreads} ${pythonInterpreter} $bindingArgs"
            echo "[BINDINGS PIPER] Arm setup for DDT done"

          else
            bindingExecutable="${workerCMD%%"$delimiter"*}$delimiter"
          fi
          workerCMD="${bindingExecutable} ${bindingArgs}"
        fi

        eval ${workerCMD} </dev/null 3>/dev/null &
        bindingPID=$!
        echo "WORKER_STARTED ${bindingPID}" >> "${controlRESULTpipe}"
        ;;

      "GET_ALIVE")
        reply="ALIVE_REPLY"
        if [ "${line}" != "GET_ALIVE" ]; then
          pids="${line}"
          alive_processes=$(ps h -o pid,stat ${pids} | awk '$2 != "Z" {print $1}')
          for alive_process in ${alive_processes}; do
            reply="${reply} ${alive_process}"
          done
        fi
        echo "${reply}" >> "${controlRESULTpipe}"
        ;;

      "QUIT")
        stop_received=true
        ;;
      *)
        echo "[BINDINGS PIPER] UNKNOWN COMMAND ${line}"
    esac
  done <"${controlCMDpipe}" 3>"${controlCMDpipe}"

  echo "QUIT" >> "${controlRESULTpipe}"

  # Exit message
  echo "[BINDINGS PIPER] Finished"
  exit 0


text:
<?xml version="1.0" encoding="UTF-8"?>

<!-- Include all common assertions -->
<?include ../../../include/common-asserts.xml?>

<!-- Include defaults assertions -->
<?include ../../../include/defaults-asserts.xml#common?>
<?include ../../../include/defaults-asserts.xml#name?>
<?include ../../../include/defaults-asserts.xml#expire?>
<?include ../../../include/defaults-asserts.xml#email?>

<!-- There should be 2 roles -->
<?assert count(mapping:get-attributes('roles')) = 2?>

<!-- The roles should be nova:admin lbaas:admin -->
<?assert every $r in ('lbaas:admin','nova:admin') satisfies $r=mapping:get-attributes('roles')?>

<!-- The doman should be 78334 -->
<?assert mapping:get-attribute('domain') = '78334'?>

<saml2p:Response ID="_7fcd6173-e6e0-45a4-a2fd-74a4ef85bf30" IssueInstant="2015-12-04T15:47:15.057Z" Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">http://test.rackspace.com</saml2:Issuer>
    <saml2p:Status>
        <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
    </saml2p:Status>
    <saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    ID="_406fb7fe-a519-4919-a42c-f67794a670a5" IssueInstant="2013-11-15T16:19:06.310Z"
    Version="2.0">
    <saml2:Issuer>http://my.rackspace.com</saml2:Issuer>
    <saml2:Subject>
        <saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">john.doe</saml2:NameID>
        <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
            <saml2:SubjectConfirmationData
                NotOnOrAfter="2013-11-17T16:19:06.298Z" />
        </saml2:SubjectConfirmation>
    </saml2:Subject>
    <saml2:AuthnStatement AuthnInstant="2013-11-15T16:19:04.055Z">
        <saml2:AuthnContext>
            <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
            </saml2:AuthnContextClassRef>
        </saml2:AuthnContext>
    </saml2:AuthnStatement>
    <saml2:AttributeStatement>
        <saml2:Attribute Name="roles">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xsi:type="xs:string">FOO</saml2:AttributeValue>
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xsi:type="xs:string">BING</saml2:AttributeValue>
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xsi:type="xs:string">DOWN</saml2:AttributeValue>
        </saml2:Attribute>
        <saml2:Attribute Name="domain">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:type="xs:string">323676</saml2:AttributeValue>
        </saml2:Attribute>
        <saml2:Attribute Name="email">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:type="xs:string">no-reply@rackspace.com</saml2:AttributeValue>
        </saml2:Attribute>
        <saml2:Attribute Name="bar">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:type="xs:string">BAR!</saml2:AttributeValue>
        </saml2:Attribute>
        <saml2:Attribute Name="FirstName">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:type="xs:string">John</saml2:AttributeValue>
        </saml2:Attribute>
        <saml2:Attribute Name="LastName">
            <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:type="xs:string">Doe</saml2:AttributeValue>
        </saml2:Attribute>
    </saml2:AttributeStatement>
   </saml2:Assertion>
</saml2p:Response>


text:
<?php

namespace AppBundle\Form;

use AppBundle\Entity\Task;
use AppBundle\Form\Type\CriteriaType;
use AppBundle\Form\Type\VariantType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TaskFormType extends AbstractType
{

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType::class, [
                    'label' => 'Название ',
                    'attr' => [
                        'class' => 'form-control'
                    ]
                 ])
                ->add('variants', CollectionType::class, [
                    'label' => 'Варианты',
                    'entry_type' => VariantType::class,
                    'allow_add' => true,
                ])
                ->add('criteria', CollectionType::class, [
                    'label' => 'Критерии',
                    'entry_type' => CriteriaType::class,
                    'allow_add' => true,
                ])
                ->add('save', SubmitType::class, [
                    'attr' => [
                        'class' => 'btn btn-primary btn-lg btn-block'
                    ]
                ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Task::class
        ]);
    }

    public function getBlockPrefix()
    {
        return 'app_bundle_task_form_type';
    }
}


text:
docker-nginx-magento
Docker NGINX container

About

This container is latest version NGINX with pagespeed with geo ip module. It require mount external config folder before start.


text:
import os
from django.db import models
from django.core.exceptions import ValidationError

class Person(models.Model):
    name = models.CharField(max_length=100)

class Triple(models.Model):
    left = models.IntegerField()
    middle = models.IntegerField()
    right = models.IntegerField()

    class Meta:
        unique_together = (('left', 'middle'), (u'middle', u'right'))

class FilePathModel(models.Model):
    path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)

class Publication(models.Model):
    title = models.CharField(max_length=30)
    date_published = models.DateField()

    def __unicode__(self):
        return self.title

class Article(models.Model):
    headline = models.CharField(max_length=100)
    publications = models.ManyToManyField(Publication)

    def __unicode__(self):
        return self.headline

class CustomFileField(models.FileField):
    def save_form_data(self, instance, data):
        been_here = getattr(self, 'been_saved', False)
        assert not been_here, "save_form_data called more than once"
        setattr(self, 'been_saved', True)

class CustomFF(models.Model):
    f = CustomFileField(upload_to='unused', blank=True)

class RealPerson(models.Model):
    name = models.CharField(max_length=100)

    def clean(self):
        if self.name.lower() == 'anonymous':
            raise ValidationError("Please specify a real name.")

class Author(models.Model):
    publication = models.OneToOneField(Publication, null=True, blank=True)
    full_name = models.CharField(max_length=255)

class Author1(models.Model):
    publication = models.OneToOneField(Publication, null=False)
    full_name = models.CharField(max_length=255)


text:
// Copyright (c) Nate Barbettini. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;

namespace SimpleTokenProvider
{
    /// <summary>
    /// Provides options for <see cref="TokenProviderMiddleware"/>.
    /// </summary>
    public class TokenProviderOptions
    {
        /// <summary>
        /// The relative request path to listen on.
        /// </summary>
        /// <remarks>The default path is <c>/token</c>.</remarks>
        public string Path { get; set; } = "/token";

        /// <summary>
        ///  The Issuer (iss) claim for generated tokens.
        /// </summary>
        public string Issuer { get; set; }

        /// <summary>
        /// The Audience (aud) claim for the generated tokens.
        /// </summary>
        public string Audience { get; set; }

        /// <summary>
        /// The expiration time for the generated tokens.
        /// </summary>
        /// <remarks>The default is five minutes (300 seconds).</remarks>
        public TimeSpan Expiration { get; set; } = TimeSpan.FromMinutes(5);

        /// <summary>
        /// The signing key to use when generating tokens.
        /// </summary>
        public SigningCredentials SigningCredentials { get; set; }

        /// <summary>
        /// Resolves a user identity given a username and password.
        /// </summary>
        public Func<string, string, Task<ClaimsIdentity>> IdentityResolver { get; set; }

        /// <summary>
        /// Generates a random value (nonce) for each generated token.
        /// </summary>
        /// <remarks>The default nonce is a random GUID.</remarks>
        public Func<Task<string>> NonceGenerator { get; set; }
            = new Func<Task<string>>(() => Task.FromResult(Guid.NewGuid().ToString()));
    }
}


text:
from pyparsing import makeHTMLTags
from contextlib import closing
import urllib.request, urllib.parse, urllib.error
import pprint

# Define the pyparsing grammar for a URL, that is:
#    URLlink ::= linkText
#    URL ::= doubleQuotedString | alphanumericWordPath
# Note that whitespace may appear just about anywhere in the link.  Note also
# that it is not necessary to explicitly show this in the pyparsing grammar; by default,
# pyparsing skips over whitespace between tokens.
linkOpenTag, linkCloseTag = makeHTMLTags("a")
link = linkOpenTag + linkOpenTag.tag_body("body") + linkCloseTag.suppress()

# Go get some HTML with some links in it.
with closing(urllib.request.urlopen("https://www.cnn.com/")) as serverListPage:
    htmlText = serverListPage.read()

# scanString is a generator that loops through the input htmlText, and for each
# match yields the tokens and start and end locations (for this application, we are
# not interested in the start and end values).
for toks, strt, end in link.scanString(htmlText):
    print(toks.startA.href, "->", toks.body)

# Create dictionary from list comprehension, assembled from each pair of tokens returned
# from a matched URL.
pprint.pprint(
    {toks.body: toks.startA.href for toks, strt, end in link.scanString(htmlText)}
    )


text:
> state: **closed** opened by: **adrianharabula** on: **5/21/2017**

{% raw %}
Momentan nu avem un standard pentru notificări, dacă vrei să afişezi o eroare, nu ştii exact cum să faci.

Trebuie făcut ceva simplu.

Gen, dacă ai o eroare, scrii asta şi va apărea asta aici.

Bările acelea colorate ar putea fi cu buton X în dreapta pentru a putea fi închise.
{% endraw %}

### Comments

---
> from: [**adrianharabula**](https://github.com/adrianharabula/condr/issues/115#issuecomment-303892357) on: **5/25/2017**

{% raw %}
https://github.com/adrianharabula/condr/pull/135/commits/168b14ed1a11631e50058e0efed30b214e54e095
{% endraw %}


text:
'''active knife tests'''

from knife._compat import unittest

from knife.tests.mixins import (
    Mixin, MapMixin, RepeatMixin, ReduceMixin, SliceMixin, FilterMixin,
    OrderMixin, MathMixin, CmpMixin)

class TestActive(
    unittest.TestCase, Mixin, FilterMixin, MapMixin, ReduceMixin, OrderMixin,
    SliceMixin, RepeatMixin, MathMixin, CmpMixin
):

    def setUp(self):
        from knife import activeknife
        self.mclass = activeknife
        self.pipe = activeknife

class TestCompare(unittest.TestCase, Mixin, CmpMixin):

    def setUp(self):
        from knife.active import cmpknife
        self.mclass = cmpknife

class TestFilter(unittest.TestCase, Mixin, FilterMixin):

    def setUp(self):
        self.maxDiff = None
        from knife.active import filterknife
        self.mclass = filterknife

class TestMap(unittest.TestCase, Mixin, MapMixin):

    def setUp(self):
        from knife.active import mapknife
        self.mclass = mapknife

class TestMath(unittest.TestCase, Mixin, MathMixin):

    def setUp(self):
        from knife.active import mathknife, reduceknife
        self.mclass = mathknife
        self.pipe = reduceknife

class TestOrder(unittest.TestCase, Mixin, OrderMixin):

    def setUp(self):
        from knife.active import orderknife
        self.mclass = orderknife

class TestReduce(unittest.TestCase, Mixin, ReduceMixin):

    def setUp(self):
        from knife.active import reduceknife
        self.mclass = reduceknife

class TestRepeat(unittest.TestCase, Mixin, RepeatMixin):

    def setUp(self):
        from knife.active import repeatknife
        self.mclass = repeatknife

class TestSlice(unittest.TestCase, Mixin, SliceMixin):

    def setUp(self):
        from knife.active import sliceknife
        self.mclass = sliceknife

if __name__ == '__main__':
    unittest.main()


text:
require "adequate_exposure/version"
require "active_support/all"

module AdequateExposure
  autoload :Controller, "adequate_exposure/controller"
  autoload :Exposure,   "adequate_exposure/exposure"
  autoload :Attribute,  "adequate_exposure/attribute"
  autoload :Context,    "adequate_exposure/context"
  autoload :Behavior,   "adequate_exposure/behavior"
  autoload :Flow,       "adequate_exposure/flow"

  ActiveSupport.on_load :action_controller do
    include Controller
  end
end


text:
module ActiveModel
  module Serializers
    module Matchers
      class Root
        attr_accessor :name, :actual

        def initialize(name = true)
          @name = name
        end

        def matches?(actual)
          @actual = actual

          serializer._root == name
        end

        def description
          "have attribute #{name}"
        end

        def failure_message
          %Q{expected "#{actual._root}" to be "#{name}", but it wasn't}
        end

        def failure_message_when_negated
          %Q{expected "#{actual._root}" to be "#{name}", but it was}
        end

        private
        def serializer
          if actual.is_a?(Class)
            actual
          else
            actual.class
          end
        end
      end

      def include_root(key = nil)
        Root.new key
      end

      class Embed
        attr_accessor :expected, :actual

        def initialize(expected)
          @expected = expected
        end

        def matches?(actual)
          @actual = actual

          serializer._embed == expected
        end

        def description
          "embed #{name}"
        end

        def failure_message
          %Q{expected "#{actual._embed}" to be "#{name}", but it wasn't}
        end

        def failure_message_when_negated
          %Q{expected "#{actual._embed}" to be "#{name}", but it was}
        end

        private
        def serializer
          if actual.is_a?(Class)
            actual
          else
            actual.class
          end
        end
      end

      def embed(value)
        Embed.new value
      end

      class HaveAttribute
        attr_accessor :name, :actual, :expected_key

        def initialize(name)
          @name = name
        end

        def matches?(actual)
          @actual = actual

          return false unless attributes.has_key?(name)
          return true unless expected_key
          attributes[name] == expected_key
        end

        def description
          "have attribute #{name}"
        end

        def failure_message
          %Q{expected #{actual.inspect} to include "#{name}", but it did not}
        end

        def failure_message_when_negated
          %Q{expected #{actual.inspect} to not include: "#{name}", but it did}
        end

        def as(value)
          self.expected_key = value
          self
        end

        private
        def serializer
          if actual.is_a?(Class)
            actual
          else
            actual.class
          end
        end

        def attributes
          serializer._attributes
        end
      end

      def have_attribute(name)
        HaveAttribute.new name
      end

      class AssociationMatcher
        attr_accessor :name, :actual, :expected_key

        def initialize(name)
          @name = name
        end

        def matches?(actual)
          @actual = actual

          matched_association = associations.detect do |key, assc|
            key == name
          end

          return false unless matched_association

          if expected_key
            association_key = matched_association.last.options[:key]
            return false if association_key != expected_key
          end

          true
        end

        def as(value)
          self.expected_key = value
          self
        end

        def description
          "have attribute #{name}"
        end

        def failure_message
          %Q{expected #{actual.inspect} to include a "#{name}" association, but it did not}
        end

        def failure_message_when_negated
          %Q{expected #{actual.inspect} to not include a "#{name}" association, but it did}
        end

        private
        def serializer
          if actual.is_a?(Class)
            actual
          else
            actual.class
          end
        end

        def associations
          serializer._associations
        end
      end

      def have_many(name)
        AssociationMatcher.new(name)
      end
      alias :have_one :have_many
    end
  end
end


text:
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DefaultConfigTestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class DefaultConfigTestBundle extends Bundle
{
}


text:
function build-kube-env {
  local master=$1
  local file=$2

  rm -f ${file}
  # TODO(dawnchen): master node is still running with debian image
  if [[ "${master}" == "true" ]]; then
  cat >$file <<EOF
ENV_TIMESTAMP: $(yaml-quote $(date -u +%Y-%m-%dT%T%z))
INSTANCE_PREFIX: $(yaml-quote ${INSTANCE_PREFIX})
NODE_INSTANCE_PREFIX: $(yaml-quote ${NODE_INSTANCE_PREFIX})
CLUSTER_IP_RANGE: $(yaml-quote ${CLUSTER_IP_RANGE:-10.244.0.0/16})
SERVER_BINARY_TAR_URL: $(yaml-quote ${SERVER_BINARY_TAR_URL})
SALT_TAR_URL: $(yaml-quote ${SALT_TAR_URL})
PORTAL_NET: $(yaml-quote ${PORTAL_NET})
ALLOCATE_NODE_CIDRS: $(yaml-quote ${ALLOCATE_NODE_CIDRS:-false})
ENABLE_CLUSTER_MONITORING: $(yaml-quote ${ENABLE_CLUSTER_MONITORING:-none})
ENABLE_NODE_MONITORING: $(yaml-quote ${ENABLE_NODE_MONITORING:-false})
ENABLE_CLUSTER_LOGGING: $(yaml-quote ${ENABLE_CLUSTER_LOGGING:-false})
ENABLE_NODE_LOGGING: $(yaml-quote ${ENABLE_NODE_LOGGING:-false})
LOGGING_DESTINATION: $(yaml-quote ${LOGGING_DESTINATION:-})
ELASTICSEARCH_LOGGING_REPLICAS: $(yaml-quote ${ELASTICSEARCH_LOGGING_REPLICAS:-})
ENABLE_CLUSTER_DNS: $(yaml-quote ${ENABLE_CLUSTER_DNS:-false})
DNS_REPLICAS: $(yaml-quote ${DNS_REPLICAS:-})
DNS_SERVER_IP: $(yaml-quote ${DNS_SERVER_IP:-})
DNS_DOMAIN: $(yaml-quote ${DNS_DOMAIN:-})
KUBE_USER: $(yaml-quote ${KUBE_USER})
KUBE_PASSWORD: $(yaml-quote ${KUBE_PASSWORD})
KUBE_BEARER_TOKEN: $(yaml-quote ${KUBE_BEARER_TOKEN})
KUBELET_TOKEN: $(yaml-quote ${KUBELET_TOKEN:-})
KUBE_PROXY_TOKEN: $(yaml-quote ${KUBE_PROXY_TOKEN:-})
ADMISSION_CONTROL: $(yaml-quote ${ADMISSION_CONTROL:-})
MASTER_IP_RANGE: $(yaml-quote ${MASTER_IP_RANGE})
KUBERNETES_CONTAINER_RUNTIME: $(yaml-quote ${CONTAINER_RUNTIME})
CA_CERT: $(yaml-quote ${CA_CERT_BASE64})
MASTER_CERT: $(yaml-quote ${MASTER_CERT_BASE64:-})
MASTER_KEY: $(yaml-quote ${MASTER_KEY_BASE64:-})
KUBECFG_CERT: $(yaml-quote ${KUBECFG_CERT_BASE64:-})
KUBECFG_KEY: $(yaml-quote ${KUBECFG_KEY_BASE64:-})
EOF
  else
    cat >>$file <<EOF
ENV_TIMESTAMP=$(yaml-quote $(date -u +%Y-%m-%dT%T%z))
INSTANCE_PREFIX=$(yaml-quote ${INSTANCE_PREFIX})
NODE_INSTANCE_PREFIX=$(yaml-quote ${NODE_INSTANCE_PREFIX})
SERVER_BINARY_TAR_URL=$(yaml-quote ${SERVER_BINARY_TAR_URL})
PORTAL_NET=$(yaml-quote ${PORTAL_NET})
ENABLE_CLUSTER_MONITORING=$(yaml-quote ${ENABLE_CLUSTER_MONITORING:-none})
ENABLE_NODE_MONITORING=$(yaml-quote ${ENABLE_NODE_MONITORING:-false})
ENABLE_CLUSTER_LOGGING=$(yaml-quote ${ENABLE_CLUSTER_LOGGING:-false})
ENABLE_NODE_LOGGING=$(yaml-quote ${ENABLE_NODE_LOGGING:-false})
LOGGING_DESTINATION=$(yaml-quote ${LOGGING_DESTINATION:-})
ELASTICSEARCH_LOGGING_REPLICAS=$(yaml-quote ${ELASTICSEARCH_LOGGING_REPLICAS:-})
ENABLE_CLUSTER_DNS=$(yaml-quote ${ENABLE_CLUSTER_DNS:-false})
DNS_REPLICAS=$(yaml-quote ${DNS_REPLICAS:-})
DNS_SERVER_IP=$(yaml-quote ${DNS_SERVER_IP:-})
DNS_DOMAIN=$(yaml-quote ${DNS_DOMAIN:-})
KUBELET_TOKEN=$(yaml-quote ${KUBELET_TOKEN:-})
KUBE_PROXY_TOKEN=$(yaml-quote ${KUBE_PROXY_TOKEN:-})
ADMISSION_CONTROL=$(yaml-quote ${ADMISSION_CONTROL:-})
MASTER_IP_RANGE=$(yaml-quote ${MASTER_IP_RANGE})
KUBERNETES_MASTER_NAME=$(yaml-quote ${MASTER_NAME})
ZONE=$(yaml-quote ${ZONE})
EXTRA_DOCKER_OPTS=$(yaml-quote ${EXTRA_DOCKER_OPTS})
ENABLE_DOCKER_REGISTRY_CACHE=$(yaml-quote ${ENABLE_DOCKER_REGISTRY_CACHE:-false})
PROJECT_ID=$(yaml-quote ${PROJECT})
KUBERNETES_CONTAINER_RUNTIME=$(yaml-quote ${CONTAINER_RUNTIME})
CA_CERT: $(yaml-quote ${CA_CERT_BASE64})
KUBELET_CERT: $(yaml-quote ${KUBELET_CERT_BASE64:-})
KUBELET_KEY: $(yaml-quote ${KUBELET_KEY_BASE64:-})
EOF
  fi
}

# create-master-instance creates the master instance. If called with
# an argument, the argument is used as the name to a reserved IP
# address for the master. (In the case of upgrade/repair, we re-use
# the same IP.)
#
# It requires a whole slew of assumed variables, partially due to to
# the call to write-master-env. Listing them would be rather
# futile. Instead, we list the required calls to ensure any additional
# variables are set:
#   ensure-temp-dir
#   detect-project
#   get-bearer-token
#
# TODO(dawnchen): Convert master node to use coreos image too
function create-master-instance {
  local address_opt=""
  [[ -n ${1:-} ]] && address_opt="--address ${1}"

  write-master-env
  gcloud compute instances create "${MASTER_NAME}" \
    ${address_opt} \
    --project "${PROJECT}" \
    --zone "${ZONE}" \
    --machine-type "${MASTER_SIZE}" \
    --image-project="${MASTER_IMAGE_PROJECT}" \
    --image "${MASTER_IMAGE}" \
    --tags "${MASTER_TAG}" \
    --network "${NETWORK}" \
    --scopes "storage-ro" "compute-rw" \
    --can-ip-forward \
    --metadata-from-file \
      "startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \
      "kube-env=${KUBE_TEMP}/master-kube-env.yaml" \
    --disk name="${MASTER_NAME}-pd" device-name=master-pd mode=rw boot=no auto-delete=no
}

# TODO(dawnchen): Check $CONTAINER_RUNTIME to decide which
# cloud_config yaml file should be passed
function create-node-instance-template {
   create-node-template "${NODE_INSTANCE_PREFIX}-template" "${scope_flags[*]}" \
    "kube-env=${KUBE_TEMP}/node-kube-env.yaml" \
    "user-data=${KUBE_ROOT}/cluster/gce/coreos/node.yaml"
}


text:
;(function ( $, window, document, undefined ) {
    var pluginName = "clear",
        defaults = {
        };
    function Plugin( element, options ) {
        this.element = element;
        this.options = $.extend( {}, defaults, options );
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }
    Plugin.prototype = {
        init: function() {
            var plugin = this;
            $(this.element).append(""+this.options.tool.label+"");
            if (this.options.tool.toggle){
                $(this.element).addClass('toggle');
            }
            $(this.element).click(function(){
            });
        }
    };
    $.fn[pluginName] = function ( options ) {
        return this.each(function () {
            //if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName, new Plugin( this, options ));
            //}
        });
    };
})( jQuery, window, document );


text:
Nakala
======

Text mining, text categorization, sentiment analysis, and NLP package

Introduction
============

Nakala is a text mining framework inspired by UIMA. It contains a number of core classes organized in a framework
that allows for rapid prototyping and maximizes code reuse, all resulting in quicker deployment to production.

Nakala's SimpleJobFlow takes Yaml configuration files that define where the input data lives, how it should be
processed and where the results should be stored.

Framework
=========

The framework is based on seven basic interfaces:

 - Analyzable: An object that contains a text content that is to be analyzed
 - Analyzer: A class that takes an Analyzable and returns an Analysis
 - Analysis: The output of an Analyzer
 - CollectionReader: An object that reads a data source and produces Analyzables
 - CollectionAnalyzer: A class that takes a CollectionReader and returns an AnalysisCollector
 - AnalysisCollector: The output of a CollectionAnalyzer. This could be either a single analysis on the entire collection or an analysis per each item in the collection.
 - DataStore: A class that stores an Analysis

One common way to use the package is to define job flows. At this time, two types of work job are defined: SimpleJobFlow and MultiThreadedJobFlow.
A SimpleJobFlow takes a CollectionReader, a CollectionAnalyzer and a list of DataStores. It then runs the CollectionAnalyzer on the data returned by the CollectionReader, and stores the results in the DataStores. The MultiThreadedJobFlow does the same except it runs many instances of the CollectionAnalyzers in parallel.

Package Highlights
==================

1. [com.groupon.ml](/src/main/java/com/groupon/ml): A set of machine learning tools for text classification.
2. [com.groupon.nakala.analysis](/src/main/java/com/groupon/nakala/analysis): A number of analyzers and analysis containers.
3. [com.groupon.nakala.core](/src/main/java/com/groupon/nakala/core): Some core tools and classes including basic NLP tools
stemming, part-of-speech tagging, named entity recognition, and chunking.
4. [com.groupon.nakala.db](/src/main/java/com/groupon/nakala/db): Data input/output classes.
5. [com.groupon.nakala.normalization](/src/main/java/com/groupon/nakala/normalization): A set of string normalization classes.
6. [com.groupon.nakala.sentiment](/src/main/java/com/groupon/nakala/sentiment): Tools to perform sentiment analysis and review snippet extraction.
7. [com.groupon.util](/src/main/java/com/groupon/util): Useful utility classes.

Getting Started
===============

Download the package
--------------------

```
git clone https://github.com/groupon/nakala.git
```

Build it
--------

```
cd nakala
mvn package
```

Nakala contains many tools to perform NLP and text mining tasks. In this guide we will focus on training,
testing, and applying an SVM text classifier. Look in the jobflows folder for a number of different
configuration examples.

Train a text classifier
-----------------------

Training a text classifier is performed in two steps: feature selection, and training. You can also test
your trained classifier on some unseen test data.

Let's assume you have a tab-separated training corpus at /home/jdoe/train.tsv with the following format:

```
record-id    categories    text
```

where "categories" is a comma-separated list of category recommendations.

### Feature selection

To perform feature selection, create a YAML file like the one below as follows:

```
python script/generate_yaml_file.py --task svm --phase feature \
    --input-file /home/jdoe/train.tsv \
    --id-field 0 --label-field 1 --text-field 2 \
    --data-store /home/jdoe/features.tsv \
    --output /home/jdoe/feature_select.yml \
    --max-feature-size 30000 --min-feature-weight 0.05
```

The above command will generate the file /home/jdoe/feature_select.yml with contents similar
to the following:

```
collection_reader:
  class_name: com.groupon.nakala.db.TsvCategorizedTextCollectionReader
  parameters:
    file_name: /home/jdoe/train.tsv
    separator: \t
    id_field: 0        # 0-based index of the record id
    label_field: 1     # 0-based index of the comma-separated recommendations
    text_field: 2      # 0-based index of the website text

collection_analyzer:
  class_name: com.groupon.nakala.analysis.BnsWeightCalculator
  parameters:
#    target_class: TARGET_CLASS_NAME # only needed if you want to train a binary classifier for a particular class
    use_absolute_values: true
    max_feature_size: 30000     # hard cap on the size of feature set
    min_feature_weight: 0.05    # minimum feature score to be included in the feature set
    tokenizer:
      class_name: com.groupon.nakala.core.RegexpTokenizerStream
    normalizers:
      - class_name: com.groupon.nakala.normalization.MarkupRemover
      - class_name: com.groupon.nakala.normalization.CaseNormalizer
      - class_name: com.groupon.nakala.normalization.NumberNormalizer
    min_df: 3    # minimum document frequency of a feature to be included in the feature set
#    stopwords:  # not required. the stopwords list specified below contain 500 English stopwords. Should not be used for other languages
#      file_name: <PATH_TO_STOP_LIST_FILE>

data_stores:
  - class_name: com.groupon.nakala.db.FlatFileStore
    parameters:
      file_name: /home/jdoe/features.tsv
```

Now run this task:

```
script/simpleJobFlow -c /home/jdoe/feature_select.yml
```

This will generate the file /home/jdoe/features.tsv.

### Training

For training we need a new YAML file.

```
python generate_yaml_file.py --task svm --phase learn --input-file /home/jdoe/train.tsv \
    --id-field 0 --label-field 1 --text-field 2 \
    --feature-file /home/jdoe/features.tsv \
    --data-store /home/jdoe/model \
    --output /home/jdoe/train.yml \
    --number-of-threads 4
```

This will generate a YAML file named /home/jdoe/train.yml with content similar to the following:

```
collection_reader:
  class_name: com.groupon.nakala.db.TsvCategorizedTextCollectionReader
    parameters:
      file_name: /home/jdoe/train.tsv
      separator: \t
      id_field: 0        # 0-based index of the record id
      label_field: 1     # 0-based index of the comma-separated recommendations
      text_field: 2      # 0-based index of the website text

collection_analyzer:
  class_name: com.groupon.ml.svm.LibSvmTrainerner
  parameters:
#    target_class: TARGET_CLASS_NAME       # Needed if building a binary classifier.
    find_best_parameters: true    # set to true to perform grid search
    number_of_threads: 4          # number of threads to use to parallelize grid search
    sample: 0.2    # 20% sample size for parameter optimization. Use this for large training sets. If unspecified, all training data is used in grid search.
    # weights: 0:1.0,1:6.0  # This is to give the second label in alphabetical order more weight.
    # c: 1.0 # default: 1 -- can be used when find_best_parameters is false
    # gamma: 0.0001 # default: 1/number of features -- can be used when find_best_parameter is false
    representer:
      class_name: com.groupon.nakala.core.TfFeatureWeightTextRepresenter
      parameters:
        normalize_by_length: true
        features:
          class_name: com.groupon.nakala.core.Features
          parameters:
            file_name: /home/jdoe/features.tsv
        tokenizer:
          class_name: com.groupon.nakala.core.RegexpTokenizerStream
        normalizers:
          - class_name: com.groupon.nakala.normalization.MarkupRemover
          - class_name: com.groupon.nakala.normalization.CaseNormalizer
          - class_name: com.groupon.nakala.normalization.NumberNormalizer

data_stores:
  - class_name: com.groupon.nakala.db.FlatFileStore
    parameters:
      # file_name here is actually a file stem: This collection analyzer produces three files:
      #    filestem.model  : the svm model
      #    filestem.range  : value range file for scaling new data
      #    filestem.recommendations : list of recommendations in the training data for labeling new data
      file_name: /home/jdoe/model
```

Now run this training task:

```
script/simpleJobFlow -c /home/jdoe/train.yml
```

The training task will generate four files:

- SVM model file: /home/jdoe/model.mod
- Value ranges used for normalization: /home/jdoe/model.range
- Labels used in the model: /home/jdoe/model.recommendations
- Best parameters found (for information only): /home/jdoe/model.params

Test the classifier
-------------------

Let's assume you have the test file /home/jdoe/test.tsv with the same format as the training file.
To test the classifier using this data generate another YAML configuration file as follows:

```
python generate_yaml_file.py --task svm --phase evaluate --input-file /home/jdoe/test.tsv \
    --id-field 0 --label-field 1 --text-field 2 \
    --feature-file /home/jdoe/features.tsv \
    --svm-output-stem /home/jdoe/model \
    --data-store /home/jdoe/report.xls
```

This will generate a YAML file similar to this:

```
collection_reader:
  class_name: com.groupon.nakala.db.TsvCategorizedTextCollectionReader
    parameters:
      file_name: /home/jdoe/test.tsv
      separator: \t
      id_field: 0        # 0-based index of the record id
      label_field: 1     # 0-based index of the comma-separated recommendations
      text_field: 2      # 0-based index of the website text

collection_analyzer:
  class_name: com.groupon.ml.ClassifierEvaluator
  parameters:
    # target_class: TARGET_CLASS_NAME # only needed when targeting a specific class
    min_threshold: 0.0  # min score threshold to report on
    max_threshold: 1.0  # max score threshold to report on
    threshold_step: 0.1 # threshold steps
    analyzer:
      class_name: com.groupon.ml.svm.LibSvmTextClassifier
      parameters:
        model:
          class_name: com.groupon.nakala.core.ResourceReader
          parameters:
            file_name: /home/jdoe/model.model
        recommendations:
          class_name: com.groupon.nakala.core.ResourceReader
          parameters:
            file_name: /home/jdoe/model.recommendations
        representer:
          class_name: com.groupon.nakala.core.TfFeatureWeightTextRepresenter
          parameters:
            normalize_by_length: true
            features:
              class_name: com.groupon.nakala.core.Features
              parameters:
                file_name: /home/jdoe/features.tsv
            tokenizer:
              class_name: com.groupon.nakala.core.RegexpTokenizerStream
            normalizers:
              - class_name: com.groupon.nakala.normalization.MarkupRemover
              - class_name: com.groupon.nakala.normalization.CaseNormalizer
              - class_name: com.groupon.nakala.normalization.NumberNormalizer
            scaler:
              class_name: com.groupon.ml.svm.ValueScaler
              parameters:
                file_name: /home/jdoe/model.range

data_stores:
  - class_name: com.groupon.nakala.db.FlatFileStore
    parameters:
      file_name: /home/jdoe/report.xls
```

Now run this test task:

```
script/simpleJobFlow -c /home/jdoe/test.yml
```

The task will run the trained classifier on the test data and generate an Excel report file.
The report contains precision, recall, and F-score numbers for the range of score thresholds specified in
the configuration file, as well as the detailed output from the classifier.

Run classifier on new data
--------------------------

Once you have one or more binary or n-ary model(s), you will want to use those models to classify
new text documents. Let's assume your unclassified data is in /home/jdoe/new_data.tsv, and it contains
two columns one id and the other the text to be classified. To classify these data, generate another
YAML file:

```
python generate_yaml_file.py --task svm --phase classify --input-file /home/jdoe/new_data.tsv \
    --id-field 0 --text-field 1 \
    --feature-file /home/jdoe/features.tsv
    --svm-output-stem /home/jdoe/model \
    --data-store /home/jdoe/new_classifications.tsv
    --output /home/jdoe/classify.yml \
```

This will generate the file /home/jdoe/classify.yml with content similar to the following:

```
collection_reader:
  class_name: com.groupon.textmining.db.TsvIdentifiableTextCollectionReader
  parameters:
    file_name: /home/jdoe/new_data.tsv
    separator: \t
    id_field: 0      # 0-based index of record id
    text_field: 1    # 0-based index of website text

collection_analyzer:
  class_name: com.groupon.ml.ClassifierCollectionAnalyzer
  parameters:
    analyzer:
      class_name: com.groupon.ml.svm.MultiModelClassifier
      parameters:
        analyzers:
              - class_name: com.groupon.ml.svm.LibSvmTextClassifier
                parameters:
                  model:
                    class_name: com.groupon.textmining.core.ResourceReader
                    parameters:
                      file_name: /home/jdoe/model.model
                  recommendations:
                    class_name: com.groupon.textmining.core.ResourceReader
                    parameters:
                      file_name: /home/jdoe/model.recommendations
                  representer:
                    class_name: com.groupon.textmining.core.TfFeatureWeightTextRepresenter
                    parameters:
                      normalize_by_length: true
                      features:
                        class_name: com.groupon.textmining.core.Features
                        parameters:
                          file_name: /home/jdoe/features.tsv
                      tokenizer:
                        class_name: com.groupon.textmining.core.RegexpTokenizerStream
                      normalizers:
                        - class_name: com.groupon.textmining.normalization.MarkupRemover
                        - class_name: com.groupon.textmining.normalization.CaseNormalizer
                        - class_name: com.groupon.textmining.normalization.NumberNormalizer
                      scaler:
                        class_name: com.groupon.ml.svm.ValueScaler
                        parameters:
                          file_name: /home/jdoe/model.range

data_stores:
  - class_name: com.groupon.textmining.db.FlatFileStore
    parameters:
      file_name: /home/jdoe/new_classifications.tsv
```

And finally run the classifier:

```
script/simpleJobFlow -c /home/jdoe/classify.yml
```

The output of the classifier will be saved in /home/jdoe/new_classifications.tsv. It will have the
following format:

```
id    recommendation1:score    label2:score ...
```

Extract Snippets from Reviews
-----------------------------

Now say you have a cropus of consumer reviews, and you want to perform some sentiment analysis. You
start by extracting some relevant positive and negative snippets. Look at the contents of

```
jobflows/extract_snippets_from_reviews.yml
```

The file looks like this:

```
collection_reader:
  class_name: com.groupon.nakala.db.TsvIdentifiableTextCollectionReader
  parameters:
    file_name: <path_to_corpus>
    separator: \t
    id_field: 0
    text_field: 1

analyzer:
  class_name: com.groupon.nakala.sentiment.SentimentAnalyzer
  parameters:
    domains:
      - cleanliness
      - family
      - food
      - location
      - luxury
      - nightlife
      - overall
      - parking
      - pet
      - quiet
      - romance
      - staff
      - value
      - view
      - would_return

data_stores:
  - class_name: com.groupon.nakala.db.FlatFileStore
    parameters:
      file_name: <path_to_output>

number_of_threads: 7
```

This configuration file assumes that your corpus is in a tab-separated file with record ids in the first column,
and the review text in the second column. It then calls the class SentimentAnalyzer and tells it to extract
positive and negative snippets for the domains listed (i.e., cleanliness, family, etc.). It will then store the
results in a flat file. This is a multithreaded job flow and is run with 7 threads. Edit the file to point to
the correct input and output. To run this type:

```
script/multithreadedjobflow -c jobflows/extract_snippets_from_reviews.yml
```

The output will look like the following:

```
<record-id>  <score>  <domain>  <snippet>  <highlighted-snippet>  <amplified-by-title>  <overridden-by-title>  <original-score>
```

where <record-id> is the original id of the review; <score> refers to the sentiment polarity of the snippet (score > 0.5 is
positive and score < 0.5 is negative); <domain> refers to the target of the sentiment (i.e., cleanliness, etc.); <snippet>
is the sentence extracted; <highlighted-snippet> is the same snippet with some keywords possibly highlighted;
<amplify-by-title> is a boolean saying whether the title of the review (if present) has been used to amplify the
score of the snippet; <overriden-by-title> is another boolean flag that says whether the score has been overriden by
the contents of the title (if present); and <original-score> is the score before overriding (if applicable).

License
=======

Copyright (c) 2013, Groupon, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Neither the name of GROUPON nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


text:
package org.ops4j.ramler.typescript;

import org.junit.jupiter.api.Test;

public class UnionTest extends AbstractGeneratorTest {

    @Override
    public String getBasename() {
        return "union";
    }

    @Test
    public void shouldFindModules() {
        assertModules("city", "dog", "favourite");
    }

    @Test
    public void shouldFindCityInterface() {
        expectInterface("City");
        assertImports();
        assertProperty("name", "string");
        assertProperty("population", "number");
        verifyInterface();
    }

    @Test
    public void shouldFindDogInterface() {
        expectInterface("Dog");
        assertImports();
        assertProperty("name", "string");
        assertProperty("furColour", "string");
        verifyInterface();
    }

    @Test
    public void shouldFindFavouriteAlias() {
        expectTypeAlias("Favourite", "City", "Dog");
        assertImports("City", "Dog");
    }
}


text:
var ibc = {};
var chaincode = {};
var async = require('async');
var creds = require("../user_creds.json");
var isRetailer = "False";

module.exports.setup = function(sdk, cc){
	ibc = sdk;
	chaincode = cc;
};

// Devesh: shouldn't 'owner' be renamed to 'user'. Also errors that are received from server side need to be handled better and actually displayed to the browser.
module.exports.process_msg = function(ws, data, owner){

	if(data.type == 'chainstats'){
		console.log('Chainstats msg');
		ibc.chain_stats(cb_chainstats);
	}
	else if(data.type == 'createItem'){
		console.log('Create Item ', data, owner);
		if(data.item){
			chaincode.invoke.createItem([data.item.id, data.item.currentowner, data.item.barcode, data.item.vdate, data.item.location], cb_invoked_createitem);				//create a new paper
		}
	}
	else if(data.type == 'transferItem'){
		console.log('Tranfer Item ', data);
		chaincode.invoke.transferOwnership([data.item.id, data.item.user, data.item.date, data.item.location, data.item.newowner], cb_invoked_transferitem);
	}
	else if(data.type == 'confirmItem'){
		console.log('Confirm Item ', data);
		for (var i in creds){
			if (creds[i].username == data.item.user && creds[i].role == "RETAILER"){
				isRetailer = "True";
			}
		}
		chaincode.invoke.confirmOwnership([data.item.id, data.item.user, data.item.date, data.item.location, isRetailer], cb_invoked_confirmitem);
	}
	else if(data.type == 'getItem'){
		console.log('Get Item', data.itemId);
		chaincode.query.getItemDetailsWithID([data.itemId], cb_got_item);
	}
	else if(data.type == 'getAllItems'){
		console.log('Get All Items', owner);
		chaincode.query.getCurrentOwnerItems([owner], cb_got_allitems);
	}
	else if(data.type == 'getAllItemsStatus'){
		console.log('Get All Items By Status', data.itstatus, owner);
		chaincode.query.getCurrentOwnerItemsByStatus([owner, data.itstatus], cb_got_allitems);
	}
//	else if(data.type == 'getItemByBarcode'){
//		console.log('Get single Item By Barcode', data.barcode);
//		chaincode.query.getItemDetailsWithBarcode([data.barcode], cb_got_item);
//	}
	else if(data.type == 'changeStatus'){
		console.log('Change status of single item', data, owner);
		chaincode.invoke.changeStatus([data.item.id, owner, data.item.date, data.item.location, data.item.status], cb_invoked_changed_status);
	}

	function cb_got_item(e, item){
		if(e != null){
			console.log('Get Item error', e);
		}
		else{
			sendMsg({msg: 'item', item: JSON.parse(item)});
		}
	}

	function cb_got_allitems(e, allItems){
		if(e != null){
			console.log('Get All Items error', e);
		}
		else{
			sendMsg({msg: 'allItems', items: JSON.parse(allItems).items});
		}
	}

	function cb_invoked_createitem(e, a){
		console.log('response: ', e, a);
		if(e != null){
			console.log('Invoked create item error', e);
		}
		else{
			console.log("Item ID #" + data.item.id)
			sendMsg({msg: 'itemCreated', Id: data.item.id});
		}
	}

	function cb_invoked_transferitem(e, a){
		console.log('response: ', e, a);
		if(e != null){
			console.log('Invoked transfer item error', e);
		}
		else{
			console.log("Item ID #" + data.item.id)
			sendMsg({msg: 'itemTransferred'});
		}
	}

	function cb_invoked_confirmitem(e, a){
		console.log('response: ', e, a);
		if(e != null){
			console.log('Invoked confirm item error', e);
		}
		else{
			console.log("Item ID #" + data.item.id)
			sendMsg({msg: 'itemConfirmed'});
		}
	}

	function cb_invoked_changed_status(e, a){
		console.log('response: ', e, a);
		if(e != null){
			console.log('Invoked change status error', e);
		}
		else{
			console.log("Item ID #" + data.item.id)
			sendMsg({msg: 'itemChangedStatus'});
		}
	}

	//call back for getting the blockchain stats, lets get the block height now
	var chain_stats = {};
	function cb_chainstats(e, stats){
		chain_stats = stats;
		if(stats && stats.height){
			var list = [];
			for(var i = stats.height - 1; i >= 1; i--){										//create a list of heights we need
				list.push(i);
				if(list.length >= 8) break;
			}
			list.reverse();																//flip it so order is correct in UI
			console.log(list);
			async.eachLimit(list, 1, function(key, cb) {								//iter through each one, and send it
				ibc.block_stats(key, function(e, stats){
					if(e == null){
						stats.height = key;
						sendMsg({msg: 'chainstats', e: e, chainstats: chain_stats, blockstats: stats});
					}
					cb(null);
				});
			}, function() {
			});
		}
	}

	//call back for getting a block's stats, lets send the chain/block stats
	function cb_blockstats(e, stats){
		if(chain_stats.height) stats.height = chain_stats.height - 1;
		sendMsg({msg: 'chainstats', e: e, chainstats: chain_stats, blockstats: stats});
	}

	//send a message, socket might be closed...
	function sendMsg(json){
		if(ws){
			try{
				ws.send(JSON.stringify(json));
			}
			catch(e){
				console.log('error ws', e);
			}
		}
	}
};


text:
package com.taoswork.tallycheck.general.solution.menu;

public interface IMenuEntryUpdater {
    void update(IMenuEntry entry);
}


text:
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2012 Couchbase, Inc.
 *
 *   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.
 */

/* View Benchmark. This application is using libcouchbase to store
 * single key and then get this key back infinitely through the view
 * through the views.
 *
 * BUILD:
 *
 *      cc -o vb vb.c -lcouchbase
 *      cl /DWIN32 /Iinclude vb.c lib\libcouchbase.lib
 *
 * RUN:
 *
 *      valgrind -v --tool=memcheck  --leak-check=full --show-reachable=yes ./vb
 *      ./vb key size <connstr> <passwd>
 *      vb.exe key size <connstr> <passwd>
 */

#include <stdio.h>
#include <libcouchbase/couchbase.h>
#include <libcouchbase/api3.h>
#include <libcouchbase/views.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#ifdef _WIN32
#define PRIu64 "I64u"
#else
#include <signal.h>
#include <inttypes.h>
#endif

#ifndef _WIN32
static void handle_sigint(int sig)
{
    (void)sig;
    printf("Exiting on SIGINT\n");
    exit(0);
}

#define INSTALL_SIGINT_HANDLER() signal(SIGINT, handle_sigint)
#else
#define INSTALL_SIGINT_HANDLER()
#endif

static void
store_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
{
    if (rb->rc == LCB_SUCCESS) {
        fprintf(stderr, "STORED \"%.*s\" CAS: %"PRIu64"\n", (int)rb->nkey, rb->key, rb->cas);
    } else {
        fprintf(stderr, "STORE ERROR: %s (0x%x)\n", lcb_strerror(instance, rb->rc), rb->rc);
        exit(EXIT_FAILURE);
    }
    (void)cbtype;
}

const char *view;
const char *design;

static void
do_query_view(lcb_t instance);

static void
viewrow_callback(lcb_t instance, int cbtype, const lcb_RESPVIEWQUERY *resp)
{
    if (resp->rflags & LCB_RESP_F_FINAL) {
        if (resp->rc == LCB_SUCCESS) {
            do_query_view(instance);
        } else {
            fprintf(stderr, "Couldn't query view: %s (0x%x)\n", lcb_strerror(NULL, resp->rc), resp->rc);
            if (resp->htresp != NULL) {
                fprintf(stderr, "HTTP Status: %u\n", resp->htresp->htstatus);
                fprintf(stderr, "HTTP Body: %.*s\n", (int)resp->htresp->nbody, resp->htresp->body);
            }
            exit(EXIT_FAILURE);
        }
    }
    (void)cbtype;
}

static void
http_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
{
    const lcb_RESPHTTP *rh = (const lcb_RESPHTTP *)rb;
    fprintf(stderr, "%.*s... %d\n", (int)rb->nkey, rh->key, rh->htstatus);
    if (rh->rc != LCB_SUCCESS) {
        fprintf(stderr, "Couldn't issue HTTP request: %s\n", lcb_strerror(NULL, rh->rc));
        exit(EXIT_FAILURE);
    } else if (rh->htstatus != 201) {
        fprintf(stderr, "Negative reply from server!\n");
        fprintf(stderr, "%*.s\n", (int)rh->nbody, rh->body);
        exit(EXIT_FAILURE);
    }

    (void)cbtype;
}

static void
do_query_view(lcb_t instance)
{
    lcb_CMDVIEWQUERY cmd = { 0 };
    lcb_error_t err;
    lcb_view_query_initcmd(&cmd, design, view, NULL, viewrow_callback);
    cmd.cmdflags |= LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
    err = lcb_view_query(instance, NULL, &cmd);
    if (err != LCB_SUCCESS) {
        fprintf(stderr, "Couldn't schedule view query: %s\n", lcb_strerror(NULL, err));
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char *argv[])
{
    lcb_error_t err;
    lcb_t instance;
    struct lcb_create_st create_options;
    const char *key = "foo";
    size_t nkey = strlen(key);
    void *bytes;
    size_t nbytes = 6; /* the size of the value */

    memset(&create_options, 0, sizeof(create_options));
    create_options.version = 3;

    if (argc > 1) {
        key = argv[1];
        nkey = strlen(key);
    }
    if (argc > 2) {
        nbytes = atol(argv[2]);
    }
    if (argc > 3) {
        create_options.v.v3.connstr = argv[3];
    }
    if (argc > 4) {
        create_options.v.v3.passwd = argv[4];
    }

    INSTALL_SIGINT_HANDLER();

    err = lcb_create(&instance, &create_options);
    if (err != LCB_SUCCESS) {
        fprintf(stderr, "Failed to create libcouchbase instance: %s\n",
                lcb_strerror(NULL, err));
        exit(EXIT_FAILURE);
    }
    /* Initiate the connect sequence in libcouchbase */
    if ((err = lcb_connect(instance)) != LCB_SUCCESS) {
        fprintf(stderr, "Failed to initiate connect: %s\n", lcb_strerror(NULL, err));
        lcb_destroy(instance);
        exit(EXIT_FAILURE);
    }
    lcb_wait(instance);
    if ((err = lcb_get_bootstrap_status(instance)) != LCB_SUCCESS) {
        fprintf(stderr, "Failed to establish connection to cluster: %s\n", lcb_strerror(NULL, err));
        exit(EXIT_FAILURE);
    }
    lcb_install_callback3(instance, LCB_CALLBACK_HTTP, http_callback);
    lcb_install_callback3(instance, LCB_CALLBACK_STORE, store_callback);

    fprintf(stderr, "key: \"%s\"\n", key);
    fprintf(stderr, "value size: %ld\n", nbytes);
    fprintf(stderr, "connection string: %s\n", create_options.v.v3.connstr ? create_options.v.v3.connstr : "");
    fprintf(stderr, "password: %s\n", create_options.v.v0.passwd ? create_options.v.v3.passwd : "");
    bytes = malloc(nbytes);

    {
        lcb_CMDSTORE cmd = { 0 };
        cmd.operation = LCB_SET;
        LCB_CMD_SET_KEY(&cmd, key, nkey);
        LCB_CMD_SET_VALUE(&cmd, bytes, nbytes);
        err = lcb_store3(instance, NULL, &cmd);
        if (err != LCB_SUCCESS) {
            fprintf(stderr, "Failed to store: %s\n", lcb_strerror(NULL, err));
            exit(EXIT_FAILURE);
        }
    }
    lcb_wait(instance);

    /* Set view and design name: */
    view = "all";
    design = key;

    {
        char design_path[64] = { 0 };
        char doc[256] = { 0 };
        lcb_CMDHTTP cmd = { 0 };
        sprintf(design_path, "_design/%s", design);
        sprintf(doc, "{\"views\":{\"all\":{\"map\":\"function(doc,meta){if(meta.id=='%s'){emit(meta.id)}}\"}}}", key);

        LCB_CMD_SET_KEY(&cmd, design_path, strlen(design_path));
        cmd.body = doc;
        cmd.nbody = strlen(doc);
        cmd.method = LCB_HTTP_METHOD_PUT;
        cmd.type = LCB_HTTP_TYPE_VIEW;
        cmd.content_type = "application/json";
        err = lcb_http3(instance, NULL, &cmd);
        if (err != LCB_SUCCESS) {
            fprintf(stderr, "Failed to create design document: %s (0x%02x)\n", lcb_strerror(NULL, err), err);
            exit(EXIT_FAILURE);
        }
    }
    lcb_wait(instance);

    do_query_view(instance);
    lcb_wait(instance);
    lcb_destroy(instance);

    exit(EXIT_SUCCESS);
}


text:
package com.heaven7.plugin.data.mediator.convertor;

import java.util.ArrayList;
import java.util.List;

import static com.heaven7.plugin.data.mediator.convertor.Util.checkArgument;

public class Property {

    private static final String TYPE_STRING = "java.lang.String";

    private static final String TYPE_int = "int";
    private static final String TYPE_long = "long";
    private static final String TYPE_short = "short";
    private static final String TYPE_byte = "byte";
    private static final String TYPE_boolean = "boolean";
    private static final String TYPE_float = "float";
    private static final String TYPE_double = "double";
    private static final String TYPE_char = "char";

    private final String type;
    private final String name;
    private final int complexType;

    /**
     * create a property instance by type , name  and complex type
     *
     * @param type the type string. eg: 'int', 'java.lang.Integer'
     * @param name the property name
     */
    public Property(String type, String name, int complexType) {
        if (type == null || name == null) {
            throw new NullPointerException();
        }
        this.type = type;
        this.name = name;
        this.complexType = complexType;
    }

    /**
     * get the type as String.
     *
     * @return the type as String.
     * @since 1.2.0
     */
    public String getTypeString() {
        return type;
    }

    /**
     * get base the property type.
     *
     * @return the base type.
     * @see #getComplexType()
     */
    public Class<?> getType() {
        switch (type) {
            case TYPE_int:
                return int.class;
            case TYPE_long:
                return long.class;
            case TYPE_short:
                return short.class;
            case TYPE_byte:
                return byte.class;
            case TYPE_boolean:
                return boolean.class;
            case TYPE_float:
                return float.class;
            case TYPE_double:
                return double.class;
            case TYPE_char:
                return char.class;
        }
        try {
            return bestGuessClass(type);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * get the property name.
     *
     * @return the property name
     */
    public String getName() {
        return name;
    }

    /**
     * get the complex type
     *
     * @return the complex type
     */
    public int getComplexType() {
        return complexType;
    }

    /**
     * {@inheritDoc}
     *
     * @param o the object
     * @return true if equals.
     * @see Object#equals(Object)
     * @since 1.0.3
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Property property = (Property) o;

        if (complexType != property.complexType) return false;
        if (!type.equals(property.type)) return false;
        return name.equals(property.name);
    }

    /**
     * {@inheritDoc}
     *
     * @return the hash code.
     * @see Object#hashCode()
     * @since 1.0.3
     */
    @Override
    public int hashCode() {
        int result = type.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + complexType;
        return result;
    }

    @Override
    public String toString() {
        return "Property{" +
                "type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", complexType=" + complexType +
                '}';
    }

    //resolve inner class
    private static Class<?> bestGuessClass(String classNameString) throws ClassNotFoundException{
        List<String> names = new ArrayList<>();

        // Add the package name, like "java.util.concurrent", or "" for no package.
        int p = 0;
        while (p < classNameString.length() && Character.isLowerCase(classNameString.codePointAt(p))) {
            p = classNameString.indexOf('.', p) + 1;
            checkArgument(p != 0, "couldn't make a guess for %s", classNameString);
        }
        names.add(p != 0 ? classNameString.substring(0, p - 1) : "");

        // Add the class names, like "Map" and "Entry".
        for (String part : classNameString.substring(p).split("\\.", -1)) {
            checkArgument(!part.isEmpty() && Character.isUpperCase(part.codePointAt(0)),
                    "couldn't make a guess for %s", classNameString);
            names.add(part);
        }

        final int size = names.size();
        checkArgument(size >= 2, "couldn't make a guess for %s", classNameString);
        //System.out.println(names);
        StringBuilder sb = new StringBuilder();
        sb.append(names.get(0))
                .append(".")
                .append(names.get(1));
        if(size > 2){
            for(int i = 2 ; i < size; i ++){
                sb.append("$")
                        .append(names.get(i));
            }
        }
        return Class.forName(sb.toString());
    }

    public boolean isString() {
        return TYPE_STRING.equals(type);
    }
}