text:
"""Management command to take screenshots and save API results for dashboard states"""
# pylint: disable=redefined-outer-name,unused-argument
import itertools
import os
import sys
from urllib.parse import quote_plus

from selenium.webdriver.common.by import By
from faker.generator import random
import pytest

from django.core.management import (
    BaseCommand,
    call_command,
)
from django.db import connection
from django.test import override_settings
from django.contrib.auth.models import User

from cms.factories import CourseCertificateSignatoriesFactory
from courses.factories import CourseRunFactory
from courses.models import (
    Course,
    CourseRun,
    Program,
)
from dashboard.models import ProgramEnrollment
from ecommerce.factories import LineFactory
from ecommerce.models import (
    Coupon,
    UserCoupon,
    Order,
)
from exams.factories import ExamRunFactory, ExamProfileFactory, ExamAuthorizationFactory
from financialaid.factories import FinancialAidFactory
from financialaid.models import FinancialAidStatus
from grades.factories import ProctoredExamGradeFactory, MicromastersCourseCertificateFactory, FinalGradeFactory
from grades.models import FinalGrade, CourseRunGradingStatus, MicromastersCourseCertificate
from roles.models import Role, Staff
from seed_data.lib import set_course_run_current, CachedEnrollmentHandler, add_paid_order_for_course, \
    set_course_run_past, set_course_run_future
from seed_data.management.commands.alter_data import EXAMPLE_COMMANDS
from selenium_tests.data_util import create_user_for_login
from selenium_tests.util import (
    DEFAULT_PASSWORD,
    DatabaseLoader,
    terminate_db_connections,
    should_load_from_existing_db,
)
from selenium_tests.page import LoginPage

# We need to have pytest skip DashboardStates when collecting tests to run, but we also want to run it as a test
# when invoked by this command so we can take advantage of Selenium and the test database infrastructure. This
# defaults the test to being skipped. When the management command runs it changes this flag to True to
# invoke the test.
RUNNING_DASHBOARD_STATES = False

# We are passing options via global variable because of the bizarre way this management command is structured. Since
# pytest is used to invoke the tests, we don't have a good way to pass options to it directly.
DASHBOARD_STATES_OPTIONS = None

DUMP_DIRECTORY = "output/dashboard_states"
SEEDED_BACKUP_DB_NAME = "backup_selenium_seeded_db"

def generate_alter_data_call(command):
    """Generates a function that will execute an alter_data command with certain arguments"""
    return lambda: call_command("alter_data", command.command, *command.args)

def bind_args(func, *args, **kwargs):
    """Helper function to bind the args to the closure"""
    return lambda: func(*args, **kwargs)

