text:
"""
MIT License

Copyright (c) 2017 s0hvaperuna

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.
"""

import asyncio
import logging
import os
import shlex
from collections import deque, OrderedDict

import discord
from discord.ext import commands
from discord.ext.commands import Cog
from numpy import random

from bot.bot import cooldown
from bot.formatter import Paginator
from bot.player import FFmpegPCMAudio, play

try:
    from gtts import gTTS
except ImportError:
    gTTS = None

from bot.bot import command
from bot.globals import TTS, SFX_FOLDER

terminal = logging.getLogger('terminal')

class SFX:
    def __init__(self, name, after_input='', options=''):
        self.name = name
        self.after_input = after_input
        self.before_options = '-nostdin'
        self.options = '-vn -b:a 128k' + options

class Playlist:
    def __init__(self, bot, disconnect, guild):
        self.voice = None
        self.bot = bot
        self.guild = guild
        self._disconnect = disconnect
        self.queue = deque(maxlen=6)
        self.not_empty = asyncio.Event()
        self.next = asyncio.Event()
        self.random_loop = None
        self.sfx_loop = None
        self.source = None
        self.random_sfx_on = self.bot.config.random_sfx
        self.on_join = True

    @property
    def player(self):
        if self.voice:
            return self.voice._player

    def on_stop(self, e):
        self.bot.loop.call_soon_threadsafe(self.next.set)
        return

    def create_tasks(self):
        if self.random_loop:
            self.random_loop.cancel()
        if self.sfx_loop:
            self.sfx_loop.cancel()
        self.random_loop = self.bot.loop.create_task(self.random_sfx())
        self.sfx_loop = self.bot.loop.create_task(self.audio_player())

    async def random_sfx(self):
        while True:
            if self.voice is not None:
                users = self.voice.channel.members
                users = list(filter(lambda x: not x.bot, users))
                if not users:
                    await self._disconnect(self)
                    return

            if self.random_sfx_on and random.random() < 0.1 and self.voice is not None:

                path = SFX_FOLDER
                files = os.listdir(path)

                sfx = os.path.join(path, random.choice(files))
                if random.random() < 0.5:
                    sfx2 = os.path.join(path, random.choice(files))
                    options = '-i "{}" '.format(sfx2)
                    options += '-filter_complex "[0:a0] [1:a:0] concat=n=2:v=0:a=1 [a]" -map "[a]"'
                    self.add_to_queue(sfx, options)
                else:
                    self.add_to_queue(sfx)

            await asyncio.sleep(60)

    async def audio_player(self):
        while True:
            self.next.clear()
            self.not_empty.clear()
            sfx = self._get_next()
            if sfx is None:
                await self.not_empty.wait()
                sfx = self._get_next()

            self.source = FFmpegPCMAudio(sfx.name, before_options=sfx.before_options,
                                         after_input=sfx.after_input, options=sfx.options,
                                         reconnect=False)

            play(self.voice, self.source, after=self.on_stop)

            await self.next.wait()

    def is_playing(self):
        if self.voice is None or not self.voice.is_connected():
            return False

        return True

    def add_to_queue(self, entry, after_input=''):
        self.queue.append(SFX(entry, after_input=after_input))
        self.bot.loop.call_soon_threadsafe(self.not_empty.set)

    def add_next(self, entry, options=''):
        self.queue.appendleft(SFX(entry, options))
        self.bot.loop.call_soon_threadsafe(self.not_empty.set)

    def _get_next(self):
        if self.queue:
            return self.queue.popleft()

    def skip(self, author):
        if self.is_playing():
            self.voice.stop()

class Audio(Cog):
    def __init__(self, bot, queue):
        self.bot = bot
        self.music_players = self.bot.music_players
        self.queue = queue
        self._lang = 'en-us'

    def get_voice_state(self, guild):
        playlist = self.music_players.get(guild.id)
        if playlist is None:
            playlist = Playlist(self.bot, self.disconnect_voice, guild)
            self.music_players[guild.id] = playlist

        return playlist

    @command(no_pm=True, ignore_extra=True, aliases=['summon2'])
    async def summon(self, ctx):
        """Summons the bot to join your voice channel."""
        voice = ctx.message.author.voice
        if voice is None:
            await ctx.send('You are not in a voice channel')
            return False

        state = self.get_voice_state(ctx.guild)
        summoned_channel = voice.channel
        if state.voice is None:
            state.voice = ctx.voice_client

        if state.voice is None:
            try:
                state.voice = await summoned_channel.connect()
            except discord.ClientException:
                terminal.exception('Failed to join vc')
                if ctx.guild.id in self.bot._connection._voice_clients:
                    state.voice = self.bot._connection._voice_clients.get(ctx.guild.id)
            state.create_tasks()
        else:
            await state.voice.move_to(summoned_channel)

        file = self._search_sfx('attention')
        if file:
            state.add_to_queue(file[0])

        return True

    @command(no_pm=True, aliases=['s'])
    async def stop_sfx(self, ctx):
        """Stop the current sfx"""
        state = self.get_voice_state(ctx.guild)
        if state:
            state.skip(ctx.author)

    async def shutdown(self):
        for key in list(self.music_players.keys()):
            state = self.music_players[key]
            await self.close_player(state)
            del self.music_players[key]

    @staticmethod
    async def close_player(musicplayer):
        if musicplayer is None:
            return

        musicplayer.skip(None)

        try:
            if musicplayer.sfx_loop is not None:
                musicplayer.sfx_loop.cancel()

            if musicplayer.voice is not None:
                await musicplayer.voice.disconnect()
                musicplayer.voice = None

        except Exception:
            terminal.exception('Error while stopping voice')

    async def disconnect_voice(self, musicplayer):
        await self.close_player(musicplayer)
        try:
            del self.music_players[musicplayer.guild.id]
        except:
            pass

    @command(no_pm=True)
    @cooldown(2, 4, type=commands.BucketType.user)
    async def sfx(self, ctx, *, name):
        """Play a sound effect"""
        file = self._search_sfx(name)
        if not file:
            return await ctx.send('Invalid sound effect name')

        file = file[0]

        state = self.get_voice_state(ctx.guild)
        if state.voice is None:
            success = await ctx.invoke(self.summon)
            if not success:
                return

        state.add_to_queue(file)

    @command(name='max_combo', no_pm=True)
    @commands.check(lambda ctx: ctx.message.author.id in [117256618617339905, 123050803752730624])
    async def change_combo(self, ctx, max_combo: int=None):
        """Change how many sound effects you can combine with {prefix}combo"""
        if max_combo is None:
            return await ctx.send(self.bot.config.max_combo)

        self.bot.config.max_combo = max_combo
        await ctx.send(f'Max combo set to {max_combo}')

    async def _combine_sfx(self, ctx, *effects, search=True):
        max_combo = self.bot.config.max_combo
        silences = []
        silenceidx = 0
        sfx_list = []
        for idx, name in enumerate(effects):
            if name.startswith('-') and name != '-':
                silence = name.split('-')[1]
                try:
                    silence = float(silence)
                except ValueError as e:
                    await ctx.send('Silence duration needs to be a number\n%s' % e, delete_after=20)
                    continue

                silences.append(('aevalsrc=0:d={}[s{}]'.format(silence, str(silenceidx)), idx))
                silenceidx += 1
                continue

            elif name.endswith('-') and name != '-':
                try:
                    bpm = int(''.join(name.split('-')[:-1]))
                    if bpm <= 0:
                        await ctx.send('BPM needs to be bigger than 0', delete_after=20)
                        continue

                    silence = 60 / bpm
                    silences.append(('aevalsrc=0:d={}[s{}]'.format(silence, str(silenceidx)), idx))
                    silenceidx += 1
                    continue
                except ValueError:
                    pass

            if search:
                sfx = self._search_sfx(name)
                if not sfx:
                    name = name.replace('@', '\u200b@')
                    await ctx.send(f"{ctx.author.mention} Couldn't find {name}. Skipping it", delete_after=30)
                    continue

                sfx_list.append(sfx[0])
            else:
                sfx_list.append(name)

        if not sfx_list:
            return await ctx.send('No sfx found', delete_after=30)

        if len(sfx_list) > max_combo:
            return await ctx.send('Cannot combine more effects than the current combo limit of %s' % max_combo)

        entry = sfx_list.pop(0)
        if not sfx_list:
            return entry

        options = ''
        filter_complex = '-filter_complex "'

        for s in silences:
            filter_complex += s[0] + ';'

        audio_order = ['[0:a:0]']
        for idx, sfx in enumerate(sfx_list):
            options += '-i "{}" '.format(sfx)
            audio_order.append('[{}:a:0] '.format(idx + 1))

        for idx, silence in enumerate(silences):
            audio_order.insert(silence[1], '[s{}]'.format(idx))

        filter_complex += ' '.join(audio_order)
        options += filter_complex
        options += 'concat=n={}:v=0:a=1 [a]" -map "[a]"'.format(len(audio_order))
        return entry, options

    @command(aliases=['r'], no_pm=True)
    async def random_sfx(self, ctx, combo=1):
        """Set how many sfx random sfx will combine if it's on"""
        if combo > self.bot.config.max_combo:
            return await ctx.send('Cannot go over max combo  {}>{}'.format(combo, self.bot.config.max_combo))

        if combo <= 0:
            return await ctx.send('Number cannot be smaller than one')

        state = self.get_voice_state(ctx.guild)
        if state.voice is None:
            success = await ctx.invoke(self.summon)
            if not success:
                return

        sfx = os.listdir(SFX_FOLDER)
        try:
            sfx.remove('-.mp3')
        except:
            pass

        effects = [os.path.join(SFX_FOLDER, f) for f in random.choice(sfx, combo)]
        entry = await self._combine_sfx(ctx, *effects, search=False)
        if isinstance(entry, tuple):
            state.add_to_queue(entry[0], entry[1])
        elif isinstance(entry, str):
            state.add_to_queue(entry)

    @command(name='combo', no_pm=True, aliases=['concat', 'c'])
    @cooldown(2, 4, type=commands.BucketType.user)
    async def combine(self, ctx, *, names: commands.clean_content):
        """Play multiple sfx in a row"""
        max_combo = self.bot.config.max_combo
        names = shlex.split(names)
        if len(names) > max_combo:
            return await ctx.send('Max %s sfx can be combined' % max_combo)

        state = self.get_voice_state(ctx.guild)
        if state.voice is None:
            success = await ctx.invoke(self.summon)
            if not success:
                return

        entry = await self._combine_sfx(ctx, *names)
        if isinstance(entry, tuple):
            state.add_to_queue(entry[0], entry[1])
        elif isinstance(entry, str):
            state.add_to_queue(entry)
        'ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a:0] [1:a:0] concat=n=2:v=0:a=1 [a]" -map "[a]" out.mp3'

    @staticmethod
    def _search_sfx(name):
        sfx = sorted(os.listdir(SFX_FOLDER))

        # A very advanced searching algorithm
        file = [x for x in sfx if '.'.join(x.split('.')[:-1]) == name]
        if not file:
            file = [x for x in sfx if '.'.join(x.split('.')[:-1]).lower().startswith(name)]
            if not file:
                file = [x for x in sfx if name in x.lower()]
                if not file:
                    file = [x for x in sfx if name.replace(' ', '').lower() in x.lower()]

        return [os.path.join(SFX_FOLDER, f) for f in file]

    @command(no_pm=True, aliases=['srs'])
    async def set_random_sfx(self, ctx, value):
        """Set random sfx on or off"""
        value = value.lower().strip()
        values = {'on': True, 'off': False}
        values_rev = {v: k for k, v in values.items()}

        value = values.get(value, False)
        state = self.get_voice_state(ctx.guild)
        state.random_sfx_on = value

        await ctx.send('Random sfx set to %s' % values_rev.get(value))

    @command()
    @cooldown(1, 4, type=commands.BucketType.user)
    async def sfxlist(self, ctx):
        """List of all the sound effects"""
        sfx = os.listdir(SFX_FOLDER)
        if not sfx:
            return await ctx.send('No sfx found')

        sfx.sort(key=str.lower)
        sorted_sfx = OrderedDict()
        curr_add = []
        start = sfx[0][0].lower()
        title = 'SFX list'
        p = Paginator(title=title)
        p.add_field(start)

        for item in sfx:
            padding = ' '
            if not item[0].lower().startswith(start):
                sorted_sfx[start] = curr_add
                start = item[0].lower()
                p.add_field(start)
                padding = ''

            p.add_to_field('{}`{}`'.format(padding, '.'.join(item.split('.')[:-1])))

        p.finalize()
        for embed in p.pages:
            await ctx.send(embed=embed)

    @command(name='on_join')
    @cooldown(2, 4, type=commands.BucketType.user)
    async def _on_join(self, ctx, val: bool=None):
        guild = ctx.guild
        state = self.get_voice_state(guild)
        if not state:
            return

        if val is None:
            return await ctx.send(f'Current on join value {state.on_join}')

        state.on_join = val
        await ctx.send(f'On join set to {val}')

    @command(no_pm=True, aliases=['stop2'])
    @cooldown(2, 4, type=commands.BucketType.user)
    async def stop(self, ctx):
        """Stops playing audio and leaves the voice channel.
        This also clears the queue.
        """
        guild = ctx.guild
        state = self.get_voice_state(guild)
        if not state:
            return
        await self.disconnect_voice(state)

    #@Cog.listener()
    async def on_voice_state_update(self, member, before, after):
        # disabled for now
        return
        if member == self.bot.user:
            return

        state = self.music_players.get(member.guild.id)
        if not state:
            return

        if not state.on_join:
            return

        if not member.guild.me.voice:
            return

        channel = member.guild.me.voice.channel
        if not channel:
            return

        try:
            if not before and after:
                if after.channel == channel:
                    await self.on_join(member)
            elif before and not after:
                if before.channel == channel:
                    await self.on_leave(member)
            elif before and after and before.channel != after.channel:
                if before.channel == channel:
                    await self.on_leave(member)
                elif after.channel == channel:
                    await self.on_join(member)
        except:
            terminal.exception('Failed to say join leave voice')

    @Cog.listener()
    async def on_join(self, member):
        string = '%s joined the channel' % member.name
        path = os.path.join(TTS, 'join.mp3')
        self._add_tts(path, string, member.guild)

    @Cog.listener()
    async def on_leave(self, member):
        string = '%s left the channel' % member.name
        path = os.path.join(TTS, 'leave.mp3')
        self._add_tts(path, string, member.guild)

    def _add_tts(self, path, string, guild):
        if gTTS is None:
            return

        gtts = gTTS(string, lang=self._lang)
        gtts.save(path)
        state = self.get_voice_state(guild)
        if not state:
            return

        state.add_next(path)

