text:
package io.gravitee.am.service.impl;

import io.gravitee.am.common.audit.EventType;
import io.gravitee.am.common.event.Action;
import io.gravitee.am.common.event.Type;
import io.gravitee.am.common.utils.RandomString;
import io.gravitee.am.identityprovider.api.User;
import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.model.common.event.Event;
import io.gravitee.am.model.common.event.Payload;
import io.gravitee.am.model.resource.ServiceResource;
import io.gravitee.am.repository.management.api.ServiceResourceRepository;
import io.gravitee.am.service.AuditService;
import io.gravitee.am.service.EventService;
import io.gravitee.am.service.FactorService;
import io.gravitee.am.service.ServiceResourceService;
import io.gravitee.am.service.exception.AbstractManagementException;
import io.gravitee.am.service.exception.ServiceResourceCurrentlyUsedException;
import io.gravitee.am.service.exception.ServiceResourceNotFoundException;
import io.gravitee.am.service.exception.TechnicalManagementException;
import io.gravitee.am.service.model.NewServiceResource;
import io.gravitee.am.service.model.UpdateServiceResource;
import io.gravitee.am.service.reporter.builder.AuditBuilder;
import io.gravitee.am.service.reporter.builder.management.ServiceResourceAuditBuilder;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Single;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Eric LELEU (eric.leleu at graviteesource.com)
 * @author GraviteeSource Team
 */
@Component
public class ServiceResourceServiceImpl implements ServiceResourceService {

    /**
     * Logger.
     */
    private final Logger LOGGER = LoggerFactory.getLogger(ServiceResourceServiceImpl.class);

    @Lazy
    @Autowired
    private ServiceResourceRepository serviceResourceRepository;

    @Autowired
    private FactorService factorService;

    @Autowired
    private EventService eventService;

    @Autowired
    private AuditService auditService;

    @Override
    public Maybe<ServiceResource> findById(String id) {
        LOGGER.debug("Find resource by ID: {}", id);
        return serviceResourceRepository.findById(id)
                .onErrorResumeNext(ex -> {
                    LOGGER.error("An error occurs while trying to find a resource using its ID: {}", id, ex);
                    return Maybe.error(new TechnicalManagementException(
                            String.format("An error occurs while trying to find a resource using its ID: %s", id), ex));
                });
    }

    @Override
    public Flowable<ServiceResource> findByDomain(String domain) {
        LOGGER.debug("Find resources by domain: {}", domain);
        return serviceResourceRepository.findByReference(ReferenceType.DOMAIN, domain)
                .onErrorResumeNext(ex -> {
                    LOGGER.error("An error occurs while trying to find resources by domain", ex);
                    return Flowable.error(new TechnicalManagementException("An error occurs while trying to find resources by domain", ex));
                });
    }

    @Override
    public Single<ServiceResource> create(String domain, NewServiceResource newServiceResource, User principal) {
        LOGGER.debug("Create a new resource {} for domain {}", newServiceResource, domain);
        ServiceResource resource = new ServiceResource();
        resource.setId(newServiceResource.getId() == null ? RandomString.generate() : newServiceResource.getId());
        resource.setReferenceId(domain);
        resource.setReferenceType(ReferenceType.DOMAIN);
        resource.setName(newServiceResource.getName());
        resource.setType(newServiceResource.getType());
        resource.setConfiguration(newServiceResource.getConfiguration());
        resource.setCreatedAt(new Date());
        resource.setUpdatedAt(resource.getCreatedAt());

        return serviceResourceRepository.create(resource)
                .flatMap(resource1 -> {
                    // send sync event to refresh plugins that are using this resource
                    Event event = new Event(Type.RESOURCE, new Payload(resource1.getId(), resource1.getReferenceType(), resource1.getReferenceId(), Action.CREATE));
                    return eventService.create(event).flatMap(__ -> Single.just(resource1));
                })
                .onErrorResumeNext(ex -> {
                    if (ex instanceof AbstractManagementException) {
                        return Single.error(ex);
                    }

                    LOGGER.error("An error occurs while trying to create a resource", ex);
                    return Single.error(new TechnicalManagementException("An error occurs while trying to create a resource", ex));
                })
                .doOnSuccess(factor1 -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_CREATED).resource(factor1)))
                .doOnError(throwable -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_CREATED).throwable(throwable)));
    }

    @Override
    public Single<ServiceResource> update(String domain, String id, UpdateServiceResource updateResource, User principal) {
        LOGGER.debug("Update a resource {} for domain {}", id, domain);

        return serviceResourceRepository.findById(id)
                .switchIfEmpty(Maybe.error(new ServiceResourceNotFoundException(id)))
                .flatMapSingle(oldServiceResource -> {
                    ServiceResource factorToUpdate = new ServiceResource(oldServiceResource);
                    factorToUpdate.setName(updateResource.getName());
                    factorToUpdate.setConfiguration(updateResource.getConfiguration());
                    factorToUpdate.setUpdatedAt(new Date());

                    return serviceResourceRepository.update(factorToUpdate)
                            .flatMap(resource1 -> {
                                // send sync event to refresh plugins that are using this resource
                                Event event = new Event(Type.RESOURCE, new Payload(resource1.getId(), resource1.getReferenceType(), resource1.getReferenceId(), Action.UPDATE));
                                return eventService.create(event).flatMap(__ -> Single.just(resource1));
                            })
                            .doOnSuccess(factor1 -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_UPDATED).oldValue(oldServiceResource).resource(factor1)))
                            .doOnError(throwable -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_UPDATED).throwable(throwable)));
                })
                .onErrorResumeNext(ex -> {
                    if (ex instanceof AbstractManagementException) {
                        return Single.error(ex);
                    }

                    LOGGER.error("An error occurs while trying to update a resource", ex);
                    return Single.error(new TechnicalManagementException("An error occurs while trying to update a resource", ex));
                });
    }

    @Override
    public Completable delete(String domain, String resourceId, User principal) {
        LOGGER.debug("Delete resource {}", resourceId);
        return serviceResourceRepository.findById(resourceId)
                .switchIfEmpty(Maybe.error(new ServiceResourceNotFoundException(resourceId)))
                .flatMapSingle(resource ->
                    factorService.findByDomain(domain)
                            .filter(factor -> factor.getConfiguration() != null && factor.getConfiguration().contains("\""+resourceId+"\""))
                            .toList()
                            .flatMap(factors -> {
                                        if (factors.isEmpty()) {
                                            return Single.just(resource);
                                        } else {
                                            return Single.error(new ServiceResourceCurrentlyUsedException(resourceId, factors.get(0).getName(), "MultiFactor Authentication"));
                                        }
                                    }
                            )
                )
                .flatMapCompletable(resource -> {
                            Event event = new Event(Type.RESOURCE, new Payload(resource.getId(), resource.getReferenceType(), resource.getReferenceId(), Action.DELETE));
                            return serviceResourceRepository.delete(resourceId)
                                    .andThen(eventService.create(event))
                                    .ignoreElement()
                                    .doOnComplete(() -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_DELETED).resource(resource)))
                                    .doOnError(throwable -> auditService.report(AuditBuilder.builder(ServiceResourceAuditBuilder.class).principal(principal).type(EventType.RESOURCE_DELETED).throwable(throwable)));
                        }
                )
                .onErrorResumeNext(ex -> {
                    if (ex instanceof AbstractManagementException) {
                        return Completable.error(ex);
                    }

                    LOGGER.error("An error occurs while trying to delete resource: {}", resourceId, ex);
                    return Completable.error(new TechnicalManagementException(
                            String.format("An error occurs while trying to delete resource: %s", resourceId), ex));
                });
    }
}


text:
package au.gov.amsa.detection.behaviour;

import au.gov.amsa.detection.model.Binary;
import au.gov.amsa.detection.model.Region;
import au.gov.amsa.detection.model.SimpleRegion;
import au.gov.amsa.detection.model.SimpleRegion.Behaviour;
import au.gov.amsa.detection.model.SimpleRegion.Events.Create;
import au.gov.amsa.detection.model.SimpleRegionType;
import xuml.tools.model.compiler.runtime.ArbitraryId;

public class SimpleRegionBehaviour implements Behaviour {

    private final SimpleRegion self;

    public SimpleRegionBehaviour(SimpleRegion self) {
        this.self = self;
    }

    @Override
    public void onEntryCreated(Create event) {
        self.setId(ArbitraryId.next());
        Binary binary = Binary.create(ArbitraryId.next());
        binary.setBytes(event.getBytes());
        binary.persist();
        self.setBinary_R21(binary);
        self.setSimpleRegionType_R19(SimpleRegionType.find(event.getSimpleRegionTypeID()).get());
        Region region = Region.create(ArbitraryId.next());
        region.setName(event.getName());
        region.setDescription(event.getDescription());
        region.relateAcrossR4(self);
        region.setState(Region.State.CREATED);
        region.persist();
    }

}

redpajama_set_name: RedPajamaGithub


text:
namespace System.Unicode
{
#if BUILD_SYSTEM
	public
#else
	internal
#endif
	readonly struct CjkRadicalData
	{
		public readonly char TraditionalRadicalCodePoint;
		public readonly char TraditionalCharacterCodePoint;
		public readonly char SimplifiedRadicalCodePoint;
		public readonly char SimplifiedCharacterCodePoint;

		internal CjkRadicalData(char radicalCodePoint, char characterCodePoint)
		{
			TraditionalRadicalCodePoint = radicalCodePoint;
			TraditionalCharacterCodePoint = characterCodePoint;
			SimplifiedRadicalCodePoint = radicalCodePoint;
			SimplifiedCharacterCodePoint = characterCodePoint;
		}

		internal CjkRadicalData(char traditionalRadicalCodePoint, char traditionalCharacterCodePoint, char simplifiedRadicalCodePoint, char simplifiedCharacterCodePoint)
		{
			TraditionalRadicalCodePoint = traditionalRadicalCodePoint;
			TraditionalCharacterCodePoint = traditionalCharacterCodePoint;
			SimplifiedRadicalCodePoint = simplifiedRadicalCodePoint;
			SimplifiedCharacterCodePoint = simplifiedCharacterCodePoint;
		}

		public bool HasSimplifiedForm
			=> SimplifiedRadicalCodePoint != TraditionalRadicalCodePoint
			|| SimplifiedCharacterCodePoint != TraditionalCharacterCodePoint;
	}
}


text:
package de.learnlib.datastructure.observationtable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import de.learnlib.api.AccessSequenceTransformer;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.Signed;

