text:
""" Virana reference tool for downlaoding taxonomically annotated
    reference genomes. Part of the Virana package.

    (c) 2013, Sven-Eric Schelhorn, MPI for Informatics.
"""

import sys
import logging
import gzip
import string
import os
import tarfile
import re

from io import BytesIO
from collections import defaultdict

try:
    from Bio.SeqRecord import SeqRecord
    from Bio import SeqIO
except ImportError:
    message = 'This script requires the BioPython python package\n'
    sys.stderr.write(message)
    sys.exit(1)

try:
    from plumbum import cli
except ImportError:
    message = 'This script requires the plumbum python package\n'
    sys.stderr.write(message)
    sys.exit(1)

try:
    import ftputil
except ImportError:
    message = 'This script requires the ftputil python package\n'
    sys.stderr.write(message)
    sys.exit(1)

NON_ID = ''.join(c for c in map(chr, range(256)) if not c.isalnum())
NON_ID = NON_ID.replace('_', '').replace('-', '')
NUC_TRANS = string.maketrans('uryswkmbdhvURYSWKMBDHV', 'tnnnnnnnnnnTNNNNNNNNNN')

logging.basicConfig(level=logging.INFO, format='%(message)s')

class DataDownloader(object):
    """ Generic class for downloading fasta records via FTP. """

    def __init__(self, host_name, base_path, user='anonymous', password='anonymous'):

        self.group     = 'NoGroup'
        self.host_name = host_name
        self.base_path = base_path

        self.host = ftputil.FTPHost(host_name, user, password)
        self.host.chdir(base_path)

    @classmethod
    def _get_fasta_record(self, record, group, family, organism, identifier, sub_identifier=None, description=''):

        record.seq._data = str(record.seq._data).translate(NUC_TRANS)

        group       = re.sub('[^A-Za-z0-9_]+', '', group)
        family      = re.sub('[^A-Za-z0-9_]+', '', family)
        organism    = re.sub('[^A-Za-z0-9_]+', '', organism)
        identifier  = re.sub('[^A-Za-z0-9_]+', '', identifier)

        if sub_identifier:
            sub_identifier = re.sub('[^A-Za-z0-9_]+', '', sub_identifier)
            record.id  = ';'.join([group, family, organism, identifier, sub_identifier])
        else:
            record.id           = ';'.join([group, family, organism, identifier])

        record.description  = description
        record.name         = ''

        return record

    def get_fasta_records(self):

        raise NotImplementedError

class SilvaDownloader(DataDownloader):
    """ Downlaods rRNA transcripts from the Silva database. """

    def __init__(self, silva_release='111'):

        self.silva_release      = silva_release
        self.silva_host_name    = 'ftp.arb-silva.de'
        self.base_path          = '/release_%s/Exports/' % self.silva_release

        super(SilvaDownloader, self).__init__(self.silva_host_name, self.base_path)

        self.group = 'rRNA'

    def get_fasta_records(self):

        remote_path = self.base_path + 'SSURef_%s_NR_tax_silva_trunc.fasta.tgz' % self.silva_release
        if self.host.path.isfile(remote_path):

            with self.host.open(remote_path, 'rb') as remote_handle:
                remote_content = BytesIO(remote_handle.read())

                with tarfile.open(fileobj=remote_content) as tar:

                    for subentry in tar.getnames():
                        if subentry.endswith('.fasta'):
                            logging.debug('Processing rRNA file %s' % subentry)
                            subhandle = tar.extractfile(subentry)

                            for record in SeqIO.parse(subhandle, "fasta"):
                                identifier  = record.id.split('.')[0]
                                description = '_'.join(record.description.split(' ')[1:])
                                taxonomy    = description.split(';')
                                organism    = taxonomy[-1]
                                family      = 'Unassigned'

                                for level in taxonomy:
                                    if level.endswith('eae'):
                                        family = level
                                        break

                                yield self._get_fasta_record(record, self.group, family, organism, identifier)

class HumanTranscriptDownloader(DataDownloader):
    """ Downloads human transcripts fasta records that contain the locations
        of their exons on the human genome within their description line.
    """

    def __init__(self, build):

        self.ensemble_host_name  = 'ftp.ensembl.org'
        self.gtf_path            = '/pub/current_gtf/homo_sapiens/'
        self.cdna_path           = '/pub/current_fasta/homo_sapiens/cdna'
        self.ncrna_path          = '/pub/current_fasta/homo_sapiens/ncrna'
        self.build               = build
        if self.build == '37':
            self.gtf_path            = '/pub/release-75/gtf/homo_sapiens/'
            self.cdna_path           = '/pub/release-75//fasta/homo_sapiens/cdna'
            self.ncrna_path          = '/pub/release-75//fasta/homo_sapiens/ncrna'

        super(HumanTranscriptDownloader, self).__init__(self.ensemble_host_name, self.gtf_path)

        self.chromosomes    = set()
        self.genes          = defaultdict(set)
        self.regions        = defaultdict(set)
        self.group          = 'Homo_sapiens_cDNA'

    def _cache_annotations(self):
        """ Obtains gtf annotations for human transcripts from ensemble and
            caches them in memory.
        """
        #logging.debug('enter _cache_annotations')

        self.host.chdir(self.gtf_path)

        entries = self.host.listdir(self.host.curdir)

        for entry in entries:
            #logging.debug(entry)

            if self.host.path.isfile(entry):
                if entry.startswith('Homo_sapiens.') and entry.endswith('.gtf.gz'):
                    logging.debug('Processing cDNA annotations %s' % self.gtf_path + '/' + entry)

                    with self.host.open(self.gtf_path + '/' + entry, 'rb') as zipped_handle:
                        remote_content = BytesIO(zipped_handle.read())

                        gzipfile = gzip.GzipFile(fileobj=remote_content)
                        for i, gtf_line in enumerate(gzipfile):
                            #logging.debug(gtf_line)
                            if i % 100000 == 0:
                                logging.debug('Cached %i human transcript annotations' % i)

                            #logging.debug('entering _add_annotation')
                            self._add_annotation(gtf_line)
                        gzipfile.close()

    def _get_raw_transcripts(self):
        """ Obtains coding and noncoding human transcripts from ensemble and
            yields them as fasta records if they have exons that have a known location
            on the human genome. Fasta records contain the exon locations in their header
            lines.
        """

        for subpath in [self.cdna_path, self.ncrna_path]:
            #logging.debug('in'+subpath)

            self.host.chdir(subpath)

            entries = self.host.listdir(self.host.curdir)

            for entry in entries:
                if self.host.path.isfile(entry):
                    if entry.endswith('cdna.all.fa.gz') or entry.endswith('ncrna.fa.gz'):

                        logging.debug('Processing human transcript file %s' % entry)

                        with self.host.open(subpath + '/' + entry, 'rb') as zipped_handle:
                            remote_content = BytesIO(zipped_handle.read())

                            gzipfile = gzip.GzipFile(fileobj=remote_content)
                            for i, record in enumerate(SeqIO.parse(gzipfile, "fasta")):

                                if record.id.startswith('ENST'):

                                    if i % 100000 == 0:
                                        logging.debug('Retrieved %i human transcripts' % i)

                                    #record.description = ''
                                    #logging.debug('record = '+record)

                                    yield record
                            gzipfile.close()

    def _add_annotation(self, gtf_line):
        """ Parses gtf annotations and stores them in memory. """
        #logging.debug("entering _add_annotation")

        if gtf_line[0] == '#':
            return

        fields = gtf_line.strip().split('\t')
        #logging.debug(fields)
        chromosome, source, feature, start, end, score, strands = fields[:7]
        attributes = fields[-1]

        start, end = sorted([int(start), int(end)])

        if feature != 'exon':
            return

        attributes = attributes.replace(' ', '').split(';')
        transcript_ids = [identifier.split('"')[1] for identifier in attributes\
                                if identifier.startswith('transcript_id')]

        gene_names = [identifier.split('"')[1] for identifier in attributes\
                                if identifier.startswith('gene_name')]

        for transcript_id in transcript_ids:
            self.genes[transcript_id] = self.genes[transcript_id].union(gene_names)
            self.regions[transcript_id].add((chromosome, start, end))

    def get_fasta_records(self):
        """ Yields annotated fasta records of human transcripts. """
        #logging.debug("get_fasta_records")
        #logging.debug('Caching annotations')
        self._cache_annotations()

        logging.debug('Downloading and annotating transcripts')
        for record in self._get_raw_transcripts():
            #logging.debug(record)
            transcript_id   = record.id

            if transcript_id in self.regions:

                mapping_locations = self.regions[transcript_id]

                description = '|'.join([';'.join(map(str, location))\
                        for location in mapping_locations])

                # Obtain gene name for transcript
                gene_names = self.genes[transcript_id]
                if gene_names:
                    gene_name = list(gene_names)[0]
                else:
                    gene_name = transcript_id
                #logging.debug(record)
                yield self._get_fasta_record(record, self.group , 'Hominidae', 'Homo_sapiens', gene_name, sub_identifier=transcript_id, description=description)

