text:
/* commit-STM.cpp - Simple(r) Timing Model */
/*
 * __COPYRIGHT__ GT
 */

#ifdef ZESTO_PARSE_ARGS
  if(!strcasecmp(commit_opt_string,"STM"))
    return std::make_unique<class core_commit_STM_t>(core);
#else

class core_commit_STM_t:public core_commit_t
{
  enum commit_stall_t {CSTALL_NONE,      /* no stall */
                       CSTALL_NOT_READY, /* oldest inst not done (no uops finished) */
                       CSTALL_PARTIAL,   /* oldest inst not done (but some uops finished) */
                       CSTALL_EMPTY,     /* ROB is empty, nothing to commit */
                       CSTALL_num
                     };

  public:

  core_commit_STM_t(struct core_t * const core);
  ~core_commit_STM_t();
  virtual void reg_stats(xiosim::stats::StatsDatabase* sdb);
  virtual void update_occupancy(void);

  virtual void step(void);
  virtual void IO_step(void);
  virtual void recover(const struct Mop_t * const Mop);
  virtual void recover(void);

  virtual bool ROB_available(void);
  virtual bool ROB_empty(void);
  virtual bool pipe_empty(void);
  virtual void ROB_insert(struct uop_t * const uop);
  virtual void ROB_fuse_insert(struct uop_t * const uop);

  virtual void pre_commit_insert(struct uop_t * const uop);
  virtual void pre_commit_fused_insert(struct uop_t * const uop);
  virtual bool pre_commit_available();
  virtual void pre_commit_step();
  virtual void pre_commit_recover(struct Mop_t * const Mop);
  virtual void squash_uop(struct uop_t * const uop);

  protected:

  struct uop_t ** ROB;
  int ROB_head;
  int ROB_tail;
  int ROB_num;

  static const char *commit_stall_str[CSTALL_num];

  /* additional temps to track timing of REP insts */
  tick_t when_rep_fetch_started;
  tick_t when_rep_fetched;
  tick_t when_rep_decode_started;
  tick_t when_rep_commit_started;
};

/* number of buckets in uop-flow-length histogram */
#define FLOW_HISTO_SIZE 9

/* VARIABLES/TYPES */

const char *core_commit_STM_t::commit_stall_str[CSTALL_num] = {
  "no stall                   ",
  "oldest inst not done       ",
  "oldest inst partially done ",
  "ROB is empty               ",
};

/*******************/
/* SETUP FUNCTIONS */
/*******************/

core_commit_STM_t::core_commit_STM_t(struct core_t * const arg_core):
  ROB_head(0), ROB_tail(0), ROB_num(0),
  when_rep_fetch_started(0), when_rep_fetched(0),
  when_rep_decode_started(0), when_rep_commit_started(0)
{
  struct core_knobs_t * knobs = arg_core->knobs;
  core = arg_core;
  ROB = (struct uop_t**) calloc(knobs->commit.ROB_size,sizeof(*ROB));
  if(!ROB)
    fatal("couldn't calloc ROB");
}

core_commit_STM_t::~core_commit_STM_t() {
    free(ROB);
}

void core_commit_STM_t::reg_stats(xiosim::stats::StatsDatabase* sdb) {
    int coreID = core->id;

    stat_reg_note(sdb, "\n#### COMMIT STATS ####");

    auto& sim_cycle_st = *stat_find_core_stat<tick_t>(sdb, coreID, "sim_cycle");
    auto& commit_insn_st = *stat_find_core_stat<counter_t>(sdb, coreID, "commit_insn");
    auto& commit_uops_st = *stat_find_core_stat<counter_t>(sdb, coreID, "commit_uops");

    stat_reg_core_formula(sdb, true, coreID, "commit_IPC", "IPC at commit",
                          commit_insn_st / sim_cycle_st, NULL);
    stat_reg_core_formula(sdb, true, coreID, "commit_uPC", "uPC at commit",
                          commit_uops_st / sim_cycle_st, NULL);
    stat_reg_core_formula(sdb, true, coreID, "avg_commit_flowlen",
                          "uops per instruction at commit", commit_uops_st / commit_insn_st, NULL);

    reg_core_queue_occupancy_stats(sdb, coreID, "ROB", &core->stat.ROB_occupancy,
                                   &core->stat.ROB_empty_cycles,
                                   &core->stat.ROB_full_cycles);

    core->stat.commit_stall = stat_reg_core_dist(
            sdb, coreID, "commit_stall", "breakdown of stalls at commit", 0, CSTALL_num,
            (PF_COUNT | PF_PDF), NULL, commit_stall_str, true, NULL);

    stat_reg_note(sdb, "#### TIMING STATS ####");
    /* instruction distribution stats */
    stat_reg_note(sdb, "\n#### INSTRUCTION STATS (no wrong-path) ####");
    stat_reg_core_formula(sdb, true, coreID, "num_insn", "total number of instructions committed",
                          commit_insn_st, NULL);
    auto& num_refs_st = stat_reg_core_counter(sdb, true, coreID, "num_refs",
                                              "total number of loads and stores committed",
                                              &core->stat.commit_refs, 0, true, NULL);
    auto& num_loads_st = stat_reg_core_counter(sdb, true, coreID, "num_loads",
                                               "total number of loads committed",
                                               &core->stat.commit_loads, 0, true, NULL);
    stat_reg_core_formula(sdb, true, coreID, "num_stores", "total number of stores committed",
                          num_refs_st - num_loads_st, "%12.0f");
}

void core_commit_STM_t::update_occupancy(void)
{
    /* ROB */
  core->stat.ROB_occupancy += ROB_num;
  if(ROB_num >= core->knobs->commit.ROB_size)
    core->stat.ROB_full_cycles++;
  if(ROB_num <= 0)
    core->stat.ROB_empty_cycles++;
}

/*************************/
/* MAIN COMMIT FUNCTIONS */
/*************************/

/* In-order instruction commit.  Individual uops cannot commit
   until it is guaranteed that the entire Mop's worth of uops will
   commit. */
void core_commit_STM_t::step(void)
{
  struct core_knobs_t * knobs = core->knobs;
  int commit_count = 0;
  enum commit_stall_t stall_reason = CSTALL_NONE;

  /* This is just a deadlock watchdog. If something got messed up
     in the pipeline and no forward progress is being made, this
     code will eventually detect it. A global watchdog will check
     if any core is making progress and accordingly if not.*/
  if(core->active && ((core->sim_cycle - core->exec->last_completed) > deadlock_threshold))
  {
    deadlocked = true;
#ifdef ZTRACE
    ztrace_print(core->id, "Possible deadlock detected.");
#endif
    return;
  }

  /* MAIN COMMIT LOOP */
  for(commit_count=0;commit_count<knobs->commit.width;commit_count++)
  {
    if(ROB_num <= 0) /* nothing to commit */
    {
      stall_reason = commit_count?CSTALL_NONE:CSTALL_EMPTY;
      break;
    }

    struct Mop_t * Mop = ROB[ROB_head]->Mop;

    if(Mop->oracle.spec_mode)
      fatal("oldest instruction in processor is on wrong-path");

    /* Are all uops in the Mop completed? */
    if(Mop->commit.complete_index != -1) /* still some outstanding insts */
    {
      while(Mop->uop[Mop->commit.complete_index].timing.when_completed <= core->sim_cycle)
      {
        struct uop_t * uop = &Mop->uop[Mop->commit.complete_index];

        Mop->commit.complete_index += uop->decode.has_imm ? 3 : 1;
        if(Mop->commit.complete_index >= (int) Mop->decode.flow_length)
        {
          Mop->commit.complete_index = -1; /* Mark this Mop as all done */
          if(Mop->fetch.bpred_update)
          {
            core->fetch->bpred->update(Mop->fetch.bpred_update, Mop->decode.opflags,
                Mop->fetch.PC, Mop->fetch.ftPC, Mop->decode.targetPC, Mop->oracle.NextPC, Mop->oracle.taken_branch);
            core->fetch->bpred->return_state_cache(Mop->fetch.bpred_update);
            Mop->fetch.bpred_update = NULL;
          }
          break;
        }
      }
    }

    if(Mop->commit.complete_index == -1) /* commit the uops if the Mop is done */
    {
      struct uop_t * uop = ROB[ROB_head];
      zesto_assert(uop->timing.when_completed <= core->sim_cycle,(void)0);
      zesto_assert(uop->alloc.ROB_index == ROB_head,(void)0);
      zesto_assert(uop == &Mop->uop[Mop->commit.commit_index],(void)0);

      if(uop->decode.BOM && (uop->Mop->timing.when_commit_started == TICK_T_MAX))
        uop->Mop->timing.when_commit_started = core->sim_cycle;

      if(uop->decode.is_load)
        core->exec->LDQ_deallocate(uop);
      else if(uop->decode.is_sta)
        core->exec->STQ_deallocate_sta();
      else if(uop->decode.is_std) /* we alloc on STA, dealloc on STD */
      {
        if(!core->exec->STQ_deallocate_std(uop))
          break;
      }

      /* any remaining transactions in-flight (only for loads)
         should now be ignored - such load requests may exist, for
         example as a result of a load that completes early due to
         a hit in the STQ while the cache request is still making
         its way through the memory hierarchy. */
      if(uop->decode.is_load)
        uop->exec.action_id = core->new_action_id();

      if(uop->decode.EOM)
        uop->Mop->timing.when_commit_finished = core->sim_cycle;

      /* remove uop from ROB */
      ROB[ROB_head] = NULL;
      ROB_num --;
      ROB_head = modinc(ROB_head,knobs->commit.ROB_size); //(ROB_head+1) % knobs->commit.ROB_size;
      uop->alloc.ROB_index = -1;

      /* this cleans up idep/odep ptrs, register mappings, and
         commit stores to the real (non-spec) memory system */
      core->oracle->commit_uop(uop);

      /* mark uop as committed in Mop */
      Mop->commit.commit_index += uop->decode.has_imm ? 3 : 1;

      if(Mop->commit.commit_index >= (int) Mop->decode.flow_length)
      {
        Mop->commit.commit_index = -1; /* The entire Mop has been committed */

        /* Update stats */
        if(Mop->uop[Mop->decode.last_uop_index].decode.EOM)
        {
          ZESTO_STAT(core->stat.commit_insn++;)
        }

        ZESTO_STAT(core->stat.commit_uops += Mop->stat.num_uops;)
        ZESTO_STAT(core->stat.commit_refs += Mop->stat.num_refs;)
        ZESTO_STAT(core->stat.commit_loads += Mop->stat.num_loads;)

        core->update_stopwatch(Mop);

        /* Let the oracle know that we are done with this Mop. */
        core->oracle->commit(Mop);
      }

    }
    else
    {
      if(Mop->commit.complete_index == 0)
        stall_reason = CSTALL_NOT_READY;
      else
        stall_reason = CSTALL_PARTIAL;
      break; /* oldest Mop not done yet */
    }
  }

  ZESTO_STAT(stat_add_sample(core->stat.commit_stall, (int)stall_reason);)
}

void core_commit_STM_t::IO_step()
{
  /* Compatibility: Simulation can call this */
}

/* Walk ROB from youngest uop until we find the requested Mop.
   (NOTE: We stop at any uop belonging to the Mop.  We assume
   that recovery only occurs on Mop boundaries.)
   Release resources (PREGs, RS/ROB/LSQ entries, etc. as we go).
   If Mop == NULL, we're blowing away the entire pipeline. */
