text:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
        <filter-name>switter</filter-name>
        <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>ru.qatools.school.switter.Server</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
            <param-value>/public/(bootstrap|jquery|app)/(js|css|img)/.*</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>switter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


text: .\GopherInvaders.exe -server -num-players 1

redpajama_set_name: RedPajamaGithub


text:
<?php

namespace Application\Controller\MembersArea;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;

class VotesController
{
    public function indexAction(Request $request, Application $app)
    {
        $data = [];

        if (
            !$app['security.authorization_checker']->isGranted('ROLE_VOTES_EDITOR') &&
            !$app['security.authorization_checker']->isGranted('ROLE_ADMIN')
        ) {
            $app->abort(403);
        }

        $limitPerPage = $request->query->get('limit_per_page', 10);
        $currentPage = $request->query->get('page');

        $voteResults = $app['orm.em']
            ->createQueryBuilder()
            ->select('v')
            ->from('Application\Entity\VoteEntity', 'v')
            ->leftJoin('v.voteMetas', 'vm')
            ->leftJoin('v.entry', 'e')
        ;

        $pagination = $app['paginator']->paginate(
            $voteResults,
            $currentPage,
            $limitPerPage,
            [
                'route' => 'members-area.votes',
                'defaultSortFieldName' => 'v.timeCreated',
                'defaultSortDirection' => 'desc',
                'searchFields' => [
                    'v.ip',
                    'v.userAgent',
                    'vm.value',
                ],
            ]
        );

        $data['pagination'] = $pagination;

        return new Response(
            $app['twig']->render(
                'contents/members-area/votes/index.html.twig',
                $data
            )
        );
    }

    public function exportAction(Request $request, Application $app)
    {
        $exportOptions = $app['exportOptions']['votes'];
        $exportOptionsKeys = array_keys($exportOptions['fields']);
        $exportOptionsValues = array_values($exportOptions['fields']);

        $response = new StreamedResponse();
        $response->setCallback(function () use ($app, $exportOptionsKeys, $exportOptionsValues) {
            $handle = fopen('php://output', 'w+');

            fputcsv(
                $handle,
                $exportOptionsKeys,
                ';'
            );

            $votes = $app['orm.em']
                ->getRepository('Application\Entity\VoteEntity')
                ->findAll()
            ;

            $twig = clone $app['twig'];
            $twig->setLoader(new \Twig_Loader_String());

            foreach ($votes as $vote) {
                $finalExportOptionsValues = [];

                foreach ($exportOptionsValues as $singleValue) {
                    $finalExportOptionsValues[] = $twig->render(
                        $singleValue,
                        [
                            'vote' => $vote,
                        ]
                    );
                }

                fputcsv(
                    $handle,
                    $finalExportOptionsValues,
                    ';'
                 );
            }

            fclose($handle);
        });

        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'text/csv; charset=utf-8');
        $response->headers->set('Content-Disposition', 'attachment; filename="votes.csv"');

        return $response;
    }

    public function newAction(Request $request, Application $app)
    {
        $data = [];

        if (
            !$app['security.authorization_checker']->isGranted('ROLE_VOTES_EDITOR') &&
            !$app['security.authorization_checker']->isGranted('ROLE_ADMIN')
        ) {
            $app->abort(403);
        }

        $form = $app['form.factory']->create(
            \Application\Form\Type\VoteType::class,
            new \Application\Entity\VoteEntity()
        );

        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);

            if ($form->isValid()) {
                $voteEntity = $form->getData();
                $voteEntity
                    ->setIp($request->getClientIp())
                    ->setUserAgent($request->headers->get('User-Agent'))
                ;

                $app['orm.em']->persist($voteEntity);
                $app['orm.em']->flush();

                $app['flashbag']->add(
                    'success',
                    $app['translator']->trans(
                        'The vote has been added!'
                    )
                );

                return $app->redirect(
                    $app['url_generator']->generate(
                        'members-area.votes.edit',
                        [
                            'id' => $voteEntity->getId(),
                        ]
                    )
                );
            }
        }

        $data['form'] = $form->createView();

        return new Response(
            $app['twig']->render(
                'contents/members-area/votes/new.html.twig',
                $data
            )
        );
    }

    public function editAction($id, Request $request, Application $app)
    {
        $data = [];

        if (
            !$app['security.authorization_checker']->isGranted('ROLE_VOTES_EDITOR') &&
            !$app['security.authorization_checker']->isGranted('ROLE_ADMIN')
        ) {
            $app->abort(403);
        }

        $vote = $app['orm.em']->find('Application\Entity\VoteEntity', $id);

        if (!$vote) {
            $app->abort(404);
        }

        $form = $app['form.factory']->create(
            \Application\Form\Type\VoteType::class,
            $vote
        );

        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);

            if ($form->isValid()) {
                $voteEntity = $form->getData();

                $app['orm.em']->persist($voteEntity);
                $app['orm.em']->flush();

                $app['flashbag']->add(
                    'success',
                    $app['translator']->trans(
                        'The vote has been edited!'
                    )
                );

                return $app->redirect(
                    $app['url_generator']->generate(
                        'members-area.votes.edit',
                        [
                            'id' => $voteEntity->getId(),
                        ]
                    )
                );
            }
        }

        $data['form'] = $form->createView();
        $data['vote'] = $vote;

        return new Response(
            $app['twig']->render(
                'contents/members-area/votes/edit.html.twig',
                $data
            )
        );
    }

    public function removeAction($id, Request $request, Application $app)
    {
        $data = [];

        if (
            !$app['security.authorization_checker']->isGranted('ROLE_VOTES_EDITOR') &&
            !$app['security.authorization_checker']->isGranted('ROLE_ADMIN')
        ) {
            $app->abort(403);
        }

        $vote = $app['orm.em']->find('Application\Entity\VoteEntity', $id);

        if (!$vote) {
            $app->abort(404);
        }

        $confirmAction = $request->query->has('action') &&
            $request->query->get('action') == 'confirm'
        ;

        if ($confirmAction) {
            try {
                $app['orm.em']->remove($vote);
                $app['orm.em']->flush();

                $app['flashbag']->add(
                    'success',
                    $app['translator']->trans(
                        'The vote has been removed!'
                    )
                );
            } catch (\Exception $e) {
                $app['flashbag']->add(
                    'danger',
                    $app['translator']->trans(
                        $e->getMessage()
                    )
                );
            }

            return $app->redirect(
                $app['url_generator']->generate(
                    'members-area.votes'
                )
            );
        }

        $data['vote'] = $vote;

        return new Response(
            $app['twig']->render(
                'contents/members-area/votes/remove.html.twig',
                $data
            )
        );
    }
}


text:
package sqx

import (
	"testing"

	sq "github.com/Masterminds/squirrel"
	"github.com/stellar/go/services/horizon/internal/test"
)

func TestStringArray(t *testing.T) {
	tt := test.Start(t).ScenarioWithoutHorizon("base")
	defer tt.Finish()

	expr := StringArray([]string{"1", "2", "3"}).(sq.Sqlizer)
	sql, args, err := expr.ToSql()

	tt.Require.NoError(err)
	tt.Assert.Equal("?::character varying[]", sql)

	tt.Assert.Len(args, 1)
	tt.Assert.Equal(`{"1","2","3"}`, args[0])
}


text:
j1Render::j1Render() : j1Module()
{
	name.create("renderer");
	background.r = 0;
	background.g = 0;
	background.b = 0;
	background.a = 0;
}

// Destructor
j1Render::~j1Render()
{}

// Called before render is available
bool j1Render::Awake(pugi::xml_node& config)
{
	LOG("Create SDL rendering context");
	bool ret = true;
	// load flags
	Uint32 flags = SDL_RENDERER_ACCELERATED;

	if(config.child("vsync").attribute("value").as_bool(true) == true)
	{
		flags |= SDL_RENDERER_PRESENTVSYNC;
		LOG("Using vsync");
	}

	renderer = SDL_CreateRenderer(App->win->window, -1, flags);

	if(renderer == NULL)
	{
		LOG("Could not create the renderer! SDL_Error: %s\n", SDL_GetError());
		ret = false;
	}
	else
	{
		camera.w = App->win->screen_surface->w;
		camera.h = App->win->screen_surface->h;
		camera.x = 0;
		camera.y = 0;
	}

	return ret;
}

// Called before the first frame
bool j1Render::Start()
{
	LOG("render start");
	// back background
	SDL_RenderGetViewport(renderer, &viewport);
	return true;
}

// Called each loop iteration
bool j1Render::PreUpdate()
{
	SDL_RenderClear(renderer);
	return true;
}

bool j1Render::Update(float dt)
{
	return true;
}

bool j1Render::PostUpdate()
{
	SDL_SetRenderDrawColor(renderer, background.r, background.g, background.g, background.a);
	SDL_RenderPresent(renderer);
	return true;
}

// Called before quitting
bool j1Render::CleanUp()
{
	LOG("Destroying SDL render");
	SDL_DestroyRenderer(renderer);
	return true;
}

bool j1Render::Load(pugi::xml_node &node)
{
	bool ret = true;

	camera.x = node.child("camera").attribute("x").as_int();
	camera.y = node.child("camera").attribute("y").as_int();

	return ret;

}

bool j1Render::Save(pugi::xml_node &node)const
{
	bool ret = true;

	pugi::xml_node cam = node.append_child("camera");

	cam.append_attribute("x") = camera.x;
	cam.append_attribute("y") = camera.y;

	return ret;
}

void j1Render::SetBackgroundColor(SDL_Color color)
{
	background = color;
}

void j1Render::SetViewPort(const SDL_Rect& rect)
{
	SDL_RenderSetViewport(renderer, &rect);
}

void j1Render::ResetViewPort()
{
	SDL_RenderSetViewport(renderer, &viewport);
}

