text:
package org.myrobotlab.framework.interfaces;

import org.myrobotlab.framework.Message;
import org.myrobotlab.framework.TimeoutException;

public interface MessageSender extends NameProvider {

  /**
   * Send invoking messages to remote location to invoke {name} instance's
   * {method} with no parameters.
   *
   * @param name
   *          - name of destination service
   * @param method
   *          - method of destination service
   */
  public void send(String name, String method);

  /**
   * Send invoking messages to remote location to invoke {name} instance's
   * {method} with parameters data.
   *
   * @param name
   *          - name of destination service
   * @param method
   *          - method of destination service
   * @param data
   *          - parameter data
   */
  public void send(String name, String method, Object... data);

  /**
   * Base method for sending messages.
   *
   * @param msg
   *          - message to be sent
   */
  public void send(Message msg);

  public Object sendBlocking(String name, String method) throws InterruptedException, TimeoutException;

  public Object sendBlocking(String name, String method, Object... data) throws InterruptedException, TimeoutException;

  public Object sendBlocking(String name, Integer timeout, String method, Object... data) throws InterruptedException, TimeoutException;

  public Object sendBlocking(Message msg, Integer timeout) throws InterruptedException, TimeoutException;

  public Object waitFor(String fullName, String method, Integer timeout) throws InterruptedException, TimeoutException;

}


text:
	<input dojoAttachPoint='textbox' dojoAttachEvent='onblur;onfocus'
		id='${this.widgetId}' name='${this.name}'
		value='${this.value}' class='${this.className}' type='${this.type}' >

redpajama_set_name: RedPajamaGithub


text:
package org.apache.nutch.scoring;

import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;

import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.io.Text;
import org.apache.nutch.crawl.CrawlDatum;
import org.apache.nutch.crawl.Inlinks;
import org.apache.nutch.indexer.NutchDocument;
import org.apache.nutch.parse.Parse;
import org.apache.nutch.parse.ParseData;
import org.apache.nutch.plugin.Pluggable;
import org.apache.nutch.protocol.Content;

/**
 * A contract defining behavior of scoring plugins.
 *
 * A scoring filter will manipulate scoring variables in CrawlDatum and in
 * resulting search indexes. Filters can be chained in a specific order, to
 * provide multi-stage scoring adjustments.
 *
 * @author Andrzej Bialecki
 */
public interface ScoringFilter extends Configurable, Pluggable {
  /** The name of the extension point. */
  public final static String X_POINT_ID = ScoringFilter.class.getName();

  /**
   * Set an initial score for newly injected pages. Note: newly injected pages
   * may have no inlinks, so filter implementations may wish to set this score
   * to a non-zero value, to give newly injected pages some initial credit.
   *
   * @param url
   *          url of the page
   * @param datum
   *          new datum. Filters will modify it in-place.
   * @throws ScoringFilterException
   */
  public void injectedScore(Text url, CrawlDatum datum)
      throws ScoringFilterException;

  /**
   * Set an initial score for newly discovered pages. Note: newly discovered
   * pages have at least one inlink with its score contribution, so filter
   * implementations may choose to set initial score to zero (unknown value),
   * and then the inlink score contribution will set the "real" value of the new
   * page.
   *
   * @param url
   *          url of the page
   * @param datum
   *          new datum. Filters will modify it in-place.
   * @throws ScoringFilterException
   */
  public void initialScore(Text url, CrawlDatum datum)
      throws ScoringFilterException;

  /**
   * This method prepares a sort value for the purpose of sorting and selecting
   * top N scoring pages during fetchlist generation.
   *
   * @param url
   *          url of the page
   * @param datum
   *          page's datum, should not be modified
   * @param initSort
   *          initial sort value, or a value from previous filters in chain
   */
  public float generatorSortValue(Text url, CrawlDatum datum, float initSort)
      throws ScoringFilterException;

  /**
   * This method takes all relevant score information from the current datum
   * (coming from a generated fetchlist) and stores it into
   * {@link org.apache.nutch.protocol.Content} metadata. This is needed in order
   * to pass this value(s) to the mechanism that distributes it to outlinked
   * pages.
   *
   * @param url
   *          url of the page
   * @param datum
   *          source datum. NOTE: modifications to this value are not persisted.
   * @param content
   *          instance of content. Implementations may modify this in-place,
   *          primarily by setting some metadata properties.
   */
  public void passScoreBeforeParsing(Text url, CrawlDatum datum, Content content)
      throws ScoringFilterException;

  /**
   * Currently a part of score distribution is performed using only data coming
   * from the parsing process. We need this method in order to ensure the
   * presence of score data in these steps.
   *
   * @param url
   *          page url
   * @param content
   *          original content. NOTE: modifications to this value are not
   *          persisted.
   * @param parse
   *          target instance to copy the score information to. Implementations
   *          may modify this in-place, primarily by setting some metadata
   *          properties.
   */
  public void passScoreAfterParsing(Text url, Content content, Parse parse)
      throws ScoringFilterException;

  /**
   * Distribute score value from the current page to all its outlinked pages.
   *
   * @param fromUrl
   *          url of the source page
   * @param parseData
   *          ParseData instance, which stores relevant score value(s) in its
   *          metadata. NOTE: filters may modify this in-place, all changes will
   *          be persisted.
   * @param targets
   *          <url, CrawlDatum> pairs. NOTE: filters can modify this
   *          in-place, all changes will be persisted.
   * @param adjust
   *          a CrawlDatum instance, initially null, which implementations may
   *          use to pass adjustment values to the original CrawlDatum. When
   *          creating this instance, set its status to
   *          {@link CrawlDatum#STATUS_LINKED}.
   * @param allCount
   *          number of all collected outlinks from the source page
   * @return if needed, implementations may return an instance of CrawlDatum,
   *         with status {@link CrawlDatum#STATUS_LINKED}, which contains
   *         adjustments to be applied to the original CrawlDatum score(s) and
   *         metadata. This can be null if not needed.
   * @throws ScoringFilterException
   */
  public CrawlDatum distributeScoreToOutlinks(Text fromUrl,
      ParseData parseData, Collection<Entry<Text, CrawlDatum>> targets,
      CrawlDatum adjust, int allCount) throws ScoringFilterException;

  /**
   * This method calculates a new score of CrawlDatum during CrawlDb update,
   * based on the initial value of the original CrawlDatum, and also score
   * values contributed by inlinked pages.
   *
   * @param url
   *          url of the page
   * @param old
   *          original datum, with original score. May be null if this is a
   *          newly discovered page. If not null, filters should use score
   *          values from this parameter as the starting values - the
   *          datum parameter may contain values that are no longer
   *          valid, if other updates occured between generation and this
   *          update.
   * @param datum
   *          the new datum, with the original score saved at the time when
   *          fetchlist was generated. Filters should update this in-place, and
   *          it will be saved in the crawldb.
   * @param inlinked
   *          (partial) list of CrawlDatum-s (with their scores) from links
   *          pointing to this page, found in the current update batch.
   * @throws ScoringFilterException
   */
  public void updateDbScore(Text url, CrawlDatum old, CrawlDatum datum,
      List<CrawlDatum> inlinked) throws ScoringFilterException;

  /**
   * This method calculates a Lucene document boost.
   *
   * @param url
   *          url of the page
   * @param doc
   *          Lucene document. NOTE: this already contains all information
   *          collected by indexing filters. Implementations may modify this
   *          instance, in order to store/remove some information.
   * @param dbDatum
   *          current page from CrawlDb. NOTE: changes made to this instance are
   *          not persisted.
   * @param fetchDatum
   *          datum from FetcherOutput (containing among others the fetching
   *          status)
   * @param parse
   *          parsing result. NOTE: changes made to this instance are not
   *          persisted.
   * @param inlinks
   *          current inlinks from LinkDb. NOTE: changes made to this instance
   *          are not persisted.
   * @param initScore
   *          initial boost value for the Lucene document.
   * @return boost value for the Lucene document. This value is passed as an
   *         argument to the next scoring filter in chain. NOTE: implementations
   *         may also express other scoring strategies by modifying Lucene
   *         document directly.
   * @throws ScoringFilterException
   */
  public float indexerScore(Text url, NutchDocument doc, CrawlDatum dbDatum,
      CrawlDatum fetchDatum, Parse parse, Inlinks inlinks, float initScore)
      throws ScoringFilterException;
}


text:
package com.opengamma.util.jms;

import java.net.URI;

import javax.jms.ConnectionFactory;

import org.apache.commons.lang.StringUtils;
import org.springframework.jms.core.JmsTemplate;

import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.Connector;
import com.opengamma.util.ReflectionUtils;

/**
 * Connector used to access JMS.
 *

 * This class is usually configured using the associated factory bean.
 */
public class JmsConnector implements Connector {

  /**
   * The configuration name.
   */
  private final String _name;
  /**
   * The JMS template for topic-based messaging.
   */
  private final JmsTemplate _jmsTemplateTopic;
  /**
   * The JMS template for queue-based messaging.
   */
  private final JmsTemplate _jmsTemplateQueue;
  /**
   * The factory for creating containers for topics.
   * This is used to listen to JMS messages.
   */
  private final JmsTopicContainerFactory _topicContainerFactory;
  /**
   * The factory for creating containers for queues.
   * This is used to listen to JMS messages.
   */
  private final JmsQueueContainerFactory _queueContainerFactory;
  /**
   * The configuration needed by the client to connect to the broker.
   */
  private final URI _clientBrokerUri;
  /**
   * The topic name.
   */
  private final String _topicName;