void
core_commit_STM_t::recover(const struct Mop_t * const Mop)
{
  assert(Mop != NULL);
  struct core_knobs_t * knobs = core->knobs;
  if(ROB_num > 0)
  {
    /* requested uop should always be in the ROB */
    int index = moddec(ROB_tail,knobs->commit.ROB_size); //(ROB_tail-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;

    /* if there's only the one inst in the pipe, then we don't need to drain */
    if(knobs->alloc.drain_flush && (ROB[index]->Mop != Mop))
      core->alloc->start_drain();

    while(ROB[index] && (ROB[index]->Mop != Mop))
    {
      struct uop_t * dead_uop = ROB[index];

      zesto_assert(ROB_num > 0,(void)0);

      /* squash this instruction - this invalidates all in-flight actions (e.g., uop execution, cache accesses) */
      dead_uop->exec.action_id = core->new_action_id();

      /* update allocation scoreboard if appropriate */
      /* if(uop->alloc.RS_index != -1) */
      if(dead_uop->timing.when_issued == TICK_T_MAX && (dead_uop->alloc.port_assignment != -1))
        core->alloc->RS_deallocate(dead_uop);

      if(dead_uop->alloc.RS_index != -1) /* currently in RS */
        core->exec->RS_deallocate(dead_uop);

      /* In the following, we have to check it the uop has even been allocated yet... this has
         to do with our non-atomic implementation of allocation for fused-uops */
      if(dead_uop->decode.is_load)
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->LDQ_squash(dead_uop);
      }
      else if(dead_uop->decode.is_std) /* dealloc when we get to the STA */
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->STQ_squash_std(dead_uop);
      }
      else if(dead_uop->decode.is_sta)
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->STQ_squash_sta(dead_uop);
      }

      /* clean up idep/odep pointers.  Since we're working our
         way back from the most speculative instruction, we only
         need to clean-up our parent's forward-pointers (odeps)
         and our own back-pointers (our fwd-ptrs would have
         already cleaned-up our own children). */
      for(size_t i=0;i<MAX_IDEPS;i++)
      {
        struct uop_t * parent = dead_uop->exec.idep_uop[i];
        if(parent) /* I have an active parent */
        {
          struct odep_t * prev, * current;
          prev = NULL;
          current = parent->exec.odep_uop;
          while(current)
          {
            if((current->uop == dead_uop) && (current->op_num == (int)i))
              break;
            prev = current;
            current = current->next;
          }

          zesto_assert(current,(void)0);

          /* remove self from parent's odep list */
          if(prev)
            prev->next = current->next;
          else
            parent->exec.odep_uop = current->next;

          /* eliminate my own idep */
          dead_uop->exec.idep_uop[i] = NULL;

          /* return the odep struct */
          core->return_odep_link(current);
        }
      }

      zesto_assert(dead_uop->exec.odep_uop == NULL,(void)0);

      ROB[index] = NULL;
      ROB_tail = moddec(ROB_tail,knobs->commit.ROB_size); //(ROB_tail-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;
      ROB_num --;
      zesto_assert(ROB_num >= 0,(void)0);

      index = moddec(index,knobs->commit.ROB_size); //(index-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;
    }
  }
}

void
core_commit_STM_t::recover(void)
{
  struct core_knobs_t * knobs = core->knobs;
  if(ROB_num > 0)
  {
    /* requested uop should always be in the ROB */
    int index = moddec(ROB_tail,knobs->commit.ROB_size); //(ROB_tail-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;

    while(ROB[index])
    {
      struct uop_t * dead_uop = ROB[index];

      zesto_assert(ROB_num > 0,(void)0);

      /* squash this instruction - this invalidates all in-flight actions (e.g., uop execution, cache accesses) */
      dead_uop->exec.action_id = core->new_action_id();

      /* update allocation scoreboard if appropriate */
      if(dead_uop->timing.when_issued == TICK_T_MAX && (dead_uop->alloc.port_assignment != -1))
        core->alloc->RS_deallocate(dead_uop);

      if(dead_uop->alloc.RS_index != -1) /* currently in RS */
        core->exec->RS_deallocate(dead_uop);

      /* In the following, we have to check it the uop has even
         been allocated yet... this has to do with our non-atomic
         implementation of allocation for fused-uops */
      if(dead_uop->decode.is_load)
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->LDQ_squash(dead_uop);
      }
      else if(dead_uop->decode.is_std) /* dealloc when we get to the STA */
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->STQ_squash_std(dead_uop);
      }
      else if(dead_uop->decode.is_sta)
      {
        if(dead_uop->timing.when_allocated != TICK_T_MAX)
          core->exec->STQ_squash_sta(dead_uop);
      }

      /* clean up idep/odep pointers.  Since we're working our
         way back from the most speculative instruction, we only
         need to clean-up our parent's forward-pointers (odeps)
         and our own back-pointers (our fwd-ptrs would have
         already cleaned-up our own children). */
      for(size_t i=0;i<MAX_IDEPS;i++)
      {
        struct uop_t * parent = dead_uop->exec.idep_uop[i];
        if(parent) /* I have an active parent */
        {
          struct odep_t * prev, * current;
          prev = NULL;
          current = parent->exec.odep_uop;
          while(current)
          {
            if((current->uop == dead_uop) && (current->op_num == (int)i))
              break;
            prev = current;
            current = current->next;
          }

          zesto_assert(current,(void)0);

          /* remove self from parent's odep list */
          if(prev)
            prev->next = current->next;
          else
            parent->exec.odep_uop = current->next;

          /* eliminate my own idep */
          dead_uop->exec.idep_uop[i] = NULL;

          /* return the odep struct */
          core->return_odep_link(current);
        }
      }

      zesto_assert(dead_uop->exec.odep_uop == NULL,(void)0);

      ROB[index] = NULL;
      ROB_tail = moddec(ROB_tail,knobs->commit.ROB_size); //(ROB_tail-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;
      ROB_num --;
      zesto_assert(ROB_num >= 0,(void)0);

      index = moddec(index,knobs->commit.ROB_size); //(index-1+knobs->commit.ROB_size) % knobs->commit.ROB_size;
    }
  }

  core->exec->recover_check_assertions();
  zesto_assert(ROB_num == 0,(void)0);
}

bool core_commit_STM_t::ROB_available(void)
{
  struct core_knobs_t * knobs = core->knobs;
  return ROB_num < knobs->commit.ROB_size;
}

bool core_commit_STM_t::ROB_empty(void)
{
  return 0 == ROB_num;
}

bool core_commit_STM_t::pipe_empty(void)
{
  return 0 == ROB_num;
}

void core_commit_STM_t::ROB_insert(struct uop_t * const uop)
{
  struct core_knobs_t * knobs = core->knobs;
  ROB[ROB_tail] = uop;
  uop->alloc.ROB_index = ROB_tail;
  ROB_num++;
  ROB_tail = modinc(ROB_tail,knobs->commit.ROB_size); //(ROB_tail+1) % knobs->commit.ROB_size;
}

void core_commit_STM_t::ROB_fuse_insert(struct uop_t * const uop)
{
  fatal("fusion not supported in STM commit module");
}

/* Dummy fucntions for compatibility with IO pipe */
void core_commit_STM_t::pre_commit_insert(struct uop_t * const uop)
{
  fatal("shouldn't be called");
}
void core_commit_STM_t::pre_commit_fused_insert(struct uop_t * const uop)
{
  fatal("shouldn't be called");
}
bool core_commit_STM_t::pre_commit_available()
{
  fatal("shouldn't be called");
}
void core_commit_STM_t::pre_commit_step()
{
  /* Compatibility: simulation can call this */
}
void core_commit_STM_t::pre_commit_recover(struct Mop_t * const Mop)
{
  fatal("shouldn't be called");
}
void core_commit_STM_t::squash_uop(struct uop_t * const uop)
{
  fatal("shouldn't be called");
}

#endif


text:
package org.fusesource.fabric.camel.c24io;

import java.util.Map;

import biz.c24.io.api.data.ValidationConstraints;
import biz.c24.io.api.data.ValidationManager;

import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.impl.ProcessorEndpoint;

/**
 * @version $Revision$
 */
public class C24IOValidateComponent extends DefaultComponent {
    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {

        C24IOValidator validator = new C24IOValidator();
        Object bean = getCamelContext().getRegistry().lookup(remaining);
        if (bean instanceof ValidationManager) {
            ValidationManager validationManager = (ValidationManager)bean;
            validator.setValidationManager(validationManager);
        } else if (bean instanceof ValidationConstraints) {
            ValidationConstraints validationConstraints = (ValidationConstraints)bean;
            ValidationManager validationManager = new ValidationManager(validationConstraints);
            validator.setValidationManager(validationManager);
        } else if (bean != null) {
            throw new IllegalArgumentException("Bean " + remaining + " not an instance of ValidationManager or ValidationContraints");
        }
        return new ProcessorEndpoint(uri, this, validator);
    }
}

redpajama_set_name: RedPajamaGithub


