text:
#include "dynet/lstm.h"

#include <fstream>
#include <string>
#include <vector>
#include <iostream>

#include "dynet/nodes.h"

using namespace std;
using namespace dynet::expr;

namespace dynet {

enum { X2I, H2I, C2I, BI, X2O, H2O, C2O, BO, X2C, H2C, BC };

LSTMBuilder::LSTMBuilder(unsigned layers,
                         unsigned input_dim,
                         unsigned hidden_dim,
                         Model& model) : layers(layers), input_dim(input_dim), hid(hidden_dim) {
  unsigned layer_input_dim = input_dim;
  for (unsigned i = 0; i < layers; ++i) {
    // i
    Parameter p_x2i = model.add_parameters({hidden_dim, layer_input_dim});
    Parameter p_h2i = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_c2i = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_bi = model.add_parameters({hidden_dim});

    // o
    Parameter p_x2o = model.add_parameters({hidden_dim, layer_input_dim});
    Parameter p_h2o = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_c2o = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_bo = model.add_parameters({hidden_dim});

    // c
    Parameter p_x2c = model.add_parameters({hidden_dim, layer_input_dim});
    Parameter p_h2c = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_bc = model.add_parameters({hidden_dim});
    layer_input_dim = hidden_dim;  // output (hidden) from 1st layer is input to next

    vector<Parameter> ps = {p_x2i, p_h2i, p_c2i, p_bi, p_x2o, p_h2o, p_c2o, p_bo, p_x2c, p_h2c, p_bc};
    params.push_back(ps);
  }  // layers
  dropout_rate = 0.f;
  dropout_rate_h = 0.f;
  dropout_rate_c = 0.f;
}

void LSTMBuilder::new_graph_impl(ComputationGraph& cg) {
  param_vars.clear();

  for (unsigned i = 0; i < layers; ++i) {
    auto& p = params[i];

    //i
    Expression i_x2i = parameter(cg, p[X2I]);
    Expression i_h2i = parameter(cg, p[H2I]);
    Expression i_c2i = parameter(cg, p[C2I]);
    Expression i_bi = parameter(cg, p[BI]);
    //o
    Expression i_x2o = parameter(cg, p[X2O]);
    Expression i_h2o = parameter(cg, p[H2O]);
    Expression i_c2o = parameter(cg, p[C2O]);
    Expression i_bo = parameter(cg, p[BO]);
    //c
    Expression i_x2c = parameter(cg, p[X2C]);
    Expression i_h2c = parameter(cg, p[H2C]);
    Expression i_bc = parameter(cg, p[BC]);

    vector<Expression> vars = {i_x2i, i_h2i, i_c2i, i_bi, i_x2o, i_h2o, i_c2o, i_bo, i_x2c, i_h2c, i_bc};
    param_vars.push_back(vars);
  }
  _cg = &cg;
}

// layout: 0..layers = c
//         layers+1..2*layers = h
void LSTMBuilder::start_new_sequence_impl(const vector<Expression>& hinit) {
  // Check input dim and hidden dim
  if (input_dim != params[0][X2I].dim()[1]) {
    cerr << "Warning : LSTMBuilder input dimension " << input_dim
         << " doesn't match with parameter dimension " << params[0][X2I].dim()[1]
         << ". Setting input_dim to " << params[0][X2I].dim()[1] << endl;
    input_dim = params[0][X2I].dim()[1];
  }
  if (hid != params[0][X2I].dim()[0]) {
    cerr << "Warning : LSTMBuilder hidden dimension " << hid
         << " doesn't match with parameter dimension " << params[0][X2I].dim()[0]
         << ". Setting hid to " << params[0][X2I].dim()[0] << endl;
    hid = params[0][X2I].dim()[0];
  }

  h.clear();
  c.clear();
  if (hinit.size() > 0) {
    DYNET_ARG_CHECK(layers * 2 == hinit.size(),
                            "LSTMBuilder must be initialized with 2 times as many expressions as layers "
                            "(hidden state and cell for each layer). However, for " << layers << " layers, "
                            << hinit.size() << " expressions were passed in");
    h0.resize(layers);
    c0.resize(layers);
    for (unsigned i = 0; i < layers; ++i) {
      c0[i] = hinit[i];
      h0[i] = hinit[i + layers];
    }
    has_initial_state = true;
  } else {
    has_initial_state = false;
  }
  // Init dropout masks
  set_dropout_masks();
}

void LSTMBuilder::set_dropout_masks(unsigned batch_size) {
  masks.clear();
  for (unsigned i = 0; i < layers; ++i) {
    std::vector<Expression> masks_i;
    unsigned idim = (i == 0) ? input_dim : hid;
    if (dropout_rate > 0.f) {
      float retention_rate = 1.f - dropout_rate;
      float retention_rate_h = 1.f - dropout_rate_h;
      float retention_rate_c = 1.f - dropout_rate_c;
      float scale = 1.f / retention_rate;
      float scale_h = 1.f / retention_rate_h;
      float scale_c = 1.f / retention_rate_c;
      // in
      masks_i.push_back(random_bernoulli(*_cg, Dim({ idim}, batch_size), retention_rate, scale));
      // h
      masks_i.push_back(random_bernoulli(*_cg, Dim({ hid}, batch_size), retention_rate_h, scale_h));
      // c
      masks_i.push_back(random_bernoulli(*_cg, Dim({ hid}, batch_size), retention_rate_c, scale_c));
      masks.push_back(masks_i);
    }
  }
}
// TO DO - Make this correct
// Copied c from the previous step (otherwise c.size()< h.size())
// Also is creating a new step something we want?
// wouldn't overwriting the current one be better?
Expression LSTMBuilder::set_h_impl(int prev, const vector<Expression>& h_new) {
  DYNET_ARG_CHECK(h_new.empty() || h_new.size() == layers,
                          "LSTMBuilder::set_h expects as many inputs as layers, but got " << h_new.size() << " inputs for " << layers << " layers");
  const unsigned t = h.size();
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  for (unsigned i = 0; i < layers; ++i) {
    Expression h_i = h_new[i];
    Expression c_i = c[t - 1][i];
    h[t][i] = h_i;
    c[t][i] = c_i;
  }
  return h[t].back();
}
// Current implementation : s_new is either {new_c[0],...,new_c[n]}
// or {new_c[0],...,new_c[n],new_h[0],...,new_h[n]}
Expression LSTMBuilder::set_s_impl(int prev, const std::vector<Expression>& s_new) {
  DYNET_ARG_CHECK(s_new.size() == layers || s_new.size() == 2 * layers,
                          "LSTMBuilder::set_s expects either as many inputs or twice as many inputs as layers, but got " << s_new.size() << " inputs for " << layers << " layers");
  bool only_c = s_new.size() == layers;
  const unsigned t = c.size();
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  for (unsigned i = 0; i < layers; ++i) {
    Expression h_i = only_c ? h[t - 1][i] : s_new[i + layers];
    Expression c_i = s_new[i];
    h[t][i] = h_i;
    c[t][i] = c_i;
  }
  return h[t].back();
}

Expression LSTMBuilder::add_input_impl(int prev, const Expression& x) {
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  vector<Expression>& ht = h.back();
  vector<Expression>& ct = c.back();
  Expression in = x;
  for (unsigned i = 0; i < layers; ++i) {
    const vector<Expression>& vars = param_vars[i];
    Expression i_h_tm1, i_c_tm1;
    bool has_prev_state = (prev >= 0 || has_initial_state);
    if (prev < 0) {
      if (has_initial_state) {
        // intial value for h and c at timestep 0 in layer i
        // defaults to zero matrix input if not set in add_parameter_edges
        i_h_tm1 = h0[i];
        i_c_tm1 = c0[i];
      }
    } else {  // t > 0
      i_h_tm1 = h[prev][i];
      i_c_tm1 = c[prev][i];
    }

    // apply dropout according to https://arxiv.org/abs/1512.05287 (tied weights)
    // x
    if (dropout_rate > 0.f) {
      in = cmult(in, masks[i][0]);

    }
    // h
    if (has_prev_state && dropout_rate_h > 0.f)
      i_h_tm1 = cmult(i_h_tm1, masks[i][1]);
    // For c, create another variable since we still need full i_c_tm1 for the componentwise mult
    Expression i_dropped_c_tm1;
    if (has_prev_state) {
      i_dropped_c_tm1 = i_c_tm1;
      if (dropout_rate_c > 0.f)
        i_dropped_c_tm1 = cmult(i_dropped_c_tm1, masks[i][2]);
    }

    // input
    Expression i_ait;
    if (has_prev_state)
      i_ait = affine_transform({vars[BI], vars[X2I], in, vars[H2I], i_h_tm1, vars[C2I], i_dropped_c_tm1});
    else
      i_ait = affine_transform({vars[BI], vars[X2I], in});
    Expression i_it = logistic(i_ait);
    // forget
    Expression i_ft = 1.f - i_it;
    // write memory cell
    Expression i_awt;
    if (has_prev_state)
      i_awt = affine_transform({vars[BC], vars[X2C], in, vars[H2C], i_h_tm1});
    else
      i_awt = affine_transform({vars[BC], vars[X2C], in});
    Expression i_wt = tanh(i_awt);
    // output
    if (has_prev_state) {
      Expression i_nwt = cmult(i_it, i_wt);
      Expression i_crt = cmult(i_ft, i_c_tm1);
      ct[i] = i_crt + i_nwt;
    } else {
      ct[i] = cmult(i_it, i_wt);
    }

    Expression i_aot;
    // Drop c. Uses the same mask as c_tm1. is this justified?
    Expression dropped_c = ct[i];
    if (dropout_rate_c > 0.f)
      dropped_c = cmult(dropped_c, masks[i][2]);
    if (has_prev_state)
      i_aot = affine_transform({vars[BO], vars[X2O], in, vars[H2O], i_h_tm1, vars[C2O], dropped_c});
    else
      i_aot = affine_transform({vars[BO], vars[X2O], in, vars[C2O], dropped_c});
    Expression i_ot = logistic(i_aot);
    Expression ph_t = tanh(ct[i]);
    in = ht[i] = cmult(i_ot, ph_t);
  }
  return ht.back();
}

void LSTMBuilder::copy(const RNNBuilder & rnn) {
  const LSTMBuilder & rnn_lstm = (const LSTMBuilder&)rnn;
  DYNET_ARG_CHECK(params.size() == rnn_lstm.params.size(),
                          "Attempt to copy LSTMBuilder with different number of parameters "
                          "(" << params.size() << " != " << rnn_lstm.params.size() << ")");
  for (size_t i = 0; i < params.size(); ++i)
    for (size_t j = 0; j < params[i].size(); ++j)
      params[i][j] = rnn_lstm.params[i][j];
}

void LSTMBuilder::save_parameters_pretraining(const string& fname) const {
  cerr << "Writing LSTM parameters to " << fname << endl;
  ofstream of(fname);
  if (!of)
    DYNET_INVALID_ARG("Couldn't write LSTM parameters to " << fname);
  boost::archive::binary_oarchive oa(of);
  std::string id = "LSTMBuilder:params";
  oa << id;
  oa << layers;
  for (unsigned i = 0; i < layers; ++i) {
    for (auto p : params[i]) {
      oa << p.get()->values;
    }
  }
}

void LSTMBuilder::load_parameters_pretraining(const string& fname) {
  cerr << "Loading LSTM parameters from " << fname << endl;
  ifstream of(fname);
  if (!of)
    DYNET_INVALID_ARG("Couldn't read LSTM parameters from " << fname);
  boost::archive::binary_iarchive ia(of);
  std::string id;
  ia >> id;
  if (id != "LSTMBuilder:params")
    DYNET_INVALID_ARG("Bad id read in LSTMBuilder::load_parameters_pretraining. Invalid model format?");
  unsigned l = 0;
  ia >> l;
  if (l != layers)
    DYNET_INVALID_ARG("Bad number of layers in LSTMBuilder::load_parameters_pretraining. Invalid model format?");
  // TODO check other dimensions
  for (unsigned i = 0; i < layers; ++i) {
    for (auto p : params[i]) {
      ia >> p.get()->values;
    }
  }
}

void LSTMBuilder::set_dropout(float d) {
  DYNET_ARG_CHECK(d >= 0.f && d <= 1.f,
                          "dropout rate must be a probability (>=0 and <=1)");
  dropout_rate = d;
  dropout_rate_h = d;
  dropout_rate_c = d;
}

void LSTMBuilder::set_dropout(float d, float d_h, float d_c) {
  DYNET_ARG_CHECK(d >= 0.f && d <= 1.f && d_h >= 0.f && d_h <= 1.f && d_c >= 0.f && d_c <= 1.f,
                          "dropout rate must be a probability (>=0 and <=1)");
  dropout_rate = d;
  dropout_rate_h = d_h;
  dropout_rate_c = d_c;
}

void LSTMBuilder::disable_dropout() {
  dropout_rate = 0.f;
  dropout_rate_h = 0.f;
  dropout_rate_c = 0.f;
}

DYNET_SERIALIZE_COMMIT(LSTMBuilder,
		       DYNET_SERIALIZE_DERIVED_DEFINE(RNNBuilder, params, layers, dropout_rate),
		       DYNET_VERSION_SERIALIZE_DEFINE(1, MAX_SERIALIZE_VERSION, dropout_rate_h, dropout_rate_c, input_dim, hid))

DYNET_SERIALIZE_IMPL(LSTMBuilder);

// Vanilla LSTM

//enum { _X2I, _H2I, _C2I, _BI, _X2F, _H2F, _C2F, _BF, _X2O, _H2O, _C2O, _BO, _X2G, _H2G, _C2G, _BG };
enum { _X2I, _H2I, _BI, _X2F, _H2F, _BF, _X2O, _H2O, _BO, _X2G, _H2G, _BG };

VanillaLSTMBuilder::VanillaLSTMBuilder() : has_initial_state(false), layers(0), input_dim(0), hid(0), dropout_rate_h(0) { }

VanillaLSTMBuilder::VanillaLSTMBuilder(unsigned layers,
                                       unsigned input_dim,
                                       unsigned hidden_dim,
                                       Model& model) : layers(layers), input_dim(input_dim), hid(hidden_dim) {
  unsigned layer_input_dim = input_dim;
  for (unsigned i = 0; i < layers; ++i) {
    // i
    Parameter p_x2i = model.add_parameters({hidden_dim * 4, layer_input_dim});
    Parameter p_h2i = model.add_parameters({hidden_dim * 4, hidden_dim});
    //Parameter p_c2i = model.add_parameters({hidden_dim, hidden_dim});
    Parameter p_bi = model.add_parameters({hidden_dim * 4});

    layer_input_dim = hidden_dim;  // output (hidden) from 1st layer is input to next

    vector<Parameter> ps = {p_x2i, p_h2i, /*p_c2i,*/ p_bi};
    params.push_back(ps);
  }  // layers
  dropout_rate = 0.f;
  dropout_rate_h = 0.f;
}

void VanillaLSTMBuilder::new_graph_impl(ComputationGraph& cg) {
  param_vars.clear();

  for (unsigned i = 0; i < layers; ++i) {
    auto& p = params[i];
    vector<Expression> vars;
    for (unsigned j = 0; j < p.size(); ++j) { vars.push_back(parameter(cg, p[j])); }
    param_vars.push_back(vars);
  }

  _cg = &cg;
}
// layout: 0..layers = c
//         layers+1..2*layers = h
void VanillaLSTMBuilder::start_new_sequence_impl(const vector<Expression>& hinit) {
  h.clear();
  c.clear();

  if (hinit.size() > 0) {
    DYNET_ARG_CHECK(layers * 2 == hinit.size(),
                            "VanillaLSTMBuilder must be initialized with 2 times as many expressions as layers "
                            "(hidden state, and cell for each layer). However, for " << layers << " layers, " <<
                            hinit.size() << " expressions were passed in");
    h0.resize(layers);
    c0.resize(layers);
    for (unsigned i = 0; i < layers; ++i) {
      c0[i] = hinit[i];
      h0[i] = hinit[i + layers];
    }
    has_initial_state = true;
  } else {
    has_initial_state = false;
  }

  // Init droupout masks
  set_dropout_masks();
}

void VanillaLSTMBuilder::set_dropout_masks(unsigned batch_size) {
  masks.clear();
  for (unsigned i = 0; i < layers; ++i) {
    std::vector<Expression> masks_i;
    unsigned idim = (i == 0) ? input_dim : hid;
    if (dropout_rate > 0.f) {
      float retention_rate = 1.f - dropout_rate;
      float retention_rate_h = 1.f - dropout_rate_h;
      float scale = 1.f / retention_rate;
      float scale_h = 1.f / retention_rate_h;
      // in
      masks_i.push_back(random_bernoulli(*_cg, Dim({ idim}, batch_size), retention_rate, scale));
      // h
      masks_i.push_back(random_bernoulli(*_cg, Dim({ hid}, batch_size), retention_rate_h, scale_h));
      masks.push_back(masks_i);
    }
  }
}

// TODO - Make this correct
// Copied c from the previous step (otherwise c.size()< h.size())
// Also is creating a new step something we want?
// wouldn't overwriting the current one be better?
Expression VanillaLSTMBuilder::set_h_impl(int prev, const vector<Expression>& h_new) {
  DYNET_ARG_CHECK(h_new.empty() || h_new.size() == layers,
                          "VanillaLSTMBuilder::set_h expects as many inputs as layers, but got " <<
                          h_new.size() << " inputs for " << layers << " layers");
  const unsigned t = h.size();
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  for (unsigned i = 0; i < layers; ++i) {
    Expression h_i = h_new[i];
    Expression c_i = c[t - 1][i];
    h[t][i] = h_i;
    c[t][i] = c_i;
  }
  return h[t].back();
}
// Current implementation : s_new is either {new_c[0],...,new_c[n]}
// or {new_c[0],...,new_c[n],new_h[0],...,new_h[n]}
Expression VanillaLSTMBuilder::set_s_impl(int prev, const std::vector<Expression>& s_new) {
  DYNET_ARG_CHECK(s_new.size() == layers || s_new.size() == 2 * layers,
                          "VanillaLSTMBuilder::set_s expects either as many inputs or twice as many inputs as layers, but got " << s_new.size() << " inputs for " << layers << " layers");
  bool only_c = s_new.size() == layers;
  const unsigned t = c.size();
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  for (unsigned i = 0; i < layers; ++i) {
    Expression h_i = only_c ? h[t - 1][i] : s_new[i + layers];
    Expression c_i = s_new[i];
    h[t][i] = h_i;
    c[t][i] = c_i;
  }
  return h[t].back();
}

Expression VanillaLSTMBuilder::add_input_impl(int prev, const Expression& x) {
  h.push_back(vector<Expression>(layers));
  c.push_back(vector<Expression>(layers));
  vector<Expression>& ht = h.back();
  vector<Expression>& ct = c.back();
  Expression in = x;
  for (unsigned i = 0; i < layers; ++i) {
    const vector<Expression>& vars = param_vars[i];
    Expression i_h_tm1, i_c_tm1;
    bool has_prev_state = (prev >= 0 || has_initial_state);
    if (prev < 0) {
      if (has_initial_state) {
        // intial value for h and c at timestep 0 in layer i
        // defaults to zero matrix input if not set in add_parameter_edges
        i_h_tm1 = h0[i];
        i_c_tm1 = c0[i];
      }
    } else {  // t > 0
      i_h_tm1 = h[prev][i];
      i_c_tm1 = c[prev][i];
    }
    // apply dropout according to https://arxiv.org/abs/1512.05287 (tied weights)
    if (dropout_rate > 0.f) {
      in = cmult(in, masks[i][0]);

    }
    if (has_prev_state && dropout_rate_h > 0.f)
      i_h_tm1 = cmult(i_h_tm1, masks[i][1]);
    // input
    Expression tmp;
    Expression i_ait;
    Expression i_aft;
    Expression i_aot;
    Expression i_agt;
    if (has_prev_state)
      tmp = affine_transform({vars[_BI], vars[_X2I], in, vars[_H2I], i_h_tm1});
    else
      tmp = affine_transform({vars[_BI], vars[_X2I], in});
    i_ait = pickrange(tmp, 0, hid);
    i_aft = pickrange(tmp, hid, hid * 2);
    i_aot = pickrange(tmp, hid * 2, hid * 3);
    i_agt = pickrange(tmp, hid * 3, hid * 4);
    Expression i_it = logistic(i_ait);
    Expression i_ft = logistic(i_aft);
    Expression i_ot = logistic(i_aot);
    Expression i_gt = tanh(i_agt);

    ct[i] = has_prev_state ? (cmult(i_ft, i_c_tm1) + cmult(i_it, i_gt)) :  cmult(i_it, i_gt);
    in = ht[i] = cmult(i_ot, tanh(ct[i]));
  }
  return ht.back();
}

void VanillaLSTMBuilder::copy(const RNNBuilder & rnn) {
  const LSTMBuilder & rnn_lstm = (const LSTMBuilder&)rnn;
  DYNET_ARG_CHECK(params.size() == rnn_lstm.params.size(),
                          "Attempt to copy LSTMBuilder with different number of parameters "
                          "(" << params.size() << " != " << rnn_lstm.params.size() << ")");
  for (size_t i = 0; i < params.size(); ++i)
    for (size_t j = 0; j < params[i].size(); ++j)
      params[i][j] = rnn_lstm.params[i][j];
}

void VanillaLSTMBuilder::save_parameters_pretraining(const string& fname) const {
  cerr << "Writing VanillaLSTM parameters to " << fname << endl;
  ofstream of(fname);
  if (!of)
    DYNET_INVALID_ARG("Couldn't write LSTM parameters to " << fname);
  boost::archive::binary_oarchive oa(of);
  std::string id = "VanillaLSTMBuilder:params";
  oa << id;
  oa << layers;
  for (unsigned i = 0; i < layers; ++i) {
    for (auto p : params[i]) {
      oa << p.get()->values;
    }
  }
}

void VanillaLSTMBuilder::load_parameters_pretraining(const string& fname) {
  cerr << "Loading VanillaLSTM parameters from " << fname << endl;
  ifstream of(fname);
  if (!of)
    DYNET_INVALID_ARG("Couldn't read LSTM parameters from " << fname);
  boost::archive::binary_iarchive ia(of);
  std::string id;
  ia >> id;
  if (id != "VanillaLSTMBuilder:params")
    DYNET_INVALID_ARG("Bad id read in VanillaLSTMBuilder::load_parameters_pretraining. Bad model format?");
  unsigned l = 0;
  ia >> l;
  if (l != layers)
    DYNET_INVALID_ARG("Bad number of layers in VanillaLSTMBuilder::load_parameters_pretraining. Bad model format?");
  // TODO check other dimensions
  for (unsigned i = 0; i < layers; ++i) {
    for (auto p : params[i]) {
      ia >> p.get()->values;
    }
  }
}

void VanillaLSTMBuilder::set_dropout(float d) {
  DYNET_ARG_CHECK(d >= 0.f && d <= 1.f,
                          "dropout rate must be a probability (>=0 and <=1)");
  dropout_rate = d;
  dropout_rate_h = d;
}

void VanillaLSTMBuilder::set_dropout(float d, float d_h) {
  DYNET_ARG_CHECK(d >= 0.f && d <= 1.f && d_h >= 0.f && d_h <= 1.f,
                          "dropout rate must be a probability (>=0 and <=1)");
  dropout_rate = d;
  dropout_rate_h = d_h;
}

void VanillaLSTMBuilder::disable_dropout() {
  dropout_rate = 0.f;
  dropout_rate_h = 0.f;
}

DYNET_SERIALIZE_COMMIT(VanillaLSTMBuilder, DYNET_SERIALIZE_DERIVED_DEFINE(RNNBuilder, params, layers, dropout_rate, dropout_rate_h, hid, input_dim))
DYNET_SERIALIZE_IMPL(VanillaLSTMBuilder);

} // namespace dynet


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE134_Uncontrolled_Format_String__char_environment_w32_vsnprintf_63b.c
Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
Template File: sources-vasinks-63b.tmpl.c
*/
/*
 * @description
 * CWE: 134 Uncontrolled Format String
 * BadSource: environment Read input from an environment variable
 * GoodSource: Copy a fixed string into data
 * Sinks: w32_vsnprintf
 *    GoodSink: vsnprintf with a format string
 *    BadSink : vsnprintf without a format string
 * Flow Variant: 63 Data flow: pointer to data passed from one function to another in different source files
 *
 * */

