text:
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using OpenTK;
using OpenTKAnalyzer.Utility;

namespace OpenTKAnalyzer.OpenTK_
{
	[DiagnosticAnalyzer(LanguageNames.CSharp)]
	public class RotationValueOpenTKMathAnalyzer : DiagnosticAnalyzer
	{
		public const string DiagnosticId = "RotatinoValueOpenTKMath";

		private const string Title = "Rotation value(OpenTK Math)";
		private const string NotRadianMessageFormat = "{0} accepts radian value.";
		private const string NotDegreeMessageFormat = "{0} accepts degree value.";
		private const string Description = "Warm on literal in argument seems invalid style(radian or degree).";
		private const string Category = nameof(OpenTKAnalyzer) + ":" + nameof(OpenTK);

		internal static DiagnosticDescriptor NotRadianRule = new DiagnosticDescriptor(
			id: DiagnosticId,
			title: Title,
			messageFormat: NotRadianMessageFormat,
			category: Category,
			defaultSeverity: DiagnosticSeverity.Warning,
			isEnabledByDefault: true,
			description: Description);
		internal static DiagnosticDescriptor NotDegreeRule = new DiagnosticDescriptor(
			id: DiagnosticId,
			title: Title,
			messageFormat: NotDegreeMessageFormat,
			category: Category,
			defaultSeverity: DiagnosticSeverity.Info,
			isEnabledByDefault: true,
			description: Description);

		public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(NotRadianRule, NotDegreeRule);

		public override void Initialize(AnalysisContext context)
		{
			context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
		}

		private static void Analyze(SyntaxNodeAnalysisContext context)
		{
			var invocation = context.Node as InvocationExpressionSyntax;

			// no arguments method filter
			if (!invocation.ArgumentList.Arguments.Any())
			{
				return;
			}

			// MathHelper
			var baseName = invocation.GetFirstToken().ValueText;
			if (baseName == nameof(MathHelper))
			{
				// check method
				switch (invocation.Expression.GetLastToken().ValueText)
				{
					case nameof(MathHelper.DegreesToRadians):
						DegreeValueAnalyze(context, invocation, 0, nameof(MathHelper) + "." + nameof(MathHelper.DegreesToRadians));
						break;

					case nameof(MathHelper.RadiansToDegrees):
						RadianValueAnalyze(context, invocation, 0, nameof(MathHelper) + "." + nameof(MathHelper.RadiansToDegrees));
						break;
				}
				return;
			}

			// Matrix2, Matrix3x4 etc...
			if (baseName.StartsWith("Matrix"))
			{
				// check method
				var methodName = invocation.Expression.GetLastToken().ValueText;
				switch (methodName)
				{
					// Matrix? or Matrix?x$(? or $ is 2)
					case nameof(Matrix2.CreateRotation):
						RadianValueAnalyze(context, invocation, 0, baseName + "." + methodName);
						return;

					// Matrix? or Matrix?x$(? or $ is 3 or 4)
					case nameof(Matrix3.CreateFromAxisAngle):
					// Matrix4
					case nameof(Matrix4.Rotate):
						// number is in second argument
						RadianValueAnalyze(context, invocation, 1, baseName + "." + methodName);
						return;
				}

				// Matrix? or Matrix?x$ Matrix?d Matrix?x$d(? or $ is 3 or 4)
				// CreateRotationX, CreateRotationY, CreateRotationZ
				if (methodName.StartsWith("CreateRotation") ||
					// Matrix4
					// RotateX, RotateY, RotateZ
					methodName.StartsWith("Rotate"))
				{
					RadianValueAnalyze(context, invocation, 0, baseName + "." + methodName);
				}
				return;
			}

			// Quartanion, Quartaniond
			if (baseName.StartsWith(nameof(Quaternion)))
			{
				var methodName = invocation.Expression.GetLastToken().ValueText;
				if (methodName == nameof(Quaternion.FromAxisAngle))
				{
					// number is in second argument
					RadianValueAnalyze(context, invocation, 1, baseName + "." + nameof(Quaternion.FromAxisAngle));
				}
			}
		}

		private static void DegreeValueAnalyze(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation, int argumentIndex, string methodName)
		{
			double value;
			var argumentExpression = invocation.GetArgumentExpressionAt(argumentIndex);
			var result = context.SemanticModel.GetConstantValue(argumentExpression);
			if (double.TryParse(result.Value?.ToString(), out value))
			{
				// perhaps degree value under 2PI is incorrect
				if (Math.Abs(value) <= 2 * Math.PI)
				{
					context.ReportDiagnostic(Diagnostic.Create(
						descriptor: NotDegreeRule,
						location: argumentExpression.GetLocation(),
						messageArgs: methodName));
				}
			}
		}

		private static void RadianValueAnalyze(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation, int argumentIndex, string methodName)
		{
			double value;
			var argumentExpression = invocation.GetArgumentExpressionAt(argumentIndex);
			var result = context.SemanticModel.GetConstantValue(argumentExpression);
			if (double.TryParse(result.Value?.ToString(), out value))
			{
				// radian value usually under 2PI
				if (Math.Abs(value) >= 2 * Math.PI)
				{
					context.ReportDiagnostic(Diagnostic.Create(
						descriptor: NotRadianRule,
						location: argumentExpression.GetLocation(),
						messageArgs: methodName));
				}
			}
		}
	}
}


text: export NODENUM=1

redpajama_set_name: RedPajamaGithub


text:
/*
 * 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.
 */

package org.apache.hadoop.hive.llap.daemon.impl;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.JwtException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.common.UgiFactory;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.llap.DaemonId;
import org.apache.hadoop.hive.llap.LlapNodeId;
import org.apache.hadoop.hive.llap.LlapUtil;
import org.apache.hadoop.hive.llap.NotTezEventHelper;
import org.apache.hadoop.hive.llap.counters.WmFragmentCounters;
import org.apache.hadoop.hive.llap.daemon.ContainerRunner;
import org.apache.hadoop.hive.llap.daemon.FragmentCompletionHandler;
import org.apache.hadoop.hive.llap.daemon.HistoryLogger;
import org.apache.hadoop.hive.llap.daemon.KilledTaskHandler;
import org.apache.hadoop.hive.llap.daemon.QueryFailedHandler;
import org.apache.hadoop.hive.llap.daemon.SchedulerFragmentCompletingListener;
import org.apache.hadoop.hive.llap.daemon.impl.LlapTokenChecker.LlapTokenInfo;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.FragmentRuntimeInfo;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.GroupInputSpecProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.IOSpecProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.NotTezEvent;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.QueryCompleteRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.QueryCompleteResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.QueryIdentifierProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SignableVertexSpec;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SourceStateUpdatedRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SourceStateUpdatedResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SubmissionStateProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SubmitWorkRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SubmitWorkResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.RegisterDagRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.RegisterDagResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.TerminateFragmentRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.TerminateFragmentResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.UpdateFragmentRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.UpdateFragmentResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SetCapacityRequestProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.SetCapacityResponseProto;
import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos.VertexOrBinary;
import org.apache.hadoop.hive.llap.metrics.LlapDaemonExecutorMetrics;
import org.apache.hadoop.hive.llap.security.LlapExtClientJwtHelper;
import org.apache.hadoop.hive.llap.security.LlapSignerImpl;
import org.apache.hadoop.hive.llap.tez.Converters;
import org.apache.hadoop.hive.llap.tezplugins.LlapTezUtils;
import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.service.CompositeService;
import org.apache.hadoop.yarn.api.ApplicationConstants;
import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper;
import org.apache.log4j.NDC;
import org.apache.tez.common.security.JobTokenIdentifier;
import org.apache.tez.common.security.TokenCache;
import org.apache.tez.dag.api.TezConfiguration;
import org.apache.tez.dag.api.TezConstants;
import org.apache.tez.dag.records.TezTaskAttemptID;
import org.apache.tez.hadoop.shim.HadoopShim;
import org.apache.tez.hadoop.shim.HadoopShimsLoader;
import org.apache.tez.runtime.api.impl.ExecutionContextImpl;
import org.apache.tez.runtime.api.impl.TezEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

import javax.net.SocketFactory;

public class ContainerRunnerImpl extends CompositeService implements ContainerRunner, FragmentCompletionHandler, QueryFailedHandler {

  // TODO Setup a set of threads to process incoming requests.
  // Make sure requests for a single dag/query are handled by the same thread

  private static final Logger LOG = LoggerFactory.getLogger(ContainerRunnerImpl.class);
  public static final String THREAD_NAME_FORMAT_PREFIX = "ContainerExecutor ";

  private UgiPool ugiPool;
  private final AMReporter amReporter;
  private final QueryTracker queryTracker;
  private final Scheduler<TaskRunnerCallable> executorService;
  private final SchedulerFragmentCompletingListener completionListener;
  private final AtomicReference<InetSocketAddress> localAddress;
  private final AtomicReference<Integer> localShufflePort;
  private final Map<String, String> localEnv = new HashMap<>();
  private final long memoryPerExecutor;
  private final LlapDaemonExecutorMetrics metrics;
  private final TaskRunnerCallable.ConfParams confParams;
  private final KilledTaskHandler killedTaskHandler = new KilledTaskHandlerImpl();
  private final HadoopShim tezHadoopShim;
  private final LlapSignerImpl signer;
  private final String clusterId;
  private final DaemonId daemonId;
  private final UgiFactory fsUgiFactory;
  private final SocketFactory socketFactory;
  private final boolean execUseFQDN;

  public ContainerRunnerImpl(Configuration conf, int numExecutors, AtomicReference<Integer> localShufflePort,
      AtomicReference<InetSocketAddress> localAddress,
      long totalMemoryAvailableBytes, LlapDaemonExecutorMetrics metrics,
      AMReporter amReporter, QueryTracker queryTracker, Scheduler<TaskRunnerCallable> executorService,
      DaemonId daemonId, UgiFactory fsUgiFactory,
      SocketFactory socketFactory) {
    super("ContainerRunnerImpl");
    Preconditions.checkState(numExecutors > 0,
        "Invalid number of executors: " + numExecutors + ". Must be > 0");
    this.ugiPool = new UgiPool(numExecutors);
    this.localAddress = localAddress;
    this.localShufflePort = localShufflePort;
    this.amReporter = amReporter;
    this.signer = UserGroupInformation.isSecurityEnabled()
        ? new LlapSignerImpl(conf, daemonId.getClusterString()) : null;
    this.fsUgiFactory = fsUgiFactory;
    this.socketFactory = socketFactory;

    this.clusterId = daemonId.getClusterString();
    this.daemonId = daemonId;
    this.queryTracker = queryTracker;
    this.executorService = executorService;
    completionListener = (SchedulerFragmentCompletingListener) executorService;
    this.execUseFQDN = conf.getBoolean(HiveConf.ConfVars.LLAP_DAEMON_EXEC_USE_FQDN.varname, true);

    // Distribute the available memory between the tasks.
    this.memoryPerExecutor = (long)(totalMemoryAvailableBytes / (float) numExecutors);
    this.metrics = metrics;

    confParams = new TaskRunnerCallable.ConfParams(
        conf.getInt(TezConfiguration.TEZ_TASK_AM_HEARTBEAT_INTERVAL_MS,
            TezConfiguration.TEZ_TASK_AM_HEARTBEAT_INTERVAL_MS_DEFAULT),
        conf.getLong(
            TezConfiguration.TEZ_TASK_AM_HEARTBEAT_COUNTER_INTERVAL_MS,
            TezConfiguration.TEZ_TASK_AM_HEARTBEAT_COUNTER_INTERVAL_MS_DEFAULT),
        conf.getInt(TezConfiguration.TEZ_TASK_MAX_EVENTS_PER_HEARTBEAT,
            TezConfiguration.TEZ_TASK_MAX_EVENTS_PER_HEARTBEAT_DEFAULT)
    );
    tezHadoopShim = new HadoopShimsLoader(conf).getHadoopShim();

    LOG.info("ContainerRunnerImpl config: " +
            "memoryPerExecutorDerviced=" + memoryPerExecutor
    );
  }

