text:
package com.streamsets.pipeline.stage.origin.lib;

import com.streamsets.pipeline.api.Field;
import com.streamsets.pipeline.api.Record;
import com.streamsets.pipeline.api.Stage;
import com.streamsets.pipeline.api.StageException;
import com.streamsets.pipeline.api.ToErrorContext;
import com.streamsets.pipeline.api.impl.Utils;
import com.streamsets.pipeline.config.DataFormat;
import com.streamsets.pipeline.config.DatagramMode;
import com.streamsets.pipeline.config.OriginAvroSchemaSource;
import com.streamsets.pipeline.lib.parser.DataParser;
import com.streamsets.pipeline.lib.parser.DataParserException;
import com.streamsets.pipeline.lib.parser.DataParserFactory;
import com.streamsets.pipeline.lib.parser.DataParserFactoryBuilder;
import com.streamsets.pipeline.lib.parser.RecoverableDataParserException;
import com.streamsets.pipeline.lib.parser.excel.WorkbookParserConstants;
import com.streamsets.pipeline.lib.parser.log.LogDataFormatValidator;
import com.streamsets.pipeline.lib.parser.log.RegExConfig;
import com.streamsets.pipeline.lib.parser.net.netflow.NetflowDataParserFactory;
import com.streamsets.pipeline.lib.parser.text.TextDataParserFactory;
import com.streamsets.pipeline.lib.parser.xml.XmlDataParserFactory;
import com.streamsets.pipeline.lib.util.DelimitedDataConstants;
import com.streamsets.pipeline.lib.util.ProtobufConstants;
import com.streamsets.pipeline.lib.xml.xpath.XPathValidatorUtil;
import com.streamsets.pipeline.stage.common.DataFormatErrors;
import com.streamsets.pipeline.stage.common.DataFormatGroups;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.streamsets.pipeline.lib.util.AvroSchemaHelper.SCHEMA_ID_KEY;
import static com.streamsets.pipeline.lib.util.AvroSchemaHelper.SCHEMA_KEY;
import static com.streamsets.pipeline.lib.util.AvroSchemaHelper.SCHEMA_REPO_URLS_KEY;
import static com.streamsets.pipeline.lib.util.AvroSchemaHelper.SCHEMA_SOURCE_KEY;
import static com.streamsets.pipeline.lib.util.AvroSchemaHelper.SUBJECT_KEY;
import static org.apache.commons.lang.StringUtils.isEmpty;

public class DataFormatParser {
  public static final String DATA_FORMAT_CONFIG_PREFIX = "dataFormatConfig.";
  private final String parentName;
  private final DataParserFormatConfig dataFormatConfig;
  private final MessageConfig messageConfig;
  private final DataFormat dataFormat;
  private LogDataFormatValidator logDataFormatValidator;
  private Charset messageCharset;
  private DataParserFactory parserFactory;

  public DataFormatParser(
      String parentName,
      DataFormat dataFormat,
      DataParserFormatConfig dataFormatConfig,
      MessageConfig messageConfig
  ) {
    this.parentName = parentName;
    this.dataFormatConfig = dataFormatConfig;
    this.messageConfig = messageConfig;
    this.dataFormat = dataFormat;
  }

  public List<Stage.ConfigIssue> init(Stage.Context context) {
    return init(context, "");
  }

