text:
package edu.udel.jogordon.bombsgoboom.android;

import android.content.Context;
import android.test.AndroidTestCase;
import edu.udel.jogordon.bombsgoboom.GameRecord;

public class GameDatabaseTest extends AndroidTestCase {

    public void test_TicTacToeDatabaseQueries() {
        Context context = getContext();

        GameDatabase database = new GameDatabase(context);

        GameRecord testRecord = new GameRecord(
            "FOO", 100, Long.valueOf(1));

        assertEquals("INSERT INTO Game_Records (Player, Score, Date) VALUES ('FOO', 100, 1)",
            database.getInsertGameRecordQuery(testRecord));
    }

    public void test_TicTacToeDatabase() {
        Context context = getContext();

        GameDatabase database = new GameDatabase(context);
        // delete game records to start
        database.deleteGameRecords();

        Long date = System.currentTimeMillis();

        database.insertGameRecord(new GameRecord("FOO", 100, date+0));
        database.insertGameRecord(new GameRecord("ACE", 200, date+1));
        database.insertGameRecord(new GameRecord("FOO", 50, date+2));
        database.insertGameRecord(new GameRecord("ACE", 60, date+3));

        GameRecord record = database.getHighestScoreGameRecord();

        assertEquals("ACE", record.getPlayer());
        assertEquals(200, record.getScore().intValue());
    }

}


text:
package codesample.java_se_api.io_and_nio.nio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

class ByteChannelAndByteBufferExample {

