text:
/*
Package swp implements the same Sliding Window Protocol that
TCP uses for flow-control and reliable, ordered delivery.

The Nats event bus (https://nats.io/) is a
software model of a hardware multicast
switch. Nats provides multicast, but no guarantees of delivery
and no flow-control. This works fine as long as your
downstream read/subscribe capacity is larger than your
publishing rate.

If your nats publisher evers produces
faster than your subscriber can keep up, you may overrun
your buffers and drop messages. If your sender is local
and replaying a disk file of traffic over nats, you are
guanateed to exhaust even the largest of the internal
nats client buffers. In addition you may wish guaranteed
order of delivery (even with dropped messages), which
swp provides.

Hence swp was built to provide flow-control and reliable, ordered
delivery on top of the nats event bus. It reproduces the
TCP sliding window and flow-control mechanism in a
Session between two nats clients. It provides flow
control between exactly two nats endpoints; in many
cases this is sufficient to allow all subscribers to
keep up.  If you have a wide variation in consumer
performance, establish the rate-controlling
swp Session between your producer and your
slowest consumer.

There is also a Session.RegisterAsap() API that can be
used to obtain possibly-out-of-order and possibly-duplicated
but as-soon-as-possible delivery (similar to that which
nats give you natively), while retaining the
flow-control required to avoid client-buffer overrun.
This can be used in tandem with the main always-ordered-and-lossless
API if so desired.
*/
package swp

import (
	"bytes"
	"fmt"
	"log"
	"os"
	"sync"
	"sync/atomic"
	"time"

	"github.com/glycerine/bchan"
	"github.com/glycerine/cryrand"
	"github.com/glycerine/idem"
	"github.com/tinylib/msgp/msgp"
)

// sliding window protocol
//
// Reference: pp118-120, Computer Networks: A Systems Approach
//  by Peterson and Davie, Morgan Kaufmann Publishers, 1996.
//
// In addition to sliding window, we implement flow-control
// similar to how tcp does for throttling senders.
// See pp296-301 of Peterson and Davie.
//
// Most of the implementation is in sender.go and recv.go.

//go:generate msgp

//msgp:ignore TxqSlot RxqSlot Semaphore SenderState RecvState SWP Session NatsNet SimNet Network Session SWP SessionConfig TermConfig ReadRequest

var mylog *log.Logger

func init() {
	mylog = log.New(os.Stderr, "", log.LUTC|log.LstdFlags|log.Lmicroseconds)
}

// here so that msgp can know what it is
type TcpEvent int

// Packet is what is transmitted between Sender A and
// Receiver B, where A and B are the two endpoints in a
// given Session. (Endpoints are specified by the strings localInbox and
// destInbox in the NewSession constructor.)
//
// Packets also flow symmetrically from Sender B to Receiver A.
//
// Special packets have AckOnly, KeepAlive, or Closing
// flagged; otherwise normal packets are data
// segments that have neither of these flags
// set. Only normal data packets are tracked
// for timeout and retry purposes.
type Packet struct {
	From string
	Dest string

	// uniquely identify a file/session with a randomly
	// chosen then fixed nonce. See NewSessionNonce() to generate.
	FromSessNonce string
	DestSessNonce string

	// ArrivedAtDestTm is timestamped by
	// the receiver immediately when the
	// packet arrives at the Dest receiver.
	ArrivedAtDestTm time.Time

	// DataSendTm is stamped anew on each data send and retry
	// from the sender. Acks by the receiver are
	// stamped with the AckReplyTm field, and DataSendTm
	// is copied to the ack to make one-way estimates (if
	// your clocks are synced) viable. Currently we do
	// as TCP does and compute RTT based on the roundtrip
	// from the originating endpoint, which avoids issues
	// around clock skew.
	//
	// For the rationale for updating the timestamp on each
	// retry, see the discussion of the Karn/Partridge
	// algorithm, p302 of Peterson and Davie 1996.
	//
	// Summary: Accurate RTT requires accurate association of
	// ack with which retry it is responding to, and thus
	// time of the retry is the relevant one for RTT computation.
	// If internally you need to know when a data packet was
	// first/originally transmitted, see the TxqSlot.OrigSendTime
	// value.
	DataSendTm time.Time

	SeqNum int64

	// SeqRetry: 0, 1, 2: allow
	// accurate RTT estimates. Only on
	// data frames; acks/control will be negative.
	SeqRetry int64

	AckNum int64

	// AckRetry: which SeqRetry attempt for
	// the AckNum this AckNum is associated with.
	AckRetry   int64
	AckReplyTm time.Time

	// things like Fin, FinAck, DataAck, KeepAlive are
	// all TcpEvents.
	TcpEvent TcpEvent

	// Convey the state in keepalives in place of
	// retry for the estabAck. Otherwise if estabAck
	// is lost, the client doing Connect() can get stuck
	// in SynSent.
	FromTcpState TcpState

	// like the byte count AdvertisedWindow in TCP, but
	// since nats has both byte and message count
	// limits, we want convey these instead.
	AvailReaderBytesCap int64
	AvailReaderMsgCap   int64

	// Estimate of the round-trip-time (RTT) from
	// the senders point of view. In nanoseconds.
	// Allows mostly passive recievers to have
	// an accurate view of the end-to-end RTT.
	FromRttEstNsec int64

	// Estimate of the standard deviation of
	// the round-trip-time from the senders
	// point of view. In nanoseconds.
	FromRttSdNsec int64

	// number of RTT observations in the From RTT
	// estimates above, also avoids double counting.
	FromRttN int64

	// CumulBytesTransmitted should give the total accumulated
	// count of bytes ever transmitted on this session
	// from `From` to `Dest`.
	// On data payloads, CumulBytesTransmitted allows
	// the receiver to figure out how
	// big any gaps are, so as to give accurate flow control
	// byte count info. The CumulBytesTransmitted count
	// should include this packet's len(Data), assuming
	// this is a data packet.
	CumulBytesTransmitted int64

	Data []byte

	// DataOffset tells us
	// where to start reading from in Data. It
	// allows us to have consumed only part of
	// a packet on one Read().
	DataOffset int

	// checksum of Data
	Blake2bChecksum []byte

	// those waiting for when this particular
	// Packet is acked by the
	// recipient can allocate a bchan.New(1) here and wait for a
	// channel receive on <-CliAcked.Ch
	CliAcked *bchan.Bchan `msg:"-"` // omit from serialization

	Accounting *ByteAccount `msg:"-"` // omit from serialization
}

// SWP holds the Sliding Window Protocol state
type SWP struct {
	Sender *SenderState
	Recver *RecvState
}

// NewSWP makes a new sliding window protocol manager, holding
// both sender and receiver components.
func NewSWP(net Network, windowMsgCount int64, windowByteCount int64,
	timeout time.Duration, inbox string, destInbox string, clk Clock, keepAliveInterval time.Duration, nonce string) *SWP {

	snd := NewSenderState(net, windowMsgCount, timeout, inbox, destInbox, clk, keepAliveInterval, nonce)
	rcv := NewRecvState(net, windowMsgCount, windowByteCount, timeout, inbox, snd, clk, nonce, destInbox, keepAliveInterval)
	swp := &SWP{
		Sender: snd,
		Recver: rcv,
	}

	return swp
}

type TerminatedError struct {
	Msg string
}

func (t *TerminatedError) Error() string {
	return t.Msg
}

// Session tracks a given point-to-point sesssion and its
// sliding window state for one of the end-points.
type Session struct {
	Cfg         *SessionConfig
	Swp         *SWP
	Destination string
	MyInbox     string

	Net               Network
	ReadMessagesCh    chan InOrderSeq
	AcceptReadRequest chan *ReadRequest

	// if terminated with error,
	// that error will live here. Retreive
	// with GetErr()
	exitErr error

	// Halt.Done.Chan is closed if session is terminated.
	// This will happen if the remote session stops
	// responding and is thus declared dead, as well
	// as after an explicit close.
	Halt *idem.Halter

	packetsConsumed                  uint64
	packetsSent                      uint64
	NumFailedKeepAlivesBeforeClosing int
	ConnectTimeout                   time.Duration
	ConnectAttempts                  int

	mut                sync.Mutex
	RemoteSenderClosed chan bool

	LocalSessNonce  string
	RemoteSessNonce string

	// testing only
	simulateLostSynCount int
}

// SessionConfig configures a Session.
type SessionConfig struct {

	// the network to use, NatsNet or SimNet
	Net Network

	// where we listen
	LocalInbox string

	// the remote destination topic for our messages
	DestInbox string

	// capacity of our receive buffers in message count
	WindowMsgCount int64

	// capacity of our receive buffers in byte count
	WindowByteSz int64

	// how often we wakeup and check
	// if packets need to be retried.
	Timeout time.Duration

	KeepAliveInterval time.Duration

	// set to -1 to disable auto-close. If
	// not set (or left at 0), then we default
	// to 50 (so after 50 keep-alive intervals
	// with no remote contact, we close the session).
	NumFailedKeepAlivesBeforeClosing int

	// the clock (real or simulated) to use
	Clk Clock

	TermCfg TermConfig
}

type TermConfig struct {
	// how long a window we use for termination
	// checking. Ignored if 0.
	TermWindowDur time.Duration

	// how many unacked packets we can see inside
	// TermWindowDur before giving up and terminating
	// the session. Ignored if 0.
	TermUnackedLimit int
}

// NewSession makes a new Session, and calls
// Swp.Start to begin the sliding-window-protocol.
//
// If windowByteSz is negative or less than windowMsgSz,
// we estimate a byte size based on 10kb messages and
// the given windowMsgSz. It is much better to give the
// aggregate byte limit you want specifically. Negative
// windowByteSz is merely a convenience for writing tests.
//
// The timeout parameter controls how often we wake up
// to check for packets that need to be retried.
//
// Packet timers (retry deadlines) are established
// using an exponential moving average + some standard
// deviations of the observed round-trip time of
// Ack packets. Retries reset the DataSentTm so
// there is never confusion as to which retry is
// being acked. The Ack packet method is not subject
// to two-clock skew because the same clock is used
// for both begin and end measurements.
//
func NewSession(cfg SessionConfig) (*Session, error) {

	if cfg.WindowMsgCount < 1 {
		return nil, fmt.Errorf("windowMsgSz must be 1 or more")
	}

	if cfg.WindowByteSz < cfg.WindowMsgCount {
		// guestimate
		cfg.WindowByteSz = cfg.WindowMsgCount * 10 * 1024
	}

	// set default; user can set to -1 to deactivate auto-close.
	if cfg.NumFailedKeepAlivesBeforeClosing == 0 {
		cfg.NumFailedKeepAlivesBeforeClosing = 50
	}

	if cfg.KeepAliveInterval == 0 {
		cfg.KeepAliveInterval = time.Millisecond * 500
	}
	nonce := NewSessionNonce()

	sess := &Session{
		Cfg: &cfg,
		Swp: NewSWP(cfg.Net, cfg.WindowMsgCount, cfg.WindowByteSz,
			cfg.Timeout, cfg.LocalInbox, cfg.DestInbox, cfg.Clk,
			cfg.KeepAliveInterval, nonce),
		MyInbox:     cfg.LocalInbox,
		Destination: cfg.DestInbox,
		Net:         cfg.Net,
		Halt:        idem.NewHalter(),
		NumFailedKeepAlivesBeforeClosing: cfg.NumFailedKeepAlivesBeforeClosing,
		RemoteSenderClosed:               make(chan bool),
		LocalSessNonce:                   nonce,
	}
	sess.Swp.Sender.NumFailedKeepAlivesBeforeClosing = cfg.NumFailedKeepAlivesBeforeClosing
	sess.Swp.Start(sess)
	sess.ReadMessagesCh = sess.Swp.Recver.ReadMessagesCh
	sess.AcceptReadRequest = sess.Swp.Recver.AcceptReadRequest

	return sess, nil
}

