text:
<?php

  $unique_key = $_SERVER['PATH_INFO'];
  if(!$unique_key) {
      $unique_key = uniqid("HiPad");
      $host  = $_SERVER['HTTP_HOST'];
      $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
      $extra = "editor.php/" . $unique_key;
      header("Location: http://$host$uri/$extra");
      exit;
  }
  if (substr($unique_key, 0, 1) == "/") {
    $unique_key = substr($unique_key, 1);
  }

?>
<html manifest="../manifest.php/<?= $unique_key ?>">

        <meta charset="UTF-8" />

Processing.js for iPad

                    Save & Run
                    New

                    <textarea id="editor" class="edit"></textarea>

redpajama_set_name: RedPajamaGithub


text:
package org.crazydays.sensortag;

import java.util.UUID;

import android.app.Fragment;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;

public abstract class CharacteristicsFragment
    extends Fragment
{
    public final static String NOTIFY_UUID =
        "00002902-0000-1000-8000-00805f9b34fb";

    public final static byte[] DISABLE_NOTIFICATION_VALUE =
        BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
    public final static byte[] ENABLE_NOTIFICATION_VALUE =
        BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;

    public static CharacteristicsFragment build(BluetoothGatt bluetoothGatt,
        UUID uuid)
    {
        CharacteristicsFragment fragment = null;

        if (UUIDHelper.IrTemperature.SERVICE.equals(uuid.toString())) {
            fragment = new IrTemperatureCharacteristicsFragment();
        } else if (UUIDHelper.Accelerometer.SERVICE.equals(uuid.toString())) {
            fragment = new AccelerometerCharacteristicsFragment();
        } else {
            fragment = new CharacteristicsListFragment();
        }

        fragment.setBluetoothGatt(bluetoothGatt);

        return fragment;
    }

    private BluetoothGatt bluetoothGatt;

    private void setBluetoothGatt(BluetoothGatt bluetoothGatt)
    {
        this.bluetoothGatt = bluetoothGatt;
    }

    protected void requestRead(BluetoothGattCharacteristic characteristic)
    {
        bluetoothGatt.readCharacteristic(characteristic);
    }

    protected void requestWrite(BluetoothGattCharacteristic characteristic)
    {
        bluetoothGatt.writeCharacteristic(characteristic);
    }

    protected void requestNotification(
        BluetoothGattCharacteristic characteristic, boolean enable)
    {
        bluetoothGatt.setCharacteristicNotification(characteristic, enable);

        BluetoothGattDescriptor descriptor =
            characteristic.getDescriptor(UUID.fromString(NOTIFY_UUID));
        descriptor.setValue(enable ? ENABLE_NOTIFICATION_VALUE
            : DISABLE_NOTIFICATION_VALUE);
        bluetoothGatt.writeDescriptor(descriptor);
    }

    public abstract void updateConnectionState(int state);

    public abstract void addCharacteristic(
        BluetoothGattCharacteristic characteristic);

    public abstract void readCharacteristic(
        BluetoothGattCharacteristic characteristic);

    public abstract void writeCharacteristic(
        BluetoothGattCharacteristic characteristic);

    public abstract void changedCharacteristic(
        BluetoothGattCharacteristic characteristic);

    public abstract void writeDescriptor(BluetoothGattDescriptor descriptor);
}


text:
using Stiletto;

namespace ContainerCreateCallsRewritten
{
    public class InjectableClass
    {
        [Inject]
        public string Foo { get; set; }
    }

    [Module(Injects = new[] { typeof(InjectableClass) })]
    public class MainModule
    {
        [Provides]
        public string ProvideString()
        {
            return "foo";
        }
    }

    public class Program
    {
        public static void Main()
        {
            var container = Container.Create(typeof(MainModule));
            container.Get<InjectableClass>();
        }
    }
}


text:
using System;
using System.Collections;
using System.IO;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Security.Certificates;

namespace Org.BouncyCastle.X509.Extension
{
	public class X509ExtensionUtilities
	{
		public static Asn1Object FromExtensionValue(
			Asn1OctetString extensionValue)
		{
			return Asn1Object.FromByteArray(extensionValue.GetOctets());
		}

		public static ICollection GetIssuerAlternativeNames(
			X509Certificate cert)
		{
			Asn1OctetString extVal = cert.GetExtensionValue(X509Extensions.IssuerAlternativeName);

			return GetAlternativeName(extVal);
		}

		public static ICollection GetSubjectAlternativeNames(
			X509Certificate cert)
		{
			Asn1OctetString extVal = cert.GetExtensionValue(X509Extensions.SubjectAlternativeName);

			return GetAlternativeName(extVal);
		}

		private static ICollection GetAlternativeName(
			Asn1OctetString extVal)
		{
			ArrayList temp = new ArrayList();

			if (extVal != null)
			{
				try
				{
					Asn1Sequence seq = DerSequence.GetInstance(FromExtensionValue(extVal));

					foreach (GeneralName genName in seq)
					{
						ArrayList list = new ArrayList();
						list.Add(genName.TagNo);

						switch (genName.TagNo)
						{
							case GeneralName.EdiPartyName:
							case GeneralName.X400Address:
							case GeneralName.OtherName:
								list.Add(genName.Name.ToAsn1Object());
								break;
							case GeneralName.DirectoryName:
								list.Add(X509Name.GetInstance(genName.Name).ToString());
								break;
							case GeneralName.DnsName:
							case GeneralName.Rfc822Name:
							case GeneralName.UniformResourceIdentifier:
								list.Add(((IAsn1String)genName.Name).GetString());
								break;
							case GeneralName.RegisteredID:
								list.Add(DerObjectIdentifier.GetInstance(genName.Name).Id);
								break;
							case GeneralName.IPAddress:
								list.Add(DerOctetString.GetInstance(genName.Name).GetOctets());
								break;
							default:
								throw new IOException("Bad tag number: " + genName.TagNo);
						}

						temp.Add(list);
					}
				}
				catch (Exception e)
				{
					throw new CertificateParsingException(e.Message);
				}
			}

			return temp;
		}
	}
}


text:
package org.araneaframework.jsp.tag.uilib.form;

import javax.servlet.jsp.JspException;

/**
 * {@link org.araneaframework.jsp.tag.uilib.form.FormKeyboardHandlerHtmlTag FormKeyboardHandlerHtmlTag} with
 * keyCode="27" by default.
 *
 * @see org.araneaframework.jsp.tag.uilib.form.FormKeyboardHandlerHtmlTag
 * @author Konstantin Tretyakov (kt@webmedia.ee)
 *
 * @jsp.tag
 *  name = "formEscapeKeyboardHandler"
 *  body-content = "empty"
 *  description = "Equivalent of formKeyboardHandler, but keyCode="27" and event="onclick" by default. As usually, the parameters elementId/fullElementId/handler must be provided."
 */
public final class FormEscapeKeyboardHandlerHtmlTag extends FormKeyboardHandlerHtmlTag {

  public FormEscapeKeyboardHandlerHtmlTag() {
    this.keyCode = 27;
    this.event = "onclick";
  }

  /**
   * Throw an exception on attempt to set key. This tag supports 27 ("escape") only!
   */
  @Override
  public void setKeyCode(String key) throws JspException {
    throw new JspException("You may not set 'keyCode' for the escape handler tag!");
  }

  /**
   * Throw an exception on attempt to set key. This tag supports "escape" (27) only!
   */
  @Override
  public void setKeyMetaCond(String keyCode) throws JspException {
    throw new JspException("You may not set 'keyMetaCond' for the escape handler tag!");
  }
}


text:
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer (typeof (Moments.MomentsPicker), typeof (Moments.iOS.MomentsPickerRenderer))]
namespace Moments.iOS
{
	public class MomentsPickerRenderer : PickerRenderer
	{
		protected override void OnElementChanged (ElementChangedEventArgs<Picker> e)
		{
			base.OnElementChanged (e);

			if (e.OldElement != null || Element == null)
				return;

			try {
				Control.TextColor = UIColor.Clear;
				Control.Font = UIFont.FromName ("HelveticaNeue-Light", 16);
				Control.TextAlignment = UITextAlignment.Center;
				Control.BorderStyle = UITextBorderStyle.None;
			} catch (Exception ex) {
				Xamarin.Insights.Report (ex);
			}
		}
	}
}


text:
package io.sundr.builder.annotations;

/**
 * Annotation to mark that a {@link io.sundr.builder.Builder} wrapper should be generated, for inlining the builder into a DSL.
 */
public @interface Inline {

  /**
   * @return The name of the inline build method.
   */
  String value();

  /**
   * @return The prefix of the Inlinable.
   */
  String prefix() default "";

  /**
   * @return The name of the Inline builder.
   */
  String name() default "";

  /**
   * @return The suffix of the inlinable.
   */
  String suffix() default "";

  /**
   * @return The type of the item to build "inline"
   */
  Class type();

