text:
package org.elasticsearch.index.shard;

import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.InternalClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.ShardLock;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.flush.FlushStats;
import org.elasticsearch.index.indexing.IndexingOperationListener;
import org.elasticsearch.index.indexing.ShardIndexingService;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.index.settings.IndexSettingsService;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.index.translog.TranslogConfig;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.test.DummyShardLock;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.VersionUtils;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.elasticsearch.cluster.metadata.IndexMetaData.EMPTY_PARAMS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;

/**
 * Simple unit-test IndexShard related operations.
 */
public class IndexShardTests extends ESSingleNodeTestCase {

    public void testFlushOnDeleteSetting() throws Exception {
        boolean initValue = randomBoolean();
        createIndex("test", settingsBuilder().put(IndexShard.INDEX_FLUSH_ON_CLOSE, initValue).build());
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        assertEquals(initValue, shard.isFlushOnClose());
        final boolean newValue = !initValue;
        assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_FLUSH_ON_CLOSE, newValue).build()));
        assertEquals(newValue, shard.isFlushOnClose());

        try {
            assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_FLUSH_ON_CLOSE, "FOOBAR").build()));
            fail("exception expected");
        } catch (IllegalArgumentException ex) {

        }
        assertEquals(newValue, shard.isFlushOnClose());

    }

    public void testWriteShardState() throws Exception {
        try (NodeEnvironment env = newNodeEnvironment()) {
            ShardId id = new ShardId("foo", 1);
            long version = between(1, Integer.MAX_VALUE / 2);
            boolean primary = randomBoolean();
            ShardStateMetaData state1 = new ShardStateMetaData(version, primary, "foo");
            write(state1, env.availableShardPaths(id));
            ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(id));
            assertEquals(shardStateMetaData, state1);

            ShardStateMetaData state2 = new ShardStateMetaData(version, primary, "foo");
            write(state2, env.availableShardPaths(id));
            shardStateMetaData = load(logger, env.availableShardPaths(id));
            assertEquals(shardStateMetaData, state1);

            ShardStateMetaData state3 = new ShardStateMetaData(version + 1, primary, "foo");
            write(state3, env.availableShardPaths(id));
            shardStateMetaData = load(logger, env.availableShardPaths(id));
            assertEquals(shardStateMetaData, state3);
            assertEquals("foo", state3.indexUUID);
        }
    }

    @Test
    public void testLockTryingToDelete() throws Exception {
        createIndex("test");
        ensureGreen();
        NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
        Path[] shardPaths = env.availableShardPaths(new ShardId("test", 0));
        logger.info("--> paths: [{}]", (Object)shardPaths);
        // Should not be able to acquire the lock because it's already open
        try {
            NodeEnvironment.acquireFSLockForPaths(Settings.EMPTY, shardPaths);
            fail("should not have been able to acquire the lock");
        } catch (LockObtainFailedException e) {
            assertTrue("msg: " + e.getMessage(), e.getMessage().contains("unable to acquire write.lock"));
        }
        // Test without the regular shard lock to assume we can acquire it
        // (worst case, meaning that the shard lock could be acquired and
        // we're green to delete the shard's directory)
        ShardLock sLock = new DummyShardLock(new ShardId("test", 0));
        try {
            env.deleteShardDirectoryUnderLock(sLock, Settings.builder().build());
            fail("should not have been able to delete the directory");
        } catch (LockObtainFailedException e) {
            assertTrue("msg: " + e.getMessage(), e.getMessage().contains("unable to acquire write.lock"));
        }
    }

    public void testPersistenceStateMetadataPersistence() throws Exception {
        createIndex("test");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(getShardStateMetadata(shard), shardStateMetaData);
        ShardRouting routing = new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1);
        shard.updateRoutingEntry(routing, true);

        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));
        assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));

        routing = new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1);
        shard.updateRoutingEntry(routing, true);
        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));
        assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));

        routing = new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1);
        shard.updateRoutingEntry(routing, true);
        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));
        assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));

        // test if we still write it even if the shard is not active
        ShardRouting inactiveRouting = TestShardRouting.newShardRouting(shard.shardRouting.index(), shard.shardRouting.shardId().id(), shard.shardRouting.currentNodeId(), null, null, true, ShardRoutingState.INITIALIZING, shard.shardRouting.version() + 1);
        shard.persistMetadata(inactiveRouting, shard.shardRouting);
        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals("inactive shard state shouldn't be persisted", shardStateMetaData, getShardStateMetadata(shard));
        assertEquals("inactive shard state shouldn't be persisted", shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));

        shard.updateRoutingEntry(new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1), false);
        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertFalse("shard state persisted despite of persist=false", shardStateMetaData.equals(getShardStateMetadata(shard)));
        assertEquals("shard state persisted despite of persist=false", shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));

        routing = new ShardRouting(shard.shardRouting, shard.shardRouting.version() + 1);
        shard.updateRoutingEntry(routing, true);
        shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));
        assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)));
    }

    public void testDeleteShardState() throws IOException {
        createIndex("test");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        try {
            shard.deleteShardState();
            fail("shard is active metadata delete must fail");
        } catch (IllegalStateException ex) {
            // fine - only delete if non-active
        }

        ShardRouting routing = shard.routingEntry();
        ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));

        routing = TestShardRouting.newShardRouting(shard.shardId.index().getName(), shard.shardId.id(), routing.currentNodeId(), null, routing.primary(), ShardRoutingState.INITIALIZING, shard.shardRouting.allocationId(), shard.shardRouting.version() + 1);
        shard.updateRoutingEntry(routing, true);
        shard.deleteShardState();

        assertNull("no shard state expected after delete on initializing", load(logger, env.availableShardPaths(shard.shardId)));

    }

    public void testFailShard() throws Exception {
        createIndex("test");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        // fail shard
        shard.failShard("test shard fail", new CorruptIndexException("", ""));
        // check state file still exists
        ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId));
        assertEquals(shardStateMetaData, getShardStateMetadata(shard));
        ShardPath shardPath = ShardPath.loadShardPath(logger, env, shard.shardId(), test.getIndexSettings());
        assertNotNull(shardPath);
        // but index can't be opened for a failed shard
        assertThat("store index should be corrupted", Store.canOpenIndex(logger, shardPath.resolveIndex()), equalTo(false));
    }

    ShardStateMetaData getShardStateMetadata(IndexShard shard) {
        ShardRouting shardRouting = shard.routingEntry();
        if (shardRouting == null) {
            return null;
        } else {
            return new ShardStateMetaData(shardRouting.version(), shardRouting.primary(), shard.indexSettings.get(IndexMetaData.SETTING_INDEX_UUID));
        }
    }

    public void testShardStateMetaHashCodeEquals() {
        ShardStateMetaData meta = new ShardStateMetaData(randomLong(), randomBoolean(), randomRealisticUnicodeOfCodepointLengthBetween(1, 10));

        assertEquals(meta, new ShardStateMetaData(meta.version, meta.primary, meta.indexUUID));
        assertEquals(meta.hashCode(), new ShardStateMetaData(meta.version, meta.primary, meta.indexUUID).hashCode());

        assertFalse(meta.equals(new ShardStateMetaData(meta.version, !meta.primary, meta.indexUUID)));
        assertFalse(meta.equals(new ShardStateMetaData(meta.version + 1, meta.primary, meta.indexUUID)));
        assertFalse(meta.equals(new ShardStateMetaData(meta.version, !meta.primary, meta.indexUUID + "foo")));
        Set<Integer> hashCodes = new HashSet<>();
        for (int i = 0; i < 30; i++) { // just a sanity check that we impl hashcode
            meta = new ShardStateMetaData(randomLong(), randomBoolean(), randomRealisticUnicodeOfCodepointLengthBetween(1, 10));
            hashCodes.add(meta.hashCode());
        }
        assertTrue("more than one unique hashcode expected but got: " + hashCodes.size(), hashCodes.size() > 1);

    }

    @Test
    public void testDeleteIndexDecreasesCounter() throws InterruptedException, ExecutionException, IOException {
        assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).get());
        ensureGreen("test");
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService indexService = indicesService.indexServiceSafe("test");
        IndexShard indexShard = indexService.shard(0);
        client().admin().indices().prepareDelete("test").get();
        assertThat(indexShard.getOperationsCount(), equalTo(0));
        try {
            indexShard.incrementOperationCounter();
            fail("we should not be able to increment anymore");
        } catch (IndexShardClosedException e) {
            // expected
        }
    }

    @Test
    public void testIndexShardCounter() throws InterruptedException, ExecutionException, IOException {
        assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).get());
        ensureGreen("test");
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService indexService = indicesService.indexServiceSafe("test");
        IndexShard indexShard = indexService.shard(0);
        assertEquals(0, indexShard.getOperationsCount());
        indexShard.incrementOperationCounter();
        assertEquals(1, indexShard.getOperationsCount());
        indexShard.incrementOperationCounter();
        assertEquals(2, indexShard.getOperationsCount());
        indexShard.decrementOperationCounter();
        indexShard.decrementOperationCounter();
        assertEquals(0, indexShard.getOperationsCount());
    }

    @Test
    public void testMarkAsInactiveTriggersSyncedFlush() throws Exception {
        assertAcked(client().admin().indices().prepareCreate("test")
                .setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
        client().prepareIndex("test", "test").setSource("{}").get();
        ensureGreen("test");
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        indicesService.indexService("test").shard(0).markAsInactive();
        assertBusy(new Runnable() { // should be very very quick
            @Override
            public void run() {
                IndexStats indexStats = client().admin().indices().prepareStats("test").clear().get().getIndex("test");
                assertNotNull(indexStats.getShards()[0].getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
            }
        });
        IndexStats indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
        assertNotNull(indexStats.getShards()[0].getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }

    public static ShardStateMetaData load(ESLogger logger, Path... shardPaths) throws IOException {
        return ShardStateMetaData.FORMAT.loadLatestState(logger, shardPaths);
    }

    public static void write(ShardStateMetaData shardStateMetaData,
                             Path... shardPaths) throws IOException {
        ShardStateMetaData.FORMAT.write(shardStateMetaData, shardStateMetaData.version, shardPaths);
    }

    public void testDurableFlagHasEffect() {
        createIndex("test");
        ensureGreen();
        client().prepareIndex("test", "bar", "1").setSource("{}").get();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        setDurability(shard, Translog.Durabilty.REQUEST);
        assertFalse(shard.engine().getTranslog().syncNeeded());
        setDurability(shard, Translog.Durabilty.ASYNC);
        client().prepareIndex("test", "bar", "2").setSource("{}").get();
        assertTrue(shard.engine().getTranslog().syncNeeded());
        setDurability(shard, Translog.Durabilty.REQUEST);
        client().prepareDelete("test", "bar", "1").get();
        assertFalse(shard.engine().getTranslog().syncNeeded());

        setDurability(shard, Translog.Durabilty.ASYNC);
        client().prepareDelete("test", "bar", "2").get();
        assertTrue(shard.engine().getTranslog().syncNeeded());
        setDurability(shard, Translog.Durabilty.REQUEST);
        assertNoFailures(client().prepareBulk()
                .add(client().prepareIndex("test", "bar", "3").setSource("{}"))
                .add(client().prepareDelete("test", "bar", "1")).get());
        assertFalse(shard.engine().getTranslog().syncNeeded());

        setDurability(shard, Translog.Durabilty.ASYNC);
        assertNoFailures(client().prepareBulk()
                .add(client().prepareIndex("test", "bar", "4").setSource("{}"))
                .add(client().prepareDelete("test", "bar", "3")).get());
        setDurability(shard, Translog.Durabilty.REQUEST);
        assertTrue(shard.engine().getTranslog().syncNeeded());
    }

    private void setDurability(IndexShard shard, Translog.Durabilty durabilty) {
        client().admin().indices().prepareUpdateSettings(shard.shardId.getIndex()).setSettings(settingsBuilder().put(TranslogConfig.INDEX_TRANSLOG_DURABILITY, durabilty.name()).build()).get();
        assertEquals(durabilty, shard.getTranslogDurability());
    }

    public void testDeleteByQueryBWC() {
        Version version = VersionUtils.randomVersion(random());
        assertAcked(client().admin().indices().prepareCreate("test")
                .setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0, IndexMetaData.SETTING_VERSION_CREATED, version.id));
        ensureGreen("test");
        client().prepareIndex("test", "person").setSource("{ \"user\" : \"kimchy\" }").get();

        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        int numDocs = 1;
        shard.state = IndexShardState.RECOVERING;
        try {
            shard.recoveryState().getTranslog().totalOperations(1);
            shard.engine().config().getTranslogRecoveryPerformer().performRecoveryOperation(shard.engine(), new Translog.DeleteByQuery(new Engine.DeleteByQuery(null, new BytesArray("{\"term\" : { \"user\" : \"kimchy\" }}"), null, null, null, Engine.Operation.Origin.RECOVERY, 0, "person")), false);
            assertTrue(version.onOrBefore(Version.V_1_0_0_Beta2));
            numDocs = 0;
        } catch (ParsingException ex) {
            assertTrue(version.after(Version.V_1_0_0_Beta2));
        } finally {
            shard.state = IndexShardState.STARTED;
        }
        shard.engine().refresh("foo");

        try (Engine.Searcher searcher = shard.engine().acquireSearcher("foo")) {
            assertEquals(numDocs, searcher.reader().numDocs());
        }
    }

    public void testMinimumCompatVersion() {
        Version versionCreated = VersionUtils.randomVersion(random());
        assertAcked(client().admin().indices().prepareCreate("test")
                .setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0, SETTING_VERSION_CREATED, versionCreated.id));
        client().prepareIndex("test", "test").setSource("{}").get();
        ensureGreen("test");
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexShard test = indicesService.indexService("test").shard(0);
        assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
        client().prepareIndex("test", "test").setSource("{}").get();
        assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
        test.engine().flush();
        assertEquals(Version.CURRENT.luceneVersion, test.minimumCompatibleVersion());
    }

    public void testUpdatePriority() {
        assertAcked(client().admin().indices().prepareCreate("test")
                .setSettings(IndexMetaData.SETTING_PRIORITY, 200));
        IndexSettingsService indexSettingsService = getInstanceFromNode(IndicesService.class).indexService("test").settingsService();
        assertEquals(200, indexSettingsService.getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue());
        client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_PRIORITY, 400).build()).get();
        assertEquals(400, indexSettingsService.getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue());
    }

    public void testRecoverIntoLeftover() throws IOException {
        createIndex("test");
        ensureGreen("test");
        client().prepareIndex("test", "bar", "1").setSource("{}").setRefresh(true).get();
        client().admin().indices().prepareFlush("test").get();
        SearchResponse response = client().prepareSearch("test").get();
        assertHitCount(response, 1l);
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        ShardPath shardPath = shard.shardPath();
        Path dataPath = shardPath.getDataPath();
        client().admin().indices().prepareClose("test").get();
        Path tempDir = createTempDir();
        Files.move(dataPath, tempDir.resolve("test"));
        client().admin().indices().prepareDelete("test").get();
        Files.createDirectories(dataPath.getParent());
        Files.move(tempDir.resolve("test"), dataPath);
        createIndex("test");
        ensureGreen("test");
        response = client().prepareSearch("test").get();
        assertHitCount(response, 0l);
    }

    public void testIndexDirIsDeletedWhenShardRemoved() throws Exception {
        Environment env = getInstanceFromNode(Environment.class);
        Path idxPath = env.sharedDataFile().resolve(randomAsciiOfLength(10));
        logger.info("--> idxPath: [{}]", idxPath);
        Settings idxSettings = Settings.builder()
                .put(IndexMetaData.SETTING_DATA_PATH, idxPath)
                .build();
        createIndex("test", idxSettings);
        ensureGreen("test");
        client().prepareIndex("test", "bar", "1").setSource("{}").setRefresh(true).get();
        SearchResponse response = client().prepareSearch("test").get();
        assertHitCount(response, 1l);
        client().admin().indices().prepareDelete("test").get();
        assertPathHasBeenCleared(idxPath);
    }

    public void testExpectedShardSizeIsPresent() throws InterruptedException {
        assertAcked(client().admin().indices().prepareCreate("test")
                .setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
        for (int i = 0; i < 50; i++) {
            client().prepareIndex("test", "test").setSource("{}").get();
        }
        ensureGreen("test");
        InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
        clusterInfoService.refresh();
        ClusterState state = getInstanceFromNode(ClusterService.class).state();
        Long test = clusterInfoService.getClusterInfo().getShardSize(state.getRoutingTable().index("test").getShards().get(0).primaryShard());
        assertNotNull(test);
        assertTrue(test > 0);
    }

    public void testIndexCanChangeCustomDataPath() throws Exception {
        Environment env = getInstanceFromNode(Environment.class);
        Path idxPath = env.sharedDataFile().resolve(randomAsciiOfLength(10));
        final String INDEX = "idx";
        Path startDir = idxPath.resolve("start-" + randomAsciiOfLength(10));
        Path endDir = idxPath.resolve("end-" + randomAsciiOfLength(10));
        logger.info("--> start dir: [{}]", startDir.toAbsolutePath().toString());
        logger.info("-->   end dir: [{}]", endDir.toAbsolutePath().toString());
        // temp dirs are automatically created, but the end dir is what
        // startDir is going to be renamed as, so it needs to be deleted
        // otherwise we get all sorts of errors about the directory
        // already existing
        IOUtils.rm(endDir);

        Settings sb = Settings.builder()
                .put(IndexMetaData.SETTING_DATA_PATH, startDir.toAbsolutePath().toString())
                .build();
        Settings sb2 = Settings.builder()
                .put(IndexMetaData.SETTING_DATA_PATH, endDir.toAbsolutePath().toString())
                .build();

        logger.info("--> creating an index with data_path [{}]", startDir.toAbsolutePath().toString());
        createIndex(INDEX, sb);
        ensureGreen(INDEX);
        client().prepareIndex(INDEX, "bar", "1").setSource("{}").setRefresh(true).get();

        SearchResponse resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get();
        assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L));

        logger.info("--> closing the index [{}]", INDEX);
        client().admin().indices().prepareClose(INDEX).get();
        logger.info("--> index closed, re-opening...");
        client().admin().indices().prepareOpen(INDEX).get();
        logger.info("--> index re-opened");
        ensureGreen(INDEX);

        resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get();
        assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L));

        // Now, try closing and changing the settings

        logger.info("--> closing the index [{}]", INDEX);
        client().admin().indices().prepareClose(INDEX).get();

        logger.info("--> moving data on disk [{}] to [{}]", startDir.getFileName(), endDir.getFileName());
        assert Files.exists(endDir) == false : "end directory should not exist!";
        Files.move(startDir, endDir, StandardCopyOption.REPLACE_EXISTING);

        logger.info("--> updating settings...");
        client().admin().indices().prepareUpdateSettings(INDEX)
                .setSettings(sb2)
                .setIndicesOptions(IndicesOptions.fromOptions(true, false, true, true))
                .get();

        assert Files.exists(startDir) == false : "start dir shouldn't exist";

        logger.info("--> settings updated and files moved, re-opening index");
        client().admin().indices().prepareOpen(INDEX).get();
        logger.info("--> index re-opened");
        ensureGreen(INDEX);

        resp = client().prepareSearch(INDEX).setQuery(matchAllQuery()).get();
        assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L));

        assertAcked(client().admin().indices().prepareDelete(INDEX));
        assertPathHasBeenCleared(startDir.toAbsolutePath().toString());
        assertPathHasBeenCleared(endDir.toAbsolutePath().toString());
    }

    public void testShardStats() throws IOException {
        createIndex("test");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        ShardStats stats = new ShardStats(shard.routingEntry(), shard.shardPath(), new CommonStats(shard, new CommonStatsFlags()), shard.commitStats());
        assertEquals(shard.shardPath().getRootDataPath().toString(), stats.getDataPath());
        assertEquals(shard.shardPath().getRootStatePath().toString(), stats.getStatePath());
        assertEquals(shard.shardPath().isCustomDataPath(), stats.isCustomDataPath());

        if (randomBoolean() || true) { // try to serialize it to ensure values survive the serialization
            BytesStreamOutput out = new BytesStreamOutput();
            stats.writeTo(out);
            StreamInput in = StreamInput.wrap(out.bytes());
            stats = ShardStats.readShardStats(in);
        }
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject();
        stats.toXContent(builder, EMPTY_PARAMS);
        builder.endObject();
        String xContent = builder.string();
        StringBuilder expectedSubSequence = new StringBuilder("\"shard_path\":{\"state_path\":\"");
        expectedSubSequence.append(shard.shardPath().getRootStatePath().toString());
        expectedSubSequence.append("\",\"data_path\":\"");
        expectedSubSequence.append(shard.shardPath().getRootDataPath().toString());
        expectedSubSequence.append("\",\"is_custom_data_path\":").append(shard.shardPath().isCustomDataPath()).append("}");
        assumeFalse("Some path weirdness on windows", Constants.WINDOWS);
        assertTrue(xContent.contains(expectedSubSequence));
    }

    private ParsedDocument testParsedDocument(String uid, String id, String type, String routing, long timestamp, long ttl, ParseContext.Document document, BytesReference source, Mapping mappingUpdate) {
        Field uidField = new Field("_uid", uid, UidFieldMapper.Defaults.FIELD_TYPE);
        Field versionField = new NumericDocValuesField("_version", 0);
        document.add(uidField);
        document.add(versionField);
        return new ParsedDocument(uidField, versionField, id, type, routing, timestamp, ttl, Arrays.asList(document), source, mappingUpdate);
    }

    public void testPreIndex() throws IOException {
        createIndex("testpreindex");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("testpreindex");
        IndexShard shard = test.shard(0);
        ShardIndexingService shardIndexingService = shard.indexingService();
        final AtomicBoolean preIndexCalled = new AtomicBoolean(false);

        shardIndexingService.addListener(new IndexingOperationListener() {
            @Override
            public Engine.Index preIndex(Engine.Index index) {
                preIndexCalled.set(true);
                return super.preIndex(index);
            }
        });

        ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
        Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
        shard.index(index);
        assertTrue(preIndexCalled.get());
    }

    public void testPostIndex() throws IOException {
        createIndex("testpostindex");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("testpostindex");
        IndexShard shard = test.shard(0);
        ShardIndexingService shardIndexingService = shard.indexingService();
        final AtomicBoolean postIndexCalled = new AtomicBoolean(false);

        shardIndexingService.addListener(new IndexingOperationListener() {
            @Override
            public void postIndex(Engine.Index index) {
                postIndexCalled.set(true);
                super.postIndex(index);
            }
        });

        ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
        Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
        shard.index(index);
        assertTrue(postIndexCalled.get());
    }

    public void testPostIndexWithException() throws IOException {
        createIndex("testpostindexwithexception");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("testpostindexwithexception");
        IndexShard shard = test.shard(0);
        ShardIndexingService shardIndexingService = shard.indexingService();

        shard.close("Unexpected close", true);
        shard.state = IndexShardState.STARTED; // It will generate exception

        final AtomicBoolean postIndexWithExceptionCalled = new AtomicBoolean(false);

        shardIndexingService.addListener(new IndexingOperationListener() {
            @Override
            public void postIndex(Engine.Index index, Throwable ex) {
                assertNotNull(ex);
                postIndexWithExceptionCalled.set(true);
                super.postIndex(index, ex);
            }
        });

        ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
        Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);

        try {
            shard.index(index);
            fail();
        }catch (IllegalIndexShardStateException e){

        }

        assertTrue(postIndexWithExceptionCalled.get());
    }

    public void testMaybeFlush() throws Exception {
        createIndex("test", settingsBuilder().put(TranslogConfig.INDEX_TRANSLOG_DURABILITY, Translog.Durabilty.REQUEST).build());
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        IndexShard shard = test.shard(0);
        assertFalse(shard.shouldFlush());
        client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1).build()).get();
        client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
        assertFalse(shard.shouldFlush());
        ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
        Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
        shard.index(index);
        assertTrue(shard.shouldFlush());
        assertEquals(2, shard.engine().getTranslog().totalOperations());
        client().prepareIndex("test", "test", "2").setSource("{}").setRefresh(randomBoolean()).get();
        assertBusy(() -> { // this is async
            assertFalse(shard.shouldFlush());
        });
        assertEquals(0, shard.engine().getTranslog().totalOperations());
        shard.engine().getTranslog().sync();
        long size = shard.engine().getTranslog().sizeInBytes();
        logger.info("--> current translog size: [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
        client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1000)
                .put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(size, ByteSizeUnit.BYTES))
                .build()).get();
        client().prepareDelete("test", "test", "2").get();
        logger.info("--> translog size after delete: [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
        assertBusy(() -> { // this is async
            logger.info("--> translog size on iter  : [{}] num_ops [{}] generation [{}]", shard.engine().getTranslog().sizeInBytes(), shard.engine().getTranslog().totalOperations(), shard.engine().getTranslog().getGeneration());
            assertFalse(shard.shouldFlush());
        });
        assertEquals(0, shard.engine().getTranslog().totalOperations());
    }

    public void testStressMaybeFlush() throws Exception {
        createIndex("test");
        ensureGreen();
        IndicesService indicesService = getInstanceFromNode(IndicesService.class);
        IndexService test = indicesService.indexService("test");
        final IndexShard shard = test.shard(0);
        assertFalse(shard.shouldFlush());
        client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put(IndexShard.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, 1).build()).get();
        client().prepareIndex("test", "test", "0").setSource("{}").setRefresh(randomBoolean()).get();
        assertFalse(shard.shouldFlush());
        final AtomicBoolean running = new AtomicBoolean(true);
        final int numThreads = randomIntBetween(2, 4);
        Thread[] threads = new Thread[numThreads];
        CyclicBarrier barrier = new CyclicBarrier(numThreads + 1);
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread() {
                public void run() {
                    try {
                        barrier.await();
                    } catch (InterruptedException | BrokenBarrierException e) {
                        throw new RuntimeException(e);
                    }
                    while (running.get()) {
                        shard.maybeFlush();
                    }
                }
            };
            threads[i].start();
        }
        barrier.await();
        FlushStats flushStats = shard.flushStats();
        long total = flushStats.getTotal();
        client().prepareIndex("test", "test", "1").setSource("{}").get();
        assertBusy(() -> {
            assertEquals(total + 1, shard.flushStats().getTotal());
        });
        running.set(false);
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        assertEquals(total + 1, shard.flushStats().getTotal());
    }

}