// Push sends a message packet, blocking until there
// is a flow-control slot available.
// The Push will block due to flow control to avoid
// over-running the receiving clients buffers.
//
// Upon return we are not guaranteed that the
// the message has reached the broker or the client.
// If you want to Flush() to the broker,
// use the PushGetAck() method instead.
// This will hurt throughput, but may be
// needed if you are going to shutdown
// right after the send (to avoid dropping
// the packet before it reaches the broker).
//
// You can use s.CountPacketsSentForTransfer() to get
// the total count of packets Push()-ed so far.
func (s *Session) Push(pack *Packet) {
	select {
	case s.Swp.Sender.BlockingSend <- pack:
		//p("%v Push succeeded on payload '%s' into BlockingSend", s.MyInbox, string(pack.Data))
		s.IncrPacketsSentForTransfer(1)
	case <-s.Swp.Sender.Halt.ReqStop.Chan:
		// give up, Sender is shutting down.
	}
}

// SelfConsumeForTesting sets up a reader to read all produced
// messages automatically. You can use CountPacketsReadConsumed() to
// see the total number consumed thus far.
func (s *Session) SelfConsumeForTesting() {
	go func() {
		for {
			select {
			case <-s.Swp.Recver.Halt.ReqStop.Chan:
				return
			case read := <-s.ReadMessagesCh:
				s.IncrPacketsReadConsumed(int64(len(read.Seq)))
			}
		}
	}()
}

// IncrementClockOnReceiveForTesting supports testing by
// incrementing the Clock automatically when a packet is
// received. Expects a SimClock to be in use, and so
// to avoid mixing testing and prod this call will panic
// if that assumption in violated.
func (s *Session) IncrementClockOnReceiveForTesting() {
	s.Swp.Recver.Clk.(*SimClock).Advance(0)
	s.Swp.Recver.testModeOn()
	s.Swp.Recver.testing.incrementClockOnReceive = true
}

// InWindow returns true iff seqno is in [min, max].
func InWindow(seqno, min, max int64) bool {
	if seqno < min {
		return false
	}
	if seqno > max {
		return false
	}
	return true
}

// Stop shutsdown the session
func (s *Session) Stop() {
	//p("%v Session.Stop called.", s.MyInbox)
	s.Swp.Stop()
	s.SetErr(s.Swp.Sender.GetErr())
	s.Halt.RequestStop()
	s.Halt.Done.Close()
}

// Stop the sliding window protocol
func (s *SWP) Stop() {
	s.Recver.Stop()
	s.Sender.Stop()
}

// Start the sliding window protocol
func (s *SWP) Start(sess *Session) {
	//q("SWP Start() called")
	s.Recver.Start()
	s.Sender.Start(sess)
}

// CountPacketsReadConsumed reports on how many packets
// the application has read from the session.
func (s *Session) CountPacketsReadConsumed() int64 {
	return int64(atomic.LoadUint64(&s.packetsConsumed))
}

// IncrPacketsReadConsumed increment packetsConsumed and return the new total.
func (s *Session) IncrPacketsReadConsumed(n int64) int64 {
	return int64(atomic.AddUint64(&s.packetsConsumed, uint64(n)))
}

// CountPacketsSentForTransfer reports on how many packets.
// the application has written to the session.
func (s *Session) CountPacketsSentForTransfer() int64 {
	return int64(atomic.LoadUint64(&s.packetsSent))
}

// IncrPacketsSentForTransfer increment packetsConsumed and return the new total.
func (s *Session) IncrPacketsSentForTransfer(n int64) int64 {
	return int64(atomic.AddUint64(&s.packetsSent, uint64(n)))
}

// RegisterAsap registers a call back channel,
// rcvUnordered, which will get *Packet that are
// unordered and possibly
// have gaps in their sequence (where packets
// where dropped). However the channel will see
// the packets as soon as possible. The session
// will still be flow controlled however, so
// if the receiver throttles the sender, packets
// may be delayed. Clients should be prepared
// to deal with duplicated, dropped, and mis-ordered packets
// on the rcvUnordered channel.
// The limit argument sets how many messages are queued before
// we drop the oldest.
func (s *Session) RegisterAsap(rcvUnordered chan *Packet, limit int64) error {
	s.Swp.Recver.setAsapHelper <- NewAsapHelper(rcvUnordered, limit)
	return nil
}

// ackCallbackFunc is used for testing: used in setPacketRecvCallback
type ackCallbackFunc func(pack *Packet)

// for testing, get a callback when packets are received.
// test-mode must have already been activated by a call
// to s.Swp.recver.testModeOn(), or we will panic.
func (s *Session) setPacketRecvCallback(cb ackCallbackFunc) {
	s.Swp.Recver.testing.ackCb = cb
}

type ReadRequest struct {
	Done chan bool
	N    int
	Err  error
	P    []byte
}

func NewReadRequest(p []byte) *ReadRequest {
	return &ReadRequest{
		Done: make(chan bool),
		P:    p,
	}
}

// Read implements io.Reader
func (s *Session) Read(fillme []byte) (n int, err error) {
	rr := NewReadRequest(fillme)
	//p("Read gets fillme with len %v. len(rr.P)=%v", len(fillme), len(rr.P))
	//p("rr=%p, s=%p", rr, s)
	select {
	case s.AcceptReadRequest <- rr:
		//p("Read: rr request accepted")
		// good, proceed to get reply
	case <-s.Halt.Done.Chan:
		return 0, ErrSessDone
	case <-s.Halt.ReqStop.Chan:
		return 0, ErrSessDone
	}
	// now get reply.
	select {
	case <-rr.Done:
		//p("Read: got rr.Done closed, rr.N=%v, rr.Err=%v", rr.N, rr.Err)
		return rr.N, rr.Err
	case <-s.Halt.Done.Chan:
		return 0, ErrSessDone
	case <-s.Halt.ReqStop.Chan:
		return 0, ErrSessDone
	}
}

// ByteAccount should be accessed with
// atomics to avoid data races.
type ByteAccount struct {
	NumBytesAcked int64
}

func (s *Session) SetConnectDefaults() {
	if s.ConnectTimeout == 0 {
		s.ConnectTimeout = time.Minute
	}
	if s.ConnectAttempts == 0 {
		s.ConnectAttempts = 5
	}
}

// Write implements io.Writer, chopping p into packet
// sized pieces if need be, and sending then in order
// over the flow-controlled Session s.
//
// simulateLostSynCount should be 0 unless testing
// for lost SYN.
func (s *Session) Write(payload []byte) (n int, err error) {

	err = s.ConnectIfNeeded(s.Destination, s.simulateLostSynCount)
	if err != nil {
		return 0, err
	}

	// use atomics to access the ByteAccount.
	// We attach this to our packets so that
	// we don't get any residual left over acks
	// that may have arrived late from another Write
	// that happened before.
	var ba ByteAccount

	lenp := int64(len(payload))
	if lenp == 0 {
		return 0, nil
	}

	// At 1MB, gnatsd freaks. Keep it under 512KB.
	// sz := int64Min(s.Cfg.WindowByteSz, 1<<19)
	const maxSz = 1 << 19
	sz := int64Min(s.Cfg.WindowByteSz, maxSz)
	if sz < 0 {
		sz = maxSz
	}

	npack := lenp / sz
	if lenp-npack*sz > 0 {
		npack++
	}
	ca := bchan.New(1)
	for i := int64(0); i < npack; i++ {
		pack := &Packet{
			From:       s.MyInbox,
			Dest:       s.Destination,
			Data:       payload[i*sz : int64Min((i+1)*sz, lenp)],
			Accounting: &ba,
			TcpEvent:   EventData,
		}
		if i == npack-1 {
			pack.CliAcked = ca
		}
		s.Push(pack)
		///p("%s Write() sent packet %v of %v", s.MyInbox, i, npack)
	}
	select {
	case <-ca.Ch:
		///p("we got end-to-end ack from receiver that all packets were delivered")
		ca.BcastAck()
	case <-time.After(10 * time.Second):
		mylog.Printf("problem in %s Write: timeout after 10 seconds waiting", s.MyInbox)
	case <-s.Halt.Done.Chan:
	}

	nba := int(atomic.LoadInt64(&ba.NumBytesAcked))
	return nba, s.GetErr()
}

func int64Min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func (s *Session) SetErr(err error) {
	s.mut.Lock()
	s.exitErr = err
	s.mut.Unlock()
}

func (s *Session) GetErr() (err error) {
	s.mut.Lock()
	err = s.exitErr
	s.mut.Unlock()
	return
}

// BigFile represents the transmission of a file;
// size is limited only by memory. Since the primary
// use is to capture the state that is being held
// in memory, this is a reasonable limit.
//
// If you requirer larger than memory transfers,
// can always do infinitely sized streams by
// using the Session implementations of the
// stardard io.Reader and io.Writer interfaces
// (the Read() and Write() methods) directly.
//
// For example, you could use io.Copy() to copy
// a file on one end and a file on the other
// end of two nats clients joined by *Session.
//
type BigFile struct {
	Filepath    string
	SizeInBytes int64
	Blake2b     []byte
	SendTime    time.Time
	Data        []byte
}

// RecvFile will check for corruption and report it
// in err. We may also return the corrupted
// *BigFile structure for further examination.
func (sess *Session) RecvFile() (*BigFile, error) {
	bf := &BigFile{}
	err := msgp.Decode(sess, bf)
	// check the size and checksum
	if bf.SizeInBytes != int64(len(bf.Data)) {
		return bf, fmt.Errorf("RecvFile corruption detected: "+
			"bf.Data was length %v, but expected %v bytes",
			len(bf.Data), bf.SizeInBytes)
	}
	if len(bf.Blake2b) == 0 {
		return bf, fmt.Errorf("got BigFile without checksum?!?!: bf.FilePath='%s', SizeInBytes='%v', SentTime=%v, len(Data)=%v", bf.Filepath, bf.SizeInBytes, bf.SendTime, len(bf.Data))

	} else {
		chksum := Blake2bOfBytes(bf.Data)
		if 0 != bytes.Compare(bf.Blake2b, chksum) {
			return bf, fmt.Errorf("RecvFile corruption detected: "+
				"bf.Data had checksum '%x', but expected '%x'",
				chksum, bf.Blake2b)
		}
	}
	return bf, err
}

func (sess *Session) SendFile(path string, writeme []byte, tm time.Time) (*BigFile, error) {
	bf := &BigFile{
		Filepath:    path,
		SendTime:    tm,
		SizeInBytes: int64(len(writeme)),
		Data:        writeme,
		Blake2b:     Blake2bOfBytes(writeme),
	}

	err := msgp.Encode(sess, bf)
	return bf, err
}

// SynAckAck is used as the encoded Data
// for EventSyn, EventSynAck, and EventEstabAck: connection setup.
type SynAckAck struct {

	// EventSyn => also conveys SessionNonce
	TcpEvent TcpEvent

	// SessionNonce identifies the file in this session (replaces port numbers).
	// Should always be present.  See NewSessionNonce() to generate.
	SessionNonce string

	// NextExpected should be 0 if fresh start;
	// i.e. we know nothing from prior evesdropping on
	// any prior multicast of this SessionNonce. Otherwise,
	// NextExpected and NackList convey knowledge of what we have
	// and don't have to allow the sender to skip
	// repeating the packets.
	//
	// This is the next serial number that the receiver has not received.
	//
	// Only present on TcpEvent == EventSynAck.
	NextExpected int64

	// NackList can be an empty slice.
	// Nacklist is a list of missing packets (on the receiver side) that we are aware of.
	// (Nack=negative acknowledgement).
	// Only present on TcpEvent == EventSynAck.
	NackList []int64
}

