text:
package com.yunhuwifi.service;
import java.io.File;
import java.io.FileOutputStream;
import org.xmlpull.v1.XmlSerializer;

import com.yunhuwifi.models.SmsField;
import com.yunhuwifi.util.FileUtil;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.util.Log;
import android.util.Xml;
import android.widget.Toast;

public class ExportSmsXml {
    Context context;
    public static final String SMS_URI_ALL = "content://sms/";
    private FileOutputStream outStream = null;
    private XmlSerializer serializer;

    public ExportSmsXml(Context context) {
        this.context = context;
    }

    public void xmlStart() {
    	String path = FileUtil.getFilePath("SMSBackup");
//        String path = Environment.getExternalStorageDirectory().getPath() + "/SMSBackup";
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        File file2 = new File(path, "message.xml");
        try {
            outStream = new FileOutputStream(file2);
            serializer = Xml.newSerializer();
            serializer.setOutput(outStream, "UTF-8");
            serializer.startDocument("UTF-8", true);
            serializer.startTag(null, "sms");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean createXml() throws Exception {

        this.xmlStart();
        Cursor cursor = null;
        try {
            ContentResolver conResolver = context.getContentResolver();
            String[] projection = new String[] { SmsField.ADDRESS, SmsField.PERSON, SmsField.DATE, SmsField.PROTOCOL,
                                                SmsField.READ, SmsField.STATUS, SmsField.TYPE, SmsField.REPLY_PATH_PRESENT,
                                                SmsField.BODY,SmsField.LOCKED,SmsField.ERROR_CODE, SmsField.SEEN }; // type=1是收件箱,==2是发件箱;read=0表示未读,read=1表示读过,seen=0表示未读,seen=1表示读过
            Uri uri = Uri.parse(SMS_URI_ALL);
            cursor = conResolver.query(uri, projection, null, null, "_id asc");
            if (cursor.moveToFirst()) {
                String address;
                String person;
                String date;
                String protocol;
                String read;
                String status;
                String type;
                String reply_path_present;
                String body;
                String locked;
                String error_code;
                String seen;
                do {
                    address = cursor.getString(cursor.getColumnIndex(SmsField.ADDRESS));
                    if (address == null) {
                        address = "";
                    }
                    person = cursor.getString(cursor.getColumnIndex(SmsField.PERSON));
                    if (person == null) {
                        person = "";
                    }
                    date = cursor.getString(cursor.getColumnIndex(SmsField.DATE));
                    if (date == null) {
                        date = "";
                    }
                    protocol = cursor.getString(cursor.getColumnIndex(SmsField.PROTOCOL));
                    if (protocol == null) {
                        protocol = "";
                    }
                    read = cursor.getString(cursor.getColumnIndex(SmsField.READ));
                    if (read == null) {
                        read = "";
                    }
                    status = cursor.getString(cursor.getColumnIndex(SmsField.STATUS));
                    if (status == null) {
                        status = "";
                    }
                    type = cursor.getString(cursor.getColumnIndex(SmsField.TYPE));
                    if (type == null) {
                        type = "";
                    }
                    reply_path_present = cursor.getString(cursor.getColumnIndex(SmsField.REPLY_PATH_PRESENT));
                    if (reply_path_present == null) {
                        reply_path_present = "";
                    }
                    body = cursor.getString(cursor.getColumnIndex(SmsField.BODY));
                    if (body == null) {
                        body = "";
                    }
                    locked = cursor.getString(cursor.getColumnIndex(SmsField.LOCKED));
                    if (locked == null) {
                        locked = "";
                    }
                    error_code = cursor.getString(cursor.getColumnIndex(SmsField.ERROR_CODE));
                    if (error_code == null) {
                        error_code = "";
                    }
                    seen = cursor.getString(cursor.getColumnIndex(SmsField.SEEN));
                    if (seen == null) {
                        seen = "";
                    }
                    serializer.startTag(null, "item");
                    serializer.attribute(null, SmsField.ADDRESS, address);
                    serializer.attribute(null, SmsField.PERSON, person);
                    serializer.attribute(null, SmsField.DATE, date);
                    serializer.attribute(null, SmsField.PROTOCOL, protocol);
                    serializer.attribute(null, SmsField.READ, read);
                    serializer.attribute(null, SmsField.STATUS, status);
                    serializer.attribute(null, SmsField.TYPE, type);
                    serializer.attribute(null, SmsField.REPLY_PATH_PRESENT, reply_path_present);
                    serializer.attribute(null, SmsField.BODY, body);
                    serializer.attribute(null, SmsField.LOCKED, locked);
                    serializer.attribute(null, SmsField.ERROR_CODE, error_code);
                    serializer.attribute(null, SmsField.SEEN, seen);
                    serializer.endTag(null, "item");

                } while (cursor.moveToNext());
            } else {
            	Toast.makeText(context, "备份失败",Toast.LENGTH_SHORT);
                return false;
            }

        } catch (SQLiteException ex) {
            ex.printStackTrace();
            Log.d("SQLiteException:", ex.getMessage());
        }finally {
            if(cursor != null) {
                cursor.close();
            }
        }
        serializer.endTag(null, "sms");
        serializer.endDocument();
        outStream.flush();
        outStream.close();
        Toast.makeText(context, "备份成功", Toast.LENGTH_SHORT);
        return true;
    }
}


text:
/**
 * \file PCI VM-to-host interface
 */

/*
 * Copyright (c) 2009, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

#include <stdlib.h>

#include "vmkitmon.h"
#include "pci.h"
#include "pci_host.h"
#include <dev/pci_hdr0_mem_dev.h>

#define INVALID         0xffffffff

#define VMKIT_PCI_HOST_DEBUG_SWITCH

#if defined(VMKIT_PCI_HOST_DEBUG_SWITCH)
#define VMKIT_PCI_HOST_DEBUG(x...) printf("VMKit PCI host: " x)
#else
#define VMKIT_PCI_HOST_DEBUG(x...) ((void)0)
#endif

struct pci_host {
    pci_hdr0_mem_t      ph;
    uint32_t            pci_header[0x40];
};

static void confspace_write(struct pci_device *dev,
                            union pci_config_address_word addr,
                            enum opsize size, uint32_t val)
{
}

static void confspace_read(struct pci_device *dev,
                           union pci_config_address_word addr,
                           enum opsize size, uint32_t *val)
{
    struct pci_host *h = dev->state;

    if(addr.d.fnct_nr != 0) {
        *val = INVALID;
        return;
    }

    if(addr.d.doubleword < 0x40) {
        *val = h->pci_header[addr.d.doubleword];
        VMKIT_PCI_HOST_DEBUG("reading register %d, opsize %d: %x\n",
                             addr.d.doubleword, size, *val);

        if(size == 1) {
            *val = (*val) & 0xffff;
        }
    } else {
        *val = INVALID;
    }
}

void init_host_devices(struct pci *pci)
{
    struct pci_device *dev = calloc(1, sizeof(struct pci_device));
    struct pci_host *host = calloc(1, sizeof(struct pci_host));
    pci_hdr0_mem_t *ph = &host->ph;

    dev->confspace_write = confspace_write;
    dev->confspace_read = confspace_read;
    dev->state = host;

    pci_hdr0_mem_initialize(ph, (mackerel_addr_t)host->pci_header);

    int r = pci_attach_device(pci, 0, 1, dev);
    assert(r == 0);
}

redpajama_set_name: RedPajamaGithub


text:
/**
 * Action type to signal that connection has disconnected.
 *
 * @type {string}
 */
export const CONNECTION_DISCONNECTED = 'CONNECTION_DISCONNECTED';

/**
 * Action type to signal that have successfully established a connection.
 *
 * @type {string}
 */
export const CONNECTION_ESTABLISHED = 'CONNECTION_ESTABLISHED';

/**
 * Action type to signal a connection failed.
 *
 * @type {string}
 */
export const CONNECTION_FAILED = 'CONNECTION_FAILED';

/**
 * Action to signal to change connection domain.
 *
 * {
 *     type: SET_DOMAIN,
 *     domain: string
 * }
 */
export const SET_DOMAIN = 'SET_DOMAIN';


text:
<?php

namespace Rocketeer\Services;

use Rocketeer\Dummies\DummyNotifier;
use Rocketeer\TestCases\RocketeerTestCase;

class TasksHandlerTest extends RocketeerTestCase
{
    public function testCanAddCommandsToArtisan()
    {
        $command = $this->tasks->add('Rocketeer\Tasks\Deploy');
        $this->assertInstanceOf('Rocketeer\Console\Commands\BaseTaskCommand', $command);
        $this->assertInstanceOf('Rocketeer\Tasks\Deploy', $command->getTask());
    }

    public function testCanGetTasksBeforeOrAfterAnotherTask()
    {
        $task   = $this->task('Deploy');
        $before = $this->tasks->getTasksListeners($task, 'before', true);

        $this->assertEquals(['before', 'foobar'], $before);
    }

    public function testCanAddTasksViaFacade()
    {
        $task   = $this->task('Deploy');
        $before = $this->tasks->getTasksListeners($task, 'before', true);

        $this->tasks->before('deploy', 'composer install');

        $newBefore = array_merge($before, ['composer install']);
        $this->assertEquals($newBefore, $this->tasks->getTasksListeners($task, 'before', true));
    }

    public function testCanAddMultipleTasksViaFacade()
    {
        $task  = $this->task('Deploy');
        $after = $this->tasks->getTasksListeners($task, 'after', true);
        $this->tasks->after('deploy', [
            'composer install',
            'bower install',
        ]);

        $newAfter = array_merge($after, ['composer install', 'bower install']);
        $this->assertEquals($newAfter, $this->tasks->getTasksListeners($task, 'after', true));
    }

    public function testCanRegisterCustomTask()
    {
        $this->swapConfig([
            'rocketeer::default' => 'production',
        ]);

        $this->tasks->task('foobar', function ($task) {
            $task->runForCurrentRelease('ls');
        });

        $this->assertInstanceOf('Rocketeer\Tasks\Closure', $this->builder->buildTask('foobar'));

        $this->queue->run('foobar');
        $this->assertHistory([['cd {server}/releases/{release}', 'ls']]);
    }

    public function testCanRegisterCustomTaskViaArray()
    {
        $this->swapConfig([
            'rocketeer::default' => 'production',
        ]);

        $this->tasks->task('foobar', ['ls', 'ls']);
        $this->assertInstanceOf('Rocketeer\Tasks\Closure', $this->builder->buildTask('foobar'));

        $this->queue->run('foobar');
        $this->assertHistory([['cd {server}/releases/{release}', 'ls', 'ls']]);
    }

    public function testCanAddSurroundTasksToNonExistingTasks()
    {
        $task = $this->task('Setup');
        $this->tasks->after('setup', 'composer install');

        $after = ['composer install'];
        $this->assertEquals($after, $this->tasks->getTasksListeners($task, 'after', true));
    }

    public function testCanAddSurroundTasksToMultipleTasks()
    {
        $this->tasks->after(['cleanup', 'setup'], 'composer install');

        $after = ['composer install'];
        $this->assertEquals($after, $this->tasks->getTasksListeners('setup', 'after', true));
        $this->assertEquals($after, $this->tasks->getTasksListeners('cleanup', 'after', true));
    }

    public function testCangetTasksListenersOrAfterAnotherTaskBySlug()
    {
        $after = $this->tasks->getTasksListeners('deploy', 'after', true);

        $this->assertEquals(['after', 'foobar'], $after);
    }

    public function testCanAddEventsWithPriority()
    {
        $this->tasks->before('deploy', 'second', -5);
        $this->tasks->before('deploy', 'first');

        $listeners = $this->tasks->getTasksListeners('deploy', 'before', true);
        $this->assertEquals(['before', 'foobar', 'first', 'second'], $listeners);
    }

    public function testCanExecuteContextualEvents()
    {
        $this->swapConfig([
            'rocketeer::stages.stages'            => ['hasEvent', 'noEvent'],
            'rocketeer::on.stages.hasEvent.hooks' => ['before' => ['check' => 'ls']],
        ]);

        $this->connections->setStage('hasEvent');
        $this->assertEquals(['ls'], $this->tasks->getTasksListeners('check', 'before', true));

        $this->connections->setStage('noEvent');
        $this->assertEquals([], $this->tasks->getTasksListeners('check', 'before', true));
    }

    public function testCanbuildTasksFromConfigHook()
    {
        $tasks = [
            'npm install',
            'bower install',
        ];

        $this->swapConfig([
            'rocketeer::hooks' => ['after' => ['deploy' => $tasks]],
        ]);

        $this->tasks->registerConfiguredEvents();
        $listeners = $this->tasks->getTasksListeners('deploy', 'after', true);

        $this->assertEquals($tasks, $listeners);
    }

    public function testCanHaveCustomConnectionHooks()
    {
        $tasks = [
            'npm install',
            'bower install',
        ];

        $this->swapConfig([
            'rocketeer::default'                      => 'production',
            'rocketeer::hooks'                        => [],
            'rocketeer::on.connections.staging.hooks' => ['after' => ['deploy' => $tasks]],
        ]);
        $this->tasks->registerConfiguredEvents();

        $this->connections->setConnection('production');
        $events = $this->tasks->getTasksListeners('deploy', 'after', true);
        $this->assertEmpty($events);

        $this->connections->setConnection('staging');
        $events = $this->tasks->getTasksListeners('deploy', 'after', true);

        $this->assertEquals($tasks, $events);
    }

    public function testPluginsArentDeregisteredWhenSwitchingConnection()
    {
        $this->swapConfig([
            'rocketeer::hooks' => ['before' => ['deploy' => 'ls']],
        ]);

        $this->tasks->plugin(new DummyNotifier($this->app));

        $listeners = $this->tasks->getTasksListeners('deploy', 'before', true);
        $this->assertEquals(['ls', 'notify'], $listeners);

        $this->connections->setConnection('production');

        $listeners = $this->tasks->getTasksListeners('deploy', 'before', true);
        $this->assertEquals(['ls', 'notify'], $listeners);
    }

    public function testDoesntRegisterPluginsTwice()
    {
        $this->swapConfig([
            'rocketeer::hooks' => [],
        ]);

        $this->tasks->plugin(new DummyNotifier($this->app));
        $this->tasks->plugin(new DummyNotifier($this->app));
        $this->tasks->plugin(new DummyNotifier($this->app));

        $listeners = $this->tasks->getTasksListeners('deploy', 'before', true);
        $this->assertEquals(['notify'], $listeners);
    }

    public function testCanBuildTasksFluently()
    {
        $this->tasks->task('phpunit')
                    ->does('foobar')
                    ->description('description');

        $task = $this->builder->buildTask('phpunit');

        $this->assertInstanceOf('Rocketeer\Tasks\Closure', $task);
        $this->assertEquals('description', $task->getDescription());
        $this->assertEquals('foobar', $task->getStringTask());
    }
}


text:
"""
Created on Thu Sep  6 20:19:34 2018

@author: chen jin

k-mean non-lib version:
    Guess some cluster centers
    Repeat until converged
        E-Step: assign points to the nearest cluster center
        M-Step: set the cluster centers to the mean

Input:
    example dataset by make_blobs of four clusters
Output:
    kmeans: fitted kmean model with cluter = 4
    y_kmeans: kmean prediection
"""
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()  # for plot styling
import numpy as np
from sklearn.metrics import pairwise_distances_argmin
from sklearn.datasets.samples_generator import make_blobs

def find_clusters(X, n_clusters, rseed=2):
    # 1. Randomly choose clusters
    rng = np.random.RandomState(rseed)
    i = rng.permutation(X.shape[0])[:n_clusters]
    centers = X[i]

    while True:
        # 2a. Assign labels based on closest center
        labels = pairwise_distances_argmin(X, centers)

        # 2b. Find new centers from means of points
        new_centers = np.array([X[labels == i].mean(0)
                                for i in range(n_clusters)])

        # 2c. Check for convergence
        if np.all(centers == new_centers):
            break
        centers = new_centers

    return centers, labels

# 1. generate a two-dimensional dataset containing four distinct blobs
X, y_true = make_blobs(n_samples=300, centers=4,
                       cluster_std=0.60, random_state=0)
# plt.scatter(X[:, 0], X[:, 1], s=50);

centers, labels = find_clusters(X, 4)
plt.scatter(X[:, 0], X[:, 1], c=labels,
            s=50, cmap='viridis');


text:
include_recipe 'wso2::common'

wso2_component 'as' do
  tarball_url node['wso2']['as']['tarball_url']
  install_dir node['wso2']['as']['install_dir']
  init_script node['wso2']['init_script']
end


text:
import socket
import struct
import unittest as ut

import numpy as np

import libx6

class TestSettersGetters(ut.TestCase):
    """
    Test reading and writing wishbone registers.
    """

    @classmethod
    def setUpClass(cls):
        cls.x6 = libx6.X6()
        cls.x6.connect(0)

    @classmethod
    def tearDownClass(cls):
        cls.x6.disconnect()

    def test_wishbone_readwrite(self):
        """ check that we can write and read the wishbone bus """
        val = np.random.randint(2**32-1, dtype=np.uint32)
        self.x6.write_register(libx6.QDSP_WB_OFFSET[0], 2, val)
        check_val = self.x6.read_register(libx6.QDSP_WB_OFFSET[0], 2)
        self.assertEqual(val, check_val, "wishbone register read did not match value written")

    def test_temperature(self):
        """test that we can read the temperature and it's sane"""
        temp = self.x6.get_logic_temperature()
        self.assertTrue( (temp > 20) and (temp < 80), "FPGA temperature seems fishy")

    def test_record_length_validators(self):
        """ test that exceptions are thrown for invalid record lengths"""
        # minimum of 128
        self.x6.record_length = 96
        self.assertRaisesRegex(Exception, "LIBX6 Error: -8", self.x6.set_averager_settings)

        # maximum of 16384
        self.x6.record_length = 16448
        self.assertRaisesRegex(Exception, "LIBX6 Error: -8", self.x6.set_averager_settings)

        # record length should be a multiple of 128
        self.x6.record_length = 320
        self.assertRaisesRegex(Exception, "LIBX6 Error: -8", self.x6.set_averager_settings)

    def test_nco_frequency(self):
        """ test setter/getter for NCO frequency """
        test_freq = np.random.randint(125e6)
        self.x6.set_nco_frequency(1, 1, test_freq)
        check_freq = self.x6.get_nco_frequency(1, 1)
        # don't expect more than 24 bits precision on a quarter sampling rate
        self.assertAlmostEqual(test_freq, check_freq, delta=1e9 / 4 / 2**24)

def expected_raw_wfs():
    """ Returns the raw test pattern generated by the gateware. """
    expected = np.zeros((1280, 64), dtype=np.float64)
    for ct in range(64):
        baseNCO = 1.0000020265579224e6; # from 24bit precision
        pulse = (1 - 1/128) * (1 - 1/2048) * np.cos(2*np.pi*(ct % 64)*baseNCO*1e-9*(np.arange(8,4108)))
        expected[23:23+pulse.size//4, ct] = np.mean(pulse.reshape((4, pulse.size//4), order="F"), axis=0)
        # catch alignment marker
        if ct % 64 == 0:
            expected[3:7,ct] = 1 - 1/2048
    return expected

def enable_test_mode(x6, interval):
    """ write the test register setting the enable bit and interval """
    # internal trigger generator runs of 250 MHz clock
    x6.write_register(libx6.QDSP_WB_OFFSET[0], 1, (1 << 16) + (int(interval * 250e6) & 0xffff))
    x6.write_register(libx6.QDSP_WB_OFFSET[1], 1, (1 << 16) + (int(interval * 250e6) & 0xffff))

class TestStreams(ut.TestCase):
    """
    Test reading data streams
    """

    def setUp(self):
        self.x6 = libx6.X6()
        self.addCleanup(self.x6.disconnect)
        self.x6.connect(0)

    def test_raw_streams(self):
        """ Check the pattern on the raw streams """

        libx6.set_logging_level(8)

        # enable the two raw streams
        self.x6.enable_stream(1, 0, 0)
        self.x6.enable_stream(2, 0, 0)
        streams = [(1,0,0), (2,0,0)]

        self.x6.record_length = 5120
        self.x6.nbr_segments = 64
        self.x6.nbr_waveforms = 1
        self.x6.nbr_round_robins = 1

        self.x6.acquire_mode = "digitizer"

        sockets = {}

        for s in streams:
            sockets[s] = socket.socketpair()
            self.x6.register_socket(*s, sockets[s][1])

        self.x6.acquire()

        enable_test_mode(self.x6, 100e-6)

        data = {}
        idx = {}
        for s in streams:
            idx[s] = 0
            data[s] = np.empty(self.x6.record_length//4 * self.x6.nbr_segments, dtype=np.float64)

        while True:
            # TODO: timeout
            all_done = all(idx[s] == data[s].size for s in streams)
            if (not self.x6.get_is_running()) or all_done:
                break

            for s in streams:
                if idx[s] < data[s].size:
                    msg = sockets[s][0].recv(8)
                    msg_size = struct.unpack('n', msg)[0]
                    buf = sockets[s][0].recv(msg_size, socket.MSG_WAITALL)
                    num_points = msg_size // np.dtype(np.float64).itemsize
                    data[s][idx[s]:idx[s]+num_points] = np.frombuffer(buf, dtype=np.float64)
                    idx[s] += num_points

        for sp in sockets.values():
            sp[0].close()
            sp[1].close()

        for s in streams:
            data[s] = data[s].reshape(self.x6.record_length //4, self.x6.nbr_segments, order="F")

        expected = expected_raw_wfs()

        for s in streams:
            np.testing.assert_allclose(data[s], expected, atol=2/2048, err_msg="Raw stream {} failed to match expected".format(s))

if __name__ == '__main__':
    ut.main()


text: __author__ = 'iresprite'


text:
require 'sequel'

module Logformat
  Sequel.default_timezone = :utc
  DB = Sequel.connect(ENV['DB'] || 'sqlite://local.db', :max_connections => 100)

  unless DB.table_exists?(:messages)
    Sequel.extension :migration
    Sequel::Migrator.run(DB, File.join(File.dirname(__FILE__),'..','migrations'))
  end

  IRC_HOST = ENV['SERVER'] || 'irc.freenode.net'
  IRC_NICK = ENV['NICK'] || 'logformat'

  WEB_PORT = ENV['PORT'] || 8080
  WEB_BIND = ENV['BIND'] || '127.0.0.1'
end


text:
import {RuleFailure, TestUtils} from "../lint";

describe("<curly>", () => {
    const fileName = "rules/curly.test.ts";
    const CurlyRule = TestUtils.getRule("curly");
    let actualFailures: RuleFailure[];

    before(() => {
        actualFailures = TestUtils.applyRuleOnFile(fileName, CurlyRule);
    });

    it("ensures if statements are always braced", () => {
        const failureString = CurlyRule.IF_FAILURE_STRING;
        const expectedFailure = TestUtils.createFailure(fileName, [10, 5], [11, 26], failureString);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure);
    });

    it("ensures for statements are always braced", () => {
        const failureString = CurlyRule.FOR_FAILURE_STRING;
        const expectedFailure1 = TestUtils.createFailure(fileName, [22, 3], [23, 24], failureString);
        const expectedFailure2 = TestUtils.createFailure(fileName, [25, 1], [26, 22], failureString);
        const expectedFailure3 = TestUtils.createFailure(fileName, [67, 1], [68, 20], failureString);

        TestUtils.assertContainsFailure(actualFailures, expectedFailure1);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure2);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure3);
    });

    it("ensures while statements are always braced", () => {
        const failureString = CurlyRule.WHILE_FAILURE_STRING;
        const expectedFailure1 = TestUtils.createFailure(fileName, [37, 1], [38, 22], failureString);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure1);
    });

    it("ensures do statements are always braced", () => {
        const failureString = CurlyRule.DO_FAILURE_STRING;
        const expectedFailure1 = TestUtils.createFailure(fileName, [50, 1], [52, 16], failureString);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure1);
    });

    it("ensures else statements are always braced", () => {
        const failureString = CurlyRule.ELSE_FAILURE_STRING;
        const expectedFailure = TestUtils.createFailure(fileName, [56, 3], [56, 25], failureString);
        TestUtils.assertContainsFailure(actualFailures, expectedFailure);
    });

    it("does not have false positives", () => {
        assert.lengthOf(actualFailures, 7);
    });
});


