text:
package org.apache.nifi.processors.kafka.pubsub;

import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.FencedInstanceIdException;
import org.apache.kafka.common.errors.ProducerFencedException;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeader;
import org.apache.nifi.components.ConfigVerificationResult;
import org.apache.nifi.components.ConfigVerificationResult.Outcome;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.logging.ComponentLog;
import org.apache.nifi.schema.access.SchemaNotFoundException;
import org.apache.nifi.serialization.MalformedRecordException;
import org.apache.nifi.serialization.RecordSetWriter;
import org.apache.nifi.serialization.RecordSetWriterFactory;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.apache.nifi.serialization.WriteResult;
import org.apache.nifi.serialization.record.MapRecord;
import org.apache.nifi.serialization.record.Record;
import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.RecordSet;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.stream.io.exception.TokenTooLargeException;
import org.apache.nifi.stream.io.util.StreamDemarcator;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.regex.Pattern;

public class PublisherLease implements Closeable {
    private final ComponentLog logger;
    private final Producer<byte[], byte[]> producer;
    private final int maxMessageSize;
    private final long maxAckWaitMillis;
    private final boolean useTransactions;
    private final Pattern attributeNameRegex;
    private final Charset headerCharacterSet;
    private final PublishStrategy publishStrategy;
    private final RecordSetWriterFactory recordKeyWriterFactory;
    private volatile boolean poisoned = false;
    private final AtomicLong messagesSent = new AtomicLong(0L);

    private volatile boolean transactionsInitialized = false;
    private volatile boolean activeTransaction = false;

    private InFlightMessageTracker tracker;

    public PublisherLease(final Producer<byte[], byte[]> producer, final int maxMessageSize, final long maxAckWaitMillis,
                          final ComponentLog logger, final boolean useTransactions, final Pattern attributeNameRegex,
                          final Charset headerCharacterSet, final PublishStrategy publishStrategy, final RecordSetWriterFactory recordKeyWriterFactory) {
        this.producer = producer;
        this.maxMessageSize = maxMessageSize;
        this.logger = logger;
        this.maxAckWaitMillis = maxAckWaitMillis;
        this.useTransactions = useTransactions;
        this.attributeNameRegex = attributeNameRegex;
        this.headerCharacterSet = headerCharacterSet;
        this.publishStrategy = publishStrategy;
        this.recordKeyWriterFactory = recordKeyWriterFactory;
    }

    protected void poison() {
        this.poisoned = true;
    }

    public boolean isPoisoned() {
        return poisoned;
    }

    void beginTransaction() {
        if (!useTransactions) {
            return;
        }

        try {
            if (!transactionsInitialized) {
                producer.initTransactions();
                transactionsInitialized = true;
            }

            producer.beginTransaction();
            activeTransaction = true;
        } catch (final Exception e) {
            poison();
            throw e;
        }
    }

    void rollback() {
        if (!useTransactions || !activeTransaction) {
            return;
        }

        try {
            producer.abortTransaction();
        } catch (final Exception e) {
            poison();
            throw e;
        }

        activeTransaction = false;
    }

    void fail(final FlowFile flowFile, final Exception cause) {
        getTracker().fail(flowFile, cause);
        rollback();
    }

    void publish(final FlowFile flowFile, final InputStream flowFileContent, final byte[] messageKey, final byte[] demarcatorBytes, final String topic, final Integer partition) throws IOException {
        if (tracker == null) {
            tracker = new InFlightMessageTracker(logger);
        }

        try {
            byte[] messageContent;
            if (demarcatorBytes == null || demarcatorBytes.length == 0) {
                if (flowFile.getSize() > maxMessageSize) {
                    tracker.fail(flowFile, new TokenTooLargeException("A message in the stream exceeds the maximum allowed message size of " + maxMessageSize + " bytes."));
                    return;
                }
                // Send FlowFile content as it is, to support sending 0 byte message.
                messageContent = new byte[(int) flowFile.getSize()];
                StreamUtils.fillBuffer(flowFileContent, messageContent);
                publish(flowFile, messageKey, messageContent, topic, tracker, partition);
                return;
            }

            try (final StreamDemarcator demarcator = new StreamDemarcator(flowFileContent, demarcatorBytes, maxMessageSize)) {
                while ((messageContent = demarcator.nextToken()) != null) {
                    publish(flowFile, messageKey, messageContent, topic, tracker, partition);

                    if (tracker.isFailed(flowFile)) {
                        // If we have a failure, don't try to send anything else.
                        return;
                    }
                }
            } catch (final TokenTooLargeException ttle) {
                tracker.fail(flowFile, ttle);
            }
        } catch (final Exception e) {
            tracker.fail(flowFile, e);
            poison();
            throw e;
        }
    }

    void publish(final FlowFile flowFile, final RecordSet recordSet, final RecordSetWriterFactory writerFactory, final RecordSchema schema,
                 final String messageKeyField, final String explicitTopic, final Function<Record, Integer> partitioner, final PublishMetadataStrategy metadataStrategy) throws IOException {
        if (tracker == null) {
            tracker = new InFlightMessageTracker(logger);
        }

        final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);

        Record record;
        int recordCount = 0;

