text:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="WARN"/>
        <layout class="org.apache.log4j.EnhancedPatternLayout">
            <!-- %L(line number) option is extremely slow. -->
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35.35c{1.}) %m%n"/>
        </layout>
    </appender>

    <appender name="dailyRollingFile" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${catalina.home}/logs/pinpoint-web.log"/>
        <param name="Append" value="true"/>
        <param name="DatePattern" value="'.'yyyy-MM-dd"/>

        <layout class="org.apache.log4j.EnhancedPatternLayout">
            <!-- %L(line number) option is extremely slow. -->
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35.35c{1.}) %m%n"/>
        </layout>
    </appender>

    <appender name="rollingFile" class="org.apache.log4j.RollingFileAppender">
        <param name="file" value="${catalina.home}/logs/pinpoint-web.log"/>
        <param name="append" value="true"/>
        <param name="maxFileSize" value="100MB"/>
        <param name="maxBackupIndex" value="20"/>
        <layout class="org.apache.log4j.EnhancedPatternLayout">
            <!-- %L(line number) option is extremely slow. -->
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35.35c{1.}) %m%n"/>
        </layout>
    </appender>

    <logger name="com.navercorp.pinpoint" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.filter" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.controller" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.applicationmap" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.calltree.server" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.mapper" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.service" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.dao" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="com.navercorp.pinpoint.web.mapper.ApiMetaDataMapper" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="org.apache.ibatis" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>
    <logger name="org.mybatis" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="org.springframework" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="org.apache.zookeeper" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="org.apache.hadoop.hbase" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>
    <logger name="org.apache.hadoop.ipc" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>
    <logger name="org.apache.hadoop" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </logger>

    <root>
        <level value="INFO"/>
        <appender-ref ref="console"/>
        <appender-ref ref="dailyRollingFile"/>
    </root>
</log4j:configuration>


text:
package com.rtg.variant.cnv.cnveval;

import java.util.ArrayList;

/**
 * Holds all of the CnaVariants for a chromosome
 */
class CnaVariantList extends ArrayList<CnaVariant> { }

redpajama_set_name: RedPajamaGithub


text:
class ThrowContainer
{
	std::list<Ball> objectList;
	public:
	ThrowContainer() { }

	void drawObjects(GLfloat rad);
	void moveObjects(GLfloat delta_time,GLfloat movement,Surface *surface);
	void cullLow();
	void addToList(Vec vel, Vec pos);
};


text:
'''
Unit tests for the robotutils.strmap_helper module.

This is a port of the JUnit test for the corresponding Java
robotutils class, StringmapHelper
Author: JMJ
'''

import unittest
import re
import random

from .context import strmap_helper

_REGEX_VALIDNAME = re.compile(r"\w+")
_STRING_DEFAULT = 'WOAH!!!'
_BOOL_DEFAULT = True

_INT_MIN = -10
_INT_MAX = 10
_INT_DEFAULT = _INT_MAX * 10

_FLOAT_MIN = -1.0
_FLOAT_MAX = 1.0
_FLOAT_DEFAULT = _FLOAT_MAX * 10

# pylint: disable=invalid-name

class TestStringmapHelper(unittest.TestCase):
    """Container class for unittest tests."""

    def test_empty_map(self):
        """Checks against empty map - should return defaults"""
        empty = strmap_helper.StringDictHelper(dict())

        self.assertEqual("bar", empty.get_as_str("foo", "bar"))
        self.assertEqual(True, empty.get_as_bool("foo", True))
        self.assertEqual(42, empty.get_as_num("foo", 42))
        self.assertAlmostEqual(3.14, empty.get_as_num("foo", 3.14))

        # Same deal, with the more complex versions...
        self.assertEqual("bar", empty.get_as_str("foo", "bar", _REGEX_VALIDNAME))
        self.assertEqual(42, empty.get_as_num("foo", 42, 0, 100))
        self.assertAlmostEqual(3.14, empty.get_as_num("foo", 3.14, 0.0, 100.0))

    @staticmethod
    def build_random_input(count):
        """Construct and return {count} random test inputs in an iterable"""
        inputs = [] # contains (k, v) tuples
        for i in range(count):
            key = "key" + str(i)
            k = random.randint(0, 3)
            if k == 0:
                # String. The following can't have any embedded digits, so substrings can never
                # be valid ints, longs or doubles. Also the two can't have overlapping
                # character sets,
                # and only good must pass the string validity test.
                good = "jfAGsrhGGhAhafHaahwHghqgQghqh"
                bad = "!@#$%^&*)&^#**%&%*@(*&*&*&*&!#%^*"
                s = good if random.randint(0, 1) else bad
                assert _REGEX_VALIDNAME.fullmatch(good)
                assert not _REGEX_VALIDNAME.match(bad)
                rs = s[:random.randint(0, len(s))]
                kvi = (key, rs)
                inputs.append(kvi)
            elif k == 1:
                # int
                ri = int(2 * (_INT_MIN + random.random() * (_INT_MAX - _INT_MIN)))
                kvi = (key, ri)
                inputs.append(kvi)
            elif k == 2:
                # float
                df = 2 * (_FLOAT_MIN + random.random() * (_FLOAT_MAX - _FLOAT_MIN))
                kvi = (key, df)
                inputs.append(kvi)
            else:
                # bool
                rb = bool(random.randint(0, 1))
                kvi = (key, rb)
                inputs.append(kvi)
        return inputs

    @staticmethod
    def build_random_dict(kv_infos):
        """Build a random dictionary of (k,v) pairs"""
        return {k: str(v) for k, v in kv_infos}

    def run_gauntlet(self, smg, kvi):
        """Run tests using all the (key, value) pairs in kv_infos"""
        key, expected_val = kvi

        # Test get_as_str without REGEX...
        got_val = smg.get_as_str(key, _STRING_DEFAULT)
        self.assertEqual(got_val, str(expected_val))

        # Test get_as_str with REGEX...
        got_val = smg.get_as_str(key, _STRING_DEFAULT, _REGEX_VALIDNAME)
        valid = _REGEX_VALIDNAME.fullmatch(str(expected_val))
        if valid:
            self.assertEqual(got_val, str(expected_val))
        else:
            self.assertEqual(got_val, _STRING_DEFAULT)

        # Test get_as_bool...
        got_val = smg.get_as_bool(key, _BOOL_DEFAULT)
        valid = isinstance(expected_val, bool)
        if valid:
            self.assertEqual(got_val, expected_val)
        else:
            self.assertEqual(got_val, _BOOL_DEFAULT)

        # Test get_as_num: int without min, max
        valid_int = isinstance(expected_val, int) and not isinstance(expected_val, bool)
        got_val = smg.get_as_num(key, _INT_DEFAULT)
        if valid_int:
            self.assertEqual(got_val, expected_val)
        elif not isinstance(expected_val, float):
            self.assertEqual(got_val, _INT_DEFAULT)

        # Test get_as_num: int with min, max
        got_val = smg.get_as_num(key, _INT_DEFAULT, _INT_MIN, _INT_MAX)
        valid = valid_int and expected_val >= _INT_MIN and expected_val <= _INT_MAX
        if valid:
            self.assertEqual(got_val, expected_val)
        elif not isinstance(expected_val, float):
            self.assertEqual(got_val, _INT_DEFAULT)

        # Test get_as_num: float without min, max
        got_val = smg.get_as_num(key, _FLOAT_DEFAULT)
        valid = isinstance(expected_val, float) or valid_int
        if valid:
            self.assertAlmostEqual(got_val, expected_val)
        else:
            self.assertAlmostEqual(got_val, _FLOAT_DEFAULT)

        # Test get_as_num: float with min, max
        got_val = smg.get_as_num(key, _FLOAT_DEFAULT, _FLOAT_MIN, _FLOAT_MAX)
        validtype = isinstance(expected_val, float) or valid_int
        valid = validtype and expected_val >= _FLOAT_MIN and expected_val <= _FLOAT_MAX
        if valid:
            self.assertAlmostEqual(got_val, expected_val)
        else:
            self.assertAlmostEqual(got_val, _FLOAT_DEFAULT)

    def test_complex_cases(self):
        """Create many (k,v) pairs and run the gauntlet test on them."""
        kv_infos = self.build_random_input(20)
        smap = self.build_random_dict(kv_infos)
        smh = strmap_helper.StringDictHelper(smap)
        for kv in kv_infos:
            self.run_gauntlet(smh, kv)


text:
require File.expand_path(File.dirname(__FILE__) + '/helper')

