text:
package postgresql

var migrate = []string{
	`
		create table if not exists users (
			id            bigserial    not null primary key,
			name          text         default null,
			created_at    timestamptz  not null,
			auth_service  text         not null,
			auth_id       text         not null,
			blocked       boolean      not null default false,
			admin         boolean      not null default false,
			avatar        text         not null default ''
		);
		create unique index on users(lower(name));
		create unique index on users(auth_service, auth_id);
	`,
	`
		create table if not exists topics (
			id               bigserial    not null primary key,
			author_id        bigint       not null references users(id),
			title            text         not null,
			created_at       timestamptz  not null,
			last_comment_at  timestamptz  not null,
			deleted          boolean      not null default false,
			comment_count    int          not null default 0
		);
		create index on topics(last_comment_at);
	`,
	`
		create table if not exists comments (
			id          bigserial     not null primary key,
			topic_id    bigint        not null references topics(id),
			author_id   bigint        not null references users(id),
			content     text          not null,
			created_at  timestamptz   not null,
			deleted     boolean       not null default false
		);
		create index on comments(topic_id);
		create index on comments(created_at);
	`,
}

var drop = []string{
	`drop table if exists users cascade`,
	`drop table if exists topics cascade`,
	`drop table if exists comments cascade`,
}


text:
import { Component, TemplateRef } from '@angular/core';
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';

@Component({
  // eslint-disable-next-line @angular-eslint/component-selector
  selector: 'demo-modal-scrolling-long-content',
  templateUrl: './scrolling-long-content.html'
})
export class DemoModalScrollingLongContentComponent {
  modalRef?: BsModalRef;
  items: any[];

  constructor(private modalService: BsModalService) {
    this.items = Array(15).fill(0);
  }

  openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template);
  }
}

redpajama_set_name: RedPajamaGithub


text:
import os

from azure import (WindowsAzureError,
                   DEV_ACCOUNT_NAME,
                   DEV_ACCOUNT_KEY,
                   _ERROR_STORAGE_MISSING_INFO,
                   )
from azure.http import HTTPError
from azure.http.httpclient import _HTTPClient
from azure.storage import _storage_error_handler

#--------------------------------------------------------------------------
# constants for azure app setting environment variables
AZURE_STORAGE_ACCOUNT = 'AZURE_STORAGE_ACCOUNT'
AZURE_STORAGE_ACCESS_KEY = 'AZURE_STORAGE_ACCESS_KEY'
EMULATED = 'EMULATED'

#--------------------------------------------------------------------------
class _StorageClient(object):
    '''
    This is the base class for BlobManager, TableManager and QueueManager.
    '''

    def __init__(self, account_name=None, account_key=None, protocol='https', host_base='', dev_host=''):
        '''
        account_name: your storage account name, required for all operations.
        account_key: your storage account key, required for all operations.
        protocol: Optional. Protocol. Defaults to http.
        host_base:
            Optional. Live host base url. Defaults to Azure url. Override this
            for on-premise.
        dev_host: Optional. Dev host url. Defaults to localhost.
        '''
        if account_name is not None:
            self.account_name = account_name.encode('ascii', 'ignore')
        else:
            self.account_name = None
        if account_key is not None:
            self.account_key = account_key.encode('ascii', 'ignore')
        else:
            self.account_key = None

        self.requestid = None
        self.protocol = protocol
        self.host_base = host_base
        self.dev_host = dev_host

        #the app is not run in azure emulator or use default development
        #storage account and key if app is run in emulator.
        self.use_local_storage = False

        #check whether it is run in emulator.
        if os.environ.has_key(EMULATED):
            if os.environ[EMULATED].lower() == 'false':
                self.is_emulated = False
            else:
                self.is_emulated = True
        else:
            self.is_emulated = False

        #get account_name and account key. If they are not set when constructing,
        #get the account and key from environment variables if the app is not run
        #in azure emulator or use default development storage account and key if
        #app is run in emulator.
        if not self.account_name or not self.account_key:
            if self.is_emulated:
                self.account_name = DEV_ACCOUNT_NAME
                self.account_key = DEV_ACCOUNT_KEY
                self.use_local_storage = True
            else:
                if os.environ.has_key(AZURE_STORAGE_ACCOUNT):
                    self.account_name = os.environ[AZURE_STORAGE_ACCOUNT]
                if os.environ.has_key(AZURE_STORAGE_ACCESS_KEY):
                    self.account_key = os.environ[AZURE_STORAGE_ACCESS_KEY]

        if not self.account_name or not self.account_key:
            raise WindowsAzureError(_ERROR_STORAGE_MISSING_INFO)

        self._httpclient = _HTTPClient(service_instance=self, account_key=self.account_key, account_name=self.account_name, protocol=protocol)
        self._batchclient = None
        self._filter = self._perform_request_worker

    def with_filter(self, filter):
        '''
        Returns a new service which will process requests with the specified
        filter.  Filtering operations can include logging, automatic retrying,
        etc...  The filter is a lambda which receives the HTTPRequest and
        another lambda.  The filter can perform any pre-processing on the
        request, pass it off to the next lambda, and then perform any
        post-processing on the response.
        '''
        res = type(self)(self.account_name, self.account_key, self.protocol)
        old_filter = self._filter
        def new_filter(request):
            return filter(request, old_filter)

        res._filter = new_filter
        return res

    def set_proxy(self, host, port, user=None, password=None):
        '''
        Sets the proxy server host and port for the HTTP CONNECT Tunnelling.

        host: Address of the proxy. Ex: '192.168.0.100'
        port: Port of the proxy. Ex: 6000
        user: User for proxy authorization.
        password: Password for proxy authorization.
        '''
        self._httpclient.set_proxy(host, port, user, password)

    def _get_host(self):
        if self.use_local_storage:
            return self.dev_host
        else:
            return self.account_name + self.host_base

    def _perform_request_worker(self, request):
        return self._httpclient.perform_request(request)

    def _perform_request(self, request):
        '''
        Sends the request and return response. Catches HTTPError and hand it
        to error handler
        '''
        try:
            if self._batchclient is not None:
                return self._batchclient.insert_request_to_batch(request)
            else:
                resp = self._filter(request)
        except HTTPError as e:
            _storage_error_handler(e)

        return resp


text:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * MoonCake v1.1 - Error Page Stylesheet
 *
 * This file is part of MoonCake, an Admin template build for sale at ThemeForest.
 * For questions, suggestions or support request, please mail me at maimairel@yahoo.com
 *
 * Development Started:
 * July 28, 2012
 * Last Update:
 * October 10, 2012
 *
 */

/* Body
================================================== */

body
{
    background: #fafafa url(../images/layout/bg/white_tiles.png);
    color: #444;
    font-size: 14px;
    line-height: 20px;
    padding: 200px 0;
}

#error-wrap
{
    text-align: center;
    width: 768px;
    margin: auto;
}

#error-digits
{
    margin: auto;
    margin-bottom: 25px;
    display: inline-block;
}

