text:
package org.opencb.opencga.storage.mongodb.variant.load.variants;

import com.mongodb.ErrorCategory;
import com.mongodb.MongoBulkWriteException;
import com.mongodb.bulk.BulkWriteError;
import org.apache.commons.lang3.time.StopWatch;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.opencb.commons.ProgressLogger;
import org.opencb.commons.datastore.core.DataResult;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.datastore.mongodb.MongoDBCollection;
import org.opencb.commons.io.DataWriter;
import org.opencb.opencga.storage.core.metadata.models.StudyMetadata;
import org.opencb.opencga.storage.mongodb.variant.adaptors.VariantMongoDBAdaptor;
import org.opencb.opencga.storage.mongodb.variant.converters.stage.StageDocumentToVariantConverter;
import org.opencb.opencga.storage.mongodb.variant.load.MongoDBVariantWriteResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
import static org.opencb.opencga.storage.core.variant.VariantStorageOptions.LOADED_GENOTYPES;
import static org.opencb.opencga.storage.mongodb.variant.converters.DocumentToStudyVariantEntryConverter.FILEID_FIELD;
import static org.opencb.opencga.storage.mongodb.variant.converters.DocumentToStudyVariantEntryConverter.FILES_FIELD;
import static org.opencb.opencga.storage.mongodb.variant.converters.DocumentToVariantConverter.STUDIES_FIELD;
import static org.opencb.opencga.storage.mongodb.variant.converters.stage.StageDocumentToVariantConverter.ID_FIELD;
import static org.opencb.opencga.storage.mongodb.variant.load.stage.MongoDBVariantStageLoader.NEW_STUDY_FIELD;

/**
 * Created on 21/11/16.
 *
 * Loads data into the VARIANTS collection
 *   New variants
 *   New study in a existing variant
 *   New data in a existing study
 * Cleans (if needed/wanted) the STAGE collection.
 *   Removes the files from the indexed field. {@link StageDocumentToVariantConverter#STUDY_FILE_FIELD}
 *   Sets {studyId}.{fileId} fields to NULL.
 *   Do NOT remove ($unset) the field. See {@link MongoDBVariantMerger#alreadyProcessedStageDocument}
 *
 * @author Jacobo Coll <jacobo167@gmail.com>
 */
public class MongoDBVariantMergeLoader implements DataWriter<MongoDBOperations> {

    private final Logger logger = LoggerFactory.getLogger(MongoDBVariantMergeLoader.class);
    private static final QueryOptions QUERY_OPTIONS = new QueryOptions();
    private static final QueryOptions UPSERT_AND_RELPACE = new QueryOptions(MongoDBCollection.UPSERT, true)
            .append(MongoDBCollection.REPLACE, true);
    private static final QueryOptions UPSERT = new QueryOptions(MongoDBCollection.UPSERT, true);
    private static final QueryOptions MULTI = new QueryOptions(MongoDBCollection.MULTI, true);

    private final MongoDBCollection studiesCollection;
    private final ProgressLogger progressLogger;
    private final MongoDBCollection variantsCollection;
    private final MongoDBCollection stageCollection;
    private final boolean resume;
    private final boolean cleanWhileLoading;
    private final Integer studyId;
    /** Files to be loaded. */
    private final List<Integer> fileIds;

    // Variables that must be aware of concurrent modification
    private final MongoDBVariantWriteResult result;
    private final Bson cleanStageDuplicated;
    private final Bson cleanStage;

    public MongoDBVariantMergeLoader(MongoDBCollection variantsCollection, MongoDBCollection stageCollection,
                                     MongoDBCollection studiesCollection, StudyMetadata studyMetadata, List<Integer> fileIds,
                                     boolean resume, boolean cleanWhileLoading, ProgressLogger progressLogger) {
        this.progressLogger = progressLogger;
        this.variantsCollection = variantsCollection;
        this.stageCollection = stageCollection;
        this.studiesCollection = studiesCollection;
        this.resume = resume;
        this.studyId = studyMetadata.getId();
        this.fileIds = fileIds;
        this.result = new MongoDBVariantWriteResult();
        result.getGenotypes().addAll(studyMetadata.getAttributes().getAsStringList(LOADED_GENOTYPES.key()));
        this.cleanWhileLoading = cleanWhileLoading;

        List<String> studyFileToPull = new ArrayList<>(fileIds.size());
        for (Integer fileId : fileIds) {
            studyFileToPull.add(studyId + "_" + fileId);
        }
        List<Bson> cleanStageDuplicatedList = new ArrayList<>(fileIds.size() + 1);
        for (Integer fileId : fileIds) {
            // Can not unset value!
            cleanStageDuplicatedList.add(set(studyId + "." + fileId, null));
        }
        cleanStageDuplicatedList.add(pullAll(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyFileToPull));

        List<Bson> cleanStageList = new ArrayList<>(cleanStageDuplicatedList.size() + 1);
        cleanStageList.addAll(cleanStageDuplicatedList);
        cleanStageList.add(set(studyId.toString() + '.' + NEW_STUDY_FIELD, false));

        cleanStageDuplicated = combine(cleanStageDuplicatedList);
        cleanStage = combine(cleanStageList);

    }

    @Override
    public boolean write(List<MongoDBOperations> batch) {
        for (MongoDBOperations mongoDBOperations : batch) {
            executeMongoDBOperations(mongoDBOperations);
        }
        return true;
    }

    public MongoDBVariantWriteResult getResult() {
        return result;
    }

    /**
     * Execute the set of mongoDB operations.
     *
     * @param mongoDBOps MongoDB operations to execute
     * @return           MongoDBVariantWriteResult
     */
    protected MongoDBVariantWriteResult executeMongoDBOperations(MongoDBOperations mongoDBOps) {
        long newVariantsTime = 0; // Impossible to know how much time spend in insert or update in operation "UPSERT"
        StopWatch existingVariants = StopWatch.createStarted();
        long newVariants = 0;
        if (!mongoDBOps.getNewStudy().getQueries().isEmpty()) {
            newVariants = executeMongoDBOperationsNewStudy(mongoDBOps, true);
        }
        existingVariants.stop();
        StopWatch fillGapsVariants = StopWatch.createStarted();
        if (!mongoDBOps.getExistingStudy().getQueries().isEmpty()) {
            DataResult update = variantsCollection.update(mongoDBOps.getExistingStudy().getQueries(),
                    mongoDBOps.getExistingStudy().getUpdates(), QUERY_OPTIONS);
            if (update.getNumMatches() != mongoDBOps.getExistingStudy().getQueries().size()) {
                onUpdateError("fill gaps", update, mongoDBOps.getExistingStudy().getQueries(), mongoDBOps.getExistingStudy().getIds());
            }
        }
        fillGapsVariants.stop();

        updateStage(mongoDBOps);

        long updatesNewStudyExistingVariant = mongoDBOps.getNewStudy().getUpdates().size() - newVariants;
        long updatesWithDataExistingStudy = mongoDBOps.getExistingStudy().getUpdates().size() - mongoDBOps.getMissingVariants();
        MongoDBVariantWriteResult writeResult = new MongoDBVariantWriteResult(newVariants,
                updatesNewStudyExistingVariant + updatesWithDataExistingStudy, mongoDBOps.getMissingVariants(),
                mongoDBOps.getOverlappedVariants(), mongoDBOps.getSkipped(), mongoDBOps.getNonInserted(), newVariantsTime,
                existingVariants.getNanoTime(), fillGapsVariants.getNanoTime(), mongoDBOps.getGenotypes());

        boolean updateGenotypes;
        synchronized (result) {
            updateGenotypes = !result.getGenotypes().containsAll(mongoDBOps.getGenotypes());
            result.merge(writeResult);
        }
        if (updateGenotypes) {
            // Update the genotypes as soon as there is a new one detected.
            // Avoid losing values in case of failure.
            logger.debug("Update list of loaded genotypes");
            studiesCollection.update(
                    eq("_id", studyId),
                    addEachToSet("attributes." + LOADED_GENOTYPES.key(), new ArrayList<>(result.getGenotypes())),
                    null);
        }

        // Modifying the stage collection MUST be the latest operation.
        // If there is any failure, we must ensure that we can resume the operation.
        // Once the stage collection is clean, we can not resume the operation.
        if (cleanWhileLoading) {
            cleanStage(mongoDBOps);
        }

        long processedVariants = mongoDBOps.getNewStudy().getQueries().size()
                + mongoDBOps.getExistingStudy().getQueries().size()
                + mongoDBOps.getMissingVariantsNoFillGaps();
        logProgress(processedVariants);
        return writeResult;
    }