text:
MARIONETTE_TIMEOUT = 60000;

const KEY = "ril.radio.preferredNetworkType";

let gSettingsEnabled = SpecialPowers.getBoolPref("dom.mozSettings.enabled");
if (!gSettingsEnabled) {
  SpecialPowers.setBoolPref("dom.mozSettings.enabled", true);
}
SpecialPowers.addPermission("mobileconnection", true, document);
SpecialPowers.addPermission("settings", true, document);

let settings = window.navigator.mozSettings;

function test_revert_previous_setting_on_invalid_value() {
  log("Testing reverting to previous setting on invalid value received");

  let getLock = settings.createLock();
  let getReq = getLock.get(KEY);
  getReq.addEventListener("success", function onGetSuccess() {
    let originalValue = getReq.result[KEY] || "wcdma/gsm";

    let setDone = false;
    settings.addObserver(KEY, function observer(setting) {
      // Mark if the invalid value has been set in db and wait.
      if (setting.settingValue == obj[KEY]) {
        setDone = true;
        return;
      }

      // Skip any change before marking but keep it as original value.
      if (!setDone) {
        originalValue = setting.settingValue;
        return;
      }

      settings.removeObserver(KEY, observer);
      is(setting.settingValue, originalValue, "Settings reverted");
      window.setTimeout(cleanUp, 0);
    });

    let obj = {};
    obj[KEY] = "AnInvalidValue";
    let setLock = settings.createLock();
    setLock.set(obj);
    setLock.addEventListener("error", function onSetError() {
      ok(false, "cannot set '" + KEY + "'");
    });
  });
  getReq.addEventListener("error", function onGetError() {
    ok(false, "cannot get default value of '" + KEY + "'");
  });
}