        try {
            while ((record = recordSet.next()) != null) {
                recordCount++;
                baos.reset();

                final String topic;
                final List<Header> headers;
                final byte[] messageContent;
                final byte[] messageKey;
                Integer partition;
                if (PublishStrategy.USE_WRAPPER.equals(publishStrategy)) {
                    headers = toHeadersWrapper(record.getValue("headers"));
                    final Object key = record.getValue("key");
                    final Object value = record.getValue("value");
                    messageContent = toByteArray("value", value, writerFactory, flowFile);
                    messageKey = toByteArray("key", key, recordKeyWriterFactory, flowFile);

                    if (metadataStrategy == PublishMetadataStrategy.USE_RECORD_METADATA) {
                        final Object metadataObject = record.getValue("metadata");
                        if (metadataObject instanceof Record) {
                            final Record metadataRecord = (Record) metadataObject;
                            final String recordTopic = metadataRecord.getAsString("topic");
                            topic = recordTopic == null ? explicitTopic : recordTopic;

                            try {
                                partition = metadataRecord.getAsInt("partition");
                            } catch (final Exception e) {
                                logger.warn("Encountered invalid partition for record in {}; will use configured partitioner for Record", flowFile);
                                partition = partitioner == null ? null : partitioner.apply(record);
                            }
                        } else {
                            topic = explicitTopic;
                            partition = partitioner == null ? null : partitioner.apply(record);
                        }
                    } else {
                        topic = explicitTopic;
                        partition = partitioner == null ? null : partitioner.apply(record);
                    }
                } else {
                    final Map<String, String> additionalAttributes;
                    try (final RecordSetWriter writer = writerFactory.createWriter(logger, schema, baos, flowFile)) {
                        final WriteResult writeResult = writer.write(record);
                        additionalAttributes = writeResult.getAttributes();
                        writer.flush();
                    }
                    headers = toHeaders(flowFile, additionalAttributes);
                    messageContent = baos.toByteArray();
                    messageKey = getMessageKey(flowFile, writerFactory, record.getValue(messageKeyField));
                    topic = explicitTopic;
                    partition = partitioner == null ? null : partitioner.apply(record);
                }

                publish(flowFile, headers, messageKey, messageContent, topic, tracker, partition);

                if (tracker.isFailed(flowFile)) {
                    // If we have a failure, don't try to send anything else.
                    return;
                }
            }

            if (recordCount == 0) {
                tracker.trackEmpty(flowFile);
            }
        } catch (final TokenTooLargeException ttle) {
            tracker.fail(flowFile, ttle);
        } catch (final SchemaNotFoundException | MalformedRecordException snfe) {
            throw new IOException(snfe);
        } catch (final Exception e) {
            tracker.fail(flowFile, e);
            poison();
            throw e;
        }
    }

    private List<Header> toHeadersWrapper(final Object fieldHeaders) {
        final List<Header> headers = new ArrayList<>();
        if (fieldHeaders instanceof Record) {
            final Record recordHeaders = (Record) fieldHeaders;
            for (String fieldName : recordHeaders.getRawFieldNames()) {
                final String fieldValue = recordHeaders.getAsString(fieldName);
                headers.add(new RecordHeader(fieldName, fieldValue.getBytes(StandardCharsets.UTF_8)));
            }
        }
        return headers;
    }

    private static final RecordField FIELD_TOPIC = new RecordField("topic", RecordFieldType.STRING.getDataType());
    private static final RecordField FIELD_PARTITION = new RecordField("partition", RecordFieldType.INT.getDataType());
    private static final RecordField FIELD_TIMESTAMP = new RecordField("timestamp", RecordFieldType.TIMESTAMP.getDataType());
    private static final RecordSchema SCHEMA_METADATA = new SimpleRecordSchema(Arrays.asList(
            FIELD_TOPIC, FIELD_PARTITION, FIELD_TIMESTAMP));
    private static final RecordField FIELD_METADATA = new RecordField("metadata", RecordFieldType.RECORD.getRecordDataType(SCHEMA_METADATA));
    private static final RecordField FIELD_HEADERS = new RecordField("headers", RecordFieldType.MAP.getMapDataType(RecordFieldType.STRING.getDataType()));

    private Record toWrapperRecord(final Record record, final List<Header> headers,
                                   final String messageKeyField, final String topic) {
        final Record recordKey = (Record) record.getValue(messageKeyField);
        final RecordSchema recordSchemaKey = ((recordKey == null) ? null : recordKey.getSchema());
        final RecordField fieldKey = new RecordField("key", RecordFieldType.RECORD.getRecordDataType(recordSchemaKey));
        final RecordField fieldValue = new RecordField("value", RecordFieldType.RECORD.getRecordDataType(record.getSchema()));
        final RecordSchema schemaWrapper = new SimpleRecordSchema(Arrays.asList(FIELD_METADATA, FIELD_HEADERS, fieldKey, fieldValue));

        final Map<String, Object> valuesMetadata = new HashMap<>();
        valuesMetadata.put("topic", topic);
        valuesMetadata.put("timestamp", getTimestamp());
        final Record recordMetadata = new MapRecord(SCHEMA_METADATA, valuesMetadata);

        final Map<String, Object> valuesHeaders = new HashMap<>();
        for (Header header : headers) {
            valuesHeaders.put(header.key(), new String(header.value(), headerCharacterSet));
        }

        final Map<String, Object> valuesWrapper = new HashMap<>();
        valuesWrapper.put("metadata", recordMetadata);
        valuesWrapper.put("headers", valuesHeaders);
        valuesWrapper.put("key", record.getValue(messageKeyField));
        valuesWrapper.put("value", record);
        return new MapRecord(schemaWrapper, valuesWrapper);
    }

    protected long getTimestamp() {
        return System.currentTimeMillis();
    }

    private List<Header> toHeaders(final FlowFile flowFile, final Map<String, ?> additionalAttributes) {
        if (attributeNameRegex == null) {
            return Collections.emptyList();
        }

        final List<Header> headers = new ArrayList<>();
        for (final Map.Entry<String, String> entry : flowFile.getAttributes().entrySet()) {
            if (attributeNameRegex.matcher(entry.getKey()).matches()) {
                headers.add(new RecordHeader(entry.getKey(), entry.getValue().getBytes(headerCharacterSet)));
            }
        }

        for (final Map.Entry<String, ?> entry : additionalAttributes.entrySet()) {
            if (attributeNameRegex.matcher(entry.getKey()).matches()) {
                final Object value = entry.getValue();
                if (value != null) {
                    final String valueString = value.toString();
                    headers.add(new RecordHeader(entry.getKey(), valueString.getBytes(headerCharacterSet)));
                }
            }
        }
        return headers;
    }

    private byte[] toByteArray(final String name, final Object object, final RecordSetWriterFactory writerFactory, final FlowFile flowFile)
            throws IOException, SchemaNotFoundException, MalformedRecordException {
        if (object == null) {
            return null;
        } else if (object instanceof Record) {
            if (writerFactory == null) {
                throw new MalformedRecordException("Record has a key that is itself a record, but the 'Record Key Writer' of the processor was not configured. If Records are expected to have a " +
                    "Record as the key, the 'Record Key Writer' property must be set.");
            }

            final Record record = (Record) object;
            final RecordSchema schema = record.getSchema();
            try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 final RecordSetWriter writer = writerFactory.createWriter(logger, schema, baos, flowFile)) {
                writer.write(record);
                writer.flush();
                return baos.toByteArray();
            }
        } else if (object instanceof Byte[]) {
            final Byte[] bytesUppercase = (Byte[]) object;
            final byte[] bytes = new byte[bytesUppercase.length];
            for (int i = 0; (i < bytesUppercase.length); ++i) {
                bytes[i] = bytesUppercase[i];
            }
            return bytes;
        } else if (object instanceof String) {
            final String string = (String) object;
            return string.getBytes(StandardCharsets.UTF_8);
        } else {
            throw new MalformedRecordException(String.format("Couldn't convert %s record data to byte array.", name));
        }
    }

    private byte[] getMessageKey(final FlowFile flowFile, final RecordSetWriterFactory writerFactory,
                                 final Object keyValue) throws IOException, SchemaNotFoundException {
        final byte[] messageKey;
        if (keyValue == null) {
            messageKey = null;
        } else if (keyValue instanceof byte[]) {
            messageKey = (byte[]) keyValue;
        } else if (keyValue instanceof Byte[]) {
            // This case exists because in our Record API we currently don't have a BYTES type, we use an Array of type
            // Byte, which creates a Byte[] instead of a byte[]. We should address this in the future, but we should
            // account for the log here.
            final Byte[] bytes = (Byte[]) keyValue;
            final byte[] bytesPrimitive = new byte[bytes.length];
            for (int i = 0; i < bytes.length; i++) {
                bytesPrimitive[i] = bytes[i];
            }
            messageKey = bytesPrimitive;
        } else if (keyValue instanceof Record) {
            final Record keyRecord = (Record) keyValue;
            try (final ByteArrayOutputStream os = new ByteArrayOutputStream(1024)) {
                try (final RecordSetWriter writerKey = writerFactory.createWriter(logger, keyRecord.getSchema(), os, flowFile)) {
                    writerKey.write(keyRecord);
                    writerKey.flush();
                }
                messageKey = os.toByteArray();
            }
        } else {
            final String keyString = keyValue.toString();
            messageKey = keyString.getBytes(StandardCharsets.UTF_8);
        }
        return messageKey;
    }

    private void addHeaders(final FlowFile flowFile, final Map<String, String> additionalAttributes, final ProducerRecord<?, ?> record) {
        if (attributeNameRegex == null) {
            return;
        }

        final Headers headers = record.headers();
        for (final Map.Entry<String, String> entry : flowFile.getAttributes().entrySet()) {
            if (attributeNameRegex.matcher(entry.getKey()).matches()) {
                headers.add(entry.getKey(), entry.getValue().getBytes(headerCharacterSet));
            }
        }

        for (final Map.Entry<String, String> entry : additionalAttributes.entrySet()) {
            if (attributeNameRegex.matcher(entry.getKey()).matches()) {
                headers.add(entry.getKey(), entry.getValue().getBytes(headerCharacterSet));
            }
        }
    }

    protected void publish(final FlowFile flowFile, final byte[] messageKey, final byte[] messageContent, final String topic, final InFlightMessageTracker tracker, final Integer partition) {
        publish(flowFile, Collections.emptyList(), messageKey, messageContent, topic, tracker, partition);
    }

    protected void publish(final FlowFile flowFile, final List<Header> headers, final byte[] messageKey, final byte[] messageContent,
                           final String topic, final InFlightMessageTracker tracker, final Integer partition) {

        final Integer moddedPartition = partition == null ? null : Math.abs(partition) % (producer.partitionsFor(topic).size());
        final ProducerRecord<byte[], byte[]> record = new ProducerRecord<>(topic, moddedPartition, messageKey, messageContent, headers);

        producer.send(record, new Callback() {
            @Override
            public void onCompletion(final RecordMetadata metadata, final Exception exception) {
                if (exception == null) {
                    tracker.incrementAcknowledgedCount(flowFile);
                } else {
                    tracker.fail(flowFile, exception);
                    poison();
                }
            }
        });

        messagesSent.incrementAndGet();
        tracker.incrementSentCount(flowFile);
    }

    void ackConsumerOffsets(final String topic, final int partition, final long offset, final Integer leaderEpoch, final String consumerGroupId) {
        final TopicPartition topicPartition = new TopicPartition(topic, partition);
        final OffsetAndMetadata offsetAndMetadata = new OffsetAndMetadata(offset + 1, Optional.ofNullable(leaderEpoch), null);
        final Map<TopicPartition, OffsetAndMetadata> offsetMap = Collections.singletonMap(topicPartition, offsetAndMetadata);

        logger.debug("Acknowledging Consumer Offsets for topic={}, partition={}, offset={}, consumerGroup={}, leaderEpoch={}", topic, partition, offset, consumerGroupId, leaderEpoch);
        producer.sendOffsetsToTransaction(offsetMap, consumerGroupId);
    }

    public PublishResult complete() {
        if (tracker == null) {
            if (messagesSent.get() == 0L) {
                return PublishResult.EMPTY;
            }

            rollback();
            throw new IllegalStateException("Cannot complete publishing to Kafka because Publisher Lease was already closed");
        }

        try {
            producer.flush();

            if (activeTransaction) {
                producer.commitTransaction();
                activeTransaction = false;
            }
        } catch (final ProducerFencedException | FencedInstanceIdException e) {
            throw e;
        } catch (final Exception e) {
            poison();
            throw e;
        }

        try {
            tracker.awaitCompletion(maxAckWaitMillis);
            return tracker.createPublishResult();
        } catch (final InterruptedException e) {
            logger.warn("Interrupted while waiting for an acknowledgement from Kafka; some FlowFiles may be transferred to 'failure' even though they were received by Kafka");
            Thread.currentThread().interrupt();
            return tracker.failOutstanding(e);
        } catch (final TimeoutException e) {
            logger.warn("Timed out while waiting for an acknowledgement from Kafka; some FlowFiles may be transferred to 'failure' even though they were received by Kafka");
            return tracker.failOutstanding(e);
        } finally {
            tracker = null;
        }
    }

    @Override
    public void close() {
        producer.close(maxAckWaitMillis, TimeUnit.MILLISECONDS);
        tracker = null;
    }

    public InFlightMessageTracker getTracker() {
        if (tracker == null) {
            tracker = new InFlightMessageTracker(logger);
        }

        return tracker;
    }

    public List<ConfigVerificationResult> verifyConfiguration(final String topic) {
        final List<ConfigVerificationResult> verificationResults = new ArrayList<>();

        try {
            final List<PartitionInfo> partitionInfos = producer.partitionsFor(topic);

            verificationResults.add(new ConfigVerificationResult.Builder()
                .verificationStepName("Determine Topic Partitions")
                .outcome(Outcome.SUCCESSFUL)
                .explanation("Determined that there are " + partitionInfos.size() + " partitions for topic " + topic)
                .build());
        } catch (final Exception e) {
            logger.error("Failed to determine Partition Information for Topic {} in order to verify configuration", topic, e);

            verificationResults.add(new ConfigVerificationResult.Builder()
                .verificationStepName("Determine Topic Partitions")
                .outcome(Outcome.FAILED)
                .explanation("Could not fetch Partition Information: " + e)
                .build());
        }

        return verificationResults;
    }
}


text:
use strict;

# $Id: db2xml.pl,v 1.6 2009-05-07 09:31:48 louise Exp $
#
# compares DB content to XML data and updates xml
#
# Magic numbers, and other properties of the destination schema
# are documented here:
#        http://parl.stand.org.uk/cgi-bin/moin.cgi/DataSchema
#
# The XML files for Hansard objects come from the Public Whip parser:
#       http://scm.kforge.net/plugins/scmsvn/cgi-bin/viewcvs.cgi/trunk/parlparse/pyscraper/?root=ukparse
# And those for MPs are in (semi-)manually updated files here:
#       http://scm.kforge.net/plugins/scmsvn/cgi-bin/viewcvs.cgi/trunk/parlparse/members/?root=ukparse

use FindBin;
chdir $FindBin::Bin;
use lib "$FindBin::Bin";
use lib "$FindBin::Bin/../../perllib";

use mySociety::Config;
mySociety::Config::set_file("$FindBin::Bin/../conf/general");

use Getopt::Long;
use DBI;
use XML::Twig;

use vars qw($cronquiet $update_person $personid $members_xml_file $dbh $parldata $lastupdatedir $pwmembers $passer $debug
);

$parldata = mySociety::Config::get('RAWDATA');
$lastupdatedir = mySociety::Config::get('XAPIANDB') . '/../xml2db/';
$pwmembers = mySociety::Config::get('PWMEMBERS');

