text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.pieShare.pieShareClient.services;

import java.io.ByteArrayInputStream;
import java.net.DatagramPacket;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import org.bouncycastle.util.Arrays;
import org.pieShare.pieShareClient.api.Callback;
import org.pieShare.pieTools.pieUtilities.service.pieLogger.PieLogger;

/**
 *
 * @author Richard
 */
public class InputTask implements Runnable {

	private DatagramPacket packet;
	private ClientSendTask sendTask;
	private String ackMsg = "{\"type\":\"ACK\"}";
	private Callback callback;

	public void setCallback(Callback callback) {
		this.callback = callback;
	}

	public void setSendTask(ClientSendTask sendTask) {
		this.sendTask = sendTask;
	}

	public void setPacket(DatagramPacket packet) {
		this.packet = packet;
	}

	public void run() {
		newPacketReceived();
	}

	private synchronized void newPacketReceived() {
		byte[] bytes = new byte[1024];
		bytes = Arrays.copyOfRange(bytes, 0, packet.getLength());
		PieLogger.info(this.getClass(), String.format("Input Message: %s", new String(bytes)));
		JsonObject input = processInput(bytes);

		if (input.getString("type").equals("connection")) {
			JsonObject newClient = input.getJsonObject("client");
			callback.Handle(newClient);
		}
		if (input.getString("type").equals("msg")) {
			System.out.println("Message Arrived: " + input.getString("msg"));
		}
		if (input.getString("type").equals("punch")) {
			sendTask.send(ackMsg.getBytes(), packet.getAddress().getHostAddress(), packet.getPort());
		}
		if (input.getString("type").equals("ACK")) {
			sendTask.setACK(true);
		}
	}

	public JsonObject processInput(byte[] input) {
		ByteArrayInputStream byteInStream = new ByteArrayInputStream(input);
		JsonReader jsonReader = Json.createReader(byteInStream);
		JsonObject ob = jsonReader.readObject();
		PieLogger.info(this.getClass(), String.format("ConnectionText: %s", ob.toString()));
		return ob;
	}
}


text:
app.controller('CompanyReviewCreateController', function(Company, CompanyReview, $scope, $routeParams, $location) {
  $scope.company = Company.get({companyId: $routeParams.companyId});
  $scope.review = new CompanyReview({
    name: '',
    stars: 0,
    title: '',
    description: '',
    company: $routeParams.companyId
  });
  $scope.isSubmitting = false;

  $scope.createReview = function(review) {
    $scope.isSubmitting = true;

    review.$save(function(review) {
      $scope.isSubmitting = false;
      $location.path('/companies/' + review.company);
    });
  };
});

redpajama_set_name: RedPajamaGithub


text:
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.offlinepages;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import com.google.android.gms.gcm.GcmNetworkManager;
import com.google.android.gms.gcm.Task;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.internal.ShadowExtractor;

import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.BaseSwitches;
import org.chromium.base.CommandLine;
import org.chromium.base.SysUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter;
import org.chromium.net.ConnectionType;

/**
 * Unit tests for BackgroundOfflinerTask.
 */
@RunWith(OfflinePageTestRunner.class)
@Config(manifest = Config.NONE,
        application = BaseChromiumApplication.class,
        shadows = { ShadowGcmNetworkManager.class })
public class BackgroundOfflinerTaskTest {
    private static final boolean REQUIRE_POWER = true;
    private static final boolean REQUIRE_UNMETERED = true;
    private static final boolean POWER_CONNECTED = true;
    private static final int MINIMUM_BATTERY_LEVEL = 33;
    private static final String IS_LOW_END_DEVICE_SWITCH =
            "--" + BaseSwitches.ENABLE_LOW_END_DEVICE_MODE;

    @Mock
    private OfflinePageUtils mOfflinePageUtils;

    private Bundle mTaskExtras;
    private long mTestTime;
    private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor;
    private TriggerConditions mTriggerConditions =
            new TriggerConditions(!REQUIRE_POWER, MINIMUM_BATTERY_LEVEL, REQUIRE_UNMETERED);
    private DeviceConditions mDeviceConditions = new DeviceConditions(
            !POWER_CONNECTED, MINIMUM_BATTERY_LEVEL + 5, ConnectionType.CONNECTION_3G);
    private Activity mTestActivity;

    private Context mContext;
    private ShadowGcmNetworkManager mGcmNetworkManager;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
                .thenReturn(mDeviceConditions);

        // Build a bundle with trigger conditions.
        mTaskExtras = new Bundle();
        TaskExtrasPacker.packTimeInBundle(mTaskExtras);
        TaskExtrasPacker.packTriggerConditionsInBundle(mTaskExtras, mTriggerConditions);

        OfflinePageUtils.setInstanceForTesting(mOfflinePageUtils);
        mStubBackgroundSchedulerProcessor = new StubBackgroundSchedulerProcessor();
        RecordHistogram.disableForTests();
        mContext =  RuntimeEnvironment.application;
        mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract(
                GcmNetworkManager.getInstance(mContext));
        mGcmNetworkManager.clear();

        // Run tests as a low-end device.
        CommandLine.init(new String[] {"testcommand", IS_LOW_END_DEVICE_SWITCH});

        // Set up single, stopped Activity.
        ApplicationStatus.destroyForJUnitTests();
        mTestActivity = new Activity();
        ApplicationStatus.onStateChangeForTesting(mTestActivity, ActivityState.CREATED);
        ApplicationStatus.onStateChangeForTesting(mTestActivity, ActivityState.STOPPED);
    }

    @After
    public void tearDown() throws Exception {
        // Clean up static state for subsequent Robolectric tests.
        CommandLine.reset();
        SysUtils.reset();
        ApplicationStatus.destroyForJUnitTests();
    }

    @Test
    @Feature({"OfflinePages"})
    public void testIncomingTask() {
        BackgroundOfflinerTask task =
                new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1000);
        task.processBackgroundRequests(mTaskExtras, mDeviceConditions, waiter);

        // Check with BackgroundSchedulerProcessor that it started processing.
        assertTrue(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
        assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());

        // Call the callback and then waiter should not block.
        mStubBackgroundSchedulerProcessor.callback();
        waiter.startWaiting();
    }

    @Test
    @Feature({"OfflinePages"})
    public void testIncomingTaskNotStarted() {
        mStubBackgroundSchedulerProcessor.setFailToStart(true);
        BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1000);
        task.processBackgroundRequests(mTaskExtras, mDeviceConditions, waiter);

        // Check with BackgroundSchedulerProcessor that it did not start.
        assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());

        // The waiter should not block if startScheduledProcessing returned false.
        waiter.startWaiting();
    }

    @Test
    @Feature({"OfflinePages"})
    public void testStartBackgroundRequests() {
        BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
        assertNull("Nothing scheduled", mGcmNetworkManager.getScheduledTask());
        assertTrue(task.startBackgroundRequests(
                RuntimeEnvironment.application, mTaskExtras, waiter));

        // Check that the backup task was scheduled.
        Task gcmTask = mGcmNetworkManager.getScheduledTask();
        assertNotNull("Backup task scheduled", gcmTask);
        assertEquals(mTriggerConditions,
                TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));

        // Check with BackgroundSchedulerProcessor that startScheduledProcessing got called.
        assertTrue(mStubBackgroundSchedulerProcessor.getDidStartProcessing());
        assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());
    }

    @Test
    @Feature({"OfflinePages"})
    public void testStartBackgroundRequestsForLowBatteryLevel() {
        DeviceConditions deviceConditionsLowBattery = new DeviceConditions(
                !POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
        when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
                .thenReturn(deviceConditionsLowBattery);
        BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
        assertNull("Nothing scheduled", mGcmNetworkManager.getScheduledTask());
        assertFalse(task.startBackgroundRequests(
                RuntimeEnvironment.application, mTaskExtras, waiter));

        // Check that the backup task was scheduled.
        Task gcmTask = mGcmNetworkManager.getScheduledTask();
        assertNotNull("Backup task scheduled", gcmTask);
        assertEquals(mTriggerConditions,
                TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));

        // Check that startScheduledProcessing was NOT called.
        assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());

        // Now verify low battery level but with power connected will start processing.
        DeviceConditions deviceConditionsPowerConnected = new DeviceConditions(
                POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
        when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
                .thenReturn(deviceConditionsPowerConnected);
        BackgroundOfflinerTask task2 =
                new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter2 = new ChromeBackgroundServiceWaiter(1);
        assertTrue(task2.startBackgroundRequests(
                RuntimeEnvironment.application, mTaskExtras, waiter2));
    }

    @Test
    @Feature({"OfflinePages"})
    public void testStartBackgroundRequestsForRunningActivityOnLowEndDevice() {
        BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
        assertNull("Nothing scheduled", mGcmNetworkManager.getScheduledTask());

        // Transition the test Activity to a running state.
        ApplicationStatus.onStateChangeForTesting(mTestActivity, ActivityState.STARTED);

        assertFalse(task.startBackgroundRequests(
                RuntimeEnvironment.application, mTaskExtras, waiter));

        // Check that the backup task was scheduled.
        Task gcmTask = mGcmNetworkManager.getScheduledTask();
        assertNotNull("Backup task scheduled", gcmTask);
        assertEquals(mTriggerConditions,
                TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));

        // Check that startScheduledProcessing was NOT called.
        assertFalse(mStubBackgroundSchedulerProcessor.getDidStartProcessing());

        // Now verify will start processing when Activity is stopped.
        ApplicationStatus.onStateChangeForTesting(mTestActivity, ActivityState.STOPPED);
        BackgroundOfflinerTask task2 =
                new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
        ChromeBackgroundServiceWaiter waiter2 = new ChromeBackgroundServiceWaiter(1);
        assertTrue(task2.startBackgroundRequests(
                RuntimeEnvironment.application, mTaskExtras, waiter2));
    }
}