function cleanUp() {
  SpecialPowers.removePermission("mobileconnection", document);
  SpecialPowers.removePermission("settings", document);
  SpecialPowers.clearUserPref("dom.mozSettings.enabled");

  finish();
}

waitFor(test_revert_previous_setting_on_invalid_value, function () {
  return navigator.mozMobileConnection.voice.connected;
});


text:
if(a instanceof String){
  final String result = ((String) a).substring(1);
}


text:
require "generators/generators_test_helper"
require "rails/generators/generated_attribute"

class GeneratedAttributeTest < Rails::Generators::TestCase
  include GeneratorsTestHelper

  def test_field_type_returns_number_field
    assert_field_type :integer, :number_field
  end

  def test_field_type_returns_text_field
    %w(float decimal string).each do |attribute_type|
      assert_field_type attribute_type, :text_field
    end
  end

  def test_field_type_returns_datetime_select
    %w(datetime timestamp).each do |attribute_type|
      assert_field_type attribute_type, :datetime_select
    end
  end

  def test_field_type_returns_time_select
    assert_field_type :time, :time_select
  end

  def test_field_type_returns_date_select
    assert_field_type :date, :date_select
  end

  def test_field_type_returns_text_area
    assert_field_type :text, :text_area
  end

  def test_field_type_returns_check_box
    assert_field_type :boolean, :check_box
  end

  def test_field_type_with_unknown_type_returns_text_field
    %w(foo bar baz).each do |attribute_type|
      assert_field_type attribute_type, :text_field
    end
  end

  def test_default_value_is_integer
    assert_field_default_value :integer, 1
  end

  def test_default_value_is_float
    assert_field_default_value :float, 1.5
  end

  def test_default_value_is_decimal
    assert_field_default_value :decimal, "9.99"
  end

  def test_default_value_is_datetime
    %w(datetime timestamp time).each do |attribute_type|
      assert_field_default_value attribute_type, Time.now.to_s(:db)
    end
  end

  def test_default_value_is_date
    assert_field_default_value :date, Date.today.to_s(:db)
  end

  def test_default_value_is_string
    assert_field_default_value :string, "MyString"
  end

  def test_default_value_for_type
    att = Rails::Generators::GeneratedAttribute.parse("type:string")
    assert_equal("", att.default)
  end

  def test_default_value_is_text
    assert_field_default_value :text, "MyText"
  end

  def test_default_value_is_boolean
    assert_field_default_value :boolean, false
  end

  def test_default_value_is_nil
    %w(references belongs_to).each do |attribute_type|
      assert_field_default_value attribute_type, nil
    end
  end

  def test_default_value_is_empty_string
    %w(foo bar baz).each do |attribute_type|
      assert_field_default_value attribute_type, ""
    end
  end

  def test_human_name
    assert_equal(
      "Full name",
      create_generated_attribute(:string, "full_name").human_name
    )
  end

  def test_reference_is_true
    %w(references belongs_to).each do |attribute_type|
      assert create_generated_attribute(attribute_type).reference?
    end
  end

  def test_reference_is_false
    %w(foo bar baz).each do |attribute_type|
      assert !create_generated_attribute(attribute_type).reference?
    end
  end

  def test_polymorphic_reference_is_true
    %w(references belongs_to).each do |attribute_type|
      assert create_generated_attribute("#{attribute_type}{polymorphic}").polymorphic?
    end
  end

  def test_polymorphic_reference_is_false
    %w(foo bar baz).each do |attribute_type|
      assert !create_generated_attribute("#{attribute_type}{polymorphic}").polymorphic?
    end
  end

  def test_blank_type_defaults_to_string_raises_exception
    assert_equal :string, create_generated_attribute(nil, "title").type
    assert_equal :string, create_generated_attribute("", "title").type
  end

  def test_handles_index_names_for_references
    assert_equal "post", create_generated_attribute("string", "post").index_name
    assert_equal "post_id", create_generated_attribute("references", "post").index_name
    assert_equal "post_id", create_generated_attribute("belongs_to", "post").index_name
    assert_equal ["post_id", "post_type"], create_generated_attribute("references{polymorphic}", "post").index_name
  end

  def test_handles_column_names_for_references
    assert_equal "post", create_generated_attribute("string", "post").column_name
    assert_equal "post_id", create_generated_attribute("references", "post").column_name
    assert_equal "post_id", create_generated_attribute("belongs_to", "post").column_name
  end

  def test_parse_required_attribute_with_index
    att = Rails::Generators::GeneratedAttribute.parse("supplier:references{required}:index")
    assert_equal "supplier", att.name
    assert_equal :references, att.type
    assert att.has_index?
    assert att.required?
  end