my $result = GetOptions (
                        "cronquiet" => \$cronquiet,
                        "update_person" => \$update_person,
                        "personid=s" => \$personid,
                        "debug" => \$debug,
                        );

#my $pwmembers = mySociety::Config::get('PWMEMBERS');
#$members_xml_file = $pwmembers . 'all-members.xml';

my $dsn = 'DBI:mysql:database=' . mySociety::Config::get('DB_NAME'). ':host=' . mySociety::Config::get('DB_HOST');
$dbh = DBI->connect($dsn, mySociety::Config::get('DB_USER'), mySociety::Config::get('DB_PASS'), { RaiseError => 1, PrintError => 0 });

if ($update_person && $personid) {
    update_person();
}

sub update_person {

    $passer->{'file_updated'} = '';

    unless (db_load_person()) {
        die "couldn't load person";
        #$passer->{'person_db_vals'} now holds mps vals
    }
    #unless ($passer->{'person_db_vals'}->{'mp_website'}) {
    #    die "no url for person in database to update";
    #}
    $passer->{'person_in_file'} = 0;

    my $twig = new XML::Twig(
        twig_handlers => {
        'personinfo' => \&xml_load_person,
    }, output_filter => 'safe',
        pretty_print => 'record',
    );

    my $twigfile = ($pwmembers . "websites.xml");
    $twig->parsefile($twigfile);
    my $root = $twig->root ;

    # the person may not have a record in the file at all yet
    unless ($passer->{'person_in_file'}) {
        my $newid = 'uk.org.publicwhip/person/' . $personid;
        my $elt= XML::Twig::Elt->new( personinfo => {
            'id' => $newid,
            'mp_website' => $passer->{'person_db_vals'}->{'mp_website'}
        });
        $elt->paste($root);
        $passer->{'file_updated'} = $pwmembers . "websites.xml";
        print "added person. ";
  #'<personinfo id="uk.org.publicwhip/person/11225" mp_website="http://www.sionsimonmp.org/"/>'

    }

    if ($passer->{'file_updated'} eq $twigfile) {
        print "writing out $twigfile" if $debug;
        open( FH, ">$twigfile") or die "cannot open $twigfile: $!";
        $twig->print( \*FH);
    }

    # should we read the file back in here to make sure it's really OK,
    # or do we trust this code and XML::Twig?

    return 1;

}

sub xml_load_person {
    my ($twig, $mp) = @_;
    #$mp->print;
    my $personinfo_id = $mp->att('id');
    my $pid = '';
    if ($personinfo_id && $personinfo_id =~ m#uk.org.publicwhip/person/(\d+)$#) {
        $pid = $1;
        if ($pid == $personid) {
        $passer->{'person_in_file'} = 1;
            if ($mp->att('mp_website') eq $passer->{'person_db_vals'}->{'mp_website'}) {
                print "XML and DB already match, no update needed \n" if $debug;
                return 1;
            }
            unless ($passer->{'person_db_vals'}->{'mp_website'}) {
                # deleting record
                $mp->delete;
            }
            my $updated = $mp->set_att( mp_website => $passer->{'person_db_vals'}->{'mp_website'});
            if ($mp->att('mp_website') eq $passer->{'person_db_vals'}->{'mp_website'}) {
                $passer->{'file_updated'} = $pwmembers . "websites.xml";
                print "MP's URL updated \n" if $debug;
            }
        }
    }
    #$twig->purge();
    return 1;
}

sub db_load_person {
    my $person_db_vals = {};
    $passer->{'person_db_vals'} = {};
    my $get_person_sql = qq[SELECT member.person_id, house, title, first_name, last_name, constituency, data_value AS mp_website FROM personinfo LEFT JOIN member ON member.person_id =  personinfo.person_id WHERE data_key = 'mp_website' AND member.person_id = ] . $dbh->quote($personid);
    my $sth = $dbh->prepare($get_person_sql);
	$sth->execute();
		while (my $ref = $sth->fetchrow_hashref()) {
    	   foreach my $fieldname ( keys (%$ref) ) {
                $passer->{'person_db_vals'}->{$fieldname} = $ref->{$fieldname};
    	   }
		}
    if (!$passer->{'person_db_vals'}->{'person_id'}) {return 0;}
    return 1;
}

$dbh->disconnect();

redpajama_set_name: RedPajamaGithub


text:
import json
from drone.utils.json_schema_validator import json_validate

def get_config(config, config_schema):

    try:
        with open(config, 'r') as f:
            config_text = f.read()
    except IOError:
        config_text = '{}'

    config_object = json.loads(config_text)
    json_validate(config_object, config_schema)
    return config_object


text:
class BookShelf < ActiveRecord::Base
  belongs_to :book
  belongs_to :shelf
end


text:
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">

  <title>Identifier Index</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />

         Home

         Trees

         Indices

         Help

Translate Toolkit

[hide private]

[frames] | no frames]

[
 Identifiers
| To Do
]

Identifier Index

[
 A
 B
 C
 D
 E
 F
 G
 H
 I
 J
 K
 L
 M
 N
 O
 P
 Q
 R
 S
 T
 U
 V
 W
 X
 Y
 Z
 _
]

A

accelerators()

(in StandardChecker)
addline()

(in oofile)
addunit()

(in tsfile)

accesskey

(in translate.convert)
addline()

(in oounit)
addValues()

(in _NGram)

accesskeysuffixes

(in translate.storage.dtd)
addlocation()

(in TranslationUnit)
AdvSubStationAlphaFile

(in translate.storage.subtitles)

acronyms()

(in StandardChecker)
addlocation()

(in pounit)
af

(in translate.lang)

ACTIONS

(in ManPageOption)
addlocation()

(in pounit)
af

(in translate.lang.af)

add()

(in LineContainer)
addlocation()

(in htmlunit)
all_your_base

(in translate.storage.placeables)

add()

(in Selector)
addlocation()

(in icalunit)
allcomments()

(in pounit)

add_dict()

(in TMDB)
addlocation()

(in iniunit)
AltAttrPlaceable

(in translate.storage.placeables.general)

add_duplicates_option()

(in ConvertOptionParser)
addlocation()

(in phpunit)
alter_length()

(in Common)

add_duplicates_option()

(in ConvertOptionParser)
addlocation()

(in pounit)
alwayswarn

(in oofilteroptions)

add_file()

(in translate.storage.odf_io)
addlocation()

(in TikiUnit)
alwayswarn

(in oofilteroptions)

add_fuzzy_option()

(in ConvertOptionParser)
addlocation()

(in tsunit)
am

(in translate.lang)

add_fuzzy_option()

(in ConvertOptionParser)
addlocation()

(in TxtUnit)
am

(in translate.lang.am)

add_instance()

(in Typeclass)
addlocation()

(in xliffunit)
ANALYZER_DEFAULT

(in CommonDatabase)

add_list()

(in TMDB)
addlocation()

(in xliffunit)
ANALYZER_EXACT

(in CommonDatabase)

add_multifile_option()

(in ConvertOptionParser)
addlocations()

(in TranslationUnit)
ANALYZER_PARTIAL

(in CommonDatabase)

add_multifile_option()

(in ConvertOptionParser)
addnote()

(in TranslationUnit)
ANALYZER_TOKENIZE

(in CommonDatabase)

add_prefix()

(in translate.tools.podebug)
addnote()

(in pounit)
And

(in translate.misc.typecheck)

add_spreadsheet_escapes()

(in csvunit)
addnote()

(in pounit)
Any

(in translate.misc.typecheck)

add_store()

(in TMServer)
addnote()

(in phpunit)
apply_to_strings()

(in StringElem)

add_store()

(in TMDB)
addnote()

(in PoXliffUnit)
apply_to_translatables()

(in podebug)

add_to_dict()

(in translate.storage.poparser)
addnote()

(in propunit)
apply_translations()

(in translate.storage.xml_extract.generate)

add_unit()

(in TMServer)
addnote()

(in pounit)
applytokenizer()

(in SimpleParser)

add_unit()

(in TMDB)
addnote()

(in QphUnit)
applytokenizers()

(in SimpleParser)

add_unit_to_index()

(in TranslationStore)
addnote()

(in rcunit)
applytranslation()

(in translate.convert.po2dtd)

addalttrans()

(in xliffunit)
addnote()

(in tmxunit)
applytranslation()

(in reoo)

addalttrans()

(in xliffunit)
addnote()

(in tsunit)
applytranslation()

(in reoo)

addcatcher()

(in ZipFileCatcher)
addnote()

(in xliffunit)
ar

(in translate.lang)

adderror()

(in TranslationUnit)
addphrases()

(in TerminologyExtractor)
ar

(in translate.lang.ar)

adderror()

(in pounit)
addplural()

(in PoXliffFile)
ArchiveConvertOptionParser

(in translate.convert.convert)

adderror()

(in pounit)
addsourceunit()

(in TranslationStore)
armenianpunc

(in hy)

adderror()

(in tmxunit)
addsourceunit()

(in LISAfile)
articlere

(in translate.lang.af)

adderror()

(in xliffunit)
addsourceunit()

(in LISAfile)
as_string_for_db()

(in Record)

adderror()

(in xliffunit)
addsourceunit()

(in xlifffile)
as_unicode()

(in translate.storage.placeables.lisa)

addheader()

(in LISAfile)
addsourceunit()

(in xlifffile)
author_re

(in translate.storage.poheader)

addheader()

(in LISAfile)
addText()

(in _NGram)
autocorrect

(in oofilteroptions)

addheader()

(in tbxfile)
addtranslation()

(in tmxfile)
autocorrect

(in oofilteroptions)

addheader()

(in tmxfile)
addtranslation()

(in QtTsParser)
autocorrect

(in translate.filters)

addheader()

(in xlifffile)
addunit()

(in TranslationStore)
autoencode

(in translate.misc)

addheader()

(in xlifffile)
addunit()

(in pofile)
autoencode

(in translate.misc.autoencode)

addheaderunit()

(in PoXliffFile)
addunit()

(in LISAfile)
available

(in translate.filters.spelling)

addhtmlblock()

(in htmlfile)
addunit()

(in LISAfile)

         Home

         Trees

         Indices

         Help

Translate Toolkit

    Generated by Epydoc 3.0.1 on Wed Mar  3 16:35:51 2010

      http://epydoc.sourceforge.net