    public static void main(String[] args) throws IOException {
        Path path = FilesCreatorNIO.createFiles()[0];
        String str = "Hello, world!";

        /* Create write channel to path */
        try (SeekableByteChannel byteChannel = Files.newByteChannel(path, StandardOpenOption.WRITE)) {

            /* Create buffer and put data from string to this buffer. Rewind buffer, because after putting data buffer's pointer is at the end */
            ByteBuffer buffer = ByteBuffer.allocate(str.length());
            buffer.put(str.getBytes());
            buffer.rewind();

            /* Put buffer to channel */
            while (buffer.hasRemaining())
                byteChannel.write(buffer);

            System.out.println("'Hello, world!' should now be written to file");
        }

        /* Create read channel to path*/
        try (SeekableByteChannel byteChannel = Files.newByteChannel(path, StandardOpenOption.READ)) {
            ByteBuffer buffer = ByteBuffer.allocate(str.length());

            /* Read data from channel to buffer */
            while (byteChannel.read(buffer) > 0) {
            }

            /* Rewind buffer, because after reading buffer's pointer is at the end */
            buffer.rewind();
            System.out.println("Output from file is: ");

            /* print out data in buffer */
            while (buffer.hasRemaining())
                System.out.print((char)buffer.get());
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
<?php

class Services_Settings_Container {
    /**
     * @var null Services_Settings_Container
     */
    private static $_instance = null;

    /**
     * Merged array with all settings (both db, and php)
     *
     * @var array
     */
    private static $_settings = array();

    /**
     * List of container implementations
     *
     * @var array[Services_Settings_IContainer]
     */
    private static $_sources;

    /**
     * Services_Settings_Container is a singleton class, this function instantiates Services_Settings_Container
     */
    public static function singleton() {
        if (self::$_instance === null) {
            self::$_instance = new Services_Settings_Container();
        } # if

        return self::$_instance;
    } # singleton

    /**
     * Add a source of settings. For all these observers, we notify
     * when to update
     *
     * @param Services_Settings_IContainer $source
     */
    public function addSource(Services_Settings_IContainer $source) {
        self::$_sources[] = $source;
        self::$_settings = array_merge(self::$_settings, $source->getAllSettings());

        /*
         * When no specific NNTP header / comments server is entered, we override these with the NZB server
         * header. This allows us to always assume those are entered by the user.
         */
        if ((empty(self::$_settings['nntp_hdr']['host'])) && (!empty(self::$_settings['nntp_nzb']))) {
            self::$_settings['nntp_hdr'] = self::$_settings['nntp_nzb'];
        } # if

        # Same for the NNTP upload server
        if ((empty(self::$_settings['nntp_post']['host'])) && (!empty(self::$_settings['nntp_nzb']))) {
            self::$_settings['nntp_post'] = self::$_settings['nntp_nzb'];
        } # if
    } # addSource

    /**
     * Returns the value of a setting
     */
    function get($name) {
        return self::$_settings[$name];
    } # get

    /**
     * Removes a certain setting from our settings, and
     * notify our observers
     */
    function remove($name) {
        unset(self::$_settings[$name]);

        foreach(self::$_sources as $src) {
            $src->remove($name);
        } # foreach
    } # remove

    /**
     * Updates a setting. It will throw an exception if the
     * setting is set from within PHP to ensure we don't create
     * an setting which seems to revert magically.
     *
     * Otherwise directly persists the setting, so be careful
     */
    function set($name, $value) {
        # Make sure we update our own settings system
        self::$_settings[$name] = $value;

        foreach(self::$_sources as $src) {
            $src->set($name, $value);
        } # foreach
    } # set

    /**
     * Does the setting actually exist?
     */
    function exists($name) {
        return isset(self::$_settings[$name]);
    } # isSet

    /**
     * Returns a list of all settings in an array
     */
    function getAllSettings() {
        return self::$_settings;
    } # getAllSettings

} # class Services_Settings_Container


text:
const {
  IconSvgPaths16,
  IconSvgPaths20,
  iconNameToPathsRecordKey,
} = require('@blueprintjs/icons');
const sass = require('sass');

const findFill = (map) => {
  for (let i = 0; i < map.getLength(); i++) {
    const key = map.getKey(i).getValue();
    const value = map.getValue(i);

    if (key === 'fill' && value instanceof sass.types.Color) {
      return `rgba(${value.getR()}, ${value.getG()}, ${value.getB()}, ${value.getA()})`;
    }

    if (value instanceof sass.types.Map) {
      const recursiveFill = findFill(value);

      if (recursiveFill !== null) {
        return recursiveFill;
      }
    }
  }

  return null;
};

// Blueprint internally uses a custom Sass function `svg-icon` [1] to inline
// icon SVGs to data URIs. In order to be able to build Blueprint from the SCSS
// source, we need to provide a reimplementation of this function to the Sass
// compiler. The implementation used by Blueprint [2] won't work out of the box,
// as it relies on the raw SVG files which are not exported by `@blueprint/icons`.
// For this reason, the `svgIcon` function is implemented differently, using the
// SVG paths exported by `@blueprint/icons`.
//
// [1]: https://sass-lang.com/documentation/js-api/interfaces/Options#functions
// [2]: https://github.com/palantir/blueprint/blob/develop/packages/core/scripts/sass-custom-functions.js

const svgIcon = (path, selectors) => {
  // Parse a string "16px/chevron-right.svg" into size (16) and a name (chevron-right).
  const { size, name } = path
    .getValue()
    .match(/^(?<size>16|20)px\/(?<name>[a-z\-]+)\.svg$/)?.groups;

  // The `selectors` argument is a nested map that represents CSS rules. For example:
  // (path: (fill: '#000')). We try to find a `fill` property in the list and use that
  // in the SVG generated below.
  const fill = findFill(selectors);

  // Get the SVG path for requested icon size and name.
  const paths = size === '16' ? IconSvgPaths16 : IconSvgPaths20;
  const path = paths[iconNameToPathsRecordKey(name)];

  // Assemble an icon SVG element and encode it as a data URI.
  const svg =
    `<svg viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg">` +
    `<path fill-rule="evenodd" clip-rule="evenodd" fill="${fill}" d="${path}" />` +
    `</svg>`;

  const value = `url('data:image/svg+xml,${encodeURIComponent(svg)}')`;

  return new sass.types.String(value);
};

module.exports = {
  style: {
    sass: {
      implementation: sass,
      loaderOptions: (options) => ({
        ...options,
        implementation: sass,
        sassOptions: {
          functions: {
            'svg-icon($path, $selectors: null)': svgIcon,
          },
        },
      }),
    },
  },
};


text:
To configure Velero on Azure, you:

* Download an official release of Velero
* Create your Azure storage account and blob container
* Create Azure service principal for Velero
* Install the server

If you do not have the `az` Azure CLI 2.0 installed locally, follow the [install guide][18] to set it up.

Run:

```bash
az login
```

## Kubernetes cluster prerequisites

Ensure that the VMs for your agent pool allow Managed Disks. If I/O performance is critical,
consider using Premium Managed Disks, which are SSD backed.

## Download Velero

1. Download the [latest official release's](https://github.com/vmware-tanzu/velero/releases) tarball for your client platform.

    _We strongly recommend that you use an [official release](https://github.com/vmware-tanzu/velero/releases) of
Velero. The tarballs for each release contain the `velero` command-line client. The code in the master branch
of the Velero repository is under active development and is not guaranteed to be stable!_

1. Extract the tarball:

    ```bash
    tar -xvf <RELEASE-TARBALL-NAME>.tar.gz -C /dir/to/extract/to
    ```

    We'll refer to the directory you extracted to as the "Velero directory" in subsequent steps.

1. Move the `velero` binary from the Velero directory to somewhere in your PATH.

## Create Azure storage account and blob container

Velero requires a storage account and blob container in which to store backups.

The storage account can be created in the same Resource Group as your Kubernetes cluster or
separated into its own Resource Group. The example below shows the storage account created in a
separate `Velero_Backups` Resource Group.

The storage account needs to be created with a globally unique id since this is used for dns. In
the sample script below, we're generating a random name using `uuidgen`, but you can come up with
this name however you'd like, following the [Azure naming rules for storage accounts][19]. The
storage account is created with encryption at rest capabilities (Microsoft managed keys) and is
configured to only allow access via https.

Create a resource group for the backups storage account. Change the location as needed.

```bash
AZURE_BACKUP_RESOURCE_GROUP=Velero_Backups
az group create -n $AZURE_BACKUP_RESOURCE_GROUP --location WestUS
```

Create the storage account.

```bash
AZURE_STORAGE_ACCOUNT_ID="velero$(uuidgen | cut -d '-' -f5 | tr '[A-Z]' '[a-z]')"
az storage account create \
    --name $AZURE_STORAGE_ACCOUNT_ID \
    --resource-group $AZURE_BACKUP_RESOURCE_GROUP \
    --sku Standard_GRS \
    --encryption-services blob \
    --https-only true \
    --kind BlobStorage \
    --access-tier Hot
```

Create the blob container named `velero`. Feel free to use a different name, preferably unique to a single Kubernetes cluster. See the [FAQ][20] for more details.

```bash
BLOB_CONTAINER=velero
az storage container create -n $BLOB_CONTAINER --public-access off --account-name $AZURE_STORAGE_ACCOUNT_ID
```

## Get resource group for persistent volume snapshots

1. Set the name of the Resource Group that contains your Kubernetes cluster's virtual machines/disks.

    **WARNING**: If you're using [AKS][22], `AZURE_RESOURCE_GROUP` must be set to the name of the auto-generated resource group that is created
    when you provision your cluster in Azure, since this is the resource group that contains your cluster's virtual machines/disks.

    ```bash
    AZURE_RESOURCE_GROUP=<NAME_OF_RESOURCE_GROUP>
    ```

    If you are unsure of the Resource Group name, run the following command to get a list that you can select from. Then set the `AZURE_RESOURCE_GROUP` environment variable to the appropriate value.

    ```bash
    az group list --query '[].{ ResourceGroup: name, Location:location }'
    ```

    Get your cluster's Resource Group name from the `ResourceGroup` value in the response, and use it to set `$AZURE_RESOURCE_GROUP`.

## Create service principal

To integrate Velero with Azure, you must create a Velero-specific [service principal][17].

1. Obtain your Azure Account Subscription ID and Tenant ID:

    ```bash
    AZURE_SUBSCRIPTION_ID=`az account list --query '[?isDefault].id' -o tsv`
    AZURE_TENANT_ID=`az account list --query '[?isDefault].tenantId' -o tsv`
    ```

1. Create a service principal with `Contributor` role. This will have subscription-wide access, so protect this credential.

    If you'll be using Velero to backup multiple clusters with multiple blob containers, it may be desirable to create a unique username per cluster rather than the default `velero`.

    Create service principal and let the CLI generate a password for you. Make sure to capture the password.

    ```bash
    AZURE_CLIENT_SECRET=`az ad sp create-for-rbac --name "velero" --role "Contributor" --query 'password' -o tsv`
    ```

    After creating the service principal, obtain the client id.

    ```bash
    AZURE_CLIENT_ID=`az ad sp list --display-name "velero" --query '[0].appId' -o tsv`
    ```

1. Now you need to create a file that contains all the environment variables you just set. The command looks like the following:

    ```
    cat << EOF  > ./credentials-velero
    AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID}
    AZURE_TENANT_ID=${AZURE_TENANT_ID}
    AZURE_CLIENT_ID=${AZURE_CLIENT_ID}
    AZURE_CLIENT_SECRET=${AZURE_CLIENT_SECRET}
    AZURE_RESOURCE_GROUP=${AZURE_RESOURCE_GROUP}
    EOF
    ```

## Install and start Velero

Install Velero, including all prerequisites, into the cluster and start the deployment. This will create a namespace called `velero`, and place a deployment named `velero` in it.

```bash
velero install \
    --provider azure \
    --bucket $BLOB_CONTAINER \
    --secret-file ./credentials-velero \
    --backup-location-config resourceGroup=$AZURE_BACKUP_RESOURCE_GROUP,storageAccount=$AZURE_STORAGE_ACCOUNT_ID \
    --snapshot-location-config apiTimeout=<YOUR_TIMEOUT>
```

Additionally, you can specify `--use-restic` to enable restic support, and `--wait` to wait for the deployment to be ready.

(Optional) Specify [additional configurable parameters][21] for the `--backup-location-config` flag.

(Optional) Specify [additional configurable parameters][8] for the `--snapshot-location-config` flag.

For more complex installation needs, use either the Helm chart, or add `--dry-run -o yaml` options for generating the YAML representation for the installation.

[0]: namespace.md
[8]: api-types/volumesnapshotlocation.md#azure
[17]: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects
[18]: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
[19]: https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions#storage
[20]: faq.md
[21]: api-types/backupstoragelocation.md#azure
[22]: https://azure.microsoft.com/en-us/services/kubernetes-service/


text:
namespace loom
{

//----------------------------------------------------------------------------
// Loom

Loom::Loom (
        rng_t & rng,
        const protobuf::Config & config,
        const char * model_in,
        const char * groups_in,
        const char * assign_in,
        const char * tares_in) :
    config_(config),
    cross_cat_(),
    assignments_()
{
    cross_cat_.model_load(model_in);
    const size_t kind_count = cross_cat_.kinds.size();
    LOOM_ASSERT(kind_count, "no kinds, loom is empty");
    assignments_.init(kind_count);

    const size_t empty_group_count =
        config_.kernels().cat().empty_group_count();
    LOOM_ASSERT_LT(0, empty_group_count);
    if (groups_in) {
        cross_cat_.mixture_load(groups_in, empty_group_count, rng);
    } else {
        cross_cat_.mixture_init_unobserved(empty_group_count, rng);
    }

    if (tares_in) {
        cross_cat_.tares_load(tares_in, rng);
    }

    if (assign_in) {
        assignments_.load(assign_in);
        for (const auto & kind : cross_cat_.kinds) {
            LOOM_ASSERT_LE(
                assignments_.row_count(),
                kind.mixture.clustering.sample_size());
        }
        LOOM_ASSERT_EQ(assignments_.kind_count(), cross_cat_.kinds.size());
    }

    cross_cat_.validate();
    assignments_.validate();
}

//----------------------------------------------------------------------------
// High level operations

void Loom::dump (
        const char * model_out,
        const char * groups_out,
        const char * assign_out) const
{
    if (model_out) {
        cross_cat_.model_dump(model_out);
    }

    if (groups_out or assign_out) {
        std::vector<std::vector<uint32_t>> sorted_to_globals =
            cross_cat_.get_sorted_groupids();

        if (groups_out) {
            cross_cat_.mixture_dump(groups_out, sorted_to_globals);
        }

        if (assign_out) {
            assignments_.dump(assign_out, sorted_to_globals);
        }
    }
}

void Loom::infer_single_pass (
        rng_t & rng,
        const char * rows_in,
        const char * assign_out)
{
    protobuf::InFile rows(rows_in);
    protobuf::Row row;
    CatKernel cat_kernel(config_.kernels().cat(), cross_cat_);

    if (assign_out) {

        protobuf::OutFile assignments(assign_out);
        protobuf::Assignment assignment;

        while (rows.try_read_stream(row)) {
            cat_kernel.add_row(rng, row, assignment);
            assignments.write_stream(assignment);
        }

    } else {

        while (rows.try_read_stream(row)) {
            cat_kernel.add_row_noassign(rng, row);
        }
    }
}

void Loom::log_metrics (Logger::Message & message)
{
    auto & summary = * message.mutable_summary();
    cross_cat_.topology.protobuf_dump(
        * summary.mutable_model_hypers());

    for (const auto & kind : cross_cat_.kinds) {
        if (not kind.featureids.empty()) {
            auto group_count = kind.mixture.clustering.counts().size()
                             - config_.kernels().cat().empty_group_count();
            summary.add_category_counts(group_count);
            summary.add_feature_counts(kind.featureids.size());
            kind.model.clustering.protobuf_dump(* summary.add_kind_hypers());
        }
    }

    rng_t rng;
    float score = cross_cat_.score_data(rng);
    auto & scores = * message.mutable_scores();
    size_t data_count = assignments_.row_count();
    float kl_divergence = data_count
                        ? (-score - log(data_count)) / data_count
                        : 0;
    scores.set_assigned_object_count(assignments_.row_count());
    scores.set_score(score);
    scores.set_kl_divergence(kl_divergence);
}

void Loom::infer_multi_pass (
        rng_t & rng,
        const char * rows_in,
        const char * checkpoint_in,
        const char * checkpoint_out)
{
    StreamInterval rows(rows_in);
    CombinedSchedule schedule(config_.schedule());
    schedule.annealing.set_extra_passes(
        schedule.accelerating.extra_passes(assignments_.row_count()));

    protobuf::Checkpoint checkpoint;
    if (checkpoint_in) {
        protobuf::InFile(checkpoint_in).read(checkpoint);
        rng.seed(checkpoint.seed());
        rows.load(checkpoint.rows());
        schedule.load(checkpoint.schedule());
        checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
    } else {
        size_t row_count =
            protobuf::InFile::stream_stats(rows_in).message_count;
        checkpoint.set_row_count(row_count);
        if (assignments_.row_count()) {
            rows.init_from_assignments(assignments_);
        }
        checkpoint.set_tardis_iter(0);
        logger([&](Logger::Message & message){
            message.set_iter(checkpoint.tardis_iter());
            log_metrics(message);
        });
    }
    LOOM_ASSERT_LT(assignments_.row_count(), checkpoint.row_count());

    checkpoint.set_finished(false);
    if (config_.kernels().kind().iterations() and schedule.disabling.test()) {
        infer_kind_structure(rows, checkpoint, schedule, rng) ||
        schedule.checkpointing.test() ||
        infer_cat_structure(rows, checkpoint, schedule, rng);
    } else {
        infer_cat_structure(rows, checkpoint, schedule, rng);
    }

    if (checkpoint_out) {
        checkpoint.set_seed(rng());
        rows.dump(* checkpoint.mutable_rows());
        schedule.dump(* checkpoint.mutable_schedule());
        protobuf::OutFile(checkpoint_out).write(checkpoint);
    }
}

bool Loom::infer_kind_structure_sequential (
        StreamInterval & rows,
        Checkpoint & checkpoint,
        CombinedSchedule & schedule,
        rng_t & rng)
{
    KindKernel kind_kernel(config_.kernels(), cross_cat_, assignments_, rng());
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);
    protobuf::Row row;

    while (LOOM_LIKELY(assignments_.row_count() != checkpoint.row_count())) {
        if (schedule.annealing.next_action_is_add()) {

            rows.read_unassigned(row);
            kind_kernel.add_row(row);
            schedule.batching.add();

        } else {

            rows.read_assigned(row);
            kind_kernel.remove_row(row);
            schedule.batching.remove();
        }

        if (LOOM_UNLIKELY(schedule.batching.test())) {
            schedule.annealing.set_extra_passes(
                schedule.accelerating.extra_passes(
                    assignments_.row_count()));
            schedule.disabling.run(kind_kernel.try_run());
            hyper_kernel.try_run(rng);
            kind_kernel.init_cache();
            checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
            logger([&](Logger::Message & message){
                message.set_iter(checkpoint.tardis_iter());
                log_metrics(message);
                kind_kernel.log_metrics(message);
                hyper_kernel.log_metrics(message);
            });
            if (schedule.checkpointing.test()) {
                return false;
            }
            if (not schedule.disabling.test()) {
                return false;
            }
        }
    }

    checkpoint.set_finished(true);
    checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
    logger([&](Logger::Message & message){
        message.set_iter(checkpoint.tardis_iter());
        log_metrics(message);
        kind_kernel.log_metrics(message);
    });
    return true;
}

bool Loom::infer_kind_structure_parallel (
        StreamInterval & rows,
        Checkpoint & checkpoint,
        CombinedSchedule & schedule,
        rng_t & rng)
{
    KindKernel kind_kernel(config_.kernels(), cross_cat_, assignments_, rng());
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);
    KindPipeline pipeline(
        config_.kernels().kind(),
        cross_cat_,
        rows,
        assignments_,
        kind_kernel,
        rng);

    size_t row_count = assignments_.row_count();
    while (LOOM_LIKELY(row_count != checkpoint.row_count())) {
        if (schedule.annealing.next_action_is_add()) {

            ++row_count;
            pipeline.add_row();
            schedule.batching.add();

        } else {

            --row_count;
            pipeline.remove_row();
            schedule.batching.remove();
        }

        if (LOOM_UNLIKELY(schedule.batching.test())) {
            pipeline.wait();
            LOOM_ASSERT_EQ(assignments_.row_count(), row_count);
            schedule.annealing.set_extra_passes(
                schedule.accelerating.extra_passes(
                    assignments_.row_count()));
            schedule.disabling.run(pipeline.try_run());
            hyper_kernel.try_run(rng);
            pipeline.init_cache();
            checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
            logger([&](Logger::Message & message){
                message.set_iter(checkpoint.tardis_iter());
                log_metrics(message);
                pipeline.log_metrics(message);
                hyper_kernel.log_metrics(message);
            });
            if (schedule.checkpointing.test()) {
                return false;
            }
            if (not schedule.disabling.test()) {
                return false;
            }
        }
    }

    pipeline.wait();
    checkpoint.set_finished(true);
    checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
    logger([&](Logger::Message & message){
        message.set_iter(checkpoint.tardis_iter());
        log_metrics(message);
        pipeline.log_metrics(message);
    });
    return true;
}

bool Loom::infer_cat_structure_sequential (
        StreamInterval & rows,
        Checkpoint & checkpoint,
        CombinedSchedule & schedule,
        rng_t & rng)
{
    CatKernel cat_kernel(config_.kernels().cat(), cross_cat_);
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);
    protobuf::Row row;

    while (LOOM_LIKELY(assignments_.row_count() != checkpoint.row_count())) {
        if (schedule.annealing.next_action_is_add()) {

            rows.read_unassigned(row);
            cat_kernel.add_row(rng, row, assignments_);
            schedule.batching.add();

        } else {

            rows.read_assigned(row);
            cat_kernel.remove_row(rng, row, assignments_);
            schedule.batching.remove();
        }

        if (LOOM_UNLIKELY(schedule.batching.test())) {
            schedule.annealing.set_extra_passes(
                schedule.accelerating.extra_passes(
                    assignments_.row_count()));
            hyper_kernel.try_run(rng);
            checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
            logger([&](Logger::Message & message){
                message.set_iter(checkpoint.tardis_iter());
                log_metrics(message);
                cat_kernel.log_metrics(message);
                hyper_kernel.log_metrics(message);
            });
            if (schedule.checkpointing.test()) {
                return false;
            }
        }
    }

    checkpoint.set_finished(true);
    checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
    logger([&](Logger::Message & message){
        message.set_iter(checkpoint.tardis_iter());
        log_metrics(message);
        cat_kernel.log_metrics(message);
    });
    return true;
}

bool Loom::infer_cat_structure_parallel (
        StreamInterval & rows,
        Checkpoint & checkpoint,
        CombinedSchedule & schedule,
        rng_t & rng)
{
    CatKernel cat_kernel(config_.kernels().cat(), cross_cat_);
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);
    CatPipeline pipeline(
        config_.kernels().cat(),
        cross_cat_,
        rows,
        assignments_,
        cat_kernel,
        rng);

    size_t row_count = assignments_.row_count();
    while (LOOM_LIKELY(row_count != checkpoint.row_count())) {
        if (schedule.annealing.next_action_is_add()) {

            ++row_count;
            pipeline.add_row();
            schedule.batching.add();

        } else {

            --row_count;
            pipeline.remove_row();
            schedule.batching.remove();
        }

        if (LOOM_UNLIKELY(schedule.batching.test())) {
            pipeline.wait();
            LOOM_ASSERT_EQ(assignments_.row_count(), row_count);
            schedule.annealing.set_extra_passes(
                schedule.accelerating.extra_passes(row_count));
            hyper_kernel.try_run(rng);
            checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
            logger([&](Logger::Message & message){
                message.set_iter(checkpoint.tardis_iter());
                log_metrics(message);
                hyper_kernel.log_metrics(message);
            });
            if (schedule.checkpointing.test()) {
                return false;
            }
        }
    }

    pipeline.wait();
    checkpoint.set_finished(true);
    checkpoint.set_tardis_iter(checkpoint.tardis_iter() + 1);
    logger([&](Logger::Message & message){
        message.set_iter(checkpoint.tardis_iter());
        log_metrics(message);
    });
    return true;
}

void Loom::posterior_enum (
        rng_t & rng,
        const char * rows_in,
        const char * samples_out)
{
    const size_t sample_count = config_.posterior_enum().sample_count();
    const size_t sample_skip = config_.posterior_enum().sample_skip();
    LOOM_ASSERT_LE(1, sample_count);
    LOOM_ASSERT(sample_skip > 0 or sample_count == 1, "zero diversity");

    CatKernel cat_kernel(config_.kernels().cat(), cross_cat_);
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);

    const auto rows = protobuf_stream_load<protobuf::Row>(rows_in);

    LOOM_ASSERT_LT(0, rows.size());
    if (assignments_.rowids().empty()) {
        for (const auto & row : rows) {
            cat_kernel.add_row(rng, row, assignments_);
        }
    }

    protobuf::OutFile sample_stream(samples_out);
    protobuf::PosteriorEnum::Sample sample;

    if (config_.kernels().kind().iterations() > 0) {

        KindKernel kind_kernel(
            config_.kernels(),
            cross_cat_,
            assignments_,
            rng());

        for (size_t i = 0; i < sample_count; ++i) {
            for (size_t t = 0; t < sample_skip; ++t) {
                for (const auto & row : rows) {
                    kind_kernel.remove_row(row);
                    kind_kernel.add_row(row);
                }
                kind_kernel.try_run();
                hyper_kernel.try_run(rng);
                kind_kernel.init_cache();
            }
            dump_posterior_enum(sample, rng);
            sample_stream.write_stream(sample);
        }

    } else {

        for (size_t i = 0; i < sample_count; ++i) {
            for (size_t t = 0; t < sample_skip; ++t) {
                for (const auto & row : rows) {
                    cat_kernel.remove_row(rng, row, assignments_);
                    cat_kernel.add_row(rng, row, assignments_);
                }
                hyper_kernel.try_run(rng);
            }
            dump_posterior_enum(sample, rng);
            sample_stream.write_stream(sample);
        }
    }
}

inline void Loom::dump_posterior_enum (
        protobuf::PosteriorEnum::Sample & message,
        rng_t & rng)
{
    float score = cross_cat_.score_data(rng);
    const size_t row_count = assignments_.row_count();
    const size_t kind_count = assignments_.kind_count();
    const auto & rowids = assignments_.rowids();

    message.Clear();
    for (size_t kindid = 0; kindid < kind_count; ++kindid) {
        const auto & kind = cross_cat_.kinds[kindid];
        if (not kind.featureids.empty()) {
            const auto & groupids = assignments_.groupids(kindid);
            auto & message_kind = * message.add_kinds();
            for (auto featureid : kind.featureids) {
                message_kind.add_featureids(featureid);
            }
            std::unordered_map<size_t, std::vector<size_t>> groupids_map;
            for (size_t i = 0; i < row_count; ++i) {
                groupids_map[groupids[i]].push_back(rowids[i]);
            }
            for (const auto & pair : groupids_map) {
                auto & message_group = * message_kind.add_groups();
                for (const auto & rowid : pair.second) {
                    message_group.add_rowids(rowid);
                }
            }
        }
    }
    message.set_score(score);
}

void Loom::generate (
        rng_t & rng,
        const char * rows_out)
{
    LOOM_ASSERT_EQ(assignments_.row_count(), 0);

    HyperKernel(config_.kernels().hyper(), cross_cat_).try_run(rng);

    generate_rows(config_.generate(), cross_cat_, assignments_, rows_out, rng);

    cross_cat_.validate();
    assignments_.validate();

    LOOM_ASSERT_EQ(assignments_.row_count(), config_.generate().row_count());
}

void Loom::mix (
        rng_t & rng,
        const char * rows_in)
{
    const size_t sample_skip = config_.generate().sample_skip();
    LOOM_ASSERT(sample_skip > 0, "zero diversity");

    CatKernel cat_kernel(config_.kernels().cat(), cross_cat_);
    HyperKernel hyper_kernel(config_.kernels().hyper(), cross_cat_);
    KindKernel kind_kernel(config_.kernels(), cross_cat_, assignments_, rng());

    for (size_t i = 0; i < sample_skip; ++i) {
        protobuf::InFile rows(rows_in);
        protobuf::Row row;
        while (rows.try_read_stream(row)) {
            kind_kernel.remove_row(row);
            kind_kernel.add_row(row);
        }
        kind_kernel.try_run();
        hyper_kernel.try_run(rng);
        kind_kernel.init_cache();
    }
}

} // namespace loom


