text:
/*
 * StockManager.cpp
 *
 *  Created on: 2011-11-9
 *      Author: fasiondog
 */

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include "GlobalInitializer.h"
#include <chrono>
#include <fmt/format.h>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>

#include "utilities/IniParser.h"
#include "utilities/util.h"
#include "utilities/thread/ThreadPool.h"
#include "StockManager.h"
#include "global/GlobalTaskGroup.h"
#include "global/schedule/inner_tasks.h"
#include "data_driver/kdata/cvs/KDataTempCsvDriver.h"
#include "data_driver/base_info/sqlite/SQLiteBaseInfoDriver.h"
#include "data_driver/base_info/mysql/MySQLBaseInfoDriver.h"
#include "data_driver/block_info/qianlong/QLBlockInfoDriver.h"
#include "data_driver/kdata/hdf5/H5KDataDriver.h"
#include "data_driver/kdata/tdx/TdxKDataDriver.h"
#include "data_driver/kdata/mysql/MySQLKDataDriver.h"

namespace hku {

StockManager* StockManager::m_sm = nullptr;

void StockManager::quit() {
    if (m_sm) {
        delete m_sm;
        m_sm = nullptr;
    }
}

StockManager::StockManager() : m_initializing(false) {
    m_stockDict_mutex = new std::mutex;
    m_marketInfoDict_mutex = new std::mutex;
    m_stockTypeInfo_mutex = new std::mutex;
    m_holidays_mutex = new std::mutex;
}

StockManager::~StockManager() {
    delete m_stockDict_mutex;
    delete m_marketInfoDict_mutex;
    delete m_stockTypeInfo_mutex;
    delete m_holidays_mutex;
    fmt::print("Quit Hikyuu system!\n\n");
}

StockManager& StockManager::instance() {
    if (!m_sm) {
        m_sm = new StockManager();
    }
    return (*m_sm);
}

Parameter default_preload_param() {
    Parameter param;
    param.set<bool>("day", true);
    param.set<bool>("week", false);
    param.set<bool>("month", false);
    param.set<bool>("quarter", false);
    param.set<bool>("halfyear", false);
    param.set<bool>("year", false);
    param.set<bool>("min", false);
    param.set<bool>("min5", false);
    param.set<bool>("min15", false);
    param.set<bool>("min30", false);
    param.set<bool>("min60", false);
    param.set<bool>("ticks", false);
    param.set<int>("day_max", 100000);
    param.set<int>("week_max", 100000);
    param.set<int>("month_max", 100000);
    param.set<int>("quarter_max", 100000);
    param.set<int>("halfyear_max", 100000);
    param.set<int>("year_max", 100000);
    param.set<int>("min_max", 5120);
    param.set<int>("min5_max", 5120);
    param.set<int>("min15_max", 5120);
    param.set<int>("min30_max", 5120);
    param.set<int>("min60_max", 5120);
    param.set<int>("ticks_max", 5120);
    return param;
}

Parameter default_other_param() {
    Parameter param;
    param.set<string>("tmpdir", ".");
    param.set<string>("logger", "");
    return param;
}

void StockManager::init(const Parameter& baseInfoParam, const Parameter& blockParam,
                        const Parameter& kdataParam, const Parameter& preloadParam,
                        const Parameter& hikyuuParam, const StrategyContext& context) {
    HKU_WARN_IF_RETURN(m_initializing, void(),
                       "The last initialization has not finished. Please try again later!");
    m_initializing = true;
    m_thread_id = std::this_thread::get_id();
    m_baseInfoDriverParam = baseInfoParam;
    m_blockDriverParam = blockParam;
    m_kdataDriverParam = kdataParam;
    m_preloadParam = preloadParam;
    m_hikyuuParam = hikyuuParam;
    m_context = context;

    // 获取路径信息
    m_tmpdir = hikyuuParam.tryGet<string>("tmpdir", ".");
    m_datadir = hikyuuParam.tryGet<string>("datadir", ".");

    m_stockDict.clear();
    m_marketInfoDict.clear();
    m_stockTypeInfo.clear();

    string funcname(" [StockManager::init]");

    //加载证券基本信息
    m_baseInfoDriver = DataDriverFactory::getBaseInfoDriver(baseInfoParam);
    HKU_CHECK(m_baseInfoDriver, "Failed get base info driver!");

    loadAllHolidays();
    loadAllMarketInfos();
    loadAllStockTypeInfo();
    loadAllStocks();
    loadAllStockWeights();

    //获取板块驱动
    m_blockDriver = DataDriverFactory::getBlockDriver(blockParam);

    //获取K线数据驱动并预加载指定的数据
    HKU_INFO("Loading KData...");
    std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now();

    setKDataDriver(DataDriverFactory::getKDataDriverPool(m_kdataDriverParam));

    // add special Market, for temp csv file
    m_marketInfoDict["TMP"] =
      MarketInfo("TMP", "Temp Csv file", "temp load from csv file", "000001", Null<Datetime>(),
                 TimeDelta(0), TimeDelta(0), TimeDelta(0), TimeDelta(0));

    std::chrono::duration<double> sec = std::chrono::system_clock::now() - start_time;
    HKU_INFO("{:<.2f}s Loaded Data.", sec.count());
    m_initializing = false;
}

void StockManager::setKDataDriver(const KDataDriverConnectPoolPtr& driver) {
    HKU_ERROR_IF_RETURN(!driver, void(), "kdata driver is null!");

    if (m_kdataDriverParam != driver->getPrototype()->getParameter()) {
        m_kdataDriverParam = driver->getPrototype()->getParameter();
    }

    bool preload_day = m_preloadParam.tryGet<bool>("day", false);
    HKU_INFO_IF(preload_day, "Preloading all day kdata to buffer!");

    bool preload_week = m_preloadParam.tryGet<bool>("week", false);
    HKU_INFO_IF(preload_week, "Preloading all week kdata to buffer!");

    bool preload_month = m_preloadParam.tryGet<bool>("month", false);
    HKU_INFO_IF(preload_month, "Preloading all month kdata to buffer!");

    bool preload_quarter = m_preloadParam.tryGet<bool>("quarter", false);
    HKU_INFO_IF(preload_quarter, "Preloading all quarter kdata to buffer!");

    bool preload_halfyear = m_preloadParam.tryGet<bool>("halfyear", false);
    HKU_INFO_IF(preload_halfyear, "Preloading all halfyear kdata to buffer!");

    bool preload_year = m_preloadParam.tryGet<bool>("year", false);
    HKU_INFO_IF(preload_year, "Preloading all year kdata to buffer!");

    bool preload_min = m_preloadParam.tryGet<bool>("min", false);
    HKU_INFO_IF(preload_min, "Preloading all 1 min kdata to buffer!");

    bool preload_min5 = m_preloadParam.tryGet<bool>("min5", false);
    HKU_INFO_IF(preload_min5, "Preloading all 5 min kdata to buffer!");

    bool preload_min15 = m_preloadParam.tryGet<bool>("min15", false);
    HKU_INFO_IF(preload_min15, "Preloading all 15 min kdata to buffer!");

    bool preload_min30 = m_preloadParam.tryGet<bool>("min30", false);
    HKU_INFO_IF(preload_min30, "Preloading all 30 min kdata to buffer!");

    bool preload_min60 = m_preloadParam.tryGet<bool>("min60", false);
    HKU_INFO_IF(preload_min60, "Preloading all 60 min kdata to buffer!");

    if (!driver->getPrototype()->canParallelLoad()) {
        for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
            if (iter->second.market() == "TMP")
                continue;
            iter->second.setKDataDriver(driver);
            if (preload_day)
                iter->second.loadKDataToBuffer(KQuery::DAY);
            if (preload_week)
                iter->second.loadKDataToBuffer(KQuery::WEEK);
            if (preload_month)
                iter->second.loadKDataToBuffer(KQuery::MONTH);
            if (preload_quarter)
                iter->second.loadKDataToBuffer(KQuery::QUARTER);
            if (preload_halfyear)
                iter->second.loadKDataToBuffer(KQuery::HALFYEAR);
            if (preload_year)
                iter->second.loadKDataToBuffer(KQuery::YEAR);
            if (preload_min)
                iter->second.loadKDataToBuffer(KQuery::MIN);
            if (preload_min5)
                iter->second.loadKDataToBuffer(KQuery::MIN5);
            if (preload_min15)
                iter->second.loadKDataToBuffer(KQuery::MIN15);
            if (preload_min30)
                iter->second.loadKDataToBuffer(KQuery::MIN30);
            if (preload_min60)
                iter->second.loadKDataToBuffer(KQuery::MIN60);
        }

    } else {
        // 异步并行加载
        auto& tg = *getGlobalTaskGroup();
        for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
            if (iter->second.market() == "TMP")
                continue;
            iter->second.setKDataDriver(driver);
            if (preload_day)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::DAY); });
            if (preload_week)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::WEEK); });
            if (preload_month)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MONTH); });
            if (preload_quarter)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::QUARTER); });
            if (preload_halfyear)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::HALFYEAR); });
            if (preload_year)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::YEAR); });
            if (preload_min)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MIN); });
            if (preload_min5)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MIN5); });
            if (preload_min15)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MIN15); });
            if (preload_min30)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MIN30); });
            if (preload_min60)
                tg.submit([=]() mutable { iter->second.loadKDataToBuffer(KQuery::MIN60); });
        }
    }

    initInnerTasek();
}

void StockManager::reload() {
    loadAllHolidays();

    loadAllMarketInfos();
    loadAllStockTypeInfo();
    loadAllStocks();
    loadAllStockWeights();

    HKU_INFO("start reload kdata to buffer");
    std::vector<Stock> can_not_parallel_stk_list;  // 记录不支持并行加载的Stock
    {
        auto* tg = getGlobalTaskGroup();
        std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
        for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
            auto driver = iter->second.getKDataDirver();
            if (!driver->getPrototype()->canParallelLoad()) {
                can_not_parallel_stk_list.push_back(iter->second);
                continue;
            }

            auto& ktype_list = KQuery::getAllKType();
            for (auto& ktype : ktype_list) {
                if (iter->second.isBuffer(ktype)) {
                    tg->submit([=]() mutable {
                        Stock& stk = iter->second;
                        stk.loadKDataToBuffer(ktype);
                    });
                }
            }
        }
    }

    for (auto& stk : can_not_parallel_stk_list) {
        auto& ktype_list = KQuery::getAllKType();
        for (auto& ktype : ktype_list) {
            if (stk.isBuffer(ktype)) {
                stk.loadKDataToBuffer(ktype);
            }
        }
    }
}

string StockManager::tmpdir() const {
    return m_tmpdir;
}

string StockManager::datadir() const {
    return m_datadir;
}

Stock StockManager::getStock(const string& querystr) const {
    Stock result;
    string query_str = querystr;
    to_upper(query_str);
    std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
    auto iter = m_stockDict.find(query_str);
    return (iter != m_stockDict.end()) ? iter->second : result;
}

