text:
module Neo4j
  module ActiveNode
    # Provides a mapping between neo4j labels and Ruby classes
    module Labels
      extend ActiveSupport::Concern
      include Neo4j::ActiveNode::Labels::Reloading

      WRAPPED_CLASSES = []
      MODELS_FOR_LABELS_CACHE = {}
      MODELS_FOR_LABELS_CACHE.clear

      included do |model|
        def self.inherited(model)
          add_wrapped_class(model)

          super
        end

        Neo4j::ActiveNode::Labels.add_wrapped_class(model) unless Neo4j::ActiveNode::Labels._wrapped_classes.include?(model)
      end

      class InvalidQueryError < StandardError; end
      class RecordNotFound < StandardError; end

      # @return the labels
      # @see Neo4j-core
      def labels
        @_persisted_obj.labels
      end

      # this is handled by core, leaving it now for posterity
      # def queried_labels
      #   self.class.query_as(:result).where("ID(result)" => self.neo_id).return("LABELS(result) as result_labels").first.result_labels.map(&:to_sym)
      # end

      # adds one or more labels
      # @see Neo4j-core
      def add_label(*label)
        @_persisted_obj.add_label(*label)
      end

      # Removes one or more labels
      # Be careful, don't remove the label representing the Ruby class.
      # @see Neo4j-core
      def remove_label(*label)
        @_persisted_obj.remove_label(*label)
      end

      def self.add_wrapped_class(model)
        _wrapped_classes << model
      end

      def self._wrapped_classes
        Neo4j::ActiveNode::Labels::WRAPPED_CLASSES
      end

      def self.model_for_labels(labels)
        MODELS_FOR_LABELS_CACHE[labels] || model_cache(labels)
      end

      def self.model_cache(labels)
        models = WRAPPED_CLASSES.select do |model|
          (model.mapped_label_names - labels).size == 0
        end

        MODELS_FOR_LABELS_CACHE[labels] = models.max do |model|
          (model.mapped_label_names & labels).size
        end
      end

      def self.clear_model_for_label_cache
        MODELS_FOR_LABELS_CACHE.clear
      end

      def self.clear_wrapped_models
        WRAPPED_CLASSES.clear
      end

      module ClassMethods
        include Neo4j::ActiveNode::QueryMethods

        # Returns the object with the specified neo4j id.
        # @param [String,Integer] id of node to find
        def find(id)
          map_id = proc { |object| object.respond_to?(:id) ? object.send(:id) : object }

          result = if id.is_a?(Array)
                     find_by_ids(id.map { |o| map_id.call(o) })
                   else
                     find_by_id(map_id.call(id))
                   end
          fail Neo4j::RecordNotFound if result.blank?
          result
        end

        # Finds the first record matching the specified conditions. There is no implied ordering so if order matters, you should specify it yourself.
        # @param values Hash args of arguments to find
        def find_by(values)
          all.where(values).limit(1).query_as(:n).pluck(:n).first
        end

        # Like find_by, except that if no record is found, raises a RecordNotFound error.
        def find_by!(values)
          find_by(values) || fail(RecordNotFound, "#{self.query_as(:n).where(n: values).limit(1).to_cypher} returned no results")
        end

        # Deletes all nodes and connected relationships from Cypher.
        def delete_all
          self.neo4j_session._query("MATCH (n:`#{mapped_label_name}`) OPTIONAL MATCH n-[r]-() DELETE n,r")
          self.neo4j_session._query("MATCH (n:`#{mapped_label_name}`) DELETE n")
        end

        # Returns each node to Ruby and calls `destroy`. Be careful, as this can be a very slow operation if you have many nodes. It will generate at least
        # one database query per node in the database, more if callbacks require them.
        def destroy_all
          all.each(&:destroy)
        end

        # Creates a Neo4j index on given property
        #
        # This can also be done on the property directly, see Neo4j::ActiveNode::Property::ClassMethods#property.
        #
        # @param [Symbol] property the property we want a Neo4j index on
        # @param [Hash] conf optional property configuration
        #
        # @example
        #   class Person
        #      include Neo4j::ActiveNode
        #      property :name
        #      index :name
        #    end
        #
        # @example with constraint
        #   class Person
        #      include Neo4j::ActiveNode
        #      property :name
        #
        #      # below is same as: index :name, index: :exact, constraint: {type: :unique}
        #      index :name, constraint: {type: :unique}
        #    end
        def index(property, conf = {})
          Neo4j::Session.on_session_available do |_|
            drop_constraint(property, type: :unique) if Neo4j::Label.constraint?(mapped_label_name, property)
            _index(property, conf)
          end
          indexed_properties.push property unless indexed_properties.include? property
        end

        # Creates a neo4j constraint on this class for given property
        #
        # @example
        #   Person.constraint :name, type: :unique
        #
        def constraint(property, constraints)
          Neo4j::Session.on_session_available do |session|
            unless Neo4j::Label.constraint?(mapped_label_name, property)
              label = Neo4j::Label.create(mapped_label_name)
              drop_index(property, label) if index?(property)
              label.create_constraint(property, constraints, session)
            end
          end
        end

        # @param [Symbol] property The name of the property index to be dropped
        # @param [Neo4j::Label] label An instance of label from Neo4j::Core
        def drop_index(property, label = nil)
          label_obj = label || Neo4j::Label.create(mapped_label_name)
          label_obj.drop_index(property)
        end

        # @param [Symbol] property The name of the property constraint to be dropped
        # @param [Hash] constraint The constraint type to be dropped.
        def drop_constraint(property, constraint = {type: :unique})
          Neo4j::Session.on_session_available do |session|
            label = Neo4j::Label.create(mapped_label_name)
            label.drop_constraint(property, constraint, session)
          end
        end

        def index?(index_def)
          mapped_label.indexes[:property_keys].include?([index_def])
        end

        # @return [Array{Symbol}] all the labels that this class has
        def mapped_label_names
          self.ancestors.find_all { |a| a.respond_to?(:mapped_label_name) }.map { |a| a.mapped_label_name.to_sym }
        end

        # @return [Symbol] the label that this class has which corresponds to a Ruby class
        def mapped_label_name
          @mapped_label_name || label_for_model
        end

        # @return [Neo4j::Label] the label for this class
        def mapped_label
          Neo4j::Label.create(mapped_label_name)
        end

        def indexed_properties
          @_indexed_properties ||= []
        end

        def base_class
          unless self < Neo4j::ActiveNode
            fail "#{name} doesn't belong in a hierarchy descending from ActiveNode"
          end

          if superclass == Object
            self
          else
            superclass.base_class
          end
        end

        protected

        def _index(property, conf)
          mapped_labels.each do |label|
            # make sure the property is not indexed twice
            existing = label.indexes[:property_keys]

            # In neo4j constraint automatically creates an index
            if conf[:constraint]
              constraint(property, conf[:constraint])
            else
              label.create_index(property) unless existing.flatten.include?(property)
            end
          end
        end

        def mapped_labels
          mapped_label_names.map { |label_name| Neo4j::Label.create(label_name) }
        end

        def mapped_label_name=(name)
          @mapped_label_name = name.to_sym
        end

        # rubocop:disable Style/AccessorMethodName
        def set_mapped_label_name(name)
          ActiveSupport::Deprecation.warn 'set_mapped_label_name is deprecated, use self.mapped_label_name= instead.', caller

          self.mapped_label_name = name
        end
        # rubocop:enable Style/AccessorMethodName

        private

        def label_for_model
          (self.name.nil? ? object_id.to_s.to_sym : decorated_label_name)
        end

        def decorated_label_name
          name =  case Neo4j::Config[:module_handling]
                  when :demodulize
                    self.name.demodulize
                  when Proc
                    Neo4j::Config[:module_handling].call self.name
                  else
                    self.name
                  end

          name.to_sym
        end
      end
    end
  end
end


text:
package schedule

import (
	"context"
	"fmt"
	"math"
	"sync"
	"time"

	"github.com/pingcap/errors"
	"github.com/pingcap/failpoint"
	"github.com/pingcap/kvproto/pkg/metapb"
	"github.com/pingcap/log"
	"github.com/tikv/pd/pkg/cache"
	"github.com/tikv/pd/pkg/errs"
	"github.com/tikv/pd/pkg/typeutil"
	"github.com/tikv/pd/server/core"
	"github.com/tikv/pd/server/schedule/filter"
	"github.com/tikv/pd/server/schedule/operator"
	"go.uber.org/zap"
)

const regionScatterName = "region-scatter"

var gcInterval = time.Minute
var gcTTL = time.Minute * 3

type selectedStores struct {
	mu                sync.RWMutex
	groupDistribution *cache.TTLString // value type: map[uint64]uint64, group -> StoreID -> count
}

func newSelectedStores(ctx context.Context) *selectedStores {
	return &selectedStores{
		groupDistribution: cache.NewStringTTL(ctx, gcInterval, gcTTL),
	}
}

// Put plus count by storeID and group
func (s *selectedStores) Put(id uint64, group string) {
	s.mu.Lock()
	defer s.mu.Unlock()
	distribution, ok := s.getDistributionByGroupLocked(group)
	if !ok {
		distribution = map[uint64]uint64{}
		distribution[id] = 0
	}
	distribution[id]++
	s.groupDistribution.Put(group, distribution)
}

// Get the count by storeID and group
func (s *selectedStores) Get(id uint64, group string) uint64 {
	s.mu.RLock()
	defer s.mu.RUnlock()
	distribution, ok := s.getDistributionByGroupLocked(group)
	if !ok {
		return 0
	}
	count, ok := distribution[id]
	if !ok {
		return 0
	}
	return count
}

// GetGroupDistribution get distribution group by `group`
func (s *selectedStores) GetGroupDistribution(group string) (map[uint64]uint64, bool) {
	s.mu.RLock()
	defer s.mu.RUnlock()
	return s.getDistributionByGroupLocked(group)
}

// TotalCountByStore counts the total count by store
func (s *selectedStores) TotalCountByStore(storeID uint64) uint64 {
	s.mu.RLock()
	defer s.mu.RUnlock()
	groups := s.groupDistribution.GetAllID()
	totalCount := uint64(0)
	for _, group := range groups {
		storeDistribution, ok := s.getDistributionByGroupLocked(group)
		if !ok {
			continue
		}
		count, ok := storeDistribution[storeID]
		if !ok {
			continue
		}
		totalCount += count
	}
	return totalCount
}

// getDistributionByGroupLocked should be called with lock
func (s *selectedStores) getDistributionByGroupLocked(group string) (map[uint64]uint64, bool) {
	if result, ok := s.groupDistribution.Get(group); ok {
		return result.(map[uint64]uint64), true
	}
	return nil, false
}

// RegionScatterer scatters regions.
type RegionScatterer struct {
	ctx            context.Context
	name           string
	cluster        Cluster
	ordinaryEngine engineContext
	specialEngines map[string]engineContext
}

// NewRegionScatterer creates a region scatterer.
// RegionScatter is used for the `Lightning`, it will scatter the specified regions before import data.
func NewRegionScatterer(ctx context.Context, cluster Cluster) *RegionScatterer {
	return &RegionScatterer{
		ctx:            ctx,
		name:           regionScatterName,
		cluster:        cluster,
		ordinaryEngine: newEngineContext(ctx, filter.NewOrdinaryEngineFilter(regionScatterName)),
		specialEngines: make(map[string]engineContext),
	}
}

type engineContext struct {
	filters        []filter.Filter
	selectedPeer   *selectedStores
	selectedLeader *selectedStores
}

