text:
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "exegesis/base/cpuid_x86.h"

#ifdef __x86_64__
#include <cpuid.h>
#endif  //  __x86_64__

#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "exegesis/proto/x86/cpuid.pb.h"
#include "exegesis/util/structured_register.h"
#include "glog/logging.h"
#include "re2/re2.h"

namespace exegesis {
namespace x86 {

// The CPUID code is based on the information provided in:
// * Intel 64 and IA-32 Architectures Software Developer's Manual (March 2017),
//   combined volumes 1-4, and
// * AMD64 Architecture Programmer's Manual, Volume 3 (March 2017, rev. 3.23).
//
// As of 2017-06-09, the information returned by CPUID is - for the purposes of
// this code - almost equivalent on both platforms. The following differences
// are relevant to this library:
// * ExtendedFeatureRegisters.ecx.prefetchw1() is marked as reserved on AMD.
// * The bits used to indicate AVX512 support are marked as reserved on AMD.

CpuIdEntryProto MakeCpuIdEntry(uint32_t leaf, uint32_t subleaf, uint32_t eax,
                               uint32_t ebx, uint32_t ecx, uint32_t edx) {
  CpuIdEntryProto entry;
  CpuIdInputProto* const input = entry.mutable_input();
  input->set_leaf(leaf);
  input->set_subleaf(subleaf);
  CpuIdOutputProto* const output = entry.mutable_output();
  output->set_eax(eax);
  output->set_ebx(ebx);
  output->set_ecx(ecx);
  output->set_edx(edx);
  return entry;
}

namespace {

// Represents the structure of registers when fetching features (EAX = 1).
struct FeatureRegisters {
  class EAXStructure : public StructuredRegister<uint32_t> {
   public:
    int step() const { return ValueAt<3, 0>(); }
    int model() const { return ValueAt<7, 4>(); }
    int family() const { return ValueAt<11, 8>(); }
    // 12 is reserved ond AMD CPUs.
    int intel_only_type() const { return ValueAt<13, 12>(); }
    // 15 - 14 reserved.
    int emodel() const { return ValueAt<19, 16>(); }
    int efamily() const { return ValueAt<27, 20>(); }
    // 31 - 28 reserved.
  };

  class ECXStructure : public StructuredRegister<uint32_t> {
   public:
    int sse3() const { return ValueAt<0, 0>(); }
    int pclmulqdq() const { return ValueAt<1, 1>(); }
    // 2 is reserved on AMD CPUs.
    int intel_only_dtes64() const { return ValueAt<2, 2>(); }
    int monitor() const { return ValueAt<3, 3>(); }
    // 4 - 8 are reserved on AMD CPUs.
    int intel_only_dscpl() const { return ValueAt<4, 4>(); }
    int intel_only_vmx() const { return ValueAt<5, 5>(); }
    int intel_only_smx() const { return ValueAt<6, 6>(); }
    int intel_only_est() const { return ValueAt<7, 7>(); }
    int intel_only_tm2() const { return ValueAt<8, 8>(); }
    int ssse3() const { return ValueAt<9, 9>(); }
    // 10 - 11 are reserved on AMD CPUs.
    int intel_only_cntxid() const { return ValueAt<10, 10>(); }
    int intel_only_sdbg() const { return ValueAt<11, 11>(); }
    int fma() const { return ValueAt<12, 12>(); }
    int cx16() const { return ValueAt<13, 13>(); }
    // 14 - 18 are reserved on AMD CPUs.
    int intel_only_xtpr() const { return ValueAt<14, 14>(); }
    int intel_only_pdcm() const { return ValueAt<15, 15>(); }
    // 16 reserved.
    int intel_only_pcid() const { return ValueAt<17, 17>(); }
    int intel_only_dca() const { return ValueAt<18, 18>(); }
    int sse4_1() const { return ValueAt<19, 19>(); }
    int sse4_2() const { return ValueAt<20, 20>(); }
    // 21 is reserved on AMD CPUs.
    int intel_only_x2apic() const { return ValueAt<21, 21>(); }
    int movbe() const { return ValueAt<22, 22>(); }
    int popcnt() const { return ValueAt<23, 23>(); }
    // 24 is reserved on AMD CPUs.
    int intel_only_tscdadline() const { return ValueAt<24, 24>(); }
    int aes() const { return ValueAt<25, 25>(); }
    int xsave() const { return ValueAt<26, 26>(); }
    int osxsave() const { return ValueAt<27, 27>(); }
    int avx() const { return ValueAt<28, 28>(); }
    int f16c() const { return ValueAt<29, 29>(); }
    int rdrand() const { return ValueAt<30, 30>(); }
    int hypervisor() const { return ValueAt<31, 31>(); }
  };

  class EDXStructure : public StructuredRegister<uint32_t> {
   public:
    int fpu() const { return ValueAt<0, 0>(); }
    int vme() const { return ValueAt<1, 1>(); }
    int de() const { return ValueAt<2, 2>(); }
    int pse() const { return ValueAt<3, 3>(); }
    int tsc() const { return ValueAt<4, 4>(); }
    int msr() const { return ValueAt<5, 5>(); }
    int pae() const { return ValueAt<6, 6>(); }
    int mce() const { return ValueAt<7, 7>(); }
    int cx8() const { return ValueAt<8, 8>(); }
    int apic() const { return ValueAt<9, 9>(); }
    // 10 reserved.
    int sep() const { return ValueAt<11, 11>(); }
    int mtrr() const { return ValueAt<12, 12>(); }
    int pge() const { return ValueAt<13, 13>(); }
    int mca() const { return ValueAt<14, 14>(); }
    int cmov() const { return ValueAt<15, 15>(); }
    int pat() const { return ValueAt<16, 16>(); }
    int pse36() const { return ValueAt<17, 17>(); }
    // 18 is reserved on AMD CPUs.
    int intel_only_psn() const { return ValueAt<18, 18>(); }
    int clfsh() const { return ValueAt<19, 19>(); }
    // 20 reserved.
    // 20 - 22 is reserved on AMD CPUs.
    int intel_only_ds() const { return ValueAt<21, 21>(); }
    int intel_only_acpi() const { return ValueAt<22, 22>(); }
    int mmx() const { return ValueAt<23, 23>(); }
    int fxsr() const { return ValueAt<24, 24>(); }
    int sse() const { return ValueAt<25, 25>(); }
    int sse2() const { return ValueAt<26, 26>(); }
    // 27 is reserved on AMD CPUs.
    int intel_only_ss() const { return ValueAt<27, 27>(); }
    int htt() const { return ValueAt<28, 28>(); }
    // 29 - 31 is reserved on AMD CPUs.
    int intel_only_tm() const { return ValueAt<29, 29>(); }
    int intel_only_ia64() const { return ValueAt<30, 30>(); }
    int intel_only_pbe() const { return ValueAt<31, 31>(); }
  };

  void SetValue(const CpuIdOutputProto& cpuid_out) {
    *eax.mutable_raw_value() = cpuid_out.eax();
    *ecx.mutable_raw_value() = cpuid_out.ecx();
    *edx.mutable_raw_value() = cpuid_out.edx();
  }

  EAXStructure eax;
  ECXStructure ecx;
  EDXStructure edx;
};

// Represents the structure of registers when fetching extended features (EAX =
// 7).
struct ExtendedFeatureRegisters {
  class EBXStructure : public StructuredRegister<uint32_t> {
   public:
    int fsgsbase() const { return ValueAt<0, 0>(); }
    // 1 - 2 is reserved on AMD CPUs.
    int intel_only_ia32tscadjust() const { return ValueAt<1, 1>(); }
    int intel_only_sgx() const { return ValueAt<2, 2>(); }
    int bmi1() const { return ValueAt<3, 3>(); }
    // 4 is reserved on AMD CPUs.
    int intel_only_hle() const { return ValueAt<4, 4>(); }
    int avx2() const { return ValueAt<5, 5>(); }
    // 6 is reserved.
    int smep() const { return ValueAt<7, 7>(); }
    int bmi2() const { return ValueAt<8, 8>(); }
    // 9 - 17 is reserved on AMD CPUs.
    int intel_only_erms() const { return ValueAt<9, 9>(); }
    int intel_only_invpcid() const { return ValueAt<10, 10>(); }
    int intel_only_rtm() const { return ValueAt<11, 11>(); }
    int intel_only_pqm() const { return ValueAt<12, 12>(); }
    int intel_only_fpucsdsdeprecated() const { return ValueAt<13, 13>(); }
    int intel_only_mpx() const { return ValueAt<14, 14>(); }
    int intel_only_pqe() const { return ValueAt<15, 15>(); }
    int intel_only_avx512f() const { return ValueAt<16, 16>(); }
    int intel_only_avx512dq() const { return ValueAt<17, 17>(); }
    int rdseed() const { return ValueAt<18, 18>(); }
    int adx() const { return ValueAt<19, 19>(); }
    int smap() const { return ValueAt<20, 20>(); }
    // 21 - 22 is reserved on AMD CPUs.
    int intel_only_avx512ifma() const { return ValueAt<21, 21>(); }
    int intel_only_pcommit() const { return ValueAt<22, 22>(); }
    int clflushopt() const { return ValueAt<23, 23>(); }
    // 24 - 28 is reserved on AMD CPUs.
    int intel_only_clwb() const { return ValueAt<24, 24>(); }
    int intel_only_intelproctrace() const { return ValueAt<25, 25>(); }
    int intel_only_avx512pf() const { return ValueAt<26, 26>(); }
    int intel_only_avx512er() const { return ValueAt<27, 27>(); }
    int intel_only_avx512cd() const { return ValueAt<28, 28>(); }
    int sha() const { return ValueAt<29, 29>(); }
    // 30 - 31 is reserved on AMD CPUs.
    int intel_only_avx512bw() const { return ValueAt<30, 30>(); }
    int intel_only_avx512vl() const { return ValueAt<31, 31>(); }
  };