  public void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);
  }

  @Override
  public void serviceStart() throws Exception {
    LOG.info("Using ShufflePort: " + localShufflePort.get());
    AuxiliaryServiceHelper.setServiceDataIntoEnv(
        TezConstants.TEZ_SHUFFLE_HANDLER_SERVICE_ID,
        ByteBuffer.allocate(4).putInt(localShufflePort.get()), localEnv);
    super.serviceStart();
  }

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

  @Override
  public RegisterDagResponseProto registerDag(RegisterDagRequestProto request)
      throws IOException {
    QueryIdentifierProto identifier = request.getQueryIdentifier();
    Credentials credentials;
    if (request.hasCredentialsBinary()) {
      credentials = LlapUtil.credentialsFromByteArray(
          request.getCredentialsBinary().toByteArray());
    } else {
      credentials = new Credentials();
    }
    queryTracker.registerDag(identifier.getApplicationIdString(),
        identifier.getDagIndex(), request.getUser(), credentials);
    LOG.info("Application with  id={}, dagId={} registered", identifier.getApplicationIdString(),
        identifier.getDagIndex());
    return RegisterDagResponseProto.newBuilder().build();
  }

  @Override
  public SubmitWorkResponseProto submitWork(SubmitWorkRequestProto request) throws IOException {
    LlapTokenInfo tokenInfo = null;
    try {
      tokenInfo = LlapTokenChecker.getTokenInfo(clusterId);
    } catch (SecurityException ex) {
      logSecurityErrorRarely(null);
      throw ex;
    }
    SignableVertexSpec vertex = extractVertexSpec(request, tokenInfo);
    TezEvent initialEvent = extractInitialEvent(request, tokenInfo);

    TezTaskAttemptID attemptId =
        Converters.createTaskAttemptId(vertex.getQueryIdentifier(), vertex.getVertexIndex(),
            request.getFragmentNumber(), request.getAttemptNumber());
    String fragmentIdString = attemptId.toString();

    QueryIdentifierProto qIdProto = vertex.getQueryIdentifier();

    verifyJwtForExternalClient(request, qIdProto.getApplicationIdString(), fragmentIdString);

    LOG.info("Queueing container for execution: fragemendId={}, {}", fragmentIdString,
        stringifySubmitRequest(request, vertex));

    HistoryLogger.logFragmentStart(qIdProto.getApplicationIdString(), request.getContainerIdString(),
        localAddress.get().getHostName(),
        constructUniqueQueryId(vertex.getHiveQueryId(), qIdProto.getDagIndex()),
        qIdProto.getDagIndex(),
        vertex.getVertexName(), request.getFragmentNumber(), request.getAttemptNumber());

    // This is the start of container-annotated logging.
    final String dagId = attemptId.getDAGID().toString();
    final String queryId = vertex.getHiveQueryId();
    final String fragmentId = LlapTezUtils.stripAttemptPrefix(fragmentIdString);
    MDC.put("dagId", dagId);
    MDC.put("queryId", queryId);
    MDC.put("fragmentId", fragmentId);
    // TODO: Ideally we want tez to use CallableWithMdc that retains the MDC for threads created in
    // thread pool. For now, we will push both dagId and queryId into NDC and the custom thread
    // pool that we use for task execution and llap io (StatsRecordingThreadPool) will pop them
    // using reflection and update the MDC.
    NDC.push(dagId);
    NDC.push(queryId);
    NDC.push(fragmentId);
    Scheduler.SubmissionState submissionState;
    SubmitWorkResponseProto.Builder responseBuilder = SubmitWorkResponseProto.newBuilder();
    try {
      Map<String, String> env = new HashMap<>();
      // TODO What else is required in this environment map.
      env.putAll(localEnv);
      env.put(ApplicationConstants.Environment.USER.name(), vertex.getUser());

      TezTaskAttemptID taskAttemptId = TezTaskAttemptID.fromString(fragmentIdString);
      int dagIdentifier = taskAttemptId.getDAGID().getId();

      QueryIdentifier queryIdentifier = new QueryIdentifier(
          qIdProto.getApplicationIdString(), dagIdentifier);

      Credentials credentials = LlapUtil.credentialsFromByteArray(
          request.getCredentialsBinary().toByteArray());

      Token<JobTokenIdentifier> jobToken = TokenCache.getSessionToken(credentials);

      LlapNodeId amNodeId = LlapNodeId.getInstance(request.getAmHost(), request.getAmPort());
      QueryFragmentInfo fragmentInfo = queryTracker.registerFragment(
          queryIdentifier, qIdProto.getApplicationIdString(), dagId,
          vertex.getDagName(), vertex.getHiveQueryId(), dagIdentifier,
          vertex.getVertexName(), request.getFragmentNumber(), request.getAttemptNumber(),
          vertex.getUser(), vertex, jobToken, fragmentIdString, tokenInfo, amNodeId, ugiPool);

      // May need to setup localDir for re-localization, which is usually setup as Environment.PWD.
      // Used for re-localization, to add the user specified configuration (conf_pb_binary_stream)

      // Lazy create conf object, as it gets expensive in this codepath.
      Supplier<Configuration> callableConf = () -> new Configuration(getConfig());
      UserGroupInformation fsTaskUgi = fsUgiFactory == null ? null : fsUgiFactory.createUgi();
      boolean isGuaranteed = request.hasIsGuaranteed() && request.getIsGuaranteed();

      // enable the printing of (per daemon) LLAP task queue/run times via LLAP_TASK_TIME_SUMMARY
      ConfVars tezSummary = ConfVars.TEZ_EXEC_SUMMARY;
      ConfVars llapTasks = ConfVars.LLAP_TASK_TIME_SUMMARY;
      boolean addTaskTimes = getConfig().getBoolean(tezSummary.varname, tezSummary.defaultBoolVal)
                             && getConfig().getBoolean(llapTasks.varname, llapTasks.defaultBoolVal);

      final String llapHost;
      if (UserGroupInformation.isSecurityEnabled()) {
        // when kerberos is enabled always use FQDN
        llapHost = localAddress.get().getHostName();
      } else if (execUseFQDN) {
        // when FQDN is explicitly requested (default)
        llapHost = localAddress.get().getHostName();
      } else {
        // when FQDN is not requested, use ip address
        llapHost = localAddress.get().getAddress().getHostAddress();
      }
      LOG.info("Using llap host: {} for execution context. hostName: {} hostAddress: {}", llapHost,
        localAddress.get().getHostName(), localAddress.get().getAddress().getHostAddress());
      // TODO: ideally we'd register TezCounters here, but it seems impossible before registerTask.
      WmFragmentCounters wmCounters = new WmFragmentCounters(addTaskTimes);
      TaskRunnerCallable callable = new TaskRunnerCallable(request, fragmentInfo, callableConf,
          new ExecutionContextImpl(llapHost), env,
          credentials, memoryPerExecutor, amReporter, confParams, metrics, killedTaskHandler,
          this, tezHadoopShim, attemptId, vertex, initialEvent, fsTaskUgi,
          completionListener, socketFactory, isGuaranteed, wmCounters);
      submissionState = executorService.schedule(callable);

      LOG.info("SubmissionState for {} : {} ", fragmentIdString, submissionState);

      if (submissionState.equals(Scheduler.SubmissionState.REJECTED)) {
        // Stop tracking the fragment and re-throw the error.
        fragmentComplete(fragmentInfo);
        return responseBuilder
            .setSubmissionState(SubmissionStateProto.valueOf(submissionState.name()))
            .build();
      }
      if (metrics != null) {
        metrics.incrExecutorTotalRequestsHandled();
      }
    } finally {
      MDC.clear();
      NDC.clear();
    }

    return responseBuilder.setUniqueNodeId(daemonId.getUniqueNodeIdInCluster())
        .setSubmissionState(SubmissionStateProto.valueOf(submissionState.name()))
        .build();
  }

  // if request is coming from llap external client, verify the JWT
  // as of now, JWT contains applicationId
  private void verifyJwtForExternalClient(SubmitWorkRequestProto request, String extClientAppIdFromSplit,
      String fragmentIdString) {
    LOG.info("Checking if request[{}] is from llap external client in a cloud based deployment",
        extClientAppIdFromSplit);
    if (request.getIsExternalClientRequest() && LlapUtil.isCloudDeployment(getConfig())) {
      LOG.info("Llap external client request - {}, verifying JWT", extClientAppIdFromSplit);
      Preconditions.checkState(request.hasJwt(), "JWT not found in request, fragmentId: " + fragmentIdString);

      LlapExtClientJwtHelper llapExtClientJwtHelper = new LlapExtClientJwtHelper(getConfig());
      Jws<Claims> claimsJws;
      try {
        claimsJws = llapExtClientJwtHelper.parseClaims(request.getJwt());
      } catch (JwtException e) {
        LOG.error("Cannot verify JWT provided with the request, fragmentId: {}, {}", fragmentIdString, e);
        throw e;
      }

      String extClientAppIdFromJwt = (String) claimsJws.getBody().get(LlapExtClientJwtHelper.LLAP_EXT_CLIENT_APP_ID);

      // this should never happen ideally.
      // extClientAppId is injected in JWT and fragment request by initial get_splits() call.
      // so both of these - extClientAppIdFromJwt and extClientAppIdFromSplit should be equal eventually if the signed JWT is valid for this request.
      // In get_splits, this extClientAppId is obtained via LlapCoordinator#createExtClientAppId which generates a
      // application Id to be used by external clients.
      Preconditions.checkState(extClientAppIdFromJwt.equals(extClientAppIdFromSplit),
          String.format("applicationId[%s] in request does not match to applicationId[%s] in JWT",
              extClientAppIdFromSplit, extClientAppIdFromJwt));
      LOG.info("Llap external client request - {}, JWT verification successful", extClientAppIdFromSplit);
    }
  }

  private SignableVertexSpec extractVertexSpec(SubmitWorkRequestProto request,
      LlapTokenInfo tokenInfo) throws InvalidProtocolBufferException, IOException {
    VertexOrBinary vob = request.getWorkSpec();
    SignableVertexSpec vertex = vob.hasVertex() ? vob.getVertex() : null;
    ByteString vertexBinary = vob.hasVertexBinary() ? vob.getVertexBinary() : null;
    if (vertexBinary != null) {
      if (vertex != null) {
        throw new IOException(
          "Vertex and vertexBinary in VertexOrBinary cannot be set at the same time");
      }
      vertex = SignableVertexSpec.parseFrom(vob.getVertexBinary());
    }

    if (tokenInfo.isSigningRequired) {
      checkSignature(vertex, vertexBinary, request, tokenInfo.userName);
    }
    return vertex;
  }

  private TezEvent extractInitialEvent(SubmitWorkRequestProto request, LlapTokenInfo tokenInfo)
      throws InvalidProtocolBufferException {
    if (!request.hasInitialEventBytes()) return null;
    ByteString initialEventByteString = request.getInitialEventBytes();
    byte[] initialEventBytes = initialEventByteString.toByteArray();
    NotTezEvent initialEvent = NotTezEvent.parseFrom(initialEventBytes);
    if (tokenInfo.isSigningRequired) {
      if (!request.hasInitialEventSignature()) {
        logSecurityErrorRarely(tokenInfo.userName);
        throw new SecurityException("Unsigned initial event is not allowed");
      }
      byte[] signatureBytes = request.getInitialEventSignature().toByteArray();
      try {
        signer.checkSignature(initialEventBytes, signatureBytes, initialEvent.getKeyId());
      } catch (SecurityException ex) {
        logSecurityErrorRarely(tokenInfo.userName);
        throw ex;
      }
    }
    return NotTezEventHelper.toTezEvent(initialEvent);
  }

  private void checkSignature(SignableVertexSpec vertex, ByteString vertexBinary,
      SubmitWorkRequestProto request, String tokenUserName) throws SecurityException, IOException {
    if (!request.hasWorkSpecSignature()) {
      logSecurityErrorRarely(tokenUserName);
      throw new SecurityException("Unsigned fragment not allowed");
    }
    if (vertexBinary == null) {
      ByteString.Output os = ByteString.newOutput();
      vertex.writeTo(os);
      vertexBinary = os.toByteString();
    }
    try {
      signer.checkSignature(vertexBinary.toByteArray(),
          request.getWorkSpecSignature().toByteArray(), (int)vertex.getSignatureKeyId());
    } catch (SecurityException ex) {
      logSecurityErrorRarely(tokenUserName);
      throw ex;
    }
    if (!vertex.hasUser() || !vertex.getUser().equals(tokenUserName)) {
      logSecurityErrorRarely(tokenUserName);
      throw new SecurityException("LLAP token is for " + tokenUserName
          + " but the fragment is for " + (vertex.hasUser() ? vertex.getUser() : null));
    }
  }

  private final AtomicLong lastLoggedError = new AtomicLong(0);
  private void logSecurityErrorRarely(String userName) {
    if (!LOG.isWarnEnabled()) return;
    long time = System.nanoTime();
    long oldTime = lastLoggedError.get();
    if (oldTime != 0 && (time - oldTime) < 1000000000L) return; // 1 second
    if (!lastLoggedError.compareAndSet(oldTime, time)) return;
    String tokens = null;
    try {
      tokens = "" + LlapTokenChecker.getLlapTokens(UserGroupInformation.getCurrentUser(), null);
    } catch (Exception e) {
      tokens = "error: " + e.getMessage();
    }
    LOG.warn("Security error from " + userName + "; cluster " + clusterId + "; tokens " + tokens);
  }

  @Override
  public SourceStateUpdatedResponseProto sourceStateUpdated(
      SourceStateUpdatedRequestProto request) throws IOException {
    LOG.info("Processing state update: " + stringifySourceStateUpdateRequest(request));
    QueryIdentifier queryId =
        new QueryIdentifier(request.getQueryIdentifier().getApplicationIdString(),
            request.getQueryIdentifier().getDagIndex());
    queryTracker.registerSourceStateChange(queryId, request.getSrcName(), request.getState());
    return SourceStateUpdatedResponseProto.getDefaultInstance();
  }

  @Override
  public QueryCompleteResponseProto queryComplete(
      QueryCompleteRequestProto request) throws IOException {
    QueryIdentifier queryIdentifier =
        new QueryIdentifier(request.getQueryIdentifier().getApplicationIdString(),
            request.getQueryIdentifier().getDagIndex());
    LOG.info("Processing queryComplete notification for {}", queryIdentifier);
    QueryInfo queryInfo = queryTracker.queryComplete(queryIdentifier, request.getDeleteDelay(), false);
    if (queryInfo != null) {
      List<QueryFragmentInfo> knownFragments = queryInfo.getRegisteredFragments();
      LOG.info("DBG: Pending fragment count for completed query {} = {}", queryIdentifier,
        knownFragments.size());
      for (QueryFragmentInfo fragmentInfo : knownFragments) {
        LOG.info("Issuing killFragment for completed query {} {}", queryIdentifier,
          fragmentInfo.getFragmentIdentifierString());
        executorService.killFragment(fragmentInfo.getFragmentIdentifierString());
      }
      amReporter.queryComplete(queryIdentifier);
    }
    return QueryCompleteResponseProto.getDefaultInstance();
  }

  @Override
  public TerminateFragmentResponseProto terminateFragment(
      TerminateFragmentRequestProto request) throws IOException {
    String fragmentId = request.getFragmentIdentifierString();
    LOG.info("DBG: Received terminateFragment request for {}", fragmentId);
    // TODO: ideally, QueryTracker should have fragment-to-query mapping.
    QueryIdentifier queryId = executorService.findQueryByFragment(fragmentId);
    // checkPermissions returns false if query is not found, throws on failure.
    if (queryId != null && queryTracker.checkPermissionsForQuery(queryId)) {
      executorService.killFragment(fragmentId);
    }
    return TerminateFragmentResponseProto.getDefaultInstance();
  }

  @Override
  public UpdateFragmentResponseProto updateFragment(
      UpdateFragmentRequestProto request) throws IOException {
    String fragmentId = request.getFragmentIdentifierString();
    boolean isGuaranteed = request.hasIsGuaranteed() && request.getIsGuaranteed();
    LOG.info("DBG: Received updateFragment request for {}", fragmentId);
    // TODO: ideally, QueryTracker should have fragment-to-query mapping.
    QueryIdentifier queryId = executorService.findQueryByFragment(fragmentId);
    // checkPermissions returns false if query is not found, throws on failure.
    boolean result = false;
    if (queryId != null && queryTracker.checkPermissionsForQuery(queryId)) {
      result = executorService.updateFragment(fragmentId, isGuaranteed);
    }
    return UpdateFragmentResponseProto.newBuilder()
        .setResult(result).setIsGuaranteed(isGuaranteed).build();
  }

  @Override
  public SetCapacityResponseProto setCapacity(
      SetCapacityRequestProto request) {
    executorService.setCapacity(request.getExecutorNum(), request.getQueueSize());
    return SetCapacityResponseProto.newBuilder().build();
  }

  private String stringifySourceStateUpdateRequest(SourceStateUpdatedRequestProto request) {
    StringBuilder sb = new StringBuilder();
    QueryIdentifier queryIdentifier = new QueryIdentifier(request.getQueryIdentifier().getApplicationIdString(),
        request.getQueryIdentifier().getDagIndex());
    sb.append("queryIdentifier=").append(queryIdentifier)
        .append(", ").append("sourceName=").append(request.getSrcName())
        .append(", ").append("state=").append(request.getState());
    return sb.toString();
  }

  public static String stringifySubmitRequest(
      SubmitWorkRequestProto request, SignableVertexSpec vertex) {
    StringBuilder sb = new StringBuilder();
    sb.append("am_details=").append(request.getAmHost()).append(":").append(request.getAmPort());
    sb.append(", taskInfo=").append(" fragment ")
      .append(request.getFragmentNumber()).append(" attempt ").append(request.getAttemptNumber());
    sb.append(", user=").append(vertex.getUser());
    sb.append(", queryId=").append(vertex.getHiveQueryId());
    sb.append(", appIdString=").append(vertex.getQueryIdentifier().getApplicationIdString());
    sb.append(", appAttemptNum=").append(vertex.getQueryIdentifier().getAppAttemptNumber());
    sb.append(", containerIdString=").append(request.getContainerIdString());
    sb.append(", dagName=").append(vertex.getDagName());
    sb.append(", vertexName=").append(vertex.getVertexName());
    sb.append(", processor=").append(vertex.getProcessorDescriptor().getClassName());
    sb.append(", numInputs=").append(vertex.getInputSpecsCount());
    sb.append(", numOutputs=").append(vertex.getOutputSpecsCount());
    sb.append(", numGroupedInputs=").append(vertex.getGroupedInputSpecsCount());
    sb.append(", Inputs={");
    if (vertex.getInputSpecsCount() > 0) {
      for (IOSpecProto ioSpec : vertex.getInputSpecsList()) {
        sb.append("{").append(ioSpec.getConnectedVertexName()).append(",")
            .append(ioSpec.getIoDescriptor().getClassName()).append(",")
            .append(ioSpec.getPhysicalEdgeCount()).append("}");
      }
    }
    sb.append("}");
    sb.append(", Outputs={");
    if (vertex.getOutputSpecsCount() > 0) {
      for (IOSpecProto ioSpec : vertex.getOutputSpecsList()) {
        sb.append("{").append(ioSpec.getConnectedVertexName()).append(",")
            .append(ioSpec.getIoDescriptor().getClassName()).append(",")
            .append(ioSpec.getPhysicalEdgeCount()).append("}");
      }
    }
    sb.append("}");
    sb.append(", GroupedInputs={");
    if (vertex.getGroupedInputSpecsCount() > 0) {
      for (GroupInputSpecProto group : vertex.getGroupedInputSpecsList()) {
        sb.append("{").append("groupName=").append(group.getGroupName()).append(", elements=")
            .append(group.getGroupVerticesList()).append("}");
        sb.append(group.getGroupVerticesList());
      }
    }
    sb.append("}");

    FragmentRuntimeInfo fragmentRuntimeInfo = request.getFragmentRuntimeInfo();
    sb.append(", FragmentRuntimeInfo={");
    sb.append("taskCount=").append(fragmentRuntimeInfo.getNumSelfAndUpstreamTasks());
    sb.append(", completedTaskCount=").append(fragmentRuntimeInfo.getNumSelfAndUpstreamCompletedTasks());
    sb.append(", dagStartTime=").append(fragmentRuntimeInfo.getDagStartTime());
    sb.append(", firstAttemptStartTime=").append(fragmentRuntimeInfo.getFirstAttemptStartTime());
    sb.append(", currentAttemptStartTime=").append(fragmentRuntimeInfo.getCurrentAttemptStartTime());
    sb.append("}");
    return sb.toString();
  }

  @Override
  public void fragmentComplete(QueryFragmentInfo fragmentInfo) {
    queryTracker.fragmentComplete(fragmentInfo);
  }

  @Override
  public void queryFailed(QueryIdentifier queryIdentifier) {
    LOG.info("Processing query failed notification for {}", queryIdentifier);
    List<QueryFragmentInfo> knownFragments;
    knownFragments = queryTracker.getRegisteredFragments(queryIdentifier);
    LOG.info("DBG: Pending fragment count for failed query {} = {}", queryIdentifier,
        knownFragments.size());
    for (QueryFragmentInfo fragmentInfo : knownFragments) {
      LOG.info("DBG: Issuing killFragment for failed query {} {}", queryIdentifier,
          fragmentInfo.getFragmentIdentifierString());
      executorService.killFragment(fragmentInfo.getFragmentIdentifierString());
    }
  }

  private class KilledTaskHandlerImpl implements KilledTaskHandler {

    @Override
    public void taskKilled(String amLocation, int port, String umbilicalUser,
                           Token<JobTokenIdentifier> jobToken, QueryIdentifier queryIdentifier,
                           TezTaskAttemptID taskAttemptId) {
      amReporter.taskKilled(amLocation, port, umbilicalUser, jobToken, queryIdentifier, taskAttemptId);
    }
  }

  public Set<String> getExecutorStatus() {
    return executorService.getExecutorsStatusForReporting();
  }

  public static String constructUniqueQueryId(String queryId, int dagIndex) {
    // Hive QueryId is not always unique.
    return queryId + "-" + dagIndex;
  }

  public int getNumActive() {
    return executorService.getNumActiveForReporting();
  }

  static class UgiPool {
    // Pool of UGI for a given appTokenIdentifier (AM). Expires after 3 hours of last access
    private final Cache<String, BlockingQueue<UserGroupInformation>> ugiPool =
        CacheBuilder
            .newBuilder().removalListener(new RemovalListener<String, BlockingQueue<UserGroupInformation>>() {
          @Override
          public void onRemoval(
              RemovalNotification<String, BlockingQueue<UserGroupInformation>> notification) {
            LOG.debug("Removing " + notification.getValue()  + " from pool.Pool size: " + ugiPool.size());
          }
        }).expireAfterAccess(60 * 3, TimeUnit.MINUTES).build();

    private final int numExecutors;

    public UgiPool(int numExecutors) {
      this.numExecutors = numExecutors;
    }

    /**
     * Get UGI for a given AM and appToken. It is possible to have more than one
     * UGI per AM.
     *
     * @param appTokenIdentifier
     * @param appToken
     * @return UserGroupInformation
     * @throws ExecutionException
     */
    public UserGroupInformation getUmbilicalUgi(String appTokenIdentifier,
        Token<JobTokenIdentifier> appToken) throws ExecutionException {
      BlockingQueue<UserGroupInformation> queue = ugiPool.get(appTokenIdentifier,
          new Callable<BlockingQueue<UserGroupInformation>>() {
            @Override
            public BlockingQueue<UserGroupInformation> call() throws Exception {
              UserGroupInformation ugi = UserGroupInformation.createRemoteUser(appTokenIdentifier);
              ugi.addToken(appToken);
              BlockingQueue<UserGroupInformation> queue = new LinkedBlockingQueue<>(numExecutors);
              queue.add(ugi);
              LOG.debug("Added new ugi pool for " + appTokenIdentifier + ", Pool Size: ");
              return queue;
            }
          });

      //Get UGI from the queue. Possible to maintain more than one UGI per AM. Ref: HIVE-16634
      UserGroupInformation ugi = queue.poll();
      if (ugi == null) {
        ugi = UserGroupInformation.createRemoteUser(appTokenIdentifier);
        ugi.addToken(appToken);
        queue.offer(ugi);
        LOG.info("Added new ugi for " + appTokenIdentifier + ". Pool size:" + ugiPool.size());
      }
      return ugi;
    }

    /**
     * Return UGI back to pool
     *
     * @param appTokenIdentifier AM identifier
     * @param ugi
     */
    public void returnUmbilicalUgi(String appTokenIdentifier, UserGroupInformation ugi) {
      BlockingQueue<UserGroupInformation> ugiQueue = ugiPool.getIfPresent(appTokenIdentifier);
      // Entry could have been removed due to expiry. Check before returning back to queue
      if (ugiQueue != null) {
        ugiQueue.offer(ugi);
      }
    }
  }

}