func NewSessionNonce() string {
	return cryrand.RandomStringWithUp(30)
}

// if not established, do the connect 3-way handshake
// to exchange Session nonces.
func (s *Session) ConnectIfNeeded(dest string, simulateLostSynCount int) error {

	s.SetConnectDefaults()
	to := s.ConnectTimeout
	if to == 0 {
		to = time.Minute
	}
	attempts := s.ConnectAttempts
	if attempts == 0 {
		attempts = 5
	}

	if s.RemoteSessNonce == "" {
		remoteNonce, err := s.Swp.Connect(dest, simulateLostSynCount, to, attempts)
		if err != nil {
			return err
		}
		s.RemoteSessNonce = remoteNonce
		return nil
	}
	return nil
}

// Connect takes an inbox (subject) as dest.
func (s *Session) Connect(dest string) error {
	return s.ConnectIfNeeded(dest, 0)
}

func (swp *SWP) Connect(dest string, simulateLostSynCount int, timeout time.Duration, attempts int) (remoteNonce string, err error) {
	return swp.Recver.Connect(dest, simulateLostSynCount, timeout, attempts)
}

type closeReq struct {
	done chan bool
}

func newCloseReq() *closeReq {
	return &closeReq{done: make(chan bool)}
}

func (sess *Session) Close() error {
	//p("%s sess Close() running, recv.TcpState=%s", sess.MyInbox, sess.Swp.Recver.TcpState)
	zr := newCloseReq()
	return sess.Swp.Recver.Close(zr)
}


text:
(function (HandsomeTrello) {
  'use strict';

  HandsomeTrello.api = {
    queue: [],

    running: false,

    request: function () {
      var self = this;

      if (!self.queue.length) {
        self.running = false;

        return false;
      }

      if (self.running) {
        return false;
      }

      self.running = true;

      var requestData = self.queue[0],
        xhttp = new XMLHttpRequest();

      if (typeof requestData.data !== 'object') {
        requestData.data = {};
      }

      if (requestData.type.toLowerCase() !== 'get') {
        requestData.data.token = HandsomeTrello.helpers.getCookie('token');
      } else if (Object.keys(requestData.data).length) {
        requestData.url += '?' + HandsomeTrello.helpers.generateGetParamsStringFromObject(requestData.data);

        requestData.data = {};
      }

      xhttp.open(requestData.type.toUpperCase(), requestData.url, true);
      xhttp.setRequestHeader('Content-Type', 'application/json');
      xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

      xhttp.onreadystatechange = function () {
        if (xhttp.readyState === 4) {
          if (xhttp.status === 200 && HandsomeTrello.helpers.isJSONString(xhttp.responseText)) {
            if (typeof requestData.callback === 'function') {
              requestData.callback(null, JSON.parse(xhttp.responseText));
            }
          } else {
            console.error('Request Error:', xhttp.status, xhttp.responseText || xhttp.statusText);

            if (typeof requestData.callback === 'function') {
              requestData.callback({
                code: xhttp.status,
                message: xhttp.statusText
              });
            }
          }

          self.queue.splice(0, 1);

          self.running = false;

          self.request();
        }
      };

      xhttp.send(JSON.stringify(requestData.data));
    },

    addToQueue: function (type, url, data, callback) {
      var self = this;

      self.queue.push({
        type: type,
        url: url,
        data: data,
        callback: callback
      });

      self.request();
    },

    board: {
      get: function (boardId, callback) {
        var self = this.base;

        self.addToQueue('get', 'https://trello.com/1/boards/' + boardId, {
          lists: 'open',
          cards: 'all',
          card_checklists: 'all',
          members: 'all'
        }, callback);
      }
    },

    card: {
      get: function (cardId, callback) {
        var self = this.base;

        self.addToQueue('get', 'https://trello.com/1/cards/' + cardId, {
          checklists: 'all'
        }, callback);
      },
      create: function (title, columnId, pos, callback) {
        var self = this.base;

        var data = {
          name: title,
          pos: pos,
          dateLastActivity: Date.now(),
          closed: false,
          idLabels: [],
          idMembers: [],
          idBoard: HandsomeTrello.data.boardId,
          idList: columnId
        };

        self.addToQueue('post', '/1/cards', data, callback);
      }
    },

    checklist: {
      getByCardId: function (cardId, callback) {
        var self = this.base;

        self.addToQueue('get', '/1/cards/' + cardId + '/checklists', {}, callback);
      },
      get: function (checklistId, callback) {
        var self = this.base;

        self.addToQueue('get', '/1/checklists/' + checklistId, {}, callback);
      },
      create: function (cardId, name, pos, callback) {
        var self = this.base;

        var data = {
          idCard: cardId,
          name: name,
          pos: pos
        };

        self.addToQueue('post', '/1/checklists', data, callback);
      },
      remove: function (checklistId, callback) {
        var self = this.base;

        self.addToQueue('delete', '/1/checklists/' + checklistId, {}, callback);
      },
      addItem: function (checklistId, name, pos, callback) {
        var self = this.base;

        var data = {
          name: name,
          pos: pos
        };

        self.addToQueue('post', '/1/checklists/' + checklistId + '/checkItems', data, callback);
      },
      deleteItem: function (checklistId, checkItemId, callback) {
        var self = this.base;

        var data = {
          idCheckItem: checkItemId
        };

        self.addToQueue('delete', '/1/checklists/' + checklistId + '/checkItems/' + checkItemId, data, callback);
      },
      nameItem: function (cardId, checklistId, checkItemId, name, callback) {
        var self = this.base;

        var data = {
          idChecklist: checklistId,
          idCheckItem: checkItemId,
          value: name
        };

        self.addToQueue('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/name', data, callback);
      },
      changeItemPos: function (cardId, checklistId, checkItemId, pos, callback) {
        var self = this.base;

        var data = {
          idChecklist: checklistId,
          idCheckItem: checkItemId,
          value: pos
        };

        self.addToQueue('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/pos', data, callback);
      }
    },

    member: {
      get: function (username, data, callback) {
        var self = this.base;

        self.addToQueue('get', '/1/members/' + username, data, callback);
      }
    }
  };

})(HandsomeTrello);

redpajama_set_name: RedPajamaGithub


text:
PEGASUS_USING_PEGASUS;
PEGASUS_USING_STD;

#include "UNIX_DirectorySpecificationFileProvider.h"

extern "C"
PEGASUS_EXPORT CIMProvider* PegasusCreateProvider(const String& providerName)
{
	if (String::equalNoCase(providerName, CIMHelper::EmptyString)) return NULL;
	else if (String::equalNoCase(providerName, "UNIX_DirectorySpecificationFileProvider")) return new UNIX_DirectorySpecificationFileProvider();
	return NULL;
}


text:
Database
-----------
user = postgres
database = jvdb
database type : postgresql

sudo -i -u postgres
to switch to postgres user

psql
to interact with postgresql

\list
to list all databases

\dt
to list all tables in current database

\connect jvdb
to connect to jvdb database

postgresql:///jvdb
jvdb is database
/// is local - so we don't have to supply password
postgresql is trype

psycog - needed

use sqlalchemy to connect to postgresql

backend - python/flask_sqlalchemy application
frontend - nodejs/angular2 application

python3 - for ubuntu
python - for windows

backend apis
------------

blogs: localhost:5000/api/blog
apps: localhost:5000/api/app
data: localhost:5000/api/data
misc: localhost:5000/api/misc

to fix npm and nodejs versions - just made new droplet and reinstall everything

fix issue with npm install --
use 'ln -s /usr/bin/nodejs /usr/bin/node'
issue was that it was running node instead of nodejs

backend
--------
sudo apt-get install python3-pip
pip3 install flask
pip3 install flask_sqlalchemy
pip3 install flask_cors
pip3 install sortedcontainers
sudo apt-get install postgresql
su postgres
psql
create database jvdb;
\q
su root
pip3 install flask_restless

To run without hangup
--------------------------
nohup npm start &
nohup python3 application.py &

to kill python3 process
------------------------
ps -fA | grep python3
second number is process number.
kill numb
you'll want to kill the one that isn't process numb=1

Files
-------
Files on server are in /home/jasonvila.com
This is because you can't access root folder with any other user
postgres user can't access root folder, thus can't run backend in root folder, have to run in home folder.

Changing Ports - frontend
--------------------------
To change ports or what can be served, change bs-config.json file.

To run frontend
---------------
npm install
nohup npm start &

To run backend
---------------
nohup python3 application.py &
python3 database_parser.py --> this is for inserting data in database.

Misc
------------
postgresql is already running in background. - user is postgres.

primeng is renderer for tables, want to edit this to make your own custom

fixed whole issue with css by add ViewEncapsulation.None in @Component

changed dynamic load with just using document.getElementById and changing the innerHTML.

Need to update database.

\n doesn't show up in html as new lines - just use br tag

using sortedcontainers.SortedDict for sorting the results.

to make flask public, just change application.run() to application.run(host='0.0.0.0') -- this fixes the cors issue. - also flask_cors - the cross origin can be fixed so that any website can request it.

To make Public
---------------
change bs-config.json to port 80
change application.py to run applicaiton on host='0.0.0.0'
change frontend/app/services/allServices.service.ts to from localhost urls to jasonvila.com urls.

To update database
------------------
update apps.json, data.json, miscs.json, blogs.json
run database_parser.py

To update database models
--------------------------
update models.py model classes
update database_parser.py

To add new Components
------------------------
Add new folder in components folder (named after your new component).
Create 3 files in new component folder.
new_component.component.ts file
new_component.html file
new_component.css file

Copy html, css, and ts file content from other component folders into these files
Update services/allServices.service.ts file if there are any new apis the new component needs
update app.module.ts to import, route (RouterModule), and declare (declarations) the component.

update app.js by running npm run build

To customize webpack
------------------------
entry - entry file that needs to be crawled for imports and combined into one js file.
output - the one js file being outputted to
module - the extension and the loader for that extension
resolve - the extensions to resolve with the following loaders.

To rebuild webpack
-----------------------
npm run build

To shutdown droplet
----------------------
sudo shutdown -h now


text:
package org.apache.oodt.product;

/**
 * Handle requests for products that are too large to fit in an {@link
 * org.apache.oodt.xmlquery.XMLQuery} object.
 *
 * @author Kelly
 * @version $Revision: 1.1.1.1 $
 */
public interface LargeProductQueryHandler extends QueryHandler {
	/**
	 * Retrieve a chunk of a product.
	 *
	 * The product is identified by a string ID.  The query handler should return a
	 * binary chunk of the product using the given offset and length.  If the ID isn't
	 * recognized, it should return null.  It should throw an exception if retrieval
	 * fails for some reason.
	 *
	 * @param id Product ID.
	 * @param offset Where in the product to get a chunk of it.
	 * @param length How much of the product to get.
	 * @return A chunk, or null if the <var>id</var> is unknown.
	 * @throws ProductException if an error occurs.
	 */
	byte[] retrieveChunk(String id, long offset, int length) throws ProductException;

	/**
	 * Close off a product.
	 *
	 * This method indicates that the product is no longer required and its resources
	 * can be freed by the query handler.  If the ID is unknown, no untoward action is
	 * required.  It should throw an exception if there is an error during the
	 * resource release (such as an {@link java.io.IOException} when closing a file.
	 *
	 * @param id Product ID.
	 * @throws ProductException if an error occurs.
	 */
	void close(String id);
}