    private void updateStage(MongoDBOperations mongoDBOps) {

        MongoDBOperations.StageSecondaryAlternates alternates = mongoDBOps.getSecondaryAlternates();
        if (!alternates.getQueries().isEmpty()) {
            DataResult update = stageCollection.update(alternates.getQueries(), alternates.getUpdates(), null);
            if (update.getNumMatches() != alternates.getQueries().size()) {
                onUpdateError("populate secondary alternates", update, alternates.getQueries(), alternates.getIds(), stageCollection);
            }
        }

        long cleanDocuments = 0;
        if (cleanWhileLoading) {
            cleanDocuments = cleanStage(mongoDBOps);
        }

    }

    private long cleanStage(MongoDBOperations mongoDBOps) {
        long modifiedCount = 0;
        if (!mongoDBOps.getDocumentsToCleanStudies().isEmpty()) {
            logger.debug("Clean study {} from stage where all the files {} where duplicated : {}", studyId, fileIds,
                    mongoDBOps.getDocumentsToCleanStudies());
            modifiedCount += stageCollection.update(
                    in(ID_FIELD, mongoDBOps.getDocumentsToCleanStudies()), cleanStageDuplicated, MULTI).getNumUpdated();
        }
        if (!mongoDBOps.getDocumentsToCleanFiles().isEmpty()) {
            logger.debug("Cleaning files {} from stage collection", fileIds);
            modifiedCount += stageCollection.update(
                    in(ID_FIELD, mongoDBOps.getDocumentsToCleanFiles()), cleanStage, MULTI).getNumUpdated();
        }

        return modifiedCount;
    }