text:
package ch.unibas.dmi.dbis.cs108pet.session;

import ch.unibas.dmi.dbis.cs108pet.ui.MainScene;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * A class that holds various information about a cs108pet session.
 *
 * @author loris.sauter
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class SessionStorage {

  /**
   * The date of when the session was created / closed
   */
  private Date date;
  /**
   * App version -- to prevent version mismatch
   */
  private String version;
  /**
   * catalogue / course
   */
  private String lastUsedDir;
  private boolean enabled = true;

  private MainScene.Mode lastOpenMode;

  private List<String> lastOpenGroups;

  private String lastUsedTemplatingConfig;
  private String lastUsedCatalogueExport;

  private UUID lastActiveProgressSummary;

  public boolean isEnabled() {
    return enabled;
  }

  public void setEnabled(boolean enabled) {
    this.enabled = enabled;
  }

  public MainScene.Mode getLastOpenMode() {
    return lastOpenMode;
  }

  public void setLastOpenMode(MainScene.Mode lastOpenMode) {
    this.lastOpenMode = lastOpenMode;
  }

  public List<String> getLastOpenGroups() {
    return lastOpenGroups;
  }

  public void setLastOpenGroups(List<String> lastOpenGroups) {
    this.lastOpenGroups = lastOpenGroups;
  }

  public UUID getLastActiveProgressSummary() {
    return lastActiveProgressSummary;
  }

  public void setLastActiveProgressSummary(UUID lastActiveProgressSummary) {
    this.lastActiveProgressSummary = lastActiveProgressSummary;
  }

  private HashMap<String, String> data;

  public Date getDate() {
    return date;
  }

  public void setDate(Date date) {
    this.date = date;
  }

  public String getVersion() {
    return version;
  }

  public void setVersion(String version) {
    this.version = version;
  }

  public String getLastUsedDir() {
    return lastUsedDir;
  }

  public void setLastUsedDir(String lastUsedDir) {
    this.lastUsedDir = lastUsedDir;
  }

  public boolean isValidDir(String lastUsedDir) {
    return Files.isDirectory(Path.of(lastUsedDir));
  }

  public SessionStorage() {
    data = new HashMap<>();
  }

  public int dataSize() {
    return data.size();
  }

  @JsonIgnore
  public boolean isDataEmpty() {
    return data.isEmpty();
  }

  public String getData(String key) {
    return data.get(key);
  }

  public boolean containsDataKey(String key) {
    return data.containsKey(key);
  }

  public String putData(String key, String value) {
    return data.put(key, value);
  }

  public void putAllData(Map<? extends String, ? extends String> m) {
    data.putAll(m);
  }

  public String removeData(String key) {
    return data.remove(key);
  }

  public void clear() {
    data.clear();
  }

  public boolean containsValue(String value) {
    return data.containsValue(value);
  }

  public Set<String> keySetData() {
    return data.keySet();
  }

  public Collection<String> dataValues() {
    return data.values();
  }

  public Set<Map.Entry<String, String>> entrySetData() {
    return data.entrySet();
  }

  public String getDataOrDefault(String key, String defaultValue) {
    return data.getOrDefault(key, defaultValue);
  }

  public String putDataIfAbsent(String key, String value) {
    return data.putIfAbsent(key, value);
  }

  public boolean removeData(String key, String value) {
    return data.remove(key, value);
  }

  public boolean replaceData(String key, String oldValue, String newValue) {
    return data.replace(key, oldValue, newValue);
  }

  public String replaceData(String key, String value) {
    return data.replace(key, value);
  }

  public String computeDataIfAbsent(String key, Function<? super String, ? extends String> mappingFunction) {
    return data.computeIfAbsent(key, mappingFunction);
  }

  public String computeDataIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
    return data.computeIfPresent(key, remappingFunction);
  }

  public String computeData(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
    return data.compute(key, remappingFunction);
  }

  public String mergeData(String key, String value, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
    return data.merge(key, value, remappingFunction);
  }

  public void forEachData(BiConsumer<? super String, ? super String> action) {
    data.forEach(action);
  }

  public void replaceAllData(BiFunction<? super String, ? super String, ? extends String> function) {
    data.replaceAll(function);
  }

    public String getLastUsedTemplatingConfig() {
        return lastUsedTemplatingConfig;
    }

    public void setLastUsedTemplatingConfig(String lastUsedTemplatingConfig) {
        this.lastUsedTemplatingConfig = lastUsedTemplatingConfig;
    }

    public String getLastUsedCatalogueExport() {
        return lastUsedCatalogueExport;
    }

    public void setLastUsedCatalogueExport(String lastUsedCatalogueExport) {
        this.lastUsedCatalogueExport = lastUsedCatalogueExport;
    }

    @Override
    public String toString() {
        return "SessionStorage{" +
            "date=" + date +
            ", version='" + version + '\'' +
            ", lastUsedDir='" + lastUsedDir + '\'' +
            ", enabled=" + enabled +
            ", lastOpenMode=" + lastOpenMode +
            ", lastOpenGroups=" + lastOpenGroups +
            ", lastUsedTemplatingConfig='" + lastUsedTemplatingConfig + '\'' +
            ", lastUsedCatalogueExport='" + lastUsedCatalogueExport + '\'' +
            ", lastActiveProgressSummary=" + lastActiveProgressSummary +
            ", data=" + data +
            '}';
    }
}


text:
<!doctype html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Foundation for Sites Testing</title>
    <link href="../assets/css/foundation.css" rel="stylesheet" />

Dropdown: Overflow Handling

These dropdowns test various overflow situations.

Right and Left Overflow

Bottom Right Default Behavior (no overflow)

          <button class="button" type="button" data-toggle="example-dropdown-bottom-right">Toggle Dropdown</button>

This dropdown should be on the bottom aligned with the left, all inside the container

Bottom Left Default Behavior (no overflow)

          <button class="button float-right" type="button" data-toggle="example-dropdown-bottom-left">Toggle Dropdown</button>

This dropdown should be on the bottom aligned with the right, all inside the container

Bottom Right Overflow Allowed

          <button class="button" type="button" data-toggle="example-dropdown-bottom-right-overflow">Toggle Dropdown</button>

This dropdown should be on the bottom aligned with the right, breaking out of the container

Bottom Left Overflow Allowed

          <button class="button float-right" type="button" data-toggle="example-dropdown-bottom-left-overflow">Toggle Dropdown</button>

This dropdown should be on the bottom aligned with the left, breaking out of the container

Bottom and Top Overflow

Right Bottom Default Behavior (no overflow)

          <button class="button" type="button" data-toggle="example-dropdown-right-bottom">Toggle Dropdown</button>

This dropdown should be on the right aligned with the top of the button after realigning

Left Bottom Default Behavior (no overflow)

          <button class="button float-right" type="button" data-toggle="example-dropdown-left-bottom">Toggle Dropdown</button>