  class ECXStructure : public StructuredRegister<uint32_t> {
   public:
    // 0 - 31 are reserved on AMD CPUs.
    int intel_only_prefetchwt1() const { return ValueAt<0, 0>(); }
    // 1 reserved.
    int intel_only_umip() const { return ValueAt<2, 2>(); }
    int intel_only_pku() const { return ValueAt<3, 3>(); }
    int intel_only_ospke() const { return ValueAt<4, 4>(); }
    // 5 - 21 reserved.
    int intel_only_rdpid() const { return ValueAt<22, 22>(); }
    // 23 - 29 reserved.
    int intel_only_sgx_lc() const { return ValueAt<30, 30>(); }
  };

  void SetValue(const CpuIdOutputProto& cpuid_out) {
    *ebx.mutable_raw_value() = cpuid_out.ebx();
    *ecx.mutable_raw_value() = cpuid_out.ecx();
  }

  EBXStructure ebx;
  ECXStructure ecx;
};

// Represents the structure of registers when fetching extended features (EAX =
// 80000001H).
struct Extended2FeatureRegisters {
  class ECXStructure : public StructuredRegister<uint32_t> {
   public:
    int lahf_sahf() const { return ValueAt<0, 0>(); }
    // 1 - 4 reserved.
    int lzcnt() const { return ValueAt<5, 5>(); }
    // 6 - 7 reserved.
    int prefetchw() const { return ValueAt<8, 8>(); }
    // 9 - 31 reserved.
  };

  class EDXStructure : public StructuredRegister<uint32_t> {
   public:
    // 0 - 10 reserved.
    int syscall_sysret_64() const { return ValueAt<11, 11>(); }
    // 12 - 19 reserved.
    int execute_disable() const { return ValueAt<20, 20>(); }
    // 21 - 25 reserved.
    int gb_pages() const { return ValueAt<26, 26>(); }
    int rdtscp_ia32_tsc_aux() const { return ValueAt<27, 27>(); }
    // 28 reserved.
    int ia64() const { return ValueAt<29, 29>(); }
    // 30 - 31 reserved.
  };

  void SetValue(const CpuIdOutputProto& cpuid_out) {
    *ecx.mutable_raw_value() = cpuid_out.ecx();
    *edx.mutable_raw_value() = cpuid_out.edx();
  }

  ECXStructure ecx;
  EDXStructure edx;
};

// Represents the structure of registers when fetching extended CPU states (EAX
// = 0DH, ECX = 1).
struct ExtendedStateRegisters {
  class EAXStructure : public StructuredRegister<uint32_t> {
   public:
    int xsaveopt() const { return ValueAt<0, 0>(); }
    // 1 - 31 are reserved on AMD CPUs.
    int xsavec() const { return ValueAt<1, 1>(); }
    int xgetbv() const { return ValueAt<2, 2>(); }
    int xsaves() const { return ValueAt<3, 3>(); }
    // 4 - 31 reserved.
  };

  void SetValue(const CpuIdOutputProto& cpuid_out) {
    *eax.mutable_raw_value() = cpuid_out.eax();
  }