describe "AppGenerator" do
  def setup
    @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
    `mkdir -p #{@apptmp}`
  end

  def teardown
    `rm -rf #{@apptmp}`
  end

  context 'the app generator' do
    should "fail outside app root" do
      out, err = capture_io { generate(:app, 'demo_root', "-r=#{@apptmp}") }
      assert_match(/not at the root/, out)
      assert_no_file_exists("#{@apptmp}/demo_root")
    end

    should "create correctly a new padrino application" do
      capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
      capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
      assert_file_exists("#{@apptmp}/sample_project")
      assert_file_exists("#{@apptmp}/sample_project/demo")
      assert_file_exists("#{@apptmp}/sample_project/demo/app.rb")
      assert_file_exists("#{@apptmp}/sample_project/demo/controllers")
      assert_file_exists("#{@apptmp}/sample_project/demo/helpers")
      assert_file_exists("#{@apptmp}/sample_project/demo/views")
      assert_file_exists("#{@apptmp}/sample_project/demo/views/layouts")
      assert_dir_exists("#{@apptmp}/sample_project/public/demo")
      assert_match_in_file('Padrino.mount("Demo").to("/demo")', "#{@apptmp}/sample_project/config/apps.rb")
      assert_match_in_file('class Demo < Padrino::Application', "#{@apptmp}/sample_project/demo/app.rb")
      assert_match_in_file(/Padrino.configure_apps do/, "#{@apptmp}/sample_project/config/apps.rb")
      assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
    end

    should "generate tiny app skeleton" do
      capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
      capture_io { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") }
      assert_file_exists("#{@apptmp}/sample_project")
      assert_file_exists("#{@apptmp}/sample_project/demo")
      assert_file_exists("#{@apptmp}/sample_project/demo/helpers.rb")
      assert_file_exists("#{@apptmp}/sample_project/demo/controllers.rb")
      assert_file_exists("#{@apptmp}/sample_project/demo/mailers.rb")
      assert_dir_exists("#{@apptmp}/sample_project/public/demo")
      assert_match_in_file(/:notifier/,"#{@apptmp}/sample_project/demo/mailers.rb")
      assert_no_file_exists("#{@apptmp}/sample_project/demo/helpers")
      assert_no_file_exists("#{@apptmp}/sample_project/demo/controllers")
    end

    should "correctly create a new controller inside a padrino application" do
      capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
      capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
      capture_io { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
      assert_match_in_file(/Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
      assert_match_in_file(/Demo.helpers do/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
      assert_file_exists("#{@apptmp}/sample_project/demo/views/demo_items")
    end

    should "correctly create a new mailer inside a padrino application" do
      capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
      capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
      capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demoapp') }
    end

    # only destroys what it generated.
    # hence, the folder will still exists if other changes were made to it.
    should "destroys itself" do
      capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
      capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
      out, err = capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project", '-d') }
      assert_no_match(/has been mounted/, out)
      assert_no_dir_exists("#{@apptmp}/sample_project/public/demo")
      assert_no_file_exists("#{@apptmp}/sample_project/demo/app.rb")
      assert_no_dir_exists("#{@apptmp}/sample_project/demo/controllers")
      assert_no_dir_exists("#{@apptmp}/sample_project/demo/helpers")
      assert_no_dir_exists("#{@apptmp}/sample_project/demo/views")
      assert_no_match_in_file(/Padrino\.mount\("Demo"\).to\("\/demo"\)/,"#{@apptmp}/sample_project/config/apps.rb")
    end
  end
end


text:
package play.data.validation;

import java.util.HashMap;
import java.util.Map;
import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;

@SuppressWarnings("serial")
public class MaxCheck extends AbstractAnnotationCheck<Max> {

    static final String mes = "validation.max";

    double max;

    @Override
    public void configure(Max max) {
        this.max = max.value();
        setMessage(max.message());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        requireMessageVariablesRecreation();
        if (value == null) {
            return true;
        }
        if (value instanceof String) {
            try {
                return Double.parseDouble(value.toString()) <= max;
            } catch (Exception e) {
                return false;
            }
        }
        if (value instanceof Number) {
            try {
                return ((Number) value).doubleValue() <= max;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }

    @Override
    public Map<String, String> createMessageVariables() {
        Map<String, String> messageVariables = new HashMap<>();
        messageVariables.put("max", Double.toString(max));
        return messageVariables;
    }

}


text:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="64dp"
        >
    <ImageView android:id="@+id/profile_image"
              android:layout_width="64dp"
              android:layout_height="match_parent"
              android:layout_alignParentLeft="true"
              android:scaleType="fitCenter"
            />
    <TextView android:id="@+id/profile_text"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_toRightOf="@id/profile_image"
              android:layout_alignParentRight="true"
              android:padding="12dp"
              android:gravity="left|center_vertical"
            />
</RelativeLayout>


text:
package com.alorma.github.ui.activity.issue;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import butterknife.ButterKnife;
import com.alorma.github.R;
import com.alorma.github.presenter.Presenter;
import com.alorma.github.sdk.bean.dto.response.Milestone;
import com.alorma.github.sdk.bean.dto.response.MilestoneState;
import com.alorma.github.sdk.bean.info.RepoInfo;
import com.alorma.github.ui.activity.base.BackActivity;
import com.alorma.github.ui.activity.base.RepositoryThemeActivity;
import com.alorma.github.ui.adapter.base.RecyclerArrayAdapter;
import com.alorma.github.utils.NaturalTimeFormatter;
import java.util.List;

public class RepositoryMilestonesActivity extends RepositoryThemeActivity
    implements Presenter.Callback<List<Milestone>>, RecyclerArrayAdapter.ItemCallback<Milestone> {

  private static final String REPO_INFO = "REPO_INFO";
  private static final String RETURN = "RETURN";
  private static final String STATE = "STATE";

  @Bind(R.id.recycler) RecyclerView recyclerView;
  private MilestonesAdapter adapter;
  private boolean returnResult;

  public static Intent createLauncher(Context context, RepoInfo repoInfo, boolean returnResult) {
    Intent intent = new Intent(context, RepositoryMilestonesActivity.class);
    intent.putExtra(REPO_INFO, repoInfo);
    intent.putExtra(RETURN, returnResult);
    intent.putExtra(STATE, MilestoneState.open);
    return intent;
  }

  public static Intent createLauncher(Context context, RepoInfo issrepoInfoeInfo, MilestoneState state, boolean returnResult) {
    Intent intent = new Intent(context, RepositoryMilestonesActivity.class);
    intent.putExtra(REPO_INFO, issrepoInfoeInfo);
    intent.putExtra(RETURN, returnResult);
    intent.putExtra(STATE, state);
    return intent;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.generic_recyclerview);
    ButterKnife.bind(this);

    setTitle(R.string.milestones);

    RepoInfo repoInfo = getIntent().getExtras().getParcelable(REPO_INFO);
    MilestoneState state = (MilestoneState) getIntent().getExtras().getSerializable(STATE);

    returnResult = getIntent().getExtras().getBoolean(RETURN, false);

    adapter = new MilestonesAdapter(getLayoutInflater());
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter.setTimeFormatter(new NaturalTimeFormatter(this));
    adapter.setCallback(this);
    recyclerView.setAdapter(adapter);

    IssueMilestonePresenter presenter = new IssueMilestonePresenter(state);
    presenter.load(repoInfo, this);
  }

  @Override
  protected void configureTheme(boolean dark) {
    if (dark) {
      setTheme(R.style.AppTheme_Dark_Repository);
    } else {
      setTheme(R.style.AppTheme_Repository);
    }
  }

  @Override
  public void showLoading() {

  }

  @Override
  public void onResponse(List<Milestone> milestones, boolean firstTime) {
    if (firstTime) {
      adapter.clear();
    }
    adapter.addAll(milestones);
  }

  @Override
  public void hideLoading() {

  }

  @Override
  public void onResponseEmpty() {

  }

  @Override
  public void onItemSelected(Milestone item) {
    if (returnResult) {
      Intent intent = new Intent();
      intent.putExtra(Milestone.class.getSimpleName(), item);
      setResult(RESULT_OK, intent);
      finish();
    }
  }
}


text:
#if DESKTOP || PHONE
using System;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Interactivity;
#elif MODERN
using Windows.UI.Interactivity;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
#endif

// ReSharper disable once CheckNamespace
namespace Neptune.UI.Behaviours
{
    /// <summary>
    /// Custom behavior that updates the source of a binding on a text box as the text changes.
    /// </summary>
    public class UpdateTextBindingOnPropertyChanged : Behavior<TextBox>
    {
        private BindingExpression _expression;

        /// <summary>
        /// Called after the behavior is attached to an AssociatedObject.
        /// </summary>
        /// <remarks>
        /// Override this to hook up functionality to the AssociatedObject.
        /// </remarks>
        protected override void OnAttached()
        {
            base.OnAttached();

            this._expression = this.AssociatedObject.GetBindingExpression(TextBox.TextProperty);
            this.AssociatedObject.TextChanged += this.OnTextChanged;
        }

        /// <summary>
        /// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.
        /// </summary>
        /// <remarks>
        /// Override this to unhook functionality from the AssociatedObject.
        /// </remarks>
        protected override void OnDetaching()
        {
            base.OnDetaching();

            this.AssociatedObject.TextChanged -= this.OnTextChanged;
            this._expression = null;
        }

#if DESKTOP || PHONE
        private void OnTextChanged(object sender, EventArgs args)
#elif MODERN
       private void OnTextChanged(object sender, TextChangedEventArgs args)
#endif
        {
            if (_expression != null)
                this._expression.UpdateSource();
        }
    }
}


text:
package org.kitesdk.data.spi.filesystem;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.Callable;
import org.apache.avro.Schema;
import org.apache.avro.SchemaBuilder;
import org.apache.avro.generic.GenericData.Record;
import org.apache.avro.generic.GenericRecord;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.kitesdk.data.Dataset;
import org.kitesdk.data.DatasetDescriptor;
import org.kitesdk.data.DatasetWriter;
import org.kitesdk.data.Datasets;
import org.kitesdk.data.Formats;
import org.kitesdk.data.LocalFileSystem;
import org.kitesdk.data.PartitionStrategy;
import org.kitesdk.data.TestHelpers;
import org.kitesdk.data.View;
import org.kitesdk.data.spi.DescriptorUtil;

import static org.kitesdk.data.CompressionType.Uncompressed;

public class TestFileSystemUtil {
  private static final Schema USER_SCHEMA = SchemaBuilder.record("User").fields()
      .requiredLong("id")
      .requiredString("username")
      .endRecord();

  private static final Schema EVENT_SCHEMA = SchemaBuilder.record("Event").fields()
      .requiredLong("timestamp")
      .requiredString("level")
      .requiredString("message")
      .endRecord();

  private static final Record USER = new Record(USER_SCHEMA);
  private static final Record EVENT = new Record(EVENT_SCHEMA);

  @BeforeClass
  public static void initRecords() {
    USER.put("id", 1L);
    USER.put("username", "test");
    EVENT.put("timestamp", System.currentTimeMillis());
    EVENT.put("level", "DEBUG");
    EVENT.put("message", "Useless information!");
  }

  @Rule
  public TemporaryFolder temp = new TemporaryFolder();

  @Test
  public void testEmptyDataset() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e/dataset_name");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();
    URI datasetUri = URI.create("dataset:file:" + folder.getAbsolutePath());
    DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
        .schema(USER_SCHEMA)
        .build();

    Datasets.create(datasetUri, descriptor);

    Collection<DatasetDescriptor> expected = Lists.newArrayList();
    Assert.assertEquals("Should succeed and find no datasets",
        expected, FileSystemUtil.findPotentialDatasets(fs, root));
  }

  @Test
  public void testUnpartitionedDataset() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e/dataset_name");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();
    URI datasetUri = URI.create("dataset:file:" + folder.getAbsolutePath());
    DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
        .schema(USER_SCHEMA)
        .build();

    Dataset<GenericRecord> dataset = Datasets.create(datasetUri, descriptor);

    // write two so that the descriptor uses the directory rather than a file
    writeUserToView(dataset);
    writeUserToView(dataset);

    DatasetDescriptor expected = dataset.getDescriptor();
    DatasetDescriptor actual = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertEquals("Should succeed and find an equivalent descriptor",
        expected, actual);
  }

  @Test
  public void testPartitionedDataset() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e/dataset_name");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();
    URI datasetUri = URI.create("dataset:file:" + folder.getAbsolutePath());
    DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
        .schema(USER_SCHEMA)
        .partitionStrategy(new PartitionStrategy.Builder()
            .hash("id", 4)
            .build())
        .build();

    Dataset<GenericRecord> dataset = Datasets.create(datasetUri, descriptor);

    // write two so that the descriptor uses the directory rather than a file
    writeUserToView(dataset);
    writeUserToView(dataset);

    Path datasetPath = new Path(folder.toURI());
    Path partitionPath = new Path(datasetPath, "id_hash=1");

    DatasetDescriptor actual = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Location should be at the partition directory",
        partitionPath.toUri(), actual.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, actual.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, actual.getFormat());
    Assert.assertFalse("Should not be partitioned", actual.isPartitioned());
  }

  @Test
  public void testPartitionedDatasetWithEscapedChars() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e/dataset_name");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();
    URI datasetUri = URI.create("dataset:file:" + folder.getAbsolutePath());
    DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
        .schema(USER_SCHEMA)
        .partitionStrategy(new PartitionStrategy.Builder()
            .provided("s")
            .build())
        .build();

    Dataset<GenericRecord> dataset = Datasets.create(datasetUri, descriptor);

    // write two so that the descriptor uses the directory rather than a file
    writeUserToView(dataset.with("s", "test/-0"));
    writeUserToView(dataset.with("s", "test/-0"));

    Path datasetPath = new Path(folder.toURI());
    Path partitionPath = new Path(datasetPath, "s=test%2F-0");

    DatasetDescriptor actual = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Location should be at the partition directory",
        URI.create(partitionPath.toString()), actual.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, actual.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, actual.getFormat());
    Assert.assertFalse("Should not be partitioned", actual.isPartitioned());
  }

  @Test
  public void testSingleAvroFile() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a single Avro file
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri().getPath(),
        parent(descriptor.getLocation()).getPath());
    Assert.assertTrue("Should be a .avro file",
        descriptor.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, descriptor.getFormat());
    Assert.assertFalse("Should not be partitioned", descriptor.isPartitioned());
  }

  @Test
  public void testMultipleAvroFilesInOneFolder() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files in parent
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, parent);
    createAvroUserFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, descriptor.getFormat());
    Assert.assertFalse("Should not be partitioned", descriptor.isPartitioned());
  }

  @Test
  public void testMultipleAvroFilesInSeparateFolders() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroUserFile(fs, new Path(parent, "2"));

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    PartitionStrategy strategy = new PartitionStrategy.Builder()
        .provided("part", "int")
        .build();

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, descriptor.getFormat());
    Assert.assertEquals("Should be partitioned by part=int",
        strategy, descriptor.getPartitionStrategy());
  }

  @Test
  public void testMultipleAvroFilesAtDifferentDepths() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroUserFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    PartitionStrategy strategy = new PartitionStrategy.Builder()
        .provided("part", "int")
        .build();

    Assert.assertTrue("Should flag data at mixed depth in the directory tree",
        DescriptorUtil.isEnabled("kite.filesystem.mixed-depth", descriptor));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, descriptor.getFormat());
    Assert.assertEquals("Should be partitioned by part=int",
        strategy, descriptor.getPartitionStrategy());
  }

  @Test
  public void testMultipleMergeTablesAtDifferentDepths() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroUserFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    PartitionStrategy strategy = new PartitionStrategy.Builder()
        .provided("part", "int")
        .build();

    Assert.assertTrue("Should flag data at mixed depth in the directory tree",
        DescriptorUtil.isEnabled("kite.filesystem.mixed-depth", descriptor));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, descriptor.getFormat());
    Assert.assertEquals("Should be partitioned by part=int",
        strategy, descriptor.getPartitionStrategy());
  }

  @Test
  public void testMultipleAvroFilesInSeparateFoldersWithUnknown() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders, with an unknown
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroUserFile(fs, new Path(parent, "part=2"));
    createUnknownFile(fs, new Path(parent, "part=3"));

    Collection<DatasetDescriptor> descriptors = FileSystemUtil
        .findPotentialDatasets(fs, root);

    Assert.assertEquals("Should have 2 descriptors", 2, descriptors.size());
    DatasetDescriptor users1;
    DatasetDescriptor users2;
    DatasetDescriptor first = Iterables.getFirst(descriptors, null);
    if (first.getLocation().toString().contains("part=1")) {
      users1 = first;
      users2 = Iterables.getLast(descriptors, null);
    } else {
      users2 = first;
      users1 = Iterables.getLast(descriptors, null);
    }

    // the descriptors may be out of order, so check and swap
    if (users1.getLocation().toString().contains("part=2")) {
      users2 = Iterables.getFirst(descriptors, null);
      users1 = Iterables.getLast(descriptors, null);
    }

    Assert.assertFalse("Should not flag at mixed depth",
        users1.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=1").toUri(),
        parent(users1.getLocation()));
    Assert.assertTrue("Should be a .avro file",
        users1.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, users1.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, users1.getFormat());
    Assert.assertFalse("Should not be partitioned",
        users1.isPartitioned());

    Assert.assertFalse("Should not flag at mixed depth",
        users2.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=2").toUri(),
        parent(users2.getLocation()));
    Assert.assertTrue("Should be a .avro file",
        users2.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, users2.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, users2.getFormat());
    Assert.assertFalse("Should not be partitioned",
        users2.isPartitioned());
  }

  @Test
  public void testSingleParquetFile() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a single Avro file
    Path parent = new Path(folder.toURI());
    createParquetEventFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri().getPath(),
        parent(descriptor.getLocation()).getPath());
    Assert.assertTrue("Should be a .parquet file",
        descriptor.getLocation().toString().endsWith(".parquet"));
    Assert.assertEquals("Should use event schema",
        EVENT_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Parquet format",
        Formats.PARQUET, descriptor.getFormat());
    Assert.assertFalse("Should not be partitioned", descriptor.isPartitioned());
  }

  @Test
  public void testMultipleParquetFilesInOneFolder() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a single Avro file
    Path parent = new Path(folder.toURI());
    createParquetEventFile(fs, parent);
    createParquetEventFile(fs, parent);

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use event schema",
        EVENT_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Parquet format",
        Formats.PARQUET, descriptor.getFormat());
    Assert.assertFalse("Should not be partitioned", descriptor.isPartitioned());
  }

  @Test
  public void testMultipleParquetFilesInSeparateFolders() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders
    Path parent = new Path(folder.toURI());
    createParquetEventFile(fs, new Path(parent, "part"));
    createParquetEventFile(fs, new Path(parent, "2"));

    DatasetDescriptor descriptor = Iterables.getOnlyElement(
        FileSystemUtil.findPotentialDatasets(fs, root));

    PartitionStrategy strategy = new PartitionStrategy.Builder()
        .provided("partition_1", "string")
        .build();

    Assert.assertFalse("Should not flag at mixed depth",
        descriptor.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(), descriptor.getLocation());
    Assert.assertEquals("Should use user schema",
        EVENT_SCHEMA, descriptor.getSchema());
    Assert.assertEquals("Should have Parquet format",
        Formats.PARQUET, descriptor.getFormat());
    Assert.assertEquals("Should be partitioned by part=int",
        strategy, descriptor.getPartitionStrategy());
  }

  @Test
  public void testIncompatibleSchemaFilesInSeparateFolders() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Avro files under separate folders, with different schemas
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, new Path(parent, "part=1"));
    createAvroEventFile(fs, new Path(parent, "part=2"));

    Collection<DatasetDescriptor> descriptors = FileSystemUtil
        .findPotentialDatasets(fs, root);

    Assert.assertEquals("Should have 2 descriptors", 2, descriptors.size());
    DatasetDescriptor users;
    DatasetDescriptor events;
    DatasetDescriptor first = Iterables.getFirst(descriptors, null);
    if (first.getLocation().toString().contains("part=1")) {
      users = first;
      events = Iterables.getLast(descriptors, null);
    } else {
      events = first;
      users = Iterables.getLast(descriptors, null);
    }

    Assert.assertFalse("Should not flag at mixed depth",
        users.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=1").toUri(),
        parent(users.getLocation()));
    Assert.assertTrue("Should be a .avro file",
        users.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, users.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, users.getFormat());
    Assert.assertFalse("Should not be partitioned",
        users.isPartitioned());

    Assert.assertFalse("Should not flag at mixed depth",
        events.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=2").toUri(),
        parent(events.getLocation()));
    Assert.assertTrue("Should be a .avro file",
        events.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use event schema",
        EVENT_SCHEMA, events.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, events.getFormat());
    Assert.assertFalse("Should not be partitioned",
        events.isPartitioned());
  }

  @Test
  public void testIncompatibleSchemaParquetFilesInSeparateFolders() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a two Parquet files under separate folders, with different schemas
    Path parent = new Path(folder.toURI());
    createParquetUserFile(fs, new Path(parent, "part=1"));
    createParquetEventFile(fs, new Path(parent, "part=2"));

    Collection<DatasetDescriptor> descriptors = FileSystemUtil
        .findPotentialDatasets(fs, root);

    Assert.assertEquals("Should have 2 descriptors", 2, descriptors.size());
    DatasetDescriptor users;
    DatasetDescriptor events;
    DatasetDescriptor first = Iterables.getFirst(descriptors, null);
    if (first.getLocation().toString().contains("part=1")) {
      users = first;
      events = Iterables.getLast(descriptors, null);
    } else {
      events = first;
      users = Iterables.getLast(descriptors, null);
    }

    Assert.assertFalse("Should not flag at mixed depth",
        users.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=1").toUri(),
        parent(users.getLocation()));
    Assert.assertTrue("Should be a .parquet file",
        users.getLocation().toString().endsWith(".parquet"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, users.getSchema());
    Assert.assertEquals("Should have Parquet format",
        Formats.PARQUET, users.getFormat());
    Assert.assertFalse("Should not be partitioned",
        users.isPartitioned());

    Assert.assertFalse("Should not flag at mixed depth",
        events.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        new Path(parent, "part=2").toUri(),
        parent(events.getLocation()));
    Assert.assertTrue("Should be a .parquet file",
        events.getLocation().toString().endsWith(".parquet"));
    Assert.assertEquals("Should use event schema",
        EVENT_SCHEMA, events.getSchema());
    Assert.assertEquals("Should have Parquet format",
        Formats.PARQUET, events.getFormat());
    Assert.assertFalse("Should not be partitioned",
        events.isPartitioned());
  }

  @Test
  public void testIncompatibleFormatFilesInSameFolder() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create Avro and Parquet files under separate folders, with the same schema
    Path parent = new Path(folder.toURI());
    createAvroUserFile(fs, parent);
    createParquetUserFile(fs, parent);

    Collection<DatasetDescriptor> descriptors = FileSystemUtil
        .findPotentialDatasets(fs, root);

    Assert.assertEquals("Should have 2 descriptors", 2, descriptors.size());
    DatasetDescriptor avro;
    DatasetDescriptor parquet;
    DatasetDescriptor first = Iterables.getFirst(descriptors, null);
    if (first.getFormat() == Formats.AVRO) {
      avro = first;
      parquet = Iterables.getLast(descriptors, null);
    } else {
      parquet = first;
      avro = Iterables.getLast(descriptors, null);
    }

    Assert.assertFalse("Should not flag at mixed depth",
        avro.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(),
        parent(avro.getLocation()));
    Assert.assertTrue("Should be a .avro file",
        avro.getLocation().toString().endsWith(".avro"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, avro.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.AVRO, avro.getFormat());
    Assert.assertFalse("Should not be partitioned",
        avro.isPartitioned());

    Assert.assertFalse("Should not flag at mixed depth",
        parquet.hasProperty("kite.filesystem.mixed-depth"));
    Assert.assertEquals("Should be directly under parent",
        parent.toUri(),
        parent(parquet.getLocation()));
    Assert.assertTrue("Should be a .parquet file",
        parquet.getLocation().toString().endsWith(".parquet"));
    Assert.assertEquals("Should use user schema",
        USER_SCHEMA, parquet.getSchema());
    Assert.assertEquals("Should have Avro format",
        Formats.PARQUET, parquet.getFormat());
    Assert.assertFalse("Should not be partitioned",
        parquet.isPartitioned());
  }

  @Test
  public void testSingleUnknownFile() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a single Avro file
    Path parent = new Path(folder.toURI());
    createUnknownFile(fs, parent);

    Collection<DatasetDescriptor> expected = Lists.newArrayList();
    Assert.assertEquals("Should succeed and find no datasets",
        expected, FileSystemUtil.findPotentialDatasets(fs, root));
  }

  @Test
  public void testMultipleUnknownFiles() throws Exception {
    File folder = temp.newFolder("a/b/c/d/e");
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();

    // create a single Avro file
    Path parent = new Path(folder.toURI());
    createUnknownFile(fs, parent);
    createUnknownFile(fs, parent);

    Collection<DatasetDescriptor> expected = Lists.newArrayList();
    Assert.assertEquals("Should succeed and find no datasets",
        expected, FileSystemUtil.findPotentialDatasets(fs, root));
  }

  @Test
  public void testEmptyDirectory() throws IOException {
    Path root = new Path(temp.getRoot().toURI());
    FileSystem fs = LocalFileSystem.getInstance();
    Collection<DatasetDescriptor> expected = Lists.newArrayList();
    Assert.assertEquals("Should succeed and find no datasets",
        expected, FileSystemUtil.findPotentialDatasets(fs, root));
  }

  @Test
  public void testMissingDirectory() throws IOException {
    final Path root = new Path(new Path(temp.getRoot().toURI()), "not_there");
    final FileSystem fs = LocalFileSystem.getInstance();

    TestHelpers.assertThrows("Should propagate missing file IOException",
        FileNotFoundException.class, new Callable<Void>() {
          @Override
          public Void call() throws IOException {
            FileSystemUtil.findPotentialDatasets(fs, root);
            return null;
          }
        });
  }

  private URI parent(URI file) {
    return new Path(file).getParent().toUri();
  }

  public void writeUserToView(View<GenericRecord> dataset) {
    DatasetWriter<GenericRecord> writer = null;
    try {
      writer = dataset.newWriter();
      writer.write(USER);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }

  public void createAvroUserFile(FileSystem fs, Path parent) throws IOException {
    Path file = new Path(parent, UUID.randomUUID().toString() + ".avro");
    AvroAppender<Record> appender = new AvroAppender<Record>(
        fs, file, USER_SCHEMA, Uncompressed);
    appender.open();
    appender.append(USER);
    appender.close();
  }

  public void createAvroEventFile(FileSystem fs, Path parent) throws IOException {
    Path file = new Path(parent, UUID.randomUUID().toString() + ".avro");
    AvroAppender<Record> appender = new AvroAppender<Record>(
        fs, file, EVENT_SCHEMA, Uncompressed);
    appender.open();
    appender.append(EVENT);
    appender.close();
  }

  public void createParquetUserFile(FileSystem fs, Path parent) throws IOException {
    Path file = new Path(parent, UUID.randomUUID().toString() + ".parquet");
    ParquetAppender<Record> appender = new ParquetAppender<Record>(
        fs, file, USER_SCHEMA, new Configuration(), Uncompressed);
    appender.open();
    appender.append(USER);
    appender.close();
  }

  public void createParquetEventFile(FileSystem fs, Path parent) throws IOException {
    Path file = new Path(parent, UUID.randomUUID().toString() + ".parquet");
    ParquetAppender<Record> appender = new ParquetAppender<Record>(
        fs, file, EVENT_SCHEMA, new Configuration(), Uncompressed);
    appender.open();
    appender.append(EVENT);
    appender.close();
  }

  public void createUnknownFile(FileSystem fs, Path parent) throws IOException {
    Path file = new Path(parent, UUID.randomUUID().toString() + ".unknown");
    fs.create(file);
  }
}


