text:
package water;

import java.lang.management.ManagementFactory;
import javax.management.*;
import water.util.LinuxProcFileReader;
import water.util.Log;
import water.init.*;

/**
 * Starts a thread publishing multicast HeartBeats to the local subnet: the
 * Leader of this Cloud.
 *
 * @author
 * @version 1.0
 */
public class HeartBeatThread extends Thread {
  public HeartBeatThread() {
    super("Heartbeat");
    setDaemon(true);
  }

  // Time between heartbeats.  Strictly several iterations less than the
  // timeout.
  static final int SLEEP = 1000;

  // Timeout in msec before we decide to not include a Node in the next round
  // of Paxos Cloud Membership voting.
  static public final int TIMEOUT = 60000;

  // Timeout in msec before we decide a Node is suspect, and call for a vote
  // to remove him.  This must be strictly greater than the TIMEOUT.
  static final int SUSPECT = TIMEOUT+500;

  // My Histogram. Called from any thread calling into the MM.
  // Singleton, allocated now so I do not allocate during an OOM event.
  static private final Cleaner.Histo myHisto = new Cleaner.Histo();

  // uniquely number heartbeats for better timelines
  static private int HB_VERSION;

  // Timeout in msec for all kinds of I/O operations on unresponsive clients.
  // Endlessly retry until this timeout, and then declare the client "dead",
  // and toss out all in-flight client ops
  static public final int CLIENT_TIMEOUT=1000;

  // The Run Method.
  // Started by main() on a single thread, this code publishes Cloud membership
  // to the Cloud once a second (across all members).  If anybody disagrees
  // with the membership Heartbeat, they will start a round of Paxos group
  // discovery.
  public void run() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName os;
    try {
      os = new ObjectName("java.lang:type=OperatingSystem");
    } catch( MalformedObjectNameException e ) {
      throw Log.throwErr(e);
    }
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    int counter = 0;
    while( true ) {
      // Update the interesting health self-info for publication also
      H2O cloud = H2O.CLOUD;
      HeartBeat hb = H2O.SELF._heartbeat;
      hb._hb_version = HB_VERSION++;
      hb._jvm_boot_msec= TimeLine.JVM_BOOT_MSEC;
      final Runtime run = Runtime.getRuntime();
      hb.set_free_mem  (run. freeMemory());
      hb.set_max_mem   (run.  maxMemory());
      hb.set_tot_mem   (run.totalMemory());
      hb._keys       = (H2O.STORE.size ());
      hb.set_mvalsz    (myHisto.histo(false)._cached);
      hb.set_tvalsz    (myHisto             ._total );
      hb._num_cpus   = (char)run.availableProcessors();

      // Run mini-benchmark every 5 mins.  However, on startup - do not have
      // all JVMs immediately launch a all-core benchmark - they will fight
      // with each other.  Stagger them using the hashcode.
      if( (counter+Math.abs(H2O.SELF.hashCode())) % 300 == 0) {
        hb._gflops   = Linpack.run(hb._cpus_allowed);
        hb._membw    = MemoryBandwidth.run(hb._cpus_allowed);
      }

      Object load = null;
      try {
        load = mbs.getAttribute(os, "SystemLoadAverage");
        if( (double)load == -1 ) // SystemLoadAverage not available on windows
          load = mbs.getAttribute(os, "SystemCpuLoad");
      } catch( Exception e ) {
        // Ignore, data probably not available on this VM
      }
      hb._system_load_average = load instanceof Double ? ((Double) load).floatValue() : 0;
      int rpcs = 0;
      for( H2ONode h2o : cloud._memary )
        rpcs += h2o.taskSize();
      hb._rpcs       = (char)rpcs;
      // Scrape F/J pool counts
      hb._fjthrds = new short[H2O.MAX_PRIORITY+1];
      hb._fjqueue = new short[H2O.MAX_PRIORITY+1];
      for( int i=0; i<hb._fjthrds.length; i++ ) {
        hb._fjthrds[i] = (short)H2O.getWrkThrPoolSize(i);
        hb._fjqueue[i] = (short)H2O.getWrkQueueSize(i);
      }
      hb._tcps_active= (char)H2ONode.TCPS.get();

      // get the usable and total disk storage for the partition where the
      // persistent KV pairs are stored
      hb.set_free_disk(H2O.getPM().getIce().getUsableSpace());
      hb.set_max_disk(H2O.getPM().getIce().getTotalSpace());

      // get cpu utilization for the system and for this process.  (linux only.)
      LinuxProcFileReader lpfr = new LinuxProcFileReader();
      lpfr.read();
      if (lpfr.valid()) {
        hb._system_idle_ticks = lpfr.getSystemIdleTicks();
        hb._system_total_ticks = lpfr.getSystemTotalTicks();
        hb._process_total_ticks = lpfr.getProcessTotalTicks();
        hb._process_num_open_fds = lpfr.getProcessNumOpenFds();
      }
      else {
        hb._system_idle_ticks = -1;
        hb._system_total_ticks = -1;
        hb._process_total_ticks = -1;
        hb._process_num_open_fds = -1;
      }
      hb._cpus_allowed = lpfr.getProcessCpusAllowed();
      if (H2O.ARGS.nthreads < hb._cpus_allowed) {
        hb._cpus_allowed = H2O.ARGS.nthreads;
      }
      hb._nthreads = H2O.ARGS.nthreads;
      hb._pid = lpfr.getProcessID();

      // Announce what Cloud we think we are in.
      // Publish our health as well.
      UDPHeartbeat.build_and_multicast(cloud, hb);

      // If we have no internet connection, then the multicast goes
      // nowhere and we never receive a heartbeat from ourselves!
      // Fake it now.
      long now = System.currentTimeMillis();
      H2O.SELF._last_heard_from = now;

      // Look for napping Nodes & propose removing from Cloud
      for( H2ONode h2o : cloud._memary ) {
        long delta = now - h2o._last_heard_from;
        if( delta > SUSPECT ) {// We suspect this Node has taken a dirt nap
          if( !h2o._announcedLostContact ) {
            Paxos.print("hart: announce suspect node",cloud._memary,h2o.toString());
            h2o._announcedLostContact = true;
          }
        } else if( h2o._announcedLostContact ) {
          Paxos.print("hart: regained contact with node",cloud._memary,h2o.toString());
          h2o._announcedLostContact = false;
        }
      }
      counter++;

      // Once per second, for the entire cloud a Node will multi-cast publish
      // itself, so other unrelated Clouds discover each other and form up.
      try { Thread.sleep(SLEEP); } // Only once-sec per entire Cloud
      catch( InterruptedException ignore ) { }
    }
  }
}


text:
<form class="form-horizontal" method="POST" action="<?php echo base_url()."operator/insert_siswa";?>">
	<fieldset>

		<legend>Tambah Data Siswa</legend>

		  Nomor Induk

		  <input id="nis" name="nis" placeholder="" class="form-control input-md" required="" type="text">

		  Nama Lengkap

		  <input id="nama_siswa" name="nama_siswa" placeholder="" class="form-control input-md" required="" type="text">

		  Jenis Kelamin

		    <select id="jk" name="jk" class="form-control">
		      <option value="L">Laki-laki</option>
		      <option value="P">Perempuan</option>
		    </select>

		  Alamat

		    <textarea class="form-control" id="alamat" name="alamat"></textarea>

		  Kelas

		    <select id="kelas" name="kelas" class="form-control">
		      <option value="X">X</option>
		      <option value="XI">XI</option>
		      <option value="XII">XII</option>
		    </select>

		  Nama Ayah

		  <input id="nama_ayah" name="nama_ayah" placeholder="" class="form-control input-md" required="" type="text">

		  Pekerjaan

		  <input id="pekerjaan" name="pekerjaan" placeholder="" class="form-control input-md" type="text">

		  No. Handphone

		  <input id="hp" name="hp" placeholder="" class="form-control input-md" required="" type="text">

		    <button type="submit" name="btn_tambah" value="tambah" class="btn btn-primary">Tambah</button>

		</fieldset>
	</form>

redpajama_set_name: RedPajamaGithub


text:
package org.teavm.jso.typedarrays;

import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;

/**
 *
 * @author Alexey Andreev
 */
public abstract class ArrayBuffer implements JSObject {
    @JSProperty
    public abstract int getByteLength();

    public abstract ArrayBuffer slice(int begin, int end);

    @JSBody(params = "length", script = "return new ArrayBuffer(length);")
    public static native ArrayBuffer create(int length);
}


text:
package com.daxlab.materialtabs.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

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

import com.daxlab.materialtabs.R;
import com.daxlab.materialtabs.fragments.OneFragment;
import com.daxlab.materialtabs.fragments.ThreeFragment;
import com.daxlab.materialtabs.fragments.TwoFragment;

public class IconTextTabsActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private int[] tabIcons = {
            R.drawable.ic_tab_favourite,
            R.drawable.ic_tab_call,
            R.drawable.ic_tab_contacts
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_icon_text_tabs);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager(viewPager);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
        setupTabIcons();
    }

    private void setupTabIcons() {
        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFrag(new OneFragment(), "One");
        adapter.addFrag(new TwoFragment(), "Two");
        adapter.addFrag(new ThreeFragment(), "Three");
        viewPager.setAdapter(adapter);
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFrag(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }
}


text:
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Tests\JsonApi\Schema\Relationship;

use PHPUnit\Framework\TestCase;
use WoohooLabs\Yin\JsonApi\Exception\DefaultExceptionFactory;
use WoohooLabs\Yin\JsonApi\Schema\Link\RelationshipLinks;
use WoohooLabs\Yin\JsonApi\Transformer\ResourceTransformation;
use WoohooLabs\Yin\JsonApi\Transformer\ResourceTransformer;
use WoohooLabs\Yin\Tests\JsonApi\Double\DummyData;
use WoohooLabs\Yin\Tests\JsonApi\Double\FakeRelationship;
use WoohooLabs\Yin\Tests\JsonApi\Double\StubJsonApiRequest;
use WoohooLabs\Yin\Tests\JsonApi\Double\StubResource;

class AbstractRelationshipTest extends TestCase
{
    /**
     * @test
     */
    public function createWithData(): void
    {
        $relationship = FakeRelationship::createWithData([], new StubResource());

        $data = $relationship->getRelationshipData();

        $this->assertEquals([], $data);
    }