This dropdown should be on the left aligned with the top of the button after realigning

Right Top Default Behavior (no overflow)

          <button class="button" type="button" data-toggle="example-dropdown-right-top">Toggle Dropdown</button>

This dropdown should be on the right aligned with the bottom of the button after realigning

Left Top Default Behavior (no overflow)

          <button class="button float-right" type="button" data-toggle="example-dropdown-left-top">Toggle Dropdown</button>

This dropdown should be on the left aligned with the bottom of the button after realigning


text:
module FHIR
    class Supply

        include Mongoid::Document
        include Mongoid::History::Trackable
        include FHIR::Element
        include FHIR::Resource
        include FHIR::Formats::Utilities
        include FHIR::Serializer::Utilities
        extend FHIR::Deserializer::Supply

        SEARCH_PARAMS = [
            'patient',
            '_id',
            'status',
            'dispenseid',
            '_language',
            'identifier',
            'supplier',
            'kind',
            'dispensestatus'
            ]

        VALID_CODES = {
            status: [ "requested", "dispensed", "received", "failed", "cancelled" ]
        }

        # This is an ugly hack to deal with embedded structures in the spec dispense
        class SupplyDispenseComponent
        include Mongoid::Document
        include FHIR::Element
        include FHIR::Formats::Utilities

            VALID_CODES = {
                status: [ "in progress", "dispensed", "abandoned" ]
            }

            embeds_one :identifier, class_name:'FHIR::Identifier'
            field :status, type: String
            validates :status, :inclusion => { in: VALID_CODES[:status], :allow_nil => true }
            embeds_one :fhirType, class_name:'FHIR::CodeableConcept'
            embeds_one :quantity, class_name:'FHIR::Quantity'
            embeds_one :suppliedItem, class_name:'FHIR::ResourceReference'
            embeds_one :supplier, class_name:'FHIR::ResourceReference'
            embeds_one :whenPrepared, class_name:'FHIR::Period'
            embeds_one :whenHandedOver, class_name:'FHIR::Period'
            embeds_one :destination, class_name:'FHIR::ResourceReference'
            embeds_many :receiver, class_name:'FHIR::ResourceReference'
        end

        embeds_one :kind, class_name:'FHIR::CodeableConcept'
        embeds_one :identifier, class_name:'FHIR::Identifier'
        field :status, type: String
        validates :status, :inclusion => { in: VALID_CODES[:status], :allow_nil => true }
        embeds_one :orderedItem, class_name:'FHIR::ResourceReference'
        embeds_one :patient, class_name:'FHIR::ResourceReference'
        embeds_many :dispense, class_name:'FHIR::Supply::SupplyDispenseComponent'
        track_history
    end
end


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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#FFFFFF">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lvSolutions"
        android:layout_gravity="right"
        android:background="#FFFFFF"/>
    <View
        android:layout_width="fill_parent"
        android:layout_height="0.2dp"
        android:visibility="visible"
        android:background="@android:color/darker_gray"/>
</LinearLayout>


text:
#include <iostream>  // NOLINT
using std::cout;
using std::endl;
#include "abstract_factory/ny_pizza_store.h"
#include "abstract_factory/chicago_pizza_store.h"
#include "abstract_factory/pizza.h"
#include "abstract_factory/pizza_store.h"
using namespace abstract_factory;  // NOLINT

int main(int argc, char *argv[]) {
  PizzaStore *nyStore = new NYPizzaStore();
  PizzaStore *chicagoStore = new ChicagoPizzaStore();

  Pizza *pizza = nyStore->orderPizza("cheese");
  cout << "Ethan ordered a " + pizza->toString() << endl;
  delete pizza;
  pizza = chicagoStore->orderPizza("cheese");
  cout << "Joel ordered a " + pizza->toString() << endl;
  delete pizza;

  pizza = nyStore->orderPizza("clam");
  cout << "Ethan ordered a " + pizza->toString() << endl;
  delete pizza;
  pizza = chicagoStore->orderPizza("clam");
  cout << "Joel ordered a " + pizza->toString() << endl;
  delete pizza;

  delete nyStore;
  delete chicagoStore;

  return 0;
}


text:
using System;
using System.Collections.Generic;

namespace _01._Reverse_Numbers_with_a_Stack
{
    class ReverseNums
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var numbersStack = new Stack<int>();

            foreach (var number in numbers)
            {
                numbersStack.Push(int.Parse(number));
            }

            while (numbersStack.Count > 0)
            {
                Console.Write($"{numbersStack.Pop()} ");
            }
            Console.WriteLine();
        }
    }
}


text:
from django.contrib import messages
from django.template.defaultfilters import pluralize
from django.urls import reverse_lazy

from conf_site.core.views import CsvImportView, SuperuserOnlyView
from conf_site.reviews.tasks import import_reviewer_csv

class ReviewerCsvImportView(SuperuserOnlyView, CsvImportView):
    raise_exception = True
    success_url = reverse_lazy("reviewer_import")
    template_name = "reviews/reviewer_import.html"

    def process(self, filename, user_id):
        result = import_reviewer_csv(filename)
        if result:
            messages.success(
                self.request,
                "{} user{} created. {} existing user{} found.".format(
                    result[0],
                    pluralize(result[0]),
                    result[1],
                    pluralize(result[1]),
                ),
            )
        else:
            messages.error(
                self.request, "Unable to successfully import CSV file."
            )


text:
if [ -z "$1" ] || [ -z "$2" ]; then
  >&2 echo "Usage: $0 keypair_name stack_name"
  exit 1
fi

# from params
keypair_name=$1
stack_name=$2

# dynamic
external_ip=$(curl --silent checkip.amazonaws.com)

# hardcoded, change if required
region=us-east-2
instance_type=m4.large

aws cloudformation create-stack --stack-name $stack_name \
  --region $region \
  --capabilities CAPABILITY_IAM \
  --template-body file://ec2-efs.template.yml \
  --parameters \
    ParameterKey=KeyPairName,ParameterValue=$keypair_name \
    ParameterKey=ExternalIP,ParameterValue=$external_ip \
    ParameterKey=InstanceType,ParameterValue=$instance_type

echo "Waiting for AWS CloudFormation to create the stack."
sleep 20

aws cloudformation wait stack-create-complete --region $region \
  --stack-name $stack_name

aws cloudformation describe-stacks --region $region --stack-name $stack_name


text:
#ifndef _SHELL_H
#define _SHELL_H

#include "common.h"

#define SHELL_INPUT_BUFFER_SIZE 256
#define SHELL_QUERY_STRING "stoomboot> "
#define SHELL_MAX_ARG_COUNT 16

/**
 * \brief Prompt the user for input.
 *
 * \param query a string printed before user input
 * \param buffer where the input is stored
 * \param length the maximum input length
 */
void prompt(const char *query, char *buffer, size_t length);

/**
 * \brief Starts the shell.
 */
void shell();

#endif /* _SHELL_H */


text:
package com.frist008.demo.activity.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Toast;

import com.frist008.demo.R;
import com.frist008.demo.activity.array.ExampleArrayActivity;
import com.frist008.demo.activity.array.ExampleMultiArrayActivity;
import com.frist008.demo.activity.cursor.ExampleCursorActivity;
import com.frist008.demo.activity.cursor.ExampleMultiCursorActivity;
import com.frist008.demo.activity.recycler.cursor.ExampleMultiRecyclerCursorActivity;
import com.frist008.demo.activity.recycler.cursor.ExampleRecyclerCursorActivity;
import com.frist008.demo.activity.recycler.list.ExampleMultiRecyclerActivity;
import com.frist008.demo.activity.recycler.list.ExampleRecyclerActivity;
import com.frist008.demo.activity.sticky.cursor.ExampleMultiStickyCursorActivity;
import com.frist008.demo.activity.sticky.cursor.ExampleStickyCursorActivity;
import com.frist008.demo.database.Provider;
import com.frist008.demo.io.file.MyFile;
import com.frist008.demo.io.pref.MyPref;

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

public class MainActivity extends FragmentActivity implements View.OnClickListener {

	private static final Map<Integer, Class<? extends Activity>> CLASS_ACTIVITY_MAP
			= new HashMap<>();