    private int executeMongoDBOperationsNewStudy(MongoDBOperations mongoDBOps, boolean retry) {
        int newVariants = 0;
        MongoDBOperations.NewStudy newStudy = mongoDBOps.getNewStudy();
        try {
            if (resume) {
                // Ensure files exists
                try {
                    if (!newStudy.getVariants().isEmpty()) {
                        newVariants += newStudy.getVariants().size();
                        variantsCollection.insert(newStudy.getVariants(), QUERY_OPTIONS);
                    }
                } catch (MongoBulkWriteException e) {
                    for (BulkWriteError writeError : e.getWriteErrors()) {
                        if (!ErrorCategory.fromErrorCode(writeError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
                            throw e;
                        } else {
                            // Not inserted variant
                            newVariants--;
                        }
                    }
                }

                // Update
                List<Bson> queriesExisting = new ArrayList<>(newStudy.getQueries().size());
                for (Bson bson : newStudy.getQueries()) {
                    queriesExisting.add(and(bson, nin(STUDIES_FIELD + "." + FILES_FIELD + "." + FILEID_FIELD, fileIds)));
                }
                // Update those existing variants
                DataResult update = variantsCollection.update(queriesExisting, newStudy.getUpdates(), QUERY_OPTIONS);
                //                if (update.first().getModifiedCount() != mongoDBOps.queriesExisting.size()) {
                //                    // FIXME: Don't know if there is some error inserting. Query already existing?
                //                    onUpdateError("existing variants", update, mongoDBOps.queriesExisting, mongoDBOps.queriesExistingId);
                //                }
            } else {
                DataResult update = variantsCollection.update(newStudy.getQueries(), newStudy.getUpdates(), UPSERT);
//                if (update.getNumUpdated() + update.first().getUpserts().size() != newStudy.getQueries().size()) {
                if (update.getNumUpdated() + update.getNumInserted() != newStudy.getQueries().size()) {
                    onUpdateError("existing variants", update, newStudy.getQueries(), newStudy.getIds());
                }
                // Add upserted documents
//                newVariants += update.first().getUpserts().size();
                newVariants += update.getNumInserted();
            }
        } catch (MongoBulkWriteException e) {
            // Add upserted documents
            newVariants += e.getWriteResult().getUpserts().size();
            Set<String> duplicatedNonInsertedId = new HashSet<>();
            for (BulkWriteError writeError : e.getWriteErrors()) {
                if (ErrorCategory.fromErrorCode(writeError.getCode()).equals(ErrorCategory.DUPLICATE_KEY)) {
                    String id = newStudy.getIds().get(writeError.getIndex());
                    duplicatedNonInsertedId.add(id);
                    logger.warn("Catch error : {}. DupKey exception inserting '{}'. Retry!",
                            writeError.toString(), id);
                } else {
                    throw e;
                }
            }
            if (retry) {
                // Retry once!
                // With UPSERT=true, this command should never throw DuplicatedKeyException.
                // See https://jira.mongodb.org/browse/SERVER-14322
                // Assume unordered bulk
                // Remove inserted variants
                logger.warn("Retry! " + e);
                Iterator<String> iteratorId = newStudy.getIds().iterator();
                Iterator<?> iteratorQuery = newStudy.getQueries().iterator();
                Iterator<?> iteratorUpdate = newStudy.getUpdates().iterator();
                while (iteratorId.hasNext()) {
                    String id = iteratorId.next();
                    iteratorQuery.next();
                    iteratorUpdate.next();
                    if (!duplicatedNonInsertedId.contains(id)) {
                        iteratorId.remove();
                        iteratorQuery.remove();
                        iteratorUpdate.remove();
                    }
                }
                newVariants += executeMongoDBOperationsNewStudy(mongoDBOps, false);
            } else {
                throw e;
            }
        }
        return newVariants;
    }

    protected void onUpdateError(String updateName, DataResult update, List<Bson> queries, List<String> queryIds) {
        onUpdateError(updateName, update, queries, queryIds, variantsCollection);
    }

    protected void onUpdateError(String updateName, DataResult update, List<Bson> queries, List<String> queryIds,
                                 MongoDBCollection collection) {
        logger.error("(Updated " + updateName + " variants = " + queries.size() + " ) != "
                + "(ModifiedCount = " + update.getNumUpdated() + "). MatchedCount:" + update.getNumMatches());
        logger.info("QueryIDs: {}", queryIds);
        List<DataResult<Document>> queryResults = collection.find(queries, null);
        logger.info("Results: {}", queryResults.size());

        for (DataResult<Document> r : queryResults) {
            logger.info("result: '{}'", r);
            if (!r.getResults().isEmpty()) {
                String id = r.first().get("_id", String.class);
                boolean remove = queryIds.remove(id);
                logger.info("remove({}): {}", id, remove);
            }
        }
        StringBuilder sb = new StringBuilder("Missing Variant for update : ");
        for (String id : queryIds) {
            logger.error("Missing Variant '" + id + '\'');
            sb.append('\'').append(id).append("', ");
        }
        throw new RuntimeException(sb.toString());
    }

    protected void logProgress(long processedVariants) {
        if (progressLogger != null) {
            progressLogger.increment(processedVariants);
        }
    }

    @Override
    public boolean post() {
        VariantMongoDBAdaptor.createIndexes(new QueryOptions(), variantsCollection);
        return true;
    }
//    protected void onInsertError(MongoDBOperations mongoDBOps, BulkWriteResult writeResult) {
//        logger.error("(Inserts = " + mongoDBOps.inserts.size() + ") "
//                + "!= (InsertedCount = " + writeResult.getInsertedCount() + ")");
//
//        StringBuilder sb = new StringBuilder("Missing Variant for insert : ");
//        for (Document insert : mongoDBOps.inserts) {
//            Long count = collection.count(eq("_id", insert.get("_id"))).first();
//            if (count != 1) {
//                logger.error("Missing insert " + insert.get("_id"));
//                sb.append(insert.get("_id")).append(", ");
//            }
//        }
//        throw new RuntimeException(sb.toString());
//    }
}


text:
package org.openoj.compiler;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author trayvon
 * @since  2015年11月16日
 *
 */
public class OpenCCompilerTest
{
	OpenCCompiler compiler;
	@Before
	public void setUp() throws Exception
	{
		compiler = new OpenCCompiler();
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void test()
	{
		String source = null;
		File file = new File("G:\\xhuoj\\oj\\test.c");
		try
		{
			source = FileUtils.readFileToString(file);
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		System.out.println(compiler.getErrorMessage());
		System.out.println(source);
		Assert.assertTrue(compiler.compile(source));

	}

}

redpajama_set_name: RedPajamaGithub


text:
package chana.avro

import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.StringWriter
import org.apache.avro.Schema
import org.apache.avro.Schema.Type
import org.apache.avro.generic.GenericDatumWriter
import org.apache.avro.generic.GenericEnumSymbol
import org.apache.avro.generic.IndexedRecord
import org.apache.avro.io.EncoderFactory
import org.apache.avro.specific.SpecificDatumWriter
import org.codehaus.jackson.JsonNode

/**
 *
 * Encode an Avro value into JSON.
 */
object ToJson {

  /**
   * Serializes a Java Avro value into JSON.
   *
   * When serializing records, fields whose value matches the fields' default value are omitted.
   *
   * @param value the Java value to serialize.
   * @param schema Avro schema of the value to serialize.
   * @return the value encoded as a JSON tree.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  def toJsonNode(value: Any, schema: Schema): JsonNode = {
    if (value != null) {
      schema.getType match {
        case Type.NULL    => JSON_NODE_FACTORY.nullNode
        case Type.BOOLEAN => JSON_NODE_FACTORY.booleanNode(value.asInstanceOf[Boolean])
        case Type.DOUBLE  => JSON_NODE_FACTORY.numberNode(value.asInstanceOf[Double])
        case Type.FLOAT   => JSON_NODE_FACTORY.numberNode(value.asInstanceOf[Float])
        case Type.INT     => JSON_NODE_FACTORY.numberNode(value.asInstanceOf[Int])
        case Type.LONG    => JSON_NODE_FACTORY.numberNode(value.asInstanceOf[Long])
        case Type.STRING  => JSON_NODE_FACTORY.textNode(value.asInstanceOf[CharSequence].toString)
        case Type.ENUM =>
          val strVal = value match {
            case x: GenericEnumSymbol => x.toString
            case x: Enum[_]           => x.toString
            case x: String            => x
          }
          JSON_NODE_FACTORY.textNode(strVal) // Enums are represented as strings

        case Type.BYTES | Type.FIXED =>
          // TODO Bytes are represented as strings (BASE64?)...
          throw new RuntimeException("toJsonNode(byte array) not implemented")

        case Type.ARRAY =>
          val jsonArray = JSON_NODE_FACTORY.arrayNode()
          val javaArray = value.asInstanceOf[java.lang.Iterable[_]].iterator
          while (javaArray.hasNext) {
            val element = javaArray.next
            jsonArray.add(toJsonNode(element, schema.getElementType))
          }
          jsonArray

        case Type.MAP =>
          val jsonObject = JSON_NODE_FACTORY.objectNode()
          val javaMap = value.asInstanceOf[java.util.Map[String, Any]].entrySet.iterator
          while (javaMap.hasNext) {
            val entry = javaMap.next
            jsonObject.put(entry.getKey, toJsonNode(entry.getValue, schema.getValueType))
          }
          jsonObject

        case Type.RECORD =>
          val jsonObject = JSON_NODE_FACTORY.objectNode()
          val record = value.asInstanceOf[IndexedRecord]
          //if (record.getSchema != schema) { // TODO not allow multiple version schema?
          //  throw new IOException("Avro schema specifies record type '%s' but got '%s'.".format(schema.getFullName, record.getSchema.getFullName))
          //}
          val fields = schema.getFields.iterator
          while (fields.hasNext) {
            val field = fields.next
            val fieldValue = record.get(field.pos)
            val fieldNode = toJsonNode(fieldValue, field.schema)
            // Outputs the field only if its value differs from the field's default:
            if (field.defaultValue == null || fieldNode != field.defaultValue) {
              jsonObject.put(field.name, fieldNode)
            }
          }
          jsonObject

        case Type.UNION =>
          toUnionJsonNode(value, schema)

        case _ =>
          throw new RuntimeException("Unexpected schema type '%s'.".format(schema))
      }
    } else {
      JSON_NODE_FACTORY.nullNode
    }
  }

  /**
   * Encodes an Avro union into a JSON node.
   *
   * @param value an Avro union to encode.
   * @param schema schema of the union to encode.
   * @return the encoded value as a JSON node.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  private def toUnionJsonNode(value: Any, schema: Schema): JsonNode = {
    if (schema.getType != Type.UNION) {
      throw new IOException("Avro schema specifies '%s' but got value: '%s'.".format(schema, value))
    }

    val optionalType = chana.avro.getFirstNoNullTypeOfUnion(schema)
    if (null != optionalType) {
      return if (null == value) JSON_NODE_FACTORY.nullNode else toJsonNode(value, optionalType)
    }

    val typeMap = new java.util.HashMap[Schema.Type, java.util.List[Schema]]()
    val tpes = schema.getTypes.iterator
    while (tpes.hasNext) {
      val tpe = tpes.next
      val typeList = typeMap.get(tpe.getType) match {
        case null =>
          val xs = new java.util.ArrayList[Schema]()
          typeMap.put(tpe.getType, xs)
          xs
        case xs => xs
      }
      typeList.add(tpe)
    }

    //  null is shortened as an immediate JSON null:
    if (null == value) {
      if (!typeMap.containsKey(Type.NULL)) {
        throw new IOException("Avro schema specifies '%s' but got 'null'.".format(schema))
      }
      return JSON_NODE_FACTORY.nullNode
    }

    val union = JSON_NODE_FACTORY.objectNode
    val tpes2 = schema.getTypes.iterator
    while (tpes2.hasNext) {
      val tpe = tpes2.next
      try {
        val actualNode = toJsonNode(value, tpe)
        union.put(tpe.getFullName, actualNode)
        return union
      } catch {
        case ex: IOException => // This type was not the correct union case, ignore...
      }
    }
    throw new IOException("Unable to encode '%s' as union '%s'.".format(value, schema))
  }

  /**
   * Encodes an Avro value into a JSON string.
   *
   * Fields with default values are omitted.
   *
   * @param value Avro value to encode.
   * @param schema Avro schema of the value.
   * @return Pretty string representation of the JSON-encoded value.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  def toJsonString(value: Any, schema: Schema): String = {
    val node = toJsonNode(value, schema)
    val stringWriter = new StringWriter()
    val generator = JSON_FACTORY.createJsonGenerator(stringWriter)
    // We have disabled this because we used unions to represent row key formats
    // in the table layout. This is a HACK and needs a better solution.
    // TODO: Find better solution.
    //generator.disable(Feature.QUOTE_FIELD_NAMES);
    JSON_MAPPER.writeValue(generator, node)
    stringWriter.toString
  }

  /**
   * Encodes an Avro record into JSON.
   *
   * @param record Avro record to encode.
   * @return Pretty JSON representation of the record.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  def toJsonString(record: IndexedRecord): String = {
    toJsonString(record, record.getSchema)
  }

  /**
   * Standard Avro/JSON encoder.
   *
   * @param value Avro value to encode.
   * @param schema Avro schema of the value.
   * @return JSON-encoded value.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  def toAvroJsonString(value: Any, schema: Schema): String = {
    try {
      val jsonOutputStream = new ByteArrayOutputStream()
      val jsonEncoder = EncoderFactory.get.jsonEncoder(schema, jsonOutputStream)
      val writer = new GenericDatumWriter[Any](schema)
      writer.write(value, jsonEncoder)
      jsonEncoder.flush()
      new String(jsonOutputStream.toByteArray)
    } catch {
      case ex: IOException => throw new RuntimeException("Internal error: " + ex)
    }
  }

  /**
   * Standard Avro/JSON encoder.
   *
   * @param record Avro record to encode.
   * @return JSON-encoded value.
   * @throws IOException on error.
   */
  @throws(classOf[IOException])
  def toAvroJsonString(record: IndexedRecord): String = {
    val schema = record.getSchema
    try {
      val jsonOutputStream = new ByteArrayOutputStream()
      val jsonEncoder = EncoderFactory.get().jsonEncoder(schema, jsonOutputStream)
      val writer = new SpecificDatumWriter(record.getClass.asInstanceOf[Class[Any]])
      writer.write(record, jsonEncoder)
      jsonEncoder.flush()
      new String(jsonOutputStream.toByteArray)
    } catch {
      case ex: IOException => throw new RuntimeException("Internal error: " + ex)
    }
  }

}


text:
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using Raven.Client;

namespace Sisyphus.Queue.Controller
{
    public class Status
    {
        public int AgentCount { get; set; }
        public int QueueCount { get; set; }
        public int TaskCount { get; set; }
    }

    public class StatusController : ApiController
    {
        private readonly IDocumentSession _documentSession;

        public StatusController(IDocumentSession documentSession)
        {
            _documentSession = documentSession;
        }

        public HttpResponseMessage<Status> Get()
        {
            var status = new Status
            {
                QueueCount = _documentSession.Query<Data.Queue>().Count()
            };

            var response = new HttpResponseMessage<Status>(status);

            return response;
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

namespace DiscUtils.CoreCompat
{
    internal static class ReflectionHelper
    {
        public static bool IsEnum(Type type)
        {
#if NETCORE
            return type.GetTypeInfo().IsEnum;
#else
            return type.IsEnum;
#endif
        }

        public static Attribute GetCustomAttribute(PropertyInfo property, Type attributeType)
        {
#if NETCORE
            return property.GetCustomAttribute(attributeType);
#else
            return Attribute.GetCustomAttribute(property, attributeType);
#endif
        }

        public static Attribute GetCustomAttribute(PropertyInfo property, Type attributeType, bool inherit)
        {
#if NETCORE
            return property.GetCustomAttribute(attributeType, inherit);
#else
            return Attribute.GetCustomAttribute(property, attributeType, inherit);
#endif
        }

        public static Attribute GetCustomAttribute(FieldInfo field, Type attributeType)
        {
#if NETCORE
            return field.GetCustomAttribute(attributeType);
#else
            return Attribute.GetCustomAttribute(field, attributeType);
#endif
        }

        public static Attribute GetCustomAttribute(Type type, Type attributeType)
        {
#if NETCORE
            return type.GetTypeInfo().GetCustomAttribute(attributeType);
#else
            return Attribute.GetCustomAttribute(type, attributeType);
#endif
        }

        public static Attribute GetCustomAttribute(Type type, Type attributeType, bool inherit)
        {
#if NETCORE
            return type.GetTypeInfo().GetCustomAttribute(attributeType, inherit);
#else
            return Attribute.GetCustomAttribute(type, attributeType);
#endif
        }

        public static IEnumerable<Attribute> GetCustomAttributes(Type type, Type attributeType, bool inherit)
        {
#if NETCORE
            return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit);
#else
            return Attribute.GetCustomAttributes(type, attributeType);
#endif
        }

        public static Assembly GetAssembly(Type type)
        {
#if NETCORE
            return type.GetTypeInfo().Assembly;
#else
            return type.Assembly;
#endif
        }

        public static int SizeOf<T>()
        {
#if NETCORE
            return Marshal.SizeOf<T>();
#else
            return Marshal.SizeOf(typeof(T));
#endif
        }
    }
}


text:
typedef NS_ENUM(NSUInteger, HXPresentTransitionType) {
    HXPresentTransitionTypePresent = 0,
    HXPresentTransitionTypeDismiss
};

typedef NS_ENUM(NSUInteger, HXPresentTransitionVcType) {
    HXPresentTransitionVcTypePhoto = 0,
    HXPresentTransitionVcTypeVideo
};

@interface HXPresentTransition : NSObject<UIViewControllerAnimatedTransitioning>

+ (instancetype)transitionWithTransitionType:(HXPresentTransitionType)type VcType:(HXPresentTransitionVcType)vcType withPhotoView:(HXPhotoView *)photoView;

- (instancetype)initWithTransitionType:(HXPresentTransitionType)type VcType:(HXPresentTransitionVcType)vcType withPhotoView:(HXPhotoView *)photoView;

@end


text:
void Timer2_Init(void);
void TIM2_IRQHandler(void);
void Timer3_Init(void);
void Timer4_Init(void);
void TIM4_IRQHandler(void);
void TIM6_Init(void);
void Delay_uS(uint32_t Delay);
void Delay_mS(uint32_t Delay);

#endif


text:
<!DOCTYPE html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />

<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Polyline | Android Developers</title>

<link rel="stylesheet"
href="//fonts.googleapis.com/css?family=Roboto+Condensed">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold"
  title="roboto">
<link href="/assets/css/default.css?v=5" rel="stylesheet" type="text/css">

            Quicknav
            Quicknav

              Design

Develop

Distribute

Links

Google Play Developer Console

Android Developers Blog

About Android

Android Sites

Android.com

Android Developers

Android Open Source Project

Language

            <select name="language" onChange="changeLangPref(this.value, true)">
                <option value="en">English</option>
                <option value="es">Español</option>
                <option value="ja">日本語</option>
                <option value="ko">한국어</option>
                <option value="ru">Русский</option>
                <option value="zh-cn">中文(简体)</option>
                <option value="zh-tw">中文(繁體)</option>
            </select>

      <form onsubmit="return submit_search()">
        <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q"
          onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)"
          onkeydown="return search_changed(event, true, '/')"
          onkeyup="return search_changed(event, false, '/')" />
      </form>

      close

About

Wear

TV

Auto

Get Started

Devices

Style

Patterns

Building Blocks

Downloads

Videos

Training

API Guides

Reference

Tools

Google Services

Samples

Google Play

Essentials

Get Users

Engage & Retain

Monetize

Analyze

Tools & Reference

Developer Stories

Training

API Guides

Reference

Tools

Google Services

Samples

Results

Loading...

Polyline

          Overview

          Games

          Location

          Google+

          Maps

          Drive

          Cast

      Ads

          Advertising ID

          Wallet

          SafetyNet

            Getting Started

      Google Play Services

          Setting Up Google Play Services

          Accessing Google APIs

              Authorizing with Google for REST APIs

            Reference

      Google Play In-app Billing

              Overview

              Version 3 API

              Implementing the API

              Reference

              Version 2 API

              Implementing the API

              Subscriptions

              Reference

              Subscriptions

              Security and Design

              Testing In-app Billing

              Administering In-app Billing

              Version Notes

        Google Cloud Messaging

            Overview

            Getting Started

            Implementing GCM Client

              Implementing GCM Server

              CCS (XMPP)

              HTTP

            Server Reference

              User Notifications

            Migration

        Google Cloud Save

      Google Play Distribution

          Filters on Google Play

              Google Play Developer API

          Multiple APK Support

          APK Expansion Files

          Application Licensing

              Licensing Overview

              Setting Up for Licensing

              Adding Licensing to Your App

              Licensing Reference

      Android Backup Service

          Register

Summary:

  Ctors

  | Methods

  | Inherited Methods

| [Expand All]

    public

    final

    class

Polyline

    extends Object

        java.lang.Object

               ↳

        com.google.android.gms.maps.model.Polyline

Class Overview

A polyline is a list of points, where line segments are drawn between consecutive points. A
 polyline has the following properties:

Points

The vertices of the line. Line segments are drawn between consecutive points. A polyline is
 not closed by default; to form a closed polyline, the start and end points must be the
 same.

Width

Line segment width in screen pixels. The width is constant and independent of the camera's
 zoom level. The default value is 10.

Color

Line segment color in ARGB format, the same format used by Color.
 The default value is black (0xff000000).

Z-Index

The order in which this tile overlay is drawn with respect to other overlays (including
 GroundOverlays, TileOverlays, Circles, and Polygons but
 not Markers). An overlay with a larger z-index is drawn over overlays with smaller
 z-indices. The order of overlays with the same z-index is arbitrary. The default
 zIndex is 0.

Visibility

Indicates if the polyline is visible or invisible, i.e., whether it is drawn on the map. An
 invisible polyline is not drawn, but retains all of its other properties. The default is
 true, i.e., visible.

Geodesic status

Indicates whether the segments of the polyline should be drawn as geodesics, as opposed to
 straight lines on the Mercator projection. A geodesic is the shortest path between two points on
 the Earth's surface. The geodesic curve is constructed assuming the Earth is a sphere

 Methods that modify a Polyline must be called on the main thread. If not, an
 IllegalStateException will be thrown at runtime.

Example

 GoogleMap map;
 // ... get a map.
 // Add a thin red line from London to New York.
 Polyline line = map.addPolyline(new PolylineOptions()
     .add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
     .width(5)
     .color(Color.RED));

Developer Guide

 For more information, read the Shapes
 developer guide.

Summary

Public Constructors

        <nobr>

            </nobr>

        <nobr>
        Polyline(IPolylineDelegate delegate)</nobr>

Public Methods

        <nobr>

            boolean</nobr>

        <nobr>
        equals(Object other)</nobr>

        <nobr>

            int</nobr>

        <nobr>
        getColor()</nobr>

          Gets the color of this polyline.

        <nobr>

            String</nobr>

        <nobr>
        getId()</nobr>

          Gets this polyline's id.

        <nobr>

            List<LatLng></nobr>

        <nobr>
        getPoints()</nobr>

          Returns a snapshot of the vertices of this polyline at this time .

        <nobr>

            float</nobr>

        <nobr>
        getWidth()</nobr>

          Gets the width of this polyline.

        <nobr>

            float</nobr>

        <nobr>
        getZIndex()</nobr>

          Gets the zIndex of this polyline.

        <nobr>

            int</nobr>

        <nobr>
        hashCode()</nobr>

        <nobr>

            boolean</nobr>

        <nobr>
        isGeodesic()</nobr>

          Gets whether each segment of the line is drawn as a geodesic or not.

        <nobr>

            boolean</nobr>

        <nobr>
        isVisible()</nobr>

          Gets the visibility of this polyline.

        <nobr>

            void</nobr>

        <nobr>
        remove()</nobr>

          Removes this polyline from the map.

        <nobr>

            void</nobr>

        <nobr>
        setColor(int color)</nobr>

          Sets the color of this polyline.

        <nobr>

            void</nobr>

        <nobr>
        setGeodesic(boolean geodesic)</nobr>

          Sets whether to draw each segment of the line as a geodesic or not.

        <nobr>

            void</nobr>

        <nobr>
        <a href="/reference/com/google/android/gms/maps/model/Polyline.html#setPoints(java.util.List<com.google.android.gms.maps.model.LatLng>)">setPoints(List<LatLng> points)</nobr>

          Sets the points of this polyline.

        <nobr>

            void</nobr>

        <nobr>
        setVisible(boolean visible)</nobr>

          Sets the visibility of this polyline.

        <nobr>

            void</nobr>

        <nobr>
        setWidth(float width)</nobr>

          Sets the width of this polyline.

        <nobr>

            void</nobr>

        <nobr>
        setZIndex(float zIndex)</nobr>

          Sets the zIndex of this polyline.

  [Expand]

Inherited Methods

From class

  java.lang.Object

        <nobr>

            Object</nobr>

        <nobr>
        clone()</nobr>

        <nobr>

            boolean</nobr>

        <nobr>
        equals(Object arg0)</nobr>

        <nobr>

            void</nobr>

        <nobr>
        finalize()</nobr>

        <nobr>

            final

            Class<?></nobr>

        <nobr>
        getClass()</nobr>

        <nobr>

            int</nobr>

        <nobr>
        hashCode()</nobr>

        <nobr>

            final

            void</nobr>

        <nobr>
        notify()</nobr>

        <nobr>

            final

            void</nobr>

        <nobr>
        notifyAll()</nobr>

        <nobr>

            String</nobr>

        <nobr>
        toString()</nobr>

        <nobr>

            final

            void</nobr>

        <nobr>
        wait()</nobr>

        <nobr>

            final

            void</nobr>

        <nobr>
        wait(long arg0, int arg1)</nobr>

        <nobr>

            final

            void</nobr>

        <nobr>
        wait(long arg0)</nobr>

Public Constructors

        public

      Polyline
      (IPolylineDelegate delegate)

Public Methods

        public

        boolean

      equals
      (Object other)

        public

        int

      getColor
      ()

Gets the color of this polyline.

Returns

the color in ARGB format.

        public

        String

      getId
      ()

Gets this polyline's id. The id will be unique amongst all Polylines on a map.

Returns

this polyline's id.

        public

        List<LatLng>

      getPoints
      ()

Returns a snapshot of the vertices of this polyline at this time . The list returned is a
 copy of the list of vertices and so changes to the polyline's vertices will not be reflected
 by this list, nor will changes to this list be reflected by the polyline. To change the
 vertices of the polyline, call <a href="/reference/com/google/android/gms/maps/model/Polyline.html#setPoints(java.util.List<com.google.android.gms.maps.model.LatLng>)">setPoints(List).

        public

        float

      getWidth
      ()

Gets the width of this polyline.

Returns

the width in screen pixels.

        public

        float

      getZIndex
      ()

Gets the zIndex of this polyline.

Returns

the zIndex of the polyline.

        public

        int

      hashCode
      ()

        public

        boolean

      isGeodesic
      ()

Gets whether each segment of the line is drawn as a geodesic or not.

Returns

true if each segment is drawn as a geodesic; false if each segment is
         drawn as a straight line on the Mercator projection.

        public

        boolean

      isVisible
      ()

Gets the visibility of this polyline.

Returns

this polyline's visibility.

        public

        void

      remove
      ()

Removes this polyline from the map. After a polyline has been removed, the behavior of all
 its methods is undefined.

        public

        void

      setColor
      (int color)

Sets the color of this polyline.

Parameters

          color
          the color in ARGB format

        public

        void

      setGeodesic
      (boolean geodesic)

Sets whether to draw each segment of the line as a geodesic or not.

Parameters

          geodesic
          if true, then each segment is drawn as a geodesic; if false,
            each segment is drawn as a straight line on the Mercator projection.

<A NAME="setPoints(java.util.List<com.google.android.gms.maps.model.LatLng>)">

        public

        void

      setPoints
      (List<LatLng> points)

Sets the points of this polyline. This method will take a copy of the points, so further
 mutations to points will have no effect on this polyline.

Parameters

          points
          an list of LatLngs that are the vertices of the polyline.

        public

        void

      setVisible
      (boolean visible)

Sets the visibility of this polyline. When not visible, a polyline is not drawn, but it keeps
 all its other properties.

Parameters

          visible
          if true, then the polyline is visible; if false, it is not.

        public

        void

      setWidth
      (float width)

Sets the width of this polyline.

Parameters

          width
          the width in screen pixels

        public

        void

      setZIndex
      (float zIndex)

Sets the zIndex of this polyline. Polylines with higher zIndices are drawn above those with
 lower indices.

Parameters

          zIndex
          the zIndex of this polyline.

  Except as noted, this content is licensed under Apache 2.0.
  For details and restrictions, see the
  Content License.

    About Android  |
    Legal  |
    Support


text:
{% include dochead.html %}

			<gcse:searchbox></gcse:searchbox>

			{% include docversionselector.html %}
			{% case page.collection %}
				{% when 'v1.1' %}
					{% include nav_v1.1.html %}
				{% when 'v1.0' %}
					{% include nav_v1.0.html %}
			{% endcase %}

			{% if page.collection == 'v1.0' %}
				{% include archivedocnotice.html %}
			{% endif %}
			{% include documentation.html %}

    <gcse:searchresults></gcse:searchresults>

{% include docfooter.html %}


text:
Cards.module("Set.Memo.SideBar", function(SideBar, App) {
	SideBar.SideBarView = Backbone.Marionette.ItemView.extend({
		template: "#set-memo-sideBar",
		className: "well well-sm sidebar-nav",
		ui: {

		}
	}),
	SideBar.ControlsView = Backbone.Marionette.ItemView.extend({
		template: "#set-memo-controls",
		className: "well well-sm sidebar-nav",
		ui: {

		},
		events: {
			"click a": "linkClicked"
		},
		initialize: function() {
			console.log(this.collection);
		},
		linkClicked : function(ev) {
			ev.preventDefault();

			console.log(this.model);
		},
		onRender: function() {

		}
	});
});


text:
import React, { Component } from 'react';

class TooltipPoint extends Component {
  render() {
    return (<g className="tooltip-point" transform={`translate(${this.props.position.x}, ${this.props.position.y})`}>
      <circle fill={this.props.stroke} stroke={this.props.stroke} />
            </g>);
  }
}

TooltipPoint.propTypes = {};
TooltipPoint.defaultProps = {};

export default TooltipPoint;


text:
background-image:url(white.png);
border: 7px double white;
font-size: 13px;
color: #333;
position: absolute;
width: 500px;
height: 200px;
top: 50%;
margin-left: 345px;
margin-top: -100px;
text-align:center;
-moz-border-radius: 30px;
-webkit-border-radius: 30px;
border-radius: 30px;
}
#search_up{
background-image:url(white.png);
border: 7px double white;
font-size: 13px;
color: #333;
width: 500px;
height: 200px;
margin-left: 345px;
margin-top: 100px;
text-align:center;
-moz-border-radius: 30px;
-webkit-border-radius: 30px;
border-radius: 30px;
}
#search_results{
padding-top:50px;
width:814px;
margin-left: 195px;
}

.left{
padding-left:30px;
font-size:17px;
font-weight:bold;
width:100px;
text-align:left;
}
.right{
padding-left:30px;
font-size:17px;
font-weight:bold;
width:100px;
text-align:left;
}
#right1{
background-color:#ffa;
width:300px;
border:6px solid #ddd;
}

