text:
using System;
using System.Collections.Generic;
using System.Text.Json;
using Azure;
using Azure.Core;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.SecurityInsights.Models;

namespace Azure.ResourceManager.SecurityInsights
{
    public partial class MetadataModelData : IUtf8JsonSerializable
    {
        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();
            if (Optional.IsDefined(ETag))
            {
                writer.WritePropertyName("etag");
                writer.WriteStringValue(ETag.Value.ToString());
            }
            writer.WritePropertyName("properties");
            writer.WriteStartObject();
            if (Optional.IsDefined(ContentId))
            {
                writer.WritePropertyName("contentId");
                writer.WriteStringValue(ContentId);
            }
            if (Optional.IsDefined(ParentId))
            {
                writer.WritePropertyName("parentId");
                writer.WriteStringValue(ParentId);
            }
            if (Optional.IsDefined(Version))
            {
                writer.WritePropertyName("version");
                writer.WriteStringValue(Version);
            }
            if (Optional.IsDefined(Kind))
            {
                writer.WritePropertyName("kind");
                writer.WriteStringValue(Kind.Value.ToString());
            }
            if (Optional.IsDefined(Source))
            {
                writer.WritePropertyName("source");
                writer.WriteObjectValue(Source);
            }
            if (Optional.IsDefined(Author))
            {
                writer.WritePropertyName("author");
                writer.WriteObjectValue(Author);
            }
            if (Optional.IsDefined(Support))
            {
                writer.WritePropertyName("support");
                writer.WriteObjectValue(Support);
            }
            if (Optional.IsDefined(Dependencies))
            {
                writer.WritePropertyName("dependencies");
                writer.WriteObjectValue(Dependencies);
            }
            if (Optional.IsDefined(Categories))
            {
                writer.WritePropertyName("categories");
                writer.WriteObjectValue(Categories);
            }
            if (Optional.IsCollectionDefined(Providers))
            {
                writer.WritePropertyName("providers");
                writer.WriteStartArray();
                foreach (var item in Providers)
                {
                    writer.WriteStringValue(item);
                }
                writer.WriteEndArray();
            }
            if (Optional.IsDefined(FirstPublishOn))
            {
                writer.WritePropertyName("firstPublishDate");
                writer.WriteStringValue(FirstPublishOn.Value, "D");
            }
            if (Optional.IsDefined(LastPublishOn))
            {
                writer.WritePropertyName("lastPublishDate");
                writer.WriteStringValue(LastPublishOn.Value, "D");
            }
            if (Optional.IsDefined(CustomVersion))
            {
                writer.WritePropertyName("customVersion");
                writer.WriteStringValue(CustomVersion);
            }
            if (Optional.IsDefined(ContentSchemaVersion))
            {
                writer.WritePropertyName("contentSchemaVersion");
                writer.WriteStringValue(ContentSchemaVersion);
            }
            if (Optional.IsDefined(Icon))
            {
                writer.WritePropertyName("icon");
                writer.WriteStringValue(Icon);
            }
            if (Optional.IsCollectionDefined(ThreatAnalysisTactics))
            {
                writer.WritePropertyName("threatAnalysisTactics");
                writer.WriteStartArray();
                foreach (var item in ThreatAnalysisTactics)
                {
                    writer.WriteStringValue(item);
                }
                writer.WriteEndArray();
            }
            if (Optional.IsCollectionDefined(ThreatAnalysisTechniques))
            {
                writer.WritePropertyName("threatAnalysisTechniques");
                writer.WriteStartArray();
                foreach (var item in ThreatAnalysisTechniques)
                {
                    writer.WriteStringValue(item);
                }
                writer.WriteEndArray();
            }
            if (Optional.IsCollectionDefined(PreviewImages))
            {
                writer.WritePropertyName("previewImages");
                writer.WriteStartArray();
                foreach (var item in PreviewImages)
                {
                    writer.WriteStringValue(item);
                }
                writer.WriteEndArray();
            }
            if (Optional.IsCollectionDefined(PreviewImagesDark))
            {
                writer.WritePropertyName("previewImagesDark");
                writer.WriteStartArray();
                foreach (var item in PreviewImagesDark)
                {
                    writer.WriteStringValue(item);
                }
                writer.WriteEndArray();
            }
            writer.WriteEndObject();
            writer.WriteEndObject();
        }

