text:
require 'spec'
require 'spec_helper'

describe TableFu do

  before :all do
    csv = FasterCSV.parse(File.open('spec/assets/test.csv'))
    @spreadsheet = TableFu.new(csv, :style => {'URL' => 'text-align: left;'})
  end

  it 'should give me back a Row object' do
    @spreadsheet.rows.each do |r|
      r.class.should eql TableFu::Row
    end
  end

  it 'should give me back a column by it\'s header name' do
    @spreadsheet.rows[0].column_for("State").to_s.should == "Alabama"
  end

  it 'should sort rows' do
    @spreadsheet.sorted_by = {'State' => {"order" => 'descending'}}
    @spreadsheet.rows[0].column_for("State").to_s.should eql "Wyoming"
    @spreadsheet.sorted_by = {'Party' => {"order" => 'descending'}}
    @spreadsheet.rows[0].column_for("Party").to_s.should eql "Republican"
    @spreadsheet.sorted_by = {'Representative' => {"order" => 'ascending', "format" => 'last_name'}}
    @spreadsheet.rows[2].column_for("Representative").to_s.should eql "Jo Bonner"

    @spreadsheet.col_opts[:columns] = ['State', 'Party', 'Total Appropriations', 'URL']
    @spreadsheet.rows.each do |row|
      row.columns.each do |column|
        if column.column_name == 'URL'
          column.style.should eql 'text-align: left;'
          column.to_s.should eql ''
          column.value.should be_nil
        end
        column.style.should_not be_nil
      end
    end

  end

  it 'should sort rows with numerals' do
    @spreadsheet.sorted_by = {'Projects' => {"order" => 'ascending'}}
    sorted = @spreadsheet.rows.map do |row|
      row.column_for("Projects").value
    end
    sorted.should eql [4, 5, 10, 12, 20, 49, nil]
  end

  it 'should be able to contain only the rows I want, after sorting' do
    @spreadsheet.sorted_by = {'State' => {"order" => 'ascending'}}
    @spreadsheet.only!(1..2)
    @spreadsheet.rows[0].column_for('State').to_s.should eql 'Arizona'
    @spreadsheet.rows[1].column_for('State').to_s.should eql 'California'
    @spreadsheet.deleted_rows.length.should eql 5
    @spreadsheet.rows.length.should eql 2
  end

  it 'should convert a total to a string' do
    @spreadsheet.total_for('Projects').to_s.should eql '24'
  end
end

describe TableFu, 'with a complicated setup' do

  before :all do
    csv = FasterCSV.parse(File.open('spec/assets/test.csv'))
    @spreadsheet = TableFu.new(csv)
    @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :currency,
                                          "Representative" => :last_name_first_name}
    @spreadsheet.col_opts[:style] = {'Leadership' => "text-align: left;", 'URL' => 'text-align: right;'}
    @spreadsheet.col_opts[:invisible] = ['URL']
    @spreadsheet.delete_rows! [8]
    @spreadsheet.sorted_by = {'State' => {"order" => 'descending'}}
    @spreadsheet.col_opts[:columns] = ['State', 'Leadership', 'Total Appropriation', 'Party', 'URL']
  end

  it 'Leadership column should be marked invisible' do
    @spreadsheet.rows[0].column_for('URL').invisible?.should be_true
    @spreadsheet.rows[0].column_for('State').invisible?.should be_false
  end

  it 'should give me back a Row object' do
    @spreadsheet.rows.each do |r|
      r.class.should eql TableFu::Row
    end
  end

  it 'should give me back a 7 rows because it ignored row 476 and header' do
    @spreadsheet.rows.size.should eql 7
  end

  it 'should give me back a column by it\'s header name' do
    @spreadsheet.rows[3].column_for('State').to_s.should eql "Georgia"
    @spreadsheet.rows[2].column_for('State').to_s.should eql "New Jersey"
    @spreadsheet.rows[0].column_for('State').to_s.should eql "Wyoming"
  end

  it 'should have some sugar' do
    @spreadsheet.rows[3]['State'].to_s.should eql "Georgia"

  end

  it 'should total a column' do
    @spreadsheet.total_for("Total Appropriation").value.should eql 16640189309
    @spreadsheet.total_for("Total Appropriation").to_s.should eql "$16,640,189,309"
  end

  it 'should format a column' do
    @spreadsheet.rows[0].column_for("Total Appropriation").to_s.should eql "$138,526,141"
    @spreadsheet.rows[0].column_for("Total Appropriation").value.should eql 138526141
    @spreadsheet.rows[4].column_for("Representative").to_s.should eql "Nunes, Devin"
  end

  it 'should format a header' do
    @spreadsheet.headers[1].style.should eql 'text-align: left;'
    @spreadsheet.headers[4].style.should eql 'text-align: right;'
  end

  it 'should not care what kind of keys the hash has' do
    @spreadsheet = TableFu.new(File.open('spec/assets/test.csv'))
    @spreadsheet.col_opts["style"] = {'Leadership' => "text-align: left;", 'URL' => 'text-align: right;'}

    @spreadsheet.rows[0].column_for('Leadership').style.should ==
                          @spreadsheet.col_opts["style"]['Leadership']
  end