#right2{
background-color:#ffa;
width:310px;
border:6px solid #ddd;
}

#submit{
background-color:#aaa;
color:black;
font-size:17px;
font-weight:bold;
width:400px;
border:6px solid #ddd;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
}

#submit:hover { text-decoration:none; font-style:italic;cursor:pointer;}

#nothing{
background-image:url(orange.png);
border: 3px solid white;
font-weight: bold;
font-size: 16px;
color: white;
margin-left:100px;
height: 50px;
width: 600px;
padding-top:10px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
text-align:center;
}
#error{
background-image:url(red.png);
border: 3px solid white;
font-weight: bold;
font-size: 16px;
color: white;
margin-left:100px;
height: 50px;
width: 600px;
padding-top:10px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
text-align:center;
}
.search_out{
background-image:url(white.png);
border: 7px double white;
color: #333;
width: 800px;
height:300px;
text-align:center;
-moz-border-radius: 30px;
-webkit-border-radius: 30px;
border-radius: 30px;
margin-bottom:50px;
}
.title {
font-size:19px;
font-weight:bold;
}
.nothing_out{
background-color:green;
font-size:20px;
font-weight:bold;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
color:white;
height:50px;
}
.out{
background-color:orange;
font-size:20px;
font-weight:bold;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
color:white;
height:50px;
}
.too_late_out{
background-color:red;
font-size:20px;
font-weight:bold;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
color:white;
height:50px;
}