text:
<!--
  Copyright (C) FuseSource, Inc.
  http://fusesource.com

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

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

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

    <reference id="zooKeeper" interface="org.fusesource.fabric.zookeeper.ZkClientFacade" availability="optional"/>

    <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" availability="optional"/>

    <bean id="fabricService" class="org.fusesource.fabric.service.FabricServiceImpl">
        <property name="zooKeeper" ref="zooKeeper"/>
        <property name="configurationAdmin" ref="configurationAdmin"/>
    </bean>

    <reference-list interface="org.fusesource.fabric.api.ContainerProvider" availability="optional">
        <reference-listener ref="fabricService" bind-method="registerProvider" unbind-method="unregisterProvider"/>
    </reference-list>

    <service ref="fabricService" auto-export="interfaces" />

    <bean id="zooKeeperClusterService" class="org.fusesource.fabric.internal.ZooKeeperClusterServiceImpl" init-method="init">
        <property name="bundleContext" ref="blueprintBundleContext"/>
        <property name="zooKeeper" ref="zooKeeper"/>
        <property name="configurationAdmin" ref="configurationAdmin"/>
    </bean>

    <service ref="zooKeeperClusterService" auto-export="interfaces" />

</blueprint>


text:
import java.awt.Graphics;
import javax.swing.JApplet;

/* <applet code="ChessDrawing.class" width="140" height="150"></applet> */
public class ChessDrawing extends JApplet {
	public static final byte COLUMNS = 16;
	public static final byte ROWS = 8;
	public static final char ON_BLACK_CHAR = '*';

	@Override
	public void paint(Graphics g) {
		for(byte row = 0; row < ROWS; ++row)
			for(byte column = 0; column < COLUMNS; ++column)
				if((row + column) % 2 == 0)
					g.drawString(
						ON_BLACK_CHAR + "",
						25 + (column * g.getFontMetrics().charWidth(ON_BLACK_CHAR)),
						25 + (row * g.getFontMetrics().getHeight())
					);
	}
}


text:
import React from "react";
import { Dialog } from "@blueprintjs/core";
import { connect } from "react-redux";
import { lifecycle, compose } from "recompose";
import { camelCase } from "lodash";
import { nanoid } from "nanoid";
import ResizableDraggableDialog from "../../ResizableDraggableDialog";

/**
 * usage:
 * in container:
 * compose(
 *   withDialog({ title: "Select Aliquot(s) From", other bp dialog props here  })
 * )
 *
 *
 * in react component
 * import MyDialogEnhancedComponent from "./MyDialogEnhancedComponent"
 *
 * render() {
 *  return <div>
 *    <MyDialogEnhancedComponent
 *      dialogProps={} //bp dialog overrides can go here
 *      target={<button>Open Dialog</button> } //target can also be passed as a child component
 *      myRandomProp={'yuppp'} //pass any other props like normal to the component
 *
 *    />
 *  </div>
 * }
 */

//  or programatically:
// const ProgramaticDialog = withDialog({
//   dialogName: "programaticDialog", //giving it a unique dialogName means you can
//   title: "Programatic Dialog Demo"
// })(DialogInner);
//
// add the no target dialog somewhere on the page
// <ProgramaticDialog></ProgramaticDialog> //this just renders without any target
//
// somewhere else on the page:
// <Button>Click To Open Dialog</Button>

export default function withDialog(topLevelDialogProps) {
  function dialogHoc(WrappedComponent) {
    return class DialogWrapper extends React.Component {
      componentWillUnmount() {
        const { dispatch, dialogName, uniqueName } = this.props;
        if (dialogName) {
          dispatch({
            type: "TG_UNREGISTER_MODAL",
            name: dialogName,
            uniqueName
          });
        }
      }
      render() {
        const {
          target,
          noTarget,
          isDialogOpen,
          showModal,
          dialogName,
          onClickRename,
          hideModal,
          fetchPolicy = "network-only",
          children,
          onCloseHook,
          dialogProps,
          title,
          isDraggable,
          alreadyRendering,
          ...rest
        } = this.props;
        const extraDialogProps = {
          ...topLevelDialogProps,
          ...dialogProps
        };
        const _onCloseHook = onCloseHook || extraDialogProps.onCloseHook;
        const { noButtonClickPropagate } = {
          ...this.props,
          ...extraDialogProps
        };
        const isOpen = isDialogOpen || extraDialogProps.isOpen;
        const targetEl = target || children;
        // if (!targetEl && !dialogName)
        //   throw new Error(
        //     "withDialog error: Please provide a target or child element to the withDialog() enhanced component. If you really don't want a target, please pass a 'noTarget=true' prop"
        //   );
        const DialogToUse =
          isDraggable || extraDialogProps.isDraggable
            ? ResizableDraggableDialog
            : Dialog;
        return (
          <React.Fragment>
            {isOpen && (
              <DialogToUse
                onClose={function() {
                  hideModal();
                  _onCloseHook && _onCloseHook();
                }}
                className={dialogName || camelCase()}
                title={title}
                isOpen={isOpen}
                canEscapeKeyClose={false}
                canOutsideClickClose={false}
                {...extraDialogProps}
              >
                <WrappedComponent
                  {...{
                    ...rest,
                    fetchPolicy,
                    ssr: false,
                    hideModal
                  }}
                />
              </DialogToUse>
            )}
            {targetEl &&
              React.cloneElement(targetEl, {
                [onClickRename || "onClick"]: e => {
                  showModal();
                  if (noButtonClickPropagate) {
                    e.preventDefault();
                    e.stopPropagation();
                  }
                }
              })}
          </React.Fragment>
        );
      }
    };
  }

  return compose(
    connect(({ tg_modalState }) => {
      return { ...topLevelDialogProps, tg_modalState };
    }),
    lifecycle({
      componentWillMount: function() {
        const { dispatch, dialogName } = this.props;
        const uniqueName = nanoid();
        const nameToUse = dialogName || uniqueName;
        this.setState({
          nameToUse,
          uniqueName
        });
        if (dialogName) {
          dispatch({
            type: "TG_REGISTER_MODAL",
            name: dialogName,
            uniqueName
          });
        }
      }
    }),
    connect(
      function({ tg_modalState }, { nameToUse, uniqueName }) {
        const dialogState = tg_modalState[nameToUse] || {};
        const { open, __registeredAs, ...rest } = dialogState;
        const newProps = {
          ...rest,
          isDialogOpen:
            open &&
            (__registeredAs
              ? Object.keys(__registeredAs)[
                  Object.keys(__registeredAs).length - 1
                ] === uniqueName
              : true)
        };
        return newProps;
      },
      function(dispatch, { nameToUse, hideModal, showModal }) {
        return {
          showModal:
            showModal ||
            function() {
              dispatch({
                type: "TG_SHOW_MODAL",
                name: nameToUse
              });
            },
          hideModal:
            hideModal ||
            function() {
              dispatch({
                type: "TG_HIDE_MODAL",
                name: nameToUse
              });
            }
        };
      }
    ),
    dialogHoc
  );
}


text:
<!---
# 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.
-->
# Apache Hadoop Changelog

## Release 1.0.2 - 2012-04-03

### NEW FEATURES:

