text:
require File.dirname(__FILE__) + '/spec_helper'
require 'cukehead/feature_writer'

module Cukehead

  describe "FeatureWriter" do

    before do
      @features = {
        "test1.feature" => "Feature: Test 1",
        "test2.feature" => "Feature: Test 2"
      }
      @writer = FeatureWriter.new
      @outdir = File.join($testing_tmp, 'feature_writer_test', 'features')
      FileUtils.remove_dir(@outdir) if File.directory? @outdir
    end

    it "writes to a subdirectory named 'features' in the current directory by default" do
      @writer.output_path.should eql File.join(Dir.getwd, 'features')
    end

    it "has an output directory attribute that can be set" do
      @writer.output_path = @outdir
      @writer.output_path.should eql @outdir
    end

    it "takes a hash of filename => featuretext and writes feature files" do
      @writer.output_path = @outdir
      @writer.write_features(@features)
    end

    it "does not overwrite existing files by default" do
      fn = File.join(@outdir, 'test1.feature')
      FileUtils.mkdir_p @outdir
      File.open(fn, 'w') {|f| f.write('###')}
      File.exists?(fn).should be_true
      @writer.output_path = @outdir
      @writer.write_features(@features)
      @writer.errors.should have(1).items
      File.open(fn, 'r') {|f|
        s = f.readline
        s.should eql "###"
      }
    end

    it "has an overwrite attribute that can be set" do
      @writer.overwrite = true
    end

    it "overwrites existing files if the overwrite attrubute is set to true" do
      fn = File.join(@outdir, 'test1.feature')
      FileUtils.mkdir_p @outdir
      File.open(fn, 'w') {|f| f.write('###')}
      File.exists?(fn).should be_true
      @writer.output_path = @outdir
      @writer.overwrite = true
      @writer.write_features(@features)
      @writer.errors.should have(0).items
      File.open(fn, 'r') {|f|
        s = f.readline
        s.should eql "Feature: Test 1"
      }
    end

  end

end


text:
<?php # -*- coding: utf-8 -*-

namespace Cockpit\Core\App;

use Cockpit\Core\View;

/**
 * Class MetaBoxVerificationProvider
 *
 * @package Cockpit\Core\App
 */
class MetaBoxVerificationProvider {

	/**
	 * @type View\MetaBoxVerificationFields
	 */
	private $verification_view;

	public function __construct( View\MetaBoxVerificationFields $verification_view ) {

		$this->verification_view = $verification_view;
	}

	public function provide_filter() {

		add_filter( 'cockpit_mb_verification_fields', array( $this->verification_view, 'get_output' ) );
	}
}

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you under the Apache License,
  ~ Version 2.0 (the "License"); you may not use this file except
  ~ in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <!--<parent>-->
        <!--<groupId>org.wso2.carbon.identity.extensions</groupId>-->
        <!--<artifactId>user-mgt</artifactId>-->
        <!--<version>4.5.3</version>-->
        <!--<relativePath>../pom.xml</relativePath>-->
    <!--</parent>-->

    <modelVersion>4.0.0</modelVersion>
    <artifactId>org.wso2.carbon.identity.account.mgt.menu.ui</artifactId>
    <packaging>bundle</packaging>
    <name>WSO2 Carbon - Identity Account Management menu structure</name>
    <description>Menus Structure for user-mgt, claim-mgt and user-mgt ui</description>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Export-Package>*</Export-Package>
                        <Bundle-ClassPath>.</Bundle-ClassPath>
                        <Carbon-Component>UIBundle</Carbon-Component>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DevDataControl
{
    public partial class FrmRepeaer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}


text:
#ifndef __COMMANDLINECOMMAND_H__
#define __COMMANDLINECOMMAND_H__

#include <exception>
#include <sstream>
#include <string>
#include <vector>
#include <set>

namespace ghoul {
namespace cmdparser {

/**
 * A command is an operation that can be called via command line arguments on program
 * startup. As this class is virtual, it has to be derived from with the #execute method
 * implemented. The CommandlineCommand are used by adding them to the CommandlineParser,
 * using the method CommandlineParser::addCommand. The common way of using the commands
 * is to pass a variable of appropriate type to the CommandlineCommand by reference, which
 * gets set to the correct value when the command is executed.
 * Within the parser, the command's name and shortName must be
 * unique.
 *
 * There exist a number of defined convenience classes to use, for example
 * CommandlineCommandBoolean, CommandlineCommandFloat, CommandlineCommandTwoFloat,
 * CommadnlineCommandInteger, CommandlineCommandTwoInteger, CommandlineCommandString,
 * CommandlineCommandTwoString that accept one or two of the listed parameter-types.
 *
 * For generic use, see the templated classes SingleCommandlineCommand and
 * MultipleCommandlineCommand which are capable of setting basic types that are
 * convertible from string using a std::stringstream.
 */
class CommandlineCommand {
public:
    /**
     * The constructor which saves the arguments to own member variables.
     * \param name The (long) name of the parameter. For example --command1
     * \param shortName The abbreviated name of the parameter. For example -c
     * \param infoText A short text (preferably one line) explaining what the command
     * does. Used in the CommandlineParser::displayHelp method
     * \param parameterList A user-readable description which parameters are used and
     * supported. This is used in the CommandlineParser::displayUsage and
     * CommandlineParser::displayHelp methods
     * \param argumentNum The number of arguments this command accepts
     * \param allowMultipleCalls If this argument is true it signals the
     * CommandlineParser that it should allow multiple instances of this
     * CommandlineCommand in a single command line
     */
    CommandlineCommand(std::string name, std::string shortName = "",
                       std::string infoText = "", std::string parameterList = "",
                       int argumentNum = 1, bool allowMultipleCalls = false);
    virtual ~CommandlineCommand();

    /**
     * Return the full name of this command.
     * \return The full name of this command
     */
    const std::string& name() const;

    /**
     * Returns the short name of this command.
     * \return The short name of this command
     */
    const std::string& shortName() const;

    /**
     * Returns the parameter list necessary for the #usage method
     * \return The parameter list this command expects
     */
    const std::string& parameterList() const;

    /**
     * Returns a short description used in the CommandlineParser::displayHelp and
     * CommandlineParser::displayUsage methods
     * \return A short description of this command
     */
    const std::string& infoText() const;

    /// Returns the number of accepted arguments for this command
    int argumentNumber() const;

    /// Returns if the command can be called more than once in a single command line
    bool allowsMultipleCalls() const;

    /**
     * Returns a message describing the error reported by #checkParameters, or an empty
     * string, if no error has occurred.
	 * \return The message describing the error reported by #checkParameters
     */
    const std::string& errorMessage() const;

    /**
     * Executes this command with the given parameters. Each subclass must implement this
     * abstract method and perform all actions within it.
     * \param parameters The parameters needed for the execution of this command. By the
     * time this method is called, the parameters have already been verified by the
     * #checkParameters method
     * \return This method should return true, if the execution was
     * successful, false otherwise and log possible errors
     */
    virtual bool execute(const std::vector<std::string>& parameters) = 0;

    /**
     * Checks the parameters for consistency and correct amount. The basic implementation
     * only checks for the correct number of parameters. If you want to test for other
     * conditions (for example type), overwrite this method in the derived class.
     * \param parameters The parameters which should be tested
     * \return true, if the parameters are correct, false
     * otherwise
     */
    virtual bool checkParameters(const std::vector<std::string>& parameters);

    /**
     * Returns the usage part for the help of this CommandlineCommand. Used in the
     * CommandlineParser::usage method.
     * \return The usage part for the help of this command
     */
    virtual std::string usage() const;

    /// Returns the help-part for a command. Used in the help()-method from the
    /// CommandlineParser
    virtual std::string help() const;

protected:
    /**
     * Tries to cast the string value s to the templated parameter T. If this
     * succeeds, true is returned; otherwise false. The
     * conversion is done via an std::stringstream so it can only cast those
     * types supported by the stream.
     * \tparam T The type of the value which should be converted
     * \param s The std::string representation of the value
     * \param t The reference which will store the converted value
     * \return true if the conversion was successful, false
     * otherwise
     */
    template <class T>
    bool cast(const std::string& s, T& t) {
        std::istringstream iss(s);
        iss >> std::dec >> t;
        return !(iss.fail());
    }

    /**
     * Checks if the string value s can be cast into the type T.
     * It only returns true for those values that can be converted using an
     * std::stringstream
     * \tparam T The type of the value which should be converted
     * \param s The std::string representation of the value
     * \return true if the value can be converted, false
     * otherwise
     */
    template <class T>
    bool is(const std::string& s) {
        std::istringstream iss(s);
        T t;
        iss >> std::dec >> t;
        return !(iss.fail());
    }

    /// Name of the command used on command-line level
    std::string _name;
    /// The short name of this command which is also usable (usually an abbreviation)
    std::string _shortName;
    /// A description of the command; used in the #help method
    std::string _infoText;
    /// The parameter list necessary for the #usage method
    std::string _parameterList;
    /// Name used as a prefix for logging
    std::string _loggerCat;
    /// Stores the number of arguments this command accepts
    int _argumentNum;
    /// Stores, if the command can be called multiple times in a single command line
    bool _allowsMultipleCalls;
    /// Error message set by checkParameters().
    std::string _errorMsg;
};

}  // namespace cmdparser
}  // namespace ghoul

#endif  //__COMMANDLINECOMMAND_H__


text:
```php
public array getList ( void )
```

## Details

Class: [BearCMS\Themes\Theme\Options](bearcms.themes.theme.options.class.md)

Location: ~/classes/BearCMS/Themes/Theme/Options.php

---

[back to index](index.md)


text:
@class BRRenderScene;

@interface ATVPluginBrowserController : BRMediaMenuController
{
    NSArray *               _plugins;
    ATVURLDataRetriever *   _asyncLoader;
    NSString *              _imageName;
    NSDictionary *          _pluginInfo;
    NSArray *               _installedPlugins;
}

+ (NSString *) controllerLabel;

- (id) initWithPlugins: (NSArray *) plugins scene: (BRRenderScene *) scene;
- (void) dealloc;

- (BOOL) isNetworkDependent;

- (void) itemSelected: (long) row;
- (id <BRMediaPreviewController>) previewControllerForItem: (long) item;