  /**
   * Creates an instance.
   *
   * @param name  the configuration name, not null
   * @param jmsTemplateTopic  the JMS Spring template for topic-based messaging, not null
   * @param jmsTemplateQueue  the JMS Spring template for queue-based messaging, not null
   * @param containerFactoryTopic  the container factory for topics, may be null
   * @param containerFactoryQueue the container factory for queues, may be null
   * @param clientBrokerUri  the client configuration to connect to the broker, such as a URI, null if no config provided for clients
   * @param topicName  the topic name, null if left up to the application
   */
  public JmsConnector(String name, JmsTemplate jmsTemplateTopic, JmsTemplate jmsTemplateQueue,
      JmsTopicContainerFactory containerFactoryTopic, JmsQueueContainerFactory containerFactoryQueue,
      URI clientBrokerUri, String topicName) {
    ArgumentChecker.notNull(name, "name");
    ArgumentChecker.notNull(jmsTemplateTopic, "jmsTemplateTopic");
    ArgumentChecker.notNull(jmsTemplateQueue, "jmsTemplateQueue");
    _name = name;
    _jmsTemplateTopic = jmsTemplateTopic;
    _jmsTemplateQueue = jmsTemplateQueue;
    _topicContainerFactory = containerFactoryTopic;
    _queueContainerFactory = containerFactoryQueue;
    _clientBrokerUri = clientBrokerUri;
    _topicName = topicName;
  }

  //-------------------------------------------------------------------------
  @Override
  public final String getName() {
    return _name;
  }

  @Override
  public final Class<? extends Connector> getType() {
    return JmsConnector.class;
  }

  //-------------------------------------------------------------------------
  /**
   * Gets the JMS connection factory.
   *

   * This extracts the factory of the topic template, which should be the same as that of the queue template.
   * This is shared between all users of this object and must not be further configured.
   *
   * @return the JMS connection factory, may be null
   */
  public ConnectionFactory getConnectionFactory() {
    return _jmsTemplateTopic.getConnectionFactory();
  }

  /**
   * Gets the shared JMS template for topic-based messaging.
   *

   * This is shared between all users of this object and must not be further configured.
   *
   * @return the JMS template for topic-based messaging, null if not setup by configuration
   */
  public JmsTemplate getJmsTemplateTopic() {
    return _jmsTemplateTopic;
  }

  /**
   * Gets the shared JMS template for queue-based messaging.
   *

   * This is shared between all users of this object and must not be further configured.
   *
   * @return the JMS template for queue-based messaging, null if not setup by configuration
   */
  public JmsTemplate getJmsTemplateQueue() {
    return _jmsTemplateQueue;
  }

  /**
   * Gets the topic container factory.
   *
   * @return the factory for topic containers, null if not available
   */
  public JmsTopicContainerFactory getTopicContainerFactory() {
    return _topicContainerFactory;
  }

  /**
   * Gets the queueContainerFactory.
   * @return the queueContainerFactory
   */
  public JmsQueueContainerFactory getQueueContainerFactory() {
    return _queueContainerFactory;
  }

  //-------------------------------------------------------------------------
  /**
   * Gets the broker configuration needed by the client to connect to the server.
   *

   * The client needs some form of configuration, frequently a URI, to connect to the JMS broker.
   * This field provides that configuration.
   *
   * @return the client broker configuration, null if no config provided for clients
   */
  public URI getClientBrokerUri() {
    return _clientBrokerUri;
  }

  //-------------------------------------------------------------------------
  /**
   * Gets the topic name.
   *
   * @return the topic name, null if topic left up to the application
   */
  public String getTopicName() {
    return _topicName;
  }

  /**
   * Returns a copy of this connector with a new topic name.
   *
   * @param topicName  the new topic name, not empty
   * @return a connector with the specified topic name, not null
   */
  public JmsConnector withTopicName(String topicName) {
    ArgumentChecker.notEmpty(topicName, "topicName");
    return new JmsConnector(_name, _jmsTemplateTopic, _jmsTemplateQueue, _topicContainerFactory, _queueContainerFactory, _clientBrokerUri, topicName);
  }

  //-------------------------------------------------------------------------
  /**
   * Ensures that the topic name is set, using the current name or the specified default
   *
   * @return a connector which definitely has a topic name, not null
   */
  public JmsConnector ensureTopicName() {
    if (StringUtils.isNotEmpty(_topicName)) {
      return this;
    }
    throw new IllegalStateException("JMS topic name must be set");
  }

  /**
   * Ensures that the topic name is set, using the current name or the specified default
   *
   * @param defaultTopicName  the default topic name, not empty
   * @return a connector which definitely has a topic name, not null
   */
  public JmsConnector ensureTopicName(String defaultTopicName) {
    if (StringUtils.isNotEmpty(_topicName)) {
      return this;
    }
    return withTopicName(defaultTopicName);
  }

  //-------------------------------------------------------------------------
  @Override
  public void close() {
    ReflectionUtils.close(getConnectionFactory());
  }

  //-------------------------------------------------------------------------
  /**
   * Returns a description of this object suitable for debugging.
   *
   * @return the description, not null
   */
  @Override
  public String toString() {
    return getClass().getSimpleName() + "[" + _name + "]";
  }

}


text:
namespace util {
namespace rpc {

class Context : public ::google::protobuf::RpcController {
 public:
  inline Context() {}
  virtual ~Context();

  Context(const Context&) = delete;
  Context& operator=(const Context&) = delete;

  // Client-side methods ---------------------------------------------
  // These calls may be made from the client side only.  Their results
  // are undefined on the server side (may crash).

  // Resets the RpcController to its initial state so that it may be reused in
  // a new call.  Must not be called while an RPC is in progress.
  virtual void Reset() {
    LOG(FATAL) << "Not implemented";
  }

  // After a call has finished, returns true if the call failed.  The possible
  // reasons for failure depend on the RPC implementation.  Failed() must not
  // be called before a call has finished.  If Failed() returns true, the
  // contents of the response message are undefined.
  virtual bool Failed() const;

  // If Failed() is true, returns a human-readable description of the error.
  virtual std::string ErrorText() const {
    LOG(FATAL) << "Not implemented";
    return "";
  }

  // Advises the RPC system that the caller desires that the RPC call be
  // canceled.  The RPC system may cancel it immediately, may wait awhile and
  // then cancel it, or may not even cancel the call at all.  If the call is
  // canceled, the "done" callback will still be called and the RpcController
  // will indicate that the call failed at that time.
  virtual void StartCancel() {
    LOG(FATAL) << "Not implemented";
  }

  // Server-side methods ---------------------------------------------
  // These calls may be made from the server side only.  Their results
  // are undefined on the client side (may crash).

  // Causes Failed() to return true on the client side.  "reason" will be
  // incorporated into the message returned by ErrorText().  If you find
  // you need to return machine-readable information about failures, you
  // should incorporate it into your response protocol buffer and should
  // NOT call SetFailed().
  virtual void SetFailed(const std::string& reason);

  // If true, indicates that the client canceled the RPC, so the server may
  // as well give up on replying to it.  The server should still call the
  // final "done" callback.
  virtual bool IsCanceled() const {
    return false;
  }

  // Asks that the given callback be called when the RPC is canceled.  The
  // callback will always be called exactly once.  If the RPC completes without
  // being canceled, the callback will be called after completion.  If the RPC
  // has already been canceled when NotifyOnCancel() is called, the callback
  // will be called immediately.
  //
  // NotifyOnCancel() must be called no more than once per request.
  virtual void NotifyOnCancel(::google::protobuf::Closure* callback) {
    LOG(FATAL) << "Not implemented";
  }

  const Status& status() const { return status_; }

  void set_status(const rpc::Status& status) {
    status_ = status;
  }

  rpc::Status* mutable_status() { return &status_; }

  void SetError(rpc::Status::Code code, const std::string& details = std::string()) {
    status_.set_code(code);
    if (!details.empty())
      status_.set_details(details);
  }
 private:
  Status status_;
};

class DoneBarrier : public ::google::protobuf::Closure {
  std::condition_variable cv_;
  std::mutex mu_;
  bool done_ = false;
public:
  void Run() {
    std::unique_lock<std::mutex> lk(mu_);
    done_ = true;
    cv_.notify_all();
  }

  // Returns true if run was called, false if the deadline was expired.
  bool Wait(uint64_t msec = -1) {
    std::unique_lock<std::mutex> lk(mu_);
    while (!done_) {
      std::cv_status status = cv_.wait_for(lk, std::chrono::milliseconds(msec));
      if (status == std::cv_status::timeout)
        return false;
    }
    return true;
  }
};

}  // namespace rpc
}  // namespace util

#endif  // _RPC_CONTEXT_H


text:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gov.hhs.fha.nhinc.account;

import gov.hhs.fha.nhinc.common.account.CreateAccountRequestType;
import gov.hhs.fha.nhinc.common.account.Response;
import gov.hhs.fha.nhinc.common.account.UpdateAccountRequestType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import gov.hhs.fha.nhinc.ldapaccess.ContactDAO;
import gov.hhs.fha.nhinc.ldapaccess.ContactDTO;
import gov.hhs.fha.nhinc.ldapaccess.LdapService;

/**
 *
 * @author Sushma
 */
public class AccountMgrImpl {

    /** Logger. */
    private static Log log = LogFactory.getLog(AccountMgrImpl.class);
    private String ERROR_CREATE_ACCOUNT = "Error while creating user Account";