text:
import abc
import json
from collections import OrderedDict
import operator
from pathlib import Path

import rasa.shared.nlu.training_data.util
from rasa.shared.constants import INTENT_MESSAGE_PREFIX

from rasa.shared.nlu.constants import (
    INTENT,
    ENTITY_ATTRIBUTE_VALUE,
    ENTITY_ATTRIBUTE_START,
    ENTITY_ATTRIBUTE_END,
    ENTITY_ATTRIBUTE_TYPE,
    ENTITY_ATTRIBUTE_GROUP,
    ENTITY_ATTRIBUTE_ROLE,
)

import rasa.shared.utils.io
import typing
from typing import Text, Dict, Any, Union

if typing.TYPE_CHECKING:
    from rasa.shared.nlu.training_data.training_data import TrainingData

class TrainingDataReader(abc.ABC):
    """Reader for NLU training data."""

    def __init__(self) -> None:
        """Creates reader instance."""
        self.filename: Text = ""

    def read(self, filename: Union[Text, Path], **kwargs: Any) -> "TrainingData":
        """Reads TrainingData from a file."""
        self.filename = filename
        return self.reads(rasa.shared.utils.io.read_file(filename), **kwargs)

    @abc.abstractmethod
    def reads(self, s: Text, **kwargs: Any) -> "TrainingData":
        """Reads TrainingData from a string."""
        raise NotImplementedError

