text:
package com.cloudera.oryx.app.serving.als.model;

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.typesafe.config.Config;
import org.apache.hadoop.conf.Configuration;
import org.dmg.pmml.PMML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cloudera.oryx.api.KeyMessage;
import com.cloudera.oryx.api.serving.ServingModelManager;
import com.cloudera.oryx.app.als.AbstractRescorerProvider;
import com.cloudera.oryx.app.als.RescorerProvider;
import com.cloudera.oryx.app.pmml.AppPMMLUtils;
import com.cloudera.oryx.common.settings.ConfigUtils;

/**
 * A {@link ServingModelManager} that manages and provides access to an {@link ALSServingModel}
 * for the ALS Serving Layer application.
 */
public final class ALSServingModelManager implements ServingModelManager<String> {

  private static final Logger log = LoggerFactory.getLogger(ALSServingModelManager.class);
  private static final ObjectMapper MAPPER = new ObjectMapper();

  private ALSServingModel model;
  private final double sampleRate;
  private final RescorerProvider rescorerProvider;

  public ALSServingModelManager(Config config) {
    String rescorerProviderClass =
        ConfigUtils.getOptionalString(config, "oryx.als.rescorer-provider-class");
    rescorerProvider = AbstractRescorerProvider.loadRescorerProviders(rescorerProviderClass);
    sampleRate = config.getDouble("oryx.als.sample-rate");
    Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0);
  }

  @Override
  public void consume(Iterator<KeyMessage<String,String>> updateIterator, Configuration hadoopConf)
      throws IOException {
    while (updateIterator.hasNext()) {
      KeyMessage<String,String> km = updateIterator.next();
      String key = km.getKey();
      String message = km.getMessage();
      Objects.requireNonNull(key, "Bad message: " + km);
      switch (key) {
        case "UP":
          if (model == null) {
            continue; // No model to interpret with yet, so skip it
          }
          List<?> update = MAPPER.readValue(message, List.class);
          // Update
          String id = update.get(1).toString();
          float[] vector = MAPPER.convertValue(update.get(2), float[].class);
          switch (update.get(0).toString()) {
            case "X":
              model.setUserVector(id, vector);
              if (update.size() > 3) {
                @SuppressWarnings("unchecked")
                Collection<String> knownItems = (Collection<String>) update.get(3);
                model.addKnownItems(id, knownItems);
              }
              break;
            case "Y":
              model.setItemVector(id, vector);
              // Right now, no equivalent knownUsers
              break;
            default:
              throw new IllegalArgumentException("Bad message: " + km);
          }
          break;

        case "MODEL":
        case "MODEL-REF":
          log.info("Loading new model");
          PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf);

          int features = Integer.parseInt(AppPMMLUtils.getExtensionValue(pmml, "features"));
          boolean implicit = Boolean.valueOf(AppPMMLUtils.getExtensionValue(pmml, "implicit"));
          if (model == null) {

            log.info("No previous model; creating new model");
            model = new ALSServingModel(features, implicit, sampleRate, rescorerProvider);

          } else if (features != model.getFeatures()) {

            log.warn("# features has changed! removing old model and creating new one");
            model = new ALSServingModel(features, implicit, sampleRate, rescorerProvider);

          } else {

            log.info("Updating current model");
            // Remove users/items no longer in the model
            Collection<String> XIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "XIDs"));
            Collection<String> YIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "YIDs"));
            model.pruneKnownItems(XIDs, YIDs);
            model.pruneX(XIDs);
            model.pruneY(YIDs);

          }

          log.info("New model: {}", model);
          break;

        default:
          throw new IllegalArgumentException("Bad message: " + km);
      }
    }
  }

  @Override
  public ALSServingModel getModel() {
    return model;
  }

  @Override
  public void close() {
    // do nothing
  }

}


text:
/**
 *
 */
package edu.washington.escience.myria.perfenforce;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.slf4j.LoggerFactory;

import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.google.gson.Gson;

import edu.washington.escience.myria.api.encoding.PerfEnforceQueryMetadataEncoding;
import edu.washington.escience.myria.api.encoding.PerfEnforceTableEncoding;
import edu.washington.escience.myria.parallel.Server;

/**
 * The PerfEnforce Driver
 *
 */
public final class PerfEnforceDriver {

  protected static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(PerfEnforceDriver.class);

  /** The cluster sizes PerfEnforce considers. */
  final public static List<Integer> configurations = Arrays.asList(4, 6, 8, 10, 12);

  /** The configuration path storing PerfEnforce helper files. */
  public static Path configurationPath;

  /** The list of relations from the user. */
  public static List<PerfEnforceTableEncoding> tableList;
  /** Metadata about the fact table. */
  public static PerfEnforceTableEncoding factTableDesc;

  private final Server server;
  private String dataPreparationStatus;
  private boolean isDonePSLA;

  private PerfEnforceOnlineLearning perfenforceOnlineLearning;

  /**
   * Constructor for the PerfEnforceDriver
   *
   * @param server the instance of the server
   * @param instancePath the path for the Myria deployment
   */
  public PerfEnforceDriver(final Server server, final String instancePath) {
    configurationPath = (Paths.get(instancePath, "perfenforce_files"));
    this.server = server;
    dataPreparationStatus = "";
    isDonePSLA = false;
  }

  /**
   * Fetch necessary files from S3
   * @throws PerfEnforceException throws an exception if there is an error fetching files from S3
   */
  public void fetchS3Files() throws PerfEnforceException {
    AmazonS3 s3Client = new AmazonS3Client(new AnonymousAWSCredentials());
    String currentFile = "";

    try {
      try (BufferedReader bufferedReader =
              new BufferedReader(
                  new FileReader(configurationPath.resolve("filesToFetch.txt").toString()))) {
        while ((currentFile = bufferedReader.readLine()) != null) {
          Path filePath = configurationPath.resolve(currentFile);
          s3Client.getObject(
              new GetObjectRequest("perfenforce", currentFile), new File(filePath.toString()));
        }
      }
    } catch (Exception e) {
      throw new PerfEnforceException("Error while fetching files from S3");
    }
  }

  /**
   * Prepares the PSLA given a list of tables
   *
   * @param tableList the tables from the user's dataset
   */
  public void preparePSLA(List<PerfEnforceTableEncoding> tableList) throws Exception {
    isDonePSLA = false;
    PerfEnforceDriver.tableList = tableList;
    fetchS3Files();

    PerfEnforceDataPreparation perfenforceDataPrepare = new PerfEnforceDataPreparation(server);

    dataPreparationStatus = "Ingesting Data";
    for (PerfEnforceTableEncoding currentTable : tableList) {
      if (currentTable.type.equalsIgnoreCase("fact")) {
        perfenforceDataPrepare.ingestFact(currentTable);
        factTableDesc = currentTable;
      } else {
        perfenforceDataPrepare.ingestDimension(currentTable);
      }
      dataPreparationStatus = "Analyzing Data";
      perfenforceDataPrepare.analyzeTable(currentTable);
    }

    dataPreparationStatus = "Collecting Statistics";
    perfenforceDataPrepare.collectSelectivities();

    Gson gson = new Gson();
    String schemaDefinitionFile = gson.toJson(tableList);
    try (PrintWriter out =
            new PrintWriter(
                configurationPath
                    .resolve("PSLAGeneration")
                    .resolve("SchemaDefinition.json")
                    .toString())) {
      out.print(schemaDefinitionFile);
    }

    dataPreparationStatus = "Generating Queries for PSLA";
    PSLAManagerWrapper pslaManager = new PSLAManagerWrapper();
    pslaManager.generateQueries();
    perfenforceDataPrepare.collectFeaturesFromGeneratedQueries();
    pslaManager.generatePSLA();

    dataPreparationStatus = "Finished";
    isDonePSLA = true;
  }

  /**
   * Returns the status of the PSLA generation process
   * @return the data preparation status
   */
  public String getDataPreparationStatus() {
    return dataPreparationStatus;
  }

  /**
   * Return a boolean to determine whether the PSLA is finished generating
   * @return a boolean determining whether the PSLA is finished
   */
  public boolean isDonePSLA() {
    return isDonePSLA;
  }

  /**
   * Returns the final PSLA
   * @return the generated PSLA
   * @throws PerfEnforceException if there is an error generating the PSLA
   */
  public String getPSLA() throws PerfEnforceException {
    StringWriter output = new StringWriter();
    try {
      Reader input =
          new FileReader(
              new File(
                  configurationPath
                      .resolve("PSLAGeneration")
                      .resolve("FinalPSLA.json")
                      .toString()));
      IOUtils.copy(input, output);
    } catch (IOException e) {
      throw new PerfEnforceException();
    }
    return output.toString();
  }

  /**
   * Sets the tier selected by the user
   *
   * @param tier the tier selected
   */
  public void setTier(final int tier) {
    perfenforceOnlineLearning = new PerfEnforceOnlineLearning(server, tier);
  }

  /**
   * Finds the SLA for a given query
   *
   * @param querySQL the given query
   * @throws PerfEnforceException if there is an error computing the SLA for a query
   */
  public void findSLA(String querySQL) throws PerfEnforceException {
    perfenforceOnlineLearning.findSLA(querySQL);
    perfenforceOnlineLearning.findBestConfigurationSize();
  }

  /**
   * Records the runtime of a query
   *
   * @param queryRuntime the runtime of a query
   * @throws PerfEnforceException throws an exception if
   */
  public void recordRealRuntime(final Double queryRuntime) throws PerfEnforceException {
    perfenforceOnlineLearning.recordRealRuntime(queryRuntime);
  }

  /**
   * Returns information about the current query, assuming the user recently requested the SLA
   * @return metadata about the current query
   */
  public PerfEnforceQueryMetadataEncoding getCurrentQuery() {
    return perfenforceOnlineLearning.getCurrentQuery();
  }

  /**
   * Returns the current cluster size
   * @return the current cluster size
   */
  public int getClusterSize() {
    return perfenforceOnlineLearning.getClusterSize();
  }
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.struts.taglib.html;

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;

import org.apache.struts.taglib.TagUtils;
import org.apache.struts.taglib.logic.IterateTag;
import org.apache.struts.util.MessageResources;

/**
 * Generate a URL-encoded hyperlink to the specified URI.
 *
 * @version $Rev: 164530 $ $Date: 2005-04-25 12:11:07 +0900 (月, 25  4月 2005) $
 */
public class LinkTag extends BaseHandlerTag {

    // ----------------------------------------------------- Instance Variables

    /**
     * The body content of this tag (if any).
     */
    protected String text = null;

    // ----------------------------------------------------- Constructor

    public LinkTag() {
        super();
        doDisabled = false;
    }

    // ------------------------------------------------------------- Properties

    /**
     * The anchor to be added to the end of the generated hyperlink.
     */
    protected String anchor = null;

    public String getAnchor() {
        return (this.anchor);
    }

    public void setAnchor(String anchor) {
        this.anchor = anchor;
    }