- (long) itemCount;
- (id) itemForRow: (long) row;
- (NSString *) titleForRow: (long) row;
- (long) rowForTitle: (NSString *) title;

@end


text:
package io.undertow.server.handlers.form;

import io.undertow.UndertowLogger;
import io.undertow.UndertowMessages;
import io.undertow.UndertowOptions;
import io.undertow.connector.PooledByteBuffer;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.UrlDecodeException;
import io.undertow.util.Headers;
import io.undertow.util.SameThreadExecutor;
import io.undertow.util.URLUtils;
import org.xnio.ChannelListener;
import org.xnio.IoUtils;
import org.xnio.channels.StreamSourceChannel;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * Parser definition for form encoded data. This handler takes effect for any request that has a mime type
 * of application/x-www-form-urlencoded. The handler attaches a {@link FormDataParser} to the chain
 * that can parse the underlying form data asynchronously.
 *
 * @author Stuart Douglas
 */
public class FormEncodedDataDefinition implements FormParserFactory.ParserDefinition<FormEncodedDataDefinition> {

    public static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
    private static boolean parseExceptionLogAsDebug = false;
    private String defaultEncoding = "ISO-8859-1";
    private boolean forceCreation = false; //if the parser should be created even if the correct headers are missing

    public FormEncodedDataDefinition() {
    }

