text:
/**
  * Created by anicolaspp on 7/2/16.
  */

package com.nico.persistence

import com.nico.persistence.storage.{InMemoryAccountStorage, AccountStorage, StorageComponent, PathProviderComponent}

trait AccountManagerComponent { this: StorageComponent =>
  val manager: AccountManager

  trait AccountManager {
    def accountInfo: Account

    def deposit(amount: Double): Account = {
      val account = accountInfo

      storage.update(Account(account.id, account.balance + amount))
    }

    def extract(amount: Double): (Boolean, Account) = {
      val account = accountInfo

      if (account.balance < amount) {
        (false, account)
      }
      else {
        (true, storage.update(Account(account.id, account.balance - amount)))
      }
    }
  }
}

trait TransactionManager extends AccountManagerComponent with StorageComponent with PathProviderComponent

object TransactionManager {

  def onDisk(account: String, root: String): TransactionManager = new TransactionManager with AccountStorage {
    override val pathProvider: PathProvider = new PathProvider {
      override def path: String = root
    }
    override val manager: AccountManager = new AccountManager {
        override def accountInfo: Account = storage.get(account)
      }
  }

  def inMemory(account: String): TransactionManager = new TransactionManager with InMemoryAccountStorage {
    override val manager: AccountManager = new AccountManager {
      override def accountInfo: Account = storage.get(account)
    }
  }
}


text:
//
// Created by hacht on 2/24/17.
//

#pragma once

#include <algorithm>  // std::fill, std::generate
#include <cmath>      // sqrt
#include <numeric>    // std::accumulate
#include <vector>

#include "../../util/util.h"
#include "cblas.h"
#include "tensor.h"

namespace simpleCNN {

  template <typename T>
  void print(T t) {
    std::cout << t << std::endl;
  }

  template <typename T>
  void print_seq(T t) {
    std::cout << t << "\t";
  }

  template <typename T>
  void printvt(std::vector<T> c, const std::string& name) {
    simple_info(name.c_str());
    for (size_t i = 0; i < c.size(); ++i) {
      print(c[i]);
    }
    print("");
  }

  template <typename T>
  void printvt_ptr(std::vector<T*> c, const std::string& name) {
    simple_info(name.c_str());
    for (size_t i = 0; i < c.size(); ++i) {
      print(*c[i]);
    }
    print("");
  }

  template <typename Container>
  void printvc(std::vector<Container> c, const std::string& name) {
    simple_info(name.c_str());
    for (size_t i = 0; i < c.size(); ++i) {
      for (auto iter = std::begin(c[i]); iter != std::end(c[i]); ++iter) {
        print_seq(*iter);
      }
      print("");
    }
  }

  template <typename Container>
  void printc(Container c, const std::string& name) {
    simple_info(name.c_str());
    for (auto iter = std::begin(c); iter != std::end(c); ++iter) {
      print_seq(*iter);
    }
    std::cout << std::endl;
  }

  template <typename T>
  void print(T t, const std::string& name) {
    simple_info(name.c_str());
    print(t);
  }

  template <typename T>
  void print_pack(std::ostream& out, T t) {
    out << t;
  }

  template <typename T, typename U, typename... Args>
  void print_pack(std::ostream& out, T t, U u, Args... args) {
    out << t << ',';
    print_pack(out, u, args...);
  }

  template <typename T, size_t kDim, typename... Args>
  inline std::ostream& print_last_two_dimensions(std::ostream& os, const Tensor<T, kDim>& tensor, const Args... args) {
    const std::array<size_t, kDim>& shape = tensor.shape();
    for (size_t k = 0; k < shape[kDim - 2]; ++k) {
      for (size_t l = 0; l < shape[kDim - 1]; ++l) {
        os << "\t" << tensor.host_at(args..., k, l);
      }
      os << "\n";
    }
    return os;
  }

  template <typename T,
            size_t kDim,
            typename... Args,
            typename std::enable_if<sizeof...(Args) == kDim - 3, int>::type = 0>
  inline std::ostream& print_last_n_dimensions(std::ostream& os,
                                               const Tensor<T, kDim>& tensor,
                                               const int d,
                                               const Args... args) {
    os << "Tensor(";
    print_pack(os, d, args...);
    os << ",:,:):\n";
    print_last_two_dimensions(os, tensor, d, args...);
    return os;
  }

  /*template<typename T,
      size_t kDim,
      typename std::enable_if<(kDim == 2), int>::type = 0>
  inline std::ostream& print_last_n_dimensions(std::ostream& os, const Tensor<T, kDim>& tensor, int d)
  {
    const std::array<size_t, kDim>& shape = tensor.shape();
    for (size_t i = 0; i < shape[kDim - 2]; ++i) {
      os << "\t" << tensor.host_at(d, i);
    }
    os << "\n";
    return os;
  };*/

  template <typename T,
            size_t kDim,
            typename... Args,
            typename std::enable_if<(sizeof...(Args) < kDim - 3), int>::type = 0>
  inline std::ostream& print_last_n_dimensions(std::ostream& os,
                                               const Tensor<T, kDim>& tensor,
                                               const int d,
                                               const Args... args) {
    const std::array<size_t, kDim>& shape = tensor.shape();
    const size_t n_dim = sizeof...(args);
    for (size_t k = 0; k < shape[n_dim + 1]; ++k) {
      print_last_n_dimensions(os, tensor, d, args..., k);
    }
    return os;
  }

  template <typename T>
  inline std::ostream& operator<<(std::ostream& os, const Tensor<T, 1>& tensor) {
    for (auto iter = tensor.host_begin(); iter != tensor.host_end(); ++iter) {
      os << "\t" << *iter;
    }
    os << "\n";
    return os;
  }

  template <typename T>
  inline std::ostream& operator<<(std::ostream& os, const Tensor<T, 2>& tensor) {
    print_last_two_dimensions(os, tensor);
    return os;
  }

  template <typename T, size_t kDim>
  inline std::ostream& operator<<(std::ostream& os, const Tensor<T, kDim>& tensor) {
    const std::array<size_t, kDim>& shape = tensor.shape();
    for (size_t i = 0; i < shape[0]; ++i) print_last_n_dimensions(os, tensor, i);
    return os;
  }

  template <typename T, size_t kDim, typename... Args>
  inline void fill_last_two_dimensions(vec_iter_t& curr,
                                       Tensor<T, kDim>& tensor,
                                       const vec_iter_t& end,
                                       const Args... args) {
    const std::array<size_t, kDim>& shape = tensor.shape();
    for (size_t k = 0; k < shape[kDim - 2]; ++k) {
      for (size_t l = 0; l < shape[kDim - 1] && curr != end; ++l) {
        *tensor.host_iter(args..., k, l) = *curr++;
      }
    }
  };

  template <typename T,
            size_t kDim,
            typename... Args,
            typename std::enable_if<(sizeof...(Args) == kDim - 3), int>::type = 0>
  inline void fill_last_n_dimensions(
    vec_iter_t& curr, Tensor<T, kDim>& tensor, const vec_iter_t& end, const int d, const Args... args) {
    fill_last_two_dimensions(curr, tensor, end, d, args...);
  };

  template <typename T,
            size_t kDim,
            typename... Args,
            typename std::enable_if<(sizeof...(Args) < kDim - 3), int>::type = 0>
  inline void fill_last_n_dimensions(
    vec_iter_t& curr, Tensor<T, kDim>& tensor, const vec_iter_t& end, const int d, const Args... args) {
    const std::array<size_t, kDim>& shape = tensor.shape();
    const size_t n_dim = sizeof...(args);
    for (size_t k = 0; k < shape[n_dim + 1]; ++k) {
      fill_last_n_dimensions(curr, tensor, end, d, args..., k);
    }
  };

  template <typename T, size_t kDim>
  inline void fill(vec_t& data, Tensor<T, kDim>& tensor) {
    vec_iter_t curr      = data.begin();
    const vec_iter_t end = data.end();
    const std::array<size_t, kDim>& shape = tensor.shape();
    for (size_t i = 0; i < shape[0]; ++i) {
      fill_last_n_dimensions(curr, tensor, end, i);
    }
  }

  template <typename T, size_t kDim>
  inline void fill(vec_t& data, Tensor<T, kDim>& tensor, const std::string& name) {
    fill(data, tensor);
    print(tensor, name.c_str());
  };

  template <typename T>
  inline void fill(vec_t& data, Tensor<T, 2>& tensor) {
    vec_iter_t curr      = data.begin();
    const vec_iter_t end = data.end();
    fill_last_two_dimensions(curr, tensor, end);
  }

  template <typename T>
  inline void fill(vec_t& data, Tensor<T, 2>& tensor, const std::string& name) {
    fill(data, tensor);
    print(tensor, name.c_str());
  }

  template <typename T>
  inline void fill(vec_t& data, Tensor<T, 1>& tensor) {
    vec_iter_t curr      = data.begin();
    const vec_iter_t end = data.end();
    const std::array<size_t, 1>& shape = tensor.shape();
    for (size_t i = 0; i < shape[0] && curr != end; ++i) {
      *tensor.host_iter(i) = *curr++;
    }
  }

  void copy_to(const tensor_t& from, tensor_t& to, const size_t start_index_from, const size_t start_index_to) {
    size_t batch_length = from.size() / from.shape()[0];

    for (size_t i = 0; i < batch_length; ++i) {
      to.host_at_index(start_index_to * batch_length + i) = from.host_at_index(start_index_from * batch_length + i);
    }
  }

  void split_training_validation(const tensor_t& from,
                                 tensor_t& to_training,
                                 tensor_t& to_validation,
                                 const float_t ratio) {
    size_t num_images  = from.shape()[0];
    size_t split_index = num_images * ratio;

    for (size_t i = 0; i < num_images; ++i) {
      if (i < split_index) {
        copy_to(from, to_training, i, i);
      } else {
        copy_to(from, to_validation, i, i - split_index);
      }
    }
  }