end


text:
#pragma once

#include <cstddef>
#include <exception>
#include <string>

namespace fly {

class Json;

/**
 * Generic exception to be raised if an error was encountered creating, accessing, or modifying a
 * Json instance.
 *
 * @author Timothy Flynn (trflynn89@pm.me)
 * @version September 24, 2017
 */
class JsonException : public std::exception
{
public:
    /**
     * Constructor.
     *
     * @param message Message indicating what error was encountered.
     */
    explicit JsonException(std::string &&message) noexcept;

    /**
     * Constructor.
     *
     * @param json The Json instance for which the error was encountered.
     * @param message Message indicating what error was encountered.
     */
    JsonException(Json const &json, std::string &&message) noexcept;

    /**
     * @return C-string representing this exception.
     */
    virtual char const *what() const noexcept override;

protected:
    /**
     * Constructor for subclasses.
     *
     * @param class_name Name of the subclass.
     * @param message Message indicating what error was encountered.
     */
    JsonException(char const *class_name, std::string &&message) noexcept;

private:
    std::string const m_message;
};

/**
 * Exception to be raised for generic JsonIterator errors.
 */
class JsonIteratorException : public JsonException
{
public:
    /**
     * Constructor.
     *
     * @param json The Json instance for which the error was encountered.
     * @param message Message indicating what error was encountered.
     */
    JsonIteratorException(Json const &json, std::string &&message) noexcept;
};

/**
 * Exception to be raised for illegally comparing iterators of two different Json instances.
 */
class BadJsonComparisonException : public JsonException
{
public:
    /**
     * Constructor.
     *
     * @param json1 The first Json instance in the comparison.
     * @param json2 The second Json instance in the comparison.
     */
    BadJsonComparisonException(Json const &json1, Json const &json2) noexcept;
};

/**
 * Exception to be raised trying to dereference an empty or past-the-end JsonIterator instance.
 */
class NullJsonException : public JsonException
{
public:
    /**
     * Constructor.
     */
    NullJsonException() noexcept;

    /**
     * Constructor.
     *
     * @param json The Json instance for which the error was encountered.
     */
    explicit NullJsonException(Json const &json) noexcept;
};

/**
 * Exception to be raised trying to create an iterator that escapes the range [begin, end] of a Json
 * instance.
 */
class OutOfRangeJsonException : public JsonException
{
public:
    /**
     * Constructor.
     *
     * @param json The Json instance for which the error was encountered.
     * @param offset The iterator offset attempted to be accessed.
     */
    OutOfRangeJsonException(Json const &json, std::ptrdiff_t offset) noexcept;

    /**
     * @return The iterator offset attempted to be accessed.
     */
    std::ptrdiff_t offset() const;

private:
    std::ptrdiff_t m_offset;
};

} // namespace fly


text:
#ifndef CAI_NMG_EX_H
#define CAI_NMG_EX_H

#include "Recast.h"

#if _MSC_VER    // TRUE for Microsoft compiler.
#define EXPORT_API __declspec(dllexport) // Required for VC++
#else
#define EXPORT_API // Otherwise don't define.
#endif

static const float NMG_EPSILON = 0.00001f;
static const float NMG_TOLERANCE = 0.0001f;

// The memory was allocated externally and cannot
// be freed by this library.
static const unsigned char NMG_ALLOC_TYPE_EXTERN = 0;

// The memory was allocated locally and can be freed locally.
static const unsigned char NMG_ALLOC_TYPE_LOCAL = 1;

// The memory was allocated locally, but it is managed by an
// owner object.  It should only be freed by that object.
static const unsigned char NMG_ALLOC_TYPE_MANAGED_LOCAL = 2;

class nmgBuildContext
    : public rcContext
{
public:
    static const int MAX_MESSAGES = 1024;
    static const int MESSAGE_POOL_SIZE = 65536;

    nmgBuildContext();
    virtual ~nmgBuildContext();

    int getMessageCount() const;
    const char* getMessage(const int i) const;

    int getMessagePoolLength() const;
    const char* getMessagePool() const;

    bool getLogEnabled() const { return m_logEnabled; }

protected:
    virtual void doResetLog();
    virtual void doLog(const rcLogCategory category
        , const char* msg
        , const int len);

private:
    const char* mMessages[MAX_MESSAGES];
    int mMessageCount;

    char mTextPool[MESSAGE_POOL_SIZE];
    int mTextPoolSize;
};

template<class T> inline bool nmgSloppyEquals(T a, T b)
{
    return !(b < a - NMG_TOLERANCE || b > a + NMG_TOLERANCE);
};

#endif


text:
var Jabaku = (function(module) {
	'use strict';

	function DepthPeelingRenderer(engine, backgroundColor) {
		this._engine = engine;
		this._backgroundColor = backgroundColor;

		this.debugRender = false;

		var size = engine.getDrawingBufferSize();
		this._rt1 = engine.createRenderTexture('depthPeelingRT1', size);
		this._rt2 = engine.createRenderTexture('depthPeelingRT2', size);
		this._rt3 = engine.createRenderTexture('depthPeelingRT3', size);
		this._rt4 = engine.createRenderTexture('depthPeelingRT4', size);

		this._dt1 = engine.createDepthTexture('depthPeelingDT1', size);
		this._dt2 = engine.createDepthTexture('depthPeelingDT2', size);
		this._dt3 = engine.createDepthTexture('depthPeelingDT3', size);

		this._fb1 = engine.createFrameBuffer('depthPeelingFB1', this._rt1, this._dt1);
		this._fb2 = engine.createFrameBuffer('depthPeelingFB2', this._rt2, this._dt2);
		this._fb3 = engine.createFrameBuffer('depthPeelingFB3', this._rt3, this._dt3);
		this._fb4 = engine.createFrameBuffer('depthPeelingFB4', this._rt4, this._dt1);

		this._finalCombineProgram = Engine3D.createProgram('dp_final_combine',
			FileUtils.loadFile('jabaku/shaders/pass_through.vshader'),
			FileUtils.loadFile('jabaku/shaders/dp_final_combine.fshader'));
	}
	DepthPeelingRenderer.extends(Object, {
		_prepareFrameBuffer: function(frameBuffer) {
			var engine = this._engine;
			if (frameBuffer) {
				engine.setFrameBuffer(frameBuffer);
			} else {
				engine.setDefaultFrameBuffer();
			}
			engine.setClearColor(this._backgroundColor);
			engine.clear();
		},
		_renderObjects: function(objects, params, blendMode) {
			var engine = this._engine;

			for (var i = 0; i < objects.length; ++i) {
				var object = objects[i];
				object.prepare(engine);
				object.setParams(params);

				var material = object.material;
				engine.setBlendMode(blendMode);
				engine.setProgram(material.programs.depthPeeling, params);
				object.render(engine);
			}
		},
		_clearFB: function(frameBuffer, depthValue) {
			var engine = this._engine;
			engine.setFrameBuffer(frameBuffer);
			engine.setClearDepth(depthValue);
			engine.clear();
		},
		render: function(objects, camera, lightSettings, frameBuffer, viewport) {
			this._prepareFrameBuffer(frameBuffer);

			var engine = this._engine;
			var utils = Jabaku.RendererUtils;
			var params = {};
			utils.setViewport(engine, viewport, params);
			utils.setCameraParameters(camera, params);
			utils.setForwardLightParameters(lightSettings, params);

			engine.setBlendMode(BlendMode.NONE);
			this._clearFB('depthPeelingFB1', 1.0);
			this._clearFB('depthPeelingFB2', 0.0);

			engine.setFrameBuffer('depthPeelingFB1');
			params.uDepthTexture = {texture: this._dt2, sampler: 1};
			this._renderObjects(objects, params, BlendMode.SOLID);

			this._clearFB('depthPeelingFB2', 1.0);
			engine.setFrameBuffer('depthPeelingFB2');
			params.uDepthTexture = {texture: this._dt1, sampler: 1};
			this._renderObjects(objects, params, BlendMode.SOLID);

			this._clearFB('depthPeelingFB3', 1.0);
			engine.setFrameBuffer('depthPeelingFB3');
			params.uDepthTexture = {texture: this._dt2, sampler: 1};
			this._renderObjects(objects, params, BlendMode.SOLID);

			this._clearFB('depthPeelingFB4', 1.0);
			engine.setFrameBuffer('depthPeelingFB4');
			params.uDepthTexture = {texture: this._dt3, sampler: 1};
			this._renderObjects(objects, params, BlendMode.SOLID);

			if (frameBuffer) {
				engine.setFrameBuffer(frameBuffer);
			} else {
				engine.setDefaultFrameBuffer();
			}
			engine.setBlendMode(BlendMode.NONE);
			engine.setProgram(this._finalCombineProgram, {
				uTexture1: {texture: this._rt1, sampler: 0},
				uTexture2: {texture: this._rt2, sampler: 1},
				uTexture3: {texture: this._rt3, sampler: 2},
				uTexture4: {texture: this._rt4, sampler: 3}
			});
			utils.setViewport(engine, viewport, params);
			engine.renderScreenQuad();

			if (this.debugRender) {
				engine.renderDepthTexture(this._dt1, 0, 0, 200, 200);
				engine.renderDepthTexture(this._dt2, 200, 0, 200, 200);
				engine.renderDepthTexture(this._dt3, 400, 0, 200, 200);

				engine.renderDebugQuad(this._rt1, 0, 568, 200, 200);
				engine.renderDebugQuad(this._rt2, 200, 568, 200, 200);
				engine.renderDebugQuad(this._rt3, 400, 568, 200, 200);
				engine.renderDebugQuad(this._rt4, 600, 568, 200, 200);
			}
		}
	});

	module.DepthPeelingRenderer = DepthPeelingRenderer;
	return module;
})(Jabaku || {});


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Gpio;
using Windows.Foundation;

