text:
#include "vglyph-data-surface.h"
#include "vglyph-rgba-uint-format.h"
#include "vglyph-rgba-uint-data-render.h"
#include "vglyph-rgba-little-uint-data-render.h"
#include "vglyph-rgba-uint16-data-render.h"
#include "vglyph-rgba-uint32-data-render.h"
#include "vglyph-type.h"
#include "vglyph-glyph.h"
#include "vglyph-figure.h"
#include "vglyph-transform.h"
#include "vglyph-segment-types.h"

static vglyph_point_t*
_vglyph_data_surface_offset_point(vglyph_point_t* result,
                                  vglyph_data_surface_t* surface,
                                  vglyph_bool_t relative,
                                  const vglyph_point_t* prev_point)
{
    result->x *= surface->base.width  << surface->shift_mulitsampling;
    result->y *= surface->base.height << surface->shift_mulitsampling;

    if (relative)
    {
        result->x += prev_point->x;
        result->y += prev_point->y;
    }

    return result;
}

static vglyph_state_t
_vglyph_data_surface_moveto(vglyph_data_surface_t* surface,
                            const vglyph_segment_moveto_t* segment,
                            const vglyph_matrix_t* matrix,
                            vglyph_bool_t relative,
                            vglyph_vector_t* points,
                            vglyph_point_t* prev_point)
{
    vglyph_point_t point = segment->point;
    _vglyph_data_surface_offset_point(&point, surface, relative, prev_point);
    *prev_point = point;

    return _vglyph_data_surface_add_point(points, matrix, &point);
}

static vglyph_state_t
_vglyph_data_surface_lineto(vglyph_data_surface_t* surface,
                            const vglyph_segment_lineto_t* segment,
                            const vglyph_matrix_t* matrix,
                            vglyph_bool_t relative,
                            vglyph_vector_t* points,
                            vglyph_point_t* prev_point)
{
    vglyph_point_t point = segment->point;
    _vglyph_data_surface_offset_point(&point, surface, relative, prev_point);
    *prev_point = point;

    return _vglyph_data_surface_add_point(points, matrix, &point);
}

static vglyph_state_t
_vglyph_data_surface_curveto_cubic(vglyph_data_surface_t* surface,
                                   const vglyph_segment_curveto_cubic_t* segment,
                                   const vglyph_matrix_t* matrix,
                                   vglyph_bool_t relative,
                                   vglyph_vector_t* points,
                                   vglyph_point_t* prev_point,
                                   vglyph_point_t* control_point)
{
    vglyph_state_t state = VGLYPH_STATE_SUCCESS;

    vglyph_point_t start  = *prev_point;
    vglyph_point_t end    = segment->point;
    vglyph_point_t point1 = segment->point1;
    vglyph_point_t point2 = segment->point2;

    _vglyph_data_surface_offset_point(&end,    surface, relative, prev_point);
    _vglyph_data_surface_offset_point(&point1, surface, relative, prev_point);
    _vglyph_data_surface_offset_point(&point2, surface, relative, prev_point);

    *prev_point = end;
    *control_point = point2;

    const vglyph_float32_t length =
        _vglyph_figure_get_cubic_bezier_length(&start, &point1, &point2, &end);

    const vglyph_float32_t dt = 1.0f / length * 4.0f;

    vglyph_point_t old_point = start;
    vglyph_point_t new_point;
    vglyph_point_t vec;

    for (vglyph_float32_t t = dt; t < 1.0f; t += dt)
    {
        _vglyph_figure_cubic_bezier(&new_point, &start, &point1, &point2, &end, t);
        _vglyph_point_sub(&vec, &new_point, &old_point);

        if (_vglyph_point_length_square(&vec) < 1.0f)
            continue;

        state = _vglyph_data_surface_add_point(points, matrix, &new_point);
        old_point = new_point;

        if (state != VGLYPH_STATE_SUCCESS)
            return state;
    }

    state = _vglyph_data_surface_add_point(points, matrix, &end);
    return state;
}

static vglyph_state_t
_vglyph_data_surface_curveto_quadratic(vglyph_data_surface_t* surface,
                                       const vglyph_segment_curveto_quadratic_t* segment,
                                       const vglyph_matrix_t* matrix,
                                       vglyph_bool_t relative,
                                       vglyph_vector_t* points,
                                       vglyph_point_t* prev_point,
                                       vglyph_point_t* control_point)
{
    vglyph_state_t state = VGLYPH_STATE_SUCCESS;

    vglyph_point_t start  = *prev_point;
    vglyph_point_t end    = segment->point;
    vglyph_point_t point1 = segment->point1;

    _vglyph_data_surface_offset_point(&end,    surface, relative, prev_point);
    _vglyph_data_surface_offset_point(&point1, surface, relative, prev_point);

    *prev_point = end;
    *control_point = point1;

    const vglyph_float32_t length =
        _vglyph_figure_get_quadratic_bezier_length(&start, &point1, &end);

    const vglyph_float32_t dt = 1.0f / length * 4.0f;

    vglyph_point_t old_point = start;
    vglyph_point_t new_point;
    vglyph_point_t vec;

    for (vglyph_float32_t t = dt; t < 1.0f; t += dt)
    {
        _vglyph_figure_quadratic_bezier(&new_point, &start, &point1, &end, t);
        _vglyph_point_sub(&vec, &new_point, &old_point);

        if (_vglyph_point_length_square(&vec) < 1.0f)
            continue;

        state = _vglyph_data_surface_add_point(points, matrix, &new_point);
        old_point = new_point;

        if (state != VGLYPH_STATE_SUCCESS)
            return state;
    }

    state = _vglyph_data_surface_add_point(points, matrix, &end);
    return state;
}

static vglyph_state_t
_vglyph_data_surface_arc(vglyph_data_surface_t* surface,
                         const vglyph_segment_arc_t* segment,
                         const vglyph_matrix_t* matrix,
                         vglyph_bool_t relative,
                         vglyph_vector_t* points,
                         vglyph_point_t* prev_point)
{
    if (segment->radius.x == 0.0f || segment->radius.y == 0.0f)
    {
        vglyph_segment_lineto_t line_segment;
        line_segment.point = segment->point;

        return _vglyph_data_surface_lineto(surface, &line_segment, matrix, relative, points, prev_point);
    }

    const vglyph_float32_t width  = (vglyph_float32_t)(surface->base.width  << surface->shift_mulitsampling);
    const vglyph_float32_t height = (vglyph_float32_t)(surface->base.height << surface->shift_mulitsampling);

    vglyph_state_t state = VGLYPH_STATE_SUCCESS;

    vglyph_point_t   radius;
    vglyph_point_t   center;
    vglyph_float32_t cos_fi;
    vglyph_float32_t sin_fi;
    vglyph_float32_t theta_0;
    vglyph_float32_t theta_d;

    vglyph_point_t start = *prev_point;
    vglyph_point_t end   = segment->point;

    _vglyph_data_surface_offset_point(&end, surface, relative, prev_point);
    *prev_point = end;

    start.x /= width;
    start.y /= height;

    end.x /= width;
    end.y /= height;

    _vglyph_figure_get_arc_params(&radius,
                                  &center,
                                  &cos_fi,
                                  &sin_fi,
                                  &theta_0,
                                  &theta_d,
                                  &start,
                                  &end,
                                  &segment->radius,
                                  _vglyph_degree_to_radians(segment->angle),
                                  segment->large_arc_flag,
                                  segment->sweep_flag);

    vglyph_point_t radius_screen = radius;
    vglyph_point_t center_screen = center;

    _vglyph_point_from_coord(&radius_screen, radius.x * width, radius.y * height);
    _vglyph_point_from_coord(&center_screen, center.x * width, center.y * height);

    const vglyph_float32_t length = _vglyph_figure_get_arc_length(&radius_screen,
                                                                  &center_screen,
                                                                  cos_fi,
                                                                  sin_fi,
                                                                  theta_0,
                                                                  theta_d);

    const vglyph_uint32_t count_part = (vglyph_uint32_t)ceilf(length * 0.5f) - 1;
    const vglyph_float32_t dt = theta_d / count_part;

    vglyph_float32_t theta;
    vglyph_point_t   point;

    vglyph_matrix_t transform;
    _vglyph_matrix_scale(&transform, matrix, width, height);

    for (vglyph_uint32_t part = 1; part < count_part; ++part)
    {
        theta = theta_0 + dt * part;

        _vglyph_figure_arc(&point, &radius, &center, cos_fi, sin_fi, theta);

        state = _vglyph_data_surface_add_point(points, &transform, &point);

        if (state != VGLYPH_STATE_SUCCESS)
            return state;
    }

    state = _vglyph_data_surface_add_point(points, matrix, prev_point);
    return state;
}

static vglyph_state_t
_vglyph_data_surface_lineto_horizontal(vglyph_data_surface_t* surface,
                                       const vglyph_segment_lineto_horizontal_t* segment,
                                       const vglyph_matrix_t* matrix,
                                       vglyph_bool_t relative,
                                       vglyph_vector_t* points,
                                       vglyph_point_t* prev_point)
{
    vglyph_segment_lineto_t line_segment;

    _vglyph_point_from_coord(&line_segment.point,
                             segment->x,
                             relative ? 0.0f : prev_point->y);

    return _vglyph_data_surface_lineto(surface, &line_segment, matrix, relative, points, prev_point);
}

static vglyph_state_t
_vglyph_data_surface_lineto_vertical(vglyph_data_surface_t* surface,
                                     const vglyph_segment_lineto_vertical_t* segment,
                                     const vglyph_matrix_t* matrix,
                                     vglyph_bool_t relative,
                                     vglyph_vector_t* points,
                                     vglyph_point_t* prev_point)
{
    vglyph_segment_lineto_t line_segment;

    _vglyph_point_from_coord(&line_segment.point,
                             relative ? 0.0f : prev_point->x,
                             segment->y);

    return _vglyph_data_surface_lineto(surface, &line_segment, matrix, relative, points, prev_point);
}

static vglyph_state_t
_vglyph_data_surface_curveto_cubic_smooth(vglyph_data_surface_t* surface,
                                          const vglyph_segment_curveto_cubic_smooth_t* segment,
                                          const vglyph_matrix_t* matrix,
                                          vglyph_bool_t relative,
                                          vglyph_vector_t* points,
                                          vglyph_point_t* prev_point,
                                          vglyph_point_t* control_point)
{
    vglyph_point_t v;

    if (control_point->x != control_point->x)
        _vglyph_point_from_coord(&v, 0.0f, 0.0f);
    else
        _vglyph_point_sub(&v, prev_point, control_point);

    if (!relative)
        _vglyph_point_add(&v, prev_point, &v);

    v.x /= surface->base.width  << surface->shift_mulitsampling;
    v.y /= surface->base.height << surface->shift_mulitsampling;

    vglyph_segment_curveto_cubic_t cubic_segment;
    cubic_segment.point  = segment->point;
    cubic_segment.point1 = v;
    cubic_segment.point2 = segment->point2;

    return _vglyph_data_surface_curveto_cubic(surface,
                                              &cubic_segment,
                                              matrix,
                                              relative,
                                              points,
                                              prev_point,
                                              control_point);
}

