text:
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/grpcpp.h>

#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>

#include "absl/flags/flag.h"
#include "src/proto/grpc/testing/metrics.grpc.pb.h"
#include "src/proto/grpc/testing/metrics.pb.h"
#include "test/cpp/interop/interop_client.h"
#include "test/cpp/interop/stress_interop_client.h"
#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/util/metrics_server.h"
#include "test/cpp/util/test_config.h"

extern void gpr_default_log(gpr_log_func_args* args);

ABSL_FLAG(int32_t, metrics_port, 8081, "The metrics server port.");

// TODO(Capstan): Consider using absl::Duration
ABSL_FLAG(int32_t, sleep_duration_ms, 0,
          "The duration (in millisec) between two"
          " consecutive test calls (per server) issued by the server.");

// TODO(Capstan): Consider using absl::Duration
ABSL_FLAG(int32_t, test_duration_secs, -1,
          "The length of time (in seconds) to run"
          " the test. Enter -1 if the test should run continuously until"
          " forcefully terminated.");

ABSL_FLAG(std::string, server_addresses, "localhost:8080",
          "The list of server addresses. The format is: \n"
          " \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n"
          " Note: <name> can be servername or IP address.");

ABSL_FLAG(int32_t, num_channels_per_server, 1,
          "Number of channels for each server");

ABSL_FLAG(int32_t, num_stubs_per_channel, 1,
          "Number of stubs per each channels to server. This number also "
          "indicates the max number of parallel RPC calls on each channel "
          "at any given time.");

// TODO(sreek): Add more test cases here in future
ABSL_FLAG(std::string, test_cases, "",
          "List of test cases to call along with the"
          " relative weights in the following format:\n"
          " \"<testcase_1:w_1>,<testcase_2:w_2>...<testcase_n:w_n>\"\n"
          " The following testcases are currently supported:\n"
          "   empty_unary\n"
          "   large_unary\n"
          "   large_compressed_unary\n"
          "   client_streaming\n"
          "   server_streaming\n"
          "   server_compressed_streaming\n"
          "   slow_consumer\n"
          "   half_duplex\n"
          "   ping_pong\n"
          "   cancel_after_begin\n"
          "   cancel_after_first_response\n"
          "   timeout_on_sleeping_server\n"
          "   empty_stream\n"
          "   status_code_and_message\n"
          "   custom_metadata\n"
          " Example: \"empty_unary:20,large_unary:10,empty_stream:70\"\n"
          " The above will execute 'empty_unary', 20% of the time,"
          " 'large_unary', 10% of the time and 'empty_stream' the remaining"
          " 70% of the time");

ABSL_FLAG(int32_t, log_level, GPR_LOG_SEVERITY_INFO,
          "Severity level of messages that should be logged. Any messages "
          "greater than or equal to the level set here will be logged. "
          "The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 "
          "(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR)");

ABSL_FLAG(bool, do_not_abort_on_transient_failures, true,
          "If set to 'true', abort() is not called in case of transient "
          "failures like temporary connection failures.");

// Options from client.cc (for compatibility with interop test).
// TODO(sreek): Consolidate overlapping options
ABSL_FLAG(bool, use_alts, false,
          "Whether to use alts. Enable alts will disable tls.");
ABSL_FLAG(bool, use_tls, false, "Whether to use tls.");
ABSL_FLAG(bool, use_test_ca, false, "False to use SSL roots for google");
ABSL_FLAG(std::string, server_host_override, "",
          "Override the server host which is sent in HTTP header");

using grpc::testing::ALTS;
using grpc::testing::INSECURE;
using grpc::testing::kTestCaseList;
using grpc::testing::MetricsServiceImpl;
using grpc::testing::StressTestInteropClient;
using grpc::testing::TestCaseType;
using grpc::testing::TLS;
using grpc::testing::transport_security;
using grpc::testing::UNKNOWN_TEST;
using grpc::testing::WeightedRandomTestSelector;

static int log_level = GPR_LOG_SEVERITY_DEBUG;

// A simple wrapper to grp_default_log() function. This only logs messages at or
// above the current log level (set in 'log_level' variable)
void TestLogFunction(gpr_log_func_args* args) {
  if (args->severity >= log_level) {
    gpr_default_log(args);
  }
}

TestCaseType GetTestTypeFromName(const std::string& test_name) {
  TestCaseType test_case = UNKNOWN_TEST;

  for (auto it = kTestCaseList.begin(); it != kTestCaseList.end(); it++) {
    if (test_name == it->second) {
      test_case = it->first;
      break;
    }
  }

  return test_case;
}

// Converts a string of comma delimited tokens to a vector of tokens
bool ParseCommaDelimitedString(const std::string& comma_delimited_str,
                               std::vector<std::string>& tokens) {
  size_t bpos = 0;
  size_t epos = std::string::npos;

  while ((epos = comma_delimited_str.find(',', bpos)) != std::string::npos) {
    tokens.emplace_back(comma_delimited_str.substr(bpos, epos - bpos));
    bpos = epos + 1;
  }

  tokens.emplace_back(comma_delimited_str.substr(bpos));  // Last token
  return true;
}

// Input: Test case string "<testcase_name:weight>,<testcase_name:weight>...."
// Output:
//   - Whether parsing was successful (return value)
//   - Vector of (test_type_enum, weight) pairs returned via 'tests' parameter
bool ParseTestCasesString(const std::string& test_cases,
                          std::vector<std::pair<TestCaseType, int>>& tests) {
  bool is_success = true;

  std::vector<std::string> tokens;
  ParseCommaDelimitedString(test_cases, tokens);

  for (auto it = tokens.begin(); it != tokens.end(); it++) {
    // Token is in the form <test_name>:<test_weight>
    size_t colon_pos = it->find(':');
    if (colon_pos == std::string::npos) {
      gpr_log(GPR_ERROR, "Error in parsing test case string: %s", it->c_str());
      is_success = false;
      break;
    }

    std::string test_name = it->substr(0, colon_pos);
    int weight = std::stoi(it->substr(colon_pos + 1));
    TestCaseType test_case = GetTestTypeFromName(test_name);
    if (test_case == UNKNOWN_TEST) {
      gpr_log(GPR_ERROR, "Unknown test case: %s", test_name.c_str());
      is_success = false;
      break;
    }

    tests.emplace_back(std::make_pair(test_case, weight));
  }

  return is_success;
}

// For debugging purposes
void LogParameterInfo(const std::vector<std::string>& addresses,
                      const std::vector<std::pair<TestCaseType, int>>& tests) {
  gpr_log(GPR_INFO, "server_addresses: %s",
          absl::GetFlag(FLAGS_server_addresses).c_str());
  gpr_log(GPR_INFO, "test_cases : %s", absl::GetFlag(FLAGS_test_cases).c_str());
  gpr_log(GPR_INFO, "sleep_duration_ms: %d",
          absl::GetFlag(FLAGS_sleep_duration_ms));
  gpr_log(GPR_INFO, "test_duration_secs: %d",
          absl::GetFlag(FLAGS_test_duration_secs));
  gpr_log(GPR_INFO, "num_channels_per_server: %d",
          absl::GetFlag(FLAGS_num_channels_per_server));
  gpr_log(GPR_INFO, "num_stubs_per_channel: %d",
          absl::GetFlag(FLAGS_num_stubs_per_channel));
  gpr_log(GPR_INFO, "log_level: %d", absl::GetFlag(FLAGS_log_level));
  gpr_log(GPR_INFO, "do_not_abort_on_transient_failures: %s",
          absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) ? "true"
                                                                  : "false");

  int num = 0;
  for (auto it = addresses.begin(); it != addresses.end(); it++) {
    gpr_log(GPR_INFO, "%d:%s", ++num, it->c_str());
  }

  num = 0;
  for (auto it = tests.begin(); it != tests.end(); it++) {
    TestCaseType test_case = it->first;
    int weight = it->second;
    gpr_log(GPR_INFO, "%d. TestCaseType: %d, Weight: %d", ++num, test_case,
            weight);
  }
}

int main(int argc, char** argv) {
  grpc::testing::InitTest(&argc, &argv, true);

  if (absl::GetFlag(FLAGS_log_level) > GPR_LOG_SEVERITY_ERROR ||
      absl::GetFlag(FLAGS_log_level) < GPR_LOG_SEVERITY_DEBUG) {
    gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d",
            GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR);
    return 1;
  }

  // Change the default log function to TestLogFunction which respects the
  // log_level setting.
  log_level = absl::GetFlag(FLAGS_log_level);
  gpr_set_log_function(TestLogFunction);

  srand(time(nullptr));

  // Parse the server addresses
  std::vector<std::string> server_addresses;
  ParseCommaDelimitedString(absl::GetFlag(FLAGS_server_addresses),
                            server_addresses);

  // Parse test cases and weights
  if (absl::GetFlag(FLAGS_test_cases).length() == 0) {
    gpr_log(GPR_ERROR, "No test cases supplied");
    return 1;
  }

  std::vector<std::pair<TestCaseType, int>> tests;
  if (!ParseTestCasesString(absl::GetFlag(FLAGS_test_cases), tests)) {
    gpr_log(GPR_ERROR, "Error in parsing test cases string %s ",
            absl::GetFlag(FLAGS_test_cases).c_str());
    return 1;
  }

  LogParameterInfo(server_addresses, tests);

  WeightedRandomTestSelector test_selector(tests);
  MetricsServiceImpl metrics_service;

  gpr_log(GPR_INFO, "Starting test(s)..");

  std::vector<std::thread> test_threads;
  std::vector<std::unique_ptr<StressTestInteropClient>> clients;

  // Create and start the test threads.
  // Note that:
  // - Each server can have multiple channels (as configured by
  // FLAGS_num_channels_per_server).
  //
  // - Each channel can have multiple stubs (as configured by
  // FLAGS_num_stubs_per_channel). This is to test calling multiple RPCs in
  // parallel on the same channel.
  int thread_idx = 0;
  int server_idx = -1;
  char buffer[256];
  transport_security security_type =
      absl::GetFlag(FLAGS_use_alts)
          ? ALTS
          : (absl::GetFlag(FLAGS_use_tls) ? TLS : INSECURE);
  for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) {
    ++server_idx;
    // Create channel(s) for each server
    for (int channel_idx = 0;
         channel_idx < absl::GetFlag(FLAGS_num_channels_per_server);
         channel_idx++) {
      gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(),
              channel_idx);
      grpc::testing::ChannelCreationFunc channel_creation_func =
          std::bind(static_cast<std::shared_ptr<grpc::Channel> (*)(
                        const std::string&, const std::string&,
                        grpc::testing::transport_security, bool)>(
                        grpc::CreateTestChannel),
                    *it, absl::GetFlag(FLAGS_server_host_override),
                    security_type, !absl::GetFlag(FLAGS_use_test_ca));

      // Create stub(s) for each channel
      for (int stub_idx = 0;
           stub_idx < absl::GetFlag(FLAGS_num_stubs_per_channel); stub_idx++) {
        clients.emplace_back(new StressTestInteropClient(
            ++thread_idx, *it, channel_creation_func, test_selector,
            absl::GetFlag(FLAGS_test_duration_secs),
            absl::GetFlag(FLAGS_sleep_duration_ms),
            absl::GetFlag(FLAGS_do_not_abort_on_transient_failures)));

        bool is_already_created = false;
        // QpsGauge name
        std::snprintf(buffer, sizeof(buffer),
                      "/stress_test/server_%d/channel_%d/stub_%d/qps",
                      server_idx, channel_idx, stub_idx);

        test_threads.emplace_back(std::thread(
            &StressTestInteropClient::MainLoop, clients.back().get(),
            metrics_service.CreateQpsGauge(buffer, &is_already_created)));

        // The QpsGauge should not have been already created
        GPR_ASSERT(!is_already_created);
      }
    }
  }

  // Start metrics server before waiting for the stress test threads
  std::unique_ptr<grpc::Server> metrics_server;
  if (absl::GetFlag(FLAGS_metrics_port) > 0) {
    metrics_server =
        metrics_service.StartServer(absl::GetFlag(FLAGS_metrics_port));
  }

  // Wait for the stress test threads to complete
  for (auto it = test_threads.begin(); it != test_threads.end(); it++) {
    it->join();
  }

  return 0;
}