	static {
		CLASS_ACTIVITY_MAP.put(R.id.arrayButton,
		                       ExampleArrayActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.multiArrayButton,
		                       ExampleMultiArrayActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.stickyCursorButton,
		                       ExampleStickyCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.multiStickyCursorButton,
		                       ExampleMultiStickyCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.cursorButton,
		                       ExampleCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.multiCursorButton,
		                       ExampleMultiCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.recyclerCursorButton,
		                       ExampleRecyclerCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.multiRecyclerCursorButton,
		                       ExampleMultiRecyclerCursorActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.recyclerButton,
		                       ExampleRecyclerActivity.class);
		CLASS_ACTIVITY_MAP.put(R.id.multiRecyclerButton,
		                       ExampleMultiRecyclerActivity.class);
	}

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

		MyFile file = new MyFile(this);
		MyPref pref1 = new MyPref(file);
		MyPref pref2 = new MyPref(this);

		pref1.save("111");
		pref2.save("222");

		Toast.makeText(this, pref1.load() + pref2.load(), Toast.LENGTH_LONG).show();

		for (Integer integer : CLASS_ACTIVITY_MAP.keySet()) {
			findViewById(integer).setOnClickListener(this);
		}
	}

	@Override
	protected void onStart() {
		super.onStart();
		Provider.clearAllTable();
	}

	@Override
	public void onClick(View view) {
		startActivity(new Intent(this, CLASS_ACTIVITY_MAP.get(view.getId())));
	}
}


text:
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Z.Core.Test
{
    [TestClass]
    public class System_Decimal_ToMoney
    {
        [TestMethod]
        public void ToMoney()
        {
            // Type
            decimal @this1 = 2.311M;
            decimal @this2 = 2.3191M;

            // Exemples
            decimal result1 = @this1.ToMoney(); // return 2.31;
            decimal result2 = @this2.ToMoney(); // return 2.32;

            // Unit Test
            Assert.AreEqual(2.31M, result1);
            Assert.AreEqual(2.32M, result2);
        }
    }
}


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE124_Buffer_Underwrite__CWE839_fgets_61a.c
Label Definition File: CWE124_Buffer_Underwrite__CWE839.label.xml
Template File: sources-sinks-61a.tmpl.c
*/
/*
 * @description
 * CWE: 124 Buffer Underwrite
 * BadSource: fgets Read data from the console using fgets()
 * GoodSource: Non-negative but less than 10
 * Sinks:
 *    GoodSink: Ensure the array index is valid
 *    BadSink : Improperly check the array index by not checking the lower bound
 * Flow Variant: 61 Data flow: data returned from one function to another in different source files
 *
 * */

#include "std_testcase.h"

#define CHAR_ARRAY_SIZE (3 * sizeof(data) + 2)

#ifndef OMITBAD

/* bad function declaration */
int CWE124_Buffer_Underwrite__CWE839_fgets_61b_badSource(int data);

void CWE124_Buffer_Underwrite__CWE839_fgets_61_bad()
{
    int data;
    /* Initialize data */
    data = -1;
    data = CWE124_Buffer_Underwrite__CWE839_fgets_61b_badSource(data);
    {
        int i;
        int buffer[10] = { 0 };
        /* POTENTIAL FLAW: Attempt to access a negative index of the array
        * This code does not check to see if the array index is negative */
        if (data < 10)
        {
            buffer[data] = 1;
            /* Print the array values */
            for(i = 0; i < 10; i++)
            {
                printIntLine(buffer[i]);
            }
        }
        else
        {
            printLine("ERROR: Array index is negative.");
        }
    }
}

#endif /* OMITBAD */

#ifndef OMITGOOD

/* goodG2B uses the GoodSource with the BadSink */
int CWE124_Buffer_Underwrite__CWE839_fgets_61b_goodG2BSource(int data);

static void goodG2B()
{
    int data;
    /* Initialize data */
    data = -1;
    data = CWE124_Buffer_Underwrite__CWE839_fgets_61b_goodG2BSource(data);
    {
        int i;
        int buffer[10] = { 0 };
        /* POTENTIAL FLAW: Attempt to access a negative index of the array
        * This code does not check to see if the array index is negative */
        if (data < 10)
        {
            buffer[data] = 1;
            /* Print the array values */
            for(i = 0; i < 10; i++)
            {
                printIntLine(buffer[i]);
            }
        }
        else
        {
            printLine("ERROR: Array index is negative.");
        }
    }
}

/* goodB2G uses the BadSource with the GoodSink */
int CWE124_Buffer_Underwrite__CWE839_fgets_61b_goodB2GSource(int data);

static void goodB2G()
{
    int data;
    /* Initialize data */
    data = -1;
    data = CWE124_Buffer_Underwrite__CWE839_fgets_61b_goodB2GSource(data);
    {
        int i;
        int buffer[10] = { 0 };
        /* FIX: Properly validate the array index and prevent a buffer underwrite */
        if (data >= 0 && data < (10))
        {
            buffer[data] = 1;
            /* Print the array values */
            for(i = 0; i < 10; i++)
            {
                printIntLine(buffer[i]);
            }
        }
        else
        {
            printLine("ERROR: Array index is out-of-bounds");
        }
    }
}

void CWE124_Buffer_Underwrite__CWE839_fgets_61_good()
{
    goodG2B();
    goodB2G();
}

#endif /* OMITGOOD */

/* Below is the main(). It is only used when building this testcase on
   its own for testing or for building a binary to use in testing binary
   analysis tools. It is not used when compiling all the testcases as one
   application, which is how source code analysis tools are tested. */

#ifdef INCLUDEMAIN

int main(int argc, char * argv[])
{
    /* seed randomness */
    srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
    printLine("Calling good()...");
    CWE124_Buffer_Underwrite__CWE839_fgets_61_good();
    printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
    printLine("Calling bad()...");
    CWE124_Buffer_Underwrite__CWE839_fgets_61_bad();
    printLine("Finished bad()");
#endif /* OMITBAD */
    return 0;
}

#endif


text:
<dom-module id="admin-button">
	<template>
		<style>
			:host {
				display: block;
			}
		</style>
		<paper-icon-button id="adminBtn" icon="settings" hidden on-tap="redirectToAdmin"></paper-icon-button>
		<paper-tooltip
		  for="adminBtn"
		  position="left"
		  offset="14">
		  Administration panel
		</paper-tooltip>
	</template>
	<script>
		Polymer({
			is: 'admin-button',
			properties: {
				role: String,
				storage: {
					observer: 'storageChanged'
				},
				baseLocation: {
				}
			},
			storageChanged: function (storage) {
				this._checkRight();
			},
			_checkRight: function () {
				var adminButton = this;
				FB.api(
				"/app/roles",
				{access_token: adminButton.storage.appToken},
				function (response) {
					if (response && !response.error) {
						for (var i = 0; i < response.data.length; i++) {
							if (response.data[i].role === adminButton.role) {
								adminButton.$.adminBtn.hidden = false;
							}
						};
					}
				});
			},
			redirectToAdmin: function () {
				console.log([this.baseLocation, 'nimda'].join('/'));
				window.location.href = "/nimda";
			}
		});
	</script>
</dom-module>


text:
namespace MassTransit.Transports.Fabric
{
    using System.Threading;

    public class Counter :
        Metric
    {
        long _count;

        public void Add()
        {
            Interlocked.Increment(ref _count);
        }
    }
}


text:
namespace thewizardplusplus {
namespace anna {
namespace graphics {

class World {
public:
	World(void);
	~World(void);
	Camera* getCamera(void);
	void setCamera(Camera* camera);
	size_t getNumberOfObjects(void) const;
	Object* getObject(size_t number) const;
	void addObject(Object* object);
	void addAnimateObject(AnimateObject* object);
	void removeObject(Object* object);
	size_t getNumberOfOpaqueMeshes(void) const;
	Mesh* getOpaqueMesh(size_t number) const;
	size_t getNumberOfTransparentMeshes(void) const;
	Mesh* getTransparentMesh(size_t number) const;
	void sortTransparentMeshes(void);
	void update(float delta_time_in_ms);

private:
	typedef std::vector<Object*>        ObjectVector;
	typedef std::vector<AnimateObject*> AnimateObjectVector;
	typedef std::vector<Mesh*>          MeshVector;

	Camera*             camera;
	ObjectVector        objects;
	AnimateObjectVector animate_objects;
	MeshVector          opaque_meshes;
	MeshVector          transparent_meshes;
};

}
}
}
#endif


