text:
package org.elasticsearch.xpack.core.ml.inference.preprocessing.customwordembedding;

import org.apache.lucene.util.Counter;

import java.util.Map;
import java.util.TreeMap;

/**
 * Derived from: https://github.com/google/cld3/blob/master/src/relevant_script_feature.cc
 *
 * This extracts an array of {@link FeatureValue} from the given text.
 *
 * These values contain the particular script id for each code point (determined via {@link ScriptDetector})
 * and their average occurrence in the text.
 *
 */
public class RelevantScriptFeatureExtractor implements FeatureExtractor {

    @Override
    public FeatureValue[] extractFeatures(String text) {
        if (text.isEmpty()) {
            return new FeatureValue[0];
        }

        // counts[s] is the number of characters with script s.
        // Use treemap so results are sorted in scriptid order
        final Counter totalCount = Counter.newCounter();
        TreeMap<ScriptDetector.Script, Counter> counts = new TreeMap<>();

        text.codePoints().forEach(cp -> {
            // Get anything that is a letter, or anything complex enough warranting a check (more than one UTF-8 byte).
            // cp > Byte.MAX_VALUE works as the first 127 codepoints are the same as the ASCII encoding,
            // which is the same as one UTF-8 byte.
            if (Character.isLetter(cp) || cp > Byte.MAX_VALUE) {
                ScriptDetector.Script script = ScriptDetector.Script.fromCodePoint(cp);
                counts.computeIfAbsent(script, (s) -> Counter.newCounter()).addAndGet(1);
                totalCount.addAndGet(1L);
            }
        });

        FeatureValue[] result = new FeatureValue[counts.size()];
        int index = 0;

        for (Map.Entry<ScriptDetector.Script, Counter> entry : counts.entrySet()) {
            ScriptDetector.Script scriptId = entry.getKey();
            long count = entry.getValue().get();
            double weight = (double) count / (double) totalCount.get();
            result[index++] = new ContinuousFeatureValue(scriptId.toInt(), weight);
        }

        return result;
    }

}


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

public class WheelPhys : MonoBehaviour
{
    WheelCollider wc;
    float originalForwardStiffness;
    float originalSidewaysStiffness;

    void Awake()
    {
        wc = gameObject.GetComponent<WheelCollider>();
        originalForwardStiffness = wc.forwardFriction.stiffness;
        originalSidewaysStiffness = wc.sidewaysFriction.stiffness;
    }