    /**
     *
The logical forward name from which to retrieve the hyperlink URI.

     *
Usage note: If a forward config is used in a hyperlink,
     * and a module is specified, the path must lead to another
     * action and not directly to a page. This is in keeping with
     * rule that in a modular application all links must be to
     * an action rather than a page.
     *

     */
    protected String forward = null;

    public String getForward() {
        return (this.forward);
    }

    public void setForward(String forward) {
        this.forward = forward;
    }

    /**
     * The hyperlink URI.
     */
    protected String href = null;

    public String getHref() {
        return (this.href);
    }

    public void setHref(String href) {
        this.href = href;
    }

    /**
     * The link name for named links.
     */
    protected String linkName = null;

    public String getLinkName() {
        return (this.linkName);
    }

    public void setLinkName(String linkName) {
        this.linkName = linkName;
    }

    /**
     * The message resources for this package.
     */
    protected static MessageResources messages =
     MessageResources.getMessageResources(Constants.Package + ".LocalStrings");

    /**
     * The JSP bean name for query parameters.
     */
    protected String name = null;

    public String getName() {
        return (this.name);
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * The module-relative page URL (beginning with a slash) to which
     * this hyperlink will be rendered.
     */
    protected String page = null;

    public String getPage() {
        return (this.page);
    }

    public void setPage(String page) {
        this.page = page;
    }

	/**
	 * The module-relative action (beginning with a slash) which will be
	 * called by this link
	 */
	protected String action = null;

	public String getAction() {
		return (this.action);
	}

	public void setAction(String action) {
		this.action = action;
	}

	/**
	 * The module prefix (beginning with a slash) which will be
	 * used to find the action for this link.
	 */
	protected String module = null;

	public String getModule() {
		return (this.module);
	}

	public void setModule(String module) {
		this.module = module;
	}

    /**
      * The single-parameter request parameter name to generate.
      */
     protected String paramId = null;

    public String getParamId() {
        return (this.paramId);
    }

    public void setParamId(String paramId) {
        this.paramId = paramId;
    }

    /**
     * The single-parameter JSP bean name.
     */
    protected String paramName = null;

    public String getParamName() {
        return (this.paramName);
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    /**
     * The single-parameter JSP bean property.
     */
    protected String paramProperty = null;

    public String getParamProperty() {
        return (this.paramProperty);
    }

    public void setParamProperty(String paramProperty) {
        this.paramProperty = paramProperty;
    }

    /**
     * The single-parameter JSP bean scope.
     */
    protected String paramScope = null;

    public String getParamScope() {
        return (this.paramScope);
    }

    public void setParamScope(String paramScope) {
        this.paramScope = paramScope;
    }

    /**
     * The JSP bean property name for query parameters.
     */
    protected String property = null;

    public String getProperty() {
        return (this.property);
    }

    public void setProperty(String property) {
        this.property = property;
    }

    /**
     * The scope of the bean specified by the name property, if any.
     */
    protected String scope = null;

    public String getScope() {
        return (this.scope);
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    /**
     * The window target.
     */
    protected String target = null;

    public String getTarget() {
        return (this.target);
    }

    public void setTarget(String target) {
        this.target = target;
    }

    /**
     * Include transaction token (if any) in the hyperlink?
     */
    protected boolean transaction = false;

    public boolean getTransaction() {
        return (this.transaction);
    }

    public void setTransaction(boolean transaction) {
        this.transaction = transaction;
    }

    /**
     * Name of parameter to generate to hold index number
     */
    protected String indexId = null;

    public String getIndexId() {
       return (this.indexId);
    }

    public void setIndexId(String indexId) {
        this.indexId = indexId;
    }

	protected boolean useLocalEncoding = false;

	public boolean isUseLocalEncoding() {
	   return useLocalEncoding;
	}

	public void setUseLocalEncoding(boolean b) {
	   useLocalEncoding = b;
	}

    // --------------------------------------------------------- Public Methods

    /**
     * Render the beginning of the hyperlink.
     *

     * Support for indexed property since Struts 1.1
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {

        // Generate the opening anchor element
        StringBuffer results = new StringBuffer("<a");

        // Special case for name anchors
        prepareAttribute(results, "name", getLinkName());

        // * @since Struts 1.1
        if (getLinkName() == null || getForward() != null  || getHref() != null ||
            getPage() != null || getAction() != null) {
            prepareAttribute(results, "href", calculateURL());
        }
        prepareAttribute(results, "target", getTarget());
        prepareAttribute(results, "accesskey", getAccesskey());
        prepareAttribute(results, "tabindex", getTabindex());
        results.append(prepareStyles());
        results.append(prepareEventHandlers());
        prepareOtherAttributes(results);
        results.append(">");

        TagUtils.getInstance().write(pageContext, results.toString());

        // Evaluate the body of this tag
        this.text = null;
        return (EVAL_BODY_TAG);

    }

    /**
     * Save the associated label from the body content.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doAfterBody() throws JspException {

        if (bodyContent != null) {
            String value = bodyContent.getString().trim();
            if (value.length() > 0)
                text = value;
        }
        return (SKIP_BODY);

    }

    /**
     * Render the end of the hyperlink.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doEndTag() throws JspException {

        // Prepare the textual content and ending element of this hyperlink
        StringBuffer results = new StringBuffer();
        if (text != null) {
            results.append(text);
        }
        results.append("");

        TagUtils.getInstance().write(pageContext, results.toString());

        return (EVAL_PAGE);

    }

    /**
     * Release any acquired resources.
     */
    public void release() {

        super.release();
        anchor = null;
        forward = null;
        href = null;
        linkName = null;
        name = null;
        page = null;
        action = null;
        module = null;
        paramId = null;
        paramName = null;
        paramProperty = null;
        paramScope = null;
        property = null;
        scope = null;
        target = null;
        text = null;
        transaction = false;
        indexId = null;
        useLocalEncoding = false;

    }

    // ------------------------------------------------------ Protected Methods

    /**
     * Return the complete URL to which this hyperlink will direct the user.
     * Support for indexed property since Struts 1.1
     *
     * @exception JspException if an exception is thrown calculating the value
     */
    protected String calculateURL() throws JspException {

        // Identify the parameters we will add to the completed URL
        Map params = TagUtils.getInstance().computeParameters
            (pageContext, paramId, paramName, paramProperty, paramScope,
             name, property, scope, transaction);

        // if "indexed=true", add "index=x" parameter to query string
        // * @since Struts 1.1
        if( indexed ) {

           int indexValue = getIndexValue();

           //calculate index, and add as a parameter
           if (params == null) {
               params = new HashMap();             //create new HashMap if no other params
           }
           if (indexId != null) {
              params.put(indexId, Integer.toString(indexValue));
           } else {
              params.put("index", Integer.toString(indexValue));
           }
        }

        String url = null;
        try {
            url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href,
                                          page, action, module, params, anchor, false, useLocalEncoding);
        } catch (MalformedURLException e) {
            TagUtils.getInstance().saveException(pageContext, e);
            throw new JspException
                (messages.getMessage("rewrite.url", e.toString()));
        }
        return (url);

    }

}


text:
require 'chefspec'

describe 'chef_gem::install' do
  let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }

  it 'installs a chef_gem with the default action' do
    expect(chef_run).to install_chef_gem('default_action')
    expect(chef_run).to_not install_chef_gem('not_default_action')
  end

  it 'installs a chef_gem with an explicit action' do
    expect(chef_run).to install_chef_gem('explicit_action')
  end

  it 'installs a chef_gem with attributes' do
    expect(chef_run).to install_chef_gem('with_attributes').with(version: '1.0.0')
    expect(chef_run).to_not install_chef_gem('with_attributes').with(version: '1.2.3')
  end

  it 'installs a chef_gem when specifying the identity attribute' do
    expect(chef_run).to install_chef_gem('identity_attribute')
  end
end


text:
<?php

namespace Brainbox\Dom;
use \LogicException,
	\InvalidArgumentException,
	\DOMDocument as DOMDocument_PHP;

/**
 * This class provides better implementation of the DOMDocument PHP class.
 *
 * @property DocumentFlavour $flavour
 * @property string $innerHTML Gets or sets the element's contents.
 */
class DOMDocument extends DOMDocument_PHP {

	/**
	 * Creates a new DOMDocument object
	 *
	 * @param string $version The version number of the document as part of the XML declaration.
	 * @param string $encoding The encoding of the document as part of the XML declaration.
	 */
	public function __construct($version = null, $encoding = null) {
		parent::__construct($version, $encoding);

		foreach($this->_getRedefinedNodeClasses() as $baseclass => $extendedclass) {
			$this->registerNodeClass($baseclass, $extendedclass);
		}

	}