/**
 * An observation table is a common method for learning algorithms to store organize their observations. This interface
 * defines a generic API for interacting with homogeneously interacting with observation tables regardless of their
 * implementation.
 *

 * Instances implementing this interface can be obtained from learning algorithms implementing the {@link
 * ObservationTableFeature observation table feature} (or {@link OTLearner}s.
 *

 * Basically, an observation table is a two-dimensional table, where both rows and columns are indexed by {@link Word}s.
 * The row indices are called prefixes, whereas the column indexes are referred to as suffixes. The table
 * is further vertically divided into two halves: the prefixes in the upper half are referred to as short
 * prefixes (these usually correspond to states in learned hypothesis automata), whereas the prefixes in the lower
 * half are referred to as long prefixes. Long prefixes must be one-letter extensions of short prefixes; they
 * refer to transitions in the hypothesis automaton. We refer to rows as short prefix rows or long prefix
 * row, depending on whether they occur in the upper or lower half of the table respectively.
 *

 * The cells of the table are filled with observations for a given prefix and suffix combination. The type of
 * observations is generic and can be specified using the type parameter {@code O}.
 *

 * There are two important properties of observation tables, which usually have to be satisfied in order to be able to
 * generate an automaton from an observation table: it must be both closed and consistent.
 *

 * In a closed observation table, the contents of each long prefix row equal the contents of at least one
 * short prefix rows. Consistency, on the other hand, is satisfied when for every two distinct short prefix rows,
 * all rows indexed by one-letter extensions of the corresponding prefix with any input symbol also have the same
 * content.
 *
 * @param
 *         input symbol type
 * @param <D>
 *         observation (output) domain type
 *
 * @author Malte Isberner
 */
public interface ObservationTable extends AccessSequenceTransformer {

    /**
     * Used to indicate that no distinguishing suffix exists in {@link #findDistinguishingSuffixIndex(Inconsistency)}
     * and {@link #findDistinguishingSuffixIndex(Row, Row)}.
     */
    int NO_DISTINGUISHING_SUFFIX = -1;

    /**
     * Retrieves the input alphabet used in this observation table.
     *
     * @return the input alphabet
     */
    Alphabet getInputAlphabet();

    /**
     * Retrieves all prefixes (short and long) in the table. The prefixes are returned in no specified order.
     *
     * @return all prefixes in the table
     */
    default Collection<Word> getAllPrefixes() {
        Collection<Word> shortPrefixes = getShortPrefixes();
        Collection<Word> longPrefixes = getLongPrefixes();
        List<Word> result = new ArrayList<>(shortPrefixes.size() + longPrefixes.size());

        result.addAll(shortPrefixes);
        result.addAll(longPrefixes);

        return result;
    }

    /**
     * Retrieves the short prefixes in the table. The prefixes are returned in no specified order.
     *
     * @return the short prefixes in the table
     */
    default Collection<Word> getShortPrefixes() {
        Collection<Row> spRows = getShortPrefixRows();
        return spRows.stream().map(Row::getLabel).collect(Collectors.toList());

    }

    /**
     * Retrieves the long prefixes in the table. The prefixes are returned in no specified order.
     *
     * @return the long prefixes in the table
     */
    default Collection<Word> getLongPrefixes() {
        Collection<Row> lpRows = getLongPrefixRows();
        return lpRows.stream().map(Row::getLabel).collect(Collectors.toList());
    }

    Collection<Row> getShortPrefixRows();

    Collection<Row> getLongPrefixRows();

    /**
     * Returns the specified row of the observation table.
     *
     * @param idx
     *         the index of the row
     *
     * @return the row
     *
     * @throws IndexOutOfBoundsException
     *         if {@code idx} is less than 0 or greater than {@code number of rows - 1}.
     */
    Row getRow(int idx);

    default @Nullable Row getRow(Word prefix) {
        for (Row row : getAllRows()) {
            if (prefix.equals(row.getLabel())) {
                return row;
            }
        }

        return null;
    }

    default Collection<Row> getAllRows() {
        Collection<Row> spRows = getShortPrefixRows();
        Collection<Row> lpRows = getLongPrefixRows();

        List<Row> result = new ArrayList<>(spRows.size() + lpRows.size());
        result.addAll(spRows);
        result.addAll(lpRows);

        return result;
    }

    /**
     * Returns the total number of rows in this observation table. This number may be used as the upper bound for the
     * (row) ids of the table rows.
     *
     * @return the number of rows
     *
     * @see Row#getRowId()
     */
    default int numberOfRows() {
        return getShortPrefixRows().size() + getLongPrefixRows().size();
    }

    default int numberOfShortPrefixRows() {
        return getShortPrefixRows().size();
    }

    default int numberOfLongPrefixRows() {
        return getLongPrefixRows().size();
    }

    /**
     * Returns the number of distinct (regarding row values) rows in this observation table. This number may be used as
     * the upper bound for the (content ids of the table rows.
     *
     * @return the number of distinct rows
     *
     * @see Row#getRowContentId()
     */
    int numberOfDistinctRows();

    default boolean isClosed() {
        return findUnclosedRow() == null;
    }

    default @Nullable Row findUnclosedRow() {
        final boolean[] spContents = new boolean[numberOfDistinctRows()];

        for (Row spRow : getShortPrefixRows()) {
            spContents[spRow.getRowContentId()] = true;
        }

        for (Row lpRow : getLongPrefixRows()) {
            if (!spContents[lpRow.getRowContentId()]) {
                return lpRow;
            }
        }

        return null;
    }

    default @Nullable Word findDistinguishingSuffix(Inconsistency inconsistency) {
        int suffixIndex = findDistinguishingSuffixIndex(inconsistency);
        if (suffixIndex != NO_DISTINGUISHING_SUFFIX) {
            return null;
        }
        return getSuffix(suffixIndex);
    }

    /**
     * @param row1
     *         the first row
     * @param row2
     *         the second row
     *
     * @return the suffix distinguishing the contents of the two rows
     */
    default @Nullable Word findDistinguishingSuffix(Row row1, Row row2) {
        int suffixIndex = findDistinguishingSuffixIndex(row1, row2);
        if (suffixIndex != NO_DISTINGUISHING_SUFFIX) {
            return null;
        }
        return getSuffix(suffixIndex);
    }

    /**
     * @return the suffix (column) index where the contents of the rows differ, or {@code #NO_DISTINGUISHING_SUFFIX} if
     * the contents of the rows are equal.
     */
    default @Signed int findDistinguishingSuffixIndex(Inconsistency inconsistency) {
        Row row1 = inconsistency.getFirstRow();
        Row row2 = inconsistency.getSecondRow();
        int symIdx = getInputAlphabet().getSymbolIndex(inconsistency.getSymbol());

        return findDistinguishingSuffixIndex(row1.getSuccessor(symIdx), row2.getSuccessor(symIdx));
    }

    /**
     * @param row1
     *         the first row
     * @param row2
     *         the second row
     *
     * @return the suffix (column) index where the contents of the rows differ, or {@code #NO_DISTINGUISHING_SUFFIX} if
     * the contents of the rows are equal.
     */
    default @Signed int findDistinguishingSuffixIndex(Row row1, Row row2) {
        for (int i = 0; i < getSuffixes().size(); i++) {
            if (!Objects.equals(cellContents(row1, i), cellContents(row2, i))) {
                return i;
            }
        }

        return NO_DISTINGUISHING_SUFFIX;
    }

    /**
     * Retrieves a suffix by its (column) index.
     *
     * @param index
     *         the index
     *
     * @return the suffix
     */
    default Word getSuffix(int index) {
        return getSuffixes().get(index);
    }

    /**
     * Retrieves all suffixes in the table.
     *
     * @return all suffixes in the table
     */
    List<Word> getSuffixes();

    default int numberOfSuffixes() {
        return getSuffixes().size();
    }

    default boolean isConsistent() {
        return findInconsistency() == null;
    }

    default @Nullable Inconsistency findInconsistency() {
        @SuppressWarnings("unchecked")
        final Row[] canonicalRows = (Row[]) new Row<?>[numberOfDistinctRows()];
        final Alphabet alphabet = getInputAlphabet();

        for (Row spRow : getShortPrefixRows()) {
            int contentId = spRow.getRowContentId();

            Row canRow = canonicalRows[contentId];
            if (canRow == null) {
                canonicalRows[contentId] = spRow;
                continue;
            }

            for (int i = 0; i < alphabet.size(); i++) {
                int spSuccContent = spRow.getSuccessor(i).getRowContentId();
                int canSuccContent = canRow.getSuccessor(i).getRowContentId();
                if (spSuccContent != canSuccContent) {
                    return new Inconsistency<>(canRow, spRow, alphabet.getSymbol(i));
                }
            }
        }

        return null;
    }

    default Row getRowSuccessor(Row row, I sym) {
        return row.getSuccessor(getInputAlphabet().getSymbolIndex(sym));
    }

    List<D> rowContents(Row row);

    default D cellContents(Row row, int columnId) {
        return rowContents(row).get(columnId);
    }

}


text:
<?php

defined('_JEXEC') or die;

/**
 * Messages Component Message Model
 *
 * @since  1.6
 */
class MessagesControllerMessage extends JControllerForm
{
	/**
	 * Method (override) to check if you can save a new or existing record.
	 *
	 * Adjusts for the primary key name and hands off to the parent class.
	 *
	 * @param   array   $data  An array of input data.
	 * @param   string  $key   The name of the key for the primary key.
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	protected function allowSave($data, $key = 'message_id')
	{
		return parent::allowSave($data, $key);
	}

	/**
	 * Reply to an existing message.
	 *
	 * This is a simple redirect to the compose form.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	public function reply()
	{
		if ($replyId = $this->input->getInt('reply_id'))
		{
			$this->setRedirect('index.php?option=com_messages&view=message&layout=edit&reply_id=' . $replyId);
		}
		else
		{
			$this->setMessage(JText::_('COM_MESSAGES_INVALID_REPLY_ID'));
			$this->setRedirect('index.php?option=com_messages&view=messages');
		}
	}
}


text:
import React from 'react'
import { Button } from 'react-bootstrap'
import { connect } from 'react-redux'

import * as uiActions from '../../actions/ui'

/**
 * Renders the "Edit" or "Back to search" button in mobile result views
 * that takes the user back to the mobile search screen.
 */
const EditSearchButton = ({ showMobileSearchScreen, ...props }) => (
  <Button onClick={showMobileSearchScreen} {...props} />
)

// connect to the redux store
const mapDispatchToProps = {
  showMobileSearchScreen: uiActions.showMobileSearchScreen
}

export default connect(null, mapDispatchToProps)(EditSearchButton)


text:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <stddef.h>
#include <ufp.h>

#include "main.h"
#include "forward.h"
#include "thread.h"

static int forward_arp_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet);
static int forward_ip_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet);
static int forward_ip6_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet);

#ifdef DEBUG
void forward_dump(struct ufp_packet *packet)
{
	struct ethhdr *eth;

	eth = (struct ethhdr *)packet->slot_buf;

	printf("packet dump:\n");
	printf("\tsrc %02x:%02x:%02x:%02x:%02x:%02x\n",
		eth->h_source[0], eth->h_source[1], eth->h_source[2],
		eth->h_source[3], eth->h_source[4], eth->h_source[5]);
	printf("\tdst %02x:%02x:%02x:%02x:%02x:%02x\n",
		eth->h_dest[0], eth->h_dest[1], eth->h_dest[2],
		eth->h_dest[3], eth->h_dest[4], eth->h_dest[5]);
	printf("\ttype 0x%x\n", eth->h_proto);
	printf("\tsize %d bytes\n", packet->slot_size);
}
#endif