def setup(bot):
    bot.add_cog(Audio(bot, None))


text:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="de.smart_sense.tracker.app.ImuLiveScreen">
    <item
        android:id="@+id/action_introduction"
        android:title="@string/title_activity_introduction"
        android:orderInCategory="100"
        android:showAsAction="never" />
    <item
        android:id="@+id/action_help"
        android:title="@string/title_activity_help_screen"
        android:orderInCategory="200"
        android:showAsAction="never" />

    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="300"
        android:showAsAction="never" />
    <item
        android:id="@+id/action_about"
        android:title="@string/title_activity_about"
        android:orderInCategory="400"
        android:showAsAction="never" />
</menu>

redpajama_set_name: RedPajamaGithub


text:
Admission Control
=================

1. Whether the system should begin processing the query immediately, or defer execution until a time when enough system resources are available to devote to this query.


text:
//
// WHObject.h
// WebHere
//
// Created by Rui Lopes on 06/10/2014.
//
// Copyright (c) 2014 Rui Lopes.
//
// 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.
//

#ifndef WHObject_h
#define WHObject_h

#import <Foundation/Foundation.h>

@class WHHTTPRequest;
@class GDataXMLDocument;

/**
 WHObject defines a protocol that needs to be implemented by all possible targets. This defines how an HTML document
 can be parsed to be turned into a WHObject by parsing its content.
 */
@protocol WHObject <NSObject>

/**
 Tells whether this object can be parsed from the HTML it receives, issued by the passed request.

 @param html the HTML to test
 @param request the request issued to the website.
 */
@optional
+ (BOOL)matches:(GDataXMLDocument *)html
    fromRequest:(WHHTTPRequest *)request;

/**
 Performs the actual parsing of the HTML document into the final form of this object.
 A developer needs to implement that method in order to inject the desired properties into its target object.
 You can use CSS selectors and various parsing methods found in the GDataXML-HTML library.

 @param html the HTML to test
 @param request the request issued to the website.

 @see [GDataXMLNode](http://cocoadocs.org/docsets/GDataXML-HTML/1.3.0/Classes/GDataXMLNode.html)
 @see [GDataXMLDocument](http://cocoadocs.org/docsets/GDataXML-HTML/1.3.0/Classes/GDataXMLDocument.html)
 */
@required
- (void)buildFromHTML:(GDataXMLDocument *)html
          fromRequest:(WHHTTPRequest *)request
                error:(NSError **)error;

@end

#endif


text:
<!DOCTYPE html>

	<title>Allan Guggenheim</title>
	<link rel="stylesheet" type="text/css" href="assets/css/style.css">

Allan Guggenheim

Home

Portfolio

Contact

About Me

 Hello, I am Allan Guggenheim. I consider myself a life learner. I'm passionate about business but I love to enjoy life with my loved ones. I am a proud parent of 4 chihuahuas: Sophie, Bunny, Tess and Lily and I'm hoping to be an awesome developer in six months.
					And now, some random text.
					Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Connect With Me

		© Copyright 2016 Allan Guggenheim


text:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.17929
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Flynn.Weather.Properties {

    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("rvo7PMHV34GF_b1JSWiELfYRRcksR5IstxSgYKM4parOUUNDj2IB.6vDunrSQQ--")]
        public string YahooApplicationID {
            get {
                return ((string)(this["YahooApplicationID"]));
            }
        }

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("demo")]
        public string GeoNames_Username {
            get {
                return ((string)(this["GeoNames_Username"]));
            }
        }

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool Weather_CacheEnabled {
            get {
                return ((bool)(this["Weather_CacheEnabled"]));
            }
        }

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool GeoData_CacheEnabled {
            get {
                return ((bool)(this["GeoData_CacheEnabled"]));
            }
        }

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool AstroData_CacheEnabled {
            get {
                return ((bool)(this["AstroData_CacheEnabled"]));
            }
        }
    }
}


text:
package com.datumbox.framework.core.machinelearning.classification;

import com.datumbox.framework.common.Configuration;
import com.datumbox.framework.core.common.dataobjects.Dataframe;
import com.datumbox.framework.core.common.dataobjects.Record;
import com.datumbox.framework.core.machinelearning.MLBuilder;
import com.datumbox.framework.core.machinelearning.modelselection.metrics.ClassificationMetrics;
import com.datumbox.framework.core.machinelearning.modelselection.Validator;
import com.datumbox.framework.core.machinelearning.modelselection.splitters.KFoldSplitter;
import com.datumbox.framework.tests.Constants;
import com.datumbox.framework.core.Datasets;
import com.datumbox.framework.tests.abstracts.AbstractTest;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
 * Test cases for MaximumEntropy.
 *
 * @author Vasilis Vryniotis <bbriniotis@datumbox.com>
 */
public class MaximumEntropyTest extends AbstractTest {

    /**
     * Test of predict method, of class MaximumEntropy.
     */
    @Test
    public void testPredict() {
        logger.info("testPredict");

        Configuration configuration = getConfiguration();

        Dataframe[] data = Datasets.carsNumeric(configuration);

        Dataframe trainingData = data[0];
        Dataframe validationData = data[1];

        String storageName = this.getClass().getSimpleName();

        MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
        param.setTotalIterations(10);

        MaximumEntropy instance = MLBuilder.create(param, configuration);

        instance.fit(trainingData);
        instance.save(storageName);

        instance.close();

        instance = MLBuilder.load(MaximumEntropy.class, storageName, configuration);

        instance.predict(validationData);

        Map<Integer, Object> expResult = new HashMap<>();
        Map<Integer, Object> result = new HashMap<>();
        for(Map.Entry<Integer, Record> e : validationData.entries()) {
            Integer rId = e.getKey();
            Record r = e.getValue();
            expResult.put(rId, r.getY());
            result.put(rId, r.getYPredicted());
        }
        assertEquals(expResult, result);

        instance.delete();

        trainingData.close();
        validationData.close();
    }