  EAXStructure eax;
};

// Runs CPUID for the given leaf and subleaf. On platforms where CPUID does not
// exist returns an empty CpuIdEntryProto.
CpuIdEntryProto GetHostCpuIdDumpEntry(uint32_t leaf, uint32_t subleaf) {
  uint32_t eax = 0;
  uint32_t ebx = 0;
  uint32_t ecx = subleaf;
  uint32_t edx = 0;
#ifdef __x86_64__
  __cpuid(leaf, eax, ebx, ecx, edx);
#endif  // __x86-64__
  return MakeCpuIdEntry(leaf, subleaf, eax, ebx, ecx, edx);
}

constexpr int kMaxSubleafStoredInEax = -1;

// Returns the maximal index of a subleaf of the given leaf. For most leafs,
// there is only one subleaf (the main subleaf); for others, the maximal index
// is either stored in the subleaf 0 of that leaf, or the maximal index is
// obtained from the documentation.
// NOTE(ondrasej): This function handles only the cases that are relevant to
// feature detection. There are other leafs that have more than one subleaf that
// are not considered by this function.
int GetMaxSubleaf(int leaf) {
  switch (leaf) {
    case 7:
      return kMaxSubleafStoredInEax;
    case 0x0D:
      return 1;
    default:
      return 0;
  }
}

// Adds leaf from a leaf range starting with 'seed' to 'dump_proto'. Assumes
// that 'seed' is the first leaf of the range, and that the index of the
// last leaf of the range is returned in
// GetHostCpuIdDumpEntry(seed, 0).output().eax().
void AddHostCpuIdEntriesFromSeed(uint32_t seed, X86CpuIdDumpProto* dump_proto) {
  CHECK(dump_proto != nullptr);
  const CpuIdEntryProto seed_leaf = GetHostCpuIdDumpEntry(seed, 0);
  *dump_proto->add_entries() = seed_leaf;
  const uint32_t num_leafs = seed_leaf.output().eax();
  for (uint32_t leaf = seed + 1; leaf <= num_leafs; ++leaf) {
    *dump_proto->add_entries() = GetHostCpuIdDumpEntry(leaf, 0);
    int max_subleaf = GetMaxSubleaf(leaf);
    if (max_subleaf == kMaxSubleafStoredInEax) {
      max_subleaf = dump_proto->entries().rbegin()->output().eax();
    }
    for (int subleaf = 1; subleaf <= max_subleaf; ++subleaf) {
      *dump_proto->add_entries() = GetHostCpuIdDumpEntry(leaf, subleaf);
    }
  }
}

}  // namespace

constexpr char CpuIdDump::kVendorStringAMD[];
constexpr char CpuIdDump::kVendorStringIntel[];

absl::StatusOr<CpuIdDump> CpuIdDump::FromString(const std::string& source) {
  static const LazyRE2 regex = {
      " *CPUID +([0-9a-fA-F]+): +"
      "([0-9a-fA-F]+)-([0-9a-fA-F]+)-([0-9a-fA-F]+)-([0-9a-fA-F]+)(?: .*)?"};
  CpuIdDump dump;
  X86CpuIdDumpProto* const dump_proto =
      dump.dump_proto_.mutable_x86_cpuid_dump();
  const std::vector<std::string> lines = absl::StrSplit(source, '\n');
  for (const std::string& line : lines) {
    uint32_t leaf = 0;
    uint32_t eax = 0;
    uint32_t ebx = 0;
    uint32_t ecx = 0;
    uint32_t edx = 0;
    if (RE2::FullMatch(line, *regex, RE2::Hex(&leaf), RE2::Hex(&eax),
                       RE2::Hex(&ebx), RE2::Hex(&ecx), RE2::Hex(&edx))) {
      const uint32_t subleaf = dump.GetNextSubleaf(leaf);
      *dump_proto->add_entries() =
          MakeCpuIdEntry(leaf, subleaf, eax, ebx, ecx, edx);
    }
  }
  if (!dump.IsValid()) {
    return absl::InvalidArgumentError(
        "Leaf 0 was not found in the parsed dump.");
  }
  return dump;
}

CpuIdDump CpuIdDump::FromHost() {
  CpuIdDump dump;
#ifdef __x86_64__
  X86CpuIdDumpProto* const dump_proto =
      dump.dump_proto_.mutable_x86_cpuid_dump();
  AddHostCpuIdEntriesFromSeed(0, dump_proto);
  AddHostCpuIdEntriesFromSeed(0x80000000, dump_proto);
#endif  // __x86_64__
  return dump;
}

std::string CpuIdDump::GetProcessorBrandString() const {
  constexpr uint32_t kStartLeaf = 0x80000002;
  constexpr uint32_t kEndLeaf = 0x80000004;
  constexpr int kBytesPerLeaf = 16;
  // There are 16 bytes of data per leaf (four 32-bit registers), and the leaf
  // range is inclusive on both ends. We reserve space for one additional char
  // at the end of the buffer for a null character that turns the buffer into
  // a valid null-terminated C string if it wasn't already.
  constexpr int kBufferSize = kBytesPerLeaf * (kEndLeaf - kStartLeaf + 1) + 1;
  char buffer[kBufferSize];
  uint32_t* const data = reinterpret_cast<uint32_t*>(buffer);
  int entry = 0;
  for (uint32_t leaf = kStartLeaf; leaf <= kEndLeaf; ++leaf) {
    const CpuIdOutputProto* const leaf_data = GetEntryOrNull(leaf, 0);
    if (leaf_data == nullptr) return std::string();
    data[entry] = leaf_data->eax();
    data[entry + 1] = leaf_data->ebx();
    data[entry + 2] = leaf_data->ecx();
    data[entry + 3] = leaf_data->edx();
    entry += 4;
    CHECK_LT(entry * 4, kBufferSize);
  }
  // Depending on the vendor and model, the data in buffer may or may not be
  // padded with zeros at the end. By adding a sentinel right after the 48 bytes
  // obtained from CPUID, we ensure that the data in buffer is always null
  // terminated, and can be safely used as a C string.
  buffer[kBufferSize - 1] = 0;
  return buffer;
}

std::string CpuIdDump::GetVendorString() const {
  const CpuIdOutputProto* const root = GetEntryOrNull(0, 0);
  CHECK(root) << "Invalid CPUID dump!";
  char buffer[12];
  uint32_t* data = reinterpret_cast<uint32_t*>(buffer);
  data[0] = root->ebx();
  data[1] = root->edx();
  data[2] = root->ecx();
  return std::string(buffer, 12);
}

#define PROCESS_FEATURE(name, reg, field)       \
  if (reg.field()) {                            \
    gtl::InsertOrDie(&indexed_features, #name); \
  }
#define PROCESS_FEATURE_IF(condition, name, reg, field) \
  if ((condition) && reg.field()) {                     \
    gtl::InsertOrDie(&indexed_features, #name);         \
  }

CpuInfo CpuIdDump::ToCpuInfo() const {
  CHECK(IsValid());
  FeatureRegisters features;
  ExtendedFeatureRegisters ext_features;
  Extended2FeatureRegisters ext2_features;
  ExtendedStateRegisters ext_state;

  for (const auto& entry : dump_proto().x86_cpuid_dump().entries()) {
    switch (entry.input().leaf()) {
      case 0x01:
        features.SetValue(entry.output());
        break;
      case 0x07:
        if (entry.input().subleaf() == 0) ext_features.SetValue(entry.output());
        break;
      case 0x0D:
        if (entry.input().subleaf() == 1) ext_state.SetValue(entry.output());
        break;
      case 0x80000001:
        ext2_features.SetValue(entry.output());
        break;
    }
  }

  const std::string vendor = GetVendorString();
  const bool is_intel = vendor == kVendorStringIntel;
  const bool is_amd = vendor == kVendorStringAMD;

  absl::flat_hash_set<std::string> indexed_features;

  if (is_intel) {
    PROCESS_FEATURE(3DNOW, ext_features.ecx, intel_only_prefetchwt1);
  } else if (is_amd) {
    indexed_features.insert("3DNOW");
  }
  PROCESS_FEATURE(ADX, ext_features.ebx, adx);
  PROCESS_FEATURE(CLFLUSHOPT, ext_features.ebx, clflushopt);
  PROCESS_FEATURE(AES, features.ecx, aes);
  PROCESS_FEATURE(AVX, features.ecx, avx);
  PROCESS_FEATURE(AVX2, ext_features.ebx, avx2);
  PROCESS_FEATURE_IF(is_intel, AVX512BW, ext_features.ebx, intel_only_avx512bw);
  PROCESS_FEATURE_IF(is_intel, AVX512CD, ext_features.ebx, intel_only_avx512cd);
  PROCESS_FEATURE_IF(is_intel, AVX512DQ, ext_features.ebx, intel_only_avx512dq);
  PROCESS_FEATURE_IF(is_intel, AVX512ER, ext_features.ebx, intel_only_avx512er);
  PROCESS_FEATURE_IF(is_intel, AVX512F, ext_features.ebx, intel_only_avx512f);
  PROCESS_FEATURE_IF(is_intel, AVX512PF, ext_features.ebx, intel_only_avx512pf);
  PROCESS_FEATURE_IF(is_intel, AVX512VL, ext_features.ebx, intel_only_avx512vl);
  PROCESS_FEATURE(BMI1, ext_features.ebx, bmi1);
  PROCESS_FEATURE(BMI2, ext_features.ebx, bmi2);
  PROCESS_FEATURE(CLMUL, features.ecx, pclmulqdq);
  PROCESS_FEATURE(F16C, features.ecx, f16c);
  PROCESS_FEATURE(FMA, features.ecx, fma);
  PROCESS_FEATURE(FPU, features.edx, fpu);
  PROCESS_FEATURE(CLFSH, features.edx, clfsh);
  PROCESS_FEATURE(FSGSBASE, ext_features.ebx, fsgsbase);
  PROCESS_FEATURE_IF(is_intel, HLE, ext_features.ebx, intel_only_hle);
  PROCESS_FEATURE_IF(is_intel, INVPCID, ext_features.ebx, intel_only_invpcid);
  PROCESS_FEATURE(LZCNT, ext2_features.ecx, lzcnt);
  PROCESS_FEATURE(MMX, features.edx, mmx);
  PROCESS_FEATURE(MOVBE, features.ecx, movbe);
  PROCESS_FEATURE_IF(is_intel, MPX, ext_features.ebx, intel_only_mpx);
  PROCESS_FEATURE_IF(is_intel, OSPKE, ext_features.ecx, intel_only_ospke);
  PROCESS_FEATURE(PREFETCHW, ext2_features.ecx, prefetchw);
  PROCESS_FEATURE_IF(is_intel, RDPID, ext_features.ecx, intel_only_rdpid);
  PROCESS_FEATURE(RDRAND, features.ecx, rdrand);
  PROCESS_FEATURE(RDSEED, ext_features.ebx, rdseed);
  PROCESS_FEATURE_IF(is_intel, RTM, ext_features.ebx, intel_only_rtm);
  PROCESS_FEATURE(SHA, ext_features.ebx, sha);
  PROCESS_FEATURE(SMAP, ext_features.ebx, smap);
  PROCESS_FEATURE(SSE, features.edx, sse);
  PROCESS_FEATURE(SSE2, features.edx, sse2);
  PROCESS_FEATURE(SSE3, features.ecx, sse3);
  PROCESS_FEATURE(SSE4_1, features.ecx, sse4_1);
  PROCESS_FEATURE(SSE4_2, features.ecx, sse4_2);
  PROCESS_FEATURE(SSSE3, features.ecx, ssse3);
  PROCESS_FEATURE(XSAVEOPT, ext_state.eax, xsaveopt);

  // If there is any AVX-512 feature, also add a meta-feature AVX512.
  constexpr char kAvx512[] = "AVX512";
  for (const std::string& feature_name : indexed_features) {
    if (absl::StartsWith(feature_name, kAvx512)) {
      indexed_features.insert(kAvx512);
      break;
    }
  }

  // See CPUID doc for the algorithm.
  const int family =
      features.eax.family() != 0x0f
          ? features.eax.family()
          : (features.eax.efamily() << 4) + features.eax.family();
  const int model =
      (features.eax.family() == 0x06 || features.eax.family() == 0x0f)
          ? (features.eax.emodel() << 4) + features.eax.model()
          : features.eax.model();

  CpuInfoProto proto;
  proto.set_model_id(absl::StrFormat("intel:%02X_%02X", family, model));
  for (const auto& feature_name : indexed_features) {
    proto.add_feature_names(feature_name);
  }
  return CpuInfo(proto);
}

#undef PROCESS_FEATURE
#undef PROCESS_FEATURE_IF

std::string CpuIdDump::ToString() const {
  std::string buffer;
  for (const CpuIdEntryProto& entry : dump_proto_.x86_cpuid_dump().entries()) {
    if (!buffer.empty()) buffer += "\n";
    absl::StrAppendFormat(&buffer, "CPUID %08X: %08X-%08X-%08X-%08X",
                          entry.input().leaf(), entry.output().eax(),
                          entry.output().ebx(), entry.output().ecx(),
                          entry.output().edx());
  }
  return buffer;
}

const CpuIdOutputProto* CpuIdDump::GetEntryOrNull(
    uint32_t leaf, uint32_t subleaf /* = 0 */) const {
  for (const CpuIdEntryProto& entry : dump_proto_.x86_cpuid_dump().entries()) {
    const CpuIdInputProto& input = entry.input();
    if (input.leaf() == leaf && input.subleaf() == subleaf) {
      return &entry.output();
    }
  }
  return nullptr;
}

uint32_t CpuIdDump::GetNextSubleaf(uint32_t leaf) const {
  CHECK_LT(leaf, 0xffffffff);
  uint32_t next_subleaf = 0;
  for (const CpuIdEntryProto& entry : dump_proto_.x86_cpuid_dump().entries()) {
    const CpuIdInputProto& input = entry.input();
    if (input.leaf() == leaf && next_subleaf <= input.subleaf()) {
      next_subleaf = input.subleaf() + 1;
    }
  }
  return next_subleaf;
}

}  // namespace x86
}  // namespace exegesis


text:
@echo off
if not "%1" == "" goto continue

if not exist imaginary\obj mkdir imaginary\obj
for %%i in (imaginary\*.yca) do call %0 %%~ni
goto end

:continue
echo Processing %1
firstify imaginary\%1.yca -mshl -o imaginary\obj\%1 > imaginary\obj\%1.txt 2>&1
goto end

:end

redpajama_set_name: RedPajamaGithub


text:
unit
====

I got asked to create small shooting game prototype. At the same time I wanted to practice use of constructors and prototypes in JavaScript. Especially because of constructors that are visible in HeapDumps. When you start looking more closely into memory this can be really useful.

install:
`npm install`

run:
`npm start`

production version:
`npm run clean`
`npm run build`
`npm run test`#starts on localhost with buid version

deploy:

`git subtree push --prefix dist origin gh-pages`


text:
"""Copyright 2014 Cyrus Dasadia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from django.shortcuts import render_to_response, redirect, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from webservice.models import Plugin
from webservice.forms import plugin_forms

@login_required(login_url='/login/')
def view_all_plugins(request):
    render_vars = dict()
    try:
        render_vars['plugins'] = Plugin.objects.all()
    except Plugin.DoesNotExist:
        render_vars['plugins'] = None

    return render_to_response('view_all_plugins.html', render_vars, context_instance=RequestContext(request))

@login_required(login_url='/login/')
def add_new_plugin(request):
    if request.method == 'POST':
        form = plugin_forms.PluginForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/plugins/')
    else:
        form = plugin_forms.PluginForm()
    render_vars = dict()
    render_vars['form'] = form
    return render_to_response('generic_form.html', render_vars, context_instance=RequestContext(request))

@login_required(login_url='/login/')
def edit_plugin(request, plugin_id):
    render_vars = dict()
    plugin_object = get_object_or_404(Plugin, pk=plugin_id)
    if request.method == "POST":
        form = plugin_forms.PluginForm(request.POST)
        if form.is_valid():
            form.save(commit=False)
            plugin_object.name = form.cleaned_data.get('name')
            plugin_object.description = form.cleaned_data.get('description')
            plugin_object.plugin_path = form.cleaned_data.get('plugin_path')
            plugin_object.status = form.cleaned_data.get('status')
            plugin_object.accessible_by = form.cleaned_data.get('accessible_by')
            plugin_object.save()
            return redirect('/plugins/')
    else:
        form = plugin_forms.PluginForm(instance=plugin_object)
    render_vars['form'] = form
    return render_to_response('generic_form.html', render_vars, context_instance=RequestContext(request))


text:
wcf-messaging-service
=====================


text:
(function(module) {
  var repoView = {};

  var ui = function() { // shows "recent" section upon calling ui()
    var $recent = $('#recent');
    $recent.empty().show();
  };

  var render = Handlebars.compile($('#recentTemplate').html()); // calls to fill in handlebars

  repoView.index = function() {
    ui();
    console.log('repos.owned()', repos.owned());
    $('#recent').append( // fills filtered results from repos.owned into the #recent section of page
      repos.owned().map(render)
    ).hide(); // hides recent repos from appearing in the portfolio section when it all loads initially
  };

  module.repoView = repoView;
})(window);


text:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Lorena Pantano on My BioBits</title>
    <link>http://lpantano.github.io/authors/lorena-pantano/</link>
    <description>Recent content in Lorena Pantano on My BioBits</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 01 Sep 2019 00:00:00 +0000</lastBuildDate>

	    <atom:link href="http://lpantano.github.io/authors/lorena-pantano/index.xml" rel="self" type="application/rss+xml" />

    <item>
      <title>Single-cell cloning of human T-cell lines reveals clonal variation in cell death responses to chemotherapeutics.</title>
      <link>http://lpantano.github.io/publication/hanlon-2019/</link>
      <pubDate>Sun, 01 Sep 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/hanlon-2019/</guid>
      <description></description>
    </item>

    <item>
      <title>Sex Differences in Adrenal Bmal1 Deletion-Induced Augmentation of Glucocorticoid Responses to Stress and ACTH in Mice.</title>
      <link>http://lpantano.github.io/publication/engeland-2019/</link>
      <pubDate>Mon, 01 Jul 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/engeland-2019/</guid>
      <description></description>
    </item>

    <item>
      <title>A High-Throughput Screening Identifies MicroRNA Inhibitors That Influence Neuronal Maintenance and/or Response to Oxidative Stress.</title>
      <link>http://lpantano.github.io/publication/pallarsalbanell-2019/</link>
      <pubDate>Sat, 01 Jun 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pallarsalbanell-2019/</guid>
      <description></description>
    </item>

    <item>
      <title>Multi omics analysis of fibrotic kidneys in two mouse models.</title>
      <link>http://lpantano.github.io/publication/pavkovic-2019/</link>
      <pubDate>Sat, 01 Jun 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pavkovic-2019/</guid>
      <description></description>
    </item>

    <item>
      <title>miRNA variants (isomiRs): real molecules or sequencing artifacts?</title>
      <link>http://lpantano.github.io/talk/bioclub2019/</link>
      <pubDate>Sat, 09 Feb 2019 00:00:00 -0500</pubDate>

      <guid>http://lpantano.github.io/talk/bioclub2019/</guid>
      <description></description>
    </item>

    <item>
      <title>Evolutionary and functional impact of common polymorphic inversions in the human genome</title>
      <link>http://lpantano.github.io/publication/giner-2019-evolutionary/</link>
      <pubDate>Tue, 01 Jan 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/giner-2019-evolutionary/</guid>
      <description></description>
    </item>

    <item>
      <title>Sex-dependent changes in miRNA expression in the bed nucleus of the stria terminalis following stress</title>
      <link>http://lpantano.github.io/publication/mavrikaki-2019-sex/</link>
      <pubDate>Tue, 01 Jan 2019 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/mavrikaki-2019-sex/</guid>
      <description></description>
    </item>

    <item>
      <title>MiRNA Wars: The isomiRs menance</title>
      <link>http://lpantano.github.io/talk/big2018/</link>
      <pubDate>Sun, 02 Dec 2018 15:06:12 -0500</pubDate>

      <guid>http://lpantano.github.io/talk/big2018/</guid>
      <description></description>
    </item>

    <item>
      <title>Unification of miRNA and isomiR research: the mirGFF3 format and the mirtop API</title>
      <link>http://lpantano.github.io/publication/desvignes-2018/</link>
      <pubDate>Sat, 01 Dec 2018 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/desvignes-2018/</guid>
      <description></description>
    </item>

    <item>
      <title>The circulating metabolome of human starvation</title>
      <link>http://lpantano.github.io/publication/steinhauser-2018/</link>
      <pubDate>Wed, 01 Aug 2018 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/steinhauser-2018/</guid>
      <description></description>
    </item>

    <item>
      <title>miRTOP: An open source community project for the development of a unified format file for miRNA data</title>
      <link>http://lpantano.github.io/talk/bosc2018/</link>
      <pubDate>Wed, 27 Jun 2018 13:13:02 -0900</pubDate>

      <guid>http://lpantano.github.io/talk/bosc2018/</guid>
      <description></description>
    </item>

    <item>
      <title>Circulating miRNAs, isomiRs and small RNA clusters in human plasma and breast milk</title>
      <link>http://lpantano.github.io/publication/rubio-2018/</link>
      <pubDate>Mon, 01 Jan 2018 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/rubio-2018/</guid>
      <description></description>
    </item>

    <item>
      <title>bcbioRNASeq: R package for bcbio RNA-seq analysis</title>
      <link>http://lpantano.github.io/publication/steinbaugh-2017/</link>
      <pubDate>Wed, 01 Nov 2017 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/steinbaugh-2017/</guid>
      <description></description>
    </item>

    <item>
      <title>Maintenance of macrophage transcriptional programs and intestinal homeostasis by epigenetic reader SP140</title>
      <link>http://lpantano.github.io/publication/mehta-2017/</link>
      <pubDate>Wed, 01 Mar 2017 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/mehta-2017/</guid>
      <description></description>
    </item>

    <item>
      <title>Molecular, phenotypic, and sample-associated data to describe pluripotent stem cell lines and derivatives</title>
      <link>http://lpantano.github.io/publication/daily-2017/</link>
      <pubDate>Wed, 01 Mar 2017 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/daily-2017/</guid>
      <description></description>
    </item>

    <item>
      <title>Empirical comparison of reduced representation bisulfite sequencing and Infinium BeadChip reproducibility and coverage of DNA methylation in humans</title>
      <link>http://lpantano.github.io/publication/carmona-2017/</link>
      <pubDate>Sun, 01 Jan 2017 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/carmona-2017/</guid>
      <description></description>
    </item>

    <item>
      <title>Characterization of the small RNA transcriptome using the bcbio-nextgen python framework</title>
      <link>http://lpantano.github.io/talk/bosc2016/</link>
      <pubDate>Sat, 09 Jul 2016 14:54:17 +0100</pubDate>

      <guid>http://lpantano.github.io/talk/bosc2016/</guid>
      <description></description>
    </item>

    <item>
      <title>Specific small-RNA signatures in the amygdala at premotor and motor stages of Parkinson's disease revealed by deep sequencing analysis.</title>
      <link>http://lpantano.github.io/publication/pantano-2015/</link>
      <pubDate>Sun, 01 Nov 2015 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pantano-2015/</guid>
      <description></description>
    </item>

    <item>
      <title>The small RNA content of human sperm reveals pseudogene-derived piRNAs complementary to protein-coding genes.</title>
      <link>http://lpantano.github.io/publication/pantano-2015-a/</link>
      <pubDate>Mon, 01 Jun 2015 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pantano-2015-a/</guid>
      <description></description>
    </item>

    <item>
      <title>Functional Impact and Evolution of a Novel Human Polymorphic Inversion That Disrupts a Gene and Creates a Fusion Transcript</title>
      <link>http://lpantano.github.io/publication/puig-2015/</link>
      <pubDate>Thu, 01 Jan 2015 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/puig-2015/</guid>
      <description></description>
    </item>

    <item>
      <title>Paternal Diet Defines Offspring Chromatin State and Intergenerational Obesity</title>
      <link>http://lpantano.github.io/publication/ost-2014/</link>
      <pubDate>Mon, 01 Dec 2014 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/ost-2014/</guid>
      <description></description>
    </item>

    <item>
      <title>InvFEST, a database integrating information of polymorphic inversions in the human genome</title>
      <link>http://lpantano.github.io/publication/martinez-fundichely-2014/</link>
      <pubDate>Wed, 01 Jan 2014 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/martinez-fundichely-2014/</guid>
      <description></description>
    </item>

    <item>
      <title>A highly expressed miR-101 isomiR is a functional silencing small RNA.</title>
      <link>http://lpantano.github.io/publication/llorens-2013/</link>
      <pubDate>Tue, 01 Jan 2013 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/llorens-2013/</guid>
      <description></description>
    </item>

    <item>
      <title>Microarray and deep sequencing cross-platform analysis of the mirRNome and isomiR variation in response to epidermal growth factor.</title>
      <link>http://lpantano.github.io/publication/llorens-2013-a/</link>
      <pubDate>Tue, 01 Jan 2013 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/llorens-2013-a/</guid>
      <description></description>
    </item>

    <item>
      <title>A Pathogenic Mechanism in Huntington's Disease Involves Small CAG-Repeated RNAs with Neurotoxic Activity.</title>
      <link>http://lpantano.github.io/publication/banez-coronel-2012/</link>
      <pubDate>Wed, 01 Feb 2012 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/banez-coronel-2012/</guid>
      <description></description>
    </item>

    <item>
      <title>A non-biased framework for the annotation and classification of the non-miRNA small RNA transcriptome.</title>
      <link>http://lpantano.github.io/publication/pantano-2011/</link>
      <pubDate>Tue, 01 Nov 2011 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pantano-2011/</guid>
      <description></description>
    </item>

    <item>
      <title>A myriad of miRNA variants in control and Huntington's disease brain regions detected by massively parallel sequencing</title>
      <link>http://lpantano.github.io/publication/marti-2010/</link>
      <pubDate>Fri, 01 Jan 2010 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/marti-2010/</guid>
      <description></description>
    </item>

    <item>
      <title>SeqBuster, a bioinformatic tool for the processing and analysis of small RNAs datasets, reveals ubiquitous miRNA modifications in human embryonic cells</title>
      <link>http://lpantano.github.io/publication/pantano-2010/</link>
      <pubDate>Fri, 01 Jan 2010 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pantano-2010/</guid>
      <description></description>
    </item>

    <item>
      <title>Fibroblast-derived induced pluripotent stem cells show no common retroviral vector insertions.</title>
      <link>http://lpantano.github.io/publication/varas-2009/</link>
      <pubDate>Sun, 01 Feb 2009 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/varas-2009/</guid>
      <description></description>
    </item>

    <item>
      <title>Identification of Copy Number Variants Defining Genomic Differences among Major Human Groups</title>
      <link>http://lpantano.github.io/publication/armengol-2009/</link>
      <pubDate>Thu, 01 Jan 2009 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/armengol-2009/</guid>
      <description></description>
    </item>

    <item>
      <title>ProSeeK: A web server for MLPA probe design</title>
      <link>http://lpantano.github.io/publication/pantano-2008/</link>
      <pubDate>Tue, 01 Jan 2008 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/pantano-2008/</guid>
      <description></description>
    </item>

    <item>
      <title>Highlights from the Third International Society for Computational Biology Student Council Symposium at the Fifteenth Annual International Conference on Intelligent Systems for Molecular Biology</title>
      <link>http://lpantano.github.io/publication/grynberg-2007/</link>
      <pubDate>Mon, 01 Jan 2007 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/grynberg-2007/</guid>
      <description></description>
    </item>

    <item>
      <title>Genome assembly comparison identifies structural variants in the human genome.</title>
      <link>http://lpantano.github.io/publication/khaja-2006/</link>
      <pubDate>Sun, 01 Jan 2006 00:00:00 +0000</pubDate>

      <guid>http://lpantano.github.io/publication/khaja-2006/</guid>
      <description></description>
    </item>

  </channel>
</rss>


text:
  Sermérieu est
      une ville localisée dans le département de l'Isère en Rhône-Alpes. Elle comptait 1 425 habitants en 2008.

À Sermérieu, la valorisation moyenne à l'achat d'un appartement s'évalue à 1 304 € du m² en vente. la valorisation moyenne d'une maison à l'achat se situe à 1 820 € du m². À la location la valorisation moyenne se situe à 10 € du m² par mois.

Le parc de logements, à Sermérieu, était réparti en 2011 en 45 appartements et 609 maisons soit
 un marché plutôt équilibré.

À proximité de Sermérieu sont positionnées géographiquement les villes de
Montcarra localisée à 6 km, 422 habitants,
Morestel située à 4 km, 3 841 habitants,
Passins à 2 km, 908 habitants,
Saint-Sorlin-de-Morestel localisée à 6 km, 539 habitants,
Soleymieu localisée à 6 km, 660 habitants,
Vasselin localisée à 5 km, 378 habitants,
 entre autres. De plus, Sermérieu est située à seulement quatorze km de Bourgoin-Jallieu.


text:
""" Module for producing the Project Summary Report
Note: Much of this code was written by Pontus and lifted from
the SciLifeLab repo
"""

from collections import defaultdict, OrderedDict
import os
from string import ascii_uppercase as alphabets

import ngi_reports.reports

class Report(ngi_reports.reports.BaseReport):

    ## initialize class and assign basic variables
    def __init__(self, LOG, working_dir, **kwargs):
        # Initialise the parent class
        super(Report, self).__init__(LOG, working_dir, **kwargs)
        # general initialization
        self.tables_info = defaultdict(dict)
        self.report_info = {}
        # report name and directory to be created
        self.report_dir = os.path.join(working_dir, 'reports')
        self.report_basename = ''
        self.signature = kwargs.get('signature')

    def generate_report_template(self, proj, template, support_email):

        ## Check and exit if signature not provided
        if not self.signature:
            self.LOG.error('It is required to provide Signature/Name while generating \'project_summary\' report, see -s opition in help')
            raise SystemExit
        else:
            self.report_info['signature'] = self.signature

        ## Helper vars
        seq_methods = OrderedDict()

        ## Get information for the report
        self.report_basename              = proj.ngi_name
        self.report_info['support_email'] = support_email
        self.report_info['dates']         = self.get_order_dates(proj.dates)
        self.report_info['report_date']   = self.creation_date
        self.report_info['accredit']      = self.get_accredit_info(proj.accredited, proj.library_construction, proj.ngi_name)

        ## Get sequecing method for the flowcell
        seq_template = '{}) Samples were sequenced on {} ({}) with a {} setup '\
                       'using {}. The Bcl to FastQ conversion was performed using {} from the CASAVA software '\
                       'suite. The quality scale used is Sanger / phred33 / Illumina 1.8+.'
        ## Collect required information for all flowcell run for the project
        for fc in proj.flowcells.values():
            ## Sort by the order of readss
            run_setup = sorted(fc.run_setup, key=lambda k: k['Number'])
            run_setup_text = ''
            read_count = 0
            index_count = 0
            for read in run_setup:
                run_setup_text += read['NumCycles']
                run_setup_text += 'nt'
                if read['IsIndexedRead'] == 'N':
                    read_count += 1
                    run_setup_text += '(Read'
                    run_setup_text += str(read_count)
                elif read['IsIndexedRead'] == 'Y':
                    index_count += 1
                    run_setup_text += '(Index'
                    run_setup_text += str(index_count)
                if run_setup.index(read) == len(run_setup)-1:
                    run_setup_text += ')'
                else:
                    run_setup_text += ')-'

            if fc.type == 'NovaSeq6000':
                fc_chem = '\'{}\' workflow in \'{}\' mode flowcell'.format(fc.chemistry.get('WorkflowType'), fc.chemistry.get('FlowCellMode'))
            elif fc.type == 'NextSeq500':
                fc_chem = '\'{}-Output\' chemistry'.format(fc.chemistry.get('Chemistry'))
            elif fc.type == 'NextSeq2000':
                fc_chem = '\'{}\' flowcell'.format(fc.chemistry.get('Chemistry'))
            else:
                fc_chem = '\'{}\' chemistry'.format(fc.chemistry.get('Chemistry'))

            applicationName = 'MSC' if fc.type == "MiSeq" else fc.seq_software.get('ApplicationName')
            seq_software = "{} {}/RTA {}".format(applicationName, fc.seq_software.get('ApplicationVersion'), fc.seq_software.get('RTAVersion'))
            tmp_method = seq_template.format('SECTION', fc.type, seq_software, run_setup_text, fc_chem, fc.casava)

            ## to make sure the sequencing methods are unique
            if tmp_method not in list(seq_methods.keys()):
                seq_methods[tmp_method] = alphabets[len(list(seq_methods.keys()))]
            fc.seq_meth = seq_methods[tmp_method]

        ## give proper section name for the methods
        self.report_info['sequencing_methods'] = "\n\n".join([m.replace('SECTION',seq_methods[m]) for m in seq_methods])
        ## Check if sequencing info is complete
        if not self.report_info['sequencing_methods']:
            self.LOG.warn('Sequencing methods may have some missing information, kindly check your inputs.')

        ###############################################################################
        ##### Create table text and header explanation from collected information #####
        ###############################################################################

        ## sample_info table
        unit_magnitude = {'#reads' : '', 'Kreads': ' Thousand','Mreads': ' Million'}
        sample_header = ['NGI ID', 'User ID', proj.samples_unit, '≥Q30']
        sample_filter = ['ngi_id', 'customer_name', 'total_reads', 'qscore']

        self.tables_info['tables']['sample_info'] = self.create_table_text(proj.samples.values(), filter_keys=sample_filter, header=sample_header)
        self.tables_info['header_explanation']['sample_info'] = '* _NGI ID:_ Internal NGI sample identifier\n'\
                                                                '* _User ID:_ Sample name submitted by user\n'\
                                                                '* _{}:_ Total{} reads (or pairs) for a sample\n'\
                                                                '* _≥Q30:_ Aggregated percentage of bases that have a quality score ≥ Q30'\
                                                                .format(proj.samples_unit, unit_magnitude[proj.samples_unit])

        ## library_info table
        library_header = ['NGI ID', 'Index', 'Lib Prep', 'Avg. FS', 'Lib QC']
        library_filter = ['ngi_id', 'barcode', 'label', 'avg_size', 'qc_status']
        library_list = []
        for s, v in list(proj.samples.items()):
            for p in list(v.preps.values()):
                p = vars(p)
                p['ngi_id'] = s
                library_list.append(p)
        self.tables_info['tables']['library_info'] = self.create_table_text(sorted(library_list, key=lambda d: d['ngi_id']), filter_keys=library_filter, header=library_header)
        self.tables_info['header_explanation']['library_info'] = '* _NGI ID:_ Internal NGI sample identifier\n'\
                                                                 '* _Index:_ Barcode sequence used for the sample\n'\
                                                                 '* _Lib. Prep:_ NGI library identifier. The first library prep will be marked "A", the second "B" and so on.\n'\
                                                                 '* _Avg. FS:_ Average fragment size of the library\n'\
                                                                 '* _Lib. QC:_ Library quality control status\n'

        ## lanes_info table
        lanes_header = ['Date', 'FC id', 'Lane', 'Cluster(M)', 'Phix', '≥Q30(%)', 'Method']
        lanes_filter = ['date', 'name', 'id', 'cluster', 'phix', 'avg_qval', 'seq_meth']
        lanes_list = []
        for f, v in list(proj.flowcells.items()):
            for l in list(v.lanes.values()):
                l = vars(l)
                l['date'] = v.date
                l['name'] = v.name
                l['seq_meth'] = v.seq_meth
                lanes_list.append(l)

        self.tables_info['tables']['lanes_info'] = self.create_table_text(sorted(lanes_list, key=lambda d: '{}_{}'.format(d['date'],d['id'])), filter_keys=lanes_filter, header=lanes_header)
        self.tables_info['header_explanation']['lanes_info'] = '* _Date:_ Date of sequencing\n'\
                                                               '* _Flowcell:_ Flowcell identifier\n'\
                                                               '* _Lane:_ Flowcell lane number\n'\
                                                               '* _Clusters:_ Number of clusters that passed the read filters (millions)\n'\
                                                               '* _≥Q30:_ Aggregated percentage of bases that have a quality score ≥ Q30\n'\
                                                               '* _PhiX:_ Average PhiX error rate for the lane\n'\
                                                               '* _Method:_ Sequencing method used. See description under Sequencing heading above.\n'

        # Make the file basename
        output_bn = os.path.realpath(os.path.join(self.working_dir, self.report_dir, '{}_project_summary'.format(self.report_basename)))

        # Parse the template
        try:
            md = template.render(project=proj, tables=self.tables_info['header_explanation'], report_info=self.report_info)
            return {output_bn: md}
        except:
            self.LOG.error('Could not parse the project_summary template')
            raise

    #####################################################
    ##### Helper methods to get certain information #####
    #####################################################

    def create_table_text(self, ip, filter_keys=None, header=None, sep='\t'):
        """ Create a single text string that will be saved in a file in TABLE format
            from given dict and filtered based upon mentioned header.