MarketInfo StockManager::getMarketInfo(const string& market) const {
    MarketInfo result;
    string market_tmp = market;
    to_upper(market_tmp);

    std::lock_guard<std::mutex> lock(*m_marketInfoDict_mutex);
    auto iter = m_marketInfoDict.find(market_tmp);
    if (iter != m_marketInfoDict.end()) {
        result = iter->second;
    } else {
        result = m_baseInfoDriver->getMarketInfo(market_tmp);
        if (result != Null<MarketInfo>()) {
            m_marketInfoDict[market_tmp] = result;
        }
    }
    return result;
}

StockTypeInfo StockManager::getStockTypeInfo(uint32_t type) const {
    StockTypeInfo result;
    std::lock_guard<std::mutex> lock(*m_stockTypeInfo_mutex);
    auto iter = m_stockTypeInfo.find(type);
    if (iter != m_stockTypeInfo.end()) {
        result = iter->second;
    } else {
        result = m_baseInfoDriver->getStockTypeInfo(type);
        if (result != Null<StockTypeInfo>()) {
            m_stockTypeInfo[type] = result;
        }
    }
    return result;
}

MarketList StockManager::getAllMarket() const {
    MarketList result;
    std::lock_guard<std::mutex> lock(*m_marketInfoDict_mutex);
    auto iter = m_marketInfoDict.begin();
    for (; iter != m_marketInfoDict.end(); ++iter) {
        result.push_back(iter->first);
    }
    return result;
}

Block StockManager::getBlock(const string& category, const string& name) {
    return m_blockDriver ? m_blockDriver->getBlock(category, name) : Block();
}

BlockList StockManager::getBlockList(const string& category) {
    return m_blockDriver ? m_blockDriver->getBlockList(category) : BlockList();
}

BlockList StockManager::getBlockList() {
    return m_blockDriver ? m_blockDriver->getBlockList() : BlockList();
}

DatetimeList StockManager::getTradingCalendar(const KQuery& query, const string& market) {
    auto marketinfo = getMarketInfo(market);
    return getStock(fmt::format("{}{}", marketinfo.market(), marketinfo.code()))
      .getDatetimeList(query);
}

Stock StockManager::addTempCsvStock(const string& code, const string& day_filename,
                                    const string& min_filename, price_t tick, price_t tickValue,
                                    int precision, size_t minTradeNumber, size_t maxTradeNumber) {
    string new_code(code);
    to_upper(new_code);
    Stock result("TMP", new_code, day_filename, STOCKTYPE_TMP, true, Datetime(199901010000),
                 Null<Datetime>(), tick, tickValue, precision, minTradeNumber, maxTradeNumber);

    Parameter param;
    param.set<string>("type", "TMPCSV");
    auto driver_pool = DataDriverFactory::getKDataDriverPool(param);
    auto driver = driver_pool->getPrototype();
    KDataTempCsvDriver* p = dynamic_cast<KDataTempCsvDriver*>(driver.get());
    p->setDayFileName(day_filename);
    p->setMinFileName(min_filename);
    result.setKDataDriver(driver_pool);
    const auto& preload_param = getPreloadParameter();
    if (preload_param.tryGet<bool>("day", true)) {
        result.loadKDataToBuffer(KQuery::DAY);
    }
    if (preload_param.tryGet<bool>("min", false)) {
        result.loadKDataToBuffer(KQuery::MIN);
    }
    return addStock(result) ? result : Null<Stock>();
}

void StockManager::removeTempCsvStock(const string& code) {
    string query_str = "TMP" + code;
    to_upper(query_str);
    auto iter = m_stockDict.find(query_str);
    if (iter != m_stockDict.end()) {
        m_stockDict.erase(iter);
    }
}

bool StockManager::addStock(const Stock& stock) {
    string market_code(stock.market_code());
    to_upper(market_code);
    std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
    HKU_ERROR_IF_RETURN(m_stockDict.find(market_code) != m_stockDict.end(), false,
                        "The stock had exist! {}", market_code);
    m_stockDict[market_code] = stock;
    return true;
}

void StockManager::loadAllStocks() {
    HKU_INFO("Loading stock information...");
    vector<StockInfo> stockInfos;
    if (m_context.isAll()) {
        stockInfos = m_baseInfoDriver->getAllStockInfo();
    } else {
        const vector<string>& context_stock_code_list = m_context.getStockCodeList();
        auto all_market = getAllMarket();
        for (auto stkcode : context_stock_code_list) {
            to_upper(stkcode);
            bool find = false;
            for (auto& market : all_market) {
                auto pos = stkcode.find(market);
                if (pos != string::npos && market.size() <= stkcode.size()) {
                    string stk_market = stkcode.substr(pos, market.size());
                    string stk_code = stkcode.substr(market.size(), stkcode.size());
                    stockInfos.push_back(m_baseInfoDriver->getStockInfo(stk_market, stk_code));
                    find = true;
                    break;
                }
            }
            HKU_WARN_IF(!find, "Invalid stock code: {}", stkcode);
        }
    }

    std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
    for (auto& info : stockInfos) {
        Datetime startDate, endDate;
        try {
            startDate = Datetime(info.startDate * 10000LL);
        } catch (...) {
            startDate = Null<Datetime>();
        }
        try {
            endDate = Datetime(info.endDate * 10000LL);
        } catch (...) {
            endDate = Null<Datetime>();
        }

        string market_code = format("{}{}", info.market, info.code);
        to_upper(market_code);
        auto iter = m_stockDict.find(market_code);
        if (iter == m_stockDict.end()) {
            Stock stock(info.market, info.code, info.name, info.type, info.valid, startDate,
                        endDate, info.tick, info.tickValue, info.precision, info.minTradeNumber,
                        info.maxTradeNumber);
            m_stockDict[market_code] = stock;

        } else {
            Stock& stock = iter->second;
            if (!stock.m_data) {
                stock.m_data = shared_ptr<Stock::Data>(
                  new Stock::Data(info.market, info.code, info.name, info.type, info.valid,
                                  startDate, endDate, info.tick, info.tickValue, info.precision,
                                  info.minTradeNumber, info.maxTradeNumber));
            } else {
                stock.m_data->m_market = info.market;
                stock.m_data->m_code = info.code;
                stock.m_data->m_name = info.name;
                stock.m_data->m_type = info.type;
                stock.m_data->m_valid = info.valid;
                stock.m_data->m_startDate = startDate;
                stock.m_data->m_lastDate = endDate;
                stock.m_data->m_tick = info.tick;
                stock.m_data->m_tickValue = info.tickValue;
                stock.m_data->m_precision = info.precision;
                stock.m_data->m_minTradeNumber = info.minTradeNumber;
                stock.m_data->m_maxTradeNumber = info.maxTradeNumber;
            }
        }
    }
}

void StockManager::loadAllMarketInfos() {
    HKU_INFO("Loading market information...");
    auto marketInfos = m_baseInfoDriver->getAllMarketInfo();
    std::lock_guard<std::mutex> lock(*m_marketInfoDict_mutex);
    m_marketInfoDict.clear();
    m_marketInfoDict.reserve(marketInfos.size());
    for (auto& marketInfo : marketInfos) {
        string market = marketInfo.market();
        to_upper(market);
        m_marketInfoDict[market] = marketInfo;
    }
}

void StockManager::loadAllStockTypeInfo() {
    HKU_INFO("Loading stock type information...");
    auto stkTypeInfos = m_baseInfoDriver->getAllStockTypeInfo();
    std::lock_guard<std::mutex> lock(*m_stockTypeInfo_mutex);
    m_stockTypeInfo.clear();
    m_stockTypeInfo.reserve(stkTypeInfos.size());
    for (auto& stkTypeInfo : stkTypeInfos) {
        m_stockTypeInfo[stkTypeInfo.type()] = stkTypeInfo;
    }
}

void StockManager::loadAllHolidays() {
    auto holidays = m_baseInfoDriver->getAllHolidays();
    std::lock_guard<std::mutex> lock(*m_holidays_mutex);
    m_holidays = std::move(holidays);
}

void StockManager::loadAllStockWeights() {
    HKU_INFO("Loading stock weight...");
    ThreadPool tg;  // 这里不用全局的线程池,可以避免在初始化后立即reload导致过长的等待
    std::vector<std::future<void>> task_list;
    std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
    for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
        task_list.push_back(tg.submit([=]() mutable {
            Stock& stock = iter->second;
            StockWeightList weightList = m_baseInfoDriver->getStockWeightList(
              stock.market(), stock.code(), Datetime::min(), Null<Datetime>());
            if (stock.m_data) {
                std::lock_guard<std::mutex> lock(stock.m_data->m_weight_mutex);
                stock.m_data->m_weightList.swap(weightList);
            }
        }));
    }
    // 权息信息如果不等待加载完毕,在数据加载期间进行计算可能导致复权错误,所以这里需要等待
    for (auto& task : task_list) {
        task.get();
    }
}

}  // namespace hku


text:
<!doctype html>

<meta charset="utf-8">
<title>Who Are You Lutra Lutra?? – Andreas Schik</title>
<meta name="description" content="Soeben bin ich auf eine Band namens "Who Are You Lutra Lutra??" gestoßen, die etwas spröde aber sehr schöne Musik machen.">
<meta name="keywords" content="Music">

<meta name="twitter:title" content="Who Are You Lutra Lutra??">
<meta name="twitter:description" content="Soeben bin ich auf eine Band namens "Who Are You Lutra Lutra??" gestoßen, die etwas spröde aber sehr schöne Musik machen.">

<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://localhost:4000/images/default-thumb.png">

<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="og:title" content="Who Are You Lutra Lutra??">
<meta property="og:description" content="Soeben bin ich auf eine Band namens "Who Are You Lutra Lutra??" gestoßen, die etwas spröde aber sehr schöne Musik machen.">
<meta property="og:url" content="http://localhost:4000/lutra_lutra/">
<meta property="og:site_name" content="Andreas Schik">

<link rel="canonical" href="http://localhost:4000/lutra_lutra/">
<link href="http://localhost:4000/feed.xml" type="application/atom+xml" rel="alternate" title="Andreas Schik Feed">

<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="http://localhost:4000/assets/css/main.css">

<meta http-equiv="cleartype" content="on">

<link href='//fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700%7CPT+Serif:400,700,400italic' rel='stylesheet' type='text/css'>

		Andreas Schik

About

Archive

Andreas Schik

Guitar, Football, Software.

   Facebook
   Google+

   Github

Who Are You Lutra Lutra??

Was steckt hinter dieser Band mit dem seltsamen Namen? "Who Are You Lutra Lutra??" kommen aus Brest in der Bretagne, leben und musizieren inzwischen in Berlin und haben nach eigener Aussage die halbe Welt bereist (na, für mich ist es die halbe Welt ;-).

Sie erzählen Geschichten, die ihnen unterwegs begegnet sind und bringen diese mit Ukulele, Gitarre, Mandoline und hellen Glocken zum klingen.

Who Are You Lutra Lutra??  sind Julien und Fabien. Sie ordnen sich selbst zwischen Damien Rice, Bonnie Prince Billy, Herman Düne oder Devendra Banhart ein. Ihre Musik beschreiben sie als "sometimes soft and calm, sometimes loud and sharp, but always elaborated with a compulsive need for a strong melodic line". Stimmt. Punkt.

Who Are You Lutra Lutra?? im Netz:
Homepage
Facebook
Bandcamp

Share on

       Twitter

       Facebook

       Google+