static vglyph_state_t
_vglyph_data_surface_curveto_quadratic_smooth(vglyph_data_surface_t* surface,
                                              const vglyph_segment_curveto_quadratic_smooth_t* segment,
                                              const vglyph_matrix_t* matrix,
                                              vglyph_bool_t relative,
                                              vglyph_vector_t* points,
                                              vglyph_point_t* prev_point,
                                              vglyph_point_t* control_point)
{
    vglyph_point_t v;

    if (control_point->x != control_point->x)
        _vglyph_point_from_coord(&v, 0.0f, 0.0f);
    else
        _vglyph_point_sub(&v, prev_point, control_point);

    if (!relative)
        _vglyph_point_add(&v, prev_point, &v);

    v.x /= surface->base.width  << surface->shift_mulitsampling;
    v.y /= surface->base.height << surface->shift_mulitsampling;

    vglyph_segment_curveto_quadratic_t quadratic_segment;
    quadratic_segment.point  = segment->point;
    quadratic_segment.point1 = v;

    return _vglyph_data_surface_curveto_quadratic(surface,
                                                  &quadratic_segment,
                                                  matrix,
                                                  relative,
                                                  points,
                                                  prev_point,
                                                  control_point);
}

static vglyph_state_t
_vglyph_data_surface_segment_to_lines(vglyph_data_surface_t* surface,
                                      vglyph_segment_t segment_type,
                                      const void* segment,
                                      const vglyph_matrix_t* matrix,
                                      vglyph_vector_t* points,
                                      vglyph_bool_t* path_closed,
                                      vglyph_point_t* start_point,
                                      vglyph_point_t* prev_point,
                                      vglyph_point_t* control_point)
{
    vglyph_state_t state = VGLYPH_STATE_SUCCESS;

    if (*path_closed && (segment_type != VGLYPH_SEGMENT_MOVETO_ABS &&
                         segment_type != VGLYPH_SEGMENT_MOVETO_REL))
    {
        *path_closed = FALSE;
        *start_point = *prev_point;

        if ((state = _vglyph_data_surface_add_point(points, matrix, prev_point)) != VGLYPH_STATE_SUCCESS)
            return state;
    }

    switch (segment_type)
    {
        case VGLYPH_SEGMENT_CLOSEPATH:
            if (!(*path_closed))
            {
                *path_closed = TRUE;

                if (prev_point->x != start_point->x ||
                    prev_point->y != start_point->y)
                {
                    prev_point = start_point;
                    state = _vglyph_data_surface_add_point(points, matrix, start_point);

                    if (state != VGLYPH_STATE_SUCCESS)
                        return state;
                }

                vglyph_point_t end_marker;
                _vglyph_point_from_coord(&end_marker, NAN, NAN);

                return _vglyph_data_surface_add_point(points, matrix, &end_marker);
            }
            break;

        case VGLYPH_SEGMENT_MOVETO_ABS:
        case VGLYPH_SEGMENT_MOVETO_REL:
            state = _vglyph_data_surface_moveto(surface,
                                                (vglyph_segment_moveto_t*)segment,
                                                matrix,
                                                segment_type - VGLYPH_SEGMENT_MOVETO_ABS,
                                                points,
                                                prev_point);

            if (*path_closed)
            {
                *path_closed = FALSE;
                *start_point = *prev_point;
            }
            break;

        case VGLYPH_SEGMENT_LINETO_ABS:
        case VGLYPH_SEGMENT_LINETO_REL:
            return _vglyph_data_surface_lineto(surface,
                                               (vglyph_segment_lineto_t*)segment,
                                               matrix,
                                               segment_type - VGLYPH_SEGMENT_LINETO_ABS,
                                               points,
                                               prev_point);

        case VGLYPH_SEGMENT_CURVETO_CUBIC_ABS:
        case VGLYPH_SEGMENT_CURVETO_CUBIC_REL:
            return _vglyph_data_surface_curveto_cubic(surface,
                                                      (vglyph_segment_curveto_cubic_t*)segment,
                                                      matrix,
                                                      segment_type - VGLYPH_SEGMENT_CURVETO_CUBIC_ABS,
                                                      points,
                                                      prev_point,
                                                      control_point);

        case VGLYPH_SEGMENT_CURVETO_QUADRATIC_ABS:
        case VGLYPH_SEGMENT_CURVETO_QUADRATIC_REL:
            return _vglyph_data_surface_curveto_quadratic(surface,
                                                          (vglyph_segment_curveto_quadratic_t*)segment,
                                                          matrix,
                                                          segment_type - VGLYPH_SEGMENT_CURVETO_QUADRATIC_ABS,
                                                          points,
                                                          prev_point,
                                                          control_point);
            break;

        case VGLYPH_SEGMENT_ARC_ABS:
        case VGLYPH_SEGMENT_ARC_REL:
            return _vglyph_data_surface_arc(surface,
                                            (vglyph_segment_arc_t*)segment,
                                            matrix,
                                            segment_type - VGLYPH_SEGMENT_ARC_ABS,
                                            points,
                                            prev_point);

        case VGLYPH_SEGMENT_LINETO_HORIZONTAL_ABS:
        case VGLYPH_SEGMENT_LINETO_HORIZONTAL_REL:
            return _vglyph_data_surface_lineto_horizontal(surface,
                                                          (vglyph_segment_lineto_horizontal_t*)segment,
                                                          matrix,
                                                          segment_type - VGLYPH_SEGMENT_LINETO_HORIZONTAL_ABS,
                                                          points,
                                                          prev_point);

        case VGLYPH_SEGMENT_LINETO_VERTICAL_ABS:
        case VGLYPH_SEGMENT_LINETO_VERTICAL_REL:
            return _vglyph_data_surface_lineto_vertical(surface,
                                                        (vglyph_segment_lineto_vertical_t*)segment,
                                                        matrix,
                                                        segment_type - VGLYPH_SEGMENT_LINETO_HORIZONTAL_ABS,
                                                        points,
                                                        prev_point);

        case VGLYPH_SEGMENT_CURVETO_CUBIC_SMOOTH_ABS:
        case VGLYPH_SEGMENT_CURVETO_CUBIC_SMOOTH_REL:
            return _vglyph_data_surface_curveto_cubic_smooth(surface,
                                                             (vglyph_segment_curveto_cubic_smooth_t*)segment,
                                                             matrix,
                                                             segment_type - VGLYPH_SEGMENT_CURVETO_CUBIC_SMOOTH_ABS,
                                                             points,
                                                             prev_point,
                                                             control_point);

        case VGLYPH_SEGMENT_CURVETO_QUADRATIC_SMOOTH_ABS:
        case VGLYPH_SEGMENT_CURVETO_QUADRATIC_SMOOTH_REL:
            return _vglyph_data_surface_curveto_quadratic_smooth(surface,
                                                                 (vglyph_segment_curveto_quadratic_smooth_t*)segment,
                                                                 matrix,
                                                                 segment_type - VGLYPH_SEGMENT_CURVETO_QUADRATIC_SMOOTH_ABS,
                                                                 points,
                                                                 prev_point,
                                                                 control_point);
    }

    return state;
}

static vglyph_vector_t*
_vglyph_data_surface_figure_to_lines(vglyph_data_surface_t* surface,
                                     vglyph_figure_t* figure,
                                     const vglyph_matrix_t* matrix,
                                     vglyph_state_t* state)
{
    *state = VGLYPH_STATE_SUCCESS;

    vglyph_uint_t segment_count = figure->segment_count;
    vglyph_uint_t offset_segment_type = 0;

    vglyph_vector_t* result = _vglyph_vector_create(sizeof(vglyph_point_t) * segment_count);

    if (!segment_count)
        return result;

    const vglyph_segment_type_t* segment_type = NULL;
    const void* segment;

    vglyph_bool_t path_closed = TRUE;

    vglyph_point_t prev_point;
    vglyph_point_t start_point;
    vglyph_point_t control_point;

    prev_point.x = 0.0f;
    prev_point.y = 0.0f;
    control_point.x = NAN;
    control_point.y = NAN;

    while (segment_count--)
    {
        segment_type = (vglyph_segment_type_t*)
            _vglyph_vector_at(figure->segment_types, offset_segment_type);

        segment = _vglyph_vector_at(figure->segments, segment_type->offset);

        if ((segment_type->segment < VGLYPH_SEGMENT_CURVETO_CUBIC_ABS ||
             segment_type->segment > VGLYPH_SEGMENT_CURVETO_QUADRATIC_REL) &&
            (segment_type->segment < VGLYPH_SEGMENT_CURVETO_CUBIC_SMOOTH_ABS ||
             segment_type->segment > VGLYPH_SEGMENT_CURVETO_QUADRATIC_SMOOTH_REL))
            _vglyph_point_from_coord(&control_point, NAN, NAN);

        *state = _vglyph_data_surface_segment_to_lines(surface,
                                                       segment_type->segment,
                                                       segment,
                                                       matrix,
                                                       result,
                                                       &path_closed,
                                                       &start_point,
                                                       &prev_point,
                                                       &control_point);

        if (*state != VGLYPH_STATE_SUCCESS)
            return result;

        offset_segment_type += sizeof(vglyph_segment_type_t);
    }

    if (segment_type->segment != VGLYPH_SEGMENT_CLOSEPATH)
    {
        vglyph_segment_closepath_t closepath;
        *state = _vglyph_data_surface_segment_to_lines(surface,
                                                       VGLYPH_SEGMENT_CLOSEPATH,
                                                       &closepath,
                                                       matrix,
                                                       result,
                                                       &path_closed,
                                                       &start_point,
                                                       &prev_point,
                                                       &control_point);
    }

    return result;
}