class DashboardStates:  # pylint: disable=too-many-locals, too-many-public-methods
    """Runs through each dashboard state taking a snapshot"""
    def __init__(self, user=None):
        """
        Args:
            user (User): A User
        """
        self.user = user

    def create_exams(self, current, edx_passed, exam_passed, new_offering, can_schedule, future_exam, need_to_pay):
        """Create an exam and mark it and the related course as passed or not passed"""
        # pylint: disable-msg=too-many-arguments
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        course = Course.objects.get(title='Digital Learning 200')
        if current:
            course_run = CourseRunFactory(course=course)
            call_command(
                "alter_data", 'set_to_enrolled', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key
            )
            FinalGradeFactory.create(
                user=self.user, course_run=course_run, grade=0.8 if edx_passed else 0.2, passed=True
            )
        else:
            if edx_passed:
                call_command(
                    "alter_data", 'set_to_passed', '--username', 'staff',
                    '--course-title', 'Digital Learning 200', '--grade', '75',
                )
            else:
                call_command(
                    "alter_data", 'set_to_failed', '--username', 'staff',
                    '--course-title', 'Digital Learning 200', '--grade', '45',
                )
            course_run = course.courserun_set.first()

        ExamProfileFactory.create(status='success', profile=self.user.profile)
        exam_run = ExamRunFactory.create(course=course, eligibility_past=True, scheduling_past=True)
        ExamAuthorizationFactory.create(
            user=self.user, course=course, exam_run=exam_run, status='success', exam_taken=True
        )
        LineFactory.create(
            order__status=Order.FULFILLED,
            course_key=course_run
        )

        ProctoredExamGradeFactory.create(
            user=self.user,
            course=course,
            exam_run=exam_run,
            passed=exam_passed,
            percentage_grade=0.8 if exam_passed else 0.3
        )
        if new_offering:
            CourseRunFactory.create(course=course)

        if can_schedule:
            exam_run = ExamRunFactory.create(
                scheduling_past=False,
                scheduling_future=False,
                authorized=True,
                course=course
            )
            ExamAuthorizationFactory.create(
                user=self.user, course=course, exam_run=exam_run, status='success',
            )

        if future_exam:
            ExamRunFactory.create(
                scheduling_past=False,
                scheduling_future=True,
                authorized=True,
                course=course
            )
        if need_to_pay:
            exam_run = ExamRunFactory.create(course=course, eligibility_past=True, scheduling_past=True)
            ExamAuthorizationFactory.create(
                user=self.user, course=course, exam_run=exam_run, status='success', exam_taken=True
            )
            ProctoredExamGradeFactory.create(
                user=self.user,
                course=course,
                exam_run=exam_run,
                passed=False,
                percentage_grade=0.3
            )

    def with_prev_passed_run(self):
        """Add a passed run to a failed course. The course should then be passed"""
        call_command(
            "alter_data", 'set_to_failed', '--username', 'staff',
            '--course-title', 'Analog Learning 200', '--grade', '45',
        )
        call_command(
            "alter_data", 'set_past_run_to_passed', '--username', 'staff',
            '--course-title', 'Analog Learning 200',
        )

    def pending_enrollment(self):
        """
        Mark a course run as offered, then use the CyberSource redirect URL to view the pending enrollment status
        """
        run = CourseRun.objects.get(title='Analog Learning 100 - August 2015')
        call_command(
            'alter_data', 'set_to_offered', '--username', 'staff',
            '--course-run-title', 'Analog Learning 100 - August 2015',
        )
        run.refresh_from_db()
        return "/dashboard?status=receipt&course_key={}".format(quote_plus(run.edx_course_key))

    def contact_course(self):
        """Show a contact course team link"""
        call_command(
            "alter_data", 'set_to_passed', '--username', 'staff',
            '--course-title', 'Analog Learning 200', '--grade', '75',
        )
        course = Course.objects.get(title='Analog Learning 200')
        course.contact_email = 'example@example.com'
        course.save()

    def missed_payment_can_reenroll(self):
        """User has missed payment but they can re-enroll"""
        call_command(
            "alter_data", 'set_to_needs_upgrade', '--username', 'staff',
            '--course-title', 'Analog Learning 200', '--missed-deadline',
        )
        course = Course.objects.get(title='Analog Learning 200')
        CourseRunFactory.create(course=course)

    def failed_run_missed_payment_can_reenroll(self):
        """Failed User has missed payment but they can re-enroll"""
        call_command(
            "alter_data", 'set_to_failed', '--username', 'staff',
            '--course-title', 'Analog Learning 200', '--grade', '0', '--audit'
        )
        course = Course.objects.get(title='Analog Learning 200')
        CourseRunFactory.create(course=course)

    def with_coupon(self, amount_type, is_program, is_free):
        """Add a course-level coupon"""
        # Set up financial aid and use Digital Learning since coupons are only allowed for financial aid programs
        self.with_financial_aid(FinancialAidStatus.AUTO_APPROVED, True)

        course = Course.objects.get(title='Digital Learning 200')
        if is_program:
            content_object = course.program
        else:
            content_object = course

        if amount_type in (Coupon.FIXED_DISCOUNT, Coupon.FIXED_PRICE):
            amount = 50
        else:
            if is_free:
                amount = 1
            else:
                amount = 0.25

        coupon = Coupon.objects.create(
            content_object=content_object, coupon_type=Coupon.STANDARD, amount_type=amount_type, amount=amount,
        )
        UserCoupon.objects.create(user=self.user, coupon=coupon)

    def with_coupon_no_financial_aid_application(self):
        """Coupon without a financial aid application"""
        self.with_coupon(Coupon.PERCENT_DISCOUNT, True, False)
        self.user.financialaid_set.update(status=FinancialAidStatus.RESET)

    def with_coupon_pending_financial_aid(self):
        """Coupon with a non-terminal financial aid application"""
        self.with_coupon(Coupon.PERCENT_DISCOUNT, True, False)
        self.user.financialaid_set.update(status=FinancialAidStatus.PENDING_MANUAL_APPROVAL)

    def with_financial_aid(self, status, is_enrolled):
        """Set the status of user's financial aid"""
        if is_enrolled:
            call_command(
                "alter_data", 'set_to_needs_upgrade', '--username', 'staff', '--course-title', 'Digital Learning 200'
            )
        else:
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff', '--course-title', 'Digital Learning 200'
            )
        self.make_fa_program_enrollment(status)

    def make_fa_program_enrollment(self, status):
        """Enroll user in financial aid program"""
        Program.objects.get(title='Analog Learning').delete()
        # We need to use Digital Learning here since it has financial aid enabled. Deleting Analog Learning
        # because it's simpler than adjusting the UI to show the right one
        program = Program.objects.get(title='Digital Learning')
        ProgramEnrollment.objects.create(user=self.user, program=program)
        FinancialAidFactory.create(
            user=self.user,
            status=status,
            tier_program__program=program,
            tier_program__discount_amount=50,
        )

    def create_paid_failed_course_run(self, *, current, in_future, fuzzy):
        """Make paid failed course run, and offer another run"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        call_command(
            "alter_data", 'set_to_failed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '45',
        )
        course = Course.objects.get(title='Digital Learning 200')

        if current:
            CourseRunFactory.create(course=course)

        if in_future:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-in-future')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key, '--in-future'
            )
        if fuzzy:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-fuzzy')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key, '--fuzzy'
            )

    def create_passed_and_offered_course_run(self, grades_frozen, with_certificate):
        """Make passed and currently offered course run, and see the View Certificate and Re-Enroll"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        call_command(
            "alter_data", 'set_to_passed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '89',
        )
        course = Course.objects.get(title='Digital Learning 200')
        # create another currently offered run
        CourseRunFactory.create(course=course)

        if grades_frozen:
            final_grade = FinalGrade.objects.filter(user=self.user, course_run__course=course, passed=True).first()
            CourseRunGradingStatus.objects.create(course_run=final_grade.course_run, status='complete')
            if with_certificate:
                MicromastersCourseCertificate.objects.create(user=self.user, course=course)
                CourseCertificateSignatoriesFactory.create(course=course)

    def create_paid_but_no_enrollable_run(self, enrollable, in_future, fuzzy):
        """Make paid but not enrolled, with offered currently, in future, and fuzzy """
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        course = Course.objects.get(title='Digital Learning 200')
        course_run = course.courserun_set.order_by('start_date').first()
        # course_run = CourseRunFactory.create(course=course, edx_course_key='course-paid')

        add_paid_order_for_course(user=self.user, course_run=course_run)
        if enrollable:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-enrollable')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key
            )
        if in_future:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-in-future')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key, '--in-future'
            )
        if fuzzy:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-fuzzy')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key, '--fuzzy'
            )

    def create_passed_enrolled_again(self):
        """Make course passed and user retaking/auditing the course again"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        course = Course.objects.get(title='Digital Learning 200')
        CourseCertificateSignatoriesFactory.create(course=course)

        call_command(
            "alter_data", 'set_past_run_to_passed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '87',
        )
        final_grade = FinalGrade.objects.filter(
            course_run__course__title='Digital Learning 200', user=self.user
        ).first()
        CourseRunGradingStatus.objects.create(course_run=final_grade.course_run, status='complete')
        MicromastersCourseCertificateFactory.create(user=self.user, course=course)

        course_run = CourseRunFactory.create(course=course)
        set_course_run_current(course_run, upgradeable=True, save=True)
        CachedEnrollmentHandler(self.user).set_or_create(course_run, verified=False)

    def create_audited_passed_enrolled_again_failed(self):
        """Make course passed and user retaking/auditing the course again"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        course = Course.objects.get(title='Digital Learning 200')
        CourseCertificateSignatoriesFactory.create(course=course)

        course_run = CourseRunFactory(course=course, edx_course_key='course-passed')
        set_course_run_past(course_run)
        call_command(
            "alter_data", 'set_to_passed', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key, '--grade', '80', '--audit'
        )
        final_grade = FinalGrade.objects.filter(
            course_run__course__title='Digital Learning 200', user=self.user
        ).first()
        CourseRunGradingStatus.objects.create(course_run=final_grade.course_run, status='complete')

        course_run = CourseRunFactory(course=course, edx_course_key='course-failed')
        set_course_run_past(course_run)
        call_command(
            "alter_data", 'set_to_failed', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key, '--grade', '10', '--audit'
        )

        course_run = CourseRunFactory(course=course, edx_course_key='course-offered')
        set_course_run_future(course_run)
        call_command(
            'alter_data', 'set_to_offered', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key,
        )

    def create_failed_course_price_pending(self):
        """Make failed course and still pending personal course price"""
        self.make_fa_program_enrollment(FinancialAidStatus.PENDING_MANUAL_APPROVAL)
        call_command(
            "alter_data", 'set_past_run_to_failed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '10', '--audit'
        )

    def create_passed_and_upgrade_deadline_past(self):
        """Make course passed in past and fail new next attempts"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)

        call_command(
            "alter_data", 'set_past_run_to_failed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '10', '--audit'
        )
        call_command(
            "alter_data", 'set_past_run_to_failed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '0', '--audit'
        )
        call_command(
            "alter_data", 'set_past_run_to_passed', '--username', 'staff',
            '--course-title', 'Digital Learning 200', '--grade', '87', '--audit',
            '--missed-deadline'
        )

    def create_missed_payment_for_exam(self, enrollable, future_exam, current):
        """Passed course but missed deadline to pay to take exam"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        if current:
            call_command(
                "alter_data", 'set_to_enrolled', '--username', 'staff',
                '--course-title', 'Digital Learning 200',
                '--missed-deadline'
            )
        else:
            call_command(
                "alter_data", 'set_past_run_to_passed', '--username', 'staff',
                '--course-title', 'Digital Learning 200', '--grade', '87', '--audit',
                '--missed-deadline'
            )
        course = Course.objects.get(title='Digital Learning 200')
        ExamProfileFactory.create(status='success', profile=self.user.profile)
        ExamRunFactory.create(course=course, eligibility_past=True, scheduling_past=True)

        if enrollable:
            course_run = CourseRunFactory.create(course=course, edx_course_key='course-enrollable')
            call_command(
                "alter_data", 'set_to_offered', '--username', 'staff',
                '--course-run-key', course_run.edx_course_key
            )
        if future_exam:
            ExamRunFactory.create(
                scheduling_past=False,
                scheduling_future=True,
                authorized=True,
                course=course
            )

    def two_no_show_exam_attempts(self):
        """Passed and later failed course, and two exam attempts"""
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)

        course = Course.objects.get(title='Digital Learning 200')
        course_run = CourseRunFactory(course=course, edx_course_key='course-passed')
        call_command(
            "alter_data", 'set_to_passed', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key
        )

        ExamProfileFactory.create(status='success', profile=self.user.profile)
        # run 1
        exam_run = ExamRunFactory.create(course=course, eligibility_past=True, scheduling_past=True)
        ExamAuthorizationFactory.create(
            user=self.user, course=course, exam_run=exam_run, status='success', exam_taken=True, exam_no_show=True
        )
        # run 2
        exam_run = ExamRunFactory.create(course=course, eligibility_past=True, scheduling_past=True)
        ExamAuthorizationFactory.create(
            user=self.user, course=course, exam_run=exam_run, status='success', exam_taken=True, exam_no_show=True
        )
        # another offered
        course_run = CourseRunFactory.create(course=course, edx_course_key='course-enrollable')
        call_command(
            "alter_data", 'set_to_offered', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key
        )
        course_run = CourseRunFactory.create(course=course, edx_course_key='course-failed')
        call_command(
            "alter_data", 'set_to_failed', '--username', 'staff',
            '--course-run-key', course_run.edx_course_key, '--audit',
        )

    def create_paid_enrolled_currently_with_future_run(self):
        """Make paid and enrolled with offered currently and a future run """
        self.make_fa_program_enrollment(FinancialAidStatus.AUTO_APPROVED)
        course = Course.objects.get(title='Digital Learning 200')
        course_run_current = CourseRunFactory(course=course)
        call_command(
            "alter_data", 'set_to_enrolled', '--username', 'staff',
            '--course-run-key', course_run_current.edx_course_key
        )

        course_run_future = CourseRunFactory(course=course)
        call_command(
            "alter_data", 'set_to_enrolled', '--username', 'staff',
            '--course-run-key', course_run_future.edx_course_key,
            '--in-future'
        )

    def __iter__(self):
        """
        Iterator over all dashboard states supported by this command.

        Yields:
            tuple of scenario_func, name:
                scenario_func is a function to make modifications to the database to produce a scenario
                name is the name of this scenario, to use with the filename
        """
        # Generate scenarios from all alter_data example commands
        yield from (
            (generate_alter_data_call(command), command.command) for command in EXAMPLE_COMMANDS
            # Complicated to handle, and this is the same as the previous command anyway
            if "--course-run-key" not in command.args and
            command.command not in ['course_info', 'clear_user_dashboard_data']
        )

        # Add scenarios for every combination of passed/failed course and exam
        for tup in itertools.product([True, False], repeat=7):
            current, edx_passed, exam_passed, is_offered, can_schedule, future_exam, has_to_pay = tup

            yield (
                bind_args(
                    self.create_exams, current, edx_passed, exam_passed, is_offered,
                    can_schedule, future_exam, has_to_pay
                ),
                'create_exams{current}_{edx_passed}_{exam_passed}{new_offering}'
                '{can_schedule}{future_exam}{has_to_pay}'.format(
                    current='_current' if current else '',
                    edx_passed='edx_✔' if edx_passed else 'edx_✖',
                    exam_passed='exam_✔' if exam_passed else 'exam_✖',
                    new_offering='_with_new_offering' if is_offered else '',
                    can_schedule='_can_schedule' if can_schedule else '',
                    future_exam='_more_exams' if future_exam else '',
                    has_to_pay='_failed_one_exam' if has_to_pay else ''
                ),
            )

        for tup in itertools.product([True, False], repeat=3):
            current, in_future, fuzzy = tup

            yield (bind_args(self.create_paid_failed_course_run, current=current, in_future=in_future, fuzzy=fuzzy),
                   'create_paid_failed_course_run{current}{in_future}{fuzzy}'.format(
                       current='_offered_now' if current else '',
                       in_future='_offered_in_future' if in_future else '',
                       fuzzy='_offered_fuzzy' if fuzzy else ''
                   ))

        yield from (
            (bind_args(self.create_passed_and_offered_course_run, frozen, with_certificate),
             'create_passed_and_offered_course_run{frozen}{with_certificate}'.format(
                 frozen='_grades_frozen' if frozen else '',
                 with_certificate='_with_certificate' if with_certificate else ''
             )) for frozen, with_certificate in [(True, True), (True, False), (False, False)]
        )

        yield (self.create_passed_enrolled_again, 'passed_and_taking_again')
        yield (self.create_passed_and_upgrade_deadline_past, 'passed_and_missed_deadline_and_fail_in_next')
        yield (self.create_failed_course_price_pending, 'failed_and_pending_price')
        yield (self.create_audited_passed_enrolled_again_failed, 'create_audited_passed_enrolled_again_failed')
        yield (self.two_no_show_exam_attempts, 'two_no_show_exam_attempts')

        for tup in itertools.product([True, False], repeat=3):
            enrollable, future_exam, current = tup

            yield (bind_args(
                self.create_missed_payment_for_exam,
                enrollable=enrollable,
                future_exam=future_exam,
                current=current
            ),
                   'create{current}_missed_payment_for_exam{enrollable}{future_exam}'.format(
                       enrollable='_enrollable_run' if enrollable else '',
                       future_exam='_future_exam' if future_exam else '',
                       current='_current_course' if current else '_passed'
                   ))

        # Add scenarios for paid and course run offered [now, in future, fuzzy future]
        for tup in itertools.product([True, False], repeat=3):
            enrollable, in_future, fuzzy = tup

            yield (bind_args(self.create_paid_but_no_enrollable_run, enrollable, in_future, fuzzy),
                   'paid_but_not_enrolled{enrollable}{in_future}{fuzzy}'.format(
                       enrollable='_has_enrollable' if enrollable else '',
                       in_future='_in_future' if in_future else '',
                       fuzzy='_fuzzy' if fuzzy else ''
                   ))

        # Also test for two different passing and failed runs on the same course
        yield (self.with_prev_passed_run, 'failed_with_prev_passed_run')

        # Add scenarios for coupons
        coupon_scenarios = [
            (Coupon.FIXED_PRICE, True, False),
            (Coupon.FIXED_PRICE, False, False),
            (Coupon.FIXED_DISCOUNT, True, False),
            (Coupon.FIXED_DISCOUNT, False, False),
            (Coupon.PERCENT_DISCOUNT, True, False),
            (Coupon.PERCENT_DISCOUNT, False, False),
            (Coupon.PERCENT_DISCOUNT, True, True),
            (Coupon.PERCENT_DISCOUNT, False, True),
        ]
        yield from (
            (bind_args(self.with_coupon, *args), "coupon_{amount_type}_{program}_{free}".format(
                amount_type=args[0],
                program='program' if args[1] else 'course',
                free='free' if args[2] else 'not-free',
            ))
            for args in coupon_scenarios
        )

        # Other misc scenarios
        yield (self.with_coupon_no_financial_aid_application, 'with_coupon_no_financial_aid_application')
        yield (self.with_coupon_pending_financial_aid, 'with_coupon_pending_financial_aid')
        yield (self.pending_enrollment, 'pending_enrollment')
        yield (self.contact_course, 'contact_course')
        yield (self.missed_payment_can_reenroll, 'missed_payment_can_reenroll')
        yield (self.failed_run_missed_payment_can_reenroll, 'failed_run_missed_payment_can_reenroll')
        yield (self.create_paid_enrolled_currently_with_future_run, 'create_paid_enrolled_currently_with_future_run')

        # Financial aid statuses
        for status in FinancialAidStatus.ALL_STATUSES:
            for is_enrolled in (True, False):
                yield (
                    bind_args(self.with_financial_aid, status, is_enrolled),
                    'finaid_{status}{enrolled}'.format(
                        status=status,
                        enrolled="_needs_upgrade" if is_enrolled else "_offered",
                    )
                )

