text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.CoreSetup.Test;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Xml.Linq;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Packaging.Tests
{
    public class NuGetArtifactTester : IDisposable
    {
        public static NuGetArtifactTester Open(
            RepoDirectoriesProvider dirs,
            string project,
            string id = null)
        {
            var tester = OpenOrNull(dirs, project, id);
            Assert.NotNull(tester);
            return tester;
        }

        public static NuGetArtifactTester OpenOrNull(
            RepoDirectoriesProvider dirs,
            string project,
            string id = null)
        {
            id = id ?? project;

            string nuspecPath = Path.Combine(
                dirs.BaseArtifactsFolder,
                "packages",
                dirs.Configuration,
                "specs",
                $"{id}.nuspec");

            if (!File.Exists(nuspecPath))
            {
                return null;
            }

            PackageIdentity builtIdentity = new NuspecReader(nuspecPath).GetIdentity();

            string nupkgPath = Path.Combine(
                dirs.BaseArtifactsFolder,
                "packages",
                dirs.Configuration,
                "Shipping",
                $"{builtIdentity}.nupkg");

            // If the nuspec exists, the nupkg should exist.
            Assert.True(File.Exists(nupkgPath));

            return new NuGetArtifactTester(nupkgPath);
        }

        public PackageIdentity Identity { get; }
        public NuGetVersion PackageVersion { get; }

        private readonly PackageArchiveReader _reader;

        public NuGetArtifactTester(string file)
        {
            _reader = new PackageArchiveReader(ZipFile.Open(file, ZipArchiveMode.Read));
            Identity = _reader.NuspecReader.GetIdentity();
            PackageVersion = _reader.NuspecReader.GetVersion();
        }

        public void Dispose()
        {
            _reader.Dispose();
        }

        public void IsTargetingPack()
        {
            IsFrameworkPack();

            Assert.NotEmpty(_reader.GetFiles("ref"));
            Assert.Empty(_reader.GetFiles("runtimes"));
            Assert.Empty(_reader.GetFiles("lib"));

            ContainsFrameworkList("FrameworkList.xml");
        }

        public void IsTargetingPackForPlatform()
        {
            IsFrameworkPack();

            HasGoodPlatformManifest();
        }

        public void IsAppHostPack()
        {
            IsRuntimeSpecificPack();
        }

        public void IsRuntimePack()
        {
            IsRuntimeSpecificPack();

            HasOnlyTheseDataFiles(
                "data/RuntimeList.xml",
                "data/PlatformManifest.txt");

            HasGoodPlatformManifest();

            ContainsFrameworkList("RuntimeList.xml");
        }

        public void HasOnlyTheseDataFiles(params string[] expectedDataFiles)
        {
            HashSet<string> dataFileSet = _reader.GetFiles("data").ToHashSet();

            Assert.True(
                dataFileSet.SetEquals(expectedDataFiles),
                "Invalid set of data files: " +
                    $"expected '{string.Join(", ", expectedDataFiles)}', " +
                    $"actual '{string.Join(", ", dataFileSet)}'");
        }

        public void HasGoodPlatformManifest()
        {
            string platformManifestContent = ReadEntryContent(
                _reader.GetEntry("data/PlatformManifest.txt"));

            // Sanity: check if the manifest has some content.
            Assert.Contains(".dll", platformManifestContent);

            // Check that the lines contain the package ID where they're supposed to.
            foreach (var parts in platformManifestContent
                .Split('\r', '\n')
                .Select(line => line.Split("|"))
                .Where(parts => parts.Length > 1))
            {
                Assert.True(
                    parts[1] == Identity.Id,
                    $"Platform manifest package id column '{parts[1]}' doesn't match " +
                        $"actual package id '{Identity.Id}'");
            }
        }

        public string ReadEntryContent(string entry)
        {
            return ReadEntryContent(_reader.GetEntry(entry));
        }

        public XDocument ReadEntryXDocument(string entry)
        {
            return ReadEntryXDocument(_reader.GetEntry(entry));
        }

        private void IsFrameworkPack()
        {
            Assert.Empty(_reader.GetPackageDependencies());

            var expectedTypes = new[] { new PackageType("DotnetPlatform", new Version(0, 0)) };
            var types = _reader.GetPackageTypes().ToArray();
            Assert.Equal(expectedTypes, types);
        }

        private void IsRuntimeSpecificPack()
        {
            IsFrameworkPack();

            Assert.Empty(_reader.GetFiles("ref"));
            Assert.NotEmpty(_reader.GetFiles("runtimes"));
            Assert.Empty(_reader.GetFiles("lib"));
        }

        private void ContainsFrameworkList(string name)
        {
            XDocument frameworkList = ReadEntryXDocument(
                _reader.GetEntry($"data/{name}"));

            XElement[] frameworkListFiles = frameworkList
                .Element("FileList")
                .Elements("File")
                .ToArray();

            // Sanity: check if the list has some content.
            Assert.NotEmpty(frameworkListFiles);
        }

        private static string ReadEntryContent(ZipArchiveEntry entry)
        {
            using (var reader = new StreamReader(entry.Open()))
            {
                return reader.ReadToEnd();
            }
        }

        private static XDocument ReadEntryXDocument(ZipArchiveEntry entry)
        {
            return XDocument.Parse(ReadEntryContent(entry));
        }
    }
}


text:
package com.sun.corba.se.PortableActivationIDL;

/**
* com/sun/corba/se/PortableActivationIDL/ServerHeldDown.java .
* Generated by the IDL-to-Java compiler (portable), version "3.2"
* from c:/re/workspace/8-2-build-windows-amd64-cygwin/jdk8u72/5732/corba/src/share/classes/com/sun/corba/se/PortableActivationIDL/activation.idl
* Tuesday, December 22, 2015 7:17:37 PM PST
*/

public final class ServerHeldDown extends org.omg.CORBA.UserException
{
  public String serverId = null;

  public ServerHeldDown ()
  {
    super(ServerHeldDownHelper.id());
  } // ctor

  public ServerHeldDown (String _serverId)
  {
    super(ServerHeldDownHelper.id());
    serverId = _serverId;
  } // ctor

  public ServerHeldDown (String $reason, String _serverId)
  {
    super(ServerHeldDownHelper.id() + "  " + $reason);
    serverId = _serverId;
  } // ctor

} // class ServerHeldDown

redpajama_set_name: RedPajamaGithub


text:
/* ------------------------------------------------------------------------- */
/*
 *  unix/thread.h
 *
 *  Copyright (c) 2004 - 2008, clown. All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    - Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    - Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *    - No names of its contributors may be used to endorse or promote
 *      products derived from this software without specific prior written
 *      permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  Distributed under the Boost Software License, Version 1.0. (See
 *  accompanying file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 *
 *  Last-modified: Sat 25 Oct 2008 05:23:00 JST
 */
/* ------------------------------------------------------------------------- */
#ifndef CLX_UNIX_THREAD_H
#define CLX_UNIX_THREAD_H

#include <pthread.h>
#include "thread_data.h"
#include "mutex.h"
#include "condition.h"
#include "system_error.h"

namespace clx {
	/* --------------------------------------------------------------------- */
	//  thread_proxy
	/* --------------------------------------------------------------------- */
	inline void* thread_proxy(void* param) {
		detail::thread_data* dat = (detail::thread_data*)param;

		{
			mutex::scoped_lock lock(dat->data_mutex);
			if (dat->joined) pthread_detach(dat->handle);
		}

		dat->run();
		return NULL;
	}

	/* --------------------------------------------------------------------- */
	//  thread
	/* --------------------------------------------------------------------- */
	class thread {
	public:
		typedef pthread_t handle_type;
		typedef handle_type* handle_pointer;
		typedef handle_type handle_id_type;

		thread() : data_() {}

		template <class Functor>
		explicit thread(Functor f, bool detached = false) :
			data_(new inherit_data<Functor>(f)) {
			data_->joined = detached;
			this->start();
		}

		virtual ~thread() throw() { this->detach(); }

		template <class Functor>
		void start(Functor f, bool detached = false) {
			data_ = detail::thread_data_ptr(new inherit_data<Functor>(f));
			data_->joined = detached;
			this->start();
		}

		bool joinable() const { return !data_->joined; }

		void join() {
			if (this->joinable()) {
				pthread_join(data_->handle, NULL);
			}
		}