  /**
     * OpenBLAS efficient matrix multiplication. This version supports
     * floating point precision only, double precision also exists but is not going to be used here.
     * The wrapper calling function is right below this function.
     *
     */
  static void matrix_multiplcation(
    float* A, int A_width, int A_height, float* B, int B_width, int B_height, float* AB, bool tA, bool tB, float beta) {
    int A_height_new = tA ? A_width : A_height;
    int A_width_new  = tA ? A_height : A_width;
    int B_height_new = tB ? B_width : B_height;
    int B_width_new  = tB ? B_height : B_width;
    int m            = A_height_new;
    int n            = B_width_new;
    int k            = A_width_new;

    // Error, width and height should match!
    assert(A_width_new == B_height_new);
    int lda = tA ? m : k;
    int ldb = tB ? k : n;
#define TRANSPOSE(X) ((X) ? CblasTrans : CblasNoTrans)
    // http://www.netlib.org/lapack/explore-html/d7/d2b/sgemm_8f.html
    cblas_sgemm(CblasRowMajor,  // I know you
                TRANSPOSE(tA), TRANSPOSE(tB), m, n, k, 1.0f, A, lda, B, ldb, beta, AB, n);
#undef TRANSPOSE(X)
  }

  /**
   * Use this for matrix_t (float_t) multiplication
   *
   */
  static void sgemm(matrix_t& A, matrix_t& B, matrix_t& AB, bool transpose_A, bool transpose_B) {
    matrix_multiplcation(&A.host_at(0, 0), A.shape()[1], A.shape()[0], &B.host_at(0, 0), B.shape()[1], B.shape()[0],
                         &AB.host_at(0, 0), transpose_A, transpose_B, 0);
  }

  /**
   * Float matrix multiplication of two tensors.
   *
   * @tparam kDims              tensor dimensions, default 4
   * @tparam kConst             if tensor is accesses as const or not
   * @tparam Allocator          allocator type used by iterator to determine next
   * @param A                   left operand
   * @param start_A             start location in tensor A, should be A.host_iter(batch_i, channel_i, 0, 0) for default
   * tensor
   * @param B                   right operand
   * @param start_B             start location in tensor B, should be B.host_iter(batch_i, channel_i, 0, 0) for default
   * tensor
   * @param AB                  matrix multiplication result
   * @param start_AB            start location in tensor AB, should be AB.host_iter(batch_i, channel_i, 0, 0) for
   * default tensor
   * @param transpose_A         if A needs to be transposed (index iterated backwards)
   * @param transpose_B         if B needs to be transposed (index iterated backwards)
   */
  template <size_t kDims = 4, bool kConst = false, typename Allocator = aligned_allocator<float_t, 64>>
  static void multiply(const Tensor<float_t, kDims, kConst, Allocator>& A,
                       float_t* start_A,
                       const Tensor<float_t, kDims, kConst, Allocator>& B,
                       float_t* start_B,
                       float_t* start_AB,
                       bool transpose_A,
                       bool transpose_B) {
    int width_A  = A.shape()[kDims - 1];
    int height_A = A.shape()[kDims - 2];
    int width_B  = B.shape()[kDims - 1];
    int height_B = B.shape()[kDims - 2];
    matrix_multiplcation(start_A, width_A, height_A, start_B, width_B, height_B, start_AB, transpose_A, transpose_B, 0);
  }

  static float_t matrix_dot_product(const int& length, float* A, const int incm, float* B, const int incn) {
    return cblas_sdot(length, A, incm, B, incn);
  }

  template <size_t kDims = 4, bool kConst = false, typename Allocator = aligned_allocator<float_t, 64>>
  static float_t dot(const Tensor<float_t, kDims, kConst, Allocator>& A,
                     float_t* start_A,
                     const Tensor<float_t, kDims, kConst, Allocator>& B,
                     float_t* start_B) {
    int width_A  = A.shape()[kDims - 1];
    int height_A = A.shape()[kDims - 2];
    int width_B  = B.shape()[kDims - 1];
    int height_B = B.shape()[kDims - 2];

    assert(width_A == width_B);
    assert(height_A == height_B);
    assert(width_A * height_A == width_B * height_B);
    int length = width_A * height_A;

    return matrix_dot_product(length, start_A, 1, start_B, 1);
  }
}  // namespace simpleCNN

redpajama_set_name: RedPajamaGithub


text:
package org.elasticsearch.indices.recovery;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexFormatTooNewException;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefIterator;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.util.Callback;
import org.elasticsearch.common.util.CancellableThreads;
import org.elasticsearch.common.util.concurrent.AbstractRefCounted;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.TranslogRecoveryPerformer;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.StoreFileMetaData;
import org.elasticsearch.index.translog.Translog;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Represents a recovery where the current node is the target node of the recovery. To track recoveries in a central place, instances of
 * this class are created through {@link RecoveriesCollection}.
 */
public class RecoveryTarget extends AbstractRefCounted implements RecoveryTargetHandler {

    private final Logger logger;

    private static final AtomicLong idGenerator = new AtomicLong();

    private final String RECOVERY_PREFIX = "recovery.";

    private final ShardId shardId;
    private final long recoveryId;
    private final IndexShard indexShard;
    private final DiscoveryNode sourceNode;
    private final String tempFilePrefix;
    private final Store store;
    private final PeerRecoveryTargetService.RecoveryListener listener;
    private final Callback<Long> ensureClusterStateVersionCallback;

    private final AtomicBoolean finished = new AtomicBoolean();

    private final ConcurrentMap<String, IndexOutput> openIndexOutputs = ConcurrentCollections.newConcurrentMap();
    private final CancellableThreads cancellableThreads;

    // last time this status was accessed
    private volatile long lastAccessTime = System.nanoTime();

    private final Map<String, String> tempFileNames = ConcurrentCollections.newConcurrentMap();

    private RecoveryTarget(RecoveryTarget copyFrom) { // copy constructor
        this(copyFrom.indexShard, copyFrom.sourceNode, copyFrom.listener, copyFrom.cancellableThreads, copyFrom.recoveryId,
            copyFrom.ensureClusterStateVersionCallback);
    }

    public RecoveryTarget(IndexShard indexShard, DiscoveryNode sourceNode, PeerRecoveryTargetService.RecoveryListener listener,
                          Callback<Long> ensureClusterStateVersionCallback) {
        this(indexShard, sourceNode, listener, new CancellableThreads(), idGenerator.incrementAndGet(), ensureClusterStateVersionCallback);
    }
    /**
     * creates a new recovery target object that represents a recovery to the provided indexShard
     *
     * @param indexShard local shard where we want to recover to
     * @param sourceNode source node of the recovery where we recover from
     * @param listener called when recovery is completed / failed
     * @param ensureClusterStateVersionCallback callback to ensure that the current node is at least on a cluster state with the provided
     *                                          version. Necessary for primary relocation so that new primary knows about all other ongoing
     *                                          replica recoveries when replicating documents (see {@link RecoverySourceHandler}).
     */
    private RecoveryTarget(IndexShard indexShard, DiscoveryNode sourceNode, PeerRecoveryTargetService.RecoveryListener listener,
                           CancellableThreads cancellableThreads, long recoveryId, Callback<Long> ensureClusterStateVersionCallback) {
        super("recovery_status");
        this.cancellableThreads = cancellableThreads;
        this.recoveryId = recoveryId;
        this.listener = listener;
        this.logger = Loggers.getLogger(getClass(), indexShard.indexSettings().getSettings(), indexShard.shardId());
        this.indexShard = indexShard;
        this.sourceNode = sourceNode;
        this.shardId = indexShard.shardId();
        this.tempFilePrefix = RECOVERY_PREFIX + UUIDs.base64UUID() + ".";
        this.store = indexShard.store();
        this.ensureClusterStateVersionCallback = ensureClusterStateVersionCallback;
        // make sure the store is not released until we are done.
        store.incRef();
        indexShard.recoveryStats().incCurrentAsTarget();
    }

    public long recoveryId() {
        return recoveryId;
    }

    public ShardId shardId() {
        return shardId;
    }

    public IndexShard indexShard() {
        ensureRefCount();
        return indexShard;
    }

    public DiscoveryNode sourceNode() {
        return this.sourceNode;
    }

    public RecoveryState state() {
        return indexShard.recoveryState();
    }

    public CancellableThreads CancellableThreads() {
        return cancellableThreads;
    }

    /** return the last time this RecoveryStatus was used (based on System.nanoTime() */
    public long lastAccessTime() {
        return lastAccessTime;
    }

    /** sets the lasAccessTime flag to now */
    public void setLastAccessTime() {
        lastAccessTime = System.nanoTime();
    }

    public Store store() {
        ensureRefCount();
        return store;
    }

    public RecoveryState.Stage stage() {
        return state().getStage();
    }

    /** renames all temporary files to their true name, potentially overriding existing files */
    public void renameAllTempFiles() throws IOException {
        ensureRefCount();
        store.renameTempFilesSafe(tempFileNames);
    }

    /**
     * Closes the current recovery target and returns a
     * clone to reset the ongoing recovery.
     * Note: the returned target must be canceled, failed or finished
     * in order to release all it's reference.
     */
    RecoveryTarget resetRecovery() throws IOException {
        ensureRefCount();
        if (finished.compareAndSet(false, true)) {
            // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now
            decRef();
        }
        indexShard.performRecoveryRestart();
        return new RecoveryTarget(this);
    }

    /**
     * cancel the recovery. calling this method will clean temporary files and release the store
     * unless this object is in use (in which case it will be cleaned once all ongoing users call
     * {@link #decRef()}
     *

     * if {@link #CancellableThreads()} was used, the threads will be interrupted.
     */
    public void cancel(String reason) {
        if (finished.compareAndSet(false, true)) {
            try {
                logger.debug("recovery canceled (reason: [{}])", reason);
                cancellableThreads.cancel(reason);
            } finally {
                // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now
                decRef();
            }
        }
    }

    /**
     * fail the recovery and call listener
     *
     * @param e                exception that encapsulating the failure
     * @param sendShardFailure indicates whether to notify the master of the shard failure
     */
    public void fail(RecoveryFailedException e, boolean sendShardFailure) {
        if (finished.compareAndSet(false, true)) {
            try {
                listener.onRecoveryFailure(state(), e, sendShardFailure);
            } finally {
                try {
                    cancellableThreads.cancel("failed recovery [" + ExceptionsHelper.stackTrace(e) + "]");
                } finally {
                    // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now
                    decRef();
                }
            }
        }
    }