namespace QiMata.DemoDevice.Drivers
{
    class ButtonDriver
    {
        private GpioPin _pin;

        public ButtonDriver(int pinNumber)
        {
            _pin = GpioController.GetDefault().OpenPin(pinNumber, GpioSharingMode.Exclusive);
            _pin.SetDriveMode(_pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                ? GpioPinDriveMode.InputPullUp
                : GpioPinDriveMode.Input);
            _pin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            var observerable = WindowsObservable.FromEventPattern<GpioPin, GpioPinValueChangedEventArgs>(
                x => _pin.ValueChanged += x,
                x => _pin.ValueChanged -= x);
        }

        public IObservable<EventPattern<GpioPin, GpioPinValueChangedEventArgs>> ButtonPressedObservable => WindowsObservable.FromEventPattern<GpioPin, GpioPinValueChangedEventArgs>(
            x => _pin.ValueChanged += x,
            x => _pin.ValueChanged -= x)
            .Throttle(TimeSpan.FromSeconds(1));
    }
}


text:
class Foo {
  gen() {
    return babelHelpers.skipFirstGeneratorNext(function* () {
      let _functionSent = yield;

      return _functionSent;
    })();
  }

}


text:
'use strict';

var Broker = require('cf-services-connector');
var Config = require('./config/echo-service');

var broker = new Broker(Config);

broker.start();

broker.on('provision', function (req, next) {
    var reply = { dashboard_url: req.params.service_id };
    next(reply);
});

broker.on('unprovision', function (req, next) {
    next();
});

broker.on('bind', function (req, next) {
    var reply = {};

    reply.credentials = {
        echo: 'echo',
        anotherEcho: 'anotherEcho',
    };
    next(reply);
});

broker.on('unbind', function (req, next) {
    next();
});

// broker.stop();


text:
namespace jxl {

// Should still be called if `icc.empty()` - if so, writes only 1 bit.
Status WriteICC(const PaddedBytes& icc, BitWriter* JXL_RESTRICT writer,
                size_t layer, AuxOut* JXL_RESTRICT aux_out);

// Exposed only for testing
Status PredictICC(const uint8_t* icc, size_t size, PaddedBytes* result);

}  // namespace jxl

#endif  // LIB_JXL_ENC_ICC_CODEC_H_


text:
#pragma once

#include <random>    // std::mt19937_64
#include <armadillo> // arma::sed

namespace pass
{
class seed
{
public:
  /**
   * The random number generator should act as a singleton, no need for default constructors.
   */
  seed() = delete;
  seed(const seed &) = delete;
  seed &operator=(const seed &) = delete;

  /**
   * The std::mersenne_twister_engine requires an l-value (a reference in this case) instead of an r-value.
   * Otherwise, calls like std::uniform_real_distribution<double>(0, 1)(seed::get_generator()) won't compile.
   */
  static std::mt19937_64 &get_generator();

  /**
   * Seeding C++'s and Armadillo's generator.
   */
  static void set_seed(
      const arma::arma_rng::seed_type seed);

  /**
   * Initialise Armadillo's generator with any random seed.
   * This seed will be overwritten later on, no need to store it.
   *
   * For programs using MPI, each node needs to seeded differently in order to avoid a degeneration
   * of the random number generator, due to synchronisation.
   * Basically, we generated as much random numbers as there are nodes and seed the i-th node
   * by the i-th generated random number.
   *
   * Without MPI, using the first random number generated by Armadillo's generator as seed is sufficient.
   */
  static void set_random_seed();

  /**
   * Gets the seed if you want to reproduce the experiment
   */
  static arma::arma_rng::seed_type get_seed();

protected:
  static arma::arma_rng::seed_type seed_;
  static std::mt19937_64 generator_;
};
} // namespace pass


text:
'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports["default"] = undefined;

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _button = require('../button');

var _button2 = _interopRequireDefault(_button);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function noop() {}

var Result = function (_React$Component) {
    (0, _inherits3["default"])(Result, _React$Component);

    function Result() {
        (0, _classCallCheck3["default"])(this, Result);
        return (0, _possibleConstructorReturn3["default"])(this, _React$Component.apply(this, arguments));
    }

    Result.prototype.render = function render() {
        var _classNames;

        var _props = this.props,
            prefixCls = _props.prefixCls,
            imgUrl = _props.imgUrl,
            title = _props.title,
            message = _props.message,
            buttonText = _props.buttonText,
            buttonClick = _props.buttonClick,
            buttonType = _props.buttonType,
            className = _props.className;

        var wrapCls = (0, _classnames2["default"])((_classNames = {}, (0, _defineProperty3["default"])(_classNames, '' + prefixCls, true), (0, _defineProperty3["default"])(_classNames, className, className), _classNames));
        return _react2["default"].createElement("div", { className: wrapCls }, _react2["default"].createElement("div", { className: prefixCls + '-pic', style: { backgroundImage: 'url(' + imgUrl + ')' } }), title !== '' ? _react2["default"].createElement("div", { className: prefixCls + '-title' }, title) : null, message !== '' ? _react2["default"].createElement("div", { className: prefixCls + '-message' }, message) : null, buttonText !== '' ? _react2["default"].createElement("div", { className: prefixCls + '-button' }, _react2["default"].createElement(_button2["default"], { type: buttonType, onClick: buttonClick }, buttonText)) : null);
    };

    return Result;
}(_react2["default"].Component);

exports["default"] = Result;

Result.defaultProps = {
    prefixCls: 'am-result',
    imgUrl: '',
    title: '',
    message: '',
    buttonText: '',
    buttonType: '',
    buttonClick: noop
};
module.exports = exports['default'];


text:
module PoiseHoist
  # Version for the poise-hoist gem.
  VERSION = '1.2.2.pre'
end


text:
module RomanNumerals where
  import Data.List

  type Numeral = String
  type MixedNumber = (String, Int)

  data RomanDigit = RomanDigit String Int

  digits = reverse [
      RomanDigit "I" 1,
      RomanDigit "IV" 4,
      RomanDigit "V" 5,
      RomanDigit "IX" 9,
      RomanDigit "X" 10,
      RomanDigit "XL" 40,
      RomanDigit "L" 50,
      RomanDigit "XM" 90,
      RomanDigit "M" 100
    ]

  convert :: Int -> Numeral
  convert n = concat $ unfoldr nextRomanNumber n

  nextRomanNumber :: Int -> Maybe MixedNumber
  nextRomanNumber n = fmap next $ find isUsableDigit digits
    where
      isUsableDigit (RomanDigit _ number) = number <= n
      next (RomanDigit numeral number) = (numeral, n - number)


text:
"""
XX. Model inheritance

Model inheritance exists in two varieties:
    - abstract base classes which are a way of specifying common
      information inherited by the subclasses. They don't exist as a separate
      model.
    - non-abstract base classes (the default), which are models in their own
      right with their own database tables and everything. Their subclasses
      have references back to them, created automatically.

Both styles are demonstrated here.
"""

from django.db import models

#
# Abstract base classes
#

class CommonInfo(models.Model):
    name = models.CharField(max_length=50)
    age = models.PositiveIntegerField()

    class Meta:
        abstract = True
        ordering = ['name']

    def __unicode__(self):
        return u'%s %s' % (self.__class__.__name__, self.name)

class Worker(CommonInfo):
    job = models.CharField(max_length=50)

class Student(CommonInfo):
    school_class = models.CharField(max_length=10)

    class Meta:
        pass

class StudentWorker(Student, Worker):
    pass

#
# Abstract base classes with related models
#

class Post(models.Model):
    title = models.CharField(max_length=50)

class Attachment(models.Model):
    post = models.ForeignKey(Post, related_name='attached_%(class)s_set')
    content = models.TextField()

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.content

class Comment(Attachment):
    is_spam = models.BooleanField()

class Link(Attachment):
    url = models.URLField()

#
# Multi-table inheritance
#

class Chef(models.Model):
    name = models.CharField(max_length=50)

    def __unicode__(self):
        return u"%s the chef" % self.name

class Place(models.Model):
    name = models.CharField(max_length=50)
    address = models.CharField(max_length=80)

    def __unicode__(self):
        return u"%s the place" % self.name

class Rating(models.Model):
    rating = models.IntegerField(null=True, blank=True)

    class Meta:
        abstract = True
        ordering = ['-rating']

class Restaurant(Place, Rating):
    serves_hot_dogs = models.BooleanField()
    serves_pizza = models.BooleanField()
    chef = models.ForeignKey(Chef, null=True, blank=True)

    class Meta(Rating.Meta):
        db_table = 'my_restaurant'

    def __unicode__(self):
        return u"%s the restaurant" % self.name

class ItalianRestaurant(Restaurant):
    serves_gnocchi = models.BooleanField()

    def __unicode__(self):
        return u"%s the italian restaurant" % self.name

class Supplier(Place):
    customers = models.ManyToManyField(Restaurant, related_name='provider')

    def __unicode__(self):
        return u"%s the supplier" % self.name

class ParkingLot(Place):
    # An explicit link to the parent (we can control the attribute name).
    parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
    main_site = models.ForeignKey(Place, related_name='lot')

    def __unicode__(self):
        return u"%s the parking lot" % self.name