    /**
     * @test
     */
    public function createWithLinks(): void
    {
        $relationship = FakeRelationship::createWithLinks(new RelationshipLinks());

        $links = $relationship->getLinks();

        $this->assertNotNull($links);
    }

    /**
     * @test
     */
    public function createWithMeta(): void
    {
        $relationship = FakeRelationship::createWithMeta(["abc" => "def"]);

        $meta = $relationship->getMeta();

        $this->assertEquals(["abc" => "def"], $meta);
    }

    /**
     * @test
     */
    public function setLinks(): void
    {
        $relationship = FakeRelationship::create();

        $relationship->setLinks(new RelationshipLinks());

        $this->assertNotNull($relationship->getLinks());
    }

    /**
     * @test
     */
    public function setData(): void
    {
        $relationship = $this->createRelationship();

        $relationship->setData(["id" => 1], new StubResource());

        $this->assertEquals(["id" => 1], $relationship->getRelationshipData());
    }

    /**
     * @test
     */
    public function setDataAsCallable(): void
    {
        $relationship = $this->createRelationship();

        $relationship->setDataAsCallable(
            function (): array {
                return ["id" => 1];
            },
            new StubResource()
        );
        $data = $relationship->getRelationshipData();

        $this->assertEquals(
            ["id" => 1],
            $data
        );
    }

    /**
     * @test
     */
    public function dataNotOmittedByDefault(): void
    {
        $relationship = $this->createRelationship();

        $isDataOmittedWhenNotIncluded = $relationship->isOmitDataWhenNotIncluded();

        $this->assertFalse($isDataOmittedWhenNotIncluded);
    }

    /**
     * @test
     */
    public function omitDataWhenNotIncluded(): void
    {
        $relationship = $this->createRelationship();

        $relationship->omitDataWhenNotIncluded();

        $this->assertTrue($relationship->isOmitDataWhenNotIncluded());
    }

    /**
     * @test
     */
    public function transformWithMeta(): void
    {
        $relationship = $this->createRelationship()
            ->setMeta(["abc" => "def"]);

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource(),
                [],
                "",
                new StubJsonApiRequest(),
                "",
                "",
                "",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertEquals(
            [
                "meta" => [
                    "abc" => "def",
                ],
                "data" => [],
            ],
            $relationshipObject
        );
    }

    /**
     * @test
     */
    public function transformWithLinks(): void
    {
        $relationship = $this->createRelationship()
            ->setLinks(new RelationshipLinks());

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource(),
                [],
                "",
                new StubJsonApiRequest(),
                "",
                "",
                "",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertEquals(
            [
                "links" => [],
                "data" => [],
            ],
            $relationshipObject
        );
    }

    /**
     * @test
     */
    public function transformWhenNotIncludedField(): void
    {
        $relationship = $this->createRelationship();

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource("user1"),
                [],
                "user1",
                new StubJsonApiRequest(["fields" => ["user1" => ""]]),
                "",
                "rel",
                "rel",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertNull($relationshipObject);
    }

    /**
     * @test
     */
    public function transformWithEmptyData(): void
    {
        $relationship = $this->createRelationship();

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource(),
                [],
                "",
                new StubJsonApiRequest(),
                "",
                "",
                "",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertEquals(
            [
                "data" => [],
            ],
            $relationshipObject
        );
    }

    /**
     * @test
     */
    public function transformWithEmptyOmittedData(): void
    {
        $relationship = $this->createRelationship()
            ->omitDataWhenNotIncluded();

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource(),
                [],
                "",
                new StubJsonApiRequest(),
                "",
                "",
                "",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertEquals(
            [],
            $relationshipObject
        );
    }

    /**
     * @test
     */
    public function transformWithEmptyOmittedDataWhenRelationship(): void
    {
        $relationship = $this->createRelationship()
            ->omitDataWhenNotIncluded();

        $relationshipObject = $relationship->transform(
            new ResourceTransformation(
                new StubResource(),
                [],
                "",
                new StubJsonApiRequest(),
                "",
                "dummy",
                "dummy",
                new DefaultExceptionFactory()
            ),
            new ResourceTransformer(),
            new DummyData(),
            []
        );

        $this->assertEquals(
            [
                "data" => [],
            ],
            $relationshipObject
        );
    }

    private function createRelationship(): FakeRelationship
    {
        return new FakeRelationship();
    }
}


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Trav. S. Africa 1:389. 1822

#### Original name
null

### Remarks
null


text:
// Elephant Puzzle.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <vector>

using namespace std;

int c = 1;
int d = 0;
// have the elephant turn
vector<char> turn(vector<char> a, int tPos) {
	if (a[tPos] == 'h') {
		a[tPos] = 'v';
	}
	else if (a[tPos] == 'v') {
		a[tPos] = 'h';
	}

	d++;
	cout << c++ << ". Turn." << endl;
	return a;
}

// slides everything all the way to the right
vector<char> slideRight(vector<char> a, int tPos) {
	vector<char>::iterator it = a.begin();
	if (a[tPos + 1] != 'v') {
		cout << c++ << ". Slide right." << endl;
		a.insert(it, ' ');
		return slideRight(a, tPos);
	}
	else {
		a = turn(a, tPos);
		return a;
	}
}

// slides everything all the way to the left
vector<char> slideLeft(vector<char> a, int tPos) {
	vector<char>::iterator it = a.begin();
	if (a[0] == ' ') {
		cout << c++ << ". Slide left." << endl;
		a.erase(it);
		return slideLeft(a, tPos);
	}
	else {
		a = turn(a, tPos);
		return a;
	}
}

vector<char> move(vector<char> a, int tPos, vector<char> correct) {
	if (a == correct) {
		cout << "The elephants are all lined up!\n" << endl;
		cout << "There are a total of " << c << " moves." << endl;
		cout << "If you consider sliding all elephants to one side as a single move, there are " << d << " moves." << endl;
		return a;
	}
	else if (a[0] != ' ') {
		d++;
		a = slideRight(a, tPos);
		return move(a, tPos, correct);
	}
	else {
		d++;
		a = slideLeft(a, tPos);
		return move(a, tPos, correct);
	}
}

int main() {
	int ele;

	cout << "How many elephants are there?" << endl;
	cin >> ele;

	while (ele < 1) {
		cout << "There have to be a positive number of elephants!\nHow many elephants are there?" << endl;
		cin >> ele;
	}

	vector<char> elephants, correct;
	int tPos = ele - 1;

	cout << "All steps are single changes." << endl;

	// build feeding area for the elephants
	for (int i(0); i < ele; i++) {
		elephants.push_back('v');
		correct.push_back('h');
	}
	elephants.push_back(' ');
	correct.push_back(' ');

	if (ele % 2 == 1) {
		elephants = turn(elephants, tPos);
	}

	elephants = move(elephants, tPos, correct);

	// let's see the pretty elephants
	/*for (int i(0); i < elephants.size(); i++) {
		cout << elephants[i];
	}
	cout << endl;*/

	return 0;
}


text:
#include <EPI/Document/DocumentParticles.moc.h>

#include <QAction>
#include <QMessageBox>

#include <QtToolbox/VFSDialog.moc.h>

#include <EPI/Document/StateRecorder.h>
#include <EPI/Document/Properties/PtyNodeEmitter/PtyDocNodeEmitters.h>
#include <EPI/Document/Properties/PtyNodeEmitter/PtyNodeEmitter.moc.h>
#include <EPI/Document/Properties/PtyDocInformation.moc.h>
#include <EPI/Document/Tools.h>

#include <EPI/ImportInfo/ImportParticlesInfo.h>