text:
<?php

/*
 * This file is part of the "EloGank League of Legends Replay Observer" package.
 *
 * https://github.com/EloGank/lol-replay-observer
 *
 * For the full license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace EloGank\Replay\Observer\Client;

use EloGank\Replay\Observer\Client\Exception\ReplayChunkNotFoundException;
use EloGank\Replay\Observer\Client\Exception\ReplayEndStatsNotFoundException;
use EloGank\Replay\Observer\Client\Exception\ReplayFolderNotFoundException;
use EloGank\Replay\Observer\Client\Exception\ReplayKeyframeNotFoundException;

/**
 * @author Sylvain Lorinet <sylvain.lorinet@gmail.com>
 */
class ReplayObserverClient
{
    /**
     * @var string
     */
    protected $replaysDirPath;

    /**
     * @param string $replaysDirPath
     */
    public function __construct($replaysDirPath)
    {
        $this->replaysDirPath = $replaysDirPath;
    }

    /**
     * @param string $region
     * @param int    $gameId
     *
     * @return array
     *
     * @throws ReplayFolderNotFoundException
     */
    public function getMetas($region, $gameId)
    {
        // Check if exists, if no disable it
        if (!is_dir($this->getReplayDirPath($region, $gameId))) {
            throw new ReplayFolderNotFoundException(
                'The replay folder #' . $gameId . ' is not found. The replay will be disabled'
            );
        }

        return json_decode(file_get_contents($this->getReplayDirPath($region, $gameId) . '/metas.json'), true);
    }