text:
(function() {
  var DISABLED = 'DISABLED';
  var ArduinoHelper = require('../../lib/ArduinoHelper');

  var ROVPilot = function ROVPilot(deps) {
    console.log('The rovpilot plugin.');
    var self = this;
    self.SAMPLE_PERIOD = 1000 / deps.config.sample_freq;
    this.physics = new ArduinoHelper().physics;

    self.cockpit = deps.cockpit;
    self.globalEventLoop = deps.globalEventLoop;
    self.sendToROVEnabled = true;
    self.sendUpdateEnabled = true;
    self.priorControls = {};
    self.powerLevel = 2;
    self.setPowerLevel(2);
    //rov.powerLevel = 2;

    self.positions = {
      throttle: 0,
      yaw: 0,
      lift: 0,
      pitch: 0,
      roll: 0,
      strafe: 0
    };

    deps.cockpit.on('plugin.rovpilot.getState',function(callback){
      var state = {
        senToROVEnabled : self.sendToROVEnabled,
        sendUpdateEnabled : self.sendUpdateEnabled,
        powerLevel : self.powerLevel,
        positions: self.positions
      }
      callback(state);
    });

    deps.cockpit.on('plugin.rovpilot.setPowerLevel',function(value){
      self.setPowerLevel(value);
    });

    //Send initial state
    deps.cockpit.emit('plugin.rovpilot.setPowerLevel', 2);

    deps.cockpit.on('plugin.rovpilot.allStop', function () {
      self.allStop();
    });

    deps.cockpit.on('plugin.rovpilot.rates.setThrottle', function (value) {
      self.positions.throttle = value;
      if (value === 0) {
          self.positions.throttle = self.ttrim;
      }
    });

    deps.cockpit.on('plugin.rovpilot.rates.setYaw', function (value) {
      self.positions.yaw = value;
    });

    deps.cockpit.on('plugin.rovpilot.rates.setLift', function (value) {
      self.positions.lift = value;
    });

    deps.cockpit.on('plugin.rovpilot.rates.setPitch', function (value) {
      self.positions.pitch = value;
    });

    deps.cockpit.on('plugin.rovpilot.rates.setRoll', function (value) {
      self.positions.roll = value;
    });

    deps.cockpit.on('plugin.rovpilot.disable', function () {
      self.sendToROVEnabled = false;
    });

    deps.cockpit.on('plugin.rovpilot.enable', function () {
      self.sendToROVEnabled = true;
    });

    deps.cockpit.on('plugin.rovpilot.desiredControlRates', function (rates,ack,fn) {
      self.positions = rates;
//      console.log("this should be a callback!");
//      console.dir(fn);
//      fn(ack); //ack
    });

    this.startInterval  = function() {
      setInterval(
        function() {
          self.sendPilotingData();
        },
        25); //constantly check to see if new commands need to be sent to arduino
    };

    this.startInterval();

    return this;
  };

  // --------------------

  ROVPilot.prototype.adjustForPowerLimit = function adjustForPowerLimit(value){
    return value * this.power;
  }

  ROVPilot.prototype.adjustYawForPowerLimit = function adjustYawForPowerLimit(value){
    return Math.min(Math.max(value * this.power * 1.5,-1),1);
  }

  ROVPilot.prototype.setPowerLevel = function setPowerLevel(value) {

    switch (value) {
      case 1:
        this.power = 0.12;
        break;
      case 2:
        this.power = 0.25;
        break;
      case 3:
        this.power = 0.40;
        break;
      case 4:
        this.power = 0.70;
        break;
      case 5:
        this.power = 1;
        break;
    }

    this.powerLevel = value;
  };

  ROVPilot.prototype.allStop = function allStop() {
    this.positions.throttle = 0;
    this.positions.yaw = 0;
    this.positions.lift = 0;
    this.positions.pitch = 0;
    this.positions.roll = 0;
    this.postitions.strafe = 0;
  };

  ROVPilot.prototype.sendPilotingData = function() {
    var self = this;
    var positions = this.positions;
    var updateRequired = false;
    //Only send if there is a change
    var controls = {};
    controls.throttle = this.adjustForPowerLimit(positions.throttle);
    controls.yaw = this.adjustYawForPowerLimit(positions.yaw);
    controls.lift = this.adjustForPowerLimit(positions.lift);
    controls.pitch = this.adjustForPowerLimit(positions.pitch);
    controls.roll = this.adjustForPowerLimit(positions.roll);
    controls.strafe = this.adjustForPowerLimit(positions.strafe);
    for (var i in positions) {
      if (controls[i] != this.priorControls[i]) {
        updateRequired = true;
        break;
      }
    }
    if (this.sendUpdateEnabled && updateRequired || this.sendToROVEnabled === false) {
      if (this.sendToROVEnabled) {
        for(var control in controls){
          if(controls[control] != this.priorControls[control]){
            var command = control + '(' + controls[control] * 100+ ')';
            self.globalEventLoop.emit( 'mcu.SendCommand', command);
          //  console.log(command);
          }
        }
      }
      this.priorControls = controls;
      //report back the actual commands after power restrictions
      var motorCommands = this.physics.mapMotors(controls.throttle, controls.yaw, controls.lift);
      this.cockpit.emit('plugin.rovpilot.controls', motorCommands);
    }
  };

  ROVPilot.prototype.getSettingSchema = function getSettingSchema(){
    return [
      {
          "title": "ROV Pilot Settings",
          "id" : "rovpilot",
          "type": "object",
          "properties": {
              "exponentialSticks": {
                  "type": "boolean",
                  "title": "Use exponential gamepad sticks",
                  "default": false
              },
              "exponentialRate": {
                "type":"number",
                "title":"The expontetial rate for mapping the stick",
                "default":3
              }
          }
      }
    ]
  };

  module.exports = function (name, deps) {
    return new ROVPilot(deps);
  };

})();


text:
from mock import Mock, patch

from .. import record
from ...tests import TestGCP

@patch('cloudify_gcp.gcp.ServiceAccountCredentials.from_json_keyfile_dict')
@patch('cloudify_gcp.utils.get_gcp_resource_name', return_value='valid_name')
@patch('cloudify_gcp.gcp.build')
class TestGCPRecord(TestGCP):

    def setUp(self):
        super(TestGCPRecord, self).setUp()

        rel = Mock()
        rel.type = 'cloudify.gcp.relationships.dns_record_contained_in_zone'
        rel.target.instance.runtime_properties = {
                'name': 'target instance',
                'dnsName': 'example.com.',
                }
        self.ctxmock.instance.relationships = [rel]

    def test_create(self, mock_build, *args):
        mock_build().changes().create().execute.side_effect = [
                {'status': 'pending', 'id': u'🛂'},
                {'status': 'done'},
                ]

        mock_build().changes().get().execute.side_effect = [
                {'status': 'pending', 'id': u'🛂'},
                {'status': 'done'},
                ]

        record.create(
                'type',
                'name',
                'resources',
                'ttl',
                )

        mock_build().changes().create.assert_called_with(
                body={
                    'additions': [{
                        'rrdatas': 'resources',
                        'type': 'type',
                        'name': 'name.example.com.',
                        'ttl': 'ttl',
                        }]},
                managedZone='target instance',
                project='not really a project',
                )

    def test_create_with_instance(self, mock_build, *args):
        mock_build().changes().create().execute.side_effect = [
                {'status': 'done'},
                ]

        rel = Mock()
        rel.type = ('cloudify.gcp.relationships.'
                    'dns_record_connected_to_instance')
        rel.target.instance.runtime_properties = {
                'networkInterfaces': [{'accessConfigs': [{
                    'natIP': 'intellectual property',
                    }]}],
                }
        # rel_target is the Instance instance context. The instance itself must
        # be connected to an external IP, so we need to mock its relationships
        # too
        rel_rel = Mock()
        rel_rel.type = 'cloudify.gcp.relationships.instance_connected_to_ip'
        rel.target.instance.relationships = [rel_rel]
        self.ctxmock.instance.relationships.append(rel)

        record.create(
                'type',
                'name',
                [],
                'ttl',
                )

        mock_build().changes().create.assert_called_with(
                body={
                    'additions': [{
                        'rrdatas': ['intellectual property'],
                        'type': 'type',
                        'name': 'name.example.com.',
                        'ttl': 'ttl',
                        }]},
                managedZone='target instance',
                project='not really a project',
                )

    def test_delete(self, mock_build, *args):
        self.ctxmock.node.properties['type'] = 'A'
        self.ctxmock.instance.runtime_properties = {
                'created': True,
                'name': 'delete me',
                }

        mock_build().resourceRecordSets().list().execute.return_value = {
                'rrsets': ['rrs'],
                }
        mock_build().resourceRecordSets().list_next.return_value = None

        mock_build().changes().create().execute.side_effect = [
                {'status': 'pending', 'id': u'🛂'},
                {'status': 'done'},
                ]

        mock_build().changes().get().execute.side_effect = [
                {'status': 'pending', 'id': u'🛂'},
                {'status': 'done'},
                ]

        record.delete()

        mock_build().changes().create.assert_called_with(
                body={'deletions': ['rrs']},
                managedZone='target instance',
                project='not really a project',
                )

    def test_delete_deleted(self, mock_build, *args):
        record.delete()

        mock_build.assert_not_called()


text:
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'libsixel'

require 'minitest/autorun'


text:
module Spine
  module Mappings
    module Syntax
      module Integer
        def integer(destination, options = {}, &block)
          command = build(destination, options, &block)
          register(
            destination,
            intercept(command, options) { |value| value.to_i }
          )
        end
      end
    end
  end
end


text:
import fcntl
import os
import sys
import pickle
from pwd import getpwnam

HOST_MAPPING_PATH = '/var/tmp/disk_mapper/host.mapping'
HOST_MAPPING_LOCK_PATH = '/var/tmp/disk_mapper/host.mapping.lock'
USER = 'apache'

def read_mapping(filename):
    file_content = {}
    if os.path.exists(filename):
        f = open(filename)
        try:
            file_content = pickle.load(f)
        except:
            pass
        f.close()
    return file_content

def write_mapping(filename, data):
    if os.path.exists(filename):
        os.remove(filename)
        f = open(filename, 'w')
        pickle.dump(data, f)
        f.close()

def acquire_lock(lock_file):
    lockfd = open(lock_file, 'w')
    fcntl.flock(lockfd.fileno(), fcntl.LOCK_EX)
    return lockfd

def release_lock(fd):
    fcntl.flock(fd.fileno(), fcntl.LOCK_UN)
    fd.close()

def remove_mapping(hostname):
    lockfd = acquire_lock(HOST_MAPPING_LOCK_PATH)
    mapping = read_mapping(HOST_MAPPING_PATH)
    replaced = 0

    for srv, disks in mapping.items():
        for disk, roles in disks.items():
            for role, host in roles.items():
                if host == hostname:
			roles[role] = "%s-(disk-bad)" %(host)
                        replaced += 1
    if replaced == 0:
        print "Unable to find host in the mapping"
    elif replaced == 2:
        write_mapping(HOST_MAPPING_PATH, mapping)
        print "Successfully removed host from the mapping"
    else:
	print "Primary or Secondary of host cannot be found"

    release_lock(lockfd)

if __name__ == '__main__':

    if os.getuid() != 0:
        print "Please run as root"
        sys.exit(1)
    else:
        uid = getpwnam(USER).pw_uid
        os.seteuid(uid)

    if len(sys.argv) == 2:
        host = sys.argv[1]
        remove_mapping(host)
    else:
        print "Invalid args"
        print "Usage: %s hostname" %sys.argv[0]
        sys.exit(1)


text:
package org.hoteia.qalingo.web.mvc.controller.retailer;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.hoteia.qalingo.core.ModelConstants;
import org.hoteia.qalingo.core.RequestConstants;
import org.hoteia.qalingo.core.domain.Customer;
import org.hoteia.qalingo.core.domain.EngineSetting;
import org.hoteia.qalingo.core.domain.EngineSettingValue;
import org.hoteia.qalingo.core.domain.Retailer;
import org.hoteia.qalingo.core.domain.RetailerCustomerComment;
import org.hoteia.qalingo.core.domain.RetailerCustomerRate;
import org.hoteia.qalingo.core.domain.Retailer_;
import org.hoteia.qalingo.core.domain.enumtype.FoUrls;
import org.hoteia.qalingo.core.fetchplan.FetchPlan;
import org.hoteia.qalingo.core.fetchplan.SpecificFetchMode;
import org.hoteia.qalingo.core.i18n.enumtype.ScopeWebMessage;
import org.hoteia.qalingo.core.pojo.RequestData;
import org.hoteia.qalingo.core.service.EngineSettingService;
import org.hoteia.qalingo.core.service.RetailerService;
import org.hoteia.qalingo.core.web.mvc.form.CustomerCommentForm;
import org.hoteia.qalingo.core.web.servlet.ModelAndViewThemeDevice;
import org.hoteia.qalingo.core.web.servlet.view.RedirectView;
import org.hoteia.qalingo.web.mvc.controller.AbstractMCommerceController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 */
@Controller("retailerCommentController")
public class RetailerCommentController extends AbstractMCommerceController {

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    protected RetailerService retailerService;

    protected List<SpecificFetchMode> retailerFetchPlans = new ArrayList<SpecificFetchMode>();;

    public RetailerCommentController() {
        retailerFetchPlans.add(new SpecificFetchMode(Retailer_.attributes.getName()));
        retailerFetchPlans.add(new SpecificFetchMode(Retailer_.assets.getName()));
        retailerFetchPlans.add(new SpecificFetchMode(Retailer_.stores.getName()));
        retailerFetchPlans.add(new SpecificFetchMode(Retailer_.addresses.getName()));
    }

	@RequestMapping(value = FoUrls.RETAILER_VOTE_URL, method = RequestMethod.GET)
	public ModelAndView displayRetailerVoteForm(final HttpServletRequest request, @PathVariable(RequestConstants.URL_PATTERN_RETAILER_CODE) final String retailerCode,
												final Model model, @ModelAttribute("customerCommentForm") CustomerCommentForm customerCommentForm) throws Exception {
        return displayCustomerCommentForm(request, retailerCode, model, customerCommentForm);
	}

