text:
"""Test that the packet formatting function works as intended."""
import pytest

from charcoal import packets

def test_timer_packet():
    """Assert timer_packet works."""
    assert list(packets.timer_packet('name', 15)) == ['name:15000|ms']

def test_counter_packet():
    """Assert counter_packet works."""
    assert list(packets.counter_packet('name', 15)) == ['name:15|c']

def test_counter_packet_negative():
    """Assert counter_packet works, also with negative numbers."""
    assert list(packets.counter_packet('name', -15)) == ['name:-15|c']

@pytest.mark.parametrize('case, expected', [
    (15, ['name:15|g']),
    (-15, ['name:0|g', 'name:-15|g']),
    (0, ['name:0|g']),
])
def test_gauge_set_packet(case, expected):
    """Assert gauge_set_packet works."""
    assert list(packets.gauge_set_packet('name', case)) == expected

@pytest.mark.parametrize('case, expected', [
    (15, ['name:+15|g']),
    (-15, ['name:-15|g']),
])
def test_gauge_update_packet(case, expected):
    """Assert gauge_update_package works."""
    assert list(packets.gauge_update_packet('name', case)) == expected

def test_set_packet():
    """Assert set_packet works."""
    assert list(packets.set_packet('name', 15)) == ['name:15|s']


text:
<?php

require_once __DIR__ . "/../lib/Dropbox/strict.php";

if (PHP_SAPI !== "cli") {
    throw new \Exception("This program was meant to be run from the command-line and not as a web app.  Bad value for PHP_SAPI.  Expected \"cli\", given \"".PHP_SAPI."\".");
}

// NOTE: You should be using Composer's global autoloader.  But just so these examples
// work for people who don't have Composer, we'll use the library's "autoload.php".
require_once __DIR__ . '/../lib/Dropbox/autoload.php';

use \Dropbox as dbx;

if ($argc === 1) {
    echoHelp($argv[0]);
    die;
}

$remainingArgs = array();
$optionsAllowed = true;
$disable = false;
for ($i = 1; $i < $argc; $i++) {
    $arg = $argv[$i];
    if ($optionsAllowed && strpos($arg, "-") === 0) {
        if ($arg === "--") {
            $optionsAllowed = false;
            continue;
        }
        if ($arg === "--disable") {
            if ($disable) {
                fwrite(STDERR, "Option \"--disable\" used more than once.\n");
                die;
            }
            $disable = true;
        }
        else {
            fwrite(STDERR, "Unrecognized option \"$arg\".\n");
            fwrite(STDERR, "Run with no arguments for help\n");
        }
    }
    else {
        array_push($remainingArgs, $arg);
    }
}

if (count($remainingArgs) !== 3) {
    fwrite(STDERR, "Expecting exactly 3 non-option arguments, got ".count($remainingArgs)."\n");
    fwrite(STDERR, "Run with no arguments for help\n");
    die;
}

$appInfoFile = $remainingArgs[0];
$oauth1AccessToken = new dbx\OAuth1AccessToken($remainingArgs[1], $remainingArgs[2]);

try {
    list($appInfoJson, $appInfo) = dbx\AppInfo::loadFromJsonFileWithRaw($appInfoFile);
}
catch (dbx\AppInfoLoadException $ex) {
    fwrite(STDERR, "Error loading <app-info-file>: ".$ex->getMessage()."\n");
    die;
}

// Get an OAuth 2 access token.

$upgrader = new dbx\OAuth1Upgrader($appInfo, "examples-authorize", "en");
$oauth2AccessToken = $upgrader->createOAuth2AccessToken($oauth1AccessToken);
echo "OAuth 2 access token obtained.\n";

// Write out auth JSON.

$authArr = array(
    "access_token" => $oauth2AccessToken,
);

if (array_key_exists('host', $appInfoJson)) {
    $authArr['host'] = $appInfoJson['host'];
}

$json_options = 0;
if (defined('JSON_PRETTY_PRINT')) {
    $json_options |= JSON_PRETTY_PRINT;  // Supported in PHP 5.4+
}
echo json_encode($authArr, $json_options)."\n";

// Disable the OAuth 1 access token.

if ($disable) {
    $upgrader->disableOAuth1AccessToken($oauth1AccessToken);
    echo "OAuth 1 access token disabled.\n";
}