void forward_process(struct ufpd_thread *thread, unsigned int port_index,
	struct ufp_packet *packet, int num_packet)
{
	struct ethhdr *eth;
	int i, ret;

	/* software prefetch is not needed when DDIO is available */
#ifdef DDIO_UNSUPPORTED
	for(i = 0; i < num_packet; i++){
		prefetchw(packet[i].slot_buf);
	}
#endif

	for(i = 0; i < num_packet; i++){
#ifdef DEBUG
		forward_dump(&packet[i]);
#endif

		if(packet[i].flag & UFP_PACKET_ERROR)
			goto packet_drop;

		/* TBD: Support jumbo frame */

		eth = (struct ethhdr *)packet[i].slot_buf;
		switch(ntohs(eth->h_proto)){
		case ETH_P_ARP:
			ret = forward_arp_process(thread,
				port_index, &packet[i]);
			break;
		case ETH_P_IP:
			ret = forward_ip_process(thread,
				port_index, &packet[i]);
			break;
		case ETH_P_IPV6:
			ret = forward_ip6_process(thread,
				port_index, &packet[i]);
			break;
		default:
			ret = -1;
			break;
		}

		if(ret < 0)
			goto packet_drop;

		ufp_tx_assign(thread->plane, ret, thread->buf,
			&packet[i]);

packet_drop:
		ufp_slot_release(thread->buf, packet[i].slot_index);
	}

	return;
}

void forward_process_tun(struct ufpd_thread *thread, unsigned int port_index,
	uint8_t *read_buf, unsigned int read_size)
{
	struct ufp_packet packet;

	if(read_size > ufp_slot_size(thread->buf))
		goto err_slot_size;

	packet.slot_index = ufp_slot_assign(thread->buf,
		thread->plane, port_index);
	if(packet.slot_index < 0){
		goto err_slot_assign;
	}

	packet.slot_buf = ufp_slot_addr_virt(thread->buf, packet.slot_index);
	memcpy(packet.slot_buf, read_buf, read_size);
	packet.slot_size = read_size;
	packet.flag = UFP_PACKET_EOF;

#ifdef DEBUG
	forward_dump(&packet);
#endif

	ufp_tx_assign(thread->plane, port_index, thread->buf, &packet);
	return;

err_slot_assign:
err_slot_size:
	return;
}

static int forward_arp_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet)
{
	int fd, ret;

	fd = ufp_tun_fd(thread->plane, port_index);
	ret = write(fd, packet->slot_buf, packet->slot_size);
	if(ret < 0)
		goto err_write_tun;

	return -1;

err_write_tun:
	return -1;
}

static int forward_ip_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet)
{
	struct ethhdr		*eth;
	struct iphdr		*ip;
	struct fib_entry	*fib_entry;
	struct neigh_entry	*neigh_entry;
	void			*dst_mac, *src_mac;
	uint32_t		check;
	int			fd, ret;

	eth = (struct ethhdr *)packet->slot_buf;
	ip = (struct iphdr *)(packet->slot_buf + sizeof(struct ethhdr));

	fib_entry = fib_lookup(thread->fib_inet, &ip->daddr);
	if(!fib_entry)
		goto packet_drop;

	if(unlikely(fib_entry->port_index < 0))
		goto packet_local;

	switch(fib_entry->type){
	case FIB_TYPE_LOCAL:
		goto packet_local;
		break;
	case FIB_TYPE_LINK:
		neigh_entry = neigh_lookup(
			thread->neigh_inet[fib_entry->port_index],
			&ip->daddr);
		break;
	case FIB_TYPE_FORWARD:
		neigh_entry = neigh_lookup(
			thread->neigh_inet[fib_entry->port_index],
			fib_entry->nexthop);
		break;
	default:
		neigh_entry = NULL;
		break;
	}

	if(!neigh_entry)
		goto packet_local;

	if(unlikely(ip->ttl == 1))
		goto packet_local;

	ip->ttl--;

	check = ip->check;
	check += htons(0x0100);
	ip->check = check + ((check >= 0xFFFF) ? 1 : 0);

	dst_mac = neigh_entry->dst_mac;
	src_mac = ufp_macaddr(thread->plane, fib_entry->port_index);
	memcpy(eth->h_dest, dst_mac, ETH_ALEN);
	memcpy(eth->h_source, src_mac, ETH_ALEN);

	ret = fib_entry->port_index;
	return ret;

packet_local:
	fd = ufp_tun_fd(thread->plane, port_index);
	write(fd, packet->slot_buf, packet->slot_size);
packet_drop:
	return -1;
}

static int forward_ip6_process(struct ufpd_thread *thread,
	unsigned int port_index, struct ufp_packet *packet)
{
	struct ethhdr		*eth;
	struct ip6_hdr		*ip6;
	struct fib_entry	*fib_entry;
	struct neigh_entry	*neigh_entry;
	void			*dst_mac, *src_mac;
	int			fd, ret;

	eth = (struct ethhdr *)packet->slot_buf;
	ip6 = (struct ip6_hdr *)(packet->slot_buf + sizeof(struct ethhdr));

	if(unlikely(IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst)))
		goto packet_local;

	fib_entry = fib_lookup(thread->fib_inet6, (uint32_t *)&ip6->ip6_dst);
	if(!fib_entry)
		goto packet_drop;

	if(unlikely(fib_entry->port_index < 0))
		goto packet_local;

	switch(fib_entry->type){
	case FIB_TYPE_LOCAL:
		goto packet_local;
		break;
	case FIB_TYPE_LINK:
		neigh_entry = neigh_lookup(
			thread->neigh_inet6[fib_entry->port_index],
			&ip6->ip6_dst);
		break;
	case FIB_TYPE_FORWARD:
		neigh_entry = neigh_lookup(
			thread->neigh_inet6[fib_entry->port_index],
			fib_entry->nexthop);
		break;
	default:
		neigh_entry = NULL;
		break;
	}

	if(!neigh_entry)
		goto packet_local;

	if(unlikely(ip6->ip6_hlim == 1))
		goto packet_local;

	ip6->ip6_hlim--;

	dst_mac = neigh_entry->dst_mac;
	src_mac = ufp_macaddr(thread->plane, fib_entry->port_index);
	memcpy(eth->h_dest, dst_mac, ETH_ALEN);
	memcpy(eth->h_source, src_mac, ETH_ALEN);

	ret = fib_entry->port_index;
	return ret;

packet_local:
	fd = ufp_tun_fd(thread->plane, port_index);
	write(fd, packet->slot_buf, packet->slot_size);
packet_drop:
	return -1;
}


text:
// vim

/*

https://scotch.io/tutorials/getting-started-with-vim-an-interactive-guide

https://vim.rtorr.com/lang/zh_cn/

view-source:https://vim.rtorr.com/lang/zh_cn/

*/


text:
ACCEPTED

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

#### Published in
null

#### Original name
Rhynchospora marginata C.B.Clarke

### Remarks
null


text:
class AddWidthAndHeightForTypes < ActiveRecord::Migration
  def change
    add_column :element_types, :width, :float
    add_column :element_types, :height, :float
  end
end


text:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="org.hisp.dhis.android.app.views.dashboard.navigation.event.create.CreateEventActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

            <org.hisp.dhis.client.sdk.ui.views.QuickSelectionContainer
                android:id="@+id/program_stage_selection_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="24dp"
                android:layout_marginEnd="@dimen/activity_vertical_margin"
                android:layout_marginLeft="@dimen/activity_vertical_margin"
                android:layout_marginRight="@dimen/activity_vertical_margin"
                android:layout_marginStart="@dimen/activity_vertical_margin"
                android:layout_marginTop="20dp"
                app:dividerDrawable="@drawable/quick_selection_divider"
                app:flexWrap="wrap"
                app:showDivider="middle" />

            <include layout="@layout/recyclerview_row_divider_horizontal" />

            <include
                android:id="@+id/org_unit"
                layout="@layout/recyclerview_row_filter" />
        </LinearLayout>
    </ScrollView>

    <android.support.v7.widget.ButtonBarLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:paddingRight="8dp">

        <Button
            android:id="@+id/schedule_button"
            style="@style/AppTheme.Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SCHEDULE FOR LATER" />

        <Button
            android:id="@+id/next_button"
            style="@style/AppTheme.Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ENTER DATA NOW" />
    </android.support.v7.widget.ButtonBarLayout>

</LinearLayout>


text:
from __future__ import with_statement

import os

all_modifs = {}

def fixdir(dir):
	"""Call all substitution functions on Waf folders"""
	for k in all_modifs:
		for v in all_modifs[k]:
			modif(os.path.join(dir, 'waflib'), k, v)

def modif(dir, name, fun):
	"""Call a substitution function"""
	if name == '*':
		lst = []
		for y in '. Tools extras'.split():
			for x in os.listdir(os.path.join(dir, y)):
				if x.endswith('.py'):
					lst.append(y + os.sep + x)
		for x in lst:
			modif(dir, x, fun)
		return

	filename = os.path.join(dir, name)
	with open(filename, 'r') as f:
		txt = f.read()

	txt = fun(txt)

	with open(filename, 'w') as f:
		f.write(txt)

def subst(*k):
	"""register a substitution function"""
	def do_subst(fun):
		for x in k:
			try:
				all_modifs[x].append(fun)
			except KeyError:
				all_modifs[x] = [fun]
		return fun
	return do_subst

@subst('*')
def r1(code):
	"utf-8 fixes for python < 2.6"
	code = code.replace('as e:', ',e:')
	code = code.replace(".decode(sys.stdout.encoding or'latin-1',errors='replace')", '')
	return code.replace('.encode()', '')

@subst('Runner.py')
def r4(code):
	"generator syntax"
	return code.replace('next(self.biter)', 'self.biter.next()')

@subst('Context.py')
def r5(code):
	return code.replace("('Execution failure: %s'%str(e),ex=e)", "('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]")


text:
namespace rime {

class TableDb : public TextDb {
 public:
  explicit TableDb(const string& name);

  static const TextFormat format;
};

// read-only tabledb
class StableDb : public TableDb {
 public:
  explicit StableDb(const string& name);

  virtual bool Open();
};

}  // namespace rime

#endif  // RIME_TEXT_DB_H_


text:
var path = require('path');
var minimatch = require('minimatch');

function minimatchList(path, patternList, options) {
  return patternList.some(function(pattern) {
    return minimatch(path, pattern, options)
  });
}

/**
 * Check the file matches on of the globs.
 *
 * @param {string} filename - The filename to test
 * @param {string[]} globs - An array of glob strings to test the filename against
 * @return {boolean}
 */
function checkGlob(filename, globs) {
  // PostCSS turns relative paths into absolute paths
  filename = path.relative(process.cwd(), filename);
  return minimatchList(filename, globs);
}

/**
 * @param {string[]|boolean} implicitComponentsConfig - The configuration value implicitComponents
 * @param {string} filename - The filename of the CSS file being checked
 * @returns {boolean}
 */
function isImplicitComponent(implicitComponentsConfig, filename) {
  if (Array.isArray(implicitComponentsConfig)) {
    return checkGlob(filename, implicitComponentsConfig);
  }

  return Boolean(implicitComponentsConfig);
}