  /**
   * @return The return type of the "inline" method.
   */
  Class returnType() default None.class;
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <RetrievePropertiesResponse xmlns="urn:vim25">
            <returnval>
                <obj type="ClusterComputeResource">domain-c8</obj>
                <propSet>
                    <name>datastore</name>
                    <val xsi:type="ArrayOfManagedObjectReference">
                        <ManagedObjectReference type="Datastore" xsi:type="ManagedObjectReference">datastore-1003</ManagedObjectReference>
                    </val>
                </propSet>
            </returnval>
        </RetrievePropertiesResponse>
    </soapenv:Body>
</soapenv:Envelope>


text:
/* Internal dependencies */
#include "CISLinearResponseTimeDependentCalculator.h"
#include "CISSettings.h"
#include "CISSpinContaminator.h"
#include <Sparrow/Implementations/Exceptions.h>
#include <Sparrow/Implementations/Nddo/NDDOMethodWrapper.h>
#include <Sparrow/Implementations/Nddo/Utils/IntegralsEvaluationUtils/Global2c2eMatrix.h>
#include <Sparrow/Implementations/TimeDependent/DiagonalPreconditionerEvaluator.h>
#include <Sparrow/Implementations/TimeDependent/TimeDependentUtils.h>
#include <Utils/IO/NativeFilenames.h>
/* External dependencies */
#include <Core/Interfaces/Calculator.h>
#include <Core/Log.h>
#include <Utils/CalculatorBasics.h>
#include <Utils/CalculatorBasics/PropertyList.h>
#include <Utils/Constants.h>
#include <Utils/Math/IterativeDiagonalizer/DavidsonDiagonalizer.h>
#include <Utils/Math/IterativeDiagonalizer/DiagonalizerSettings.h>
#include <Utils/Scf/LcaoUtils/ElectronicOccupation.h>
#include <Utils/Scf/MethodExceptions.h>
#include <Utils/TimeDependent/TransitionDipoleCalculator.h>
#include <cereal/archives/xml.hpp>
#include <cereal/types/map.hpp>
#include <fstream>

namespace Scine {
namespace Sparrow {
InvalidCalculatorTypeForCIS::InvalidCalculatorTypeForCIS(std::shared_ptr<Scine::Core::Calculator> method) {
  error = "Calculator " + method->name() + " is not an NDDO method and cannot calculate CIS.";
}

void CISLinearResponseTimeDependentCalculator::setReferenceCalculator(std::shared_ptr<Scine::Core::Calculator> method) {
  nddoMethod_ = std::dynamic_pointer_cast<NDDOMethodWrapper>(method);
  if (!nddoMethod_) {
    throw InvalidCalculatorTypeForCIS(method);
  }
  cisData_ = std::make_unique<CISData>(nddoMethod_->getCISData());
}

CISLinearResponseTimeDependentCalculator::CISLinearResponseTimeDependentCalculator() {
  settings_ = std::make_unique<CISSettings>();
}

Utils::Results& CISLinearResponseTimeDependentCalculator::results() {
  return results_;
}

const Utils::Results& CISLinearResponseTimeDependentCalculator::results() const {
  return results_;
}

void CISLinearResponseTimeDependentCalculator::referenceCalculation() {
  if (!nddoMethod_)
    throw MissingReferenceCalculatorException();
  if (nddoMethod_->settings().getDouble(Utils::SettingsNames::selfConsistenceCriterion) > 1e-8) {
    nddoMethod_->settings().modifyDouble(Utils::SettingsNames::selfConsistenceCriterion, 1e-8);
  }
  nddoMethod_->setRequiredProperties(Utils::Property::Energy | Utils::Property::DipoleMatrixMO);
  nddoMethod_->calculate("CIS reference calculation.");
  cisData_ = std::make_unique<CISData>(nddoMethod_->getCISData());
}

Core::Calculator& CISLinearResponseTimeDependentCalculator::getReferenceCalculator() {
  return *nddoMethod_;
}

const Core::Calculator& CISLinearResponseTimeDependentCalculator::getReferenceCalculator() const {
  return *nddoMethod_;
}

Utils::Settings& CISLinearResponseTimeDependentCalculator::settings() {
  return *settings_;
}

const Utils::Settings& CISLinearResponseTimeDependentCalculator::settings() const {
  return *settings_;
}

std::string CISLinearResponseTimeDependentCalculator::name() const {
  return model;
}

void CISLinearResponseTimeDependentCalculator::applySettings() {
}

inline Eigen::MatrixXd generateGuess(int nConfigurations, int initialSubspaceDimension,
                                     std::shared_ptr<LinearResponseCalculator::GuessSpecifier> guess,
                                     Utils::SpinTransition spinBlock, Utils::Reference restrictedness) {
  if (!guess) {
    srand(42);
    Eigen::MatrixXd guessVectors = Eigen::MatrixXd::Identity(nConfigurations, initialSubspaceDimension);
    guessVectors.block(0, 0, nConfigurations, initialSubspaceDimension) +=
        0.01 * Eigen::MatrixXd::Random(nConfigurations, initialSubspaceDimension);
    return guessVectors;
  }
  else {
    if (restrictedness == Utils::Reference::Unrestricted) {
      assert(guess->unrestricted.rows() == nConfigurations);
      return guess->unrestricted;
    }
    else if (spinBlock == Utils::SpinTransition::Singlet) {
      assert(guess->singlet.rows() == nConfigurations);
      return guess->singlet;
    }
    else {
      assert(guess->triplet.rows() == nConfigurations);
      return guess->triplet;
    }
  }
}

inline int getNConfigurations(Utils::SpinAdaptedContainer<Utils::Reference::Restricted, Eigen::VectorXd> energyDiffVector) {
  return energyDiffVector.restricted.size();
}
inline int getNConfigurations(Utils::SpinAdaptedContainer<Utils::Reference::Unrestricted, Eigen::VectorXd> energyDiffVector) {
  return energyDiffVector.alpha.size() + energyDiffVector.beta.size();
}

template<Utils::Reference restrictedness>
Utils::ElectronicTransitionResult
CISLinearResponseTimeDependentCalculator::solve(Utils::SpinAdaptedContainer<restrictedness, Eigen::VectorXd> energyDifferenceVector,
                                                int numberOfEnergyLevels, int initialSubspaceDimension,
                                                Utils::SpinTransition spinBlock) {
  const int nConfigurations = getNConfigurations(energyDifferenceVector);

  // If 0 is given, then give all the energy levels
  if (numberOfEnergyLevels == 0 || numberOfEnergyLevels > nConfigurations) {
    numberOfEnergyLevels = nConfigurations;
  }
  if (initialSubspaceDimension == 0 || initialSubspaceDimension < numberOfEnergyLevels ||
      initialSubspaceDimension > nConfigurations) {
    initialSubspaceDimension = numberOfEnergyLevels;
  }

  checkMemoryRequirement(nConfigurations, numberOfEnergyLevels);

  Utils::NonOrthogonalDavidson diagonalizer(numberOfEnergyLevels, nConfigurations);
  diagonalizer.settings().modifyInt(Utils::initialGuessDimensionOption, initialSubspaceDimension);
  diagonalizer.settings().modifyDouble(Utils::residualNormToleranceOption, settings_->getDouble(convergence));
  diagonalizer.settings().modifyString("gep_algo", settings_->getString("gep_algo"));
  if (settings_->getInt(Utils::SettingsNames::maxDavidsonIterations) != 0) {
    diagonalizer.settings().modifyInt(Utils::SettingsNames::maxDavidsonIterations,
                                      settings_->getInt(Utils::SettingsNames::maxDavidsonIterations));
  }
  diagonalizer.setGuess(generateGuess(nConfigurations, initialSubspaceDimension, guess_, spinBlock, restrictedness));

  diagonalizer.setPreconditionerEvaluator(
      std::make_unique<DiagonalPreconditionerEvaluator>(energyDifferenceVector, OrderTag{}));
  diagonalizer.setSigmaVectorEvaluator(std::make_unique<CISSigmaVectorEvaluator<restrictedness>>(
      *cisData_, excitedStatesParam_, energyDifferenceVector, integralsThresholds_, orderMap_, spinBlock));

  Utils::ElectronicTransitionResult excitedStates;
  excitedStates.eigenStates = diagonalizer.solve(getLog());

  generateTransitionDipoleMoments<restrictedness>(excitedStates, *cisData_, spinBlock);

  //    results.spinContamination = CISSpinContaminator::calculateSpinContaminationOpenShell(
  //        cisData_->molecularOrbitals, results.eigenStates.eigenVectors,
  //        cisData_->occupation.getFilledAlphaOrbitals(), cisData_->occupation.getFilledBetaOrbitals(),
  //        excitationsIndices);

  return excitedStates;
}

void CISLinearResponseTimeDependentCalculator::checkMemoryRequirement(int excitationsDim, int numberOfEnergyLevels) {
  double memRequ = 0.;
  double maxMem = settings_->getDouble(Utils::SettingsNames::maxMemory);
  int nAtoms = cisData_->AOInfo.getNAtoms();
  int maxSubspaceDim = 0;
  if (numberOfEnergyLevels < 1000) { // Formula for good number of iterations before subspace collapse.
    maxSubspaceDim = static_cast<int>((6 * numberOfEnergyLevels + 50) - pow(numberOfEnergyLevels, 1.2));
    maxSubspaceDim += numberOfEnergyLevels - maxSubspaceDim % numberOfEnergyLevels;
  }
  else {
    maxSubspaceDim = 2 * numberOfEnergyLevels;
  }

  memRequ += static_cast<double>(maxSubspaceDim * excitationsDim * 2);

  for (int i = 0; i < nAtoms; ++i) {
    int nAOsI = cisData_->AOInfo.getNOrbitals(i);
    memRequ += static_cast<double>(std::pow(nAOsI, 4));
    for (int j = i + 1; j < nAtoms; ++j) {
      int nAOsJ = cisData_->AOInfo.getNOrbitals(j);
      memRequ += static_cast<double>(nAOsI * nAOsI * nAOsJ * nAOsJ);
    }
  }
  memRequ = memRequ * sizeof(double) * 1.e-9;
  getLog().output << "Memory Required: " << memRequ << " GB"
                  << " (specified maximum: " << maxMem << " GB).";
  if (memRequ > maxMem) {
    throw std::runtime_error("This calculation setup would require more memory than specified!"); // TODO setting for
                                                                                // allowed memory
  }
}

const Utils::Results& CISLinearResponseTimeDependentCalculator::calculate() {
  prepareIntegralScreening();
  if (!nddoMethod_) {
    throw std::runtime_error("No reference calculator assigned.");
  }
  if (!cisData_) {
    throw std::runtime_error("No CISData was set.");
  }
  if (!nddoMethod_->results().has<Utils::Property::Energy>()) {
    throw InvalidReferenceCalculationException();
  }

  Utils::SpinAdaptedElectronicTransitionResult transitionResult{};

  bool is_unrestricted = cisData_->occupation.isUnrestricted();
  int numberOfRoots = settings().getInt(Utils::SettingsNames::numberOfEigenstates);
  int initialSubspaceDimension = settings().getInt(Utils::SettingsNames::initialSubspaceDimension);

  if (!is_unrestricted) { // Here choose if restricted or unrestricted reference
    Utils::SpinAdaptedContainer<Utils::Reference::Restricted, Eigen::VectorXd> energyDifferenceVector;
    TimeDependentUtils::generateEnergyDifferenceVector(cisData_->MOEnergies, cisData_->occupation, energyDifferenceVector);
    orderMap_ = TimeDependentUtils::generateEnergyOrderMap(energyDifferenceVector);

    TimeDependentUtils::transformOrder(
        TimeDependentUtils::generateExcitationsLabels(TimeDependentUtils::generateExcitations<Utils::Reference::Restricted>(
            cisData_->molecularOrbitals, cisData_->occupation)),
        transitionResult.transitionLabels, orderMap_, TimeDependentUtils::Direction::To);

    auto spinBlock = settings_->getString(Utils::SettingsNames::spinBlock);

    if (spinBlock == Utils::SettingsNames::SpinBlocks::singlet || spinBlock == "both") { // If singlet
      setExcitedStatesParam(Utils::Reference::Restricted, Utils::SpinTransition::Singlet);
      transitionResult.singlet = std::make_unique<Utils::ElectronicTransitionResult>(
          solve(energyDifferenceVector, numberOfRoots, initialSubspaceDimension, Utils::SpinTransition::Singlet));
    }
    if (spinBlock == Utils::SettingsNames::SpinBlocks::triplet || spinBlock == "both") { // If triplet
      setExcitedStatesParam(Utils::Reference::Restricted, Utils::SpinTransition::Triplet);
      transitionResult.triplet = std::make_unique<Utils::ElectronicTransitionResult>(
          solve(energyDifferenceVector, numberOfRoots, initialSubspaceDimension, Utils::SpinTransition::Triplet));
    }
  }
  else { // If unrestricted
    Utils::SpinAdaptedContainer<Utils::Reference::Unrestricted, Eigen::VectorXd> energyDifferenceVector;
    TimeDependentUtils::generateEnergyDifferenceVector(cisData_->MOEnergies, cisData_->occupation, energyDifferenceVector);
    orderMap_ = TimeDependentUtils::generateEnergyOrderMap(energyDifferenceVector);
    TimeDependentUtils::transformOrder(TimeDependentUtils::generateExcitationsLabels(
                                           TimeDependentUtils::generateExcitations<Utils::Reference::Unrestricted>(
                                               cisData_->molecularOrbitals, cisData_->occupation)),
                                       transitionResult.transitionLabels, orderMap_, TimeDependentUtils::Direction::To);
    setExcitedStatesParam(Utils::Reference::Unrestricted, {});
    transitionResult.unrestricted = std::make_unique<Utils::ElectronicTransitionResult>(
        solve(energyDifferenceVector, numberOfRoots, initialSubspaceDimension));
  }

  results_.set<Utils::Property::ExcitedStates>(std::move(transitionResult));
  guess_.reset();
  return results_;
}

template<Utils::Reference restrictedness>
void CISLinearResponseTimeDependentCalculator::generateTransitionDipoleMoments(Utils::ElectronicTransitionResult& excitedStatesResults,
                                                                               const CISData& cisData,
                                                                               Utils::SpinTransition spinBlock) const {
  assert(!orderMap_.empty());
  // Triplets have a transition dipole moment of 0, the function transitionDipoleMoment just multiplies by 2 in the
  // restricted case so care must be taken.
  if (getReferenceCalculator().results().has<Utils::Property::DipoleMatrixMO>() && spinBlock == Utils::SpinTransition::Singlet) {
    std::vector<Utils::Excitation> orderedExcitation;
    TimeDependentUtils::transformOrder(TimeDependentUtils::flatten(TimeDependentUtils::generateExcitations<restrictedness>(
                                           cisData.molecularOrbitals, cisData.occupation)),
                                       orderedExcitation, orderMap_, TimeDependentUtils::Direction::To);

    excitedStatesResults.transitionDipoles = Utils::TransitionDipoleCalculator::calculate<restrictedness>(
        getReferenceCalculator().results().get<Utils::Property::DipoleMatrixMO>(),
        excitedStatesResults.eigenStates.eigenVectors, orderedExcitation);
  }
  else {
    excitedStatesResults.transitionDipoles = Eigen::Matrix3Xd::Zero(3, excitedStatesResults.eigenStates.eigenValues.size());
  }
}

void CISLinearResponseTimeDependentCalculator::prepareIntegralScreening() {
  int nAtoms = cisData_->AOInfo.getNAtoms();
  integralsThresholds_.clear();
  integralsThresholds_.resize(nAtoms);
  for (int atomI = 0; atomI < nAtoms; ++atomI) {
    for (int atomJ = atomI + 1; atomJ < nAtoms; ++atomJ) {
      const auto& twoCenterBlock = cisData_->twoCenterIntegrals.get(atomI, atomJ)->getGlobalMatrix();
      double maxIntegral = std::max(std::abs(twoCenterBlock.maxCoeff()), std::abs(twoCenterBlock.minCoeff()));
      integralsThresholds_[atomI].insert({maxIntegral, atomJ});
    }
  }
}

void CISLinearResponseTimeDependentCalculator::setExcitedStatesParam(Utils::Reference restrictedness,
                                                                     Utils::SpinTransition spinBlock) {
  std::string path = settings_->getString(Utils::SettingsNames::excitedStatesParamFile);
  std::map<std::string, ExcitedStatesParam> readExcParam = {};

  if (!path.empty()) {
    std::ifstream fs(path);
    if (!fs.is_open())
      throw Utils::Methods::ParameterFileCannotBeOpenedException(path);
    cereal::XMLInputArchive archive(fs);
    archive(readExcParam);
    if (restrictedness == Utils::Reference::Restricted) {
      if (spinBlock == Utils::SpinTransition::Singlet) {
        excitedStatesParam_ = readExcParam["S"];
      }
      if (spinBlock == Utils::SpinTransition::Triplet) {
        excitedStatesParam_ = readExcParam["T"];
      }
    }
    else if (restrictedness == Utils::Reference::Unrestricted) {
      excitedStatesParam_ = readExcParam["U"];
    }
    else
      throw std::runtime_error("CISLinearResponseTimeDependentCalulator: Invalid Reference");
  }
  else {
    excitedStatesParam_ = {1., 1., 1.};
  }
}

void CISLinearResponseTimeDependentCalculator::setGuess(std::shared_ptr<GuessSpecifier> guessVectorMatrix) {
  guess_ = std::move(guessVectorMatrix);
}

auto CISLinearResponseTimeDependentCalculator::getGuess() const -> std::shared_ptr<GuessSpecifier> {
  if (results_.has<Utils::Property::ExcitedStates>()) {
    auto guess = std::make_shared<GuessSpecifier>();
    const auto& excitedStates = results_.get<Utils::Property::ExcitedStates>();
    if (excitedStates.singlet) {
      guess->singlet = excitedStates.singlet->eigenStates.eigenVectors;
    }
    if (excitedStates.triplet) {
      guess->triplet = excitedStates.triplet->eigenStates.eigenVectors;
    }
    if (excitedStates.singlet) {
      guess->unrestricted = excitedStates.unrestricted->eigenStates.eigenVectors;
    }
    return guess;
  }
  else {
    return std::shared_ptr<GuessSpecifier>();
  }
}

} // namespace Sparrow
} // namespace Scine


text:
/*
Description
How many minutes do you spend on the problem?

Input
The input consists of two lines.
The first line contains two integer h1 and m1, separated from the symbol :, and h1:m1 is the time you begin to do the problem.
The second line contains two integer h2 and m2, separated from the symbol :, and h2:m2 is the time you finished the problem.

Output
You should output how many minutes you have spended on the problem on one line.

Sample Input
9:10
9:20

Sample Output
10

Source
yhr
*/
#include<stdio.h>
int main()
{
	int h1,m1,h2,m2,a;
	scanf("%d:%d",&h1,&m1);
	scanf("%d:%d",&h2,&m2);
	printf("%d\n",a=(m2-m1)+(h2-h1)*60);
	return 0;
}


text:
/**
 * Entrypoint module for the SparkMonitor frontend extension.
 *
 * @module module
 */

import SparkMonitor from './SparkMonitor'
import currentcell from './currentcell'

/** Entrypoint: Called when the extension is loaded by jupyter. */
function load_ipython_extension() {
	console.log('SparkMonitor: Loading SparkMonitor Front-End Extension');
	var monitor = new SparkMonitor();
	window.sm = monitor;
	currentcell.register();
}

export { load_ipython_extension }


text:
module xlib.reflection.properties {