            :param dict/list ip: Input dictionary/list to be convertead as table string
            :param list filter: A list of keys that will be used to filter the ip_dict
            :param list header: A list that will be used as header
            :param str sep: A string that will be used as separator
        """
        op_string = []
        if isinstance(ip, dict):
            ip = list(ip.values())
        if header:
            op_string.append(sep.join(header))
        if not filter_keys:
            filter_keys = []
            for i in ip:
                filter_keys.extend(list(i.keys()))
            filter_keys = sorted(list(set(filter_keys)))
        for i in ip:
            row = []
            for k in filter_keys:
                if type(i) is dict:
                    row.append(i.get(k,'NA'))
                else:
                    row.append(getattr(i, k, 'NA'))
            row = list(map(str, row))
            op_string.append(sep.join(row))
        return '\n'.join(op_string)

    def get_order_dates(self, project_dates):
        """ Get order dates as a markdown string. Ignore if unavailable
        """
        dates = []
        for item in project_dates:
            if project_dates.get(item):
                dates.append('_{}:_ {}'.format(item.replace('_', ' ').capitalize(), project_dates[item]))
        return ', '.join(dates)

    def get_accredit_info(self, accredit_dict, library_construction, proj_name):
        """Get swedac accreditation info for given step 'k'

        :param Project proj: Project object containing details of the relevant project
        """
        accredit_info = {}
        for key in accredit_dict:
            accredit = accredit_dict[key]
            ## For "finished library" projects, set certain accredation steps as "NA" even if not set by default
            if key in ['library_preparation','data_analysis'] and library_construction == 'Library was prepared by user.':
                accredit_info[key] = 'Not Applicable'
            elif accredit in ['Yes','No']:
                accredit_info[key] = '{} under ISO/IEC 17025'.format(['[cross] Not accredited','[tick] Accredited'][accredit == 'Yes'])
            elif accredit == 'N/A':
                accredit_info[key] = 'Not Applicable'
            else:
                self.LOG.error('Accreditation step {} for project {} is found, but no value is set'.format(key, proj_name))
        return accredit_info

    # Generate CSV files for the tables
    def create_txt_files(self, op_dir=None):
        """ Generate the CSV files for mentioned tables i.e. a dictionary with table name as key,
            which will be used as file name and the content of file in single string as value to
            put in the TXT file