text:
macro(map_keys this)
  get_property(__ans GLOBAL PROPERTY "${this}.__keys__")
  #return_ref(keys)
endmacro()
# returns all keys for the specified map
#function(map_keys this)
#  get_property(keys GLOBAL PROPERTY "${this}")
#  return_ref(keys)
#endfunction()


text:
var http = require('http');

http.globalAgent.maxSockets = 65535

var httpProxy = require('http-proxy');
var debug = require('debug');
var lodash = require('lodash');

function HttpProxyWorker(options){
    this.proxy = httpProxy.createProxyServer({});
    this.server = http.createServer(options.requestHandler);
    this.server.on('upgrade', options.wsReqestHandler);

    this.logger = options.logger;
    if (!this.logger) {
        this.logger = debug("cloudbrowser:master:proxy");
    }
    this.infoLogger = options.infoLogger;
    if (!this.infoLogger) {
        this.infoLogger = this.logger;
    }
    var infoLogger = this.infoLogger;
    this.proxy.on('error', function proxyError(err, req, res, target){
        var errorMsg = null;
        if (target && target.host) {
            errorMsg = "Proxy error "+ err.message + " @ " + target.host + ":" + target.port +" " + req.url;
        }else{
            errorMsg = "Proxy error "+ err.message + " @null " + req.url;
        }
        infoLogger(errorMsg);
        infoLogger(err.stack);
        res.writeHead(500, "Proxy Error.");
        res.end();
    });
}