class TrainingDataWriter:
    """A class for writing training data to a file."""

    def dump(self, filename: Text, training_data: "TrainingData") -> None:
        """Writes a TrainingData object to a file."""
        s = self.dumps(training_data)
        rasa.shared.utils.io.write_text_file(s, filename)

    def dumps(self, training_data: "TrainingData") -> Text:
        """Turns TrainingData into a string."""
        raise NotImplementedError

    @staticmethod
    def prepare_training_examples(training_data: "TrainingData") -> OrderedDict:
        """Pre-processes training data examples by removing not trainable entities."""

        import rasa.shared.nlu.training_data.util as rasa_nlu_training_data_utils

        training_examples = OrderedDict()

        # Sort by intent while keeping basic intent order
        for example in [e.as_dict_nlu() for e in training_data.training_examples]:
            if not example.get(INTENT):
                continue
            rasa_nlu_training_data_utils.remove_untrainable_entities_from(example)
            intent = example[INTENT]
            training_examples.setdefault(intent, [])
            training_examples[intent].append(example)

        return training_examples

    @staticmethod
    def generate_list_item(text: Text) -> Text:
        """Generates text for a list item."""
        return f"- {rasa.shared.nlu.training_data.util.encode_string(text)}\n"

    @staticmethod
    def generate_message(message: Dict[Text, Any]) -> Text:
        """Generates text for a message object."""

        md = ""
        text = message.get("text", "")

        pos = 0

        # If a message was prefixed with `INTENT_MESSAGE_PREFIX` (this can only happen
        # in end-to-end stories) then potential entities were provided in the json
        # format (e.g. `/greet{"name": "Rasa"}) and we don't have to add the NLU
        # entity annotation
        if not text.startswith(INTENT_MESSAGE_PREFIX):

            entities = message.get("entities", [])
            entities_with_start_and_end = [
                e for e in entities if "start" in e and "end" in e
            ]
            sorted_entities = sorted(
                entities_with_start_and_end, key=operator.itemgetter("start")
            )

            for entity in sorted_entities:
                md += text[pos : entity["start"]]
                md += TrainingDataWriter.generate_entity(text, entity)
                pos = entity["end"]

        md += text[pos:]

        return md

    @staticmethod
    def generate_entity(text: Text, entity: Dict[Text, Any]) -> Text:
        """Generates text for an entity object."""

        entity_text = text[
            entity[ENTITY_ATTRIBUTE_START] : entity[ENTITY_ATTRIBUTE_END]
        ]
        entity_type = entity.get(ENTITY_ATTRIBUTE_TYPE)
        entity_value = entity.get(ENTITY_ATTRIBUTE_VALUE)
        entity_role = entity.get(ENTITY_ATTRIBUTE_ROLE)
        entity_group = entity.get(ENTITY_ATTRIBUTE_GROUP)

        if entity_value and entity_value == entity_text:
            entity_value = None

        use_short_syntax = (
            entity_value is None and entity_role is None and entity_group is None
        )

        if use_short_syntax:
            return f"[{entity_text}]({entity_type})"
        else:
            entity_dict = OrderedDict(
                [
                    (ENTITY_ATTRIBUTE_TYPE, entity_type),
                    (ENTITY_ATTRIBUTE_ROLE, entity_role),
                    (ENTITY_ATTRIBUTE_GROUP, entity_group),
                    (ENTITY_ATTRIBUTE_VALUE, entity_value),
                ]
            )
            entity_dict = OrderedDict(
                [(k, v) for k, v in entity_dict.items() if v is not None]
            )

            return f"[{entity_text}]{json.dumps(entity_dict)}"