  public List<Stage.ConfigIssue> init(Stage.Context context, String configPrefix) {
    List<Stage.ConfigIssue> issues = new ArrayList<>();
    final String prefix = configPrefix + DATA_FORMAT_CONFIG_PREFIX;
    switch (dataFormat) {
      case JSON:
        if (dataFormatConfig.jsonMaxObjectLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormat.JSON.name(),
                  prefix + "maxJsonObjectLen",
                  ParserErrors.PARSER_04
              )
          );
        }
        break;
      case TEXT:
        if (dataFormatConfig.textMaxLineLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormat.TEXT.name(),
                  prefix + "maxLogLineLength",
                  ParserErrors.PARSER_04
              )
          );
        }
        break;
      case DELIMITED:
        if (dataFormatConfig.csvMaxObjectLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormat.DELIMITED.name(),
                  prefix + "csvMaxObjectLen",
                  ParserErrors.PARSER_04
              )
          );
        }
        break;
      case XML:
        if (messageConfig != null && messageConfig.produceSingleRecordPerMessage) {
          issues.add(
              context.createConfigIssue(
                  parentName,
                  configPrefix + "messageConfig.produceSingleRecordPerMessage",
                  ParserErrors.PARSER_06
              )
          );
        }
        if (dataFormatConfig.xmlMaxObjectLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormatGroups.DATA_FORMAT.name(),
                  prefix + "maxXmlObjectLen",
                  ParserErrors.PARSER_04
              )
          );
        }
        if (StringUtils.isNotBlank(dataFormatConfig.xmlRecordElement)) {
          String invalidXPathError = XPathValidatorUtil.getXPathValidationError(dataFormatConfig.xmlRecordElement);
          if (StringUtils.isNotBlank(invalidXPathError)) {
            issues.add(context.createConfigIssue(
                DataFormatGroups.DATA_FORMAT.name(),
                prefix + "xmlRecordElement",
                ParserErrors.PARSER_02,
                dataFormatConfig.xmlRecordElement,
                invalidXPathError
            ));
          } else {
            final Set<String> nsPrefixes = XPathValidatorUtil.getNamespacePrefixes(dataFormatConfig.xmlRecordElement);
            nsPrefixes.removeAll(dataFormatConfig.xPathNamespaceContext.keySet());
            if (!nsPrefixes.isEmpty()) {
              issues.add(context.createConfigIssue(
                  DataFormatGroups.DATA_FORMAT.name(),
                  prefix + "xPathNamespaceContext",
                  ParserErrors.PARSER_09,
                  StringUtils.join(nsPrefixes, ", ")
              ));
            }
          }
        }
        break;
      case SDC_JSON:
        break;
      case LOG:
        logDataFormatValidator = new LogDataFormatValidator(
            dataFormatConfig.logMode,
            dataFormatConfig.logMaxObjectLen,
            dataFormatConfig.retainOriginalLine,
            dataFormatConfig.customLogFormat,
            dataFormatConfig.regex,
            dataFormatConfig.grokPatternDefinition,
            dataFormatConfig.grokPattern,
            dataFormatConfig.enableLog4jCustomLogFormat,
            dataFormatConfig.log4jCustomLogFormat,
            dataFormatConfig.onParseError,
            dataFormatConfig.maxStackTraceLines,
            DataFormat.LOG.name(),
            getFieldPathToGroupMap(dataFormatConfig.fieldPathsToGroupName)
        );
        logDataFormatValidator.validateLogFormatConfig(context, prefix, issues);
        break;
      case AVRO:
        if(dataFormatConfig.avroSchemaSource == OriginAvroSchemaSource.INLINE && isEmpty(dataFormatConfig.avroSchema)) {
          issues.add(
              context.createConfigIssue(
                  DataFormat.AVRO.name(),
                  prefix + "avroSchema",
                  ParserErrors.PARSER_07,
                  dataFormatConfig.avroSchema
              )
          );
        }
        break;
      case PROTOBUF:
        if (dataFormatConfig.protoDescriptorFile == null || dataFormatConfig.protoDescriptorFile.isEmpty()) {
          issues.add(
            context.createConfigIssue(
              DataFormatGroups.DATA_FORMAT.name(),
                prefix + "protoDescriptorFile",
              DataFormatErrors.DATA_FORMAT_07
            )
          );
        } else {
          File file = new File(context.getResourcesDirectory(), dataFormatConfig.protoDescriptorFile);
          if (!file.exists()) {
            issues.add(
              context.createConfigIssue(
                DataFormatGroups.DATA_FORMAT.name(),
                  prefix + "protoDescriptorFile",
                DataFormatErrors.DATA_FORMAT_09,
                file.getAbsolutePath()
              )
            );
          }
          if (dataFormatConfig.messageType == null || dataFormatConfig.messageType.isEmpty()) {
            issues.add(
              context.createConfigIssue(
                DataFormatGroups.DATA_FORMAT.name(),
                  prefix + "messageType",
                DataFormatErrors.DATA_FORMAT_08
              )
            );
          }
        }
        break;
      case WHOLE_FILE:
        if (dataFormatConfig.wholeFileMaxObjectLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormat.XML.name(),
                  prefix + "maxWholeFileObjectLen",
                  ParserErrors.PARSER_04
              )
          );
        }
        break;
      case BINARY:
        if (dataFormatConfig.binaryMaxObjectLen < 1) {
          issues.add(
              context.createConfigIssue(
                  DataFormatGroups.DATA_FORMAT.name(),
                  prefix + "binaryMaxObjectLen",
                  ParserErrors.PARSER_04
              )
          );
        }
        break;
      case DATAGRAM:
        if (dataFormatConfig.datagramMode == DatagramMode.COLLECTD) {
          dataFormatConfig.checkCollectdParserConfigs(context, prefix, issues);
        } else if (dataFormatConfig.datagramMode == DatagramMode.NETFLOW) {
          NetflowDataParserFactory.validateConfigs(
              context,
              issues,
              DataFormatGroups.DATA_FORMAT.name(),
              prefix,
              dataFormatConfig.maxTemplateCacheSizeDatagram,
              dataFormatConfig.templateCacheTimeoutMsDatagram,
              "maxTemplateCacheSizeDatagram",
              "templateCacheTimeoutMsDatagram"
          );
        }
        break;
      case NETFLOW:
        NetflowDataParserFactory.validateConfigs(
            context,
            issues,
            DataFormatGroups.DATA_FORMAT.name(),
            prefix,
            dataFormatConfig.maxTemplateCacheSize,
            dataFormatConfig.templateCacheTimeoutMs
        );
        break;
      case SYSLOG:
        // nothing to validate
        break;
      case EXCEL:
        // nothing to validate
        break;
      default:
        issues.add(
            context.createConfigIssue(
                parentName,
                configPrefix +"dataFormat",
                ParserErrors.PARSER_05,
                dataFormat
            )
        );
    }

    DataParserFactoryBuilder builder = new DataParserFactoryBuilder(context, dataFormat.getParserFormat())
      .setCharset(Charset.defaultCharset());
    if (dataFormatConfig.charset == null) {
      messageCharset = StandardCharsets.UTF_8;
    } else {
      try {
        messageCharset = Charset.forName(dataFormatConfig.charset);
      } catch (UnsupportedCharsetException ex) {
        // setting it to a valid one so the parser factory can be configured and tested for more errors
        messageCharset = StandardCharsets.UTF_8;
        issues.add(
            context.createConfigIssue(
                parentName,
                "charset",
                ParserErrors.PARSER_01,
                dataFormatConfig.charset
            )
        );
      }
    }
    builder.setCharset(messageCharset).setRemoveCtrlChars(dataFormatConfig.removeCtrlChars);

    switch (dataFormat) {
      case TEXT:
        builder.setMaxDataLen(dataFormatConfig.textMaxLineLen)
            .setConfig(TextDataParserFactory.USE_CUSTOM_DELIMITER_KEY, dataFormatConfig.useCustomDelimiter)
            .setConfig(TextDataParserFactory.CUSTOM_DELIMITER_KEY, dataFormatConfig.customDelimiter)
            .setConfig(TextDataParserFactory.INCLUDE_CUSTOM_DELIMITER_IN_TEXT_KEY, dataFormatConfig.includeCustomDelimiterInTheText);
        break;
      case JSON:
        builder.setMode(dataFormatConfig.jsonContent);
        builder.setMaxDataLen(dataFormatConfig.jsonMaxObjectLen);
        break;
      case DELIMITED:
        builder.setMaxDataLen(dataFormatConfig.csvMaxObjectLen)
          .setMode(dataFormatConfig.csvFileFormat).setMode(dataFormatConfig.csvHeader)
          .setMode(dataFormatConfig.csvRecordType)
          .setConfig(DelimitedDataConstants.DELIMITER_CONFIG, dataFormatConfig.csvCustomDelimiter)
          .setConfig(DelimitedDataConstants.ESCAPE_CONFIG, dataFormatConfig.csvCustomEscape)
          .setConfig(DelimitedDataConstants.QUOTE_CONFIG, dataFormatConfig.csvCustomQuote)
          .setConfig(DelimitedDataConstants.PARSE_NULL, dataFormatConfig.parseNull)
          .setConfig(DelimitedDataConstants.NULL_CONSTANT, dataFormatConfig.nullConstant)
          .setConfig(DelimitedDataConstants.COMMENT_ALLOWED_CONFIG, dataFormatConfig.csvEnableComments)
          .setConfig(DelimitedDataConstants.COMMENT_MARKER_CONFIG, dataFormatConfig.csvCommentMarker)
          .setConfig(DelimitedDataConstants.IGNORE_EMPTY_LINES_CONFIG, dataFormatConfig.csvIgnoreEmptyLines)
          .setConfig(DelimitedDataConstants.ALLOW_EXTRA_COLUMNS, dataFormatConfig.csvAllowExtraColumns)
          .setConfig(DelimitedDataConstants.EXTRA_COLUMN_PREFIX, dataFormatConfig.csvExtraColumnPrefix)
          .setConfig(
              DelimitedDataConstants.MULTI_CHARACTER_FIELD_DELIMITER_CONFIG,
              dataFormatConfig.multiCharacterFieldDelimiter
          ).setConfig(
              DelimitedDataConstants.MULTI_CHARACTER_LINE_DELIMITER_CONFIG,
              dataFormatConfig.multiCharacterLineDelimiter
          );
        break;
      case XML:
        builder.setMaxDataLen(dataFormatConfig.xmlMaxObjectLen);
        builder.setConfig(XmlDataParserFactory.RECORD_ELEMENT_KEY, dataFormatConfig.xmlRecordElement);
        builder.setConfig(XmlDataParserFactory.INCLUDE_FIELD_XPATH_ATTRIBUTES_KEY,
            dataFormatConfig.includeFieldXpathAttributes);
        builder.setConfig(XmlDataParserFactory.RECORD_ELEMENT_XPATH_NAMESPACES_KEY, dataFormatConfig.xPathNamespaceContext);
        builder.setConfig(XmlDataParserFactory.USE_FIELD_ATTRIBUTES, dataFormatConfig.outputFieldAttributes);
        break;
      case SDC_JSON:
        builder.setMaxDataLen(-1);
        break;
      case LOG:
        logDataFormatValidator.populateBuilder(builder);
        break;
      case AVRO:
        builder
            .setMaxDataLen(Integer.MAX_VALUE)
            .setConfig(SCHEMA_KEY, dataFormatConfig.avroSchema)
            .setConfig(SUBJECT_KEY, dataFormatConfig.subject)
            .setConfig(SCHEMA_ID_KEY, dataFormatConfig.schemaId)
            .setConfig(SCHEMA_SOURCE_KEY, dataFormatConfig.avroSchemaSource)
            .setConfig(SCHEMA_REPO_URLS_KEY, dataFormatConfig.schemaRegistryUrls);
        break;
      case PROTOBUF:
        builder
          .setConfig(ProtobufConstants.PROTO_DESCRIPTOR_FILE_KEY, dataFormatConfig.protoDescriptorFile)
          .setConfig(ProtobufConstants.MESSAGE_TYPE_KEY, dataFormatConfig.messageType)
          .setConfig(ProtobufConstants.DELIMITED_KEY, dataFormatConfig.isDelimited)
          .setMaxDataLen(-1);
        break;
      case WHOLE_FILE:
        builder.setMaxDataLen(dataFormatConfig.wholeFileMaxObjectLen);
        break;
      case BINARY:
        builder.setMaxDataLen(dataFormatConfig.binaryMaxObjectLen);
        break;
      case DATAGRAM:
        dataFormatConfig.buildDatagramParser(builder);
        break;
      case SYSLOG:
        builder.setMaxDataLen(-1);
        break;
      case NETFLOW:
        builder
          .setMaxDataLen(-1)
          .setConfig(NetflowDataParserFactory.OUTPUT_VALUES_MODE_KEY, dataFormatConfig.netflowOutputValuesMode)
          .setConfig(NetflowDataParserFactory.MAX_TEMPLATE_CACHE_SIZE_KEY, dataFormatConfig.maxTemplateCacheSize)
          .setConfig(NetflowDataParserFactory.TEMPLATE_CACHE_TIMEOUT_MS_KEY, dataFormatConfig.templateCacheTimeoutMs);
        break;
      case EXCEL:
        builder
            .setMaxDataLen(-1)
            .setConfig(WorkbookParserConstants.HEADER, dataFormatConfig.excelHeader);
        break;
      default:
        throw new IllegalStateException(Utils.format("Unknown data format: {}", dataFormat));
    }
    try {
      parserFactory = builder.build();
    } catch (Exception ex) {
      issues.add(context.createConfigIssue(null, null, DataFormatErrors.DATA_FORMAT_06, ex.toString(), ex));
    }
    return issues;
  }

  public <CT extends Stage.Context & ToErrorContext> List<Record> parse(CT context, String messageId, byte[] payload) throws StageException {
    List<Record> records = new ArrayList<>();
    try (DataParser parser = parserFactory.getParser(messageId, payload)) {
      Record record = null;
      do {
        try {
          record = parser.parse();
        } catch (RecoverableDataParserException e) {
          handleException(context, messageId, e, e.getUnparsedRecord());
          //Go to next record
          continue;
        }
        if (record != null) {
          records.add(record);
        }
      } while (record != null);
    } catch (IOException |DataParserException ex) {
      Record record = context.createRecord(messageId);
      record.set(Field.create(payload));
      handleException(context, messageId, ex, record);
      return records;
    }
    if (messageConfig != null && messageConfig.produceSingleRecordPerMessage) {
      List<Field> list = new ArrayList<>();
      for (Record record : records) {
        list.add(record.get());
      }
      Record record = records.get(0);
      record.set(Field.create(list));
      records.clear();
      records.add(record);
    }
    return records;
  }

  private <CT extends Stage.Context & ToErrorContext> void handleException(CT context, String messageId, Exception ex, Record record)
    throws StageException {
    switch (context.getOnErrorRecord()) {
      case DISCARD:
        break;
      case TO_ERROR:
        context.toError(record, ParserErrors.PARSER_03, messageId, ex.toString(), ex);
        break;
      case STOP_PIPELINE:
        if (ex instanceof StageException) {
          throw (StageException) ex;
        } else {
          throw new StageException(ParserErrors.PARSER_03, messageId, ex.toString(), ex);
        }
      default:
        throw new IllegalStateException(Utils.format("Unknown on error value '{}'",
          context.getOnErrorRecord(), ex));
    }
  }

  public Charset getCharset() {
    return messageCharset;
  }

  private Map<String, Integer> getFieldPathToGroupMap(List<RegExConfig> fieldPathsToGroupName) {
    if(fieldPathsToGroupName == null) {
      return new HashMap<>();
    }
    Map<String, Integer> fieldPathToGroup = new HashMap<>();
    for(RegExConfig r : fieldPathsToGroupName) {
      fieldPathToGroup.put(r.fieldPath, r.group);
    }
    return fieldPathToGroup;
  }

}


text:
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
import unittest, os, sys, shutil

from server.users import calculate_hash
from server.users import User
from server.users import UserStorage

class TestServerStorage(unittest.TestCase):

    def test_creating_user(self):
        User({'username':'teemu',
              'salt':'',
              'hash':''})

    def test_create_user_storage(self):
        UserStorage()

    def test_fetching_user_from_storage(self):
        storage = UserStorage()
        storage.add_user(User({'username' : 'teemu',
                    'hash': calculate_hash('test'+'test'),
                    'hash': 'test'}))
        self.assertIsNotNone(storage.get_user('teemu'),'There sould be at least one user at the storage')

    def test_authentication(self):
        user = User({'username':'teemu',
                      'hash':calculate_hash('testtest'),
                      'salt':'test',})
        self.assertEqual( user.authenticate('test'), True, 'User should be now authenticated succesfully' )

    def test_fail_authentication(self):
        user = User({'username':'teemu',
                      'hash':calculate_hash('testtest'),
                      'salt':'test',})
        self.assertEqual( user.authenticate('lolo'), False, 'Authentication should fail' )
        user = User({'username':'teemu',
                      'hash':calculate_hash('testtest'),
                      'salt':'lol',})
        self.assertEqual( user.authenticate('test'), False, 'Authentication should fail' )

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

redpajama_set_name: RedPajamaGithub


text:
require 'active_support/all'
require 'active_record'
require 'kawaii_validation/attributed_validator'
require 'kawaii_validation/non_attributed_validator'

module KawaiiValidation
  module ValidatesWithBlock
    def validates(*attributes, &block)
      if block
        validates_block_validator = if attributes.any?
          KawaiiValidation::AttributedValidator.new self, attributes
        else
          KawaiiValidation::NonAttributedValidator.new self
        end
        validates_block_validator.instance_eval(&block)
      else
        super
      end
    end
  end
end


text:
% DOCKER(1) Docker User Manuals
% Docker Community
% JUNE 2014
# NAME
docker-pull - Pull an image or a repository from a registry

# SYNOPSIS
**docker pull**
[**-a**|**--all-tags**]
[**--help**]
NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]

# DESCRIPTION

This command pulls down an image or a repository from a registry. If
there is more than one image for a repository (e.g., fedora) then all
images for that repository name can be pulled down including any tags
(see the option **-a** or **--all-tags**).

If you do not specify a `REGISTRY_HOST`, the command uses Docker's public
registry located at `registry-1.docker.io` by default.

# OPTIONS
**-a**, **--all-tags**=*true*|*false*
   Download all tagged images in the repository. The default is *false*.

**--help**
  Print usage statement