Who Are You Lutra Lutra?? was published on <time datetime="2014-03-21T00:00:00+01:00">March 21, 2014</time> and last modified on <time datetime="2014-03-21">March 21, 2014</time>.

You might also enjoy (View all posts)

Musikalische Entdeckung des Tages: Kandle Osborne

Heute Auf Dauerrotation: Nick Cave and the Bad Seeds – Push the Sky (Remix)

CDPlayer 0.6.0 Released

© 2015 Andreas Schik. Powered by Jekyll using the Minimal Mistakes theme.

redpajama_set_name: RedPajamaGithub


text:
package handlers

import (
	"net/http"
)

func Configurations(w http.ResponseWriter, r *http.Request) error {

  return nil
}


text:
Katalog programów pomocniczych i demonów Postfiksa

<tt>program_directory</tt>

Ten parametr okre¶la po³o¿enie demonów i programów pomocniczych
Postfiksa. W³a¶cicielem tego katalogu musi byæ <tt>root</tt>.


text:
package dml_test

import (
	"context"
	"testing"

	"github.com/DATA-DOG/go-sqlmock"
	"github.com/corestoreio/errors"
	"github.com/corestoreio/log"
	"github.com/corestoreio/pkg/sql/dml"
	"github.com/corestoreio/pkg/sql/dmltest"
	"github.com/corestoreio/pkg/storage/null"
	"github.com/corestoreio/pkg/util/assert"
)

func TestDelete_Prepare(t *testing.T) {
	t.Run("ToSQL Error", func(t *testing.T) {
		compareToSQL(t, dml.NewDelete("").Where(dml.Column("a").Int64(1)), errors.Empty, "", "")
	})

	t.Run("Prepare Error", func(t *testing.T) {
		d := &dml.Delete{
			BuilderBase: dml.BuilderBase{
				Table: dml.MakeIdentifier("table"),
			},
		}
		ddbr := d.WithDBR(dbMock{
			error: errors.AlreadyClosed.Newf("Who closed myself?"),
		})

		d.Where(dml.Column("a").Int(1))
		stmt, err := ddbr.Prepare(context.TODO())
		assert.Nil(t, stmt)
		assert.ErrorIsKind(t, errors.AlreadyClosed, err)
	})

	t.Run("ExecArgs One Row", func(t *testing.T) {
		dbc, dbMock := dmltest.MockDB(t)
		defer dmltest.MockClose(t, dbc, dbMock)

		prep := dbMock.ExpectPrepare(dmltest.SQLMockQuoteMeta("DELETE FROM `customer_entity` WHERE (`email` = ?) AND (`group_id` = ?)"))
		prep.ExpectExec().WithArgs("a@b.c", 33).WillReturnResult(sqlmock.NewResult(0, 1))
		prep.ExpectExec().WithArgs("x@y.z", 44).WillReturnResult(sqlmock.NewResult(0, 2))

		stmt, err := dbc.WithQueryBuilder(dml.NewDelete("customer_entity").
			Where(dml.Column("email").PlaceHolder(), dml.Column("group_id").PlaceHolder())).
			Prepare(context.TODO())
		assert.NoError(t, err, "failed creating a prepared statement")
		defer dmltest.Close(t, stmt)

		tests := []struct {
			email   string
			groupID int
			affRows int64
		}{
			{"a@b.c", 33, 1},
			{"x@y.z", 44, 2},
		}

		for i, test := range tests {
			res, err := stmt.ExecContext(context.TODO(), test.email, test.groupID)
			if err != nil {
				t.Fatalf("Index %d => %+v", i, err)
			}
			ra, err := res.RowsAffected()
			if err != nil {
				t.Fatalf("Result index %d with error: %s", i, err)
			}
			assert.Exactly(t, test.affRows, ra, "Index %d has different RowsAffected", i)
			stmt.Reset()
		}
	})

	t.Run("ExecRecord One Row", func(t *testing.T) {
		dbc, dbMock := dmltest.MockDB(t)
		defer dmltest.MockClose(t, dbc, dbMock)

		prep := dbMock.ExpectPrepare(dmltest.SQLMockQuoteMeta("DELETE FROM `dml_person` WHERE (`name` = ?) AND (`email` = ?)"))
		prep.ExpectExec().WithArgs("Peter Gopher", "peter@gopher.go").WillReturnResult(sqlmock.NewResult(0, 4))
		prep.ExpectExec().WithArgs("John Doe", "john@doe.go").WillReturnResult(sqlmock.NewResult(0, 5))

		stmt, err := dbc.WithQueryBuilder(dml.NewDelete("dml_person").
			Where(dml.Column("name").PlaceHolder(), dml.Column("email").PlaceHolder())).
			Prepare(context.TODO())
		assert.NoError(t, err, "failed creating a prepared statement")
		defer func() {
			assert.NoError(t, stmt.Close(), "Close on a prepared statement")
		}()

		tests := []struct {
			name     string
			email    string
			insertID int64
		}{
			{"Peter Gopher", "peter@gopher.go", 4},
			{"John Doe", "john@doe.go", 5},
		}

		for i, test := range tests {

			p := &dmlPerson{
				Name:  test.name,
				Email: null.MakeString(test.email),
			}

			res, err := stmt.ExecContext(context.TODO(), dml.Qualify("", p))
			if err != nil {
				t.Fatalf("Index %d => %+v", i, err)
			}
			lid, err := res.RowsAffected()
			if err != nil {
				t.Fatalf("Result index %d with error: %s", i, err)
			}
			assert.Exactly(t, test.insertID, lid, "Index %d has different RowsAffected", i)
		}
	})

	t.Run("ExecContext", func(t *testing.T) {
		dbc, dbMock := dmltest.MockDB(t)
		defer dmltest.MockClose(t, dbc, dbMock)

		prep := dbMock.ExpectPrepare(dmltest.SQLMockQuoteMeta("DELETE FROM `dml_person` WHERE (`name` = ?) AND (`email` = ?)"))
		prep.ExpectExec().WithArgs("Peter Gopher", "peter@gopher.go").WillReturnResult(sqlmock.NewResult(0, 4))

		stmt, err := dbc.WithQueryBuilder(dml.NewDelete("dml_person").
			Where(dml.Column("name").PlaceHolder(), dml.Column("email").PlaceHolder())).
			Prepare(context.TODO())
		assert.NoError(t, err, "failed creating a prepared statement")
		defer func() {
			assert.NoError(t, stmt.Close(), "Close on a prepared statement")
		}()

		res, err := stmt.ExecContext(context.TODO(), "Peter Gopher", "peter@gopher.go")
		assert.NoError(t, err, "failed to execute ExecContext")

		lid, err := res.RowsAffected()
		if err != nil {
			t.Fatal(err)
		}
		assert.Exactly(t, int64(4), lid, "Different RowsAffected")
	})
}

func TestDelete_Join(t *testing.T) {
	del1 := dml.NewDelete("customer_entity").Alias("ce").
		FromTables("customer_address", "customer_company").
		Join(
			dml.MakeIdentifier("customer_company").Alias("cc"),
			dml.Columns("ce.entity_id", "cc.customer_id"),
		).
		RightJoin(
			dml.MakeIdentifier("customer_address").Alias("ca"),
			dml.Columns("ce.entity_id", "ca.parent_id"),
		).
		Where(
			dml.Column("ce.created_at").Less().PlaceHolder(),
		)

	t.Run("JOIN USING with alias", func(t *testing.T) {
		compareToSQL(t, del1, errors.NoKind,
			"DELETE `ce`,`customer_address`,`customer_company` FROM `customer_entity` AS `ce` INNER JOIN `customer_company` AS `cc` USING (`ce.entity_id`,`cc.customer_id`) RIGHT JOIN `customer_address` AS `ca` USING (`ce.entity_id`,`ca.parent_id`) WHERE (`ce`.`created_at` < ?)",
			"",
		)
	})

	t.Run("JOIN USING with alias WithDBR", func(t *testing.T) {
		compareToSQL(t, del1.WithDBR(dbMock{}).TestWithArgs(now()), errors.NoKind,
			"DELETE `ce`,`customer_address`,`customer_company` FROM `customer_entity` AS `ce` INNER JOIN `customer_company` AS `cc` USING (`ce.entity_id`,`cc.customer_id`) RIGHT JOIN `customer_address` AS `ca` USING (`ce.entity_id`,`ca.parent_id`) WHERE (`ce`.`created_at` < ?)",
			"DELETE `ce`,`customer_address`,`customer_company` FROM `customer_entity` AS `ce` INNER JOIN `customer_company` AS `cc` USING (`ce.entity_id`,`cc.customer_id`) RIGHT JOIN `customer_address` AS `ca` USING (`ce.entity_id`,`ca.parent_id`) WHERE (`ce`.`created_at` < '2006-01-02 15:04:05')",
			now(),
		)
	})

	t.Run("LeftJoin USING without alias", func(t *testing.T) {
		del := dml.NewDelete("customer_entity").
			FromTables("customer_address").
			LeftJoin(
				dml.MakeIdentifier("customer_address").Alias("ca"),
				dml.Columns("ce.entity_id", "ca.parent_id"),
			).
			Where(
				dml.Column("ce.created_at").Less().PlaceHolder(),
			)

		compareToSQL(t, del, errors.NoKind,
			"DELETE `customer_entity`,`customer_address` FROM `customer_entity` LEFT JOIN `customer_address` AS `ca` USING (`ce.entity_id`,`ca.parent_id`) WHERE (`ce`.`created_at` < ?)",
			"",
		)
	})

	t.Run("OuterJoin USING without alias", func(t *testing.T) {
		del := dml.NewDelete("customer_entity").
			FromTables("customer_address").
			OuterJoin(
				dml.MakeIdentifier("customer_address").Alias("ca"),
				dml.Columns("ce.entity_id", "ca.parent_id"),
			)

		compareToSQL(t, del, errors.NoKind,
			"DELETE `customer_entity`,`customer_address` FROM `customer_entity` OUTER JOIN `customer_address` AS `ca` USING (`ce.entity_id`,`ca.parent_id`)",
			"",
		)
	})

	t.Run("JOIN USING without FromTables", func(t *testing.T) {
		del := dml.NewDelete("customer_entity").
			CrossJoin(
				dml.MakeIdentifier("customer_address").Alias("ca"),
				dml.Column("ce.entity_id").Equal().Column("ca.parent_id"),
			).
			Where(
				dml.Column("ce.created_at").Less().PlaceHolder(),
			)

		compareToSQL(t, del, errors.NoKind,
			"DELETE FROM `customer_entity` CROSS JOIN `customer_address` AS `ca` ON (`ce`.`entity_id` = `ca`.`parent_id`) WHERE (`ce`.`created_at` < ?)",
			"",
		)
	})
}

func TestDelete_Returning(t *testing.T) {
	t.Run("not allowed", func(t *testing.T) {
		del := dml.NewDelete("customer_entity").
			FromTables("customer_address").
			OuterJoin(
				dml.MakeIdentifier("customer_address").Alias("ca"),
				dml.Columns("ce.entity_id", "ca.parent_id"),
			)
		del.Returning = dml.NewSelect()
		compareToSQL(t, del, errors.NotAllowed,
			"",
			"",
		)
	})

	t.Run("return delete rows", func(t *testing.T) {
		del := dml.NewDelete("customer_entity").
			Where(
				dml.Column("ce.entity_id").GreaterOrEqual().PlaceHolder(),
			)
		del.Returning = dml.NewSelect("entity_id", "created_at").From("customer_entity")
		compareToSQL(t, del, errors.NoKind,
			"DELETE FROM `customer_entity` WHERE (`ce`.`entity_id` >= ?) RETURNING SELECT `entity_id`, `created_at` FROM `customer_entity`",
			"",
		)
	})
}