text:
package uk.ac.ebi.biosamples;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageUtils {

  @Autowired private RabbitTemplate rabbitTemplate;

  private Logger log = LoggerFactory.getLogger(this.getClass());

  public long getQueueCount(String queue) {
    long count = rabbitTemplate.execute(channel -> channel.messageCount(queue));
    log.trace("Number of messages in " + queue + " = " + count);
    return count;
  }
}


text:
namespace GoTweet
{
    partial class GoTweet
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            ngio.dispose();
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.panel1 = new System.Windows.Forms.Panel();
            this.nameLabel = new System.Windows.Forms.Label();
            this.panel3 = new System.Windows.Forms.Panel();
            this.unit = new System.Windows.Forms.Label();
            this.reading = new System.Windows.Forms.Label();
            this.panel2 = new System.Windows.Forms.Panel();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.preToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.readingsTimer = new System.Windows.Forms.Timer(this.components);
            this.startDelay = new System.Windows.Forms.Timer(this.components);
            this.tweetTimer = new System.Windows.Forms.Timer(this.components);
            this.panel1.SuspendLayout();
            this.panel3.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            //
            // panel1
            //
            this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(225)))), ((int)(((byte)(234)))));
            this.panel1.Controls.Add(this.nameLabel);
            this.panel1.Controls.Add(this.panel3);
            this.panel1.Controls.Add(this.panel2);
            this.panel1.Controls.Add(this.menuStrip1);
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(547, 366);
            this.panel1.TabIndex = 0;
            //
            // nameLabel
            //
            this.nameLabel.AutoSize = true;
            this.nameLabel.Font = new System.Drawing.Font("Nina", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nameLabel.Location = new System.Drawing.Point(225, 67);
            this.nameLabel.Name = "nameLabel";
            this.nameLabel.Size = new System.Drawing.Size(59, 23);
            this.nameLabel.TabIndex = 2;
            this.nameLabel.Text = "Name";
            //
            // panel3
            //
            this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(218)))), ((int)(((byte)(224)))));
            this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.panel3.Controls.Add(this.unit);
            this.panel3.Controls.Add(this.reading);
            this.panel3.Location = new System.Drawing.Point(24, 103);
            this.panel3.Name = "panel3";
            this.panel3.Size = new System.Drawing.Size(496, 166);
            this.panel3.TabIndex = 1;
            //
            // unit
            //
            this.unit.AutoSize = true;
            this.unit.Font = new System.Drawing.Font("Nina", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.unit.Location = new System.Drawing.Point(197, 119);
            this.unit.Name = "unit";
            this.unit.Size = new System.Drawing.Size(74, 33);
            this.unit.TabIndex = 1;
            this.unit.Text = "units";
            this.unit.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            //
            // reading
            //
            this.reading.AutoSize = true;
            this.reading.Font = new System.Drawing.Font("Nina", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.reading.Location = new System.Drawing.Point(113, 0);
            this.reading.Name = "reading";
            this.reading.Size = new System.Drawing.Size(263, 77);
            this.reading.TabIndex = 0;
            this.reading.Text = "Reading";
            this.reading.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            //
            // panel2
            //
            this.panel2.BackColor = System.Drawing.Color.Black;
            this.panel2.Location = new System.Drawing.Point(0, 291);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(547, 75);
            this.panel2.TabIndex = 0;
            //
            // menuStrip1
            //
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(547, 24);
            this.menuStrip1.TabIndex = 3;
            this.menuStrip1.Text = "menuStrip1";
            //
            // fileToolStripMenuItem
            //
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.preToolStripMenuItem,
            this.exitToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.fileToolStripMenuItem.Text = "File";
            //
            // preToolStripMenuItem
            //
            this.preToolStripMenuItem.Name = "preToolStripMenuItem";
            this.preToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
            this.preToolStripMenuItem.Text = "Preferences...";
            this.preToolStripMenuItem.Click += new System.EventHandler(this.openPrefrences);
            //
            // exitToolStripMenuItem
            //
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
            this.exitToolStripMenuItem.Text = "Exit";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.closeApplication);
            //
            // readingsTimer
            //
            this.readingsTimer.Interval = 1000;
            this.readingsTimer.Tick += new System.EventHandler(this.updateReadings);
            //
            // startDelay
            //
            this.startDelay.Enabled = true;
            this.startDelay.Interval = 500;
            this.startDelay.Tick += new System.EventHandler(this.updateReadings);
            //
            // tweetTimer
            //
            this.tweetTimer.Interval = 60000;
            this.tweetTimer.Tick += new System.EventHandler(this.tweetTime);
            //
            // GoTweet
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(225)))), ((int)(((byte)(234)))));
            this.ClientSize = new System.Drawing.Size(547, 366);
            this.Controls.Add(this.panel1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MainMenuStrip = this.menuStrip1;
            this.MaximizeBox = false;
            this.Name = "GoTweet";
            this.ShowIcon = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "GoTweet";
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.panel3.ResumeLayout(false);
            this.panel3.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Panel panel3;
        private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.Label reading;
        private System.Windows.Forms.Timer readingsTimer;
        private System.Windows.Forms.Label unit;
        private System.Windows.Forms.Label nameLabel;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem preToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
        private System.Windows.Forms.Timer startDelay;
        private System.Windows.Forms.Timer tweetTimer;

    }
}


text:
:man_page: mongoc_apm_command_started_get_service_id

mongoc_apm_command_started_get_service_id()
===========================================

Synopsis
--------

.. code-block:: c

  const bson_oid_t *
  mongoc_apm_command_started_get_service_id (
     const mongoc_apm_command_started_t *event);

Returns this event's service ID, which identifies the MongoDB service behind a
load balancer, or ``NULL`` if not connected to a load balanced cluster.

Parameters
----------

* ``event``: A :symbol:`mongoc_apm_command_started_t`.

Returns
-------

A :symbol:`bson_oid_t` that should not be modified or freed or ``NULL``.


text:
env    = PATH=./env/bin:${PATH}
image  = biobox_testing/abyss

ssh: .image env
	@$(env) biobox login short_read_assembler $(image)

test: .image env
	@$(env) biobox verify short_read_assembler $(image) --verbose
	@$(env) biobox verify short_read_assembler $(image) --verbose --task=adaptive

build: .image

.image: $(shell find image -type f) Dockerfile
	@docker build --tag $(image) .
	@touch $@

env:
	@virtualenv -p python3 $@
	@$@/bin/pip install biobox_cli


text: document.getElementById("impress").innerHTML = sessionStorage.preview;


text:
package org.apache.pinot.tools.admin.command;

import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pinot.controller.recommender.io.metadata.SchemaWithMetaData;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.utils.DataSizeUtils;
import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.tools.Command;
import org.apache.pinot.controller.recommender.realtime.provisioning.MemoryEstimator;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Given a set of input params, output a table of num hosts to num hours and the memory required per host
 *
 */
public class RealtimeProvisioningHelperCommand extends AbstractBaseAdminCommand implements Command {

  private static final Logger LOGGER = LoggerFactory.getLogger(RealtimeProvisioningHelperCommand.class);

  private static final int MEMORY_STR_LEN = 16;
  private static final String COMMA_SEPARATOR = ",";
  private static final int DEFAULT_RETENTION_FOR_HOURLY_PUSH = 24;
  private static final int DEFAULT_RETENTION_FOR_DAILY_PUSH = 72;
  private static final int DEFAULT_RETENTION_FOR_WEEKLY_PUSH = 24*7 + 72;
  private static final int DEFAULT_RETENTION_FOR_MONTHLY_PUSH = 24*31 + 72;
  private static final int DEFAULT_NUMBER_OF_ROWS = 10_000;

  @Option(name = "-tableConfigFile", required = true, metaVar = "<String>")
  private String _tableConfigFile;

  @Option(name = "-numPartitions", required = true, metaVar = "<int>", usage = "number of stream partitions for the table")
  private int _numPartitions;

  @Option(name = "-retentionHours", metaVar = "<int>", usage = "Number of recent hours queried most often"
      + "\n\t(-pushFrequency is ignored)")
  private int _retentionHours;

  @Option(name = "-pushFrequency", metaVar = "<String>", usage =
      "Frequency with which offline table pushes happen, if this is a hybrid table"
          + "\n\t(hourly,daily,weekly,monthly). Do not specify if realtime-only table")
  private String _pushFrequency;