            :param str op_dir: Path where the TXT files should be created, current dir is default
        """
        for tb_nm, tb_cont in list(self.tables_info['tables'].items()):
            op_fl = '{}_{}.txt'.format(self.report_basename, tb_nm)
            if op_dir:
                op_fl = os.path.join(op_dir, op_fl)
            with open(op_fl, 'w') as TXT:
                TXT.write(tb_cont)


text:
<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Roles Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines are used in roles throughout the system.
    | Regardless where it is placed, a role can be listed here so it is easily
    | found in a intuitive way.
    |
    */

    'web_developer' => 'Webbutvecklare',
    'administrator' => 'Administratör',
    'user' => 'Användare',

];


text:
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.ReadabilityRules
{
    using System;
    using System.Collections.Immutable;
    using System.Linq;
    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CSharp;
    using Microsoft.CodeAnalysis.CSharp.Syntax;
    using Microsoft.CodeAnalysis.Diagnostics;
    using StyleCop.Analyzers.Helpers;
    using StyleCop.Analyzers.Lightup;

    ///
    /// The start of the parameter list for a method or indexer call or declaration does not begin on the same line as
    /// the opening bracket, or on the line after the opening bracket.
    ///
    /// <remarks>
    /// <para>A violation of this rule occurs when there are one or more blank lines between the opening bracket and the
    /// start of the parameter list. For example:</para>
    ///
    /// public string JoinName(
    ///
    ///     string first, string last)
    /// {
    /// }
    ///
    /// <para>The parameter list should begin on the same line as the opening bracket, or on the next line. For
    /// example:</para>
    ///
    /// public string JoinName(string first, string last)
    /// {
    /// }
    ///
    /// public string JoinName(
    ///     string first, string last)
    /// {
    /// }
    ///
    /// </remarks>
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    internal class SA1114ParameterListMustFollowDeclaration : DiagnosticAnalyzer
    {
        ///
        /// The ID for diagnostics produced by the <see cref="SA1114ParameterListMustFollowDeclaration"/> analyzer.
        ///
        public const string DiagnosticId = "SA1114";
        private const string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1114.md";
        private static readonly LocalizableString Title = new LocalizableResourceString(nameof(ReadabilityResources.SA1114Title), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
        private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1114MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));
        private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1114Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources));

        private static readonly DiagnosticDescriptor Descriptor =
            new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

        private static readonly ImmutableArray<SyntaxKind> BaseMethodDeclarationKinds =
            ImmutableArray.Create(SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration, SyntaxKind.OperatorDeclaration, SyntaxKind.ConversionOperatorDeclaration);

        private static readonly Action<SyntaxNodeAnalysisContext> BaseMethodDeclarationAction = HandleBaseMethodDeclaration;
        private static readonly Action<SyntaxNodeAnalysisContext> LocalFunctionStatementAction = HandleLocalFunctionStatement;
        private static readonly Action<SyntaxNodeAnalysisContext> InvocationExpressionAction = HandleInvocationExpression;
        private static readonly Action<SyntaxNodeAnalysisContext> ObjectCreationExpressionAction = HandleObjectCreationExpression;
        private static readonly Action<SyntaxNodeAnalysisContext> IndexerDeclarationAction = HandleIndexerDeclaration;
        private static readonly Action<SyntaxNodeAnalysisContext> ArrayCreationExpressionAction = HandleArrayCreationExpression;
        private static readonly Action<SyntaxNodeAnalysisContext> ElementAccessExpressionAction = HandleElementAccessExpression;
        private static readonly Action<SyntaxNodeAnalysisContext> AttributeAction = HandleAttribute;
        private static readonly Action<SyntaxNodeAnalysisContext> AttributeListAction = HandleAttributeList;
        private static readonly Action<SyntaxNodeAnalysisContext> DelegateDeclarationAction = HandleDelegateDeclaration;
        private static readonly Action<SyntaxNodeAnalysisContext> AnonymousMethodExpressionAction = HandleAnonymousMethodExpression;
        private static readonly Action<SyntaxNodeAnalysisContext> ParenthesizedLambdaExpressionAction = HandleParenthesizedLambdaExpression;

        /// <inheritdoc/>
        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
            ImmutableArray.Create(Descriptor);

        /// <inheritdoc/>
        public override void Initialize(AnalysisContext context)
        {
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
            context.EnableConcurrentExecution();

            context.RegisterSyntaxNodeAction(BaseMethodDeclarationAction, BaseMethodDeclarationKinds);
            context.RegisterSyntaxNodeAction(LocalFunctionStatementAction, SyntaxKindEx.LocalFunctionStatement);
            context.RegisterSyntaxNodeAction(InvocationExpressionAction, SyntaxKind.InvocationExpression);
            context.RegisterSyntaxNodeAction(ObjectCreationExpressionAction, SyntaxKind.ObjectCreationExpression);
            context.RegisterSyntaxNodeAction(IndexerDeclarationAction, SyntaxKind.IndexerDeclaration);
            context.RegisterSyntaxNodeAction(ArrayCreationExpressionAction, SyntaxKind.ArrayCreationExpression);
            context.RegisterSyntaxNodeAction(ElementAccessExpressionAction, SyntaxKind.ElementAccessExpression);
            context.RegisterSyntaxNodeAction(AttributeAction, SyntaxKind.Attribute);
            context.RegisterSyntaxNodeAction(AttributeListAction, SyntaxKind.AttributeList);
            context.RegisterSyntaxNodeAction(DelegateDeclarationAction, SyntaxKind.DelegateDeclaration);
            context.RegisterSyntaxNodeAction(AnonymousMethodExpressionAction, SyntaxKind.AnonymousMethodExpression);
            context.RegisterSyntaxNodeAction(ParenthesizedLambdaExpressionAction, SyntaxKind.ParenthesizedLambdaExpression);
        }

        private static void HandleParenthesizedLambdaExpression(SyntaxNodeAnalysisContext context)
        {
            var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)context.Node;
            AnalyzeParametersList(context, lambdaExpression.ParameterList);
        }

        private static void HandleAnonymousMethodExpression(SyntaxNodeAnalysisContext context)
        {
            var anonymousMethod = (AnonymousMethodExpressionSyntax)context.Node;
            AnalyzeParametersList(context, anonymousMethod.ParameterList);
        }

        private static void HandleDelegateDeclaration(SyntaxNodeAnalysisContext context)
        {
            var delegateDeclaration = (DelegateDeclarationSyntax)context.Node;
            AnalyzeParametersList(context, delegateDeclaration.ParameterList);
        }

        private static void HandleAttributeList(SyntaxNodeAnalysisContext context)
        {
            var attributesList = (AttributeListSyntax)context.Node;

            AnalyzeAttributeList(context, attributesList);
        }

        private static void HandleAttribute(SyntaxNodeAnalysisContext context)
        {
            var attribute = (AttributeSyntax)context.Node;
            AnalyzeArgumentList(context, attribute.ArgumentList);
        }

        private static void HandleElementAccessExpression(SyntaxNodeAnalysisContext context)
        {
            var elementAccess = (ElementAccessExpressionSyntax)context.Node;
            AnalyzeArgumentList(context, elementAccess.ArgumentList);
        }

        private static void HandleArrayCreationExpression(SyntaxNodeAnalysisContext context)
        {
            var arrayCreation = (ArrayCreationExpressionSyntax)context.Node;
            if (arrayCreation.Type == null)
            {
                return;
            }

            AnalyzeRankSpecifiers(context, arrayCreation);
        }

        private static void HandleIndexerDeclaration(SyntaxNodeAnalysisContext context)
        {
            var indexerDeclaration = (IndexerDeclarationSyntax)context.Node;
            AnalyzeBracketParametersList(context, indexerDeclaration.ParameterList);
        }

        private static void HandleObjectCreationExpression(SyntaxNodeAnalysisContext context)
        {
            var objectCreation = (ObjectCreationExpressionSyntax)context.Node;
            if (objectCreation?.ArgumentList != null)
            {
                AnalyzeArgumentList(context, objectCreation.ArgumentList);
            }
        }

        private static void HandleInvocationExpression(SyntaxNodeAnalysisContext context)
        {
            var invocationExpression = (InvocationExpressionSyntax)context.Node;
            AnalyzeArgumentList(context, invocationExpression.ArgumentList);
        }

        private static void HandleBaseMethodDeclaration(SyntaxNodeAnalysisContext context)
        {
            var methodDeclaration = (BaseMethodDeclarationSyntax)context.Node;

            AnalyzeParametersList(context, methodDeclaration.ParameterList);
        }

        private static void HandleLocalFunctionStatement(SyntaxNodeAnalysisContext context)
        {
            var localFunctionStatement = (LocalFunctionStatementSyntaxWrapper)context.Node;

            AnalyzeParametersList(context, localFunctionStatement.ParameterList);
        }

        private static void AnalyzeRankSpecifiers(SyntaxNodeAnalysisContext context, ArrayCreationExpressionSyntax arrayCreation)
        {
            if (!arrayCreation.Type.RankSpecifiers.Any())
            {
                return;
            }

            foreach (var arrayRankSpecifierSyntax in arrayCreation.Type.RankSpecifiers)
            {
                var openBracketToken = arrayRankSpecifierSyntax.OpenBracketToken;
                if (openBracketToken.IsMissing ||
                    arrayRankSpecifierSyntax.IsMissing ||
                    !arrayRankSpecifierSyntax.Sizes.Any())
                {
                    return;
                }

                var firstSize = arrayRankSpecifierSyntax.Sizes[0];

                var firstSizeLineSpan = firstSize.GetLineSpan();
                if (!firstSizeLineSpan.IsValid)
                {
                    return;
                }

                var openBracketLineSpan = openBracketToken.GetLineSpan();
                if (!openBracketLineSpan.IsValid)
                {
                    return;
                }

                if (openBracketLineSpan.EndLinePosition.Line != firstSizeLineSpan.StartLinePosition.Line &&
                    openBracketLineSpan.EndLinePosition.Line != (firstSizeLineSpan.StartLinePosition.Line - 1))
                {
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstSize.GetLocation()));
                }
            }
        }

        private static void AnalyzeAttributeList(SyntaxNodeAnalysisContext context, AttributeListSyntax attributesList)
        {
            var openBracketToken = attributesList.OpenBracketToken;
            if (openBracketToken.IsMissing ||
                attributesList.IsMissing ||
                !attributesList.Attributes.Any())
            {
                return;
            }

            var firstAttribute = attributesList.Attributes[0];

            var firstAttributeLineSpan = firstAttribute.GetLineSpan();
            if (!firstAttributeLineSpan.IsValid)
            {
                return;
            }

            var openBracketLineSpan = openBracketToken.GetLineSpan();
            if (!openBracketLineSpan.IsValid)
            {
                return;
            }

            if (openBracketLineSpan.EndLinePosition.Line != firstAttributeLineSpan.StartLinePosition.Line &&
                openBracketLineSpan.EndLinePosition.Line != (firstAttributeLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstAttribute.GetLocation()));
            }
        }

        private static void AnalyzeArgumentList(SyntaxNodeAnalysisContext context, BracketedArgumentListSyntax argumentListSyntax)
        {
            var openBracketToken = argumentListSyntax.OpenBracketToken;
            if (openBracketToken.IsMissing ||
                argumentListSyntax.IsMissing ||
                !argumentListSyntax.Arguments.Any())
            {
                return;
            }

            var firstArgument = argumentListSyntax.Arguments[0];
            if (firstArgument.GetLeadingTrivia().Any(SyntaxKind.PragmaWarningDirectiveTrivia))
            {
                return;
            }

            var firstArgumentLineSpan = firstArgument.GetLineSpan();
            if (!firstArgumentLineSpan.IsValid)
            {
                return;
            }

            var openBracketLineSpan = openBracketToken.GetLineSpan();
            if (!openBracketLineSpan.IsValid)
            {
                return;
            }

            if (openBracketLineSpan.EndLinePosition.Line != firstArgumentLineSpan.StartLinePosition.Line &&
                openBracketLineSpan.EndLinePosition.Line != (firstArgumentLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation()));
            }
        }

        private static void AnalyzeArgumentList(SyntaxNodeAnalysisContext context, AttributeArgumentListSyntax argumentListSyntax)
        {
            if (argumentListSyntax == null ||
                argumentListSyntax.OpenParenToken.IsMissing ||
                argumentListSyntax.IsMissing ||
                !argumentListSyntax.Arguments.Any())
            {
                return;
            }

            var firstArgument = argumentListSyntax.Arguments[0];
            if (firstArgument.GetLeadingTrivia().Any(SyntaxKind.PragmaWarningDirectiveTrivia))
            {
                return;
            }

            var firstArgumentLineSpan = firstArgument.GetLineSpan();
            if (!firstArgumentLineSpan.IsValid)
            {
                return;
            }

            var openParenLineSpan = argumentListSyntax.OpenParenToken.GetLineSpan();
            if (!openParenLineSpan.IsValid)
            {
                return;
            }

            if (openParenLineSpan.EndLinePosition.Line != firstArgumentLineSpan.StartLinePosition.Line &&
                openParenLineSpan.EndLinePosition.Line != (firstArgumentLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation()));
            }
        }

        private static void AnalyzeArgumentList(SyntaxNodeAnalysisContext context, ArgumentListSyntax argumentListSyntax)
        {
            var openParenToken = argumentListSyntax.OpenParenToken;
            if (openParenToken.IsMissing ||
                argumentListSyntax.IsMissing ||
                !argumentListSyntax.Arguments.Any())
            {
                return;
            }

            var firstArgument = argumentListSyntax.Arguments[0];
            if (firstArgument.GetLeadingTrivia().Any(SyntaxKind.PragmaWarningDirectiveTrivia))
            {
                return;
            }

            var firstArgumentLineSpan = firstArgument.GetLineSpan();
            if (!firstArgumentLineSpan.IsValid)
            {
                return;
            }

            var openParenLineSpan = openParenToken.GetLineSpan();
            if (!openParenLineSpan.IsValid)
            {
                return;
            }

            if (openParenLineSpan.EndLinePosition.Line != firstArgumentLineSpan.StartLinePosition.Line &&
                openParenLineSpan.EndLinePosition.Line != (firstArgumentLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation()));
            }
        }

        private static void AnalyzeBracketParametersList(SyntaxNodeAnalysisContext context, BracketedParameterListSyntax parameterListSyntax)
        {
            var openBracketToken = parameterListSyntax.OpenBracketToken;
            if (openBracketToken.IsMissing ||
                parameterListSyntax.IsMissing ||
                !parameterListSyntax.Parameters.Any())
            {
                return;
            }

            var firstParameter = parameterListSyntax.Parameters[0];

            var firstParameterLineSpan = firstParameter.GetLineSpan();
            if (!firstParameterLineSpan.IsValid)
            {
                return;
            }

            var openBracketLineSpan = openBracketToken.GetLineSpan();
            if (!openBracketLineSpan.IsValid)
            {
                return;
            }

            if (openBracketLineSpan.EndLinePosition.Line != firstParameterLineSpan.StartLinePosition.Line &&
                openBracketLineSpan.EndLinePosition.Line != (firstParameterLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstParameter.GetLocation()));
            }
        }

        private static void AnalyzeParametersList(SyntaxNodeAnalysisContext context, ParameterListSyntax parameterListSyntax)
        {
            if (parameterListSyntax == null ||
                parameterListSyntax.OpenParenToken.IsMissing ||
                parameterListSyntax.IsMissing ||
                !parameterListSyntax.Parameters.Any())
            {
                return;
            }

            var firstParameter = parameterListSyntax.Parameters[0];
            int firstParameterLine;

            if (firstParameter.HasLeadingTrivia && firstParameter.GetLeadingTrivia().All(trivia => IsValidTrivia(trivia)))
            {
                firstParameterLine = firstParameter.SyntaxTree.GetLineSpan(firstParameter.FullSpan).StartLinePosition.Line;
            }
            else
            {
                firstParameterLine = firstParameter.GetLineSpan().StartLinePosition.Line;
            }

            var parenLine = parameterListSyntax.OpenParenToken.GetLineSpan().EndLinePosition.Line;

            if ((firstParameterLine - parenLine) > 1)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstParameter.GetLocation()));
            }
        }

        private static bool IsValidTrivia(SyntaxTrivia trivia)
        {
            switch (trivia.Kind())
            {
            case SyntaxKind.IfDirectiveTrivia:
            case SyntaxKind.ElseDirectiveTrivia:
            case SyntaxKind.ElifDirectiveTrivia:
            case SyntaxKind.EndIfDirectiveTrivia:
            case SyntaxKind.DisabledTextTrivia:
            case SyntaxKind.WhitespaceTrivia:
                return true;

            default:
                return false;
            }
        }
    }
}


text:
import { createTrainingSet } from './training-set';

export const goRustAssignmentsTrainingSet = {
    title: "Go vs Rust",
    left: "Go.Assignment.",
    right: "Rust.Assignment.",
    baseUrl: "languages/",
    examples: createTrainingSet({ name: "Go.Assignment.", number: 19, prefix: ".png" }, { name: "Rust.Assignment.", number: 18, prefix: ".png" })
};

export const haskellRustAssignmentsTrainingSet = {
    title: "Haskell vs Rust",
    left: "Haskell.Assignment.",
    right: "Rust.Assignment.",
    baseUrl: "languages/",
    examples: createTrainingSet({ name: "Haskell.Assignment.", number: 17, prefix: ".png" }, { name: "Rust.Assignment.", number: 18, prefix: ".png" })
};

export const goRustTrainingSet = {
    title: "Go vs Rust",
    left: "Go.",
    right: "Rust.",
    baseUrl: "languages/",
    examples: createTrainingSet({ name: "Go.", number: 23, prefix: ".png" }, { name: "Rust.", number: 23, prefix: ".png" })
};

export const haskellRustTrainingSet = {
    title: "Haskell vs Rust",
    left: "Haskell.",
    right: "Rust.",
    baseUrl: "languages/",
    examples: createTrainingSet({ name: "Haskell.", number: 21, prefix: ".png" }, { name: "Rust.", number: 21, prefix: ".png" })
};


text:
<?php
require_once 'pdo.php';

define('CACHEDIR','cache/');
define('MTGJSON','http://mtgjson.com/json/');
define('VERFILE','version.json');
define('SETFILE','SetCodes.json');

if (!file_exists(CACHEDIR.VERFILE) || file_get_contents(CACHEDIR.VERFILE) !=  file_get_contents(MTGJSON.VERFILE) ) {
	$db = new Model(db());
	file_put_contents(CACHEDIR.VERFILE,  file_get_contents(MTGJSON.VERFILE)) ;
	$sets_json =  file_get_contents(MTGJSON.SETFILE);
	file_put_contents(CACHEDIR.SETFILE,  $sets_json);
	foreach(json_decode( $sets_json ) as $set ) {
		$setjson = file_get_contents(MTGJSON.$set.'.json');
		file_put_contents(CACHEDIR.$set.'.json',$setjson);
		$cset = json_decode( $setjson );
		$fields = ['id'=>$cset->code,'name'=>$cset->name,'rls_dt'=>$cset->releaseDate];
		var_dump($fields);
		$db->upsert('cset','id',$fields);
	}
}


text:
The `Rakefile` creates a login script in the normal location, `~/.config/fish/config.fish`, that sources the login script in this project, `fish/config.fish`. That login script only performs a few tasks:

1. Creates a `PROFILE` environment variable that points to the running script
1. Creates a `SCRIPT_DIR` environment variable that points to the root of this project
1. Creates a `SOURCE_DIR` environment variable that points to the directory above the root of the project
1. Adds `$SCRIPT_DIR/fish/functions` to the front of the `fish_function_path` list so that the functions contained here override the ones that came with fish
1. Sources each file that matches: `$SCRIPT_DIR/fish/init/*.fish`

The individual initialization scripts perform other environment configuration and initialization for particular purposes. See the comments in each script for more information.


text:
var navigationWindow = null;
var collection = null;
var currentIndex = null;
var startIndex = null;
var endIndex = null;

(function constructor(args) {

	navigationWindow = args.navigationWindow;

	collection = args.collection;

	var model = args.model;

	currentIndex = collection.indexOf(model);

	Ti.API.info("SELECTED INDEX: " + currentIndex);

	Ti.API.info("SELECTED MODEL: " + JSON.stringify(model));

	startIndex = currentIndex - 1;
	endIndex = currentIndex + 1;

	if (startIndex > -1) {
		addPageBefore(collection.at(startIndex));
	}

	addPageAfter(model);

	if (endIndex < collection.length) {
		addPageAfter(collection.at(endIndex));
	}

	var previousPage = 1;

	$.scrollableView.addEventListener("scrollend", function(args) {

		if (previousPage != args.currentPage) {
			if (args.currentPage < previousPage) {
				currentIndex--;
			} else if (args.currentPage > previousPage) {
				currentIndex++;
			}
			previousPage = args.currentPage;
		}

		if (args.currentPage == 0) {
			startIndex--;
			if (startIndex > -1) {
				addPageBefore(collection.at(startIndex));
			}

		} else if (args.currentPage == $.scrollableView.getViews().length - 1) {
			endIndex++;
			if (endIndex < collection.length) {
				addPageAfter(collection.at(endIndex));
			}
		}

		$.postsPager.fireEvent("itemSelected", collection.at(currentIndex).toJSON());
	});

})(arguments[0] || {});

function addPageBefore(model) {

	if (OS_IOS) {
		var postPage = Alloy.createController("postPage", {
			model : model,
			navigationWindow : navigationWindow
		}).getView();

		var views = $.scrollableView.getViews();
		views.unshift(postPage);
		$.scrollableView.setViews(views);
		$.scrollableView.setCurrentPage(1);
	}
	if (OS_ANDROID) {
		var postPage = Alloy.createController("postPage", {
			model : model
		}).getView();

		var views = $.scrollableView.getViews();
		views.unshift(postPage);
		$.scrollableView.setViews(views);
		setTimeout(function() {
			$.scrollableView.setCurrentPage(1);
		}, 1000);

		//$.scrollableView.setCurrentPage(0);
	}

	Ti.API.info("ADD BEFORE - CURRENT PAGE: " + $.scrollableView.getCurrentPage());

};

function addPageAfter(model) {

	if (OS_IOS) {
		var postPage = Alloy.createController("postPage", {
			model : model,
			navigationWindow : navigationWindow
		}).getView();

		$.scrollableView.addView(postPage);

		/*var views = $.scrollableView.getViews();
		 views.push(postPage);
		 $.scrollableView.setViews(views);*/
	}
	if (OS_ANDROID) {
		var postPage = Alloy.createController("postPage", {
			model : model
		}).getView();

		$.scrollableView.addView(postPage);

		/*var views = $.scrollableView.getViews();
		 views.push(postPage);
		 $.scrollableView.setViews(views);*/
	}

	Ti.API.info("ADD AFTER - CURRENT PAGE: " + $.scrollableView.getCurrentPage());

};

function onHomeIconItemSelected() {
	$.postsPager.close();
}


text:
<!DOCTYPE html>

<meta charset="US-ASCII">
<title>WebRTC rtcomm.* test</title>

Presence EndPoints Provider Testing


text:
package com.intellij.psi;

import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.PsiTestCase;

import java.io.File;

/**
 *  @author dsl
 */
public class FindClassInDeepPackagesTest extends PsiTestCase {
  @Override
  protected void setUpJdk() {
  }

  private void setUpLibrary(final String s) throws Exception {
    final String testRoot = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/deepPackages";
    VirtualFile classesRoot = WriteCommandAction.runWriteCommandAction(null, new Computable<VirtualFile>() {
      @Override
      public VirtualFile compute() {
        String path = testRoot + "/" + s;
        path = path.replace(File.separatorChar, '/');
        return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
      }
    });
    assertNotNull(classesRoot);
    ModuleRootModificationUtil.addModuleLibrary(myModule, classesRoot.getUrl());
  }

  public void testSRC() throws Exception {
    setUpLibrary("classes");
    final JavaPsiFacade psiManager = getJavaFacade();
    final PsiClass classA = psiManager.findClass("a.a.a.a.e.f.i", GlobalSearchScope.moduleWithLibrariesScope(myModule));
    assertNotNull(classA);
  }

  public void test3() throws Exception {
    setUpLibrary("classes2");
    final JavaPsiFacade psiManager = getJavaFacade();
    final PsiClass classA = psiManager.findClass("com.intellij.internal.f.a.b.a.i", GlobalSearchScope.moduleWithLibrariesScope(myModule));
    assertNotNull(classA);
  }
}


text:
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.

// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_VIEWS_DETAIL_RANGE_TYPE_HPP
#define BOOST_GEOMETRY_VIEWS_DETAIL_RANGE_TYPE_HPP

#include <boost/mpl/assert.hpp>
#include <boost/type_traits.hpp>

#include <boost/geometry/core/ring_type.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>

#include <boost/geometry/views/box_view.hpp>

namespace boost { namespace geometry
{

#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{

template <typename GeometryTag, typename Geometry>
struct range_type
{
    BOOST_MPL_ASSERT_MSG
        (
            false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
            , (types<Geometry>)
        );
};

template <typename Geometry>
struct range_type<ring_tag, Geometry>
{
    typedef Geometry type;
};

template <typename Geometry>
struct range_type<linestring_tag, Geometry>
{
    typedef Geometry type;
};

template <typename Geometry>
struct range_type<polygon_tag, Geometry>
{
    typedef typename ring_type<Geometry>::type type;
};

template <typename Geometry>
struct range_type<box_tag, Geometry>
{
    typedef box_view<Geometry> type;
};

} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH

// Will probably be replaced by the more generic "view_as", therefore in detail
namespace detail
{

/*!
\brief Meta-function defining a type which is a boost-range.
\details
- For linestrings and rings, it defines the type itself.
- For polygons it defines the ring type.
- For multi-points, it defines the type itself
- For multi-polygons and multi-linestrings, it defines the single-version
    (so in the end the linestring and ring-type-of-multi-polygon)
\ingroup iterators
*/
template <typename Geometry>
struct range_type
{
    typedef typename dispatch::range_type
        <
            typename tag<Geometry>::type,
            Geometry
        >::type type;
};

}

}} // namespace boost::geometry

#endif // BOOST_GEOMETRY_VIEWS_DETAIL_RANGE_TYPE_HPP