| JIRA | Summary | Priority | Component | Reporter | Contributor |
|:---- |:---- | :--- |:---- |:---- |:---- |
| [HADOOP-7206](https://issues.apache.org/jira/browse/HADOOP-7206) | Integrate Snappy compression |  Major | . | Eli Collins | Alejandro Abdelnur |

### IMPROVEMENTS:

| JIRA | Summary | Priority | Component | Reporter | Contributor |
|:---- |:---- | :--- |:---- |:---- |:---- |
| [HADOOP-1722](https://issues.apache.org/jira/browse/HADOOP-1722) | Make streaming to handle non-utf8 byte array |  Major | . | Runping Qi | Klaas Bosteels |
| [HADOOP-5450](https://issues.apache.org/jira/browse/HADOOP-5450) | Add support for application-specific typecodes to typed bytes |  Blocker | . | Klaas Bosteels | Klaas Bosteels |
| [HDFS-2701](https://issues.apache.org/jira/browse/HDFS-2701) | Cleanup FS\* processIOError methods |  Major | namenode | Eli Collins | Eli Collins |
| [HDFS-3075](https://issues.apache.org/jira/browse/HDFS-3075) | Backport HADOOP-4885 to branch-1 |  Major | namenode | Brandon Li | Brandon Li |
| [HADOOP-8090](https://issues.apache.org/jira/browse/HADOOP-8090) | rename hadoop 64 bit rpm/deb package name |  Major | . | Giridharan Kesavan | Giridharan Kesavan |

### BUG FIXES:

| JIRA | Summary | Priority | Component | Reporter | Contributor |
|:---- |:---- | :--- |:---- |:---- |:---- |
| [MAPREDUCE-764](https://issues.apache.org/jira/browse/MAPREDUCE-764) | TypedBytesInput's readRaw() does not preserve custom type codes |  Blocker | contrib/streaming | Klaas Bosteels | Klaas Bosteels |
| [HDFS-2703](https://issues.apache.org/jira/browse/HDFS-2703) | removedStorageDirs is not updated everywhere we remove a storage dir |  Major | namenode | Eli Collins | Eli Collins |
| [HDFS-2702](https://issues.apache.org/jira/browse/HDFS-2702) | A single failed name dir can cause the NN to exit |  Critical | namenode | Eli Collins | Eli Collins |
| [MAPREDUCE-3824](https://issues.apache.org/jira/browse/MAPREDUCE-3824) | Distributed caches are not removed properly |  Critical | distributed-cache | Allen Wittenauer | Thomas Graves |
| [HADOOP-8050](https://issues.apache.org/jira/browse/HADOOP-8050) | Deadlock in metrics |  Major | metrics | Kihwal Lee | Kihwal Lee |
| [MAPREDUCE-3583](https://issues.apache.org/jira/browse/MAPREDUCE-3583) | ProcfsBasedProcessTree#constructProcessInfo() may throw NumberFormatException |  Critical | . | Ted Yu | Ted Yu |
| [HDFS-3006](https://issues.apache.org/jira/browse/HDFS-3006) | Webhdfs "SETOWNER" call returns incorrect content-type |  Major | webhdfs | bc Wong | Tsz Wo Nicholas Sze |
| [HDFS-3101](https://issues.apache.org/jira/browse/HDFS-3101) | cannot read empty file using webhdfs |  Major | webhdfs | Zhanwei Wang | Tsz Wo Nicholas Sze |
| [MAPREDUCE-3851](https://issues.apache.org/jira/browse/MAPREDUCE-3851) | Allow more aggressive action on detection of the jetty issue |  Major | tasktracker | Kihwal Lee | Thomas Graves |
| [HADOOP-8132](https://issues.apache.org/jira/browse/HADOOP-8132) | 64bit secure datanodes do not start as the jsvc path is wrong |  Major | . | Arpit Gupta | Arpit Gupta |
| [HADOOP-8201](https://issues.apache.org/jira/browse/HADOOP-8201) | create the configure script for native compilation as part of the build |  Blocker | build | Giridharan Kesavan | Giridharan Kesavan |


text:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="latest_ob.xsl" type="text/xsl"?>
<current_observation version="1.0"
	 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:noNamespaceSchemaLocation="http://www.weather.gov/view/current_observation.xsd">
	<credit>NOAA's National Weather Service</credit>
	<credit_URL>http://weather.gov/</credit_URL>
	<image>
		<url>http://weather.gov/images/xml_logo.gif</url>
		<title>NOAA's National Weather Service</title>
		<link>http://weather.gov</link>
	</image>
	<suggested_pickup>15 minutes after the hour</suggested_pickup>
	<suggested_pickup_period>60</suggested_pickup_period>
	<location>Unknown Station</location>
	<station_id>46205</station_id>
	<observation_time>Last Updated on Jan 4 2016, 10:00 pm AST</observation_time>
        <observation_time_rfc822>Mon, 04 Jan 2016 22:00:00 -0400</observation_time_rfc822>
	<temperature_string>43.0 F (6.1 C)</temperature_string>
	<temp_f>43.0</temp_f>
	<temp_c>6.1</temp_c>
	<water_temp_f>48.0</water_temp_f>
	<water_temp_c>8.9</water_temp_c>
	<wind_string>Southeast at 9.0 MPH (7.78 KT)</wind_string>
	<wind_dir>Southeast</wind_dir>
	<wind_degrees>120</wind_degrees>
	<wind_mph>9.0</wind_mph>
	<wind_gust_mph>0.0</wind_gust_mph>
	<wind_kt>7.78</wind_kt>
	<pressure_string>1006.4 mb</pressure_string>
	<pressure_mb>1006.4</pressure_mb>
	<pressure_tendency_mb>-0.5</pressure_tendency_mb>
	<windchill_string>38 F (3 C)</windchill_string>
      	<windchill_f>38</windchill_f>
      	<windchill_c>3</windchill_c>
	<wave_height_m>3.1</wave_height_m>
	<wave_height_ft>10.17</wave_height_ft>
	<dominant_period_sec>20</dominant_period_sec>
	<mean_wave_dir>West</mean_wave_dir>
	<mean_wave_degrees></mean_wave_degrees>
	<disclaimer_url>http://weather.gov/disclaimer.html</disclaimer_url>
	<copyright_url>http://weather.gov/disclaimer.html</copyright_url>
	<privacy_policy_url>http://weather.gov/notice.html</privacy_policy_url>
</current_observation>


text:
package com.esri.samples.buffer;

import java.util.Arrays;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Spinner;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.geometry.GeodeticCurveType;
import com.esri.arcgisruntime.geometry.GeometryEngine;
import com.esri.arcgisruntime.geometry.LinearUnit;
import com.esri.arcgisruntime.geometry.LinearUnitId;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.Polygon;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;

public class BufferSample extends Application {

  private MapView mapView;

  @Override
  public void start(Stage stage) {

    try {
      // create stack pane and application scene
      StackPane stackPane = new StackPane();
      Scene scene = new Scene(stackPane);

      // set title, size, and add scene to stage
      stage.setTitle("Buffer Sample");
      stage.setWidth(800);
      stage.setHeight(700);
      stage.setScene(scene);
      stage.show();

      // authentication with an API key or named user is required to access basemaps and other location services
      String yourAPIKey = System.getProperty("apiKey");
      ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);

      // create a map with the topographic basemap style
      ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);

      // create a map view and set the map to it
      mapView = new MapView();
      mapView.setMap(map);

      // create a graphics overlay to contain the buffered geometry graphics
      GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
      mapView.getGraphicsOverlays().add(graphicsOverlay);

      // create a spinner to set the buffer size (in miles)
      Spinner<Integer> bufferSpinner = new Spinner<>(500, 2000, 1000);
      bufferSpinner.setEditable(true);

      // set up units to convert from miles to meters
      final LinearUnit miles = new LinearUnit(LinearUnitId.MILES);
      final LinearUnit meters = new LinearUnit(LinearUnitId.METERS);

      // create a white cross marker symbol to show where the user clicked
      final SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CROSS, 0xFFFFFFFF, 14);

      // create a semi-transparent purple fill symbol for the geodesic buffers
      final SimpleFillSymbol geodesicFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x88FF00FF, null);

      // create a semi-transparent green fill symbol for the planar buffers
      final SimpleFillSymbol planarFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x8800FF00, null);

      // create buffers around the clicked location
      mapView.setOnMouseClicked(e -> {
        if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
          Point2D point2D = new Point2D(e.getX(), e.getY());
          // buffer around the clicked point
          Point point = mapView.screenToLocation(point2D);
          Polygon geodesicBufferGeometry = GeometryEngine.bufferGeodetic(point, miles.convertTo(meters, bufferSpinner.getValue()), meters, Double.NaN, GeodeticCurveType.GEODESIC);
          Polygon planarBufferGeometry = GeometryEngine.buffer(point, miles.convertTo(meters, bufferSpinner.getValue()));
          // show the buffered regions
          Graphic geodesicBufferGraphic = new Graphic(geodesicBufferGeometry, geodesicFillSymbol);
          Graphic planarBufferGraphic = new Graphic(planarBufferGeometry, planarFillSymbol);
          graphicsOverlay.getGraphics().addAll(Arrays.asList(geodesicBufferGraphic, planarBufferGraphic));
          // show a white marker where clicked
          Graphic markerGraphic = new Graphic(point, markerSymbol);
          graphicsOverlay.getGraphics().add(markerGraphic);
          // set the z index of each graphic so they display in the correct order
          geodesicBufferGraphic.setZIndex(0);
          planarBufferGraphic.setZIndex(1);
          markerGraphic.setZIndex(2);
        }
      });

      // create a button to clear graphics
      Button clearButton = new Button("Clear");
      // clear the graphics overlay when the clear button is clicked
      clearButton.setOnMouseClicked(event -> graphicsOverlay.getGraphics().clear());

      // create a vbox that contains the spinner and clear button
      VBox controlsVBox = new VBox(6);
      controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
        Insets.EMPTY)));
      controlsVBox.setPadding(new Insets(10.0));
      controlsVBox.setMaxSize(100, 75);
      controlsVBox.getChildren().addAll(bufferSpinner, clearButton);
      // add the map view and vbox to the stack pane
      stackPane.getChildren().addAll(mapView, controlsVBox);
      StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);
      StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));
    } catch (Exception e) {
      // on any error, display the stack trace.
      e.printStackTrace();
    }
  }

  /**
   * Stops and releases all resources used in application.
   */
  @Override
  public void stop() {

    if (mapView != null) {
      mapView.dispose();
    }
  }

  /**
   * Opens and runs application.
   *
   * @param args arguments passed to this application
   */
  public static void main(String[] args) {

    Application.launch(args);
  }

}


text:
# A tool to generate `compile_commands.json`

[`compile_commands.json`](http://clang.llvm.org/docs/JSONCompilationDatabase.html)
is a file used by [Clang](http://clang.llvm.org/) tools such as
[ClangCheck](http://clang.llvm.org/docs/ClangCheck.html),
[atom-clang-linter](https://atom.io/packages/linter-clang).
It is a database descriing the options passed to compile each file in a project.
This file can be generated by recent version of [cmake](http://www.cmake.org/)
with `CMAKE_EXPORT_COMPILE_COMMANDS` or [bear](https://github.com/rizsotto/Bear).

However, sometimes you want another solution. For example, cmake does not
generate any entry for .h files. It might be useful to have entries for the
header files as well.

## gen_compile_commands

This tool generate the JSON file from a simpler YAML supporting globbing file:

~~~
---
- pattern:
  - "**/*.{h,hpp}"
  - "**/*.cpp"
  command: clang++ -x c++ -std=c++11 -c
- pattern: "**/*.c"
  command: clang -std=gnu11 -c
---
~~~

Usage:

~~~
gen_compile_commands compile_commands.yaml > compile_commands.json
~~~

This will generate a file looking like this:

~~~
[
  {
    "file": "src/foo.h",
    "command": "clang++ -x c++ -std=c++11 -c src/foo.h"
  },
  {
    "file": "src/foo.cpp",
    "command": "clang++ -x c++ -std=c++11 -c src/foo.cpp"
  },
  {
    "file": "src/foo.c",
    "command": "clang -std=gnu+11 -c src/foo.c"
  }
]
~~~

## TODO list

* variable definition and variable expansion (will change the YAML format)


text:
description("Tests that navigator.webkitGetUserMedia is present.");

function hasGetUserMediaProperty()
{
    for (var property in navigator) {
        if (property == "webkitGetUserMedia")
            return true;
    }
    return false;
}

shouldBeTrue("typeof navigator.webkitGetUserMedia == 'function'");
shouldBeTrue("hasGetUserMediaProperty()");
shouldBeTrue("'webkitGetUserMedia' in navigator");
shouldBeFalse("navigator.hasOwnProperty('webkitGetUserMedia')");

window.jsTestIsAsync = false;


text:
package com.efrei.gopizza;

import com.example.gopizza.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

public class Info extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		// Enlever la title bar de l'application
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.onCreate(savedInstanceState);

		setContentView(R.layout.info_fullscreen);

	}

	@Override
	public void onBackPressed() {

		startActivity(new Intent(Info.this, Mainmenu.class));
		finish();

	}

}


text:
![](http://s28.postimg.org/p5d2dlrp7/newsfeeds.gif)

Run:

    bower install
    npm install
    grunt serve


text:
package zipkin2.elasticsearch.integration;

import com.google.common.io.Closer;
import java.io.IOException;
import java.util.Arrays;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.junit.AssumptionViolatedException;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.HttpWaitStrategy;
import zipkin2.CheckResult;
import zipkin2.elasticsearch.ElasticsearchStorage;

public class ElasticsearchStorageRule extends ExternalResource {
  static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchStorageRule.class);
  static final int ELASTICSEARCH_PORT = 9200;
  final String image;
  final String index;
  GenericContainer container;
  Closer closer = Closer.create();

  public ElasticsearchStorageRule(String image, String index) {
    this.image = image;
    this.index = index;
  }

  @Override
  protected void before() throws Throwable {
    try {
      LOGGER.info("Starting docker image " + image);
      container = new GenericContainer(image)
        .withExposedPorts(ELASTICSEARCH_PORT)
        .waitingFor(new HttpWaitStrategy().forPath("/"));
      container.start();
      if (Boolean.valueOf(System.getenv("ES_DEBUG"))) {
        container.followOutput(new Slf4jLogConsumer(LoggerFactory.getLogger(image)));
      }
      System.out.println("Starting docker image " + image);
    } catch (RuntimeException e) {
      LOGGER.warn("Couldn't start docker image " + image + ": " + e.getMessage(), e);
    }

    try {
      tryToInitializeSession();
    } catch (RuntimeException | Error e) {
      if (container == null) throw e;
      LOGGER.warn("Couldn't connect to docker image " + image + ": " + e.getMessage(), e);
      container.stop();
      container = null; // try with local connection instead
      tryToInitializeSession();
    }
  }

  void tryToInitializeSession() throws IOException {
    ElasticsearchStorage result = computeStorageBuilder().build();
    CheckResult check = result.check();
    if (!check.ok()) {
      throw new AssumptionViolatedException(check.error().getMessage(), check.error());
    }
  }

  public ElasticsearchStorage.Builder computeStorageBuilder() {
    OkHttpClient ok = Boolean.valueOf(System.getenv("ES_DEBUG"))
      ? new OkHttpClient.Builder()
      .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
      .addNetworkInterceptor(chain -> chain.proceed( // logging interceptor doesn't gunzip
        chain.request().newBuilder().removeHeader("Accept-Encoding").build()))
      .build()
      : new OkHttpClient();
    return ElasticsearchStorage.newBuilder(ok).index(index)
      .flushOnWrites(true)
      .hosts(Arrays.asList(baseUrl()));
  }

  String baseUrl() {
    if (container != null && container.isRunning()) {
      return String.format("http://%s:%d",
        container.getContainerIpAddress(),
        container.getMappedPort(ELASTICSEARCH_PORT)
      );
    } else {
      // Use localhost if we failed to start a container (i.e. Docker is not available)
      return "http://localhost:" + ELASTICSEARCH_PORT;
    }
  }

  @Override protected void after() {
    try {
      closer.close();
    } catch (Exception | Error e) {
      LOGGER.warn("error closing session " + e.getMessage(), e);
    } finally {
      if (container != null) {
        LOGGER.info("Stopping docker image " + image);
        container.stop();
      }
    }
  }

  public static String index(TestName testName) {
    String result = testName.getMethodName().toLowerCase();
    return result.length() <= 48 ? result : result.substring(result.length() - 48);
  }
}


text:
#ifndef _PARTICLE
#define _PARTICLE

#include <FiberTrackingExports.h>
#include <vnl/vnl_vector_fixed.h>

namespace mitk
{

/**
* \brief A particle is the basic element of the Gibbs fiber tractography method.   */

class FiberTracking_EXPORT Particle
{
public:

    Particle()
    {
        label = 0;
        pID = -1;
        mID = -1;
    }

    ~Particle()
    {
    }

    vnl_vector_fixed<float, 3> pos; // particle position (world coordinates. corner based voxels. not accounted for image rotation.
    vnl_vector_fixed<float, 3> dir; // normalized direction vector

    int gridindex;          // index in the grid where it is living
    int ID;                 // particle ID
    int pID;                // successor ID
    int mID;                // predecessor ID
    unsigned char label;    // label used in the fiber building process
};

class FiberTracking_EXPORT EndPoint
{
public:
    EndPoint()
    {}

    EndPoint(Particle *p,int ep)
    {
        this->p = p;
        this->ep = ep;
    }
    Particle *p;
    int ep;

    inline bool operator==(EndPoint P)
    {
        return (P.p == p) && (P.ep == ep);
    }
};

}

#endif


text:
package com.jike.counttime;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {
    private EditText inputtext ;
    private Button gettime;
    private TextView time;
    private Button starttimer;
    private Button stoptimer;
    private int i =0;
    private Timer timer = null;
    private TimerTask task = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		inputtext = (EditText) findViewById(R.id.inputtext);
		gettime =  (Button) findViewById(R.id.gettime);
		time =  (TextView) findViewById(R.id.time);
		starttimer =  (Button) findViewById(R.id.starttimer);
		stoptimer =  (Button) findViewById(R.id.stoptimer);
		gettime.setOnClickListener(this);
		starttimer.setOnClickListener(this);
		stoptimer.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.gettime:
			time.setText(inputtext.getText().toString());
			i = Integer.parseInt((String) time.getText());
			break;
		case R.id.starttimer:
			starttimer();
			break;
		case R.id.stoptimer:
			stoptimer();
		    break;

		}
	}

	private Handler mHandler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			time.setText(msg.arg1+"");
			starttimer();
		}

	};
	private void stoptimer() {
		// TODO Auto-generated method stub
		timer.cancel();
	}

	private void starttimer() {
		// TODO Auto-generated method stub
		timer = new Timer();
		task = new TimerTask(){

			@Override
			public void run() {
				i--;
				Message message = mHandler.obtainMessage();
				message.arg1 = i;
				mHandler.sendMessage(message);
			}

		};
		timer.schedule(task, 1000);
	}

}


text:
package com.zql.android.clippings.device.view.taggroup;

import android.animation.Animator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.zql.android.clippings.device.ClippingsApplication;
import com.zql.android.clippings.R;
import com.zql.android.clippings.device.db.Label;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author qinglian.zhang, created on 2017/3/2.
 */
public class TagsGroup extends ViewGroup implements Tag.TagCallback ,SpecialTag.SpecialTagCallback{

    public static final int[] DEFAULT_TAG_COLORS = new int[]{Color.WHITE,Color.BLACK};
    public static final int[] DEFAULT_SPECAIL_TAG_COLORS = new int[]{Color.WHITE,Color.parseColor("#607D8B")};

    /**
     * 编辑模式,可添加可删除
     */
    public static final int MODE_EDIT =1;
    /**
     * 正常模式,只可点击
     */
    public static final int MODE_NORMAL =2;

    /**
     * 从TagsGroup移除,并从数据库移除
     */
    public static final int TAG_CHANGE_REMOVE = 1;
    /**
     * 添加进TagsGroup,并添加进数据库
     */
    public static final int TAG_CHANGE_ADD = 2;
    /**
     * 在TagsGroup上显示,无需添加数据库,该数据应该是从数据库中取出
     */
    public static final int TAG_CHAGE_SHOW = 3;

    private int mChildMargin = 0;

    private int mChildHeight = 0;

    private List<List<Tag>> mChilds = new ArrayList<>();

    private Handler mTestHandler = new Handler();

    private SpecialTag mSpecialTag;

    private Set<String> mTagSet = new HashSet<>();

    private TagsGroupCallback mCallback;

    private int mMode = MODE_NORMAL;
    public interface TagsGroupCallback{
        /**
         *
         * @param tagText
         * @param status
         */
        void onTagChanged(String tagText,int status);

        /**
         *
         * @param index
         * @param label
         */
        void onTagClick(int index,String label);
    }
    public TagsGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        initDefault(attrs);
    }

    public TagsGroup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initDefault(attrs);
    }

    private void initDefault( AttributeSet attrs){
        if(attrs != null){
            TypedArray typedArray = getContext().obtainStyledAttributes(attrs,new int[]{R.attr.tag_mode});
            int mode = typedArray.getInt(0,-1);
            if(mode == MODE_EDIT){
                mMode = MODE_EDIT;
            }else {
                mMode = MODE_NORMAL;
            }
            typedArray.recycle();
        }
        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                mTestHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if(mMode == MODE_EDIT){
                            addSpecalTag(new SpecialTag(getContext(),getResources().getString(R.string.add_label)));
                        }
                    }
                });
                getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    }

    /**
     * add a tag
     * @param tag {@link Tag}
     */
    public void addTag(Tag tag){
        if(mTagSet.contains(tag.getTagText())){
            Toast.makeText(ClippingsApplication.own(),getResources().getString(R.string.label_already_exist),Toast.LENGTH_SHORT).show();
        }else {
            addTagText(tag.getTagText(),TAG_CHANGE_ADD);
            addView(tag);
        }
    }

    public void showLables(List<Label> labels){
        if(labels != null){
            if(mMode == MODE_NORMAL){
                mTagSet.clear();
                removeAllViews();
            }
            for(int i = 0;i<labels.size();i++){
                Label label = labels.get(i);
                if(mTagSet.contains(label.label)) continue;
                addTagText(label.label,TAG_CHAGE_SHOW);
                Tag tag = new Tag(getContext(),label.label);
                tag.setTag(label.id);
                addView(tag);
            }
        }
    }
    public void addSpecalTag(SpecialTag tag){
        addView(tag,0);
    }
    public void addCallback(TagsGroupCallback callback){
        mCallback = callback;
    }
    private void addTagText(String text,int status){
        mTagSet.add(text);
        if(mCallback != null){
            mCallback.onTagChanged(text,status);
        }
    }

    private void removeTagText(String text,int status){
        mTagSet.remove(text);
        if(mCallback != null){
            mCallback.onTagChanged(text,status);
        }
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        mChilds.clear();
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);

        int childrenCount = getChildCount();

        int childMeasureSpecWidth = MeasureSpec.makeMeasureSpec(width - getPaddingLeft() - getPaddingRight(),MeasureSpec.UNSPECIFIED);
        int childMeasureSpecHeigth = MeasureSpec.makeMeasureSpec(height - getPaddingBottom() - getPaddingTop(),MeasureSpec.UNSPECIFIED);

        if(getChildCount() > 0){
            Tag tag = (Tag) getChildAt(0);
            tag.measure(childMeasureSpecWidth,childMeasureSpecHeigth);
            mChildMargin = tag.getMeasuredHeight()/10;
            mChildHeight = tag.getMeasuredHeight();
        }

        for(int i = 0;i<childrenCount;i++){
            if(i>0){
                Tag tag = (Tag) getChildAt(i);
                tag.setIndex(i);
                tag.setCallback(this);
                tag.measure(childMeasureSpecWidth,childMeasureSpecHeigth);
                putChildren(tag,width - getPaddingRight() - getPaddingLeft());
            }else {
                if(getChildAt(i) instanceof SpecialTag){
                    SpecialTag tag = (SpecialTag) getChildAt(i);
                    tag.setIndex(i);
                    tag.setSpecialCallback(this);
                    tag.measure(childMeasureSpecWidth,childMeasureSpecHeigth);
                    putChildren(tag,width - getPaddingRight() - getPaddingLeft());
                }else {
                    Tag tag = (Tag) getChildAt(i);
                    tag.setIndex(i);
                    tag.setCallback(this);
                    tag.measure(childMeasureSpecWidth,childMeasureSpecHeigth);
                    putChildren(tag,width - getPaddingRight() - getPaddingLeft());
                }
            }
        }

        setMeasuredDimension(width,(mChildHeight + mChildMargin*2) * mChilds.size()+ getPaddingBottom() + getPaddingTop());
    }

    /**
     * 在measure阶段将子view放进一个二维列表,然后再layout阶段取出并确定其位置
     * @param tag
     * @param width
     */
    private void putChildren(Tag tag,int width){
        List<Tag> tags;
        if(mChilds.size() == 0){
            tags = new ArrayList<>();
            mChilds.add(tags);
        }else {
            tags = mChilds.get(mChilds.size()-1);
        }

        if(!checkWidth(tags,tag,width)){
            tags = new ArrayList<>();
            mChilds.add(tags);
        }
        tags.add(tag);

    }

    private boolean checkWidth(List<Tag> tags,Tag tag,int width){
        int ruler = 0;
        for(Tag t : tags){
            ruler += (t.getMeasuredWidth() + mChildMargin*2);
        }
        return ruler + (tag.getMeasuredWidth() + mChildMargin * 2) <= width;
    }
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        for(int i = 0;i<mChilds.size();i++){
            List<Tag> tags = mChilds.get(i);
            int turlyPadding = getChildTurlyPadding(getChildsRowWidth(tags));
            int widthRuler = turlyPadding;
            for(int j = 0;j<tags.size();j++){
                Tag tag = tags.get(j);
                int left = widthRuler + mChildMargin;
                int top = getPaddingTop() + i*(tag.getMeasuredHeight() + mChildMargin*2) + mChildMargin;
                int right = left + tag.getMeasuredWidth();
                int bottom = top + tag.getMeasuredHeight();
                tag.layout(left,top,right,bottom);
                widthRuler = right + mChildMargin;
            }
        }
    }

    private int getChildsRowWidth(List<Tag> tags){
        int w = 0;
        for(int i = 0;i<tags.size();i++) w += (tags.get(i).getMeasuredWidth() + mChildMargin*2);
        return w;
    }

    private int getChildTurlyPadding(int width){
        return (getMeasuredWidth() - width)/2;
    }

    @Override
    public void onTagClick(int index, int status,String label) {
        if(mMode == MODE_EDIT){
            if(status == Tag.STATUS_EDIT){
                performExitAnimation((Tag) getChildAt(index));
            }
        }else {
            if(status == Tag.STATUS_NORMAL){
                if(mCallback != null){
                    mCallback.onTagClick(index,label);
                }
            }
        }
    }

    @Override
    public void onTagLongClick(int index, int status) {
        if(mMode == MODE_EDIT){
            if(status == Tag.STATUS_NORMAL){
                changeTagsStatus(Tag.STATUS_EDIT);
            }else {
                changeTagsStatus(Tag.STATUS_NORMAL);
            }
        }else {

        }
    }

    private void changeTagsStatus(int status){
        for(int i = 0;i<getChildCount();i++){
            View view = getChildAt(i);
            if(view instanceof Tag){
                Tag tag = (Tag) getChildAt(i);
                tag.changeStatus(status);
            }
        }
    }
    private void performExitAnimation(final Tag tag){
        tag.setClickable(false);
        tag.animate().alpha(0).setDuration(800).scaleX(0).scaleY(0).setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                removeView(tag);
                removeTagText(tag.getTagText(),TAG_CHANGE_REMOVE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        }).withLayer().start();
    }

    @Override
    public void onSpecialTagClick(int status) {
        if(status == Tag.STATUS_EDIT){
            changeTagsStatus(Tag.STATUS_NORMAL);
        }else {
            final EditText editText = new EditText(ClippingsApplication.own());
            editText.setSingleLine();
            editText.setGravity(Gravity.CENTER);
            editText.setTextColor(getResources().getColor(R.color.colorPrimary));
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setMessage(R.string.add_label)
                   .setView(editText).setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String tag = editText.getText().toString();
                    if(tag == null || tag.trim().length() == 0){
                        //do nothing
                    }else {
                        addTag(new Tag(getContext(),tag));
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
                    .setCancelable(false)
                    .show();
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    showKeyboard(editText);
                }
            },200);
        }
    }

    private void showKeyboard(EditText editText){
        if(editText!=null){
            editText.setFocusable(true);
            editText.setFocusableInTouchMode(true);
            editText.requestFocus();
            InputMethodManager inputManager = (InputMethodManager) editText
                    .getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(editText, 0);
        }
    }
}