text:
namespace ncode {
namespace geo {

struct CityData {
  CityData(const std::string& name, const std::string& country_code,
           size_t population, double longitude, double latitude)
      : name(name),
        country_code(country_code),
        population(population),
        longitude(longitude),
        latitude(latitude) {}

  // The ASCII name of the city.
  const std::string name;

  // Country code.
  const std::string country_code;

  // Population.
  const size_t population;

  // Coordinates of the city.
  const double longitude;
  const double latitude;
};

std::ostream& operator<<(std::ostream& out, const CityData& city);

// A generic interface for projections.
class ProjectionInterface {
 public:
  virtual ~ProjectionInterface() {}

  // Returns the x,y coordinates of a lon,lat point. Both should be in decimal
  // degrees.
  virtual std::pair<double, double> Project(double longitude,
                                            double latitude) const = 0;
};

class WebMercator : public ProjectionInterface {
 public:
  WebMercator(double zoom_level = 1.0) : zoom_level_(zoom_level) {}

  std::pair<double, double> Project(double longitude,
                                    double latitude) const override {
    double lon_rad = (M_PI / 180.0) * longitude;
    double lat_rad = (M_PI / 180.0) * latitude;

    double c = (128.0 / M_PI) * std::pow(2, zoom_level_);
    double x = c * (lon_rad + M_PI);
    double y = c * (M_PI - std::log(std::tan(M_PI / 4.0 + lat_rad / 2.0)));

    DCHECK(x == x);
    DCHECK(y == y);
    return std::make_pair(x, y);
  }

 private:
  double zoom_level_;
};

// Given a city populates its x,y coordinates according to some projection.
bool CityXY(const CityData& city, const ProjectionInterface& projection,
            double* x, double* y);

struct FindCityRequest {
  // The name of the city. Out of all non-filtered cities the one that whose
  // name has the closest distance (Livenshtein) to this string will be
  // returned.
  std::string ascii_name;

  // A regex filter to be applied to names before shortest-distance matching.
  std::string regex_ascii_name_filter = ".*";

  // Only cities with country codes that pass this filter will be considered.
  std::string regex_country_code_filter = ".*";

  bool operator<(const FindCityRequest& other) const {
    return std::tie(ascii_name, regex_ascii_name_filter,
                    regex_country_code_filter) <
           std::tie(other.ascii_name, other.regex_ascii_name_filter,
                    other.regex_country_code_filter);
  }
};

class Localizer {
 public:
  static constexpr char kDefaultCitiesFileLocation[] =
      "geonames/cities5000.txt";

  Localizer(
      const std::string& world_cities_db_file = kDefaultCitiesFileLocation);

  // Finds a city by name.
  const CityData* FindCityOrNull(const FindCityRequest& request);

  // Returns all cities in no particular order.
  const std::vector<CityData>& AllCities() const { return cities_; }

 private:
  static constexpr size_t kCacheSize = 10000;

  // Only cities with non-0 population are retained.
  std::vector<CityData> cities_;

  // Cache of requests.
  std::map<FindCityRequest, const CityData*> request_to_city_;
};

}  // namespace geo
}  // namespace ncode
#endif

redpajama_set_name: RedPajamaGithub


text:
package in.thekreml.recaptcha;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.URL;

/**
 * Provides an implementation of ReCaptchaValidator using Apache HttpClient
 */
public class HttpClientReCaptchaValidator extends ConfigurableReCaptchaValidator {
	private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientReCaptchaValidator.class);
	private static final HttpClient HTTP_CLIENT = HttpClients.createMinimal();

	@Override
	public Boolean validate(String challenge, String response, InetAddress remoteAddr) {
		final URL url = getRequestURL(challenge, response, remoteAddr);

		try {
			final HttpGet httpRequest = new HttpGet(url.toURI());
			final HttpResponse httpResponse = HTTP_CLIENT.execute(httpRequest);

			if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
				LOGGER.warn("Got response code {}", httpResponse.getStatusLine().getStatusCode());
				return false;
			}

			String[] responseLines = EntityUtils.toString(httpResponse.getEntity()).split("\n");
			return responseLines.length >= 1 && responseLines[0].trim().toLowerCase().equals("true");
		} catch (Exception e) {
			LOGGER.error("Exception during reCAPTCHA validation request", e);
		}

		return false;
	}
}


text:
'use stric'
var constants = require('../misc/constants')
var default_values = require('../misc/default_values')

var promise = require('../facades/promise')
var clone = require('../facades/clone')

var handlers = require('./params_processor_handlers')

module.exports = function() {
  return params_processor_factory.get_instance()
};

var params_processor_factory = {
   instance : undefined,

   get_instance : function() {
      if (typeof this.instance === 'undefined' || this.instance === null) {
          this.instance = params_processor()
      }
      return this.instance
   }
}

var params_processor = function() {
  return {
    process : function(params) {
      return _process(params);
    }
  }
}

var _process = function(params) {
  if(params.help === true) {
    return promise.resolve({ help : true })
  }

  if(params.version === true) {
    return promise.resolve({ version : true })
  }

  if(params[constants.GENERATE_PARAM_NAME] === true) {
    return handlers.handle_generate_param(params);
  }

  if(typeof params[constants.APPLY_PARAM_NAME] === 'string') {
    return handlers.handle_apply_param(params)
  }

  if(typeof params[constants.GENERATE_AND_APPLY_PARAM_NAME] === 'string') {
    return handlers.handle_generate_param(params).then(
      function(generate_params) {
        return handlers.handle_apply_param(params).then(
          function(apply_params) {
            return _merge_params(generate_params, apply_params)
          }
        )
      }
    )
  }

  return promise.reject("main param missing (processor)");
}

var _merge_params = function(generate_params, apply_params) {
  return Object.assign(clone(generate_params), clone(apply_params))
}


text:
using System;
using System.Windows.Input;
using Metrolib;

namespace NewDesign.Dashboard.Widgets.QuickInfos
{
	public sealed class QuickInfoViewModel
		: NamedValueViewModel
	{
		private string _query;
		private readonly ICommand _removeCommand;

		public event Action<QuickInfoViewModel> OnRemove;

		public QuickInfoViewModel(string name, object value = null) : base(name, value)
		{
			_removeCommand = new DelegateCommand(Remove);
		}

		private void Remove()
		{
			OnRemove?.Invoke(this);
		}

		public string Query
		{
			get { return _query; }
			set
			{
				if (value == _query)
					return;

				_query = value;
				EmitPropertyChanged();
			}
		}

		public ICommand RemoveCommand
		{
			get { return _removeCommand; }
		}
	}
}


text:
package realmrelay.net;

import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;

public abstract class ListenSocket implements Runnable {

	private final SocketAddress endpoint;
	private ServerSocket serversocket;
	private Thread thread;

	public ListenSocket(int port) {
		this.endpoint = new InetSocketAddress(port);
	}

	public ListenSocket(String hostname, int port) {
		this.endpoint = new InetSocketAddress(hostname, port);
	}

	public boolean isClosed() {
		return this.serversocket == null || this.serversocket.isClosed();
	}

	public boolean start() {
		stop();
		try {
			this.serversocket = new ServerSocket();
			this.serversocket.bind(this.endpoint);
		} catch (Exception e) {
			stop();
			return false;
		}
		this.thread = new Thread(this);
		this.thread.start();
		return true;
	}