func TestDelete_Clone(t *testing.T) {
	dbc, dbMock := dmltest.MockDB(t, dml.WithLogger(log.BlackHole{}, func() string { return "uniqueID" }))
	defer dmltest.MockClose(t, dbc, dbMock)

	t.Run("nil", func(t *testing.T) {
		var d *dml.Delete
		d2 := d.Clone()
		assert.Nil(t, d)
		assert.Nil(t, d2)
	})

	t.Run("non-nil", func(t *testing.T) {
		d := dml.NewDelete("dml_people").Alias("dmlPpl").FromTables("a1", "b2").
			Where(
				dml.Column("id").PlaceHolder(),
			).OrderBy("id")
		d2 := d.Clone()
		notEqualPointers(t, d, d2)
		notEqualPointers(t, d, d2)
		notEqualPointers(t, d.BuilderConditional.Wheres, d2.BuilderConditional.Wheres)
		notEqualPointers(t, d.BuilderConditional.OrderBys, d2.BuilderConditional.OrderBys)
		notEqualPointers(t, d.MultiTables, d2.MultiTables)
		// assert.Exactly(t, d.DB, d2.DB)
	})
}


text:
module Hadupils::Search
  # Searches for directory containing a subdirectory `name`, starting at
  # the specified `start` directory and walking upwards until it can go
  # no farther.  On first match, the absolute path to that subdirectory
  # is returned.  If not found, returns nil.
  def self.find_from_dir(name, start)
    curr = ::File.expand_path(start)
    last = nil
    while curr != last
      p = ::File.join(curr, name)
      return p if ::File.directory? p
      last = curr
      curr = ::File.dirname(curr)
    end
    nil
  end

  # Performs a `find_from_dir` starting at the present working directory.
  def self.find_from_pwd(name)
    find_from_dir(name, ::Dir.pwd)
  end

  # The directory for user-specific configuration files.
  def self.user_config
    @user_config || ::File.expand_path(::File.join('~', 'conf'))
  end

  def self.user_config=(path)
    @user_config = path
  end

  # The basename to use when looking for hadoop assets from pwd.
  def self.hadoop_assets_name
    @hadoop_assets_name || 'hadoop-ext'
  end

  # Set the basename to use when looking for hadoop assets from pwd.
  def self.hadoop_assets_name=(basename)
    @hadoop_assets_name = basename
  end

  # A search for #hadoop_assets_name from the pwd.
  # The default behavior is to look for a subdir named "hadoop-ext",
  # starting from the current working directory and walking upwards until
  # a match is found or the file system root is encountered.
  def self.hadoop_assets
    find_from_pwd(hadoop_assets_name)
  end

  # The basename to use when looking for hive extensions from pwd.
  def self.hive_extensions_name
    @hive_extensions_name || 'hive-ext'
  end

  # Set the basename to use when looking for hive assets from pwd.
  def self.hive_extensions_name=(basename)
    @hive_extensions_name = basename
  end

  # A search for #hive_extensions_name from the pwd.
  # The default behavior is to look for a subdir named +hive-ext+,
  # starting from the current working directory and walking upwards until
  # a match is found or the file system root is encountered.
  def self.hive_extensions
    find_from_pwd(hive_extensions_name)
  end
end


text:
"""
AMQP management client for Qpid dispatch.
"""

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

import qpid_dispatch_site
import proton
from proton import Url
from .error import *        # import all error symbols for convenience to users.
from .entity import EntityBase, clean_dict
from proton.utils import SyncRequestResponse, BlockingConnection

class Entity(EntityBase):
    """
    Proxy for an AMQP manageable entity.

    Modifying local attributes dict will not change the remote entity. Call
    update() to send the local attributes to the remote entity.

    The standard AMQP requests read, update and delete are defined
    here. create() is defined on L{Node}.

    Attribute access:
    - via index operator: entity['foo']
    - as python attributes: entity.foo (only if attribute name is a legal python identitfier)

    @ivar attributes: Map of attribute values for this entity.
    """

    def __init__(self, node, attributes=None, **kwattrs):
        super(Entity, self).__init__(attributes, **kwattrs)
        self.__dict__['_node'] = node # Avoid getattr recursion

    def call(self, operation, expect=OK, **arguments):
        """Call an arbitrary management method on this entity"""
        request = self._node.request(
            operation=operation, type=self.type, identity=self.identity, **arguments)
        return self._node.call(request, expect=expect).body

    def read(self):
        """Read the remote entity attributes into the local attributes."""
        self.attributes = self.call(u'READ', expect=OK)

    def update(self):
        """Update the remote entity attributes from the local attributes."""
        self.attributes = self.call(u'UPDATE', expect=OK, body=self.attributes)

    def delete(self):
        """Delete the remote entity"""
        self.call(u'DELETE', expect=NO_CONTENT)

class Node(object):
    """Client proxy for an AMQP management node"""

    def clean_attrs(self, attrs):
        BOOL_VALUES = {"yes"  : True,
                       "true" : True,
                       "on"   : True,
                       "no"   : False,
                       "false": False,
                       "off"  : False}
        if isinstance(attrs, dict):
            for key in attrs.keys():
                if isinstance(attrs[key], str) and attrs[key] in BOOL_VALUES.keys():
                    attrs[key] = BOOL_VALUES[attrs[key]]

        return attrs

    @staticmethod
    def connection(url=None, router=None, timeout=10, ssl_domain=None, sasl=None, edge_router=None):
        """Return a BlockingConnection suitable for connecting to a management node
        @param url: URL of the management node.
        @param router: If address does not contain a path, use the management node for this router ID.
            If not specified and address does not contain a path, use the default management node.
        """
        url = Url(url)          # Convert string to Url class.

        if url.path is None:
            if router:
                url.path = u'_topo/0/%s/$management' % router
            elif edge_router:
                url.path = u'_edge/%s/$management' % edge_router
            else:
                url.path = u'$management'

        if ssl_domain:
            sasl_enabled = True
        else:
            sasl_enabled = True if sasl else False

        # if sasl_mechanism is unicode, convert it to python string
        return BlockingConnection(url,
                                  timeout=timeout,
                                  ssl_domain=ssl_domain,
                                  sasl_enabled=sasl_enabled,
                                  allowed_mechs=str(sasl.mechs) if sasl and sasl.mechs != None else None,
                                  user=str(sasl.user) if sasl and sasl.user != None else None,
                                  password=str(sasl.password) if sasl and sasl.password != None else None)

    @staticmethod
    def connect(url=None, router=None, timeout=10, ssl_domain=None, sasl=None,
                edge_router=None):
        """Return a Node connected with the given parameters, see L{connection}"""
        return Node(Node.connection(url, router, timeout, ssl_domain, sasl,
                                    edge_router=edge_router))

    def __init__(self, connection, locales=None):
        """
        Create a management node proxy using the given connection.
        @param locales: Default list of locales for management operations.
        @param connection: a L{BlockingConnection} to the management agent.
        """
        self.name = self.identity = u'self'
        self.type = u'org.amqp.management' # AMQP management node type
        self.locales = locales

        self.locales = locales
        self.url = connection.url
        self.client = SyncRequestResponse(connection, self.url.path)
        self.reply_to = self.client.reply_to
        self.connection = connection

    def set_client(self, url_path):
        if url_path:
            self.url.path = u'%s'%url_path
            self.client = SyncRequestResponse(self.connection, self.url.path)

    def close(self):
        """Shut down the node"""
        if self.client:
            self.client.connection.close()
            self.client = None

    def __repr__(self):
        return "%s(%s)"%(self.__class__.__name__, self.url)

    @staticmethod
    def check_response(response, expect=OK):
        """
        Check a management response message for errors and correlation ID.
        """
        code = response.properties.get(u'statusCode')
        if code != expect:
            if 200 <= code <= 299:
                raise ValueError("Response was %s(%s) but expected %s(%s): %s" % (
                    code, STATUS_TEXT[code], expect, STATUS_TEXT[expect],
                    response.properties.get(u'statusDescription')))
            else:
                raise ManagementError.create(code, response.properties.get(u'statusDescription'))

    def request(self, body=None, **properties):
        """
        Make a L{proton.Message} containining a management request.
        @param body: The request body, a dict or list.
        @param properties: Keyword arguments for application-properties of the request.
        @return: L{proton.Message} containining the management request.
        """
        if self.locales: properties.setdefault(u'locales', self.locales)
        request = proton.Message()
        request.properties = clean_dict(properties)
        request.body = body or {}
        return request

    def node_request(self, body=None, **properties):
        """Construct a request for the managment node itself"""
        return self.request(body, name=self.name, type=self.type, **properties)

    def call(self, request, expect=OK):
        """
        Send a management request message, wait for a response.
        @return: Response message.
        """
        response = self.client.call(request)
        self.check_response(response, expect=expect)
        return response

    class QueryResponse(object):
        """
        Result returned by L{query}.
        @ivar attribute_names: List of attribute names for the results.
        @ivar results: list of lists of attribute values in same order as attribute_names
        """
        def __init__(self, node, attribute_names, results):
            """
            @param response: the respose message to a query.
            """
            self.node = node
            self.attribute_names = attribute_names
            self.results = results

        def iter_dicts(self, clean=False):
            """
            Return an iterator that yields a dictionary for each result.
            @param clean: if True remove any None values from returned dictionaries.
            """
            for r in self.results:
                if clean: yield clean_dict(zip(self.attribute_names, r))
                else: yield dict(zip(self.attribute_names, r))

        def iter_entities(self, clean=False):
            """
            Return an iterator that yields an L{Entity} for each result.
            @param clean: if True remove any None values from returned dictionaries.
            """
            for d in self.iter_dicts(clean=clean): yield Entity(self.node, d)

        def get_dicts(self, clean=False):
            """Results as list of dicts."""
            return [d for d in self.iter_dicts(clean=clean)]

        def get_entities(self, clean=False):
            """Results as list of entities."""
            return [d for d in self.iter_entities(clean=clean)]

        def __repr__(self):
            return "QueryResponse(attribute_names=%r, results=%r"%(self.attribute_names, self.results)

    def query(self, type=None, attribute_names=None, offset=None, count=None):
        """
        Send an AMQP management query message and return the response.
        At least one of type, attribute_names must be specified.
        @keyword type: The type of entity to query.
        @keyword attribute_names: A list of attribute names to query.
        @keyword offset: An integer offset into the list of results to return.
        @keyword count: A count of the maximum number of results to return.
        @return: A L{QueryResponse}
        """

        # There is a bug in proton (PROTON-1846) wherein we cannot ask for
        # too many rows. So, as a safety we are going to ask only for
        # MAX_ALLOWED_COUNT_PER_REQUEST. Since this is used by both qdstat
        # and qdmanage, we have determined that the optimal value for
        # MAX_ALLOWED_COUNT_PER_REQUEST is 500
        MAX_ALLOWED_COUNT_PER_REQUEST = 500

        response_results = []
        response_attr_names = []
        if offset is None:
            offset = 0

        if count is None or count==0:
            # count has not been specified. For each request the
            # maximum number of rows we can get without proton
            # failing is MAX_ALLOWED_COUNT_PER_REQUEST
            request_count = MAX_ALLOWED_COUNT_PER_REQUEST
        else:
            request_count = min(MAX_ALLOWED_COUNT_PER_REQUEST, count)

        while True:
            request = self.node_request(
                {u'attributeNames': attribute_names or []},
                operation=u'QUERY', entityType=type, offset=offset,
                count=request_count)

            response = self.call(request)

            if not response_attr_names:
                response_attr_names += response.body[u'attributeNames']

            response_results += response.body[u'results']

            if len(response.body[u'results']) < request_count:
                break

            if count:
                len_response_results = len(response_results)
                if count == len_response_results:
                    break

                if count - len_response_results < request_count:
                    request_count = count - len_response_results

            offset += request_count

        query_reponse = Node.QueryResponse(self,
                                           response_attr_names,
                                           response_results)
        return query_reponse

    def create(self, attributes=None, type=None, name=None):
        """
        Create an entity.
        type and name can be specified in the attributes.

        @param attributes: Attributes for the new entity.
        @param type: Type of entity to create.
        @param name: Name for the new entity.
        @return: Entity proxy for the new entity.
        """
        attributes = attributes or {}
        type = type or attributes.get(u'type')
        name = name or attributes.get(u'name')
        request = self.request(operation=u'CREATE', type=type, name=name, body=attributes)
        return Entity(self, self.call(request, expect=CREATED).body)

    def read(self, type=None, name=None, identity=None):
        """
        Read an AMQP entity.
        If both name and identity are specified, only identity is used.

        @param type: Entity type.
        @param name: Entity name.
        @param identity: Entity identity.
        @return: An L{Entity}
        """
        if name and identity: name = None # Only specify one
        request = self.request(operation=u'READ', type=type, name=name, identity=identity)
        return Entity(self, self.call(request).body)

    def update(self, attributes, type=None, name=None, identity=None):
        """
        Update an entity with attributes.
        type, name and identity can be specified in the attributes.
        If both name and identity are specified, only identity is used.

        @param attributes: Attributes for the new entity.
        @param type: Entity type.
        @param name: Entity name.
        @param identity: Entity identity.
        @return: L{Entity} for the updated entity.

        """
        attributes = attributes or {}
        type = type or attributes.get(u'type')
        name = name or attributes.get(u'name')
        identity = identity or attributes.get(u'identity')
        if name and identity: name = None # Only send one
        request = self.request(operation=U'UPDATE', type=type, name=name,
                               identity=identity, body=self.clean_attrs(attributes))
        return Entity(self, self.call(request).body)

    def delete(self, type=None, name=None, identity=None):
        """
        Delete the remote entity.
        If both name and identity are specified, only identity is used.

        @param type: Entity type.
        @param name: Entity name.
        @param identity: Entity identity.
        """
        if name and identity: name = None # Only specify one
        request = self.request(operation=U'DELETE', type=type, name=name,
                               identity=identity)
        self.call(request, expect=NO_CONTENT)

    def get_types(self, type=None):
        return self.call(self.node_request(operation=u"GET-TYPES", entityType=type)).body

    def get_annotations(self, type=None):
        return self.call(self.node_request(operation=u"GET-ANNOTATIONS", entityType=type)).body

    def get_attributes(self, type=None):
        return self.call(self.node_request(operation=u"GET-ATTRIBUTES", entityType=type)).body

    def get_operations(self, type=None):
        return self.call(self.node_request(operation=u"GET-OPERATIONS", entityType=type)).body

    def get_mgmt_nodes(self, type=None):
        return self.call(self.node_request(operation=u"GET-MGMT-NODES", entityType=type)).body

    def get_log(self, limit=None, type=None):
        return self.call(self.node_request(operation=u"GET-LOG", entityType=type, limit=limit)).body