#include <EPI/Document/GuiDescription.h>
#include <EPI/DocumentRenderer.h>
namespace EPI
{
//-----------------------------------------------------------------------------
DocumentParticles::DocumentParticles(GuiDocument& guiGoc, const Ptr<DocumentRenderer>& pDocRdr)
:   DocumentBase(guiGoc, DOC_PARTICLES, pDocRdr),
    _pPtyDocNodeEmitters(null)
{
    Ptr<GuiDescription> pGuiDesc(new GuiDescription());

    Core::List<EViewportCameraNavigation> viewCameraNavigation;
    viewCameraNavigation.push_back(VIEWPORT_CAMERA_ORBITAL);
    viewCameraNavigation.push_back(VIEWPORT_CAMERA_QUAKE);
    pGuiDesc->setViewportCameraNavigations(viewCameraNavigation);

    setGuiDescription(pGuiDesc);

    _pPtyDocNodeEmitters = Ptr<PtyDocNodeEmitters>(new PtyDocNodeEmitters(getWorld(), false));
    getPropertyDocumentContent()->addChild(_pPtyDocNodeEmitters);

    //actions
    getActionsCreateProperty().push_back(new QAction("Node emitter", this));
    connect(getActionsCreateProperty().back(), SIGNAL(triggered()), this, SLOT(createPropertyNodeEmitter()));

}
//-----------------------------------------------------------------------------
DocumentParticles::DocumentParticles(GuiDocument& guiGoc, const Ptr<DocumentRenderer>& pDocRdr, const Core::String & fileName)
:   DocumentBase(guiGoc, DOC_PARTICLES, pDocRdr),
    _pPtyDocNodeEmitters(null)
{
    Ptr<GuiDescription> pGuiDesc(new GuiDescription());

    Core::List<EViewportCameraNavigation> viewCameraNavigation;
    viewCameraNavigation.push_back(VIEWPORT_CAMERA_ORBITAL);
    viewCameraNavigation.push_back(VIEWPORT_CAMERA_QUAKE);
    pGuiDesc->setViewportCameraNavigations(viewCameraNavigation);

    setGuiDescription(pGuiDesc);

    _pPtyDocNodeEmitters = Ptr<PtyDocNodeEmitters>(new PtyDocNodeEmitters(getWorld(), true));
    getPropertyDocumentContent()->addChild(_pPtyDocNodeEmitters);

    loadFile(fileName);

    //actions
    getActionsCreateProperty().push_back(new QAction("Node emitter", this));
    connect(getActionsCreateProperty().back(), SIGNAL(triggered()), this, SLOT(createPropertyNodeEmitter()));
}
//-----------------------------------------------------------------------------
DocumentParticles::~DocumentParticles()
{
}
//-----------------------------------------------------------------------------
Ptr<Property> DocumentParticles::getDefaultProperty() const
{
    if(getPropertyDocumentContent()->getChild(0)->getNbChildren() > 0)
        return getPropertyDocumentContent()->getChild(0)->getChild(0);
    else
        return getPropertyDocumentContent()->getChild(0);
}
//-----------------------------------------------------------------------------
Ptr<Universe::World> DocumentParticles::getWorldDeco()
{
    Ptr<PtyDocNodeEmitters> pPtyDocNodeEmitters = LM_DEBUG_PTR_CAST<PtyDocNodeEmitters>(getPropertyDocumentContent()->getChild(0));

    if (_worldDecoPath != pPtyDocNodeEmitters->getWorldDecoPath())
    {
        _worldDecoPath = pPtyDocNodeEmitters->getWorldDecoPath();
        _pWorldDeco = null;

        if (_worldDecoPath != L"")
        {
            _pWorldDeco = Ptr<Universe::World>( new Universe::World(getDocumentRenderer()->getRenderer(),  getDocumentRenderer()->getVFS(), null, getDocumentRenderer()->getAudioDevice()));
            _pWorldDeco->getNodeListener()->setGain(0.f);
            try
            {
                Ptr<Core::InputStream> pInput = getDocumentRenderer()->getVFS()->readFile(_worldDecoPath);
                Core::XMLDocument xmlDocument;
                xmlDocument.loadDocument(*pInput);
                _pWorldDeco->importWorldXML(xmlDocument);
            }
            catch(Core::Exception & e)
            {
                String message;
                message << L"An exception has been caught while extracting data from the XML file :\n" << e.getMessage();
                QMessageBox::critical( NULL, "Nyx", Core::String8(message).c_str());
            }

            copyEnvironnementParam(*getWorld(), *_pWorldDeco);
            configWorldDeco(getWorld(), _pWorldDeco);
        }
    }

    return _pWorldDeco;
}
//-----------------------------------------------------------------------------
void DocumentParticles::createPropertyNodeEmitter()
{
    const Core::List<Ptr<Property> >& selectedPties = getSelectedProperties();

    Ptr<Property> pPtyNodeEmitter = _pPtyDocNodeEmitters->createNewNodeEmitter();

    Ptr<Property> pParent;
    if (selectedPties.size() > 0)   pParent = selectedPties[0];
    else                            pParent = getPropertyDocumentContentStart();
    addChildRecording(getStateRecorder(), pPtyNodeEmitter, pParent);

    emit documentContentUpdated();
    contentIsModified();
}
//-----------------------------------------------------------------------------
void DocumentParticles::save()
{
    if (getTitle().startsWith(L"/") == true)
    {
        saveFile(getTitle());
    }
    else
    {
        saveAs();
    }
}
//-----------------------------------------------------------------------------
void DocumentParticles::saveAs()
{
    QtToolbox::VFSDialog dlg (*getDocumentRenderer()->getVFS(), QtToolbox::VFSD_SAVE, DOCUMENT_PARTS_EXT, NULL);
    if(dlg.exec())
    {
        Core::String fileName = dlg.getSelectedFile();
        saveFile(fileName);
        Ptr<PyDocumentInformation> pPinfo = LM_DEBUG_PTR_CAST<PyDocumentInformation>(getPyDocumentInformation());
        pPinfo->setTitle(fileName);
    }
}
//-----------------------------------------------------------------------------
void DocumentParticles::saveFile(const Core::String & fileName)
{
    Core::XMLDocument xmlDocument;

    for(int32 iChild = 0; iChild < _pPtyDocNodeEmitters->getNbChildren(); ++iChild)
    {
        Ptr<PtyNode> pProperty = LM_DEBUG_PTR_CAST<PtyNode>(_pPtyDocNodeEmitters->getChild(iChild));

        if (pProperty!=null)
        {
            Ptr<Universe::NodeEmitter> pNodeEmitter = LM_DEBUG_PTR_CAST<Universe::NodeEmitter>(pProperty->getUniverseNode());
            if(pNodeEmitter != null)
            {
                Ptr<Core::XMLNode> pXMLNode(new Core::XMLNode(L"node"));
                getWorld()->exportXML(pXMLNode, pNodeEmitter);
                xmlDocument.addNode(L"root", pXMLNode);
            }
        }
    }

    Ptr<Core::OutputStream> pOutput = getDocumentRenderer()->getVFS()->writeFile(fileName);
    xmlDocument.saveDocument(*pOutput);
    pOutput->close();

    Ptr<ImportParticlesInfo> pParticlesInfo(new ImportParticlesInfo());
    pParticlesInfo->particlesFileName = fileName;

    Ptr<Core::XMLDocument> pXMLParticlesInfo(new Core::XMLDocument());
    pParticlesInfo->exportXML(pXMLParticlesInfo);

    Core::String infoFile;
    infoFile << fileName << L".xml";
    Ptr<Core::OutputStream> pParticlesInfoOutput = getDocumentRenderer()->getVFS()->writeFile(infoFile);
    pXMLParticlesInfo->saveDocument(*pParticlesInfoOutput);
    pParticlesInfoOutput->close();

    setModified(false);
}
//-----------------------------------------------------------------------------
void DocumentParticles::loadFile(const Core::String & fileName)
{
    Core::XMLDocument xmlDocument;

    Ptr<Core::InputStream> pInput = getDocumentRenderer()->getVFS()->readFile(fileName);

    Ptr<Property> pPtyNodeEmitter = null;

    try
    {
        xmlDocument.loadDocument(*pInput);

        Core::List<Ptr<Core::XMLNode> > nodes;
        xmlDocument.getNodes(L"root", L"node", nodes);

        for(int32 iNode=0; iNode < nodes.size(); ++iNode)
        {
            Ptr<Universe::Node> pNode = getWorld()->importXML(nodes[iNode]);
            Ptr<Universe::NodeEmitter> pEmitter = LM_DEBUG_PTR_CAST<Universe::NodeEmitter>(pNode);

            pPtyNodeEmitter = _pPtyDocNodeEmitters->addNodeEmitter(pEmitter);

            getPropertyDocumentContent()->getChild(0)->addChild(pPtyNodeEmitter);
        }
    }
    catch(Core::Exception & e)
    {
        String message;
        message << L"An exception has been caught while extracting data from the XML file :\n" << e.getMessage();
        QMessageBox::critical( NULL, "Nyx", Core::String8(message).c_str());
    }
}
//-----------------------------------------------------------------------------
}  // namespace EPI


text:
from django.apps import AppConfig

class HomeConfig(AppConfig):
    name = 'home'


text:
package com.mapzen.tangram.geometry;

import com.mapzen.tangram.LngLat;

import java.util.List;
import java.util.Map;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * {@code Polyline} is a sequence of LngLat points and its properties.
 */
@Keep
public class Polyline extends Geometry {

    /**
     * Create a polyline geometry with properties.
     * @param polyline A list of coordinates that define the line segments of the feature.
     * @param properties The properties of the feature, used for filtering and styling according to
     * the scene file used by the map; may be null.
     */
    public Polyline(@NonNull final List<LngLat> polyline, @Nullable final Map<String, String> properties) {
        this.coordinates = new double[polyline.size() * 2];
        int i = 0;
        for (final LngLat point : polyline) {
            coordinates[i++] = point.longitude;
            coordinates[i++] = point.latitude;
        }
        if (properties != null) {
            this.properties = getStringMapAsArray(properties);
        }
    }

}


text:
#ifndef ART_RUNTIME_GC_COLLECTOR_IMMUNE_REGION_H_
#define ART_RUNTIME_GC_COLLECTOR_IMMUNE_REGION_H_

#include "base/macros.h"
#include "base/mutex.h"

namespace art {
namespace mirror {
class Object;
}  // namespace mirror
namespace gc {
namespace space {
class ContinuousSpace;
}  // namespace space

namespace collector {

// An immune region is a continuous region of memory for which all objects contained are assumed to
// be marked. This is used as an optimization in the GC to avoid needing to test the mark bitmap of
// the zygote, image spaces, and sometimes non moving spaces. Doing the ContainsObject check is
// faster than doing a bitmap read. There is no support for discontinuous spaces and you need to be
// careful that your immune region doesn't contain any large objects.
class ImmuneRegion {
 public:
  ImmuneRegion();
  void Reset();
  bool AddContinuousSpace(space::ContinuousSpace* space)
      EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
  bool ContainsSpace(const space::ContinuousSpace* space) const;
  // Returns true if an object is inside of the immune region (assumed to be marked).
  bool ContainsObject(const mirror::Object* obj) const ALWAYS_INLINE {
    // Note: Relies on integer underflow behavior.
    return reinterpret_cast<uintptr_t>(obj) - reinterpret_cast<uintptr_t>(begin_) < size_;
  }
  void SetBegin(mirror::Object* begin) {
    begin_ = begin;
    UpdateSize();
  }
  void SetEnd(mirror::Object* end) {
    end_ = end;
    UpdateSize();
  }

  mirror::Object* Begin() {
    return begin_;
  }
  mirror::Object* End() {
    return end_;
  }

 private:
  bool IsEmpty() const {
    return size_ == 0;
  }
  void UpdateSize() {
    size_ = reinterpret_cast<uintptr_t>(end_) - reinterpret_cast<uintptr_t>(begin_);
  }

  mirror::Object* begin_;
  mirror::Object* end_;
  uintptr_t size_;
};

}  // namespace collector
}  // namespace gc
}  // namespace art

#endif  // ART_RUNTIME_GC_COLLECTOR_IMMUNE_REGION_H_


text:
"""
send documents representing object data to elasticsearch for supported file extensions.
note: we truncate outbound documents to DOC_SIZE_LIMIT characters
(to bound memory pressure and request size to elastic)

a little knowledge on deletes and delete markers:
if bucket versioning is on:
    - `aws s3api delete-object (no --version-id)` or `aws s3 rm`
        - push a new delete marker onto the stack with a version-id
        - generate ObjectRemoved:DeleteMarkerCreated

if bucket versioning was on and is then turned off:
    - `aws s3 rm` or `aws s3api delete-object (no --version-id)`
        - replace event at top of stack
            - if a versioned delete marker, push a new one on top of it
            - if an un-versioned delete marker, replace that marker with new marker
            with version "null" (ObjectCreate will similarly replace the same with an object
            of version "null")
            - if object, destroy object
        - generate ObjectRemoved:DeleteMarkerCreated
            - problem: no way of knowing if DeleteMarkerCreated destroyed bytes
            or just created a DeleteMarker; this is usually given by the return
            value of `delete-object` but the S3 event has no knowledge of the same
    - `aws s3api delete-object --version-id VERSION`
        - destroy corresponding delete marker or object; v may be null in which
        case it will destroy the object with version null (occurs when adding
        new objects to a bucket that aws versioned but is no longer)
        - generate ObjectRemoved:Deleted

if bucket version is off and has always been off:
    - `aws s3 rm` or `aws s3api delete-object`
        - destroy object
        - generate a single ObjectRemoved:Deleted

counterintuitive things:
    - turning off versioning doesn't mean version stack can't get deeper (by at
    least 1) as indicated above in the case where a new marker is pushed onto
    the version stack
    - both creating a delete marker (soft delete) and hard deleting a delete marker
    by providing it's version-id will result in an eventType of DeleteObject
    and $.detail.responseElements.x-amz-delete-marker = true; it is therefore
    not possible to tell the difference between a new delete marker and the deletion
    of an existing one

See docs/EventBridge.md for more
"""