  export interface IOptions {}

}


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
N. Z. Jl Bot. 42(5): 929 (2004)

#### Original name
Phyllachora rostkoviae P.R. Johnst. & P.F. Cannon, 2004

### Remarks
null


text:
"""
API base application
===============================================

.. module:: apibase
    :platform: Django
    :synopsis: API base application
.. moduleauthor:: (C) 2014 Oliver Gutiérrez
"""

# Application imports
from sitetools.utils import inject_app_defaults

# Default application settings injection
inject_app_defaults(__name__)


text:
<?php
/**
 * Created by PhpStorm.
 * User: elex
 * Date: 10.01.18
 * Time: 19:02
 */
namespace OCA\SensorLogger\Controller;

use PHPUnit_Framework_TestCase;

class apisensorloggercontrollerTest extends PHPUnit_Framework_TestCase
{

    private $controller;
    private $mapper;
    private $userId = 'john';

    public function setUp() {

    }

    public function testCreateLog() {

    }

}


text:
Implementation aspects & how-tos:
* [Configuration](CONFIG.md)
* [Logging](LOGGING.md)
* Plugins
  * [Lifecycle](PLUGIN_LIFECYCLE.md)
  * [Dependencies](PLUGIN_DEPENDENCIES.md)
  * [Flavours](PLUGIN_FLAVORS.md)
* [System integration](SYSTEM_INTEGRATION.md) - connecting to DB / Message Bus, calling RPCs

Implementation is not good enough without:
* [Comments, READMEs, doc.go](DOCUMENTING.md)
* [Examples](EXAMPLES.md)
* [Testing](TESTING.md)
* Proper [coding style](CODINGSTYLE.md)


text:
#ifndef FdoCommonOSUtil___H
#define FdoCommonOSUtil___H	1

// Operating-System-independent c-style declarations:
#ifdef _WIN32
#define OS__cdecl __cdecl
#else // not _WIN32
#define OS__cdecl
#endif

// This class define methods that run on both Windows and Linux.
class FdoCommonOSUtil
{
public:
    /// format a wide-char string to a wide-char string:
    static int swprintf(wchar_t* buffer, size_t bufferSize, const wchar_t* format, ...);

    /// format a char string to a char string:
    static int scprintf(char* buffer, size_t bufferSize, const char* format, ...);

    /// convert a double to an ascii string:
    static char* gcvt(double number, size_t ndigit, char *buf);

    /// compare two ascii strings in a case-insensitive manner:
    static int stricmp(const char *s1, const char *s2);
    static int strnicmp(const char *s1, const char *s2, size_t len);

    /// compare two unicode strings in a case-insensitive manner:
    static int wcsicmp(const wchar_t *s1, const wchar_t *s2);
    static int wcsnicmp(const wchar_t *s1, const wchar_t *s2, size_t len);

    /// convert an int to an ascii string (radix is always 10):
    static char* itoa(int value, char* buffer);

    /// convert a long to an ascii string (radix is always 10):
    static char* ltoa(long value, char* buffer);

    /// convert an int to a wide string (radix is always 10):
    static wchar_t* itow(int value, wchar_t* buffer, size_t bufferSize);

    /// convert a long to a wide string (radix is always 10):
    static wchar_t* ltow(long value, wchar_t* buffer, size_t bufferSize);

    /// convert a string to an int (radix is always 10):
    static int wtoi(const wchar_t* value);

    /// convert a string to a floating point value
    static double wtof(const wchar_t* value);

    /// multibyte character string functions:
    static int ismbslead(const unsigned char *string, const unsigned char *current);
    static int ismbstrail(const unsigned char *string, const unsigned char *current);
    static int ismbcalnum(const unsigned char *string, long stringLength, const unsigned char *current);
    static int ismbcalpha(const unsigned char *string, long stringLength, const unsigned char *current);
    static char* mbscat(char *strDestination, const char *strSource);

    /// get current system time:
    static void getsystime(struct tm *systime);