  @Option(name = "-numHosts", metaVar = "<String>", usage = "number of hosts as comma separated values (default 2,4,6,8,10,12,14,16)")
  private String _numHosts = "2,4,6,8,10,12,14,16";

  @Option(name = "-numHours", metaVar = "<String>", usage = "number of hours to consume as comma separated values (default 2,3,4,5,6,7,8,9,10,11,12)")
  private String _numHours = "2,3,4,5,6,7,8,9,10,11,12";

  @Option(name = "-sampleCompletedSegmentDir", required = false, metaVar = "<String>", usage = "Consume from the topic for n hours and provide the path of the segment dir after it completes")
  private String _sampleCompletedSegmentDir;

  @Option(name = "-schemaWithMetadataFile", required = false, metaVar = "<String>", usage = "Schema file with extra information on each column describing characteristics of data")
  private String _schemaWithMetadataFile;

  @Option(name = "-numRows", required = false, metaVar = "<String>", usage = "Number of rows to be generated based on schema with metadata file")
  private int _numRows;

  @Option(name = "-ingestionRate", required = true, metaVar = "<String>", usage = "Avg number of messages per second ingested on any one stream partition (assumed all partitions are uniform)")
  private int _ingestionRate;

  @Option(name = "-maxUsableHostMemory", required = false, metaVar = "<String>", usage = "Maximum memory per host that can be used for pinot data (e.g. 250G, 100M). Default 48g")
  private String _maxUsableHostMemory = "48G";

  @Option(name = "-help", help = true, aliases = {"-h", "--h", "--help"})
  private boolean _help = false;

  public RealtimeProvisioningHelperCommand setTableConfigFile(String tableConfigFile) {
    _tableConfigFile = tableConfigFile;
    return this;
  }

  public RealtimeProvisioningHelperCommand setNumPartitions(int numPartitions) {
    _numPartitions = numPartitions;
    return this;
  }

  public RealtimeProvisioningHelperCommand setPushFrequency(String pushFrequency) {
    _pushFrequency = pushFrequency;
    return this;
  }

  public RealtimeProvisioningHelperCommand setRetentionHours(int retentionHours) {
    _retentionHours = retentionHours;
    return this;
  }

  public RealtimeProvisioningHelperCommand setNumHosts(String numHosts) {
    _numHosts = numHosts;
    return this;
  }

  public RealtimeProvisioningHelperCommand setMaxUsableHostMemory(String maxUsableHostMemory) {
    _maxUsableHostMemory = maxUsableHostMemory;
    return this;
  }

  public RealtimeProvisioningHelperCommand setNumHours(String numHours) {
    _numHours = numHours;
    return this;
  }

  public RealtimeProvisioningHelperCommand setSampleCompletedSegmentDir(String sampleCompletedSegmentDir) {
    _sampleCompletedSegmentDir = sampleCompletedSegmentDir;
    return this;
  }

  public RealtimeProvisioningHelperCommand setIngestionRate(int ingestionRate) {
    _ingestionRate = ingestionRate;
    return this;
  }

  public RealtimeProvisioningHelperCommand setNumRows(int numRows) {
    _numRows = numRows;
    return this;
  }

  @Override
  public String toString() {
    String segmentStr = _sampleCompletedSegmentDir != null
        ? " -sampleCompletedSegmentDir " + _sampleCompletedSegmentDir
        : " -schemaWithMetadataFile " + _schemaWithMetadataFile + " -numRows " + _numRows;
    return "RealtimeProvisioningHelper -tableConfigFile " + _tableConfigFile + " -numPartitions " + _numPartitions
        + " -pushFrequency " + _pushFrequency + " -numHosts " + _numHosts + " -numHours " + _numHours + segmentStr
        + " -ingestionRate " + _ingestionRate + " -maxUsableHostMemory " + _maxUsableHostMemory + " -retentionHours "
        + _retentionHours;
  }

  @Override
  public final String getName() {
    return "RealtimeProvisioningHelperCommand";
  }

  @Override
  public String description() {
    return
        "Given the table config, partitions, retention and a sample completed segment for a realtime table to be setup, "
            + "this tool will provide memory used by each host and an optimal segment size for various combinations of hours to consume and hosts. "
            + "Instead of a completed segment, if schema with characteristics of data is provided, a segment will be generated and used for memory estimation.";
  }

  @Override
  public boolean getHelp() {
    return _help;
  }

  @Override
  public void printExamples() {
    StringBuilder builder = new StringBuilder();
    builder.append("\n\nThis command allows you to estimate the capacity needed for provisioning realtime hosts")
        .append("It assumes that there is no upper limit to the amount of memory you can mmap")
        .append("\nIf you have a hybrid table, then consult the push frequency setting in your offline table specify it in the -pushFrequency argument")
        .append("\nIf you have a realtime-only table, then the default behavior is to assume that your queries need all data in memory all the time")
        .append("\nHowever, if most of your queries are going to be for (say) the last 96 hours, then you can specify that in -retentionHours")
        .append("\nDoing so will let this program assume that you are willing to take a page hit when querying older data")
        .append("\nand optimize memory and number of hosts accordingly.")
        .append("\n See https://docs.pinot.apache.org/operators/operating-pinot/tuning/realtime for details");
        ;
    System.out.println(builder.toString());
  }

  @Override
  public boolean execute()
      throws IOException {

    boolean segmentProvided = _sampleCompletedSegmentDir != null;
    boolean characteristicsProvided = _schemaWithMetadataFile != null;
    Preconditions.checkState(segmentProvided ^ characteristicsProvided, "Either completed segment should be provided or schema with characteristics file!");

    LOGGER.info("Executing command: {}", toString());

    TableConfig tableConfig;
    try (FileInputStream fis = new FileInputStream(new File(_tableConfigFile))) {
      String tableConfigString = IOUtils.toString(fis);
      tableConfig = JsonUtils.stringToObject(tableConfigString, TableConfig.class);
    } catch (IOException e) {
      throw new RuntimeException("Exception in reading table config from file " + _tableConfigFile, e);
    }

    StringBuilder note = new StringBuilder();
    note.append("\nNote:\n");
    int numReplicas = tableConfig.getValidationConfig().getReplicasPerPartitionNumber();
    int tableRetentionHours = (int) TimeUnit.valueOf(tableConfig.getValidationConfig().getRetentionTimeUnit())
            .toHours(Long.parseLong(tableConfig.getValidationConfig().getRetentionTimeValue()));
    if (_retentionHours > 0) {
      note.append("\n* Table retention and push frequency ignored for determining retentionHours since it is specified in command");
    } else {
      if (_pushFrequency == null) {
        // This is a realtime-only table. Pick up the retention time
        _retentionHours = tableRetentionHours;
        note.append("\n* Retention hours taken from tableConfig");
      } else {
        if ("hourly".equalsIgnoreCase(_pushFrequency)) {
          _retentionHours = DEFAULT_RETENTION_FOR_HOURLY_PUSH;
        } else if ("daily".equalsIgnoreCase(_pushFrequency)) {
          _retentionHours = DEFAULT_RETENTION_FOR_DAILY_PUSH;
        } else if ("weekly".equalsIgnoreCase(_pushFrequency)) {
          _retentionHours = DEFAULT_RETENTION_FOR_WEEKLY_PUSH;
        } else if ("monthly".equalsIgnoreCase(_pushFrequency)) {
          _retentionHours = DEFAULT_RETENTION_FOR_MONTHLY_PUSH;
        } else {
          throw new IllegalArgumentException("Illegal value for pushFrequency: '" + _pushFrequency + "'");
        }
        note.append("\n* Retention hours taken from pushFrequency");
      }
    }

    int[] numHosts = Arrays.stream(_numHosts.split(COMMA_SEPARATOR)).mapToInt(Integer::parseInt).sorted().toArray();
    int[] numHours = Arrays.stream(_numHours.split(COMMA_SEPARATOR)).mapToInt(Integer::parseInt).sorted().toArray();

    int totalConsumingPartitions = _numPartitions * numReplicas;

    // TODO: allow multiple segments.
    // Consuming: Build statsHistory using multiple segments. Use multiple data points of (totalDocs,numHoursConsumed) to calculate totalDocs for our numHours
    // Completed: Use multiple (completedSize,numHours) data points to calculate completed size for our numHours

    long maxUsableHostMemBytes = DataSizeUtils.toBytes(_maxUsableHostMemory);

    MemoryEstimator memoryEstimator;
    if (segmentProvided) {
      // use the provided segment to estimate memory
      memoryEstimator =
          new MemoryEstimator(tableConfig, new File(_sampleCompletedSegmentDir), _ingestionRate, maxUsableHostMemBytes,
              tableRetentionHours);
    } else {
      // no segments provided;
      // generate a segment based on the provided characteristics and then use it to estimate memory
      if (_numRows == 0) {
        _numRows = DEFAULT_NUMBER_OF_ROWS;
      }
      File file = new File(_schemaWithMetadataFile);
      Schema schema = deserialize(file, Schema.class);
      SchemaWithMetaData schemaWithMetaData = deserialize(file, SchemaWithMetaData.class);
      memoryEstimator =
          new MemoryEstimator(tableConfig, schema, schemaWithMetaData, _numRows, _ingestionRate, maxUsableHostMemBytes,
              tableRetentionHours);
    }
    File sampleStatsHistory = memoryEstimator.initializeStatsHistory();
    memoryEstimator
        .estimateMemoryUsed(sampleStatsHistory, numHosts, numHours, totalConsumingPartitions, _retentionHours);

    note.append("\n* See https://docs.pinot.apache.org/operators/operating-pinot/tuning/realtime");
    // TODO: Make a recommendation of what config to choose by considering more inputs such as qps
    displayOutputHeader(note);
    LOGGER.info("\nMemory used per host (Active/Mapped)");
    displayResults(memoryEstimator.getActiveMemoryPerHost(), numHosts, numHours);
    LOGGER.info("\nOptimal segment size");
    displayResults(memoryEstimator.getOptimalSegmentSize(), numHosts, numHours);
    LOGGER.info("\nConsuming memory");
    displayResults(memoryEstimator.getConsumingMemoryPerHost(), numHosts, numHours);
    LOGGER.info("\nTotal number of segments queried per host (for all partitions)");
    displayResults(memoryEstimator.getNumSegmentsQueriedPerHost(), numHosts, numHours);
    return true;
  }