import datetime
import json
import os
import pathlib
import re
from os.path import split
from typing import Optional
from urllib.parse import unquote_plus

import boto3
import botocore
import nbformat
from dateutil.tz import tzutc
from document_queue import (
    EVENT_PREFIX,
    MAX_RETRY,
    DocTypes,
    DocumentQueue,
    get_content_index_bytes,
    get_content_index_extensions,
)
from jsonschema import ValidationError, draft7_format_checker, validate
from pdfminer.high_level import extract_text as extract_pdf_text
from tenacity import (
    retry,
    retry_if_exception,
    stop_after_attempt,
    wait_exponential,
)

from t4_lambda_shared.preview import (
    ELASTIC_LIMIT_LINES,
    extract_excel,
    extract_fcs,
    extract_parquet,
    get_bytes,
    get_preview_lines,
    trim_to_bytes,
)
from t4_lambda_shared.utils import (
    MANIFEST_PREFIX_V1,
    POINTER_PREFIX_V1,
    get_available_memory,
    get_quilt_logger,
    query_manifest_content,
    separated_env_to_iter,
)

# translate events to S3 native names
EVENTBRIDGE_TO_S3 = {
    "PutObject": EVENT_PREFIX["Created"] + "Put",
    "CopyObject": EVENT_PREFIX["Created"] + "Copy",
    "CompleteMultipartUpload": EVENT_PREFIX["Created"] + "CompleteMultipartUpload",
    # see map_event_name for complete logic
    "DeleteObject": None,
    # "DeleteObjects" is not handled since it does not contain enough information on
    # which objects where deleted
}

# ensure that we process events of known and expected shape
EVENT_SCHEMA = {
    'type': 'object',
    'properties': {
        'awsRegion': {
            'type': 'string'
        },
        'eventName': {
            'type': 'string'
        },
        'eventTime': {
            'type': 'string',
            'format': 'date-time'
        },
        's3': {
            'type': 'object',
            'properties': {
                'bucket': {
                    'type': 'object',
                    'properties': {
                        'name': {
                            'type': 'string'
                        }
                    },
                    'required': ['name'],
                    'additionalProperties': True
                },
                'object': {
                    'type': 'object',
                    'properties': {
                        'eTag': {
                            'type': 'string'
                        },
                        'isDeleteMarker': {
                            'type': 'string'
                        },
                        'key': {
                            'type': 'string'
                        },
                        'versionId': {
                            'type': 'string'
                        }
                    },
                    'required': ['key'],
                    'additionalProperties': True
                },
            },
            'required': ['bucket', 'object'],
            'additionalProperties': True
        },
    },
    'required': ['s3', 'eventName'],
    'additionalProperties': True
}
# Max number of PDF pages to extract because it can be slow
MAX_PDF_PAGES = 100
# 10 MB, see https://amzn.to/2xJpngN
NB_VERSION = 4  # default notebook version for nbformat
# currently only affects .parquet, TODO: extend to other extensions
assert 'SKIP_ROWS_EXTS' in os.environ
SKIP_ROWS_EXTS = separated_env_to_iter('SKIP_ROWS_EXTS')
SELECT_PACKAGE_META = "SELECT * from S3Object o WHERE o.version IS NOT MISSING LIMIT 1"
# No WHERE clause needed for aggregations since S3 Select skips missing fields for aggs
SELECT_PACKAGE_STATS = (
    "SELECT COALESCE(SUM(obj['size']), 0) as total_bytes,"
    " COUNT(obj['size']) as total_files from S3Object obj"
)
TEST_EVENT = "s3:TestEvent"
# we need to filter out GetObject and HeadObject calls generated by the present
#  lambda in order to display accurate analytics in the Quilt catalog
#  a custom user agent enables said filtration
USER_AGENT_EXTRA = " quilt3-lambdas-es-indexer"

def now_like_boto3():
    """ensure timezone UTC for consistency with boto3:
    Example of what boto3 returns on head_object:
        'LastModified': datetime.datetime(2019, 11, 6, 3, 1, 16, tzinfo=tzutc()),
    """
    return datetime.datetime.now(tz=tzutc())

def infer_extensions(key, ext):
    """guess extensions if possible"""
    # Handle special case of hive partitions
    # see https://www.qubole.com/blog/direct-writes-to-increase-spark-performance/
    if (
            re.fullmatch(r".c\d{3,5}", ext) or re.fullmatch(r".*-c\d{3,5}$", key)
            or key.endswith("_0")
            or ext == ".pq"
    ):
        return ".parquet"

    return ext

def should_retry_exception(exception):
    """don't retry certain 40X errors"""
    if hasattr(exception, 'response'):
        error_code = exception.response.get('Error', {}).get('Code', 218)
        return error_code not in ["402", "403", "404"]
    return False

@retry(
    stop=stop_after_attempt(MAX_RETRY),
    wait=wait_exponential(multiplier=2, min=4, max=10),
    retry=(retry_if_exception(should_retry_exception))
)
def select_manifest_meta(s3_client, bucket: str, key: str):
    """
    wrapper for retry and returning a string
    """
    try:
        raw = query_manifest_content(
            s3_client,
            bucket=bucket,
            key=key,
            sql_stmt=SELECT_PACKAGE_META
        )
        return raw.read()
    except botocore.exceptions.ClientError as cle:
        print(f"Unable to S3 select manifest: {cle}")

    return None

def do_index(
        s3_client,
        doc_queue: DocumentQueue,
        event_type: str,
        *,
        bucket: str,
        etag: str,
        ext: str,
        key: str,
        last_modified: str,
        text: str = '',
        size: int = 0,
        version_id: Optional[str] = None,
):
    """wrap dual indexing of packages and objects"""
    logger_ = get_quilt_logger()
    # index as object (always)
    logger_.debug("%s to indexing queue (%s)", key, event_type)
    doc_queue.append(
        event_type,
        DocTypes.OBJECT,
        bucket=bucket,
        ext=ext,
        etag=etag,
        key=key,
        last_modified=last_modified,
        size=size,
        text=text,
        version_id=version_id
    )
    # maybe index as package
    if index_if_package(
        s3_client,
        doc_queue,
        event_type,
        bucket=bucket,
        etag=etag,
        ext=ext,
        key=key,
        last_modified=last_modified,
        size=size,
        version_id=version_id,
    ):
        logger_.debug("%s indexed as package (%s)", key, event_type)

def index_if_package(
        s3_client,
        doc_queue: DocumentQueue,
        event_type: str,
        *,
        bucket: str,
        etag: str,
        ext: str,
        key: str,
        last_modified: str,
        version_id: Optional[str],
        size: int
) -> bool:
    """index manifest pointer files as package documents in ES
        Returns:
            - True if pointer to manifest (and passes to doc_queue for indexing)
            - False if not a manifest (no attempt at indexing)
    """
    logger_ = get_quilt_logger()
    pointer_prefix, pointer_file = split(key)
    handle = pointer_prefix[len(POINTER_PREFIX_V1):]
    if (
            not pointer_file
            or not pointer_prefix.startswith(POINTER_PREFIX_V1)
            or len(handle) < 3
            or '/' not in handle
    ):
        logger_.debug("Not indexing as manifest file s3://%s/%s", bucket, key)
        return False
    try:
        manifest_timestamp = int(pointer_file)
        is_tag = False
        if not 1451631600 <= manifest_timestamp <= 1767250800:
            logger_.warning("Unexpected manifest timestamp s3://%s/%s", bucket, key)
            return False
    except ValueError as err:
        is_tag = True
        logger_.debug("Non-integer manifest pointer: s3://%s/%s, %s", bucket, key, err)

    package_hash = ''
    first_dict = {}
    stats = None
    # we only need to get manifest contents for proper create events (not latest pointers)
    if event_type.startswith(EVENT_PREFIX["Created"]) and not is_tag:
        package_hash = get_plain_text(
            bucket,
            key,
            size,
            None,
            etag=etag,
            s3_client=s3_client,
            version_id=version_id,
        ).strip()
        manifest_key = f'{MANIFEST_PREFIX_V1}{package_hash}'
        first = select_manifest_meta(s3_client, bucket, manifest_key)
        stats = select_package_stats(s3_client, bucket, manifest_key)
        if not first:
            logger_.error("S3 select failed %s %s", bucket, manifest_key)
            return False
        try:
            first_dict = json.loads(first)
        except (json.JSONDecodeError, botocore.exceptions.ClientError) as exc:
            print(
                f"{exc}\n"
                f"\tFailed to select first line of manifest s3://{bucket}/{key}."
                f"\tGot {first}."
            )
            return False

    doc_queue.append(
        event_type,
        DocTypes.PACKAGE,
        bucket=bucket,
        etag=etag,
        ext=ext,
        handle=handle,
        key=key,
        last_modified=last_modified,
        # if we don't have the hash, we're processing a tag
        package_hash=(package_hash or pointer_file),
        package_stats=stats,
        pointer_file=pointer_file,
        comment=str(first_dict.get("message", "")),
        metadata=json.dumps(first_dict.get("user_meta", {})),
        version_id=version_id,
    )

    return True

def select_package_stats(s3_client, bucket, manifest_key) -> str:
    """use s3 select to generate file stats for package"""
    logger_ = get_quilt_logger()
    try:
        raw_stats = query_manifest_content(
            s3_client,
            bucket=bucket,
            key=manifest_key,
            sql_stmt=SELECT_PACKAGE_STATS
        ).read()

        if raw_stats:
            stats = json.loads(raw_stats)
            assert isinstance(stats['total_bytes'], int)
            assert isinstance(stats['total_files'], int)

            return stats

    except (
            AssertionError,
            botocore.exceptions.ClientError,
            json.JSONDecodeError,
            KeyError,
    ) as err:
        logger_.error("Unable to compute package stats via S3 select: %s", err)

    return None