#error-digits > span
{
    display: inline-block;
    font-size: 96px;
    margin: 5px;
    line-height: 96px;
    font-weight: bold;
    background-color: #fff;
    padding: 16px 32px;
    position: relative;
    border: 1px solid #ccc;
    -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

#error-digits > span:after,
#error-digits > span:before
{
    content: '';
    position: absolute;
    display: block;
    height: 1px;
    bottom: -3px;
    left: 3px;
    right: 3px;
    background-color: #fff;
    border: 1px solid #d3d3d3;
    border-top: 0;
}

#error-digits > span:before
{
    bottom: -5px;
    left: 6px;
    right: 6px;
}

#error-wrap h1
{
    margin-bottom: 15px;
    text-shadow: 1px 1px #fff;
    color: #313131;
}

#error-wrap p a
{
    border-bottom: 1px dotted #999;
    text-decoration: none;
}

#error-form.form-search
{
    padding: 25px 0;
}

#error-form.form-search .search-query
{
    height: 28px;
}

#error-form.form-search .btn
{
    line-height: 28px;
}

/*
Animate.css - http://daneden.me/animate
LICENSED UNDER THE  MIT LICENSE (MIT)

Copyright (c) 2012 Dan Eden

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

.animated
{
    -webkit-animation-fill-mode: both;
    -moz-animation-fill-mode: both;
    -ms-animation-fill-mode: both;
    -o-animation-fill-mode: both;
    animation-fill-mode: both;
    -webkit-animation-duration: 1s;
    -moz-animation-duration: 1s;
    -ms-animation-duration: 1s;
    -o-animation-duration: 1s;
    animation-duration: 1s;
}

@-webkit-keyframes bounceInDown
{
    0%
    {
        opacity: 0;
        -webkit-transform: translateY(-2000px);
    }

    60%
    {
        opacity: 1;
        -webkit-transform: translateY(30px);
    }

    80%
    {
        -webkit-transform: translateY(-10px);
    }

    100%
    {
        -webkit-transform: translateY(0);
    }
}

@-moz-keyframes bounceInDown
{
    0%
    {
        opacity: 0;
        -moz-transform: translateY(-2000px);
    }

    60%
    {
        opacity: 1;
        -moz-transform: translateY(30px);
    }

    80%
    {
        -moz-transform: translateY(-10px);
    }

    100%
    {
        -moz-transform: translateY(0);
    }
}

@-o-keyframes bounceInDown
{
    0%
    {
        opacity: 0;
        -o-transform: translateY(-2000px);
    }

    60%
    {
        opacity: 1;
        -o-transform: translateY(30px);
    }

    80%
    {
        -o-transform: translateY(-10px);
    }

    100%
    {
        -o-transform: translateY(0);
    }
}

@keyframes bounceInDown
{
    0%
    {
        opacity: 0;
        transform: translateY(-2000px);
    }

    60%
    {
        opacity: 1;
        transform: translateY(30px);
    }

    80%
    {
        transform: translateY(-10px);
    }

    100%
    {
        transform: translateY(0);
    }
}

.delay300
{
    animation-delay: 300ms;
    -moz-animation-delay: 300ms;
    -webkit-animation-delay: 300ms;
    -o-animation-delay: 300ms;
}

.delay600
{
    animation-delay: 600ms;
    -moz-animation-delay: 600ms;
    -webkit-animation-delay: 600ms;
    -o-animation-delay: 600ms;
}

.bounceInDown
{
    -webkit-animation-name: bounceInDown;
    -moz-animation-name: bounceInDown;
    -o-animation-name: bounceInDown;
    animation-name: bounceInDown;
}


text:
body {
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #eee;
}
.form-signin {
  max-width: 330px;
  padding: 15px;
  margin: 150px auto;
  /*-webkit-animation: fadein 5s;*/
}
.form-signin .form-signin-heading {
  margin-bottom: 20px;
}
.form-signin .form-control {
  position: relative;
  height: auto;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
  padding: 10px;
  font-size: 16px;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.form-signin input {
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}


text:
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence').use(gulp);

gulp.task('build:production', function (cb) {
    process.env.NODE_ENV = 'production';
    gulpSequence('clean', ['bower-copy', 'fonts', 'images'], ['sass', 'webpack:production'], 'favicons', cb);
});


text:
from SafeRLBench import config

from SafeRLBench import Bench, BenchConfig
from SafeRLBench.algo import PolicyGradient
from SafeRLBench.envs import LinearCar
from SafeRLBench.policy import LinearPolicy
from SafeRLBench.measure import BestPerformance

from unittest2 import TestCase

import logging

logger = logging.getLogger(__name__)

class TestIntegration(TestCase):
    """Test integration with PolicyGradient and LinearCar."""

    def test_integration(self):
        """Integration: bench with pc and lc."""
        # setup config:
        config.logger_set_level(logging.DEBUG)
        config.monitor_set_verbosity(3)

        policy = LinearPolicy(2, 1, biased=True)
        algs = [(PolicyGradient, {'policy': policy,
                                  'max_it': 10,
                                  'estimator': 'central_fd'})]
        env = [[(LinearCar, {'horizon': 100})]]

        test_config = BenchConfig(algs, env)

        benchmark = Bench(test_config, [BestPerformance()])
        benchmark()

        assert(benchmark.measures[0].result is not None)

    def test_parallel_integration(self):
        """Integration: bench with pc and lc (parallel)."""
        # setup config:
        config.logger_set_level(logging.DEBUG)
        config.monitor_set_verbosity(3)
        config.jobs_set(2)

        policy = LinearPolicy(2, 1)
        algs = [(PolicyGradient, [{'policy': policy,
                                   'max_it': 10,
                                   'estimator': 'central_fd'},
                                  {'policy': policy,
                                   'max_it': 20,
                                   'estimator': 'central_fd'}])]
        env = [[(LinearCar, {'horizon': 100})]]

        test_config = BenchConfig(algs, env)

        benchmark = Bench(test_config, [BestPerformance()])
        benchmark()

        assert(benchmark.measures[0].result is not None)
        assert(len(benchmark.measures[0].result) == 2)


text:
from django.shortcuts import render
from uganda_common.models import Access

__author__ = 'kenneth'

class AccessMiddleWare(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        if not 'wraps' in view_func.func_globals:
            return None
        if request.user.is_authenticated():
            try:
                access = Access.objects.get(user=request.user)
                if access.denied(request):
                    return render(request, '403.html', status=403)
            except Access.DoesNotExist:
                return None
        return None

class AccessTemplateMiddleWare(object):
    pass


text:
with open(file) as handle:
    for b in handle.read(1):
        try:
            char = b.encode("ascii")


text:
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DebugInput.cs" company="Slash Games">
//   Copyright (c) Slash Games. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Slash.Unity.Common.Diagnostics
{
    using UnityEngine;

    /// <summary>
    ///   Enables the DebugInputEditor to show information about the unity input.
    /// </summary>
    public class DebugInput : MonoBehaviour
    {
    }
}


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 System;
using System.Composition;
using System.IO;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
    [ExportLanguageServiceFactory(typeof(ISyntaxTreeFactoryService), LanguageNames.CSharp), Shared]
    internal partial class CSharpSyntaxTreeFactoryServiceFactory : ILanguageServiceFactory
    {
        private static readonly CSharpParseOptions _parseOptionWithLatestLanguageVersion = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview);

        [ImportingConstructor]
        [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
        public CSharpSyntaxTreeFactoryServiceFactory()
        {
        }

        public ILanguageService CreateLanguageService(HostLanguageServices provider)
            => new CSharpSyntaxTreeFactoryService(provider);

        private partial class CSharpSyntaxTreeFactoryService : AbstractSyntaxTreeFactoryService
        {
            public CSharpSyntaxTreeFactoryService(HostLanguageServices languageServices) : base(languageServices)
            {
            }

            public override ParseOptions GetDefaultParseOptions()
                => CSharpParseOptions.Default;

            public override ParseOptions GetDefaultParseOptionsWithLatestLanguageVersion()
                => _parseOptionWithLatestLanguageVersion;

            public override SyntaxTree CreateSyntaxTree(string filePath, ParseOptions options, Encoding encoding, SyntaxNode root)
            {
                options ??= GetDefaultParseOptions();
                return CSharpSyntaxTree.Create((CSharpSyntaxNode)root, (CSharpParseOptions)options, filePath, encoding);
            }

            public override SyntaxTree ParseSyntaxTree(string filePath, ParseOptions options, SourceText text, CancellationToken cancellationToken)
            {
                options ??= GetDefaultParseOptions();
                return SyntaxFactory.ParseSyntaxTree(text, options, filePath, cancellationToken: cancellationToken);
            }

            public override SyntaxNode DeserializeNodeFrom(Stream stream, CancellationToken cancellationToken)
                => CSharpSyntaxNode.DeserializeFrom(stream, cancellationToken);

            public override bool CanCreateRecoverableTree(SyntaxNode root)
                => base.CanCreateRecoverableTree(root) && root is CompilationUnitSyntax cu && cu.AttributeLists.Count == 0;

            public override SyntaxTree CreateRecoverableTree(
                ProjectId cacheKey,
                string filePath,
                ParseOptions options,
                ValueSource<TextAndVersion> text,
                Encoding encoding,
                SyntaxNode root)
            {
                System.Diagnostics.Debug.Assert(CanCreateRecoverableTree(root));
                return RecoverableSyntaxTree.CreateRecoverableTree(
                    this,
                    cacheKey,
                    filePath,
                    options ?? GetDefaultParseOptions(),
                    text,
                    encoding,
                    (CompilationUnitSyntax)root);
            }
        }
    }
}


text:
'use strict';
define([
    'utils', 'components/component'
], function (Utils, Component) {
    var Transcripts = Component.extend({
        _constructor: function (runtime) {
            this.runtime = runtime;
            this.player = runtime.getPlayer();
            this.media = runtime.getMedia();

            var container = this.player.element,
                transcripts = this.element = this.runtime.$('<ol class="s2js-transcripts" />'),
                title = Utils.i18n.t('transcripts');

            this.runtime.$.ajax({
                url: 'http://localhost:3000/srt',
                success: function (response) {
                    this.build(container, response);
                }.bind(this)
            });
        },

        build: function (container, content) {
            this.srt = new SubRip(content);
            var items = this.generateItems(this.srt._subripArray);

            this.element
                .append(items)
                .appendTo(container);
            this.items = this.element.find('li');

            this.media.element.addEventListener('timeupdate', function () {
                this.setItemBySeconds(this.media.currentTime);
            }.bind(this));

            this.element.on('click', 'li', function (event) {
                var index = this.runtime.$(event.currentTarget).index();
                this.media.setCurrentTime(this.srt._subripArray[index].start);
            }.bind(this));
        },

        generateItems: function (array) {
            var frag = document.createDocumentFragment();
            this.runtime.$.each(array, function(index, SubRipItem) {
                var item = this.runtime.$('<li />', {'class': 's2js-transcripts-item'});
                item.text(SubRipItem.text);
                frag.appendChild(item[0]);
            });

            return [frag];
        },

        setItemBySeconds: function (seconds) {
            var SubRip = this.srt.search(seconds);
            if (SubRip) {
                this.setItemByIndex(SubRip.id - 1);
            } else {
                this.items.removeClass('s2js-transcripts-item-active');
            }
        },

        setItemByIndex: function (index) {
            this.items
                .removeClass('s2js-transcripts-item-active')
                .eq(index)
                .addClass('s2js-transcripts-item-active');
        }
    });

    return Transcripts;
});


text:
require 'spec_helper'

describe "Basic" do
  let(:filename) { 'test.txt' }

  specify "no placeholders" do
    add_snippet_file 'test.snippets', <<-EOF
      snippet test
      	One, two, three
    EOF

    set_file_contents <<-EOF
      test
    EOF

    vim.feedkeys 'A\<c-t>'
    vim.write

    assert_file_contents <<-EOF
      One, two, three
    EOF
  end

  specify "a single placeholder" do
    add_snippet_file 'test.snippets', <<-EOF
      snippet test
      	One, ${1}, three
    EOF

    set_file_contents <<-EOF
      test
    EOF

    vim.normal
    vim.feedkeys 'A\<c-t>'
    vim.feedkeys 'two'
    vim.write

    assert_file_contents <<-EOF
      One, two, three
    EOF
  end
end


text:
Mixture of Gaussian Example (Colab):

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/deepmind/deepmind_research/blob/master/ode_gan/odegan_mog16.ipynb)

Cifar 10 Example (Tensorflow):
Launch Training from
https://github/deepmind/deepmind_research/tree/master/cs_gan/run_ode.sh