function echoHelp($command) {
    echo "\n";
    echo "Usage: $command <app-info-file> <oa1-access-token-key> <oa1-access-token-secret>\n";
    echo "\n";
    echo "<app-info-file>: A JSON file with information about your API app.  Example:\n";
    echo "\n";
    echo "  {\n";
    echo "    \"key\": \"Your Dropbox API app key\",\n";
    echo "    \"secret\": \"Your Dropbox API app secret\",\n";
    echo "  }\n";
    echo "\n";
    echo "  Get an API app key by registering with Dropbox:\n";
    echo "    https://dropbox.com/developers/apps\n";
    echo "\n";
    echo "<oa1-access-token-key>: The OAuth 1 access token key.\n";
    echo "\n";
    echo "<oa1-access-token-secret>: The OAuth 1 access token secret.\n";
    echo "\n";
    echo "Options:\n";
    echo "\n";
    echo "  --disable: After we get an OAuth 2 access token, tell the server to\n";
    echo "      disable the OAuth 1 access token.\n";
    echo "\n";
}

redpajama_set_name: RedPajamaGithub


text:
package migration;

import bbm.database.DatabaseModule;
import bbm.database.branches.Branch;
import bbm.database.branches.BranchModule;
import bbm.database.repositories.Repositories;
import bbm.database.repositories.Repository;
import bbm.database.repositories.RepositoryModule;
import com.google.inject.Injector;
import org.mongodb.morphia.Datastore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Scanner;

/**
 * Created by mario on 3/8/17.
 * This class is to migrate productive data to have branches related with repositories.
 * One branch belongs to exactly one repo.
 *
 * Requires that MONGODB_URI is set in the environment
 */
public class RelateBranchesWithRepositories {
    private final static Logger logger = LoggerFactory.getLogger(RelateBranchesWithRepositories.class);

    @Deprecated
    public static void main(String[] args) {
        Injector injector = com.google.inject.Guice.createInjector(
                new DatabaseModule(),
                new BranchModule(),
                new RepositoryModule()
        );

        Datastore datastore = injector.getInstance(Datastore.class);
        logger.info("***MongoClientDescription: {}", datastore.getDB().getName());

        Scanner in = new Scanner(System.in);

        logger.info("***Dry run (y/n)?:");
        Boolean dryRun = "y".equals(in.nextLine());

        Repositories repositories = injector.getInstance(Repositories.class);
        Repository repo = null;
        List<Repository> repos = repositories.getRepositories();
        if(repos.size() > 1){
            logger.info("***Found multiple repositories. Exiting!");
            return;
        }
        if(repos.size() == 1){
            logger.info("***Found a repository!");
            logger.info("***Name: {}, Uuid:{}", repos.get(0).getRepo_slug(), repos.get(0).getUuid());
            logger.info("***Take the existing one? (y/n)?:");
            Boolean take = "y".equals(in.nextLine());
            if(take) {
                repo = repos.get(0);
            }
        }
        if(repo == null) {
            Job job = getRepoJob(in, dryRun);
            if (!dryRun) {
                repo = createRepo(repositories, job);
            }
        }

        List<Branch> branches = datastore.find(Branch.class).asList();
        logger.info("***Found branches: {}", branches.size());

        for(Branch branch : branches){
            logger.info("***********************************************************");
            logger.info("***branch name: {}", branch.getName());
            logger.info("***branch managed: {}", branch.getManaged());
            Boolean reassign = true;
            if(branch.getRepository() != null) {
                logger.info("***branch repo is not null: {}", branch.getRepository().getRepo_slug());
                logger.info("Reassign to repo? ({})", repo.getRepo_slug());
                reassign = "y".equals(in.nextLine());
            }
            //if(reassign)
            //    branch.setRepository(repo);
        }

        if(!dryRun){
            datastore.save(branches);
        }
    }

    private static Repository createRepo(Repositories repositories, Job job) {
        repositories.createRepository(job.getRepoSlug(), job.getUuid(), job.getProvider());
        return repositories.getRepository(job.getUuid()).get();
    }