	@RequestMapping(value = FoUrls.RETAILER_COMMENT_URL, method = RequestMethod.GET)
	public ModelAndView displayCustomerCommentForm(final HttpServletRequest request, @PathVariable(RequestConstants.URL_PATTERN_RETAILER_CODE) final String retailerCode,
												   final Model model, @ModelAttribute("customerCommentForm") CustomerCommentForm customerCommentForm) throws Exception {
		ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request), FoUrls.RETAILER_COMMENT.getVelocityPage());

		model.addAttribute(ModelConstants.URL_BACK, urlService.generateUrl(FoUrls.HOME, requestUtil.getRequestData(request)));

		// STAR
		String qualityOfServiceMax = "5";
		EngineSetting engineSetting = engineSettingService.getSettingRetailerMaxScoreValue();
		if(engineSetting != null){
			qualityOfServiceMax = engineSetting.getDefaultValue();
			EngineSettingValue engineSettingValue = engineSetting.getEngineSettingValue(EngineSettingService.ENGINE_SETTING_CONTEXT_STAR_SCORE_MAX);
			if(engineSettingValue != null){
				qualityOfServiceMax = engineSettingValue.getValue();
			}
		}

		try {
			model.addAttribute(ModelConstants.QUALITY_OF_SERVICE_SCORE_MAX, Integer.parseInt(qualityOfServiceMax));
        } catch (Exception e) {
    		model.addAttribute(ModelConstants.QUALITY_OF_SERVICE_SCORE_MAX, 5);
        }

		// PRICE
		String priceMax = "5";
		if(engineSetting != null){
			priceMax = engineSetting.getDefaultValue();
			EngineSettingValue engineSettingValue = engineSetting.getEngineSettingValue(EngineSettingService.ENGINE_SETTING_CONTEXT_STAR_SCORE_MAX);
			if(engineSettingValue != null){
				priceMax = engineSettingValue.getValue();
			}
		}

		try {
			model.addAttribute(ModelConstants.PRICE_SCORE_MAX, Integer.parseInt(priceMax));
        } catch (Exception e) {
    		model.addAttribute(ModelConstants.PRICE_SCORE_MAX, 5);
        }

        final RequestData requestData = requestUtil.getRequestData(request);

		Retailer retailer = retailerService.getRetailerByCode(retailerCode, new FetchPlan(retailerFetchPlans));

		if(customerCommentForm == null
	    		|| customerCommentForm.equals(new CustomerCommentForm())){
			customerCommentForm = formFactory.buildCustomerCommentForm(requestData, retailer.getCode());
			model.addAttribute("retailerContactForm", customerCommentForm);
		}

		model.addAttribute("urlSubmit", urlService.generateUrl(FoUrls.RETAILER_COMMENT, requestData, retailer));

        overrideDefaultMainContentTitle(request, modelAndView, FoUrls.RETAILER_COMMENT.getKey());

        return modelAndView;
	}

	@RequestMapping(value = FoUrls.RETAILER_COMMENT_URL, method = RequestMethod.POST)
	public ModelAndView submitRetailerComment(final HttpServletRequest request, @PathVariable(RequestConstants.URL_PATTERN_RETAILER_CODE) final String retailerCode,
											  @Valid @ModelAttribute("customerCommentForm") CustomerCommentForm customerCommentForm,
								BindingResult result, final Model model) throws Exception {
        final RequestData requestData = requestUtil.getRequestData(request);
        final Locale locale = requestData.getLocale();

		if (result.hasErrors()) {
			return displayCustomerCommentForm(request, retailerCode, model, customerCommentForm);
		}

        int qualityOfService = customerCommentForm.getQualityOfService();
        int ratioQualityPrice = customerCommentForm.getRatioQualityPrice();
        int priceScore = customerCommentForm.getPriceScore();

		if (StringUtils.isEmpty(customerCommentForm.getComment())
				&& qualityOfService == 0
				&& ratioQualityPrice == 0
				&& priceScore == 0) {
			// WARNING
			addSessionInfoMessage(request, getSpecificMessage(ScopeWebMessage.RETAILER, "comment_form_empty_warning_message",  locale));
			return displayCustomerCommentForm(request, retailerCode, model, customerCommentForm);
		}

		final Retailer retailer = retailerService.getRetailerByCode(retailerCode, new FetchPlan(retailerFetchPlans));
		final Customer customer = requestData.getCustomer();

		if (qualityOfService != 0) {
			RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
			retailerCustomerRate.setRate(qualityOfService);
			retailerCustomerRate.setRetailerId(retailer.getId());
			retailerCustomerRate.setCustomerId(customer.getId());
			retailerCustomerRate.setType("QUALITY_OF_SERVICE");
			retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
		}

		if (ratioQualityPrice != 0) {
			RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
			retailerCustomerRate.setRate(ratioQualityPrice);
			retailerCustomerRate.setRetailerId(retailer.getId());
			retailerCustomerRate.setCustomerId(customer.getId());
			retailerCustomerRate.setType("RATIO_QUALITY_PRICE");
			retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
		}

		if (priceScore != 0) {
			RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
			retailerCustomerRate.setRate(priceScore);
			retailerCustomerRate.setRetailerId(retailer.getId());
			retailerCustomerRate.setCustomerId(customer.getId());
			retailerCustomerRate.setType("PRICE_SCORE");
			retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
		}

		if (StringUtils.isNotEmpty(customerCommentForm.getComment())) {
			RetailerCustomerComment retailerCustomerComment = new RetailerCustomerComment();
			retailerCustomerComment.setComment(customerCommentForm.getComment());
			retailerCustomerComment.setRetailer(retailer);
			retailerCustomerComment.setCustomer(customer);
			retailerService.saveOrUpdateRetailerCustomerComment(retailerCustomerComment);
		}

		addSessionSuccessMessage(request, getSpecificMessage(ScopeWebMessage.RETAILER, "comment_form_success_message",  locale));

		final String urlRedirect = urlService.generateRedirectUrl(FoUrls.RETAILER_DETAILS, requestUtil.getRequestData(request), retailer);
        return new ModelAndView(new RedirectView(urlRedirect));
	}

}


text:
<?php

/**
 * @namespace
 */
namespace ZendTest\Pdf\InternalType;
use Zend\Pdf\InternalType;
use Zend\Pdf;

/**
 * \Zend\Pdf\InternalType\DictionaryObject
 */

/**
 * PHPUnit Test Case
 */

/**
 * @category   Zend
 * @package    Zend_PDF
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_PDF
 */
class DictionaryTest extends \PHPUnit_Framework_TestCase
{
    public function testPDFDictionary1()
    {
        $dictionaryObj = new InternalType\DictionaryObject();
        $this->assertTrue($dictionaryObj instanceof InternalType\DictionaryObject);
    }

    public function testPDFDictionary2()
    {
        $srcArray = array();
        $srcArray['Bool'] = new InternalType\BooleanObject(false);
        $srcArray['Number'] = new InternalType\NumericObject(100.426);
        $srcArray['Name'] = new InternalType\NameObject('MyName');
        $srcArray['Text'] = new InternalType\StringObject('some text');
        $srcArray['BinaryText'] = new InternalType\BinaryStringObject('some text');

        $dictionaryObj = new InternalType\DictionaryObject($srcArray);
        $this->assertTrue($dictionaryObj instanceof InternalType\DictionaryObject);
    }

    public function testPDFDictionaryBadInput1()
    {
        try {
            $arrayObj = new InternalType\DictionaryObject(346);
        } catch (Pdf\Exception $e) {
            $this->assertContains('must be an array', $e->getMessage());
            return;
        }
        $this->fail('Expected \Zend\Pdf\Exception to be thrown');
    }

    public function testPDFDictionaryBadInput2()
    {
        try {
            $srcArray = array();
            $srcArray['Bool'] = new InternalType\BooleanObject(false);
            $srcArray['Number'] = new InternalType\NumericObject(100.426);
            $srcArray['Name'] = new InternalType\NameObject('MyName');
            $srcArray['Text'] = new InternalType\StringObject('some text');
            $srcArray['BinaryText'] = new InternalType\BinaryStringObject('some text');
            $srcArray['bad value'] = 24;
            $dictionaryObj = new InternalType\DictionaryObject($srcArray);
        } catch (Pdf\Exception $e) {
            $this->assertContains('must be \Zend\Pdf\InternalType', $e->getMessage());
            return;
        }
        $this->fail('Expected \Zend\Pdf\Exception to be thrown');
    }

    public function testPDFDictionaryBadInput3()
    {
        try {
            $srcArray = array();
            $srcArray['Bool'] = new InternalType\BooleanObject(false);
            $srcArray['Number'] = new InternalType\NumericObject(100.426);
            $srcArray['Name'] = new InternalType\NameObject('MyName');
            $srcArray['Text'] = new InternalType\StringObject('some text');
            $srcArray['BinaryText'] = new InternalType\BinaryStringObject('some text');
            $srcArray[5] = new InternalType\StringObject('bad name');
            $dictionaryObj = new InternalType\DictionaryObject($srcArray);
        } catch (Pdf\Exception $e) {
            $this->assertContains('keys must be strings', $e->getMessage());
            return;
        }
        $this->fail('Expected \Zend\Pdf\Exception to be thrown');
    }

    public function testGetType()
    {
        $dictionaryObj = new InternalType\DictionaryObject();
        $this->assertEquals($dictionaryObj->getType(), InternalType\AbstractTypeObject::TYPE_DICTIONARY);
    }

    public function testToString()
    {
        $srcArray = array();
        $srcArray['Bool'] = new InternalType\BooleanObject(false);
        $srcArray['Number'] = new InternalType\NumericObject(100.426);
        $srcArray['Name'] = new InternalType\NameObject('MyName');
        $srcArray['Text'] = new InternalType\StringObject('some text');
        $srcArray['BinaryText'] = new InternalType\BinaryStringObject("\x01\x02\x00\xff");
        $dictionaryObj = new InternalType\DictionaryObject($srcArray);
        $this->assertEquals($dictionaryObj->toString(),
                            '<</Bool false /Number 100.426 /Name /MyName /Text (some text) /BinaryText <010200FF> >>');
    }

    public function testAdd()
    {
        $dictionaryObj = new InternalType\DictionaryObject();
        $dictionaryObj->add(new InternalType\NameObject('Var1'), new InternalType\BooleanObject(false));
        $dictionaryObj->add(new InternalType\NameObject('Var2'), new InternalType\NumericObject(100.426));
        $dictionaryObj->add(new InternalType\NameObject('Var3'), new InternalType\NameObject('MyName'));
        $dictionaryObj->add(new InternalType\NameObject('Var4'), new InternalType\StringObject('some text'));
        $this->assertEquals($dictionaryObj->toString(),
                            '<</Var1 false /Var2 100.426 /Var3 /MyName /Var4 (some text) >>');
    }

}


text:
.class public abstract Lcom/google/android/gms/internal/cd$a;
.super Landroid/os/Binder;

# interfaces
.implements Lcom/google/android/gms/internal/cd;

# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/google/android/gms/internal/cd;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x409
    name = "a"
.end annotation

.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/google/android/gms/internal/cd$a$a;
    }
.end annotation

# direct methods
.method public constructor <init>()V
    .locals 1

    invoke-direct {p0}, Landroid/os/Binder;-><init>()V

    const-string v0, "com.google.android.gms.ads.internal.request.IAdRequestService"

    invoke-virtual {p0, p0, v0}, Lcom/google/android/gms/internal/cd$a;->attachInterface(Landroid/os/IInterface;Ljava/lang/String;)V

    return-void
.end method