# EXAMPLE

## Pull a repository with multiple images with the -a|--all-tags option set to true.
Note that if the  image is previously downloaded then the status would be
`Status: Image is up to date for fedora`.

    $ docker pull --all-tags fedora
    Pulling repository fedora
    ad57ef8d78d7: Download complete
    105182bb5e8b: Download complete
    511136ea3c5a: Download complete
    73bd853d2ea5: Download complete

    Status: Downloaded newer image for fedora

    $ docker images
    REPOSITORY   TAG         IMAGE ID        CREATED      VIRTUAL SIZE
    fedora       rawhide     ad57ef8d78d7    5 days ago   359.3 MB
    fedora       20          105182bb5e8b    5 days ago   372.7 MB
    fedora       heisenbug   105182bb5e8b    5 days ago   372.7 MB
    fedora       latest      105182bb5e8b    5 days ago   372.7 MB

## Pull a repository with the -a|--all-tags option set to false (this is the default).

    $ docker pull debian
    Using default tag: latest
    latest: Pulling from library/debian
    2c49f83e0b13: Pull complete
    4a5e6db8c069: Pull complete

    Status: Downloaded newer image for debian:latest

    $ docker images
    REPOSITORY   TAG         IMAGE ID        CREATED      VIRTUAL SIZE
    debian       latest     4a5e6db8c069     5 days ago   125.1 MB

## Pull an image, manually specifying path to Docker's public registry and tag
Note that if the  image is previously downloaded then the status would be
`Status: Image is up to date for registry.hub.docker.com/fedora:20`

    $ docker pull registry.hub.docker.com/fedora:20
    Pulling repository fedora
    3f2fed40e4b0: Download complete
    511136ea3c5a: Download complete
    fd241224e9cf: Download complete

    Status: Downloaded newer image for registry.hub.docker.com/fedora:20

    $ docker images
    REPOSITORY   TAG         IMAGE ID        CREATED      VIRTUAL SIZE
    fedora       20          3f2fed40e4b0    4 days ago   372.7 MB

# HISTORY
April 2014, Originally compiled by William Henry (whenry at redhat dot com)
based on docker.com source material and internal work.
June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
August 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
April 2015, updated by John Willis <john.willis@docker.com>
April 2015, updated by Mary Anthony for v2 <mary@docker.com>
September 2015, updated by Sally O'Malley <somalley@redhat.com>


text:
package shaft.poker.agent.handranges;

import shaft.poker.agent.IHandRange;
import shaft.poker.game.Card;

/**
 *
 * @author Thomas Schaffer <thomas.schaffer@epitech.eu>
 */
public class UniformRange implements IHandRange {

    @Override
    public double handWeight(Card c1, Card c2) {
        return 1.0;
    }
}


text:
module Utils
  ALTOOL = "/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool"

  def altool(arg)
    if verbose?
      puts "----------------------------------------"
      puts " COMMAND :                              "
      puts "\"#{ALTOOL}\" #{arg}"
    end
    message = `\"#{ALTOOL}\" #{arg} 2>&1`
    if verbose?
      puts "----------------------------------------"
      puts " RETURN :                               "
      puts message
    end

    messages = parse_nslog_message(message)
    print_messages(messages, $?.exitstatus == 0)

    $?.exitstatus
  end

  CONFIG_KEY = %w(
    build_dir
    deployment_target
  )

  def config
    unless File.exist?('Rakefile')
      help! "Run on root directoy of RubyMotion project."
    end

    unless @config
      config = `rake config`.strip
      if config.empty?
        # for motion-game/flow
        config = `rake ios:config`.strip
      end

      @config = {}
      config.lines.each do |line|
        m = line.strip.match(/(\w+)\s+: (.+)$/)
        if CONFIG_KEY.include?($1)
          k = $1
          v = eval($2.strip)
          @config[k] = v
        end
      end
    end
    @config
  end

  def build_dir
    config['build_dir']
  end

  def deployment_target
    config['deployment_target']
  end

  def archive_path
    # select *.ipa or *.pkg in Release directory.
    target = deployment_target || "*"
    archive = Dir.glob("#{build_dir}/{iPhoneOS,MacOSX,AppleTVOS}-#{target}-Release/*.{ipa,pkg}").first
    unless archive
      help! "Can't find *.ipa or *.pkg. First, need to create archive file with `rake archive:distribution'."
    end
    archive
  end

  def password
    # retrieve password from keychain which might be created by Xcode
    if verbose?
      puts "----------------------------------------"
      puts " PASSWORD :                             "
    end
    `security find-internet-password -g -a \"#{@adc_id}\" -s idmsa.apple.com -r htps 2>&1`.each_line { |line|
      puts line if verbose?
      if line =~ /^password: "(.+)"$/
        return $1
      end
    }

    # retrieve password by user input
    begin
      require 'io/console'
    rescue LoadError
    end

    prompt = bold("Enter your password: ")
    if STDIN.respond_to?(:noecho)
      print prompt
      pass = STDIN.noecho(&:gets).strip
    else
      pass = `read -s -p "#{prompt}" password; echo $password`.strip
    end
    puts ""
    puts pass if verbose?
    pass
  end

  def parse_nslog_message(message)
    messages = []
    tmp = message.split("\n")
    tmp.shift if tmp[0].end_with?("Error: (")
    tmp.each do |msg|
      msg.strip!
      if m = msg.match(/(No errors.+)/)
        # success
        messages << m[1]
      elsif m = msg.match(/NSLocalizedDescription=(.+), NSLocalizedFailureReason=/)
        # error
        messages << m[1]
      elsif m = msg.match(/(Error:.+)/)
        # other errors
        messages << m[1]
      end
    end
    messages
  end

  def print_messages(messages, is_success)
    mark = is_success ? green("✓ ") : red("✗ ")
    messages.each do |msg|
      puts mark + msg
    end
  end

  def bold(msg)
    ansi_output? ? "\e[1;34m" + msg + "\e[0m" : msg
  end

  def red(msg)
    ansi_output? ? "\e[1;31m" + msg + "\e[0m" : msg
  end

  def green(msg)
    ansi_output? ? "\e[1;32m" + msg + "\e[0m" : msg
  end

end


text:
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\data\ArrayDataProvider;
use yii\helpers\ArrayHelper;
/**
 * @var yii\web\View $this
 */

