text:
EMAIL_FROM_ADDRESS = 'doesnt@matter.com'

PASSWORD_HASHERS = (
    'django.contrib.auth.hashers.MD5PasswordHasher',
)

MOZILLIANS_API_APPNAME = 'something'
MOZILLIANS_API_BASE = 'https://shouldneveractuallybeused.net'
MOZILLIANS_API_KEY = 'supersecret'

VIDLY_API_URL = 'http://vid.ly.shouldneveractuallybeused.com/api/'

# So that we never accidentally send tweets during tests
TWITTER_CONSUMER_KEY = \
TWITTER_CONSUMER_SECRET = \
TWITTER_ACCESS_TOKEN = \
TWITTER_ACCESS_TOKEN_SECRET = "test"
TWEETER_BACKEND = None

URL_TRANSFORM_PASSWORDS = {
    'bla': 'bla',
}

BITLY_ACCESS_TOKEN = '123456789'
BITLY_URL = 'https://bitly-mock/v3/shorten'

# don't accidentally send anything to sentry whilst running tests
RAVEN_CONFIG = {}
SENTRY_DSN = None

SITE_URL = 'http://localhost:8000'

AWS_ACCESS_KEY_ID = AWS_SECRET_ACCESS_KEY = 'something'
#S3_UPLOAD_BUCKET = 'air-mozilla-uploads'

EDGECAST_SECURE_KEY = 'soemthing'

AKAMAI_SECURE_KEY = 'something'

BROWSERID_AUDIENCES = ['http://testserver']

import tempfile
MEDIA_ROOT = tempfile.mkdtemp(prefix='testmedia')

SCRAPE_CREDENTIALS = {}

LOG_SEARCHES = True

TWITTER_USERNAME = 'airmozilla'

MEDIA_URL = '/media/'
STATIC_URL = '/static/'

VIDLY_BASE_URL = 'https://vid.ly.example'
VIDLY_USER_ID = 'any...'
VIDLY_USER_KEY = '...thing not empty'
EDGECAST_SECURE_KEY = 'anythingheretoo'

ALLOWED_BID = (
    'mozilla.com',
)

# Use memcached only for session storage
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

# deliberately set so tests never actually accidentally use it
AUTOCOMPETER_URL = 'https://autocompeter.example/v1'
AUTOCOMPETER_DOMAIN = ''

# make sure these are definitely off
GOD_MODE = False
BROWSERID_DISABLED = False

# Don't actually use celery in tests
CELERY_ALWAYS_EAGER = True

SCREENCAPTURES_NO_PICTURES = 5 # faster


text:
'use strict';

import React, { PropTypes, Component } from 'react';
import Icon from '../../../_helpers/Icon';

export default class Site extends Component {
  constructor(props) {
    super(props);

    this.onEditBtnClick = this.onEditBtnClick.bind(this);
    this.onDeleteBtnClick = this.onDeleteBtnClick.bind(this);
  }

  onEditBtnClick(e) {
    e.preventDefault();
    const { showEdit, data } = this.props;
    if (showEdit) {
      showEdit('edit', data);
    }
  }

  onDeleteBtnClick(e) {
    e.preventDefault();
    const { deleteSite, unuseCounter, data } = this.props;
    deleteSite(data.id);
    unuseCounter('google', data.google);
    unuseCounter('yandex', data.yandex);
  }

  render() {
    const { type } = this.props;
    return (

          {
            this.props.data &&

                {this.props.data.title} - {type}
                <Icon className={['icon', 'icon--chevron-down']} />

        }

              Edit site

              Delete site

    );
  }
}

Site.propTypes = {
  type: PropTypes.string,
  showEdit: PropTypes.func,
  deleteSite: PropTypes.func,
  unuseCounter: PropTypes.func,
  data: PropTypes.object
};

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CalbucciLib
{
	public class PerfLogger : IDisposable
	{
		private Stopwatch _Stopwatch;
		public static Logger DefaultLogger { get; set; }

		public TimeSpan MaxThreshold { get; set; }

		public string Message { get; set; }

		static PerfLogger()
		{
			DefaultLogger = Logger.Default;
		}

		public PerfLogger(TimeSpan alertThreshold, string message = null, bool autoStart = true)
		{
			MaxThreshold = alertThreshold;
			Message = message;
			if (autoStart)
			{
				_Stopwatch = new Stopwatch();
				_Stopwatch.Start();
			}
		}

		public PerfLogger(int alertThresholdSeconds, string message = null, bool autoStart = true)
		{
			Message = message;
			MaxThreshold = TimeSpan.FromSeconds(alertThresholdSeconds);
			if (autoStart)
			{
				_Stopwatch = new Stopwatch();
				_Stopwatch.Start();
			}
		}

		public void Start()
		{
			if(_Stopwatch != null)
				throw new Exception("PerfLogger can only be started once.");
			_Stopwatch = new Stopwatch();
			_Stopwatch.Start();
		}

		public void Stop()
		{
			if(_Stopwatch != null)
			{
				_Stopwatch.Stop();
				if (_Stopwatch.Elapsed > MaxThreshold)
				{
				    string message = Message ?? "PerfLog > " + MaxThreshold.TotalSeconds.ToString("F") + " secs";
					DefaultLogger.PerfIssue(logEvent =>
					{
						logEvent.Add("Perf", "MaxThreshold", MaxThreshold.TotalSeconds.ToString("F"));
						logEvent.Add("Perf", "Elapsed", _Stopwatch.Elapsed.TotalSeconds.ToString("F"));
					}, message);
				}
				_Stopwatch = null;
			}
		}

		public void Dispose()
		{
			Stop();

		}
	}
}


text:
Given /^I have bookmarked this node$/ do
  user = User.first
  node = Node.first
  FactoryGirl.create(:bookmark, :user => user, :bookmarkable => node)
end

Given /^I have bookmarked this topic$/ do
  user = User.first
  topic = Topic.first
  FactoryGirl.create(:bookmark, :user => user, :bookmarkable => topic)
end

Given /^I have bookmarked (\d+) nodes$/ do |n|
  u = User.first
  n.to_i.times do
    node = FactoryGirl.create(:node)
    FactoryGirl.create(:bookmark, :user => u, :bookmarkable => node)
  end
end

Then /^it should display (\d+) bookmarked nodes$/ do |n|
  page.should have_css('td tr', :count => n.to_i)
end

Given /^I have bookmarked (\d+) topics$/ do |n|
  u = User.first
  n.to_i.times do
    topic = FactoryGirl.create(:topic)
    FactoryGirl.create(:bookmark, :user => u, :bookmarkable => topic)
  end
end

Then /^it should display (\d+) bookmarked topics$/ do |n|
  page.should have_css('td.avatar', :count => n.to_i)
end


text:
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace DotNetty.Codecs
{
    using System;
    using System.Text;

    /// <summary>
    ///     Thrown if an unsupported message is received by an codec.
    /// </summary>
    [Serializable]
    public class UnsupportedMessageTypeException : CodecException
    {
        public UnsupportedMessageTypeException(
            object message, params Type[] expectedTypes)
            : base(ComposeMessage(
                message == null ? "null" : message.GetType().Name, expectedTypes))
        {
        }

        public UnsupportedMessageTypeException()
        {
        }

        public UnsupportedMessageTypeException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        public UnsupportedMessageTypeException(string message)
            : base(message)
        {
        }

        public UnsupportedMessageTypeException(Exception innerException)
            : base(innerException)
        {
        }

        static string ComposeMessage(string actualType, params Type[] expectedTypes)
        {
            var buf = new StringBuilder(actualType);

            if (expectedTypes != null && expectedTypes.Length > 0)
            {
                buf.Append(" (expected: ").Append(expectedTypes[0].Name);
                for (int i = 1; i < expectedTypes.Length; i++)
                {
                    Type t = expectedTypes[i];
                    if (t == null)
                    {
                        break;
                    }
                    buf.Append(", ").Append(t.Name);
                }
                buf.Append(')');
            }

            return buf.ToString();
        }
    }
}