	public void stop() {
		this.thread = null;
		if (this.serversocket != null) {
			try {
				this.serversocket.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			this.serversocket = null;
		}
	}

	@Override
	public void run() {
		while (this.serversocket != null && !this.serversocket.isClosed()) {
			try {
				final Socket socket = this.serversocket.accept();
				new Thread(new Runnable() {

					@Override
					public void run() {
						socketAccepted(socket);
					}

				}).start();

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

	public abstract void socketAccepted(Socket socket);

	@Override
	public String toString() {
		return "ListenSocket[endpoint=" + this.endpoint + "]";
	}

}


text:
package main

// extract-giflzw.go extracts or analyzes the LZW-compressed block data in a
// GIF image.
//
//   - Add the "-extract" flag to write the LZW data to a file. The initial
//     byte in each written file is the LZW literal width.
//
//   - Add the "-histogram" flag to print emission length histograms instead of
//     writing out *.indexes.giflzw files.
//
// Add the optional "-allframes" flag to process all frames of an animated GIF,
// not just the first frame. It applies to both -extract and -histogram.
//
// Usage: go run extract-giflzw.go -extract              foo.gif bar.gif
//        go run extract-giflzw.go -histogram -allframes foo.gif bar.gif

import (
	"bytes"
	"compress/lzw"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
)

var (
	allframesFlag = flag.Bool("allframes", false, "process all frames, not just the first")
	extractFlag   = flag.Bool("extract", false, "write LZW data to a file")
	histogramFlag = flag.Bool("histogram", false, "print emission length histograms")
)

func main() {
	if err := main1(); err != nil {
		os.Stderr.WriteString(err.Error() + "\n")
		os.Exit(1)
	}
}

func main1() error {
	flag.Parse()
	if !*extractFlag && !*histogramFlag {
		return fmt.Errorf("none of -extract or -histogram given")
	}

	for argIndex, arg := range flag.Args() {
		frames, err := extractLZWFrames(arg)
		if err != nil {
			return err
		}

		if *histogramFlag {
			which := "first frame"
			if *allframesFlag {
				which = "all frames"
			}
			fmt.Printf("\n%s (%s)\n", arg, which)

			histogramTotal = 0
			for i := range histogram {
				histogram[i] = 0
			}
		}

		for frameIndex, frame := range frames {
			if err := checkLZW(frame); err != nil {
				fmt.Printf("Warning: frame #%d: %v\n", frameIndex, err)
			}

			if *extractFlag {
				filename := arg[:len(arg)-len(filepath.Ext(arg))]
				if *allframesFlag {
					filename = fmt.Sprintf("%s-frame-%03d", filename, argIndex)
				}
				filename += ".indexes.giflzw"
				if err := ioutil.WriteFile(filename, frame, 0644); err != nil {
					return err
				}
			}
			if *histogramFlag {
				// Ignore any LZW format errors. Decode as much as we can.
				_ = buildHistogram(frame)
			}

			if !*allframesFlag {
				break
			}
		}

		if *histogramFlag {
			fmt.Printf(" Percent   Count  Emission_Length_Bucket\n")
			for i, h := range histogram {
				percent := float64(100*h) / float64(histogramTotal)
				fmt.Printf("  %6.2f  %6d  %s\n", percent, h, bucketNames[i])
			}
		}
	}
	return nil
}

func extractLZWFrames(filename string) (ret [][]byte, err error) {
	src, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}

	// Read the header (6 bytes) and screen descriptor (7 bytes).
	if len(src) < 6+7 {
		return nil, fmt.Errorf("not a GIF")
	}
	switch string(src[:6]) {
	case "GIF87a", "GIF89a":
		// No-op.
	default:
		return nil, fmt.Errorf("not a GIF")
	}
	ctSize := 0
	if src[10]&fColorTable != 0 {
		ctSize = 1 << (1 + src[10]&fColorTableBitsMask)
	}
	if src, err = skipColorTable(src[13:], ctSize); err != nil {
		return nil, err
	}

	for len(src) > 0 {
		switch src[0] {
		case sExtension:
			if src, err = skipExtension(src[1:]); err != nil {
				return nil, err
			}
		case sImageDescriptor:
			compressed := []byte(nil)
			if src, compressed, err = readImageDescriptor(src[1:]); err != nil {
				return nil, err
			}
			ret = append(ret, compressed)
		case sTrailer:
			if len(src) != 1 {
				return nil, fmt.Errorf("extraneous data after GIF trailer section")
			}
			return ret, nil
		default:
			return nil, fmt.Errorf("unsupported GIF section")
		}
	}
	return nil, fmt.Errorf("missing GIF trailer section")
}

func skipColorTable(src []byte, ctSize int) (src1 []byte, err error) {
	if ctSize == 0 {
		return src, nil
	}
	n := 3 * ctSize
	if len(src) < n {
		return nil, fmt.Errorf("short color table")
	}
	return src[n:], nil
}

func skipExtension(src []byte) (src1 []byte, err error) {
	if len(src) < 2 {
		return nil, fmt.Errorf("bad GIF extension")
	}
	ext := src[0]
	blockSize := int(src[1])
	if len(src) < 2+blockSize {
		return nil, fmt.Errorf("bad GIF extension")
	}
	src = src[2+blockSize:]
	switch ext {
	case ePlainText, eGraphicControl, eComment, eApplication:
		src1, _, err = readBlockData(src, nil)
		return src1, err
	}
	return nil, fmt.Errorf("unsupported GIF extension")
}

func readImageDescriptor(src []byte) (src1 []byte, ret1 []byte, err error) {
	if len(src) < 9 {
		return nil, nil, fmt.Errorf("bad GIF image descriptor")
	}
	ctSize := 0
	if src[8]&fColorTable != 0 {
		ctSize = 1 << (1 + src[8]&fColorTableBitsMask)
	}
	if src, err = skipColorTable(src[9:], ctSize); err != nil {
		return nil, nil, err
	}

	if len(src) < 1 {
		return nil, nil, fmt.Errorf("bad GIF image descriptor")
	}
	literalWidth := src[0]
	if literalWidth < 2 || 8 < literalWidth {
		return nil, nil, fmt.Errorf("bad GIF literal width")
	}
	return readBlockData(src[1:], []byte{literalWidth})
}

func readBlockData(src []byte, ret []byte) (src1 []byte, ret1 []byte, err error) {
	for {
		if len(src) < 1 {
			return nil, nil, fmt.Errorf("bad GIF block")
		}
		n := int(src[0]) + 1
		if len(src) < n {
			return nil, nil, fmt.Errorf("bad GIF block")
		}
		ret = append(ret, src[1:n]...)
		src = src[n:]
		if n == 1 {
			return src, ret, nil
		}
	}
}

func checkLZW(data []byte) error {
	if len(data) == 0 {
		return fmt.Errorf("missing GIF literal width")
	}
	rc := lzw.NewReader(bytes.NewReader(data[1:]), lzw.LSB, int(data[0]))
	defer rc.Close()
	_, err := ioutil.ReadAll(rc)
	if err != nil {
		return fmt.Errorf("block data is not valid LZW: %v", err)
	}
	return nil
}

const numBuckets = 14

var (
	histogramTotal = uint32(0)
	histogram      = [numBuckets]uint32{}
	bucketNames    = [numBuckets]string{
		"         1 (Literal Code)",
		"         2",
		"         3",
		"         4",
		"         5",
		"         6",
		"         7",
		"         8",
		"  9 ..  16",
		" 17 ..  32",
		" 33 ..  64",
		" 65 .. 128",
		"127 .. 256",
		"256+   ",
	}
)

func bucket(emissionLength uint32) uint32 {
	switch {
	case emissionLength <= 0:
		panic("bad emissionLength")
	case emissionLength <= 8:
		return emissionLength - 1
	case emissionLength <= 16:
		return 8
	case emissionLength <= 32:
		return 9
	case emissionLength <= 64:
		return 10
	case emissionLength <= 128:
		return 11
	case emissionLength <= 256:
		return 12
	default:
		return 13
	}
}

func buildHistogram(data []byte) error {
	if len(data) == 0 {
		return fmt.Errorf("missing GIF literal width")
	}

	literalWidth, data := uint32(data[0]), data[1:]
	clearCode := uint32(1) << literalWidth
	endCode := clearCode + 1

	saveCode := endCode
	prevCode := uint32(0)
	width := literalWidth + 1

	prefixes := [4096]uint32{}
	emissionLengths := [4096]uint32{}
	for i := uint32(0); i < clearCode; i++ {
		emissionLengths[i] = 1
	}

	bits := uint32(0)
	nBits := uint32(0)

	for {
		for nBits < width {
			if len(data) == 0 {
				return fmt.Errorf("bad LZW data: short read")
			}
			bits |= uint32(data[0]) << nBits
			data = data[1:]
			nBits += 8
		}

		code := bits & ((uint32(1) << width) - 1)
		bits >>= width
		nBits -= width

		if code < clearCode {
			// Literal, emitting exactly 1 byte.

		} else if code == clearCode {
			saveCode = endCode
			prevCode = 0
			width = literalWidth + 1
			continue

		} else if code == endCode {
			break

		} else if code <= saveCode {
			// Copy, emitting 2 or more bytes.

		} else {
			return fmt.Errorf("bad LZW data: code out of range")
		}

		n := emissionLengths[code]
		if code == saveCode {
			n = emissionLengths[prevCode] + 1
		}
		histogram[bucket(n)]++
		histogramTotal++

		if saveCode <= 4095 {
			prefixes[saveCode] = prevCode
			emissionLengths[saveCode] = emissionLengths[prevCode] + 1
			saveCode++
			if (saveCode == (1 << width)) && (width < 12) {
				width++
			}
			prevCode = code
		}
	}

	return nil
}

// The constants below are intrinsic to the GIF file format. The spec is
// http://www.w3.org/Graphics/GIF/spec-gif89a.txt
const (
	// Flags.
	fColorTableBitsMask = 0x07
	fColorTable         = 0x80

	// Sections.
	sExtension       = 0x21
	sImageDescriptor = 0x2C
	sTrailer         = 0x3B

	// Extensions.
	ePlainText      = 0x01
	eGraphicControl = 0xF9
	eComment        = 0xFE
	eApplication    = 0xFF
)


text:
package alpine.model;

import org.junit.Assert;
import org.junit.Test;

import java.sql.Timestamp;
import java.util.Date;

public class EventServiceLogTest {

    @Test
    public void idTest() {
        EventServiceLog esl = new EventServiceLog();
        esl.setId(123L);
        Assert.assertEquals(123L, esl.getId());
    }

    @Test
    public void subscriberClassTest() {
        EventServiceLog esl = new EventServiceLog();
        esl.setSubscriberClass("com.example.SubscriberClass");
        Assert.assertEquals("com.example.SubscriberClass", esl.getSubscriberClass());
    }

    @Test
    public void startedTest() {
        Timestamp ts = Timestamp.from(new Date().toInstant());
        EventServiceLog esl = new EventServiceLog();
        esl.setStarted(ts);
        Assert.assertEquals(ts, esl.getStarted());
    }

    @Test
    public void completedTest() {
        Timestamp ts = Timestamp.from(new Date().toInstant());
        EventServiceLog esl = new EventServiceLog();
        esl.setCompleted(ts);
        Assert.assertEquals(ts, esl.getCompleted());
    }
}


text:
require 'test_helper'

module CornFlakes
  class SerialTest < MiniTest::Unit::TestCase
    def setup
      @serial = Serial.new(100)
    end

    def test_to_s
      assert_equal "CCGgiWlOCA", @serial.to_s
    end

    def test_string_seed
      serial = Serial.new("test")
      assert_equal "kBrbcAjPGK", serial.to_s
    end

    def test_separator
      serial = Serial.new(100, separator: '-', separate_size: 4)
      assert_equal "CCGg-iWlO-CA", serial.to_s
    end

    def test_separator_no_separate_size
      serial = Serial.new(100, separator: '-')
      assert_equal "CCGgiWlOCA", serial.to_s
    end

    def test_no_separator_with_separate_size
      serial = Serial.new(100, separate_size: 4)
      assert_equal "CCGgiWlOCA", serial.to_s
    end

    def test_immutable_to_s
      @serial.to_s
      @serial.to_s
      @serial.to_s
      assert_equal "CCGgiWlOCA", @serial.to_s
    end

    def test_next
      assert_equal "hpDcTGIUMU", @serial.next.to_s
    end

    def test_string_seed_next
      serial = Serial.new("test").next
      assert_equal "wjElyYbGrx", serial.to_s
    end

    def test_separator_next
      serial = Serial.new(100, separator: '-', separate_size: 4).next
      assert_equal "hpDc-TGIU-MU", serial.to_s
    end

    def test_ignores_next
      serial = Serial.new(100, ignores: ['h', 'T']).next # next: hpDcTGIUMU
      assert !(serial.to_s.include?('h'))
      assert !(serial.to_s.include?('T'))
    end

    def test_prefix_and_suffix_next
      serial = Serial.new(100, prefix: "A-", suffix: "-Z").next
      assert_equal "A-hpDcTGIUMU-Z", serial.to_s
    end

    def test_default_length_is_10
      assert_equal 10, @serial.to_s.size
    end

    def test_set_length
      serial = Serial.new(100, length: 5)
      assert_equal "CCGgi", serial.to_s
      assert_equal 5, serial.to_s.size
    end

    def test_ignore_chars
      serial = Serial.new(100, ignores: ['g', 'A'])
      assert !(serial.to_s.include?('g'))
      assert !(serial.to_s.include?('A'))
    end

    def test_prefix
      serial = Serial.new(100, prefix: "A-")
      assert_equal "A-CCGgiWlOCA", serial.to_s
    end

    def test_suffix
      serial = Serial.new(100, suffix: "-Z")
      assert_equal "CCGgiWlOCA-Z", serial.to_s
    end

    def test_prefix_and_suffix
      serial = Serial.new(100, prefix: "A-", suffix: "-Z")
      assert_equal "A-CCGgiWlOCA-Z", serial.to_s
    end

    def test_length_is_not_affected_by_prefix
      serial = Serial.new(100, prefix: "A-")
      assert_equal 12, serial.to_s.size
    end

    def test_length_is_not_affected_by_suffix
      serial = Serial.new(100, suffix: "-Z")
      assert_equal 12, serial.to_s.size
    end

    def test_length_is_not_affected_by_prefix_and_suffix
      serial = Serial.new(100, prefix: "A-", suffix: "-Z")
      assert_equal 14, serial.to_s.size
    end

    def test_separator_is_not_affected_by_prefix_and_suffix
      serial = Serial.new(100, separator: '-', separate_size: 4, prefix: "A-", suffix: "-Z")
      assert_equal "A-CCGg-iWlO-CA-Z", serial.to_s
    end

  end
end


text:
<!DOCTYPE html>

    <title></title>


text:
COMPONENT=TestDripSend

PFLAGS += -I$(TOSDIR)/../beta/Drip/
PFLAGS += -I$(TOSDIR)/../contrib/nucleus/tos/lib/Nucleus

include $(TOSDIR)/../apps/Makerules


text:
<?php
/**
* Verb      Path                  Action
* GET       /members              index
* GET       /members/create       create
* POST      /members              store
* GET       /members/{id}         show
* GET       /members/{id}/edit    edit
* PUT/PATCH /members/{id}         update
* DELETE    /members/{id}         destroy
*/
class MembersController extends BaseController {

  /**
  * The database table implementation.
  *
  * @var Members
  */
  protected $member_roles;

  /**
  * Set our Member instance.
  *
  * @param Member $member
  * @return void
  */
  public function __construct(MemberRoles $member_roles)
  {
    $this->member_roles = $member_roles;
  }

  /**
  * GET -> /members
  *
  * @return View
  */
  public function index ()
  {
    $roles = $this->member_roles->with(array('members' => function($query)
    {

      $query->orderBy('last_name')->orderBy('first_name');

    }))
    ->where('id', '>', 0)->get();

    return View::make('members.index')->with('roles', $roles);
  }

}


text:
namespace emu
{
    class YamlReader : public ISerializer
    {
    public:
        static YamlReader* create();
        static void destroy(YamlReader& instance);

        virtual bool read(const std::string& data) = 0;
    };

    class YamlWriter : public ISerializer
    {
    public:
        static YamlWriter* create();
        static void destroy(YamlWriter& instance);

        virtual bool write(std::string& data) = 0;
    };
}


text:
- Concatenate files
- Sourcemaps support
- Minify with Terser (ES5 and ES6)

## Options

```js
require("gulp-task-maker").task("gulp-tasks/minjs.js", {
  // (Required) Source can be a single script or pattern,
  // or an array of paths or patterns
  src: "assets/scripts/*.js",

  // (Required) Destination can be a folder name, or a filename ending in ".js".
  // The main difference is when building more than one script.
  // - Filename ending in ".js": the result will be concatenated
  // - Otherwise: original filenames are used, and put in the destination folder.
  dest: "public/css/main.js",

  // (Optional; defaults to false)
  // File patterns to watch for changes
  watch: true,

  // (Optional; defaults to true)
  // Should we minify with csso?
  minify: true,

  // (Optional; pass a filename to use)
  // Should we concatenate all resulting files?
  concat: undefined,

  // (Optional; defaults to "."; false to disable)
  // Where should we write sourcemaps (relative to "dest")
  sourcemaps: ".",

  // (Optional; uses terser-js defaults)
  // Accepts an object of terser options:
  // https://github.com/terser-js/terser#minify-options
  terser: undefined
})
```


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

import com.facebook.airlift.configuration.testing.ConfigAssertions;
import com.facebook.presto.execution.scheduler.NodeSchedulerConfig;
import com.google.common.collect.ImmutableMap;
import org.testng.annotations.Test;

import java.util.Map;

import static com.facebook.presto.execution.scheduler.NodeSchedulerConfig.NetworkTopologyType.LEGACY;
import static com.facebook.presto.execution.scheduler.NodeSchedulerConfig.ResourceAwareSchedulingStrategy.RANDOM;
import static com.facebook.presto.execution.scheduler.NodeSchedulerConfig.ResourceAwareSchedulingStrategy.TTL;
import static com.facebook.presto.execution.scheduler.NodeSelectionHashStrategy.CONSISTENT_HASHING;
import static com.facebook.presto.execution.scheduler.NodeSelectionHashStrategy.MODULAR_HASHING;

public class TestNodeSchedulerConfig
{
    @Test
    public void testDefaults()
    {
        ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(NodeSchedulerConfig.class)
                .setNetworkTopology(LEGACY)
                .setMinCandidates(10)
                .setMaxSplitsPerNode(100)
                .setMaxPendingSplitsPerTask(10)
                .setMaxUnacknowledgedSplitsPerTask(500)
                .setIncludeCoordinator(true)
                .setNodeSelectionHashStrategy(MODULAR_HASHING)
                .setMinVirtualNodeCount(1000)
                .setResourceAwareSchedulingStrategy(RANDOM));
    }

    @Test
    public void testExplicitPropertyMappings()
    {
        Map<String, String> properties = new ImmutableMap.Builder<String, String>()
                .put("node-scheduler.network-topology", "flat")
                .put("node-scheduler.min-candidates", "11")
                .put("node-scheduler.include-coordinator", "false")
                .put("node-scheduler.max-pending-splits-per-task", "11")
                .put("node-scheduler.max-unacknowledged-splits-per-task", "501")
                .put("node-scheduler.max-splits-per-node", "101")
                .put("node-scheduler.node-selection-hash-strategy", "CONSISTENT_HASHING")
                .put("node-scheduler.consistent-hashing-min-virtual-node-count", "2000")
                .put("experimental.resource-aware-scheduling-strategy", "TTL")
                .build();

        NodeSchedulerConfig expected = new NodeSchedulerConfig()
                .setNetworkTopology("flat")
                .setIncludeCoordinator(false)
                .setMaxSplitsPerNode(101)
                .setMaxPendingSplitsPerTask(11)
                .setMaxUnacknowledgedSplitsPerTask(501)
                .setMinCandidates(11)
                .setNodeSelectionHashStrategy(CONSISTENT_HASHING)
                .setMinVirtualNodeCount(2000)
                .setResourceAwareSchedulingStrategy(TTL);

        ConfigAssertions.assertFullMapping(properties, expected);
    }
}


text:
require 'feature_spec_helper'

feature 'The Inbox album', js: true do
  given!(:user) { create :real_user, password: 'abc' }
  given!(:photo) { create :real_photo, user: user }

  subject(:album_page) { Pages::Album.open('Inbox') }

  context "when authenticated" do
    before do
      Pages::Authentication.authenticate(user.email, 'abc')
    end

    scenario 'is shown at the root path' do
      visit '/'
      expect(Pages::Navigation.new).to have_active_item('Inbox')
    end

    scenario 'has photos not in another album' do
      # TODO: enhance by creating a photo in a different album that will not appear here
      expect(album_page).to have_photos([photo])
    end
  end

  context "when not authenticated" do
    scenario "is displayed after logging in" do
      visit '/'
      expect(Pages::Album.new).not_to be_present
      Pages::Authentication.authenticate(user.email, 'abc')
      visit '/'
      expect(Pages::Album.new).to be_present
    end
  end
end


text:
package com.jayway.awaitility.proxy;

import com.jayway.awaitility.classes.ClassWithMethods;
import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

public class ProxyCreatorTest {

    @Test
    public void interceptsStandardMethodCalls() throws Exception {
        ClassWithMethods object = (ClassWithMethods) ProxyCreator.create(ClassWithMethods.class,
                new InvocationHandler() {

                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        return "test";
                    }
                });

        assertEquals("test", object.aMethod());
    }

    @Test
    public void interceptsReflectionMethodCalls() throws Exception {
        ClassWithMethods object = (ClassWithMethods) ProxyCreator.create(ClassWithMethods.class,
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        return "test";
                    }
                });
        Method method = object.getClass().getMethod("aMethod");
        assertEquals("test", method.invoke(object));
    }
}