#include <stdarg.h>
#include "std_testcase.h"

#ifndef _WIN32
#include <wchar.h>
#endif

#define ENV_VARIABLE "ADD"

#ifdef _WIN32
#define GETENV getenv
#else
#define GETENV getenv
#endif

#ifndef OMITBAD

static void badVaSink(char * data, ...)
{
    {
        char dest[100] = "";
        va_list args;
        va_start(args, data);
        /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
        vsnprintf(dest, 100-1, data, args);
        va_end(args);
        printLine(dest);
    }
}

void CWE134_Uncontrolled_Format_String__char_environment_w32_vsnprintf_63b_badSink(char * * dataPtr)
{
    char * data = *dataPtr;
    badVaSink(data, data);
}

#endif /* OMITBAD */

#ifndef OMITGOOD

/* goodG2B uses the GoodSource with the BadSink */
static void goodG2BVaSink(char * data, ...)
{
    {
        char dest[100] = "";
        va_list args;
        va_start(args, data);
        /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
        vsnprintf(dest, 100-1, data, args);
        va_end(args);
        printLine(dest);
    }
}

void CWE134_Uncontrolled_Format_String__char_environment_w32_vsnprintf_63b_goodG2BSink(char * * dataPtr)
{
    char * data = *dataPtr;
    goodG2BVaSink(data, data);
}