	/**
	 * Returns creates DOM element.
	 *
	 * There are two types of call:
	 * 1) createElement($name, $value) – old type
	 * 2) createElement($name, $attributes[], $children[]) – new type {@see NodeUtils::createElement()}.
	 *
	 * @param string $name The tag name.
	 * @param string|string[] $value_or_attributes Either the element's value or its attributes
	 * @param array $children Array of element's children.
	 * @return DOMElement Newly created DOM element.
	 * @throws InvalidArgumentException When $value_or_attributes is non-array value and $children is array (mixed type of call)
	 */
	public function createElement($name, $value_or_attributes = null, array $children = array()) {
		if (is_array($value_or_attributes)) {
			return NodeUtils::createElement($this, $name, $value_or_attributes, $children);
		} else {
			if ($value_or_attributes && $children) {
				throw new InvalidArgumentException('Cannot set element's value in $value_or_attributes and $children at once.');
			}
			return parent::createElement($name, $value_or_attributes);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public function loadHTML($source) {
		return parent::loadHTML($source);
	}

	public function loadHTMLFile($filename) {

	}

	public function load($filename, $options = null) {

	}

	public function loadXML($source, $options = null) {

	}

	public function xloadHTML($source, $content_type = null) {
		$old_errors = libxml_use_internal_errors(true);

		// Funkce loadHTML neumí převzít kódování nijak jinak, než z hlavičky <meta http-equiv="Content-Type">
		// proto jí nastavíme v HTML souboru
		// viz. http://latrine.dgx.cz/php-dom-interni-poznamky
		// META tag dáme na konec tagu HEAD, protože pokud by existovala nějaká META s content typem
		// v hlavičce, DOMDocument při parsování bere tu první.
		if ($content_type) {
			if (preg_match('@<head@i', $source)) {
				$source = preg_replace('@<head[^>]*+>@i', '\0<meta http-equiv="Content-Type" content="' . htmlspecialchars($content_type) . '" />', $source);
			} else {
				$source = '<meta http-equiv="Content-Type" content="' . htmlspecialchars($content_type) . '" />' . $source;
			}
		}

		if ($content_type) {
			$charset = http_get_charset($content_type);
			$this->encoding = $charset;
		}

		$status = parent::loadHTML($source);

		$errors = libxml_get_errors();
		libxml_clear_errors();

		if ($errors) {
			$error_message = 'Following errors found while parsing HTML document:';
			/** @var $error \libXMLError */
			foreach ($errors as $error) {
				switch ($error->level) {
					case LIBXML_ERR_WARNING:
						$error_message .= "\r\n" . 'warning';
						break;
					case LIBXML_ERR_ERROR:
						$error_message .= "\r\n" . 'error';
						break;
					case LIBXML_ERR_FATAL:
						$error_message .= "\r\n" . 'fatal error';
						break;
					default:
						throw new DOMException('Unknown type of libXml error level [' . $error->level . ']');
						break;
				}
				$error_message .= ' ' . $error->code . ': ' . trim($error->message) . ' on line ' . $error->line . '';
			}
			throw new DOMException($error_message);

			libxml_use_internal_errors($old_errors);

			return $status;
		}
	}

	public function saveHTML() {
		$html = parent::saveHTML();
		return $this->_fixDOMSavedHtml($html);
	}

	/**
	 * Converts HTML entities (includes dangerous) in HTML from
	 * {@link DOMDocument->saveHTML()} to UTF-8 characters..
	 *
	 * @param string $html_text HTML code
	 * @return string HTML code with UTF-8 characters and without HTML entities
	 */
	private function _fixDOMSavedHtml($html_text) {
		// Replace all entities by callback
		$html_text = preg_replace_callback('/&[^;]+;/', function($matches) {
			// Create decoding table
			static $decode_table = null, $wanted_entities = null;
			if ($decode_table === null) {
				// PHP does not know all special entities so tell it about them
				$decode_table = array(
					'š' => 'š', 'Š' => 'Š', '€' => '€', '‰' => '‰', '…' => '…',
					'•' => '•', '–' => '–', '—' => '—', '„' => '"', '“' => '"',
					'’' => ''', '”' => '"',
				);
				$table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
				foreach ($table as $k => $v) {
					$k = iconv('ISO-8859-1', 'UTF-8', $k);
					$decode_table[$v] = $k;
				}

				// Some entities does not need to be convert to UTF-8…
				$wanted_entities = array_flip(array(' ', '<', '>', '&', '"', '''));
				// …so remove them
				$decode_table = array_diff_key($decode_table, $wanted_entities);
			}

			// Entity can has a lot of formats:
			// € // hexadecimal unicode
			// € // unicode value
			// < // entity name

			$entity = $matches[0];

			if (0 == substr_compare($entity, '#', 1, 1)) {
				// It is number entity. Hexadecimal or decimal. It does not matter because this works well :-)
				return html_entity_decode($entity, ENT_QUOTES, 'UTF-8');
			} elseif (array_key_exists($entity, $decode_table)) {
				// This is entity which is decoded
				return $decode_table[$entity];
			} elseif (array_key_exists($entity, $wanted_entities)) {
				// This is entity which stay
				return $entity;
			} else {
				// This is unknown entity. Try it recode throuth mb_*
				$new_entity = mb_convert_encoding($entity, 'utf-8', 'html-entities');
				if ($new_entity && $new_entity != $entity) {
					$decode_table[$entity] = $new_entity;
					$entity = $new_entity;
				} else {
					throw new DOMException('Unknown entity [' . $entity . '].');
				}
				return $entity;
			}
		}, $html_text);

		// For not-paired tags add ending slash
		$html_text = preg_replace('%<(' . implode('|', $this->_getUnpairElements()) . ')([^>]*)(?<!/)>%', '<\1\2 />', $html_text);

		return trim($html_text);
	}

	/**
	 * Returns set of unpair HTML tags in lower case.
	 *
	 * @return string[]
	 */
	private function _getUnpairElements() {
		return array('hr', 'br', 'img', 'input');
	}

	/**
	 * Returns set of block HTML tags in lower case.
	 *
	 * @return string[]
	 */
	private function _getBlockElements() {
		return array('div', 'li', 'ul', 'ol', 'p', 'form', 'dl', 'table',);
	}

	/**
	 * Returns first element which matches given CSS selector.
	 *
	 * @param $selector string CSS selector.
	 * @return DOMElement|null Found element or null.
	 */
	public function querySelector($selector) {
		throw new \LogicException('Not implemented yet!');
	}

	/**
	 * Returns all elements which match given CSS selector.
	 *
	 * @param $selector string CSS selector.
	 * @return DOMElement[] Found element or empty array.
	 */
	public function querySelectorAll($selector) {
		throw new \LogicException('Not implemented yet!');
	}

	/**
	 * Returns first result of the XPath query.
	 *
	 * For the XPath query, this node is set as the root.
	 *
	 * @param $xpath string XPath query.
	 * @return DOMElement|mixed Result of the XPath query or null when nothing found.
	 */
	public function queryXpath($xpath) {
		$result = NodeUtils::evalXpath($xpath, $this);
		return count($result)
			? $result[0]
			: null;
	}

	/**
	 * Returns results of the XPath query.
	 *
	 * For the XPath query, this node is set as the root.
	 *
	 * @param $xpath string XPath query.
	 * @return DOMNodeList|mixed[] Result of the XPath query or empty array when nothing found.
	 */
	public function queryXpathAll($xpath) {
		$result = NodeUtils::evalXpath($xpath, $this);
		return new DOMNodeList($result);
	}

	protected function _getRedefinedNodeClasses() {
		return array(
			'DOMElement' => __NAMESPACE__.'\\DOMElement',
		);
	}

	public function __get($name) {
		switch($name) {
			case 'innerHTML':
				return NodeUtils::getInnerHtml($this);
			default:
				throw new LogicException("Cannot get undefined property '".get_class($this)."->".$name."'!");
		}
	}

	public function __set($name, $value) {
		switch($name) {
			case 'innerHTML':
				NodeUtils::setInnerHtml($this, $value);
				return;
			default:
				throw new LogicException("Cannot set undefined property '".get_class($this)."->".$name."'!");
		}
	}

}


text:
package io.fabric8.spi;

import java.io.InputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;

import org.jboss.gravia.resource.DefaultResourceBuilder;
import org.jboss.gravia.resource.ResourceBuilder;

/**
 * Read repository content from XML.
 *
 * @author thomas.diesler@jboss.com
 * @since 11-Jun-2014
 */
public class DefaultProfileXMLReader extends AbstractProfileXMLReader {

    public DefaultProfileXMLReader(InputStream inputStream) {
        super(inputStream);
    }

    @Override
    protected XMLStreamReader createXMLStreamReader(InputStream inputStream) {
        try {
            return XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot initialize repository reader", ex);
        }
    }

    @Override
    protected ResourceBuilder createResourceBuilder() {
        return new DefaultResourceBuilder();
    }
}


text:
#ifndef Scene_h
#define Scene_h

#include <memory>
#include <vector>
#include "mog/base/Drawable.h"
#include "mog/base/DrawableGroup.h"
#include "mog/core/PubSub.h"

namespace mog {
    class AppBase;
    class Engine;

    class Scene : public std::enable_shared_from_this<Scene> {
        friend class AppBase;
    public:
        virtual void updateFrame(const std::shared_ptr<Engine> &engine, float delta, unsigned char parentDirtyFlag);
        virtual void drawFrame(float delta, const std::map<unsigned int, TouchInput> &touches);
        void add(const std::shared_ptr<Drawable> &drawable);
        void insertBefore(const std::shared_ptr<Drawable> &drawable, const std::shared_ptr<Drawable> &baseDrawable);
        void insertAfter(const std::shared_ptr<Drawable> &drawable, const std::shared_ptr<Drawable> &baseDrawable);
        void remove(const std::shared_ptr<Drawable> &drawable);
        void removeAll();
        std::shared_ptr<AppBase> getApp();
        std::shared_ptr<PubSub> getPubSub();
        std::shared_ptr<DrawableGroup> getRootDrawableGroup();

    protected:
        Scene();
        void setApp(const std::shared_ptr<AppBase> &app);

        virtual void onLoad() {};
        virtual void onDispose() {};
        virtual void onEnable() {};
        virtual void onDisable() {};
        virtual void onUpdate(float delta) {};

        std::shared_ptr<DrawableGroup> rootGroup;
        std::shared_ptr<PubSub> pubsub;
        std::weak_ptr<AppBase> app;
        float matrix[20] = {
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1,
            1, 1, 1, 1,
        };
        unsigned char dirtyFlag = DIRTY_ALL;
        bool sortOrderDirty = false;
    };
}

#endif /* Scene_h */


text:
% Copyright 2020 Makani Technologies LLC
%
% 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.

function [y_bar, Pyy, Pxy] = ...
    unscented_transform(x, Pxx, alpha, beta, kappa, f, param)

% Compute sigma points.
nx = size(x,1);
lambda = alpha^2*(nx + kappa) - nx;
chi = unscented_sigma_points(x, Pxx, lambda);
n_sigma_pts = size(chi,2);

% Compute output mean.
w_mean = [lambda/(nx+lambda) 0.5/(nx+lambda)*ones(1, 2*nx)];
Y = f(chi(:,1), param);
ny = size(Y,1);
Y = [Y, zeros(ny, n_sigma_pts-1)];
y_bar = w_mean(1)*Y(:,1);
for i = 2:n_sigma_pts
  Y(:,i) = f(chi(:,i), param);
  y_bar = y_bar + w_mean(i)*Y(:,i);
end

% Compute output covariance.
w_cov = [lambda/(nx+lambda)+(1-alpha^2+beta) 0.5/(nx+lambda)*ones(1, 2*nx)];
Pyy = zeros(ny,ny);
Pxy = zeros(nx,ny);
for i = 1:n_sigma_pts
  dy = Y(:,i) - y_bar;
  dx = chi(:,i) - x;
  Pyy = Pyy + w_cov(i)*(dy*dy');
  Pxy = Pxy + w_cov(i)*(dx*dy');
end


text:
package org.apache.flink.runtime.io.network.partition.hybrid;

import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;

/** Mock {@link HsFileDataIndex} for testing. */
public class TestingFileDataIndex implements HsFileDataIndex {
    private final BiFunction<Integer, Integer, Optional<ReadableRegion>> getReadableRegionFunction;

    private final Consumer<List<SpilledBuffer>> addBuffersConsumer;

    private final BiConsumer<Integer, Integer> markBufferReadableConsumer;

    private TestingFileDataIndex(
            BiFunction<Integer, Integer, Optional<ReadableRegion>> getReadableRegionFunction,
            Consumer<List<SpilledBuffer>> addBuffersConsumer,
            BiConsumer<Integer, Integer> markBufferReadableConsumer) {
        this.getReadableRegionFunction = getReadableRegionFunction;
        this.addBuffersConsumer = addBuffersConsumer;
        this.markBufferReadableConsumer = markBufferReadableConsumer;
    }

    @Override
    public Optional<ReadableRegion> getReadableRegion(int subpartitionId, int bufferIndex) {
        return getReadableRegionFunction.apply(subpartitionId, bufferIndex);
    }

    @Override
    public void addBuffers(List<SpilledBuffer> spilledBuffers) {
        addBuffersConsumer.accept(spilledBuffers);
    }

    @Override
    public void markBufferReadable(int subpartitionId, int bufferIndex) {
        markBufferReadableConsumer.accept(subpartitionId, bufferIndex);
    }

    public static Builder builder() {
        return new Builder();
    }

    /** Builder for {@link TestingFileDataIndex}. */
    public static class Builder {
        private BiFunction<Integer, Integer, Optional<ReadableRegion>> getReadableRegionFunction =
                (ignore1, ignore2) -> Optional.empty();

        private Consumer<List<SpilledBuffer>> addBuffersConsumer = (ignore) -> {};

        private BiConsumer<Integer, Integer> markBufferReadableConsumer = (ignore1, ignore2) -> {};

        private Builder() {}

        public Builder setGetReadableRegionFunction(
                BiFunction<Integer, Integer, Optional<ReadableRegion>> getReadableRegionFunction) {
            this.getReadableRegionFunction = getReadableRegionFunction;
            return this;
        }

        public Builder setAddBuffersConsumer(Consumer<List<SpilledBuffer>> addBuffersConsumer) {
            this.addBuffersConsumer = addBuffersConsumer;
            return this;
        }

        public Builder setMarkBufferReadableConsumer(
                BiConsumer<Integer, Integer> markBufferReadableConsumer) {
            this.markBufferReadableConsumer = markBufferReadableConsumer;
            return this;
        }

        public TestingFileDataIndex build() {
            return new TestingFileDataIndex(
                    getReadableRegionFunction, addBuffersConsumer, markBufferReadableConsumer);
        }
    }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Drop Shadow Stack -->
    <!-- alpha 00 is for disabling shadow over popup -->
<!--    <item>-->
<!--        <shape>-->

<!--            <solid android:color="#00707070" />-->

<!--            <corners android:radius="@dimen/button_corner_radius" />-->
<!--        </shape>-->
<!--    </item>-->

    <item>
        <shape>
            <padding
                android:bottom="7dp"
                android:left="3dp"
                android:right="3dp"
                android:top="7dp" />
        </shape>
    </item>

    <item>
        <shape>
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="@color/buttonBorderColor" />

            <corners android:radius="@dimen/button_corner_radius" />
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape>
            <padding
                android:left="10dp"
                android:right="10dp"
                android:top="0dp"
                android:bottom="0dp" />

            <solid android:color="@color/buttonBackgroundColor" />

            <corners android:radius="@dimen/button_corner_radius" />
        </shape>
    </item>

</layer-list>


text:
'use strict';

angular.module('trackit.prediction')
  .directive('inspireTree', ['$q', '$parse', '$timeout', function($q, $parse, $timeout) {
    return {
      scope: {
        inspireTree: '&',
        selected: '=',
        selectedId: '='
      },
      link: function link(scope, element, attrs) {
        var tree = null;

        scope.$watch(attrs.selectedId, function(value) {
          if (tree) {
            var node = tree.node(value)
            if (node) {
              node.select();
            }
          }
        });

        buildTree();

        element.on('$destroy', destroyTree);

        function destroyTree() {
          tree = null;
        }

        function buildTree() {
          destroyTree();
          var selectedId = scope.selectedId;
          tree = new InspireTree({
            target: element[0],
            data: function(node, resolve, reject) {
              try {
                var promise = scope.inspireTree()(node);
              } catch(e) {
                console.error(e);
                return;
              }
              promise.then(function(res, err) {
                if (res || !err) {
                  resolve(res);
                  if (selectedId && tree) {
                    $timeout(function() {
                      tree.node(selectedId).select();
                      selectedId = null;
                    });
                  }
                } else {
                  reject(err);
                }
              });
            }
          });

          tree.on('node.selected', function(node) {
            scope.selected = node;
            scope.selectedId = node ? node.id : null;
            $timeout(function() {
              scope.$apply();
            });
          });
        }
      }
    };
  }])
  .controller('StorageTreeController', ['$uibModalInstance', '$scope', 'EstimationModel', '$cookies', 'selectedPath',
    function($uibModalInstance, $scope, EstimationModel, $cookies, selectedPath) {
        $scope.ok = function() {
            $uibModalInstance.dismiss();
        };

        $scope.selectedId = selectedPath;
        $scope.filterTag = '';
        $scope.tagKey = '';
        $scope.metadataLoaded = false;
        $scope.tags = [];
        $scope.tagKeys = [];

        $scope.$watch('selectedId', loadMetadata);
        $scope.$watch('filterTag', loadMetadata,true);
        $scope.$watch('tagKey', loadMetadata,true);

        var loaded = '';
        function loadMetadata() {
          var loaded_ = JSON.stringify([$scope.selectedId, $scope.filterTag, $scope.tagKey]);
          if (loaded == loaded_) { return; }
          loaded = loaded_;
          $scope.metadataLoaded = false;
          var args = {id: $cookies.getObject('awsKey'), path: $scope.selectedId};
          if ($scope.filterTag) {
            args.tag = $scope.filterTag;
          }
          if ($scope.tagKey) {
            args.tagkey = $scope.tagKey;
          }
          EstimationModel.getS3SpaceUsageTags(args).$promise.then(function(res) {
            $scope.tags = [''].concat(Object.keys(res.tags));
            $scope.tagKeys = [''].concat(res.keys);
            if ($scope.tagKey) {
              $scope.metadata = formatVals(res.tags, 12, $scope.tagKey + '=other');
              stripTagKey($scope.metadata, $scope.tagKey);
            } else {
              $scope.metadata = formatVals(res.tags, 10);
            }
            $scope.metadataLoaded = true;
          });
        }

        function formatVals(tags, limit, sumLabel) {
          console.log(arguments);
            var formatted = [];
            for (var tag in tags) {
              if (tags.hasOwnProperty(tag) && tags[tag]) {
                formatted.push({x: tag, y: tags[tag]});
              }
            }
            formatted.sort(function(a, b) { return b.y - a.y });
            if (limit) {
              if (sumLabel) {
                var rest = 0;
                for (var i=limit; i<formatted.length; i++) {
                  rest += formatted[i].y;
                }
                formatted = formatted.slice(0, limit - 1);
                if (rest) {
                  console.log(rest);
                  formatted.push({x: sumLabel, y: rest});
                }
              } else {
                formatted = formatted.slice(0, limit);
              }
            }
            return formatted;
        }

        function stripTagKey(axes, tagKey) {
          var prefixLen = tagKey.length + 1;
          for (var i=0; i<axes.length; i++) {
            axes[i].x = axes[i].x.slice(prefixLen);
          }
        }

        $scope.popularChartOpts = {
          chart: {
            type: 'discreteBarChart',
            height: 500,
            showValues: true,
            valueFormat: bytesAbbr,
            duration: 500,
            xAxis: {
              rotateLabels: 60
            },
            yAxis: {
              tickFormat: bytesAbbr
            },
            margin: {
              bottom: 200,
              right: 50
            }
          }
        };

        $scope.breakdownChartOpts = {
          chart: {
            type: 'pieChart',
            height: 500,
            donut: true,
            donutRatio: 0.45,
            showValues: true,
            showLabels: false,
            valueFormat: bytesAbbr,
            duration: 500
          }
        };

        $scope.getTreeData = function(node) {
          var args = {id: $cookies.getObject('awsKey')};
          var nodeId = node ? node.id : '';
          if (nodeId) {
            args.path = nodeId;
          }
          return EstimationModel.getS3SpaceUsageTree(args).$promise.then(function(res) {
            return map(res.dirs, function(size, name) {
              return {
                text: name + ' ' + bytesAbbr(size),
                id: nodeId ? nodeId + '/' + name : name,
                children: true,
                itree: {
                  icon: 'icon-folder'
                }
              };
            });
          });
        };

        function bytesAbbr(bytes) {
          var abbrs = ['B', 'KB', 'MB', 'GB', 'TB'];
          while (bytes / 1000 > 1 && abbrs.length > 1) {
            bytes = bytes / 1000;
            abbrs.shift();
          }
          return bytes.toFixed(2) + ' ' + abbrs[0];
        }

        function map(o, fn) {
          var acc = [];
          for (var key in o) {
            if (o.hasOwnProperty(key)) {
              acc.push(fn(o[key], key));
            }
          }
          return acc;
        }
    }]);


text:
__author__ = "Mohammad Dabiri"
__copyright__ = "Free to use, copy and modify"
__credits__ = ["Mohammad Dabiri"]
__license__ = "MIT Licence"
__version__ = "0.0.1"
__maintainer__ = "Mohammad Dabiri"
__email__ = "moddabiri@yahoo.com"

import os, sys, inspect, importlib

current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
mb_path = os.path.join(current_dir, '..')
sys.path.append(mb_path)
from MiniBatchSet import MiniBatchSet
import numpy as np

if not importlib.find_loader('tensorflow') is None:
    import tensorflow as tf
else:
    print("WARNING! Tensorflow is not installed on the vm.")

if not importlib.find_loader('sklearn') is None:
    from sklearn import linear_model
else:
    print("WARNING! sklearn is not installed on the vm.")

#*****!!NOTE!!    Sample configs, change these before running the sample
snapshot_path = os.path.join(current_dir, "test_data/minibatchset_ss.json")
train_folder = os.path.join(current_dir, "test_data/train/")
test_folder = os.path.join(current_dir, "test_data/test/")
output_path = os.path.join(current_dir, "test_data/output/")
even_path = os.path.join(current_dir, "test_data/even/")
number_of_iterations = 10
batch_size = 10
training_kit = 'tensorflow' #'sklearn' / 'none'

def weight_variable(shape):
      initial = tf.truncated_normal(shape, stddev=0.1, dtype=tf.float32)
      return tf.Variable(initial, dtype=tf.float32)

def bias_variable(shape):
    initial = tf.constant(0.1, shape=shape, dtype=tf.float32)
    return tf.Variable(initial, dtype=tf.float32)

#Scenario 1: Mini-batches kept on memory
#This method loads all the samples on the memory. Best if the sample can be fit on the memory.
def sample1():
    bs = MiniBatchSet(file_paths_or_folder=train_folder, batch_size=batch_size, hold_in_memory=True)
    bs.save_snapshot(snapshot_path)
    do_train(bs)

#TF - Scenario 2: Mini-batches read from the files in the runtime.
#This method keeps an index list of all the rows in the set on memory which requires more memory, but, it assures that all of the samples are visited once and only once in each round.
#It works best if you could allocate the required memory for the index list and assure completely normal distribution of the sample. Works well with medium size sets.
def sample2():
    bs = MiniBatchSet(file_paths_or_folder=train_folder, batch_size=batch_size)
    bs.save_snapshot(snapshot_path)
    do_train(bs)

#Scenario 3: Mini-batches read from the files with ad-hoc random sampling.
#This method is designed for the large sets. It will not store the index list to avoid memory overflow, but performs a normally distributed random sampling from the data. However, it will perform slowly in order to fetch the data from the disk in each batch request.
def sample3():
    bs = MiniBatchSet(file_paths_or_folder=train_folder, batch_size=batch_size)
    bs.save_snapshot(snapshot_path)
    do_train(bs)

#Scenario 4: Mini-batches read from the files with ad-hoc random sampling.
#This method is the optimized alternative for the 3rd scenario. It loads a bulk of mini-batches on the memory to avoid data I/O overhead. It fetches another batch if the loaded bulk goes lower than 50%.
def sample4():
    bs = MiniBatchSet(file_paths_or_folder=train_folder, batch_size=batch_size, bulk_size=10)
    bs.save_snapshot(snapshot_path)
    do_train(bs)

#Scenario 5: Restoring a snapshot.
def sample5():
    bs = MiniBatchSet(file_paths_or_folder=train_folder, batch_size=batch_size)
    bs.save_snapshot(snapshot_path)
    bs2 = MiniBatchSet.from_snapshot(snapshot_path)
    assert bs == bs2

#Scenario 6: Normalizing a data set.
def sample6():
    bs = MiniBatchSet(file_paths_or_folder=train_folder)
    bs.normalize(output_path, [0,1,2,3,4])

#Scenario 7: Performing custom actions on the data.
def sample7():
    bs = MiniBatchSet(file_paths_or_folder=train_folder)

    #----------------Step1: Get the maximum of all the features
    max_of_features = np.array([0.0] * 7,np.float64)

    #the first argument is reserved for data transformer to input the sample to the action
    #0 or more arguments could be used for running variables. Note that these variables must be returned as a list in order for the transform function to keep them running through the iterations
    def get_max_action(data, max_of_features):
            data = np.array(data, dtype=np.float64)
            max_of_features = np.maximum(max_of_features, data)

            #The running arguments must be returned to keep them running through the iterations
            return [max_of_features]

    #The output path is passed as None, it makes the transformer to not produce any output files and simply execute the action over the rows
    max_of_features = bs.transform_data(get_max_action, None, max_of_features)[0]

    #----------------Step2: Divide the features by their maximum values and write it to an output file
    max_of_features = np.array([1.0 if x == 0.0 else x for x in max_of_features], dtype=np.float32)
    def divide_by_max_action(data):
            data = np.array(data, dtype=np.float64)
            data = np.divide(data, max_of_features)
            return data, []

    #The output path is passed now, it will generate the transformed data in the destination
    bs.transform_data(divide_by_max_action, output_path)

#Scenario 8: Distribute the data amongst files with the same number of rows. This will help optimize the sampling process by avoiding too small files to waste the time or too large files to overflow the memory.
def sample8():
    bs = MiniBatchSet(file_paths_or_folder=train_folder)
    bs.even_files(100, even_path)

def do_train(bs):
    if training_kit == 'tensorflow':
        train_tf(bs)
    elif training_kit == 'sklearn':
        train_sk(bs)
    else:
        print("None of the known training kits were chosen. Skipping the training.")

#A simple nn with tensorflow
def train_tf(bs):
    sess = tf.InteractiveSession()
    x = tf.placeholder(tf.float32, shape=[None, 6])
    y_ = tf.placeholder(tf.float32, shape=[None, 1])

    W_layer1 = weight_variable([6, 64])
    b_layer1 = bias_variable([64])
    h_layer1 = tf.nn.softsign(tf.matmul(x, W_layer1) + b_layer1)

    W_readout = weight_variable([64, 1])
    b_readout = bias_variable([1])
    y_readout = tf.sigmoid(tf.matmul(h_layer1, W_readout) + b_readout)

    loss = tf.reduce_mean(tf.square(y_ - y_readout))
    train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)

    sess.run(tf.initialize_all_variables())

    for i in range(number_of_iterations):
        minibatch = np.matrix(next(bs))
        batch_x = np.asarray(minibatch[:,0:6])
        batch_y = np.asarray(minibatch[:,6])

        sess.run(train_step, feed_dict={x: batch_x, y_: batch_y})

#Basic linear regression with sklearn
def train_sk(bs):
    regr = linear_model.SGDRegressor()

    for i in range(number_of_iterations):
        minibatch = np.matrix(next(bs))
        batch_x = np.asarray(minibatch[:,0:6])
        batch_y = np.asarray(minibatch[:,6])
        regr.partial_fit(batch_x, batch_y)

if __name__ == '__main__':
    sample1()
    sample2()
    sample3()
    sample4()
    sample5()
    sample6()
    sample7()
    sample8()


text:
package org.gbougeard.model.changes

/**
 * Created with IntelliJ IDEA.
 * User: gbougeard
 * Date: 13/07/13
 * Time: 21:14
 * To change this template use File | Settings | File Templates.
 */
case class ReviewerInput(reviewer:String,
                          confirmed:Option[Boolean])

object ReviewerInput {

  import play.api.libs.json.Json
  import play.api.libs.functional.syntax._

  implicit val format = Json.format[ReviewerInput]
}


text:
lz4xx - A C++ Wrapper for LZ4 algorithm
=======================================

Tsz-Ho Yu (tszhoyu@gmail.com) @ 2015

# Introduction

This is an easy-to-use and independent data compression library based on the LZ4 algorithm. I started this project when I was working on another side project which needed lossless compression to big model files.

About LZ4 (From Wikipedia): LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes. The algorithm gives a slightly worse compression ratio than the LZO algorithm - which in turn is worse than algorithms like gzip. However, compression speeds are similar to LZO and several times faster than gzip while decompression speeds can be significantly faster than LZO.

It provides a more intuitive way to compress/decompress d, for example:

### Example 1: Compress a file to another file

    fd_in = fopen("input.data", "r");
    fd_out = fopen("compressed.data.lz4", "w");
    encoder.open(fd_in);
    encoder.encode(fd_out);
    encoder.close();
    fclose(fd_in);
    fclose(fd_out);

### Example 2: Compress a byte array (e.g. string, image, etc.)

    char input_msg[] = "This is a test string";
    char *compressed_msg = NULL;
    size_t compressed_size = 0;

    /* open output array, it is allocated automatically */
    encoder.open(&compressed_msg, &compressed_size);

    /* encoder the encode inputs separately */
    for (int i = 0; i < 10; i++)
    {
        encoder.encode(input_msg, strlen(input_msg));
    }
    encoder.close();

# Installation

The source package is supposed to be used as a library, or included directly in the source tree.

Demo programs can be compiled using CMAKE:

    $ mkdir debug
    $ cd debug
    $ cmake ..
    $ make

# Examples

The source code of two demo programs are included in the "example" folder.

* example1.cpp --- Compress a file, and decompress it again.
* example2.cpp --- Compress a text-message from a byte array, and decompress it again.

# TODO
* Operator overloading
* Support C++ fstreams?


text:
import React from "react";

import Input from "./input";
import Submit from "./submit";
import { required, email, RuleFn } from "react-validify/lib/rules";
import { Form } from "react-validify";

const greaterThanDate2: RuleFn = (value, values) => {
  if (!values.date2) return false;

  if (value.length < values.date2.length)
    return "Must be longer date than date 2";
};

type TestValues = {
  email: string;
  date1?: string;
  name?: string;
};

const App = () => {
  let [values, setValues] = React.useState<TestValues>({ email: "test" });

  return (
    <Form values={values} onValues={setValues}>
      <Input name="email" rules={[required, email]} />
      <Input name="name" rules={[required]} />
      <Input name="date1" rules={[greaterThanDate2]} />
      <Input name="date2" />
      <Submit />
    </Form>
  );
};

export default App;


text:
layout: post
title: Основы оптимизации запросов
---

Почему запрос выполняется так долго? Почему не используются индексы?
Наверное, все слышали об EXPLAIN в PostgreSQL.

Серия статей, которая поможет новичкам разобраться с этим замечательным инструментом.

[Часть 1](https://habrahabr.ru/post/203320/)

[Часть 2](https://habrahabr.ru/post/203386/)

[Часть 3](https://habrahabr.ru/post/203484/)


text:
#ifndef BOOST_HANA_MEMBERS_HPP
#define BOOST_HANA_MEMBERS_HPP

#include <hana/fwd/members.hpp>

#include <hana/accessors.hpp>
#include <hana/concept/struct.hpp>
#include <hana/config.hpp>
#include <hana/core/dispatch.hpp>
#include <hana/second.hpp>
#include <hana/transform.hpp>

BOOST_HANA_NAMESPACE_BEGIN
    //! @cond
    template <typename Object>
    constexpr auto members_t::operator()(Object&& object) const {
        using S = typename hana::tag_of<Object>::type;
        using Members = BOOST_HANA_DISPATCH_IF(members_impl<S>,
            hana::Struct<S>::value
        );

        #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
            static_assert(hana::Struct<S>::value,
            "hana::members(object) requires 'object' to be a Struct");
        #endif

        return Members::apply(static_cast<Object&&>(object));
    }
    //! @endcond

    namespace struct_detail {
        template <typename Holder, typename Forward>
        struct members_helper {
            Holder object;
            template <typename Accessor>
            constexpr decltype(auto) operator()(Accessor&& accessor) const {
                return hana::second(static_cast<Accessor&&>(accessor))(
                    static_cast<Forward>(object)
                );
            }
        };
    }

    template <typename S, bool condition>
    struct members_impl<S, when<condition>> : default_ {
        template <typename Object>
        static constexpr auto apply(Object&& object) {
            return hana::transform(hana::accessors<S>(),
                struct_detail::members_helper<Object&, Object&&>{object}
            );
        }
    };
BOOST_HANA_NAMESPACE_END

#endif // !BOOST_HANA_MEMBERS_HPP


text:
/*!
 * Sharedown
 *
 * @author  Alexander Lokhman
 * @email   alex.lokhman@gmail.com
 * @link    https://github.com/lokhman/sharedown
 */
(function(window, $) {
    'use strict';

    window.Sharedown.Users = new function() {
        var _sharedown = window.Sharedown,
            _self = this;

        if ('Users' in _sharedown)
            return _sharedown.Users;

        var $modal = $('#modal_user'),
            $form = $modal.find('form'),
            $formLogin = $('#_login'),
            $formPassword = $('#_password'),
            $formEnabled = $form.find('[name="is_enabled"]'),
            $formLevel = $form.find('[name="level"]'),
            $usersList = $('.users-list'),
            $usersTotal = $('.users-total'),
            $usersItem = $usersList.find('.users-item').show().detach(),
            $usersTokenGroup = $('.users-token-group'),
            $usersTokenShow = $('.users-token-show'),
            $usersTokenUpdate = $('.users-token-update'),
            $usersTokenDelete = $('.users-token-delete'),
            apiUsers = $usersList.data('api');

        this.loadUsers = function() {
            $.getJSON(apiUsers).done(function(data) {
                if (!data.users || !Array.isArray(data.users))
                    return;

                $usersList.empty();
                $.each(data.users, function(_, item) {
                    $usersItem.clone()
                        .find('.users-token')
                                .attr('title', (item.has_token ? 'Has' : 'No') + ' API token')
                                .toggleClass('text-muted-2', !item.has_token).end()
                        .find('.users-feed')
                            .each(function() {
                                if (item.has_feed)
                                    $(this).prop('href', '/feed/' + item.login);
                                else
                                    $(this).attr('title', 'Feed is disabled').addClass('text-muted-2');
                            }).end()
                        .find('.users-login')
                            .text(function() {
                                if (!item.is_enabled)
                                    $(this).wrap('<s>');
                                return item.login;
                            }).end()
                        .find('.users-level')
                            .text(item.level).end()
                        .find('.users-storage > *')
                            .text(item.files + (item.files !== 1 ? ' files' : ' file'))
                            .prop('href', '/web/?login=' + item.login).end()
                        .find('.users-activity')
                            .html(item.activity_at || '—').end()
                        .find('.users-created')
                            .text(item.created_at).end()
                        .find('[title]')
                            .tooltip().end()
                        .attr('data-login', item.login)
                        .addClass(
                            item.level === 'SUPER' ? 'danger' :
                            item.level === 'ADMIN' ? 'warning' : ''
                        )
                        .appendTo($usersList);
                });
            }).always(function() {
                $usersTotal.text('Total: ' + $('.users-item').length);
            });
        };

        $modal.on({
            'show.bs.modal': function(e) {
                var $button = $(e.relatedTarget),
                    login = $button.closest('[data-login]').data('login'),
                    submit_only = true;

                if (login) {
                    $usersTokenGroup.find('a').data('href', apiUsers + '/' + login + '/token').end().show();
                    $form.prop({ action: apiUsers + '/' + login, method: 'PATCH' }).data('message',
                        'User "' + login + '" details were successfully updated.');
                    $formPassword.prop('required', false);
                    submit_only = false;
                } else {
                    $form.prop({ action: apiUsers, method: 'POST' }).data('message',
                        'User was successfully created.');
                    $formPassword.prop('required', true);
                    $usersTokenGroup.hide();
                }

                _sharedown.form_dynamic($form[0], function() {
                    $modal.modal('hide');
                    _self.loadUsers();
                }, submit_only);
            },
            'hide.bs.modal': function() {
                $formLevel.filter(':first').add($formEnabled).prop('checked', true);
                $formLogin.add($formPassword).val('').trigger('keyup');
            }
        });

        $usersList.on('click', '.users-delete', function() {
            var login = $(this).closest('.users-item').data('login');

            _sharedown.modal('Delete', 'Do you want to delete this user?', function() {
                $.ajax(apiUsers + '/' + login, {
                    type: 'DELETE',
                    global: false
                }).done(_self.loadUsers).fail(function() {
                    setTimeout(function() {
                        _sharedown.modal('Error', 'Failed to delete the user from the system.');
                    }, 500);
                });
            });
        });

        $usersTokenShow.on('click', function() {
            $.getJSON($(this).data('href')).done(function(data) {
                _sharedown.modal('API Token', data.token ? '
' + data.token + '
' :
                    'User does not have any API token configured.');
            });
            return false;
        });

        $usersTokenUpdate.on('click', function() {
            if (window.confirm("Do you really want to UPDATE the user's API token?"))
                $.post($(this).data('href')).done(function(data) {
                    _sharedown.modal('New API Token', '
API token was successfully updated. The new token is:
' +
                        '
' + data.token + '
');
                });
            return false;
        });

        $usersTokenDelete.on('click', function() {
            if (window.confirm("Do you really want to DELETE the user's API token?"))
                $.ajax($(this).data('href'), { method: 'DELETE' }).done(function() {
                    _sharedown.modal('API Token Deleted', 'API token was successfully deleted.');
                });
            return false;
        });

        $(this.loadUsers);
    };
})(window, jQuery);


text:
package com.bstek.ureport.expression.function;

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

import org.apache.commons.lang3.StringUtils;

import com.bstek.ureport.Utils;
import com.bstek.ureport.build.BindData;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.expression.model.data.BindDataListExpressionData;
import com.bstek.ureport.expression.model.data.ExpressionData;
import com.bstek.ureport.expression.model.data.ObjectExpressionData;
import com.bstek.ureport.expression.model.data.ObjectListExpressionData;
import com.bstek.ureport.model.Cell;

/**
 * @author Jacky.gao
 * @since 2017年9月5日
 */
public class GetFunction implements Function {

	@Override
	public Object execute(List<ExpressionData<?>> dataList, Context context,Cell currentCell) {
		int index=1;
		String propertyName=null;
		List<Object> list= new ArrayList<Object>();
		if(dataList.size()==1){
			buildList(dataList.get(0),list);
		}else if(dataList.size()==2){
			buildList(dataList.get(0),list);
			index = buildIndex(dataList.get(1));
		}else if(dataList.size()==3){
			buildList(dataList.get(0),list);
			index = buildIndex(dataList.get(1));
			ExpressionData<?> d=dataList.get(2);
			if(d instanceof ObjectExpressionData){
				ObjectExpressionData exprData=(ObjectExpressionData)d;
				Object obj=exprData.getData();
				if(obj!=null){
					propertyName=obj.toString();
				}
			}
		}
		Object obj=null;
		if(list.size()>0){
			if(index<=list.size()){
				obj = list.get(index-1);
			}else{
				obj = list.get(list.size()-1);
			}
		}
		if(StringUtils.isNotBlank(propertyName)){
			obj=Utils.getProperty(obj, propertyName);
		}
		return obj;
	}

	private int buildIndex(ExpressionData<?> d) {
		int index=1;
		if(d instanceof ObjectExpressionData){
			ObjectExpressionData exprData=(ObjectExpressionData)d;
			Object obj=exprData.getData();
			if(obj!=null){
				index=Utils.toBigDecimal(obj).intValue();
			}
		}
		return index;
	}

	private void buildList(ExpressionData<?> d, List<Object> list) {
		if(d instanceof ObjectExpressionData){
			ObjectExpressionData exprData=(ObjectExpressionData)d;
			list.add(exprData.getData());
		}else if(d instanceof ObjectListExpressionData){
			ObjectListExpressionData listData=(ObjectListExpressionData)d;
			list.addAll(listData.getData());
		}else if(d instanceof BindDataListExpressionData){
			BindDataListExpressionData listData=(BindDataListExpressionData)d;
			for(BindData bindData:listData.getData()){
				list.addAll(bindData.getDataList());
			}
		}
	}

	@Override
	public String name() {
		return "get";
	}
}


text:
package org.kuali.kfs.fp.document.validation.impl;

import org.apache.commons.lang.StringUtils;
import org.kuali.kfs.sys.KFSKeyConstants;
import org.kuali.kfs.sys.KFSPropertyConstants;
import org.kuali.kfs.sys.businessobject.AccountingLine;
import org.kuali.kfs.sys.document.validation.GenericValidation;
import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
import org.kuali.rice.kns.service.DataDictionaryService;
import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
import org.kuali.rice.krad.util.GlobalVariables;

public class PreEncumbranceRequiredReferenceFieldValidation extends GenericValidation {
    private DataDictionaryService dataDictionaryService;
    private AccountingLine accountingLineForValidation;

    public boolean validate(AttributedDocumentEvent event) {
        boolean valid = true;
        if (this.getAccountingLineForValidation().isTargetAccountingLine()) {
            final BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(getAccountingLineForValidation().getClass().getName());

            if (StringUtils.isEmpty(getAccountingLineForValidation().getReferenceNumber())) {
                putRequiredPropertyError(boe, KFSPropertyConstants.REFERENCE_NUMBER);
                valid = false;
            }
        }
        return valid;
    }

    /**
     * Adds a global error for a missing required property. This is used for properties, such as reference origin code, which cannot
     * be required by the DataDictionary validation because not all documents require them.
     *
     * @param boe
     * @param propertyName
     */
    protected void putRequiredPropertyError(BusinessObjectEntry boe, String propertyName) {
        final String label = boe.getAttributeDefinition(propertyName).getShortLabel();
        GlobalVariables.getMessageMap().putError(propertyName, KFSKeyConstants.ERROR_REQUIRED, label);
    }

    /**
     * Gets the dataDictionaryService attribute.
     * @return Returns the dataDictionaryService.
     */
    public DataDictionaryService getDataDictionaryService() {
        return dataDictionaryService;
    }

    /**
     * Sets the dataDictionaryService attribute value.
     * @param dataDictionaryService The dataDictionaryService to set.
     */
    public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
        this.dataDictionaryService = dataDictionaryService;
    }

    /**
     * Gets the accountingLineForValidation attribute.
     * @return Returns the accountingLineForValidation.
     */
    public AccountingLine getAccountingLineForValidation() {
        return accountingLineForValidation;
    }

    /**
     * Sets the accountingLineForValidation attribute value.
     * @param accountingLineForValidation The accountingLineForValidation to set.
     */
    public void setAccountingLineForValidation(AccountingLine accoutingLineForValidation) {
        this.accountingLineForValidation = accoutingLineForValidation;
    }
}


text:
package im.tny.segvault.disturbances.database;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.Date;
import java.util.List;

@Dao
public interface StationUseDao {
    @Query("SELECT * FROM station_use WHERE trip_id = :tripID ORDER BY `order`")
    List<StationUse> getOfTrip(String tripID);

    @Query("SELECT COUNT(*) FROM station_use WHERE entry_date <= :end AND leave_date >= :start")
    int countOverlapping(Date start, Date end);

    @Query("SELECT station_id FROM" +
            "(SELECT station_id, COUNT(station_id) AS c " +
            "FROM station_use " +
            "WHERE type = \"NETWORK_ENTRY\" OR type = \"NETWORK_EXIT\" OR type = \"INTERCHANGE\" " +
            "GROUP BY station_id ORDER BY c DESC, entry_date DESC LIMIT :limit) " +
            "WHERE c > 0")
    List<String> getMostUsedStations(int limit);

    @Query("SELECT COUNT(*) FROM station_use WHERE type = :type AND station_id = :stationID")
    int countStationUsesOfType(String stationID, StationUse.UseType type);

    @Query("SELECT COUNT(*) FROM station_use WHERE type = \"INTERCHANGE\" AND station_id = :stationID AND source_line = :sourceLineID")
    int countStationInterchangesToLine(String stationID, String sourceLineID);

    @Insert
    void insertAll(StationUse... stationUses);

    @Update
    void updateAll(StationUse... stationUses);

    @Delete
    void delete(StationUse stationUse);

    @Query("DELETE FROM station_use WHERE trip_id = :tripID")
    void deleteOfTrip(String tripID);

    @Query("DELETE FROM station_use")
    void deleteAll();

}


text:
package com.msaf.validador.consultaonline.validador;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.msaf.validador.consultaonline.exceptions.ValidadorRuntimeException;
import com.msaf.validador.consultaonline.jna.IConsultaOnLineJNA;

/**
 *
 * @author Ederson de Lima
 *
 */
public class ValidadorOnlineRMIClient implements IConsultaOnLineJNA {
	public static final String RETORNO_PARAMETROS_INVALIDO="retornoParametrosInvalidos";
	public static final String RETORNO_TIMEOUT="retornoTimeout";

	Logger log = Logger.getLogger(ValidadorOnlineRMIClient.class);

	//processo do servidor RMI
	private Process rmiServerProcess;

	//Stub apontando para o processo que está rodando em this.rmiServerProcess
	private IConsultaOnLineJNA consultaOnLineJNA;

	//timeout para destruir o processo
	private long timeOut;

	/**
	 *
	 * @param envServer
	 * @param pathServer
	 * @param timeOut
	 */
	public ValidadorOnlineRMIClient(long timeOut,String serviceName) {

		//this.rmiServerProcess = instanciaProcessoValidadorRMI(serviceName);

		try {
			this.consultaOnLineJNA = localizaServico("hhh");
		} catch (MalformedURLException e) {
			throw new ValidadorRuntimeException("Erro ao tentar localizar serviço! URL mal formada!",e);
		} catch (RemoteException e) {
			throw new ValidadorRuntimeException("Erro ao tentar localizar serviço!",e);
		} catch (NotBoundException e) {
			throw new ValidadorRuntimeException("Erro ao tentar localizar serviço! Serviço não encontrado!",e);
		}

		this.timeOut = timeOut;
	}

	/**
	 * Localiza serviço RMI
	 * @param serviceName
	 * @return
	 * @throws NotBoundException
	 * @throws RemoteException
	 * @throws MalformedURLException
	 */
	private IConsultaOnLineJNA localizaServico(String serviceName) throws MalformedURLException, RemoteException, NotBoundException {

		IConsultaOnLineJNA consultaOnLineJNA = (IConsultaOnLineJNA) Naming.lookup(serviceName);

		return consultaOnLineJNA;

	}

	/**
	 * Inicializar processo do servidor RMI
	 * @param serviceName
	 * @return
	 */
	protected Process instanciaProcessoValidadorRMI(String serviceName) {
		List<String> comandos = new ArrayList<String>();

		comandos.add("java");
		comandos.add("-jar");
		comandos.add("msaf.validador.jmsconsumer-1.0.jar");
		comandos.add(serviceName);
		//comandos.add("-Xdebug");
		//comandos.add("-Xrunjdwp:transport=dt_socket,address=4145,server=y,suspend=y");

		ProcessBuilder processBuilder = new ProcessBuilder(comandos);
		processBuilder.directory(new File("C:\\darcio\\trabalho\\SVN_Validador\\jmsconsumer\\target"));
		try {
			return processBuilder.start();
		} catch (IOException e) {
			throw new ValidadorRuntimeException("Erro ao tentar inicializar processo!",e);
		}
	}

	/**
	 * Limpa área de memoria da DLL
	 */
	@Override
	public void DBI_DLLStrFree(String memId) {
		this.DBI_DLLStrFree(memId);
	}

	/**
	 * Efetuar consulta pela DLL
	 */
	@Override
	public String DBI_EfetuaConsultaServico(Integer servico, String parametros, String dllPath, String evServer) {
		return this.consultaOnLineJNA.DBI_EfetuaConsultaServico(servico, parametros, dllPath, evServer);
	}

	/**
	 * Cria thread monitora do timeout das consultas
	 * @param process
	 */
	protected void criarThreadTimeout(final Process process, final Long timeout) {
		Thread controlaTimeoutProcesso = new Thread(){
			@Override
			public void run() {
				long tempoMaximo = System.currentTimeMillis()+timeout;

				while(System.currentTimeMillis() < tempoMaximo){
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				process.destroy();
			}
		};
		controlaTimeoutProcesso.start();
	}

}


text:
import {
  ConversationAppTestQuery,
  ConversationAppTestQuery$rawResponse,
} from "__generated__/ConversationAppTestQuery.graphql"
import { screen } from "@testing-library/react"
import { MockedConversation } from "Apps/__tests__/Fixtures/Conversation"
import { setupTestWrapperTL } from "DevTools/setupTestWrapper"
import { SystemContextProvider } from "System"
import { MockBoot } from "DevTools"
import { HeadProvider } from "react-head"
import { graphql } from "react-relay"
import { ConversationAppFragmentContainer } from "../ConversationApp"

jest.unmock("react-relay")

const { renderWithRelay } = setupTestWrapperTL<ConversationAppTestQuery>({
  Component: props => {
    return (
      <MockBoot>
        <HeadProvider>
          <SystemContextProvider
            user={{
              type: "NotAdmin",
            }}
          >
            {/* @ts-ignore */}
            <ConversationAppFragmentContainer me={props.me} />
          </SystemContextProvider>
        </HeadProvider>
      </MockBoot>
    )
  },
  query: graphql`
    query ConversationAppTestQuery @raw_response_type @relay_test_operation {
      me {
        ...ConversationApp_me
      }
    }
  `,
})

const pageInfo: NonNullable<
  NonNullable<
    ConversationAppTestQuery$rawResponse["me"]
  >["conversationsConnection"]
>["pageInfo"] = {
  startCursor: "NQ",
  endCursor: "MQ",
  hasNextPage: true,
  hasPreviousPage: false,
}

describe("Conversation app", () => {
  beforeAll(() => {
    jest.resetAllMocks()
  })
  beforeEach(() => {
    // IntersectionObserver isn't available in test environment
    const mockIntersectionObserver = jest.fn()
    mockIntersectionObserver.mockReturnValue({
      observe: () => null,
      unobserve: () => null,
      disconnect: () => null,
    })
    window.IntersectionObserver = mockIntersectionObserver
  })

  describe("as non admin user", () => {
    describe("having previous conversations", () => {
      it("renders conversations", () => {
        renderWithRelay({
          Me: () => ({
            id: "111",
          }),
          ConversationConnection: () => ({
            edges: [{ node: MockedConversation, cursor: "absc" }],
            pageInfo,
          }),
        })
        expect(screen.getByText("Ashkan Gallery")).toBeInTheDocument()
      })
    })

    describe("not having previous conversations", () => {
      it("shows an empty state when loading the conversationsConnection", () => {
        renderWithRelay({
          Me: () => ({
            id: "111",
          }),
          ConversationConnection: () => ({
            edges: [],
            pageInfo,
          }),
        })

        expect(
          screen.getByText("You don't have any messages yet.")
        ).toBeInTheDocument()
        expect(
          screen.getByText(
            "Contact galleries to purchase available work. You'll find your ongoing conversations here."
          )
        ).toBeInTheDocument()

        expect(screen.getByText("Explore artworks")).toBeInTheDocument()
        expect(screen.getByRole("link")).toHaveAttribute("href", "/collect")
      })
    })
  })
})


text:
namespace my
{
  // Called when ASSERT, CHECK or VERIFY failed.
  typedef void (*AssertFailedFn)(SrcPoint const &, string const &);
  extern AssertFailedFn OnAssertFailed;

  /// @return Pointer to previous message function.
  AssertFailedFn SetAssertFunction(AssertFailedFn fn);
}

// TODO: Evaluate X only once in CHECK().
#define CHECK(X, msg) do { if (X) {} else { \
    ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X")", ::my::impl::Message msg));} } while(false)
#define CHECK_EQUAL(X, Y, msg) do { if ((X) == (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" == "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_NOT_EQUAL(X, Y, msg) do { if ((X) != (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" != "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_LESS(X, Y, msg) do { if ((X) < (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" < "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_LESS_OR_EQUAL(X, Y, msg) do { if ((X) <= (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" <= "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_GREATER(X, Y, msg) do { if ((X) > (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" > "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_GREATER_OR_EQUAL(X, Y, msg) do { if ((X) >= (Y)) {} else { \
  ::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" >= "#Y")", \
                                                   ::my::impl::Message(X, Y), \
                                                   ::my::impl::Message msg));} } while (false)
#define CHECK_OR_CALL(fail, call, X, msg) do { if (X) {} else { \
  if (fail) {\
    ::my::OnAssertFailed(SRC(), ::my::impl::Message(::my::impl::Message("CHECK("#X")"), \
                                                     ::my::impl::Message msg)); \
  } else { \
    call(); \
  } } } while (false)

#ifdef DEBUG
// for Symbian compatibility
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(X, msg) CHECK(X, msg)
#define VERIFY(X, msg) CHECK(X, msg)
#define ASSERT_EQUAL(X, Y, msg) CHECK_EQUAL(X, Y, msg)
#define ASSERT_NOT_EQUAL(X, Y, msg) CHECK_NOT_EQUAL(X, Y, msg)
#define ASSERT_LESS(X, Y, msg) CHECK_LESS(X, Y, msg)
#define ASSERT_LESS_OR_EQUAL(X, Y, msg) CHECK_LESS_OR_EQUAL(X, Y, msg)
#define ASSERT_GREATER(X, Y, msg) CHECK_GREATER(X, Y, msg)
#define ASSERT_GREATER_OR_EQUAL(X, Y, msg) CHECK_GREATER_OR_EQUAL(X, Y, msg)
#else
// for Symbian compatibility
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(X, msg)
#define VERIFY(X, msg) (void)(X)
#define ASSERT_EQUAL(X, Y, msg)
#define ASSERT_NOT_EQUAL(X, Y, msg)
#define ASSERT_LESS(X, Y, msg)
#define ASSERT_LESS_OR_EQUAL(X, Y, msg)
#define ASSERT_GREATER(X, Y, msg)
#define ASSERT_GREATER_OR_EQUAL(X, Y, msg)
#endif


text:
require 'simplecov'
require 'simplecov-console'

if ENV['CODECLIMATE_REPO_TOKEN']
  require 'codeclimate-test-reporter'
  CodeClimate::TestReporter.start
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
    SimpleCov::Formatter::Console,
    SimpleCov::Formatter::HTMLFormatter,
    CodeClimate::TestReporter::Formatter
  ]