text:
#region Usings

using System;

#endregion

namespace de.ahzf.Styx
{

    /// <summary>
    /// The DuplicateFilterArrow will not allow a duplicate object to pass through it.
    /// This is accomplished by the Arrow maintaining an internal HashSet that is used
    /// to store a history of previously seen objects.
    /// Thus, the more unique objects that pass through this Arrow, the slower it
    /// becomes as a log_2 index is checked for every object.
    /// </summary>
    public static class DuplicateFilterArrowExtensions
    {

        #region DuplicateFilter(this ArrowSender)

        /// <summary>
        /// The DuplicateFilterArrow will not allow a duplicate object to pass through it.
        /// This is accomplished by the Arrow maintaining an internal HashSet that is used
        /// to store a history of previously seen objects.
        /// Thus, the more unique objects that pass through this Arrow, the slower it
        /// becomes as a log_2 index is checked for every object.
        /// </summary>
        /// <param name="ArrowSender">The sender of the messages/objects.</param>
        public static DuplicateFilterArrow<TMessage> DuplicateFilter<TMessage>(this IArrowSender<TMessage> ArrowSender)
        {
            var _DuplicateFilterArrow = new DuplicateFilterArrow<TMessage>();
            ArrowSender.OnMessageAvailable += _DuplicateFilterArrow.ReceiveMessage;
            return _DuplicateFilterArrow;
        }

        #endregion

        #region DuplicateFilter(this ArrowSender, MessageRecipient.Recipient, params MessageRecipient.Recipients)

        /// <summary>
        /// The DuplicateFilterArrow will not allow a duplicate object to pass through it.
        /// This is accomplished by the Arrow maintaining an internal HashSet that is used
        /// to store a history of previously seen objects.
        /// Thus, the more unique objects that pass through this Arrow, the slower it
        /// becomes as a log_2 index is checked for every object.
        /// </summary>
        /// <param name="ArrowSender">The sender of the messages/objects.</param>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">Further recipients of the processed messages.</param>
        public static DuplicateFilterArrow<TMessage> DuplicateFilter<TMessage>(this IArrowSender<TMessage> ArrowSender, MessageRecipient<TMessage> Recipient, params MessageRecipient<TMessage>[] Recipients)
        {
            var _DuplicateFilterArrow = new DuplicateFilterArrow<TMessage>(Recipient, Recipients);
            ArrowSender.OnMessageAvailable += _DuplicateFilterArrow.ReceiveMessage;
            return _DuplicateFilterArrow;
        }

        #endregion