text:
set -e
echo "${OS_DISTRO}: Setting environment Vars For Keystone"
################################################################################
. /etc/os-container.env
. /opt/harbor/service-hosts.sh
. /opt/harbor/harbor-common.sh
. /opt/harbor/mistral/vars.sh

################################################################################
check_required_vars OS_DOMAIN \
                    AUTH_MISTRAL_KEYSTONE_REGION \
                    AUTH_MISTRAL_KEYSTONE_DOMAIN \
                    AUTH_MISTRAL_KEYSTONE_PROJECT_DOMAIN \
                    AUTH_MISTRAL_KEYSTONE_PROJECT \
                    AUTH_MISTRAL_KEYSTONE_USER \
                    AUTH_MISTRAL_KEYSTONE_PASSWORD

################################################################################
unset OS_AUTH_URL
unset OS_REGION_NAME
unset OS_CACERT
unset OS_IDENTITY_API_VERSION
unset OS_PROJECT_NAME
unset OS_PROJECT_DOMAIN_NAME
unset OS_DOMAIN_NAME
unset OS_PASSWORD
unset OS_USERNAME
unset OS_USER_DOMAIN_NAME

################################################################################
export OS_AUTH_URL="https://${KEYSTONE_API_SERVICE_HOST_SVC}:5000/v3"
export OS_REGION_NAME="${AUTH_MISTRAL_KEYSTONE_REGION}"
export OS_CACERT="${MISTRAL_DB_CA}"
export OS_IDENTITY_API_VERSION="3"
export OS_PROJECT_NAME="${AUTH_MISTRAL_KEYSTONE_PROJECT}"
export OS_PROJECT_DOMAIN_NAME="${AUTH_MISTRAL_KEYSTONE_PROJECT_DOMAIN}"
export OS_DOMAIN_NAME="${AUTH_MISTRAL_KEYSTONE_DOMAIN}"
export OS_PASSWORD="${AUTH_MISTRAL_KEYSTONE_PASSWORD}"
export OS_USERNAME="${AUTH_MISTRAL_KEYSTONE_USER}"
export OS_USER_DOMAIN_NAME="${AUTH_MISTRAL_KEYSTONE_DOMAIN}"