text:
package core

import (
	"crypto/sha256"
	"fmt"
	"io/ioutil"
	"time"

	"github.com/intelsdi-x/snap/core/cdata"
)

type Plugin interface {
	TypeName() string
	Name() string
	Version() int
}

type PluginType int

func ToPluginType(name string) (PluginType, error) {
	pts := map[string]PluginType{
		"collector": 0,
		"processor": 1,
		"publisher": 2,
	}
	t, ok := pts[name]
	if !ok {
		return -1, fmt.Errorf("invalid plugin type name given %s", name)
	}
	return t, nil
}

func (pt PluginType) String() string {
	return []string{
		"collector",
		"processor",
		"publisher",
	}[pt]
}

const (
	// List of plugin type
	CollectorPluginType PluginType = iota
	ProcessorPluginType
	PublisherPluginType
)

type AvailablePlugin interface {
	Plugin
	HitCount() int
	LastHit() time.Time
	ID() uint32
}

// the public interface for a plugin
// this should be the contract for
// how mgmt modules know a plugin
type CatalogedPlugin interface {
	Plugin
	IsSigned() bool
	Status() string
	PluginPath() string
	LoadedTimestamp() *time.Time
}

// the collection of cataloged plugins used
// by mgmt modules
type PluginCatalog []CatalogedPlugin