lodash.assign(HttpProxyWorker.prototype, {
    listen : function(socket, callback){
        if(!callback){
            callback = lodash.noop;
        }
        var self = this;
        this.server.listen(socket, 2048, function(){
            callback(null, self);
        });
    },
    // return if it is successfully proxied
    proxyRequest : function(req, res, worker, redirect){
        if(!worker){
            this.infoLogger('cannot find a worker');
            res.writeHead(404);
            res.end("The url is no longer valid.");
            return false
        }
        if(redirect!=null){
            this.logger("Redirect "+req.url +" to "+redirect);
            req.url = redirect;
            return false
        }
        this.logger("proxy reqeust "+ req.url+" to "+worker.id);
        this.proxy.web(req, res, {
            target:
                {
                    host : worker.host,
                    port : worker.httpPort
                }
         })
        return true
    },
    proxyWebSocketRequest : function(req, socket, head, worker){
        if(!worker){
            // TODO integrate with socket.io to send useful
            // error info back to client
            return socket.close();
        }
        this.logger("proxy ws request "+ req.url +" to "+ worker.id);
        this.proxy.ws(req, socket, head, {
            target:
                {
                    host : worker.host,
                    port : worker.httpPort
                }
        })
    }
});

if (require.main === module){
    var logger = debug('cloudbrowser:master:proxy');
    var infoLogger = debug('cloudbrowser:master:proxyInfo');
    var pid = process.pid;
    var workerId = -1;
    infoLogger("Proxy worker "+pid+" started.");

    var msgId = 0;
    var requestQueue = {};

    function getWorkerResHandler(msg){
        var id = msg.id;
        var queued = requestQueue[id];
        if (queued != null) {
            delete requestQueue[id];
            var worker = msg.worker;
            if (queued.socket != null) {
                httpProxyWorker.proxyWebSocketRequest(queued.req, queued.socket, queued.head, worker);
            }else{
                var redirect = msg.redirect;
                httpProxyWorker.proxyRequest(queued.req, queued.res, worker, redirect);
            }
        }else{
            infoLogger("cannot find matched request for "+JSON.stringify(msg));
        }
    }

    function createGetWorkerReq(req){
        var id = msgId++;
        var reqObj = {
            url : req.url
        };
        if (req.headers && req.headers.referer) {
            reqObj.headers = {
                referer : req.headers.referer
            };
        }
        return {
            type : 'getWorkerReq',
            id: id,
            req : reqObj
        };
    }

    function RequestQueueEle(id, req, res, socket, head){
        this.id = id;
        this.req = req;
        this.res = res;
        this.socket = socket;
        this.head = head;
    }

    function putNewRequestQueueEle(id, req, res, socket, head){
        requestQueue[id] = new RequestQueueEle(id, req, res, socket, head);
    }

    function proxyRequest(req, res){
        logger("ProxyWorker #"+workerId+" get a request "+req.url);
        var getWorkerReq = createGetWorkerReq(req);
        process.send(getWorkerReq);
        putNewRequestQueueEle(getWorkerReq.id, req, res);
    }

    function proxyWebSocketRequest(req, socket, head){
        logger("ProxyWorker #"+workerId+" get a request "+req.url);
        var getWorkerReq = createGetWorkerReq(req);
        // indicate this is from websocket request
        getWorkerReq.websocket = true;
        process.send(getWorkerReq);
        putNewRequestQueueEle(getWorkerReq.id, req, null, socket, head);
    }

    var httpProxyWorker = new HttpProxyWorker({
        requestHandler : proxyRequest,
        wsReqestHandler : proxyWebSocketRequest,
        logger : logger,
        infoLogger : infoLogger
    });

    process.on("message", function(msg, sendHandle){
        if (msg.type === 'config') {
            var config = msg.config;
            logger("proxy worker "+pid + "->" + config.id+" get config.");
            workerId = config.id;
            httpProxyWorker.listen(sendHandle);
            return;
        }
        if (msg.type === 'getWorkerRes') {
            getWorkerResHandler(msg);
            return;
        }
        infoLogger("unknown type of message "+JSON.stringify(msg));
    });
}