    void FixedUpdate()
    {
        WheelHit hit;
        if (wc.GetGroundHit(out hit))
        {
            WheelFrictionCurve fFriction = wc.forwardFriction;
            fFriction.stiffness = hit.collider.material.staticFriction * originalForwardStiffness;
            wc.forwardFriction = fFriction;

            WheelFrictionCurve sFriction = wc.sidewaysFriction;
            sFriction.stiffness = hit.collider.material.staticFriction * originalSidewaysStiffness;
            wc.sidewaysFriction = sFriction;
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.IO;
using Microsoft.Extensions.Options;
using Mustache.Reports.Domain;
using Mustache.Reports.Domain.Csv;
using Mustache.Reports.Domain.Options;
using StoneAge.CleanArchitecture.Domain.Messages;
using StoneAge.CleanArchitecture.Domain.Presenters;
using StoneAge.Synchronous.Process.Runner;

namespace Mustache.Reports.Data.Csv
{
    public class CsvGateway : ICsvGateway
    {
        private readonly string _libreOffice;

        public CsvGateway(IOptions<MustacheReportOptions> options)
        {
            _libreOffice = options.Value.LibreOfficeLocation;
        }

        public RenderedDocumentOutput ConvertToCsv(RenderCsvInput inputMessage)
        {
            using (var renderDirectory = GetWorkspace())
            {
                var pdfPresenter = new PropertyPresenter<string, ErrorOutput>();

                var reportPath = PresistFile(inputMessage, renderDirectory);

                CovertToCsv(reportPath, renderDirectory, pdfPresenter);

                return RenderingErrors(pdfPresenter) ? ReturnErrors(pdfPresenter) : ReturnPdf(reportPath);
            }
        }

        private void CovertToCsv(string reportPath, DisposableWorkSpace renderDirectory, PropertyPresenter<string, ErrorOutput> pdfPresenter)
        {
            var executor = new SynchronousAction(new XlsxToCsvTask(_libreOffice, reportPath, renderDirectory.TmpPath),
                new ProcessFactory());
            executor.Execute(pdfPresenter);
        }

        private bool RenderingErrors(PropertyPresenter<string, ErrorOutput> presenter)
        {
            return presenter.IsErrorResponse();
        }

        private RenderedDocumentOutput ReturnPdf(string reportPath)
        {
            var filePath = reportPath.Replace(".xlsx", ".csv");
            var result = new RenderedDocumentOutput
            {
                Base64String = Convert.ToBase64String(File.ReadAllBytes(filePath)),
                ContentType = ContentTypes.Pdf
            };
            return result;
        }

        private string PresistFile(RenderCsvInput inputMessage, DisposableWorkSpace renderDirectory)
        {
            var reportPath = Path.Combine(renderDirectory.TmpPath, "report.xlsx");
            WriteTo(reportPath, inputMessage.Base64ExcelFile);
            return reportPath;
        }

        private RenderedDocumentOutput ReturnErrors(PropertyPresenter<string, ErrorOutput> presenter)
        {
            var result = new RenderedDocumentOutput();
            result.ErrorMessages.AddRange(presenter.ErrorContent.Errors);
            return result;
        }

        private void WriteTo(string filePath, string data)
        {
            var decodedData = Convert.FromBase64String(data);
            File.WriteAllBytes(filePath, decodedData);
        }

        private DisposableWorkSpace GetWorkspace()
        {
            return new DisposableWorkSpace();
        }
    }
}


text:
IonPopup = {
  show: function (options) {
    this.template = Template.ionPopup;
    this.buttons = [];
    var innerTemplate;

    for (var i = 0; i < options.buttons.length; i++) {
      var button = options.buttons[i];
      this.buttons.push({
        text: button.text,
        type: button.type,
        index: i,
        onTap: button.onTap
      });
    }

    //Figure out if a template or just a html string was passed
    if (options.templateName) {
      innerTemplate = Template[options.templateName].renderFunction().value;
    } else {
      innerTemplate = '' + options.template + '';
    }

    var data = {
      title: options.title,
      subTitle: options.subTitle,
      buttons: this.buttons,
      template: innerTemplate
    };

    this.view = Blaze.renderWithData(this.template, data, $('.ionic-body').get(0));
    $('body').addClass('popup-open');

    var $backdrop = $(this.view.firstNode());
    $backdrop.addClass('visible active');
    var $popup = $backdrop.find('.popup-container');
    $popup.addClass('popup-showing active');
  },

  alert: function (options) {
    IonPopup.show({
      title: options.title,
      subTitle: options.subTitle,
      template: options.template,
      templateName: options.templateName,
      buttons: [
        {
          text: options.okText ? options.okText : 'Ok',
          type: options.okType ? options.okType : 'button-positive',
          onTap: function(event, template) {
            if (options.onOk) options.onOk(event, template);
            return true;
          }
        }
      ]
    });
  },

  confirm: function (options) {
    IonPopup.show({
      title: options.title,
      subTitle: options.subTitle,
      template: options.template,
      templateName: options.templateName,
      buttons: [
        {
          text: options.okText ? options.okText : 'Ok',
          type: options.okType ? options.okType : 'button-positive',
          onTap: function (event, template) {
            if (options.onOk) options.onOk(event, template);
            return true;
          }
        },
        {
          text: options.cancelText ? options.cancelText : 'Cancel',
          type: options.cancelType ? options.cancelType : 'button-default',
          onTap: function (event, template) {
            if (options.onCancel) options.onCancel(event, template);
            return true;
          }
        }
      ]
    });
  },

  prompt: function (options) {

    if (options.templateName) {
      template = Template[options.templateName].renderFunction().value;
    } else {
      template = '' + options.template + '';
    }

    template += '<input type="' + options.inputType + '" placeholder="' +
      options.inputPlaceholder + '" name="prompt" >';

    IonPopup.show({
      title: options.title,
      subTitle: options.subTitle,
      template: template,
      buttons: [
        {
          text: options.okText ? options.okText : 'Ok',
          type: options.okType ? options.okType : 'button-positive',
          onTap: function (event, template) {
            var inputVal = $(template.firstNode).find('[name=prompt]').val();
            if (options.onOk) options.onOk(event, inputVal);
            return true;
          }
        },
        {
          text: options.cancelText ? options.cancelText : 'Cancel',
          type: options.cancelType ? options.cancelType : 'button-default',
          onTap: function (event, template) {
            if (options.onCancel) options.onCancel(event, template);
            return true;
          }
        }
      ]
    });
  },

  close: function () {
    var $backdrop = $(this.view.firstNode());
    var $popup = $backdrop.find('.popup-container');
    $popup.addClass('popup-hidden').removeClass('active');

    setTimeout(function () {
      $('body').removeClass('popup-open');
      Blaze.remove(this.view);
    }.bind(this), 100);
  },

  buttonClicked: function (index, event, template) {
    var callback = this.buttons[index].onTap;
    if(callback){
      if (callback(event, template) === true) {
        IonPopup.close();
      }
    }
  }
};

Template.ionPopup.rendered = function () {
  $(window).on('keyup.ionPopup', function(event) {
    if (event.which == 27) {
      IonPopup.close();
    }
  });
};

Template.ionPopup.destroyed = function () {
  $(window).off('keyup.ionPopup');
};

Template.ionPopup.events({
  // Handle clicking the backdrop
  'click': function (event, template) {
    if ($(event.target).hasClass('popup-container')) {
      IonPopup.close();
    }
  },

  'click [data-index]': function (event, template) {
    var index = $(event.target).data('index');
    IonPopup.buttonClicked(index, event, template);
  }

});


text:
/* -*- mode: c -*-
 * $Id: methcall.c 36673 2007-05-03 16:55:46Z laurov $
 * http://www.bagley.org/~doug/shootout/
 */

#include <stdio.h>
#include <stdlib.h>

enum {false, true};

#define TOGGLE \
    char state; \
    char (*value)(struct Toggle *); \
    struct Toggle *(*activate)(struct Toggle *)

#define DESTROY  free

typedef struct Toggle {
    TOGGLE;
} Toggle;

char toggle_value(Toggle *this) {
    return(this->state);
}
Toggle *toggle_activate(Toggle *this) {
    this->state = !this->state;
    return(this);
}
Toggle *init_Toggle(Toggle *this, char start_state) {
    this->state = start_state;
    this->value = toggle_value;
    this->activate = toggle_activate;
    return(this);
}
Toggle *new_Toggle(char start_state) {
    Toggle *this = (Toggle *)malloc(sizeof(Toggle));
    return(init_Toggle(this, start_state));
}

typedef struct NthToggle {
    TOGGLE;
    int count_max;
    int counter;
} NthToggle;

NthToggle *nth_toggle_activate(NthToggle *this) {
    if (++this->counter >= this->count_max) {
	this->state = !this->state;
	this->counter = 0;
    }
    return(this);
}
NthToggle *init_NthToggle(NthToggle *this, int max_count) {
    this->count_max = max_count;
    this->counter = 0;
    this->activate = (Toggle *(*)(Toggle *))nth_toggle_activate;
    return(this);
}
NthToggle *new_NthToggle(char start_state, int max_count) {
    NthToggle *this = (NthToggle *)malloc(sizeof(NthToggle));
    this = (NthToggle *)init_Toggle((Toggle *)this, start_state);
    return(init_NthToggle(this, max_count));
}

int main(int argc, char *argv[]) {
#ifdef SMALL_PROBLEM_SIZE
#define LENGTH 50000000
#else
#define LENGTH 500000000
#endif
    int i, n = ((argc == 2) ? atoi(argv[1]) : LENGTH);
    Toggle *tog;
    NthToggle *ntog;
    char val = true;

    tog = new_Toggle(true);
    for (i=0; i<n; i++) {
	val = tog->activate(tog)->value(tog);
    }
    puts(val ? "true\n" : "false\n");
    DESTROY(tog);

    val = true;
    ntog = new_NthToggle(val, 3);
    for (i=0; i<n; i++) {
	val = ntog->activate(ntog)->value(ntog);
    }
    puts(val ? "true\n" : "false\n");
    DESTROY(ntog);
    return 0;
}


text:
package calendar

import (
	"time"

	SDK "google.golang.org/api/calendar/v3"
)

type EventListResponse struct {
	*SDK.Events
}

// EventList contains multiple calendar events.
type EventList struct {
	List []Event
}

// Event contains event information on Google Calendar.
type Event struct {
	ID          string
	Status      string
	Summary     string
	Description string
	Location    string
	HTMLLink    string
	HangoutLink string
	ICalUID     string

	StartTime     time.Time
	EndTime       time.Time
	IsAllDayEvent bool

	Attendees []User
	Creator   User
	Organizer User

	Transparent bool
	Visibility  string
	Locked      bool
	PrivateCopy bool
	Sequence    int64
	Kind        string

	Source    EventSource
	Reminders EventReminders

	Created time.Time
	Updated time.Time
}

func (e Event) IsStatusConfirmed() bool {
	return e.Status == "confirmed"
}

func NewEvents(list []*SDK.Event) []Event {
	results := make([]Event, len(list))
	for i, e := range list {
		results[i] = NewEvent(e)
	}
	return results
}

func NewEvent(e *SDK.Event) Event {
	return Event{
		ID:            e.Id,
		Status:        e.Status,
		Summary:       e.Summary,
		Description:   e.Description,
		Location:      e.Location,
		HTMLLink:      e.HtmlLink,
		HangoutLink:   e.HangoutLink,
		ICalUID:       e.ICalUID,
		StartTime:     mustTimeFromDateTime(e.Start),
		EndTime:       mustTimeFromDateTime(e.End),
		IsAllDayEvent: isAllDayEvent(e.Start, e.End),
		Creator:       newUserFromCreator(e.Creator),
		Organizer:     newUserFromOrganizer(e.Organizer),
		Attendees:     newUserFromAttendees(e.Attendees),
		Transparent:   e.Transparency == "tranparent",
		Visibility:    e.Visibility,
		Locked:        e.Locked,
		PrivateCopy:   e.PrivateCopy,
		Sequence:      e.Sequence,
		Kind:          e.Kind,
		Reminders:     newEventReminders(e.Reminders),
		Source:        newEventSource(e.Source),
		Created:       mustTimeFromString(e.Created),
		Updated:       mustTimeFromString(e.Updated),
	}
}

func mustTimeFromString(str string) time.Time {
	dt, _ := time.Parse(time.RFC3339, str)
	return dt
}

func mustTimeFromDateTime(dt *SDK.EventDateTime) time.Time {
	if dt.Date != "" {
		t, _ := time.Parse("2006-01-02", dt.Date)
		return t
	}

	t, _ := time.Parse(time.RFC3339, dt.DateTime)
	return t
}

func isAllDayEvent(start, end *SDK.EventDateTime) bool {
	return start.Date != "" && end.Date != ""
}

type User struct {
	ID             string
	Email          string
	DisplayName    string
	ResponseStatus string
	Self           bool
	Organizer      bool
}

func newUserFromAttendees(list []*SDK.EventAttendee) []User {
	results := make([]User, len(list))
	for i, e := range list {
		results[i] = newUserFromAttendee(e)
	}
	return results
}

func newUserFromAttendee(e *SDK.EventAttendee) User {
	if e == nil {
		return User{}
	}

	return User{
		ID:             e.Id,
		Email:          e.Email,
		DisplayName:    e.DisplayName,
		ResponseStatus: e.ResponseStatus,
		Self:           e.Self,
		Organizer:      e.Organizer,
	}
}

func newUserFromCreator(e *SDK.EventCreator) User {
	if e == nil {
		return User{}
	}

	return User{
		ID:          e.Id,
		Email:       e.Email,
		DisplayName: e.DisplayName,
		Self:        e.Self,
	}
}

func newUserFromOrganizer(e *SDK.EventOrganizer) User {
	if e == nil {
		return User{}
	}

	return User{
		ID:          e.Id,
		Email:       e.Email,
		DisplayName: e.DisplayName,
		Self:        e.Self,
	}
}

type EventSource struct {
	Title string
	URL   string
}

func newEventSource(s *SDK.EventSource) EventSource {
	if s == nil {
		return EventSource{}
	}

	return EventSource{
		Title: s.Title,
		URL:   s.Url,
	}
}

type EventReminders struct {
	Overrides  []EventReminder
	UseDefault bool
}

func newEventReminders(r *SDK.EventReminders) EventReminders {
	if r == nil {
		return EventReminders{}
	}
	return EventReminders{
		Overrides:  newEventReminderList(r.Overrides),
		UseDefault: r.UseDefault,
	}
}

type EventReminder struct {
	Method  string
	Minutes int64
}

func newEventReminderList(list []*SDK.EventReminder) []EventReminder {
	result := make([]EventReminder, len(list))
	for i, e := range list {
		result[i] = newEventReminder(e)
	}
	return result
}

func newEventReminder(e *SDK.EventReminder) EventReminder {
	return EventReminder{
		Method:  e.Method,
		Minutes: e.Minutes,
	}
}

type CalendarListResponse struct {
	*SDK.CalendarList
}

// CalendarList contains multiple calendars.
type CalendarList struct {
	List          []CalendarEntry
	ETag          string
	Kind          string
	NextPageToken string
	NextSyncToken string
}

// CalendarEntry contains calendar information on Google Calendar.
type CalendarEntry struct {
	ID              string
	ETag            string
	Summary         string
	SummaryOverride string
	Description     string
	Kind            string
	Location        string

	AccessRole      string
	BackgroundColor string
	ColorID         string
	ForegroundColor string
	TimeZone        string

	Primary  bool
	Selected bool
	Deleted  bool
	Hidden   bool

	DefaultReminders     []EventReminder
	ConferenceProperties ConferenceProperties
	NotificationSettings NotificationSettings
}

func NewCalendarEntries(list []*SDK.CalendarListEntry) []CalendarEntry {
	results := make([]CalendarEntry, len(list))
	for i, e := range list {
		results[i] = NewCalendarEntry(e)
	}
	return results
}

func NewCalendarEntry(e *SDK.CalendarListEntry) CalendarEntry {
	return CalendarEntry{
		ID:              e.Id,
		ETag:            e.Etag,
		Summary:         e.Summary,
		SummaryOverride: e.SummaryOverride,
		Description:     e.Description,
		Kind:            e.Kind,
		Location:        e.Location,

		AccessRole:      e.AccessRole,
		ColorID:         e.ColorId,
		BackgroundColor: e.BackgroundColor,
		ForegroundColor: e.ForegroundColor,
		TimeZone:        e.TimeZone,

		Primary:  e.Primary,
		Selected: e.Selected,
		Deleted:  e.Deleted,
		Hidden:   e.Hidden,

		DefaultReminders:     newEventReminderList(e.DefaultReminders),
		ConferenceProperties: newConferenceProperties(e.ConferenceProperties),
		NotificationSettings: newNotificationSettings(e.NotificationSettings),
	}
}

type ConferenceProperties struct {
	AllowedConferenceSolutionTypes []string
}

func newConferenceProperties(s *SDK.ConferenceProperties) ConferenceProperties {
	if s == nil {
		return ConferenceProperties{}
	}

	list := make([]string, len(s.AllowedConferenceSolutionTypes))
	for i, t := range s.AllowedConferenceSolutionTypes {
		list[i] = t
	}
	return ConferenceProperties{
		AllowedConferenceSolutionTypes: list,
	}
}

type NotificationSettings struct {
	Notifications []CalendarNotification
}

func newNotificationSettings(s *SDK.CalendarListEntryNotificationSettings) NotificationSettings {
	if s == nil {
		return NotificationSettings{}
	}

	list := make([]CalendarNotification, len(s.Notifications))
	for i, n := range s.Notifications {
		list[i] = newCalendarNotification(n)
	}
	return NotificationSettings{
		Notifications: list,
	}
}

type CalendarNotification struct {
	Method string
	Type   string
}

func newCalendarNotification(n *SDK.CalendarNotification) CalendarNotification {
	return CalendarNotification{
		Method: n.Method,
		Type:   n.Type,
	}
}


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

  <title>Description of extract_numeric</title>
  <meta name="keywords" content="extract_numeric">
  <meta name="description" content="">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 © 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../../../../../m2html.css">

Home >  .. > SMASHtoolbox > +SMASH > +FileAccess > @SDAfile > private > extract_numeric.m

extract_numeric

PURPOSE

SYNOPSIS

function data=extract_numeric(archive,setname)

DESCRIPTION

CROSS-REFERENCE INFORMATION

This function calls:

readAttribute	readAttribute Read HDF5 attribute

This function is called by:

extract_cell

extract_structure

SOURCE CODE

0001 function data=extract_numeric(archive,setname)
0002
0003 file=archive.ArchiveFile;
0004 empty=readAttribute(file,setname,'Empty');
0005 if strcmp(empty,'yes')
0006     empty=true;
0007 else
0008     empty=false;
0009 end
0010
0011 if empty
0012     data=[];
0013 else
0014     data=h5read(file,setname);
0015 end
0016
0017 try
0018     value=readAttribute(file,setname,'Sparse');
0019 catch
0020     value='no';
0021 end
0022 if strcmpi(value,'yes')
0023     data=sparse(data(:,1),data(:,2),data(:,3));
0024 end
0025
0026 try
0027     value=readAttribute(file,setname,'Complex');
0028 catch
0029     value='no';
0030 end
0031 if strcmpi(value,'yes')
0032     data=data(:,1)+1i*data(:,2);
0033     ArraySize=readAttribute(file,setname,'ArraySize');
0034     ArraySize=reshape(ArraySize,[1 numel(ArraySize)]);
0035     data=reshape(data,ArraySize);
0036 end
0037
0038 end

<address>Generated on Tue 10-Nov-2020 17:53:50 by m2html © 2005</address>


text:
this is second
this is a readme
hahhahaha
88888
9999999


text:
/**
 * @unrestricted
 */
TextEditor.CodeMirrorUtils = class extends UI.InplaceEditor {
  constructor() {
    super();
  }

  /**
   * @param {!Common.TextRange} range
   * @return {!{start: !CodeMirror.Pos, end: !CodeMirror.Pos}}
   */
  static toPos(range) {
    return {
      start: new CodeMirror.Pos(range.startLine, range.startColumn),
      end: new CodeMirror.Pos(range.endLine, range.endColumn)
    };
  }

  /**
   * @param {!CodeMirror.Pos} start
   * @param {!CodeMirror.Pos} end
   * @return {!Common.TextRange}
   */
  static toRange(start, end) {
    return new Common.TextRange(start.line, start.ch, end.line, end.ch);
  }

  /**
   * @param {!CodeMirror.ChangeObject} changeObject
   * @return {{oldRange: !Common.TextRange, newRange: !Common.TextRange}}
   */
  static changeObjectToEditOperation(changeObject) {
    var oldRange = TextEditor.CodeMirrorUtils.toRange(changeObject.from, changeObject.to);
    var newRange = oldRange.clone();
    var linesAdded = changeObject.text.length;
    if (linesAdded === 0) {
      newRange.endLine = newRange.startLine;
      newRange.endColumn = newRange.startColumn;
    } else if (linesAdded === 1) {
      newRange.endLine = newRange.startLine;
      newRange.endColumn = newRange.startColumn + changeObject.text[0].length;
    } else {
      newRange.endLine = newRange.startLine + linesAdded - 1;
      newRange.endColumn = changeObject.text[linesAdded - 1].length;
    }
    return {oldRange: oldRange, newRange: newRange};
  }

  /**
   * @param {!CodeMirror} codeMirror
   * @param {number} linesCount
   * @return {!Array.<string>}
   */
  static pullLines(codeMirror, linesCount) {
    var lines = [];
    codeMirror.eachLine(0, linesCount, onLineHandle);
    return lines;

    /**
     * @param {!{text: string}} lineHandle
     */
    function onLineHandle(lineHandle) {
      lines.push(lineHandle.text);
    }
  }

  /**
   * @param {!Element} element
   */
  static appendThemeStyle(element) {
    if (UI.themeSupport.hasTheme())
      return;
    var backgroundColor = InspectorFrontendHost.getSelectionBackgroundColor();
    var backgroundColorRule =
        backgroundColor ? '.CodeMirror .CodeMirror-selected { background-color: ' + backgroundColor + ';}' : '';
    var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
    var foregroundColorRule = foregroundColor ?
        '.CodeMirror .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) { color: ' + foregroundColor +
            '!important;}' :
        '';
    var style = createElement('style');
    if (foregroundColorRule || backgroundColorRule)
      style.textContent = backgroundColorRule + foregroundColorRule;
    element.appendChild(style);
  }

  /**
   * @override
   * @return {string}
   */
  editorContent(editingContext) {
    return editingContext.codeMirror.getValue();
  }

  /**
   * @param {!Event} e
   */
  _consumeCopy(e) {
    e.consume();
  }

  /**
   * @override
   */
  setUpEditor(editingContext) {
    var element = editingContext.element;
    var config = editingContext.config;
    editingContext.cssLoadView = new TextEditor.CodeMirrorCSSLoadView();
    editingContext.cssLoadView.show(element);
    element.focus();
    element.addEventListener('copy', this._consumeCopy, false);
    var codeMirror = new window.CodeMirror(element, {
      mode: config.mode,
      lineWrapping: config.lineWrapping,
      lineWiseCopyCut: false,
      smartIndent: config.smartIndent,
      autofocus: true,
      theme: config.theme,
      value: config.initialValue
    });
    codeMirror.getWrapperElement().classList.add('source-code');
    codeMirror.on('cursorActivity', function(cm) {
      cm.display.cursorDiv.scrollIntoViewIfNeeded(false);
    });
    editingContext.codeMirror = codeMirror;
  }

  /**
   * @override
   */
  closeEditor(editingContext) {
    editingContext.element.removeEventListener('copy', this._consumeCopy, false);
    editingContext.cssLoadView.detach();
  }

  /**
   * @override
   */
  cancelEditing(editingContext) {
    editingContext.codeMirror.setValue(editingContext.oldText);
  }

  /**
   * @override
   */
  augmentEditingHandle(editingContext, handle) {
    function setWidth(editingContext, width) {
      var padding = 30;
      var codeMirror = editingContext.codeMirror;
      codeMirror.getWrapperElement().style.width = (width - codeMirror.getWrapperElement().offsetLeft - padding) + 'px';
      codeMirror.refresh();
    }

    handle.codeMirror = editingContext.codeMirror;
    handle.setWidth = setWidth.bind(null, editingContext);
  }
};

/**
 * @implements {Common.TokenizerFactory}
 * @unrestricted
 */
TextEditor.CodeMirrorUtils.TokenizerFactory = class {
  /**
   * @override
   * @param {string} mimeType
   * @return {function(string, function(string, ?string, number, number))}
   */
  createTokenizer(mimeType) {
    var mode = CodeMirror.getMode({indentUnit: 2}, mimeType);
    var state = CodeMirror.startState(mode);
    function tokenize(line, callback) {
      var stream = new CodeMirror.StringStream(line);
      while (!stream.eol()) {
        var style = mode.token(stream, state);
        var value = stream.current();
        callback(value, style, stream.start, stream.start + value.length);
        stream.start = stream.pos;
      }
    }
    return tokenize;
  }
};

/**
 * @unrestricted
 */
TextEditor.CodeMirrorCSSLoadView = class extends UI.VBox {
  /**
   * This bogus view is needed to load/unload CodeMirror-related CSS on demand.
   */
  constructor() {
    super();
    this.element.classList.add('hidden');
    this.registerRequiredCSS('cm/codemirror.css');
    this.registerRequiredCSS('text_editor/cmdevtools.css');
    TextEditor.CodeMirrorUtils.appendThemeStyle(this.element);
  }
};


text:
#pragma once

#if ENABLE(DFG_JIT)

#include "JITCode.h"
#include "MacroAssemblerCodeRef.h"
#include <wtf/FastMalloc.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>

namespace JSC { namespace DFG {

struct Plan;

class Finalizer {
    WTF_MAKE_NONCOPYABLE(Finalizer); WTF_MAKE_FAST_ALLOCATED;
public:
    Finalizer(Plan&);
    virtual ~Finalizer();

    virtual size_t codeSize() = 0;
    virtual bool finalize() = 0;
    virtual bool finalizeFunction() = 0;

protected:
    Plan& m_plan;
};

} } // namespace JSC::DFG

#endif // ENABLE(DFG_JIT)


text:
/*
 * Do not modify this file. This file is generated from the storagegateway-2013-06-30.normal.json service model.
 */
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using System.IO;

using Amazon.Runtime;
using Amazon.Runtime.Internal;

namespace Amazon.StorageGateway.Model
{
    ///
    /// Container for the parameters to the UpdateGatewaySoftwareNow operation.
    /// This operation updates the gateway virtual machine (VM) software. The request immediately
    /// triggers the software update.
    ///
    ///  <note>When you make this request, you get a 200 OK success response
    /// immediately. However, it might take some time for the update to complete. You can
    /// call DescribeGatewayInformation to verify the gateway is in the STATE_RUNNING
    /// state.</note> <important>A software update forces a system restart of your gateway.
    /// You can minimize the chance of any disruption to your applications by increasing your
    /// iSCSI Initiators' timeouts. For more information about increasing iSCSI Initiator
    /// timeouts for Windows and Linux, see Customizing
    /// Your Windows iSCSI Settings and Customizing
    /// Your Linux iSCSI Settings, respectively.</important>
    ///
    public partial class UpdateGatewaySoftwareNowRequest : AmazonStorageGatewayRequest
    {
        private string _gatewayARN;

        ///
        /// Gets and sets the property GatewayARN.
        ///
        public string GatewayARN
        {
            get { return this._gatewayARN; }
            set { this._gatewayARN = value; }
        }

        // Check to see if GatewayARN property is set
        internal bool IsSetGatewayARN()
        {
            return this._gatewayARN != null;
        }

    }
}


text:
/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { ConversationService } from './conversation.service';

describe('Service: Conversation', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [ConversationService]
    });
  });

  it('should ...', inject([ConversationService], (service: ConversationService) => {
    expect(service).toBeTruthy();
  }));
});