type SubscribedPlugin interface {
	Plugin
	Config() *cdata.ConfigDataNode
}

type RequestedPlugin struct {
	path      string
	checkSum  [sha256.Size]byte
	signature []byte
}

func NewRequestedPlugin(path string) (*RequestedPlugin, error) {
	rp := &RequestedPlugin{
		path:      path,
		signature: nil,
	}
	err := rp.generateCheckSum()
	if err != nil {
		return nil, err
	}
	return rp, nil
}

func (p *RequestedPlugin) Path() string {
	return p.path
}

func (p *RequestedPlugin) CheckSum() [sha256.Size]byte {
	return p.checkSum
}

func (p *RequestedPlugin) Signature() []byte {
	return p.signature
}

func (p *RequestedPlugin) SetPath(path string) {
	p.path = path
}

func (p *RequestedPlugin) SetSignature(data []byte) {
	p.signature = data
}

func (p *RequestedPlugin) generateCheckSum() error {
	var b []byte
	var err error
	if b, err = ioutil.ReadFile(p.path); err != nil {
		return err
	}
	p.checkSum = sha256.Sum256(b)
	return nil
}

func (p *RequestedPlugin) ReadSignatureFile(file string) error {
	var b []byte
	var err error
	if b, err = ioutil.ReadFile(file); err != nil {
		return err
	}
	p.SetSignature(b)
	return nil
}


text:
<!-- Twitter Card -->
    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="{{ site.twitter_username }}">
    <meta name="twitter:url" content="{{ site.url }}/{{ page.class }}">
    <meta name="twitter:creator" content="{{ site.twitter_username }}">
    <meta name="twitter:title" content="{{ page.title }} - {{ site.title }}">
    <meta name="twitter:description" content="{{ page.description }}">


text:
using Google.Api.Ads.AdManager.Lib;
using Google.Api.Ads.AdManager.Util.v202208;
using Google.Api.Ads.AdManager.v202208;

using System;
using System.Collections.Generic;

namespace Google.Api.Ads.AdManager.Examples.CSharp.v202208
{
    /// <summary>
    /// This code example deactivates a custom field. To determine which custom fields exist,
    /// run GetAllCustomFields.cs.
    /// </summary>
    public class DeactivateCustomFields : SampleBase
    {
        /// <summary>
        /// Returns a description about the code example.
        /// </summary>
        public override string Description
        {
            get
            {
                return "This code example deactivates a custom field. To determine which custom " +
                    "fields exist, run GetAllCustomFields.cs.";
            }
        }

        /// <summary>
        /// Main method, to run this code example as a standalone application.
        /// </summary>
        public static void Main()
        {
            DeactivateCustomFields codeExample = new DeactivateCustomFields();
            Console.WriteLine(codeExample.Description);
            codeExample.Run(new AdManagerUser());
        }

        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (CustomFieldService customFieldService = user.GetService<CustomFieldService>())
            {
                // Set the ID of the custom field to update.
                int customFieldId = int.Parse(_T("INSERT_CUSTOM_FIELD_ID_HERE"));

                // Create statement to select only active custom fields that apply to
                // line items.
                StatementBuilder statementBuilder = new StatementBuilder()
                    .Where("id = :id")
                    .OrderBy("id ASC")
                    .Limit(1)
                    .AddValue("id", customFieldId);

                // Set default for page.
                CustomFieldPage page = new CustomFieldPage();
                int i = 0;
                List<string> customFieldIds = new List<string>();

                try
                {
                    do
                    {
                        // Get custom fields by statement.
                        page = customFieldService.getCustomFieldsByStatement(
                            statementBuilder.ToStatement());

                        if (page.results != null)
                        {
                            foreach (CustomField customField in page.results)
                            {
                                Console.WriteLine(
                                    "{0}) Custom field with ID \"{1}\" and name \"{2}\" will be " +
                                    "deactivated.", i, customField.id, customField.name);
                                customFieldIds.Add(customField.id.ToString());
                                i++;
                            }
                        }

                        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                    } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                    Console.WriteLine("Number of custom fields to be deactivated: " +
                        customFieldIds.Count);

                    if (customFieldIds.Count > 0)
                    {
                        // Remove limit and offset from statement.
                        statementBuilder.RemoveLimitAndOffset();

                        // Create action.
                        Google.Api.Ads.AdManager.v202208.DeactivateCustomFields action =
                            new Google.Api.Ads.AdManager.v202208.DeactivateCustomFields();

                        // Perform action.
                        UpdateResult result =
                            customFieldService.performCustomFieldAction(action,
                                statementBuilder.ToStatement());

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of custom fields deactivated: " +
                                result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No custom fields were deactivated.");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to deactivate custom fields. Exception says \"{0}\"",
                        e.Message);
                }
            }
        }
    }
}


text:
<!DOCTYPE html>

@include('adminlte::layouts.partials.htmlheader')

            @yield('main-content')

    @section('scripts')
        @include('adminlte::layouts.partials.scripts')
    @show


text:
/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 3.0.12
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package com.intel.analytics.bigdl.friesian.serving.recall.faiss.swighnswlib;

public class OperatingPoint {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