		void detach() {
			if (this->joinable()) pthread_detach(data_->handle);
			data_->joined = true;
		}

		void sleep(double sec) {
			clx::timer t;
			for (int foo = 0; foo < 5; ++foo) {
				mutex mx;
				mutex::scoped_lock lock(mx);
				condition cond;
				cond.timed_wait(lock, sec - t.total_elapsed());
				if (t.total_elapsed() > sec) return;
			}
		}

		handle_id_type get_id() const { return pthread_self(); }

	private:
		template <class F>
		class inherit_data : public detail::thread_data {
		public:
			inherit_data(F f) : f_(f) {}
			void run() { f_(); }
		private:
			F f_;
		};

		detail::thread_data_ptr data_;

		// non-copyable
		thread(const thread& cp);
		thread& operator=(const thread& cp);

		void start() {
			int const res = pthread_create(&data_->handle, NULL, thread_proxy, data_.get());
			if (res) throw system_error("pthread_create");
		}
	};
}

#endif // CLX_UNIX_THREAD_H


text:
const gulp = require('gulp');
const uglifyJS = require('gulp-uglify');
const uglifyCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const rollup = require('rollup-stream');
const source = require('vinyl-source-stream');

// custom logger to avoid using gulp-plumber
function logError(err) {
  console.error.bind(err);
}

gulp.task('scripts', () => {
  rollup({
      entry: './src/js/app.js'
  })
  .pipe(source('app.js'))
  .pipe(rename({ suffix: '.min' }))
  .pipe(gulp.dest('./public/js/'));
});

gulp.task('styles', () => {
  gulp.src('./src/css/main.css')
    .pipe(uglifyCSS())
    .pipe(rename({ suffix: '.min' }))
    .pipe(gulp.dest('public/css/'));
});

gulp.task('watch', () => {
  gulp.watch('src/js/**/*.js', ['scripts']);
  gulp.watch('src/css/**/*.css', ['styles']);
});

gulp.task('default', ['scripts', 'styles', 'watch'], () => {});
gulp.task('build', ['scripts', 'styles'], () => {});


text:
import functools
import fnmatch
import json
import itertools
import os

from botocore.paginate import Paginator

from c7n.query import QueryResourceManager, ChildResourceManager, TypeInfo, RetryPageIterator
from c7n.manager import resources
from c7n.utils import chunks, get_retry, generate_arn, local_session, type_schema
from c7n.actions import BaseAction
from c7n.filters import Filter

from c7n.resources.shield import IsShieldProtected, SetShieldProtection
from c7n.tags import RemoveTag, Tag

class Route53Base:

    permissions = ('route53:ListTagsForResources',)
    retry = staticmethod(get_retry(('Throttled',)))

    @property
    def generate_arn(self):
        if self._generate_arn is None:
            self._generate_arn = functools.partial(
                generate_arn,
                self.get_model().service,
                resource_type=self.get_model().arn_type)
        return self._generate_arn

    def get_arn(self, r):
        return self.generate_arn(r[self.get_model().id].split("/")[-1])

    def augment(self, resources):
        _describe_route53_tags(
            self.get_model(), resources, self.session_factory,
            self.executor_factory, self.retry)
        return resources

def _describe_route53_tags(
        model, resources, session_factory, executor_factory, retry):

    def process_tags(resources):
        client = local_session(session_factory).client('route53')
        resource_map = {}
        for r in resources:
            k = r[model.id]
            if "hostedzone" in k:
                k = k.split("/")[-1]
            resource_map[k] = r

        for resource_batch in chunks(list(resource_map.keys()), 10):
            results = retry(
                client.list_tags_for_resources,
                ResourceType=model.arn_type,
                ResourceIds=resource_batch)
            for resource_tag_set in results['ResourceTagSets']:
                if ('ResourceId' in resource_tag_set and
                        resource_tag_set['ResourceId'] in resource_map):
                    resource_map[resource_tag_set['ResourceId']]['Tags'] = resource_tag_set['Tags']

    with executor_factory(max_workers=2) as w:
        return list(w.map(process_tags, chunks(resources, 20)))

@resources.register('hostedzone')
class HostedZone(Route53Base, QueryResourceManager):

    class resource_type(TypeInfo):
        service = 'route53'
        arn_type = 'hostedzone'
        enum_spec = ('list_hosted_zones', 'HostedZones', None)
        # detail_spec = ('get_hosted_zone', 'Id', 'Id', None)
        id = 'Id'
        name = 'Name'
        universal_taggable = True
        # Denotes this resource type exists across regions
        global_resource = True
        cfn_type = 'AWS::Route53::HostedZone'

    def get_arns(self, resource_set):
        arns = []
        for r in resource_set:
            _id = r[self.get_model().id].split("/")[-1]
            arns.append(self.generate_arn(_id))
        return arns

HostedZone.filter_registry.register('shield-enabled', IsShieldProtected)
HostedZone.action_registry.register('set-shield', SetShieldProtection)

@resources.register('healthcheck')
class HealthCheck(Route53Base, QueryResourceManager):

    class resource_type(TypeInfo):
        service = 'route53'
        arn_type = 'healthcheck'
        enum_spec = ('list_health_checks', 'HealthChecks', None)
        name = id = 'Id'
        universal_taggable = True
        cfn_type = 'AWS::Route53::HealthCheck'

@resources.register('rrset')
class ResourceRecordSet(ChildResourceManager):

    class resource_type(TypeInfo):
        service = 'route53'
        arn_type = 'rrset'
        parent_spec = ('hostedzone', 'HostedZoneId', True)
        enum_spec = ('list_resource_record_sets', 'ResourceRecordSets', None)
        name = id = 'Name'
        cfn_type = 'AWS::Route53::RecordSet'

@resources.register('r53domain')
class Route53Domain(QueryResourceManager):

    class resource_type(TypeInfo):
        service = 'route53domains'
        arn_type = 'r53domain'
        enum_spec = ('list_domains', 'Domains', None)
        name = id = 'DomainName'
        global_resource = True

    permissions = ('route53domains:ListTagsForDomain',)

    def augment(self, domains):
        client = local_session(self.session_factory).client('route53domains')
        for d in domains:
            d['Tags'] = self.retry(
                client.list_tags_for_domain,
                DomainName=d['DomainName'])['TagList']
        return domains

@Route53Domain.action_registry.register('tag')
class Route53DomainAddTag(Tag):
    """Adds tags to a route53 domain

    :example:

    .. code-block:: yaml

        policies:
          - name: route53-tag
            resource: r53domain
            filters:
              - "tag:DesiredTag": absent
            actions:
              - type: tag
                key: DesiredTag
                value: DesiredValue
    """
    permissions = ('route53domains:UpdateTagsForDomain',)

    def process_resource_set(self, client, domains, tags):
        mid = self.manager.resource_type.id
        for d in domains:
            client.update_tags_for_domain(
                DomainName=d[mid],
                TagsToUpdate=tags)

@Route53Domain.action_registry.register('remove-tag')
class Route53DomainRemoveTag(RemoveTag):
    """Remove tags from a route53 domain

    :example:

    .. code-block:: yaml

        policies:
          - name: route53-expired-tag
            resource: r53domain
            filters:
              - "tag:ExpiredTag": present
            actions:
              - type: remove-tag
                tags: ['ExpiredTag']
    """
    permissions = ('route53domains:DeleteTagsForDomain',)

    def process_resource_set(self, client, domains, keys):
        for d in domains:
            client.delete_tags_for_domain(
                DomainName=d[self.id_key],
                TagsToDelete=keys)