/**
 * @param {string[]|boolean} implicitUtilitiesConfig - The configuration value implicitUtilities
 * @param {string} filename - The filename of the CSS file being checked
 * @return {boolean}
 */
function isImplicitUtilities(implicitUtilitiesConfig, filename) {
  if (Array.isArray(implicitUtilitiesConfig)) {
    return checkGlob(filename, implicitUtilitiesConfig);
  }

  return false;
}

module.exports = {
  isImplicitComponent: isImplicitComponent,
  isImplicitUtilities: isImplicitUtilities,
};


text:
*This document is oriented at developers who want to change existing APIs.
A set of API conventions, which applies to new APIs and to changes, can be
found at [API Conventions](api-conventions.md).

**Table of Contents**
<!-- BEGIN MUNGE: GENERATED_TOC -->

- [So you want to change the API?](#so-you-want-to-change-the-api)
  - [Operational overview](#operational-overview)
  - [On compatibility](#on-compatibility)
  - [Incompatible API changes](#incompatible-api-changes)
  - [Changing versioned APIs](#changing-versioned-apis)
    - [Edit types.go](#edit-typesgo)
    - [Edit defaults.go](#edit-defaultsgo)
    - [Edit conversion.go](#edit-conversiongo)
  - [Changing the internal structures](#changing-the-internal-structures)
    - [Edit types.go](#edit-typesgo-1)
  - [Edit validation.go](#edit-validationgo)
  - [Edit version conversions](#edit-version-conversions)
  - [Generate protobuf objects](#generate-protobuf-objects)
  - [Edit json (un)marshaling code](#edit-json-unmarshaling-code)
  - [Making a new API Group](#making-a-new-api-group)
  - [Update the fuzzer](#update-the-fuzzer)
  - [Update the semantic comparisons](#update-the-semantic-comparisons)
  - [Implement your change](#implement-your-change)
  - [Write end-to-end tests](#write-end-to-end-tests)
  - [Examples and docs](#examples-and-docs)
  - [Alpha, Beta, and Stable Versions](#alpha-beta-and-stable-versions)
    - [Adding Unstable Features to Stable Versions](#adding-unstable-features-to-stable-versions)

<!-- END MUNGE: GENERATED_TOC -->

# So you want to change the API?

Before attempting a change to the API, you should familiarize yourself with a
number of existing API types and with the [API conventions](api-conventions.md).
If creating a new API type/resource, we also recommend that you first send a PR
containing just a proposal for the new API types, and that you initially target
the extensions API (pkg/apis/extensions).

The Kubernetes API has two major components - the internal structures and
the versioned APIs. The versioned APIs are intended to be stable, while the
internal structures are implemented to best reflect the needs of the Kubernetes
code itself.

What this means for API changes is that you have to be somewhat thoughtful in
how you approach changes, and that you have to touch a number of pieces to make
a complete change.  This document aims to guide you through the process, though
not all API changes will need all of these steps.

## Operational overview

It is important to have a high level understanding of the API system used in
Kubernetes in order to navigate the rest of this document.

As mentioned above, the internal representation of an API object is decoupled
from any one API version. This provides a lot of freedom to evolve the code,
but it requires robust infrastructure to convert between representations. There
are multiple steps in processing an API operation - even something as simple as
a GET involves a great deal of machinery.

The conversion process is logically a "star" with the internal form at the
center. Every versioned API can be converted to the internal form (and
vice-versa), but versioned APIs do not convert to other versioned APIs directly.
This sounds like a heavy process, but in reality we do not intend to keep more
than a small number of versions alive at once. While all of the Kubernetes code
operates on the internal structures, they are always converted to a versioned
form before being written to storage (disk or etcd) or being sent over a wire.
Clients should consume and operate on the versioned APIs exclusively.

To demonstrate the general process, here is a (hypothetical) example:

   1. A user POSTs a `Pod` object to `/api/v7beta1/...`
   2. The JSON is unmarshalled into a `v7beta1.Pod` structure
   3. Default values are applied to the `v7beta1.Pod`
   4. The `v7beta1.Pod` is converted to an `api.Pod` structure
   5. The `api.Pod` is validated, and any errors are returned to the user
   6. The `api.Pod` is converted to a `v6.Pod` (because v6 is the latest stable
version)
   7. The `v6.Pod` is marshalled into JSON and written to etcd

Now that we have the `Pod` object stored, a user can GET that object in any
supported api version. For example:

   1. A user GETs the `Pod` from `/api/v5/...`
   2. The JSON is read from etcd and unmarshalled into a `v6.Pod` structure
   3. Default values are applied to the `v6.Pod`
   4. The `v6.Pod` is converted to an `api.Pod` structure
   5. The `api.Pod` is converted to a `v5.Pod` structure
   6. The `v5.Pod` is marshalled into JSON and sent to the user

The implication of this process is that API changes must be done carefully and
backward-compatibly.

## On compatibility

Before talking about how to make API changes, it is worthwhile to clarify what
we mean by API compatibility.  Kubernetes considers forwards and backwards
compatibility of its APIs a top priority.

An API change is considered forward and backward-compatible if it:

   * adds new functionality that is not required for correct behavior (e.g.,
does not add a new required field)
   * does not change existing semantics, including:
     * default values and behavior
     * interpretation of existing API types, fields, and values
     * which fields are required and which are not

Put another way:

1. Any API call (e.g. a structure POSTed to a REST endpoint) that worked before
your change must work the same after your change.
2. Any API call that uses your change must not cause problems (e.g. crash or
degrade behavior) when issued against servers that do not include your change.
3. It must be possible to round-trip your change (convert to different API
versions and back) with no loss of information.
4. Existing clients need not be aware of your change in order for them to
continue to function as they did previously, even when your change is utilized.

If your change does not meet these criteria, it is not considered strictly
compatible, and may break older clients, or result in newer clients causing
undefined behavior.

Let's consider some examples. In a hypothetical API (assume we're at version
v6), the `Frobber` struct looks something like this:

```go
// API v6.
type Frobber struct {
  Height int    `json:"height"`
  Param  string `json:"param"`
}
```

You want to add a new `Width` field. It is generally safe to add new fields
without changing the API version, so you can simply change it to:

```go
// Still API v6.
type Frobber struct {
  Height int    `json:"height"`
  Width  int    `json:"width"`
  Param  string `json:"param"`
}
```

The onus is on you to define a sane default value for `Width` such that rule #1
above is true - API calls and stored objects that used to work must continue to
work.

For your next change you want to allow multiple `Param` values. You can not
simply change `Param string` to `Params []string` (without creating a whole new
API version) - that fails rules #1 and #2. You can instead do something like:

```go
// Still API v6, but kind of clumsy.
type Frobber struct {
  Height int           `json:"height"`
  Width  int           `json:"width"`
  Param  string        `json:"param"`  // the first param
  ExtraParams []string `json:"extraParams"` // additional params
}
```

Now you can satisfy the rules: API calls that provide the old style `Param`
will still work, while servers that don't understand `ExtraParams` can ignore
it. This is somewhat unsatisfying as an API, but it is strictly compatible.

Part of the reason for versioning APIs and for using internal structs that are
distinct from any one version is to handle growth like this. The internal
representation can be implemented as:

```go
// Internal, soon to be v7beta1.
type Frobber struct {
  Height int
  Width  int
  Params []string
}
```

The code that converts to/from versioned APIs can decode this into the somewhat
uglier (but compatible!) structures. Eventually, a new API version, let's call
it v7beta1, will be forked and it can use the clean internal structure.

We've seen how to satisfy rules #1 and #2. Rule #3 means that you can not
extend one versioned API without also extending the others. For example, an
API call might POST an object in API v7beta1 format, which uses the cleaner
`Params` field, but the API server might store that object in trusty old v6
form (since v7beta1 is "beta"). When the user reads the object back in the
v7beta1 API it would be unacceptable to have lost all but `Params[0]`. This
means that, even though it is ugly, a compatible change must be made to the v6
API.

However, this is very challenging to do correctly. It often requires multiple
representations of the same information in the same API resource, which need to
be kept in sync in the event that either is changed. For example, let's say you
decide to rename a field within the same API version. In this case, you add
units to `height` and `width`. You implement this by adding duplicate fields:

```go
type Frobber struct {
  Height         *int          `json:"height"`
  Width          *int          `json:"width"`
  HeightInInches *int          `json:"heightInInches"`
  WidthInInches  *int          `json:"widthInInches"`
}
```

You convert all of the fields to pointers in order to distinguish between unset
and set to 0, and then set each corresponding field from the other in the
defaulting pass (e.g., `heightInInches` from `height`, and vice versa), which
runs just prior to conversion. That works fine when the user creates a resource
from a hand-written configuration -- clients can write either field and read
either field, but what about creation or update from the output of GET, or
update via PATCH (see
[In-place updates](../user-guide/managing-deployments.md#in-place-updates-of-resources))?
In this case, the two fields will conflict, because only one field would be
updated in the case of an old client that was only aware of the old field (e.g.,
`height`).

Say the client creates:

```json
{
  "height": 10,
  "width": 5
}
```

and GETs:

```json
{
  "height": 10,
  "heightInInches": 10,
  "width": 5,
  "widthInInches": 5
}
```

then PUTs back:

```json
{
  "height": 13,
  "heightInInches": 10,
  "width": 5,
  "widthInInches": 5
}
```

The update should not fail, because it would have worked before `heightInInches`
was added.

Therefore, when there are duplicate fields, the old field MUST take precedence
over the new, and the new field should be set to match by the server upon write.
A new client would be aware of the old field as well as the new, and so can
ensure that the old field is either unset or is set consistently with the new
field. However, older clients would be unaware of the new field. Please avoid
introducing duplicate fields due to the complexity they incur in the API.

A new representation, even in a new API version, that is more expressive than an
old one breaks backward compatibility, since clients that only understood the
old representation would not be aware of the new representation nor its
semantics. Examples of proposals that have run into this challenge include
[generalized label selectors](http://issues.k8s.io/341) and [pod-level security
context](http://prs.k8s.io/12823).

As another interesting example, enumerated values cause similar challenges.
Adding a new value to an enumerated set is *not* a compatible change. Clients
which assume they know how to handle all possible values of a given field will
not be able to handle the new values. However, removing value from an enumerated
set *can* be a compatible change, if handled properly (treat the removed value
as deprecated but allowed). This is actually a special case of a new
representation, discussed above.

For [Unions](api-conventions.md#unions), sets of fields where at most one should
be set, it is acceptable to add a new option to the union if the [appropriate
conventions](api-conventions.md#objects) were followed in the original object.
Removing an option requires following the deprecation process.

## Incompatible API changes

There are times when this might be OK, but mostly we want changes that meet this
definition. If you think you need to break compatibility, you should talk to the
Kubernetes team first.

Breaking compatibility of a beta or stable API version, such as v1, is
unacceptable. Compatibility for experimental or alpha APIs is not strictly
required, but breaking compatibility should not be done lightly, as it disrupts
all users of the feature. Experimental APIs may be removed. Alpha and beta API
versions may be deprecated and eventually removed wholesale, as described in the
[versioning document](../design-proposals/versioning.md). Document incompatible changes
across API versions under the appropriate
[{v? conversion tips tag in the api.md doc](../api.md).

If your change is going to be backward incompatible or might be a breaking
change for API consumers, please send an announcement to
`kubernetes-dev@googlegroups.com` before the change gets in. If you are unsure,
ask. Also make sure that the change gets documented in the release notes for the
next release by labeling the PR with the "release-note" github label.

If you found that your change accidentally broke clients, it should be reverted.

In short, the expected API evolution is as follows:

* `extensions/v1alpha1` ->
* `newapigroup/v1alpha1` -> ... -> `newapigroup/v1alphaN` ->
* `newapigroup/v1beta1` -> ... -> `newapigroup/v1betaN` ->
* `newapigroup/v1` ->
* `newapigroup/v2alpha1` -> ...

While in extensions we have no obligation to move forward with the API at all
and may delete or break it at any time.

While in alpha we expect to move forward with it, but may break it.

Once in beta we will preserve forward compatibility, but may introduce new
versions and delete old ones.

v1 must be backward-compatible for an extended length of time.

## Changing versioned APIs

For most changes, you will probably find it easiest to change the versioned
APIs first. This forces you to think about how to make your change in a
compatible way. Rather than doing each step in every version, it's usually
easier to do each versioned API one at a time, or to do all of one version
before starting "all the rest".

### Edit types.go

The struct definitions for each API are in `pkg/api/<version>/types.go`. Edit
those files to reflect the change you want to make. Note that all types and
non-inline fields in versioned APIs must be preceded by descriptive comments -
these are used to generate documentation. Comments for types should not contain
the type name; API documentation is generated from these comments and end-users
should not be exposed to golang type names.

Optional fields should have the `,omitempty` json tag; fields are interpreted as
being required otherwise.

### Edit defaults.go

If your change includes new fields for which you will need default values, you
need to add cases to `pkg/api/<version>/defaults.go`. Of course, since you
have added code, you have to add a test: `pkg/api/<version>/defaults_test.go`.

Do use pointers to scalars when you need to distinguish between an unset value
and an automatic zero value.  For example,
`PodSpec.TerminationGracePeriodSeconds` is defined as `*int64` the go type
definition.  A zero value means 0 seconds, and a nil value asks the system to
pick a default.

Don't forget to run the tests!

### Edit conversion.go

Given that you have not yet changed the internal structs, this might feel
premature, and that's because it is. You don't yet have anything to convert to
or from. We will revisit this in the "internal" section. If you're doing this
all in a different order (i.e. you started with the internal structs), then you
should jump to that topic below. In the very rare case that you are making an
incompatible change you might or might not want to do this now, but you will
have to do more later. The files you want are
`pkg/api/<version>/conversion.go` and `pkg/api/<version>/conversion_test.go`.

Note that the conversion machinery doesn't generically handle conversion of
values, such as various kinds of field references and API constants. [The client
library](../../pkg/client/restclient/request.go) has custom conversion code for
field references. You also need to add a call to
api.Scheme.AddFieldLabelConversionFunc with a mapping function that understands
supported translations.

## Changing the internal structures

Now it is time to change the internal structs so your versioned changes can be
used.

### Edit types.go

Similar to the versioned APIs, the definitions for the internal structs are in
`pkg/api/types.go`. Edit those files to reflect the change you want to make.
Keep in mind that the internal structs must be able to express *all* of the
versioned APIs.

## Edit validation.go

Most changes made to the internal structs need some form of input validation.
Validation is currently done on internal objects in
`pkg/api/validation/validation.go`. This validation is the one of the first
opportunities we have to make a great user experience - good error messages and
thorough validation help ensure that users are giving you what you expect and,
when they don't, that they know why and how to fix it. Think hard about the
contents of `string` fields, the bounds of `int` fields and the
requiredness/optionalness of fields.

Of course, code needs tests - `pkg/api/validation/validation_test.go`.

## Edit version conversions

At this point you have both the versioned API changes and the internal
structure changes done.  If there are any notable differences - field names,
types, structural change in particular - you must add some logic to convert
versioned APIs to and from the internal representation.  If you see errors from
the `serialization_test`, it may indicate the need for explicit conversions.

Performance of conversions very heavily influence performance of apiserver.
Thus, we are auto-generating conversion functions that are much more efficient
than the generic ones (which are based on reflections and thus are highly
inefficient).

The conversion code resides with each versioned API. There are two files:

   - `pkg/api/<version>/conversion.go` containing manually written conversion
functions
   - `pkg/api/<version>/conversion_generated.go` containing auto-generated
conversion functions
   - `pkg/apis/extensions/<version>/conversion.go` containing manually written
conversion functions
   - `pkg/apis/extensions/<version>/conversion_generated.go` containing
auto-generated conversion functions

Since auto-generated conversion functions are using manually written ones,
those manually written should be named with a defined convention, i.e. a
function converting type X in pkg a to type Y in pkg b, should be named:
`convert_a_X_To_b_Y`.

Also note that you can (and for efficiency reasons should) use auto-generated
conversion functions when writing your conversion functions.

Once all the necessary manually written conversions are added, you need to
regenerate auto-generated ones. To regenerate them run:

```sh
hack/update-codegen.sh
```

As part of the build, kubernetes will also generate code to handle deep copy of
your versioned api objects. The deep copy code resides with each versioned API:
   - `<path_to_versioned_api>/zz_generated.deepcopy.go` containing auto-generated copy functions

If regeneration is somehow not possible due to compile errors, the easiest
workaround is to comment out the code causing errors and let the script to
regenerate it. If the auto-generated conversion methods are not used by the
manually-written ones, it's fine to just remove the whole file and let the
generator to create it from scratch.

Unsurprisingly, adding manually written conversion also requires you to add
tests to `pkg/api/<version>/conversion_test.go`.

## Generate protobuf objects

For any core API object, we also need to generate the Protobuf IDL and marshallers.
That generation is done with

```sh
hack/update-generated-protobuf.sh
```

The vast majority of objects will not need any consideration when converting
to protobuf, but be aware that if you depend on a Golang type in the standard
library there may be additional work required, although in practice we typically
use our own equivalents for JSON serialization. The `pkg/api/serialization_test.go`
will verify that your protobuf serialization preserves all fields - be sure to
run it several times to ensure there are no incompletely calculated fields.

## Edit json (un)marshaling code

We are auto-generating code for marshaling and unmarshaling json representation
of api objects - this is to improve the overall system performance.

The auto-generated code resides with each versioned API:

   - `pkg/api/<version>/types.generated.go`
   - `pkg/apis/extensions/<version>/types.generated.go`

To regenerate them run:

```sh
hack/update-codecgen.sh
```

## Making a new API Group

This section is under construction, as we make the tooling completely generic.

At the moment, you'll have to make a new directory under `pkg/apis/`; copy the
directory structure from `pkg/apis/authentication`. Add the new group/version to all
of the `hack/{verify,update}-generated-{deep-copy,conversions,swagger}.sh` files
in the appropriate places--it should just require adding your new group/version
to a bash array.  See [docs on adding an API group](adding-an-APIGroup.md) for
more.

Adding API groups outside of the `pkg/apis/` directory is not currently
supported, but is clearly desirable. The deep copy & conversion generators need
to work by parsing go files instead of by reflection; then they will be easy to
point at arbitrary directories: see issue [#13775](http://issue.k8s.io/13775).

## Update the fuzzer

Part of our testing regimen for APIs is to "fuzz" (fill with random values) API
objects and then convert them to and from the different API versions. This is
a great way of exposing places where you lost information or made bad
assumptions. If you have added any fields which need very careful formatting
(the test does not run validation) or if you have made assumptions such as
"this slice will always have at least 1 element", you may get an error or even
a panic from the `serialization_test`. If so, look at the diff it produces (or
the backtrace in case of a panic) and figure out what you forgot. Encode that
into the fuzzer's custom fuzz functions. Hint: if you added defaults for a
field, that field will need to have a custom fuzz function that ensures that the
field is fuzzed to a non-empty value.

The fuzzer can be found in `pkg/api/testing/fuzzer.go`.

## Update the semantic comparisons

VERY VERY rarely is this needed, but when it hits, it hurts. In some rare cases
we end up with objects (e.g. resource quantities) that have morally equivalent
values with different bitwise representations (e.g. value 10 with a base-2
formatter is the same as value 0 with a base-10 formatter). The only way Go
knows how to do deep-equality is through field-by-field bitwise comparisons.
This is a problem for us.

The first thing you should do is try not to do that. If you really can't avoid
this, I'd like to introduce you to our `semantic DeepEqual` routine. It supports
custom overrides for specific types - you can find that in `pkg/api/helpers.go`.

There's one other time when you might have to touch this: `unexported fields`.
You see, while Go's `reflect` package is allowed to touch `unexported fields`,
us mere mortals are not - this includes `semantic DeepEqual`. Fortunately, most
of our API objects are "dumb structs" all the way down - all fields are exported
(start with a capital letter) and there are no unexported fields. But sometimes
you want to include an object in our API that does have unexported fields
somewhere in it (for example, `time.Time` has unexported fields). If this hits
you, you may have to touch the `semantic DeepEqual` customization functions.

## Implement your change

Now you have the API all changed - go implement whatever it is that you're
doing!

## Write end-to-end tests

Check out the [E2E docs](e2e-tests.md) for detailed information about how to
write end-to-end tests for your feature.

## Examples and docs

At last, your change is done, all unit tests pass, e2e passes, you're done,
right? Actually, no. You just changed the API. If you are touching an existing
facet of the API, you have to try *really* hard to make sure that *all* the
examples and docs are updated. There's no easy way to do this, due in part to
JSON and YAML silently dropping unknown fields. You're clever - you'll figure it
out. Put `grep` or `ack` to good use.

If you added functionality, you should consider documenting it and/or writing
an example to illustrate your change.

Make sure you update the swagger and OpenAPI spec by running:

```sh
hack/update-swagger-spec.sh
hack/update-openapi-spec.sh
```

The API spec changes should be in a commit separate from your other changes.

## Alpha, Beta, and Stable Versions

New feature development proceeds through a series of stages of increasing
maturity:

- Development level
  - Object Versioning: no convention
  - Availability: not committed to main kubernetes repo, and thus not available
in official releases
  - Audience: other developers closely collaborating on a feature or
proof-of-concept
  - Upgradeability, Reliability, Completeness, and Support: no requirements or
guarantees
- Alpha level
  - Object Versioning: API version name contains `alpha` (e.g. `v1alpha1`)
  - Availability: committed to main kubernetes repo;  appears in an official
release; feature is disabled by default, but may be enabled by flag
  - Audience: developers and expert users interested in giving early feedback on
features
  - Completeness: some API operations, CLI commands, or UI support may not be
implemented; the API need not have had an *API review* (an intensive and
targeted review of the API, on top of a normal code review)
  - Upgradeability: the object schema and semantics may change in a later
software release, without any provision for preserving objects in an existing
cluster; removing the upgradability concern allows developers to make rapid
progress; in particular, API versions can increment faster than the minor
release cadence and the developer need not maintain multiple versions;
developers should still increment the API version when object schema or
semantics change in an [incompatible way](#on-compatibility)
  - Cluster Reliability: because the feature is relatively new, and may lack
complete end-to-end tests, enabling the feature via a flag might expose bugs
with destabilize the cluster (e.g. a bug in a control loop might rapidly create
excessive numbers of object, exhausting API storage).
  - Support: there is *no commitment* from the project to complete the feature;
the feature may be dropped entirely in a later software release
  - Recommended Use Cases: only in short-lived testing clusters, due to
complexity of upgradeability and lack of long-term support and lack of
upgradability.
- Beta level:
  - Object Versioning: API version name contains `beta` (e.g. `v2beta3`)
  - Availability: in official Kubernetes releases, and enabled by default
  - Audience: users interested in providing feedback on features
  - Completeness: all API operations, CLI commands, and UI support should be
implemented; end-to-end tests complete; the API has had a thorough API review
and is thought to be complete, though use during beta may frequently turn up API
issues not thought of during review
  - Upgradeability: the object schema and semantics may change in a later
software release; when this happens, an upgrade path will be documented; in some
cases, objects will be automatically converted to the new version; in other
cases, a manual upgrade may be necessary; a manual upgrade may require downtime
for anything relying on the new feature, and may require manual conversion of
objects to the new version; when manual conversion is necessary, the project
will provide documentation on the process (for an example, see [v1 conversion
tips](../api.md#v1-conversion-tips))
  - Cluster Reliability: since the feature has e2e tests, enabling the feature
via a flag should not create new bugs in unrelated features; because the feature
is new, it may have minor bugs
  - Support: the project commits to complete the feature, in some form, in a
subsequent Stable version; typically this will happen within 3 months, but
sometimes longer; releases should simultaneously support two consecutive
versions (e.g. `v1beta1` and `v1beta2`; or `v1beta2` and `v1`) for at least one
minor release cycle (typically 3 months) so that users have enough time to
upgrade and migrate objects
  - Recommended Use Cases: in short-lived testing clusters; in production
clusters as part of a short-lived evaluation of the feature in order to provide
feedback
- Stable level:
  - Object Versioning: API version `vX` where `X` is an integer (e.g. `v1`)
  - Availability: in official Kubernetes releases, and enabled by default
  - Audience: all users
  - Completeness: same as beta
  - Upgradeability: only [strictly compatible](#on-compatibility) changes
allowed in subsequent software releases
  - Cluster Reliability: high
  - Support: API version will continue to be present for many subsequent
software releases;
  - Recommended Use Cases: any

### Adding Unstable Features to Stable Versions

When adding a feature to an object which is already Stable, the new fields and
new behaviors need to meet the Stable level requirements. If these cannot be
met, then the new field cannot be added to the object.

For example, consider the following object:

```go
// API v6.
type Frobber struct {
  Height int    `json:"height"`
  Param  string `json:"param"`
}
```

A developer is considering adding a new `Width` parameter, like this:

```go
// API v6.
type Frobber struct {
  Height int    `json:"height"`
  Width  int    `json:"height"`
  Param  string `json:"param"`
}
```

However, the new feature is not stable enough to be used in a stable version
(`v6`). Some reasons for this might include:

- the final representation is undecided (e.g. should it be called `Width` or
`Breadth`?)
- the implementation is not stable enough for general use (e.g. the `Area()`
routine sometimes overflows.)

The developer cannot add the new field until stability is met. However,
sometimes stability cannot be met until some users try the new feature, and some
users are only able or willing to accept a released version of Kubernetes. In
that case, the developer has a few options, both of which require staging work
over several releases.

A preferred option is to first make a release where the new value (`Width` in
this example) is specified via an annotation, like this:

```go
kind: frobber
version: v6
metadata:
  name: myfrobber
  annotations:
    frobbing.alpha.kubernetes.io/width: 2
height: 4
param: "green and blue"
```

This format allows users to specify the new field, but makes it clear that they
are using a Alpha feature when they do, since the word `alpha` is in the
annotation key.

Another option is to introduce a new type with an new `alpha` or `beta` version
designator, like this:

```
// API v6alpha2
type Frobber struct {
  Height int    `json:"height"`
  Width  int    `json:"height"`
  Param  string `json:"param"`
}
```

The latter requires that all objects in the same API group as `Frobber` to be
replicated in the new version, `v6alpha2`. This also requires user to use a new
client which uses the other version. Therefore, this is not a preferred option.

A related issue is how a cluster manager can roll back from a new version
with a new feature, that is already being used by users. See
https://github.com/kubernetes/kubernetes/issues/4855.

<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/api_changes.md?pixel)]()
<!-- END MUNGE: GENERATED_ANALYTICS -->


text:
package org.switchyard.component.bean.tests;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.switchyard.Message;
import org.switchyard.test.Invoker;
import org.switchyard.test.ServiceOperation;
import org.switchyard.test.SwitchYardRunner;
import org.switchyard.test.SwitchYardTestCaseConfig;
import org.switchyard.component.test.mixins.cdi.CDIMixIn;

/*
 * Assorted methods for testing a CDI bean providing a service in SwitchYard.
 */
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(mixins = CDIMixIn.class)
public class BeanProviderTest {

    @ServiceOperation("OneWay.oneWay")
    private Invoker oneWay;
    @ServiceOperation("RequestResponse.reply")
    private Invoker reply;

    @Test
    public void invokeOneWayProviderWithInOnly() {
        oneWay.sendInOnly("hello");
    }

    @Test
    public void invokeRequestResponseProviderWithInOut() {
        String ECHO_MSG = "hello";
        Message response = reply.sendInOut(ECHO_MSG);

        Assert.assertEquals(ECHO_MSG, response.getContent());
    }
}


text:
from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import *
from ti import models

import logging
from dateutil import parser
import urllib
import urlparse
import cgi
import subprocess
import warnings
import time
import random
import string
import datetime
import csv

# hide facebook deprecation warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)

# global logging setup
logging.basicConfig(level=logging.INFO)

class Command(BaseCommand):
    args = '<filename>'
    help = 'Import geo data for locations'

    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self._log = logging.getLogger('cmd')

    def handle(self, *args, **options):
        if args is None or len(args) < 1:
            raise CommandError('Invalid arguments. Expected: <filename>')

        fname = args[0]
        self._log.info('ImportCountryData initializing.')
        self._log.info('Filename: %s' % fname)
        self.importData(fname)

    def importData(self, filename):
        with open(filename) as f:
            reader = csv.reader(f, delimiter=';', quoting=csv.QUOTE_NONE)
            next(reader, None) # skip header line
            for row in reader:
                self.importRow(row)

    def importRow(self, row):
        print row
        _, created = models.CountryLocales.objects.get_or_create(ccode=row[1], defaults={'continent': row[0], 'cname': row[2], 'lati': row[3], 'longi': row[4]})
        if created:
            self._log.info('Country created: %s' % row[2]) #Continent;Code;Name;Latitude;Longitude


text:
export class ContactFormModel {
    name?: string;
    email?: string;
    message?: string;
    captcha?: string;
}


text:
package com.intellij.ui;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import javax.swing.*;
import java.util.List;

/**
 * @author traff
 */
public abstract class AbstractCollectionComboBoxModel<T> extends AbstractListModel<T> implements ComboBoxModel<T> {
  protected T mySelection;

  public AbstractCollectionComboBoxModel(@Nullable T selection) {
    mySelection = selection;
  }

  @Override
  public int getSize() {
    return getItems().size();
  }

  @Override
  public T getElementAt(final int index) {
    return getItems().get(index);
  }

  @Override
  public void setSelectedItem(@Nullable Object anItem) {
    //noinspection unchecked
    mySelection = (T)anItem;
  }

  @Override
  @Nullable
  public Object getSelectedItem() {
    return mySelection;
  }

  @Nullable
  public T getSelected() {
    return mySelection;
  }

  public void update() {
    super.fireContentsChanged(this, -1, -1);
  }

  public boolean contains(T item) {
    return getItems().contains(item);
  }

  @Nonnull
  abstract protected List<T> getItems();
}


text:
<?php

/**
 * This file is part of Gitonomy.
 *
 * (c) Alexandre Salomé <alexandre.salome@gmail.com>
 * (c) Julien DIDIER <genzo.wm@gmail.com>
 *
 * This source file is subject to the GPL license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Gitonomy\Bundle\CoreBundle\Validation\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Doctrine\Bundle\DoctrineBundle\Registry;

class NewEmailValidator extends ConstraintValidator
{
    /**
     * @var Symfony\Bundle\DoctrineBundle\Registry
     */
    protected $doctrineRegistry;

    public function __construct(Registry $doctrineRegistry)
    {
        $this->doctrineRegistry = $doctrineRegistry;
    }

    public function validate($value, Constraint $constraint)
    {
        if (!$value) {
            return;
        }

        $email = $this->doctrineRegistry->getRepository('GitonomyCoreBundle:Email')->findOneByEmail($value);
        if ($email) {
            $this->context->addViolation($constraint->message);
        }
    }
}


text:
package com.kifile.android.cornerstone.impl.fetchers;

import java.io.IOException;
import java.io.InputStream;

import com.kifile.android.cornerstone.core.AbstractFetcherConverter;
import com.kifile.android.cornerstone.core.DataFetcher;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * Convert a InputStream to Bitmap.
 *
 * @author kifile
 */
public class InputStream2BitmapConverter extends AbstractFetcherConverter<InputStream, Bitmap> {

    public InputStream2BitmapConverter(DataFetcher<InputStream> proxy) {
        super(proxy);
    }

    @Override
    protected Bitmap convert(InputStream inputStream) {
        if (inputStream != null) {
            try {
                return BitmapFactory.decodeStream(inputStream);
            } finally {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}


text:
GRAPH_SIZES=(1000 10000 100000 1000000)
GRAPH_NAME_SIZES=(1k 10k 100k 1m)
GRAPH_TYPE=sf
#GRAPH_EDGES=2
GRAPH_AVG_K=8
GRAPH_MAX_K=20
GRAPH_MU=0.1
NPROCS=(2 4 8)

# Graph directory
GRAPH_DIR=../../../data/graphs

# Use weighted graphs or not
USEWEIGHT=0

# Remove old graphs
rm ${GRAPH_DIR}/*.txt
rm ${GRAPH_DIR}/*.bin
rm ${GRAPH_DIR}/*.weights
rm ${GRAPH_DIR}/*.remote
rm ${GRAPH_DIR}/*.metis
rm ${GRAPH_DIR}/*.part.*

# Create the graphs
for (( i = 0 ; i < ${#GRAPH_SIZES[@]} ; i=$i+1 ));
do
    GRAPHFILE=${GRAPH_DIR}/graph_${GRAPH_TYPE}_${GRAPH_NAME_SIZES[$i]}
    echo "Saving ${GRAPH_TYPE} graph with ${GRAPH_SIZES[$i]} nodes to ${GRAPHFILE}:"
    if [ $USEWEIGHT -eq 0 ]; then
	WEIGHTFLAG=""
    else
	echo "ERROR: These codes do not support weighted graphs"
	exit 1
    fi

    # Generate the graph
    ./benchmark -N ${GRAPH_SIZES[$i]} -k ${GRAPH_AVG_K} -maxk ${GRAPH_MAX_K} -mu ${GRAPH_MU} -minc 20 -maxc 50
    mv network.dat ${GRAPHFILE}.txt
    rm *.dat
    if [ $USEWEIGHT -eq 0 ]; then
	WEIGHTFLAG=""
    else
	WEIGHTFLAG="-w ${GRAPHFILE}.weights"
    fi

    # Convert for serial louvain
    ../../sequential/convert -i ${GRAPHFILE}.txt -o ${GRAPHFILE}.bin ${WEIGHTFLAG}

    # Convert for metis
    echo "./txt2metis.py ${WEIGHTFLAG} ${GRAPHFILE}.txt ${GRAPHFILE}.metis"
    ./txt2metis.py ${WEIGHTFLAG} ${GRAPHFILE}.txt ${GRAPHFILE}.metis

    # Create partitions for each node count
    for NPROC in "${NPROCS[@]}";
    do
	# Partition with metis
	pmetis ${GRAPHFILE}.metis ${NPROC}

        # Run the parallel converter on the partitioned graph
        ../../parallel/convert -i ${GRAPHFILE}.txt -p ${GRAPHFILE}.metis.part.${NPROC} -o ${GRAPHFILE}_${NPROC} -n ${NPROC} ${WEIGHTFLAG}

    done

done


text:
package com.facebook.buck.features.project.intellij;

import com.facebook.buck.android.AndroidBinaryDescriptionArg;
import com.facebook.buck.android.AndroidLibraryDescription;
import com.facebook.buck.android.AndroidLibraryGraphEnhancer;
import com.facebook.buck.android.AndroidResourceDescription;
import com.facebook.buck.android.AndroidResourceDescriptionArg;
import com.facebook.buck.android.DummyRDotJava;
import com.facebook.buck.core.model.BuildTarget;
import com.facebook.buck.core.model.targetgraph.TargetNode;
import com.facebook.buck.core.rules.ActionGraphBuilder;
import com.facebook.buck.core.rules.BuildRule;
import com.facebook.buck.core.rules.SourcePathRuleFinder;
import com.facebook.buck.core.sourcepath.SourcePath;
import com.facebook.buck.core.sourcepath.resolver.SourcePathResolver;
import com.facebook.buck.features.project.intellij.model.IjModuleFactoryResolver;
import com.facebook.buck.io.filesystem.ProjectFilesystem;
import com.facebook.buck.jvm.java.CompilerOutputPaths;
import com.facebook.buck.jvm.java.JavacPluginParams;
import com.facebook.buck.jvm.java.JvmLibraryArg;
import com.facebook.buck.util.Optionals;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

class DefaultIjModuleFactoryResolver implements IjModuleFactoryResolver {

  private final ActionGraphBuilder graphBuilder;
  private final SourcePathResolver sourcePathResolver;
  private final SourcePathRuleFinder ruleFinder;
  private final ProjectFilesystem projectFilesystem;
  private final Set<BuildTarget> requiredBuildTargets;

  DefaultIjModuleFactoryResolver(
      ActionGraphBuilder graphBuilder,
      SourcePathResolver sourcePathResolver,
      SourcePathRuleFinder ruleFinder,
      ProjectFilesystem projectFilesystem,
      Set<BuildTarget> requiredBuildTargets) {
    this.graphBuilder = graphBuilder;
    this.sourcePathResolver = sourcePathResolver;
    this.ruleFinder = ruleFinder;
    this.projectFilesystem = projectFilesystem;
    this.requiredBuildTargets = requiredBuildTargets;
  }

  @Override
  public Optional<Path> getDummyRDotJavaPath(TargetNode<?> targetNode) {
    BuildTarget dummyRDotJavaTarget =
        AndroidLibraryGraphEnhancer.getDummyRDotJavaTarget(targetNode.getBuildTarget());
    Optional<BuildRule> dummyRDotJavaRule = graphBuilder.getRuleOptional(dummyRDotJavaTarget);
    if (dummyRDotJavaRule.isPresent()) {
      requiredBuildTargets.add(dummyRDotJavaTarget);
      return Optional.of(DummyRDotJava.getOutputJarPath(dummyRDotJavaTarget, projectFilesystem));
    }
    return Optional.empty();
  }

  @Override
  public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescriptionArg> targetNode) {
    AndroidBinaryDescriptionArg arg = targetNode.getConstructorArg();
    Optional<SourcePath> manifestSourcePath = arg.getManifest();
    if (!manifestSourcePath.isPresent()) {
      manifestSourcePath = arg.getManifestSkeleton();
    }
    if (!manifestSourcePath.isPresent()) {
      throw new IllegalArgumentException(
          "android_binary "
              + targetNode.getBuildTarget()
              + " did not specify manifest or manifest_skeleton");
    }
    return sourcePathResolver.getAbsolutePath(manifestSourcePath.get());
  }

  @Override
  public Optional<Path> getLibraryAndroidManifestPath(
      TargetNode<AndroidLibraryDescription.CoreArg> targetNode) {
    Optional<SourcePath> manifestPath = targetNode.getConstructorArg().getManifest();
    return manifestPath.map(sourcePathResolver::getAbsolutePath).map(projectFilesystem::relativize);
  }

  @Override
  public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescriptionArg> targetNode) {
    return targetNode
        .getConstructorArg()
        .getProguardConfig()
        .map(this::getRelativePathAndRecordRule);
  }

  @Override
  public Optional<Path> getAndroidResourcePath(
      TargetNode<AndroidResourceDescriptionArg> targetNode) {
    return AndroidResourceDescription.getResDirectoryForProject(graphBuilder, targetNode)
        .map(this::getRelativePathAndRecordRule);
  }

  @Override
  public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescriptionArg> targetNode) {
    return AndroidResourceDescription.getAssetsDirectoryForProject(graphBuilder, targetNode)
        .map(this::getRelativePathAndRecordRule);
  }

  @Override
  public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg> targetNode) {
    JavacPluginParams annotationProcessingParams =
        targetNode
            .getConstructorArg()
            .buildJavaAnnotationProcessorParams(targetNode.getBuildTarget(), graphBuilder);
    if (annotationProcessingParams == null || annotationProcessingParams.isEmpty()) {
      return Optional.empty();
    }

    return CompilerOutputPaths.getAnnotationPath(projectFilesystem, targetNode.getBuildTarget());
  }

  @Override
  public Optional<Path> getCompilerOutputPath(TargetNode<? extends JvmLibraryArg> targetNode) {
    BuildTarget buildTarget = targetNode.getBuildTarget();
    Path compilerOutputPath = CompilerOutputPaths.getOutputJarPath(buildTarget, projectFilesystem);
    return Optional.of(compilerOutputPath);
  }

  private Path getRelativePathAndRecordRule(SourcePath sourcePath) {
    requiredBuildTargets.addAll(
        Optionals.toStream(ruleFinder.getRule(sourcePath).map(BuildRule::getBuildTarget))
            .collect(Collectors.toList()));
    return sourcePathResolver.getRelativePath(sourcePath);
  }
}


text:
import matplotlib.pyplot as plt
import numpy as np
import sys

prefix = '../alphaWhales/'
files = sys.argv[1:]
entropies = []
for file in files:
   f = open(prefix + file, 'r')
   for line in f:
      if (line.startswith("train cross entropy: ")):
         entropy = float(line.split('train cross entropy: ')[1][:-1])
         entropies.append(entropy)
# logs = np.zeros(len(entropies))
logs = np.log10(np.array(entropies))
plt.plot(logs)
x,p = plt.xticks()
xticks = [str(t*25) for t in x]
plt.xticks(x, xticks)

y,p = plt.yticks()
yticks = [str(round(pow(10,t))) for t in y]
plt.yticks(y, yticks)

plt.show()


text:
using System.Collections.Generic;

namespace Snowflake.Information
{
    public class Info: IInfo
    {
        public string PlatformID { get; }
        public string Name { get; }
        public IDictionary<string, string> Metadata { get; set; }

        public Info(string platformId, string name, IDictionary<string,string> metadata)
        {
            this.PlatformID = platformId;
            this.Name = name;
            this.Metadata = metadata;
        }

    }
}


text:
package org.encog.app.analyst.script.segregate;

/**
 * Holds all of the segregation targets for a script.
 *
 */
public class AnalystSegregate {

	/**
	 * The segregation targets.
	 */
	private AnalystSegregateTarget[] segregateTargets;

	/**
	 * @return the segregateTargets.
	 */
	public final AnalystSegregateTarget[] getSegregateTargets() {
		return this.segregateTargets;
	}

	/**
	 * @param theSegregateTargets
	 *            the segregateTargets to set.
	 */
	public final void setSegregateTargets(
			final AnalystSegregateTarget[] theSegregateTargets) {
		this.segregateTargets = theSegregateTargets;
	}

}


text:
from motorengine import Document, StringField

class User(Document):
    """ 用户 """
    username = StringField(required=True)
    password = StringField(required=True)


text:
var _ = require('lodash');

class TimeLogService {
  constructor () {
    this._referenceTimes = [];
  }

  log (event) {
    this._referenceTimes.push({event: event, time: process.hrtime()});
  }

  exportMillis () {
    var startReference = this._referenceTimes[0];
    return _.map(this._referenceTimes, (reference) => {
      return {
        event: reference.event,
        time: (reference.time[0] - startReference.time[0]) * 1000 + (reference.time[1] - startReference.time[1]) / 1000000
      };
    });
  }
}

module.exports = TimeLogService;


text:
test_description="Testing out subcomm "
. ./test-lib.sh

test_todo_session "Testing of subcomm" <<EOF
>>> ruby bin/subcommand.rb help foo
Usage: foo [options]
desc for foo
    -f, --[no-]force                 force verbosely
>>> end
>>> ruby bin/subcommand.rb foo --help
Usage: foo [options]
desc for foo
    -f, --[no-]force                 force verbosely
>>> end

EOF
test_done


text:
<?php

class CompanyUser extends Eloquent {

	public $timestamps = false;

	protected $primaryKey = 'company_user_id';
	protected $table = 'company_user';

	protected $fillable = array('user_id', 'company_id');

	public function Company()
	{
		return $this->belongsTo('company', 'company_id');
	}

	public function User()
	{
		return $this->belongsTo('user', 'user_id');
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='../../../../../../../../../../../test.xsl'?>
<!--
    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.
-->
<!DOCTYPE Test SYSTEM '../../../../../../../../../../../test.dtd'>
<!--
-->

<Test
    ID="ReadConfiguration_03"
    date-of-creation="2005-11-03"
    timeout="1"
    >

    <APITestDescription>
        <TestedClass name="java.util.logging.LogManager"/>
        <TestedMethod name="public static LogManager getLogManager()" />
        <TestedMethod name="public void readConfiguration(InputStream ins)" />

        <Description>
            Verify how LogManager.readConfiguration calls are reflected
            in results of LogManager.getProperty calls
            - static configurator through class specified in
            java.util.logging.config.class system property
        </Description>

    </APITestDescription>

    <Keyword name="functional" />

    <Source name="ReadConfiguration_03.java"/>

    <Runner ID="Runtime">
        <Param name="toRun" value="org.apache.harmony.test.func.api.java.util.logging.LogManager.ReadConfiguration_03">
            <Option name="vmParam" value="-Dorg.apache.harmony.test.func.api.java.logging.LogManager.readConfiguration.path=$TestDirectory$FileSeparatorauxiliary$FileSeparatorsc.cfg" />
            <Option name="vmParam" value="-Djava.util.logging.config.class=org.apache.harmony.test.func.api.java.util.logging.LogManager.LogManagerConfigurator" />
        </Param>
    </Runner>

    <Restriction name="OtherVMOnly"/>

</Test>


text:
package controllers

import (
	"github.com/revel/revel"
	"github.com/MoonBabyLabs/kekcollections"
	"github.com/MoonBabyLabs/kek"
	"errors"
	"log"
	"strings"
)

type Put struct {
	*revel.Controller
	Base
}

func (c Put) PutResource(resource string) revel.Result {
        if revel.Config.StringDefault("require.jwt.putResource", "true") == "true" {
                accessErr := c.HasAccess(c.Request.Header.Get("Authorization"),"update"); if accessErr != nil {
                        return c.RenderError(accessErr)
                }
        }

	item := make(map[string]interface{})
	c.Params.BindJSON(&item)
	itemType := resource[0:2]
	hiddenFieldsConf := revel.Config.StringDefault("hide.fields", "password")
	hiddenFields := strings.Split(hiddenFieldsConf, ",")

	switch itemType {
	case "cc":
		col, loadEr := kekcollections.Collection{}.LoadById(resource, false, false)

		// Looks like its not in our space. Lets try to verify that its good kekcontact and put into the space
		if loadEr != nil {

		} else {
			// Lets update the item in our space.
			c.Params.BindJSON(&col)
			col.Id = resource
			updErr := col.Save()

			if updErr != nil {
				return c.RenderError(updErr)
			}
			return c.RenderJSON(col)
		}
		break
	case "dd":
		_, loadErr := kek.Doc{}.Get(resource, false)
		log.Print(loadErr)

		if loadErr != nil {

		} else {
			upd, err := kek.Doc{}.Update(resource, item, false)

			if err != nil {
				data := make(map[string]interface{})
				data["success"] = false
				data["error"] = err.Error()

				return c.RenderJSON(data)
			}

			for _, hf := range hiddenFields {
				delete(upd.Attributes, hf)
			}

			return c.RenderContent(upd)
			break
		}
	}

	return c.RenderError(errors.New("could not find item to update"))
}

func (c Put) PutCollectionResource(collection string, resource string) revel.Result {
	if revel.Config.StringDefault("require.jwt.putCollectionResource", "true") == "true" {
		accessErr := c.HasAccess(c.Request.Header.Get("Authorization"),"update"); if accessErr != nil {
			return c.RenderError(accessErr)
		}
	}

	kd, kdLoadErr := kek.Doc{}.Get(resource, false)

	if kdLoadErr != nil {
		return c.RenderError(kdLoadErr)
	}

	resType := collection[0:2]

	if resType == "dd" {
		return c.RenderError(errors.New("you are trying to save a resource into a kekdoc. This isn't possible. You must save into an appropriate kekcollection"))
	} else if resType == "cc" {
		col, colErr := kekcollections.Collection{}.LoadById(collection, false, false)

		if colErr != nil {
			return c.RenderError(colErr)
		}

		col.AddResource(resource)
	} else {
		col, colErr := kekcollections.Collection{}.LoadBySlug(collection, false, false)

		if colErr != nil {
			return c.RenderError(colErr)
		}

		col.AddResource(resource)
	}

	return c.RenderContent(kd)
}


text:
import random
import string
import glob
import os
from time import sleep
import uuid
import jinja2

from memoize import mproperty

from osmaxx.conversion.converters.converter_gis.detail_levels import (
    DETAIL_LEVEL_ALL,
    DETAIL_LEVEL_TABLES,
)
from osmaxx.conversion.converters.converter_gis.helper.default_postgres import (
    get_default_postgres_wrapper,
)
from osmaxx.conversion.converters.converter_gis.helper.osm_boundaries_importer import (
    OSMBoundariesImporter,
)
from osmaxx.conversion.converters.utils import logged_check_call
from osmaxx.utils import polyfile_helpers
from osmaxx.conversion.conversion_settings import DBConfig

def get_random_string(length):
    # choose from all lowercase letter
    letters = string.ascii_lowercase
    result_str = ''.join(random.choice(letters) for i in range(length))
    return result_str

class BootStrapper:
    def __init__(
        self, area_polyfile_string, *, cutted_pbf_file, detail_level=DETAIL_LEVEL_ALL
    ):

        self.area_polyfile_string = area_polyfile_string
        self._pbf_file_path = cutted_pbf_file
        self._detail_level = DETAIL_LEVEL_TABLES[detail_level]
        tmp_name = get_random_string(20)
        self.db_config = DBConfig(db_name=f"osmaxx_{tmp_name}")
        self._postgres = get_default_postgres_wrapper(
            db_name=self.db_config.db_name,
        )

        self._script_base_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "templates")
        )
        self._terminal_style_path = os.path.join(
            self._script_base_dir, "styles", "terminal.style"
        )
        self._style_path = os.path.join(self._script_base_dir, "styles", "style.lua")

    def __enter__(self):
        self._postgres.create_db()
        return self

    def __exit__(self, *args, **kwargs):
        self._postgres.drop_db()

    def bootstrap(self):
        print("Bootstrap", "#" * 30)
        # print("resetting database/views")
        # self._reset_database()
        print("setup database")
        self._setup_db()
        print("import boundaries")
        self._import_boundaries()
        print("import pbf")
        self._import_pbf()
        print("setup db functions")
        self._setup_db_functions()
        print("harmonize db")
        self._harmonize_database()
        print("filter data")
        self._filter_data()
        print("create views")
        self._create_views()

    @mproperty
    def geom(self):
        return polyfile_helpers.parse_poly_string(self.area_polyfile_string)

    def _reset_database(self):
        self._postgres.drop_db()
        self._postgres.create_db()
        self._setup_db()

    def _setup_db(self):
        drop_and_recreate_script_folder = os.path.join(
            self._script_base_dir, "sql", "drop_and_recreate"
        )
        self._execute_sql_scripts_in_folder(drop_and_recreate_script_folder)
        extensions = [
            "postgis",
            "hstore",
            "unaccent",
            "fuzzystrmatch",
            "osml10n",
            "osml10n_thai_transcript",
        ]
        for extension in extensions:
            print(30 * "#")
            print(extension)
            self._postgres.create_extension(extension)
            self._postgres.create_extension(
                extension, schema=self.db_config.db_schema_tmp
            )
            self._postgres.create_extension(
                extension, schema=self.db_config.db_schema_tmp_view
            )

    def _import_boundaries(self):
        osm_importer = OSMBoundariesImporter(db_config=self.db_config)
        osm_importer.load_area_specific_data(extent=self.geom)

    def _setup_db_functions(self):
        self._execute_sql_scripts_in_folder(
            os.path.join(self._script_base_dir, "sql", "functions")
        )

    def _harmonize_database(self):
        cleanup_sql_path = os.path.join(
            self._script_base_dir, "sql", "sweeping_data.sql.jinja2"
        )
        sql = self._compile_template(
            cleanup_sql_path, temp_table=f"tmp_{self.db_config.db_name}_harmonize"
        )
        print(self._postgres.execute_sql_command(sql))

    def _filter_data(self):
        self._postgres = get_default_postgres_wrapper(
            db_name=self.db_config.db_name,
        )
        filter_sql_script_folders = [
            "address",
            "adminarea_boundary",
            "building",
            "landuse",
            "military",
            "natural",
            "nonop",
            "geoname",
            "pow",
            "poi",
            "misc",
            "transport",
            "railway",
            "road",
            "route",
            "traffic",
            "utility",
            "water",
        ]
        base_dir = os.path.join(self._script_base_dir, "sql", "filter")
        for script_folder in filter_sql_script_folders:
            script_folder_path = os.path.join(base_dir, script_folder)
            self._execute_sql_scripts_in_folder(script_folder_path)

    def _create_views(self):
        create_view_sql_script_folder = os.path.join(
            self._script_base_dir, "sql", "create_view"
        )

        def filter_script_names(sql_file_path):
            file_name = os.path.basename(sql_file_path)
            if any(
                table_name in file_name
                for table_name in self._detail_level["included_layers"]
            ):
                return True
            return False

        self._execute_sql_scripts_in_folder(
            create_view_sql_script_folder, filter_function=filter_script_names
        )

    def _level_adapted_script_path(self, script_path):
        script_directory = os.path.dirname(script_path)
        script_name = os.path.basename(script_path)
        level_folder_name = self._detail_level["level_folder_name"]
        if level_folder_name:
            level_script_path = os.path.join(
                script_directory, level_folder_name, script_name
            )
            if os.path.exists(level_script_path):
                return level_script_path
        return script_path

    def _execute_sql_scripts_in_folder(
        self,
        folder_path,
        *,
        filter_function=lambda x: True,
    ):
        sql_scripts_in_folder = filter(
            filter_function, glob.glob(os.path.join(folder_path, "*.sql.jinja2"))
        )
        for script_path in sorted(sql_scripts_in_folder, key=os.path.basename):
            script_path = self._level_adapted_script_path(script_path)
            print(script_path)
            compiled_sql = self._compile_template(script_path)
            self._postgres.execute_sql_command(compiled_sql)

    def _compile_template(self, script_path, **kwargs):
        with open(script_path, "r") as _f:
            template = jinja2.Template(_f.read(), autoescape=False)
        return template.render(
            schema_name=self.db_config.db_schema_tmp,
            view_schema_name=self.db_config.db_schema_tmp_view,
            **kwargs,
        )

    def _import_pbf(self):
        db_name = self._postgres.get_db_name()
        db_host = self._postgres.get_host()
        db_port = self._postgres.get_port()
        db_user = self._postgres.get_user()

        osm_2_pgsql_command = [
            "osm2pgsql",
            "--database",
            f"{db_name}",
            "--username",
            f"{db_user}",
            "--host",
            f"{db_host}",
            "--port",
            f"{db_port}",
            "--create",
            "--extra-attributes",
            "--slim",
            "--latlon",
            "--prefix=osm",
            f"--style={self._terminal_style_path}",
            f"--tag-transform-script={self._style_path}",
            "--number-processes=4",
            "--hstore-all",
            "--input-reader",
            "pbf",
            self._pbf_file_path,
        ]
        logged_check_call(osm_2_pgsql_command)