func newEngineContext(ctx context.Context, filters ...filter.Filter) engineContext {
	filters = append(filters, &filter.StoreStateFilter{ActionScope: regionScatterName, MoveRegion: true, ScatterRegion: true})
	return engineContext{
		filters:        filters,
		selectedPeer:   newSelectedStores(ctx),
		selectedLeader: newSelectedStores(ctx),
	}
}

const maxSleepDuration = 1 * time.Minute
const initialSleepDuration = 100 * time.Millisecond
const maxRetryLimit = 30

// ScatterRegionsByRange directly scatter regions by ScatterRegions
func (r *RegionScatterer) ScatterRegionsByRange(startKey, endKey []byte, group string, retryLimit int) ([]*operator.Operator, map[uint64]error, error) {
	regions := r.cluster.ScanRegions(startKey, endKey, -1)
	if len(regions) < 1 {
		scatterCounter.WithLabelValues("skip", "empty-region").Inc()
		return nil, nil, errors.New("empty region")
	}
	failures := make(map[uint64]error, len(regions))
	regionMap := make(map[uint64]*core.RegionInfo, len(regions))
	for _, region := range regions {
		regionMap[region.GetID()] = region
	}
	// If there existed any region failed to relocated after retry, add it into unProcessedRegions
	ops, err := r.ScatterRegions(regionMap, failures, group, retryLimit)
	if err != nil {
		return nil, nil, err
	}
	return ops, failures, nil
}

// ScatterRegionsByID directly scatter regions by ScatterRegions
func (r *RegionScatterer) ScatterRegionsByID(regionsID []uint64, group string, retryLimit int) ([]*operator.Operator, map[uint64]error, error) {
	if len(regionsID) < 1 {
		scatterCounter.WithLabelValues("skip", "empty-region").Inc()
		return nil, nil, errors.New("empty region")
	}
	failures := make(map[uint64]error, len(regionsID))
	regions := make([]*core.RegionInfo, 0, len(regionsID))
	for _, id := range regionsID {
		region := r.cluster.GetRegion(id)
		if region == nil {
			scatterCounter.WithLabelValues("skip", "no-region").Inc()
			log.Warn("failed to find region during scatter", zap.Uint64("region-id", id))
			failures[id] = errors.New(fmt.Sprintf("failed to find region %v", id))
			continue
		}
		regions = append(regions, region)
	}
	regionMap := make(map[uint64]*core.RegionInfo, len(regions))
	for _, region := range regions {
		regionMap[region.GetID()] = region
	}
	// If there existed any region failed to relocated after retry, add it into unProcessedRegions
	ops, err := r.ScatterRegions(regionMap, failures, group, retryLimit)
	if err != nil {
		return nil, nil, err
	}
	return ops, failures, nil
}

// ScatterRegions relocates the regions. If the group is defined, the regions' leader with the same group would be scattered
// in a group level instead of cluster level.
// RetryTimes indicates the retry times if any of the regions failed to relocate during scattering. There will be
// time.Sleep between each retry.
// Failures indicates the regions which are failed to be relocated, the key of the failures indicates the regionID
// and the value of the failures indicates the failure error.
func (r *RegionScatterer) ScatterRegions(regions map[uint64]*core.RegionInfo, failures map[uint64]error, group string, retryLimit int) ([]*operator.Operator, error) {
	if len(regions) < 1 {
		scatterCounter.WithLabelValues("skip", "empty-region").Inc()
		return nil, errors.New("empty region")
	}
	if retryLimit > maxRetryLimit {
		retryLimit = maxRetryLimit
	}
	ops := make([]*operator.Operator, 0, len(regions))
	for currentRetry := 0; currentRetry <= retryLimit; currentRetry++ {
		for _, region := range regions {
			op, err := r.Scatter(region, group)
			failpoint.Inject("scatterFail", func() {
				if region.GetID() == 1 {
					err = errors.New("mock error")
				}
			})
			if err != nil {
				failures[region.GetID()] = err
				continue
			}
			if op != nil {
				ops = append(ops, op)
			}
			delete(regions, region.GetID())
			delete(failures, region.GetID())
		}
		// all regions have been relocated, break the loop.
		if len(regions) < 1 {
			break
		}
		// Wait for a while if there are some regions failed to be relocated
		time.Sleep(typeutil.MinDuration(maxSleepDuration, time.Duration(math.Pow(2, float64(currentRetry)))*initialSleepDuration))
	}
	return ops, nil
}

// Scatter relocates the region. If the group is defined, the regions' leader with the same group would be scattered
// in a group level instead of cluster level.
func (r *RegionScatterer) Scatter(region *core.RegionInfo, group string) (*operator.Operator, error) {
	if !IsRegionReplicated(r.cluster, region) {
		r.cluster.AddSuspectRegions(region.GetID())
		scatterCounter.WithLabelValues("skip", "not-replicated").Inc()
		log.Warn("region not replicated during scatter", zap.Uint64("region-id", region.GetID()))
		return nil, errors.Errorf("region %d is not fully replicated", region.GetID())
	}

	if region.GetLeader() == nil {
		scatterCounter.WithLabelValues("skip", "no-leader").Inc()
		log.Warn("region no leader during scatter", zap.Uint64("region-id", region.GetID()))
		return nil, errors.Errorf("region %d has no leader", region.GetID())
	}

	if r.cluster.IsRegionHot(region) {
		scatterCounter.WithLabelValues("skip", "hot").Inc()
		log.Warn("region too hot during scatter", zap.Uint64("region-id", region.GetID()))
		return nil, errors.Errorf("region %d is hot", region.GetID())
	}

	return r.scatterRegion(region, group), nil
}

func (r *RegionScatterer) scatterRegion(region *core.RegionInfo, group string) *operator.Operator {
	ordinaryFilter := filter.NewOrdinaryEngineFilter(r.name)
	ordinaryPeers := make(map[uint64]*metapb.Peer, len(region.GetPeers()))
	specialPeers := make(map[string]map[uint64]*metapb.Peer)
	// Group peers by the engine of their stores
	for _, peer := range region.GetPeers() {
		store := r.cluster.GetStore(peer.GetStoreId())
		if store == nil {
			return nil
		}
		if ordinaryFilter.Target(r.cluster.GetOpts(), store) {
			ordinaryPeers[peer.GetStoreId()] = peer
		} else {
			engine := store.GetLabelValue(core.EngineKey)
			if _, ok := specialPeers[engine]; !ok {
				specialPeers[engine] = make(map[uint64]*metapb.Peer)
			}
			specialPeers[engine][peer.GetStoreId()] = peer
		}
	}

	targetPeers := make(map[uint64]*metapb.Peer, len(region.GetPeers()))                  // StoreID -> Peer
	selectedStores := make(map[uint64]struct{}, len(region.GetPeers()))                   // StoreID set
	scatterWithSameEngine := func(peers map[uint64]*metapb.Peer, context engineContext) { // peers: StoreID -> Peer
		for _, peer := range peers {
			if _, ok := selectedStores[peer.GetStoreId()]; ok {
				// It is both sourcePeer and targetPeer itself, no need to select.
				continue
			}
			for {
				candidates := r.selectCandidates(region, peer.GetStoreId(), selectedStores, context)
				newPeer := r.selectStore(group, peer, peer.GetStoreId(), candidates, context)
				targetPeers[newPeer.GetStoreId()] = newPeer
				selectedStores[newPeer.GetStoreId()] = struct{}{}
				// If the selected peer is a peer other than origin peer in this region,
				// it is considered that the selected peer select itself.
				// This origin peer re-selects.
				if _, ok := peers[newPeer.GetStoreId()]; !ok || peer.GetStoreId() == newPeer.GetStoreId() {
					break
				}
			}
		}
	}

	scatterWithSameEngine(ordinaryPeers, r.ordinaryEngine)
	// FIXME: target leader only considers the ordinary stores, maybe we need to consider the
	// special engine stores if the engine supports to become a leader. But now there is only
	// one engine, tiflash, which does not support the leader, so don't consider it for now.
	targetLeader := r.selectAvailableLeaderStore(group, targetPeers, r.ordinaryEngine)
	if targetLeader == 0 {
		scatterCounter.WithLabelValues("no-leader", "").Inc()
		return nil
	}

	for engine, peers := range specialPeers {
		ctx, ok := r.specialEngines[engine]
		if !ok {
			ctx = newEngineContext(r.ctx, filter.NewEngineFilter(r.name, engine))
			r.specialEngines[engine] = ctx
		}
		scatterWithSameEngine(peers, ctx)
	}

	if isSameDistribution(region, targetPeers, targetLeader) {
		scatterCounter.WithLabelValues("unnecessary", "").Inc()
		r.Put(targetPeers, targetLeader, group)
		return nil
	}
	op, err := operator.CreateScatterRegionOperator("scatter-region", r.cluster, region, targetPeers, targetLeader)
	if err != nil {
		scatterCounter.WithLabelValues("fail", "").Inc()
		for _, peer := range region.GetPeers() {
			targetPeers[peer.GetStoreId()] = peer
		}
		r.Put(targetPeers, region.GetLeader().GetStoreId(), group)
		log.Debug("fail to create scatter region operator", errs.ZapError(err))
		return nil
	}
	if op != nil {
		scatterCounter.WithLabelValues("success", "").Inc()
		r.Put(targetPeers, targetLeader, group)
		op.SetPriorityLevel(core.HighPriority)
	}
	return op
}

func isSameDistribution(region *core.RegionInfo, targetPeers map[uint64]*metapb.Peer, targetLeader uint64) bool {
	peers := region.GetPeers()
	for _, peer := range peers {
		if _, ok := targetPeers[peer.GetStoreId()]; !ok {
			return false
		}
	}
	return region.GetLeader().GetStoreId() == targetLeader
}

func (r *RegionScatterer) selectCandidates(region *core.RegionInfo, sourceStoreID uint64, selectedStores map[uint64]struct{}, context engineContext) []uint64 {
	sourceStore := r.cluster.GetStore(sourceStoreID)
	if sourceStore == nil {
		log.Error("failed to get the store", zap.Uint64("store-id", sourceStoreID), errs.ZapError(errs.ErrGetSourceStore))
		return nil
	}
	filters := []filter.Filter{
		filter.NewExcludedFilter(r.name, nil, selectedStores),
	}
	scoreGuard := filter.NewPlacementSafeguard(r.name, r.cluster.GetOpts(), r.cluster.GetBasicCluster(), r.cluster.GetRuleManager(), region, sourceStore)
	filters = append(filters, context.filters...)
	filters = append(filters, scoreGuard)
	stores := r.cluster.GetStores()
	candidates := make([]uint64, 0)
	maxStoreTotalCount := uint64(0)
	minStoreTotalCount := uint64(math.MaxUint64)
	for _, store := range r.cluster.GetStores() {
		count := context.selectedPeer.TotalCountByStore(store.GetID())
		if count > maxStoreTotalCount {
			maxStoreTotalCount = count
		}
		if count < minStoreTotalCount {
			minStoreTotalCount = count
		}
	}
	for _, store := range stores {
		storeCount := context.selectedPeer.TotalCountByStore(store.GetID())
		// If storeCount is equal to the maxStoreTotalCount, we should skip this store as candidate.
		// If the storeCount are all the same for the whole cluster(maxStoreTotalCount == minStoreTotalCount), any store
		// could be selected as candidate.
		if storeCount < maxStoreTotalCount || maxStoreTotalCount == minStoreTotalCount {
			if filter.Target(r.cluster.GetOpts(), store, filters) {
				candidates = append(candidates, store.GetID())
			}
		}
	}
	return candidates
}