class RefSeqDownloader(DataDownloader):
    """ Generic downloader that known how to interpret and parse genbank records """

    def __init__(self, group, build):

        self.refseq_host_name  = 'ftp.ncbi.nih.gov'
        self.base_path         = '/genomes/' + group

        super(RefSeqDownloader, self).__init__(self.refseq_host_name, self.base_path)

        self.group              = group

    @classmethod
    def _get_project_from_genbank(self, gb_record):
        """ Parses genbank project identifier from genbank record. """

        project = ''
        for dbxref in gb_record.dbxrefs:
            for entry in dbxref.split(' '):
                if entry.startswith('BioProject'):
                    project = entry.split(':')[1]
                    return project

        if not project:
            for dbxref in gb_record.dbxrefs:
                for entry in dbxref.split(' '):
                    if entry.startswith('Project'):
                        project = entry.split(':')[1]
                        return project

        return project

    @classmethod
    def _get_annotations_from_genbank(self, gb_record):
        """ Parses taxonomic annotation from genbank record. """

        accession   = gb_record.annotations['accessions'][0]
        organism    = gb_record.annotations['organism'].replace(' ', '_')
        organism    = '_'.join(organism.split('_')[:2])
        taxonomy    = ("; ").join(gb_record.annotations['taxonomy'])
        gi          = gb_record.annotations['gi']

        family      = 'Unassigned'
        if len(gb_record.annotations['taxonomy']) > 0:
            for level in gb_record.annotations['taxonomy']:
                if level.endswith('dae') or level.endswith('aceae'):
                    family = level
                    break

        if family == 'Unassigned':
            logging.debug('Unassigned family found based on %s' % taxonomy)

        return organism, accession, gi, taxonomy, family

    @classmethod
    def _get_record_from_genbank(self, gb_record):
        """ Parses sequence from genbank record. """

        return SeqRecord(gb_record.seq)

    @classmethod
    def _parse_genbank_records(self, file_handle):

        try:
            for gb_record in SeqIO.parse(file_handle, 'genbank'):

                project = self._get_project_from_genbank(gb_record)
                organism, accession, gi, taxonomy, family =\
                    self._get_annotations_from_genbank(gb_record)
                record = self._get_record_from_genbank(gb_record)

                if len(record) > 0:
                    yield record, project, taxonomy, family, organism, gi
        except ValueError:
            logging.debug('Error parsing genbank record, skipping')

    def _get_nc(self, entry_path):

        if self.host.path.isfile(entry_path):
            logging.debug('Processing refseq entry %s' % entry_path)
            with self.host.open(entry_path) as remote_handle:

                for record, project, taxonomy, family, organism, gi\
                    in self._parse_genbank_records(remote_handle):

                    cleaned = self._get_fasta_record(record, self.group , family, organism, gi)

                    yield cleaned

    def _get_nz(self, entry_path):

        scaffold_path = entry_path.replace('.gbk', '.scaffold.gbk.tgz')
        if self.host.path.isfile(scaffold_path):
            logging.debug('Processing refseq entry %s' % scaffold_path)
            remote_handle = self.host.open(scaffold_path, 'rb')
            remote_content = BytesIO(remote_handle.read())
            tar = tarfile.open(fileobj=remote_content)
            for subentry in tar.getnames():
                if subentry.endswith('.gbk'):
                    logging.debug('Processing subaccession %s' % subentry)
                    subhandle = tar.extractfile(subentry)
                    for record, project, taxonomy, family, organism, gi in self._parse_genbank_records(subhandle):
                        yield self._get_fasta_record(record, self.group , family, organism, gi)
            tar.close()
            remote_handle.close()

    def get_fasta_records(self):

        species_dirs = self.host.listdir(self.host.curdir)

        for species_dir in species_dirs:

            species_path = self.base_path + '/' + species_dir

            if self.host.path.isdir(species_path):

                self.host.chdir(species_path)

                logging.debug('Processing species directory %s' % species_path)

                if self.host.path.isdir(species_path):

                    self.host.chdir(species_path)

                    entries = self.host.listdir(self.host.curdir)

                    for entry in entries:

                        if self.host.path.isfile(self.host.curdir + '/' + entry):

                            if entry.endswith('.gbk') or entry.endswith('.gbk.gz'):

                                logging.debug('Processing entry %s' % entry)

                                entry_path = species_path + '/' + entry

                                if entry.startswith('NC_'):
                                    for record in self._get_nc(entry_path):
                                        yield record

                                elif entry.startswith('NZ_'):
                                    for record in self._get_nz(entry_path):
                                        yield record

class HumanGenomeDownloader(DataDownloader):

    def __init__(self, build):

        self.ensemble_host_name  = 'ftp.ensembl.org'
        self.base_path           = '/pub/current_fasta/homo_sapiens/'
        self.build               = build
        if self.build == '37':
            self.base_path           = '/pub/release-75/fasta/homo_sapiens/dna'

        super(HumanGenomeDownloader, self).__init__(self.ensemble_host_name, self.base_path)

        self.group          = 'Homo_sapiens'

    def get_fasta_records(self):

        entries = self.host.listdir(self.host.curdir)
        for entry in entries:

            if self.host.path.isfile(entry):

                # You may want to change your filtering criteria here if you would like to include patches and haplotypes
                if entry.endswith('fa.gz') and 'dna_sm.primary_assembly' in entry:

                    logging.debug('Processing human entry %s' % entry)

                    with self.host.open(self.host.getcwd() + '/' + entry, 'rb') as zipped_handle:
                        remote_content = BytesIO(zipped_handle.read())

                        gzipfile = gzip.GzipFile(fileobj=remote_content)

                        for record in SeqIO.parse(gzipfile, "fasta"):

                            identifier      = record.id
                            organism        = 'Homo_sapiens'
                            family          = 'Hominidae'

                            yield self._get_fasta_record(record, self.group, family, organism, identifier)

                        gzipfile.close()

class UniVecDownloader(DataDownloader):

    def __init__(self, build):
        self.univec_host_name  = 'ftp.ncbi.nih.gov'
        self.base_path         = '/pub/UniVec'
        self.build             = build
        if self.build == '37':
            self.base_path         = '/pub/UniVec'

        super(UniVecDownloader, self).__init__(self.univec_host_name, self.base_path)

        self.group          = 'UniVec'

    def get_fasta_records(self):

        logging.debug('Processing Univec entries')

        with self.host.open(self.host.getcwd() + '/' + 'UniVec') as remote_handle:
            for record in SeqIO.parse(remote_handle, "fasta"):
                organism    = '_'.join(record.description.split(' ')[1:])
                family      = 'Unassigned'
                identifier  = '000000000'

                yield self._get_fasta_record(record, self.group, family, organism, identifier)

class CLI(cli.Application):
    """Downloads taxonomically annotated genomic and transcriptomic reference sequences."""
    PROGNAME = "vref"
    VERSION = "1.0.0"
    DESCRIPTION = \
"""DESCRIPTION: Virana vref - downloads taxonomically annotated reference sequences.

The Virana reference utility ('vref') downloads up-to-date human and microbial
reference sequences for analysis of metagenomic short read data. In addition
to allowing convenient download and pooling of reference genomes and transcriptomes,
vref employs a simple but effective taxonomic annotation scheme that is used
by later stages of the Virana pipeline.

https://github.com/schelhorn/virana

Schelhorn S-E, Fischer M, Tolosi L, Altmueller J, Nuernberg P, et al. (2013)
Sensitive Detection of Viral Transcripts in Human Tumor Transcriptomes.
PLoS Comput Biol 9(10): e1003228. doi:10.1371/journal.pcbi.1003228"""

    USAGE = """USAGE: The program has two modes that can be accessed by
       [vref | python vref.py] [fasta, blast]
       """

    def main(self, *args):

        if args:
            print self.DESCRIPTION
            print
            print self.USAGE
            print("ERROR: Unknown command %r" % (args[0]))
            return 1

        if not self.nested_command:
            print self.DESCRIPTION
            print
            print self.USAGE
            print("ERROR : No command given")
            return 1

@CLI.subcommand("fasta")
class References(cli.Application):
    """ Obtains NCBI RefSeq and Ensembl reference genomes and transcriptomes."""

    valid_references = ['Fungi', 'Fungi_DRAFT', 'Bacteria',
              'Bacteria_DRAFT', 'Homo_sapiens',
              'Viruses', 'UniVec', 'Plasmids',
              'Protozoa', 'rRNA', 'Homo_sapiens_cDNA']

    build = cli.SwitchAttr(['-g', '--genome_build'], mandatory=False, default='38', help="Provisions records based on the genome build provided please provide 37 or 38; default is set to GrCh38")

    references = cli.SwitchAttr(['-r', '--reference'],
                                   cli.Set(*valid_references, case_sensitive=True),
                                   list=True, default=valid_references,
                                   mandatory=False,
                                   help="Sets the kind of references to obtain; microbial ('Fungi', 'Fungi_DRAFT', 'Bacteria', 'Bacteria_DRAFT', 'Protozoa', 'Viruses'), 'Plasmids'), human ('Homo_sapiens', 'Homo_sapiens_cDNA'), as well as taxonomically mixed ('rRNA' (from SILVA), 'UniVec') references are available.")

    fasta_path  = cli.SwitchAttr(['-o', '--output_file'], str, mandatory=True,
                                 help="Sets the fasta output file. Note that all downloaded fasta records are stored within a single fasta file.")

    zipped      = cli.Flag(["-z", "--zipped"], help="Write gzipped output")
    debug       = cli.Flag(["-d", "--debug"], help="Enable debug messages")

    def main(self):
        """ Downloads genome fasta files from reference databases"""

        if self.debug:
            logging.getLogger().setLevel(logging.DEBUG)

        if os.path.dirname(self.fasta_path) and not os.path.exists(os.path.dirname(self.fasta_path)):
            logging.debug('Making directories for output file %s' % self.fasta_path)
            os.makedirs(os.path.dirname(self.fasta_path))

        if self.zipped:
            logging.debug('Making zipped output file %s' % self.fasta_path)
            output_file = gzip.open(self.fasta_path, 'wb')

        else:
            logging.debug('Making regular output file %s' % self.fasta_path)
            output_file = open(self.fasta_path, 'w', buffering=100 * 1024 * 1024)

        for reference in self.references:

            if reference == 'UniVec':
                downloader = UniVecDownloader(self.build)
            elif reference == 'Homo_sapiens':
                downloader = HumanGenomeDownloader(self.build)
            elif reference == 'rRNA':
                downloader = SilvaDownloader()
            elif reference == 'Homo_sapiens_cDNA':
                downloader = HumanTranscriptDownloader(self.build)
            else:
                downloader = RefSeqDownloader(group=reference)

            for record in downloader.get_fasta_records():
                #print record
                SeqIO.write([record], output_file, "fasta")

        output_file.close()