else
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
    [SimpleCov::Formatter::Console,
     SimpleCov::Formatter::HTMLFormatter]
  )
end

SimpleCov.start do
  coverage_dir 'coverage'
end

ENV['RAILS_ENV'] = 'test'

require "#{File.dirname(__FILE__)}/dummy/config/environment.rb"
require 'rspec/rails'

RSpec.configure do |config|
  config.infer_base_class_for_anonymous_controllers = true
  config.order = 'random'
end


text:
//This file is automatically rebuilt by the Cesium build process.
/*global define*/
define(function() {
    "use strict";
    return "/**\n\
 * Compositing for Weighted Blended Order-Independent Transparency. See:\n\
 * - http://jcgt.org/published/0002/02/09/\n\
 * - http://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html\n\
 */\n\
 \n\
uniform sampler2D u_opaque;\n\
uniform sampler2D u_accumulation;\n\
uniform sampler2D u_revealage;\n\
\n\
varying vec2 v_textureCoordinates;\n\
\n\
void main()\n\
{\n\
    vec4 opaque = texture2D(u_opaque, v_textureCoordinates);\n\
    vec4 accum = texture2D(u_accumulation, v_textureCoordinates);\n\
    float r = texture2D(u_revealage, v_textureCoordinates).r;\n\
    \n\
#ifdef MRT\n\
    vec4 transparent = vec4(accum.rgb / clamp(r, 1e-4, 5e4), accum.a);\n\
#else\n\
    vec4 transparent = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);\n\
#endif\n\
    \n\
    gl_FragColor = (1.0 - transparent.a) * transparent + transparent.a * opaque;\n\
}\n\
";
});