    private static Job getRepoJob(Scanner in, Boolean dryRun) {
        Job job;
        logger.info("***Repo UUID?: ");
        String uuid = in.next();

        logger.info("***Repo Name: ");
        String name = in.next();

        logger.info("***Repo provider is always Bitbucket.");
        job = new Job(dryRun, name, uuid, Repositories.Provider.BITBUCKET);

        logger.info("***Job:\n***dryRun: {}\n***uuid: {}\n***name: {}\n***provider: {}", job.getDryRun(), job.getUuid(), job.getRepoSlug(), job.getProvider().name());
        return job;
    }

    public static class Job {
        private final Boolean dryRun;
        private final String repoSlug;
        private final String uuid;
        private final Repositories.Provider provider;

        public Job(Boolean dryRun, String repoSlug, String uuid, Repositories.Provider provider) {
            this.dryRun = dryRun;
            this.repoSlug = repoSlug;
            this.uuid = uuid;
            this.provider = provider;
        }

        public Boolean getDryRun() {
            return dryRun;
        }

        public String getRepoSlug() {
            return repoSlug;
        }

        public String getUuid() {
            return uuid;
        }

        public Repositories.Provider getProvider() {
            return provider;
        }
    }
}


text:
package com.tectonica.jonix.codelist;

/*
 * NOTE: THIS IS AN AUTO-GENERATED FILE, DON'T EDIT MANUALLY
 */

/**
 * Enum that corresponds to ONIX Codelist 95
 *

 * Description: Default unit of weight
 *
 * @see ONIX Codelists
 */
public enum DefaultUnitOfWeights
{
	Pounds_US("lb"), //

	Grams("gr"), //

	Ounces_US("oz");

	public final String value;

	private DefaultUnitOfWeights(String value)
	{
		this.value = value;
	}

	public static DefaultUnitOfWeights byValue(String value)
	{
		if (value == null || value.isEmpty())
			return null;
		for (DefaultUnitOfWeights e : values())
			if (e.value.equals(value))
				return e;
		return null;
	}
}


text:
from ..excel_comparison_test import ExcelComparisonTest
from ...workbook import Workbook

class TestCompareXLSXFiles(ExcelComparisonTest):
    """
    Test file created by XlsxWriter against a file created by Excel.

    """

    def setUp(self):

        self.set_filename('tutorial02.xlsx')

        self.ignore_files = ['xl/calcChain.xml',
                             '[Content_Types].xml',
                             'xl/_rels/workbook.xml.rels']

    def test_create_file(self):
        """Example spreadsheet used in the tutorial 2."""

        workbook = Workbook(self.got_filename)
        worksheet = workbook.add_worksheet()

        # Add a bold format to use to highlight cells.
        bold = workbook.add_format({'bold': True})

        # Add a number format for cells with money.
        money_format = workbook.add_format({'num_format': '\\$#,##0'})

        # Write some data headers.
        worksheet.write('A1', 'Item', bold)
        worksheet.write('B1', 'Cost', bold)

        # Some data we want to write to the worksheet.
        expenses = (
            ['Rent', 1000],
            ['Gas', 100],
            ['Food', 300],
            ['Gym', 50],
        )

        # Start from the first cell below the headers.
        row = 1
        col = 0

        # Iterate over the data and write it out row by row.
        for item, cost in (expenses):
            worksheet.write(row, col, item)
            worksheet.write(row, col + 1, cost, money_format)
            row += 1

        # Write a total using a formula.
        worksheet.write(row, 0, 'Total', bold)
        worksheet.write(row, 1, '=SUM(B2:B5)', money_format, 1450)

        workbook.close()

        self.assertExcelEqual()


text:
package org.corundummc.listeners.plugins;

import org.corundummc.listeners.results.EventResult;
import org.corundummc.plugins.CorundumPlugin;

public interface PluginEnableListener {
    /** This listener method is called whenever a {@link CorundumPlugin} is enabled. When a plugin is enabled, its commands become usable and its listeners become active.
     *
     * @param plugin
     *            is the plugin that is currently being enabled.
     * @return @return the {@link EventResult} describing any changes to this event's properties. */
    public EventResult onPluginEnable(CorundumPlugin plugin);
}


text:
import actions from '../constants';

export default function (state = {}, action) {
  switch (action.type) {
    case actions.FETCH_SUBMISSION_SUCCESS:
    case actions.FETCH_SUBMISSIONS_SUCCESS:
      return action.payload.assessment;
    default:
      return state;
  }
}