#
# Abstract base classes with related models where the sub-class has the
# same name in a different app and inherits from the same abstract base
# class.
# NOTE: The actual API tests for the following classes are in
#       model_inheritance_same_model_name/models.py - They are defined
#       here in order to have the name conflict between apps
#

class Title(models.Model):
    title = models.CharField(max_length=50)

class NamedURL(models.Model):
    title = models.ForeignKey(Title, related_name='attached_%(app_label)s_%(class)s_set')
    url = models.URLField()

    class Meta:
        abstract = True

class Copy(NamedURL):
    content = models.TextField()

    def __unicode__(self):
        return self.content

class Mixin(object):
    def __init__(self):
        self.other_attr = 1
        super(Mixin, self).__init__()

class MixinModel(models.Model, Mixin):
    pass


text:
<compoundRegex title="snp">
    <regex weight="1.0" fields="snp">(SNPs?)</regex>
</compoundRegex>


text:
var Script = function () {

    // begin first table
    $('#sample_1').dataTable({
        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page",
            "oPaginate": {
                "sPrevious": "Prev",
                "sNext": "Next"
            }
        },
        "aoColumnDefs": [{
            'bSortable': false,
            'aTargets': [0]
        }]
    });

    jQuery('#sample_1 .group-checkable').change(function () {
        var set = jQuery(this).attr("data-set");
        var checked = jQuery(this).is(":checked");
        jQuery(set).each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
        jQuery.uniform.update(set);
    });

    jQuery('#sample_1_wrapper .dataTables_filter input').addClass("input-medium"); // modify table search input
    jQuery('#sample_1_wrapper .dataTables_length select').addClass("input-mini"); // modify table per page dropdown

    // begin second table
    $('#sample_2').dataTable({
        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ per page",
            "oPaginate": {
                "sPrevious": "Prev",
                "sNext": "Next"
            }
        },
        "aoColumnDefs": [{
            'bSortable': false,
            'aTargets': [0]
        }]
    });

    jQuery('#sample_2 .group-checkable').change(function () {
        var set = jQuery(this).attr("data-set");
        var checked = jQuery(this).is(":checked");
        jQuery(set).each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
        jQuery.uniform.update(set);
    });

    jQuery('#sample_2_wrapper .dataTables_filter input').addClass("input-small"); // modify table search input
    jQuery('#sample_2_wrapper .dataTables_length select').addClass("input-mini"); // modify table per page dropdown

    // begin: third table
    $('#sample_3').dataTable({
        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ per page",
            "oPaginate": {
                "sPrevious": "Prev",
                "sNext": "Next"
            }
        },
        "aoColumnDefs": [{
            'bSortable': false,
            'aTargets': [0]
        }]
    });

    jQuery('#sample_3 .group-checkable').change(function () {
        var set = jQuery(this).attr("data-set");
        var checked = jQuery(this).is(":checked");
        jQuery(set).each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
        jQuery.uniform.update(set);
    });

    jQuery('#sample_3_wrapper .dataTables_filter input').addClass("input-small"); // modify table search input
    jQuery('#sample_3_wrapper .dataTables_length select').addClass("input-mini"); // modify table per page dropdown

}();


text:
http://nodejs.org/api/readline.html
https://docs.nodejitsu.com/articles/command-line/how-to-prompt-for-command-line-input


text:
class DirectoryGroups < ActiveRecord::Migration
  def change
    add_column :droom_groups, :directory, :boolean
    add_column :droom_events, :confidential, :boolean
    add_index :droom_groups, :directory
    add_index :droom_events, :confidential
  end
end


text:
/**
 * @file export.c
 * @author Alex Merritt, merritt.alex@gatech.edu
 * @date 2011-11-22
 * @brief Implementation separated from assembly.c to support exporting and
 * importing of assembly data across process address spaces. Used to restore
 * state into the assembly module required of of a multi-process runtime. It's
 * separate because a) I don't want to clutter assembly.c with all this, b) it's
 * a workaround for something I hadn't originally intended to implement in the
 * first place.
 */

// System includes
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

// Project includes
#include <assembly.h>

// Directory-immediate includes
#include "types.h"

/*-------------------------------------- DEFINITIONS -------------------------*/

#define EXPORT_KEY_FMT		"assm-export-key-%d"
#define EXPORT_KEY_LEN		255
#define EXPORT_SHM_FLAGS	(O_RDWR | O_CREAT | O_EXCL)
#define EXPORT_SHM_MODE		0660	// -rw-rw----
#define EXPORT_SHM_SIZE		sizeof(struct assembly)
#define EXPORT_MMAP_PERMS	PROT_WRITE
#define EXPORT_MMAP_FLAGS	MAP_SHARED

#define IMPORT_SHM_FLAGS	O_RDWR
#define IMPORT_MMAP_FLAGS	MAP_SHARED
#define IMPORT_MMAP_PERMS	PROT_READ

/*-------------------------------------- EXTERNAL FUNCTIONS ------------------*/

int export_assembly(assembly_key key, struct assembly *assm)
{
	int err;
	char shm_file[EXPORT_KEY_LEN];
	void *shm = NULL;
	int shm_fd = -1;

	memset(shm_file, 0, EXPORT_KEY_LEN);
	snprintf(shm_file, EXPORT_KEY_LEN, EXPORT_KEY_FMT, key);

	// create the shm file and map it in
	shm_fd = shm_open(shm_file, EXPORT_SHM_FLAGS, EXPORT_SHM_MODE);
	if (shm_fd < 0)
		goto fail;
	err = ftruncate(shm_fd, EXPORT_SHM_SIZE); // enlarge the space
	if (err < 0)
		goto fail;
	shm = mmap(NULL, EXPORT_SHM_SIZE, EXPORT_MMAP_PERMS,
			EXPORT_MMAP_FLAGS, shm_fd, 0);
	if (shm == MAP_FAILED)
		goto fail;

	// copy the assembly into it
	memcpy(shm, assm, sizeof(*assm));

	// unmap and close it off but don't delete it
	err = munmap(shm, EXPORT_SHM_SIZE);
	err = close(shm_fd);

	return 0;

fail:
	if (shm != MAP_FAILED)
		munmap(shm, EXPORT_SHM_SIZE);
	if (shm_fd) {
		close(shm_fd);
		shm_unlink(shm_file);
	}
	return -1;
}

int import_assembly(assembly_key key, struct assembly *assm)
{
	int err, exit_errno = -1;
	char shm_file[EXPORT_KEY_LEN];
	void *shm = NULL;
	int shm_fd = -1;

	memset(shm_file, 0, EXPORT_KEY_LEN);

	snprintf(shm_file, EXPORT_KEY_LEN, EXPORT_KEY_FMT, key);

	// open the shm file and map it in
	shm_fd = shm_open(shm_file, IMPORT_SHM_FLAGS, EXPORT_SHM_MODE);
	if (shm_fd < 0) {
		if (errno == ENOENT)
			exit_errno = -ENOENT;
		goto fail;
	}
	err = ftruncate(shm_fd, EXPORT_SHM_SIZE); // enlarge the space
	if (err < 0)
		goto fail;
	shm = mmap(NULL, EXPORT_SHM_SIZE, IMPORT_MMAP_PERMS,
			IMPORT_MMAP_FLAGS, shm_fd, 0);
	if (shm == MAP_FAILED)
		goto fail;

	// copy the assembly out
	memcpy(assm, shm, sizeof(*assm));

	// unmap, close and delete the file
	err = munmap(shm, EXPORT_SHM_SIZE);
	err = close(shm_fd);
	err = shm_unlink(shm_file);

	return 0;
fail:
	if (shm != MAP_FAILED)
		munmap(shm, EXPORT_SHM_SIZE);
	if (shm_fd) {
		close(shm_fd);
		shm_unlink(shm_file);
	}
	return exit_errno;
}


text:
input()
throws = [int(x) for x in input().split()]
sorted_throws = throws.copy()
sorted_throws.sort(reverse=True)
for i in sorted_throws:
    if sorted_throws.count(i) == 1:
        print(throws.index(i)+1)
        exit()
print("none")


text:
from collections import OrderedDict
from datetime import datetime, timedelta
import csv
import inspect
import json
import logging
import os
import random
import unittest

from cityhash import CityHash32
import tensorflow.compat.v1 as tf
from tensorflow.compat.v1 import gfile

from fedlearner.common.common import set_logger
from fedlearner.data_join.raw_data.raw_data import RawData
from fedlearner.data_join.raw_data.common import DataKeyword, \
    JobType, OutputType
from fedlearner.data_join.raw_data.raw_data_job import RawDataJob