@HostedZone.action_registry.register('delete')
class Delete(BaseAction):
    """Action to delete Route 53 hosted zones.

    It is recommended to use a filter to avoid unwanted deletion of R53 hosted zones.

    If set to force this action will wipe out all records in the hosted zone
    before deleting the zone.

    :example:

    .. code-block:: yaml

            policies:
              - name: route53-delete-testing-hosted-zones
                resource: aws.hostedzone
                filters:
                  - 'tag:TestTag': present
                actions:
                  - type: delete
                    force: true

    """

    schema = type_schema('delete', force={'type': 'boolean'})
    permissions = ('route53:DeleteHostedZone',)

    def process(self, hosted_zones):
        client = local_session(self.manager.session_factory).client('route53')
        error = None
        for hz in hosted_zones:
            if self.data.get('force'):
                self.delete_records(client, hz)
            try:
                self.manager.retry(
                    client.delete_hosted_zone,
                    Id=hz['Id'],
                    ignore_err_codes=('NoSuchHostedZone'))
            except client.exceptions.HostedZoneNotEmpty as e:
                self.log.warning(
                    "HostedZone: %s cannot be deleted, "
                    "set force to remove all records in zone",
                    hz['Name'])
                error = e
        if error:
            raise error

    def delete_records(self, client, hz):
        paginator = client.get_paginator('list_resource_record_sets')
        paginator.PAGE_ITERATOR_CLS = RetryPageIterator
        rrsets = paginator.paginate(HostedZoneId=hz['Id']).build_full_result()

        for rrset in rrsets['ResourceRecordSets']:
            # Trigger the deletion of all the resource record sets before deleting
            # the hosted zone

            # Exempt the two zone associated mandatory records
            if rrset['Name'] == hz['Name'] and rrset['Type'] in ('NS', 'SOA'):
                continue
            self.manager.retry(
                client.change_resource_record_sets,
                HostedZoneId=hz['Id'],
                ChangeBatch={
                    'Changes': [
                        {
                            'Action': 'DELETE',
                            'ResourceRecordSet': {
                                'Name': rrset['Name'],
                                'Type': rrset['Type'],
                                'TTL': rrset['TTL'],
                                'ResourceRecords': rrset['ResourceRecords']
                            },
                        }
                    ]
                },
                ignore_err_codes=('InvalidChangeBatch'))

@HostedZone.action_registry.register('set-query-logging')
class SetQueryLogging(BaseAction):
    """Enables query logging on a hosted zone.

    By default this enables a log group per route53 domain, alternatively
    a log group name can be specified for a unified log across domains.

    Note this only applicable to public route53 domains, and log groups
    must be created in us-east-1 region.

    This action can optionally setup the resource permissions needed for
    route53 to log to cloud watch logs via `set-permissions: true`, else
    the cloud watch logs resource policy would need to be set separately.

    Its recommended to use a separate custodian policy on the log
    groups to set the log retention period for the zone logs. See
    `custodian schema aws.log-group.actions.set-retention`

    :example:

    .. code-block:: yaml

        policies:
          - name: enablednsquerylogging
            resource: hostedzone
            region: us-east-1
            filters:
              - type: query-logging-enabled
                state: false
            actions:
              - type: set-query-logging
                state: true

    """

    permissions = (
        'route53:GetQueryLoggingConfig',
        'route53:CreateQueryLoggingConfig',
        'route53:DeleteQueryLoggingConfig',
        'logs:DescribeLogGroups',
        'logs:CreateLogGroup',
        'logs:GetResourcePolicy',
        'logs:PutResourcePolicy')

    schema = type_schema(
        'set-query-logging', **{
            'set-permissions': {'type': 'boolean'},
            'log-group-prefix': {'type': 'string', 'default': '/aws/route53'},
            'log-group': {'type': 'string', 'default': 'auto'},
            'state': {'type': 'boolean'}})

    statement = {
        "Sid": "Route53LogsToCloudWatchLogs",
        "Effect": "Allow",
        "Principal": {"Service": ["route53.amazonaws.com"]},
        "Action": ["logs:PutLogEvents", "logs:CreateLogStream"],
        "Resource": None}

    def validate(self):
        if not self.data.get('state', True):
            # By forcing use of a filter we ensure both getting to right set of
            # resources as well avoiding an extra api call here, as we'll reuse
            # the annotation from the filter for logging config.
            if not [f for f in self.manager.iter_filters() if isinstance(
                    f, IsQueryLoggingEnabled)]:
                raise ValueError(
                    "set-query-logging when deleting requires "
                    "use of query-logging-enabled filter in policy")
        return self

    def get_permissions(self):
        perms = []
        if self.data.get('set-permissions'):
            perms.extend(('logs:GetResourcePolicy', 'logs:PutResourcePolicy'))
        if self.data.get('state', True):
            perms.append('route53:CreateQueryLoggingConfig')
            perms.append('logs:CreateLogGroup')
            perms.append('logs:DescribeLogGroups')
            perms.append('tag:GetResources')
        else:
            perms.append('route53:DeleteQueryLoggingConfig')
        return perms

    def process(self, resources):
        if self.manager.config.region != 'us-east-1':
            self.log.warning("set-query-logging should be only be performed region: us-east-1")

        client = local_session(self.manager.session_factory).client('route53')
        state = self.data.get('state', True)

        zone_log_names = {z['Id']: self.get_zone_log_name(z) for z in resources}
        if state:
            self.ensure_log_groups(set(zone_log_names.values()))

        for r in resources:
            if not state:
                try:
                    client.delete_query_logging_config(Id=r['c7n:log-config']['Id'])
                except client.exceptions.NoSuchQueryLoggingConfig:
                    pass
                continue
            log_arn = "arn:aws:logs:us-east-1:{}:log-group:{}".format(
                self.manager.account_id, zone_log_names[r['Id']])
            client.create_query_logging_config(
                HostedZoneId=r['Id'],
                CloudWatchLogsLogGroupArn=log_arn)

    def get_zone_log_name(self, zone):
        if self.data.get('log-group', 'auto') == 'auto':
            log_group_name = "%s/%s" % (
                self.data.get('log-group-prefix', '/aws/route53').rstrip('/'),
                zone['Name'][:-1])
        else:
            log_group_name = self.data['log-group']
        return log_group_name

    def ensure_log_groups(self, group_names):
        log_manager = self.manager.get_resource_manager('log-group')
        log_manager.config = self.manager.config.copy(region='us-east-1')

        if len(group_names) == 1:
            groups = []
            if log_manager.get_resources(list(group_names), augment=False):
                groups = [{'logGroupName': g} for g in group_names]
        else:
            common_prefix = os.path.commonprefix(list(group_names))
            if common_prefix not in ('', '/'):
                groups = log_manager.get_resources(
                    [common_prefix], augment=False)
            else:
                groups = list(itertools.chain(*[
                    log_manager.get_resources([g]) for g in group_names]))

        missing = group_names.difference({g['logGroupName'] for g in groups})

        # Logs groups must be created in us-east-1 for route53.
        client = local_session(
            self.manager.session_factory).client('logs', region_name='us-east-1')

        for g in missing:
            client.create_log_group(logGroupName=g)

        if self.data.get('set-permissions', False):
            self.ensure_route53_permissions(client, group_names)

    def ensure_route53_permissions(self, client, group_names):
        if self.check_route53_permissions(client, group_names):
            return
        if self.data.get('log-group', 'auto') != 'auto':
            p_resource = "arn:aws:logs:us-east-1:{}:log-group:{}:*".format(
                self.manager.account_id, self.data['log-group'])
        else:
            p_resource = "arn:aws:logs:us-east-1:{}:log-group:{}/*".format(
                self.manager.account_id,
                self.data.get('log-group-prefix', '/aws/route53').rstrip('/'))

        statement = dict(self.statement)
        statement['Resource'] = p_resource

        client.put_resource_policy(
            policyName='Route53LogWrites',
            policyDocument=json.dumps(
                {"Version": "2012-10-17", "Statement": [statement]}))

    def check_route53_permissions(self, client, group_names):
        group_names = set(group_names)
        for p in client.describe_resource_policies().get('resourcePolicies', []):
            for s in json.loads(p['policyDocument']).get('Statement', []):
                if (s['Effect'] == 'Allow' and
                        s['Principal'].get('Service', ['']) == "route53.amazonaws.com"):
                    group_names.difference_update(
                        fnmatch.filter(group_names, s['Resource'].rsplit(':', 1)[-1]))
                    if not group_names:
                        return True
        return not bool(group_names)

def get_logging_config_paginator(client):
    return Paginator(
        client.list_query_logging_configs,
        {'input_token': 'NextToken', 'output_token': 'NextToken',
         'result_key': 'QueryLoggingConfigs'},
        client.meta.service_model.operation_model('ListQueryLoggingConfigs'))