    /**
     * Test of validate method, of class MaximumEntropy.
     */
    @Test
    public void testKFoldCrossValidation() {
        logger.info("testKFoldCrossValidation");

        Configuration configuration = getConfiguration();

        int k = 5;

        Dataframe[] data = Datasets.carsNumeric(configuration);
        Dataframe trainingData = data[0];
        data[1].close();

        MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
        param.setTotalIterations(10);

        ClassificationMetrics vm = new Validator<>(ClassificationMetrics.class, configuration)
                .validate(new KFoldSplitter(k).split(trainingData), param);

        double expResult = 0.6051098901098901;
        double result = vm.getMacroF1();
        assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);

        trainingData.close();
    }

}


text:
'''
code to interface with Reddit
'''
import configparser
import random
import praw
import duplicates
from twitter import Tweet

class Reddit:
    '''
    Encapsulate reddit access
    '''

    def __init__(self, tweet_length=138):
        self.__reddit_connection = praw.Reddit(
            'bot1', user_agent='bot1 user agent')
        self.__tweet_length = tweet_length
        self.__duplicates = duplicates.Duplicates('posted_tweets.txt')

    def __get_tweets(self, subreddit_name):
        '''
        grabs tweets from reddit and formats them for processing
        '''
        tweets = []
        print('[bot] Getting tweets from Reddit\\r\\{}'.format(subreddit_name))
        subreddit = self.__reddit_connection.subreddit(subreddit_name)
        filtered_domains = {'imgur.com'}

        should_be_filtered = \
            lambda domain, post_id, stickied: domain in filtered_domains or \
            self.__duplicates.duplicate_check(post_id) or \
            stickied

        for submission in subreddit.hot(limit=10):
            if not should_be_filtered(
                    submission.domain,
                    submission.id,
                    submission.stickied):
                first, second = self.__convert_post_to_tweet(
                    submission.title,
                    submission.author.name,
                    submission.is_self,
                    submission.subreddit.display_name,
                    submission.url,
                    submission.shortlink)
                tweets.append(Tweet(first, second))
                self.__duplicates.add_id(submission.id)
        return tweets

    @staticmethod
    def __shorten_title(title, max_len):
        '''
        shortens title to fit in the tweet
        '''
        if len(title) <= max_len:
            return title
        return title[:max_len - 3] + "..."

    def __convert_post_to_tweet(
            self,
            title,
            user,
            is_self,
            subreddit_name,
            url,
            reddit_url):
        '''
        split the post into two tweets, one primary and one that is the reply.
        keep all the communication here.
        '''
        user_preamble = 'u/{user} says: '.format(user=user)
        hash_tag = '#{tag}'.format(tag=subreddit_name)
        shortened_title = self.__shorten_title(
            title,
            self.__tweet_length -
            23 -
            len(user_preamble) -
            len(hash_tag))
        primary_tweet = user_preamble + shortened_title + ' ' + url + ' ' + hash_tag
        reply_tweet = ''
        if not is_self:
            reply_tweet = 'further discussion to be had here: {url}'.format(
                url=reddit_url)
        return primary_tweet, reply_tweet

    def __bootstrap_source(self, source_subreddit):
        subreddit = self.__reddit_connection.subreddit(source_subreddit)
        for post in subreddit.hot(limit=10):
            self.__duplicates.add_id(post.id)

    def __get_subreddits(self):
        def empty(subreddit_name):
            return not subreddit_name or subreddit_name.isspace()

        def parse_list(line):
            return [x for x in line.splitlines() if not empty(x)]

        CONFIG_FILE = 'subreddits.ini'
        CONFIG_SECTION = 'subreddits'
        CONFIG_NEW = 'new'
        CONFIG_KNOWN = 'known'

        cfg = configparser.ConfigParser()
        cfg.read(CONFIG_FILE)
        subreddits_cfg = cfg.get(CONFIG_SECTION, CONFIG_KNOWN)
        subreddits = parse_list(subreddits_cfg)

        new_subreddits = cfg.get(CONFIG_SECTION, CONFIG_NEW)
        if not empty(new_subreddits):
            subreddits_cfg = subreddits_cfg + new_subreddits
            cfg[CONFIG_SECTION][CONFIG_NEW] = ''
            cfg[CONFIG_SECTION][CONFIG_KNOWN] = subreddits_cfg
            with open(CONFIG_FILE, 'w') as cfg_file:
                cfg.write(cfg_file)
            new_subreddits = parse_list(new_subreddits)
            for subreddit in new_subreddits:
                self.__bootstrap_source(subreddit)
                subreddits.append(subreddit)

        if not subreddits:
            print('error: subreddit list is totally empty')

        return subreddits

    def get_tweets(self):
        '''
        Get's posts from reddits and converts them to tweets.
        '''
        tweets = []
        for subreddit in self.__get_subreddits():
            for tweet in self.__get_tweets(subreddit):
                tweets.append(tweet)
        random.shuffle(tweets)
        return tweets


text:
_This page explains dynamic insert statements. Before studying this page, you should read about [static insert statements](Insert.md)._

If you know the exact structure of your inserts at compile time, statically constructed insert statements are perfect. But if the structure depends on runtime information like user input, you will need dynamic insert statements. For those only provide part fields of table schema, leave others to default value or NULL, dynamic insert statement is a must. Depending on your needs, you can choose the required dosage.

# A Basic Example
So let us construct insert statement with a dynamic part
```C++
auto s = dynamic_insert_into(db, foo).dynamic_set(
    foo.name = name,
);
s.insert_list.add(foo.id = runtimeStatement.id);
s.insert_list.add(foo.hasFun = runtimeStatement.hasFun);
const int64_t result = db(s);
```
Admittedly, a rather simplistic example (please suggest nicer ones), but anyway, this is what's happening:
```C++
dynamic_insert_into(db, table)
```
This initializes a dynamic insert. One major difference between `dynamic_insert_into` and `insert_into` is the first argument of `dynamic_insert_into`: a database connection. This is used to evaluate the dynamic parts of the statement as they are added.

```C++
.dynamic_set(...);
...
s.insert_list.add(foo.id = runtimeStatement.id);
s.insert_list.add(foo.hasFun = runtimeStatement.hasFun);
```
The first part creates a new insert object that accepts a dynamically constructed set expression. In this case the user can determine whether to search for a certain id or a certain hasFun, or neither or both.

```C++
const int64_t result = db(s);
```
Finally use `db(s)` to execute the insert statement, and returns a `int64_t` value. If `foo.id` column is a `AUTO INCREMENT` (auto generated) id field, this will returns the auto generated id, for others this will returns 0.


text:
<dataConfig>
    <dataSource type="BinFileDataSource" />
    <document>
        <entity name="tika-test" processor="TikaEntityProcessor"
                url="../contrib/extraction/src/test-files/extraction/solr-word.pdf" format="text">
                <field column="Author" name="author" meta="true"/>
                <field column="title" name="title" meta="true"/>
                <field column="text" name="text"/>
        </entity>
    </document>
</dataConfig>


text:
DIRECTORY=`dirname $0`
echo $DIRECTORY

source $DIRECTORY/processes.sh

node_file=$1
node_arg=$2

is_running=false
for process in "${usgs_api_processes[@]}"
do
  #if[ps -ax | grep $i | grep -v grep]
  numprocesses=$(ps -ax | grep $process | grep -v grep | grep -v metadata_updates.sh | wc -l)
  if [[ $numprocesses -gt 0 ]] ; then
   is_running=true
   echo "working on $process."
  fi
done

if $is_running ; then
  echo 'you CANNOT run a proccess'
else
 echo 'running ' $node_file
 cd $DIRECTORY
 if [ -z "$node_arg" ]; then
     node $node_file
 else
   node $node_file $node_arg
 fi
fi


text: .hiddens { display: none; }


text:
using System;
using System.Collections.Generic;
using System.Linq;
using Abacus.Exceptions;
using Abacus.Helper;
using Abacus.Interface;
using Abacus.MatrixDecomp;

namespace Abacus
{
    /// <summary>
    ///     Used for working with double[,] as a matrix
    /// </summary>
    public static class Array2DExtensions
    {
        #region SLICING/SUBMATRIX

        public static double[] GetRow(this double[,] matrix, int row)
        {
            int rowSize = matrix.ColumnCount();
            return matrix.Cast<double>().Skip(rowSize*row).Take(rowSize).ToArray();
        }

        public static double[] GetColumn(this double[,] matrix, int col)
        {
            int colSize = matrix.RowCount();
            var result = new double[colSize];
            for (int i = 0; i < colSize; i++)
            {
                result[i] = matrix[i, col];
            }
            return result;
        }

        public static double[,] Submatrix(this double[,] matrix, int[] rowIndices, int startingCol, int endingCol)
        {
            var result = new double[rowIndices.Length, endingCol - startingCol + 1];
            try
            {
                for (int i = 0; i < rowIndices.Length; i++)
                {
                    for (int j = startingCol; j <= endingCol; j++)
                    {
                        result[i, j - startingCol] = matrix[rowIndices[i], j];
                    }
                }
            }
            catch (IndexOutOfRangeException e)
            {
                throw new IndexOutOfRangeException("Submatrix indices", e);
            }
            return result;
        }

        public static double[,] Submatrix(this double[,] matrix, int startingRow, int endingRow, int startingCol,
            int endingCol)
        {
            var result = new double[endingRow - startingRow + 1, endingCol - startingCol + 1];

            try
            {
                for (int i = startingRow; i <= endingRow; i++)
                {
                    for (int j = startingCol; j <= endingCol; j++)
                    {
                        result[i - startingRow, j - startingCol] = matrix[i, j];
                    }
                }
            }
            catch (IndexOutOfRangeException e)
            {
                throw new IndexOutOfRangeException("Submatrix indices", e);
            }
            return result;
        }

        #endregion

        #region MATRIX PROPERTIES

        public static int RowCount(this double[,] matrix)
        {
            return matrix.GetUpperBound(0) + 1;
        }

        public static int ColumnCount(this double[,] matrix)
        {
            return matrix.GetUpperBound(1) + 1;
        }

        public static bool IsSquare(this double[,] matrix)
        {
            return matrix.RowCount() == matrix.ColumnCount();
        }

        #endregion