class TestDataGenerator(object):
    @staticmethod
    def _get_input_fpath(output_dir, date_str, partition_id, extension="gz"):
        return "{}/{}/partition_{:04}.{}".format(
            output_dir, date_str, partition_id, extension)

    @staticmethod
    def _get_data(partition_num, num_item_per_partition):
        start_time = datetime.strptime('2021-1-1', '%Y-%m-%d')
        event_times = [
            int((start_time + timedelta(hours=idx)).strftime("%Y%m%d%H%M%S"))
            for idx in range(num_item_per_partition)]
        eid_etime_dict = OrderedDict()
        etime_eid_dict = OrderedDict()

        example_id = 1000001
        for idx in range(partition_num * num_item_per_partition):
            etime_idx = idx % num_item_per_partition
            eid_etime_dict[example_id] = [
                idx, example_id, event_times[etime_idx]]
            if event_times[etime_idx] not in etime_eid_dict:
                etime_eid_dict[event_times[etime_idx]] = []
            etime_eid_dict[event_times[etime_idx]].append(str(example_id))
            example_id += 1
        return event_times, eid_etime_dict, etime_eid_dict

    def _generate_tfrecord_partition(self, output_dir,
                                     partition_id,
                                     example_ids,
                                     event_times,
                                     is_miss,
                                     is_wrong):
        types = ['Chinese', 'English', 'Math', 'Physics']
        date_str = str(event_times[0])[:8]
        fpath = self._get_input_fpath(output_dir, date_str, partition_id)
        dirname = os.path.dirname(fpath)
        if not gfile.Exists(dirname):
            gfile.MakeDirs(dirname)
        options = tf.python_io.TFRecordOptions(
            tf.python_io.TFRecordCompressionType.GZIP)
        with tf.io.TFRecordWriter(fpath, options=options) as writer:
            for example_id, event_time in zip(example_ids, event_times):
                feat = {}
                if not is_miss:
                    if isinstance(example_id, int):
                        feat['example_id'] = tf.train.Feature(
                           int64_list=tf.train.Int64List(value=[example_id]))
                    else:
                        feat['example_id'] = tf.train.Feature(
                            bytes_list=tf.train.BytesList(value=[
                                str(example_id).encode(
                                    'utf-8')]))
                    feat['raw_id'] = tf.train.Feature(
                        bytes_list=tf.train.BytesList(value=[
                            str(example_id).encode(
                                'utf-8')]))
                    if is_wrong:
                        feat['event_time'] = tf.train.Feature(
                            bytes_list=tf.train.BytesList(value=[
                                str("a").encode(
                                    'utf-8')]))
                    else:
                        feat['event_time'] = tf.train.Feature(
                            int64_list=tf.train.Int64List(
                                value=[event_time]))
                if random.random() < 0.8:
                    feat['label'] = tf.train.Feature(
                        int64_list=tf.train.Int64List(
                            value=[random.randint(0, 1)]))
                if random.random() < 0.8:
                    feat['type'] = tf.train.Feature(
                        bytes_list=tf.train.BytesList(
                            value=[types[random.randint(0, 3)].encode('utf-8')])
                    )
                example = tf.train.Example(
                    features=tf.train.Features(feature=feat))
                writer.write(example.SerializeToString())
        success_flag_fpath = "{}/_SUCCESS".format(dirname)
        with gfile.GFile(success_flag_fpath, 'w') as fh:
            fh.write('')
        return fpath

    def _generate_csv_partition(self, output_dir,
                                partition_id,
                                example_ids,
                                event_times,
                                is_miss,
                                is_wrong):
        types = ['Chinese', 'English', 'Math', 'Physics']
        date_str = str(event_times[0])[:8]
        fpath = self._get_input_fpath(output_dir, date_str, partition_id, "csv")
        dirname = os.path.dirname(fpath)
        if not gfile.Exists(dirname):
            gfile.MakeDirs(dirname)
        headers = []
        if not is_miss:
            headers = ['example_id', 'raw_id', 'event_time']
        headers.append('type')
        with open(fpath, 'w') as csv_file:
            writer = csv.DictWriter(csv_file, fieldnames=headers)
            writer.writeheader()
            for example_id, event_time in zip(example_ids, event_times):
                if is_miss:
                    writer.writerow({
                        "type": types[random.randint(0, 3)]
                    })
                elif is_wrong:
                    writer.writerow({
                        "example_id": str(example_id),
                        "raw_id": str(example_id),
                        "event_time": "a",
                        "type": types[random.randint(0, 3)]
                    })
                else:
                    writer.writerow({
                        "example_id": str(example_id),
                        "raw_id": str(example_id),
                        "event_time": event_time,
                        "type": types[random.randint(0, 3)]
                    })
        return fpath

    def generate_input_data(self, output_dir, partition_num,
                            num_item_per_partition,
                            is_miss=False,
                            is_dirty=False,
                            is_wrong=False,
                            input_format="TF_RECORD"):
        if not gfile.Exists(output_dir):
            gfile.MakeDirs(output_dir)
        start_time = datetime.strptime('2020-7-1', '%Y-%m-%d')
        example_id = 1000001

        etime_eid_dict = OrderedDict()
        output_files = []
        for partition_id in range(partition_num):
            event_times = []
            eids = []
            for idx in range(num_item_per_partition):
                event_times.append(int((start_time + timedelta(
                    hours=idx)).strftime("%Y%m%d%H%M%S")))
                if is_dirty:
                    eids.append(example_id)
                else:
                    eids.append(str(example_id))
                etime_eid_dict[event_times[-1]] = [str(example_id)]
                example_id += 1
            if input_format == "CSV_DICT":
                filename = self._generate_csv_partition(
                    output_dir, partition_id,
                    eids, event_times, is_miss, is_wrong)
            else:
                filename = self._generate_tfrecord_partition(
                    output_dir, partition_id,
                    eids, event_times, is_miss, is_wrong)
            output_files.append(filename)
            start_time += timedelta(days=1)
        return etime_eid_dict, output_files

def parse_example(record_str):
    try:
        example = tf.train.Example()
        example.ParseFromString(record_str)
        return example
    except Exception as e: # pylint: disable=broad-except
        logging.error("Failed parse tf.Example from record %s, reason %s",
                      record_str, e)
    return None

def convert_tf_example_to_dict(src_tf_example):
    assert isinstance(src_tf_example, tf.train.Example)
    dst_dict = OrderedDict()
    tf_feature = src_tf_example.features.feature
    for key, feat in tf_feature.items():
        if feat.HasField('int64_list'):
            csv_val = [item for item in
                       feat.int64_list.value]  # pylint: disable=unnecessary-comprehension
        elif feat.HasField('bytes_list'):
            csv_val = [item for item in
                       feat.bytes_list.value]  # pylint: disable=unnecessary-comprehension
        elif feat.HasField('float_list'):
            csv_val = [item for item in
                       feat.float_list.value]  # pylint: disable=unnecessary-comprehension
        else:
            assert False, "feat type must in int64, byte, float"
        assert isinstance(csv_val, list)
        dst_dict[key] = csv_val[0] if len(csv_val) == 1 else csv_val
    return dst_dict

