text:
NSTimeInterval const EFDefaultReviewInterval = 2592000;
NSString* const EFUserDetaultsMarkerDate = @"ef_marker_date";
NSString* const EFUserDetaultsReviewPromptDate = @"ef_review_prompt";
NSString* const EFUserDetailNotProvided = @"[NOT PROVIDED]";

@interface EmailFeedback() {
    UIViewController* root;
    UIAlertView* reviewPrompt;
    UIAlertView* feedbackPrompt;
}

- (NSString*)_defaultEmailBody;
- (void)_processPropertyDictionary:(NSDictionary*)dict fromObject:(id)object intoArray:(NSMutableArray*)array;

@end

@implementation EmailFeedback

#pragma mark Public

- (id)init {
    if (self = [super init]) {
        self.sendUserDetails = YES;
        self.promptReviewAfter = EFDefaultReviewInterval;
        self.repeatPrompt = NO;

        self.reviewPromptTitle = @"Review Us?";
        self.reviewPromptMessage = @"If you like this app, would you mind writing a review for us?";
        self.feedbackPromptTitle = @"Feedback";
        self.feedbackPromptMessage = @"Would you prefer to send us feedback directly to help us improve the app?";
        self.promptCancelLabel = @"No Thanks";
        self.promptReviewLabel = @"Write Review";
        self.promptSendFeedbackLabel = @"Send Feedback";

        self.emailSubject = @"App Feedback";
        self.emailIsHTML = NO;

        NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];

        NSNumber* installDate = [defs objectForKey:EFUserDetaultsMarkerDate];
        if (!installDate) {
            NSTimeInterval now = [NSDate date].timeIntervalSince1970;
            [defs setObject:@(now) forKey:EFUserDetaultsMarkerDate];
        }

        NSNumber* didPrompt = [defs objectForKey:EFUserDetaultsReviewPromptDate];
        if (!didPrompt) {
            [defs setObject:@FALSE forKey:EFUserDetaultsReviewPromptDate];
        }
    }
    return self;
}

- (void)ping {
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSTimeInterval now = [NSDate date].timeIntervalSince1970;
    NSNumber *installTimeObj = [defs objectForKey:EFUserDetaultsMarkerDate];
    NSTimeInterval installTime = installTimeObj.doubleValue;
    if ((now - installTime) > self.promptReviewAfter) {
        BOOL didPrompt = [[defs objectForKey:EFUserDetaultsReviewPromptDate] boolValue];
        if (self.repeatPrompt || !didPrompt) {
            [defs setObject:@TRUE forKey:EFUserDetaultsReviewPromptDate];
        }
        if (self.repeatPrompt) {
            [defs setObject:@(now) forKey:EFUserDetaultsMarkerDate];
        }
    }
}

- (void)promptForReview {
    if (self.reviewURL) {
        reviewPrompt = [[UIAlertView alloc] initWithTitle:self.reviewPromptTitle
                                                  message:self.reviewPromptMessage
                                                 delegate:self
                                        cancelButtonTitle:self.promptCancelLabel
                                        otherButtonTitles:self.promptReviewLabel,nil];
        [reviewPrompt show];
    }
}

- (void)promptForFeedback {
    if ([MFMailComposeViewController canSendMail] && self.emailRecipient && self.emailSubject) {
        feedbackPrompt = [[UIAlertView alloc] initWithTitle:self.feedbackPromptTitle
                                                    message:self.feedbackPromptMessage
                                                   delegate:self
                                          cancelButtonTitle:self.promptCancelLabel
                                          otherButtonTitles:self.promptSendFeedbackLabel, nil];
        [feedbackPrompt show];
    }
}

- (MFMailComposeViewController*)sendFeedback:(BOOL)presentViewController {
    root = [UIApplication sharedApplication].keyWindow.rootViewController;
    MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil
                                                                                bundle:nil];
    [composeViewController setToRecipients:@[self.emailRecipient]];
    [composeViewController setSubject:self.emailSubject];
    if (!self.emailBody) {
        self.emailBody = [self _defaultEmailBody];
    }
    [composeViewController setMessageBody:self.emailBody isHTML:self.emailIsHTML];

    if (presentViewController) {
        composeViewController.mailComposeDelegate = self;
        [root presentViewController:composeViewController animated:YES completion:nil];
    }

    return composeViewController;
}

#pragma mark UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSString* title = [alertView buttonTitleAtIndex:buttonIndex];
    if ([title isEqualToString:self.promptReviewLabel]) {
        [[UIApplication sharedApplication] openURL:self.reviewURL];
    } else if ([title isEqualToString:self.promptSendFeedbackLabel]) {
        [self sendFeedback:true];
    } else if ([title isEqualToString:self.promptCancelLabel] && alertView == reviewPrompt) {
        [self promptForFeedback];
    }
    reviewPrompt = nil;
    feedbackPrompt = nil;
}

#pragma mark MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [root dismissViewControllerAnimated:YES completion:nil];
    root = nil;
}

#pragma mark Private

- (NSString*)_defaultEmailBody {
    if (self.sendUserDetails) {
        NSMutableArray* userData = [[NSMutableArray alloc] init];

        [self _processPropertyDictionary:@{
                                           @"Device Name": @"name",
                                           @"Device System Name": @"systemName",
                                           @"Device System Version": @"systemVersion",
                                           @"Device Model": @"model",
                                           @"Device Localized Model": @"localizedModel",
                                           @"Device Vendor ID": @"identifierForVendor"
                                           }
                              fromObject: [UIDevice currentDevice]
                               intoArray:userData];

        [self _processPropertyDictionary:@{
                                           @"System Version": @"operatingSystemVersionString"
                                           }
                              fromObject:[NSProcessInfo processInfo]
                               intoArray:userData];

        [self _processPropertyDictionary:@{
                                           @"App Bundle": @"CFBundleIdentifier",
                                           @"App Short Version": @"CFBundleShortVersionString",
                                           @"App Version": @"CFBundleVersion"
                                           }
                              fromObject:[[NSBundle mainBundle] infoDictionary]
                               intoArray:userData];

        NSArray* langs = [NSLocale preferredLanguages];
        [userData addObject:[NSString stringWithFormat:@"Languages: %@",[langs componentsJoinedByString:@", "]]];

        return [@"Your feedback ...\n\n\n\n" stringByAppendingString:[userData componentsJoinedByString:@"\n"]];
    } else {
        return @"";
    }
}

- (void)_processPropertyDictionary:(NSDictionary*)dict fromObject:(id)object intoArray:(NSMutableArray*)array {
    for(NSString* key in dict.allKeys) {
        NSString* property = [dict valueForKey:key];
        id value = nil;
        if ([object isKindOfClass:[NSDictionary class]]) {
            value = [object objectForKey:property];
        } else {
            SEL selector = NSSelectorFromString(property);
            if ([object respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                value = [object performSelector:selector];
#pragma clang diagnostic pop
            }
        }
        if (!value) {
            value = EFUserDetailNotProvided;
        }
        [array addObject:[NSString stringWithFormat:@"%@: %@",key,value]];
    }
}

#pragma mark Static

+ (instancetype)defaultFeedback {
    static EmailFeedback* feedback;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        feedback = [[EmailFeedback alloc] init];
    });
    return feedback;
}

@end


text:
package org.jgap;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Abstract class for reproduction operators.  Handles intra-species breeding and someday will handle
 * inter-species breeding.  Each specie gets a number of offspring relative to its fitness, following
 * NEAT paradigm.
 * @author Philip Tucker
 */
public abstract class ReproductionOperator {

private float slice = 0.0f;

/**
 * The reproduce method will be invoked on each of the reproduction operators referenced by the current
 * Configuration object during the evolution phase. Operators are given an opportunity to run in the order
 * they are added to the Configuration.  Iterates over species and determines each one's number of offspring
 * based on fitness, then passes control to subclass reproduce( final Configuration config,
 * final List parents, int numOffspring, List offspring ) method to perform specific reproduction.
 *
 * @param config The current active genetic configuration.
 * @param parentSpecies List contains Specie objects containing parent
 * chromosomes from which to produce offspring.
 * @param offspring List contains offspring ChromosomeMaterial objects; this
 * method adds new offspring to this list
 * @throws InvalidConfigurationException
 * @see ReproductionOperator#reproduce(Configuration, List, int, List)
 */
final public void reproduce( final Configuration config, final List parentSpecies, List offspring )
	throws InvalidConfigurationException
{
	int targetNewOffspringCount = (int) ( ( config.getPopulationSize() * getSlice() ) + 0.5 );

	if ( targetNewOffspringCount > 0 ) {
		if ( parentSpecies.isEmpty() )
			throw new IllegalStateException( "no parent species from which to product offspring" );
		List newOffspring = new ArrayList( targetNewOffspringCount );

		// calculate total fitness
		double totalSpeciesFitness = 0;
		Iterator specieIter = parentSpecies.iterator();
		while ( specieIter.hasNext() ) {
			Specie specie = (Specie) specieIter.next();
			totalSpeciesFitness += specie.getFitnessValue();
		}

		// reproduce from each specie relative to its percentage of total fitness
		specieIter = parentSpecies.iterator();
		while ( specieIter.hasNext() ) {
			Specie specie = (Specie) specieIter.next();
			double percentFitness = specie.getFitnessValue() / totalSpeciesFitness;
			int numSpecieOffspring = (int) ( ( percentFitness * targetNewOffspringCount ) + 0.5 );
			reproduce( config, specie.getChromosomes(), numSpecieOffspring, newOffspring );
		}

		// allow for rounding error - adjust by removing or cloning random offspring
		while ( newOffspring.size() > targetNewOffspringCount ) {
			int idx = config.getRandomGenerator().nextInt( newOffspring.size() );
			newOffspring.remove( idx );
		}
		while ( newOffspring.size() < targetNewOffspringCount ) {
			int idx = config.getRandomGenerator().nextInt( newOffspring.size() );
			ChromosomeMaterial clonee = (ChromosomeMaterial) newOffspring.get( idx );
			newOffspring.add( clonee.clone( null ) );
		}

		offspring.addAll( newOffspring );
	}
}

/**
 * @param config
 * @param parents List contains chromosome objects
 * @param numOffspring # Chromosomes to return in List
 * @param offspring List contains ChromosomeMaterial objects
 * @throws InvalidConfigurationException
 * @see ReproductionOperator#reproduce(Configuration, List, List)
 */
protected abstract void reproduce( final Configuration config, final List parents, int numOffspring, List offspring )
	throws InvalidConfigurationException;

/**
 * @return float slice of population this reproduction operator will fill with offspring
 */
final public float getSlice() {
	return slice;
}

/**
 * @param aSlice slice of population this reproduction operator will fill with offspring
 */
final public void setSlice( float aSlice ) {
	this.slice = aSlice;
}

}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using GenderPayGap.BusinessLogic;
using GenderPayGap.BusinessLogic.Repositories;
using GenderPayGap.BusinessLogic.Services;
using GenderPayGap.Core;
using GenderPayGap.Core.Interfaces;
using GenderPayGap.Database;
using GenderPayGap.Extensions;
using GenderPayGap.Tests.Common.TestHelpers;
using GenderPayGap.Tests.TestHelpers;
using GenderPayGap.WebUI.Controllers;
using GenderPayGap.WebUI.Models.Admin;
using GenderPayGap.WebUI.Tests.TestHelpers;
using NUnit.Framework;