        #region MANIPULATION/COPY

        public static double[,] InsertRow(this double[,] matrix, double[] row, int rowPos)
        {
            int rowSize = matrix.ColumnCount();
            if (row.Length != rowSize)
            {
                throw new InvalidSizeException(rowSize, row.Length);
            }
            var rows = new List<double[]>();
            for (int k = 0; k < matrix.RowCount(); k++)
            {
                rows.Add(matrix.GetRow(k));
            }
            if (rows.Count > rowPos)
            {
                rows[rowPos] = row;
            }
            else //Add zeros until position is reached
            {
                while (rows.Count < rowPos)
                {
                    rows.Add(Enumerable.Range(1, rowSize).Select(r => 0.0).ToArray());
                }
                rows.Add(row);
            }
            int m = rows.Count;
            int n = rowSize;
            var result = new double[m, n];
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    result[i, j] = rows[i][j];
                }
            }
            return result;
        }

        public static double[,] InsertRow(this double[,] matrix, IVector row, int rowPos)
        {
            return matrix.InsertRow(row.Values, rowPos);
        }

        public static double[,] Transpose(this double[,] matrix)
        {
            int m = matrix.RowCount();
            int n = matrix.ColumnCount();

            var result = new double[n, m];
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    result[j, i] = matrix[i, j];
                }
            }
            return result;
        }

        public static double[,] Copy(this double[,] matrix)
        {
            var copy = new double[matrix.RowCount(), matrix.ColumnCount()];
            Array.Copy(matrix, copy, matrix.Length);
            return copy;
        }

        #endregion

        #region COMPUTATION/SOLVING

        public static SvdResult Svd(this double[,] matrix)
        {
            return MatrixDecomp.Svd.ComputeSvd(matrix);
        }

        public static double[,] Solve(this double[,] matrix, double[,] b)
        {
            return (matrix.IsSquare() ? (LUD.ComputeLUD(matrix)).Solve(b) : (QRD.ComputeQRD(matrix)).Solve(b));
        }

        public static double[,] Inverse(this double[,] matrix)
        {
            return matrix.Solve(MatrixHelper.Identity(matrix.RowCount()));
        }

        public static double Determinant(this double[,] matrix)
        {
            if (matrix.ColumnCount() != matrix.RowCount())
            {
                return double.NaN; //Not a square matrix
            }
            return LUD.ComputeLUD(matrix).Determinant();
        }

        #endregion

        #region OPERATIONS

        public static double[,] ElementWiseOperate(this double[,] matrix1, double[,] matrix2,
            Func<double, double, double> elementWiseOp)
        {
            int m = matrix1.RowCount();
            int n = matrix1.ColumnCount();

            if (matrix1.GetUpperBound(0) != matrix2.GetUpperBound(0))
            {
                throw new InvalidSizeException(matrix1.GetUpperBound(0), matrix2.GetUpperBound(0));
            }
            if (matrix1.GetUpperBound(1) != matrix2.GetUpperBound(1))
            {
                throw new InvalidSizeException(matrix1.GetUpperBound(1), matrix2.GetUpperBound(1));
            }
            var result = new double[m, n];
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    result[i, j] = elementWiseOp(matrix1[i, j], matrix2[i, j]);
                }
            }
            return result;
        }

        public static double[,] ElementWiseOperate(this double[,] matrix1, double scalar,
            Func<double, double, double> elementWiseOp)
        {
            int m = matrix1.GetUpperBound(0) + 1;
            int n = matrix1.GetUpperBound(1) + 1;

            var result = new double[m, n];
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    result[i, j] = elementWiseOp(matrix1[i, j], scalar);
                }
            }
            return result;
        }

        public static double[,] Add(this double[,] matrix1, double[,] matrix2)
        {
            return ElementWiseOperate(matrix1, matrix2, (m1, m2) => { return m1 + m2; });
        }

        public static double[,] Subtract(this double[,] matrix1, double[,] matrix2)
        {
            return ElementWiseOperate(matrix1, matrix2, (m1, m2) => { return m1 - m2; });
        }

        public static double[,] ElementWiseMultiply(this double[,] matrix1, double[,] matrix2)
        {
            return ElementWiseOperate(matrix1, matrix2, (m1, m2) => { return m1*m2; });
        }

        public static double[,] Multiply(this double[,] matrix1, double[,] matrix2)
        {
            int m1 = matrix1.GetUpperBound(0) + 1;
            int n1 = matrix1.GetUpperBound(1) + 1;
            int m2 = matrix2.GetUpperBound(0) + 1;
            int n2 = matrix2.GetUpperBound(1) + 1;

            if (n1 != m2)
            {
                throw new InvalidSizeException(n1, m2);
            }

            var result = new double[m1, n2];

            for (int m = 0; m < m1; m++)
            {
                for (int n = 0; n < n2; n++)
                {
                    for (int k = 0; k < n1; k++)
                    {
                        result[m, n] += matrix1[m, k]*matrix2[k, n];
                    }
                }
            }

            return result;
        }

        public static double[,] Multiply(this double[,] matrix1, double scalar)
        {
            return ElementWiseOperate(matrix1, scalar, (m1, s) => { return m1*s; });
        }

        public static double[] Multiply(this double[,] matrix, double[] vector)
        {
            int m = matrix.RowCount();
            int n = matrix.ColumnCount();

            if (vector.Length != n)
            {
                throw new InvalidSizeException(n, vector.Length);
            }

            var result = new List<double>();

            for (int i = 0; i < m; i++)
            {
                double current = 0.0;
                for (int j = 0; j < n; j++)
                {
                    current += matrix[i, j]*vector[j];
                }
                result.Add(current);
            }

            return result.ToArray();
        }

        public static double[] Multiply(this double[,] matrix, IVector vector)
        {
            return matrix.Multiply(vector.Values);
        }

        public static double[,] Divide(this double[,] matrix1, double scalar)
        {
            return ElementWiseOperate(matrix1, scalar, (m1, s) => { return m1/s; });
        }

        #endregion
    }
}


text:
title: Equilibrium index
localeTitle: Índice de Equilíbrio
---
## Índice de Equilíbrio

Este é um esboço. [Ajude nossa comunidade a expandi-lo](https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/coding-interview-prep/rosetta-code/equilibrium-index/index.md) .