        #region DuplicateFilter(this ArrowSender, IArrowReceiver.Recipient, params IArrowReceiver.Recipients)

        /// <summary>
        /// The DuplicateFilterArrow will not allow a duplicate object to pass through it.
        /// This is accomplished by the Arrow maintaining an internal HashSet that is used
        /// to store a history of previously seen objects.
        /// Thus, the more unique objects that pass through this Arrow, the slower it
        /// becomes as a log_2 index is checked for every object.
        /// </summary>
        /// <param name="ArrowSender">The sender of the messages/objects.</param>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">Further recipients of the processed messages.</param>
        public static DuplicateFilterArrow<TMessage> DuplicateFilter<TMessage>(this IArrowSender<TMessage> ArrowSender, IArrowReceiver<TMessage> Recipient, params IArrowReceiver<TMessage>[] Recipients)
        {
            var _DuplicateFilterArrow = new DuplicateFilterArrow<TMessage>(Recipient, Recipients);
            ArrowSender.OnMessageAvailable += _DuplicateFilterArrow.ReceiveMessage;
            return _DuplicateFilterArrow;
        }

        #endregion

    }

}


text:
namespace System.Runtime.InteropServices
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
    internal sealed class StructLayoutAttribute : Attribute
    {
        public StructLayoutAttribute(LayoutKind layoutKind)
        {
        }

        // These fields are expected by C# compiler,
        // so just disable the 'unused' warning
#pragma warning disable 649
        public LayoutKind Value;
        public int Pack;
        public int Size;
        public CharSet CharSet;
    }
}


text:
.. include:: ../../Includes.txt

============================================================
Deprecation: #68860 - Deprecate SelectImage.initEventHandler
============================================================

See :issue:`68860`

Description
===========

Removes the calls of `SelectImage.initEventHandler` method.
This was limited to WebKit UserAgents and the provided implementation of
`require` was wrong, so that the EventListener was not registered at all.
Nevertheless the functionality of drag and drop is not broken without the
initEventHandler.

Impact
======

Throws console log with deprecation message.

Affected Installations
======================

All installations calling `SelectImage.initEventHandler`.

Migration
=========

Remove the call of `SelectImage.initEventHandler`.


text:
package stdlib

import (
	"reflect"
)

func init() {
	Symbols["reflect"] = map[string]reflect.Value{
		// function, constant and variable definitions
		"Append":          reflect.ValueOf(reflect.Append),
		"AppendSlice":     reflect.ValueOf(reflect.AppendSlice),
		"Array":           reflect.ValueOf(reflect.Array),
		"ArrayOf":         reflect.ValueOf(reflect.ArrayOf),
		"Bool":            reflect.ValueOf(reflect.Bool),
		"BothDir":         reflect.ValueOf(reflect.BothDir),
		"Chan":            reflect.ValueOf(reflect.Chan),
		"ChanOf":          reflect.ValueOf(reflect.ChanOf),
		"Complex128":      reflect.ValueOf(reflect.Complex128),
		"Complex64":       reflect.ValueOf(reflect.Complex64),
		"Copy":            reflect.ValueOf(reflect.Copy),
		"DeepEqual":       reflect.ValueOf(reflect.DeepEqual),
		"Float32":         reflect.ValueOf(reflect.Float32),
		"Float64":         reflect.ValueOf(reflect.Float64),
		"Func":            reflect.ValueOf(reflect.Func),
		"FuncOf":          reflect.ValueOf(reflect.FuncOf),
		"Indirect":        reflect.ValueOf(reflect.Indirect),
		"Int":             reflect.ValueOf(reflect.Int),
		"Int16":           reflect.ValueOf(reflect.Int16),
		"Int32":           reflect.ValueOf(reflect.Int32),
		"Int64":           reflect.ValueOf(reflect.Int64),
		"Int8":            reflect.ValueOf(reflect.Int8),
		"Interface":       reflect.ValueOf(reflect.Interface),
		"Invalid":         reflect.ValueOf(reflect.Invalid),
		"MakeChan":        reflect.ValueOf(reflect.MakeChan),
		"MakeFunc":        reflect.ValueOf(reflect.MakeFunc),
		"MakeMap":         reflect.ValueOf(reflect.MakeMap),
		"MakeMapWithSize": reflect.ValueOf(reflect.MakeMapWithSize),
		"MakeSlice":       reflect.ValueOf(reflect.MakeSlice),
		"Map":             reflect.ValueOf(reflect.Map),
		"MapOf":           reflect.ValueOf(reflect.MapOf),
		"New":             reflect.ValueOf(reflect.New),
		"NewAt":           reflect.ValueOf(reflect.NewAt),
		"Ptr":             reflect.ValueOf(reflect.Ptr),
		"PtrTo":           reflect.ValueOf(reflect.PtrTo),
		"RecvDir":         reflect.ValueOf(reflect.RecvDir),
		"Select":          reflect.ValueOf(reflect.Select),
		"SelectDefault":   reflect.ValueOf(reflect.SelectDefault),
		"SelectRecv":      reflect.ValueOf(reflect.SelectRecv),
		"SelectSend":      reflect.ValueOf(reflect.SelectSend),
		"SendDir":         reflect.ValueOf(reflect.SendDir),
		"Slice":           reflect.ValueOf(reflect.Slice),
		"SliceOf":         reflect.ValueOf(reflect.SliceOf),
		"String":          reflect.ValueOf(reflect.String),
		"Struct":          reflect.ValueOf(reflect.Struct),
		"StructOf":        reflect.ValueOf(reflect.StructOf),
		"Swapper":         reflect.ValueOf(reflect.Swapper),
		"TypeOf":          reflect.ValueOf(reflect.TypeOf),
		"Uint":            reflect.ValueOf(reflect.Uint),
		"Uint16":          reflect.ValueOf(reflect.Uint16),
		"Uint32":          reflect.ValueOf(reflect.Uint32),
		"Uint64":          reflect.ValueOf(reflect.Uint64),
		"Uint8":           reflect.ValueOf(reflect.Uint8),
		"Uintptr":         reflect.ValueOf(reflect.Uintptr),
		"UnsafePointer":   reflect.ValueOf(reflect.UnsafePointer),
		"ValueOf":         reflect.ValueOf(reflect.ValueOf),
		"Zero":            reflect.ValueOf(reflect.Zero),

		// type definitions
		"ChanDir":      reflect.ValueOf((*reflect.ChanDir)(nil)),
		"Kind":         reflect.ValueOf((*reflect.Kind)(nil)),
		"MapIter":      reflect.ValueOf((*reflect.MapIter)(nil)),
		"Method":       reflect.ValueOf((*reflect.Method)(nil)),
		"SelectCase":   reflect.ValueOf((*reflect.SelectCase)(nil)),
		"SelectDir":    reflect.ValueOf((*reflect.SelectDir)(nil)),
		"SliceHeader":  reflect.ValueOf((*reflect.SliceHeader)(nil)),
		"StringHeader": reflect.ValueOf((*reflect.StringHeader)(nil)),
		"StructField":  reflect.ValueOf((*reflect.StructField)(nil)),
		"StructTag":    reflect.ValueOf((*reflect.StructTag)(nil)),
		"Type":         reflect.ValueOf((*reflect.Type)(nil)),
		"Value":        reflect.ValueOf((*reflect.Value)(nil)),
		"ValueError":   reflect.ValueOf((*reflect.ValueError)(nil)),

		// interface wrapper definitions
		"_Type": reflect.ValueOf((*_reflect_Type)(nil)),
	}
}

// _reflect_Type is an interface wrapper for Type type
type _reflect_Type struct {
	WAlign           func() int
	WAssignableTo    func(u reflect.Type) bool
	WBits            func() int
	WChanDir         func() reflect.ChanDir
	WComparable      func() bool
	WConvertibleTo   func(u reflect.Type) bool
	WElem            func() reflect.Type
	WField           func(i int) reflect.StructField
	WFieldAlign      func() int
	WFieldByIndex    func(index []int) reflect.StructField
	WFieldByName     func(name string) (reflect.StructField, bool)
	WFieldByNameFunc func(match func(string) bool) (reflect.StructField, bool)
	WImplements      func(u reflect.Type) bool
	WIn              func(i int) reflect.Type
	WIsVariadic      func() bool
	WKey             func() reflect.Type
	WKind            func() reflect.Kind
	WLen             func() int
	WMethod          func(a0 int) reflect.Method
	WMethodByName    func(a0 string) (reflect.Method, bool)
	WName            func() string
	WNumField        func() int
	WNumIn           func() int
	WNumMethod       func() int
	WNumOut          func() int
	WOut             func(i int) reflect.Type
	WPkgPath         func() string
	WSize            func() uintptr
	WString          func() string
}

func (W _reflect_Type) Align() int                                   { return W.WAlign() }
func (W _reflect_Type) AssignableTo(u reflect.Type) bool             { return W.WAssignableTo(u) }
func (W _reflect_Type) Bits() int                                    { return W.WBits() }
func (W _reflect_Type) ChanDir() reflect.ChanDir                     { return W.WChanDir() }
func (W _reflect_Type) Comparable() bool                             { return W.WComparable() }
func (W _reflect_Type) ConvertibleTo(u reflect.Type) bool            { return W.WConvertibleTo(u) }
func (W _reflect_Type) Elem() reflect.Type                           { return W.WElem() }
func (W _reflect_Type) Field(i int) reflect.StructField              { return W.WField(i) }
func (W _reflect_Type) FieldAlign() int                              { return W.WFieldAlign() }
func (W _reflect_Type) FieldByIndex(index []int) reflect.StructField { return W.WFieldByIndex(index) }
func (W _reflect_Type) FieldByName(name string) (reflect.StructField, bool) {
	return W.WFieldByName(name)
}
func (W _reflect_Type) FieldByNameFunc(match func(string) bool) (reflect.StructField, bool) {
	return W.WFieldByNameFunc(match)
}
func (W _reflect_Type) Implements(u reflect.Type) bool                { return W.WImplements(u) }
func (W _reflect_Type) In(i int) reflect.Type                         { return W.WIn(i) }
func (W _reflect_Type) IsVariadic() bool                              { return W.WIsVariadic() }
func (W _reflect_Type) Key() reflect.Type                             { return W.WKey() }
func (W _reflect_Type) Kind() reflect.Kind                            { return W.WKind() }
func (W _reflect_Type) Len() int                                      { return W.WLen() }
func (W _reflect_Type) Method(a0 int) reflect.Method                  { return W.WMethod(a0) }
func (W _reflect_Type) MethodByName(a0 string) (reflect.Method, bool) { return W.WMethodByName(a0) }
func (W _reflect_Type) Name() string                                  { return W.WName() }
func (W _reflect_Type) NumField() int                                 { return W.WNumField() }
func (W _reflect_Type) NumIn() int                                    { return W.WNumIn() }
func (W _reflect_Type) NumMethod() int                                { return W.WNumMethod() }
func (W _reflect_Type) NumOut() int                                   { return W.WNumOut() }
func (W _reflect_Type) Out(i int) reflect.Type                        { return W.WOut(i) }
func (W _reflect_Type) PkgPath() string                               { return W.WPkgPath() }
func (W _reflect_Type) Size() uintptr                                 { return W.WSize() }
func (W _reflect_Type) String() string                                { return W.WString() }