class JsonTrainingDataReader(TrainingDataReader):
    def reads(self, s: Text, **kwargs: Any) -> "TrainingData":
        """Transforms string into json object and passes it on."""
        js = json.loads(s)
        return self.read_from_json(js, **kwargs)

    def read_from_json(self, js: Dict[Text, Any], **kwargs: Any) -> "TrainingData":
        """Reads TrainingData from a json object."""
        raise NotImplementedError


text:
var cp = require('child_process'),
    logger;

module.exports = function(robot){
    logger = robot.logger;

    robot.respond(/tug$/i, function(msg){
        pull(msg, function(){
            cleanup(function(){
                sepukku(msg);
            });
        });
    });
};

var pull = function(msg, callback){
    var gitpull = cp.spawn('git', ['pull']);

    gitpull.stdout.on('data', function (data) {
        logger.debug('[git-pull] ' + data);
    });

    gitpull.stderr.on('data', function (data) {
        logger.error('[git-pull] err: ' + data);
    });

    gitpull.on('close', function (code) {
        logger.info('[git-pull] updated repo, exited with code: ' + code);
        if(code !== 0){
            msg.send('Could not update hubot, git-pull exited with code ' + code);
        }
        else{
            callback()
        }
    });
},

cleanup = function(callback){
    var rm = cp.spawn('rm', ['-rf', process.cwd() + '/node_modules/hubot-scripts']);

    rm.stdout.on('data', function (data) {
        logger.debug('[rm] ' + data);
    });

    rm.stderr.on('data', function (data) {
        logger.error('[rm] err: ' + data);
    });

    rm.on('close', function (code) {
        logger.info('[rm] deleted hubot-scripts directory');
        if(code !== 0){
            msg.send('Could not update hubot, rm exited with code ' + code);
        }
        else{
            callback()
        }
    });
},

sepukku = function(msg){
    msg.send('hubot has climaxed, sleep now zzzzz ....');
    setTimeout(function(){
        process.exit(0);
    }, 2000);
};


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

	<dimen name="font_size_tiny">13sp</dimen>
	<dimen name="font_size_small">16sp</dimen>
	<dimen name="font_size_normal">20sp</dimen>
	<dimen name="font_size_xlarge">31sp</dimen>
	<dimen name="font_size_huge">46sp</dimen>
	<dimen name="symbol_size_normal">15sp</dimen>
	<dimen name="wallet_address_qr_size">112dp</dimen>
	<dimen name="wallet_address_qr_size_large">160dp</dimen>

</resources>


text:
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace Google.Protobuf.TestProtos.OldGenerator {

  /// Holder for reflection information generated from old_extensions2.proto
  public static partial class OldExtensions2Reflection {

    #region Descriptor
    /// File descriptor for old_extensions2.proto
    public static pbr::FileDescriptor Descriptor {
      get { return descriptor; }
    }
    private static pbr::FileDescriptor descriptor;

    static OldExtensions2Reflection() {
      byte[] descriptorData = global::System.Convert.FromBase64String(
          string.Concat(
            "ChVvbGRfZXh0ZW5zaW9uczIucHJvdG8aIGdvb2dsZS9wcm90b2J1Zi9kZXNj",
            "cmlwdG9yLnByb3RvOjQKCm1ldGhvZF9leHQSHi5nb29nbGUucHJvdG9idWYu",
            "TWV0aG9kT3B0aW9ucxiHrUsgASgJQiqqAidHb29nbGUuUHJvdG9idWYuVGVz",
            "dFByb3Rvcy5PbGRHZW5lcmF0b3JiBnByb3RvMw=="));
      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { pbr::FileDescriptor.DescriptorProtoFileDescriptor, },
          new pbr::GeneratedClrTypeInfo(null, null));
    }
    #endregion

  }
}

#endregion Designer generated code


text:
<?php

/**
 * Provides next triggers:

 *  admin/System/components/modules/install/process

 *  ['name'	=> module_name]

 *
 *  admin/System/components/modules/uninstall/process

 *  ['name'	=> module_name]

 *
 *  admin/System/components/modules/default_module/process

 *  ['name'	=> module_name]

 *
 *  admin/System/components/modules/db/process

 *  ['name'	=> module_name]

 *
 *  admin/System/components/modules/storage/process

 *  ['name'	=> module_name]
 */