static vglyph_vector_t**
_vglyph_data_surface_compute_intersections(vglyph_data_surface_t* surface,
                                           vglyph_vector_t* points,
                                           vglyph_state_t* state)
{
    *state = VGLYPH_STATE_SUCCESS;

    const vglyph_sint_t height = (vglyph_sint_t)(surface->base.height << surface->shift_mulitsampling);
    vglyph_vector_t** intersections = (vglyph_vector_t**)malloc(sizeof(vglyph_vector_t*) * height);

    if (!intersections)
    {
        *state = VGLYPH_STATE_OUT_OF_MEMORY;
        return NULL;
    }

    for (vglyph_sint_t y = 0; y < height; ++y)
        intersections[y] = NULL;

    const vglyph_uint_t size = _vglyph_vector_size_in_bytes(points);
    vglyph_point_t start = *((vglyph_point_t*)_vglyph_vector_at(points, 0));
    vglyph_point_t end;

    for (vglyph_uint_t offset = sizeof(vglyph_point_t); offset < size; offset += sizeof(vglyph_point_t))
    {
        end = *((vglyph_point_t*)_vglyph_vector_at(points, offset));

        if (end.x != end.x)
        {
            offset += sizeof(vglyph_point_t);

            if (offset == size)
                break;

            start = *((vglyph_point_t*)_vglyph_vector_at(points, offset));
            continue;
        }

        vglyph_point_t start_point;
        vglyph_point_t end_point;

        if (start.y > end.y)
        {
            start_point = end;
            end_point   = start;
        }
        else
        {
            start_point = start;
            end_point   = end;
        }

        vglyph_point_t v;
        _vglyph_point_sub(&v, &end_point, &start_point);

        vglyph_sint_t start_y = (vglyph_sint_t)floorf(start_point.y);
        vglyph_sint_t end_y   = start_y + (vglyph_sint_t)ceilf(v.y) + 1;

        if (start_y < height && end_y >= 0)
        {
            if (start_y < 0)
                start_y = 0;

            if (end_y > height)
                end_y = height;

            vglyph_float32_t t;

            for (vglyph_sint_t y = start_y; y < end_y; ++y)
            {
                t = (y - start_point.y) / v.y;

                if (t >= 0.0 && t < 1.0)
                {
                    if (!intersections[y])
                    {
                        vglyph_vector_t* item = _vglyph_vector_create(sizeof(vglyph_float32_t) << 3);

                        if (!_vglyph_vector_is_valid(item))
                        {
                            *state = _vglyph_vector_get_state(item);
                            _vglyph_vector_destroy(item);

                            return intersections;
                        }

                        intersections[y] = item;
                    }

                    vglyph_float32_t intersection_x = (vglyph_float32_t)(start_point.x + v.x * t);
                    vglyph_float32_t intersection_current;

                    vglyph_uint_t count_intersections = _vglyph_vector_size_in_bytes(intersections[y]);
                    vglyph_uint_t find_offset;

                    for (find_offset = 0; find_offset < count_intersections; find_offset += sizeof(vglyph_float32_t))
                    {
                        intersection_current = *(vglyph_float32_t*)_vglyph_vector_at(intersections[y], find_offset);

                        if (intersection_x < intersection_current)
                            break;
                    }

                    _vglyph_vector_insert(intersections[y],
                                          (vglyph_uint8_t*)&intersection_x,
                                          sizeof(vglyph_float32_t),
                                          find_offset);

                    if (!_vglyph_vector_is_valid(intersections[y]))
                    {
                        *state = _vglyph_vector_get_state(intersections[y]);
                        return intersections;
                    }
                }
            }
        }

        start = end;
    }

    return intersections;
}

static void
_vglyph_data_surface_draw_polygon_without_multisampling(vglyph_data_surface_t* surface,
                                                        vglyph_vector_t** intersections,
                                                        const vglyph_color_t* color)
{
    vglyph_render_t* render = surface->base.render;

    void (*set_pixel)(vglyph_render_t*,
                      vglyph_surface_t*,
                      vglyph_sint32_t,
                      vglyph_sint32_t,
                      const vglyph_color_t*) = color->alpha < 1.0 ?
        render->backend->alpha_blend :
        render->backend->set_pixel;

    const vglyph_sint32_t width  = (vglyph_sint32_t)surface->base.width;
    const vglyph_sint32_t height = (vglyph_sint32_t)surface->base.height;
    const vglyph_uint_t offset_1 = sizeof(vglyph_float32_t);
    const vglyph_uint_t offset_2 = sizeof(vglyph_float32_t) << 1;

    vglyph_vector_t* currect_intersections;

    vglyph_float32_t s_x;
    vglyph_float32_t e_x;

    vglyph_sint32_t s_ix;
    vglyph_sint32_t e_ix;

    for (vglyph_sint32_t y = 0; y < height; ++y)
    {
        currect_intersections = intersections[y];

        if (currect_intersections)
        {
            const vglyph_uint_t count_intersections = _vglyph_vector_size_in_bytes(currect_intersections);

            for (vglyph_uint_t i = 0; i < count_intersections; i += offset_2)
            {
                s_x = *(vglyph_float32_t*)_vglyph_vector_at(currect_intersections, i);
                e_x = *(vglyph_float32_t*)_vglyph_vector_at(currect_intersections, i + offset_1);

                s_ix = (vglyph_sint32_t)floorf(s_x);
                e_ix = (vglyph_sint32_t)ceilf(e_x);

                if (s_ix < 0)
                    s_ix = 0;
                else if (s_ix > width)
                    s_ix = width;

                if (e_ix < 0)
                    e_ix = 0;
                else if (e_ix > width)
                    e_ix = width;

                for (vglyph_sint32_t x = s_ix; x < e_ix; ++x)
                    set_pixel(render, &surface->base, x, y, color);
            }
        }
    }
}

static void
_vglyph_data_surface_draw_polygon(vglyph_data_surface_t* surface,
                                  vglyph_vector_t** intersections,
                                  const vglyph_color_t* color)
{
    vglyph_render_t* render    = surface->base.render;
    vglyph_uint8_t*  data_back = surface->data_back;

    void (*set_pixel)(vglyph_render_t*,
                      vglyph_surface_t*,
                      vglyph_sint32_t,
                      vglyph_sint32_t,
                      const vglyph_color_t*) = color->alpha < 1.0 ?
        render->backend->alpha_blend :
        render->backend->set_pixel;

    const vglyph_sint32_t multisampling       = (vglyph_sint_t)surface->base.multisampling;
    const vglyph_uint_t   shift_mulitsampling = surface->shift_mulitsampling;

    const vglyph_sint32_t  width             = surface->base.width;
    const vglyph_sint32_t  height            = surface->base.height;
    const vglyph_sint32_t  rasterizer_width  = width  << shift_mulitsampling;
    const vglyph_sint32_t  rasterizer_height = height << shift_mulitsampling;
    const vglyph_uint_t    offset_1          = sizeof(vglyph_float32_t);
    const vglyph_uint_t    offset_2          = sizeof(vglyph_float32_t) << 1;
    const vglyph_uint_t    max_samples       = (vglyph_uint_t)(multisampling * multisampling);
    const vglyph_float64_t inv_max_samples   = 1.0 / max_samples;
    const vglyph_float64_t alpha             = color->alpha;

    vglyph_vector_t* currect_intersections;

    vglyph_float32_t s_x;
    vglyph_float32_t e_x;

    vglyph_sint32_t s_ix;
    vglyph_sint32_t e_ix;

    vglyph_sint32_t min_s_ix = INT32_MAX;
    vglyph_sint32_t max_e_ix = INT32_MIN;

    vglyph_sint32_t min_x;
    vglyph_sint32_t max_x;

    vglyph_color_t result_color = *color;

    for (vglyph_sint32_t y = 0; y < height; ++y)
    {
        for (vglyph_sint32_t sample_y = 0; sample_y < multisampling; ++sample_y)
        {
            currect_intersections = intersections[(y << shift_mulitsampling) + sample_y];

            if (currect_intersections)
            {
                const vglyph_sint32_t offset_y = rasterizer_width * sample_y;
                const vglyph_uint_t count_intersections = _vglyph_vector_size_in_bytes(currect_intersections);

                for (vglyph_uint_t i = 0; i < count_intersections; i += offset_2)
                {
                    s_x = *(vglyph_float32_t*)_vglyph_vector_at(currect_intersections, i);
                    e_x = *(vglyph_float32_t*)_vglyph_vector_at(currect_intersections, i + offset_1);

                    s_ix = (vglyph_sint32_t)floorf(s_x);
                    e_ix = (vglyph_sint32_t)ceilf(e_x);

                    if (s_ix < 0)
                        s_ix = 0;
                    else if (s_ix > rasterizer_width)
                        s_ix = rasterizer_width;

                    if (e_ix < 0)
                        e_ix = 0;
                    else if (e_ix > rasterizer_width)
                        e_ix = rasterizer_width;

                    if (s_ix < min_s_ix)
                        min_s_ix = s_ix;

                    if (e_ix > max_e_ix)
                        max_e_ix = e_ix;

                    for (vglyph_sint32_t x = s_ix; x < e_ix; ++x)
                        data_back[x + offset_y] = 1;
                }
            }
        }

        if (min_s_ix != INT32_MAX)
        {
            min_x = (min_s_ix) >> shift_mulitsampling;
            max_x = (max_e_ix + multisampling - 1) >> shift_mulitsampling;

            for (vglyph_sint32_t x = min_x, offset_x = min_x << shift_mulitsampling
                 ; x < max_x
                 ; ++x, offset_x += multisampling)
            {
                vglyph_uint_t samples = 0;

                for (vglyph_sint_t sample_y = 0, offset_y = 0
                     ; sample_y < multisampling
                     ; ++sample_y, offset_y += rasterizer_width)
                {
                    for (vglyph_sint32_t mx = 0; mx < multisampling; ++mx)
                    {
                        samples += data_back[offset_x + mx + offset_y];
                        data_back[offset_x + mx + offset_y] = 0;
                    }
                }

                if (samples)
                {
                    result_color.alpha = alpha;

                    if (samples == max_samples)
                    {
                        set_pixel(render, &surface->base, x, y, &result_color);
                    }
                    else
                    {
                        result_color.alpha *= samples * inv_max_samples;
                        render->backend->alpha_blend(render, &surface->base, x, y, &result_color);
                    }
                }
            }

            min_s_ix = INT32_MAX;
            max_e_ix = INT32_MIN;
        }
    }
}