text:
/**
 *
 */
package gov.nih.nci.calims2.ui.administration.customerservice.contract;

import static org.junit.Assert.assertEquals;

import java.util.Locale;

import org.junit.Test;
import org.springframework.web.servlet.ModelAndView;

import gov.nih.nci.calims2.domain.administration.customerservice.Contract;
import gov.nih.nci.calims2.domain.administration.customerservice.enumeration.ContractStatus;
import gov.nih.nci.calims2.ui.generic.crud.CRUDAssert;
import gov.nih.nci.calims2.ui.generic.crud.CRUDTableDecorator;

/**
 * @author connollym
 *
 */
public class ContractControllerTest {

  /**
   * Test the controller constructor.
   */
  @Test
  public void testConstructor() {
    ContractController controller = new ContractController();
    CRUDAssert.assertControllerConstructor(controller, ContractController.URL_PREFIX, "administration.customerservice.contract.",
        "name", Contract.class, ContractForm.class, CRUDTableDecorator.class);

  }

  /**
   * Test the controller completeEditModel method.
   */
  @Test
  public void testCompleteEditModel() {
    ContractController controller = new ContractController();
    ModelAndView model = new ModelAndView();
    ModelAndView result = controller.completeEditModel(model, Locale.US);
    assertEquals("Wrong model returned", model, result);
    CRUDAssert.assertEnumerationCollection(result, "contractStatuses", ContractStatus.class);
  }
}


text:
package com.oracle.xmlns.webservices.jaxws_databinding;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import java.lang.annotation.Annotation;

/**
 * This file was generated by JAXB-RI v2.2.6 and afterwards modified
 * to implement appropriate Annotation
 *
 *
Java class for anonymous complex type.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *
 *
{@code
 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <attribute name="value" type="{http://www.w3.org/2001/XMLSchema}string" default="" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * }

 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "binding-type")
public class XmlBindingType implements jakarta.xml.ws.BindingType {

    @XmlAttribute(name = "value")
    protected String value;

    /**
     * Gets the value of the value property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String value() {
        return Util.nullSafe(value);
    }
    @Override
    public Class<? extends Annotation> annotationType() {
        return jakarta.xml.ws.BindingType.class;
    }
}


text:
<template name="search">
  {{#if canSearch}}

        <input id="search" type="search" class="search-field" placeholder="{{_ 'search'}}" value="{{searchQuery}}">

    {{#unless searchQueryEmpty}}

 Clear Search?

    {{/unless}}
  {{/if}}
</template>


text:
/******************************************************************************
* File Name          : pay_flt_cnv.h
* Date First Issued  : 01/15/015
* Board              : little endian
* Description        : Conversion to/from float to half-float IEEE-754
*******************************************************************************/

#ifndef __PAYTOLOATCNV
#define __PAYTOLOATCNV

#include <stdint.h>

//#include "common.h"

/******************************************************************************/
float payhalffptofloat(uint8_t *p);
/* @brief 	: Convert CAN payload bytes holding half-float to float
 * @param	: p = pointer to payload start byte
 * @return	: float
*******************************************************************************/
void floattopayhalffp(uint8_t *p, float f);
/* @brief 	: Convert float to CAN payload bytes holding half-float representation
 * @param	: p = pointer to payload start byte
 * @param	: f = single precision float to be converted to payload
*******************************************************************************/
void floattopay3qtrfp(uint8_t *p, float f);
/* @brief 	: Convert float to CAN payload bytes holding 3/4 fp representation
 * @param	: p = pointer to payload start byte
 * @param	: f = single precision float to be converted to payload
*******************************************************************************/
float pay3qtrfptofloat(uint8_t *p);
/* @brief 	: Convert CAN payload bytes holding 3/4 fp representation to float
 * @param	: p = pointer to payload start byte
 * @return	: float
*******************************************************************************/
void floattopaysinglefp(uint8_t *p, float f);
/* @brief 	: Convert float to CAN payload bytes holding single precision representation
 * @param	: p = pointer to payload start byte
 * @param	: f = single precision float to be converted to payload
*******************************************************************************/
float paysinglefptofloat(uint8_t *p);
/* @brief 	: Convert float to CAN payload bytes holding single precision representation
 * @param	: p = pointer to payload start byte
 * @return	: float
*******************************************************************************/

#endif


text:
[![Total Downloads](https://poser.pugx.org/groundsix/config/d/total.png)](https://packagist.org/packages/groundsix/config)

This component allows you to merge a number of configuration files together. Typically you may use a .gitignore so that all developers in your team can maintain their own development-environment-specific settings, however this approach allows you to keep a version controlled configuration file which contains the structure and shared contents, and each developer can override their own settings in a seperate file which they control.

The resulting merged configuration will be an array.

## Installation

Add the project to your composer.json file

	{
	    "require": {
	        "groundsix/config": "dev-master"
	    }
	}
Install the project

	php composer.phar update

## Usage

	require_once(__DIR__.'/vendor/autoload.php');
    $xml_loader = new \GroundSix\Config\XmlLoader(new \GroundSix\Config\ConfigurationsCollection());
    $xml_loader->loadFiles(__DIR__.'/config1.xml', __DIR__.'/config2.xml');
    $merger = new \GroundSix\Config\Merger();
    $config = $merger->merge($xml_loader->getConfigurations());

## Example

#### Config 1

	<?xml version="1.0" ?>
	<settings>
	    <application>
	        <template_set>twig</template_set>
	        <environment>production</environment>
	    </application>
	    <notice>
	        <enabled>true</enabled>
	    </notice>
	    <databases>
	        <mysql>
	            <user>production</user>
	        </mysql>
	    </databases>
	    <search>
	        <period>31536000</period>
	    </search>
	    <payments>
	        <sandbox>0</sandbox>
	        <methods>
	            <provider_a>
	                <app_id>A</app_id>
	                <app_secret>S</app_secret>
	                <merchant_id>M</merchant_id>
	                <access_token>T</access_token>
	            </provider_a>
	        </methods>
	    </payments>
	</settings>

### Config 2

	<?xml version="1.0" ?>
	<settings>
	    <application>
	        <environment>staging</environment>
	    </application>
	    <databases>
	        <mysql>
	            <user>staging</user>
	        </mysql>
	    </databases>
	    <payments>
	        <sandbox>1</sandbox>
	        <methods>
	            <provider_a>
	                <app_id>A2</app_id>
	                <app_secret>S2</app_secret>
	                <merchant_id>M2</merchant_id>
	                <access_token>T2</access_token>
	            </provider_a>
	        </methods>
	    </payments>
	</settings>

#### Merged config

	Array
	(
	    [application] => Array
	        (
	            [template_set] => twig
	            [environment] => staging
	        )
	    [notice] => Array
	        (
	            [enabled] => true
	        )
	    [databases] => Array
	        (
	            [mysql] => Array
	                (
	                    [user] => staging
	                )
	        )
	    [search] => Array
	        (
	            [period] => 31536000
	        )
	    [payments] => Array
	        (
	            [sandbox] => 1
	            [methods] => Array
	                (
	                    [provider_a] => Array
	                        (
	                            [app_id] => A2
	                            [app_secret] => S2
	                            [merchant_id] => M2
	                            [access_token] => T2
	                        )
	                )
	        )
	)


text:
'use strict';

/**
 * Module dependencies.
 */
var path = require('path'),
  mongoose = require('mongoose'),
  Device = mongoose.model('Device'),
  errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
  _ = require('lodash');

/**
 * Create a Device
 */
exports.create = function(req, res) {
  var device = new Device(req.body);
  device.user = req.user;

  var seccode = req.cookies.seccode;
  if (seccode !== process.env.SEC_CODE) {
    return res.status(401).send();
  }

  device.save(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      var socketio = req.app.get('socketio');
      socketio.sockets.emit('device.created', device);
      res.jsonp(device);
    }
  });
};

/**
 * Show the current Device
 */
exports.read = function(req, res) {
  // convert mongoose document to JSON
  var device = req.device ? req.device.toJSON() : {};

  // Add a custom field to the Article, for determining if the current User is the "owner".
  // NOTE: This field is NOT persisted to the database, since it doesn't exist in the Article model.
  device.isCurrentUserOwner = req.user && device.user && device.user._id.toString() === req.user._id.toString() ? true : false;

  res.jsonp(device);
};

/**
 * Update a Device
 */
exports.update = function(req, res) {
  var device = req.device ;

  device = _.extend(device , req.body);

  device.save(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      res.jsonp(device);
    }
  });
};

/**
 * Delete an Device
 */
exports.delete = function(req, res) {
  var device = req.device ;

  device.remove(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      res.jsonp(device);
    }
  });
};

/**
 * List of Devices
 */
exports.list = function(req, res) {
  Device.find().sort('-created').populate('user', 'displayName').exec(function(err, devices) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      res.jsonp(devices);
    }
  });
};

/**
 * Device middleware
 */
exports.deviceByID = function(req, res, next, id) {

  if (!mongoose.Types.ObjectId.isValid(id)) {
    return res.status(400).send({
      message: 'Device is invalid'
    });
  }

  Device.findById(id).populate('user', 'displayName').exec(function (err, device) {
    if (err) {
      return next(err);
    } else if (!device) {
      return res.status(404).send({
        message: 'No Device with that identifier has been found'
      });
    }
    req.device = device;
    next();
  });
};


text:
#include <gasnet.h>
#include <gasnet_tools.h>

#include <test.h>