namespace	cs;
$Cache		= Cache::instance();
$Config		= Config::instance();
$Core		= Core::instance();
$db			= DB::instance();
$L			= Language::instance();
$Page		= Page::instance();
$User		= User::instance();
$Permission	= Permission::instance();
$a			= Index::instance();
if (isset($_POST['update_modules_list'])) {
	/**
	 * List of currently presented modules in file system
	 */
	$modules_list	= array_fill_keys(
		$new_modules = get_files_list(MODULES, false, 'd'),
		[
			'active'	=> -1,
			'db'		=> [],
			'storage'	=> []
		]
	);
	/**
	 * Already known modules
	 */
	$modules		= &$Config->components['modules'];
	$old_modules	= array_keys($modules);
	/**
	 * Deletion of undefined modules permissions
	 */
	if ($new_modules != $old_modules) {
		$permissions_ids = [];
		foreach ($old_modules as $module_name) {
			if (!isset($modules_list[$module_name])) {
				$permissions_ids = array_merge(
					$permissions_ids,
					(array)$Permission->get(null, $module_name),
					(array)$Permission->get(null, "admin/$module_name"),
					(array)$Permission->get(null, "api/$module_name")
				);
			}
		}
		unset($old_modules, $module_name);
		if (!empty($permissions_ids)) {
			foreach ($permissions_ids as &$id) {
				$id = $id['id'];
			}
			unset($id);
			$Permission->del($permissions_ids);
		}
		unset($permissions_ids);
	}
	unset($new_modules, $old_modules);
	$modules			= array_merge($modules_list, array_intersect_key($modules, $modules_list));
	ksort($modules, SORT_STRING | SORT_FLAG_CASE);
	$a->save();
} elseif (isset($_POST['mode'], $_POST['module'], $Config->components['modules'][$_POST['module']])) {
	$module_name	= $_POST['module'];
	$module_data	= &$Config->components['modules'][$module_name];
	switch ($_POST['mode']) {
		case 'install':
			if ($module_data['active'] != -1) {
				break;
			}
			unset($Cache->languages);
			if (!Trigger::instance()->run(
				'admin/System/components/modules/install/process',
				[
					'name' => $module_name
				]
			)) {
				break;
			}
			$module_data['active'] = 0;
			if (isset($_POST['db']) && is_array($_POST['db']) && file_exists(MODULES."/$module_name/meta/db.json")) {
				$module_data['db'] = $_POST['db'];
				$db_json = file_get_json(MODULES."/$module_name/meta/db.json");
				time_limit_pause();
				foreach ($db_json as $database) {
					if ($module_data['db'][$database] == 0) {
						$db_type	= $Core->db_type;
					} else {
						$db_type	= $Config->db[$module_data['db'][$database]]['type'];
					}
					$sql_file	= MODULES."/$module_name/meta/install_db/$database/$db_type.sql";
					if (file_exists($sql_file)) {
						$db->{$module_data['db'][$database]}()->q(
							explode(';', file_get_contents($sql_file))
						);
					}
				}
				unset($db_json, $database, $db_type, $sql_file);
				time_limit_pause(false);
			}
			if (isset($_POST['storage']) && is_array($_POST['storage'])) {
				$module_data['storage'] = $_POST['storage'];
			}
			$a->save();
			clean_pcache();
			unset($Cache->functionality);
		break;
		case 'uninstall':
			if ($module_data['active'] == -1 || $module_name == 'System' || $module_name == $Config->core['default_module']) {
				break;
			}
			unset($Cache->languages);
			if (!Trigger::instance()->run(
				'admin/System/components/modules/uninstall/process',
				[
					'name' => $module_name
				]
			)) {
				break;
			}
			$module_data['active']	= -1;
			Trigger::instance()->run(
				'admin/System/components/modules/disable',
				[
					'name'	=> $module_name
				]
			);
			$Config->save();
			if (isset($module_data['db']) && file_exists(MODULES."/$module_name/meta/db.json")) {
				$db_json = file_get_json(MODULES."/$module_name/meta/db.json");
				time_limit_pause();
				foreach ($db_json as $database) {
					if ($module_data['db'][$database] == 0) {
						$db_type	= $Core->db_type;
					} else {
						$db_type	= $Config->db[$module_data['db'][$database]]['type'];
					}
					$sql_file	= MODULES."/$module_name/meta/uninstall_db/$database/$db_type.sql";
					if (file_exists($sql_file)) {
						$db->{$module_data['db'][$database]}()->q(
							explode(';', file_get_contents($sql_file))
						);
					}
				}
				unset($db_json, $database, $db_type, $sql_file);
				time_limit_pause(false);
			}
			$permissions_ids		= array_merge(
				$Permission->get(null, $module_name),
				$Permission->get(null, "$module_name/admin"),
				$Permission->get(null, "$module_name/api")
			);
			if (!empty($permissions_ids)) {
				foreach ($permissions_ids as &$id) {
					$id = $id['id'];
				}
				$Permission->del($permissions_ids);
			}
			$module_data			= ['active' => -1];
			$a->save();
			clean_pcache();
			unset($Cache->functionality);
		break;
		case 'update':
			/**
			 * Temporary disable module
			 */
			$active					= $module_data['active'];
			if ($active) {
				$module_data['active']	= 0;
				$Config->save();
				Trigger::instance()->run(
					'admin/System/components/modules/disable',
					[
						'name'	=> $module_name
					]
				);
			}
			$module_dir				= MODULES."/$module_name";
			/**
			 * Backing up some necessary information about current version
			 */
			copy("$module_dir/fs.json",		"$module_dir/fs_old.json");
			copy("$module_dir/meta.json",	"$module_dir/meta_old.json");
			/**
			 * Extracting new versions of files
			 */
			$tmp_dir	= 'phar://'.TEMP.'/'.$User->get_session().'_module_update.phar.php';
			$fs			= file_get_json("$tmp_dir/fs.json");
			$extract	= array_product(
				array_map(
					function ($index, $file) use ($tmp_dir, $module_dir) {
						if (
							!file_exists(dirname("$module_dir/$file")) &&
							!mkdir(dirname("$module_dir/$file"), 0700, true)
						) {
							return 0;
						}
						return (int)copy("$tmp_dir/fs/$index", "$module_dir/$file");
					},
					$fs,
					array_keys($fs)
				)
			);
			if (!$extract) {
				$Page->warning($L->module_files_unpacking_error);
				unlink("$module_dir/fs_old.json");
				unlink("$module_dir/meta_old.json");
				break;
			}
			unset($extract);
			$tmp_file	= TEMP.'/'.$User->get_session().'_module_update.phar.php';
			rename($tmp_file, $tmp_file = mb_substr($tmp_file, 0, -9));
			$api_request							= $Core->api_request(
				'System/admin/update_module',
				[
					'package'	=> str_replace(DIR, $Config->base_url(), $tmp_file)
				]
			);
			if ($api_request) {
				$success	= true;
				foreach ($api_request as $mirror => $result) {
					if ($result == 1) {
						$success	= false;
						$Page->warning($L->cant_unpack_module_on_mirror($mirror));
					}
				}
				if (!$success) {
					$Page->warning($L->module_files_unpacking_error);
					unlink("$module_dir/fs_old.json");
					unlink("$module_dir/meta_old.json");
					break;
				}
				unset($success, $mirror, $result);
			}
			unlink($tmp_file);
			unset($api_request, $tmp_file);
			file_put_json("$module_dir/fs.json", $fs = array_keys($fs));
			/**
			 * Removing of old unnecessary files and directories
			 */
			foreach (array_diff(file_get_json("$module_dir/fs_old.json"), $fs) as $file) {
				$file	= "$module_dir/$file";
				if (file_exists($file) && is_writable($file)) {
					unlink($file);
					if (!get_files_list($dir = dirname($file))) {
						rmdir($dir);
					}
				}
			}
			unset($fs, $file, $dir);
			/**
			 * Updating of module
			 */
			if ($active && file_exists("$module_dir/versions.json")) {
				$old_version	= file_get_json("$module_dir/meta_old.json")['version'];
				foreach (file_get_json("$module_dir/versions.json") as $version) {
					if (version_compare($old_version, $version, '<')) {
						/**
						 * PHP update script
						 */
						_include("$module_dir/meta/update/$version.php", true, false);
						/**
						 * Database update
						 */
						if (isset($module_data['db']) && file_exists("$module_dir/meta/db.json")) {
							$db_json = file_get_json("$module_dir/meta/db.json");
							time_limit_pause();
							foreach ($db_json as $database) {
								if ($module_data['db'][$database] == 0) {
									$db_type	= $Core->db_type;
								} else {
									$db_type	= $Config->db[$module_data['db'][$database]]['type'];
								}
								$sql_file	= "$module_dir/meta/update_db/$database/$version/$db_type.sql";
								if (file_exists($sql_file)) {
									$db->{$module_data['db'][$database]}()->q(
										explode(';', file_get_contents($sql_file))
									);
								}
							}
							unset($db_json, $database, $db_type, $sql_file);
							time_limit_pause(false);
						}
					}
				}
			}
			unlink("$module_dir/fs_old.json");
			unlink("$module_dir/meta_old.json");
			/**
			 * Restore previous module state
			 */
			if ($active) {
				$module_data['active']	= 1;
				$Config->save();
				clean_pcache();
				Trigger::instance()->run(
					'admin/System/components/modules/enable',
					[
						'name'	=> $module_name
					]
				);
				unset($Cache->languages);
			}
			$a->save();
			unset($Cache->functionality);
		break;
		case 'update_system':
			/**
			 * Temporary close site
			 */
			$site_mode				= $Config->core['site_mode'];
			if ($site_mode) {
				$Config->core['site_mode']	= 0;
				$Config->save();
			}
			$module_dir				= MODULES.'/System';
			/**
			 * Backing up some necessary information about current version
			 */
			copy(DIR.'/core/fs.json',		DIR.'/core/fs_old.json');
			copy("$module_dir/meta.json",	"$module_dir/meta_old.json");
			/**
			 * Extracting new versions of files
			 */
			$tmp_dir	= 'phar://'.TEMP.'/'.$User->get_session().'_update_system.phar.php';
			$fs			= file_get_json("$tmp_dir/fs.json")['core/fs.json'];
			$fs			= file_get_json("$tmp_dir/fs/$fs");
			$extract	= array_product(
				array_map(
					function ($index, $file) use ($tmp_dir, $module_dir) {
						if (
							!file_exists(dirname(DIR."/$file")) &&
							!mkdir(dirname(DIR."/$file"), 0700, true)
						) {
							return 0;
						}
						return (int)copy("$tmp_dir/fs/$index", DIR."/$file");
					},
					$fs,
					array_keys($fs)
				)
			);
			if (!$extract) {
				$Page->warning($L->system_files_unpacking_error);
				unlink(DIR.'/core/fs_old.json');
				unlink("$module_dir/meta_old.json");
				break;
			}
			unset($extract);
			$tmp_file	= TEMP.'/'.$User->get_session().'_update_system.phar.php';
			rename($tmp_file, $tmp_file = mb_substr($tmp_file, 0, -9));
			$api_request							= $Core->api_request(
				'System/admin/update_system',
				[
					'package'	=> str_replace(DIR, $Config->base_url(), $tmp_file)
				]
			);
			if ($api_request) {
				$success	= true;
				foreach ($api_request as $mirror => $result) {
					if ($result == 1) {
						$success	= false;
						$Page->warning($L->cant_unpack_system_on_mirror($mirror));
					}
				}
				if (!$success) {
					$Page->warning($L->system_files_unpacking_error);
					unlink(DIR.'/core/fs_old.json');
					unlink("$module_dir/meta_old.json");
					break;
				}
				unset($success, $mirror, $result);
			}
			unlink($tmp_file);
			unset($api_request, $tmp_file);
			file_put_json(DIR.'/core/fs.json', $fs = array_keys($fs));
			/**
			 * Removing of old unnecessary files and directories
			 */
			foreach (array_diff(file_get_json(DIR.'/core/fs_old.json'), $fs) as $file) {
				$file	= DIR."/$file";
				if (file_exists($file) && is_writable($file)) {
					unlink($file);
					if (!get_files_list($dir = dirname($file))) {
						rmdir($dir);
					}
				}
			}
			unset($fs, $file, $dir);
			/**
			 * Updating of System
			 */
			if (file_exists("$module_dir/versions.json")) {
				$old_version	= file_get_json("$module_dir/meta_old.json")['version'];
				foreach (file_get_json("$module_dir/versions.json") as $version) {
					if (version_compare($old_version, $version, '<')) {
						/**
						 * PHP update script
						 */
						_include("$module_dir/meta/update/$version.php", true, false);
						/**
						 * Database update
						 */
						if (isset($module_data['db']) && file_exists("$module_dir/meta/db.json")) {
							$db_json = file_get_json("$module_dir/meta/db.json");
							time_limit_pause();
							foreach ($db_json as $database) {
								if ($module_data['db'][$database] == 0) {
									$db_type	= $Core->db_type;
								} else {
									$db_type	= $Config->db[$module_data['db'][$database]]['type'];
								}
								$sql_file	= "$module_dir/meta/update_db/$database/$version/$db_type.sql";
								if (file_exists($sql_file)) {
									$db->{$module_data['db'][$database]}()->q(
										explode(';', file_get_contents($sql_file))
									);
								}
							}
							unset($db_json, $database, $db_type, $sql_file);
							time_limit_pause(false);
						}
					}
				}
			}
			unlink(DIR.'/core/fs_old.json');
			unlink("$module_dir/meta_old.json");
			/**
			 * Restore previous site mode
			 */
			if ($site_mode) {
				$Config->core['site_mode']	= 1;
			}
			$a->save();
			clean_pcache();
		break;
		case 'default_module':
			if (
				$module_data['active'] != 1 ||
				$module_name == $Config->core['default_module'] ||
				!(
					file_exists(MODULES."/$module_name/index.php") ||
					file_exists(MODULES."/$module_name/index.html") ||
					file_exists(MODULES."/$module_name/index.json")
				)
			) {
				break;
			}
			if (Trigger::instance()->run(
				'admin/System/components/modules/default_module/process',
				[
					'name' => $module_name
				]
			)) {
				$Config->core['default_module'] = $module_name;
				$a->save();
			}
		break;
		case 'db':
			if (Trigger::instance()->run(
				'admin/System/components/modules/db/process',
				[
					'name' => $module_name
				]
			)) {
				if (isset($_POST['db']) && is_array($_POST['db']) && count($Config->db) > 1) {
					$module_data['db'] = xap($_POST['db']);
					$a->save();
				}
			}
		break;
		case 'storage':
			if (Trigger::instance()->run(
				'admin/System/components/modules/storage/process',
				[
					'name' => $module_name
				]
			)) {
				if(isset($_POST['storage']) && is_array($_POST['storage']) && count($Config->storage) > 1) {
					$module_data['storage'] = xap($_POST['storage']);
					$a->save();
				}
			}
		break;
		case 'enable':
			$module_data['active'] = 1;
			$a->save();
			clean_pcache();
			Trigger::instance()->run(
				'admin/System/components/modules/enable',
				[
					'name'	=> $module_name
				]
			);
			unset(
				$Cache->functionality,
				$Cache->languages
			);
		break;
		case 'disable':
			$module_data['active'] = 0;
			$a->save();
			clean_pcache();
			Trigger::instance()->run(
				'admin/System/components/modules/disable',
				[
					'name'	=> $module_name
				]
			);
			unset(
				$Cache->functionality,
				$Cache->languages
			);
		break;
		case 'remove':
			if ($module_name == 'System' || $module_data['active'] != '-1') {
				break;
			}
			$ok			= true;
			get_files_list(
				MODULES."/$module_name",
				false,
				'fd',
				true,
				true,
				false,
				false,
				true,
				function ($item) use (&$ok) {
					if (is_writable($item)) {
						is_dir($item) ? @rmdir($item) : @unlink($item);
					} else {
						$ok = false;
					}
				}
			);
			if ($ok && @rmdir(MODULES."/$module_name")) {
				unset($Config->components['modules'][$module_name]);
				$a->save();
			} else {
				$a->save(false);
			}
		break;
	}
}