def maybe_get_contents(bucket, key, ext, *, etag, version_id, s3_client, size):
    """get the byte contents of a file if it's a target for deep indexing"""
    logger_ = get_quilt_logger()

    if ext.endswith('.gz'):
        compression = 'gz'
        ext = ext[:-len('.gz')]
    else:
        compression = None
    logger_.debug(
        "Entering maybe_get_contents (could run out of mem.) %s %s %s", bucket, key, version_id
    )
    content = ""
    inferred_ext = infer_extensions(key, ext)
    if inferred_ext in get_content_index_extensions(bucket_name=bucket):
        if inferred_ext == ".fcs":
            obj = retry_s3(
                "get",
                bucket,
                key,
                size,
                etag=etag,
                s3_client=s3_client,
                version_id=version_id
            )
            body, info = extract_fcs(get_bytes(obj["Body"], compression), as_html=False)
            # be smart and just send column names to ES (instead of bloated full schema)
            # if this is not an HTML/catalog preview
            content = trim_to_bytes(f"{body}\n{info}", get_content_index_bytes(bucket_name=bucket))
        elif inferred_ext == ".ipynb":
            content = trim_to_bytes(
                # we have no choice but to fetch the entire notebook, because we
                # are going to parse it
                # warning: huge notebooks could spike memory here
                get_notebook_cells(
                    bucket,
                    key,
                    size,
                    compression,
                    etag=etag,
                    s3_client=s3_client,
                    version_id=version_id
                ),
                get_content_index_bytes(bucket_name=bucket),
            )
        elif inferred_ext == ".parquet":
            if size >= get_available_memory():
                print(f"{bucket}/{key} too large to deserialize; skipping contents")
                # at least index the key and other stats, but don't overrun memory
                # and fail indexing altogether
                return ""
            obj = retry_s3(
                "get",
                bucket,
                key,
                size,
                etag=etag,
                s3_client=s3_client,
                version_id=version_id
            )
            body, info = extract_parquet(
                get_bytes(obj["Body"], compression),
                as_html=False,
                skip_rows=(inferred_ext in SKIP_ROWS_EXTS),
                max_bytes=get_content_index_bytes(bucket_name=bucket),
            )
            # be smart and just send column names to ES (instead of bloated full schema)
            # if this is not an HTML/catalog preview
            columns = ','.join(list(info['schema']['names']))
            content = trim_to_bytes(f"{columns}\n{body}", get_content_index_bytes(bucket_name=bucket))
        elif inferred_ext == ".pdf":
            obj = retry_s3(
                "get",
                bucket,
                key,
                size,
                etag=etag,
                s3_client=s3_client,
                version_id=version_id
            )
            content = trim_to_bytes(
                extract_pdf(get_bytes(obj["Body"], compression)),
                get_content_index_bytes(bucket_name=bucket),
            )
        elif inferred_ext in (".xls", ".xlsx"):
            obj = retry_s3(
                "get",
                bucket,
                key,
                size,
                etag=etag,
                s3_client=s3_client,
                version_id=version_id
            )
            body, _ = extract_excel(get_bytes(obj["Body"], compression), as_html=False)
            content = trim_to_bytes(
                body,
                get_content_index_bytes(bucket_name=bucket),
            )
        else:
            content = get_plain_text(
                bucket,
                key,
                size,
                compression,
                etag=etag,
                s3_client=s3_client,
                version_id=version_id
            )

    return content

def extract_pdf(file_):
    """Get plain text form PDF for searchability.
    Args:
        file_ - file-like object opened in binary mode, pointing to XLS or XLSX
    Returns:
        pdf text as a string

    Warning:
        This function can be slow. The 8-page test PDF takes ~10 sec to turn into a string.
    """
    txt = extract_pdf_text(file_, maxpages=MAX_PDF_PAGES)
    # crunch down space; extract_text inserts multiple spaces
    # between words, literal newlines, etc.
    return re.sub(r"\s+", " ", txt)

def extract_text(notebook_str):
    """ Extract code and markdown
    Args:
        * nb - notebook as a string
    Returns:
        * str - select code and markdown source (and outputs)
    Pre:
        * notebook is well-formed per notebook version 4
        * "cell_type" is defined for all cells
        * "source" defined for all "code" and "markdown" cells
    Throws:
        * Anything nbformat.reads() can throw :( which is diverse and poorly
        documented, hence the `except Exception` in handler()
    Notes:
        * Deliberately decided not to index output streams and display strings
        because they were noisy and low value
        * Tested this code against ~6400 Jupyter notebooks in
        s3://alpha-quilt-storage/tree/notebook-search/
        * Might be useful to index "cell_type" : "raw" in the future
    See also:
        * Format reference https://nbformat.readthedocs.io/en/latest/format_description.html
    """
    formatted = nbformat.reads(notebook_str, as_version=NB_VERSION)
    text = []
    for cell in formatted.get("cells", []):
        if "source" in cell and cell.get("cell_type") in ("code", "markdown"):
            text.append(cell["source"])

    return "\n".join(text)

def get_notebook_cells(bucket, key, size, compression, *, etag, s3_client, version_id):
    """extract cells for ipynb notebooks for indexing"""
    text = ""
    try:
        obj = retry_s3(
            "get",
            bucket,
            key,
            size,
            etag=etag,
            s3_client=s3_client,
            version_id=version_id
        )
        data = get_bytes(obj["Body"], compression)
        notebook = data.getvalue().decode("utf-8")
        try:
            text = extract_text(notebook)
        except (json.JSONDecodeError, nbformat.reader.NotJSONError):
            print(f"Invalid JSON in {key}.")
        except (KeyError, AttributeError) as err:
            print(f"Missing key in {key}: {err}")
        # there might be more errors than covered by test_read_notebook
        # better not to fail altogether
        except Exception as exc:  # pylint: disable=broad-except
            print(f"Exception in file {key}: {exc}")
    except UnicodeDecodeError as uni:
        print(f"Unicode decode error in {key}: {uni}")

    return text

def get_plain_text(
        bucket,
        key,
        size,
        compression,
        *,
        etag,
        s3_client,
        version_id
) -> str:
    """get plain text object contents"""
    text = ""
    try:
        obj = retry_s3(
            "get",
            bucket,
            key,
            size,
            etag=etag,
            s3_client=s3_client,
            limit=get_content_index_bytes(bucket_name=bucket),
            version_id=version_id
        )
        lines = get_preview_lines(
            obj["Body"],
            compression,
            ELASTIC_LIMIT_LINES,
            get_content_index_bytes(bucket_name=bucket),
        )
        text = '\n'.join(lines)
    except UnicodeDecodeError as ex:
        print(f"Unicode decode error in {key}", ex)

    return text

def make_s3_client():
    """make a client with a custom user agent string so that we can
    filter the present lambda's requests to S3 from object analytics"""
    configuration = botocore.config.Config(user_agent_extra=USER_AGENT_EXTRA)
    return boto3.client("s3", config=configuration)

def map_event_name(event: dict):
    """transform eventbridge names into S3-like ones"""
    input_ = event["eventName"]
    if input_ in EVENTBRIDGE_TO_S3:
        if input_ == "DeleteObject":
            if event["s3"]["object"].get("isDeleteMarker"):
                return EVENT_PREFIX["Removed"] + "DeleteMarkerCreated"
            return EVENT_PREFIX["Removed"] + "Delete"
        # all non-delete events just use the map
        return EVENTBRIDGE_TO_S3[input_]
    # leave event type unchanged if we don't recognize it
    return input_

def shape_event(event: dict):
    """check event schema, return None if schema check fails"""
    logger_ = get_quilt_logger()

    try:
        validate(
            instance=event,
            schema=EVENT_SCHEMA,
            # format_checker= required for for format:date-time validation
            # (we also need strict-rfc3339 in requirements.txt)
            format_checker=draft7_format_checker,
        )
    except ValidationError as error:
        logger_.error("Invalid event format: %s\n%s", error, event)
        return None
    # be a good citizen and don't modify params
    return {
        **event,
        'eventName': map_event_name(event),
    }