text:
const models = require("../../../models");
const log = require('../../utils/logger');
const toJson = require('../../utils/to_json');
const moment = require('moment');
const _ = require('lodash');

const getPointDomainIncludes = (id) => {
  return [
    {
      model: models.Post,
      required: true,
      attributes: [],
      include: getDomainIncludes(id)
    }
  ]
};

const getDomainIncludes = (id) => {
  return [
    {
      model: models.Group,
      required: true,
      attributes: [],
      include: [
        {
          model: models.Community,
          required: true,
          attributes: [],
          include: [
            {
              model: models.Domain,
              where: { id: id },
              required: true,
              attributes: []
            }
          ]
        }
      ]
    }
  ]
};

const getPointCommunityIncludes = (id) => {
  return [
    {
      model: models.Post,
      required: true,
      attributes: [],
      include: getCommunityIncludes(id)
    }
  ]
};

const getCommunityIncludes = (id) => {
  return [
    {
      model: models.Group,
      required: true,
      attributes: [],
      include: [
        {
          model: models.Community,
          where: { id: id },
          required: true,
          attributes: []
        }
      ]
    }
  ]
};

const getPointGroupIncludes = (id) => {
  return [
    {
      model: models.Post,
      required: true,
      attributes: [],
      include: getGroupIncludes(id)
    }
  ]
};

const getGroupIncludes = (id) => {
  return [
    {
      model: models.Group,
      required: true,
      where: { id: id },
      attributes: []
    }
  ]
};

const countModelRowsByTimePeriod = (req, cacheKey, model, whereOptions, includeOptions, done) => {
  const redisKey = "cachev4:"+cacheKey;
  req.redisClient.get(redisKey, (error, results) => {
    if (!error && results) {
      done(null, results);
    } else {
      if (error) {
        log.error('Could not get stats from redis', {
          err: error,
          context: 'countModelRowsByTimePeriod',
          userId: req.user ? req.user.id : null
        });
      }
      model.findAll({
        where: whereOptions,
        include: includeOptions,
        attributes: ['created_at'],
        order: [['created_at', 'ASC']]
      }).then((results) => {
        if (results && results.length>0) {const startDate = moment(results[0].created_at);
          const endDate = moment(results[results.length - 1].created_at);

          const days = _.groupBy(results, function (item) {
            return moment(item.created_at).format("YYYY/MM/DD");
          });

          const months = _.groupBy(results, function (item) {
            return moment(item.created_at).format("YYYY/MM");
          });

          const years = _.groupBy(results, function (item) {
            return moment(item.created_at).format("YYYY");
          });

          const totalDaysCount = endDate.diff(startDate, 'days', false) + 2;
          let currentDate = moment(results[0].created_at);
          let finalDays = [];
          for (let i = 0; i < totalDaysCount; i++) {
            const currentDateText = currentDate.format("YYYY/MM/DD");
            if (days[currentDateText]) {
              finalDays.push({x: currentDate.format("YYYY-MM-DD"), y: days[currentDateText].length})
            } else {
              //    finalDays.push({ x: currentDate.format("YYYY-MM-DD"), y: 0})
            }
            currentDate = currentDate.add(1, "days");
          }

          const totalMonthsCount = endDate.diff(startDate, 'months', false) + 2;
          let currentMonth = moment(results[0].created_at);
          let finalMonths = [];
          for (let i = 0; i < totalMonthsCount; i++) {
            const currentMonthText = currentMonth.format("YYYY/MM");
            if (months[currentMonthText]) {
              finalMonths.push({x: currentMonth.format("YYYY-MM"), y: months[currentMonthText].length})
            } else {
              //    finalMonths.push({ x: currentMonth.format("YYYY-MM"), y: 0})
            }
            currentMonth = currentMonth.add(1, "months");
          }

          const totalYearsCount = endDate.diff(startDate, 'years', false) + 2;
          let currentYear = moment(results[0].created_at);
          let finalYears = [];
          for (let i = 0; i < totalYearsCount; i++) {
            const currentYearText = currentYear.format("YYYY");
            if (years[currentYearText]) {
              finalYears.push({x: currentYearText, y: years[currentYearText].length})
            } else {
//        finalYears.push({ x: currentYearText, y: 0})
            }
            currentYear = currentYear.add(1, "years");
          }

          const finalResults = {finalDays, finalMonths, finalYears};
          req.redisClient.setex(redisKey, process.env.STATS_CACHE_TTL ? parseInt(process.env.STATS_CACHE_TTL) : 5 * 60, JSON.stringify(finalResults));
          done(null, finalResults);
        } else {
          done(null, {});
        }
      }).catch((error) => {
        done(error);
      });
    }
  });
};

/*
countModelRowsByTimePeriod(models.AcActivity, {
  type: {
    $in: [
      "activity.user.login"
    ]
  },
  domain_id: 1
},[], (results) => {
  var a = results;
});

*/

module.exports = {
  getPointDomainIncludes,
  getDomainIncludes,
  getPointCommunityIncludes,
  getCommunityIncludes,
  getPointGroupIncludes,
  getGroupIncludes,
  countModelRowsByTimePeriod
};


text:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Semmle.Extraction.CSharp.Entities;
using System.Collections.Generic;
using System.Linq;

namespace Semmle.Extraction.CSharp.Comments
{
    internal class CommentBlock
    {
        private readonly List<CommentLine> lines;

        public IEnumerable<CommentLine> CommentLines => lines;

        public Location Location { get; private set; }

        public CommentBlock(CommentLine firstLine)
        {
            lines = new List<CommentLine> { firstLine };
            Location = firstLine.Location;
        }

        /// <summary>
        ///     Determine whether commentlines should be merged.
        /// </summary>
        /// <param name="newLine">A comment line to be appended to this comment block.</param>
        /// <returns>Whether the new line should be appended to this block.</returns>
        public bool CombinesWith(CommentLine newLine)
        {
            if (!CommentLines.Any())
                return true;

            var sameFile = Location.SourceTree == newLine.Location.SourceTree;
            var sameRow = Location.EndLine() == newLine.Location.StartLine();
            var sameColumn = Location.EndLine() + 1 == newLine.Location.StartLine();
            var nextRow = Location.StartColumn() == newLine.Location.StartColumn();
            var adjacent = sameFile && (sameRow || (sameColumn && nextRow));

            return
                newLine.Type == CommentLineType.MultilineContinuation ||
                adjacent;
        }

        /// <summary>
        /// Adds a comment line to the this comment block.
        /// </summary>
        /// <param name="line">The line to add.</param>
        public void AddCommentLine(CommentLine line)
        {
            Location = !lines.Any()
                ? line.Location
                : Location.Create(
                    line.Location.SourceTree!,
                    new TextSpan(Location.SourceSpan.Start, line.Location.SourceSpan.End - Location.SourceSpan.Start));

            lines.Add(line);
        }
    }
}


text:
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.flowable.cmmn.engine.impl.persistence.entity;

import java.util.List;