def make_filename(num, name, output_directory='', use_mobile=False):
    """Format the filename without extension for dashboard states"""
    return os.path.join(
        output_directory,
        "dashboard_state_{num:03d}_{command}{mobile}".format(
            num=num,
            command=name,
            mobile="_mobile" if use_mobile else "",
        )
    )

@pytest.fixture(scope="session")
def seeded_database_loader():
    """
    Fixture for a DatabaseLoader object. Using a different object than the fixture defined
    in selenium_tests/conftest.py because we don't want to overwrite the backup database used
    in the actual Selenium test suite.
    """
    return DatabaseLoader(db_backup_name=SEEDED_BACKUP_DB_NAME)

@pytest.fixture(scope="session")
def test_data(django_db_blocker, seeded_database_loader, pytestconfig):
    """
    Fixture that creates a login-enabled test user and backs up a seeded database to be
    loaded in between dashboard states and cleaned up at the end of the test run.
    """
    user = None
    with django_db_blocker.unblock():
        with connection.cursor() as cur:
            load_from_existing_db = should_load_from_existing_db(seeded_database_loader, cur, config=pytestconfig)
            if not load_from_existing_db:
                user = create_user_for_login(is_staff=True, username='staff')
                call_command("seed_db")
                # Analog Learning program enrollment is being created here because
                # no programs are enrolled in the initial data snapshot. Setting this enrollment
                # ensures that the user will see the Analog Learning program in the dashboard.
                # Right now we manually delete this enrollment in scenarios where we want the user
                # to see the Digital Learning dashboard.
                ProgramEnrollment.objects.create(
                    user=user,
                    program=Program.objects.get(title='Analog Learning')
                )
                seeded_database_loader.create_backup(db_cursor=cur)
    if load_from_existing_db:
        with django_db_blocker.unblock():
            terminate_db_connections()
        seeded_database_loader.load_backup()
        user = User.objects.get(username='staff')
    yield dict(user=user)

# pylint: disable=too-many-locals
@pytest.mark.skipif(
    'not RUNNING_DASHBOARD_STATES',
    reason='DashboardStates test suite is only meant to be run via management command',
)
def test_dashboard_states(browser, override_allowed_hosts, seeded_database_loader, django_db_blocker, test_data):
    """Iterate through all possible dashboard states and save screenshots/API results of each one"""
    output_directory = DASHBOARD_STATES_OPTIONS.get('output_directory')
    use_learner_page = DASHBOARD_STATES_OPTIONS.get('learner')
    os.makedirs(output_directory, exist_ok=True)
    use_mobile = DASHBOARD_STATES_OPTIONS.get('mobile')
    if use_mobile:
        browser.driver.set_window_size(480, 854)

    dashboard_states = DashboardStates(test_data['user'])
    dashboard_state_iter = enumerate(dashboard_states)
    match = DASHBOARD_STATES_OPTIONS.get('match')
    if match is not None:
        dashboard_state_iter = filter(
            lambda scenario: match in make_filename(scenario[0], scenario[1][1]),
            dashboard_state_iter
        )

    LoginPage(browser).log_in_via_admin(dashboard_states.user, DEFAULT_PASSWORD)
    for num, (run_scenario, name) in dashboard_state_iter:
        skip_screenshot = False
        with django_db_blocker.unblock():
            dashboard_states.user.refresh_from_db()
            if use_learner_page:
                for program in Program.objects.all():
                    Role.objects.create(role=Staff.ROLE_ID, user=dashboard_states.user, program=program)
            filename = make_filename(num, name, output_directory=output_directory, use_mobile=use_mobile)
            new_url = run_scenario()
            if new_url is None:
                if use_learner_page:
                    new_url = '/learner'
                else:
                    new_url = '/dashboard'
            elif use_learner_page:
                # the new_url is only for the dashboard page, skip
                skip_screenshot = True
            if not skip_screenshot:
                browser.get(new_url)
                browser.store_api_results(
                    dashboard_states.user.username,
                    filename=filename
                )
                if use_learner_page:
                    browser.wait_until_loaded(By.CLASS_NAME, 'user-page')
                else:
                    browser.wait_until_loaded(By.CLASS_NAME, 'course-list')
                browser.take_screenshot(filename=filename)
        with django_db_blocker.unblock():
            terminate_db_connections()
        seeded_database_loader.load_backup()

class Command(BaseCommand):
    """
    Take screenshots and save API results for dashboard states
    """
    help = "Take screenshots and save API results for dashboard states"

    def add_arguments(self, parser):
        parser.add_argument(
            "--match",
            dest="match",
            help="Runs only scenarios matching the given string",
            required=False,
        )
        parser.add_argument(
            "--create-db",
            dest="create_db",
            action='store_true',
            help="Passes the --create-db flag to py.test, guaranteeing a fresh database",
            required=False,
        )
        parser.add_argument(
            "--list-scenarios",
            dest="list_scenarios",
            action='store_true',
            help="List scenario names and exit",
            required=False
        )
        parser.add_argument(
            "--mobile",
            dest="mobile",
            action='store_true',
            help="Take screenshots with a smaller width as if viewed with a mobile device",
            required=False,
        )
        parser.add_argument(
            "--learner",
            dest="learner",
            action="store_true",
            help="Take screenshots of /learner instead",
            required=False,
        )
        parser.add_argument(
            "--output",
            dest="output_directory",
            default=DUMP_DIRECTORY,
            help="The output directory to put the files in",
            required=False,
        )

    def handle(self, *args, **options):
        random.seed(12345)
        if options.get('list_scenarios'):
            self.stdout.write('Scenarios:\n')
            for num, (_, name) in enumerate(DashboardStates()):
                self.stdout.write("  {:03}_{}\n".format(num, name))
            return

        if not os.environ.get('WEBPACK_DEV_SERVER_HOST'):
            # This should only happen if the user is running in an environment without Docker, which isn't allowed
            # for this command.
            raise Exception('Missing environment variable WEBPACK_DEV_SERVER_HOST.')

        if os.environ.get('RUNNING_SELENIUM') != 'true':
            raise Exception(
                "This management command must be run with ./scripts/test/run_snapshot_dashboard_states.sh"
            )

        # We need to use pytest here instead of invoking the tests directly so that the test database
        # is used. Using override_settings(DATABASE...) causes a warning message and is not reliable.
        global RUNNING_DASHBOARD_STATES  # pylint: disable=global-statement
        RUNNING_DASHBOARD_STATES = True
        global DASHBOARD_STATES_OPTIONS  # pylint: disable=global-statement
        DASHBOARD_STATES_OPTIONS = options

        with override_settings(
            OPENSEARCH_INDEX='testindex',
        ):
            pytest_args = ["{}::test_dashboard_states".format(__file__), "-s"]
            if options.get('create_db'):
                pytest_args.append('--create-db')
            sys.exit(pytest.main(args=pytest_args))


text:
package org.batfish.datamodel.matchers;

import static org.hamcrest.Matchers.equalTo;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.batfish.datamodel.FlowDiff;
import org.batfish.datamodel.Ip;
import org.batfish.datamodel.matchers.FlowDiffMatchersImpl.IsIpRewrite;
import org.batfish.datamodel.matchers.FlowDiffMatchersImpl.IsPortRewrite;
import org.batfish.datamodel.transformation.IpField;
import org.batfish.datamodel.transformation.PortField;
import org.hamcrest.Matcher;

@ParametersAreNonnullByDefault
public final class FlowDiffMatchers {

  /**
   * Returns a matcher that matches when the {@link FlowDiff} is an IP rewrite with {@code
   * expectedIpField}, with old IP {@code expectedOldIp}, and with new IP {@code expectedNewIp}.
   */
  public static @Nonnull Matcher<FlowDiff> isIpRewrite(
      IpField expectedIpField, Ip expectedOldIp, Ip expectedNewIp) {
    return new IsIpRewrite(
        equalTo(expectedIpField), equalTo(expectedOldIp), equalTo(expectedNewIp));
  }

  /**
   * Returns a matcher that matches when the {@link FlowDiff} is an IP rewrite with {@code
   * expectedIpField} whose old IP is matched by {@code oldIpMatcher} and whose new IP is matched by
   * {@code newIpMatcher}.
   */
  public static @Nonnull Matcher<FlowDiff> isIpRewrite(
      IpField expectedIpField, Matcher<? super Ip> oldIpMatcher, Matcher<? super Ip> newIpMatcher) {
    return new IsIpRewrite(equalTo(expectedIpField), oldIpMatcher, newIpMatcher);
  }

  /**
   * Returns a matcher that matches when the {@link FlowDiff} is a port rewrite with {@code
   * expectedPortField} whose old port is matched by {@code oldPortMatcher} and whose new port is
   * matched by {@code newPortMatcher}.
   */
  public static @Nonnull Matcher<FlowDiff> isPortRewrite(
      PortField expectedPortField,
      Matcher<? super Integer> oldPortMatcher,
      Matcher<? super Integer> newPortMatcher) {
    return new IsPortRewrite(equalTo(expectedPortField), oldPortMatcher, newPortMatcher);
  }

  private FlowDiffMatchers() {}
}

redpajama_set_name: RedPajamaGithub


text:
"""Unittest for network_utils.py module."""

from google_compute_engine import network_utils
from google_compute_engine.test_compat import builtin
from google_compute_engine.test_compat import mock
from google_compute_engine.test_compat import unittest