    /// tokenize a unicode string:
    static wchar_t* wcstok(wchar_t *tokens, const wchar_t *delimiters, wchar_t **state);

    /// Convert a wide string to uppercase:
    static wchar_t* wcsupr(wchar_t* str);

    /// Convert a wide string to lowercase:
    static wchar_t* wcslwr(wchar_t* str);

    /// Return a duplicate copy of a wide string (use free() to deallocate):
    static wchar_t* wcsdup(wchar_t* str);

    /// Tests for Not-A-Number (NaN), returns non-zero if value is NaN, returns zero otherwise:
    static int _isnan(double value);

    /// Fetch a wide char from input:
    static wint_t _getwch(void);

    /// Set an environment variable:
    static void setenv(const char *varname, const char *varvalue);

    /// Get the current user's name:
    static FdoStringP GetCurrentUserName(void);
};

#endif // FdoCommonOSUtil___H


text:
define([
	'amd.namespace'
], function(namespace) {
	'use strict';

	function Storage() {}

	/**
	 * Setting data into browser's local storage
	 * @method setData
	 * @param {String} key Key for stored value
	 * @param {Object} data JSON object will going to stringify and store as String
	 * @requires compatibility.polyfill.localstorage
	 * @default {Boolean} true
	 * @return {Boolean} true
	 */
	Storage.prototype.setData = function(key, data) {
		localStorage.setItem(key, JSON.stringify(data));
		return true;
	};

	/**
	 * Getting data from browser's local storage
	 * @method getData
	 * @param {String} key Key for stored value
	 * @requires compatibility.polyfill.localstorage
	 * @return {Object|Boolean} JSON parsed object | false
	 */
	Storage.prototype.getData = function(key) {
		if (localStorage.getItem(key)) {
			return JSON.parse(localStorage.getItem(key));
		}
		return false;
	};

	namespace.Storage = new Storage();
	return namespace.Storage;
});


text:
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**success** | **string** |  | [default to null]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


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

<title>java.net Class Hierarchy (Java Platform SE 7 )</title>
<meta name="date" content="2014-12-18">
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Java™ Platform
Standard Ed. 7

Prev

Next

Frames

No Frames

All Classes

Hierarchy For Package java.net

Package Hierarchies:

All Packages

Class Hierarchy

java.lang.Object

java.net.Authenticator

java.net.CacheRequest

java.net.CacheResponse

java.net.SecureCacheResponse

java.lang.ClassLoader

java.security.SecureClassLoader

java.net.URLClassLoader (implements java.io.Closeable)

java.net.ContentHandler

java.net.CookieHandler

java.net.CookieManager

java.net.DatagramPacket

java.net.DatagramSocket (implements java.io.Closeable)

java.net.MulticastSocket

java.net.DatagramSocketImpl (implements java.net.SocketOptions)

java.net.HttpCookie (implements java.lang.Cloneable)

java.net.IDN

java.net.InetAddress (implements java.io.Serializable)

java.net.Inet4Address

java.net.Inet6Address

java.net.InterfaceAddress

java.net.NetworkInterface

java.net.PasswordAuthentication

java.security.Permission (implements java.security.Guard, java.io.Serializable)

java.security.BasicPermission (implements java.io.Serializable)

java.net.NetPermission

java.net.SocketPermission (implements java.io.Serializable)

java.net.Proxy

java.net.ProxySelector

java.net.ResponseCache

java.net.ServerSocket (implements java.io.Closeable)

java.net.Socket (implements java.io.Closeable)

java.net.SocketAddress (implements java.io.Serializable)

java.net.InetSocketAddress

java.net.SocketImpl (implements java.net.SocketOptions)

java.net.StandardSocketOptions

java.lang.Throwable (implements java.io.Serializable)

java.lang.Exception

java.io.IOException

java.net.HttpRetryException

java.io.InterruptedIOException

java.net.SocketTimeoutException

java.net.MalformedURLException

java.net.ProtocolException

java.net.SocketException

java.net.BindException

java.net.ConnectException

java.net.NoRouteToHostException

java.net.PortUnreachableException

java.net.UnknownHostException

java.net.UnknownServiceException

java.net.URISyntaxException

java.net.URI (implements java.lang.Comparable<T>, java.io.Serializable)

java.net.URL (implements java.io.Serializable)

java.net.URLConnection

java.net.HttpURLConnection

java.net.JarURLConnection

java.net.URLDecoder

java.net.URLEncoder

java.net.URLStreamHandler

Interface Hierarchy

java.net.ContentHandlerFactory

java.net.CookiePolicy

java.net.CookieStore

java.net.DatagramSocketImplFactory

java.net.FileNameMap

java.net.ProtocolFamily

java.net.SocketImplFactory

java.net.SocketOption<T>

java.net.SocketOptions

java.net.URLStreamHandlerFactory

Enum Hierarchy

java.lang.Object

java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)

java.net.StandardProtocolFamily (implements java.net.ProtocolFamily)

java.net.Proxy.Type

java.net.Authenticator.RequestorType

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Java™ Platform
Standard Ed. 7

Prev

Next

Frames

No Frames

All Classes

 Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2015, Oracle and/or its affiliates.  All rights reserved.


text:
"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./lib/number"));
__export(require("./main"));
var words_1 = require("./words");
exports.words = words_1.default;
var templates_1 = require("./templates");
exports.Genre = templates_1.Genre;
exports.isGenre = templates_1.isGenre;
exports.templates = templates_1.templates;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxrQ0FBNkI7QUFDN0IsNEJBQXVCO0FBRXZCLGlDQUF5QztBQUFqQyx3QkFBQSxPQUFPLENBQVM7QUFDeEIseUNBQXNEO0FBQTlDLDRCQUFBLEtBQUssQ0FBQTtBQUFFLDhCQUFBLE9BQU8sQ0FBQTtBQUFFLGdDQUFBLFNBQVMsQ0FBQSJ9


text:
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("http://mockbin.com/har"),
    Content = new MultipartFormDataContent
    {
        new StringContent("Hello World")
        {
            Headers =
            {
                ContentType = new MediaTypeHeaderValue("text/plain"),
                ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "foo",
                    FileName = "hello.txt",
                }
            }
        },
    },
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}


text:
require 'set'
require 'elasticity'
require 'sluice'
require 'awrence'
require 'json'
require 'base64'
require 'contracts'
require 'iglu-client'
require 'securerandom'
require 'tempfile'
require 'fog'