/* goodB2G uses the BadSource with the GoodSink */
static void goodB2GVaSink(char * data, ...)
{
    {
        char dest[100] = "";
        va_list args;
        va_start(args, data);
        /* FIX: Specify the format disallowing a format string vulnerability */
        vsnprintf(dest, 100-1, "%s", args);
        va_end(args);
        printLine(dest);
    }
}

void CWE134_Uncontrolled_Format_String__char_environment_w32_vsnprintf_63b_goodB2GSink(char * * dataPtr)
{
    char * data = *dataPtr;
    goodB2GVaSink(data, data);
}

#endif /* OMITGOOD */

redpajama_set_name: RedPajamaGithub


text:
package org.dstadler.commoncrawl;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;

import org.dstadler.commons.http.HttpClientWrapper;
import org.dstadler.commons.logging.jdk.LoggerFactory;

/**
 * Small helper app to load a chunk of data from the URL Crawl index
 * for testing/analyzing the data locally.
 *
 * @author dominik.stadler
 */
public class ReadTestData {
    private final static Logger log = LoggerFactory.make();

    private static final int DOWNLOAD_DATA_SIZE = 10*1024*1024;

    private static final int SKIP_BLOCKS = 0;

    public static void main(String[] args) throws IOException {
        try (HttpClientWrapper client = new HttpClientWrapper("", null, 1800_000)) {
            // TODO: disabled until new data is published to save us one additional HTTP Request during startup
//            Pair<Long, Long> values = readStartPos(client.getHttpClient());
//            long startPos = values.getRight();
//            int blockSize = values.getLeft().intValue();
            int blockSize = Utils.BLOCK_SIZE;
            long startPos = (long)Utils.HEADER_BLOCK_SIZE + (blockSize * Utils.INDEX_BLOCK_COUNT) + ((long)blockSize * SKIP_BLOCKS);

            readTestData(client.getHttpClient(), startPos);
        }

        log.info("Done");
    }

    public static void readTestData(CloseableHttpClient client, long startPos) throws IOException {
        log.info("Reading data starting at " + startPos + " from " + Utils.INDEX_URL);
        HttpGet httpGet = new HttpGet(Utils.INDEX_URL);
        httpGet.addHeader("Range", "bytes=" + startPos + "-");
        try (CloseableHttpResponse response = client.execute(httpGet)) {
            HttpEntity entity = HttpClientWrapper.checkAndFetch(response, Utils.INDEX_URL);

            try (InputStream stream = entity.getContent()) {
                try {
                    log.info("Reading data");
                    byte[] block = new byte[DOWNLOAD_DATA_SIZE];
                    IOUtils.read(stream, block);

                    FileUtils.writeByteArrayToFile(new File("/tmp/data.bin"), block);
                } finally {
                    // always abort reading here inside the finally block of the InputStream as
                    // otherwise HttpClient tries to read the stream fully, which is at least 270GB...
                    httpGet.abort();
                }
            }
        }
    }

}


text:
#ifndef CORE_OBJ_H_INCLUDED
#define CORE_OBJ_H_INCLUDED

#include <iostream>
#include <set>
#include "../Parser/Token.hpp"
#include "../Func/Core.hpp"
#include "../Err/Msg.hpp"

namespace Obj
{

    class Core : public Parser::Token, public Func::Core
    {
        public:
        Core();
        Core(std::string, std::string, const Parser::Token&);
        bool defineClass( Parser::Token& );
        typedef std::set<Core> funcSet;

        private:
        std::string m_name;
        static funcSet m_definedClasses;
        std::string m_content;
        Parser::Token m_body;
    };

}

#endif // CORE_OBJ_H_INCLUDED


text:
<!DOCTYPE html>

        <meta charset="UTF-8" />
        <meta name="robots" content="index, follow, all" />
        <title>HealthCareAbroad\UserBundle\Services\InstitutionUserService | HealthCareAbroad API</title>
                    <link rel="stylesheet" type="text/css" href="../../../stylesheet.css">

Classes

Namespaces

Interfaces

Index

HealthCareAbroad API

Class

HealthCareAbroad\UserBundle\Services\InstitutionUserService

class    InstitutionUserService        extends UserService

Methods

                    setEventDispatcher($eventDispatcher)

                from UserService

                    setEventFactory(EventFactory $eventFactory)

                from UserService

                    setSession($session)

                from UserService

                    setDoctrine(Registry $doctrine)

                from UserService

                    setSecurityContext(SecurityContext $context)

                from UserService

                    setChromediaRequest(ChromediaGlobalRequest $request)

                from UserService

                    setChromediaAccountsUri($uri)

                from UserService

                    array

                    find(array $searchBy, array $options)