exports.HttpProxyWorker = HttpProxyWorker


text:
#include <aws/network-firewall/model/CreateRuleGroupResult.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/AmazonWebServiceResult.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/UnreferencedParam.h>

#include <utility>

using namespace Aws::NetworkFirewall::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
using namespace Aws;

CreateRuleGroupResult::CreateRuleGroupResult()
{
}

CreateRuleGroupResult::CreateRuleGroupResult(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  *this = result;
}

CreateRuleGroupResult& CreateRuleGroupResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  JsonView jsonValue = result.GetPayload().View();
  if(jsonValue.ValueExists("UpdateToken"))
  {
    m_updateToken = jsonValue.GetString("UpdateToken");

  }

  if(jsonValue.ValueExists("RuleGroupResponse"))
  {
    m_ruleGroupResponse = jsonValue.GetObject("RuleGroupResponse");

  }

  return *this;
}


text:
{% extends 'layout.html' %}

{% block title %}Error{% endblock %}

{% block content %}

500 Internal Server Error

Yeah, something went wrong…
{% endblock %}


text:
<Record>
<Term>Benzphetamine</Term>
<SemanticType>Pharmacologic Substance</SemanticType>
<SemanticType>Organic Chemical</SemanticType>
<PrimarySemanticType>Pharmacologic Substance</PrimarySemanticType>
<Synonym>Benzphetamine</Synonym>
<Synonym>Benzphetamine hydrochloride</Synonym>
<Synonym>Didrex</Synonym>
<Source>FDA Registry</Source>
</Record>