# Ruby class to execute Snowplow's Hive jobs against Amazon EMR
# using Elasticity (https://github.com/rslifka/elasticity).
module Snowplow
  module EmrEtlRunner
    class EmrJob

      include Contracts

      # Constants
      JAVA_PACKAGE = "com.snowplowanalytics.snowplow"
      PARTFILE_REGEXP = ".*part-.*"
      SUCCESS_REGEXP = ".*_SUCCESS"
      STANDARD_HOSTED_ASSETS = "s3://snowplow-hosted-assets"
      ENRICH_STEP_INPUT = 'hdfs:///local/snowplow/raw-events/'
      ENRICH_STEP_OUTPUT = 'hdfs:///local/snowplow/enriched-events/'
      SHRED_STEP_OUTPUT = 'hdfs:///local/snowplow/shredded-events/'

      # Need to understand the status of all our jobflow steps
      @@running_states = Set.new(%w(WAITING RUNNING PENDING SHUTTING_DOWN))
      @@failed_states  = Set.new(%w(FAILED CANCELLED))

      include Monitoring::Logging
      include Snowplow::EmrEtlRunner::Utils

      # Initializes our wrapper for the Amazon EMR client.
      Contract Bool, Bool, Bool, Bool, Bool, Bool, Bool, ArchiveStep, ArchiveStep, ConfigHash, ArrayOf[String], String, TargetsHash, RdbLoaderSteps => EmrJob
      def initialize(debug, staging, enrich, shred, es, archive_raw, rdb_load, archive_enriched, archive_shredded, config, enrichments_array, resolver, targets, rdbloader_steps)

        logger.debug "Initializing EMR jobflow"

        # Configuration
        custom_assets_bucket =
          get_hosted_assets_bucket(STANDARD_HOSTED_ASSETS, config[:aws][:s3][:buckets][:assets], config[:aws][:emr][:region])
        standard_assets_bucket =
          get_hosted_assets_bucket(STANDARD_HOSTED_ASSETS, STANDARD_HOSTED_ASSETS, config[:aws][:emr][:region])
        assets = get_assets(
          custom_assets_bucket,
          config[:enrich][:versions][:spark_enrich],
          config[:storage][:versions][:rdb_shredder],
          config[:storage][:versions][:hadoop_elasticsearch],
          config[:storage][:versions][:rdb_loader])

        collector_format = config[:collectors][:format]
        run_tstamp = Time.new
        run_id = run_tstamp.strftime("%Y-%m-%d-%H-%M-%S")
        @run_id = run_id
        @rdb_loader_log_base = config[:aws][:s3][:buckets][:log] + "rdb-loader/#{@run_id}/"
        @rdb_loader_logs = []   # pairs of target name and associated log
        etl_tstamp = (run_tstamp.to_f * 1000).to_i.to_s
        output_codec = output_codec_from_compression_format(config[:enrich][:output_compression])

        s3 = Sluice::Storage::S3::new_fog_s3_from(
          config[:aws][:s3][:region],
          config[:aws][:access_key_id],
          config[:aws][:secret_access_key])

        # Configure Elasticity with your AWS credentials
        Elasticity.configure do |c|
          c.access_key = config[:aws][:access_key_id]
          c.secret_key = config[:aws][:secret_access_key]
        end

        # Create a job flow
        @jobflow = Elasticity::JobFlow.new

        # Configure
        @jobflow.name                 = config[:aws][:emr][:jobflow][:job_name]

        if config[:aws][:emr][:ami_version] =~ /^[1-3].*/
          @legacy = true
          @jobflow.ami_version = config[:aws][:emr][:ami_version]
        else
          @legacy = false
          @jobflow.release_label = "emr-#{config[:aws][:emr][:ami_version]}"
        end

        @jobflow.tags                 = config[:monitoring][:tags]
        @jobflow.ec2_key_name         = config[:aws][:emr][:ec2_key_name]

        @jobflow.region               = config[:aws][:emr][:region]
        @jobflow.job_flow_role        = config[:aws][:emr][:jobflow_role] # Note job_flow vs jobflow
        @jobflow.service_role         = config[:aws][:emr][:service_role]
        @jobflow.placement            = config[:aws][:emr][:placement]
        @jobflow.additional_info      = config[:aws][:emr][:additional_info]
        unless config[:aws][:emr][:ec2_subnet_id].nil? # Nils placement so do last and conditionally
          @jobflow.ec2_subnet_id      = config[:aws][:emr][:ec2_subnet_id]
        end

        @jobflow.log_uri              = config[:aws][:s3][:buckets][:log]
        @jobflow.enable_debugging     = debug
        @jobflow.visible_to_all_users = true

        @jobflow.instance_count       = config[:aws][:emr][:jobflow][:core_instance_count] + 1 # +1 for the master instance
        @jobflow.master_instance_type = config[:aws][:emr][:jobflow][:master_instance_type]
        @jobflow.slave_instance_type  = config[:aws][:emr][:jobflow][:core_instance_type]

        s3_endpoint = get_s3_endpoint(config[:aws][:s3][:region])
        csbr = config[:aws][:s3][:buckets][:raw]
        csbe = config[:aws][:s3][:buckets][:enriched]
        csbs = config[:aws][:s3][:buckets][:shredded]

        # staging
        if staging
          src_pattern = collector_format == 'clj-tomcat' ? '.*localhost\_access\_log.*\.txt.*' : '.+'
          src_pattern_regex = Regexp.new src_pattern
          non_empty_locs = csbr[:in].select { |l|
            loc = Sluice::Storage::S3::Location.new(l)
            files = Sluice::Storage::S3::list_files(s3, loc)
              .select { |f| !(f.key =~ src_pattern_regex).nil? }
            files.length > 0
          }

          if non_empty_locs.empty?
            raise NoDataToProcessError, "No Snowplow logs to process since last run"
          else
            non_empty_locs.each { |l|
              staging_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
              staging_step.arguments = [
                "--src", l,
                "--dest", csbr[:processing],
                "--s3Endpoint", s3_endpoint,
                "--srcPattern", src_pattern,
                "--deleteOnSuccess"
              ]
              if collector_format == 'clj-tomcat'
                staging_step.arguments = staging_step.arguments + [ '--groupBy', '.*/_*(.+)' ]
              end
              staging_step.name << ": Raw #{l} -> Raw Staging S3"
              @jobflow.add_step(staging_step)
            }
          end
        end

        # EBS
        unless config[:aws][:emr][:jobflow][:core_instance_ebs].nil?
          ebs_bdc = Elasticity::EbsBlockDeviceConfig.new

          ebs_bdc.volume_type          = config[:aws][:emr][:jobflow][:core_instance_ebs][:volume_type]
          ebs_bdc.size_in_gb           = config[:aws][:emr][:jobflow][:core_instance_ebs][:volume_size]
          ebs_bdc.volumes_per_instance = 1
          if config[:aws][:emr][:jobflow][:core_instance_ebs][:volume_type] == "io1"
            ebs_bdc.iops = config[:aws][:emr][:jobflow][:core_instance_ebs][:volume_iops]
          end

          ebs_c = Elasticity::EbsConfiguration.new
          ebs_c.add_ebs_block_device_config(ebs_bdc)
          ebs_c.ebs_optimized = true

          unless config[:aws][:emr][:jobflow][:core_instance_ebs][:ebs_optimized].nil?
            ebs_c.ebs_optimized = config[:aws][:emr][:jobflow][:core_instance_ebs][:ebs_optimized]
          end

          @jobflow.set_core_ebs_configuration(ebs_c)
        end
        @jobflow.add_application("Hadoop")

        if collector_format == 'thrift'
          if @legacy
            [
              Elasticity::HadoopBootstrapAction.new('-c', 'io.file.buffer.size=65536'),
              Elasticity::HadoopBootstrapAction.new('-m', 'mapreduce.user.classpath.first=true')
            ].each do |action|
              @jobflow.add_bootstrap_action(action)
            end
          else
            [{
              "Classification" => "core-site",
              "Properties" => {
                "io.file.buffer.size" => "65536"
              }
            },
            {
              "Classification" => "mapred-site",
              "Properties" => {
                "mapreduce.user.classpath.first" => "true"
              }
            }].each do |config|
              @jobflow.add_configuration(config)
            end
          end
        end

        # Add custom bootstrap actions
        bootstrap_actions = config[:aws][:emr][:bootstrap]
        unless bootstrap_actions.nil?
          bootstrap_actions.each do |bootstrap_action|
            @jobflow.add_bootstrap_action(Elasticity::BootstrapAction.new(bootstrap_action))
          end
        end

        # Prepare a bootstrap action based on the AMI version
        bootstrap_script_location = if @legacy
          "#{standard_assets_bucket}common/emr/snowplow-ami3-bootstrap-0.1.0.sh"
        else
          "#{standard_assets_bucket}common/emr/snowplow-ami4-bootstrap-0.2.0.sh"
        end
        cc_version = get_cc_version(config[:enrich][:versions][:spark_enrich])
        @jobflow.add_bootstrap_action(Elasticity::BootstrapAction.new(bootstrap_script_location, cc_version))

        # Install and launch HBase
        hbase = config[:aws][:emr][:software][:hbase]
        unless not hbase
          install_hbase_action = Elasticity::BootstrapAction.new("s3://#{config[:aws][:emr][:region]}.elasticmapreduce/bootstrap-actions/setup-hbase")
          @jobflow.add_bootstrap_action(install_hbase_action)

          start_hbase_step = Elasticity::CustomJarStep.new("/home/hadoop/lib/hbase-#{hbase}.jar")
          start_hbase_step.name = "Start HBase #{hbase}"
          start_hbase_step.arguments = [ 'emr.hbase.backup.Main', '--start-master' ]
          @jobflow.add_step(start_hbase_step)
        end

        # Install Lingual
        lingual = config[:aws][:emr][:software][:lingual]
        unless not lingual
          install_lingual_action = Elasticity::BootstrapAction.new("s3://files.concurrentinc.com/lingual/#{lingual}/lingual-client/install-lingual-client.sh")
          @jobflow.add_bootstrap_action(install_lingual_action)
        end

        # EMR configuration: Spark, YARN, etc
        configuration = config[:aws][:emr][:configuration]
        unless configuration.nil?
          configuration.each do |k, h|
            @jobflow.add_configuration({"Classification" => k, "Properties" => h})
          end
        end

        # Now let's add our task group if required
        tic = config[:aws][:emr][:jobflow][:task_instance_count]
        if tic > 0
          instance_group = Elasticity::InstanceGroup.new.tap { |ig|
            ig.count = tic
            ig.type  = config[:aws][:emr][:jobflow][:task_instance_type]

            tib = config[:aws][:emr][:jobflow][:task_instance_bid]
            if tib.nil?
              ig.set_on_demand_instances
            else
              ig.set_spot_instances(tib)
            end
          }

          @jobflow.set_task_instance_group(instance_group)
        end

        enrich_final_output = if enrich
          partition_by_run(csbe[:good], run_id)
        else
          csbe[:good] # Doesn't make sense to partition if enrich has already been done
        end

        if enrich

          raw_input = csbr[:processing]

          # for ndjson/urbanairship we can group by everything, just aim for the target size
          group_by = is_ua_ndjson(collector_format) ? ".*\/(\w+)\/.*" : ".*([0-9]+-[0-9]+-[0-9]+)-[0-9]+.*"

          # Create the Hadoop MR step for the file crushing
          compact_to_hdfs_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          compact_to_hdfs_step.arguments = [
            "--src"         , raw_input,
            "--dest"        , ENRICH_STEP_INPUT,
            "--s3Endpoint"  , s3_endpoint
          ] + [
            "--groupBy"     , group_by,
            "--targetSize"  , "128",
            "--outputCodec" , "lzo"
          ].select { |el|
            is_cloudfront_log(collector_format) || is_ua_ndjson(collector_format)
          }
          compact_to_hdfs_step.name << ": Raw S3 -> Raw HDFS"

          # Add to our jobflow
          @jobflow.add_step(compact_to_hdfs_step)

          # 2. Enrichment
          enrich_step =
            if is_spark_enrich(config[:enrich][:versions][:spark_enrich]) then
              @jobflow.add_application("Spark")
              build_spark_step(
                "Enrich Raw Events",
                assets[:enrich],
                "enrich.spark.EnrichJob",
                { :in     => glob_path(ENRICH_STEP_INPUT),
                  :good   => ENRICH_STEP_OUTPUT,
                  :bad    => partition_by_run(csbe[:bad],    run_id)
                },
                { 'input-format'    => collector_format,
                  'etl-timestamp'   => etl_tstamp,
                  'iglu-config'     => build_iglu_config_json(resolver),
                  'enrichments'     => build_enrichments_json(enrichments_array)
                }
              )
            else
              build_scalding_step(
                "Enrich Raw Events",
                assets[:enrich],
                "enrich.hadoop.EtlJob",
                { :in     => glob_path(ENRICH_STEP_INPUT),
                  :good   => ENRICH_STEP_OUTPUT,
                  :bad    => partition_by_run(csbe[:bad],    run_id),
                  :errors => partition_by_run(csbe[:errors], run_id, config[:enrich][:continue_on_unexpected_error])
                },
                { :input_format     => collector_format,
                  :etl_tstamp       => etl_tstamp,
                  :iglu_config      => build_iglu_config_json(resolver),
                  :enrichments      => build_enrichments_json(enrichments_array)
                }
              )
            end

          # Late check whether our enrichment directory is empty. We do an early check too
          csbe_good_loc = Sluice::Storage::S3::Location.new(csbe[:good])
          unless Sluice::Storage::S3::is_empty?(s3, csbe_good_loc)
            raise DirectoryNotEmptyError, "Cannot safely add enrichment step to jobflow, #{csbe_good_loc} is not empty"
          end
          @jobflow.add_step(enrich_step)

          # We need to copy our enriched events from HDFS back to S3
          copy_to_s3_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          copy_to_s3_step.arguments = [
            "--src"        , ENRICH_STEP_OUTPUT,
            "--dest"       , enrich_final_output,
            "--srcPattern" , PARTFILE_REGEXP,
            "--s3Endpoint" , s3_endpoint
          ] + output_codec
          copy_to_s3_step.name << ": Enriched HDFS -> S3"
          @jobflow.add_step(copy_to_s3_step)

          copy_success_file_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          copy_success_file_step.arguments = [
            "--src"        , ENRICH_STEP_OUTPUT,
            "--dest"       , enrich_final_output,
            "--srcPattern" , SUCCESS_REGEXP,
            "--s3Endpoint" , s3_endpoint
          ]
          copy_success_file_step.name << ": Enriched HDFS _SUCCESS -> S3"
          @jobflow.add_step(copy_success_file_step)
        end

        if shred

          # 3. Shredding
          shred_final_output = partition_by_run(csbs[:good], run_id)

          # If we enriched, we free some space on HDFS by deleting the raw events
          # otherwise we need to copy the enriched events back to HDFS
          if enrich
            @jobflow.add_step(get_rmr_step(ENRICH_STEP_INPUT, standard_assets_bucket))
          else
            copy_to_hdfs_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
            copy_to_hdfs_step.arguments = [
              "--src"        , enrich_final_output, # Opposite way round to normal
              "--dest"       , ENRICH_STEP_OUTPUT,
              "--srcPattern" , PARTFILE_REGEXP,
              "--s3Endpoint" , s3_endpoint
            ] # Either user doesn't want compression, or files are already compressed
            copy_to_hdfs_step.name << ": Enriched S3 -> HDFS"
            @jobflow.add_step(copy_to_hdfs_step)
          end

          shred_step =
            if is_rdb_shredder(config[:storage][:versions][:rdb_shredder]) then
              @jobflow.add_application("Spark")
              duplicate_storage_config = build_duplicate_storage_json(targets[:DUPLICATE_TRACKING], false)
              build_spark_step(
                "Shred Enriched Events",
                assets[:shred],
                "storage.spark.ShredJob",
                { :in   => glob_path(ENRICH_STEP_OUTPUT),
                  :good => SHRED_STEP_OUTPUT,
                  :bad  => partition_by_run(csbs[:bad], run_id)
                },
                {
                  'iglu-config' => build_iglu_config_json(resolver)
                }.merge(duplicate_storage_config)
              )
            else
              duplicate_storage_config = build_duplicate_storage_json(targets[:DUPLICATE_TRACKING])
              build_scalding_step(
                "Shred Enriched Events",
                assets[:shred],
                "enrich.hadoop.ShredJob",
                { :in          => glob_path(ENRICH_STEP_OUTPUT),
                  :good        => SHRED_STEP_OUTPUT,
                  :bad         => partition_by_run(csbs[:bad],    run_id),
                  :errors      => partition_by_run(csbs[:errors], run_id, config[:enrich][:continue_on_unexpected_error])
                },
                {
                  :iglu_config => build_iglu_config_json(resolver)
                }.merge(duplicate_storage_config)
              )
            end

          # Late check whether our target directory is empty
          csbs_good_loc = Sluice::Storage::S3::Location.new(csbs[:good])
          unless Sluice::Storage::S3::is_empty?(s3, csbs_good_loc)
            raise DirectoryNotEmptyError, "Cannot safely add shredding step to jobflow, #{csbs_good_loc} is not empty"
          end
          @jobflow.add_step(shred_step)

          # We need to copy our shredded types from HDFS back to S3
          copy_to_s3_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          copy_to_s3_step.arguments = [
            "--src"        , SHRED_STEP_OUTPUT,
            "--dest"       , shred_final_output,
            "--srcPattern" , PARTFILE_REGEXP,
            "--s3Endpoint" , s3_endpoint
          ] + output_codec
          copy_to_s3_step.name << ": Shredded HDFS -> S3"
          @jobflow.add_step(copy_to_s3_step)

          copy_success_file_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          copy_success_file_step.arguments = [
            "--src"        , SHRED_STEP_OUTPUT,
            "--dest"       , shred_final_output,
            "--srcPattern" , SUCCESS_REGEXP,
            "--s3Endpoint" , s3_endpoint
          ]
          copy_success_file_step.name << ": Shredded HDFS _SUCCESS -> S3"
          @jobflow.add_step(copy_success_file_step)
        end

        if es
          get_elasticsearch_steps(config, assets, enrich, shred, targets[:FAILED_EVENTS]).each do |step|
            @jobflow.add_step(step)
          end
        end

        if archive_raw
          # We need to copy our enriched events from HDFS back to S3
          archive_raw_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
          archive_raw_step.arguments = [
            "--src"        , csbr[:processing],
            "--dest"       , partition_by_run(csbr[:archive], run_id),
            "--s3Endpoint" , s3_endpoint,
            "--deleteOnSuccess"
          ]
          archive_raw_step.name << ": Raw Staging S3 -> Raw Archive S3"
          @jobflow.add_step(archive_raw_step)
        end

        if rdb_load
          get_rdb_loader_steps(config, targets[:ENRICHED_EVENTS], resolver, assets[:loader], rdbloader_steps).each do |step|
            @jobflow.add_step(step)
          end
        end

        if archive_enriched == 'pipeline'
          archive_enriched_step = get_archive_step(csbe[:good], csbe[:archive], run_id, s3_endpoint, ": Enriched S3 -> Enriched Archive S3")
          @jobflow.add_step(archive_enriched_step)
        elsif archive_enriched == 'recover'
          latest_run_id = get_latest_run_id(s3, csbe[:good])
          archive_enriched_step = get_archive_step(csbe[:good], csbe[:archive], latest_run_id, s3_endpoint, ': Enriched S3 -> S3 Enriched Archive')
          @jobflow.add_step(archive_enriched_step)
        else    # skip
          nil
        end

        if archive_shredded == 'pipeline'
          archive_shredded_step = get_archive_step(csbs[:good], csbs[:archive], run_id, s3_endpoint, ": Shredded S3 -> Shredded Archive S3")
          @jobflow.add_step(archive_shredded_step)
        elsif archive_shredded == 'recover'
          latest_run_id = get_latest_run_id(s3, csbe[:good])
          archive_shredded_step = get_archive_step(csbs[:good], csbs[:archive], latest_run_id, s3_endpoint, ": Shredded S3 -> S3 Shredded Archive")
          @jobflow.add_step(archive_shredded_step)
        else    # skip
          nil
        end

        self
      end

      # Create one step for each Elasticsearch target for each source for that target
      #
      Contract ConfigHash, Hash, Bool, Bool, ArrayOf[Iglu::SelfDescribingJson] => ArrayOf[Elasticity::ScaldingStep]
      def get_elasticsearch_steps(config, assets, enrich, shred, failure_storages)

        # The default sources are the enriched and shredded errors generated for this run
        sources = []
        sources << partition_by_run(config[:aws][:s3][:buckets][:enriched][:bad], @run_id) if enrich
        sources << partition_by_run(config[:aws][:s3][:buckets][:shredded][:bad], @run_id) if shred

        steps = failure_storages.flat_map { |target|

          sources.map { |source|
            step = Elasticity::ScaldingStep.new(
              assets[:elasticsearch],
              "com.snowplowanalytics.snowplow.storage.hadoop.ElasticsearchJob",
              ({
                :input => source,
                :host => target.data[:host],
                :port => target.data[:port].to_s,
                :index => target.data[:index],
                :type => target.data[:type],
                :es_nodes_wan_only => target.data[:nodesWanOnly] ? "true" : "false"
              }).reject { |k, v| v.nil? }
            )
            step_name = "Errors in #{source} -> Elasticsearch: #{target.data[:name]}"
            step.name << ": #{step_name}"
            step
          }
        }

        # Wait 60 seconds before starting the first step so S3 can become consistent
        if (enrich || shred) && steps.any?
          steps[0].arguments << '--delay' << '60'
        end
        steps
      end

      # Run (and wait for) the daily ETL job.
      #
      # Throws a BootstrapFailureError if the job fails due to a bootstrap failure.
      # Throws an EmrExecutionError if the jobflow fails for any other reason.
      Contract ConfigHash => nil
      def run(config)

        snowplow_tracking_enabled = ! config[:monitoring][:snowplow].nil?

        jobflow_id = @jobflow.run
        logger.debug "EMR jobflow #{jobflow_id} started, waiting for jobflow to complete..."

        if snowplow_tracking_enabled
          Monitoring::Snowplow.parameterize(config)
          Monitoring::Snowplow.instance.track_job_started(@jobflow)
        end

        status = wait_for()

        if status.successful or status.rdb_loader_failure or status.rdb_loader_cancellation
          log_level = if status.successful
            'info'
          elsif status.rdb_loader_cancellation
            'warn'
          else
            'error'
          end
          output_rdb_loader_logs(config[:aws][:s3][:region], config[:aws][:access_key_id],
            config[:aws][:secret_access_key], log_level)
        end

        if status.successful
          logger.debug "EMR jobflow #{jobflow_id} completed successfully."
          if snowplow_tracking_enabled
            Monitoring::Snowplow.instance.track_job_succeeded(@jobflow)
          end

        elsif status.bootstrap_failure
          if snowplow_tracking_enabled
            Monitoring::Snowplow.instance.track_job_failed(@jobflow)
          end
          raise BootstrapFailureError, get_failure_details(jobflow_id)

        else
          if snowplow_tracking_enabled
            Monitoring::Snowplow.instance.track_job_failed(@jobflow)
          end
          raise EmrExecutionError, get_failure_details(jobflow_id)
        end

        nil
      end

      # Fetch logs from S3 left by RDB Loader steps
      #
      # Parameters:
      # +region+:: region for logs bucket
      Contract String, String, String, String => nil
      def output_rdb_loader_logs(region, aws_access_key_id, aws_secret_key, log_level)

        s3 = Sluice::Storage::S3::new_fog_s3_from(region, aws_access_key_id, aws_secret_key)

        loc = Sluice::Storage::S3::Location.new(@rdb_loader_log_base)

        if @rdb_loader_logs.empty? or Sluice::Storage::S3::is_empty?(s3, loc)
          logger.info "No RDB Loader logs"
        else
          logger.info "RDB Loader logs"

          @rdb_loader_logs.each do |l|
            tmp = Tempfile.new("rdbloader")
            uri = URI.parse(l[1])
            bucket, key = uri.host, uri.path[1..-1]
            logger.debug "Downloading #{uri} to #{tmp.path}"
            begin
              log = s3.directories.get(bucket).files.head(key)
              Sluice::Storage::S3::download_file(s3, log, tmp)
              if log_level == 'info'
                logger.info l[0]
                logger.info tmp.read
              elsif log_level == 'warn'
                logger.warn l[0]
                logger.warn tmp.read
              else
                logger.error l[0]
                logger.error tmp.read
              end
            rescue Exception => e
              logger.error "Error while downloading RDB log #{l[1]}"
              logger.error e.message
            ensure
              tmp.close
              tmp.unlink
            end
          end
        end

        nil
      end

    private

      # Build an Elasticity RDB Loader step.
      #
      # Parameters:
      # +config+:: main Snowplow config.yml
      # +targets+:: list of Storage target config hashes
      # +resolver+:: base64-encoded Iglu resolver JSON
      # +jar+:: s3 object with RDB Loader jar
      Contract ConfigHash, ArrayOf[Iglu::SelfDescribingJson], String, String, RdbLoaderSteps => ArrayOf[Elasticity::CustomJarStep]
      def get_rdb_loader_steps(config, targets, resolver, jar, rdbloader_steps)
        # Remove credentials from config
        clean_config = deep_copy(config)
        clean_config[:aws][:access_key_id] = ""
        clean_config[:aws][:secret_access_key] = ""

        default_arguments = {
          :config      => Base64.strict_encode64(recursive_stringify_keys(clean_config).to_yaml),
          :resolver    => build_iglu_config_json(resolver)
        }

        unless rdbloader_steps[:skip].empty?
          default_arguments.merge({
            :skip => rdbloader_steps[:skip].join(",")
          })
        end

        unless rdbloader_steps[:include].empty?
          default_arguments.merge({
            :include => rdbloader_steps[:skip].join(",")
          })
        end

        targets.map { |target|
          name = target.data[:name]
          log_key = @rdb_loader_log_base + SecureRandom.uuid
          @rdb_loader_logs << [name, log_key]
          encoded_target = Base64.strict_encode64(target.to_json.to_json)
          arguments = [
            "--config", default_arguments[:config],
            "--resolver", default_arguments[:resolver],
            "--logkey", log_key,
            "--target", encoded_target
          ] + unless rdbloader_steps[:skip].empty?
            ["--skip", rdbloader_steps[:skip].join(",")]
          else
            []
          end + unless rdbloader_steps[:include].empty?
            ["--include", rdbloader_steps[:include].join(",")]
          else
            []
          end

          rdb_loader_step = Elasticity::CustomJarStep.new(jar)
          rdb_loader_step.arguments = arguments
          rdb_loader_step.name << ": Load #{name} Storage Target"
          rdb_loader_step
        }
      end

      # List bucket (enriched:good or shredded:good) and return latest run folder
      # Assuming, there's usually just one folder
      #
      # Parameters:
      # +s3+:: AWS S3 client
      # +s3_path+:: Full S3 path to folder
      def get_latest_run_id(s3, s3_path)
        uri = URI.parse(s3_path)
        folders = s3.directories.get(uri.host, delimiter: '/', prefix: uri.path[1..-1]).files.common_prefixes
        run_folders = folders.select { |f| f.include?('run=') }
        begin
          folder = run_folders[-1].split('/')[-1]
          folder.slice('run='.length, folder.length)
        rescue NoMethodError => _
          logger.error "No run folders in [#{s3_path}] found"
          raise UnexpectedStateError, "No run folders in [#{s3_path}] found"
        end
      end

      # Defines a S3DistCp step for archiving enriched or shred folder
      #
      # Parameters:
      # +good_path+:: shredded:good or enriched:good full S3 path
      # +archive_path+:: enriched:archive or shredded:archive full S3 path
      # +run_id_folder+:: run id foler name (2017-05-10-02-45-30, without `=run`)
      # +name+:: step description to show in EMR console
      #
      # Returns a step ready for adding to the Elasticity Jobflow.
      Contract String, String, String, String, String => Elasticity::S3DistCpStep
      def get_archive_step(good_path, archive_path, run_id_folder, s3_endpoint, name)
        archive_step = Elasticity::S3DistCpStep.new(legacy = @legacy)
        archive_step.arguments = [
          "--src"        , partition_by_run(good_path, run_id_folder),
          "--dest"       , partition_by_run(archive_path, run_id_folder),
          "--s3Endpoint" , s3_endpoint,
          "--deleteOnSuccess"
        ]
        archive_step.name << name
        archive_step
      end

      # Defines an Elasticity Scalding step.
      #
      # Parameters:
      # +step_name+:: name of step
      # +main_class+:: Java main class to run
      # +folders+:: hash of in, good, bad, errors S3/HDFS folders
      # +extra_step_args+:: additional arguments to pass to the step
      # +targets+:: list of targets parsed from self-describing JSONs
      #
      # Returns a step ready for adding to the Elasticity Jobflow.
      Contract String, String, String, Hash, Hash => Elasticity::ScaldingStep
      def build_scalding_step(step_name, jar, main_class, folders, extra_step_args={})

        # Build our argument hash
        arguments = extra_step_args
          .merge({
            :input_folder      => folders[:in],
            :output_folder     => folders[:good],
            :bad_rows_folder   => folders[:bad],
            :exceptions_folder => folders[:errors]
          })
          .reject { |k, v| v.nil? } # Because folders[:errors] may be empty

        arguments['tool.partialok'] = ''

        # Now create the Hadoop MR step for the jobflow
        scalding_step = Elasticity::ScaldingStep.new(jar, "#{JAVA_PACKAGE}.#{main_class}", arguments)
        scalding_step.name << ": #{step_name}"

        scalding_step
      end

      # Defines an Elasticity Spark step.
      #
      # Parameters:
      # +step_name+:: name of the step
      # +main_class+:: class to run
      # +folders+:: hash of input, output, bad S3/HDFS folders
      # +extra_step_args+:: additional command line arguments to pass to the step
      #
      # Returns a step read to be added to the Elasticity Jobflow.
      Contract String, String, String, Hash, Hash => Elasticity::SparkStep
      def build_spark_step(step_name, jar, main_class, folders, extra_step_args={})
        arguments = extra_step_args
          .merge({
            'input-folder'  => folders[:in],
            'output-folder' => folders[:good],
            'bad-folder'    => folders[:bad],
          })
        spark_step = Elasticity::SparkStep.new(jar, "#{JAVA_PACKAGE}.#{main_class}")
        spark_step.app_arguments = arguments
        spark_step.spark_arguments = {
          'master' => 'yarn',
          'deploy-mode' => 'cluster'
        }
        spark_step.name << ": #{step_name}"
        spark_step
      end

      # Wait for a jobflow.
      # Check its status every 5 minutes till it completes.
      #
      # Returns true if the jobflow completed without error,
      # false otherwise.
      Contract None => JobResult
      def wait_for()

        success = false
        bootstrap_failure = false
        rdb_loader_failure = false
        rdb_loader_cancellation = false

        # Loop until we can quit...
        while true do
          begin
            # Count up running tasks and failures
            statuses = @jobflow.cluster_step_status.map(&:state).inject([0, 0]) do |sum, state|
              [ sum[0] + (@@running_states.include?(state) ? 1 : 0), sum[1] + (@@failed_states.include?(state) ? 1 : 0) ]
            end

            # If no step is still running, then quit
            if statuses[0] == 0
              success = statuses[1] == 0 # True if no failures
              bootstrap_failure = EmrJob.bootstrap_failure?(@jobflow)
              rdb_loader_failure = EmrJob.rdb_loader_failure?(@jobflow.cluster_step_status)
              rdb_loader_cancellation = EmrJob.rdb_loader_cancellation?(@jobflow.cluster_step_status)
              break
            else
              # Sleep a while before we check again
              sleep(120)
            end

          rescue SocketError => se
            logger.warn "Got socket error #{se}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue Errno::ECONNREFUSED => ref
            logger.warn "Got connection refused #{ref}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue Errno::ECONNRESET => res
            logger.warn "Got connection reset #{res}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue Errno::ETIMEDOUT => to
            logger.warn "Got connection timeout #{to}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue RestClient::InternalServerError => ise
            logger.warn "Got internal server error #{ise}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue Elasticity::ThrottlingException => te
            logger.warn "Got Elasticity throttling exception #{te}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue ArgumentError => ae
            logger.warn "Got Elasticity argument error #{ae}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue IOError => ioe
            logger.warn "Got IOError #{ioe}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          rescue RestClient::SSLCertificateNotVerified => sce
            logger.warn "Got RestClient::SSSLCertificateNotVerified #{sce}, waiting 5 minutes before checking jobflow again"
            sleep(300)
          end
        end

        JobResult.new(success, bootstrap_failure, rdb_loader_failure, rdb_loader_cancellation)
      end

      # Prettified string containing failure details
      # for this job flow.
      Contract String => String
      def get_failure_details(jobflow_id)

        cluster_step_status = @jobflow.cluster_step_status
        cluster_status = @jobflow.cluster_status

        [
          "EMR jobflow #{jobflow_id} failed, check Amazon EMR console and Hadoop logs for details (help: https://github.com/snowplow/snowplow/wiki/Troubleshooting-jobs-on-Elastic-MapReduce). Data files not archived.",
          "#{@jobflow.name}: #{cluster_status.state} [#{cluster_status.last_state_change_reason}] ~ #{self.class.get_elapsed_time(cluster_status.ready_at, cluster_status.ended_at)} #{self.class.get_timespan(cluster_status.ready_at, cluster_status.ended_at)}"
        ].concat(cluster_step_status
            .sort { |a,b|
              self.class.nilable_spaceship(a.started_at, b.started_at)
            }
            .each_with_index
            .map { |s,i|
              " - #{i + 1}. #{s.name}: #{s.state} ~ #{self.class.get_elapsed_time(s.started_at, s.ended_at)} #{self.class.get_timespan(s.started_at, s.ended_at)}"
            })
          .join("\n")
      end

      # Gets the time span.
      #
      # Parameters:
      # +start+:: start time
      # +_end+:: end time
      Contract Maybe[Time], Maybe[Time] => String
      def self.get_timespan(start, _end)
        "[#{start} - #{_end}]"
      end

      # Spaceship operator supporting nils
      #
      # Parameters:
      # +a+:: First argument
      # +b+:: Second argument
      Contract Maybe[Time], Maybe[Time] => Num
      def self.nilable_spaceship(a, b)
        case
        when (a.nil? and b.nil?)
          0
        when a.nil?
          1
        when b.nil?
          -1
        else
          a <=> b
        end
      end

      # Gets the elapsed time in a
      # human-readable format.
      #
      # Parameters:
      # +start+:: start time
      # +_end+:: end time
      Contract Maybe[Time], Maybe[Time] => String
      def self.get_elapsed_time(start, _end)
        if start.nil? or _end.nil?
          "elapsed time n/a"
        else
          # Adapted from http://stackoverflow.com/a/19596579/255627
          seconds_diff = (start - _end).to_i.abs

          hours = seconds_diff / 3600
          seconds_diff -= hours * 3600

          minutes = seconds_diff / 60
          seconds_diff -= minutes * 60

          seconds = seconds_diff

          "#{hours.to_s.rjust(2, '0')}:#{minutes.to_s.rjust(2, '0')}:#{seconds.to_s.rjust(2, '0')}"
        end
      end

      # Recursively change the keys of a YAML from symbols to strings
      def recursive_stringify_keys(h)
        if h.class == [].class
          h.map {|key| recursive_stringify_keys(key)}
        elsif h.class == {}.class
          Hash[h.map {|k,v| [k.to_s, recursive_stringify_keys(v)]}]
        else
          h
        end
      end

      def deep_copy(o)
        Marshal.load(Marshal.dump(o))
      end

      # Returns true if the jobflow failed at a rdb loader step
      Contract ArrayOf[Elasticity::ClusterStepStatus] => Bool
      def self.rdb_loader_failure?(cluster_step_statuses)
        rdb_loader_failure_indicator = /Storage Target/
        cluster_step_statuses.any? { |s| s.state == 'FAILED' && !(s.name =~ rdb_loader_failure_indicator).nil? }
      end

      # Returns true if the rdb loader step was cancelled
      Contract ArrayOf[Elasticity::ClusterStepStatus] => Bool
      def self.rdb_loader_cancellation?(cluster_step_statuses)
        rdb_loader_failure_indicator = /Storage Target/
        cluster_step_statuses.any? { |s| s.state == 'CANCELLED' && !(s.name =~ rdb_loader_failure_indicator).nil? }
      end

      # Returns true if the jobflow seems to have failed due to a bootstrap failure
      Contract Elasticity::JobFlow => Bool
      def self.bootstrap_failure?(jobflow)
        bootstrap_failure_indicator = /BOOTSTRAP_FAILURE|bootstrap action|Master instance startup failed/
        jobflow.cluster_step_status.all? {|s| s.state == 'CANCELLED'} &&
          (!(jobflow.cluster_status.last_state_change_reason =~ bootstrap_failure_indicator).nil?)
      end

      Contract String, String => Elasticity::CustomJarStep
      def get_rmr_step(location, bucket)
        step = Elasticity::CustomJarStep.new("s3://#{@jobflow.region}.elasticmapreduce/libs/script-runner/script-runner.jar")
        step.arguments = ["#{bucket}common/emr/snowplow-hadoop-fs-rmr-0.1.0.sh", location]
        step.name << ": Empty Raw HDFS"
        step
      end

    end
  end