class RawDataTests(unittest.TestCase):
    def setUp(self) -> None:
        self._job_path = "test_raw_data_path"
        self._job_name = "test_raw_data"

        self._input_dir = "{}/input_data".format(self._job_path)
        self._num_partition = 4
        self._num_item_per_partition = 50
        cur_dir = os.path.dirname(os.path.realpath(__file__))
        jar_path = os.path.join(cur_dir, 'jars')
        self._jars = []
        for filename in gfile.ListDirectory(jar_path):
            self._jars.append(os.path.join(jar_path, filename))
        os.environ['SPARK_JARS'] = ','.join(self._jars)

    def tearDown(self) -> None:
        if gfile.Exists(self._job_path):
            gfile.DeleteRecursively(self._job_path)

    def _check_tfrecord(self, file_paths, output_partitions, wanted_cnt):
        total_cnt = 0
        for partition_id, fpath in enumerate(sorted(file_paths)):
            event_time = 0
            options = tf.io.TFRecordOptions(compression_type='GZIP')
            for record in tf.python_io.tf_record_iterator(fpath, options):
                tf_item = convert_tf_example_to_dict(parse_example(record))
                new_event_time = tf_item[DataKeyword.event_time]
                self.assertTrue(new_event_time >= event_time,
                                "{}, {}".format(new_event_time, event_time))
                event_time = new_event_time
                self.assertEqual(partition_id, CityHash32(
                    tf_item[DataKeyword.example_id]) % output_partitions)
                total_cnt += 1
        self.assertEqual(total_cnt, wanted_cnt)

    def _check_csv(self, file_paths, output_partitions, wanted_cnt):
        total_cnt = 0
        for partition_id, fpath in enumerate(sorted(file_paths)):
            event_time = 0
            with open(fpath) as f:
                for item in csv.DictReader(f):
                    new_event_time = int(item[DataKeyword.event_time])
                    self.assertTrue(new_event_time >= event_time,
                                    "{}, {}".format(new_event_time, event_time))
                    event_time = new_event_time
                    self.assertEqual(partition_id, CityHash32(
                        item[DataKeyword.example_id]) % output_partitions)
                    total_cnt += 1
        self.assertEqual(total_cnt, wanted_cnt)

    def _test_raw_data(self, input_format, output_format):
        # generate test data
        generator = TestDataGenerator()
        self._input_data, self._input_files = \
            generator.generate_input_data(
                self._input_dir, self._num_partition,
                self._num_item_per_partition, input_format=input_format)

        schema_file_path = os.path.join(self._job_path, "raw_data",
                                        "data.schema.json")
        output_path = os.path.join(self._job_path, "raw_data", str(0))
        output_partition_num = 20

        json_str = """{
            "job_type": "%s",
            "input_files": "%s",
            "input_format": "%s",
            "schema_path": "%s",
            "output_type": "raw_data",
            "output_path": "%s",
            "output_format": "%s",
            "output_partition_num": %d,
            "validation": 1
        }""" % (JobType.Streaming, ','.join(self._input_files), input_format,
                schema_file_path, output_path, output_format,
                output_partition_num)
        config = json.loads(json_str)
        processor = RawData(None, self._jars)
        processor.run(config)
        processor.stop()

        total_num = self._num_partition * self._num_item_per_partition
        if output_format == "CSV_DICT":
            file_paths = []
            for file in gfile.ListDirectory(output_path):
                if file.endswith("csv"):
                    file_paths.append(os.path.join(output_path, file))

            self.assertEqual(output_partition_num, len(file_paths))
            self._check_csv(file_paths, output_partition_num, total_num)
        else:
            file_paths = []
            for file in gfile.ListDirectory(output_path):
                if file.endswith("gz"):
                    file_paths.append(os.path.join(output_path, file))

            self.assertEqual(output_partition_num, len(file_paths))
            self._check_tfrecord(file_paths, output_partition_num, total_num)

    def test_from_tfrecord(self):
        self._test_raw_data("TF_RECORD", "TF_RECORD")

    def test_from_csv_to_tfrecord(self):
        self._test_raw_data("CSV_DICT", "TF_RECORD")

    def test_from_csv_to_csv(self):
        self._test_raw_data("CSV_DICT", "CSV_DICT")

    def _test_dirty_input(self, input_format, is_miss, is_wrong):
        # generate test data
        generator = TestDataGenerator()
        self._input_data, self._input_files = \
            generator.generate_input_data(
                self._input_dir, self._num_partition,
                self._num_item_per_partition, is_miss=is_miss,
                is_wrong=is_wrong,
                input_format=input_format)

        schema_file_path = os.path.join(self._job_path, "raw_data",
                                        "data.schema.json")
        output_path = os.path.join(self._job_path, "raw_data", str(0))
        output_partition_num = 4

        json_str = """{
            "job_type": "%s",
            "input_files": "%s",
            "input_format": "%s",
            "schema_path": "%s",
            "output_type": "raw_data",
            "output_path": "%s",
            "output_format": "TF_RECORD",
            "output_partition_num": %d,
            "validation": 1
        }""" % (JobType.Streaming, ','.join(self._input_files), input_format,
                schema_file_path, output_path, output_partition_num)
        config = json.loads(json_str)
        processor = RawData(None, self._jars)
        with self.assertRaises(RuntimeError):
            processor.run(config)
        processor.stop()

    def test_missed_field_tfrecord(self):
        self._test_dirty_input("TF_RECORD", is_miss=True, is_wrong=False)

    def test_missed_field_csv(self):
        self._test_dirty_input("CSV_DICT", is_miss=True, is_wrong=False)

    def test_wrong_field_tfrecord(self):
        self._test_dirty_input("TF_RECORD", is_miss=False, is_wrong=True)

    def test_run_raw_data_dirty(self):
        # generate test data
        generator = TestDataGenerator()
        self._input_data, self._input_files = \
            generator.generate_input_data(
                self._input_dir, self._num_partition,
                self._num_item_per_partition, is_miss=True)

        output_partition_num = 4
        os.environ['STORAGE_ROOT_PATH'] = self._job_path
        output_path = os.path.join(self._job_path, "raw_data", self._job_name)
        raw_data_publish_dir = os.path.join("portal_publish_dir",
                                            self._job_name)
        upload_dir = os.path.join(output_path, "upload")
        if not gfile.Exists(upload_dir):
            gfile.MakeDirs(upload_dir)
        entry_file_path = inspect.getfile(RawData)
        file_name = os.path.basename(entry_file_path)
        target_dir = os.path.join(upload_dir, file_name)
        gfile.Copy(entry_file_path, target_dir)
        job = RawDataJob(self._job_name, output_path,
                         job_type=JobType.Streaming,
                         output_partition_num=output_partition_num,
                         raw_data_publish_dir=raw_data_publish_dir,
                         output_type=OutputType.RawData,
                         check_success_tag=True,
                         single_subfolder=True,
                         upload_dir=upload_dir,
                         kvstore_type="dfs",
                         use_fake_client=True)
        with self.assertRaises(SystemExit):
            job.run(self._input_dir, "TF_RECORD", "TF_RECORD")

        for job_id in range(self._num_partition):
            output_dir = os.path.join(output_path, str(job_id))
            self.assertFalse(gfile.Exists(output_dir))

    def test_run_raw_data(self):
        # generate test data
        generator = TestDataGenerator()
        self._input_data, self._input_files = \
            generator.generate_input_data(
                self._input_dir, self._num_partition,
                self._num_item_per_partition)

        output_partition_num = 4
        os.environ['STORAGE_ROOT_PATH'] = self._job_path
        output_path = os.path.join(self._job_path, "raw_data", self._job_name)
        raw_data_publish_dir = os.path.join("portal_publish_dir",
                                            self._job_name)
        upload_dir = os.path.join(output_path, "upload")
        if not gfile.Exists(upload_dir):
            gfile.MakeDirs(upload_dir)
        entry_file_path = inspect.getfile(RawData)
        file_name = os.path.basename(entry_file_path)
        target_dir = os.path.join(upload_dir, file_name)
        gfile.Copy(entry_file_path, target_dir)
        job = RawDataJob(self._job_name, output_path,
                         job_type=JobType.Streaming,
                         output_partition_num=output_partition_num,
                         raw_data_publish_dir=raw_data_publish_dir,
                         output_type=OutputType.RawData,
                         check_success_tag=True,
                         single_subfolder=True,
                         upload_dir=upload_dir,
                         kvstore_type="dfs",
                         use_fake_client=True)
        job.run(self._input_dir, "TF_RECORD", "TF_RECORD")

        for job_id in range(self._num_partition):
            file_paths = []
            output_dir = os.path.join(output_path, str(job_id))
            self.assertTrue(gfile.IsDirectory(output_dir))
            filenames = [file for file in gfile.ListDirectory(output_dir)
                         if not file.startswith(('_', '.'))]
            self.assertEqual(len(filenames), output_partition_num, filenames)
            file_paths.extend([
                os.path.join(output_dir, fname) for fname in filenames
            ])

            self._check_tfrecord(file_paths, output_partition_num,
                                 self._num_item_per_partition)

if __name__ == '__main__':
    set_logger()
    unittest.main()


text:
package org.apache.spark.util

import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import scala.collection.mutable.Buffer
import java.util.NoSuchElementException

class NextIteratorSuite extends FunSuite with ShouldMatchers {
  test("one iteration") {
    val i = new StubIterator(Buffer(1))
    i.hasNext should be === true
    i.next should be === 1
    i.hasNext should be === false
    intercept[NoSuchElementException] { i.next() }
  }

  test("two iterations") {
    val i = new StubIterator(Buffer(1, 2))
    i.hasNext should be === true
    i.next should be === 1
    i.hasNext should be === true
    i.next should be === 2
    i.hasNext should be === false
    intercept[NoSuchElementException] { i.next() }
  }

  test("empty iteration") {
    val i = new StubIterator(Buffer())
    i.hasNext should be === false
    intercept[NoSuchElementException] { i.next() }
  }

  test("close is called once for empty iterations") {
    val i = new StubIterator(Buffer())
    i.hasNext should be === false
    i.hasNext should be === false
    i.closeCalled should be === 1
  }

  test("close is called once for non-empty iterations") {
    val i = new StubIterator(Buffer(1, 2))
    i.next should be === 1
    i.next should be === 2
    // close isn't called until we check for the next element
    i.closeCalled should be === 0
    i.hasNext should be === false
    i.closeCalled should be === 1
    i.hasNext should be === false
    i.closeCalled should be === 1
  }

  class StubIterator(ints: Buffer[Int])  extends NextIterator[Int] {
    var closeCalled = 0

    override def getNext() = {
      if (ints.size == 0) {
        finished = true
        0
      } else {
        ints.remove(0)
      }
    }

    override def close() {
      closeCalled += 1
    }
  }
}


text:
<?php

namespace Elixir\Security\Auth\Storage;

use Elixir\Security\Auth\AuthEvent;
use Elixir\Security\Auth\Identity;

/**
 * @author Cédric Tanghe <ced.tanghe@gmail.com>
 */
trait StorageTrait
{
    /**
     * @var array
     */
    protected $identities = [];

    /**
     * @param Identity $identity
     */
    protected function observe(Identity $identity)
    {
        if (!in_array($identity, $this->identities, true)) {
            $identity->addListener(AuthEvent::IDENTITY_UPDATED, [$this, 'onIdentityUpdated']);
            $identity->addListener(AuthEvent::IDENTITY_REMOVED, [$this, 'onIdentityRemoved']);

            $this->identities[] = $identity;
        }
    }

    /**
     * @param Identity $identity
     */
    protected function unObserve(Identity $identity)
    {
        if ($pos = array_search($identity, $this->identities, true)) {
            $identity->removeListener(AuthEvent::IDENTITY_UPDATED, [$this, 'onIdentityUpdated']);
            $identity->removeListener(AuthEvent::IDENTITY_REMOVED, [$this, 'onIdentityRemoved']);

            array_splice($this->identities, $pos, 1);
        }
    }

    /**
     * @internal
     */
    public function onIdentityUpdated(AuthEvent $event)
    {
        $this->addIdentity($event->getTarget()->getDomain(), $event->getTarget());
    }

    /**
     * @internal
     */
    public function onIdentityRemoved(AuthEvent $event)
    {
        $this->clearIdentity($event->getTarget()->getDomain());
    }
}


text:
<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="header">
    <meta charset="UTF-8" />
    <title th:text="${titleName}"></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta http-equiv="keywords" content="java,数据结构,算法分析,云计算,大数据"/>
    <link rel="shortcut icon" th:href="@{/logo/bedoing.ico}" />

    <!--LOCAL-->
    <!--<link rel="stylesheet" type="text/css" th:href="@{/bootstrap 3.3.5/css/bootstrap.css}"/>

    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/bootstrap 3.3.5/js/bootstrap.js}"></script>-->

    <!--CDN-->
    <link rel="stylesheet" type="text/css" th:href="@{http://cdn.staticfile.org/twitter-bootstrap/3.3.5/css/bootstrap.min.css}"/>

    <script th:src="@{http://cdn.staticfile.org/jquery/2.2.1/jquery.min.js}"></script>
    <script th:src="@{http://cdn.staticfile.org/twitter-bootstrap/3.3.5/js/bootstrap.min.js}"></script>

    <!--CUSTOM-->
    <script th:src="@{/js/common.js}"></script>

    <link rel="stylesheet" type="text/css" th:href="@{/css/admin/style.css}"/>
</head>
</html>


text:
int64_t bitfield_get(void *data, int is_signed, int offset, int nbits);
int64_t bitfield_set(void *data, int is_signed, int offset, int nbits, int64_t value);


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.
[assembly: AssemblyTitle("GPS Diagnostics")]
[assembly: AssemblyDescription("Searches for GPS devices and helps solve connectivity issues.")]
[assembly: AssemblyConfiguration("Public Release")]
[assembly: AssemblyCompany("DotSpatial.Positioning")]
[assembly: AssemblyProduct("GPS Diagnostics")]
[assembly: AssemblyCopyright("Copyright © DotSpatial Team 2015")]
[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("572317a9-4bb1-4207-918d-63c0bdb68034")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8")]
[assembly: AssemblyInformationalVersion("1.8 Experimental Release")]
[assembly: AssemblyFileVersion("1.8")]