text:
<?php

namespace Eventerza\Dj;

use Eventerza\Address\Services\Repositories\PostalCodeRepository;
use Eventerza\Auth\Services\AuthenticatesUserService;
use Eventerza\Core\App;
use Eventerza\Core\Module\ModuleBootstrapInterface;
use Eventerza\Core\Storage\StorageInterface;
use Eventerza\Dj\Services\Handler\DjRequestHandler;
use Eventerza\Dj\Services\Mapper\DjMapper;
use Eventerza\Dj\Services\Repositories\DjRepository;

/**
 * Class Registration
 *
 * @package Eventerza\Dj
 */
class Registration implements ModuleBootstrapInterface
{
    /**
     * Registration constructor.
     *
     * @param App $app
     */
    public function __construct(App $app)
    {
        $this->configureDI($app);
    }

    /**
     *
     * Configure the dependency injection container
     *
     * @param App $app
     */
    private function configureDI(App $app)
    {
        /** @var \DI\Container $container */
        $container = $app->getContainer();

        $container->set(DjMapper::class, \DI\object());
        $container->set(DjRepository::class, \DI\object()
            ->constructor(
                \DI\get(StorageInterface::class),
                \DI\get(DjMapper::class))
        );
    }
}


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

package app.metatron.discovery.domain.code;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;

import app.metatron.discovery.domain.AbstractHistoryEntity;
import app.metatron.discovery.domain.MetatronDomain;

/**
 * @date        : 2016.04.22
 * @description : CommonCode
 * @author      : lKJ
 */
@Entity
@Table(name="common_code")
public class CommonCode extends AbstractHistoryEntity implements MetatronDomain<Long> {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO, generator="native")
    @GenericGenerator(name = "native", strategy = "native")
    @Column(name = "id")
    Long id;

    @Column(name="CATEGORY_CODE")
    private String categoryCode;

    @Column(name="COMMON_CODE")
    private String commonCode;

    @Column(name="COMMON_VALUE")
    private String commonValue;

    @Column(name="CATEGORY_CODE_NM")
    private String categoryCommonCodeNm;

    @Column(name="COMMON_CODE_NM")
    private String commonCodeNm;

    @Column(name="COMMON_CODE_SNO")
    int commonCodeSNO;

    @Column(name="COMMON_USE_FL")
    private String commonUseFl;

    @Lob
    @Column(name = "DESCRIPTION")
    private String description;

    @Transient
    private String syntax;

    @Transient
    private String example;

    @Transient
    private String param;

    @Transient
    private String descriptionEn;

    @Transient
    private String paramEn;

    @Transient
    private String exampleEn;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCategoryCode() {
        return categoryCode;
    }

    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }

    public String getCommonCode() {
        return commonCode;
    }

    public void setCommonCode(String commonCode) {
        this.commonCode = commonCode;
    }

    public String getCategoryCommonCodeNm() {
        return categoryCommonCodeNm;
    }

    public void setCategoryCommonCodeNm(String categoryCommonCodeNm) {
        this.categoryCommonCodeNm = categoryCommonCodeNm;
    }

    public String getCommonCodeNm() {
        return commonCodeNm;
    }

    public void setCommonCodeNm(String commonCodeNm) {
        this.commonCodeNm = commonCodeNm;
    }

    public int getCommonCodeSNO() {
        return commonCodeSNO;
    }

    public void setCommonCodeSNO(int commonCodeSNO) {
        this.commonCodeSNO = commonCodeSNO;
    }

    public String getCommonUseFl() {
        return commonUseFl;
    }

    public void setCommonUseFl(String commonUseFl) {
        this.commonUseFl = commonUseFl;
    }

    public String getCommonValue() {
        return commonValue;
    }

    public void setCommonValue(String commonValue) {
        this.commonValue = commonValue;
    }

    public String getDescription() { return description; }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSyntax() { return syntax; }

    public void setSyntax(String syntax) { this.syntax = syntax; }

    public String getExample() { return example; }

    public void setExample(String example) { this.example = example; }

    public String getDescriptionEn() { return StringUtils.isBlank(descriptionEn) ? description : descriptionEn; }

    public void setDescriptionEn(String descriptionEn) { this.descriptionEn = descriptionEn; }

    public String getParam() { return param; }

    public void setParam(String param) { this.param = param; }

    public String getParamEn() { return StringUtils.isBlank(paramEn) ? param : paramEn; }

    public void setParamEn(String paramEn) { this.paramEn = paramEn; }

    public String getExampleEn() { return StringUtils.isBlank(exampleEn) ? example : exampleEn; }

    public void setExampleEn(String exampleEn) { this.exampleEn = exampleEn; }

    @Override
    public String toString() {
        return "CommonCode{" +
                "Id='" + id + '\'' +
                "categoryCode='" + categoryCode + '\'' +
                ", commonCode='" + commonCode + '\'' +
                ", categoryCommonCodeNm='" + categoryCommonCodeNm + '\'' +
                ", commonCodeNm='" + commonCodeNm + '\'' +
                ", commonCodeSNO=" + commonCodeSNO +
                ", commonUseFl='" + commonUseFl + '\'' +
                ", commonValue='" + commonValue + '\'' +
                ", description='" + description + '\'' +
                ", syntax='" + syntax + '\'' +
                ", param='" + param + '\'' +
                ", example='" + example + '\'' +
                '}';
    }
}


text:
/**
 * @file utest.h    Public definitions for libutest
 */
#ifndef UTEST_H
#define UTEST_H

#include <stddef.h>

/** @cond HIDDEN */
#define _ut_STRINGIFY_INT(x) #x
#define _ut_STRINGIFY(x) _ut_STRINGIFY_INT(x)

#define _ut_BOLD    "\033[1m"
#define _ut_NORMAL  "\033[0m"

#define _ut_INBOLD(x)   _ut_BOLD x _ut_NORMAL
#define _ut_INBOLD_S(x) _ut_INBOLD(_ut_STRINGIFY(x))

/**
 * Enumeration for callback types: setup and teardown functions. Using these
 * directly is not neecessary.
 */
typedef enum {
    UT_CALLBACK_SETUP,
    UT_CALLBACK_TEARDOWN
} UtCallbackType;

/**
 * Structure with data passed to testing functions.
 * This is an opaque data type, do not access it directly.
 */
typedef struct ut_test_data UtTestData;

/**
 * Type of a test function. Do not use directly.
 */
typedef void (*UtFunc)(UtTestData *);

/**
 * Type of a callback.
 */
typedef void (*UtCallback)(void);

/**
 * Internal macro for defining tests.
 */
#define _ut_UT_SUITE_TEST(suite, suitename, tname)                          \
    static void _ut_test_##suite##_##tname (UtTestData *_ut_test_data);     \
    static void __attribute__((constructor(__COUNTER__ + 101)))             \
    _ut_test_register_##suite##_##tname (void) {                            \
        ut_register_test(suitename, #tname,                                 \
                _ut_test_##suite##_##tname, __FILE__);                      \
    }                                                                       \
    static void _ut_test_##suite##_##tname (UtTestData * _ut_test_data      \
            __attribute__((unused)))