[Este guia de estilo rápido ajudará a garantir que sua solicitação de recebimento seja aceita](https://github.com/freecodecamp/guides/blob/master/README.md) .


text:
static const int kAdtsHeaderMinSize = 7;

static const int adts_frequency_table[16] = {
  96000,
  88200,
  64000,
  48000,
  44100,
  32000,
  24000,
  22050,
  16000,
  12000,
  11025,
  8000,
  7350,
  0,
  0,
  0,
};
static const int kMaxSupportedFrequencyIndex = 12;

static media::ChannelLayout adts_channel_layout[8] = {
  media::CHANNEL_LAYOUT_NONE,
  media::CHANNEL_LAYOUT_MONO,
  media::CHANNEL_LAYOUT_STEREO,
  media::CHANNEL_LAYOUT_SURROUND,
  media::CHANNEL_LAYOUT_4_0,
  media::CHANNEL_LAYOUT_5_0_BACK,
  media::CHANNEL_LAYOUT_5_1_BACK,
  media::CHANNEL_LAYOUT_7_1,
};

// Number of samples per frame.
static const int kNumberSamplesPerAACFrame = 1024;

static int ExtractAdtsFrameSize(const uint8* adts_header) {
  return ((static_cast<int>(adts_header[5]) >> 5) |
          (static_cast<int>(adts_header[4]) << 3) |
          ((static_cast<int>(adts_header[3]) & 0x3) << 11));
}

static int ExtractAdtsFrequencyIndex(const uint8* adts_header) {
  return ((adts_header[2] >> 2) & 0xf);
}

static int ExtractAdtsChannelConfig(const uint8* adts_header) {
  return (((adts_header[3] >> 6) & 0x3) |
          ((adts_header[2] & 0x1) << 2));
}

// Return true if buf corresponds to an ADTS syncword.
// |buf| size must be at least 2.
static bool isAdtsSyncWord(const uint8* buf) {
  return (buf[0] == 0xff) && ((buf[1] & 0xf6) == 0xf0);
}

// Look for an ADTS syncword.
// |new_pos| returns
// - either the byte position of the ADTS frame (if found)
// - or the byte position of 1st byte that was not processed (if not found).
// In every case, the returned value in |new_pos| is such that new_pos >= pos
// |frame_sz| returns the size of the ADTS frame (if found).
// Return whether a syncword was found.
static bool LookForSyncWord(const uint8* raw_es, int raw_es_size,
                            int pos,
                            int* new_pos, int* frame_sz) {
  DCHECK_GE(pos, 0);
  DCHECK_LE(pos, raw_es_size);

  int max_offset = raw_es_size - kAdtsHeaderMinSize;
  if (pos >= max_offset) {
    // Do not change the position if:
    // - max_offset < 0: not enough bytes to get a full header
    //   Since pos >= 0, this is a subcase of the next condition.
    // - pos >= max_offset: might be the case after reading one full frame,
    //   |pos| is then incremented by the frame size and might then point
    //   to the end of the buffer.
    *new_pos = pos;
    return false;
  }

  for (int offset = pos; offset < max_offset; offset++) {
    const uint8* cur_buf = &raw_es[offset];

    if (!isAdtsSyncWord(cur_buf))
      // The first 12 bits must be 1.
      // The layer field (2 bits) must be set to 0.
      continue;

    int frame_size = ExtractAdtsFrameSize(cur_buf);
    if (frame_size < kAdtsHeaderMinSize) {
      // Too short to be an ADTS frame.
      continue;
    }

    // Check whether there is another frame
    // |size| apart from the current one.
    int remaining_size = raw_es_size - offset;
    if (remaining_size >= frame_size + 2 &&
        !isAdtsSyncWord(&cur_buf[frame_size])) {
      continue;
    }

    *new_pos = offset;
    *frame_sz = frame_size;
    return true;
  }

  *new_pos = max_offset;
  return false;
}

namespace media {
namespace mp2t {

EsParserAdts::EsParserAdts(
    const NewAudioConfigCB& new_audio_config_cb,
    const EmitBufferCB& emit_buffer_cb)
  : new_audio_config_cb_(new_audio_config_cb),
    emit_buffer_cb_(emit_buffer_cb) {
}

EsParserAdts::~EsParserAdts() {
}

bool EsParserAdts::Parse(const uint8* buf, int size,
                         base::TimeDelta pts,
                         base::TimeDelta dts) {
  int raw_es_size;
  const uint8* raw_es;

  // The incoming PTS applies to the access unit that comes just after
  // the beginning of |buf|.
  if (pts != kNoTimestamp()) {
    es_byte_queue_.Peek(&raw_es, &raw_es_size);
    pts_list_.push_back(EsPts(raw_es_size, pts));
  }

  // Copy the input data to the ES buffer.
  es_byte_queue_.Push(buf, size);
  es_byte_queue_.Peek(&raw_es, &raw_es_size);

  // Look for every ADTS frame in the ES buffer starting at offset = 0
  int es_position = 0;
  int frame_size;
  while (LookForSyncWord(raw_es, raw_es_size, es_position,
                         &es_position, &frame_size)) {
    DVLOG(LOG_LEVEL_ES)
        << "ADTS syncword @ pos=" << es_position
        << " frame_size=" << frame_size;
    DVLOG(LOG_LEVEL_ES)
        << "ADTS header: "
        << base::HexEncode(&raw_es[es_position], kAdtsHeaderMinSize);

    // Do not process the frame if this one is a partial frame.
    int remaining_size = raw_es_size - es_position;
    if (frame_size > remaining_size)
      break;

    // Update the audio configuration if needed.
    DCHECK_GE(frame_size, kAdtsHeaderMinSize);
    if (!UpdateAudioConfiguration(&raw_es[es_position]))
      return false;

    // Get the PTS & the duration of this access unit.
    while (!pts_list_.empty() &&
           pts_list_.front().first <= es_position) {
      audio_timestamp_helper_->SetBaseTimestamp(pts_list_.front().second);
      pts_list_.pop_front();
    }

    base::TimeDelta current_pts = audio_timestamp_helper_->GetTimestamp();
    base::TimeDelta frame_duration =
        audio_timestamp_helper_->GetFrameDuration(kNumberSamplesPerAACFrame);

    // Emit an audio frame.
    bool is_key_frame = true;
    scoped_refptr<StreamParserBuffer> stream_parser_buffer =
        StreamParserBuffer::CopyFrom(
            &raw_es[es_position],
            frame_size,
            is_key_frame);
    stream_parser_buffer->SetDecodeTimestamp(current_pts);
    stream_parser_buffer->set_timestamp(current_pts);
    stream_parser_buffer->set_duration(frame_duration);
    emit_buffer_cb_.Run(stream_parser_buffer);

    // Update the PTS of the next frame.
    audio_timestamp_helper_->AddFrames(kNumberSamplesPerAACFrame);

    // Skip the current frame.
    es_position += frame_size;
  }

  // Discard all the bytes that have been processed.
  DiscardEs(es_position);

  return true;
}

void EsParserAdts::Flush() {
}

void EsParserAdts::Reset() {
  es_byte_queue_.Reset();
  pts_list_.clear();
  last_audio_decoder_config_ = AudioDecoderConfig();
}

bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) {
  int frequency_index = ExtractAdtsFrequencyIndex(adts_header);
  if (frequency_index > kMaxSupportedFrequencyIndex) {
    // Frequency index 13 & 14 are reserved
    // while 15 means that the frequency is explicitly written
    // (not supported).
    return false;
  }

  int channel_configuration = ExtractAdtsChannelConfig(adts_header);
  if (channel_configuration == 0) {
    // TODO(damienv): Add support for inband channel configuration.
    return false;
  }

  // TODO(damienv): support HE-AAC frequency doubling (SBR)
  // based on the incoming ADTS profile.
  int samples_per_second = adts_frequency_table[frequency_index];
  int adts_profile = (adts_header[2] >> 6) & 0x3;

  AudioDecoderConfig audio_decoder_config(
      kCodecAAC,
      kSampleFormatS16,
      adts_channel_layout[channel_configuration],
      samples_per_second,
      NULL, 0,
      false);

  if (!audio_decoder_config.Matches(last_audio_decoder_config_)) {
    DVLOG(1) << "Sampling frequency: " << samples_per_second;
    DVLOG(1) << "Channel config: " << channel_configuration;
    DVLOG(1) << "Adts profile: " << adts_profile;
    // Reset the timestamp helper to use a new time scale.
    if (audio_timestamp_helper_) {
      base::TimeDelta base_timestamp = audio_timestamp_helper_->GetTimestamp();
      audio_timestamp_helper_.reset(
        new AudioTimestampHelper(samples_per_second));
      audio_timestamp_helper_->SetBaseTimestamp(base_timestamp);
    } else {
      audio_timestamp_helper_.reset(
          new AudioTimestampHelper(samples_per_second));
    }
    // Audio config notification.
    last_audio_decoder_config_ = audio_decoder_config;
    new_audio_config_cb_.Run(audio_decoder_config);
  }

  return true;
}

void EsParserAdts::DiscardEs(int nbytes) {
  DCHECK_GE(nbytes, 0);
  if (nbytes <= 0)
    return;

  // Adjust the ES position of each PTS.
  for (EsPtsList::iterator it = pts_list_.begin(); it != pts_list_.end(); ++it)
    it->first -= nbytes;

  // Discard |nbytes| of ES.
  es_byte_queue_.Pop(nbytes);
}

}  // namespace mp2t
}  // namespace media


text:
set -e

if [ -z ${AWS_SSH_PRIVATE_KEY_FILE} ]
then
    echo "ERROR: You must set AWS_SSH_PRIVATE_KEY_FILE in the environment."
    exit 1
fi

flatfileName=flatfile.txt
rm -f ${flatfileName}
for privateIp in $(cat nodes-private)
do
    echo ${privateIp}:54321 >> ${flatfileName}
done

i=0
for publicDnsName in $(cat nodes-public)
do
    i=$((i+1))
    echo "Copying flatfile to node ${i}: ${publicDnsName}"
    scp -o StrictHostKeyChecking=no -i ${AWS_SSH_PRIVATE_KEY_FILE} ${flatfileName} ec2-user@${publicDnsName}:
done

echo Success.


text:
package br.com.developer.redu.models;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: igor
 * Date: 8/31/12
 * Time: 12:21 PM
 * To change this template use File | Settings | File Templates.
 */
public class Course {
    public String id;
    public String name;
    public String path;
    public String created_at;
    public List<Link> links;

    @Override
    public String toString(){
        return String.format("id: %s\nname: %s\npath: %s\ncreated_at: %s\nlinks: %s",
                id,path, name, created_at, links);
    }
}


text:
package alicloud

import (
	"encoding/json"
	"fmt"
	"net"
	"regexp"
	"strconv"
	"strings"
	"time"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"github.com/denverdino/aliyungo/cdn"
	"github.com/denverdino/aliyungo/common"
	"github.com/denverdino/aliyungo/dns"
	"github.com/denverdino/aliyungo/ram"
	"github.com/hashicorp/terraform/helper/schema"
	"gopkg.in/yaml.v2"
)

// common
func validateInstancePort(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 1 || value > 65535 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid port between 1 and 65535",
			k))
		return
	}
	return
}

func validateInstanceProtocol(v interface{}, k string) (ws []string, errors []error) {
	protocol := v.(string)
	if !isProtocolValid(protocol) {
		errors = append(errors, fmt.Errorf(
			"%q is an invalid value. Valid values are either http, https, tcp or udp",
			k))
		return
	}
	return
}

// ecs
func validateDiskCategory(v interface{}, k string) (ws []string, errors []error) {
	category := DiskCategory(v.(string))
	if _, ok := SupportedDiskCategory[category]; !ok {
		var valid []string
		for key := range SupportedDiskCategory {
			valid = append(valid, string(key))
		}
		errors = append(errors, fmt.Errorf("%s must be one of %s", k, strings.Join(valid, ", ")))
	}

	return
}

func validateInstanceName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 128 characters", k))
	}

	if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
		errors = append(errors, fmt.Errorf("%s cannot starts with http:// or https://", k))
	}

	return
}

func validateInstanceDescription(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 256 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 256 characters", k))

	}
	return
}

func validateDiskName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if value == "" {
		return
	}

	if len(value) < 2 || len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 128 characters", k))
	}

	if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
		errors = append(errors, fmt.Errorf("%s cannot starts with http:// or https://", k))
	}

	return
}

func validateDiskDescription(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 256 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 256 characters", k))

	}
	return
}

//security group
func validateSecurityGroupName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 128 characters", k))
	}

	if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
		errors = append(errors, fmt.Errorf("%s cannot starts with http:// or https://", k))
	}

	return
}

func validateSecurityGroupDescription(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 256 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 256 characters", k))

	}
	return
}

func validateSecurityRuleType(v interface{}, k string) (ws []string, errors []error) {
	rt := Direction(v.(string))
	if rt != DirectionIngress && rt != DirectionEgress {
		errors = append(errors, fmt.Errorf("%s must be one of %s %s", k, DirectionIngress, DirectionEgress))
	}

	return
}

func validateSecurityRuleIpProtocol(v interface{}, k string) (ws []string, errors []error) {
	pt := Protocol(v.(string))
	if pt != Tcp && pt != Udp && pt != Icmp && pt != Gre && pt != All {
		errors = append(errors, fmt.Errorf("%s must be one of %s, %s, %s, %s and %s", k,
			Tcp, Udp, Icmp, Gre, All))
	}

	return
}

func validateSecurityRuleNicType(v interface{}, k string) (ws []string, errors []error) {
	pt := GroupRuleNicType(v.(string))
	if pt != GroupRuleInternet && pt != GroupRuleIntranet {
		errors = append(errors, fmt.Errorf("%s must be one of %s %s", k, GroupRuleInternet, GroupRuleIntranet))
	}

	return
}

func validateSecurityRulePolicy(v interface{}, k string) (ws []string, errors []error) {
	pt := GroupRulePolicy(v.(string))
	if pt != GroupRulePolicyAccept && pt != GroupRulePolicyDrop {
		errors = append(errors, fmt.Errorf("%s must be one of %s %s", k, GroupRulePolicyAccept, GroupRulePolicyDrop))
	}

	return
}

func validateSecurityPriority(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 1 || value > 100 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid authorization policy priority between 1 and 100",
			k))
		return
	}
	return
}