.method public static q(Landroid/os/IBinder;)Lcom/google/android/gms/internal/cd;
    .locals 2

    if-nez p0, :cond_0

    const/4 v0, 0x0

    return-object v0

    :cond_0
    const-string v0, "com.google.android.gms.ads.internal.request.IAdRequestService"

    invoke-interface {p0, v0}, Landroid/os/IBinder;->queryLocalInterface(Ljava/lang/String;)Landroid/os/IInterface;

    move-result-object v0

    move-object v1, v0

    if-eqz v0, :cond_1

    instance-of v0, v1, Lcom/google/android/gms/internal/cd;

    if-eqz v0, :cond_1

    move-object v0, v1

    check-cast v0, Lcom/google/android/gms/internal/cd;

    return-object v0

    :cond_1
    new-instance v0, Lcom/google/android/gms/internal/cd$a$a;

    invoke-direct {v0, p0}, Lcom/google/android/gms/internal/cd$a$a;-><init>(Landroid/os/IBinder;)V

    return-object v0
.end method

# virtual methods
.method public asBinder()Landroid/os/IBinder;
    .locals 0

    return-object p0
.end method

.method public onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
    .locals 2

    sparse-switch p1, :sswitch_data_0

    goto :goto_2

    :sswitch_data_0
    .sparse-switch
        0x1 -> :sswitch_1
        0x5f4e5446 -> :sswitch_0
    .end sparse-switch

    :sswitch_0
    const-string v0, "com.google.android.gms.ads.internal.request.IAdRequestService"

    invoke-virtual {p3, v0}, Landroid/os/Parcel;->writeString(Ljava/lang/String;)V

    const/4 v0, 0x1

    return v0

    :sswitch_1
    const-string v0, "com.google.android.gms.ads.internal.request.IAdRequestService"

    invoke-virtual {p2, v0}, Landroid/os/Parcel;->enforceInterface(Ljava/lang/String;)V

    invoke-virtual {p2}, Landroid/os/Parcel;->readInt()I

    move-result v0

    const/4 v1, 0x0

    if-eq v1, v0, :cond_0

    sget-object v0, Lcom/google/android/gms/internal/bz;->CREATOR:Lcom/google/android/gms/internal/ca;

    invoke-virtual {v0, p2}, Lcom/google/android/gms/internal/ca;->f(Landroid/os/Parcel;)Lcom/google/android/gms/internal/bz;

    move-result-object p1

    goto :goto_0

    :cond_0
    const/4 p1, 0x0

    :goto_0
    invoke-virtual {p0, p1}, Lcom/google/android/gms/internal/cd$a;->b(Lcom/google/android/gms/internal/bz;)Lcom/google/android/gms/internal/cb;

    move-result-object p1

    invoke-virtual {p3}, Landroid/os/Parcel;->writeNoException()V

    if-eqz p1, :cond_1

    const/4 v0, 0x1

    invoke-virtual {p3, v0}, Landroid/os/Parcel;->writeInt(I)V

    const/4 v0, 0x1

    invoke-virtual {p1, p3, v0}, Lcom/google/android/gms/internal/cb;->writeToParcel(Landroid/os/Parcel;I)V

    goto :goto_1

    :cond_1
    const/4 v0, 0x0

    invoke-virtual {p3, v0}, Landroid/os/Parcel;->writeInt(I)V

    :goto_1
    const/4 v0, 0x1

    return v0

    :goto_2
    invoke-super {p0, p1, p2, p3, p4}, Landroid/os/Binder;->onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z

    move-result v0

    return v0
.end method


text:
GrownAssAdultBlog
=================

Person blog which is used as a brain dump.


text:
#ifndef PopupMenuChromium_h
#define PopupMenuChromium_h

#include "config.h"

#include "FramelessScrollView.h"
#include "IntRect.h"
#include "PlatformString.h"
#include "PopupMenu.h"
#include "PopupMenuPrivate.h"
#include "PopupMenuStyle.h"

namespace WebCore {

class ChromeClientChromium;
class FrameView;
class PopupListBox;
class PopupMenuClient;

// A container for the data for each menu item (e.g. represented by <option>
// or <optgroup> in a <select> widget) and is used by PopupListBox.
struct PopupItem {
    enum Type {
        TypeOption,
        TypeGroup,
        TypeSeparator
    };

    PopupItem(const String& label, Type type)
        : label(label)
        , type(type)
        , yOffset(0)
    {
    }
    String label;
    Type type;
    int yOffset; // y offset of this item, relative to the top of the popup.
    TextDirection textDirection;
    bool hasTextDirectionOverride;
    bool enabled;
};

// FIXME: Our FramelessScrollView classes should probably implement HostWindow!

// The PopupContainer class holds a PopupListBox (see cpp file).  Its sole purpose is to be
// able to draw a border around its child.  All its paint/event handling is
// just forwarded to the child listBox (with the appropriate transforms).
// NOTE: this class is exposed so it can be instantiated direcly for the
// autofill popup.  We cannot use the Popup class directly in that case as the
// autofill popup should not be focused when shown and we want to forward the
// key events to it (through handleKeyEvent).

struct PopupContainerSettings {
    // Whether the PopupMenuClient should be told to change its text when a
    // new item is selected by using the arrow keys.
    bool setTextOnIndexChange;

    // Whether the selection should be accepted when the popup menu is
    // closed (through ESC being pressed or the focus going away).
    // Note that when TAB is pressed, the selection is always accepted
    // regardless of this setting.
    bool acceptOnAbandon;

    // Whether we should move the selection to the first/last item when
    // the user presses down/up arrow keys and the last/first item is
    // selected.
    bool loopSelectionNavigation;

    // Whether we should restrict the width of the PopupListBox or not.
    // Autocomplete popups are restricted, combo-boxes (select tags) aren't.
    bool restrictWidthOfListBox;
};

class PopupContainer : public FramelessScrollView {
public:
    enum PopupType {
        Select, // HTML select popup.
        Suggestion, // Autocomplete/autofill popup.
    };

    static PassRefPtr<PopupContainer> create(PopupMenuClient*, PopupType,
                                             const PopupContainerSettings&);

    // Whether a key event should be sent to this popup.
    virtual bool isInterestedInEventForKey(int keyCode);

    // FramelessScrollView
    virtual void paint(GraphicsContext*, const IntRect&);
    virtual void hide();
    virtual bool handleMouseDownEvent(const PlatformMouseEvent&);
    virtual bool handleMouseMoveEvent(const PlatformMouseEvent&);
    virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&);
    virtual bool handleWheelEvent(const PlatformWheelEvent&);
    virtual bool handleKeyEvent(const PlatformKeyboardEvent&);

    // PopupContainer methods

    // Show the popup
    void showPopup(FrameView*);

    // Show the popup in the specified rect for the specified frame.
    // Note: this code was somehow arbitrarily factored-out of the Popup class
    // so WebViewImpl can create a PopupContainer. This method is used for
    // displaying auto complete popup menus on Mac Chromium, and for all
    // popups on other platforms.
    void showInRect(const IntRect&, FrameView*, int index);

    // Hides the popup.
    void hidePopup();

    // The popup was hidden.
    void notifyPopupHidden();

    // Compute size of widget and children. Return right offset for RTL.
    int layoutAndGetRightOffset();

    PopupListBox* listBox() const { return m_listBox.get(); }

    // Gets the index of the item that the user is currently moused-over or
    // has selected with the keyboard up/down arrows.
    int selectedIndex() const;

    // Refresh the popup values from the PopupMenuClient.
    void refresh(const IntRect& targetControlRect);

    // The menu per-item data.
    const WTF::Vector<PopupItem*>& popupData() const;

    // The height of a row in the menu.
    int menuItemHeight() const;

    // The size of the font being used.
    int menuItemFontSize() const;

    // The style of the menu being used.
    PopupMenuStyle menuStyle() const;

    PopupType popupType() const { return m_popupType; }

private:
    friend class WTF::RefCounted<PopupContainer>;

    PopupContainer(PopupMenuClient*, PopupType popupType, const PopupContainerSettings&);
    ~PopupContainer();

    // Paint the border.
    void paintBorder(GraphicsContext*, const IntRect&);

    // Layout and calculate popup widget size and location and returns it as IntRect.
    IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntPoint& popupInitialCoordinate);

    // Returns the ChromeClient of the page this popup is associated with.
    ChromeClientChromium* chromeClientChromium();

    RefPtr<PopupListBox> m_listBox;
    RefPtr<FrameView> m_frameView;

    PopupContainerSettings m_settings;
    PopupType m_popupType;
    // Whether the popup is currently open.
    bool m_popupOpen;
};

class PopupMenuChromium : public PopupMenu {
public:
    PopupMenuChromium(PopupMenuClient*);
    ~PopupMenuChromium();

    virtual void show(const IntRect&, FrameView*, int index);
    virtual void hide();
    virtual void updateFromElement();
    virtual void disconnectClient();

private:
    PopupMenuClient* client() const { return m_popupClient; }

    PopupMenuClient* m_popupClient;
    PopupMenuPrivate p;
};

} // namespace WebCore

#endif


text:
<?php

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

/* @var $this yii\web\View */
/* @var $model kozlovsv\crud\modules\auth\models\AuthItem */
/* @var $form yii\widgets\ActiveForm */
?>
<?php Pjax::begin(); ?>
    <?php $form = ActiveForm::begin([
        'action' => 'create',
        'layout' => 'horizontal',
        'options' => [
            'data-pjax' => 1,
        ],
    ]); ?>
        <?= $form->field($model, 'description')->textInput() ?>
        <div class="text-right">
            <?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
        </div>
    <?php ActiveForm::end(); ?>
<?php Pjax::end() ?>


text:
package benchmarkdp.datagenerator.mappers;

import java.io.File;

import benchmarkdp.datagenerator.properties.ExperimentProperties;
import org.apache.commons.configuration2.XMLConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;

public class PropertiesMapper {

	// the most recent configuration
	FileBasedConfigurationBuilder<XMLConfiguration> builder;
	XMLConfiguration xmlC;

	public PropertiesMapper() {
	}