This package demos the algorithm [ODE-GAN](https://arxiv.org/abs/2010.15040).

If you make use of any code in your work, please cite:

```
@article{qin2020training,
  title={Training Generative Adversarial Networks by Solving Ordinary Differential Equations},
  author={Qin, Chongli and Wu, Yan and Springenberg, Jost Tobias and
  Brock, Andy and Donahue, Jeff and Lillicrap, Timothy and Kohli, Pushmeet},
  journal={Advances in Neural Information Processing Systems},
  volume={33},
  year={2020}
}
```


text:
/// Copyright (c) 2012 Ecma International.  All rights reserved.
/**
 * @path ch15/15.4/15.4.4/15.4.4.18/15.4.4.18-3-18.js
 * @description Array.prototype.forEach - value of 'length' is a string that can't convert to a number
 */

function testcase() {

        var accessed = false;

        function callbackfn(val, idx, obj) {
            accessed = true;
        }

        var obj = { 0: 9, length: "asdf!_" };

        Array.prototype.forEach.call(obj, callbackfn);

        return !accessed;
    }
runTestCase(testcase);


text:
A minimalist query language. In JSON.

See the live examples and tutorial at https://jrgql.github.io

# Discussion

https://news.ycombinator.com/item?id=15005130

# License

MIT


text:
MobileUserShow = {
    init : function() {
        $("#delete_button").click(function() {
            MobileUserIndex.verifyIfUserHasSessionData($(this).attr("user_id"));
        });
    }
}

$(MobileUserShow.init);


text:
#ifndef RIGIDREGISTRATION_HPP
#define RIGIDREGISTRATION_HPP

#include <Eigen/Dense>
#include <stdio.h>
#include <memory.h>
#include <time.h>
#include "../global.hpp"
#include "CorrespondenceFilter.hpp"
#include "SymmetricCorrespondenceFilter.hpp"
#include "InlierDetector.hpp"
#include "RigidTransformer.hpp"

typedef Eigen::VectorXf VecDynFloat;
typedef Eigen::Matrix< float, Eigen::Dynamic, registration::NUM_FEATURES> FeatureMat; //matrix Mx6 of type float
typedef Eigen::Matrix4f Mat4Float;

namespace registration{

class RigidRegistration
{
    /*
    # GOAL
    This class performs icp-based rigid registration between two oriented pointclouds.

    # INPUTS
    -ioFloatingFeatures
    -inTargetFeatures
    -inFloatingFlags
    -inTargetFlags

    # PARAMETERS
    -numNeighbours(=3):
    number of nearest neighbours

    # OUTPUT
    -outCorrespondingFeatures
    -outCorrespondingFlags
    */

    public:

        void set_input(FeatureMat * const ioFloatingFeatures,
                       const FeatureMat * const inTargetFeatures,
                       const VecDynFloat * const inFloatingFlags,
                       const VecDynFloat * const inTargetFlags);
        void set_parameters(bool symmetric, size_t numNeighbours,
                            float flagThreshold, bool equalizePushPull,
                            float kappaa, bool inlierUseOrientation,
                            size_t numIterations, bool useScaling);
        Mat4Float get_transformation() const {return _transformationMatrix;}

        void update();

    protected:

    private:
        //# Inputs/Outputs
        FeatureMat * _ioFloatingFeatures = NULL;
        const FeatureMat * _inTargetFeatures = NULL;
        const VecDynFloat * _inFloatingFlags = NULL;
        const VecDynFloat * _inTargetFlags = NULL;

        //# User Parameters
        //## Correspondences
        bool _symmetric = true;
        size_t _numNeighbours = 3;
        float _flagThreshold = 0.9f;
        bool _equalizePushPull = false;
        //## Inliers
        float _kappaa = 3.0;
        bool _inlierUseOrientation = true;
        //## Transformation
        size_t _numIterations = 10;
        bool _useScaling = false;

        //# Internal Data structures
        Mat4Float _transformationMatrix = Mat4Float::Identity();

        //# Internal Parameters

        //# Internal functions
};

}//namespace registration

#endif // RIGIDREGISTRATION_HPP


text:
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/clipboard_host_impl.h"

#include <memory>
#include <set>
#include <utility>

#include "base/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/pickle.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h"
#include "content/browser/file_system/browser_file_system_helper.h"
#include "content/browser/file_system_access/file_system_access_manager_impl.h"
#include "content/browser/permissions/permission_controller_impl.h"
#include "content/browser/renderer_host/data_transfer_util.h"
#include "content/browser/renderer_host/render_frame_host_delegate.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_client.h"
#include "content/public/common/drop_data.h"
#include "ipc/ipc_message.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "skia/ext/skia_utils_base.h"
#include "third_party/blink/public/mojom/clipboard/clipboard.mojom.h"
#include "third_party/blink/public/mojom/drag/drag.mojom-forward.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/clipboard/file_info.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#include "url/gurl.h"

namespace content {

namespace {
bool IsRendererPasteAllowed(RenderFrameHost& render_frame_host) {
  ContentBrowserClient* browser_client = GetContentClient()->browser();
  return browser_client->IsClipboardPasteAllowed(&render_frame_host);
}
}  // namespace

// 5 mins is based on the timeout in BinaryUploadService. This scanning timeout
// of 5 mins means no paste will be held back longer before being allowed or
// blocked, so matching this timeout with the threshold for a paste being too
// old ensures scans that:
//  - Scans that timeout can be retried without waiting
//  - Scans that succeed will apply their verdicts without the risk that their
//    associated IsPasteContentAllowedRequest is already too old.
const base::TimeDelta ClipboardHostImpl::kIsPasteContentAllowedRequestTooOld =
    base::Minutes(5);

ClipboardHostImpl::IsPasteContentAllowedRequest::
    IsPasteContentAllowedRequest() = default;
ClipboardHostImpl::IsPasteContentAllowedRequest::
    ~IsPasteContentAllowedRequest() = default;

bool ClipboardHostImpl::IsPasteContentAllowedRequest::AddCallback(
    IsClipboardPasteContentAllowedCallback callback) {
  // If this request has already completed, invoke the callback immediately
  // and return.
  if (data_.has_value()) {
    std::move(callback).Run(data_.value());
    return false;
  }

  callbacks_.push_back(std::move(callback));

  // If this is the first callback registered tell the caller to start the scan.
  return callbacks_.size() == 1;
}

void ClipboardHostImpl::IsPasteContentAllowedRequest::Complete(
    IsClipboardPasteContentAllowedCallbackArgType data) {
  data_ = std::move(data);
  InvokeCallbacks();
}

bool ClipboardHostImpl::IsPasteContentAllowedRequest::IsObsolete(
    base::Time now) {
  // If the request is old and no longer has any registered callbacks it is
  // obsolete.
  return (now - time_) > kIsPasteContentAllowedRequestTooOld &&
         callbacks_.empty();
}

void ClipboardHostImpl::IsPasteContentAllowedRequest::InvokeCallbacks() {
  DCHECK(data_);

  auto callbacks = std::move(callbacks_);
  for (auto& callback : callbacks) {
    if (!callback.is_null())
      std::move(callback).Run(data_.value());
  }
}

ClipboardHostImpl::ClipboardHostImpl(
    RenderFrameHost& render_frame_host,
    mojo::PendingReceiver<blink::mojom::ClipboardHost> receiver)
    : DocumentService(render_frame_host, std::move(receiver)) {
  clipboard_writer_ = std::make_unique<ui::ScopedClipboardWriter>(
      ui::ClipboardBuffer::kCopyPaste,
      render_frame_host.GetBrowserContext()->IsOffTheRecord()
          ? nullptr
          : std::make_unique<ui::DataTransferEndpoint>(
                render_frame_host.GetMainFrame()->GetLastCommittedURL()));
}

void ClipboardHostImpl::Create(
    RenderFrameHost* render_frame_host,
    mojo::PendingReceiver<blink::mojom::ClipboardHost> receiver) {
  CHECK(render_frame_host);
  // The object is bound to the lifetime of |render_frame_host| and the mojo
  // connection. See DocumentService for details.
  new ClipboardHostImpl(*render_frame_host, std::move(receiver));
}

ClipboardHostImpl::~ClipboardHostImpl() {
  clipboard_writer_->Reset();
}

void ClipboardHostImpl::GetSequenceNumber(ui::ClipboardBuffer clipboard_buffer,
                                          GetSequenceNumberCallback callback) {
  std::move(callback).Run(
      ui::Clipboard::GetForCurrentThread()->GetSequenceNumber(
          clipboard_buffer));
}

void ClipboardHostImpl::ReadAvailableTypes(
    ui::ClipboardBuffer clipboard_buffer,
    ReadAvailableTypesCallback callback) {
  std::vector<std::u16string> types;
  auto* clipboard = ui::Clipboard::GetForCurrentThread();
  auto data_endpoint = CreateDataEndpoint();

  // ReadAvailableTypes() returns 'text/uri-list' if either files are provided,
  // or if it was set as a custom web type. If it is set because files are
  // available, do not include other types such as text/plain which contain the
  // full path on some platforms (http://crbug.com/1214108). But do not exclude
  // other types when it is set as a custom web type (http://crbug.com/1241671).
  if (clipboard->IsFormatAvailable(ui::ClipboardFormatType::FilenamesType(),
                                   clipboard_buffer, data_endpoint.get())) {
    types = {base::UTF8ToUTF16(ui::kMimeTypeURIList)};
  } else {
    clipboard->ReadAvailableTypes(clipboard_buffer, data_endpoint.get(),
                                  &types);
  }
  std::move(callback).Run(types);
}

void ClipboardHostImpl::IsFormatAvailable(blink::mojom::ClipboardFormat format,
                                          ui::ClipboardBuffer clipboard_buffer,
                                          IsFormatAvailableCallback callback) {
  ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
  bool result = false;
  auto data_endpoint = CreateDataEndpoint();
  switch (format) {
    case blink::mojom::ClipboardFormat::kPlaintext:
      result =
          clipboard->IsFormatAvailable(ui::ClipboardFormatType::PlainTextType(),
                                       clipboard_buffer, data_endpoint.get());
#if BUILDFLAG(IS_WIN)
      result |= clipboard->IsFormatAvailable(
          ui::ClipboardFormatType::PlainTextAType(), clipboard_buffer,
          data_endpoint.get());
#endif
      break;
    case blink::mojom::ClipboardFormat::kHtml:
      result =
          clipboard->IsFormatAvailable(ui::ClipboardFormatType::HtmlType(),
                                       clipboard_buffer, data_endpoint.get());
      break;
    case blink::mojom::ClipboardFormat::kSmartPaste:
      result = clipboard->IsFormatAvailable(
          ui::ClipboardFormatType::WebKitSmartPasteType(), clipboard_buffer,
          data_endpoint.get());
      break;
    case blink::mojom::ClipboardFormat::kBookmark:
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
      result =
          clipboard->IsFormatAvailable(ui::ClipboardFormatType::UrlType(),
                                       clipboard_buffer, data_endpoint.get());
#else
      result = false;
#endif
      break;
  }
  std::move(callback).Run(result);
}

void ClipboardHostImpl::ReadText(ui::ClipboardBuffer clipboard_buffer,
                                 ReadTextCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::u16string());
    return;
  }
  ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
  std::u16string result;
  auto data_dst = CreateDataEndpoint();
  if (clipboard->IsFormatAvailable(ui::ClipboardFormatType::PlainTextType(),
                                   clipboard_buffer, data_dst.get())) {
    clipboard->ReadText(clipboard_buffer, data_dst.get(), &result);
  } else {
#if BUILDFLAG(IS_WIN)
    if (clipboard->IsFormatAvailable(ui::ClipboardFormatType::PlainTextAType(),
                                     clipboard_buffer, data_dst.get())) {
      std::string ascii;
      clipboard->ReadAsciiText(clipboard_buffer, data_dst.get(), &ascii);
      result = base::ASCIIToUTF16(ascii);
    }
#endif
  }

  std::string data = base::UTF16ToUTF8(result);
  PasteIfPolicyAllowed(clipboard_buffer,
                       ui::ClipboardFormatType::PlainTextType(),
                       std::move(data),
                       base::BindOnce(
                           [](std::u16string result, ReadTextCallback callback,
                              const absl::optional<std::string>& data) {
                             if (!data)
                               result.clear();
                             std::move(callback).Run(result);
                           },
                           std::move(result), std::move(callback)));
}

void ClipboardHostImpl::ReadHtml(ui::ClipboardBuffer clipboard_buffer,
                                 ReadHtmlCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::u16string(), GURL(), 0, 0);
    return;
  }
  ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
  std::u16string markup;
  std::string src_url_str;
  uint32_t fragment_start = 0;
  uint32_t fragment_end = 0;
  auto data_dst = CreateDataEndpoint();
  clipboard->ReadHTML(clipboard_buffer, data_dst.get(), &markup, &src_url_str,
                      &fragment_start, &fragment_end);

  std::string data = base::UTF16ToUTF8(markup);
  PasteIfPolicyAllowed(
      clipboard_buffer, ui::ClipboardFormatType::HtmlType(), std::move(data),
      base::BindOnce(
          [](std::u16string markup, std::string src_url_str,
             uint32_t fragment_start, uint32_t fragment_end,
             ReadHtmlCallback callback,
             const absl::optional<std::string>& data) {
            if (!data)
              markup.clear();
            std::move(callback).Run(std::move(markup), GURL(src_url_str),
                                    fragment_start, fragment_end);
          },
          std::move(markup), std::move(src_url_str), fragment_start,
          fragment_end, std::move(callback)));
}

void ClipboardHostImpl::ReadSvg(ui::ClipboardBuffer clipboard_buffer,
                                ReadSvgCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::u16string());
    return;
  }
  std::u16string markup;
  ui::Clipboard::GetForCurrentThread()->ReadSvg(clipboard_buffer,
                                                /*data_dst=*/nullptr, &markup);

  std::string data = base::UTF16ToUTF8(markup);
  PasteIfPolicyAllowed(clipboard_buffer, ui::ClipboardFormatType::SvgType(),
                       std::move(data),
                       base::BindOnce(
                           [](std::u16string markup, ReadSvgCallback callback,
                              const absl::optional<std::string>& data) {
                             if (!data)
                               markup.clear();
                             std::move(callback).Run(std::move(markup));
                           },
                           std::move(markup), std::move(callback)));
}

void ClipboardHostImpl::ReadRtf(ui::ClipboardBuffer clipboard_buffer,
                                ReadRtfCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::string());
    return;
  }
  std::string result;
  auto data_dst = CreateDataEndpoint();
  ui::Clipboard::GetForCurrentThread()->ReadRTF(clipboard_buffer,
                                                data_dst.get(), &result);

  std::string data = result;
  PasteIfPolicyAllowed(clipboard_buffer, ui::ClipboardFormatType::RtfType(),
                       std::move(data),
                       base::BindOnce(
                           [](std::string result, ReadRtfCallback callback,
                              const absl::optional<std::string>& data) {
                             if (!data)
                               result.clear();
                             std::move(callback).Run(result);
                           },
                           std::move(result), std::move(callback)));
}