end

describe TableFu, "with faceting" do

  before :all do
    csv = FasterCSV.parse(File.open('spec/assets/test.csv'))
    @spreadsheet = TableFu.new(csv)
    @spreadsheet.col_opts[:style] = {'Projects' => 'text-align:left;'}
    @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :currency}
    @spreadsheet.delete_rows! [8]
    @spreadsheet.sorted_by = {'State' => {:order => 'ascending'}}
    @faceted_spreadsheets = @spreadsheet.faceted_by("Party", :total => ['Projects', 'Total Appropriation'])
  end

  it "should have 2 facets" do
    @faceted_spreadsheets.size.should == 2
  end

  it "should total up the projects and expenses" do
    @faceted_spreadsheets[1].total_for("Projects").value.should eql 63
    @faceted_spreadsheets[0].total_for("Projects").value.should eql 32
    @faceted_spreadsheets[1].total_for("State").value.should eql 3
    @faceted_spreadsheets[1].total_for("Total Appropriation").value.should eql 175142465
  end

  it "should keep formatting on totals" do
    @faceted_spreadsheets[1].total_for("Total Appropriation").to_s.should eql "$175,142,465"
  end

  it "should remember what facet it belongs to" do
    @faceted_spreadsheets[1].faceted?.should be_true
    @faceted_spreadsheets[0].faceted_on.should == 'Democrat'
  end

  it "should keep the formatting" do

    @faceted_spreadsheets[1].rows[1].column_for('Total Appropriation').to_s.should eql "$25,320,127"
    @faceted_spreadsheets[1].rows[1].column_for('Projects').style.should eql "text-align:left;"
  end

end

describe TableFu, 'with macro columns' do

  class TableFu::Formatting

    class<<self

      def append(first, second)
        "#{first}#{second}"
      end

      def null(first)
        nil
      end

    end

  end

  before :all do
    csv = FasterCSV.parse(File.open('spec/assets/test_macro.csv').read)
    @spreadsheet = TableFu.new(csv)
    @spreadsheet.col_opts[:style] = {'Projects' => 'text-align:left;'}
    @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :currency,
                                          'MacroColumn' => {'method' => 'append', 'arguments' => ['Projects','State']},
                                          'NullColumn' => {'method' => 'null', 'arguments' => ['Projects']}}
    @spreadsheet.sorted_by = {'Projects' => {'order' => 'descending'}}
    @spreadsheet.col_opts[:columns] = ['State', 'Total Appropriation', 'Projects', 'MacroColumn']
  end

  it "should let us specify a macro for a column" do
    @spreadsheet.rows[1].column_for('MacroColumn').to_s.should eql '20Arizona'
  end

  it "should keep the rows in order" do
    @spreadsheet.rows[0].column_for('Projects').value.should eql 49
    @spreadsheet.rows[1].column_for('Total Appropriation').to_s.should eql '$42,367,198'
  end

  it "should allow macros that take arguments to return nil" do
    @spreadsheet.rows[0].column_for('NullColumn').to_s.should eql ''
  end

  it "should not barf if we try a bad formatter" do
    @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :bad_formatter }
    @spreadsheet.rows[1].column_for('Total Appropriation').to_s.should eql "bad_formatter not a valid formatter!"
  end