text:
/* gs16spl.c */
/* 16-bit access to print spooler from Win32s */
/* by Russell Lang */
/* 1995-11-23 */

/*
 * Ghostscript produces printer specific output
 * which must be given to the print spooler.
 * Under Win16, the APIs OpenJob, WriteSpool etc. are used
 * Under Win32 and Windows 95/NT, the APIs OpenPrinter, WritePrinter etc.
 * are used.
 * Under Win32s, the 16-bit spooler APIs are not available, and the
 * 32-bit spooler APIs are not implemented.
 * This purpose of this application is to provide a means for the Win32s
 * version of Ghostscript to send output to the 16-bit spooler.
 */

/*
 * Usage:  gs16spl port filename
 *
 * filename will be sent to the spooler port.
 */

#define STRICT
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ID_TEXT 100

/* documented in Device Driver Adaptation Guide */
/* Prototypes taken from print.h */
DECLARE_HANDLE(HPJOB);

HPJOB   WINAPI OpenJob(LPSTR, LPSTR, HPJOB);
int     WINAPI StartSpoolPage(HPJOB);
int     WINAPI EndSpoolPage(HPJOB);
int     WINAPI WriteSpool(HPJOB, LPSTR, int);
int     WINAPI CloseJob(HPJOB);
int     WINAPI DeleteJob(HPJOB, int);
int     WINAPI WriteDialog(HPJOB, LPSTR, int);
int     WINAPI DeleteSpoolPage(HPJOB);

#define MAXSTR 256
#define PRINT_BUF_SIZE 16384

HPJOB hJob;
HWND hwndspl;
DLGPROC lpfnSpoolProc;
HINSTANCE phInstance;
char port[MAXSTR];
char filename[MAXSTR];
char error_message[MAXSTR];
int error;

char szAppName[] = "GS Win32s/Win16 spooler";