text:
namespace extensions {

// Keys used in JSON representation of extensions.
namespace manifest_keys {
extern const char kNWJSInternalFlag[];
extern const char kNWJSInternalMainFilename[];
extern const char kNWJSInternalManifest[];
extern const char kNWJSContentVerifyFlag[];
extern const char kNWJSMain[];
extern const char kNWJSMixedContext[];
extern const char kNWJSEnableNode[];
extern const char kNWJSDomain[];

extern const char kAboutPage[];
extern const char kAction[];
extern const char kActionDefaultIcon[];
extern const char kActionDefaultPopup[];
extern const char kActionDefaultState[];
extern const char kActionDefaultTitle[];
extern const char kApp[];
extern const char kAutomation[];
extern const char kBackground[];
extern const char kBackgroundAllowJsAccess[];
extern const char kBackgroundPage[];
extern const char kBackgroundPersistent[];
extern const char kBackgroundScripts[];
extern const char kBackgroundServiceWorkerScript[];
extern const char kBackgroundServiceWorkerType[];
extern const char kBluetooth[];
extern const char kBookmarkUI[];
extern const char kBrowserAction[];
extern const char kBrowseURLs[];
extern const char kChromeOSSystemExtension[];
extern const char kCommands[];
extern const char kContentCapabilities[];
extern const char kContentSecurityPolicy[];
extern const char kContentSecurityPolicy_ExtensionPagesPath[];
extern const char kContentSecurityPolicy_IsolatedWorldPath[];
extern const char kContentSecurityPolicy_SandboxedPagesPath[];
extern const char kConvertedFromUserScript[];
extern const char kCurrentLocale[];
extern const char kDefaultLocale[];
extern const char kDescription[];
extern const char kDevToolsPage[];
extern const char kDifferentialFingerprint[];
extern const char kDisplayInLauncher[];
extern const char kDisplayInNewTabPage[];
extern const char kEventName[];
extern const char kExternallyConnectable[];
extern const char kEventRules[];
extern const char kFileAccessList[];
extern const char kFileHandlers[];
extern const char kFileHandlerExtensions[];
extern const char kFileHandlerIncludeDirectories[];
extern const char kFileHandlerTypes[];
extern const char kFileHandlerVerb[];
extern const char kFileFilters[];
extern const char kFileBrowserHandlerId[];
extern const char kFileBrowserHandlers[];
extern const char kGlobal[];
extern const char kHideBookmarkButton[];
extern const char kHomepageURL[];
extern const char kHostPermissions[];
extern const char kIcons[];
extern const char kId[];
extern const char kImeOptionsPage[];
extern const char kIndicator[];
extern const char kInputComponents[];
extern const char kInputView[];
extern const char kIsolation[];
extern const char kKey[];
extern const char kKiosk[];
extern const char kKioskAlwaysUpdate[];
extern const char kKioskEnabled[];
extern const char kKioskOnly[];
extern const char kKioskMode[];
extern const char kKioskRequiredPlatformVersion[];
extern const char kKioskSecondaryApps[];
extern const char kLanguage[];
extern const char kLaunch[];
extern const char kLaunchContainer[];
extern const char kLauncherPage[];
extern const char kLauncherPagePage[];
extern const char kLaunchHeight[];
extern const char kLaunchLocalPath[];
extern const char kLaunchWebURL[];
extern const char kLaunchWidth[];
extern const char kLayouts[];
extern const char kLinkedAppIcons[];
extern const char kLinkedAppIconURL[];
extern const char kLinkedAppIconSize[];
extern const char kManifestVersion[];
extern const char kInMainWorld[];
extern const char kMatches[];
extern const char kMIMETypes[];
extern const char kMimeTypesHandler[];
extern const char kMinimumChromeVersion[];
extern const char kNaClModules[];
extern const char kNaClModulesMIMEType[];
extern const char kNaClModulesPath[];
extern const char kName[];
extern const char kNativelyConnectable[];
extern const char kOfflineEnabled[];
extern const char kOmniboxKeyword[];
extern const char kOptionalHostPermissions[];
extern const char kOptionalPermissions[];
extern const char kOptionsPage[];
extern const char kOptionsUI[];
extern const char kOverrideHomepage[];
extern const char kOverrideSearchProvider[];
extern const char kOverrideStartupPage[];
extern const char kPageAction[];
extern const char kPermissions[];
extern const char kPlatformAppBackground[];
extern const char kPlatformAppBackgroundPage[];
extern const char kPlatformAppBackgroundScripts[];
extern const char kPlatformAppContentSecurityPolicy[];
extern const char kPublicKey[];
extern const char kRemoveButton[];
extern const char kReplacementAndroidApp[];
extern const char kReplacementWebApp[];
extern const char kSandboxedPages[];
extern const char kSandboxedPagesCSP[];
extern const char kSettingsOverride[];
extern const char kSettingsOverrideAlternateUrls[];
extern const char kShortName[];
extern const char kSockets[];
extern const char kStorageManagedSchema[];
extern const char kSuggestedKey[];
extern const char kSystemIndicator[];
extern const char kTheme[];
extern const char kThemeColors[];
extern const char kThemeDisplayProperties[];
extern const char kThemeImages[];
extern const char kThemeTints[];
extern const char kTtsEngine[];
extern const char kTtsEngineSampleRate[];
extern const char kTtsEngineBufferSize[];
extern const char kTtsVoices[];
extern const char kTtsVoicesEventTypeEnd[];
extern const char kTtsVoicesEventTypeError[];
extern const char kTtsVoicesEventTypeMarker[];
extern const char kTtsVoicesEventTypeSentence[];
extern const char kTtsVoicesEventTypeStart[];
extern const char kTtsVoicesEventTypeWord[];
extern const char kTtsVoicesEventTypes[];
extern const char kTtsVoicesGender[];
extern const char kTtsVoicesLang[];
extern const char kTtsVoicesRemote[];
extern const char kTtsVoicesVoiceName[];
extern const char kUpdateURL[];
extern const char kUrlHandlers[];
extern const char kUrlHandlerTitle[];
extern const char kUsbPrinters[];
extern const char kVersion[];
extern const char kVersionName[];
extern const char kWebURLs[];
extern const char kWebview[];
extern const char kWebviewName[];
extern const char kWebviewAccessibleResources[];
extern const char kWebviewPartitions[];
#if BUILDFLAG(IS_CHROMEOS)
extern const char kFileSystemProviderCapabilities[];
extern const char kActionHandlers[];
extern const char kActionHandlerActionKey[];
extern const char kActionHandlerEnabledOnLockScreenKey[];
#endif
}  // namespace manifest_keys

// Some values expected in manifests.
namespace manifest_values {

extern const char kActionCommandEvent[];
extern const char kApiKey[];
extern const char kBrowserActionCommandEvent[];
extern const char kIncognitoNotAllowed[];
extern const char kIncognitoSplit[];
extern const char kIncognitoSpanning[];
extern const char kIsolatedStorage[];
extern const char kKeybindingPlatformChromeOs[];
extern const char kKeybindingPlatformDefault[];
extern const char kKeybindingPlatformLinux[];
extern const char kKeybindingPlatformMac[];
extern const char kKeybindingPlatformWin[];
extern const char kKeyAlt[];
extern const char kKeyShift[];
extern const char kKeyCommand[];
extern const char kKeyCtrl[];
extern const char kKeyComma[];
extern const char kKeyDel[];
extern const char kKeyDown[];
extern const char kKeyHome[];
extern const char kKeyEnd[];
extern const char kKeyIns[];
extern const char kKeyLeft[];
extern const char kKeyMacCtrl[];
extern const char kKeyMediaNextTrack[];
extern const char kKeyMediaPlayPause[];
extern const char kKeyMediaPrevTrack[];
extern const char kKeyMediaStop[];
extern const char kKeyPgDwn[];
extern const char kKeyPgUp[];
extern const char kKeyPeriod[];
extern const char kKeyRight[];
extern const char kKeySearch[];
extern const char kKeySeparator[];
extern const char kKeySpace[];
extern const char kKeyTab[];
extern const char kKeyUp[];
extern const char kLaunchContainerPanelDeprecated[];
extern const char kLaunchContainerTab[];
extern const char kLaunchContainerWindow[];
extern const char kPageActionCommandEvent[];

}  // namespace manifest_values

// Error messages returned from extension installation.
namespace manifest_errors {

extern const char kActiveTabPermissionNotGranted[];
extern const char kAllURLOrActiveTabNeeded[];
extern const char kAppsNotEnabled[];
extern const char16_t kBackgroundPermissionNeeded[];
extern const char16_t kBackgroundRequiredForPlatformApps[];
extern const char kBackgroundSpecificationInvalidForManifestV3[];
extern const char kCannotAccessAboutUrl[];
extern const char kCannotAccessChromeUrl[];
extern const char kCannotAccessExtensionUrl[];
extern const char kCannotAccessPage[];
extern const char kCannotAccessPageWithUrl[];
extern const char kCannotChangeExtensionID[];
extern const char kCannotClaimAllHostsInExtent[];
extern const char kCannotClaimAllURLsInExtent[];
extern const char kCannotScriptGallery[];
extern const char kCannotScriptNtp[];
extern const char kCannotScriptSigninPage[];
extern const char kCannotUninstallManagedExtension[];
extern const char16_t kChromeStyleInvalidForManifestV3[];
extern const char kChromeVersionTooLow[];
extern const char kDeclarativeNetRequestPermissionNeeded[];
extern const char16_t kDefaultStateShouldNotBeSet[];
extern const char kDevToolsExperimental[];
extern const char kExpectString[];
extern const char kFileNotFound[];
extern const char kHasDifferentialFingerprint[];
extern const char16_t kInvalidAboutPage[];
extern const char16_t kInvalidAboutPageExpectRelativePath[];
extern const char kInvalidAction[];
extern const char16_t kInvalidActionDefaultIcon[];
extern const char16_t kInvalidActionDefaultPopup[];
extern const char16_t kInvalidActionDefaultState[];
extern const char16_t kInvalidActionDefaultTitle[];
extern const char16_t kInvalidBackground[];
extern const char16_t kInvalidBackgroundAllowJsAccess[];
extern const char16_t kInvalidBackgroundCombination[];
extern const char kInvalidBackgroundScript[];
extern const char16_t kInvalidBackgroundScripts[];
extern const char16_t kInvalidBackgroundServiceWorkerScript[];
extern const char16_t kInvalidBackgroundServiceWorkerType[];
extern const char16_t kInvalidBackgroundInHostedApp[];
extern const char16_t kInvalidBackgroundPersistent[];
extern const char kInvalidBackgroundPersistentInPlatformApp[];
extern const char16_t kInvalidBackgroundPersistentNoPage[];
extern const char kInvalidBrowserAction[];
extern const char kInvalidBrowseURL[];
extern const char kInvalidBrowseURLs[];
extern const char kInvalidChromeURLOverrides[];
extern const char16_t kInvalidCommandsKey[];
extern const char16_t kInvalidContentCapabilities[];
extern const char kInvalidContentCapabilitiesMatch[];
extern const char kInvalidContentCapabilitiesMatchOrigin[];
extern const char kInvalidContentCapabilitiesPermission[];
extern const char kInvalidCSPInsecureValueIgnored[];
extern const char kInvalidCSPInsecureValueError[];
extern const char kInvalidCSPMissingSecureSrc[];
extern const char kInvalidDefaultLocale[];
extern const char16_t kInvalidDefaultLocale16[];
extern const char16_t kInvalidDescription[];
extern const char16_t kInvalidDevToolsPage[];
extern const char16_t kInvalidDisplayInLauncher[];
extern const char16_t kInvalidDisplayInNewTabPage[];
extern const char kInvalidEmptyDictionary[];
extern const char kInvalidExcludeMatch[];
extern const char kInvalidExcludeMatches[];
extern const char kInvalidExportPermissions[];
extern const char kInvalidExportAllowlistString[];
extern const char16_t kInvalidFileAccessList[];
extern const char kInvalidFileAccessValue[];
extern const char kInvalidFileBrowserHandler[];
extern const char16_t kInvalidFileBrowserHandler16[];
extern const char16_t kInvalidFileBrowserHandlerId[];
extern const char kInvalidFileBrowserHandlerMissingPermission[];
extern const char16_t kInvalidFileFiltersList[];
extern const char kInvalidFileFilterValue[];
extern const char16_t kInvalidFileHandlers[];
extern const char16_t kInvalidFileHandlersTooManyTypesAndExtensions[];
extern const char kInvalidFileHandlerExtension[];
extern const char kInvalidFileHandlerExtensionElement[];
extern const char kInvalidFileHandlerIncludeDirectories[];
extern const char kInvalidFileHandlerNoTypeOrExtension[];
extern const char kInvalidFileHandlerType[];
extern const char kInvalidFileHandlerTypeElement[];
extern const char kInvalidFileHandlerVerb[];
extern const char kInvalidHomepageOverrideURL[];
extern const char kInvalidHomepageURL[];
extern const char kInvalidHostPermission[];
extern const char kInvalidHostPermissions[];
extern const char kInvalidIconKey[];
extern const char kInvalidIconPath[];
extern const char16_t kInvalidIcons[];
extern const char16_t kInvalidImportAndExport[];
extern const char kInvalidImportId[];
extern const char kInvalidImportVersion[];
extern const char kInvalidInputComponents[];
extern const char16_t kInvalidInputComponents16[];
extern const char kInvalidInputComponentLayoutName[];
extern const char kInvalidInputComponentName[];
extern const char kInvalidInputView[];
extern const char16_t kInvalidIsolation[];
extern const char kInvalidIsolationValue[];
extern const char16_t kInvalidKey[];
extern const char kInvalidKeyBinding[];
extern const char kInvalidKeyBindingDescription[];
extern const char kInvalidKeyBindingDictionary[];
extern const char kInvalidKeyBindingMediaKeyWithModifier[];
extern const char kInvalidKeyBindingMissingPlatform[];
extern const char kInvalidKeyBindingTooMany[];
extern const char kInvalidKeyBindingUnknownPlatform[];
extern const char16_t kInvalidKioskAlwaysUpdate[];
extern const char16_t kInvalidKioskEnabled[];
extern const char16_t kInvalidKioskOnly[];
extern const char16_t kInvalidKioskOnlyButNotEnabled[];
extern const char16_t kInvalidKioskRequiredPlatformVersion[];
extern const char16_t kInvalidKioskSecondaryApps[];
extern const char16_t kInvalidKioskSecondaryAppsBadAppEntry[];
extern const char kInvalidKioskSecondaryAppsDuplicateApp[];
extern const char kInvalidKioskSecondaryAppsPropertyUnavailable[];
extern const char kInvalidLauncherPage[];
extern const char kInvalidLauncherPagePage[];
extern const char16_t kInvalidLaunchContainer[];
extern const char kInvalidLaunchValue[];
extern const char kInvalidLaunchValueContainer[];
extern const char kInvalidLinkedAppIcon[];
extern const char kInvalidLinkedAppIconSize[];
extern const char kInvalidLinkedAppIconURL[];
extern const char kInvalidLinkedAppIcons[];
extern const char kInvalidManifest[];
extern const char kInvalidManifestKey[];
extern const char kInvalidManifestVersionMissingKey[];
extern const char kInvalidManifestVersionUnsupported[];
extern const char kInvalidMatch[];
extern const char kInvalidInMainWorld[];
extern const char kInvalidMatchCount[];
extern const char kInvalidMatches[];
extern const char16_t kInvalidMIMETypes[];
extern const char16_t kInvalidMimeTypesHandler[];
extern const char16_t kInvalidMinimumChromeVersion[];
extern const char16_t kInvalidNaClModules[];
extern const char kInvalidNaClModulesMIMEType[];
extern const char kInvalidNaClModulesPath[];
extern const char kInvalidName[];
extern const char16_t kInvalidName16[];
extern const char16_t kInvalidNativelyConnectable[];
extern const char kInvalidNativelyConnectableValue[];
extern const char16_t kInvalidNativelyConnectableValue16[];
extern const char16_t kInvalidOAuth2ClientId[];
extern const char16_t kInvalidOfflineEnabled[];
extern const char16_t kEmptyOmniboxKeyword[];
extern const char kInvalidOptionsUIChromeStyle[];
extern const char kInvalidOptionsUIOpenInTab[];
extern const char kInvalidOptionsPage[];
extern const char16_t kInvalidOptionsPageExpectUrlInPackage[];
extern const char16_t kInvalidOptionsPageInHostedApp[];
extern const char kInvalidPageAction[];
extern const char kInvalidPermission[];
extern const char kInvalidPermissions[];
extern const char kInvalidPermissionScheme[];
extern const char kInvalidPermissionWithDetail[];
extern const char16_t kInvalidReplacementAndroidApp[];
extern const char16_t kInvalidReplacementWebApp[];
extern const char kInvalidRulesetID[];
extern const char16_t kInvalidSandboxedPagesList[];
extern const char kInvalidSandboxedPage[];
extern const char kInvalidSearchEngineMissingKeys[];
extern const char kInvalidSearchEngineURL[];
extern const char16_t kInvalidShortName[];
extern const char kInvalidStartupOverrideURL[];
extern const char16_t kInvalidSystemIndicator[];
extern const char16_t kInvalidTheme[];
extern const char16_t kInvalidThemeColors[];
extern const char16_t kInvalidThemeImages[];
extern const char kInvalidThemeImagesMissing[];
extern const char16_t kInvalidThemeTints[];
extern const char16_t kInvalidTts[];
extern const char16_t kInvalidTtsSampleRateFormat[];
extern const char kInvalidTtsSampleRateRange[];
extern const char16_t kInvalidTtsBufferSizeFormat[];
extern const char kInvalidTtsBufferSizeRange[];
extern const char16_t kInvalidTtsRequiresSampleRateAndBufferSize[];
extern const char16_t kInvalidTtsVoices[];
extern const char16_t kInvalidTtsVoicesEventTypes[];
extern const char kInvalidTtsVoicesGender[];
extern const char16_t kInvalidTtsVoicesLang[];
extern const char16_t kInvalidTtsVoicesRemote[];
extern const char16_t kInvalidTtsVoicesVoiceName[];
extern const char kInvalidUpdateURL[];
extern const char kInvalidURLPatternError[];
extern const char16_t kInvalidURLHandlers[];
extern const char kInvalidURLHandlerPatternElement[];
extern const char16_t kInvalidURLHandlerPatternElement16[];
extern const char16_t kInvalidURLHandlerTitle[];
extern const char kInvalidURLHandlerPattern[];
extern const char16_t kInvalidVersion[];
extern const char16_t kInvalidVersionName[];
extern const char kInvalidWebAccessibleResourcesList[];
extern const char kInvalidWebAccessibleResource[];
extern const char kInvalidSidePanel[];
extern const char16_t kInvalidWebview[];
extern const char16_t kInvalidWebviewAccessibleResourcesList[];
extern const char kInvalidWebviewAccessibleResource[];
extern const char kInvalidWebviewPartition[];
extern const char kInvalidWebviewPartitionName[];
extern const char16_t kInvalidWebviewPartitionsList[];
extern const char kInvalidWebURL[];
extern const char kInvalidWebURLs[];
extern const char kInvalidZipHash[];
extern const char kKeyIsDeprecatedWithReplacement[];
extern const char kLauncherPagePageRequired[];
extern const char16_t kLaunchPathAndExtentAreExclusive[];
extern const char16_t kLaunchPathAndURLAreExclusive[];
extern const char16_t kLaunchURLRequired[];
extern const char kLocalesInvalidLocale[];
extern const char16_t kLocalesMessagesFileMissing[];
extern const char kLocalesNoDefaultMessages[];
extern const char kLocalesNoValidLocaleNamesListed[];
extern const char kLocalesTreeMissing[];
extern const char kManifestParseError[];
extern const char kManifestUnreadable[];
extern const char kManifestV2IsDeprecatedWarning[];
extern const char kManifestVersionTooHighWarning[];
extern const char kMatchOriginAsFallbackCantHavePaths[];
extern const char kMatchOriginAsFallbackRestrictedToMV3[];
extern const char kMissingFile[];
extern const char16_t kMultipleOverrides[];
extern const char kNoWildCardsInPaths[];
extern const char16_t kNPAPIPluginsNotSupported[];
extern const char16_t kOneUISurfaceOnly[];
extern const char kPageCaptureNeeded[];
extern const char kPermissionCannotBeOptional[];
extern const char kPermissionMarkedOptionalAndRequired[];
extern const char kPermissionNotAllowed[];
extern const char kPermissionNotAllowedInManifest[];
extern const char kPermissionUnknownOrMalformed[];
extern const char kPluginsRequirementDeprecated[];
extern const char kReservedMessageFound[];
extern const char16_t kSandboxPagesCSPKeyNotAllowed[];
extern const char kRulesFileIsInvalid[];
extern const char kRulesetCountExceeded[];
extern const char kEnabledRulesetCountExceeded[];
extern const char kSidePanelManifestDefaultPathError[];
extern const char16_t kTransientBackgroundConflictsWithPersistentBackground[];
extern const char kTtsGenderIsDeprecated[];
extern const char kUnrecognizedManifestKey[];
extern const char kUnrecognizedManifestProperty[];
extern const char16_t kWebRequestConflictsWithLazyBackground[];
#if BUILDFLAG(IS_CHROMEOS)
extern const char16_t kInvalidFileSystemProviderMissingCapabilities[];
extern const char kInvalidFileSystemProviderMissingPermission[];
extern const char kDuplicateActionHandlerFound[];
extern const char kIllegalPlugins[];
extern const char16_t kInvalidActionHandlerDictionary[];
extern const char kInvalidActionHandlersActionType[];
extern const char16_t kInvalidActionHandlersType[];
#endif

}  // namespace manifest_errors

}  // namespace extensions