    /** mark the current recovery as done */
    public void markAsDone() {
        if (finished.compareAndSet(false, true)) {
            assert tempFileNames.isEmpty() : "not all temporary files are renamed";
            try {
                // this might still throw an exception ie. if the shard is CLOSED due to some other event.
                // it's safer to decrement the reference in a try finally here.
                indexShard.postRecovery("peer recovery done");
            } finally {
                // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now
                decRef();
            }
            listener.onRecoveryDone(state());
        }
    }

    /** Get a temporary name for the provided file name. */
    public String getTempNameForFile(String origFile) {
        return tempFilePrefix + origFile;
    }

    public IndexOutput getOpenIndexOutput(String key) {
        ensureRefCount();
        return openIndexOutputs.get(key);
    }

    /** remove and {@link org.apache.lucene.store.IndexOutput} for a given file. It is the caller's responsibility to close it */
    public IndexOutput removeOpenIndexOutputs(String name) {
        ensureRefCount();
        return openIndexOutputs.remove(name);
    }

    /**
     * Creates an {@link org.apache.lucene.store.IndexOutput} for the given file name. Note that the
     * IndexOutput actually point at a temporary file.
     *

     * Note: You can use {@link #getOpenIndexOutput(String)} with the same filename to retrieve the same IndexOutput
     * at a later stage
     */
    public IndexOutput openAndPutIndexOutput(String fileName, StoreFileMetaData metaData, Store store) throws IOException {
        ensureRefCount();
        String tempFileName = getTempNameForFile(fileName);
        if (tempFileNames.containsKey(tempFileName)) {
            throw new IllegalStateException("output for file [" + fileName + "] has already been created");
        }
        // add first, before it's created
        tempFileNames.put(tempFileName, fileName);
        IndexOutput indexOutput = store.createVerifyingOutput(tempFileName, metaData, IOContext.DEFAULT);
        openIndexOutputs.put(fileName, indexOutput);
        return indexOutput;
    }

    @Override
    protected void closeInternal() {
        try {
            // clean open index outputs
            Iterator<Entry<String, IndexOutput>> iterator = openIndexOutputs.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, IndexOutput> entry = iterator.next();
                logger.trace("closing IndexOutput file [{}]", entry.getValue());
                try {
                    entry.getValue().close();
                } catch (Exception e) {
                    logger.debug(
                        (Supplier<?>) () -> new ParameterizedMessage("error while closing recovery output [{}]", entry.getValue()), e);
                }
                iterator.remove();
            }
            // trash temporary files
            for (String file : tempFileNames.keySet()) {
                logger.trace("cleaning temporary file [{}]", file);
                store.deleteQuiet(file);
            }
        } finally {
            // free store. increment happens in constructor
            store.decRef();
            indexShard.recoveryStats().decCurrentAsTarget();
        }
    }

    @Override
    public String toString() {
        return shardId + " [" + recoveryId + "]";
    }

    private void ensureRefCount() {
        if (refCount() <= 0) {
            throw new ElasticsearchException("RecoveryStatus is used but it's refcount is 0. Probably a mismatch between incRef/decRef " +
                    "calls");
        }
    }

    /*** Implementation of {@link RecoveryTargetHandler } */

    @Override
    public void prepareForTranslogOperations(int totalTranslogOps, long maxUnsafeAutoIdTimestamp) throws IOException {
        state().getTranslog().totalOperations(totalTranslogOps);
        indexShard().skipTranslogRecovery(maxUnsafeAutoIdTimestamp);
    }

    @Override
    public void finalizeRecovery(final long globalCheckpoint) {
        indexShard().updateGlobalCheckpointOnReplica(globalCheckpoint);
        final IndexShard indexShard = indexShard();
        indexShard.finalizeRecovery();
    }

    @Override
    public String getTargetAllocationId() {
        return indexShard().routingEntry().allocationId().getId();
    }

    @Override
    public void ensureClusterStateVersion(long clusterStateVersion) {
        ensureClusterStateVersionCallback.handle(clusterStateVersion);
    }

    @Override
    public void indexTranslogOperations(List<Translog.Operation> operations, int totalTranslogOps) throws TranslogRecoveryPerformer
            .BatchOperationException {
        final RecoveryState.Translog translog = state().getTranslog();
        translog.totalOperations(totalTranslogOps);
        assert indexShard().recoveryState() == state();
        indexShard().performBatchRecovery(operations);
    }

    @Override
    public void receiveFileInfo(List<String> phase1FileNames,
                                List<Long> phase1FileSizes,
                                List<String> phase1ExistingFileNames,
                                List<Long> phase1ExistingFileSizes,
                                int totalTranslogOps) {
        final RecoveryState.Index index = state().getIndex();
        for (int i = 0; i < phase1ExistingFileNames.size(); i++) {
            index.addFileDetail(phase1ExistingFileNames.get(i), phase1ExistingFileSizes.get(i), true);
        }
        for (int i = 0; i < phase1FileNames.size(); i++) {
            index.addFileDetail(phase1FileNames.get(i), phase1FileSizes.get(i), false);
        }
        state().getTranslog().totalOperations(totalTranslogOps);
        state().getTranslog().totalOperationsOnStart(totalTranslogOps);

    }

    @Override
    public void cleanFiles(int totalTranslogOps, Store.MetadataSnapshot sourceMetaData) throws IOException {
        state().getTranslog().totalOperations(totalTranslogOps);
        // first, we go and move files that were created with the recovery id suffix to
        // the actual names, its ok if we have a corrupted index here, since we have replicas
        // to recover from in case of a full cluster shutdown just when this code executes...
        renameAllTempFiles();
        final Store store = store();
        try {
            store.cleanupAndVerify("recovery CleanFilesRequestHandler", sourceMetaData);
        } catch (CorruptIndexException | IndexFormatTooNewException | IndexFormatTooOldException ex) {
            // this is a fatal exception at this stage.
            // this means we transferred files from the remote that have not be checksummed and they are
            // broken. We have to clean up this shard entirely, remove all files and bubble it up to the
            // source shard since this index might be broken there as well? The Source can handle this and checks
            // its content on disk if possible.
            try {
                try {
                    store.removeCorruptionMarker();
                } finally {
                    Lucene.cleanLuceneIndex(store.directory()); // clean up and delete all files
                }
            } catch (Exception e) {
                logger.debug("Failed to clean lucene index", e);
                ex.addSuppressed(e);
            }
            RecoveryFailedException rfe = new RecoveryFailedException(state(), "failed to clean after recovery", ex);
            fail(rfe, true);
            throw rfe;
        } catch (Exception ex) {
            RecoveryFailedException rfe = new RecoveryFailedException(state(), "failed to clean after recovery", ex);
            fail(rfe, true);
            throw rfe;
        }
    }

    @Override
    public void writeFileChunk(StoreFileMetaData fileMetaData, long position, BytesReference content,
                               boolean lastChunk, int totalTranslogOps) throws IOException {
        final Store store = store();
        final String name = fileMetaData.name();
        state().getTranslog().totalOperations(totalTranslogOps);
        final RecoveryState.Index indexState = state().getIndex();
        IndexOutput indexOutput;
        if (position == 0) {
            indexOutput = openAndPutIndexOutput(name, fileMetaData, store);
        } else {
            indexOutput = getOpenIndexOutput(name);
        }
        BytesRefIterator iterator = content.iterator();
        BytesRef scratch;
        while((scratch = iterator.next()) != null) { // we iterate over all pages - this is a 0-copy for all core impls
            indexOutput.writeBytes(scratch.bytes, scratch.offset, scratch.length);
        }
        indexState.addRecoveredBytesToFile(name, content.length());
        if (indexOutput.getFilePointer() >= fileMetaData.length() || lastChunk) {
            try {
                Store.verify(indexOutput);
            } finally {
                // we are done
                indexOutput.close();
            }
            final String temporaryFileName = getTempNameForFile(name);
            assert Arrays.asList(store.directory().listAll()).contains(temporaryFileName) :
                "expected: [" + temporaryFileName + "] in " + Arrays.toString(store.directory().listAll());
            store.directory().sync(Collections.singleton(temporaryFileName));
            IndexOutput remove = removeOpenIndexOutputs(name);
            assert remove == null || remove == indexOutput; // remove maybe null if we got finished
        }
    }
}


text:
package net.bitpot.railways.utils;

import com.intellij.execution.ExecutionModes;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import net.bitpot.railways.gui.ErrorInfoDlg;
import net.bitpot.railways.gui.StringFormatter;
import net.bitpot.railways.models.Route;
import net.bitpot.railways.models.RouteList;
import net.bitpot.railways.routesView.RoutesManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.ruby.gem.RubyGemExecutionContext;
import org.jetbrains.plugins.ruby.rails.model.RailsApp;

/**
 * Class that contains all API methods for Railways plugin.
 */
public class RailwaysUtils {
    @SuppressWarnings("unused")
    private final static Logger log = Logger.getInstance(RailwaysUtils.class.getName());

    public final static StringFormatter STRIP_REQUEST_FORMAT = RailwaysUtils::stripRequestFormat;

    /**
     * Returns true if specified project has at least one Ruby on Rails module.
     *
     * @param project Project which should be checked for Rails modules.
     * @return True if a project has at least one Ruby on Rails module.
     */
    public static boolean hasRailsModules(Project project) {
        Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module m : modules)
            if (RailsApp.fromModule(m) != null)
                return true;