// Blit to screen
bool j1Render::Blit(SDL_Texture* texture, int x, int y, const SDL_Rect* section, uint scale, float speed, double angle, int pivot_x, int pivot_y) const
{
	bool ret = true;
	if (scale != App->win->GetScale())
	{

	}
	//uint scale = App->win->GetScale();

	SDL_Rect rect;
	rect.x = (int)(camera.x * speed) + x * scale;
	rect.y = (int)(camera.y * speed) + y * scale;

	if(section != NULL)
	{
		rect.w = section->w;
		rect.h = section->h;
	}
	else
	{
		SDL_QueryTexture(texture, NULL, NULL, &rect.w, &rect.h);
	}

	rect.w *= scale;
	rect.h *= scale;

	SDL_Point* p = NULL;
	SDL_Point pivot;

	if(pivot_x != INT_MAX && pivot_y != INT_MAX)
	{
		pivot.x = pivot_x;
		pivot.y = pivot_y;
		p = &pivot;
	}

	if(SDL_RenderCopyEx(renderer, texture, section, &rect, angle, p, SDL_FLIP_NONE) != 0)
	{
		LOG("Cannot blit to screen. SDL_RenderCopy error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}

bool j1Render::DrawQuad(const SDL_Rect& rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool filled, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	SDL_Rect rec(rect);
	if(use_camera)
	{
		rec.x = (int)(camera.x + rect.x * scale);
		rec.y = (int)(camera.y + rect.y * scale);
		rec.w *= scale;
		rec.h *= scale;
	}

	int result = (filled) ? SDL_RenderFillRect(renderer, &rec) : SDL_RenderDrawRect(renderer, &rec);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}

bool j1Render::DrawLine(int x1, int y1, int x2, int y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	int result = -1;

	if(use_camera)
		result = SDL_RenderDrawLine(renderer, camera.x + x1 * scale, camera.y + y1 * scale, camera.x + x2 * scale, camera.y + y2 * scale);
	else
		result = SDL_RenderDrawLine(renderer, x1 * scale, y1 * scale, x2 * scale, y2 * scale);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}

bool j1Render::DrawCircle(int x, int y, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	int result = -1;
	SDL_Point points[360];

	float factor = (float)M_PI / 180.0f;

	for(uint i = 0; i < 360; ++i)
	{
		points[i].x = (int)(x + radius * cos(i * factor));
		points[i].y = (int)(y + radius * sin(i * factor));
	}

	result = SDL_RenderDrawPoints(renderer, points, 360);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}


text:
'use strict';
angular.module('ExperimentApp')

.constant('QUESTIONS', {
    NL: {
        title: 'Vragenlijst over muziek- en taalachtergrond',
        subtitle: 'Na deze vragenlijst zie je hoe goed je de test hebt gedaan!',
        title_music: 'Muziek Achtergrond',
        birthdate: '1) Geboortedatum (dd-mm-jjjj)',
        sex: '2) Geslacht',
        education: '3) Hoogst afgeronde opleiding:',
        musiclessons: '4) Heeft u muzieklessen gevolgd?',
        yearsofmusiclessons: '5) Zoja, hoeveel jaren les heeft u gehad?',
        ageofmusiclessonsstart: '6) Zoja, hoe oud was u toen u deze lessen heeft gehad?',
        playmusicalinstrumentyesno: '7) Bespeelt u een muziekinstrument?',
        whichmusicalinstrument: '8) Zoja, welke?',
        followdancelessonsyesno: '9) Heeft u danslessen gevolgd?',
        yearsofdancelessons: '10) Zoja, hoeveel jaren les heeft u gehad?',
        hoursperdaymusiclistening: '11) Hoeveel uren luistert u gemiddeld per dag naar muziek?',
        favoritemusicalgenre: '12) Welke muziekgenre luistert u graag?',
        title_language: 'Taal Achtergrond',
        nativelanguage: '1) Wat is uw moedertaal?',
        otherfluentlanguage: '2) Welke andere taal spreekt u vloeind naast uw moedertaal?',
        skilllevelotherfluentlanguage: '3) Hoe goed is uw vaardigheid in deze andere taal (talen) in vergelijking met je moedertaal?',
        skilllevelotherfluentlanguageAnswers: [
            {
                value: '10',
                answer: '10: Net zo goed als mijn moedertaal',
            },
            {
                value: '9',
                answer: '9: Bijna net zo goed als mijn moedertaal',
            },
            {
                value: '8',
                answer: '8: Heel goed, maar minder goed dan mijn moedertaal',
            },
            {
                value: '7',
                answer: '7: Vrij goed',
            },
            {
                value: '6',
                answer: '6: Gemiddeld niveau',
            },
            {
                value: '5',
                answer: '5: Gemiddeld niveau',
            },
            {
                value: '4',
                answer: '4: Beginnersniveau',
            },
            {
                value: '3',
                answer: '3: Beginnersniveau',
            },
            {
                value: '2',
                answer: '2: Rudimentair',
            },
            {
                value: '1',
                answer: '1: Rudimentair'
            }
        ],
        ageotherfluentlanguage: '4)	Hoe oud was u toen u deze andere taal (talen) geleerd heeft?',
        howoftenperweekusingnativelanguage: '5)	Hoe vaak per week gebruikt u uw moedertaal?',
        howoftenperweekusingotherfluentlanguage: '6) Hoe vaak per week gebruikt u deze andere taal (talen)?',
        gotoresults: 'Ga naar de resultaten'
    },
    TR: {
        title: 'Müzik ve Dil Geçmişi Anketi',
        subtitle: 'Bu anketi tamamladıktan sonra testteki performansınızı görebilirsiniz.',
        title_music: 'Müzik geçmişi',
        birthdate: '1) Doğum tarihi (Gün-ay-yıl)',
        sex: '2) Cinsiyet',
        education: '3) Tamamlanmış en yüksek eğitim seviyesi:',
        musiclessons: '4) Daha önce müzik dersi aldınız mı?',
        yearsofmusiclessons: '5) Eğer daha önce müzik dersi aldıysanız, kaç yıl ders aldınız?',
        ageofmusiclessonsstart: '6) Eğer daha önce müzik dersi aldıysanız, bu dersi alırken kaç yaşındaydınız?',
        playmusicalinstrumentyesno: '7) Bir müzik aleti çalıyor musunuz?',
        whichmusicalinstrument: '8) Eğer bir önceki soruya yanıtınız evet ise, hangi müzik aletini çalıyorsunuz?',
        followdancelessonsyesno: '9) Daha önce dans dersi aldınız mı?',
        yearsofdancelessons: '10) Eğer daha önce dans dersi aldıysanız, kaç yıl ders aldınız?',
        hoursperdaymusiclistening: '11) Ortalama olarak bir günde kaç saat müzik dinliyorsunuz?',
        favoritemusicalgenre: '12) Hangi müzik türlerini dinlemekten hoşlanırsınız?',
        title_language: 'Dil anketi',
        nativelanguage: '1) Ana diliniz nedir?',
        otherfluentlanguage: '2) Ana diliniz dışında hangi dil(ler)i akıcı olarak konuşuyorsunuz?',
        skilllevelotherfluentlanguage: '3) Bu dil(ler)deki becerileriniz ana dilinizle kıyaslandığında nasıldır?',
        skilllevelotherfluentlanguageAnswers: [
            {
                value: '10',
                answer: '10: Ana dilim kadar iyi',
            },
            {
                value: '9',
                answer: '9: Neredeyse ana dilim kadar iyi',
            },
            {
                value: '8',
                answer: '8: Çok iyi, ancak ana dilim kadar iyi değil',
            },
            {
                value: '7',
                answer: '7: Oldukça iyi',
            },
            {
                value: '6',
                answer: '6: Ortalama',
            },
            {
                value: '5',
                answer: '5: Ortalama',
            },
            {
                value: '4',
                answer: '4: Başlangıç seviyesinde',
            },
            {
                value: '3',
                answer: '3: Başlangıç seviyesinde',
            },
            {
                value: '2',
                answer: '2: Temel seviyede',
            },
            {
                value: '1',
                answer: '1: Temel seviyede'
            }
        ],
        ageotherfluentlanguage: '4)	İkinci dilinizi öğrendiğinizde kaç yaşındaydınız?',
        howoftenperweekusingnativelanguage: '5)	Bir hafta içinde ana dilinizi ne sıklıkta kullanıyorsunuz?',
        howoftenperweekusingotherfluentlanguage: '6) İkinci dilinizi bir hafta içinde ne sıklıkta kullanıyorsunuz?',
        gotoresults: 'Sonuçlara gidin'
    },
    EN: {

    }
})


text:
from unittest import TestCase

import mock

from src.main.Parser import Parser

@mock.patch('random.randint', return_value=3)
class TestParser(TestCase):
    def test_double_dice_roll(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("2d4+3d5"), 15)
        self.assertEqual(parser.parse("2d4-3d5"), -3)
        self.assertEqual(parser.parse("2d4*3d5"), 54)
        self.assertEqual(parser.parse("4d4/2d4"), 2)

    def test_mulitply(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("2d4*4"), 24)

    def test_divide(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("2d4/6"), 1)

    def test_subtract(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("2d4-2"), 4)

    def test_addition(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("2d4+5"), 11)

    def test_constants(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("4"), 4)
        self.assertEqual(parser.parse("4+3"), 7)
        self.assertEqual(parser.parse("4-3"), 1)
        self.assertEqual(parser.parse("6/3"), 2)
        self.assertEqual(parser.parse("4*3"), 12)

    def test_dice_roll(self, mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("3d4"), 9)

    def test_negative_roll(self, mocked_roll):
        parser = Parser()
        self.assertRaises(SyntaxError,lambda:parser.parse("-3d4"))
        self.assertRaises(SyntaxError,lambda:parser.parse("3d-4"))
        self.assertRaises(SyntaxError,lambda:parser.parse("-3d4-4"))

    def test_mod(self,mocked_roll):
        parser = Parser()
        self.assertEqual(parser.parse("3d4"),9)
        self.assertEqual(parser.parse("3d4k2H"),6)
        self.assertEqual(parser.parse("3d4r4"),9)
        self.assertEqual(parser.parse("3d4r4k2H"),6)

    def test_negative_mod(self, mocked_roll):
        parser = Parser()
        self.assertRaises(SyntaxError,lambda: parser.parse("3d3k4Hr2"))
        self.assertRaises(ValueError,lambda:parser.parse("0d4k2H"))
        self.assertRaises(ValueError,lambda:parser.parse("3d0k2H"))
        self.assertRaises(ValueError, lambda: parser.parse("3d3k0L"))
        self.assertRaises(ValueError,lambda: parser.parse("3d3k4H"))
        self.assertRaises(ValueError, lambda: parser.parse("3d3r0k2L"))
        self.assertRaises(SyntaxError, lambda: parser.parse("3d3k2Lr0"))


text:
/*******************************************************************************
 * Created by Koen Deschacht (koendeschacht@gmail.com) 2017-3-11. For license
 * information see the LICENSE file in the root folder of this repository.
 ******************************************************************************/

package be.bagofwords.minidepi.testbeans;

import be.bagofwords.minidepi.annotations.Inject;

public class Dao1 extends TestBean {

    @Inject
    public DatabaseService databaseService;

}


text:
<?php
    /****************************************************************/
    /* ATutor Calendar Module                                       */
    /* https://atutorcalendar.wordpress.com/                        */
    /*                                                              */
    /* This module provides standard calendar features in ATutor.   */
    /*                                                              */
    /* Author: Anurup Raveendran, Herat Gandhi                      */
    /* This program is free software. You can redistribute it and/or*/
    /* modify it under the terms of the GNU General Public License  */
    /* as published by the Free Software Foundation.                */
    /****************************************************************/

    /**
     * This php file is used for side menu. When instructor allows students to
     * access this module as a course tool then in side menu of course's home page
     * one entry will be created.
     */
    /* start output buffering: */
    ob_start();
    global $savant;
?>

<link href="<?php echo AT_BASE_HREF; ?>mods/_standard/calendar/lib/fullcalendar/fullcalendar.css" rel="stylesheet" type="text/css" />
<link href="<?php echo AT_BASE_HREF; ?>mods/_standard/calendar/lib/fullcalendar/miniCal.css" rel="stylesheet" type="text/css" />

<?php
    $savant->assign('dropdown_contents', ob_get_contents());
    ob_end_clean();

    $savant->assign('title', _AT('calendar_header')); //The box title
    $savant->display('include/box.tmpl.php');
?>


text:
package com.serotonin.bacnet4j.type.primitive;

import java.io.UnsupportedEncodingException;

import com.serotonin.bacnet4j.exception.BACnetErrorException;
import com.serotonin.bacnet4j.exception.BACnetRuntimeException;
import com.serotonin.bacnet4j.type.enumerated.ErrorClass;
import com.serotonin.bacnet4j.type.enumerated.ErrorCode;
import org.free.bacnet4j.util.ByteQueue;

public class CharacterString extends Primitive {
    private static final long serialVersionUID = -3146333907363025078L;
    public static final byte TYPE_ID = 7;

    public interface Encodings {
        byte ANSI_X3_4 = 0;
        byte IBM_MS_DBCS = 1;
        byte JIS_C_6226 = 2;
        byte ISO_10646_UCS_4 = 3;
        byte ISO_10646_UCS_2 = 4;
        byte ISO_8859_1 = 5;
    }

    private final byte encoding;
    private final String value;

    public CharacterString(String value) {
        encoding = Encodings.ANSI_X3_4;
        this.value = value;
    }

    public CharacterString(byte encoding, String value) {
        try {
            validateEncoding();
        }
        catch (BACnetErrorException e) {
            // This is an API constructor, so it doesn't need to throw checked exceptions. Convert to runtime.
            throw new BACnetRuntimeException(e);
        }
        this.encoding = encoding;
        this.value = value;
    }

    public byte getEncoding() {
        return encoding;
    }

    public String getValue() {
        return value;
    }

    //
    // Reading and writing
    //
    public CharacterString(ByteQueue queue) throws BACnetErrorException {
        int length = (int) readTag(queue);

        encoding = queue.pop();
        validateEncoding();

        byte[] bytes = new byte[length - 1];
        queue.pop(bytes);

        value = decode(encoding, bytes);
    }

    @Override
    public void writeImpl(ByteQueue queue) {
        queue.push(encoding);
        queue.push(encode(encoding, value));
    }

    @Override
    protected long getLength() {
        return encode(encoding, value).length + 1;
    }

    @Override
    protected byte getTypeId() {
        return TYPE_ID;
    }

    private static byte[] encode(byte encoding, String value) {
        try {
            switch (encoding) {
            case Encodings.ANSI_X3_4:
                return value.getBytes("UTF-8");
            case Encodings.ISO_10646_UCS_2:
                return value.getBytes("UTF-16");
            case Encodings.ISO_8859_1:
                return value.getBytes("ISO-8859-1");
            }
        }
        catch (UnsupportedEncodingException e) {
            // Should never happen, so convert to a runtime exception.
            throw new RuntimeException(e);
        }
        return null;
    }

    private static String decode(byte encoding, byte[] bytes) {
        try {
            switch (encoding) {
            case Encodings.ANSI_X3_4:
                return new String(bytes, "UTF-8");
            case Encodings.ISO_10646_UCS_2:
                return new String(bytes, "UTF-16");
            case Encodings.ISO_8859_1:
                return new String(bytes, "ISO-8859-1");
            }
        }
        catch (UnsupportedEncodingException e) {
            // Should never happen, so convert to a runtime exception.
            throw new RuntimeException(e);
        }
        return null;
    }

    private void validateEncoding() throws BACnetErrorException {
        if (encoding != Encodings.ANSI_X3_4 && encoding != Encodings.ISO_10646_UCS_2
                && encoding != Encodings.ISO_8859_1)
            throw new BACnetErrorException(ErrorClass.property, ErrorCode.characterSetNotSupported,
                    Byte.toString(encoding));
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((value == null) ? 0 : value.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final CharacterString other = (CharacterString) obj;
        if (encoding != other.encoding)
            return false;
        if (value == null) {
            if (other.value != null)
                return false;
        }
        else if (!value.equals(other.value))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return value;
    }
}


text:
from typing import Union

import bleach
from django import template
from django.conf import settings
from django.utils.safestring import mark_safe
from markdown import markdown as render_markdown

from grandchallenge.core.utils.markdown import LinkBlankTargetExtension

register = template.Library()

@register.filter
def clean(html: str):
    """Clean the html with bleach."""
    cleaned_html = bleach.clean(
        html,
        tags=settings.BLEACH_ALLOWED_TAGS,
        attributes=settings.BLEACH_ALLOWED_ATTRIBUTES,
        styles=settings.BLEACH_ALLOWED_STYLES,
        protocols=settings.BLEACH_ALLOWED_PROTOCOLS,
        strip=settings.BLEACH_STRIP,
    )

    return mark_safe(cleaned_html)

@register.filter
def md2html(markdown: Union[str, None], link_blank_target=False):
    """Convert markdown to clean html"""

    extensions = settings.MARKDOWNX_MARKDOWN_EXTENSIONS

    if link_blank_target:
        extensions.append(LinkBlankTargetExtension())

    html = render_markdown(
        text=markdown or "",
        extensions=extensions,
        extension_configs=settings.MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS,
    )

    return clean(html)


text:
package evanq.game.cardgame.domain.service.impl;

import evanq.game.cardgame.domain.model.role.RoleId;
import evanq.game.cardgame.domain.model.role.RoleInfo;
import evanq.game.cardgame.domain.model.role.RoleRepository;
import evanq.game.cardgame.domain.service.IRoleService;

/**
 * @author Evan cppmain@gmail.com
 *
 */
public class RoleServiceImpl implements IRoleService {

	private RoleRepository roleRepository;

	@Override
	public RoleInfo findRoleInfo(RoleId roleId) {
		return null;
	}

	@Override
	public void enterWorld(RoleInfo roleInfo) {

	}

	@Override
	public void leaveWorld(RoleInfo roleInfo) {

	}

	public RoleRepository getRoleRepository() {
		return roleRepository;
	}

	public void setRoleRepository(RoleRepository roleRepository) {
		this.roleRepository = roleRepository;
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<ldswebml type="image" uri="/media-library/images/technology#girl-ipod-901803" xml:lang="eng" locale="eng" status="publish" xmlns:its="http://www.w3.org/2005/11/its">
  <search-meta>
      <uri-title its:translate="no">girl-ipod-901803</uri-title>
      <source>girl-ipod-901803</source>
      <publication-type its:translate="no">image</publication-type>
      <media-type its:translate="no">image</media-type>
      <publication value="ldsorg">LDS.org</publication>
      <publication-date value="2012-07-02">2012-07-02</publication-date>
      <title/>
      <description/>
      <collections>
          <collection its:translate="no">global-search</collection>
          <collection its:translate="no">media</collection>
          <collection its:translate="no">images</collection>
      </collections>
      <subjects>
          <subject>girls</subject>
          <subject>young women</subject>
          <subject>youth</subject>
          <subject>teenagers</subject>
          <subject>technology</subject>
          <subject>ipods</subject>
          <subject>mp3 players</subject>
          <subject>headphones</subject>
          <subject>earbuds</subject>
          <subject>music</subject>
          <subject>listening</subject>
          <subject>media</subject>
          <subject>technology</subject>
          <subject>equipment</subject>
          <subject>electronics</subject>
      </subjects>
  </search-meta>
  <no-search>
      <path>http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-gallery.jpg</path>
      <images>
          http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-thumbnail.jpg
      </images>
          <download-urls>
              <download-url>
                  Mobile
                  <size>139 KB</size>
                  <path>http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-mobile.jpg</path>
              </download-url>
              <download-url>
                  Tablet
                  <size>203 KB</size>
                  <path>http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-tablet.jpg</path>
              </download-url>
              <download-url>
                  Print
                  <size>527 KB</size>
                  <path>http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-print.jpg</path>
              </download-url>
              <download-url>
                  Wallpaper
                  <size>950 KB</size>
                  <path>http://media.ldscdn.org/images/media-library/technology/girl-ipod-901803-wallpaper.jpg</path>
              </download-url>
          </download-urls>
  </no-search>
</ldswebml>


text:
/**
 * Imports
 */

import test from 'tape'
import GridSizeSelector from '.'

/**
 * <Grid Size Selector/> tests
 */

test('<GridSizeSelector/> should work', t => {

})


text:
layout       : blocks/working-session
title        : Top 10 Selection Criteria
type         : workshop
track        : Owasp Top 10 2017
technology   :
related-to   :
status       : final stage; add content
when-day     : Mon
when-time    : PM-1
location     : Room-2
organizers   : Dave Wichers,Josh Grossman
participants : Bjoern Kimminich
---

## Why

Any issue that is part of the OWASP Top 10 should match very specific Selection/Inclusion criteria.

These criteria should be clear, easy to understand, agreed by the community, and measurable. When applied to the
Top 10, the selection of these specific categories should be self-explanatory.

> In the Big 4 context, this is relevant for "Auditor Independence" where a Financial Auditor firm and its staff must demonstrate that they are able to perform a completely unbiased review of a company's financial reporting without being exposed to external pressures which prevent it from being impartial such as a financial interest or inducement.
>
>  We were told that a Financial Auditor must both "be independent" and "be seen to be independent". This second definition effectively means that even something that just looks like it would threaten independence, even if it does not, should be considered as a risk and avoided as carefully as an actual independence risk.
(from [Behind the The OWASP Top 10 2017 RC1](https://medium.com/@JoshCGrossman/behind-the-the-owasp-top-10-2017-rc1-df43236f79ff))

Given the controversy surrounding the current Top 10 2017 RC1, it is very important to get this right, and this Working Session will discuss, identify, and agree a 'Top 10 Selection Criteria'.

## What

 - Create a 'Top 10 Selection Criteria'
 - Apply the selection criteria to the all versions of the OWASP Top 10 (and see how they rank)
 - Create framework for it to be used in the other Working Sessions in the OWASP Top 10 2017 Track

## Outcomes

- 'Top 10 Selection Criteria' published
- Framework for Top 10 criteria to be used in other OWASP Top 10 2017 Working Sessions

## Who

The target audience for this Working Session is:

 - OWASP Top 10 2017 Track participants

## References

 - [Behind the The OWASP Top 10 2017 RC1](https://medium.com/@JoshCGrossman/behind-the-the-owasp-top-10-2017-rc1-df43236f79ff)

---

## Working materials

 - Long list of criteria for inclusion in 'Top 10 Selection Criteria'.
 - Draft framework for Top 10 criteria to be used in other OWASP Top 10 2017 Working Sesions.
(please add as much information as possible before the sessions)

### Content

... Add content ...


text:
/* -*-C++-*-
 *****************************************************************************
 *
 * File:         ExFastTransport.cpp
 * Description:  TDB/TCB for Fast transport
 *
 * Created:      08/28/2012
 * Language:     C++
 *
 *
 *****************************************************************************
 */
#include "ex_stdh.h"
#include "ExFastTransport.h"
#include "ex_globals.h"
#include "ex_exe_stmt_globals.h"
#include "exp_attrs.h"
#include "exp_clause_derived.h"
#include "ex_error.h"
#include "ExStats.h"
#include "ExCextdecs.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <pthread.h>
#include "ComSysUtils.h"
#include "SequenceFileReader.h"
#include "HdfsClient_JNI.h"
#include  "cli_stdh.h"
#include "ComSmallDefs.h"

//----------------------------------------------------------------------
// ExFastExtractTcb methods
//----------------------------------------------------------------------
ex_tcb *ExFastExtractTdb::build(ex_globals *glob)
{
  // first build the child TCBs
  ex_tcb *childTcb ;
  ExFastExtractTcb *feTcb;

  childTcb = childTdb_->build(glob);

    feTcb = new (glob->getSpace()) ExHdfsFastExtractTcb(*this, *childTcb,glob);

  feTcb->registerSubtasks();
  feTcb->registerResizeSubtasks();

  return feTcb;

}

ExFastExtractTcb::ExFastExtractTcb(
    const ExFastExtractTdb &fteTdb,
    const ex_tcb & childTcb,
    ex_globals *glob)
  : ex_tcb(fteTdb, 1, glob),
    workAtp_(NULL),
    outputPool_(NULL),
    inputPool_(NULL),
    childTcb_(&childTcb)
  , inSqlBuffer_(NULL)
  , childOutputTD_(NULL)
  , sourceFieldsConvIndex_(NULL)
  , currBuffer_(NULL)
  , bufferAllocFailuresCount_(0)
  , modTS_(-1)
{

  ex_globals *stmtGlobals = getGlobals();

  Space *globSpace = getSpace();
  CollHeap *globHeap = getHeap();

  heap_ = globHeap;

  //convert to non constant to access the members.
  ExFastExtractTdb *mytdb = (ExFastExtractTdb*)&fteTdb;
  numBuffers_ = mytdb->getNumIOBuffers();

  // Allocate queues to communicate with parent
  allocateParentQueues(qParent_);

  // get the queue that child use to communicate with me
  qChild_  = childTcb.getParentQueue();

  // Allocate the work ATP
  if (myTdb().getWorkCriDesc())
    workAtp_ = allocateAtp(myTdb().getWorkCriDesc(), globSpace);

  // Fixup expressions
  // NOT USED in M9
  /*
  if (myTdb().getInputExpression())
    myTdb().getInputExpression()->fixup(0, getExpressionMode(), this,
                                       globSpace, globHeap);

  if (myTdb().getOutputExpression())
    myTdb().getOutputExpression()->fixup(0, getExpressionMode(), this,
                                        globSpace, globHeap);
  */

  if (myTdb().getChildDataExpr())
    myTdb().getChildDataExpr()->fixup(0,getExpressionMode(),this,
                                       globSpace, globHeap, FALSE, glob);

  //maybe we can move the below few line to the init section od work methods??
  UInt32 numAttrs = myTdb().getChildTuple()->numAttrs();

   sourceFieldsConvIndex_ = (int *)((NAHeap *)heap_)->allocateAlignedHeapMemory((UInt32)(sizeof(int) * numAttrs), 512, FALSE);

  maxExtractRowLength_ = ROUND8(myTdb().getChildDataRowLen()) ;

  const ULng32 sqlBufferSize = maxExtractRowLength_ +
                               ROUND8(sizeof(SqlBufferNormal)) +
                               sizeof(tupp_descriptor) +
                               16 ;//just in case

  inSqlBuffer_ = (SqlBuffer *) new (heap_) char[sqlBufferSize];
  inSqlBuffer_->driveInit(sqlBufferSize, TRUE, SqlBuffer::NORMAL_);
  childOutputTD_ = inSqlBuffer_->add_tuple_desc(maxExtractRowLength_);

  endOfData_ = FALSE;

} // ExFastExtractTcb::ExFastExtractTcb

ExFastExtractTcb::~ExFastExtractTcb()
{
  // Release resources acquired
  //
  freeResources();

  delete qParent_.up;
  delete qParent_.down;

  if (workAtp_)
  {
    workAtp_->release();
    deallocateAtp(workAtp_, getSpace());
  }

  if (inSqlBuffer_ && getHeap())
  {
    getHeap()->deallocateMemory(inSqlBuffer_);
    inSqlBuffer_ = NULL;
    childOutputTD_ = NULL;
  }
  if (sourceFieldsConvIndex_)
    getHeap()->deallocateMemory(sourceFieldsConvIndex_);

} // ExFastExtractTcb::~ExFastExtractTcb()

//
// This function frees any resources acquired.
// It should only be called by the TCB destructor.
//
void ExFastExtractTcb::freeResources()
{
  for(Int16 i=0; i < numBuffers_; i++)
  {
    if(bufferPool_[i])
    {
      NADELETE(bufferPool_[i], IOBuffer, getHeap());
      bufferPool_[i] = NULL;
    }
  }
}

void ExFastExtractTcb::registerSubtasks()
{
  ex_tcb :: registerSubtasks();
}

ex_tcb_private_state *ExFastExtractTcb::allocatePstates(
  Lng32 &numElems,      // [IN/OUT] desired/actual elements
  Lng32 &pstateLength)  // [OUT] length of one element
{
  PstateAllocator<ExFastExtractPrivateState> pa;
  return pa.allocatePstates(this, numElems, pstateLength);
}

// Insert a single entry into the up queue and optionally
// remove the head of the down queue
//
// Right now this function does not handle data rows, only error
// and end-of-data. It could possibly be extended to handle a data
// row. I have not looked at that closely enough yet.
//
void ExFastExtractTcb::insertUpQueueEntry(ex_queue::up_status status,
                                  ComDiagsArea *diags,
                                  NABoolean popDownQueue)
{

  ex_queue_entry *upEntry = qParent_.up->getTailEntry();
  ex_queue_entry *downEntry = qParent_.down->getHeadEntry();
  ExFastExtractPrivateState &privateState =
    *((ExFastExtractPrivateState *) downEntry->pstate);

  // Initialize the up queue entry.
  //
  // copyAtp() will copy all tuple pointers and the diags area from
  // the down queue entry to the up queue entry.
  //
  // When we return Q_NO_DATA if the match count is > 0:
  // * assume down queue diags were returned with the Q_OK_MMORE entries
  // * release down queue diags before copyAtp()
  //
  if (status == ex_queue::Q_NO_DATA && privateState.matchCount_ > 0)
  {
    downEntry->setDiagsArea(NULL);
    upEntry->copyAtp(downEntry);
  }
  else
  {
    upEntry->copyAtp(downEntry);
    downEntry->setDiagsArea(NULL);
  }

  upEntry->upState.status = status;
  upEntry->upState.parentIndex = downEntry->downState.parentIndex;
  upEntry->upState.downIndex = qParent_.down->getHeadIndex();
  upEntry->upState.setMatchNo(privateState.matchCount_);

  // Move any diags to the up queue entry
  if (diags != NULL)
  {
    ComDiagsArea *atpDiags = upEntry->getDiagsArea();
    if (atpDiags == NULL)
    {
      // setDiagsArea() does not increment the reference count
      upEntry->setDiagsArea(diags);
      diags->incrRefCount();
    }
    else
    {
      atpDiags->mergeAfter(*diags);
    }
  }

  // Insert into up queue
  qParent_.up->insert();

  // Optionally remove the head of the down queue
  if (popDownQueue)
  {
    privateState.init();
    qParent_.down->removeHead();
  }
}

const char *ExFastExtractTcb::getTcbStateString(FastExtractStates s)
{
  switch (s)
  {
    case EXTRACT_NOT_STARTED:           return "EXTRACT_NOT_STARTED";
    case EXTRACT_INITIALIZE:            return "EXTRACT_INITIALIZE";
    case EXTRACT_PASS_REQUEST_TO_CHILD: return "EXTRACT_PASS_REQUEST_TO_CHILD";
    case EXTRACT_RETURN_ROWS_FROM_CHILD:return "EXTRACT_RETURN_ROWS_FROM_CHILD";
    case EXTRACT_DATA_READY_TO_SEND:    return "EXTRACT_DATA_READY_TO_SEND";
    case EXTRACT_SYNC_WITH_IO_THREAD:   return "EXTRACT_SYNC_WITH_IO_THREAD";
    case EXTRACT_ERROR:                 return "EXTRACT_ERROR";
    case EXTRACT_DONE:                  return "EXTRACT_DONE";
    case EXTRACT_CANCELED:              return "EXTRACT_CANCELED";
    default:                            return "UNKNOWN";
  }
}

/* Work method, where all the action happens
The stick figure shows transitions between various states.
Transitions to EXTRACT_ERROR are not shown for clarity.

EXTRACT_NOT_STARTED
        |
        |
        V
EXTRACT_INITIALIZE
        |
        |
        V
EXTRACT_PASS_REQUEST_TO_CHILD
        |
        |                   |----|
        V                   V    |
EXTRACT_RETURN_ROWS_FROM_CHILD ->|    EXTRACT_ERROR
        |      ^           |                |
        |      |       |------|             |
        V      |       V   |  |             |
EXTRACT_SYNC_WITH_IO_THREAD|->|             |
        |      ^           |                |
        |      |           |                |
        V      |           |                V
EXTRACT_DATA_READY_TO_SEND<-           EXTRACT_CANCELLED
                       \               /
                        \             /
                         V           V
                         EXTRACT_DONE

*/
ExWorkProcRetcode ExFastExtractTcb::work()
{

  assert(0);
  return WORK_OK;

}//ExFastExtractTcb::work()

void ExFastExtractTcb::updateWorkATPDiagsArea(ComDiagsArea *da)
{
    if (da)
    {
      if (workAtp_->getDiagsArea())
      {
        workAtp_->getDiagsArea()->mergeAfter(*da);
      }
      else
      {
        ComDiagsArea * da1 = da;
        workAtp_->setDiagsArea(da1);
        da1->incrRefCount();
      }
    }
}
void ExFastExtractTcb::updateWorkATPDiagsArea(ex_queue_entry * centry)
{
    if (centry->getDiagsArea())
    {
      if (workAtp_->getDiagsArea())
      {
        workAtp_->getDiagsArea()->mergeAfter(*centry->getDiagsArea());
      }
      else
      {
        ComDiagsArea * da = centry->getDiagsArea();
        workAtp_->setDiagsArea(da);
        da->incrRefCount();
        centry->setDiagsArea(0);
      }
    }
}

void ExFastExtractTcb::updateWorkATPDiagsArea(ExeErrorCode rc, const char *msg)
{
    ComDiagsArea *da = workAtp_->getDiagsArea();
    if(!da)
    {
      da = ComDiagsArea::allocate(getHeap());
      workAtp_->setDiagsArea(da);
    }
   if(msg != NULL)
   {
	   *da << DgSqlCode(-rc)
    	   << DgString0(msg);
   }
   else
   {
	  *da << DgSqlCode(-rc);
   }

}

void ExFastExtractTcb::updateWorkATPDiagsArea(const char *file,
                                              int line, const char *msg)
{
    ComDiagsArea *da = workAtp_->getDiagsArea();
    if(!da)
    {
      da = ComDiagsArea::allocate(getHeap());
      workAtp_->setDiagsArea(da);
    }

    *da << DgSqlCode(-1001)
        << DgString0(file)
        << DgInt0(line)
        << DgString1(msg);
}

NABoolean ExFastExtractTcb::needStatsEntry()
{
  if ((getGlobals()->getStatsArea()->getCollectStatsType() == ComTdb::ALL_STATS) ||
      (getGlobals()->getStatsArea()->getCollectStatsType() == ComTdb::OPERATOR_STATS))
    return TRUE;
  else
    return FALSE;
}
ExOperStats * ExFastExtractTcb::doAllocateStatsEntry(
                                              CollHeap *heap,
                                              ComTdb *tdb)
{
  ExOperStats *stat = NULL;

  ComTdb::CollectStatsType statsType = getGlobals()->getStatsArea()->getCollectStatsType();

  if (statsType == ComTdb::OPERATOR_STATS)
  {
     ExEspStmtGlobals *espGlobals = getGlobals()->castToExExeStmtGlobals()->castToExEspStmtGlobals();
     StmtStats *ss;
     if (espGlobals != NULL)
        ss = espGlobals->getStmtStats();
     else
        ss = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals()->getStatement()->getStmtStats();
     ExHdfsScanStats *hdfsScanStats = new (heap) ExHdfsScanStats(heap, this, tdb);
     if (ss != NULL)
        hdfsScanStats->setQueryId(ss->getQueryId(), ss->getQueryIdLen());
     return hdfsScanStats;
  }
  else
  {

    return new(heap) ExFastExtractStats( heap,
                                         this,
                                         tdb);
  }
}

ExHdfsFastExtractTcb::ExHdfsFastExtractTcb(
    const ExFastExtractTdb &fteTdb,
    const ex_tcb & childTcb,
    ex_globals *glob)
  : ExFastExtractTcb(
      fteTdb,
      childTcb,
      glob),
    sequenceFileWriter_(NULL)
  , hdfsClient_(NULL)
{

} // ExHdfsFastExtractTcb::ExFastExtractTcb

ExHdfsFastExtractTcb::~ExHdfsFastExtractTcb()
{

  if (sequenceFileWriter_ != NULL) {
     NADELETE(sequenceFileWriter_, SequenceFileWriter, getHeap());
     sequenceFileWriter_ = NULL;
  }

  if (hdfsClient_ != NULL) {
     NADELETE(hdfsClient_, HdfsClient, getHeap());
     hdfsClient_ = NULL;
  }

} // ExHdfsFastExtractTcb::~ExHdfsFastExtractTcb()

Int32 ExHdfsFastExtractTcb::fixup()
{
  ex_tcb::fixup();

  strncpy(hdfsHost_, myTdb().getHdfsHostName(), sizeof(hdfsHost_));
  hdfsPort_ = myTdb().getHdfsPortNum();

  modTS_ = myTdb().getModTSforDir();

  return 0;
}

void ExHdfsFastExtractTcb::convertSQRowToString(ULng32 nullLen,
                            ULng32 recSepLen,
                            ULng32 delimLen,
                            tupp_descriptor* dataDesc,
                            char* targetData,
                            NABoolean & convError) {
  char* childRow = dataDesc->getTupleAddress();
  ULng32 childRowLen = dataDesc->getAllocatedSize();
  UInt32 vcActualLen = 0;

  for (UInt32 i = 0; i < myTdb().getChildTuple()->numAttrs(); i++) {
    Attributes * attr = myTdb().getChildTableAttr(i);
    Attributes * attr2 = myTdb().getChildTableAttr2(i);
    char *childColData = NULL; //childRow + attr->getOffset();
    UInt32 childColLen = 0;
    UInt32 maxTargetColLen = attr2->getLength();

    //format is aligned format--
    //----------
    // field is varchar
    if (attr->getVCIndicatorLength() > 0) {
      childColData = childRow + *((UInt32*) (childRow + attr->getVoaOffset()));
      childColLen = attr->getLength(childColData);
      childColData += attr->getVCIndicatorLength();
    } else {              //source is fixed length
      childColData = childRow + attr->getOffset();
      childColLen = attr->getLength();
      if ((attr->getCharSet() == CharInfo::ISO88591
          || attr->getCharSet() == CharInfo::UTF8) && childColLen > 0) {
        // trim trailing blanks
        while (childColLen > 0 && childColData[childColLen - 1] == ' ') {
          childColLen--;
        }
      } else if (attr->getCharSet() == CharInfo::UCS2 && childColLen > 1) {
        ex_assert(childColLen % 2 == 0, "invalid ucs2");
        NAWchar* wChildColData = (NAWchar*) childColData;
        Int32 wChildColLen = childColLen / 2;
        while (wChildColLen > 0 && wChildColData[wChildColLen - 1] == L' ') {
          wChildColLen--;
        }
        childColLen = wChildColLen * 2;
      }
    }

    if (attr->getNullFlag()
        && ExpAlignedFormat::isNullValue(childRow + attr->getNullIndOffset(),
            attr->getNullBitIndex())) {
      // source is a null value.

      nullLen = 0;
      if (myTdb().getNullString()) {
        nullLen = strlen(myTdb().getNullString());
        memcpy(targetData, myTdb().getNullString(), nullLen);
      }

      targetData += nullLen;
      currBuffer_->bytesLeft_ -= nullLen;
    } else {
      switch ((ConvInstruction) sourceFieldsConvIndex_[i]) {
      case CONV_ASCII_V_V:
      case CONV_ASCII_F_V:
      case CONV_UNICODE_V_V:
      case CONV_UNICODE_F_V: {
        if (childColLen > 0) {
          memcpy(targetData, childColData, childColLen);
          targetData += childColLen;
          currBuffer_->bytesLeft_ -= childColLen;
        }
      }
        break;

      default:
        ex_expr::exp_return_type err = convDoIt(childColData, childColLen,
            attr->getDatatype(), attr->getPrecision(), attr->getScale(),
            targetData, attr2->getLength(), attr2->getDatatype(),
            attr2->getPrecision(), attr2->getScale(), (char*) &vcActualLen,
            sizeof(vcActualLen), 0, 0,             // diags may need to be added
            (ConvInstruction) sourceFieldsConvIndex_[i]);

        if (err == ex_expr::EXPR_ERROR) {
          convError = TRUE;
          // not exit loop -- we will log the errenous row later
          // do not cancel processing for this type of error???
        }
        targetData += vcActualLen;
        currBuffer_->bytesLeft_ -= vcActualLen;
        break;
      }                      //switch
    }

    if (i == myTdb().getChildTuple()->numAttrs() - 1) {
      strncpy(targetData, myTdb().getRecordSeparator(), recSepLen);
      targetData += recSepLen;
      currBuffer_->bytesLeft_ -= recSepLen;
    } else {
      strncpy(targetData, myTdb().getDelimiter(), delimLen);
      targetData += delimLen;
      currBuffer_->bytesLeft_ -= delimLen;
    }

  }
}

ExWorkProcRetcode ExHdfsFastExtractTcb::work()
{
  Lng32 retcode = 0;
  SFW_RetCode sfwRetCode = SFW_OK;
  HDFS_Client_RetCode hdfsClientRetCode = HDFS_CLIENT_OK;
  ULng32 recSepLen = strlen(myTdb().getRecordSeparator());
  ULng32 delimLen = strlen(myTdb().getDelimiter());
  ULng32 nullLen =
    (myTdb().getNullString() ? strlen(myTdb().getNullString()) : 0);
  if (myTdb().getIsHiveInsert())
  {
    recSepLen = 1;
    delimLen = 1;
  }
  if (getEmptyNullString()) //covers hive null case also
    nullLen = 0;

  ExOperStats *stats = NULL;
  ExFastExtractStats *feStats = getFastExtractStats();
  ExHdfsScanStats *hdfsStats = getHdfsScanStats();

  while (TRUE)
  {
    // if no parent request, return
    if (qParent_.down->isEmpty())
      return WORK_OK;

    ex_queue_entry *pentry_down = qParent_.down->getHeadEntry();
    const ex_queue::down_request request = pentry_down->downState.request;
    const Lng32 value = pentry_down->downState.requestValue;
    ExFastExtractPrivateState &pstate = *((ExFastExtractPrivateState *) pentry_down->pstate);
    switch (pstate.step_)
    {
    case EXTRACT_NOT_STARTED:
    {
      pstate.step_ = EXTRACT_INITIALIZE;
    }
    break;
    case EXTRACT_INITIALIZE:
    {
      pstate.processingStarted_ = FALSE;
      errorOccurred_ = FALSE;

      //Allocate writeBuffers.
      numBuffers_ = 1;
      for (Int16 i = 0; i < numBuffers_; i++)
      {
        bool done = false;
        Int64 input_datalen = myTdb().getHdfsIoBufferSize();
        char * buf_addr = 0;
        while ((!done) && input_datalen >= 32 * 1024)
        {
          buf_addr = 0;
          buf_addr = (char *)((NAHeap *)heap_)->allocateAlignedHeapMemory((UInt32)input_datalen, 512, FALSE);
          if (buf_addr)
          {
            done = true;
            bufferPool_[i] = new (heap_) IOBuffer((char*) buf_addr, (Int32)input_datalen);
          }
          else
          {
            bufferAllocFailuresCount_++;
            input_datalen = input_datalen / 2;
          }
        }
        if (!done)
        {
          numBuffers_ = i;
          break ; // if too few buffers have been allocated we will raise
        }         // an error later
      }

      if (feStats)
      {
        feStats->setBufferAllocFailuresCount(bufferAllocFailuresCount_);
        feStats->setBuffersCount(numBuffers_);
      }

      ComDiagsArea *da = NULL;

      if (myTdb().getTargetFile() )
        {
          Lng32 fileNum = getGlobals()->castToExExeStmtGlobals()->getMyInstanceNumber();
          memset (hdfsHost_, '\0', sizeof(hdfsHost_));
          strncpy(hdfsHost_, myTdb().getHdfsHostName(), sizeof(hdfsHost_));
          hdfsPort_ = myTdb().getHdfsPortNum();
          memset (fileName_, '\0', sizeof(fileName_));
          memset (targetLocation_, '\0', sizeof(targetLocation_));
          snprintf(targetLocation_,999, "%s", myTdb().getTargetName());

          char pt[80]="";
          char usec_buf[6]="";
          struct timeval tmnow;
          struct tm *currgmtime;
          gettimeofday(&tmnow, NULL);
          currgmtime = gmtime(&tmnow.tv_sec);
          strftime(pt, sizeof(pt), "%Y%m%d%H%M%S", currgmtime);
          sprintf(usec_buf,"%d",(int)tmnow.tv_usec);
          strcat(pt,usec_buf);
          srand(getpid());

          if (myTdb().getIsHiveInsert())
            snprintf(fileName_,999, "%s%d-%s-%d", myTdb().getHiveTableName(), fileNum, pt,rand() % 1000);
          else
            snprintf(fileName_,999, "%s%d-%s-%d", "file", fileNum, pt,rand() % 1000);

          if (isSequenceFile() && sequenceFileWriter_ == NULL)
          {
            sequenceFileWriter_ = new(getHeap())
                                     SequenceFileWriter((NAHeap *)getHeap());
            sfwRetCode = sequenceFileWriter_->init();
            if (sfwRetCode != SFW_OK)
            {
              createSequenceFileError(sfwRetCode);
              pstate.step_ = EXTRACT_ERROR;
              break;
            }
          }
          else if (!isSequenceFile() && hdfsClient_ == NULL)
          {
             hdfsClient_ = HdfsClient::newInstance((NAHeap *)getHeap(), (ExHdfsScanStats *)getHdfsScanStats(), hdfsClientRetCode);
             if (hdfsClientRetCode != HDFS_CLIENT_OK)
             {
                createHdfsClientFileError(hdfsClientRetCode);
                pstate.step_ = EXTRACT_ERROR;
                break;
             }
          }

          strcat(targetLocation_, "//");
          strcat(targetLocation_, fileName_);
          if (isSequenceFile())
          {
            sfwRetCode = sequenceFileWriter_->open(targetLocation_, SFW_COMP_NONE);
            if (sfwRetCode != SFW_OK)
            {
              createSequenceFileError(sfwRetCode);
              pstate.step_ = EXTRACT_ERROR;
              break;
            }
          }
          else
          {
             hdfsClientRetCode = hdfsClient_->hdfsOpen(targetLocation_, isHdfsCompressed());
             if (hdfsClientRetCode != HDFS_CLIENT_OK)
             {
                createHdfsClientFileError(hdfsClientRetCode);
                NADELETE(hdfsClient_,
                       HdfsClient,
                       heap_);
                hdfsClient_ = NULL;
                pstate.step_ = EXTRACT_ERROR;
                break;
             }
           }
           if (feStats)
           {
             feStats->setPartitionNumber(fileNum);
           }
       }
       else
       {
           updateWorkATPDiagsArea(__FILE__,__LINE__,"sockets are not supported");
           pstate.step_ = EXTRACT_ERROR;
           break;
       }

      for (UInt32 i = 0; i < myTdb().getChildTuple()->numAttrs(); i++)
      {
        Attributes * attr = myTdb().getChildTableAttr(i);
        Attributes * attr2 = myTdb().getChildTableAttr2(i);

        ex_conv_clause tempClause;
        int convIndex = 0;
        sourceFieldsConvIndex_[i] =
            tempClause.findInstruction(
                attr->getDatatype(),
                0,
                attr2->getDatatype(),
                0,
                0);

      }

      pstate.step_= EXTRACT_PASS_REQUEST_TO_CHILD;
    }
    break;

    case EXTRACT_PASS_REQUEST_TO_CHILD:
    {
      // pass the parent request to the child downqueue
      if (!qChild_.down->isFull())
      {
        ex_queue_entry * centry = qChild_.down->getTailEntry();

        if (request == ex_queue::GET_N)
          centry->downState.request = ex_queue::GET_ALL;
        else
          centry->downState.request = request;

        centry->downState.requestValue = pentry_down->downState.requestValue;
        centry->downState.parentIndex = qParent_.down->getHeadIndex();
        // set the child's input atp
        centry->passAtp(pentry_down->getAtp());
        qChild_.down->insert();
        pstate.processingStarted_ = TRUE;
      }
      else
        // couldn't pass request to child, return
        return WORK_OK;

      pstate.step_ = EXTRACT_RETURN_ROWS_FROM_CHILD;
    }
    break;
    case EXTRACT_RETURN_ROWS_FROM_CHILD:
    {
      if ((qChild_.up->isEmpty()))
      {
        return WORK_OK;
      }

      if (currBuffer_ == NULL)
      {
        currBuffer_ = bufferPool_[0];
        memset(currBuffer_->data_, '\0',currBuffer_->bufSize_);
        currBuffer_->bytesLeft_ = currBuffer_->bufSize_;
      }

      ex_queue_entry * centry = qChild_.up->getHeadEntry();
      ComDiagsArea *cda = NULL;
      ex_queue::up_status child_status = centry->upState.status;

      switch (child_status)
      {
      case ex_queue::Q_OK_MMORE:
      {
        // for the very first row retruned from child
        // include the header row if necessary
        if ((pstate.matchCount_ == 0) && myTdb().getIncludeHeader())
        {
          if (!myTdb().getIsAppend())
          {
            Int32 headerLength = strlen(myTdb().getHeader());
            char * target = currBuffer_->data_;
            if (headerLength + 1 < currBuffer_->bufSize_)
            {
              strncpy(target, myTdb().getHeader(),headerLength);
              target[headerLength] = '\n' ;
              currBuffer_->bytesLeft_ -= headerLength+1 ;
            }
            else
            {
              updateWorkATPDiagsArea(__FILE__,__LINE__,"header does not fit in buffer");
              pstate.step_ = EXTRACT_ERROR;
              break;
            }
          }
        }

        tupp_descriptor *dataDesc = childOutputTD_;
        ex_expr::exp_return_type expStatus = ex_expr::EXPR_OK;
        if (myTdb().getChildDataExpr())
        {
          UInt32 childTuppIndex = myTdb().childDataTuppIndex_;

          workAtp_->getTupp(childTuppIndex) = dataDesc;

          // Evaluate the child data expression. If diags are generated they
          // will be left in the down entry ATP.
          expStatus = myTdb().getChildDataExpr()->eval(centry->getAtp(), workAtp_);
          workAtp_->getTupp(childTuppIndex).release();

          if (expStatus == ex_expr::EXPR_ERROR)
          {
            if (myTdb().getContinueOnError())
              {
                // ignore this row and continue to the next row
                if (workAtp_->getDiagsArea())
                  workAtp_->getDiagsArea()->clear();
                break;
              }
            else
              {
                updateWorkATPDiagsArea(centry);
                pstate.step_ = EXTRACT_ERROR;
                break;
              }
          }
        } // if (myTdb().getChildDataExpr())
        ///////////////////////
        char * targetData = currBuffer_->data_ + currBuffer_->bufSize_ - currBuffer_->bytesLeft_;
        if (targetData == NULL)
        {
          updateWorkATPDiagsArea(__FILE__,__LINE__,"targetData is NULL");
          pstate.step_ = EXTRACT_ERROR;
          break;
        }
        NABoolean convError = FALSE;
        convertSQRowToString(nullLen, recSepLen, delimLen, dataDesc,
            targetData, convError);
        ///////////////////////////////
        pstate.matchCount_++;
        if (!convError)
        {
          if (feStats)
          {
            feStats->incProcessedRowsCount();
          }
              if (hdfsStats != NULL) {
                 hdfsStats->incUsedRows();
                 hdfsStats->incAccessedRows();
              }
          pstate.successRowCount_ ++;
        }
        else
        {
          if (feStats)
          {
            feStats->incErrorRowsCount();
          }
              if (hdfsStats != NULL)
                 hdfsStats->incAccessedRows();
          pstate.errorRowCount_ ++;
        }
        if (currBuffer_->bytesLeft_ < (Int32) maxExtractRowLength_)
        {
          pstate.step_ = EXTRACT_DATA_READY_TO_SEND;
        }
      }
      break;

      case ex_queue::Q_NO_DATA:
      {
        pstate.step_ = EXTRACT_DATA_READY_TO_SEND;
        endOfData_ = TRUE;
        pstate.processingStarted_ = FALSE ; // so that cancel does not
        //wait for this Q_NO_DATA
      }
      break;
      case ex_queue::Q_SQLERROR:
      {
        if ((centry->getDiagsArea()) &&
            (!pentry_down->getDiagsArea()))
          {
            ComDiagsArea *diagsArea = pentry_down->getDiagsArea();
            diagsArea = ComDiagsArea::allocate(getGlobals()->getDefaultHeap());
            pentry_down->setDiagsArea(diagsArea);
            pentry_down->getDiagsArea()->mergeAfter(*centry->getDiagsArea());
          }

        pstate.step_ = EXTRACT_ERROR;
      }
      break;
      case ex_queue::Q_INVALID:
      {
        updateWorkATPDiagsArea(__FILE__,__LINE__,
            "ExFastExtractTcb::work() Invalid state returned by child");
        pstate.step_ = EXTRACT_ERROR;
      }
      break;

      } // switch
      qChild_.up->removeHead();
    }
    break;

    case EXTRACT_DATA_READY_TO_SEND:
    {
      ssize_t bytesToWrite = currBuffer_->bufSize_ - currBuffer_->bytesLeft_;

      if (isSequenceFile())
        {
          sfwRetCode = sequenceFileWriter_->writeBuffer(currBuffer_->data_, bytesToWrite, myTdb().getRecordSeparator());
          if (sfwRetCode != SFW_OK)
          {
            createSequenceFileError(sfwRetCode);
            pstate.step_ = EXTRACT_ERROR;
            break;
          }
        }
      else
        {
          hdfsClient_->hdfsWrite(currBuffer_->data_, bytesToWrite, hdfsClientRetCode);
          if (hdfsClientRetCode != HDFS_CLIENT_OK)
          {
            createSequenceFileError(hdfsClientRetCode);
            pstate.step_ = EXTRACT_ERROR;
            break;
          }
        }

      if (feStats)
      {
        feStats->incReadyToSendBuffersCount();
        feStats->incReadyToSendBytes(currBuffer_->bufSize_ - currBuffer_->bytesLeft_);
      }
      currBuffer_ = NULL;

      if (endOfData_)
      {
        pstate.step_ = EXTRACT_DONE;
      }
      else
      {
        pstate.step_ = EXTRACT_RETURN_ROWS_FROM_CHILD;
      }
    }
    break;

    case EXTRACT_ERROR:
    {
      // If there is no room in the parent queue for the reply,
      // try again later.
      //Later we may split this state into 2 one for cancel and one for query
      if (qParent_.up->isFull())
        return WORK_OK;
      // Cancel the child request - there must be a child request in
      // progress to get to the ERROR state.
      if (pstate.processingStarted_)
      {
        qChild_.down->cancelRequestWithParentIndex(qParent_.down->getHeadIndex());
        //pstate.processingStarted_ = FALSE;
      }
      while (pstate.processingStarted_ && pstate.step_ == EXTRACT_ERROR)
      {
        if (qChild_.up->isEmpty())
          return WORK_OK;
        ex_queue_entry * childEntry = qChild_.up->getHeadEntry();
        ex_queue::up_status childStatus = childEntry->upState.status;

        if (childStatus == ex_queue::Q_NO_DATA)
        {
          pstate.step_ = EXTRACT_DONE;
          pstate.processingStarted_ = FALSE;
        }
        qChild_.up->removeHead();
      }
      ex_queue_entry *pentry_up = qParent_.up->getTailEntry();
      pentry_up->copyAtp(pentry_down);
      // Construct and return the error row.
      //
      if (workAtp_->getDiagsArea())
      {
        ComDiagsArea *diagsArea = pentry_up->getDiagsArea();
        if (diagsArea == NULL)
        {
          diagsArea = ComDiagsArea::allocate(getGlobals()->getDefaultHeap());
          pentry_up->setDiagsArea(diagsArea);
        }
        pentry_up->getDiagsArea()->mergeAfter(*workAtp_->getDiagsArea());
        workAtp_->setDiagsArea(NULL);
      }
      pentry_up->upState.status = ex_queue::Q_SQLERROR;
      pentry_up->upState.parentIndex
      = pentry_down->downState.parentIndex;
      pentry_up->upState.downIndex = qParent_.down->getHeadIndex();
      pentry_up->upState.setMatchNo(pstate.matchCount_);
      qParent_.up->insert();
      //
      errorOccurred_ = TRUE;
      pstate.step_ = EXTRACT_DONE;
    }
    break;

    case EXTRACT_DONE:
    {
      // If there is no room in the parent queue for the reply,
      // try again later.
      //
      if (qParent_.up->isFull())
        return WORK_OK;

      if (isSequenceFile())
      {
         if (sequenceFileWriter_)
         {
            sfwRetCode = sequenceFileWriter_->close();
            if (!errorOccurred_ && sfwRetCode != SFW_OK )
            {
               createSequenceFileError(sfwRetCode);
               pstate.step_ = EXTRACT_ERROR;
               break;
            }
         }
      }
      else
      {
         if (hdfsClient_)
         {
            hdfsClientRetCode = hdfsClient_->hdfsClose();
            if (!errorOccurred_ && HDFS_CLIENT_OK != HDFS_CLIENT_OK )
            {
               createHdfsClientFileError(hdfsClientRetCode);
               pstate.step_ = EXTRACT_ERROR;
               break;
            }
         }
      }

      //insertUpQueueEntry will insert Q_NO_DATA into the up queue and
      //remove the head of the down queue
      insertUpQueueEntry(ex_queue::Q_NO_DATA, NULL, TRUE);
      errorOccurred_ = FALSE;

      endOfData_ = FALSE;

      //we need to set the next state so that the query can get re-executed
      //and we start from the beginning again. Not sure if pstate will be
      //valid anymore because insertUpQueueEntry() might have cleared it
      //already.
      pstate.step_ = EXTRACT_NOT_STARTED;

      //exit out now and not break.
      return WORK_OK;
    }
    break;

    default:
    {
      ex_assert(FALSE, "Invalid state in  ExHdfsFastExtractTcb ");
    }

    break;

    } // switch(pstate.step_)
  } // while

  return WORK_OK;
}//ExHdfsFastExtractTcb::work()

void ExHdfsFastExtractTcb::insertUpQueueEntry(ex_queue::up_status status, ComDiagsArea *diags, NABoolean popDownQueue)
{

  ex_queue_entry *upEntry = qParent_.up->getTailEntry();
  ex_queue_entry *downEntry = qParent_.down->getHeadEntry();
  ExFastExtractPrivateState &privateState = *((ExFastExtractPrivateState *) downEntry->pstate);

  // Initialize the up queue entry.
  //
  // copyAtp() will copy all tuple pointers and the diags area from
  // the down queue entry to the up queue entry.
  //
  // When we return Q_NO_DATA if the match count is > 0:
  // * assume down queue diags were returned with the Q_OK_MMORE entries
  // * release down queue diags before copyAtp()
  //
  if (status == ex_queue::Q_NO_DATA && privateState.matchCount_ > 0)
  {
    downEntry->setDiagsArea(NULL);
    upEntry->copyAtp(downEntry);
  }
  else
  {
    upEntry->copyAtp(downEntry);
    downEntry->setDiagsArea(NULL);
  }

  upEntry->upState.status = status;
  upEntry->upState.parentIndex = downEntry->downState.parentIndex;
  upEntry->upState.downIndex = qParent_.down->getHeadIndex();
  upEntry->upState.setMatchNo(privateState.matchCount_);

  // rows affected code (below) medeled after ex_partn_access.cpp
  ExMasterStmtGlobals *g = getGlobals()->castToExExeStmtGlobals()->castToExMasterStmtGlobals();
  if (!g)
  {
    ComDiagsArea *da = upEntry->getDiagsArea();
    if (da == NULL)
    {
      da = ComDiagsArea::allocate(getGlobals()->getDefaultHeap());
      upEntry->setDiagsArea(da);
    }
    da->addRowCount(privateState.matchCount_);
  }
  else
  {
    g->setRowsAffected(privateState.matchCount_);
  }

  //
  // Insert into up queue
  qParent_.up->insert();

  // Optionally remove the head of the down queue
  if (popDownQueue)
  {
    privateState.init();
    qParent_.down->removeHead();
  }
}

NABoolean ExHdfsFastExtractTcb::isSequenceFile()
{
  return myTdb().getIsSequenceFile();
}
NABoolean ExHdfsFastExtractTcb::isHdfsCompressed()
{
  return myTdb().getHdfsCompressed();
}

void ExHdfsFastExtractTcb::createSequenceFileError(Int32 sfwRetCode)
{
  ContextCli *currContext = GetCliGlobals()->currContext();

  ComDiagsArea * diagsArea = NULL;
  char* errorMsg = sequenceFileWriter_->getErrorText((SFW_RetCode)sfwRetCode);
  ExRaiseSqlError(getHeap(),
                  &diagsArea,
                  (ExeErrorCode)(8447),
                  NULL, NULL, NULL, NULL,
                  errorMsg,
                (char *)GetCliGlobals()->getJniErrorStr());
  //ex_queue_entry *pentry_down = qParent_.down->getHeadEntry();
  //pentry_down->setDiagsArea(diagsArea);
  updateWorkATPDiagsArea(diagsArea);
}

void ExHdfsFastExtractTcb::createHdfsClientFileError(Int32 hdfsClientRetCode)
{
  ContextCli *currContext = GetCliGlobals()->currContext();

  ComDiagsArea * diagsArea = NULL;
  char* errorMsg = hdfsClient_->getErrorText((HDFS_Client_RetCode)hdfsClientRetCode);
  ExRaiseSqlError(getHeap(),
                  &diagsArea,
                  (ExeErrorCode)(8447),
                  NULL, NULL, NULL, NULL,
                  errorMsg,
                  (char *)GetCliGlobals()->getJniErrorStr());
  updateWorkATPDiagsArea(diagsArea);
}

ExFastExtractPrivateState::ExFastExtractPrivateState()
{
  init();
}

ExFastExtractPrivateState::~ExFastExtractPrivateState()
{
}


text:
package com.sun.jini.jeri.internal.mux;

import com.sun.jini.action.GetIntegerAction;
import com.sun.jini.thread.Executor;
import com.sun.jini.thread.GetThreadPoolAction;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.jini.core.constraint.InvocationConstraints;
import net.jini.io.UnsupportedConstraintException;
import net.jini.jeri.InboundRequest;
import net.jini.jeri.RequestDispatcher;
import net.jini.security.Security;
import net.jini.security.SecurityContext;

/**
 * A MuxServer controls the server side of a multiplexed connection.
 *
 * @author Sun Microsystems, Inc.
 **/
public class MuxServer extends Mux {

    /** initial inbound ration as server, default is 32768 */
    private static final int serverInitialInboundRation =
	((Integer) AccessController.doPrivileged(new GetIntegerAction(
	    "com.sun.jini.jeri.connection.mux.server.initialInboundRation",
	    32768))).intValue();

    /**
     * pool of threads for executing tasks with user code: used for
     * dispatching incoming requests to request dispatchers
     **/
    private static final Executor userThreadPool =
	(Executor) AccessController.doPrivileged(
	    new GetThreadPoolAction(true));

    /** mux logger */
    private static final Logger logger =
	Logger.getLogger("net.jini.jeri.connection.mux");

    /** the request dispatcher to dispatch incoming requests to */
    private final RequestDispatcher requestDispatcher;

    /** the security context to dispatch incoming requests in */
    private final SecurityContext securityContext;

    /**
     * Initiates the server side of a multiplexed connection over the
     * given input/output stream pair.
     *
     * @param out the output stream of the underlying connection
     *
     * @param in the input stream of the underlying connection
     *
     * @param requestDispatcher the request dispatcher to dispatch
     * incoming requests received on this multiplexed connection to
     **/
    public MuxServer(OutputStream out, InputStream in,
		     RequestDispatcher requestDispatcher)
	throws IOException
    {
	super(out, in, Mux.SERVER, serverInitialInboundRation, 1024);

	this.requestDispatcher = requestDispatcher;
	this.securityContext = Security.getContext();
    }

    public MuxServer(SocketChannel channel,
		     RequestDispatcher requestDispatcher)
	throws IOException
    {
	super(channel, Mux.SERVER, serverInitialInboundRation, 1024);

	this.requestDispatcher = requestDispatcher;
	this.securityContext = Security.getContext();
    }

    /**
     * Shuts down this multiplexed connection.  Requests in progress
     * will throw IOException for future I/O operations.
     *
     * On the client side, requests that were in progress will appear
     * to have been aborted with unknown partial execution status.
     *
     * @param message reason for shutdown to be included in
     * IOExceptions thrown from future I/O operations
     **/
    public void shutdown(String message) {
	synchronized (muxLock) {
	    /*
	     * Be graceful, if possible: i.e. if there are no busy sessions.
	     * REMIND: this current implementation is extremely conservative,
	     * because most previously-used sessions will still appear busy!
	     *
	     * We can only send a Shutdown message if we have already sent
	     * the ServerConnectionHeader.  The header may not have been sent
	     * if, for example, the ServerEndpointListener was closed right
	     * as a connection was accepted.  REMIND: should/could we try to
	     * send a ServerConnectionHeader here, in order to be able to
	     * send the Shutdown message?
	     */
	    if (serverConnectionReady && busySessions.isEmpty()) {
		asyncSendShutdown(null);
	    }
	    setDown(message, null);
	}
    }

    /**
     * Shuts down this multiplexed connection only if there are no
     * requests in progress (i.e. requests that have been dispatched
     * to the request dispatcher but that have not been aborted or had
     * their response fully written to the client).
     *
     * @return true if the connection was shut down (because there
     * were no requests in progress), and false otherwise
     **/
    public boolean shutdownGracefully() {
	synchronized (muxLock) {
	    if (busySessions.isEmpty()) {
		asyncSendShutdown(null);
		setDown("mux connection shut down gracefully", null);
		return true;
	    } else {
		return false;
	    }
	}
    }

    /**
     * Verifies that the calling context has all of the security
     * permissions necessary to receive a request on this connection.
     *
     * This method should be overridden by subclasses to implement the
     * desired behavior of the checkPermissions method for
     * InboundRequest instances generated for this connection.
     **/
    protected void checkPermissions() {
    }

    /**
     * Checks that the specified requirements are either fully or
     * partially satisfied by the constraints actually in force for
     * this connection, and returns any constraints that must be fully
     * or partially implemented by higher layers in order to fully
     * satisfy all of the specified requirements.
     *
     * This method should be overridden by subclasses to implement the
     * desired behavior of the checkConstraints method for
     * InboundRequest instances generated for this connection.
     **/
    protected InvocationConstraints
	checkConstraints(InvocationConstraints constraints)
	throws UnsupportedConstraintException
    {
	if (constraints.requirements().isEmpty()) {
	    return InvocationConstraints.EMPTY;
	}
	throw new UnsupportedConstraintException(
	    "cannot satisfy constraints: " + constraints);
    }

    /**
     * Populates the context collection with information representing
     * this connection (such as the client host).
     *
     * This method should be overridden by subclasses to implement the
     * desired behavior of the populateContext method for
     * InboundRequest instances generated for this connection.
     **/
    protected void populateContext(Collection context) {
    }

    /**
     * Handles message to open a new session over this connection.
     *
     * This method must NOT be invoked while synchronized on muxLock.
     **/
    void handleOpen(int sessionID) throws ProtocolException {
	assert !Thread.holdsLock(muxLock);

	Session session;
	synchronized (muxLock) {
	    if (!busySessions.get(sessionID)) {
		dispatchNewRequest(sessionID);
		return;
	    } else {
		session = (Session) sessions.get(new Integer(sessionID));
		assert session != null;
	    }
	}

	session.handleOpen();

	synchronized (muxLock) {
	    dispatchNewRequest(sessionID);
	}
    }

    private void dispatchNewRequest(int sessionID) throws ProtocolException {
	assert Thread.holdsLock(muxLock);
	if (muxDown) {
	    throw new ProtocolException(
		"connection down, cannot add new session");
	}
	/*
	 * REMIND: Here we might want to decide to reject the session,
	 * if current conditions warrant.
	 */
	final Session session = new Session(this, sessionID, Session.SERVER);
	addSession(sessionID, session);
	try {
	    userThreadPool.execute(new Runnable() {
		public void run() {
		    final InboundRequest request = session.getInboundRequest();
		    try {
			AccessController.doPrivileged(securityContext.wrap(
			    new PrivilegedAction() {
				public Object run() {
				    requestDispatcher.dispatch(request);
				    return null;
				}
			    }), securityContext.getAccessControlContext());
		    } finally {
			request.abort();
		    }
		}
	    }, "mux request dispatch");
	} catch (OutOfMemoryError e) {	// assume out of threads
	    try {
		logger.log(Level.WARNING,
			   "could not create thread for request dispatch", e);
	    } catch (Throwable t) {
	    }
	    // reject request but absorb exception to preserve connection
	    session.abort();
	}
    }
}


text:
package io.getclump

import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner

@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Spec {
  val tweetRepository = new TweetRepository
  val userRepository = new UserRepository
  val zipUserRepository = new ZipUserRepository
  val filteredUserRepository = new FilteredUserRepository
  val timelineRepository = new TimelineRepository
  val likeRepository = new LikeRepository
  val trackRepository = new TrackRepository
  val topTracksRepository = new TopTracksRepository
  val failingTweetRepository = new FailingTweetRepository

  val tweets = Clump.source(tweetRepository.tweetsFor _)
  val users = Clump.source(userRepository.usersFor _)
  val filteredUsers = Clump.source(filteredUserRepository.usersFor _)(_.userId)
  val zippedUsers = Clump.sourceZip(zipUserRepository.usersFor _)
  val timelines = Clump.source(timelineRepository.timelinesFor _)(_.timelineId)
  val likes = Clump.source(likeRepository.likesFor _)(_.likeId)
  val tracks = Clump.source(trackRepository.tracksFor _)(_.trackId)

  "A Clump should batch calls to services" in {
    val tweetRepositoryMock = mock[TweetRepository]
    val tweets = Clump.source(tweetRepositoryMock.tweetsFor _)

    val userRepositoryMock = mock[UserRepository]
    val users = Clump.source(userRepositoryMock.usersFor _)
    val topTracks = Clump.sourceSingle(topTracksRepository.topTracksFor _)

    tweetRepositoryMock.tweetsFor(Set(1L, 2L, 3L)) returns
      Future.successful(Map(
        1L -> Tweet("Tweet1", 10),
        2L -> Tweet("Tweet2", 20),
        3L -> Tweet("Tweet3", 30)
      ))

    userRepositoryMock.usersFor(Set(10L, 20L, 30L)) returns
      Future.successful(Map(
        10L -> User(10, "User10"),
        20L -> User(20, "User20"),
        30L -> User(30, "User30")
      ))

    val enrichedTweets = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get(tweetId)
        user <- users.get(tweet.userId)
        tracks <- topTracks.get(user)
      } yield (tweet, user, tracks)
    }

    awaitResult(enrichedTweets.get) ==== Some(List(
      (Tweet("Tweet1", 10), User(10, "User10"), Set(Track(10, "Track10"), Track(11, "Track11"), Track(12, "Track12"))),
      (Tweet("Tweet2", 20), User(20, "User20"), Set(Track(20, "Track20"), Track(21, "Track21"), Track(22, "Track22"))),
      (Tweet("Tweet3", 30), User(30, "User30"), Set(Track(30, "Track30"), Track(31, "Track31"), Track(32, "Track32")))))
  }

  "A Clump should batch calls to parameterized services" in {
    val parameterizedTweetRepositoryMock = mock[ParameterizedTweetRepository]
    val tweets = Clump.source(parameterizedTweetRepositoryMock.tweetsFor _)

    val parameterizedUserRepositoryMock = mock[ParameterizedUserRepository]
    val users = Clump.source(parameterizedUserRepositoryMock.usersFor _)(_.userId)

    parameterizedTweetRepositoryMock.tweetsFor("foo", Set(1, 2, 3)) returns
      Future.successful(Map(
        1L -> Tweet("Tweet1", 10),
        2L -> Tweet("Tweet2", 20),
        3L -> Tweet("Tweet3", 30)
      ))

    parameterizedUserRepositoryMock.usersFor("bar", Set(10, 20, 30)) returns
      Future.successful(Set(
        User(10, "User10"),
        User(20, "User20"),
        User(30, "User30")
      ))

    val enrichedTweets = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get("foo", tweetId)
        user <- users.get("bar", tweet.userId)
      } yield (tweet, user)
    }

    awaitResult(enrichedTweets.get) ==== Some(List(
      (Tweet("Tweet1", 10), User(10, "User10")),
      (Tweet("Tweet2", 20), User(20, "User20")),
      (Tweet("Tweet3", 30), User(30, "User30"))))
  }

  "it should be able to be used in complex nested fetches" in {
    val timelineIds = List(1, 3)
    val enrichedTimelines = Clump.traverse(timelineIds) { id =>
        for {
          timeline <- timelines.get(id)
          enrichedLikes <- Clump.traverse(timeline.likeIds) { id =>
            for {
              like <- likes.get(id)
              (tracks, users) <- tracks.get(like.trackIds).join(users.get(like.userIds))
            } yield (like, tracks, users)
          }
        } yield (timeline, enrichedLikes)
      }

    awaitResult(enrichedTimelines.get) ==== Some(List(
      (Timeline(1, List(10, 20)), List(
        (Like(10, List(100, 200), List(1000, 2000)), List(Track(100, "Track100"), Track(200, "Track200")), List(User(1000, "User1000"), User(2000, "User2000"))),
        (Like(20, List(200, 400), List(2000, 4000)), List(Track(200, "Track200"), Track(400, "Track400")), List(User(2000, "User2000"), User(4000, "User4000"))))),
      (Timeline(3, List(30, 60)), List(
        (Like(30, List(300, 600), List(3000, 6000)), List(Track(300, "Track300"), Track(600, "Track600")), List(User(3000, "User3000"), User(6000, "User6000"))),
        (Like(60, List(600, 1200), List(6000, 12000)), List(Track(600, "Track600"), Track(1200, "Track1200")), List(User(6000, "User6000"), User(12000, "User12000")))))))
  }

  "it should be usable with regular maps and flatMaps" in {
    val tweetIds = List(1L, 2L, 3L)
    val enrichedTweets: Clump[List[(Tweet, User)]] =
      Clump.traverse(tweetIds) { tweetId =>
        tweets.get(tweetId).flatMap(tweet =>
          users.get(tweet.userId).map(user => (tweet, user)))
      }

    awaitResult(enrichedTweets.get) ==== Some(List(
      (Tweet("Tweet1", 10), User(10, "User10")),
      (Tweet("Tweet2", 20), User(20, "User20")),
      (Tweet("Tweet3", 30), User(30, "User30"))))
  }

  "it should allow unwrapping Clumped lists with clump.list" in {
    val enrichedTweets: Clump[List[(Tweet, User)]] = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get(tweetId)
        user <- users.get(tweet.userId)
      } yield (tweet, user)
    }

    awaitResult(enrichedTweets.list) ==== List(
      (Tweet("Tweet1", 10), User(10, "User10")),
      (Tweet("Tweet2", 20), User(20, "User20")),
      (Tweet("Tweet3", 30), User(30, "User30")))
  }

  "it should work with Clump.sourceZip" in {
    val enrichedTweets = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get(tweetId)
        user <- zippedUsers.get(tweet.userId)
      } yield (tweet, user)
    }

    awaitResult(enrichedTweets.get) ==== Some(List(
      (Tweet("Tweet1", 10), User(10, "User10")),
      (Tweet("Tweet2", 20), User(20, "User20")),
      (Tweet("Tweet3", 30), User(30, "User30"))))
  }

  "A Clump can have a partial result" in {
    val onlyFullObjectGraph: Clump[List[(Tweet, User)]] = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get(tweetId)
        user <- filteredUsers.get(tweet.userId)
      } yield (tweet, user)
    }

    awaitResult(onlyFullObjectGraph.get) ==== Some(List((Tweet("Tweet2", 20), User(20, "User20"))))

    val partialResponses: Clump[List[(Tweet, Option[User])]] = Clump.traverse(1, 2, 3) { tweetId =>
      for {
        tweet <- tweets.get(tweetId)
        user <- filteredUsers.get(tweet.userId).optional
      } yield (tweet, user)
    }

    awaitResult(partialResponses.get) ==== Some(List(
      (Tweet("Tweet1", 10), None),
      (Tweet("Tweet2", 20), Some(User(20, "User20"))),
      (Tweet("Tweet3", 30), None)))
  }

  "A Clump can have individual failing entities" in {
    val source = Clump.sourceTry(failingTweetRepository.tweetsFor _)

    def getTweetWithoutFallback(id: Long) = source.get(id)
    def getTweetWithFallback(id: Long) = source.get(id).fallback(Tweet("<error>", 0))

    val fail = for {
      tweetA <- getTweetWithoutFallback(1)
      tweetB <- getTweetWithoutFallback(-1)
    } yield (tweetA, tweetB)

    awaitResult(fail.get) must throwA[IllegalStateException]

    val success = for {
      tweetA <- getTweetWithFallback(1)
      tweetB <- getTweetWithFallback(-1)
    } yield (tweetA, tweetB)

    awaitResult(success.get) ==== Some((Tweet("Tweet1", 10), Tweet("<error>", 0)))
  }
}