func (r *RegionScatterer) selectStore(group string, peer *metapb.Peer, sourceStoreID uint64, candidates []uint64, context engineContext) *metapb.Peer {
	if len(candidates) < 1 {
		return peer
	}
	var newPeer *metapb.Peer
	minCount := uint64(math.MaxUint64)
	for _, storeID := range candidates {
		count := context.selectedPeer.Get(storeID, group)
		if count < minCount {
			minCount = count
			newPeer = &metapb.Peer{
				StoreId: storeID,
				Role:    peer.GetRole(),
			}
		}
	}
	// if the source store have the least count, we don't need to scatter this peer
	for _, storeID := range candidates {
		if storeID == sourceStoreID && context.selectedPeer.Get(sourceStoreID, group) <= minCount {
			return peer
		}
	}
	if newPeer == nil {
		return peer
	}
	return newPeer
}

// selectAvailableLeaderStore select the target leader store from the candidates. The candidates would be collected by
// the existed peers store depended on the leader counts in the group level.
func (r *RegionScatterer) selectAvailableLeaderStore(group string, peers map[uint64]*metapb.Peer, context engineContext) uint64 {
	leaderCandidateStores := make([]uint64, 0)
	for storeID := range peers {
		store := r.cluster.GetStore(storeID)
		if store == nil {
			return 0
		}
		engine := store.GetLabelValue(core.EngineKey)
		if len(engine) < 1 {
			leaderCandidateStores = append(leaderCandidateStores, storeID)
		}
	}
	minStoreGroupLeader := uint64(math.MaxUint64)
	id := uint64(0)
	for _, storeID := range leaderCandidateStores {
		storeGroupLeaderCount := context.selectedLeader.Get(storeID, group)
		if minStoreGroupLeader > storeGroupLeaderCount {
			minStoreGroupLeader = storeGroupLeaderCount
			id = storeID
		}
	}
	return id
}

// Put put the final distribution in the context no matter the operator was created
func (r *RegionScatterer) Put(peers map[uint64]*metapb.Peer, leaderStoreID uint64, group string) {
	ordinaryFilter := filter.NewOrdinaryEngineFilter(r.name)
	// Group peers by the engine of their stores
	for _, peer := range peers {
		storeID := peer.GetStoreId()
		store := r.cluster.GetStore(storeID)
		if store == nil {
			continue
		}
		if ordinaryFilter.Target(r.cluster.GetOpts(), store) {
			r.ordinaryEngine.selectedPeer.Put(storeID, group)
			scatterDistributionCounter.WithLabelValues(
				fmt.Sprintf("%v", storeID),
				fmt.Sprintf("%v", false),
				core.EngineTiKV).Inc()
		} else {
			engine := store.GetLabelValue(core.EngineKey)
			r.specialEngines[engine].selectedPeer.Put(storeID, group)
			scatterDistributionCounter.WithLabelValues(
				fmt.Sprintf("%v", storeID),
				fmt.Sprintf("%v", false),
				engine).Inc()
		}
	}
	r.ordinaryEngine.selectedLeader.Put(leaderStoreID, group)
	scatterDistributionCounter.WithLabelValues(
		fmt.Sprintf("%v", leaderStoreID),
		fmt.Sprintf("%v", true),
		core.EngineTiKV).Inc()
}

redpajama_set_name: RedPajamaGithub


text:
package org.nlpcn.es4sql.parse;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.*;
import org.nlpcn.es4sql.Util;
import org.nlpcn.es4sql.domain.Where;
import org.nlpcn.es4sql.exception.SqlParseException;

import java.util.List;

/**
 * Created by Eliran on 12/11/2015.
 */
public class NestedType {
    //字段名称
    public String field;
    //排序时的路径和条件
    public String path;
    public Where where;
    public String mode;
    private boolean reverse;
    private boolean simple;

    public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException {
        if (!(expr instanceof SQLMethodInvokeExpr)) return false;
        SQLMethodInvokeExpr method = (SQLMethodInvokeExpr) expr;
        String methodNameLower = method.getMethodName().toLowerCase();
        if (!(methodNameLower.equals("nested") || methodNameLower.equals("reverse_nested"))) return false;

        reverse = methodNameLower.equals("reverse_nested");

        List<SQLExpr> parameters = method.getParameters();
        if (parameters.size() != 3 && parameters.size() != 2 && parameters.size() != 1)
            throw new SqlParseException("on nested object only allowed 2 parameters (field,path)/(path,conditions..) or 1 parameter (field) ");

        String field = Util.extendedToString(parameters.get(0));
        this.field = field;
        if (parameters.size() == 1) {
            //calc path myself..
            if (!field.contains(".")) {
                if (!reverse)
                    throw new SqlParseException("nested should contain . on their field name");
                else {
                    this.path = null;
                    this.simple = true;
                }
            } else {
                int lastDot = field.lastIndexOf(".");
                this.path = field.substring(0, lastDot);
                this.simple = true;

            }

        } else if (parameters.size() == 2) {
            SQLExpr lastParameter = parameters.get(1);
            if (lastParameter instanceof SQLTextLiteralExpr || lastParameter instanceof SQLIdentifierExpr || lastParameter instanceof SQLPropertyExpr) {
                String pathString = Util.extendedToString(lastParameter);
                if (pathString.equals(""))
                    this.path = null;
                else
                    this.path = pathString;
                this.simple = true;
            } else {
                this.path = field;
                Where where = Where.newInstance();
                new SqlParser().parseWhere(lastParameter, where);
                if (where.getWheres().size() == 0)
                    throw new SqlParseException("unable to parse filter where.");
                this.where = where;
                simple = false;
            }
        } else if (parameters.size() == 3) {
            this.path = field;
            SQLExpr secondParameter = parameters.get(1);
            if (secondParameter instanceof SQLAggregateExpr){
                this.mode = ((SQLAggregateExpr) secondParameter).getMethodName();
                this.field = ((SQLAggregateExpr) secondParameter).getArguments().get(0).toString();
            }
            SQLExpr lastParameter = parameters.get(2);
            Where where = Where.newInstance();
            new SqlParser().parseWhere(lastParameter, where);
            if (where.getWheres().size() == 0)
                throw new SqlParseException("unable to parse filter where.");
            this.where = where;
            simple = false;
        }

        return true;
    }

    public boolean isSimple() {
        return simple;
    }

    public boolean isReverse() {
        return reverse;
    }
}


text:
var hasPadAccess = require("../../padaccess");
var settings = require('../../utils/Settings');
var exportHandler = require('../../handler/ExportHandler');
var importHandler = require('../../handler/ImportHandler');

exports.expressCreateServer = function (hook_name, args, cb) {
  args.app.get('/p/:pad/:rev?/export/:type', function(req, res, next) {
    var types = ["pdf", "doc", "txt", "html", "odt", "etherpad"];
    //send a 404 if we don't support this filetype
    if (types.indexOf(req.params.type) == -1) {
      next();
      return;
    }

    //if abiword is disabled, and this is a format we only support with abiword, output a message
    if (settings.exportAvailable() == "no" &&
       ["odt", "pdf", "doc"].indexOf(req.params.type) !== -1) {
      res.send("This export is not enabled at this Etherpad instance. Set the path to Abiword or SOffice in settings.json to enable this feature");
      return;
    }

    res.header("Access-Control-Allow-Origin", "*");

    hasPadAccess(req, res, function() {
      exportHandler.doExport(req, res, req.params.pad, req.params.type);
    });
  });

  //handle import requests
  args.app.post('/p/:pad/import', function(req, res, next) {
    hasPadAccess(req, res, function() {
      importHandler.doImport(req, res, req.params.pad);
    });
  });
}


text:
SYNONYM

#### According to
Index Fungorum

#### Published in
null

#### Original name
Ustilago molleri Bref.

### Remarks
null


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<title>{Saivi:$tpl.wxname}</title>

<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="format-detection" content="telephone=no">

<meta charset="utf-8">

<link href="./tpl/static/tpl/1114/css/cate.css" rel="stylesheet" type="text/css" />

 <link href="./tpl/static/tpl/com/css/iscroll.css" rel="stylesheet" type="text/css" />

		<if condition="$homeInfo['musicurl'] neq false">

			<include file="Index:music"/>

		</if>

				<volist name="flash" id="so">

{Saivi:$so.info}

				</volist>

← prev

				<volist name="flash" id="so">

					<li <if condition="$i eq 1">class="active"</if> >

				</volist>

next →

<volist name="info" id="vo" offset="0" length='4'>

	<if condition="$i%4 == 1">

	</if>

<a href="<if condition="$vo['url'] eq ''">{Saivi::U('Wap/Index/lists',array('classid'=>$vo['id'],'token'=>$vo['token']))}<else/>{Saivi:$vo.url|htmlspecialchars_decode}</if>">
{Saivi:$vo.name}

	<if condition="$i%4 == 0">

	</if>

</volist>

			<for start="4" end="count($info)">

               <li <if condition="$i == 4">class="on"</if>>

			 </for>

					<volist name="info" id="vo" offset="4">

							<a href="javascript:swiper_2.slide({Saivi:$i-1});" <if condition="$i == 1">class="on"</if>>

								{Saivi:$vo.name}

					</volist>

	<volist name="info" id="vo" offset="4">

	<volist name="vo['sub']" id="res">

				<a href="<if condition="$res['url'] eq ''">{Saivi::U('Wap/Index/lists',array('classid'=>$res['id'],'token'=>$vo['token']))}<else/>{Saivi:$res.url|htmlspecialchars_decode}</if>">

						{Saivi:$res.name}

	   </volist>

	   </volist>

<if condition="$iscopyright eq 1">

{Saivi:$homeInfo.copyright}

<else/>

{Saivi:$siteCopyright}

</if>

  <include file="Index:styleInclude"/><include file="$cateMenuFileName"/>

<include file="Index:share" />

<if condition="$kefu['status'] eq '1'"></if>


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