class NetworkUtilsTest(unittest.TestCase):

  def setUp(self):
    self.mock_logger = mock.Mock()
    self.interfaces = {'address': 'interface'}
    self.mock_utils = network_utils.NetworkUtils(self.mock_logger)
    self.mock_utils.interfaces = self.interfaces

  @mock.patch('google_compute_engine.network_utils.os.listdir')
  def testCreateInterfaceMap(self, mock_listdir):
    mock_open = mock.mock_open()
    interface_map = {
        '1': 'a',
        '2': 'b',
        '3': 'c',
    }
    mock_listdir.return_value = interface_map.values()

    with mock.patch('%s.open' % builtin, mock_open, create=False):
      addresses = interface_map.keys()
      addresses = ['%s\n' % address for address in addresses]
      mock_open().read.side_effect = interface_map.keys()
      self.assertEqual(self.mock_utils._CreateInterfaceMap(), interface_map)

  @mock.patch('google_compute_engine.network_utils.os.listdir')
  def testCreateInterfaceMapError(self, mock_listdir):
    mock_open = mock.mock_open()
    mock_listdir.return_value = ['a', 'b', 'c']

    with mock.patch('%s.open' % builtin, mock_open, create=False):
      mock_open().read.side_effect = [
          '1', OSError('OSError'), IOError('IOError')]
      self.assertEqual(self.mock_utils._CreateInterfaceMap(), {'1': 'a'})
      expected_calls = [
          mock.call.warning(mock.ANY, 'b', 'OSError'),
          mock.call.warning(mock.ANY, 'c', 'IOError'),
      ]
      self.assertEqual(self.mock_logger.mock_calls, expected_calls)

  def testGetNetworkInterface(self):
    self.assertIsNone(self.mock_utils.GetNetworkInterface('invalid'))
    self.assertEqual(
        self.mock_utils.GetNetworkInterface('address'), 'interface')


text:
<?php

namespace DigitalOceanV2\Entity;

/**
 * @author Antoine Corcy <contact@sbin.dk>
 */
class Meta extends AbstractEntity
{
    /**
     * @var int
     */
    public $total;
}


text:
/*!
  Theme: Bespin
  Author: Jan T. Sott
  License: ~ MIT (or more permissive) [via base16-schemes-source]
  Maintainer: @highlightjs/core-team
  Version: 2021.09.0
*/

/*
  WARNING: DO NOT EDIT THIS FILE DIRECTLY.

  This theme file was auto-generated from the Base16 scheme bespin
  by the Highlight.js Base16 template builder.

  - https://github.com/highlightjs/base16-highlightjs
*/

/*
base00  #28211c  Default Background
base01  #36312e  Lighter Background (Used for status bars, line number and folding marks)
base02  #5e5d5c  Selection Background
base03  #666666  Comments, Invisibles, Line Highlighting
base04  #797977  Dark Foreground (Used for status bars)
base05  #8a8986  Default Foreground, Caret, Delimiters, Operators
base06  #9d9b97  Light Foreground (Not often used)
base07  #baae9e  Light Background (Not often used)
base08  #cf6a4c  Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
base09  #cf7d34  Integers, Boolean, Constants, XML Attributes, Markup Link Url
base0A  #f9ee98  Classes, Markup Bold, Search Text Background
base0B  #54be0d  Strings, Inherited Class, Markup Code, Diff Inserted
base0C  #afc4db  Support, Regular Expressions, Escape Characters, Markup Quotes
base0D  #5ea6ea  Functions, Methods, Attribute IDs, Headings
base0E  #9b859d  Keywords, Storage, Selector, Markup Italic, Diff Changed
base0F  #937121  Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
*/

pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 1em;
}

code.hljs {
  padding: 3px 5px;
}

.hljs {
  color: #8a8986;
  background: #28211c;
}

.hljs::selection,
.hljs ::selection {
  background-color: #5e5d5c;
  color: #8a8986;
}

/* purposely do not highlight these things */
.hljs-formula,
.hljs-params,
.hljs-property
{}

/* base03 - #666666 -  Comments, Invisibles, Line Highlighting */
.hljs-comment {
  color: #666666;
}

/* base04 - #797977 -  Dark Foreground (Used for status bars) */
.hljs-tag {
  color: #797977;
}

/* base05 - #8a8986 -  Default Foreground, Caret, Delimiters, Operators */
.hljs-subst,
.hljs-punctuation,
.hljs-operator {
  color: #8a8986;
}

.hljs-operator {
  opacity: 0.7;
}

/* base08 - Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted */
.hljs-bullet,
.hljs-variable,
.hljs-template-variable,
.hljs-selector-tag,
.hljs-name,
.hljs-deletion {
  color: #cf6a4c;
}

/* base09 - Integers, Boolean, Constants, XML Attributes, Markup Link Url */
.hljs-symbol,
.hljs-number,
.hljs-link,
.hljs-attr,
.hljs-variable.constant_,
.hljs-literal {
  color: #cf7d34;
}

/* base0A - Classes, Markup Bold, Search Text Background */
.hljs-title,
.hljs-class .hljs-title,
.hljs-title.class_
{
  color: #f9ee98;
}

.hljs-strong {
  font-weight:bold;
  color: #f9ee98;
}

/* base0B - Strings, Inherited Class, Markup Code, Diff Inserted */
.hljs-code,
.hljs-addition,
.hljs-title.class_.inherited__,
.hljs-string {
  color: #54be0d;
}

/* base0C - Support, Regular Expressions, Escape Characters, Markup Quotes */
.hljs-built_in,
.hljs-doctag, /* guessing */
.hljs-quote,
.hljs-keyword.hljs-atrule,
.hljs-regexp {
  color: #afc4db;
}

/* base0D - Functions, Methods, Attribute IDs, Headings */
.hljs-function .hljs-title,
.hljs-attribute,
.ruby .hljs-property,
.hljs-title.function_,
.hljs-section {
  color: #5ea6ea;
}

/* base0E - Keywords, Storage, Selector, Markup Italic, Diff Changed */
.hljs-type,
/* .hljs-selector-id, */
/* .hljs-selector-class, */
/* .hljs-selector-attr, */
/* .hljs-selector-pseudo, */
.hljs-template-tag,
.diff .hljs-meta,
.hljs-keyword {
  color: #9b859d;
}
.hljs-emphasis {
  color: #9b859d;
  font-style: italic;
}

/* base0F - Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?> */
.hljs-meta,
/*
  prevent top level .keyword and .string scopes
  from leaking into meta by accident
*/
.hljs-meta .hljs-keyword,
.hljs-meta .hljs-string
{
  color: #937121;
}

.hljs-meta .hljs-keyword,
/* for v10 compatible themes */
.hljs-meta-keyword {
  font-weight: bold;
}


text:
package tasks

import (
	"io/ioutil"
	"strconv"

	"github.com/ansible-semaphore/semaphore/util"
)

func (t *task) installInventory() error {
	if t.inventory.SshKeyID != nil {
		// write inventory key
		err := t.installKey(t.inventory.SshKey)
		if err != nil {
			return err
		}
	}

	switch t.inventory.Type {
	case "static":
		return t.installStaticInventory()
	}

	return nil
}

func (t *task) installStaticInventory() error {
	t.log("installing static inventory")

	// create inventory file
	return ioutil.WriteFile(util.Config.TmpPath+"/inventory_"+strconv.Itoa(t.task.ID), []byte(t.inventory.Inventory), 0664)
}


text:
class FltGroup : public FltBeadID {
public:
  FltGroup(FltHeader *header);

  enum Flags {
    F_forward_animation   = 0x40000000,
    F_swing_animation     = 0x20000000,
    F_bounding_box        = 0x10000000,
    F_freeze_bounding_box = 0x08000000,
    F_default_parent      = 0x04000000,
  };

  int _relative_priority;
  unsigned int _flags;
  int _special_id1, _special_id2;
  int _significance;
  int _layer_id;

protected:
  virtual bool extract_record(FltRecordReader &reader);
  virtual bool build_record(FltRecordWriter &writer) const;

public:
  virtual TypeHandle get_type() const {
    return get_class_type();
  }
  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  static TypeHandle get_class_type() {
    return _type_handle;
  }
  static void init_type() {
    FltBeadID::init_type();
    register_type(_type_handle, "FltGroup",
                  FltBeadID::get_class_type());
  }

private:
  static TypeHandle _type_handle;
};

#endif


text:
A set of scripts for working with PostgreSQL and ArangoDB databases based on extending Jeroen Janssens 'Data Science on the Command Line' https://github.com/jeroenjanssens/data-science-at-the-command-line, plus helper and miscellaneous scripts

Now with additional scripts for processing and converting large(ish) xml files to (ndjson)

More information about ArangoDB and PostGres can be found here:
 * ArangoDB: https://www.arangodb.com
 * PostgreSQL: https://www.postgresql.org

## osmrailway

A set of query shell-scripts that extract railway data from an OpenStreetMap Overpass API server. An example docker build for OpenStreetMap Overpass API server under a Debian based Linux distribution can be found here. https://github.com/guidoeco/osm-overpass

More information about OpenStreetMap and Overpass API can be found here:
  * OpenStreetMap: http://www.openstreetmap.org
  * Overpass API: http://overpass-api.de

## testrailway

The scripts in **testrailway** will create a **testrailway** Arangodb database instance, import the railway data extracted from an OpenStreetMap Overpass API server in **osmrailway** and create a json report containing OSM node information which can then be viewed in the 'visualisation' sub-directory using a d3/leaflet mashup http://bl.ocks.org/anisotropi4/3452a4d2d7e848511feafe8a6c1bfaee

The **testrailway** dataset was used on a smaller North Yorkshire dataset based to prove the concept before moving to the British Isles which is manged using the **fullrailway** scripts, and is due to issues with scaling the visualisation.

The ArangoDB used is based on the ArangoDB server docker build scripts here https://github.com/guidoeco/docker in the arangodb directory.