    public Response updateAccount(UpdateAccountRequestType updateAccountRequest) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public Response createAccount(CreateAccountRequestType createAccountRequest) {
        log.debug("Starting create Account for createAccountRequest query.");
        Response response = new Response();

        try {
            ContactDAO contactDAO = LdapService.getContactDAO();
            ContactDTO contactDTO = new ContactDTO();
            contactDTO.setCommonName(createAccountRequest.getUserName());
            contactDTO.setUid(createAccountRequest.getSsn());
            contactDTO.setGivenName(createAccountRequest.getName().getFirstName());
            contactDTO.setInitials(createAccountRequest.getName().getMiddleName());
            contactDTO.setSurname(createAccountRequest.getName().getLastName());
            contactDTO.setHomePhone(createAccountRequest.getPhoneNumber().getHomeNumber());
            contactDTO.setMobile(createAccountRequest.getPhoneNumber().getMobileNumber());
            contactDTO.setTelephoneNumber(createAccountRequest.getPhoneNumber().getWorkNumber());
            contactDTO.setPostalAddress(createAccountRequest.getAddress().getAddress1());
            contactDTO.setStreet(createAccountRequest.getAddress().getAddress2());
            contactDTO.setCity(createAccountRequest.getAddress().getCity());
            contactDTO.setState(createAccountRequest.getAddress().getState());
            contactDTO.setPostalCode(createAccountRequest.getAddress().getZipCode());
            contactDTO.setMail(createAccountRequest.getEmailAddress());
            contactDTO.setUserPassword(createAccountRequest.getPassword().getBytes());
            contactDAO.insertContact(contactDTO);
            response.setText("Your information has been received, we will email "
                    + "you once your account has been created");
            log.info("User details successfully inserted into LDAP");
            response.setSuccess(true);

        } catch (Throwable t) {
            response.setSuccess(false);
            log.error("Error creating User Account", t);
            response.setText(ERROR_CREATE_ACCOUNT + t.getMessage() == null ? t.getClass().getName() : t.getMessage());
        }
        return response;
    }
}


text:
title: Listing the months and weekdays of the current Moment.js locale
version: 2.3.0
signature: |
  moment.months()
  moment.monthsShort()
  moment.weekdays()
  moment.weekdaysShort()
  moment.weekdaysMin()
---

It is sometimes useful to get the list of months or weekdays in a locale, for example when populating a dropdown menu.

```javascript
moment.months();
```

Returns the list of months in the current locale.

```javascript
[ 'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December' ]
```

Similarly, `moment.monthsShort` returns abbreviated month names, and `moment.weekdays`, `moment.weekdaysShort`, `moment.weekdaysMin` return lists of weekdays.

You can pass an integer into each of those functions to get a specific month or weekday.

```javascript
moment.weekdays(3); // 'Wednesday'
```

As of **2.13.0** you can pass a bool as the first parameter of the weekday functions. If true, the weekdays will be returned in locale specific order.
For instance, in the Arabic locale, Saturday is the first day of the week, thus:

```javascript
moment.locale('ar');
moment.weekdays(true); // lists weekdays Saturday-Friday in Arabic
moment.weekdays(true, 2); //will result in Monday in Arabic
```

**Note:** Absent the locale specific parameter, weekdays always have Sunday as index 0, regardless of the local first day of the week.

Some locales make special considerations into account when formatting month names. For example, Dutch formats month abbreviations without a trailing period, but only if it's formatting the month between dashes. The `months` method supports passing a format in so that the months will be listed in the proper context.

```javascript
moment.locale('nl');
moment.monthsShort(); // ['jan.', 'feb.', 'mrt.', ...]
moment.monthsShort('-MMM-'); // [ 'jan', 'feb', 'mrt', ...]
```

And finally, you can combine both the format option and the integer option.

```javascript
moment.monthsShort('-MMM-', 3); // 'apr'
```


text:
import argparse
import logging
import os
import sys

if __name__ == '__main__':
  sys.path.append(os.path.abspath(os.path.join(
      os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)))
from devil.android import device_blacklist
from devil.android import device_errors
from devil.android import device_utils
from devil.android import fastboot_utils
from devil.android.sdk import adb_wrapper
from devil.constants import exit_codes
from devil.utils import run_tests_helper

def GetDeviceList(device=None):
  """Returns a list of devices.

  If device is passed to it, returns only that device.
  """
  available_devices = [device_utils.DeviceUtils(d)
                       for d in adb_wrapper.AdbWrapper.GetDevices()]
  if not available_devices:
    raise device_errors.NoDevicesError
  if not device:
    return available_devices
  for d in available_devices:
    if str(d) == device:
      return [d]
  raise device_errors.NoDevicesError

def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('build_path', help='Path to android build.')
  parser.add_argument('-d', '--device', help='Device to flash.')
  parser.add_argument('-v', '--verbose', default=0, action='count',
                      help='Verbose level (multiple times for more)')
  parser.add_argument('-w', '--wipe', action='store_true',
                       help='If set, wipes user data')
  parser.add_argument('--blacklist-file', help='Device blacklist file.')
  args = parser.parse_args()
  run_tests_helper.SetLogLevel(args.verbose)

  if args.blacklist_file:
    blacklist = device_blacklist.Blacklist(args.blacklist_file).Read()
    if blacklist:
      logging.critical('Device(s) in blacklist, not flashing devices:')
      for key in blacklist:
        logging.critical('  %s', key)
      return exit_codes.INFRA

  flashed_devices = []
  failed_devices = []

  def flash(device):
    fastboot = fastboot_utils.FastbootUtils(device)
    try:
      fastboot.FlashDevice(args.build_path, wipe=args.wipe)
      flashed_devices.append(device)
    except Exception: # pylint: disable=broad-except
      logging.exception('Device %s failed to flash.', str(device))
      failed_devices.append(device)

  devices = GetDeviceList(device=args.device)
  device_utils.DeviceUtils.parallel(devices).pMap(flash)

  if flashed_devices:
    logging.info('The following devices were flashed:')
    logging.info('  %s', ' '.join(str(d) for d in flashed_devices))
  if failed_devices:
    logging.critical('The following devices failed to flash:')
    logging.critical('  %s', ' '.join(str(d) for d in failed_devices))
    return exit_codes.INFRA
  return 0

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


text:
package org.openintents.filemanager.dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.openintents.filemanager.R;
import org.openintents.filemanager.files.FileHolder;
import org.openintents.filemanager.lists.FileListFragment;
import org.openintents.filemanager.util.MediaScannerUtils;
import org.openintents.filemanager.util.UIUtils;
import org.openintents.intents.FileManagerIntents;

import java.io.File;

public class RenameDialog extends DialogFragment {
    private FileHolder mFileHolder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mFileHolder = getArguments().getParcelable(FileManagerIntents.EXTRA_DIALOG_FILE_HOLDER);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_text_input, null);
        final EditText v = (EditText) view.findViewById(R.id.foldername);
        v.setText(mFileHolder.getName());

        v.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView text, int actionId,
                                          KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_GO)
                    renameTo(text.getText().toString());
                dismiss();
                return true;
            }
        });

        return new AlertDialog.Builder(getActivity())
                .setInverseBackgroundForced(UIUtils.shouldDialogInverseBackground(getActivity()))
                .setTitle(R.string.menu_rename)
                .setIcon(mFileHolder.getIcon())
                .setView(view)
                .setNegativeButton(android.R.string.cancel, null)
                .setPositiveButton(android.R.string.ok,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                renameTo(v.getText().toString());

                            }
                        }).create();
    }

    private void renameTo(String to) {
        boolean res = false;

        if (to.length() > 0) {
            File from = mFileHolder.getFile();

            File dest = new File(mFileHolder.getFile().getParent() + File.separator + to);
            if (!dest.exists()) {
                res = mFileHolder.getFile().renameTo(dest);
                ((FileListFragment) getTargetFragment()).refresh();

                // Inform media scanner
                MediaScannerUtils.informFileDeleted(getActivity().getApplicationContext(), from);
                MediaScannerUtils.informFileAdded(getActivity().getApplicationContext(), dest);
            }
        }

        Toast.makeText(getActivity(), res ? R.string.rename_success : R.string.rename_failure, Toast.LENGTH_SHORT).show();
    }
}


text:
import rest from './rest';
export default rest;


text:
package joedoe.mastermind.types;

import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import joedoe.mastermind.types.Color;
import joedoe.mastermind.types.Row;
import joedoe.mastermind.types.RowRating;
import joedoe.mastermind.types.SolutionSpace;

import org.junit.Test;

public class SolutionSpaceTest {

	@Test(expected = IllegalArgumentException.class)
	public void solutionSpaceCreationSizeNegativeTest() {
		new SolutionSpace(-1);
	}

	@Test(expected = IllegalArgumentException.class)
	public void solutionSpaceCreationSizeEmptyTest() {
		new SolutionSpace(0);
	}

	@Test(expected = NullPointerException.class)
	public void createNull() {
		Row[] rows = null;
		new SolutionSpace(rows);
	}

	@Test(expected = NullPointerException.class)
	public void createWithNullRow() {
		new SolutionSpace(new Row(Color.GREEN), new Row(Color.BLUE), null, new Row(Color.GREEN));
	}

	public void createEmptyAllowed() {
		Row[] rows = new Row[0];
		SolutionSpace solSpace = new SolutionSpace(rows);
		assertThat(solSpace.getSolutionSpaceElements().length, is(0));
	}

