text:
import tests
from common import TestCommon
from results import PassFailMultiResult

# generate test-cases with <=CHUNK_SIZE compiler-rt tests each
CHUNK_SIZE=26
# array just to keep the class objects somewhere
compiler_rt_tests_classes = []

def get_modules_tpl(ts, self, build, machine):
    '''Function template for get_modules() for each compiler-rt test case'''
    modules = super(CompilerRTBuiltinsAbstract, self).get_modules(build, machine)
    for m in ts:
        if hasattr(machine, "name") and machine.name.startswith("panda") and \
           (m.endswith("floatdisf_test") or m.endswith("floatdidf_test")):
            # Skip failing test on pandaboard
            continue
        modules.add_module(m)
    modules.add_module("usleeptest", [ "5" ])
    return modules

def chunker(seq, size):
    '''Helper function: this takes a sequence `seq` and splits it up into
    `size`-sized chunks, except for the last chunk which is just the <= size
    long remainder of the sequence'''
    return (seq[pos:pos+size] for pos in xrange(0, len(seq), size))

def generate_test_cases(prefix, testlist):
    for i, ts in enumerate(chunker(testlist, CHUNK_SIZE)):
        # append new class to our array
        compiler_rt_tests_classes.append(
            # this is essentially the decorator @tests.add_test
            tests.add_test(
                # type is the (built-in) base-class for python classes, here we
                # construct classes by calling its constructor
                # signature of type constructor:
                #   type(classname, baseclass tuple, dict with methods/attributes)
                type('CompilerRTBuiltins%d' % (i+1),
                     (CompilerRTBuiltinsAbstract,),
                     { 'name': '%s%d' % (prefix, (i+1)),
                        # partially bind the get_modules() template to select the
                        # right set of tests. Note the ts=ts in the lambda
                        # arguments, this prevents python's default late-binding
                        # for closure arguments.
                         'get_modules':
                             lambda s, b, m, ts=ts: get_modules_tpl(ts, s, b, m)})))

class CompilerRTBuiltinsAbstract(TestCommon):

    def get_finish_string(self):
        return "usleeptest_done"

    def process_data(self, testdir, rawiter):
        # the test passed if no error occurred
        errors = []
        for line in rawiter:
            if "error in" in line:
                errors.append(line)
            if line.startswith("Assertion failed on core"):
                errors.append(line)

        return PassFailMultiResult(self.name, errors)

# lists of tests to run for compiler-rt
vector_fp_tests = [
        "compiler-rt/test/builtins/Unit/adddf3vfp_test",
        "compiler-rt/test/builtins/Unit/addsf3vfp_test",
        "compiler-rt/test/builtins/Unit/divdf3vfp_test",
        "compiler-rt/test/builtins/Unit/divsf3vfp_test",
        "compiler-rt/test/builtins/Unit/eqdf2vfp_test",
        "compiler-rt/test/builtins/Unit/eqsf2vfp_test",
        "compiler-rt/test/builtins/Unit/extebdsfdf2vfp_test",
        "compiler-rt/test/builtins/Unit/fixdfsivfp_test",
        "compiler-rt/test/builtins/Unit/fixsfsivfp_test",
        "compiler-rt/test/builtins/Unit/fixunsdfsivfp_test",
        "compiler-rt/test/builtins/Unit/fixunssfsivfp_test",
        "compiler-rt/test/builtins/Unit/floatsidfvfp_test",
        "compiler-rt/test/builtins/Unit/floatsisfvfp_test",
        "compiler-rt/test/builtins/Unit/floatunssidfvfp_test",
        "compiler-rt/test/builtins/Unit/floatunssisfvfp_test",
        "compiler-rt/test/builtins/Unit/gedf2vfp_test",
        "compiler-rt/test/builtins/Unit/gesf2vfp_test",
        "compiler-rt/test/builtins/Unit/gtdf2vfp_test",
        "compiler-rt/test/builtins/Unit/gtsf2vfp_test",
        "compiler-rt/test/builtins/Unit/ledf2vfp_test",
        "compiler-rt/test/builtins/Unit/lesf2vfp_test",
        "compiler-rt/test/builtins/Unit/ltdf2vfp_test",
        "compiler-rt/test/builtins/Unit/ltsf2vfp_test",
        "compiler-rt/test/builtins/Unit/muldf3vfp_test",
        "compiler-rt/test/builtins/Unit/mulsf3vfp_test",
        "compiler-rt/test/builtins/Unit/nedf2vfp_test",
        "compiler-rt/test/builtins/Unit/negdf2vfp_test",
        "compiler-rt/test/builtins/Unit/negsf2vfp_test",
        "compiler-rt/test/builtins/Unit/nesf2vfp_test",
        "compiler-rt/test/builtins/Unit/subdf3vfp_test",
        "compiler-rt/test/builtins/Unit/subsf3vfp_test",
        "compiler-rt/test/builtins/Unit/truncdfsf2vfp_test",
        "compiler-rt/test/builtins/Unit/unorddf2vfp_test",
        "compiler-rt/test/builtins/Unit/unordsf2vfp_test",
]

generate_test_cases("compiler-rt-vfp", vector_fp_tests)

fp_tests = [
        "compiler-rt/test/builtins/Unit/absvdi2_test",
        "compiler-rt/test/builtins/Unit/absvsi2_test",
        "compiler-rt/test/builtins/Unit/absvti2_test",
        "compiler-rt/test/builtins/Unit/addtf3_test",
        "compiler-rt/test/builtins/Unit/addvdi3_test",
        "compiler-rt/test/builtins/Unit/addvsi3_test",
        "compiler-rt/test/builtins/Unit/addvti3_test",
        "compiler-rt/test/builtins/Unit/ashldi3_test",
        "compiler-rt/test/builtins/Unit/ashlti3_test",
        "compiler-rt/test/builtins/Unit/ashrdi3_test",
        "compiler-rt/test/builtins/Unit/ashrti3_test",
        "compiler-rt/test/builtins/Unit/bswapdi2_test",
        "compiler-rt/test/builtins/Unit/bswapsi2_test",
#       "compiler-rt/test/builtins/Unit/clear_cache_test",
        "compiler-rt/test/builtins/Unit/clzdi2_test",
        "compiler-rt/test/builtins/Unit/clzsi2_test",
        "compiler-rt/test/builtins/Unit/clzti2_test",
        "compiler-rt/test/builtins/Unit/cmpdi2_test",
        "compiler-rt/test/builtins/Unit/cmpti2_test",
        "compiler-rt/test/builtins/Unit/comparedf2_test",
        "compiler-rt/test/builtins/Unit/comparesf2_test",
        "compiler-rt/test/builtins/Unit/ctzdi2_test",
        "compiler-rt/test/builtins/Unit/ctzsi2_test",
        "compiler-rt/test/builtins/Unit/ctzti2_test",
        "compiler-rt/test/builtins/Unit/divdc3_test",
        "compiler-rt/test/builtins/Unit/divdi3_test",
        "compiler-rt/test/builtins/Unit/divmodsi4_test",
        "compiler-rt/test/builtins/Unit/divsc3_test",
        "compiler-rt/test/builtins/Unit/divsi3_test",
#       "compiler-rt/test/builtins/Unit/divtc3_test",
        "compiler-rt/test/builtins/Unit/divtf3_test",
        "compiler-rt/test/builtins/Unit/divti3_test",
        "compiler-rt/test/builtins/Unit/divxc3_test",
#       "compiler-rt/test/builtins/Unit/enable_execute_stack_test",
        "compiler-rt/test/builtins/Unit/eqtf2_test",
        "compiler-rt/test/builtins/Unit/extenddftf2_test",
#       "compiler-rt/test/builtins/Unit/extendhfsf2_test",
        "compiler-rt/test/builtins/Unit/extendsftf2_test",
        "compiler-rt/test/builtins/Unit/ffsdi2_test",
        "compiler-rt/test/builtins/Unit/ffsti2_test",
        "compiler-rt/test/builtins/Unit/fixdfdi_test",
        "compiler-rt/test/builtins/Unit/fixdfti_test",
        "compiler-rt/test/builtins/Unit/fixsfdi_test",
        "compiler-rt/test/builtins/Unit/fixsfti_test",
        "compiler-rt/test/builtins/Unit/fixtfdi_test",
        "compiler-rt/test/builtins/Unit/fixtfsi_test",
        "compiler-rt/test/builtins/Unit/fixtfti_test",
        # this errors on 0X1P+64
        #"compiler-rt/test/builtins/Unit/fixunsdfdi_test",
        "compiler-rt/test/builtins/Unit/fixunsdfsi_test",
        "compiler-rt/test/builtins/Unit/fixunsdfti_test",
        # this errors on 0X1P+64
        #"compiler-rt/test/builtins/Unit/fixunssfdi_test",
        "compiler-rt/test/builtins/Unit/fixunssfsi_test",
        "compiler-rt/test/builtins/Unit/fixunssfti_test",
        "compiler-rt/test/builtins/Unit/fixunstfdi_test",
        "compiler-rt/test/builtins/Unit/fixunstfsi_test",
        "compiler-rt/test/builtins/Unit/fixunstfti_test",
        "compiler-rt/test/builtins/Unit/fixunsxfdi_test",
        "compiler-rt/test/builtins/Unit/fixunsxfsi_test",
        "compiler-rt/test/builtins/Unit/fixunsxfti_test",
        "compiler-rt/test/builtins/Unit/fixxfdi_test",
        "compiler-rt/test/builtins/Unit/fixxfti_test",
        "compiler-rt/test/builtins/Unit/floatdidf_test",
        "compiler-rt/test/builtins/Unit/floatdisf_test",
        "compiler-rt/test/builtins/Unit/floatditf_test",
        "compiler-rt/test/builtins/Unit/floatdixf_test",
        "compiler-rt/test/builtins/Unit/floatsitf_test",
        "compiler-rt/test/builtins/Unit/floattidf_test",
        "compiler-rt/test/builtins/Unit/floattisf_test",
        "compiler-rt/test/builtins/Unit/floattixf_test",
        "compiler-rt/test/builtins/Unit/floatundidf_test",
        "compiler-rt/test/builtins/Unit/floatundisf_test",
        "compiler-rt/test/builtins/Unit/floatunditf_test",
        "compiler-rt/test/builtins/Unit/floatundixf_test",
        "compiler-rt/test/builtins/Unit/floatunsitf_test",
        "compiler-rt/test/builtins/Unit/floatuntidf_test",
        "compiler-rt/test/builtins/Unit/floatuntisf_test",
        "compiler-rt/test/builtins/Unit/floatuntixf_test",
#       "compiler-rt/test/builtins/Unit/gcc_personality_test",
        "compiler-rt/test/builtins/Unit/getf2_test",
        "compiler-rt/test/builtins/Unit/gttf2_test",
        "compiler-rt/test/builtins/Unit/letf2_test",
        "compiler-rt/test/builtins/Unit/lshrdi3_test",
        "compiler-rt/test/builtins/Unit/lshrti3_test",
        "compiler-rt/test/builtins/Unit/lttf2_test",
        "compiler-rt/test/builtins/Unit/moddi3_test",
        "compiler-rt/test/builtins/Unit/modsi3_test",
        "compiler-rt/test/builtins/Unit/modti3_test",
        "compiler-rt/test/builtins/Unit/muldc3_test",
        "compiler-rt/test/builtins/Unit/muldi3_test",
        "compiler-rt/test/builtins/Unit/mulodi4_test",
        "compiler-rt/test/builtins/Unit/mulosi4_test",
        "compiler-rt/test/builtins/Unit/muloti4_test",
        "compiler-rt/test/builtins/Unit/mulsc3_test",
        "compiler-rt/test/builtins/Unit/multc3_test",
        "compiler-rt/test/builtins/Unit/multf3_test",
        "compiler-rt/test/builtins/Unit/multi3_test",
        "compiler-rt/test/builtins/Unit/mulvdi3_test",
        "compiler-rt/test/builtins/Unit/mulvsi3_test",
        "compiler-rt/test/builtins/Unit/mulvti3_test",
        "compiler-rt/test/builtins/Unit/mulxc3_test",
        "compiler-rt/test/builtins/Unit/negdi2_test",
        "compiler-rt/test/builtins/Unit/negti2_test",
        "compiler-rt/test/builtins/Unit/negvdi2_test",
        "compiler-rt/test/builtins/Unit/negvsi2_test",
        "compiler-rt/test/builtins/Unit/negvti2_test",
        "compiler-rt/test/builtins/Unit/netf2_test",
        "compiler-rt/test/builtins/Unit/paritydi2_test",
        "compiler-rt/test/builtins/Unit/paritysi2_test",
        "compiler-rt/test/builtins/Unit/parityti2_test",
        "compiler-rt/test/builtins/Unit/popcountdi2_test",
        "compiler-rt/test/builtins/Unit/popcountsi2_test",
        "compiler-rt/test/builtins/Unit/popcountti2_test",
        "compiler-rt/test/builtins/Unit/powidf2_test",
        "compiler-rt/test/builtins/Unit/powisf2_test",
        "compiler-rt/test/builtins/Unit/powitf2_test",
        "compiler-rt/test/builtins/Unit/powixf2_test",
        "compiler-rt/test/builtins/Unit/subtf3_test",
        "compiler-rt/test/builtins/Unit/subvdi3_test",
        "compiler-rt/test/builtins/Unit/subvsi3_test",
        "compiler-rt/test/builtins/Unit/subvti3_test",
#       "compiler-rt/test/builtins/Unit/trampoline_setup_test",
#       "compiler-rt/test/builtins/Unit/truncdfhf2_test",
        "compiler-rt/test/builtins/Unit/truncdfsf2_test",
#       "compiler-rt/test/builtins/Unit/truncsfhf2_test",
        "compiler-rt/test/builtins/Unit/trunctfdf2_test",
        "compiler-rt/test/builtins/Unit/trunctfsf2_test",
        "compiler-rt/test/builtins/Unit/ucmpdi2_test",
        "compiler-rt/test/builtins/Unit/ucmpti2_test",
        "compiler-rt/test/builtins/Unit/udivdi3_test",
        "compiler-rt/test/builtins/Unit/udivmoddi4_test",
        "compiler-rt/test/builtins/Unit/udivmodsi4_test",
        "compiler-rt/test/builtins/Unit/udivmodti4_test",
        "compiler-rt/test/builtins/Unit/udivsi3_test",
        "compiler-rt/test/builtins/Unit/udivti3_test",
        "compiler-rt/test/builtins/Unit/umoddi3_test",
        "compiler-rt/test/builtins/Unit/umodsi3_test",
        "compiler-rt/test/builtins/Unit/umodti3_test",
        "compiler-rt/test/builtins/Unit/unordtf2_test",
]