void ClipboardHostImpl::ReadPng(ui::ClipboardBuffer clipboard_buffer,
                                ReadPngCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(mojo_base::BigBuffer());
    return;
  }
  auto data_dst = CreateDataEndpoint();
  ui::Clipboard::GetForCurrentThread()->ReadPng(
      clipboard_buffer, data_dst.get(),
      base::BindOnce(&ClipboardHostImpl::OnReadPng,
                     weak_ptr_factory_.GetWeakPtr(), clipboard_buffer,
                     std::move(callback)));
}

void ClipboardHostImpl::OnReadPng(ui::ClipboardBuffer clipboard_buffer,
                                  ReadPngCallback callback,
                                  const std::vector<uint8_t>& data) {
  std::string string_data(data.begin(), data.end());
  PasteIfPolicyAllowed(
      clipboard_buffer, ui::ClipboardFormatType::PngType(),
      std::move(string_data),
      base::BindOnce(
          [](std::vector<uint8_t> data, ReadPngCallback callback,
             const absl::optional<std::string>& allowed) {
            if (!allowed) {
              std::move(callback).Run(mojo_base::BigBuffer());
              return;
            }
            std::move(callback).Run(mojo_base::BigBuffer(data));
          },
          std::move(data), std::move(callback)));
}

void ClipboardHostImpl::ReadFiles(ui::ClipboardBuffer clipboard_buffer,
                                  ReadFilesCallback callback) {
  blink::mojom::ClipboardFilesPtr result = blink::mojom::ClipboardFiles::New();
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::move(result));
    return;
  }

  ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
  std::vector<ui::FileInfo> filenames;
  auto data_dst = CreateDataEndpoint();
  clipboard->ReadFilenames(clipboard_buffer, data_dst.get(), &filenames);

  // Convert the vector of ui::FileInfo into a vector of std::string so that
  // it can be passed to PerformPasteIfContentAllowed() for analysis.  When
  // the latter is called with ui::ClipboardFormatType::FilenamesType() the
  // data to be analyzed is expected to be a newline-separated list of full
  // paths.
  std::vector<std::string> paths;
  paths.reserve(filenames.size());
  std::transform(
      filenames.cbegin(), filenames.cend(), std::back_inserter(paths),
      [](const ui::FileInfo& info) { return info.path.AsUTF8Unsafe(); });
  std::string data = base::JoinString(paths, "\n");

  // This code matches the drag-and-drop DataTransfer code in
  // RenderWidgetHostImpl::DragTargetDrop().

  // Call PrepareDataTransferFilenamesForChildProcess() to register files so
  // they can be accessed by the renderer.
  RenderProcessHost* process = render_frame_host().GetProcess();
  result->file_system_id = PrepareDataTransferFilenamesForChildProcess(
      filenames, ChildProcessSecurityPolicyImpl::GetInstance(),
      process->GetID(), process->GetStoragePartition()->GetFileSystemContext());

  // Convert to DataTransferFiles which creates the access token for each file.
  StoragePartitionImpl* storage_partition = static_cast<StoragePartitionImpl*>(
      render_frame_host().GetProcess()->GetStoragePartition());
  std::vector<blink::mojom::DataTransferFilePtr> files =
      FileInfosToDataTransferFiles(
          filenames, storage_partition->GetFileSystemAccessManager(),
          process->GetID());
  std::move(files.begin(), files.end(), std::back_inserter(result->files));

  PerformPasteIfContentAllowed(
      clipboard->GetSequenceNumber(clipboard_buffer),
      ui::ClipboardFormatType::FilenamesType(), std::move(data),
      base::BindOnce(
          [](blink::mojom::ClipboardFilesPtr result, ReadFilesCallback callback,
             const absl::optional<std::string>& data) {
            if (!data) {
              result->files.clear();
              result->file_system_id->clear();
            } else {
              // A subset of the files can be copied.  Remove any files that
              // should be blocked.  First build a list of the files that are
              // allowed.
              std::vector<std::string> allowed_files_vector =
                  base::SplitString(data.value(), "\n", base::TRIM_WHITESPACE,
                                    base::SPLIT_WANT_NONEMPTY);
              std::set<std::string> allowed_files(
                  std::move_iterator(allowed_files_vector.begin()),
                  std::move_iterator(allowed_files_vector.end()));

              for (auto it = result->files.begin();
                   it != result->files.end();) {
                if (allowed_files.find(it->get()->path.AsUTF8Unsafe()) !=
                    allowed_files.end()) {
                  it = std::next(it);
                } else {
                  it = result->files.erase(it);
                }
              }
            }
            std::move(callback).Run(std::move(result));
          },
          std::move(result), std::move(callback)));
}

void ClipboardHostImpl::ReadCustomData(ui::ClipboardBuffer clipboard_buffer,
                                       const std::u16string& type,
                                       ReadCustomDataCallback callback) {
  if (!IsRendererPasteAllowed(render_frame_host())) {
    std::move(callback).Run(std::u16string());
    return;
  }
  std::u16string result;
  auto data_dst = CreateDataEndpoint();
  ui::Clipboard::GetForCurrentThread()->ReadCustomData(clipboard_buffer, type,
                                                       data_dst.get(), &result);

  std::string data = base::UTF16ToUTF8(result);
  PasteIfPolicyAllowed(
      clipboard_buffer, ui::ClipboardFormatType::WebCustomDataType(),
      std::move(data),
      base::BindOnce(
          [](std::u16string result, ReadCustomDataCallback callback,
             const absl::optional<std::string>& data) {
            if (!data)
              result.clear();
            std::move(callback).Run(result);
          },
          std::move(result), std::move(callback)));
}

void ClipboardHostImpl::WriteText(const std::u16string& text) {
  CopyIfAllowed(
      text.size() * sizeof(std::u16string::value_type),
      base::BindOnce(&ui::ScopedClipboardWriter::WriteText,
                     base::Unretained(clipboard_writer_.get()), text));
}

void ClipboardHostImpl::WriteHtml(const std::u16string& markup,
                                  const GURL& url) {
  CopyIfAllowed(markup.size() * sizeof(std::u16string::value_type),
                base::BindOnce(&ui::ScopedClipboardWriter::WriteHTML,
                               base::Unretained(clipboard_writer_.get()),
                               markup, url.spec()));
}

void ClipboardHostImpl::WriteSvg(const std::u16string& markup) {
  clipboard_writer_->WriteSvg(markup);
}

void ClipboardHostImpl::WriteSmartPasteMarker() {
  clipboard_writer_->WriteWebSmartPaste();
}

void ClipboardHostImpl::WriteCustomData(
    const base::flat_map<std::u16string, std::u16string>& data) {
  base::Pickle pickle;
  ui::WriteCustomDataToPickle(data, &pickle);
  clipboard_writer_->WritePickledData(
      pickle, ui::ClipboardFormatType::WebCustomDataType());
}

void ClipboardHostImpl::WriteBookmark(const std::string& url,
                                      const std::u16string& title) {
  clipboard_writer_->WriteBookmark(title, url);
}

void ClipboardHostImpl::WriteImage(const SkBitmap& bitmap) {
  clipboard_writer_->WriteImage(bitmap);
}

void ClipboardHostImpl::CommitWrite() {
  clipboard_writer_ = std::make_unique<ui::ScopedClipboardWriter>(
      ui::ClipboardBuffer::kCopyPaste, CreateDataEndpoint());
}

bool ClipboardHostImpl::IsUnsanitizedCustomFormatContentAllowed() {
  if (!base::FeatureList::IsEnabled(blink::features::kClipboardCustomFormats)) {
    mojo::ReportBadMessage("Custom format read/write is not enabled.");
    return false;
  }

  return render_frame_host().HasTransientUserActivation();
}

void ClipboardHostImpl::ReadAvailableCustomAndStandardFormats(
    ReadAvailableCustomAndStandardFormatsCallback callback) {
  if (!IsUnsanitizedCustomFormatContentAllowed())
    return;
  std::vector<std::u16string> format_types =
      ui::Clipboard::GetForCurrentThread()
          ->ReadAvailableStandardAndCustomFormatNames(
              ui::ClipboardBuffer::kCopyPaste, CreateDataEndpoint().get());
  std::move(callback).Run(format_types);
}

void ClipboardHostImpl::ReadUnsanitizedCustomFormat(
    const std::u16string& format,
    ReadUnsanitizedCustomFormatCallback callback) {
  if (!IsUnsanitizedCustomFormatContentAllowed())
    return;
  // `kMaxFormatSize` includes the null terminator as well so we check if
  // the `format` size is strictly less than `kMaxFormatSize` or not.
  if (format.length() >= blink::mojom::ClipboardHost::kMaxFormatSize)
    return;

  // Extract the custom format names and then query the web custom format
  // corresponding to the MIME type.
  std::string format_name = base::UTF16ToASCII(format);
  auto data_endpoint = CreateDataEndpoint();
  std::map<std::string, std::string> custom_format_names =
      ui::Clipboard::GetForCurrentThread()->ExtractCustomPlatformNames(
          ui::ClipboardBuffer::kCopyPaste, data_endpoint.get());
  std::string web_custom_format_string;
  if (custom_format_names.find(format_name) != custom_format_names.end())
    web_custom_format_string = custom_format_names[format_name];
  if (web_custom_format_string.empty())
    return;

  std::string result;
  ui::Clipboard::GetForCurrentThread()->ReadData(
      ui::ClipboardFormatType::GetType(web_custom_format_string),
      data_endpoint.get(), &result);
  if (result.size() >= blink::mojom::ClipboardHost::kMaxDataSize)
    return;
  base::span<const uint8_t> span = base::as_bytes(base::make_span(result));
  mojo_base::BigBuffer buffer = mojo_base::BigBuffer(span);
  std::move(callback).Run(std::move(buffer));
}

void ClipboardHostImpl::WriteUnsanitizedCustomFormat(
    const std::u16string& format,
    mojo_base::BigBuffer data) {
  if (!IsUnsanitizedCustomFormatContentAllowed())
    return;
  // `kMaxFormatSize` & `kMaxDataSize` includes the null terminator.
  if (format.length() >= blink::mojom::ClipboardHost::kMaxFormatSize)
    return;
  if (data.size() >= blink::mojom::ClipboardHost::kMaxDataSize)
    return;

  // The `format` is mapped to user agent defined web custom format before
  // writing to the clipboard. This happens in
  // `ScopedClipboardWriter::WriteData`.
  clipboard_writer_->WriteData(format, std::move(data));
}

void ClipboardHostImpl::PasteIfPolicyAllowed(
    ui::ClipboardBuffer clipboard_buffer,
    const ui::ClipboardFormatType& data_type,
    std::string data,
    IsClipboardPasteContentAllowedCallback callback) {
  if (data.empty()) {
    std::move(callback).Run(data);
    return;
  }
  const size_t data_size = data.size();
  auto policy_cb =
      base::BindOnce(&ClipboardHostImpl::PasteIfPolicyAllowedCallback,
                     weak_ptr_factory_.GetWeakPtr(), clipboard_buffer,
                     data_type, std::move(data), std::move(callback));

  if (ui::DataTransferPolicyController::HasInstance()) {
    ui::DataTransferPolicyController::Get()->PasteIfAllowed(
        ui::Clipboard::GetForCurrentThread()->GetSource(clipboard_buffer),
        CreateDataEndpoint().get(), data_size, &render_frame_host(),
        std::move(policy_cb));
    return;
  }
  std::move(policy_cb).Run(/*is_allowed=*/true);
}