    /**
     * @param array $metas
     * @param int   $chunkId
     * @param bool  $throwException
     *
     * @return int
     *
     * @throws ReplayKeyframeNotFoundException
     */
    public function findKeyframeByChunkId(array $metas, $chunkId, $throwException = false)
    {
        // Method based on metas.json > pendingAvailableKeyFrameInfo
        foreach ($metas['pendingAvailableKeyFrameInfo'] as $keyframe) {
            if ($chunkId == $keyframe['nextChunkId']) {
                return $keyframe['id'];
            }
        }

        if ($throwException) {
            throw new ReplayKeyframeNotFoundException('No keyframe found for chunk #' . ($chunkId + 1));
        }

        return $this->findKeyframeByChunkId($metas, $chunkId - 1, true);
    }

    /**
     * @param string $region
     * @param string $gameId
     * @param int    $chunkId
     *
     * @return string
     *
     * @throws ReplayChunkNotFoundException
     */
    public function getChunkPath($region, $gameId, $chunkId)
    {
        $filePath = $this->getReplayDirPath($region, $gameId) . '/chunks/' . $chunkId;

        if (!is_file($filePath)) {
            throw new ReplayChunkNotFoundException('The chunk #' . $chunkId . ' is not found');
        }

        return $filePath;
    }

    /**
     * @param string $region
     * @param string $gameId
     * @param int    $keyframeId
     *
     * @return string
     *
     * @throws ReplayKeyframeNotFoundException
     */
    public function getKeyframePath($region, $gameId, $keyframeId)
    {
        $filePath = $this->getReplayDirPath($region, $gameId) . '/keyframes/' . $keyframeId;

        if (!is_file($filePath)) {
            throw new ReplayKeyframeNotFoundException('The keyframe #' . $keyframeId . ' is not found');
        }

        return $filePath;
    }