end

describe TableFu, 'with reordered columns' do

  before :all do
    csv = FasterCSV.parse(File.open('spec/assets/test.csv'))
    @spreadsheet = TableFu.new(csv)
    @spreadsheet.col_opts[:style] = {'Projects' => 'text-align:left;'}
    @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :currency}
    @spreadsheet.col_opts[:sorted_by] = {'State' => {:order => 'ascending'}}
  end

  it "should display columns in the correct order" do
    @spreadsheet.col_opts[:columns] = ['State', 'Blah', 'Projects']
    @spreadsheet.column_headers.size.should eql 7
    @spreadsheet.columns.size.should eql 3
    facets  = @spreadsheet.faceted_by('State')
    @spreadsheet.rows[0].column_for('Blah').to_s.should eql ''
    @spreadsheet.rows[0].column_for('Projects').to_s.should eql '10'
  end

end


text:
package org.innovateuk.ifs.category.builder;

import org.innovateuk.ifs.category.domain.InnovationArea;
import org.innovateuk.ifs.category.domain.InnovationSector;

import java.util.List;
import java.util.function.BiConsumer;

import static java.util.Collections.emptyList;
import static org.innovateuk.ifs.base.amend.BaseBuilderAmendFunctions.uniqueIds;

public class InnovationAreaBuilder extends CategoryBuilder<InnovationArea, InnovationAreaBuilder> {

    protected InnovationAreaBuilder(List<BiConsumer<Integer, InnovationArea>> multiActions) {
        super(multiActions);
    }

    public static InnovationAreaBuilder newInnovationArea() {
        return new InnovationAreaBuilder(emptyList()).with(uniqueIds());
    }

    @Override
    protected InnovationAreaBuilder createNewBuilderWithActions(List<BiConsumer<Integer, InnovationArea>> actions) {
        return new InnovationAreaBuilder(actions);
    }

    @Override
    protected InnovationArea createInitial() {
        return new InnovationArea();
    }

    public InnovationAreaBuilder withSector(InnovationSector... innovationSectors) {
        return withArraySetFieldByReflection("sector", innovationSectors);
    }
}

redpajama_set_name: RedPajamaGithub


text:
@import be.objectify.deadbolt.java.DeadboltHandler
@import be.objectify.deadbolt.java.ViewAccessPoint.Implicits._
@import play.api.Play.current
@(roleName: String, handler: DeadboltHandler = handlerCache.get(), content: Optional[String] = Optional.empty(), timeout: java.util.function.Supplier[Long] = viewSupport.defaultTimeout)(body: => Html)

@if(viewSupport.viewRoleBasedPermissions(roleName, handler, content, timeout.get())) {
    @body
}


text:
#include <stdarg.h>
#include <stdlib.h>
#if defined(__CC_ARM)
#include <stdio.h>
#endif

#include "fsl_debug_console.h"
#include "fsl_debug_console_conf.h"
#include "fsl_log.h"
#include "fsl_str.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
/*!
 * @brief This is a printf call back function which is used to relocate the log to buffer
 * or print the log immediately when the local buffer is full.
 *
 * @param[in] buf   Buffer to store log.
 * @param[in] indicator Buffer index.
 * @param[in] val Target character to store.
 * @param[in] len length of the character
 *
 */
#if SDK_DEBUGCONSOLE
static void DbgConsole_RelocateLog(char *buf, int32_t *indicator, char val, int len);
#endif
/*******************************************************************************
 * Code
 ******************************************************************************/

/*************Code for DbgConsole Init, Deinit, Printf, Scanf *******************************/