static vglyph_bool_t
_vglyph_data_surface_draw_glyph_matrix(vglyph_surface_t* surface,
                                       vglyph_glyph_t* glyph,
                                       const vglyph_color_t* color,
                                       const vglyph_matrix_t* mat)
{
    vglyph_data_surface_t* data_surface = (vglyph_data_surface_t*)surface;

    vglyph_state_t    state         = VGLYPH_STATE_SUCCESS;
    vglyph_vector_t*  points        = NULL;
    vglyph_vector_t** intersections = NULL;

    do
    {
        points = _vglyph_data_surface_figure_to_lines(data_surface, glyph->figure, mat, &state);

        if (state != VGLYPH_STATE_SUCCESS)
            break;

        intersections = _vglyph_data_surface_compute_intersections(data_surface, points, &state);

        if (state != VGLYPH_STATE_SUCCESS)
            break;

        _vglyph_vector_destroy(points);
        points = NULL;

        if (data_surface->base.multisampling == VGLYPH_MULTISAMPLING_1)
            _vglyph_data_surface_draw_polygon_without_multisampling(data_surface, intersections, color);
        else
            _vglyph_data_surface_draw_polygon(data_surface, intersections, color);

    } while (FALSE);

    if (points)
        _vglyph_vector_destroy(points);

    if (intersections)
    {
        const vglyph_uint32_t height =
            surface->height << data_surface->shift_mulitsampling;

        for (vglyph_uint32_t y = 0; y < height; ++y)
        {
            if (intersections[y])
                _vglyph_vector_destroy(intersections[y]);
        }

        free(intersections);
    }

    if (state != VGLYPH_STATE_SUCCESS)
    {
        _vglyph_data_surface_set_state(data_surface, state);
        _vglyph_object_set_state_not_fatal(&data_surface->base.object);

        return FALSE;
    }

    return TRUE;
}

void
_vglyph_data_surface_init(vglyph_data_surface_t* surface,
                          const vglyph_object_backend_t* object_backend,
                          const vglyph_surface_backend_t* surface_backend,
                          vglyph_format_t* format,
                          vglyph_render_t* render,
                          vglyph_uint32_t width,
                          vglyph_uint32_t height,
                          vglyph_uint32_t pitch,
                          vglyph_uint8_t* data)
{
    assert(data);

    _vglyph_surface_init(&surface->base,
                         object_backend,
                         surface_backend,
                         format,
                         render,
                         width,
                         height,
                         pitch);

    surface->data      = data;
    surface->data_back = NULL;

    _vglyph_data_surface_update_multisampling(&surface->base);
}

void
_vglyph_data_surface_ctor(vglyph_data_surface_t* surface)
{
    _vglyph_surface_ctor(&surface->base);

    if (_vglyph_data_surface_is_valid(surface))
    {
    }
}

void
_vglyph_data_surface_dtor(vglyph_data_surface_t* surface)
{
    free(surface->data_back);

    _vglyph_surface_dtor(&surface->base);
}

vglyph_bool_t
_vglyph_data_surface_is_cast(vglyph_type_t* type)
{
    return _vglyph_data_surface_get_type() == type
        || _vglyph_surface_is_cast(type);
}

vglyph_type_t*
_vglyph_data_surface_get_type(void)
{
    static vglyph_type_t type = _vglyph_type_create(_vglyph_data_surface_is_cast);
    return &type;
}

static void
_vglyph_data_surface_destroy(vglyph_object_t* object)
{
    vglyph_data_surface_t* surface = (vglyph_data_surface_t*)object;
    _vglyph_data_surface_dtor(surface);

    free(surface);
}

void
_vglyph_data_surface_update_multisampling(vglyph_surface_t* surface)
{
    vglyph_multisampling_t multisampling = surface->multisampling;
    vglyph_data_surface_t* data_surface = (vglyph_data_surface_t*)surface;

    if (multisampling != VGLYPH_MULTISAMPLING_1)
    {
        vglyph_uint_t data_back_size =
            surface->width * multisampling * surface->multisampling;

        vglyph_uint8_t* data_back = (vglyph_uint8_t*)malloc(data_back_size);

        if (!data_back)
        {
            _vglyph_data_surface_set_state(data_surface, VGLYPH_STATE_OUT_OF_MEMORY);
            _vglyph_object_set_state_not_fatal(&data_surface->base.object);
            return;
        }

        memset(data_back, 0, data_back_size);
        free(data_surface->data_back);

        data_surface->data_back = data_back;
    }
    else
    {
        free(data_surface->data_back);
        data_surface->data_back = NULL;
    }

    vglyph_uint_t samples = multisampling;
    data_surface->shift_mulitsampling = 0;

    while (samples >>= 1)
        ++data_surface->shift_mulitsampling;
}

vglyph_uint8_t*
_vglyph_data_surface_lock(vglyph_surface_t* surface,
                          vglyph_uint32_t x,
                          vglyph_uint32_t y,
                          vglyph_uint32_t width,
                          vglyph_uint32_t height)
{
    return ((vglyph_data_surface_t*)surface)->data;
}

void
_vglyph_data_surface_unlock(vglyph_surface_t* surface)
{
}

void
_vglyph_data_surface_fill(vglyph_surface_t* surface,
                          vglyph_uint32_t x,
                          vglyph_uint32_t y,
                          vglyph_uint32_t width,
                          vglyph_uint32_t height,
                          const vglyph_color_t* color)
{
    vglyph_render_t* render = surface->render;
    render->backend->fill(render, surface, x, y, width, height, color);
}

void
_vglyph_data_surface_get_pixel(vglyph_surface_t* surface,
                               vglyph_sint32_t x,
                               vglyph_sint32_t y,
                               vglyph_color_t* color)
{
    vglyph_render_t* render = surface->render;
    render->backend->get_pixel(render, surface, x, y, color);
}

void
_vglyph_data_surface_set_pixel(vglyph_surface_t* surface,
                               vglyph_sint32_t x,
                               vglyph_sint32_t y,
                               const vglyph_color_t* color)
{
    vglyph_render_t* render = surface->render;
    render->backend->set_pixel(render, surface, x, y, color);
}

vglyph_uint_t
_vglyph_data_surface_get_dpi(vglyph_surface_t* surface)
{
    return _vglyph_get_device_dpi();
}

vglyph_bool_t
_vglyph_data_surface_draw_glyph(vglyph_surface_t* surface,
                                vglyph_glyph_t* glyph,
                                vglyph_float32_t pt,
                                const vglyph_color_t* color,
                                const vglyph_point_t* position,
                                const vglyph_point_t* origin,
                                const vglyph_point_t* scale,
                                vglyph_float32_t angle,
                                vglyph_bool_t vertical_layout,
                                vglyph_point_t* next_position)
{
    vglyph_data_surface_t* data_surface;
    VGLYPH_CAST(surface, data_surface);

    const vglyph_float32_t size_glyph = _vglyph_data_surface_pt_to_px(data_surface, pt);

    if (size_glyph == 0.0f)
        return TRUE;

    const vglyph_sint_t multisampling =
        (vglyph_sint_t)(((vglyph_data_surface_t*)surface)->base.multisampling);

    const vglyph_float32_t width  = (vglyph_float32_t)(surface->width  * multisampling);
    const vglyph_float32_t height = (vglyph_float32_t)(surface->height * multisampling);

    if (width == 0.0f || height == 0.0f)
        return TRUE;

    const vglyph_float32_t glyph_width  = vglyph_glyph_get_width(glyph);
    const vglyph_float32_t glyph_height = vglyph_glyph_get_height(glyph);

    if (glyph_width == 0.0f || glyph_height == 0.0f)
        return TRUE;

    vglyph_matrix_t mat;
    _vglyph_matrix_init_translate(&mat, 0.0f, height);

    if (position)
        _vglyph_matrix_translate(&mat, &mat, position->x * multisampling, -position->y * multisampling);

    if (angle != 0.0f)
        _vglyph_matrix_rotate(&mat, &mat, -_vglyph_degree_to_radians(angle));

    _vglyph_matrix_scale(&mat, &mat, size_glyph / surface->width, -size_glyph / surface->height);

    if (scale)
    {
        if (scale->x == 0.0f || scale->y == 0.0f)
            return TRUE;

        _vglyph_matrix_scale(&mat, &mat, scale->x, scale->y);
    }

    if (vertical_layout)
        _vglyph_matrix_translate(&mat, &mat, -glyph->vertical_bearing_x * width, 0.0f);
    else
        _vglyph_matrix_translate(&mat, &mat, 0.0f, -glyph->horizontal_bearing_y * height);

    vglyph_matrix_t transform = mat;
    vglyph_point_t  point_origin;

    if (origin)
    {
        point_origin = *origin;
    }
    else
    {
        point_origin.x = 0.0f;
        point_origin.y = 0.0f;
    }

    if (vertical_layout)
        point_origin.y += glyph->vertical_advance * size_glyph;

    _vglyph_matrix_translate(&mat,
                             &mat,
                             -point_origin.x * surface->width  * multisampling / size_glyph,
                             -point_origin.y * surface->height * multisampling / size_glyph);

    if (next_position)
    {
        if (vertical_layout)
        {
            next_position->x =  glyph->vertical_bearing_x * surface->width  * multisampling;
            next_position->y = -glyph->vertical_advance   * surface->height * multisampling;
        }
        else
        {
            next_position->x = glyph->horizontal_advance   * surface->width  * multisampling;
            next_position->y = glyph->horizontal_bearing_y * surface->height * multisampling;
        }

        _vglyph_matrix_transform_point(next_position, &transform, next_position);

        next_position->x = next_position->x / multisampling;
        next_position->y = surface->height - next_position->y / multisampling;
    }

    return _vglyph_data_surface_draw_glyph_matrix(surface,
                                                  glyph,
                                                  color,
                                                  &mat);
}

vglyph_bool_t
_vglyph_data_surface_draw_glyph_viewport(vglyph_surface_t* surface,
                                         vglyph_glyph_t* glyph,
                                         const vglyph_color_t* color,
                                         const vglyph_point_t* position,
                                         const vglyph_point_t* viewport,
                                         const vglyph_point_t* origin,
                                         vglyph_float32_t angle,
                                         vglyph_bool_t fit_to_viewport)
{
    const vglyph_sint_t multisampling =
        (vglyph_sint_t)(((vglyph_data_surface_t*)surface)->base.multisampling);

    const vglyph_float32_t width  = (vglyph_float32_t)(surface->width  * multisampling);
    const vglyph_float32_t height = (vglyph_float32_t)(surface->height * multisampling);

    vglyph_rectangle_t glyph_bound;
    _vglyph_figure_get_bound(glyph->figure, &glyph_bound);

    const vglyph_float32_t glyph_width  = glyph_bound.right  - glyph_bound.left;
    const vglyph_float32_t glyph_height = glyph_bound.bottom - glyph_bound.top;

    if (glyph_width == 0.0f || glyph_height == 0.0f)
        return TRUE;

    vglyph_matrix_t mat;
    _vglyph_matrix_init_translate(&mat, 0.0f, height);

    if (position)
    {
        _vglyph_matrix_translate(&mat, &mat, position->x * multisampling, -position->y * multisampling);
    }

    if (origin)
    {
        _vglyph_matrix_translate(&mat, &mat, origin->x * multisampling, -origin->y * multisampling);
    }

    if (angle != 0.0f)
    {
        const vglyph_float32_t center_viewport_x = viewport->x * 0.5f * multisampling;
        const vglyph_float32_t center_viewport_y = viewport->y * 0.5f * multisampling;

        _vglyph_matrix_translate(&mat, &mat, center_viewport_x, -center_viewport_y);
        _vglyph_matrix_rotate(&mat, &mat, -_vglyph_degree_to_radians(angle));
        _vglyph_matrix_translate(&mat, &mat, -center_viewport_x, center_viewport_y);
    }

    if (origin)
    {
        _vglyph_matrix_translate(&mat, &mat, -origin->x * multisampling, origin->y * multisampling);
    }

    if (viewport)
    {
        _vglyph_matrix_scale(&mat, &mat, viewport->x / surface->width, viewport->y / surface->height);
    }

    if (fit_to_viewport)
    {
        _vglyph_matrix_scale(&mat, &mat, 1.0f / glyph_width, -1.0f / glyph_height);
        _vglyph_matrix_translate(&mat, &mat, -glyph_bound.left * width, -glyph_bound.top * height);
    }
    else
    {
        _vglyph_matrix_scale(&mat, &mat, 1.0f, -1.0f);
    }

    return _vglyph_data_surface_draw_glyph_matrix(surface,
                                                  glyph,
                                                  color,
                                                  &mat);
}