import org.flowable.cmmn.api.history.HistoricCaseInstance;
import org.flowable.cmmn.api.history.HistoricMilestoneInstance;
import org.flowable.cmmn.api.repository.CaseDefinition;
import org.flowable.cmmn.api.repository.CaseDefinitionQuery;
import org.flowable.cmmn.api.runtime.CaseInstance;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.impl.history.CmmnHistoryHelper;
import org.flowable.cmmn.engine.impl.history.HistoricCaseInstanceQueryImpl;
import org.flowable.cmmn.engine.impl.history.HistoricMilestoneInstanceQueryImpl;
import org.flowable.cmmn.engine.impl.persistence.entity.data.CaseDefinitionDataManager;
import org.flowable.cmmn.engine.impl.repository.CaseDefinitionQueryImpl;
import org.flowable.cmmn.engine.impl.runtime.CaseInstanceQueryImpl;
import org.flowable.cmmn.engine.impl.task.TaskHelper;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.context.Context;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.persistence.entity.AbstractEngineEntityManager;
import org.flowable.identitylink.service.impl.persistence.entity.HistoricIdentityLinkEntityManager;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.HistoricTaskInstanceQueryImpl;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntityManager;

/**
 * @author Joram Barrez
 */
public class CaseDefinitionEntityManagerImpl
    extends AbstractEngineEntityManager<CmmnEngineConfiguration, CaseDefinitionEntity, CaseDefinitionDataManager>
    implements CaseDefinitionEntityManager {

    public CaseDefinitionEntityManagerImpl(CmmnEngineConfiguration cmmnEngineConfiguration, CaseDefinitionDataManager caseDefinitionDataManager) {
        super(cmmnEngineConfiguration, caseDefinitionDataManager);
    }

    @Override
    public CaseDefinitionEntity findLatestCaseDefinitionByKey(String caseDefinitionKey) {
        return dataManager.findLatestCaseDefinitionByKey(caseDefinitionKey);
    }

    @Override
    public CaseDefinitionEntity findLatestCaseDefinitionByKeyAndTenantId(String caseDefinitionKey, String tenantId) {
        return dataManager.findLatestCaseDefinitionByKeyAndTenantId(caseDefinitionKey, tenantId);
    }

    @Override
    public CaseDefinitionEntity findCaseDefinitionByDeploymentAndKey(String deploymentId, String caseDefinitionKey) {
        return dataManager.findCaseDefinitionByDeploymentAndKey(deploymentId, caseDefinitionKey);
    }

    @Override
    public CaseDefinitionEntity findCaseDefinitionByDeploymentAndKeyAndTenantId(String deploymentId, String caseDefinitionKey, String tenantId) {
        return dataManager.findCaseDefinitionByDeploymentAndKeyAndTenantId(deploymentId, caseDefinitionKey, tenantId);
    }

    @Override
    public CaseDefinitionEntity findCaseDefinitionByParentDeploymentAndKey(String parentDeploymentId, String caseDefinitionKey) {
        return dataManager.findCaseDefinitionByParentDeploymentAndKey(parentDeploymentId, caseDefinitionKey);
    }

    @Override
    public CaseDefinitionEntity findCaseDefinitionByParentDeploymentAndKeyAndTenantId(String parentDeploymentId, String caseDefinitionKey, String tenantId) {
        return dataManager.findCaseDefinitionByParentDeploymentAndKeyAndTenantId(parentDeploymentId, caseDefinitionKey, tenantId);
    }

    @Override
    public CaseDefinition findCaseDefinitionByKeyAndVersionAndTenantId(String caseDefinitionKey, Integer caseDefinitionVersion, String tenantId) {
        if (tenantId == null || CmmnEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            return dataManager.findCaseDefinitionByKeyAndVersion(caseDefinitionKey, caseDefinitionVersion);
        } else {
            return dataManager.findCaseDefinitionByKeyAndVersionAndTenantId(caseDefinitionKey, caseDefinitionVersion, tenantId);
        }
    }

    @Override
    public void deleteCaseDefinitionAndRelatedData(String caseDefinitionId, boolean cascadeHistory) {

        // Case instances
        CaseInstanceEntityManager caseInstanceEntityManager = getCaseInstanceEntityManager();
        CommandContext commandContext = Context.getCommandContext();
        List<CaseInstance> caseInstances = caseInstanceEntityManager.findByCriteria(
                new CaseInstanceQueryImpl(commandContext, engineConfiguration).caseDefinitionId(caseDefinitionId));
        for (CaseInstance caseInstance : caseInstances) {
            caseInstanceEntityManager.delete(caseInstance.getId(), true, null);
        }

        if (cascadeHistory) {
            engineConfiguration.getTaskServiceConfiguration().getHistoricTaskService().deleteHistoricTaskLogEntriesForScopeDefinition(ScopeTypes.CMMN, caseDefinitionId);

            HistoricIdentityLinkEntityManager historicIdentityLinkEntityManager = getHistoricIdentityLinkEntityManager();
            historicIdentityLinkEntityManager.deleteHistoricIdentityLinksByScopeDefinitionIdAndScopeType(caseDefinitionId, ScopeTypes.CMMN);

            // Historic milestone
            HistoricMilestoneInstanceEntityManager historicMilestoneInstanceEntityManager = getHistoricMilestoneInstanceEntityManager();
            List<HistoricMilestoneInstance> historicMilestoneInstances = historicMilestoneInstanceEntityManager
                    .findHistoricMilestoneInstancesByQueryCriteria(new HistoricMilestoneInstanceQueryImpl().milestoneInstanceCaseDefinitionId(caseDefinitionId));
            for (HistoricMilestoneInstance historicMilestoneInstance : historicMilestoneInstances) {
                historicMilestoneInstanceEntityManager.delete(historicMilestoneInstance.getId());
            }

            // Historic tasks
            HistoricTaskInstanceEntityManager historicTaskInstanceEntityManager = getHistoricTaskInstanceEntityManager();
            List<HistoricTaskInstance> historicTaskInstances = historicTaskInstanceEntityManager
                    .findHistoricTaskInstancesByQueryCriteria(new HistoricTaskInstanceQueryImpl().scopeDefinitionId(caseDefinitionId).scopeType(ScopeTypes.CMMN));
            for (HistoricTaskInstance historicTaskInstance : historicTaskInstances) {
                TaskHelper.deleteHistoricTask(historicTaskInstance.getId(), engineConfiguration);
            }

            // Historic Plan Items
            HistoricPlanItemInstanceEntityManager historicPlanItemInstanceEntityManager = getHistoricPlanItemInstanceEntityManager();
            historicPlanItemInstanceEntityManager.findByCaseDefinitionId(caseDefinitionId)
                    .forEach(p -> historicPlanItemInstanceEntityManager.delete(p.getId()));

            HistoricCaseInstanceEntityManager historicCaseInstanceEntityManager = getHistoricCaseInstanceEntityManager();
            List<HistoricCaseInstance> historicCaseInstanceEntities = historicCaseInstanceEntityManager
                    .findByCriteria(new HistoricCaseInstanceQueryImpl().caseDefinitionId(caseDefinitionId));
            for (HistoricCaseInstance historicCaseInstanceEntity : historicCaseInstanceEntities) {
                CmmnHistoryHelper.deleteHistoricCaseInstance(engineConfiguration, historicCaseInstanceEntity.getId());
            }
        }

        CaseDefinitionEntity caseDefinitionEntity = findById(caseDefinitionId);
        delete(caseDefinitionEntity);
    }

    @Override
    public CaseDefinitionQuery createCaseDefinitionQuery() {
        return new CaseDefinitionQueryImpl(engineConfiguration.getCommandExecutor());
    }

    @Override
    public List<CaseDefinition> findCaseDefinitionsByQueryCriteria(CaseDefinitionQuery caseDefinitionQuery) {
        return dataManager.findCaseDefinitionsByQueryCriteria((CaseDefinitionQueryImpl) caseDefinitionQuery);
    }

    @Override
    public long findCaseDefinitionCountByQueryCriteria(CaseDefinitionQuery caseDefinitionQuery) {
        return dataManager.findCaseDefinitionCountByQueryCriteria((CaseDefinitionQueryImpl) caseDefinitionQuery);
    }

    protected CaseInstanceEntityManager getCaseInstanceEntityManager() {
        return engineConfiguration.getCaseInstanceEntityManager();
    }

    protected HistoricIdentityLinkEntityManager getHistoricIdentityLinkEntityManager() {
        return engineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkEntityManager();
    }

    protected HistoricMilestoneInstanceEntityManager getHistoricMilestoneInstanceEntityManager() {
        return engineConfiguration.getHistoricMilestoneInstanceEntityManager();
    }

    protected HistoricTaskInstanceEntityManager getHistoricTaskInstanceEntityManager() {
        return engineConfiguration.getTaskServiceConfiguration().getHistoricTaskInstanceEntityManager();
    }

    protected HistoricPlanItemInstanceEntityManager getHistoricPlanItemInstanceEntityManager() {
        return engineConfiguration.getHistoricPlanItemInstanceEntityManager();
    }

    protected HistoricCaseInstanceEntityManager getHistoricCaseInstanceEntityManager() {
        return engineConfiguration.getHistoricCaseInstanceEntityManager();
    }

}


text:
require_relative '../../test_helper'

describe Fog::Vsphere::Compute::Real do
  include Fog::Vsphere::TestHelper

  before { Fog.unmock! }
  after { Fog.mock! }

  let(:compute) { prepare_compute }

  describe '#get_virtual_machine' do
    it 'gets virtual machine by uuid' do
      with_webmock_cassette('get_virtual_machine') do
        vm = compute.get_virtual_machine('52d810bd-077b-368d-a86f-0b2ad84269f8', 'BRQ')
        assert_equal(vm['name'], 'DC1')
      end
    end
  end
end


text:
#ifndef __EXPORT_H__
#define __EXPORT_H__

#include "sys.h"
#include "index.h"
#include "code_ix.h"

/*
** Export entry
*/

typedef struct export
{
    void* addressv[ERTS_NUM_CODE_IX];  /* Pointer to code for function. */

    BeamInstr fake_op_func_info_for_hipe[2]; /* MUST be just before code[] */
    /*
     * code[0]: Tagged atom for module.
     * code[1]: Tagged atom for function.
     * code[2]: Arity (untagged integer).
     * code[3]: This entry is 0 unless the 'address' field points to it.
     *          Threaded code instruction to load function
     *		(em_call_error_handler), execute BIF (em_apply_bif),
     *		or a breakpoint instruction (op_i_generic_breakpoint).
     * code[4]: Function pointer to BIF function (for BIFs only),
     *		or pointer to threaded code if the module has an
     *		on_load function that has not been run yet, or pointer
     *          to code for function code[3] is a breakpont instruction.
     *		Otherwise: 0.
     */
    BeamInstr code[5];
} Export;

void init_export_table(void);
void export_info(int, void *);

ERTS_GLB_INLINE Export* erts_active_export_entry(Eterm m, Eterm f, unsigned a);
Export* erts_export_put(Eterm mod, Eterm func, unsigned int arity);

Export* erts_export_get_or_make_stub(Eterm, Eterm, unsigned);

Export *export_list(int,ErtsCodeIndex);
int export_list_size(ErtsCodeIndex);
int export_table_sz(void);
int export_entries_sz(void);
Export *export_get(Export*);
void export_start_staging(void);
void export_end_staging(int commit);