text:
echo_section "Installing OpenSSH"

ensure_pkg openssh
if [[ ! -e /etc/ssh/sshd_config.defaults ]]; then
  echo_info "Creating backup copy of the configuration file"
  sudopw cp /etc/ssh/sshd_config /etc/ssh/sshd_config.defaults
else
  echo_info "Backup copy of default configuration file already exists"
fi

if [[ "${OPENSSH_SERVER_PASSWORD_AUTHENTICATION}" == "true" ]]; then
  echo_subsection "Configuring OpenSSH Server to allow password authentication"
  replace_conf "PasswordAuthentication no" "PasswordAuthentication yes" /etc/ssh/sshd_config -sudo
  replace_conf "#PasswordAuthentication no" "PasswordAuthentication yes" /etc/ssh/sshd_config -sudo
  replace_conf "#PasswordAuthentication yes" "PasswordAuthentication yes" /etc/ssh/sshd_config -sudo
else
  echo_subsection "Configuring OpenSSH Server for authentication with keys only"
  replace_conf "PasswordAuthentication yes" "PasswordAuthentication no" /etc/ssh/sshd_config -sudo
  replace_conf "#PasswordAuthentication yes" "PasswordAuthentication no" /etc/ssh/sshd_config -sudo
  replace_conf "#PasswordAuthentication no" "PasswordAuthentication no" /etc/ssh/sshd_config -sudo