Find user/s in chromedia global accounts based on searchBy options

                from UserService

                    getAccountDataById($id)

                from UserService

                    SiteUser

                    getUser(SiteUser $user)

Find an account in global chromedia by accountId

                from UserService

                    login(string $email, password $password)

                    SiteUser

                    create(InstitutionUser $institutionUser)

Create a institution user

                    SiteUser

                    update(InstitutionUser $institutionUser)

Update Account of institution user

                    InstitutionUser

                    findByEmailAndPassword(string $email, string $password)

                    InstitutionUser

                    findByIdAndPassword($id, $password)

                    Ambigous

                    findById(int $id, boolean $activeOnly = true)

Find a InstitutionUser by accountId

                    getAccountData(InstitutionUser $institutionUser)

Details

in UserService at line 60

                    public
    setEventDispatcher($eventDispatcher)

Parameters

                $eventDispatcher

in UserService at line 65

                    public
    setEventFactory(EventFactory $eventFactory)

Parameters

                EventFactory
                $eventFactory

in UserService at line 70

                    public
    setSession($session)

Parameters

                $session

in UserService at line 79

                    public
    setDoctrine(Registry $doctrine)

Parameters

                Registry
                $doctrine

in UserService at line 84

                    public
    setSecurityContext(SecurityContext $context)

Parameters

                SecurityContext
                $context

in UserService at line 95

                    public
    setChromediaRequest(ChromediaGlobalRequest $request)

Parameters

                ChromediaGlobalRequest
                $request

in UserService at line 100

                    public
    setChromediaAccountsUri($uri)

Parameters

                $uri

in UserService at line 189

                    public            array
    find(array $searchBy, array $options)

Find user/s in chromedia global accounts based on searchBy options

Parameters

                array
                $searchBy

                array
                $options

Return Value

            array

in UserService at line 205

                    public
    getAccountDataById($id)

Parameters

                $id

in UserService at line 216

                    public            SiteUser
    getUser(SiteUser $user)

Find an account in global chromedia by accountId

Parameters

                SiteUser
                $user

Return Value

            SiteUser

at line 28

                    public
    login(string $email, password $password)

Parameters

                string
                $email

                password
                $password

at line 67

                    public            SiteUser
    create(InstitutionUser $institutionUser)

Create a institution user

Parameters

                InstitutionUser
                $institutionUser

Return Value

            SiteUser

at line 89

                    public            SiteUser
    update(InstitutionUser $institutionUser)

Update Account of institution user

Parameters

                InstitutionUser
                $institutionUser

Return Value

            SiteUser

at line 106

                    public            InstitutionUser
    findByEmailAndPassword(string $email, string $password)

Parameters

                string
                $email

                string
                $password

Return Value

            InstitutionUser

at line 137

                    public            InstitutionUser
    findByIdAndPassword($id, $password)

Parameters

                $id

                $password

Return Value

            InstitutionUser

at line 169

                    public            Ambigous
    findById(int $id, boolean $activeOnly = true)

Find a InstitutionUser by accountId

Parameters

                int
                $id

                boolean
                $activeOnly

Return Value

            Ambigous
            <NULL, \HealthCareAbroad\UserBundle\Entity\InstitutionUser>

at line 181

                    public
    getAccountData(InstitutionUser $institutionUser)

Parameters

                InstitutionUser
                $institutionUser

        Generated by Sami, the API Documentation Generator.


text:
(function () {
    // mixin Editor for canvas-studio
    Editor.require('app://canvas-studio/page/editor-init');

    // init engine-framework
    Editor.require('app://engine-framework');

    // init asset-db
    Editor.require('app://asset-db');

    // init canvas-assets
    Editor.require('packages://canvas-assets/init');

    // init ui-property
    Editor.require('packages://ui-property/init');

    // init runtime-assets
    Editor.require('app://runtime/runtime-' + Editor.projectInfo.runtime + '/init');
})();


text:
/*$AMPERSAND_VERSION*/
var sync = require('ampersand-sync');
var assign = require('lodash.assign');

module.exports = {
    // Fetch the default set of models for this collection, resetting the
    // collection when they arrive. If `reset: true` is passed, the response
    // data will be passed through the `reset` method instead of `set`.
    fetch: function(options) {
        options = options ? assign({}, options) : {};
        if (options.parse === void 0) options.parse = true;
        var self = this;

        var success = options.success;
        options.success = function(resp) {
            var method = options.reset ? 'reset' : 'set';
            if (options.set !== false) self[method](resp, options);
            if (success) success(self, resp, options);
            if (options.set !== false) self.trigger('sync', self, resp, options);
        };

        // Wrap an optional error callback with a fallback error event.
        var error = options.error;
        options.error = function(resp) {
            if (error) error(self, resp, options);
            self.trigger('error', self, resp, options);
        };

        var request = this.sync('read', this, options);
        // Make the request available on the options object so it can be accessed
        // further down the line by `parse`, sync listeners, etc
        // https://github.com/AmpersandJS/ampersand-collection-rest-mixin/commit/d32d788aaff912387eb1106f2d7ad183ec39e11a#diff-84c84703169bf5017b1bc323653acaa3R32
        options.xhr = request;
        return request;
    },

    // Create a new instance of a model in this collection. Add the model to the
    // collection immediately, unless `wait: true` is passed, in which case we
    // wait for the server to agree.
    create: function(model, options) {
        options = options ? assign({}, options) : {};
        if (!(model = this._prepareModel(model, options))) return false;
        if (!options.wait) this.add(model, options);
        var self = this;
        var success = options.success;
        options.success = function(model, resp) {
            if (options.wait) self.add(model, options);
            if (success) success(model, resp, options);
        };
        model.save(null, options);
        return model;
    },

    sync: function() {
        return sync.apply(this, arguments);
    },

    // Get or fetch a model by Id.
    getOrFetch: function (id, options, cb) {
        if (arguments.length !== 3) {
            cb = options;
            options = {};
        }

        var self = this;
        var model = this.get(id);

        if (model) {
            return window.setTimeout(cb.bind(null, null, model), 0);
        }

        if (options.all) {
            //preserve original `options.always`
            var always = options.always;
            options.always = function(err, resp, body) {
                if (always) always(err, resp, body);
                if (!cb) return;

                var model = self.get(id);
                var err2 = model ? null : new Error('not found');
                cb(err2, model);
            };
            return this.fetch(options);
        } else {
            return this.fetchById(id, options, cb);
        }
    },

    // fetchById: fetches a model and adds it to
    // collection when fetched.
    fetchById: function (id, options, cb) {
        if (arguments.length !== 3) {
            cb = options;
            options = {};
        }

        var self = this;
        var idObj = {};
        idObj[this.mainIndex] = id;
        var model = new this.model(idObj, {collection: this});

        //preserve original `options.success`
        var success = options.success;
        options.success = function (resp) {
            model = self.add(model);
            if (success) success(self, resp, options);
            if (cb) cb(null, model);
        };

        //preserve original `options.error`
        var error = options.error;
        options.error = function (collection, resp) {
            delete model.collection;

            if (error) error(collection, resp, options);

            if (cb) {
                var err = new Error(resp.rawRequest.statusText);
                err.status = resp.rawRequest.status;
                cb(err);
            }
        };

        return model.fetch(options);
    }
};


text:
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\TravellersLifeAgenda */
/* @var $form yii\widgets\ActiveForm */
?>

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'traveller_id')->hiddenInput(['value' => $traveller_id])->label(false) ?>

What's next on your life's agenda?

    <?= $form->field($model, 'life_agenda')->textarea(['maxlength' => true, 'class' => 'texarea-box'])->label(false) ?>

What's next on your life's agenda.What's next on your life's agenda.


text:
using System.ComponentModel.DataAnnotations;
using Riganti.Utils.Infrastructure.Core;

namespace Altairis.NemesisEvents.DAL {
    public class Tag : IEntity<int> {

        [Key]
        public int Id { get; set; }

        [Required, MaxLength(50)]
        public string Name { get; set; }

    }
}


text:
module NounProjectApi
  # Basic connection methods and setup.
  module Connection
    attr_accessor :token, :secret, :access_token

    def initialize(token, secret)
      @token = token
      @secret = secret
      raise ArgumentError, "Missing token or secret" unless @token && @secret

      @access_token = OAuth::AccessToken.new(OAuth::Consumer.new(token, secret))
    end
  end
end