@HostedZone.filter_registry.register('query-logging-enabled')
class IsQueryLoggingEnabled(Filter):

    permissions = ('route53:GetQueryLoggingConfig', 'route53:GetHostedZone')
    schema = type_schema('query-logging-enabled', state={'type': 'boolean'})

    def process(self, resources, event=None):
        client = local_session(self.manager.session_factory).client('route53')
        state = self.data.get('state', False)
        results = []

        enabled_zones = {
            c['HostedZoneId']: c for c in
            get_logging_config_paginator(
                client).paginate().build_full_result().get(
                    'QueryLoggingConfigs', ())}
        for r in resources:
            zid = r['Id'].split('/', 2)[-1]
            # query logging is only supported for Public Hosted Zones.
            if r['Config']['PrivateZone'] is True:
                continue
            logging = zid in enabled_zones
            if logging and state:
                r['c7n:log-config'] = enabled_zones[zid]
                results.append(r)
            elif not logging and not state:
                results.append(r)
        return results


text:
class ArticleReport < BaseReport
	include Datagrid
	scope do
		Article.order("articles.created_at desc")
	end

	filter(:title, :string) {|value| where("title ilike '%#{value}%'")}
	filter(:content, :string) {|value| where("content ilike '%#{value}%'")}
	#date_range_filters(:updated_at)

	column(:actions, :html => true) { |article| render :partial => "/shared/check_box",:locals => { :s => article }}
	column(:title, :html => true ) { |article| can?(:update, Article) ? link_to(article.title, edit_article_path(article)) : article.title }
	column(:content)
	column(:created_at)
	column(:updated_at)
	column(:published, :html => true) { |asset| asset.published? ? "  #{image_tag('checked.png')} " : "  #{image_tag('checkbox.png')} " }
end


text:
/* Includes ------------------------------------------------------------------*/
#include "usbh_usr.h"
#include "stm32f4xx_it.h"
#include "stm32f4xx_conf.h"

/** @addtogroup STM32F4-Discovery_Audio_Player_Recorder
 * @{
 */

/* External variables --------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint8_t Command_index = 0;
/*  Points to the DEVICE_PROP structure of current device */
/*  The purpose of this register is to speed up the execution */
FATFS fatfs;
FIL fileR;
DIR dir;
FILINFO fno;

extern volatile int enum_done;

USBH_Usr_cb_TypeDef USR_Callbacks =
{
		USBH_USR_Init,
		USBH_USR_DeInit,
		USBH_USR_DeviceAttached,
		USBH_USR_ResetDevice,
		USBH_USR_DeviceDisconnected,
		USBH_USR_OverCurrentDetected,
		USBH_USR_DeviceSpeedDetected,
		USBH_USR_Device_DescAvailable,
		USBH_USR_DeviceAddressAssigned,
		USBH_USR_Configuration_DescAvailable,
		USBH_USR_Manufacturer_String,
		USBH_USR_Product_String,
		USBH_USR_SerialNum_String,
		USBH_USR_EnumerationDone,
		USBH_USR_UserInput,
		USBH_USR_MSC_Application,
		USBH_USR_DeviceNotSupported,
		USBH_USR_UnrecoveredError
};

/**
 * @brief  USBH_USR_Init
 * @param  None
 * @retval None
 */
void USBH_USR_Init(void)
{
}

/**
 * @brief  USBH_USR_DeviceAttached
 * @param  None
 * @retval None
 */
void USBH_USR_DeviceAttached(void)
{
	GPIO_SetBits(GPIOD, GPIO_Pin_14);
}

/**
 * @brief  USBH_USR_UnrecoveredError
 * @param  None
 * @retval None
 */
void USBH_USR_UnrecoveredError (void)
{
}

/**
 * @brief  USBH_DisconnectEvent
 *         Device disconnect event
 * @param  None
 * @retval Staus
 */
void USBH_USR_DeviceDisconnected (void)
{
	GPIO_ResetBits(GPIOD, GPIO_Pin_14);
	GPIO_ResetBits(GPIOD, GPIO_Pin_12);
	enum_done = 0;
}

/**
 * @brief  USBH_USR_ResetUSBDevice
 * @param  None
 * @retval None
 */
void USBH_USR_ResetDevice(void)
{
	/* callback for USB-Reset */
}

/**
 * @brief  USBH_USR_DeviceSpeedDetected
 *         Displays the message on LCD for device speed
 * @param  Device speed:
 * @retval None
 */
void USBH_USR_DeviceSpeedDetected(uint8_t DeviceSpeed)
{
}

/**
 * @brief  USBH_USR_Device_DescAvailable
 * @param  device descriptor
 * @retval None
 */
void USBH_USR_Device_DescAvailable(void *DeviceDesc)
{
	/* callback for device descriptor */
}

/**
 * @brief  USBH_USR_DeviceAddressAssigned
 *         USB device is successfully assigned the Address
 * @param  None
 * @retval None
 */
void USBH_USR_DeviceAddressAssigned(void)
{
	/* callback for device successfully assigned the Address */
}

/**
 * @brief  USBH_USR_Conf_Desc
 * @param  Configuration descriptor
 * @retval None
 */
void USBH_USR_Configuration_DescAvailable(USBH_CfgDesc_TypeDef * cfgDesc,
		USBH_InterfaceDesc_TypeDef *itfDesc,
		USBH_EpDesc_TypeDef *epDesc)
{
	/* callback for configuration descriptor */
}

/**
 * @brief  USBH_USR_Manufacturer_String
 * @param  Manufacturer String
 * @retval None
 */
void USBH_USR_Manufacturer_String(void *ManufacturerString)
{
	/* callback for  Manufacturer String */
}

/**
 * @brief  USBH_USR_Product_String
 * @param  Product String
 * @retval None
 */
void USBH_USR_Product_String(void *ProductString)
{
	/* callback for Product String */
}

/**
 * @brief  USBH_USR_SerialNum_String
 * @param  SerialNum_String
 * @retval None
 */
void USBH_USR_SerialNum_String(void *SerialNumString)
{
	/* callback for SerialNum_String */
}

/**
 * @brief  EnumerationDone
 *         User response request is displayed to ask application jump to class
 * @param  None
 * @retval None
 */
void USBH_USR_EnumerationDone(void)
{
	/* 0.5 seconds delay */
	USB_OTG_BSP_mDelay(500);
	USBH_USR_MSC_Application();
}

/**
 * @brief  USBH_USR_DeviceNotSupported
 *         Device is not supported
 * @param  None
 * @retval None
 */
void USBH_USR_DeviceNotSupported(void)
{
}

/**
 * @brief  USBH_USR_UserInput
 *         User Action for application state entry
 * @param  None
 * @retval USBH_USR_Status : User response for key button
 */
USBH_USR_Status USBH_USR_UserInput(void)
{
	/* callback for Key botton: set by software in this case */
	return USBH_USR_RESP_OK;
}

/**
 * @brief  USBH_USR_OverCurrentDetected
 *         Over Current Detected on VBUS
 * @param  None
 * @retval None
 */
void USBH_USR_OverCurrentDetected (void)
{
}

/**
 * @brief  USBH_USR_MSC_Application
 * @param  None
 * @retval Staus
 */
int USBH_USR_MSC_Application(void)
{
	if (f_mount( 0, &fatfs ) != FR_OK )
	{
		/* efs initialisation fails*/
		return(-1);
	}

	enum_done++;
	GPIO_SetBits(GPIOD, GPIO_Pin_12);
	return(0);
}

/**
 * @brief  USBH_USR_DeInit
 *         Deint User state and associated variables
 * @param  None
 * @retval None
 */
void USBH_USR_DeInit(void)
{

}

/**
 * @}
 */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/


text:
from __future__ import absolute_import
from __future__ import division

from typing import Any, Callable, List, Optional, Sequence, TypeVar, Iterable, Set, Tuple, Text
from six import binary_type
import base64
import errno
import hashlib
import heapq
import itertools
import os
import sys
from time import sleep

from django.conf import settings
from django.http import HttpRequest
from six.moves import range, map, zip_longest
from zerver.lib.str_utils import force_text

T = TypeVar('T')

def statsd_key(val, clean_periods=False):
    # type: (Any, bool) -> str
    if not isinstance(val, str):
        val = str(val)

    if ':' in val:
        val = val.split(':')[0]
    val = val.replace('-', "_")
    if clean_periods:
        val = val.replace('.', '_')

    return val