#endif  // EXTENSIONS_COMMON_MANIFEST_CONSTANTS_H_


text:
FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y curl

# CHANGEME: Create the files that correspond to your configuration in the conf directory
# COPY conf/net/auth/google_auth.json /usr/src/app/conf/net/auth/google_auth.json
COPY start_script.sh /start_script.sh

CMD ["/bin/bash", "/start_script.sh"]


text:
/*

Template:  AppTech
Author:bootexperts.com
Version: 1
Developed by: bootexperts.com

NOTE: This is Style customizer stylesheet of template.

*/

#main-menu.stick {
    background: #009688 none repeat scroll 0 0;
}
.bg-oapcity-40::before {
    background: #009688 none repeat scroll 0 0;
}
.single-item:hover i {
    background-color: #009688;
}
.about-icon li a i:hover {
    color: #009688;
}
.single-features-list:hover .feature-list-icon i,
.single-features-list2:hover .feature-list-icon2 i {
    background-color: #009688;
}
.video-popup:hover {
    border: 5px solid #009688;
}
.video-popup:hover i {
    color: #009688;
}
.sauget-accordion .panel-heading h4 a {
    background: #009688 none repeat scroll 0 0;
}
.slick-dots li.slick-active button {
    border: 3px solid #009688;
}
.slider-2 .slick-dots li.slick-active button {
    border: 3px solid #009688;
}
.single-price-package:hover .button,
.single-price-package:hover .price,
.single-price-package.active .button,
.single-price-package.active .price {
    background-color: #009688;
}
.counter:hover .icon-coun i {
    background-color: #009688;
}
.subscribe-form form button i {
    color: #009688;
}
input.submit:hover {
    background-color: #009688;
    border: 1px solid #009688;
}
.contact-from input:focus,
.contact-from textarea:focus {
    border-color: #009688;
}
.single-contact-info:hover .contact-icon {
    border: 1px solid #009688;
    background-color: #009688;
}
.footer-icon a:hover {
    border: 1px solid #009688;
    background-color: #009688;
}
.footer-text span a:hover {
    color: #009688;
}
#toTop i:hover {
    background-color: #009688;
}
.contact-text > span a:hover {
  color: #009688;
}