        return false;
    }

    /**
     * Internally used method that runs rake task and gets its output. This
     * method should be called from backgroundable task.
     *
     * @param module Rails module for which rake task should be run.
     * @return Output of 'rake routes'.
     */
    @Nullable
    public static ProcessOutput queryRakeRoutes(Module module,
                                                String routesTaskName, String railsEnv) {
        // Get root path of Rails application from module.
        RailsApp app = RailsApp.fromModule(module);
        if ((app == null) || (app.getRailsApplicationRoot() == null))
            return null;

        String moduleContentRoot = app.getRailsApplicationRoot().getPresentableUrl();

        ModuleRootManager mManager = ModuleRootManager.getInstance(module);
        Sdk sdk = mManager.getSdk();
        if (sdk == null) {
            Notifications.Bus.notify(new Notification("Railways",
                    "Railways error",
                    "Cannot update route list for '" + module.getName() +
                    "' module, because its SDK is not set",
                    NotificationType.ERROR)
                    , module.getProject());
            return null;
        }

        try {
            railsEnv = (railsEnv == null) ? "" : "RAILS_ENV=" + railsEnv;

            // Will work on IntelliJ platform since 2017.3
            return RubyGemExecutionContext.create(sdk, "rails")
                    .withModule(module)
                    .withWorkingDirPath(moduleContentRoot)
                    .withExecutionMode(new ExecutionModes.SameThreadMode())
                    .withArguments(routesTaskName, "--trace", railsEnv)
                    .executeScript();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * Shows a dialog with 'rake routes' error stacktrace.
     *
     * @param routesManager RoutesManager which error stacktrace should be
     *                      displayed.
     */
    public static void showErrorInfo(@NotNull RoutesManager routesManager) {
        ErrorInfoDlg.showError("Error information:",
                routesManager.getParseErrorStackTrace());
    }

    /**
     * Invokes action with specified ID. This method provides very simple
     * implementation of invoking action manually when ActionEvent and
     * DataContext are unavailable. Created DataContext in this method provides
     * only CommonDataKeys.PROJECT value.
     *
     * @param actionId ID of action to invoke
     * @param project Current project
     */
    public static void invokeAction(String actionId, final Project project) {
        AnAction act = ActionManager.getInstance().getAction(actionId);

        // For simple actions which don't heavily use data context, we can create
        // it manually.
        DataContext dataContext = dataId -> {
            if (CommonDataKeys.PROJECT.is(dataId))
                return project;

            return null;
        };

        act.actionPerformed(new AnActionEvent(null, dataContext,
                ActionPlaces.UNKNOWN, act.getTemplatePresentation(),
                ActionManager.getInstance(), 0));
    }

    public static void updateActionsStatus(Module module, RouteList routeList) {
        RailsApp app = RailsApp.fromModule(module);
        if ((app == null) || (DumbService.isDumb(module.getProject())))
            return;

        // TODO: investigate multiple calls of this method when switching focus from code to tool window without any changes.

        for (Route route: routeList)
            route.updateActionStatus(app);
    }

    private final static String FORMAT_STR = "(.:format)";

    @NotNull
    public static String stripRequestFormat(@NotNull String routePath) {
        int endIndex = routePath.length() - FORMAT_STR.length();
        if (routePath.indexOf(FORMAT_STR) == endIndex)
            return routePath.substring(0, endIndex);

        return routePath;
    }

}


text:
package us.monoid.psql.async.message;

public class BackendKeyData extends BackendMessage {

	public int getProcessID() {
		return buffer.getInt(5);
	}

	public int getSecretKey() {
		return buffer.getInt(9);
	}
}


text:
package org.pac4j.oauth.client;

import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.pac4j.core.client.Client;
import org.pac4j.core.profile.Gender;
import org.pac4j.core.profile.ProfileHelper;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.oauth.profile.windowslive.WindowsLiveProfile;

import com.esotericsoftware.kryo.Kryo;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

/**
 * This class tests the {@link WindowsLiveClient} class by simulating a complete authentication.
 *
 * @author Jerome Leleu
 * @since 1.1.0
 */
public class WindowsLiveClientIT extends OAuthClientIT {

    @Override
    protected boolean isJavascriptEnabled() {
        return true;
    }

    @SuppressWarnings("rawtypes")
    @Override
    protected Client getClient() {
        final WindowsLiveClient liveClient = new WindowsLiveClient();
        liveClient.setKey("00000000400BFE75");
        liveClient.setSecret("9yz0WtTIUQVV7HhBV2tccTziETOt4pRG");
        liveClient.setCallbackUrl(PAC4J_URL);
        return liveClient;
    }

    @Override
    protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage) throws Exception {
        final HtmlTextInput login = authorizationPage.getElementByName("login");
        login.setValueAttribute("testscribeup@gmail.com");
        final HtmlPasswordInput password = authorizationPage.getElementByName("passwd");
        password.setValueAttribute("testpwdscribe12");
        final HtmlSubmitInput submit = authorizationPage.getElementByName("SI");
        final HtmlPage callbackPage = submit.click();
        final String callbackUrl = callbackPage.getUrl().toString();
        logger.debug("callbackUrl : {}", callbackUrl);
        return callbackUrl;
    }

    @Override
    protected void registerForKryo(final Kryo kryo) {
        kryo.register(WindowsLiveProfile.class);
    }

    @Override
    protected void verifyProfile(final UserProfile userProfile) {
        final WindowsLiveProfile profile = (WindowsLiveProfile) userProfile;
        logger.debug("userProfile : {}", profile);
        assertEquals("416c383b220392d8", profile.getId());
        assertEquals(WindowsLiveProfile.class.getSimpleName() + UserProfile.SEPARATOR + "416c383b220392d8",
                     profile.getTypedId());
        assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), WindowsLiveProfile.class));
        assertTrue(StringUtils.isNotBlank(profile.getAccessToken()));
        assertCommonProfile(userProfile, null, "Test", "ScribeUP", "Test ScribeUP", null, Gender.UNSPECIFIED,
                            Locale.FRANCE, null, "https://profile.live.com/", null);
        assertNotNull(profile.getUpdatedTime());
        assertEquals(7, profile.getAttributes().size());
    }
}


text:
    <meta charset="UTF-8">
    <title data-lift="Menu.title">App: </title>
    <link href="static/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/css/spa.css" rel="stylesheet">

            Home
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">

            </button>

                    Page 1

                    Page 2

                    Page 3

Login

Register

Lift Single Page Application (SPA) Demo

What do you think?

The main content will get bound here


text:
trait Cloning {
  trait Foo
  def fn(g: Any => Unit): Foo

  abstract class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo }

  implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null }

  val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 }
}


text:
{% for location in locations %}

            <input class="location" type="radio" value="{{ location }}" name="location"> {{ location }}

{% else %}

        No location found.

{% endfor %}


text:
import React, {ComponentType} from 'react'
import internalRouterContextTypeCheck from './internalRouterContextTypeCheck'
import {HOCRouter, InternalRouter} from './types'

const NO_CONTEXT_STATE = {
  state: {},
  navigate: (state: any) => {
    throw new Error(
      `Cannot navigate to the state ${JSON.stringify(state)}. No router found in context`
    )
  },
  navigateIntent: (intentName: string) => {
    throw new Error(`Cannot navigate to the intent ${intentName}. No router found in context`)
  },
}

export default function withRouterHOC<Props>(
  Component: ComponentType<Props & {router: HOCRouter}>
) {
  return class WithRouter extends React.Component<Props> {
    static displayName = `withRouter(${Component.displayName || Component.name})`
    unsubscribe: (() => void) | null = null

    state = {
      routerState: {},
    }

    context: {
      __internalRouter?: InternalRouter
    } | null = null

    static contextTypes = {
      __internalRouter: internalRouterContextTypeCheck,
    }

    constructor(props, context) {
      super(props)

      const __internalRouter = context.__internalRouter

      if (__internalRouter) {
        this.state = {routerState: __internalRouter.getState()}
      }
    }

    // eslint-disable-next-line camelcase
    UNSAFE_componentWillMount() {
      if (!this.context) throw new Error('WithRouter: missing context value')

      const __internalRouter = this.context.__internalRouter
      if (!__internalRouter) {
        return
      }
      this.unsubscribe = __internalRouter.channel.subscribe(() => {
        this.setState({routerState: __internalRouter.getState()})
      })
    }

    componentWillUnmount() {
      if (this.unsubscribe) this.unsubscribe()
    }

    render() {
      if (!this.context) throw new Error('WithRouter: missing context value')

      const internalRouter = this.context.__internalRouter

      const router: HOCRouter = internalRouter
        ? {
            state: this.state.routerState,
            navigate: internalRouter.navigate,
            navigateIntent: internalRouter.navigateIntent,
          }
        : NO_CONTEXT_STATE

      return <Component {...this.props} router={router} />
    }
  }
}