@CLI.subcommand("blast")
class Blast(cli.Application):
    """ Obtains blast databases from NCBI."""

    valid_references = ['nt', 'nr']

    references = cli.SwitchAttr(['-r', '--reference_database'],
                                   cli.Set(*valid_references, case_sensitive=True),
                                   list=True, default=valid_references,
                                   mandatory=False,
                                   help="Sets the kind of database to obtain; argument can be supplied multiple times. Common choices for reference databases are 'nr' and 'nt'.")

    database_path  = cli.SwitchAttr(['-o', '--output_path'], str, mandatory=True,
                                 help="Sets the output directory for the blast database. ")

    debug       = cli.Flag(["-d", "--debug"], help="Enable debug messages")

    def main(self):
        """ Downloads blast database files """

        if self.debug:
            logging.getLogger().setLevel(logging.DEBUG)

        if not os.path.exists(self.database_path):
            logging.debug('Making output directory %s' % self.database_path)
            os.makedirs(self.database_path)

        host_name = 'ftp.ncbi.nih.gov'
        host = ftputil.FTPHost(host_name, 'anonymous', 'anonymous')

        for reference in self.references:

            path = '/blast/db'
            host.chdir(path)

            entries = host.listdir(host.curdir)

            for entry in entries:

                if host.path.isfile(entry):

                    if entry.startswith(reference) and entry.endswith('.tar.gz'):
                        logging.debug('Downloading %s' % entry)
                        local_path = os.path.join(self.database_path, entry)
                        host.download(entry, local_path, 'b')
                        logging.debug('Unpacking %s' % entry)
                        tfile = tarfile.open(local_path, 'r:gz')
                        tfile.extractall(self.database_path)
                        os.remove(local_path)

if __name__ == "__main__":
    CLI.run()


text:
import unittest
from stdnet import orm

class TestCase(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        self.orm = orm
        super(TestCase,self).__init__(*args, **kwargs)

    def unregister(self):
        pass

    def tearDown(self):
        orm.clearall()
        self.unregister()

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
 <status>OK</status>
 <result>
  <type>locality</type>
  <type>political</type>
  <formatted_address>Newark-on-Trent, Newark, Nottinghamshire NG24, UK</formatted_address>
  <address_component>
   <long_name>Newark-on-Trent</long_name>
   <short_name>Newark-on-Trent</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Newark</long_name>
   <short_name>Newark</short_name>
   <type>postal_town</type>
  </address_component>
  <address_component>
   <long_name>Newark</long_name>
   <short_name>Newark</short_name>
   <type>administrative_area_level_4</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Newark and Sherwood District</long_name>
   <short_name>Newark and Sherwood District</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Nottinghamshire</long_name>
   <short_name>Nottinghamshire</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>England</long_name>
   <short_name>England</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>United Kingdom</long_name>
   <short_name>GB</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>NG24</long_name>
   <short_name>NG24</short_name>
   <type>postal_code</type>
   <type>postal_code_prefix</type>
  </address_component>
  <geometry>
   <location>
    <lat>53.0700391</lat>
    <lng>-0.8065700</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>53.0568207</lat>
     <lng>-0.8358300</lng>
    </southwest>
    <northeast>
     <lat>53.0957204</lat>
     <lng>-0.7682374</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>53.0568207</lat>
     <lng>-0.8358300</lng>
    </southwest>
    <northeast>
     <lat>53.0957204</lat>
     <lng>-0.7682374</lng>
    </northeast>
   </bounds>
  </geometry>
  <partial_match>true</partial_match>
  <place_id>ChIJ15BFXkU0eEgRw_NBNFilpi8</place_id>
 </result>
</GeocodeResponse>


text:
// ReSharper disable SuspiciousTypeConversion.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable StringIndexOfIsCultureSpecific.1
// ReSharper disable StringIndexOfIsCultureSpecific.2
// ReSharper disable StringCompareToIsCultureSpecific
// ReSharper disable StringCompareIsCultureSpecific.1
// ReSharper disable UnusedMemberInSuper.Global
namespace Apache.Ignite.Core.Tests.Cache.Query.Linq
{
    using System;
    using System.Collections;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Threading;
    using Apache.Ignite.Core.Binary;
    using Apache.Ignite.Core.Cache;
    using Apache.Ignite.Core.Cache.Configuration;
    using Apache.Ignite.Linq;
    using NUnit.Framework;

    /// <summary>
    /// Tests LINQ.
    /// </summary>
    public partial class CacheLinqTest
    {
        /** Cache name. */
        private const string PersonOrgCacheName = "person_org";

        /** Cache schema. */
        private const string PersonOrgCacheSchema = "person_org_Schema";

        /** Cache name. */
        private const string PersonSecondCacheName = "person_cache";

        /** Cache schema. */
        private const string PersonSecondCacheSchema = "\"person_cache_SCHEMA\"";

        /** Role cache name: uses invalid characters to test name escaping. */
        private const string RoleCacheName = "role$ cache.";

        /** */
        private const int RoleCount = 3;

        /** */
        private const int PersonCount = 900;

        /** */
        private bool _runDbConsole;

        /** */
        private static readonly DateTime StartDateTime = new DateTime(2000, 5, 17, 15, 4, 5, DateTimeKind.Utc);

        /// <summary>
        /// Fixture set up.
        /// </summary>
        [TestFixtureSetUp]
        public void FixtureSetUp()
        {
            _runDbConsole = false;  // set to true to open H2 console

            if (_runDbConsole)
                Environment.SetEnvironmentVariable("IGNITE_H2_DEBUG_CONSOLE", "true");

            Ignition.Start(GetConfig());
            Ignition.Start(GetConfig("grid2"));

            // Populate caches
            var cache = GetPersonCache();
            var personCache = GetSecondPersonCache();

            for (var i = 0; i < PersonCount; i++)
            {
                cache.Put(i, new Person(i, string.Format(" Person_{0}  ", i))
                {
                    Address = new Address {Zip = i, Street = "Street " + i, AliasTest = i},
                    OrganizationId = i%2 + 1000,
                    Birthday = StartDateTime.AddYears(i),
                    AliasTest = -i
                });

                var i2 = i + PersonCount;
                personCache.Put(i2, new Person(i2, "Person_" + i2)
                {
                    Address = new Address {Zip = i2, Street = "Street " + i2},
                    OrganizationId = i%2 + 1000,
                    Birthday = StartDateTime.AddYears(i)
                });
            }

            var orgCache = GetOrgCache();

            orgCache[1000] = new Organization {Id = 1000, Name = "Org_0"};
            orgCache[1001] = new Organization {Id = 1001, Name = "Org_1"};
            orgCache[1002] = new Organization {Id = 1002, Name = null};

            var roleCache = GetRoleCache();

            roleCache[new RoleKey(1, 101)] = new Role {Name = "Role_1", Date = StartDateTime};
            roleCache[new RoleKey(2, 102)] = new Role {Name = "Role_2", Date = StartDateTime.AddYears(1)};
            roleCache[new RoleKey(3, 103)] = new Role {Name = null, Date = StartDateTime.AddHours(5432)};
        }

        /// <summary>
        /// Gets the configuration.
        /// </summary>
        private IgniteConfiguration GetConfig(string gridName = null)
        {
            return new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                BinaryConfiguration = new BinaryConfiguration(typeof(Person),
                    typeof(Organization), typeof(Address), typeof(Role), typeof(RoleKey), typeof(Numerics))
                {
                    NameMapper = GetNameMapper()
                },
                IgniteInstanceName = gridName
            };
        }

        /// <summary>
        /// Gets the name mapper.
        /// </summary>
        protected virtual IBinaryNameMapper GetNameMapper()
        {
            return new BinaryBasicNameMapper {IsSimpleName = false};
        }

        /// <summary>
        /// Gets the SqlEscapeAll setting.
        /// </summary>
        protected virtual bool GetSqlEscapeAll()
        {
            return false;
        }

        /// <summary>
        /// Fixture tear down.
        /// </summary>
        [TestFixtureTearDown]
        public void FixtureTearDown()
        {
            if (_runDbConsole)
                Thread.Sleep(Timeout.Infinite);
            Ignition.StopAll(true);
        }

        /// <summary>
        /// Gets the person cache.
        /// </summary>
        /// <returns></returns>
        private ICache<int, Person> GetPersonCache()
        {
            return GetCacheOf<Person>();
        }

        /// <summary>
        /// Gets the org cache.
        /// </summary>
        /// <returns></returns>
        private ICache<int, Organization> GetOrgCache()
        {
            return GetCacheOf<Organization>();
        }

        /// <summary>
        /// Gets the cache.
        /// </summary>
        private ICache<int, T> GetCacheOf<T>()
        {
            return Ignition.GetIgnite()
                .GetOrCreateCache<int, T>(new CacheConfiguration(PersonOrgCacheName,
                    new QueryEntity(typeof (int), typeof (Person))
                    {
                        Aliases = new[]
                        {
                            new QueryAlias("AliasTest", "Person_AliasTest"),
                            new QueryAlias("Address.AliasTest", "Addr_AliasTest")
                        },
                        KeyFieldName = "MyKey",
                        ValueFieldName = "MyValue",
                        Fields =
                        {
                            new QueryField("MyKey", typeof(int)),
                            new QueryField("MyValue", typeof(T)),
                        }
                    },
                    new QueryEntity(typeof (int), typeof (Organization)))
                {
                    CacheMode = CacheMode.Replicated,
                    SqlEscapeAll = GetSqlEscapeAll(),
                    SqlSchema = PersonOrgCacheSchema
                });
        }

        /// <summary>
        /// Gets the role cache.
        /// </summary>
        private ICache<RoleKey, Role> GetRoleCache()
        {
            return Ignition.GetIgnite()
                .GetOrCreateCache<RoleKey, Role>(new CacheConfiguration(RoleCacheName,
                    new QueryEntity(typeof (RoleKey), typeof (Role)))
                {
                    CacheMode = CacheMode.Replicated,
                    SqlEscapeAll = GetSqlEscapeAll()
                });
        }

        /// <summary>
        /// Gets the second person cache.
        /// </summary>
        private ICache<int, Person> GetSecondPersonCache()
        {
            return Ignition.GetIgnite()
                .GetOrCreateCache<int, Person>(
                    new CacheConfiguration(PersonSecondCacheName,
                        new QueryEntity(typeof(int), typeof(Person))
                        {
                            TableName = "CustomPersons"
                        })
                    {
                        CacheMode = CacheMode.Replicated,
                        SqlEscapeAll = GetSqlEscapeAll(),
                        SqlSchema = PersonSecondCacheSchema
                    });
        }

        /// <summary>
        /// Checks that function maps to SQL function properly.
        /// </summary>
        private static void CheckFunc<T, TR>(Expression<Func<T, TR>> exp, IQueryable<T> query,
            Func<TR, TR> localResultFunc = null)
        {
            localResultFunc = localResultFunc ?? (x => x);

            // Calculate result locally, using real method invocation
            var expected = query.ToArray().AsQueryable().Select(exp).Select(localResultFunc).OrderBy(x => x).ToArray();

            // Perform SQL query
            var actual = query.Select(exp).ToArray().OrderBy(x => x).ToArray();

            // Compare results
            CollectionAssert.AreEqual(expected, actual, new NumericComparer());

            // Perform intermediate anonymous type conversion to check type projection
            actual = query.Select(exp).Select(x => new {Foo = x}).ToArray().Select(x => x.Foo)
                .OrderBy(x => x).ToArray();

            // Compare results
            CollectionAssert.AreEqual(expected, actual, new NumericComparer());
        }

        /// <summary>
        /// Checks that function used in Where Clause maps to SQL function properly
        /// </summary>
        private static void CheckWhereFunc<TKey, TEntry>(IQueryable<ICacheEntry<TKey,TEntry>> query,
            Expression<Func<ICacheEntry<TKey, TEntry>,bool>> whereExpression)
        {
            // Calculate result locally, using real method invocation
            var expected = query
                .ToArray()
                .AsQueryable()
                .Where(whereExpression)
                .Select(entry => entry.Key)
                .OrderBy(x => x)
                .ToArray();

            // Perform SQL query
            var actual = query
                .Where(whereExpression)
                .Select(entry => entry.Key)
                .ToArray()
                .OrderBy(x => x)
                .ToArray();

            // Compare results
            CollectionAssert.AreEqual(expected, actual, new NumericComparer());
        }

        /// <summary>
        /// Tests conditinal statement
        /// </summary>
        private void TestConditional<T>(T even , T odd, Func<T,T,bool> comparer = null)
        {
            var persons = GetPersonCache().AsCacheQueryable();

            var res = persons
                .Select(x => new { x.Key, Foo = x.Key % 2 == 0 ? even : odd, x.Value })
                .OrderBy(x => x.Key)
                .ToArray();

            if (comparer != null)
            {
                Assert.IsTrue(comparer(even, res[0].Foo));
                Assert.IsTrue(comparer(odd, res[1].Foo));
            }
            else
            {
                Assert.AreEqual(even, res[0].Foo);
                Assert.AreEqual(odd, res[1].Foo);
            }
        }

        /// <summary>
        /// Tests conditinal statement for structs with default and null values
        /// </summary>
        private void TestConditionalWithNullableStructs<T>(T? defaultFalue = null) where T : struct
        {
            var def = defaultFalue ?? default(T);
            TestConditional(def, (T?) null);
        }

        public interface IPerson
        {
            int Age { get; set; }
            string Name { get; set; }
        }

        public class Person : IBinarizable, IPerson
        {
            public Person(int age, string name)
            {
                Age = age;
                Name = name;
            }

            [QuerySqlField(Name = "age1")] public int Age { get; set; }

            [QuerySqlField] public string Name { get; set; }

            [QuerySqlField] public Address Address { get; set; }

            [QuerySqlField] public int OrganizationId { get; set; }

            [QuerySqlField] public DateTime? Birthday { get; set; }

            [QuerySqlField] public int AliasTest { get; set; }

            [QuerySqlField] public bool Bool { get; set; }

            public void WriteBinary(IBinaryWriter writer)
            {
                writer.WriteInt("age1", Age);
                writer.WriteString("name", Name);
                writer.WriteInt("OrganizationId", OrganizationId);
                writer.WriteObject("Address", Address);
                writer.WriteTimestamp("Birthday", Birthday);
                writer.WriteInt("AliasTest", AliasTest);
                writer.WriteBoolean("Bool", Bool);
            }

            public void ReadBinary(IBinaryReader reader)
            {
                Age = reader.ReadInt("age1");
                Name = reader.ReadString("name");
                OrganizationId = reader.ReadInt("OrganizationId");
                Address = reader.ReadObject<Address>("Address");
                Birthday = reader.ReadTimestamp("Birthday");
                AliasTest = reader.ReadInt("AliasTest");
                Bool = reader.ReadBoolean("Bool");
            }
        }

        public class Address
        {
            [QuerySqlField] public int Zip { get; set; }
            [QuerySqlField] public string Street { get; set; }
            [QuerySqlField] public int AliasTest { get; set; }
        }

        public class Organization
        {
            [QuerySqlField] public int Id { get; set; }
            [QuerySqlField] public string Name { get; set; }
        }

        public interface IRole
        {
            string Name { get; }
            DateTime Date { get; }
        }

        public class Role : IRole
        {
            [QuerySqlField] public string Name { get; set; }
            [QuerySqlField] public DateTime Date { get; set; }
        }

        public class Numerics
        {
            public Numerics(double val)
            {
                Double = val;
                Float = (float) val;
                Decimal = (decimal) val;
                Int = (int) val;
                Uint = (uint) val;
                Long = (long) val;
                Ulong = (ulong) val;
                Short = (short) val;
                Ushort = (ushort) val;
                Byte = (byte) val;
                Sbyte =  (sbyte) val;
            }

            [QuerySqlField] public double Double { get; set; }
            [QuerySqlField] public float Float { get; set; }
            [QuerySqlField] public decimal Decimal { get; set; }
            [QuerySqlField] public int Int { get; set; }
            [QuerySqlField] public uint Uint { get; set; }
            [QuerySqlField] public long Long { get; set; }
            [QuerySqlField] public ulong Ulong { get; set; }
            [QuerySqlField] public short Short { get; set; }
            [QuerySqlField] public ushort Ushort { get; set; }
            [QuerySqlField] public byte Byte { get; set; }
            [QuerySqlField] public sbyte Sbyte { get; set; }
        }

        public struct RoleKey : IEquatable<RoleKey>
        {
            private readonly int _foo;
            private readonly long _bar;

            public RoleKey(int foo, long bar)
            {
                _foo = foo;
                _bar = bar;
            }

            [QuerySqlField(Name = "_foo")]
            public int Foo
            {
                get { return _foo; }
            }

            [QuerySqlField(Name = "_bar")]
            public long Bar
            {
                get { return _bar; }
            }

            public bool Equals(RoleKey other)
            {
                return _foo == other._foo && _bar == other._bar;
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj)) return false;
                return obj is RoleKey && Equals((RoleKey) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (_foo*397) ^ _bar.GetHashCode();
                }
            }

            public static bool operator ==(RoleKey left, RoleKey right)
            {
                return left.Equals(right);
            }

            public static bool operator !=(RoleKey left, RoleKey right)
            {
                return !left.Equals(right);
            }
        }

        /// <summary>
        /// Epsilon comparer.
        /// </summary>
        private class NumericComparer : IComparer
        {
            /** <inheritdoc /> */
            public int Compare(object x, object y)
            {
                if (Equals(x, y))
                    return 0;

                if (x is double && y is double)
                {
                    var dx = (double) x;
                    var dy = (double) y;

                    // Epsilon is proportional to the min value, but not too small.
                    const double epsilon = 2E-10d;
                    var min = Math.Min(Math.Abs(dx), Math.Abs(dy));
                    var relEpsilon = Math.Max(min*epsilon, epsilon);

                    // Compare with epsilon because some funcs return slightly different results.
                    return Math.Abs((double) x - (double) y) < relEpsilon ? 0 : 1;
                }

                // ReSharper disable once PossibleNullReferenceException
                return ((IComparable) x).CompareTo(y);
            }
        }
    }
}