text:
ActionController::Routing::Routes.draw do |map|
  map.connect '/post_pipelines/help', :controller=>:post_pipelines, :action=>:help
  map.resources :post_pipelines, :member=>{:launch=>:get}
  map.resources :rnaseq_pipelines
end


text:
package com.enioka.jqm.tools;

import org.junit.Assert;
import org.junit.Test;

import com.enioka.jqm.api.JobRequest;
import com.enioka.jqm.test.helpers.CreationTools;
import com.enioka.jqm.test.helpers.TestHelpers;

public class EngineCLIsolationTest extends JqmBaseTest
{

    /**
     * Create JobDef corresponding to TestCLIsolation.TestSet and submit it to queue
     */
    void createSubmitSetJob(String specificIsolationContext)
    {
        CreationTools.createJobDef(null, true, "com.enioka.jqm.TestCLIsolation.TestSet", null,
                "jqm-tests/jqm-test-cl-isolation/target/test.jar", TestHelpers.qVip, -1, "TestSet", null, null, null, null, null, false,
                cnx, specificIsolationContext);
        JobRequest.create("TestSet", null).submit();
    }

    /**
     * Create JobDef corresponding to TestCLIsolation.TestGet and submit it to queue
     */
    void createSubmitGetJob(String specificIsolationContext)
    {
        CreationTools.createJobDef(null, true, "com.enioka.jqm.TestCLIsolation.TestGet", null,
                "jqm-tests/jqm-test-cl-isolation/target/test.jar", TestHelpers.qVip, -1, "TestGet", null, null, null, null, null, false,
                cnx, specificIsolationContext);
        JobRequest.create("TestGet", null).submit();
    }