// validateCIDRNetworkAddress ensures that the string value is a valid CIDR that
// represents a network address - it adds an error otherwise
func validateCIDRNetworkAddress(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	_, ipnet, err := net.ParseCIDR(value)
	if err != nil {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid CIDR, got error parsing: %s", k, err))
		return
	}

	if ipnet == nil || value != ipnet.String() {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid network CIDR, expected %q, got %q",
			k, ipnet, value))
	}

	return
}

func validateIpAddress(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	res := net.ParseIP(value)

	if res == nil {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid ip address, got error parsing: %s", k, value))
	}

	return
}

func validateRouteEntryNextHopType(v interface{}, k string) (ws []string, errors []error) {
	nht := NextHopType(v.(string))
	if nht != NextHopIntance && nht != NextHopRouterInterface && nht != NextHopHaVip &&
		nht != NextHopTunnel && nht != NextHopVpnGateway {
		errors = append(errors, fmt.Errorf("%s must be one of %s %s %s %s %s", k,
			NextHopIntance, NextHopRouterInterface, NextHopTunnel, NextHopHaVip, NextHopVpnGateway))
	}

	return
}

func validateSwitchCIDRNetworkAddress(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	_, ipnet, err := net.ParseCIDR(value)
	if err != nil {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid CIDR, got error parsing: %s", k, err))
		return
	}

	if ipnet == nil || value != ipnet.String() {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid network CIDR, expected %q, got %q",
			k, ipnet, value))
		return
	}

	mark, _ := strconv.Atoi(strings.Split(ipnet.String(), "/")[1])
	if mark < 16 || mark > 29 {
		errors = append(errors, fmt.Errorf(
			"%q must contain a network CIDR which mark between 16 and 29",
			k))
	}

	return
}

// validateIoOptimized ensures that the string value is a valid IoOptimized that
// represents a IoOptimized - it adds an error otherwise
func validateIoOptimized(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		ioOptimized := OptimizedType(value)
		if ioOptimized != NoneOptimized &&
			ioOptimized != IOOptimized {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid IoOptimized, expected %s or %s, got %q",
				k, IOOptimized, NoneOptimized, ioOptimized))
		}
	}

	return
}

// validateInstanceNetworkType ensures that the string value is a classic or vpc
func validateInstanceNetworkType(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		network := InstanceNetWork(value)
		if network != ClassicNet &&
			network != VpcNet {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid InstanceNetworkType, expected %s or %s, go %q",
				k, ClassicNet, VpcNet, network))
		}
	}
	return
}

func validateInstanceChargeType(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		chargeType := common.InstanceChargeType(value)
		if chargeType != common.PrePaid &&
			chargeType != common.PostPaid {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid InstanceChargeType, expected %s or %s, got %q",
				k, common.PrePaid, common.PostPaid, chargeType))
		}
	}

	return
}

func validateInternetChargeType(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		chargeType := common.InternetChargeType(value)
		if chargeType != common.PayByBandwidth &&
			chargeType != common.PayByTraffic {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid InstanceChargeType, expected %s or %s, got %q",
				k, common.PayByBandwidth, common.PayByTraffic, chargeType))
		}
	}

	return
}

func validateLifecycleTransaction(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		transition := LifecycleTransition(value)
		if transition != ScaleIn &&
			transition != ScaleOut {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid LifecycleTransition, expected %s or %s, got %q",
				k, ScaleIn, ScaleOut, transition))
		}
	}
	return
}

func validateActionResult(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		actionResult := ActionResult(value)
		if actionResult != Continue &&
			actionResult != Abandon {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid default result, expected %s or %s, got %q",
				k, Continue, Abandon, actionResult))
		}
	}
	return
}

func validateInternetMaxBandWidthOut(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 0 || value > 100 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid internet bandwidth out between 0 and 100",
			k))
		return
	}
	return
}

func validateInstanceChargeTypePeriod(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if (value > 0 && value < 10) || (value > 11 && value < 61 && value%12 == 0) {
		return
	}
	errors = append(errors, fmt.Errorf(
		"%q must be a valid period, expected [1-9], 12, 24, 36, 48 or 60, got %d.", k, value))
	return
}
func validateInstanceChargeTypePeriodUnit(v interface{}, k string) (ws []string, errors []error) {
	unit := common.TimeType(v.(string))
	if unit != common.Week && unit != common.Month {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid PeriodUnit, expected %s or %s, got %s.",
			k, common.Week, common.Month, unit))
	}
	return
}

func validateInstanceStatus(v interface{}, k string) (ws []string, errors []error) {
	status := Status(v.(string))
	if status != Running && status != Stopped && status != Creating &&
		status != Starting && status != Stopping {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid status, expected %s or %s or %s or %s or %s, got %s.",
			k, Creating, Starting, Running, Stopping, Stopped, status))
	}
	return
}

// SLB
func validateSlbName(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 1 || len(value) > 80 {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid load balancer name characters between 1 and 80",
				k))
			return
		}
	}

	return
}

func validateSlbInternetChargeType(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {

		// Uniform all internet chare type value and be compatible with previous lower value.
		if strings.ToLower(value) != strings.ToLower(string(PayByBandwidth)) &&
			strings.ToLower(value) != strings.ToLower(string(PayByTraffic)) {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid InternetChargeType, expected %s or %s, got %q",
				k, PayByBandwidth, PayByTraffic, value))
		}
	}

	return
}

func validateSlbInstanceSpecType(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		specType := LoadBalancerSpecType(value)
		validLoadBalancerSpec := []LoadBalancerSpecType{S1Small, S2Small, S2Medium, S3Small, S3Medium, S3Large}

		for _, s := range validLoadBalancerSpec {
			if s == specType {
				return
			}
		}
		errors = append(errors, fmt.Errorf("%q must contain a valid LoadBalancerSpecType,"+
			" expected %#v, got %q", k, validLoadBalancerSpec, value))
	}
	return
}

func validateSlbListenerBandwidth(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if (value < 1 || value > 1000) && value != -1 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid load balancer bandwidth between 1 and 1000 or -1",
			k))
		return
	}
	return
}

func validateSlbListenerScheduler(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		scheduler := SchedulerType(value)

		if scheduler != WRRScheduler && scheduler != WLCScheduler {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid SchedulerType, expected %s or %s, got %q",
				k, "wrr", "wlc", value))
		}
	}

	return
}

func validateSlbListenerCookie(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 1 || len(value) > 200 {
			errors = append(errors, fmt.Errorf("%q cannot be longer than 200 characters", k))
		}
	}
	return
}

func validateSlbListenerCookieTimeout(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 1 || value > 86400 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid load balancer cookie timeout between 1 and 86400",
			k))
		return
	}
	return
}

func validateSlbListenerPersistenceTimeout(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 0 || value > 3600 {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid load balancer persistence timeout between 0 and 86400",
			k))
		return
	}
	return
}

func validateSlbListenerHealthCheckDomain(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if value == "$_ip" {
			errors = append(errors, fmt.Errorf("%q value '$_ip' has been deprecated, and empty string will replace it.", k))
		}
		if reg := regexp.MustCompile(`^[\w\-.]{1,80}$`); !reg.MatchString(value) {
			errors = append(errors, fmt.Errorf("%q length is limited to 1-80 and only characters such as letters, digits, '-' and '.' are allowed", k))
		}
	}
	return
}

func validateSlbListenerHealthCheckUri(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 1 || len(value) > 80 {
			errors = append(errors, fmt.Errorf("%q cannot be longer than 80 characters", k))
		}
	}
	return
}

func validateSlbListenerHealthCheckConnectPort(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value < 1 || value > 65535 {
		if value != -520 {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid load balancer health check connect port between 1 and 65535 or -520",
				k))
			return
		}

	}
	return
}

func validateDBBackupPeriod(v interface{}, k string) (ws []string, errors []error) {
	days := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
	value := v.(string)
	exist := false
	for _, d := range days {
		if value == d {
			exist = true
			break
		}
	}
	if !exist {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid backup period value should in array %#v, got %q",
			k, days, value))
	}

	return
}

func validateAllowedStringValue(ss []string) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		value := Trim(v.(string))
		existed := false
		for _, s := range ss {
			if s == value {
				existed = true
				break
			}
		}
		if !existed {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid string value should be in array %#v, got %q",
				k, ss, value))
		}
		return

	}
}

func validateAllowedSplitStringValue(ss []string, splitStr string) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		value := v.(string)
		existed := false
		tsList := strings.Split(value, splitStr)

		for _, ts := range tsList {
			existed = false
			for _, s := range ss {
				if ts == s {
					existed = true
					break
				}
			}
		}
		if !existed {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid string value should in %#v, got %q",
				k, ss, value))
		}
		return

	}
}

func validateAllowedIntValue(is []int) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		value := v.(int)
		existed := false
		for _, i := range is {
			if i == value {
				existed = true
				break
			}
		}
		if !existed {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid int value should be in array %#v, got %q",
				k, is, value))
		}
		return

	}
}

func validateIntegerInRange(min, max int) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		value := v.(int)
		if value < min || value > max {
			errors = append(errors, fmt.Errorf(
				"%q cannot be lower than %d and larger than %d. Current value is %d.", k, min, max, value))
		}
		return
	}
}

func validateStringLengthInRange(min, max int) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		value := v.(string)
		if len(value) < min || len(value) > max {
			errors = append(errors, fmt.Errorf(
				"%q length cannot be lower than %d and larger than %d. Current length is %d.", k, min, max, len(value)))
		}
		return
	}
}

//data source validate func
//data_source_alicloud_image
func validateNameRegex(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if _, err := regexp.Compile(value); err != nil {
		errors = append(errors, fmt.Errorf(
			"%q contains an invalid regular expression: %s",
			k, err))
	}
	return
}

func validateImageOwners(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		owners := ImageOwnerAlias(value)
		if owners != ImageOwnerSystem &&
			owners != ImageOwnerSelf &&
			owners != ImageOwnerOthers &&
			owners != ImageOwnerMarketplace &&
			owners != ImageOwnerDefault {
			errors = append(errors, fmt.Errorf(
				"%q must contain a valid Image owner , expected %s, %s, %s, %s or %s, got %q",
				k, ImageOwnerSystem, ImageOwnerSelf, ImageOwnerOthers, ImageOwnerMarketplace, ImageOwnerDefault, owners))
		}
	}
	return
}