generate_test_cases("compiler-rt-fp", fp_tests)


text:
import { inject, injectable } from 'inversify';
import * as apid from '../../../../../api';
import IRepositoryModel from '../IRepositoryModel';
import IRecordingApiModel from './IRecordingApiModel';

@injectable()
export default class RecordingApiModel implements IRecordingApiModel {
    private repository: IRepositoryModel;

    constructor(@inject('IRepositoryModel') repository: IRepositoryModel) {
        this.repository = repository;
    }

    /**
     * 録画情報の取得
     * @param option: GetRecordedOption
     * @return Promise<apid.Records>
     */
    public async gets(option: apid.GetRecordedOption): Promise<apid.Records> {
        const result = await this.repository.get('/recording', {
            params: option,
        });

        return result.data;
    }
}

redpajama_set_name: RedPajamaGithub


text:
import sys
import pickle
import math
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
from subprocess import Popen, PIPE
from collections import defaultdict

def tree(): return defaultdict(tree)

def run_command_with_params_and_get_output(command, args):
    # Compile first
    Popen(["make", command+"_compile"] + args, stdout=PIPE).communicate()[0]
    print(" ".join(["make", command+"_run"] + args))
    ret_val = Popen(["make", command+"_run"] + args, stdout=PIPE).communicate()[0].strip().split()
    print(ret_val)
    return ret_val

def get_values(v, command_range, epoch_range, batch_size_range, thread_range, rank_range, sync_range):
    values = []
    for c in command_range:
        for e in epoch_range:
            for b in batch_size_range:
                for t in thread_range:
                    for r in rank_range:
                        for s in sync_range:
                            values.append(v[c][e][b][t][r][s])
    return values

def draw_time_loss_graph(should_load_from_file, epoch_range, batch_size_range, thread_range, rank_range, sync_range, commands, n_rep):
    total_iter = len(batch_size_range) * len(thread_range) * len(rank_range) * len(sync_range) * len(commands) * n_rep
    cur_iter = 0
    loss_values = tree()
    overall_time_values = tree()
    gradient_time_values = tree()

    if not should_load_from_file:
        for b in batch_size_range:
            for t in thread_range:
                for r in rank_range:
                    for s in sync_range:
                        for c in commands:
                            losses, overall_times, gradient_times = [], [], []
                            for n in range(n_rep):
                                print("Iteration %d of %d" % (cur_iter, total_iter))
                                cur_iter += 1
                                output = run_command_with_params_and_get_output(c, ["N_EPOCHS="+str(epoch_range), "BATCH_SIZE="+str(b), "NTHREAD="+str(t), "RLENGTH="+str(r), "SHOULD_SYNC="+\
                                                                                str(s), "SHOULD_PRINT_LOSS_TIME_EVERY_EPOCH=1"])
                                values = [float(x) for x in output]
                                if n == 0:
                                    losses = [values[i] for i in range(0, len(values), 3)]
                                    overall_times = [values[i] for i in range(1, len(values), 3)]
                                    gradient_times = [values[i] for i in range(2, len(values), 3)]
                                else:
                                    losses = [losses[i/3] + values[i] for i in range(0, len(values), 3)]
                                    overall_times = [overall_times[i/3] + values[i] for i in range(1, len(values), 3)]
                                    gradient_times = [gradient_times[i/3] + values[i] for i in range(2, len(values), 3)]
                            losses = [x / float(n_rep) for x in losses]
                            overall_times = [x / float(n_rep) for x in overall_times]
                            gradient_times = [x / float(n_rep) for x in gradient_times]
                            loss_values[c][epoch_range][b][t][r][s] = losses
                            overall_time_values[c][epoch_range][b][t][r][s] = overall_times
                            gradient_time_values[c][epoch_range][b][t][r][s] = gradient_times
    else:
        with open('time_data.pickle') as f:
            loss_values, overall_time_values, gradient_time_values = pickle.load(f)
    with open('time_data.pickle', "w") as f:
        pickle.dump([loss_values, overall_time_values, gradient_time_values], f)

    for b in batch_size_range:
        for t in thread_range:
            for r in rank_range:
                title = "Overall_Time_Loss_batch=%d_thread=%d_rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.xlabel("Time")
                plt.ylabel("Loss")
                for s in sync_range:
                    for c in commands:
                        times = overall_time_values[c][epoch_range][b][t][r][s]
                        losses = loss_values[c][epoch_range][b][t][r][s]
                        if 'hog' in c:
                            if s:
                                plt.plot(times, losses, label=c, marker='o')
                        else:
                            plt.plot(times, losses, label=c+" sync="+str(s), marker='o')
                plt.yscale('log')
                #plt.xscale('log')
                plt.legend(loc="upper right", fontsize=8)
                plt.savefig(title + ".png")
                plt.clf()

    for b in batch_size_range:
        for t in thread_range:
            for r in rank_range:
                title = "Gradient_Time_Loss_batch=%d_thread=%d_rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.xlabel("Time")
                plt.ylabel("Loss")
                for s in sync_range:
                    for c in commands:
                        times = gradient_time_values[c][epoch_range][b][t][r][s]
                        losses = loss_values[c][epoch_range][b][t][r][s]
                        if 'hog' in c:
                            if s:
                                plt.plot(times, losses, label=c, marker='o')
                        else:
                            plt.plot(times, losses, label=c+" sync="+str(s), marker='o')
                plt.yscale('log')
                #plt.xscale('log')
                plt.legend(loc="upper right", fontsize=8)
                plt.savefig(title + ".png")
                plt.clf()

    hog_command = [x for x in commands if 'hog' in x][0]
    for b in batch_size_range:
        for t in thread_range:
            for r in rank_range:
                title = "Gradient_Time_Loss_Ratios_batch=%d_thread=%d_rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.xlabel("Time")
                plt.ylabel("Loss(hog)/Loss(cyc)")
                for s in sync_range:
                    for c in commands:
                        if c == hog_command:
                            continue
                        hog_times = gradient_time_values[hog_command][epoch_range][b][t][r][s]
                        cyc_times = gradient_time_values[c][epoch_range][b][t][r][s]
                        hog_losses = loss_values[hog_command][epoch_range][b][t][r][s]
                        cyc_losses = loss_values[c][epoch_range][b][t][r][s]
                        # Compute cyc losses -- the best loss cyc achieved by hog's time
                        cyc_losses_aligned = []
                        for i1, t1 in enumerate(hog_times):
                            best_loss = 1000000000
                            for i2, t2 in enumerate(cyc_times):
                                if t2 > t1:
                                    break
                                best_loss = min(best_loss, cyc_losses[i2])
                            cyc_losses_aligned.append(best_loss)
                        loss_ratio = [hog_losses[i] / cyc_losses_aligned[i] for i in range(len(hog_losses))]
                        plt.plot(hog_times, loss_ratio, label=c+" sync="+str(s))
                plt.legend(loc="upper right", fontsize=8)
                plt.savefig(title + ".png")
                plt.clf()

    for b in batch_size_range:
        for t in thread_range:
            for r in rank_range:
                title = "Overall_Time_Loss_Ratios_batch=%d_thread=%d_rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.xlabel("Time")
                plt.ylabel("Loss(hog)/Loss(cyc)")
                for s in sync_range:
                    for c in commands:
                        if hog_command == c:
                            continue
                        hog_times = overall_time_values[hog_command][epoch_range][b][t][r][s]
                        cyc_times = overall_time_values[c][epoch_range][b][t][r][s]
                        hog_losses = loss_values[hog_command][epoch_range][b][t][r][s]
                        cyc_losses = loss_values[c][epoch_range][b][t][r][s]
                        # Compute cyc losses -- the best loss cyc achieved by hog's time
                        cyc_losses_aligned = []
                        for i1, t1 in enumerate(hog_times):
                            best_loss = 1000000000
                            for i2, t2 in enumerate(cyc_times):
                                if t2 > t1:
                                    break
                                best_loss = min(best_loss, cyc_losses[i2])
                            cyc_losses_aligned.append(best_loss)
                        loss_ratio = [hog_losses[i] / cyc_losses_aligned[i] for i in range(len(hog_losses))]
                        plt.plot(hog_times, loss_ratio, label=c+" sync="+str(s))
                plt.legend(loc="upper right", fontsize=8)
                plt.savefig(title + ".png")
                plt.clf()

