text:
package whisk.core.database

import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration._

import akka.actor.ActorSystem
import akka.event.Logging.ErrorLevel
import akka.http.scaladsl.model._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl._
import akka.util.ByteString
import spray.json._
import whisk.common.Logging
import whisk.common.LoggingMarkers
import whisk.common.TransactionId
import whisk.core.entity.BulkEntityResult
import whisk.core.entity.DocInfo
import whisk.core.entity.DocRevision
import whisk.core.entity.WhiskDocument
import whisk.http.Messages
import whisk.core.entity.DocumentReader

/**
 * Basic client to put and delete artifacts in a data store.
 *
 * @param dbProtocol the protocol to access the database with (http/https)
 * @param dbHost the host to access database from
 * @param dbPort the port on the host
 * @param dbUserName the user name to access database as
 * @param dbPassword the secret for the user name required to access the database
 * @param dbName the name of the database to operate on
 * @param serializerEvidence confirms the document abstraction is serializable to a Document with an id
 */
class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: String,
                                                                  dbHost: String,
                                                                  dbPort: Int,
                                                                  dbUsername: String,
                                                                  dbPassword: String,
                                                                  dbName: String,
                                                                  useBatching: Boolean = false)(
  implicit system: ActorSystem,
  val logging: Logging,
  jsonFormat: RootJsonFormat[DocumentAbstraction],
  materializer: ActorMaterializer,
  docReader: DocumentReader)
    extends ArtifactStore[DocumentAbstraction]
    with DefaultJsonProtocol {

  protected[core] implicit val executionContext = system.dispatcher

  private val client: CouchDbRestClient =
    new CouchDbRestClient(dbProtocol, dbHost, dbPort.toInt, dbUsername, dbPassword, dbName)

  // This the the amount of allowed parallel requests for each entity, before batching starts. If there are already maxOpenDbRequests
  // and more documents need to be stored, then all arriving documents will be put into batches (if enabled) to avoid a long queue.
  private val maxOpenDbRequests = system.settings.config.getInt("akka.http.host-connection-pool.max-connections") / 2

  private val batcher: Batcher[JsObject, Either[ArtifactStoreException, DocInfo]] =
    new Batcher(500, maxOpenDbRequests)(put(_)(TransactionId.unknown))

  override protected[database] def put(d: DocumentAbstraction)(implicit transid: TransactionId): Future[DocInfo] = {
    val asJson = d.toDocumentRecord

    val id: String = asJson.fields("_id").convertTo[String].trim
    val rev: Option[String] = asJson.fields.get("_rev").map(_.convertTo[String])
    require(!id.isEmpty, "document id must be defined")

    val docinfoStr = s"id: $id, rev: ${rev.getOrElse("null")}"
    val start = transid.started(this, LoggingMarkers.DATABASE_SAVE, s"[PUT] '$dbName' saving document: '${docinfoStr}'")

    val f = if (useBatching) {
      batcher.put(asJson).map { e =>
        e match {
          case Right(response) =>
            transid.finished(this, start, s"[PUT] '$dbName' completed document: '${docinfoStr}', response: '$response'")
            response

          case Left(e: DocumentConflictException) =>
            transid.finished(this, start, s"[PUT] '$dbName', document: '${docinfoStr}'; conflict.")
            // For compatibility.
            throw DocumentConflictException("conflict on 'put'")

          case Left(e: ArtifactStoreException) =>
            transid.finished(this, start, s"[PUT] '$dbName', document: '${docinfoStr}'; ${e.getMessage}.")
            throw PutException("error on 'put'")
        }
      }
    } else {
      val request: CouchDbRestClient => Future[Either[StatusCode, JsObject]] = rev match {
        case Some(r) =>
          client =>
            client.putDoc(id, r, asJson)
        case None =>
          client =>
            client.putDoc(id, asJson)
      }
      request(client).map {
        case Right(response) =>
          transid.finished(this, start, s"[PUT] '$dbName' completed document: '${docinfoStr}', response: '$response'")
          response.convertTo[DocInfo]
        case Left(StatusCodes.Conflict) =>
          transid.finished(this, start, s"[PUT] '$dbName', document: '${docinfoStr}'; conflict.")
          // For compatibility.
          throw DocumentConflictException("conflict on 'put'")
        case Left(code) =>
          transid.failed(
            this,
            start,
            s"[PUT] '$dbName' failed to put document: '${docinfoStr}'; http status: '${code}'",
            ErrorLevel)
          throw new Exception("Unexpected http response code: " + code)
      }
    }

    reportFailure(
      f,
      failure =>
        transid.failed(this, start, s"[PUT] '$dbName' internal error, failure: '${failure.getMessage}'", ErrorLevel))
  }

  private def put(ds: Seq[JsObject])(
    implicit transid: TransactionId): Future[Seq[Either[ArtifactStoreException, DocInfo]]] = {
    val count = ds.size
    val start = transid.started(this, LoggingMarkers.DATABASE_BULK_SAVE, s"'$dbName' saving $count documents")

    val f = client.putDocs(ds).map {
      _ match {
        case Right(response) =>
          transid.finished(this, start, s"'$dbName' completed $count documents")

          response.convertTo[Seq[BulkEntityResult]].map { singleResult =>
            singleResult.error
              .map {
                case "conflict" => Left(DocumentConflictException("conflict on 'bulk_put'"))
                case e          => Left(PutException(s"Unexpected $e: ${singleResult.reason.getOrElse("")} on 'bulk_put'"))
              }
              .getOrElse {
                Right(singleResult.toDocInfo)
              }
          }

        case Left(code) =>
          transid.failed(this, start, s"'$dbName' failed to put documents, http status: '${code}'", ErrorLevel)
          throw new Exception("Unexpected http response code: " + code)
      }
    }

    reportFailure(
      f,
      failure =>
        transid.failed(this, start, s"[PUT] '$dbName' internal error, failure: '${failure.getMessage}'", ErrorLevel))
  }

  override protected[database] def del(doc: DocInfo)(implicit transid: TransactionId): Future[Boolean] = {
    require(doc != null && doc.rev.asString != null, "doc revision required for delete")

    val start = transid.started(this, LoggingMarkers.DATABASE_DELETE, s"[DEL] '$dbName' deleting document: '$doc'")

    val f = client.deleteDoc(doc.id.id, doc.rev.rev).map { e =>
      e match {
        case Right(response) =>
          transid.finished(this, start, s"[DEL] '$dbName' completed document: '$doc', response: $response")
          response.fields("ok").convertTo[Boolean]

        case Left(StatusCodes.NotFound) =>
          transid.finished(this, start, s"[DEL] '$dbName', document: '${doc}'; not found.")
          // for compatibility
          throw NoDocumentException("not found on 'delete'")

        case Left(StatusCodes.Conflict) =>
          transid.finished(this, start, s"[DEL] '$dbName', document: '${doc}'; conflict.")
          throw DocumentConflictException("conflict on 'delete'")

        case Left(code) =>
          transid.failed(
            this,
            start,
            s"[DEL] '$dbName' failed to delete document: '${doc}'; http status: '${code}'",
            ErrorLevel)
          throw new Exception("Unexpected http response code: " + code)
      }
    }

    reportFailure(
      f,
      failure =>
        transid.failed(
          this,
          start,
          s"[DEL] '$dbName' internal error, doc: '$doc', failure: '${failure.getMessage}'",
          ErrorLevel))
  }

  override protected[database] def get[A <: DocumentAbstraction](doc: DocInfo)(implicit transid: TransactionId,
                                                                               ma: Manifest[A]): Future[A] = {

    val start = transid.started(this, LoggingMarkers.DATABASE_GET, s"[GET] '$dbName' finding document: '$doc'")

    require(doc != null, "doc undefined")
    val request: CouchDbRestClient => Future[Either[StatusCode, JsObject]] = if (doc.rev.rev != null) { client =>
      client.getDoc(doc.id.id, doc.rev.rev)
    } else { client =>
      client.getDoc(doc.id.id)
    }

    val f = request(client).map { e =>
      e match {
        case Right(response) =>
          transid.finished(this, start, s"[GET] '$dbName' completed: found document '$doc'")

          val asFormat = try {
            docReader.read(ma, response)
          } catch {
            case e: Exception => jsonFormat.read(response)
          }

          if (asFormat.getClass != ma.runtimeClass) {
            throw DocumentTypeMismatchException(
              s"document type ${asFormat.getClass} did not match expected type ${ma.runtimeClass}.")
          }

          val deserialized = asFormat.asInstanceOf[A]

          val responseRev = response.fields("_rev").convertTo[String]
          assert(doc.rev.rev == null || doc.rev.rev == responseRev, "Returned revision should match original argument")
          // FIXME remove mutability from appropriate classes now that it is no longer required by GSON.
          deserialized.asInstanceOf[WhiskDocument].revision(DocRevision(responseRev))

          deserialized

        case Left(StatusCodes.NotFound) =>
          transid.finished(this, start, s"[GET] '$dbName', document: '${doc}'; not found.")
          // for compatibility
          throw NoDocumentException("not found on 'get'")

        case Left(code) =>
          transid.finished(this, start, s"[GET] '$dbName' failed to get document: '${doc}'; http status: '${code}'")
          throw new Exception("Unexpected http response code: " + code)
      }
    } recoverWith {
      case e: DeserializationException => throw DocumentUnreadable(Messages.corruptedEntity)
    }

    reportFailure(
      f,
      failure =>
        transid.failed(
          this,
          start,
          s"[GET] '$dbName' internal error, doc: '$doc', failure: '${failure.getMessage}'",
          ErrorLevel))
  }

  override protected[core] def query(table: String,
                                     startKey: List[Any],
                                     endKey: List[Any],
                                     skip: Int,
                                     limit: Int,
                                     includeDocs: Boolean,
                                     descending: Boolean,
                                     reduce: Boolean,
                                     stale: StaleParameter)(implicit transid: TransactionId): Future[List[JsObject]] = {

    require(!(reduce && includeDocs), "reduce and includeDocs cannot both be true")

    // Apparently you have to do that in addition to setting "descending"
    val (realStartKey, realEndKey) = if (descending) {
      (endKey, startKey)
    } else {
      (startKey, endKey)
    }

    val parts = table.split("/")

    val start = transid.started(this, LoggingMarkers.DATABASE_QUERY, s"[QUERY] '$dbName' searching '$table")

    val f = for (eitherResponse <- client.executeView(parts(0), parts(1))(
                   startKey = realStartKey,
                   endKey = realEndKey,
                   skip = Some(skip),
                   limit = Some(limit),
                   stale = stale,
                   includeDocs = includeDocs,
                   descending = descending,
                   reduce = reduce))
      yield
        eitherResponse match {
          case Right(response) =>
            val rows = response.fields("rows").convertTo[List[JsObject]]

            val out = if (reduce && !rows.isEmpty) {
              assert(rows.length == 1, s"result of reduced view contains more than one value: '$rows'")
              rows.head.fields("value").convertTo[List[JsObject]]
            } else if (reduce) {
              List(JsObject())
            } else {
              rows
            }

            transid.finished(this, start, s"[QUERY] '$dbName' completed: matched ${out.size}")
            out

          case Left(code) =>
            transid.failed(this, start, s"Unexpected http response code: $code", ErrorLevel)
            throw new Exception("Unexpected http response code: " + code)
        }

    reportFailure(
      f,
      failure =>
        transid.failed(this, start, s"[QUERY] '$dbName' internal error, failure: '${failure.getMessage}'", ErrorLevel))
  }

  override protected[core] def attach(
    doc: DocInfo,
    name: String,
    contentType: ContentType,
    docStream: Source[ByteString, _])(implicit transid: TransactionId): Future[DocInfo] = {

    val start = transid.started(
      this,
      LoggingMarkers.DATABASE_ATT_SAVE,
      s"[ATT_PUT] '$dbName' uploading attachment '$name' of document '$doc'")

    require(doc != null, "doc undefined")
    require(doc.rev.rev != null, "doc revision must be specified")

    val f = client.putAttachment(doc.id.id, doc.rev.rev, name, contentType, docStream).map { e =>
      e match {
        case Right(response) =>
          transid
            .finished(this, start, s"[ATT_PUT] '$dbName' completed uploading attachment '$name' of document '$doc'")
          val id = response.fields("id").convertTo[String]
          val rev = response.fields("rev").convertTo[String]
          DocInfo ! (id, rev)

        case Left(StatusCodes.NotFound) =>
          transid
            .finished(this, start, s"[ATT_PUT] '$dbName' uploading attachment '$name' of document '$doc'; not found")
          throw NoDocumentException("Not found on 'readAttachment'.")

        case Left(code) =>
          transid.failed(
            this,
            start,
            s"[ATT_PUT] '$dbName' failed to upload attachment '$name' of document '$doc'; http status '$code'")
          throw new Exception("Unexpected http response code: " + code)
      }
    }

    reportFailure(
      f,
      failure =>
        transid.failed(
          this,
          start,
          s"[ATT_PUT] '$dbName' internal error, name: '$name', doc: '$doc', failure: '${failure.getMessage}'",
          ErrorLevel))
  }

  override protected[core] def readAttachment[T](doc: DocInfo, name: String, sink: Sink[ByteString, Future[T]])(
    implicit transid: TransactionId): Future[(ContentType, T)] = {

    val start = transid.started(
      this,
      LoggingMarkers.DATABASE_ATT_GET,
      s"[ATT_GET] '$dbName' finding attachment '$name' of document '$doc'")

    require(doc != null, "doc undefined")
    require(doc.rev.rev != null, "doc revision must be specified")

    val f = client.getAttachment[T](doc.id.id, doc.rev.rev, name, sink)
    val g = f.map { e =>
      e match {
        case Right((contentType, result)) =>
          transid.finished(this, start, s"[ATT_GET] '$dbName' completed: found attachment '$name' of document '$doc'")
          (contentType, result)

        case Left(StatusCodes.NotFound) =>
          transid.finished(
            this,
            start,
            s"[ATT_GET] '$dbName', retrieving attachment '$name' of document '$doc'; not found.")
          throw NoDocumentException("Not found on 'readAttachment'.")

        case Left(code) =>
          transid.failed(
            this,
            start,
            s"[ATT_GET] '$dbName' failed to get attachment '$name' of document '$doc'; http status: '${code}'")
          throw new Exception("Unexpected http response code: " + code)
      }
    }

    reportFailure(
      g,
      failure =>
        transid.failed(
          this,
          start,
          s"[ATT_GET] '$dbName' internal error, name: '$name', doc: '$doc', failure: '${failure.getMessage}'",
          ErrorLevel))
  }

  override def shutdown(): Unit = {
    Await.ready(client.shutdown(), 1.minute)
  }

  private def reportFailure[T, U](f: Future[T], onFailure: Throwable => U): Future[T] = {
    f.onFailure({
      case _: ArtifactStoreException => // These failures are intentional and shouldn't trigger the catcher.
      case x                         => onFailure(x)
    })
    f
  }
}