void ClipboardHostImpl::PasteIfPolicyAllowedCallback(
    ui::ClipboardBuffer clipboard_buffer,
    const ui::ClipboardFormatType& data_type,
    std::string data,
    IsClipboardPasteContentAllowedCallback callback,
    bool is_allowed) {
  if (is_allowed) {
    PerformPasteIfContentAllowed(
        ui::Clipboard::GetForCurrentThread()->GetSequenceNumber(
            clipboard_buffer),
        data_type, std::move(data), std::move(callback));
  } else {
    // If not allowed, then don't proceed with content checks.
    std::move(callback).Run(absl::nullopt);
  }
}

void ClipboardHostImpl::PerformPasteIfContentAllowed(
    const ui::ClipboardSequenceNumberToken& seqno,
    const ui::ClipboardFormatType& data_type,
    std::string data,
    IsClipboardPasteContentAllowedCallback callback) {
  CleanupObsoleteRequests();
  // Add |callback| to the callbacks associated to the sequence number, adding
  // an entry to the map if one does not exist.
  auto& request = is_allowed_requests_[seqno];
  if (request.AddCallback(std::move(callback)))
    StartIsPasteContentAllowedRequest(seqno, data_type, std::move(data));
}

void ClipboardHostImpl::StartIsPasteContentAllowedRequest(
    const ui::ClipboardSequenceNumberToken& seqno,
    const ui::ClipboardFormatType& data_type,
    std::string data) {
  static_cast<RenderFrameHostImpl&>(render_frame_host())
      .IsClipboardPasteContentAllowed(
          data_type, data,
          base::BindOnce(&ClipboardHostImpl::FinishPasteIfContentAllowed,
                         weak_ptr_factory_.GetWeakPtr(), seqno));
}

void ClipboardHostImpl::FinishPasteIfContentAllowed(
    const ui::ClipboardSequenceNumberToken& seqno,
    const absl::optional<std::string>& data) {
  if (is_allowed_requests_.count(seqno) == 0)
    return;

  auto& request = is_allowed_requests_[seqno];
  request.Complete(std::move(data));
}

void ClipboardHostImpl::CopyIfAllowed(size_t data_size_in_bytes,
                                      CopyAllowedCallback callback) {
  std::u16string replacement_data;
  if (GetContentClient()->browser()->IsClipboardCopyAllowed(
          render_frame_host().GetBrowserContext(),
          render_frame_host().GetLastCommittedURL(), data_size_in_bytes,
          replacement_data)) {
    std::move(callback).Run();
  } else {
    clipboard_writer_->WriteText(replacement_data);
  }
}

void ClipboardHostImpl::CleanupObsoleteRequests() {
  for (auto it = is_allowed_requests_.begin();
       it != is_allowed_requests_.end();) {
    it = it->second.IsObsolete(base::Time::Now())
             ? is_allowed_requests_.erase(it)
             : std::next(it);
  }
}

std::unique_ptr<ui::DataTransferEndpoint>
ClipboardHostImpl::CreateDataEndpoint() {
  if (render_frame_host().GetBrowserContext()->IsOffTheRecord()) {
    return nullptr;
  }
  return std::make_unique<ui::DataTransferEndpoint>(
      render_frame_host().GetMainFrame()->GetLastCommittedURL(),
      render_frame_host().HasTransientUserActivation());
}
}  // namespace content


text:
"""\
===============================================================
Parse entities, attributes and relations definition received
===============================================================

Parse entities and relations definition received, one line one time.

1. Definition format
1.) Empty line (including any number of white spaces)
2.) Line starting with # to comment
3.) Entity definition
Example:
--------
person mum
person dad gender=male,shape=rect,width=80,height=80
person son gender="male",photo="../Files/son.gif,width=60,height=60"
person daughter radius=100
4.) Relation definition
Example:
--------
childof(mum, son)

2. NOTE:
1.) Any number of spaces can exist before, after and between the above line
Example:
--------
  person    mum
     childof  (  mum  , son  )
2.) Parse one line one time and then send out
3.) Entity definition needs to come before relation definition
if the relations definition uses the entity
4.) When encountering repeated entity, it will update its attributes rather than
create a new one.
"""

def parseEntity(entityLine):
    """ parse entity line """
    result = entityLine.split()
    #entity_ID = result[0]+'_'+result[1]
    entity_name = result[1]
    #particle = '-'
    particle = 'GenericParticle'
    if len(result) == 3:
        attributes = result[2]
        #attributes = attributes.lower()
        attributes = attributes.replace('gender','color')
        attributes = attributes.replace('female','pink')
        attributes = attributes.replace('male','blue')
        attributes = attributes.replace('photo','pic')
        attributes = attributes + ',type=' + result[0]
    else:
        attributes = 'type=' + result[0]
    return "ADD NODE %s %s auto %s %s" % (entity_name,entity_name,particle,attributes)

def parseUpdatedEntity(entityLine):
    """ parse entity line """
    result = entityLine.split()
    #entity_ID = result[0]+'_'+result[1]
    entity_name = result[1]
    #particle = '-'
    #particle = 'GenericParticle'
    if len(result) == 3:
        attributes = result[2]
        #attributes = attributes.lower()
        attributes = attributes.replace('gender','color')
        attributes = attributes.replace('female','pink')
        attributes = attributes.replace('male','blue')
        attributes = attributes.replace('photo','pic')
        attributes = attributes.replace('name','label')
    else:
        attributes = 'label=' + entity_name
    return "UPDATE NODE %s %s" % (entity_name,attributes)

def parseRelation(relationLine):
    """ parse relation line """
    result = relationLine.split('(')
    relation = result[0].strip()
    entities_str = result[1].rstrip(')')
    entities_list = entities_str.split(',')
    src = entities_list[0].strip()
    dst = entities_list[1].strip()
    return "ADD LINK %s %s %s" % (src,dst,relation)

import re

import Axon
from Axon.Ipc import producerFinished, shutdownMicroprocess

class RelationAttributeParser(Axon.Component.component):
    """\
======================================================================
A component to parse entities, attributes and relations definition
======================================================================
"""
    def shutdown(self):
        """ shutdown method: define when to shun down"""
        while self.dataReady("control"):
            data = self.recv("control")
            if isinstance(data, producerFinished) or isinstance(data, shutdownMicroprocess):
                self.shutdown_mess = data
                return True
        return False

    def main(self):
        """ main method: do stuff """

        previousNodes = []

        # Put all codes within the loop, so that others can be run even it doesn't shut down
        while not self.shutdown():
            X = []
            links = []
            nodes = []
            updatedNodes = []
            while not self.anyReady():
                self.pause()
                yield 1

            while self.dataReady("inbox"):
                L = self.recv("inbox")
                if L.strip() == "": continue # empty line
                if L.lstrip()[0] == "#": continue # comment
                X.append(L.strip())
            #yield 1

            for item in X:
                if re.match('(.+)\((.+),(.+)\)',item): # relation
                    command = parseRelation(item)
                    links.append(command)
                else:
                    isRepeated = False
                    for node in previousNodes:
                        if item.split()[1] == node.split()[2]:
                            isRepeated = True
                    if not isRepeated: # new entity
                        command = parseEntity(item)
                        nodes.append(command)
                        previousNodes.append(command)
                    else: # old entity
                        command = parseUpdatedEntity(item)
                        updatedNodes.append(command)
            #yield 1
            for node in nodes:
                self.send(node, "outbox")
            for updatedNode in updatedNodes:
                self.send(updatedNode, "outbox")
            for link in links:
                self.send(link, "outbox")
            yield 1

        self.send(self.shutdown_mess,"signal")

if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists
    from Kamaelia.Util.Console import ConsoleReader,ConsoleEchoer
    from GenericTopologyViewer import GenericTopologyViewer
    from Kamaelia.Chassis.Graphline import Graphline

    # Data can be from both DataSource and console inputs
    Graphline(
        CONSOLEREADER = ConsoleReader(),
        DATASOURCE = DataSource(["  person  mum   gender=female,photo=../Files/mum.jpg,width=80,height=80 ", '  ', """
                    """, 'person dad gender=male,shape=rect,width=80,height=80',
                    '  person  son   gender=male,photo=../Files/son.gif,width=60,height=60',
                    'person son photo=../Files/son1.gif',
                     'person daughter radius=20', 'person daughter radius=100',
                     ' childof  (  mum  , son  ) ', 'childof(mum, daughter)',
                     'childof(dad, son)', 'childof(dad, daughter)']),
        PARSER = RelationAttributeParser(),
        TOKENS = lines_to_tokenlists(),
        VIEWER = GenericTopologyViewer(),
        CONSOLEECHOER = ConsoleEchoer(),
    linkages = {
        ("CONSOLEREADER","outbox") : ("PARSER","inbox"),
        ("DATASOURCE","outbox") : ("PARSER","inbox"),
        ("PARSER","outbox") : ("TOKENS","inbox"),
        ("TOKENS","outbox")   : ("VIEWER","inbox"),
        ("VIEWER","outbox")  : ("CONSOLEECHOER","inbox"),

    }
).run()


text:
using namespace fl::metis;
using namespace fl::metis::manager;
using namespace fl::utils;
using fl::db::ESC;
using fl::chrono::Time;

namespace EIndexRangeFlds
{
	enum EIndexRangeFlds
	{
		ID,
		INDEXID,
		RANGE_INDEX,
		MANAGERID,
		STORAGES
	};
};

const char * const INDEX_RANGE_SQL = "SELECT id, indexID, rangeIndex, managerID, storageIDs FROM index_range";

Range::Range(class RangeIndex *parent, MysqlResult *res, ClusterManager &clusterManager)
	: _parent(parent),
		_rangeID(res->get<decltype(_rangeID)>(EIndexRangeFlds::ID)),
		_rangeIndex(res->get<decltype(_rangeIndex)>(EIndexRangeFlds::RANGE_INDEX)),
		_managerID(res->get<decltype(_managerID)>(EIndexRangeFlds::MANAGERID))
{
	TServerIDList storageIds;
	if (explode<TServerIDList::value_type>(res->get(EIndexRangeFlds::STORAGES), storageIds)) {
		clusterManager.findStorages(storageIds, _storages);
	}
}

TLevel Range::level() const
{
	return _parent->level();
}

TSubLevel  Range::subLevel() const
{
	return _parent->subLevel();
}

void Range::update(Range *src)
{
	_managerID = src->_managerID;
	std::swap(_storages, src->_storages);
}

StorageNode *Range::getStorageForCopy(const TSize size, Config *config, class ClusterManager &clusterManager,
	TStorageList &storages, bool &wasAdded)
{
	for (auto s = _storages.begin(); s != _storages.end(); s++) {
		if ((*s)->canPut(size)) {
			bool found = false;
			for (auto existsStorage = storages.begin(); existsStorage != storages.end(); existsStorage++) {
				if ((*existsStorage)->groupID() == (*s)->groupID()) {
					found = true;
					break;
				}
			}
			if (!found) {
				return (*s);
			}
		}
	}
	wasAdded = true;
	return _addNewNode(config, clusterManager, size, storages);
}

StorageNode *Range::_addNewNode(Config *config, class ClusterManager &clusterManager, const TSize size,
	TStorageList &storages)
{
	StorageNode *newNode = clusterManager.findFreeStorage(size, storages);
	if (!newNode)
		return NULL;
	Mysql sql;
	if (!config->connectDb(sql)) {
		log::Error::L("Range::_addNewNode: Cannot connect to db, check db parameters\n");
		return NULL;
	}
	auto sqlBuf = sql.createQuery();
	sqlBuf << "UPDATE index_range SET storageIDs='";
	for (auto s = _storages.begin(); s != _storages.end(); s++) {
		sqlBuf << (*s)->id() << ",";
	}
	sqlBuf << newNode->id() << "' WHERE id=" << _rangeID << " AND storageIDs='";
	for (auto s = _storages.begin(); s != _storages.end(); s++) {
		sqlBuf << (*s)->id() << ",";
	}
	if (!_storages.empty())
		sqlBuf.trimLast();
	sqlBuf << '\'';
	if (!sql.execute(sqlBuf) && !sql.affectedRows())
		return NULL;

	_storages.push_back(newNode);

	return newNode;
}