text:
using DSA.DataStructures.Graphs;
using DSA.DataStructures.Interfaces;
using DSA.DataStructures.Queues;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DSA.Algorithms.Graphs
{
    /// <summary>
    /// A static class containing extension methods for minimum spanning tree finding using Prim's algorithm.
    /// </summary>
    public static class PrimMSTFinder
    {
        /// <summary>
        /// Uses Prim's algorithm to find the minimum spanning tree of the undirected weighted graph. Returns a <see cref="WeightedALGraph{TVertex, TWeight}"/> representing the MST.
        /// </summary>
        /// <typeparam name="TVertex">The data type of the vertices. TVertex implements <see cref="IComparable{T}"/>.</typeparam>
        /// <typeparam name="TWeight">The data type of weight of the edges. TWeight implements <see cref="IComparable{T}"/>.</typeparam>
        /// <param name="graph">The graph structure that implements <see cref="IWeightedGraph{TVertex, TWeight}"/>.</param>
        /// <returns>Returns a <see cref="WeightedALGraph{TVertex, TWeight}"/> representing the MST.</returns>
        public static WeightedALGraph<TVertex, TWeight> PrimMST<TVertex, TWeight>(this IWeightedGraph<TVertex, TWeight> graph)
            where TVertex : IComparable<TVertex>
            where TWeight : IComparable<TWeight>
        {
            if (graph.IsDirected)
                throw new ArgumentException("Graph is directed!");

            var mst = new WeightedALGraph<TVertex, TWeight>();

            // A hash set of the added vertices to the MST
            var addedVertices = new HashSet<TVertex>();
            // Comparer for the kvp in the priority queue
            var kvpComparer = Comparer<KeyValuePair<TWeight, KeyValuePair<TVertex, TVertex>>>.Create((x, y) =>
            {
                int cmp = 0;
                // null checking because TWeight can be null
                if (x.Key == null)
                {
                    if (y.Key == null) cmp = -1; // change cmp to skip next comparisons
                    else return int.MinValue;
                }

                if (cmp == 0)// if x.Key and y.Key are not null
                {
                    if (y.Key == null) return int.MaxValue;
                    // normal check if both weights are not null
                    cmp = x.Key.CompareTo(y.Key);
                }
                else cmp = 0;// if x.Key and y.Key were both null, compare the kvp value

                if (cmp == 0) cmp = x.Value.Key.CompareTo(y.Value.Key);
                if (cmp == 0) cmp = x.Value.Value.CompareTo(y.Value.Value);
                return cmp;
            });
            // Priority queue of the edges for computing. Having the weight as key and as value - another kvp with source vertex as key and destination vertex as value.
            var priorityQueue = new MinPriorityQueue<TWeight, KeyValuePair<TVertex, TVertex>>(kvpComparer);

            var vertices = graph.Vertices.ToList();
            if (vertices.Count == 0) return mst;
            int verticesIndex = 0;

            mst.AddVertices(vertices);

            // Add dummy edge to the priority queue
            priorityQueue.Enqueue(default(TWeight), new KeyValuePair<TVertex, TVertex>(vertices[verticesIndex], vertices[verticesIndex]));
            addedVertices.Add(vertices[verticesIndex]);

            while (priorityQueue.Count > 0)
            {
                var curKVP = priorityQueue.Dequeue();
                TVertex curSourceVertex = curKVP.Value.Key;
                TVertex curDestinationVertex = curKVP.Value.Value;

                // If the destination verex of the edge is not added we add the edge
                if (!addedVertices.Contains(curDestinationVertex))
                {
                    mst.AddEdge(curSourceVertex, curDestinationVertex, curKVP.Key);
                    addedVertices.Add(curDestinationVertex);
                }

                foreach (var edge in graph.OutgoingEdgesSorted(curDestinationVertex))
                {
                    var edgeDestination = edge.Destination;
                    var edgeWeight = edge.Weight;

                    // If the destination vertex is added to the MST we skip it
                    if (addedVertices.Contains(edgeDestination))
                        continue;

                    // Add the edge for computing
                    priorityQueue.Enqueue(edgeWeight, new KeyValuePair<TVertex, TVertex>(curDestinationVertex, edgeDestination));
                }

                // If priority queue is empty
                if (priorityQueue.Count == 0)
                {
                    // Check if all vertices of the graph were added to the MST
                    if (addedVertices.Count != vertices.Count)
                    {
                        // If not we have a forest.
                        // Add the next non added vertex
                        while (verticesIndex < vertices.Count)
                        {
                            if (!addedVertices.Contains(vertices[verticesIndex]))
                            {
                                // Add dummy edge to the priority queue
                                priorityQueue.Enqueue(default(TWeight), new KeyValuePair<TVertex, TVertex>(vertices[verticesIndex], vertices[verticesIndex]));
                                addedVertices.Add(vertices[verticesIndex]);

                                break;
                            }
                            verticesIndex++;
                        }
                    }
                }
            }

            // Return MST
            return mst;
        }
    }
}


text:
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}

namespace crash_reporter {

class CrashReporterWin : public CrashReporter {
 public:
  static CrashReporterWin* GetInstance();

  void InitBreakpad(const std::string& product_name,
                    const std::string& version,
                    const std::string& company_name,
                    const std::string& submit_url,
                    const base::FilePath& crashes_dir,
                    bool upload_to_server,
                    bool skip_system_crash_handler) override;
  void SetUploadParameters() override;

  // Crashes the process after generating a dump for the provided exception.
  int CrashForException(EXCEPTION_POINTERS* info);

 private:
  friend struct base::DefaultSingletonTraits<CrashReporterWin>;

  CrashReporterWin();
  ~CrashReporterWin() override;

  static bool FilterCallback(void* context,
                             EXCEPTION_POINTERS* exinfo,
                             MDRawAssertionInfo* assertion);

  static bool MinidumpCallback(const wchar_t* dump_path,
                               const wchar_t* minidump_id,
                               void* context,
                               EXCEPTION_POINTERS* exinfo,
                               MDRawAssertionInfo* assertion,
                               bool succeeded);

  // Returns the custom info structure based on parameters.
  google_breakpad::CustomClientInfo* GetCustomInfo(
      const std::string& product_name,
      const std::string& version,
      const std::string& company_name,
      bool upload_to_server);

  // Custom information to be passed to crash handler.
  std::vector<google_breakpad::CustomInfoEntry> custom_info_entries_;
  google_breakpad::CustomClientInfo custom_info_;

  bool skip_system_crash_handler_ = false;
#ifdef _WIN64
  bool code_range_registered_ = false;
#endif
  std::unique_ptr<google_breakpad::ExceptionHandler> breakpad_;

  DISALLOW_COPY_AND_ASSIGN(CrashReporterWin);
};

}  // namespace crash_reporter

#endif  // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_WIN_H_


text:
/**
 * Created by Administrator on 2/24/2017.
 */

var mongoDB = require('mongodb').MongoClient,
    ObjectId = require('mongodb').ObjectID;

var bookController = function (bookService, nav) {

    var getIndex = function (req, res) {

        var bookurl = 'mongodb://localhost:27017/libraryApp';
        mongoDB.connect(bookurl, function (err, db) {

            var collection = db.collection('books');
            collection.find({})
                .toArray(function (err, result) {
                    res.render('books', {
                        title: 'Books',
                        nav: nav,
                        books: result
                    });
                });

        });
    };

    var getById = function (req, res) {
        var singleBook = 'mongodb://localhost:27017/libraryApp';
        var id = new ObjectId(req.params.id);

        mongoDB.connect(singleBook, function (err, db) {

            var collection = db.collection('books');
            collection.findOne({_id: id},
                function (err, result) {
                    if(result.bookId){
                        bookService.getBookById(result.bookId,
                            function (err, book) {
                                result.book = book;
                                res.render('book', {
                                    title: 'Book',
                                    nav: nav,
                                    book: result
                                });
                            });
                    }else{
                        res.render('bookView',{
                            title: 'Book',
                            nav: nav,
                            book: result
                        })
                    }

                });
        });

    };

    var middleware = function (req, res, next) {
        //if(!req.user){
        //    res.redirect('/');
        //}
        next();
    };

    return {
        getIndex: getIndex,
        getById: getById,
        middleware: middleware
    };
};

module.exports = bookController;


text:
using Konscious.Security.Cryptography;
using System;
using System.Text;
using BenchmarkDotNet.Attributes;
using System.Threading.Tasks;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Diagnosers;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Diagnostics.Windows.Configs;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Jobs;

namespace ArgonBenchmarks
{
    internal class Program
    {
        public static void Main()
        {
            BenchmarkRunner.Run<ArgonBenchmarks>();
        }
    }

    [MemoryDiagnoser]
    [SimpleJob(RuntimeMoniker.Net462)]
    [SimpleJob(RuntimeMoniker.Net60)]
    [JsonExporterAttribute.BriefCompressed, CsvExporter(BenchmarkDotNet.Exporters.Csv.CsvSeparator.CurrentCulture)]
    public class ArgonBenchmarks
    {
        private readonly string _toHash = "iamapasswordthatneedshashing";
        private Argon2id _argon;

        [Benchmark]
        public async Task<byte[]> GetHashAsync()
        {
            return await _argon.GetBytesAsync(128);
        }

        [IterationSetup]
        public void IterationSetup()
        {
            _argon = new Argon2id(Encoding.UTF8.GetBytes(_toHash))
            {
                DegreeOfParallelism = 4,
                Iterations = Iterations,
                MemorySize = RamKilobytes,
                Salt = Guid.NewGuid().ToByteArray()
            };
        }

        [ParamsSource(nameof(IterationValues))]
        public int Iterations { get; set; }

        [ParamsSource(nameof(RamKilobytesValues))]
        public int RamKilobytes { get; set; }

        //CN - Full
        public IEnumerable<int> RamKilobytesValues => Enumerable.Range(0, 16)
            .Select(x => x * 1024 * 4 + 65536)
            .Concat(new[] { 1048576, 4 * 1048576 });

        //CN -- Quick
        //public IEnumerable<int> RamKilobytesValues => Enumerable.Range(0, 4).Select(x => x * 1024 * 8 + 65536);

        //CN -- Full
        public IEnumerable<int> IterationValues => Enumerable.Range(1, 5).Select(x => 2*x - 1);

        //CN -- Quick
        //public IEnumerable<int> IterationValues => Enumerable.Range(1, 2).Select(x => x + (x - 1) * 4);
    }

    [MemoryDiagnoser, ThreadingDiagnoser]
    public class BlitMarks
    {
        private readonly byte[] _toBlitWithBytes = new byte[64];
        private readonly byte[] _bytes = new byte[128 * 8 * 1024];
        private ulong[] _longs;

        private static readonly Random _random = new Random();

        [Benchmark]
        public void Blit()
        {
            for (var i = 1; i < 100_000_000; i++)
            {
                _longs.AsSpan().Blit(_toBlitWithBytes);
            }
        }

        [IterationSetup]
        public void IterationSetup()
        {
            _random.NextBytes(_bytes);
            _longs = MemoryMarshal.Cast<byte, ulong>(_bytes).ToArray();
            _random.NextBytes(_toBlitWithBytes);
        }
    }
}


text:
<?php
namespace yiiunit\framework\helpers;

use yii\helpers\StringHelper;
use yiiunit\TestCase;

/**
 * StringHelperTest
 * @group helpers
 */
class StringHelperTest extends TestCase
{
	public function testStrlen()
	{
		$this->assertEquals(4, StringHelper::byteLength('this'));
		$this->assertEquals(6, StringHelper::byteLength('это'));
	}

	public function testSubstr()
	{
		$this->assertEquals('th', StringHelper::byteSubstr('this', 0, 2));
		$this->assertEquals('э', StringHelper::byteSubstr('это', 0, 2));
	}