	@Test
	public void solutionSpaceCreationSize1Test() {
		SolutionSpace solSpace = new SolutionSpace(1);
		assertThat(solSpace.getSolutionSpaceElements().length, is(8));
		for (Color c : Color.values())
			assertThat(solSpace.containsRow(new Row(c)), is(true));
	}

	@Test
	public void solutionSpaceCreationSize2Test() {
		SolutionSpace solSpace = new SolutionSpace(2);
		assertThat(solSpace.getSolutionSpaceElements().length, is(8*7));
		// not explicitly enumerating and checking solution space
	}

	@Test
	public void solutionSpaceCreationSize4Test() {
		SolutionSpace solSpace = new SolutionSpace(4);
		assertThat(solSpace.getSolutionSpaceElements().length, is(8*7*6*5));
		// not explicitly enumerating and checking solution space
	}

	@Test(expected = NullPointerException.class)
	public void filterNoRow() {
		new SolutionSpace(1).filterByRating(null);
	}

	@Test(expected = IllegalArgumentException.class)
	public void filterNoRating() {
		new SolutionSpace(1).filterByRating(new Row(Color.BLUE));
	}

	@Test
	public void filterBlueExact() {
		SolutionSpace solSpace = new SolutionSpace(1);
		Row row = new Row(Color.BLUE);
		row.setRating(new RowRating(1, 0));
		SolutionSpace filtered = solSpace.filterByRating(row);
		assertThat(filtered.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.BLUE)));
	}

	@Test
	public void filterBlueWhiteExactly() {
		SolutionSpace solSpace = new SolutionSpace(2);
		Row row = new Row(Color.BLUE, Color.WHITE);
		row.setRating(new RowRating(2, 0));
		SolutionSpace filtered = solSpace.filterByRating(row);
		assertThat(filtered.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.BLUE, Color.WHITE)));
	}

	@Test
	public void filterBlueWhiteWithColor() {
		SolutionSpace solSpace = new SolutionSpace(2);
		Row row = new Row(Color.BLUE, Color.WHITE);
		row.setRating(new RowRating(0, 2));
		SolutionSpace filtered = solSpace.filterByRating(row);
		assertThat(filtered.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.WHITE, Color.BLUE)));
	}

	@Test
	public void filterStartingWithBlueOrWhite() {
		SolutionSpace solSpace = new SolutionSpace(2);
		Row row = new Row(Color.BLUE, Color.WHITE);
		row.setRating(new RowRating(0, 2));
		SolutionSpace filtered = solSpace.filterByRating(row);
		assertThat(filtered.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.WHITE, Color.BLUE)));
	}

	@Test(expected = NullPointerException.class)
	public void intersectNullPointer() {
		SolutionSpace solSpace = new SolutionSpace(1);
		solSpace.intersect(null);
	}
	@Test
	public void intersect1() {
		SolutionSpace solSpace = new SolutionSpace(1);
		Row rowBlue = new Row(Color.BLUE);
		rowBlue.setRating(new RowRating(1, 0));
		Row rowGreen = new Row(Color.GREEN);
		rowGreen.setRating(new RowRating(1, 0));
		SolutionSpace blueFiltered = solSpace.filterByRating(rowBlue);
		SolutionSpace greenFiltered = solSpace.filterByRating(rowGreen);
		SolutionSpace intersect = blueFiltered.intersect(greenFiltered);
		assertThat(intersect.getSolutionSpaceElements().length, is(0));
	}

	@Test
	public void intersect2() {
		SolutionSpace solSpace = new SolutionSpace(1);
		Row rowBlue = new Row(Color.BLUE);
		rowBlue.setRating(new RowRating(1, 0));
		SolutionSpace blueFiltered = solSpace.filterByRating(rowBlue);
		SolutionSpace intersect = blueFiltered.intersect(blueFiltered);
		assertThat(intersect.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.BLUE)));
	}

	@Test
	public void intersect3() {
		SolutionSpace solSpace = new SolutionSpace(1);
		Row rowBlue = new Row(Color.BLUE);
		rowBlue.setRating(new RowRating(1, 0));
		SolutionSpace blueFiltered = solSpace.filterByRating(rowBlue);
		SolutionSpace intersect = new SolutionSpace(1).intersect(blueFiltered);
		assertThat(intersect.getSolutionSpaceElements(), arrayContainingInAnyOrder(new Row(Color.BLUE)));
	}
}


text:
/* jshint strict: false, sub: true */
/* global print */
'use strict';

// //////////////////////////////////////////////////////////////////////////////
// / DISCLAIMER
// /
// / Copyright 2016 ArangoDB GmbH, Cologne, Germany
// /
// / 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.
// /
// / Copyright holder is ArangoDB GmbH, Cologne, Germany
// /
// / @author Dr. Frank Celler
// //////////////////////////////////////////////////////////////////////////////

const internal = require('internal');
const fs = require('fs');
const tasks = require('@arangodb/tasks');
const pathForTesting = internal.pathForTesting;

const _ = require('lodash');

const executeExternalAndWait = require('internal').executeExternalAndWait;

const db = internal.db;
const sleep = internal.sleep;

const optsDefault = {
  duration: 60, // in minutes
  gnuplot: false,
  results: 'results',
  runId: 'run'
};

// //////////////////////////////////////////////////////////////////////////////
// / @brief create image using gnuplot
// //////////////////////////////////////////////////////////////////////////////

function gnuplot () {
  executeExternalAndWait('gnuplot', 'out/kills.plot');
}

// //////////////////////////////////////////////////////////////////////////////
// / @brief statistics generator
// //////////////////////////////////////////////////////////////////////////////

let statisticsInitialized = false;

const killsLog = fs.join('out', 'kills.csv');
const types = ['inserter', 'updater', 'remover', 'killer'];

function statistics (opts) {
  if (!statisticsInitialized) {
    fs.makeDirectoryRecursive('out');

    fs.write(killsLog, '# ' + types.join('\t') + '\n');

    statisticsInitialized = true;
  }

  const results = opts.results;

  let runtime = Math.round(((new Date()) - opts.startTime) / 1000);
  let line = [runtime];

  for (let i = 0; i < types.length; ++i) {
    const s = db._query(
      `
       FOR u IN @@results
         FILTER u.type == @type
         RETURN u.statistics
      `, {
        '@results': results,
        'type': types[i]
      }).toArray()[0];

    if (s !== undefined) {
      line.push(s.count);
      line.push(s.success);
      line.push(s.failures);
    } else {
      line.push(0);
      line.push(0);
      line.push(0);
    }
  }

  fs.append(killsLog, line.join('\t') + '\n');
}

// //////////////////////////////////////////////////////////////////////////////
// / @brief INSERTER
// //////////////////////////////////////////////////////////////////////////////

exports.inserter = function (opts) {
  const runId = opts.runId;

  const duration = opts.duration;
  const start = Date.now();
  const end = start + 1000 * 60 * duration;

  const results = opts.results;
  const r = db._collection(results);

  try {
    r.remove(runId);
  } catch (err) {}

  r.save({
    _key: runId,
    started: true,
    finished: false,
    startDate: start,
    endDate: end,
    type: 'inserter',
    statistics: {
      count: 0,
      success: 0,
      failures: 0
    }
  });

  let count = 0;
  let success = 0;
  let failures = 0;
  let lastErr = '';

  while (true) {
    ++count;

    if (count % 1000 === 0) {
      r.update(runId, {
        statistics: {
          count: count,
          success: success,
          failures: failures
        },
        lastError: lastErr
      });
    }

    let c = Math.floor(Math.random() * 8) + 2;
    let q = `
      FOR doc IN 1..@c
        INSERT {
          _from: CONCAT("posts/test", doc),
          _to: CONCAT("posts/test", @c),
          value: doc
        }
        IN edges`;

    try {
      db._query({
        query: q,
        bindVars: {
        c}
      });

      ++success;
    } catch (err) {
      if (err.errorNum !== 1500) {
        lastErr = String(err);
        print(err);
        ++failures;
      }
    }

    if (Date.now() > end) {
      break;
    }
  }

  r.update(runId, {
    finished: true,
    statistics: {
      count: count,
      success: success,
      failures: failures
    }
  });
};

// //////////////////////////////////////////////////////////////////////////////
// / @brief UPDATER
// //////////////////////////////////////////////////////////////////////////////

exports.updater = function (opts) {
  const runId = opts.runId;

  const duration = opts.duration;
  const start = Date.now();
  const end = start + 1000 * 60 * duration;

  const results = opts.results;
  const r = db._collection(results);

  try {
    r.remove(runId);
  } catch (err) {}

  r.save({
    _key: runId,
    started: true,
    finished: false,
    startDate: start,
    endDate: end,
    type: 'updater',
    statistics: {
      count: 0,
      success: 0,
      failures: 0
    }
  });

  let count = 0;
  let success = 0;
  let failures = 0;
  let lastErr = '';

  while (true) {
    ++count;

    if (count % 1000 === 0) {
      r.update(runId, {
        statistics: {
          count: count,
          success: success,
          failures: failures
        }
      });
    }

    let c = Math.floor(Math.random() * 8) + 2;
    let q = `
      FOR doc IN edges
        SORT RAND()
        LIMIT @c
        UPDATE doc WITH { value: doc.value + 1 }
        IN edges`;

    try {
      db._query({
        query: q,
        bindVars: {
        c}
      });

      success++;
    } catch (err) {
      if (err.errorNum !== 1500) {
        lastErr = String(err);
        print(err);
        ++failures;
      }
    }

    if (Date.now() > end) {
      break;
    }
  }

  r.update(runId, {
    finished: true,
    statistics: {
      count: count,
      success: success,
      failures: failures
    }
  });
};