echo "${OS_DISTRO}: testing ${OS_USERNAME}:${OS_PROJECT_NAME}@${OS_DOMAIN_NAME}"
################################################################################
openstack token issue


text:
<?php

namespace fibe\CommunityBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Discriminator;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\VirtualProperty;

use Symfony\Component\Validator\Constraints as Assert;

/**
 * This entity complete informations on a person or on an organization as well
 *
 *
 * @ORM\Table(name="additional_informations")
 * @ORM\Entity(repositoryClass="fibe\CommunityBundle\Repository\AdditionalInformationsRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorMap({
 *     "Organization"="Organization",
 *     "OrganizationVersion"="OrganizationVersion",
 *     "Person"="Person"
 * })
 * @ExclusionPolicy("all")
 */
class AdditionalInformations
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue()
     * @Expose
     */
    protected $id;

    /**
     * label
     *
     * @ORM\Column(type="string")
     * @Expose
     */
    protected $label;

    /**
     * Url of the website
     *
     * @ORM\Column(type="string", nullable=true)
     * @Expose
     */
    protected $website;

    /**
     * @TODO Enum : I18N (CodeInfo/JS/...)
     *
     * country
     * @ORM\Column(type="string", nullable=true)
     * @Expose
     */
    protected $country;

    /**
     * img
     * @ORM\Column(type="string", nullable=true,  name="img")
     * @Expose
     */
    protected $img;

    /**
     * email
     * @ORM\Column(type="string", nullable=true,  name="email")
     * @Expose
     */
    protected $email;

    /**
     * @ORM\Column(type="text", nullable=true)
     * @Expose
     */
    private $description;

    /**
     * fix an issue with jms-serializer and form validation when applied to a doctrine InheritanceType("SINGLE_TABLE")
     */
    public $dtype;

    public function __toString()
    {
        //@TODO : méthode to String fonctionnel
        return 'toString @TODO in AdditionalInformation Entity';
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getWebsite()
    {
        return $this->website;
    }

    /**
     * @param mixed $website
     */
    public function setWebsite($website)
    {
        $this->website = $website;
    }

    /**
     * @return mixed
     */
    public function getCountry()
    {
        return $this->country;
    }

    /**
     * @param mixed $country
     */
    public function setCountry($country)
    {
        $this->country = $country;
    }

    /**
     * @return mixed
     */
    public function getImg()
    {
        return $this->img;
    }

    /**
     * @param mixed $img
     */
    public function setImg($img)
    {
        $this->img = $img;
    }

    /**
     * @return mixed
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param mixed $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * @return mixed
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param mixed $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }
}


text:
@interface RecipeContent : NSObject

@property (nonatomic, assign) NSInteger photoWidth;
@property (nonatomic, assign) NSInteger photoHeight;
@property (nonatomic, strong) NSString *photoURL;
@property (nonatomic, strong) UIImage *photo;
@property (nonatomic, strong) NSString *thumbnailURL;
@property (nonatomic, strong) UIImage *thumbnail;
@property (nonatomic, strong) NSString *description;

+ (id)recipeContentFromDictionary:(NSDictionary *)dictionary;

@end


text:
package org.midao.jdbc.examples.derby;

import org.midao.jdbc.core.MjdbcFactory;
import org.midao.jdbc.core.service.QueryRunnerService;

import java.sql.Connection;
import java.sql.SQLException;

/**
 */
public class BatchExample1 {

    public static void main(String[] args) throws SQLException {
        Connection conn = DerbyParameters.createConnection();

        QueryRunnerService runner = MjdbcFactory.getQueryRunner(conn);

        try {
            runner.update("CREATE TABLE students ("
                    + "id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),"
                    + "name VARCHAR(24) NOT NULL,"
                    + "address VARCHAR(1024)," + "CONSTRAINT primary_key PRIMARY KEY (id))");

            Object[] batch1Parameters = new Object[]{"not me"};
            Object[] batch2Parameters = new Object[]{"not me either"};

            Object[][] batchParameters = new Object[][]{
                    batch1Parameters,
                    batch2Parameters
            };

            int[] rowsUpdated = runner.batch("INSERT INTO students (name) VALUES (?)", batchParameters);

            System.out.println("Queries executed: " + rowsUpdated.length);
            System.out.println("Query N1 rows updated: " + rowsUpdated[0]);
            System.out.println("Query N2 rows updated: " + rowsUpdated[1]);
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            runner.update("DROP TABLE students");
        }
    }
}


text:
import unittest
import mock
from savory_pie.resources import _ParamsImpl, EmptyParams

class EmptyParamsTestCase(unittest.TestCase):

    def test_get(self):
        params = EmptyParams()
        self.assertEqual(params.get('key', default='value'), 'value')

    def test_get_as(self):
        params = EmptyParams()
        self.assertEqual(params.get_as('key', str, default='value'), 'value')

    def test_get_list(self):
        params = EmptyParams()
        self.assertEqual(params.get_list('key'), [])

    def test_get_list_of(self):
        params = EmptyParams()
        self.assertEqual(params.get_list_of('key', str), [])

class ParamsImplTestCase(unittest.TestCase):
    def test_init(self):
        params = _ParamsImpl('some var')
        self.assertEqual(params._GET, 'some var')

    def test_keys(self):
        params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
        self.assertEqual(sorted(params.keys()), ['key1', 'key2'])

    def test_contains(self):
        params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
        self.assertTrue('key1' in params)
        self.assertFalse('key3' in params)

    def test_get_item(self):
        params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
        self.assertEqual(params['key1'], 'value1')

    def test_parameters_get(self):
        params = _ParamsImpl({'key1': 'value1'})
        self.assertEqual(params.get('key1', 'other'), 'value1')

    def test_parameters_get_default(self):
        params = _ParamsImpl({'key1': 'value1'})
        self.assertEqual(params.get('some', 'other'), 'other')

    def test_parameters_get_as(self):
        params = _ParamsImpl({'key1': 'value1'})
        self.assertEqual(params.get_as('key1', str, 'other'), 'value1')

    def test_parameters_get_as_wrong_type(self):
        params = _ParamsImpl({'key1': 1})
        self.assertEqual(params.get_as('key1', str, 'other'), '1')

    def test_parameters_get_as_default(self):
        params = _ParamsImpl({'key1': 1})
        self.assertEqual(params.get_as('key2', str, 'other'), 'other')

    def test_parameters_get_list(self):
        get = mock.Mock()
        get.getlist.return_value = ['value1']
        params = _ParamsImpl(get)
        self.assertEqual(params.get_list('key1'), ['value1'])

    def test_get_list_of(self):
        params = _ParamsImpl({'key1': [1]})
        self.assertEqual(params.get_list_of('key1', str), ['1'])

    def test_get_list_of_not_found(self):
        params = _ParamsImpl({'key1': [1]})
        self.assertEqual(params.get_list_of('key2', str), [])


text:
package ph.devcon.android.news.event;

/**
 * Created by lope on 10/29/14.
 */
public class FetchedNewsListFailedEvent {
}


text:
from unittest import TestCase

import networkx

from gtfspy.routing.connection import Connection
from gtfspy.routing.label import LabelTime
from gtfspy.routing.pseudo_connection_scan_profiler import PseudoConnectionScanProfiler

class TestPseudoPseudoConnectionScanProfiler(TestCase):
    # noinspection PyAttributeOutsideInit

    def setUp(self):
        event_list_raw_data = [
            (2, 4, 40, 50, "trip_6", 1),
            (1, 3, 32, 40, "trip_5", 1),
            (3, 4, 32, 35, "trip_4", 1),
            (2, 3, 25, 30, "trip_3", 1),
            (1, 2, 10, 20, "trip_2", 1),
            (0, 1, 0, 10, "trip_1", 1)
        ]
        self.transit_connections = list(map(lambda el: Connection(*el), event_list_raw_data))
        self.walk_network = networkx.Graph()
        self.walk_network.add_edge(1, 2, d_walk=20)
        self.walk_network.add_edge(3, 4, d_walk=15)
        self.walk_speed = 1
        self.source_stop = 1
        self.target_stop = 4
        self.transfer_margin = 0
        self.start_time = 0
        self.end_time = 50

    def test_basics(self):
        csa_profile = PseudoConnectionScanProfiler(self.transit_connections, self.target_stop,
                                                   self.start_time, self.end_time, self.transfer_margin,
                                                   self.walk_network, self.walk_speed)
        csa_profile.run()

        stop_3_labels = csa_profile.stop_profiles[3].get_final_optimal_labels()
        self.assertEqual(len(stop_3_labels), 1)
        self.assertIn(LabelTime(32, 35), stop_3_labels)

        stop_2_labels = csa_profile.stop_profiles[2].get_final_optimal_labels()
        self.assertEqual(len(stop_2_labels), 2)
        self.assertIn(LabelTime(40, 50), stop_2_labels)
        self.assertIn(LabelTime(25, 35), stop_2_labels)

        source_stop_profile = csa_profile.stop_profiles[self.source_stop]
        source_stop_pareto_optimal_tuples = source_stop_profile.get_final_optimal_labels()

        labels = []
        labels.append(LabelTime(departure_time=10, arrival_time_target=35))
        labels.append(LabelTime(departure_time=20, arrival_time_target=50))
        labels.append(LabelTime(departure_time=32, arrival_time_target=55))

        self._assert_pareto_tuple_sets_equal(
            labels,
            source_stop_pareto_optimal_tuples
        )

    def test_simple(self):
        event_list_raw_data = [
            (2, 4, 40, 50, "trip_5", 1),
        ]
        transit_connections = list(map(lambda el: Connection(*el), event_list_raw_data))
        walk_network = networkx.Graph()
        walk_network.add_edge(1, 2, d_walk=20)
        walk_network.add_edge(3, 4, d_walk=15)
        walk_speed = 1
        source_stop = 1
        target_stop = 4
        transfer_margin = 0
        start_time = 0
        end_time = 50

        labels = []
        labels.append(LabelTime(departure_time=20, arrival_time_target=50))

        csa_profile = PseudoConnectionScanProfiler(transit_connections, target_stop,
                                                   start_time, end_time, transfer_margin,
                                                   walk_network, walk_speed)
        csa_profile.run()
        source_stop_profile = csa_profile.stop_profiles[source_stop]
        source_stop_labels = source_stop_profile.get_final_optimal_labels()

        self._assert_pareto_tuple_sets_equal(
            labels,
            source_stop_labels
        )

    def test_last_leg_is_walk(self):
        event_list_raw_data = [
            (0, 1, 0, 10, "trip_1", 1)
        ]
        transit_connections = list(map(lambda el: Connection(*el), event_list_raw_data))
        walk_network = networkx.Graph()
        walk_network.add_edge(1, 2, d_walk=20)

        walk_speed = 1
        source_stop = 0
        target_stop = 2
        transfer_margin = 0
        start_time = 0
        end_time = 50
        labels = []
        labels.append(LabelTime(departure_time=0, arrival_time_target=30))

        csa_profile = PseudoConnectionScanProfiler(transit_connections, target_stop,
                                                   start_time, end_time, transfer_margin,
                                                   walk_network, walk_speed)
        csa_profile.run()
        found_tuples = csa_profile.stop_profiles[source_stop].get_final_optimal_labels()
        self._assert_pareto_tuple_sets_equal(found_tuples, labels)

    def test_walk_is_faster_than_by_trip(self):
        event_list_raw_data = [
            (0, 1, 0, 10, "trip_1", 1)
        ]
        transit_connections = list(map(lambda el: Connection(*el), event_list_raw_data))
        walk_speed = 2
        source_stop = 0
        target_stop = 1
        transfer_margin = 0
        start_time = 0
        end_time = 50

        walk_network = networkx.Graph()
        walk_network.add_edge(0, 1, d_walk=1)
        csa_profile = PseudoConnectionScanProfiler(transit_connections, target_stop,
                                                   start_time, end_time, transfer_margin,
                                                   walk_network, walk_speed)
        csa_profile.run()
        source_profile = csa_profile.stop_profiles[source_stop]
        self.assertEqual(source_profile.evaluate_earliest_arrival_time_at_target(0, 0), 0.5)
        found_tuples = source_profile.get_final_optimal_labels()
        self.assertEqual(len(found_tuples), 0)

    def test_target_node_not_in_walk_network(self):
        event_list_raw_data = [
            (0, 1, 0, 10, "trip_1", 1)
        ]
        transit_connections = list(map(lambda el: Connection(*el), event_list_raw_data))
        walk_speed = 2
        source_stop = 0
        target_stop = 1
        transfer_margin = 0
        start_time = 0
        end_time = 50

        walk_network = networkx.Graph()
        csa_profile = PseudoConnectionScanProfiler(transit_connections, target_stop,
                                                   start_time, end_time, transfer_margin,
                                                   walk_network, walk_speed)
        csa_profile.run()
        source_profile = csa_profile.stop_profiles[source_stop]
        self.assertEqual(source_profile.evaluate_earliest_arrival_time_at_target(0, 0), 10)
        found_tuples = source_profile.get_final_optimal_labels()
        self.assertEqual(len(found_tuples), 1)

    def _assert_pareto_tuple_sets_equal(self, found_tuples, should_be_tuples):
        for found_tuple in found_tuples:
            self.assertIn(found_tuple, should_be_tuples)
        for should_be_tuple in should_be_tuples:
            self.assertIn(should_be_tuple, found_tuples)


text:
package com.intellij.dvcs.push;

import javax.annotation.Nonnull;

import javax.swing.tree.DefaultMutableTreeNode;

public interface TreeNodeLinkListener {
  void onClick(@Nonnull DefaultMutableTreeNode source);
}