text:
using NUnit.Framework;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Osu.Tests
{
    public class TestSceneSpinnerApplication : OsuTestScene
    {
        [Test]
        public void TestApplyNewSpinner()
        {
            DrawableSpinner dho = null;

            AddStep("create spinner", () => Child = dho = new DrawableSpinner(prepareObject(new Spinner
            {
                Position = new Vector2(256, 192),
                IndexInCurrentCombo = 0,
                Duration = 500,
            }))
            {
                Clock = new FramedClock(new StopwatchClock())
            });

            AddStep("rotate some", () => dho.RotationTracker.AddRotation(180));
            AddAssert("rotation is set", () => dho.Result.RateAdjustedRotation == 180);

            AddStep("apply new spinner", () => dho.Apply(prepareObject(new Spinner
            {
                Position = new Vector2(256, 192),
                ComboIndex = 1,
                Duration = 1000,
            })));

            AddAssert("rotation is reset", () => dho.Result.RateAdjustedRotation == 0);
        }

        private Spinner prepareObject(Spinner circle)
        {
            circle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
            return circle;
        }
    }
}


text:
exec getRoomsPerTrack 'Other'
exec getRoomsPerTrack 'BI'


text: Dummy README to keep foodcritic from complaining.


text:
const fsActual = jest.requireActual("fs");
const fs = jest.genMockFromModule("fs");
const path = require("path");

let mockFiles;

fs.__setMockFiles = function (newMockFiles) {
  mockFiles = Object.create(null);
  Object.keys(newMockFiles).forEach((fileName) => {
    let newFileName = fileName;
    if (!path.isAbsolute(fileName)) {
      newFileName = path.resolve(process.cwd(), fileName);
    }
    mockFiles[newFileName] = newMockFiles[fileName];
  });
};

fs.__setJsonMockFiles = function (newMockFiles, stringify) {
  Object.keys(newMockFiles).forEach((fileName) => {
    newMockFiles[fileName] =
      stringify === false
        ? newMockFiles[fileName]
        : JSON.stringify(newMockFiles[fileName]);
  });
  fs.__setMockFiles(newMockFiles);
};

fs.readFileSync = jest.fn(function (fileName) {
  if (mockFiles !== undefined && mockFiles[fileName] !== undefined) {
    return mockFiles[fileName];
  } else {
    return fsActual.readFileSync(fileName, "utf8");
  }
});

module.exports = fs;


text:
from sqlobject import *
from sqlobject.tests.dbtest import *

########################################
## Test PosgreSQL sslmode
########################################

class TestSSLMode(SQLObject):
    test = StringCol()

def test_sslmode():
    setupClass(TestSSLMode)
    connection = TestSSLMode._connection
    if (connection.dbName != 'postgres') or \
            (not connection.module.__name__.startswith('psycopg')):
        # sslmode is only implemented by psycopg[12] PostgreSQL driver
        return

    connection = getConnection(sslmode='require')
    TestSSLMode._connection = connection
    test = TestSSLMode(test='test') # Connect to the DB to test sslmode

    connection.cache.clear()
    test = TestSSLMode.select()[0]
    assert test.test == 'test'


text:
var gulp = require("gulp");
var path = require("path");
var gulpVersion = require("./lib/gulp-version");

gulp.task("default", function() {
    return gulp
        .src([ "./package.json", "bower.json" ], { buffer: false })
        .pipe(gulpVersion(path.join(__dirname, "/gulp-version.json")))
        .pipe(gulp.dest("./test"));
});


text:
import { Component, EventEmitter, Input, Output, AfterViewInit } from '@angular/core';
import { Observable, Observer } from 'rxjs';

// Import models
import { TrafficPole, Camera } from '../../../service/models/CameraModel';

declare let jwplayer: any;

@Component({
    moduleId: module.id,
    selector: 'traffic-pole-modal-cmp',
    templateUrl: 'traffic-pole-modal.component.html'
})

export class TrafficPoleModalComponent implements AfterViewInit {
    @Input() TrafficPole: TrafficPole;
    @Output() Camera: EventEmitter<Camera>;
    @Output() Listener: EventEmitter<Observer<any>> = new EventEmitter<Observer<any>>();

    private observable: Observable<any>;

    constructor() {
        this.TrafficPole = null;
        this.Camera = new EventEmitter<Camera>();
    }

    ngAfterViewInit() {
        this.observable = new Observable<any>((observer: any) => {
            this.Listener.next(observer);
        });
        this.observable.subscribe(
            (result: any) => {
                setTimeout(() => {
                    for (var idx = 0; idx < this.TrafficPole.Cameras.length; idx++) {
                        var camera = this.TrafficPole.Cameras[idx];
                        if(camera.IsActive) {
                            var lastIdx = camera.StreamId.lastIndexOf('/');
                            var first = camera.StreamId.substring(0, lastIdx);
                            var second = camera.StreamId.substring(lastIdx + 1, camera.StreamId.length);
                            jwplayer(camera.StreamId).setup({
                                'flashplayer': 'assets/js/player.swf',
                                'file': second,
                                'streamer': first,
                                'controlbar': 'bottom',
                                'width': '100%',
                                'height': '450'
                            });
                        }
                    }
                }, 1000);
            },
            (err: any) => {
                console.log(err);
            }
        );
    }