/* returns TRUE on success, FALSE on failure */
int
spoolfile(char *portname, char *filename)
{
FILE *f;
char *buffer;
char pcdone[64];
long ldone;
long lsize;
int count;
MSG msg;
	if ( (*portname == '\0') || (*filename == '\0') ) {
	    strcpy(error_message, "Usage: gs16spl port filename");
	    return FALSE;
	}

	if ((buffer = malloc(PRINT_BUF_SIZE)) == (char *)NULL)
	    return FALSE;

	if ((f = fopen(filename, "rb")) == (FILE *)NULL) {
	    sprintf(error_message, "Can't open %s", filename);
	    free(buffer);
	    return FALSE;
	}
	fseek(f, 0L, SEEK_END);
	lsize = ftell(f);
	if (lsize <= 0)
	    lsize = 1;
	fseek(f, 0L, SEEK_SET);
	ldone = 0;

	hJob = OpenJob(portname, filename, (HDC)NULL);
	switch ((int)hJob) {
	    case SP_APPABORT:
	    case SP_ERROR:
	    case SP_OUTOFDISK:
	    case SP_OUTOFMEMORY:
	    case SP_USERABORT:
		fclose(f);
		free(buffer);
		return FALSE;
	}
	if (StartSpoolPage(hJob) < 0)
	    error = TRUE;

	while (!error
	  && (count = fread(buffer, 1, PRINT_BUF_SIZE, f)) != 0 ) {
	    if (WriteSpool(hJob, buffer, count) < 0)
		error = TRUE;
	    ldone += count;
	    sprintf(pcdone, "%d%% written to %s", (int)(ldone * 100 / lsize), portname);
	    SetWindowText(GetDlgItem(hwndspl, ID_TEXT), pcdone);
	    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
  	    }
  	}
	free(buffer);
	fclose(f);

	EndSpoolPage(hJob);
	if (error)
	    DeleteJob(hJob, 0);
	else
	    CloseJob(hJob);
	return !error;
}

/* Modeless dialog box - main window */
BOOL CALLBACK _export
SpoolDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message) {
	case WM_INITDIALOG:
	    SetWindowText(hDlg, szAppName);
	    return TRUE;
	case WM_COMMAND:
	    switch(LOWORD(wParam)) {
		case IDCANCEL:
		    error = TRUE;
		    DestroyWindow(hDlg);
		    EndDialog(hDlg, 0);
		    PostQuitMessage(0);
		    return TRUE;
	    }
    }
    return FALSE;
}

void
init_window(LPSTR cmdline)
{
    LPSTR s;
    char *d;
    s = cmdline;
    /* skip leading spaces */
    while (*s && *s==' ')
	s++;
    /* copy port name */
    d = port;
    while (*s && *s!=' ')
	*d++ = *s++;
    *d='\0';
    /* skip spaces */
    while (*s && *s==' ')
	s++;
    /* copy port name */
    d = filename;
    while (*s && *s!=' ')
	*d++ = *s++;
    *d='\0';

    lpfnSpoolProc = (DLGPROC)MakeProcInstance((FARPROC)SpoolDlgProc, phInstance);
    hwndspl = CreateDialog(phInstance, "SpoolDlgBox", HWND_DESKTOP, lpfnSpoolProc);

    return;
}

int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
	MSG msg;
	phInstance = hInstance;

	init_window(lpszCmdLine);
	ShowWindow(hwndspl, cmdShow);

	if (!spoolfile(port, filename)) {
	    /* wait, showing error message */
	    SetWindowText(GetDlgItem(hwndspl, ID_TEXT), error_message);
	    while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
		    TranslateMessage(&msg);
		    DispatchMessage(&msg);
	    }
	}

	DestroyWindow(hwndspl);
	FreeProcInstance((FARPROC)lpfnSpoolProc);
	return 0;
}


text:
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.entities.MCHanging;
import com.laytonsmith.abstraction.enums.MCRemoveCause;
import com.laytonsmith.core.events.BindableEvent;

public interface MCHangingBreakEvent extends BindableEvent {

	MCHanging getEntity();

	MCRemoveCause getCause();

	MCEntity getRemover();
}


text:
#include <aws/eks/model/AMITypes.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/core/Globals.h>
#include <aws/core/utils/EnumParseOverflowContainer.h>

using namespace Aws::Utils;

namespace Aws
{
  namespace EKS
  {
    namespace Model
    {
      namespace AMITypesMapper
      {

        static const int AL2_x86_64_HASH = HashingUtils::HashString("AL2_x86_64");
        static const int AL2_x86_64_GPU_HASH = HashingUtils::HashString("AL2_x86_64_GPU");
        static const int AL2_ARM_64_HASH = HashingUtils::HashString("AL2_ARM_64");
        static const int CUSTOM_HASH = HashingUtils::HashString("CUSTOM");
        static const int BOTTLEROCKET_ARM_64_HASH = HashingUtils::HashString("BOTTLEROCKET_ARM_64");
        static const int BOTTLEROCKET_x86_64_HASH = HashingUtils::HashString("BOTTLEROCKET_x86_64");
        static const int BOTTLEROCKET_ARM_64_NVIDIA_HASH = HashingUtils::HashString("BOTTLEROCKET_ARM_64_NVIDIA");
        static const int BOTTLEROCKET_x86_64_NVIDIA_HASH = HashingUtils::HashString("BOTTLEROCKET_x86_64_NVIDIA");

        AMITypes GetAMITypesForName(const Aws::String& name)
        {
          int hashCode = HashingUtils::HashString(name.c_str());
          if (hashCode == AL2_x86_64_HASH)
          {
            return AMITypes::AL2_x86_64;
          }
          else if (hashCode == AL2_x86_64_GPU_HASH)
          {
            return AMITypes::AL2_x86_64_GPU;
          }
          else if (hashCode == AL2_ARM_64_HASH)
          {
            return AMITypes::AL2_ARM_64;
          }
          else if (hashCode == CUSTOM_HASH)
          {
            return AMITypes::CUSTOM;
          }
          else if (hashCode == BOTTLEROCKET_ARM_64_HASH)
          {
            return AMITypes::BOTTLEROCKET_ARM_64;
          }
          else if (hashCode == BOTTLEROCKET_x86_64_HASH)
          {
            return AMITypes::BOTTLEROCKET_x86_64;
          }
          else if (hashCode == BOTTLEROCKET_ARM_64_NVIDIA_HASH)
          {
            return AMITypes::BOTTLEROCKET_ARM_64_NVIDIA;
          }
          else if (hashCode == BOTTLEROCKET_x86_64_NVIDIA_HASH)
          {
            return AMITypes::BOTTLEROCKET_x86_64_NVIDIA;
          }
          EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
          if(overflowContainer)
          {
            overflowContainer->StoreOverflow(hashCode, name);
            return static_cast<AMITypes>(hashCode);
          }

          return AMITypes::NOT_SET;
        }

        Aws::String GetNameForAMITypes(AMITypes enumValue)
        {
          switch(enumValue)
          {
          case AMITypes::AL2_x86_64:
            return "AL2_x86_64";
          case AMITypes::AL2_x86_64_GPU:
            return "AL2_x86_64_GPU";
          case AMITypes::AL2_ARM_64:
            return "AL2_ARM_64";
          case AMITypes::CUSTOM:
            return "CUSTOM";
          case AMITypes::BOTTLEROCKET_ARM_64:
            return "BOTTLEROCKET_ARM_64";
          case AMITypes::BOTTLEROCKET_x86_64:
            return "BOTTLEROCKET_x86_64";
          case AMITypes::BOTTLEROCKET_ARM_64_NVIDIA:
            return "BOTTLEROCKET_ARM_64_NVIDIA";
          case AMITypes::BOTTLEROCKET_x86_64_NVIDIA:
            return "BOTTLEROCKET_x86_64_NVIDIA";
          default:
            EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
            if(overflowContainer)
            {
              return overflowContainer->RetrieveOverflow(static_cast<int>(enumValue));
            }

            return {};
          }
        }

      } // namespace AMITypesMapper
    } // namespace Model
  } // namespace EKS
} // namespace Aws


text:
// Copyright 2017 The Oppia Authors. All Rights Reserved.
//
// 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.

/**
 * @fileoverview Directive for the FractionInput interaction.
 */

require('domain/objects/FractionObjectFactory.ts');
require(
  'interactions/FractionInput/directives/' +
  'fraction-input-rules.service.ts');
require(
  'pages/exploration-player-page/services/current-interaction.service.ts');
require(
  'interactions/interaction-attributes-extractor.service.ts');

require('domain/objects/objects-domain.constants.ajs.ts');