$this->title = Yii::t('rbac-admin', 'Generate Routes');
$this->params['breadcrumbs'][] = ['label' => Yii::t('rbac-admin', 'Routes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<?= Yii::t('rbac-admin', 'Generate Routes') ?>

<?php
echo Html::beginForm();
echo GridView::widget([
    'dataProvider' => new ArrayDataProvider([
        'allModels' => $new,
            ]),
    'columns' => [
        [
            'class' => 'yii\\grid\\CheckboxColumn',
            'checkboxOptions' => function ($model) {
                return [
                    'value' => ArrayHelper::getValue($model, 'name'),
                    'checked' => true,
                ];
            },
        ],
        [
            'class' => 'yii\\grid\\DataColumn',
            'attribute' => 'name',
        ]
    ]
]);
echo Html::submitButton(Yii::t('rbac-admin', 'Append'), ['name' => 'Submit','class' => 'btn btn-primary']);
echo Html::endForm();
?>


text:
<!doctype html>
<meta charset="utf-8">
<title>CSS Pseudo-Elements Test: highlight cascade: inheritance with both universal and non-universal rules</title>
<link rel="author" title="Delan Azabani" href="mailto:dazabani@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-cascade">
<link rel="match" href="highlight-cascade-005-ref.html">
<meta name="assert" content="This test verifies that, given both universal and non-universal ::selection rules, the subject of the non-universal rule has styles from both rules with the non-universal styles overriding the universal styles (due to the cascade), its descendants have styles from both rules with the universal styles overriding the non-universal styles (due to highlight inheritance), and its siblings have the universal styles only.">

<link rel="stylesheet" href="support/highlights.css">

white
yellow white white
white yellow


text:
goog.module('grrUi.semantic.statEntryDirective');
goog.module.declareLegacyNamespace();

const apiService = goog.requireType('grrUi.core.apiService');
const {ServerErrorButtonDirective} = goog.require('grrUi.core.serverErrorButtonDirective');
const {pathSpecToAff4Path} = goog.require('grrUi.core.fileDownloadUtils');

/** @const */
var ERROR_EVENT_NAME = ServerErrorButtonDirective.error_event_name;

/**
 * Controller for StatEntryDirective.
 *
 * @param {!angular.Scope} $rootScope
 * @param {!angular.Scope} $scope
 * @param {!apiService.ApiService} grrApiService
 * @constructor
 * @ngInject
 */
const StatEntryController = function(
    $rootScope, $scope, grrApiService) {
  /** @private {!angular.Scope} */
  this.rootScope_ = $rootScope;

  /** @private {!angular.Scope} */
  this.scope_ = $scope;

  /** @private {!apiService.ApiService} */
  this.grrApiService_ = grrApiService;

  /** @type {string} */
  this.clientId;

  /** @type {Object} */
  this.aff4Path;

  /** @type {Object} */
  this.statEntry;

  /** @type {string} */
  this.downloadUrl;

  /** @type {Object} */
  this.downloadParams;

  this.scope_.$watch('::value', this.onValueChange_.bind(this));
};

/**
 * Handles changes of scope.value attribute.
 *
 * @param {Object} newValue StatEntry or __DownloadableStatEntry value.
 * @private
 */
StatEntryController.prototype.onValueChange_ = function(newValue) {
  if (angular.isUndefined(newValue)) {
    return;
  }

  if (newValue['type'] == '__DownloadableStatEntry') {
    this.statEntry = newValue['originalValue'];
    this.downloadUrl = newValue['downloadUrl'];
    this.downloadParams = newValue['downloadParams'];
  } else {
    this.statEntry = newValue;
  }

  if (this.clientId && angular.isDefined(this.statEntry['value']['pathspec'])) {
    this.aff4Path = {
      type: 'RDFURN',
      value: pathSpecToAff4Path(this.statEntry['value']['pathspec'], this.clientId)
    };
  } else {
    this.aff4Path = {
      type: 'RDFString',
      value: '<unknown>'
    };
  }
};

/**
 * Handler for the download click events.
 */
StatEntryController.prototype.onDownloadClick = function() {
  this.grrApiService_.downloadFile(this.downloadUrl, this.downloadParams).then(
      function success() {}.bind(this),
      function failure(response) {
        if (response.status !== 500) {
          this.rootScope_.$broadcast(
              ERROR_EVENT_NAME, {
                message: 'Couldn\'t download the file. Most likely ' +
                    'it was just referenced and not downloaded from the ' +
                    'client.'
              });
        }
      }.bind(this));
};

/**
 * Directive that displays AFF4 object label.
 *
 * @return {angular.Directive} Directive definition object.
 * @export
 */
exports.StatEntryDirective = function() {
  return {
    scope: {
      value: '='
    },
    require: '?^grrClientContext',
    restrict: 'E',
    templateUrl: '/static/angular-components/semantic/stat-entry.html',
    controller: StatEntryController,
    controllerAs: 'controller',
    link: function(scope, element, attrs, grrClientContextCtrl) {
      if (grrClientContextCtrl) {
        scope['controller'].clientId = grrClientContextCtrl.clientId;
      }
    }
  };
};

/**
 * Name of the directive in Angular.
 */
exports.StatEntryDirective.directive_name = 'grrStatEntry';

/**
 * Semantic type corresponding to this directive.
 *
 * @const
 * @export
 */
exports.StatEntryDirective.semantic_types =
    ['StatEntry', '__DownloadableStatEntry'];


text:
import sys
from collections import defaultdict

import hasher
import json5_generator
import template_expander

from blinkbuild.name_style_converter import NameStyleConverter

def _symbol(tag):
    return 'k' + tag['name'].to_upper_camel_case()

class MakeElementTypeHelpersWriter(json5_generator.Writer):
    default_parameters = {
        'Conditional': {},
        'ImplementedAs': {},
        'JSInterfaceName': {},
        'constructorNeedsCreateElementFlags': {},
        'interfaceHeaderDir': {},
        'interfaceName': {},
        'noConstructor': {},
        'noTypeHelpers': {},
        'runtimeEnabled': {},
    }
    default_metadata = {
        'attrsNullNamespace': None,
        'export': '',
        'fallbackInterfaceName': '',
        'fallbackJSInterfaceName': '',
        'namespace': '',
        'namespacePrefix': '',
        'namespaceURI': '',
    }
    filters = {
        'hash': hasher.hash,
        'symbol': _symbol,
    }

    def __init__(self, json5_file_path, output_dir):
        super(MakeElementTypeHelpersWriter, self).__init__(
            json5_file_path, output_dir)

        self.namespace = self.json5_file.metadata['namespace'].strip('"')
        self.fallback_interface = self.json5_file.metadata[
            'fallbackInterfaceName'].strip('"')

        assert self.namespace, 'A namespace is required.'

        basename = self.namespace.lower() + '_element_type_helpers'
        self._outputs = {
            (basename + '.h'): self.generate_helper_header,
            (basename + '.cc'): self.generate_helper_implementation,
        }

        base_element_header = 'third_party/blink/renderer/core/{}/{}_element.h'.format(
            self.namespace.lower(),
            NameStyleConverter(self.namespace).to_snake_case())
        self._template_context = {
            'base_element_header': base_element_header,
            'cpp_namespace': self.namespace.lower() + '_names',
            'input_files': self._input_files,
            'namespace': self.namespace,
            'tags': self.json5_file.name_dictionaries,
            'elements': set(),
        }

        tags = self._template_context['tags']
        elements = self._template_context['elements']
        interface_counts = defaultdict(int)
        for tag in tags:
            tag['interface'] = self._interface(tag)
            interface_counts[tag['interface']] += 1
            tag['js_interface'] = tag['interface']
            if tag['JSInterfaceName']:
                tag['js_interface'] = tag['JSInterfaceName']
            elements.add(tag['js_interface'])

        for tag in tags:
            tag['multipleTagNames'] = (
                interface_counts[tag['interface']] > 1
                or tag['interface'] == self.fallback_interface)

    @template_expander.use_jinja(
        "templates/element_type_helpers.h.tmpl", filters=filters)
    def generate_helper_header(self):
        return self._template_context

    @template_expander.use_jinja(
        "templates/element_type_helpers.cc.tmpl", filters=filters)
    def generate_helper_implementation(self):
        return self._template_context

    def _interface(self, tag):
        if tag['interfaceName']:
            return tag['interfaceName']
        name = tag['name'].to_upper_camel_case()
        # FIXME: We shouldn't hard-code HTML here.
        if name == 'HTML':
            name = 'Html'
        return '%s%sElement' % (self.namespace, name)

if __name__ == "__main__":
    json5_generator.Maker(MakeElementTypeHelpersWriter).main()


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Leucocoprinus flavipes Earle

### Remarks
null


text:
var events = require('events');
var util = require('util');

var Worker = function(){
    events.EventEmitter.call(this);

    var self = this;
    process.on('message', function(msg){
        self.dispatcher(msg);
    });
};
util.inherits(Worker, events.EventEmitter);

Worker.prototype.dispatcher = function(msg){
    msg.param._seq = msg._seq;
    this.emit(msg.type, msg.param);
}
Worker.prototype.send = function(type, param){
    process.send({
        _seq : param._seq,
        type : type,
        param : param
    });
}

var worker = module.exports = new Worker();


text:
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace Assets.Scripts.Binding
{
    public class NotifyingObjectProperty
    {
        private const string GetValueMethodName = "GetValue";
        private const string SetValueMethodName = "SetValue";
        private const string DefaultCategory = "Misc";

        private readonly Type _type;
        private readonly MethodInfo _getter;
        private readonly MethodInfo _setter;
        private readonly object _notifyingObject;
        private readonly string _displayName;
        private readonly string _description;
        private readonly string _category;
        private readonly string _propertyName;
        private readonly PropertyKind _propertyKind;

        public NotifyingObjectProperty(PropertyInfo property, object obj)
        {
            _type = property.PropertyType.GetGenericArguments()[0];
            _notifyingObject = property.GetValue(obj, null);
            _getter = _notifyingObject.GetType().GetMethod(GetValueMethodName);
            _setter = _notifyingObject.GetType().GetMethod(SetValueMethodName);

            var displayNameAttribute = property.GetCustomAttributes(typeof(DisplayNameAttribute), false)
                .Cast<DisplayNameAttribute>()
                .SingleOrDefault();

            _displayName = displayNameAttribute != null
                ? displayNameAttribute.DisplayName
                : property.Name;

            var descriptionAttribute = property.GetCustomAttributes(typeof(DescriptionAttribute), false)
                .Cast<DescriptionAttribute>()
                .SingleOrDefault();

            _description = descriptionAttribute != null
                ? descriptionAttribute.Description
                : string.Empty;

            var categoryAttribute = property.GetCustomAttributes(typeof(CategoryAttribute), false)
                .Cast<CategoryAttribute>()
                .SingleOrDefault();

            _category = categoryAttribute != null
                ? categoryAttribute.Category
                : DefaultCategory;

            _propertyName = property.Name;

            var propertyKindAttribut = property.GetCustomAttributes(typeof(PropertyKindAttribute), false)
                .Cast<PropertyKindAttribute>()
                .SingleOrDefault();

            _propertyKind = propertyKindAttribut != null
                ? propertyKindAttribut.PropertyKind
                : PropertyKind.Undefined;
        }

        public Type Type
        {
            get { return _type; }
        }

        public string DisplayName
        {
            get { return _displayName; }
        }

        public string Description
        {
            get { return _description; }
        }

        public string Category
        {
            get { return _category; }
        }

        public string PropertyName
        {
            get { return _propertyName; }
        }

        public PropertyKind PropertyKind
        {
            get { return _propertyKind; }
        }

        public void SetValue<T>(T value)
        {
            _setter.Invoke(_notifyingObject, new object[] {value});
        }

        public T GetValue<T>()
        {
            return (T) _getter.Invoke(_notifyingObject, null);
        }
    }
}


text:
/**
 * Created by pablo on 6/14/17.
 */

'use strict';

let CECMonitor = require('../index').CECMonitor;
let CEC = require('../index').CEC;

let monitor = new CECMonitor('CECMONITOR', {
  debug: true,
  player: true,
  hdmiport: 2,
  no_serial: {
    reconnect: true,
    wait_time: 10
  }
});

var status = CEC.PowerStatus.UNKNOWN;

monitor.on(CECMonitor.EVENTS._DATA, console.log);

monitor.once(CECMonitor.EVENTS._READY, function() {
  console.log( ' -- READY -- ' );
  monitor.WriteMessage(CEC.LogicalAddress.RECORDINGDEVICE1, CEC.LogicalAddress.BROADCAST, CEC.Opcode.ACTIVE_SOURCE, [monitor.state_manager.primary.physical >> 8, monitor.state_manager.primary.physical & 0xFF]);
});

monitor.once(CECMonitor.EVENTS._NOTICE, function() {
  console.log( ' -- NOTICE -- ' );
});

monitor.once(CECMonitor.EVENTS._WARNING, function() {
  console.log( ' -- WARNING -- ' );
});

monitor.once(CECMonitor.EVENTS._DEBUG, function() {
  console.log( ' -- DEBUG -- ' );
});

monitor.once(CECMonitor.EVENTS._TRAFFIC, function() {
  console.log( ' -- TRAFFIC -- ' );
});

monitor.on(CECMonitor.EVENTS._NOSERIALPORT, function() {
  console.log( ' -- NO SERIAL PORT -- ' );
});

monitor.on(CECMonitor.EVENTS._STOP, function() {
  console.log( ' -- STOP -- ' );
});

monitor.on(CECMonitor.EVENTS._ERROR, console.error);

monitor.on(CECMonitor.EVENTS.REPORT_POWER_STATUS, function (packet, _status) {
  var keys = Object.keys(CEC.PowerStatus);

  for (let i = keys.length - 1; i >= 0; i--) {
    if (CEC.PowerStatus[keys[i]] === _status) {
      status = _status;
      console.log('POWER_STATUS:', keys[i], status);
      break;
    }
  }
});

monitor.on(CECMonitor.EVENTS.ROUTING_CHANGE, function(packet, from, to) {
  console.log('--ROUTING CHANGE--');
  console.log(packet, from, to);
});

monitor.on(CECMonitor.EVENTS.ACTIVE_SOURCE, function(packet, from, to) {
  console.log('--ACTIVE SOURCE--');
  console.log(packet, from, to);
});

monitor.on(CECMonitor.EVENTS.STANDBY, function (packet) {
  if (packet.source === CEC.LogicalAddress.TV) {
    status = CEC.PowerStatus.STANDBY;
  }
})

setInterval(function () {
  if (status !== CEC.PowerStatus.ON) {
    monitor.WriteMessage(CEC.LogicalAddress.RECORDINGDEVICE1, CEC.LogicalAddress.TV, CEC.Opcode.IMAGE_VIEW_ON);
  } else {
    monitor.WriteMessage(CEC.LogicalAddress.RECORDINGDEVICE1, CEC.LogicalAddress.TV, CEC.Opcode.STANDBY);
  }
  setTimeout(() => monitor.WriteMessage(CEC.LogicalAddress.RECORDINGDEVICE1, CEC.LogicalAddress.TV, CEC.Opcode.GIVE_DEVICE_POWER_STATUS), 5000);
}, 60000)


text:
title: Telerik.Web.UI.DropDownListEventArgs
page_title: Telerik.Web.UI.DropDownListEventArgs
description: Telerik.Web.UI.DropDownListEventArgs
---

# Telerik.Web.UI.DropDownListEventArgs

Provides data for the E:Telerik.Web.UI.RadDropDownList.SelectedIndexChanged event of the
            Telerik.Web.UI.RadDropDownList control.

## Inheritance Hierarchy

* System.Object
* System.EventArgs
* Telerik.Web.UI.DropDownListEventArgs

## Properties

###  Index `Int32`

Gets or sets the index of the referenced item in the  control when the event is raised.

###  Text `String`

Gets or sets the text of the referenced item in the  control when the event is raised.

###  Value `String`

Gets or sets the value of the referenced item in the  control when the event is raised.


text:
..
  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.

Plugin Writer's Guide
=====================

Senlin provides an open design where developer can incorporate new profile
or policy implementations for different purposes.

[TBC]


text:
module QaePdfForms::Awards2016::Innovation
  class Base < FormPdf
    # HERE YOU CAN OVERRIDE STANDART METHODS
  end
end


text:
package com.google.devtools.mobileharness.infra.controller.plugin.provider;

import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import com.google.wireless.qa.mobileharness.shared.controller.plugin.Plugin;
import com.google.wireless.qa.mobileharness.shared.controller.plugin.Plugin.PluginType;
import com.google.wireless.qa.mobileharness.shared.log.LogCollector;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.reflections.Reflections;

/** Provides plugin classes that have been annotated with the given {@link PluginType}s. */
public class AnnotatedPluginClassProvider implements PluginClassProvider {

  private static final FluentLogger logger = FluentLogger.forEnclosingClass();

  private final Reflections reflections;
  @Nullable private final LogCollector<?> log;
  private final boolean warnUnmatchedTypes;
  private final ImmutableSet<PluginType> pluginTypes;

  /**
   * @param reflections The reflection object ot use when finding the classes.
   * @param pluginTypes The types of plugin to allow.
   */
  public AnnotatedPluginClassProvider(
      Reflections reflections,
      @Nullable LogCollector<?> log,
      boolean warnUnmatchedTypes,
      PluginType... pluginTypes) {
    this.reflections = reflections;
    this.log = log;
    this.warnUnmatchedTypes = warnUnmatchedTypes;
    this.pluginTypes = ImmutableSet.copyOf(pluginTypes);
  }

  @Override
  public Set<Class<?>> getPluginClasses() {
    return reflections.getTypesAnnotatedWith(Plugin.class).stream()
        .filter(
            aClass ->
                checkPluginType(
                    aClass,
                    clazz -> clazz.getDeclaredAnnotation(Plugin.class).type(),
                    log,
                    warnUnmatchedTypes,
                    pluginTypes))
        .collect(Collectors.toSet());
  }

  static boolean checkPluginType(
      Class<?> aClass,
      Function<Class<?>, PluginType> pluginTypeGetter,
      @Nullable LogCollector<?> log,
      boolean warnUnmatchedTypes,
      ImmutableSet<PluginType> pluginTypes) {
    PluginType pluginType = pluginTypeGetter.apply(aClass);
    if (pluginTypes.contains(pluginType)) {
      return true;
    } else {
      if (log != null && warnUnmatchedTypes) {
        log.atWarning()
            .alsoTo(logger)
            .log(
                "Plugin class [%s] is found when loading plugins whose type is in %s"
                    + " but its type is %s. Do you %s",
                aClass.getName(),
                pluginTypes,
                pluginType,
                PluginType.UNSPECIFIED.equals(pluginType)
                    ? "forget to add PluginType to the @Plugin annotation like"
                        + " @Plugin(type = CLIENT) or @Plugin(type = LAB)?"
                    : "specify a wrong plugin jar? If the class is depended by other"
                        + " plugins, you can ignore this warning.");
      }
      return false;
    }
  }
}


text:
from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        ('pages', '0021_auto_20180607_1434'),
    ]

    operations = [
        migrations.AlterField(
            model_name='faqspage',
            name='page_ptr',
            field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page'),
        ),
        migrations.AlterField(
            model_name='homepage',
            name='page_ptr',
            field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page'),
        ),
        migrations.AlterField(
            model_name='standardindexpage',
            name='page_ptr',
            field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page'),
        ),
        migrations.AlterField(
            model_name='standardpage',
            name='page_ptr',
            field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page'),
        ),
        migrations.AlterField(
            model_name='videogallerypagecarouselitem',
            name='link_document',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtaildocs.Document'),
        ),
        migrations.AlterField(
            model_name='videogallerypagecarouselitem',
            name='link_page',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.Page'),
        ),
    ]


text:
import org.junit.*;
import java.util.*;
import models.*;
import helpers.*;
import notifiers.*;
import javax.*;

import play.*;
import play.db.jpa.*;
import play.mvc.*;
import play.test.*;
import play.libs.*;

public class EmailTests extends UnitTest {
    //TODO: Expand these to test multiple email sending (ex. handleRFIupdated logic)
    @Test
    public void testAllEmailSending() {
        RFI r = RFI.findById(1L);
        Comment c = r.comments.get(0);
        Event e = r.event;
        RelatedRFIItem rel = r.relatedItems.get(0);

        Mails.commentCreated(c, "test@test.com");
        Mails.eventCreated(e, "test@test.com");
        Mails.eventGroupUpdated(e, "test@test.com");
        Mails.rfiCreated(r, "test@test.com");
        Mails.groupChanged(r, "test@test.com");
        Mails.rfiAssigned(r, "test@test.com");
        Mails.sendStatusChange(r, "test@test.com");
        Mails.sendProductAdded(rel, "test@test.com");

        // For testing classification strings
        RFI r2 = RFI.findById(2L);
        Mails.rfiCreated(r2, "test@test.com");

        RFI activityRFI = RFI.findById(17L);
        Mails.rfiCreated(activityRFI, "test@test.com");
        Event activityEvent = activityRFI.event;
        Mails.eventCreated(activityEvent, "test@test.com");
    }

    @Test
    public void testEmailClassificationFormatting() {
        RFI r = RFI.findById(2L);
        String [] cls = RFIHelpers.gatherClassificationEmailStrings(r);
        assertTrue(cls.length == 2);
        Logger.debug(cls[0]);
        Logger.debug(cls[1]);

        RFI r2 = RFI.findById(1L);
        String [] cls2 = RFIHelpers.gatherClassificationEmailStrings(r2);
        assertTrue(cls.length == 2);
        assertEquals(cls2[0], "CLASSIFICATION COULD BE UP TO Unclassified//FOUO");
    }
}


text:
function shuf_indices = random_tuples(in_noshufs, filenum, tuple_size)

if isempty(in_noshufs)

    shuf_indices = nan(in_noshufs, tuple_size);

    for n = 1:tuple_size

        shuf_indices(:, n) = randperm(filenum);

    end

elseif factorial(tuple_size)*nchoosek(filenum, tuple_size) < in_noshufs

    noshufs = factorial(tuple_size)*nchoosek(filenum, tuple_size);

    display(['There are not enough data files to create ', num2str(in_noshufs),...
        ' independent shuffles; there are only ', num2str(filenum),' data files, so ',...
        num2str(noshufs), ' shuffles will be created instead.'])

    shuf_indices = make_all_tuples(filenum, tuple_size);

else

    noshufs = in_noshufs;

    tuples = make_all_tuples(filenum, tuple_size);

    choices = randperm(size(tuples, 1));

    choices = choices(1:noshufs);

    shuf_indices = tuples(choices, :);

end

end


text:
Session.set('initialLoad', true);
Session.set('today', new Date());
Session.set('view', 'top');
Session.set('postsLimit', getSetting('postsPerPage', 10));
Session.set('sessionId', Meteor.default_connection._lastSessionId);

STATUS_PENDING=1;
STATUS_APPROVED=2;
STATUS_REJECTED=3;

viewNav = typeof viewNav === 'undefined' ? [] : viewNav;
viewNav = viewNav.concat([
  {
    route: 'posts_top',
    label: 'Top'
  },
  {
    route: 'posts_new',
    label: 'New'
  },
  {
    route: 'posts_best',
    label: 'Best'
  },
  {
    route: 'posts_digest',
    label: 'Digest'
  }
]);

adminNav = typeof adminNav === 'undefined' ? [] : adminNav;
adminNav = adminNav.concat([
  {
    route: 'posts_pending',
    label: 'Pending'
  },
  {
    route: 'all-users',
    label: 'Users'
  },
  {
    route: 'settings',
    label: 'Settings'
  },
  {
    route: 'logs',
    label: 'Search Logs'
  },
  {
    route: 'toolbox',
    label: 'Toolbox'
  }
]);

// Notifications - only load if user is logged in
// Not mandatory, because server won't publish anything even if we try to load.
// Remember about Deps.autorun - user can log in and log out several times
Deps.autorun(function() {
  // userId() can be changed before user(), because loading profile takes time
  if(Meteor.userId()) {
    Meteor.subscribe('notifications');
    if(isAdmin(Meteor.user())){
      // Subscribe to all users for now to make user selection autocomplete work
      Meteor.subscribe('allUsersAdmin');
    }
  }
});


text:
package io.github.configur8

import org.scalatest.{FunSpec, Matchers}

class ExposeModeTest extends FunSpec with Matchers {

  describe("Expose mode") {
    it("Public") {
      ExposeMode.Public.display("input") shouldBe "input"
    }

    it("Private conceals the value with '*' characters") {
      ExposeMode.Private.display("input") shouldBe "*********"
    }
  }
}


text:
/*
 * 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.
 */
define([
    "app",
    "../../../spawn2/js/modules/datatable",
    "../../../spawn2/js/modules/util",
    "text!../../templates/jobs.filter.html",
    "text!../../templates/jobs.selectable.html",
    "backbone"
],
function(
    app,
    DataTable,
    util,
    jobsFilterTemplate,
    jobsSelectableTemplate
){
    var States = [
        "IDLE",
        "SCHEDULED",
        "RUNNING",
        "DEGRADED",
        "UNKNOWN",
        "ERROR",
        "REBALANCE"
    ];
    var Labels = [
        "label-default",
        "label-info",
        "label-success",
        "label-inverse",
        "label-inverse",
        "label-danger",
        "label-info"
    ];
    var Model = Backbone.Model.extend({
        defaults:{
            "description": "(no title)",
            "state": "",
            "creator": "",
            "owner": "",
            "submitTime": "",
            "startTime": "",
            "endTime": "",
            "replicas": "",
            "backups": "",
            "nodes": ""
        },
        parse:function(data){
            data.DT_RowId=data.id;
            data.DT_RowClass='job-row';
            return data;
        }
    });
    var Collection = Backbone.Collection.extend({
        url:"/v2/job/list",
        model:Model,
        parse:function(collection){
            var array = new Array(collection.length);
            _.each(collection,function(model,idx){
                array[idx]= Model.prototype.parse(model);
            });
            return array;
        }
    });
    var View = Backbone.View.extend({
        initialize:function(options){
        },
        render:function(){
            this.$el.html("queryable jobs view..");
            return this;
        }
    });
    var TableView = DataTable.View.extend({
        initialize:function(options){
            options = options || {};
            this.id = options.id || "jobsTable";
            this.$el.attr("id",this.id);
            var columns = [
                {
                    "sTitle":"ID",
                    "sClass":"jobs-id",
                    "mData": "id",
                    "sWidth":"10%",
                    "bVisible":true,
                    "bSearchable":true
                },
                {
                    "sTitle":"State",
                    "sClass":"job-state center",
                    "mData": "state",
                    "sWidth":"8%",
                    "bSearchable":false,
                    "mRender":function(val){
                        return "
"+States[val]+"
";
                    },
                    "aDataSort":[2],
                    "aTargets":[3]
                },
                {
                    "sTitle":"Description",
                    "sClass":"jobs-desc",
                    "mData": "description",
                    //"sWidth":"100%",
                    "bVisible":true,
                    "bSearchable":true,
                    "mRender":function(value,type,data){
                        return ""+value+"";
                    }
                },
                {
                    "sTitle":"Creator",
                    "sClass":"job-creator center",
                    "mData": "creator",
                    "sWidth":"7%",
                    "bSearchable":true
                },
                {
                    "sTitle":"Submitted",
                    "sClass":"job-submitTime center",
                    "mData": "submitTime",
                    "sWidth":"8%",
                    "bSearchable":false,
                    "mRender":function(val){
                        return util.convertToDateTimeText(val);
                    }
                },
                {
                    "sTitle":"Started",
                    "sClass":"job-startTime center",
                    "mData": "submitTime",
                    "sWidth":"8%",
                    "bSearchable":false,
                    "mRender":function(val){
                        return util.convertToDateTimeText(val);
                    }
                },
                {
                    "sTitle":"Ended",
                    "sClass":"job-endTime center",
                    "mData": "endTime",
                    "sWidth":"8%",
                    "bSearchable":false,
                    "mRender":function(val){
                        return util.convertToDateTimeText(val);
                    }
                },
                {
                    "sTitle":"Nodes",
                    "sClass":"job-nodes center",
                    "mData": "nodes",
                    "sWidth":"7%",
                    "bSearchable":false
                }
            ];
            DataTable.View.prototype.initialize.apply(this,[{
                columns:columns,
                filterTemplate:jobsFilterTemplate,
                selectableTemplate:jobsSelectableTemplate,
                heightBuffer:80,
                id:this.id,
                emptyMessage:"No queryable jobs detected yet.."
            }]);
        }
    });
    return {
        TableView:TableView,
        Model:Model,
        Collection:Collection
    };
});


text:
Got tired of configuring stuff via the kibana GUI ...  so we are going to hackaboo data into the .kibana configuration index.  Why would we do this?
  - You need to instantiate many instances of the same searches, visualizations, dashboards but for slightly different index names.  Wildcard index is not optimal for you.
  - You hate building dashboards in the GUI.

Currently generates
  - Index Patterns
  - Searches
  - Visualizations (only Metrics, Tables, and Histograms for now)
  - Dashboards

## Tested against
  - elasticsearch:2.4.5 / kibana:4.6.4
  - elasticsearch 5.1.1 / kibana:5.1.1
  - elasticsearch 5.5.0 / kibana:5.5.0

## Todos
https://github.com/hwshadow/kibana-asset-generator/projects/1
  - Implement simplistic Visualization package
  - Buff up Dashboard, Visualization, Search package as needed
  - API to load objects into target elasticsearch server
  - Abstract templates into a database?

## Testing
Made super easy with docker.

### Get docker
https://docs.docker.com/engine/installation/

### (Optionally) tweak the template information
```sh
$ ls ./testdata/dnd/kag_template
```

### Run the bootstrap script
if this is your first time running the bootstrap script
```sh
cd ./dev/; docker-compose run build-alpine-kag sh -c 'gb vendor restore'; cd -;
```
then
```sh
$ ./dev/bootstrap.sh
```

### Browse to kibana
http://localhost:5601/ to enjoy

## Build
My preference is to use inside a docker container, but if so desired you can build locally.

### From container
#### Get docker
https://docs.docker.com/engine/installation/

#### Build inside a container
```sh
$ cd ./dev/
$ docker-compose run build-alpine-kag sh -c 'gb vendor restore && gb build'
$ ls ../bin/kag
```
By default we build against alpine.
Build behavior can be changed to target debian by using 'build-debian-kag'
Or any other distribution following the pattern in docker-compose.yml

### Locally
#### Get the gb build tool
https://getgb.io/docs/install/
```sh
$ go get github.com/constabulary/gb/...
```

#### Build local
```sh
$ gb vendor restore && gb build
$ ls ./bin/kag
```

## Usage
### Run dry with no connection to elastic
```sh
$ kag -conf="/etc/app.yaml" -template="/etc/" -ops="ids"
```
### Run dry with connection to elastic
```sh
$ kag -conf="/etc/app.yaml" -template="/etc/" -ops="ids" -index="testdata.dnd"
```
### Run dry with connection to elastic only generate searches
```sh
$ kag -conf="/etc/app.yaml" -template="/etc/" -ops="s" -index="testdata.dnd"
```
#### Run with connection to elastic and writes enabled
```sh
$ kag -conf="/etc/app.yaml" -template="./kag_template/" -ops="idvs" -index="testdata.dnd" -dashTitle="dash" -prefix="testdata-dnd-" -timeField="dob" -write=true
```

## About
See package specific readmes: idxp, search, dashboard


text:
package com.ibm.mobilefirstplatform.clientsdk.android.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import android.app.AlertDialog.Builder;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushException;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationButton;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationCategory;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationListener;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationOptions;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationStatus;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushNotificationStatusListener;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushResponseListener;
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPSimplePushNotification;
import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends Activity {

    private TextView txtVResult = null;

    private MFPPush push = null;
    private MFPPushNotificationListener notificationListener = null;

    private List<String> allTags;
    private List<String> subscribedTags;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtVResult = (TextView) findViewById(R.id.display);

        updateTextView("Starting Push Android Sample..");

        String appGuid = "Appp GUID";
        String clientSecret = "App client secret";

        BMSClient.getInstance().initialize(getApplicationContext(), BMSClient.REGION_UK);

        // Actionable Notifications
        MFPPushNotificationOptions options = new MFPPushNotificationOptions();

        MFPPushNotificationButton firstButton = new MFPPushNotificationButton.Builder("Accept Button")
        .setIcon("check_circle_icon")
        .setLabel("Accept")
        .build();

        MFPPushNotificationButton secondButton = new MFPPushNotificationButton.Builder("Decline Button")
        .setIcon("extension_circle_icon")
        .setLabel("Decline")
        .build();

        MFPPushNotificationButton secondButton1 = new MFPPushNotificationButton.Builder("Decline Button2")
                .setIcon("extension_circle_icon")
                .setLabel("Decline2")
                .build();

         List<MFPPushNotificationButton> getButtons =  new ArrayList<MFPPushNotificationButton>();
        getButtons.add(firstButton);
        getButtons.add(secondButton);
        getButtons.add(secondButton1);

        List<MFPPushNotificationButton> getButtons1 =  new ArrayList<MFPPushNotificationButton>();
        getButtons1.add(firstButton);
        getButtons1.add(secondButton);

        List<MFPPushNotificationButton> getButtons2 =  new ArrayList<MFPPushNotificationButton>();
        getButtons2.add(firstButton);

        MFPPushNotificationCategory category = new MFPPushNotificationCategory.Builder("First_Button_Group1").setButtons(getButtons).build();
        MFPPushNotificationCategory category1 = new MFPPushNotificationCategory.Builder("First_Button_Group2").setButtons(getButtons1).build();
        MFPPushNotificationCategory category2 = new MFPPushNotificationCategory.Builder("First_Button_Group3").setButtons(getButtons2).build();

        List<MFPPushNotificationCategory> categoryList =  new ArrayList<MFPPushNotificationCategory>();
        categoryList.add(category);
        categoryList.add(category1);
        categoryList.add(category2);

        options.setInteractiveNotificationCategories(categoryList);
        options.setDeviceid("your_device_id");
        JSONObject tempValue = new JSONObject();
        try {
            tempValue.put("username","testname");
            tempValue.put("accountNumber","3564758697057869");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        options.setPushVariables(tempValue);

        push = MFPPush.getInstance();
        push.initialize(getApplicationContext(),appGuid,clientSecret,options);

        //Uncomment this code to use Push notification without userId support.

        push.registerDevice(new MFPPushResponseListener<String>() {
            @Override
            public void onSuccess(String deviceId) {
                updateTextView("Device is registered with Push Service.");
                displayTags();
            }

            @Override
            public void onFailure(MFPPushException ex) {
                updateTextView("Error registering with Push Service...\n" + ex.toString()
                        + "Push notifications will not be received.");
            }
        });

        push.setNotificationStatusListener(new MFPPushNotificationStatusListener() {
            @Override
            public void onStatusChange(String messageId, MFPPushNotificationStatus status) {
                //handle status change here.
            }
        });

        //Uncomment this code to use Push notification with userId support.

      /*  push.registerDeviceWithUserId("", new MFPPushResponseListener<String>() {
            @Override
            public void onSuccess(String deviceId) {
                updateTextView("Device is registered with Push Service.");
                displayTags();
            }

            @Override
            public void onFailure(MFPPushException ex) {
                updateTextView("Error registering with Push Service...\n"
                        + "Push notifications will not be received.");
            }
        });*/

        final Activity activity = this;

        notificationListener = new MFPPushNotificationListener() {

            @Override
            public void onReceive(final MFPSimplePushNotification message) {

              /*
                if (message.actionName.equals("Accept Button")){

                   System.out.print("Clicked Accept Action");

               }else if (message.actionName.equals("Decline Button")){
                   System.out.print("Clicked Decline Action");
               }
                */

                showNotification(activity, message);

            }
        };
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (push != null) {
            push.listen(notificationListener);
        }
    }

    void showNotification(Activity activity, MFPSimplePushNotification message) {
        Builder builder = new AlertDialog.Builder(activity);
        builder.setMessage("Notification Received : " + message.toString());
        builder.setCancelable(true);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {

            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();

    }

    void displayTags() {
        push.getTags(new MFPPushResponseListener<List<String>>() {
            @Override
            public void onSuccess(List<String> tags) {
                updateTextView("Retrieved Tags : " + tags);
                allTags = tags;
                displayTagSubscriptions();
            }

            @Override
            public void onFailure(MFPPushException ex) {
                updateTextView("Error getting tags..." + ex.getMessage());
            }
        });
    }

    void unregisterDevice(){
        push.unregister(new MFPPushResponseListener<String>() {
            @Override
            public void onSuccess(String s) {
                updateTextView("Device is successfully unregistered. Success response is: " + s);
            }

            @Override
            public void onFailure(MFPPushException e) {
                updateTextView("Device unregistration failure. Failure response is: "+ e);
            }
        });
    }

    void unsubscribeFromTags(final String tag) {
        push.unsubscribe(tag, new MFPPushResponseListener<String>() {

            @Override
            public void onSuccess(String s) {
                updateTextView("Unsubscribing from tag");
                updateTextView("Successfully unsubscribed from tag . " + tag);
            }

            @Override
            public void onFailure(MFPPushException e) {
                updateTextView("Error while unsubscribing from tags. " + e.getMessage());
            }

        });
    }

    void displayTagSubscriptions() {
        push.getSubscriptions(new MFPPushResponseListener<List<String>>() {
            @Override
            public void onSuccess(List<String> tags) {
                updateTextView("Retrieved subscriptions : " + tags);
                System.out.println("Subscribed tags are: " + tags);
                subscribedTags = tags;
                subscribeToTag();
            }

            @Override
            public void onFailure(MFPPushException ex) {
                updateTextView("Error getting subscriptions.. "
                        + ex.getMessage());
            }
        });
    }

    void subscribeToTag() {
        System.out.println("subscribedTags: "+ subscribedTags+ "size is: "+subscribedTags.size());
        System.out.println("allTags: " + allTags + "Size is: " + allTags.size());

        if ((allTags.size() != 0)) {
            push.subscribe(allTags.get(0),
                    new MFPPushResponseListener<String>() {
                        @Override
                        public void onFailure(MFPPushException ex) {
                            updateTextView("Error subscribing to Tag1.."
                                    + ex.getMessage());
                        }

                        @Override
                        public void onSuccess(String arg0) {
                            updateTextView("Succesfully Subscribed to: "+ arg0);
                            unsubscribeFromTags(arg0);
                        }
                    });
        } else {
            updateTextView("Not subscribing to any more tags.");
        }

    }

    public void updateTextView(final String str) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                txtVResult.append(str);
                txtVResult.append("\n");
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (push != null) {
            push.hold();
        }

    }
}


text:
.class public Landroid/provider/BrowserContract;
.super Ljava/lang/Object;
.source "BrowserContract.java"

# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Landroid/provider/BrowserContract$BaseSyncColumns;,
        Landroid/provider/BrowserContract$ChromeSyncColumns;,
        Landroid/provider/BrowserContract$SyncColumns;,
        Landroid/provider/BrowserContract$CommonColumns;,
        Landroid/provider/BrowserContract$ImageColumns;,
        Landroid/provider/BrowserContract$HistoryColumns;,
        Landroid/provider/BrowserContract$ImageMappingColumns;,
        Landroid/provider/BrowserContract$Bookmarks;,
        Landroid/provider/BrowserContract$Accounts;,
        Landroid/provider/BrowserContract$History;,
        Landroid/provider/BrowserContract$Searches;,
        Landroid/provider/BrowserContract$SyncState;,
        Landroid/provider/BrowserContract$Images;,
        Landroid/provider/BrowserContract$ImageMappings;,
        Landroid/provider/BrowserContract$Combined;,
        Landroid/provider/BrowserContract$Settings;
    }