	public function testBasename()
	{
		$this->assertEquals('', StringHelper::basename(''));

		$this->assertEquals('file', StringHelper::basename('file'));
		$this->assertEquals('file.test', StringHelper::basename('file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('file.test', '.test'));

		$this->assertEquals('file', StringHelper::basename('/file'));
		$this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('/file.test', '.test'));

		$this->assertEquals('file', StringHelper::basename('/path/to/file'));
		$this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test'));

		$this->assertEquals('file', StringHelper::basename('\file'));
		$this->assertEquals('file.test', StringHelper::basename('\file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('\file.test', '.test'));

		$this->assertEquals('file', StringHelper::basename('C:\file'));
		$this->assertEquals('file.test', StringHelper::basename('C:\file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('C:\file.test', '.test'));

		$this->assertEquals('file', StringHelper::basename('C:\path\to\file'));
		$this->assertEquals('file.test', StringHelper::basename('C:\path\to\file.test', '.test2'));
		$this->assertEquals('file', StringHelper::basename('C:\path\to\file.test', '.test'));

		// mixed paths
		$this->assertEquals('file.test', StringHelper::basename('/path\to/file.test'));
		$this->assertEquals('file.test', StringHelper::basename('/path/to\file.test'));
		$this->assertEquals('file.test', StringHelper::basename('\path/to\file.test'));

		// \ and / in suffix
		$this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st'));
		$this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\st'));
		$this->assertEquals('file', StringHelper::basename('/path/to/filete\st', 'te\st'));
		$this->assertEquals('st', StringHelper::basename('/path/to/filete\st', 'te/st'));

		// http://www.php.net/manual/en/function.basename.php#72254
		$this->assertEquals('foo', StringHelper::basename('/bar/foo/'));
		$this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\'));
	}
}


text:
import Solidran.Rna.Detail (dnaToRna)

main :: IO ()
main = getLine >>= (putStr . dnaToRna)


text:
<?php

use yii\db\Schema;
use yii\db\Migration;

class m151124_171726_subject_table extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%subject}}', [
            'id' => $this->primaryKey(),
            'name' => $this->string()->notNull(),
            'position' => $this->string()->notNull(),
            'nominal' => $this->double()->notNull(),
            'shortfall_penalty' => $this->integer()->notNull(),
            'penalty' => $this->double()->notNull(),
            'disenfranchisement' => $this->text()->notNull(),
            'progress_id' => $this->integer()->notNull(),
            'agenda_id' => $this->integer()->notNull(),
            'status_id' => $this->integer()->notNull(),
        ], $tableOptions);
    }

    public function down()
    {
        $this->dropTable('{{%subject}}');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}


text:
<?php

namespace Kwejk\UserBundle\Form\Type\User;

use Admingenerated\KwejkUserBundle\Form\BaseUserType\FiltersType as BaseFiltersType;

/**
 * FiltersType
 */
class FiltersType extends BaseFiltersType
{
}


text:
import { navigate } from "app/navigation/navigate"
import { Schema } from "app/utils/track"
import { Flex, Text } from "palette"
import { TouchableOpacity } from "react-native"
import { useTracking } from "react-tracking"
import styled from "styled-components/native"

interface BMWSponsorshipProps {
  url?: string
  logoText?: string
  pressable?: boolean
}
export const BMWSponsorship: React.FC<BMWSponsorshipProps> = ({
  logoText = "In Partnership with BMW",
  url,
  pressable = true,
}) => {
  const tracking = useTracking()
  const view = (
    <Flex flexDirection="row" alignItems="center" mb={2}>
      <Logo
        resizeMode="contain"
        source={require("images/bmw-logo.webp")}
        style={{ marginRight: 10 }}
      />
      <Text color="black60">{logoText}</Text>
    </Flex>
  )

  if (!pressable) {
    return view
  }

  return (
    <TouchableOpacity
      onPress={() => {
        navigate(url || "https://www.bmw-arts-design.com/bmw_art_guide")

        tracking.trackEvent({
          action_name: Schema.ActionNames.BMWLogo,
          action_type: Schema.ActionTypes.Tap,
        })
      }}
    >
      {view}
    </TouchableOpacity>
  )
}

export const Logo = styled.Image`
  height: 32;
  width: 32;
`


text:
#ifndef _SCHED_H
#define _SCHED_H

#undef PTW32_LEVEL

#if defined(_POSIX_SOURCE)
#define PTW32_LEVEL 0
/* Early POSIX */
#endif

#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
#undef PTW32_LEVEL
#define PTW32_LEVEL 1
/* Include 1b, 1c and 1d */
#endif

#if defined(INCLUDE_NP)
#undef PTW32_LEVEL
#define PTW32_LEVEL 2
/* Include Non-Portable extensions */
#endif

#define PTW32_LEVEL_MAX 3

#if !defined(PTW32_LEVEL)
#define PTW32_LEVEL PTW32_LEVEL_MAX
/* Include everything */
#endif

#if __GNUC__ && ! defined (__declspec)
# error Please upgrade your GNU compiler to one that supports __declspec.
#endif

/*
 * When building the DLL code, you should define PTW32_BUILD so that
 * the variables/functions are exported correctly. When using the DLL,
 * do NOT define PTW32_BUILD, and then the variables/functions will
 * be imported correctly.
 */
#ifndef PTW32_STATIC_LIB
#  ifdef PTW32_BUILD
#    define PTW32_DLLPORT __declspec (dllexport)
#  else
#    define PTW32_DLLPORT __declspec (dllimport)
#  endif
#else
#  define PTW32_DLLPORT
#endif

/*
 * This is a duplicate of what is in the autoconf config.h,
 * which is only used when building the pthread-win32 libraries.
 */

#ifndef PTW32_CONFIG_H
#  if defined(WINCE)
#    define NEED_ERRNO
#    define NEED_SEM
#  endif
#  if defined(_UWIN) || defined(__MINGW32__)
#    define HAVE_MODE_T
#  endif
#endif

/*
 *
 */

#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
#include "need_errno.h"
#else
#include <errno.h>
#endif
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */

#if defined(__MINGW32__) || defined(_UWIN)
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
/* For pid_t */
#  include <sys/types.h>
/* Required by Unix 98 */
#  include <time.h>
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#else
typedef int pid_t;
#endif

/* Thread scheduling policies */

enum {
  SCHED_OTHER = 0,
  SCHED_FIFO,
  SCHED_RR,
  SCHED_MIN   = SCHED_OTHER,
  SCHED_MAX   = SCHED_RR
};

struct sched_param {
  int sched_priority;
};

#ifdef __cplusplus
extern "C"
{
#endif                          /* __cplusplus */

PTW32_DLLPORT int __cdecl sched_yield (void);

PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);

PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);

PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);

PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);

/*
 * Note that this macro returns ENOTSUP rather than
 * ENOSYS as might be expected. However, returning ENOSYS
 * should mean that sched_get_priority_{min,max} are
 * not implemented as well as sched_rr_get_interval.
 * This is not the case, since we just don't support
 * round-robin scheduling. Therefore I have chosen to
 * return the same value as sched_setscheduler when
 * SCHED_RR is passed to it.
 */
#define sched_rr_get_interval(_pid, _interval) \
  ( errno = ENOTSUP, (int) -1 )

#ifdef __cplusplus
}                               /* End of extern "C" */
#endif                          /* __cplusplus */

#undef PTW32_LEVEL
#undef PTW32_LEVEL_MAX

#endif                          /* !_SCHED_H */


text:
@interface GRPlayer : NSObject

@property (nonatomic, strong) NSString *playerId;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *emailHash;
@property (nonatomic) NSInteger totalPointsAchievement;
@property (nonatomic, strong) NSString *locale;
@property (nonatomic, strong) NSDictionary *dynProp;

- (id)initWithDictionary:(NSDictionary*)player;

@end