text:
using Edi.Advance.BTEC.UiTests.Flows;
using NUnit.Framework;

namespace Edi.Advance.BTEC.UiTests.Tests
{
    public class CookieMessageTest : TestBase
    {
        private const int sessionTimeout = 9*60*1000;

        [Test]
        public void CookieMessageBoxTest()
        {
            Start
                .GoToLoginPage()
                .ClearCookies()
                .EnterCredentials(UiConst.Login.PearsonManager, UiConst.Password.PearsonManager)
                .Login()
                .AssertCookieMsgBoxTextCorrect(UI.CookieTitle, UI.CookieText)
                .AssertCookieMsgBoxLearnMoreLinkIsOpened(UI.CookieLearnMoreUrl)
                .CloseCookieMsgBox()
                .AssertCookieMsgBoxClosed()
                .GoToReports()
                .AssertCookieMsgBoxClosed();
        }

        [Test]
        public void SessionExpiringAutoLogoutTest()
        {
            Start
                .LoginWithQN()
                .GoToCourses()
                .Wait(sessionTimeout)
                .AssertSessionExpiredPopupAppearedDoNothing()
                .LoginWithPearsonManager()
                .GoToTermsOfUse();
        }

        [Test]
        public void SessionExpiringContinueSessionTest()
        {
            Start
                .LoginWithPearsonManager()
                .GoToBroadcast()
                .Wait(sessionTimeout)
                .AssertSessionExpiredPopupAppeared()
                .ContinueSession()
                .GoToTermsOfUse();
        }

        [Test]
        public void SessionExpiringOnAssignmentStep3AutoSaveOnAutoLogoutTest()
        {
            var assignmentContext = new CreateAssignmentContext();
            Start
                .LoginWithAssessor()
                .CreateAssignmentTillStep3(assignmentContext)
                .FillAllRequiredDataOnStep3(assignmentContext).Next((flow, id) =>
                    flow
                        .Wait(sessionTimeout)
                        .AssertSessionExpiredPopupAppearedDoNothing()
                        .LoginWithAssessor()
                        .GoToAssignments()
                        .Edit(id)
                        .SaveAndContinue()
                        .SaveAndContinue()
                        .CheckAllEnteredDataOnStep3(assignmentContext));
        }