namespace GenderPayGap.WebUI.Tests.Controllers.Administration
{
    public class AdminControllerManualChangesSecurityCodeTests
    {
        private object[] _dbObjects;
        private User _databaseAdminUser;
        private const string TestEmployerReference = "S3CUR1TYC0D3T35T5";
        private const string SetToCreateSecurityCodeCommand = "Create security code";
        private const string SetToExtendSecurityCodeCommand = "Extend security code";
        private const string SetToExpireSecurityCodeCommand = "Expire security code";

        [SetUp]
        public void InitialiseDbObjectsBeforeEachTest()
        {
            var org = OrganisationHelper.GetOrganisationInScope(TestEmployerReference, Global.FirstReportingYear);
            org.SetSecurityCode(DateTime.Now.AddDays(90));
            _databaseAdminUser = UserHelper.GetDatabaseAdmin();
            _dbObjects = new object[] { org, _databaseAdminUser };
        }

        #region methods to complement the tests in this class

        private AdminController GetControllerForOutOfScopeTests()
        {
            var mockedController = UiTestHelper.GetController<AdminController>(_databaseAdminUser.UserId, null, _dbObjects);

            var organisationBusinessLogic = new OrganisationBusinessLogic(
                DependencyResolver.Current.GetService<ICommonBusinessLogic>(),
                DependencyResolver.Current.GetService<IDataRepository>(),
                DependencyResolver.Current.GetService<ISubmissionBusinessLogic>(),
                DependencyResolver.Current.GetService<IScopeBusinessLogic>(),
                DependencyResolver.Current.GetService<ISecurityCodeBusinessLogic>());

            mockedController.OrganisationBusinessLogic = organisationBusinessLogic;
            return mockedController;
        }

        private static ManualChangesViewModel ActOnTheAdminControllerManualChanges(AdminController adminController, ManualChangesViewModel manualChangesViewModel)
        {
            var manualChangesViewResult = adminController.ManualChanges(manualChangesViewModel) as ViewResult;
            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;
            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            return actualManualChangesViewModel;
        }

        #endregion