text:
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import { Ratings } from '../imports/api/ratings';
import { Users } from '../imports/api/users';

import { name as Srec } from '../imports/ui/components/srec/srec';


text:
package com.android.ide.common.xml;

import com.android.ide.common.xml.ManifestData.UsesFeature;
import com.android.ide.common.xml.ManifestData.UsesLibrary;
import com.android.resources.Keyboard;
import com.android.resources.Navigation;
import com.android.resources.TouchScreen;

import junit.framework.TestCase;

import java.io.InputStream;

/**
 * Tests for {@link AndroidManifestParser}
 */
public class AndroidManifestParserTest extends TestCase {
    private ManifestData mManifestTestApp;
    private ManifestData mManifestInstrumentation;

    private static final String TESTDATA_PATH =
        "/com/android/sdklib/testdata/";  //$NON-NLS-1$
    private static final String INSTRUMENTATION_XML = TESTDATA_PATH +
        "AndroidManifest-instrumentation.xml";  //$NON-NLS-1$
    private static final String TESTAPP_XML = TESTDATA_PATH +
        "AndroidManifest-testapp.xml";  //$NON-NLS-1$
    private static final String ACTIVITY_ALIAS_XML = TESTDATA_PATH +
            "AndroidManifest-activityalias.xml";  //$NON-NLS-1$
    private static final String PACKAGE_NAME =  "com.android.testapp"; //$NON-NLS-1$
    private static final Integer VERSION_CODE = 42;
    private static final String ACTIVITY_NAME = "com.android.testapp.MainActivity"; //$NON-NLS-1$
    private static final String LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
    private static final String LIBRARY_NAME2 = "android.test.runner2"; //$NON-NLS-1$
    private static final String FEATURE_NAME = "com.foo.feature"; //$NON-NLS-1$
    private static final String INSTRUMENTATION_NAME = "android.test.InstrumentationTestRunner"; //$NON-NLS-1$
    private static final String INSTRUMENTATION_TARGET = "com.android.AndroidProject"; //$NON-NLS-1$

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        InputStream manifestStream = this.getClass().getResourceAsStream(TESTAPP_XML);