/* ------------------------------------------------------------------------------------ */
int main(int argc, char **argv) {
  int iters = 0, threads=0;
  int arg = 1;
  gasnet_handlerentry_t *htable; int htable_cnt;
  char *test_sections = NULL;
  gasnett_diagnostic_gethandlers(&htable, &htable_cnt);

  GASNET_Safe(gasnet_init(&argc, &argv));
  GASNET_Safe(gasnet_attach(htable, htable_cnt,
                            TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
  #if GASNET_PAR
    test_init("testinternal",0,"(iters) (threadcnt) (test_sections)");
  #else
    test_init("testinternal",0,"(iters) (test_sections)");
  #endif
  TEST_PRINT_CONDUITINFO();

  if (argc > arg) iters = atoi(argv[arg++]);
  if (iters < 1) iters = 1000;
  #if GASNET_PAR
  if (argc > arg) threads = atoi(argv[arg++]);
  #endif
  if (threads < 1) threads = 4;
  #if GASNET_PAR
  threads = test_thread_limit(threads);
  #endif
  if (argc > arg) test_sections = argv[arg++];

  #if GASNET_PAR
    MSG0("Running GASNet internal diagnostics with iters=%i and threads=%i", iters, threads);
  #else
    MSG0("Running GASNet internal diagnostics with iters=%i", iters);
  #endif

  BARRIER();
  test_errs = gasnett_run_diagnostics(iters, threads, test_sections, TEST_SEGINFO());
  BARRIER();

  if (test_errs) ERR("gasnett_run_diagnostics(%i) failed.", iters);

  gasnet_exit(test_errs);
  return 0;
}


text:
package it.larus.bigdata.dossier.analyzer;

import java.util.Map;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer082;
import org.apache.flink.streaming.util.serialization.SimpleStringSchema;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * --topic news-topic --bootstrap.servers localhost:9092 --zookeeper.connect
 * localhost:2181 --group.id myGroup --tokenfile en-token.bin --namefile en-ner-person.bin
 *
 * @author Omar Rampado
 *
 */
public class FlinkNewsAnalyzer {

	public static void main(String[] args) throws Exception {
		// FIXME handle errors

		// create execution environment
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

		// parse user parameters
		ParameterTool parameterTool = ParameterTool.fromArgs(args);

		DataStream<String> messageStream = env.addSource(new FlinkKafkaConsumer082<>(parameterTool.getRequired("topic"),
				new SimpleStringSchema(), parameterTool.getProperties()));

		final NaturalLanguageProcessor languageProcessor = new NaturalLanguageProcessor(parameterTool.getRequired("tokenfile"),parameterTool.getRequired("namefile"));

		messageStream.rebalance().map(new MapFunction<String, String>() {
			private static final long serialVersionUID = -1;

			private ObjectMapper mapper = new ObjectMapper();

			@Override
			public String map(String value) throws Exception {

				Map<String, String> map = mapper.readValue(value, new TypeReference<Map<String, Object>>() {
				});
				String body = map.get("body_text");

				return "News title: " + map.get("title") + " => " + languageProcessor.extractNames(body);
			}
		}).print();

		env.execute();
	}

}


text:
This repository contains my [OpenCon2017 application](https://github.com/SamanthaHindle/OpenCon/blob/master/OpenCon2017%20Application.md). I hope you will find it both interesting and useful.

It also includes some of my upcoming ideas for Open Science workshops, so if you are interested in contributing to these, please don't hesitate to create an issue.

I will also post future updates related to the Open Access and Open Education Week events described in my application.


text:
<?php

namespace Konstrui\Task;

class CleanTaskIntegrationTest extends \PHPUnit_Framework_TestCase
{
    public function testDeletePaths()
    {
        $tmpDirPath = __DIR__ . '/tmp/';
        mkdir($tmpDirPath);
        touch($tmpDirPath . 'test-file');
        mkdir($tmpDirPath . 'test-subdirectory');
        touch($tmpDirPath . 'test-subdirectory/another-file');
        $tmpFilePath = __DIR__ . 'test-file';

        $cleanupTask = new CleanTask(
            [
                $tmpDirPath,
                $tmpFilePath,
            ]
        );
        $cleanupTask->perform();

        $this->assertFileNotExists($tmpDirPath);
        $this->assertFileNotExists($tmpFilePath);
    }

    public function testSkipsEmptyPaths()
    {
        $cleanupTask = new CleanTask(
            [
                __DIR__ . '/non-existing-file',
            ]
        );
        $this->assertNull($cleanupTask->perform());
    }
}


text:
package org.lilyproject.rest.providers.json;

import org.apache.commons.io.output.CloseShieldOutputStream;
import org.lilyproject.repository.api.Blob;
import org.lilyproject.rest.ResourceException;
import org.lilyproject.tools.import_.json.BlobConverter;
import org.lilyproject.util.json.JsonFormat;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

@Provider
public class BlobMessageBodyWriter implements MessageBodyWriter<Blob> {
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        return type.equals(Blob.class) && mediaType.equals(MediaType.APPLICATION_JSON_TYPE);
    }

    public long getSize(Blob blob, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        return -1;
    }

    public void writeTo(Blob blob, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
            throws IOException, WebApplicationException {

        try {
            JsonFormat.serialize(BlobConverter.toJson(blob), new CloseShieldOutputStream(entityStream));
        } catch (Throwable e) {
            // We catch every throwable, since otherwise no one does it and we will not have any trace
            // of Errors that happened.
            throw new ResourceException("Error serializing entity.", e, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        }
    }
}


text:
layout: global
title: Advanced topics
displayTitle: Advanced topics
license: |
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
---

* Table of contents
{:toc}

`\[
\newcommand{\R}{\mathbb{R}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\x}{\mathbf{x}}
\newcommand{\y}{\mathbf{y}}
\newcommand{\wv}{\mathbf{w}}
\newcommand{\av}{\mathbf{\alpha}}
\newcommand{\bv}{\mathbf{b}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\id}{\mathbf{I}}
\newcommand{\ind}{\mathbf{1}}
\newcommand{\0}{\mathbf{0}}
\newcommand{\unit}{\mathbf{e}}
\newcommand{\one}{\mathbf{1}}
\newcommand{\zero}{\mathbf{0}}
\]`

# Optimization of linear methods (developer)

## Limited-memory BFGS (L-BFGS)
[L-BFGS](http://en.wikipedia.org/wiki/Limited-memory_BFGS) is an optimization
algorithm in the family of quasi-Newton methods to solve the optimization problems of the form
`$\min_{\wv \in\R^d} \; f(\wv)$`. The L-BFGS method approximates the objective function locally as a
quadratic without evaluating the second partial derivatives of the objective function to construct the
Hessian matrix. The Hessian matrix is approximated by previous gradient evaluations, so there is no
vertical scalability issue (the number of training features) unlike computing the Hessian matrix
explicitly in Newton's method. As a result, L-BFGS often achieves faster convergence compared with
other first-order optimizations.

[Orthant-Wise Limited-memory
Quasi-Newton](https://www.microsoft.com/en-us/research/wp-content/uploads/2007/01/andrew07scalable.pdf)
(OWL-QN) is an extension of L-BFGS that can effectively handle L1 and elastic net regularization.

L-BFGS is used as a solver for [LinearRegression](api/scala/index.html#org.apache.spark.ml.regression.LinearRegression),
[LogisticRegression](api/scala/index.html#org.apache.spark.ml.classification.LogisticRegression),
[AFTSurvivalRegression](api/scala/index.html#org.apache.spark.ml.regression.AFTSurvivalRegression)
and [MultilayerPerceptronClassifier](api/scala/index.html#org.apache.spark.ml.classification.MultilayerPerceptronClassifier).

MLlib L-BFGS solver calls the corresponding implementation in [breeze](https://github.com/scalanlp/breeze/blob/master/math/src/main/scala/breeze/optimize/LBFGS.scala).

## Normal equation solver for weighted least squares

MLlib implements normal equation solver for [weighted least squares](https://en.wikipedia.org/wiki/Least_squares#Weighted_least_squares) by [WeightedLeastSquares]({{site.SPARK_GITHUB_URL}}/blob/v{{site.SPARK_VERSION_SHORT}}/mllib/src/main/scala/org/apache/spark/ml/optim/WeightedLeastSquares.scala).

Given $n$ weighted observations $(w_i, a_i, b_i)$:

* $w_i$ the weight of i-th observation
* $a_i$ the features vector of i-th observation
* $b_i$ the label of i-th observation

The number of features for each observation is $m$. We use the following weighted least squares formulation:
`\[
\min_{\mathbf{x}}\frac{1}{2} \sum_{i=1}^n \frac{w_i(\mathbf{a}_i^T \mathbf{x} -b_i)^2}{\sum_{k=1}^n w_k} + \frac{\lambda}{\delta}\left[\frac{1}{2}(1 - \alpha)\sum_{j=1}^m(\sigma_j x_j)^2 + \alpha\sum_{j=1}^m |\sigma_j x_j|\right]
\]`
where $\lambda$ is the regularization parameter, $\alpha$ is the elastic-net mixing parameter, $\delta$ is the population standard deviation of the label
and $\sigma_j$ is the population standard deviation of the j-th feature column.

This objective function requires only one pass over the data to collect the statistics necessary to solve it. For an
$n \times m$ data matrix, these statistics require only $O(m^2)$ storage and so can be stored on a single machine when $m$ (the number of features) is
relatively small. We can then solve the normal equations on a single machine using local methods like direct Cholesky factorization or iterative optimization programs.

Spark MLlib currently supports two types of solvers for the normal equations: Cholesky factorization and Quasi-Newton methods (L-BFGS/OWL-QN). Cholesky factorization
depends on a positive definite covariance matrix (i.e. columns of the data matrix must be linearly independent) and will fail if this condition is violated. Quasi-Newton methods
are still capable of providing a reasonable solution even when the covariance matrix is not positive definite, so the normal equation solver can also fall back to
Quasi-Newton methods in this case. This fallback is currently always enabled for the `LinearRegression` and `GeneralizedLinearRegression` estimators.

`WeightedLeastSquares` supports L1, L2, and elastic-net regularization and provides options to enable or disable regularization and standardization. In the case where no
L1 regularization is applied (i.e. $\alpha = 0$), there exists an analytical solution and either Cholesky or Quasi-Newton solver may be used. When $\alpha > 0$ no analytical
solution exists and we instead use the Quasi-Newton solver to find the coefficients iteratively.

In order to make the normal equation approach efficient, `WeightedLeastSquares` requires that the number of features is no more than 4096. For larger problems, use L-BFGS instead.

## Iteratively reweighted least squares (IRLS)

MLlib implements [iteratively reweighted least squares (IRLS)](https://en.wikipedia.org/wiki/Iteratively_reweighted_least_squares) by [IterativelyReweightedLeastSquares]({{site.SPARK_GITHUB_URL}}/blob/v{{site.SPARK_VERSION_SHORT}}/mllib/src/main/scala/org/apache/spark/ml/optim/IterativelyReweightedLeastSquares.scala).
It can be used to find the maximum likelihood estimates of a generalized linear model (GLM), find M-estimator in robust regression and other optimization problems.
Refer to [Iteratively Reweighted Least Squares for Maximum Likelihood Estimation, and some Robust and Resistant Alternatives](http://www.jstor.org/stable/2345503) for more information.

It solves certain optimization problems iteratively through the following procedure:

* linearize the objective at current solution and update corresponding weight.
* solve a weighted least squares (WLS) problem by WeightedLeastSquares.
* repeat above steps until convergence.

Since it involves solving a weighted least squares (WLS) problem by `WeightedLeastSquares` in each iteration,
it also requires the number of features to be no more than 4096.
Currently IRLS is used as the default solver of [GeneralizedLinearRegression](api/scala/index.html#org.apache.spark.ml.regression.GeneralizedLinearRegression).


text:
<link rel="import" href="grapp-websocket-rails-subscribe.html">

<dom-module id="grapp-websocket-rails">

  <!-- build:script inline grapp-websocket-rails -->
  <script src="grapp-websocket-rails.js"></script>
  <!-- /build -->

  <!-- build:script inline websocket-rails -->
  <script src="websocket_rails/websocket_rails.js"></script>
  <script src="websocket_rails/event.js"></script>
  <script src="websocket_rails/abstract_connection.js"></script>
  <script src="websocket_rails/http_connection.js"></script>
  <script src="websocket_rails/websocket_connection.js"></script>
  <script src="websocket_rails/channel.js"></script>
  <!-- /build -->

</dom-module>


text:
/* all script functions of this site defined in this file */
function confirm_on_del(val)
{

	if(val.length==0)
	val = "Are you sure?";

		if(confirm(val))
			return true;
		else
			return false;
}

function alert_delete(val1,val2,val3)
{
    if(confirm_on_del(''))
    {
        str=val2+"&id="+val1+"&type="+val3;
        window.location.href=str;
    }
}

function chk_email(str)
{
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    {
       testresults = true;
    }
    else
    {
       testresults = false;
    }
    return (testresults)
}

function chk_characters(obj, max_length)
{
	if(obj.value.length > max_length)
	{
		obj.value=obj.value.substr(0, max_length);
	}
}

function doformaction(pageno)
{
    document.search_form.page.value=pageno;
    document.search_form.submit();
}

function isValidEmail($email)
{
    return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

function onFormSubmit ()
{
    document.banner.email.value = "Email";
    return true; // allow form submission to continue
}

function do_login()
{
    var data =  $("#login_form").serialize();
    $.post('includes/login.php',
            data,
            function (data)
            {
              if(data.status == 1)
              {
               window.location.href='http://flatfindr.com/user/';
              }
              else
              {
               alert(data.msg);
              }

             },'json'

           )

}

function do_page_login()
{
    var data =  $("#loginfrm").serialize();
    $.post('includes/login.php',
            data,
            function (data)
            {
              if(data.status == 1)
              {
               window.location.href='http://flatfindr.com/user/';
              }
              else
              {
               alert(data.msg);
              }

             },'json'

           )

}

$(document).ready(function()
{

			    $("#register").click(function(){

					alert('vishal');
                var element = $(this);
                var Id = element.attr("id");
                var loadplacecomment = $("#message");

                var username = $("#name").val();
                var email = $("#email").val();
                var password = $("#password").val();
                var mobile = $("#phonenumber").val();
                var dataString = 'name='+ username + '&email='+ email + '&password='+ password + '&phonenumber='+ mobile;

                if(username=='' || email=='' || password=='' || mobile=='' || username=='Name' || email=='Email' || password=='Password' || mobile=='Phone Number')
                {
                 document.getElementById('message').innerHTML='
Please enter all field.
';
                }

                else
                {
                    $("#flash").show();
                    $("#flash").fadeIn(400).html(' loading.....');

                    $.ajax({
                        type: "POST",
                        url: "includes/ajaxinsert.php",
                        data: dataString,
                        cache: false,
                        success: function(html)
                        {
                            loadplacecomment.html('');
                            $("#message").append(html);
                            $("#flash").hide();
                        }
                    });
                }
                return false;});
}
);

function register_user()
{
        var username = $("#uname").val();
        var email    = $("#uemail").val();
        var password = $("#upassword").val();
        var mobile   = $("#uphonenumber").val();
        var dataString = 'name='+ username + '&email='+ email + '&password='+ password + '&phonenumber='+ mobile;

        if(username=='' || email=='' || password=='' || mobile=='' || username=='Name' || email=='Email' || password=='Password' || mobile=='Phone Number')
        {
            $('#error_message').html('Please enter all field.');
        }
        else
        {
            if(chk_email(email))
            {
                $.ajax({
                type: "POST",
                url: "includes/ajaxinsert.php",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    $("#error_message").html(html);
                }
                });
            }
            else
            {
                $('#error_message').html('Please enter valid email.');
            }

        }
        return false;
}

$(document).ready(function() {

	//if submit button is clicked
	$('#submit').click(function () {

		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var phone = $('input[name=phone]');
		var location = $('textarea[name=location]');
		var txtwantto = $('select[name=txtwantto]');
		var txtprotype = $('select[name=txtprotype]');
		var image = $('input[type=file]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');

		if (email.val()=='') {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');

		if (phone.val()=='') {
			phone.addClass('hightlight');
			return false;
		} else phone.removeClass('hightlight');

		if (location.val()=='') {
			location.addClass('hightlight');
			return false;
		} else location.removeClass('hightlight');

		if (txtwantto.val()=='') {
			txtwantto.addClass('hightlight');
			return false;
		} else txtwantto.removeClass('hightlight');
		if (txtprotype.val()=='') {
			txtprotype.addClass('hightlight');
			return false;
		} else txtprotype.removeClass('hightlight');

		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&phone=' +
		phone.val() + '&location='  + encodeURIComponent(location.val()) + '&txtwantto=' + txtwantto.val() + '&txtprotype=' + txtprotype.val() + '&image=' + image.val();
		//alert(data);
		//disabled all the text fields
		$('.text').attr('disabled','true');

		//show the loading sign
		$('.loading').show();

		//start the ajax
		$.ajax({

			//GET method is used
			type: "GET",
		//this is the php file that processes the data and send mail
			url: "includes/process.php",
			//pass the data
			data: data,

			//Do not cache the page
			cache: false,

			//success
			success: function (html) {//alert(html);
				//if process.php returned 1/true (send mail success)
				if (html==1) {
					//hide the form
					$('.form').fadeOut('slow');

					//show the success message
					$('.done').fadeIn('slow');

				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');
			}
		});

		//cancel the submit button default behaviours
		return false;
	});
});


text:
module Aws.SimpleDb.Commands
(
  module Aws.SimpleDb.Commands.BatchDeleteAttributes
, module Aws.SimpleDb.Commands.BatchPutAttributes
, module Aws.SimpleDb.Commands.CreateDomain
, module Aws.SimpleDb.Commands.DeleteAttributes
, module Aws.SimpleDb.Commands.DeleteDomain
, module Aws.SimpleDb.Commands.DomainMetadata
, module Aws.SimpleDb.Commands.GetAttributes
, module Aws.SimpleDb.Commands.ListDomains
, module Aws.SimpleDb.Commands.PutAttributes
, module Aws.SimpleDb.Commands.Select
)
where

import Aws.SimpleDb.Commands.BatchDeleteAttributes
import Aws.SimpleDb.Commands.BatchPutAttributes
import Aws.SimpleDb.Commands.CreateDomain
import Aws.SimpleDb.Commands.DeleteAttributes
import Aws.SimpleDb.Commands.DeleteDomain
import Aws.SimpleDb.Commands.DomainMetadata
import Aws.SimpleDb.Commands.GetAttributes
import Aws.SimpleDb.Commands.ListDomains
import Aws.SimpleDb.Commands.PutAttributes
import Aws.SimpleDb.Commands.Select


text:
package liquibase.change.custom;

import liquibase.database.Database;
import liquibase.exception.RollbackImpossibleException;
import liquibase.exception.SetupException;
import liquibase.exception.UnsupportedChangeException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.RawSqlStatement;
import liquibase.structure.core.Column;
import liquibase.structure.core.Table;

public class ExampleCustomSqlChange implements CustomSqlChange, CustomSqlRollback {

    private String tableName;
    private String columnName;
    private String newValue;

    @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"})
    private ResourceAccessor resourceAccessor;

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getNewValue() {
        return newValue;
    }

    public void setNewValue(String newValue) {
        this.newValue = newValue;
    }

    public SqlStatement[] generateStatements(Database database) {
        return new SqlStatement[]{
                new RawSqlStatement("update "+database.escapeObjectName(tableName, Table.class)
                        +" set "+database.escapeObjectName(columnName, Column.class)+" = "+newValue)
        };
    }

    public SqlStatement[] generateRollbackStatements(Database database) throws RollbackImpossibleException {
        return new SqlStatement[]{
                new RawSqlStatement("update "+database.correctObjectName(tableName, Table.class)
                        +" set "+database.escapeObjectName(columnName, Column.class)+" = null")
        };
    }

    public String getConfirmationMessage() {
        return "Custom class updated "+tableName+"."+columnName;
    }

    public void setUp() throws SetupException {
    }

    public void setFileOpener(ResourceAccessor resourceAccessor) {
        this.resourceAccessor = resourceAccessor;
    }

    public ValidationErrors validate(Database database) {
        return new ValidationErrors();
    }

}


text: Rails.application.config.session_store :cookie_store, key: '_camp_base_session'


text:
require_relative '../../test_helper'
require_relative '../../support/utils/operation_test_utils'
# require_relative '../../support/utils/jsonapi_test_utils'

class DivisionCreateTest < ActiveSupport::TestCase
  # include JsonapiTestUtils
  include OperationTestUtils

  let(:user) { users(:researcher) }
  let(:orga) { organizations(:basic) }
  let(:basic_params) do
    {
      addition: 'DivisionAddition',
      description: 'DivisionDescription',
      organization: orga,
      section: orga.sections.first,
      city: orga.locations.first.city
    }
  end

  describe '::Division::Create' do
    it 'must create a Division given valid data' do
      operation_must_work ::Division::Create, basic_params
    end

    it 'must create a division with presumed (solution) categories and label' do
      tag1 = FactoryGirl.create(:tag)
      tag2 = FactoryGirl.create(:tag)

      params = basic_params.merge(
        presumed_tags: [{ id: tag1.id }, { id: tag2.id }],
        presumed_solution_categories: [{ id: 1 }]
      )
      result = operation_must_work ::Division::Create, params
      result['model'].presumed_tags.count.must_equal 2
      result['model'].presumed_tags.first.id.must_equal tag1.id
      result['model'].presumed_tags.last.id.must_equal tag2.id
      result['model'].presumed_solution_categories.count.must_equal 1
      result['model'].presumed_solution_categories.first.id.must_equal 1
      result['model'].label.must_equal(
        'foobar (family), City: Berlin, Addition: DivisionAddition'
      )
    end

    it 'must create a division without an addition' do
      basic_params[:addition] = nil
      result = operation_must_work ::Division::Create, basic_params
      result['model'].label.must_equal('foobar (family), City: Berlin')
    end

    describe 'validations' do
      it 'must validate organization' do
        basic_params[:organization] = nil
        operation_wont_work ::Division::Create, basic_params
      end

      it 'must validate section' do
        basic_params[:section] = nil
        operation_wont_work ::Division::Create, basic_params
      end
    end

    describe 'side-effects' do
      describe '#SyncOrganization' do
        it 'created division must not be done it should reset'\
        ' orga to approved' do
          orga.aasm_state.must_equal 'all_done'
          operation_must_work ::Division::Create, basic_params,
                              current_user: user
          orga.reload.aasm_state.must_equal 'approved'
        end

        it 'should not change the Orga-state when it is not all_done' do
          orga.update_columns aasm_state: 'completed'
          operation_must_work ::Division::Create, basic_params,
                              current_user: user
          orga.reload.aasm_state.must_equal 'completed'
        end
      end
    end
  end
end


text:
class GithubUrlFromBasePathLine

  def initialize(base, commit_sha, path, line)
    @base = base
    @commit_sha = commit_sha
    @line = line
    @path = path
  end

  # https://github.com/codetriage/docs_doctor/blob/f5dd91595d5cdad0a2348515c6f715ef19c51070/app/models/github_url_from_base_path_line.rb#L10
  def to_github
    File.join(@base, 'blob', @commit_sha, @path, "#L#{@line}")
  end
end