text:
"""Module for variants of ops in tf.nn."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


text:
"""
Tests for Topology DSL
"""

import logging
import unittest
from io import BytesIO

from streamparse.dsl import Grouping, Stream, Topology
from streamparse.storm import (Bolt, Component, JavaBolt, JavaSpout, ShellBolt,
                               ShellSpout, Spout)
from streamparse.thrift import JavaObjectArg

log = logging.getLogger(__name__)

class WordSpout(Spout):
    outputs = ["word"]

class WordCountBolt(Bolt):
    outputs = ["word", "count"]

class MultiStreamWordCountBolt(Bolt):
    outputs = [Stream(fields=['word', 'count']),
               Stream(fields=['all_word_count'], name='sum')]

class DatabaseDumperBolt(Bolt):
    outputs = []

class TopologyTests(unittest.TestCase):
    maxDiff = 1000

    def test_basic_spec(self):
        class WordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = WordCountBolt.spec(inputs={word_spout:
                                                   Grouping.fields("word")},
                                           par=8)

        self.assertEqual(len(WordCount.specs), 2)
        self.assertEqual(list(WordCount.word_bolt.inputs.keys()),
                         [WordCount.word_spout['default']])
        self.assertEqual(WordCount.thrift_spouts['word_spout'].common.parallelism_hint,
                         2)
        self.assertEqual(WordCount.thrift_bolts['word_bolt'].common.parallelism_hint,
                         8)
        self.assertEqual(WordCount.word_bolt.inputs[WordCount.word_spout['default']],
                         Grouping.fields('word'))

    def test_spec_with_inputs_as_list(self):
        class WordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = WordCountBolt.spec(inputs=[word_spout], par=8)
        self.assertEqual(len(WordCount.specs), 2)
        self.assertEqual(len(WordCount.thrift_spouts), 1)
        self.assertEqual(len(WordCount.thrift_bolts), 1)
        self.assertEqual(list(WordCount.word_bolt.inputs.keys()),
                         [WordCount.word_spout['default']])
        self.assertEqual(WordCount.word_bolt.inputs[WordCount.word_spout['default']],
                         Grouping.SHUFFLE)

    def test_multi_stream_bolt(self):
        class WordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = MultiStreamWordCountBolt.spec(inputs=[word_spout],
                                                      par=8)
            db_dumper_bolt = DatabaseDumperBolt.spec(par=4,
                                                     inputs=[word_bolt['sum'],
                                                             word_bolt['default']])
        self.assertEqual(len(WordCount.specs), 3)
        self.assertEqual(len(WordCount.thrift_spouts), 1)
        self.assertEqual(len(WordCount.thrift_bolts), 2)
        self.assertEqual(list(WordCount.word_bolt.inputs.keys()),
                         [WordCount.word_spout['default']])
        self.assertEqual(WordCount.word_bolt.inputs[WordCount.word_spout['default']],
                         Grouping.SHUFFLE)
        db_dumper_bolt_input_set = set(WordCount.db_dumper_bolt.inputs.keys())
        self.assertEqual(len(WordCount.db_dumper_bolt.inputs.keys()),
                         len(db_dumper_bolt_input_set))
        self.assertEqual(db_dumper_bolt_input_set,
                         {WordCount.word_bolt['sum'], WordCount.word_bolt['default']})

    def test_long_chain_spec(self):
        class WordCount(Topology):
            word_spout = WordSpout.spec()
            word_bolt1 = WordCountBolt.spec(inputs=[word_spout])
            word_bolt2 = WordCountBolt.spec(inputs=[word_bolt1])
            word_bolt3 = WordCountBolt.spec(inputs=[word_bolt2])
            word_bolt4 = WordCountBolt.spec(inputs=[word_bolt3])
            word_bolt5 = WordCountBolt.spec(inputs=[word_bolt4])
            word_bolt6 = WordCountBolt.spec(inputs=[word_bolt5])
            word_bolt7 = WordCountBolt.spec(inputs=[word_bolt6])
            word_bolt8 = WordCountBolt.spec(inputs=[word_bolt7])
            word_bolt9 = WordCountBolt.spec(inputs=[word_bolt8])
            word_bolt10 = WordCountBolt.spec(inputs=[word_bolt9])
            word_bolt11 = WordCountBolt.spec(inputs=[word_bolt10])
            word_bolt12 = WordCountBolt.spec(inputs=[word_bolt11])
        self.assertEqual(len(WordCount.specs), 13)
        self.assertEqual(len(WordCount.thrift_spouts), 1)
        self.assertEqual(len(WordCount.thrift_bolts), 12)
        self.assertEqual(list(WordCount.word_bolt1.inputs.keys())[0],
                         WordCount.word_spout['default'])
        self.assertEqual(WordCount.word_bolt1.inputs[WordCount.word_spout['default']],
                         Grouping.SHUFFLE)
        for i in range(2, 13):
            bolt = getattr(WordCount, 'word_bolt{}'.format(i))
            prev_bolt = getattr(WordCount, 'word_bolt{}'.format(i - 1))
            self.assertEqual(list(bolt.inputs.keys())[0], prev_bolt['default'])
            self.assertEqual(bolt.inputs[prev_bolt['default']], Grouping.SHUFFLE)

    def test_many_spouts_spec(self):
        class WordCount(Topology):
            word_spout1 = WordSpout.spec()
            word_spout2 = WordSpout.spec()
            word_spout3 = WordSpout.spec()
            word_spout4 = WordSpout.spec()
            word_spout5 = WordSpout.spec()
            word_bolt = WordCountBolt.spec(inputs=[word_spout1, word_spout2,
                                                   word_spout3, word_spout4,
                                                   word_spout5])

    def test_invalid_bolt_group_field(self):
        # Fields grouping must specify field output by spout
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs={word_spout:
                                                       Grouping.fields("foo")})

    def test_empty_bolt_group_field(self):
        # Fields groupings require field names to be specified
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs={word_spout:
                                                       Grouping.fields()})

    def test_duplicate_name(self):
        # Each component name must be unique
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word = WordSpout.spec()
                word_ = WordCountBolt.spec(name='word', inputs=[word])

    def test_no_input_bolt(self):
        # All bolts must have at least one input
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[])

    def test_no_outputs_spout_empty(self):
        # All spouts must have output fields
        class PointlessSpout(Spout):
            outputs = []
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = PointlessSpout.spec()

    def test_no_outputs_spout(self):
        # All spouts must have output fields
        class PointlessSpout(Spout):
            outputs = []
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = PointlessSpout.spec()

    def test_base_component_rejection(self):
        # Topology components must inherit from Bolt/Spout, not Component directly
        class MyComponent(Component):
            outputs = []
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = MyComponent.spec()

    def test_component_instead_of_spec(self):
        # Make sure we catch things early when people forget to call .spec
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout(input_stream=BytesIO(),
                                       output_stream=BytesIO())

    def test_no_spout(self):
        # Every topology must have a spout
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                pass

    def test_zero_par(self):
        # Component parallelism (number of processes) can't be 0
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = WordSpout.spec(par=0)

    def test_negative_par(self):
        # Component parallelism (number of processes) can't be negative
        with self.assertRaises(ValueError):
            class WordCount(Topology):
                word_spout = WordSpout.spec(par=-1)

    def test_float_par(self):
        # Component parallelism (number of processes) must be an int
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec(par=5.4)

    def test_dict_par(self):
        # Component parallelism (number of processes) can temporarily be a dict
        class WordCount(Topology):
            word_spout = WordSpout.spec(par={'prod': 5, 'beta': 1})
        self.assertEqual(WordCount.thrift_spouts['word_spout'].common.parallelism_hint,
                         {'prod': 5, 'beta': 1})

    def test_dict_par_bad_key_type(self):
        # Component parallelism dict must map for str to int
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec(par={1000: 5, 'beta': 1})

    def test_dict_par_bad_value_type(self):
        # Component parallelism dict must map for str to int
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec(par={'prod': 5.5, 'beta': 1})

    def test_invalid_bolt_input_dict_key(self):
        # Keys in input dict must be either GlobalStreamId or ComponentSpec
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs={'word_spout':
                                                       Grouping.fields('word')})

    def test_invalid_bolt_input_dict_val(self):
        # Values in input dict must be Grouping objects
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs={word_spout:
                                                       'word'})

    def test_invalid_bolt_input_str(self):
        # inputs must be either list, dict, or None; not str
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs='word_spout')

    def test_invalid_config_str(self):
        # configs must be either dict, or None; not str
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[word_spout],
                                               config='{"foo": "bar"}')

    def test_invalid_topology_config_str(self):
        # configs must be either dict, or None; not str
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                config = '{"foo": "bar"}'
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[word_spout])

    def test_invalid_outputs_entry_int(self):
        # Outputs must either be list of strings or list of streams, not ints
        class BadSpout(Spout):
            outputs = ['foo', 2]
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                bad_spout = BadSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[bad_spout])

    def test_invalid_outputs_str(self):
        # Outputs must either be list of strings or list of streams
        class BadSpout(Spout):
            outputs = 'foo'
        with self.assertRaises(TypeError):
            class WordCount(Topology):
                bad_spout = BadSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[bad_spout])

    def test_unknown_stream(self):
        # Should raise keyerror if stream name is not valid
        with self.assertRaises(KeyError):
            class WordCount(Topology):
                word_spout = WordSpout.spec()
                word_bolt = WordCountBolt.spec(inputs=[word_spout['word']])

    def test_perl_bolt(self):
        # Make sure ShellBolt.spec works
        class PerlWordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = ShellBolt.spec(command='perl', script='count_words.pl',
                                       inputs={word_spout: Grouping.fields("word")},
                                       par=8, outputs=['word', 'count'])

        self.assertEqual(len(PerlWordCount.specs), 2)
        self.assertEqual(list(PerlWordCount.word_bolt.inputs.keys()),
                         [PerlWordCount.word_spout['default']])
        self.assertEqual(PerlWordCount.thrift_spouts['word_spout'].common.parallelism_hint,
                         2)
        self.assertEqual(PerlWordCount.thrift_bolts['word_bolt'].common.parallelism_hint,
                         8)
        self.assertEqual(PerlWordCount.word_bolt.inputs[PerlWordCount.word_spout['default']],
                         Grouping.fields('word'))

    def test_shell_bolt_no_command(self):
        # Should raise ValueError if command is None
        with self.assertRaises(ValueError):
            class PerlWordCount(Topology):
                word_spout = WordSpout.spec(par=2)
                word_bolt = ShellBolt.spec(script='count_words.pl',
                                           inputs={word_spout: Grouping.fields("word")},
                                           par=8, outputs=['word', 'count'])

    def test_shell_bolt_no_script(self):
        # Should raise TypeError if script is None
        with self.assertRaises(TypeError):
            class PerlWordCount(Topology):
                word_spout = WordSpout.spec(par=2)
                word_bolt = ShellBolt.spec(command='perl',
                                           inputs={word_spout: Grouping.fields("word")},
                                           par=8, outputs=['word', 'count'])

    def test_java_bolt_valid_arg_list(self):
        # JavaBolt should work fine when given basic data types
        class JavaWordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = JavaBolt.spec(full_class_name='com.bar.foo.counter.WordCountBolt',
                                      args_list=[u'foo', 1, b'\x09\x10', True,
                                                 3.14159],
                                      inputs={word_spout: Grouping.fields("word")},
                                      par=8, outputs=['word', 'count'])
        java_object = JavaWordCount.thrift_bolts['word_bolt'].bolt_object.java_object
        self.assertEqual(java_object.full_class_name, 'com.bar.foo.counter.WordCountBolt')
        self.assertEqual(java_object.args_list,
                         [JavaObjectArg(string_arg=u'foo'),
                          JavaObjectArg(long_arg=1),
                          JavaObjectArg(binary_arg=b'\x09\x10'),
                          JavaObjectArg(bool_arg=True),
                          JavaObjectArg(double_arg=3.14159)])
        self.assertIsNone(JavaWordCount.thrift_bolts['word_bolt'].bolt_object.serialized_java)
        self.assertIsNone(JavaWordCount.thrift_bolts['word_bolt'].bolt_object.shell)

    def test_java_bolt_invalid_arg_list(self):
        # JavaBolt should raise TypeError when given something other than basic data types
        with self.assertRaises(TypeError):
            class JavaWordCount(Topology):
                word_spout = WordSpout.spec(par=2)
                word_bolt = JavaBolt.spec(full_class_name='com.bar.foo.counter.WordCountBolt',
                                          args_list=[{'foo': 'bar'}, 1],
                                          inputs={word_spout: Grouping.fields("word")},
                                          par=8, outputs=['word', 'count'])

    def test_java_bolt_valid_serialized_java(self):
        # JavaBolt should work fine when given a byte string for serialized_java
        serialized_java = b'\x01\x02\x03\x04\x05'
        class JavaWordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = JavaBolt.spec(serialized_java=serialized_java,
                                      inputs={word_spout: Grouping.fields("word")},
                                      par=8, outputs=['word', 'count'])
        self.assertEqual(JavaWordCount.thrift_bolts['word_bolt'].bolt_object.serialized_java, serialized_java)
        self.assertIsNone(JavaWordCount.thrift_bolts['word_bolt'].bolt_object.java_object)
        self.assertIsNone(JavaWordCount.thrift_bolts['word_bolt'].bolt_object.shell)

    def test_perl_spout(self):
        # Make sure ShellBolt.spec works
        class PerlWordCount(Topology):
            word_spout = ShellSpout.spec(command='perl',
                                         script='count_words.pl', par=2,
                                         outputs=['word'])
            word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                           par=8)
        self.assertEqual(len(PerlWordCount.specs), 2)
        self.assertEqual(list(PerlWordCount.word_bolt.inputs.keys()),
                         [PerlWordCount.word_spout['default']])
        self.assertEqual(PerlWordCount.thrift_spouts['word_spout'].common.parallelism_hint,
                         2)
        self.assertEqual(PerlWordCount.thrift_bolts['word_bolt'].common.parallelism_hint,
                         8)
        self.assertEqual(PerlWordCount.word_bolt.inputs[PerlWordCount.word_spout['default']],
                         Grouping.fields('word'))

    def test_shell_spout_no_command(self):
        # Should raise ValueError if command is None
        with self.assertRaises(ValueError):
            class PerlWordCount(Topology):
                word_spout = ShellSpout.spec(script='count_words.pl', par=8,
                                             outputs=['word'])
                word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                               par=8)

    def test_shell_spout_no_script(self):
        # Should raise TypeError if script is None
        with self.assertRaises(TypeError):
            class PerlWordCount(Topology):
                word_spout = ShellSpout.spec(command='perl', par=8,
                                             outputs=['word'])
                word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                               par=8)

    def test_java_spout_valid_arg_list(self):
        # JavaSpout should work fine when given basic data types
        class JavaWordCount(Topology):
            word_spout = JavaSpout.spec(full_class_name='com.bar.foo.counter.WordSpout',
                                        args_list=[u'foo', 1, b'\x09\x10', True,
                                                   3.14159],
                                        par=8, outputs=['word'])
            word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                           par=8)
        java_object = JavaWordCount.thrift_spouts['word_spout'].spout_object.java_object
        self.assertEqual(java_object.full_class_name, 'com.bar.foo.counter.WordSpout')
        self.assertEqual(java_object.args_list,
                         [JavaObjectArg(string_arg=u'foo'),
                          JavaObjectArg(long_arg=1),
                          JavaObjectArg(binary_arg=b'\x09\x10'),
                          JavaObjectArg(bool_arg=True),
                          JavaObjectArg(double_arg=3.14159)])
        self.assertIsNone(JavaWordCount.thrift_spouts['word_spout'].spout_object.serialized_java)
        self.assertIsNone(JavaWordCount.thrift_spouts['word_spout'].spout_object.shell)

    def test_java_spout_invalid_arg_list(self):
        # JavaSpout should raise TypeError when given something other than basic data types
        with self.assertRaises(TypeError):
            class JavaWordCount(Topology):
                word_spout = JavaSpout.spec(full_class_name='com.bar.foo.counter.WordSpout',
                                            args_list=[{'foo': 'bar'}, 1],
                                            par=8, outputs=['word'])
                word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                               par=8)

    def test_java_spout_valid_serialized_java(self):
        # JavaSpout should work fine when given a byte string for serialized_java
        serialized_java = b'\x01\x02\x03\x04\x05'
        class JavaWordCount(Topology):
            word_spout = JavaSpout.spec(serialized_java=serialized_java,
                                        par=8, outputs=['word'])
            word_bolt = WordCountBolt.spec(inputs={word_spout: Grouping.fields("word")},
                                           par=8)
        self.assertEqual(JavaWordCount.thrift_spouts['word_spout'].spout_object.serialized_java, serialized_java)
        self.assertIsNone(JavaWordCount.thrift_spouts['word_spout'].spout_object.java_object)
        self.assertIsNone(JavaWordCount.thrift_spouts['word_spout'].spout_object.shell)

    def test_basic_to_flux_dict(self):
        class WordCount(Topology):
            word_spout = WordSpout.spec(par=2)
            word_bolt = WordCountBolt.spec(inputs={word_spout:
                                                   Grouping.fields("word")},
                                           par=8)

        self.assertEqual(WordCount.to_flux_dict('word_count'),
                         {'name': 'word_count',
                          'spouts': [{'id': 'word_spout',
                                      'className': 'org.apache.storm.flux.wrappers.spouts.FluxShellSpout',
                                      'configMethods': [],
                                      'constructorArgs': [['streamparse_run',
                                                           'test.streamparse.test_dsl.WordSpout'],
                                                          ['word']],
                                      'parallelism': 2}],
                          'streams': [{'to': 'word_bolt',
                                       'from': 'word_spout',
                                       'grouping': {'streamId': 'default',
                                                    'args': ['word'],
                                                    'type': 'FIELDS'}}],
                          'bolts': [{'id': 'word_bolt',
                                     'className': 'org.apache.storm.flux.wrappers.bolts.FluxShellBolt',
                                     'configMethods': [],
                                     'constructorArgs': [['streamparse_run',
                                                          'test.streamparse.test_dsl.WordCountBolt'],
                                                         ['word', 'count']],
                                     'parallelism': 8}]})


text:
<?php
/**
 * @group Core
 */
class Box_PeriodTest extends PHPUnit\Framework\TestCase
{

    public function testException()
    {
        $this->expectException(\Box_Exception::class);
        $this->expectExceptionMessage('Invalid period code. Period definition must be 2 chars length');
        $p = new Box_Period('1');

    }

    public function testException2()
    {
        $this->expectException(\Box_Exception::class);
        $this->expectExceptionMessage('Period Error. Unit Z is not defined');
        $p = new Box_Period('1Z');
    }

    public function testOneMonth()
    {
        $p = new Box_Period('1M');

        $this->assertEquals('M', $p->getUnit());
        $this->assertEquals(1, $p->getQty());
        $this->assertEquals('1M', $p->getCode());
        $this->assertEquals('Every 1 months', $p->getTitle());
        $this->assertEquals(30, $p->getDays());
        $this->assertEquals(1, $p->getMonths());
        $this->assertEquals(strtotime('+1 month'), $p->getExpirationTime());
    }
}


text:
var assert = require('assert')
var histo = require('../lib/index')
var async = require('async')
var streamUtils = require('simple-stream')

var createContentAddressable = require('./mock-stores/content-addressable')
var createKeyValueStore = require('./mock-stores/key-value-store')

var revs1 = [
  {data: 'abc'},
  {data: 'def'},
  {data: 'ghi'},
  {data: 'jkl'},
  {data: 'mno'},
  {data: 'pqr'}
]

var forkAHead = revs1[5]
var commonAncestor = revs1[2]

var revs2 = [
  {data: 'stu'},
  {data: 'vwx'},
  {data: 'yz'}
]

var forkBHead = revs2[2]

var writeRevs = function(db, revs, cb) {
  async.forEach(revs, function(each, cb) {
    db.put(each.data, function(err, res) {
      each.ref = res.head
      cb()
    })
  }, cb)
}

describe('HistoDB', function() {
  describe('local interfaces', function() {
    var cas = createContentAddressable()
    var kvStore = createKeyValueStore()
    var db = histo.createDB({revisionStore: cas, branchStore: kvStore})
    it('should write some data', function(done) {
      var rev = revs1[0]
      db.put(rev.data, function(err, res) {
        assert.ok(res.head)
        rev.ref = res.head
        done()
      })
    })
    it('should read the data', function(done) {
      var rev = revs1[0]
      db.get(function(err, res) {
        assert.equal(res, rev.data)
        done()
      })
    })
    it('should write more data', function(done) {
      var revs = revs1.slice(1)
      writeRevs(db, revs, done)
    })
    it('should read the head', function(done) {
      db.get(function(err, res) {
        assert.equal(res, revs1[5].data)
        done()
      })
    })
    it('should read the data of a previous revision', function(done) {
      db.get(revs1[0].ref, function(err, res) {
        assert.deepEqual(res, revs1[0].data)
        done()
      })
    })
    it('should set the head to a previous rev leaving a fork A', function(done) {
      db.setHead(commonAncestor.ref, function() {
        db.get(function(err, res) {
          assert.equal(res, commonAncestor.data)
          done()
        })
      })
    })
    it('should write more data creating a fork B', function(done) {
      writeRevs(db, revs2, done)
    })
    var refDiff
    var expectedRevs = revs1.slice(3)
    it('should find the missing refs to get from fork B to fork A', function(done) {
      db.head(function(err, head) {
        db.refDifference(head, forkAHead.ref, function(err, res) {
          var expectedDiff = expectedRevs.map(function(each) { return each.ref }).reverse()
          assert.deepEqual(res, expectedDiff)
          refDiff = res
          done()
        })
      })
    })
    it('should create an iterator for bulk-reading revisions', function(done) {
      var stream = db.createStream(refDiff)
      streamUtils.toArray(stream)(function(err, res) {
        res.reverse().map(function(each, i) {
          assert.equal(each.data, expectedRevs[i].data)
          assert.equal(each.ancestors[0], revs1[i+2].ref)
        })
        done()
      })
    })
    it('should find all revs of fork A', function(done) {
      db.refDifference(null, forkAHead.ref, function(err, res) {
        var expectedDiff = revs1.map(function(each) { return each.ref }).reverse()
        assert.deepEqual(res, expectedDiff)
        done()
      })
    })
    it('should read the ancestors of a ref', function(done) {
      db.ancestors(revs1[4].ref, function(err, res) {
        assert.equal(res, revs1[3].ref)
        done()
      })
    })
    it('should find the common ancestor of two refs', function(done) {
      db.commonAncestor(forkAHead.ref, forkBHead.ref, function(err, res) {
        assert.equal(res, commonAncestor.ref)
        done()
      })
    })
    it('should find the common ancestor of head and a ref', function(done) {
      db.commonAncestor(forkAHead.ref, function(err, res) {
        assert.equal(res, commonAncestor.ref)
        done()
      })
    })
    describe('optimistic locking when setting head', function() {
      it('should not set head if previous head wrong', function(done) {
        db.setHead(revs1[2].ref, revs1[1].ref, function(err) {
          assert.equal(err.message, 'head conflict')
          done()
        })
      })
    })
  })
  describe('synchronization', function() {
    var db1RevStore = createContentAddressable()
    var db1 = histo.createDB({
      revisionStore: db1RevStore,
      branchStore: createKeyValueStore()
    })
    var db2RevStore = createContentAddressable()
    var db2 = histo.createDB({
      revisionStore: db2RevStore,
      branchStore: createKeyValueStore()
    })

    it('should populate db1', function(done) {
      writeRevs(db1, revs1.slice(0, 2), done)
    })

    var source = histo.createLocalSource(db1)
    var target = histo.createLocalTarget(db2)
    var synchronizer = histo.createSynchronizer(source, target)

    it('should pull changes from db1 to db2', function(done) {
      assert.notDeepEqual(db2RevStore.data, db1RevStore.data)
      synchronizer.run(function() {
        assert.deepEqual(db2RevStore.data, db1RevStore.data)
        done()
      })
    })
  })
})


text:
title:      Release Notes for v2.4

Python-Markdown 2.4 Release Notes
=================================

We are pleased to release Python-Markdown 2.4 which adds one new extension
and fixes various bugs. See the list of changes below for details.

Python-Markdown supports Python versions 2.6, 2.7, 3.1, 3.2, and 3.3.

Backwards-incompatible Changes
------------------------------

* The `force_linenos` configuration setting of the CodeHilite extension has been
  marked as **Deprecated**. It had previously been marked as "Pending
  Deprecation" in version 2.3 when a new setting `linenums` was added to replace
  it. See documentation for the [CodeHilite Extension] for an explanation of the
  new `linenums` setting. The new setting will honor the old `force_linenos` if
  it is set, but `force_linenos` will raise a `DeprecationWarning` and will
  likely be removed in a future version of Python-Markdown.

[CodeHilite Extension]: ../extensions/code_hilite.md

* URLs are no longer percent-encoded. This improves compatibility with the
  original (written in Perl) Markdown implementation. Please percent-encode your
  URLs manually when needed.

What's New in Python-Markdown 2.4
---------------------------------

* Thanks to the hard work of [Dmitry Shachnev] the [Smarty Extension] has been
  added, which implements [SmartyPants] using Python-Markdown's Extension API.
  This offers a few benefits over a third party script. The HTML does not need
  to be "tokenized" twice, no hacks are required to combine SmartyPants and code
  highlighting, and we get markdown's escaping feature for free. Please try it
  out and report bugs and/or improvements.

[Dmitry Shachnev]: https://github.com/mitya57
[Smarty Extension]: ../extensions/smarty.md
[SmartyPants]: https://daringfireball.net/projects/smartypants/

* The [Table of Contents Extension] now supports new `permalink` option for
  creating [Sphinx]-style anchor links.

[Table of Contents Extension]: ../extensions/toc.md
[Sphinx]: http://sphinx-doc.org/

* It is now possible to enable Markdown formatting inside HTML blocks by
  appending `markdown=1` to opening tag attributes. See [Markdown Inside HTML
  Blocks] section for details. Thanks to [ryneeverett] for implementing this
  feature.

[Markdown Inside HTML Blocks]: ../extensions/extra.md#nested-markdown-inside-html-blocks
[ryneeverett]: https://github.com/ryneeverett

* The code blocks now support emphasizing some of the code lines. To use this
  feature, specify `hl_lines` option after language name, for example (using the
  [Fenced Code Extension]):

        ```.python hl_lines="1 3"
        # This line will be emphasized.
        # This one won't.
        # This one will be also emphasized.
        ```

    Thanks to [A. Jesse Jiryu Davis] for implementing this feature.

[Fenced Code Extension]: ../extensions/fenced_code_blocks.md
[A. Jesse Jiryu Davis]: https://github.com/ajdavis

* Various bug fixes have been made. See the [commit
  log](https://github.com/Python-Markdown/markdown/commits/master) for a
  complete history of the changes.


text:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="beyondj_persistence_unit">
        <class>com.lenox.domain.AuthUser</class>
        <class>com.lenox.domain.AuthUserToken</class>
        <class>com.lenox.domain.ContactRequest</class>
        <class>com.lenox.domain.EmailMessage</class>
        <class>com.lenox.domain.Image</class>
        <class>com.lenox.domain.Message</class>
        <class>com.lenox.domain.PlatformUser</class>
        <class>com.lenox.domain.Role</class>
        <class>com.lenox.domain.DeploymentRun</class>
        <class>com.lenox.domain.Location</class>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.globally_quoted_identifiers" value="true"/>
        </properties>
    </persistence-unit>
</persistence>


text: goog.require('core.locators'); goog.exportSymbol('_', core.locators.findElement);


text:
@class MSPage, MSDocumentWindow, MSContentDrawViewController;

@interface MSDocument : NSDocument <NSMenuDelegate, NSToolbarDelegate, NSWindowDelegate>

@property(copy, nonatomic) MSLayerArray * _Nonnull selectedLayers;
@property(retain, nonatomic) MSContentDrawViewController * _Nonnull currentContentViewController;

- (MSDocumentWindow * _Nonnull)window;
- (MSPage * _Nonnull)currentPage;
- (void)showMessage:(NSString *_Nonnull)message;
- (NSArray<MSPage *> *_Nonnull) pages;
- (BOOL)readDocumentFromURL:(NSURL *_Nonnull)url ofType:(NSString *_Nonnull)typeName error:(NSError *_Nullable)error;

@end


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Autofac;
using FrontendBuster;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace Clix.QA.Selenium.Tests
{

    public class LandingPage : PageBase
    {
        public LandingPage(IWebDriver driver) : base(driver)
        {
            var codePenIframe = driver.FindElement(By.Id("result"));
            driver.SwitchTo().Frame(codePenIframe);
        }
        public override void WaitLoading()
        {
            By loadingElementLocator = By.Id("clix_wrapper");
            this.Driver.WaitUntil(ExpectedConditions.ElementExists(loadingElementLocator), TimeSpan.FromMilliseconds(5000));
        }
    }

    /// <summary>
    /// this test class is to check if the JqueryDatatable https://datatables.net/ automation class is working
    /// I created a codepen here https://codepen.io/newcools/full/pWpGaO/
    /// </summary>
    [TestClass]
    public class JqueryDatatableTest
    {
        private static readonly Guid DriverToken = Guid.NewGuid();

        private static IWebDriver driver;

        /// <summary>
        /// search something in the table
        /// </summary>
        [TestMethod]
        public void JqueryDatatableSearch()
        {
            driver.GoToUrl("https://codepen.io/newcools/full/pWpGaO/");
            var landingPage = new LandingPage(driver);
            var tableWrapper = landingPage.FindElement(By.Id("clix_wrapper"));
            JqueryDatatable datatable = new JqueryDatatable(tableWrapper, landingPage);
            datatable.SearchTable("chengwei");
            Assert.IsTrue(datatable.Rows.Count > 0 );
            Assert.IsTrue(datatable[1, 1].Text == "Chengwei Li");
            var targetRow = datatable.GetRow(1);
            var chengweiOffice = datatable.GetDataCellElement(targetRow, "Office");
            var chengweiSalary = datatable.GetDataCellElement(targetRow, "Salary");
            var chengweiExtn = datatable.GetDataCellElement(targetRow, "Extn.");
            Assert.IsTrue(chengweiOffice.Text == "Sydney");
            Assert.IsTrue(chengweiSalary.Text == "$8,888,888");
            Assert.IsTrue(chengweiExtn.Text == "8888");
        }

        /// <summary>
        /// to test if JqueryDatatable can handle the empty table scenario well
        /// </summary>
        [TestMethod]
        public void JqueryDatatableNoData()
        {
            driver.GoToUrl("https://codepen.io/newcools/full/Oxzqwr/");
            var landingPage = new LandingPage(driver);
            var tableWrapper = landingPage.FindElement(By.Id("clix_wrapper"));
            JqueryDatatable datatable = new JqueryDatatable(tableWrapper, landingPage);
            Assert.AreEqual(0, datatable.Rows.Count);
        }

        [ClassInitialize]
        public static void Setup(TestContext context)
        {
            Registrar.Instance.RegisterModule(new FrontendBusterModule());
            Registrar.Instance.RegisterType(cb => cb.RegisterType<LandingPage>());
            driver = Registrar.NewLifetimeScope.ResolveWebDriver(DriverToken);
        }
    }
}


text:
UUFNScaleBiasModule::UUFNScaleBiasModule(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
	, InputModule(nullptr)
	, Scale(1.0f)
	, Bias(0.f)
{
}

float UUFNScaleBiasModule::GetNoise3D(float InX, float InY, float InZ)
{
	if (!(InputModule))
	{
		return 0.0f;
	}

	return (InputModule->GetNoise3D(InX, InY, InZ) * Scale) + Bias;
}

float UUFNScaleBiasModule::GetNoise2D(float InX, float InY)
{
	if (!(InputModule))
	{
		return 0.0f;
	}

	return (InputModule->GetNoise2D(InX, InY) * Scale) + Bias;
}


text:
require "test_helper"

# Single integration test.
class NamesSearchNameStatusSimple < ActionDispatch::IntegrationTest
  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL

  test "name status search" do
    Capybara.default_driver = :selenium
    visit_home_page
    select "Name", from: "query-on"
    select "with name status", from: "query-field"
    assert find("#query-field option[value='ns']")["selected"],
           "ns should be selected for name rank search"
    fill_in "search-field", with: "nom. inval."
    click_button "Search"
    sleep(0.1)
    search_result_must_include("[nom. inval.]",
                               "Name status search should have returned a
                               record for nom. inval.")
    search_result_must_not_include("[nom. inval., nom. nud.]",
                                   "Name status search should not have
                                   returned a record for nom. inval.,
                                   nom. nud.")
  end
end


text:
namespace erespacker
{

class UnpackFromBin
{
public:
	static void Unpack(const std::string& filepath,
		const std::vector<ee::ImagePtr>& images);

private:
	static void Unpack(uint8_t** ptr, const std::vector<ee::ImagePtr>& images);

}; // UnpackFromBin

}

#endif // _EASYRESPACKER_UNPACKE_FROM_BIN_H_


text:
<?php

namespace GraphAware\Neo4j\OGM\Metadata\Factory\Xml;

use GraphAware\Neo4j\OGM\Exception\MappingException;
use GraphAware\Neo4j\OGM\Metadata\NodeAnnotationMetadata;
use GraphAware\Neo4j\OGM\Metadata\NodeEntityMetadata;

class NodeEntityMetadataFactory
{
    private $propertyXmlMetadataFactory;
    private $relationshipXmlMetadataFactory;
    private $idXmlMetadataFactory;

    public function __construct(
        PropertyXmlMetadataFactory $propertyXmlMetadataFactory,
        RelationshipXmlMetadataFactory $relationshipXmlMetadataFactory,
        IdXmlMetadataFactory $idXmlMetadataFactory
    ) {
        $this->propertyXmlMetadataFactory = $propertyXmlMetadataFactory;
        $this->relationshipXmlMetadataFactory = $relationshipXmlMetadataFactory;
        $this->idXmlMetadataFactory = $idXmlMetadataFactory;
    }

    /**
     * @param \SimpleXMLElement $node
     * @param string            $className
     *
     * @return NodeEntityMetadata
     */
    public function buildNodeEntityMetadata(\SimpleXMLElement $node, $className)
    {
        $reflection = new \ReflectionClass($className);

        return new NodeEntityMetadata(
            $className,
            $reflection,
            $this->buildNodeMetadata($node, $className),
            $this->idXmlMetadataFactory->buildEntityIdMetadata($node, $className, $reflection),
            $this->propertyXmlMetadataFactory->buildPropertiesMetadata($node, $className, $reflection),
            $this->relationshipXmlMetadataFactory->buildRelationshipsMetadata($node, $className, $reflection)
        );
    }

    /**
     * @param \SimpleXMLElement $node
     * @param string            $className
     *
     * @return NodeAnnotationMetadata
     */
    private function buildNodeMetadata(\SimpleXMLElement $node, $className)
    {
        if (!isset($node['label'])) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML node configuration is missing "label" attribute', $className)
            );
        }

        return new NodeAnnotationMetadata(
            (string) $node['label'],
            isset($node['repository-class']) ? (string) $node['repository-class'] : null
        );
    }
}


text:
using UnityEngine;
using System.Collections;

public class Hose : MonoBehaviour {

	public float maxPower = 20;
	public float minPower = 5;
	public float changeSpeed = 5;

	float power;
	public ParticleSystem[] hoseWaterSystems;

	// Update is called once per frame
	void Update () {

		if (Input.GetMouseButton(0))
		{
			power = Mathf.Lerp(power,maxPower,Time.deltaTime*changeSpeed);
		} else {
			power = Mathf.Lerp(power,minPower,Time.deltaTime*changeSpeed);
		}

		if (Input.GetKeyDown(KeyCode.Alpha1))
		{
			var sys = transform.Find("Callback Particles").particleSystem;
			sys.renderer.enabled = !sys.renderer.enabled;
		}

		//audio.volume = Mathf.InverseLerp(0,maxPower,power);

		foreach (var system in hoseWaterSystems)
		{
			system.startSpeed = power;
			system.enableEmission = (power > minPower*1.1f);
		}
	}
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Treton.Core.Concurrency
{
	public static class TaskHelpers
	{
		private static TaskFactory _factory;

		internal static void Initialize(MainThreadScheduler mainThreadScheduler)
		{
			_factory = new TaskFactory(mainThreadScheduler);
		}

		public static Task RunOnMainThread(Action f)
		{
			return _factory.StartNew(f);
		}

		public static Task<T> RunOnMainThread<T>(Func<T> f)
		{
			return _factory.StartNew(f);
		}
	}
}


text:
@extends('_layouts.master')

@section('body')

Multisort Test

@foreach ($sort_tests as $item)

{{ $item->number }}-{{ $item->letter }}

@endforeach

@endsection


text:
<?php

namespace Magento\Authorization\Model\Resource\Role\Grid;

use Magento\Authorization\Model\Acl\Role\Group as RoleGroup;

/**
 * Admin role data grid collection
 */
class Collection extends \Magento\Authorization\Model\Resource\Role\Collection
{
    /**
     * Prepare select for load
     *
     * @return $this
     */
    protected function _initSelect()
    {
        parent::_initSelect();
        $this->addFieldToFilter('role_type', RoleGroup::ROLE_TYPE);
        return $this;
    }
}


text:
[![npm version](https://badge.fury.io/js/tsconfig-lint.svg)](http://badge.fury.io/js/tsconfig-lint)
[![Downloads](http://img.shields.io/npm/dm/tsconfig-lint.svg)](https://npmjs.org/package/tsconfig-lint)
[![Dependency Status](https://david-dm.org/wjohnsto/tsconfig-lint.svg)](https://david-dm.org/wjohnsto/tsconfig-lint)
[![devDependency Status](https://david-dm.org/wjohnsto/tsconfig-lint/dev-status.svg)](https://david-dm.org/wjohnsto/tsconfig-lint#info=devDependencies)

# tsconfig-lint
A tsconfig tool for running [tslint](https://github.com/palantir/tslint) on files found in the tsconfig. Integrates with [tsconfig-glob](https://github.com/wjohnsto/tsconfig-glob) to allow for `filesGlob` in the tsconfig.json.

## Install

Use `npm` to install this package.

Locally:

```shell
npm install tsconfig-lint --save-dev
```

or, Globally:

```shell
npm install -g tsconfig-lint --save-dev
```

## Usage

You can use this library as either a CLI or in a node script. It follows a similar format to the [atom-typescript](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md) plugin:

0. You provide a path to a directory containing a tsconfig.json
  - You can also provide the full path to a `.json` file that contains a `files` or `filesGlob` property along with your tslint rules.
0. You specify a `files` pattern in your tsconfig.json
0. You specify a `lintOptions` property in your tsconfig.json that contains your tslint rules.
  - If you do not specify `lintOptions`, the default tslint rules will be used.

### Using the CLI
```shell
tsconfig-lint .
```

#### Options

```shell
	-u, --use-glob A flag indicating that tsconfig-glob should be executed on the .json file before running lint on the files.
	-i, --indent <number> The number of spaces to indent the tsconfig.json file (defaults to 4). Only necessary if using --use-glob
```

### Using with Node

```ts
import * as lint from 'tsconfig-lint';
lint(undefined, (err) => {
    //...
});
```

#### Options

```ts
{
	/**
	 * A relative path from cwd to the directory containing a tsconfig.json. If not specified, the '.' is used.
	 */
	configPath?: string;

	/**
	 * The current working directory, defaults to `process.cwd()`
	 */
	cwd?: string;

	/**
	 * Whether or not tsconfig-glob should be executed on the .json file before running lint on the files.
	 */
	useGlob?: boolean;

	tsconfigOptions: {
		/**
		 * The number of spaces to indent the tsconfig.json
		 */
		indent?: number;
	};

}
```
#### Realistic Node Usage

```ts
import * as lint from 'tsconfig-lint';
lint({
	configPath: '.',
	cwd: process.cwd(),
	useGlob: true,
	tsconfigOptions: {
		indent: 2
	}
}, (err) => {
    //...
});
```

## Default Rules

The default rules (found in the tsconfig.json) are below:

```ts
"rules": {
    "class-name": true,
    "curly": true,
    "eofline": true,
    "forin": true,
    "indent": [
        true,
        4
    ],
    "interface-name": true,
    "jsdoc-format": true,
    "label-position": true,
    "label-undefined": true,
    "max-line-length": false,
    "member-ordering": [
        true,
        "public-before-private",
        "static-before-instance",
        "variables-before-functions"
    ],
    "no-any": false,
    "no-arg": true,
    "no-bitwise": false,
    "no-console": [
        true,
        "debug",
        "info",
        "time",
        "timeEnd",
        "trace"
    ],
    "no-consecutive-blank-lines": true,
    "no-construct": true,
    "no-constructor-vars": false,
    "no-debugger": true,
    "no-duplicate-key": true,
    "no-duplicate-variable": true,
    "no-empty": false,
    "no-eval": true,
    "no-string-literal": true,
    "no-trailing-comma": true,
    "no-trailing-whitespace": true,
    "no-unreachable": true,
    "no-unused-expression": true,
    "no-unused-variable": false,
    "no-use-before-declare": true,
    "one-line": [
        true,
        "check-open-brace",
        "check-catch",
        "check-else",
        "check-whitespace"
    ],
    "quotemark": [
        true,
        "single"
    ],
    "radix": true,
    "semicolon": true,
    "triple-equals": [
        true,
        "allow-null-check"
    ],
    "typedef": [
        true,
        "property-declaration",
        "member-variable-declaration",
        "call-signature"
    ],
    "typedef-whitespace": [
        true,
        [
            "call-signature",
            "nospace"
        ],
        [
            "catch-clause",
            "nospace"
        ],
        [
            "index-signature",
            "space"
        ],
        [
            "parameter",
            "nospace"
        ],
        [
            "property-declaration",
            "nospace"
        ],
        [
            "variable-declaration",
            "nospace"
        ]
    ],
    "use-strict": [
        true,
        "check-module"
    ],
    "variable-name": false,
    "whitespace": [
        false,
        "check-branch",
        "check-decl",
        "check-operator",
        "check-separator",
        "check-type"
    ]
}
```