/* See fsl_debug_console.h for documentation of this function. */
status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq)
{
    assert(device != DEBUG_CONSOLE_DEVICE_TYPE_NONE);

    return LOG_Init(baseAddr, device, baudRate, clkSrcFreq);
}

/* See fsl_debug_console.h for documentation of this function. */
status_t DbgConsole_Deinit(void)
{
    /* LOG deinit */
    LOG_Deinit();

    return kStatus_Success;
}

status_t DbgConsole_Flush(void)
{
    /* wait log and io idle */
    return LOG_WaitIdle();
}

#if SDK_DEBUGCONSOLE
/* See fsl_debug_console.h for documentation of this function. */
int DbgConsole_Printf(const char *fmt_s, ...)
{
    va_list ap;
    int logLength = 0U, result = 0U;
    char printBuf[DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN] = {0U};

    va_start(ap, fmt_s);
    /* format print log first */
    logLength = StrFormatPrintf(fmt_s, ap, printBuf, DbgConsole_RelocateLog);
    /* print log */
    result = LOG_Push((uint8_t *)printBuf, logLength);

    va_end(ap);

    return result;
}

/* See fsl_debug_console.h for documentation of this function. */
int DbgConsole_Putchar(int ch)
{
    /* print char */
    return LOG_Push((uint8_t *)&ch, 1U);
}

/* See fsl_debug_console.h for documentation of this function. */
int DbgConsole_Scanf(char *fmt_ptr, ...)
{
    va_list ap;
    int result;
    char scanfBuf[DEBUG_CONSOLE_SCANF_MAX_LOG_LEN + 1U] = {0U};

    /* scanf log */
    LOG_ReadLine((uint8_t *)scanfBuf, DEBUG_CONSOLE_SCANF_MAX_LOG_LEN);
    /* get va_list */
    va_start(ap, fmt_ptr);
    /* format scanf log */
    result = StrFormatScanf(scanfBuf, fmt_ptr, ap);

    va_end(ap);

    return result;
}

#ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
status_t DbgConsole_TryGetchar(char *ch)
{
    if (NULL != ch)
    {
        return LOG_TryReadCharacter((uint8_t *)ch);
    }

    return kStatus_Fail;
}
#endif

/* See fsl_debug_console.h for documentation of this function. */
int DbgConsole_Getchar(void)
{
    uint8_t ch;

    /* Get char */
    LOG_ReadCharacter(&ch);

    return ch;
}

static void DbgConsole_RelocateLog(char *buf, int32_t *indicator, char val, int len)
{
    int i = 0;

    for (i = 0; i < len; i++)
    {
        if ((*indicator + 1) >= DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN)
        {
            LOG_Push((uint8_t *)buf, *indicator);
            *indicator = 0U;
        }

        buf[*indicator] = val;
        (*indicator)++;
    }
}

#endif /* SDK_DEBUGCONSOLE */

/*************Code to support toolchain's printf, scanf *******************************/
/* These function __write and __read is used to support IAR toolchain to printf and scanf*/
#if (defined(__ICCARM__))
#if defined(SDK_DEBUGCONSOLE_UART)
#pragma weak __write
size_t __write(int handle, const unsigned char *buffer, size_t size)
{
    if (buffer == 0)
    {
        /*
         * This means that we should flush internal buffers.  Since we don't we just return.
         * (Remember, "handle" == -1 means that all handles should be flushed.)
         */
        return 0;
    }

    /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
    if ((handle != 1) && (handle != 2))
    {
        return ((size_t)-1);
    }

    /* Send data. */
    LOG_Push((uint8_t *)buffer, 1U);

    return size;
}

#pragma weak __read
size_t __read(int handle, unsigned char *buffer, size_t size)
{
    /* This function only reads from "standard in", for all other file  handles it returns failure. */
    if (handle != 0)
    {
        return ((size_t)-1);
    }

    /* Receive data.*/
    LOG_ReadLine(buffer, size);

    return size;
}
#endif /* SDK_DEBUGCONSOLE_UART */