.end annotation

# static fields
.field public static final AUTHORITY:Ljava/lang/String; = "com.android.browser"

.field public static final AUTHORITY_URI:Landroid/net/Uri;

.field public static final CALLER_IS_SYNCADAPTER:Ljava/lang/String; = "caller_is_syncadapter"

.field public static final PARAM_LIMIT:Ljava/lang/String; = "limit"

# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 49
    const-string/jumbo v0, "content://com.android.browser"

    invoke-static {v0}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v0

    sput-object v0, Landroid/provider/BrowserContract;->AUTHORITY_URI:Landroid/net/Uri;

    .line 44
    return-void
.end method

.method public constructor <init>()V
    .registers 1

    .prologue
    .line 44
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


text:
@interface OneTest : NSObject <MQTTSessionDelegate>
@property (strong, nonatomic) MQTTSession *session;
@property (nonatomic) NSInteger event;
@property (strong, nonatomic) NSError *error;
@property (strong, nonatomic) NSDictionary *parameters;
@end

@implementation OneTest

- (id)setup:(NSDictionary *)parameters
{
    self.parameters = parameters;

    self.session = [[MQTTSession alloc] initWithClientId:nil
                                                userName:parameters[@"user"]
                                                password:parameters[@"pass"]
                                               keepAlive:60
                                            cleanSession:YES
                                                    will:NO
                                               willTopic:nil
                                                 willMsg:nil
                                                 willQoS:0
                                          willRetainFlag:NO
                                           protocolLevel:[parameters[@"protocollevel"] intValue]
                                                 runLoop:[NSRunLoop currentRunLoop]
                                                 forMode:NSRunLoopCommonModes
                                          securityPolicy:[self securityPolicy:parameters]
                                            certificates:[self clientCerts:parameters]];

    self.session.delegate = self;
    self.session.persistence.persistent = PERSISTENT;
    return self;
}

