text:
require 'spec_helper'

describe 'Launch Configuration' do
  include_context :terraform

  subject {
    launch_configuration(output_for(:harness, 'launch_configuration_name'))
  }

  it { should exist }
  its(:instance_type) { should eq(vars.cluster_instance_type) }

  context 'uses latest amazon linux 2 optimised for ECS' do
    let(:latest_amazon_linux_2_ecs_optimised_ami_id) {
      response = ec2_client.describe_images(
          {
              owners: ['amazon'],
              filters: [
                  {
                      name: 'name',
                      values: ['amzn2-ami-ecs-hvm-*-x86_64-ebs']
                  }
              ]
          })
      most_recent_image = response.images.max_by do |image|
        DateTime.parse(image.creation_date)
      end

      most_recent_image.image_id
    }

    its(:image_id) do
      should eq(latest_amazon_linux_2_ecs_optimised_ami_id)
    end
  end

  it 'does not add a docker block device' do
    expect(subject.block_device_mappings.size).to(eq(1))
  end

  context 'when custom security groups are provided' do
    before(:all) do
      security_group_ids =
          output_for(:prerequisites, 'security_group_ids')
      reprovision(
          security_groups:
              '["' + security_group_ids.join('","') + '"]'
      )
    end

    it { should have_security_group("#{vars.component}-#{vars.deployment_identifier}-0") }
    it { should have_security_group("#{vars.component}-#{vars.deployment_identifier}-1") }

    it 'should have correct number of security groups' do
      expect(subject.security_groups.size).to(eq(3))
    end
  end

  context 'when AMIs specified' do
    it 'uses provided image ID' do
      ami_id = configuration.for(:harness).ami_id_in_region
      puts ami_id
      reprovision(
          cluster_instance_amis:
              '{' + vars.region + '="' + ami_id + '"}')

      expect(
          launch_configuration(
              output_for(:harness, 'launch_configuration_name'))
              .image_id).to eq(ami_id)
    end
  end

  its(:key_name) do
    should eq("cluster-#{vars.component}-#{vars.deployment_identifier}-#{vars.cluster_name}")
  end

  its(:iam_instance_profile) do
    should eq("cluster-instance-profile-#{vars.component}-#{vars.deployment_identifier}-#{vars.cluster_name}")
  end

  its(:user_data) do
    should eq(Base64.strict_encode64(<<~DOC))
      #!/bin/bash
      echo "ECS_CLUSTER=#{vars.component}-#{vars.deployment_identifier}-#{vars.cluster_name}" > /etc/ecs/ecs.config
    DOC
  end

  it { should have_security_group("#{vars.component}-#{vars.deployment_identifier}-#{vars.cluster_name}") }

  it 'has a name containing the component, deployment_identifier and cluster_name' do
    launch_configuration_name = output_for(:harness, 'launch_configuration_name')

    expect(launch_configuration_name).to(match(/#{vars.component}/))
    expect(launch_configuration_name).to(match(/#{vars.deployment_identifier}/))
    expect(launch_configuration_name).to(match(/#{vars.cluster_name}/))
  end

  it 'uses the specified size for the root block device' do
    root_device_mapping = subject.block_device_mappings.find do |d|
      d.device_name != '/dev/xvdcz'
    end
    expect(root_device_mapping.ebs.volume_size)
        .to(eq(vars.cluster_instance_root_block_device_size.to_i))
  end
end


text:
export * from "./reexport2";
import { value4 } from "./reexport2";
import v from "./reexport-concat";
export const value3 = v + value4 - value4;

redpajama_set_name: RedPajamaGithub


text:
package com.baidubce.services.ruleengine.model.dict;

import com.baidubce.model.GenericAccountRequest;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * Class for write dict data request
 *
 * Created by liudawei02 on 19/4/3.
 */
@Data
public class WriteDictDataRequest extends GenericAccountRequest {
    private String uuid;
    private Map<String, String> data = new HashMap<String, String>();
}


text:
<?php

use Bee\Utils\IOrdered;

/**
 * User: mp
 * Date: Feb 19, 2010
 * Time: 10:40:52 PM
 */

abstract class Bee_AOP_Support_AbstractPointcutAdvisor implements Bee_AOP_IPointcutAdvisor, IOrdered {

    /**
     * @var int
     */
    private $order = IOrdered::LOWEST_PRECEDENCE;

    /**
     * Gets the Order
     *
     * @return int $order
     */
    public function getOrder() {
        return $this->order;
    }

    /**
     * Sets the Order
     *
     * @param int $order
     * @return void
     */
    public function setOrder($order) {
        $this->order = $order;
    }
}

?>


text:
$(window).load(function(){
    $('a[href^="#"]:not([href^="#carousel"]):not([data-toggle="dropdown"])').on('click', function(e) {

        // prevent default anchor click behavior
        e.preventDefault();

        // store hash
        var hash = this.hash;

        // animate
        $('html, body').animate({
            scrollTop: $(this.hash).offset().top - 100
        }, 300, function(){

            // when done, add hash to url
            // (default click behaviour)
            window.location.hash = hash;
        });

    });
});

// Proper tab selection (adding back attributes removed by maven/reflow skin)
$('.nav-tabs li a').attr('data-toggle', 'tab');
$('.nav-tabs li a').click(function (e) {
    e.preventDefault();
    e.stopImmediatePropagation();
    $(this).tab('show');
})


text:
<!--============================================================
TITLE: UPnP AV Scheduled Recording Service (SRS) Template

Purpose:
To identify the required/optional actions and state variables
and the required allowed values defined by this service type.

Note:
This file uses tabs (not spaces) for block indentation.
Any updates to this file should maintain this convention.
This includes disabling any automatic tab-to-space conversion
feature provided by your editor.
================================================================-->
<scpd>
	<serviceStateTable>
		<stateVariable>
			<name>SortCapabilities</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>SortLevelCapability</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>ui4</dataType>
		</stateVariable>

		<stateVariable>
			<name>StateUpdateID</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>ui4</dataType>
		</stateVariable>

		<stateVariable>
			<name>LastChange</name>
			<sendEventsAttribute>yes</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_PropertyList</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_DataTypeID</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
			<allowedValueList>
				<allowedValue>A_ARG_TYPE_RecordSchedule</allowedValue>
				<allowedValue>A_ARG_TYPE_RecordTask</allowedValue>
				<allowedValue>A_ARG_TYPE_RecordScheduleParts</allowedValue>
			</allowedValueList>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_ObjectID</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<Optional/>
			<name>A_ARG_TYPE_ObjectIDList</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_PropertyInfo</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_Index</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>ui4</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_Count</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>ui4</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_SortCriteria</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_RecordSchedule</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_RecordTask</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>

		<stateVariable>
			<name>A_ARG_TYPE_RecordScheduleParts</name>
			<sendEventsAttribute>no</sendEventsAttribute>
			<dataType>string</dataType>
		</stateVariable>
	</serviceStateTable>

	<actionList>
		<action>
			<name>GetSortCapabilities</name>
			<argumentList>
				<argument>
					<name>SortCaps</name>
					<direction>out</direction>
					<relatedStateVariable>SortCapabilities</relatedStateVariable>
				</argument>
				<argument>
					<name>SortLevelCap</name>
					<direction>out</direction>
					<relatedStateVariable>SortLevelCapability</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>GetPropertyList</name>
			<argumentList>
				<argument>
					<name>DataTypeID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_DataTypeID</relatedStateVariable>
				</argument>
				<argument>
					<name>PropertyList</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>GetAllowedValues</name>
			<argumentList>
				<argument>
					<name>DataTypeID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_DataTypeID</relatedStateVariable>
				</argument>
				<argument>
					<name>Filter</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
				<argument>
					<name>PropertyInfo</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyInfo</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>GetStateUpdateID</name>
			<argumentList>
				<argument>
					<name>Id</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>BrowseRecordSchedules</name>
			<argumentList>
				<argument>
					<name>Filter</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
				<argument>
					<name>StartingIndex</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_Index</relatedStateVariable>
				</argument>
				<argument>
					<name>RequestedCount</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>SortCriteria</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_SortCriteria</relatedStateVariable>
				</argument>
				<argument>
					<name>Result</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordSchedule</relatedStateVariable>
				</argument>
				<argument>
					<name>NumberReturned</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>TotalMatches</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>BrowseRecordTasks</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>Filter</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
				<argument>
					<name>StartingIndex</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_Index</relatedStateVariable>
				</argument>
				<argument>
					<name>RequestedCount</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>SortCriteria</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_SortCriteria</relatedStateVariable>
				</argument>
				<argument>
					<name>Result</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordTask</relatedStateVariable>
				</argument>
				<argument>
					<name>NumberReturned</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>TotalMatches</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_Count</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>CreateRecordSchedule</name>
			<argumentList>
				<argument>
					<name>Elements</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordScheduleParts</relatedStateVariable>
				</argument>
				<argument>
					<name>RecordScheduleID</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>Result</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordSchedule</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>DeleteRecordSchedule</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>GetRecordSchedule</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>Filter</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
				<argument>
					<name>Result</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordSchedule</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>EnableRecordSchedule</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>DisableRecordSchedule</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>DeleteRecordTask</name>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>GetRecordTask</name>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>Filter</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_PropertyList</relatedStateVariable>
				</argument>
				<argument>
					<name>Result</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_RecordTask</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>EnableRecordTask</name>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>DisableRecordTask</name>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<name>ResetRecordTask</name>
			<Optional/>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>GetRecordScheduleConflicts</name>
			<argumentList>
				<argument>
					<name>RecordScheduleID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>RecordScheduleConflictIDList</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectIDList</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID</relatedStateVariable>
				</argument>
			</argumentList>
		</action>

		<action>
			<Optional/>
			<name>GetRecordTaskConflicts</name>
			<argumentList>
				<argument>
					<name>RecordTaskID</name>
					<direction>in</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
				</argument>
				<argument>
					<name>RecordTaskConflictIDList</name>
					<direction>out</direction>
					<relatedStateVariable>A_ARG_TYPE_ObjectIDList</relatedStateVariable>
				</argument>
				<argument>
					<name>UpdateID</name>
					<direction>out</direction>
					<relatedStateVariable>StateUpdateID
					</relatedStateVariable>
				</argument>
			</argumentList>
		</action>
	</actionList>
</scpd>


text:
using System.Web;
using System.Web.Optimization;

namespace Project.Web
{
    public class BundleConfig
    {
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/bower_components/jquery/dist/jquery.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/bower_components/jquery-validation/dist/jquery.validate.js",
                        "~/bower_components/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/bower_components/bootstrap/dist/js/bootstrap.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/bower_components/bootstrap/dist/css/bootstrap.css",
                      "~/Content/site.css"));

            // Set EnableOptimizations to false for debugging. For more information,
            // visit http://go.microsoft.com/fwlink/?LinkId=301862
            BundleTable.EnableOptimizations = true;
        }
    }
}


text:
PATH=/bin:/usr/bin:/sbin:/usr/sbin

# We are confirming that igb0 hasn't locked up.  Our own switch doesn't
# have an IP address in that vlan, so we ping something else (which is farther
# from us, network-wise).
switch=140.211.11.1
ping -t 1 -c 1 $switch > /dev/null && exit 0

echo mino cannot ping the switch at $switch - toggling igb0 interface
ifconfig igb0 down
sleep 5
ifconfig igb0 up

exit 0


text:
<?php

	require_once(TOOLKIT . '/class.datasource.php');

	Class datasourceBreadcrumb extends Datasource {

		/**
		 *
		 * name of the root XML element that wraps the data
		 * @var string
		 */
		public $dsParamROOTELEMENT = 'breadcrumb';

		/**
		 *
		 * Flag to detect is site is multilingual
		 * Must have the and extension installed and enabled
		 * @var boolean
		 */
		protected $isMultiLangual = false;

		/**
		 *
		 * Credits method
		 */
		public function about(){

			return array('name' => 'Breadcrumb',
			             'version' => 'Breadcrumb 1.2',
			             'release-date' => '2012-05-02',
			             'author' => array('name' => 'Symphony Community', 'website' => 'https://github.com/symphonists/'));
		}

		/**
		 *
		 * Class constructor
		 * @param object $parent
		 * @param array $env
		 * @param boolean $process_params
		 */
		public function __construct(Array $env = null, $process_params=true){
			parent::__construct($env, $process_params);

			// detect if multilangual field AND language redirect is enabled
			$this->isMultiLangual =
					(Symphony::ExtensionManager()->fetchStatus('page_lhandles') == EXTENSION_ENABLED &&
					 Symphony::ExtensionManager()->fetchStatus('language_redirect') == EXTENSION_ENABLED);

			// add a ref to the Language redirect
			if ($this->isMultiLangual) {
				require_once (EXTENSIONS . '/language_redirect/lib/class.languageredirect.php');
			}
		}

		/**
		 *
		 * Method called by Symphony in order to build the
		 * @param $param_pool
		 * @return XMLElement
		 */
		public function grab(&$param_pool){

			// get the current page id
			$current_page_id = (int)$this->_env['param']['current-page-id'];

			// prepare output
			$result = new XMLElement($this->dsParamROOTELEMENT);

			// if multilangual extensions are enabled
			if ($this->isMultiLangual) {

				// current language
				$lang = LanguageRedirect::instance()->getLanguageCode();
			}

			// get current page title including all parents
			$titles = PageManager::resolvePage($current_page_id, isset($lang) ? 'page_lhandles_t_' . $lang : 'title');

			// get current page path including all parents
			$handles = PageManager::resolvePage($current_page_id, isset($lang) ? 'page_lhandles_h_' . $lang : 'handle');

			// generate the output
			foreach ($titles as $key => $title) {

				$path = implode('/', array_slice($handles, 0, $key + 1));

				$result->appendChild(new XMLElement( 'page', $title, array('path'=>$path) ));
			}

			// return xml result set
			return $result;
		}
	}


text:
package jp.fujiu.TweetNicoMovieForQuerychan;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown=true)
public class Json1stDefinition {
    public String dqnid;
    public String type;
    public Json1stDefinitionValue values[];

}


text:
package kafka.log

import java.io.File
import java.util.Properties

import kafka.api.KAFKA_0_11_0_IV0
import kafka.api.{KAFKA_0_10_0_IV1, KAFKA_0_9_0}
import kafka.server.KafkaConfig
import kafka.server.checkpoints.OffsetCheckpointFile
import kafka.utils._
import org.apache.kafka.common.TopicPartition
import org.apache.kafka.common.record._
import org.junit.Assert._
import org.junit._
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

import scala.Seq
import scala.collection._

/**
 * This is an integration test that tests the fully integrated log cleaner
 */
@RunWith(value = classOf[Parameterized])
class LogCleanerParameterizedIntegrationTest(compressionCodec: String) extends AbstractLogCleanerIntegrationTest {

  val codec: CompressionType = CompressionType.forName(compressionCodec)
  val time = new MockTime()

  val topicPartitions = Array(new TopicPartition("log", 0), new TopicPartition("log", 1), new TopicPartition("log", 2))

  @Test
  def cleanerTest() {
    val largeMessageKey = 20
    val (largeMessageValue, largeMessageSet) = createLargeSingleMessageSet(largeMessageKey, RecordBatch.CURRENT_MAGIC_VALUE)
    val maxMessageSize = largeMessageSet.sizeInBytes

    cleaner = makeCleaner(partitions = topicPartitions, maxMessageSize = maxMessageSize)
    val log = cleaner.logs.get(topicPartitions(0))

    val appends = writeDups(numKeys = 100, numDups = 3, log = log, codec = codec)
    val startSize = log.size
    cleaner.startup()

    val firstDirty = log.activeSegment.baseOffset
    checkLastCleaned("log", 0, firstDirty)
    val compactedSize = log.logSegments.map(_.size).sum
    assertTrue(s"log should have been compacted: startSize=$startSize compactedSize=$compactedSize", startSize > compactedSize)

    checkLogAfterAppendingDups(log, startSize, appends)

    val appendInfo = log.appendAsLeader(largeMessageSet, leaderEpoch = 0)
    val largeMessageOffset = appendInfo.firstOffset.get

    val dups = writeDups(startKey = largeMessageKey + 1, numKeys = 100, numDups = 3, log = log, codec = codec)
    val appends2 = appends ++ Seq((largeMessageKey, largeMessageValue, largeMessageOffset)) ++ dups
    val firstDirty2 = log.activeSegment.baseOffset
    checkLastCleaned("log", 0, firstDirty2)

    checkLogAfterAppendingDups(log, startSize, appends2)

    // simulate deleting a partition, by removing it from logs
    // force a checkpoint
    // and make sure its gone from checkpoint file
    cleaner.logs.remove(topicPartitions(0))
    cleaner.updateCheckpoints(logDir)
    val checkpoints = new OffsetCheckpointFile(new File(logDir, cleaner.cleanerManager.offsetCheckpointFile)).read()
    // we expect partition 0 to be gone
    assertFalse(checkpoints.contains(topicPartitions(0)))
  }

  @Test
  def testCleansCombinedCompactAndDeleteTopic(): Unit = {
    val logProps  = new Properties()
    val retentionMs: Integer = 100000
    logProps.put(LogConfig.RetentionMsProp, retentionMs: Integer)
    logProps.put(LogConfig.CleanupPolicyProp, "compact,delete")

    def runCleanerAndCheckCompacted(numKeys: Int): (Log, Seq[(Int, String, Long)]) = {
      cleaner = makeCleaner(partitions = topicPartitions.take(1), propertyOverrides = logProps, backOffMs = 100L)
      val log = cleaner.logs.get(topicPartitions(0))

      val messages = writeDups(numKeys = numKeys, numDups = 3, log = log, codec = codec)
      val startSize = log.size

      log.onHighWatermarkIncremented(log.logEndOffset)

      val firstDirty = log.activeSegment.baseOffset
      cleaner.startup()

      // should compact the log
      checkLastCleaned("log", 0, firstDirty)
      val compactedSize = log.logSegments.map(_.size).sum
      assertTrue(s"log should have been compacted: startSize=$startSize compactedSize=$compactedSize", startSize > compactedSize)
      (log, messages)
    }

    val (log, _) = runCleanerAndCheckCompacted(100)
    // should delete old segments
    log.logSegments.foreach(_.lastModified = time.milliseconds - (2 * retentionMs))

    TestUtils.waitUntilTrue(() => log.numberOfSegments == 1, "There should only be 1 segment remaining", 10000L)
    assertEquals(1, log.numberOfSegments)

    cleaner.shutdown()

    // run the cleaner again to make sure if there are no issues post deletion
    val (log2, messages) = runCleanerAndCheckCompacted(20)
    val read = readFromLog(log2)
    assertEquals("Contents of the map shouldn't change", toMap(messages), toMap(read))
  }

  @Test
  def testCleanerWithMessageFormatV0(): Unit = {
    // zstd compression is not supported with older message formats
    if (codec == CompressionType.ZSTD)
      return

    val largeMessageKey = 20
    val (largeMessageValue, largeMessageSet) = createLargeSingleMessageSet(largeMessageKey, RecordBatch.MAGIC_VALUE_V0)
    val maxMessageSize = codec match {
      case CompressionType.NONE => largeMessageSet.sizeInBytes
      case _ =>
        // the broker assigns absolute offsets for message format 0 which potentially causes the compressed size to
        // increase because the broker offsets are larger than the ones assigned by the client
        // adding `5` to the message set size is good enough for this test: it covers the increased message size while
        // still being less than the overhead introduced by the conversion from message format version 0 to 1
        largeMessageSet.sizeInBytes + 5
    }

    cleaner = makeCleaner(partitions = topicPartitions, maxMessageSize = maxMessageSize)

    val log = cleaner.logs.get(topicPartitions(0))
    val props = logConfigProperties(maxMessageSize = maxMessageSize)
    props.put(LogConfig.MessageFormatVersionProp, KAFKA_0_9_0.version)
    log.config = new LogConfig(props)

    val appends = writeDups(numKeys = 100, numDups = 3, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V0)
    val startSize = log.size
    cleaner.startup()

    val firstDirty = log.activeSegment.baseOffset
    checkLastCleaned("log", 0, firstDirty)
    val compactedSize = log.logSegments.map(_.size).sum
    assertTrue(s"log should have been compacted: startSize=$startSize compactedSize=$compactedSize", startSize > compactedSize)

    checkLogAfterAppendingDups(log, startSize, appends)

    val appends2: Seq[(Int, String, Long)] = {
      val dupsV0 = writeDups(numKeys = 40, numDups = 3, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V0)
      val appendInfo = log.appendAsLeader(largeMessageSet, leaderEpoch = 0)
      val largeMessageOffset = appendInfo.firstOffset.get

      // also add some messages with version 1 and version 2 to check that we handle mixed format versions correctly
      props.put(LogConfig.MessageFormatVersionProp, KAFKA_0_11_0_IV0.version)
      log.config = new LogConfig(props)
      val dupsV1 = writeDups(startKey = 30, numKeys = 40, numDups = 3, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V1)
      val dupsV2 = writeDups(startKey = 15, numKeys = 5, numDups = 3, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V2)
      appends ++ dupsV0 ++ Seq((largeMessageKey, largeMessageValue, largeMessageOffset)) ++ dupsV1 ++ dupsV2
    }
    val firstDirty2 = log.activeSegment.baseOffset
    checkLastCleaned("log", 0, firstDirty2)

    checkLogAfterAppendingDups(log, startSize, appends2)
  }

  @Test
  def testCleaningNestedMessagesWithMultipleVersions(): Unit = {
    // zstd compression is not supported with older message formats
    if (codec == CompressionType.ZSTD)
      return

    val maxMessageSize = 192
    cleaner = makeCleaner(partitions = topicPartitions, maxMessageSize = maxMessageSize, segmentSize = 256)

    val log = cleaner.logs.get(topicPartitions(0))
    val props = logConfigProperties(maxMessageSize = maxMessageSize, segmentSize = 256)
    props.put(LogConfig.MessageFormatVersionProp, KAFKA_0_9_0.version)
    log.config = new LogConfig(props)

    // with compression enabled, these messages will be written as a single message containing
    // all of the individual messages
    var appendsV0 = writeDupsSingleMessageSet(numKeys = 2, numDups = 3, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V0)
    appendsV0 ++= writeDupsSingleMessageSet(numKeys = 2, startKey = 3, numDups = 2, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V0)

    props.put(LogConfig.MessageFormatVersionProp, KAFKA_0_10_0_IV1.version)
    log.config = new LogConfig(props)

    var appendsV1 = writeDupsSingleMessageSet(startKey = 4, numKeys = 2, numDups = 2, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V1)
    appendsV1 ++= writeDupsSingleMessageSet(startKey = 4, numKeys = 2, numDups = 2, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V1)
    appendsV1 ++= writeDupsSingleMessageSet(startKey = 6, numKeys = 2, numDups = 2, log = log, codec = codec, magicValue = RecordBatch.MAGIC_VALUE_V1)

    val appends = appendsV0 ++ appendsV1

    val startSize = log.size
    cleaner.startup()

    val firstDirty = log.activeSegment.baseOffset
    assertTrue(firstDirty > appendsV0.size) // ensure we clean data from V0 and V1

    checkLastCleaned("log", 0, firstDirty)
    val compactedSize = log.logSegments.map(_.size).sum
    assertTrue(s"log should have been compacted: startSize=$startSize compactedSize=$compactedSize", startSize > compactedSize)

    checkLogAfterAppendingDups(log, startSize, appends)
  }

  @Test
  def cleanerConfigUpdateTest() {
    val largeMessageKey = 20
    val (largeMessageValue, largeMessageSet) = createLargeSingleMessageSet(largeMessageKey, RecordBatch.CURRENT_MAGIC_VALUE)
    val maxMessageSize = largeMessageSet.sizeInBytes

    cleaner = makeCleaner(partitions = topicPartitions, backOffMs = 1, maxMessageSize = maxMessageSize,
      cleanerIoBufferSize = Some(1))
    val log = cleaner.logs.get(topicPartitions(0))

    writeDups(numKeys = 100, numDups = 3, log = log, codec = codec)
    val startSize = log.size
    cleaner.startup()
    assertEquals(1, cleaner.cleanerCount)

    // Verify no cleaning with LogCleanerIoBufferSizeProp=1
    val firstDirty = log.activeSegment.baseOffset
    val topicPartition = new TopicPartition("log", 0)
    cleaner.awaitCleaned(topicPartition, firstDirty, maxWaitMs = 10)
    assertTrue("Should not have cleaned", cleaner.cleanerManager.allCleanerCheckpoints.isEmpty)

    def kafkaConfigWithCleanerConfig(cleanerConfig: CleanerConfig): KafkaConfig = {
      val props = TestUtils.createBrokerConfig(0, "localhost:2181")
      props.put(KafkaConfig.LogCleanerThreadsProp, cleanerConfig.numThreads.toString)
      props.put(KafkaConfig.LogCleanerDedupeBufferSizeProp, cleanerConfig.dedupeBufferSize.toString)
      props.put(KafkaConfig.LogCleanerDedupeBufferLoadFactorProp, cleanerConfig.dedupeBufferLoadFactor.toString)
      props.put(KafkaConfig.LogCleanerIoBufferSizeProp, cleanerConfig.ioBufferSize.toString)
      props.put(KafkaConfig.MessageMaxBytesProp, cleanerConfig.maxMessageSize.toString)
      props.put(KafkaConfig.LogCleanerBackoffMsProp, cleanerConfig.backOffMs.toString)
      props.put(KafkaConfig.LogCleanerIoMaxBytesPerSecondProp, cleanerConfig.maxIoBytesPerSecond.toString)
      KafkaConfig.fromProps(props)
    }

    // Verify cleaning done with larger LogCleanerIoBufferSizeProp
    val oldConfig = kafkaConfigWithCleanerConfig(cleaner.currentConfig)
    val newConfig = kafkaConfigWithCleanerConfig(CleanerConfig(numThreads = 2,
      dedupeBufferSize = cleaner.currentConfig.dedupeBufferSize,
      dedupeBufferLoadFactor = cleaner.currentConfig.dedupeBufferLoadFactor,
      ioBufferSize = 100000,
      maxMessageSize = cleaner.currentConfig.maxMessageSize,
      maxIoBytesPerSecond = cleaner.currentConfig.maxIoBytesPerSecond,
      backOffMs = cleaner.currentConfig.backOffMs))
    cleaner.reconfigure(oldConfig, newConfig)

    assertEquals(2, cleaner.cleanerCount)
    checkLastCleaned("log", 0, firstDirty)
    val compactedSize = log.logSegments.map(_.size).sum
    assertTrue(s"log should have been compacted: startSize=$startSize compactedSize=$compactedSize", startSize > compactedSize)
  }

  private def checkLastCleaned(topic: String, partitionId: Int, firstDirty: Long) {
    // wait until cleaning up to base_offset, note that cleaning happens only when "log dirty ratio" is higher than
    // LogConfig.MinCleanableDirtyRatioProp
    val topicPartition = new TopicPartition(topic, partitionId)
    cleaner.awaitCleaned(topicPartition, firstDirty)
    val lastCleaned = cleaner.cleanerManager.allCleanerCheckpoints(topicPartition)
    assertTrue(s"log cleaner should have processed up to offset $firstDirty, but lastCleaned=$lastCleaned",
      lastCleaned >= firstDirty)
  }

  private def checkLogAfterAppendingDups(log: Log, startSize: Long, appends: Seq[(Int, String, Long)]) {
    val read = readFromLog(log)
    assertEquals("Contents of the map shouldn't change", toMap(appends), toMap(read))
    assertTrue(startSize > log.size)
  }

  private def toMap(messages: Iterable[(Int, String, Long)]): Map[Int, (String, Long)] = {
    messages.map { case (key, value, offset) => key -> (value, offset) }.toMap
  }

  private def readFromLog(log: Log): Iterable[(Int, String, Long)] = {
    import JavaConverters._
    for (segment <- log.logSegments; deepLogEntry <- segment.log.records.asScala) yield {
      val key = TestUtils.readString(deepLogEntry.key).toInt
      val value = TestUtils.readString(deepLogEntry.value)
      (key, value, deepLogEntry.offset)
    }
  }

  private def writeDupsSingleMessageSet(numKeys: Int, numDups: Int, log: Log, codec: CompressionType,
                                        startKey: Int = 0, magicValue: Byte): Seq[(Int, String, Long)] = {
    val kvs = for (_ <- 0 until numDups; key <- startKey until (startKey + numKeys)) yield {
      val payload = counter.toString
      incCounter()
      (key, payload)
    }

    val records = kvs.map { case (key, payload) =>
      new SimpleRecord(key.toString.getBytes, payload.toString.getBytes)
    }

    val appendInfo = log.appendAsLeader(MemoryRecords.withRecords(magicValue, codec, records: _*), leaderEpoch = 0)
    val offsets = appendInfo.firstOffset.get to appendInfo.lastOffset

    kvs.zip(offsets).map { case (kv, offset) => (kv._1, kv._2, offset) }
  }

}

object LogCleanerParameterizedIntegrationTest {
  @Parameters
  def parameters: java.util.Collection[Array[String]] = {
    val list = new java.util.ArrayList[Array[String]]()
    for (codec <- CompressionType.values)
      list.add(Array(codec.name))
    list
  }
}


text:
import ast
import textwrap
from pprint import pformat

from ampy.pyboard import PyboardError

BUFFER_SIZE = 32  # Amount of data to read or write to the serial port at a time.
                  # This is kept small because small chips and USB to serial
                  # bridges usually have very small buffers.

class Files(object):
    """Class to interact with a MicroPython board files over a serial connection.
    Provides functions for listing, uploading, and downloading files from the
    board's filesystem.
    """

    def __init__(self, pyboard):
        """Initialize the MicroPython board files class using the provided pyboard
        instance.  In most cases you should create a Pyboard instance (from
        pyboard.py) which connects to a board over a serial connection and pass
        it in, but you can pass in other objects for testing, etc.
        """
        self._pyboard = pyboard

    def get(self, filename):
        """Retrieve the contents of the specified file and return its contents
        as a byte string.
        """
        # Open the file and read it a few bytes at a time and print out the
        # raw bytes.  Be careful not to overload the UART buffer so only write
        # a few bytes at a time, and don't use print since it adds newlines and
        # expects string data.
        command = """
            import sys
            with open('{0}', 'rb') as infile:
                while True:
                    result = infile.read({1})
                    if result == b'':
                        break
                    len = sys.stdout.write(result)
        """.format(filename, BUFFER_SIZE)
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            # Check if this is an OSError #2, i.e. file doesn't exist and
            # rethrow it as something more descriptive.
            if ex.args[2].decode('utf-8').find('OSError: [Errno 2] ENOENT') != -1:
                raise RuntimeError('No such file: {0}'.format(filename))
            else:
                raise ex
        self._pyboard.exit_raw_repl()
        return out

    def ls(self, directory='/'):
        """List the contents of the specified directory (or root if none is
        specified).  Returns a list of strings with the names of files in the
        specified directory.
        """
        # Execute os.listdir() command on the board.
        command = """
            import os
            print(os.listdir('{0}'))
        """.format(directory)
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            # Check if this is an OSError #2, i.e. directory doesn't exist and
            # rethrow it as something more descriptive.
            if ex.args[2].decode('utf-8').find('OSError: [Errno 2] ENOENT') != -1:
                raise RuntimeError('No such directory: {0}'.format(directory))
            else:
                raise ex
        self._pyboard.exit_raw_repl()
        # Parse the result list and return it.
        return ast.literal_eval(out.decode('utf-8'))

    def mkdir(self, directory):
        """Create the specified directory.  Note this cannot create a recursive
        hierarchy of directories, instead each one should be created separately.
        """
        # Execute os.mkdir command on the board.
        command = """
            import os
            os.mkdir('{0}')
        """.format(directory)
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            # Check if this is an OSError #17, i.e. directory already exists.
            if ex.args[2].decode('utf-8').find('OSError: [Errno 17] EEXIST') != -1:
                raise RuntimeError('Directory already exists: {0}'.format(directory))
            else:
                raise ex
        self._pyboard.exit_raw_repl()

    def put(self, filename, data):
        """Create or update the specified file with the provided data.
        """
        # Open the file for writing on the board and write chunks of data.
        self._pyboard.enter_raw_repl()
        self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
        size = len(data)
        # Loop through and write a buffer size chunk of data at a time.
        for i in range(0, size, BUFFER_SIZE):
            chunk_size = min(BUFFER_SIZE, size-i)
            chunk = repr(data[i:i+chunk_size])
            # Make sure to send explicit byte strings (handles python 2 compatibility).
            if not chunk.startswith('b'):
                chunk = 'b' + chunk
            self._pyboard.exec_("f.write({0})".format(chunk))
        self._pyboard.exec_('f.close()')
        self._pyboard.exit_raw_repl()

    def rm(self, filename):
        """Remove the specified file or directory."""
        command = """
            import os
            os.remove('{0}')
        """.format(filename)
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            message = ex.args[2].decode('utf-8')
            # Check if this is an OSError #2, i.e. file/directory doesn't exist
            # and rethrow it as something more descriptive.
            if message.find('OSError: [Errno 2] ENOENT') != -1:
                raise RuntimeError('No such file/directory: {0}'.format(filename))
            # Check for OSError #13, the directory isn't empty.
            if message.find('OSError: [Errno 13] EACCES') != -1:
                raise RuntimeError('Directory is not empty: {0}'.format(filename))
            else:
                raise ex
        self._pyboard.exit_raw_repl()

    def run(self, filename, wait_output=True, run_arguments=[]):
        """Run the provided script and return its output.  If wait_output is True
        (default) then wait for the script to finish and then print its output,
        otherwise just run the script and don't wait for any output.
        """
        self._pyboard.enter_raw_repl()
        if len(run_arguments) > 0:
            argexec = "import sys\n"
            argexec += "sys.argv.append("+pformat(filename)+")\n"
            for arg in run_arguments:
                argQuoted = pformat(str(arg))
                argexec += "sys.argv.append("+argQuoted+")\n"
            self._pyboard.exec_raw_no_follow(argexec)
        out = None
        if wait_output:
            # Run the file and wait for output to return.
            out = self._pyboard.execfile(filename)
        else:
            # Read the file and run it using lower level pyboard functions that
            # won't wait for it to finish or return output.
            with open(filename, 'rb') as infile:
                self._pyboard.exec_raw_no_follow(infile.read())
        self._pyboard.exit_raw_repl()
        return out


text:
<!DOCTYPE html>

        <meta charset="utf-8">
        <title>Leaflet Vector Layers - Jason Sanford</title>
        <meta name="description" content="Display vector data from ArcGIS Server, GeoIQ, Geocommons, Arc2Earth, CartoDB and others in a Leaflet map">
        <meta name="author" content="Jason Sanford">

        <link href="../docs-demo/css/bootstrap.css" rel="stylesheet">
        <link href="../docs-demo/css/prettify.css" rel="stylesheet">
        <link href="../docs-demo/css/docs.css" rel="stylesheet">
        <link href="../docs-demo/css/demo.css" rel="stylesheet">

                    Leaflet Vector Layers

Home

Documentation

                            Demos

ArcGIS Server

Arc2Earth

CartoDB

GeoIQ

PostGIS RESTful Web Service Framework

GIS Cloud

Tips + Tricks

Download

Classes

lvector.AGS

lvector.A2E

lvector.GeoIQ

lvector.CartoDB

lvector.PRWSF

lvector.GISCloud

Other Reference

Symbology Options

Popup Template

Dynamic Data

Classes

lvector.AGS ArcGIS Server

This class creates a layer that processes and displays features from an ArcGIS Server. You can also use this class to create a layer from any services that implement Esri's Geo REST specification, like Arc2Earth.

Usage Example

var myAGSLayer = new lvector.AGS({
    url: "http://maps.rtd-denver.com/ArcGIS/rest/services/BusLocations/MapServer/0",
    fields: "*",
    uniqueField: "OBJECTID",
    scaleRange: [13, 20],
    popupTemplate: "<h3>Bus #{BUS_NUMBER}</h3><p>Speed: {SPEED} mph</p>"
});

Constructor

Constructor	Description

lvector.AGS( <AGS options> options )	Instantiates an AGS layer with an object literal with AGS options described below.

Options

Option	Type	Default Value	Description

url	String	null	Required -  A url for a specific layer in an ArcGIS Server service.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or after a defined interval. For details check the dynamic data documentation.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated at an interval set by the autoUpdateInterval option. For details check the dynamic data documentation.

autoUpdateInterval	Integer	null	The interval (in milliseconds) between checks for updated feature geometry and attributes when the autoUpdate option is set to true. For details check the dynamic data documentation.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

fields	String	null	A list of comma separated fields to be returned with the features. For example "OBJECTID,OWNER_NAME" returns two fields and "*" returns all fields.

uniqueField	String	null	A field in the returned data that can be considered unique. This isn't required but is very helpful in determining which features are already on the map when the map extent changes.

Methods

Method	Description

setMap( <L.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

lvector.A2E Arc2Earth

This class creates a layer that processes and displays features from an Arc2Earth Sync instance.

Usage Example

var myA2ELayer = new lvector.A2E({
    url: "http://sync.arc2earth.com/6442491/ArcGIS/rest/services/tfs/2447544/FeatureServer/0",
    esriOptions: true,
    uniqueField: "global_fid",
    popupTemplate: '<div class="iw-content"><h3>{Name}</h3></div>',
    singlePopup: true,
    dynamic: true,
    autoUpdate: true
});

Constructor

Constructor	Description

lvector.A2E( <A2E options> options )	Instantiates an A2E layer with an object literal with A2E options described below.

Options

Option	Type	Default Value	Description

url	String	null	Required -  A url for a specific layer in an ArcGIS Server service.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or when a PubNub message is sent to the client.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated in near real-time by subscribing to PubNub events.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

fields	String	null	A list of comma separated fields to be returned with the features. For example "OBJECTID,OWNER_NAME" returns two fields and "*" returns all fields.

uniqueField	String	null	A field in the returned data that can be considered unique. This isn't required but is very helpful in determining which features are already on the map when the map extent changes.

esriOptions	Boolean	false	Whether or not to request scaleRange and symbology settings from the Arc2Earth Sync back-end. Layers loaded from ArcGIS Desktop into Arc2Earth Sync will retain scaleRange and symbology settings from ArcGIS Desktop.

Methods

Method	Description

setMap( <L.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

lvector.GeoIQ GeoIQ - Geocommons

This class creates a layer that processes and displays features from a GeoIQ dataset.

Usage Example

var myGeoIQLayer = new lvector.GeoIQ({
    dataset: 164880,
    uniqueField: "NAME",
    scaleRange: [6, 20],
    popupTemplate: '<div class="iw-content"><h3>{NAME}</h3></div>',
    singlePopup: true,
    symbology: {
        type: "single",
        vectorOptions: {
    	    icon: new customIcon({
                iconUrl: "../../docs-demo/img/markers/ski-lift.png"
            })
        }
    }
});

Constructor

Constructor	Description

lvector.GeoIQ( <GeoIQ options> options )	Instantiates a GeoIQ layer with an object literal with GeoIQ options described below.

Options

Option	Type	Default Value	Description

dataset	Number	null	Required -  A dataset id for a GeoIQ/Geocommons dataset.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or after a defined interval. For details check the dynamic data documentation.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated at an interval set by the autoUpdateInterval option. For details check the dynamic data documentation.

autoUpdateInterval	Integer	null	The interval (in milliseconds) between checks for updated feature geometry and attributes when the autoUpdate option is set to true. For details check the dynamic data documentation.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

uniqueField	String	null	A field in the returned data that can be considered unique. This isn't required but is very helpful in determining which features are already on the map when the map extent changes.

Methods

Method	Description

setMap( <L.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

lvector.CartoDB CartoDB

This class creates a layer that processes and displays features from a CartoDB table.

Usage Example

var myCartoDBLayer = new lvector.CartoDB({
    user: "geojason",
    table: "man_hole",
    scaleRange: [16, 20],
    symbology: {
        type: "single",
        vectorOptions: {
            icon: new customIcon({
                iconUrl: "../../docs-demo/img/markers/manhole.png"
            })
        }
    },
    popupTemplate: '<h3>Man Hole</h3<p>Depth: {mh_depth}</p>',
    singlePopup: true
});

Constructor

Constructor	Description

lvector.CartoDB( <CartoDB options> options )	Instantiates a CartoDB layer with an object literal with CartoDB options described below.

Options

Option	Type	Default Value	Description

user	String	null	Required -  The CartoDB user that owns the table to be displayed. For example a CartoDB map viewed via a URL like http://geojason.cartodb.com/map, "geojason" is the CartoDB user.

table	String	null	Required -  The CartoDB table name for the data to be displayed.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or after a defined interval. For details check the dynamic data documentation.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated at an interval set by the autoUpdateInterval option. For details check the dynamic data documentation.

autoUpdateInterval	Integer	null	The interval (in milliseconds) between checks for updated feature geometry and attributes when the autoUpdate option is set to true. For details check the dynamic data documentation.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

fields	String	"*"	A list of comma separated fields to be returned with the features. By default all fields are returned.

Methods

Method	Description

setMap( <L.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

lvector.PRWSF PostGIS RESTful Web Service Framework

This class creates a layer that processes and displays features from a PostGIS RESTful Web Service Framework geotable.

The PostGIS RESTful Web Service Framework is an open source project written in PHP that creates a set of web services that allow you to query geo data in a PostGIS database. These web services are extemely flexible allowing you to project, aggregate, order and serialize your data in many different ways. Below are some implementations I've found:

Union County GeoData API (A .Net port)

Mecklenburg County GeoPortal

Denver Regional Council of Governments

Usage Example

var myPrwsfLayer = new lvector.PRWSF({
    url: "http://gis.drcog.org/REST",
    geotable: "mountain_backdrop_preservation_area",
    fields: "gid",
    uniqueField: "gid",
    srid: 2232,
    showAll: true,
    symbology: {
        type: "single",
        vectorOptions: {
            fillColor: "#2f4a00",
            fillOpacity: 0.4,
            strokeWeight: 1.8,
            strokeColor: "#2f4a00",
            strokeOpacity: 1,
            clickable: false
        }
    }
});

Constructor

Constructor	Description

lvector.PRWSF( <PRWSF options> options )	Instantiates a PRWSF layer with an object literal with PRWSF options described below.

Options

Option	Type	Default Value	Description

url	String	null	Required -  The root URL for the PostGIS RESTful Web Service Framework instance.

geotable	String	null	Required -  The geotable for which we want data to be displayed.

fields	String	null	A list of comma separated fields to be returned with the features. By default only the geometry field is returned. You'd likely want to also return a unique id and some other attribute information.

geomFieldName	String	"the_geom"	The geometry field name for this geotable. Most commonly found as the_geom

srid	Integer	null	The SRID of the geometry in this geotable. This isn't required but increases performance drastically as the bounding box geometry can be projected to match your features' projection, which makes use of spatial indexes (that you've hopefully built).

where	String	null	Any additional SQL query(ies) to further filter the returned features.

limit	Integer	null	Limit the number of returned features.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or after a defined interval. For details check the dynamic data documentation.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated at an interval set by the autoUpdateInterval option. For details check the dynamic data documentation.

autoUpdateInterval	Integer	null	The interval (in milliseconds) between checks for updated feature geometry and attributes when the autoUpdate option is set to true. For details check the dynamic data documentation.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

Methods

Method	Description

setMap( <L.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

lvector.GISCloud GIS Cloud

This class creates a layer that processes and displays features from a GIS Cloud map layer.

Usage Example

var myGisCloudLayer = new lvector.GISCloud({
    mapID: 27322,
    layerID: 117755,
    symbology: {
        type: "single",
        vectorOptions: {
            weight: 4,
            color: "#46461f",
            opacity: 0.8
        }
    },
    scaleRange: [13, 18]
});

Constructor

Constructor	Description

lvector.GISCloud( <GISCloud options> options )	Instantiates a GISCloud layer with an object literal with GISCloud options described below.

Options

Option	Type	Default Value	Description

mapID	String|Number	null	Required -  The GIS Cloud Map ID where your layer can be found.

layerID	String|Number	null	Required -  The GIS Cloud Layer ID for your layer.

where	String	null	Any additional SQL query(ies) to further filter the returned features.

map	Object L.Map object	null	The Leaflet Map object where the layer will be added. The layer can be added to the map later with the setMap method.

scaleRange	Array	null	An array with two number values that represent the minimum and maximum scales the layer is visible. For example: [14, 17]

dynamic	Boolean	false	Whether or not the layer contains dynamic data. If true, feature geometry and attributes will be checked for changes after extent change and/or after a defined interval. For details check the dynamic data documentation.

autoUpdate	Boolean	false	Whether or not to auto-update a dynamic layer. If true, feature geometry and attributes will be updated at an interval set by the autoUpdateInterval option. For details check the dynamic data documentation.

autoUpdateInterval	Integer	null	The interval (in milliseconds) between checks for updated feature geometry and attributes when the autoUpdate option is set to true. For details check the dynamic data documentation.

popupTemplate	String|Function	null	A template for creating the content of a Leaflet Popup when a feature is clicked. For details check the Popup Template documentation.

singlePopup	Boolean	false	Whether or not to show a single Popup for a layer when features are clicked. This keeps the map from getting cluttered when multiple features are clicked.

popupOptions	Object Leaflet Popup options	null	Controls the width of and the presence of a close button for the Popup and whether the map should be panned when the Popup is opened.

symbology	Object symbology options	null	The symbology options for the layer. Features can be rendered with a single symbology or can also be symbolized based on an attribute using unique values or a value range. For details check the symbology options documentation.

showAll	Boolean	false	If true, all features will be fetched and shown once, not after a map extent change. This is helpful for layers with only a handful of features.

Methods

Method	Description

setMap( <google.maps.Map> Map )	Adds the layer to a map. Remove the layer by passing null.

getMap()	Gets the map (if any) that the layer has been added to.

Other Reference

Symbology

Symbology for a layer can be defined a few different ways including single, unique and range. If no symbology is defined the default Leaflet vector styles will be used.

When instantiating a new layer, use one of the options below when setting the symbology option value.

single

The single type displays all features with the same symbology.

{
    type: "single", // Defines the symbology as a single type of representation for all features
    vectorOptions: { // Leaflet Path options for all features
        fillColor: "#46461f",
        fillOpacity: 0.5,
        weight: 4,
        color: "#ff7800"
    }
}

unique

The unique type displays features with the same attibute values with the same symbology. This is helpful when you have a handful of discrete values for which you want to define symbology.

Check the districts example on the ArcGIS Server demo page and view source to see it in action.

{
    type: "unique", // Defines the symbology as a unique type where features with an attribute of a specific value are symbolized the same way
    property: "DISTRICT", // The property (field, attribute) to use for defining unique values and styles
    values: [ // An array of values to set symbology. Each value has a specific symbology
        {
            value: "A", // If feature.properties.DISTRICT == "A"
            vectorOptions: { // Use these Leaflet Path options for features matching
                fillColor: "#6600FF",
                fillOpacity: 0.6,
                color: "#666666",
                opacity: 0.8,
                weight: 1
            }
        },
        {
            value: "B",
            vectorOptions: {
                fillColor: "#660066",
                fillOpacity: 0.6,
                color: "#666666",
                opacity: 0.8,
                weight: 1
            }
        },
        {
            value: "C",
            vectorOptions: {
                fillColor: "#FF9900",
                fillOpacity: 0.6,
                color: "#666666",
                opacity: 0.8,
                weight: 1
            }
        }
    ]
}

range

The range type tests values to see if they are within a specified range and symbolizes them accordingly. This is helpful for datasets that have values with lots of individual values like population counts per county in the US or in this example, vehicle speeds.

{
    type: "range", // Defines the symbology as a range type where values above a minimum and below a maximum value are symbolized the same way
    property: "SPEED", // The property (field, attribute) to use for defining range values and styles
    ranges: [ // An array of value ranges to set symbology. Each value range has a specific symbology.
        {
            range: [1, 20], // if feature.properties.SPEED >= 1 AND feature.properties.SPEED <= 20
            vectorOptions: { // Use these Leaflet Path options for features with values in this range
                icon: new customIcon({
                    iconUrl: "../../docs-demo/img/markers/bus-brown.png"
                })
            }
        },{
            range: [21, 100],
            vectorOptions: {
                icon: new customIcon({
                    iconUrl: "../../docs-demo/img/markers/bus-green.png"
                })
            }
        }
    ]
}

Popup Templates

To create content to show Popups when features are clicked we can use the popupTemplate option. a popupTemplate can be set two ways:

A string with property names wrapped in curly brackets ({road_name}) to act as placeholders for the values

A function that returns a string that will be used as the Popup content. This function is passed the feature properties so that these properties can be used any number of ways to create Popup content. You could do things like create a chart with Google's Chart API or format ALL CAPS text to Proper Case.

String Based

A simple popupTemplate might look like:

"<h3>{road_name}</h3><p>Speed Limit: {speed_limit} mph</p>"

which gets transformed to:

"<h3>S Bemis St</h3><p>Speed Limit: 25 mph</p>"

Function Based

For more flexibility we can use a function to do some more complex operations with our feature properties for customized output. A function for a popupTemplate might look like:

function(properties) {
    /* Assuming "properties" is an object like:
    {
        ROAD_NAME: "S Bemis St",
        SPEED_LIMIT: 25
    }
    */

    var output = "<h3>State Road</h3>";

    for (var prop in properties) {
        output += prop.replace(/_/gi, " ").replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}) + ": " + properties[prop] + "<br />";
    }
    return output;
}

This function iterates through each property in properties and formats each to Proper Case for better looking output.

"<h3>State Road</h3>Road Name: S Bemis St<br />Speed Limit: 25<br />"

Dynamic Data

To create a dynamic layer simply set the dynamic option to true. Using this option alone (without autoUpdate and autoUpdateInterval) will check for feature geometry and property changes when the map extent changes. If geometry changes are found the feature is altered on the map. If properties changes are found any Popups associated with this feature are updated to reflect this change.

Auto-update

Using the autoUpdate and autoUpdateInterval options we can set a layer to automatically fetch new features every x seconds, even when the map extent hasn't changed. Set the autoUpdate option to true and autoUpdateInterval to the amount of time (in milliseconds) for how often you want features fetched. To create a dynamic layer that auto-updates every 5 seconds you might create your layer like:

var myAGSLayer = new lvector.AGS({
    url: "http://maps.rtd-denver.com/ArcGIS/rest/services/BusLocations/MapServer/0",
    fields: "*",
    uniqueField: "OBJECTID",
    dynamic: true,
    autoUpdate: true,
    autoUpdateInterval: 5000
});

Arc2Earth

Auto-updating works slightly different with Arc2Earth layers. Since update messages are almost immediately sent to the client using PubNub, only the dynamic and autoUpdate parameters must be set (both to true). This eliminates the need for constant polling, thus reducing the load on the server.

An auto-updating Arc2Earth layer might look something like:

myA2ELayer = new lvector.A2E({
    url: "http://sync.arc2earth.com/6442491/ArcGIS/rest/services/tfs/2447544/FeatureServer/0",
    esriOptions: true,
    uniqueField: "global_fid",
    popupTemplate: '<div class="iw-content"><h3>{Name}</h3></div>',
    singlePopup: true,
    dynamic: true,
    autoUpdate: true
});

© Jason Sanford - geojason.info 2012


text:
Boar
====

Convenient classes and extension methods for C#.
Especially for Gaming.

IDictionary extentions
----
* GetOrDefault(key, defaultValue/getter)
* GetOrAdd(key, value/getter)
* GetOrIncrease(key, increment)
* GetOrDecrease(key, decrement)

int/long extentions
----
* Between(min, max)
* Clamp(min, max)

Random extentions for array
----
* Pick([offset], [count])
* PickN(n)
* Suffle()

RandomByWeight
----
Round-table implementation.


text:
<?php

namespace BlueDB\Entity;

abstract class StrongAssociativeEntity extends StrongEntity implements IAssociativeEntity
{
	use AssociativeEntityTrait;
}


text:
@interface AWRuntimeHelper : NSObject

+ (void)aw_printCallStackWithCount:(NSUInteger)count;

@end


text:
define([
	"jquery", "underscore", "backbone"
			, "text!templates/popover/popover-main.html"
			, "text!templates/popover/popover-input.html"
			, "text!templates/popover/popover-select.html"
			, "text!templates/popover/popover-textarea.html"
			, "text!templates/popover/popover-textarea-split.html"
			, "text!templates/popover/popover-checkbox.html"
			, "templates/snippet/snippet-templates"
			, "bootstrap"
], function(
		$, _, Backbone
		, _PopoverMain
		, _PopoverInput
		, _PopoverSelect
		, _PopoverTextArea
		, _PopoverTextAreaSplit
		, _PopoverCheckbox
		, _snippetTemplates
		) {
	return Backbone.View.extend({
		tagName: "div"
		, className: function()
		{
			return "component";
		}
		, initialize: function() {
			this.template = _.template(_snippetTemplates[this.model.idFriendlyTitle()])

			var className = this.model.get("className");
			this.className = (className !== null) ?
					className :
					"component";

			this.popoverTemplates = {
				"input": _.template(_PopoverInput)
				, "select": _.template(_PopoverSelect)
				, "textarea": _.template(_PopoverTextArea)
				, "textarea-split": _.template(_PopoverTextAreaSplit)
				, "checkbox": _.template(_PopoverCheckbox)
			}
		}
		, render: function(withAttributes) {
			var that = this;
			var className = this.model.get("className");
			this.className = (className !== null) ?
					className :
					"component";
			var content = _.template(_PopoverMain)({
				"title": that.model.get("title"),
				"items": that.model.get("fields"),
				"popoverTemplates": that.popoverTemplates
			});
			if (withAttributes) {
				return this.$el.html(
						that.template(that.model.getValues())
						).attr({
					"class": this.className
					, "data-content": content
                    , "data-placement": "bottom"
					, "data-title": that.model.get("title")
					, "data-trigger": "manual"
					, "data-html": true
				});
			} else {
				return this.$el.html(
						that.template(that.model.getValues())
						)
			}
		}
	});
});


text:
package org.jbpm.services.task.commands;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.kie.api.task.model.TaskSummary;
import org.kie.internal.command.Context;

@XmlRootElement(name = "get-task-assigned-by-groups-command")
@XmlAccessorType(XmlAccessType.NONE)
public class GetTaskAssignedByGroupsCommand extends TaskCommand<List<TaskSummary>> {

    private static final long serialVersionUID = 6296898155907765061L;

    public GetTaskAssignedByGroupsCommand() {
    }

    public GetTaskAssignedByGroupsCommand(List<String> groupIds) {
        this.groupIds = groupIds;
    }

    public List<TaskSummary> execute(Context cntxt) {
        TaskContext context = (TaskContext) cntxt;
        return context.getTaskQueryService().getTasksAssignedByGroups(groupIds);
    }

}


text:
package by.bsuir.verpav.misoi.clustering.steps

import java.awt.image.BufferedImage
import javax.swing.{JFrame, JOptionPane}

import by.bsuir.verpav.misoi.util.ImageUtils

/**
  * Created by Pavel_Verkhovtsov on 10/5/16.
  */
object BrightnessCorrection extends ClusteringStep {

  override def perform(baseImage: BufferedImage): BufferedImage = {
    val isUseCorrection = params.getOrElse("isUseCorrection", 1)
    if (isUseCorrection == 1) {
      val colors = ImageUtils.extractColors(baseImage)
      val red = colors.map(_._1)
      val redMin = red.min
      val redMax = red.max
      val green = colors.map(_._2)
      val greenMin = green.min
      val greenMax = green.max
      val blue = colors.map(_._3)
      val blueMin = blue.min
      val blueMax = blue.max

      def newPixelValue(pixel: Int, max: Int, min: Int) = ((pixel - min).toDouble / (max - min).toDouble * 255).toInt

      ImageUtils.binaryImageTransformation(baseImage,
        (r: Int, g: Int, b: Int) => true,
        (r: Int, g: Int, b: Int) => Array(newPixelValue(r, redMax, redMin), newPixelValue(g, greenMax, greenMin), newPixelValue(b, blueMax, blueMin)),
        (r: Int, g: Int, b: Int) => Array(0, 0, 0))
    }
    else
      baseImage
  }

  override def requestParameters(frame: JFrame): Unit = {
    val isUseCorrection = JOptionPane.showInputDialog(frame, "Use correction 0 or 1: ")
    params.put("isUseCorrection", isUseCorrection.toInt)
  }
}


text:
package org.trustedanalytics.cfbroker.config;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.IOUtils;
import org.apache.commons.net.util.Base64;
import org.apache.hadoop.conf.Configuration;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import com.google.common.collect.ImmutableMap;

public final class HadoopZipConfiguration implements HadoopConfiguration {

  private final String encodedZip;

  private final Map<String, String> configParams;

  private HadoopZipConfiguration(String encodedZip) throws IOException {
    this.encodedZip = encodedZip;
    try {
      this.configParams = getAsMap();
    } catch (XPathExpressionException e) {
      throw new ConfigurationException("Zip configuration corrupted", e);
    }
  }

  public static HadoopZipConfiguration createHadoopZipConfiguration(String encodedZip) throws IOException {
    return new HadoopZipConfiguration(encodedZip);
  }

  @Override
  public Configuration getAsHadoopConfiguration() {
    Configuration configuration = new Configuration();
    configParams.entrySet().forEach(pair -> configuration.set(pair.getKey(), pair.getValue()));
    return configuration;
  }

  @Override
  public ImmutableMap getBrokerCredentials() {
    return ImmutableMap.of(ConfigConstants.HADOOP_CONFIG_KEY_VALUE, ImmutableMap.copyOf(configParams),
        ConfigConstants.HADOOP_CONFIG_ZIP_VALUE, ImmutableMap.of(ConfigConstants.DESCRIPTION_KEY,
            ConfigConstants.DESCRIPTION, ConfigConstants.ZIP, encodedZip));
  }

  @Override
  public Map<String, String> getAsParameterMap() {
    return configParams;
  }

  private Map<String, String> getAsMap() throws IOException, XPathExpressionException {
    InputStream zipInputStream =
        new ZipInputStream(new ByteArrayInputStream(Base64.decodeBase64(encodedZip)));
    ZipEntry zipFileEntry;
    Map<String, String> map = new HashMap<>();
    while ((zipFileEntry = ((ZipInputStream) zipInputStream).getNextEntry()) != null) {
      if (!zipFileEntry.getName().endsWith("-site.xml")) {
        continue;
      }
      byte[] bytes = IOUtils.toByteArray(zipInputStream);
      InputSource is = new InputSource(new ByteArrayInputStream(bytes));
      XPath xPath = XPathFactory.newInstance().newXPath();
      NodeList nodeList =
          (NodeList) xPath
              .evaluate(ConfigConstants.CONF_PROPERTY_XPATH, is, XPathConstants.NODESET);
      for (int i = 0; i < nodeList.getLength(); i++) {
        Node propNode = nodeList.item(i);
        String key = (String) xPath.evaluate("name/text()", propNode, XPathConstants.STRING);
        String value = (String) xPath.evaluate("value/text()", propNode, XPathConstants.STRING);
        map.put(key, value);
      }
    }
    return map;
  }

}


text:
s.Controls = function(options) {
  // Store references to game objects
  this.game = options.game;
  this.player = options.player;

  // Hook to the gameloop
  this.update = this.update.bind(this);
  this.game.hook(this.update);

  // Choose control method
  var hasTouch = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch;
  this.controlMethod = hasTouch ? 'touch' : 'keyboard';

  // Create interpreters for controllers
  this.keyboard = new s.Controls.Keyboard();

  if (hasTouch) {
    this.touch = new s.Controls.Touch();
  }
};

s.Controls.prototype.destruct = function() {
  this.game.unhook(this.update);
};

s.Controls.prototype.update = function(time, delta) {
  if (!this.ship) {
    return;
  }

  // Calculate the difference between the ideal framerate and the actual framerate
  // This is used to avoid sluggish controls on slow devices
  var frameRateFactor = (delta/1000) / (1/60);

  var root = this.ship.root;
  var body = this.ship.body;

  var pitch = 0;
  var roll = 0;
  var yaw = 0;

  var thrust = 0;

  var changeViewMode = false;
  var fire = false;
  var showBackCam = false;

  // Control method
  if (this.controlMethod === 'touch') {
    pitch = this.touch.pitch;
    roll = this.touch.roll;
    yaw = this.touch.yaw;
    thrust = this.touch.thrust;
    fire = this.touch.fire;
    changeViewMode = this.touch.changeViewMode;
  }
  else if (this.controlMethod === 'keyboard') {
    // Update keyboard before polling
    this.keyboard.update();

    pitch = this.keyboard.pitch;
    roll = this.keyboard.roll;
    yaw = this.keyboard.yaw;
    thrust = this.keyboard.thrust;
    fire = this.keyboard.fire;
    changeViewMode = this.keyboard.changeViewMode;
    showBackCam = this.keyboard.showBackCam;
  }

  // Calculate thrust impulse based on direction
  var thrustImpulse = 0;
  if (thrust > 0) {
    thrustImpulse = thrust * s.constants.ship.forwardThrust;
  }
  else if (thrust < 0) {
    thrustImpulse = thrust * s.constants.ship.backwardThrust;
  }

  // Expose thrust impulse for visuals
  this.ship.thrustImpulse = thrustImpulse;

  // A scalar used to control rate of turn based on thrust
  var thrustScalar = Math.abs(thrustImpulse)/s.constants.ship.forwardThrust + 1;

  // Apply speeds to values so ship behaves the same for each control type
  // Apply thrustScalar so the ship turns slower when under thrust
  // Apply frameRateFactor so control is still fast at lower framerates
  pitch = frameRateFactor * pitch * s.constants.ship.pitchSpeed / thrustScalar;
  roll = frameRateFactor * roll * s.constants.ship.rollSpeed / thrustScalar;
  yaw = frameRateFactor * yaw * s.constants.ship.yawSpeed / thrustScalar;

  // Apply values to physics simulation
  var angularVelocity = body.angularVelocity;
  var rotationMatrix = new THREE.Matrix4();
  rotationMatrix.extractRotation(root.matrix);

  // Add to the existing angular velocity,
  var newAngularVelocity = new THREE.Vector3(pitch, yaw, roll).applyMatrix4(rotationMatrix).add(angularVelocity);
  body.angularVelocity.set(newAngularVelocity.x, newAngularVelocity.y, newAngularVelocity.z);

  var forceVector = new THREE.Vector3(0, 0, thrustImpulse * this.ship.engineImpulse).applyMatrix4(rotationMatrix);
  var cannonVector = new CANNON.Vec3(forceVector.x, forceVector.y, forceVector.z);
  body.applyImpulse(cannonVector, body.position);

  // Tell the player to perform actions
  if (fire) {
    // this.emit('fire');
    this.ship.fire();
  }

  if (showBackCam) {
    // @todo animate along top
    // Show cam from behind
    // this.emit('lookBack');
    this.player.setCameraViewMode('front');
  }
  else if (changeViewMode) {
    // this.emit('cycleCameraViewMode');
    this.player.cycleCameraViewMode();
  }
  else {
    // this.emit('restoreViewMode');
    this.player.restoreViewMode();
  }
};


text:
package no.nordicsemi.puckcentral.actuators;

import android.app.AlertDialog;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

import org.droidparts.activity.Activity;
import org.json.JSONException;
import org.json.JSONObject;

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

import no.nordicsemi.puckcentral.R;
import no.nordicsemi.puckcentral.bluetooth.gatt.GattOperationBundle;
import no.nordicsemi.puckcentral.bluetooth.gatt.operations.GattCharacteristicWriteOperation;
import no.nordicsemi.puckcentral.bluetooth.gatt.operations.GattDisconnectOperation;
import no.nordicsemi.puckcentral.models.Action;
import no.nordicsemi.puckcentral.models.Puck;
import no.nordicsemi.puckcentral.models.Rule;
import no.nordicsemi.puckcentral.services.GattServices;
import no.nordicsemi.puckcentral.utils.UUIDUtils;

public class IRActuator extends PuckActuator {

    public static final String ARGUMENT_CODE = "code";

    public static final String CODE = "Remote control code";
    public static final UUID CHARACTERISTIC_COMMAND_UUID = UUIDUtils.stringToUUID("bftj ir command ");
    public static final UUID CHARACTERISTIC_DATA_UUID = UUIDUtils.stringToUUID("bftj ir data    ");
    public static final UUID CHARACTERISTIC_PERIOD_UUID = UUIDUtils.stringToUUID("bftj ir period  ");

    private static final byte COMMAND_BEGIN_CODE_TRANSMISSION = 0;
    private static final byte COMMAND_END_CODE_TRANSMISSION = 1;

    @Override
    public String describeActuator() {
        return "IR Actuator";
    }

    @Override
    public String describeArguments(JSONObject arguments) {
        try {
            return "Sends an IR signal to " + arguments.getString(ARGUMENT_UUID) + ":" + arguments.getString(ARGUMENT_MAJOR) + ":" + arguments.getString(ARGUMENT_MINOR);
        } catch (JSONException e) {
            e.printStackTrace();
            return "Invalid arguments for actuator";
        }
    }

    @Override
    public int getId() {
        return 3;
    }

    @Override
    public AlertDialog getActuatorDialog(Activity activity, final Action action, final Rule rule, final ActuatorDialogFinishListener listener) {
        LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View view = layoutInflater.inflate(R.layout.dialog_actuator_single_select_single_textinput, null);
        final EditText editText1 = (EditText) view.findViewById(R.id.etDialogActuatorEditText1);
        editText1.setHint(CODE);

        final List<Puck> irPucks = mPuckManager.withServiceUUID(GattServices.IR_SERVICE_UUID);

        final Spinner spinner = (Spinner) view.findViewById(R.id.spinner1);
        List<String> irPuckNames = new ArrayList<>();
        for (Puck irPuck : irPucks) {
            irPuckNames.add(irPuck.getName());
        }

        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(activity,
                android.R.layout.simple_spinner_item, irPuckNames);
        spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinnerAdapter);

        AlertDialog.Builder builder = new AlertDialog.Builder(activity)
                .setView(view)
                .setTitle(describeActuator())
                .setPositiveButton(activity.getString(R.string.accept), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        int idx = spinner.getSelectedItemPosition();
                        Puck puck = irPucks.get(idx);

                        String arguments = Action.jsonStringBuilder(
                                IRActuator.ARGUMENT_UUID, puck.getProximityUUID(),
                                IRActuator.ARGUMENT_MAJOR, puck.getMajor(),
                                IRActuator.ARGUMENT_MINOR, puck.getMinor(),
                                IRActuator.ARGUMENT_CODE, editText1.getText().toString());

                        action.setArguments(arguments);
                        rule.addAction(action);
                        listener.onActuatorDialogFinish(action, rule);
                    }
                })
                .setNegativeButton(activity.getString(R.string.reject), null);
        return builder.create();
    }

    @Override
    public void actuateOnPuck(BluetoothDevice device, JSONObject arguments) throws JSONException {
        GattOperationBundle bundle = new GattOperationBundle();
        bundle.addOperation(new GattCharacteristicWriteOperation(
                device,
                GattServices.IR_SERVICE_UUID,
                CHARACTERISTIC_PERIOD_UUID,
                new byte[]{ 26 } ));
        bundle.addOperation(new GattCharacteristicWriteOperation(
                device,
                GattServices.IR_SERVICE_UUID,
                CHARACTERISTIC_COMMAND_UUID,
                new byte[] { COMMAND_BEGIN_CODE_TRANSMISSION }));

        int ON = 1260;
        int E = 420;
        int ZE = 420;
        int RO = 1260;
        int PAU = 0;
        int SE = 20 * 1680;

        int source[] = new int[] {
                ON,E,    ON,E,    ON,E,    ON,E,
                ZE,RO,   ZE,RO,   ZE,RO,   ZE,RO,
                ZE,RO,   ON,E,    ZE,RO,   ZE,RO,

                PAU,SE,

                ON,E,    ON,E,    ON,E,    ON,E,
                ZE,RO,   ZE,RO,   ZE,RO,   ZE,RO,
                ZE,RO,   ON,E,    ZE,RO,   ZE,RO
        };

        assert(source.length % 10 == 0);

        byte array[] = new byte[20];
        for(int i = 0; i < source.length; i++) {
            array[(i % 10) * 2] = (byte) ((source[i] & 0xFF00) >> 8);
            array[(i % 10) * 2 + 1] = (byte) (source[i] & 0xFF);
            if(i % 10 == 9) {
                bundle.addOperation(new GattCharacteristicWriteOperation(device,
                        GattServices.IR_SERVICE_UUID,
                        CHARACTERISTIC_DATA_UUID, array));
                array = new byte[20];
            }
        }
        bundle.addOperation(new GattCharacteristicWriteOperation(device,
                GattServices.IR_SERVICE_UUID,
                CHARACTERISTIC_COMMAND_UUID,
                new byte[] { COMMAND_END_CODE_TRANSMISSION }));
        bundle.addOperation(new GattDisconnectOperation(device));
        mGattManager.queue(bundle);
    }
}


text:
import {describe, it} from 'mocha'

describe('computedRectangle', function () {
  // Replace this with your real tests.
  it('works', function () {
    // let result = computedRectangle()
    // expect(result).to.be.ok
  })
})


text:
package leaktest

import (
	"context"
	"fmt"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"time"
)

type goroutine struct {
	id    uint64
	stack string
}

type goroutineByID []*goroutine

func (g goroutineByID) Len() int           { return len(g) }
func (g goroutineByID) Less(i, j int) bool { return g[i].id < g[j].id }
func (g goroutineByID) Swap(i, j int)      { g[i], g[j] = g[j], g[i] }

func interestingGoroutine(g string) (*goroutine, error) {
	sl := strings.SplitN(g, "\n", 2)
	if len(sl) != 2 {
		return nil, fmt.Errorf("error parsing stack: %q", g)
	}
	stack := strings.TrimSpace(sl[1])
	if strings.HasPrefix(stack, "testing.RunTests") {
		return nil, nil
	}

	if stack == "" ||
		// Ignore HTTP keep alives
		strings.Contains(stack, ").readLoop(") ||
		strings.Contains(stack, ").writeLoop(") ||
		// Below are the stacks ignored by the upstream leaktest code.
		strings.Contains(stack, "testing.Main(") ||
		strings.Contains(stack, "testing.(*T).Run(") ||
		strings.Contains(stack, "runtime.goexit") ||
		strings.Contains(stack, "created by runtime.gc") ||
		strings.Contains(stack, "interestingGoroutines") ||
		strings.Contains(stack, "runtime.MHeap_Scavenger") ||
		strings.Contains(stack, "signal.signal_recv") ||
		strings.Contains(stack, "sigterm.handler") ||
		strings.Contains(stack, "runtime_mcall") ||
		strings.Contains(stack, "goroutine in C code") {
		return nil, nil
	}

	// Parse the goroutine's ID from the header line.
	h := strings.SplitN(sl[0], " ", 3)
	if len(h) < 3 {
		return nil, fmt.Errorf("error parsing stack header: %q", sl[0])
	}
	id, err := strconv.ParseUint(h[1], 10, 64)
	if err != nil {
		return nil, fmt.Errorf("error parsing goroutine id: %s", err)
	}

	return &goroutine{id: id, stack: strings.TrimSpace(g)}, nil
}

// interestingGoroutines returns all goroutines we care about for the purpose
// of leak checking. It excludes testing or runtime ones.
func interestingGoroutines(t ErrorReporter) []*goroutine {
	buf := make([]byte, 2<<20)
	buf = buf[:runtime.Stack(buf, true)]
	var gs []*goroutine
	for _, g := range strings.Split(string(buf), "\n\n") {
		gr, err := interestingGoroutine(g)
		if err != nil {
			t.Errorf("leaktest: %s", err)
			continue
		} else if gr == nil {
			continue
		}
		gs = append(gs, gr)
	}
	sort.Sort(goroutineByID(gs))
	return gs
}

// ErrorReporter is a tiny subset of a testing.TB to make testing not such a
// massive pain
type ErrorReporter interface {
	Errorf(format string, args ...interface{})
}

// Check snapshots the currently-running goroutines and returns a
// function to be run at the end of tests to see whether any
// goroutines leaked, waiting up to 5 seconds in error conditions
func Check(t ErrorReporter) func() {
	return CheckTimeout(t, 5*time.Second)
}

// CheckTimeout is the same as Check, but with a configurable timeout
func CheckTimeout(t ErrorReporter, dur time.Duration) func() {
	ctx, cancel := context.WithCancel(context.Background())
	fn := CheckContext(ctx, t)
	return func() {
		timer := time.AfterFunc(dur, cancel)
		fn()
		// Remember to clean up the timer and context
		timer.Stop()
		cancel()
	}
}

// CheckContext is the same as Check, but uses a context.Context for
// cancellation and timeout control
func CheckContext(ctx context.Context, t ErrorReporter) func() {
	orig := map[uint64]bool{}
	for _, g := range interestingGoroutines(t) {
		orig[g.id] = true
	}
	return func() {
		var leaked []string
		for {
			select {
			case <-ctx.Done():
				t.Errorf("leaktest: timed out checking goroutines")
			default:
				leaked = make([]string, 0)
				for _, g := range interestingGoroutines(t) {
					if !orig[g.id] {
						leaked = append(leaked, g.stack)
					}
				}
				if len(leaked) == 0 {
					return
				}
				// don't spin needlessly
				time.Sleep(time.Millisecond * 50)
				continue
			}
			break
		}
		for _, g := range leaked {
			t.Errorf("leaktest: leaked goroutine: %v", g)
		}
	}
}


text:
<bill session="111" type="h" number="1451" updated="2009-03-12T12:05:13-04:00">
	<status><introduced date="1236744000" datetime="2009-03-11"/></status>

	<introduced date="1236744000" datetime="2009-03-11"/>
	<titles>
		<title type="official" as="introduced">To amend title 23, United States Code, to allow an exception for the weight limits for certain towing trucks.</title>
	</titles>
	<sponsor id="409888"/>
	<cosponsors>
		<cosponsor id="400047" joined="2009-03-11"/>
	</cosponsors>
	<actions>
		<action date="1236744000" datetime="2009-03-11"><text>Referred to the House Committee on Transportation and Infrastructure.</text></action>
	</actions>
	<committees>
		<committee name="House Transportation and Infrastructure" subcommittee="" activity="Referral, In Committee" />
	</committees>
	<relatedbills>

	</relatedbills>
	<subjects>

	</subjects>
	<amendments>

	</amendments>
	<summary>

	</summary>
</bill>