<!--
  Copyright 2011 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <item name="ic_action_av_connect">@drawable/presence_online</item>
        <item name="ic_action_av_next">@drawable/ic_action_next</item>
        <item name="ic_action_av_pause">@drawable/ic_action_pause</item>
        <item name="ic_action_av_play">@drawable/ic_action_play</item>
        <item name="ic_action_av_previous">@drawable/ic_action_previous</item>

        <item name="ic_action_av_repeat_off">@drawable/btn_repeat_off</item>
        <item name="ic_action_av_repeat_one">@drawable/btn_repeat_one</item>
        <item name="ic_action_av_repeat_all">@drawable/btn_repeat_all</item>

        <item name="ic_action_av_shuffle_off">@drawable/btn_shuffle_off</item>
        <item name="ic_action_av_shuffle_song">@drawable/btn_shuffle_song</item>
        <item name="ic_action_av_shuffle_album">@drawable/btn_shuffle_album</item>

        <item name="ic_action_view_as_grid">@drawable/ic_action_view_as_grid</item>
        <item name="ic_action_view_as_list">@drawable/ic_action_view_as_list</item>

        <item name="playing_item">@drawable/abc_list_pressed_holo_dark</item>

        <item name="alarm_dow_selected">@android:color/white</item>
        <item name="alarm_am_pm_color">@android:color/white</item>
        <item name="transparent_themed">@color/transparent_white</item>
        <item name="alarm_list_background">@color/alarm_list_background</item>
        <item name="item_background">@drawable/item_background</item>
        <item name="main_button_background">@drawable/main_button_normal</item>
        <item name="ic_alarm_settings">@drawable/ic_alarm_settings</item>
        <item name="ic_delete">@drawable/ic_delete</item>

        <item name="floatLabelColor">@color/float_label_dark</item>
    </style>

    <style name="AppTheme.Light.DarkActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="ic_action_av_connect">@drawable/presence_online</item>
        <item name="ic_action_av_next">@drawable/ic_action_av_next_holo_light</item>
        <item name="ic_action_av_pause">@drawable/ic_action_av_pause_holo_light</item>
        <item name="ic_action_av_play">@drawable/ic_action_av_play_holo_light</item>
        <item name="ic_action_av_previous">@drawable/ic_action_av_previous_holo_light</item>

        <item name="ic_action_av_repeat_off">@drawable/ic_action_av_repeat_holo_light</item>
        <item name="ic_action_av_repeat_one">@drawable/btn_repeat_one</item>
        <item name="ic_action_av_repeat_all">@drawable/btn_repeat_all</item>

        <item name="ic_action_av_shuffle_off">@drawable/ic_action_av_shuffle_holo_light</item>
        <item name="ic_action_av_shuffle_song">@drawable/btn_shuffle_song</item>
        <item name="ic_action_av_shuffle_album">@drawable/btn_shuffle_album</item>

        <item name="ic_action_view_as_grid">@drawable/ic_action_view_as_grid_light</item>
        <item name="ic_action_view_as_list">@drawable/ic_action_view_as_list_light</item>

        <item name="playing_item">@drawable/abc_list_pressed_holo_light</item>

        <item name="alarm_dow_selected">@android:color/black</item>
        <item name="alarm_am_pm_color">@android:color/black</item>
        <item name="transparent_themed">@color/transparent_black</item>
        <item name="alarm_list_background">@color/alarm_list_background_light</item>
        <item name="item_background">@drawable/item_background_light</item>
        <item name="main_button_background">@drawable/main_button_light</item>
        <item name="ic_alarm_settings">@drawable/ic_alarm_settings_light</item>
        <item name="ic_delete">@drawable/ic_delete_light</item>

        <item name="floatLabelColor">@color/float_label_light</item>
    </style>

    <!-- Text Styles. Apply these to the android:textAppearance attribute of the views. -->

    <!-- Base styles that the rest of the app inherits from. -->
    <style name="SqueezerTextAppearance.XLarge" parent="@android:style/TextAppearance.Large">
        <item name="android:textSize">44sp</item>
    </style>
    <style name="SqueezerTextAppearance.Large" parent="@android:style/TextAppearance.Large"/>
    <style name="SqueezerTextAppearance.Medium" parent="@android:style/TextAppearance.Medium"/>
    <style name="SqueezerTextAppearance.Small" parent="@android:style/TextAppearance.Small"/>

    <!-- Text in list items -->
    <style name="SqueezerTextAppearance.ListItem.Primary" parent="SqueezerTextAppearance.Medium"/>
    <style name="SqueezerTextAppearance.ListItem.Secondary" parent="SqueezerTextAppearance.Small"/>

    <!-- Text in grid items -->
    <style name="SqueezerTextAppearance.GridItem.Primary" parent="SqueezerTextAppearance.Medium"/>
    <style name="SqueezerTextAppearance.GridItem.Secondary" parent="SqueezerTextAppearance.Small"/>

    <!-- Anywhere we want to display information about a song in an activity (and not in a list). -->
    <style name="SqueezerTextAppearance.SongInfo.Primary" parent="SqueezerTextAppearance.Medium"/>
    <style name="SqueezerTextAppearance.SongInfo.Secondary" parent="SqueezerTextAppearance.Small"/>
    <style name="SqueezerTextAppearance.SongInfo.Tertiary" parent="SqueezerTextAppearance.Small"/>

    <!-- Text on the NowPlayingFragment. -->
    <style name="SqueezerTextAppearance.NowPlaying.Primary" parent="SqueezerTextAppearance.SongInfo.Primary"/>
    <style name="SqueezerTextAppearance.NowPlaying.Secondary" parent="SqueezerTextAppearance.SongInfo.Secondary"/>
    <style name="SqueezerTextAppearance.NowPlaying.Tertiary" parent="SqueezerTextAppearance.SongInfo.Tertiary"/>

    <style name="SqueezerTextAppearance.NowPlaying.SongName" parent="SqueezerTextAppearance.NowPlaying.Primary"/>
    <style name="SqueezerTextAppearance.NowPlaying.AlbumName" parent="SqueezerTextAppearance.NowPlaying.Secondary"/>
    <style name="SqueezerTextAppearance.NowPlaying.ArtistName" parent="SqueezerTextAppearance.NowPlaying.Secondary"/>

    <!-- Text on the NowPlayingFragment mini player. -->
    <style name="SqueezerTextAppearance.NowPlayingMini.Primary" parent="SqueezerTextAppearance.SongInfo.Primary"/>
    <style name="SqueezerTextAppearance.NowPlayingMini.Secondary" parent="SqueezerTextAppearance.SongInfo.Secondary"/>
    <style name="SqueezerTextAppearance.NowPlayingMini.Tertiary" parent="SqueezerTextAppearance.SongInfo.Tertiary"/>

    <style name="SqueezerTextAppearance.NowPlayingMini.SongName" parent="SqueezerTextAppearance.NowPlayingMini.Primary"/>
    <style name="SqueezerTextAppearance.NowPlayingMini.AlbumName" parent="SqueezerTextAppearance.NowPlayingMini.Secondary"/>
    <style name="SqueezerTextAppearance.NowPlayingMini.ArtistName" parent="SqueezerTextAppearance.NowPlayingMini.Secondary"/>

    <style name="SqueezerNotificationTitle">
        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="SqueezerNotificationText">
        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
    </style>

    <style name="SqueezerTextAppearance.FloatLabel" parent="SqueezerTextAppearance.Small">
        <item name="android:textColor">?attr/floatLabelColor</item>
        <item name="android:textSize">11sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <!-- Widget appearance. Apply these using the "style" attribute. -->
    <style name="SqueezerWidget"/>

    <style name="SqueezerWidget.NowPlaying"/>

    <style name="SqueezerWidget.NowPlaying.SongName">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:hint">@string/unknown_track</item>
        <item name="android:singleLine">true</item>
        <item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlaying.SongName</item>
    </style>

    <style name="SqueezerWidget.NowPlaying.AlbumName">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:hint">@string/unknown_album</item>
        <item name="android:singleLine">true</item>
        <item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlaying.AlbumName</item>
    </style>

    <style name="SqueezerWidget.NowPlaying.ArtistName">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:hint">@string/unknown_artist</item>
        <item name="android:singleLine">true</item>
        <item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlaying.ArtistName</item>
    </style>

    <style name="SqueezerWidget.NowPlaying.Timestamp">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_horizontal</item>
        <item name="android:gravity">center_vertical</item>
        <item name="android:text">0:00</item>
        <item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlaying.Tertiary</item>
    </style>

    <style name="SqueezerWidget.NowPlayingMini"/>

    <style name="SqueezerWidget.NowPlayingMini.SongName">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:hint">@string/unknown_track</item>
        <item name="android:marqueeRepeatLimit">marquee_forever</item>
        <item name="android:singleLine">true</item>
        <item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlayingMini.SongName</item>
    </style>

    <style name="SqueezerWidget.NowPlayingMini.AlbumName">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:hint">@string/unknown_album</item>
        <item name="android:singleLine">true</item>
    </style>

    <!-- Media controller styles -->
    <style name="SqueezerWidget.MediaButton">
        <item name="android:layout_width">0dip</item>
        <item name="android:layout_height">52dip</item>
        <item name="android:layout_weight">1</item>
        <item name="android:background">@drawable/list_selector_holo_dark</item>
    </style>

    <style name="SqueezerWidget.MediaButton.Previous">
        <item name="android:src">?attr/ic_action_av_previous</item>
    </style>

    <style name="SqueezerWidget.MediaButton.Next">
        <item name="android:src">?attr/ic_action_av_next</item>
    </style>

    <style name="SqueezerWidget.MediaButton.Play">
        <item name="android:src">?attr/ic_action_av_play</item>
    </style>

    <style name="SqueezerWidget.MediaButton.Shuffle">
        <item name="android:src">?attr/ic_action_av_shuffle_off</item>
    </style>

    <style name="SqueezerWidget.MediaButton.Repeat">
        <item name="android:src">?attr/ic_action_av_repeat_off</item>
    </style>

    <style name="VolumePanel" parent="@android:style/Theme.Panel">
        <item name="android:windowAnimationStyle">@style/VolumeDialogAnimation</item>
    </style>

    <style name="VolumeDialogAnimation">
        <item name="android:windowExitAnimation">@android:anim/fade_out</item>
    </style>

    <!-- UndoBar -->
    <style name="UndoBar">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">bottom</item>
        <item name="android:layout_marginLeft">8dp</item>
        <item name="android:layout_marginRight">8dp</item>
        <item name="android:layout_marginBottom">16dp</item>
        <item name="android:orientation">horizontal</item>
        <item name="android:background">@android:drawable/toast_frame</item>
        <item name="android:clickable">true</item>
        <item name="android:divider">@drawable/undobar_divider</item>
    </style>

    <style name="UndoBarMessage">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_vertical</item>
        <item name="android:gravity">center_vertical</item>
        <item name="android:layout_marginTop">8dp</item>
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:layout_marginLeft">12dp</item>
        <item name="android:layout_marginRight">12dp</item>
        <item name="android:textAppearance">?android:textAppearanceMedium</item>
        <item name="android:textColor">#fff</item>
    </style>

    <style name="UndoBarButton">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_marginLeft">12dp</item>
        <item name="android:layout_marginRight">12dp</item>
        <item name="android:background">@drawable/undobar_button</item>
        <item name="android:drawableLeft">@drawable/ic_undobar_undo</item>
        <item name="android:drawablePadding">8dp</item>
        <item name="android:textAppearance">?android:textAppearanceSmall</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#fff</item>
        <item name="android:text">@string/undo</item>
    </style>
</resources>


text:
package br.com.etyllica.network.crunchbase.serialization;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import br.com.etyllica.network.crunchbase.model.investment.Investment;
import br.com.etyllica.network.crunchbase.model.investment.InvestmentList;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

public class AquisitionListSerializer implements JsonDeserializer<InvestmentList> {

	@Override
	public InvestmentList deserialize(JsonElement element, Type type,
			JsonDeserializationContext context) throws JsonParseException {

		List<Investment> list = new ArrayList<Investment>();

		JsonArray items = element.getAsJsonArray();

		for (int i = 0; i < items.size(); i++) {
			JsonObject item = items.get(i).getAsJsonObject();

			list.add((Investment) context.deserialize(item, Investment.class));
		}

		InvestmentList itemList = new InvestmentList();
		itemList.setItems(list);

		return itemList;
	}

}


text:
<!DOCTYPE HTML>

		<title>Nietzsches Butterfly: An Introduction to Chaos Theory and Chaos Engineering · Inherently Chaotic</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href='/assets/css/main.css' />

		<link rel="stylesheet" href='/assets/css/noscript.css' />

    Inherently Chaotic

Inherently Chaotic

Contact

Twitter

LinkedIn

GitHub

                                June 14, 2018

Nietzsches Butterfly: An Introduction to Chaos Theory and Chaos Engineering

Chaos theory was immortalized in fiction by "The Sound of Thunder," a short story that tells the tale of a contemporary presidential election being affected significantly by the death of a pre-historic butterfly.