  protected OperatingPoint(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  protected static long getCPtr(OperatingPoint obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        swigfaissJNI.delete_OperatingPoint(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public void setPerf(double value) {
    swigfaissJNI.OperatingPoint_perf_set(swigCPtr, this, value);
  }

  public double getPerf() {
    return swigfaissJNI.OperatingPoint_perf_get(swigCPtr, this);
  }

  public void setT(double value) {
    swigfaissJNI.OperatingPoint_t_set(swigCPtr, this, value);
  }

  public double getT() {
    return swigfaissJNI.OperatingPoint_t_get(swigCPtr, this);
  }

  public void setKey(String value) {
    swigfaissJNI.OperatingPoint_key_set(swigCPtr, this, value);
  }

  public String getKey() {
    return swigfaissJNI.OperatingPoint_key_get(swigCPtr, this);
  }

  public void setCno(int value) {
    swigfaissJNI.OperatingPoint_cno_set(swigCPtr, this, value);
  }

  public int getCno() {
    return swigfaissJNI.OperatingPoint_cno_get(swigCPtr, this);
  }

  public OperatingPoint() {
    this(swigfaissJNI.new_OperatingPoint(), true);
  }

}


text:
class Boost < Formula
  desc "Collection of portable C++ source libraries"
  homepage "https://www.boost.org/"
  url "https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2"
  sha256 "7f6130bc3cf65f56a618888ce9d5ea704fa10b462be126ad053e80e553d6d8b7"
  head "https://github.com/boostorg/boost.git"

  bottle do
    cellar :any
    sha256 "d447d437cd81b059b61fef235e8f2099434a587fff3af319b8f32971096da6ad" => :mojave
    sha256 "07dbc64ae90c2d1a5d496621b47bcf4e8a660392a02d64fa5fe780dba5e47f88" => :high_sierra
    sha256 "40f3b92d543b9ffe437f1724c26ab55f9873e59fdc7afd46d82c83239a03fa9b" => :sierra
  end

  option "with-icu4c", "Build regexp engine with icu support"
  option "without-single", "Disable building single-threading variant"
  option "without-static", "Disable building static library variant"

  deprecated_option "with-icu" => "with-icu4c"

  depends_on "icu4c" => :optional

  needs :cxx14

  def install
    # Force boost to compile with the desired compiler
    open("user-config.jam", "a") do |file|
      file.write "using darwin : : #{ENV.cxx} ;\n"
    end

    # libdir should be set by --prefix but isn't
    bootstrap_args = ["--prefix=#{prefix}", "--libdir=#{lib}"]

    if build.with? "icu4c"
      icu4c_prefix = Formula["icu4c"].opt_prefix
      bootstrap_args << "--with-icu=#{icu4c_prefix}"
    else
      bootstrap_args << "--without-icu"
    end

    # Handle libraries that will not be built.
    without_libraries = ["python", "mpi"]

    # Boost.Log cannot be built using Apple GCC at the moment. Disabled
    # on such systems.
    without_libraries << "log" if ENV.compiler == :gcc

    bootstrap_args << "--without-libraries=#{without_libraries.join(",")}"

    # layout should be synchronized with boost-python and boost-mpi
    args = ["--prefix=#{prefix}",
            "--libdir=#{lib}",
            "-d2",
            "-j#{ENV.make_jobs}",
            "--layout=tagged",
            "--user-config=user-config.jam",
            "-sNO_LZMA=1",
            "install"]

    if build.with? "single"
      args << "threading=multi,single"
    else
      args << "threading=multi"
    end

    if build.with? "static"
      args << "link=shared,static"
    else
      args << "link=shared"
    end

    # Boost is using "clang++ -x c" to select C compiler which breaks C++14
    # handling using ENV.cxx14. Using "cxxflags" and "linkflags" still works.
    args << "cxxflags=-std=c++14"
    if ENV.compiler == :clang
      args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++"
    end

    system "./bootstrap.sh", *bootstrap_args
    system "./b2", "headers"
    system "./b2", *args
  end

  def caveats
    s = ""
    # ENV.compiler doesn't exist in caveats. Check library availability
    # instead.
    if Dir["#{lib}/libboost_log*"].empty?
      s += <<~EOS
        Building of Boost.Log is disabled because it requires newer GCC or Clang.
      EOS
    end

    s
  end

  test do
    (testpath/"test.cpp").write <<~EOS
      #include <boost/algorithm/string.hpp>
      #include <string>
      #include <vector>
      #include <assert.h>
      using namespace boost::algorithm;
      using namespace std;

      int main()
      {
        string str("a,b");
        vector<string> strVec;
        split(strVec, str, is_any_of(","));
        assert(strVec.size()==2);
        assert(strVec[0]=="a");
        assert(strVec[1]=="b");
        return 0;
      }
    EOS
    system ENV.cxx, "test.cpp", "-std=c++1y", "-L#{lib}", "-lboost_system", "-o", "test"
    system "./test"
  end
end


text:
import argparse
import cPickle
import gzip
import bz2
import logging
import os
import subprocess

import numpy
import tables
import h5py

from collections import Counter
from numpy.lib.stride_tricks import as_strided
from tqdm import tqdm
from scipy.sparse import lil_matrix, csr_matrix, save_npz

parser = argparse.ArgumentParser(
    description="""
This takes a list of .txt or .txt.gz files and does word counting and
creating a dictionary (potentially limited by size). It uses this
dictionary to binarize the text into a numeric format (replacing OOV
words with 2) and create n-grams of a fixed size (padding the sentence
with 0 for EOS and BOS markers as necessary). The n-gram data can be
split up in a training and validation set.

The n-grams are saved to HDF5 format whereas the dictionary, word counts
and binarized text are all pickled Python objects.
""", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("input", type=argparse.FileType('r'), nargs="+",
                    help="The input files")
parser.add_argument("-b", "--binarized-text", default='binarized_text.pkl',
                    help="the name of the pickled binarized text file")
parser.add_argument('--chunk-size', type=int, default=128000,
                    help='size of chunk to save binarized text to')
parser.add_argument("-d", "--dictionary", default='vocab.pkl',
                    help="the name of the pickled binarized text file")
parser.add_argument("-n", "--ngram", type=int, metavar="N",
                    help="create n-grams")
parser.add_argument("-v", "--vocab", type=int, metavar="N",
                    help="limit vocabulary size to this number, which must "
                          "include BOS/EOS and OOV markers")
parser.add_argument("-p", "--pickle", action="store_true",
                    help="pickle the text as a list of lists of ints")
parser.add_argument("-s", "--split", type=float, metavar="N",
                    help="create a validation set. If >= 1 take this many "
                         "samples for the validation set, if < 1, take this "
                         "fraction of the samples")
parser.add_argument("-o", "--overwrite", action="store_true",
                    help="overwrite earlier created files, also forces the "
                         "program not to reuse count files")
parser.add_argument("-e", "--each", action="store_true",
                    help="output files for each separate input file")
parser.add_argument("-c", "--count", action="store_true",
                    help="save the word counts")
parser.add_argument("-t", "--char", action="store_true",
                    help="character-level processing")
parser.add_argument("-l", "--lowercase", action="store_true",
                    help="lowercase")
parser.add_argument('--start-token', type=int, default=0,
                    help='token for <START>')
parser.add_argument('--pad-token', type=int, default=1, help='token for <PAD>')
parser.add_argument('--unk-token', type=int, default=2, help='token for <UNK>')

def gzip_uncompressed_size(gzipfile_path):
    return int(subprocess.check_output(
        'gzip -l {}'.format(gzipfile_path).split()
    ).split()[5])

# Source: http://stackoverflow.com/a/434328
def chunker(seq, size):
    return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))

def open_files():
    base_filenames = []
    for i, input_file in enumerate(args.input):
        dirname, filename = os.path.split(input_file.name)
        if filename.split(os.extsep)[-1] == 'gz':
            base_filename = filename.rstrip('.gz')
        elif filename.split(os.extsep)[-1] == 'bz2':
            base_filename = filename.rstrip('.bz2')
        else:
            base_filename = filename
        if base_filename.split(os.extsep)[-1] == 'txt':
            base_filename = base_filename.rstrip('.txt')
        if filename.split(os.extsep)[-1] == 'gz':
            args.input[i] = gzip.GzipFile(input_file.name, input_file.mode,
                                          9, input_file)
        elif filename.split(os.extsep)[-1] == 'bz2':
            args.input[i] = bz2.BZ2File(input_file.name, input_file.mode)
        base_filenames.append(base_filename)
    return base_filenames

def safe_pickle(obj, filename):
    if os.path.isfile(filename) and not args.overwrite:
        logger.warning("Not saving %s, already exists." % (filename))
    else:
        if os.path.isfile(filename):
            logger.info("Overwriting %s." % filename)
        else:
            logger.info("Saving to %s." % filename)
        with open(filename, 'wb') as f:
            cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)

def safe_hdf(array, name):
    if os.path.isfile(name + '.hdf') and not args.overwrite:
        logger.warning("Not saving %s, already exists." % (name + '.hdf'))
    else:
        if os.path.isfile(name + '.hdf'):
            logger.info("Overwriting %s." % (name + '.hdf'))
        else:
            logger.info("Saving to %s." % (name + '.hdf'))
        with tables.openFile(name + '.hdf', 'w') as f:
            atom = tables.Atom.from_dtype(array.dtype)
            filters = tables.Filters(complib='blosc', complevel=5)
            ds = f.createCArray(f.root, name.replace('.', ''), atom,
                                array.shape, filters=filters)
            ds[:] = array

def create_dictionary():
    # Part I: Counting the words
    counters = []
    sentence_counts = []
    global_counter = Counter()