class StatsDWrapper(object):
    """Transparently either submit metrics to statsd
    or do nothing without erroring out"""

    # Backported support for gauge deltas
    # as our statsd server supports them but supporting
    # pystatsd is not released yet
    def _our_gauge(self, stat, value, rate=1, delta=False):
            # type: (str, float, float, bool) -> None
            """Set a gauge value."""
            from django_statsd.clients import statsd
            if delta:
                value_str = '%+g|g' % (value,)
            else:
                value_str = '%g|g' % (value,)
            statsd._send(stat, value_str, rate)

    def __getattr__(self, name):
        # type: (str) -> Any
        # Hand off to statsd if we have it enabled
        # otherwise do nothing
        if name in ['timer', 'timing', 'incr', 'decr', 'gauge']:
            if settings.STATSD_HOST != '':
                from django_statsd.clients import statsd
                if name == 'gauge':
                    return self._our_gauge
                else:
                    return getattr(statsd, name)
            else:
                return lambda *args, **kwargs: None

        raise AttributeError

statsd = StatsDWrapper()

# Runs the callback with slices of all_list of a given batch_size
def run_in_batches(all_list, batch_size, callback, sleep_time = 0, logger = None):
    # type: (Sequence[T], int, Callable[[Sequence[T]], None], int, Optional[Callable[[str], None]]) ->  None
    if len(all_list) == 0:
        return

    limit = (len(all_list) // batch_size) + 1
    for i in range(limit):
        start = i*batch_size
        end = (i+1) * batch_size
        if end >= len(all_list):
            end = len(all_list)
        batch = all_list[start:end]

        if logger:
            logger("Executing %s in batch %s of %s" % (end-start, i+1, limit))

        callback(batch)

        if i != limit - 1:
            sleep(sleep_time)

def make_safe_digest(string, hash_func=hashlib.sha1):
    # type: (Text, Callable[[binary_type], Any]) -> Text
    """
    return a hex digest of `string`.
    """
    # hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must
    # be encoded.
    return force_text(hash_func(string.encode('utf-8')).hexdigest())

def log_statsd_event(name):
    # type: (str) -> None
    """
    Sends a single event to statsd with the desired name and the current timestamp

    This can be used to provide vertical lines in generated graphs,
    for example when doing a prod deploy, bankruptcy request, or
    other one-off events

    Note that to draw this event as a vertical line in graphite
    you can use the drawAsInfinite() command
    """
    event_name = "events.%s" % (name,)
    statsd.incr(event_name)

def generate_random_token(length):
    # type: (int) -> Text
    return base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower()

def mkdir_p(path):
    # type: (str) -> None
    # Python doesn't have an analog to `mkdir -p` < Python 3.2.
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise

def query_chunker(queries, id_collector=None, chunk_size=1000, db_chunk_size=None):
    # type: (List[Any], Set[int], int, int) -> Iterable[Any]
    '''
    This merges one or more Django ascending-id queries into
    a generator that returns chunks of chunk_size row objects
    during each yield, preserving id order across all results..

    Queries should satisfy these conditions:
        - They should be Django filters.
        - They should return Django objects with "id" attributes.
        - They should be disjoint.

    The generator also populates id_collector, which we use
    internally to enforce unique ids, but which the caller
    can pass in to us if they want the side effect of collecting
    all ids.
    '''
    if db_chunk_size is None:
        db_chunk_size = chunk_size // len(queries)

    assert db_chunk_size >= 2
    assert chunk_size >= 2

    if id_collector is not None:
        assert(len(id_collector) == 0)
    else:
        id_collector = set()

    def chunkify(q, i):
        # type: (Any, int) -> Iterable[Tuple[int, int, Any]]
        q = q.order_by('id')
        min_id = -1
        while True:
            rows = list(q.filter(id__gt=min_id)[0:db_chunk_size])
            if len(rows) == 0:
                break
            for row in rows:
                yield (row.id, i, row)
            min_id = rows[-1].id

    iterators = [chunkify(q, i) for i, q in enumerate(queries)]
    merged_query = heapq.merge(*iterators)

    while True:
        tup_chunk = list(itertools.islice(merged_query, 0, chunk_size))
        if len(tup_chunk) == 0:
            break

        # Do duplicate-id management here.
        tup_ids = set([tup[0] for tup in tup_chunk])
        assert len(tup_ids) == len(tup_chunk)
        assert len(tup_ids.intersection(id_collector)) == 0
        id_collector.update(tup_ids)

        yield [row for row_id, i, row in tup_chunk]

def _extract_subdomain(request):
    # type: (HttpRequest) -> Text
    domain = request.get_host().lower()
    index = domain.find("." + settings.EXTERNAL_HOST)
    if index == -1:
        return ""
    return domain[0:index]

def get_subdomain(request):
    # type: (HttpRequest) -> Text
    subdomain = _extract_subdomain(request)
    if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:
        return ""
    return subdomain

def is_subdomain_root_or_alias(request):
    # type: (HttpRequest) -> bool
    subdomain = _extract_subdomain(request)
    return not subdomain or subdomain in settings.ROOT_SUBDOMAIN_ALIASES

def check_subdomain(realm_subdomain, user_subdomain):
    # type: (Text, Text) -> bool
    if settings.REALMS_HAVE_SUBDOMAINS and realm_subdomain is not None:
        if (realm_subdomain == "" and user_subdomain is None):
            return True
        if realm_subdomain != user_subdomain:
            return False
    return True

def split_by(array, group_size, filler):
    # type: (List[Any], int, Any) -> List[List[Any]]
    """
    Group elements into list of size `group_size` and fill empty cells with
    `filler`. Recipe from https://docs.python.org/3/library/itertools.html
    """
    args = [iter(array)] * group_size
    return list(map(list, zip_longest(*args, fillvalue=filler)))


text:
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace DriveProxy.Utils
{
  public abstract class Pipe : IDisposable
  {
    protected IntPtr _handle = IntPtr.Zero;
    protected bool _isConnected = false;
    protected FileAccess _mode;

    protected string _name;
    protected TimeSpan readTimeout = new TimeSpan(0, 0, 30);

    protected Pipe(string name, FileAccess mode, IntPtr handle)
    {
      _name = name;
      _handle = handle;
      _mode = mode;
    }

    public IntPtr Handle
    {
      get { return _handle; }
      set { _handle = value; }
    }

    public string Name
    {
      get { return _name; }
    }

    public FileAccess Mode
    {
      get { return _mode; }
    }

    public TimeSpan ReadTimeout
    {
      get { return readTimeout; }
      set { readTimeout = value; }
    }

    public bool IsCreated
    {
      get
      {
        if (_handle != IntPtr.Zero)
        {
          return true;
        }

        return false;
      }
    }

    public bool IsConnected
    {
      get { return _isConnected; }
    }

    public bool CanRead
    {
      get
      {
        if (Mode == FileAccess.Read ||
            Mode == FileAccess.ReadWrite)
        {
          return true;
        }

        return false;
      }
    }

    public bool CanWrite
    {
      get
      {
        if (Mode == FileAccess.Write ||
            Mode == FileAccess.ReadWrite)
        {
          return true;
        }

        return false;
      }
    }

    public virtual void Dispose()
    {
      try
      {
        Close();
      }
      catch (Exception exception)
      {
        Log.Error(exception);
      }
    }

    public int Peek()
    {
      try
      {
        int bytesRead = 0;
        int bytesAvail = 0;
        int bytesLeft = 0;

        if (!Peek(ref bytesRead, ref bytesAvail, ref bytesLeft))
        {
          return 0;
        }

        return bytesAvail;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return 0;
      }
    }

    public bool Peek(ref int bytesRead, ref int bytesAvail, ref int bytesLeft)
    {
      try
      {
        if (_handle == IntPtr.Zero)
        {
          throw new Exception("The pipe has been closed.");
        }

        if (!CanRead)
        {
          throw new Exception("The pipe is not configured for reading.");
        }

        uint bytesRead2 = 0;
        uint bytesAvail2 = 0;
        uint bytesLeft2 = 0;

        if (!Win32.PeekNamedPipe(_handle, null, 0, ref bytesRead2, ref bytesAvail2, ref bytesLeft2))
        {
          int err = Marshal.GetLastWin32Error();

          throw new Exception(string.Format("Pipe.Peek failed, win32 error code {0}, pipe name '{1}' ", err, Name));
        }

        if (bytesRead2 > int.MaxValue)
        {
          bytesRead2 = int.MaxValue;
        }

        if (bytesAvail > int.MaxValue)
        {
          bytesAvail = int.MaxValue;
        }

        if (bytesLeft > int.MaxValue)
        {
          bytesLeft = int.MaxValue;
        }

        bytesRead = (int)bytesRead2;
        bytesAvail = (int)bytesAvail2;
        bytesLeft = (int)bytesLeft2;

        if (bytesAvail > 0)
        {
          return true;
        }

        return false;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return false;
      }
    }

    public byte[] Read()
    {
      try
      {
        return Read(0);
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return null;
      }
    }

    public byte[] Read(int bufferSize)
    {
      try
      {
        int bytesAvail = 0;
        double waitInMilliseconds = ReadTimeout.TotalMilliseconds;
        double waited = 0;

        while (true)
        {
          bytesAvail = Peek();

          if (bytesAvail >= bufferSize)
          {
            break;
          }
          int sleep = 10;

          if (waitInMilliseconds > 50)
          {
            sleep = 50;
          }

          System.Threading.Thread.Sleep(sleep);

          waited += sleep;
        }

        if (bufferSize > 0)
        {
          bytesAvail = bufferSize;
        }

        var bytes = new byte[bytesAvail];

        int bytesRead = Read(bytes);

        if (bytesRead < bytes.Length)
        {
          throw new Exception("Read data is less than requested.");
        }

        return bytes;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return null;
      }
    }

    public int Read(byte[] buffer)
    {
      try
      {
        return Read(buffer, 0, buffer.Length);
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return 0;
      }
    }

    public int Read(byte[] buffer, int offset, int count)
    {
      try
      {
        if (_handle == IntPtr.Zero)
        {
          throw new Exception("The pipe has been closed.");
        }

        if (!CanRead)
        {
          throw new Exception("The pipe is not configured for reading.");
        }

        if (buffer == null)
        {
          throw new Exception("The pipe buffer for reading is null.");
        }

        if (offset < 0)
        {
          throw new Exception("The pipe buffer for reading offset is less than zero.");
        }

        if (count < 0)
        {
          throw new Exception("The pipe buffer for reading count is less than zero.");
        }

        if (buffer.Length < (offset + count))
        {
          throw new Exception("The pipe buffer for reading is not large enough to hold requested data.");
        }

        byte[] buf = buffer;

        if (offset != 0)
        {
          buf = new byte[count];
        }

        uint read = 0;

        if (!Win32.ReadFile(_handle, buf, (uint)count, ref read, IntPtr.Zero))
        {
          int err = Marshal.GetLastWin32Error();

          throw new Exception(string.Format("Pipe.Read failed, win32 error code {0}, pipe name '{1}' ", err, Name));
        }

        if (offset != 0)
        {
          for (int x = 0; x < read; x++)
          {
            buffer[offset + x] = buf[x];
          }
        }

        return (int)read;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return 0;
      }
    }

    public int Write(byte[] buffer)
    {
      try
      {
        return Write(buffer, 0, buffer.Length);
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return 0;
      }
    }

    public int Write(byte[] buffer, int offset, int count)
    {
      try
      {
        if (_handle == IntPtr.Zero)
        {
          throw new Exception("The pipe has been closed.");
        }

        if (!CanWrite)
        {
          throw new Exception("The pipe is not configured for writing.");
        }

        if (buffer == null)
        {
          throw new Exception("The pipe buffer for writing is null.");
        }

        if (offset < 0)
        {
          throw new Exception("The pipe buffer for writing offset is less than zero.");
        }

        if (count < 0)
        {
          throw new Exception("The pipe buffer for writing count is less than zero.");
        }

        if (buffer.Length < (offset + count))
        {
          throw new Exception("The pipe buffer for writing does not contain amount of requested data.");
        }

        if (offset != 0)
        {
          var buf = new byte[count];

          for (int x = 0; x < count; x++)
          {
            buf[x] = buffer[offset + x];
          }

          buffer = buf;
        }

        uint written = 0;

        if (!Win32.WriteFile(_handle, buffer, (uint)count, ref written, IntPtr.Zero))
        {
          int err = Marshal.GetLastWin32Error();

          throw new Exception(string.Format("Pipe.Write failed, win32 error code {0}, pipe name '{1}' ", err, Name));
        }

        if (written < count)
        {
          throw new Exception("Written data is less than requested.");
        }

        return (int)written;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return 0;
      }
    }

    public bool Flush()
    {
      try
      {
        if (_handle == IntPtr.Zero)
        {
          throw new Exception("The pipe has been closed.");
        }

        if (!CanWrite)
        {
          throw new Exception("The pipe is not configured for writing.");
        }

        if (!Win32.FlushFileBuffers(_handle))
        {
          int err = Marshal.GetLastWin32Error();
          return false;
        }

        return true;
      }
      catch (Exception exception)
      {
        Log.Error(exception);

        return false;
      }
    }

    public void Close()
    {
      try
      {
        if (_handle == IntPtr.Zero)
        {
          return;
        }

        Win32.CloseHandle(_handle);
      }
      catch (Exception exception)
      {
        Log.Error(exception);
      }
      finally
      {
        _handle = IntPtr.Zero;
      }
    }

    public class Client : Pipe
    {
      public Client(string name, FileAccess mode, IntPtr handle)
        : base(name, mode, handle)
      {
      }

      public static Client Open(string name, FileAccess mode, bool shortRetry = false)
      {
        try
        {
          string pipeName = @"\\.\pipe\" + name;

          IntPtr handle = IntPtr.Zero;

          int retryCount = 300;

          if (shortRetry)
          {
            retryCount = 10;
          }

          for (int i = 0; i < retryCount; i++)
          {
            handle = Win32.CreateFileW(
                                       pipeName,
                                       mode,
                                       FileShare.ReadWrite,
                                       IntPtr.Zero,
                                       FileMode.Open,
                                       0,
                                       IntPtr.Zero);

            if (handle.ToInt32() != Win32.INVALID_HANDLE_VALUE && handle != IntPtr.Zero)
            {
              break;
            }

            System.Threading.Thread.Sleep(10);
          }

          if (handle.ToInt32() == Win32.INVALID_HANDLE_VALUE || handle == IntPtr.Zero)
          {
            int err = Marshal.GetLastWin32Error();

            throw new Exception(string.Format("Pipe.Client.Open failed, win32 error code {0}, pipe name '{1}' ",
                                              err,
                                              pipeName));
          }

          var pipe = new Client(name, mode, handle);

          return pipe;
        }
        catch (Exception exception)
        {
          Log.Error(exception);

          return null;
        }
      }
    }

    public class Server : Pipe
    {
      protected Server(string name, FileAccess mode, IntPtr handle)
        : base(name, mode, handle)
      {
      }

      public static Server Create(string name, FileAccess mode, bool shortRetry = false)
      {
        try
        {
          string pipeName = @"\\.\pipe\" + name;

          uint pipeMode = Win32.PIPE_ACCESS_DUPLEX;

          if (mode == FileAccess.Read)
          {
            pipeMode = Win32.PIPE_ACCESS_INBOUND;
          }
          else if (mode == FileAccess.Write)
          {
            pipeMode = Win32.PIPE_ACCESS_OUTBOUND;
          }

          IntPtr handle = IntPtr.Zero;

          int retryCount = 300;

          if (shortRetry)
          {
            retryCount = 100;
          }

          for (int i = 0; i < retryCount; i++)
          {
            handle = Win32.CreateNamedPipeW(
                                            pipeName,
                                            pipeMode,
                                            Win32.PIPE_TYPE_BYTE | Win32.PIPE_WAIT,
                                            Win32.PIPE_UNLIMITED_INSTANCES,
                                            0,
                                            1024,
                                            Win32.NMPWAIT_WAIT_FOREVER,
                                            IntPtr.Zero);

            if (handle.ToInt32() != Win32.INVALID_HANDLE_VALUE && handle != IntPtr.Zero)
            {
              break;
            }

            System.Threading.Thread.Sleep(10);
          }

          if (handle.ToInt32() == Win32.INVALID_HANDLE_VALUE)
          {
            int err = Marshal.GetLastWin32Error();

            throw new Exception(string.Format("Pipe.Server.Create failed, win32 error code {0}, pipe name '{1}' ",
                                              err,
                                              name));
          }

          var pipe = new Server(name, mode, handle);

          return pipe;
        }
        catch (Exception exception)
        {
          Log.Error(exception);

          return null;
        }
      }

      public bool Connect()
      {
        try
        {
          Disconnect();

          if (_handle == IntPtr.Zero)
          {
            throw new Exception("Pipe has not been created.");
          }

          if (!Win32.ConnectNamedPipe(_handle, IntPtr.Zero))
          {
            var err = (uint)Marshal.GetLastWin32Error();

            if (err != Win32.ERROR_PIPE_CONNECTED)
            {
              return false;
            }
          }

          _isConnected = true;

          return _isConnected;
        }
        catch (Exception exception)
        {
          Log.Error(exception);

          return false;
        }
      }

      public void Disconnect()
      {
        try
        {
          if (_isConnected)
          {
            Win32.DisconnectNamedPipe(_handle);

            _isConnected = false;
          }
        }
        catch (Exception exception)
        {
          Log.Error(exception);
        }
      }

      public override void Dispose()
      {
        try
        {
          try
          {
            Close();
          }
          catch (Exception exception)
          {
            Log.Error(exception);
          }
          finally
          {
            base.Dispose();
          }
        }
        catch (Exception exception)
        {
          Log.Error(exception);
        }
      }
    }

    private class Win32
    {
      //Constants for dwDesiredAccess:
      public const UInt32 GENERIC_READ = 0x80000000;
      public const UInt32 GENERIC_WRITE = 0x40000000;

      //Constants for return value:
      public const Int32 INVALID_HANDLE_VALUE = -1;

      //Constants for dwFlagsAndAttributes:
      public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000;
      public const UInt32 FILE_FLAG_NO_BUFFERING = 0x20000000;

      //Constants for dwCreationDisposition:
      public const UInt32 OPEN_EXISTING = 3;

      /// <summary>
      ///   Outbound pipe access.
      /// </summary>
      public const uint PIPE_ACCESS_OUTBOUND = 0x00000002;

      /// <summary>
      ///   Duplex pipe access.
      /// </summary>
      public const uint PIPE_ACCESS_DUPLEX = 0x00000003;

      /// <summary>
      ///   Inbound pipe access.
      /// </summary>
      public const uint PIPE_ACCESS_INBOUND = 0x00000001;

      /// <summary>
      ///   Pipe blocking mode.
      /// </summary>
      public const uint PIPE_WAIT = 0x00000000;

      /// <summary>
      ///   Pipe non-blocking mode.
      /// </summary>
      public const uint PIPE_NOWAIT = 0x00000001;

      /// <summary>
      ///   Pipe read mode of type Byte.
      /// </summary>
      public const uint PIPE_READMODE_BYTE = 0x00000000;

      /// <summary>
      ///   Pipe read mode of type Message.
      /// </summary>
      public const uint PIPE_READMODE_MESSAGE = 0x00000002;

      /// <summary>
      ///   Byte pipe type.
      /// </summary>
      public const uint PIPE_TYPE_BYTE = 0x00000000;

      /// <summary>
      ///   Message pipe type.
      /// </summary>
      public const uint PIPE_TYPE_MESSAGE = 0x00000004;

      /// <summary>
      ///   Pipe client end.
      /// </summary>
      public const uint PIPE_CLIENT_END = 0x00000000;

      /// <summary>
      ///   Pipe server end.
      /// </summary>
      public const uint PIPE_SERVER_END = 0x00000001;

      /// <summary>
      ///   Unlimited server pipe instances.
      /// </summary>
      public const uint PIPE_UNLIMITED_INSTANCES = 255;

      /// <summary>
      ///   Waits indefinitely when connecting to a pipe.
      /// </summary>
      public const uint NMPWAIT_WAIT_FOREVER = 0xffffffff;

      /// <summary>
      ///   Does not wait for the named pipe.
      /// </summary>
      public const uint NMPWAIT_NOWAIT = 0x00000001;

      /// <summary>
      ///   Uses the default time-out specified in a call to the CreateNamedPipe method.
      /// </summary>
      public const uint NMPWAIT_USE_DEFAULT_WAIT = 0x00000000;

      public const ulong ERROR_PIPE_CONNECTED = 535;

      public const uint FILE_SHARE_READ = 0x00000001;

      public const uint FILE_SHARE_WRITE = 0x00000002;

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
      public static extern IntPtr CreateFileW(
        [MarshalAs(UnmanagedType.LPWStr)] string filename,
        [MarshalAs(UnmanagedType.U4)] FileAccess access,
        [MarshalAs(UnmanagedType.U4)] FileShare share,
        IntPtr securityAttributes,
        [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
        [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
        IntPtr templateFile);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern IntPtr CreateNamedPipeW(
        [MarshalAs(UnmanagedType.LPWStr)] String lpName,
        // pipe name
        [MarshalAs(UnmanagedType.U4)] uint dwOpenMode,
        // pipe open mode
        [MarshalAs(UnmanagedType.U4)] uint dwPipeMode,
        // pipe-specific modes
        [MarshalAs(UnmanagedType.U4)] uint nMaxInstances,
        // maximum number of instances
        [MarshalAs(UnmanagedType.U4)] uint nOutBufferSize,
        // output buffer size
        [MarshalAs(UnmanagedType.U4)] uint nInBufferSize,
        // input buffer size
        [MarshalAs(UnmanagedType.U4)] uint nDefaultTimeOut,
        // time-out interval
        IntPtr pipeSecurityDescriptor // SD
        );

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool DisconnectNamedPipe(
        IntPtr hHandle);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool ConnectNamedPipe(
        IntPtr hHandle,
        // handle to named pipe
        IntPtr lpOverlapped // overlapped structure
        );

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool PeekNamedPipe(IntPtr handle,
                                              byte[] buffer,
                                              uint nBufferSize,
                                              ref uint bytesRead,
                                              ref uint bytesAvail,
                                              ref uint bytesLeftThisMessage);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool ReadFile(IntPtr handle,
                                         byte[] buffer,
                                         uint toRead,
                                         ref uint read,
                                         IntPtr lpOverLapped);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool WriteFile(IntPtr handle,
                                          byte[] buffer,
                                          uint count,
                                          ref uint written,
                                          IntPtr lpOverlapped);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool CloseHandle(IntPtr handle);

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
      public static extern bool FlushFileBuffers(IntPtr handle);
    }
  }
}


text:
<?php

declare(strict_types=1);

namespace Artisanry\Database\Traits\Repositories;

use Artisanry\Database\Utils\DateTime;
use Carbon\Carbon;

trait DateTimeTrait
{
    use DateTimeFindTrait;

    public function fromToday()
    {
        return $this->fromThisDay();
    }

    public function fromYesterday()
    {
        return $this->fromLastDay();
    }

    public function fromLastSevenDays()
    {
        return $this->fromDaysAgo(6, Carbon::now()->endOfDay());
    }

    public function fromLastThirtyDays()
    {
        return $this->fromDaysAgo(29, Carbon::now()->endOfDay());
    }

    public function fromLastFourWeeks()
    {
        return $this->fromDaysAgo(Carbon::now()->daysInMonth, Carbon::now()->endOfDay());
    }

    public function fromThisDay()
    {
        return $this->fromDaysAgo(0);
    }

    public function fromThisWeek()
    {
        return $this->fromWeeksAgo(0);
    }

    public function fromThisMonth()
    {
        return $this->fromMonthsAgo(0);
    }

    public function fromThisYear()
    {
        return $this->fromYearsAgo(0);
    }

    public function fromThisDecade()
    {
        return $this->fromDecadesAgo(0);
    }

    public function fromThisCentury()
    {
        return $this->fromCenturiesAgo(0);
    }

    public function fromLastDay()
    {
        return $this->fromDaysAgo(1);
    }

    public function fromLastWeek()
    {
        return $this->fromWeeksAgo(1);
    }

    public function fromLastMonth()
    {
        return $this->fromMonthsAgo(1);
    }

    public function fromLastYear()
    {
        return $this->fromYearsAgo(1);
    }

    public function fromLastDecade()
    {
        return $this->fromDecadesAgo(1);
    }

    public function fromLastCentury()
    {
        return $this->fromCenturiesAgo(1);
    }

    public function fromDaysAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getDaysAgo($ago, $endDateTime));
    }

    public function fromWeeksAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getWeeksAgo($ago, $endDateTime));
    }

    public function fromMonthsAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getMonthsAgo($ago, $endDateTime));
    }

    public function fromYearsAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getYearsAgo($ago, $endDateTime));
    }

    public function fromDecadesAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getDecadesAgo($ago, $endDateTime));
    }

    public function fromCenturiesAgo($ago, $endDateTime = null)
    {
        return $this->fromDateTimeRange(DateTime::getCenturiesAgo($ago, $endDateTime));
    }

    public function fromDateTimeRange($range, $exact = false)
    {
        if (!is_array($range)) {
            $range = DateTime::getDateTimeRange($range, $range, $exact);
        } else {
            $range = [
                (string) new Carbon($range[0]),
                (string) new Carbon($range[1]),
            ];
        }

        return $this->findWhereBetween('created_at', $range);
    }
}