    /**
     * @param string $region
     * @param string $gameId
     * @param int    $currentChunkId
     * @param int    $keyframeId     Passed in reference to be dumped for debug purpose
     *
     * @return array
     *
     * @throws ReplayFolderNotFoundException
     * @throws ReplayKeyframeNotFoundException
     */
    public function getLastChunkInfo($region, $gameId, $currentChunkId, &$keyframeId = null)
    {
        $metas = $this->getMetas($region, $gameId);

        // Game loading information
        //$firstChunkId = $replayManager->findFirstChunkId($metas);
        $firstChunkId = $metas['firstChunkId'];

        // A bug appears when endStartupChunkId = 3 and startGameChunkId = 5, the game won't load
        if ($metas['endStartupChunkId'] + 2 == $firstChunkId) {
            $firstChunkId = $metas['startGameChunkId'] + 2;
        }

        $keyframeId = $this->findKeyframeByChunkId($metas, $firstChunkId);

        $lastChunkInfo = array(
            'chunkId'            => $firstChunkId,
            'availableSince'     => 30000,
            'nextAvailableChunk' => 30000,
            'keyFrameId'         => $keyframeId,
            'nextChunkId'        => $firstChunkId,
            'endStartupChunkId'  => $metas['endStartupChunkId'],
            'startGameChunkId'   => $metas['startGameChunkId'],
            'endGameChunkId'     => 0,
            'duration'           => 30000
        );

        // In game information
        if ($firstChunkId != $metas['startGameChunkId'] && $currentChunkId - 1 == $metas['startGameChunkId']) {
            $currentChunkId = $firstChunkId;
        }

        if ($currentChunkId > $metas['startGameChunkId']) {
            if ($currentChunkId > $metas['lastChunkId']) {
                $currentChunkId = $metas['lastChunkId'];
            } elseif ($currentChunkId < $metas['firstChunkId']) {
                $currentChunkId = $metas['firstChunkId'];
            }

            $keyframeId = $this->findKeyframeByChunkId($metas, $currentChunkId);

            $lastChunkInfo['chunkId']            = $currentChunkId;
            $lastChunkInfo['nextChunkId']        = $metas['lastChunkId'];
            $lastChunkInfo['keyFrameId']         = $keyframeId;
            $lastChunkInfo['nextAvailableChunk'] = $currentChunkId == $firstChunkId + 6 ? 30000 : 100; // wait for full loading
        }

        // End game, stop downloading
        if ($currentChunkId == $metas['lastChunkId']) {
            $lastChunkInfo['nextAvailableChunk'] = 90000;
            $lastChunkInfo['endGameChunkId']     = $metas['endGameChunkId'];
        }

        return $lastChunkInfo;
    }

    /**
     * @param string $region
     * @param string $gameId
     *
     * @return string
     *
     * @throws ReplayEndStatsNotFoundException
     */
    public function getEndStats($region, $gameId)
    {
        $filePath = $this->getReplayDirPath($region, $gameId) . '/endstats';

        if (!is_file($filePath)) {
            throw new ReplayEndStatsNotFoundException('The endstats for game #' . $gameId . ' is not found');
        }

        return $filePath;
    }

    /**
     * @param string $region
     * @param int    $gameId
     *
     * @return string
     */
    protected function getReplayDirPath($region, $gameId)
    {
        $stringGameId = (string) $gameId;

        return sprintf(
            '%s/%s/%s/%s/%s/%s',
            $this->replaysDirPath,
            $region,
            $stringGameId[0] . $stringGameId[1],
            $stringGameId[2],
            $stringGameId[3],
            $gameId
        );
    }
}

redpajama_set_name: RedPajamaGithub


text:
package de.orolle.bigsense.server.devicemgmt;

import java.util.List;

import de.orolle.bigsense.server.database.MySQL;

/**
 * The Class VersionManagement.
 */
public class VersionManagement {

	/** The version management. */
	private static VersionManagement versionManagement;

	/**
	 * Gets the single instance of VersionManagement.
	 *
	 * @return single instance of VersionManagement
	 */
	public static VersionManagement getInstance() {
		if(versionManagement == null) versionManagement = new VersionManagement();
		return versionManagement;
	}

	/** The smartphones. */
	private List<Smartphone> smartphones;

	/** The apps. */
	private List<AppVersion> apps;

	/** The groups. */
	private List<Group> groups;

	/** SQL Connection */
	private MySQL sqlConnection;

	/**
	 * Instantiates a new version management.
	 */
	public VersionManagement() {
		this.sqlConnection = MySQL.getInstance();

		smartphones = sqlConnection.getAllPhones();
		apps = sqlConnection.getAllAppVersions();
		groups = sqlConnection.getAllGroups();
	}

	/**
	 * Save.
	 */
	public void save() {
		sqlConnection.setAllPhones(smartphones);
		smartphones = sqlConnection.getAllPhones();

		sqlConnection.setAllAppVersions(apps);
		apps = sqlConnection.getAllAppVersions();

		sqlConnection.setAllGroups(groups);
		groups = sqlConnection.getAllGroups();
	}

	/**
	 * Gets the smartphones.
	 *
	 * @return the smartphones
	 */
	public List<Smartphone> getSmartphones() {
		return smartphones;
	}

	/**
	 * Sets the smartphones.
	 *
	 * @param smartphones the new smartphones
	 */
	public void setSmartphones(List<Smartphone> smartphones) {
		this.smartphones = smartphones;
		save();
	}

	/**
	 * Gets the apps.
	 *
	 * @return the apps
	 */
	public List<AppVersion> getApps() {
		return apps;
	}

	/**
	 * Sets the apps.
	 *
	 * @param apps the new apps
	 */
	public void setApps(List<AppVersion> apps) {
		this.apps = apps;
		save();
	}

	/**
	 * Gets the groups.
	 *
	 * @return the groups
	 */
	public List<Group> getGroups() {
		return groups;
	}

	/**
	 * Sets the groups.
	 *
	 * @param groups the new groups
	 */
	public void setGroups(List<Group> groups) {
		this.groups = groups;
		save();
	}
}


text:
namespace content {
class NavigationHandle;
}  // namespace content

namespace payments {
// The navigation throttle for the payment handler WebContents, used to
// prevent the WebContents from openning pages of certain categories, e.g. pdf.
class PaymentHandlerNavigationThrottle : public content::NavigationThrottle {
 public:
  explicit PaymentHandlerNavigationThrottle(
      content::NavigationHandle* navigation_handle);
  ~PaymentHandlerNavigationThrottle() override;

  PaymentHandlerNavigationThrottle(const PaymentHandlerNavigationThrottle&) =
      delete;
  PaymentHandlerNavigationThrottle& operator=(
      const PaymentHandlerNavigationThrottle&) = delete;

  // Marks the given WebContents as a PaymentHandler WebContents. Ignores null
  // web_contents.
  static void MarkPaymentHandlerWebContents(content::WebContents* web_contents);

  static std::unique_ptr<PaymentHandlerNavigationThrottle>
  MaybeCreateThrottleFor(content::NavigationHandle* handle);

  // content::NavigationThrottle implementation:
  ThrottleCheckResult WillProcessResponse() override;
  const char* GetNameForLogging() override;
};
}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_HANDLER_NAVIGATION_THROTTLE_H_


text:
from sys import exit
from random import randint

# Class structure from game concept
"""
Map
- next_scene
-opening_scene
Engine
- play
Scene
- enter
  Death
  Central Corridor
  Laser Weapon Armory
  The Bridge
  Excape Pod

"""

# Actual class creation

class Scene(object):
    def enter(self):
        print "This scene is not yet configured. Subclass it and implement enter()."
        exit(1)

class Engine(object):
    def __init__(self, scene_map):
        self.scene_map = scene_map

    def play(self):
        current_scene = self.scene_map.opening_scene()
        print "first instance current_scene:  %s" % current_scene

        while True:
            print "\n---------"
            next_scene_name = current_scene.enter() # calls the enter function for each scene to get the next_scene_name
            print "next_scene_name: %s " % next_scene_name
            current_scene = self.scene_map.next_scene(next_scene_name) # This serves to change the current scene value
            print "second instance current_scene:  %s" %  current_scene

class Death(Scene):
    quips = [
             "You died. You knida suck at this.",
             "Your mom would be proud...if she were smarter.",
             "Such a luser.",
             "I have a small puppy that's better at this."
         ]
    def enter(self):
        print Death.quips[randint(0, len(self.quips)-1)]
        exit(1)

class CentralCorridor(Scene):
    def enter(self):
        print "This Gothons of Planet Percal #25 invaded your ship and destroyed"
        print "your entire crew. You are the last surviving member and your last"
        print "mission is to get the neutron destruct bomb from the Weapons Armory."
        print "put it in the bridge, and blow ths ship up after getting into an "
        print "escape pod."
        print "\n"
        print "You\'re running down the central corridpr to the Weapons Armory when"
        print "a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume"
        print "flowing around his hate filled body. He\'s blocking the door to the"
        print "Armory and about to pull a weapon to blast you."
        print "\n"
        print "Try one of this if you don't know what to do: shoot!, dodge!, or tell a joke"

        action = raw_input("> ")

        if action == "shoot!":
            print "Quick on the draw you yank out your blaster and fire it at the Gothon."
            print "His clown costume is flowing and moving around his body, which throws"
            print "off your aim. Your laser hits his custom but misses him entirely. This"
            print "completely ruins his brand new costume his mother bought him, which"
            print "makes him fly into a rage and blast you repeatedly in the face until"
            print "you are dead. Then he eats you."
            return 'death'

        elif action == "dodge!":

            print "Like a world class boxer you dodge, weave, slip and slide right"
            print "as th Gothon's blaster cranks a laser past your head."
            print "In the middle of your artful dodge your foot slips and you"
            print "bang your head on the metal wall and pass out."
            print "You wake up shortly after only to die as the Gothon stomps on"
            print "your head and eats you."
            return 'death'

        elif action =="tell a joke":
            print "Lucky for you they made you learn Gothon insults in the acedemy."
            print "You tell the one Gothon joke you know:"
            print "Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr."
            print "The Gothon stops , tries not to laugh, then busts out laughing and can't move."
            print "while he's laughing you run up and shoot him square in the head"
            print "putting him down, then through then jump through the Weapon Armory door."
            return 'laser_weapon_armory'
        else:
            print"DOES NOT COMPUTE!"
            return 'central_corridor'

class LaserWeaponArmory(Scene):
    def enter(self):
        print "You do a dive roll into the Weapon Armory, crouch and scan the room"
        print "for more Gothons that might be hiding. It's dead wuiet, too quiet."
        print "You stand up and run to the far side of the room and find the"
        print "neutron bomb in its container. There's a keypad lock on the box"
        print "and you need the code to get the bomb out. if you get the code"
        print "wrong 10 times then the lock closes forever and you can't"
        print "get the bomb. The code is 3 digits."
        code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
        print "If your feeling lucky you may try this number: %s" % code
        guess = raw_input("[keypad]> ")
        guesses = 1

        while guess != code and guesses < 10:
            print "BZZZZEDDD!"
            guesses += 1
            guess = raw_input("[keypad]> ")

        if guess == code:
            print "The container clicks open and the seal breaks, letting gas out."
            print "You grab the neutron bomb and run as fast as you can to the"
            print "bridge where you must place it in the right spot."
            return 'the_bridge'
        else:
            print "The lock buzzes one last time and then you hear a sickening"
            print "melting sound as the mechanism is fused together."
            print "You decide to sit there, and finally the Gothons blow up the"
            print "ship from their ship and you die."
            return 'death'