text:
Fast Json reader/writer

## How to use it

### Read json file
```cpp
#include "JsonStthm.h"

JsonStthm::JsonValue oJson;
oJson.ReadFile("data.json");

// Or (faster but read only)
JsonStthm::JsonDoc oJson;
oJson.ReadFile("data.json");
```

### Create json
```cpp
#include "JsonStthm.h"

JsonStthm::JsonValue oValue;
JsonStthm::JsonValue& oArray = oValue["myArray"];
oArray[0] = "test";
oArray[1] = false;
oArray[2] = 3.14159265359f;

JsonStthm::String sOut;
oValue.WriteString(sOut);
```
Content of **sOut**
```json
{
	"myArray": [
		"test",
		false,
		3.1415927410125732
	]
}
```

redpajama_set_name: RedPajamaGithub


text:
package com.github.novamage.svalidator.binding

import com.github.novamage.svalidator.validation.{Localizer, MessageParts}

/** Contains information of errors for fields during binding
  *
  * @param fieldName Name of the field that caused the error
  * @param messageParts Error message information for the field
  */
sealed case class FieldError(fieldName: String, messageParts: MessageParts) {

  /** Returns the message key of this object's [[com.github.novamage.svalidator.validation.MessageParts MessageParts]]
    * formatted alongside the format values using [[scala.collection.immutable.StringLike#format StringLike.format]]'s method.
    */
  def message: String = messageParts.messageKey.format(messageParts.messageFormatValues: _*)

  /** Returns a field error with localized messageParts generated passing the given localizer to
    * [[com.github.novamage.svalidator.validation.MessageParts#localize MessageParts.localize]]'s method.
    *
    * @param localizer Localizer to apply to the [[com.github.novamage.svalidator.validation.MessageParts MessageParts]]
    */
  def localize(implicit localizer: Localizer): FieldError = {
    FieldError(fieldName, messageParts.localize)
  }

}

/** Contains helper methods for alternate ways of building a [[com.github.novamage.svalidator.binding.FieldError FieldError]]
  */
object FieldError {

  /** Returns a field error with the given field name and message without formatting arguments
    */
  def apply(fieldName: String, message: String): FieldError = FieldError(fieldName, MessageParts(message))

}


text:
\documentclass{beamer}
\usepackage{color,amsmath}
\usepackage{subfigure}
\usepackage{booktabs}
\usepackage{framed}
\usepackage{comment}

\def\vf{\vfill}