Chaos theory was immortalized in fiction by “The Sound of Thunder,” a short story that tells the tale of a contemporary presidential election being affected significantly by the death of a pre-historic butterfly. The chain of coincidences that led to this altered future seemed to be random and unpredictable, but when all the changes are tracked-a gargantuan, realistically impossible undertaking-order does emerge. The problem is, you have to accept the idea of chaos trumping simple cause and effect first, before you can see the inherent order at all.

Chaos theory falls into that category of scientific ideas that few actually understand but many have heard of, due to its expansive, epic-sounding principles and thoughts. Who wouldn’t love to write a scientific paper entitled “If a butterfly flaps its wings in Brazil, does it cause a tornado in Texas?” Inherent to the theory is the idea that extremely small changes produce enormous effects, but ones that can only be described fully in retrospect. There are many great examples of this in nature, and climate change is one of them. Small atmospheric changes in one part of the globe can produce enormous effects years later in another region, thanks to the system feeding back changes into itself.

Does any of this ring bells when we compare the situations with modern day distributed systems in the age of internet where multitudes of services are being deployed every second across the system? Alright, let’s take a humanly example:

The neurons in a human brain only fire in response to another electric signal firing at them. If each neuron represents a self-enclosed one-dimensional object-in a space with billions of one-dimensional objects-then your brain has a hypothetical billion dimensions within it. So when one neuron fires, the path may be initially deterministic, but the cascade of electrochemical transmissions rapidly becomes unpredictable. From ten billion neurons, or dimensions, a single thought generates a hypothetically infinite number of chaotic paths. However, this process is not random - it is merely chaotic.

If the electric signals in your heart show signs of chaos and unpredictability, this can lead to a heart attack. On the other hand, an epileptic seizure is nothing more than a pattern of abnormally periodical order in the electrochemical signals in your brain. Either way, understanding that systems are inherently chaotic, despite having simple deterministic variables, is important to coming up with conclusions as to how they will behave in the future.

So here’s something very important to relate with the distributed systems, neurons and the electrochemical signals:

Consider a neuron as a single service from your system. Now, it is just a hypothetical scenario to consider billions of services in every distributed system. But, they’re definitely not any less than our humanly example. Next, consider the electrochemical signals as the requests. So, what happens when the distributed system receives requests? Passing through all the services, communication between the services, the trajectory will quickly become unpredictable if you have a huge number of services.

Similarly, in case of your heart and the distributed system, the chaos is inherently there. One way or another, we cannot disagree to the fact the understanding the systems which are inherently chaotic in nature is important to make the system more reliable to handle the failures which might arise at any point in future.

So, how do we find the point of failures in such a complex world of neurons? This is where experimentations pitch in. We perform well thought experiments on our systems to find the point of failures, fix them before they turn into a disaster in future. This is called proactive approach. We act before something goes wrong. Chaos Engineering is not just another discipline where you'll focus only on tools, it is a shift in culture and mindset as well.

In technical terms, as stated by Principles of Chaos:

Chaos Engineering is the discipline of experimenting on a distributed system
in order to build confidence in the system's capability
to withstand turbulent conditions in production.

Stay tuned for next steps of getting started with Chaos Engineering.

References/Credits:

nietzsches_butterfly

Principles of Chaos

        <form method="post" action="https://formspree.io/shantanud106@.com">

                Name
                <input type="text" name="name" id="name" />

                Email
                <input type="text" name="email" id="email" />

                Message
                <textarea name="message" id="message" rows="3"></textarea>

<input type="submit" value='Send A Message' />

        </form>

Address

                     Earth

Phone

+91-9284092596

Email

shantanud106@gmail.com

Social

Twitter

LinkedIn

GitHub

© Inherently Chaotic

Design: HTML5 UP

Hugo Port: curttimson


text:
APPHOME=${PWD}

## Load process configuration files
. config/patronload.config

if [ ! -d $config_tempfolder ]; then
        mkdir $config_tempfolder
fi

# Retrieve patron data file from the Banner SFTP server
# sshpass is not ideal, but key-based ssh auth wasn't a possibility
cd $config_tempfolder
sshpass \
        -p $config_banner_sftppass sftp -oStrictHostKeyChecking=no -oBatchMode=no -b - \
        $config_banner_sftpuser@$config_banner_sftphost << EOF
cd $config_banner_path
get $config_banner_filename
bye
EOF

# Retrieve the non-distance ZIP codes file from DFS
smbclient -U $config_ad_user -c "cd $config_ad_path; get $config_ad_zipcodefilename; get $config_ad_deptcodefilename; exit" //$config_ad_fileserver/$config_ad_share "$config_ad_pass"

# Sanitize the patron data file
cd $APPHOME
sed -i -e 's/\([0-9]"\)"/\1/g' $config_tempfolder/$config_banner_filename

declare -A affected_users

#todo: make this dynamic
declare -A patron_types
patron_types=(
        ["FACULTY"]="faculty"
        ["EMERITUS"]="emeritus"
        ["GRADASSISTANT"]="gradasst"
        ["GRADUATE"]="grad"
        ["HONOR"]="honors"
        ["UNDERGRADUATE"]="undergrad"
        ["HIGHSCHOOL"]="highschool"
        ["STAFF"]="staff"
)

if [[ $config_debug ]]; then
        echo "python fetch-analytics-report-data.py -k ${config_alma_analitycs_api_key} -p ${config_alma_analytics_expired_group_members_report_path} -f ${config_alma_analytics_unexpirations_barcode_field}"
fi

# Change groups where appropriate
if [[ $config_debug ]]; then
        echo "Processing unexpirations (`date`)..."
fi

venv/bin/python ./fetch-analytics-report-data.py -k ${config_alma_analitycs_api_key} -p ${config_alma_analytics_expired_group_members_report_path} -f ${config_alma_analytics_unexpirations_barcode_field} > $config_tempfolder/$config_alma_expired_patrons_list
for barcode in `cat $config_tempfolder/$config_alma_expired_patrons_list`; do
	if [[ $config_debug ]]; then
        	echo "Processing ${barcode}..."
	fi
        if [ $(grep -ic ${barcode} ${config_tempfolder}/${config_banner_filename}) -gt 0 ]; then
                zip_code="$(grep ${barcode} ${config_tempfolder}/${config_banner_filename} | awk -F, '{print $12}' | sed -e 's/\"//g' | cut -c1-5)"

                if [[ $zip_code =~ ^[0-9]{5}([-][0-9]{4})?$ ]]; then
                        patron_group=${patron_types[$(grep ${barcode} ${config_tempfolder}/${config_banner_filename} | awk -F, '{print $1}' | sed -e 's/\"//g')]}
                        if [ $(grep -ic ${zip_code} ${config_tempfolder}/${config_ad_zipcodefilename}) -eq 0 ]; then
                                patron_group="${patron_group}-distance"
                        fi

                        if [[ $config_do_unexpirations ]]; then
                                venv/bin/python change-patron-group.py -g ${patron_group} -k ${config_alma_analitycs_api_key} ${barcode}
                        else
                                echo "venv/bin/python change-patron-group.py -g ${patron_group} -k ${config_alma_analitycs_api_key} ${barcode}"
                        fi
                        affected_users[$barcode]=$patron_group
                fi
        fi
done

if [[ $config_debug ]]; then
        echo "${#affected_users[@]} users were unexpired."
fi