	public ExperimentProperties loadProperties(String file) {
		Configurations configs = new Configurations();
		ExperimentProperties prop = new ExperimentProperties();
		String s = calculateAbsoluteFolder(file);
		prop.setFullFolderPath(s);
		try {
			builder = configs.xmlBuilder(file);
			xmlC = builder.getConfiguration();
			String en = xmlC.getString("experimentName");
			prop.setExperimentName(en);
			String es = xmlC.getString("experimentState");
			prop.setExperimentState(es);
			String tcN = xmlC.getString("testCaseNumber");
			prop.setTestCaseNumber(Integer.parseInt(tcN));
			String mutationSettings = xmlC.getString("mutationPlatformSettings");
			prop.setMutationPlatformSettings(mutationSettings);
			String formatSettings = xmlC.getString("mutationFormatSettings");
			prop.setMutationFormatSettings(formatSettings);

			if (es.compareTo("START") != 0) {
				prop.setDocumentFolder(xmlC.getString("folderPath.Documents"));
				prop.setResultsFolder(xmlC.getString("folderPath.Results"));
				prop.setFitsFolder(xmlC.getString("folderPath.Fits"));
				prop.setToolOutputFolder(xmlC.getString("folderPath.ToolOutput"));
				prop.setGroundTruthFolder(xmlC.getString("folderPath.GroundTruth"));
				prop.setMetadataFolder(xmlC.getString("folderPath.Metadata"));
				prop.setModelMetadataFolder(xmlC.getString("folderPath.ModelMetadata"));
				prop.setGeneratedMetadataFolder(xmlC.getString("folderPath.GeneratedMetadata"));
				prop.setTextFolder(xmlC.getString("folderPath.Text"));
				prop.setModelTextFolder(xmlC.getString("folderPath.ModelText"));
				prop.setGeneratedTextFolder(xmlC.getString("folderPath.GeneratedText"));
				prop.setModelsFolder(xmlC.getString("folderPath.Models"));
				prop.setMacroFolder(xmlC.getString("folderPath.Macro"));
			}
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return prop;
	}

	public void saveProperties(ExperimentProperties prop) {
		try {
			xmlC.setProperty("experimentState", prop.getExperimentState());
			if (prop.getDocumentFolder() != null) {
				xmlC.setProperty("folderPath.Documents", prop.getDocumentFolder());
				xmlC.setProperty("folderPath.Results", prop.getResultsFolder());
				xmlC.setProperty("folderPath.Fits", prop.getFitsFolder());
				xmlC.setProperty("folderPath.ToolOutput", prop.getToolOutputFolder());
				xmlC.setProperty("folderPath.GroundTruth", prop.getGroundTruthFolder());
				xmlC.setProperty("folderPath.Metadata", prop.getMetadataFolder());
				xmlC.setProperty("folderPath.ModelMetadata", prop.getModelMetadataFolder());
				xmlC.setProperty("folderPath.GeneratedMetadata", prop.getGeneratedMetadataFolder());
				xmlC.setProperty("folderPath.Text", prop.getTextFolder());
				xmlC.setProperty("folderPath.ModelText", prop.getModelTextFolder());
				xmlC.setProperty("folderPath.GeneratedText", prop.getGeneratedTextFolder());
				xmlC.setProperty("folderPath.Models", prop.getModelsFolder());
				xmlC.setProperty("folderPath.Macro", prop.getMacroFolder());
			}
			builder.save();
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private String calculateAbsoluteFolder(String file) {
		File f = new File(file);
		String s = f.getAbsolutePath();
		s = s.substring(0, s.lastIndexOf(File.separator)) + File.separator;
		return s;
	}
}


text:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using HtmlAgilityPack;
using IQAppProvisioningBaseClasses;
using IQAppProvisioningBaseClasses.Provisioning;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;
using Microsoft.SharePoint.Client.WebParts;
using ScrapySharp.Extensions;
using File = Microsoft.SharePoint.Client.File;
using static IQAppProvisioningBaseClasses.Constants;

namespace IQAppManifestBuilders
{
    public class FoldersAndFileCreator
    {
        public virtual List<string> Folders { get; set; }
        public virtual Dictionary<string, FileCreator> FileCreators { get; set; }
    }

    public class FileCreatorBuilder : CreatorBuilderBase
    {
        public NetworkCredential RequestContextCredentials { get; set; }

        public AppManifestBase GetFileCreator(ClientContext ctx, Web web, string fileWebRelativeUrl,
            string downloadFolderPath)
        {
            return GetFileCreator(ctx, web, fileWebRelativeUrl, downloadFolderPath, string.Empty, false);
        }

        public AppManifestBase GetFileCreator(ClientContext ctx, Web web, string fileWebRelativeUrl,
            string downloadFolderPath, string appManifestJson, bool getRelatedFileCreators)
        {
            var js = new JavaScriptSerializer();

            var existingManifest = js.Deserialize<AppManifestBase>(appManifestJson);

            return GetFileCreator(ctx, web, fileWebRelativeUrl, downloadFolderPath, existingManifest,
                getRelatedFileCreators);
        }

        public AppManifestBase GetFileCreator(ClientContext ctx, Web web, string fileWebRelativeUrl,
            string downloadFolderPath, AppManifestBase existingManifest, bool getRelatedFileCreators)
        {
            if (!fileWebRelativeUrl.StartsWith("/")) fileWebRelativeUrl = "/" + fileWebRelativeUrl;
            fileWebRelativeUrl = fileWebRelativeUrl.Replace("%20", " ");
            OnVerboseNotify("Getting file creator for " + fileWebRelativeUrl);

            if (string.IsNullOrEmpty(downloadFolderPath))
            {
                downloadFolderPath = existingManifest.BaseFilePath;
            }

            existingManifest = existingManifest ?? new AppManifestBase();
            existingManifest.FileCreators = existingManifest.FileCreators ?? new Dictionary<string, FileCreator>();
            existingManifest.Folders = existingManifest.Folders ?? new List<string>();

            var fileCreator = GetFoldersAndFileCreatorFromSite(ctx, web, fileWebRelativeUrl, downloadFolderPath,
                getRelatedFileCreators, existingManifest);
            if (fileCreator == null)
            {
                return existingManifest;
            }
            if (fileCreator.FileCreators.ContainsKey(fileWebRelativeUrl))
            {
                existingManifest.FileCreators[fileWebRelativeUrl] = fileCreator.FileCreators[fileWebRelativeUrl];
                foreach (var folder in fileCreator.Folders)
                {
                    if (!existingManifest.Folders.Contains(folder)) existingManifest.Folders.Add(folder);
                }
                existingManifest.Folders.Sort();
            }

            return existingManifest;
        }

        public AppManifestBase RemoveFileCreator(ClientContext ctx, Web web, string fileWebRelativeUrl,
            AppManifestBase existingManifest)
        {
            if (!fileWebRelativeUrl.StartsWith("/")) fileWebRelativeUrl = "/" + fileWebRelativeUrl;
            fileWebRelativeUrl = fileWebRelativeUrl.Replace("%20", " ");

            if (existingManifest?.FileCreators == null || !existingManifest.FileCreators.ContainsKey(fileWebRelativeUrl))
                return existingManifest;

            existingManifest.FileCreators.Remove(fileWebRelativeUrl);

            if (existingManifest.StorageType == StorageTypes.AzureStorage)
            {
                var azureStorageInfo = existingManifest.GetAzureStorageInfo();
                var blobStorage = new BlobStorage(azureStorageInfo.Account, azureStorageInfo.AccountKey,
                    azureStorageInfo.Container);
                blobStorage.DeleteBlob(fileWebRelativeUrl);
            }
            //TODO: File system deletion

            return existingManifest;
        }

        private FoldersAndFileCreator GetFoldersAndFileCreatorFromSite(ClientContext ctx, Web web,
            string fileWebRelativeUrl, string downloadFolderPath, bool getRelatedFileCreators,
            AppManifestBase appManifest)
        {
            OnVerboseNotify("Getting file from site " + fileWebRelativeUrl);

            var retVal = new FoldersAndFileCreator
            {
                Folders = new List<string>(),
                FileCreators = new Dictionary<string, FileCreator>()
            };
            if (!fileWebRelativeUrl.StartsWith("/")) fileWebRelativeUrl = "/" + fileWebRelativeUrl;

            var parts = fileWebRelativeUrl.Split('/');
            var lastFolder = string.Empty;
            for (var i = 1; i < parts.Length - 1; i++)
            {
                lastFolder = lastFolder + "/" + parts[i];
                retVal.Folders.Add(lastFolder);
            }

            ctx.Load(web, w => w.ServerRelativeUrl);
            ctx.ExecuteQueryRetry();

            var fileUrl = fileWebRelativeUrl;
            if (web.ServerRelativeUrl != "/") fileUrl = web.ServerRelativeUrl + fileWebRelativeUrl;

            //Get the file
            var file = web.GetFileByServerRelativeUrl(fileUrl);
            ctx.Load(file, f => f.Exists);
            ctx.ExecuteQueryRetry();

            if (file.Exists)
            {
                OnVerboseNotify("Got file from site " + fileWebRelativeUrl);

                //Try to load the list items, if the list doesn't exist, ie. it's a folder there will be an exception
                ctx.Load(file, f => f.ListItemAllFields);
                ctx.Load(file.ListItemAllFields, l => l.ParentList, l => l.HasUniqueRoleAssignments,
                    l => l.FieldValuesForEdit, l => l.ContentType);

                var couldGetListItem = false;
                try
                {
                    ctx.ExecuteQueryRetry();
                    couldGetListItem = file.ListItemAllFields.ServerObjectIsNull != null &&
                                       !(bool)file.ListItemAllFields.ServerObjectIsNull;
                }
                catch
                {
                    // ignored
                }

                var fileName = parts[parts.Length - 1];

                retVal.FileCreators.Add(fileWebRelativeUrl, new FileCreator
                {
                    Name = fileName,
                    ForceOverwrite = true,
                    Url = fileWebRelativeUrl
                });

                var newFileCreator = retVal.FileCreators[fileWebRelativeUrl];

                newFileCreator.RelativeFilePath = fileWebRelativeUrl.Replace(@"/", @"\");

                if (couldGetListItem && file.ListItemAllFields.FieldValues.Count > 0)
                {
                    newFileCreator.List = file.ListItemAllFields.ParentList.Title;
                    AnalyzeSecurityConfiguration(newFileCreator, file.ListItemAllFields, ctx);

                    var listItemCreatorBuilder = new ListItemCreatorBuilder(ctx, web, file.ListItemAllFields.ParentList);

                    newFileCreator.ListItemFieldValues = listItemCreatorBuilder.GetListItemCreator(file.ListItemAllFields).FieldValues;

                    //Some item types have a list value, but a server null content type, such as dwp files
                    if (file.ListItemAllFields.ContentType.ServerObjectIsNull != true)
                    {
                        newFileCreator.ContentType = file.ListItemAllFields.ContentType.Name;
                        newFileCreator.ContentTypeId = file.ListItemAllFields.ContentType.StringId;

                        if (newFileCreator.ContentTypeId.StartsWith(WikiPageContentTypeId) || newFileCreator.ContentTypeId.StartsWith(PublishingPageContentTypeId))
                        {
                            var contentFieldName = newFileCreator.ContentTypeId.StartsWith(WikiPageContentTypeId) ? WikiPageContentFieldName : PublishingPageContentFieldName;
                            ProcessWikiOrPublishingPage(ctx, web, fileUrl, file, contentFieldName, newFileCreator);

                            if (getRelatedFileCreators)
                            {
                                var contentField = file.ListItemAllFields[contentFieldName]?.ToString() ?? string.Empty;
                                GetRelatedFileCreators(ctx, web, appManifest, downloadFolderPath, contentField);
                            }

                            newFileCreator.IsHomePage = IsHomePage(ctx, fileUrl);

                            //Wiki pages don't get downloaded, they are created from a template
                            return retVal;
                        }
                        //0x010107 is declarative workflow document
                        if (file.ListItemAllFields.ContentType.Id.StringValue.StartsWith(DeclarativeWorkflowDocumentContentTypeId))
                        {
                            DownloadWorkflowFile(ctx, web, downloadFolderPath, fileUrl, newFileCreator, appManifest);
                            newFileCreator.ContentType = "Workflow";
                            return retVal;
                        }
                    }
                }
                if (fileName.ToLowerInvariant().EndsWith(".aspx"))
                {
                    var listIds = GetWebListIds(ctx, web);
                    ProcessWebPartPage(ctx, web, fileUrl, file, newFileCreator, listIds);
                    DownloadAspxFile(ctx, downloadFolderPath, fileUrl, newFileCreator, listIds, appManifest);
                    if (newFileCreator.WebParts != null && newFileCreator.WebParts.Count > 0)
                    {
                        newFileCreator.ContentType = "Web Part Page";
                    }
                    newFileCreator.IsHomePage = IsHomePage(ctx, newFileCreator.Url);
                }
                else
                {
                    var listIds = GetWebListIds(ctx, web);
                    DownloadFile(ctx, downloadFolderPath, fileUrl, newFileCreator, listIds, appManifest);
                }
            }

            return retVal;
        }

        private bool IsHomePage(ClientContext ctx, string fileUrl)
        {
            var rootFolder = ctx.Web.RootFolder;
            ctx.Load(rootFolder, f => f.WelcomePage);
            ctx.ExecuteQueryRetry();
            return !string.IsNullOrEmpty(rootFolder.WelcomePage.ToLower()) &&
                   (rootFolder.WelcomePage.ToLower().EndsWith(fileUrl.ToLower()) ||
                    fileUrl.ToLower().EndsWith(rootFolder.WelcomePage.ToLower()));
        }

        private void GetRelatedFileCreators(ClientContext ctx, Web web, AppManifestBase appManifest,
            string downloadFolderPath, string pageContent)
        {
            OnVerboseNotify("Looking for related files from page content");
            var pageContentHtmlDoc = new HtmlDocument();
            pageContentHtmlDoc.LoadHtml(pageContent);

            var anchors = pageContentHtmlDoc.DocumentNode.CssSelect("a");
            var images = pageContentHtmlDoc.DocumentNode.CssSelect("img");

            foreach (var anchor in anchors)
            {
                var url = anchor.Attributes["href"].Value;
                if (web.ServerRelativeUrl != "/") url = url.Replace(web.ServerRelativeUrl, "");
                ProcessRelatedFile(ctx, web, appManifest, downloadFolderPath, url);
            }
            foreach (var img in images)
            {
                var url = img.Attributes["src"].Value;
                if (web.ServerRelativeUrl != "/") url = url.Replace(web.ServerRelativeUrl, "");
                ProcessRelatedFile(ctx, web, appManifest, downloadFolderPath, url);
            }
        }

        private void ProcessRelatedFile(ClientContext ctx, Web web, AppManifestBase appManifest,
            string downloadFolderPath, string url)
        {
            OnVerboseNotify("Processing related file " + url);
            var fileName = GetFileName(url);
            if (appManifest.FileCreators.ContainsKey(fileName)) return;

            GetFileCreator(ctx, web, url, downloadFolderPath, appManifest, true);
        }

        private string GetFileName(string url)
        {
            var parts = url.Split('/');
            //Strip the space encoding to avoid duplicates
            return parts[parts.Length - 1].Replace("%20", " ");
        }

        private void DownloadFile(ClientContext ctx, string downloadFolderPath, string fileUrl,
            FileCreator newFileCreator, Dictionary<Guid, List> listIds, AppManifestBase appManifest)
        {
            byte[] fileArray;
            string fileString;
            GetFile(ctx, fileUrl, out fileArray, out fileString);

            //As with all character encoding in .Net this is dicey. Assumption is a null byte indicates a binary file
            if (fileString.Contains("\0")) newFileCreator.IsBinary = true;
            else
            {
                fileString = TokenizeText(ctx.Web, listIds, fileString);
                fileArray = fileString.ToByteArrayUtf8();
            }

            PutFile(downloadFolderPath, newFileCreator, appManifest, fileArray);
        }

        private void SaveFileToAzure(string blobUrl, byte[] fileArray, AzureStorageInfo azureStorageInfo)
        {
            var blobStorage = new BlobStorage(azureStorageInfo.Account, azureStorageInfo.AccountKey,
                azureStorageInfo.Container);
            blobStorage.UploadFromByteArray(fileArray, blobUrl);
        }

        private void DownloadAspxFile(ClientContext ctx, string downloadFolderPath, string fileUrl,
            FileCreator newFileCreator, Dictionary<Guid, List> listIds, AppManifestBase appManifest)
        {
            byte[] fileArray;
            string fileString;
            GetFile(ctx, fileUrl, out fileArray, out fileString);

            //As with all character encoding in .Net this is dicey. Assumption is a null byte indicates a binary file
            if (fileString.Contains("\0")) newFileCreator.IsBinary = true;
            else
            {
                fileString = TokenizeText(ctx.Web, listIds, fileString);
                fileArray = fileString.ToByteArrayUtf8();
            }

            PutFile(downloadFolderPath, newFileCreator, appManifest, fileArray);
        }

        private void DownloadWorkflowFile(ClientContext ctx, Web web, string downloadFolderPath, string fileUrl,
            FileCreator newFileCreator, AppManifestBase appManifest)
        {
            byte[] fileArray;
            string fileString;
            GetFile(ctx, fileUrl, out fileArray, out fileString);

            fileArray = ReplaceWorkflowWebSpecificIDsWithTokens(ctx, web, fileString).ToByteArrayUtf8();

            //As with all character encoding in .Net this is dicey. Assumption is a null byte indicates a binary file
            if (fileString.Contains("\0")) newFileCreator.IsBinary = true;

            PutFile(downloadFolderPath, newFileCreator, appManifest, fileArray);

            //Store workflow for association on target site
            if (fileUrl.ToLowerInvariant().EndsWith(".wfconfig.xml"))
            {
                var webRelativeUrl = newFileCreator.Url;
                if (webRelativeUrl.StartsWith("/")) webRelativeUrl = webRelativeUrl.Substring(1);
                var def = new ClassicWorkflowCreator
                {
                    AssociateWorkflowMarkupConfigUrl = webRelativeUrl,
                    ConfigVersion = "V1.0"
                };
                //Althoguh the 2013 XOML version is V2.0, using it will fail!
                if (appManifest.ClassicWorkflowCreators == null)
                    appManifest.ClassicWorkflowCreators = new Dictionary<string, ClassicWorkflowCreator>();
                appManifest.ClassicWorkflowCreators[webRelativeUrl] = def;
            }
        }

        private void PutFile(string downloadFolderPath, FileCreator newFileCreator, AppManifestBase appManifest,
            byte[] fileArray)
        {
            if (appManifest.StorageType == StorageTypes.FileSystem)
            {
                var filePath = newFileCreator.RelativeFilePath;
                if (!downloadFolderPath.EndsWith(@"\")) downloadFolderPath = downloadFolderPath + @"\";

                SaveToFileSystem(downloadFolderPath, filePath, fileArray);
            }
            else if (appManifest.StorageType == StorageTypes.AzureStorage && appManifest.GetAzureStorageInfo() != null)
            {
                SaveFileToAzure(newFileCreator.Url, fileArray, appManifest.GetAzureStorageInfo());
            }
        }

        private void GetFile(ClientContext ctx, string fileUrl, out byte[] fileArray, out string fileString)
        {
            OnVerboseNotify("Downloading " + fileUrl);
            var fileInfo = File.OpenBinaryDirect(ctx, fileUrl);
            ctx.ExecuteQueryRetry();

            var dowloadFileStream = fileInfo.Stream;

            fileArray = GetFileAsByteArray(dowloadFileStream);
            fileString = GetFileString(fileArray);
        }

        private byte[] GetFileAsByteArray(Stream dowloadFileStream)
        {
            byte[] fileArray;
            using (var streamReader = new MemoryStream())
            {
                dowloadFileStream.CopyTo(streamReader);
                fileArray = streamReader.ToArray();
            }
            return fileArray;
        }

        private string GetFileString(byte[] fileArray)
        {
            return Encoding.UTF8.GetString(fileArray);
        }

        /// <summary>
        /// Gets the content and parts for wiki and publishing pages
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="web"></param>
        /// <param name="fileUrl"></param>
        /// <param name="file"></param>
        /// <param name="pageContentFieldName"></param>
        /// <param name="newFileCreator"></param>
        private void ProcessWikiOrPublishingPage(ClientContext ctx, Web web, string fileUrl, File file, string pageContentFieldName, FileCreator newFileCreator)
        {
            OnVerboseNotify("Processing Wiki or Publishing Page " + fileUrl);
            //Get the web part manager
            var webPartManager = TryToGetWebPartManager(ctx, file);
            if (webPartManager != null)
            {
                OnVerboseNotify("Processing web parts");
                var listIds = GetWebListIds(ctx, web);

                //Get each web part and do token replacements
                var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds);

                var pageContentListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml);

                //Get the field contents
                var pageContent = file.ListItemAllFields.FieldValuesForEdit[pageContentFieldName];

                newFileCreator.WebParts = webPartsXml;
                newFileCreator.WikiPageWebPartListViews = pageContentListViews;

                //Extract the storage keys
                var storageKeys = WikiPageUtility.GetStorageKeysFromWikiContent(pageContent);

                //Fetch the page
                var page = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl)
                    : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl);

                //Search throught the page looking for the web part ID's that match the storage keys
                newFileCreator.WikiPageWebPartStorageKeyMappings = WikiPageUtility.GetStorageKeyMappings(page,
                    storageKeys);
            }
        }

        private void ProcessWebPartPage(ClientContext ctx, Web web, string fileUrl, File file,
            FileCreator newFileCreator, Dictionary<Guid, List> listIds)
        {
            OnVerboseNotify("Processing Web Part Page " + fileUrl);
            //Get the web part manager
            var webPartManager = TryToGetWebPartManager(ctx, file);
            if (webPartManager != null)
            {
                OnVerboseNotify("Processing web parts");

                //Get each web part and do token replacements
                var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds);

                var webPartListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml);

                newFileCreator.WebParts = webPartsXml;
                newFileCreator.WebPartPageWebPartListViews = webPartListViews;

                var page = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl)
                    : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl);

                newFileCreator.WebPartPageZoneMappings = WebPartPageUtility.GetWebPartZoneMappings(page, webPartsXml);
            }
        }

        private Dictionary<string, string> GetListViewWebPartViewSchemas(ClientContext ctx, Web web,
            Dictionary<string, string> webPartsXml)
        {
            OnVerboseNotify("Getting view schemas for list view web parts");
            var retVal = new Dictionary<string, string>();
            foreach (var key in webPartsXml.Keys)
            {
                var xml = webPartsXml[key].Replace("{@WebServerRelativeUrl}", web.ServerRelativeUrl);
                if (xml.Contains("{@ListId:") && xml.Contains("View Name=\""))
                {
                    var listTitle = xml.GetInnerText("{@ListId:", "}", true);
                    if (!string.IsNullOrEmpty(listTitle))
                    {
                        var viewId = xml.GetInnerText("View Name=\"", "\"", true);
                        if (!string.IsNullOrEmpty(listTitle))
                        {
                            var listViewXml = GetListViewXml(ctx, web, listTitle, viewId);
                            if (!string.IsNullOrEmpty(listViewXml))
                            {
                                retVal[key] = listViewXml;
                            }
                        }
                    }
                }
            }
            return retVal;
        }

        private string GetListViewXml(ClientContext ctx, Web web, string listTitle, string viewId)
        {
            var retVal = string.Empty;

            try
            {
                var list = web.Lists.GetByTitle(listTitle);
                var view = list.Views.GetById(Guid.Parse(viewId));
                ctx.Load(view, v => v.ListViewXml);
                ctx.ExecuteQueryRetry();

                XDocument document;
                using (var s = new StringReader(view.ListViewXml))
                {
                    document = XDocument.Load(s);
                }

                var element = document.Root;

                if (element != null)
                {
                    var reader = element.CreateReader();
                    reader.MoveToContent();
                    retVal = reader.ReadInnerXml();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Failed to get view schema for " + listTitle + " | " + ex);
            }
            return retVal;
        }

        private Dictionary<string, string> ReplaceWebPartWebSpecificIDsWithTokens(ClientContext ctx, Web web,
            string fileUrl, LimitedWebPartManager webPartManager, Dictionary<Guid, List> listIds)
        {
            var webPartsXml = new Dictionary<string, string>();
            foreach (var wpmWebPart in webPartManager.WebParts)
            {
                var part = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPart(ctx, web, fileUrl, wpmWebPart.Id)
                        .Replace("\r", "")
                        .Replace("\n", "")
                        .Trim()
                        .Replace("  ", " ")
                        .Replace("  ", " ")
                    : WebPartUtility.GetWebPart(web, RequestContextCredentials, fileUrl, wpmWebPart.Id)
                        .Replace("\r", "")
                        .Replace("\n", "")
                        .Trim()
                        .Replace("  ", " ")
                        .Replace("  ", " ");

                part = TokenizeText(web, listIds, part);
                webPartsXml[wpmWebPart.Id.ToString().ToLower().Replace("{", "").Replace("}", "")] = part;
            }
            return webPartsXml;
        }

        private string TokenizeText(Web web, Dictionary<Guid, List> listIds, string text)
        {
            foreach (var list in listIds)
            {
                var match = list.Key.ToString().Replace("{", "").Replace("}", "").ToLower();
                text = text.Replace(match, "{@ListId:" + list.Value.Title + "}")
                    .Replace(match.ToUpper(), "{@ListId:" + list.Value.Title + "}");
                text = text.Replace(list.Value.RootFolder.ServerRelativeUrl, "{@ListUrl:" + list.Value.Title + "}");
            }

            return TokenizeText(web, text);
        }

        private string TokenizeText(Web web, string text)
        {
            var ctx = web.Context.GetSiteCollectionContext();
            var rootWeb = ctx.Site.RootWeb;
            rootWeb.EnsureProperties(w => w.Url, w => w.ServerRelativeUrl);

            text = text.Replace(web.Url, "{@WebUrl}");
            if (web.ServerRelativeUrl != "/") text = text.Replace(web.ServerRelativeUrl, "{@WebServerRelativeUrl}");
            if (web.Url != rootWeb.Url)
            {
                text = text.Replace(rootWeb.Url, "{@SiteUrl}");
                text = text.Replace(rootWeb.ServerRelativeUrl, "{@SiteServerRelativeUrl}");
            }
            return text;
        }

        private string ReplaceWorkflowWebSpecificIDsWithTokens(ClientContext ctx, Web web, string fileString)
        {
            var listIds = GetWebListIds(ctx, web);
            var preparedFile = fileString;

            foreach (var list in listIds)
            {
                var match = list.Key.ToString().Replace("{", "").Replace("}", "").ToLower();
                if (preparedFile.Contains(match) || preparedFile.Contains(match.ToUpper()))
                {
                    preparedFile =
                        preparedFile.Replace(match, "{@ListId:" + list.Value.Title + "}")
                            .Replace(match.ToUpper(), "{@ListId:" + list.Value.Title + "}");
                    preparedFile = TokenizeListContentTypes(ctx, list.Value, preparedFile);
                }
            }

            if (web.ServerRelativeUrl != "/")
                preparedFile = preparedFile.Replace(web.ServerRelativeUrl, "{@WebServerRelativeUrl}");

            return preparedFile;
        }

        private string TokenizeListContentTypes(ClientContext ctx, List list, string preparedFile)
        {
            var listCTypes = list.ContentTypes;
            ctx.Load(listCTypes, cts => cts.Include(ct => ct.Id, ct => ct.Name));
            ctx.ExecuteQueryRetry();

            foreach (var cType in listCTypes)
            {
                preparedFile = preparedFile.Replace(cType.Id.ToString(),
                    $"{{@ListContentType: {list.Title}|{cType.Name}}}");
            }

            return preparedFile;
        }

        private LimitedWebPartManager TryToGetWebPartManager(ClientContext ctx, File file)
        {
            try
            {
                var webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
                ctx.Load(webPartManager.WebParts, wp => wp.Include(p => p.Id, p => p.WebPart));
                ctx.ExecuteQueryRetry();

                return webPartManager;
            }
            catch
            {
                return null;
            }
        }

        private void SaveToFileSystem(string downloadFolderPath, string filePath, byte[] fileArray)
        {
            if (!string.IsNullOrEmpty(downloadFolderPath) && !string.IsNullOrEmpty(filePath))
            {
                OnVerboseNotify("Downloading " + filePath);
                var outputPath = downloadFolderPath + @"\" + filePath;
                new FileInfo(outputPath).Directory?.Create();
                System.IO.File.WriteAllBytes(outputPath, fileArray);
            }
        }

        private void AnalyzeSecurityConfiguration(FileCreator creator, ListItem file, ClientContext ctx)
        {
            OnVerboseNotify("Analyzing security config");
            if (file.HasUniqueRoleAssignments)
            {
                ctx.Load(file, l => l.RoleAssignments);
                ctx.Load(file.RoleAssignments, ras => ras.Include(ra => ra.Member, ra => ra.RoleDefinitionBindings));
                ctx.Load(file.ParentList, l => l.RoleAssignments);
                ctx.Load(file.ParentList.RoleAssignments,
                    ras => ras.Include(ra => ra.Member, ra => ra.RoleDefinitionBindings));
                ctx.ExecuteQueryRetry();

                if (creator.SecurityConfiguration == null)
                {
                    creator.SecurityConfiguration = new SecureObjectCreator
                    {
                        SecureObjectType = SecureObjectType.File,
                        GroupRoleDefinitions = new Dictionary<string, string>()
                    };
                }

                creator.SecurityConfiguration.Title = creator.Name;
                creator.SecurityConfiguration.Url = creator.Url;
                creator.SecurityConfiguration.BreakInheritance = true;

                //First loop thorugh and see if the parent has principals with assignments not found in the file
                CheckShouldCopyExistingPermissions(creator, file);

                //Next loop through the assignments on the file and build the output
                FillFileGroupRoleDefinitions(creator, file, ctx);
            }
        }

        private void CheckShouldCopyExistingPermissions(FileCreator creator, ListItem file)
        {
            creator.SecurityConfiguration.CopyExisting = true;
            foreach (var roleAssignment in file.ParentList.RoleAssignments)
            {
                var principal = roleAssignment.Member;
                if (principal.PrincipalType == PrincipalType.SharePointGroup)
                {
                    var foundMatch = false;
                    foreach (var fileRoleAssignment in file.RoleAssignments)
                    {
                        if (fileRoleAssignment.Member.Id == roleAssignment.Member.Id)
                        {
                            foundMatch = true;
                            break;
                        }
                    }
                    //The first unique ancestor has one that isn't in the file, assume break inheritance
                    if (!foundMatch)
                    {
                        creator.SecurityConfiguration.CopyExisting = false;
                        break;
                    }
                }
            }
        }

        private void FillFileGroupRoleDefinitions(FileCreator creator, ListItem file, ClientContext ctx)
        {
            ctx.Load(ctx.Web.AssociatedMemberGroup, g => g.Id);
            ctx.Load(ctx.Web.AssociatedOwnerGroup, g => g.Id);
            ctx.Load(ctx.Web.AssociatedVisitorGroup, g => g.Id);
            ctx.ExecuteQueryRetry();

            foreach (var roleAssignment in file.RoleAssignments)
            {
                var principal = roleAssignment.Member;
                var principalName = principal.LoginName;
                var principalId = principal.Id;

                if (principalId == ctx.Web.AssociatedMemberGroup.Id)
                {
                    principalName = "AssociatedMemberGroup";
                }
                if (principalId == ctx.Web.AssociatedOwnerGroup.Id)
                {
                    principalName = "AssociatedOwnerGroup";
                }
                if (principalId == ctx.Web.AssociatedVisitorGroup.Id)
                {
                    principalName = "AssociatedVisitorGroup";
                }

                Debug.WriteLine(principalName);
                if ((principal.PrincipalType == PrincipalType.SharePointGroup ||
                    principal.PrincipalType == PrincipalType.SecurityGroup) &&
                    !principalName.StartsWith("SharingLinks.")
                    )
                {
                    foreach (var roleDefinition in roleAssignment.RoleDefinitionBindings)
                    {
                        //This part of the object model is quirky
                        //There should be at most two for a given principal
                        //butif there are more the first one that isn't Limited Access wins
                        if (roleDefinition.Name != "Limited Access" && roleDefinition.Name != "System.LimitedEdit")
                        {
                            if (!creator.SecurityConfiguration.CopyExisting)
                            {
                                if (!creator.SecurityConfiguration.GroupRoleDefinitions.ContainsKey(principalName))
                                {
                                    creator.SecurityConfiguration.GroupRoleDefinitions.Add(principalName,
                                        roleDefinition.Name);
                                }
                            }
                            else
                            {
                                var inFirstAncestor = false;
                                foreach (var parentWebRoleAssignment in file.ParentList.RoleAssignments)
                                {
                                    if (parentWebRoleAssignment.Member.LoginName == principalName)
                                    {
                                        foreach (
                                            var parentWebRoleDefinition in
                                                parentWebRoleAssignment.RoleDefinitionBindings)
                                        {
                                            if (roleDefinition.Name == parentWebRoleDefinition.Name)
                                            {
                                                inFirstAncestor = true;
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (!inFirstAncestor)
                                {
                                    if (!creator.SecurityConfiguration.GroupRoleDefinitions.ContainsKey(principalName))
                                    {
                                        creator.SecurityConfiguration.GroupRoleDefinitions.Add(principalName,
                                            roleDefinition.Name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        private Dictionary<Guid, List> GetWebListIds(ClientContext ctx, Web web)
        {
            OnVerboseNotify("Getting web list ids " + web.ServerRelativeUrl);
            var retVal = new Dictionary<Guid, List>();
            ctx.Load(web.Lists,
                list =>
                    list.Include(property => property.Id, property => property.Title, property => property.RootFolder));
            ctx.ExecuteQueryRetry();
            foreach (var list in web.Lists)
            {
                retVal[list.Id] = list;
            }
            return retVal;
        }
    }
}


text:
//go:build !windows
// +build !windows

package cio

import (
	"context"
	"path/filepath"
	"testing"

	"gotest.tools/v3/assert"
)

func TestOpenFifos(t *testing.T) {
	scenarios := []*FIFOSet{
		{
			Config: Config{
				Stdin:  "",
				Stdout: filepath.Join("This/does/not/exist", "test-stdout"),
				Stderr: filepath.Join("This/does/not/exist", "test-stderr"),
			},
		},
		{
			Config: Config{
				Stdin:  filepath.Join("This/does/not/exist", "test-stdin"),
				Stdout: "",
				Stderr: filepath.Join("This/does/not/exist", "test-stderr"),
			},
		},
		{
			Config: Config{
				Stdin:  "",
				Stdout: "",
				Stderr: filepath.Join("This/does/not/exist", "test-stderr"),
			},
		},
	}
	for _, scenario := range scenarios {
		_, err := openFifos(context.Background(), scenario)
		assert.Assert(t, err != nil, scenario)
	}
}

// TestOpenFifosWithTerminal tests openFifos should not open stderr if terminal
// is set.
func TestOpenFifosWithTerminal(t *testing.T) {
	var ctx, cancel = context.WithCancel(context.Background())
	defer cancel()

	ioFifoDir := t.TempDir()

	cfg := Config{
		Stdout: filepath.Join(ioFifoDir, "test-stdout"),
		Stderr: filepath.Join(ioFifoDir, "test-stderr"),
	}

	// Without terminal, pipes.Stderr should not be nil
	{
		p, err := openFifos(ctx, NewFIFOSet(cfg, nil))
		if err != nil {
			t.Fatalf("unexpected error during openFifos: %v", err)
		}

		if p.Stderr == nil {
			t.Fatalf("unexpected empty stderr pipe")
		}
	}

	// With terminal, pipes.Stderr should be nil
	{
		cfg.Terminal = true
		p, err := openFifos(ctx, NewFIFOSet(cfg, nil))
		if err != nil {
			t.Fatalf("unexpected error during openFifos: %v", err)
		}

		if p.Stderr != nil {
			t.Fatalf("unexpected stderr pipe")
		}
	}
}