        [Test]
        public void AdminController_ManualChanges_POST_Expire_SecurityCode_Succeeds_When_Running_In_Test_Mode()
        {
            // Arrange
            var adminControllerToExtendSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = DateTime.Now.AddDays(-10); // in the past, we're expiring
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate:dd/MM/yyyy}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToExpireSecurityCodeCommand, securityCodeExpirationParameters);

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerToExtendSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY TESTED 'Expire security code': 1 of 1");
                Assert.AreEqual(actualManualChangesViewModel.Results, $"1: S3CUR1TYC0D3T35T5: will be updated to be '*******' and to expire on '{securityCodeExpiryDate:dd/MMMM/yyyy}'\r\n");
                Assert.AreEqual(manualChangesViewModelMockObject.LastTestedCommand, actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual($"{securityCodeExpirationParameters}", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be true as this case is running in test mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        [Test]
        public void AdminController_ManualChanges_POST_Exire_SecurityCode_Succeeds_When_Running_In_Live_Mode()
        {
            // Arrange
            var adminControllerToExtendSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = DateTime.Now.AddDays(-10);
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate:dd/MM/yyyy}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToExpireSecurityCodeCommand, securityCodeExpirationParameters);

            /* live */
            manualChangesViewModelMockObject.LastTestedCommand = manualChangesViewModelMockObject.Command;
            manualChangesViewModelMockObject.LastTestedInput = manualChangesViewModelMockObject.Parameters;

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerToExtendSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY EXECUTED 'Expire security code': 1 of 1");
                Assert.True(actualManualChangesViewModel.Results.Contains("1: S3CUR1TYC0D3T35T5: has been updated to be '"));
                Assert.True(actualManualChangesViewModel.Results.Contains($"' and to expire on '{securityCodeExpiryDate:dd/MMMM/yyyy}'\r\n"));
                Assert.Null(actualManualChangesViewModel.LastTestedCommand);
                Assert.Null(actualManualChangesViewModel.LastTestedInput);
                Assert.False(actualManualChangesViewModel.Tested, "Must be Tested=false as this case is running in LIVE mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        #region Expire security code

        #endregion

        #region Extend security code

        [Test]
        public void AdminController_ManualChanges_POST_Extend_SecurityCode_Fails_When_Security_Code_Is_Null()
        {
            // Arrange (data for this test is slightly different than others in this class)
            var organisationWithoutSecurityCode = OrganisationHelper.GetOrganisationInScope(TestEmployerReference, Global.FirstReportingYear);
            organisationWithoutSecurityCode.SecurityCode = null;
            organisationWithoutSecurityCode.SecurityCodeExpiryDateTime = null;
            organisationWithoutSecurityCode.SecurityCodeCreatedDateTime = null;
            _dbObjects = new object[] { organisationWithoutSecurityCode, _databaseAdminUser };

            var adminControllerToExtendSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = $"{DateTime.Now.AddDays(10):dd/MM/yyyy}";
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToExtendSecurityCodeCommand, securityCodeExpirationParameters);

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerToExtendSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY TESTED 'Extend security code': 0 of 1");
                Assert.True(actualManualChangesViewModel.Results.Contains("1: ERROR: 'S3CUR1TYC0D3T35T5' Nothing to modify: Unable to modify the security code expiry date of Organisation 'Org123' employerReference 'S3CUR1TYC0D3T35T5' because it's security code is null"));
                Assert.AreEqual(manualChangesViewModelMockObject.LastTestedCommand, actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual($"{securityCodeExpirationParameters}", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be true as this case is running in test mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        [Test]
        public void AdminController_ManualChanges_POST_Extend_SecurityCode_Succeeds_When_Running_In_Test_Mode()
        {
            // Arrange
            var adminControllerToExtendSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = DateTime.Now.AddDays(10);
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate:dd/MM/yyyy}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToExtendSecurityCodeCommand, securityCodeExpirationParameters);

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerToExtendSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY TESTED 'Extend security code': 1 of 1");
                Assert.AreEqual(actualManualChangesViewModel.Results, $"1: S3CUR1TYC0D3T35T5: will be updated to be '*******' and to expire on '{securityCodeExpiryDate:dd/MMMM/yyyy}'\r\n");
                Assert.AreEqual(manualChangesViewModelMockObject.LastTestedCommand, actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual($"{securityCodeExpirationParameters}", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be true as this case is running in test mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        [Test]
        public void AdminController_ManualChanges_POST_Extend_SecurityCode_Succeeds_When_Running_In_Live_Mode()
        {
            // Arrange
            var adminControllerToExtendSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = DateTime.Now.AddDays(10);
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate:dd/MM/yyyy}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToExtendSecurityCodeCommand, securityCodeExpirationParameters);

            /* live */
            manualChangesViewModelMockObject.LastTestedCommand = manualChangesViewModelMockObject.Command;
            manualChangesViewModelMockObject.LastTestedInput = manualChangesViewModelMockObject.Parameters;

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerToExtendSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY EXECUTED 'Extend security code': 1 of 1");
                Assert.True(actualManualChangesViewModel.Results.Contains("1: S3CUR1TYC0D3T35T5: has been updated to be '"));
                Assert.True(actualManualChangesViewModel.Results.Contains($"' and to expire on '{securityCodeExpiryDate:dd/MMMM/yyyy}'\r\n"));
                Assert.Null(actualManualChangesViewModel.LastTestedCommand);
                Assert.Null(actualManualChangesViewModel.LastTestedInput);
                Assert.False(actualManualChangesViewModel.Tested, "Must be Tested=false as this case is running in LIVE mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        #endregion

        #region Create security code

        [Test]
        public void AdminController_ManualChanges_POST_Create_SecurityCode_Succeeds_When_Running_In_Test_Mode()
        {
            // Arrange
            var adminControllerForCreateSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = DateTime.Now.AddDays(1);
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate:dd/MM/yyyy}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToCreateSecurityCodeCommand, securityCodeExpirationParameters);

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerForCreateSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY TESTED 'Create security code': 1 of 1");
                Assert.True(actualManualChangesViewModel.Results.Contains("1: S3CUR1TYC0D3T35T5: will be updated to be '"));
                Assert.True(actualManualChangesViewModel.Results.Contains($"' and to expire on '{securityCodeExpiryDate:dd/MMMM/yyyy}'"));
                Assert.AreEqual(manualChangesViewModelMockObject.LastTestedCommand, actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual($"{securityCodeExpirationParameters}", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be true as this case is running in test mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        [Test]
        public void AdminController_ManualChanges_POST_Create_SecurityCode_Succeeds_When_Running_In_Live_Mode()
        {
            // Arrange
            var adminControllerForCreateSecurityCodeTests = GetControllerForOutOfScopeTests();
            var securityCodeExpiryDate = $"{DateTime.Now.AddDays(1):dd/MMMM/yyyy}";
            var securityCodeExpirationParameters = $"{TestEmployerReference}={securityCodeExpiryDate}";
            var manualChangesViewModelMockObject = ManualChangesViewModelHelper.GetMock(SetToCreateSecurityCodeCommand, securityCodeExpirationParameters);

            /* live */
            manualChangesViewModelMockObject.LastTestedCommand = manualChangesViewModelMockObject.Command;
            manualChangesViewModelMockObject.LastTestedInput = manualChangesViewModelMockObject.Parameters;

            // Act
            var actualManualChangesViewModel = ActOnTheAdminControllerManualChanges(adminControllerForCreateSecurityCodeTests, manualChangesViewModelMockObject);

            // Assert
            Assert.Multiple(() => {
                Assert.AreEqual(actualManualChangesViewModel.SuccessMessage, "SUCCESSFULLY EXECUTED 'Create security code': 1 of 1");
                Assert.True(actualManualChangesViewModel.Results.Contains("1: S3CUR1TYC0D3T35T5: has been updated to be '"), $"Result [{actualManualChangesViewModel.Results}] does NOT contain Expected [1: S3CUR1TYC0D3T35T5: has been updated to be ']");
                Assert.True(actualManualChangesViewModel.Results.Contains($"' and to expire on '{securityCodeExpiryDate}'"), $"Result [{actualManualChangesViewModel.Results}] does NOT contain Expected [' and to expire on '{securityCodeExpiryDate}']");
                Assert.True(actualManualChangesViewModel.Results.Contains("INFO: Changes saved to database"), $"Result [{actualManualChangesViewModel.Results}] does NOT contain Expected [INFO: Changes saved to database]");
                Assert.Null(actualManualChangesViewModel.LastTestedCommand, "During a LIVE mode execution, the LastTestedCommand is expected to be 'null'");
                Assert.Null(actualManualChangesViewModel.LastTestedInput, "During a LIVE mode execution, the LastTestedInput is expected to be 'null'");
                Assert.False(actualManualChangesViewModel.Tested, "Must be tested=false as this case is running in LIVE mode");
                Assert.Null(actualManualChangesViewModel.Comment);
            });
        }

        #endregion
    }
}


text:
module RSpec
  def self.bdd
    Bdd::FeatureInjection.instance
  end
end

module Bdd
  class FeatureInjection
    include Singleton

    def capability(s, *metadata, &example_group_block)
      data = get_data(*metadata, &example_group_block)
      s_vision = format('Vision', data['vision'])
      RSpec.describe(s_vision, *metadata) do
        goal data['goal'] do
          capability s, type: :feature, &example_group_block
        end
      end
    end

    def uic(s, *metadata, &example_group_block)
      data = get_data(*metadata, &example_group_block)
      s_vision = format('Vision', data['vision'])
      RSpec.describe(s_vision, *metadata) do
        goal data['goal'] do
          capability data['capability'] do
            uic s, type: :feature, &example_group_block
          end
        end
      end
    end

    def api(s, *metadata, &example_group_block)
      data = get_data(*metadata, &example_group_block)
      s_vision = format('Vision', data['vision'])
      RSpec.describe(s_vision, *metadata) do
        goal data['goal'] do
          capability data['capability'] do
            api s, type: :request, &example_group_block
          end
        end
      end
    end

    def get_data(*_metadata, &example_group_block)
      data = Hash.new('-')

      # data = LOAD bdd.yml files from parent folders into
      p = Pathname(example_group_block.source_location.first)
      # data['feature'] = s
      loop do
        break if p.to_s.ends_with? '/spec'
        r = p.join('bdd.yml')
        data.reverse_merge!(YAML.load_file(r)) if r.exist?
        p = p.parent
        xxx = p.join('support.rb')
        xxx.exist? && load(xxx)
      end
      data
    end

    def format(s1, s2)
      [s1.underline.light_white, s2].join(': ')
    end
  end

  module RSpec
    module ExampleGroups
      def dig_context(k, v, *args, &b)
        context(::RSpec.bdd.format(k, v), *args, &b)
      end

      def the_context(s, *args, &b)
        context(::RSpec.bdd.format('Context', s), *args, &b)
      end

      def vision(s, *args, &b)
        context(::RSpec.bdd.format('Vision', s), *args, &b)
      end

      def goal(s, *args, &b)
        context(::RSpec.bdd.format('Goal', s), *args, &b)
      end

      def capability(s, *args, &b)
        context(::RSpec.bdd.format('Capability', s), *args, &b)
      end

      def feature(s, *args, &b)
        context(::RSpec.bdd.format('Feature', s), *args, &b)
      end

      def api(s, *args, &b)
        context(::RSpec.bdd.format('Interface', s), *args, &b)
      end

      def uic(s, *args, &b)
        context(::RSpec.bdd.format('Component', s), *args, &b)
      end

      def role(s, *args, &b)
        context(::RSpec.bdd.format('Role', s), *args, &b)
      end

      def story(s, *args, &b)
        context(::RSpec.bdd.format('Story', s), *args, &b)
      end

      def scenario(s, *args, &b)
        super(::RSpec.bdd.format('Scenario', s), *args, &b)
      end
    end
  end
end

RSpec.configure do |config|
  config.extend Bdd::RSpec::ExampleGroups
end


text:
\c job_manager
insert into status values (DEFAULT, 'Queued');
insert into status values (DEFAULT, 'Active');
insert into status values (DEFAULT, 'Completed');
insert into status values (DEFAULT, 'Error');
insert into status values (DEFAULT, 'Deleted');

insert into job_type values (DEFAULT, 'Sample');


text:
Know Me API
###########

.. image:: https://img.shields.io/travis/knowmetools/km-api.svg
  :target: https://travis-ci.org/knowmetools/km-api

.. image:: https://img.shields.io/codecov/c/github/knowmetools/km-api.svg
  :target: https://codecov.io/gh/knowmetools/km-api

API Root
  https://toolbox.knowmetools.com

API Endpoint Documentation
  https://toolbox.knowmetools.com/docs/

Developer Documentation
  http://know-me-api.readthedocs.io/

*****
About
*****

This is the API behind our Know Me app. It is written in Python using Django and
Django Rest Framework.

**********
Deployment
**********

Changes to this repository are automatically deployed based on the configuration
in `our deployment repository <deploy-repo_>`_.

.. _deploy-repo: https://github.com/knowmetools/km-api-deployment


text:
package org.springframework.security.oauth2.provider.token.store.jwk;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import static org.springframework.security.oauth2.provider.token.store.jwk.JwkAttributes.*;

/**
 * A {@link Converter} that converts the supplied InputStream to a Set of {@link JwkDefinition}(s).
 * The source of the InputStream must be a JWK Set representation which is a JSON object
 * that has a "keys" member and its value is an array of JWKs.
 *

 *

 *
 * NOTE: The Key Type ("kty") currently supported by this {@link Converter} is {@link JwkDefinition.KeyType#RSA}.
 *

 *

 *
 * @see JwkDefinition
 * @see JWK Set Format
 *
 * @author Joe Grandja
 * @author Vedran Pavic
 * @author Michael Duergner
 */
class JwkSetConverter implements Converter<InputStream, Set<JwkDefinition>> {
	private final JsonFactory factory = new JsonFactory();

	/**
	 * Converts the supplied InputStream to a Set of {@link JwkDefinition}(s).
	 *
	 * @param jwkSetSource the source for the JWK Set
	 * @return a Set of {@link JwkDefinition}(s)
	 * @throws JwkException if the JWK Set JSON object is invalid
	 */
	@Override
	public Set<JwkDefinition> convert(InputStream jwkSetSource) {
		Set<JwkDefinition> jwkDefinitions;
		JsonParser parser = null;

		try {
			parser = this.factory.createParser(jwkSetSource);

			if (parser.nextToken() != JsonToken.START_OBJECT) {
				throw new JwkException("Invalid JWK Set Object.");
			}
			if (parser.nextToken() != JsonToken.FIELD_NAME) {
				throw new JwkException("Invalid JWK Set Object.");
			}
			if (!parser.getCurrentName().equals(KEYS)) {
				throw new JwkException("Invalid JWK Set Object. The JWK Set MUST have a " + KEYS + " attribute.");
			}
			if (parser.nextToken() != JsonToken.START_ARRAY) {
				throw new JwkException("Invalid JWK Set Object. The JWK Set MUST have an array of JWK(s).");
			}

			jwkDefinitions = new LinkedHashSet<JwkDefinition>();
			Map<String, String> attributes = new HashMap<String, String>();

			while (parser.nextToken() == JsonToken.START_OBJECT) {
				attributes.clear();
				while (parser.nextToken() == JsonToken.FIELD_NAME) {
					String attributeName = parser.getCurrentName();
					// gh-1082 - skip arrays such as x5c as we can't deal with them yet
					if (parser.nextToken() == JsonToken.START_ARRAY) {
						while (parser.nextToken() != JsonToken.END_ARRAY) {
						}
					} else {
						attributes.put(attributeName, parser.getValueAsString());
					}
				}

				// gh-1470 - skip unsupported public key use (enc) without discarding the entire set
				JwkDefinition.PublicKeyUse publicKeyUse =
						JwkDefinition.PublicKeyUse.fromValue(attributes.get(PUBLIC_KEY_USE));
				if (JwkDefinition.PublicKeyUse.ENC.equals(publicKeyUse)) {
					continue;
				}

				JwkDefinition jwkDefinition = null;
				JwkDefinition.KeyType keyType =
						JwkDefinition.KeyType.fromValue(attributes.get(KEY_TYPE));
				if (JwkDefinition.KeyType.RSA.equals(keyType)) {
					jwkDefinition = this.createRsaJwkDefinition(attributes);
				} else if (JwkDefinition.KeyType.EC.equals(keyType)) {
					jwkDefinition = this.createEllipticCurveJwkDefinition(attributes);
				}
				if (jwkDefinition != null) {
					if (!jwkDefinitions.add(jwkDefinition)) {
						throw new JwkException("Duplicate JWK found in Set: " +
								jwkDefinition.getKeyId() + " (" + KEY_ID + ")");
					}
				}
			}

		} catch (IOException ex) {
			throw new JwkException("An I/O error occurred while reading the JWK Set: " + ex.getMessage(), ex);
		} finally {
			try {
				if (parser != null) parser.close();
			} catch (IOException ex) { }
		}

		return jwkDefinitions;
	}

	/**
	 * Creates a {@link RsaJwkDefinition} based on the supplied attributes.
	 *
	 * @param attributes the attributes used to create the {@link RsaJwkDefinition}
	 * @return a {@link JwkDefinition} representation of a RSA Key
	 * @throws JwkException if at least one attribute value is missing or invalid for a RSA Key
	 */
	private JwkDefinition createRsaJwkDefinition(Map<String, String> attributes) {
		// kid
		String keyId = attributes.get(KEY_ID);
		if (!StringUtils.hasText(keyId)) {
			throw new JwkException(KEY_ID + " is a required attribute for a JWK.");
		}

		// use
		JwkDefinition.PublicKeyUse publicKeyUse =
				JwkDefinition.PublicKeyUse.fromValue(attributes.get(PUBLIC_KEY_USE));
		if (!JwkDefinition.PublicKeyUse.SIG.equals(publicKeyUse)) {
			throw new JwkException((publicKeyUse != null ? publicKeyUse.value() : "unknown") +
					" (" + PUBLIC_KEY_USE + ") is currently not supported.");
		}

		// alg
		JwkDefinition.CryptoAlgorithm algorithm =
				JwkDefinition.CryptoAlgorithm.fromHeaderParamValue(attributes.get(ALGORITHM));
		if (algorithm != null &&
				!JwkDefinition.CryptoAlgorithm.RS256.equals(algorithm) &&
				!JwkDefinition.CryptoAlgorithm.RS384.equals(algorithm) &&
				!JwkDefinition.CryptoAlgorithm.RS512.equals(algorithm)) {
			throw new JwkException(algorithm.standardName() + " (" + ALGORITHM + ") is currently not supported.");
		}

		// n
		String modulus = attributes.get(RSA_PUBLIC_KEY_MODULUS);
		if (!StringUtils.hasText(modulus)) {
			throw new JwkException(RSA_PUBLIC_KEY_MODULUS + " is a required attribute for a RSA JWK.");
		}

		// e
		String exponent = attributes.get(RSA_PUBLIC_KEY_EXPONENT);
		if (!StringUtils.hasText(exponent)) {
			throw new JwkException(RSA_PUBLIC_KEY_EXPONENT + " is a required attribute for a RSA JWK.");
		}

		RsaJwkDefinition jwkDefinition = new RsaJwkDefinition(
				keyId, publicKeyUse, algorithm, modulus, exponent);

		return jwkDefinition;
	}

	/**
	 * Creates an {@link EllipticCurveJwkDefinition} based on the supplied attributes.
	 *
	 * @param attributes the attributes used to create the {@link EllipticCurveJwkDefinition}
	 * @return a {@link JwkDefinition} representation of an EC Key
	 * @throws JwkException if at least one attribute value is missing or invalid for an EC Key
	 */
	private JwkDefinition createEllipticCurveJwkDefinition(Map<String, String> attributes) {
		// kid
		String keyId = attributes.get(KEY_ID);
		if (!StringUtils.hasText(keyId)) {
			throw new JwkException(KEY_ID + " is a required attribute for an EC JWK.");
		}

		// use
		JwkDefinition.PublicKeyUse publicKeyUse =
				JwkDefinition.PublicKeyUse.fromValue(attributes.get(PUBLIC_KEY_USE));
		if (!JwkDefinition.PublicKeyUse.SIG.equals(publicKeyUse)) {
			throw new JwkException((publicKeyUse != null ? publicKeyUse.value() : "unknown") +
					" (" + PUBLIC_KEY_USE + ") is currently not supported.");
		}

		// alg
		JwkDefinition.CryptoAlgorithm algorithm =
				JwkDefinition.CryptoAlgorithm.fromHeaderParamValue(attributes.get(ALGORITHM));
		if (algorithm != null &&
				!JwkDefinition.CryptoAlgorithm.ES256.equals(algorithm) &&
				!JwkDefinition.CryptoAlgorithm.ES384.equals(algorithm) &&
				!JwkDefinition.CryptoAlgorithm.ES512.equals(algorithm)) {
			throw new JwkException(algorithm.standardName() + " (" + ALGORITHM + ") is currently not supported.");
		}

		// x
		String x = attributes.get(EC_PUBLIC_KEY_X);
		if (!StringUtils.hasText(x)) {
			throw new JwkException(EC_PUBLIC_KEY_X + " is a required attribute for an EC JWK.");
		}

		// y
		String y = attributes.get(EC_PUBLIC_KEY_Y);
		if (!StringUtils.hasText(y)) {
			throw new JwkException(EC_PUBLIC_KEY_Y + " is a required attribute for an EC JWK.");
		}

		// crv
		String curve = attributes.get(EC_PUBLIC_KEY_CURVE);
		if (!StringUtils.hasText(curve)) {
			throw new JwkException(EC_PUBLIC_KEY_CURVE + " is a required attribute for an EC JWK.");
		}

		EllipticCurveJwkDefinition jwkDefinition = new EllipticCurveJwkDefinition(
				keyId, publicKeyUse, algorithm, x, y, curve);

		return jwkDefinition;
	}
}


text:
require 'active_record'
require File.dirname(__FILE__) + '/modelfactory/factory'
require File.dirname(__FILE__) + '/modelfactory/legacy'

ActiveRecord::Base.class_eval do
  def self.factory ; ModelFactory[self] ; end
end

module ModelFactory
  # Configure the factory singleton by passing a block.
  #
  # You can call this method multiple times. Each time you do so it will
  # clear the existing configuration and reset the counters.
  #
  # You don't need to configure ModelFactory to use it.
  def self.configure(&block)
    @singleton = Wrapper.new(&block)
  end

  # Get the Factory for a given model class.
  def self.[](klass)
    @singleton ||= Wrapper.new
    @singleton.wrap(klass)
  end

  # Enable legacy API compatibility.
  def self.extended(mod) # :nodoc:
    mod.extend(ModelFactory::Legacy)
  end

  # Singleton Factory wrapper class.
  class Wrapper # :nodoc:
    # Create a new FactoryConfiguration with the given block.
    def initialize(&block)
      @config = FactoryConfiguration.new(&block)
      @factory = {}
    end

    # Wraps a given class in a configured Factory instance.
    def wrap(klass)
      # We might have a definition for a parent class. If so, use that.
      target = klass
      while target && !@config.class_opts.key?(target)
        target = target.superclass
      end
      @factory[klass] ||= Factory.new(klass, @config.class_opts[target])
    end
  end

  # Factory configuration class.
  class FactoryConfiguration # :nodoc:
    attr_reader :class_opts

    def initialize(&block)
      @class_opts = {}
      instance_eval(&block) if block_given?
    end

    # All method calls set up a configuration named after the method.
    def method_missing(method, klass, &block)
      @class_opts[klass] ||= {}
      @class_opts[klass][method] = block
    end

    # Route common method names to method_missing.
    # XXX There must be a better way to do this, assuming we should be doing
    # this at all. BasicObject doesn't work because I lose instance_eval.
    [ :inspect, :send, :id, :object_id ].each do |meth|
      eval %{
        def #{meth}(*args, &block)
          method_missing(:#{meth}, *args, &block)
        end
      }
    end
  end
end


text:
module Metadata

using Dates, FlatBuffers

@enum(DType, BOOL = 0, INT8 = 1, INT16 = 2, INT32 = 3, INT64 = 4,
  UINT8 = 5, UINT16 = 6, UINT32 = 7, UINT64 = 8,
  FLOAT = 9, DOUBLE = 10,  UTF8 = 11,  BINARY = 12,
  CATEGORY = 13, TIMESTAMP = 14, DATE = 15, TIME = 16)

@enum(Encoding, PLAIN = 0, DICTIONARY = 1)

@enum(TimeUnit, SECOND = 0, MILLISECOND = 1, MICROSECOND = 2, NANOSECOND = 3)

# FlatBuffers.enumsizeof(::Type{TimeUnit}) = UInt8

mutable struct PrimitiveArray
    dtype::DType
    encoding::Encoding
    offset::Int64
    length::Int64
    null_count::Int64
    total_bytes::Int64
end

mutable struct CategoryMetadata
    levels::PrimitiveArray
    ordered::Bool
end

@DEFAULT CategoryMetadata ordered=false

mutable struct TimestampMetadata
    unit::TimeUnit
    timezone::String
end

mutable struct DateMetadata
end

mutable struct TimeMetadata
    unit::TimeUnit
end

@UNION TypeMetadata (Nothing,CategoryMetadata,TimestampMetadata,DateMetadata,TimeMetadata)

mutable struct Column
    name::String
    values::PrimitiveArray
    metadata_type::Int8
    metadata::TypeMetadata
    user_metadata::String
end

function Column(name::String, values::PrimitiveArray, metadata::TypeMetadata=nothing,
                user_metadata::String="")
    Column(name, values, FlatBuffers.typeorder(TypeMetadata, typeof(metadata)),
           metadata, user_metadata)
end

mutable struct CTable
    description::String
    num_rows::Int64
    columns::Vector{Column}
    version::Int32
    metadata::String
end

end # module

# wesm/feather/cpp/src/metadata_generated.h
# wesm/feather/cpp/src/types.h
const JULIA_TYPE_DICT = Dict{Metadata.DType,DataType}(
    Metadata.BOOL      => Bool,
    Metadata.INT8      => Int8,
    Metadata.INT16     => Int16,
    Metadata.INT32     => Int32,
    Metadata.INT64     => Int64,
    Metadata.UINT8     => UInt8,
    Metadata.UINT16    => UInt16,
    Metadata.UINT32    => UInt32,
    Metadata.UINT64    => UInt64,
    Metadata.FLOAT     => Float32,
    Metadata.DOUBLE    => Float64,
    Metadata.UTF8      => String,  # can also be WeakRefString{UInt8}
    Metadata.BINARY    => Vector{UInt8},
    Metadata.CATEGORY  => Int64,
    Metadata.TIMESTAMP => Int64,
    Metadata.DATE      => Int64,
    Metadata.TIME      => Int64
)

const METADATA_TYPE_DICT = Dict{DataType,Metadata.DType}(
    Bool    => Metadata.BOOL,
    Int8    => Metadata.INT8,
    Int16   => Metadata.INT16,
    Int32   => Metadata.INT32,
    Int64   => Metadata.INT64,
    UInt8   => Metadata.UINT8,
    UInt16  => Metadata.UINT16,
    UInt32  => Metadata.UINT32,
    UInt64  => Metadata.UINT64,
    Float32 => Metadata.FLOAT,
    Float64 => Metadata.DOUBLE,
    String  => Metadata.UTF8,
    Vector{UInt8} => Metadata.BINARY,
    Dates.Time => Metadata.INT64,
    Dates.DateTime => Metadata.INT64,
    Dates.Date => Metadata.INT32,
    # WeakRefString{UInt8} => Metadata.UTF8  # not currently being used
)

const NON_PRIMITIVE_TYPES = Set([Metadata.UTF8, Metadata.BINARY])

const JULIA_TIME_DICT = Dict{Metadata.TimeUnit,DataType}(
    Metadata.SECOND => Dates.Second,
    Metadata.MILLISECOND => Dates.Millisecond,
    Metadata.MICROSECOND => Dates.Microsecond,
    Metadata.NANOSECOND => Dates.Nanosecond
)
const METADATA_TIME_DICT = Dict{DataType,Metadata.TimeUnit}(v=>k for (k,v) in JULIA_TIME_DICT)

isprimitivetype(t::Metadata.DType) = t ∉ NON_PRIMITIVE_TYPES

juliatype(meta::Nothing, values_type::Metadata.DType) = JULIA_TYPE_DICT[values_type]
juliatype(values_type::Metadata.DType) = juliatype(nothing, values_type)
function juliatype(meta::Metadata.CategoryMetadata, values_type::Metadata.DType)
    JULIA_TYPE_DICT[meta.levels.dtype]
end
function juliatype(meta::Metadata.TimestampMetadata, values_type::Metadata.DType)
    Timestamp{JULIA_TIME_DICT[meta.unit]}
end
function juliatype(meta::Metadata.TimeMetadata, values_type::Metadata.DType)
    TimeOfDay{JULIA_TIME_DICT[meta.unit],JULIA_TYPE_DICT[values_type]}
end
juliatype(meta::Metadata.DateMetadata, values_type::Metadata.DType) = Datestamp

function juliatype(col::Metadata.Column)
    T = juliatype(col.metadata, col.values.dtype)
    col.values.null_count == 0 ? T : Union{T,Missing}
end

function feathertype(::Type{T}) where T
    if T ∉ keys(METADATA_TYPE_DICT)
        throw(ArgumentError("Type $T is not supported by the Feather format."))
    else
        METADATA_TYPE_DICT[T]
    end
end
feathertype(::Type{Union{T,Missing}}) where T = feathertype(T)
feathertype(::Type{<:Arrow.Datestamp}) = Metadata.INT32
feathertype(::Type{<:Arrow.Timestamp}) = Metadata.INT64
feathertype(::Type{<:Arrow.TimeOfDay{P,Int32}}) where P = Metadata.INT32
feathertype(::Type{<:Arrow.TimeOfDay{P,Int64}}) where P = Metadata.INT64

getmetadata(io::IO, ::Type{T}, A::ArrowVector) where T = nothing
getmetadata(io::IO, ::Type{Union{T,Missing}}, A::ArrowVector) where T = getmetadata(io, T, A)
getmetadata(io::IO, ::Type{Arrow.Datestamp}, A::ArrowVector) = Metadata.DateMetadata()
function getmetadata(io::IO, ::Type{Arrow.Timestamp{T}}, A::ArrowVector) where T
    Metadata.TimestampMetadata(METADATA_TIME_DICT[T], "")
end
function getmetadata(io::IO, ::Type{Arrow.TimeOfDay{P,T}}, A::ArrowVector) where {P,T}
    Metadata.TimeMetadata(METADATA_TIME_DICT[P])
end
# WARNING Arrow standard says nothing about specifying whether DictEncoding is ordered!
function getmetadata(io::IO, ::Type{T}, A::DictEncoding) where T
    vals = writecontents(Metadata.PrimitiveArray, io, levels(A))
    Metadata.CategoryMetadata(vals, true)
end
# below method needed to fix method ambiguity
function getmetadata(io::IO, ::Type{Union{T,Missing}}, A::DictEncoding) where {T}
    vals = writecontents(Metadata.PrimitiveArray, io, levels(A))
    Metadata.CategoryMetadata(vals, true)
end


text:
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ServiceProviderExtensions
    {
        public static T GetServiceOr<T>(this IServiceProvider resolver, T defaultValue) where T : class
            => resolver.GetService<T>() ?? defaultValue;

        public static ILoggerFactory GetLoggerFactory(this IServiceProvider resolver)
        {
            return resolver.GetServiceOr<ILoggerFactory>(NullLoggerFactory.Instance);
        }

        public static ILogger CreateLogger(this IServiceProvider provider, string name)
            => provider.GetLoggerFactory().CreateLogger(name);

        public static ILogger CreateLogger(this IServiceProvider provider, Type type)
            => provider.GetLoggerFactory().CreateLogger(type);

        public static ILogger<T> CreateLogger<T>(this IServiceProvider provider)
            => provider.GetLoggerFactory().CreateLogger<T>();

        public static void ResolveAndDo<T>(this IServiceProvider provider, Action<T> action) where T : notnull
        {
            var service = provider.GetRequiredService<T>();
            action(service);
        }

        public static void ResolveAndDo<T1, T2>(this IServiceProvider provider, Action<T1, T2> action) where T1 : notnull where T2 : notnull
        {
            var t1 = provider.GetRequiredService<T1>();
            var t2 = provider.GetRequiredService<T2>();
            action(t1, t2);
        }

        public static Task ResolveAndDoAsync<T>(this IServiceProvider provider, Func<T, Task> action) where T : notnull
        {
            var service = provider.GetRequiredService<T>();
            return action(service);
        }

        public static Task ResolveAndDoAsync<T1, T2>(this IServiceProvider provider, Func<T1, T2, Task> action) where T1 : notnull where T2 : notnull
        {
            var t1 = provider.GetRequiredService<T1>();
            var t2 = provider.GetRequiredService<T2>();
            return action(t1, t2);
        }

        public static TResult ResolveAndDo<T, TResult>(this IServiceProvider provider, Func<T, TResult> action) where T : notnull
        {
            var service = provider.GetRequiredService<T>();
            return action(service);
        }

        public static TResult ResolveAndDo<T1, T2, TResult>(this IServiceProvider provider, Func<T1, T2, TResult> action) where T1 : notnull where T2 : notnull
        {
            var t1 = provider.GetRequiredService<T1>();
            var t2 = provider.GetRequiredService<T2>();
            return action(t1, t2);
        }

        public static Task<TResult> ResolveAndDoAsync<T, TResult>(this IServiceProvider provider, Func<T, Task<TResult>> action) where T : notnull
        {
            var service = provider.GetRequiredService<T>();
            return action(service);
        }

        public static Task<TResult> ResolveAndDoAsync<T1, T2, TResult>(this IServiceProvider provider, Func<T1, T2, Task<TResult>> action) where T1 : notnull where T2 : notnull
        {
            var t1 = provider.GetRequiredService<T1>();
            var t2 = provider.GetRequiredService<T2>();
            return action(t1, t2);
        }
    }
}


text:
<?php

namespace League\Torrent\Helper;

class FileSystem
{
    /**
     *
     * @var int
     */
    const timeout = 30;

    /**
     * List of strings that can start a torrent file
     *
     * @static
     * @var array
     */
    protected static $torrentsChecks = array('d8:announce', 'd10:created', 'd13:creatio', 'd4:info', 'd9:');

    public static function filesize($filename)
    {
        if (is_file($filename)) {
            return (double) sprintf('%u', @filesize($filename));
        } else {
            if ($content_length = preg_grep($pattern = '#^Content-Length:\s+(\d+)$#i', (array) @get_headers($filename))
            ) {
                return (int) preg_replace($pattern, '$1', reset($content_length));
            }
        }
    }

    /**
     * pack data hash to binary
     *
     * @param $data
     *
     * @return string
     */
    public static function pack(& $data)
    {
        return pack('H*', sha1($data)) . ($data = null);
    }

    /**
     * @param $url
     *
     * @return int
     */
    public static function is_url($url)
    {
        return preg_match('#^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$#i', $url);
    }

    /**
     * @param $url
     *
     * @return bool
     */
    public static function url_exists($url)
    {
        return FileSystem::is_url($url) ?
            (bool) FileSystem::filesize($url) :
            false;
    }

    /**
     * @param $announces
     *
     * @return array
     */
    public static function untier($announces)
    {
        $list = array();
        foreach ((array) $announces as $tier) {
            is_array($tier) ?
                $list = array_merge($list, FileSystem::untier($tier)) :
                array_push($list, $tier);
        }
        return $list;
    }

    /**
     * @param $array
     *
     * @return bool
     */
    public static function is_list($array)
    {
        foreach (array_keys($array) as $key) {
            if (!is_int($key)) {
                return false;
            }
        }
        return true;
    }

    /**
     * @param $path
     * @param $folder
     *
     * @return string
     */
    public static function path($path, $folder)
    {
        array_unshift($path, $folder);
        return join(DIRECTORY_SEPARATOR, $path);
    }

    /**
     * @param $dir
     *
     * @return array
     */
    public static function scandir($dir)
    {
        $paths = array();
        foreach (scandir($dir) as $item) {
            if ($item != '.' && $item != '..') {
                if (is_dir($path = realpath($dir . DIRECTORY_SEPARATOR . $item))) {
                    $paths = array_merge(self::scandir($path), $paths);
                } else {
                    $paths[] = $path;
                }
            }
        }
        return $paths;
    }

    /**
     * @param $data
     *
     * @return bool|string
     */
    public static function char($data)
    {
        return empty($data) ?
            false :
            substr($data, 0, 1);
    }

    public static function downloadTorrent($url, $timeout = self::timeout)
    {
        if (ini_get('allow_url_fopen')) {
            return self::downloadViaStream($url, $timeout);
        } else {
            return self::downloadViaCurl($url, $timeout);
        }
    }

    public static function downloadViaStream($url, $timeout = self::timeout)
    {
        if (!ini_get('allow_url_fopen')) {
            throw new \Exception('Install CURL or enable "allow_url_fopen"');
        }

        return file_get_contents($url, false, stream_context_create(array('http' => array('timeout' => $timeout))));
    }

    public static function downloadViaCurl($url, $timeout = self::timeout)
    {
        if (!function_exists('curl_init')) {
            throw new \Exception('Install CURL or enable "allow_url_fopen"');
        }
        $handle = curl_init($url);
        if ($timeout) {
            curl_setopt($handle, CURLOPT_TIMEOUT, $timeout);
        }
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
        $content = curl_exec($handle);
        curl_close($handle);
        return $content;
    }

    /**
     * @param $file
     *
     * @return bool
     */
    public static function isTorrent($file)
    {
        $start = substr($file, 0, 11);
        $check = false;
        foreach (self::$torrentsChecks as $value) {
            if (0 === strpos($start, $value)) {
                $check = true;
                continue;
            }
        }

        return $check;
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;

using Scallion.Core;

namespace Scallion.Raw.Components.Project
{
    internal struct BoneReference
    {
        public readonly static BoneReference Empty = new BoneReference(-1, 0);

        public int ModelIndex { get; set; }
        public int BoneIndex { get; set; }

        public BoneReference(int modelIndex, int boneIndex)
            : this()
        {
            ModelIndex = modelIndex;
            BoneIndex = boneIndex;
        }
    }
}


text:
<Procedure
    title="Girl's Details"
    author="Martin"
    uuid="f37c8a98-09e8-45f8-b763-48e5e3e23696"
    version="1.0"
    locale="en"
    concept="MAPPING FORM"
    class="org.sana.core.Subject"
    on_complete="intent://org.sana.provider/core/procedure/ae0775ec-5a8c-4f2c-8c78-13325e26f03f#Intent;scheme=content;action=org.sana.android.intent.action.RUN_PROCEDURE;type=vnd.android.cursor.item/org.sana.procedure;end">
    <!-- This uuid was picked from registration xml file  !-->
    <Page>
        <Element
            id="1"
            type="TEXT"
            concept="demographics text"
            question="GIRL'S DEMOGRAPHICS DETAILS"
        />
        <Element
            id="2"
            concept="GIVEN NAME"
            type="ENTRY"
            required="true"
            question="Enter First Name"
            answer=""
            helpText="Please enter the given name"
        />
        <Element
            id="3"
            concept="FAMILY NAME"
            type="ENTRY"
            required="true"
            question="Enter Last Name"
            answer=""
        />
        <Element
            id="4"
            concept="DOB"
            type="DATE"
            required="true"
            question="Enter Date of Birth"
            answer=""
        />

        <Element
            id="5"
            concept="AGE"
            type="HIDDEN"
            required="false"
            question="What is your age"
            answer=""/>
    </Page>
    <Page>
        <Element
            id="6"
            concept="PNUMBER"
            type="ENTRY"
            numeric="DIALPAD"
            required="true"
            question="Enter Girl's Phone Number"
            answer=""
            pattern="[0-9]{10}"
            helpText="Enter 10 digit number"
        />
        <Element
            id="7"
            concept="HOLDER PNUMBER"
            type="ENTRY"
            numeric="DIALPAD"
            required="true"
            question="Enter PowerHolder's Number"
            answer=""
            pattern="[0-9]{10}"
            helpText="Enter 10 digit number"
        />
        <Element
            id="8"
            type="DATE"
            question="When was your last Menstruation Date"
            concept="LMD"
            required="true"
            answer=""
        />
    </Page>
    <Page>
        <Element
            id="01a00"
            concept="DISTRICT"
            type="SELECT"
            required="true"
            question="Pick Girls District"
            choices=""
            answer=""
            query="content://org.sana.provider/core/district/"/>
    </Page>

    <Page>
        <ShowIf>
            <Criteria type="EQUALS" id="01a00" value="BUNDIBUGYO"/>
        </ShowIf>
        <Element
            id="01a01"
            concept="COUNTY"
            type="SELECT"
            required="true"
            question="Pick Girls County"
            choices=""
            answer=""
            query="content://org.sana.provider/core/county/?district=@01a00"/>
    </Page>

    <Page>
        <Element
            id="01a02"
            concept="SUBCOUNTY"
            type="SELECT"
            required="true"
            question="Pick Girls Subcounty"
            choices=""
            answer=""
            query="content://org.sana.provider/core/subcounty/?district=@01a00"/>
    </Page>

    <Page>
        <Element
            id="01a03"
            concept="PARISH"
            type="SELECT"
            required="true"
            question="Pick Girls Parish"
            choices=""
            answer=""
            query="content://org.sana.provider/core/parish/?subcounty=@01a02"/>
    </Page>

    <Page>
        <Element
            id="01a04"
            concept="LOCATION"
            type="SELECT"
            required="true"
            question="Pick Girls Village"
            choices=""
            answer=""
            query="content://org.sana.provider/core/location/?parish=@01a03"/>
    </Page>
    <!--
    <Page>
        <Element id="9" type="RADIO"
             concept="LOCATION PATIENT HOUSE"
             question="Are you at the girl's home?"
             answer="Yes"
             choices="Yes;No" />
    </Page>
    <Page>
        <ShowIf>
            <Criteria type="EQUALS" id="9" value="yes"/>
        </ShowIf>
        <Element
            id="10"
            concept="LOCATION"
            type="HIDDEN"
            required="false"
            question="Girl's Address/Location"
            Default ="29da1cb1a8da486d80c80fbd4ee3f9ca:"
            action="intent://org.sana.provider/subject/{uuid}#Intent;scheme=content;action=org.sana.android.intent.ACTION_RECORD_GPS;end"
        />
    </Page>
    -->
    <Page>
        <Element
            id="11"
            concept="MARITAL STATUS"
            type="SELECT"
            required="true"
            question="Martial Status"
            choices="SINGLE;MARRIED;DIVORCED"
            answer=""
        />
        <Element
            id="12"
            concept="EDUCATION LEVEL"
            type="SELECT"
            required="true"
            question="Highest Education Level"
            choices="Primary_level;OLevel;Alevel;Tertiary"
            answer=""/>
    </Page>
    <Page>
        <Element
            id="13"
            concept="CONTRACEPTIVE USE"
            type="RADIO"
            choices="Yes;No"
            question="Have you used Contraceptives before?"
            answer=""/>
        <Element
            id="14"
            type="RADIO" choices="Yes;No"
            question="Have you attended ANC during this pregnancy?"
            concept="ANC Status"
            required="true"
            answer=""
        />
    </Page>
    <Page>
        <Element
            id="15"
            type="RADIO" choices="Yes;No"
            question="Are you on the any  Voucher Programme?"
            concept="VOUCHER Status"
            required="true"
            answer=""
        />
    </Page>
         <Page>
            <ShowIf>
                <Criteria type="EQUALS" id="15" value="Yes"/>
            </ShowIf>
            <Element id="15b"
                type="ENTRY"
                concept="SYSTEM ID"
                question="Enter Patient Voucher Number"
                answer=""
                pattern="HBBH[0-9]{6}|FPUG [0-9]{6}|SMA[0-9]{6}|LKUP[0-9]{6}"
                helpText="Invalid Voucher Number format."/>
            />
        </Page>
   <!-- <Page>
        <ShowIf>
            <Criteria type="EQUALS" id="14" value="Yes"/>
        </ShowIf>
        <Element id="15a" type="DATE"
            concept="ANC VISIT"
            question="Enter Next ANC visit from Card"
            required="true"
            answer=""
        />
    </Page>-->
    <!-- Are these supposed to be patient fields -->
    <!--
        They are not included in the Patient Model if they are
        and seem more likely transactional data that is associated
        with a Midwife appointment note.
    -->
    <!--
    <Page>
        <Element
            id="16"
            type="TEXT"
            question="GIRLS APPOINTMENT NOTES"
            />
        <Element
            id="17"
            type="ENTRY"
            concept="MIDWIFE RISK IDENTIFIED"
            question="Any RISK identified?"
            answer=""
            />
        <Element
            id="18"
            type="ENTRY"
            concept=" MIDWIFE ACTION TAKEN"
            question="Action taken"
            answer=""
            />
    </Page>
    -->
</Procedure>


text:
import scrapy
import sqlite3

connection = sqlite3.connect('lanacion.db')
cursor = connection.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS articles (url string primary key, content text)''')
connection.commit()

def getStartUrls():
  firstArticleId = 1756600 # aprox principio del 2015
  lastArticleId = 1858700 # aprox principio del 2016
  for articleId in range(firstArticleId, lastArticleId + 1):
   yield 'http://www.lanacion.com.ar/%d' % articleId

def addArticle(url, content):
  cursor = connection.cursor()
  cursor.execute('''INSERT OR REPLACE INTO articles VALUES (?,?)''', [url, content])
  connection.commit()

class LanacionSpider(scrapy.Spider):
  name = 'lanacionspider'
  start_urls = getStartUrls()

  def parse(self, response):
    addArticle(response.url, response.body)


text:
package org.moeaframework.util.tree;

/**
 * The node for calculating the largest integer value that is less than or
 * equal to a number.  The inputs and outputs to this node are shown below:
 *
 *

 *

 *     Name
 *     Type
 *     Description
 *

 *

 *     Argument 1
 *     Number
 *     The number
 *

 *

 *     Return Value
 *     Number
 *     The floor of the number
 *

 *

 *
 * @see Math#floor(double)
 */
public class Floor extends Node {

	/**
	 * Constructs a new node for calculating the largest integer value that is
	 * less than or equal to a number.
	 */
	public Floor() {
		super(Number.class, Number.class);
	}

	@Override
	public Floor copyNode() {
		return new Floor();
	}

	@Override
	public Number evaluate(Environment environment) {
		return NumberArithmetic.floor(
				(Number)getArgument(0).evaluate(environment));
	}

}


text:
<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * CmsStzefContracts
 *
 * @ORM\Table(name="cms_stzef_contracts")
 * @ORM\Entity
 */
class CmsStzefContracts
{
    /**
     * @var string
     *
     * @ORM\Column(name="proceso", type="string", length=45, nullable=false)
     */
    private $proceso;

    /**
     * @var string
     *
     * @ORM\Column(name="descripcion", type="text", length=65535, nullable=true)
     */
    private $descripcion;

    /**
     * @var integer
     *
     * @ORM\Column(name="objeto", type="integer", nullable=false)
     */
    private $objeto;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="apertura", type="date", nullable=false)
     */
    private $apertura;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="aclaracion", type="date", nullable=false)
     */
    private $aclaracion;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="cierre", type="date", nullable=false)
     */
    private $cierre;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="adjudicion", type="date", nullable=false)
     */
    private $adjudicion;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * Set proceso
     *
     * @param string $proceso
     * @return CmsStzefContracts
     */
    public function setProceso($proceso)
    {
        $this->proceso = $proceso;

        return $this;
    }

    /**
     * Get proceso
     *
     * @return string
     */
    public function getProceso()
    {
        return $this->proceso;
    }

    /**
     * Set descripcion
     *
     * @param string $descripcion
     * @return CmsStzefContracts
     */
    public function setDescripcion($descripcion)
    {
        $this->descripcion = $descripcion;

        return $this;
    }

    /**
     * Get descripcion
     *
     * @return string
     */
    public function getDescripcion()
    {
        return $this->descripcion;
    }

    /**
     * Set objeto
     *
     * @param integer $objeto
     * @return CmsStzefContracts
     */
    public function setObjeto($objeto)
    {
        $this->objeto = $objeto;

        return $this;
    }

    /**
     * Get objeto
     *
     * @return integer
     */
    public function getObjeto()
    {
        return $this->objeto;
    }

    /**
     * Set apertura
     *
     * @param \DateTime $apertura
     * @return CmsStzefContracts
     */
    public function setApertura($apertura)
    {
        $this->apertura = $apertura;

        return $this;
    }

    /**
     * Get apertura
     *
     * @return \DateTime
     */
    public function getApertura()
    {
        return $this->apertura;
    }

    /**
     * Set aclaracion
     *
     * @param \DateTime $aclaracion
     * @return CmsStzefContracts
     */
    public function setAclaracion($aclaracion)
    {
        $this->aclaracion = $aclaracion;

        return $this;
    }

    /**
     * Get aclaracion
     *
     * @return \DateTime
     */
    public function getAclaracion()
    {
        return $this->aclaracion;
    }

    /**
     * Set cierre
     *
     * @param \DateTime $cierre
     * @return CmsStzefContracts
     */
    public function setCierre($cierre)
    {
        $this->cierre = $cierre;

        return $this;
    }

    /**
     * Get cierre
     *
     * @return \DateTime
     */
    public function getCierre()
    {
        return $this->cierre;
    }

    /**
     * Set adjudicion
     *
     * @param \DateTime $adjudicion
     * @return CmsStzefContracts
     */
    public function setAdjudicion($adjudicion)
    {
        $this->adjudicion = $adjudicion;

        return $this;
    }

    /**
     * Get adjudicion
     *
     * @return \DateTime
     */
    public function getAdjudicion()
    {
        return $this->adjudicion;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * @var string
     */
    private $proccess;

    /**
     * @var string
     */
    private $description;

    /**
     * @var string
     */
    private $path;

    /**
     * @var \DateTime
     */
    private $dateApertura;

    /**
     * @var \DateTime
     */
    private $dateAclaracion;

    /**
     * @var \DateTime
     */
    private $dateCierre;

    /**
     * @var \DateTime
     */
    private $dateAdjudicion;

    /**
     * Set proccess
     *
     * @param string $proccess
     * @return CmsStzefContracts
     */
    public function setProccess($proccess)
    {
        $this->proccess = $proccess;

        return $this;
    }

    /**
     * Get proccess
     *
     * @return string
     */
    public function getProccess()
    {
        return $this->proccess;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return CmsStzefContracts
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set path
     *
     * @param string $path
     * @return CmsStzefContracts
     */
    public function setPath($path)
    {
        $this->path = $path;

        return $this;
    }

    /**
     * Get path
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path;
    }

    /**
     * Set dateApertura
     *
     * @param \DateTime $dateApertura
     * @return CmsStzefContracts
     */
    public function setDateApertura($dateApertura)
    {
        $this->dateApertura = $dateApertura;

        return $this;
    }

    /**
     * Get dateApertura
     *
     * @return \DateTime
     */
    public function getDateApertura()
    {
        return $this->dateApertura;
    }

    /**
     * Set dateAclaracion
     *
     * @param \DateTime $dateAclaracion
     * @return CmsStzefContracts
     */
    public function setDateAclaracion($dateAclaracion)
    {
        $this->dateAclaracion = $dateAclaracion;

        return $this;
    }

    /**
     * Get dateAclaracion
     *
     * @return \DateTime
     */
    public function getDateAclaracion()
    {
        return $this->dateAclaracion;
    }

    /**
     * Set dateCierre
     *
     * @param \DateTime $dateCierre
     * @return CmsStzefContracts
     */
    public function setDateCierre($dateCierre)
    {
        $this->dateCierre = $dateCierre;

        return $this;
    }

    /**
     * Get dateCierre
     *
     * @return \DateTime
     */
    public function getDateCierre()
    {
        return $this->dateCierre;
    }

    /**
     * Set dateAdjudicion
     *
     * @param \DateTime $dateAdjudicion
     * @return CmsStzefContracts
     */
    public function setDateAdjudicion($dateAdjudicion)
    {
        $this->dateAdjudicion = $dateAdjudicion;

        return $this;
    }

    /**
     * Get dateAdjudicion
     *
     * @return \DateTime
     */
    public function getDateAdjudicion()
    {
        return $this->dateAdjudicion;
    }
}


text:
# Chapter 3. Lexical Analysis (Tokenization)

Esprima tokenizer takes a string as an input and produces an array of tokens, a list of object representing categorized input characters.
This is known as _[lexical analysis](https://en.wikipedia.org/wiki/Lexical_analysis)_.

The interface of the `tokenize` function is as follows:

```js
esprima.tokenize(input, config)
```

where

* `input` is a string representing the program to be tokenized
* `config` is an object used to customize the parsing behavior (optional)

The `input` argument is mandatory. Its type must be a string, otherwise the tokenization behavior is not determined.

The description of various properties of `config` is summarized in the following table:

Name	 Type	 Default	 Description

range	 Boolean	 false	 Annotate each token with its zero-based start and end location

loc	 Boolean	 false	 Annotate each token with its column and row-based location

comment	 Boolean	 false	 Include every line and block comment in the output

An example Node.js REPL session that demonstrates the use of Esprima tokenizer is:

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('answer = 42')
[ { type: 'Identifier', value: 'answer' },
  { type: 'Punctuator', value: '=' },
  { type: 'Numeric', value: '42' } ]
```

In the above example, the input string is tokenized into 3 tokens: an identifier, a punctuator, and a number. For each token, the `type` property is a string indicating the type of the token and the `value` property stores the corresponding the _lexeme_, i.e. a string of characters which forms a syntactic unit.

Unlike the `parse` function, the `tokenize` function can work with an input string that does not represent a valid JavaScript program. This is because lexical analysis, as the name implies, does _not_ involve the process of understanding the syntactic structure of the input.

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('42 = answer')
[ { type: 'Numeric', value: '42' },
  { type: 'Punctuator', value: '=' },
  { type: 'Identifier', value: 'answer' } ]
> esprima.tokenize('while (if {}')
[ { type: 'Keyword', value: 'while' },
  { type: 'Punctuator', value: '(' },
  { type: 'Keyword', value: 'if' },
  { type: 'Punctuator', value: '{' },
  { type: 'Punctuator', value: '}' } ]
```

## Token Location

By default, each token in the array returned by the tokenizer only has two properties, the _type_ of the token and the _lexeme_. For some use cases, the location of each token needs to be known as well (e.g. to offer a meaningful feedback to the user). Esprima tokenizer can add that location information to each token in two forms, zero-based range and line-column location. This is done by customizing the tokenization process with the configuration object.

Setting `range` (in the configuration object) to true adds a new property, `range`, to each token. It is an array of two elements, each indicating the zero-based index of the _starting_ and _end_ location (exclusive) of the token. A simple example follows:

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('answer = 42', { range: true })
[ { type: 'Identifier', value: 'answer', range: [ 0, 6 ] },
  { type: 'Punctuator', value: '=', range: [ 7, 8 ] },
  { type: 'Numeric', value: '42', range: [ 9, 11 ] } ]
```

In the above example, the starting and end location of each token can be determined from its range property. For instance, the equal sign (`=`) is the 7th character in the input string, because its range is `[7, 8]`.

Setting `loc` to true adds a new property, `loc`, to each token. It is a object that contains the _line number_ and _column number_ of the starting and end location (exclusive) of the token. This is illustrated in the example:

```js
$ node
> var esprima = require('esprima')
> tokens = esprima.tokenize('answer = 42', { loc: true });
> tokens[2]
{ type: 'Numeric',
  value: '42',
  loc: { start: { line: 1, column: 9 }, end: { line: 1, column: 11 } } }
```

Note that the line number is _one-based_ while the column number is _zero-based_.

It is possible to set both `range` and `loc` to true, thereby giving each token the most complete location information.

## Line and Block Comments

By default, Esprima tokenizer ignores every line and block comment. If each comment needs to be included in the output, then the property `comment` in the configuration object needs to be set to true. To illustrate this, compare the following simple tokenization:

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('/* answer */ 42')
[ { type: 'Numeric', value: '42' } ]
```

with the following situation where the token array also contains the block comment:

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('/* answer */ 42', { comment: true })
[ { type: 'BlockComment', value: ' answer ' },
  { type: 'Numeric', value: '42' } ]
```

If the location of each comment is needed, enable the location information using `range` and/or `loc` (as explained in the previous section):

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('/* answer */ 42', { comment: true, range: true })
[ { type: 'BlockComment', value: ' answer ', range: [ 0, 12 ] },
  { type: 'Numeric', value: '42', range: [ 13, 15 ] } ]
```

## Limitation on Keywords

Since a tokenization process does not have the context of the syntactic structure, it is unable to infer properly that a particular reserved word is being used not as a keyword. Therefore, it always classifies a reserved word as keyword. A simple example to illustrate this limitation:

```js
$ node
> var esprima = require('esprima')
> esprima.tokenize('x.if = 1')
[ { type: 'Identifier', value: 'x' },
  { type: 'Punctuator', value: '.' },
  { type: 'Keyword', value: 'if' },
  { type: 'Punctuator', value: '=' },
  { type: 'Numeric', value: '1' } ]
```

In the above session, the type of the `if` token is `Keyword`.

This is however different than what will be obtained using Esprima parser since the parser correctly matches the `if` token as an object property and therefore constructs an associated `Identifier` node, not a `Keyword` node.

```js
$ node
> var esprima = require('esprima')
> esprima.parseScript('x.if = 1').body[0].expression.left.property
Identifier { type: 'Identifier', name: 'if' }
```

## Limitation on JSX

[JSX](http://facebook.github.io/jsx/) is a syntax extension to JavaScript, popularly known to build web applications using [React](https://facebook.github.io/react/). JSX is not part of any [official ECMAScript specification](http://www.ecma-international.org/publications/standards/Ecma-262.htm).

Esprima tokenizer is unable to process input source that contains a mix of JavaScript code and JSX. This is because switching to JSX mode requires an understanding of the context, which a tokenizer does not have. In particular, a closing JSX element (such as `</title>`) confuses the tokenizer since the forward slash (`/`) is identified as the start of a regular expression.

## Example: Syntax Highlighting

The following Node.js script demonstrates the use of Esprima tokenizer to apply [syntax highlighting](https://en.wikipedia.org/wiki/Syntax_highlighting) of JavaScript code fragment. It accepts the input from `stdin` and produces color coded version to `stdout` by using [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code).

```js
const esprima = require('esprima');
const readline = require('readline');

const CYAN = '\x1b[36m';
const RESET = '\x1b[0m'
let source = '';

readline.createInterface({ input: process.stdin, terminal: false })
.on('line', line => { source += line + '\n' })
.on('close', () => {
    const tokens = esprima.tokenize(source, { range: true });
    const ids = tokens.filter(x => x.type === 'Identifier');
    const markers = ids.sort((a, b) => { return b.range[0] - a.range[0] });
    markers.forEach(t => {
        const id = CYAN + t.value + RESET;
        const start = t.range[0];
        const end = t.range[1];
        source = source.slice(0, start) + id + source.slice(end);
    });
    console.log(source);
});
```

An example run is shown in the following screenshot (the script is called `highlight.js`):

![Syntax highlighting](highlight.png)

The script uses the [readline module](https://nodejs.org/api/readline.html) to read the input line-by-line, collecting each line to a local string buffer. Once there is no more input, it invokes Esprima tokenizer to break the source into a list of tokens. The script only cares about identifier tokens, hence the filtering. For each token, the starting location is used to determine where to insert the [escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) to change the color to cyan and the end location is used to reset the color. This is done from the last identifier token to the first identifier token, which necessities the sorting in reverse order.

For a real-world syntax highlighter that has many more features, take a look at _cardinal_ (source repository: [github.com/thlorenz/cardinal](https://github.com/thlorenz/cardinal)). It uses a similar approach, i.e. using Esprima tokenizer to break the source into tokens and then wrap each token with a type-specific color.


text:
Write a Haskell function `repeated :: [String] -> Int` that takes a list of strings and returns the number of values that are repeated in the input list.

**Sample Test Cases**

Test Case | Input	| Output
--------- | ----- | ------
Test Case 1	| `repeated ["the","higher","you","climb","the","further","you","fall"]` | `2`
Test Case 2	| `repeated ["to", "be", "or", "not", "to", "be", "or", "neither"]` | `3`


text:
package com.sany.masterdata.hr.entity;

/**
 * TdSmOrgJob.java
 * @author caix3
 * @since 2012-3-22
 */
public class TdSmOrgJob {

    private String orgId;

    private String jobId;

    private Long jobSn;

    public String getJobId() {
        return jobId;
    }

    public Long getJobSn() {
        return jobSn;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public void setJobSn(Long jobSn) {
        this.jobSn = jobSn;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

}


text:
module Queens where

import Data.List
import Control.Monad.Par (parMap, runPar, NFData)

data Queen = Queen | NoQueen

data RowInfo = RowInfo { rQueen :: [Bool], rDiagLeft :: [Bool], rVertical :: [Bool], rDiagRight :: [Bool] }
             deriving (Show)

type Solution = [[Bool]]

(|-) :: a -> (a -> b) -> b
x |- f = f x

emptyRow :: Int -> RowInfo
emptyRow cols = RowInfo noData noData noData noData
  where noData = take cols (repeat False)

type MapStrat = Int -> (RowInfo -> [Solution]) -> [RowInfo] -> [[Solution]]
simpleStrat d = map
naiveParStrat d f xs = runPar $ parMap f xs
cutoffParStrat d = if d > 6 then naiveParStrat d else simpleStrat d
strategies :: [MapStrat]
strategies = [simpleStrat, naiveParStrat, cutoffParStrat]

queens d = map tail $ solveQueens cutoffParStrat d (emptyRow d)
--queens d = map tail $ solveQueens naiveParStrat d (emptyRow d)

solveQueens :: MapStrat -> Int -> RowInfo -> [Solution]
solveQueens _ 0 prevRowInfo = [[rQueen prevRowInfo]]
solveQueens mapStrategy rows prevRowInfo =
  let newRows = validMoves prevRowInfo
      solver = solveQueens mapStrategy (rows - 1)
      validSuffixes = concat $ map' solver newRows
  in map (rQueen prevRowInfo :) validSuffixes
  where map' f xs = mapStrategy rows f xs

validMoves :: RowInfo -> [RowInfo]
validMoves prevRowInfo =
  let diagLeft = shiftLeft (rDiagLeft prevRowInfo)
      diagRight = shiftRight (rDiagRight prevRowInfo)
      vertical = rVertical (prevRowInfo)
      available = map not $ map or3 $ zip3 diagLeft diagRight vertical
      moves = chooseOneByOne available
  in [let m xs = map or2 (zip move xs) in
       RowInfo move (m diagLeft) (m vertical) (m diagRight) | move <- moves]
     where or2 (a, b) = a || b
           or3 (x, y, z) = x || y || z

dropLast [] = undefined
dropLast [x] = []
dropLast (x:xs) = x : dropLast xs
-- TODO: rewrite using foldr

shiftLeft row = tail row ++ [False]

shiftRight row = False : (dropLast row)

chooseOneByOne :: [Bool] -> [[Bool]]
chooseOneByOne xs =
  let pos = positions xs 0 []
  in [(take n falses) ++ [True] ++ (take (len-n-1) falses) | n <- pos]
  where falses = repeat False
        len = length xs
        positions [] i result = result
        positions (y:ys) i result = positions ys (i+1) newResult
          where newResult = if y then (i:result) else result

showSolution :: Solution -> String
showSolution rows = intercalate "\n" (map rowstr rows)
  where rowstr = map repr
        repr x = if x then 'X' else '.'

p d = putStrLn $ intercalate "\n\n" $ map showSolution (queens d)
cs d = length (queens d)


text:
class OesnServer : public node::ObjectWrap {
 public:
  static void Init(v8::Handle<v8::Object> target);

 protected:
  OesnServer(OesnDispatcher *, char *, OesnNet *, OesnStore *);
  ~OesnServer();
  OepServer getImpl();

  OepServer impl_;

  static v8::Handle<v8::Value> New(const v8::Arguments& args);
  static v8::Handle<v8::Value> AddLoginModule(const v8::Arguments& args);
  static v8::Handle<v8::Value> AddKernel(const v8::Arguments& args);
};

#endif