- (BOOL)runSynch {
    NSLog(@"%@ connecting", self.session.clientId);

    if ([self.session connectAndWaitToHost:self.parameters[@"host"]
                                      port:[self.parameters[@"port"] intValue]
                                  usingSSL:[self.parameters[@"tls"] boolValue]]) {

        [self.session subscribeAndWaitToTopic:@"#" atLevel:MQTTQosLevelAtLeastOnce];

        [self.session publishAndWaitData:[@"data" dataUsingEncoding:NSUTF8StringEncoding]
                                 onTopic:@"MQTTClient"
                                  retain:NO
                                     qos:2];

        [self.session closeAndWait];
        return true;
    } else {
        return false;
    }
}

- (void)start
{
    self.event = -1;
    [self.session connectToHost:self.parameters[@"host"]
                           port:[self.parameters[@"port"] intValue]
                       usingSSL:[self.parameters[@"tls"] boolValue]];
    NSLog(@"%@ connecting", self.session.clientId);

}

- (void)sub
{
    self.event = -1;
    [self.session subscribeToTopic:@"MQTTClient/#" atLevel:1];
}

- (void)pub
{
    self.event = -1;
    [self.session publishData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] onTopic:@"MQTTClient" retain:NO qos:2];
}

- (void)close
{
    self.event = -1;
    [self.session close];
}