end


text:
package com.graphhopper.routing.util.parsers;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.EnumEncodedValue;
import com.graphhopper.routing.ev.Hazmat;
import com.graphhopper.storage.IntsRef;

public class OSMHazmatParser implements TagParser {

    private final EnumEncodedValue<Hazmat> hazEnc;

    public OSMHazmatParser(EnumEncodedValue<Hazmat> hazEnc) {
        this.hazEnc = hazEnc;
    }

    @Override
    public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
        if (readerWay.hasTag("hazmat", "no")) {
            hazEnc.setEnum(false, edgeFlags, Hazmat.NO);
        }
        return edgeFlags;
    }
}


text:
<?php

namespace Frontend\Controllers;

use Phalcon\Mvc\Controller;
use Frontend\Models\Cities;
use Output\JSON as Output;

/**
 * Class CitiesController
 * @package Frontend\Controllers
 */
class CitiesController extends Controller
{
    /**
     * @var int
     */
    private $limit = 10;

    /**
     * @return string
     */
    public function indexAction()
    {
        $this->view->disable();

        $response = [];

        $offset = 0;
        $page = intval($this->request->get('page') ?? 1);
        $limit = intval($this->request->get('limit') ?? $this->limit);

        if ($page > 0) {
            $offset = ($limit * --$page);
        }

        $cities = Cities::find(
            [
                "active = 1",
                "offset" => $offset,
                "limit" => $limit,
            ]
        );

        foreach ($cities as $city) {
            $response[] = $this->_format($city);
        }

        return Output::render($response);
    }