bool Range::getPutStorages(const TSize size, Config *config, class ClusterManager &clusterManager,
	TStorageList &storages, bool &wasAdded)
{
	for (auto s = _storages.begin(); s != _storages.end(); s++) {
		if ((*s)->canPut(size)) {
			bool found = false;
			for (auto existsStorage = storages.begin(); existsStorage != storages.end(); existsStorage++) {
				if ((*existsStorage)->groupID() == (*s)->groupID()) {
					found = true;
					break;
				}
			}
			if (!found) {
				storages.push_back(*s);
				if (storages.size() >= config->minimumCopies())
					return true;
			}
		}
	}
	StorageNode *newNode = _addNewNode(config, clusterManager, size, storages);
	if (newNode) {
		wasAdded = true;
		storages.push_back(newNode);
		return true;
	} else {
		return false;
	}
}

namespace EIndexFlds
{
	enum EIndexFlds
	{
		ID,
		LEVEL,
		SUBLEVEL,
		STATUS,
		RANGE_SIZE,
	};
};
const char * const INDEX_SQL = "SELECT id, level, subLevel, status, rangeSize FROM `index`";

RangeIndex::RangeIndex(MysqlResult *res)
	: _level(res->get<decltype(_level)>(EIndexFlds::LEVEL)),
		_subLevel(res->get<decltype(_subLevel)>(EIndexFlds::SUBLEVEL)),
		_id(res->get<decltype(_id)>(EIndexFlds::ID)),
		_status(res->get<decltype(_status)>(EIndexFlds::STATUS)),
		_rangeSize(res->get<decltype(_rangeSize)>(EIndexFlds::RANGE_SIZE))
{
}

void RangeIndex::addNL(TRangePtr &range)
{
	auto res = _ranges.emplace(range->rangeIndex(), range);
	if (!res.second)
		res.first->second->update(range.get());
}

TItemKey RangeIndex::calcRangeIndex(const TItemKey itemKey)
{
	return itemKey / _rangeSize;
}

bool RangeIndex::find(const TItemKey rangeIndex, TRangePtr &range)
{
	AutoMutex autoSync(&_sync);
	auto f = _ranges.find(rangeIndex);
	if (f == _ranges.end()) {
		return false;
	} else {
		range = f->second;
		return true;
	}
}

void RangeIndex::update(RangeIndex *src)
{
	_status = src->_status;
}

IndexManager::IndexManager(class Config *config)
	: _config(config)
{
}

bool IndexManager::_loadIndex(Mysql &sql)
{
	auto res = sql.query(INDEX_SQL);
	if (!res)	{
		log::Error::L("Cannot load information about index top levels\n");
		return false;
	}
	while (res->next()) {
		TRangeIndexPtr rangeIndex( new RangeIndex(res.get()));
		_add(rangeIndex);
	}
	log::Info::L("Load %u indexes\n", _indexRanges.size());
	return true;
}

void IndexManager::_addRange(TRangePtr &range)
{
	_ranges.emplace(range->rangeID(), range);
}

bool IndexManager::_loadIndexRanges(Mysql &sql, ClusterManager &clusterManager)
{
	auto res = sql.query(INDEX_RANGE_SQL);
	if (!res)	{
		log::Error::L("Cannot load information about index ranges\n");
		return false;
	}
	uint32_t c = 0;
	while (res->next()) {
		auto indexID = res->get<RangeIndex::TIndexID>(EIndexRangeFlds::INDEXID);
		auto f = _indexRanges.find(indexID);
		if (f == _indexRanges.end()) {
			log::Warning::L("Can't find index %u\n", indexID);
			continue;
		}
		c++;
		TRangePtr range(new Range(f->second.get(), res.get(), clusterManager));
		f->second->addNL(range);
		_addRange(range);
	}
	log::Info::L("Load %u index ranges\n", c);
	return true;
}

void IndexManager::_add(TRangeIndexPtr &rangeIndex)
{
	static TSubLevelMap empty;
	auto res = _index.emplace(rangeIndex->level(), empty);
	auto sublevelRes = res.first->second.emplace(rangeIndex->subLevel(), rangeIndex);
	if (!sublevelRes.second)
		sublevelRes.first->second->update(rangeIndex.get());

	_indexRanges.emplace(rangeIndex->id(), rangeIndex);
}

bool IndexManager::loadAll(Mysql &sql, ClusterManager &clusterManager)
{
	if (!_loadIndex(sql))
		return false;

	if (!_loadIndexRanges(sql, clusterManager))
		return false;

	return true;
}

bool IndexManager::parseURL(const std::string &host, const std::string &fileName, ItemLevelIndex &item, TCrc &crc)
{
	bzero(&item, sizeof(item));
	const char *pFileName = fileName.c_str();
	char *pEnd = NULL;
	if (*pFileName == '/')
		pFileName++;
	item.level = strtoul(pFileName, &pEnd, 10);
	if (!pEnd || (*pEnd != '/')) {
		log::Warning::L("Can't find level in %s\n", fileName.c_str());
		return false;
	}
	pFileName = pEnd + 1;
	item.subLevel = strtoul(pFileName, &pEnd, 10);
	if (*pEnd != '/') {
		return true;
	}
	pFileName = pEnd + 1;
	item.itemKey = convertStringTo<decltype(item.itemKey)>(pFileName, &pEnd, 10);
	crc = 0;
	if (!pEnd || (*pEnd != '_'))
		return true;
	pFileName = pEnd + 1;
	crc = convertStringTo<TCrc>(pFileName, &pEnd, 16);
	return true;
}

bool RangeIndex::loadRange(TRangePtr &range, const TItemKey rangeIndex, IndexManager *index,
	ClusterManager &clusterManager, Mysql &sql)
{
	auto sqlQuery = sql.createQuery();
	sqlQuery << INDEX_RANGE_SQL << " WHERE indexID=" << ESC << _id << " AND rangeIndex=" << ESC << rangeIndex;
	auto res = sql.query(sqlQuery);
	if (!res || !res->next())	{
		log::Error::L("Cannot load information about index ranges\n");
		return false;
	}
	range.reset(new Range(this, res.get(), clusterManager));
	add(range);
	index->addRange(range);
	return true;
}

bool IndexManager::find(const ItemLevelIndex &item, TRangePtr &range)
{
	AutoMutex autoSync(&_sync);
	auto level = _index.find(item.level);
	if (level == _index.end()) {
		log::Warning::L("Can't find level %u\n", item.level);
		return false;
	}
	auto subLevel = level->second.find(item.subLevel);
	if (subLevel == level->second.end()) {
		log::Warning::L("Can't find level %u / subLevel %u\n", item.level, item.subLevel);
		return false;
	}
	TRangeIndexPtr rangesIndex = subLevel->second;
	autoSync.unLock();

	auto rangeIndex = rangesIndex->calcRangeIndex(item.itemKey);
	if (rangesIndex->find(rangeIndex, range)) {
		return true;
	}
	else
		return false;
}

bool IndexManager::fillAndAdd(ItemHeader &item, TRangePtr &range, ClusterManager &clusterManager, bool &wasAdded)
{
	AutoMutex autoSync(&_sync);
	auto level = _index.find(item.level);
	if (level == _index.end()) {
		log::Warning::L("Can't find level %u\n", item.level);
		return false;
	}
	auto subLevel = level->second.find(item.subLevel);
	if (subLevel == level->second.end()) {
		log::Warning::L("Can't find level %u / subLevel %u\n", item.level, item.subLevel);
		return false;
	}
	TRangeIndexPtr rangesIndex = subLevel->second;
	autoSync.unLock();

	auto rangeIndex = rangesIndex->calcRangeIndex(item.itemKey);
	if (!rangesIndex->find(rangeIndex, range)) {
		Mysql sql;
		if (!_config->connectDb(sql)) {
			log::Error::L("RangeIndex::fillAndAdd: Cannot connect to db, check db parameters\n");
			return false;
		}
		int64_t minLeftSpace = rangesIndex->rangeSize() * _config->averageItemSize();

		TServerIDList storageIDs;
		if (!clusterManager.findFreeStorages(_config->minimumCopies(), storageIDs, minLeftSpace)) {
			log::Error::L("RangeIndex::fillAndAdd: Cannot find free storages for a new range\n");
			return false;
		}
		TServerID managerID = clusterManager.findFreeManager();
		auto sqlBuf = sql.createQuery();
		sqlBuf << "INSERT IGNORE INTO `index_range` SET indexID=" << ESC << rangesIndex->id() << ",rangeIndex="
			<< ESC << rangeIndex << ",storageIDs=" << ESC << storageIDs << ",managerID=" << ESC << managerID;
		if (!sql.execute(sqlBuf))
			return false;

		wasAdded = true;
		if (!rangesIndex->loadRange(range, rangeIndex, this, clusterManager, sql))
			return false;
	}
	item.rangeID = range->rangeID();
	item.timeTag = genNewTimeTag();
	return true;
}

uint32_t IndexManager::_curOperation  = 0;

ModTimeTag IndexManager::genNewTimeTag()
{
	Time curTime;
	ModTimeTag tag;
	tag.modTime = curTime.unix();
	tag.op = __sync_add_and_fetch(&_curOperation, 1);
	return tag;
}

bool IndexManager::addLevel(const TLevel levelID, const TSubLevel subLevelID)
{
	AutoMutex autoSync(&_sync);
	auto level = _index.find(levelID);
	if (level != _index.end()) { // create new level
		auto subLevel = level->second.find(subLevelID);
		if (subLevel != level->second.end()) {
			log::Error::L("Level %u / subLevel %s is already exists\n", levelID, subLevelID);
			return false;
		}
	}
	autoSync.unLock();

	Mysql sql;
	if (!_config->connectDb(sql)) {
		log::Error::L("Index::addLevel: Cannot connect to db, check db parameters\n");
		return false;
	}
	auto sqlBuf = sql.createQuery();
	sqlBuf << "INSERT IGNORE INTO `index` SET level=" << ESC << levelID << ",subLevel=" << ESC << subLevelID;
	if (!sql.execute(sqlBuf))
		return false;

	return loadLevel(levelID, subLevelID, sql);
}

bool IndexManager::loadLevel(const TLevel level, const TSubLevel subLevel, Mysql &sql)
{
	auto sqlBuf = sql.createQuery();
	sqlBuf << INDEX_SQL << " WHERE level=" << ESC << level << " AND subLevel=" << ESC << subLevel;
	auto res = sql.query(sqlBuf);
	if (!res || !res->next()) {
		log::Error::L("Index::addLevel: Cannot load index.id from db\n");
		return false;
	}
	AutoMutex autoSync(&_sync);
	TRangeIndexPtr rangeIndex(new RangeIndex(res.get()));
	_add(rangeIndex);
	return true;
}

StorageNode *IndexManager::getStorageForCopy(const TRangeID rangeID, const TSize size, class ClusterManager &clusterManager,
	TStorageList &storages, bool &wasAdded)
{
	wasAdded = false;
	TRangePtr range;
	AutoMutex autoSync(&_sync);
	auto f = _ranges.find(rangeID);
	if (f == _ranges.end()) {
		log::Fatal::L("Try find put storage for unknown rangeID %u\n", rangeID);
		return NULL;
	}
	range = f->second;
	autoSync.unLock();
	return range->getStorageForCopy(size, _config, clusterManager, storages, wasAdded);
}