    ClickAddCamera(camera: Camera): void {
        camera.Parent = this.TrafficPole;
        this.Camera.next(camera);
    }
}


text:
package com.azure.resourcemanager.digitaltwins.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.digitaltwins.fluent.models.DigitalTwinsDescriptionInner;
import com.azure.resourcemanager.digitaltwins.fluent.models.PrivateEndpointConnectionInner;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsDescription;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsIdentity;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsPatchDescription;
import com.azure.resourcemanager.digitaltwins.models.DigitalTwinsPatchProperties;
import com.azure.resourcemanager.digitaltwins.models.PrivateEndpointConnection;
import com.azure.resourcemanager.digitaltwins.models.ProvisioningState;
import com.azure.resourcemanager.digitaltwins.models.PublicNetworkAccess;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public final class DigitalTwinsDescriptionImpl
    implements DigitalTwinsDescription, DigitalTwinsDescription.Definition, DigitalTwinsDescription.Update {
    private DigitalTwinsDescriptionInner innerObject;

    private final com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public String location() {
        return this.innerModel().location();
    }

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public DigitalTwinsIdentity identity() {
        return this.innerModel().identity();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public OffsetDateTime createdTime() {
        return this.innerModel().createdTime();
    }

    public OffsetDateTime lastUpdatedTime() {
        return this.innerModel().lastUpdatedTime();
    }

    public ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public String hostname() {
        return this.innerModel().hostname();
    }

    public List<PrivateEndpointConnection> privateEndpointConnections() {
        List<PrivateEndpointConnectionInner> inner = this.innerModel().privateEndpointConnections();
        if (inner != null) {
            return Collections
                .unmodifiableList(
                    inner
                        .stream()
                        .map(inner1 -> new PrivateEndpointConnectionImpl(inner1, this.manager()))
                        .collect(Collectors.toList()));
        } else {
            return Collections.emptyList();
        }
    }

    public PublicNetworkAccess publicNetworkAccess() {
        return this.innerModel().publicNetworkAccess();
    }

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public DigitalTwinsDescriptionInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String resourceName;

    private DigitalTwinsPatchDescription updateDigitalTwinsPatchDescription;

    public DigitalTwinsDescriptionImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public DigitalTwinsDescription create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .createOrUpdate(resourceGroupName, resourceName, this.innerModel(), Context.NONE);
        return this;
    }

    public DigitalTwinsDescription create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .createOrUpdate(resourceGroupName, resourceName, this.innerModel(), context);
        return this;
    }

    DigitalTwinsDescriptionImpl(
        String name, com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager) {
        this.innerObject = new DigitalTwinsDescriptionInner();
        this.serviceManager = serviceManager;
        this.resourceName = name;
    }

    public DigitalTwinsDescriptionImpl update() {
        this.updateDigitalTwinsPatchDescription = new DigitalTwinsPatchDescription();
        return this;
    }

    public DigitalTwinsDescription apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .update(resourceGroupName, resourceName, updateDigitalTwinsPatchDescription, Context.NONE);
        return this;
    }

    public DigitalTwinsDescription apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .update(resourceGroupName, resourceName, updateDigitalTwinsPatchDescription, context);
        return this;
    }

    DigitalTwinsDescriptionImpl(
        DigitalTwinsDescriptionInner innerObject,
        com.azure.resourcemanager.digitaltwins.AzureDigitalTwinsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "digitalTwinsInstances");
    }

    public DigitalTwinsDescription refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .getByResourceGroupWithResponse(resourceGroupName, resourceName, Context.NONE)
                .getValue();
        return this;
    }

    public DigitalTwinsDescription refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDigitalTwins()
                .getByResourceGroupWithResponse(resourceGroupName, resourceName, context)
                .getValue();
        return this;
    }

    public DigitalTwinsDescriptionImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

    public DigitalTwinsDescriptionImpl withRegion(String location) {
        this.innerModel().withLocation(location);
        return this;
    }

    public DigitalTwinsDescriptionImpl withTags(Map<String, String> tags) {
        if (isInCreateMode()) {
            this.innerModel().withTags(tags);
            return this;
        } else {
            this.updateDigitalTwinsPatchDescription.withTags(tags);
            return this;
        }
    }

    public DigitalTwinsDescriptionImpl withIdentity(DigitalTwinsIdentity identity) {
        if (isInCreateMode()) {
            this.innerModel().withIdentity(identity);
            return this;
        } else {
            this.updateDigitalTwinsPatchDescription.withIdentity(identity);
            return this;
        }
    }

    public DigitalTwinsDescriptionImpl withPrivateEndpointConnections(
        List<PrivateEndpointConnectionInner> privateEndpointConnections) {
        this.innerModel().withPrivateEndpointConnections(privateEndpointConnections);
        return this;
    }

    public DigitalTwinsDescriptionImpl withPublicNetworkAccess(PublicNetworkAccess publicNetworkAccess) {
        this.innerModel().withPublicNetworkAccess(publicNetworkAccess);
        return this;
    }

    public DigitalTwinsDescriptionImpl withProperties(DigitalTwinsPatchProperties properties) {
        this.updateDigitalTwinsPatchDescription.withProperties(properties);
        return this;
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}


text:
#pragma once

#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

namespace renderpass {
namespace colorattachment {
/**
 * Creates color attachment description preconfigured with constants
 */
VkAttachmentDescription create(const VkFormat& format);

/**
 * Creates color attachment reference preconfigured with constants
 */
VkAttachmentReference ref(const uint32_t index);

} /* colorattachment */

namespace subpass {

/**
 *
 */
VkSubpassDescription createDescription(VkAttachmentReference& colorAttachment);

/**
 *
 */
VkSubpassDependency createDependency(const uint32_t index);

} /* subpass */
} /* renderpass */


text:
from datetime import datetime

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    "sphinx.ext.mathjax",
    "sphinx.ext.ifconfig",
    "sphinx.ext.githubpages",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

# General information about the project.
project = "Crispy"
copyright = (
    f"2016–{datetime.now().year}, Marius Retegan, "
    "European Synchrotron Radiation Facility, Grenoble, France"
)
author = "Marius Retegan"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "_drafts", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "default"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False

# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
    "navigation_depth": 2,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
    "**": [
        "relations.html",  # needs 'show_related': True theme option to display
        "searchbox.html",
    ]
}

# Don't add .txt suffix to source files:
html_sourcelink_suffix = ""


text: Programming tasks solutions


text:
Option Infer On

Imports System
Imports System.Runtime.InteropServices

Namespace Examples
    Friend Class Program
        <STAThread>
        Shared Sub Main(ByVal args() As String)
            Dim application As SolidEdgeFramework.Application = Nothing

            Try
                ' See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic.
                OleMessageFilter.Register()

                ' Attempt to connect to a running instance of Solid Edge.
                application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)

                ' Get the documents collection.
                Dim documents = application.Documents

                ' Iterate through the collection.
                For i As Integer = 1 To documents.Count
                    Dim document = CType(documents.Item(i), SolidEdgeFramework.SolidEdgeDocument)
                Next i
            Catch ex As System.Exception
                Console.WriteLine(ex)
            Finally
                OleMessageFilter.Unregister()
            End Try
        End Sub
    End Class
End Namespace


text:
using System;
using UnityEngine;
using UnityEngine.UI;
using Rayman;

public class PortalView : BasePanel{
	public const string NAME = "PortalView";
	public const int MAX_LEVEL = 1;
	public const int MAX_STAGE = 2;

	public GameObject Item;

	public override void OnPopup(){

	}

	void Start () {
		Transform tran = transform;
		Vector3 op = Item.transform.localPosition;

		for (int row = 0; row < MAX_STAGE; row++){
			for (int col = 0; col < MAX_LEVEL; col++){
				GameObject go = GameObject.Instantiate(Item);
				PortalItemView comp = go.GetComponent<PortalItemView>();
				comp.level = row * MAX_STAGE + col + 1;
				go.name = string.Format("level_{0}", comp.level);
				go.transform.SetParent(tran, false);
				go.transform.localPosition = new Vector3(op.x + col * 100.0f, op.y - row * 80.0f);
			}
		}

	}

	public override void Dispose(){

	}
}


text:
package org.apache.harmony.test.func.jpda.jdwp.scenario.EB01;

import org.apache.harmony.test.share.jpda.jdwp.debuggee.QARawDebuggee;

/**
 * Created on 03.10.2006
 */
public class EB01Debuggee extends QARawDebuggee {

    /* (non-Javadoc)
     * @see jpda.share.Debuggee#run()
     */
    public void run() {
        logWriter.println("EB01Debuggee: Start...");

        logWriter.println("EB01Debuggee: Creating new object of 'EB01Debuggee_Tested_Class'...");
        EB01Debuggee_Tested_Class dummyObject = new EB01Debuggee_Tested_Class();

        logWriter.println("EB01Debuggee: Finishing...");
    }

    public static void main(String[] args) {
        runDebuggee(EB01Debuggee.class);
    }
}

class EB01Debuggee_Tested_Class {
}


text:
- Deprecated. Replaced with McAfee Threat Intelligence Exchange v2. See McAfee Threat Intelligence Exchange v2 below for the list of new features and improvements.

##### New: McAfee Threat Intelligence Exchange v2
- Updated the Docker image to: *demisto/dxl:1.0.0.35274*.
- You can now pass more than one file to the following commands:
   - ***tie-set-file-reputation***
   - ***tie-file-references***
- Improved implementation of the ***file*** command, making it retrieve results faster.
- Added support for additional context outputs to the following commands:
   - ***file***
   - ***tie-file-references***
- Added support for handling data received from unmapped paths. The data is added to context (won't show in human readable).