def handler(event, context):
    """enumerate S3 keys in event, extract relevant data, queue events, send to
    elastic via bulk() API
    """
    logger_ = get_quilt_logger()
    # message is a proper SQS message, which either contains a single event
    # (from the bucket notification system) or batch-many events as determined
    # by enterprise/**/bulk_loader.py
    # An exception that we'll want to re-raise after the batch sends
    content_exception = None
    batch_processor = DocumentQueue(context)
    s3_client = make_s3_client()
    for message in event["Records"]:
        body = json.loads(message["body"])
        body_message = json.loads(body["Message"])
        if "Records" not in body_message:
            # could be TEST_EVENT, or another unexpected event; skip it
            logger_.error("No 'Records' key in message['body']: %s", message)
            continue
        events = body_message["Records"]
        # event is a single S3 event
        for event_ in events:
            validated = shape_event(event_)
            if not validated:
                logger_.debug("Skipping invalid event %s", event_)
                continue
            event_ = validated
            logger_.debug("Processing %s", event_)
            try:
                event_name = event_["eventName"]
                # Process all Create:* and Remove:* events
                if not any(event_name.startswith(n) for n in EVENT_PREFIX.values()):
                    logger_.warning("Skipping unknown event type: %s", event_name)
                    continue
                bucket = event_["s3"]["bucket"]["name"]
                # In the grand tradition of IE6, S3 events turn spaces into '+'
                # TODO: check if eventbridge events do the same thing with +
                key = unquote_plus(event_["s3"]["object"]["key"])
                version_id = event_["s3"]["object"].get("versionId", None)
                # ObjectRemoved:Delete does not include "eTag"
                etag = event_["s3"]["object"].get("eTag", "")
                # synthetic events from bulk scanner might define lastModified
                last_modified = (
                    event_["s3"]["object"].get("lastModified") or event_["eventTime"]
                )
                # Get two levels of extensions to handle files like .csv.gz
                path = pathlib.PurePosixPath(key)
                ext1 = path.suffix
                ext2 = path.with_suffix('').suffix
                ext = (ext2 + ext1).lower()
                # Handle delete and deletemarker first and then continue so that
                # head_object and get_object (below) don't fail
                if event_name.startswith(EVENT_PREFIX["Removed"]):
                    do_index(
                        s3_client,
                        batch_processor,
                        event_name,
                        bucket=bucket,
                        etag=etag,
                        ext=ext,
                        key=key,
                        last_modified=last_modified,
                        version_id=version_id
                    )
                    continue
                try:
                    head = retry_s3(
                        "head",
                        bucket,
                        key,
                        s3_client=s3_client,
                        version_id=version_id,
                        etag=etag
                    )
                except botocore.exceptions.ClientError as first:
                    logger_.warning("head_object error: %s", first)
                    # "null" version sometimes results in 403s for buckets
                    # that have changed versioning, retry without it
                    if (first.response.get('Error', {}).get('Code') == "403"
                            and version_id == "null"):
                        try:
                            head = retry_s3(
                                "head",
                                bucket,
                                key,
                                s3_client=s3_client,
                                version_id=None,
                                etag=etag
                            )
                        except botocore.exceptions.ClientError as second:
                            # this will bypass the DLQ but that's the right thing to do
                            # as some listed objects may NEVER succeed head requests
                            # (e.g. foreign owner) and there's no reason to torpedo
                            # the whole batch (which might include good files)
                            logger_.warning("Retried head_object error: %s", second)
                    logger_.error("Fatal head_object, skipping event: %s", event_)
                    continue
                # backfill fields based on the head_object
                size = head["ContentLength"]
                last_modified = last_modified or head["LastModified"].isoformat()
                etag = head.get("etag") or etag
                version_id = head.get("VersionId") or version_id
                try:
                    text = maybe_get_contents(
                        bucket,
                        key,
                        ext,
                        etag=etag,
                        version_id=version_id,
                        s3_client=s3_client,
                        size=size
                    )
                # we still want an entry for this document in elastic so that, e.g.,
                # the file counts from elastic are correct
                # these exceptions can happen for a variety of reasons (e.g. glacier
                # storage class, index event arrives after delete has occurred, etc.)
                # given how common they are, we shouldn't fail the batch for this
                except Exception as exc:  # pylint: disable=broad-except
                    text = ""
                    logger_.warning("Content extraction failed %s %s %s", bucket, key, exc)

                do_index(
                    s3_client,
                    batch_processor,
                    event_name,
                    bucket=bucket,
                    etag=etag,
                    ext=ext,
                    key=key,
                    last_modified=last_modified,
                    size=size,
                    text=text,
                    version_id=version_id
                )

            except botocore.exceptions.ClientError as boto_exc:
                if not should_retry_exception(boto_exc):
                    logger_.warning("Skipping non-fatal exception: %s", boto_exc)
                    continue
                logger_.critical("Failed record: %s, %s", event, boto_exc)
                raise boto_exc
    # flush the queue
    batch_processor.send_all()

def retry_s3(
        operation,
        bucket,
        key,
        size=None,
        limit=None,
        *,
        etag,
        version_id,
        s3_client
):
    """retry head or get operation to S3 with; stop before we run out of time.
    retry is necessary since, due to eventual consistency, we may not
    always get the required version of the object.
    """
    logger_ = get_quilt_logger()

    if operation == "head":
        function_ = s3_client.head_object
    elif operation == "get":
        function_ = s3_client.get_object
    else:
        raise ValueError(f"unexpected operation: {operation}")
    # Keyword arguments to function_
    arguments = {
        "Bucket": bucket,
        "Key": key
    }
    if operation == 'get' and size and limit:
        # can only request range if file is not empty
        arguments['Range'] = f"bytes=0-{min(size, limit) - 1}"
    if version_id:
        arguments['VersionId'] = version_id
    elif etag:
        arguments['IfMatch'] = etag

    logger_.debug("Entering @retry: %s, %s", operation, arguments)

    @retry(
        # debug
        reraise=True,
        stop=stop_after_attempt(MAX_RETRY),
        wait=wait_exponential(multiplier=2, min=4, max=10),
        retry=(retry_if_exception(should_retry_exception))
    )
    def call():
        """local function so we can set stop_after_delay dynamically"""
        # TODO: remove all this, stop_after_delay is not dynamically loaded anymore
        return function_(**arguments)

    return call()


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<TITLE>
org.apache.pig.backend.hadoop.streaming (Pig 0.8.0-CDH3B4-SNAPSHOT API)
</TITLE>

<META NAME="date" CONTENT="2011-02-16">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../../stylesheet.css" TITLE="Style">

org.apache.pig.backend.hadoop.streaming

Classes

HadoopExecutableManager


text:
namespace Nancy.Tests.Unit.Responses
{
    using System;
    using System.IO;
    using FakeItEasy;
    using Nancy.Responses;
    using Xunit;

    public class StreamResponseFixture
    {
        [Fact]
        public void Should_copy_stream_to_output_when_body_invoked()
        {
            // Given
            var streamContent =
                new byte[] { 1, 2, 3, 4, 5 };

            var inputStream =
                new MemoryStream(streamContent);

            var response =
                new StreamResponse(() => inputStream, "test");

            var outputStream = new MemoryStream();

            // When
            response.Contents.Invoke(outputStream);

            // Then
            outputStream.ToArray().ShouldEqualSequence(streamContent);
        }

        [Fact]
        public void Should_return_content_of_stream_from_current_location_of_stream()
        {
            // Given
            var streamContent =
                new byte[] { 1, 2, 3, 4, 5 };

            var inputStream =
                new MemoryStream(streamContent) { Position = 2 };

            var response =
                new StreamResponse(() => inputStream, "test");

            var outputStream = new MemoryStream();

            var expectedContent =
                new byte[] { 3, 4, 5 };

            // When
            response.Contents.Invoke(outputStream);

            // Then
            outputStream.ToArray().ShouldEqualSequence(expectedContent);
        }

        [Fact]
        public void Should_throw_exception_when_stream_is_non_readable()
        {
            // Given
            var inputStream =
                new TestStream(canRead: false);

            var response =
                new StreamResponse(() => inputStream, "test");

            var outputStream = new MemoryStream();

            // When
            var exception = Record.Exception(() => response.Contents.Invoke(outputStream));

            // Then
            exception.ShouldNotBeNull();
        }

        public class TestStream : Stream
        {
            public TestStream(bool canRead = true, bool canWrite = true)
            {
                this.CanRead = canRead;
                this.CanWrite = canWrite;
            }

            public override bool CanRead { get; }

            public override bool CanSeek
            {
                get { return true; }
            }

            public override bool CanWrite  { get; }

            public override long Length
            {
                get { return 0; }
            }

            public override long Position
            {
                get { return 0; }
                set { }
            }

            public override void Flush()
            {
            }
            public override int Read(byte[] buffer, int offset, int count)
            {
                return 0;
            }

            public override long Seek(long offset, SeekOrigin origin)
            {
                return 0;
            }

            public override void SetLength(long value)
            {
            }

            public override void Write(byte[] buffer, int offset, int count)
            {
            }
        }
    }
}


text:
/**
 * Simple version of jQuery's Deferred.
 */

class Deferred {
    constructor() {
        this.promise = new Promise((resolve, reject) => {
            this.resolve = resolve;
            this.reject = reject;
        });
    }

    then(callback) {
        return this.promise.then(callback);
    }
}

module.exports = Deferred;


text:
/**
 * Created by hxsd on 2016/6/7.
 */
angular.module("myapp").controller("xiangxiCtrl",function($scope){
    $scope.message = "这是一个xiangxi页面"
})


text:
package com.jivesoftware.os.routing.bird.http.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jivesoftware.os.mlogger.core.MetricLogger;
import com.jivesoftware.os.mlogger.core.MetricLoggerFactory;
import com.jivesoftware.os.routing.bird.shared.InstanceThrown;
import com.jivesoftware.os.routing.bird.shared.InstanceThrowns;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author jonathan.colt
 */
public class HttpDeliveryClientThrown implements Runnable {

    private static final MetricLogger LOG = MetricLoggerFactory.getLogger();

    private final String instanceId;
    private final HttpRequestHelper httpRequestHelper;
    private final String path;
    private final long interval;
    private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

    public HttpDeliveryClientThrown(String instanceId, HttpRequestHelper httpRequestHelper, String path, long interval) {
        this.instanceId = instanceId;
        this.httpRequestHelper = httpRequestHelper;
        this.path = path;
        this.interval = interval;
    }

    public void start() {
        scheduledExecutorService.scheduleAtFixedRate(this, interval, interval, TimeUnit.MILLISECONDS);
    }

    public void stop() throws InterruptedException {
        if (httpRequestHelper != null) {
            scheduledExecutorService.shutdownNow();
            scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS);
        }
    }

    @Override
    public void run() {
        try {
            List<InstanceThrown> throwns = new ArrayList<>();
//            throwns

            httpRequestHelper.executeRequest(new InstanceThrowns(instanceId, throwns), path, String.class, null);
        } catch (Exception x) {
            LOG.warn("Failed to deliver client health.", x);
        }
    }

    static HttpRequestHelper buildRequestHelper(OAuthSigner signer, String host, int port) {
        HttpClientConfig httpClientConfig = HttpClientConfig.newBuilder().build();
        HttpClientFactory httpClientFactory = new HttpClientFactoryProvider().createHttpClientFactory(Arrays.<HttpClientConfiguration>asList(httpClientConfig),
            false);
        HttpClient httpClient = httpClientFactory.createClient(signer, host, port);
        HttpRequestHelper requestHelper = new HttpRequestHelper(httpClient, new ObjectMapper());
        return requestHelper;
    }

}


text:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ldml SYSTEM "http://www.unicode.org/cldr/dtd/1.4/ldml.dtd">
<ldml>
	<identity>
		<version number="$Revision: 1.43 $"/>
		<generation date="$Date: 2006/06/28 01:23:33 $"/>
		<language type="fr"/>
		<territory type="CA"/>
	</identity>
	<dates>
		<calendars>
			<calendar type="gregorian">
				<dateFormats>
					<dateFormatLength type="medium">
						<dateFormat>
							<pattern>yy-MM-dd</pattern>
						</dateFormat>
					</dateFormatLength>
					<dateFormatLength type="short">
						<dateFormat>
							<pattern>yy-MM-dd</pattern>
						</dateFormat>
					</dateFormatLength>
				</dateFormats>
				<timeFormats>
					<timeFormatLength type="full">
						<timeFormat>
							<pattern>HH' h 'mm' min 'ss' s 'z</pattern>
						</timeFormat>
					</timeFormatLength>
				</timeFormats>
				<dateTimeFormats>
					<availableFormats>
						<dateFormatItem id="MMdd" draft="provisional">MM-dd</dateFormatItem>
						<dateFormatItem id="yyMM" draft="provisional">yy-MM</dateFormatItem>
					</availableFormats>
				</dateTimeFormats>
			</calendar>
		</calendars>
	</dates>
	<numbers>
		<currencyFormats>
			<currencyFormatLength>
				<currencyFormat>
					<pattern>#,##0.00 ¤;(#,##0.00¤)</pattern>
				</currencyFormat>
			</currencyFormatLength>
		</currencyFormats>
		<currencies>
			<currency type="CAD">
				<symbol>$</symbol>
			</currency>
			<currency type="USD">
				<symbol>$ US</symbol>
			</currency>
		</currencies>
	</numbers>
</ldml>


text:
class Admin::AdminController < ApplicationController

  before_filter :user_valid?

  layout 'admin'

  def user_valid?
    if logged_in?
      redirect_to root_path, :notice => t('.invalid_account') unless Cartoset::Config.valid_user?(current_user)
    else
      session[:return_to] = request.request_uri
      redirect_to login_required_path
    end
  end
  protected :user_valid?

end


text:
package com.asakusafw.lang.compiler.extension.iterative;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import org.junit.Test;

import com.asakusafw.lang.compiler.analyzer.FlowGraphAnalyzer;
import com.asakusafw.lang.compiler.analyzer.JobflowAnalyzer;
import com.asakusafw.lang.compiler.extension.iterative.mock.BatchWithAttributes;
import com.asakusafw.lang.compiler.extension.iterative.mock.MockBatch;
import com.asakusafw.lang.compiler.extension.iterative.mock.MockExternalPortAnalyzer;
import com.asakusafw.lang.compiler.extension.iterative.mock.MockJobflow;
import com.asakusafw.lang.compiler.extension.iterative.mock.PlainBatch;
import com.asakusafw.lang.compiler.model.description.Descriptions;
import com.asakusafw.lang.compiler.model.graph.Batch;
import com.asakusafw.lang.compiler.model.graph.BatchElement;
import com.asakusafw.lang.compiler.model.graph.ExternalInput;
import com.asakusafw.lang.compiler.model.graph.Jobflow;
import com.asakusafw.lang.compiler.model.info.BatchInfo;
import com.asakusafw.lang.compiler.model.iterative.IterativeExtension;

/**
 * Test for {@link IterativeBatchAnalyzer}.
 */
public class IterativeBatchAnalyzerTest {

    /**
     * is batch.
     */
    @Test
    public void is_batch() {
        assertThat(IterativeBatchAnalyzer.isBatch(PlainBatch.class), is(false));
        assertThat(IterativeBatchAnalyzer.isBatch(MockBatch.class), is(true));
        assertThat(IterativeBatchAnalyzer.isBatch(MockJobflow.class), is(false));
    }

    /**
     * analyze info.
     */
    @Test
    public void info_simple() {
        BatchInfo info = IterativeBatchAnalyzer.analyzeInfo(MockBatch.class);
        assertThat(info.getBatchId(), is("MockBatch"));
        assertThat(info.getDescriptionClass(), is(Descriptions.classOf(MockBatch.class)));
        assertThat(info.getComment(), is(nullValue()));
        assertThat(info.getParameters(), is(empty()));
        assertThat(info.getAttributes(), not(hasItem(BatchInfo.Attribute.STRICT_PARAMETERS)));
    }

    /**
     * batch with parameters.
     */
    @Test
    public void info_parameters() {
        BatchInfo info = IterativeBatchAnalyzer.analyzeInfo(BatchWithAttributes.class);
        assertThat(info.getBatchId(), is("BatchWithAttributes"));
        assertThat(info.getComment(), is("testing"));
        assertThat(info.getParameters(), hasSize(2));
        assertThat(info.getAttributes(), hasItem(BatchInfo.Attribute.STRICT_PARAMETERS));

        BatchInfo.Parameter p0 = findParameter(info, "a");
        assertThat(p0.getKey(), is("a"));
        assertThat(p0.getComment(), is("A"));
        assertThat(p0.isMandatory(), is(false));
        assertThat(p0.getPattern(), is(notNullValue()));
        assertThat(p0.getPattern().pattern(), is("a+"));

        BatchInfo.Parameter p1 = findParameter(info, "b");
        assertThat(p1.getKey(), is("b"));
        assertThat(p1.getComment(), is(nullValue()));
        assertThat(p1.isMandatory(), is(true));
        assertThat(p1.getPattern(), is(nullValue()));
    }

    /**
     * analyze - simple.
     */
    @Test
    public void analyze_simple() {
        IterativeBatchAnalyzer analyzer = new IterativeBatchAnalyzer(
                new JobflowAnalyzer(
                        new FlowGraphAnalyzer(
                                new MockExternalPortAnalyzer(),
                                new IterativeOperatorAnalyzer())));
        Batch batch = analyzer.analyze(MockBatch.class);
        assertThat(batch.getElements(), hasSize(1));
        BatchElement element = batch.findElement(IterativeBatchAnalyzer.FLOW_ID);
        assertThat(element, is(notNullValue()));
        Jobflow flow = element.getJobflow();

        ExternalInput input = flow.getOperatorGraph().getInputs().get("in");
        assertThat(input, is(notNullValue()));

        IterativeExtension extension = input.getAttribute(IterativeExtension.class);
        assertThat(extension, is(notNullValue()));
        assertThat(extension.isScoped(), is(true));
        assertThat(extension.getParameters(), containsInAnyOrder("testing"));
    }

    private BatchInfo.Parameter findParameter(BatchInfo info, String key) {
        for (BatchInfo.Parameter parameter : info.getParameters()) {
            if (parameter.getKey().equals(key)) {
                return parameter;
            }
        }
        throw new AssertionError(key);
    }
}


text:
package com.hazelcast.query.impl;

import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;

import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class MapIndexInfo implements IdentifiedDataSerializable {

    private String mapName;
    private List<IndexInfo> indexInfos = new LinkedList<IndexInfo>();

    public MapIndexInfo(String mapName) {
        this.mapName = mapName;
    }

    public MapIndexInfo() {
    }

    public void addIndexInfo(String attributeName, boolean ordered) {
        indexInfos.add(new IndexInfo(attributeName, ordered));
    }

    public void addIndexInfos(Collection<IndexInfo> indexInfos) {
        this.indexInfos.addAll(indexInfos);
    }

    public String getMapName() {
        return mapName;
    }

    public List<IndexInfo> getIndexInfos() {
        return indexInfos;
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        out.writeUTF(mapName);
        out.writeInt(indexInfos.size());
        for (IndexInfo indexInfo : indexInfos) {
            indexInfo.writeData(out);
        }
    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {
        mapName = in.readUTF();
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            IndexInfo indexInfo = new IndexInfo();
            indexInfo.readData(in);
            indexInfos.add(indexInfo);
        }
    }

    @Override
    public int getFactoryId() {
        return MapDataSerializerHook.F_ID;
    }

    @Override
    public int getId() {
        return MapDataSerializerHook.MAP_INDEX_INFO;
    }

}


text:
CREATE TABLE ccdsInfo (
    ccds char(12) not null,	# CCDS id
    srcDb char(1) not null,	# source database: N=NCBI, H=Hinxton
    mrnaAcc char(18) not null,	# mRNA accession (NCBI or Hinxton)
    protAcc char(18) not null,	# protein accession (NCBI or Hinxton)
              #Indices
    INDEX(ccds),
    INDEX(mrnaAcc)
);


text:
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });

function preload() {
    game.load.spritesheet('start-input-button', 'assets/buttons/gamepad-input-start.png', 168,70);
    game.load.image('reset-buttons','assets/buttons/gamepad-reset-buttons.png');
}

var startInputButton;
var resetButton;

var supportedText;
var activeText;
var gamepadCountText;

var pad1;
var pad1Text;
var pad2;
var pad2Text;
var pad3;
var pad3Text;
var pad4;
var pad4Text;

var activityPad1Text;
var activityPad2Text;
var activityPad3Text;
var activityPad4Text;
var activityGlobalText;

var pad1StateText;
var pad2StateText;
var pad3StateText;
var pad4StateText;

function create() {

    game.stage.backgroundColor = '#222222';
    startInputButton = game.add.button(625, 5, 'start-input-button', onStartInput, this, 0, 0, 0);
    resetButton = game.add.button(425, 5, 'reset-buttons', onResetButtons, this);

    pad1 = game.input.gamepad.pad1;
    pad2 = game.input.gamepad.pad2;
    pad3 = game.input.gamepad.pad3;
    pad4 = game.input.gamepad.pad4;

    setupText();
}

function onStartInput() {
    if(game.input.gamepad.active) {
        game.input.gamepad.stop();
        startInputButton.setFrames(0,0,0);
    } else {
        game.input.gamepad.start();
        startInputButton.setFrames(1,1,1);
        console.log(pad1._axesLen);
    }
}

function onResetButtons() {
    game.input.gamepad.reset();
}

function update() {
    supportedText.setText('Gamepad supported in this browser: '+game.input.gamepad.supported);
    activeText.setText('Gamepad input active: '+game.input.gamepad.active);
    gamepadCountText.setText('Gamepads connected: '+game.input.gamepad.padsConnected);

    updatePadStatusText(pad1._rawPad, pad1Text, 1);
    updatePadStatusText(pad2._rawPad, pad2Text, 2);
    updatePadStatusText(pad3._rawPad, pad3Text, 3);
    updatePadStatusText(pad4._rawPad, pad4Text, 4);

    updatePadsButtonsAxes(pad1._rawPad, pad1StateText, 1);
    updatePadsButtonsAxes(pad2._rawPad, pad2StateText, 2);
    updatePadsButtonsAxes(pad3._rawPad, pad3StateText, 3);
    updatePadsButtonsAxes(pad4._rawPad, pad4StateText, 4);
}

function updatePadStatusText(rawPad, padText, num) {
    if(rawPad) {
        padText.setText('Pad '+num+': [ index: '+rawPad['index']+' | id: '+rawPad['id']
            +' | timestamp: '+rawPad['timestamp']+']'
            +' | buttons: '+rawPad.buttons.length
            +' | axes: '+rawPad.axes.length
        );
    } else {
        padText.setText('Pad '+num+': Not connected');
    }
}