        [Test]
        public void SessionExpiringOnAssignmentStep3BreakSessionTest()
        {
            var assignmentContext = new CreateAssignmentContext();
            Start
                .LoginWithAssessor()
                .CreateAssignmentTillStep3(assignmentContext)
                .FillAllRequiredDataOnStep3(assignmentContext).Next((flow, id) =>
                    flow
                        .Wait(sessionTimeout)
                        .AssertSessionExpiredPopupAppeared()
                        .BreakSession()
                        .LoginWithAssessor()
                        .GoToAssignments()
                        .Edit(id)
                        .SaveAndContinue()
                        .SaveAndContinue()
                        .CheckAllEnteredDataOnStep3(assignmentContext));
        }
    }
}


text:
var hashtrie = {};

var constant = x => () => x;

/* Configuration
 ******************************************************************************/
var SIZE = 4;

var BUCKET_SIZE = Math.pow(2, SIZE);

var mask = BUCKET_SIZE - 1;

/* Nothing
 ******************************************************************************/
var nothing = ({});

/* Bit Ops
 ******************************************************************************/
var hashFragment = (shift, h) =>
    (h >>> shift) & mask;

/* Hashing
 ******************************************************************************/
/**
	Get 32 bit hash of string.

	Based on:
	http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
 */
const hash = hashtrie.hash = str => {
    if (typeof str === 'number')
        return str;

    let hash = 0;
    for (let i = 0, len = str.length; i < len; i = i + 1) {
        const c = str.charCodeAt(i);
        hash = (((hash << 5) - hash) + c) | 0;
    }
    return hash;
};

/* Node Structures
 ******************************************************************************/
function Map(root) {
    this.root = root;
};

const LEAF = 1;
const COLLISION = 2;
const INTERNAL = 3;

/**
	Empty node.
 */
const empty = { __hashtrie_empty: true };

const isEmptyNode = x =>
    x === empty || (x && x.__hashtrie_empty);

/**
	Leaf holding a value.

	@member hash Hash of key.
	@member key Key.
	@member value Value stored.
 */
function Leaf(hash, key, value) {
    this.type = LEAF;
    this.hash = hash;
    this.key = key;
    this.value = value;
};

/**
	Leaf holding multiple values with the same hash but different keys.

	@member hash Hash of key.
	@member children Array of collision nodes.
 */
function Collision(hash, children) {
    this.type = COLLISION;
    this.hash = hash;
    this.children = children;
};

/**
	Internal node

	@member count Number of children.
	@member children Array of child nodes.
 */
function InternalNode(count, children) {
    this.type = INTERNAL;
    this.count = count;
    this.children = children;
};

/* Array ops
 ******************************************************************************/
/**
	Set a value in an array.

	Returns copy of the array with value set.

	@param at Index to set.
	@param v Value.
	@param arr Array.
 */
const arrayUpdate = (at, v, arr) => {
    const len = arr.length;
    const out = new Array(len);
    for (let i = 0; i < len; ++i)
        out[i] = arr[i];
    out[at] = v;
    return out;
};

/**
	Remove a value from an array.

	@param at Index to remove.
	@param arr Array.
 */
var arrayRemove = (at, arr) =>
    arrayUpdate(at, undefined, arr);

/**
	Remove a value from an array.

	@param at Index to remove.
	@param arr Array.
*/
const arraySpliceOut = (at, arr) => {
    const len = arr.length;
    const out = new Array(len - 1);
    let i = 0, g = 0;
    while (i < at)
        out[g++] = arr[i++];
    ++i;
    while (i < len)
        out[g++] = arr[i++];
    return out;
};

/*
 ******************************************************************************/
/**
	Create an internal node with one child
 */
var create1Internal = (h, n) => {
    var children = new Array(BUCKET_SIZE);
    children[h] = n;
    return new InternalNode(1, children);
};

/**
	Create an internal node with two children
 */
var create2Internal = (h1, n1, h2, n2) => {
    var children = new Array(BUCKET_SIZE);
    children[h1] = n1;
    children[h2] = n2;
    return new InternalNode(2, children);
};

/**
	Merge two leaf nodes.

	@param shift Current shift.
	@param h1 Hash of node 1.
	@param n1 Node 1.
	@param h2 Hash of node 2.
	@param n2 Node 2.
 */
var mergeLeaves = (shift, h1, n1, h2, n2) => {
    if (h1 === h2)
        return new Collision(h1, [n2, n1]);

    const subH1 = hashFragment(shift, h1);
    const subH2 = hashFragment(shift, h2);
    return subH1 === subH2
        ?create1Internal(subH1, mergeLeaves(shift + SIZE, n1, n2))
        :create2Internal(subH1, n1, subH2, n2);
};

/**
	Update an entry in a collision list.
 */
const updateCollisionList = (h, list, f, k) => {
    let target;
    let i = 0;
    for (const len = list.length; i < len; ++i) {
        const child = list[i];
        if (child.key === k) {
            target = child;
            break;
        }
    }

    const v = target ? f(target.value) : f();
    return v === nothing
        ?arraySpliceOut(i, list)
        :arrayUpdate(i, new Leaf(h, k, v), list);
};

/* Lookups
 ******************************************************************************/
var _lookup = (node, h, k) => {
    let shift = 0;
    while (true) switch (node.type) {
    case LEAF:
    {
        return k === node.key ? node.value : nothing;
    }
    case COLLISION:
    {
        if (h === node.hash) {
            const children = node.children;
            for (let i = 0, len = children.length; i < len; ++i) {
                const child = children[i];
                if (k === child.key)
                    return child.value;
            }
        }
        return nothing;
    }
    case INTERNAL:
    {
        node = node.children[hashFragment(shift, h)];
        if (node) {
            shift += SIZE;
            break;
        } else {
            return nothing;
        }
    }
    default:
        return nothing;
    }
};

/* Editing
 ******************************************************************************/
empty._modify = function(shift, f, h, k) {
    const v = f()
    return v === nothing ? empty : new Leaf(h, k, v);
};

Leaf.prototype._modify = function(shift, f, h, k) {
   if (k === this.key) {
        const v = f(this.value);
        return v === nothing ? empty : new Leaf(h, k, v);
    }
    const v = f();
    return v === nothing
        ?this
        :mergeLeaves(shift, this.hash, this, h, new Leaf(h, k, v));
};

Collision.prototype._modify = function(shift, f, h, k) {
    if (h === this.hash) {
        const list = updateCollisionList(this.hash, this.children, f, k);
        return list.length > 1
            ?new Collision(this.hash, list)
            :list[0]; // collapse single element collision list
    }
    const v = f();
    return v === nothing
        ?this
        :mergeLeaves(shift, this.hash, this, h, new Leaf(h, k, v));
};

InternalNode.prototype._modify = function(shift, f, h, k) {
    var frag = hashFragment(shift, h);
    var child = this.children[frag] || empty;
    var newChild = child._modify(shift + SIZE, f, h, k);

    if (isEmptyNode(child) && !isEmptyNode(newChild)) { // added
        return new InternalNode(
            this.count + 1,
            arrayUpdate(frag, newChild, this.children))
    }

    if (!isEmptyNode(child) && isEmptyNode(newChild)) { // removed
        return this.count - 1 <= 0
            ?empty
            :new InternalNode(
                this.count - 1,
                arrayRemove(frag, this.children));
    }

    // modified
    return new InternalNode(
        this.count,
        arrayUpdate(frag, newChild, this.children));
};

/*
 ******************************************************************************/
/**
	Is an object a hashtrie?
 */
hashtrie.isHashTrie = m =>
    (m instanceof Map);

/* Queries
 ******************************************************************************/
/**
    Lookup the value for `key` in `map` using a custom `hash`.

    Returns the value or `alt` if none.
*/
const tryGetHash = hashtrie.tryGetHash = (alt, hash, key, map) => {
    const v = _lookup(map.root, hash, key);
    return v === nothing ? alt : v;
};

Map.prototype.tryGetHash = function(hash, key, alt) {
    return tryGetHash(alt, hash, key, this);
};

/**
    Lookup the value for `key` in `map` using internal hash function.

    @see `tryGetHash`
*/
const tryGet = hashtrie.tryGet = (alt, key, map) =>
    tryGetHash(alt, hash(key), key, map);

Map.prototype.tryGet = function(key, alt) {
    return tryGet(alt, key, this);
};

/**
    Lookup the value for `key` in `map` using a custom `hash`.

    Returns the value or `undefined` if none.
*/
const getHash = hashtrie.getHash = (hash, key, map) =>
    tryGetHash(undefined, hash, key, map);

Map.prototype.getHash = function(hash, key, alt) {
    return getHash(hash, key, this);
};

/**
    Lookup the value for `key` in `map` using internal hash function.

    @see `get`
*/
const get = hashtrie.get = (key, map) =>
    tryGet(undefined, key, map);

Map.prototype.get = function(key, alt) {
    return tryGet(alt, key, this);
};

/**
    Does an entry exist for `key` in `map`? Uses custom `hash`.
*/
const hasHash = hashtrie.has = (hash, key, map) =>
    tryGetHash(nothing, hash, key, map) !== nothing;

Map.prototype.hasHash = function(hash, key) {
    return hasHash(hash, key, this);
};

/**
    Does an entry exist for `key` in `map`? Uses internal hash function.
*/
const has = hashtrie.has = (key, map) =>
    hasHash(hash(key), key, map);

Map.prototype.has = function(key) {
    return has(key, this);
};

/**
    Empty node.
*/
hashtrie.empty = new Map(empty);

/**
    Does `map` contain any elements?
*/
const isEmpty = hashtrie.isEmpty = (map) =>
    !!isEmptyNode(map.root);

Map.prototype.isEmpty = function() {
    return isEmpty(this);
};

/* Updates
 ******************************************************************************/
/**
    Alter the value stored for `key` in `map` using function `f` using
    custom hash.

    `f` is invoked with the current value for `k` if it exists,
    or no arguments if no such value exists. `modify` will always either
    update or insert a value into the map.

    Returns a map with the modified value. Does not alter `map`.
*/
const modifyHash = hashtrie.modifyHash = (f, hash, key, map) =>
    new Map(map.root._modify(0, f, hash, key));