fi

echo_subsection "Setting default port for OpenSSH Server"
# Changing the default port: Good or bad?
# https://danielmiessler.com/blog/putting-ssh-another-port-good-idea/
# https://major.io/2013/05/14/changing-your-ssh-servers-port-from-the-default-is-it-worth-it/
sudo grep -q -F "Port ${OPENSSH_SERVER_PORT}" /etc/ssh/sshd_config || sudo sed -i "s/#Port 22/Port ${OPENSSH_SERVER_PORT}/" /etc/ssh/sshd_config

ensure_dir /etc/systemd/system/sshd.socket.d -sudo
sudo tee /etc/systemd/system/sshd.socket.d/override.conf << EOF > /dev/null
[Socket]
ListenStream=
ListenStream=${OPENSSH_SERVER_PORT}
EOF
sudopw systemctl daemon-reload

echo_subsection "Starting OpenSSH Server"
sudopw systemctl enable sshd.socket
sudopw systemctl start sshd.socket


text:
import { graphql } from "react-relay"
import { useMutation } from "Utils/Hooks/useMutation"
import { useDeleteArtworkMutation } from "__generated__/useDeleteArtworkMutation.graphql"

export const useDeleteArtwork = () => {
  return useMutation<useDeleteArtworkMutation>({
    mutation: graphql`
      mutation useDeleteArtworkMutation(
        $input: MyCollectionDeleteArtworkInput!
      ) {
        myCollectionDeleteArtwork(input: $input) {
          artworkOrError {
            ... on MyCollectionArtworkMutationSuccess {
              artwork {
                internalID
              }
            }
            ... on MyCollectionArtworkMutationFailure {
              mutationError {
                message
              }
            }
          }
        }
      }
    `,
  })
}