vglyph_bool_t
_vglyph_data_surface_draw_glyph_transform(vglyph_surface_t* surface,
                                          vglyph_glyph_t* glyph,
                                          const vglyph_color_t* color,
                                          const vglyph_transform_t* transform)
{
    const vglyph_sint_t multisampling =
        (vglyph_sint_t)(((vglyph_data_surface_t*)surface)->base.multisampling);

    const vglyph_float32_t width  = (vglyph_float32_t)(surface->width  * multisampling);
    const vglyph_float32_t height = (vglyph_float32_t)(surface->height * multisampling);

    const vglyph_float32_t glyph_width  = vglyph_glyph_get_width(glyph);
    const vglyph_float32_t glyph_height = vglyph_glyph_get_height(glyph);

    if (glyph_width == 0.0f || glyph_height == 0.0f)
        return TRUE;

    vglyph_matrix_t mat;
    _vglyph_matrix_init_translate(&mat, 0.0f, height);
    _vglyph_matrix_scale(&mat, &mat, 1.0f / glyph_width, -1.0f / glyph_height);

    if (transform)
    {
        vglyph_matrix_t mat2 = transform->matrix;
        mat2.x0 *= multisampling;
        mat2.y0 *= multisampling;

        _vglyph_matrix_multiply(&mat, &mat2, &mat);
    }

    _vglyph_matrix_translate(&mat, &mat, -glyph->horizontal_bearing_x * width, -glyph->horizontal_bearing_y * height);

    return _vglyph_data_surface_draw_glyph_matrix(surface,
                                                  glyph,
                                                  color,
                                                  &mat);
}

static const vglyph_object_backend_t vglyph_data_surface_object_backend = {
    _vglyph_data_surface_get_type,
    _vglyph_data_surface_is_cast,
    _vglyph_data_surface_destroy
};

const vglyph_surface_backend_t vglyph_data_surface_backend = {
    _vglyph_data_surface_update_multisampling,
    _vglyph_data_surface_lock,
    _vglyph_data_surface_unlock,
    _vglyph_data_surface_fill,
    _vglyph_data_surface_get_pixel,
    _vglyph_data_surface_set_pixel,
    _vglyph_data_surface_get_dpi,
    _vglyph_data_surface_draw_glyph,
    _vglyph_data_surface_draw_glyph_viewport,
    _vglyph_data_surface_draw_glyph_transform
};

vglyph_uint32_t
_vglyph_data_surface_get_pitch(vglyph_format_t* format,
                               vglyph_uint32_t width,
                               vglyph_uint32_t height,
                               vglyph_alignment_t row_alignment)
{
    assert(format);
    assert(row_alignment == VGLYPH_ALIGNMENT_1 ||
           row_alignment == VGLYPH_ALIGNMENT_2 ||
           row_alignment == VGLYPH_ALIGNMENT_4 ||
           row_alignment == VGLYPH_ALIGNMENT_8);

    vglyph_uint32_t bits_per_pixel = vglyph_format_get_bits_per_pixel(format);
    vglyph_uint32_t pitch = (width * bits_per_pixel + 7) >> 3;
    vglyph_uint32_t align = row_alignment - 1;
    pitch = (pitch + align) & ~align;

    return pitch;
}

vglyph_render_t*
_vglyph_data_surface_create_render(vglyph_format_t* format)
{
    if (vglyph_object_is_cast(&format->object, vglyph_get_rgba_uint_format_type()))
    {
        vglyph_rgba_uint_format_t* rgba_uint_format = (vglyph_rgba_uint_format_t*)format;

        if (rgba_uint_format->bit_count.r +
            rgba_uint_format->bit_count.g +
            rgba_uint_format->bit_count.b +
            rgba_uint_format->bit_count.a == 32)
            return _vglyph_rgba_uint32_data_render_create(rgba_uint_format);

        if (rgba_uint_format->bit_count.r +
            rgba_uint_format->bit_count.g +
            rgba_uint_format->bit_count.b +
            rgba_uint_format->bit_count.a == 16)
            return _vglyph_rgba_uint16_data_render_create(rgba_uint_format);

        if ((rgba_uint_format->base.packaging_bytes.endianness == VGLYPH_ENDIANNESS_HOST && _vglyph_is_little_endian()) ||
            rgba_uint_format->base.packaging_bytes.endianness == VGLYPH_ENDIANNESS_LITTLE)
            return _vglyph_rgba_little_uint_data_render_create();

        return _vglyph_rgba_uint_data_render_create();
    }

    return (vglyph_render_t*)_vglyph_object_invalid_format();
}

vglyph_uint32_t
vglyph_surface_get_data_size(vglyph_format_t* format,
                             vglyph_uint32_t width,
                             vglyph_uint32_t height,
                             vglyph_alignment_t row_alignment)
{
    vglyph_uint32_t pitch =
        _vglyph_data_surface_get_pitch(format, width, height, row_alignment);

    return pitch * height;
}

vglyph_surface_t*
vglyph_surface_create_for_data(vglyph_uint8_t* data,
                               vglyph_uint32_t data_size,
                               vglyph_format_t* format,
                               vglyph_uint32_t width,
                               vglyph_uint32_t height,
                               vglyph_alignment_t row_alignment)
{
    assert(data);
    assert(format);
    assert(data_size >= vglyph_surface_get_data_size(format, width, height, row_alignment));

    vglyph_data_surface_t* surface = (vglyph_data_surface_t*)malloc(sizeof(vglyph_data_surface_t));

    if (!surface)
        return (vglyph_surface_t*)_vglyph_object_out_of_memory();

    vglyph_uint32_t pitch =
        _vglyph_data_surface_get_pitch(format, width, height, row_alignment);

    vglyph_render_t* render = _vglyph_data_surface_create_render(format);

    _vglyph_data_surface_init(surface,
                              &vglyph_data_surface_object_backend,
                              &vglyph_data_surface_backend,
                              format,
                              render,
                              width,
                              height,
                              pitch,
                              data);

    _vglyph_render_destroy(render);

    _vglyph_data_surface_ctor(surface);

    return &surface->base;
}


text:
using System.Collections.Generic;

using Microsoft.AspNet.Identity;

namespace OnLineShop.Web.Models.Menage
{
    public class IndexViewModel
    {
        public bool HasPassword { get; set; }

        public IList<UserLoginInfo> Logins { get; set; }

        public string PhoneNumber { get; set; }

        public bool TwoFactor { get; set; }

        public bool BrowserRemembered { get; set; }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.knowm.xchange.hitbtc.dto.trade;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.knowm.xchange.hitbtc.dto.HitbtcBaseResponse;

public class HitbtcExecutionReportResponse extends HitbtcBaseResponse {

  HitbtcExecutionReport executionReport;
  HitbtcCancelReject cancelReject;

  public HitbtcExecutionReportResponse(@JsonProperty(value = "ExecutionReport", required = false) HitbtcExecutionReport executionReport,
      @JsonProperty(value = "CancelReject", required = false) HitbtcCancelReject cancelReject) {

    super();
    this.executionReport = executionReport;
    this.cancelReject = cancelReject;
  }

  public HitbtcExecutionReport getExecutionReport() {

    return executionReport;
  }

  public HitbtcCancelReject getCancelReject() {

    return cancelReject;
  }

  @Override
  public String toString() {

    StringBuilder builder = new StringBuilder();
    builder.append("HitbtcExecutionReportResponse [executionReport=");
    builder.append(executionReport);
    builder.append(", cancelReject=");
    builder.append(cancelReject);
    builder.append("]");
    return builder.toString();
  }
}


text:
<?php
namespace Phwoolcon\Tests\Helper;

use Phwoolcon\Controller;

class TestController extends Controller
{

    public function getTestRoute()
    {
        $this->response->setContent('Test Controller Route Content');
    }

    public function getTestPrefixedRoute()
    {
        $this->response->setContent('Test Prefixed Route Content');
    }

    public function getTestInput()
    {
        $this->response->setContent($this->input('key'));
    }

    public function testJsonReturn($data)
    {
        $this->jsonReturn($data);
    }

    public function testInput($key, $default = null)
    {
        return $this->input($key, $default);
    }

    public function testRedirect($url)
    {
        $this->redirect($url);
    }

    public function testSetBrowserCache($pageId, $type = null)
    {
        $this->setBrowserCache($pageId, $type);
    }