    /**
     * @param $id
     * @return string
     * @throws \Exception
     */
    public function showAction($id)
    {
        $this->view->disable();

        $city = Cities::findFirstById($id);

        if (false === $city) {
            http_response_code(204);
            throw new \Exception("Ressource does not exist.");
        }

        $response = $this->_format($city);

        return Output::render($response);
    }

    /**
     * @param Cities $city
     * @return array
     */
    private function _format(Cities $city): array
    {
        return
            [
                "id" => $city->getId(),
                "name" => $city->getName(),
                "latitude" => $city->getLatitude(),
                "longitude" => $city->getLongitude(),
            ];
    }
}


text:
package org.keycloak.authentication.forms;

import org.keycloak.Config;
import org.keycloak.authentication.FormAction;
import org.keycloak.authentication.FormActionFactory;
import org.keycloak.authentication.FormContext;
import org.keycloak.authentication.ValidationContext;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.forms.login.LoginFormsProvider;
import org.keycloak.models.AuthenticationExecutionModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.utils.FormMessage;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.validation.Validation;

import javax.ws.rs.core.MultivaluedMap;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
public class RegistrationProfile implements FormAction, FormActionFactory {
    public static final String PROVIDER_ID = "registration-profile-action";

    @Override
    public String getHelpText() {
        return "Validates email, first name, and last name attributes and stores them in user data.";
    }