function updatePadsButtonsAxes(rawPad, padStateText, num) {
    if(rawPad) {
        var txt = 'Pad '+num+' buttons/axes: \n';
        for (var i = 0; i < rawPad.buttons.length; i += 1) {
            // txt += 'Button '+i+': '+rawPad.buttons[i].pressed+'\n';
            txt += 'Button '+i+': '+rawPad.buttons[i].value+'\n';
        }
        for (var i = 0; i < rawPad.axes.length; i += 1) {
            txt += 'Axis '+i+': '+rawPad.axes[i]+'\n';
        }
        padStateText.setText(txt);
    }
}

function setupText() {

    var style = { font: "12px Arial", fill: "#ffffff", align: "left" };
    var tinyStyle = { font: "10px Arial", fill: "#ffffff", align: "left" };
    supportedText = game.add.text(10, 10, 'Gamepad supported in this browser: '+game.input.gamepad.supported, style);
    activeText = game.add.text(10, 30, 'Gamepad input active: '+game.input.gamepad.active, style);
    gamepadCountText = game.add.text(10, 50, 'Gamepads connected: '+game.input.gamepad.padsConnected, style);
    pad1StateText = game.add.text(10, 300, 'Pad 1 buttons/axes: ', tinyStyle);
    pad2StateText = game.add.text(200, 300, 'Pad 2 buttons/axes: ', tinyStyle);
    pad3StateText = game.add.text(390, 300, 'Pad 3 buttons/axes: ', tinyStyle);
    pad4StateText = game.add.text(580, 300, 'Pad 4 buttons/axes: ', tinyStyle);

    // Setting up infotext and callbacks for all separate four gamepads

    pad1 = game.input.gamepad.pad1;
    pad1Text = game.add.text(10, 80, 'Pad 1: ', style);
    pad2 = game.input.gamepad.pad2;
    pad2Text = game.add.text(10, 100, 'Pad 2: ', style);
    pad3 = game.input.gamepad.pad3;
    pad3Text = game.add.text(10, 120, 'Pad 3: ', style);
    pad4 = game.input.gamepad.pad4;
    pad4Text = game.add.text(10, 140, 'Pad 4: ', style);

    activityPad1Text = game.add.text(10, 180, 'Last activity pad 1: ', style);
    addPadCallbacks(pad1, activityPad1Text, 1);

    activityPad2Text = game.add.text(10, 200, 'Last activity pad 2: ', style);
    addPadCallbacks(pad2, activityPad2Text, 2);

    activityPad3Text = game.add.text(10, 220, 'Last activity pad 3: ', style);
    addPadCallbacks(pad3, activityPad3Text, 3);

    activityPad4Text = game.add.text(10, 240, 'Last activity pad 4: ', style);
    addPadCallbacks(pad4, activityPad4Text, 4);

    activityGlobalText = game.add.text(10, 270, 'Last activity all pads: ', style);

    // Here we're setting callbacks that will trigger from ALL gamepads connected
    game.input.gamepad.addCallbacks(this, {
        onConnect: function(padIndex){
            activityGlobalText.setText('Last activity all pads: Connected with pad index '+padIndex);
        },
        onDisconnect: function(padIndex){
            activityGlobalText.setText('Last activity all pads: Disconnected with pad index '+padIndex);
        },
        onDown: function(buttonCode, value, padIndex){
            activityGlobalText.setText('Last activity all pads: Pad index '+padIndex+' buttonCode: '+buttonCode+' | value: '+value);
        },
        onUp: function(buttonCode, value, padIndex){
            activityGlobalText.setText('Last activity all pads: Pad index '+padIndex+' buttonCode: '+buttonCode+' | value: '+value);
        },
        onAxis: function(pad, axis, value) {
            activityGlobalText.setText('Last activity all pads: Pad index '+pad.index+': axis '+axis+': '+value);
        },
        onFloat: function(buttonCode, value, padIndex) {
            activityGlobalText.setText('Last activity all pads: Pad index '+padIndex+' buttonCode: '+buttonCode+' | value (float): '+value);
        }
    });
}

function addPadCallbacks(pad, text, index) {
    pad.addCallbacks(this, {
        onConnect: function(){
            text.setText('Last activity pad '+index+': Connected');
        },
        onDisconnect: function(){
            text.setText('Last activity pad '+index+': Disconnected');
        },
        onDown: function(buttonCode, value){
            text.setText('Last activity pad '+index+': buttonCode: '+buttonCode+' | value: '+value);
        },
        onUp: function(buttonCode, value){
            text.setText('Last activity pad '+index+': buttonCode: '+buttonCode+' | value: '+value);
        },
        onAxis: function(pad, axis, value) {
            text.setText('Last activity pad '+pad.index+': axis '+axis+': '+value);
        },
        onFloat: function(buttonCode, value) {
            text.setText('Last activity pad '+index+': buttonCode: '+buttonCode+' | value (float): '+value);
        }
    });
}


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.prestosql.tests;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.prestosql.Session;
import io.prestosql.connector.ConnectorId;
import io.prestosql.metadata.SessionPropertyManager;
import io.prestosql.plugin.tpch.TpchConnectorFactory;
import io.prestosql.spi.connector.CatalogSchemaTableName;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.FormattedDomain;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.FormattedMarker;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.FormattedRange;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.IOPlan;
import io.prestosql.sql.planner.planPrinter.IOPlanPrinter.IOPlan.TableColumnInfo;
import io.prestosql.testing.LocalQueryRunner;
import io.prestosql.testing.MaterializedResult;
import org.testng.annotations.Test;

import java.util.Optional;

import static com.google.common.collect.Iterables.getOnlyElement;
import static io.airlift.json.JsonCodec.jsonCodec;
import static io.prestosql.SystemSessionProperties.PUSH_PARTIAL_AGGREGATION_THROUGH_JOIN;
import static io.prestosql.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static io.prestosql.spi.predicate.Marker.Bound.EXACTLY;
import static io.prestosql.spi.type.DoubleType.DOUBLE;
import static io.prestosql.spi.type.VarcharType.VARCHAR;
import static io.prestosql.spi.type.VarcharType.createVarcharType;
import static io.prestosql.testing.MaterializedResult.resultBuilder;
import static io.prestosql.testing.TestingSession.TESTING_CATALOG;
import static io.prestosql.testing.TestingSession.testSessionBuilder;
import static io.prestosql.testing.assertions.Assert.assertEquals;

public class TestLocalQueries
        extends AbstractTestQueries
{
    public TestLocalQueries()
    {
        super(TestLocalQueries::createLocalQueryRunner);
    }

    public static LocalQueryRunner createLocalQueryRunner()
    {
        Session defaultSession = testSessionBuilder()
                .setCatalog("local")
                .setSchema(TINY_SCHEMA_NAME)
                .setSystemProperty(PUSH_PARTIAL_AGGREGATION_THROUGH_JOIN, "true")
                .build();

        LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);

        // add the tpch catalog
        // local queries run directly against the generator
        localQueryRunner.createCatalog(
                defaultSession.getCatalog().get(),
                new TpchConnectorFactory(1),
                ImmutableMap.of());

        localQueryRunner.getMetadata().addFunctions(CUSTOM_FUNCTIONS);

        SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager();
        sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES);
        sessionPropertyManager.addConnectorSessionProperties(new ConnectorId(TESTING_CATALOG), TEST_CATALOG_PROPERTIES);

        return localQueryRunner;
    }

    @Test
    public void testShowColumnStats()
    {
        // FIXME Add tests for more complex scenario with more stats
        MaterializedResult result = computeActual("SHOW STATS FOR nation");

        MaterializedResult expectedStatistics =
                resultBuilder(getSession(), VARCHAR, DOUBLE, DOUBLE, DOUBLE, DOUBLE, VARCHAR, VARCHAR)
                        .row("nationkey", null, 25.0, 0.0, null, "0", "24")
                        .row("name", 177.0, 25.0, 0.0, null, null, null)
                        .row("regionkey", null, 5.0, 0.0, null, "0", "4")
                        .row("comment", 1857.0, 25.0, 0.0, null, null, null)
                        .row(null, null, null, null, 25.0, null, null)
                        .build();

        assertEquals(result, expectedStatistics);
    }

    @Test
    public void testRejectStarQueryWithoutFromRelation()
    {
        assertQueryFails("SELECT *", "line \\S+ SELECT \\* not allowed in queries without FROM clause");
        assertQueryFails("SELECT 1, '2', *", "line \\S+ SELECT \\* not allowed in queries without FROM clause");
    }

    @Test
    public void testDecimal()
    {
        assertQuery("SELECT DECIMAL '1.0'", "SELECT CAST('1.0' AS DECIMAL)");
        assertQuery("SELECT DECIMAL '1.'", "SELECT CAST('1.0' AS DECIMAL)");
        assertQuery("SELECT DECIMAL '0.1'", "SELECT CAST('0.1' AS DECIMAL)");
        assertQuery("SELECT 1.0", "SELECT CAST('1.0' AS DECIMAL)");
        assertQuery("SELECT 1.", "SELECT CAST('1.0' AS DECIMAL)");
        assertQuery("SELECT 0.1", "SELECT CAST('0.1' AS DECIMAL)");
    }

    @Test
    public void testIOExplain()
    {
        String query = "SELECT * FROM orders";
        MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) " + query);
        TableColumnInfo input = new TableColumnInfo(
                new CatalogSchemaTableName("local", "sf0.01", "orders"),
                ImmutableSet.of(
                        new ColumnConstraint(
                                "orderstatus",
                                createVarcharType(1).getTypeSignature(),
                                new FormattedDomain(
                                        false,
                                        ImmutableSet.of(
                                                new FormattedRange(
                                                        new FormattedMarker(Optional.of("F"), EXACTLY),
                                                        new FormattedMarker(Optional.of("F"), EXACTLY)),
                                                new FormattedRange(
                                                        new FormattedMarker(Optional.of("O"), EXACTLY),
                                                        new FormattedMarker(Optional.of("O"), EXACTLY)),
                                                new FormattedRange(
                                                        new FormattedMarker(Optional.of("P"), EXACTLY),
                                                        new FormattedMarker(Optional.of("P"), EXACTLY)))))));
        assertEquals(
                jsonCodec(IOPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())),
                new IOPlan(ImmutableSet.of(input), Optional.empty()));
    }
}