angular.module('oppia').directive('oppiaInteractiveFractionInput', [
  'InteractionAttributesExtractorService',
  function(InteractionAttributesExtractorService) {
    return {
      restrict: 'E',
      scope: {},
      bindToController: {},
      template: require('./fraction-input-interaction.directive.html'),
      controllerAs: '$ctrl',
      controller: [
        '$attrs', '$scope', 'CurrentInteractionService',
        'FractionInputRulesService', 'FractionObjectFactory',
        'FRACTION_PARSING_ERRORS',
        function(
            $attrs, $scope, CurrentInteractionService,
            FractionInputRulesService, FractionObjectFactory,
            FRACTION_PARSING_ERRORS) {
          var ctrl = this;
          // Label for errors caused whilst parsing a fraction.
          var FORM_ERROR_TYPE = 'FRACTION_FORMAT_ERROR';
          var errorMessage = '';
          const {
            requireSimplestForm,
            allowImproperFraction
          } = InteractionAttributesExtractorService.getValuesFromAttributes(
            'FractionInput',
            $attrs
          );

          ctrl.getWarningText = function() {
            return errorMessage;
          };

          ctrl.submitAnswer = function(answer) {
            try {
              var fraction = FractionObjectFactory.fromRawInputString(
                answer);
              if (requireSimplestForm &&
                !angular.equals(fraction, fraction.convertToSimplestForm())
              ) {
                errorMessage = (
                  'Please enter an answer in simplest form ' +
                  '(e.g., 1/3 instead of 2/6).');
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else if (
                !allowImproperFraction && fraction.isImproperFraction()) {
                errorMessage = (
                  'Please enter an answer with a "proper" fractional part ' +
                  '(e.g., 1 2/3 instead of 5/3).');
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else if (
                !ctrl.allowNonzeroIntegerPart &&
                  fraction.hasNonzeroIntegerPart()) {
                errorMessage = (
                  'Please enter your answer as a fraction (e.g., 5/3 instead ' +
                  'of 1 2/3).');
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else {
                CurrentInteractionService.onSubmit(
                  fraction, FractionInputRulesService);
              }
            } catch (parsingError) {
              errorMessage = parsingError.message;
              ctrl.FractionInputForm.answer.$setValidity(
                FORM_ERROR_TYPE, false);
            }
          };

          ctrl.isAnswerValid = function() {
            if (ctrl.FractionInputForm === undefined) {
              return false;
            }
            return (!ctrl.FractionInputForm.$invalid && ctrl.answer !== '');
          };

          var submitAnswerFn = function() {
            ctrl.submitAnswer(ctrl.answer);
          };
          ctrl.$onInit = function() {
            /**
             * Disables the input box if the data entered is not a valid prefix
             * for a fraction.
             * Examples of valid prefixes:
             * -- 1
             * -- 1 2
             * -- 1 2/
             * -- 2/
             * -- 1 2/3
             */
            $scope.$watch('$ctrl.answer', function(newValue) {
              var INVALID_CHARS_REGEX = /[^\d\s\/-]/g;
              var INVALID_CHARS_LENGTH_REGEX = /\d{8,}/;
              // Accepts incomplete fraction inputs
              // (see examples above except last).
              var PARTIAL_FRACTION_REGEX =
                /^\s*(-?\s*((\d*\s*\d+\s*\/?\s*)|\d+)\s*)?$/;
              // Accepts complete fraction inputs.
              var FRACTION_REGEX =
                /^\s*-?\s*((\d*\s*\d+\s*\/\s*\d+)|\d+)\s*$/;
              if (INVALID_CHARS_LENGTH_REGEX.test(newValue)) {
                errorMessage = FRACTION_PARSING_ERRORS.INVALID_CHARS_LENGTH;
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else if (INVALID_CHARS_REGEX.test(newValue)) {
                errorMessage = FRACTION_PARSING_ERRORS.INVALID_CHARS;
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else if (!(FRACTION_REGEX.test(newValue) ||
                  PARTIAL_FRACTION_REGEX.test(newValue))) {
                errorMessage = FRACTION_PARSING_ERRORS.INVALID_FORMAT;
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, false);
              } else {
                errorMessage = '';
                ctrl.FractionInputForm.answer.$setValidity(
                  FORM_ERROR_TYPE, true);
              }
            });
            ctrl.answer = '';
            ctrl.labelForFocusTarget = $attrs.labelForFocusTarget || null;
            const {
              allowNonzeroIntegerPart,
              customPlaceholder
            } = InteractionAttributesExtractorService.getValuesFromAttributes(
              'FractionInput',
              $attrs
            );
            ctrl.allowNonzeroIntegerPart = allowNonzeroIntegerPart;
            ctrl.customPlaceholder = customPlaceholder.getUnicode();

            ctrl.FRACTION_INPUT_FORM_SCHEMA = {
              type: 'unicode',
              ui_config: {}
            };

            CurrentInteractionService.registerCurrentInteraction(
              submitAnswerFn, ctrl.isAnswerValid);
          };
        }
      ]
    };
  }
]);


text:
import React, { Component } from 'react';
import { Navbar, Nav, NavItem } from 'react-bootstrap';
import PropTypes from 'prop-types';

export default class NavBar extends Component {

  static contextTypes = {
    router: PropTypes.object
  }

  handleLogout = () => this.props.logout(this.context.router);

  render() {
    const { isAuthenticated } =  this.props;
    const token = localStorage.getItem('token');

    return (

        <Navbar inverse>
          <Navbar.Header>
            <Navbar.Brand>
              Online Notebook App
            </Navbar.Brand>
            <Navbar.Toggle />
          </Navbar.Header>
          <Navbar.Collapse>
            {
              (isAuthenticated && !!token) ?

                  <NavItem eventKey={1} href="/">Home</NavItem>
                  <NavItem eventKey={2} href="/dashboard">Dashboard</NavItem>
                  <NavItem eventKey={3} href="/notes/new">Create a New Note</NavItem>
                  <NavItem eventKey={4} onClick={this.handleLogout}>Log Out</NavItem>

                :

                  <NavItem eventKey={1} href="/">Home</NavItem>
                  <NavItem eventKey={2} href="/login">Login</NavItem>
                  <NavItem eventKey={3} href="/signup">Signup</NavItem>

            }
          </Navbar.Collapse>
        </Navbar>

    )
  }
}

NavBar.propTypes = {
  isAuthenticated: PropTypes.bool.isRequired,
  logout: PropTypes.func
};


text:
package org.apache.pig.backend.hadoop.executionengine.util;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.ColumnChainInfo;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.ColumnInfo;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.SortKeyInfo;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PORelationToExprProject;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.JoinPackager;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.PODistinct;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POGlobalRearrange;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLimit;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackage;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POSort;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POSortedDistinct;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POUnion;
import org.apache.pig.backend.hadoop.executionengine.spark.operator.POGlobalRearrangeSpark;
import org.apache.pig.backend.hadoop.executionengine.spark.operator.POReduceBySpark;
import org.apache.pig.classification.InterfaceAudience;
import org.apache.pig.data.DataType;
import org.apache.pig.impl.io.PigNullableWritable;
import org.apache.pig.impl.logicalLayer.FrontendException;
import org.apache.pig.impl.plan.NodeIdGenerator;
import org.apache.pig.impl.plan.OperatorKey;
import org.apache.pig.impl.plan.PlanException;
import org.apache.pig.impl.plan.VisitorException;

@InterfaceAudience.Public
public class SecondaryKeyOptimizerUtil {
    private static Log log = LogFactory.getLog(SecondaryKeyOptimizerUtil.class.getName());
    private static boolean isSparkMode;

    public SecondaryKeyOptimizerUtil() {

    }

    private static class POToChange {
        POToChange(PhysicalOperator oper, PhysicalPlan plan, POForEach forEach) {
            this.oper = oper;
            this.plan = plan;
            this.forEach = forEach;
        }

        PhysicalOperator oper;

        PhysicalPlan plan;

        POForEach forEach;
    }

    public static class SecondaryKeyOptimizerInfo {

        private int numSortRemoved = 0;
        private int numDistinctChanged = 0;
        private int numUseSecondaryKey = 0;
        private boolean useSecondaryKey = false;
        private boolean[] secondarySortOrder;

        public int getNumSortRemoved() {
            return numSortRemoved;
        }

        public void incrementNumSortRemoved() {
            this.numSortRemoved++;
        }

        public int getNumDistinctChanged() {
            return numDistinctChanged;
        }

        public void incrementNumDistinctChanged() {
            this.numDistinctChanged++;
        }

        public int getNumUseSecondaryKey() {
            return numUseSecondaryKey;
        }

        public void incrementNumUseSecondaryKey() {
            this.numUseSecondaryKey++;
        }

        public boolean isUseSecondaryKey() {
            return useSecondaryKey;
        }

        public void setUseSecondaryKey(boolean useSecondaryKey) {
            this.useSecondaryKey = useSecondaryKey;
        }

        public boolean[] getSecondarySortOrder() {
            return secondarySortOrder;
        }

        public void setSecondarySortOrder(boolean[] secondarySortOrder) {
            this.secondarySortOrder = secondarySortOrder;
        }

    }

    // Build sort key structure from POLocalRearrange
    private static SortKeyInfo getSortKeyInfo(POLocalRearrange rearrange) throws ExecException {
        SortKeyInfo result = new SortKeyInfo();
        List<PhysicalPlan> plans = rearrange.getPlans();
        nextPlan: for (int i = 0; i < plans.size(); i++) {
            PhysicalPlan plan = plans.get(i);
            ColumnChainInfo columnChainInfo = new ColumnChainInfo();
            if (plan.getRoots() == null) {
                log.debug("POLocalRearrange plan is null");
                return null;
            } else if (plan.getRoots().size() != 1) {
                // POLocalRearrange plan contains more than 1 root.
                // Probably there is an Expression operator in the local
                // rearrangement plan, skip this plan
                continue nextPlan;
            } else {
                List<Integer> columns = new ArrayList<Integer>();
                columns
                        .add(rearrange.getIndex()
                                & PigNullableWritable.idxSpace);

                // The first item inside columnChainInfo is set to type Tuple.
                // This value is not actually in use, but it intends to match
                // the type of POProject in reduce side
                columnChainInfo.insert(columns, DataType.TUPLE);

                PhysicalOperator node = plan.getRoots().get(0);
                while (node != null) {
                    if (node instanceof POProject) {
                        POProject project = (POProject) node;
                        if(project.isProjectToEnd()){
                            columnChainInfo.insert(project.getStartCol(),
                                    project.getResultType());
                        }else {
                            columnChainInfo.insert(
                                    project.getColumns(), project.getResultType());
                        }

                        if (plan.getSuccessors(node) == null)
                            node = null;
                        else if (plan.getSuccessors(node).size() != 1) {
                            log.debug(node + " have more than 1 successor");
                            node = null;
                        } else
                            node = plan.getSuccessors(node).get(0);
                    } else
                        // constant, UDF, we will pass
                        continue nextPlan;
                }
            }
            // Let's assume all main key is sorted ascendant, we can further
            // optimize it to match one of the nested sort/distinct key, because we do not
            // really care about how cogroup key are sorted; But it may not be the case
            // if sometime we switch all the comparator to byte comparator, so just
            // leave it as it is for now
            result.insertColumnChainInfo(i, columnChainInfo, true);
        }
        return result;
    }

    public SecondaryKeyOptimizerInfo applySecondaryKeySort(PhysicalPlan mapPlan, PhysicalPlan reducePlan) throws VisitorException {
        log.trace("Entering SecondaryKeyOptimizerUtil.addSecondaryKeySort");
        SecondaryKeyOptimizerInfo secKeyOptimizerInfo = new SecondaryKeyOptimizerInfo();
        List<SortKeyInfo> sortKeyInfos = new ArrayList<SortKeyInfo>();
        SortKeyInfo secondarySortKeyInfo = null;
        List<POToChange> sortsToRemove = null;
        List<POToChange> distinctsToChange = null;

        List<PhysicalOperator> mapLeaves = mapPlan.getLeaves();
        if (mapLeaves == null || mapLeaves.size() != 1) {
            log.debug("Expected map to have single leaf! Skip secondary key optimizing");
            return null;
        }
        PhysicalOperator mapLeaf = mapLeaves.get(0);

        // Figure out the main key of the map-reduce job from POLocalRearrange
        try {
            if (mapLeaf instanceof POLocalRearrange) {
                SortKeyInfo sortKeyInfo = getSortKeyInfo((POLocalRearrange) mapLeaf);
                if (sortKeyInfo == null) {
                    log.debug("Cannot get sortKeyInfo from POLocalRearrange, skip secondary key optimizing");
                    return null;
                }
                sortKeyInfos.add(sortKeyInfo);
            } else if (mapLeaf instanceof POUnion) {
                List<PhysicalOperator> preds = mapPlan
                        .getPredecessors(mapLeaf);
                for (PhysicalOperator pred : preds) {
                    if (pred instanceof POLocalRearrange) {
                        SortKeyInfo sortKeyInfo = getSortKeyInfo((POLocalRearrange) pred);
                        if (sortKeyInfo == null) {
                            log.debug("Cannot get sortKeyInfo from POLocalRearrange, skip secondary key optimizing");
                            return null;
                        }
                        sortKeyInfos.add(sortKeyInfo);
                    }
                }
            } else {
                log.debug("Cannot find POLocalRearrange or POUnion in map leaf, skip secondary key optimizing");
                return null;
            }
        } catch (ExecException e) {
            log.debug("Cannot get sortKeyInfo from POLocalRearrange, skip secondary key optimizing");
            return null;
        }

        if (reducePlan.isEmpty()) {
            log.debug("Reduce plan is empty, skip secondary key optimizing");
            return null;
        }

        List<PhysicalOperator> reduceRoots = reducePlan.getRoots();
        if (reduceRoots.size() != 1) {
            log.debug("Expected reduce to have single root, skip secondary key optimizing");
            return null;
        }

        PhysicalOperator root = reduceRoots.get(0);
        PhysicalOperator currentNode = getCurrentNode(root,reducePlan);

        // visit the POForEach of the reduce plan. We can have Limit and Filter
        // in the middle

        POForEach foreach = null;
        while (currentNode != null) {
            if (currentNode instanceof POPackage
                    && !(((POPackage) currentNode).getPkgr() instanceof JoinPackager)
                    || currentNode instanceof POFilter
                    || currentNode instanceof POLimit) {
                List<PhysicalOperator> succs = reducePlan
                        .getSuccessors(currentNode);
                if (succs == null) // We didn't find POForEach
                    return null;
                if (succs.size() != 1) {
                    log.debug("See multiple output for " + currentNode
                            + " in reduce plan, skip secondary key optimizing");
                    return null;
                }
                currentNode = succs.get(0);
            } else if (currentNode instanceof POForEach) {
                foreach = (POForEach) currentNode;
                break;
            } else { // Skip optimization
                return null;
            }
        }

        // We do not find a foreach (we shall not come here, a trick to fool findbugs)
        if (foreach==null)
            return null;

        sortsToRemove = new ArrayList<POToChange>();
        distinctsToChange = new ArrayList<POToChange>();

        for (PhysicalPlan innerPlan : foreach.getInputPlans()) {
            // visit inner plans to figure out the sort order for distinct /
            // sort
            SecondaryKeyDiscover innerPlanDiscover = new SecondaryKeyDiscover(
                    innerPlan, sortKeyInfos, secondarySortKeyInfo);
            try {
                innerPlanDiscover.process();
            } catch (FrontendException e) {
                int errorCode = 2213;
                throw new VisitorException("Error visiting inner plan for ForEach", errorCode, e);
            }
            secondarySortKeyInfo = innerPlanDiscover.getSecondarySortKeyInfo();
            if (innerPlanDiscover.getSortsToRemove() != null) {
                for (POSort sort : innerPlanDiscover.getSortsToRemove()) {
                    sortsToRemove.add(new POToChange(sort, innerPlan, foreach));
                }
            }
            if (innerPlanDiscover.getDistinctsToChange() != null) {
                for (PODistinct distinct : innerPlanDiscover
                        .getDistinctsToChange()) {
                    distinctsToChange.add(new POToChange(distinct, innerPlan,
                            foreach));
                }
            }
        }

        try {
            // Change PODistinct to use POSortedDistinct, which assume the input
            // data is sorted
            for (POToChange distinctToChange : distinctsToChange) {
                secKeyOptimizerInfo.incrementNumDistinctChanged();
                PODistinct oldDistinct = (PODistinct) distinctToChange.oper;
                String scope = oldDistinct.getOperatorKey().scope;
                POSortedDistinct newDistinct = new POSortedDistinct(
                        new OperatorKey(scope, NodeIdGenerator.getGenerator()
                                .getNextNodeId(scope)), oldDistinct
                                .getRequestedParallelism(), oldDistinct
                                .getInputs());
                newDistinct.setInputs(oldDistinct.getInputs());
                newDistinct.setResultType(oldDistinct.getResultType());
                distinctToChange.plan.replace(oldDistinct, newDistinct);
                distinctToChange.forEach.getLeaves();
            }
            // Removed POSort, if the successor require a databag, we need to
            // add a PORelationToExprProject
            // to convert tuples into databag
            for (POToChange sortToRemove : sortsToRemove) {
                secKeyOptimizerInfo.incrementNumSortRemoved();
                POSort oldSort = (POSort) sortToRemove.oper;
                String scope = oldSort.getOperatorKey().scope;
                List<PhysicalOperator> preds = sortToRemove.plan
                        .getPredecessors(sortToRemove.oper);
                List<PhysicalOperator> succs = sortToRemove.plan
                .getSuccessors(sortToRemove.oper);
                POProject project = null;
                if ((preds == null
                        || preds.get(0).getResultType() != DataType.BAG
                        && oldSort.getResultType() == DataType.BAG) // sort to remove do change the result type
                        && (succs == null || !(succs.get(0) instanceof PORelationToExprProject))) // successor is not PORelationToExprProject
                {
                    project = new PORelationToExprProject(new OperatorKey(
                            scope, NodeIdGenerator.getGenerator()
                                    .getNextNodeId(scope)), oldSort
                            .getRequestedParallelism());
                    project.setInputs(oldSort.getInputs());
                    project.setResultType(DataType.BAG);
                    project.setStar(true);
                }
                if (project == null)
                    sortToRemove.plan.removeAndReconnect(sortToRemove.oper);
                else
                    sortToRemove.plan.replace(oldSort, project);
                sortToRemove.forEach.getLeaves();
            }
        } catch (PlanException e) {
            int errorCode = 2202;
            throw new VisitorException(
                    "Error change distinct/sort to use secondary key optimizer",
                    errorCode, e);
        }
        if (secondarySortKeyInfo != null) {
            // Adjust POLocalRearrange, POPackage, MapReduceOper to use the
            // secondary key
            secKeyOptimizerInfo.incrementNumUseSecondaryKey();
            secKeyOptimizerInfo.setUseSecondaryKey(true);
            secKeyOptimizerInfo.setSecondarySortOrder(secondarySortKeyInfo.getAscs());
            int indexOfRearrangeToChange = -1;
            for (ColumnChainInfo columnChainInfo : secondarySortKeyInfo
                    .getColumnChains()) {
                ColumnInfo currentColumn = columnChainInfo.getColumnInfos()
                        .get(0);
                int index = currentColumn.getColumns().get(0);
                if (indexOfRearrangeToChange == -1)
                    indexOfRearrangeToChange = index;
                else if (indexOfRearrangeToChange != index) {
                    int errorCode = 2203;
                    throw new VisitorException("Sort on columns from different inputs.", errorCode);
                }
            }
            if (mapLeaf instanceof POLocalRearrange) {
                ((POLocalRearrange) mapLeaf).setUseSecondaryKey(true);
                setSecondaryPlan(mapPlan, (POLocalRearrange) mapLeaf,
                        secondarySortKeyInfo);
            } else if (mapLeaf instanceof POUnion) {
                List<PhysicalOperator> preds = mapPlan
                        .getPredecessors(mapLeaf);
                boolean found = false;
                for (PhysicalOperator pred : preds) {
                    POLocalRearrange rearrange = (POLocalRearrange) pred;
                    rearrange.setUseSecondaryKey(true);
                    if (rearrange.getIndex() == indexOfRearrangeToChange) {
                        // Try to find the POLocalRearrange for the secondary key
                        found = true;
                        setSecondaryPlan(mapPlan, rearrange, secondarySortKeyInfo);
                    }
                }
                if (!found)
                {
                    int errorCode = 2214;
                    throw new VisitorException("Cannot find POLocalRearrange to set secondary plan", errorCode);
                }
            }

            if (root instanceof POGlobalRearrangeSpark) {
                POGlobalRearrangeSpark plg = (POGlobalRearrangeSpark) root;
                plg.setUseSecondaryKey(true);
                plg.setSecondarySortOrder(secondarySortKeyInfo.getAscs());
            } else if (root instanceof POPackage) {
                POPackage pack = (POPackage) root;
                pack.getPkgr().setUseSecondaryKey(true);
            } else if (root instanceof POReduceBySpark) {
                POReduceBySpark reduceBySpark = (POReduceBySpark) root;
                reduceBySpark.setUseSecondaryKey(true);
                reduceBySpark.setSecondarySortOrder(secondarySortKeyInfo.getAscs());
            }
        }
        return secKeyOptimizerInfo;
    }

    protected PhysicalOperator getCurrentNode(PhysicalOperator root, PhysicalPlan reducePlan) {
        PhysicalOperator currentNode = null;
        if (!(root instanceof POPackage)) {
            log.debug("Expected reduce root to be a POPackage, skip secondary key optimizing");
        } else {
            currentNode = root;
        }
        return currentNode;
    }

    private static void setSecondaryPlan(PhysicalPlan plan, POLocalRearrange rearrange,
            SortKeyInfo secondarySortKeyInfo) throws VisitorException {
        // Put plan to project secondary key to the POLocalRearrange
        try {
            String scope = rearrange.getOperatorKey().scope;
            List<PhysicalPlan> secondaryPlanList = new ArrayList<PhysicalPlan>();
            for (ColumnChainInfo columnChainInfo : secondarySortKeyInfo
                    .getColumnChains()) {
                PhysicalPlan secondaryPlan = new PhysicalPlan();
                for (int i = 1; i < columnChainInfo.size(); i++) {
                    // The first item in columnChainInfo indicate the index of
                    // input, we have addressed
                    // already before we come here
                    ColumnInfo columnInfo = columnChainInfo.getColumnInfo(i);
                    POProject project = new POProject(
                            new OperatorKey(scope, NodeIdGenerator
                                    .getGenerator().getNextNodeId(scope)),
                            rearrange.getRequestedParallelism());
                    if(columnInfo.isRangeProject())
                        project.setProjectToEnd(columnInfo.getStartCol());
                    else
                        project
                                .setColumns((ArrayList<Integer>) columnInfo.getColumns());
                    project.setResultType(columnInfo.getResultType());
                    secondaryPlan.addAsLeaf(project);
                }
                if (secondaryPlan.isEmpty()) { // If secondary key sort on the
                                               // input as a whole
                    POProject project = new POProject(
                            new OperatorKey(scope, NodeIdGenerator
                                    .getGenerator().getNextNodeId(scope)),
                            rearrange.getRequestedParallelism());
                    project.setStar(true);
                    secondaryPlan.addAsLeaf(project);
                }
                secondaryPlanList.add(secondaryPlan);
            }
            rearrange.setSecondaryPlans(secondaryPlanList);
        } catch (PlanException e) {
            int errorCode = 2204;
            throw new VisitorException("Error setting secondary key plan",
                    errorCode, e);
        }
    }

    // Find eligible sort and distinct physical operators from the reduce plan.
    // SecondaryKeyChecker will check for sort/distinct keys (for distinct, it
    // is
    // always the entire bag), if it is the same with the main key, then we can
    // just
    // remove it. If it is not, then we can have 1 secondary sort key, put the
    // first
    // such sort/distinct key as the secondary sort key. For subsequent
    // sort/distinct,
    // we cannot do any secondary key optimization because we only have 1
    // secondary
    // sort key.
    private static class SecondaryKeyDiscover {
        PhysicalPlan mPlan;

        List<POSort> sortsToRemove = new ArrayList<POSort>();

        List<PODistinct> distinctsToChange = new ArrayList<PODistinct>();

        List<SortKeyInfo> sortKeyInfos;

        SortKeyInfo secondarySortKeyInfo;

        ColumnChainInfo columnChainInfo = null;

        // PhysicalPlan here is foreach inner plan
        SecondaryKeyDiscover(PhysicalPlan plan,
                List<SortKeyInfo> sortKeyInfos, SortKeyInfo secondarySortKeyInfo) {
            this.mPlan = plan;
            this.sortKeyInfos = sortKeyInfos;
            this.secondarySortKeyInfo = secondarySortKeyInfo;
        }

        public void process() throws FrontendException
        {
            List<PhysicalOperator> roots = mPlan.getRoots();
            for (PhysicalOperator root : roots) {
                columnChainInfo = new ColumnChainInfo();
                processRoot(root);
            }
        }

        public void processRoot(PhysicalOperator root) throws FrontendException {
            PhysicalOperator currentNode = root;
            while (currentNode!=null) {
                boolean sawInvalidPhysicalOper = false;
                if (currentNode instanceof PODistinct)
                    sawInvalidPhysicalOper = processDistinct((PODistinct)currentNode);
                else if (currentNode instanceof POSort)
                    sawInvalidPhysicalOper = processSort((POSort)currentNode);
                else if (currentNode instanceof POProject)
                    sawInvalidPhysicalOper = processProject((POProject)currentNode);
                else if (currentNode instanceof POUserFunc ||
                         currentNode instanceof POUnion ||
                         // We don't process foreach, since foreach is too complex to get right
                         currentNode instanceof POForEach)
                    break;

                if (sawInvalidPhysicalOper)
                    break;

                List<PhysicalOperator> succs = mPlan.getSuccessors(currentNode);
                if (succs==null)
                    currentNode = null;
                else {
                    if (succs.size()>1) {
                        int errorCode = 2215;
                        throw new FrontendException("See more than 1 successors in the nested plan for "+currentNode,
                                errorCode);
                    }
                    currentNode = succs.get(0);
                }
            }
        }

        // We see PODistinct, check which key it is using
        public boolean processDistinct(PODistinct distinct) throws FrontendException {
            SortKeyInfo keyInfos = new SortKeyInfo();
            try {
                keyInfos.insertColumnChainInfo(0,
                        (ColumnChainInfo) columnChainInfo.clone(), true);
            } catch (CloneNotSupportedException e) { // We implement Clonable,
                                                     // impossible to get here
            }

            // if it is part of main key
            for (SortKeyInfo sortKeyInfo : sortKeyInfos) {
                if (sortKeyInfo.moreSpecificThan(keyInfos)) {
                    distinctsToChange.add(distinct);
                    return false;
                }
            }

            // if it is part of secondary key
            if (secondarySortKeyInfo != null
                    && secondarySortKeyInfo.moreSpecificThan(keyInfos)) {
                distinctsToChange.add(distinct);
                return false;
            }

            // Now set the secondary key
            if (secondarySortKeyInfo == null) {
                distinctsToChange.add(distinct);
                secondarySortKeyInfo = keyInfos;
            }
            return false;
        }

        // Accumulate column info
        public boolean processProject(POProject project) throws FrontendException {
            columnChainInfo.insertInReduce(project);
            return false;
        }

        // We see POSort, check which key it is using
        public boolean processSort(POSort sort) throws FrontendException{
            SortKeyInfo keyInfo = new SortKeyInfo();
            for (int i = 0; i < sort.getSortPlans().size(); i++) {
                PhysicalPlan sortPlan = sort.getSortPlans().get(i);
                ColumnChainInfo sortChainInfo = null;
                try {
                    sortChainInfo = (ColumnChainInfo) columnChainInfo.clone();
                } catch (CloneNotSupportedException e) { // We implement
                                                         // Clonable, impossible
                                                         // to get here
                }
                boolean r = false;
                try {
                    r = collectColumnChain(sortPlan, sortChainInfo);
                } catch (PlanException e) {
                    int errorCode = 2206;
                    throw new FrontendException("Error visiting POSort inner plan",
                            errorCode, e);
                }
                if (r==true) // if we saw physical operator other than project in sort plan
                {
                    return true;
                }
                keyInfo.insertColumnChainInfo(i, sortChainInfo, sort
                        .getMAscCols().get(i));
            }
            // if it is part of main key
            for (SortKeyInfo sortKeyInfo : sortKeyInfos) {
                if (sortKeyInfo.moreSpecificThan(keyInfo)) {
                    sortsToRemove.add(sort);
                    return false;
                }
            }
            // if it is part of secondary key
            if (secondarySortKeyInfo != null
                    && secondarySortKeyInfo.moreSpecificThan(keyInfo)) {
                sortsToRemove.add(sort);
                return false;
            }

            // Now set the secondary key
            if (secondarySortKeyInfo == null) {
                sortsToRemove.add(sort);
                secondarySortKeyInfo = keyInfo;
            }
            return false;
        }

        public List<POSort> getSortsToRemove() {
            return sortsToRemove;
        }

        public List<PODistinct> getDistinctsToChange() {
            return distinctsToChange;
        }

        public SortKeyInfo getSecondarySortKeyInfo() {
            return secondarySortKeyInfo;
        }
    }

    // Return true if we saw physical operators other than project in the plan
    static private boolean collectColumnChain(PhysicalPlan plan,
            ColumnChainInfo columnChainInfo) throws PlanException {
        if (plan.getRoots().size() != 1) {
            return true;
        }

        PhysicalOperator currentNode = plan.getRoots().get(0);

        while (currentNode != null) {
            if (currentNode instanceof POProject) {
                POProject project = (POProject) currentNode;
                columnChainInfo.insertInReduce(project);
            } else {
                return true;
            }
            List<PhysicalOperator> succs = plan.getSuccessors(currentNode);
            if (succs == null)
                break;
            if (succs.size() != 1) {
                int errorCode = 2208;
                throw new PlanException(
                        "Exception visiting foreach inner plan", errorCode);
            }
            currentNode = succs.get(0);
        }
        return false;
    }

    public static void setIsSparkMode(boolean isSparkMode) {
        SecondaryKeyOptimizerUtil.isSparkMode = isSparkMode;
    }
}


text:
using Microsoft.Band.Sensors;
using System;
using System.IO;

namespace FakeBand.Fakes
{
    public class FakeBandDistanceReading : IBandDistanceReading
    {
        public FakeBandDistanceReading(double speed, long totalDistance, DateTimeOffset timestamp)
        {
            _speed = speed;
            _pace = CalcPace(_speed);
            _distance = totalDistance;
            _timestamp = timestamp;
        }

        // speed is measured in cm/s, Pace measured in ms/m
        // Running Speed is measured in cm/s
        // - 3 - 15 miles per hour roughly walking - running
        // Running Pace is measured in ms/m
        //  3 miles per hour -> 4.8km/h -> 4800 m/h -> 480000 cm/h -> 133 cm/s
        // (convert to pace) 133 cm / s : 0.00752 s / cm-> 0.752 s / m-> 752 ms / m
        // 15 miles per hour-> 24.138km / h-> 24138 m / h-> 2413800 cm / h-> 670 cm / s
        // (convert to pace) 670 cm / s :  0.00149 s / cm-> 1.49 s / m-> 1490 ms / m
        private double CalcPace(double speed)
        {
            return 100000.0 / speed;
        }

        public MotionType CurrentMotion
        {
            get
            {
                return Pace > 200 ? MotionType.Running : MotionType.Jogging;
            }
        }

        public double Pace
        {
            get
            {
                return _pace;
            }
        }

        Random rnd = new Random();

        public double Speed
        {
            get
            {
                return _speed;
            }
        }

        private DateTimeOffset _timestamp;
        public DateTimeOffset Timestamp
        {
            get
            {
                return _timestamp;
            }
        }

        long _distance;
        private double _speed;
        private double _pace;

        // Mesured in cm
        public long TotalDistance
        {
            get
            {
                return _distance;
            }
        }

        public long DistanceToday
        {
            get
            {
                return 800;
            }
        }

        public override string ToString()
        {
            return $"Distance Reading: Speed [{Speed}] Pace [{Pace}] Total Distance [{TotalDistance}]";
        }
    }
}


text:
<?php

namespace Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
    protected $model = User::class;

    public function definition(): array
    {
        return [
            'name'           => $this->faker->name,
            'email'          => $this->faker->unique()->safeEmail,
            'password'       => bcrypt('secret'),
            'remember_token' => Str::random(10),
        ];
    }

    public function isStudent(): UserFactory
    {
        return $this->state(function (array $attributes) {
            $isTeacher = $this->faker->boolean();
            $nid = $isTeacher
                ? $this->faker->regexify('[DEPMV]([0-9]){7}')
                : $this->faker->regexify('T[0-9]{5}');

            return [
                'nid' => $nid,
            ];
        });
    }
}


text:
<?php
function smarty_function_moduleRun($params){
    $module = isset($params['m']) ? $params['m'] : null;
    if( !is_null($module) ){
        return Modules::run($module);
    }

}


text:
using std::fabs;
#include "compute_residual.hpp"

int compute_residual(const int n, const double * const v1,
		     const double * const v2, double * const residual)
{
  double local_residual = 0.0;

  for (int i=0; i<n; i++) {
    double diff = fabs(v1[i] - v2[i]);
    if (diff > local_residual) local_residual = diff;
  }
#ifdef USING_MPI
  // Use MPI's reduce function to collect all partial sums

  double global_residual = 0;

  MPI_Allreduce(&local_residual, &global_residual, 1, MPI_DOUBLE, MPI_MAX,
                MPI_COMM_WORLD);
  *residual = global_residual;
#else
  *residual = local_residual;
#endif

  return(0);
}


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

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>com.amazonaws.services.marketplacecommerceanalytics (AWS SDK for Java - 1.11.60)</title>
<meta name="date" content="2016-11-23">
<link rel="stylesheet" type="text/css" href="../../../../JavaDoc.css" title="Style">

com.amazonaws.services.marketplacecommerceanalytics

Interfaces

AWSMarketplaceCommerceAnalytics

AWSMarketplaceCommerceAnalyticsAsync

Classes

AbstractAWSMarketplaceCommerceAnalytics

AbstractAWSMarketplaceCommerceAnalyticsAsync

AWSMarketplaceCommerceAnalyticsAsyncClient

AWSMarketplaceCommerceAnalyticsAsyncClientBuilder

AWSMarketplaceCommerceAnalyticsClient

AWSMarketplaceCommerceAnalyticsClientBuilder


text:
RSpec.describe Hshtg::Stream::StreamController, '#stream_controller', focus: true do
  context 'initialize' do
    it 'can be initialized' do
      controller = Hshtg::Stream::StreamController.instance
      expect(controller).to_not be_nil
    end

    it 'can get tags' do
      text       = '#one #one #two # three #One'
      controller = Hshtg::Stream::StreamController.instance
      parser     = Hshtg::Stream::StreamParser.new(Hshtg::Storage::InMemoryStore.new)
      tags       = Hshtg::Stream::HashtagExtractor.hash_tags_from_tweet(text)
      parser.send(:add_tags, tags)
      controller.stream_parser = parser
      top_tags                 = controller.top_n(2)
      expect(top_tags.count).to eq(2)
      expect(top_tags[0].tag.downcase).to eq('one')
    end
  end
end


text:
<?php

if (!\function_exists('printnodeSetUp')) {
    require('setUpTearDown.php');
}

class PrintJobsTest extends PHPUnit_Framework_TestCase
{

    /**
     * @test
     */
    public function testViewPrintJobs()
    {

        $computerIds = printnodeSetUp();

        $credentials = new \PrintNode\Credentials\ApiKey(API_KEY);

        $client = new \PrintNode\Client($credentials);

        $client->apiHost = API_HOST;

        $printJobs = $client->viewPrintJobs();

        $this->assertTrue(\is_array($printJobs));

        $this->assertContainsOnlyInstancesOf('\PrintNode\Entity\PrintJob', $printJobs);

        $printJob = array_pop($printJobs);

        $this->assertObjectHasAttribute('id', $printJob);
        $this->assertObjectHasAttribute('printer', $printJob);
        $this->assertObjectHasAttribute('printerId', $printJob);
        $this->assertObjectHasAttribute('title', $printJob);
        $this->assertObjectHasAttribute('contentType', $printJob);
        $this->assertObjectHasAttribute('content', $printJob);
        $this->assertObjectHasAttribute('source', $printJob);
        $this->assertObjectHasAttribute('filesize', $printJob);
        $this->assertObjectHasAttribute('options', $printJob);
        $this->assertObjectHasAttribute('expireAfter', $printJob);
        $this->assertObjectHasAttribute('qty', $printJob);
        $this->assertObjectHasAttribute('authentication', $printJob);
        $this->assertObjectHasAttribute('createTimestamp', $printJob);
        $this->assertObjectHasAttribute('state', $printJob);
        $this->assertObjectHasAttribute('expireAt', $printJob);

        printnodeTearDown();

    }

    /**
     * Tear down the remote environment if a previous method failed before
     * tearing down
     */
    public static function tearDownAfterClass()
    {

        printnodeTearDown();

    }

}


text:
Join at [https://anti-social.herokuapp.com](https://anti-social.herokuapp.com) !!!

### Are you tired of not having enough online followers in your social networks?

Can't you stand the fact that only the cool kids are popular and have all the "likes"? Nobody "stars" or "retweets" your stories? Do you wish you had more friends to love all your pointless posts?

### Your problems are over!

Get as many friends as you need to feel good about yourself again! Register Today!

### Posts are not limited to 140 characters and you can write in rich text!

### Screenshots:

![](http://i.imgur.com/aWITmEH.png)

![](http://i.imgur.com/fRnw4Ok.png)

![](http://i.imgur.com/N9e8kTB.png)

![](http://i.imgur.com/M9WeNOs.png)

![](http://i.imgur.com/GM6WNIK.png)

![](http://i.imgur.com/8ugLkBq.png)

## Instructions - Development

The Anti-Social Network was built on Flask&Python. The License is MIT, feel free to play:

#### Start your virtual environment.

#### Import the dependences:

```
(anti) $ pip install -r requirements/*
```

####Import environment variables for user authentications (this can also be added to your .bash):

```
(anti) $ export MAIL_USERNAME=<Gmail username>
(anti) $ export MAIL_PASSWORD=<Gmail password>
(anti) $ export ANTISOCIAL_ADMIN=<your-email-address>
(anti) $ export SECRET_KEY=<choose-a-secrecy>
```

#### Upgrade your DB:

```
$ python manage.py db migrate
$ python manage.py db upgrade
```

#### Run!

```
$ python manage.py runserver
```

#### You can also do:

```
$ python manage.py shell
$ python manage.py test
```

## Instructions - Production

If you want to use the machinery to deploy the app somewhere (MIT License).
[Instructions here](https://coderwall.com/p/pstm1w?i=2&p=1&q=author%3Abt3gl&t%5B%5D=bt3gl).

----

## License

When making a reference to my work, please use my [website](http://bt3gl.github.io/index.html).
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).


text:
package com.epam.dlab.automation.cloud.gcp;

import com.epam.dlab.automation.exceptions.CloudException;
import com.epam.dlab.automation.helper.ConfigPropertyValue;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.compute.Compute;
import com.google.api.services.compute.model.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Assert;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.time.Duration;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class GcpHelper {

	private static final Logger LOGGER = LogManager.getLogger(GcpHelper.class);
	private static final Duration CHECK_TIMEOUT = Duration.parse("PT10m");
	private static final String LOCALHOST_IP = ConfigPropertyValue.get("LOCALHOST_IP");
	private static final String NOT_EXIST = "doesn't exist for this resource type";

	private GcpHelper() {
	}

	private static List<Instance> getInstances(String projectId, List<String> zones) throws IOException {
		List<Instance> instanceList = new ArrayList<>();
		for (String zone : zones) {
			Compute.Instances.List request = ComputeService.getInstance().instances().list(projectId, zone);
			InstanceList response;
			do {
				response = request.execute();
				if (response.getItems() == null) {
					continue;
				}
				instanceList.addAll(response.getItems());
				request.setPageToken(response.getNextPageToken());
			} while (response.getNextPageToken() != null);

		}
		return !instanceList.isEmpty() ? instanceList : null;
	}

	public static List<String> getInstancePrivateIps(Instance instance) {
		return instance.getNetworkInterfaces().stream().filter(Objects::nonNull)
				.map(NetworkInterface::getNetworkIP).filter(Objects::nonNull)
				.collect(Collectors.toList());
	}

	public static List<String> getInstancePublicIps(Instance instance) {
		return instance.getNetworkInterfaces()
				.stream().filter(Objects::nonNull)
				.map(NetworkInterface::getAccessConfigs)
				.filter(Objects::nonNull).map(Collection::stream)
				.flatMap(Function.identity()).filter(Objects::nonNull)
				.map(AccessConfig::getNatIP).filter(Objects::nonNull)
				.collect(Collectors.toList());
	}

	public static List<Instance> getInstancesByName(String name, String projectId, boolean restrictionMode,
													List<String> zones) throws IOException {
		if (ConfigPropertyValue.isRunModeLocal()) {
			List<Instance> mockedInstanceList = new ArrayList<>();
			Instance mockedInstance = mock(Instance.class);
			NetworkInterface mockedNetworkInterface = mock(NetworkInterface.class);
			when(mockedInstance.getNetworkInterfaces()).thenReturn(Collections.singletonList(mockedNetworkInterface));
			when(mockedInstance.getNetworkInterfaces().get(0).getNetworkIP()).thenReturn(LOCALHOST_IP);
			AccessConfig mockedAccessConfig = mock(AccessConfig.class);
			when(mockedInstance.getNetworkInterfaces().get(0).getAccessConfigs())
					.thenReturn(Collections.singletonList(mockedAccessConfig));
			when(mockedInstance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP())
					.thenReturn(LOCALHOST_IP);
			mockedInstanceList.add(mockedInstance);
			return mockedInstanceList;
		}
		List<Instance> instanceList = getInstances(projectId, zones);
		if (instanceList == null) {
			LOGGER.warn("There is not any virtual machine in GCP for project with id {}", projectId);
			return instanceList;
		}
		if (restrictionMode) {
			instanceList.removeIf(instance -> !hasName(instance, name));
		} else {
			instanceList.removeIf(instance -> !containsName(instance, name));
		}
		return !instanceList.isEmpty() ? instanceList : null;
	}

	private static boolean hasName(Instance instance, String name) {
		return instance.getName().equals(name);
	}

	private static boolean containsName(Instance instance, String name) {
		return instance.getName().contains(name);
	}

	private static String getStatus(Instance instance) {
		return instance.getStatus().toLowerCase();
	}

	public static void checkGcpStatus(String instanceName, String projectId, GcpInstanceState expGcpStatus, boolean
			restrictionMode, List<String> zones) throws InterruptedException, IOException {

		LOGGER.info("Check status of instance with name {} on GCP", instanceName);
		if (ConfigPropertyValue.isRunModeLocal()) {
			LOGGER.info("GCP instance with name {} fake status is {}", instanceName, expGcpStatus);
			return;
		}
		List<Instance> instancesWithName = getInstancesByName(instanceName, projectId, restrictionMode, zones);
		if (instancesWithName == null) {
			LOGGER.warn("There is not any instance in GCP with name {}", instanceName);
			return;
		}

		String instanceStatus;
		long requestTimeout = ConfigPropertyValue.getGcpRequestTimeout().toMillis();
		long timeout = CHECK_TIMEOUT.toMillis();
		long expiredTime = System.currentTimeMillis() + timeout;
		Instance instance = instancesWithName.get(0);
		while (true) {
			instanceStatus = getStatus(instance);
			if (instanceStatus.equalsIgnoreCase(expGcpStatus.toString())) {
				break;
			}
			if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
				LOGGER.info("GCP instance with name {} state is {}", instanceName, getStatus(instance));
				throw new CloudException("Timeout has been expired for check status of GCP instance with " +
						"name " + instanceName);
			}
			Thread.sleep(requestTimeout);
		}

		for (Instance inst : instancesWithName) {
			LOGGER.info("GCP instance with name {} status is {}. Instance id {}, private IP {}, public " +
							"IP {}",
					instanceName, getStatus(inst), inst.getId(), (!getInstancePrivateIps(inst).isEmpty() ?
							getInstancePrivateIps(inst).get(0) : NOT_EXIST),
					(!getInstancePublicIps(inst).isEmpty() ? getInstancePublicIps(inst).get(0) : NOT_EXIST));
		}
		Assert.assertEquals(instanceStatus, expGcpStatus.toString(), "GCP instance with name " + instanceName +
				" status is not correct. Instance id " + instance.getId() + ", private IP " +
				(!getInstancePrivateIps(instance).isEmpty() ? getInstancePrivateIps(instance).get(0) : NOT_EXIST) +
				", public IP " +
				(!getInstancePublicIps(instance).isEmpty() ? getInstancePublicIps(instance).get(0) : NOT_EXIST));
	}

	public static List<String> getAvailableZonesForProject(String projectId) throws IOException {
		if (ConfigPropertyValue.isRunModeLocal()) {
			return Collections.emptyList();
		}
		List<Zone> zoneList = new ArrayList<>();
		Compute.Zones.List request = ComputeService.getInstance().zones().list(projectId);
		ZoneList response;
		do {
			response = request.execute();
			if (response.getItems() == null) {
				continue;
			}
			zoneList.addAll(response.getItems());
			request.setPageToken(response.getNextPageToken());
		} while (response.getNextPageToken() != null);
		return zoneList.stream().map(Zone::getDescription).collect(Collectors.toList());
	}

	private static class ComputeService {

		private static Compute instance;

		private ComputeService() {
		}

		static synchronized Compute getInstance() throws IOException {
			if (!ConfigPropertyValue.isRunModeLocal() && instance == null) {
				try {
					instance = createComputeService();
				} catch (GeneralSecurityException e) {
					LOGGER.info("An exception occured: {}", e);
				}
			}
			return instance;
		}

		private static Compute createComputeService() throws IOException, GeneralSecurityException {
			HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
			JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

			GoogleCredential credential =
					GoogleCredential.fromStream(new FileInputStream(ConfigPropertyValue.getGcpAuthFileName()));
			if (credential.createScopedRequired()) {
				credential = credential.createScoped(
						Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
			}

			return new Compute.Builder(httpTransport, jsonFactory, credential)
					.setApplicationName("Google-ComputeSample/0.1")
					.build();
		}

	}

}


text:
package com.all.core.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class PasswordDigest {

	private PasswordDigest() {

	}

	public static String md5(byte[] password) {
		MessageDigest md5;
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			return new String(password);
		}
		md5.reset();
		md5.update(password);
		StringBuilder sb = new StringBuilder();
		for(byte b:md5.digest()) {
			String hexString = Integer.toHexString(0xFF&b);
			if(hexString.length()==1) {
				sb.append('0');
			}
			sb.append(hexString);
		}
		return sb.toString();
	}

}