class TheBridge(Scene):
    def enter(self):
        print "You burst unto the Bridge with the neutron destruction bomb"
        print "under our arm and surprise 5 Gothons who are tring to"
        print "take control of the ship. Each of them has an even uglier"
        print "clown costume than the last. They haven't pulled their"
        print "weapons out yet, as they see the active bomb under your"
        print "arm and don't want to set it off."
        print "\n"
        print "suggested response: 'slowly place the bomb'"

        action = raw_input("> ")

        if action == "throw the bomb":
            print "In a panic you throw the bomb at the group of Gothons."
            print "and make a leap for the door. Rights as you drop it a"
            print "Gothon shoots you right in the back killing you."
            print "As you die you see another Gothon frantically try to disarm"
            print "the bomb. You die knowing they will probably blow up when"
            print "it goes off."
            return 'death'
        elif action == "slowly place the bomb":
            print "You point your blaster at the bomb under your arm"
            print "and the Gothons put their hands up and start to sweat."
            print "You inch backward to the door, open it, and then carefully"
            print "place the bomb on the floor, pointing your blaster at it."
            print "You then jumpback through the door, puch the close button"
            print "and blast the lock so the Gothons can't get out."
            print "Now that the bomb is placed you run to the escape pod to"
            print "get off this tin can"
            return 'escape_pod'
        else:
            print "DOES NOT COMPUTE!"
            return "the_bridge"

class EscapePod(Scene):
    def enter(self):
        print "You rush through the ship desperately trying to make it to"
        print "the excape pad before the whole ship explodes. It seems like"
        print "hardly any Gothons are on the ship, so your run is clear of"
        print "interference. You get to the chamber with the escape pods, and"
        print "now need to pick one to take. SOme of them could be damaged"
        print "but you don't have time to look. There's 5 pods, which one"
        print "do you take?"

        good_pod = randint(1,5)
        print "I would suggest the pod number of: %s" % good_pod
        guess = raw_input("[pad #]> ")

        if int(guess) != good_pod:
            print "You jump into pod %s and hit the eject button." % guess
            print "The pod escapes out into the void of space, then"
            print "implodes as the hull ruptures, crushing your body"
            print "into jam jelly."
            return 'death'
        else:
            print "You jump into pod %s and hit the eject button." % guess
            print "The pod easily slides out into space heading to"
            print "the planet below. As it flies to the planet, you look"
            print "back ans see your ship implode then explode like a"
            print "bright star, taking out the Gothon ship at the same"
            print "time. You won!"

            return 'finished'

class Map(object):

    scenes = {
        'central_corridor': CentralCorridor(),
        'laser_weapon_armory': LaserWeaponArmory(),
        'the_bridge': TheBridge(),
        'escape_pod': EscapePod(),
        'death': Death()
        }

    def __init__(self, start_scene):
        self.start_scene = start_scene

    def next_scene(self, scene_name):
        print "get function calls:  %s" % Map.scenes.get(scene_name)
        return Map.scenes.get(scene_name)

    def opening_scene(self):
        return self.next_scene(self.start_scene)
        """ """

a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()

"""
STUDY DRILLS

1. Door lock guessing 11 times, why?
   answer: guesses variable set to 0 rather than .

2. How the returning the next door works?
   answer: The engine class uses the while loop in the play function to juggle through
           the variuos doors.
           The return value of the enter function of each scene class will give the next scene
           which then becomes the current_scene and has its enter function called. This continues
           until Map class opening_scene function returns no value.

 """


text:
require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(*Rails.groups)

module Vanzeiro
  class Application < Rails::Application
    config.assets.enabled = true
    config.assets.compile = true
    config.exceptions_app = routes
    config.autoload_paths << Rails.root.join('lib')
    config.assets.paths << Rails.root.join('app', 'assets', 'fonts', 'videos')

    Dir.glob(Rails.root.join('config/locales/**/*/')).each do |dir|
      paths['config/locales'] << dir
    end

    config.active_record.raise_in_transactional_callbacks = true

    config.generators do |g|
      g.hidden_namespaces << :test_unit << :erb << :mongoid << :less << :sass <<
        :scss << :js << :coffee << :active_record

      g.view_specs      false
      g.helper_specs    false
      g.assets          false
      g.helper          false
    end

    config.time_zone = 'Brasilia'
    config.i18n.default_locale = :'pt-BR'

    time_path = "#{Rails.root}/config/locales/pt-BR/vendors/business_time.yml"
    BusinessTime::Config.load(time_path)
  end
end


text:
E_BADARGS=65
E_BADDEPS=66
E_SOURCE_DONT_EXISTS=67
E_TARGET_DONT_EXISTS=68

EXPECTED_ARGS=2