bool IndexManager::getPutStorages(const TRangeID rangeID, const TSize size, class ClusterManager &clusterManager,
	TStorageList &storages, bool &wasAdded)
{
	wasAdded = false;
	TRangePtr range;
	AutoMutex autoSync(&_sync);
	auto f = _ranges.find(rangeID);
	if (f == _ranges.end()) {
		log::Fatal::L("Try find put storage for unknown rangeID %u\n", rangeID);
		return NULL;
	}
	range = f->second;
	autoSync.unLock();
	return range->getPutStorages(size, _config, clusterManager, storages, wasAdded);
}

TRangePtrVector IndexManager::getControlledRanges()
{
	TRangePtrVector ranges;
	TServerID managerID = _config->serverID();
	AutoMutex autoSync(&_sync);
	for (auto r = _ranges.begin(); r != _ranges.end(); r++) {
		if (r->second->managerID() == managerID)
			ranges.push_back(r->second);
	}
	return ranges;
}


text:
/**
 *  Created on: 7 Jun 2014
 *      Author: swale
 */

#ifndef CLIENTBASEIMPL_H_
#define CLIENTBASEIMPL_H_

#include "ClientBase.h"

/*
#ifdef _WINDOWS
template<typename K, typename V>
struct hash_map
{
  typedef std::map<K, V> type;
};
#else
#include <tr1/unordered_map>

template<typename K, typename V>
struct hash_map
{
  typedef std::tr1::unordered_map<K, V> type;
};
#endif
*/
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>

template<typename K, typename V>
struct hash_map {
  typedef boost::unordered_map<K, V> type;
};

template<typename K>
struct hash_set {
  typedef boost::unordered_set<K> type;
};

#endif /* CLIENTBASEIMPL_H_ */


text:
package com.intellij.tasks.actions;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.TaskManager;
import com.intellij.tasks.config.TaskSettings;
import consulo.actionSystem.ex.ComboBoxButtonImpl;
import consulo.ui.annotation.RequiredUIAccess;

import javax.annotation.Nonnull;
import javax.swing.*;

/**
 * @author Dmitry Avdeev
 */
public class SwitchTaskCombo extends ComboBoxAction implements DumbAware
{
	@Nonnull
	public JComponent createCustomComponent(final Presentation presentation)
	{
		ComboBoxButtonImpl button = new ComboBoxButtonImpl(this, presentation);
		return button;
	}

	@Nonnull
	@Override
	public JBPopup createPopup(@Nonnull JComponent component, @Nonnull DataContext context, @Nonnull Runnable onDispose)
	{
		return SwitchTaskAction.createPopup(context, onDispose, false);
	}

	@RequiredUIAccess
	@Override
	public void update(@Nonnull AnActionEvent e)
	{
		Presentation presentation = e.getPresentation();
		Project project = e.getData(CommonDataKeys.PROJECT);
		ComboBoxButtonImpl button = (ComboBoxButtonImpl) presentation.getClientProperty(CustomComponentAction.COMPONENT_KEY);
		if(project == null || project.isDefault() || project.isDisposed() || button == null)
		{
			presentation.setEnabled(false);
			presentation.setText("");
			presentation.setIcon(null);
		}
		else
		{
			TaskManager taskManager = TaskManager.getManager(project);
			LocalTask activeTask = taskManager.getActiveTask();
			presentation.setVisible(true);
			presentation.setEnabled(true);

			if(isImplicit(activeTask) && taskManager.getAllRepositories().length == 0 && !TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO)
			{
				presentation.setVisible(false);
			}
			else
			{
				String s = getText(activeTask);
				presentation.setText(s);
				presentation.setIcon(activeTask.getIcon());
				presentation.setDescription(activeTask.getSummary());
			}
		}
	}

	@Nonnull
	@Override
	protected DefaultActionGroup createPopupActionGroup(JComponent button)
	{
		throw new IllegalArgumentException();
	}

	private static boolean isImplicit(LocalTask activeTask)
	{
		return activeTask.isDefault() && Comparing.equal(activeTask.getCreated(), activeTask.getUpdated());
	}

	private static String getText(LocalTask activeTask)
	{
		String text = activeTask.getPresentableName();
		return StringUtil.first(text, 50, true);
	}
}


text:
placehold.it placeholder snippet for atom

<img src="http://placehold.it/WIDTHxHEIGHT" alt="" />

**tabTrigger** : `placehold`