/* support LPC Xpresso with RedLib */
#elif(defined(__REDLIB__))

#if (!SDK_DEBUGCONSOLE) && (defined(SDK_DEBUGCONSOLE_UART))
int __attribute__((weak)) __sys_write(int handle, char *buffer, int size)
{
    if (buffer == 0)
    {
        /* return -1 if error. */
        return -1;
    }

    /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
    if ((handle != 1) && (handle != 2))
    {
        return -1;
    }

    /* Send data. */
    LOG_Push((uint8_t *)buffer, size);

    return 0;
}

int __attribute__((weak)) __sys_readc(void)
{
    char tmp;

    /* Receive data. */
    LOG_ReadCharacter((uint8_t *)&tmp);

    return tmp;
}
#endif

/* These function __write and __read is used to support ARM_GCC, KDS, Atollic toolchains to printf and scanf*/
#elif(defined(__GNUC__))

#if ((defined(__GNUC__) && (!defined(__MCUXPRESSO)) && (defined(SDK_DEBUGCONSOLE_UART))) || \
     (defined(__MCUXPRESSO) && (!SDK_DEBUGCONSOLE) && (defined(SDK_DEBUGCONSOLE_UART))))

int __attribute__((weak)) _write(int handle, char *buffer, int size)
{
    if (buffer == 0)
    {
        /* return -1 if error. */
        return -1;
    }

    /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
    if ((handle != 1) && (handle != 2))
    {
        return -1;
    }

    /* Send data. */
    LOG_Push((uint8_t *)buffer, size);

    return size;
}

int __attribute__((weak)) _read(int handle, char *buffer, int size)
{
    /* This function only reads from "standard in", for all other file handles it returns failure. */
    if (handle != 0)
    {
        return -1;
    }

    /* Receive data. */
    return LOG_ReadLine((uint8_t *)buffer, size);
}
#endif

/* These function fputc and fgetc is used to support KEIL toolchain to printf and scanf*/
#elif defined(__CC_ARM)
#if defined(SDK_DEBUGCONSOLE_UART)
struct __FILE
{
    int handle;
    /*
     * Whatever you require here. If the only file you are using is standard output using printf() for debugging,
     * no file handling is required.
     */
};

/* FILE is typedef in stdio.h. */
#pragma weak __stdout
#pragma weak __stdin
FILE __stdout;
FILE __stdin;

#pragma weak fputc
int fputc(int ch, FILE *f)
{
    /* Send data. */
    return LOG_Push((uint8_t *)(&ch), 1);
}

#pragma weak fgetc
int fgetc(FILE *f)
{
    char ch;

    /* Receive data. */
    LOG_ReadCharacter((uint8_t *)&ch);

    return ch;
}
#endif /* SDK_DEBUGCONSOLE_UART */
#endif /* __ICCARM__ */


text:
package chaincode

import (
	"fmt"

	"github.com/spf13/cobra"
)

func invokeCmd() *cobra.Command {
	return chaincodeInvokeCmd
}

var chaincodeInvokeCmd = &cobra.Command{
	Use:       "invoke",
	Short:     fmt.Sprintf("Invoke the specified %s.", chainFuncName),
	Long:      fmt.Sprintf(`Invoke the specified %s.`, chainFuncName),
	ValidArgs: []string{"1"},
	RunE: func(cmd *cobra.Command, args []string) error {
		return chaincodeInvoke(cmd, args)
	},
}

func chaincodeInvoke(cmd *cobra.Command, args []string) error {
	return chaincodeInvokeOrQuery(cmd, args, true)
}


text:
package minium.web.actions;

import java.util.Set;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import minium.internal.Module;
import minium.internal.Modules;
import minium.web.WebElements;
import minium.web.internal.WebElementsFactory;
import minium.web.internal.WebElementsFactory.Builder;
import minium.web.internal.WebModules;
import minium.web.internal.actions.InternalBrowser;

public class WebDriverBrowser<T extends WebElements> implements Browser<T> {