/**
 * Internal macro for defining setup function.
 */
#define _ut_UT_SETUP(id, suitename)                                         \
    static void _ut_setup_##id (void);                                      \
    static void __attribute__((constructor))                                \
    _ut_setup_##id##_register (void) {                                      \
        ut_register_callback(_ut_setup_##id, suitename, UT_CALLBACK_SETUP); \
    }                                                                       \
    static void _ut_setup_##id(void)

/**
 * Internal helper macro for writing simple assertions.
 */
#define _ut_assert_eq_with_type(type, fmt, expected, actual)                \
    do {                                                                    \
        type _ut_exp = expected;                                            \
        type _ut_act = actual;                                              \
        ut_assert_func((_ut_exp) == (_ut_act),                              \
                "Expected <"_ut_INBOLD(fmt)">, got <"_ut_INBOLD(fmt)">",    \
                _ut_exp, _ut_act);                                          \
    } while (0)

/**
 * Internal helper macro for writing teardown functions.
 */
#define _ut_UT_TEARDOWN(id, suitename)                                      \
    static void _ut_teardown_##id (void);                                   \
    static void __attribute__((constructor))                                \
    _ut_teardown_##id##_register (void) {                                   \
        ut_register_callback(_ut_teardown_##id,                             \
                suitename, UT_CALLBACK_TEARDOWN);                           \
    }                                                                       \
    static void _ut_teardown_##id(void)

/**
 * Internal function to register a test.
 *
 * @param suite name of the test suite
 * @param name  name of the test
 * @param f     function to run
 * @param file  file where the test is defined
 */
void ut_register_test(const char *suite, const char *name, UtFunc f,
        const char *file);

/**
 * Internal function to register setup/teardown functions.
 *
 * @param cb    function to be called
 * @param suite name of the modified test suite
 * @param type  0 for setup, 1 for teardown
 */
void ut_register_callback(UtCallback cb, const char *suite, UtCallbackType type);

/** @endcond */

/**
 * Define a new test in global file suite.
 *
 * The test name should be an identifier such as for a function or a variable.
 *
 * @param tname name of the new test
 */
#define UT_TEST(tname)                                                      \
    _ut_UT_SUITE_TEST(def, __FILE__, tname)

/**
 * Define new test in a suite.
 *
 * Both arguments should be identifiers such as for a function or a variable.
 *
 * @param suite name of the suite
 * @param tname test name
 */