# Send summary of changes
if [[ ${#affected_users[@]} != 0 ]]; then
        declare message_body

        for key in "${!affected_users[@]}"; do
                message_body=$(printf "%s\nAssigning patron with barcode %s to group %s.\n" "$message_body" "$key" "${affected_users[$key]}")
        done

        if [[ $config_send_unexpiration_notice ]]; then
                printf "%s\n" "${message_body}" | /bin/mail -s "${config_unexpirations_notice_subject}" ${config_unexpirations_notice_recipient}
        else
                echo "Not sending unexpirations notice."
                printf "%s\n" "${message_body}" >&2
        fi
fi

if [[ $config_debug ]]; then
        echo "Finished processing unexpirations (`date`)."
fi

cd $APPHOME


text:
package io.onedecision.engine.decisions.web;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import io.onedecision.engine.TestApplication;
import io.onedecision.engine.decisions.examples.ExamplesConstants;
import io.onedecision.engine.decisions.model.ui.DecisionInput;
import io.onedecision.engine.decisions.model.ui.DecisionModel;
import io.onedecision.engine.decisions.model.ui.DecisionOutput;
import io.onedecision.engine.decisions.model.ui.DecisionRule;

import java.util.List;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

/**
 * @author Tim Stephenson
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestApplication.class)
@WebAppConfiguration
public class DecisionUIModelControllerTest implements ExamplesConstants {

    @Autowired
    private DecisionUIModelController controller;

    @Test
    @Ignore
    // TODO currently failing see DecisionExpression.expressions
    public void testInstall() {
        controller.installExamples(TENANT_ID);
    }

    @Test
    @Ignore
    // TODO UI to be dropped?
    public void testLifecycle() {
        DecisionModel model = new DecisionModel();
        model.setName("Test");
        model.getInputs().add(
                new DecisionInput().withName("timeSinceLogin").withLabel(
                        "Time since login"));
        model.getOutputs().add(
                new DecisionOutput().withName("subjectLine").withLabel(
                        "Subject line"));
        model.getRules().add(new DecisionRule()
                .withInputEntries(new String[] { "<P7D", ">=P7D" })
                .withOutputEntries(new String[] { "foo", "bar" }));

        model = controller.createModelForTenant(model, TENANT_ID);
        assertNotNull(model);
        assertNotNull(model.getId());

        List<DecisionModel> models = controller.listForTenant(TENANT_ID);
        assertEquals(1, models.size());
        // assertEquals(model, models.get(0));
        assertEquals(model.getId(), models.get(0).getId());
        assertEquals(model.getName(), models.get(0).getName());
        assertEquals(model.getTenantId(), models.get(0).getTenantId());
        assertEquals(model.getInputs().size(), models.get(0)
                .getInputs().size());
        assertEquals(model.getOutputs().size(), models.get(0)
                .getOutputs().size());

        // assertEquals(model.hashCode(), models.get(0).hashCode());
    }

}


text:
package net.firejack.platform.api.config;

import net.firejack.platform.api.config.domain.Config;
import net.firejack.platform.api.config.model.ConfigType;
import net.firejack.platform.core.domain.ListLookup;
import net.firejack.platform.core.response.ServiceResponse;

import java.util.List;

public interface IConfigService {

	/**
	 * Read config by id
	 *
	 * @param configId config id
	 *
	 * @return founded config
	 */
	ServiceResponse<Config> readConfig(Long configId);

	/**
	 * Read config by lookup
	 *
	 * @param lookup lookup
	 * @param type config type
	 *
	 * @return founded type
	 */
	ServiceResponse<Config> findByLookup(String lookup, ConfigType type);

    ServiceResponse<Config> findListByLookup(ListLookup listLookup);

	/**
	 * Read all by parent id
	 *
	 * @param registryNodeId parent id
	 *
	 * @return founded configs
	 */
	ServiceResponse<Config> readAllConfigsByRegistryNodeId(Long registryNodeId);

	/**
	 * Search configs  by parent and term expression
	 *
	 * @param parentId parent id
	 * @param term term expression
	 *
	 * @return founded configs
	 */
	ServiceResponse<Config> searchConfig(Long parentId, String term);

		/**
	 * Create new config
	 *
	 * @param data config data
	 *
	 * @return created config
	 */
	ServiceResponse<Config> createConfig(Config data);

    ServiceResponse<Config> createBatchConfig(List<Config> configs);

	/**
	 * Update config by id
	 *
	 * @param configId config id
	 *
	 * @param data config config
	 *
	 * @return updated config
	 */
	ServiceResponse<Config> updateConfig(Long configId, Config data);

	/**
	 * Delete config by id
	 *
	 * @param configId config id
	 *
	 * @return deleted config
	 */
	ServiceResponse<Config> deleteConfig(Long configId);
}


text:
from google.cloud import gaming_v1beta

async def sample_get_game_server_deployment():
    # Create a client
    client = gaming_v1beta.GameServerDeploymentsServiceAsyncClient()

    # Initialize request argument(s)
    request = gaming_v1beta.GetGameServerDeploymentRequest(
        name="name_value",
    )

    # Make the request
    response = await client.get_game_server_deployment(request=request)

    # Handle the response
    print(response)

# [END gameservices_v1beta_generated_GameServerDeploymentsService_GetGameServerDeployment_async]


text:
<form id="form-place" action="#">
    <fieldset>
        <legend>Add/Edit Event</legend>

            Name

                <input id="name" type="text" class="input-medium" value="<%= name %>">
                Less than 15 characters

            Label

                <select id="label">
                    <option value="club" selected>club</option>
                    <option value="rock">rock</option>
                </select>

            Ticket price

                <input id="price" type="text" class="input-small" value="<%= price %>">
                Number between 0.5 and 100

            <button type="submit" class="btn btn-primary" id="save">Save</button>
            <button type="submit" class="btn" id="cancel">Cancel</button>
            <button type="submit" class="btn btn-danger pull-right" id="delete">Delete</button>

    </fieldset>
</form>


text:
var ajax = require('./ajax');
var utf8 = require('utf8');
var fs = require('fs');
var http = require('http');
var md5 = require('MD5');
var LastfmAPI = require('lastfmapi');

var lastfmScrobble = function(lastfm, track) {

  var lfm = new LastfmAPI({
      'api_key' : lastfm.api_key,
      'secret' : lastfm.api_secret
  });

  // step 1.
  // if(!lastfm.session_key) {
  //   console.log('go here', 'http://www.last.fm/api/auth/?api_key=' + lastfm.api_key + '&cb=http://example.com');
  //   return;
  // }
  //
  // step 2
  // lfm.authenticate('ENTER_TOKEN_HERE', function (err, session) {
  //     if (err) { throw err; }
  //     console.log(session); // {"name": "LASTFM_USERNAME", "key": "THE_USER_SESSION_KEY"}
  // });
  //

  lfm.setSessionCredentials(lastfm.user, lastfm.session_key);

  lfm.track.scrobble({
      'artist' : track.artist,
      'track' : track.track,
      'timestamp' : track.played_time,
      'duration' : track.duration
  }, function (err, scrobbles) {
  });

  // ajax.get(options).done(function(data) {
  //   console.log('we are back with data..', data);
  // })

}

module.exports = lastfmScrobble;


text:
package io.quarkus.kafka.client.serialization;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;

final class ObjectMapperProducer {

    private ObjectMapperProducer() {
    }

    // Try to get the ObjectMapper from Arc but fallback to regular ObjectMapper creation
    // The fallback could be used for example in unit tests where Arc has not been initialized
    static ObjectMapper get() {
        ObjectMapper objectMapper = null;
        ArcContainer container = Arc.container();
        if (container != null) {
            objectMapper = container.instance(ObjectMapper.class).get();
        }
        return objectMapper != null ? objectMapper : new ObjectMapper();
    }
}


text:
package ca.uhn.fhir.context;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.Test;

import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.MyOrganization;
import ca.uhn.fhir.parser.MyPatient;
import ca.uhn.fhir.util.TestUtil;

public class ModelExtensionTest {
	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ModelExtensionTest.class);
	private FhirContext ourCtx = FhirContext.forDstu1();

	@Test
	public void testModelExtension() throws DataFormatException {
		MyOrganization org = new MyOrganization();
		org.getName().setValue("org0");

		MyPatient patient = new MyPatient();
		patient.addIdentifier("foo", "bar");
		patient.getManagingOrganization().setResource(org);

		IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
		String str = p.encodeResourceToString(patient);

		ourLog.info(str);

		MyPatient parsed = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
		assertEquals("foo", parsed.getIdentifierFirstRep().getSystem().getValueAsString());

//		assertEquals(MyOrganization.class, parsed.getManagingOrganization().getResource().getClass());
//		MyOrganization parsedOrg = (MyOrganization) parsed.getManagingOrganization().getResource();
//		assertEquals("arg0", parsedOrg.getName().getValue());
	}

	@AfterClass
	public static void afterClassClearContext() {
		TestUtil.clearAllStaticFieldsForUnitTest();
	}

}


text:
git-spaces(1) -- Multiple workspaces for git
=================================================

## SYNOPSIS

`git-spaces` <command> [args]

## DESCRIPTION

  Mutiple working directories for a single repository.

## EXAMPLES

  * Initalize a git working directory for spaces:

    $ git spaces init

  * Create a new space:

    $ git spaces create some-feature

## AUTHOR

Written by Blake Taylor <<blakeforst@gmail.com>>

## REPORTING BUGS

<<http://github.com/blakefrost/git-spaces/issues>>


text:
Open File in Visual Studio Code

[download](https://github.com/mohemohe/OpenInVSCode/releases)

please put the "OpenInVSCode.exe" in the same location to the "Update.exe".
(probably to "AppData\Local\Code")

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


text:
using namespace vgui;

CHudBaseTimer::CHudBaseTimer(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
{
	m_iMinutes = 0;
	m_iSeconds = 0;
	SetLabelText(L"");
}

void CHudBaseTimer::SetMinutes(int minutes)
{
	m_iMinutes = minutes;
}

void CHudBaseTimer::SetSeconds(int seconds)
{
	m_iSeconds = seconds;
}

void CHudBaseTimer::PaintTime(HFont font, int xpos, int ypos, int mins, int secs)
{
	surface()->DrawSetTextFont(font);
	wchar_t unicode[6];
	swprintf(unicode, L"%d:%.2d", mins, secs);

	surface()->DrawSetTextPos(xpos, ypos);
	surface()->DrawUnicodeString( unicode );
}

void CHudBaseTimer::Paint()
{
	float alpha = m_flAlphaOverride / 255;
	Color fgColor = GetFgColor();
	fgColor[3] *= alpha;
	SetFgColor( fgColor );

	surface()->DrawSetTextColor(GetFgColor());
	PaintTime( m_hNumberFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds );

	// draw the overbright blur
	for (float fl = m_flBlur; fl > 0.0f; fl -= 1.0f)
	{
		if (fl >= 1.0f)
		{
			PaintTime(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds);
		}
		else
		{
			// draw a percentage of the last one
			Color col = GetFgColor();
			col[3] *= fl;
			surface()->DrawSetTextColor(col);
			PaintTime(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds);
		}
	}

	BaseClass::PaintLabel();
}

void CHudBaseTimer::SetToPrimaryColor()
{
	SetFgColor(m_TextColor);
}

void CHudBaseTimer::SetToSecondaryColor()
{
	SetFgColor(m_FlashColor);
}


text:
/* eslint-disable camelcase */
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * This file exports all controls available for use in chart plugins internal to Superset.
 * It is not recommended to use the controls here for any third-party plugins.
 *
 * While the React components located in `controls/components` represent different
 * types of controls (CheckboxControl, SelectControl, TextControl, ...), the controls here
 * represent instances of control types, that can be reused across visualization types.
 *
 * When controls are reused across viz types, their values are carried over as a user
 * changes the chart types.
 *
 * While the keys defined in the control itself get passed to the controlType as props,
 * here's a list of the keys that are common to all controls, and as a result define the
 * control interface.
 */
import React from 'react';
import {
  FeatureFlag,
  t,
  getCategoricalSchemeRegistry,
  getSequentialSchemeRegistry,
  isFeatureEnabled,
  SequentialScheme,
  legacyValidateInteger,
  validateNonEmpty,
} from '@superset-ui/core';

import {
  formatSelectOptions,
  D3_FORMAT_OPTIONS,
  D3_FORMAT_DOCS,
  D3_TIME_FORMAT_OPTIONS,
  D3_TIME_FORMAT_DOCS,
  DEFAULT_TIME_FORMAT,
  DEFAULT_NUMBER_FORMAT,
} from '../utils';
import { TIME_FILTER_LABELS, TIME_COLUMN_OPTION } from '../constants';
import {
  Metric,
  SharedControlConfig,
  ColumnMeta,
  ExtraControlProps,
  SelectControlConfig,
} from '../types';
import { ColumnOption } from '../components/ColumnOption';

import {
  dnd_adhoc_filters,
  dnd_adhoc_metric,
  dnd_adhoc_metrics,
  dnd_granularity_sqla,
  dnd_sort_by,
  dnd_secondary_metric,
  dnd_size,
  dnd_x,
  dnd_y,
  dndColumnsControl,
  dndEntity,
  dndGroupByControl,
  dndSeries,
  dnd_adhoc_metric_2,
} from './dndControls';

const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
const sequentialSchemeRegistry = getSequentialSchemeRegistry();

export const PRIMARY_COLOR = { r: 0, g: 122, b: 135, a: 1 };

const ROW_LIMIT_OPTIONS = [10, 50, 100, 250, 500, 1000, 5000, 10000, 50000];
const SERIES_LIMITS = [5, 10, 25, 50, 100, 500];

type Control = {
  savedMetrics?: Metric[] | null;
  default?: unknown;
};

const groupByControl: SharedControlConfig<'SelectControl', ColumnMeta> = {
  type: 'SelectControl',
  label: t('Group by'),
  multi: true,
  freeForm: true,
  clearable: true,
  default: [],
  includeTime: false,
  description: t(
    'One or many columns to group by. High cardinality groupings should include a sort by metric ' +
      'and series limit to limit the number of fetched and rendered series.',
  ),
  sortComparator: (a: { label: string }, b: { label: string }) =>
    a.label.localeCompare(b.label),
  optionRenderer: c => <ColumnOption showType column={c} />,
  valueRenderer: c => <ColumnOption column={c} />,
  valueKey: 'column_name',
  allowAll: true,
  filterOption: ({ data: opt }, text: string) =>
    (opt.column_name &&
      opt.column_name.toLowerCase().includes(text.toLowerCase())) ||
    (opt.verbose_name &&
      opt.verbose_name.toLowerCase().includes(text.toLowerCase())) ||
    false,
  promptTextCreator: (label: unknown) => label,
  mapStateToProps(state, { includeTime }) {
    const newState: ExtraControlProps = {};
    if (state.datasource) {
      const options = state.datasource.columns.filter(c => c.groupby);
      if (includeTime) {
        options.unshift(TIME_COLUMN_OPTION);
      }
      newState.options = options;
    }
    return newState;
  },
  commaChoosesOption: false,
};

const metrics: SharedControlConfig<'MetricsControl'> = {
  type: 'MetricsControl',
  multi: true,
  label: t('Metrics'),
  validators: [validateNonEmpty],
  mapStateToProps: ({ datasource }) => ({
    columns: datasource ? datasource.columns : [],
    savedMetrics: datasource ? datasource.metrics : [],
    datasource,
    datasourceType: datasource?.type,
  }),
  description: t('One or many metrics to display'),
};

const metric: SharedControlConfig<'MetricsControl'> = {
  ...metrics,
  multi: false,
  label: t('Metric'),
  description: t('Metric'),
};

const datasourceControl: SharedControlConfig<'DatasourceControl'> = {
  type: 'DatasourceControl',
  label: t('Datasource'),
  default: null,
  description: null,
  mapStateToProps: ({ datasource, form_data }) => ({
    datasource,
    form_data,
  }),
};

const viz_type: SharedControlConfig<'VizTypeControl'> = {
  type: 'VizTypeControl',
  label: t('Visualization Type'),
  default: 'table',
  description: t('The type of visualization to display'),
};

const color_picker: SharedControlConfig<'ColorPickerControl'> = {
  type: 'ColorPickerControl',
  label: t('Fixed Color'),
  description: t('Use this to define a static color for all circles'),
  default: PRIMARY_COLOR,
  renderTrigger: true,
};

const metric_2: SharedControlConfig<'MetricsControl'> = {
  ...metric,
  label: t('Right Axis Metric'),
  clearable: true,
  description: t('Choose a metric for right axis'),
};

const linear_color_scheme: SharedControlConfig<'ColorSchemeControl'> = {
  type: 'ColorSchemeControl',
  label: t('Linear Color Scheme'),
  choices: () =>
    (sequentialSchemeRegistry.values() as SequentialScheme[]).map(value => [
      value.id,
      value.label,
    ]),
  default: sequentialSchemeRegistry.getDefaultKey(),
  clearable: false,
  description: '',
  renderTrigger: true,
  schemes: () => sequentialSchemeRegistry.getMap(),
  isLinear: true,
};

const secondary_metric: SharedControlConfig<'MetricsControl'> = {
  ...metric,
  label: t('Color Metric'),
  default: null,
  validators: [],
  description: t('A metric to use for color'),
};

const columnsControl: typeof groupByControl = {
  ...groupByControl,
  label: t('Columns'),
  description: t('One or many columns to pivot as columns'),
};

const druid_time_origin: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: TIME_FILTER_LABELS.druid_time_origin,
  choices: [
    ['', 'default'],
    ['now', 'now'],
  ],
  default: null,
  description: t(
    'Defines the origin where time buckets start, ' +
      'accepts natural dates as in `now`, `sunday` or `1970-01-01`',
  ),
};

const granularity: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: TIME_FILTER_LABELS.granularity,
  default: 'one day',
  choices: [
    [null, 'all'],
    ['PT5S', '5 seconds'],
    ['PT30S', '30 seconds'],
    ['PT1M', '1 minute'],
    ['PT5M', '5 minutes'],
    ['PT30M', '30 minutes'],
    ['PT1H', '1 hour'],
    ['PT6H', '6 hour'],
    ['P1D', '1 day'],
    ['P7D', '7 days'],
    ['P1W', 'week'],
    ['week_starting_sunday', 'week starting Sunday'],
    ['week_ending_saturday', 'week ending Saturday'],
    ['P1M', 'month'],
    ['P3M', 'quarter'],
    ['P1Y', 'year'],
  ],
  description: t(
    'The time granularity for the visualization. Note that you ' +
      'can type and use simple natural language as in `10 seconds`, ' +
      '`1 day` or `56 weeks`',
  ),
};

const granularity_sqla: SharedControlConfig<'SelectControl', ColumnMeta> = {
  type: 'SelectControl',
  label: TIME_FILTER_LABELS.granularity_sqla,
  description: t(
    'The time column for the visualization. Note that you ' +
      'can define arbitrary expression that return a DATETIME ' +
      'column in the table. Also note that the ' +
      'filter below is applied against this column or ' +
      'expression',
  ),
  default: (c: Control) => c.default,
  clearable: false,
  optionRenderer: c => <ColumnOption showType column={c} />,
  valueRenderer: c => <ColumnOption column={c} />,
  valueKey: 'column_name',
  mapStateToProps: state => {
    const props: Partial<SelectControlConfig<ColumnMeta>> = {};
    if (state.datasource) {
      props.options = state.datasource.columns.filter(c => c.is_dttm);
      props.default = null;
      if (state.datasource.main_dttm_col) {
        props.default = state.datasource.main_dttm_col;
      } else if (props.options && props.options.length > 0) {
        props.default = props.options[0].column_name;
      }
    }
    return props;
  },
};

const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  label: TIME_FILTER_LABELS.time_grain_sqla,
  default: 'P1D',
  description: t(
    'The time granularity for the visualization. This ' +
      'applies a date transformation to alter ' +
      'your time column and defines a new time granularity. ' +
      'The options here are defined on a per database ' +
      'engine basis in the Superset source code.',
  ),
  mapStateToProps: ({ datasource }) => ({
    choices: datasource?.time_grain_sqla || null,
  }),
};