        internal static MetadataModelData DeserializeMetadataModelData(JsonElement element)
        {
            Optional<ETag> etag = default;
            ResourceIdentifier id = default;
            string name = default;
            ResourceType type = default;
            Optional<SystemData> systemData = default;
            Optional<string> contentId = default;
            Optional<string> parentId = default;
            Optional<string> version = default;
            Optional<SecurityInsightsKind> kind = default;
            Optional<MetadataSource> source = default;
            Optional<MetadataAuthor> author = default;
            Optional<MetadataSupport> support = default;
            Optional<MetadataDependencies> dependencies = default;
            Optional<MetadataCategories> categories = default;
            Optional<IList<string>> providers = default;
            Optional<DateTimeOffset> firstPublishDate = default;
            Optional<DateTimeOffset> lastPublishDate = default;
            Optional<string> customVersion = default;
            Optional<string> contentSchemaVersion = default;
            Optional<string> icon = default;
            Optional<IList<string>> threatAnalysisTactics = default;
            Optional<IList<string>> threatAnalysisTechniques = default;
            Optional<IList<string>> previewImages = default;
            Optional<IList<string>> previewImagesDark = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("etag"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    etag = new ETag(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    systemData = JsonSerializer.Deserialize<SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("contentId"))
                        {
                            contentId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("parentId"))
                        {
                            parentId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("version"))
                        {
                            version = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("kind"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            kind = new SecurityInsightsKind(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("source"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            source = MetadataSource.DeserializeMetadataSource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("author"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            author = MetadataAuthor.DeserializeMetadataAuthor(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("support"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            support = MetadataSupport.DeserializeMetadataSupport(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("dependencies"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            dependencies = MetadataDependencies.DeserializeMetadataDependencies(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("categories"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            categories = MetadataCategories.DeserializeMetadataCategories(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("providers"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List<string> array = new List<string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            providers = array;
                            continue;
                        }
                        if (property0.NameEquals("firstPublishDate"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            firstPublishDate = property0.Value.GetDateTimeOffset("D");
                            continue;
                        }
                        if (property0.NameEquals("lastPublishDate"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastPublishDate = property0.Value.GetDateTimeOffset("D");
                            continue;
                        }
                        if (property0.NameEquals("customVersion"))
                        {
                            customVersion = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("contentSchemaVersion"))
                        {
                            contentSchemaVersion = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("icon"))
                        {
                            icon = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("threatAnalysisTactics"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List<string> array = new List<string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            threatAnalysisTactics = array;
                            continue;
                        }
                        if (property0.NameEquals("threatAnalysisTechniques"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List<string> array = new List<string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            threatAnalysisTechniques = array;
                            continue;
                        }
                        if (property0.NameEquals("previewImages"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List<string> array = new List<string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            previewImages = array;
                            continue;
                        }
                        if (property0.NameEquals("previewImagesDark"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List<string> array = new List<string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            previewImagesDark = array;
                            continue;
                        }
                    }
                    continue;
                }
            }
            return new MetadataModelData(id, name, type, systemData.Value, contentId.Value, parentId.Value, version.Value, Optional.ToNullable(kind), source.Value, author.Value, support.Value, dependencies.Value, categories.Value, Optional.ToList(providers), Optional.ToNullable(firstPublishDate), Optional.ToNullable(lastPublishDate), customVersion.Value, contentSchemaVersion.Value, icon.Value, Optional.ToList(threatAnalysisTactics), Optional.ToList(threatAnalysisTechniques), Optional.ToList(previewImages), Optional.ToList(previewImagesDark), Optional.ToNullable(etag));
        }
    }
}


text:
#ifndef SKY_ENGINE_PUBLIC_WEB_SKY_H_
#define SKY_ENGINE_PUBLIC_WEB_SKY_H_

#include "../platform/Platform.h"

namespace blink {

// Must be called on the thread that will be the main WebKit thread before
// using any other WebKit APIs. The provided Platform; must be
// non-null and must remain valid until the current thread calls shutdown.
BLINK_EXPORT void initialize(Platform*);

// Once shutdown, the Platform passed to initialize will no longer
// be accessed. No other WebKit objects should be in use when this function is
// called. Any background threads created by WebKit are promised to be
// terminated by the time this function returns.
BLINK_EXPORT void shutdown();

} // namespace blink

#endif  // SKY_ENGINE_PUBLIC_WEB_SKY_H_

redpajama_set_name: RedPajamaGithub


text:
namespace stk {
namespace mesh {

////////////////////// INTERNAL ////////////////////

class Watch
{
 public:
  virtual ~Watch() {}
  virtual const std::type_info& type() const = 0;
  virtual bool match(const void* item_) const = 0;
  virtual void* item() = 0;
};

std::vector<Watch*>& watch_vector();

template <typename T>
bool internal_is_watching(const T& item)
{
  for (std::vector<Watch*>::const_iterator
       itr = watch_vector().begin(); itr != watch_vector().end(); ++itr) {
    if ((*itr)->type() == typeid(T) &&
        (*itr)->match(&item)) {
      return true;
    }
  }
  return false;
}

template <typename T>
class WatchClass : public Watch
{
 public:
  WatchClass(const T& watch_item) : m_watch_item(watch_item),
                                    m_type_info(&typeid(T)) {
    watch_vector().push_back(this);
  }

  virtual const std::type_info& type() const { return *m_type_info; }

  virtual bool match(const void* item_) const {
    return *(static_cast<const T*>(item_)) == m_watch_item;
  }

  virtual void* item() { return &m_watch_item; }

 private:
  T m_watch_item;
  const std::type_info* m_type_info;
};

/////////////////// API /////////////////////////

template <typename T>
void watch(const T& watch_item)
{
  // leaks, but who cares
  new WatchClass<T>(watch_item);
}

#ifdef STK_MESH_TRACE_ENABLED

#define Trace_(location) stk::mesh::Trace trace__(location)

#define TraceIf(location, mask) stk::mesh::Trace trace__(location, mask)

#define TraceIfWatching(location, mask, item) \
stk::mesh::Trace trace__(location, mask, stk::mesh::internal_is_watching(item)); \
DiagIfWatching(mask, item, "Watched item is: " << item << stk::diag::dendl)

// Useful if you need two traces in the same scope, dec is used to modify the
// name of the trace object to avoid conflicting.
#define TraceIfWatchingDec(location, mask, item, dec) \
stk::mesh::Trace trace##dec__(location, mask, stk::mesh::internal_is_watching(item)); \
DiagIfWatching(mask, item, "Watched item is: " << item << stk::diag::dendl)

#define DiagIfWatching(mask, item, message)                             \
meshlog.w(stk::mesh::internal_is_watching(item), mask) << message << stk::diag::dendl

#define DiagIf(mask, message)                   \
meshlog.m(mask) << message << stk::diag::dendl

/////////////////////////////////////////////////

#else

#define Trace_(location)                              ((void) (0))
#define TraceIf(location, mask)                       ((void) (0))
#define TraceIfWatching(location, mask, item)         ((void) (0))
#define TraceIfWatchingDec(location, mask, item, dec) ((void) (0))
#define DiagIf(mask, message)                         ((void) (0))
#define DiagIfWatching(mask, item, message)           ((void) (0))

#endif

} // namespace mesh
} // namespace stk

#endif


text:
"""
author : wanghe
company: LogInsight
email_ : wangh@loginsight.cn
file: constants.py
time   : 16/4/19 下午8:06
"""
import os

MODULE_ROOT = os.path.dirname(__import__('wangblog').__file__)


text:
Core Concepts of Spatial Information - Haskell
==============================================

Abstract: Specifications and implementation of the core concepts in Haskell.

See the [Readme](../README.md) in the parent directory for general information about the Core Concepts.

Currently, the implementation is in a proof of concept state and should not be considered stable for a production environment.

Contents
----------------------

- `Event.hs`: Specifications of events.
- `Field.hs`: Specifications of fields.
- `Location.hs`: Specifications of locations.
- `Makefile`: Common commands for unix platforms.
- `NetworkExamples.hs`: Examples for networks.
- `Network.hs`: Specifications of networks.
- `NetworkImpl.hs`: Implementations of networks.
- `Object.hs`: Specifications of objects.

How to test the code and run the examples
-----------------------------------------

### Unix/Linux platforms
To run the Unit Tests execute: `make test-all`

To run the examples execute: `make example-all`

Dependencies
----------------------
- [FGL](https://hackage.haskell.org/package/fgl) (Version: latest*)

\* Most recent stable release on package

### Unix/Linux platforms
To install the dependencies execute: `make install-dependencies`


text:
require 'formula'

class Unac < Formula
  homepage 'http://savannah.nongnu.org/projects/unac'
  url 'http://ftp.de.debian.org/debian/pool/main/u/unac/unac_1.8.0.orig.tar.gz'
  sha1 '3e779bb7f3b505880ac4f43b48ee2f935ef8aa36'

  depends_on 'autoconf' => :build
  depends_on 'automake' => :build
  depends_on 'libtool' => :build
  depends_on 'gettext' => :build

  patch :DATA

  patch :p0 do
    url "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340"
    sha1 "5b273127609b98092b8f3bb1b4c3e9f137968151"
  end

  patch :p0 do
    url "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=10;filename=patch-unaccent.c.txt;att=1;bug=623340"
    sha1 "689a1f32cdf08e3dab04bef1605666e4288ae64e"
  end

  patch do
    url "http://ftp.de.debian.org/debian/pool/main/u/unac/unac_1.8.0-6.diff.gz"
    sha1 "ed44c7dd2a093a970be51f19dfd1da396b08797e"
  end

  def install
    chmod 0755, "configure"
    touch "config.rpath"
    inreplace "autogen.sh", "libtool", "glibtool"
    system "./autogen.sh"
    system "./configure", "--disable-dependency-tracking",
                          "--prefix=#{prefix}"

    # Separate steps to prevent race condition in folder creation
    system "make"
    ENV.j1
    system "make install"
  end

  test do
    assert_equal "foo", shell_output("#{bin}/unaccent utf-8 fóó").strip
  end
end

# configure.ac doesn't properly detect Mac OS's iconv library. This patch fixes that.
__END__
diff --git a/configure.ac b/configure.ac
index 4a4eab6..9f25d50 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,7 @@ AM_MAINTAINER_MODE

 AM_ICONV

+LIBS="$LIBS -liconv"
 AC_CHECK_FUNCS(iconv_open,,AC_MSG_ERROR([
 iconv_open not found try to install replacement from
 http://www.gnu.org/software/libiconv/


text:
package org.apache.eagle.security.userprofile.job

import org.apache.commons.math3.linear.{Array2DRowRealMatrix, RealMatrix}
import org.apache.eagle.security.userprofile.UserProfileConstants
import org.apache.eagle.security.userprofile.model.AuditLogTransformer
import org.apache.spark.storage.StorageLevel
import org.apache.spark.{Logging, SparkConf, SparkContext}
import org.joda.time.Period

import scala.collection.mutable

/**
 * Audit Log UserProfileTrainingJob Implementation
 *
 * @param site site
 * @param input input path
 * @param master  spark master
 * @param appName spark application name
 * @param cmdTypes command features
 * @param period model aggregation granularity
 */
case class AuditLogTrainingSparkJob(
    site:String = null,
    var input:String=null,
    master:String="local[4]",
    appName:String=UserProfileConstants.DEFAULT_TRAINING_APP_NAME,
    cmdTypes:Seq[String] = UserProfileConstants.DEFAULT_CMD_TYPES,
    period:Period = Period.parse("PT1m")
  ) extends UserProfileTrainingJob with Logging {
  import org.apache.eagle.security.userprofile.job.AuditlogTrainingSparkJobFuncs._

  val conf = new SparkConf().setMaster(master).setAppName(appName)
  val sc = new SparkContext(conf)

  override def run(){
    logInfo(s"Starting $appName")
    buildDAG(sc)
    logInfo(s"Stopping $appName")
    sc.stop()
    logInfo(s"Finished $appName")
  }

  /**
   * Build Spark DAG
   *
   * @param sc
   */
  private def buildDAG(sc:SparkContext): Unit = {
    if (input == null) throw new IllegalArgumentException("input is null")

    val _site = site
    val _sc = sc
    val _cmdTypes = cmdTypes
    val _modelers = modelers
    val _modelSinks = modelSinks
    val _aggSinks = aggSinks

    val _period = period
    val tmp = _sc.textFile(input)
      .map(AuditLogTransformer(_period).transform)
      .filter(e => e.isDefined)
      .map(e => {((e.get.user,e.get.periodWindowSeconds,e.get.cmd),1.toDouble) }) // [(user,period,cmd),count]

    val _aggRDD = tmp
      .reduceByKey(_ + _)                                           // [(user,period,cmd),totalCount]
      .map(kv => {((kv._1._1, kv._1._2), (kv._1._3, kv._2))})       // [(user,period),(cmd,totalCount)]
      .groupByKey()
      .map(asUserCmdCountArray(_cmdTypes))                          // [(user,(period,array))]
      .sortBy(asUserPeriod, ascending = true)
      .groupByKey()
      .map(asMatrix)

    if (_modelers.size > 1 || _aggSinks.size > 1) _aggRDD.persist(StorageLevel.MEMORY_ONLY)

    _aggSinks.foreach(sink =>{
      sink.persist(_aggRDD,_cmdTypes,_site)
    })

    val modelRDDS = _modelers.map(
      modeler => {
        (_aggRDD.flatMap(v => {
          val _modeler = modeler
          _modeler.build(_site,v._1, v._2)
        }), modeler.context())
    })

    if(_modelSinks.size > 1) modelRDDS.foreach(_._1.cache())

    modelRDDS.foreach(kv => {
      _modelSinks.foreach(sink => {
        sink.persist(kv._1, kv._2)
      })
    })
  }

  def input(path:String):AuditLogTrainingSparkJob = {
    this.input = path
    this
  }
}

private object AuditlogTrainingSparkJobFuncs extends Logging{
  /**
   * From: [(user,period),(cmd,count)]
   *
   * To: [(user), (period,"getfileinfo", "open", "listStatus", "setTimes", "setPermission", "rename", "mkdirs", "create", "setReplication", "contentSummary", "delete", "setOwner", "fsck")]
   *
   * @param keyValue
   * @return
   */
  def asUserCmdCountArray(cmdTypes:Seq[String])(keyValue:(((String,Long),Iterable[(String,Double)])))={
    // make sure instance variables are always in local for closure
    val key = keyValue._1
    val it = keyValue._2
    var cmdCount = Map[String, Double]()
    it.foreach(k => {
      cmdCount += (k._1 -> k._2)
    })
    var cmdCounts = mutable.MutableList[Double]()
    cmdTypes.foreach(_cmdType => {
      cmdCounts += cmdCount.getOrElse[Double](_cmdType, 0.0)
    })
    val cmdCountsInDouble:Array[Double] = cmdCounts.toArray
    (key._1,(key._2,cmdCountsInDouble))
  }

  /**
   * @param pair
   * @return (user,matrix)
   */
  def asMatrix(pair:(String,Iterable[(Long,Array[Double])]))={
    val data = new mutable.MutableList[Array[Double]]
    pair._2.foreach(v => data += v._2)
    val matrix:RealMatrix = new Array2DRowRealMatrix(data.toArray)
    (pair._1,matrix)
  }

  def asUserPeriod(param:(String,(Long,Array[Double]))) ={
    (param._1, param._2._1)
  }
}


text:
package tud.time4maps.json;

import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
import tud.time4maps.objects.JsonContainer;

/**
 * This class creates JSON object from maps. The structure for the JSON object is defined by the class JsonContainer, but can also be set by the structure of a map.
 * @see JsonContainer
 *
 * @author Christin Henzen, Daniel Kadner. Professorship of Geoinformation Systems
 *
 */
public class JsonObjectBuilder {

	public static Object buildLayer(Map<String, Object> allData, String type) {
		ObjectMapper mapper = new ObjectMapper();
		if (type.equalsIgnoreCase("string")) { //building json string
			try {
				return mapper.writeValueAsString(allData);
			} catch (Exception e) { e.printStackTrace(); }
		} else if (type.equalsIgnoreCase("jsoncontainer")) { //building object
			return mapper.convertValue(allData, JsonContainer.class);
		}

		return null;

		// testing fileWriter .. from map to json-file
		// mapper.writeValue(new File("json_test_file"), allData);
	}
}


text:
// API/controllers/types.js

/**
* @apiDefine TypeObjectPostParam
*
* @apiParam {String} name Name of the Type
* @apiParam {String} [category] Category of the Type
*/

/**
* @apiDefine TypeObjectPutParam
*
* @apiParam {String} [name] Name of the Type
* @apiParam {String} [category] Category of the Type
*/

/**
* @apiDefine TypeObjectSuccess
*
* @apiSuccess {String} _id Id of the Type
* @apiSuccess  {String} name Name of the Type
* @apiSuccess  {String} [category] Category of the Type
*/

/**
* @apiDefine TypeRequestJSON
*
* @apiParamExample {json} Request-Example:
*     {
*       "name": "Loukoums",
*       "category": "Desserts"
*     }
*/

var Types = require('../models/types');

/*
** POSTS
*/

/**
* @api {post} /types/ Create a new Type
* @apiName postType
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiUse TypeObjectPostParam
*
* @apiUse TypeRequestJSON
*
* @apiSuccess message Type succesfully created!
*
* @apiSuccessExample Success-Response
*     HTTP/1.1 200 OK
*	  {
*		"message" : "Type succesfully created!"
*	  }
*
* @apiErrorExample Bad Value Definition
*	  HTTP/1.1 400 BAD REQUEST
*	  {
*		...
*		mongoose custom error
*		...
*	  }
*
*/
exports.postType = function (req, res) {
	//binds the new type
	var type = new Types({
		name : req.body.name,
		category : req.body.category
	});

	//saves the type to the db
	 type.save(function (err) {
        if (err)
        	return (res.status(400).send(err));

        return (res.json({message: 'Type succesfully created!'}));
    });
};

/*
** GETS
*/

/**
* @apiDefine getTypeAnswer
*
* @apiSuccessExample Success-Response:
*     HTTP/1.1 200 OK
*     {
*		"_id" : "561830c5fecdba4f72668fe8",
*       "name": "Loukoums",
*       "category": "Desserts"
*     }
*/

/**
* @api {get} /types/ Request all the Types
* @apiName getAllTypes
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiUse TypeObjectSuccess
*
* @apiUse getTypeAnswer
*
* @apiError message There are no existing types.
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "There are no existing types."
*     }
*/

exports.getAllTypes = function(req, res) {
	Types.find({},
		function(err, docs) {
			if (err)
				return (res.send(err));
			else if (docs.length <= 0)
				return (res.status(404).json({message : 'There are no existing types.'}))
			return (res.json(docs));
		}
	);
	return (1);
};

/**
* @api {get} /types/id/:id Request Type informations by id
* @apiName getTypeById
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiParam {Number} id Types unique ID
*
* @apiUse TypeObjectSuccess
*
* @apiUse getTypeAnswer
*
* @apiError message The id of the Type was not found
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "The id was not found."
*     }
*/
exports.getTypeById = function (req, res, flag) {
	var id = flag === true ? req.body.id : req.params.id;
	if (!id)
		return flag === true ? -1 : res.status(400).json({message : 'The id musn\'t be null'});
	Types.findById(id,
		function (err, doc) {
			if (err)
				return (res.send(err));
			else if (doc === null)
				return (res.status(404).json({message : 'The id was not found.'}))
			return (res.json(doc));
		}
	);
	return (1);
};

/**
* @api {get} /types/name/:name Request Type informations by name
* @apiName getTypeByName
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiParam {String} name Type partial or full name
*
* @apiUse TypeObjectSuccess
*
* @apiUse getTypeAnswer
*
* @apiError message The name of the type was not found
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "The name was not found."
*     }
*/
exports.getTypesByName = function (req, res, flag) {
	var name = flag === true ? req.body.name : req.params.name;
	if (!name)
		return flag === true ? -1 : res.json(400, {message : 'The name musn\'t be null'});
	Types.find({
		"name": { "$regex": name, "$options": "i" }
		},
		function (err, docs) {
			if (err)
				return (res.send(err));
			else if (docs.length <= 0)
				return (res.status(404).json({message : 'The name was not found.'}))
			return (res.json(docs));
		}
	);
	return (1);
};

/*
** DELETES
*/

/**
* @apiDefine deleteTypeSuccess
* @apiSuccess message Type succesfully deleted!
* @apiSuccessExample Success-Response:
*     HTTP/1.1 200 OK
*	  {
*		"message" : "Type succesfully deleted!"
*	  }
*/

/**
* @api {delete} /types/ Delete Types (JSON)
* @apiName deleteTypes
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiParam {Number} [id] Type unique ID
* @apiParam {Sting} [name] Type full name
*
* @apiParamExample {json} Request-Example:
*	  {
*		"id" : "56183b64753d867e016c80d2"
*	  }
*
* @apiUse deleteTypeSuccess
*
* @apiError message The id was not found.
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "The id was not found."
*     }
*/
exports.deleteTypes = function (req, res) {
	var i = -1;
	var callbackReturn = -1;
	var functionPointer = [module.exports.deleteTypeById(req, res, true),
							module.exports.deleteTypeByName(req, res, true)];
	var usage = "No correct argument given. Specify an id or a name";

	while ((callbackReturn = functionPointer[++i]) == -1
		&& i < functionPointer.length - 1);
	return callbackReturn == -1 ? res.json({message : usage}) : callbackReturn;

};

/**
* @api {delete} /types/id/:id Delete Type by id
* @apiName deleteTypeById
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiParam {Number} id Type unique ID
*
* @apiUse deleteTypeSuccess
*
* @apiError message The id was not found.
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "The id was not found."
*     }
*/
exports.deleteTypeById = function (req, res, flag) {
	var id = flag === true ? req.body.id : req.params.id;
	if (!id)
		return flag === true ? -1 : res.json(400, {message : 'The id musn\'t be null'});
	Types.remove({
		_id : id
		},
		function (err, removed) {
			if (err)
				return (res.send(err));
			else if (removed.result.n === 0)
				return (res.status(404).json({message : 'The id was not found.'}))
			return (res.json({message : 'Type succesfully deleted!'}));
		}
	);
	return (1);
};

/**
* @api {delete} /types/name/:name Delete Type by name
* @apiName deleteTypeByName
* @apiGroup Types
* @apiVersion 0.1.0
*
* @apiParam {String} name Type full name
*
* @apiUse deleteTypeSuccess
*
* @apiError message The name was not found.
* @apiErrorExample Invalid Parameter Value
*     HTTP/1.1 404 Not Found
*     {
*       "message": "The name was not found."
*     }
*/
exports.deleteTypeByName = function (req, res, flag) {
	var name = flag === true ? req.body.name : req.params.name;
	if (!name)
		return flag === true ? -1 : res.json(400, {message : 'The name musn\'t be null'});
	Types.remove({
		name : name
		},
		function (err, removed) {
			if (err)
				return (res.send(err));
			else if (removed.result.n === 0)
				return (res.status(404).json({message : 'The name was not found.'}))
			return (res.json({message : 'Type succesfully deleted!'}));
		}
	);
	return (1);
};


text:
package net.uchoice.exf.core.expression.ognl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;

public class OgnlExpression {

	private OgnlContext context;

	public OgnlExpression() {
		this(null);
	}

	public OgnlExpression(Map<String, Object> context) {
		this.context = new OgnlContext(context);
	}

	public Object evaluate(String expression) throws OgnlException {
		return Ognl.getValue(expression, this.context, new Object());
	}

	@SuppressWarnings("unchecked")
	public <T> T evaluate(String expression, Class<T> cls) throws OgnlException {
		return (T) Ognl.getValue(expression, this.context, new Object(), cls);
	}

	public static void main(String[] args) throws OgnlException {
		Map<String, Object> context = new HashMap<String, Object>();

		Person person1 = new Person();
		person1.setName("zhangsan");

		Person person2 = new Person();
		person2.setName("lisi");

		Person person3 = new Person();
		person3.setName("wangwu");

		Person person4 = new Person();
		person4.setName("zhaoliu");

		List<Person> persons = new ArrayList<>();
		persons.add(person1);
		persons.add(person2);
		persons.add(person3);
		persons.add(person4);

		context.put("person1", person1);
		context.put("person2_p", person2);
		context.put("person3", person3);
		context.put("persons", persons);

		Object value = Ognl.getValue("name", context, person2);
		System.out.println("ognl expression \"name\" evaluation is : " + value);

		Object value2 = Ognl.getValue("#person2_p.name", context, person2);
		System.out.println("ognl expression \"#person2.name\" evaluation is : " + value2);

		Object value4 = Ognl.getValue("name", context, person4);
		System.out.println("ognl expression \"name\" evaluation is : " + value4);

		Object value5 = Ognl.getValue("#persons.size() == 4 && (1>2 || 4 in {1,2,3,#persons.size()})", context,
				new Object());
		System.out.println("ognl expression \"name\" evaluation is : " + value5);
	}
}

class Person {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}


text:
require 'test_helper'

class RheinlandPfalzLandtagScraperDetailTest < ActiveSupport::TestCase
  def setup
    @scraper = RheinlandPfalzLandtagScraper
  end

  test 'extract complete paper of legislative_term 17' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_17.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '17',
        full_reference: '17/435',
        reference: '435',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Einstellungssituation an Gymnasien und Gesamtschulen zum neuen Schuljahr 2016/2017 im Westerwaldkreis',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/435-17.pdf',
        published_at: Date.parse('13.07.2016'),
        originators: { people: ['Ralf Seekatz', 'Gabriele Wieland'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium für Bildung'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D17+AND+DART%3DD+AND+DNR%2CKORD%3D435'
      }, paper)
  end

  test 'extract complete paper of legislative_term 16' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/4608',
        reference: '4608',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Grundversorgung mit leistungsfähigem Breitband im Wahlkreis 29',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/4608-16.pdf',
        published_at: Date.parse('13.02.2015'),
        originators: { people: ['Dorothea Schäfer'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium des Innern, für Sport und Infrastruktur'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D4608'
      }, paper)
  end

  test 'extract paper with different originators in interpellations and answer like in 17/439' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_17_439.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '17',
        full_reference: '17/439',
        reference: '439',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Einsatz von Streifenbeamten gegen potenzielle Terroristen',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/439-17.pdf',
        published_at: Date.parse('13.07.2016'),
        originators: { people: ['Matthias Lammert', 'Adolf Kessel'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium des Innern und für Sport'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D17+AND+DART%3DD+AND+DNR%2CKORD%3D439'
      }, paper)
  end

  test 'extract paper with additional link like in 16/4097' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16_4097.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/4097',
        reference: '4097',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Laufende Beihilfeverfahren/Antwort der Landesregierung',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/4097-16.pdf',
        published_at: Date.parse('14.10.2014'),
        originators: { people: ['Alexander Licht'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium des Innern, für Sport und Infrastruktur'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D4097'
      }, paper)
  end

  test 'extract paper with multiple ministries like in 16/3813' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16_3813.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/3813',
        reference: '3813',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Erstes rheinland-pfälzisches Green Hospital entsteht in Meisenheim',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/3813-16.pdf',
        published_at: Date.parse('25.07.2014'),
        originators: { people: ['Ulrich Steinbach', 'Andreas Hartenfels'], parties: ['BÜNDNIS 90/DIE GRÜNEN'] },
        is_answer: true,
        answerers: { ministries: [
          'Ministerium für Wirtschaft, Klimaschutz, Energie und Landesplanung',
          'Ministerium für Soziales, Arbeit, Gesundheit und Demografie'
        ] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D3813'
      }, paper)
  end

  test 'extract paper without party like 16/863' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16_863.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/863',
        reference: '863',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Mehrfache Verschiebung der Mediation zur Geothermie',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/863-16.pdf',
        published_at: Date.parse('07.02.2012'),
        originators: { people: ['Martin Brandl'], parties: [] },
        is_answer: true,
        answerers: { ministries: [
          'Ministerium für Wirtschaft, Klimaschutz, Energie und Landesplanung'
        ] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D863'
      }, paper)
  end

  test 'extract paper with two meta_rows like 16/1734' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16_1734.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/1734',
        reference: '1734',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Aktive Stadt- und Ortsteilzentren. Das Zentrenprogramm der Städtebauförderung',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/1734-16.pdf',
        published_at: Date.parse('24.10.2012'),
        originators: { people: ['Michael Billen'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: [
          'Ministerium des Innern, für Sport und Infrastruktur'
        ] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D1734'
      }, paper)
  end

  test 'extract paper with ministry staatskanzlei like 16/4965' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/detail_16_4965.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/4965',
        reference: '4965',
        doctype: Paper::DOCTYPE_MINOR_INTERPELLATION,
        title: 'Umgang der Ministerpräsidentin mit Kritik zu den Abläufen rund um den Nürburgring',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/4965-16.pdf',
        published_at: Date.parse('2015-04-30'),
        originators: { people: ['Alexander Licht'], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: [
          'Staatskanzlei'
        ] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D4965'
      }, paper)
  end

  test 'extract complete paper from Major' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/major_detail.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/4788',
        reference: '4788',
        doctype: Paper::DOCTYPE_MAJOR_INTERPELLATION,
        title: 'Situation kinderreicher Familien in Rheinland-Pfalz',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/4788-16.pdf',
        published_at: Date.parse('20.03.2015'),
        originators: { people: [], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium für Integration, Familie, Kinder, Jugend und Frauen'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D4788'
      }, paper)
  end

  test 'extract complete paper from Major with more information and links' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/major_detail_16_4503.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/4503',
        reference: '4503',
        doctype: Paper::DOCTYPE_MAJOR_INTERPELLATION,
        title: 'Sterben in Würde',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/4503-16.pdf',
        published_at: Date.parse('21.01.2015'),
        originators: { people: [], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium für Soziales, Arbeit, Gesundheit und Demografie'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D4503'
      }, paper)
  end

  test 'extract complete paper from Major with an additional answer' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/major_detail_16_579.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/579',
        reference: '579',
        doctype: Paper::DOCTYPE_MAJOR_INTERPELLATION,
        title: 'Prüfung vergaberechtlicher sowie weiterer rechtlicher Fragestellungen im Rahmen der Verträge zur Umsetzung des Zukunftskonzeptes Nürburgring',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/579-16.pdf',
        published_at: Date.parse('16.11.2011'),
        originators: { people: [], parties: ['CDU'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium des Innern, für Sport und Infrastruktur'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D579'
      }, paper)
  end

  test 'extract complete major paper with multiple originator parties' do
    @html = Nokogiri::HTML(File.read(Rails.root.join('test/fixtures/rp/major_detail_16_2887.html')))
    record = @scraper.extract_records(@html).first
    paper = @scraper.extract_paper(record, check_pdf: false)

    assert_equal(
      {
        legislative_term: '16',
        full_reference: '16/2887',
        reference: '2887',
        doctype: Paper::DOCTYPE_MAJOR_INTERPELLATION,
        title: 'Bilanz und Perspektiven für die Weiterentwicklung des Bologna-Prozesses in Rheinland-Pfalz',
        url: 'http://www.landtag.rlp.de/landtag/drucksachen/2887-16.pdf',
        published_at: Date.parse('15.10.2013'),
        originators: { people: [], parties: ['SPD', 'BÜNDNIS 90/DIE GRÜNEN'] },
        is_answer: true,
        answerers: { ministries: ['Ministerium für Bildung, Wissenschaft, Weiterbildung und Kultur'] },
        source_url: 'http://opal.rlp.de/starweb/OPAL_extern/servlet.starweb?path=OPAL_extern/PDOKUFL.web&id=ltrpopalfastlink' +
          '&format=PDOKU_Vollanzeige_Report&search=WP%3D16+AND+DART%3DD+AND+DNR%2CKORD%3D2887'
      }, paper)
  end
end


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Test for http://bugs.webkit.org/show_bug.cgi?id=14329</title>
    <script src="resources/text-based-repaint.js" type="text/javascript"></script>
    <script>
        function repaintTest()
        {
            document.getElementById("z").focus();
        }
    </script>
</head>
<body onload="runRepaintTest();">
    <iframe id="z" src="resources/text-selection-rect-in-overflow-frame.html"></iframe>
</body>
</html>


text:
AbilityItemWindow
=================

### Parent: [Window](../WindowControls/Window.md)

------------------------------------------------------------------------

`Event`

AbilitySelected
---------------

### Params

-   **wndHandler** **([Window](../WindowControls/Window.md))** - The
    window that fires the event
-   **wndControl** **([Window](../WindowControls/Window.md))** - The
    window control with the event happened

------------------------------------------------------------------------

`Method`

GetAbilityDescription()
-----------------------

### Description

Does a lua\_pushwstring of the ability's description from the tool tip
id, or "" if the ability is not found.

------------------------------------------------------------------------

`Method`

GetAbilityId()
--------------

### Description

Does a lua\_pushinteger of the caller's m\_iSpellId.

------------------------------------------------------------------------

`Method`

GetAbilityName()
----------------

### Description

Does a lua\_pushwstring of the ability's name from the name id, or "" if
the ability is not found.

------------------------------------------------------------------------

`Method`

GetAbilityTierId()
------------------

------------------------------------------------------------------------

`Method`

SetAbilityId(nSpellId)
----------------------

### Description

Sets the caller's ability id to nSpellId.

### Params

-   **nSpellId** **(Integer)** - (Default value: -1)

------------------------------------------------------------------------

`Method`

SetSelected(bSelected)
----------------------

### Description

Sets the caller's m\_bSelected boolean to bSelected.

### Params

-   **bSelected** **(Boolean)**


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

<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
 "../../../frameworks/dita/DITA-OT/dtd/concept.dtd">
<concept id="lawnmowerconcept" xml:lang="en-us">
<title>Lawnmower</title>
<conbody>
The lawnmower is a machine used to cut grass in the yard. Lawnmowers can be
electric, gas-powered, or manual.
</conbody>
</concept>


text:
from __future__ import unicode_literals, print_function
from django.db import migrations

def forwards_func(apps, schema_editor):
    Lexeme = apps.get_model('lexicon', 'Lexeme')
    fields = ['phoneMic',
              'transliteration',
              'not_swadesh_term',
              'rfcWebLookup1',
              'rfcWebLookup2',
              'dubious']
    print('Copying JSON data to dedicated columns.')
    for l in Lexeme.objects.all():
        for f in fields:
            if f in l.data:
                setattr(l, f, l.data[f])
        l.save()

def reverse_func(apps, schema_editor):
    print('Nothing to do for reverse_func of 0069_lexeme_unjson')

class Migration(migrations.Migration):

    dependencies = [('lexicon', '0068_auto_20160510_1835')]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]


text:
<?php

if(!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") {
	exit();
}
else {
	$memberInfo = $member->get_info_filtered();
	$consoleObj->select($_GET['cID']);
	if(!$member->hasAccess($consoleObj)) {
		exit();
	}
}

if(!$gameObj->select($_GET['gID'])) {
	echo "

	";
	exit();
}

$gameInfo = $gameObj->get_info_filtered();

echo "

";

if($_POST['submit']) {

	// Check Game Name
	$checkGameName = trim($_POST['gamename']);
	if($checkGameName == "") {
		$countErrors++;
		$dispError .= "   · You may not enter a blank game name.
";
	}

	// Check Image Height

	if(!is_numeric($_POST['gameimageheight']) AND trim($_POST['gameimageheight']) != "") {
		$countErrors++;
		$dispError .="   · The Image Height must be a numeric value.
";
	}
	elseif(is_numeric($_POST['gameimageheight']) AND $_POST['gameimageheight'] <= 0) {
		$countErrors++;
		$dispError .= "   · The Image Height must be a value greater than 0.
";
	}

	if($_FILES['gameimagefile']['name'] == "" AND trim($_POST['gameimageurl']) == "" AND $gameObj->getLocalImageURL() === false AND (trim($_POST['gameimageheight']) == "" OR $_POST['gameimageheight'] <= 0)) {
		$countErrors++;
		$dispError .= "   · You must supply an image height for images that aren't uploaded.
";
	}

	// Check Image Width

	if(!is_numeric($_POST['gameimagewidth']) AND trim($_POST['gameimagewidth']) != "") {
		$countErrors++;
		$dispError .="   · The Image Width must be a numeric value.
";
	}
	elseif(is_numeric($_POST['gameimagewidth']) AND $_POST['gameimagewidth'] <= 0) {
		$countErrors++;
		$dispError .= "   · The Image Width must be a value greater than 0.
";
	}

	if($_FILES['gameimagefile']['name'] == "" AND trim($_POST['gameimageurl']) == "" AND $gameObj->getLocalImageURL() === false AND (trim($_POST['gameimagewidth']) == "" OR $_POST['gameimagewidth'] <= 0)) {
		$countErrors++;
		$dispError .= "   · You must supply an image width for images that aren't uploaded.
";
	}

	// Check Display Order

	$intGameOrderNum = $gameObj->validateOrder($_POST['gameorder'], $_POST['beforeafter'], true, $gameObj->get_info("ordernum"));

	if($intGameOrderNum === false) {
		$countErrors++;
		$dispError .= "   · You selected an invalid category order.
";
	}

	if($countErrors == 0) {
		// No Errors! Check game image, if it needs to be uploaded, try uploading.

		$gameImageURL = "";
		if($_FILES['gameimagefile']['name'] != "") {

			$btUploadObj = new BTUpload($_FILES['gameimagefile'], "game_", "../images/gamesplayed/", array(".jpg", ".png", ".bmp", ".gif"));

			if(!$btUploadObj->uploadFile()) {
				$countErrors++;
				$dispError .= "   · Unable to upload games image file.  Please make sure the file extension is either .jpg, .png, .gif or .bmp
";
			}
			else {
				$gameImageURL = "images/gamesplayed/".$btUploadObj->getUploadedFileName();
			}

		}
		elseif(trim($_POST['gameimageurl']) != "") {
			$gameImageURL = $_POST['gameimageurl'];
		}

	}

	// Check if there are still no errors after uploading image

	if($countErrors == 0) {
		$gameObj->select($gameInfo['gamesplayed_id']);

		// update column names
		$updateColumns = array("name", "imagewidth", "imageheight", "ordernum");

		// update column values
		$updateValues = array($_POST['gamename'], $_POST['gameimagewidth'], $_POST['gameimageheight'], $intGameOrderNum);

		// Check if need to update image
		if($gameImageURL != "") {
			$updateColumns[] = "imageurl";
			$updateValues[] = $gameImageURL;
		}

		if($gameObj->update($updateColumns, $updateValues)) {

			// Resort order if needed
			if($resortOrder) {
				$gameObj->resortOrder();
			}

			// Updated Game Info ---> now update game stats
			$gameInfo = $gameObj->get_info_filtered(); // Make sure we have the most up to date game info.

			$updateGameStatCol = array("name", "stattype", "calcop", "decimalspots", "ordernum", "hidestat", "gamesplayed_id", "textinput"); //,

			// First update/add name and stat type
			foreach($_SESSION['btStatCache'] as $key => $statInfo) {

				$updateGameStatsVal = array($statInfo['statName'], $statInfo['statType'], $statInfo['calcOperation'], $statInfo['rounding'], $key, $statInfo['hideStat'], $gameInfo['gamesplayed_id'], $statInfo['textInput']);

				if($statInfo['gamestatsID'] != "" AND $gameStatsObj->select($statInfo['gamestatsID'])) {
				// Updating already added stats
					$checkSave = $gameStatsObj->update($updateGameStatCol, $updateGameStatsVal);
				}
				else {
				// Adding new stats
					$checkSave = $gameStatsObj->addNew($updateGameStatCol, $updateGameStatsVal);
				}

				if($checkSave) {
					$arrSavedStats[] = $gameStatsObj->get_info_filtered();
				}
				else {
					$countErrors++;
					$dispError .= "  · ".filterText($statInfo['statName'])."
";
				}

			}

			// Now update other stat information
			$updateGameStatCol = array("firststat_id", "secondstat_id");

			/*
			 * 	1. Make sure that all of the game stats were successfully inserted into the db
			*   2. For each stat that was an auto-calculated stat, we need to update the firststat and secondstat IDs
			*   3. We can identify the correct $arrSavedStat index by accessing the stat order which is stored in
			*     $_SESSION[btStatCache][key][firstStat] and $_SESSION[btStatCache][key][secondStat]
			*/

			if($countErrors == 0) {
				foreach($arrSavedStats as $key => $statInfo) {
					if($statInfo['stattype'] == "calculate") {

						$intFirstStatOrder = $_SESSION['btStatCache'][$key]['firstStat'];
						$intFirstStatID = $arrSavedStats[$intFirstStatOrder]['gamestats_id'];

						$intSecondStatOrder = $_SESSION['btStatCache'][$key]['secondStat'];
						$intSecondStatID = $arrSavedStats[$intSecondStatOrder]['gamestats_id'];

						$arrValues = array($intFirstStatID, $intSecondStatID);

						$gameStatsObj->select($statInfo['gamestats_id']);
						$gameStatsObj->update($updateGameStatCol, $arrValues);
					}
				}
			}
			else {
				$showErrorMessage = "

However, the following stats were unable to be saved:

".$dispError;
			}

			//$newGameInfo = $gameObj->get_info_filtered();

			echo "

			Successfully Edited Game: ".$gameInfo['name']."!".$showErrorMessage."

			";

		}
		else {
			$dispError .= "   · Unable to save game information.  Please try again.
";
			$_POST['submit'] = false;
		}

	}
	else {
		$_POST['submit'] = false;
	}

}

if(!$_POST['submit']) {

	$localImageURL = $gameObj->getLocalImageURL();

	if($gameInfo['imagewidth'] == 0 AND $localImageURL !== false) {
		$gameImageSize = getimagesize($prevFolder.$localImageURL);

		$gameInfo['imagewidth'] = $gameImageSize[0];
	}

	if($gameInfo['imageheight'] == 0 AND $localImageURL !== false) {
		$gameImageSize = getimagesize($prevFolder.$localImageURL);

		$gameInfo['imageheight'] = $gameImageSize[1];
	}

	$popupWidth = $gameInfo['imagewidth']+50;
	echo "

	";

	echo "

	<form action='console.php?cID=".$cID."&gID=".$_GET['gID']."&action=edit' method='post' enctype='multipart/form-data'>

	";

	if($dispError != "") {
		echo "

		Unable to add new game because the following errors occurred:

		$dispError

		";
	}

	$afterSelected = "";
	$intGameBeforeAfter = "";

	$intNextGameOrder = $gameInfo['ordernum']-1;
	$result = $mysqli->query("SELECT * FROM ".$dbprefix."gamesplayed WHERE ordernum = '".$intNextGameOrder."'");
	if($result->num_rows == 1) {
		$beforeGameInfo = $result->fetch_assoc();
		$intGameBeforeAfter = $beforeGameInfo['gamesplayed_id'];
	}
	else {
		// Editing First Game Need to select "After" option
		$intGameAfter = $gameInfo['ordernum']+1;
		$result = $mysqli->query("SELECT * FROM ".$dbprefix."gamesplayed WHERE ordernum = '".$intGameAfter."'");
		if($result->num_rows == 1) {
			$afterGameInfo = $result->fetch_assoc();
			$intGameBeforeAfter = $afterGameInfo['gamesplayed_id'];
			$afterSelected = " selected";
		}
	}
	$counter = 0;

	$result = $mysqli->query("SELECT * FROM ".$dbprefix."gamesplayed WHERE gamesplayed_id != '".$gameInfo['gamesplayed_id']."' ORDER BY ordernum DESC");
	while($row = $result->fetch_assoc()) {
		$counter++;
		$gameName = filterText($row['name']);
		if($row['gamesplayed_id'] == $intGameBeforeAfter) {
			$gameOrderOptions .= "<option value='".$row['gamesplayed_id']."' selected>".$gameName."</option>";
		}
		else {
			$gameOrderOptions .= "<option value='".$row['gamesplayed_id']."'>".$gameName."</option>";
		}

	}

	if($counter == 0) {
		$gameOrderOptions = "<option value='first'>(no other games)</option>";
	}

	// Set btStatCache
	$_SESSION['btStatCache'] = array();
	$result = $mysqli->query("SELECT * FROM ".$dbprefix."gamestats WHERE gamesplayed_id = '".$gameInfo['gamesplayed_id']."' ORDER BY ordernum");
	while($row = $result->fetch_assoc()) {
		$row = filterArray($row);

		$intFirstStatID = "";
		$intSecondStatID = "";

		if($row['stattype'] == "calculate") {
			$gameStatsObj->select($row['firststat_id']);
			$intFirstStatID = $gameStatsObj->get_info_filtered("ordernum");

			$gameStatsObj->select($row['secondstat_id']);
			$intSecondStatID = $gameStatsObj->get_info_filtered("ordernum");
		}

		$_SESSION['btStatCache'][] = array(
					'statName' => $row['name'],
					'statType' => $row['stattype'],
					'calcOperation' => $row['calcop'],
					'firstStat' => $intFirstStatID,
					'secondStat' => $intSecondStatID,
					'rounding' => $row['decimalspots'],
					'hideStat' => $row['hidestat'],
					'textInput' => $row['textinput'],
					'gamestatsID' => $row['gamestats_id']

				);

	}

	echo "
		Use the form below to modify the selected game.

		NOTE: When adding a Game Image, if both the File and URL are filled out, the File will be used.  If you don't want to change an already uploaded image, leave both the File and URL blank.

						General Information

					Game Name:
					<input type='text' name='gamename' value='".$gameInfo['name']."' class='textBox' style='width: 250px'>

					Game Image:

						Current Image: View Game Image

						File:
<input type='file' name='gameimagefile' class='textBox' style='width: 250px; border: 0px'>

						File Types: .jpg, .gif, .png, .bmp | File Size: ".ini_get("upload_max_filesize")."B or less

OR

						URL:
<input type='text' name='gameimageurl' value='".$_POST['gameimageurl']."' class='textBox' style='width: 250px'>

					Image Width: (?)

						<input type='text' name='gameimagewidth' value='".$gameInfo['imagewidth']."' class='textBox' style='width: 40px'> px

					Image Height: (?)

						<input type='text' name='gameimageheight' value='".$gameInfo['imageheight']."' class='textBox' style='width: 40px'> px

					Display Order: (?)

						<select name='beforeafter' class='textBox'><option value='before'>Before</option><option value='after' ".$afterSelected.">After</option></select>

						<select name='gameorder' class='textBox'>".$gameOrderOptions."</select>

						Game Statistics Information

							In this section you can add new game statistics for the game you are adding.  You can add auto-calculated stats after adding two input stats.  The highest stat will be the default stat used to rank members on the top players page.

						<input type='button' value='Add New Stat' onclick='showAddNewStat()' class='submitButton' style='width: 125px'>

Loading

						<input type='submit' name='submit' value='Edit Game' class='submitButton' style='width: 125px'>

	</form>

	";

}

?>


text:
1. Update Dockerfile to pull in an x-server lib. This is required for running a headless browser on a linux instance and is needed for running tests
    ```
    # place immediately after FROM definition
    RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    RUN apt-get update && apt-get install xvfb -y
    ```

## Setup DB
1. Create the db's
    ```
    # create dummy app db
    docker-compose run app rake db:create db:migrate

    # create test db
    docker-compose run -e 'RAILS_ENV=test' app rake db:create db:migrate
    ```
3. Seed db
    ```
    docker-compose run app rake fae:seed_db
    ```

## Running tests on dummy app gemset
1. Start a bash shell in containers /app directory
    ```
    docker-compose run -w /app app /bin/bash
    ```
2. Run tests while inside container shell
    ```
    RAILS_ENV=test xvfb-run -a bundle exec rspec
    ```

## Running tests using Appraisal

1. Start a bash shell in containers /app directory
    ```
    docker-compose run -w /app app /bin/bash
    ```
2. Download gems for appraisal versions
    ```
    appraisal install
    ```
3. If you need to update any gems for a specific appraisal gemset
    ```
    bundle update --gemfile='/app/gemfiles/rails_5_2.gemfile'

    # change to use whichever gemfile.lock you need updated
    ```
4. Run tests against an appraisal gemset. Omit the appraisal name to run tests against all versions
    ```
    RAILS_ENV=test appraisal rails_5_2 xvfb-run -a rspec
    ```


text:
/* From private/pp_video_capture_format.idl,
 *   modified Wed Feb 18 01:41:26 2015.
 */

#ifndef PPAPI_C_PRIVATE_PP_VIDEO_CAPTURE_FORMAT_H_
#define PPAPI_C_PRIVATE_PP_VIDEO_CAPTURE_FORMAT_H_

#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_size.h"
#include "ppapi/c/pp_stdint.h"

/**
 * @file
 * This file defines the struct used to hold a video capture format.
 */

/**
 * @addtogroup Structs
 * @{
 */
/**
 * The PP_VideoCaptureFormat struct represents a video capture
 * format.
 */
struct PP_VideoCaptureFormat {
  /**
   * Frame size in pixels.
   */
  struct PP_Size frame_size;
  /**
   * Frame rate in frames per second.
   */
  float frame_rate;
};
PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoCaptureFormat, 12);
/**
 * @}
 */

#endif  /* PPAPI_C_PRIVATE_PP_VIDEO_CAPTURE_FORMAT_H_ */


text:
package com.intellij.diff.tools.util.base;

import com.intellij.diff.DiffContext;
import com.intellij.diff.FrameDiffTool;
import com.intellij.diff.FrameDiffTool.DiffViewer;
import com.intellij.diff.requests.ContentDiffRequest;
import com.intellij.diff.tools.util.DiffDataKeys;
import com.intellij.diff.util.DiffTaskQueue;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.Alarm;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.SmartList;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.*;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

public abstract class DiffViewerBase implements DiffViewer, DataProvider {
  protected static final Logger LOG = Logger.getInstance(DiffViewerBase.class);

  @NotNull private final List<DiffViewerListener> myListeners = new SmartList<DiffViewerListener>();

  @Nullable protected final Project myProject;
  @NotNull protected final DiffContext myContext;
  @NotNull protected final ContentDiffRequest myRequest;

  @NotNull private final DiffTaskQueue myTaskExecutor = new DiffTaskQueue();
  @NotNull private final Alarm myTaskAlarm = new Alarm();
  private volatile boolean myDisposed;

  public DiffViewerBase(@NotNull DiffContext context, @NotNull ContentDiffRequest request) {
    myProject = context.getProject();
    myContext = context;
    myRequest = request;
  }

  @NotNull
  @Override
  public final FrameDiffTool.ToolbarComponents init() {
    processContextHints();
    onInit();

    FrameDiffTool.ToolbarComponents components = new FrameDiffTool.ToolbarComponents();
    components.toolbarActions = createToolbarActions();
    components.popupActions = createPopupActions();
    components.statusPanel = getStatusPanel();

    fireEvent(EventType.INIT);

    rediff(true);
    return components;
  }

  @Override
  @CalledInAwt
  public final void dispose() {
    if (myDisposed) return;

    Runnable doDispose = new Runnable() {
      @Override
      public void run() {
        if (myDisposed) return;
        myDisposed = true;

        abortRediff();
        updateContextHints();

        fireEvent(EventType.DISPOSE);

        onDispose();
      }
    };

    if (!ApplicationManager.getApplication().isDispatchThread()) LOG.warn(new Throwable("dispose() not from EDT"));
    UIUtil.invokeLaterIfNeeded(doDispose);
  }

  @CalledInAwt
  protected void processContextHints() {
  }

  @CalledInAwt
  protected void updateContextHints() {
  }

  @CalledInAwt
  public final void scheduleRediff() {
    if (isDisposed()) return;

    abortRediff();
    myTaskAlarm.addRequest(new Runnable() {
      @Override
      public void run() {
        rediff();
      }
    }, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS);
  }

  @CalledInAwt
  public final void abortRediff() {
    myTaskExecutor.abort();
    myTaskAlarm.cancelAllRequests();
    fireEvent(EventType.REDIFF_ABORTED);
  }

  @CalledInAwt
  public final void rediff() {
    rediff(false);
  }

  @CalledInAwt
  public void rediff(boolean trySync) {
    if (isDisposed()) return;
    abortRediff();

    fireEvent(EventType.BEFORE_REDIFF);
    onBeforeRediff();

    // most of performRediff implementations take ReadLock inside. If EDT is holding write lock - this will never happen,
    // and diff will not be calculated. This could happen for diff from FileDocumentManager.
    boolean forceEDT = ApplicationManager.getApplication().isWriteAccessAllowed();

    int waitMillis = trySync || tryRediffSynchronously() ? ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS : 0;

    myTaskExecutor.executeAndTryWait(
      new Function<ProgressIndicator, Runnable>() {
        @Override
        public Runnable fun(final ProgressIndicator indicator) {
          final Runnable callback = performRediff(indicator);
          return new Runnable() {
            @Override
            public void run() {
              callback.run();
              onAfterRediff();
              fireEvent(EventType.AFTER_REDIFF);
            }
          };
        }
      },
      new Runnable() {
        @Override
        public void run() {
          onSlowRediff();
        }
      },
      waitMillis, forceEDT
    );
  }

  //
  // Getters
  //

  @Nullable
  public Project getProject() {
    return myProject;
  }

  @NotNull
  public ContentDiffRequest getRequest() {
    return myRequest;
  }

  @NotNull
  public DiffContext getContext() {
    return myContext;
  }

  public boolean isDisposed() {
    return myDisposed;
  }

  //
  // Abstract
  //

  @CalledInAwt
  protected boolean tryRediffSynchronously() {
    return myContext.isWindowFocused();
  }

  protected List<AnAction> createToolbarActions() {
    List<AnAction> group = new ArrayList<AnAction>();
    ContainerUtil.addAll(group, ((ActionGroup)ActionManager.getInstance().getAction(IdeActions.DIFF_VIEWER_TOOLBAR)).getChildren(null));
    return group;
  }

  protected List<AnAction> createPopupActions() {
    List<AnAction> group = new ArrayList<AnAction>();
    ContainerUtil.addAll(group, ((ActionGroup)ActionManager.getInstance().getAction(IdeActions.DIFF_VIEWER_POPUP)).getChildren(null));
    return group;
  }

  @Nullable
  protected JComponent getStatusPanel() {
    return null;
  }

  @CalledInAwt
  protected void onInit() {
  }

  @CalledInAwt
  protected void onSlowRediff() {
  }

  @CalledInAwt
  protected void onBeforeRediff() {
  }

  @CalledInAwt
  protected void onAfterRediff() {
  }

  @CalledInBackground
  @NotNull
  protected abstract Runnable performRediff(@NotNull ProgressIndicator indicator);

  @CalledInAwt
  protected void onDispose() {
    Disposer.dispose(myTaskAlarm);
  }

  @Nullable
  protected OpenFileDescriptor getOpenFileDescriptor() {
    return null;
  }

  //
  // Listeners
  //

  @CalledInAwt
  public void addListener(@NotNull DiffViewerListener listener) {
    myListeners.add(listener);
  }

  @CalledInAwt
  public void removeListener(@NotNull DiffViewerListener listener) {
    myListeners.remove(listener);
  }

  @NotNull
  @CalledInAwt
  protected List<DiffViewerListener> getListeners() {
    return myListeners;
  }

  @CalledInAwt
  private void fireEvent(@NotNull EventType type) {
    for (DiffViewerListener listener : myListeners) {
      switch (type) {
        case INIT:
          listener.onInit();
          break;
        case DISPOSE:
          listener.onDispose();
          break;
        case BEFORE_REDIFF:
          listener.onBeforeRediff();
          break;
        case AFTER_REDIFF:
          listener.onAfterRediff();
          break;
        case REDIFF_ABORTED:
          listener.onRediffAborted();
          break;
      }
    }
  }

  //
  // Helpers
  //

  @Nullable
  @Override
  public Object getData(@NonNls String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
      return getOpenFileDescriptor();
    }
    else if (DiffDataKeys.OPEN_FILE_DESCRIPTOR.is(dataId)) {
      return getOpenFileDescriptor();
    }
    else if (CommonDataKeys.PROJECT.is(dataId)) {
      return myProject;
    }
    else {
      return null;
    }
  }

  private enum EventType {
    INIT, DISPOSE, BEFORE_REDIFF, AFTER_REDIFF, REDIFF_ABORTED,
  }
}


text:
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.shortcuts import get_object_or_404
from django.contrib.admin.widgets import FilteredSelectMultiple
from uchicagohvz.game.models import Award, Kill, MissionPicture, New_Squad, Player
from uchicagohvz.webhooks import *

class SquadForm(forms.Form):
	create_squad = forms.CharField(required=False)
	choose_squad = forms.ModelChoiceField(required=False, queryset=New_Squad.objects.none())

	def __init__(self, *args, **kwargs):
		self.game = kwargs.pop('game')
		super(SquadForm, self).__init__(*args, **kwargs)
		self.fields['choose_squad'].queryset = New_Squad.objects.filter(game=self.game)
		self.fields['choose_squad'].widget.attrs['class'] = 'form-control' # for Bootstrap 3

	def clean_create_squad(self):
		sn = self.cleaned_data.get('create_squad')
		if sn and New_Squad.objects.filter(game=self.game, name=sn).exists():
			raise forms.ValidationError(
				"There is already a squad named %s. Please join %s or use a different squad name." \
				% (sn, sn))
		return sn

	def clean(self):
		cleaned_data = super(SquadForm, self).clean()
		if not (cleaned_data.get('create_squad') or cleaned_data.get('choose_squad')):
			raise forms.ValidationError(
				"You must either create a squad or join an existing squad.")
		return cleaned_data

class GameRegistrationForm(forms.ModelForm):
	class Meta:
		model = Player
		fields = ('dorm', 'gun_requested', 'opt_out_hvt', 'agree')

	agree = forms.BooleanField()

	def __init__(self, *args, **kwargs):
		self.game = kwargs.pop('game')
		super(GameRegistrationForm, self).__init__(*args, **kwargs)
		self.fields['dorm'].queryset = self.game.dorms.all()
		self.fields['dorm'].widget.attrs['class'] = 'form-control' # for Bootstrap 3
		self.fields['dorm'].widget.attrs['required'] = 'required'

def validate_lat(value):
	if not (settings.GAME_SW_BOUND[0] <= value <= settings.GAME_NE_BOUND[0]):
		raise ValidationError('Latitude is outside of game boundaries')

def validate_lng(value):
	if not (settings.GAME_SW_BOUND[1] <= value <= settings.GAME_NE_BOUND[1]):
		raise ValidationError('Longitude is outside of game boundaries')

class BiteCodeForm(forms.Form):
	bite_code = forms.CharField()
	lat = forms.FloatField(required=False, validators=[validate_lat])
	lng = forms.FloatField(required=False, validators=[validate_lng])
	notes = forms.CharField(required=False)

	def __init__(self, *args, **kwargs):
		self.killer = kwargs.pop('killer')
		require_location = kwargs.pop('require_location', False)
		super(BiteCodeForm, self).__init__(*args, **kwargs)
		if require_location:
			self.fields['lat'].required = True
			self.fields['lng'].required = True

	def clean_bite_code(self):
		if not self.killer.active:
			raise forms.ValidationError('Player entering bite code is not activated for this game.')
		if self.killer.human:
			raise forms.ValidationError('Player entering bite code is not a zombie.')
		bite_code = self.cleaned_data['bite_code'].lower().strip()
		try:
			self.victim = Player.objects.get(game=self.killer.game, active=True, bite_code__iexact=bite_code)
		except Player.DoesNotExist:
			raise forms.ValidationError('Invalid bite code entered. Check your spelling and try again.')
		if self.killer.game.status != 'in_progress':
			raise forms.ValidationError('Game is not in progress.')
		if self.victim == self.killer:
			raise forms.ValidationError('You can\'t kill yourself. You\'re already dead, anyway...')
		if not self.victim.human:
			raise forms.ValidationError("%s is already dead!" % (self.victim.bite_code))
		return bite_code

class AnnotateKillForm(forms.ModelForm):
	class Meta:
		model = Kill
		fields = ('lat', 'lng', 'notes')
	lat = forms.FloatField(required=False, validators=[validate_lat])
	lng = forms.FloatField(required=False, validators=[validate_lng])

	def __init__(self, *args, **kwargs):
		super(AnnotateKillForm, self).__init__(*args, **kwargs)

class UploadMissionPictureForm(forms.ModelForm):
	class Meta:
		model = MissionPicture
		fields = ('lat', 'lng', 'picture', 'players')

	players = forms.ModelMultipleChoiceField(required=False, queryset=Player.objects.none(),
		widget=FilteredSelectMultiple(('Players'), False,))
	lat = forms.FloatField(required=False, validators=[validate_lat])
	lng = forms.FloatField(required=False, validators=[validate_lng])
	picture = forms.FileField(required=False)

	def __init__(self, *args, **kwargs):
		self.game = kwargs.pop('game')
		super(UploadMissionPictureForm, self).__init__(*args, **kwargs)
		self.fields['players'].queryset = Player.objects.filter(game=self.game)

class AwardCodeForm(forms.Form):
	code = forms.CharField()

	def __init__(self, *args, **kwargs):
		self.player = kwargs.pop('player')
		super(AwardCodeForm, self).__init__(*args, **kwargs)

	def clean(self):
		if not self.player.active:
			raise forms.ValidationError('Player entering code is not activated for this game.')
		data = super(AwardCodeForm, self).clean()
		code = data.get('code', '').lower().strip()
		if code:
			redeem_types = ['A']
			if self.player.human:
				redeem_types.append('H')
			else:
				redeem_types.append('Z')
			redeem_types = set(redeem_types)
			try:
				self.award = Award.objects.get(game=self.player.game, code__iexact=code)
			except Award.DoesNotExist:
				raise forms.ValidationError('Invalid code entered. Check your spelling and try again.')
			if self.award.game.status != 'in_progress':
				raise forms.ValidationError('Game is not in progress.')
			if not (self.award.redeem_type in redeem_types):
				raise forms.ValidationError('You are not eligible to redeem this code.')
			if self.award.players.filter(id=self.player.id).exists():
				raise forms.ValidationError('You have already redeemed this code.')
			if self.award.players.all().count() >= self.award.redeem_limit:
				raise forms.ValidationError('Sorry, the redemption limit for this code has been reached.')
		return data

class DiscordTagForm(forms.Form):
	tag = forms.CharField()

	def __init__(self, *args, **kwargs):
		self.player = kwargs.pop('player')
		self.user = kwargs.pop('user')
		super(DiscordTagForm, self).__init__(*args, **kwargs)

	def clean(self):
		data = super(DiscordTagForm, self).clean()
		self.tag = data.get('tag')
		if self.tag:
			self.tag = self.tag.strip()
		if not self.tag or self.tag == "":
			self.user.profile.discord_tag = ""
			self.user.profile.save()
			return data
		if not "#" in self.tag:
			raise forms.ValidationError("Invalid username entered, username must have # and must be of the form Username#1234")
		else:
			tagparts = self.tag.split("#")
			tagnums = tagparts[1]
			tagusr = tagparts[0]
			if len(tagnums) != 4:
				raise forms.ValidationError("Invalid username entered, username did not contain four numbers after #")
			if tagusr == '':
				raise forms.ValidationError("Invalid username entered, no name supplied, tag must be of the form Username#1234")
		webhook_send_command("!register_player %s %d" %(self.tag, self.player.human))
		self.user.profile.discord_tag = self.tag
		self.user.profile.save()
		return data

class ZombieTextForm(forms.Form):
	message = forms.CharField()


text:
<?php

namespace App\Models;

class Coupon extends Model
{
    protected $connection = "default";
    protected $table = "coupon";

    public function expire()
    {
        return date("Y-m-d H:i:s", $this->attributes['expire']);
    }

    public function order($shop)
    {
        if ($this->attributes['shop']=="") {
            return true;
        }

        $shop_array=explode(",", $this->attributes['shop']);

        foreach ($shop_array as $shopid) {
            if ($shopid==$shop) {
                return true;
            }
        }

        return false;
    }
}


text:
<project name="Build and Test a Plugin" default="help">

    <!-- LOAD PROPERTIES -->

    <property name="plugin.dir"        location="plugin" />
    <property name="plugin.build.file" location="${plugin.dir}/build.xml" />
    <property name="plugin.build.dir"  location="${plugin.dir}/build" />
    <property name="app.dir"           location="test" />
    <property name="app.build.file"    location="${app.dir}/build.xml" />

    <!-- BUILD PLUGIN -->

    <target name="build">
        <build-plugin />
    </target>

    <!-- LOAD DEVICE -->

    <target name="load-device">
        <build-plugin />
        <ant antfile="${app.build.file}" target="load-device" dir="${app.dir}" />
    </target>

    <!-- LOAD SIMULATOR -->

    <target name="load-simulator">
        <build-plugin />
        <ant antfile="${app.build.file}" target="load-simulator" dir="${app.dir}" />
    </target>

    <!-- HELP -->

    <target name="help">
        <echo>
NAME
  ${ant.project.name}

SYNOPSIS
  ant COMMAND

DESCRIPTION
  You can build and deploy the plugin to the test application.

COMMANDS
  help .............. Show this help menu.
                        ant, ant help

  build ............. Build the plugin to ${plugin.build.dir}
                        build

  load-device ....... Build plugin and run test-suite on a connected USB device.
                        ant load-device

  load-simulator .... Build plugin and run test-suite on default simulator.
                        ant load-simulator

GETTING STARTED
  1. Edit ${app.dir}/project.properties

  2. <ant load-simulator> to run the plugin on the simulator
        </echo>
    </target>

    <!-- MACRO: BUILD PLUGIN -->

    <macrodef name="build-plugin">
        <sequential>
            <ant antfile="${plugin.build.file}" target="build" dir="${plugin.dir}" />
            <copy todir="${app.dir}">
                <fileset dir="${plugin.build.dir}" />
            </copy>
        </sequential>
    </macrodef>

</project>


text:
package org.wso2.carbon.databridge.agent.test.binary;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.databridge.agent.AgentHolder;
import org.wso2.carbon.databridge.agent.DataPublisher;
import org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointAuthenticationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointException;
import org.wso2.carbon.databridge.agent.test.DataPublisherTestUtil;
import org.wso2.carbon.databridge.commons.Event;
import org.wso2.carbon.databridge.commons.exception.MalformedStreamDefinitionException;
import org.wso2.carbon.databridge.commons.exception.TransportException;
import org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils;
import org.wso2.carbon.databridge.core.exception.DataBridgeException;
import org.wso2.carbon.databridge.core.exception.StreamDefinitionStoreException;

import java.io.IOException;
import java.net.SocketException;

/**
 * ServerOfflineSyncBinaryTest.
 */
public class ServerOfflineSyncBinaryTest {
    private static final String STREAM_NAME = "org.wso2.esb.MediatorStatistics";
    private static final String VERSION = "1.0.0";
    private String agentConfigFileName = "sync.data.agent.config.yaml";

    private static final String STREAM_DEFN = "{" +
            "  'name':'" + STREAM_NAME + "'," +
            "  'version':'" + VERSION + "'," +
            "  'nickName': 'Stock Quote Information'," +
            "  'description': 'Some Desc'," +
            "  'tags':['foo', 'bar']," +
            "  'metaData':[" +
            "          {'name':'ipAdd','type':'STRING'}" +
            "  ]," +
            "  'payloadData':[" +
            "          {'name':'symbol','type':'STRING'}," +
            "          {'name':'price','type':'DOUBLE'}," +
            "          {'name':'volume','type':'INT'}," +
            "          {'name':'max','type':'DOUBLE'}," +
            "          {'name':'min','type':'Double'}" +
            "  ]" +
            "}";

    private BinaryTestServer binaryTestServer;

    @BeforeClass
    public static void init() {
        DataPublisherTestUtil.setKeyStoreParams();
        DataPublisherTestUtil.setTrustStoreParams();
    }

    @AfterClass
    public static void stop() throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException,
            TransportException, DataEndpointException, DataEndpointConfigurationException {
        DataPublisher dataPublisher = new DataPublisher("Binary", "tcp://localhost:9687",
                "ssl://localhost:9787", "admin", "admin");
        dataPublisher.shutdownWithAgent();
    }

    @Test
    public void testTrySendingEventsWhileServerOffline()
            throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, TransportException,
            DataEndpointException, DataEndpointConfigurationException, SocketException {
        DataPublisherTestUtil.setKeyStoreParams();
        DataPublisherTestUtil.setTrustStoreParams();

        AgentHolder.setConfigPath(DataPublisherTestUtil.getDataAgentConfigPath(agentConfigFileName));
        String hostName = DataPublisherTestUtil.LOCAL_HOST;
        DataPublisher dataPublisher = new DataPublisher("Binary", "tcp://" + hostName + ": 9612",
                "ssl://" + hostName + ":9712", "admin", "admin");

        String streamID = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME, VERSION);
        Object[] metaData = new Object[]{"127.0.0.1"};
        Object[] correlationData = null;
        Object[] payLoad = new Object[]{"WSO2", 123.4, 2, 12.4, 1.3};

        int numberOfEventsSent = 1000;
        for (int i = 0; i < numberOfEventsSent; i++) {
            dataPublisher.tryPublish(streamID, metaData, correlationData, payLoad);
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        dataPublisher.shutdown();
    }

    @Test
    public void testBlockingEventSendingAndServerStartup()
            throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, TransportException,
            DataEndpointException, DataEndpointConfigurationException, MalformedStreamDefinitionException,
            DataBridgeException, StreamDefinitionStoreException, IOException {
        DataPublisherTestUtil.setKeyStoreParams();
        DataPublisherTestUtil.setTrustStoreParams();
        AgentHolder.setConfigPath(DataPublisherTestUtil.getDataAgentConfigPath(agentConfigFileName));
        String hostName = DataPublisherTestUtil.LOCAL_HOST;
        DataPublisher dataPublisher = new DataPublisher("Binary", "tcp://" + hostName + ":9620",
                "ssl://" + hostName + ":9720", "admin", "admin");
        Event event = new Event();
        event.setStreamId(DataBridgeCommonsUtils.generateStreamId(STREAM_NAME, VERSION));
        event.setMetaData(new Object[]{"127.0.0.1"});
        event.setCorrelationData(null);
        event.setPayloadData(new Object[]{"WSO2", 123.4, 2, 12.4, 1.3});

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }

        binaryTestServer = new BinaryTestServer();
        binaryTestServer.addStreamDefinition(STREAM_DEFN);
        binaryTestServer.stopAndStartDuration(9620, 9720, 1000, 1000);

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }

        int queueSize = AgentHolder.getInstance().getDataEndpointAgent("Binary").
                getAgentConfiguration().getQueueSize();
        int numberOfEventsSent = queueSize + 1000;
        for (int i = 0; i < numberOfEventsSent; i++) {
            dataPublisher.publish(event);
        }

        try {
            Thread.sleep(40000);
        } catch (InterruptedException e) {
        }

        Assert.assertEquals(binaryTestServer.getNumberOfEventsReceived(), queueSize + 1000);
        dataPublisher.shutdown();
        binaryTestServer.stop();
    }

    @Test
    public void testNonBlockingEventSendingAndServerStartup()
            throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException,
            TransportException, DataEndpointException, DataEndpointConfigurationException,
            MalformedStreamDefinitionException, DataBridgeException,
            StreamDefinitionStoreException, IOException {
        DataPublisherTestUtil.setKeyStoreParams();
        DataPublisherTestUtil.setTrustStoreParams();
        AgentHolder.setConfigPath(DataPublisherTestUtil.getDataAgentConfigPath(agentConfigFileName));
        String hostName = DataPublisherTestUtil.LOCAL_HOST;
        DataPublisher dataPublisher = new DataPublisher("Binary", "tcp://" + hostName + ":9652",
                "ssl://" + hostName + ":9752", "admin", "admin");

        String streamID = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME, VERSION);
        Object[] metaData = new Object[]{"127.0.0.1"};
        Object[] correlationData = null;
        Object[] payLoad = new Object[]{"WSO2", 123.4, 2, 12.4, 1.3};
        Long timeStamp = System.currentTimeMillis();

        binaryTestServer = new BinaryTestServer();
        binaryTestServer.addStreamDefinition(STREAM_DEFN);
        binaryTestServer.stopAndStartDuration(9652, 9752, 7000, 1000);

        int queueSize = AgentHolder.getInstance().getDataEndpointAgent("Binary").
                getAgentConfiguration().getQueueSize();
        int numberOfEventsSent = queueSize + 1000;
        for (int i = 0; i < numberOfEventsSent; i++) {
            dataPublisher.tryPublish(streamID, timeStamp, metaData, correlationData, payLoad);
        }
        try {
            Thread.sleep(16000);
        } catch (InterruptedException e) {
        }

        Assert.assertEquals(0, binaryTestServer.getNumberOfEventsReceived());
        dataPublisher.shutdown();
        binaryTestServer.stop();
    }

}


text:
package com.payneteasy.superfly.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity(name = "temp_actions")
public class ActionToSave implements Serializable {
    private String name;
    private String description;

    public ActionToSave() {
    }

    public ActionToSave(String name) {
        this.name = name;
    }

    @Column(name = "action_name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "action_description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}


text:
namespace quark {
    namespace ast {

        const tags::TagMap& Ast::getTags() const {
            return _tags;
        }

        bool Ast::addTag(const tags::TagRegistry& registry,
                         const tags::TagName&     key,
                         const tags::TagValue&    value)
        {
            const bool is_valid = registry.isValid(key, value);
            if (is_valid) {
                auto it = _tags.find(key);
                if (it == _tags.end()) {
                    auto tuple = _tags.emplace(std::make_pair(key, value));
                    assert(tuple.second);
                } else {
                    it->second = value;
                }
            }
            return is_valid;
        }

    } // namespace ast
} // namespace quark


text:
void testMemory()
{
  // test alloc small
  {
    usize size;
    void* buffer = Memory::alloc(123, size);
    ASSERT(buffer);
    ASSERT(size >= 123);
    ASSERT(Memory::size(buffer) == size);
    Memory::free(buffer);
    buffer = Memory::alloc(123, size);
    ASSERT(size >= 123);

    char testBuffer[100];
    memset(testBuffer, 'a', sizeof(testBuffer));
    Memory::fill(buffer, 'b', size);
    ASSERT(Memory::compare(buffer, testBuffer, sizeof(testBuffer)) != 0);
    ASSERT(Memory::compare(buffer, testBuffer, sizeof(testBuffer)) == memcmp(buffer, testBuffer, sizeof(testBuffer)));
    ASSERT(Memory::compare(testBuffer, buffer, sizeof(testBuffer)) == memcmp(testBuffer, buffer, sizeof(testBuffer)));
    Memory::fill(buffer, 'a', size);
    ASSERT(Memory::compare(buffer, testBuffer, sizeof(testBuffer)) == 0);

    Memory::free(buffer);
  }

  // test alloc large
  {
    usize size;
    void* buffer = Memory::alloc(50000 * 5, size);
    ASSERT(buffer);
    ASSERT(size >= 50000 * 5);
    Memory::free(buffer);
    buffer = Memory::alloc(50000 * 5, size);
    ASSERT(size >= 50000 * 5);
    Memory::free(buffer);
  }
}

void testNewDelete()
{
  static uint constructorCalls = 0;
  static uint destructorCalls = 0;
  class MyClass
  {
  public:
    MyClass()
    {
      if(constructorCalls == 0)
      {
        ASSERT(Memory::size(this) >= sizeof(MyClass));
      }
      ++constructorCalls;
    };
    ~MyClass() {++destructorCalls;};
    String aaaa;
  };

  MyClass* aa = new MyClass;
  delete aa;

  MyClass* bb = new MyClass[23];
  delete [] bb;

  ASSERT(constructorCalls == 24);
  ASSERT(destructorCalls == 24);
}

int main(int argc, char* argv[])
{
  testMemory();
  testNewDelete();
  return 0;
}