// //////////////////////////////////////////////////////////////////////////////
// / @brief REOMVER
// //////////////////////////////////////////////////////////////////////////////

exports.remover = function (opts) {
  const runId = opts.runId;

  const duration = opts.duration;
  const start = Date.now();
  const end = start + 1000 * 60 * duration;

  const results = opts.results;
  const r = db._collection(results);

  try {
    r.remove(runId);
  } catch (err) {}

  r.save({
    _key: runId,
    started: true,
    finished: false,
    startDate: start,
    endDate: end,
    type: 'remover',
    statistics: {
      count: 0,
      success: 0,
      failures: 0
    }
  });

  let count = 0;
  let success = 0;
  let failures = 0;
  let lastErr = '';

  while (true) {
    ++count;

    if (count % 1000 === 0) {
      r.update(runId, {
        statistics: {
          count: count,
          success: success,
          failures: failures
        }
      });
    }

    let c = Math.floor(Math.random() * 8) + 2;
    let q = `
      FOR doc IN edges
        SORT RAND()
        LIMIT @c
        REMOVE doc._key
        IN edges`;

    try {
      db._query({
        query: q,
        bindVars: {
        c}
      });

      success++;
    } catch (err) {
      if (err.errorNum !== 1500) {
        lastErr = String(err);
        print(err);
        ++failures;
      }
    }

    if (Date.now() > end) {
      break;
    }
  }

  r.update(runId, {
    finished: true,
    statistics: {
      count: count,
      success: success,
      failures: failures
    }
  });
};

// //////////////////////////////////////////////////////////////////////////////
// / @brief KILLER
// //////////////////////////////////////////////////////////////////////////////

exports.killer = function (opts) {
  const runId = opts.runId;

  const duration = opts.duration;
  const start = Date.now();
  const end = start + 1000 * 60 * duration;

  const results = opts.results;
  const r = db._collection(results);

  try {
    r.remove(runId);
  } catch (err) {}

  r.save({
    _key: runId,
    started: true,
    finished: false,
    startDate: start,
    endDate: end,
    type: 'killer',
    statistics: {
      count: 0,
      success: 0,
      failures: 0
    }
  });

  let count = 0;
  let success = 0;
  let failures = 0;
  let lastErr = '';

  const queries = require('org/arangodb/aql/queries');

  while (true) {
    ++count;

    if (count % 100 === 0) {
      r.update(runId, {
        statistics: {
          count: count,
          success: success,
          failures: failures
        }
      });
    }

    queries.current().forEach(function (q) {
      if (q.query.indexOf('edges') !== -1) {
        try {
          queries.kill(q.id);
          success++;
        } catch (err) {
          if (err.errorNum !== 1591) {
            lastErr = String(err);
            print(err);
          }
          ++failures;
        }
      }
    });

    if (Date.now() > end) {
      break;
    }

    internal.wait(Math.random() * 0.1, false);
  }

  r.update(runId, {
    finished: true,
    statistics: {
      count: count,
      success: success,
      failures: failures
    }
  });
};

// //////////////////////////////////////////////////////////////////////////////
// / @brief killing
// //////////////////////////////////////////////////////////////////////////////

exports.killingParallel = function (opts) {
  _.defaults(opts, optsDefault);

  // start time
  opts.startTime = new Date();

  // create the test collections
  db._drop('edges');
  db._createEdgeCollection('edges');

  db._drop('posts');
  db._create('posts');

  // create the "results" collection
  const results = opts.results;
  db._drop(results);
  db._create(results);

  // create output directory
  fs.makeDirectoryRecursive('out');

  // start worker
  const w = [
    function (params) {
      require('./' + pathForTesting('server/stress/killingQueries')).inserter(params);
    },
    function (params) {
      require('./' + pathForTesting('server/stress/killingQueries')).updater(params);
    },
    function (params) {
      require('./' + pathForTesting('server/stress/killingQueries')).remover(params);
    },
    function (params) {
      require('./' + pathForTesting('server/stress/killingQueries')).killer(params);
    }
  ];

  for (let i = 0; i < w.length; ++i) {
    const cmd = w[i];
    let o = JSON.parse(JSON.stringify(opts));

    o.runId = 'run_' + i;

    tasks.register({
      id: 'stress' + i,
      name: 'stress test ' + i,
      offset: i,
      params: o,
      command: cmd
    });
  }

  // wait for a result
  const countDone = function () {
    const a = db._query('FOR u IN @@results FILTER u.finished RETURN 1', {
      '@results': 'results'
    });

    const b = db._query('FOR u IN @@results FILTER u.started RETURN 1', {
      '@results': 'results'
    });

    return a.count() === b.count();
  };

  let m = 0;

  for (let i = 0; i < 10; ++i) {
    m = db._query('FOR u IN @@results FILTER u.started RETURN 1', {
      '@results': 'results'
    }).count();

    print(m + ' workers are up and running');

    if (m === w.length) {
      break;
    }

    sleep(30);
  }

  if (m < w.length) {
    print('cannot start enough workers (want', w.length + ',', 'got', m + '),',
      'please check number V8 contexts');
    throw new Error('cannot start workers');
  }

  if (opts.gnuplot) {
    fs.write(fs.join('out', 'kills.plot'),
      `
set terminal png size 1024,1024
set size ratio 0.3
set output "out/kills.png"

set multiplot layout 4, 1 title "Killing Queries Stress Test" font ",14"

set autoscale
set logscale y
set key outside
set xlabel "runtime in seconds"

set ylabel "inserter"
plot \
  "out/kills.csv" using 1:2 title "count" with lines lw 2, \
  '' using 1:3 title "success" with lines, \
  '' using 1:4 title "failures" with lines

set ylabel "updater"
plot \
  "out/kills.csv" using 1:5 title "count" with lines lw 2, \
  '' using 1:6 title "success" with lines, \
  '' using 1:7 title "failures" with lines

set ylabel "remover"
plot \
  "out/kills.csv" using 1:8 title "count" with lines lw 2, \
  '' using 1:9 title "success" with lines, \
  '' using 1:10 title "failures" with lines

set ylabel "killer"
plot \
  "out/kills.csv" using 1:11 title "count" with lines lw 2, \
  '' using 1:12 title "success" with lines, \
  '' using 1:13 title "failures" with lines
`);
  }

  let count = 0;

  while (!countDone()) {
    ++count;
    statistics(opts);

    if (opts.gnuplot && count % 6 === 0) {
      print('generating image');
      gnuplot();
    }

    sleep(10);
  }

  statistics(opts);

  if (opts.gnuplot) {
    gnuplot();
  }

  return true;
};


text:
using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;

namespace DotSpatial.NTSExtension
{
    /// <summary>
    /// EnumerableEM
    /// </summary>
    public static class EnumerableExt
    {
        #region Methods

        /// <summary>
        /// cycles through any strong typed collection where the type implements ICLoneable
        /// and clones each member, inserting that member into the new list.
        /// </summary>
        /// <typeparam name="T">The type of the values in the list.</typeparam>
        /// <param name="original">The original enumerable collection of type T.</param>
        /// <returns>A deep copy of the list.</returns>
        public static List<T> CloneList<T>(this IEnumerable<T> original) where T : ICloneable
        {
            List<T> result = new List<T>();
            foreach (T item in original)
            {
                result.Add(SafeCastTo<T>(item.Clone()));
            }
            return result;
        }

        /// <summary>
        /// A Generic Safe Casting method that should simply exist as part of the core framework
        /// </summary>
        /// <typeparam name="T">The type of the member to attempt to cast to.</typeparam>
        /// <param name="obj">The original object to attempt to System.Convert.</param>
        /// <returns>An output variable of type T.</returns>
        private static T SafeCastTo<T>(object obj)
        {
            if (obj == null)
            {
                return default(T);
            }
            if (!(obj is T))
            {
                return default(T);
            }
            return (T)obj;
        }

        /// <summary>
        /// Converts an array of coordinates into points.
        /// Eventually I hope to reduce the amount of "casting" necessary, in order
        /// to allow as much as possible to occur via an interface.
        /// </summary>
        /// <param name="rawPoints"></param>
        /// <returns></returns>
        public static IPoint[] CastToPointArray(this IEnumerable<Coordinate> rawPoints)
        {
            List<IPoint> result = new List<IPoint>();
            foreach (Coordinate rawPoint in rawPoints)
            {
                result.Add(new Point(rawPoint));
            }
            return result.ToArray();
        }

        #endregion
    }
}


text:
package com.jetbrains.python.psi.resolve;

import javax.annotation.Nullable;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.psi.PyImportedNameDefiner;

/**
 * @author yole
 */
public class ImportedResolveResult extends RatedResolveResult
{
	@Nullable
	private final PyImportedNameDefiner myDefiner;

	public ImportedResolveResult(PsiElement element, int rate, @Nullable PyImportedNameDefiner definer)
	{
		super(rate, element);
		myDefiner = definer;
	}

	@Nullable
	public PyImportedNameDefiner getDefiner()
	{
		return myDefiner;
	}

	@Override
	public RatedResolveResult replace(PsiElement what)
	{
		return new ImportedResolveResult(what, getRate(), myDefiner);
	}
}


text:
package be.nokorbis.spigot.commandsigns.command.subcommands;