const time_range: SharedControlConfig<'DateFilterControl'> = {
  type: 'DateFilterControl',
  freeForm: true,
  label: TIME_FILTER_LABELS.time_range,
  default: t('No filter'), // this value is translated, but the backend wouldn't understand a translated value?
  description: t(
    'The time range for the visualization. All relative times, e.g. "Last month", ' +
      '"Last 7 days", "now", etc. are evaluated on the server using the server\'s ' +
      'local time (sans timezone). All tooltips and placeholder times are expressed ' +
      'in UTC (sans timezone). The timestamps are then evaluated by the database ' +
      "using the engine's local timezone. Note one can explicitly set the timezone " +
      'per the ISO 8601 format if specifying either the start and/or end time.',
  ),
  mapStateToProps: ({ datasource, form_data }) => ({
    datasource,
    endpoints: form_data?.time_range_endpoints || null,
  }),
};

const row_limit: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: t('Row limit'),
  validators: [legacyValidateInteger],
  default: 10000,
  choices: formatSelectOptions(ROW_LIMIT_OPTIONS),
  description: t('Limits the number of rows that get displayed.'),
};

const limit: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: t('Series limit'),
  validators: [legacyValidateInteger],
  choices: formatSelectOptions(SERIES_LIMITS),
  clearable: true,
  description: t(
    'Limits the number of series that get displayed. A joined subquery (or an extra phase ' +
      'where subqueries are not supported) is applied to limit the number of series that get ' +
      'fetched and rendered. This feature is useful when grouping by high cardinality ' +
      'column(s) though does increase the query complexity and cost.',
  ),
};

const series_limit: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: t('Series limit'),
  validators: [legacyValidateInteger],
  choices: formatSelectOptions(SERIES_LIMITS),
  description: t(
    'Limits the number of series that get displayed. A joined subquery (or an extra phase ' +
      'where subqueries are not supported) is applied to limit the number of series that get ' +
      'fetched and rendered. This feature is useful when grouping by high cardinality ' +
      'column(s) though does increase the query complexity and cost.',
  ),
};

const sort_by: SharedControlConfig<'MetricsControl'> = {
  type: 'MetricsControl',
  label: t('Sort by'),
  default: null,
  description: t(
    'Metric used to define how the top series are sorted if a series or row limit is present. ' +
      'If undefined reverts to the first metric (where appropriate).',
  ),
  mapStateToProps: ({ datasource }) => ({
    columns: datasource?.columns || [],
    savedMetrics: datasource?.metrics || [],
    datasource,
    datasourceType: datasource?.type,
  }),
};

const series: typeof groupByControl = {
  ...groupByControl,
  label: t('Series'),
  multi: false,
  default: null,
  description: t(
    'Defines the grouping of entities. ' +
      'Each series is shown as a specific color on the chart and ' +
      'has a legend toggle',
  ),
};

const entity: typeof groupByControl = {
  ...groupByControl,
  label: t('Entity'),
  default: null,
  multi: false,
  validators: [validateNonEmpty],
  description: t('This defines the element to be plotted on the chart'),
};

const x: SharedControlConfig<'MetricsControl'> = {
  ...metric,
  label: t('X Axis'),
  description: t('Metric assigned to the [X] axis'),
  default: null,
};

const y: SharedControlConfig<'MetricsControl'> = {
  ...metric,
  label: t('Y Axis'),
  default: null,
  description: t('Metric assigned to the [Y] axis'),
};

const size: SharedControlConfig<'MetricsControl'> = {
  ...metric,
  label: t('Bubble Size'),
  description: t('Metric used to calculate bubble size'),
  default: null,
};

const y_axis_format: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: t('Y Axis Format'),
  renderTrigger: true,
  default: DEFAULT_NUMBER_FORMAT,
  choices: D3_FORMAT_OPTIONS,
  description: D3_FORMAT_DOCS,
  mapStateToProps: state => {
    const showWarning = state.controls?.comparison_type?.value === 'percentage';
    return {
      warning: showWarning
        ? t(
            'When `Calculation type` is set to "Percentage change", the Y ' +
              'Axis Format is forced to `.1%`',
          )
        : null,
      disabled: showWarning,
    };
  },
};

const x_axis_time_format: SharedControlConfig<'SelectControl'> = {
  type: 'SelectControl',
  freeForm: true,
  label: t('Time format'),
  renderTrigger: true,
  default: DEFAULT_TIME_FORMAT,
  choices: D3_TIME_FORMAT_OPTIONS,
  description: D3_TIME_FORMAT_DOCS,
};

const adhoc_filters: SharedControlConfig<'AdhocFilterControl'> = {
  type: 'AdhocFilterControl',
  label: t('Filters'),
  default: null,
  description: '',
  mapStateToProps: ({ datasource, form_data }) => ({
    columns: datasource?.columns.filter(c => c.filterable) || [],
    savedMetrics: datasource?.metrics || [],
    // current active adhoc metrics
    selectedMetrics:
      form_data.metrics || (form_data.metric ? [form_data.metric] : []),
    datasource,
  }),
};

const color_scheme: SharedControlConfig<'ColorSchemeControl'> = {
  type: 'ColorSchemeControl',
  label: t('Color Scheme'),
  default: categoricalSchemeRegistry.getDefaultKey(),
  renderTrigger: true,
  choices: () => categoricalSchemeRegistry.keys().map(s => [s, s]),
  description: t('The color scheme for rendering chart'),
  schemes: () => categoricalSchemeRegistry.getMap(),
  mapStateToProps: state => ({
    dashboardId: state?.form_data?.dashboardId,
  }),
};

const enableExploreDnd = isFeatureEnabled(
  FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP,
);

const sharedControls = {
  metrics: enableExploreDnd ? dnd_adhoc_metrics : metrics,
  metric: enableExploreDnd ? dnd_adhoc_metric : metric,
  datasource: datasourceControl,
  viz_type,
  color_picker,
  metric_2: enableExploreDnd ? dnd_adhoc_metric_2 : metric_2,
  linear_color_scheme,
  secondary_metric: enableExploreDnd ? dnd_secondary_metric : secondary_metric,
  groupby: enableExploreDnd ? dndGroupByControl : groupByControl,
  columns: enableExploreDnd ? dndColumnsControl : columnsControl,
  druid_time_origin,
  granularity,
  granularity_sqla: enableExploreDnd ? dnd_granularity_sqla : granularity_sqla,
  time_grain_sqla,
  time_range,
  row_limit,
  limit,
  timeseries_limit_metric: enableExploreDnd ? dnd_sort_by : sort_by,
  orderby: enableExploreDnd ? dnd_sort_by : sort_by,
  series: enableExploreDnd ? dndSeries : series,
  entity: enableExploreDnd ? dndEntity : entity,
  x: enableExploreDnd ? dnd_x : x,
  y: enableExploreDnd ? dnd_y : y,
  size: enableExploreDnd ? dnd_size : size,
  y_axis_format,
  x_axis_time_format,
  adhoc_filters: enableExploreDnd ? dnd_adhoc_filters : adhoc_filters,
  color_scheme,
  series_columns: enableExploreDnd ? dndColumnsControl : columnsControl,
  series_limit,
  series_limit_metric: enableExploreDnd ? dnd_sort_by : sort_by,
  legacy_order_by: enableExploreDnd ? dnd_sort_by : sort_by,
};