#echo $0
if [ $# -ne $EXPECTED_ARGS ]
then
  echo " This script expect $EXPECTED_ARGS arguments instead of $#"
  exit $E_BADARGS
fi

AWK=$(which awk)
MKDIR=$(which mkdir)
RM=$(which rm)
CP=$(which cp)
LN=$(which ln)
READLINK=$(which readlink)

SOURCE=$1
TARGET=$2
echo "*** Copying files & settings from $SOURCE $TARGET"

if [ ! -d $SOURCE ]; then
  echo " ABORTED: Source $SOURCE doesn't exists"
  exit $E_SOURCE_DONT_EXISTS
fi
if [ ! -d $TARGET ]; then
  echo " ABORTED: Target $TARGET doesn't exists"
  exit $E_TARGET_DONT_EXISTS
fi

S_DIR="$SOURCE/sites"
T_DIR="$TARGET/sites"

# For each directory except "all" inside $SOURCE's sites
for drup_site in $S_DIR/*; do
  if [ -d $drup_site ]; then
    if [ ! $drup_site = "$S_DIR/all" ]; then
      d_site=$(echo $drup_site | $AWK 'BEGIN {FS="/" } ; { print $NF }')
      # If the site doesn't exits we recreate it
      if [ ! -d "$T_DIR/$d_site" ]; then
        $MKDIR -p $T_DIR/$d_site
      fi
      # If there are files directory on source we replace target's with a copy of it
      if [ -d "$drup_site/files" ]; then
        $RM -fr $T_DIR/$d_site/files
        if [ -L "$drup_site/files" ]; then
          $LN -s $($READLINK -f "$drup_site/files") $T_DIR/$d_site
        else
          $CP -a $drup_site/files $T_DIR/$d_site
        fi
      fi
      # If there are private directory on source we replace target's with a copy of it
      if [ -d "$drup_site/private" ]; then
        $RM -fr $T_DIR/$d_site/private
        if [ -L "$drup_site/private" ]; then
          $LN -s $($READLINK -f "$drup_site/private") $T_DIR/$d_site
        else
          $CP -a $drup_site/private $T_DIR/$d_site
        fi
      fi
      # We only copy settings.php if it doesn't exists on target or if a flag is set
      if [ ! "${CONF_OVERWRITE}" = 'true' ] || [ ! -e "$T_DIR/$d_site/settings.php" ] ; then
        $CP -a $drup_site/settings.php $T_DIR/$d_site/
      else
        if [ ! "${CONF_OVERWRITE}" = 'true' ] && [ ! "${CONF_OVERWRITE}" = 'no_warn' ]; then
          echo "WARNING: $T_DIR/$d_site/settings.php already exists NOT overwritten"
        fi
      fi
    fi
  fi
done


text:
class Viewer_interface;

class Texture{
private:
     int Width;
     int Height;
     int size;
    GLubyte *data;
public:
    Texture(int w, int h)
    {
        Width = w;
        Height = h;
        size = 3*Height*Width;
        data = new GLubyte[size];
    }
    int getWidth() const {return Width;}
    int getHeight() const {return Height;}
    int getSize() const {return size;}
    void setData(int i, int j, int r, int g, int b){
        data[j*Width*3 +i*3] = r;
        data[j*Width*3 +i*3+1] = g;
        data[j*Width*3 +i*3+2] = b;}
    GLubyte* getData(){return data; }

};
class SCENE_IMPLICIT_FUNCTION_ITEM_EXPORT Scene_implicit_function_item
  : public CGAL::Three::Scene_item
{
  Q_OBJECT

  typedef qglviewer::ManipulatedFrame ManipulatedFrame;

public:
  Scene_implicit_function_item(Implicit_function_interface*);
  virtual ~Scene_implicit_function_item();

  Implicit_function_interface* function() const { return function_; }

  bool isFinite() const { return true; }
  bool isEmpty() const { return false; }
  void compute_bbox() const;

  Scene_implicit_function_item* clone() const { return NULL; }

  // rendering mode
  virtual bool supportsRenderingMode(RenderingMode m) const;
  virtual bool manipulatable() const { return true; }
  virtual ManipulatedFrame* manipulatedFrame() { return frame_; }

  // actually draw() is also overloaded to detect when the cut plane is moved
  virtual void draw()const {}
  virtual void draw(CGAL::Three::Viewer_interface*) const;
  virtual void draw_edges(CGAL::Three::Viewer_interface*) const;

  virtual QString toolTip() const;
  virtual void invalidateOpenGLBuffers();
public Q_SLOTS:
  void plane_was_moved() { need_update_ = true; }
  void compute_function_grid() const;
  void timerEvent(QTimerEvent*);

private:
  typedef qglviewer::Vec                  Point;
  typedef std::pair <Point,double>        Point_value;
  void compute_min_max();

private:
  Implicit_function_interface* function_;
  ManipulatedFrame* frame_;

  mutable bool need_update_;
  int grid_size_;
  double max_value_;
  double min_value_;
  mutable Point_value implicit_grid_[SCENE_IMPLICIT_GRID_SIZE][SCENE_IMPLICIT_GRID_SIZE];

  Color_ramp blue_color_ramp_;
  Color_ramp red_color_ramp_;

  enum VAOs {
      Plane = 0,
      BBox,
      Grid,
      NbOfVaos = Grid +1
  };
  enum VBOs {
      Quad_vertices = 0,
      TexMap,
      Cube_vertices,
      Grid_vertices,
      NbOfVbos = Grid_vertices +1
  };

  std::vector<float> positions_cube;
  std::vector<float> positions_grid;
  std::vector<float> positions_tex_quad;
  std::vector<float> texture_map;
  Texture *texture;

  mutable QOpenGLShaderProgram *program;
  mutable GLuint textureId;

  GLuint vao;
  GLuint buffer[4];
  using CGAL::Three::Scene_item::initialize_buffers;
  void initialize_buffers(CGAL::Three::Viewer_interface *viewer) const;
  void compute_vertices_and_texmap(void);
  void compute_texture(int, int);
};

#endif // SCENE_IMPLICIT_FUNCTION_ITEM


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Statistics of iobj in UD_Nheengatu-CompLin</title>
    <link rel="root" href=""/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/jquery-ui-redmond.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style-vis.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/hint.css"/>

          home

          edit page
          issue tracker

          <gcse:search></gcse:search>

        This page pertains to UD version 2.

            It appears that you have Javascript disabled.
            Please consider enabling Javascript for this page to see the visualizations.

Treebank Statistics: UD_Nheengatu-CompLin: Relations: iobj

This relation is universal.

17 nodes (1%) are attached to their parents as iobj.

17 instances of iobj (100%) are left-to-right (parent precedes child).
Average distance between parent and child is 1.76470588235294.

The following 3 pairs of parts of speech are connected with iobj: <tt>VERB</tt>-<tt>PRON</tt> (11; 65% instances), <tt>VERB</tt>-<tt>NOUN</tt> (5; 29% instances), <tt>VERB</tt>-<tt>PROPN</tt> (1; 6% instances).

# visual-style 5	bgColor:blue
# visual-style 5	fgColor:white
# visual-style 3	bgColor:blue
# visual-style 3	fgColor:white
# visual-style 3 5 iobj	color:blue
1	Aintá	aintá	PRON	PRON	Number=Plur|Person=3|PronType=Prs	3	nsubj	_	TokenRange=0:5
2	paá	paá	PART	RPRT	Evident=Nfh	3	advmod	_	TokenRange=6:9
3	umeẽ	meẽ	VERB	V	Person=3|VerbForm=Fin	0	root	_	TokenRange=10:14
4	supiara	supiara	NOUN	N	Number=Sing|Rel=Abs	3	obj	_	TokenRange=15:22
5	i	i	PRON	PRON2	Case=Gen|Number=Sing|Person=3|PronType=Prs	3	iobj	_	TokenRange=23:24
6	xupé	xupé	ADP	ADP	_	5	case	_	SpaceAfter=No|TokenRange=25:29
7	,	,	PUNCT	PUNCT	_	9	punct	_	TokenRange=29:30
8	nhaãsé	nhaãsé	ADV	CADV	_	9	advmod	_	TokenRange=31:37
9	umanú	manú	VERB	V	Person=3|VerbForm=Fin	3	parataxis	_	TokenRange=38:43
10	ã	ã	PART	PFV	_	9	advmod	_	SpaceAfter=No|TokenRange=44:45
11	.	.	PUNCT	PUNCT	_	3	punct	_	SpaceAfter=No|TokenRange=45:46

# visual-style 9	bgColor:blue
# visual-style 9	fgColor:white
# visual-style 6	bgColor:blue
# visual-style 6	fgColor:white
# visual-style 6 9 iobj	color:blue
1	Penhẽ	penhẽ	PRON	PRON	Number=Plur|Person=2|PronType=Prs	2	nsubj	_	TokenRange=0:5
2	pesendú	sendú	VERB	V	Number=Plur|Person=2|VerbForm=Fin	0	root	_	TokenRange=6:13
3	será	será	PART	PQ	PartType=Int	2	advmod	_	TokenRange=14:18
4	katú	katú	ADV	ADV	_	2	advmod	_	TokenRange=19:23
5	maã	maã	PRON	INT	PronType=Int	2	obj	_	TokenRange=24:27
6	anheẽ	nheẽ	VERB	V	Number=Sing|Person=1|VerbForm=Fin	5	acl:relcl	_	TokenRange=28:33
7	waá	waá	PRON	REL	Number=Sing	6	obj	_	TokenRange=34:37
8	se	se	PRON	PRON2	Case=Gen|Number=Sing|Person=1|Poss=Yes|PronType=Prs	9	nmod:poss	_	TokenRange=38:40
9	raíra	taíra	NOUN	N	Number=Sing|Rel=Cont	6	iobj	_	TokenRange=41:46
10	supé	supé	ADP	ADP	_	9	case	_	SpaceAfter=No|TokenRange=47:51
11	?	?	PUNCT	PUNCT	_	2	punct	_	SpaceAfter=No|TokenRange=51:52

# visual-style 10	bgColor:blue
# visual-style 10	fgColor:white
# visual-style 9	bgColor:blue
# visual-style 9	fgColor:white
# visual-style 9 10 iobj	color:blue
1	Ape	ape	ADV	ADVD	PronType=Dem	8	advmod	_	TokenRange=0:3
2	kwá	kwá	PRON	DEMX	Deixis=Prox|Number=Sing|PronType=Dem	8	nsubj	_	TokenRange=4:7
3	upurungitá	purungitá	VERB	V	Person=3|VerbForm=Fin	2	acl:relcl	_	TokenRange=8:18
4	waá	waá	PRON	REL	Number=Sing|PronType=Rel	3	nsubj	_	TokenRange=19:22
5	amú	amú	DET	IND	Number=Sing|PronType=Ind	6	det	_	TokenRange=23:26
6	nheenga	nheenga	NOUN	N	Number=Sing	3	obl	_	TokenRange=27:34
7	rupí	rupí	ADP	ADP	_	6	case	_	TokenRange=35:39
8	urikuté	rikuté	VERB	V	Person=3|VerbForm=Fin	0	root	_	TokenRange=40:47
9	upurandú	purandú	VERB	V	Person=3|VerbForm=Fin	8	xcomp	_	TokenRange=48:56
10	Deus	deus	PROPN	PROPN	_	9	iobj	_	TokenRange=57:61
11	irumu	irumu	ADP	ADP	_	10	case	_	TokenRange=62:67
12	ukwawa	kwawa	VERB	V	Person=3|VerbForm=Fin	9	ccomp	_	TokenRange=68:74
13	arama	arama	SCONJ	SCONJ	_	12	mark	_	TokenRange=75:80
14	mayesawa	mayesawa	ADV	ADVR	_	12	ccomp	_	TokenRange=81:89
15	taá	taá	PART	CQ	PartType=Int	14	advmod	_	TokenRange=90:93
16	kwá	kwá	PRON	DEMX	Deixis=Prox|Number=Sing|PronType=Dem	14	nsubj	_	TokenRange=94:97
17	umbeú	mbeú	VERB	V	Person=3|VerbForm=Fin	16	acl:relcl	_	TokenRange=98:103
18	waá	waá	PRON	REL	Number=Sing|PronType=Rel	17	obj	_	TokenRange=104:107
19	aintá	aintá	PRON	PRON2	Case=Gen|Number=Plur|Person=3|PronType=Prs	17	iobj	_	TokenRange=108:113
20	supé	supé	ADP	ADP	_	19	case	_	SpaceAfter=No|TokenRange=114:118
21	.	.	PUNCT	PUNCT	_	8	punct	_	SpaceAfter=No|TokenRange=118:119

© 2014–2021
            Universal Dependencies contributors.
            Site powered by Annodoc and brat
.


text:
<?php

namespace Snide\Osrc;

use Snide\Osrc\Model\User;
use Snide\Osrc\Hydrator\SimpleHydrator;
use Guzzle\Http\Client as GuzzleClient;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Class Client
 *
 * @author Pascal DENIS <pascal.denis.75@gmail.com>
 */
class Client
{
    /**
     * API URL
     *
     * @var string
     */
    protected $endpoint = 'http://osrc.dfm.io';

    /**
     * Object Hydrator
     *
     * @var SimpleHydrator
     */
    protected $hydrator;

    /**
     * Guzzle Client
     *
     * @var \Guzzle\Http\Client
     */
    protected $httpClient;

    /**
     * Constructor
     *
     * @param Hydrator\SimpleHydrator $hydrator
     */
    public function __construct(SimpleHydrator $hydrator = null)
    {
        if (null === $hydrator) {
            $hydrator = new SimpleHydrator();
        }

        $this->setHydrator($hydrator);

        $this->httpClient = new GuzzleClient($this->endpoint, array());
    }

    /**
     * Fetch data from User URL
     *
     * @param Model\User $user
     * @return Model\User
     */
    public function fetchUser(User $user)
    {
        $response = $this->getResponse(
            sprintf('%s.json',
                $user->getUsername()
            )
        );

        return $this->hydrator->hydrate($user, $response);
    }

    /**
     * Getter hydrator
     *
     * @return SimpleHydrator
     */
    public function getHydrator()
    {
        return $this->hydrator;
    }

    /**
     * Setter hydrator
     *
     * @param SimpleHydrator $hydrator
     */
    public function setHydrator(SimpleHydrator $hydrator)
    {
        $this->hydrator = $hydrator;
    }

    /**
     * Add Http client subscriber
     *
     * @param EventSubscriberInterface $subscriber
     */
    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->httpClient->addSubscriber($subscriber);
    }

    /**
     * Get Response from API
     * Response is an array (Result of json_decode)
     *
     * @param string $uri API URI
     * @param array $queryParams Query params
     * @return mixed
     */
    protected function getResponse($uri, array $queryParams = array())
    {
        $request = $this->httpClient->get($uri, array(), array('query' => $queryParams));

        return $request->send()->json();
    }
}


text:
using namespace std;
using namespace ros::console::levels;

const char* HOST_IP = "10.0.0.108";
//const char* HOST_IP = "192.168.1.70";
const int HOST_PORT = 4000;
int sock_image_sender;
sockaddr_in client_addr_image;
class DepthImageSenderCls
{
public:
	DepthImageSenderCls();
private:
	ros::NodeHandle nh_;
	//image_transport::ImageTransport it_;
	//image_transport::Subscriber< stereo_msgs::DisparityImage> disp_image_sub_;
	ros::Subscriber disp_image_sub_;
	void disparityCallback(const stereo_msgs::DisparityImage::ConstPtr& disp_image_msg);
	//void disparityCallback(const stereo_msgs::DisparityImage& disp_image_msg);
	int Width;
	int Height;
};