- (void)stop
{
    self.session.delegate = nil;
    self.session = nil;
}

- (void)subAckReceived:(MQTTSession *)session msgID:(UInt16)msgID grantedQoss:(NSArray *)qoss
{
    self.event = 999;
}

- (void)messageDelivered:(MQTTSession *)session msgID:(UInt16)msgID
{
    self.event = 999;
}

- (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString *)topic qos:(MQTTQosLevel)qos retained:(BOOL)retained mid:(unsigned int)mid
{
    //NSLog(@"newMessage:%@ onTopic:%@ qos:%d retained:%d mid:%d", data, topic, qos, retained, mid);
}

- (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode error:(NSError *)error
{
    //NSLog(@"handleEvent:%ld error:%@", eventCode, error);
    self.event = eventCode;
    self.error = error;
}

- (NSArray *)clientCerts:(NSDictionary *)parameters {
    NSArray *clientCerts = nil;
    if (parameters[@"clientp12"] && parameters[@"clientp12pass"]) {

        NSString *path = [[NSBundle bundleForClass:[OneTest class]] pathForResource:parameters[@"clientp12"]
                                                                                ofType:@"p12"];

        clientCerts = [MQTTSession clientCertsFromP12:path passphrase:parameters[@"clientp12pass"]];
    }
    return clientCerts;
}

- (MQTTSSLSecurityPolicy *)securityPolicy:(NSDictionary *)parameters {
    MQTTSSLSecurityPolicy *securityPolicy = nil;

    if (parameters[@"serverCER"]) {

        NSString *path = [[NSBundle bundleForClass:[OneTest class]] pathForResource:parameters[@"serverCER"]
                                                                                ofType:@"cer"];
        if (path) {
            NSData *certificateData = [NSData dataWithContentsOfFile:path];
            if (certificateData) {
                securityPolicy = [MQTTSSLSecurityPolicy policyWithPinningMode:MQTTSSLPinningModeCertificate];
                securityPolicy.pinnedCertificates = [[NSArray alloc] initWithObjects:certificateData, nil];
                securityPolicy.validatesCertificateChain = TRUE;
                securityPolicy.allowInvalidCertificates = FALSE;
                securityPolicy.validatesDomainName = TRUE;
            }
        }
    }
    return securityPolicy;
}

@end

@interface MultiThreadingTests : XCTestCase <MQTTSessionDelegate>
@property (nonatomic) BOOL timeout;

@end

@implementation MultiThreadingTests

- (void)setUp
{
    [super setUp];
}

- (void)tearDown
{
    [super tearDown];
}

- (void)testAsynch
{
    for (NSString *broker in BROKERLIST) {
        NSLog(@"testing broker %@", broker);
        NSDictionary *parameters = BROKERS[broker];
        [self runAsynch:parameters];
    }
}

- (void)testSynch
{
    for (NSString *broker in BROKERLIST) {
        NSLog(@"testing broker %@", broker);
        NSDictionary *parameters = BROKERS[broker];
        [self runSynch:parameters];
    }
}

- (void)testMultiConnect
{
    for (NSString *broker in BROKERLIST) {
        NSLog(@"testing broker %@", broker);
        NSDictionary *parameters = BROKERS[broker];
        NSMutableArray *connections = [[NSMutableArray alloc] initWithCapacity:MULTI];

        for (int i = 0; i < MULTI; i++) {
            OneTest *oneTest = [[OneTest alloc] init];
            [connections addObject:oneTest];
        }

        for (OneTest *oneTest in connections) {
            [oneTest setup:parameters];
        }

        for (OneTest *oneTest in connections) {
            [oneTest start];
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
        }

        for (OneTest *oneTest in connections) {
            XCTAssertEqual(oneTest.event, MQTTSessionEventConnected, @"%@ Not Connected %ld %@", oneTest.session.clientId, (long)oneTest.event, oneTest.error);
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
        }

        for (OneTest *oneTest in connections) {
            [oneTest sub];
        }

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];

        for (OneTest *oneTest in connections) {
            [oneTest pub];
        }

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];

        for (OneTest *oneTest in connections) {
            [oneTest close];
        }

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];

        for (OneTest *oneTest in connections) {
            [oneTest stop];
        }
    }
}

- (void)testAsynchThreads
{
    for (NSString *broker in BROKERLIST) {
        NSLog(@"testing broker %@", broker);
        NSDictionary *parameters = BROKERS[broker];

        NSMutableArray *threads = [[NSMutableArray alloc] initWithCapacity:MULTI];

        for (int i = 0; i < MULTI; i++) {
            NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(runAsynch:) object:parameters];
            [threads addObject:thread];
        }

        for (NSThread *thread in threads) {
            [thread start];
        }

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];

        for (NSThread *thread in threads) {
            [thread cancel];
        }
    }
}