export { sharedControls, dndEntity, dndColumnsControl };


text:
import { ElementRef } from '@angular/core';
import { CallbackType } from './prism.type';

export interface PrismInterface {
  async: boolean;
  callback?: CallbackType;
  code: string;
  el: ElementRef;
  language: string;
  interpolation?: Object;
}

export interface OptionsInterface  {
  async?: boolean;
  callback?: CallbackType;
  code?: string;
  interpolation?: Object;
};


text:
#ifndef GONGNV_H
#define GONGNV_H
#include "Role.h"
class GongNv : public Role
{
    Q_OBJECT
public:
    GongNv();
    void GuanChuanSheJi();
    void JingZhunSheJi();
    void normal();
    void askForSkill(network::Command* cmd);
public slots:
    void onOkClicked();
    void onCancelClicked();
    void cardAnalyse();
    void ShanGuangXianJing();
    void JuJi();
private:
    bool JuJiAdditon;
};

#endif // GONGNV_H


text:
import scrapy
import sys
import codecs
import locale
from datetime import datetime

from routescraper.generate_queue_items import all_queue_items
from routescraper.items import RouteItem

class JetStarSpider(scrapy.Spider):
    name = "jetstar"
    allowed_domains = ["jetstar.com", "airasia.com"]
    start_urls = ['http://www.airasia.com/ot/en/home.page?cid=1']

    def __init__(self, data=None):
        sys.stdout = codecs.getwriter(
            locale.getpreferredencoding())(sys.stdout)
        reload(sys)
        sys.setdefaultencoding('utf-8')
        if not data:
            data = all_queue_items('jetstar')
        self.data = data
        super(JetStarSpider, self).__init__()

    def parse(self, response):
        for record in self.data:
            url = (
                "https://booking.jetstar.com/sg/en/booking/search-flights"
                "?origin1={0}&destination1={1}&departuredate1={2}"
                "&adults={3}&children={4}&infants={5}&currency=SGD"
                "&uuid={6}".format(
                    record['origin'], record['destination'],
                    record['departure_date'], record['num_adult'],
                    record['num_child'], record['num_infant'],
                    record['uuid']
                )
            )
            yield scrapy.Request(
                url, callback=self.parse_results,
                meta=record, dont_filter=True
            )

    def parse_results(self, response):
        item = RouteItem()

        item['origin'] = response.meta['origin']
        item['destination'] = response.meta['destination']
        item['num_adult'] = response.meta['num_adult']
        item['num_child'] = response.meta['num_child']
        item['num_infant'] = response.meta['num_infant']
        depart = response.meta['departure_date']
        item['uuid'] = response.meta['uuid']
        item['site'] = 'jetstar'

        elem = response.xpath(
            "//div[contains(@class, 'fare-row js-fare-row')]"
        )
        try:
            elem = elem[0]
        except:
            elem = None
            self.logger.info('Flightinfo not available for {}'.format(depart))

        if elem:
            depart_time = elem.xpath(
                ".//div[@class="
                "'columns fare__departure-time "
                "js-departure-time departuretime'"
                "]/text()"
            ).extract_first().strip()
            am_pm = elem.xpath(
                ".//div[@class="
                "'columns fare__departure-time "
                "js-departure-time departuretime'"
                "]/span/text()"
            ).extract_first().strip()
            full_depart_datetime = depart + ' ' + depart_time +\
                ' ' + am_pm.upper()
            depart_date_obj = datetime.strptime(
                full_depart_datetime, "%Y-%m-%d %I:%M %p")
            item['departure_date'] = depart_date_obj.strftime('%Y-%m-%d %H:%M')
            item['days_to_flight'] = (depart_date_obj - datetime.today()).days
            price = elem.xpath(
                ".//span[@class='price js-price']/text()"
            ).extract_first().strip()
            price = price.replace(',', '')
            item['price'] = float(price)
            item['price_date'] = datetime.now().strftime('%Y-%m-%d')
            item['currency'] = elem.xpath(
                ".//span[@class='currency-symbol']/text()"
            ).extract_first()
            if not item['currency']:
                item['currency'] = '$'
            else:
                item['currency'] = item['currency'].strip()

            item['flight_number'] = elem.xpath(
                ".//div[@class='row fare__info-flight-number']"
                "/div[@class='medium-11 columns']/strong/text()"
            ).extract_first().strip()

            arrival_date = elem.xpath(
                ".//strong[@class='arrivalstation']/text()"
            ).extract_first().strip()
            arrival_date = arrival_date.replace(',', '')
            arrival_date_obj = datetime.strptime(
                arrival_date, "%I:%M%p %A %d %B %Y")
            item['arrival_date'] = arrival_date_obj.strftime('%Y-%m-%d %H:%M')

            item['fare_class'] = elem.xpath(
                ".//strong[@class='cabintype']/text()"
            ).extract_first().strip()
            item['airline_name'] = elem.xpath(
                ".//strong[@class='operatedby']/text()"
            ).extract_first().strip()

            yield item


text:
package main

import (
	"flag"
	"fmt"
	"log"

	//"github.com/GreenNav/service-database/database"
	"github.com/GreenNav/service-database/database/sqlite"
	"github.com/GreenNav/service-database/importer"
)

var dbTypeFlagDescription = "Determines which database to use. Can be sqlite or postgres"
var dbFileFlagDescription = "Sets the name of the database file to import to"
var dbSchemaFlagDescription = "File with the database setup queries"
var importFlagDescription = "Pbf file to import"

var dbTypeFlag = flag.String("dbtype", "sqlite", dbTypeFlagDescription)
var dbFileFlag = flag.String("dbfile", "gn.db", dbFileFlagDescription)
var dbSchemaFlag = flag.String("dbschema", "./schemata/sqlite.sql", dbSchemaFlagDescription)
var importFlag = flag.String("import", "", importFlagDescription)

func init() {
	flag.StringVar(dbTypeFlag, "d", "sqlite", dbTypeFlagDescription+" (shorthand)")
	flag.StringVar(dbFileFlag, "f", "gn.db", dbFileFlagDescription+" (shorthand)")
	flag.StringVar(dbSchemaFlag, "s", "./schemata/sqlite.sql", dbSchemaFlagDescription+" (shorthand)")
	flag.StringVar(importFlag, "i", "", importFlagDescription+" (shorthand)")
}

func main() {
	flag.Parse()

	if *importFlag == "" {
		log.Fatal("Please use the -import flag to import a .pbf file")
	}

	fmt.Println("Creating the database")
	db, err := sqlite.CreateEmpty(*dbFileFlag, *dbSchemaFlag)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Importing the file")
	err = importer.WriteToDatabase(*importFlag, db)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Closing database")
	db.Close()
	fmt.Println("Done!")
}


text:
"""
miriam.py - clean up stale files in target directories
"""

import os
import stat
import time
import logging
import argparse
import shutil
import zipfile

logging.basicConfig(filename='/var/log/miriam.log',
                    format='%(asctime)s%(message)s',
                    formatdmt='%m/%d/%Y %I:%M:%S %p',
                    level=logging.INFO)

def is_file(obj):
    return stat.S_ISREG(os.stat(obj).st_mode)

def scan_dir(target_dir):
    ''' Scans directory and returns list of dictionaries describing the objects
        in the directory.

        Args:
            target_dir: string - Path to directory to scan
        Returns:
            dir_listing: list of dicts describing the objects in the directory
    '''
    def remove_hidden_files(dir_list):
        """ Remove hidden files from dir listing."""
        return [item for item in dir_list if '.' not in item[:1]]

    dir_listing = remove_hidden_files(os.listdir(target_dir))
    logging.info("scan_dir -- dir_listing: %r", dir_listing)
    result_list = []
    for dir_obj in dir_listing:
        path = target_dir if '.' not in target_dir else ''
        result_list.append({'name': dir_obj, 'last_access_time':
                           os.stat(path + "/" + dir_obj).st_atime,
                           'parent_dir': path})

    return result_list

def find_old_files(dir_listing, expiration):
    ''' This takes the listing of object dictionaries in the directory and
        compares their last_accessed_time against current time to determine if
        they are older than 30 days. If so, add them to a list.

        Args:
            dir_listing: list of dictionaries representing file objects.
            expiration:  integer representing the number of days before a file
            expires and is considered stale.
        Returns:
            stale_obj_list: list of file objects older than given time period
    '''
    SECS_PER_DAY = 86400
    stale_file_list = []
    for file_obj in dir_listing:
        logging.info('find_old_files -- dir: %s, name: %s, last_access_time:\
                     %r', file_obj['parent_dir'],
                     file_obj['name'],
                     time.ctime(file_obj['last_access_time']))
        if (time.time() - file_obj['last_access_time']) / SECS_PER_DAY\
                > expiration:
            logging.info("expiration: %r", expiration)
            logging.info("find_old_files -- Appending %r to stale files list",
                         file_obj['name'])
            stale_file_list.append(file_obj)

    return stale_file_list

def delete_expired_files(file_list, target_dir):
    """ Delete the file objects passed in

        Args:
            file_list: list of file objects
            target_dir:    directory to clean
    """
    for file_obj in file_list:
        if is_file(target_dir + "/" + file_obj['name']):
            logging.info('Deleting %r.', file_obj['name'])
            try:
                os.remove(target_dir + "/" + file_obj['name'])
            except OSError:     # We are dealing with a directory
                shutil.rmtree(target_dir + "/" + file_obj['name'])
        else:
            logging.info('Deleting %r and all its contents.', file_obj['name'])
            shutil.rmtree(target_dir + "/" + file_obj['name'])

def archive_expired_files(file_list, target_dir):
    """ Archive the expired files in a zip file.

        Args:
            file_list: list of file objects
            target_dir:    directory to clean
    """
    def zipdir(path, ziph):
        # ziph is zipfile handle
        for root, dirs, files in os.walk(path):
            for file in files:
                ziph.write(os.path.join(root, file))

    archive_file = "miriam-archive-" + time.strftime("%Y%m%d", time.gmtime())\
        + ".zip"
    for file_obj in file_list:
        with zipfile.ZipFile(archive_file, "a",
                             compression=zipfile.ZIP_DEFLATED,
                             allowZip64=True) as my_zip:
            if is_file(target_dir + "/" + file_obj['name']):
                logging.info('Archiving %r.', file_obj['name'])
                my_zip.write(target_dir + "/" + file_obj['name'])
            else:
                logging.info('Archiving folder %r.', file_obj['name'])
                zipdir(target_dir + "/" + file_obj['name'], my_zip)

def clean_up(file_list, target_dir):
    """ The existence of this function made me realize this
        would be better written as a class """

    archive_expired_files(file_list, target_dir)
    delete_expired_files(file_list, target_dir)

if __name__ == '__main__':

    parser = argparse.ArgumentParser()

    parser.add_argument('-nop', action='store_true',
                        help='Show what changes would be made but don\'t actually do anything.\
                        (Not yet implemented.)')
    parser.add_argument('target_dir', help='Target directory to scan for stale\
                        files', type=str)
    parser.add_argument('expiration', help='Number of days before an object is\
                        considered stale', type=int)
    args = parser.parse_args()

    contents = scan_dir(args.target_dir)
    logging.info('main -- contents: %r', contents)
    stale_list = find_old_files(contents, args.expiration)
    archive_expired_files(stale_list, args.target_dir)

    print stale_list