  private void displayOutputHeader(StringBuilder note) {
    System.out.println("\n============================================================\n" + toString());
    System.out.println(note.toString());
  }

  /**
   * Displays the output values as a grid of numHoursToConsume vs numHostsToProvision
   * @param outputValues
   * @param numHosts
   * @param numHours
   */
  private void displayResults(String[][] outputValues, int[] numHosts, int[] numHours) {
    System.out.println();
    System.out.print("numHosts --> ");
    for (int numHostsToProvision : numHosts) {
      System.out.print(getStringForDisplay(String.valueOf(numHostsToProvision)));
      System.out.print("|");
    }
    System.out.println();

    System.out.println("numHours");

    for (int r = 0; r < outputValues.length; r++) {
      System.out.print(String.format("%2d", numHours[r]));
      System.out.print(" --------> ");
      for (int c = 0; c < outputValues[r].length; c++) {
        System.out.print(getStringForDisplay(outputValues[r][c]));
        System.out.print("|");
      }
      System.out.println();
    }
  }

  private String getStringForDisplay(String memoryStr) {
    int numSpacesToPad = MEMORY_STR_LEN - memoryStr.length();
    return memoryStr + StringUtils.repeat(" ", numSpacesToPad);
  }

  private <T> T deserialize(File file, Class<T> clazz) {
    try {
      return JsonUtils.fileToObject(file, clazz);
    } catch (Exception e) {
      throw new RuntimeException(
          String.format("Cannot read schema file '%s' to '%s' object.", file, clazz.getSimpleName()), e);
    }
  }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--
 |  Copyright 2015 Adobe Systems Incorporated
 |
 |  Licensed under the Apache License, Version 2.0 (the "License");
 |  you may not use this file except in compliance with the License.
 |  You may obtain a copy of the License at
 |
 |      http://www.apache.org/licenses/LICENSE-2.0
 |
 |  Unless required by applicable law or agreed to in writing, software
 |  distributed under the License is distributed on an "AS IS" BASIS,
 |  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 |  See the License for the specific language governing permissions and
 |  limitations under the License.
-->
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="aem-archetype"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <requiredProperties>
        <!--
            This is the id of the application and will be used for
              * artifact id
              * /apps, /content and /conf subfolders
              * CSS ids
        -->
        <requiredProperty key="appId">
            <validationRegex>^[a-zA-Z0-9\-]+$</validationRegex>
        </requiredProperty>
        <!--
            Maven artifact groupId for all projects
        -->
        <requiredProperty key="groupId">
            <validationRegex>^[a-zA-Z0-9\.\-_]+$</validationRegex>
        </requiredProperty>
        <!--
            Maven artifact "root" artifactId, is suffixed for the individual modules
        -->
        <requiredProperty key="artifactId">
            <defaultValue>${appId}</defaultValue>
            <validationRegex>^[a-zA-Z0-9\.\-_]+$</validationRegex>
        </requiredProperty>
        <!--
            Maven version
        -->
        <requiredProperty key="version">
            <defaultValue>1.0.0-SNAPSHOT</defaultValue>
            <validationRegex>^[a-zA-Z0-9\.\-]+$</validationRegex>
        </requiredProperty>
        <!--
            This is the human-readable title for the project
        -->
        <requiredProperty key="appTitle"/>
        <!--
            ISO 639-1 language code to create initial content structure
         -->
        <requiredProperty key="language">
            <defaultValue>en</defaultValue>
            <validationRegex>[a-z]{2,3}</validationRegex>
        </requiredProperty>
        <!--
            ISO 639-1 country code to create initial content structure
         -->
        <requiredProperty key="country">
            <defaultValue>us</defaultValue>
            <validationRegex>[a-z]{2,3}</validationRegex>
        </requiredProperty>
        <!--
            Option to create language master structure in example content package
         -->
        <requiredProperty key="singleCountry">
            <defaultValue>y</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>
        <!--
            Option to set target AEM version.
        -->
        <requiredProperty key="aemVersion">
            <defaultValue>cloud</defaultValue>
            <validationRegex>^(6\.4\.8|6\.5\.5|cloud)$</validationRegex>
        </requiredProperty>
        <!--
            AEM as a Cloud Service SDK API version.
        -->
        <requiredProperty key="sdkVersion">
            <defaultValue>latest</defaultValue>
            <validationRegex>^(\d{4}\.\d{2}\.\d{4}\.\d{8}T\d{6}Z-\d{6}|latest)$</validationRegex>
        </requiredProperty>
        <!--
            Option to include Component Library examples as subpackage in the
            ui.apps content package.
        -->
        <requiredProperty key="includeExamples">
            <defaultValue>n</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>
        <!--
            Option to include server wide error handler for 404 response code
         -->
        <requiredProperty key="includeErrorHandler">
            <defaultValue>n</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>
        <!--
            Option to include a dedicated frontend module
         -->
        <requiredProperty key="frontendModule">
            <defaultValue>general</defaultValue>
            <validationRegex>^(none|general|angular|react)$</validationRegex>
        </requiredProperty>

        <!--
            Option to include one of the Dispatcher configuration modules.
        -->
        <requiredProperty key="includeDispatcherConfig">
            <defaultValue>y</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>

        <!--
            Option to include CIF Core Components & corresponding configuration.
        -->
        <requiredProperty key="includeCommerce">
            <defaultValue>n</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>

        <!--
            Set commerce system endpoint for usage with CIF
        -->
        <requiredProperty key="commerceEndpoint">
            <defaultValue>https://hostname.com/graphql</defaultValue>
            <validationRegex>^(?:https:\/\/)[\w.-]+(?:\.[\w\.-]+)+[\w:]+\/graphql$</validationRegex>
        </requiredProperty>

        <!--
            Adobe Client Data Layer integration
        -->
        <requiredProperty key="datalayer">
            <defaultValue>y</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>

        <!--
            Option to add AMP support
        -->
        <requiredProperty key="amp">
            <defaultValue>n</defaultValue>
            <validationRegex>^(y|n)$</validationRegex>
        </requiredProperty>

    </requiredProperties>