Map.prototype.modifyHash = function(hash, key, f) {
    return modifyHash(f, hash, key, this);
};

/**
    Alter the value stored for `key` in `map` using function `f` using
    internal hash function.

    @see `modifyHash`
*/
const modify = hashtrie.modify = (f, key, map) =>
    modifyHash(f, hash(key), key, map);

Map.prototype.modify = function(key, f) {
    return modify(f, key, this);
};

/**
    Store `value` for `key` in `map` using custom `hash`.

    Returns a map with the modified value. Does not alter `map`.
*/
const setHash = hashtrie.setHash = (value, hash, key, map) =>
    modifyHash(constant(value), hash, key, map);

Map.prototype.setHash = function(hash, key, value) {
    return setHash(value, hash, key, this);
};

/**
    Store `value` for `key` in `map` using internal hash function.

    @see `setHash`
*/
const set = hashtrie.set = (value, key, map) =>
    setHash(value, hash(key), key, map);

Map.prototype.set = function(key, value) {
    return set(value, key, this);
};

/**
    Remove the entry for `key` in `map`.

    Returns a map with the value removed. Does not alter `map`.
*/
const del = constant(nothing);
const removeHash = hashtrie.removeHash = (hash, key, map) =>
    modifyHash(del, hash, key, map);

Map.prototype.removeHash = Map.prototype.deleteHash = function(hash, key) {
    return removeHash(hash, key, this);
};

/**
    Remove the entry for `key` in `map` using internal hash function.

    @see `removeHash`
*/
const remove = hashtrie.remove = (key, map) =>
    removeHash(hash(key), key, map);

Map.prototype.remove = Map.prototype.delete = function(key) {
    return remove(key, this);
};

/* Fold
 ******************************************************************************/
Leaf.prototype._fold = function(f, z) {
    return f(z, this.value, this.key);
};

Collision.prototype._fold = function(f, z) {
    return this.children.reduce((p, c) => f(p, c.value, c.key), z);
};

InternalNode.prototype._fold = function(f, z) {
    const children = this.children;
    for (let i = 0, len = children.length; i < len; ++i) {
        const c = children[i];
        if (c && c._fold)
            z = c instanceof Leaf
                ?f(z, c.value, c.key)
                :c._fold(f, z);
    }
    return z;
};

/**
    Visit every entry in the map, aggregating data.

    Order of nodes is not guaranteed.

    @param f Function mapping previous value and key value object to new value.
    @param z Starting value.
    @param m HAMT
*/
const fold = hashtrie.fold = (f, z, m) =>
    isEmptyNode(m.root) ? z : m.root._fold(f, z);

Map.prototype.fold = function(f, z) {
    return fold(f, z, this);
};

/* Aggregate
 ******************************************************************************/
/**
    Get the number of entries in `map`.
*/
let inc = x => x + 1;
const count = hashtrie.count = map =>
    fold(inc, 0, map);

Map.prototype.count = function() {
    return count(this);
};

/**
    Get array of all key value pairs as arrays of [key, value] in `map`.

    Order is not guaranteed.
*/
const buildPairs = (p, value, key) => { p.push([key, value]); return p; };
const pairs = hashtrie.pairs = map =>
    fold(buildPairs, [], m);

Map.prototype.pairs = function() {
    return count(this);
};

/**
    Get array of all keys in `map`.

    Order is not guaranteed.
*/
const buildKeys = (p, _, key) => { p.push(key); return p; };
const keys = hashtrie.keys = m =>
    fold(buildKeys, [], m);

Map.prototype.keys = function() {
    return keys(this);
};

/**
    Get array of all values in `map`.

    Order is not guaranteed, duplicates are preserved.
*/
const buildValues = (p, value) => { p.push(value); return p; };
const values = hashtrie.values = m =>
    fold(buildValues, [], m);

Map.prototype.values = function() {
    return values(this);
};

/* Export
 ******************************************************************************/
if (typeof module !== 'undefined' && module.exports) {
    module.exports = hashtrie;
} else if (typeof define === 'function' && define.amd) {
    define('hashtrie', [], () => hashtrie);
} else {
    this.hashtrie = hashtrie;
}


text:
package ch.epfl.data.squall.examples.imperative.dbtoaster;

import ch.epfl.data.squall.components.DataSourceComponent;
import ch.epfl.data.squall.components.OperatorComponent;
import ch.epfl.data.squall.components.dbtoaster.DBToasterJoinComponent;
import ch.epfl.data.squall.components.dbtoaster.DBToasterJoinComponentBuilder;
import ch.epfl.data.squall.expressions.ColumnReference;
import ch.epfl.data.squall.operators.AggregateSumOperator;
import ch.epfl.data.squall.operators.ProjectOperator;
import ch.epfl.data.squall.query_plans.QueryBuilder;
import ch.epfl.data.squall.query_plans.QueryPlan;
import ch.epfl.data.squall.types.LongType;
import ch.epfl.data.squall.types.StringType;

import java.util.Arrays;
import java.util.Map;

public class DBToasterHyracksPlan extends QueryPlan {

    private final QueryBuilder _queryBuilder = new QueryBuilder();
    private static final LongType _lc = new LongType();
    private static final StringType _sc = new StringType();

    public DBToasterHyracksPlan(String dataPath, String extension, Map conf) {
        // -------------------------------------------------------------------------------------

        final ProjectOperator projectionCustomer = new ProjectOperator(
                new int[] { 0, 6 });
        final DataSourceComponent relationCustomer = new DataSourceComponent(
                "CUSTOMER", dataPath + "customer" + extension).add(
                projectionCustomer).setOutputPartKey(Arrays.asList(0));
        _queryBuilder.add(relationCustomer);

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

        final ProjectOperator projectionOrders = new ProjectOperator(
                new int[] { 0, 1 });
        final DataSourceComponent relationOrders = new DataSourceComponent(
                "ORDERS", dataPath + "orders" + extension)
                .add(projectionOrders).setOutputPartKey(Arrays.asList(1));
        _queryBuilder.add(relationOrders);

        // -------------------------------------------------------------------------------------
        DBToasterJoinComponentBuilder builder = new DBToasterJoinComponentBuilder();
        builder.addRelation(relationCustomer, _lc, _sc);
        builder.addRelation(relationOrders, _lc, _lc);
        builder.setSQL("SELECT CUSTOMER.f1, COUNT(ORDERS.f0) FROM CUSTOMER, ORDERS WHERE CUSTOMER.f0 = ORDERS.f1 GROUP BY CUSTOMER.f1");

        DBToasterJoinComponent dbToasterComponent = builder.build();
        dbToasterComponent.setPrintOut(false);
        _queryBuilder.add(dbToasterComponent);

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

        final AggregateSumOperator agg = new AggregateSumOperator(
                new ColumnReference(_lc, 1), conf).setGroupByColumns(Arrays
                .asList(0));

        OperatorComponent oc = new OperatorComponent(dbToasterComponent,
                "COUNTAGG").add(agg);
        _queryBuilder.add(oc);

    }

    @Override
    public QueryBuilder getQueryPlan() {
        return _queryBuilder;
    }
}


text:
import LinearConvert from '../src/core/LinearConverter';
describe('LinearConvert', () => {
    it('LinearConvert object should be defined', () => {
        //LinearConvert.should.not.be.undefined;
    });

    it('should return 1 for value equals parameter "to"', () => {
        const result: number = LinearConvert(0, 100, 100);
        result.should.be.equal(1);
    });

    it('should return 1 for value greater than parameter "to"', () => {
        const result: number = LinearConvert(0, 100, 100);
        result.should.be.equal(1);
    });

    it('should return 0 for value equals parameter "from"', () => {
        const result: number = LinearConvert(0, 100, 0);
        result.should.be.equal(0);
    });

    it('should return 0 for value less than parameter "from"', () => {
        const result: number = LinearConvert(0, 100, 0);
        result.should.be.equal(0);
    });

    it('should return 0.5 for value in a middle between "from" and "to"', () => {
        const result: number = LinearConvert(0, 100, 50);
        result.should.be.equal(0.5);

        const result2: number = LinearConvert(-100, 0, -50);
        result2.should.be.equal(0.5);
    });

    it('Gamepad scenario', () => {
        const result: number = LinearConvert(0, -1, -1);
        result.should.be.equal(1);
    });
});


text:
Input::
//// [/user/username/projects/myproject/a.ts]
export class C {}

//// [/user/username/projects/myproject/b.ts]
import {C} from './a';
export function f(p: C) { return p; }

//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{}}

//// [/a/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }

/a/lib/tsc.js -w
Output::
>> Screen clear
[12:00:23 AM] Starting compilation in watch mode...

[12:00:28 AM] Found 0 errors. Watching for file changes.

Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Shape signatures in builder refreshed for::
/a/lib/lib.d.ts (used version)
/user/username/projects/myproject/a.ts (used version)
/user/username/projects/myproject/b.ts (used version)

PolledWatches::
/user/username/projects/myproject/node_modules/@types:
  {"pollingInterval":500}

FsWatches::
/user/username/projects/myproject/tsconfig.json:
  {}
/user/username/projects/myproject/a.ts:
  {}
/user/username/projects/myproject/b.ts:
  {}
/a/lib/lib.d.ts:
  {}

FsWatchesRecursive::
/user/username/projects/myproject:
  {}

exitCode:: ExitStatus.undefined

//// [/user/username/projects/myproject/a.js]
"use strict";
exports.__esModule = true;
exports.C = void 0;
var C = /** @class */ (function () {
    function C() {
    }
    return C;
}());
exports.C = C;

//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
exports.f = void 0;
function f(p) { return p; }
exports.f = f;

Change:: Set to "remove"

Input::
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"remove"}}

Output::
>> Screen clear
[12:00:32 AM] File change detected. Starting incremental compilation...

[12:00:39 AM] Found 0 errors. Watching for file changes.

Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":0,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program structureReused: Completely
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

No shapes updated in the builder::

PolledWatches::
/user/username/projects/myproject/node_modules/@types:
  {"pollingInterval":500}