text:
class RenamePersonColumn < ActiveRecord::Migration
  def change
    rename_column :individuals, :person_type_id, :individual_type_id
  end
end


text:
\setcounter{footnote}{0}

1. Once upon a time, a certain old bonze\footnote{I.e., a Mahayana Buddhist monk. The word comes from French \textit{bonze} < Portuguese \textit{bonzo} < Jse. \textit{bonsō} < Chinese, ult. < Sanskrit.} took the Trickster [ɛ̀-qhɛ̀] along
with him to go carry salt.

2. The old bonze was riding a horse.

3. As for the Trickster, he made him go on foot.

4. Then after a while he made the Trickster carry the salt.

5. He [the bonze] arrived at a certain place on horseback, and stopped to rest.

6. At this point Trickster knocked loose\footnote{\textbf{dɔ̂ʔ-pū}: `sprinkle by striking' (``strike-pour'').} some cow-sage beans\footnote{\textbf{phɨ̂-(h)á-le} `cowsage; horse-eye bean' [\textit{Mucuna pruriens}] a creeper with fuzzy brown beans containing an itchy substance. See DL:921.} onto the horse's
saddle.

7. Then when the two of them continued on their way and reached a certain point,
[the bonze] said, ``Hey, Trickster, are you finding it easy to carry the salt?''

8. The Trickster said, ``Oh, it's very easy! It's not at all tiring. And how is
it going with you?'', he asked.

9. ``Oh, I can't ride this horse. My ass is itching like crazy. It's most unfitting!''
he said.

10. So then he said, ``Say, Trickster, let me carry your salt. You come ride the
horse.''

11. Then [the bonze] went further ahead.

12. Once he [the bonze] got further ahead, the Trickster knocked away what he had
sprinkled onto the horse, and went riding along.

13. Riding along he reached the outskirts of a strange village\footnote{\textbf{šu} \textbf{qhâʔ}: lit. ``other peoples' village''.}, and stayed
there [waiting for the bonze to catch up].

14. By the time the old bonze carrying the salt also reached the village, night
had fallen.

15. When it got dark he said to Trickster, ``How shall the two of us hide away
this salt?''\footnote{So it wouldn't be stolen during the night.}

16. Trickster said, ``Let's hide it down there inside that pond!''

17. Early the next morning, when the two of them went to look for the salt they
had hidden, they couldn't find it.

18. It had all become [dissolved in the] water.

19. He said to the Trickster, ``ɛ̀-qhɛ̀, what could have happened! I can't
find the salt!''

20. Trickster said, ``The fish have eaten it, the fish have eaten it! Let's hurry
and drain this pond.''

21. As they were draining it, some pa-ná-tɔ̄\footnote{An edible black fish with a white belly, about a foot long. Also called \textbf{pa-ná-qāy}. See DL:802.} came out, and Trickster slapped
them to death.

22. When some catfish\footnote{Spiny bottom feeders [\textit{Clarias batrachus}]. See DL:803.} emerged, [Trickster] made [the bonze] slap them [too].
\footnote{Thus lacerating his hand on the spines.}

23. So this old bonze suffered a world of pain.

24. Since he hurt so much, he said to Trickster, ``You're going to have to carry
me. If you don't carry me I can't make it.''

25. Thereupon Trickster said, ``Take it easy, take it easy! I'll go look for somebody
to carry you.''

26. So he wound his way upwards and dislodged a rock so it would roll downhill.

27. When [Trickster] said, ``Run! If it's not a tiger, it's a bear! Run!'', the
old bonze ran all the way back home.


text:
/*
 * 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.
 */
package com.facebook.presto.parquet.cache;

import org.apache.parquet.hadoop.metadata.ParquetMetadata;

import static java.util.Objects.requireNonNull;

public class ParquetFileMetadata
{
    private final ParquetMetadata parquetMetadata;
    private final int metadataSize;
    private final long modificationTime;

    public ParquetFileMetadata(ParquetMetadata parquetMetadata, int metadataSize, long modificationTime)
    {
        this.parquetMetadata = requireNonNull(parquetMetadata, "parquetMetadata is null");
        this.metadataSize = metadataSize;
        this.modificationTime = modificationTime;
    }

    public int getMetadataSize()
    {
        return metadataSize;
    }

    public ParquetMetadata getParquetMetadata()
    {
        return parquetMetadata;
    }

    public long getModificationTime()
    {
        return modificationTime;
    }
}


text:
"""Fichier contenant la classe SignalRelais."""

from secondaires.navigation.equipage.signaux.termine import SignalTermine

class SignalRelais(SignalTermine):

    """Signal utilisé pour dire que l'ordre ne peut s'exécuter.

    La différence avec le SignalAbandonne, c'est qu'on demande ici
    à relayer l'ordre (pour X raison, le matelot sélectionné ne peut
    pas accomplir les ordres qui lui ont été assignés et il demande
    à d'autres de le faire).

    """

    def __init__(self, raison):
        SignalTermine.__init__(self)
        self.raison = raison

    def __repr__(self):
        return "<signal relais {}>".format(repr(self.raison))

    def traiter(self, generateur, profondeur):
        """Traite le générateur."""
        ordre = generateur.ordre
        matelot = ordre.matelot
        if ordre.peut_deleguer:
            matelot.relayer_ordres()
            matelot.ordres[:] = []
            SignalTermine.traiter(self, generateur, profondeur)


text:
from __future__ import print_function
"""
report how many days it has been since each developer committed.  You
must do an

svn log > log.txt

and place the output next to this file before running

"""
import os, datetime

import matplotlib.cbook as cbook

todate = cbook.todate('%Y-%m-%d')
today = datetime.date.today()
if not os.path.exists('log.txt'):
    print('You must place the "svn log" output into a file "log.txt"')
    raise SystemExit

parse = False

lastd = dict()
for line in file('log.txt'):
    if line.startswith('--------'):
        parse = True
        continue

    if parse:
        parts = [part.strip() for part in line.split('|')]
        developer = parts[1]
        dateparts = parts[2].split(' ')
        ymd = todate(dateparts[0])

    if developer not in lastd:
        lastd[developer] = ymd

    parse = False

dsu = [((today - lastdate).days, developer) for developer, lastdate in lastd.items()]

dsu.sort()
for timedelta, developer in dsu:
    print('%s : %d'%(developer, timedelta))


text:
<?php
return array (
  '%displayName% commented %contentTitle%.' => '%displayName% comentó %contentTitle%.',
);


text:
package com.rodrigodev.xgen4j.test.code.codeNameCanBeEqualToRootCodeNameForErrorsThatAreNotChildrenOfRootError_nameOnly.code_name_eb1.code_name_root.code_name_root;

import com.rodrigodev.xgen4j.test.code.codeNameCanBeEqualToRootCodeNameForErrorsThatAreNotChildrenOfRootError_nameOnly.code_name_eb1.code_name_root.EB2Error;

import com.rodrigodev.xgen4j.test.code.codeNameCanBeEqualToRootCodeNameForErrorsThatAreNotChildrenOfRootError_nameOnly.ErrorCode;

/**
 * Autogenerated by XGen4J on January 1, 0001.
 */
public abstract class EB3Error extends EB2Error {

    public static final ErrorCode CODE = new ErrorCode("code-name-root", EB2Error.CODE);

}