The render uses a mash up of d3 (https://d3js.org) and leaflet (http://leafletjs.com).

## fullrailway

The scripts in **fullrailway** will create a **fullrailway** Arangodb database instance for a larger geographical area, import the railway data extracted from an OpenStreetMap Overpass API server in **osmrailway** and create a json report containing OSM node information which can then be viewed in the 'visualisation' sub-directory using a d3/leaflet mashup.

Due to the large size of data associated with the British Isles (920k+ points) two approaches are used to render the information. The first is based on a random selection heuristic and can be seen here http://bl.ocks.org/anisotropi4/85107c0e617f382e8462b1f264998718

## overlapfilter

This contains a set of scripts that calculate a "valid distance" parameter for the data associated with the British Isles (920k+ points). The visualisation based on this overlap heuristic can be seen here: http://bl.ocks.org/anisotropi4/003ed4f355160a49f0c4b3e169191ac8

## volpe

This contains a set of scripts to create an ArangoDB edge collection and Foxx service that provides a shortest-path d3/leaflet mashup visualisation using a simple URL /startnode/endnode/ microservice

## ogrrailway

A set of query shell-scripts that extract British railway data using the [osmctools](https://gitlab.com/osm-c-tools/osmctools) toolset rather than the Overpass API under a Debian based Linux distribution. This then processes the railway data using an [arangodb database](https://www.arangodb.com/) for visualisation in a d3/Leaflet javascript mashup

More information about OpenStreetMap can be found here:
  * OpenStreetMap: http://www.openstreetmap.org

## markdown

A set of python and shell scripts to locally process and convert between [Markdown](https://daringfireball.net/projects/markdown) `.md` and `.yaml` format files, and out `.html`

## xl2tsv

A python script that dumps the content of xls(x) files to a `[<source-filename>:]<tabname>.tsv` files in the (default) output directory.

## pwdcheck

A set of scripts to generate and search 128 ordered sha1sum hash files for passwords known to be hacked. Thanks to Troy Hunt and https://haveibeenpwned.com/ for making this data available

## 'bin' directory scripts

The 'bin' directory 'aql' scripts are used extensively in the 'goldfinch' and other projects and should be installed in the user-account `${HOME}/bin` directory:

### **create_table.py**

Based on column names in a tsv file-format this python3 script create a PostgreSQL import script. Run the script to create a table create/import script 'table_CORPUS.sql' that imports the file 'CORPUS.tsv':
`$ bin/create_table.py CORPUS.tsv`

 To then import 'CORPUS.tsv' into the table table_corpus (database user 'finch' and postgres server 'raven') run the following:
`$ < table_CORPUS.sql psql -U finch -h raven`
 * The tablename is lowercase 'table_corpus'
 * All columns are varchar by default but can be changed in the import script ahead of the import
 * csv is also supported by editing the create_table.py script

### **aqls.sh**
A command-line wrapper script for arangodb that allows either readline quoted text or input file. Connection parameters are set in shell environment variables as follows:
* username      ARUSR default root
* password      ARPWD default lookup as key:pair from $HOME/.aqlpass file
* server-name   ARSVR default ar-server
* database-name ARDBN default _system

 For example, select five elements from the collection 'fullnodes':
`$ aqlx.sh 'for i in fullnodes limit 5 return i'`

 The same query using the script file 'test-script.aql':
`$ cat test-script.aql`
`for i in fullnodes`
`limit 5`
`return i`
`$ < test-script.aql aql.sh`

The output is in json pretty-printed using the 'jq' command-line tool https://stedolan.github.io/jq

### **aqlx.sh**
A command-line wrapper script for arangodb identical to 'aqls.sh' but without 'jq' pretty-print.

### **ar-env.sh**
A wrapper script to set the following shell environment parameters used by the aqls.sh and aqlx.sh arangodb wrapper scripts
* username      ARUSR default root
* password      ARPWD default lookup as key:pair from $HOME/.aqlpass file
* server-name   ARSVR default ar-server
* database-name ARDBN default _system

If the ARPWD password variable is not set, the script uses the 'jq' command-line tool https://stedolan.github.io/jq to lookup from a json format file in the $HOME/.aqlpass
`$ cat ~/.aqlpass`
`{"root": "dontbedaft", "nodeuser": "tryharder"}`

Notes: The key element is the use of the quadtree function in the visiblenodes function to quickly find nodes and is based on at least:
 * The excellent work of Mike Bostock in developing d3 (<https://bost.ocks.org/mike>)
 * Scott Murray's 'Interactive Data Visualization for the Web' (<http://alignedleft.com/work/d3-book>)
 * The Sumbera implementation 'Many points with d3 and leaflet' here <http://bl.ocks.org/sumbera/10463358>
 * OpenStreetMap data and maptiles (<https://www.openstreetmap.org>)
 * Leaflet javascript library (<http://leafletjs.com>)

### **add-x-tag.sh**
A wrapper script that applies a filter (default 'cat') and adds an arbitary xml tag (default "_wrapper") to an xml-file for use in a shell script. This allows large xml files to be split and inserted into a pipeline to allow for easier processing.

### **rmxmlns.sh**
A wrapper script that uses the `xsltproc` transformation `rmxmlns.xslt` to remove namespace information from an xml-file.

Assumptions
  * The xml tranformation `xsltproc` utility is installed

The `rmxmlns.sh` xslt transformation is based on the answer by "jasso" in the discussion stackoverflow discussoin <https://stackoverflow.com/questions/5268182/how-to-remove-namespaces-from-xml-using-xslt">.

   On an Debian base Linux version run:

  `$ sudo apt install xsltproc`

### **xml-to-ndjson.sh**
A wrapper script that transforms xml to ndjson files in a shell pipeline. The transformation takes pre-split temporary xml-file with an arbitrary wrapper xml-tag, applies the transformation using the `xml-to-json` script, and deletes the temporary file.

  * `jq` tool is installed (<https://stedolan.github.io/jq>)
  * `xml-to-json` utility is installed (<https://github.com/sinelaw/xml-to-json>)


text:
module Partitioner
  class Base
    def initialize(build, kochiku_yml)
      @build = build
      @kochiku_yml = kochiku_yml
    end

    def partitions
      [
        {
          'type' => 'test',
          'files' => ['no-manifest'],
          'queue' => @build.branch_record.convergence? ? 'ci' : 'developer',
          'retry_count' => 0
        }
      ]
    end

    def emails_for_commits_causing_failures
      {}
    end
  end
end


text:
"use strict";

var input  = document.getElementById("in"),
    output = document.getElementById("out"),
    settings = {
    	deflate        : document.getElementById("deflate"),
    	spaces         : document.getElementById("spaces"),
    	indent         : document.getElementById("indent"),
    	nlBracket      : document.getElementById("nlBracket"),
    	collapseBracket: document.getElementById("collapseBracket"),
    	collapsePrim   : document.getElementById("collapsePrim"),
    	trailingComma  : document.getElementById("trailingComma"),
    	sortType       : document.getElementById("sortType"),
    	sortAlpha      : document.getElementById("sortAlpha"),
    	quoteKeys      : document.getElementById("quoteKeys"),
    	quoteStrings   : document.getElementById("quoteStrings"),
    	quoteChoice    : document.getElementById("quoteChoice"),
    	boolChoice     : document.getElementById("boolChoice"),
    	capitalL       : document.getElementById("capitalL"),
    	capitalSuff    : document.getElementById("capitalSuff"),
    },
    parsedData,
    notes = [];

function updateSetting(item) {
	updateOutput();
	item = item instanceof Event ? this : item || this;
	localStorage.setItem(item.id, item.type === "checkbox" ? item.checked : item.value);
}

for (var name in settings) {
	var el = settings[name];
	el[el.type === "checkbox" ? "onclick" : "oninput"] = updateSetting;
}
indent.oninput = function() {
	updateSetting(this);
	var val = settings.indent.value;
	if (val.length === 1 && val >= "0" && val <= "8") {
		document.body.className = "tab-" + val;
	}
};

function loadSettings() {
	for (var name in settings) {
		var el = settings[name], val = localStorage.getItem(el.id);

		if (val !== null) {
			if (el.type === "checkbox") {
				el.checked = (val !== "false");
				el.onclick();
			} else {
				el.value = val;
				el.oninput();
			}
		}
	}
}
loadSettings();

function getNoteString() {
	if (notes.length === 0) {
		return "";
	} else {
		return notes.join("\n") + "\n\n";
	}
}

function validateNBT() {
	parsedData = undefined;
	notes = [];
	// If input starts with quotation mark, try unescaping JSON
	var text = input.value;
	while (/^\s*"/.test(text)) {
		notes.push("NOTE: Input looks like a JSON string and will be unescaped.");
		try {
			text = JSON.parse(text);
		} catch (e) {
			output.value = getNoteString() + "ERROR while unescaping JSON: " + e.message;
			return;
		}
		notes[notes.length - 1] = "NOTE: Input looked like a JSON string and was unescaped.";
	}
	try {
		parsedData = nbtlint.parse(text);
	} catch (e) {
		console.log(e);
		output.value = getNoteString() + e.message;
		if (e.suggestion) {
			output.value += "\n\n" + e.suggestion;
		}
		return;
	}
	updateOutput();
}
document.getElementById("go").onclick = function() {
	location.hash = "#" + input.value.replace(/[%\r\n\0]/g, function(m) {
		var esc = m.charCodeAt(0).toString(16);
		if (esc.length < 2) esc = "0" + esc;
		return "%" + esc;
	});
	validateNBT();
};

function updateOutput() {
	if (parsedData) {
		var sort = false;
		if (settings.sortAlpha.checked && settings.sortType.checked) {
			sort = nbtlint.compareTypeAlpha;
		} else if (settings.sortType.checked) {
			sort = nbtlint.compareType;
		} else if (settings.sortAlpha.checked) {
			sort = nbtlint.compareAlpha;
		}
		output.value = getNoteString();
		output.value += nbtlint.stringify(parsedData,
			(settings.spaces.checked
				? "        ".substr(0, +settings.indent.value)
				: "\t"),
			{
				nlBrackets      : settings.nlBracket.checked,
				collapseBrackets: settings.collapseBracket.checked,
				expandPrimitives: !settings.collapsePrim.checked,
				trailingComma   : settings.trailingComma.checked,
				sort            : sort,
				quoteKeys       : settings.quoteKeys.checked,
				unquoteStrings  : !settings.quoteStrings.checked,
				quoteChoice     : settings.quoteChoice.value,
				boolChoice      : settings.boolChoice.value,
				deflate         : settings.deflate.checked,
				capitalizeSuffix: {
					l: settings.capitalL.checked,
					default: settings.capitalSuff.checked,
				},
			});
	}
}

function loadLink() {
	var linkInput = decodeURIComponent(location.hash.substr(1));

	if (linkInput === input.value) {
		return;
	} else {
		input.value = linkInput;
	}

	if (input.value) {
		validateNBT();
	} else {
		output.value = "";
	}
}
window.onhashchange = document.onhashchange = loadLink;
loadLink();


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

package com.thoughtworks.selenium.webdriven.commands;

import com.thoughtworks.selenium.Wait;
import com.thoughtworks.selenium.webdriven.SeleneseCommand;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;

import java.util.logging.Logger;

public class WaitForPageToLoad extends SeleneseCommand<Void> {
  Logger log = Logger.getLogger(WaitForPageToLoad.class.getName());
  private int timeToWait = 250;

  /**
   * Overrides the default time to wait (in milliseconds) after a page has finished loading.
   *
   * @param timeToWait the time to wait, in milliseconds, after the page has finished loading
   */
  public void setTimeToWait(int timeToWait) {
    this.timeToWait = timeToWait;
  }

  @Override
  protected Void handleSeleneseCommand(final WebDriver driver, String timeout, String ignored) {
    // Wait until things look like they've been stable for "timeToWait"
    if (!(driver instanceof JavascriptExecutor)) {
      // Assume that we Do The Right Thing
      return null;
    }

    long timeoutInMillis = Long.parseLong(timeout);

    // Micro sleep before we continue in case an async click needs processing.
    hesitate(timeToWait);

    Object result;
    try {
      result = ((JavascriptExecutor) driver).executeScript(
          "return !!document['readyState'];");
    } catch (WebDriverException e) {
      // Page might still be loading. Give it a chance to get some content.
      hesitate(500);
      try {
        result = ((JavascriptExecutor) driver).executeScript(
            "return !!document['readyState'];");
      } catch (WebDriverException e2) {
        log.warning("Cannot determine whether page supports ready state. Abandoning wait.");
        return null;
      }
    }

    log.fine("Does browser support readyState: " + result);

    Wait wait = (result != null && (Boolean) result) ?
        getReadyStateUsingWait(driver) : getLengthCheckingWait(driver);

    wait.wait(String.format("Failed to load page within %s ms", timeout), timeoutInMillis);

    hesitate(timeToWait);

    return null;
  }

  private void hesitate(long duration) {
    try {
      Thread.sleep(duration);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }

  private Wait getReadyStateUsingWait(final WebDriver driver) {
    return new Wait() {
      @Override
      public boolean until() {
        try {
          Object result = ((JavascriptExecutor) driver).executeScript(
              "return 'complete' == document.readyState;");

          if (result instanceof Boolean && (Boolean) result) {
            return true;
          }
        } catch (Exception e) {
          // Possible page reload. Fine
        }
        return false;
      }
    };
  }

  public Wait getLengthCheckingWait(final WebDriver driver) {
    return new Wait() {
      private int length;
      private long seenAt;

      @Override
      public boolean until() {
        // Page length needs to be stable for a second
        try {
          int currentLength = driver.findElement(By.tagName("body")).getText().length();
          if (seenAt == 0) {
            seenAt = System.currentTimeMillis();
            length = currentLength;
            return false;
          }

          if (currentLength != length) {
            seenAt = System.currentTimeMillis();
            length = currentLength;
            return false;
          }

          return System.currentTimeMillis() - seenAt > 1000;
        } catch (NoSuchElementException | NullPointerException ignored) {
        }

        return false;
      }
    };
  }
}


text:
layout: post
title: Fat Ebony Babe Diamond Dior Gets Pleased By A Fat Black Cock
titleinfo: pornvd
desc: Watch Fat Ebony Babe Diamond Dior Gets Pleased By A Fat Black Cock. Pornhub is the ultimate xxx porn and sex site.
---

Fat Ebony Babe Diamond Dior Gets Pleased By A Fat Black Cock

Watch Fat Ebony Babe Diamond Dior Gets Pleased By A Fat Black Cock. Pornhub is the ultimate xxx porn and sex site.


text:
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <EditText
                android:id="@+id/search_edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:background="@drawable/bg_search"
                android:drawableStart="@drawable/ic_arrow_back"
                android:gravity="center_vertical"
                android:hint="@string/search_message"
                android:padding="5dp"
                android:textColor="@android:color/darker_gray"
                android:transitionName="@string/transition_name_search"/>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/message_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>


text:
package io.datalayer.kafka;

public enum KafkaQueue {
    QUEUE_TEST_1, //
    QUEUE_TEST_2
}


text:
<?php

namespace PhpOffice\PhpWord\Writer\ODText\Style;

/**
 * Image style writer
 *
 * @since 0.11.0
 */
class Image extends AbstractStyle
{
    /**
     * Write style.
     */
    public function write()
    {
        /** @var \PhpOffice\PhpWord\Style\Image $style Type hint */
        $style = $this->getStyle();
        if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
            return;
        }
        $xmlWriter = $this->getXmlWriter();

        $xmlWriter->startElement('style:style');
        $xmlWriter->writeAttribute('style:name', $style->getStyleName());
        $xmlWriter->writeAttribute('style:family', 'graphic');
        $xmlWriter->writeAttribute('style:parent-style-name', 'Graphics');
        $xmlWriter->startElement('style:graphic-properties');
        $xmlWriter->writeAttribute('style:vertical-pos', 'top');
        $xmlWriter->writeAttribute('style:vertical-rel', 'baseline');
        $xmlWriter->endElement(); // style:graphic-properties
        $xmlWriter->endElement(); // style:style
    }
}


text:
#include "FileListModel.hpp"
#include <QString>

FileListModel::FileListModel(QObject *parent)
{
    setParent(parent);
}

QList<QUrl> FileListModel::files() const
{
    QList<QUrl> fileList;
    for (int row = 0; row < size(); ++row)
        fileList << QUrl::fromLocalFile(value(row));

    return fileList;
}

void FileListModel::addFile(const QString &filePath, QString uuid)
{
    clear();
	const int pos = indexOf(filePath);
    if (pos != -1)
        return;

    QString newPath = filePath;
    int number = newPath.indexOf(".jpg") - newPath.indexOf("IMG");
    newPath.replace(newPath.indexOf("IMG"), number, uuid);

    QFile::copy(filePath, newPath);

    append(newPath);
    bb::system::InvokeManager iManager;
    bb::system::InvokeRequest request;
	// Who do we want to send the invoke request to?
	request.setTarget("com.split.view");
	// What do we want the target application to do with it?
	request.setAction("bb.action.VIEW");
	// What are we sending?
	request.setMimeType("image/jpeg");
	// Where is the data?
	request.setUri(QUrl("file://" +filePath));
	request.setData("");
	bb::system::InvokeTargetReply *reply = iManager.invoke(request);
	// Remember to take ownership of the reply object.
	reply->setParent(this);
	// Listen for the invoke response.

	// If any Q_ASSERT statement(s) indicate that the slot failed to connect to
	// the signal, make sure you know exactly why this has happened. This is not
	// normal, and will cause your app to stop working!!
	bool connectResult;

	// Since the variable is not used in the app, this is added to avoid a
	// compiler warning.
	Q_UNUSED(connectResult);

	connectResult =  QObject::connect(reply, SIGNAL(finished()),
									  this,  SLOT(onInvokeResult()));

	// This is only available in Debug builds.
	 Q_ASSERT(connectResult);

	// Store reply somewhere, so you can
	// access it when onInvokeResult fires.
	_invokeTargetReply = reply;
    emit changed();
}

void FileListModel::removeFile(const QString &filePath)
{
    const int pos = indexOf(filePath);
    if (pos == -1)
        return;

    removeAt(pos);
    emit changed();
}

// Because we connected this method to the finished() SIGNAL on the
// reply object, this method will be called when the application
// receives an invoke response.
void FileListModel::onInvokeResult()
{
    // Check for errors
    switch(_invokeTargetReply->error()) {
        // Invocation could not find the target
        // did we use the right target ID?
    case bb::system::InvokeReplyError::NoTarget: {
            qDebug() << "invokeFinished(): Error: no target";
            break;
        }
        // There was a problem with the invoke request
        // did we set all the values correctly?
    case bb::system::InvokeReplyError::BadRequest: {
    	qDebug() << "invokeFinished(): Error: bad request";
            break;
        }
        // Something went completely
        // wrong inside the invocation request
        // Find an alternate route :(
    case bb::system::InvokeReplyError::Internal: {
    	qDebug() << "invokeFinished(): Error: internal";
            break;
        }
        //Message received if the invoke request is successful
    default:
    	qDebug() << "invokeFinished(): Invoke Succeeded";
        break;
    }

    // A little house keeping never hurts...
    delete _invokeTargetReply;
}


text:
#include <aws/iot/model/ServerCertificateSummary.h>
#include <aws/core/utils/json/JsonSerializer.h>

#include <utility>

using namespace Aws::Utils::Json;
using namespace Aws::Utils;

namespace Aws
{
namespace IoT
{
namespace Model
{

ServerCertificateSummary::ServerCertificateSummary() :
    m_serverCertificateArnHasBeenSet(false),
    m_serverCertificateStatus(ServerCertificateStatus::NOT_SET),
    m_serverCertificateStatusHasBeenSet(false),
    m_serverCertificateStatusDetailHasBeenSet(false)
{
}

ServerCertificateSummary::ServerCertificateSummary(JsonView jsonValue) :
    m_serverCertificateArnHasBeenSet(false),
    m_serverCertificateStatus(ServerCertificateStatus::NOT_SET),
    m_serverCertificateStatusHasBeenSet(false),
    m_serverCertificateStatusDetailHasBeenSet(false)
{
  *this = jsonValue;
}

ServerCertificateSummary& ServerCertificateSummary::operator =(JsonView jsonValue)
{
  if(jsonValue.ValueExists("serverCertificateArn"))
  {
    m_serverCertificateArn = jsonValue.GetString("serverCertificateArn");

    m_serverCertificateArnHasBeenSet = true;
  }

  if(jsonValue.ValueExists("serverCertificateStatus"))
  {
    m_serverCertificateStatus = ServerCertificateStatusMapper::GetServerCertificateStatusForName(jsonValue.GetString("serverCertificateStatus"));

    m_serverCertificateStatusHasBeenSet = true;
  }

  if(jsonValue.ValueExists("serverCertificateStatusDetail"))
  {
    m_serverCertificateStatusDetail = jsonValue.GetString("serverCertificateStatusDetail");

    m_serverCertificateStatusDetailHasBeenSet = true;
  }

  return *this;
}

JsonValue ServerCertificateSummary::Jsonize() const
{
  JsonValue payload;

  if(m_serverCertificateArnHasBeenSet)
  {
   payload.WithString("serverCertificateArn", m_serverCertificateArn);

  }

  if(m_serverCertificateStatusHasBeenSet)
  {
   payload.WithString("serverCertificateStatus", ServerCertificateStatusMapper::GetNameForServerCertificateStatus(m_serverCertificateStatus));
  }

  if(m_serverCertificateStatusDetailHasBeenSet)
  {
   payload.WithString("serverCertificateStatusDetail", m_serverCertificateStatusDetail);

  }

  return payload;
}

} // namespace Model
} // namespace IoT
} // namespace Aws


text:
Bind server installation - Centos 64

## Overview

Install everything needed to run a bind service on ubuntu.  The goal is to make the installation co-exist with other playbooks.  THis is a rewrite of bind-playbook which was ubuntu centric.

## Installation

## Notes

This has been used as a learning tool for me to better know Ansible.


text:
import os
import sys
import foodblock
import random
import motko
import pygame
import logging
from common import timing_function
import argparse

@timing_function
def loadmotkos(path, amount, trainingloops, size, hiddenlayers, loadfromfile, test):
    loadedmotkos = []
    motkoslist = os.listdir(os.path.join(path, 'brains'))

    for k in range(len(motkoslist)):
        if(int(motkoslist[k].split('_')[1]) == trainingloops):
            motkoinstance = motko.motkowrapper(os.path.join(path, 'brains', motkoslist[k]), size, hiddenlayers, loadfromfile, test)
            motkoinstance.motkolive.setname(motkoslist[k])
            print("loading motko", motkoinstance.motkolive.getname())
            motkoinstance.motkolive.reinit()
            # if(test):
            #    os.remove(os.path.join(path, 'brains', motkoslist[k]))
            loadedmotkos.append(motkoinstance)
            if(len(loadedmotkos) >= amount):
                return loadedmotkos
    return loadedmotkos

class PyManMain:
    """The Main PyMan Class - This class handles the main
    initialization and creating of the Game."""

    @timing_function
    def __init__(self, test, noscreen, width=1024, height=768, foodamount=400, motkotamount=20):
        """Initialize"""
        self.cwd = os.getcwd()
        logging.basicConfig(filename=os.path.join(self.cwd, "pygame_main.log"), filemode='w', level=logging.INFO)
        logging.info("start main")
        self.gamescreen = True
        self.test = False
        self.motkotamount = motkotamount
        self.test = test
        if(noscreen):
            self.gamescreen = False
            print ("setted", sys.argv[1], self.gamescreen)
        if(test):
            self.gamescreen = False
            print ("setted", sys.argv[1], self.gamescreen)
            self.test = True
            self.motkotamount = 3
        if(self.gamescreen):
            pygame.init()
        self.BLACK = (0, 0, 0)
        self.WHITE = (255, 255, 255)
        self.BLUE = (0, 0, 255)
        self.GREEN = (0, 255, 0)
        self.RED = (255, 0, 0)
        self.RED2 = (242, 120, 120)
        self.PURB = (255, 0, 255)
        self.GRAY = (224, 224, 224)
        self.GRAY2 = (192, 192, 192)
        self.GRAY3 = (160, 160, 160)
        self.GRAY4 = (128, 128, 128)
        self.GRAY5 = (96, 96, 96)
        self.GRAY6 = (32, 32, 32)
        self.X = 0
        self.Y = 0
        self.width = width
        self.height = height
        self.foodamount = foodamount
        self.foodblocks = []
        self.trainingloops = 1
        self.hiddenlayers = 4
        self.SaveWhenTrained = 100
        # self.sleeptime = 0.1

        if(self.gamescreen):
            self.screen = pygame.display.set_mode((self.width, self.height))
            self.screen2 = pygame.display.set_mode((self.width, self.height))
            self.myfont = pygame.font.SysFont("monospace", 15)

        for i in range(self.foodamount):
            tempplace = [random.randint(0, self.width), random.randint(0, self.height)]
            fb = foodblock.foodblock(tempplace, [2, 2])
            # print (fb.getinfo())
            self.foodblocks.append(fb)
        self.cwd = os.getcwd()
        self.motkot = loadmotkos(self.cwd, self.motkotamount, self.trainingloops, [self.width, self.height], self.hiddenlayers, loadfromfile=True, test=self.test)

    @timing_function
    def MainLoop(self):
        """This is the Main Loop of the Game"""
        if(self.gamescreen):
            pygame.key.set_repeat(500, 30)
            self.background = pygame.Surface(self.screen.get_size())
            self.background = self.background.convert()
            self.background.fill((255, 255, 255))
        print ("mainloop testing %s motkos at same time" % (self.motkotamount))
        dontprintdata = False
        printsnapshotinfo = False
        last_steps = []
        self.FoodBlockID = [] * self.motkotamount
        for _ in range(self.motkotamount):
            self.FoodBlockID.append(None)
        print len(self.FoodBlockID)
        print len(self.motkot)
        printmotko = 99
        # deletemotkoindex = []

        while 1:
            # loopStart = datetime.datetime.fromtimestamp(time.mktime(time.gmtime()))
            if(self.gamescreen):
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        sys.exit()
                    elif event.type == pygame.KEYDOWN:
                        if (event.key == pygame.K_RIGHT):
                            dontprintdata = False
                        elif (event.key == pygame.K_LEFT):
                            dontprintdata = True
                        elif (event.key == pygame.K_UP):
                            printsnapshotinfo = True
                        elif (event.key == pygame.K_DOWN):
                            printmotko = 99
                        elif (event.key == pygame.K_1):
                            printmotko = 1
                        elif (event.key == pygame.K_2):
                            printmotko = 2
                        elif (event.key == pygame.K_3):
                            printmotko = 3
                        elif (event.key == pygame.K_4):
                            printmotko = 4
                        elif (event.key == pygame.K_5):
                            printmotko = 5
                        elif (event.key == pygame.K_6):
                            printmotko = 6
                        elif (event.key == pygame.K_7):
                            printmotko = 7
                        elif (event.key == pygame.K_8):
                            printmotko = 8
                        elif (event.key == pygame.K_9):
                            printmotko = 9
                        elif (event.key == pygame.K_0):
                            printmotko = 0
            for k in range(len(self.motkot) - 1, -1, -1):
                # print (self.motkot[k].motkolive.returnname())
                status = self.motkot[k].motkolive.areyouallive()
                if status[0] == "dood" or status[0] == "viable NN":
                    last_steps = self.motkot[k].motkolive.getliveinfo()
                    self.motkot[k].setNotViable()
                    print ("!:", self.motkot[k].motkolive.getname(), status, self.motkot[k].motkolive.getliveinfo())
                    # print (self.motkot[k].motkolive.nn.inspect())
                    del self.motkot[k]
                # for i in range(len(self.motkot) - 1, -1, -1):
                # if (self.motkot[k].motkolive.collision([self.motkot[k].motkolive.X, self.motkot[k].motkolive.Y], [self.motkot[k].motkolive.size, self.motkot[k].motkolive.size]) == 1):
                # print("kill or sex or flee?")
            textplaceY = 0

            for k in range(len(self.motkot)):
                # self.motkot[k].motkolive.addfoodavail(0.001)
                for i in range(len(self.motkot[k].motkolive.shadow)):
                    if(self.gamescreen):
                        pygame.draw.rect(self.screen, [255 - (i * 2), 255 - (i * 2), 255 - (i * 2)], [self.motkot[k].motkolive.shadow[i][0], self.motkot[k].motkolive.shadow[i][1], 2, 2], 0)
                # print ("check food bloks")
                for i in range(len(self.foodblocks)):
                    if self.foodblocks[i].collision([self.motkot[k].motkolive.X, self.motkot[k].motkolive.Y], [self.motkot[k].motkolive.size, self.motkot[k].motkolive.size]) == 1:
                        self.motkot[k].motkolive.addfoodavail(self.foodblocks[i].returnfoodamount(), self.foodblocks[i].colornumber)
                        self.FoodBlockID[k] = i
                    if(self.foodblocks[i].collision([self.motkot[k].motkolive.eyeleftplace[0], self.motkot[k].motkolive.eyeleftplace[1]], self.motkot[k].motkolive.eyesightsizeleft) == 1):
                        self.motkot[k].motkolive.foodleft(self.foodblocks[i].returnfoodamount())
                        # print ("left hit!")
                    if(self.foodblocks[i].collision([self.motkot[k].motkolive.eyerightplace[0], self.motkot[k].motkolive.eyerightplace[1]], self.motkot[k].motkolive.eyesightsizeright) == 1):
                        self.motkot[k].motkolive.foodright(self.foodblocks[i].returnfoodamount())
                        # print ("right hit!")

                if(printmotko != 99):
                    dontprintdata = False
                    if(k == printmotko):
                        self.motkot[k].motkolive.live(True, test=self.test)
                    else:
                        self.motkot[k].motkolive.live(False, test=self.test)
                else:
                    self.motkot[k].motkolive.live(dontprintdata, test=self.test)
                didoueat = self.motkot[k].motkolive.didoueat()
                if(len(self.FoodBlockID) > 0):
                    if(didoueat > 0 and self.FoodBlockID[k] is not None):
                        self.foodblocks[self.FoodBlockID[k]].calculateFoodamount(didoueat)
                        if (self.foodblocks[self.FoodBlockID[k]].foodamount <= 0.01):
                            del self.foodblocks[self.FoodBlockID[k]]
                            tempplace = [random.randint(0, self.width), random.randint(0, self.height)]
                            newfb = foodblock.foodblock(tempplace, [2, 2])
                            self.FoodBlockID[k] = None
                            self.foodblocks.append(newfb)

                if(self.motkot[k].motkolive.trainings == self.SaveWhenTrained):
                    name = "%s_%s_%s.%d.pkl" % (self.motkot[k].motkolive.filename.split('_')[0], self.SaveWhenTrained, self.motkot[k].motkolive.filename.split('_')[2])
                    self.motkot[k].saveNNwithname(name)
                    self.SaveWhenTrained += 100
                    print("Saving {} with errorcount {}".format(name, self.motkot[k].motkolive.currenterror))

                if(printsnapshotinfo):
                    print(self.motkot[k].motkolive.getliveinfo2())

                if(self.gamescreen):
                    pygame.draw.rect(self.screen, self.motkot[k].motkolive.color, [self.motkot[k].motkolive.X, self.motkot[k].motkolive.Y, self.motkot[k].motkolive.size, self.motkot[k].motkolive.size], 0)
                    pygame.draw.rect(self.screen, self.motkot[k].motkolive.color, [self.motkot[k].motkolive.eyeleftplace[0], self.motkot[k].motkolive.eyeleftplace[1], self.motkot[k].motkolive.eyesightsizeleft[0], self.motkot[k].motkolive.eyesightsizeleft[1]], 1)
                    pygame.draw.rect(self.screen, self.motkot[k].motkolive.color, [self.motkot[k].motkolive.eyerightplace[0], self.motkot[k].motkolive.eyerightplace[1], self.motkot[k].motkolive.eyesightsizeright[0], self.motkot[k].motkolive.eyesightsizeright[1]], 1)
                    if (len(self.motkot) < 6):
                        coretext = self.myfont.render(str(self.motkot[k].motkolive.getliveinfo()), 1, (0, 0, 0), (255, 255, 255))
                        self.screen.blit(coretext, (0, textplaceY))
                        textplaceY += 15
                # else:
                    # print(self.motkot[k].motkolive.getliveinfo())
            for i in range(len(self.foodblocks)):
                if(self.gamescreen):
                    pygame.draw.rect(self.screen, self.foodblocks[i].color, [self.foodblocks[i].X, self.foodblocks[i].Y, self.foodblocks[i].getSize1(), self.foodblocks[i].getSize2()], 0)

            if(self.gamescreen):
                for i in range(0, self.width, 25):
                    for k in range(0, self.height, 25):
                        pygame.draw.rect(self.screen, self.GRAY, [i, k, 1, 1], 1)

            # pygame.draw.rect(self.screen, self.GREEN, [self.X, self.Y, 5, 5], 0)
            if(self.gamescreen):
                pygame.display.flip()
                self.screen.blit(self.background, (0, 0))
                # oopStop = datetime.datetime.fromtimestamp(time.mktime(time.gmtime()))
                # delta = loopStop - loopStart
                # print (self.sleeptime, delta.total_seconds(), (delta.total_seconds()/1000), delta, (self.sleeptime-(delta.total_seconds()/1000)))
                # time.sleep(self.sleeptime-(delta.total_seconds()/1000))
                # time.sleep(self.sleeptime)
            if (len(self.motkot) == 0):
                if(len(last_steps) > 2):
                    print ("last motko: ", last_steps[1], "trained:", last_steps[1].split('_')[1], "times, steps taken", last_steps[2], last_steps[0])
                    last_steps = []
                self.trainingloops += 1
                self.motkot = loadmotkos(self.cwd, self.motkotamount, self.trainingloops, [self.width, self.height], self.hiddenlayers, loadfromfile=True, test=self.test)

            if(self.trainingloops > 1000000):  # i think that is enought
                break
            if(self.test and self.trainingloops > 1000):
                break
            printsnapshotinfo = False

if __name__ == "__main__":
    logging.basicConfig(filename="pygame_main.log", format='%(asctime)s:%(levelname)s:%(message)s', level=logging.INFO)
    logging.info("pygame_main start")
    parser = argparse.ArgumentParser()
    parser.add_argument("--test", help="run testrun", action="store_true")
    parser.add_argument("--width", help="Width of the world, default 1024", default=1024, type=int)
    parser.add_argument("--height", help="Height of the world, default 768", default=768, type=int)
    parser.add_argument("--foodamount", help="food amount in world, default 400", default=400, type=int)
    parser.add_argument("--motkotamount", help="How many motkos you have in your world, default 3", default=3, type=int)
    parser.add_argument("--noscreen", help="run headles", action="store_true")
    args = parser.parse_args()
    logging.info(args)
    MainWindow = PyManMain(test=args.test, width=args.width, height=args.height, foodamount=args.foodamount, motkotamount=args.motkotamount, noscreen=args.noscreen)
    MainWindow.MainLoop()


text:
namespace Lunchorder.Domain.Dtos
{
    /// <summary>
    /// Represents the profile of the user
    /// </summary>
    public class UserProfile
    {
        /// <summary>
        /// First name of the user
        /// </summary>
        public string FirstName { get; set; }

        /// <summary>
        /// Last name of the user
        /// </summary>
        public string LastName { get; set; }

        /// <summary>
        /// Picture of the user (url)
        /// </summary>
        public string Picture { get; set; }

        /// <summary>
        /// The UI culture of the user
        /// </summary>
        public string Culture { get; set; }
    }
}


text:
set(DOCUMENTATION "This module contains classes to simulate and
evaluate noise. These classes were originally contributed via the
Insight Journal (https://hdl.handle.net/10380/3158).")

itk_module(ITKImageNoise
  COMPILE_DEPENDS
    ITKStatistics
  TEST_DEPENDS
    ITKTestKernel
  DESCRIPTION
    "${DOCUMENTATION}"
)


text:
  My Profile

  Edit Profile

{{Get_Data.data.player.player[0].first_name}} {{Get_Data.data.player.player[0].last_name}}

 Denver, CO

About Me:

{{Get_Data.data.player.player[0].tagline}}

{{Get_Data.data.player.player[0].availability | availability}}


text:
import {
    DocsAction,
    DocsActionContent,
    DocsActionTargetType,
    DocsAction_action,
    DocsAction_request,
    DocsContent,
    DocsDescription,
    DocsNegativeNote,
    DocsSection,
} from "./data"

export function docsSection(title: string, body: DocsContent[]): DocsSection {
    return { type: "normal", title, body }
}
export function docsSection_pending(title: string, body: DocsContent[]): DocsSection {
    return { type: "pending", title, body }
}
export function docsSection_double(title: string, body: DocsContent[]): DocsSection {
    return { type: "double", title, body }
}

export function docsPurpose(content: string[]): DocsContent {
    return { type: "purpose", content }
}
export function docsModule(content: string[]): DocsContent {
    return { type: "module", content }
}
export function docsItem(title: string, content: string[]): DocsContent {
    return { type: "item", title, content }
}
export function docsDescription(content: DocsDescription[]): DocsContent {
    return { type: "description", content }
}
export function docsExplanation(target: DocsActionTargetType[]): DocsContent {
    return { type: "explanation", target }
}
export function docsNegativeNote(content: DocsNegativeNote[]): DocsContent {
    return { type: "negativeNote", content }
}
export function docsAction(content: { (factory: DocsActionFactory): DocsAction[] }): DocsContent {
    return { type: "action", content: content({ request, action, message, validate }) }

    function request(content: DocsAction_request): DocsAction {
        return { type: "request", content }
    }
    function action(content: DocsAction_action): DocsAction {
        return { type: "action", content }
    }
    function message(messages: string[]): DocsActionContent[] {
        return messages.map((message) => ({ type: "normal", message }))
    }
    function validate(messages: string[]): DocsActionContent[] {
        return messages.map((message) => ({ type: "validate", message }))
    }
}
export function docsNote(content: string[]): DocsContent {
    return { type: "note", content }
}

export interface DocsActionFactory {
    request(content: DocsAction_request): DocsAction
    action(content: DocsAction_action): DocsAction
    message(messages: string[]): DocsActionContent[]
    validate(messages: string[]): DocsActionContent[]
}


text:
Simple sbt project to demonstrate how to create and pack sbt project with [sbt-pack plugin](https://github.com/xerial/sbt-pack)

For cross building add + before sbt command:

```
+ package
+ publish
+ compile
+ test
```


text:
<?php

namespace MyAllocator\phpsdk\src\Exception;

/**
 * The API exception class. The generic API exception used during validation,
 * request, and response flows.
 */
class ApiException extends MaException
{
}


text: sudo apt-get install --only-upgrade python-django=1.7.11-1+deb8u1 -y


text:
Cli Client
==========

Use hurl as a simple curl-like interface to work with endpoints that are protected by this jersey-hmac-auth module.

Usage
-----

```
export PATH=~/work/jersey-hmac-auth/cli:$PATH
hurl --apiKey somekey --secretKey somesecret URL
```

```
hurl -h
usage: hurl [-h] [-X {GET,POST}] --apiKey APIKEY --secretKey SECRETKEY [-v] [--data DATA] url

Like curl, for hmac-protected resources

configuration:

 hurl can be configured to use the auth parms in multiple ways:
  * environment variables HURL_APIKEY & HURL_SECRET
  * file ~/.hurl/default.conf containing these two params
        apiKey <api key>
        secret <secret key>
  * runtime arguments (see optional arguments below)

positional arguments:
  url

optional arguments:
  --configure            configure api key & secret key for current session
  -h, --help             show this help message and exit
  -X {GET,POST}, --request {GET,POST}
                         GET (default) or POST (default: GET)
  --apiKey APIKEY
  --secretKey SECRETKEY
  -v, --verbose          Prints additional information to stderr (default: false)
  --data DATA, --data-binary DATA
                         The data to use in a POST (or @filename for a file full of data)
```


text:
package com.github.tomaszglinski.acropyga.metadata.parsing;

/**
 * Interface for classes, that parse out metadata from property comment.
 *
 * @author Tomasz Glinski
 */
public interface SinglePropertyMetadataParser {

    String getMetadataId();

    /**
     * @param comment
     *            comment to be parsed
     * @return null if no metadata found or filled transport object
     */
    SinglePropertyMetadataParserResult parse(String comment);
}


text:
package com.morgan.server.mtg;

/**
 * The rarities of a card.
 *
 * @author mark@mark-morgan.net (Mark Morgan)
 */
public enum Rarity {

  UNCOMMON,
  RARE,
  BASIC_LAND,
  SPECIAL,
  MYTHIC_RARE,
  COMMON;
}


text:
import json
import pytest

import loginsightwebhookdemo.servicenow

import conftest

# IMPORTANT: The service now account leveraged below
# hibernates after 6 hours of inactivity and is reclaimed
# if not used at least once every 10 days. A new URL can
# be generated as needed using the provided credentials.
# More information here: https://community.servicenow.com/community/develop/blog/2016/05/26/hibernation-and-developer-instances
#
# You can tell that hibernation/reclaimation has happened
# when the third test fails with '200 OK'.
#
# Given this, tox is configured to ignore testing SNOW.
# Please run pytest manually whenever changing the SNOW shim.
URL = 'https://dev18597.service-now.com'
USER = 'admin'
PASSWORD = 'L0g1ns1ght!'

BADPASSWORD = 'changeme'

@pytest.mark.parametrize("url,user,password,post,data,expected", [
    (None, None, None, '/endpoint/servicenow', conftest.payload, '500 INTERNAL SERVER ERROR'),
    (None, None, None, '/endpoint/servicenow/', conftest.payload, '404 NOT FOUND'),
    (URL, USER, BADPASSWORD, '/endpoint/servicenow', conftest.payload, '401 UNAUTHORIZED'),
    (URL, USER, PASSWORD, '/endpoint/servicenow', conftest.payload, '201 CREATED'),
    (URL, USER, PASSWORD, '/endpoint/servicenow', conftest.payloadvROps60, '201 CREATED'),
    (URL, USER, PASSWORD, '/endpoint/servicenow', conftest.payloadLI_test, '200 OK'),
])
def test_servicenow(url, user, password, post, data, expected):
    if url is not None:
        loginsightwebhookdemo.servicenow.SERVICENOWURL = url
    if user is not None:
        loginsightwebhookdemo.servicenow.SERVICENOWUSER = user
    if password is not None:
        loginsightwebhookdemo.servicenow.SERVICENOWPASS = password
    rsp = conftest.client.post(post, data=data, content_type="application/json")
    assert rsp.status == expected

def test_servicenow_e2e():
    headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
    url = URL + '/incident.do?JSONv2&sysparm_query=active=true^short_description=Hello World'
    sys_id = json.loads(loginsightwebhookdemo.callapi(url, 'get', None, headers, (USER, PASSWORD)))['records'][0]['sys_id']
    url = URL + '/incident.do?JSONv2&sysparm_query=active=true^short_description=<None>'
    sys_id2 = json.loads(loginsightwebhookdemo.callapi(url, 'get', None, headers, (USER, PASSWORD)))['records'][0]['sys_id']
    ids = [sys_id, sys_id2]

    url = URL + '/sys_journal_field.do?JSONv2&sysparm_query=element_id=' + sys_id
    records = json.loads(loginsightwebhookdemo.callapi(url, 'get', None, headers, (USER, PASSWORD)))
    assert 'You can view this alert by clicking' in json.dumps(records)
    assert 'hello world 1' in json.dumps(records)

    payload = {"incident_state": "7"}
    for incident_id in ids:
        url = URL + '/api/now/table/incident/' + incident_id
        loginsightwebhookdemo.callapi(url, 'put', json.dumps(payload), headers, (USER, PASSWORD))
    url = URL + '/incident.do?JSONv2&sysparm_query=sys_id=' + sys_id
    result = json.loads(loginsightwebhookdemo.callapi(url, 'get', None, headers, (USER, PASSWORD)))['records'][0]['active']
    assert result == 'false'