        mManifestTestApp = AndroidManifestParser.parse(manifestStream);
        assertNotNull(mManifestTestApp);

        manifestStream = this.getClass().getResourceAsStream(INSTRUMENTATION_XML);
        mManifestInstrumentation = AndroidManifestParser.parse(manifestStream);
        assertNotNull(mManifestInstrumentation);
    }

    public void testGetInstrumentationInformation() {
        assertEquals(1, mManifestInstrumentation.getInstrumentations().length);
        assertEquals(INSTRUMENTATION_NAME,
                mManifestInstrumentation.getInstrumentations()[0].getName());
        assertEquals(INSTRUMENTATION_TARGET,
                mManifestInstrumentation.getInstrumentations()[0].getTargetPackage());
    }

    public void testGetPackage() {
        assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
    }

    public void testGetVersionCode() {
        assertEquals(VERSION_CODE, mManifestTestApp.getVersionCode());
        assertEquals(null, mManifestInstrumentation.getVersionCode());
    }

    public void testMinSdkVersion() {
        assertEquals(7, mManifestTestApp.getMinSdkVersion());
        assertEquals(8, mManifestTestApp.getTargetSdkVersion());

        assertEquals("foo", mManifestInstrumentation.getMinSdkVersionString());
        assertEquals(ManifestData.MIN_SDK_CODENAME, mManifestInstrumentation.getMinSdkVersion());
    }

    public void testGetActivities() {
        assertEquals(1, mManifestTestApp.getActivities().length);
        ManifestData.Activity activity = mManifestTestApp.getActivities()[0];
        assertEquals(ACTIVITY_NAME, activity.getName());
        assertTrue(activity.hasAction());
        assertTrue(activity.isHomeActivity());
        assertTrue(activity.hasAction());
        assertEquals(activity, mManifestTestApp.getActivities()[0]);
    }

    public void testGetLauncherActivity() {
        ManifestData.Activity activity = mManifestTestApp.getLauncherActivity();
        assertEquals(ACTIVITY_NAME, activity.getName());
        assertTrue(activity.hasAction());
        assertTrue(activity.isHomeActivity());
    }

    public void testSupportsScreen() {
        ManifestData.SupportsScreens supportsScreens =
            mManifestTestApp.getSupportsScreensFromManifest();

        assertNotNull(supportsScreens);
        assertEquals(Boolean.TRUE, supportsScreens.getAnyDensity());
        assertEquals(Boolean.TRUE, supportsScreens.getResizeable());
        assertEquals(Boolean.TRUE, supportsScreens.getSmallScreens());
        assertEquals(Boolean.TRUE, supportsScreens.getNormalScreens());
        assertEquals(Boolean.TRUE, supportsScreens.getLargeScreens());
    }

    public void testUsesConfiguration() {
        ManifestData.UsesConfiguration usesConfig = mManifestTestApp.getUsesConfiguration();

        assertNotNull(usesConfig);
        assertEquals(Boolean.TRUE, usesConfig.getReqFiveWayNav());
        assertEquals(Navigation.NONAV, usesConfig.getReqNavigation());
        assertEquals(Boolean.TRUE, usesConfig.getReqHardKeyboard());
        assertEquals(Keyboard.TWELVEKEY, usesConfig.getReqKeyboardType());
        assertEquals(TouchScreen.FINGER, usesConfig.getReqTouchScreen());
    }

    private void assertEquals(ManifestData.Activity lhs, ManifestData.Activity rhs) {
        assertTrue(lhs == rhs || (lhs != null && rhs != null));
        if (lhs != null && rhs != null) {
            assertEquals(lhs.getName(),        rhs.getName());
            assertEquals(lhs.isExported(),     rhs.isExported());
            assertEquals(lhs.hasAction(),      rhs.hasAction());
            assertEquals(lhs.isHomeActivity(), rhs.isHomeActivity());
        }
    }

    public void testGetUsesLibraries() {
        UsesLibrary[] libraries = mManifestTestApp.getUsesLibraries();

        assertEquals(2,             libraries.length);
        assertEquals(LIBRARY_NAME,  libraries[0].getName());
        assertEquals(Boolean.FALSE, libraries[0].getRequired());
        assertEquals(LIBRARY_NAME2, libraries[1].getName());
        assertEquals(Boolean.TRUE,  libraries[1].getRequired());
    }

    public void testGetUsesFeatures() {
        UsesFeature[] features = mManifestTestApp.getUsesFeatures();

        assertEquals(2,            features.length);
        assertEquals(0x00020001,   features[0].mGlEsVersion);
        assertEquals(Boolean.TRUE, features[0].getRequired());
        assertEquals(FEATURE_NAME, features[1].getName());
        assertEquals(Boolean.TRUE, features[1].getRequired());
    }

    public void testGetPackageName() {
        assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
    }

    public void testActivityAlias() throws Exception {
        InputStream manifestStream = this.getClass().getResourceAsStream(ACTIVITY_ALIAS_XML);

        ManifestData manifest = AndroidManifestParser.parse(manifestStream);
        assertNotNull(manifest);

        assertEquals(manifest.getLauncherActivity().getName(),
                "com.android.testapp.AliasActivity"); //$NON-NLS-1$
    }
}