- (void)testSynchThreads
{
    for (NSString *broker in BROKERLIST) {
        NSLog(@"testing broker %@", broker);
        NSDictionary *parameters = BROKERS[broker];

        NSMutableArray *threads = [[NSMutableArray alloc] initWithCapacity:MULTI];

        for (int i = 0; i < MULTI; i++) {
            NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(runSynch:) object:parameters];
            [threads addObject:thread];
        }

        for (NSThread *thread in threads) {
            [thread start];
        }

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];

        for (NSThread *thread in threads) {
            [thread cancel];
        }
    }
}

- (void)ackTimeout:(id)object
{
    //NSLog(@"ackTimeout");
    self.timeout = TRUE;
}

- (void)runAsynch:(NSDictionary *)parameters
{
    OneTest *test = [[OneTest alloc] init];
    [test setup:parameters];
    [test start];

    while (test.event == -1) {
        //NSLog(@"waiting for connection");
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    }

    XCTAssertEqual(test.event, MQTTSessionEventConnected, @"%@ Not Connected %ld %@", test.session.clientId, (long)test.event, test.error);

    if (test.session.status == MQTTSessionStatusConnected) {

        [test sub];

        while (test.event == -1) {
            //NSLog(@"%@ waiting for suback", test.session.clientId);
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
        }

        [test pub];

        while (test.event == -1) {
            //NSLog(@"%@ waiting for puback", test.session.clientId);
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
        }

        [test close];

        while (test.event == -1) {
            //NSLog(@"%@ waiting for close", test.session.clientId);
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
        }
    }

    [test stop];
}

- (void)runSynch:(NSDictionary *)parameters
{
    OneTest *test = [[OneTest alloc] init];
    [test setup:parameters];

    if (![test runSynch]) {
        XCTFail(@"%@ Not Connected %ld %@", test.session.clientId, (long)test.event, test.error);
    }
}

@end


text:
#include <yaml.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#include "yaml-tree.h"

typedef struct
{
	yaml_parser_t parser;
	yaml_event_t event;
	yaml_event_t next_event;
	yaml_error *error;
} parser_context;

static yaml_node *process_node(parser_context *ctx);

char yaml_last_error[1024];
char *format_error_string(parser_context *ctx)
{
	assert(ctx->parser.error != YAML_NO_ERROR);

	switch (ctx->parser.error)
	{
		case YAML_MEMORY_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: failed to allocate or reallocate a block of memory.");
			break;

		case YAML_READER_ERROR:
			if (ctx->parser.problem_value != -1)
				snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: reader error: '%s:#%X' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_value, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			else
				snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: reader error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		case YAML_SCANNER_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: scanner error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		case YAML_PARSER_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: parser error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		case YAML_COMPOSER_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: composer error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		case YAML_WRITER_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: writer error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		case YAML_EMITTER_ERROR:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "libyaml: emitter error: '%s' at line %zu, column %zu.", ctx->parser.problem, ctx->parser.problem_mark.line, ctx->parser.problem_mark.column);
			break;

		default:
			snprintf(yaml_last_error, sizeof(yaml_last_error)-1, "unknown error code (%i) from libyaml. possible memory corruption?", ctx->parser.error);
			break;
	}

	return yaml_last_error;
}

static const char *event_to_string(yaml_event_type_t event)
{
	switch (event)
	{
		case YAML_NO_EVENT:
			return "YAML_NO_EVENT";
		case YAML_STREAM_START_EVENT:
			return "YAML_STREAM_START_EVENT";
		case YAML_STREAM_END_EVENT:
			return "YAML_STREAM_END_EVENT";
		case YAML_DOCUMENT_START_EVENT:
			return "YAML_DOCUMENT_START_EVENT";
		case YAML_DOCUMENT_END_EVENT:
			return "YAML_DOCUMENT_END_EVENT";
		case YAML_ALIAS_EVENT:
			return "YAML_ALIAS_EVENT";
		case YAML_SCALAR_EVENT:
			return "YAML_SCALAR_EVENT";
		case YAML_SEQUENCE_START_EVENT:
			return "YAML_SEQUENCE_START_EVENT";
		case YAML_SEQUENCE_END_EVENT:
			return "YAML_SEQUENCE_END_EVENT";
		case YAML_MAPPING_START_EVENT:
			return "YAML_MAPPING_START_EVENT";
		case YAML_MAPPING_END_EVENT:
			return "YAML_MAPPING_END_EVENT";
		default:
			return "UNKNOWN";
	}

	assert(0);
	return "UNKNOWN";
}

static int is_error_set(parser_context *ctx)
{
	return ctx->error->problem != NULL;
}

static int set_error(parser_context *ctx)
{
	if (!is_error_set(ctx) && ctx->parser.error)
	{
		ctx->error->problem = format_error_string(ctx);
		return 1;
	}

	return 0;
}

static int process_event(parser_context *ctx)
{
	memcpy(&ctx->event, &ctx->next_event, sizeof(yaml_event_t));
	yaml_parser_parse(&ctx->parser, &ctx->next_event);
	return set_error(ctx) ? (-1) : (0);
}

static yaml_event_type_t peek_next_event(parser_context *ctx)
{
	// just peek the next event
	return ctx->next_event.type;
}

static yaml_event_type_t next_event(parser_context *ctx)
{
	// process event and return it
	if (process_event(ctx) < 0)
		return YAML_NO_EVENT;

	return ctx->event.type;
}

static yaml_node *process_scalar(parser_context *ctx)
{
	yaml_node *scalar = malloc(sizeof(yaml_node));
	scalar->type = NODE_SCALAR;
	scalar->position.line = ctx->event.start_mark.line;
	scalar->position.column = ctx->event.start_mark.column;
	scalar->data.scalar.value = strdup(ctx->event.data.scalar.value);
	scalar->data.scalar.len = ctx->event.data.scalar.length;
	return scalar;
}

static yaml_node *process_sequence(parser_context *ctx)
{
	yaml_node *sequence = malloc(sizeof(yaml_node));
	yaml_sequence *seq = &sequence->data.sequence;

	sequence->type = NODE_SEQUENCE;
	sequence->position.line = ctx->event.start_mark.line;
	sequence->position.column = ctx->event.start_mark.column;

	// zero out values
	seq->count = 0;
	seq->nodes = NULL;

	while (peek_next_event(ctx) != YAML_SEQUENCE_END_EVENT)
	{
		yaml_node *node = process_node(ctx);

		if (!node)
			return NULL;

		// extend space
		seq->nodes = realloc(seq->nodes, (seq->count+1)*sizeof(yaml_node*));
		seq->nodes[seq->count++] = node;
	}

	if (process_event(ctx) < 0)
		return NULL;

	return sequence;
}

static yaml_node *process_mapping(parser_context *ctx)
{
	yaml_node *mapping = malloc(sizeof(yaml_node));
	yaml_mapping *map = &mapping->data.mapping;

	mapping->type = NODE_MAPPING;
	mapping->position.line = ctx->event.start_mark.line;
	mapping->position.column = ctx->event.start_mark.column;

	// zero out values
	map->count = 0;
	map->pairs = NULL;

	while (peek_next_event(ctx) != YAML_MAPPING_END_EVENT)
	{
		yaml_node_pair *pair = malloc(sizeof(yaml_node_pair));

		pair->lhs = process_node(ctx);

		if (!pair->lhs)
			return NULL;

		pair->rhs = process_node(ctx);

		if (!pair->rhs)
			return NULL;

		// extend space as needed
		map->pairs = realloc(map->pairs, (map->count+1)*sizeof(yaml_node_pair*));
		map->pairs[map->count++] = pair;
	}

	if (process_event(ctx) < 0)
		return NULL;

	return mapping;
}

static yaml_node *process_node(parser_context *ctx)
{
	// we expect either: alias, scalar, sequence or mapping
	switch (next_event(ctx))
	{
		case YAML_ALIAS_EVENT:
			// TODO: we dont support aliases for now
			snprintf(ctx->error->problem=yaml_last_error, sizeof(yaml_last_error)-1,"yamltree: there is no support for aliases implemented.");
			return NULL;

		case YAML_SCALAR_EVENT:
			return process_scalar(ctx);

		case YAML_SEQUENCE_START_EVENT:
			return process_sequence(ctx);

		case YAML_MAPPING_START_EVENT:
			return process_mapping(ctx);

		default:
			// probably an error
			break;
	}

	return NULL;
}

static yaml_document *process_document(parser_context *ctx)
{
	// look for document start event.
	if (next_event(ctx) != YAML_DOCUMENT_START_EVENT)
	{
		if (!is_error_set(ctx))
		{
			snprintf(ctx->error->problem=yaml_last_error, sizeof(yaml_last_error)-1,"yamltree: expecting YAML_DOCUMENT_START_EVENT got '%s'.", event_to_string(ctx->event.type));
		}

		return NULL;
	}

	// a document is basically a fancy name for a root node
	yaml_document *doc = process_node(ctx);

	if (!doc)
		return NULL;

	// get end of document
	if (next_event(ctx) != YAML_DOCUMENT_END_EVENT)
	{
		if (!is_error_set(ctx))
		{
			snprintf(ctx->error->problem=yaml_last_error, sizeof(yaml_last_error)-1,"yamltree: expecting YAML_DOCUMENT_END_EVENT got '%s'.", event_to_string(ctx->event.type));
		}

		return NULL;
	}

	return doc;
}

yaml_tree *parse_yaml_stream(FILE *input, yaml_error *error)
{
	parser_context ctx;
	ctx.error = error;
	yaml_parser_initialize(&ctx.parser);
	yaml_parser_set_input_file(&ctx.parser, input);

	if (process_event(&ctx) < 0)
		goto error;

	if (ctx.next_event.type != YAML_STREAM_START_EVENT)
	{
		snprintf(ctx.error->problem = yaml_last_error, sizeof(yaml_last_error)-1, "yamltree: expecting YAML_STREAM_START_EVENT got '%s'.", event_to_string(ctx.next_event.type));
		goto error;
	}

	yaml_tree *stream = malloc(sizeof(yaml_tree));

	stream->count = 0;
	stream->docs = NULL;

	while (next_event(&ctx) != YAML_STREAM_END_EVENT)
	{
		// check error
		if (is_error_set(&ctx))
		{
			goto error;
		}

		yaml_document *document = process_document(&ctx);

		if (!document)
		{
			// TODO: clean up structure
			goto error;
		}

		stream->docs = realloc(stream->docs, (stream->count+1)*sizeof(yaml_tree));
		stream->docs[stream->count++] = document;
	}

	yaml_parser_delete(&ctx.parser);
	return stream;

error:
	yaml_parser_delete(&ctx.parser);
	return NULL;
}

void free_yaml_tree(yaml_tree *tree)
{
	// TODO: implement
}

const char *node_type_str(yaml_node *node)
{
	switch (node->type)
	{
		case NODE_MAPPING:
			return "mapping";
		case NODE_SEQUENCE:
			return "sequence";
		case NODE_SCALAR:
			return "scalar";
		default:
			assert(0);
			break;
	}

	assert(0);
	return NULL;
}