def draw_all_graphs(load_previous, epoch_range, batch_size_range, thread_range, rank_range,
                    sync_range, commands, average_over_n_rep):
    total_iter = len(epoch_range) * len(batch_size_range) * len(thread_range) * len(rank_range) * len(sync_range) * len(commands) * average_over_n_rep
    average_losses = tree()
    average_gradient_times = tree()
    average_total_times = tree()

    if not load_previous:
        cur_iter = 0
        # Collect all relevant data
        for epoch in epoch_range:
            for batch_size in batch_size_range:
                for thread in thread_range:
                    for rank in rank_range:
                        for sync in sync_range:
                            for command in commands:
                                avg_overall_time, avg_gradient_time, avg_loss = 0, 0, 0
                                for i in range(average_over_n_rep):
                                    print("Iteration %d of %d" % (cur_iter, total_iter))
                                    cur_iter += 1
                                    # Run command with all params
                                    output = run_command_with_params_and_get_output(command, ["N_EPOCHS="+str(epoch), "BATCH_SIZE="+str(batch_size), "NTHREAD="+str(thread), "RLENGTH="+str(rank), "SHOULD_SYNC="+str(sync)])

                                    # overall elapsed, gradient time, loss
                                    overall_time = float(output[0])
                                    gradient_time = float(output[1])
                                    loss = float(output[2])

                                    avg_overall_time += overall_time
                                    avg_gradient_time += gradient_time
                                    avg_loss += loss

                                avg_overall_time /= average_over_n_rep
                                avg_gradient_time /= average_over_n_rep
                                avg_loss /= average_over_n_rep

                                average_losses[command][epoch][batch_size][thread][rank][sync] = avg_loss
                                average_gradient_times[command][epoch][batch_size][thread][rank][sync] = avg_gradient_time
                                average_total_times[command][epoch][batch_size][thread][rank][sync] = avg_overall_time
    else:
        with open('epochs_data.pickle') as f:
            average_losses, average_gradient_times, average_total_times = pickle.load(f)

    with open('epochs_data.pickle', 'w') as f:
        pickle.dump([average_losses, average_gradient_times, average_total_times], f)

    """# Reminder: arrays of form [command][epoch][batch_size][thread][rank][sync]
                    plt.clf()"""
    for (time_data, label) in [(average_gradient_times, "Gradient Time"), (average_total_times, "Overall Time")]:
        for r in rank_range:
            for b in batch_size_range:
                f, plots = plt.subplots(1, len(thread_range), sharex=True, sharey=True)
                title = "Epoch_%s_Plot_Batch=%d_Rank=%d" % (label, b, r)
                f.suptitle(title, fontsize=12)
                for index, t in enumerate(thread_range):
                    plots[index].set_title("%d threads" % t)
                    for s in sync_range:
                        for c in commands:
                            plots[index].set_xlabel("Epoch")
                            plots[index].tick_params(axis='both', which='major', labelsize=5)
                            plots[index].tick_params(axis='both', which='minor', labelsize=5)
                            plots[index].set_ylabel(label)
                            times = get_values(time_data, [c], epoch_range, [b], [t], [r], [s])
                            epochs = epoch_range
                            low = min(times)
                            high = max(times)
                            if 'hog' in c:
                                plots[index].plot(epochs, times, label=c)
                            else:
                                plots[index].plot(epochs, times, label=c+" sync="+str(s))
                        #plots[index].set_ylim([math.ceil(low-0.5*(high-low)), math.ceil(high+0.5*(high-low))])
                    plots[index].legend(loc="upper left", fontsize=5)
            #f.subplots_adjust(hspace=0)
                f.tight_layout()
                f.subplots_adjust(top=.85)
                f.savefig(title+".png")
                f.clf()
    for (time_data, label) in [(average_gradient_times, "Gradient Time"), (average_total_times, "Overall Time")]:
        for r in rank_range:
            for b in batch_size_range:
                f, plots = plt.subplots(1, len(epoch_range), sharex=True, sharey=True)
                title = "Thread_%s_Plot_Batch=%d_Rank=%d" % (label, b, r)
                f.suptitle(title, fontsize=12)
                for index, e in enumerate(epoch_range):
                    plots[index].set_title("%d epoch" % e)
                    for s in sync_range:
                        for c in commands:
                            plots[index].tick_params(axis='both', which='major', labelsize=8)
                            plots[index].tick_params(axis='both', which='minor', labelsize=8)
                            plots[index].set_xlabel("Thread")
                            plots[index].set_ylabel(label)
                            times = get_values(time_data, [c], [e], [b], thread_range, [r], [s])
                            threads = thread_range
                            low = min(times)
                            high = max(times)
                            if 'hog' in c:
                                plots[index].plot(threads, times, label=c)
                            else:
                                plots[index].plot(threads, times, label=c+" sync="+str(s))
                        #plots[index].set_ylim([math.ceil(low-0.5*(high-low)), math.ceil(high+0.5*(high-low))])
                    plots[index].legend(loc="upper left", fontsize=5)
            #f.subplots_adjust(hspace=0)
                f.tight_layout()
                f.subplots_adjust(top=.85)
                f.savefig(title+".png")
                f.clf()

    ########################################
    # TIME RATIOS OVER 1 THREAD
    ########################################
    if 1 in thread_range:
        for r in rank_range:
            for b in batch_size_range:
                for e in epoch_range:
                    for s in sync_range:
                        for c in commands:
                            if 'hog' in c and not s:
                                continue
                            title = ""
                            if 'hog' in c:
                                title = "Overall_Speedup_Over_Serial_%s_Batch=%d_Epoch=%d_Rank=%d" % (c, b, e, r)
                            else:
                                title = "Overall_Speedup_Over_Serial_%s_Sync=%d_Batch=%d_Epoch=%d_Rank=%d" % (c, s, b, e, r)
                            plt.figure()
                            plt.title(title, fontsize=12)
                            plt.ylabel("Serial_Time/Time_With_N_Threads")
                            plt.xlabel("N")
                            base_time = average_total_times[c][e][b][1][r][s]
                            time_values = get_values(average_total_times, [c], [e], [b], thread_range, [r], [s])
                            time_ratios = [float(base_time)/x for x in time_values]
                            plt.plot(thread_range, time_ratios)
                            plt.legend(loc="upper left", fontsize=5)
                            plt.savefig(title+".png")
                            plt.clf()
        for r in rank_range:
            for b in batch_size_range:
                for e in epoch_range:
                    for s in sync_range:
                        for c in commands:
                            if 'hog' in c and not s:
                                continue
                            title = ""
                            if 'hog' in c:
                                title = "Gradient_Speedup_Over_Serial_%s_Batch=%d_Epoch=%d_Rank=%d" % (c, b, e, r)
                            else:
                                title = "Gradient_Speedup_Over_Serial_%s_Sync=%d_Batch=%d_Epoch=%d_Rank=%d" % (c, s, b, e, r)
                            plt.figure()
                            plt.title(title, fontsize=12)
                            plt.ylabel("Serial_Time/Time_With_N_Threads")
                            plt.xlabel("N")
                            base_time = average_gradient_times[c][e][b][1][r][s]
                            time_values = get_values(average_total_times, [c], [e], [b], thread_range, [r], [s])
                            time_ratios = [float(base_time)/x for x in time_values]
                            plt.plot(thread_range, time_ratios)
                            plt.legend(loc="upper left", fontsize=5)
                            plt.savefig(title+".png")
                            plt.clf()

    ########################################
    # TIME RATIOS OVER HOG PER EPOCH
    ########################################
    hog_command = [x for x in commands if 'hog' in x][0]
    for t in thread_range:
        for r in rank_range:
            for b in batch_size_range:
                title = "Overall_Time_Ratios_Over_Hog_Per_Epoch_Batch=%d_Thread=%d_Rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.ylabel("Hog Time / Cyclades Time")
                plt.xlabel("Epoch")
                for s in sync_range:
                    for c in commands:
                        if 'hog' not in c:
                            baseline_hog_times = get_values(average_total_times, [hog_command], epoch_range, [b], [t], [r], [s])
                            times = get_values(average_total_times, [c], epoch_range, [b], [t], [r], [s])
                            ratio_times = [float(baseline_hog_times[i]) / float(times[i]) for i in range(len(times))]
                            plt.plot(epoch_range, ratio_times, label=c+"_sync="+str(s))
                plt.legend(loc="upper left", fontsize=5)
                plt.savefig(title+".png")
                plt.clf()

    hog_command = [x for x in commands if 'hog' in x][0]
    for t in thread_range:
        for r in rank_range:
            for b in batch_size_range:
                title = "Gradient_Time_Ratios_Over_Hog_Per_Epoch_Batch=%d_Thread=%d_Rank=%d" % (b, t, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.ylabel("Hog Time / Cyclades Time")
                plt.xlabel("Epoch")
                for s in sync_range:
                    for c in commands:
                        if 'hog' not in c:
                            baseline_hog_times = get_values(average_total_times, [hog_command], epoch_range, [b], [t], [r], [s])
                            times = get_values(average_gradient_times, [c], epoch_range, [b], [t], [r], [s])
                            ratio_times = [float(baseline_hog_times[i]) / float(times[i]) for i in range(len(times))]
                            plt.plot(epoch_range, ratio_times, label=c+"_sync="+str(s))
                plt.legend(loc="upper left", fontsize=5)
                plt.savefig(title+".png")
                plt.clf()

    #####################################
    # TIME RATIOS OVER HOG PER THREAD
    #####################################
    for e in epoch_range:
        for r in rank_range:
            for b in batch_size_range:
                title = "Overall_Time_Ratios_Over_Hog_Per_Thread_Batch=%d_Epoch=%d_Rank=%d" % (b, e, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.ylabel("Hog Time / Cyclades Time")
                plt.xlabel("Thread")
                for s in sync_range:
                    for c in commands:
                        if 'hog' not in c:
                            baseline_hog_times = get_values(average_total_times, [hog_command], [e], [b], thread_range, [r], [s])
                            times = get_values(average_total_times, [c], [e], [b], thread_range, [r], [s])
                            ratio_times = [float(baseline_hog_times[i]) / float(times[i]) for i in range(len(times))]
                            plt.plot(thread_range, ratio_times, label=c+"_sync="+str(s))
                plt.legend(loc="upper left", fontsize=5)
                plt.savefig(title+".png")
                plt.clf()

    for e in epoch_range:
        for r in rank_range:
            for b in batch_size_range:
                title = "Gradient_Time_Ratios_Over_Hog_Per_Thread_Batch=%d_Epoch=%d_Rank=%d" % (b, e, r)
                plt.figure()
                plt.title(title, fontsize=12)
                plt.ylabel("Hog Time / Cyclades Time")
                plt.xlabel("Thread")
                for s in sync_range:
                    for c in commands:
                        if 'hog' not in c:
                            baseline_hog_times = get_values(average_total_times, [hog_command], [e], [b], thread_range, [r], [s])
                            times = get_values(average_gradient_times, [c], [e], [b], thread_range, [r], [s])
                            ratio_times = [float(baseline_hog_times[i]) / float(times[i]) for i in range(len(times))]
                            plt.plot(thread_range, ratio_times, label=c+"_sync="+str(s))
                plt.legend(loc="upper left", fontsize=5)
                plt.savefig(title+".png")
                plt.clf()

#draw_all_graphs(0, [10, 30, 80, 100, 150], [2000], [1, 2, 4, 8, 10, 16, 32], [200], [0, 1], ["cyc_movielens_cyc", "cyc_movielens_hog"], 2)
#draw_time_loss_graph(0, 150, [2000], [2, 4, 8, 10, 16], [200], [0, 1], ["cyc_movielens_cyc", "cyc_movielens_hog"])

#W/o regularization
#draw_all_graphs(0, 200, [5000], [1, 4, 8, 16, 32], [100, 200], [1], ["cyc_movielens_cyc", "cyc_movielens_hog"], 3)
draw_time_loss_graph(0, 200, [5000], [1, 4, 8, 16, 32], [100, 200], [1], ["cyc_movielens_cyc", "cyc_movielens_hog"], 3)
#draw_time_loss_graph(0, 200, [5000], [8], [10], [1], ["cyc_movielens_cyc", "cyc_movielens_hog"], 3)

# W/ regularization
#draw_all_graphs(0, [50, 100, 150, 200], [5000], [1, 4, 8, 16, 32], [100, 200], [1], ["cyc_movielens_cyc_regularize", "cyc_movielens_hog_regularize"], 2)
#draw_time_loss_graph(0, 200, [5000], [1, 4, 8, 16, 32], [100, 200], [1], ["cyc_movielens_cyc_regularize", "cyc_movielens_hog_regularize"])


text:
package org.apache.commons.jcs3.utils.discovery;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Objects;

/**
 * This contains info about a discovered service. These objects are stored in a set in the
 * UDPDiscoveryService.
 */
public class DiscoveredService
    implements Serializable
{
    /** For serialization. Don't change. */
    private static final long serialVersionUID = -7810164772089509751L;

    /** region names */
    private ArrayList<String> cacheNames;

    /** service address */
    private String serviceAddress;

    /** service port */
    private int servicePort;

    /** last time we heard from this service? */
    private long lastHearFromTime;

    /**
     * Default constructor
     */
    public DiscoveredService()
    {
        // empty
    }

    /**
     * Constructor
     *
     * @param message incoming message
     * @since 3.1
     */
    public DiscoveredService(UDPDiscoveryMessage message)
    {
        setServiceAddress( message.getHost() );
        setCacheNames( message.getCacheNames() );
        setServicePort( message.getPort() );
        setLastHearFromTime( System.currentTimeMillis() );
    }

    /**
     * @param cacheNames the cacheNames to set
     */
    public void setCacheNames( final ArrayList<String> cacheNames )
    {
        this.cacheNames = cacheNames;
    }

    /**
     * @return the cacheNames
     */
    public ArrayList<String> getCacheNames()
    {
        return cacheNames;
    }

    /**
     * @param serviceAddress The serviceAddress to set.
     */
    public void setServiceAddress( final String serviceAddress )
    {
        this.serviceAddress = serviceAddress;
    }

    /**
     * @return Returns the serviceAddress.
     */
    public String getServiceAddress()
    {
        return serviceAddress;
    }

    /**
     * @param servicePort The servicePort to set.
     */
    public void setServicePort( final int servicePort )
    {
        this.servicePort = servicePort;
    }

    /**
     * @return Returns the servicePort.
     */
    public int getServicePort()
    {
        return servicePort;
    }

    /**
     * @param lastHearFromTime The lastHearFromTime to set.
     */
    public void setLastHearFromTime( final long lastHearFromTime )
    {
        this.lastHearFromTime = lastHearFromTime;
    }

    /**
     * @return Returns the lastHearFromTime.
     */
    public long getLastHearFromTime()
    {
        return lastHearFromTime;
    }

    /** @return hashcode based on address/port */
	@Override
	public int hashCode()
	{
		return Objects.hash(serviceAddress, servicePort);
	}

	/**
     * NOTE - this object is often put into sets, so equals needs to be overridden.
     *

     * We can't use cache names as part of the equals unless we manually only use the address and
     * port in a contains check. So that we can use normal set functionality, I've kept the cache
     * names out.
     *

     * @param otherArg other
     * @return equality based on the address/port
     */
	@Override
	public boolean equals(final Object otherArg)
	{
		if (this == otherArg)
		{
			return true;
		}
		if (otherArg == null)
		{
			return false;
		}
		if (!(otherArg instanceof DiscoveredService))
		{
			return false;
		}
		final DiscoveredService other = (DiscoveredService) otherArg;
		if (!Objects.equals(serviceAddress, other.serviceAddress))
		{
			return false;
		}
        return servicePort == other.servicePort;
    }

    /**
     * @return string for debugging purposes.
     */
    @Override
    public String toString()
    {
        final StringBuilder buf = new StringBuilder();
        buf.append( "\n DiscoveredService" );
        buf.append( "\n CacheNames = [" + getCacheNames() + "]" );
        buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" );
        buf.append( "\n ServicePort = [" + getServicePort() + "]" );
        buf.append( "\n LastHearFromTime = [" + getLastHearFromTime() + "]" );
        return buf.toString();
    }
}


text:
Settings

Add

Preview

Background

Page

Headline

Text

Image

Button


text:
using System.Collections.Generic;

namespace Stratageme15.Core.JavascriptCodeDom
{
    internal static class DictionaryExtensions
    {
        internal static TKey GetKeyByValue<TKey, TValue>(this Dictionary<TKey, TValue> dict, TValue value)
        {
            foreach (var kv in dict)
            {
                if (kv.Value.Equals(value)) return kv.Key;
            }
            throw new KeyNotFoundException(value.ToString());
        }
    }
    public class OperatorConverter
    {
        private static Dictionary<string, AssignmentOperator> AssignmentOperator =
            new Dictionary<string, AssignmentOperator>
                    {
                        { "=",JavascriptCodeDom.AssignmentOperator.Set},
                        { "+=", JavascriptCodeDom.AssignmentOperator.PlusSet},
                        { "-=", JavascriptCodeDom.AssignmentOperator.MinusSet},
                        { "*=", JavascriptCodeDom.AssignmentOperator.MulSet},
                        { "/=", JavascriptCodeDom.AssignmentOperator.DivSet},
                        { "<<=", JavascriptCodeDom.AssignmentOperator.LeftShiftSet},
                        { ">>=", JavascriptCodeDom.AssignmentOperator.RightShiftSet},
                        { ">>>=", JavascriptCodeDom.AssignmentOperator.UnnsignedRightShiftSet},
                        { "%=", JavascriptCodeDom.AssignmentOperator.ModSet},
                        { "|=", JavascriptCodeDom.AssignmentOperator.OrSet},
                        { "&=", JavascriptCodeDom.AssignmentOperator.AndSet},
                        { "^=", JavascriptCodeDom.AssignmentOperator.XorSet}

                    };

        private static Dictionary<string, UnaryOperator> UnaryOperator =
            new Dictionary<string, UnaryOperator>
                    {
                        { "+", JavascriptCodeDom.UnaryOperator.Plus},
                        { "-", JavascriptCodeDom.UnaryOperator.Minus},
                        { "~", JavascriptCodeDom.UnaryOperator.BitwiseNot},
                        { "!", JavascriptCodeDom.UnaryOperator.LogicalNot},
                        { "++", JavascriptCodeDom.UnaryOperator.Increment},
                        { "--", JavascriptCodeDom.UnaryOperator.Decrement}
                    };
        private static Dictionary<string, IndrementDecrementOperator> IndrementDecrementOperator =
            new Dictionary<string, IndrementDecrementOperator>
                {
                    {"++",JavascriptCodeDom.IndrementDecrementOperator.Increment},
                    {"--",JavascriptCodeDom.IndrementDecrementOperator.Decrement}
                }
            ;
        private static Dictionary<string, MathOperator> MathOperator =
            new Dictionary<string, MathOperator>
                    {
                        { "+", JavascriptCodeDom.MathOperator.Plus},
                        { "-", JavascriptCodeDom.MathOperator.Minus},
                        { "/", JavascriptCodeDom.MathOperator.Div},
                        { "*", JavascriptCodeDom.MathOperator.Mul},
                        { "%", JavascriptCodeDom.MathOperator.Mod}
                    };

        private static Dictionary<string, LogicalOperator> LogicalOperator =
            new Dictionary<string, LogicalOperator>
                    {
                        {"||",JavascriptCodeDom.LogicalOperator.Or},
                        {"&&",JavascriptCodeDom.LogicalOperator.And},
                        {"in",JavascriptCodeDom.LogicalOperator.In},
                        {"instanceof",JavascriptCodeDom.LogicalOperator.Instanceof}
                    };

        private static Dictionary<string, BitwiseOperator> BitwiseOperator =
            new Dictionary<string, BitwiseOperator>
                    {
                        {"&",JavascriptCodeDom.BitwiseOperator.And},
                        {"|",JavascriptCodeDom.BitwiseOperator.Or},
                        {"^",JavascriptCodeDom.BitwiseOperator.Xor},
                        {"<<",JavascriptCodeDom.BitwiseOperator.LeftShift},
                        {">>",JavascriptCodeDom.BitwiseOperator.RightShift},
                        {">>>",JavascriptCodeDom.BitwiseOperator.UnsignedRightShift}
                    };

        private static Dictionary<string, ComparisonOperator> ComparisonOperator =
            new Dictionary<string, ComparisonOperator>
                    {
                        { "<", JavascriptCodeDom.ComparisonOperator.Less},
                        { ">", JavascriptCodeDom.ComparisonOperator.More},
                        { "<=", JavascriptCodeDom.ComparisonOperator.LessOrEqual},
                        { ">=", JavascriptCodeDom.ComparisonOperator.MoreOrEqual},
                        { "!=", JavascriptCodeDom.ComparisonOperator.NotEqual},
                        { "==", JavascriptCodeDom.ComparisonOperator.Equal},
                        { "===", JavascriptCodeDom.ComparisonOperator.TypeEqual},
                        { "!==", JavascriptCodeDom.ComparisonOperator.TypeNotEqual}
                    };

        public static string OperatorString(BitwiseOperator op)
        {
            return BitwiseOperator.GetKeyByValue(op);
        }

        public static string OperatorString(ComparisonOperator op)
        {
            return ComparisonOperator.GetKeyByValue(op);
        }

        public static string OperatorString(LogicalOperator op)
        {
            return LogicalOperator.GetKeyByValue(op);
        }

        public static string OperatorString(MathOperator op)
        {
            return MathOperator.GetKeyByValue(op);
        }

        public static string OperatorString(UnaryOperator op)
        {
            return UnaryOperator.GetKeyByValue(op);
        }

        public static string OperatorString(AssignmentOperator op)
        {
            return AssignmentOperator.GetKeyByValue(op);
        }

        public static string OperatorString(IndrementDecrementOperator op)
        {
            return IndrementDecrementOperator.GetKeyByValue(op);
        }

        public static BitwiseOperator GetBitwiseOperator(string op)
        {
            return BitwiseOperator[op];
        }
        public static AssignmentOperator GetAssignmentOperator(string op)
        {
            return AssignmentOperator[op];
        }
        public static UnaryOperator GetUnaryOperator(string op)
        {
            return UnaryOperator[op];
        }
        public static MathOperator GetMathOperator(string op)
        {
            return MathOperator[op];
        }
        public static LogicalOperator GetLogicalOperator(string op)
        {
            return LogicalOperator[op];
        }
        public static ComparisonOperator GetComparisonOperator(string op)
        {
            return ComparisonOperator[op];
        }

        public static IndrementDecrementOperator GetIndrementDecrementOperator(string op)
        {
            return IndrementDecrementOperator[op];
        }
    }
}


text:
import * as React from 'react';
import { GlobalStyles } from '@mui/system';
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
import type { Theme } from '@mui/joy/styles';
import Box from '@mui/joy/Box';
import Typography from '@mui/joy/Typography';
import TextField from '@mui/joy/TextField';
import IconButton from '@mui/joy/IconButton';

// Icons import
import SearchRoundedIcon from '@mui/icons-material/SearchRounded';
import DarkModeRoundedIcon from '@mui/icons-material/DarkModeRounded';
import LightModeRoundedIcon from '@mui/icons-material/LightModeRounded';
import GridViewRoundedIcon from '@mui/icons-material/GridViewRounded';
import MailRoundedIcon from '@mui/icons-material/MailRounded';
import KeyboardArrowDownRoundedIcon from '@mui/icons-material/KeyboardArrowDownRounded';
import MenuIcon from '@mui/icons-material/Menu';
import BookRoundedIcon from '@mui/icons-material/BookRounded';

// custom
import emailTheme from './theme';
import Menu from './components/Menu';
import Layout from './components/Layout';
import Navigation from './components/Navigation';
import Mails from './components/Mails';
import MailContent from './components/MailContent';

const ColorSchemeToggle = () => {
  const { mode, setMode } = useColorScheme();
  const [mounted, setMounted] = React.useState(false);
  React.useEffect(() => {
    setMounted(true);
  }, []);
  if (!mounted) {
    return <IconButton size="sm" variant="outlined" color="primary" />;
  }
  return (
    <IconButton
      id="toggle-mode"
      size="sm"
      variant="outlined"
      color="primary"
      onClick={() => {
        if (mode === 'light') {
          setMode('dark');
        } else {
          setMode('light');
        }
      }}
    >
      {mode === 'light' ? <DarkModeRoundedIcon /> : <LightModeRoundedIcon />}
    </IconButton>
  );
};

export default function EmailExample() {
  const [drawerOpen, setDrawerOpen] = React.useState(false);
  return (
    <CssVarsProvider disableTransitionOnChange theme={emailTheme}>
      <GlobalStyles<Theme>
        styles={(theme) => ({
          body: {
            margin: 0,
            fontFamily: theme.vars.fontFamily.body,
          },
        })}
      />
      {drawerOpen && (
        <Layout.SideDrawer onClose={() => setDrawerOpen(false)}>
          <Navigation />
        </Layout.SideDrawer>
      )}
      <Layout.Root
        sx={{
          ...(drawerOpen && {
            height: '100vh',
            overflow: 'hidden',
          }),
        }}
      >
        <Layout.Header>
          <Box
            sx={{
              display: 'flex',
              flexDirection: 'row',
              alignItems: 'center',
              gap: 1.5,
            }}
          >
            <IconButton
              variant="outlined"
              size="sm"
              onClick={() => setDrawerOpen(true)}
              sx={{ display: { sm: 'none' } }}
            >
              <MenuIcon />
            </IconButton>
            <IconButton
              size="sm"
              variant="solid"
              sx={{ display: { xs: 'none', sm: 'inline-flex' } }}
            >
              <MailRoundedIcon />
            </IconButton>
            <Typography fontWeight={700}>Email</Typography>
          </Box>
          <TextField
            size="sm"
            placeholder="Search anything..."
            startDecorator={<SearchRoundedIcon color="primary" />}
            endDecorator={
              <IconButton variant="outlined" size="sm" color="neutral">
                <Typography fontWeight="lg" fontSize="sm" textColor="text.tertiary">
                  /
                </Typography>
              </IconButton>
            }
            sx={{
              flexBasis: '500px',
              display: {
                xs: 'none',
                sm: 'flex',
              },
            }}
          />
          <Box sx={{ display: 'flex', flexDirection: 'row', gap: 1.5 }}>
            <IconButton
              size="sm"
              variant="outlined"
              color="primary"
              sx={{ display: { xs: 'inline-flex', sm: 'none' } }}
            >
              <SearchRoundedIcon />
            </IconButton>
            <IconButton
              size="sm"
              variant="outlined"
              color="primary"
              component="a"
              href="/blog/first-look-at-joy/"
            >
              <BookRoundedIcon />
            </IconButton>
            <Menu
              id="app-selector"
              control={
                <IconButton
                  size="sm"
                  variant="outlined"
                  color="primary"
                  aria-label="Apps"
                >
                  <GridViewRoundedIcon />
                </IconButton>
              }
              menus={[
                {
                  label: 'Email',
                  active: true,
                  href: '/joy-ui/getting-started/templates/email/',
                  'aria-current': 'page',
                },
                {
                  label: 'Team',
                  href: '/joy-ui/getting-started/templates/team/',
                },
                {
                  label: 'Files',
                  href: '/joy-ui/getting-started/templates/files/',
                },
              ]}
            />
            <ColorSchemeToggle />
          </Box>
        </Layout.Header>
        <Layout.SideNav>
          <Navigation />
        </Layout.SideNav>
        <Layout.SidePane>
          <Box
            sx={{
              p: 2,
              mb: 1,
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'space-between',
            }}
          >
            <Typography
              textColor="neutral.500"
              fontWeight={700}
              sx={{
                fontSize: '10px',
                textTransform: 'uppercase',
                letterSpacing: '.1rem',
              }}
            >
              Unread
            </Typography>
            <IconButton
              size="sm"
              variant="plain"
              color="primary"
              sx={{ '--IconButton-size': '24px' }}
            >
              <KeyboardArrowDownRoundedIcon fontSize="small" color="primary" />
            </IconButton>
          </Box>
          <Box sx={{ py: 10 }}>
            <Typography
              textColor="text.tertiary"
              level="body2"
              sx={{ textAlign: 'center' }}
            >
              You've read all messages in your inbox.
            </Typography>
          </Box>
          <Box
            sx={{
              p: 2,
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'space-between',
            }}
          >
            <Typography
              textColor="neutral.500"
              fontWeight={700}
              sx={{
                fontSize: '10px',
                textTransform: 'uppercase',
                letterSpacing: '.1rem',
              }}
            >
              Everything else
            </Typography>
            <IconButton
              size="sm"
              variant="plain"
              color="primary"
              sx={{ '--IconButton-size': '24px' }}
            >
              <KeyboardArrowDownRoundedIcon fontSize="small" color="primary" />
            </IconButton>
          </Box>
          <Mails />
        </Layout.SidePane>
        <Layout.Main>
          <MailContent />
        </Layout.Main>
      </Layout.Root>
    </CssVarsProvider>
  );
}


text:
package client

import (
	"context"
	"flag"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/google/subcommands"
)

type routesPutCommand struct{}

func (c routesPutCommand) SetFlags(f *flag.FlagSet) {}

func (c routesPutCommand) Execute(ctx context.Context, f *flag.FlagSet) subcommands.ExitStatus {
	args := f.Args()
	infile := os.Stdin

	switch len(args) {
	case 2:
		g, err := os.Open(args[1])
		if err != nil {
			return handleError(err)
		}
		defer g.Close()
		infile = g
	case 1:
		// ok
	default:
		f.Usage()
		return subcommands.ExitUsageError
	}
	id := args[0]

	data, err := ioutil.ReadAll(infile)
	if err != nil {
		return handleError(err)
	}

	_, err = Call(ctx, "PUT", "/routes/"+id, data)
	if err == nil {
		fmt.Println("success")
	}
	return handleError(err)
}

// RoutesPutCommand implements "routes put" subcommand.
func RoutesPutCommand() subcommands.Command {
	return subcmd{
		routesPutCommand{},
		"put",
		"add or update a route",
		`put ID [FILENAME]:

    Create a new route with ID, or edit the existing route matching ID.
    If FILENAME is given, it should be a JSON file.  If FILENAME is not
    given, JSON will be read from stdin.

The JSON must be an array of objects.  Each object must have "type"
field that speficies the type of transport such as "email" or "slack".

An example JSON may look like:

[
    {
        "type": "email",
        "from": "kkok@example.org",
        "to": ["ymmt2005@example.org"]
    },
    {
        "type": "slack",
        "url": "https://hooks.slack.com/xxxxxxx"
    }
]
`}
}


text:
hello

Welcome to SurveyMe. Give your feedback and get rewards ... instantly!

    Take a survey
    Find rewards

    My rewards wallet4


text:
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'yaml'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'music_xray_api'

class Test::Unit::TestCase

  #YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
end


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

/**
 * @fileoverview Unit tests for the PlaythroughObjectFactory.
 */

describe('Playthrough Object Factory', function() {
  beforeEach(module('oppia'));

  beforeEach(inject(function($injector) {
    this.pof = $injector.get('PlaythroughObjectFactory');
    this.laof = $injector.get('LearnerActionObjectFactory');
  }));

  it('should create a new playthrough', function() {
    var actions = [this.laof.createNew('AnswerSubmit', {}, 1)];
    var playthroughObject = this.pof.createNew(
      'playthroughId1', 'expId1', 1, 'EarlyQuit', {}, actions);

    expect(playthroughObject.playthroughId).toEqual('playthroughId1');
    expect(playthroughObject.expId).toEqual('expId1');
    expect(playthroughObject.expVersion).toEqual(1);
    expect(playthroughObject.issueType).toEqual('EarlyQuit');
    expect(playthroughObject.issueCustomizationArgs).toEqual({});
    expect(playthroughObject.actions).toEqual(actions);
  });

  it('should create a new playthrough from a backend dict', function() {
    var playthroughObject = this.pof.createFromBackendDict(
      {
        playthrough_id: 'playthroughId1',
        exp_id: 'expId1',
        exp_version: 1,
        issue_type: 'EarlyQuit',
        issue_customization_args: {},
        actions: [{
          action_type: 'AnswerSubmit',
          action_customization_args: {},
          schema_version: 1
        }]
      }
    );

    expect(playthroughObject.playthroughId).toEqual('playthroughId1');
    expect(playthroughObject.expId).toEqual('expId1');
    expect(playthroughObject.expVersion).toEqual(1);
    expect(playthroughObject.issueType).toEqual('EarlyQuit');
    expect(playthroughObject.issueCustomizationArgs).toEqual({});
    expect(playthroughObject.actions).toEqual([this.laof.createNew(
      'AnswerSubmit', {}, 1)]);
  });

  it('should convert a playthrough to a backend dict', function() {
    var actions = [this.laof.createNew('AnswerSubmit', {}, 1)];
    var playthroughObject = this.pof.createNew(
      'playthroughId1', 'expId1', 1, 'EarlyQuit', {}, actions);

    var playthroughDict = playthroughObject.toBackendDict();
    expect(playthroughDict).toEqual({
      id: 'playthroughId1',
      exp_id: 'expId1',
      exp_version: 1,
      issue_type: 'EarlyQuit',
      issue_customization_args: {},
      actions: [{
        action_type: 'AnswerSubmit',
        action_customization_args: {},
        schema_version: 1
      }]
    });
  });
});


text:
/**
 * Client connection socket APIs.
 */
package org.apache.hc.client5.http.socket;


text:
<?php
namespace Liuwen\Alipay\Request;

/**
 * ALIPAY API: alipay.acquire.refund request
 *
 * @author auto create
 * @since 1.0, 2014-06-12 17:17:03
 */
class AlipayAcquireRefundRequest
{
	/**
	 * 卖家的操作员ID。
	 **/
	private $operatorId;

	/**
	 * 操作员的类型:
0:支付宝操作员
1:商户的操作员
如果传入其它值或者为空,则默认设置为1。
	 **/
	private $operatorType;

	/**
	 * 商户退款请求单号,用以标识本次交易的退款请求。
如果不传入本参数,则以out_trade_no填充本参数的值。同时,认为本次请求为全额退款,要求退款金额和交易支付金额一致。
	 **/
	private $outRequestNo;

	/**
	 * 商户网站唯一订单号
	 **/
	private $outTradeNo;

	/**
	 * 业务关联ID集合,用于放置商户的退款单号、退款流水号等信息,json格式
	 **/
	private $refIds;

	/**
	 * 退款金额;退款金额不能大于订单金额,全额退款必须与订单金额一致。
	 **/
	private $refundAmount;

	/**
	 * 退款原因说明。
	 **/
	private $refundReason;

	/**
	 * 该交易在支付宝系统中的交易流水号。
最短16位,最长64位。
如果同时传了out_trade_no和trade_no,则以trade_no为准
	 **/
	private $tradeNo;

	private $apiParas = array();
	private $terminalType;
	private $terminalInfo;
	private $prodCode;
	private $apiVersion="1.0";
	private $notifyUrl;
	private $returnUrl;
    private $needEncrypt=false;

	public function setOperatorId($operatorId)
	{
		$this->operatorId = $operatorId;
		$this->apiParas["operator_id"] = $operatorId;
	}

	public function getOperatorId()
	{
		return $this->operatorId;
	}

	public function setOperatorType($operatorType)
	{
		$this->operatorType = $operatorType;
		$this->apiParas["operator_type"] = $operatorType;
	}

	public function getOperatorType()
	{
		return $this->operatorType;
	}

	public function setOutRequestNo($outRequestNo)
	{
		$this->outRequestNo = $outRequestNo;
		$this->apiParas["out_request_no"] = $outRequestNo;
	}

	public function getOutRequestNo()
	{
		return $this->outRequestNo;
	}

	public function setOutTradeNo($outTradeNo)
	{
		$this->outTradeNo = $outTradeNo;
		$this->apiParas["out_trade_no"] = $outTradeNo;
	}

	public function getOutTradeNo()
	{
		return $this->outTradeNo;
	}

	public function setRefIds($refIds)
	{
		$this->refIds = $refIds;
		$this->apiParas["ref_ids"] = $refIds;
	}

	public function getRefIds()
	{
		return $this->refIds;
	}

	public function setRefundAmount($refundAmount)
	{
		$this->refundAmount = $refundAmount;
		$this->apiParas["refund_amount"] = $refundAmount;
	}

	public function getRefundAmount()
	{
		return $this->refundAmount;
	}

	public function setRefundReason($refundReason)
	{
		$this->refundReason = $refundReason;
		$this->apiParas["refund_reason"] = $refundReason;
	}

	public function getRefundReason()
	{
		return $this->refundReason;
	}

	public function setTradeNo($tradeNo)
	{
		$this->tradeNo = $tradeNo;
		$this->apiParas["trade_no"] = $tradeNo;
	}

	public function getTradeNo()
	{
		return $this->tradeNo;
	}

	public function getApiMethodName()
	{
		return "alipay.acquire.refund";
	}

	public function setNotifyUrl($notifyUrl)
	{
		$this->notifyUrl=$notifyUrl;
	}

	public function getNotifyUrl()
	{
		return $this->notifyUrl;
	}

	public function setReturnUrl($returnUrl)
	{
		$this->returnUrl=$returnUrl;
	}

	public function getReturnUrl()
	{
		return $this->returnUrl;
	}

	public function getApiParas()
	{
		return $this->apiParas;
	}

	public function getTerminalType()
	{
		return $this->terminalType;
	}

	public function setTerminalType($terminalType)
	{
		$this->terminalType = $terminalType;
	}

	public function getTerminalInfo()
	{
		return $this->terminalInfo;
	}

	public function setTerminalInfo($terminalInfo)
	{
		$this->terminalInfo = $terminalInfo;
	}

	public function getProdCode()
	{
		return $this->prodCode;
	}

	public function setProdCode($prodCode)
	{
		$this->prodCode = $prodCode;
	}

	public function setApiVersion($apiVersion)
	{
		$this->apiVersion=$apiVersion;
	}

	public function getApiVersion()
	{
		return $this->apiVersion;
	}

  public function setNeedEncrypt($needEncrypt)
  {

     $this->needEncrypt=$needEncrypt;

  }

  public function getNeedEncrypt()
  {
    return $this->needEncrypt;
  }

}


text:
				   	      <button type="button" class="navbar-toggle" data-toggle="collapse"  data-target="#example-navbar-collapse">

					      </button>

						 	{{ site.title }}

分类

归档

关于

						  	<input type="text" class="search-query st-default-search-input" placeholder="Search">

 首页

 分类

 标签

 归档

 关于


text:
@interface PodsDummy_NVDSP : NSObject
@end
@implementation PodsDummy_NVDSP
@end


text:
This repository contains old, deprecated extension to Server Farmer.

## History of New Relic support in Server Farmer

### 2012-2015

New Relic was used by Server Farmer authors since around 2012-13 - in fact, we were its early adopters in Allegro.pl (of paid version, at larger scale). We even got a few [T-shirts](https://newrelic.com/blog/nerd-life/how-many-t-shirts-has-new-relic-given-out-in-the-last-2-years) from them :)

We were so satisfied of their services, that we also wanted to implement them (this time in free version) as an automated service discovery, monitoring and alerting platform for our side customers.

Initial implementations for particular customers were made in 2013 - and the final, universal implementation in Server Farmer, meeting its code quality and separation from customer-specific stuff, was finished around 2014-15.

We also created a few New Relic Plugins, integrated with Server Farmer:

- for monitoring hard drive SMART metrics
- for moniroring MySQL server metrics (using [New Relic Platform MySQL Plugin - Java](https://github.com/newrelic/newrelic_mysql_java_plugin))
- for monitoring [backup collectors](https://github.com/serverfarmer/sm-backup-collector) and alerting about backup failures
- for visualizing [Pastebin.com](https://pastebin.com/) public paste volume (this integration was private)

### 2017-2018

In 2017 we had New Relic Servers (now referred as the "old" platform), with basic alerting, enabled on **over 1000 hosts**:

- for many various customers
- using many separate New Relic accounts (our own + per customer)
- with completely different alerting policies and integrations for each customer
- for Linux and Windows
- 100% free (with 1 exception: 1 customer paid for 2 hosts for 1 month, to solve a particular problem with MySQL)

Unfortunately, in 2017, after gaining a sufficiently large group of paid clients, New Relic started to cut down their really-free services and replacing them with either 30-day free trials, or (later) services with limited free volume. It was first announced here, and our protests were completely ignored:

https://discuss.newrelic.com/t/important-upcoming-changes-for-new-relic-servers-and-legacy-alerting-features/49474

### Our reaction

We decided to replace New Relic Servers with combination of 3 separate services:

1. Heartbeat subproject (implementation finished in 2018) - for [service discovery](https://github.com/serverfarmer/heartbeat-linux), and [heartbeat service](https://github.com/serverfarmer/heartbeat-server) itself. So each server reports to Heartbeat every 2 minutes, which services were detected to be alive.

2. Any internal or external monitoring service (possibly separate for each customer) - to query Heartbeat server and send email/push/Slack/Teams alerts about dead services. We choosed [UptimeRobot](https://uptimerobot.com/), since back then, it was almost 10x cheaper than competing [StatusCake](https://www.statuscake.com/) and [Pingdom](https://www.pingdom.com/) (at least for bigger plans), while having enough quality.

3. [Cacti](https://www.cacti.net/) for recording metrics, where it was really required.

We also decided to drop most raw metrics and convert them to simple boolean alive/dead statuses on-the-fly in Heartbeat - eg. a hard drive either meets basic quality requirements, or not (see [the details](https://github.com/serverfarmer/heartbeat-linux#smart-monitoring-details)).

At that time, we didn't touch New Relic Plugins.

### 2019-2021

In early 2021, New Relic made another announcement, about New Relic Plugins:

https://discuss.newrelic.com/t/new-relic-plugin-eol-wednesday-june-16th-2021/127267

Fortunately, we managed to migrate all remaining monitoring services from New Relic to other platforms yet in 2019, so it didn't affect our customers at all.

### 2022

In 2022, as a part of the new roadmap for Server Farmer, we plan to finally remove several features deprecated in past years, including anything related to New Relic.


text:
This Python-script integrates the old rotary dial and handset on the
AS Elektrisk Bureau pulse phone to use SIP.

It uses GPIO on Raspberry Pi to communicate with the rotary dial, and
the onboard soundcard for ringtone. An USB-soundcard is used for mic
and handset audio.

Some configuration on the Raspberry Pi is needed to make everything work,
including installing the dependencies and configuring PulseAudio and ALSA
to enable software mixing of sounds.

Linphone (linphonec for console) is also required because it handles the
SIP-connection.

There is some code to use Pjsip, but it's not finished.

For more information on the build, see http://imgur.com/a/HECDL/.

![Phone](phone.jpg)


text:
package betterwithmods.module.hardcore.world;

import betterwithmods.api.util.IWood;
import betterwithmods.common.BWMBlocks;
import betterwithmods.common.BWMItems;
import betterwithmods.common.BWOreDictionary;
import betterwithmods.module.Feature;
import betterwithmods.util.item.ToolsManager;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import javax.annotation.Nullable;
import java.util.Set;

/**
 * Created by primetoxinz on 4/20/17.
 */
public class HCStumping extends Feature {

    public static boolean SPEED_UP_WITH_TOOLS;
    public static float STUMP_BREAK_SPEED;
    public static float ROOT_BREAK_SPEED;

    public static Set<Block> STUMP_BLACKLIST = Sets.newHashSet(BWMBlocks.BLOOD_LOG);

    @Override
    public String getFeatureDescription() {
        return "Makes the bottom block of trees into stumps which cannot be removed by hand, making your mark on the world more obvious";
    }

    @Override
    public void init(FMLInitializationEvent event) {
    }

    @Nullable
    public static BlockPlanks.EnumType getWoodType(IBlockState state) {
        if (state.getProperties().containsKey(BlockPlanks.VARIANT)) {
            return state.getValue(BlockPlanks.VARIANT);
        } else if (state.getProperties().containsKey(BlockOldLog.VARIANT)) {
            return state.getValue(BlockOldLog.VARIANT);
        } else if (state.getProperties().containsKey(BlockNewLog.VARIANT)) {
            return state.getValue(BlockNewLog.VARIANT);
        } else
            return null;
    }

    @Override
    public boolean requiresMinecraftRestartToEnable() {
        return true;
    }

    @Override
    public boolean hasSubscriptions() {
        return true;
    }

    public static String[] BLACKLIST_CONFIG;

    public static boolean isStump(IBlockState state) {
        if (!STUMP_BLACKLIST.contains(state.getBlock()) && state.getBlock() instanceof BlockLog) {
            if (state.getPropertyKeys().contains(BlockLog.LOG_AXIS)) {
                return state.getValue(BlockLog.LOG_AXIS).equals(BlockLog.EnumAxis.Y);
            }
            return true;
        }
        return BWOreDictionary.getWoodFromState(state) != null;
    }

    public static boolean isRoots(IBlockState state) {
        return state.getMaterial() == Material.GROUND || state.getMaterial() == Material.GRASS;
    }

    @Override
    public void setupConfig() {
        BLACKLIST_CONFIG = loadPropStringList("Stump Blacklist", "Logs which do not create stumps", new String[0]);
        for (String block : BLACKLIST_CONFIG) {
            STUMP_BLACKLIST.add(Block.REGISTRY.getObject(new ResourceLocation(block)));
        }
        SPEED_UP_WITH_TOOLS = loadPropBool("Speed up with tool", "Speed up Stump mining with tools", true);
        STUMP_BREAK_SPEED = (float) loadPropDouble("Stump Break speed", "Base break speed of stumps, scaled by tool speed option", 0.03f);
        ROOT_BREAK_SPEED = (float) loadPropDouble("Root Break speed", "Base break speed of roots, scaled by tool speed option", 0.01f);
    }

    @SubscribeEvent
    public void getHarvest(PlayerEvent.BreakSpeed event) {
        World world = event.getEntityPlayer().getEntityWorld();
        if (isStump(world.getBlockState(event.getPos())) && isRoots(world.getBlockState(event.getPos().down()))) {
            float scale = SPEED_UP_WITH_TOOLS ? ToolsManager.getSpeed(event.getEntityPlayer().getHeldItemMainhand(), event.getState()) : 1;
            event.setNewSpeed(STUMP_BREAK_SPEED * scale);
        }
        if (isRoots(world.getBlockState(event.getPos())) && isStump(world.getBlockState(event.getPos().up()))) {
            float scale = SPEED_UP_WITH_TOOLS ? ToolsManager.getSpeed(event.getEntityPlayer().getHeldItemMainhand(), event.getState()) : 1;
            event.setNewSpeed(ROOT_BREAK_SPEED * scale);
        }
    }

    @SubscribeEvent(priority = EventPriority.HIGH)
    public void onHarvest(BlockEvent.HarvestDropsEvent event) {

        if (isStump(event.getState()) && isRoots(event.getWorld().getBlockState(event.getPos().down()))) {
            IWood wood = BWOreDictionary.getWoodFromState(event.getState());
            if (wood != null) {
                event.getDrops().clear();
                event.getDrops().addAll(Lists.newArrayList(wood.getSawdust(1), wood.getBark(1)));
            }
        }
        if (isRoots(event.getState()) && isStump(event.getWorld().getBlockState(event.getPos().up()))) {
            IWood wood = BWOreDictionary.getWoodFromState(event.getWorld().getBlockState(event.getPos().up()));
            if (wood != null) {
                event.setResult(Event.Result.DENY);
                event.getDrops().clear();
                event.getDrops().addAll(Lists.newArrayList(new ItemStack(BWMItems.DIRT_PILE, 2), wood.getSawdust(1), wood.getBark(1)));
            }
        }
    }

}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<title>Configure</title>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../styles/styles.css">

Configure

main |
exported functions

The <dfn>Configure</dfn> function allows the user to configure the plugin module.
It is called when one of the items exported by this plugin to the "Plugin
configuration" menu is selected.

int WINAPI Configure(
  int ItemNumber
);

Parameters

ItemNumber

The number of selected item in the list
      of items exported by this plugin to the "Plugin configuration" menu.

Return value

If the function succeeds, the return value must be
TRUE - in this case FAR updates the panels.
If the configuration is canceled by user,
FALSE should be returned.

Remarks

If your plugin exports only one menu item then you
can ignore ItemNumber.

Example

int WINAPI _export Configure(int ItemNumber)
{
  switch(ItemNumber)
  {
    case 0:
      return(Config());
  }
  return(FALSE);
}

See also:

GetPluginInfo


text:
package plugins

import (
	"fmt"
	"reflect"
	"testing"

	v1 "k8s.io/api/core/v1"
	storage "k8s.io/api/storage/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewStorageClass(params map[string]string, allowedTopologies []v1.TopologySelectorTerm) *storage.StorageClass {
	return &storage.StorageClass{
		Parameters:        params,
		AllowedTopologies: allowedTopologies,
	}
}

func TestTranslatePDInTreeStorageClassToCSI(t *testing.T) {
	g := NewGCEPersistentDiskCSITranslator()

	tcs := []struct {
		name       string
		options    *storage.StorageClass
		expOptions *storage.StorageClass
		expErr     bool
	}{
		{
			name:       "nothing special",
			options:    NewStorageClass(map[string]string{"foo": "bar"}, nil),
			expOptions: NewStorageClass(map[string]string{"foo": "bar"}, nil),
		},
		{
			name:       "fstype",
			options:    NewStorageClass(map[string]string{"fstype": "myfs"}, nil),
			expOptions: NewStorageClass(map[string]string{"csi.storage.k8s.io/fstype": "myfs"}, nil),
		},
		{
			name:       "empty params",
			options:    NewStorageClass(map[string]string{}, nil),
			expOptions: NewStorageClass(map[string]string{}, nil),
		},
		{
			name:       "zone",
			options:    NewStorageClass(map[string]string{"zone": "foo"}, nil),
			expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo"})),
		},
		{
			name:       "zones",
			options:    NewStorageClass(map[string]string{"zones": "foo,bar,baz"}, nil),
			expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo", "bar", "baz"})),
		},
		{
			name:       "some normal topology",
			options:    NewStorageClass(map[string]string{}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo"})),
			expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo"})),
		},
		{
			name:       "some translated topology",
			options:    NewStorageClass(map[string]string{}, generateToplogySelectors(v1.LabelFailureDomainBetaZone, []string{"foo"})),
			expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo"})),
		},
		{
			name:    "zone and topology",
			options: NewStorageClass(map[string]string{"zone": "foo"}, generateToplogySelectors(GCEPDTopologyKey, []string{"foo"})),
			expErr:  true,
		},
	}

	for _, tc := range tcs {
		t.Logf("Testing %v", tc.name)
		gotOptions, err := g.TranslateInTreeStorageClassToCSI(tc.options)
		if err != nil && !tc.expErr {
			t.Errorf("Did not expect error but got: %v", err)
		}
		if err == nil && tc.expErr {
			t.Errorf("Expected error, but did not get one.")
		}
		if !reflect.DeepEqual(gotOptions, tc.expOptions) {
			t.Errorf("Got parameters: %v, expected :%v", gotOptions, tc.expOptions)
		}
	}
}

func TestRepairVolumeHandle(t *testing.T) {
	testCases := []struct {
		name                 string
		volumeHandle         string
		nodeID               string
		expectedVolumeHandle string
		expectedErr          bool
	}{
		{
			name:                 "fully specified",
			volumeHandle:         fmt.Sprintf(volIDZonalFmt, "foo", "bar", "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "bada", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDZonalFmt, "foo", "bar", "baz"),
		},
		{
			name:                 "fully specified (regional)",
			volumeHandle:         fmt.Sprintf(volIDRegionalFmt, "foo", "us-central1-c", "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "bada", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDRegionalFmt, "foo", "us-central1-c", "baz"),
		},
		{
			name:                 "no project",
			volumeHandle:         fmt.Sprintf(volIDZonalFmt, UnspecifiedValue, "bar", "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "bada", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDZonalFmt, "bing", "bar", "baz"),
		},
		{
			name:                 "no project or zone",
			volumeHandle:         fmt.Sprintf(volIDZonalFmt, UnspecifiedValue, UnspecifiedValue, "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "bada", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDZonalFmt, "bing", "bada", "baz"),
		},
		{
			name:                 "no project or region",
			volumeHandle:         fmt.Sprintf(volIDRegionalFmt, UnspecifiedValue, UnspecifiedValue, "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "us-central1-c", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDRegionalFmt, "bing", "us-central1", "baz"),
		},
		{
			name:                 "no project (regional)",
			volumeHandle:         fmt.Sprintf(volIDRegionalFmt, UnspecifiedValue, "us-west1", "baz"),
			nodeID:               fmt.Sprintf(nodeIDFmt, "bing", "us-central1-c", "boom"),
			expectedVolumeHandle: fmt.Sprintf(volIDRegionalFmt, "bing", "us-west1", "baz"),
		},
		{
			name:         "invalid handle",
			volumeHandle: "foo",
			nodeID:       fmt.Sprintf(nodeIDFmt, "bing", "us-central1-c", "boom"),
			expectedErr:  true,
		},
		{
			name:         "invalid node ID",
			volumeHandle: fmt.Sprintf(volIDRegionalFmt, UnspecifiedValue, "us-west1", "baz"),
			nodeID:       "foo",
			expectedErr:  true,
		},
	}
	g := NewGCEPersistentDiskCSITranslator()
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			gotVolumeHandle, err := g.RepairVolumeHandle(tc.volumeHandle, tc.nodeID)
			if err != nil && !tc.expectedErr {
				if !tc.expectedErr {
					t.Fatalf("Got error: %v, but expected none", err)
				}
				return
			}
			if err == nil && tc.expectedErr {
				t.Fatal("Got no error, but expected one")
			}

			if gotVolumeHandle != tc.expectedVolumeHandle {
				t.Fatalf("Got volume handle %s, but expected %s", gotVolumeHandle, tc.expectedVolumeHandle)
			}
		})
	}
}

func TestBackwardCompatibleAccessModes(t *testing.T) {
	testCases := []struct {
		name           string
		accessModes    []v1.PersistentVolumeAccessMode
		expAccessModes []v1.PersistentVolumeAccessMode
	}{
		{
			name: "ROX",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadOnlyMany,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadOnlyMany,
			},
		},
		{
			name: "RWO",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
		{
			name: "RWX",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteMany,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
		{
			name: "RWO, ROX",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadOnlyMany,
				v1.ReadWriteOnce,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
		{
			name: "RWO, RWX",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
				v1.ReadWriteMany,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
		{
			name: "RWX, ROX",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteMany,
				v1.ReadOnlyMany,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
		{
			name: "RWX, ROX, RWO",
			accessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteMany,
				v1.ReadWriteOnce,
				v1.ReadOnlyMany,
			},
			expAccessModes: []v1.PersistentVolumeAccessMode{
				v1.ReadWriteOnce,
			},
		},
	}

	for _, tc := range testCases {
		t.Logf("running test: %v", tc.name)

		got := backwardCompatibleAccessModes(tc.accessModes)

		if !reflect.DeepEqual(tc.expAccessModes, got) {
			t.Fatalf("Expected access modes: %v, instead got: %v", tc.expAccessModes, got)
		}
	}
}

func TestInlineReadOnly(t *testing.T) {
	g := NewGCEPersistentDiskCSITranslator()
	pv, err := g.TranslateInTreeInlineVolumeToCSI(&v1.Volume{
		VolumeSource: v1.VolumeSource{
			GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
				PDName:   "foo",
				ReadOnly: true,
			},
		},
	})
	if err != nil {
		t.Fatalf("Failed to translate in tree inline volume to CSI: %v", err)
	}

	if pv == nil || pv.Spec.PersistentVolumeSource.CSI == nil {
		t.Fatal("PV or volume source unexpectedly nil")
	}

	if !pv.Spec.PersistentVolumeSource.CSI.ReadOnly {
		t.Error("PV readonly value not true")
	}

	ams := pv.Spec.AccessModes
	if len(ams) != 1 {
		t.Errorf("got am %v, expected length of 1", ams)
	}

	if ams[0] != v1.ReadOnlyMany {
		t.Errorf("got am %v, expected access mode of ReadOnlyMany", ams[0])
	}
}

func TestTranslateInTreePVToCSIVolIDFmt(t *testing.T) {
	g := NewGCEPersistentDiskCSITranslator()
	pdName := "pd-name"
	tests := []struct {
		desc               string
		topologyLabelKey   string
		topologyLabelValue string
		wantVolId          string
	}{
		{
			desc:               "beta topology key zonal",
			topologyLabelKey:   v1.LabelFailureDomainBetaZone,
			topologyLabelValue: "us-east1-a",
			wantVolId:          "projects/UNSPECIFIED/zones/us-east1-a/disks/pd-name",
		},
		{
			desc:               "v1 topology key zonal",
			topologyLabelKey:   v1.LabelTopologyZone,
			topologyLabelValue: "us-east1-a",
			wantVolId:          "projects/UNSPECIFIED/zones/us-east1-a/disks/pd-name",
		},
		{
			desc:               "beta topology key regional",
			topologyLabelKey:   v1.LabelFailureDomainBetaZone,
			topologyLabelValue: "us-central1-a__us-central1-c",
			wantVolId:          "projects/UNSPECIFIED/regions/us-central1/disks/pd-name",
		},
		{
			desc:               "v1 topology key regional",
			topologyLabelKey:   v1.LabelTopologyZone,
			topologyLabelValue: "us-central1-a__us-central1-c",
			wantVolId:          "projects/UNSPECIFIED/regions/us-central1/disks/pd-name",
		},
	}
	for _, tc := range tests {
		t.Run(tc.desc, func(t *testing.T) {
			translatedPV, err := g.TranslateInTreePVToCSI(&v1.PersistentVolume{
				ObjectMeta: metav1.ObjectMeta{
					Labels: map[string]string{tc.topologyLabelKey: tc.topologyLabelValue},
				},
				Spec: v1.PersistentVolumeSpec{
					PersistentVolumeSource: v1.PersistentVolumeSource{
						GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
							PDName: pdName,
						},
					},
				},
			})
			if err != nil {
				t.Errorf("got error translating in-tree PV to CSI: %v", err)
			}
			if got := translatedPV.Spec.PersistentVolumeSource.CSI.VolumeHandle; got != tc.wantVolId {
				t.Errorf("got translated volume handle: %q, want %q", got, tc.wantVolId)
			}
		})
	}
}


text:
/**
 * Represents a vector (or point) in two dimensions.
 *
 * @param x the x-coordinate of the vector.
 * @param y the y-coordinate of the vector.
 */
function Vector(x, y) {
  this.x = x;
  this.y = y;
}

/**
 * Returns the distance from this vector to the specified vector (x,
 * y).
 *
 * @param x the x-coordinate of the point.
 * @param y the y-coordinate of the point.
 */
Vector.prototype.distance = function(x, y) {
  var dx = this.x - x;
  var dy = this.y - y;
  return Math.sqrt(dx * dx + dy * dy);
};

/** Returns the perpendicular vector to this vector, (-y, x). */
Vector.prototype.perp = function() {
  return new Vector(-this.y, this.x);
};

/** Returns the dot product of this vector with the specified vector. */
Vector.prototype.dot = function(v) {
  return this.x * v.x + this.y * v.y;
};

/** Returns the cross product (Z) of this vector with the specified vector. */
Vector.prototype.cross = function(v) {
  return this.x * v.y - this.y * v.x;
};

/** Returns the string representation of this vector. */
Vector.prototype.toString = function() {
  return "(" + this.x + ", " + this.y + ")";
};


text:
<?php
/**
 * Progress Types
 * enum
 */
abstract class ProgressTypes {
	const FinishedSectionsTotal = 1;
	const FinishedLesson = 2;
	/**
	 * number of lessons finished in course
	 */
	const CourseFinishedLessonsTotal = 3;
	/**
	 * number of lessons finished in section
	 */
	const SectionFinishedLessonsTotal = 4;
	/**
	 * enrolled to course
	 */
	const Enrolled = 5;
}
?>


text:
import sys
import Image
import itertools
import numpy as np

if sys.version_info.major < 3:
    range = xrange

# functions

def image_to_array(im, reshape=True):
    """
    Converts a PIL Image object into a numpy array representing
    a greyscale image.
    Parameters:
        im - a PIL Image object
        reshape (default: True) - if True then returns a 2D image
                                otherwise it returns a flat 1D araray.
    Output:
        A numpy array.
    """
    im_greyscale = im.convert("L")
    width, height = im_greyscale.size
    im_array = np.ndarray(width * height)
    for i, p in enumerate(im_greyscale.getdata()):
        im_array[i] = p
    if reshape:
        im_array.shape = (height, width)
    return im_array

def array_to_image(array):
    height, width = array.shape
    im = Image.new('L', (width, height), 255)
    for x in range(width):
        for y in range(height):
            im.putpixel((x,y), array[y][x])
    return im

def windows0(im, rectangles, output_size):
    im_width, im_height = im.size
    for dx, dy in rectangles:
        for x0, y0 in itertools.product(range(im_width-dx+1),range(im_height-dy+1)):
            yield im.crop((x0, y0, x0+dx, y0+dy))

def windows(im, rectangles, output_size):
    """
    Parameters:
    im - a PIL image
    rectangles - a list of (width, height) pairs of rectangle sizes
    output_size - the desired output size in (width, height) format
    """
    im_width, im_height = im.size
    for dx, dy in rectangles:
        for x0, y0 in itertools.product(range(im_width-dx+1),range(im_height-dy+1)):
            yield im.transform(output_size, Image.EXTENT, (x0, y0, x0+dx, y0+dy))

def array_windows(im, rectangles, output_size):
    """
    Parameters:
    im - a PIL image
    rectangles - a list of (width, height) pairs of rectangle sizes
    output_size - the desired output size in (width, height) format
    """
    return (image_to_array(w) for w in windows(im, rectangles, output_size))

if __name__ == '__main__':
    # testing code
    testfile = "data/hk.png"
    im_raw = Image.open(testfile)
    im_array = image_to_array(im_raw)


text:
export * from './grid-list-module';
export * from './grid-list';
export { MatGridTile } from './grid-tile';


text:
#include "config.h"
#include "PlatformTouchEvent.h"
#include <wtf/CurrentTime.h>

#if ENABLE(TOUCH_EVENTS)

namespace WebCore {

PlatformTouchEvent::PlatformTouchEvent(QTouchEvent* event)
{
    switch (event->type()) {
    case QEvent::TouchBegin: m_type = TouchStart; break;
    case QEvent::TouchUpdate: m_type = TouchMove; break;
    case QEvent::TouchEnd: m_type = TouchEnd; break;
    }
    const QList<QTouchEvent::TouchPoint>& points = event->touchPoints();
    for (int i = 0; i < points.count(); ++i)
        m_touchPoints.append(PlatformTouchPoint(points.at(i)));

    m_ctrlKey = (event->modifiers() & Qt::ControlModifier);
    m_altKey = (event->modifiers() & Qt::AltModifier);
    m_shiftKey = (event->modifiers() & Qt::ShiftModifier);
    m_metaKey = (event->modifiers() & Qt::MetaModifier);
    m_timestamp = WTF::currentTime();
}

}

#endif


text:
from . import quandl  # noqa
from .core import (
    UnknownBundle,
    bundles,
    clean,
    from_bundle_ingest_dirname,
    ingest,
    load,
    register,
    to_bundle_ingest_dirname,
    unregister,
)
from .yahoo import yahoo_equities

__all__ = [
    'UnknownBundle',
    'bundles',
    'clean',
    'from_bundle_ingest_dirname',
    'ingest',
    'load',
    'register',
    'to_bundle_ingest_dirname',
    'unregister',
    'yahoo_equities',
]


text:
#include <aws/route53/model/UpdateTrafficPolicyInstanceRequest.h>
#include <aws/core/utils/xml/XmlSerializer.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>

#include <utility>

using namespace Aws::Route53::Model;
using namespace Aws::Utils::Xml;
using namespace Aws::Utils;

UpdateTrafficPolicyInstanceRequest::UpdateTrafficPolicyInstanceRequest() :
    m_idHasBeenSet(false),
    m_tTL(0),
    m_tTLHasBeenSet(false),
    m_trafficPolicyIdHasBeenSet(false),
    m_trafficPolicyVersion(0),
    m_trafficPolicyVersionHasBeenSet(false)
{
}

Aws::String UpdateTrafficPolicyInstanceRequest::SerializePayload() const
{
  XmlDocument payloadDoc = XmlDocument::CreateWithRootNode("UpdateTrafficPolicyInstanceRequest");

  XmlNode parentNode = payloadDoc.GetRootElement();
  parentNode.SetAttributeValue("xmlns", "https://route53.amazonaws.com/doc/2013-04-01/");

  Aws::StringStream ss;
  if(m_tTLHasBeenSet)
  {
   XmlNode tTLNode = parentNode.CreateChildElement("TTL");
   ss << m_tTL;
   tTLNode.SetText(ss.str());
   ss.str("");
  }

  if(m_trafficPolicyIdHasBeenSet)
  {
   XmlNode trafficPolicyIdNode = parentNode.CreateChildElement("TrafficPolicyId");
   trafficPolicyIdNode.SetText(m_trafficPolicyId);
  }

  if(m_trafficPolicyVersionHasBeenSet)
  {
   XmlNode trafficPolicyVersionNode = parentNode.CreateChildElement("TrafficPolicyVersion");
   ss << m_trafficPolicyVersion;
   trafficPolicyVersionNode.SetText(ss.str());
   ss.str("");
  }

  return payloadDoc.ConvertToString();
}


text:
package br.org.cesar.unittests;

import br.org.cesar.unittests.api.ApiConsumerListener;
import br.org.cesar.unittests.api.MyApiConsumer;
import br.org.cesar.unittests.api.ProductionServer;

public class Application {

	public static void main(String[] args) {

		MyApiConsumer api = new MyApiConsumer(new ProductionServer());

		System.out.println("Calling sumAtoB method");
		api.sumAtoB(new ApiConsumerListener() {

			@Override
			public void onSuccess(int result) {
				System.out.println("A + B = " + result);
			}

			@Override
			public void onError(String msg) {
				System.out.println(msg);
			}
		});
		System.out.println("Calling subtractAfromB method");
		api.subtractAfromB(new ApiConsumerListener() {

			@Override
			public void onSuccess(int result) {
				System.out.println("B - A = " + result);
			}

			@Override
			public void onError(String msg) {
				System.out.println(msg);

			}
		});
	}
}