text:
package io.moquette.broker;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MemoryQueueRepository implements IQueueRepository {

    private Map<String, Queue<SessionRegistry.EnqueuedMessage>> queues = new HashMap<>();

    @Override
    public Queue<SessionRegistry.EnqueuedMessage> createQueue(String cli, boolean clean) {
        final ConcurrentLinkedQueue<SessionRegistry.EnqueuedMessage> queue = new ConcurrentLinkedQueue<>();
        queues.put(cli, queue);
        return queue;
    }

    @Override
    public void removeQueue(String cli) {
        queues.remove(cli);
    }

    @Override
    public Map<String, Queue<SessionRegistry.EnqueuedMessage>> listAllQueues() {
        return Collections.unmodifiableMap(queues);
    }
}


text:
package jadx.plugins.input.smali;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

import org.jetbrains.annotations.Nullable;
import org.jf.smali.Smali;
import org.jf.smali.SmaliOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SmaliConvert implements Closeable {
	private static final Logger LOG = LoggerFactory.getLogger(SmaliConvert.class);

	@Nullable
	private Path tmpDex;

	public boolean execute(List<Path> input) {
		List<Path> smaliFiles = filterSmaliFiles(input);
		if (smaliFiles.isEmpty()) {
			return false;
		}
		LOG.debug("Compiling smali files: {}", smaliFiles.size());
		try {
			this.tmpDex = Files.createTempFile("jadx-", ".dex");
			if (compileSmali(tmpDex, smaliFiles)) {
				return true;
			}
		} catch (Exception e) {
			LOG.error("Smali process error", e);
		}
		close();
		return false;
	}

	private static boolean compileSmali(Path output, List<Path> inputFiles) throws IOException {
		SmaliOptions options = new SmaliOptions();
		options.outputDexFile = output.toAbsolutePath().toString();
		options.verboseErrors = true;

		List<String> inputFileNames = inputFiles.stream()
				.map(p -> p.toAbsolutePath().toString())
				.distinct()
				.collect(Collectors.toList());

		try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
			boolean result = collectSystemErrors(out, () -> Smali.assemble(options, inputFileNames));
			if (!result) {
				LOG.error("Smali compilation error:\n{}", out);
			}
			return result;
		}
	}

	private static boolean collectSystemErrors(OutputStream out, Callable<Boolean> exec) {
		PrintStream systemErr = System.err;
		try (PrintStream err = new PrintStream(out)) {
			System.setErr(err);
			try {
				return exec.call();
			} catch (Exception e) {
				e.printStackTrace(err);
				return false;
			}
		} finally {
			System.setErr(systemErr);
		}
	}

	private List<Path> filterSmaliFiles(List<Path> input) {
		PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.smali");
		return input.stream()
				.filter(matcher::matches)
				.collect(Collectors.toList());
	}

	public List<Path> getDexFiles() {
		if (tmpDex == null) {
			return Collections.emptyList();
		}
		return Collections.singletonList(tmpDex);
	}

	@Override
	public void close() {
		try {
			if (tmpDex != null) {
				Files.deleteIfExists(tmpDex);
			}
		} catch (Exception e) {
			LOG.error("Failed to remove tmp dex file: {}", tmpDex, e);
		}
	}
}