    for input_file, base_filename in zip(args.input, base_filenames):
        count_filename = base_filename + '.count.pkl'
        input_filename = os.path.basename(input_file.name)
        if os.path.isfile(count_filename) and not args.overwrite:
            logger.info("Loading word counts for %s from %s"
                        % (input_filename, count_filename))
            with open(count_filename, 'rb') as f:
                counter = cPickle.load(f)
            sentence_count = sum([1 for line in input_file])
        else:
            logger.info("Counting words in %s" % input_filename)
            counter = Counter()
            sentence_count = 0

            input_file_bsize = gzip_uncompressed_size(input_file.filename)
            with tqdm(total=input_file_bsize, unit='byte') as pbar:
                last_tell = input_file.tell()
                for line in input_file:
                    new_tell = input_file.tell()
                    pbar.update(new_tell - last_tell)
                    last_tell = new_tell

                    if args.lowercase:
                        line = line.lower()
                    words = None
                    if args.char:
                        words = list(line.strip().decode('utf-8'))
                    else:
                        words = line.strip().split(' ')
                    counter.update(words)
                    global_counter.update(words)
                    sentence_count += 1
        counters.append(counter)
        sentence_counts.append(sentence_count)
        logger.info("%d unique words in %d sentences with a total of %d words."
                    % (len(counter), sentence_count, sum(counter.values())))
        if args.each and args.count:
            safe_pickle(counter, count_filename)
        input_file.seek(0)

    # Part II: Combining the counts
    combined_counter = global_counter
    logger.info("Total: %d unique words in %d sentences with a total "
                "of %d words."
                % (len(combined_counter), sum(sentence_counts),
                   sum(combined_counter.values())))
    if args.count:
        safe_pickle(combined_counter, 'combined.count.pkl')

    # Part III: Creating the dictionary
    if args.vocab is not None:
        if args.vocab <= 2:
            logger.info('Building a dictionary with all unique words')
            args.vocab = len(combined_counter) + 2
        vocab_count = combined_counter.most_common(args.vocab - 2)
        logger.info("Creating dictionary of %s most common words, covering "
                    "%2.1f%% of the text."
                    % (args.vocab,
                       100.0 * sum([count for word, count in vocab_count]) /
                       sum(combined_counter.values())))
    else:
        logger.info("Creating dictionary of all words")
        vocab_count = counter.most_common()
    vocab = {
        '<UNK>': args.unk_token,
        '<START>': args.start_token,
        '<PAD>': args.pad_token}
    for i, (word, count) in enumerate(vocab_count):
        vocab[word] = i + 2
    safe_pickle(vocab, args.dictionary)
    return combined_counter, sentence_counts, counters, vocab

def binarize():
    if args.ngram:
        assert numpy.iinfo(numpy.uint16).max > len(vocab)
        ngrams = numpy.empty((sum(combined_counter.values()) +
                              sum(sentence_counts), args.ngram),
                             dtype='uint16')
    binarized_corpora = []
    total_ngram_count = 0
    for input_file, base_filename, sentence_count in \
            zip(args.input, base_filenames, sentence_counts):
        input_filename = os.path.basename(input_file.name)
        logger.info("Binarizing %s." % (input_filename))
        binarized_corpus = []
        ngram_count = 0

        input_file_bsize = gzip_uncompressed_size(input_file.filename)
        with tqdm(total=input_file_bsize, unit='byte') as pbar:
            last_tell = input_file.tell()
            for sentence in input_file:
                new_tell = input_file.tell()
                pbar.update(new_tell - last_tell)
                last_tell = new_tell
                if args.lowercase:
                    sentence = sentence.lower()
                if args.char:
                    words = list(sentence.strip().decode('utf-8'))
                else:
                    words = sentence.strip().split(' ')
                binarized_sentence = numpy.array([vocab.get(word, args.unk_token)
                                      for word in words])
                binarized_corpus.append(binarized_sentence)
                if args.ngram:
                    padded_sentence = numpy.asarray(
                        [0] * (args.ngram - 1) + binarized_sentence + [0]
                    )
                    ngrams[total_ngram_count + ngram_count:
                           total_ngram_count + ngram_count + len(words) + 1] =  \
                        as_strided(
                            padded_sentence,
                            shape=(len(words) + 1, args.ngram),
                            strides=(padded_sentence.itemsize,
                                     padded_sentence.itemsize)
                        )
                ngram_count += len(words) + 1
            # endfor sentence in input_file
        # Output
        if args.each:
            if args.pickle:
                safe_pickle(binarized_corpus, base_filename + '.pkl')
            if args.ngram and args.split:
                if args.split >= 1:
                    rows = int(args.split)
                else:
                    rows = int(ngram_count * args.split)
                logger.info("Saving training set (%d samples) and validation "
                            "set (%d samples)."
                            % (ngram_count - rows, rows))
                rows = numpy.random.choice(ngram_count, rows, replace=False)
                safe_hdf(ngrams[total_ngram_count + rows],
                         base_filename + '_valid')
                safe_hdf(
                    ngrams[total_ngram_count + numpy.setdiff1d(
                        numpy.arange(ngram_count),
                        rows, True
                    )], base_filename + '_train'
                )
            elif args.ngram:
                logger.info("Saving n-grams to %s." % (base_filename + '.hdf'))
                safe_hdf(ngrams, base_filename)
        binarized_corpora += binarized_corpus
        total_ngram_count += ngram_count
        input_file.seek(0)
    # endfor input_file in args.input

    if args.chunk_size:
        total_num_chunks = len(binarized_corpora)/args.chunk_size
        for chunk_i, chunk in enumerate(chunker(binarized_corpora, args.chunk_size)):
            chunk_name = '{}-{:03d}.h5.gz'.format(args.binarized_text, chunk_i)
            with h5py.File(chunk_name, 'w') as chunkfile:
                max_sentence_len = max(len(s) for s in chunk)
                dataset = chunkfile.create_dataset(
                    'default', dtype='i', shape=(len(chunk), max_sentence_len),
                    fillvalue=0, compression='gzip',
                    compression_opts=9)
                for si, s in enumerate(sorted(chunk, key=lambda seq: len(seq))):
                    dataset[si, :len(s)] = s
            print('Saved chunk {}/{} ({})'.format(chunk_i+1, total_num_chunks, chunk_name))
    else:
        safe_pickle(binarized_corpora, args.binarized_text)

    if args.split:
        if args.split >= 1:
            rows = int(args.split)
        else:
            rows = int(total_ngram_count * args.split)
        logger.info("Saving training set (%d samples) and validation set (%d "
                    "samples)."
                    % (total_ngram_count - rows, rows))
        rows = numpy.random.choice(total_ngram_count, rows, replace=False)
        if args.ngram:
            safe_hdf(ngrams[rows], 'combined_valid')
            safe_hdf(ngrams[numpy.setdiff1d(numpy.arange(total_ngram_count),
                                            rows, True)], 'combined_train')
        else:
            safe_hdf(binarized_corpora[rows], 'combined_valid.hdf')
            safe_hdf(binarized_corpora[
                numpy.setdiff1d(numpy.arange(total_ngram_count),
                                rows, True)], 'combined_train.hdf')
    elif args.ngram:
        safe_hdf(ngrams, 'combined')

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger('preprocess')
    args = parser.parse_args()
    base_filenames = open_files()
    combined_counter, sentence_counts, counters, vocab = create_dictionary()
    binarize()


text:
"""Tests for VGG16 application."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow.contrib.keras.python import keras
from tensorflow.python.platform import test

class VGG16Test(test.TestCase):

  def test_with_top(self):
    model = keras.applications.VGG16(weights=None)
    self.assertEqual(model.output_shape, (None, 1000))

  def test_no_top(self):
    model = keras.applications.VGG16(weights=None, include_top=False)
    self.assertEqual(model.output_shape, (None, None, None, 512))

  def test_with_pooling(self):
    model = keras.applications.VGG16(weights=None,
                                     include_top=False,
                                     pooling='avg')
    self.assertEqual(model.output_shape, (None, 512))

  def test_weight_loading(self):
    with self.assertRaises(ValueError):
      keras.applications.VGG16(weights='unknown',
                               include_top=False)
    with self.assertRaises(ValueError):
      keras.applications.VGG16(weights='imagenet',
                               classes=2000)

if __name__ == '__main__':
  test.main()