FsWatches::
/user/username/projects/myproject/tsconfig.json:
  {}
/user/username/projects/myproject/a.ts:
  {}
/user/username/projects/myproject/b.ts:
  {}
/a/lib/lib.d.ts:
  {}

FsWatchesRecursive::
/user/username/projects/myproject:
  {}

exitCode:: ExitStatus.undefined

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents

Change:: Set to "error"

Input::
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"error"}}

Output::
>> Screen clear
[12:00:43 AM] File change detected. Starting incremental compilation...

b.ts:1:1 - error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.

1 import {C} from './a';
  ~~~~~~~~~~~~~~~~~~~~~~

[12:00:50 AM] Found 1 error. Watching for file changes.

Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":2,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program structureReused: Completely
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

No shapes updated in the builder::

PolledWatches::
/user/username/projects/myproject/node_modules/@types:
  {"pollingInterval":500}

FsWatches::
/user/username/projects/myproject/tsconfig.json:
  {}
/user/username/projects/myproject/a.ts:
  {}
/user/username/projects/myproject/b.ts:
  {}
/a/lib/lib.d.ts:
  {}

FsWatchesRecursive::
/user/username/projects/myproject:
  {}

exitCode:: ExitStatus.undefined

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
exports.f = void 0;
require("./a");
function f(p) { return p; }
exports.f = f;

Change:: Set to "preserve"

Input::
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"preserve"}}

Output::
>> Screen clear
[12:00:54 AM] File change detected. Starting incremental compilation...

[12:01:01 AM] Found 0 errors. Watching for file changes.

Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":1,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program structureReused: Completely
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts

No shapes updated in the builder::

PolledWatches::
/user/username/projects/myproject/node_modules/@types:
  {"pollingInterval":500}

FsWatches::
/user/username/projects/myproject/tsconfig.json:
  {}
/user/username/projects/myproject/a.ts:
  {}
/user/username/projects/myproject/b.ts:
  {}
/a/lib/lib.d.ts:
  {}

FsWatchesRecursive::
/user/username/projects/myproject:
  {}

exitCode:: ExitStatus.undefined

//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents


text:
#ifndef RANDOMVOCABULARY_H
#define RANDOMVOCABULARY_H

#include "global.h"

#include <QObject>

class RandomVocabulary : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString word READ word WRITE setWord NOTIFY wordChanged)
    Q_PROPERTY(QString translation READ translation WRITE setTranslation NOTIFY translationChanged)

public:
    explicit RandomVocabulary(QObject *parent = 0);
    QString word();
    QString translation();

signals:
    void wordChanged(QString text);
    void translationChanged(QString translation);

public slots:
    void newRandom();
    void setWord(QString word);
    void setTranslation(QString translation);

private:
    QString _word;
    QString _translation;
};

#endif // RANDOMVOCABULARY_H


text:
layout: reference
title: "Planktic foraminifera form their shells via metastable carbonate phases"
shorttitle: "Vaterite in foraminifera."
author: "Jacob, D.E., Wirth, R., Agbaje, O.B.A., Branson, O., Eggins, S.M."
journal: "Nature Communications"
year: 2017
vol: "8"
pg: "1265"
doi: "doi:10.1038/s41467-017-00955-0"
purl: "https://www.nature.com/articles/s41467-017-00955-0"
description: "Foraminifera employ metastable phases in calcification, which could transform our understanding of their geochemistry."
caption: "Calcification is complicated."
openaccess: false
date: 2017-11-02T12:00
categories: papers
tags: science publication
image:
  thumb: papers_vaterite.png
---


text:
#ifndef OscillatorNode_h
#define OscillatorNode_h

#include "core/platform/audio/AudioBus.h"
#include "modules/webaudio/AudioParam.h"
#include "modules/webaudio/AudioScheduledSourceNode.h"
#include "wtf/OwnArrayPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/Threading.h"

namespace WebCore {

class AudioContext;
class PeriodicWave;

// OscillatorNode is an audio generator of periodic waveforms.

class OscillatorNode : public AudioScheduledSourceNode {
public:
    // The waveform type.
    // These must be defined as in the .idl file.
    enum {
        SINE = 0,
        SQUARE = 1,
        SAWTOOTH = 2,
        TRIANGLE = 3,
        CUSTOM = 4
    };

    static PassRefPtr<OscillatorNode> create(AudioContext*, float sampleRate);

    virtual ~OscillatorNode();

    // AudioNode
    virtual void process(size_t framesToProcess);
    virtual void reset();

    String type() const;

    bool setType(unsigned); // Returns true on success.
    void setType(const String&);

    AudioParam* frequency() { return m_frequency.get(); }
    AudioParam* detune() { return m_detune.get(); }

    void setPeriodicWave(PeriodicWave*);

private:
    OscillatorNode(AudioContext*, float sampleRate);

    // Returns true if there are sample-accurate timeline parameter changes.
    bool calculateSampleAccuratePhaseIncrements(size_t framesToProcess);

    virtual bool propagatesSilence() const OVERRIDE;

    // One of the waveform types defined in the enum.
    unsigned short m_type;

    // Frequency value in Hertz.
    RefPtr<AudioParam> m_frequency;

    // Detune value (deviating from the frequency) in Cents.
    RefPtr<AudioParam> m_detune;

    bool m_firstRender;

    // m_virtualReadIndex is a sample-frame index into our buffer representing the current playback position.
    // Since it's floating-point, it has sub-sample accuracy.
    double m_virtualReadIndex;

    // This synchronizes process().
    mutable Mutex m_processLock;

    // Stores sample-accurate values calculated according to frequency and detune.
    AudioFloatArray m_phaseIncrements;
    AudioFloatArray m_detuneValues;

    RefPtr<PeriodicWave> m_periodicWave;

    // Cache the wave tables for different waveform types, except CUSTOM.
    static PeriodicWave* s_periodicWaveSine;
    static PeriodicWave* s_periodicWaveSquare;
    static PeriodicWave* s_periodicWaveSawtooth;
    static PeriodicWave* s_periodicWaveTriangle;
};

} // namespace WebCore

#endif // OscillatorNode_h


text:
namespace EpisodeInformer.Data.Basics
{
    public enum EpidoseUpdateType
    {
        Everyday = 1,
        OnADay = 2,
        OnADayAtATime = 3,
    }
}


text:
By Yash Rane and Brian Lim, with help from Kitty Fung

UCSB's Discord chat server has been growing quickly over the past year, and this rapid growth has made moderation harder and harder. We wanted to find a way to make managing the server easier, so we built a set of moderator tools.
First, we created a Discord bot using the discord.py module to compile a record of all chat logs. Then, we designed a recurrent neural network to analyze the toxicity of these messages. Finally, we took the data collected from the bot, and the toxicity predictions from the RNN, and created a dashboard that moderators could use to manage and monitor the server.

## Data Collection
The discord.py module allows us to easily create a bot that scrapes each message that gets sent in the server and logs that message to a .csv file. This gives us a convinent way of organizing the data for later analysis. A sample data observation is shown below (toxicity score appended to data later)

## Toxicity Analysis
We created an LSTM with both word embeddings (using word2vec) and character-wise embeddings. Our network architecture is shown below.

Our model was trained on the Google Jigsaw Toxicity data, taken from kaggle.com. We acheived an ROC AUC of 0.88. Google's state-of-the-art model recieved a score of 0.99, but considering that we don't have access to the same kind of resouces that Google does, our score is still impressive.

## Dashboard

Our dashboard was created using plot.ly's dash library for python. On the left side, there are the introductions - information that a moderator could immediately act on. This is especially important to us that we display actionable data, since theres no point showing information that you can't do anything about. On the right side, we have the monitoring portion. This includes a graph of how active the server has been over the past day, and the average toxicity over the same time span.

## Misc Data Visualizations

Looking at the distribution of class years, it's pretty clear that the chat is dominated by freshman, with almost twice as many freshman as any other group. This is reflected in some of our freshman-oriented channels, such as `#questions` and `#roommates-finder`, which are both dominated by incoming first years

## Conclusions
Moving forward, there are a few improvement planned for this project. We want to integrate our dashboard straight into a Discord bot. This would let moderators view and interact with our analytics without ever having to leave the discord app, which would streamline the whole process. We also want to try different neural network architectures, such as a Bi-LSTM or attention models, to try to improve our accuracy
.
While this project has come a long way since we started it in October 2017, there is still a lot of work that needs to be done before it is published and ready to use for a general audience. This being said, it has the potential to become a powerful and impactful tool in the years to come.


text:
import {VNode} from '../VNode';

function updateProps(oldVnode: VNode, vnode: VNode) {
  let key: any;
  let cur: any;
  let old: any;
  let elm = vnode.elm;
  let oldProps = oldVnode.data.props || {};
  let props = vnode.data.props || {};

  for (key in oldProps) {
    if (!props[key]) {
      delete elm[key];
    }
  }
  for (key in props) {
    cur = props[key];
    old = oldProps[key];
    if (old !== cur && (key !== 'value' || elm[key] !== cur)) {
      elm[key] = cur;
    }
  }
}

const PropsModule = {
  create: updateProps,
  update: updateProps,
};

export default PropsModule;


text:
import boto3
import json
import os

def get_cmk():
    client = boto3.client('kms')
    keys = client.list_keys()['Keys']
    return [k['KeyArn'] for k in keys]

def gen_data_key(cmk_key_id):
    client = boto3.client('kms')
    res = client.generate_data_key(
        KeyId=cmk_key_id,
        KeySpec='AES_256'
    )
    return (res['Plaintext'], res['CiphertextBlob'])

def decrypt_data_key(encrypted_key_bytes):
    client = boto3.client('kms')
    res = client.decrypt(
        CiphertextBlob=encrypted_key_bytes
    )
    return res['Plaintext']