    public function testGetBrowserCache($pageId, $type = null)
    {
        return $this->getBrowserCache($pageId, $type);
    }
}


text:
/*
 * This file is generated by jOOQ.
 */
package generated.rx.jdbc.guice.vertx;

import generated.rx.jdbc.guice.vertx.tables.Something;
import generated.rx.jdbc.guice.vertx.tables.Somethingcomposite;
import generated.rx.jdbc.guice.vertx.tables.records.SomethingRecord;
import generated.rx.jdbc.guice.vertx.tables.records.SomethingcompositeRecord;

import org.jooq.TableField;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.Internal;

/**
 * A class modelling foreign key relationships and constraints of tables in
 * VERTX.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Keys {

    // -------------------------------------------------------------------------
    // UNIQUE and PRIMARY KEY definitions
    // -------------------------------------------------------------------------

    public static final UniqueKey<SomethingRecord> SYS_PK_10508 = Internal.createUniqueKey(Something.SOMETHING, DSL.name("SYS_PK_10508"), new TableField[] { Something.SOMETHING.SOMEID }, true);
    public static final UniqueKey<SomethingcompositeRecord> SYS_PK_10512 = Internal.createUniqueKey(Somethingcomposite.SOMETHINGCOMPOSITE, DSL.name("SYS_PK_10512"), new TableField[] { Somethingcomposite.SOMETHINGCOMPOSITE.SOMEID, Somethingcomposite.SOMETHINGCOMPOSITE.SOMESECONDID }, true);
}


text:
from __future__ import division, absolute_import, print_function

import numpy as np
from numpy.testing import TestCase, run_module_suite, assert_, assert_equal

rlevel = 1

class TestRegression(TestCase):
    def test_kron_matrix(self, level=rlevel):
        # Ticket #71
        x = np.matrix('[1 0; 1 0]')
        assert_equal(type(np.kron(x, x)), type(x))

    def test_matrix_properties(self,level=rlevel):
        # Ticket #125
        a = np.matrix([1.0], dtype=float)
        assert_(type(a.real) is np.matrix)
        assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)

    def test_matrix_multiply_by_1d_vector(self, level=rlevel):
        # Ticket #473
        def mul():
            np.mat(np.eye(2))*np.ones(2)

        self.assertRaises(ValueError, mul)

    def test_matrix_std_argmax(self,level=rlevel):
        # Ticket #83
        x = np.asmatrix(np.random.uniform(0, 1, (3, 3)))
        self.assertEqual(x.std().shape, ())
        self.assertEqual(x.argmax().shape, ())

if __name__ == "__main__":
    run_module_suite()


text:
DD_DETAIL_BEGIN_
#	if DDCPP_COMPAT_STL
DD_NESTED_TYPE_TRAIT(IteratorOfStl_, RangeT_::iterator, void)

#	endif
template <typename RangeT_>
struct Iterator_ {
#	if DDCPP_COMPAT_STL
	DD_ALIAS(Type, DD_MODIFY_TRAIT(IteratorOfStl_, RangeT_));
#	else
	DD_ALIAS(Type, void);
#	endif

};

template <typename ValueT_, LengthType length_c_>
struct Iterator_<ValueT_[length_c_]> {
	DD_ALIAS(Type, ValueT_*);

};

template <typename ValueT_>
struct Iterator_<ValueT_[]> {
	DD_ALIAS(Type, ValueT_*);

};

template <typename ValueT_>
struct Iterator_<ValueT_*> {
	DD_ALIAS(Type, ValueT_*);

};

#	if __cplusplus >= 201103L
#		if DDCPP_COMPAT_STL
DD_NESTED_TYPE_TRAIT(Iterator, Iterator, typename ::DD::detail_::Iterator_<MACRO_ObjectT_>::Type)
#		else
DD_NESTED_TYPE_TRAIT(Iterator, Iterator, typename ::DD::detail_::Iterator_<MACRO_ObjectT_>::Type)
#		endif

template <typename RangeT_>
using IteratorType = typename Iterator<RangeT_>::Type;
#	else
#		if DDCPP_COMPAT_STL
DD_NESTED_TYPE_TRAIT(Iterator, Iterator, typename ::DD::detail_::Iterator_<typename RemoveCV<MACRO_ObjectT_>::Type>::Type);
#		else
template <typename RangeT_>
struct Iterator : Iterator_<typename RemoveCV<RangeT_>::Type> {
};
#		endif
#	endif

DD_DETAIL_END_

DD_BEGIN_
using detail_::Iterator;
#	if __cplusplus >= 201103L
using detail_::IteratorType;
#	endif

DD_END_

#endif


text:
This is a simple implementation of a dynamic search using Angular JS

A demo can be previewed at: http://stewartium.com/apps/checkins/


text:
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Diagnostics.Contracts;
using System;

// Disable the "this variable is not used" warning as every field would imply it.
#pragma warning disable 0414
// Disable the "this variable is never assigned to".
#pragma warning disable 0067
// Disable the "this event is never assigned to".
#pragma warning disable 0649
// Disable the "this variable is never used".
#pragma warning disable 0169
// Disable the "new keyword not required" warning.
#pragma warning disable 0109
// Disable the "extern without DllImport" warning.
#pragma warning disable 0626
// Disable the "could hide other member" warning, can happen on certain properties.
#pragma warning disable 0108

namespace System.ServiceModel.Dispatcher
{
  internal partial interface IListenerBinder
  {
    #region Methods and constructors
    IChannelBinder Accept(TimeSpan timeout);

    IAsyncResult BeginAccept(TimeSpan timeout, AsyncCallback callback, Object state);

    IChannelBinder EndAccept(IAsyncResult result);
    #endregion

    #region Properties and indexers
    System.ServiceModel.Channels.IChannelListener Listener
    {
      get;
    }

    System.ServiceModel.Channels.MessageVersion MessageVersion
    {
      get;
    }
    #endregion
  }
}


text:
{% load i18n %}
{% load static %}

{% trans "Vorschau Ihres Eintrages" %}

{% trans 'Wenn Sie Ihren Beitrag so abschicken möchten, tippen Sie bitte auf "Weiter".' %}

	<form>

{% trans "Zurück" %}

{% trans "Weiter" %}

	</form>


text:
package remote

import (
	"context"
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/m3db/m3/src/metrics/policy"
	"github.com/m3db/m3/src/query/api/v1/handler/prometheus/handleroptions"
	"github.com/m3db/m3/src/query/block"
	"github.com/m3db/m3/src/query/generated/proto/rpcpb"
	rpc "github.com/m3db/m3/src/query/generated/proto/rpcpb"
	"github.com/m3db/m3/src/query/models"
	"github.com/m3db/m3/src/query/storage"
	"github.com/m3db/m3/src/query/storage/m3/storagemetadata"
	"github.com/m3db/m3/src/query/util/logging"
	"github.com/m3db/m3/src/x/instrument"
	xtime "github.com/m3db/m3/src/x/time"

	"google.golang.org/grpc/metadata"
)

const reqIDKey = "reqid"

func fromTime(t time.Time) int64 {
	return storage.TimeToPromTimestamp(xtime.ToUnixNano(t))
}

func toTime(t int64) time.Time {
	return storage.PromTimestampToTime(t)
}

func encodeTags(tags models.Tags) []*rpc.Tag {
	encodedTags := make([]*rpc.Tag, 0, tags.Len())
	for _, t := range tags.Tags {
		encodedTags = append(encodedTags, &rpc.Tag{
			Name:  t.Name,
			Value: t.Value,
		})
	}

	return encodedTags
}

// encodeFetchResult  encodes fetch result to rpc response
func encodeFetchResult(results *storage.FetchResult) *rpc.FetchResponse {
	series := make([]*rpc.Series, len(results.SeriesList))
	for i, result := range results.SeriesList {
		vLen := result.Len()
		datapoints := make([]*rpc.Datapoint, vLen)
		for j := 0; j < vLen; j++ {
			dp := result.Values().DatapointAt(j)
			datapoints[j] = &rpc.Datapoint{
				Timestamp: int64(dp.Timestamp),
				Value:     dp.Value,
			}
		}

		series[i] = &rpc.Series{
			Meta: &rpc.SeriesMetadata{
				Id: result.Name(),
			},
			Value: &rpc.Series_Decompressed{
				Decompressed: &rpc.DecompressedSeries{
					Datapoints: datapoints,
					Tags:       encodeTags(result.Tags),
				},
			},
		}
	}

	return &rpc.FetchResponse{
		Series: series,
		Meta:   encodeResultMetadata(results.Metadata),
	}
}

// encodeFetchRequest encodes fetch request into rpc FetchRequest
func encodeFetchRequest(
	query *storage.FetchQuery,
	options *storage.FetchOptions,
) (*rpc.FetchRequest, error) {
	matchers, err := encodeTagMatchers(query.TagMatchers)
	if err != nil {
		return nil, err
	}

	opts, err := encodeFetchOptions(options)
	if err != nil {
		return nil, err
	}

	return &rpc.FetchRequest{
		Start: fromTime(query.Start),
		End:   fromTime(query.End),
		Matchers: &rpc.FetchRequest_TagMatchers{
			TagMatchers: matchers,
		},
		Options: opts,
	}, nil
}

func encodeTagMatchers(modelMatchers models.Matchers) (*rpc.TagMatchers, error) {
	if modelMatchers == nil {
		return nil, nil
	}

	matchers := make([]*rpc.TagMatcher, len(modelMatchers))
	for i, matcher := range modelMatchers {
		t, err := encodeMatcherTypeToProto(matcher.Type)
		if err != nil {
			return nil, err
		}

		matchers[i] = &rpc.TagMatcher{
			Name:  matcher.Name,
			Value: matcher.Value,
			Type:  t,
		}
	}

	return &rpc.TagMatchers{
		TagMatchers: matchers,
	}, nil
}

func encodeFanoutOption(opt storage.FanoutOption) (rpc.FanoutOption, error) {
	switch opt {
	case storage.FanoutDefault:
		return rpc.FanoutOption_DEFAULT_OPTION, nil
	case storage.FanoutForceDisable:
		return rpc.FanoutOption_FORCE_DISABLED, nil
	case storage.FanoutForceEnable:
		return rpc.FanoutOption_FORCE_ENABLED, nil
	}

	return 0, fmt.Errorf("unknown fanout option for proto encoding: %v", opt)
}

func encodeFetchOptions(options *storage.FetchOptions) (*rpc.FetchOptions, error) {
	if options == nil {
		return nil, nil
	}

	fanoutOpts := options.FanoutOptions
	result := &rpc.FetchOptions{
		Limit:  int64(options.SeriesLimit),
		Source: options.Source,
	}

	unagg, err := encodeFanoutOption(fanoutOpts.FanoutUnaggregated)
	if err != nil {
		return nil, err
	}

	result.Unaggregated = unagg
	agg, err := encodeFanoutOption(fanoutOpts.FanoutAggregated)
	if err != nil {
		return nil, err
	}

	result.Aggregated = agg
	aggOpt, err := encodeFanoutOption(fanoutOpts.FanoutAggregatedOptimized)
	if err != nil {
		return nil, err
	}

	result.AggregatedOptimized = aggOpt
	if v := options.RestrictQueryOptions; v != nil {
		restrict, err := encodeRestrictQueryOptions(v)
		if err != nil {
			return nil, err
		}

		result.Restrict = restrict
	}

	if v := options.LookbackDuration; v != nil {
		result.LookbackDuration = int64(*v)
	}

	return result, nil
}

func encodeRestrictQueryOptionsByType(
	o *storage.RestrictByType,
) (*rpcpb.RestrictQueryType, error) {
	if o == nil {
		return nil, nil
	}

	if err := o.Validate(); err != nil {
		return nil, err
	}

	result := &rpcpb.RestrictQueryType{}
	switch o.MetricsType {
	case storagemetadata.UnaggregatedMetricsType:
		result.MetricsType = rpcpb.MetricsType_UNAGGREGATED_METRICS_TYPE
	case storagemetadata.AggregatedMetricsType:
		result.MetricsType = rpcpb.MetricsType_AGGREGATED_METRICS_TYPE

		storagePolicyProto, err := o.StoragePolicy.Proto()
		if err != nil {
			return nil, err
		}

		result.MetricsStoragePolicy = storagePolicyProto
	}

	return result, nil
}

func encodeRestrictQueryOptionsByTag(
	o *storage.RestrictByTag,
) (*rpcpb.RestrictQueryTags, error) {
	if o == nil {
		return nil, nil
	}

	matchers, err := encodeTagMatchers(o.GetMatchers())
	if err != nil {
		return nil, err
	}

	return &rpcpb.RestrictQueryTags{
		Restrict: matchers,
		Strip:    o.Strip,
	}, nil
}

func encodeRestrictQueryOptions(
	o *storage.RestrictQueryOptions,
) (*rpcpb.RestrictQueryOptions, error) {
	if o == nil {
		return nil, nil
	}

	byType, err := encodeRestrictQueryOptionsByType(o.GetRestrictByType())
	if err != nil {
		return nil, err
	}

	byTags, err := encodeRestrictQueryOptionsByTag(o.GetRestrictByTag())
	if err != nil {
		return nil, err
	}

	return &rpcpb.RestrictQueryOptions{
		RestrictQueryType: byType,
		RestrictQueryTags: byTags,
	}, nil
}

func encodeMatcherTypeToProto(t models.MatchType) (rpc.MatcherType, error) {
	switch t {
	case models.MatchEqual:
		return rpc.MatcherType_EQUAL, nil
	case models.MatchNotEqual:
		return rpc.MatcherType_NOTEQUAL, nil
	case models.MatchRegexp:
		return rpc.MatcherType_REGEXP, nil
	case models.MatchNotRegexp:
		return rpc.MatcherType_NOTREGEXP, nil
	case models.MatchField:
		return rpc.MatcherType_EXISTS, nil
	case models.MatchNotField:
		return rpc.MatcherType_NOTEXISTS, nil
	case models.MatchAll:
		return rpc.MatcherType_ALL, nil
	default:
		return 0, fmt.Errorf("unknown matcher type for proto encoding")
	}
}

// encodeMetadata creates a context that propagates request metadata as well as requestID
func encodeMetadata(ctx context.Context, requestID string) context.Context {
	if ctx == nil {
		return ctx
	}

	headerValues := ctx.Value(handleroptions.RequestHeaderKey)
	headers, ok := headerValues.(http.Header)
	if !ok {
		return metadata.NewOutgoingContext(ctx, metadata.MD{reqIDKey: []string{requestID}})
	}

	return metadata.NewOutgoingContext(ctx, convertHeaderToMetaWithID(headers, requestID))
}

func convertHeaderToMetaWithID(headers http.Header, requestID string) metadata.MD {
	meta := make(metadata.MD, len(headers)+1)
	meta[reqIDKey] = []string{requestID}

	// Metadata keys must be in lowe case
	for k, v := range headers {
		meta[strings.ToLower(k)] = v
	}

	return meta
}

// creates a context with propagated request metadata as well as requestID
func retrieveMetadata(
	streamCtx context.Context,
	instrumentOpts instrument.Options,
) context.Context {
	md, ok := metadata.FromIncomingContext(streamCtx)
	id := "unknown"
	if ok {
		ids := md[reqIDKey]
		if len(ids) == 1 {
			id = ids[0]
		}
	}

	return logging.NewContextWithID(streamCtx, id, instrumentOpts)
}

func decodeFetchRequest(
	req *rpc.FetchRequest,
) (*storage.FetchQuery, error) {
	tags, err := decodeTagMatchers(req.GetTagMatchers())
	if err != nil {
		return nil, err
	}

	return &storage.FetchQuery{
		TagMatchers: tags,
		Start:       toTime(req.Start),
		End:         toTime(req.End),
	}, nil
}

func decodeTagMatchers(rpcMatchers *rpc.TagMatchers) (models.Matchers, error) {
	tagMatchers := rpcMatchers.GetTagMatchers()
	matchers := make([]models.Matcher, len(tagMatchers))
	for i, matcher := range tagMatchers {
		matchType, name, value := models.MatchType(matcher.GetType()), matcher.GetName(), matcher.GetValue()
		mMatcher, err := models.NewMatcher(matchType, name, value)
		if err != nil {
			return matchers, err
		}

		matchers[i] = mMatcher
	}

	return models.Matchers(matchers), nil
}

func decodeFanoutOption(opt rpc.FanoutOption) (storage.FanoutOption, error) {
	switch opt {
	case rpc.FanoutOption_DEFAULT_OPTION:
		return storage.FanoutDefault, nil
	case rpc.FanoutOption_FORCE_DISABLED:
		return storage.FanoutForceDisable, nil
	case rpc.FanoutOption_FORCE_ENABLED:
		return storage.FanoutForceEnable, nil
	}

	return 0, fmt.Errorf("unknown fanout option for proto encoding: %v", opt)
}

func decodeRestrictQueryOptionsByType(
	p *rpc.RestrictQueryType,
) (*storage.RestrictByType, error) {
	if p == nil {
		return nil, nil
	}

	result := &storage.RestrictByType{}
	switch p.GetMetricsType() {
	case rpcpb.MetricsType_UNAGGREGATED_METRICS_TYPE:
		result.MetricsType = storagemetadata.UnaggregatedMetricsType
	case rpcpb.MetricsType_AGGREGATED_METRICS_TYPE:
		result.MetricsType = storagemetadata.AggregatedMetricsType
	}

	if p.GetMetricsStoragePolicy() != nil {
		storagePolicy, err := policy.NewStoragePolicyFromProto(
			p.MetricsStoragePolicy)
		if err != nil {
			return result, err
		}

		result.StoragePolicy = storagePolicy
	}

	if err := result.Validate(); err != nil {
		return nil, err

	}

	return result, nil
}

func decodeRestrictQueryOptionsByTag(
	p *rpc.RestrictQueryTags,
) (*storage.RestrictByTag, error) {
	if p == nil {
		return nil, nil
	}

	matchers, err := decodeTagMatchers(p.GetRestrict())
	if err != nil {
		return nil, err
	}

	return &storage.RestrictByTag{
		Restrict: matchers,
		Strip:    p.Strip,
	}, nil
}

func decodeRestrictQueryOptions(
	p *rpc.RestrictQueryOptions,
) (*storage.RestrictQueryOptions, error) {
	if p == nil {
		return nil, nil
	}

	byType, err := decodeRestrictQueryOptionsByType(p.GetRestrictQueryType())
	if err != nil {
		return nil, err
	}

	byTag, err := decodeRestrictQueryOptionsByTag(p.GetRestrictQueryTags())
	if err != nil {
		return nil, err
	}

	return &storage.RestrictQueryOptions{
		RestrictByType: byType,
		RestrictByTag:  byTag,
	}, nil
}

func decodeFetchOptions(rpcFetchOptions *rpc.FetchOptions) (*storage.FetchOptions, error) {
	result := storage.NewFetchOptions()
	result.Remote = true
	if rpcFetchOptions == nil {
		return result, nil
	}

	result.SeriesLimit = int(rpcFetchOptions.Limit)
	unagg, err := decodeFanoutOption(rpcFetchOptions.GetUnaggregated())
	if err != nil {
		return nil, err
	}

	agg, err := decodeFanoutOption(rpcFetchOptions.GetAggregated())
	if err != nil {
		return nil, err
	}

	aggOpt, err := decodeFanoutOption(rpcFetchOptions.GetAggregatedOptimized())
	if err != nil {
		return nil, err
	}

	result.FanoutOptions = &storage.FanoutOptions{
		FanoutUnaggregated:        unagg,
		FanoutAggregated:          agg,
		FanoutAggregatedOptimized: aggOpt,
	}

	if v := rpcFetchOptions.Restrict; v != nil {
		restrict, err := decodeRestrictQueryOptions(v)
		if err != nil {
			return nil, err
		}

		result.RestrictQueryOptions = restrict
	}

	if v := rpcFetchOptions.LookbackDuration; v > 0 {
		duration := time.Duration(v)
		result.LookbackDuration = &duration
	}

	result.Source = rpcFetchOptions.Source
	return result, nil
}

func encodeResolutions(res []time.Duration) []int64 {
	encoded := make([]int64, 0, len(res))
	for _, r := range res {
		encoded = append(encoded, int64(r))
	}

	return encoded
}

func encodeResultMetadata(meta block.ResultMetadata) *rpc.ResultMetadata {
	warnings := make([]*rpc.Warning, 0, len(meta.Warnings))
	for _, warn := range meta.Warnings {
		warnings = append(warnings, &rpc.Warning{
			Name:    []byte(warn.Name),
			Message: []byte(warn.Message),
		})
	}

	return &rpc.ResultMetadata{
		Exhaustive:  meta.Exhaustive,
		Warnings:    warnings,
		Resolutions: encodeResolutions(meta.Resolutions),
	}
}

func decodeResolutions(res []int64) []time.Duration {
	decoded := make([]time.Duration, 0, len(res))
	for _, d := range res {
		decoded = append(decoded, time.Duration(d))
	}

	return decoded
}

func decodeResultMetadata(meta *rpc.ResultMetadata) block.ResultMetadata {
	rpcWarnings := meta.GetWarnings()
	warnings := make([]block.Warning, 0, len(rpcWarnings))
	for _, warn := range rpcWarnings {
		warnings = append(warnings, block.Warning{
			Name:    string(warn.Name),
			Message: string(warn.Message),
		})
	}

	return block.ResultMetadata{
		Exhaustive:  meta.Exhaustive,
		Warnings:    warnings,
		Resolutions: decodeResolutions(meta.GetResolutions()),
	}
}


text:
<!DOCTYPE html>

    <title>Matthew Chan| Web Developer</title>
    <link rel="stylesheet" type="text/css" href="./stylesheets/blog_template.css">
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Lora' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>

            home
            about
            blog
            projects
            resources

Public vs Private Interface

On Interface.

Today I was exposed to the idea of interface, or how much of a object should you expose to your users. A central component of good object-oriented design is understanding how much of your object to expose. Let's take a look at an example I created today.

In this challenge, I was asked to design a program that would allow users to create a new bank account. After thinking about what changes a user might want in creating a bank account, I set about creating the interface of my BankAccount class.

Notice the words in red; Public and Private. These words specify which methods are part of my BankAccount class's public interface or private interface. The private interface is an area that is never accessible to the user, therefore it should be a place to store information. The public interface is an area that is accessible to the user. Users can call methods in located here. For example, if a user accidentally entered in an extra letter in his name when he created a new bank account, he will need to be able to change it. However, I don't want anyone to be able to change the name of who the account is registered to, so I prompt the user to type in his account number.


text:
namespace ast {

class expression {
public:
    virtual ~expression() {}
    virtual std::string repr() const = 0;
    virtual const lex::token& start_token() const = 0;
    virtual const lex::token& end_token() const = 0;
};

class literal_expression : public expression {
public:
    literal_expression(const lex::token& token);

    double value() const { return std::stod(token_.str()); }

    virtual std::string repr() const override { return "{literal " + token_.str() + "}"; }
    virtual const lex::token& start_token() const override { return token_; }
    virtual const lex::token& end_token() const override { return token_; }
private:
    lex::token token_;
};

class atom_expression : public expression {
public:
    atom_expression(const lex::token& token);

    std::string id() const { return token_.str(); }

    virtual std::string repr() const override { return "{atom " + token_.str() + "}"; }
    virtual const lex::token& start_token() const override { return token_; }
    virtual const lex::token& end_token() const override { return token_; }
private:
    lex::token token_;
};

class binary_expression : public expression {
public:
    const expression& lhs() const { return *lhs_; }
    const expression& rhs() const { return *rhs_; }
protected:
    binary_expression(std::unique_ptr<expression> lhs, std::unique_ptr<expression> rhs);
private:
    std::unique_ptr<expression> lhs_;
    std::unique_ptr<expression> rhs_;
    virtual const lex::token& start_token() const override { return lhs_->start_token(); }
    virtual const lex::token& end_token() const override { return rhs_->end_token(); }
};

class binary_operation : public binary_expression {
public:
    binary_operation(std::unique_ptr<expression> lhs, std::unique_ptr<expression> rhs, char op);
    virtual std::string repr() const override;
    char op() const { return op_; }
private:
    char op_;
};

class parser {
public:
    explicit parser(const source::file& src) : src_(src), tokenizer_(src_) {
    }

    bool eof() {
        return tokenizer_.eof();
    }

    std::unique_ptr<expression> parse_expression();

private:
    const source::file& src_;
    lex::tokenizer      tokenizer_;

    std::unique_ptr<expression> parse_expression_1(std::unique_ptr<expression> lhs, int min_precedence);
    std::unique_ptr<expression> parse_primary_expression();
    std::runtime_error parse_error(const std::string& message);
};

} // namespace ast

#endif


text:
package org.wso2.carbon.governance.platform.extensions.mediation;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.governance.platform.extensions.util.MediationUtils;
import org.wso2.carbon.ntask.core.Task;

import java.util.Map;

public class MediationArtifactPopulatorTask implements Task {

    private static final Log log = LogFactory.getLog(MediationArtifactPopulatorTask.class);

    @Override
    public void setProperties(Map<String, String> properties) {
        MediationUtils.setUserName(properties.get("userName"));
        MediationUtils.setPassword(properties.get("password"));
        MediationUtils.setServerEpr(properties.get("serverUrl"));
        MediationUtils.setProxyArtifactKey(properties.get("proxyArtifactKey"));
        MediationUtils.setEndpointArtifactKey(properties.get("endpointArtifactKey"));
        MediationUtils.setSequenceArtifactKey(properties.get("sequenceArtifactKey"));
    }

    @Override
    public void init() {
       log.info("MediationArtifactPopulatorTask initialized..");
    }

    @Override
    public void execute() {
        try {
            MediationUtils.populateMediationArtifacts();
        } catch (Exception e) {
          log.error("Error while performing MediationArtifactPopulatorTask" + e.getMessage());
        }
    }

}


text:
require 'faraday_middleware'
require 'hashie/mash'
require 'logger'
require 'openstates/version'
require 'openstates/mashed'
require 'openstates/mashify'
require 'openstates/connection'
require 'openstates/configuration'
require 'openstates/api'
require 'openstates/model'
require 'openstates/models/legislator'
require 'openstates/models/bill'
require 'openstates/models/committee'
require 'openstates/models/district'
require 'openstates/models/event'

module OpenStates
  extend OpenStates::Configuration
  extend OpenStates::Connection
  extend OpenStates::Api
end


text:
<resources>

    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
       <dimen name="slidingmenu_offset">100dp</dimen>
    <dimen name="list_padding">10dp</dimen>
    <dimen name="shadow_width">15dp</dimen>

    <integer name="num_cols">1</integer>

</resources>


text:
package com.sksamuel.elastic4s.requests.cluster

import com.fasterxml.jackson.annotation.JsonProperty

case class NodeUsage(timestamp: Long, since: Long, @JsonProperty("rest_actions") restActions: Map[String, Int])


text:
@interface PodsDummy_HTMINetWork : NSObject
@end
@implementation PodsDummy_HTMINetWork
@end


text:
package metrics

import "github.com/prometheus/client_golang/prometheus"

var (
	// DataSourceQueryTotal is metric counter for getting total number of data source queries
	DataSourceQueryTotal *prometheus.CounterVec

	// ZabbixAPIQueryTotal is metric counter for getting total number of zabbix API queries
	ZabbixAPIQueryTotal *prometheus.CounterVec

	// CacheHitTotal is metric counter for getting total number of cache hits for requests
	CacheHitTotal *prometheus.CounterVec
)

func init() {
	DataSourceQueryTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name:      "datasource_query_total",
			Help:      "Total number of data source queries.",
			Namespace: "zabbix_datasource",
		},
		[]string{"query_type"},
	)

	ZabbixAPIQueryTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name:      "zabbix_api_query_total",
			Help:      "Total number of Zabbix API queries.",
			Namespace: "zabbix_datasource",
		},
		[]string{"method"},
	)

	CacheHitTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name:      "cache_hit_total",
			Help:      "Total number of cache hits.",
			Namespace: "zabbix_datasource",
		},
		[]string{"method"},
	)

	prometheus.MustRegister(
		DataSourceQueryTotal,
		ZabbixAPIQueryTotal,
		CacheHitTotal,
	)
}


text:
from fastapi import FastAPI

app = FastAPI()

@app.get("/items/", tags=["items"])
async def read_items():
    return [{"name": "Foo", "price": 42}]

@app.get("/users/", tags=["users"])
async def read_users():
    return [{"username": "johndoe"}]

@app.get("/elements/", tags=["items"], deprecated=True)
async def read_elements():
    return [{"item_id": "Foo"}]


text:
namespace _06.Filter_Base
{
    using System;
    using System.Collections.Generic;

    public class FilterBase
    {
        public static void Main()
        {
            var usersByAge = new Dictionary<string, string>();
            var usersBySelary = new Dictionary<string, double>();
            var usersByPlace = new Dictionary<string, string>();
            var input = Console.ReadLine();
            while (input != "filter base")
            {
                var temporary = input.Split(' ');
                var name = temporary[0];
                var action = temporary[temporary.Length - 1];

                var integer = 0;
                var flotingpoint = 0.0;

                if (int.TryParse(action, out integer))
                {
                    usersByAge[name] = action;
                }
                else if (double.TryParse(action, out flotingpoint))
                {
                    usersBySelary[name] = flotingpoint;
                }
                else
                {
                    usersByPlace[name] = action;
                }
                input = Console.ReadLine();
            }
            input = Console.ReadLine();
            if (input == "Age")
            {
                foreach (var item in usersByAge)
                {
                    Console.WriteLine($"Name: {item.Key}\nAge: {item.Value}");
                    Console.WriteLine("====================");
                }
            }
            else if (input == "Salary")
            {
                foreach (var item in usersBySelary)
                {
                    Console.WriteLine($"Name: {item.Key}\nSalary: {item.Value.ToString("0.00")}");
                    Console.WriteLine("====================");
                }
            }
            else
            {
                foreach (var item in usersByPlace)
                {
                    Console.WriteLine($"Name: {item.Key}\nPosition: {item.Value}");
                    Console.WriteLine("====================");
                }
            }
        }
    }
}


text:
/**
 *
 * All document ready functions
 *
 */
$(document).ready(function() {

  $(window).resize(function() {
    //console.log("word");
    gallery.utilities.responsive.printScreenWidth();
  });

});


text:
Exercise 2 (ex2)
==================

## Description

This repository contains a Django server for visualizing MODIS fire hostpost layers.

## Installation

Ex2 builds on ex1, as such, please complete the installation instructions for ex1 before continuing, including installing & configuring PostGIS.

https://github.com/pjdufour/ex1#installation

Have you you finished the ex1 installation instructions?  If so, continue.  As root (`sudo su -`), execute the following commands:

```
apt-get update
apt-get install -y supervisor nginx
```

Then, as ubuntu, clone this repo with commands like the following.

```
cd ~
git clone https://github.com/pjdufour/ex2.git ex2.git
```

Then, as root, then install python packages with:
```
cd ex2.git
sudo pip install -r requirements.txt
```

Then, update SITEURL (e.g., http://example.com/) in settings.py:

```
vim ex2.git/ex2/settings.py
```

Create directory for static files for NGINX and copy over static files.

```
sudo mkdir -p /var/www/static
sudo python manage.py collectstatic
```

## Usage

The application can be run through the Django built-in development server or Gnuicron ([http://gunicorn.org/](http://gunicorn.org/)).

There is a [supervisord.conf configuration file](https://github.com/pjdufour/ex2/blob/master/supervisord.conf) that should automate some of this process in a full production environment.  It is configured for vagrant, but can be easily configured for other users.

First prepare the databse.

```
cd ~/ex2.git
python manage.py syncdb
```

If `syncdb` asks if you would like to create an admin user, do it.

This server is configured to access the same database as setup in [Exercise 1](https://github.com/pjdfour/ex1).

You'll need to one `python manage.py importcountrydata.py --source country` once `ex1-init-countries.sh` is run in exercise 1.  Every 24 hours, you'll need to run `python manage.py importhotspotdata.py --source hotspot` if you want to pull in the latest fire data.

To run the application using the Django built-in development server, execute the following:

```
python manage.py runserver [::]:8000
```

To run the application using Gnuicorn, execute the following:

```
gunicorn --workers=4 --worker-class gevent -b 0.0.0.0:8000 ex2.wsgi
or
gunicorn --workers=4 --worker-class gevent -b unix:///tmp/gunicorn.sock --error-logfile error.log ittc.wsgi
```

You can learn more about gunicron configuration at [http://docs.gunicorn.org/en/develop/configure.html](http://docs.gunicorn.org/en/develop/configure.html).

## Contributing

We are not accepting pull requests for this repository.

## License

Copyright (c) 2015, Patrick Dufour
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of ex2 nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


text:
/* This file has been generated by Stubmaker (de.uka.ilkd.stubmaker)
 * Date: Wed Nov 26 11:26:00 CET 2014
 */
package java.nio.file;

public interface DirectoryStream extends java.io.Closeable, java.lang.Iterable
{

   /*@ requires true; ensures true; assignable \everything; */
   public java.util.Iterator iterator();
}