extern erts_smp_mtx_t export_staging_lock;
#define export_staging_lock()	erts_smp_mtx_lock(&export_staging_lock)
#define export_staging_unlock()	erts_smp_mtx_unlock(&export_staging_lock)

#include "beam_load.h" /* For em_* extern declarations */
#define ExportIsBuiltIn(EntryPtr) 			\
(((EntryPtr)->addressv[erts_active_code_ix()] == (EntryPtr)->code + 3) && \
 ((EntryPtr)->code[3] == (BeamInstr) em_apply_bif))

#if ERTS_GLB_INLINE_INCL_FUNC_DEF

ERTS_GLB_INLINE Export*
erts_active_export_entry(Eterm m, Eterm f, unsigned int a)
{
    extern Export* erts_find_export_entry(Eterm m, Eterm f, unsigned a, ErtsCodeIndex);
    return erts_find_export_entry(m, f, a, erts_active_code_ix());
}

#endif /* ERTS_GLB_INLINE_INCL_FUNC_DEF */

#endif /* __EXPORT_H__ */


text:
/**
 * This file contains all type definitions that are purely for documentation purposes.
 */

/**
 * Options used when loading a path.
 *
 * @typedef {object} LoadOptions
 *
 * @property {string} [encoding='utf-8'] - The encoding to use when loading the file *(File loader only)*
 * @property {string} [method=get] - The HTTP method to use for the request *(HTTP loader only)*
 * @property {module:path-loader.PrepareRequestCallback} [prepareRequest] - The callback used to prepare the request *(HTTP loader only)*
 * @property {module:path-loader.ProcessResponseCallback} [processContent] - The callback used to process the response
 *
 * @memberof module:path-loader
 */

/**
 * Callback used to provide access to altering a remote request prior to the request being made.
 *
 * @callback PrepareRequestCallback
 *
 * @param {object} req - The Superagent request object
 * @param {string} location - The location being retrieved
 * @param {function} callback - First callback
 *
 * @memberof module:path-loader
 */

 /**
  * Callback used to provide access to processing the raw response of the request being made. *(HTTP loader only)*
  *
  * @callback ProcessResponseCallback
  *
  * @param {object} res - The Superagent response object *(For non-HTTP loaders, this object will be like the Superagent
  * object in that it will have a `text` property whose value is the raw string value being processed.  This was done
  * for consistency.  There will also be a `location` property containing the location of the path being loaded.)*
  * @param {function} callback - Error-first callback
  *
  * @returns {*} the result of processing the responses
 *
 * @memberof module:path-loader
  */


text:
from swgpy.object import *

def create(kernel):
	result = Building()

	result.template = "object/building/faction_perk/hq/shared_hq_s02_imp_pvp.iff"
	result.attribute_template_id = -1
	result.stfName("faction_perk_n","hq_s02_imp_pvp")

	#### BEGIN MODIFICATIONS ####
	####  END MODIFICATIONS  ####

	return result


text:
//  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
//
//   Copyright 2016-2018 Pascal ECHEMANN.
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

import {EjpStaticResourcesConfigImpl} from "../../../src/com/onsoft/glasscat/context/ejp/EjpStaticResourcesConfigImpl";
import { EjpStaticResourcesConfig } from "jec-glasscat-config";

/*!
 * This module constains utilities used by the BasicStaticResourcesTest test
 * suite.
 */

// Utilities:
export const buildConfig:Function = function():EjpStaticResourcesConfig {
  const config:EjpStaticResourcesConfig = new EjpStaticResourcesConfigImpl();
  config.urlPattern = CONFIG_URL_PATTERN;
  return config;
};
export const CONFIG_URL_PATTERN:string = "url/pattern";


text:
#ifndef _ICONV_H_INCLUDED
#define _ICONV_H_INCLUDED

#include <sys/anvil_internal.h>

#define __need_size_t
#include <stddef.h>

typedef void *iconv_t;

__BEGIN_DECLS

size_t  iconv(iconv_t, char **_Restrict, size_t *_Restrict,
            char **_Restrict, size_t *_Restrict);
int     iconv_close(iconv_t);
iconv_t iconv_open(const char *, const char *);

__END_DECLS

#endif /* _ICONV_H_INCLUDED */


text:
namespace IPFilter.Models
{
    public enum CompressionFormat
    {
        None = 0,
        GZip = 1,
        Zip = 2
    }
}


text:
package tree

// EvaluatorVisitor will generate an unambigious representation of an expression
type EvaluatorVisitor struct {
	booleanResults []bool
	numericResults []uint64
}

func (sv *EvaluatorVisitor) popNumeric() uint64 {
	last := sv.numericResults[0]
	sv.numericResults = sv.numericResults[1:]
	return last
}

func (sv *EvaluatorVisitor) pushNumeric(v uint64) {
	sv.numericResults = append([]uint64{v}, sv.numericResults...)
}

func (sv *EvaluatorVisitor) popBoolean() bool {
	last := sv.booleanResults[0]
	sv.booleanResults = sv.booleanResults[1:]
	return last
}

func (sv *EvaluatorVisitor) pushBoolean(v bool) {
	sv.booleanResults = append([]bool{v}, sv.booleanResults...)
}

// AcceptAnd implements Visitor
func (sv *EvaluatorVisitor) AcceptAnd(v And) {
	v.Left.Accept(sv)
	leftVal := sv.popBoolean()
	if leftVal {
		v.Right.Accept(sv)
	} else {
		sv.pushBoolean(false)
	}
}

// AcceptArgument implements Visitor
func (sv *EvaluatorVisitor) AcceptArgument(v Argument) {}

// AcceptArithmetic implements Visitor
func (sv *EvaluatorVisitor) AcceptArithmetic(v Arithmetic) {
	v.Left.Accept(sv)
	v.Right.Accept(sv)

	right := sv.popNumeric()
	left := sv.popNumeric()

	switch v.Op {
	case PLUS:
		sv.pushNumeric(left + right)
	case MINUS:
		sv.pushNumeric(left - right)
	case MULT:
		sv.pushNumeric(left * right)
	case DIV:
		sv.pushNumeric(left / right)
	}
}

// AcceptBinaryNegation implements Visitor
func (sv *EvaluatorVisitor) AcceptBinaryNegation(v BinaryNegation) {
	v.Operand.Accept(sv)
	sv.pushNumeric(^sv.popNumeric())
}

// AcceptBooleanLiteral implements Visitor
func (sv *EvaluatorVisitor) AcceptBooleanLiteral(v BooleanLiteral) {
	sv.pushBoolean(v.Value)
}

// AcceptCall implements Visitor
func (sv *EvaluatorVisitor) AcceptCall(v Call) {}

// AcceptComparison implements Visitor
func (sv *EvaluatorVisitor) AcceptComparison(v Comparison) {
	v.Left.Accept(sv)
	v.Right.Accept(sv)

	right := sv.popNumeric()
	left := sv.popNumeric()

	switch v.Op {
	case EQL:
		sv.pushBoolean(left == right)
	case NEQL:
		sv.pushBoolean(left != right)
	case GT:
		sv.pushBoolean(left > right)
	case GTE:
		sv.pushBoolean(left >= right)
	case LT:
		sv.pushBoolean(left < right)
	case LTE:
		sv.pushBoolean(left <= right)
	}
}

// AcceptInclusion implements Visitor
func (sv *EvaluatorVisitor) AcceptInclusion(v Inclusion) {}

// AcceptNegation implements Visitor
func (sv *EvaluatorVisitor) AcceptNegation(v Negation) {
	v.Operand.Accept(sv)
	sv.pushBoolean(!sv.popBoolean())
}

// AcceptNumericLiteral implements Visitor
func (sv *EvaluatorVisitor) AcceptNumericLiteral(v NumericLiteral) {
	sv.pushNumeric(v.Value)
}

// AcceptOr implements Visitor
func (sv *EvaluatorVisitor) AcceptOr(v Or) {
	v.Left.Accept(sv)
	leftVal := sv.popBoolean()
	if !leftVal {
		v.Right.Accept(sv)
	} else {
		sv.pushBoolean(true)
	}
}

// AcceptVariable implements Visitor
func (sv *EvaluatorVisitor) AcceptVariable(v Variable) {}


text:
package io.quarkus.arc.processor;

import java.util.Collection;

import org.jboss.jandex.AnnotationTarget;

/**
 * Represents an additional way of defining priorities for alternative beans.
 */
public interface AlternativePriorities {

    /**
     *
     * @param target The bean class, producer method or field
     * @param stereotypes The collection of stereotypes
     * @return a computed priority value or {@code null}
     */
    Integer compute(AnnotationTarget target, Collection<StereotypeInfo> stereotypes);

}


text:
module Chargeover
  class TokenizedCard < Resource

    self.prefix = '/tokenized'

    attr_accessor :tokenized_id,
                  :type,
                  :token,
                  :customer_id

    def self.find_all_by_customer_id(customer_id)
      filter = "?where=customer_id:EQUALS:#{customer_id}"

      response = get(base_url + filter)
      cards = []
      response.each do |card|
        cards << new(card)
      end
      cards
    end

  end
end


text:
"use strict";

var when = require("when");
var _ = require("lodash");
var validator = require("validator");
var helpers = require("../helpers");

var StringValidators = {

    is: function is() {
        return function (value) {
            return when.promise(function (resolve, reject) {
                if (helpers.isEmpty(value) || _.isString(value)) {
                    resolve(value);
                } else {
                    reject({
                        code: "string.is",
                        message: "This value should be a string."
                    });
                }
            });
        };
    },

    min: function min(limit) {

        helpers.assert(_.isNumber(limit) && limit >= 0, "limit must be a positive integer");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || _.isString(valueResolved) && valueResolved.length >= limit) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.min",
                            message: "This value should have greater than or equal " + limit + " characters."
                        });
                    }
                });
            });
        }).bind(this);
    },

    max: function max(limit) {

        helpers.assert(_.isNumber(limit) && limit >= 0, "limit must be a positive integer");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || _.isString(valueResolved) && valueResolved.length <= limit) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.max",
                            message: "This value should have less than or equal " + limit + " characters."
                        });
                    }
                });
            });
        }).bind(this);
    },

    length: function length(limit) {

        helpers.assert(_.isNumber(limit) && limit >= 0, "limit must be a positive integer");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || _.isString(valueResolved) && valueResolved.length === limit) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.length",
                            message: "This value should have exactly " + limit + " characters."
                        });
                    }
                });
            });
        }).bind(this);
    },

    rangeLength: function rangeLength(limitMin, limitMax) {

        helpers.assert(_.isNumber(limitMin) && limitMin >= 0, "limit min must be a positive integer");
        helpers.assert(_.isNumber(limitMax) && limitMax >= 0, "limit max must be a positive integer");
        helpers.assert(limitMin <= limitMax, "limit min must be less than or equals to limit max");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || _.isString(valueResolved) && valueResolved.length >= limitMin && valueResolved.length <= limitMax) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.rangeLength",
                            message: "This value should have between " + limitMin + " and " + limitMax + " characters."
                        });
                    }
                });
            });
        }).bind(this);
    },

    alphanumeric: function alphanumeric() {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isAlphanumeric(valueResolved)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.alphanumeric",
                            message: "This value is not an alphanumeric."
                        });
                    }
                });
            });
        }).bind(this);
    },

    ip: function ip(version) {

        helpers.assert(version === 4 || version === 6, "version 4 or 6 allowed");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isIP(valueResolved, version)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.ip",
                            message: "This value is not a valid IP"
                        });
                    }
                });
            });
        }).bind(this);
    },

    url: function url() {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isURL(valueResolved)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.url",
                            message: "This value is not a valid URL."
                        });
                    }
                });
            });
        }).bind(this);
    },

    equals: function equals(comparison) {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.equals(valueResolved, comparison)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.equals",
                            message: "This value should be equal to " + comparison + "."
                        });
                    }
                });
            });
        }).bind(this);
    },

    contains: function contains(seed) {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.contains(valueResolved, seed)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.contains",
                            message: "This value should not contains " + seed + "."
                        });
                    }
                });
            });
        }).bind(this);
    },

    "in": function _in(values) {

        helpers.assert(_.isArray(values), "the parameter is not an array");

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isIn(valueResolved, values)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.in",
                            message: "This value is not allowed."
                        });
                    }
                });
            });
        }).bind(this);
    },

    creditcard: function creditcard() {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isCreditCard(valueResolved)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.creditcard",
                            message: "This value is not a valid credit card."
                        });
                    }
                });
            });
        }).bind(this);
    },

    email: function email() {

        return (function (value) {
            return this.is()(value).then(function (valueResolved) {
                return when.promise(function (resolve, reject) {
                    if (helpers.isEmpty(valueResolved) || validator.isEmail(valueResolved)) {
                        resolve(valueResolved);
                    } else {
                        reject({
                            code: "string.email",
                            message: "This value is not a valid email address."
                        });
                    }
                });
            });
        }).bind(this);
    }
};