case class Tweet(body: String, userId: Long)

case class User(userId: Long, name: String)

case class Timeline(timelineId: Int, likeIds: List[Long])

case class Like(likeId: Long, trackIds: List[Long], userIds: List[Long])

case class Track(trackId: Long, name: String)

class TweetRepository {
  def tweetsFor(ids: Set[Long]): Future[Map[Long, Tweet]] = {
    Future.successful(ids.map(id => id -> Tweet(s"Tweet$id", id * 10)).toMap)
  }
}

trait ParameterizedTweetRepository {
  def tweetsFor(prefix: String, ids: Set[Long]): Future[Map[Long, Tweet]]
}

class FailingTweetRepository {
  def tweetsFor(ids: Set[Long]): Future[Map[Long, Try[Tweet]]] = {
    Future.successful(ids.map {
      case id if id > 0 => id -> Success(Tweet(s"Tweet$id", id * 10))
      case id => id -> Failure(new IllegalStateException)
    }.toMap)
  }
}

class UserRepository {
  def usersFor(ids: Set[Long]): Future[Map[Long, User]] = {
    Future.successful(ids.map(id => id -> User(id, s"User$id")).toMap)
  }
}

trait ParameterizedUserRepository {
  def usersFor(prefix: String, ids: Set[Long]): Future[Set[User]]
}