import be.nokorbis.spigot.commandsigns.command.ICommand;
import be.nokorbis.spigot.commandsigns.model.CommandSignsCommandException;
import be.nokorbis.spigot.commandsigns.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by nokorbis on 1/20/16.
 */
public class HelpCommand extends Command {

	private List<ICommand> commands;

	public HelpCommand(List<ICommand> commands) {
		super("help", new String[] {"h", "?"});
		this.basePermission = "commandsign.admin.help";
		this.commands = commands;
	}

	@Override
	public boolean execute(CommandSender sender, List<String> args) throws CommandSignsCommandException {
		if (args.isEmpty()) {
			if (!(sender instanceof Player)) {
				throw new CommandSignsCommandException(commandMessages.get("error.command.player_requirement"));
			}
			for (ICommand cmd : this.commands) {
				cmd.printUsage(sender, false);
			}
		}
		else {
			Counter count = new Counter();
			String subCmd = args.get(0).toLowerCase();
			this.commands.stream().filter((cmd) -> cmd.isCommand(subCmd)).forEach((cmd) -> {
				cmd.printUsage(sender);
				count.increment();
			});
			if (count.value == 0) {
				sender.sendMessage(commandMessages.get("error.command.help.invalid"));
			}
		}
		return true;
	}

	@Override
	public void printUsage(CommandSender sender) {
		sender.sendMessage("/commandsign help [command]");
	}

	@Override
	public List<String> autoComplete(CommandSender sender, List<String> args) {
		Stream<String> commandStream = this.commands.stream().filter(cmd -> cmd.hasBasePermission(sender)).map(ICommand::getCommand);

		if (!args.isEmpty()) {
			final String start = args.get(0).toLowerCase();
			commandStream = commandStream.filter(value -> value.startsWith(start));
		}
		return commandStream.collect(Collectors.toList());
	}

	private static class Counter {
		int value = 0;

		void increment() {
			value += 1;
		}
	}
}


text:
package org.csanchez.jenkins.plugins.kubernetes.pipeline;

import java.io.Serializable;

/**
 * Context object for PodTemplate during pipeline execution
 */
public class PodTemplateContext implements Serializable {
    private static final long serialVersionUID = 3065143885759619305L;

    private final String namespace;
    private final String name;

    public PodTemplateContext(String namespace, String name) {
        this.namespace = namespace;
        this.name = name;
    }

    public String getNamespace() {
        return namespace;
    }

    public String getName() {
        return name;
    }
}


text:
namespace SVI {

	class SVIRotateEffector : public SVITransitionEffector {
	public:
		SVIRotateEffector(SVIGLSurface *surface);
		virtual ~SVIRotateEffector() {}

	protected:
		void setAnimation();
	private:
		SVIFloat rotationAngle;

	};

}
#endif


text:
from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
)

urlpatterns += patterns(
    'microdash.core.views',
    url(r'^$', 'station_dashboard', name='home'),
    url(r'^(?P<shortcode>[-\w]+)/$', 'station_dashboard', name='station'),
)


text:
build:
	./bin/build


text:
/* ====================================================================
 * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    openssl-core@openssl.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */
/* ====================================================================
 * Copyright 2005 Nokia. All rights reserved.
 *
 * The portions of the attached software ("Contribution") is developed by
 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
 * license.
 *
 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
 * support (see RFC 4279) to OpenSSL.
 *
 * No patent licenses or other rights except those expressly stated in
 * the OpenSSL open source license shall be deemed granted or received
 * expressly, by implication, estoppel, or otherwise.
 *
 * No assurances are provided by Nokia that the Contribution does not
 * infringe the patent or other intellectual property rights of any third
 * party or that the license provides you with all the necessary rights
 * to make use of the Contribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
 * OTHERWISE. */

#include <openssl/ssl.h>

#include <openssl/buf.h>
#include <openssl/digest.h>
#include <openssl/err.h>

#include "internal.h"

BSSL_NAMESPACE_BEGIN

SSLTranscript::SSLTranscript() {}

SSLTranscript::~SSLTranscript() {}

bool SSLTranscript::Init() {
  buffer_.reset(BUF_MEM_new());
  if (!buffer_) {
    return false;
  }

  hash_.Reset();
  return true;
}

// InitDigestWithData calls |EVP_DigestInit_ex| on |ctx| with |md| and then
// writes the data in |buf| to it.
static bool InitDigestWithData(EVP_MD_CTX *ctx, const EVP_MD *md,
                               const BUF_MEM *buf) {
  if (!EVP_DigestInit_ex(ctx, md, NULL)) {
    return false;
  }
  EVP_DigestUpdate(ctx, buf->data, buf->length);
  return true;
}

bool SSLTranscript::InitHash(uint16_t version, const SSL_CIPHER *cipher) {
  const EVP_MD *md = ssl_get_handshake_digest(version, cipher);
  return InitDigestWithData(hash_.get(), md, buffer_.get());
}

void SSLTranscript::FreeBuffer() {
  buffer_.reset();
}

size_t SSLTranscript::DigestLen() const {
  return EVP_MD_size(Digest());
}

const EVP_MD *SSLTranscript::Digest() const {
  return EVP_MD_CTX_md(hash_.get());
}

bool SSLTranscript::UpdateForHelloRetryRequest() {
  if (buffer_) {
    buffer_->length = 0;
  }

  uint8_t old_hash[EVP_MAX_MD_SIZE];
  size_t hash_len;
  if (!GetHash(old_hash, &hash_len)) {
    return false;
  }
  const uint8_t header[4] = {SSL3_MT_MESSAGE_HASH, 0, 0,
                             static_cast<uint8_t>(hash_len)};
  if (!EVP_DigestInit_ex(hash_.get(), Digest(), nullptr) ||
      !Update(header) ||
      !Update(MakeConstSpan(old_hash, hash_len))) {
    return false;
  }
  return true;
}

bool SSLTranscript::CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest) {
  const EVP_MD *transcript_digest = Digest();
  if (transcript_digest != nullptr &&
      EVP_MD_type(transcript_digest) == EVP_MD_type(digest)) {
    return EVP_MD_CTX_copy_ex(ctx, hash_.get());
  }

  if (buffer_) {
    return EVP_DigestInit_ex(ctx, digest, nullptr) &&
           EVP_DigestUpdate(ctx, buffer_->data, buffer_->length);
  }

  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  return false;
}

bool SSLTranscript::Update(Span<const uint8_t> in) {
  // Depending on the state of the handshake, either the handshake buffer may be
  // active, the rolling hash, or both.
  if (buffer_ &&
      !BUF_MEM_append(buffer_.get(), in.data(), in.size())) {
    return false;
  }

  if (EVP_MD_CTX_md(hash_.get()) != NULL) {
    EVP_DigestUpdate(hash_.get(), in.data(), in.size());
  }

  return true;
}

bool SSLTranscript::GetHash(uint8_t *out, size_t *out_len) {
  ScopedEVP_MD_CTX ctx;
  unsigned len;
  if (!EVP_MD_CTX_copy_ex(ctx.get(), hash_.get()) ||
      !EVP_DigestFinal_ex(ctx.get(), out, &len)) {
    return false;
  }
  *out_len = len;
  return true;
}

bool SSLTranscript::GetFinishedMAC(uint8_t *out, size_t *out_len,
                                   const SSL_SESSION *session,
                                   bool from_server) {
  static const char kClientLabel[] = "client finished";
  static const char kServerLabel[] = "server finished";
  auto label = from_server
                   ? MakeConstSpan(kServerLabel, sizeof(kServerLabel) - 1)
                   : MakeConstSpan(kClientLabel, sizeof(kClientLabel) - 1);

  uint8_t digest[EVP_MAX_MD_SIZE];
  size_t digest_len;
  if (!GetHash(digest, &digest_len)) {
    return false;
  }

  static const size_t kFinishedLen = 12;
  if (!tls1_prf(Digest(), MakeSpan(out, kFinishedLen),
                MakeConstSpan(session->master_key, session->master_key_length),
                label, MakeConstSpan(digest, digest_len), {})) {
    return false;
  }

  *out_len = kFinishedLen;
  return true;
}

BSSL_NAMESPACE_END


text:
using System.Collections.Generic;
using PeNet.FileParser;

namespace PeNet.Header.Resource
{
    /// <summary>
    /// Describes the data representation in a file-version resource.
    /// Information about different languages and codes pages is contained in
    /// this structure.
    /// </summary>
    public class StringFileInfo : AbstractStructure
    {
        private StringTable[]? _stringTable;

        /// <summary>
        /// Create a new StringFileInfo instance.
        /// </summary>
        /// <param name="peFile">A PE file.</param>
        /// <param name="offset">Offset of a StringFileInfo structure in the PE file.</param>
        public StringFileInfo(IRawFile peFile, long offset)
            : base(peFile, offset)
        {
        }

        /// <summary>
        /// Length of the StringFileInfo in bytes, including all children.
        /// </summary>
        public ushort WLength
        {
            get => PeFile.ReadUShort(Offset);
            set => PeFile.WriteUShort(Offset, value);
        }

        /// <summary>
        /// Always zero.
        /// </summary>
        public ushort WValueLength
        {
            get => PeFile.ReadUShort(Offset + 0x2);
            set => PeFile.WriteUShort(Offset + 0x2, value);
        }