    @Override
    public List<ProviderConfigProperty> getConfigProperties() {
        return null;
    }

    @Override
    public void validate(ValidationContext context) {
        MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
        List<FormMessage> errors = new ArrayList<>();

        context.getEvent().detail(Details.REGISTER_METHOD, "form");
        String eventError = Errors.INVALID_REGISTRATION;

        if (Validation.isBlank(formData.getFirst((RegistrationPage.FIELD_FIRST_NAME)))) {
            errors.add(new FormMessage(RegistrationPage.FIELD_FIRST_NAME, Messages.MISSING_FIRST_NAME));
        }

        if (Validation.isBlank(formData.getFirst((RegistrationPage.FIELD_LAST_NAME)))) {
            errors.add(new FormMessage(RegistrationPage.FIELD_LAST_NAME, Messages.MISSING_LAST_NAME));
        }

        String email = formData.getFirst(Validation.FIELD_EMAIL);
        boolean emailValid = true;
        if (Validation.isBlank(email)) {
            errors.add(new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.MISSING_EMAIL));
            emailValid = false;
        } else if (!Validation.isEmailValid(email)) {
            context.getEvent().detail(Details.EMAIL, email);
            errors.add(new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.INVALID_EMAIL));
            emailValid = false;
        }

        if (emailValid && context.getSession().users().getUserByEmail(email, context.getRealm()) != null) {
            eventError = Errors.EMAIL_IN_USE;
            formData.remove(Validation.FIELD_EMAIL);
            context.getEvent().detail(Details.EMAIL, email);
            errors.add(new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.EMAIL_EXISTS));
        }

        if (errors.size() > 0) {
            context.error(eventError);
            context.validationError(formData, errors);
            return;

        } else {
            context.success();
        }
    }

    @Override
    public void success(FormContext context) {
        UserModel user = context.getUser();
        MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
        user.setFirstName(formData.getFirst(RegistrationPage.FIELD_FIRST_NAME));
        user.setLastName(formData.getFirst(RegistrationPage.FIELD_LAST_NAME));
        user.setEmail(formData.getFirst(RegistrationPage.FIELD_EMAIL));
    }

    @Override
    public void buildPage(FormContext context, LoginFormsProvider form) {
        // complete
    }

    @Override
    public boolean requiresUser() {
        return false;
    }

    @Override
    public boolean configuredFor(KeycloakSession session, RealmModel realm, UserModel user) {
        return true;
    }

    @Override
    public void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) {

    }

    @Override
    public boolean isUserSetupAllowed() {
        return false;
    }

    @Override
    public void close() {

    }

    @Override
    public String getDisplayType() {
        return "Profile Validation";
    }

    @Override
    public String getReferenceCategory() {
        return null;
    }

    @Override
    public boolean isConfigurable() {
        return false;
    }

    private static AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
            AuthenticationExecutionModel.Requirement.REQUIRED,
            AuthenticationExecutionModel.Requirement.DISABLED
    };
    @Override
    public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
        return REQUIREMENT_CHOICES;
    }
    @Override
    public FormAction create(KeycloakSession session) {
        return this;
    }

    @Override
    public void init(Config.Scope config) {

    }

    @Override
    public void postInit(KeycloakSessionFactory factory) {

    }

    @Override
    public String getId() {
        return PROVIDER_ID;
    }
}


text:
package EDM.edm.main.items.tools.shovel;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import EDM.edm.main.handler.enums.EnumToolMaterials;
import EDM.edm.main.items.tools.ItemToolMain;

public class ItemSpadeMain extends ItemToolMain
{

	private static Block[] blocksEffectiveAgainst = new Block[]
	{
		Block.grass,
		Block.dirt,
		Block.sand,
		Block.gravel,
		Block.snow,
		Block.blockSnow,
		Block.blockClay,
		Block.tilledField,
		Block.slowSand,
		Block.mycelium
	};

	public ItemSpadeMain(int par1, EnumToolMaterials par2EnumToolMaterial, String name)
	{
         super(par1, 1, par2EnumToolMaterial, blocksEffectiveAgainst, name);
         this.setTextureName("mod_beta"+":"+name);
	}

	public boolean canHarvestBlock(Block par1Block)
	{
         return par1Block == Block.snow ? true : par1Block == Block.blockSnow;
	}

	public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
	{
         par1ItemStack.damageItem(1, par3EntityLiving);
         return true;
	}
}


text:
class testApp : public ofBaseApp {
public:
	void setup();
	void update();
	void draw();
	void mouseDragged(int x, int y, int button);
	void keyPressed(int key);
	void keyReleased(int key);
	void updatePath();
	void origin();

	ofVideoGrabber cam;
	ofxFaceTracker tracker;
	ofRectangle cameraBox, boundingBox, innerBox;

	ofxCv::RunningBackground background;
	ofImage thresholded;

	ofImage square, gray, edge;
	ofImage fg;

	ofxPathfinder pathfinder;
	vector<bool> original;
	typedef std::pair<int, int> intPair;
	list<intPair> remaining;
	ofPolyline target;

	ofxOscSender osc;
	float progress;
	int lastState;
	ofPolyline drawn;

	bool moving, lastMoving;
	float eyeOpenness;

	ofSoundPlayer beep;
	bool cleanedUp;
};


text:
package se.citerus.dddsample.domain.model.location;

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

import org.junit.Test;

public class UnLocodeTest {

  @Test
  public void testNew() {
    assertValid("AA234");
    assertValid("AAA9B");
    assertValid("AAAAA");

    assertInvalid("AAAA");
    assertInvalid("AAAAAA");
    assertInvalid("AAAA");
    assertInvalid("AAAAAA");
    assertInvalid("22AAA");
    assertInvalid("AA111");
    assertInvalid(null);
  }

  @Test
  public void testIdString() {
    assertThat(new UnLocode("AbcDe").idString()).isEqualTo("ABCDE");
  }

  @Test
  public void testEquals() {
    UnLocode allCaps = new UnLocode("ABCDE");
    UnLocode mixedCase = new UnLocode("aBcDe");

    assertThat(allCaps.equals(mixedCase)).isTrue();
    assertThat(mixedCase.equals(allCaps)).isTrue();
    assertThat(allCaps.equals(allCaps)).isTrue();

    assertThat(allCaps.equals(null)).isFalse();
    assertThat(allCaps.equals(new UnLocode("FGHIJ"))).isFalse();
  }

  @Test
  public void testHashCode() {
    UnLocode allCaps = new UnLocode("ABCDE");
    UnLocode mixedCase = new UnLocode("aBcDe");

    assertThat(mixedCase.hashCode()).isEqualTo(allCaps.hashCode());
  }

  private void assertValid(String unlocode) {
    new UnLocode(unlocode);
  }

  private void assertInvalid(String unlocode) {
    try {
      new UnLocode(unlocode);
      fail("The combination [" + unlocode + "] is not a valid UnLocode");
    } catch (IllegalArgumentException expected) {}
  }

}