text:
package project

import (
	"bytes"
	"encoding/json"
	"fmt"
	"go/build"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"sort"
	"strings"

	"github.com/akshayjshah/hardhat/internal/git"
	"github.com/akshayjshah/hardhat/internal/hhlog"
)

// deps is a portion of the information returned by "go list -json".
type deps struct {
	ImportPath   string
	Imports      []string
	TestImports  []string
	XTestImports []string
	Deps         []string
}

// Status describes the state of a file or package relative to a previous
// commit.
type Status uint8

// Relative to a previous commit, each file or package is either unchanged,
// modified, or deleted.
const (
	StatusUnknown Status = iota
	StatusUnchanged
	StatusModified
	StatusDeleted
)

func (s Status) String() string {
	switch s {
	case StatusUnchanged:
		return "-"
	case StatusModified:
		return "M"
	case StatusDeleted:
		return "D"
	default:
		return "?"
	}
}

// MarshalText implements encoding.TextMarshaler.
func (s Status) MarshalText() ([]byte, error) {
	return []byte(s.String()), nil
}

// A PathDiff describes the state of a single file relative to a previous
// commit.
type PathDiff struct {
	Status Status `json:"status"`
	Path   string `json:"path"`
}

func (pd PathDiff) less(other PathDiff) bool {
	if pd.Status < other.Status {
		return true
	}
	return pd.Path < other.Path
}