        /// <summary>
        /// Type of the data in the version resource. Contains a 1 if the data
        /// is text data and a 0 if it contains binary data.
        /// </summary>
        public ushort WType
        {
            get => PeFile.ReadUShort(Offset + 0x4);
            set => PeFile.WriteUShort(Offset + 0x4, value);
        }

        /// <summary>
        /// Contains the Unicode string "StringFileInfo".
        /// </summary>
        public string SzKey => PeFile.ReadUnicodeString(Offset + 0x6);

        /// <summary>
        /// One ore more StringTable structures, where each tables szKey indicates
        /// the language and code page for displaying the text in the StringTable.
        /// </summary>
        public StringTable[] StringTable {
            get
            {
                _stringTable ??= ReadChildren();
                return _stringTable;
            }
        }

        private StringTable[] ReadChildren()
        {
            var currentOffset =
                Offset + 6 + SzKey.UStringByteLength()
                + (Offset + 6 + SzKey.UStringByteLength()).PaddingBytes(32);

            var children = new List<StringTable>();

            while (currentOffset < Offset + WLength)
            {
                var st = new StringTable(PeFile, currentOffset);

                if (st.WLength == 0)
                    break;

                currentOffset += st.WLength;
                children.Add(st);
            }

            return children.ToArray();
        }
    }
}


text:
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Query\AST;

/**
 * ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary
 */
class ArithmeticFactor extends Node
{
    /**
     * @var Node
     */
    public $arithmeticPrimary;

    /**
     * NULL represents no sign, TRUE means positive and FALSE means negative sign.
     *
     * @var bool|null
     */
    public $sign;

    /**
     * @param mixed     $arithmeticPrimary
     * @param bool|null $sign
     */
    public function __construct($arithmeticPrimary, $sign = null)
    {
        $this->arithmeticPrimary = $arithmeticPrimary;
        $this->sign              = $sign;
    }

    /**
     * @return bool
     */
    public function isPositiveSigned()
    {
        return $this->sign === true;
    }

    /**
     * @return bool
     */
    public function isNegativeSigned()
    {
        return $this->sign === false;
    }

    /**
     * {@inheritdoc}
     */
    public function dispatch($sqlWalker)
    {
        return $sqlWalker->walkArithmeticFactor($this);
    }
}


text:
<!doctype html>

		<title>Zabuun - Learn Egyptian Arabic for English speakers</title>
		<meta name="description" content="">
		<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/head.php';?>

		<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/ie8.php';?>
		<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/header.php';?>

			<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/side.php';?>

Essays > My Dad

						Expand All | Collapse All

My Dad

  I love my dad. He was a good man. He taught me to work hard. He taught me to keep trying. He taught me to do things right or don't do them at all. He grew up on the streets of New York City. His parents didn't speak English. He had three brothers and one sister. His brothers ended up in jail. His sister died in a car crash. My dad married my mom when they were both 19. My dad joined the army. He jumped out of airplanes. Then he became a military policeman. He did this for 20 years. He liked his job. He was a hard worker. He went to college while he was in the army. He got two college degrees. One college degree is good. Two college degrees is very good. He retired from the army and became a teacher. He taught high school kids. He taught high school kids for 20 years. He had a lot of patience. Teachers need a lot of patience. Then my dad retired. He traveled around the world with my mom. They both died in a plane crash. That was bad. But they died together. That was good.

		<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/footer.php';?>
		<?php include $_SERVER['DOCUMENT_ROOT'].'/layout/scripts.php';?>


text:
A collection of PowerShell scripts to make server administration easier

## Exchange Scripts
### Create Sequential Public Folders
Use to create sequentially numbered public folders in a given path.

### Set Calendar Access
Use to allow all users in a group to view all calendars.

## File/Folder Scripts
### Delete Empty Directories
Use to delete empty directories that match a name.


text:
import os
import sys
import logging

class HandlerRegistry(object):
    """Register anaconda JsonServer handlers
    """

    initialized = False

    def __init__(self):
        self._handlers = {}

    def initialize(self):
        """Load handlers from anaconda installed plugins
        """

        if self.initialized:
            return

        self._import_plugin_handlers()
        self.initialized = True

    def get(self, handler_type):
        """Retrieve the given handler type or none
        """

        return self._handlers.get(handler_type)

    def register(self, handler):
        """Register a new handler
        """

        self._handlers[handler.__handler_type__] = handler

    def _import_plugin_handlers(self):
        """Import hadnlers from anaconda plugins
        """

        path = os.path.join(os.path.dirname(__file__), '../../../')
        packages = [
            os.path.join(path, f) for f in os.listdir(path)
            if f.startswith('anaconda_')
        ]
        for package in packages:
            if 'vagrant' in package or not os.path.isdir(package):
                continue

            lang = package.rsplit('anaconda_', 1)[1]
            sys.path.append('{}/plugin'.format(package))
            mod_name = 'handlers_{}'.format(lang)
            mod = __import__(mod_name, globals(), locals())
            logging.info(
                '[anaconda_plugins] imported handlers for {}'.format(mod)
            )


text:
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

module GRApi where

import Auth
       (signRequest, grAuthenticate, credz, defaultAuthHandler)
import Settings
import Types
import Web.Authenticate.OAuth
       (unCredential,
        newCredential)
import XML
import Data.AppSettings
       (GetSetting(..), readSettings,
        FileLocation(AutoFromAppName),
        saveSettings, setSetting, Conf)
import Data.ByteString.Char8 (pack)
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.ByteString.UTF8 (ByteString)
import Data.Foldable (for_)
import qualified Data.Text.IO as T
import qualified Data.Text as DT
import Data.Text.Lazy (fromStrict)
import Data.Text.Lazy.Encoding (decodeUtf8)
import Formatting
import Network.HTTP (urlEncode)
import Network.HTTP.Client
       (newManager, responseBody, Manager, httpLbs, method)
import Network.HTTP.Simple
       (Request, parseRequest, setRequestQueryString, getResponseBody)
import qualified Text.Pandoc as Pandoc
import Text.XML (parseText_, def)
import Control.Exception.Safe -- (IOException(..), catches, try, throw, Exception)
import Control.Monad (guard)
import qualified Data.ByteString.UTF8 as BSU
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import System.Console.Haskeline
import System.Environment (getEnv)
import System.IO.Error (isDoesNotExistError)

-- | Auth Stuff: API Key and API Secret, get from system environment.
getKeysFromEnv :: IO AppCredentials
getKeysFromEnv = do
  grApiKey <- getEnv "GOODREADS_API_KEY"
  grApiSecret <- getEnv "GOODREADS_API_SECRET"
  return
    AppCredentials
    {applicationKey = pack grApiKey, applicationSecret = pack grApiSecret}

lookupConfig :: IO (Maybe (Conf, GetSetting))
lookupConfig =
  catchJust
    (guard . isDoesNotExistError)
    (Just <$> (readSettings (AutoFromAppName "goodreads")))
    (\_ -> return Nothing)

saveConfig :: GrConfig -> AppCredentials -> IO ()
saveConfig cfg _ -- conf? as 2nd arg
 = do
  let (tokenString, tokenSecretString) = credz (loginCredentials cfg)
  let defaultUID = fromMaybe 0 (defaultUserID cfg)
  let conf1 = setSetting Map.empty oAuthToken tokenString
  let conf2 = setSetting conf1 oAuthSecret tokenSecretString
  let conf3 = setSetting conf2 defaultUser defaultUID
  let conf4 = setSetting conf3 setApiKey "" -- appCredentials
  let conf5 = setSetting conf4 setApiSecret ""
  saveSettings defaultConfig (AutoFromAppName "goodreads") conf5

initGr :: Manager -> AuthRequest -> AuthHandler -> IO Gr
initGr man req authMethod = do
  x <- lookupConfig
  case x of
    Just (conf, GetSetting getSetting) -> do
      let secret = getSetting oAuthSecret
      case secret of
        "" -> do
          putStrLn "No OAuth token found" -- getnewsecrets?
          creds <- grAuthenticate man req authMethod
          let (tokenString, tokenSecretString) = credz creds
          putStrLn "Saved new OAauth token and secret to config file"
          let cfg =
                GrConfig
                { loginCredentials =
                    newCredential
                      (pack $ tokenString)
                      (pack $ tokenSecretString)
                , defaultUserID = Just (getSetting defaultUser)
                }
          let crd = (requestAppCredentials req)
          saveConfig cfg crd
          return $ Gr cfg man crd
        _ -> do
          let cfg =
                GrConfig
                { loginCredentials =
                    newCredential (pack $ getSetting oAuthToken) (pack $ secret)
                , defaultUserID = Just (getSetting defaultUser)
                }
          saveSettings defaultConfig (AutoFromAppName "goodreads") conf
          putStrLn "Loaded config file"
          return $ Gr cfg man (requestAppCredentials req)
    Nothing -> do
      putStrLn "No config file found."
      credentials <- grAuthenticate man req authMethod
      let (tokenString, tokenSecretString) = credz credentials
      putStrLn "Saved new OAauth token and secret to config file"
      let cfg =
            GrConfig
            { loginCredentials =
                newCredential (pack $ tokenString) (pack $ tokenSecretString)
            , defaultUserID = Nothing
            }
      let appCreds = (requestAppCredentials req)
      saveConfig cfg appCreds
      return $ Gr cfg man appCreds

-- | Begin Api Methods
restAPI
  :: MonadThrow m
  => Gr -> String -> [(ByteString, Maybe ByteString)] -> m Request