    @Override
    public FormDataParser create(final HttpServerExchange exchange)  {
        String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
        if (forceCreation || (mimeType != null && mimeType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED))) {

            String charset = defaultEncoding;
            String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
            if (contentType != null) {
                String cs = Headers.extractQuotedValueFromHeader(contentType, "charset");
                if (cs != null) {
                    charset = cs;
                }
            }
            UndertowLogger.REQUEST_LOGGER.tracef("Created form encoded parser for %s", exchange);
            return new FormEncodedDataParser(charset, exchange);
        }
        return null;
    }

    public String getDefaultEncoding() {
        return defaultEncoding;
    }

    public boolean isForceCreation() {
        return forceCreation;
    }

    public FormEncodedDataDefinition setForceCreation(boolean forceCreation) {
        this.forceCreation = forceCreation;
        return this;
    }

    public FormEncodedDataDefinition setDefaultEncoding(final String defaultEncoding) {
        this.defaultEncoding = defaultEncoding;
        return this;
    }

    private static final class FormEncodedDataParser implements ChannelListener<StreamSourceChannel>, FormDataParser {

        private final HttpServerExchange exchange;
        private final FormData data;
        private final StringBuilder builder = new StringBuilder();
        private String name = null;
        private String charset;
        private HttpHandler handler;

        //0= parsing name
        //1=parsing name, decode required
        //2=parsing value
        //3=parsing value, decode required
        //4=finished
        private int state = 0;

        private FormEncodedDataParser(final String charset, final HttpServerExchange exchange) {
            this.exchange = exchange;
            this.charset = charset;
            this.data = new FormData(exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, 1000));
        }

        @Override
        public void handleEvent(final StreamSourceChannel channel) {
            try {
                doParse(channel);
                if (state == 4) {
                    exchange.dispatch(SameThreadExecutor.INSTANCE, handler);
                }
            } catch (IOException e) {
                IoUtils.safeClose(channel);
                UndertowLogger.REQUEST_IO_LOGGER.ioExceptionReadingFromChannel(e);
                exchange.endExchange();

            }
        }

        private void doParse(final StreamSourceChannel channel) throws IOException {
            int c = 0;
            final PooledByteBuffer pooled = exchange.getConnection().getByteBufferPool().allocate();
            try {
                final ByteBuffer buffer = pooled.getBuffer();
                do {
                    buffer.clear();
                    c = channel.read(buffer);
                    if (c > 0) {
                        buffer.flip();
                        while (buffer.hasRemaining()) {
                            byte n = buffer.get();
                            switch (state) {
                                case 0: {
                                    if (n == '=') {
                                        name = builder.toString();
                                        builder.setLength(0);
                                        state = 2;
                                    } else if (n == '&') {
                                        addPair(builder.toString(), "");
                                        builder.setLength(0);
                                        state = 0;
                                    } else if (n == '%' || n == '+' || n < 0) {
                                        state = 1;
                                        builder.append((char) (n & 0xFF));
                                    } else {
                                        builder.append((char) n);
                                    }
                                    break;
                                }
                                case 1: {
                                    if (n == '=') {
                                        name = decodeParameterName(builder.toString(), charset, true, new StringBuilder());
                                        builder.setLength(0);
                                        state = 2;
                                    } else if (n == '&') {
                                        addPair(decodeParameterName(builder.toString(), charset, true, new StringBuilder()), "");
                                        builder.setLength(0);
                                        state = 0;
                                    } else {
                                        builder.append((char) (n & 0xFF));
                                    }
                                    break;
                                }
                                case 2: {
                                    if (n == '&') {
                                        addPair(name, builder.toString());
                                        builder.setLength(0);
                                        state = 0;
                                    } else if (n == '%' || n == '+' || n < 0) {
                                        state = 3;
                                        builder.append((char) (n & 0xFF));
                                    } else {
                                        builder.append((char) n);
                                    }
                                    break;
                                }
                                case 3: {
                                    if (n == '&') {
                                        addPair(name, decodeParameterValue(name, builder.toString(), charset, true, new StringBuilder()));
                                        builder.setLength(0);
                                        state = 0;
                                    } else {
                                        builder.append((char) (n & 0xFF));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                } while (c > 0);
                if (c == -1) {
                    if (state == 2) {
                        addPair(name, builder.toString());
                    } else if (state == 3) {
                        addPair(name, decodeParameterValue(name, builder.toString(), charset, true, new StringBuilder()));
                    } else if(builder.length() > 0) {
                        if(state == 1) {
                            addPair(decodeParameterName(builder.toString(), charset, true, new StringBuilder()), "");
                        } else {
                            addPair(builder.toString(), "");
                        }
                    }
                    state = 4;
                    exchange.putAttachment(FORM_DATA, data);
                }
            } finally {
                pooled.close();
            }
        }

        private void addPair(String name, String value) {
            //if there was exception during decoding ignore the parameter [UNDERTOW-1554]
            if(name != null && value != null) {
                data.add(name, value);
            }
        }

        private String decodeParameterValue(String name, String value, String charset, boolean decodeSlash, StringBuilder stringBuilder) {
            String decodedValue = null;

            try {
                decodedValue = URLUtils.decode(value, charset, decodeSlash, stringBuilder);
            } catch (UrlDecodeException e) {
                if (!parseExceptionLogAsDebug) {
                    UndertowLogger.REQUEST_LOGGER.errorf(UndertowMessages.MESSAGES.failedToDecodeParameterValue(name, value, e));
                    parseExceptionLogAsDebug = true;
                } else {
                    UndertowLogger.REQUEST_LOGGER.debugf(UndertowMessages.MESSAGES.failedToDecodeParameterValue(name, value, e));
                }
            }

            return decodedValue;
        }

        private String decodeParameterName(String name, String charset, boolean decodeSlash, StringBuilder stringBuilder) {
            String decodedName = null;

            try {
                decodedName = URLUtils.decode(name, charset, decodeSlash, stringBuilder);
            } catch (UrlDecodeException e) {
                if (!parseExceptionLogAsDebug) {
                    UndertowLogger.REQUEST_LOGGER.errorf(UndertowMessages.MESSAGES.failedToDecodeParameterName(name, e));
                    parseExceptionLogAsDebug = true;
                } else {
                    UndertowLogger.REQUEST_LOGGER.debugf(UndertowMessages.MESSAGES.failedToDecodeParameterName(name, e));
                }
            }

            return decodedName;
        }

        @Override
        public void parse(HttpHandler handler) throws Exception {
            if (exchange.getAttachment(FORM_DATA) != null) {
                handler.handleRequest(exchange);
                return;
            }
            this.handler = handler;
            StreamSourceChannel channel = exchange.getRequestChannel();
            if (channel == null) {
                throw new IOException(UndertowMessages.MESSAGES.requestChannelAlreadyProvided());
            } else {
                doParse(channel);
                if (state != 4) {
                    channel.getReadSetter().set(this);
                    channel.resumeReads();
                } else {
                    exchange.dispatch(SameThreadExecutor.INSTANCE, handler);
                }
            }
        }

        @Override
        public FormData parseBlocking() throws IOException {
            final FormData existing = exchange.getAttachment(FORM_DATA);
            if (existing != null) {
                return existing;
            }

            StreamSourceChannel channel = exchange.getRequestChannel();
            if (channel == null) {
                throw new IOException(UndertowMessages.MESSAGES.requestChannelAlreadyProvided());
            } else {
                while (state != 4) {
                    doParse(channel);
                    if (state != 4) {
                        channel.awaitReadable();
                    }
                }
            }
            return data;
        }

        @Override
        public void close() throws IOException {

        }

        @Override
        public void setCharacterEncoding(final String encoding) {
            this.charset = encoding;
        }
    }

}


text:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

// Get rid of the below attributes, because 1) When compiling for NetStandard they get copied from somewhere and the compiler
// complains the below are duplicates; and 2) they are not used anyway.

//[assembly: AssemblyTitle("JSNLog")]
//[assembly: AssemblyDescription("")]
//[assembly: AssemblyConfiguration("")]
//[assembly: AssemblyCompany("")]
//[assembly: AssemblyProduct("JSNLog")]
//[assembly: AssemblyCopyright("Copyright ©  2016")]
//[assembly: AssemblyTrademark("")]
//[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dc2f1e35-c7cc-4054-8671-424e801a104e")]

// Get the compiler to create a strong named assembly, using the key pair in this file.
// Note that they key file gets checked into Github, as per
// http://stackoverflow.com/questions/36141302/why-is-it-recommended-to-include-the-private-key-used-for-assembly-signing-in-op
[assembly: AssemblyKeyFileAttribute("../jsnlog.strongname.snk")]

// Allow project JSNLog.Tests to access the internals of this project.
// Have to add the public key of JSNLog.Tests (which lives in the JSNLog.Tests solution),
// because this JSNLog project is strongly signed.
//
// See https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx
// To get the public key, in Visual Studio command window, run:
// sn -p jsnlog.tests.strongname.snk public.out
// sn -tp public.out
//
[assembly: InternalsVisibleTo("JSNLog.Tests, PublicKey=" +
    "002400000480000094000000060200000024000052534131000400000100010089dd0d93cfa65f" +
    "cebdc52181975e43cbe31d26ed803efeaa3ba5df99b602c5ca0dfc5131d14f15f8e57845171632" +
    "53ffb1f070476dd13062903dda4fa93deb0982bf3e7956da923e94f40ac22b42c356d8c4b9434f" +
    "a81d2c528afa798d7ff7ff3691a19e270acc184ed7c77a0c74991558be3e06ce8a08e8169d1ba3" +
    "78d17283")]


text:
const helpers = require("../../helpers");
const headers = helpers.decorator(require("../../../src/middleware/headers"));
const connect = require("connect");
const request = require("supertest");

const defaultHeaders = [
  { source: "/test1", headers: [{ key: "Content-Type", value: "mime/type" }] },
  {
    source: "/test3",
    headers: [
      { key: "Access-Control-Allow-Origin", value: "https://www.example.net" },
    ],
  },
  {
    source: "/api/**",
    headers: [{ key: "Access-Control-Allow-Origin", value: "*" }],
  },
];

function okay(req, res) {
  res.writeHead(200);
  res.end();
}

describe("cors middleware", () => {
  it("serves custom content types", (done) => {
    const app = connect()
      .use(headers({ headers: defaultHeaders }))
      .use(okay);

    request(app)
      .get("/test1")
      .expect(200)
      .expect("Content-Type", "mime/type")
      .end(done);
  });

  it("serves custom access control headers", (done) => {
    const app = connect()
      .use(headers({ headers: defaultHeaders }))
      .use(okay);

    request(app)
      .get("/test3")
      .expect(200)
      .expect("Access-Control-Allow-Origin", "https://www.example.net")
      .end(done);
  });

  it("uses routing rules", (done) => {
    const app = connect()
      .use(headers({ headers: defaultHeaders }))
      .use(okay);

    request(app)
      .get("/api/whatever/you/wish")
      .expect(200)
      .expect("Access-Control-Allow-Origin", "*")
      .end(done);
  });

  it("uses glob negation to set headers", (done) => {
    const app = connect()
      .use(
        headers({
          headers: [
            {
              source: "!/anything/**",
              headers: [{ key: "custom-header", value: "for testing" }],
            },
          ],
        })
      )
      .use(okay);

    request(app)
      .get("/something")
      .expect(200)
      .expect("custom-header", "for testing")
      .end(done);
  });

  it("uses regular expressions to set headers", (done) => {
    const app = connect()
      .use(
        headers({
          headers: [
            {
              regex: "/resources/\\d+\\.jpg",
              headers: [{ key: "custom-header", value: "for testing" }],
            },
          ],
        })
      )
      .use(okay);

    request(app)
      .get("/resources/281.jpg")
      .expect(200)
      .expect("custom-header", "for testing")
      .end(done);
  });
});


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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/category_icon"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_width="@dimen/icon_selector_change"
        android:layout_height="@dimen/icon_selector_change"
        android:padding="@dimen/middle_padding"
        android:layout_marginRight="10dp"
        android:layout_marginEnd="10dp"
        android:tint="@color/primary"
        android:background="@drawable/icon_change_background"/>

    <EditText
        android:id="@+id/category_name"
        style="@style/DialogContent"
        android:layout_toRightOf="@id/category_icon"
        android:layout_toEndOf="@id/category_icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapSentences"
        android:singleLine="true"
        android:imeOptions="actionDone"/>

</RelativeLayout>


text:
package com.hazelcast.console;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.HazelcastInstanceAware;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.DataSerializable;
import com.hazelcast.nio.serialization.impl.BinaryInterface;

import java.io.IOException;
import java.util.concurrent.Callable;

/**
 * Echoes to screen.
 */
@BinaryInterface
public class Echo implements Callable<String>, DataSerializable, HazelcastInstanceAware {

    String input;

    private transient HazelcastInstance hz;

    public Echo(String input) {
        this.input = input;
    }

    @Override
    public String call() {
        hz.getCountDownLatch("latch").countDown();
        return hz.getCluster().getLocalMember().toString() + ":" + input;
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        out.writeUTF(input);
    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {
        input = in.readUTF();
    }

    @Override
    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
        this.hz = hazelcastInstance;
    }
}


text:
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';

@Injectable()
export class DataService {

  filteredData: any = [];
  private subject = new Subject<any>();

  setData(data: any) {

    this.filteredData = data;
    this.subject.next(data);
  }
  getData(): Observable<any> {
    return this.subject.asObservable();
  }
  getFilteredData() {
    if (this.filteredData && this.filteredData.length > 0) {
      return this.filteredData;
    }
    else {
      return [];
    }
  }

}


text:
require_relative 'spec_helper'
require_relative '../lib/blank_monkeypatch'

describe Object do
  it 'should have the blank? method' do
    Object.new.should respond_to :blank?
  end

  it 'should be blank if nil' do
    o = nil
    o.blank?.should be true
  end

  context 'a string' do
    it 'should be blank if empty' do
      ''.blank?.should be true
    end

    it 'should not be blank if not empty' do
      'not blank'.blank?.should be false
    end
  end
end


text:
<!DOCTYPE html>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Visual Alchemist</title>

<link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='css/bootstrap.min-3.3.5.css'/>
<link rel="icon" href="img/thumb.png"/>
<link type="text/css" href="lib/prettify/prettify.css" rel="stylesheet" />
<link rel='stylesheet' href='css/app.css'/>

      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        Toggle navigation

      </button>

 New Table

 Clear All

 Code

 Export Canvas

<form action="#" onchange="importCanvas();"><input id="inputCanvasFile" type="file"> Import Canvas</input></form>
-->

 Help

          Links

Github Project

Bug Tracker

Discussion Room

About

				  <button type="button" class="close" data-dismiss="alert">×Close</button>
				  How to: Just click the New Table link above to start creating tables.
				  Once done, simply click the Code button to get the python code for the sqlalchemy models!

				  To create relationships, drag the orange dots (primary-keys) and connect them to blue dots (candidate foreign-keys).

© Prahlad Yeri . Code licensed under GPLv3.


text:
package com.beecavegames.common.handlers;

import java.util.HashMap;
import java.util.Map;

import com.beecavegames.GameSession;
import com.beecavegames.Network;
import com.beecavegames.Product;
import com.beecavegames.bjc.util.PlayerUtil;
import com.beecavegames.common.Response;
import com.beecavegames.common.data.AltSummary;
import com.beecavegames.data.AppId;
import com.beecavegames.dispatch.Param;
import com.beecavegames.entities.User;
import com.google.inject.Inject;

import lombok.NoArgsConstructor;

public class StartIncentiveHandler {

	@NoArgsConstructor
	public static class StartIncentiveResponse extends Response {

		public int statusCode;
		public Map<Long,AltSummary> alts = new HashMap<>(); // Long is BeeID

		public StartIncentiveResponse(GameSession session) {
			super(session);
		}
	}

	@Inject
	PlayerUtil playerUtil;

	// revised process:
	//  1. client determines a product, makes a request. productReq will be that product (per Product.java)
	//  2. server responds with a full product code (from, to, level, amount); also stores it local

	// rough process:
	//  0. client has already received an incentive proposal
	//  1. user says "let's do it"
	//  2. client makes a request with the incentive code (from, to, level, reward)
	//  3. server verifies the product code
	//  4. once it passes muster, record the proposal in the correct places
	public StartIncentiveResponse handle(@Param("incentiveCode") final String code) {
		GameSession session = GameSession.getGameSession();
		StartIncentiveResponse response = new StartIncentiveResponse(session);

		// verify components : levelproduct, grantproduct, level, amount
		String[] components = code.split(",");
		if (components.length!=4) {
			response.statusCode = 400;
			return response;
		}

		// stash in player that will be leveling up, if it's been created already
		User user = playerUtil.getUser(session.beeId);
		Map<AppId, Long> assocs = user.getAppAssociations();
		Product prod = Product.valueOf(components[0]);
		AppId myAppId = new AppId(prod, Network.FACEBOOK);
		Long key = assocs.get(myAppId);
		if (key!=null) {
			// target player (that the player needs to level up to, eg, 10, already exists)
			playerUtil.modifyPlayer(key, tplayer -> {
				tplayer.internalCrossPromoIncentiveCode = code;
			});
		}

		playerUtil.modifyPlayer(session.beeId, player -> {
			player.inboundIncentiveCode = code;
		});

		// done
		response.statusCode = 100;
		return response;

	}
/*
	// build code
	String newcode = createCode(response.levelProduct, response.level, response.grantToProduct, response.amount);

	// stash in level product player
	User user = playerUtil.getUser(session.beeId);
	Map<AppId, Long> assocs = user.getAppAssociations();
	String prod = targetProduct + ":FACEBOOK"; // should use the same network
	if (assocs.containsKey(prod)) {
		// target player (that the player needs to level up to, eg, 10, already exists)
		Long beeidKey = assocs.get(prod);
		playerUtil.modifyPlayer(beeidKey, tplayer -> {
			tplayer.internalCrossPromoIncentiveCode = newcode;
		});
	}
	// otherwise, wait for it to be created. Code is in EntryPointServlet.onAuth/PlayerUtil.newPlayerSetup

	playerUtil.modifyPlayer(session.beeId, player -> {
		player.inboundIncentiveCode = newcode;
	});
*/
/*
	Map<Long,Player> players = store.loadAll(Player.class, assocs.values(), AbstractStore.AVOID_CACHE_POLLUTION);
	Map<Long,User> users = store.loadAll(User.class, assocs.values(), AbstractStore.AVOID_CACHE_POLLUTION);
	for (Player player: players.values()) {
		// create summary and append to the response
		User u2 = users.get(player.getBeeId());
		//alts.add(new AltSummary(u2, player));
		response.alts.put(player.getBeeId(), new AltSummary(u2, player));
	}
*/
/*
	static private String createCode(String levelProduct, int level, String toProduct, int amount) {
		String rv = levelProduct + "," + level + "," + toProduct + "," + amount;
		return rv;
	}
*/
}


text:
const { predicate, Table, RecordBatchReader } = require('../targets/es2015/cjs');
const { col } = predicate;

const Benchmark = require('benchmark');

const suites = [];

for (let { name, buffers } of require('./table_config')) {
    const parseSuiteName = `Parse "${name}"`;
    const sliceSuiteName = `Slice "${name}" vectors`;
    const iterateSuiteName = `Iterate "${name}" vectors`;
    const getByIndexSuiteName = `Get "${name}" values by index`;
    const sliceToArraySuiteName = `Slice toArray "${name}" vectors`;
    suites.push(createTestSuite(parseSuiteName, createFromTableTest(name, buffers)));
    suites.push(createTestSuite(parseSuiteName, createReadBatchesTest(name, buffers)));
    const table = Table.from(buffers), schema = table.schema;
    suites.push(...schema.fields.map((f, i) => createTestSuite(getByIndexSuiteName, createGetByIndexTest(table.getColumnAt(i), f.name))));
    suites.push(...schema.fields.map((f, i) => createTestSuite(iterateSuiteName, createIterateTest(table.getColumnAt(i), f.name))));
    suites.push(...schema.fields.map((f, i) => createTestSuite(sliceToArraySuiteName, createSliceToArrayTest(table.getColumnAt(i), f.name))));
    suites.push(...schema.fields.map((f, i) => createTestSuite(sliceSuiteName, createSliceTest(table.getColumnAt(i), f.name))));
}

for (let {name, buffers, countBys, counts} of require('./table_config')) {
    const table = Table.from(buffers);

    const tableIterateSuiteName = `Table Iterate "${name}"`;
    const dfCountBySuiteName = `DataFrame Count By "${name}"`;
    const dfFilterCountSuiteName = `DataFrame Filter-Scan Count "${name}"`;
    const dfDirectCountSuiteName = `DataFrame Direct Count "${name}"`;

    suites.push(createTestSuite(tableIterateSuiteName, createTableIterateTest(table)));
    suites.push(...countBys.map((countBy) => createTestSuite(dfCountBySuiteName, createDataFrameCountByTest(table, countBy))));
    suites.push(...counts.map(({ col, test, value }) => createTestSuite(dfFilterCountSuiteName, createDataFrameFilterCountTest(table, col, test, value))));
    suites.push(...counts.map(({ col, test, value }) => createTestSuite(dfDirectCountSuiteName, createDataFrameDirectCountTest(table, col, test, value))));
}

console.log('Running apache-arrow performance tests...\n');

run();

function run() {
    var suite = suites.shift();
    suite && suite.on('complete', function() {
        console.log(suite.name + ':\n' + this.map(function(x) {
            var str = x.toString();
            var meanMsPerOp = Math.round(x.stats.mean * 100000)/100;
            var sliceOf60FPS = Math.round((meanMsPerOp / (1000/60)) * 100000)/1000;
            return `${str}\n   avg: ${meanMsPerOp}ms\n   ${sliceOf60FPS}% of a frame @ 60FPS ${x.suffix || ''}`;
        }).join('\n') + '\n');
        if (suites.length > 0) {
            setTimeout(run, 1000);
        }
    })
    .run({ async: true });
}

function createTestSuite(name, test) {
    return new Benchmark.Suite(name, { async: true }).add(test);
}

function createFromTableTest(name, buffers) {
    let table;
    return {
        async: true,
        name: `Table.from\n`,
        fn() { table = Table.from(buffers); }
    };
}

function createReadBatchesTest(name, buffers) {
    let recordBatch;
    return {
        async: true,
        name: `readBatches\n`,
        fn() { for (recordBatch of RecordBatchReader.from(buffers)) {} }
    };
}

function createSliceTest(vector, name) {
    let xs;
    return {
        async: true,
        name: `name: '${name}', length: ${vector.length}, type: ${vector.type}\n`,
        fn() { xs = vector.slice(); }
    };
}

function createSliceToArrayTest(vector, name) {
    let xs;
    return {
        async: true,
        name: `name: '${name}', length: ${vector.length}, type: ${vector.type}\n`,
        fn() { xs = vector.slice().toArray(); }
    };
}

function createIterateTest(vector, name) {
    let value;
    return {
        async: true,
        name: `name: '${name}', length: ${vector.length}, type: ${vector.type}\n`,
        fn() { for (value of vector) {} }
    };
}

function createGetByIndexTest(vector, name) {
    let value;
    return {
        async: true,
        name: `name: '${name}', length: ${vector.length}, type: ${vector.type}\n`,
        fn() {
            for (let i = -1, n = vector.length; ++i < n;) {
                value = vector.get(i);
            }
        }
    };
}

function createTableIterateTest(table) {
    let value;
    return {
        async: true,
        name: `length: ${table.length}\n`,
        fn() { for (value of table) {} }
    };
}

function createDataFrameDirectCountTest(table, column, test, value) {
    let sum, colidx = table.schema.fields.findIndex((c)=>c.name === column);

    if (test == 'gt') {
        op = () => {
            sum = 0;
            let batches = table.chunks;
            let numBatches = batches.length;
            for (let batchIndex = -1; ++batchIndex < numBatches;) {
                // load batches
                const batch = batches[batchIndex];
                const vector = batch.getChildAt(colidx);
                // yield all indices
                for (let index = -1, length = batch.length; ++index < length;) {
                    sum += (vector.get(index) >= value);
                }
            }
            return sum;
        }
    } else if (test == 'eq') {
        op = () => {
            sum = 0;
            let batches = table.chunks;
            let numBatches = batches.length;
            for (let batchIndex = -1; ++batchIndex < numBatches;) {
                // load batches
                const batch = batches[batchIndex];
                const vector = batch.getChildAt(colidx);
                // yield all indices
                for (let index = -1, length = batch.length; ++index < length;) {
                    sum += (vector.get(index) === value);
                }
            }
            return sum;
        }
    } else {
        throw new Error(`Unrecognized test "${test}"`);
    }

    return {
        async: true,
        name: `name: '${column}', length: ${table.length}, type: ${table.getColumnAt(colidx).type}, test: ${test}, value: ${value}\n`,
        fn: op
    };
}

function createDataFrameCountByTest(table, column) {
    let colidx = table.schema.fields.findIndex((c)=> c.name === column);

    return {
        async: true,
        name: `name: '${column}', length: ${table.length}, type: ${table.getColumnAt(colidx).type}\n`,
        fn() {
            table.countBy(column);
        }
    };
}

function createDataFrameFilterCountTest(table, column, test, value) {
    let colidx = table.schema.fields.findIndex((c)=> c.name === column);
    let df;

    if (test == 'gt') {
        df = table.filter(col(column).gt(value));
    } else if (test == 'eq') {
        df = table.filter(col(column).eq(value));
    } else {
        throw new Error(`Unrecognized test "${test}"`);
    }

    return {
        async: true,
        name: `name: '${column}', length: ${table.length}, type: ${table.getColumnAt(colidx).type}, test: ${test}, value: ${value}\n`,
        fn() {
            df.count();
        }
    };
}


text:
<?php

class CM_FormField_Birthdate extends CM_FormField_Date {

    /** @var integer */
    protected $_minAge;

    /** @var integer */
    protected $_maxAge;

    /**
     * @param int $minAge
     * @param int $maxAge
     */
    public function __construct($minAge, $maxAge) {
        $this->_minAge = (int) $minAge;
        $this->_maxAge = (int) $maxAge;

        $yearFirst = date('Y') - $this->_minAge;
        $yearLast = date('Y') - $this->_maxAge;
        parent::__construct($yearFirst, $yearLast);
    }

    public function validate($userInput, CM_Response_Abstract $response) {
        $userInput = parent::validate($userInput, $response);
        $age = $userInput->diff(new DateTime())->y;
        if ($age < $this->_minAge || $age > $this->_maxAge) {
            throw new CM_Exception_FormFieldValidation('Invalid birthdate');
        }
        return $userInput;
    }
}


text:
TEST_CASE( "Factorials are computed")
{

    REQUIRE( 1 == 1 );

    HelloWorldPrinter printer;
    printer.Print();

}


text:
package org.apache.batik.dom.svg12;

import org.apache.batik.dom.events.AbstractEvent;
import org.apache.batik.dom.xbl.ShadowTreeEvent;
import org.apache.batik.dom.xbl.XBLShadowTreeElement;

/**
 * This class implements the {@link ShadowTreeEvent} event class.
 *
 * @author Cameron McCormack
 * @version $Id: XBLOMShadowTreeEvent.java 475477 2006-11-15 22:44:28Z cam $
 */
public class XBLOMShadowTreeEvent extends AbstractEvent
                                  implements ShadowTreeEvent {

    /**
     * The shadow tree that is the object of this event.
     */
    protected XBLShadowTreeElement xblShadowTree;

    /**
     * Returns the shadow tree that is the object of this event.
     */
    public XBLShadowTreeElement getXblShadowTree() {
        return xblShadowTree;
    }

    /**
     * Initializes this event object.
     */
    public void initShadowTreeEvent(String typeArg,
                                    boolean canBubbleArg,
                                    boolean cancelableArg,
                                    XBLShadowTreeElement xblShadowTreeArg) {
        initEvent(typeArg, canBubbleArg, cancelableArg);
        xblShadowTree = xblShadowTreeArg;
    }

    /**
     * Initializes this event object with a namespaced event type.
     */
    public void initShadowTreeEventNS(String namespaceURIArg,
                                      String typeArg,
                                      boolean canBubbleArg,
                                      boolean cancelableArg,
                                      XBLShadowTreeElement xblShadowTreeArg) {
        initEventNS(namespaceURIArg, typeArg, canBubbleArg, cancelableArg);
        xblShadowTree = xblShadowTreeArg;
    }
}


text:
package io.apptik.tarator;

public class AndroidCubes {
}


text:
<?php
/**
 *
 */

namespace Mvc5\Test\Response;

use Mvc5\Http\HttpHeaders;
use Mvc5\Response\RedirectResponse;
use Mvc5\Test\Test\TestCase;

final class RedirectTest
    extends TestCase
{
    /**
     *
     */
    function test()
    {
        $redirect = new RedirectResponse('foobar', 302, ['foo' => 'bar']);

        $this->assertEquals(302, $redirect->status());
        $this->assertEquals(new HttpHeaders(['Location' => 'foobar', 'foo' => 'bar']), $redirect->headers());
    }
}


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
in van der Walt et al. , Antonie van Leeuwenhoek 37(4): 456 (1971)

#### Original name
Candida entomophila D.B. Scott, van der Walt & Klift, 1971

### Remarks
null


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

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.hyperledger.common.TID;

import java.io.IOException;

public class TIDSerializer extends StdSerializer<TID> {
    public TIDSerializer() {
        super(TID.class);
    }

    @Override
    public void serialize(TID value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeString(value.toString());
    }
}


text:
package de.kumpelblase2.remoteentities.services;

import org.bukkit.entity.LivingEntity;

public interface NMSEntityService
{
	public boolean checkAffected(LivingEntity inEntity);
	public void resetAffection(LivingEntity inEntity);
}


text:
<?php

namespace Gladtur\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        if($this->getUser() && $this->getUser()->hasRole('ROLE_ADMIN')){
            return $this->redirect('/admin/tag');
        }
        if($this->getUser() && $this->getUser()->hasRole('ROLE_TVGUSER')){
            return $this->redirect('/test');
        }
        return $this->redirect('/login');
		$menuItems = array('Oversigt over Tags' => 'tag', 'Oversigt over stedtags' => 'locationtag', 'Oversigt over steder' =>'location', 'Oversigt over tag-kategorier' => 'tagcategory');
        return $this->render('GladturTagBundle:Default:index.html.twig', array('menuItems' => $menuItems));
    }
}


text:
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import AnchorControllerSupport from 'ember-anchor/mixins/controller-support';
import { tracked } from '@glimmer/tracking';

export default class MethodsController extends Controller.extend(
  AnchorControllerSupport
) {
  @service
  filterData;

  @tracked
  anchor;

  queryParams = ['anchor'];

  updateAnchor(fieldName) {
    this.anchor = fieldName;
  }
}


text:
const cloneDeep = require("lodash/cloneDeep");
const has = require("lodash/has");
const { normalizeREProperties } = require("../utl/normalize-re-properties");

const VALID_SEVERITIES = /^(error|warn|info|ignore)$/;
const DEFAULT_SEVERITY = "warn";
const DEFAULT_RULE = "unnamed";
const DEFAULT_SCOPE = "module";

function normalizeSeverity(pSeverity) {
  const lSeverity = pSeverity ? pSeverity : DEFAULT_SEVERITY;

  return Boolean(lSeverity.match(VALID_SEVERITIES))
    ? lSeverity
    : DEFAULT_SEVERITY;
}
/**
 *
 * @param {string} pRuleName
 * @returns {string}
 */
function normalizeName(pRuleName) {
  return pRuleName ? pRuleName : DEFAULT_RULE;
}

/**
 *
 * @param {import("../../../types/shared-types").RuleScopeType} pScope?
 * @returns {import("../../../types/shared-types").RuleScopeType}
 */
function normalizeScope(pScope) {
  return pScope ? pScope : DEFAULT_SCOPE;
}

/**
 *
 * @param {import("../../../types/rule-set").IAnyRuleType} pRule
 * @returns {import("../../../types/strict-rule-set").IStrictAnyRuleType}
 */
function normalizeRule(pRule) {
  return {
    ...pRule,
    severity: normalizeSeverity(pRule.severity),
    name: normalizeName(pRule.name),
    from: normalizeREProperties(pRule.from),
    to: normalizeREProperties(pRule.to),
    scope: normalizeScope(pRule.scope),
    ...(pRule.module ? { module: normalizeREProperties(pRule.module) } : {}),
  };
}

/**
 * 'Normalizes' the given rule set pRuleSet by adding default values for
 * attributes that are optional and not present in the rule set; in casu:
 * - rule name (default 'unnamed')
 * - severity (default 'warn')
 *
 * @param  {import("../../../types/dependency-cruiser").IFlattenedRuleSet} pRuleSet
 * @return {import("../../../types/strict-rule-set").IStrictRuleSet}
 */
module.exports = function normalizeRuleSet(pRuleSet) {
  const lRuleSet = cloneDeep(pRuleSet);

  if (has(lRuleSet, "allowed")) {
    lRuleSet.allowedSeverity = normalizeSeverity(lRuleSet.allowedSeverity);
    if (lRuleSet.allowedSeverity === "ignore") {
      Reflect.deleteProperty(lRuleSet, "allowed");
      Reflect.deleteProperty(lRuleSet, "allowedSeverity");
    } else {
      lRuleSet.allowed = lRuleSet.allowed.map((pRule) => ({
        ...pRule,
        name: "not-in-allowed",
        from: normalizeREProperties(pRule.from),
        to: normalizeREProperties(pRule.to),
      }));
    }
  }

  if (has(lRuleSet, "forbidden")) {
    lRuleSet.forbidden = lRuleSet.forbidden
      .map(normalizeRule)
      .filter((pRule) => pRule.severity !== "ignore");
  }

  if (has(lRuleSet, "required")) {
    lRuleSet.required = lRuleSet.required
      .map(normalizeRule)
      .filter((pRule) => pRule.severity !== "ignore");
  }

  return lRuleSet;
};


text:
<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: google/bigtable/admin/v2/instance.proto

namespace Google\Cloud\Bigtable\Admin\V2;

use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;

/**
 * Limits for the number of nodes a Cluster can autoscale up/down to.
 *
 * Generated from protobuf message google.bigtable.admin.v2.AutoscalingLimits
 */
class AutoscalingLimits extends \Google\Protobuf\Internal\Message
{
    /**
     * Required. Minimum number of nodes to scale down to.
     *
     * Generated from protobuf field int32 min_serve_nodes = 1 [(.google.api.field_behavior) = REQUIRED];
     */
    private $min_serve_nodes = 0;
    /**
     * Required. Maximum number of nodes to scale up to.
     *
     * Generated from protobuf field int32 max_serve_nodes = 2 [(.google.api.field_behavior) = REQUIRED];
     */
    private $max_serve_nodes = 0;

    /**
     * Constructor.
     *
     * @param array $data {
     *     Optional. Data for populating the Message object.
     *
     *     @type int $min_serve_nodes
     *           Required. Minimum number of nodes to scale down to.
     *     @type int $max_serve_nodes
     *           Required. Maximum number of nodes to scale up to.
     * }
     */
    public function __construct($data = NULL) {
        \GPBMetadata\Google\Bigtable\Admin\V2\Instance::initOnce();
        parent::__construct($data);
    }

    /**
     * Required. Minimum number of nodes to scale down to.
     *
     * Generated from protobuf field int32 min_serve_nodes = 1 [(.google.api.field_behavior) = REQUIRED];
     * @return int
     */
    public function getMinServeNodes()
    {
        return $this->min_serve_nodes;
    }

    /**
     * Required. Minimum number of nodes to scale down to.
     *
     * Generated from protobuf field int32 min_serve_nodes = 1 [(.google.api.field_behavior) = REQUIRED];
     * @param int $var
     * @return $this
     */
    public function setMinServeNodes($var)
    {
        GPBUtil::checkInt32($var);
        $this->min_serve_nodes = $var;

        return $this;
    }

    /**
     * Required. Maximum number of nodes to scale up to.
     *
     * Generated from protobuf field int32 max_serve_nodes = 2 [(.google.api.field_behavior) = REQUIRED];
     * @return int
     */
    public function getMaxServeNodes()
    {
        return $this->max_serve_nodes;
    }

    /**
     * Required. Maximum number of nodes to scale up to.
     *
     * Generated from protobuf field int32 max_serve_nodes = 2 [(.google.api.field_behavior) = REQUIRED];
     * @param int $var
     * @return $this
     */
    public function setMaxServeNodes($var)
    {
        GPBUtil::checkInt32($var);
        $this->max_serve_nodes = $var;

        return $this;
    }

}


text:
@implementation CALayer (QMUI)

- (void)qmui_sendSublayerToBack:(CALayer *)sublayer {
    if (sublayer.superlayer == self) {
        [sublayer removeFromSuperlayer];
        [self insertSublayer:sublayer atIndex:0];
    }
}

- (void)qmui_bringSublayerToFront:(CALayer *)sublayer {
    if (sublayer.superlayer == self) {
        [sublayer removeFromSuperlayer];
        [self insertSublayer:sublayer atIndex:(unsigned)self.sublayers.count];
    }
}

- (void)qmui_removeDefaultAnimations {
    NSMutableDictionary<NSString *, id<CAAction>> *actions = @{NSStringFromSelector(@selector(bounds)): [NSNull null],
                                                               NSStringFromSelector(@selector(position)): [NSNull null],
                                                               NSStringFromSelector(@selector(zPosition)): [NSNull null],
                                                               NSStringFromSelector(@selector(anchorPoint)): [NSNull null],
                                                               NSStringFromSelector(@selector(anchorPointZ)): [NSNull null],
                                                               NSStringFromSelector(@selector(transform)): [NSNull null],
                                                               BeginIgnoreClangWarning(-Wundeclared-selector)
                                                               NSStringFromSelector(@selector(hidden)): [NSNull null],
                                                               NSStringFromSelector(@selector(doubleSided)): [NSNull null],
                                                               EndIgnoreClangWarning
                                                               NSStringFromSelector(@selector(sublayerTransform)): [NSNull null],
                                                               NSStringFromSelector(@selector(masksToBounds)): [NSNull null],
                                                               NSStringFromSelector(@selector(contents)): [NSNull null],
                                                               NSStringFromSelector(@selector(contentsRect)): [NSNull null],
                                                               NSStringFromSelector(@selector(contentsScale)): [NSNull null],
                                                               NSStringFromSelector(@selector(contentsCenter)): [NSNull null],
                                                               NSStringFromSelector(@selector(minificationFilterBias)): [NSNull null],
                                                               NSStringFromSelector(@selector(backgroundColor)): [NSNull null],
                                                               NSStringFromSelector(@selector(cornerRadius)): [NSNull null],
                                                               NSStringFromSelector(@selector(borderWidth)): [NSNull null],
                                                               NSStringFromSelector(@selector(borderColor)): [NSNull null],
                                                               NSStringFromSelector(@selector(opacity)): [NSNull null],
                                                               NSStringFromSelector(@selector(compositingFilter)): [NSNull null],
                                                               NSStringFromSelector(@selector(filters)): [NSNull null],
                                                               NSStringFromSelector(@selector(backgroundFilters)): [NSNull null],
                                                               NSStringFromSelector(@selector(shouldRasterize)): [NSNull null],
                                                               NSStringFromSelector(@selector(rasterizationScale)): [NSNull null],
                                                               NSStringFromSelector(@selector(shadowColor)): [NSNull null],
                                                               NSStringFromSelector(@selector(shadowOpacity)): [NSNull null],
                                                               NSStringFromSelector(@selector(shadowOffset)): [NSNull null],
                                                               NSStringFromSelector(@selector(shadowRadius)): [NSNull null],
                                                               NSStringFromSelector(@selector(shadowPath)): [NSNull null]}.mutableCopy;

    if ([self isKindOfClass:[CAShapeLayer class]]) {
        [actions addEntriesFromDictionary:@{NSStringFromSelector(@selector(path)): [NSNull null],
                                            NSStringFromSelector(@selector(fillColor)): [NSNull null],
                                            NSStringFromSelector(@selector(strokeColor)): [NSNull null],
                                            NSStringFromSelector(@selector(strokeStart)): [NSNull null],
                                            NSStringFromSelector(@selector(strokeEnd)): [NSNull null],
                                            NSStringFromSelector(@selector(lineWidth)): [NSNull null],
                                            NSStringFromSelector(@selector(miterLimit)): [NSNull null],
                                            NSStringFromSelector(@selector(lineDashPhase)): [NSNull null]}];
    }

    if ([self isKindOfClass:[CAGradientLayer class]]) {
        [actions addEntriesFromDictionary:@{NSStringFromSelector(@selector(colors)): [NSNull null],
                                            NSStringFromSelector(@selector(locations)): [NSNull null],
                                            NSStringFromSelector(@selector(startPoint)): [NSNull null],
                                            NSStringFromSelector(@selector(endPoint)): [NSNull null]}];
    }

    self.actions = actions;
}

+ (CALayer *)qmui_separatorLayer {
    CALayer *layer = [CALayer layer];
    [layer qmui_removeDefaultAnimations];
    layer.backgroundColor = UIColorSeparator.CGColor;
    layer.frame = CGRectMake(0, 0, 0, PixelOne);
    return layer;
}

+ (CALayer *)qmui_separatorLayerForTableView {
    CALayer *layer = [self qmui_separatorLayer];
    layer.backgroundColor = TableViewSeparatorColor.CGColor;
    return layer;
}

@end


text:
template: post.html
title: What Have Language Models Learned?
summary: By asking language models to fill in the blank, we can probe their understanding of the world.
shareimg: https://pair.withgoogle.com/explorables/images/fill-in-the-blank.png
shareimgabstract: https://pair.withgoogle.com/explorables/images/fill-in-the-blank-abstract.png
permalink: /fill-in-the-blank/
date: 2021-07-28
---

Large language models are making it possible for computers to [write stories](https://openai.com/blog/better-language-models/), [program a website](https://twitter.com/sharifshameem/status/1282676454690451457) and [turn captions into images](https://openai.com/blog/dall-e/).

One of the first of these models, [BERT](https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html), is trained by taking sentences, splitting them into individual words, randomly hiding some of them, and predicting what the hidden words are. After doing this millions of times, BERT has "read" enough Shakespeare to predict how this phrase usually ends:

This page is hooked up to a version of BERT trained on Wikipedia and books.¹ Try clicking on different words to see how they'd be filled in or typing in another sentence to see what else has BERT picked up on.

### Cattle or Clothes?

Besides Hamlet's existential dread, the text BERT was trained on also contains more patterns:

Cattle and horses aren't top purchase predictions in every state, though! In New York, some of the most likely words are clothes, books and art:

There are more than 30,000 words, punctuation marks and word fragments in BERT's [vocabulary](https://huggingface.co/transformers/tokenizer_summary.html). Every time BERT fills in a hidden word, it assigns each of them a probability. By looking at how slightly different sentences shift those probabilities, we can get a glimpse at how purchasing patterns in different places are understood.

You can **edit these sentences**. Or try one of these comparisons to get started:

To the extent that a computer program can "know" something, what does BERT know about where you live?
### What's in a Name?

This technique can also probe what associations BERT has learned about different groups of people. For example, it predicts people named Elsie are older than people named Lauren:

It's also learned that people named Jim have more [typically masculine](https://flowingdata.com/2017/09/11/most-female-and-male-occupations-since-1950/) jobs than people named Jane:

These aren't just spurious correlations — Elsies really are more likely to be [older](https://rhiever.github.io/name-age-calculator/) than Laurens. And occupations the model associates with feminine names are held by a [higher percentage](https://purehost.bath.ac.uk/ws/portalfiles/portal/168480066/CaliskanEtAl_authors_full.pdf ) of women.

Should we be concerned about these correlations? BERT was trained to fill in blanks in Wikipedia articles and books —  it does a great job at that! The problem is that the internal representations of language these models have learned are used for much more – by some [measures](https://super.gluebenchmark.com/leaderboard), they're the best way we have of getting computers to understand and manipulate text.

We wouldn't hesitate to call a conversation partner or recruiter who blithely assumed that doctors are men sexist, but that's exactly what BERT might do if heedlessly incorporated into a chatbot or HR software:

Adjusting for assumptions like this isn't trivial. *Why* machine learning systems produce a given output still isn't well understood – determining if a credit model built on top of BERT rejected a loan application because of [gender discrimation](https://pair.withgoogle.com/explorables/hidden-bias/) might be quite difficult.

Deploying large language models at scale also risks [amplifying](https://machinesgonewrong.com/bias_i/#harms-of-representation) and [perpetuating](http://faculty.washington.edu/ebender/papers/Stochastic_Parrots.pdf) today's harmful stereotypes. When [prompted](https://arxiv.org/pdf/2101.05783v1.pdf#page=3) with "Two Muslims walked into a…", for example, [GPT-3](https://en.wikipedia.org/wiki/GPT-3) typically finishes the sentence with descriptions of violence.
### How Can We Fix This?

One conceptually straightforward approach: reduce unwanted correlations from the training data to [mitigate](https://arxiv.org/abs/1906.08976) model [bias](https://arxiv.org/abs/2005.14050).

Last year a version of BERT called [Zari](https://ai.googleblog.com/2020/10/measuring-gendered-correlations-in-pre.html) was [trained](https://arxiv.org/pdf/2010.06032.pdf#page=6) with an additional set of generated sentences. For every sentence with a [gendered noun](https://github.com/uclanlp/corefBias/blob/master/WinoBias/wino/generalized_swaps.txt), like boy or aunt, another sentence that replaced the noun with its gender-partner was added to the training data: in addition to "The *lady* doth protest too much," Zari was also trained on "The *gentleman* doth protest too much."

Unlike BERT, Zari assigns nurses and doctors an equal probability of being a "she" or a "he" after being trained on the swapped sentences. This approach hasn't removed all the gender correlations; because names weren't swapped, Zari's association between masculine names and doctors has only slightly decreased from BERT's. And the retraining doesn't change how the model understands nonbinary gender.

Something similar happened with [other attempts](https://arxiv.org/abs/1607.06520) to remove gender bias from models' representations of words. It's possible to mathematically define bias and perform "brain surgery" on a model to remove it, but language is steeped in gender. Large models can have billions of parameters in which to learn stereotypes — slightly different measures of bias have found the retrained models only [shifted the stereotypes](https://www.aclweb.org/anthology/N19-1061/) around to be undetectable by the initial measure.

As with [other applications](https://pair.withgoogle.com/explorables/measuring-fairness/) of machine learning, it's helpful to focus instead on the actual harms that could occur. Tools like [AllenNLP](https://allennlp.org/), [LMdiff](http://lmdiff.net/) and the [Language Interpretability Tool](https://pair-code.github.io/lit/) make it easier to interact with language models to find where they might be falling short. Once those shortcomings are spotted, [task specific](https://arxiv.org/abs/2004.07667) mitigation measures can be simpler to apply than modifying the entire model.

It's also possible that as models grow more capable, they might be able to [explain](https://arxiv.org/abs/2004.14546) and perform some of this debiasing themselves. Instead of forcing the model to tell us the gender of "the doctor," we could let it respond with [uncertainty](https://arr.am/2020/07/25/gpt-3-uncertainty-prompts/) that's [shown to the user](https://ai.googleblog.com/2018/12/providing-gender-specific-translations.html) and controls to override assumptions.

### Credits

Adam Pearce // July 2021

Thanks to Ben Wedin, Emily Reif, James Wexler, Fernanda Viégas, Ian Tenney, Kellie Webster, Kevin Robinson, Lucas Dixon, Ludovic Peran, Martin Wattenberg, Michael Terry, Tolga Bolukbasi, Vinodkumar Prabhakaran, Xuezhi Wang, Yannick Assogba, and Zan Armstrong for their help with this piece.

### Footnotes

 The BERT model used on this page is the Hugging Face version of [bert-large-uncased-whole-word-masking](https://huggingface.co/bert-large-uncased-whole-word-masking). "BERT" also refers to a type of model architecture; hundreds of BERT models have been [trained and published](https://huggingface.co/models?filter=bert). The model and chart code used here are available on [GitHub](https://github.com/PAIR-code/ai-explorables).

 Notice that "1800", "1900" and "2000" are some of the top predictions, though. People aren't actually more likely to be born at the start of a century, but in BERT's training corpus of books and Wikipedia articles round numbers are [more common](https://blocks.roadtolarissa.com/1wheel/cea123a8c17d51d9dacbd1c17e6fe601).

Comparing BERT and Zari in this interface requires carefully tracking tokens during a transition. The [BERT Difference Plots](https://colab.research.google.com/drive/1xfPGKqjdE635cVSi-Ggt-cRBU5pyJNWP) colab has ideas for extensions to systemically look at differences between the models' output.

 This analysis shouldn't stop once a model is deployed — as language and model usage shifts, it's important to continue studying and mitigating potential harms.

### Appendix: Differences Over Time

In addition to looking at how predictions for <c0>men</c0> and <c1>women</c1> are different for a given sentence, we can also chart how those differences have changed over time:

The convergence in more recent years suggests another potential mitigation technique: using a prefix to steer the model away from unwanted correlations while preserving its understanding of natural language.

Using "In $year" as the prefix is quite limited, though, as it doesn't handle <c2>gender-neutral</c2> pronouns and potentially [increases](https://www.pnas.org/content/pnas/115/16/E3635.full.pdf#page=8) other correlations. However, it may be possible to [find a better prefix](https://arxiv.org/abs/2104.08691) that mitigates a specific type of bias with just a [couple of dozen examples](https://www.openai.com/blog/improving-language-model-behavior/  ).

Closer examination of these differences in differences also shows there's a limit to the facts we can pull out of BERT this way.

Below, the top row of charts shows how predicted differences in occupations between men and women change between 1908 and 2018. The rightmost chart shows the he/she difference in 1908 against the he/she difference in 2018.

The flat slope of the rightmost chart indicates that the he/she difference has decreased for each job by about the same amount. But in reality, [shifts in occupation](https://www.weforum.org/agenda/2016/03/a-visual-history-of-gender-and-employment) weren't nearly so smooth and some occupations, like accounting, switched from being majority male to majority female.

This reality-prediction mismatch could be caused by lack of training data, model size or the coarseness of the probing method. There's an immense amount of general knowledge inside of these models — with a little bit of focused training, they can even become expert [trivia](https://t5-trivia.glitch.me/) players.

More Explorables

<link rel="stylesheet" href="style.css">


text:
import requests

def get_remote_addr(request):
    address = request.headers.get('X-Forwarded-For', request.remote_addr)
    if address is not None:
        address = address.encode('utf-8')
        address = address.split(',')[0]
    else:
        address = request.remote_addr

    return address

def get_location_data(ip):
    geoip_server = 'http://ec2-54-152-137-106.compute-1.amazonaws.com:8080/json'
    if not (ip and geoip_server):
        return

    url = '%s/%s' % (geoip_server, ip)
    try:
        resp = requests.get(url)
        resp.raise_for_status()
        return resp.json()
    except Exception as e:
        print 'Error fetching location: ' + sys.exc_info()


text:
"""Part of speech tag annotator"""
from __future__ import absolute_import
from .annotator import Annotator, AnnoSpan, AnnoTier
from .spacy_annotator import SpacyAnnotator

class POSAnnotator(Annotator):

    def annotate(self, doc):
        if 'spacy.tokens' not in doc.tiers:
            doc.add_tiers(SpacyAnnotator())
        pos_spans = [AnnoSpan(span.start, span.end, doc, label=span.token.tag_)
                     for span in doc.tiers['spacy.tokens'].spans]
        doc.tiers['pos'] = AnnoTier(pos_spans)
        return doc


text:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <display-name>Transmem Web Application</display-name>
  <description>
     Transmem web application.
  </description>

  <resource-ref>
	<description>PostgreSQL Datasource for Transmem database</description>
	<res-ref-name>jdbc/Transmem</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
  </resource-ref>

  <servlet>
	<servlet-name>Transmem</servlet-name>
	<servlet-class>com.transmem.TransmemServlet</servlet-class>
	<init-param>
		<param-name>ds-MAIN-READWRITE</param-name>
		<param-value>jdbc/Transmem</param-value>
	</init-param>
	<init-param>
		<param-name>ds-USER-READ</param-name>
		<param-value>jdbc/Transmem</param-value>
	</init-param>
	<init-param>
		<param-name>ds-CORPUS-READWRITE</param-name>
		<param-value>jdbc/Transmem</param-value>
	</init-param>
  </servlet>

  <servlet-mapping>
	<servlet-name>Transmem</servlet-name>
	<url-pattern>/tm</url-pattern>
  </servlet-mapping>

  <error-page>
    <error-code>999</error-code>
    <location>/WEB-INF/jsp/error.jsp</location>
  </error-page>

  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

</web-app>


text:
<meta charset="utf-8"/>
<?php if(isset($title) && $title): ?>
<title><?php echo $title ?> - Aria Templates - Javascript Framework</title>
<?php else: ?>
<title>Aria Templates - Javascript Framework</title>
<?php endif; ?>
<link href="/favicon.ico" type="image/ico" rel="shortcut icon"/>
<link title="AriaTemplates" href="/fluidicon.png" rel="fluid-icon"/>
<link rel="stylesheet" href="/styles/all.css" type="text/css"/>
<script type="text/javascript">//Aria={debug:true}</script>
<script type="text/javascript" src="/aria/aria-templates-1.7.13.js"></script>
<script type="text/javascript" src="/css/atwiki-1.7.13.js"></script>

<!--[if lt IE 9]>
<script type="text/javascript" src="/js/iemap.js"></script>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" type="text/javascript" charset="utf-8"></script>
<style>
	.ie-hidden {
		display: none;
	}
</style>
<![endif]-->
<!--[if lt IE 8]>
<link href="/styles/ie/ie7.css" rel="stylesheet" type="text/css"/>
<![endif]-->

<script type="text/javascript" src="/js/carouselmap.js"></script>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-29575860-1']);
  _gaq.push(['_setDomainName', 'ariatemplates.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>


text:
package org.camunda.bpm.tasklist.impl;

import org.camunda.bpm.tasklist.TasklistRuntimeDelegate;
import org.camunda.bpm.tasklist.plugin.spi.TasklistPlugin;
import org.camunda.bpm.webapp.impl.AbstractAppRuntimeDelegate;

/**
 * @author Roman Smirnov
 *
 */
public class DefaultTasklistRuntimeDelegate extends AbstractAppRuntimeDelegate<TasklistPlugin> implements TasklistRuntimeDelegate {

  public DefaultTasklistRuntimeDelegate() {
    super(TasklistPlugin.class);
  }

}


text:
import ez_setup
ez_setup.use_setuptools()

from setuptools import setup, find_packages, Extension, Feature
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError, DistutilsExecError, \
                             DistutilsPlatformError
import numpy

BUILD_EXT_WARNING = """
WARNING: The C extensions could not be compiled.
         Pebl will run normally but will be slower.

Below is the output showing how the compilation failed:
"""

long_desc = """
Pebl is a python library and command line application for learning the
structure of a Bayesian network given prior knowledge and observations.  Pebl
includes the following features:

 * Can learn with observational and interventional data
 * Handles missing values and hidden variables using exact and heuristic
   methods
 * Provides several learning algorithms; makes creating new ones simple
 * Supports hard and soft structural priors
 * Has facilities for transparent parallel execution
 * Calculates edge marginals and consensus networks
 * Presents results in a variety of formats
"""

# This class allows C extension building to fail.
# from http://simplejson.googlecode.com/svn/trunk/setup.py
class ve_build_ext(build_ext):
    def run(self):
        try:
            build_ext.run(self)
        except DistutilsPlatformError, x:
            self._unavailable(x)

    def build_extension(self, ext):
        try:
            build_ext.build_extension(self, ext)
        except (CCompilerError, DistutilsExecError), x:
           self._unavailable(x)

    def _unavailable(self, exc):
         print '*'*70
         print BUILD_EXT_WARNING
         print exc
         print '*'*70

# C extension modules (as an optional feature)
speedymodules = Feature(
    "Optional speedier C modules.",
    standard = True,
    ext_modules = [
        Extension('pebl._network', sources=['src/pebl/_network.c']),
        Extension('pebl._cpd', sources=['src/pebl/_cpd.c'],
                  include_dirs=[numpy.get_include()]),
    ]
)

setup(
    name='pebl',
    version='1.0.2',
    description='Python Environment for Bayesian Learning',
    long_description = long_desc,
    package_dir={'': 'src'},
    packages=find_packages('src'),

    ## Package metadata.. for upload to PyPI
    author='Abhik Shah',
    author_email='abhikshah@gmail.comm',
    url='http://pebl-project.googlecode.com',
    download_url='http://pypi.python.org/pypi/pebl',
    license='MIT',
    zip_safe=False,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
        'Topic :: Scientific/Engineering :: Bio-Informatics',
    ],

    # required dependencies
    install_requires=[
        # 'numpy >= 1.0.3',     # matrices, linear algebra, etc
        'pydot',                # to output network as dot file
        'pyparsing >= 1.4.7',   # required by pydot but not specified in its setup
    ],

    # data files, resources, etc
    include_package_data = True,

    # tests
    test_suite = 'nose.collector',

    # scripts
    entry_points = {
        'console_scripts': [
            'pebl = pebl.pebl_script:main'
        ]
    },

    # C extension modules (as an optional feature)
    features = { 'speedups': speedymodules },

    # build extensions optionally
    cmdclass={'build_ext': ve_build_ext},
)


text:
"""
========================================================================================================
Tutorials for Developing Scientific Workflows in Pycroscopy - Part 3: Handling Multidimensional datasets
========================================================================================================

**Suhas Somnath**
8/8/2017

This set of notebooks will serve as examples for developing end-to-end workflows for and using pycroscopy.

**In this example, we will learn how to slice multidimensional datasets.**

Introduction
============

In pycroscopy, all position dimensions of a dataset are collapsed into the first dimension and all other
(spectroscopic) dimensions are collapsed to the second dimension to form a two dimensional matrix. The ancillary
matricies, namely the spectroscopic indices and values matrix as well as the position indicies and values matrices
will be essential for reshaping the data back to its original N dimensional form and for slicing multidimensional
datasets

"""

# Ensure python 3 compatibility:
from __future__ import division, print_function, absolute_import, unicode_literals

# The package for accessing files in directories, etc.:
import os
import wget

# The mathematical computation package:
import numpy as np

# The package used for creating and manipulating HDF5 files:
import h5py

# Packages for plotting:
import matplotlib.pyplot as plt

# basic interactive widgets:
from ipywidgets import interact

# Finally import pycroscopy for certain scientific analysis:
import pycroscopy as px

#########################################################################
# Load the dataset
# ================
#
# For this example, we will be working with a Band Excitation Polarization Switching (BEPS) First Order Reversal
# Curve (FORC) dataset acquired from advanced atomic force microscopes. In the much simpler Band Excitation (BE)
# imaging datasets, a single spectra is acquired at each location in a two dimensional grid of spatial locations.
# Thus, BE imaging datasets have two position dimensions (X, Y) and one spectroscopic dimension (frequency - against
# which the spectra is recorded). The BEPS-FORC dataset used in this example has a spectra for each combination of
# three other paramaters (DC offset, Field, bias waveform type {FORC}). Thus, this dataset has three new spectral
# dimensions in addition to the spectra itself. Hence, this dataet becomes a 2+4 = 6 dimensional dataset

# download the raw data file from Github:
h5_path = 'temp.h5'
url = 'https://raw.githubusercontent.com/pycroscopy/pycroscopy/master/data/FORC_BEPS.h5'
if os.path.exists(h5_path):
    os.remove(h5_path)
_ = wget.download(url, h5_path, bar=None)

# Open the file in read-only mode
h5_file = h5py.File(h5_path, mode='r')

print('Datasets and datagroups within the file:\n------------------------------------')
px.hdf_utils.print_tree(h5_file)

#########################################################################

h5_meas_grp = h5_file['Measurement_000']
h5_main = h5_meas_grp['Channel_000/Raw_Data']
print('\nThe main dataset:\n------------------------------------')
print(h5_main)

#########################################################################
# The main dataset clearly does not provide the multidimensional information about the data that will be necessary to
# slice the data. For that we need the ancillary datasets that support this main dataset

# pycroscopy has a convenient function to access datasets linked to a given dataset:
h5_spec_ind = px.hdf_utils.getAuxData(h5_main, 'Spectroscopic_Indices')[0]
h5_spec_val = px.hdf_utils.getAuxData(h5_main, 'Spectroscopic_Values')[0]
h5_pos_ind = px.hdf_utils.getAuxData(h5_main, 'Position_Indices')[0]
h5_pos_val = px.hdf_utils.getAuxData(h5_main, 'Position_Values')[0]

#########################################################################
# Understanding the ancillary datasets:
# =====================================
#
# The position datasets are shaped as [spatial points, dimension] while the spectroscopic datasets are shaped as
# [dimension, spectral points]. Clearly the first axis of the position dataset and the second axis of the spectroscopic
# datasets match the correponding sizes of the main dataset.
#
# Again, the sum of the position and spectroscopic dimensions results in the 6 dimensions originally described above.
#
# Essentially, there is a unique combination of position and spectroscopic parameters for each cell in the two
# dimensionam main dataset. The interactive widgets below illustrate this point. The first slider represents the
# position dimension while the second represents the spectroscopic dimension. Each position index can be decoded
# to a set of X and Y indices and values while each spectroscopic index can be decoded into a set of frequency,
# dc offset, field, and forc parameters

print('Main Datasets of shape:', h5_main.shape)
print('Position Datasets of shape:', h5_pos_ind.shape)
print('Spectroscopic Datasets of shape:', h5_spec_ind.shape)

spec_labels = px.hdf_utils.get_formatted_labels(h5_spec_ind)
pos_labels = px.hdf_utils.get_formatted_labels(h5_pos_ind)

def myfun(pos_index, spec_index):
    for dim_ind, dim_name in enumerate(pos_labels):
        print(dim_name,':',h5_pos_ind[pos_index, dim_ind])
    for dim_ind, dim_name in enumerate(spec_labels):
        print(dim_name,':',h5_spec_ind[dim_ind, spec_index])
interact(myfun, pos_index=(0,h5_main.shape[0]-1, 1), spec_index=(0,h5_main.shape[1]-1, 1));

#########################################################################
# Visualizing the ancillary datasets
# ==================================
#
# The plots below show how the position and spectrocopic dimensions vary. Due to the high dimensionality of the
# spectroscopic dimensions, the variation of each dimension has been plotted separately.
#
# How we interpret these plots:
# =============================
#
# **Positions**: For each Y index, the X index ramps up from 0 to 4 and repeats. Essentially, this means that for
# a given Y index, there were multiple measurments (different values of X)
#
# **Spectroscopic**: The plot for `FORC` shows that the next fastest dimension - `DC offset` was varied 6 times.
# Correspondingly, the plot for `DC offset` plot shows that this dimension ramps up from 0 to a little less than
# 40 for each `FORC` index. This trend is the same for the faster varying dimensions - `Frequency` and `Field`.

fig_1, axes = plt.subplots(ncols=2, figsize=(10, 5))
px.plot_utils.plot_line_family(axes[0], np.arange(h5_pos_ind.shape[0]), h5_pos_ind[()].T,
                               line_names=pos_labels)
axes[0].set_xlabel('Position points')
axes[0].set_ylabel('Index')
axes[0].set_title('Position Indices')
axes[0].legend()
px.plot_utils.plot_line_family(axes[1], np.arange(h5_spec_ind.shape[1]), h5_spec_ind,
                               line_names=spec_labels)
axes[1].set_xlabel('Spectroscopic points')
axes[1].set_title('Spectroscopic Indices')
axes[1].legend()

fig_2, axes = plt.subplots(ncols=3, nrows=2, figsize=(15, 10))
for dim_ind, axis, dim_label, dim_array in zip([0, 2], [axes.flat[0], axes.flat[3]],
                                               [spec_labels[0], spec_labels[2]],
                                               [h5_spec_ind[0, :500], h5_spec_ind[2, :500]]):
    axis.plot(np.arange(dim_array.size), dim_array)
    axis.set_xlabel('Spectroscopic points')
    axis.set_ylabel('Index')
    axis.set_title('Dim ' + str(dim_ind) + ' - ' + dim_label)

rhs_axes = [axes.flat[ind] for ind in [1, 2, 4, 5]]
for dim_ind, axis, dim_label, dim_array in zip(range(h5_spec_ind.shape[0]), rhs_axes, spec_labels, h5_spec_ind):
    axis.plot(np.arange(dim_array.size), dim_array)
    axis.set_xlabel('Spectroscopic points')
    axis.set_ylabel('Index')
    axis.set_title('Dim ' + str(dim_ind) + ' - ' + dim_label)

#########################################################################

# A similar version of this function is available in pycroscopy.io.hdf_utils.get_formatted_labels
def describe_dimensions(h5_aux):
    for name, unit in zip(px.hdf_utils.get_attr(h5_aux, 'labels'),
                            px.hdf_utils.get_attr(h5_aux, 'units')):
        print(name, '[', unit, ']')

print('Position dimension names and units:')
describe_dimensions(h5_pos_ind)

print('\nSpectrocopic dimension names and units:')
describe_dimensions(h5_spec_ind)

#########################################################################
# Now lets find the size in each dimension
# ========================================
# For now lets assume that data is sampled at each position and at each spectral step
# In other words lets assume that data was not sampled over a random subset of points within a grid of points

# The function below has been implemented as pycroscopy.io.hdf_utils.get_dimensionality
def get_dim_sizes(ind_dset, is_position=False):
    # ind_dset here is expected to be of the shape [dimension, points] like the spectroscopic indices
    if is_position:
        # Position dimensions will be turned from [points, dimension] to [dimension, points]
        ind_dset = np.transpose(ind_dset[()])

    dim_size = []
    for col in ind_dset:
        # For each dimension array, we will find the number of unique elements in it
        dim_size.append(len(np.unique(col)))
    return dim_size

pos_dim_sizes = get_dim_sizes(h5_pos_ind, is_position=True)
spec_dim_sizes = get_dim_sizes(h5_spec_ind)

print('Positions:', pos_dim_sizes, '\nSpectroscopic:', spec_dim_sizes)


text:
from math import floor, log10
from helpers import list_add, deepcopy

class Puzzle:

    def __init__(self, length):
        """
        Creates an ordered puzzle of dimension lengthXlength with length > 1
        :param length: Int the size of the edge of the puzzle
        """

        if (length <= 1 or length.__class__ != int):

            try:
                raise ValueError('length must be an integer greater than 1')

            except:
                print('something went wrong!')
                raise

        self.__length = length
        self.__possibilities = (True, False, True, False) # up, down, left, right
        self.__blank_box = (length-1, length-1)
        self.__board = [[i*length+j+1 for j in range(length)]
                for i in range(length)]
        self.__board[length-1][length-1] = None
        self.__sorted = deepcopy(self.__board)
        self.__previous_move = ''

    def __get_box(self, position):
        """
        Gets the item at the exact coordinate in the board
        :param position: An integer representation of the position.
        :returns: The item at the coordinate ((position/length), (position%length))
        """
        return self.__board[position//self.__length][position%self.__length]

    def is_sorted(self, ):
        return self.__board == self.__sorted

    def swap(self, direction):
        """
        Changes the position of the blank box
        :param direction: the direction to move the blank box, it must be either
        one of up, down, left or right
        """
        directions = {'up': (-1, 0), 'down': (1, 0), 'left': (0, -1), 'right': (0, 1),}
        new_row = self.__blank_box[0] + directions[direction][0]
        new_col = self.__blank_box[1] + directions[direction][1]
        new_position = self.__get_box((new_row*self.__length)+new_col)
        self.__board[self.__blank_box[0]][self.__blank_box[1]] \
                = new_position
        self.__board[new_row][new_col] = None
        self.__blank_box = (new_row, new_col)
        self.__set_possibilities()
        self.__previous_move = direction

    def __set_possibilities(self, ):
        self.__possibilities = ((self.__blank_box[0] > 0), (self.__blank_box[0] < self.__length-1),
            (self.__blank_box[1] > 0), (self.__blank_box[1] < self.__length-1))

    @property
    def previous_move(self, ):
        return self.__previous_move

    @property
    def length(self, ):
        return self.__length

    @property
    def possibilities(self, ):
        return self.__possibilities

    @property
    def blank_box(self, ):
        return self.__blank_box

    @property
    def board(self, ):
        return deepcopy(self.__board)

    @property
    def misplaceds(self, ):
        misplaceds = 0

        for row in range(self.__length):

            for col in range(self.__length):
                misplaced = self.__board[row][col] != self.__sorted[row][col]
                misplaceds += int(misplaced)

        return misplaceds

    @property
    def possible_moves(self):
        directions = ['up', 'down', 'left', 'right']
        moves = []

        for pos_index in range(4):

            if self.__possibilities[pos_index]:
                moves.append(directions[pos_index])

        return moves

    def __eq__(self, other):
        return self.__board == other.__board

    def __eq__(self, other):
        return self.__board == other.board

    def __str__(self, ):
        puzzle = ''
        max_digits = floor(log10(self.__length**2))+1
        last_col = self.__length-1

        for i in range(self.__length**2):
            digits = floor(log10(self.__get_box(i) or 1)+1)
            actual_col = i%self.__length
            puzzle += ' ' + ' ' * (max_digits-digits) \
                    + str(self.__get_box(i) or 'X') \
                    + ('\n' if actual_col == last_col else '')

        return puzzle


text:
<?php

class TeaException extends Exception {

}