![](http://gifyu.com/images/ezgif-372213323.gif)

fork from [fakeimg-atom-snippet](https://github.com/AlexW867/fakeimg-atom-snippet)


text:
var Backbone = require('backbone'),
  _ = require('underscore');

var FooView = Backbone.View.extend({
  id: 'foo'
});

// A comment.
// Another comment.
module.exports = FooView;


text:
module PowerShop
  class CategoriesController < ApplicationController
    def show
      @category = ::Category.find(params[:id])

      @products = @category
                    .products_with_child_categories
                    .where(active: true)
                    .page(params[:page])
                    .per(products_per_page)
    end

    private

    def products_per_page
      1
    end
  end
end


text:
<?php

namespace Magento\Framework\Interception\Test\Unit\Custom\Module\Model;

class ItemContainer
{
    /**
     * @return string
     */
    public function getName()
    {
        return 'item_container';
    }
}


text:
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var karma = require('karma').server;
var insert = require('gulp-insert');
var sourcemaps = require('gulp-sourcemaps');
var packageJson = require('./package.json');
var pluginList = ['stSearch', 'stSelectRow', 'stSort', 'stPagination', 'stPipe'];
var disFolder = './dist/';
var src = (['smart-table.module', 'stConfig', 'stTable']).concat(pluginList).map(function (val) {
    return 'src/' + val + '.js';
});

src.push('src/bottom.txt');
src.unshift('src/top.txt');

gulp.task('karma-CI', function (done) {
    var conf = require('./test/karma.common.js');
    conf.singleRun = true;
    conf.browsers = ['PhantomJS'];
    conf.basePath = './';
    karma.start(conf, done);
});

gulp.task('uglify', function () {
    gulp.src(src)
      .pipe(concat('smart-table.min.js'))
      .pipe(sourcemaps.init())
      .pipe(uglify())
      .pipe(sourcemaps.write('.'))
      .pipe(gulp.dest(disFolder));
});

gulp.task('concat', function () {
    gulp.src(src, { base: '.' })
      .pipe(concat('smart-table.js'))
      .pipe(gulp.dest(disFolder));
});

gulp.task('test', ['karma-CI']);

gulp.task('build',['test', 'uglify', 'concat'], function () {

    var version = packageJson.version;
    var string = '/** \n* @version ' + version + '\n* @license MIT\n*/\n';

    gulp.src(disFolder + '*.js')
        .pipe(insert.prepend(string))
        .pipe(gulp.dest(disFolder));
});


text:
#import <SpriteKit/SpriteKit.h>
#import "SKTTimingFunctions.h"

/**
 * Allows you to perform actions with custom timing functions.
 *
 * Unfortunately, SKAction does not have a concept of a timing function, so
 * we need to replicate the actions using SKTEffect subclasses.
 */
@interface SKTEffect : NSObject

@property (nonatomic, weak) SKNode *node;
@property (nonatomic, assign) NSTimeInterval duration;
@property (nonatomic, copy) SKTTimingFunction timingFunction;

+ (instancetype)effectWithNode:(SKNode *)node duration:(NSTimeInterval)duration;
- (instancetype)initWithNode:(SKNode *)node duration:(NSTimeInterval)duration;

- (void)update:(float)t;

@end

/**
 * Moves a node from its current position to a new position.
 */
@interface SKTMoveEffect : SKTEffect

+ (instancetype)effectWithNode:(SKNode *)node duration:(NSTimeInterval)duration startPosition:(CGPoint)startPosition endPosition:(CGPoint)endPosition;
- (instancetype)initWithNode:(SKNode *)node duration:(NSTimeInterval)duration startPosition:(CGPoint)startPosition endPosition:(CGPoint)endPosition;

@end

/**
 * Scales a node to a certain scale factor.
 */
@interface SKTScaleEffect : SKTEffect

+ (instancetype)effectWithNode:(SKNode *)node duration:(NSTimeInterval)duration startScale:(CGPoint)startScale endScale:(CGPoint)endScale;
- (instancetype)initWithNode:(SKNode *)node duration:(NSTimeInterval)duration startScale:(CGPoint)startScale endScale:(CGPoint)endScale;

@end

/**
 * Rotates a node to a certain angle.
 */
@interface SKTRotateEffect : SKTEffect

+ (instancetype)effectWithNode:(SKNode *)node duration:(NSTimeInterval)duration startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle;
- (instancetype)initWithNode:(SKNode *)node duration:(NSTimeInterval)duration startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle;

@end

/**
 * Wrapper that allows you to use SKTEffect objects as regular SKActions.
 */
@interface SKAction (SKTEffect)

+ (instancetype)actionWithEffect:(SKTEffect *)effect;

@end


text:
package datomisca
package macros

import scala.language.experimental.macros

import clojure.lang.Keyword

private[datomisca] trait ExtraMacros {
  /** Parse the string representation of a Clojure keyword into a [[Keyword]] object.
    *
    * Implemented as a macro that generates a keyword literal at compile time.
    *
    * {{{val kw = KW(":namespace/name")}}}
    *
    * @param str a Clojure keyword as a string
    * @return a Clojure [[Keyword]]
    */
  def KW(str: String): Keyword = macro MacroImpl.KWImpl
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<TITLE>
E-Index
</TITLE>

<META NAME="date" CONTENT="2010-03-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style">

      Overview
      Package
      Class
      Use
      Tree
      Deprecated
    Index
      Help

 PREV LETTER
 NEXT LETTER

  FRAMES
 NO FRAMES

  All Classes

A B C D E F G H I K L M N O P R S T U V W

E

equals(Object) -
Method in class org.deuce.transaction.tl2.field.ReadFieldAccess

exclude(String) -
Static method in class org.deuce.transform.asm.ExcludeIncludeStore

Exclude - Annotation Type in org.deuce.transform

EXCLUDE_DESC -
Static variable in class org.deuce.transform.asm.ClassTransformer

ExcludeIncludeStore - Class in org.deuce.transform.asm
Holds the include/exclude information for the classes to instrument.
execute(ReadFieldAccess) -
Method in interface org.deuce.transaction.tl2.ReadSet.ReadSetListener

execute(ReadFieldAccess) -
Method in interface org.deuce.transaction.tl2cm.ReadSet.ReadSetListener

ExternalFieldsHolder - Class in org.deuce.transform.asm
Creates a class to hold the fields address, used by the offline instrumentation.
ExternalFieldsHolder(String) -
Constructor for class org.deuce.transform.asm.ExternalFieldsHolder

      Overview
      Package
      Class
      Use
      Tree
      Deprecated
    Index
      Help

 PREV LETTER
 NEXT LETTER

  FRAMES
 NO FRAMES

  All Classes

A B C D E F G H I K L M N O P R S T U V W


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.

#nullable disable

using System;
using System.Collections.Concurrent;
using System.Composition;
using System.IO;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Host
{
    [ExportWorkspaceServiceFactory(typeof(IDocumentationProviderService), ServiceLayer.Default), Shared]
    internal sealed class DocumentationProviderServiceFactory : IWorkspaceServiceFactory
    {
        [ImportingConstructor]
        [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
        public DocumentationProviderServiceFactory()
        {
        }

        public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
            => new DocumentationProviderService();

        internal sealed class DocumentationProviderService : IDocumentationProviderService
        {
            private readonly ConcurrentDictionary<string, DocumentationProvider> _assemblyPathToDocumentationProviderMap =
                new();

            public DocumentationProvider GetDocumentationProvider(string assemblyPath)
            {
                if (assemblyPath == null)
                {
                    throw new ArgumentNullException(nameof(assemblyPath));
                }

                assemblyPath = Path.ChangeExtension(assemblyPath, "xml");
                if (!_assemblyPathToDocumentationProviderMap.TryGetValue(assemblyPath, out var provider))
                {
                    provider = _assemblyPathToDocumentationProviderMap.GetOrAdd(assemblyPath, XmlDocumentationProvider.CreateFromFile);
                }

                return provider;
            }
        }
    }
}


text:
using NT = CGAL::Quotient<CGAL::MP_Float>;
using Kernel = CGAL::Cartesian<NT>;
using Point_2 = Kernel::Point_2;
using Traits_2 = CGAL::Arr_segment_traits_2<Kernel>;
using Segment_2 = Traits_2::Curve_2;

namespace {

class TPointPrinterIterator {
public:
    TPointPrinterIterator& operator= (const Point_2& point) {
        std::cout << to_double(point.x()) << ' ' << to_double(point.y()) << '\n';
    }
    TPointPrinterIterator& operator*() { return *this; }
    TPointPrinterIterator& operator++() { return *this; }
    TPointPrinterIterator& operator++(int) { return *this; }
};

} // anonymous namespace

int main(int argc, char** argv) {
    // Construct the input segments.
    std::vector<Segment_2> segments;
    for (double x1,x2,y1,y2 = 0; !std::cin.eof();) {
        std::cin >> x1 >> y1;
        std::cin >> x2 >> y2;
        segments.push_back({
            Point_2(x1, y1), Point_2(x2, y2)
        });
    }
    std::cerr << "Read completed: " << segments.size() << std::endl;
    // Compute all intersection points.
    CGAL::compute_intersection_points(segments.begin(), segments.end(), TPointPrinterIterator());
    return 0;
}


text:
If you would like to contribute code to HAHA you can do so through GitHub by
forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions
and style in order to keep the code as readable as possible. Please also make
sure your code compiles by running:

``` shell
git submodule sync && git submodule update --init --recursive
mvn clean install
```

Before your code can be accepted into the project you must also sign the
[Individual Contributor License Agreement (CLA)][1].

 [1]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1


text:
package com.xiongyingqi.spring.mvc.bind.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 *
 * 该注解用于绑定请求参数(JSON字符串)
 *
 * @author Zhang Kaitao
 *
 */
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestJsonParam {

	/**
	 * 用于绑定的请求参数名字
	 */
	String value() default "";

	/**
	 * 是否必须,默认是
	 */
	boolean required() default true;

}


text:
angular.module("calendar").factory("Item", [
    "moment", "$http", "$log", "API_BASE", "Appointment", "Note",
    function(moment, $http, $log, API_BASE, Appointment, Note)
{
    var itemFactory = {};

    function isAppointment(item) {
        return item.data_type === "appointment";
    }

    function isNote(item) {
        return item.data_type === "note";
    }

    /**
     * Set up calendar ID for modification
     * @param id
     */
    itemFactory.setCalendarID = function(id) {
        itemFactory.calendarID = id;
    };

    /**
     * Get calendar ID
     * @returns {*}
     */
    itemFactory.getCalendarID = function() {
        return itemFactory.calendarID;
    };

    /**
     * Get a given item type, between start and end dates.
     *
     * @param itemType
     * @param startDate
     * @param endDate
     * @returns {*}
     */
    itemFactory.get = function(itemType, startDate, endDate) {
        var response;

        if (itemType == "appointment") {
            response = Appointment.get(itemFactory.calendarID, startDate, endDate);
        } else if (itemType == "note") {
            response = Note.get(itemFactory.calendarID, startDate, endDate);
        } else {
            throw "Invalid item type" + itemType;
        }

        return response.then(function(response) {
            return itemFactory.filterBetweenDates(response.data, startDate, endDate);
        });
    };

    itemFactory.create = function(itemType, item) {
        if (itemType == "appointment") {
            return Appointment.create(itemFactory.calendarID, item).then(function(response) {
                $log.debug("successfully created appointment, reattaching time information");
                return itemFactory.processTimes(response.data);
            });
        } else if (itemType == "note") {
            return Note.create(itemFactory.calendarID, item);
        } else {
            throw "Invalid item type";
        }
    };

    itemFactory.delete = function(item, dateToDelete) {
        if (!isAppointment(item) && !isNote(item)) {
            throw "Invalid item type";
        }

        return $http.delete(API_BASE + "calendar/" + itemFactory.calendarID + "/" + item.data_type + "/" + item.id, {
            data: {
                date: dateToDelete !== null && dateToDelete.toISOString() || moment().toISOString(),
                delete_all: dateToDelete === null
            }
        });
    };

    itemFactory.update = function(item) {
        if (isAppointment(item)) {
            return Appointment.update(itemFactory.calendarID, item);
        } else if (isNote(item)) {
            return Note.update(itemFactory.calendarID, item);
        } else {
            throw "Invalid item type";
        }
    };

    /**
     * Filter items to only display those occurring between two dates. between two dates.
     * @param items
     * @param startDate
     * @param endDate
     * @returns {Array}
     */
    itemFactory.filterBetweenDates = function(items, startDate, endDate) {
        var filtered = [];

        startDate.hour(0).minute(0).second(0);
        endDate.hour(23).minute(59).second(59);

        for (var itemIndex = 0; itemIndex < items.length; itemIndex++) {
            var item = itemFactory.processTimes(items[itemIndex]);

            // mark collisions
            item.collisions = [];

            if (!!item.recurrence_rule) {
                try {
                    item.recurrences = recurrencesBetween(item.recurrence_rule, item.start, startDate, endDate);

                    if (!item.recurrences) {
                        throw "invalid recurrence count";
                    }

                    if (item.recurrences.length > 0) {
                        filtered.push(item);
                    }
                } catch (err) {
                    $log.debug("recurrence error: " + err + " on item: " + item.text);

                    // add to filtered w/o rule
                    item.recurrences = [];
                    filtered.push(item);
                }

            } else {
                item.recurrences = [];
                filtered.push(item);
            }
        }

        return filtered;
    };

    /**
     *
     * @param rrulestr
     * @param dtstart
     * @param setStart
     * @param setEnd
     * @returns {Array}
     */
    function recurrencesBetween(rrulestr, dtstart, setStart, setEnd) {
        var start = ICAL.Time.fromJSDate(dtstart.toDate());

        // hack: https://github.com/mozilla-comm/ical.js/issues/243
        var rule = ICAL.Recur.fromData(ICAL.Recur._stringToData(rrulestr, true));

        var iterator = rule.iterator(start);

        setStart = ICAL.Time.fromJSDate(setStart.toDate());
        setEnd = ICAL.Time.fromJSDate(setEnd.toDate());

        var recurrences = [];

        for (var next = iterator.next(); next; next = iterator.next()) {
            if (next.compare(setStart) < 0) {
                // keep going till we hit start
                continue;
            } else if (next.compare(setEnd) > 0) {
                // stop if we get past the end
                break;
            }

            recurrences.push(next.toJSDate());
        }

        return recurrences;
    }

    itemFactory.removeDeletedDates = function(items) {
        var filtered = [];

        for (var index = 0; index < items.length; index++) {
            var item = items[index];

            if (item.recurrences.length > 0) {
                for (var recurrIndex = 0; recurrIndex < item.recurrences.length; recurrIndex++) {
                    var recurrence = item.recurrences[recurrIndex];
                    var recurrenceDate = moment(recurrence);
                    var isDeleted = false;

                    if (item.deleted && item.deleted.length) {
                        for (var deletedIndex = 0; deletedIndex < item.deleted.length; deletedIndex++) {
                            var deletedDate = moment(item.deleted[deletedIndex].date, "YYYY-MM-DDTHH:mm:ss");

                            if (deletedDate.isSame(recurrenceDate, 'day')) {
                                isDeleted = true;
                            }
                        }

                        if (isDeleted) {
                            continue;
                        }
                    }

                    filtered.push(item);
                }
            } else {
                filtered.push(item);
            }
        }

        return filtered;
    };

    /**
     * Remove exdate from recurrence rule.
     *
     * @param rule
     * @returns {string}
     */
    itemFactory.stripExDate = function(rule) {
        // strip exclusion dates from the recurrence rule, because despite the library saying it
        // supports them, it does not.
        if (rule.indexOf(";EXDATE") !== -1) {
            rule = rule.substring(0, rule.indexOf(';EXDATE'));
        }

        return "RRULE:" + rule.replace("UNTIL:", "UNTIL=");
    };

    /**
     * Given an item, assign it a length, offset and start and end moment objects.
     * @param item
     * @returns {*}
     */
    itemFactory.processTimes = function(item) {
        if (!item.timezone || item.timezone == "<Local>" || item.timezone == "Local") {
            item.timezone = moment.tz.guess();
        }

        item.start = moment.tz(item.start, "YYYY-MM-DDTHH:mm:ss", item.timezone).seconds(0);
        item.finish = moment.tz(item.finish, "YYYY-MM-DDTHH:mm:ss", item.timezone).seconds(0);
        item.length = Math.abs(moment.duration(item.finish.diff(item.start)).asMinutes());
        item.offset = Math.abs((item.start.hour() * 60) + item.start.minute());

        if (!!item.recurrence_rule) {
            try {
                item.rule = rrulestr(itemFactory.stripExDate(item.recurrence_rule), {
                    dtstart: item.start.toDate()
                });
            } catch (err) {
                $log.debug(err);
            }
        }

        return item;
    };

    return itemFactory;
}]);


text:
require 'bundler/setup'
require 'ffi-czmq'

class BaseConfig
  include CZMQ
  extend Forwardable

  def_delegators :@parent_pipe, :<<, :tell, :recv, :wait, :signal, :destructor

  def initialize
    @parent_pipe = Zactor.new_actor(&method(:run))
    at_exit { destructor }
  end

  private

  def run(child_pipe)
    @reactor = Zloop.new
    @reactor.add_reader(child_pipe, &method(:handle_pipe))

    config = Zconfig.load("#{File.dirname(__FILE__)}/examples.cfg")
    @base = Zactor.new_zgossip(config.resolve('/gossip/base/logprefix', nil))
    @base.tell('BIND', config.resolve('/gossip/base/endpoint', nil))

    @reactor.add_reader(@base, &method(:handle_gossip))

    child_pipe.signal(0)

    @reactor.start
  end

  def handle_pipe(zsock)
    msg = zsock.recv

    case msg.first.to_str
    when '$TERM'
      -1
    end
  end

  def handle_gossip(zsock)
    puts zsock.recv.print
    0
  end
end

base = BaseConfig.new

config = CZMQ::Zconfig.load("#{File.dirname(__FILE__)}/examples.cfg")
node_prefix = config.resolve('/gossip/node/logprefix', nil)
node_endpoint = config.resolve('/gossip/node/endpoint', nil)
node_connect = config.resolve('/gossip/node/connect', nil)

nodes = []

4.times do |i|
  nodes << node = CZMQ::Zactor.new_zgossip("#{node_prefix}#{i}")
  node.tell('CONNECT', node_connect)
  node.tell('BIND', node_endpoint)
  node << 'PORT'
  port = node.recv.last.to_str
  node.tell('PUBLISH', "service#{i}", "tcp://localhost:#{port}")
end

sleep 1