    /**
     * Run test without any change in the default configuration (i.e. jobs are isolated).
     *
     * Expected : isolation
     */
    @Test
    public void testDefault() throws Exception
    {
        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob(null);
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(2, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test setting global parameter launch_isolation_default to Isolated.
     *
     * Expected : Isolation
     */
    @Test
    public void testGlobalIsolated() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "Isolated", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob(null);
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(2, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test setting global parameter launch_isolation_default to SharedJar with two jobs inside the same jar.
     *
     * Expected : shared CL
     */
    @Test
    public void testGlobalSharedJarSame() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "SharedJar", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob(null);
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(1, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test setting global parameter launch_isolation_default to SharedJar with two jobs in different jars.
     *
     * Expected : isolation
     */
    @Test
    public void testGlobalSharedJarDifferent() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "SharedJar", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        // Use get job from test-pyl jar
        CreationTools.createJobDef(null, true, "pyl.EngineCLIsolationGet", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip,
                -1, "EngineCLIsolationGet", null, null, null, null, null, false, cnx);
        JobRequest.create("EngineCLIsolationGet", null).submit();
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(2, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test setting global parameter launch_isolation_default to Shared with two jobs in the same jar.
     *
     * Expected : shared CL
     */
    @Test
    public void testGlobalSharedSame() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "Shared", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob(null);
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(1, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test setting global parameter launch_isolation_default to Shared with two jobs in the different jars.
     *
     * Expected : shared CL
     */
    @Test
    public void testGlobalSharedDifferent() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "Shared", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob(null);
        TestHelpers.waitFor(1, 10000, cnx);
        // Use get job from test-pyl jar
        CreationTools.createJobDef(null, true, "pyl.EngineCLIsolationGet", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip,
                -1, "EngineCLIsolationGet", null, null, null, null, null, false, cnx);
        JobRequest.create("EngineCLIsolationGet", null).submit();
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(1, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test using JobDef parameter specific_isolation_context with two jobs with same specific_isolation_context values using default
     * engine parameters.
     *
     * Expected : shared CL
     */
    @Test
    public void testJobDefSpecificSame() throws Exception
    {
        addAndStartEngine();

        createSubmitSetJob("test");
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob("test");
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(1, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test using JobDef parameter specific_isolation_context with two jobs using different specific_isolation_context values using
     * default engine parameters.
     *
     * Expected : isolation
     */
    @Test
    public void testJobDefSpecificDifferentDefault() throws Exception
    {
        addAndStartEngine();

        createSubmitSetJob("test1");
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob("test2");
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(2, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Run test using JobDef parameter specific_isolation_context with two jobs using different specific_isolation_context values setting
     * launch_isolation_default to Shared.
     *
     * Expected : isolation
     */
    @Test
    public void testJobDefSpecificDifferentShared() throws Exception
    {
        Helpers.setSingleParam("launch_isolation_default", "Shared", cnx);
        cnx.commit();

        addAndStartEngine();

        createSubmitSetJob("test1");
        TestHelpers.waitFor(1, 10000, cnx);
        createSubmitGetJob("test2");
        TestHelpers.waitFor(2, 10000, cnx);

        Assert.assertEquals(2, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }

    /**
     * Tests that using a static field for the JobManager API works even with shared CL, but shows a warning.
     */
    @Test
    public void testJobDefSharedWithStaticJobManagerField() throws Exception
    {
        CreationTools.createJobDef(null, true, "pyl.EngineApiStaticInjection", null, "jqm-tests/jqm-test-pyl/target/test.jar",
                TestHelpers.qVip, -1, "TestSet", null, null, null, null, null, false, cnx, "mycontext");

        JobRequest.create("TestSet", null).submit();

        addAndStartEngine();
        TestHelpers.waitFor(1, 10000, cnx);

        Assert.assertEquals(1, TestHelpers.getOkCount(cnx));
        Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx));
    }
}


text:
package com.ibm.spark.comm

import java.util.UUID

import com.ibm.spark.kernel.protocol.v5
import com.ibm.spark.kernel.protocol.v5._
import com.ibm.spark.kernel.protocol.v5.content._
import org.mockito.Matchers.{eq => mockEq, _}
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FunSpec, BeforeAndAfter, Matchers}

class CommWriterSpec extends FunSpec with Matchers with BeforeAndAfter
  with MockitoSugar
{
  private val TestCommId = UUID.randomUUID().toString

  class TestCommWriter extends CommWriter(TestCommId) {
    // Stub this implementation to do nothing
    override protected[comm] def sendCommKernelMessage[
      T <: KernelMessageContent with CommContent
    ](commContent: T): Unit = {}
  }

  private var commWriter: CommWriter = _

  before {
    commWriter = spy(new TestCommWriter())
  }

  describe("CommWriter") {
    describe("#writeOpen") {
      it("should package a CommOpen instance") {
        commWriter.writeOpen("")

        verify(commWriter).sendCommKernelMessage(any[CommOpen])
      }

      it("should include the comm_id in the message") {
        val expected = TestCommId
        commWriter.writeOpen("")

        verify(commWriter).sendCommKernelMessage(
          CommOpen(comm_id = expected, target_name = "", data = MsgData.Empty))
      }

      it("should include the target name in the message") {
        val expected = "<TARGET_NAME>"
        commWriter.writeOpen(expected)

        verify(commWriter).sendCommKernelMessage(
          CommOpen(
            comm_id = TestCommId, target_name = expected, data = MsgData.Empty
          )
        )
      }

      it("should provide empty data in the message if no data is provided") {
        val expected: v5.MsgData = MsgData.Empty
        commWriter.writeOpen("")

        verify(commWriter).sendCommKernelMessage(
          CommOpen(comm_id = TestCommId, target_name = "", data = expected))
      }

      it("should include the data in the message") {
        val expected = MsgData("message" -> "a", "foo" -> "bar")
        commWriter.writeOpen("", expected)

        verify(commWriter).sendCommKernelMessage(
          CommOpen(comm_id = TestCommId, target_name = "", data = expected))
      }
    }

    describe("#writeMsg") {
      it("should send a comm_msg message to the relay") {
        commWriter.writeMsg(MsgData.Empty)

        verify(commWriter).sendCommKernelMessage(any[CommMsg])
      }

      it("should include the comm_id in the message") {
        val expected = TestCommId
        commWriter.writeMsg(MsgData.Empty)

        verify(commWriter).sendCommKernelMessage(
          CommMsg(comm_id = expected, data = MsgData.Empty))
      }

      it("should fail a require if the data is null") {
        intercept[IllegalArgumentException] {
          commWriter.writeMsg(null)
        }
      }

      it("should include the data in the message") {
        val expected = MsgData("message" -> "a")
        commWriter.writeMsg(expected)

        verify(commWriter).sendCommKernelMessage(
          CommMsg(comm_id = TestCommId, data = expected))
      }
    }

    describe("#writeClose") {
      it("should send a comm_close message to the relay") {
        commWriter.writeClose()

        verify(commWriter).sendCommKernelMessage(any[CommClose])
      }

      it("should include the comm_id in the message") {
        val expected = TestCommId
        commWriter.writeClose()

        verify(commWriter).sendCommKernelMessage(
          CommClose(comm_id = expected, data = MsgData.Empty))
      }

      it("should provide empty data in the message if no data is provided") {
        val expected: v5.MsgData = MsgData.Empty
        commWriter.writeClose()

        verify(commWriter).sendCommKernelMessage(
          CommClose(comm_id = TestCommId, data = expected))
      }

      it("should include the data in the message") {
        val expected = MsgData("message" -> "a")
        commWriter.writeClose(expected)

        verify(commWriter).sendCommKernelMessage(
          CommClose(comm_id = TestCommId, data = expected))
      }
    }

    describe("#write") {
      it("should send a comm_msg message to the relay") {
        commWriter.write(Array('a'), 0, 1)

        verify(commWriter).sendCommKernelMessage(any[CommMsg])
      }

      it("should include the comm_id in the message") {
        val expected = TestCommId
        val messageData = MsgData("message" -> "a")
        commWriter.write(Array('a'), 0, 1)

        verify(commWriter).sendCommKernelMessage(
          CommMsg(comm_id = expected, data = messageData))
      }

      it("should package the string as part of the data with a 'message' key") {
        val expected = MsgData("message" -> "a")
        commWriter.write(Array('a'), 0, 1)

        verify(commWriter).sendCommKernelMessage(
          CommMsg(comm_id = TestCommId, data = expected))
      }
    }

    describe("#flush") {
      it("should do nothing") {
        // TODO: Is this test necessary? It does nothing.
        commWriter.flush()
      }
    }

    describe("#close") {
      it("should send a comm_close message to the relay") {
        commWriter.close()

        verify(commWriter).sendCommKernelMessage(any[CommClose])
      }

      it("should include the comm_id in the message") {
        val expected = TestCommId
        commWriter.close()

        verify(commWriter).sendCommKernelMessage(
          CommClose(comm_id = expected, data = MsgData.Empty))
      }

      it("should provide empty data in the message") {
        val expected: v5.MsgData = MsgData.Empty
        commWriter.close()

        verify(commWriter).sendCommKernelMessage(
          CommClose(comm_id = TestCommId, data = expected))
      }
    }
  }
}


text:
package com.worthed.framework;

/**
 * 后台任务管理器(异步任务管理器)
 * Created by jingle1267@163.com on 14-9-28.
 */
public class ServiceTaskManager {

    private static ClientTaskManager instance;

    public synchronized static ClientTaskManager instance() {
        if (instance == null) {
            instance = new ClientTaskManager();
        }
        return instance;
    }

}


text:
require 'sidekiq'
require 'sidekiq/api'

require_relative 'adapter_api_stats'
require_relative 'adapter_api_state'
require_relative 'adapter_api_logging'
require_relative 'adapter_api_cleanup'

module ActiveJob
  module Unique
    module Adapters
      module SidekiqAdapter
        class AdapterApi
          include ActiveJob::Unique::ApiBase
          include ActiveJob::Unique::Adapters::SidekiqAdapter::AdapterApiStats
          include ActiveJob::Unique::Adapters::SidekiqAdapter::AdapterApiState
          include ActiveJob::Unique::Adapters::SidekiqAdapter::AdapterApiLogging
          include ActiveJob::Unique::Adapters::SidekiqAdapter::AdapterApiCleanup

          class << self
            def another_job_in_queue?(queue_name, enqueued_at)
              queue = Sidekiq::Queue.new(queue_name)
              return false if queue.size.zero?

              queue.latency > (Time.now.utc.to_f - enqueued_at)
            end

            def another_job_in_worker?(job_name, queue_name, uniqueness_id, job_id)
              Sidekiq::Workers.new.any? {|_p, _t, w| w['queue'] == queue_name && w['payload']['wrapped'] == job_name && w['payload']['args'][0]['uniqueness_id'] == uniqueness_id && w['payload']['args'][0]['job_id'] != job_id }
            end
          end

        end
      end
    end
  end
end


text:
package org.n52.iceland.statistics.generator;

import static java.util.stream.Collectors.groupingBy;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.n52.iceland.statistics.api.mappings.MetadataDataMapping;
import org.n52.iceland.statistics.api.mappings.ServiceEventDataMapping;
import org.n52.iceland.statistics.api.parameters.AbstractEsParameter;
import org.n52.iceland.statistics.api.parameters.Description.InformationOrigin;
import org.n52.iceland.statistics.api.parameters.Description.Operation;
import org.n52.iceland.statistics.generator.formats.MdFormat;

import com.google.common.io.Files;

public class ParameterGenerator {

    private static String outputFilePath = "PARAMETER.MD";

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        if (args.length >= 2) {
            outputFilePath = args[0];
            ParameterGenerator gen = new ParameterGenerator();
            List<Class<?>> processClasses = new ArrayList<>(args.length+1);
            for (int i = 1; i < args.length; i++) {
                processClasses.add(Class.forName(args[i]));
            }
            processClasses.add(MetadataDataMapping.class);
            processClasses.add(ServiceEventDataMapping.class);
            gen.processClass(processClasses);
        } else {
            // throw new IllegalArgumentException(String.format("Usage %s [%s]",
            // "..\\PARAMETERS.MD", "SosDataMapping"));
            System.out.println("Application's DataMapping class is not specified. Add the class name of your data mapping class.");
            System.out.println(String.format("Usage java -jar statistics-kibana %s [%s]", "..\\PARAMETERS.MD", "SosDataMapping"));
        }
    }

    public void processClass(List<Class<?>> classes) throws IOException {
        MdFormat formatter = new MdFormat();
        formatter.setParameters(getParameters(classes));
        String printable = formatter.create();
        // System.out.println(printable);
        try {
            Files.write(printable, new File(outputFilePath), Charset.forName("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }

    private Map<Operation, Map<InformationOrigin, List<AbstractEsParameter>>> getParameters(List<Class<?>> classes) {
        return classes.stream()
                .map(Class::getFields)
                .flatMap(Arrays::stream)
                .map(this::getFieldValue)
                .filter(Objects::nonNull)
                .filter(AbstractEsParameter::hasDescription)
                .collect(groupingBy(l -> l.getDescription().getOperation(),
                                            groupingBy(l -> l.getDescription().getInformationOrigin())));
    }

    private AbstractEsParameter getFieldValue(Field field) {
        if (Modifier.isFinal(field.getModifiers()) &&
            Modifier.isStatic(field.getModifiers()) &&
            Modifier.isPublic(field.getModifiers()) &&
            field.getType().isAssignableFrom((AbstractEsParameter.class))) {
            try {
                return (AbstractEsParameter) field.get(null);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}


text:
[![Build Status](https://travis-ci.org/fastest963/portluck.svg?branch=master)](https://travis-ci.org/fastest963/portluck)

Accepts arbitrary data on a single port via HTTP, HTTPS, WebSockets, or a TCP socket. Optimally data
should be delimited by a `\n` character to speed up connection detection (read below).

Since we're sniffing for the connection type you will need to send at **least** 3 bytes over a raw TCP
socket in order to trigger a `message` event. If those 3 bytes happen to match the beginning of a valid HTTP
method we additionally wait for `\r` or `\n` to determine that it is/isn't an HTTP request.

## portluck.Server ##

### new portluck.Server([messageCallback][, options]) ###
Creates a new server that inherits [https.Server](https://nodejs.org/api/https.html#https_class_https_server).
If `messageCallback` is sent, it will be added as a listener for `"message"` event. See bottom for `options`.

### Event: 'message' ###
Fired when a client sends a message. Event is sent `(message, writer, socket, source)`. `message` is a buffer containing
the message received. `writer` is an instance of `ResponseWriter` and can be used to respond to the message.
`socket` is the source socket that sent the message. You should only read properties off the socket, like
`remoteAddress` and not use the `write`/`end` methods. `source` is either a `net.Socket` or a `http.IncomingMessage`.

### Event: 'clientConnect' ###
Fired when a client connects. Event is sent `(writer, socket, source)`. You should only read properties off the socket,
like `remoteAddress` and not use the `write`/`end` methods. `writer` is an instance of `ResponseWriter` can be
used to respond. The `writer` has `write`, `end`, and `destroy` methods. `source` is either a `net.Socket` or a
`http.IncomingMessage`.

### Event: 'clientDisconnect' ###
Fired when a client disconnects. Event is sent `socket` which is the socket that disconnected.

### Event: 'clientError' ###
Fired when there's an error emitted from a client. Event is sent `(error, socket)`.

### server.listen(port [,callback]) ###
Accepts the same parameters and options as [http.Server.listen](http://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback).

## ResponseWriter ##

### writer.write(message) ###
Writes `message` to the underlying source socket. `message` can be a string or Buffer. If you plan on
responding to messages asynchronously, you should call `endAfterWrite` since HTTP/HTTPS requests are
automatically closed on the next tick (unless you sent `explicitEnd` option).

### writer.endAfterWrite() ###
If an automatic `end()` is scheduled to happen next tick, calling `doneAfterWrite` prevents that from
happening and waits to automatically call `end()` until the next `write()`. This is not needed if you created
the server with the `explicitEnd` option.

### writer.end([message]) ###
Writes `message`, if passed, to the underlying source socket. If the source was a HTTP/HTTPS request, it is
`end`ed and a response is sent. No more writes are allowed on this writer. If the request was already terminated
on the client side then `message` will be silently dropped and not sent.

### writer.close() ###
Closes (by sending a FIN) the underlying source socket. No more writes are allowed on this writer.

### writer.destroy() ###
Immediately closes the underlying source socket. Similar to `socket.destroy()` No more writes are allowed
on this writer.

## Options ##

### rawFallback ###
Boolean for whether we should fallback to a raw socket connetion if http/tls/websocket isn't detected.

### timeout ###
See [net.Server.timeout](https://nodejs.org/api/http.html#http_server_timeout). Defaults to 2 minutes.
Note: We wait 1 second to try and wait for bytes to determine what type of connection it is. Your `timeout`
applies AFTER that if no data is sent immediately.

### allowOrigin ###
Origin to respond with `Allow-Access-Control-Origin` for. Value can be a string or RegExp. String values can
contain a single `*` for wildcard matching `[a-zA-Z0-9_-]`. **Do not add a protocol (like `https://`).**
Note: `*.example.com` is special and matches `example.com`, `www.example.com`, and `www.staging.example.com`.
Note 2: A origin ending in `:*` will allow any ports. So `example.com:*` would match `example.com` and
`example.com:4000`.

### allowUndefinedOrigin ###
Automatically allow a request if the origin is undefined. You usually want this to be true since browsers only
don't send origin headers for same-domain requests. Defaults to true. If this is false, then the undefined
origin will be passed to `allowOrigin` function/regex.

### explicitEnd ###
If set to `true` you are **required** to call `writer.end()` on every message received. By default, messages are
ended on the nextTick after firing `'message'` event.

### messageLimit ###
Maximum number of bytes per message. This is also the max size of the buffer when sniffing for connection type.
Defaults to 0, which means no limit.

## Todo ##

* Support UDP sockets as well

By [James Hartig](https://github.com/fastest963/)


text:
package org.apache.druid.query.lookup;

import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.inject.Injector;
import com.google.inject.Key;
import org.apache.druid.guice.ExpressionModule;
import org.apache.druid.guice.GuiceInjectors;
import org.apache.druid.guice.annotations.Json;
import org.apache.druid.initialization.DruidModule;
import org.apache.druid.math.expr.ExprMacroTable;
import org.apache.druid.query.dimension.DimensionSpec;
import org.apache.druid.query.dimension.ExtractionDimensionSpec;
import org.apache.druid.query.filter.DimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.segment.VirtualColumn;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.transform.ExpressionTransform;
import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class LookupSerdeModuleTest
{
  private Injector injector;
  private ObjectMapper objectMapper;

  @Before
  public void setUp()
  {
    final ImmutableList<DruidModule> modules = ImmutableList.of(
        new ExpressionModule(),
        new LookupSerdeModule()
    );

    injector = GuiceInjectors.makeStartupInjectorWithModules(modules);
    objectMapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
    objectMapper.setInjectableValues(
        new InjectableValues.Std()
            .addValue(ExprMacroTable.class, injector.getInstance(ExprMacroTable.class))
            .addValue(
                LookupExtractorFactoryContainerProvider.class,
                injector.getInstance(LookupExtractorFactoryContainerProvider.class)
            )
    );
    modules.stream().flatMap(module -> module.getJacksonModules().stream()).forEach(objectMapper::registerModule);
  }

  @Test
  public void testExpressionVirtualColumnSerde() throws Exception
  {
    final ExpressionVirtualColumn virtualColumn = new ExpressionVirtualColumn(
        "v",
        "lookup(xxx, 'beep')",
        ValueType.STRING,
        injector.getInstance(ExprMacroTable.class)
    );

    Assert.assertEquals(
        virtualColumn,
        objectMapper.readValue(objectMapper.writeValueAsBytes(virtualColumn), VirtualColumn.class)
    );
  }

  @Test
  public void testExtractionDimensionSerde() throws Exception
  {
    final ExtractionDimensionSpec dimensionSpec = new ExtractionDimensionSpec(
        "xxx",
        "d",
        new RegisteredLookupExtractionFn(null, "beep", false, null, null, null)
    );

    Assert.assertEquals(
        dimensionSpec,
        objectMapper.readValue(objectMapper.writeValueAsBytes(dimensionSpec), DimensionSpec.class)
    );
  }

  @Test
  public void testExtractionFilterSere() throws Exception
  {
    final SelectorDimFilter filter = new SelectorDimFilter(
        "xxx",
        "d",
        new RegisteredLookupExtractionFn(null, "beep", false, null, null, null)
    );

    Assert.assertEquals(
        filter,
        objectMapper.readValue(objectMapper.writeValueAsBytes(filter), DimFilter.class)
    );
  }

  @Test
  public void testExpressionTransformSerde() throws Exception
  {
    final ExpressionTransform transform = new ExpressionTransform(
        "xxx",
        "lookup(xxx, 'beep')",
        injector.getInstance(ExprMacroTable.class)
    );

    Assert.assertEquals(
        transform,
        objectMapper.readValue(objectMapper.writeValueAsBytes(transform), ExpressionTransform.class)
    );
  }
}


text:
import base64
import requests
import StringIO
import json
from pyvcloud.schema.vcd.v1_5.schemas.vcloud import sessionType, organizationType

class VCS(object):

    def __init__(self, url, username, org, instance, api_url, org_url, version='5.7', verify=True):
        self.url = url
        self.username = username
        self.token = None
        self.org = org
        self.instance = instance
        self.version = version
        self.verify = verify
        self.api_url = api_url
        self.org_url = org_url
        self.organization = None
        self.response = None

    def get_vcloud_headers(self):
        headers = {}
        headers["x-vcloud-authorization"] = self.token
        headers["Accept"] = "application/*+xml;version=" + self.version
        return headers

    def login(self, password=None, token=None):
        if token:
            headers = {}
            headers["x-vcloud-authorization"] = token
            headers["Accept"] = "application/*+xml;version=" + self.version
            self.response = requests.get(self.org_url, headers=headers, verify=self.verify)
            if self.response.status_code == requests.codes.ok:
                self.token = token
                self.organization = organizationType.parseString(self.response.content, True)
                return True
            else:
                return False
        else:
            encode = "Basic " + base64.standard_b64encode(self.username + "@" + self.org + ":" + password)
            headers = {}
            headers["Authorization"] = encode.rstrip()
            headers["Accept"] = "application/*+xml;version=" + self.version
            self.response = requests.post(self.url, headers=headers, verify=self.verify)
            if self.response.status_code == requests.codes.ok:
                self.token = self.response.headers["x-vcloud-authorization"]
                session = sessionType.parseString(self.response.content, True)
                self.org_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.org+xml', session.Link)[0].href
                return True
            else:
                return False


text:
#include <memory>
#include <utility>

#include "absl/memory/memory.h"
#include "tensorflow/compiler/xla/client/xla_builder.h"
#include "tensorflow/compiler/xla/literal_util.h"
#include "tensorflow/compiler/xla/service/cpu/custom_call_target_registry.h"
#include "tensorflow/compiler/xla/service/hlo_computation.h"
#include "tensorflow/compiler/xla/service/hlo_instruction.h"
#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/hlo_opcode.h"
#include "tensorflow/compiler/xla/shape_util.h"
#include "tensorflow/compiler/xla/tests/client_library_test_base.h"
#include "tensorflow/compiler/xla/tests/hlo_test_base.h"
#include "tensorflow/compiler/xla/tests/literal_test_util.h"
#include "tensorflow/compiler/xla/tests/test_macros.h"
#include "tensorflow/compiler/xla/xla_data.pb.h"
#include "tensorflow/core/platform/dynamic_annotations.h"
#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/platform/test.h"

namespace {
void R0F32Add2(float* out, float** in) {
  TF_ANNOTATE_MEMORY_IS_INITIALIZED(in, sizeof(float*));
  *out = **in + 2.0f;
}

void R2F32ReduceSum(float* out, float** in) {
  TF_ANNOTATE_MEMORY_IS_INITIALIZED(in, sizeof(float) * 4);
  float* array = in[0];
  *out = array[0] + array[1] + array[2] + array[3];
}

void Add1ToValues(float* out, float** in) {
  TF_ANNOTATE_MEMORY_IS_INITIALIZED(in, sizeof(float) * 4);
  float* array = in[0];
  out[0] = array[0] + 1;
  out[1] = array[1] + 1;
  out[2] = array[2] + 1;
  out[3] = array[3] + 1;
}
}  // namespace

REGISTER_CUSTOM_CALL_TARGET(R0F32Add2);
REGISTER_CUSTOM_CALL_TARGET(R2F32ReduceSum);
REGISTER_CUSTOM_CALL_TARGET(Add1ToValues);

namespace xla {
namespace {

class CustomCallTest : public HloTestBase {
 protected:
  Shape r0f32_ = ShapeUtil::MakeShape(F32, {});
  Shape r2f32_ = ShapeUtil::MakeShape(F32, {2, 2});
};

XLA_TEST_F(CustomCallTest, DISABLED_ON_GPU(CustomCallR0F32Add2)) {
  auto module = CreateNewModule();
  auto builder = HloComputation::Builder(TestName());

  auto constant = builder.AddInstruction(
      HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(42.0f)));
  builder.AddInstruction(
      HloInstruction::CreateCustomCall(r0f32_, {constant}, "R0F32Add2"));

  module->AddEntryComputation(builder.Build());

  Literal result = ExecuteAndTransfer(std::move(module), {});
  LiteralTestUtil::ExpectR0Near<float>(44.0f, result, error_spec_);
}

XLA_TEST_F(CustomCallTest, DISABLED_ON_GPU(CustomCallR2F32Reduce)) {
  auto module = CreateNewModule();
  auto builder = HloComputation::Builder(TestName());

  Array2D<float> array(2, 2);
  array(0, 0) = 1.0f;
  array(0, 1) = 2.0f;
  array(1, 0) = 3.0f;
  array(1, 1) = 4.0f;

  auto constant = builder.AddInstruction(
      HloInstruction::CreateConstant(LiteralUtil::CreateR2FromArray2D(array)));
  builder.AddInstruction(
      HloInstruction::CreateCustomCall(r0f32_, {constant}, "R2F32ReduceSum"));

  module->AddEntryComputation(builder.Build());

  Literal result = ExecuteAndTransfer(std::move(module), {});
  LiteralTestUtil::ExpectR0Near<float>(10.0f, result, error_spec_);
}

XLA_TEST_F(CustomCallTest, DISABLED_ON_GPU(UsedInOtherComputations)) {
  auto module = CreateNewModule();
  auto b = HloComputation::Builder(TestName());

  auto input = b.AddInstruction(
      HloInstruction::CreateConstant(LiteralUtil::CreateR2FromArray2D(
          Array2D<float>{{1.0f, 2.0f}, {3.0f, 4.0f}})));
  auto incremented = b.AddInstruction(HloInstruction::CreateCustomCall(
      ShapeUtil::MakeShape(F32, {1, 2, 2}), {input}, "Add1ToValues"));
  auto incremented_again = b.AddInstruction(HloInstruction::CreateCustomCall(
      ShapeUtil::MakeShape(F32, {1, 2, 2}), {incremented}, "Add1ToValues"));

  // Concatenate the values along first dim.
  b.AddInstruction(
      HloInstruction::CreateConcatenate(ShapeUtil::MakeShape(F32, {2, 2, 2}),
                                        {incremented, incremented_again}, 0));

  module->AddEntryComputation(b.Build());

  Literal result = ExecuteAndTransfer(std::move(module), {});
  LiteralTestUtil::ExpectR3EqualArray3D<float>(
      Array3D<float>{{{2, 3}, {4, 5}}, {{3, 4}, {5, 6}}}, result);
}

XLA_TEST_F(CustomCallTest, DISABLED_ON_GPU(InputAndOutputLayoutDiffer)) {
  auto module = CreateNewModule();
  auto b = HloComputation::Builder(TestName());

  auto input =
      b.AddInstruction(HloInstruction::CreateParameter(0, r2f32_, "p"));
  b.AddInstruction(
      HloInstruction::CreateCustomCall(r2f32_, {input}, "Add1ToValues"));

  module->AddEntryComputation(b.Build());
  ForceParameterLayout(module.get(), 0, LayoutUtil::MakeLayout({1, 0}));
  ForceResultLayout(module.get(), LayoutUtil::MakeLayout({0, 1}));

  Literal argument = LiteralUtil::CreateR2<float>({{1.f, 2.f}, {3.f, 4.f}});

  // Note, the expected result is transposed! This is because the input and
  // output layouts of the custom call differ and the called function just
  // blindly adds one to each element.
  Literal result = ExecuteAndTransfer(std::move(module), {&argument});
  LiteralTestUtil::ExpectR2Equal<float>({{2.f, 4.f}, {3.f, 5.f}}, result);
}

XLA_TEST_F(CustomCallTest, DISABLED_ON_GPU(LayoutConstrained)) {
  // The argument and result of the computation are set to different layouts,
  // but the custom call is layout constrained to a fixed operand and result
  // layout, so the correct result should be produced.
  auto module = CreateNewModule();
  auto b = HloComputation::Builder(TestName());

  auto input =
      b.AddInstruction(HloInstruction::CreateParameter(0, r2f32_, "p"));

  const Shape& r2f32_dim0_major =
      ShapeUtil::MakeShapeWithLayout(F32, {2, 2}, {1, 0});
  b.AddInstruction(HloInstruction::CreateCustomCall(
      r2f32_dim0_major, {input}, "Add1ToValues", {r2f32_dim0_major}));

  module->AddEntryComputation(b.Build());
  ForceParameterLayout(module.get(), 0, LayoutUtil::MakeLayout({1, 0}));
  ForceResultLayout(module.get(), LayoutUtil::MakeLayout({0, 1}));

  Literal argument = LiteralUtil::CreateR2<float>({{1.f, 2.f}, {3.f, 4.f}});

  Literal result = ExecuteAndTransfer(std::move(module), {&argument});
  LiteralTestUtil::ExpectR2Equal<float>({{2.f, 3.f}, {4.f, 5.f}}, result);
}

class CustomCallClientAPITest : public ClientLibraryTestBase {};

// When using the client API, CustomCall targets can't begin with '$' -- these
// are reserved for internal use.
XLA_TEST_F(CustomCallClientAPITest, IllegalCustomCallTarget) {
  XlaBuilder builder(TestName());
  CustomCall(&builder, "$illegal", /*operands=*/{},
             ShapeUtil::MakeShape(F32, {1}));

  StatusOr<std::unique_ptr<GlobalData>> result =
      Execute(&builder, /*arguments=*/{});
  EXPECT_FALSE(result.ok());
}

}  // namespace
}  // namespace xla


text:
namespace SaddyKopper
{
    using System;
    using System.Numerics;

    public class Start
    {
        public static void Main()
        {
            // currentNum = "99999999999999999";
            string currentNum = Console.ReadLine();
            int transformationsCount = 0;
            while (currentNum.Length >= 2 && transformationsCount <= 9)
            {
                BigInteger product = 1;
                for (int digitsToRemove = 1; digitsToRemove < currentNum.Length; digitsToRemove++)
                {
                    int sum = 0;
                    int searchedNumLength = currentNum.Length - digitsToRemove;

                    // calc sums of digits
                    for (int i = 0; i < searchedNumLength; i += 2)
                    {
                        int currentDigit = (int)(currentNum[i] - '0');
                        sum += currentDigit;
                    }

                    product *= sum;
                }

                currentNum = product.ToString();
                transformationsCount++;
            }

            if (transformationsCount <= 9)
            {
                Console.WriteLine(transformationsCount);
            }

            Console.WriteLine(currentNum);
        }
    }
}