text:
define([
    'agrc/widgets/map/BaseMap',

    'app/config',
    'app/Router',

    'dijit/Destroyable',

    'dojo/dom-style',
    'dojo/hash',
    'dojo/io-query',
    'dojo/topic',
    'dojo/_base/declare',
    'dojo/_base/lang',

    'esri/geometry/Extent',
    'esri/geometry/Point',
    'esri/graphic',
    'esri/layers/ArcGISDynamicMapServiceLayer',

    'layer-selector/LayerSelector',

    'proj4'
], function (
    BaseMap,

    config,
    Router,

    Destroyable,

    domStyle,
    hash,
    ioQuery,
    topic,
    declare,
    lang,

    Extent,
    Point,
    Graphic,
    ArcGISDynamicMapServiceLayer,

    LayerSelector,

    proj4
) {
    var MC = declare([Destroyable], {
        // map: BaseMap
        map: null,

        // dLayers: Object
        //      dynamic layers
        dLayers: {},

        // childWidgets: Object[]
        childWidgets: [],

        initMap: function (mapDiv) {
            // summary:
            //      Sets up the map
            console.info('app/mapController:initMap', arguments);

            // switch out UTM for web mercator coords, if exists
            hash(this.checkForUTMCoords(hash()));

            this.map = new BaseMap(mapDiv, {
                useDefaultBaseMap: false,
                extent: new Extent({
                    xmax: -12423300.906798368,
                    xmin: -12494387.343103563,
                    ymax: 4998590.4098829115,
                    ymin: 4923452.811078603,
                    spatialReference: {
                        wkid: 3857
                    }
                }),
                router: true,
                showLabels: true
            });

            this.childWidgets.push(
                new LayerSelector({
                    map: this.map,
                    quadWord: config.quadWord,
                    baseLayers: ['Terrain', 'Hybrid', 'Lite', 'Topo'],
                    overlays: ['Address Points', {
                        Factory: ArcGISDynamicMapServiceLayer,
                        url: config.urls.landOwnership,
                        id: 'Land Ownership',
                        opacity: 0.5
                    }],
                    right: false
                })
            );
            this.childWidgets.push(this.map);

            // force map to auto height
            // required for proper alignment in firefox
            domStyle.set(mapDiv, 'height', 'auto');
            this.map.resize();

            var that = this;
            this.own(
                topic.subscribe(config.topics.addLayer,
                    lang.hitch(this, 'addLayer')),
                topic.subscribe(config.topics.layer.toggleDynamicLayer,
                    lang.hitch(this, 'toggleDynamicLayer')),
                topic.subscribe(config.topics.slider.change,
                    lang.hitch(this, 'onSliderChange')),
                topic.subscribe('agrc.widgets.locate.FindAddress.OnFindStart',
                    lang.hitch(that.map.graphics, 'clear')),
                this.map.on('click', lang.hitch(this, 'onMapClick'))
            );
            setTimeout(function () {
                new Router();
            }, 100);
        },
        checkForUTMCoords: function (urlHash) {
            // summary:
            //      projects utm coords to web mercator if needed
            // urlHash: String
            //      The current URL hash
            // returns: String
            //      The updated (if needed) URL hash
            console.log('app/mapController:checkForUTMCoords', arguments);

            // return hash untouched if missing x, y or scale coords or if they are already
            // in web mercator
            var params = ioQuery.queryToObject(urlHash);
            if (!(params.x && params.y && params.scale) || parseInt(params.x, 10) < 0) {
                return urlHash;
            }

            // project to web mercator and return updated hash
            var utm = '+proj=utm +zone=12 +ellps=GRS80 +datum=NAD83 +units=m +no_defs';
            var coords = proj4(utm, proj4('EPSG:3857'), [parseInt(params.x), parseInt(params.y)]);
            params.x = coords[0];
            params.y = coords[1];

            return ioQuery.objectToQuery(params);
        },
        addLayer: function (lyr, bottom) {
            // summary:
            //      description
            // lyr: Layer
            // bottom: Boolean
            console.log('app/mapController:addLayer', arguments);

            var index = (bottom) ? 1 : undefined;
            this.map.addLayer(lyr, index);
            this.map.addLoaderToLayer(lyr);
        },
        toggleDynamicLayer: function (layerId, show, groupName, defaultOpacity, isRadio, layerType) {
            // summary:
            //      sets the appropriate visible layers on the dynamic service
            // layerId: String
            //      The id (or id's separated by a comma)
            // show: Boolean
            // groupName: String
            // defaultOpacity: Number
            // isRadio: Boolean
            //      Determines if more than one layer can be shown at a time in a group
            // layerType: String
            console.log('app/mapController:toggleDynamicLayer', arguments);

            if (layerType !== 'dynamic' && groupName && this.dLayers[groupName]) {
                this.dLayers[groupName].setVisibleLayers([-1]);
                return;
            }

            var dLayer;
            var that = this;
            if (!this.dLayers[groupName]) {
                dLayer = this.dLayers[groupName] = new ArcGISDynamicMapServiceLayer(config.urls.mapService, {
                    opacity: defaultOpacity || 0.5
                });
                this.map.addLayer(dLayer, true);
                this.map.addLoaderToLayer(dLayer);
                dLayer.on('load', function () {
                    that.toggleDynamicLayer(layerId, show, groupName, defaultOpacity, isRadio, layerType);
                });
                return;
            } else {
                dLayer = this.dLayers[groupName];
                if (!dLayer.loaded) {
                    dLayer.on('load', function () {
                        that.toggleDynamicLayer(layerId, show, groupName, defaultOpacity, isRadio, layerType);
                    });
                    return;
                }
            }

            var toggleIds = layerId.split(',').map(function (idTxt) {
                return parseInt(idTxt, 10);
            });
            var layerIds;

            if (show) {
                if (isRadio || !dLayer.visibleLayers) {
                    layerIds = toggleIds;
                } else {
                    if (dLayer.visibleLayers.every(function (id) {
                        return toggleIds.indexOf(id) === -1;
                    })) {
                        layerIds = toggleIds.concat(dLayer.visibleLayers);
                    } else {
                        return;
                    }
                }
            } else {
                if (dLayer.visibleLayers) {
                    layerIds = dLayer.visibleLayers.filter(function (id) {
                        return toggleIds.indexOf(id) === -1;
                    });
                } else {
                    return;
                }
            }

            dLayer.setVisibleLayers(layerIds);
        },
        onSliderChange: function (newValue, groupName) {
            // summary:
            //      the user is changing the tranparency slider
            // newValue: Number
            //      0 - 100
            console.log('mapController:onSliderChange', arguments);

            this.dLayers[groupName].setOpacity(newValue / 100);
        },
        onMapClick: function (evt) {
            // summary:
            //      user clicks on the map
            // evt: MapClick Event Object
            console.log('mapController:onMapClick', arguments);

            this.map.graphics.clear();

            this.map.graphics.add(new Graphic(evt.mapPoint, config.currentLocationSymbol));
            topic.publish(config.topics.mapClick, evt.mapPoint);
        },
        destroy: function () {
            // summary:
            //
            console.log('mapController:destroy', arguments);

            this.childWidgets.forEach(function (w) {
                w.destroy();
            });
        }
    });
    return new MC();
});


text:
{-# LANGUAGE MagicHash #-}
module T5478 where

import GHC.Exts

data Foo = Foo0 ByteArray#  deriving Show


text:
using xwalk::Runtime;
using xwalk::RuntimeDownloadManagerDelegate;
using content::DownloadItem;
using content::DownloadManager;
using content::DownloadManagerImpl;
using content::DownloadTestObserver;
using content::DownloadTestObserverTerminal;
using content::BrowserContext;

namespace {

static DownloadManagerImpl* DownloadManagerForXWalk(Runtime* runtime) {
  return static_cast<DownloadManagerImpl*>(
      BrowserContext::GetDownloadManager(
          runtime->web_contents()->GetBrowserContext()));
}

class XWalkDownloadBrowserTest : public InProcessBrowserTest {
 public:
  virtual void SetUpOnMainThread() OVERRIDE {
    ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());

    DownloadManagerImpl* manager = DownloadManagerForXWalk(runtime());
    RuntimeDownloadManagerDelegate* delegate =
        static_cast<RuntimeDownloadManagerDelegate*>(manager->GetDelegate());
    delegate->SetDownloadBehaviorForTesting(downloads_directory_.path());
  }

  // Create a DownloadTestObserverTerminal that will wait for the
  // specified number of downloads to finish.
  DownloadTestObserver* CreateWaiter(Runtime* runtime, int num_downloads) {
    DownloadManager* download_manager = DownloadManagerForXWalk(runtime);
    return new DownloadTestObserverTerminal(download_manager, num_downloads,
        DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
  }

 private:
  // Location of the downloads directory for these tests
  base::ScopedTempDir downloads_directory_;
};

IN_PROC_BROWSER_TEST_F(XWalkDownloadBrowserTest, FileDownload) {
  GURL url = xwalk_test_utils::GetTestURL(
      base::FilePath().AppendASCII("download"),
      base::FilePath().AppendASCII("test.lib"));
  scoped_ptr<DownloadTestObserver> observer(CreateWaiter(runtime(), 1));
  xwalk_test_utils::NavigateToURL(runtime(), url);
  observer->WaitForFinished();
  EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
  std::vector<DownloadItem*> downloads;
  DownloadManagerForXWalk(runtime())->GetAllDownloads(&downloads);
  ASSERT_EQ(1u, downloads.size());
  ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState());
  base::FilePath file(downloads[0]->GetFullPath());
  ASSERT_TRUE(base::ContentsEqual(
      file, xwalk_test_utils::GetTestFilePath(
          base::FilePath().AppendASCII("download"),
          base::FilePath().AppendASCII("test.lib"))));
}

}  // namespace


text:
package com.amazonaws.services.batch.model.transform;

import java.util.Map;

import javax.annotation.Generated;

import com.amazonaws.SdkClientException;
import com.amazonaws.services.batch.model.*;

import com.amazonaws.protocol.*;
import com.amazonaws.annotation.SdkInternalApi;

/**
 * ArrayPropertiesDetailMarshaller
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
@SdkInternalApi
public class ArrayPropertiesDetailMarshaller {

    private static final MarshallingInfo<Map> STATUSSUMMARY_BINDING = MarshallingInfo.builder(MarshallingType.MAP).marshallLocation(MarshallLocation.PAYLOAD)
            .marshallLocationName("statusSummary").build();
    private static final MarshallingInfo<Integer> SIZE_BINDING = MarshallingInfo.builder(MarshallingType.INTEGER).marshallLocation(MarshallLocation.PAYLOAD)
            .marshallLocationName("size").build();
    private static final MarshallingInfo<Integer> INDEX_BINDING = MarshallingInfo.builder(MarshallingType.INTEGER).marshallLocation(MarshallLocation.PAYLOAD)
            .marshallLocationName("index").build();

    private static final ArrayPropertiesDetailMarshaller instance = new ArrayPropertiesDetailMarshaller();

    public static ArrayPropertiesDetailMarshaller getInstance() {
        return instance;
    }

    /**
     * Marshall the given parameter object.
     */
    public void marshall(ArrayPropertiesDetail arrayPropertiesDetail, ProtocolMarshaller protocolMarshaller) {

        if (arrayPropertiesDetail == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            protocolMarshaller.marshall(arrayPropertiesDetail.getStatusSummary(), STATUSSUMMARY_BINDING);
            protocolMarshaller.marshall(arrayPropertiesDetail.getSize(), SIZE_BINDING);
            protocolMarshaller.marshall(arrayPropertiesDetail.getIndex(), INDEX_BINDING);
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }

}


text:
import bisect
import json as json_

from collections import namedtuple
from jembatan.core.spandex.typesys_base import Span, Annotation, AnnotationScope
from pathlib import Path
from typing import ClassVar, Dict, Iterable, Optional, Tuple, Union

SpandexConstants = namedtuple("SpandexContstants", ["SPANDEX_DEFAULT_VIEW", "SPANDEX_URI_VIEW"])

constants = SpandexConstants("_SpandexDefaultView", "_SpandexUriView")