#define UT_SUITE_TEST(suite, tname)                                         \
    _ut_UT_SUITE_TEST(suite, #suite, tname)

/**
 * Fail the test unless `exp` evaluates to true.
 *
 * This is the simplest possible assertion. You can use it to perform any kind
 * of test you need. However, using some more specialized assertion, you can
 * get better error message if the assertion fails.
 *
 * @param exp   expression that must evaluate to `TRUE`
 */
#define ut_assert(exp) ut_assert_func(exp, _ut_STRINGIFY(exp))

/**
 * Fail the test unless `exp` evaluates to `NULL`.
 *
 * @param exp   expression that must evaluate to `NULL`
 */
#define ut_assert_null(exp)                                                 \
    ut_assert_func((exp) == NULL,                                           \
            _ut_INBOLD(#exp)" (%p) is not NULL", (void *)(exp))

/**
 * Fail the test if expression evaluates to `NULL`.
 *
 * @param exp   expression that must evaluate to anything but `NULL`
 */
#define ut_assert_not_null(exp)                                             \
    ut_assert_func((exp) != NULL, _ut_INBOLD_S(exp) " is NULL")

/**
 * Fail the test unless two integer values are the same.
 *
 * @param expected  expected value in the second parameter
 * @param actual    expression that evaluates to integer value
 */
#define ut_assert_equal_int(expected, actual)                               \
    _ut_assert_eq_with_type(int, "%d", expected, actual)

/**
 * Fail the test unless two char values are the same.
 *
 * @param expected  expected value in the second parameter
 * @param actual    expression that evaluates to char value
 */
#define ut_assert_equal_char(expected, actual)                              \
    _ut_assert_eq_with_type(char, "%c", expected, actual)

/**
 * Fail the test unless two unsigned integer values are the same.
 *
 * @param expected  expected value in the second parameter
 * @param actual    expression that evaluates to unsigned integer value
 */
#define ut_assert_equal_uint(expected, actual)                              \
    _ut_assert_eq_with_type(unsigned int, "%u", expected, actual)

/**
 * Fail the test unless two strings are both `NULL` or have the same contents.
 *
 * @param expected  expected value of the string
 * @param actual    expression that evaluates to a pointer to `char`
 */
#define ut_assert_equal_string(expected, actual)                            \
    _ut_assert_equal_string(_ut_test_data, __LINE__, expected, actual)

/**
 * Actual string compare assertion.
 *
 * @param data      test data
 * @param line      line from which the assertion was called
 * @param expected  expected string
 * @param actual    actual string
 */
void _ut_assert_equal_string(UtTestData *data, int line,
        const char *expected, const char *actual);

/**
 * Add a setup function to the default file suite.
 *
 * This code will be run before each test in this file that is not explicitly
 * added to a named test suite.
 */
#define UT_SETUP                                                            \
    _ut_UT_SETUP(, __FILE__)

/**
 * Add a setup function to a given test suite.
 *
 * This code will be run before each test in the test suite with given name.
 *
 * @param suitename     the test suite to be extended with this code
 */
#define UT_SUITE_SETUP(suitename)                                           \
    _ut_UT_SETUP(suitename, #suitename)

/**
 * Add a teardown to the default file suite.
 *
 * This code will be run after each test in this file that is not explicitly
 * added to a named test suite.
 */
#define UT_TEARDOWN                                                         \
    _ut_UT_TEARDOWN(, __FILE__)

/**
 * Add a teardown function to a given test suite.
 *
 * This code will be run after each test in the test suite with given name.
 */
#define UT_SUITE_TEARDOWN(suitename)                                        \
    _ut_UT_TEARDOWN(suitename, #suitename)

typedef enum {
    UT_QUIET        = 1 << 0,   /**< Do not print anything at all. */
    UT_NO_FORK      = 1 << 1,   /**< Run each test in separate process. */
    UT_COLOR_NEVER  = 1 << 2,   /**< Never use colors in output. */
    UT_COLOR_ALWAYS = 1 << 3    /**< Always use colors in output. */
} UtFlags;

/**
 * Run all defined tests.
 *
 * @param flags     flags affecting the runtime
 * @return          number of failed tests
 */
int ut_run_all_tests(UtFlags flags);

/**
 * Frontend for _ut_assert_func(). This macro automatically inserts correct
 * file name and line number.
 */
#define ut_assert_func(exp,...)                                            \
    _ut_assert_func(_ut_test_data, __LINE__, exp, __VA_ARGS__)

/**
 * Function implementing the assertion.
 *
 * This function is intended for writing custom assertions. Direct calls
 * are not advised.
 *
 * @param data  test data
 * @param line  line number where the assertion is located
 * @param expr  expression that is tested by the assertion
 * @param msg   `printf`-like format string to print error message in case
 *              assertion fails
 */
void _ut_assert_func(UtTestData *data,
                     int line,
                     int expr,
                     const char *msg,
                     ...)
    __attribute__((format(printf, 4, 5)));

/**
 * Wrapper around `_ut_fail`. This prints standard failure message and marks
 * the assertion as failed. The message includes a filename, which is
 * automatically determined from the current test.
 *
 * @param line  line number to be included in the message
 */
#define ut_fail(line)   _ut_fail(_ut_test_data, line)

/**
 * Mark current assertion as failed and print standard failure message.
 *
 * @param data  test data
 * @param line  line number to be included in the message
 */
void _ut_fail(UtTestData *data, int line);

/**
 * Mark current assertion as passed.
 */
#define ut_pass()   _ut_pass(_ut_test_data);

/**
 * Mark current assertion as passed.
 *
 * @param data  test data
 */
void _ut_pass(UtTestData *data);

/**
 * Print detailed message about failed assertion. This macro uses
 * `printf`-like arguments. The message will be properly indented and
 * followed by appropriate number of newlines.
 */
#define ut_message(...) _ut_message(_ut_test_data, __VA_ARGS);

/**
 * Print detailed message about failed assertion.
 *
 * The message will be properly indented and followed by appropriate number of
 * newlines.
 *
 * @param data  test data
 * @param msg   `printf`-like format string
 * @param ...   the rest of arguments
 */
void _ut_message(UtTestData *data, const char *msg, ...)
    __attribute__((format(printf, 2, 3)));

/**
 * Helper function for the generated main() entrypoint. Do not call this
 * function directly. If you want to use provided functionality, use
 * UT_DEFAULT_MAIN instead to generate whole main function.
 */
int _ut_default_main_worker (int argc, char **argv);

/**
 * This macro expands to a simple main. This main function runs all the
 * defined tests and then exits with number of failed tests.
 */
#define UT_DEFAULT_MAIN                                                     \
    int main (int argc, char **argv)                                        \
    { return _ut_default_main_worker(argc, argv); }

/**
 * Register memory to be freed upon test completion (whether successful or not.
 *
 * @param data  pointer to the data
 * @param func  function to free the data of type `void(*)(void *)`
 * @return      returns the first argument, `data`
 */
#define ut_take_memory(data, func)                                          \
    _ut_take_memory(_ut_test_data, data, func)

typedef void (*UtFreeFunc) (void *);

/**
 * Actual implementation for taking responsibility of data freeing.
 *
 * @param data  test data
 * @param ptr   pointer to be freed
 * @param func  function to perform actual freeing
 * @return      passed pointer
 */
void * _ut_take_memory(UtTestData *data, void *ptr, UtFreeFunc func);

#endif /* end of include guard: UTEST_H */


text:
const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();

const describe = lab.describe;
const experiment = lab.experiment;
const test = lab.test;
const it = lab.it;
const before = lab.before;
const after = lab.after;

const expect = Code.expect;

const _ = require('../src/index');

const options = { parallel: true }

experiment('# Map ', options, () => {
    test('should iterate correctly over collection with promise', options, () => {
      let collection = { a:1, b:2, c:3 }
      let iterator = (value, index, collection) => value * 2

      return _.map(collection, iterator)
        .then((result) => {
          expect(result).to.equal([2,4,6]);
        })
    });

    test('should iterate correctly over collection with callbacks', options, () => {
      let collection = { a:1, b:2, c:3 }
      let iterator = (value, index, collection) => value * 2
      let cb = (result, err) => {
        expect(result).to.equal([2,4,6]);
      }

      return _.map(collection, iterator, cb)
    });

    test('should iterate correctly over array with promise', options, () => {
      let collection = [1,2,3]
      let iterator = (value, index, collection) => value * 2

      return _.map(collection, iterator)
        .then((result) => {
          expect(result).to.equal([2,4,6]);
        })
    });

    test('should iterate correctly over array with callbacks', options, () => {
      let collection = [1,2,3]
      let iterator = (value, index, collection) => value * 2
      let cb = (result, err) => {
        expect(result).to.equal([2,4,6]);
      }

      return _.map(collection, iterator, cb)
    });
  })


text:
module Omnibus
  class ManifestEntry
    attr_reader :locked_version, :locked_source, :source_type, :described_version, :name, :license
    def initialize(name, manifest_data)
      @name = name
      @locked_version = manifest_data[:locked_version]
      @locked_source = manifest_data[:locked_source]
      @source_type = manifest_data[:source_type]
      @described_version = manifest_data[:described_version]
      @license = manifest_data[:license]
    end

    def to_hash
      {
        locked_version: @locked_version,
        locked_source: @locked_source,
        source_type: @source_type,
        described_version: @described_version,
        license: @license,
      }
    end

    def ==(other)
      if other.is_a?(ManifestEntry)
        (to_hash == other.to_hash) && (name == other.name)
      end
    end
  end
end


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Bull. Torrey bot. Club 20: 251 (1893)

#### Original name
Cercospora arctii-ambrosiae Halst.

### Remarks
null


text:
package com.davidleston.stream;

import org.junit.Before;
import org.junit.Test;

import java.util.Comparator;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

import static org.assertj.core.api.Assertions.*;

public class FirstRankCollectorConcurrentTest {

  private Helper<?> collector;

  @Before
  public void beforeEachTest() {
    collector = Helper.create(FirstRankCollector.multiMin.byNaturalOrder());
  }

  @Test
  public void leftCollectedNothing_rightCollectedNothing() {
    assertThat(collector.combineAndFinish()).isEmpty();
  }

  @Test
  public void leftCollectedSomething_rightCollectedNothing() {
    collector.left("a");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("a");
  }

  @Test
  public void leftCollectedNothing_rightCollectedSomething() {
    collector.right("a");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("a");
  }

  @Test
  public void leftCollectedA_rightCollectedA() {
    collector.left("a");
    collector.right("a");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("a", "a");
  }

  @Test
  public void leftCollectedA_rightCollectedB() {
    collector.left("a");
    collector.right("b");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("a");
  }

  @Test
  public void leftCollectedB_rightCollectedA() {
    collector.left("b");
    collector.right("a");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("a");
  }

  @Test
  public void maintainsOrder() {
    collector = Helper.create(FirstRankCollector.multiMin.compareBy(Comparator.comparing(element -> true)));
    collector.left("d");
    collector.left("c");
    collector.right("b");
    collector.right("a");
    List<String> elements = collector.combineAndFinish();
    assertThat(elements).containsExactly("d", "c", "b", "a");
  }

  private static final class Helper<A> {
    private final BiConsumer<A, String> accumulator;
    private final A left;
    private final A right;
    private final BinaryOperator<A> combiner;
    private final Function<A, List<String>> finisher;

    private Helper(Collector<String, A, List<String>> collector) {
      Supplier<A> supplier = collector.supplier();
      accumulator = collector.accumulator();
      left = supplier.get();
      right = supplier.get();
      combiner = collector.combiner();
      finisher = collector.finisher();
    }

    private static <A> Helper<A> create(Collector<String, A, List<String>> collector) {
      return new Helper<>(collector);
    }

    private void left(String element) {
      accumulator.accept(left, element);
    }

    private void right(String element) {
      accumulator.accept(right, element);
    }

    private List<String> combineAndFinish() {
      A container = combiner.apply(left, right);
      return finisher.apply(container);
    }
  }
}


text:
/*
 * Main author: Yann Sagon <yann.sagon@unige.ch>
 */

package jlabos;
import java.io.*;

public class MultiNTensorField3DDouble {
   private jlabos.PlbMultiNTensorField3DDouble block;
   private Descriptor desc;
   private jlabos.Box3D domain;

   public MultiNTensorField3DDouble(jlabos.Box3D domain, int dim){
      System.gc();
      this.domain = domain;
      block = jlabos.double_block.double_generateMultiNTensorField3D(domain, dim);
   }

   public MultiNTensorField3DDouble(jlabos.PlbMultiNTensorField3DDouble block){
      this.block = block;
      domain = block.getBoundingBox();
   }

   public jlabos.MultiNTensorField3DDouble add(double[] val){
      return add(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble add(double[] val, jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_add(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DDouble add(jlabos.MultiNTensorField3DDouble val){
      return add(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble add(jlabos.MultiNTensorField3DDouble val, jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_add(block, val.getObject(), domain));
   }

   public jlabos.MultiNTensorField3DDouble subtract(double[] val){
      return subtract(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble subtract(double[] val, jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_subtract(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DDouble subtract(jlabos.MultiNTensorField3DDouble val){
      return subtract(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble subtract(jlabos.MultiNTensorField3DDouble val, jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_subtract(block, val.getObject(), domain));
   }

   public jlabos.MultiNTensorField3DDouble multiply(double[] val){
      return multiply(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble multiply(double[] val , jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_multiply(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DDouble multiply(jlabos.MultiNTensorField3DDouble val){
      return multiply(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble multiply(jlabos.MultiNTensorField3DDouble val, jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_multiply(block, val.getObject(), domain));
   }

   public jlabos.MultiNTensorField3DDouble toThePower(double[] val){
      return toThePower(val, domain);
   }

   public jlabos.MultiNTensorField3DDouble toThePower(double[] val , jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_toThePower(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DInt lessThan(double[] val){
      return lessThan(val, domain);
   }

   public jlabos.MultiNTensorField3DInt lessThan(double[] val , jlabos.Box3D domain){
      System.gc();
      return new jlabos.MultiNTensorField3DInt(jlabos.double_block.double_lessThan(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DInt greaterThan(double[] val){
      return greaterThan(val, domain);
   }

   public jlabos.MultiNTensorField3DInt greaterThan(double[] val, jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DInt(jlabos.double_block.double_greaterThan(block, val, val.length, domain));
   }

   public jlabos.MultiNTensorField3DDouble strainRate(jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_plbComputeStrainRate(block, domain));
   }

   public jlabos.MultiNTensorField3DDouble symmetricTensorNorm(jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_plbComputeSymmetricTensorNorm(block, domain));
   }

   public void writeToFile(String filename){
      jlabos.Mpi mpi = new jlabos.Mpi();
      double[] myArray = toArray();
      if(mpi.getRankMpi()==0){
         try{
            // Create file
            FileWriter fstream = new FileWriter(filename);
            BufferedWriter out = new BufferedWriter(fstream);
            for (int x=0; x<myArray.length; x++) {
               out.write(Double.toString(myArray[x]));
               out.newLine();
            }
            out.close();
         }catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
         }
      }
   }

   public jlabos.MultiNTensorField3DDouble computeStrainRate(){
      return computeStrainRate(domain);
   }

   public jlabos.MultiNTensorField3DDouble computeStrainRate(jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_plbComputeStrainRate(block, domain));
   }

   public jlabos.MultiNTensorField3DDouble computeSymmetricTensorNorm(jlabos.Box3D domain){
      return new jlabos.MultiNTensorField3DDouble(jlabos.double_block.double_plbComputeSymmetricTensorNorm(block, domain));
   }

   public double average(){
      double[] result = {0.};
      int size = 1;
      jlabos.double_block.double_plbAverage(block, domain, result, size);
      return result[0];
   }

   public double[][] to2DArray(){
      int nx = domain.getNx();
      int ny = domain.getNy();
      int nz = domain.getNz();
      //assert domain.getNy() == 1 : "Matrix must be [x][y][z] with y==1";
      double[] ser = toArray();

      int a = 0;
      int b = 0;

      if(nx == 1){
         a = ny;
         b = nz;
      }else if(ny == 1){
         a = nx;
         b = nz;
      }else if(nz == 1){
         a = nx;
         b = ny;
      }else{
         assert false : "bad dimensions";
      }

      double[][] myArray = new double[a][b];
      for(int x=0; x<a; x++){
         for(int z=0; z<b; z++){
            myArray[x][z] = ser[x*b+z];
         }
      }
      return myArray;
   }

   public double[] toArray(){
      jlabos.double_NTensorFieldSerializer3D mat = new jlabos.double_NTensorFieldSerializer3D(block);
      double[] myArray = new double[mat.getSize()];
      mat.execute(myArray, mat.getSize());
      return myArray;
   }

   public jlabos.PlbMultiNTensorField3DDouble getObject(){
      return this.block;
   }
}


text:
const fs = require('fs');
const request = require('request');
const dateformat = require('dateformat');

download = (uri, filename, callback) => {
    request.head(uri, (err, res, body) => {
        request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
    });
};

exports.setDatabaseHelpers = (db) => {
    db._.mixin({
        findUser: (array, input) => {
            var _in = input.toLowerCase();
            for (var i = 0; i < array.length; i++)
                if (array[i].username.toLowerCase() == _in || array[i].email.toLowerCase() == _in || array[i].uid.toLowerCase() == _in)
                    return array[i];
            return null;
        }
    });
};

exports.getAvatar = (uid, req, res) => {
    download(`https://robohash.org/${uid}`, `./public/images/avatar/${uid}.png`, () => {
        res.redirect('/');
    });
};

exports.getUsers = (mysql, callback) => {
    mysql.query('SELECT * FROM user', (err, rows, fields) => {
        if (err) throw err;
        callback(rows);
    });
};

exports.getUserByUid = (mysql, uid, callback) => {
    mysql.query(`SELECT * FROM user WHERE uid = ?`, [uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows[0]);
    });
};

exports.getUserByEmailOrUsername = (mysql, login, callback) => {
    mysql.query(`SELECT * FROM user WHERE email = ? OR username = ?`, [login, login], (err, rows, fields) => {
        if (err) throw err;
        callback(rows[0]);
    });
};

exports.createOrUpdateUser = (mysql, uid, email, username, password, last_login, salt, callback) => {
    module.exports.getUserByUid(mysql, uid, (user) => {
        if (user != null)
            mysql.query(`UPDATE user SET email = ?, username = ?, password = ?, last_login = ?, salt = ? WHERE uid = ?`, [email, username, password, last_login, salt, uid], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
        else
            mysql.query(`INSERT INTO user VALUES (?, ?, ?, ?, ?, ?)`, [uid, email, username, password, last_login, salt], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
    });
};

exports.removeUser = (mysql, uid, callback) => {
    mysql.query(`DELETE FROM user WHERE uid = ?`, [uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.getPosts = (mysql, callback) => {
    mysql.query('SELECT * FROM post ORDER BY created DESC', (err, rows, fields) => {
        if (err) throw err;
        callback(rows);
    })
};

exports.getPostsByAuthorUid = (mysql, author_uid, callback) => {
    mysql.query(`SELECT uid FROM post WHERE author_uid = ?`, [author_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows.map((val, ind, arr) => {
            return val.uid;
        }));
    });
};

exports.getPostByUid = (mysql, author_uid, uid, callback) => {
    mysql.query(`SELECT * FROM post WHERE author_uid = ? AND uid = ?`, [author_uid, uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows[0]);
    });
};

exports.createOrUpdatePost = (mysql, uid, author_uid, date, message, display, callback) => {
    var created = date.getTime();
    var full_date = dateformat(date, 'dddd, mmmm dS, yyyy, hh:MM TT');
    date = dateformat(date, 'd mmmm yyyy');
    module.exports.getPostByUid(mysql, author_uid, uid, (post) => {
        if (post != null)
            mysql.query(`UPDATE post SET author_uid = ?, date = ?, full_date = ?, message = ?, display = ? WHERE uid = ?`, [author_uid, date, full_date, message, display, uid], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
        else
            mysql.query(`INSERT INTO post VALUES (?, ?, ?, ?, ?, ?, ?)`, [uid, author_uid, date, full_date, message, display, created], (err, rows, fields) => {
                if (err) throw err;
                callback(false);
            });
    });
};

exports.updatePostDisplay = (mysql, uid, display, callback) => {
    mysql.query(`UPDATE post SET display = ? WHERE uid = ?`, [display, uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.removePostByUid = (mysql, uid, callback) => {
    mysql.query(`DELETE FROM post WHERE uid = ?`, [uid], (err, rows, fields) => {
        if (err) throw err;
        module.exports.removeCommentsByPostUid(mysql, uid, (result) => {
            callback(result);
        });
    });
};

exports.removePostsByAuthorUid = (mysql, author_uid, callback) => {
    mysql.query(`DELETE FROM post WHERE author_uid = ?`, [author_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.getHiddenPostsByUserUid = (mysql, user_uid, callback) => {
    mysql.query(`SELECT post_uid FROM hidden WHERE user_uid = ?`, [user_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows.map((val, ind, arr) => {
            return val.post_uid;
        }));
    });
};

exports.getHiddenPost = (mysql, user_uid, post_uid, callback) => {
    mysql.query(`SELECT * FROM hidden WHERE user_uid = ? AND post_uid = ?`, [user_uid, post_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows[0]);
    });
};

exports.createOrUpdateHiddenPost = (mysql, user_uid, post_uid, hide, callback) => {
    module.exports.getHiddenPost(mysql, user_uid, post_uid, (result) => {
        if (result != null && !hide)
            mysql.query(`DELETE FROM hidden WHERE user_uid = ? AND post_uid = ?`, [user_uid, post_uid], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
        else if (!result && hide)
            mysql.query(`INSERT INTO hidden VALUES (?, ?)`, [user_uid, post_uid], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
    });
};

exports.removeHiddenPostsByUserUid = (mysql, user_uid, callback) => {
    mysql.query(`DELETE FROM hidden WHERE user_uid = ?`, [user_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.getComments = (mysql, post_uid, callback) => {
    mysql.query(`SELECT uid FROM comment WHERE post_uid = ? ORDER BY created ASC`, [post_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows.map((val, ind, arr) => {
            return val.uid;
        }));
    });
};

exports.getCommentByUid = (mysql, post_uid, uid, callback) => {
    mysql.query(`SELECT * FROM comment WHERE post_uid = ? AND uid = ?`, [post_uid, uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows[0]);
    });
};

exports.getCommentsByPostUid = (mysql, post_uid, callback) => {
    mysql.query(`SELECT * FROM comment WHERE post_uid = ? ORDER BY created ASC`, [post_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows);
    });
};

exports.getCommentsByAuthorUid = (mysql, author_uid, callback) => {
    mysql.query(`SELECT uid FROM comment WHERE author_uid = ? ORDER BY created DESC`, [author_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(rows.map((val, ind, arr) => {
            return val.uid;
        }));
    });
};

exports.createOrUpdateComment = (mysql, uid, author_uid, author_name, post_uid, date, message, callback) => {
    var created = date.getTime();
    var full_date = dateformat(date, 'dddd, mmmm dS, yyyy, hh:MM TT');
    date = dateformat(date, 'd mmmm yyyy');
    module.exports.getCommentByUid(mysql, post_uid, uid, (comment) => {
        if (comment != null)
            mysql.query(`UPDATE comment SET author_uid = ?, author_name = ?, post_uid = ?, date = ?, full_date = ?, message = ? WHERE uid = ?`, [author_uid, author_name, post_uid, date, full_date, message, uid], (err, rows, fields) => {
                if (err) throw err;
                callback(true);
            });
        else
            mysql.query(`INSERT INTO comment VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [uid, author_uid, author_name, post_uid, date, full_date, message, created], (err, rows, fields) => {
                if (err) throw err;
                callback(false);
            });
    });
}

exports.removeCommentByUid = (mysql, uid, callback) => {
    mysql.query(`DELETE FROM comment WHERE uid = ?`, [uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.removeCommentsByAuthorUid = (mysql, author_uid, callback) => {
    mysql.query(`DELETE FROM comment WHERE author_uid = ?`, [author_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};

exports.removeCommentsByPostUid = (mysql, post_uid, callback) => {
    mysql.query(`DELETE FROM comment WHERE post_uid = ?`, [post_uid], (err, rows, fields) => {
        if (err) throw err;
        callback(true);
    });
};


text:
package nl.mvdr.javafx8sandbox;

import java.util.Arrays;
import java.util.List;

/**
 * Playing around with Collectors for fun. (Not really related to JavaFX.)
 *
 * @author Martijn van de Rijdt
 */
public class CollectorSandbox {
    /**
     * Main method.
     *
     * @param args command line parameters; these are ignored
     */
    public static void main(String[] args) {
        List<String> names = Arrays.asList("Jan", "Klaas", "Piet", "Ton", "Kees", "Sjaak", "Herman", "en", "nog", "meer", "namen");

        long start = System.currentTimeMillis();

        String string = names
                .parallelStream()
                .collect(CollectorSandbox::supply, CollectorSandbox::accumulate, CollectorSandbox::combine)
                .toString();
        System.out.println(string);

        System.out.println("Time spent: " + (System.currentTimeMillis() - start) + "milliseconds.");
    }

    /**
     * Supplies a new string builder.
     *
     * @return
     */
    private static StringBuilder supply() {
        log("Creating new string buffer.");
        return new StringBuilder();
    }

    /**
     * Accumulates the given string into the given string builder.
     *
     * @param builder builder
     * @param string string
     */
    private static void accumulate(StringBuilder builder, String string) {
        log("Appending to builder \"" + builder + "\": \"" + string + "\"");

        try {
            Thread.sleep(1_000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        builder.append(string);
    }

    /**
     * Combines the given builders.
     *
     * @param builder0 builder
     * @param builder1 builder
     */
    private static void combine(StringBuilder builder0, StringBuilder builder1) {
        log("Combining string builders \"" + builder0 + "\" and \"" + builder1 + "\"");
        builder0.append(builder1);
    }

    /**
     * Logs the given message.
     *
     * @param message message
     */
    private static void log(String message) {
        System.out.println(Thread.currentThread().getName() + " - " + message);
    }
}


text:
using System;
using System.Text;

/*
 * General ideas of the Hebrew charset recognition
 *
 * Four main charsets exist in Hebrew:
 * "ISO-8859-8" - Visual Hebrew
 * "windows-1255" - Logical Hebrew
 * "ISO-8859-8-I" - Logical Hebrew
 * "x-mac-hebrew" - ?? Logical Hebrew ??
 *
 * Both "ISO" charsets use a completely identical set of code points, whereas
 * "windows-1255" and "x-mac-hebrew" are two different proper supersets of
 * these code points. windows-1255 defines additional characters in the range
 * 0x80-0x9F as some misc punctuation marks as well as some Hebrew-specific
 * diacritics and additional 'Yiddish' ligature letters in the range 0xc0-0xd6.
 * x-mac-hebrew defines similar additional code points but with a different
 * mapping.
 *
 * As far as an average Hebrew text with no diacritics is concerned, all four
 * charsets are identical with respect to code points. Meaning that for the
 * main Hebrew alphabet, all four map the same values to all 27 Hebrew letters
 * (including final letters).
 *
 * The dominant difference between these charsets is their directionality.
 * "Visual" directionality means that the text is ordered as if the renderer is
 * not aware of a BIDI rendering algorithm. The renderer sees the text and
 * draws it from left to right. The text itself when ordered naturally is read
 * backwards. A buffer of Visual Hebrew generally looks like so:
 * "[last word of first line spelled backwards] [whole line ordered backwards
 * and spelled backwards] [first word of first line spelled backwards]
 * [end of line] [last word of second line] ... etc' "
 * adding punctuation marks, numbers and English text to visual text is
 * naturally also "visual" and from left to right.
 *
 * "Logical" directionality means the text is ordered "naturally" according to
 * the order it is read. It is the responsibility of the renderer to display
 * the text from right to left. A BIDI algorithm is used to place general
 * punctuation marks, numbers and English text in the text.
 *
 * Texts in x-mac-hebrew are almost impossible to find on the Internet. From
 * what little evidence I could find, it seems that its general directionality
 * is Logical.
 *
 * To sum up all of the above, the Hebrew probing mechanism knows about two
 * charsets:
 * Visual Hebrew - "ISO-8859-8" - backwards text - Words and sentences are
 *    backwards while line order is natural. For charset recognition purposes
 *    the line order is unimportant (In fact, for this implementation, even
 *    word order is unimportant).
 * Logical Hebrew - "windows-1255" - normal, naturally ordered text.
 *
 * "ISO-8859-8-I" is a subset of windows-1255 and doesn't need to be
 *    specifically identified.
 * "x-mac-hebrew" is also identified as windows-1255. A text in x-mac-hebrew
 *    that contain special punctuation marks or diacritics is displayed with
 *    some unconverted characters showing as question marks. This problem might
 *    be corrected using another model prober for x-mac-hebrew. Due to the fact
 *    that x-mac-hebrew texts are so rare, writing another model prober isn't
 *    worth the effort and performance hit.
 *
 * *** The Prober ***
 *
 * The prober is divided between two nsSBCharSetProbers and an nsHebrewProber,
 * all of which are managed, created, fed data, inquired and deleted by the
 * nsSBCSGroupProber. The two nsSBCharSetProbers identify that the text is in
 * fact some kind of Hebrew, Logical or Visual. The final decision about which
 * one is it is made by the nsHebrewProber by combining final-letter scores
 * with the scores of the two nsSBCharSetProbers to produce a final answer.
 *
 * The nsSBCSGroupProber is responsible for stripping the original text of HTML
 * tags, English characters, numbers, low-ASCII punctuation characters, spaces
 * and new lines. It reduces any sequence of such characters to a single space.
 * The buffer fed to each prober in the SBCS group prober is pure text in
 * high-ASCII.
 * The two nsSBCharSetProbers (model probers) share the same language model:
 * Win1255Model.
 * The first nsSBCharSetProber uses the model normally as any other
 * nsSBCharSetProber does, to recognize windows-1255, upon which this model was
 * built. The second nsSBCharSetProber is told to make the pair-of-letter
 * lookup in the language model backwards. This in practice exactly simulates
 * a visual Hebrew model using the windows-1255 logical Hebrew model.
 *
 * The nsHebrewProber is not using any language model. All it does is look for
 * final-letter evidence suggesting the text is either logical Hebrew or visual
 * Hebrew. Disjointed from the model probers, the results of the nsHebrewProber
 * alone are meaningless. nsHebrewProber always returns 0.00 as confidence
 * since it never identifies a charset by itself. Instead, the pointer to the
 * nsHebrewProber is passed to the model probers as a helper "Name Prober".
 * When the Group prober receives a positive identification from any prober,
 * it asks for the name of the charset identified. If the prober queried is a
 * Hebrew model prober, the model prober forwards the call to the
 * nsHebrewProber to make the final decision. In the nsHebrewProber, the
 * decision is made according to the final-letters scores maintained and Both
 * model probers scores. The answer is returned in the form of the name of the
 * charset identified, either "windows-1255" or "ISO-8859-8".
 *
 */

namespace UtfUnknown.Core.Probers;

/// <summary>
/// This prober doesn't actually recognize a language or a charset.
/// It is a helper prober for the use of the Hebrew model probers
/// </summary>
internal class HebrewProber : CharsetProber
{
    // windows-1255 / ISO-8859-8 code points of interest
    private const byte FINAL_KAF  = 0xEA;
    private const byte NORMAL_KAF = 0xEB;
    private const byte FINAL_MEM  = 0xED;
    private const byte NORMAL_MEM = 0xEE;
    private const byte FINAL_NUN  = 0xEF;
    private const byte NORMAL_NUN = 0xF0;
    private const byte FINAL_PE = 0xF3;
    private const byte NORMAL_PE = 0xF4;
    private const byte FINAL_TSADI = 0xF5;
    private const byte NORMAL_TSADI = 0xF6;

    // Minimum Visual vs Logical final letter score difference.
    // If the difference is below this, don't rely solely on the final letter score distance.
    private const int MIN_FINAL_CHAR_DISTANCE = 5;

    // Minimum Visual vs Logical model score difference.
    // If the difference is below this, don't rely at all on the model score distance.
    private const float MIN_MODEL_DISTANCE = 0.01f;

    protected const string VISUAL_NAME = CodepageName.ISO_8859_8;
    protected const string LOGICAL_NAME = CodepageName.WINDOWS_1255;

    // owned by the group prober.
    protected CharsetProber logicalProber, visualProber;
    protected int finalCharLogicalScore, finalCharVisualScore;

    // The two last bytes seen in the previous buffer.
    protected byte prev, beforePrev;

    public HebrewProber()
    {
        Reset();
    }

    public void SetModelProbers(CharsetProber logical, CharsetProber visual)
    {
        logicalProber = logical;
        visualProber = visual;
    }

    /**
         * Final letter analysis for logical-visual decision.
         * Look for evidence that the received buffer is either logical Hebrew or
         * visual Hebrew.
         * The following cases are checked:
         * 1) A word longer than 1 letter, ending with a final letter. This is an
         *    indication that the text is laid out "naturally" since the final letter
         *    really appears at the end. +1 for logical score.
         * 2) A word longer than 1 letter, ending with a Non-Final letter. In normal
         *    Hebrew, words ending with Kaf, Mem, Nun, Pe or Tsadi, should not end with
         *    the Non-Final form of that letter. Exceptions to this rule are mentioned
         *    above in isNonFinal(). This is an indication that the text is laid out
         *    backwards. +1 for visual score
         * 3) A word longer than 1 letter, starting with a final letter. Final letters
         *    should not appear at the beginning of a word. This is an indication that
         *    the text is laid out backwards. +1 for visual score.
         *
         * The visual score and logical score are accumulated throughout the text and
         * are finally checked against each other in GetCharSetName().
         * No checking for final letters in the middle of words is done since that case
         * is not an indication for either Logical or Visual text.
         *
         * The input buffer should not contain any white spaces that are not (' ')
         * or any low-ascii punctuation marks.
         */
    public override ProbingState HandleData(byte[] buf, int offset, int len)
    {
        // Both model probers say it's not them. No reason to continue.
        if (GetState() == ProbingState.NotMe)
            return ProbingState.NotMe;

        int max = offset + len;

        for (int i = offset; i < max; i++) {

            byte b = buf[i];

            // a word just ended
            if (b == 0x20) {
                // *(curPtr-2) was not a space so prev is not a 1 letter word
                if (beforePrev != 0x20) {
                    // case (1) [-2:not space][-1:final letter][cur:space]
                    if (IsFinal(prev))
                        finalCharLogicalScore++;
                    // case (2) [-2:not space][-1:Non-Final letter][cur:space]
                    else if (IsNonFinal(prev))
                        finalCharVisualScore++;
                }

            } else {
                // case (3) [-2:space][-1:final letter][cur:not space]
                if ((beforePrev == 0x20) && (IsFinal(prev)) && (b != ' '))
                    ++finalCharVisualScore;
            }
            beforePrev = prev;
            prev = b;
        }

        // Forever detecting, till the end or until both model probers
        // return NotMe (handled above).
        return ProbingState.Detecting;
    }

    // Make the decision: is it Logical or Visual?
    public override string GetCharsetName()
    {
        // If the final letter score distance is dominant enough, rely on it.
        int finalsub = finalCharLogicalScore - finalCharVisualScore;
        if (finalsub >= MIN_FINAL_CHAR_DISTANCE)
            return LOGICAL_NAME;
        if (finalsub <= -(MIN_FINAL_CHAR_DISTANCE))
            return VISUAL_NAME;

        // It's not dominant enough, try to rely on the model scores instead.
        float modelsub = logicalProber.GetConfidence() - visualProber.GetConfidence();
        if (modelsub > MIN_MODEL_DISTANCE)
            return LOGICAL_NAME;
        if (modelsub < -(MIN_MODEL_DISTANCE))
            return VISUAL_NAME;

        // Still no good, back to final letter distance, maybe it'll save the day.
        if (finalsub < 0)
            return VISUAL_NAME;

        // (finalsub > 0 - Logical) or (don't know what to do) default to Logical.
        return LOGICAL_NAME;
    }

    public override void Reset()
    {
        finalCharLogicalScore = 0;
        finalCharVisualScore = 0;
        prev = 0x20;
        beforePrev = 0x20;
    }

    public override ProbingState GetState()
    {
        // Remain active as long as any of the model probers are active.
        if (logicalProber.GetState() == ProbingState.NotMe &&
            visualProber.GetState() == ProbingState.NotMe)
            return ProbingState.NotMe;
        return ProbingState.Detecting;
    }

    public override string DumpStatus()
    {
        StringBuilder status = new StringBuilder();

        status.AppendLine($"  HEB: {finalCharLogicalScore} - {finalCharVisualScore} [Logical-Visual score]");

        return status.ToString();
    }

    public override float GetConfidence(StringBuilder status = null)
    {
        return 0.0f;
    }

    protected static bool IsFinal(byte b)
    {
        return (b == FINAL_KAF || b == FINAL_MEM || b == FINAL_NUN
                || b == FINAL_PE || b == FINAL_TSADI);
    }

    protected static bool IsNonFinal(byte b)
    {
        // The normal Tsadi is not a good Non-Final letter due to words like
        // 'lechotet' (to chat) containing an apostrophe after the tsadi. This
        // apostrophe is converted to a space in FilterWithoutEnglishLetters causing
        // the Non-Final tsadi to appear at an end of a word even though this is not
        // the case in the original text.
        // The letters Pe and Kaf rarely display a related behavior of not being a
        // good Non-Final letter. Words like 'Pop', 'Winamp' and 'Mubarak' for
        // example legally end with a Non-Final Pe or Kaf. However, the benefit of
        // these letters as Non-Final letters outweighs the damage since these words
        // are quite rare.
        return (b == NORMAL_KAF || b == NORMAL_MEM || b == NORMAL_NUN || b == NORMAL_PE);
    }
}


text:
/***Generated Resource **/

var resource = require('resource');
var MedicalSignOrSymptom = resource.define('MedicalSignOrSymptom');

MedicalSignOrSymptom.schema.description = "Any indication of the existence of a medical condition or disease.";
MedicalSignOrSymptom.persist('fs');

MedicalSignOrSymptom.property('additionalType', {
  "name" : "additionalType",
  "displayName" : "Additional Type",
  "description" : "An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in. In RDFa syntax, it is better to use the native RDFa syntax - the 'typeof' attribute - for multiple types. Schema.org tools may have only weaker understanding of extra types, in particular those defined externally.",
"type":  "string"
});

MedicalSignOrSymptom.property('description', {
  "name" : "description",
  "displayName" : "Description",
  "description" : "A short description of the item.",
"type":  "string"
});

MedicalSignOrSymptom.property('image', {
  "name" : "image",
  "displayName" : "Image",
  "description" : "URL of an image of the item.",
"type":  "string"
});

MedicalSignOrSymptom.property('name', {
  "name" : "name",
  "displayName" : "Name",
  "description" : "The name of the item.",
"type":  "string"
});

MedicalSignOrSymptom.property('sameAs', {
  "name" : "sameAs",
  "displayName" : "Same as",
  "description" : "URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Freebase page, or official website.",
"type":  "string"
});

MedicalSignOrSymptom.property('url', {
  "name" : "url",
  "displayName" : "Url",
  "description" : "URL of the item.",
"type":  "string"
});

exports.MedicalSignOrSymptom = MedicalSignOrSymptom;

MedicalSignOrSymptom.property('alternateName', {
  "name" : "alternateName",
  "displayName" : "Alternate Name",
  "description" : "Any alternate name for this medical entity.",
"type":  "string"
});

MedicalSignOrSymptom.property('code', {
  "name" : "code",
  "displayName" : "Code",
  "description" : "A medical code for the entity, taken from a controlled vocabulary or ontology such as ICD-9, DiseasesDB, MeSH, SNOMED-CT, RxNorm, etc.",
"type":"object","properties" : {"MedicalCode" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('guideline', {
  "name" : "guideline",
  "displayName" : "Guideline",
  "description" : "A medical guideline related to this entity.",
"type":"object","properties" : {"MedicalGuideline" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('medicineSystem', {
  "name" : "medicineSystem",
  "displayName" : "Medicine System",
  "description" : "The system of medicine that includes this MedicalEntity, for example 'evidence-based', 'homeopathic', 'chiropractic', etc.",
"type":"object","properties" : {"MedicineSystem" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('recognizingAuthority', {
  "name" : "recognizingAuthority",
  "displayName" : "Recognizing Authority",
  "description" : "If applicable, the organization that officially recognizes this entity as part of its endorsed system of medicine.",
"type":"object","properties" : {"Organization" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('relevantSpecialty', {
  "name" : "relevantSpecialty",
  "displayName" : "Relevant Specialty",
  "description" : "If applicable, a medical specialty in which this entity is relevant.",
"type":"object","properties" : {"MedicalSpecialty" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('study', {
  "name" : "study",
  "displayName" : "Study",
  "description" : "A medical study or trial related to this entity.",
"type":"object","properties" : {"MedicalStudy" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

exports.MedicalSignOrSymptom = MedicalSignOrSymptom;

MedicalSignOrSymptom.property('cause', {
  "name" : "cause",
  "displayName" : "Cause",
  "description" : "An underlying cause. More specifically, one of the causative agent(s) that are most directly responsible for the pathophysiologic process that eventually results in the occurrence.",
"type":"object","properties" : {"MedicalCause" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

MedicalSignOrSymptom.property('possibleTreatment', {
  "name" : "possibleTreatment",
  "displayName" : "Possible Treatment",
  "description" : "A possible treatment to address this condition, sign or symptom.",
"type":"object","properties" : {"MedicalTherapy" :    {"type" :"object",   "properties" : {                    "id" : { "type" : "array" }}}}
});

exports.MedicalSignOrSymptom = MedicalSignOrSymptom;