%%%%%%%%%%%%%%%%%%%%%%%%%%
\title[]{Ethics}
\author[]{Matthew J. Salganik\\Department of Sociology\\Princeton University}
\date[]{Summer Institute in Computational Social Science\\June 19, 2017
\vfill
\begin{flushright}
\vspace{0.6in}
\includegraphics[width=0.1\textwidth]{figures/cc-by.png}
\end{flushright}
}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\frame{\titlepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\LARGE{Why care about ethics?}
\end{center}
\pause
\begin{itemize}
\item fear-based reasons
\pause
\item hope-based reasons
\pause
\item we have no choice
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

In the past, what we \textbf{could} do has been the limitation, increasingly what we \textbf{should} do will be the limitation.\\
Research ethics will become increasingly central; it will become harder and harder to avoid.\\

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

I want you to be able to:
\begin{itemize}
\item design ethically thoughtful research
\item explain your decisions to others
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

A note on lectures and readings:\\
For today, I'm going to repeat some of what is in my book, but going forward, I will assume that you've read the chapter.

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Three approaches:
\begin{itemize}
\item Rules-based approach
\pause
\item Ad hoc approach
\pause
\item Principles-based approach
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Examples:
\begin{itemize}
\item Emotional contagion
\pause
\item Tastes, Ties, and Time
\pause
\item Encore
\pause
\item Think-pair-share other examples?
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

What's the problem?
\begin{itemize}
\item increasing power
\pause
\item inconsistent and overlapping rules, norms, and expectations
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\includegraphics[width=0.9\textwidth]{figures/ethics_schematic_simple.png}
\end{center}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Respect for persons
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Respect for persons:\\
Participants decide not you

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Respect for persons
\item Beneficence
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Beneficence:\\
Minimize risk, maximize benefits, then decide

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Respect for persons
\item Beneficence
\item Justice
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Justice:\\
distribution of burdens and benefits of research
\pause
\begin{itemize}
\item poorly education and disenfranchised citizens
\item prisoners
\item institutionalized and mentally disabled children
\item old and debilitated hospital patients
\end{itemize}
\pause
Also includes access to benefits of research

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Respect for persons
\item Beneficence
\item Justice
\item Respect for Law and Public Interest
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Respect for Law and Public Interest:\\
\begin{itemize}
\item compliance
\item transparency-based accountability
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Terms-of-service agreements

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\includegraphics[width=0.9\textwidth]{figures/soeller_mapwatch_2016_title.png}
\end{center}

\vf
\url{http://dx.doi.org/10.1145/2872427.2883016}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Abstract:\\
``Maps have long played a crucial role in enabling people to conceptualize and navigate the world around them. However, maps also encode the world-views of their creators. Disputed international borders are one example of this: governments may mandate that cartographers produce maps that conform to their view of a territorial dispute. Today, online maps maintained by private corporations have become the norm. However, these new maps are still subject to old debates. Companies like Google and Bing resolve these disputes by localizing their maps to meet government requirements and user preferences, i.e., users in different locations are shown maps with different international boundaries. We argue that this non-transparent personalization of maps may exacerbate nationalistic disputes by promoting divergent views of geopolitical realities.''

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Abstract, part 2:\\
``To address this problem, we present MapWatch, our system for detecting and cataloging personalization of international borders in online maps. Our system continuously crawls all map tiles from Google and Bing maps, and leverages crowdworkers to identify border personalization. In this paper, we present the architecture of MapWatch, and analyze the instances of border personalization on Google and Bing, including one border change that MapWatch identified live, as Google was rolling out the update.''

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\includegraphics[width=\textwidth]{figures/soeller_mapwatch_2016_fig5.png}
\end{center}

\vf
\url{http://dx.doi.org/10.1145/2872427.2883016}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\includegraphics[width=\textwidth]{figures/soeller_mapwatch_2016_ethics.png}
\end{center}

\vf
\url{http://dx.doi.org/10.1145/2872427.2883016}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Researchers (with the support of the ACLU) have filed a case challenging the CFAA, Sandivg v Lynch:\\
\tiny{\textcolor{blue}{\url{https://www.aclu.org/cases/sandvig-v-lynch-challenge-cfaa-prohibition-uncovering-racial-discrimination-online}}}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Respect for persons
\item Beneficence
\item Justice
\item Respect for Law and Public Interest
\end{itemize}

\vf
How do you balance these four principles?

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{itemize}
\item Consequentialism
\item Deontology
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} {Quick question}

In arguing against the Emotional Contagion experiment (Kleinsman and Buckley, 2015) wrote:
\begin{quote}
``Even if it is true that the risks for the Facebook experiment were low and even if, in hindsight, the results are judged to be useful, there is an important principle at stake here that must be upheld.  In the same way that stealing is stealing no matter what amounts are involved, so we all have a right not to be experimented on without our knowledge and consent, whatever the nature of the research.''
\end{quote}
This argument is rooted in which ethical framework?
\begin{enumerate}
\item Consequentialism
\item Deontology
\end{enumerate}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{center}
\includegraphics[width=0.9\textwidth]{figures/ethics_schematic_simple.png}
\end{center}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Applying these ideas can be tricky, and there are 4 areas of particular difficulty

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


text:
package build

import (
	"archive/tar"
	"bytes"
	"context"
	"encoding/json"
	"io"
	"io/ioutil"
	"strings"
	"testing"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/filters"
	"github.com/docker/docker/integration-cli/cli/build/fakecontext"
	"github.com/docker/docker/integration/util/request"
	"github.com/docker/docker/pkg/jsonmessage"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestBuildWithRemoveAndForceRemove(t *testing.T) {
	defer setupTest(t)()
	t.Parallel()
	cases := []struct {
		name                           string
		dockerfile                     string
		numberOfIntermediateContainers int
		rm                             bool
		forceRm                        bool
	}{
		{
			name: "successful build with no removal",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 0`,
			numberOfIntermediateContainers: 2,
			rm:      false,
			forceRm: false,
		},
		{
			name: "successful build with remove",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 0`,
			numberOfIntermediateContainers: 0,
			rm:      true,
			forceRm: false,
		},
		{
			name: "successful build with remove and force remove",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 0`,
			numberOfIntermediateContainers: 0,
			rm:      true,
			forceRm: true,
		},
		{
			name: "failed build with no removal",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 1`,
			numberOfIntermediateContainers: 2,
			rm:      false,
			forceRm: false,
		},
		{
			name: "failed build with remove",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 1`,
			numberOfIntermediateContainers: 1,
			rm:      true,
			forceRm: false,
		},
		{
			name: "failed build with remove and force remove",
			dockerfile: `FROM busybox
			RUN exit 0
			RUN exit 1`,
			numberOfIntermediateContainers: 0,
			rm:      true,
			forceRm: true,
		},
	}

	client := request.NewAPIClient(t)
	ctx := context.Background()
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			t.Parallel()
			dockerfile := []byte(c.dockerfile)

			buff := bytes.NewBuffer(nil)
			tw := tar.NewWriter(buff)
			require.NoError(t, tw.WriteHeader(&tar.Header{
				Name: "Dockerfile",
				Size: int64(len(dockerfile)),
			}))
			_, err := tw.Write(dockerfile)
			require.NoError(t, err)
			require.NoError(t, tw.Close())
			resp, err := client.ImageBuild(ctx, buff, types.ImageBuildOptions{Remove: c.rm, ForceRemove: c.forceRm, NoCache: true})
			require.NoError(t, err)
			defer resp.Body.Close()
			filter, err := buildContainerIdsFilter(resp.Body)
			require.NoError(t, err)
			remainingContainers, err := client.ContainerList(ctx, types.ContainerListOptions{Filters: filter, All: true})
			require.NoError(t, err)
			require.Equal(t, c.numberOfIntermediateContainers, len(remainingContainers), "Expected %v remaining intermediate containers, got %v", c.numberOfIntermediateContainers, len(remainingContainers))
		})
	}
}

func buildContainerIdsFilter(buildOutput io.Reader) (filters.Args, error) {
	const intermediateContainerPrefix = " ---> Running in "
	filter := filters.NewArgs()

	dec := json.NewDecoder(buildOutput)
	for {
		m := jsonmessage.JSONMessage{}
		err := dec.Decode(&m)
		if err == io.EOF {
			return filter, nil
		}
		if err != nil {
			return filter, err
		}
		if ix := strings.Index(m.Stream, intermediateContainerPrefix); ix != -1 {
			filter.Add("id", strings.TrimSpace(m.Stream[ix+len(intermediateContainerPrefix):]))
		}
	}
}

func TestBuildMultiStageParentConfig(t *testing.T) {
	dockerfile := `
		FROM busybox AS stage0
		ENV WHO=parent
		WORKDIR /foo

		FROM stage0
		ENV WHO=sibling1
		WORKDIR sub1

		FROM stage0
		WORKDIR sub2
	`
	ctx := context.Background()
	source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
	defer source.Close()

	apiclient := testEnv.APIClient()
	resp, err := apiclient.ImageBuild(ctx,
		source.AsTarReader(t),
		types.ImageBuildOptions{
			Remove:      true,
			ForceRemove: true,
			Tags:        []string{"build1"},
		})
	require.NoError(t, err)
	_, err = io.Copy(ioutil.Discard, resp.Body)
	resp.Body.Close()
	require.NoError(t, err)

	image, _, err := apiclient.ImageInspectWithRaw(ctx, "build1")
	require.NoError(t, err)

	assert.Equal(t, "/foo/sub2", image.Config.WorkingDir)
	assert.Contains(t, image.Config.Env, "WHO=parent")
}

func TestBuildWithEmptyLayers(t *testing.T) {
	dockerfile := `
		FROM    busybox
		COPY    1/ /target/
		COPY    2/ /target/
		COPY    3/ /target/
	`
	ctx := context.Background()
	source := fakecontext.New(t, "",
		fakecontext.WithDockerfile(dockerfile),
		fakecontext.WithFile("1/a", "asdf"),
		fakecontext.WithFile("2/a", "asdf"),
		fakecontext.WithFile("3/a", "asdf"))
	defer source.Close()

	apiclient := testEnv.APIClient()
	resp, err := apiclient.ImageBuild(ctx,
		source.AsTarReader(t),
		types.ImageBuildOptions{
			Remove:      true,
			ForceRemove: true,
		})
	require.NoError(t, err)
	_, err = io.Copy(ioutil.Discard, resp.Body)
	resp.Body.Close()
	require.NoError(t, err)
}


text:
use ruma_events_macros::MessageEventContent;
use serde::{Deserialize, Serialize};

use crate::{room::ImageInfo, MessageEvent};

/// A sticker message.
pub type StickerEvent = MessageEvent<StickerEventContent>;

/// The payload for `StickerEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, MessageEventContent)]
#[ruma_event(type = "m.sticker")]
pub struct StickerEventContent {
    /// A textual representation or associated description of the sticker image. This could
    /// be the alt text of the original image, or a message to accompany and further
    /// describe the sticker.
    pub body: String,

    /// Metadata about the image referred to in `url` including a thumbnail representation.
    pub info: ImageInfo,

    /// The URL to the sticker image. This must be a valid `mxc://` URI.
    pub url: String,
}


text:
namespace mus {

ViewTreeHostConnection::ViewTreeHostConnection(
    scoped_ptr<ViewTreeHostImpl> host_impl,
    ConnectionManager* manager)
    : host_(host_impl.Pass()),
      tree_(nullptr),
      connection_manager_(manager),
      connection_closed_(false) {}

ViewTreeHostConnection::~ViewTreeHostConnection() {
  // If this DCHECK fails then something has tried to delete this object without
  // calling CloseConnection.
  DCHECK(connection_closed_);
}

void ViewTreeHostConnection::CloseConnection() {
  // A connection error will trigger the display to close and so we want to make
  // sure we signal the ConnectionManager only once.
  if (connection_closed_)
    return;
  // We have to shut down the focus system for this host before destroying the
  // host, as destruction of the view tree will attempt to change focus.
  host_->DestroyFocusController();
  connection_manager()->OnHostConnectionClosed(this);
  connection_closed_ = true;
  delete this;
}

ViewTreeImpl* ViewTreeHostConnection::GetViewTree() {
  return tree_;
}

void ViewTreeHostConnection::OnDisplayInitialized() {}

void ViewTreeHostConnection::OnDisplayClosed() {
  CloseConnection();
}

ViewTreeHostConnectionImpl::ViewTreeHostConnectionImpl(
    mojo::InterfaceRequest<mojo::ViewTreeHost> request,
    scoped_ptr<ViewTreeHostImpl> host_impl,
    mojo::ViewTreeClientPtr client,
    ConnectionManager* manager)
    : ViewTreeHostConnection(host_impl.Pass(), manager),
      binding_(view_tree_host(), request.Pass()),
      client_(client.Pass()) {}

ViewTreeHostConnectionImpl::~ViewTreeHostConnectionImpl() {}

void ViewTreeHostConnectionImpl::OnDisplayInitialized() {
  connection_manager()->AddHost(this);
  set_view_tree(connection_manager()->EmbedAtView(
      kInvalidConnectionId, view_tree_host()->root_view()->id(),
      mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT, client_.Pass()));
}

}  // namespace mus


text:
import React from 'react';
import { mount } from 'enzyme';

import { Documents } from '../Documents';
import { doc, directory } from './fixtures';

function setup(documents = [directory, doc]) {
  const actions = {
    fetchCollection: jest.fn(),
    deleteDocument: jest.fn(),
    search: jest.fn(),
  };

  const props = {
    documents,
    params: { collection_name: 'movies', splat: 'test' },
    isFetching: false,
  };

  const component = mount(<Documents {...actions} {...props} />);

  return {
    actions,
    component,
    h1: component.find('h1').last(),
    breadcrumbs: component.find('.breadcrumbs'),
    new_button: component.find('.page-buttons a').first(),
    row_title: component.find('strong a'),
    table: component.find('.content-table'),
    deleteButton: component.find('.btn-delete'),
  };
}

describe('Containers::Documents', () => {
  it('should render correctly', () => {
    const { component, breadcrumbs, new_button } = setup();
    expect(breadcrumbs.node).toBeTruthy();
    expect(new_button.text()).toBe('New document');
    component.setProps({ params: { collection_name: 'posts' } });
    expect(new_button.text()).toBe('New post');
  });

  it('should render correctly when there are not any documents', () => {
    const { table, h1 } = setup([]);
    expect(table.node).toBeFalsy();
    expect(h1.text()).toBe(`No documents found.`);
  });

  it('should not render elements when isFetching', () => {
    const { component } = setup();
    component.setProps({ isFetching: true, params: { splat: '' } });
    expect(component.find('.content-header').node).toBeFalsy();
  });

  it('should show filename if title is empty', () => {
    const { row_title } = setup([
      {
        ...doc,
        title: '',
      },
    ]);
    expect(row_title.text()).toBe(doc.name);
  });

  it('should call fetchDocuments action after mounted', () => {
    const { actions } = setup();
    expect(actions.fetchCollection).toHaveBeenCalled();
  });

  it('should fetch documents again when params change', () => {
    const { component, actions } = setup();
    component.setProps({
      params: { collection_name: 'movies', splat: 'test' },
    });
    expect(actions.fetchCollection.mock.calls.length).toBe(1);

    component.setProps({
      params: { collection_name: 'puppies', splat: 'test' },
    });
    expect(actions.fetchCollection.mock.calls.length).toBe(2);
  });

  it('should call deleteDocument', () => {
    const { component, actions } = setup();
    component.find('.btn-delete').simulate('click');
    expect(actions.deleteDocument.mock.calls.length).toBe(1);
  });
});


text:
<?php

namespace app\models;

use Yii;
use yii\web\IdentityInterface;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $id
 * @property string $username
 * @property string $email
 * @property string $password_hash
 * @property integer $status
 * @property string $auth_key
 * @property integer $created_at
 * @property integer $updated_at
 */
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
    const STATUS_DELETED = 0;
    const STATUS_NOT_ACTIVE = 1;
    const STATUS_ACTIVE = 10;

    public $password;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'email', 'password'], 'filter', 'filter' => 'trim'],
            [['username', 'email', 'status'], 'required'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['username'], 'string', 'min' => 2, 'max' => 255],
            ['password', 'required', 'on' => 'create'],
            ['email', 'email'],
            ['username', 'unique', 'message' => 'Это имя занято'],
            ['email', 'unique', 'message' => 'Эта почта уже зарегистрирована'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => 'Имя',
            'email' => 'Почта',
            'password_hash' => 'Пароль',
            'status' => 'Статус',
            'auth_key' => 'Ключ',
            'created_at' => 'Дата создания',
            'updated_at' => 'Дата изменения',
        ];
    }
    /* Поведение */

    public function behaviors(){
      return  [
            TimestampBehavior::className()
        ];
    }
    /* Поиск */

    public static function  findByUsername($username){
        return static::findOne([
            'username' => $username
        ]);
    }
    /*Хелперы*/

    public function setPassword($password)
    {
        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
    }
    public function generateAuthKey()
    {
        $this->auth_key = Yii::$app->security->generateRandomString();
    }
    public function validatePassword($password)
    {
        return Yii::$app->security->validatePassword($password, $this->password_hash);
    }
     /*Аутентификация пользователя*/

    public static function findIdentity($id)
    {
        return static::findOne([
            'id' => $id,
            'status' => self::STATUS_ACTIVE
        ]);
    }

    public static function findIdentityByAccessToken($token, $type = null)
    {
        return static::findOne(['access_token' => $token]);
    }

    public function getId()
    {
        return $this->id;
    }

    public function getAuthKey()
    {
        return $this->auth_key;
    }

    public function validateAuthKey($authKey)
    {
        return $this->auth_key === $authKey;
    }

}


text:
package com.facebook.buck.swift;

public class SwiftUtil {

  /** Utility class: do not instantiate. */
  private SwiftUtil() { }

  public static class Constants {

    /** Utility class: do not instantiate. */
    private Constants() { }

    static final String SWIFT_HEADER_SUFFIX = "-Swift";
    static final String SWIFT_MAIN_FILENAME = "main.swift";
    public static final String SWIFT_EXTENSION = "swift";
  }

  static String toSwiftHeaderName(String moduleName) {
    return moduleName + Constants.SWIFT_HEADER_SUFFIX;
  }

  static String normalizeSwiftModuleName(String moduleName) {
    return moduleName.replaceAll("[^A-Za-z0-9]", "_");
  }
}


text: Used for notification of default parser.


text:
"""
"""
from .datasets import Dataset;
from.mnist import get_mnist_data;

__all__ = ['get_mnist_data', 'Dataset'];


text:
package com.github.eirslett.maven.plugins.frontend.lib;

import java.io.File;

public interface NodeExecutorConfig {
  File getNodePath();
  File getNpmPath();
  File getWorkingDirectory();
  Platform getPlatform();
}

final class InstallNodeExecutorConfig implements NodeExecutorConfig {

  private static final String NODE_WINDOWS = "\\node\\node.exe";
  private static final String NODE_DEFAULT = "/node/node";
  private static final String NPM = "/node/node_modules/npm/bin/npm-cli.js";

  private final InstallConfig installConfig;

  public InstallNodeExecutorConfig(InstallConfig installConfig) {
    this.installConfig = installConfig;
  }

  @Override
  public File getNodePath() {
    String nodeExecutable = getPlatform().isWindows() ? NODE_WINDOWS : NODE_DEFAULT;
    return new File(installConfig.getInstallDirectory() + nodeExecutable);
  }

  @Override
  public File getNpmPath() {
    return new File(installConfig.getInstallDirectory() + Utils.normalize(NPM));
  }

  @Override
  public File getWorkingDirectory() {
    return installConfig.getWorkingDirectory();
  }

  @Override
  public Platform getPlatform() {
    return installConfig.getPlatform();
  }
}


text:
//
//  CMHeadView.h
//  CMKit
//
//  Created by HC on 16/11/17.
//  Copyright © 2016年 UTOUU. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CMHeadView : UITableViewHeaderFooterView

@property (nonatomic, copy) NSString *titleStr;

@property (nonatomic, assign) CGFloat hight;

/** 创建HeadView */
+ (instancetype)headView;

@end


text:
var mdgram=require("../mdgram");

var socket=mdgram.createSocket("udp4");
function send() {
	var msg = new Buffer(JSON.stringify(new Date()));
	socket.send(msg,0,msg.length,1811,"225.0.0.73");
};
setInterval(send,1000);


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>main.java.positionalIndex</title>
<meta name="date" content="2015-02-21">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">

main.java.positionalIndex

Interfaces

PositionalIndex

Classes

DiskPositionalIndex

InMemoryPositionalIndex

LogarithmicEngine


text:
import itertools
import logging
from typing import cast

from pants.backend.python.dependency_inference import import_parser, module_mapper
from pants.backend.python.dependency_inference.import_parser import (
    ParsedPythonImports,
    ParsePythonImportsRequest,
)
from pants.backend.python.dependency_inference.module_mapper import PythonModule, PythonModuleOwners
from pants.backend.python.target_types import PythonSourceField, PythonTestSourceField
from pants.backend.python.util_rules import ancestor_files, pex
from pants.backend.python.util_rules.ancestor_files import AncestorFiles, AncestorFilesRequest
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
from pants.core.util_rules import stripped_source_files
from pants.engine.addresses import Address
from pants.engine.internals.graph import Owners, OwnersRequest
from pants.engine.rules import Get, MultiGet, SubsystemRule, rule
from pants.engine.target import (
    Dependencies,
    DependenciesRequest,
    ExplicitlyProvidedDependencies,
    HydratedSources,
    HydrateSourcesRequest,
    InferDependenciesRequest,
    InferredDependencies,
    WrappedTarget,
)
from pants.engine.unions import UnionRule
from pants.option.global_options import OwnersNotFoundBehavior
from pants.option.subsystem import Subsystem
from pants.python.python_setup import PythonSetup

logger = logging.getLogger(__name__)

class PythonInferSubsystem(Subsystem):
    options_scope = "python-infer"
    help = "Options controlling which dependencies will be inferred for Python targets."

    @classmethod
    def register_options(cls, register):
        super().register_options(register)
        register(
            "--imports",
            default=True,
            type=bool,
            help=(
                "Infer a target's imported dependencies by parsing import statements from sources."
            ),
        )
        register(
            "--string-imports",
            default=False,
            type=bool,
            help=(
                "Infer a target's dependencies based on strings that look like dynamic "
                "dependencies, such as Django settings files expressing dependencies as strings. "
                "To ignore any false positives, put `!{bad_address}` in the `dependencies` field "
                "of your target."
            ),
        )
        register(
            "--string-imports-min-dots",
            default=2,
            type=int,
            help=(
                "If --string-imports is True, treat valid-looking strings with at least this many "
                "dots in them as potential dynamic dependencies. E.g., `'foo.bar.Baz'` will be "
                "treated as a potential dependency if this option is set to 2 but not if set to 3."
            ),
        )
        register(
            "--inits",
            default=False,
            type=bool,
            help=(
                "Infer a target's dependencies on any `__init__.py` files in the packages "
                "it is located in (recursively upward in the directory structure).\n\nEven if this "
                "is disabled, Pants will still include any ancestor `__init__.py` files, only they "
                "will not be 'proper' dependencies, e.g. they will not show up in "
                "`./pants dependencies` and their own dependencies will not be used.\n\nIf you "
                "have empty `__init__.py` files, it's safe to leave this option off; otherwise, "
                "you should enable this option."
            ),
        )
        register(
            "--conftests",
            default=True,
            type=bool,
            help=(
                "Infer a test target's dependencies on any conftest.py files in the current "
                "directory and ancestor directories."
            ),
        )
        register(
            "--entry-points",
            default=True,
            type=bool,
            help=(
                "Infer dependencies on targets' entry points, e.g. `pex_binary`'s "
                "`entry_point` field, `python_awslambda`'s `handler` field and "
                "`python_distribution`'s `entry_points` field."
            ),
        )

    @property
    def imports(self) -> bool:
        return cast(bool, self.options.imports)

    @property
    def string_imports(self) -> bool:
        return cast(bool, self.options.string_imports)

    @property
    def string_imports_min_dots(self) -> int:
        return cast(int, self.options.string_imports_min_dots)

    @property
    def inits(self) -> bool:
        return cast(bool, self.options.inits)

    @property
    def conftests(self) -> bool:
        return cast(bool, self.options.conftests)

    @property
    def entry_points(self) -> bool:
        return cast(bool, self.options.entry_points)

class InferPythonImportDependencies(InferDependenciesRequest):
    infer_from = PythonSourceField

@rule(desc="Inferring Python dependencies by analyzing imports")
async def infer_python_dependencies_via_imports(
    request: InferPythonImportDependencies,
    python_infer_subsystem: PythonInferSubsystem,
    python_setup: PythonSetup,
) -> InferredDependencies:
    if not python_infer_subsystem.imports:
        return InferredDependencies([])

    wrapped_tgt = await Get(WrappedTarget, Address, request.sources_field.address)
    explicitly_provided_deps, detected_imports = await MultiGet(
        Get(ExplicitlyProvidedDependencies, DependenciesRequest(wrapped_tgt.target[Dependencies])),
        Get(
            ParsedPythonImports,
            ParsePythonImportsRequest(
                cast(PythonSourceField, request.sources_field),
                InterpreterConstraints.create_from_targets([wrapped_tgt.target], python_setup),
                string_imports=python_infer_subsystem.string_imports,
                string_imports_min_dots=python_infer_subsystem.string_imports_min_dots,
            ),
        ),
    )

    owners_per_import = await MultiGet(
        Get(PythonModuleOwners, PythonModule(imported_module))
        for imported_module in detected_imports
    )
    merged_result: set[Address] = set()
    for owners, imp in zip(owners_per_import, detected_imports):
        merged_result.update(owners.unambiguous)
        address = wrapped_tgt.target.address
        explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
            owners.ambiguous,
            address,
            import_reference="module",
            context=f"The target {address} imports `{imp}`",
        )
        maybe_disambiguated = explicitly_provided_deps.disambiguated(owners.ambiguous)
        if maybe_disambiguated:
            merged_result.add(maybe_disambiguated)

    return InferredDependencies(sorted(merged_result))

class InferInitDependencies(InferDependenciesRequest):
    infer_from = PythonSourceField

@rule(desc="Inferring dependencies on `__init__.py` files")
async def infer_python_init_dependencies(
    request: InferInitDependencies, python_infer_subsystem: PythonInferSubsystem
) -> InferredDependencies:
    if not python_infer_subsystem.inits:
        return InferredDependencies([])

    # Locate __init__.py files not already in the Snapshot.
    hydrated_sources = await Get(HydratedSources, HydrateSourcesRequest(request.sources_field))
    extra_init_files = await Get(
        AncestorFiles,
        AncestorFilesRequest("__init__.py", hydrated_sources.snapshot),
    )

    # And add dependencies on their owners.
    # NB: Because the python_sources rules always locate __init__.py files, and will trigger an
    # error for files that have content but have not already been included via a dependency, we
    # don't need to error for unowned files here.
    owners = await MultiGet(
        Get(Owners, OwnersRequest((f,))) for f in extra_init_files.snapshot.files
    )
    return InferredDependencies(itertools.chain.from_iterable(owners))

class InferConftestDependencies(InferDependenciesRequest):
    infer_from = PythonTestSourceField

@rule(desc="Inferring dependencies on `conftest.py` files")
async def infer_python_conftest_dependencies(
    request: InferConftestDependencies,
    python_infer_subsystem: PythonInferSubsystem,
) -> InferredDependencies:
    if not python_infer_subsystem.conftests:
        return InferredDependencies([])

    # Locate conftest.py files not already in the Snapshot.
    hydrated_sources = await Get(HydratedSources, HydrateSourcesRequest(request.sources_field))
    extra_conftest_files = await Get(
        AncestorFiles,
        AncestorFilesRequest("conftest.py", hydrated_sources.snapshot),
    )

    # And add dependencies on their owners.
    # NB: Because conftest.py files effectively always have content, we require an owning target.
    owners = await MultiGet(
        Get(Owners, OwnersRequest((f,), OwnersNotFoundBehavior.error))
        for f in extra_conftest_files.snapshot.files
    )
    return InferredDependencies(itertools.chain.from_iterable(owners))

# This is a separate function to facilitate tests registering import inference.
def import_rules():
    return [
        infer_python_dependencies_via_imports,
        *pex.rules(),
        *import_parser.rules(),
        *module_mapper.rules(),
        *stripped_source_files.rules(),
        SubsystemRule(PythonInferSubsystem),
        SubsystemRule(PythonSetup),
        UnionRule(InferDependenciesRequest, InferPythonImportDependencies),
    ]

def rules():
    return [
        *import_rules(),
        infer_python_init_dependencies,
        infer_python_conftest_dependencies,
        *ancestor_files.rules(),
        UnionRule(InferDependenciesRequest, InferInitDependencies),
        UnionRule(InferDependenciesRequest, InferConftestDependencies),
    ]


text:
module Fog
  module StringifyKeys
    # Returns a new hash with all keys converted to strings.
    def self.stringify(original_hash)
      transform_hash(original_hash) do |hash, key, value|
        hash[key.to_s] = value
      end
    end

    private

    # http://devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/
    def self.transform_hash(original, &block)
      original.reduce({}) do |result, (key, value)|
        block.call(result, key, value)
        result
      end
    end
  end
end


text:
using static STULib.Types.Generic.Common;

namespace STULib.Types.Dump {
    [STU(0x1B93D61B)]
    public class STU_1B93D61B : STUStatescriptState {
        [STUField(0xC3E03C7F, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_C3E03C7F;

        [STUField(0xAF872E86, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_AF872E86;

        [STUField(0x1E8637CF, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_1E8637CF;

        [STUField(0x2D8ADFF8, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_2D8ADFF8;

        [STUField(0x2068FD7A, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_2068FD7A;

        [STUField(0xEC1A7839, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_EC1A7839;

        [STUField(0xAC183F7E, EmbeddedInstance = true)]
        public STULib.Types.STUConfigVar m_AC183F7E;
    }
}


text:
import os
from appdirs import AppDirs
import q2d2

def get_install_path():
    return os.path.abspath(os.path.split(__file__)[0])

data_dirs = AppDirs("q2d2", "biocore", version=q2d2.__version__)


text:
package e2e

import (
	"context"
	"os"
	"strings"
	"testing"
	"time"

	"github.com/coreos/etcd/clientv3"
)

func TestCtlV3Alarm(t *testing.T) {
	// The boltdb minimum working set is six pages.
	testCtl(t, alarmTest, withQuota(int64(13*os.Getpagesize())))
}

func alarmTest(cx ctlCtx) {
	// test small put still works
	smallbuf := strings.Repeat("a", 64)
	if err := ctlV3Put(cx, "1st_test", smallbuf, ""); err != nil {
		cx.t.Fatal(err)
	}

	// write some chunks to fill up the database
	buf := strings.Repeat("b", int(os.Getpagesize()))
	for {
		if err := ctlV3Put(cx, "2nd_test", buf, ""); err != nil {
			if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
				cx.t.Fatal(err)
			}
			break
		}
	}

	// quota alarm should now be on
	if err := ctlV3Alarm(cx, "list", "alarm:NOSPACE"); err != nil {
		cx.t.Fatal(err)
	}

	// '/health' handler should return 'false'
	if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"false"}`}); err != nil {
		cx.t.Fatalf("failed get with curl (%v)", err)
	}

	// check that Put is rejected when alarm is on
	if err := ctlV3Put(cx, "3rd_test", smallbuf, ""); err != nil {
		if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
			cx.t.Fatal(err)
		}
	}

	eps := cx.epc.EndpointsV3()

	// get latest revision to compact
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   eps,
		DialTimeout: 3 * time.Second,
	})
	if err != nil {
		cx.t.Fatal(err)
	}
	defer cli.Close()
	sresp, err := cli.Status(context.TODO(), eps[0])
	if err != nil {
		cx.t.Fatal(err)
	}

	// make some space
	if err := ctlV3Compact(cx, sresp.Header.Revision, true); err != nil {
		cx.t.Fatal(err)
	}
	if err := ctlV3Defrag(cx); err != nil {
		cx.t.Fatal(err)
	}

	// turn off alarm
	if err := ctlV3Alarm(cx, "disarm", "alarm:NOSPACE"); err != nil {
		cx.t.Fatal(err)
	}

	// put one more key below quota
	if err := ctlV3Put(cx, "4th_test", smallbuf, ""); err != nil {
		cx.t.Fatal(err)
	}
}

func ctlV3Alarm(cx ctlCtx, cmd string, as ...string) error {
	cmdArgs := append(cx.PrefixArgs(), "alarm", cmd)
	return spawnWithExpects(cmdArgs, as...)
}


text:
"""Utility for reading / writing command-line flag files on device(s)."""

from __future__ import print_function

import argparse
import logging
import sys

import devil_chromium

from devil.android import device_errors
from devil.android import device_utils
from devil.android import flag_changer
from devil.android.tools import script_common
from devil.utils import cmd_helper
from devil.utils import logging_common

def CheckBuildTypeSupportsFlags(device, command_line_flags_file):
  is_webview = command_line_flags_file == 'webview-command-line'
  if device.IsUserBuild() and is_webview:
    raise device_errors.CommandFailedError(
        'WebView only respects flags on a userdebug or eng device, yours '
        'is a user build.', device)
  if device.IsUserBuild():
    logging.warning(
        'Your device (%s) is a user build; Chrome may or may not pick up '
        'your commandline flags. Check your '
        '"command_line_on_non_rooted_enabled" preference, or switch '
        'devices.', device)

def main():
  parser = argparse.ArgumentParser(description=__doc__)
  parser.usage = '''%(prog)s --name FILENAME [--device SERIAL] [flags...]

No flags: Prints existing command-line file.
Empty string: Deletes command-line file.
Otherwise: Writes command-line file.

'''
  parser.add_argument('--name', required=True,
                      help='Name of file where to store flags on the device.')
  parser.add_argument('-e', '--executable', dest='executable', default='chrome',
                      help='(deprecated) No longer used.')
  script_common.AddEnvironmentArguments(parser)
  script_common.AddDeviceArguments(parser)
  logging_common.AddLoggingArguments(parser)

  args, remote_args = parser.parse_known_args()
  devil_chromium.Initialize(adb_path=args.adb_path)
  logging_common.InitializeLogging(args)

  devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices,
                                                    default_retries=0)
  all_devices = device_utils.DeviceUtils.parallel(devices)

  if not remote_args:
    # No args == do not update, just print flags.
    remote_args = None
    action = ''
  elif len(remote_args) == 1 and not remote_args[0]:
    # Single empty string arg == delete flags
    remote_args = []
    action = 'Deleted command line file. '
  else:
    action = 'Wrote command line file. '

  def update_flags(device):
    CheckBuildTypeSupportsFlags(device, args.name)
    changer = flag_changer.FlagChanger(device, args.name)
    if remote_args is not None:
      flags = changer.ReplaceFlags(remote_args)
    else:
      flags = changer.GetCurrentFlags()
    return (device, device.build_description, flags)

  updated_values = all_devices.pMap(update_flags).pGet(None)

  print('%sCurrent flags (in %s):' % (action, args.name))
  for d, desc, flags in updated_values:
    if flags:
      # Shell-quote flags for easy copy/paste as new args on the terminal.
      quoted_flags = ' '.join(cmd_helper.SingleQuote(f) for f in sorted(flags))
    else:
      quoted_flags = '( empty )'
    print('  %s (%s): %s' % (d, desc, quoted_flags))

  return 0

if __name__ == '__main__':
  sys.exit(main())


text:
package org.jboss.aesh.extensions.text.highlight.scanner;

import org.jboss.aesh.extensions.text.highlight.Syntax;
import org.jboss.aesh.extensions.text.highlight.Syntax.Builder;
import org.jboss.aesh.extensions.text.highlight.TokenType;
import org.junit.Ignore;
import org.junit.Test;

import static org.jboss.aesh.extensions.text.highlight.encoder.AssertEncoder.assertTextToken;

public class HTMLScannerTestCase extends AbstractScannerTestCase {

    @Test
    @Ignore
    // simple developer test
    public void should() throws Exception {

        String source = "
#{q.answers.size.to_i} answers
";

        Syntax.Builder.create().scannerType(HTMLScanner.TYPE.getName()).encoderType(ASSERT_ENCODER).execute(source);

        assertTextToken(TokenType.tag, "<p");
        assertTextToken(TokenType.attribute_name, "style");
        assertTextToken(TokenType.key, "float");
        // assertTextToken(TokenType.tag, "", "", "<meta", "<title>", "", "<link", "


text:
<?php

namespace Spiral\Commands\Inspector;

use Spiral\Console\Command;
use Spiral\Models\Inspector;

/**
 * Provides inspection of ORM and ODM models to check unhidden fields, missed validations and etc.
 */
class InspectCommand extends Command
{
    /**
     * Visual constants.
     */
    const YES = 'yes';
    const NO = 'no';
    const RED_YES = '<fg=red>yes</fg=red>';
    const RED_NO = '<fg=red>no</fg=red>';
    const GREEN_YES = '<fg=green>yes</fg=green>';
    const GREEN_NO = '<fg=green>no</fg=green>';

    /**
     * Description for different rank levels, rank level multiplied by 100 in this table.
     *
     * @var array
     */
    protected $ranks = [
        0   => '<fg=red>Very Bad</fg=red>',
        25  => '<fg=red>Bad</fg=red>',
        50  => '<fg=yellow>Moderate</fg=yellow>',
        75  => '<fg=yellow>Good</fg=yellow>',
        100 => '<fg=green>Very Good</fg=green>'
    ];

    /**
     * {@inheritdoc}
     */
    protected $name = 'inspect';

    /**
     * {@inheritdoc}
     */
    protected $description = 'Inspect ORM and ODM models to locate unprotected field and rules.';

    /**
     * Perform command.
     */
    public function perform()
    {
        $inspector = $this->getInspector();

        if ($this->isVerbosing()) {
            $table = $this->tableHelper(['Entity', 'Rank', 'Fields', 'Fillable', 'Validated']);
            foreach ($inspector->getInspections() as $inspection) {
                $table->addRow([
                    $inspection->getName(),
                    $this->describeRank($inspection->getRank()),
                    $inspection->countFields(),
                    $inspection->countFillable(),
                    $inspection->countValidated()
                ]);
            }

            $table->render();
            $this->writeln("");
        }

        $this->writeln(interpolate(
            "Inspected entities <fg=yellow>{count}</fg=yellow>, average rank {level} ({rank}).",
            [
                'count' => number_format($inspector->countInspections()),
                'level' => $this->describeRank($inspector->getRank()),
                'rank'  => number_format($inspector->getRank(), 2)
            ]
        ));
    }

    /**
     * Get description for given rank value.
     *
     * @param float $rank
     * @return string
     */
    protected function describeRank($rank)
    {
        foreach (array_reverse($this->ranks, true) as $lowest => $message) {
            if ($rank * 100 >= $lowest) {
                return $message;
            }
        }

        return $this->ranks[0];
    }

    /**
     * Create instance of inspector associated with ORM and ODM entities.
     *
     * @return Inspector
     */
    protected function getInspector()
    {
        if ($this->container->hasBinding(\Spiral\ODM\Entities\SchemaBuilder::class)) {
            $odmBuilder = $this->container->get(\Spiral\ODM\Entities\SchemaBuilder::class);
        } else {
            $odmBuilder = $this->odm->schemaBuilder();
        }

        if ($this->container->hasBinding(\Spiral\ORM\Entities\SchemaBuilder::class)) {
            $ormBuilder = $this->container->get(\Spiral\ORM\Entities\SchemaBuilder::class);
        } else {
            $ormBuilder = $this->orm->schemaBuilder();
        }

        return $this->container->get(Inspector::class, [
            'entities' => array_merge(
                $odmBuilder->getDocuments(),
                $ormBuilder->getRecords()
            )
        ]);
    }
}


text:
<!DOCTYPE html>

  <meta charset="utf-8">
  <title>CSS Shape Test: float right, ellipse() reference</title>
  <link rel="author" title="Ting-Yu Lin" href="mailto:tlin@mozilla.com">
  <link rel="author" title="Mozilla" href="http://www.mozilla.org/">


text:
pep8 \
  setup.py \
  acme \
  letsencrypt \
  letsencrypt-apache \
  letsencrypt-nginx \
  letsencrypt-compatibility-test \
  letshelp-letsencrypt \
  || echo "PEP8 checking failed, but it's ignored in Travis"

# echo exits with 0


text:
package org.apache.hadoop.hbase.procedure;

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.DaemonThreadFactory;
import org.apache.hadoop.hbase.errorhandling.ForeignException;
import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher;

import com.google.common.collect.MapMaker;

/**
 * This is the master side of a distributed complex procedure execution.
 * <p>
 * The {@link Procedure} is generic and subclassing or customization shouldn't be
 * necessary -- any customization should happen just in {@link Subprocedure}s.
 */
@InterfaceAudience.Private
public class ProcedureCoordinator {
  private static final Log LOG = LogFactory.getLog(ProcedureCoordinator.class);

  final static long KEEP_ALIVE_MILLIS_DEFAULT = 5000;
  final static long TIMEOUT_MILLIS_DEFAULT = 60000;
  final static long WAKE_MILLIS_DEFAULT = 500;

  private final ProcedureCoordinatorRpcs rpcs;
  private final ExecutorService pool;
  private final long wakeTimeMillis;
  private final long timeoutMillis;

  // Running procedure table.  Maps procedure name to running procedure reference
  private final ConcurrentMap<String, Procedure> procedures =
      new MapMaker().concurrencyLevel(4).weakValues().makeMap();

  /**
   * Create and start a ProcedureCoordinator.
   *
   * The rpc object registers the ProcedureCoordinator and starts any threads in this
   * constructor.
   *
   * @param rpcs
   * @param pool Used for executing procedures.
   */
  public ProcedureCoordinator(ProcedureCoordinatorRpcs rpcs, ThreadPoolExecutor pool) {
    this(rpcs, pool, TIMEOUT_MILLIS_DEFAULT, WAKE_MILLIS_DEFAULT);
  }

  /**
   * Create and start a ProcedureCoordinator.
   *
   * The rpc object registers the ProcedureCoordinator and starts any threads in
   * this constructor.
   *
   * @param rpcs
   * @param pool Used for executing procedures.
   * @param timeoutMillis
   */
  public ProcedureCoordinator(ProcedureCoordinatorRpcs rpcs, ThreadPoolExecutor pool,
      long timeoutMillis, long wakeTimeMillis) {
    this.timeoutMillis = timeoutMillis;
    this.wakeTimeMillis = wakeTimeMillis;
    this.rpcs = rpcs;
    this.pool = pool;
    this.rpcs.start(this);
  }

  /**
   * Default thread pool for the procedure
   *
   * @param coordName
   * @param opThreads the maximum number of threads to allow in the pool
   */
  public static ThreadPoolExecutor defaultPool(String coordName, int opThreads) {
    return defaultPool(coordName, opThreads, KEEP_ALIVE_MILLIS_DEFAULT);
  }

  /**
   * Default thread pool for the procedure
   *
   * @param coordName
   * @param opThreads the maximum number of threads to allow in the pool
   * @param keepAliveMillis the maximum time (ms) that excess idle threads will wait for new tasks
   */
  public static ThreadPoolExecutor defaultPool(String coordName, int opThreads,
      long keepAliveMillis) {
    return new ThreadPoolExecutor(1, opThreads, keepAliveMillis, TimeUnit.MILLISECONDS,
        new SynchronousQueue<Runnable>(),
        new DaemonThreadFactory("(" + coordName + ")-proc-coordinator-pool"));
  }

  /**
   * Shutdown the thread pools and release rpc resources
   * @throws IOException
   */
  public void close() throws IOException {
    // have to use shutdown now to break any latch waiting
    pool.shutdownNow();
    rpcs.close();
  }

  /**
   * Submit an procedure to kick off its dependent subprocedures.
   * @param proc Procedure to execute
   * @return <tt>true</tt> if the procedure was started correctly, <tt>false</tt> if the
   *         procedure or any subprocedures could not be started.  Failure could be due to
   *         submitting a procedure multiple times (or one with the same name), or some sort
   *         of IO problem.  On errors, the procedure's monitor holds a reference to the exception
   *         that caused the failure.
   */
  boolean submitProcedure(Procedure proc) {
    // if the submitted procedure was null, then we don't want to run it
    if (proc == null) {
      return false;
    }
    String procName = proc.getName();

    // make sure we aren't already running a procedure of that name
    Procedure oldProc = procedures.get(procName);
    if (oldProc != null) {
      // procedures are always eventually completed on both successful and failed execution
      if (oldProc.completedLatch.getCount() != 0) {
        LOG.warn("Procedure " + procName + " currently running.  Rejecting new request");
        return false;
      } else {
        LOG.debug("Procedure " + procName
          + " was in running list but was completed.  Accepting new attempt.");
        if (!procedures.remove(procName, oldProc)) {
          LOG.warn("Procedure " + procName
            + " has been resubmitted by another thread. Rejecting this request.");
          return false;
        }
      }
    }

    // kick off the procedure's execution in a separate thread
    try {
      if (this.procedures.putIfAbsent(procName, proc) == null) {
        this.pool.submit(proc);
        return true;
      } else {
        LOG.error("Another thread has submitted procedure '" + procName + "'. Ignoring this attempt.");
        return false;
      }
    } catch (RejectedExecutionException e) {
      LOG.warn("Procedure " + procName + " rejected by execution pool.  Propagating error.", e);
      // Remove the procedure from the list since is not started
      this.procedures.remove(procName, proc);
      // the thread pool is full and we can't run the procedure
      proc.receive(new ForeignException(procName, e));
    }
    return false;
  }

  /**
   * The connection to the rest of the procedure group (members and coordinator) has been
   * broken/lost/failed. This should fail any interested procedures, but not attempt to notify other
   * members since we cannot reach them anymore.
   * @param message description of the error
   * @param cause the actual cause of the failure
   */
  void rpcConnectionFailure(final String message, final IOException cause) {
    Collection<Procedure> toNotify = procedures.values();

    for (Procedure proc : toNotify) {
      if (proc == null) {
        continue;
      }
      // notify the elements, if they aren't null
      proc.receive(new ForeignException(proc.getName(), cause));
    }
  }

  /**
   * Abort the procedure with the given name
   * @param procName name of the procedure to abort
   * @param reason serialized information about the abort
   */
  public void abortProcedure(String procName, ForeignException reason) {
    // if we know about the Procedure, notify it
    Procedure proc = procedures.get(procName);
    if (proc == null) {
      return;
    }
    proc.receive(reason);
  }

  /**
   * Exposed for hooking with unit tests.
   * @param procName
   * @param procArgs
   * @param expectedMembers
   * @return the newly created procedure
   */
  Procedure createProcedure(ForeignExceptionDispatcher fed, String procName, byte[] procArgs,
      List<String> expectedMembers) {
    // build the procedure
    return new Procedure(this, fed, wakeTimeMillis, timeoutMillis,
        procName, procArgs, expectedMembers);
  }

  /**
   * Kick off the named procedure
   * @param procName name of the procedure to start
   * @param procArgs arguments for the procedure
   * @param expectedMembers expected members to start
   * @return handle to the running procedure, if it was started correctly, <tt>null</tt> otherwise
   * @throws RejectedExecutionException if there are no more available threads to run the procedure
   */
  public Procedure startProcedure(ForeignExceptionDispatcher fed, String procName, byte[] procArgs,
      List<String> expectedMembers) throws RejectedExecutionException {
    Procedure proc = createProcedure(fed, procName, procArgs, expectedMembers);
    if (!this.submitProcedure(proc)) {
      LOG.error("Failed to submit procedure '" + procName + "'");
      return null;
    }
    return proc;
  }

  /**
   * Notification that the procedure had the specified member acquired its part of the barrier
   * via {@link Subprocedure#acquireBarrier()}.
   * @param procName name of the procedure that acquired
   * @param member name of the member that acquired
   */
  void memberAcquiredBarrier(String procName, final String member) {
    Procedure proc = procedures.get(procName);
    if (proc == null) {
      LOG.warn("Member '"+ member +"' is trying to acquire an unknown procedure '"+ procName +"'");
      return;
    }

    proc.barrierAcquiredByMember(member);
  }

  /**
   * Notification that the procedure had another member finished executing its in-barrier subproc
   * via {@link Subprocedure#insideBarrier()}.
   * @param procName name of the subprocedure that finished
   * @param member name of the member that executed and released its barrier
   */
  void memberFinishedBarrier(String procName, final String member) {
    Procedure proc = procedures.get(procName);
    if (proc == null) {
      LOG.warn("Member '"+ member +"' is trying to release an unknown procedure '"+ procName +"'");
      return;
    }
    proc.barrierReleasedByMember(member);
  }

  /**
   * @return the rpcs implementation for all current procedures
   */
  ProcedureCoordinatorRpcs getRpcs() {
    return rpcs;
  }

  /**
   * Returns the procedure.  This Procedure is a live instance so should not be modified but can
   * be inspected.
   * @param name Name of the procedure
   * @return Procedure or null if not present any more
   */
  public Procedure getProcedure(String name) {
    return procedures.get(name);
  }

  /**
   * @return Return set of all procedure names.
   */
  public Set<String> getProcedureNames() {
    return new HashSet<String>(procedures.keySet());
  }
}


text:
import * as React from 'react';
import Alert from '.';

interface ErrorBoundaryProps {
  message?: React.ReactNode;
  description?: React.ReactNode;
  children?: React.ReactNode;
}

export default class ErrorBoundary extends React.Component<
  ErrorBoundaryProps,
  {
    error?: Error | null;
    info: {
      componentStack?: string;
    };
  }
> {
  state = {
    error: undefined,
    info: {
      componentStack: '',
    },
  };

  componentDidCatch(error: Error | null, info: object) {
    this.setState({ error, info });
  }

  render() {
    const { message, description, children } = this.props;
    const { error, info } = this.state;
    const componentStack = info && info.componentStack ? info.componentStack : null;
    const errorMessage = typeof message === 'undefined' ? (error || '').toString() : message;
    const errorDescription = typeof description === 'undefined' ? componentStack : description;
    if (error) {
      return (
        <Alert type="error" message={errorMessage} description={<pre>{errorDescription}</pre>} />
      );
    }
    return children;
  }
}


text:
// ********************************************************************************************************
// Product Name: DotSpatial.Layout.Elements.LayoutLegend
// Description:  The Legend element for use in the DotSpatial Layout
//
// ********************************************************************************************************
//
// The Original Code is DotSpatial.dll Version 6.0
//
// The Initial Developer of this Original Code is Brian Marchionni. Created in Jul, 2009.
//
// Contributor(s): (Open source contributors should list themselves and their modifications here).
//
// ********************************************************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using DotSpatial.Symbology;

namespace DotSpatial.Controls
{
    /// <summary>
    /// Draws a legend for the layout
    /// </summary>
    public class LayoutLegend : LayoutElement
    {
        private readonly List<IMapLayer> _layers;
        private Color _color;
        private Font _font;
        private LayoutControl _layoutControl;
        private LayoutMap _layoutMap;
        private int _numCol;
        private TextRenderingHint _textHint;

        #region ------------------ Public Properties

        /// <summary>
        /// Gets or sets the layoutmap to use to base the legend on
        /// </summary>
        [Browsable(true), Category("Symbol"), Editor(typeof(LayoutMapEditor), typeof(UITypeEditor))]
        public virtual LayoutMap Map
        {
            get { return _layoutMap; }
            set
            {
                if (value != null && value != _layoutMap)
                {
                    _layoutMap = value;
                    _layers.Clear();
                    if (Map.MapControl != null)
                    {
                        foreach (IMapLayer t in Map.MapControl.Layers)
                        {
                            if (t.Checked)
                            {
                                _layers.Add(t);
                            }
                        }
                    }

                    base.UpdateThumbnail();
                    base.OnInvalidate();
                }
                else if (value == null)
                {
                    _layers.Clear();
                }
            }
        }

        /// <summary>
        /// Gets or sets the layers to include in the legend
        /// </summary>
        [Browsable(true), Category("Symbol"), Editor(typeof(LayoutLayerEditor), typeof(UITypeEditor))]
        public virtual List<int> Layers
        {
            get
            {
                if (Map == null || Map.MapControl == null)
                    return new List<int>();
                List<int> layerInts = new List<int>();
                for (int i = 0; i < Map.MapControl.Layers.Count; i++)
                    if (_layers.Contains(Map.MapControl.Layers[i])) layerInts.Add(i);
                return layerInts;
            }
            set
            {
                if (Map == null || Map.MapControl != null)
                {
                    _layers.Clear();
                    value.Sort();
                    value.Reverse();
                    foreach (int i in value)
                    {
                        if (i < Map.MapControl.Layers.Count)
                            _layers.Add(Map.MapControl.Layers[i]);
                    }
                }
                else
                {
                    _layers.Clear();
                }
                base.UpdateThumbnail();
                base.OnInvalidate();
            }
        }

        /// <summary>
        /// Gets or sets the font used to draw this text
        /// </summary>
        [Browsable(true), Category("Symbol")]
        public virtual Font Font
        {
            get { return _font; }
            set { _font = value; base.UpdateThumbnail(); base.OnInvalidate(); }
        }

        /// <summary>
        /// Gets or sets the color of the text
        /// </summary>
        [Browsable(true), Category("Symbol")]
        public virtual Color Color
        {
            get { return _color; }
            set { _color = value; base.UpdateThumbnail(); base.OnInvalidate(); }
        }

        /// <summary>
        /// Gets or sets the number of columns to use when rendering the legend
        /// </summary>
        [Browsable(true), Category("Symbol")]
        public virtual int NumColumns
        {
            get { return _numCol; }
            set
            {
                _numCol = value < 1 ? 1 : value;
                UpdateThumbnail();
                OnInvalidate();
            }
        }

        /// <summary>
        /// Gets or sets the hinting used to draw the text
        /// </summary>
        [Browsable(true), Category("Symbol")]
        public virtual TextRenderingHint TextHint
        {
            get { return _textHint; }
            set { _textHint = value; base.UpdateThumbnail(); base.OnInvalidate(); }
        }

        /// <summary>
        /// Gets or sets a layout control
        /// </summary>
        [Browsable(false)]
        public virtual LayoutControl LayoutControl
        {
            get { return _layoutControl; }
            set
            {
                if (_layoutControl != null)
                {
                    _layoutControl.ElementsChanged -= LayoutControlElementsChanged;
                }
                _layoutControl = value;
                if (_layoutControl != null)
                {
                    _layoutControl.ElementsChanged += LayoutControlElementsChanged;
                }
            }
        }

        #endregion

        #region ------------------- event handlers

        /// <summary>
        /// Updates the scale bar if the map is deleted
        /// </summary>
        private void LayoutControlElementsChanged(object sender, EventArgs e)
        {
            if (_layoutControl.LayoutElements.Contains(_layoutMap) == false)
                Map = null;
        }

        #endregion

        #region ------------------- public methods

        /// <summary>
        /// Constructor
        /// </summary>
        public LayoutLegend()
        {
            Name = "Legend";
            _font = new Font("Arial", 10);
            _color = Color.Black;
            _textHint = TextRenderingHint.AntiAliasGridFit;
            _numCol = 1;
            _layers = new List<IMapLayer>();
            ResizeStyle = ResizeStyle.NoScaling;
        }

        /// <summary>
        /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="printing">A boolean value indicating if the Draw code is being called to print</param>
        public override void Draw(Graphics g, bool printing)
        {
            //Make sure we don't get any null reference exceptions
            if (_layoutMap == null || _layoutMap.MapControl == null || _layoutMap.MapControl.Legend == null) return;

            //Makes sure that it is big enough to be drawn to
            if (Size.Width < 1 || Size.Height < 1) return;

            //Saves the old graphis settings
            TextRenderingHint oldTextHint = g.TextRenderingHint;
            g.TextRenderingHint = _textHint;
            Matrix oldTrans = g.Transform;

            //Calculates the size of each item and the max number of columns and rows
            SizeF itemSize = new SizeF(Size.Width / NumColumns, g.MeasureString("SampleText", _font).Height + 4);
            int maxCol = Convert.ToInt32(Size.Width / itemSize.Width);
            int maxRow = Convert.ToInt32(Math.Floor(Size.Height / itemSize.Height));
            int col = 0;
            int row = 0;

            //Loops through all of the legend items and populates the legend
            foreach (IMapLayer mapLayer in _layers)
            {
                if (mapLayer.LegendItems == null)
                    DrawLegendItem(g, mapLayer, itemSize, ref col, ref row, ref maxCol, ref maxRow);
                else
                    DrawLegendList(g, mapLayer.LegendItems, itemSize, ref col, ref row, ref maxCol, ref maxRow);
            }

            //Restored the old graphics settings
            g.Transform = oldTrans;
            g.TextRenderingHint = oldTextHint;
        }

        private void DrawLegendList(Graphics g, IEnumerable<ILegendItem> items, SizeF itemSize, ref int col, ref int row, ref int maxCol, ref int maxRow)
        {
            //If we are passed the max size return;
            if (col > maxCol)
                return;

            if (items == null || !items.Any()) return;
            List<ILegendItem> itemList = items.ToList();

            for (int i = itemList.Count - 1; i >= 0; i--)
            {
                if (itemList[i].LegendItems == null)
                {
                    DrawLegendItem(g, itemList[i], itemSize, ref col, ref row, ref maxCol, ref maxRow);
                }
                else
                    DrawLegendList(g, itemList[i].LegendItems, itemSize, ref col, ref row, ref maxCol, ref maxRow);
            }
        }

        private void DrawLegendItem(Graphics g, ILegendItem item, SizeF itemSize, ref int col, ref int row, ref int maxCol, ref int maxRow)
        {
            if (row >= maxRow)
            {
                row = 0;
                col++;
                if (col > maxCol)
                    return;
            }

            g.TranslateTransform(LocationF.X + (col * itemSize.Width), LocationF.Y + (row * itemSize.Height));
            item.PrintLegendItem(g, _font, _color, itemSize);
            g.TranslateTransform(-(LocationF.X + (col * itemSize.Width)), -(LocationF.Y + (row * itemSize.Height)));
            row++;
        }

        #endregion
    }
}


text:
package org.assertj.core.osgi;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import org.junit.jupiter.api.Test;

class SimpleTest {

  @Test
  void simple_success() {
    assertThat("A String").isNotNull()
                          .isNotEmpty()
                          .contains("A", "String")
                          .isEqualTo("A String");
  }

  @Test
  void simple_failure() {
    assertThatCode(() -> assertThat("A String").isNull()).isInstanceOf(AssertionError.class);
  }

}


text:
Simple wrapper for Graphite and Statsd

## Instructions

Check the `test` folder for examples, if you need more explanations please contact us.

## Installation

Add this line to your application's Gemfile:

    gem 'mini_graphite'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install mini_graphite

## Usage

### Config

    Dalia::MiniGraphite.config({
      :graphite_host => "my.graphite.server.com",
      :graphite_port => 2003, # default 2003
      :statsd_host => "my.statsd.server.com",
      :statsd_port => 8125, # default 8125
      :mock_mode => false, # default false
      :debug_mode => true # default false
    })

Also support multiple servers:

    Dalia::MiniGraphite.config({
      :graphite_host => ["my.graphite1.server.com", "my.graphite2.server.com"],
      :graphite_port => 2003, # default 2003
      :statsd_host => ["my.statsd1.server.com", "my.statsd2.server.com", "my.statsd3.server.com"],
      :statsd_port => 8125, # default 8125
      :mock_mode => false, # default false
      :debug_mode => true # default false
    })

### Simple signals

    Dalia::MiniGraphite.datapoint("my.key", 120, Time.now) # to Graphite
    Dalia::MiniGraphite.counter("my.key", 120) # to StatSD with `c` modifyer
    Dalia::MiniGraphite.time("my.key", 120) # to StatSD with `ms` modifyer

### Block wrapper benchmark

     # Dalia::MiniGraphite.benchmark_wrapper(key_prefix, result_send_method)
     result =
       Dalia::MiniGraphite.benchmark_wrapper("key_prefix", :length) do
         sleep(1)
         "RESULT"
       end

     puts result # => RESULT

This will send several signals:

- *key_prefix.ini:1|c*            # At the begining of the block
- *key_prefix.result:6|c*         # At the end of the block, send the block `result.send(result_send_method)`. Only if `result_send_method` paramater is present.
- *key_prefix.time:1000|c*        # At the end of the block, with the Benchmark.realtime result of the execution
- *key_prefix.end:1|c*            # At the end of the block
- *key_prefix.time_stats:1000|ms* # At the end of the block, with the Benchmark.realtime result of the execution

### Method wrapper benchmark

    # Dalia::MiniGraphite::MethodWrapper.mini_graphite_benchmark_method(method_name, key_prefix)
    class MyClass
      # Trigger the method wrapper in an instance method
      extend Dalia::MiniGraphite::MethodWrapper

      def my_instance_method
      end

      mini_graphite_benchmark_method(:my_instance_method, "key_name")

      # Trigger the method wrapper in a class method
      def self.my_class_method
      end

      class << self
        extend Dalia::MiniGraphite::MethodWrapper
        mini_graphite_benchmark_method(:my_class_method, "key_name")
      end
    end

This will send several signals:

- *key_prefix.time:1000|c*        # At the end of the method, with the Benchmark.realtime result of the execution
- *key_prefix.end:1|c*            # At the end of the method

### Routes reporter for Sinatra

The rack middleware must be added to the Rack chain in config.ru passing along with it a block with  config options:

- *set_graphite_key "graphite_key", /route_regexp/*   #  The regular expression will be used to match the Sinatra route and the corresponding graphite_key will be used to build the Graphite metrics:

- "[graphite\_key].count"           # The counter of the times a particular route is requested.
- "[graphite\_key].duration"        # The duration in milliseconds of each request/response cycle.
- "[graphite\_key].duration\_stats" # The duration in milliseconds of each request/response cycle in a "ms" metric

If the requested url doesn't match any configured regular expression the Graphite metrics will not be sent.

Example:

    # config.ru

    use Dalia::MiniGraphite::RoutesReporter do
      set_graphite_key "app.my_app.production.routes.active_surveys", /active_surveys\/this_should_be_a_password/
      set_graphite_key "app.my_app.production.routes.get_surveys", /\:offer_click_id\/\:panel_user_id\/\:panel_user_id_kind/
      set_graphite_key "app.my_app.production.routes.error", /error/
      set_graphite_key "app.my_app.production.routes.homepage", /\/$/
    end

    run MyApp::App

## Contributing

1. Fork it ( http://github.com/<my-github-username>/mini_graphite/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request