restAPI gr endpoint params
    -- Add API Key to params (if it is not in there FIXME?)
 = do
  let key = (BSU.toString (applicationKey (appCredentials gr)))
  let paramsWithKey =
        Map.toList $
        Map.insert (pack "key") (Just (pack key)) $ Map.fromList params
  req' <- parseRequest $ "https://www.goodreads.com/" ++ endpoint
  let request = setRequestQueryString paramsWithKey $ req'
  return request

doGr :: AppOptions -> IO Gr
doGr app = do
  keys <-
    try $
    case apiKey app of
      Just k -- Key was provided as argument
       ->
        return
          AppCredentials
          {applicationKey = pack k, applicationSecret = pack "NOT IMPLEMENTED"}
      Nothing -> do
        x <- lookupConfig
        case x of
          Just (_, GetSetting getSetting) -> do
            let api_Key = getSetting setApiKey
            let apiSecret = getSetting setApiSecret
            case (any null [api_Key, apiSecret]) of
              False ->
                return
                  AppCredentials
                  { applicationKey = pack api_Key
                  , applicationSecret = pack apiSecret
                  }
              True -> getKeysFromEnv -- not found in args, nor in config file.
          Nothing -> getKeysFromEnv
  case keys of
    Left (_ :: SomeException) ->
      error
        "Error Loading API Keys: Set GOODREADS_API_KEY, GOODREADS_API_SECRET"
    Right k -> do
      let authReq =
            AuthRequest
            { applicationName = "Gr"
            , expiration = Nothing
            , scope = [Read, Write]
            , requestAppCredentials = k
            }
      manager <- newManager tlsManagerSettings
      initGr manager authReq defaultAuthHandler

putAddBook
  :: MonadThrow m
  => Gr -> ShelfName -> BookID -> m Request
putAddBook conMan shelfName bookID = do
  let i = restAPI conMan ("shelf/add_to_shelf.xml") opts
        where
          opts =
            [ (pack "name", Just $ pack shelfName)
            , (pack "book_id", Just $ pack $ show bookID)
            ] :: [(ByteString, Maybe ByteString)]
  z <- i
  let req = z {method = "POST"}
  return req

getShowBook
  :: MonadThrow m
  => Gr -> BookID -> m Request
getShowBook conMan eBookQ = do
  let (uri, opts) = ("book/show/" ++ show eBookQ ++ ".xml", [])
  restAPI conMan uri opts

getFindAuthorByName
  :: MonadThrow m
  => Gr -> AuthorName -> m Request
getFindAuthorByName conMan authorName = do
  restAPI conMan ("api/author_url/" ++ (urlEncode authorName)) []

getUserFollowers
  :: MonadThrow m
  => Gr -> User -> m Request
getUserFollowers conMan user =
  restAPI conMan ("user/" ++ show (uid user) ++ "/followers.xml") []

getFindBooks
  :: MonadThrow m
  => Gr -> String -> m Request
getFindBooks conMan t = restAPI conMan ("search/index.xml") opts
  where
    opts = [(pack "q", Just $ pack t)] :: [(ByteString, Maybe ByteString)]

getBooksFromShelf
  :: MonadThrow m
  => Gr -> User -> String -> m Request
getBooksFromShelf conMan user shelf =
  restAPI conMan ("review/list/" ++ show (uid user) ++ ".xml") opts
  where
    opts =
      [(pack "v", Just $ pack "2"), (pack "shelf", Just $ pack shelf)] :: [(ByteString, Maybe ByteString)]

out :: DT.Text -> IO ()
out txt = runInputT defaultSettings loop
  where
    loop :: InputT IO ()
    loop = do
      outputStr $ DT.unpack txt
      return ()

doFindBook :: AppOptions -> String -> IO ()
doFindBook opts findTitle = do
  gr <- doGr opts
  req <- getFindBooks gr findTitle
  resp <- httpLbs req (connectionManager gr)
  let eBooks = respToBooks resp
  case eBooks of
    Right books -> printListOfBooks books
    Left _ -> do
      print req -- FIXME: Case debug
      fail "failed in parsing." -- FIXME: undefined -- some error in parsing See Throw, control.exceptions
  where
    respToBooks = parseBookSearch . parseText_ def . decodeUtf8 . responseBody

printListOfBooks :: [Book] -> IO ()
printListOfBooks books = do
  let booksEnumerated = (zip [1 :: Integer ..] books)
  for_ booksEnumerated $ \(i, book) -> do
    let formatEnum = (int % ": " % text % " [" % text % "]\n")
    let msg =
          sformat
            formatEnum
            i
            (fromStrict (title book))
            (fromStrict $ fromMaybe "" (bookId book))
    out msg

doShowShelf :: AppOptions -> ShelfName -> UserID -> IO ()
doShowShelf opts shelf uID = do
  gr <- doGr opts
  let user_id =
        case uID of
          0 ->
            case defaultUserID (config gr) of
              Just u -> u
              Nothing -> uID -- try the default user
          _ -> uID
  req <-
    getBooksFromShelf
      gr
      User
      { uid = user_id -- fixme: this shouldn't ever be called with 0
      , name = Nothing
      }
      shelf
  resp <- signRequest gr req -- try
  let eBooks = respToBooks resp
  case eBooks of
    Right books -> do
      printListOfBooks books -- for_ books $ \book -> printT $ title book
      putStrLn ("OAuth Used: " ++ statusOauth)
      where statusOauth =
              case (snd (head (unCredential (loginCredentials (config gr))))) of
                "" -> "NO"
                _ -> "YES/MAYBE"
    Left _ -> do
      print req -- FIXME: Case debug
      fail "failed in parsing." -- FIXME: undefined -- some error in parsing See Throw, control.exceptions
  where
    respToBooks =
      parseGoodreadsFeed . parseText_ def . decodeUtf8 . responseBody

doFindAuthor :: AppOptions -> AuthorName -> IO ()
doFindAuthor opts authorName = do
  gr <- doGr opts
  req <- getFindAuthorByName gr authorName
  response <- signRequest gr req
  L8.putStrLn $ getResponseBody response

doAddBook :: AppOptions -> ShelfName -> BookID -> IO ()
doAddBook opts shelfName bookID = do
  gr <- doGr opts
  req <- putAddBook gr shelfName bookID
  response <- signRequest gr req
  L8.putStrLn $ getResponseBody response

htmlToMd html =
  Pandoc.runPure $ Pandoc.readHtml Pandoc.def html >>= Pandoc.writeMarkdown Pandoc.def

doShowBook :: AppOptions -> BookID -> IO ()
doShowBook opts eBookQ = do
  gr <- doGr opts
  req <- getShowBook gr eBookQ
  response <- signRequest gr req
  let bookInf = parseBookInfo . parseText_ def . decodeUtf8 . responseBody
  let bookInfo = bookInf response
  L8.putStrLn $ getResponseBody response
  case bookInfo of
    Just t -> case htmlToMd t of
        Left _ -> fail "Pandoc failed"
        Right x -> out x
    _ -> fail "Fetch failed"


text:
package org.apache.pig.backend.hadoop.executionengine.spark.running;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobID;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigHadoopLogger;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigInputFormat;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigMapReduce;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigSplit;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
import org.apache.pig.backend.hadoop.executionengine.shims.HadoopShims;
import org.apache.pig.backend.hadoop.executionengine.util.MapRedUtil;
import org.apache.pig.data.SchemaTupleBackend;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.PigContext;
import org.apache.pig.impl.PigImplConstants;
import org.apache.pig.impl.util.ObjectSerializer;
import org.apache.pig.impl.util.UDFContext;
import org.apache.pig.tools.pigstats.PigStatusReporter;

public class PigInputFormatSpark extends PigInputFormat {

@Override
public RecordReader<Text, Tuple> createRecordReader(InputSplit split,
                                                    TaskAttemptContext context) throws IOException,
        InterruptedException {
    initLogger();
    resetUDFContext();
    //PigSplit#conf is the default hadoop configuration, we need get the configuration
    //from context.getConfigration() to retrieve pig properties
    PigSplit pigSplit = (PigSplit) split;
    Configuration conf = context.getConfiguration();
    pigSplit.setConf(conf);
    //Set current splitIndex in PigMapReduce.sJobContext.getConfiguration.get(PigImplConstants.PIG_SPLIT_INDEX)
    //which will be used in POMergeCogroup#setup
    if (PigMapReduce.sJobContext == null) {
        PigMapReduce.sJobContext = HadoopShims.createJobContext(conf, new JobID());
    }
    PigMapReduce.sJobContext.getConfiguration().setInt(PigImplConstants.PIG_SPLIT_INDEX, pigSplit.getSplitIndex());
    // Here JobConf is first available in spark Executor thread, we initialize PigContext,UDFContext and
    // SchemaTupleBackend by reading properties from JobConf
    initialize(conf);
    return super.createRecordReader(split, context);
}

    private void initialize(Configuration jobConf) throws IOException {
        MapRedUtil.setupUDFContext(jobConf);
        PigContext pc = (PigContext) ObjectSerializer.deserialize(jobConf.get("pig.pigContext"));
        SchemaTupleBackend.initialize(jobConf, pc);
        PigMapReduce.sJobConfInternal.set(jobConf);
    }

    private void resetUDFContext() {
        UDFContext.getUDFContext().reset();
    }

    private void initLogger() {
        PigHadoopLogger pigHadoopLogger = PigHadoopLogger.getInstance();
        pigHadoopLogger.setReporter(PigStatusReporter.getInstance());
        PhysicalOperator.setPigLogger(pigHadoopLogger);
    }
}