module.exports = StringValidators;


text:
/**
 *
 */
package com.linkedin.bowser.core.functions;

import java.util.List;
import java.util.Map;

import com.linkedin.bowser.core.objects.Collection;
import com.linkedin.bowser.core.objects.NQLObject;
import com.linkedin.bowser.core.objects.TupleObject;

/**
 * @author sdawson
 *
 */
public class Tuple extends AbstractNQLFunction implements NQLFunction
{
  /*
   * (non-Javadoc)
   *
   * @see com.linkedin.nql.core.functions.Function#getName()
   */
  @Override
  public String getName()
  {
    return "tuple";
  }

  /*
   * (non-Javadoc)
   *
   * @see com.linkedin.nql.core.functions.Function#apply(java.util.List)
   */
  @Override
  public NQLObject apply(Map<String, NQLObject> globals, List<NQLObject> arguments)
  {
    assertNumberOfArguments(arguments, 1);
    Collection c = getAsCollection(arguments.get(0));

    NQLObject[] array = new NQLObject[c.len()];
    int i = 0;
    for (NQLObject o : c)
      array[i++] = o;

    return new TupleObject(array);
  }
}


text:
var StudentManager = {};
module.exports = StudentManager;

StudentManager.registerStudent = function(args) {
    console.log("adding student.. ");
};

StudentManager.getStudent = function(args) {
    console.log("get student... ");
};


text:
using System;
using System.Configuration;
using System.Net;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFSHelper.Helper
{
    public class TFSService
    {
        #region Private Fields

        private static string TFSConfiguredUri
        {
            get
            {
                return new AppSettingsReader().GetValue("TFSServerUri", typeof(string)).ToString();
            }
        }

        internal string TfsConfiguredCollectionName
        {
            get { return new AppSettingsReader().GetValue("TFSCollectionName", typeof(string)).ToString(); }
        }

        private WorkItemStore _store;
        private WorkItemStore _freeStore;
        private string _uri;
        private string _collectionName;
        private TfsConfigurationServer _tfsConfigurationServer;
        private TeamFoundationJobService _teamFoundationJobService;

        #endregion

        #region Public Property

        public bool IsInitiated = false;

        public TfsTeamProjectCollection TeamProjectCollectionInstance { get; private set; }
        public WorkItemStore Store
        {
            get
            {
                if (_store != null)
                    return _store;
                _store = TeamProjectCollectionInstance.GetService<WorkItemStore>();
                if (_store == null) throw new Exception("The workitem store is null!");
                return _store;
            }
        }
        /// <summary>
        /// for bypassing all the tfs rules, be careful when using this kind of WorkItemStore!
        /// </summary>
        public WorkItemStore FreeStore
        {
            get
            {
                if (_freeStore != null)
                    return _freeStore;
                _freeStore = new WorkItemStore(TeamProjectCollectionInstance, WorkItemStoreFlags.BypassRules);

                return _freeStore;
            }
        }

        public TfsConfigurationServer ConfigurationServer
        {
            get
            {
                if (_tfsConfigurationServer == null)
                    GetTFSConfigurationServer();
                return _tfsConfigurationServer;

            }
        }
        public TeamFoundationJobService TeamFoundationJobService
        {
            get
            {
                if (_teamFoundationJobService == null)
                    GetTFSJobService();
                return _teamFoundationJobService;

            }
        }

        /// <summary>
        /// The default name for the TFS Team Project Collection, if you haven't set this whithin your app config (as a key value pair, 'TFSCollectionName' in appsettings) you should set it implicitly.
        /// </summary>
        ///
        public string DefaultCollectionName
        {
            get { return string.IsNullOrEmpty(_collectionName) ? TfsConfiguredCollectionName : _collectionName; }
            set { _collectionName = value; }
        }
        /// <summary>
        /// The default Uri for TFS Server, if you haven't set this whithin your app config (as a key value pair, 'TFSServerUri' in appsettings) you should set it implicitly.
        /// </summary>
        public string TFSServerUri
        {
            get { return string.IsNullOrEmpty(_uri) ? TFSConfiguredUri : _uri; }
            set { _uri = value; }
        }
        public Uri TFSCollectionUri
        {
            get
            {
                var serverUri = TFSServerUri.EndsWith("/") ? TFSServerUri : TFSServerUri + "/";
                return new Uri(serverUri + DefaultCollectionName);
            }
        }
        /// <summary>
        /// if been set, credential will use to initiating tfs service with if not the service gonna initiate with default user.
        /// </summary>
        public ICredentials Credential { get; set; }
        /// <summary>
        /// if been set, TFS Service is impersonated using this User Domain Name thus every action through this service gonna happen by the of this user.
        /// </summary>
        public string ImpersonateeDomainName { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Default Constructor.
        /// </summary>
        public TFSService()
        {

        }

        /// <summary>
        /// Initilizing TFS Service via 'Team Foundation Request Conxtext' whcich usually is passing through tfs plugins.
        /// </summary>
        /// <param name="requestContext">Team Foundation Request Conxtext</param>
        public TFSService(TeamFoundationRequestContext requestContext)
        {
            //Extracting TFS Uri from it's request context
            var locationService = requestContext.GetService<TeamFoundationLocationService>();
            _uri = locationService.GetServerAccessMapping(requestContext).AccessPoint;
            _collectionName = requestContext.ServiceHost.Name;
        }

        /// <summary>
        /// If you Initilized the service before and you have the projectcollection you can use this constructor.
        /// </summary>
        /// <param name="projectCollection">Team Foundation Project Collection</param>
        public TFSService(TfsTeamProjectCollection projectCollection)
        {
            TeamProjectCollectionInstance = projectCollection;
        }

        /// <summary>
        /// Initilizing TFS Service.
        /// </summary>
        public void Init()
        {
            EmployTFSServices(ImpersonateeDomainName, Credential);
            IsInitiated = true;
        }

        #endregion

        #region Private Methods

        private void EmployTFSServices(string impersonateeDomainName, ICredentials credential)
        {
            if (string.IsNullOrEmpty(DefaultCollectionName))
                throw new Exception("There is no Collection Name was set for initiating tfs service.");
            if (string.IsNullOrEmpty(TFSServerUri))
                throw new Exception("There is no Server URI was set for initiating tfs service.");

            TeamProjectCollectionInstance = string.IsNullOrEmpty(impersonateeDomainName)
                ? GetTFSCollection(credential)
                : GetImpersonatedCollection(impersonateeDomainName, credential);

            TeamProjectCollectionInstance.Authenticate();

        }
        private TfsTeamProjectCollection GetImpersonatedCollection(string impersonateeDomainName,
            ICredentials credential)
        {
            var currentCollection = GetTFSCollection(credential);

            var identityService = new IdentityService(currentCollection);
            var identity = identityService.GetTFSIdentity(impersonateeDomainName, IdentitySearchFactor.AccountName);

            return credential != null
                ? new TfsTeamProjectCollection(TFSCollectionUri,
                    new TfsClientCredentials(new WindowsCredential(credential)), identity.Descriptor)
                : new TfsTeamProjectCollection(TFSCollectionUri, identity.Descriptor);
        }
        private TfsTeamProjectCollection GetTFSCollection(ICredentials credential)
        {
            return credential != null
                ? new TfsTeamProjectCollection(TFSCollectionUri, credential)
                : new TfsTeamProjectCollection(TFSCollectionUri);
        }

        private void GetTFSConfigurationServer()
        {
            _tfsConfigurationServer = new TfsConfigurationServer(new Uri(TFSServerUri), Credential);
        }
        private void GetTFSJobService()
        {
            _teamFoundationJobService = ConfigurationServer.GetService<TeamFoundationJobService>();
        }
        #endregion

    }
}


text:
<!DOCTYPE html >

          <title></title>
          <meta name="description" content="" />
          <meta name="keywords" content="" />
          <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

      <link href="../lib/ref-index.css" media="screen" type="text/css" rel="stylesheet" />

hasNext

BufferedReaderIterator


text:
sbatch tsp19_name=dog-bark_sc=none_J=12_wav=gammatone.sbatch
sbatch tsp19_name=dog-bark_sc=none_J=12_wav=morlet.sbatch
sbatch tsp19_name=dog-bark_sc=time_J=12_wav=gammatone.sbatch
sbatch tsp19_name=dog-bark_sc=time_J=12_wav=morlet.sbatch
sbatch tsp19_name=dog-bark_sc=time-frequency_J=12_wav=gammatone.sbatch
sbatch tsp19_name=dog-bark_sc=time-frequency_J=12_wav=morlet.sbatch


text:
package br.udesc.loman.filters;

import java.io.IOException;
import javax.servlet.*;

public class CharacterEncodingFilter implements Filter {

	    @Override
	    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
	        req.setCharacterEncoding("UTF-8");
	        resp.setCharacterEncoding("UTF-8");
	        chain.doFilter(req, resp);
	    }

	    @Override
	    public void init(FilterConfig filterConfig) throws ServletException {
	    }

	    @Override
	    public void destroy() {
	    }
}


text:
package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

public class GroupModificationTests extends TestBase{
	@Test(dataProvider = "randomValidGroupGenerator")
	public void modifysomeGroup(GroupData group){
		// save old state
		SortedListOf<GroupData> oldList = app.getGroupHelper().getGroups();

		Random rnd = new Random();
		int index = rnd.nextInt(oldList.size()-1);

		//actions
		app.getGroupHelper().modifyGroup(index,group);

	    //save new state
		SortedListOf<GroupData> newList = app.getGroupHelper().getGroups();

	    //compare states
		assertThat(newList, equalTo(oldList.without(index).withAdded(group)));
	}

}