    private static final Logger LOGGER = LoggerFactory.getLogger(WebDriverBrowser.class);

    private final InternalBrowser<T> browser;

    public WebDriverBrowser(WebDriver webDriver, Class<T> intf) {
        this(webDriver, intf, null);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public WebDriverBrowser(WebDriver webDriver, Class<T> intf, Module module) {
        Module combinedModules = module == null ?
                WebModules.defaultModule(webDriver) :
                Modules.combine(WebModules.baseModule(webDriver), module);
        LOGGER.debug("Creating a WebDriverBrowser for modules: {}", combinedModules);

        Builder<T> builder = new WebElementsFactory.Builder<>();
        combinedModules.configure(builder);
        WebElementsFactory<T> factory = builder.build();
        Set<Class<?>> providedInterfaces = factory.getProvidedInterfaces();

        LOGGER.trace("Provided interfaces: {}", providedInterfaces);

        this.browser = new InternalBrowser(factory);
    }

    @Override
    public T root() {
        return browser.root();
    }

    // CHECKSTYLE:OFF
    @Override
    public T $(String selector) {
        return browser.$(selector);
    }

    @Override
    public T $(WebElements... elems) {
        return browser.$(elems);
    }
    // CHECKSTYLE:ON

    @Override
    public void get(String url) {
        browser.get(url);
    }

    @Override
    public String getCurrentUrl() {
        return browser.getCurrentUrl();
    }

    @Override
    public String getPerformance() {
        return browser.getPerformance();
    }

    @Override
    public String getTitle() {
        return browser.getTitle();
    }

    @Override
    public void close() {
        browser.close();
    }

    @Override
    public void quit() {
        browser.quit();
    }

    @Override
    public Navigation navigate() {
        return browser.navigate();
    }

    @Override
    public WebConfiguration configure() {
        return browser.configure();
    }

    @Override
    public Screenshot screenshot() {
        return browser.screenshot();
    }

    @Override
    public String toString() {
        return browser.toString();
    }
}


text:
package joshie.mariculture.fishery.fish.dna;

import joshie.mariculture.api.fishery.fish.FishDNA;
import joshie.mariculture.api.fishery.fish.FishSpecies;

public class FishDNAFertility extends FishDNA {
    @Override
    public Integer getDNAFromSpecies(FishSpecies species) {
        return species.getFertility();
    }

    @Override
    public int getCopyChance() {
        return 15;
    }
}


text:
extern zend_class_entry *zendframework_stdlib_initializableinterface_ce;

ZEPHIR_INIT_CLASS(ZendFramework_Stdlib_InitializableInterface);

ZEPHIR_INIT_FUNCS(zendframework_stdlib_initializableinterface_method_entry) {
	PHP_ABSTRACT_ME(ZendFramework_Stdlib_InitializableInterface, init, NULL)
  PHP_FE_END
};


text:
<?php
/**
 * @file
 * The main Traverser interface.
 */

namespace QueryPath\CSS;

/**
 * An object capable of walking (and searching) a datastructure.
 */
interface Traverser {
  /**
   * Process a CSS selector and find matches.
   *
   * This specifies a query to be run by the Traverser. A given
   * Traverser may, in practice, delay the finding until some later time
   * but must return the found results when getMatches() is called.
   *
   * @param string $selector
   *   A selector. Typically this is a CSS 3 Selector.
   * @return \Traverser
   *  The Traverser that can return matches.
   */
  public function find($selector);
  /**
   * Get the results of a find() operation.
   *
   * Return an array of matching items.
   *
   * @return array
   *   An array of matched values. The specific data type in the matches
   *   will differ depending on the data type searched, but in the core
   *   QueryPath implementation, this will be an array of DOMNode
   *   objects.
   */
  public function matches();
}


text:
module RedminePluginSupport
  class EnvironmentTask < GeneralTask
    def define
      task :environment do
        require(File.join(RedmineHelper.redmine_root + '/config', 'environment'))
      end
    end
  end
end