    <modules>
        <module id="${rootArtifactId}.all" dir="all" name="all">
            <fileSets>
                <fileSet filtered="true" packaged="false"
                         encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.core" dir="core" name="core">
            <fileSets>
                <fileSet filtered="true" packaged="true"
                    encoding="UTF-8">
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </fileSet>
                <fileSet filtered="true" packaged="true"
                    encoding="UTF-8">
                    <directory>src/test/java</directory>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.dispatcher.ams" dir="dispatcher.ams" name="dispatcher.ams">
            <fileSets>
                <fileSet filtered="true" packaged="false" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/*.conf</include>
                        <include>**/*.vhost</include>
                        <include>**/*.rules</include>
                        <include>**/*.vars</include>
                        <include>**/*.any</include>
                        <include>**/*.farm</include>
                        <include>assembly.xml</include>
                    </includes>
                </fileSet>
                <fileSet filtered="false" packaged="false" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/magic</include>
                        <include>**/README*</include>
                        <include>immutable.files</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.dispatcher.cloud" dir="dispatcher.cloud" name="dispatcher.cloud">
            <fileSets>
                <fileSet filtered="true" packaged="false" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/*.conf</include>
                        <include>**/*.vhost</include>
                        <include>**/*.rules</include>
                        <include>**/*.vars</include>
                        <include>**/*.any</include>
                        <include>**/*.farm</include>
                        <include>assembly.xml</include>
                    </includes>
                </fileSet>
                <fileSet filtered="false" packaged="false" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/README*</include>
                        <include>immutable.files</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.frontend.general" dir="ui.frontend.general" name="ui.frontend.general">
            <fileSets>
                <fileSet filtered="true" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <!-- Exclude Node.js installation (frontend-maven-plugin) -->
                        <exclude>**/node/</exclude>
                        <!-- Exclude NPM dependencies -->
                        <exclude>**/node_modules/</exclude>
                        <exclude>**/package-lock.json</exclude>
                        <exclude>**/yarn.lock</exclude>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <exclude>**/*.gif</exclude>
                        <exclude>**/*.ico</exclude>
                        <exclude>**/*.jpeg</exclude>
                        <exclude>**/*.jpg</exclude>
                        <exclude>**/*.png</exclude>
                        <exclude>**/*.svg</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false">
                    <directory></directory>
                    <includes>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <include>**/*.gif</include>
                        <include>**/*.ico</include>
                        <include>**/*.jpeg</include>
                        <include>**/*.jpg</include>
                        <include>**/*.png</include>
                        <include>**/*.svg</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.frontend.angular" dir="ui.frontend.angular" name="ui.frontend.angular">
            <fileSets>
                <fileSet filtered="true" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <!-- Exclude Node.js installation (frontend-maven-plugin) -->
                        <exclude>**/node/</exclude>
                        <!-- Exclude NPM dependencies -->
                        <exclude>**/node_modules/</exclude>
                        <exclude>**/package-lock.json</exclude>
                        <exclude>**/yarn.lock</exclude>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <exclude>**/*.gif</exclude>
                        <exclude>**/*.ico</exclude>
                        <exclude>**/*.jpeg</exclude>
                        <exclude>**/*.jpg</exclude>
                        <exclude>**/*.png</exclude>
                        <exclude>**/*.svg</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false">
                    <directory></directory>
                    <includes>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <include>**/*.gif</include>
                        <include>**/*.ico</include>
                        <include>**/*.jpeg</include>
                        <include>**/*.jpg</include>
                        <include>**/*.png</include>
                        <include>**/*.svg</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.frontend.react" dir="ui.frontend.react" name="ui.frontend.react">
            <fileSets>
                <fileSet filtered="true" encoding="UTF-8">
                    <directory></directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <!-- Exclude Node.js installation (frontend-maven-plugin) -->
                        <exclude>**/node/</exclude>
                        <!-- Exclude NPM dependencies -->
                        <exclude>**/node_modules/</exclude>
                        <exclude>**/package-lock.json</exclude>
                        <exclude>**/yarn.lock</exclude>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <exclude>**/*.gif</exclude>
                        <exclude>**/*.ico</exclude>
                        <exclude>**/*.jpeg</exclude>
                        <exclude>**/*.jpg</exclude>
                        <exclude>**/*.png</exclude>
                        <exclude>**/*.svg</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false">
                    <directory></directory>
                    <includes>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <include>**/*.gif</include>
                        <include>**/*.ico</include>
                        <include>**/*.jpeg</include>
                        <include>**/*.jpg</include>
                        <include>**/*.png</include>
                        <include>**/*.svg</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.apps" dir="ui.apps" name="ui.apps">
            <fileSets>
                <fileSet filtered="true" encoding="UTF-8">
                <directory></directory>
                <includes>
                    <include>.gitignore</include>
                </includes>
                </fileSet>
                <fileSet filtered="true" packaged="false"
                    encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <exclude>**/*.png</exclude>
                        <exclude>**/*.jpeg</exclude>
                        <exclude>**/image</exclude>
                        <exclude>**/original</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false" packaged="false"
                    encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*.png</include>
                        <include>**/*.jpeg</include>
                        <include>**/image</include>
                        <include>**/original</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.config" dir="ui.config" name="ui.config">
            <fileSets>
                <fileSet filtered="true" packaged="false"
                    encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*.cfg.json</include>
                        <include>**/*.xml</include>
                        <include>**/*.config</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.content" dir="ui.content" name="ui.content">
            <fileSets>
                <fileSet filtered="true" packaged="false"
                    encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <exclude>**/*.png</exclude>
                        <exclude>**/*.jpeg</exclude>
                        <exclude>**/image</exclude>
                        <exclude>**/original</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false" packaged="false"
                    encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*.png</include>
                        <include>**/image</include>
                        <include>**/file</include>
                        <include>**/*.png</include>
                        <include>**/*.jpeg</include>
                        <include>**/image</include>
                        <include>**/original</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.it.tests" dir="it.tests" name="it.tests">
            <fileSets>
                <fileSet filtered="true" packaged="true"
                    encoding="UTF-8">
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </fileSet>
                <fileSet filtered="true" packaged="true"
                    encoding="UTF-8">
                    <directory>src/test/java</directory>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.tests" dir="ui.tests" name="ui.tests">
            <fileSets>
                <fileSet filtered="true">
                    <directory></directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <excludes>
                        <!-- Exclude Test Reports -->
                        <exclude>**/reports/</exclude>
                        <!-- Exclude NPM dependencies -->
                        <exclude>**/node_modules/</exclude>
                        <exclude>**/package-lock.json</exclude>

                        <exclude>**/*.sh</exclude>
                        <exclude>**/*.png</exclude>
                    </excludes>
                </fileSet>
                <fileSet filtered="false">
                    <directory></directory>
                    <includes>
                        <!-- Do not filter binary files (will become corrupted) -->
                        <include>**/*.sh</include>
                        <include>**/*.png</include>
                    </includes>
                </fileSet>
                <fileSet filtered="false" packaged="false"
                    encoding="UTF-8">
                    <directory>test-module</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
        <module id="${rootArtifactId}.ui.apps.structure" dir="ui.apps.structure" name="ui.apps.structure">
            <fileSets>
                <fileSet filtered="true" packaged="false"
                         encoding="UTF-8">
                    <directory>src/main/content</directory>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                </fileSet>
            </fileSets>
        </module>
    </modules>

  <fileSets>
    <fileSet encoding="UTF-8">
      <directory></directory>
      <includes>
        <include>README.md</include>
        <include>README-CIF.md</include>
        <include>.gitignore</include>
        <include>LICENSE</include>
      </includes>
    </fileSet>
    <fileSet filtered="true" encoding="UTF-8">
      <directory></directory>
      <includes>
        <include>archetype.properties</include>
      </includes>
    </fileSet>
  </fileSets>
</archetype-descriptor>


text:
module MundaneSearch
  class Stack
    def all_filters
      return @all_filters if @all_filters
      @all_filters = all_results.collect(&:filter)
    end

    def all_results
      [self] + previous_result.all_results
    end

    def initialize(previous_result, filter_canister)
      @previous_result, @filter_canister = previous_result, filter_canister
    end

    def collection
      filter.call.first
    end

    # necessary?
    def params
      filter.call.last
    end

    def add(filter_canister)
      Stack.new(self,filter_canister)
    end

    def filter
      @filter ||= filter_canister.build(previous_result.collection, previous_result.params)
    end

    private

    attr_reader :previous_result, :filter_canister

  end
end


text:
/* The Purpose of this query is to clean the data before the training*/
SELECT
 *
FROM `{{ source_dataset }}.{{ source_table }}`