DepthImageSenderCls::DepthImageSenderCls()// : it_(nh_)
{
	disp_image_sub_ = nh_.subscribe("/stereo/disparity", 1, &DepthImageSenderCls::disparityCallback, this);
	////////////////////
	// UDP command sender
	if ((sock_image_sender = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		ROS_ERROR("Socket creation problem!");
		exit(1);
	}
	hostent *host;
	host = (hostent *) gethostbyname((char *)HOST_IP);
	client_addr_image.sin_family = AF_INET;
	client_addr_image.sin_port = htons(HOST_PORT);
	client_addr_image.sin_addr = *((in_addr *)host->h_addr);
	bzero(&(client_addr_image.sin_zero),8);
	ROS_INFO("Disparity sender socket created.");
}

void DepthImageSenderCls::disparityCallback(
	//const stereo_msgs::DisparityImage& disp_image_msg)
	const stereo_msgs::DisparityImage::ConstPtr& disp_image_msg)
{
	ROS_INFO("Disparity image received.");
	//cv_bridge::CvImageConstPtr cv_ptr_disp = cv_bridge::toCvShare(disp_image_msg->image, disp_image_msg, sensor_msgs::image_encodings::TYPE_32FC1);
	cv_bridge::CvImageConstPtr cv_ptr_disp = cv_bridge::toCvCopy(disp_image_msg->image, sensor_msgs::image_encodings::TYPE_32FC1);
	const cv::Mat disp_image = cv_ptr_disp->image;
	ROS_INFO("Disparity image converted.");
	ROS_INFO("Image size %dx%d", disp_image.cols, disp_image.rows);
	vector<int> compression_params;
	compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
    compression_params.push_back(75);
	//cv::Mat rgb_image;
	//cvtColor(disp_image, rgb_image, CV_GRAY2BGR );
	//ROS_INFO("Disparity image color converted.");
	//cv::imwrite("/tmp/disp.jpg", rgb_image);
	cv::imwrite("/tmp/disp.jpg", disp_image);

	vector<uchar> buff;
	cv::imencode(".jpg", disp_image*2, buff, compression_params);
	ROS_INFO("Disparity image encoded.");
	sendto(sock_image_sender, (void*)buff.data(), buff.size(), 0, (sockaddr *)&client_addr_image, sizeof(sockaddr));
	ROS_INFO("Disparity image sent.");
	// Release images using deallocate (not release) otherwise memory leakge happens after imread
	//disp_image.deallocate();
	ROS_INFO("Disparity image deallocated.");
}

int main(int argc, char** argv)
{
	ros::init(argc, argv, "DepthImageSender");
	DepthImageSenderCls depth_image_sender;
	ros::spin();
	close (sock_image_sender);
}


text:
package h2o.common.util.valid;

public interface Validator {

    String getMessage();

    void setK(String k);

    String getK();

    boolean validate(Object bean);

}


text:
/*===================================================================
SDL_MT2DBeep.h SDL_MT2DBeep.cpp created by: Lucas Zimerman Fraulob

	Here, you'll see the implementation of the PC SPEAKER code
	in SDL, the only function required is SDL_Beep, and the usage
	is similar to the normal MT2D Beep code, you need a frequency
	and a delayed timing that the beep will occur
===================================================================*/

void SDL_Beep(int frequency, int TimeMS);


text:
import {rollup} from "rollup";
import { existsSync, readdirSync, statSync } from "fs";
import commonjsPlugin from "rollup-plugin-commonjs";
import nodeResolvePlugin from "rollup-plugin-node-resolve";
import { dirname, join, resolve } from "path";
import replace from "rollup-plugin-replace";
import terser from '@rollup/plugin-terser';
import alias from "@rollup/plugin-alias";
import { fileURLToPath } from "url";
import babel from "@rollup/plugin-babel";

const isProduction = process.env.NODE_ENV === 'production';

const __dirname = dirname(fileURLToPath(import.meta.url));
const benchmarks = readdirSync(__dirname).filter(file => statSync(join(__dirname, file)).isDirectory());
const resolvePkg = pkg => resolve(__dirname, '../packages', pkg, 'dist', 'index.esm.js');

console.log(resolvePkg('inferno'));

// see below for details on the options
const plugins = [
  replace({
    'process.env.NODE_ENV': '"production"',
    sourcemap: false
  }),
  nodeResolvePlugin({
    preferBuiltins: false
  }),
  babel({
    exclude: 'node_modules/**',
    sourceMaps: false,
    babelrc: false,
    presets: [['@babel/env', {loose: true, modules: false}]],
    plugins: [
      ['babel-plugin-inferno', {imports: true, defineAllArguments: true}],
      ["@babel/plugin-proposal-class-properties", { "loose": true }]
    ]
  }),
  commonjsPlugin({
    sourceMap: false
  }),
  alias({
    resolve: ['.js'],
    entries: [
      {find: 'inferno', replacement: resolvePkg('inferno')},
      {find: 'inferno-animation', replacement: resolvePkg('inferno-animation')},
      {find: 'inferno-compat', replacement: resolvePkg('inferno-compat')},
      {find: 'inferno-create-class', replacement: resolvePkg('inferno-create-class')},
      {find: 'inferno-create-element', replacement: resolvePkg('inferno-create-element')},
      {find: 'inferno-hydrate', replacement: resolvePkg('inferno-hydrate')},
      {find: 'inferno-extras', replacement: resolvePkg('inferno-extras')},
      {find: 'inferno-hyperscript', replacement: resolvePkg('inferno-hyperscript')},
      {find: 'inferno-mobx', replacement: resolvePkg('inferno-mobx')},
      {find: 'inferno-redux', replacement: resolvePkg('inferno-redux')},
      {find: 'inferno-router', replacement: resolvePkg('inferno-router')},
      {find: 'inferno-server', replacement: resolvePkg('inferno-server')},
      {find: 'inferno-shared', replacement: resolvePkg('inferno-shared')},
      {find: 'inferno-test-utils', replacement: resolvePkg('inferno-test-utils')},
      {find: 'inferno-vnode-flags', replacement: resolvePkg('inferno-vnode-flags')},
      {find: 'inferno-clone-vnode', replacement: resolvePkg('inferno-clone-vnode')},
      {find: 'mobx', replacement: join(__dirname, '../../node_modules/mobx/dist/mobx.esm.js')}
    ]
  })
];

if (isProduction) {
  plugins.push(
    terser({
      compress: {
        ecma: 5,
        inline: true,
        if_return: false,
        reduce_funcs: false,
        passes: 5,
        comparisons: false,
      },
      ie8: false,
      mangle: {
        toplevel: true
      },
      parse: {
        html5_comments: false,
        shebang: false
      },
      toplevel: false,
      warnings: false
    })
  );
}

benchmarks.forEach(dir => {
  const benchmarkPath = join(__dirname, dir);
  const appJsPath = resolve(benchmarkPath, 'app.js')

  // Don't build examples that don't have app.js
  if (!existsSync(appJsPath)) return

  const inputOptions = {
    input: appJsPath,
    plugins: plugins
  };

  const start = new Date();

  console.log(`Build started -- ${start}`);

  rollup(inputOptions).then(function (opts) {
    return opts.write({
      format: 'iife',
      file: join(benchmarkPath, 'dist', 'bundle.js'),
      sourcemap: false,
      name: 'inferno'
    });
  });
});


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.5.2" />
<title>git-fetch(1)</title>

git-fetch(1) Manual Page

NAME

git-fetch -
   Download objects and refs from another repository

SYNOPSIS

git fetch [<options>] [<repository> [<refspec>…]]
git fetch [<options>] <group>
git fetch --multiple [<options>] [(<repository> | <group>)…]
git fetch --all [<options>]

DESCRIPTION

Fetches named heads or tags from one or more other repositories,
along with the objects necessary to complete them.

The ref names and their object names of fetched refs are stored
in <tt>.git/FETCH_HEAD</tt>.  This information is left for a later merge
operation done by git merge.

When <refspec> stores the fetched result in remote-tracking branches,
the tags that point at these branches are automatically
followed.  This is done by first fetching from the remote using
the given <refspec>s, and if the repository has objects that are
pointed by remote tags that it does not yet have, then fetch
those missing tags.  If the other end has tags that point at
branches you are not interested in, you will not get them.

git fetch can fetch from either a single named repository,
or from several repositories at once if <group> is given and
there is a remotes.<group> entry in the configuration file.
(See git-config(1)).

OPTIONS

--all

        Fetch all remotes.

-a

--append

        Append ref names and object names of fetched refs to the
        existing contents of <tt>.git/FETCH_HEAD</tt>.  Without this
        option old data in <tt>.git/FETCH_HEAD</tt> will be overwritten.

--depth=<depth>

        Deepen the history of a shallow repository created by
        <tt>git clone</tt> with <tt>--depth=<depth></tt> option (see git-clone(1))
        to the specified number of commits from the tip of each remote
        branch history. Tags for the deepened commits are not fetched.

--dry-run

        Show what would be done, without making any changes.

-f

--force

        When git fetch is used with <tt><rbranch>:<lbranch></tt>
        refspec, it refuses to update the local branch
        <tt><lbranch></tt> unless the remote branch <tt><rbranch></tt> it
        fetches is a descendant of <tt><lbranch></tt>.  This option
        overrides that check.

-k

--keep

        Keep downloaded pack.

--multiple

        Allow several <repository> and <group> arguments to be
        specified. No <refspec>s may be specified.

-p

--prune

        After fetching, remove any remote-tracking branches which
        no longer exist on the remote.

-n

--no-tags

        By default, tags that point at objects that are downloaded
        from the remote repository are fetched and stored locally.
        This option disables this automatic tag following. The default
        behavior for a remote may be specified with the remote.<name>.tagopt
        setting. See git-config(1).

-t

--tags

        Most of the tags are fetched automatically as branch
        heads are downloaded, but tags that do not point at
        objects reachable from the branch heads that are being
        tracked will not be fetched by this mechanism.  This
        flag lets all tags and their associated objects be
        downloaded. The default behavior for a remote may be
        specified with the remote.<name>.tagopt setting. See
        git-config(1).

--recurse-submodules[=yes|on-demand|no]

        This option controls if and under what conditions new commits of
        populated submodules should be fetched too. It can be used as a
        boolean option to completely disable recursion when set to no or to
        unconditionally recurse into all populated submodules when set to
        yes, which is the default when this option is used without any
        value. Use on-demand to only recurse into a populated submodule
        when the superproject retrieves a commit that updates the submodule’s
        reference to a commit that isn’t already in the local submodule
        clone.

--no-recurse-submodules

        Disable recursive fetching of submodules (this has the same effect as
        using the --recurse-submodules=no option).

--submodule-prefix=<path>

        Prepend <path> to paths printed in informative messages
        such as "Fetching submodule foo".  This option is used
        internally when recursing over submodules.

--recurse-submodules-default=[yes|on-demand]

        This option is used internally to temporarily provide a
        non-negative default value for the --recurse-submodules
        option.  All other methods of configuring fetch’s submodule
        recursion (such as settings in gitmodules(5) and
        git-config(1)) override this option, as does
        specifying --[no-]recurse-submodules directly.

-u

--update-head-ok

        By default git fetch refuses to update the head which
        corresponds to the current branch.  This flag disables the
        check.  This is purely for the internal use for git pull
        to communicate with git fetch, and unless you are
        implementing your own Porcelain you are not supposed to
        use it.

--upload-pack <upload-pack>

        When given, and the repository to fetch from is handled
        by git fetch-pack, --exec=<upload-pack> is passed to
        the command to specify non-default path for the command
        run on the other end.

-q

--quiet

        Pass --quiet to git-fetch-pack and silence any other internally
        used git commands. Progress is not reported to the standard error
        stream.

-v

--verbose

        Be verbose.

--progress

        Progress status is reported on the standard error stream
        by default when it is attached to a terminal, unless -q
        is specified. This flag forces progress status even if the
        standard error stream is not directed to a terminal.

<repository>

        The "remote" repository that is the source of a fetch
        or pull operation.  This parameter can be either a URL
        (see the section GIT URLS below) or the name
        of a remote (see the section REMOTES below).

<group>

        A name referring to a list of repositories as the value
        of remotes.<group> in the configuration file.
        (See git-config(1)).

<refspec>

        The format of a <refspec> parameter is an optional plus
        <tt>+</tt>, followed by the source ref <src>, followed
        by a colon <tt>:</tt>, followed by the destination ref <dst>.

The remote ref that matches <src>
is fetched, and if <dst> is not empty string, the local
ref that matches it is fast-forwarded using <src>.
If the optional plus <tt>+</tt> is used, the local ref
is updated even if it does not result in a fast-forward
update.

Note

If the remote branch from which you want to pull is
modified in non-linear ways such as being rewound and
rebased frequently, then a pull will attempt a merge with
an older version of itself, likely conflict, and fail.
It is under these conditions that you would want to use
the <tt>+</tt> sign to indicate non-fast-forward updates will
be needed.  There is currently no easy way to determine
or declare that a branch will be made available in a
repository with this behavior; the pulling user simply
must know this is the expected usage pattern for a branch.

Note

You never do your own development on branches that appear
on the right hand side of a <refspec> colon on <tt>Pull:</tt> lines;
they are to be updated by git fetch.  If you intend to do
development derived from a remote branch <tt>B</tt>, have a <tt>Pull:</tt>
line to track it (i.e. <tt>Pull: B:remote-B</tt>), and have a separate
branch <tt>my-B</tt> to do your development on top of it.  The latter
is created by <tt>git branch my-B remote-B</tt> (or its equivalent <tt>git
checkout -b my-B remote-B</tt>).  Run <tt>git fetch</tt> to keep track of
the progress of the remote side, and when you see something new
on the remote branch, merge it into your development branch with
<tt>git pull . remote-B</tt>, while you are on <tt>my-B</tt> branch.

Note

There is a difference between listing multiple <refspec>
directly on git pull command line and having multiple
<tt>Pull:</tt> <refspec> lines for a <repository> and running
git pull command without any explicit <refspec> parameters.
<refspec> listed explicitly on the command line are always
merged into the current branch after fetching.  In other words,
if you list more than one remote refs, you would be making
an Octopus.  While git pull run without any explicit <refspec>
parameter takes default <refspec>s from <tt>Pull:</tt> lines, it
merges only the first <refspec> found into the current branch,
after fetching all the remote refs.  This is because making an
Octopus from remote refs is rarely done, while keeping track
of multiple remote heads in one-go by fetching more than one
is often useful.

Some short-cut notations are also supported.

<tt>tag <tag></tt> means the same as <tt>refs/tags/<tag>:refs/tags/<tag></tt>;
  it requests fetching everything up to the given tag.

A parameter <ref> without a colon is equivalent to
  <ref>: when pulling/fetching, so it merges <ref> into the current
  branch without storing the remote branch anywhere locally

GIT URLS

In general, URLs contain information about the transport protocol, the
address of the remote server, and the path to the repository.
Depending on the transport protocol, some of this information may be
absent.

Git supports ssh, git, http, and https protocols (in addition, ftp,
and ftps can be used for fetching and rsync can be used for fetching
and pushing, but these are inefficient and deprecated; do not use
them).

The following syntaxes may be used with them:

ssh://[user@]host.xz[:port]/path/to/repo.git/

git://host.xz[:port]/path/to/repo.git/

http[s]://host.xz[:port]/path/to/repo.git/

ftp[s]://host.xz[:port]/path/to/repo.git/

rsync://host.xz/path/to/repo.git/

An alternative scp-like syntax may also be used with the ssh protocol:

[user@]host.xz:path/to/repo.git/

The ssh and git protocols additionally support ~username expansion:

ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/

git://host.xz[:port]/~[user]/path/to/repo.git/

[user@]host.xz:/~[user]/path/to/repo.git/

For local repositories, also supported by git natively, the following
syntaxes may be used:

/path/to/repo.git/

file:///path/to/repo.git/

These two syntaxes are mostly equivalent, except when cloning, when
the former implies --local option. See git-clone(1) for
details.

When git doesn’t know how to handle a certain transport protocol, it
attempts to use the remote-<transport> remote helper, if one
exists. To explicitly request a remote helper, the following syntax
may be used:

<transport>::<address>

where <address> may be a path, a server and path, or an arbitrary
URL-like string recognized by the specific remote helper being
invoked. See git-remote-helpers(1) for details.

If there are a large number of similarly-named remote repositories and
you want to use a different format for them (such that the URLs you
use will be rewritten into URLs that work), you can create a
configuration section of the form:

<tt>        [url "<actual url base>"]
                insteadOf = <other url base></tt>

For example, with this:

<tt>        [url "git://git.host.xz/"]
                insteadOf = host.xz:/path/to/
                insteadOf = work:</tt>

a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
rewritten in any context that takes a URL to be "git://git.host.xz/repo.git".

If you want to rewrite URLs for push only, you can create a
configuration section of the form:

<tt>        [url "<actual url base>"]
                pushInsteadOf = <other url base></tt>

For example, with this:

<tt>        [url "ssh://example.org/"]
                pushInsteadOf = git://example.org/</tt>

a URL like "git://example.org/path/to/repo.git" will be rewritten to
"ssh://example.org/path/to/repo.git" for pushes, but pulls will still
use the original URL.

REMOTES

The name of one of the following can be used instead
of a URL as <tt><repository></tt> argument:

a remote in the git configuration file: <tt>$GIT_DIR/config</tt>,

a file in the <tt>$GIT_DIR/remotes</tt> directory, or

a file in the <tt>$GIT_DIR/branches</tt> directory.

All of these also allow you to omit the refspec from the command line
because they each contain a refspec which git will use by default.

Named remote in configuration file

You can choose to provide the name of a remote which you had previously
configured using git-remote(1), git-config(1)
or even by a manual edit to the <tt>$GIT_DIR/config</tt> file.  The URL of
this remote will be used to access the repository.  The refspec
of this remote will be used by default when you do
not provide a refspec on the command line.  The entry in the
config file would appear like this:

<tt>        [remote "<name>"]
                url = <url>
                pushurl = <pushurl>
                push = <refspec>
                fetch = <refspec></tt>

The <tt><pushurl></tt> is used for pushes only. It is optional and defaults
to <tt><url></tt>.

Named file in <tt>$GIT_DIR/remotes</tt>

You can choose to provide the name of a
file in <tt>$GIT_DIR/remotes</tt>.  The URL
in this file will be used to access the repository.  The refspec
in this file will be used as default when you do not
provide a refspec on the command line.  This file should have the
following format:

<tt>        URL: one of the above URL format
        Push: <refspec>
        Pull: <refspec></tt>

<tt>Push:</tt> lines are used by git push and
<tt>Pull:</tt> lines are used by git pull and git fetch.
Multiple <tt>Push:</tt> and <tt>Pull:</tt> lines may
be specified for additional branch mappings.

Named file in <tt>$GIT_DIR/branches</tt>

You can choose to provide the name of a
file in <tt>$GIT_DIR/branches</tt>.
The URL in this file will be used to access the repository.
This file should have the following format:

<tt>        <url>#<head></tt>

<tt><url></tt> is required; <tt>#<head></tt> is optional.

Depending on the operation, git will use one of the following
refspecs, if you don’t provide one on the command line.
<tt><branch></tt> is the name of this file in <tt>$GIT_DIR/branches</tt> and
<tt><head></tt> defaults to <tt>master</tt>.

git fetch uses:

<tt>        refs/heads/<head>:refs/heads/<branch></tt>

git push uses:

<tt>        HEAD:refs/heads/<head></tt>

EXAMPLES

Update the remote-tracking branches:

<tt>$ git fetch origin</tt>

The above command copies all branches from the remote refs/heads/
namespace and stores them to the local refs/remotes/origin/ namespace,
unless the branch.<name>.fetch option is used to specify a non-default
refspec.

Using refspecs explicitly:

<tt>$ git fetch origin +pu:pu maint:tmp</tt>

This updates (or creates, as necessary) branches <tt>pu</tt> and <tt>tmp</tt> in
the local repository by fetching from the branches (respectively)
<tt>pu</tt> and <tt>maint</tt> from the remote repository.

The <tt>pu</tt> branch will be updated even if it is does not fast-forward,
because it is prefixed with a plus sign; <tt>tmp</tt> will not be.

BUGS

Using --recurse-submodules can only fetch new commits in already checked
out submodules right now. When e.g. upstream added a new submodule in the
just fetched commits of the superproject the submodule itself can not be
fetched, making it impossible to check out that submodule later without
having to do a fetch again. This is expected to be fixed in a future git
version.

SEE ALSO

git-pull(1)

GIT

Part of the git(1) suite

Last updated 2011-11-15 13:45:02 PDT