// A Diff identifies the files and packages modified since the base commit.
// Recursive diffs also include packages that depend on modified code.
type Diff struct {
	Files    []PathDiff `json:"files"`
	Packages []PathDiff `json:"packages"`

	recursive bool
}

func (d Diff) String() string {
	if len(d.Files)+len(d.Packages) == 0 {
		return "No changes."
	}

	buf := bytes.NewBuffer(nil)
	if len(d.Files) == 0 {
		buf.WriteString("No modified or deleted files.\n")
	} else {
		fmt.Fprintf(buf, "%d modified or deleted files:\n", len(d.Files))
		for _, pd := range d.Files {
			fmt.Fprintf(buf, "\t%s\t%s\n", pd.Status, pd.Path)
		}
	}

	if len(d.Packages) == 0 {
		buf.WriteString("No affected packages.\n")
	} else {
		fmt.Fprintf(buf, "%d modified or deleted packages:\n", len(d.Packages))
		for _, pd := range d.Packages {
			fmt.Fprintf(buf, "\t%s\t%s\n", pd.Status, pd.Path)
		}
	}
	return strings.TrimSpace(buf.String())
}

// A Project represents a git repository of Go source code.
type Project struct {
	logger *hhlog.Logger
	repo   *git.Repository
	root   string
}

// New constructs a project.
func New(logger *hhlog.Logger, r *git.Repository) (*Project, error) {
	p := &Project{
		logger: logger,
		repo:   r,
	}
	if err := p.setRoot(); err != nil {
		return nil, fmt.Errorf("can't determine root package: %v", err)
	}
	return p, nil
}

// Root returns the Go import path of the project's root package.
func (p *Project) Root() string { return p.root }

// Diff identifies the files and packages directly modified since the supplied
// commitish.
func (p *Project) Diff(since string) (Diff, error) {
	raw, err := p.repo.Diff(since)
	if err != nil {
		return Diff{}, err
	}
	return p.processDiff(raw)
}

// RecursiveDiff identifies the files and packages directly modified since the
// supplied commitish, along with any packages that depend on modified code.
func (p *Project) RecursiveDiff(since string) (Diff, error) {
	base, err := p.Diff(since)
	if err != nil {
		return Diff{}, err
	}

	g, err := p.graph()
	if err != nil {
		return Diff{}, fmt.Errorf("can't build project's import graph: %v", err)
	}

	affected := make(map[PathDiff]struct{})
	for _, pd := range base.Packages {
		affected[pd] = struct{}{}
		for _, dep := range g[pd.Path] {
			affected[PathDiff{StatusModified, dep}] = struct{}{}
		}
	}

	base.Packages = make([]PathDiff, 0, len(affected))
	for pkg := range affected {
		base.Packages = append(base.Packages, pkg)
	}
	sort.Slice(base.Packages, func(i, j int) bool {
		return base.Packages[i].less(base.Packages[j])
	})
	base.recursive = true
	return base, nil
}

// All identifies all the files and packages in the project.
func (p *Project) All() (Diff, error) {
	raw, err := p.repo.All()
	if err != nil {
		return Diff{}, err
	}
	return p.processDiff(raw)
}

// Exec executes a command, sending the output directly to standard out and
// standard error.
func (p *Project) Exec(cmd string, args ...string) error {
	c := exec.Command(cmd, args...)
	c.Dir = p.repo.Root()
	c.Stdout, c.Stderr = os.Stdout, os.Stderr
	return c.Run()
}

func (p *Project) processDiff(raw git.Diff) (Diff, error) {
	d := Diff{
		Files:    make([]PathDiff, 0, len(raw.Modified)),
		Packages: make([]PathDiff, 0, len(raw.Deleted)),
	}
	for _, mod := range raw.Modified {
		d.Files = append(d.Files, PathDiff{StatusModified, mod})
	}
	for _, del := range raw.Deleted {
		d.Files = append(d.Files, PathDiff{StatusDeleted, del})
	}

	dirs := make(map[string]struct{})
	for _, f := range raw.Deleted {
		dirs[filepath.Dir(f)] = struct{}{}
	}
	for _, f := range raw.Modified {
		dirs[filepath.Dir(f)] = struct{}{}
	}

	for dir := range dirs {
		if !exists(dir) {
			d.Packages = append(d.Packages, PathDiff{StatusDeleted, filepath.Join(p.Root(), dir)})
			continue
		}

		if filepath.Base(dir) == "testdata" {
			// If a testdata directory is changed, assume that it affects only the
			// containing package.
			dir = filepath.Dir(dir)
		}

		pkg, importErr := build.Import(fmt.Sprintf("./%s", dir), p.repo.Root(), build.ImportComment)
		if importErr != nil {
			contains, err := containsGo(filepath.Join(p.repo.Root(), dir))
			if err != nil {
				return d, fmt.Errorf("couldn't check if directory %q contains Go source: %v", dir, err)
			}
			if !contains {
				// Not all directories are packages.
				continue
			}
			return d, fmt.Errorf("Go tool can't import directory %q: %v", dir, importErr)
		}

		if dir == "." {
			d.Packages = append(d.Packages, PathDiff{StatusModified, p.Root()})
		} else {
			d.Packages = append(d.Packages, PathDiff{StatusModified, pkg.ImportPath})
		}
	}
	sort.Slice(d.Packages, func(i, j int) bool {
		return d.Packages[i].less(d.Packages[j])
	})
	return d, nil
}

func (p *Project) setRoot() error {
	pkg, importErr := build.ImportDir(p.repo.Root(), build.ImportComment)
	if importErr == nil && pkg.ImportPath != "" {
		p.root = pkg.ImportPath
		p.logger.Debugf("found root package %q", p.root)
		return nil
	}

	// We couldn't import the root of the repository. This is fine as long as
	// there's no Go code there.
	contains, err := containsGo(p.repo.Root())
	if err != nil {
		return err
	}
	if contains {
		return importErr
	}

	p.logger.Debugf("no Go source files in repository root, guessing root package from path")
	importPath, err := filepath.Rel(filepath.Join(build.Default.GOPATH, "src"), p.repo.Root())
	if err != nil {
		return fmt.Errorf("can't find repository path relative to $GOPATH: %v", err)
	}
	p.logger.Debugf("assuming root package is %q", importPath)
	p.root = importPath
	return nil
}

func (p *Project) graph() (map[string][]string, error) {
	out := bytes.NewBuffer(nil)
	cmd := exec.Command("go", "list", "-json", "./...")
	cmd.Dir = p.repo.Root()
	cmd.Stderr, cmd.Stdout = out, out
	if err := cmd.Run(); err != nil {
		return nil, err
	}

	dependencies := make(map[string][]string)
	dec := json.NewDecoder(out)
	for dec.More() {
		var d deps
		if err := dec.Decode(&d); err != nil {
			return nil, err
		}
		d.Deps = append(d.Deps, d.Imports...)
		d.Deps = append(d.Deps, d.TestImports...)
		d.Deps = append(d.Deps, d.XTestImports...)
		for _, pkg := range d.Deps {
			dependencies[pkg] = append(dependencies[pkg], d.ImportPath)
		}
	}
	return dependencies, nil
}