class ZipUserRepository {
  def usersFor(ids: List[Long]): Future[List[User]] = {
    Future.successful(ids.map(id => User(id, s"User$id")))
  }
}

class FilteredUserRepository {
  def usersFor(ids: Set[Long]): Future[Set[User]] = {
    Future.successful(ids.filter(_ % 20 == 0).map(id => User(id, s"User$id")))
  }
}

class TimelineRepository {
  def timelinesFor(ids: Set[Int]): Future[Set[Timeline]] = {
    Future.successful(ids.map(id => Timeline(id, List(id * 10, id * 20))))
  }
}

class LikeRepository {
  def likesFor(ids: Set[Long]): Future[Set[Like]] = {
    Future.successful(ids.map(id => Like(id, List(id * 10, id * 20), List(id * 100, id * 200))))
  }
}

class TrackRepository {
  def tracksFor(ids: Set[Long]): Future[Set[Track]] = {
    Future.successful(ids.map(id => Track(id, s"Track$id")))
  }
}

class TopTracksRepository {
  def topTracksFor(user: User): Future[Set[Track]] = {
    def track(id: Long): Track = Track(id, s"Track$id")
    val userId = user.userId
    Future.successful(Set(track(userId), track(userId + 1), track(userId + 2)))
  }
}


text:
<!DOCTYPE html>

    <title>Classes  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>

TwilioLookup Docs (28% documented)

View on GitHub

        TwilioLookup Reference

        Classes  Reference

            Classes

                TwilioLookup

Classes

The following classes are available globally.

                    TwilioLookup

Class used to lookup phone number using the Lookup feature of Twilio.

To use TwilioLookup methods you need to set the accountSid and accountToken found in the Twilio console dashboard [https://www.twilio.com/console/sms/dashboard].

                        See more

Declaration

Swift

public class TwilioLookup

2016 © Fabio Borella - Pencildrummer

Generated by jazzy ♪♫ v0.7.0, a Realm project.


text:
class CreateCiSourcesProjects < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  def change
    create_table :ci_sources_projects do |t|
      t.bigint :pipeline_id, null: false
      t.bigint :source_project_id, null: false

      t.index [:source_project_id, :pipeline_id], unique: true
      t.index :pipeline_id
    end
  end
end