func validateRegion(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		region := common.Region(value)
		var valid string
		for _, re := range common.ValidRegions {
			if region == re {
				return
			}
			valid = valid + ", " + string(re)
		}
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid Region ID , expected %#v, got %q",
			k, valid, value))

	}
	return
}

func validateForwardPort(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "any" {
		valueConv, err := strconv.Atoi(value)
		if err != nil || valueConv < 1 || valueConv > 65535 {
			errors = append(errors, fmt.Errorf("%q must be a valid port between 1 and 65535 or any ", k))
		}
	}
	return
}

func validateOssBucketName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 3 || len(value) > 63 {
		errors = append(errors, fmt.Errorf("%q cannot be less than 3 and longer than 63 characters", k))
	}
	return
}

func validateOssBucketAcl(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		acls := oss.ACLType(value)
		if acls != oss.ACLPrivate && acls != oss.ACLPublicRead && acls != oss.ACLPublicReadWrite {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid ACL value , expected %s, %s or %s, got %q",
				k, oss.ACLPrivate, oss.ACLPublicRead, oss.ACLPublicReadWrite, acls))
		}
	}
	return
}

func validateOssBucketLifecycleRuleId(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) > 255 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 255 characters", k))
	}
	return
}

func validateOssBucketDateTimestamp(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	_, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT00:00:00Z", value))
	if err != nil {
		errors = append(errors, fmt.Errorf(
			"%q cannot be parsed as RFC3339 Timestamp Format", value))
	}
	return
}

func validateOssBucketObjectServerSideEncryption(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if ServerSideEncryptionAes256 != value {
		errors = append(errors, fmt.Errorf(
			"%q must be a valid value, expected %s", k, ServerSideEncryptionAes256))
	}
	return
}

func validateDomainName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if vp := strings.Split(value, "."); len(vp) > 1 {
		mainDomain := strings.Join(vp[:len(vp)-1], ".")
		if len(mainDomain) > 63 || len(mainDomain) < 1 {
			errors = append(errors, fmt.Errorf("Main domain cannot be longer than 63 characters or less than 1 character"))
		}
	}

	if strings.HasSuffix(value, ".sh") || strings.HasSuffix(value, ".tel") {
		errors = append(errors, fmt.Errorf("Domain ends with .sh or .tel is not supported."))
	}

	if strings.HasPrefix(value, "-") || strings.HasSuffix(value, "-") {
		errors = append(errors, fmt.Errorf("Domain name is invalid, it can not starts or ends with '-'"))
	}
	return
}

func validateDomainRecordType(v interface{}, k string) (ws []string, errors []error) {
	// Valid Record types
	// A, NS, MX, TXT, CNAME, SRV, AAAA, REDIRECT_URL, FORWORD_URL
	validTypes := map[string]string{
		dns.ARecord:           "",
		dns.NSRecord:          "",
		dns.MXRecord:          "",
		dns.TXTRecord:         "",
		dns.CNAMERecord:       "",
		dns.SRVRecord:         "",
		dns.AAAARecord:        "",
		dns.RedirectURLRecord: "",
		dns.ForwordURLRecord:  "",
	}

	value := v.(string)
	if _, ok := validTypes[value]; !ok {
		errors = append(errors, fmt.Errorf("%q must be one of [A, NS, MX, TXT, CNAME, SRV, AAAA, REDIRECT_URL, FORWORD_URL]", k))
	}
	return
}

func validateDomainRecordPriority(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value > 10 || value < 1 {
		errors = append(errors, fmt.Errorf("%q value is 1-10.", k))
	}
	return
}

func validateRR(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if strings.HasPrefix(value, "-") || strings.HasSuffix(value, "-") {
		errors = append(errors, fmt.Errorf("RR is invalid, it can not starts or ends with '-'"))
	}

	if len(value) > 253 {
		errors = append(errors, fmt.Errorf("RR can not longer than 253 characters."))
	}

	for _, part := range strings.Split(value, ".") {
		if len(part) > 63 {
			errors = append(errors, fmt.Errorf("Each part of RR split with . can not longer than 63 characters."))
			return
		}
	}
	return
}

func validateDomainRecordLine(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "default" && value != "telecom" && value != "unicom" && value != "mobile" && value != "oversea" && value != "edu" {
		errors = append(errors, fmt.Errorf("Record parsing line must be one of [default, telecom, unicom, mobile, oversea, edu]."))
	}
	return
}

func validateKeyPairName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 128 characters and less than 2", k))
	}

	if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
		errors = append(errors, fmt.Errorf("%s cannot starts with http:// or https://", k))
	}

	return
}

func validateKeyPairPrefix(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) > 100 {
		errors = append(errors, fmt.Errorf(
			"%q cannot be longer than 100 characters, name is limited to 128", k))
	}

	return
}

func validateRamName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 64 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 64 characters.", k))
	}

	pattern := `^[a-zA-Z0-9\.@\-_]+$`
	if match, _ := regexp.Match(pattern, []byte(value)); !match {
		errors = append(errors, fmt.Errorf("%q is invalid.", k))
	}
	return
}

func validateRamDisplayName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	pattern := `^[a-zA-Z0-9\.@\-\p{Han}]{1,12}$`
	if match, _ := regexp.Match(pattern, []byte(value)); !match {
		errors = append(errors, fmt.Errorf("%q is invalid.", k))
	}
	return
}

func validateComment(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 128 characters.", k))
	}
	return
}

func validateRamDesc(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 1024 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 1024 characters.", k))
	}
	return
}

func validateRamPolicyName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 128 characters.", k))
	}

	pattern := `^[a-zA-Z0-9\-]+$`
	if match, _ := regexp.Match(pattern, []byte(value)); !match {
		errors = append(errors, fmt.Errorf("%q is invalid.", k))
	}
	return
}

// Takes a value containing JSON string and passes it through
// the JSON parser to normalize it, returns either a parsing
// error or normalized JSON string.
func normalizeYamlString(yamlString interface{}) (string, error) {
	var j interface{}

	if yamlString == nil || yamlString.(string) == "" {
		return "", nil
	}

	s := yamlString.(string)

	err := yaml.Unmarshal([]byte(s), &j)
	if err != nil {
		return s, err
	}

	// The error is intentionally ignored here to allow empty policies to passthrough validation.
	// This covers any interpolated values
	bytes, _ := yaml.Marshal(j)

	return string(bytes[:]), nil
}

// Takes a value containing JSON string and passes it through
// the JSON parser to normalize it, returns either a parsing
// error or normalized JSON string.
func normalizeJsonString(jsonString interface{}) (string, error) {
	var j interface{}

	if jsonString == nil || jsonString.(string) == "" {
		return "", nil
	}

	s := jsonString.(string)

	err := json.Unmarshal([]byte(s), &j)
	if err != nil {
		return s, err
	}

	// The error is intentionally ignored here to allow empty policies to passthrough validation.
	// This covers any interpolated values
	bytes, _ := json.Marshal(j)

	return string(bytes[:]), nil
}

func validateYamlString(v interface{}, k string) (ws []string, errors []error) {
	if _, err := normalizeYamlString(v); err != nil {
		errors = append(errors, fmt.Errorf("%q contains an invalid YAML: %s", k, err))
	}

	return
}

func validateJsonString(v interface{}, k string) (ws []string, errors []error) {
	if _, err := normalizeJsonString(v); err != nil {
		errors = append(errors, fmt.Errorf("%q contains an invalid JSON: %s", k, err))
	}
	return
}

func validatePolicyType(v interface{}, k string) (ws []string, errors []error) {
	value := ram.Type(v.(string))

	if value != ram.System && value != ram.Custom {
		errors = append(errors, fmt.Errorf("%q must be '%s' or '%s'.", k, ram.System, ram.Custom))
	}
	return
}

func validateRamGroupName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 64 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 64 characters.", k))
	}

	pattern := `^[a-zA-Z0-9\-]+$`
	if match, _ := regexp.Match(pattern, []byte(value)); !match {
		errors = append(errors, fmt.Errorf("%q is invalid.", k))
	}
	return
}

func validateRamAlias(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if len(value) > 32 || len(value) < 2 {
		errors = append(errors, fmt.Errorf("%q can not be longer than 32 or less than 2 characters.", k))
	}
	return
}

func validateRamAKStatus(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if value != string(Active) && value != string(Inactive) {
		errors = append(errors, fmt.Errorf("%q must be 'Active' or 'Inactive'.", k))
	}
	return
}

func validateContainerName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 1 || len(value) > 63 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 63 characters and less than 1", k))
	}
	reg := regexp.MustCompile("^[a-zA-Z0-9\u4E00-\u9FA5]{1}[a-zA-Z0-9\u4E00-\u9FA5-]{0,62}$")
	if !reg.MatchString(value) {
		errors = append(errors, fmt.Errorf("%s should be 1-63 characters long, and can contain numbers, Chinese characters, English letters and hyphens, but cannot start with hyphens.", k))
	}

	return
}

func validateContainerNamePrefix(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) > 37 {
		errors = append(errors, fmt.Errorf(
			"%q cannot be longer than 37 characters, name is limited to 63", k))
	}

	reg := regexp.MustCompile("^[a-zA-Z0-9\u4E00-\u9FA5]?[a-zA-Z0-9\u4E00-\u9FA5-]{0,36}$")
	if !reg.MatchString(value) {
		errors = append(errors, fmt.Errorf("%s should be 0-37 characters long, and can contain numbers, Chinese characters, English letters and hyphens, but cannot start with hyphens.", k))
	}

	return
}

func validateContainerAppName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	reg := regexp.MustCompile("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,63}$")
	if !reg.MatchString(value) {
		errors = append(errors, fmt.Errorf("%s should be 1-64 characters long, and can contain numbers, English letters and hyphens, but cannot start with hyphens.", k))
	}

	return
}

func validateCdnChargeType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)

	if value != "PayByTraffic" && value != "PayByBandwidth" {
		errors = append(errors, fmt.Errorf("%q must be 'PayByTraffic' or 'PayByBandwidth'.", k))
	}
	return
}

func validateCdnType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	for _, val := range cdn.CdnTypes {
		if val == value {
			return
		}
	}
	errors = append(errors, fmt.Errorf("%q must be one of %v.", k, cdn.CdnTypes))
	return
}