text:
sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF
sudo dnf -y install elasticsearch java-1.8.0-openjdk
sudo bash -c "echo 'network.host: 0.0.0.0' >> /etc/elasticsearch/elasticsearch.yml"
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo mkdir -p /etc/skydive
sudo tee /etc/skydive/skydive.yml << EOF
analyzer:
  listen: 0.0.0.0:8082
  flowtable_expire: 60
  flowtable_update: 5
  flowtable_agent_ratio: 0.5
  storage: elasticsearch
  topology:
    fabric:
      - TOR1[Name=tor1] -> TOR1_PORT1[Name=port1, MTU=1500]
      - TOR1[Name=tor1] -> TOR1_PORT2[Name=port2, MTU=1500]
      - TOR1_PORT1 -> *[Type=host,Name=agent1]/eth1
      - TOR1_PORT2 -> *[Type=host,Name=agent2]/eth1
etcd:
  client_timeout: 100
graph:
  backend: elasticsearch
elasticsearch:
  addr: 127.0.0.1:9200
EOF
sudo curl -o /usr/lib/systemd/system/skydive-analyzer.service https://raw.githubusercontent.com/skydive-project/skydive/master/contrib/systemd/skydive-analyzer.service
sudo systemctl daemon-reload
sudo systemctl enable skydive-analyzer.service


text:
#region License

#endregion

using System.Threading.Tasks;

namespace ShipStation4Net.Clients.Interfaces
{
    internal interface IGets<T>
    {
        Task<T> GetAsync(int id);
    }
}


text:
package adapter

import (
	"entity"
	"testing"
)

func TestGetAllUsers(t *testing.T) {
	InitStorage()
	ClearAllUsers()

	users, err := GetAllUsers()
	if err != nil {
		t.Fatal("failed to get all users. ", err.Error())
	}

	if len(users) != 0 {
		t.Fatal("There should be no user initial")
	}

	if err = AddUser(&entity.User{
		Name:     "test",
		Password: "123456",
		HeadImg:  "/images/test.png",
	}); err != nil {
		t.Fatal("failed to add user.", err.Error())
	}

	users, err = GetAllUsers()
	if err != nil {
		t.Fatal("failed to get all user again.", err.Error())
	}

	if len(users) != 1 || users[0].Name != "test" || users[0].Password != "123456" || users[0].HeadImg != "/images/test.png" {
		t.Fatal("failed to get correct user.")
	}

	// ADD another user
	if err = AddUser(&entity.User{
		Name:     "test2",
		Password: "123457",
		HeadImg:  "/images/test2.png",
	}); err != nil {
		t.Fatal("failed to add user2.", err.Error())
	}

	users, err = GetAllUsers()
	if err != nil {
		t.Fatal("failed to get all user again .", err.Error())
	}

	if len(users) != 2 {
		t.Fatal("failed to get correct user.")
	}
}


text:
#ifndef _G2_H
#define _G2_H

/* g2 version */
#define G2_VERSION "0.70"

#if defined(__cplusplus)
extern "C"
{
#endif

/* Common Library header for DLL and application */
#ifdef WIN32
#ifdef G2DLL
#ifdef MAKEDLL
/* Create DLL */
#pragma message( "Building DLL library")
#define G2L __declspec( dllexport)
#else
/* Use DLL */
#define G2L __declspec( dllimport)
#endif
#else
/* Use static win32 */
#define G2L
#endif
#else
/* Use non-win32 */
#define G2L
#endif

#define G2LD g2_ld()

#if defined(SWIG)
#if defined(DO_X11)
%include "X11/g2_X11.h"
#endif
#if defined(DO_PS)
%include "PS/g2_PS.h"
#endif
#if defined(DO_GD)
%include "GD/g2_gd.h"
#endif
#if defined(DO_WIN32)
%include "WIN32/g2_win32.h"
#endif

%module g2

%include typemaps.i

%{
#include "g2.h"
#if defined(DO_X11)
#include "g2_X11.h"
#endif
#if defined(DO_PS)
#include "g2_PS.h"
#endif
#if defined(DO_GD)
#include "g2_gd.h"
#endif
#if defined(DO_WIN32)
#include "WIN32/g2_win32.h"
#endif
%}

#endif
/* end SWIG */

enum QPshape {
    QPrect, /**< rectangular quasi pixel */
    QPcirc  /**< circle as a quasi pixel */
};

/* compatibility with old versions */
#define g2_draw_string(dev, x, y, text) g2_string((dev), (x), (y), (text))

G2L int  g2_open_vd(void);
G2L void g2_attach(int vd_dev, int dev);
G2L void g2_detach(int vd_dev, int dev);

G2L void g2_close(int dev);
G2L void g2_set_auto_flush(int dev, int on_off);
G2L void g2_flush(int dev);
G2L void g2_save(int dev);
G2L void g2_set_coordinate_system(int dev, double x_origin, double y_origin,
			      double x_mul,    double y_mul);

G2L int  g2_ld();
G2L void g2_set_ld(int dev);

G2L int  g2_ink(int pd_dev, double red, double green, double blue);
G2L void g2_pen(int dev, int color);
G2L void g2_set_dash(int dev, int N, double *dashes);
G2L void g2_set_font_size(int dev, double size);
G2L void g2_set_line_width(int dev, double w);
G2L void g2_clear_palette(int dev);
G2L void g2_reset_palette(int dev);
G2L void g2_allocate_basic_colors(int dev);

G2L void g2_clear(int dev);
G2L void g2_set_background(int dev, int color);

G2L void g2_move(int dev, double x, double y);
G2L void g2_move_r(int dev, double dx, double dy);

G2L void g2_plot(int dev, double x, double y);
G2L void g2_plot_r(int dev, double dx, double dy);
G2L void g2_line(int dev, double x1, double y1, double x2, double y2);
G2L void g2_line_r(int dev, double dx, double dy);
G2L void g2_line_to(int dev, double x, double y);
G2L void g2_poly_line(int dev, int N_pt, double *points);
G2L void g2_triangle(int dev, double x1, double y1,
		 double x2, double y2,
		 double x3, double y3);
G2L void g2_filled_triangle(int dev, double x1, double y1,
			double x2, double y2,
			double x3, double y3);
G2L void g2_rectangle(int dev, double x1, double y1, double x2, double y2);
G2L void g2_filled_rectangle(int dev,
			     double x1, double y1, double x2, double y2);
G2L void g2_polygon(int dev, int N_pt, double *points);
G2L void g2_filled_polygon(int dev, int N_pt, double *points);
G2L void g2_circle(int dev, double x, double y, double r);
G2L void g2_filled_circle(int dev, double x, double y, double r);
G2L void g2_ellipse(int dev, double x, double y, double r1, double r2);
G2L void g2_filled_ellipse(int dev, double x, double y, double r1, double r2);
G2L void g2_arc(int dev,
	    double x, double y,
	    double r1, double r2,
	    double a1, double a2);
G2L void g2_filled_arc(int dev, double x, double y,
		   double r1, double r2,
		   double a1, double a2);
G2L void g2_string(int dev, double x, double y, const char *text);
G2L void g2_image(int dev,
		  double x, double y, int x_size, int y_size, int *pens);

G2L void g2_set_QP(int dev, double d, enum QPshape shape);
G2L void g2_plot_QP(int dev, double x, double y);
#if !defined(SWIG)
G2L void g2_query_pointer(int dev, double *x, double *y, unsigned int *button);
#else
extern void g2_query_pointer(int dev, double *OUTPUT,double *OUTPUT,unsigned int *OUTPUT);
#endif

 /* Tijs Michels */
 /* 06/16/99	 */

G2L void g2_spline(int id, int n, double *points, int o);
G2L void g2_b_spline(int id, int n, double *points, int o);
G2L void g2_raspln(int id, int n, double *points, double tn);
G2L void g2_para_3(int id, int n, double *points);
G2L void g2_para_5(int id, int n, double *points);
G2L void g2_filled_spline(int id, int n, double *points, int o);
G2L void g2_filled_b_spline(int id, int n, double *points, int o);
G2L void g2_filled_raspln(int id, int n, double *points, double tn);
G2L void g2_filled_para_3(int id, int n, double *points);
G2L void g2_filled_para_5(int id, int n, double *points);

/** Actualy private function, but... **/
G2L int g2_device_exist(int dix);

/** Use only if you know what are you doing **/
#define G2_PD_HANDLES_SIZE 32
G2L void g2_get_pd_handles(int pd, void *handles[G2_PD_HANDLES_SIZE]);

#if defined(__cplusplus)
} /* end extern "C" */
#endif

#endif /* _G2_H */


text:
require "ruby_on_run/version"

module RubyOnRun

  BASE_LIB_PATH = File.expand_path("..", __FILE__)

   # Load all constants.
  Dir["#{BASE_LIB_PATH}/ruby_on_run/*.rb"].sort.each do |f|
    require "ruby_on_run/#{File.basename(f, '.rb')}"
  end

  Dir["#{BASE_LIB_PATH}/ruby_on_run/vm/*.rb"].sort.each do |f|
    require "ruby_on_run/vm/#{File.basename(f, '.rb')}"
  end

  # compiling in future
  Dir["#{BASE_LIB_PATH}/ruby_on_run/builtin/*.rb"].sort.each do |f|
    require "ruby_on_run/builtin/#{File.basename(f, '.rb')}"
  end

  # just for now
  # in final version injecting file th params from CLI

#  stream = File.open('spec/bytecode_samples/if_statement.bytecode').read
end


text:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.07.02 at 03:35:23 PM MSK
//

package ru.gov.zakupki.oos.types._1;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

/**
 * Ссылка на справочник "Коды видов расходов" (КВР)
 *
 *
Java class for zfcs_KVRRef complex type.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *
 *

 * <complexType name="zfcs_KVRRef">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="code" type="{http://zakupki.gov.ru/oos/types/1}zfcs_KVRCodeType"/>
 *         <element name="name" type="{http://zakupki.gov.ru/oos/types/1}zfcs_longTextMinType" minOccurs="0"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "zfcs_KVRRef", propOrder = {
    "code",
    "name"
})
public class ZfcsKVRRef {

    @XmlElement(required = true)
    protected String code;
    protected String name;

    /**
     * Gets the value of the code property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getCode() {
        return code;
    }

    /**
     * Sets the value of the code property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setCode(String value) {
        this.code = value;
    }

    /**
     * Gets the value of the name property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the value of the name property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setName(String value) {
        this.name = value;
    }

}