# object is mutable for performant reasons
class Spandex(object):
    """
    Spandex - data structure for holding a view of data, its content, and annotations
    """

    def __init__(self, parent: "Jembatan", content_string: str=None, content_mime: str = None, viewname=None):
        self._parent = parent
        self._content_string = content_string
        self._content_mime = content_mime
        self._annotations = []
        self._annotation_keys = []
        self.viewname = viewname

    def __repr__(self):
        return "<{}/{} at 0x{:x}>".format(self.__class__.__name__, self.viewname, id(self))

    @property
    def parent(self) -> "JembatanDoc":
        return self._parent

    @property
    def content_string(self) -> str:
        return self._content_string

    @content_string.setter
    def content_string(self, value: str):
        self._content_string = value

    @property
    def content_mime(self) -> str:
        return self._content_mime

    @content_mime.setter
    def content_mime(self, value: str):
        self._content_mime = value

    @property
    def annotations(self) -> Iterable[Annotation]:
        return self._annotations

    def compute_keys(self, annotations: Iterable[Annotation]) -> Iterable[Tuple]:
        return [a.index_key for a in annotations]

    def spanned_text(self, span: Span) -> str:
        """
        Return text covered by the span
        """
        return self.content_string[span.begin:span.end]

    def add_annotations(self, *annotations: Annotation):
        items = sorted(self._annotations + list(annotations))
        keys = self.compute_keys(items)
        self._annotations = items
        self._annotation_keys = keys

    def index_annotations(self, *annotations: Annotation):
        return self.add_annotations(annotations)

    def select(self, type_: ClassVar[Annotation]) -> Iterable[Annotation]:
        """
        Return all annotations of type_
        """
        return [a for a in self.annotations if isinstance(a, type_)]

    def select_covered(self, type_: ClassVar[Annotation], span: Span) -> Iterable[Annotation]:
        """
        Return all annotations in a type_ that are covered by the input span
        """
        begin = bisect.bisect_left(self._annotation_keys, (AnnotationScope.SPAN, span.begin))
        end = bisect.bisect_left(self._annotation_keys, (AnnotationScope.SPAN, span.end))
        return [a for a in self.annotations[begin:end] if isinstance(a, type_)]

    def select_preceding(self, type_: ClassVar[Annotation], span: Span, count: int=None) -> Iterable[Annotation]:
        """
        Return all annotations in a type_ that precede the input span
        """
        precede_span = Span(begin=0, end=span.begin)
        preceding = self.select_covered(type_, precede_span)
        return preceding if count is None else preceding[-count:]

    def select_following(self, type_: ClassVar[Annotation], span: Span, count: int=None) -> Iterable[Annotation]:
        """
        Return all annotations in a type_ that follow the input span
        """
        follow_span = Span(begin=span.end+1, end=len(self.content_string))
        following = self.select_covered(type_, follow_span)
        return following if count is None else following[0:count]

    def select_all(self, span: Span) -> Iterable[Annotation]:
        """
        Return all annotations in a view
        """
        return self.annotations

    def to_json(self, path: Union[str, Path, None] = None, pretty_print: bool = False) -> Optional[str]:
        """Creates a JSON representation of this Spandex.
        Args:
            path: File path, if `None` is provided the result is returned as a string
            pretty_print: `True` if the resulting JSON should be pretty-printed, else `False`
        Returns:
            If `path` is None, then the JSON representation of this Spandex is returned as a string
        """
        from jembatan.core.spandex.json import SpandexJsonEncoder

        indent = 4 if pretty_print else None
        # If `path` is None, then serialize to a string and return it
        if path is None:
            return json_.dumps(self, cls=SpandexJsonEncoder, indent=indent)
        elif isinstance(path, str):
            with open(path, "w") as f:
                json_.dump(self, f, cls=SpandexJsonEncoder, indent=indent)
        elif isinstance(path, Path):
            with path.open("w") as f:
                json_.dump(self, f, cls=SpandexJsonEncoder, indent=indent)
        else:
            raise TypeError("`path` needs to be one of [str, None, Path], but was <{0}>".format(type(path)))

class JembatanDoc(object):
    """
    Top level container for processing.  The JembatanDoc roughly describes / manages a document or artifact.
    It is responsible for managing views.
    """

    def __init__(self, metadata: Dict=None, content_string: str=None, content_mime: str=None):
        self.metadata = metadata
        self._views = {}

        self.create_view(
            constants.SPANDEX_DEFAULT_VIEW,
            content_string=content_string,
            content_mime=content_mime,
        )

    @property
    def default_view(self):
        return self.get_view(constants.SPANDEX_DEFAULT_VIEW)

    def get_view(self, viewname: str):
        view = None

        try:
            view = self.views[viewname]
        except KeyError as e:
            raise KeyError("No view named '{}' in Jembatan {}".format(viewname, self))

        return view

    def get_or_create_view(self, viewname: str):
        try:
            view = self.get_view(viewname)
        except KeyError:
            view = self.create_view(viewname)
        return view

    def __getitem__(self, viewname: str):
        return self.get_view(viewname)

    def create_view(self, viewname: str, content_string: str=None, content_mime: str=None):

        if viewname in self.views:
            raise KeyError("View {} already exists in Jembatan{}".format(viewname, self))

        new_view_spndx = Spandex(content_string=content_string, content_mime=content_mime, parent=self, viewname=viewname)
        self.views[viewname] = new_view_spndx
        return new_view_spndx

    @property
    def views(self):
        return self._views

class ViewMappedSpandex(object):

    def __init__(self, spandex: Spandex, view_mapped_parent: JembatanDoc):
        '''
        Wrapper constructor.
        @param obj: object to wrap
        '''
        # wrap the object
        self._wrapped_spandex = spandex
        self._wrapped_parent = view_mapped_parent

        if view_mapped_parent.wrapped != self.wrapped.parent:
            raise ValueError("Can not wrap parent from different Jembatans")

    def __getattr__(self, attr):
        # see if this object has attr
        # NOTE do not use hasattr, it goes into
        # infinite recurrsion
        if attr in self.__dict__:
            # this object has it
            return getattr(self, attr)
        # proxy to the wrapped object
        return getattr(self.wrapped, attr)

    def __repr__(self):
        return "<{}/{} at 0x{:x}>".format(self.__class__.__name__, self.viewname, id(self))

    @property
    def wrapped(self):
        return self._wrapped_spandex

    @property
    def parent(self):
        return self._wrapped_parent

class ViewMappedJembatanDoc(object):
    '''
    Object wrapper class.
    This a wrapper for objects. It is initialiesed with the object to wrap
    and then proxies the unhandled getattribute methods to it.
    Other classes are to inherit from it.
    '''
    def __init__(self, jemdoc: JembatanDoc, view_map):
        '''
        Wrapper constructor.
        @param obj: object to wrap
        '''
        # wrap the object
        self._wrapped_jemdoc = jemdoc
        self.view_map = view_map

    def __getattr__(self, attr):
        # see if this object has attr
        # NOTE do not use hasattr, it goes into
        # infinite recurrsion
        if attr in self.__dict__:
            # this object has it
            return getattr(self, attr)
        # proxy to the wrapped object
        return getattr(self._wrapped_jemdoc, attr)

    @property
    def wrapped(self):
        return self._wrapped_jemdoc

    @property
    def default_view(self):
        return self.get_view(constants.SPANDEX_DEFAULT_VIEW)

    def get_view(self, viewname):
        mapped_viewname = self.view_map.get(viewname, None)
        if mapped_viewname is None:
            # viewname was not specified in view map, so return the original view
            view = self.wrapped.get_view(viewname)
        else:
            view = self.wrapped.get_view(mapped_viewname)

        # we need to wrap the view so that if it references its parent it can get back to the ViewMapped version
        # instead of the original one
        return ViewMappedSpandex(view, self)

    def create_view(self, viewname: str) -> Spandex:
        if viewname in self.view_map:
            mapped_viewname = self.view_map[viewname]
            view = self.wrapped.create_view(mapped_viewname)
        else:
            view = self.wrapped.create_view(viewname)

        return ViewMappedSpandex(view, parent=self)

    def __getitem__(self, viewname: str) -> Spandex:
        return self.get_view(viewname)

__all__ = ['errors', 'encoders']


text:
import unittest

import pydoop
pp = pydoop.import_version_specific_module('_pipes')
from pydoop.pipes import Factory, RecordReader

class test_record_reader(RecordReader):

  DEFAULT_VALUE = 'The quick red fox jumped on the lazy brown dog'
  KEY_FORMAT = 'key-%d'
  NUMBER_RECORDS = 10

  def __init__(self, ctx):
    RecordReader.__init__(self)
    self.ctx = ctx
    self.counter = 0

  def next(self):
    if self.counter < self.NUMBER_RECORDS:
      self.counter += 1
      return (True, self.KEY_FORMAT % self.counter, self.DEFAULT_VALUE)
    else:
      return (False, '', '')

  def getProgress(self):
    return float(self.counter)/self.NUMBER_RECORDS

class record_reader_tc(unittest.TestCase):

  def setUp(self):
    pass

  def test_record_reader_from_cpluplus(self):
    d = {'input_key' : 'inputkey',
         'input_value' : 'inputvalue',
         'input_split' : 'inputsplit',
         'input_key_class' : 'keyclass',
         'input_value_class' : 'valueclass',
         'job_conf' : {}}
    ctx = pp.get_MapContext_object(d)
    self.assertEqual(ctx.getInputKey(), d['input_key'])
    self.assertEqual(ctx.getInputValue(), d['input_value'])
    self.assertEqual(ctx.getInputSplit(), d['input_split'])
    self.assertEqual(ctx.getInputKeyClass(), d['input_key_class'])
    self.assertEqual(ctx.getInputValueClass(), d['input_value_class'])
    f = Factory(None, None, test_record_reader)
    rr = f.createRecordReader(ctx)
    for i in range(test_record_reader.NUMBER_RECORDS):
      (f, k, v) = pp.get_record_from_record_reader(rr)
      self.assertTrue(f)
      self.assertEqual(k, test_record_reader.KEY_FORMAT % (i+1))
      self.assertEqual(v, test_record_reader.DEFAULT_VALUE)
      self.assertAlmostEqual(pp.get_progress_from_record_reader(rr),
                             float(i+1)/test_record_reader.NUMBER_RECORDS)
    (f, k, v) = pp.get_record_from_record_reader(rr)
    self.assertFalse(f)

def suite():
  suite = unittest.TestSuite()
  suite.addTest(record_reader_tc('test_record_reader_from_cpluplus'))
  return suite

if __name__ == '__main__':
  runner = unittest.TextTestRunner(verbosity=2)
  runner.run((suite()))


text:
title: "Agones News"
linkTitle: "News"
weight: 20
---