func validateCdnSourceType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	for _, val := range cdn.SourceTypes {
		if val == value {
			return
		}
	}
	errors = append(errors, fmt.Errorf("%q must be one of %v.", k, cdn.SourceTypes))
	return
}

func validateCdnScope(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	for _, val := range cdn.Scopes {
		if val == value {
			return
		}
	}
	errors = append(errors, fmt.Errorf("%q must be one of %v.", k, cdn.Scopes))
	return
}

func validateCdnSourcePort(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value != 80 && value != 443 {
		errors = append(errors, fmt.Errorf("%q must be one 80 or 443.", k))
	}
	return
}

func validateCdnHttpHeader(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	for _, val := range cdn.HeaderKeys {
		if val == value {
			return
		}
	}
	errors = append(errors, fmt.Errorf("%q must be one of %v.", k, cdn.HeaderKeys))
	return
}

func validateCacheType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "suffix" && value != "path" {
		errors = append(errors, fmt.Errorf("%q must be 'suffix' or 'path'.", k))
	}
	return
}

func validateCdnEnable(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "on" && value != "off" {
		errors = append(errors, fmt.Errorf("%q must be 'on' or 'off'.", k))
	}
	return
}

func validateCdnHashKeyArg(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if strings.Contains(value, ",") {
		errors = append(errors, fmt.Errorf("%q can not contains any ','.", k))
	}
	return
}

func validateCdnPage404Type(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "default" && value != "charity" && value != "other" {
		errors = append(errors, fmt.Errorf("%q must be one of ['default', 'charity', 'other'].", k))
	}
	return
}

func validateCdnRedirectType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "Off" && value != "Http" && value != "Https" {
		errors = append(errors, fmt.Errorf("%q must be one of ['Off', 'Http', 'Https'].", k))
	}
	return
}

func validateCdnReferType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "block" && value != "allow" {
		errors = append(errors, fmt.Errorf("%q must be 'block' or 'allow'.", k))
	}
	return
}

func validateCdnAuthType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "no_auth" && value != "type_a" && value != "type_b" && value != "type_c" {
		errors = append(errors, fmt.Errorf("%q must be one of ['no_auth', 'type_a', 'type_b', 'type_c']", k))
	}
	return
}

func validateCdnAuthKey(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	pattern := `^[a-zA-Z0-9]{6,32}$`
	if match, _ := regexp.Match(pattern, []byte(value)); !match {
		errors = append(errors, fmt.Errorf("%q can only consists of alphanumeric characters and can not be longer than 32 or less than 6 characters.", k))
	}
	return
}

func validatePolicyDocVersion(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if value != "1" {
		errors = append(errors, fmt.Errorf("%q can only be '1' so far.", k))
	}
	return
}

func validateRouterInterfaceDescription(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 2 || len(value) > 256 {
		errors = append(errors, fmt.Errorf("%q cannot be less than 2 characters or longer than 256 characters", k))
	}

	if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
		errors = append(errors, fmt.Errorf("%s cannot starts with http:// or https://", k))
	}
	return
}

func validateInstanceType(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if !strings.HasPrefix(value, "ecs.") {
		errors = append(errors, fmt.Errorf("Invalid %q: %s. It must be 'ecs.' as prefix.", k, value))
	}
	return
}

func validateDBConnectionPort(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		port, err := strconv.Atoi(value)
		if err != nil {
			errors = append(errors, err)
		}
		if port < 3001 || len(value) > 3999 {
			errors = append(errors, fmt.Errorf("%q cannot be less than 3001 and larger than 3999.", k))
		}
	}
	return
}

func validateInstanceSpotStrategy(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		spot := SpotStrategyType(value)
		if spot != NoSpot && spot != SpotAsPriceGo && spot != SpotWithPriceLimit {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid Spot Strategy value , expected %s, %s or %s, got %q",
				k, NoSpot, SpotAsPriceGo, SpotWithPriceLimit, spot))
		}
	}
	return
}

func validateDBConnectionPrefix(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 1 || len(value) > 31 {
			errors = append(errors, fmt.Errorf("%q cannot be less than 1 and larger than 30.", k))
		}
	}
	return
}

func validateDBInstanceName(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 2 || len(value) > 256 {
			errors = append(errors, fmt.Errorf("%q cannot be less than 1 and larger than 30.", k))
		}
	}
	return
}

func validateRKVInstanceName(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 2 || len(value) > 128 {
			errors = append(errors, fmt.Errorf("%q cannot be less than 2 and larger than 128.", k))
		}
	}
	return
}

func validateRKVPassword(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 8 || len(value) > 30 {
			errors = append(errors, fmt.Errorf("%q cannot be less than 8 and larger than 30", k))
		}
		if strings.ContainsAny(value, "! < > ( ) [ ] { { , ` ~ . - _ @ # $ % ^ & *") {
			errors = append(errors, fmt.Errorf("%q cannot contain exclamation mark (!), angle brackets (<>), parentheses (()), square brackets ([]), braces ({}), comma (,), backquote (`), tilde (~), period (.), hyphen (-), underscore (_), at sign (@), number sign (#), dollar sign ($), percent sign %%), caret (^), ampersand (&), and asterisk (*)", k))
		}
	}
	return
}

func validateKmsKeyStatus(v interface{}, k string) (ws []string, errors []error) {
	status := KeyState(v.(string))
	if status != Enabled && status != Disabled && status != PendingDeletion {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid status, expected %s or %s or %s, got %s.",
			k, Enabled, Disabled, PendingDeletion, status))
	}
	return
}

func validateNatGatewaySpec(v interface{}, k string) (ws []string, errors []error) {
	spec := NatGatewaySpec(v.(string))
	if spec != NatGatewaySmallSpec && spec != NatGatewayMiddleSpec && spec != NatGatewayLargeSpec {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid specification, expected %s or %s or %s, got %s.",
			k, NatGatewaySmallSpec, NatGatewayMiddleSpec, NatGatewayLargeSpec, spec))
	}
	return
}

func validateEipChargeTypePeriod(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if (value > 0 && value < 10) || (value > 11 && value < 37 && value%12 == 0) {
		return
	}
	errors = append(errors, fmt.Errorf(
		"%q must be a valid period, expected [1-9], 12, 24 or 36, got %d.", k, value))
	return
}

func validateRouterInterfaceChargeTypePeriod(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if (value > 0 && value < 10) || (value > 11 && value < 37 && value%12 == 0) {
		return
	}
	errors = append(errors, fmt.Errorf(
		"%q must be a valid period, expected [1-9], 12, 24 or 36, got %d.", k, value))
	return
}

// VPN
func validateVpnName(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 1 || len(value) > 128 {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid vpn name characters between 2 and 128",
				k))
			return
		}
	}

	return
}

// period : 1-9 | 12 | 24 | 36
func validateVpnPeriod(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if (value >= 1 && value <= 9) || value == 12 || value == 24 || value == 36 {
		return
	}
	errors = append(errors, fmt.Errorf("%q must contain a valid period (1-9|12|24|36), got %s", k, string(value)))
	return
}

func validateVpnBandwidth(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value != 5 && value != 10 && value != 20 && value != 50 && value != 100 {
		errors = append(errors, fmt.Errorf("%q must contain a valid bandwith (prepaid user: 5|10|20|50|100 ; postpaid user: 10|100), got %q", k, string(value)))
		return
	}
	return
}

func validateVpnDescription(v interface{}, k string) (ws []string, errors []error) {
	if value := v.(string); value != "" {
		if len(value) < 2 || len(value) > 256 {
			errors = append(errors, fmt.Errorf(
				"%q must be a valid vpn description characters between 2 and 256",
				k))
			return
		}
	}

	return
}

func validateSslVpnPortValue(is []int) schema.SchemaValidateFunc {
	return func(v interface{}, k string) (ws []string, errors []error) {
		ws, errors = validateInstancePort(v, k)
		if errors != nil {
			return
		}

		value := v.(int)
		for _, i := range is {
			if i == value {
				errors = append(errors, fmt.Errorf(
					"%q must contain a valid int value should not be in array %#v, got %q",
					k, is, value))
				return
			}
		}
		return

	}
}

func validateEvaluationCount(v interface{}, k string) (ws []string, errors []error) {
	value := v.(int)
	if value <= 0 {
		errors = append(errors, fmt.Errorf(
			"%q must contain a valid evaluation count , expected greater than zero, got %d",
			k, value))
	}

	return
}

func validateDatahubProjectName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 3 || len(value) > 32 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 32 characters and less than 3", k))
	}
	reg := regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9_]{2,31}$")
	if !reg.MatchString(value) {
		errors = append(errors, fmt.Errorf("%s length is limited to 3-32 and only characters such as letters, digits and '_' are allowed", k))
	}

	return
}

func validateDatahubTopicName(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len(value) < 1 || len(value) > 128 {
		errors = append(errors, fmt.Errorf("%q cannot be longer than 128 characters and less than 1", k))
	}
	reg := regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9_]{0,127}$")
	if !reg.MatchString(value) {
		errors = append(errors, fmt.Errorf("%s length is limited to 1-128 and only characters such as letters, digits and '_' are allowed", k))
	}

	return
}

func validateEndpoint(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	if len([]rune(value)) <= 0 {
		return
	}
	url := "^http://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]$"
	queue := "^acs:mns:\\S{2}-\\S+:\\d+:queues/\\S+$"
	email := "^directmail:\\w+@\\w+\\.\\w{2,4}$"
	urlRe, err := regexp.Compile(url)
	if err != nil {
		panic(fmt.Errorf("url pattern has an error! %#v", err))
	}
	queueRe, err := regexp.Compile(queue)
	if err != nil {
		panic(fmt.Errorf("queue pattern has an error! %#v", err))
	}
	emailRe, err := regexp.Compile(email)
	if err != nil {
		panic(fmt.Errorf("email pattern has an error! %#v", err))
	}
	if !urlRe.MatchString(value) && !queueRe.MatchString(value) && !emailRe.MatchString(value) {
		errors = append(errors, fmt.Errorf(
			"%q must match the format.the format should be start with `http://` or directmail:{MailAddress} or acs:mns:{REGION}:{AccountID}:queues/{QueueName}, got %s",
			k, value))
	}
	return

}