func exists(path string) bool {
	_, err := os.Stat(path)
	return err == nil
}

func containsGo(path string) (bool, error) {
	files, err := ioutil.ReadDir(path)
	if err != nil {
		return false, err
	}
	for _, f := range files {
		if strings.HasSuffix(f.Name(), ".go") {
			return true, nil
		}
	}
	return false, nil
}


text:
<?php

    // Added by KP on March 31, 2015.  So, if something is buggered, it's probably my bad!  ;-)

    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }

    if ( ! class_exists( 'reduxNewsflash' ) ) {
        class reduxNewsflash {
            private $parent = null;
            private $notice_data = '';
            private $server_file = '';
            private $interval = 3;
            private $cookie_id = '';

            public function __construct( $parent, $params ) {
                // set parent object
                $this->parent = $parent;

                if ( ! is_admin() ) {
                    return;
                }

                $this->server_file = $params['server_file'];
                $this->interval    = isset( $params['interval'] ) ? $params['interval'] : 3;
                $this->cookie_id   = isset( $params['cookie_id'] ) ? $params['cookie_id'] : $parent->args['opt_name'] . '_blast';

                $this->notice_data = get_option( 'r_notice_data', '' );

                $fname = Redux_Functions::bub( 'get_notice_json', $parent->args['opt_name'] );
                $mname = Redux_Functions::yo( 'display_message', $parent->args['opt_name'] );

                // if notice data is empty
                if ( empty( $this->notice_data ) ) {
                    // get notice data from server and create cache data
                    $this->$fname();
                } else {
                    // check expiry time
                    if ( ! isset( $_COOKIE[ $this->cookie_id ] ) ) {
                        // expired!  get notice data from server
                        $this->$fname();
                    }
                }

                // set the admin notice msg
                $this->$mname();
            }

            private function bub() {
                $this->notice_data = '';
            }

            private function get_notice_json() {

                // get notice data from server

                $data = @wp_remote_get( $this->server_file, array( 'sslverify' => false ) );
                if ( isset( $data ) && ! empty( $data ) && ! is_wp_error( $data ) && $data['response']['code'] == 200 ) {
                    $data = $data['body'];
                    // if some data exists
                    if ( $data != '' || ! empty( $data ) ) {

                        if ( ! empty( $this->notice_data ) ) {
                            if ( strcmp( $data, $this->notice_data ) == 0 ) {
                                // set new cookie for interval value
                                Redux_Functions::setCookie( $this->cookie_id, time(), time() + ( 86400 * $this->interval ), '/' );

                                // bail out
                                return;
                            }
                        }

                        update_option( 'r_notice_data', $data );
                        $this->notice_data = $data;

                        // set cookie for three day expiry
                        setcookie( $this->cookie_id, time(), time() + ( 86400 * $this->interval ), '/' );

                        // set unique key for dismiss meta key
                        update_option( $this->cookie_id, time() );
                    }
                }
            }

            private function display_message() {
                // Notice data exists?
                if ( ! empty( $this->notice_data ) ) {
                    // decode json string
                    $data = (Array) json_decode( $this->notice_data );
                    // must be array and not empty
                    if ( is_array( $data ) && ! empty( $data ) ) {

                        // No message means nothing to display.
                        if ( ! isset( $data['message'] ) || $data['message'] == '' || empty( $data['message'] ) ) {
                            return;
                        }

                        // validate data
                        $data['type']  = isset( $data['type'] ) && $data['type'] != '' ? $data['type'] : 'updated';
                        $data['title'] = isset( $data['title'] ) && $data['title'] != '' ? $data['title'] : '';

                        if ( $data['type'] == 'redux-message' ) {
                            $data['type'] = 'updated redux-message';
                        }

                        $data['color'] = isset( $data['color'] ) ? $data['color'] : '#00A2E3';

                        // get unique meta key
                        $key = get_option( $this->cookie_id );

                        // set admin notice array
                        $this->parent->admin_notices[] = array(
                            'type'    => $data['type'],
                            'msg'     => $data['title'] . $data['message'],
                            'id'      => $this->cookie_id . '_' . $key,
                            'dismiss' => true,
                            'color'   => $data['color']
                        );
                    }
                }
            }
        }
    }


text:
using MusicMink.MediaSources;
using MusicMink.Pages;
using MusicMink.ViewModels;
using MusicMinkAppLayer.Diagnostics;
using System;
using System.Reflection;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.System.Threading;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;

// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=391641

namespace MusicMink
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    public sealed partial class App : Application
    {
        private TransitionCollection transitions;

        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += this.OnSuspending;
            this.Resuming += this.OnResuming;

            this.UnhandledException += LogUnhandledException;
        }

        async void LogUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            DebugHelper.Alert(new CallerInfo(), "UnhandledException: TYPE: {0} MESSAGE: {1} STRING: {2} SOURCE: {3}", e.Exception.GetType(), e.Message, e.Exception.ToString(), e.Exception.Source);

            await Logger.Current.Flush();
        }

        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Logger.Current.Init(LogType.FG);

            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "App launched");

            PerfTracer pt = new PerfTracer("Startup Perf");
            LibraryViewModel.Current.PreInitalize();

            UpdateTheme();

            pt.Trace("LibraryViewModelInitalized");

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 1;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated += this.RootFrame_FirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter

                Type target = typeof(LandingPage);
                if (SettingsViewModel.Current.IsClassicModeEnabled)
                {
                    target = typeof(MainPage);
                }

                if (!rootFrame.Navigate(target, e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();

            // TODO: need to do this async to get load times down
            LibraryViewModel.Current.InitalizeLibrary();

            MediaImportManager.Current.Initalize();

            pt.Trace("Startup Done");
        }

        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            var continuationEventArgs = args as IContinuationActivatedEventArgs;
            if (continuationEventArgs != null)
            {
                NavigationManager.Current.HandleContinuation(continuationEventArgs);
            }
        }

        private void UpdateTheme()
        {
            SolidColorBrush brush = DebugHelper.CastAndAssert<SolidColorBrush>(App.Current.Resources["PhoneAccentBrush"]);

            Color c = brush.Color;

            c.R = (byte)(byte.MaxValue - c.R * 0.2);
            c.G = (byte)(byte.MaxValue - c.G * 0.2);
            c.B = (byte)(byte.MaxValue - c.B * 0.2);

            ((SolidColorBrush)App.Current.Resources["PlayerControlBackgroundColor"]).Color = c;
        }

        /// <summary>
        /// Restores the content transitions after the app has launched.
        /// </summary>
        /// <param name="sender">The object where the handler is attached.</param>
        /// <param name="e">Details about the navigation event.</param>
        private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
        {
            var rootFrame = sender as Frame;
            rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
            rootFrame.Navigated -= this.RootFrame_FirstNavigated;
        }

        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            LibraryViewModel.Current.PlayQueue.Suspend();

            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "App suspended");

            await Logger.Current.Flush();

            deferral.Complete();
        }

        void OnResuming(object sender, object e)
        {
            Logger.Current.Init(LogType.FG);

            LibraryViewModel.Current.PlayQueue.Resume();

            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "App resumed");
        }
    }
}


text:
import React from 'react';
import {Jumbotron} from 'apparena-patterns-react';

export default function JumbotronExample() {
    return (
        <Jumbotron>

This is an Jumbotrom item

And this is one too

        </Jumbotron>
    );
}

/*;;usage
<JumbotronExample />
;;*/


text:
export build=~/devtools # or wherever you'd like to build
mkdir -p $build

##
# Autoconf
# http://ftpmirror.gnu.org/autoconf

cd $build
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-*.tar.gz
cd autoconf-*
./configure --prefix=/usr/local
make
sudo make install
export PATH=$PATH:/usr/local/bin
cd ..
rm -r autoconf-*

##
# Automake
# http://ftpmirror.gnu.org/automake

cd $build
curl -OL http://ftpmirror.gnu.org/automake/automake-1.11.tar.gz
tar xzf automake-1.11.tar.gz
cd automake-1.11
./configure --prefix=/usr/local
make
sudo make install

##
# Libtool
# http://ftpmirror.gnu.org/libtool

cd $build
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.tar.gz
tar xzf libtool-2.4.tar.gz
cd libtool-2.4
./configure --prefix=/usr/local
make
sudo make install

echo "Installation complete."


text:
import sys

if len(sys.argv) < 2:
	print("Print sequence identifiers in fasta file")
	print("Usage: fastanames.py input_fasta")
	raise SystemExit

infile = open(sys.argv[1], "r")

for line in infile:
	if len(line) > 0 and line[0] == ">":
		print(line)


text:
name: von Quelldateien
---

# Upgrade von Quelldateien

Der allgemeine Weg um Gogs zu aktualisieren:

```bash
# Upgrade source and install dependencies
$ go get -u github.com/gogs/gogs

$ cd $GOPATH/src/github.com/gogs/gogs

# Remove old build
$ rm gogs

# or move old build
$ mv gogs gogs-$(./gogs -v | awk '{print $3}')

# And rebuild Gogs
$ go build
```

Andere Operationen:

- [Build aus dem `develop`-Branch](/docs/installation/install_from_source#build-aus-dem-develop-branch)
- [Testen der Installation](/docs/installation/install_from_source#testen-der-installation)
- [Build mit Tags](/docs/installation/install_from_source#build-mit-tags)


text:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:horaires="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_reload"
        android:icon="@mipmap/ic_cached_black_24dp"
        android:title="@string/vider"
        horaires:showAsAction="ifRoom"/>

</menu>


text:
package protocol

type NewUserBroadcast struct {
	Content string `json:"content"`
}


text:
namespace _64BitArray
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class BitArray64 : IEnumerable<int>
    {
        public BitArray64(ulong number)
        {
            string binaryString = DecimalToBinary(number);
            this.Bits = ToBitArray(binaryString);
        }

        public int[] Bits { get; private set; }

        public int this[int index]
        {
            get
            {
                return this.Bits[index];
            }
            set
            {
                if (index < 0 || index > this.Bits.Length - 1)
                {
                    throw new ArgumentOutOfRangeException("Index out of range.");
                }

                this.Bits[index] = value;
            }
        }

        public IEnumerator<int> GetEnumerator()
        {
            for (int i = 0; i < this.Bits.Length; i++)
            {
                yield return this.Bits[i];
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        public override bool Equals(object obj)
        {
            return this == (obj as BitArray64);
        }

        public override int GetHashCode()
        {
            return this.Bits.GetHashCode() ^ this.Bits.Length.GetHashCode();
        }

        public static bool operator ==(BitArray64 first, BitArray64 second)
        {
            if (first.Bits.Length != second.Bits.Length)
            {
                return false;
            }

            int length = first.Bits.Length;
            for (int i = 0; i < length; i++)
            {
                if (first[i] != second[i])
                {
                    return false;
                }
            }

            return true;
        }

        public static bool operator !=(BitArray64 first, BitArray64 second)
        {
            if (first.Bits.Length != second.Bits.Length)
            {
                return true;
            }

            int length = first.Bits.Length;
            for (int i = 0; i < length; i++)
            {
                if (first[i] != second[i])
                {
                    return true;
                }
            }

            return false;
        }

        private int[] ToBitArray(string numberString)
        {
            int[] result = numberString.ToCharArray().Select(b => int.Parse(b.ToString())).ToArray();
            return result;
        }

        private string DecimalToBinary(ulong number)
        {
            ulong num;
            StringBuilder sb = new StringBuilder();
            string str = String.Empty;
            while (number != 0)
            {
                num = number % 2;
                if (num != 0)
                {
                    sb.Append(1);
                }
                if (num == 0)
                {
                    sb.Append(0);
                }
                number = number / 2;
            }

            string reverse = sb.ToString();
            sb.Clear();
            for (int i = reverse.Length - 1; i >= 0; i--)
            {
                sb.Append(reverse[i]);
            }

            return sb.ToString().PadLeft(64, '0');
        }
    }
}


text:
#define XBYTE ((unsigned char volatile xdata*) 0)

/* a few useful Ethernet definitions. */
#define     BUFSIZ          1600
#define     NBUF            10
#define     MIN_PACKET_SIZE 60      /* smallest legal size packet, no fcs    */
#define     MAX_PACKET_SIZE 1514	/* largest legal size packet, no fcs     */
#define     ETHER_ADDR_LEN	6   /* Etherne;a few useful Ethernet definitions.*/

#define     TX_PAGES	    12
#define     START_PG	    0x40     	/* First page of TX buffer           */
#define		TX_START_PG		START_PG
#define     STOP_PG	        0x80		/* Last page + 1 of RX Ring          */
#define     RX_STOP_PG      STOP_PG
#define     RX_START_PG	    START_PG + TX_PAGES
#define     RX_CURR_PG      RX_START_PG + 1

#define     EN_RBUF_STAT	0	    /*  Received frame status                */
#define     EN_RBUF_NXT_PG	1	    /*  Page after this frame                */
#define     EN_RBUF_SIZE_LO	2	    /*  Length of this frame                 */
#define     EN_RBUF_SIZE_HI	3	    /*  Length of this frame                 */
#define     SIZE_OF_8019_HDR 4	    /*  size of 8019 specific packet header  */

#define		SBUFSIZ			1600
#define		BUFSIZ			1600
#define     PKT_DEST		0
#define     PKT_SRC			6
#define     PKT_TYPE		12
#define     SIZE_OF_ETH_PKT_HDR	14

/* IPADDR: The IP address of this 8019 node. */
#define IPADDR0     192
#define IPADDR1     168
#define IPADDR2     0
#define IPADDR3     2

/* NETMASK: The netmask. */
#define IPMASK0 255
#define IPMASK1 255
#define IPMASK2 255
#define IPMASK3 0

/* RIPADDR: IP address of the default router. */
#define RIPADDR0 192
#define RIPADDR1 168
#define RIPADDR2 0
#define RIPADDR3 1

/* ETHADDR: The Ethernet address. */
#define ETHADDR0 0x52
#define ETHADDR1 0x54
#define ETHADDR2 0x4C
#define ETHADDR3 0xC1
#define ETHADDR4 0x18
#define ETHADDR5 0xCF

/*****************************************************************************/
/* The EN registers - the Realtek RTL8019AS chip registers                   */
/* There are four pages of registers in the chip. You select                 */
/* which page you want, then address them at offsets 00-0F from base.        */
/* The chip command register (EN_CMD) appears in all pages.                  */

#define     CR              XBYTE [0x300]   /*	The command register (for all pages) */
#define     DMA_DATA		XBYTE [0x310]	/*  Remote DMA Port10~17h (for all pages)*/
#define     RESET	        XBYTE [0x318]	/*  Reset Port 18~1fh(for all pages)     */

/* Register accessed at EN_CMD, the RTL8019 base addr                        */
#define     CR_STOP		    0x01	//  Stop and reset the chip
#define     CR_START	    0x02	//  Start the chip, clear reset
#define     CR_TRANS	    0x04	//  Transmit a frame
#define     CR_RREAD	    0x08	//  Remote read
#define     CR_RWRITE	    0x10	//  Remote write
#define     CR_NODMA	    0x20	//  Remote DMA
#define     CR_PAGE0	    0x00	//  Select page chip registers
#define     CR_PAGE1	    0x40	//  using the two high-order bits
#define     CR_PAGE2	    0x80
#define     CR_PAGE3	    0xc0

/*
#define		E8390_STOP		0x01	// Stop and reset the chip
#define		E8390_START		0x02	// Start the chip, clear reset
#define		E8390_TRANS		0x04	// Transmit a frame
#define		E8390_RREAD		0x08	// Remote read
#define		E8390_RWRITE	0x10	// Remote write
#define		E8390_SPACKET	0x18	// Send Packet
#define		E8390_NODMA		0x00	// Remote DMA
#define		E8390_PAGE0		0x00	// Select page chip registers
#define		E8390_PAGE1		0x40	// using the two high-order bits
#define		E8390_PAGE2		0x80	// Page 3 is invalid.
*/

/* Page 0 register offsets                                                   */
#define     CLDA0		XBYTE [0x301]   // Current Locat DMA 0: RD Low byte of current local dma addr
#define     PSTART      XBYTE [0x301]	// Page Start:  WR Starting page of ring buffer
#define     CLDA1		XBYTE [0x302]   // Current Locat DMA 1:  RD High byte of current local dma add
#define     PSTOP  	    XBYTE [0x302]	// Page Stop:  WR Ending page +1 of ring buffer
#define     BNRY	    XBYTE [0x303]	// Boundary Reg:  RD/WR Boundary page of ring buffer
#define     TSR			XBYTE [0x304]	// Transmit Status Reg: RD Transmit status reg
#define     TPSR		XBYTE [0x304]	// Transmit Page Start: WR Transmit starting page
#define     NCR			XBYTE [0x305]	// Number of Collision:  RD Number of collision reg
#define     TBCR0  	    XBYTE [0x305]	// Transmit Byte Count 0:  WR Low  byte of tx byte count
#define     FIFO		XBYTE [0x306]	// RD FIFO
#define     TBCR1		XBYTE [0x306]	// Transmit Byte Count 1:  WR High byte of tx byte count
#define     ISR			XBYTE [0x307]	// Interrupt Status Reg:   RD/WR Interrupt status reg
#define     CRDA0  	    XBYTE [0x308]	// Current Remote DMA 0:  RD low byte of current remote dma add
#define     RSAR0		XBYTE [0x308]	// Remote Start DMA 0:  WR Remote start address reg 0
#define     CRDA1		XBYTE [0x309]	// Current Remote DMA 1:  RD high byte, current remote dma add.
#define     RSAR1		XBYTE [0x309]	// Remote Start DMA 1:  WR Remote start address reg 1
#define     RBCR0	    XBYTE [0x30a]	// Remote Byte Count 0:  WR Remote byte count reg 0
#define     R8019ID0	XBYTE [0x30a]	// Only 8019AS
#define     RBCR1		XBYTE [0x30b]	// Remote Byte Count 1:  WR Remote byte count reg 1
#define     R8019ID1 	XBYTE [0x30b]	// Only 8019AS
#define     RSR			XBYTE [0x30c]	// Reciever Status Reg:  RD RX status reg
#define     RCR		    XBYTE [0x30c]	// Reciever Configuration Reg:  WR RX configuration reg
#define     TCR		    XBYTE [0x30d]	// Transmit Configuration Reg:  WR TX configuration reg
#define     CNTR0	    XBYTE [0x30d]	// RD Rcv alignment error counter
#define     DCR		    XBYTE [0x30e]	// Data Configuration Reg:  WR Data configuration reg
#define     CNTR1	    XBYTE [0x30e]	// RD Rcv CRC error counter
#define     IMR			XBYTE [0x30f]	// Interrupt Mask Reg:  WR Interrupt mask reg
#define     CNTR2	    XBYTE [0x30f]	// RD Rcv missed frame error counter

/* Bits in TSR - Transmit status                               */
#define     TSR_PTX	    0x01	/*  Packet transmitted without error     */
//#define     TSR_ND	    0x02	/*  The transmit wasn't deferred.  ?     */
#define     TSR_COL	    0x04	/*  The transmit collided at least once. */
											/*  Record of collision remain NCR reg.  */
#define     TSR_ABT	    0x08	/*  The transmit collided 16 times, and was deferred. */
#define     TSR_CRS	    0x10	/*  The carrier sense was lost.          */
#define     TSR_FU	    0x20	/*  A "FIFO underrun" occurred during transmit. */
#define     TSR_CDH	    0x40	/*  The collision detect "heartbeat" signal was lost. */
#define     TSR_OWC	    0x80	/*  There was an out-of-window collision.*/
/*  After slot time, there was collision. This case was excuted retransmission.  ? */

/* Bits in ISR - Interrupt status register        (RD WR)                */
#define     ISR_PRX   	  0x01	/*  Receiver, no error                   */
#define     ISR_PTX	      0x02	/*  Transceiver, no error                */
#define     ISR_RXE	      0x04	/*  Receiver, with error                 */
#define     ISR_TXE	      0x08	/*  Transmitter, with error              */
#define     ISR_OVW	      0x10	/*  Receiver overwrote the ring          */
                       /*  Gap area of receiver ring buffer was disappeared  */
#define     ISR_CNT	      0x20	/*  Counters need emptying               */
                                    /* MSB of network tally counter became 1 */
#define     ISR_RDC	      0x40	/*  remote dma complete                  */
#define     ISR_RESET     0x80	/*  Reset completed                      */
#define     ISR_ALL	      0x35	/*3f  Interrupts we will enable 	 */
                                	/*  RST RDC CNT OVW TXE RXE PTX PRX		 */
/* Bits in RSR and received packet status byte                           */
#define     RSR_RRX  	0x01	/*  Received a good packet               */
#define     RSR_CRC	    0x02	/*  CRC error(CNTR1++)                   */
#define     RSR_FAE	    0x04	/*  Frame alignment error(CNTR0++)       */
                                    /*Packet isn't finished in byte boundary.*/
#define     RSR_FO	    0x08	/*  FIFO overrun when receiving          */
#define     RSR_MPA	    0x10	/*  Missed packet.. Gap area isn't exist */
             /* or because of monitor mode, packet is not buffered (CNTR2++) */
#define     RSR_PHY	    0x20	/* Physical/multicase address            */

#define     RSR_DIS	    0x40	/*  Receiver disable.set in monitor mode */
#define     RSR_DEF	    0x80	/*  Deferring because of collision       */

/*****************************************************************************/
/* Some generic ethernet register configurations.                            */
#define E8390_TX_IRQ_MASK   0x0A  /* For register EN0_ISR */
#define E8390_RX_IRQ_MASK   0x05                                           */
#define E8390_RXCONFIG      0x04 /* EN0_RXCR: broadcasts, no multicast & errors */
#define E8390_RXOFF         0x20    /* EN0_RXCR: Accept no packets */
#define E8390_TXCONFIG      0x00 /* EN0_TXCR: Normal transmit mode */
#define E8390_TXOFF         0x02    /* EN0_TXCR: Transmitter off */
/*****************************************************************************/

/* Bits in RCR - RX configuration reg                                   */
//#define     ENRXCR_RXCONFIG 0x04 	/* EN0_RXCR: broadcasts,no multicast,errors */
#define     RCR_RXCONFIG 0x00 	/* EN0_RXCR: only unicast */
#define     RCR_SEP	     0x01	/*  Save error packets(admit)            */
#define     RCR_AR	     0x02	/*  Accept runt pckt(below 64bytes)      */
#define     RCR_AB	     0x04	/*  Accept broadcasts when 1             */
#define     RCR_AM	     0x08	/*  Multicast (if pass filter) when 0    */
#define     RCR_PRO 	 0x10	/*  Promiscuous physical addresses when 1*/
											/* when 0,accept assigned PAR0~5 address */
#define     RCR_MON	     0x20	/*  Monitor mode (no packets rcvd)       */

/* Bits in TCR - TX configuration reg                                   */
#define     TCR_TXCONFIG 0x00    /* Normal transmit mode                  */
#define     TCR_CRC	     0x01	/*  inhibit CRC,do not append crc when 1 */
#define     TCR_LOOP	 0x02	/*  set internal loopback mode     ?     */
#define     TCR_LB01	 0x06	/*  encoded loopback control       ?     */
#define     TCR_ATD	     0x08	/*  auto tx disable                      */
/* when 1, if specified multicast packet was received, disable transmit      */
#define     TCR_OFST	 0x10	/*  collision offset enable              */
/* selection of collision algorithm. When 0, gererally back-off algorithm select */

/* Bank0/Reg0E                                                               */
/* Bits in DCR - Data config register                                   */
#define     DCR_WTS	    0x01	    /*  byte transfer mode selection         */
/*#endif    */
#define     DCR_BOS	    0x02	    /*  byte order selection                 */
                                    /* 0: MD15-8, LSB on MD7-0;little endian */
                                    /* 1: MSB on MD7-0, LSB on MD15-8     ?  */
#define     DCR_LAS	    0x04	    /* long addr selection (must be set to zero) */
                                    /* when 1 is 32bit address mode          */
#define     DCR_LS	    0x08	    /* loopback select       set is normal  mode      */
                                    /* 0: Loopback mode select. Bits 1 and 2 of the
                                       TCR must also be programmed for Loopback
                                       1: Normal operation                            */
#define     DCR_ARM	        0x10	/*  autoinitialize remote when 1         */
#define     DCR_FT00	    0x00	/*  fifo treshold   2 byte               */
#define     DCR_FT01	    0x20	/*                  4 byte               */
#define     DCR_FT10	    0x40	/*                  8 byte               */
#define     DCR_FT11	    0x60	/*                 12 byte               */

/* Page 1 register offsets                                                   */
#define     PAR0	    XBYTE [0x301]	// RD/WR This board's physical ethernet addr */
#define     PAR1	    XBYTE [0x302]
#define     PAR2	    XBYTE [0x303]
#define     PAR3	    XBYTE [0x304]
#define     PAR4	    XBYTE [0x305]
#define     PAR5	    XBYTE [0x306]
#define     CURR	    XBYTE [0x307]   // RD/WR current page reg */
//#define		EN1_CURPAG		EN1_CURR
#define     MAR0        XBYTE [0x308]   // RD/WR Multicast filter mask array (8 bytes) */
#define     MAR1		XBYTE [0x309]
#define     MAR2        XBYTE [0x30a]
#define     MAR3        XBYTE [0x30b]
#define     MAR4        XBYTE [0x30c]
#define     MAR5        XBYTE [0x30d]
#define     MAR6        XBYTE [0x30e]
#define     MAR7        XBYTE [0x30f]

/* Page 2 register offsets                                                   */
#define     STARTPG_R     XBYTE [0x301]   // RD only Reg.
#define     STOPPG_R      XBYTE [0x302]
#define     TPSR_R		  XBYTE [0x304]
#define     RXCR_R		  XBYTE [0x30c]
#define     TXCR_R		  XBYTE [0x30d]
#define     DCR_R		  XBYTE [0x30e]
#define     IMR_R	      XBYTE [0x30f]

/* // Page 3 register offsets    There is no Reg. in the DP8390.
#define     CR9346			XBYTE [0x301]   // RD/WR There is no Reg. in the DP8390
#define     BPAGE			XBYTE [0x302]   // RD/WR
#define     CONFIG0			XBYTE [0x303]   // RD
#define     CONFIG1			XBYTE [0x304]   // RD/WR
#define     CONFIG2			XBYTE [0x305]   // RD/WR
#define     CONFIG3			XBYTE [0x306]   // RD/WR
#define     CONFIG4			XBYTE [0x30d]   // RD
#define     CSNSAV          XBYTE [0x308]   // RD
#define     HLTCLK			XBYTE [0x309]   // WR
#define     INTR			XBYTE [0x30B]   // RD
*/


text:
#include <shift.hpp>

#include <common/jit/ShiftNodeBase.hpp>
#include <err_oneapi.hpp>
#include <traits.hpp>

using af::dim4;
using common::Node_ptr;
using common::ShiftNodeBase;
using std::array;
using std::make_shared;
using std::static_pointer_cast;
using std::string;

namespace oneapi {

template<typename T>
Array<T> shift(const Array<T> &in, const int sdims[4]) {
    ONEAPI_NOT_SUPPORTED("");
    Array<T> o = createEmptyArray<T>(dim4(1));
    return o;
    /*
    // Shift should only be the first node in the JIT tree.
    // Force input to be evaluated so that in is always a buffer.
    in.eval();

    string name_str("Sh");
    name_str += shortname<T>(true);
    const dim4 &iDims = in.dims();
    dim4 oDims        = iDims;

    array<int, 4> shifts{};
    for (int i = 0; i < 4; i++) {
        // sdims_[i] will always be positive and always [0, oDims[i]].
        // Negative shifts are converted to position by going the other way
        // round
        shifts[i] = -(sdims[i] % static_cast<int>(oDims[i])) +
                    oDims[i] * (sdims[i] > 0);
        assert(shifts[i] >= 0 && shifts[i] <= oDims[i]);
    }

    auto node = make_shared<ShiftNode>(
        static_cast<af::dtype>(dtype_traits<T>::af_type),
        static_pointer_cast<BufferNode>(in.getNode()), shifts);
    return createNodeArray<T>(oDims, common::Node_ptr(node));
    */
}

#define INSTANTIATE(T) \
    template Array<T> shift<T>(const Array<T> &in, const int sdims[4]);

INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(cfloat)
INSTANTIATE(cdouble)
INSTANTIATE(int)
INSTANTIATE(uint)
INSTANTIATE(intl)
INSTANTIATE(uintl)
INSTANTIATE(uchar)
INSTANTIATE(char)
INSTANTIATE(short)
INSTANTIATE(ushort)
}  // namespace oneapi


text:
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

public class HighScore : MonoBehaviour {

    Dictionary<string, Dictionary<string, int>> PlayerStats;

    int changeCounter = 0;

    void Start()
    {
        SetScore("Danilo", "wave", 970);
        SetScore("Danilo", "hours", 1);
        SetScore("Danilo", "minutes", 12);
        SetScore("Danilo", "seconds", 12);

        SetScore("Piet", "wave", 10000);
        SetScore("Bob", "wave", 44);
        SetScore("Rob", "wave", 21);
        SetScore("Kob", "wave", 3);
        Debug.Log( GetScore("Danilo", "wave") );
    }

    void Init()
    {
        if(PlayerStats != null)
            return;

        PlayerStats = new Dictionary<string, Dictionary<string, int>>();
    }

    public int GetScore(string username, string scoreType)
    {
        Init();

        if(PlayerStats.ContainsKey(username) == false)
        {
            return 0;
        }
        if(PlayerStats[username].ContainsKey(scoreType) == false)
        {
            return 0;
        }

        return PlayerStats[username][scoreType];
    }

    public void SetScore(string username, string scoreType, int value)
    {
        Init();
        changeCounter++;

        if (PlayerStats.ContainsKey(username) == false)
        {
            PlayerStats[username] = new Dictionary<string, int>();
        }
        PlayerStats[username][scoreType] = value;

    }
    public void ChangeScore(string username, string scoreType, int amount)
    {
        Init();
        int currentScore = GetScore(username, scoreType);
        SetScore(username, scoreType, currentScore + amount);
    }

    public string[] GetPlayerNames()
    {
        Init();
        return PlayerStats.Keys.ToArray();
    }

    public string[] GetPlayerNames(string sortingScoreType)
    {
        Init();

        return PlayerStats.Keys.OrderByDescending(  n => GetScore(n, sortingScoreType) ).ToArray();

    }

    public int GetChangeCounter()
    {
        return changeCounter;
    }

}


text:
There have been great strides in making it easier to share and re-use research data throughout Australia, and EnMaSSe is a tool that takes it one step further.  EnMaSSe is designed to increase the efficiency of creating and sharing research data, which means quicker progress within Australia as a whole, higher potential for new technologies and a better understanding of our environment.

Think of research data as information scientists & engineers have available for creating new technologies such as mapping how climate change will affect your life in the next 30 years, the latest medical cures or preserving our great Australian environment - almost anything you can think of, the building blocks of our entire modern lifestyle is research!

The EnMaSSe application provides a user-friendly interface for:

* Flexible and scalable research data ingestion (both streamed or manually input).
* High quality, fine grained, project based, metadata creation and export (eg. Enter 1 record, export many).
* Administerable and maintainable project lifecycle and workflows.

This project has been developed as part of EnMaSSe (Environmental Monitoring and Sensor Storage) and is related to:

* [Documentation](https://github.com/jcu-eresearch/TDH-Rich-Data-Capture-Documentation) - Contains full user, administrator and developer guides.
* [Deployment](https://github.com/jcu-eresearch/EnMaSSe-Deployment) - Recommended way to install
* [Ingester Platform](https://github.com/jcu-eresearch/TDH-dc24-ingester-platform) - Handles ingestion of data streaming and storage for the EnMaSSe project.
* [Ingester API](https://github.com/jcu-eresearch/jcu.dc24.ingesterapi) - API for integrating the EnMaSSe provisioning interface with the ingester platform
* [SimpleSOS](https://github.com/jcu-eresearch/python-simplesos) - Library used for the SOSScraperDataSource.

# Installation

**Please refer to the [Deployment](https://github.com/jcu-eresearch/EnMaSSe-Deployment) repository for installation instructions.**

Links
-----
* [Project Blog](http://jcu-eresearch.github.com/TDH-rich-data-capture/)
* Manuals:
 * [User Guide](https://tdh-rich-data-capture-documentation.readthedocs.org/en/latest/enmasse-user.html)
 * [Administrator Guide](https://tdh-rich-data-capture-documentation.readthedocs.org/en/latest/enmasse-admin.html)
 * [Developer Dcumentation](https://tdh-rich-data-capture-documentation.readthedocs.org/en/latest/enmasse-developer.html)
* Related material:
 * [Sensor Observation Service (SOS)](http://www.opengeospatial.org/standards/sos)
 * [Australian National Data Service (ANDS)](http://www.ands.org.au/)
 * [RIF-CS (metadata)](http://www.ands.org.au/guides/content-providers-guide.html)
 * [Research Data Australia (RDA)](http://researchdata.ands.org.au/)

Credits
-------

This project is supported by [the Australian National Data Service (ANDS)](http://www.ands.org.au/) through the National Collaborative Research Infrastructure Strategy Program and the Education Investment Fund (EIF) Super Science Initiative, as well as through the [Queensland Cyber Infrastructure Foundation (QCIF)](http://www.qcif.edu.au/).

License
-------

See `LICENCE.txt`.


text:
require 'test_helper'

class DeliveryMailsControllerOwnerTest < ActionController::TestCase
  setup do
    @controller = DeliveryMailsController.new
    login_user = users(:users_16)
  	sign_in login_user
    @owner_id = login_user.owner_id
    @delivery_mail = delivery_mails(:delivery_mails_3)
    @delivery_mail_params = {
      bp_pic_group_id: 2,
      subject: "test mail",
      content: "test",
      planned_setting_at: DateTime.now.strftime("%Y/%m/%d"),
      planned_setting_at_hour: DateTime.now.hour,
      planned_setting_at_minute: DateTime.now.min
    }
    @attachment1 = fixture_file_upload('files/test_attachment_file_01.xls', 'application/vnd.ms-excel', :binary)
    request.env['REQUEST_URI'] = ""
  end

  test "should get index" do
  	current_owner_delivery_mails = DeliveryMail.where(:owner_id => @owner_id)

    get :index, :bp_pic_group_id => BpPicGroup.where(:owner_id => @owner_id).first.id
    delivery_mails = assigns(:delivery_mails).select {|delivery_mail| delivery_mail.owner_id == @owner_id}

    assert_equal(current_owner_delivery_mails.size, delivery_mails.size)
  end

  test "should create delivery_mail" do
    assert_difference("DeliveryMail.where(:owner_id => #{@owner_id}).count", +1) do
      assert_difference("AttachmentFile.where(:owner_id => #{@owner_id}).count", +1) do
        post :create, delivery_mail: @delivery_mail_params, attachment1: @attachment1, back_to: "/bp_pic_groups"
      end
    end

    created_delivery_mail = DeliveryMail.order("id desc").first
    assert_redirected_to "/bp_pic_groups/#{created_delivery_mail.bp_pic_group_id}?back_to=%2Fbp_pic_groups&delivery_mail_id=#{created_delivery_mail.id}"
  end

  test "should copy delivery_mail" do
    src_mail_id = 3
    af_count = AttachmentFile.get_attachment_files('delivery_mails', src_mail_id).count
    assert_difference("DeliveryMail.where(:owner_id => #{@owner_id}).count", +1) do
      assert_difference("AttachmentFile.where(:owner_id => #{@owner_id}).count", +(af_count+1)) do
        post :create, src_mail_id: af_count.to_s, delivery_mail: @delivery_mail_params, attachment1: @attachment1, back_to: "/bp_pic_groups"
      end
    end

    created_delivery_mail = DeliveryMail.order("id desc").first
    assert_redirected_to "/bp_pic_groups/#{created_delivery_mail.bp_pic_group_id}?back_to=%2Fbp_pic_groups&delivery_mail_id=#{created_delivery_mail.id}"
  end

  test "should create delivery_mail(contact_mail_create)" do
    bp_pic_ids = [5, 6]
    assert_difference("DeliveryMail.where(:owner_id => #{@owner_id}).count", +1) do
      assert_difference("AttachmentFile.where(:owner_id => #{@owner_id}).count", +1) do
        assert_difference("DeliveryMailTarget.where(:owner_id => #{@owner_id}).count", bp_pic_ids.size) do
          assert_no_difference("DeliveryError.count") do
            post :create, bp_pic_ids: bp_pic_ids.join(' '), delivery_mail: @delivery_mail_params, attachment1: @attachment1, back_to: "/bp_pic"
          end
        end
      end
    end

    assert_redirected_to "/bp_pic"
  end

  test "should create delivery_mail(reply_mail_create)" do
    source_bp_pic = BpPic.where(:owner_id => @owner_id).first

    assert_difference("DeliveryMail.where(:owner_id => #{@owner_id}).count", +1) do
      assert_difference("AttachmentFile.where(:owner_id => #{@owner_id}).count", +1) do
        assert_difference("DeliveryMailTarget.where(:owner_id => #{@owner_id}).count", +1) do
          assert_no_difference("DeliveryError.count") do
            post :create, source_bp_pic_id: source_bp_pic.id, delivery_mail: @delivery_mail_params, attachment1: @attachment1, back_to: "/import_mail/show/1"
          end
        end
      end
    end

    assert_redirected_to "/import_mail/show/1"
  end

  test "should get index by another owner" do
    sign_in users(:users_1)
    get :index, :bp_pic_group_id => BpPicGroup.where(:owner_id => users(:users_1).owner_id).first.id
    delivery_mails = assigns(:delivery_mails).select {|dm| dm.owner_id == @owner_id}
    assert_empty(delivery_mails)
    assert_response :success
  end

end


text:
/**
 * Created by ben on 8/24/2015.
 */
var gulp = require('gulp');
var runSequence = require('run-sequence');
var babel = require('gulp-babel');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var paths = require('../paths');
var compileOptions = require('../babel-options');
var assign = Object.assign || require('object.assign');
var notify = require('gulp-notify');

gulp.task('build-system', function(){
	return gulp.src([paths.source, '!' + paths.jspm, '!' + paths.config])
		.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
		.pipe(changed(paths.output, {extension: '.js'}))
		.pipe(sourcemaps.init({loadMaps: true}))
		.pipe(babel(assign({}, compileOptions, {modules: 'system'})))
		.pipe(sourcemaps.write({includeContent: true}))
		.pipe(gulp.dest(paths.output));
});

gulp.task('build-html', function(){
	return gulp.src([paths.html, '!' + paths.jspm])
		.pipe(changed(paths.output, {extension: '.html'}))
		.pipe(gulp.dest(paths.output));
});

gulp.task('build', function(callback){
	return runSequence(
		'clean',
		['build-system', 'build-html'],
		callback
	);
});


text:
#include "lexer.h"
#include "lexer.defines.h"
#include "lexer.internal.h"

#include "tokenizer.h"

#include <string>

#define LOG_LEVEL LOG_LEVEL_SPAM
#include "debug.h"

namespace {

struct BufferState {
    YY_BUFFER_STATE m_state;
    BufferState(const char* text) {
        m_state = yy_scan_string(text);
    }
    ~BufferState() {
        yy_delete_buffer(m_state);
    }
};

}

using namespace Nope::Parser::AST;

namespace Nope {
namespace Lexer {

class PLexer;

PLexer *_instance = NULL;

class PLexer {
public:
    std::string m_errormsg;
    BufferState* m_bufferState;
    Symbol* m_sym;

    PLexer() {
        _instance = this;
        m_bufferState = NULL;
        m_sym = NULL;
    }

    ~PLexer() {
        _instance = NULL;
        delete m_bufferState;
        delete m_sym;
    }

    void freeData() {
        delete m_bufferState;
    }

    void SetText(const char* data) {
        freeData();
        m_bufferState = new BufferState(data);
        _lexerResetPos();
    }

    Terminal* Lex() {
        int r = yylex();
        if (_lexerTerminal != NULL && r != 0)
            _lexerTerminal->SetCode(r);
        return r == 0 ? NULL : _lexerTerminal;
    }

    int yyerror(const char* msg) {
        m_errormsg = msg;
        TR_ERR("Parsing error - line %d, text `%s`, msg `%s`",
            yylineno, yytext, msg);
        return 0;

    }

    int yywrap() {
        return 1;
    }
};

/***************************************************************************/

Lexer::Lexer() : p(new PLexer()) {}

Lexer::~Lexer() { delete p; }

Terminal* Lexer::Lex() {
    return p->Lex();
}

void Lexer::SetText(const char* data) { p->SetText(data); }

}}

int yyerror(const char* msg) {
    return Nope::Lexer::_instance->yyerror(msg);
}

int yywrap() {
    return Nope::Lexer::_instance->yywrap();
}


text:
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:paddingRight="5dp">

    <android.support.v7.widget.CardView
        android:id="@+id/checklist_item_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_margin="@dimen/card_margin"
        app:cardElevation="5dp"
        android:background="@color/todo_light_amber">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp">

            <ImageView
                android:id="@+id/check_image"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:src="@drawable/blank_todo"
                android:layout_marginRight="10dp"
                android:layout_gravity="center_vertical"/>

            <LinearLayout
                android:id="@+id/checklist_item_layout"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/checklist_item_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textStyle="bold"
                        android:textSize="20sp"
                        android:textColor="@color/title_color"/>

                    <TextView
                        android:id="@+id/checklist_item_description"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textStyle="italic"
                        android:textSize="14sp"
                        android:textColor="@color/desc_color"/>

            </LinearLayout>

        </LinearLayout>

    </android.support.v7.widget.CardView>

</FrameLayout>


text:
PREPS=(
	'echo "ERROR: CDIST2700E The operator requires an attribute called analysisResult on the output port"'
	'copyOnly'
)

STEPS=(
	"splCompileInterceptAndError"
	'linewisePatternMatchInterceptAndSuccess "$TT_evaluationFile" "" "*CDIST2700E*"'
)


text:
/*
 * Description:
 *     What is this file about?
 *
 * Revision history:
 *     xxxx-xx-xx, author, first version
 *     xxxx-xx-xx, author, fix bug about xxx
 */

# include <dsn/service_api_c.h>

//
// this svchost is a loader than can run all
// rDSN-based service modules with configuration as below.
//
// [apps.xxx]
// dmodule = echo //.so, .dll will be automatically appended
// count = 1
// arguments = xxx
//
// dsn_run will load all these *dmodule*s which automatically
// register their correspondent app roles into the system
// using dsn_register_app, and run them as specified.
//

int main(int argc, char** argv)
{
    //
    // run the system with arguments
    //   config [-cargs k1=v1;k2=v2] [-app_list app_name1@index1;app_name2@index]
    // e.g., config.ini -app_list replica@1 to start the first replica as a new process
    //       config.ini -app_list replica to start ALL replicas (count specified in config) as a new process
    //       config.ini -app_list replica -cargs replica-port=34556 to start ALL replicas with given port variable specified in config.ini
    //       config.ini to start ALL apps as a new process
    //
    dsn_run(argc, argv, true);
    return 0;
}


text:
package org.lpw.tephra.ctrl.template.freemarker;

import com.alibaba.fastjson.JSONObject;
import org.lpw.tephra.ctrl.Failure;
import org.lpw.tephra.ctrl.template.TemplateSupport;
import org.lpw.tephra.ctrl.template.Templates;
import org.lpw.tephra.freemarker.Freemarker;
import org.springframework.stereotype.Controller;

import javax.inject.Inject;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author lpw
 */
@Controller("tephra.ctrl.template.freemarker")
public class TemplateImpl extends TemplateSupport {
    @Inject
    private Freemarker freemarker;

    @Override
    public String getType() {
        return Templates.FREEMARKER;
    }

    @Override
    public String getContentType() {
        return "text/html";
    }

    @Override
    public void process(String name, Object data, OutputStream output) throws IOException {
        if (data instanceof Failure) {
            failure(getFailure((Failure) data), output);

            return;
        }

        if (data instanceof JSONObject && failure((JSONObject) data, output))
            return;

        freemarker.process(name, data, output);
    }

    private boolean failure(JSONObject object, OutputStream outputStream) throws IOException {
        if (object.containsKey("code") && object.getIntValue("code") > 0) {
            outputStream.write(object.toString().getBytes());

            return true;
        }

        return false;
    }
}


text:
.type-stripe-small {
	position: absolute;
	top: 25px;
	right: 0;
	-ms-transform: rotate(45deg);
	-webkit-transform: rotate(45deg);
	transform: rotate(45deg);
	border-left: 20px solid transparent;
	border-right: 20px solid transparent;
	height: 0;
}

.type-stripe-big {
	position: absolute;
	top: 150px;
	right: 0px;
	-ms-transform: rotate(45deg);
	-webkit-transform: rotate(45deg);
	transform: rotate(45deg);
	border-left: 30px solid transparent;
	border-right: 30px solid transparent;
	height: 0;
	font-size: 20px;
}