text:
// -*- mode: c; tab-width: 4; indent-tabs-mode: nil; st-rulers: [132] -*-
// vim: ts=4 sw=4 ft=c et

#include "libsodium_api_crypto_pwhash_argon2id.h"

static void LS_API_EXEC(crypto_pwhash_argon2id, alg_argon2id13);
static void LS_API_EXEC(crypto_pwhash_argon2id, bytes_min);
static void LS_API_EXEC(crypto_pwhash_argon2id, bytes_max);
static void LS_API_EXEC(crypto_pwhash_argon2id, passwd_min);
static void LS_API_EXEC(crypto_pwhash_argon2id, passwd_max);
static void LS_API_EXEC(crypto_pwhash_argon2id, saltbytes);
static void LS_API_EXEC(crypto_pwhash_argon2id, strbytes);
static void LS_API_EXEC(crypto_pwhash_argon2id, strprefix);
static void LS_API_EXEC(crypto_pwhash_argon2id, opslimit_min);
static void LS_API_EXEC(crypto_pwhash_argon2id, opslimit_max);
static void LS_API_EXEC(crypto_pwhash_argon2id, memlimit_min);
static void LS_API_EXEC(crypto_pwhash_argon2id, memlimit_max);
static void LS_API_EXEC(crypto_pwhash_argon2id, opslimit_interactive);
static void LS_API_EXEC(crypto_pwhash_argon2id, memlimit_interactive);
static void LS_API_EXEC(crypto_pwhash_argon2id, opslimit_moderate);
static void LS_API_EXEC(crypto_pwhash_argon2id, memlimit_moderate);
static void LS_API_EXEC(crypto_pwhash_argon2id, opslimit_sensitive);
static void LS_API_EXEC(crypto_pwhash_argon2id, memlimit_sensitive);
static int LS_API_INIT(crypto_pwhash_argon2id, crypto_pwhash_argon2id);
static void LS_API_EXEC(crypto_pwhash_argon2id, crypto_pwhash_argon2id);
static int LS_API_INIT(crypto_pwhash_argon2id, str);
static void LS_API_EXEC(crypto_pwhash_argon2id, str);
static int LS_API_INIT(crypto_pwhash_argon2id, str_verify);
static void LS_API_EXEC(crypto_pwhash_argon2id, str_verify);
static int LS_API_INIT(crypto_pwhash_argon2id, str_needs_rehash);
static void LS_API_EXEC(crypto_pwhash_argon2id, str_needs_rehash);

libsodium_function_t libsodium_functions_crypto_pwhash_argon2id[] = {
    LS_API_R_ARG0(crypto_pwhash_argon2id, alg_argon2id13),
    LS_API_R_ARG0(crypto_pwhash_argon2id, bytes_min),
    LS_API_R_ARG0(crypto_pwhash_argon2id, bytes_max),
    LS_API_R_ARG0(crypto_pwhash_argon2id, passwd_min),
    LS_API_R_ARG0(crypto_pwhash_argon2id, passwd_max),
    LS_API_R_ARG0(crypto_pwhash_argon2id, saltbytes),
    LS_API_R_ARG0(crypto_pwhash_argon2id, strbytes),
    LS_API_R_ARG0(crypto_pwhash_argon2id, strprefix),
    LS_API_R_ARG0(crypto_pwhash_argon2id, opslimit_min),
    LS_API_R_ARG0(crypto_pwhash_argon2id, opslimit_max),
    LS_API_R_ARG0(crypto_pwhash_argon2id, memlimit_min),
    LS_API_R_ARG0(crypto_pwhash_argon2id, memlimit_max),
    LS_API_R_ARG0(crypto_pwhash_argon2id, opslimit_interactive),
    LS_API_R_ARG0(crypto_pwhash_argon2id, memlimit_interactive),
    LS_API_R_ARG0(crypto_pwhash_argon2id, opslimit_moderate),
    LS_API_R_ARG0(crypto_pwhash_argon2id, memlimit_moderate),
    LS_API_R_ARG0(crypto_pwhash_argon2id, opslimit_sensitive),
    LS_API_R_ARG0(crypto_pwhash_argon2id, memlimit_sensitive),
    LS_API_R_ARGV(crypto_pwhash_argon2id, crypto_pwhash_argon2id, 6),
    LS_API_R_ARGV(crypto_pwhash_argon2id, str, 3),
    LS_API_R_ARGV(crypto_pwhash_argon2id, str_verify, 2),
    LS_API_R_ARGV(crypto_pwhash_argon2id, str_needs_rehash, 3),
    {NULL}};

/* crypto_pwhash_argon2id_alg_argon2id13/0 */

LS_API_GET_SINT(crypto_pwhash_argon2id, alg_argon2id13);

/* crypto_pwhash_argon2id_bytes_min/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, bytes_min);

/* crypto_pwhash_argon2id_bytes_max/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, bytes_max);

/* crypto_pwhash_argon2id_passwd_min/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, passwd_min);

/* crypto_pwhash_argon2id_passwd_max/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, passwd_max);

/* crypto_pwhash_argon2id_saltbytes/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, saltbytes);

/* crypto_pwhash_argon2id_strbytes/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, strbytes);

/* crypto_pwhash_argon2id_strprefix/0 */

LS_API_GET_STR(crypto_pwhash_argon2id, strprefix);

/* crypto_pwhash_argon2id_opslimit_min/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, opslimit_min);

/* crypto_pwhash_argon2id_opslimit_max/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, opslimit_max);

/* crypto_pwhash_argon2id_memlimit_min/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, memlimit_min);

/* crypto_pwhash_argon2id_memlimit_max/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, memlimit_max);

/* crypto_pwhash_argon2id_opslimit_interactive/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, opslimit_interactive);

/* crypto_pwhash_argon2id_memlimit_interactive/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, memlimit_interactive);

/* crypto_pwhash_argon2id_opslimit_moderate/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, opslimit_moderate);

/* crypto_pwhash_argon2id_memlimit_moderate/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, memlimit_moderate);

/* crypto_pwhash_argon2id_opslimit_sensitive/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, opslimit_sensitive);

/* crypto_pwhash_argon2id_memlimit_sensitive/0 */

LS_API_GET_SIZE(crypto_pwhash_argon2id, memlimit_sensitive);

/* crypto_pwhash_argon2id_crypto_pwhash_argon2id/6 */

typedef struct LS_API_F_ARGV(crypto_pwhash_argon2id, crypto_pwhash_argon2id) {
    unsigned long long outlen;
    const char *passwd;
    unsigned long long passwdlen;
    const unsigned char *salt;
    size_t saltlen;
    unsigned long long opslimit;
    size_t memlimit;
    int alg;
} LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id);

static int
LS_API_INIT(crypto_pwhash_argon2id, crypto_pwhash_argon2id)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id) * argv;
    int skip;
    int type;
    int type_length;
    unsigned long long outlen;
    unsigned long long passwdlen;
    size_t saltbytes;
    size_t saltlen;
    unsigned long long opslimit;
    size_t memlimit;
    long alg;
    ErlDrvSizeT x;
    void *p;

    if (ei_decode_ulong(buffer, index, (unsigned long *)&(outlen)) < 0) {
        return -1;
    }

    if (ei_get_type(buffer, index, &type, &type_length) < 0 || type != ERL_BINARY_EXT) {
        return -1;
    }

    passwdlen = (unsigned long long)(type_length);

    skip = *index;

    if (ei_skip_term(buffer, &skip) < 0) {
        return -1;
    }

    saltbytes = crypto_pwhash_argon2id_saltbytes();

    if (ei_get_type(buffer, &skip, &type, &type_length) < 0 || type != ERL_BINARY_EXT || type_length < saltbytes) {
        return -1;
    }

    saltlen = (size_t)(type_length);

    if (ei_skip_term(buffer, &skip) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(opslimit)) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(memlimit)) < 0) {
        return -1;
    }

    if (ei_decode_long(buffer, &skip, (long *)&(alg)) < 0) {
        return -1;
    }

    x = (ErlDrvSizeT)(passwdlen + saltlen + (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id))));
    p = (void *)(driver_alloc(x));

    if (p == NULL) {
        return -1;
    }

    argv = (LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id) *)(p);
    argv->outlen = outlen;
    argv->opslimit = opslimit;
    argv->memlimit = memlimit;
    argv->alg = (int)alg;
    p += (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id)));
    argv->passwd = (const char *)(p);
    p += passwdlen;
    argv->salt = (const unsigned char *)(p);
    argv->saltlen = saltlen;

    if (ei_decode_binary(buffer, index, (void *)(argv->passwd), (long *)&(argv->passwdlen)) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_decode_binary(buffer, index, (void *)(argv->salt), (long *)&(argv->saltlen)) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_skip_term(buffer, index) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_skip_term(buffer, index) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_skip_term(buffer, index) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    request->argv = (void *)(argv);

    return 0;
}

static void
LS_API_EXEC(crypto_pwhash_argon2id, crypto_pwhash_argon2id)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, crypto_pwhash_argon2id) * argv;
    LS_API_READ_ARGV(crypto_pwhash_argon2id, crypto_pwhash_argon2id);

    unsigned char out[argv->outlen];

    LS_SAFE_REPLY(crypto_pwhash_argon2id(out, argv->outlen, argv->passwd, argv->passwdlen, argv->salt, argv->opslimit,
                                         argv->memlimit, argv->alg),
                  LS_PROTECT({LS_RES_TAG(request), ERL_DRV_BUF2BINARY, (ErlDrvTermData)(out), argv->outlen, ERL_DRV_TUPLE, 2}),
                  __FILE__, __LINE__);

    (void)sodium_memzero(out, argv->outlen);
}

/* crypto_pwhash_argon2id_str/3 */

typedef struct LS_API_F_ARGV(crypto_pwhash_argon2id, str) {
    const char *passwd;
    unsigned long long passwdlen;
    unsigned long long opslimit;
    size_t memlimit;
} LS_API_F_ARGV_T(crypto_pwhash_argon2id, str);

static int
LS_API_INIT(crypto_pwhash_argon2id, str)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str) * argv;
    int skip;
    int type;
    int type_length;
    unsigned long long passwdlen;
    unsigned long long opslimit;
    size_t memlimit;
    ErlDrvSizeT x;
    void *p;

    if (ei_get_type(buffer, index, &type, &type_length) < 0 || type != ERL_BINARY_EXT) {
        return -1;
    }

    passwdlen = (unsigned long long)(type_length);

    skip = *index;

    if (ei_skip_term(buffer, &skip) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(opslimit)) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(memlimit)) < 0) {
        return -1;
    }

    x = (ErlDrvSizeT)(passwdlen + (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, str))));
    p = (void *)(driver_alloc(x));

    if (p == NULL) {
        return -1;
    }

    argv = (LS_API_F_ARGV_T(crypto_pwhash_argon2id, str) *)(p);
    argv->opslimit = opslimit;
    argv->memlimit = memlimit;
    p += (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, str)));
    argv->passwd = (const char *)(p);

    if (ei_decode_binary(buffer, index, (void *)(argv->passwd), (long *)&(argv->passwdlen)) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_skip_term(buffer, index) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_skip_term(buffer, index) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    request->argv = (void *)(argv);

    return 0;
}

static void
LS_API_EXEC(crypto_pwhash_argon2id, str)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str) * argv;
    LS_API_READ_ARGV(crypto_pwhash_argon2id, str);

    char out[crypto_pwhash_argon2id_STRBYTES];

    LS_SAFE_REPLY(crypto_pwhash_argon2id_str(out, argv->passwd, argv->passwdlen, argv->opslimit, argv->memlimit),
                  LS_PROTECT({LS_RES_TAG(request), ERL_DRV_BUF2BINARY, (ErlDrvTermData)(out), strlen(out), ERL_DRV_TUPLE, 2}),
                  __FILE__, __LINE__);

    (void)sodium_memzero(out, sizeof(out));
}

/* crypto_pwhash_argon2id_str_verify/2 */

typedef struct LS_API_F_ARGV(crypto_pwhash_argon2id, str_verify) {
    const char str[crypto_pwhash_argon2id_STRBYTES];
    const char *passwd;
    unsigned long long passwdlen;
} LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify);

static int
LS_API_INIT(crypto_pwhash_argon2id, str_verify)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify) * argv;
    int skip;
    int type;
    int type_length;
    unsigned long long passwdlen;
    ErlDrvSizeT x;
    void *p;

    if (ei_get_type(buffer, index, &type, &type_length) < 0 || type != ERL_BINARY_EXT ||
        type_length > crypto_pwhash_argon2id_STRBYTES) {
        return -1;
    }

    skip = *index;

    if (ei_skip_term(buffer, &skip) < 0) {
        return -1;
    }

    if (ei_get_type(buffer, &skip, &type, &type_length) < 0 || type != ERL_BINARY_EXT) {
        return -1;
    }

    passwdlen = (unsigned long long)(type_length);

    x = (ErlDrvSizeT)(passwdlen + (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify))));
    p = (void *)(driver_alloc(x));
    (void)sodium_memzero(p, x);

    if (p == NULL) {
        return -1;
    }

    argv = (LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify) *)(p);
    p += (sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify)));
    argv->passwd = (const char *)(p);

    if (ei_decode_binary(buffer, index, (void *)(argv->str), NULL) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    if (ei_decode_binary(buffer, index, (void *)(argv->passwd), (long *)&(argv->passwdlen)) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    request->argv = (void *)(argv);

    return 0;
}

static void
LS_API_EXEC(crypto_pwhash_argon2id, str_verify)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_verify) * argv;
    LS_API_READ_ARGV(crypto_pwhash_argon2id, str_verify);

    int r = crypto_pwhash_argon2id_str_verify(argv->str, argv->passwd, argv->passwdlen);

    ErlDrvTermData spec[] = {LS_RES_TAG(request), ERL_DRV_INT, (ErlDrvSInt)(r), ERL_DRV_TUPLE, 2};

    LS_RESPOND(request, spec, __FILE__, __LINE__);
}

/* crypto_pwhash_argon2id_str_needs_rehash/2 */

typedef struct LS_API_F_ARGV(crypto_pwhash_argon2id, str_needs_rehash) {
    const char str[crypto_pwhash_argon2id_STRBYTES];
    unsigned long long opslimit;
    size_t memlimit;
} LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_needs_rehash);

static int
LS_API_INIT(crypto_pwhash_argon2id, str_needs_rehash)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_needs_rehash) * argv;
    int skip;
    int type;
    int type_length;
    unsigned long long opslimit;
    size_t memlimit;
    ErlDrvSizeT x;
    void *p;

    if (ei_get_type(buffer, index, &type, &type_length) < 0 || type != ERL_BINARY_EXT ||
        type_length > crypto_pwhash_argon2id_STRBYTES) {
        return -1;
    }

    skip = *index;

    if (ei_skip_term(buffer, &skip) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(opslimit)) < 0) {
        return -1;
    }

    if (ei_decode_ulong(buffer, &skip, (unsigned long *)&(memlimit)) < 0) {
        return -1;
    }

    x = (ErlDrvSizeT)(sizeof(LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_needs_rehash)));
    p = (void *)(driver_alloc(x));
    (void)sodium_memzero(p, x);

    if (p == NULL) {
        return -1;
    }

    argv = (LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_needs_rehash) *)(p);
    argv->opslimit = opslimit;
    argv->memlimit = memlimit;

    if (ei_decode_binary(buffer, index, (void *)(argv->str), NULL) < 0) {
        (void)driver_free(argv);
        return -1;
    }

    request->argv = (void *)(argv);

    return 0;
}

static void
LS_API_EXEC(crypto_pwhash_argon2id, str_needs_rehash)
{
    LS_API_F_ARGV_T(crypto_pwhash_argon2id, str_needs_rehash) * argv;
    LS_API_READ_ARGV(crypto_pwhash_argon2id, str_needs_rehash);

    int r = crypto_pwhash_argon2id_str_needs_rehash(argv->str, argv->opslimit, argv->memlimit);

    ErlDrvTermData spec[] = {LS_RES_TAG(request), ERL_DRV_INT, (ErlDrvSInt)(r), ERL_DRV_TUPLE, 2};

    LS_RESPOND(request, spec, __FILE__, __LINE__);
}


text:
/**
 * PlayOff Round Entity
 * */

var _ = require("underscore");

var Round = function () {

    var column = this.column = {};

    column.RoundID = 0;
    column.HostID = 0;
    column.HostName = '';
    column.HostRank = 0;
    column.HostWin = 0;
    column.VisitID = 0;
    column.VisitName = 0;
    column.VisitRank = 0;
    column.VisitWin = 0;
    column.Round = 1;
    column.Area = Round.AREA_WEST;
    column.Season = 0;
    column.Status = 0;

};

Round.prototype.data = function () {
    return this.column;
};

Round.create = function (round) {
    var instance = new Round();
    _.extendOwn(instance.column, round);
    return instance;
};

Round.AREA_WEST = 1;
Round.AREA_EAST = 2;
Round.STATUS_IN = 1;
Round.STATUS_OVER = 2;

module.exports = Round;

redpajama_set_name: RedPajamaGithub


text:
require 'tmpdir'

# Test TwilioDelivery by setting twilio_settings for account_sid and token. Does that work?

module ActionTexter
  # This module handles everything related to SMS delivery, from registering new
  # delivery methods to configuring the message object to be sent.
  module DeliveryMethods
    extend ActiveSupport::Concern

    included do
      class_attribute :delivery_methods, :delivery_method

      # Do not make this inheritable, because we always want it to propagate
      cattr_accessor :raise_delivery_errors
      self.raise_delivery_errors = true

      cattr_accessor :perform_deliveries
      self.perform_deliveries = true

      self.delivery_methods = {}.freeze
      self.delivery_method = :file

      add_delivery_method :twilio, ActionTexter::TwilioDelivery,
        :account_sid  => nil,
        :token        => nil

      add_delivery_method :file, ActionTexter::FileDelivery,
        :location => defined?(Rails.root) ? "#{Rails.root}/tmp/sms" : "#{Dir.tmpdir}/sms"
    end

    module ClassMethods
      # Adds a new delivery method through the given class using the given symbol
      # as alias and the default options supplied:
      #
      # Example:
      #
      #   add_delivery_method :twilio, ActionTexter::TwilioDelivery,
      #     :account_sid   => 'abcdef',
      #     :token         => 'abcdef'
      #
      def add_delivery_method(symbol, klass, default_options={})
        class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
        send(:"#{symbol}_settings=", default_options)
        self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
      end

      def wrap_delivery_behavior(message, method=nil) #:nodoc:
        method ||= self.delivery_method

        case method
        when NilClass
          raise "Delivery method cannot be nil"
        when Symbol
          if klass = delivery_methods[method.to_sym]
            message.delivery_method(klass, send(:"#{method}_settings"))
          else
            raise "Invalid delivery method #{method.inspect}"
          end
        else
          message.delivery_method(method)
        end
      end
    end

    def wrap_delivery_behavior!(*args) #:nodoc:
      self.class.wrap_delivery_behavior(message, *args)
    end
  end
end


text:
public gUserExamDetail[] GetUserExams() throws IOException, XmlPullParserException, JSONException {
        final String SOAP_ACTION = "http://tempuri.org/GetUserExams";
        final String OPERATION_NAME = "GetUserExams";
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        List<HeaderProperty> reqHeaders = new LinkedList<>();
        SetCookie(reqHeaders, cntxt);
        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        httpTransport.call(SOAP_ACTION, envelope, reqHeaders);
        Object response = envelope.getResponse();
        Gson gsonConvert = new Gson();
        gsonConvert = new GsonBuilder().setDateFormat(DateFormat.FULL, DateFormat.FULL).create();
//        if(response.toString().contains("\"StatusID\":0")){
//
//        }
        return gsonConvert.fromJson(response.toString(), gUserExamDetail[].class);
    }


text:
from src.handler.start_event import run

run()


text:
package HandlerSocket.Protocol
import java.io.ByteArrayOutputStream
import akka.util.ByteString
import java.util

import org.slf4j.LoggerFactory

class TokenEnumerator(input:ByteString) {
  private var v:ByteString = input
  def filter(bytes:ByteString):String = {
    val out = new ByteArrayOutputStream
    var convert = false
    bytes.foreach(ch =>{
      if (ch == 0x01) convert = true
      else if (convert) {
        convert = false
        out.write(ch^0x40)
      } else out.write(ch)
    })
    new String(out.toByteArray, ResultDecoder.encoding)
  }
  def readToken(): String = {
    val tokenBytes = v.takeWhile(ch => (ch!='\t') )
    v = v.drop(tokenBytes.size+1) // skip the '\t' and sliding forward
    filter(tokenBytes)
  }
  def left = v
}
object ResultDecoder {
  val encoding = "utf-8"
  val log = LoggerFactory.getLogger("HandlerSocket")
  def assembly(input:ByteString):HsResult = {
    val source = new TokenEnumerator(input)
    val errorCode = source.readToken().toInt
    val columnNumber = source.readToken().toInt
    if (source.left.size<=1) HsResult(errorCode, columnNumber, Array[String]())
    else {
      val colList = new util.ArrayList[String]()
      //Fix: Change from >1 to >=1 as one result:"0" was dropped at last char
      while (source.left.size>=1) colList.add(source.readToken())
      val columns:Array[String] = new Array[String](colList.size())
      colList.toArray[String](columns)
      HsResult(errorCode, columnNumber,columns)
    }
  }
}


text:
@class CoreSocketConnection;
@interface CoreSocketPacket : NSObject
@property (nonatomic, strong, readonly) NSMutableData *data;
@property (nonatomic, assign, readonly) NSInteger totalBytes;
@property (nonatomic, assign, readonly) int tag;
@property (nonatomic, assign) NSTimeInterval timeOut;
- (instancetype)initWithData:(NSData *)data;
@end

@interface CoreSocketReadPacket : CoreSocketPacket
@property (nonatomic, assign, readonly) NSInteger maxLength;
@property (nonatomic, assign, readonly) NSInteger readLength;
@property (nonatomic, assign, readonly) NSInteger offset;
@property (nonatomic, assign) BOOL finish;

- (instancetype)initWithBytesAvaliable:(size_t)bytesAvaliable
                            readMaxLen:(NSInteger)maxLen
                               timeOut:(NSTimeInterval)timeout;

- (uint8_t *)readLength:(size_t)bytesAvaliable;
- (size_t)readBuffer:(uint8_t *)buffer len:(size_t)len;

@end

@interface CoreSocketWritePacket : CoreSocketPacket
@end

@protocol CoreSocketConnectionDelegate <NSObject>
@required
- (void)onSocketConnection:(CoreSocketConnection *)connection writeSourceDidHandle:(int)socketFD;
- (void)onSocketConnection:(CoreSocketConnection *)connection readSourceDidHandle:(int)socketFD;
@end

@interface CoreSocketConnection : NSObject
@property (nonatomic, assign, readonly) int socketFD;
@property (nonatomic, strong, readonly) NSData *remoteAddress;
@property (nonatomic, strong, readonly) dispatch_source_t readSource;
@property (nonatomic, strong, readonly) dispatch_source_t writeSource;
@property (nonatomic, strong, readonly) dispatch_queue_t handleQueue;
@property (nonatomic, weak, readonly) id <CoreSocketConnectionDelegate> delegate;

- (void)destoryHandle;
- (instancetype)initWithSocketFD:(int)socketFD
                         address:(NSData *)address
                        delegate:(id<CoreSocketConnectionDelegate>)delegate;
@end


text:
Bogey is a web-based log visualization framework.

It tails your log files and emits events using [Socket.IO](http://socket.io/) to browser visualization plugins.

Bogey ships with [Bogey Pong](https://github.com/cognizo/bogey-pong), a Pong-like visualization
inspired by [Logstalgia](https://code.google.com/p/logstalgia/) that works with common web server
logs, but it's designed to make it easy to plug in your own visualizations.

## Installing

Bogey is a [Node.js](http://nodejs.org/) module.

Install with `npm`:

    npm install -g bogey

## Details

Bogey's Node.js module runs a server that watches any number of log files, parses them with a
configurable regular expression, and emits the processed data to connected clients via [Socket.IO](http://socket.io/).

The [web frontend](https://github.com/cognizo/bogey-web) is an [Ember](http://emberjs.com/) application that
listens for log events and provides an API to visualization modules that can display the log data
however they want.

Creating a visualization is easy, since all you need to do is expose a JavaScript module that Bogey
can `require()`, hook into Bogey's events, and render the data however you want.

Bogey provides modules with a render loop, simple stats (requests per minute, etc) and keyboard events,
but doesn't enforce anything about how to render log data.

For a basic example of how a visualization module works, check out
[Bogey Example](https://github.com/cognizo/bogey-example). You can also check out the code for
[Bogey Pong](https://github.com/cognizo/bogey-pong), which uses the [Phaser](http://phaser.io/) HTML5
game framework.

## Usage

Run Bogey with the `bogey` command.

### Options

    -c <config file> Config file

Specify a JSON config file to load for configuration settings. This setting is optional.

See `config.json.example` for an example configuration.

    -f <filename:regexp name> Watch a file

Watch a file. Specify the file in the format `filename:regexp-name`. Bogey comes with a regular expression
for parsing files in the [Common Log Format](http://en.wikipedia.org/wiki/Common_Log_Format), but it's
easy to add your own. See the [regular expressions](#regular-expressions) section for details. This
setting is optional, but if no logs are specified only [demo mode](#demo-mode) or [HTTP POSTs](#using-with-logstash)
will be available.

    -p <port> Port

Port for the web server to listen on.

### Usage examples

Tail an Nginx or Apache access log:

    bogey -f /var/log/nginx/access.log:apache-combined

Tail multiple files:

    bogey -f /var/log/nginx/access.log:apache-combined -f /var/www/my-site/logs/access.log:apache-combined

### Regular expressions

Bogey uses regular expressions to parse log files into data that modules can use. It uses the
[named-regexp](https://www.npmjs.org/package/named-regexp) module to allow for using named
captures with JavaScript regular expressions.

Bogey comes with the `apache-combined` regular expression, but it's easy to add your own. Just add a
section to your `config.json`:

    "regexp": {
        "my-regexp": "/(:<myAttr>.*) (:<myOtherAttr>.*)/"
    }

And then specify it either on the command line with `-f` like:

    bogey -f /var/log/my-custom.log:my-regexp

Or in your `config.json` like:

    "logs": [
        {
            "file": "/var/log/my-custom.log",
            "regexp": "my-regexp"
        }
    ]

Check the [named-regexp documentation](https://www.npmjs.org/package/named-regexp) for details on the
named capture syntax.

## Using with Logstash

If you're using Logstash, Bogey supports receiving log data via HTTP POST.

Just enable the [http output](http://logstash.net/docs/latest/outputs/http) and map the data so that
Bogey understands it.

Here's an example Logstash configuration using the COMBINEDAPACHELOG grok filter:

    output {
        http {
            http_method => "post"
            mapping => {
                "ip" => "%{clientip}"
                "uri" => "%{request}"
                "statusCode" => "%{response}"
            }
            url => "http://bogey-host:8008/log"
        }
    }

## Demo mode

Bogey comes with a demo mode that runs in the browser and creates fake log data. You can enable it by
appending `?demo=true` to the URL when viewing a visualization, or by pressing the `D` key.

## Creating visualizations

Visualizations are CommonJS modules `require()`ed by the Bogey web frontend.

A visualization should export a `bogey` object with the following properties:

    bogey: {
        name: 'Visualization name',
        thumbnail: 'Path to thumbnail image',
        run: function (bogey) {
            // Run the visualization
        }
    }

The `bogey` object passed to a module's `bogey.run()` emits the following events:

        bogey.on('request', function (data) {
            // Passes an object with parsed data from a log line.
        });

        bogey.on('frame', function () {
            // A new frame is ready for rendering. If you use Bogey's render loop, this your
            // main update function.
        });

        bogey.on('pause', function () {
            // The visualization has been paused (Space key pressed).
        });

        bogey.on('play', function () {
            // The visualization has been unpaused (Space key pressed while paused).
        });

        bogey.on('speedUp', function () {
            // The visualization has been sped up (+ key pressed).
        });

        bogey.on('slowDown', function () {
            // The visualization has been slowed down (- key pressed).
        });

        bogey.on('defaultSpeed', function () {
            // The visualization has been reset to normal speed (0 key pressed).
        });

        bogey.on('resize', function () {
            // The visualization window has been resized.
        });

        bogey.on('close', function () {
            // The visualization has been closed (Escape or Q key pressed).
        });

Note that in the case of `pause`, `play`, `speedUp`, `slowDown`, `defaultSpeed` and `resize`, it is up to the
visualization module to act on each of these requests.

You also don't have to use Bogey's render loop. If you choose to use a different engine, you can ignore
the `frame` event and implement your own. For example, the [Bogey Pong](https://github.com/cognizo/bogey-pong)
module uses the [Phaser](http://phaser.io/) engine which has its own render loop.

### Visualization development

Since Bogey expects visualizations to be CommonJS modules, it comes with build scripts that will automatically
[Browserify](http://browserify.org/) your modules and include them in Bogey.

While developing a visualization, you'll need to run the development version of Bogey.

Check out the repository:

    git clone https://github.com/cognizo/bogey.git

Install its dependencies:

    cd bogey
    npm install

To include a visualization module, add a `visualizations` section to your `config.json` like:

    "visualizations": [
        "my-module" // "my-module" should be an npm module that Bogey can require()
    ]

Then run:

    gulp build

This will build your visualization and include it in the web frontend's configuration.

You can also run a development server that will automatically rebuild your visualizations any time
they change with:

    gulp serve


text:
* Dynamic terminal view resizing

## v0.5.1 - Patch
* Remove trailing whitespace from terminal rename

## v0.5.0 - Beta Release
* Add terminal naming via the status icon

## v0.4.3 - Patch
* Rebuild pty.js binaries for electron release 0.30.6
* Requires Atom >= 1.0.12

## v0.4.2 - Patch
* Specify commit for pty.js prebuilt

## v0.4.1 - Patch
* Make button toolbar smaller by keeping buttons minimal
  * No more names next to button
  * Make button fit to icon
* Use --login shell argument by default for bash and zsh

## v0.4.0 - Beta Release
* Add prebuilt binaries for pty.js
* Better support for systems without the tools needed to compile (Windows)

## v0.3.1 - Patch
* Add warning for custom font family (must use monospaced font)

## v0.3.0 - Beta Release
* Refactor resizing to snap to row
* Fix cursor line being removed if blank
* Possible fix for refresh error
* Fix for improper resizing when displaying the terminal for the first time

## v0.2.0 - Beta Release
* Bump up to minor version 2
* New settings and features added
* Bug fixes listed below in v0.1.x patches

## v0.1.10 - Patch
* Add option to auto close terminal on shell process exit

## v0.1.9 - Patch
* Add insert selected text (see commit)
* Remove login command

## v0.1.8 - Patch
* Remove quiet option from login
* Disable resize and input on terminal exit

## v0.1.7 - Patch
* Resize terminal on maximize and minimize
* Fix powershell.exe resolve
* Fix shell launch bugs

## v0.1.6 - Patch
* Make sure to properly resize terminal on open

## v0.1.5 - Patch
* On shell process exit, disable input to prevent error

## v0.1.4 - Patch
* Make terminal scroll to bottom on input
* Don't close the terminal view on process exit

## v0.1.3 - Patch
* Add more features to README.md
* Fix issue #1

## v0.1.2 - Patch
* Absolute image source paths in README.md
 * Update image in color coding section

## v0.1.1 - Patch
* Update the README.md and CHANGELOG.md

## v0.1.0 - Beta Release
* Initial release


text:
package commands.guildAdministration;

import commands.Command;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import utils.MSGS;
import utils.STATICS;

import java.awt.*;
import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by zekro on 07.05.2017 / 10:55
 * DiscordBot/commands.guildAdministration
 * © zekro 2017
 */

public class Moveall implements Command {
    @Override
    public boolean called(String[] args, MessageReceivedEvent event) {
        return false;
    }

    @Override
    public void action(String[] args, MessageReceivedEvent event) throws ParseException, IOException {

        if (core.Perms.check(1, event)) return;

        try {

            StringBuilder sb = new StringBuilder();
            Arrays.stream(args).forEach(s -> sb.append(s + " "));
            String vcName = sb.toString().substring(0, sb.toString().length() - 1);

            final VoiceChannel vc = event.getGuild().getVoiceChannels().stream()
                    .filter(voiceChannel -> voiceChannel.getName().toLowerCase().contains(vcName.toLowerCase()))
                    .findFirst().get();

            if (event.getMember().getVoiceState().inVoiceChannel()) {
                if (!event.getMember().getVoiceState().getChannel().equals(vc)) {

                    int membersInChannel = event.getMember().getVoiceState().getChannel().getMembers().size();
                    String VCfrom = event.getMember().getVoiceState().getChannel().getName();
                    String VCto = vc.getName();

                    event.getMember().getVoiceState().getChannel().getMembers()
                            .forEach(member -> event.getGuild().getController().moveVoiceMember(member, vc).queue());

                    event.getMessage().delete().queue();
                    Message msg = event.getTextChannel().sendMessage(new EmbedBuilder().setColor(new Color(0, 169, 255))
                            .setDescription("Moved **" + membersInChannel + "** members from `" + VCfrom + "` to `" + VCto + "`.")
                            .build()).complete();
                    new Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                            msg.delete().queue();
                        }
                    }, 5000);

                } else {
                    event.getTextChannel().sendMessage(
                            MSGS.error().setDescription("You don't need to move everyone in the same channel you are still in...").build()
                    ).queue();
                }
            } else
                event.getTextChannel().sendMessage(
                        MSGS.error().setDescription("You need to be in a voice channel to use this command!").build()
                ).queue();

        } catch (NoSuchElementException e) {
            event.getTextChannel().sendMessage(
                    MSGS.error().setDescription("Please enter a valid voice channel existing on this guild!").build()
            ).queue();
        } catch (Exception e) {
            event.getTextChannel().sendMessage(
                    MSGS.error()
                        .addField("Error Message", e.getMessage(), false)
                    .build()
            ).queue();
        }

    }

    @Override
    public void executed(boolean success, MessageReceivedEvent event) {

    }

    @Override
    public String help() {
        return "Использование: -moveall <voicechannel (can also just be a part of a voice channels name)>";
    }

    @Override
    public String description() {
        return "Move everyone in your channel to another channel.";
    }

    @Override
    public String commandType() {
        return STATICS.CMDTYPE.guildadmin;
    }

    @Override
    public int permission() {
        return 2;
    }
}


text:
title: Data DIPA
organization: KPU REPUBLIK INDONESIA
notes: Data DIPA
resources:
  - name: CSV DIPA Anggaran Activies
    url: 'https://github.com/pemiluAPI/pemilu-data/raw/master/dipa/dipa-anggaran-activities.csv'
    format: csv
  - name: CSV DIPA Anggaran Identities
    url: 'https://github.com/pemiluAPI/pemilu-data/raw/master/dipa/dipa-anggaran-identities.csv'
    format: csv
  - name: CSV DIPA Anggaran Keterkaitans
    url: 'https://github.com/pemiluAPI/pemilu-data/raw/master/dipa/dipa-anggaran-keterkaitans.csv'
    format: csv
  - name: CSV DIPA Anggarans
    url: 'https://github.com/pemiluAPI/pemilu-data/raw/master/dipa/dipa-anggarans.csv'
    format: csv
category:
  - DIPA
maintainer: ''
maintainer_email: ''
---


text:
package com.mongodb.connection;

import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.internal.authentication.NativeAuthenticationHelper;

import javax.crypto.Mac;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.util.HashMap;
import java.util.Random;

import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_1;

class ScramSha1Authenticator extends SaslAuthenticator {

    private final RandomStringGenerator randomStringGenerator;

    ScramSha1Authenticator(final MongoCredential credential) {
        this(credential, new DefaultRandomStringGenerator());
    }

    ScramSha1Authenticator(final MongoCredential credential, final RandomStringGenerator randomStringGenerator) {
        super(credential);

        this.randomStringGenerator = randomStringGenerator;
    }

    @Override
    public String getMechanismName() {
        return SCRAM_SHA_1.getMechanismName();
    }

    @Override
    protected SaslClient createSaslClient(final ServerAddress serverAddress) {
        return new ScramSha1SaslClient(getCredential(), randomStringGenerator);
    }

    private static class ScramSha1SaslClient implements SaslClient {

        private static final String GS2_HEADER = "n,,";
        private static final int RANDOM_LENGTH = 24;

        private final Base64Codec base64Codec;
        private final MongoCredential credential;
        private String clientFirstMessageBare;
        private final RandomStringGenerator randomStringGenerator;
        private String rPrefix;
        private byte[] serverSignature;
        private int step;

        ScramSha1SaslClient(final MongoCredential credential, final RandomStringGenerator randomStringGenerator) {
            this.credential = credential;
            this.base64Codec = new Base64Codec();
            this.randomStringGenerator = randomStringGenerator;
        }

        public String getMechanismName() {
            return SCRAM_SHA_1.getMechanismName();
        }

        public boolean hasInitialResponse() {
            return true;
        }

        public byte[] evaluateChallenge(final byte[] challenge) throws SaslException {
            if (this.step == 0) {
                this.step++;

                return computeClientFirstMessage();
            }
            else if (this.step == 1) {
                this.step++;

                return computeClientFinalMessage(challenge);
            }
            else if (this.step == 2) {
                this.step++;

                String serverResponse = encodeUTF8(challenge);
                HashMap<String, String> map = parseServerResponse(serverResponse);

                if (!MessageDigest.isEqual(decodeBase64(map.get("v")), this.serverSignature)) {
                    throw new SaslException("Server signature was invalid.");
                }

                return challenge;
            }
            else {
                throw new SaslException("Too many steps involved in the SCRAM-SHA-1 negotiation.");
            }
        }

        public boolean isComplete() {
            return this.step > 2;
        }

        public byte[] unwrap(final byte[] incoming, final int offset, final int len) throws SaslException {
            throw new UnsupportedOperationException("Not implemented yet!");
        }

        public byte[] wrap(final byte[] outgoing, final int offset, final int len) throws SaslException {
            throw new UnsupportedOperationException("Not implemented yet!");
        }

        public Object getNegotiatedProperty(final String propName) {
            throw new UnsupportedOperationException("Not implemented yet!");
        }

        public void dispose() throws SaslException {
            // nothing to do
        }

        private byte[] computeClientFirstMessage() throws SaslException {
            String userName = "n=" + prepUserName(this.credential.getUserName());
            this.rPrefix = randomStringGenerator.generate(RANDOM_LENGTH);

            String nonce = "r=" + this.rPrefix;

            this.clientFirstMessageBare = userName + "," + nonce;
            String clientFirstMessage = GS2_HEADER + this.clientFirstMessageBare;

            return decodeUTF8(clientFirstMessage);
        }

        private byte[] computeClientFinalMessage(final byte[] challenge) throws SaslException {
            String serverFirstMessage = encodeUTF8(challenge);

            HashMap<String, String> map = parseServerResponse(serverFirstMessage);
            String r = map.get("r");
            if (!r.startsWith(this.rPrefix)) {
                throw new SaslException("Server sent an invalid nonce.");
            }

            String s = map.get("s");
            String i = map.get("i");

            String channelBinding = "c=" + encodeBase64(decodeUTF8(GS2_HEADER));
            String nonce = "r=" + r;
            String clientFinalMessageWithoutProof = channelBinding + "," + nonce;

            byte[] saltedPassword = hi(
                    NativeAuthenticationHelper.createAuthenticationHash(this.credential.getUserName(),
                                                                        this.credential.getPassword()),
                    decodeBase64(s),
                    Integer.parseInt(i)
            );
            byte[] clientKey = hmac(saltedPassword, "Client Key");
            byte[] storedKey = h(clientKey);
            String authMessage = this.clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
            byte[] clientSignature = hmac(storedKey, authMessage);
            byte[] clientProof = xor(clientKey, clientSignature);
            byte[] serverKey = hmac(saltedPassword, "Server Key");
            this.serverSignature = hmac(serverKey, authMessage);

            String proof = "p=" + encodeBase64(clientProof);
            String clientFinalMessage = clientFinalMessageWithoutProof + "," + proof;

            return decodeUTF8(clientFinalMessage);
        }

        private byte[] decodeBase64(final String str) {
            return this.base64Codec.decode(str);
        }

        private byte[] decodeUTF8(final String str) throws SaslException {
            try {
                return str.getBytes("UTF-8");
            }
            catch (UnsupportedEncodingException e) {
                throw new SaslException("UTF-8 is not a supported encoding.", e);
            }
        }

        private String encodeBase64(final byte[] bytes) {
            return this.base64Codec.encode(bytes);
        }

        private String encodeUTF8(final byte[] bytes) throws SaslException {
            try {
                return new String(bytes, "UTF-8");
            }
            catch (UnsupportedEncodingException e) {
                throw new SaslException("UTF-8 is not a supported encoding.", e);
            }
        }

        private byte[] h(final byte[] data) throws SaslException {
            try {
                return MessageDigest.getInstance("SHA-1").digest(data);
            }
            catch (NoSuchAlgorithmException e) {
                throw new SaslException("SHA-1 could not be found.", e);
            }
        }

        private byte[] hi(final String password, final byte[] salt, final int iterations) throws SaslException {
            PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, 20 * 8 /* 20 bytes */);

            SecretKeyFactory keyFactory;
            try {
                keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
            }
            catch (NoSuchAlgorithmException e) {
                throw new SaslException("Unable to find PBKDF2WithHmacSHA1.", e);
            }

            try {
                return keyFactory.generateSecret(spec).getEncoded();
            }
            catch (InvalidKeySpecException e) {
                throw new SaslException("Invalid key spec for PBKDC2WithHmacSHA1.", e);
            }
        }

        private byte[] hmac(final byte[] bytes, final String key) throws SaslException {
            SecretKeySpec signingKey = new SecretKeySpec(bytes, "HmacSHA1");

            Mac mac;
            try {
                mac = Mac.getInstance("HmacSHA1");
            }
            catch (NoSuchAlgorithmException e) {
                throw new SaslException("Could not find HmacSHA1.", e);
            }

            try {
                mac.init(signingKey);
            }
            catch (InvalidKeyException e) {
                throw new SaslException("Could not initialize mac.", e);
            }

            return mac.doFinal(decodeUTF8(key));
        }

        /**
         * The server provides back key value pairs using an = sign and delimited
         * by a command. All keys are also a single character.
         * For example: a=kg4io3,b=skljsfoiew,c=1203
         */
        private HashMap<String, String> parseServerResponse(final String response) {
            HashMap<String, String> map = new HashMap<String, String>();
            String[] pairs = response.split(",");
            for (String pair : pairs) {
                String[] parts = pair.split("=", 2);
                map.put(parts[0], parts[1]);
            }

            return map;
        }

        private String prepUserName(final String userName) {
            return userName.replace("=", "=3D").replace(",", "=2D");
        }

        private byte[] xor(final byte[] a, final byte[] b) {
            byte[] result = new byte[a.length];

            for (int i = 0; i < a.length; i++) {
                result[i] = (byte) (a[i] ^ b[i]);
            }

            return result;
        }
    }

    public interface RandomStringGenerator {
        String generate(int length);
    }

    public static class DefaultRandomStringGenerator implements RandomStringGenerator {
        public String generate(final int length) {
            int comma = 44;
            int low = 33;
            int high = 126;
            int range = high - low;

            Random random = new SecureRandom();
            char[] text = new char[length];
            for (int i = 0; i < length; i++) {
                int next = random.nextInt(range) + low;
                while (next == comma) {
                    next = random.nextInt(range) + low;
                }
                text[i] = (char) next;
            }
            return new String(text);
        }
    }
}


text:
=begin
#运行本脚本前,请开启appium_server;
#手机API18(4.3)及以上,手机连接WiFi路由;#手机连接电脑;
#WiFi模块工作在STA模式
#脚本中未做异常网络处理,因此网络需要稳定,平台连接稳定
=end

require 'rubygems'
require 'rspec'
require 'appium_lib'
require 'net/http'
require File.join(File.dirname(__FILE__), 'public_method')

APP_PATH = 'E:\SSC_长虹软服中心\项目文档\智能冰箱技术研究与应用\低成本WiFi模块开发(QCA4004方案)\IceBoxControl_20150615.apk'

def desired_caps
   {
      caps: {
         app:               APP_PATH,
         appActivity:      'com.iceboxcontrol.activitys.LoginActivity',
         appPackage:       'com.iceboxcontrol',
         platformName:     'android',
         platformVersion:  '4.4.4',#API:19
         deviceName:       '274b3f06',#MI 3真机
         # deviceName:       'emulator-5554',
         # platformVersion:  '5.1',#API:22
         # deviceName:       '15584d42', #MI 4真机
         unicodeKeyboard:  'true',
         resetKeyboard:    'true',
         noReset:       'false'
         # newCommandTimeout:'60'
      },
      appium_lib: {
         sauce_username: nil, # don't run on sauce
         sauce_access_key: nil,
         wait: 10,
      }
   }
end

describe 'iceboxcontrol_STA_mode' do
   before(:all) do
      @driver = Appium::Driver.new(desired_caps).start_driver
      Appium.promote_appium_methods RSpec::Core::ExampleGroup
      @username = "13540774227"
      @old_password = @new_password = "123456"
      @wrong_username = "13340774227"
      @wrong_password = @short_password = "12345"
      @new_nickname = "Lucy"
      @wrong_fridgePwd = @short_fridgeNewPwd = "12345"
      @new_fridgeNewPwd = "4008111666"
      @device_name = '成都21'
      @device_sn = "FRTEST400911700407014921"
   end
   after(:all) do
      @drive_quit
   end

   context 'after user login as STA mode' do
      before :all do
         @username_textfiled = find_element(:id, 'com.iceboxcontrol:id/login_username')
         @password_textfiled = find_element(:id, 'com.iceboxcontrol:id/login_password')
         @login_button = find_element(:id, 'com.iceboxcontrol:id/login_btn')
         @autoLogin_button = find_element(:id, 'com.iceboxcontrol:id/auto_login')
         @rememberPassword_button = find_element(:id, 'com.iceboxcontrol:id/remember_psw')
         @forgotPassword_textview = find_element(:id, 'com.iceboxcontrol:id/forgot_psw')
         @registerId_textview = find_element(:id, 'com.iceboxcontrol:id/register_id')
         @mode_textview = find_element(:id, 'android:id/text1')
      end

      context 'login_page' do
         after :each do
            sleep 3
         end
         it 'check the login page elements' do
            expect(@username_textfiled.displayed?).to be true
            expect(@password_textfiled.displayed?).to be true
            expect(@login_button.displayed?).to be true
            expect(@autoLogin_button.displayed?).to be true
            expect(@rememberPassword_button.displayed?).to be true
            expect(@forgotPassword_textview.displayed?).to be true
            expect(@registerId_textview.displayed?).to be true
         end
         it 'can not login as AP mode' do
            if @mode_textview.text == '远程模式'
               @mode_textview.click
               modes = find_elements(:class_name, 'android.widget.CheckedTextView')
               modes[0].click #点击'本地模式'
            elsif @mode_textview.text == '本地模式'
            end
            @login_button.click
            expect((@mode_textview.text) == '本地模式').to be true
            expect(@login_button.displayed?).to be true
         end
         it 'confirm the work mode is STA' do
            if @mode_textview.text == '本地模式'
               @mode_textview.click
               modes = find_elements(:class_name, 'android.widget.CheckedTextView')
               modes[1].click #点击'远程模式'
            elsif @mode_textview.text == '远程模式'
            end
            expect(@login_button.displayed?).to be true
            expect((@mode_textview.text) == '远程模式').to be true
         end
         # context 'login in' do
            it 'can not login with empty username and empty password' do
               login()
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can not login with empty username and no-empty password' do
               login(nil,@old_password)
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can not login with no-empty username and empty password' do
               login(@username,nil)
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can not login with wrong username and wrong password' do
               login(@wrong_username,@wrong_password)
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can not login with right username and wrong password' do
               login(@username,@wrong_password)
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can not login with wrong username and right password' do
               login(@wrong_username,@old_password)
               sleep 5
               expect(@login_button.displayed?).to be true
            end
            it 'can be login with right username and right password' do
               login(@username,@old_password)
               sleep 5
               enter_wkzx_page()
               back_click
               expect(button('确定').displayed?).to be true
               alert_click('确定')
            end
            it 'auto-login worked' do
               start_activity app_package: 'com.iceboxcontrol', app_activity: 'com.iceboxcontrol.activitys.LoginActivity'
               @username_textfiled.clear
               @username_textfiled.type @username
               @password_textfiled.clear
               @password_textfiled.type @old_password
               @autoLogin_button.click
               # @rememberPassword_button.click
               @login_button.click
               sleep 5
               enter_wkzx_page()
               sleep 3
               back_click
               expect(button('确定').displayed?).to be true
               alert_click('确定')
               start_activity app_package: 'com.iceboxcontrol', app_activity: 'com.iceboxcontrol.activitys.LoginActivity'
               sleep 5
               enter_wkzx_page()
               @handle = find_element(:id, 'com.iceboxcontrol:id/handle')
               expect(@handle.displayed?).to be true
            end
         # end
      end

      context 'setting_page' do
         before :all do
            enter_setting_page()
            sleep 5
            @page_title = texts_exact('设置')[0]
            @userinfo_textview = find_element(:id, 'com.iceboxcontrol:id/info')
            @userinfo_textview_text = find_element(:id, 'com.iceboxcontrol:id/infotext')
            @identify_textview = find_element(:id, 'com.iceboxcontrol:id/identify')
            @identify_textview_text = find_element(:id, 'com.iceboxcontrol:id/identifytext')
            @net_setting_textview = find_element(:id, 'com.iceboxcontrol:id/net_setting')
            @net_setting_textview_text = find_element(:id, 'com.iceboxcontrol:id/net_settingtext')
            @dev_connect_textview = find_element(:id, 'com.iceboxcontrol:id/dev_connect')
            @dev_connect_textview_text = find_element(:id, 'com.iceboxcontrol:id/dev_connecttext')
            @soft_update_textview = find_element(:id, 'com.iceboxcontrol:id/soft_update')
            @soft_update_textview_text = find_element(:id, 'com.iceboxcontrol:id/soft_updatetext')
            @soft_update_textview_noupdate = find_element(:id, 'com.iceboxcontrol:id/soft_update_noupdate')
            @telephone_textview = find_element(:id, 'com.iceboxcontrol:id/telephone')
            @unlogin_textview = find_element(:id, 'com.iceboxcontrol:id/unlogin')
            @unlogin_textview_text = find_element(:id, 'com.iceboxcontrol:id/munlogin')
         end
         after :all do
            sleep 5
         end

         it 'check the setting page elements' do
            expect(@page_title.displayed?).to be true
            expect((@page_title.text) == '设置').to be true
            expect((@userinfo_textview_text.text) == '个人信息').to be true
            expect((@identify_textview_text.text) == '冰箱密码').to be true
            expect((@net_setting_textview_text.text) == '网络设置').to be true
            expect((@dev_connect_textview_text.text) == '设备连接').to be true
            expect((@soft_update_textview_text.text) == '软件更新').to be true
            expect((@soft_update_textview_noupdate.text) == '已是最新版本').to be true
            expect((@unlogin_textview_text.text) == '退出登录').to be true
         end

         context 'userinfo page' do
            before :each do
               # sleep 3
               # @userinfo_textview.click #进入个人信息页面
               # sleep 5
               enter_userinfo_page()
               @userinfo_title_textview = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_title')
               @userinfo_nickname_textfiled = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_nickname_input')
               @userinfo_saveUserinfo_button = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_saveinfo')
               @userinfo_passwordModify_button = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modifypassword')
            end
            after :all do
               sleep 3
            end
            ##修改个人信息
            it 'check user nickname' do
               begin
                  expect((@userinfo_title_textview.text) == '个人信息').to be true
                  expect((@userinfo_nickname_textfiled.text) == @new_nickname).to be true
               ensure
                  back_click() #返回设置页面
               end
            end
            it 'change user nickname without confirm' do
               clear_nickname()
               sleep 5
               set_nickname(@new_nickname)
               @driver.navigate.back #取消,返回设置页面
               sleep 5
               expect((@page_title.text) == '设置').to be true
            end
            it 'change user nickname with 21 characters(limit:20)' do
               begin
                  clear_nickname()
                  sleep 5
                  set_nickname(nickname = " abc !@#$%^&*()  def ")
                  @userinfo_saveUserinfo_button.click
                  sleep 10
                  expect(@page_title.text) == '设置'#保存成功,返回设置页面
                  @userinfo_textview.click #进入个人信息页面
                  expect(@userinfo_nickname_textfiled.text == nickname[0..-2]).to be true #确认信息修改成功
               ensure
                  back_click #返回设置页面
                  sleep 3
               end
            end
            it 'change user nickname with confirm' do
               begin
                  clear_nickname()
                  sleep 5
                  set_nickname(@new_nickname)
                  @userinfo_saveUserinfo_button.click #保存成功,返回设置页面
                  sleep 5
                  @userinfo_textview.click #进入个人信息页面,确认信息修改成功
                  expect((@userinfo_nickname_textfiled.text) == @new_nickname).to be true
               ensure
                  back_click #返回设置页面
               end
            end
            context 'change userinfo_password page' do
               before :each do
                  sleep 3
                  @userinfo_passwordModify_button.click #从个人信息页面进入密码修改页面
                  sleep 5
                  @userinfo_oldpwd_textfiled = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modify_oldpwd_input')
                  @userinfo_newpwd_textfiled = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modify_newpwd_input')
                  @userinfo_newpwdRepeat_textfiled = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modify_newpwd_repeat_input')
                  @confirm_button = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modify_yes')
                  @cancel_button = find_element(:id, 'com.iceboxcontrol:id/setting_userinfo_modify_no')
               end
               after :all do
                  sleep 3
               end

               it 'check the password modify page elements' do
                  begin
                     expect(@confirm_button.displayed?).to be true
                     expect((@confirm_button.text) == '确定').to be true
                     expect(@cancel_button.displayed?).to be true
                     expect((@cancel_button.text) == '取消').to be true
                  ensure
                     @cancel_button.click #返回个人信息页面
                     back_click #返回设置页面
                  end
               end
               it 'click cancel_button before type any text' do
                  begin
                     @cancel_button.click
                     expect((@userinfo_title_textview.text) == '个人信息').to be true #取消修改则返回个人信息页面
                  ensure
                     back_click #返回设置页面
                  end
               end
               it 'click confirm_button before type any text' do
                  begin
                     @confirm_button.click
                     expect(@userinfo_oldpwd_textfiled.displayed?).to be true #未输入数据就确认修改,则停留在修改页面
                  ensure
                     @cancel_button.click #返回个人信息页面
                     back_click #返回设置页面
                  end
               end
               it 'change userinfo_password with wrong password' do
                  begin
                     change_user_password(@wrong_password,@new_password,@new_password)
                     @confirm_button.click
                     expect((@userinfo_title_textview.text) == '个人信息').to be true #提示旧密码错误后,返回个人信息页面
                  ensure
                     back_click #返回设置页面
                  end
               end
               it 'change userinfo_password with new password short' do
                  begin
                     change_user_password(@old_password,@short_password,@short_password)
                     @confirm_button.click
                     expect(@userinfo_oldpwd_textfiled.displayed?).to be true #新密码长度不够,则停留在修改页面
                     sleep 3
                  ensure
                     @cancel_button.click;sleep 1 #返回个人信息页面
                     back_click #返回设置页面
                     expect((@page_title.text) == '设置').to be true #返回设置页面
                  end
               end
               it 'change userinfo_password with new password & repeat password not match' do
                  begin
                     change_user_password(@old_password,@new_password,@username)
                     @confirm_button.click
                     expect(@userinfo_oldpwd_textfiled.displayed?).to be true #新密码两次输入不一致,则停留在修改页面
                     sleep 3
                  ensure
                     @cancel_button.click;sleep 1 #返回个人信息页面
                     back_click #返回设置页面
                     expect((@page_title.text) == '设置').to be true #返回设置页面
                  end
               end
               it 'confirm change userinfo_password' do
                  change_user_password(@old_password,@new_password,@new_password)
                  @confirm_button.click
                  expect((@page_title.text) == '设置').to be true #修改成功,返回设置页面
               end
            end
         end

         context 'fridgePwd page'do
            before :each do
               enter_fridgePwd_page()
               sleep 3
               @fridgeNewPwd_page_back = find_element(:id, 'com.iceboxcontrol:id/identify_back')
               @fridgePwd_page_title = find_element(:id, 'com.iceboxcontrol:id/identify_title')
               @fridgeNewPwd_sninput = find_element(:id, 'com.iceboxcontrol:id/resetvericode_sninput')
               @fridgeNewPwd = find_element(:id, 'com.iceboxcontrol:id/resetvericode_vericodeinput')
               @fridgeNewPwdRepeat = find_element(:id, 'com.iceboxcontrol:id/resetvericode_vericoderepeat')
               @fridgeNewPwd_confirm_button = find_element(:id, 'com.iceboxcontrol:id/resetvericode_confirm')
            end
            after :all do
               sleep 5
            end
            it 'check the fridgePwd page elements'do
               begin
                  expect(@fridgeNewPwd_page_back.displayed?).to be true
                  expect((@fridgePwd_page_title).displayed?).to be true
                  expect((@fridgePwd_page_title).text == '冰箱密码').to be true
                  expect(@fridgeNewPwd_sninput.displayed?).to be true
                  expect(@fridgeNewPwd.displayed?).to be true
                  expect(@fridgeNewPwdRepeat.displayed?).to be true
                  expect(@fridgeNewPwd_confirm_button.displayed?).to be true
               ensure
                  @fridgeNewPwd_page_back.click #返回设置页面
               end
            end
            it 'click confirm_button before type any text' do
               begin
                  @fridgeNewPwd_confirm_button.click
                  expect(@fridgePwd_page_title.displayed?).to be true
               ensure
                  @fridgeNewPwd_page_back.click #返回设置页面
               end
            end
            it 'change fridgePwd with new password & repeat password not match' do
               begin
                  change_fridgePwd(@short_fridgeNewPwd,@new_fridgeNewPwd)
                  @fridgeNewPwd_confirm_button.click
                  expect(@fridgePwd_page_title.displayed?).to be true #新密码两次输入不一致,则停留在当前页面
                  sleep 3
               ensure
                  @fridgeNewPwd_page_back.click #返回设置页面
               end
            end
            it 'confirm change fridgePwd' do
               begin
                  change_fridgePwd(@new_fridgeNewPwd,@new_fridgeNewPwd)
                  @fridgeNewPwd_confirm_button.click
                  @fridgeNewPwd_page_back.click #返回设置页面
                  enter_fridgePwd_page()
                  expect((@fridgeNewPwd_sninput).displayed?).to be true
               ensure
                  @fridgeNewPwd_page_back.click #返回设置页面
               end
            end
         end

         context 'network_setting page'do
            it 'can not enter net_setting page'do
               enter_net_setting_page()
               expect(exists{@net_setting_textview_text}).to be true
            end
         end

         context 'device_connect page'do
            before :each do
               enter_device_connect_page()
               sleep 3
               @device_setting_back = find_element(:id, 'com.iceboxcontrol:id/device_setting_back')
               @device_connect_title = find_element(:id, 'com.iceboxcontrol:id/device_connect_title')
               @device_connect_devicelist = find_element(:id, 'com.iceboxcontrol:id/device_connect_devicelist')
               @device_connect_add_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_add')
               @device_connect_connect_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_connect')
            end
            after :all do
               sleep 5
            end

            it 'check the device_connect page elements'do
               begin
                  expect(@device_setting_back.displayed?).to be true
                  expect(@device_connect_title.displayed?).to be true
                  expect((@device_connect_title).text == '设备连接').to be true
                  expect(@device_connect_devicelist.displayed?).to be true
                  expect(@device_connect_add_button.displayed?).to be true
                  expect(@device_connect_connect_button.displayed?).to be true
               ensure
                  @device_setting_back.click #返回设置页面
               end
            end

            it 'delete all devices before add' do
               begin
                  if exists{button('解绑定')}== false
                  else
                     devices = buttons('解绑定')
                     for device in devices
                        button('解绑定').click
                        button('确定').click
                     end
                  end
               ensure
                  back_click
               end
            end

            context 'device_connect_add page' do
               before :each do
                  enter_device_connect_add_page() #从设备连接页面进入添加绑定设备页面
                  sleep 3
                  @device_connect_add_name = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_nameinput')
                  @device_connect_add_sn = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_sninput')
                  @device_connect_add_scan = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_scan')
                  @device_connect_add_fridgePwd = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_vericodeinput')
                  @device_connect_add_confirm_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_yes')
                  @device_connect_add_cancel_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_add_no')
               end
               after :all do
                  sleep 3
               end
               it 'check the device_connect page elements'do
                  expect(@device_connect_add_name.displayed?).to be true
                  expect((@device_connect_add_sn).displayed?).to be true
                  expect(@device_connect_add_fridgePwd.displayed?).to be true
                  expect(@device_connect_add_confirm_button.displayed?).to be true
                  expect(@device_connect_add_cancel_button.displayed?).to be true
                  @device_connect_add_cancel_button.click
                  back_click #返回设置页面
               end
               it 'click confirm_button before type any text' do
                  begin
                     clear_device_connect_add_info()
                     device_connect_add()
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #未输入数据就确认修改,则停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回个人信息页面
                     @device_setting_back.click #返回设置页面
                  end
               end
               it 'device_connect_add with no name' do
                  begin
                     clear_device_connect_add_info()
                     device_connect_add(nil,@device_sn,@wrong_fridgePwd)
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回个人信息页面
                     @device_setting_back.click #返回设置页面
                  end
               end
               it 'device_connect_add with no sn' do
                  begin
                     clear_device_connect_add_info()
                     device_connect_add(@device_name,nil,@wrong_fridgePwd)
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回个人信息页面
                     @device_setting_back.click #返回设置页面
                  end
               end
               it 'device_connect_add with no password' do
                  begin
                     clear_device_connect_add_info()
                     device_connect_add(@device_name,@device_sn,nil)
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回个人信息页面
                     @device_setting_back.click #返回设置页面
                  end
               end
               it 'device_connect_add with wrong sn' do
                  begin
                     clear_device_connect_add_info()
                     device_connect_add(@device_name,@device_sn.chop,@wrong_fridgePwd) #移除sn中的最后一个字符
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #提示旧密码错误后,则停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回设备连接页面
                     back_click #返回设置页面
                  end
               end
               it 'device_connect_add with wrong password' do
                  begin
                     device_connect_add(@device_name,@device_sn,@wrong_fridgePwd)
                     @device_connect_add_confirm_button.click
                     expect(@device_connect_add_confirm_button.displayed?).to be true #提示旧密码错误后,则停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回设备连接页面
                     back_click #返回设置页面
                  end
               end
               it 'device_connect_add success' do
                  begin
                     device_connect_add(@device_name,@device_sn,@new_fridgeNewPwd)
                     @device_connect_add_confirm_button.click
                     sleep 3
                     @device_connect_item_name = find_element(:id, 'com.iceboxcontrol:id/device_connect_item_name')
                     expect(@device_connect_item_name.text).to eq(@device_name)
                     expect(exists{button('解绑定')}).to be true
                  ensure
                     @device_setting_back.click #返回设置页面
                  end
               end
               it 'device_connect_add fail by twice' do
                  begin
                     device_connect_add(@device_name,@device_sn,@new_fridgeNewPwd)
                     @device_connect_add_confirm_button.click
                     sleep 3
                     expect(@device_connect_add_confirm_button.displayed?).to be true #停留在当前页面
                  ensure
                     @device_connect_add_cancel_button.click #返回设备连接页面
                     back_click #返回设置页面
                  end
               end
            end

            context 'device_connect_select page' do
               before :each do
                  enter_device_connect_select_page() #从设备连接页面进入设备选择页面
                  sleep 3
                  @device_connect_control_name = find_element(:id, 'com.iceboxcontrol:id/device_connect_control_item_name')
                  @device_connect_item_choosed = find_element(:id, 'com.iceboxcontrol:id/device_connect_item_choosed')
                  @device_connect_control_confirm_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_control_yes')
                  @device_connect_control_cancel_button = find_element(:id, 'com.iceboxcontrol:id/device_connect_control_no')
               end
               after :all do
                  sleep 3
               end

               it 'check the device_connect_select page elements' do
                  begin
                     expect(@device_connect_control_confirm_button.displayed?).to be true
                     expect((@device_connect_control_confirm_button.text) == '确定').to be true
                     expect(@device_connect_control_cancel_button.displayed?).to be true
                     expect((@device_connect_control_cancel_button.text) == '取消').to be true
                  ensure
                     @device_connect_control_cancel_button.click #返回设备连接页面
                     back_click #返回设置页面
                  end
               end
               it 'click  cancel button before select any device' do
                  begin
                     @device_connect_control_cancel_button.click
                     expect(@device_connect_title.text).to eq('设备连接') #返回设备连接页面
                     expect(exists{text_exact('已连接')}).to be false
                  ensure
                     back_click #返回设置页面
                  end
               end
               it 'click  confirm button before select any device' do
                  begin
                     @device_connect_control_confirm_button.click
                     expect(@device_connect_control_confirm_button.displayed?).to be true #停留在当前页面
                  ensure
                     @device_connect_control_cancel_button.click #返回设备连接页面
                     back_click #返回设置页面
                  end
               end
               it 'click cancel button after select an device' do
                  begin
                     @device_connect_control_name.click
                     @device_connect_control_cancel_button.click
                     expect(@device_connect_title.text).to eq('设备连接') #返回设备连接页面
                     expect(exists{text_exact('已连接')}).to be false
                  ensure
                     back_click #返回设置页面
                  end
               end
               it 'connect an device' do
                  begin
                     @device_connect_control_name.click
                     @device_connect_control_confirm_button.click
                     expect(exists{text_exact('已连接')}).to be true #设备已连接
                  ensure
                     back_click #返回设置页面
                  end
               end
            end
         end

         context 'unlogin page' do
            before :each do
               @unlogin_textview.click
            end
            after :all do
               sleep 3
            end
            it 'check unlogin page elements' do
               begin
                  expect(text('确定退出登录吗!').displayed?).to be true
                  expect(button('确定').displayed?).to be true
                  expect(button('取消').displayed?).to be true
               ensure
                  button('取消').click
               end
            end
            it 'click cancel button maintain login status' do
               button('取消').click
               expect(@unlogin_textview_text.text).to eq('退出登录')
            end
            it 'click confirm button to logout' do
               begin
                  button('确定').click
                  sleep 3
                  start_activity app_package: 'com.iceboxcontrol', app_activity: 'com.iceboxcontrol.activitys.LoginActivity'
                  expect(@autoLogin_button.attribute('checked')).to eq('false')
                  expect(@rememberPassword_button.attribute('checked')).to eq('true')
               ensure
                  @login_button.click
                  enter_wkzx_page()
                  sleep 3
               end
            end
         end
      end

      context 'foodmanage_page' do
         before :all do
            enter_foodmanage_page()
            @foodmanage_title = id('com.iceboxcontrol:id/foodmanage_title')
            @foodmanage_foodadd = id('com.iceboxcontrol:id/foodmanage_foodadd')
            @foodmanage_categary_list = id('com.iceboxcontrol:id/foodmanage_categary_list')
            # @foodmanage_item_icon = id('com.iceboxcontrol:id/foodmanage_item_icon')
            # @foodmanage_item_name = id('com.iceboxcontrol:id/foodmanage_item_name')
            # @foodmanage_item_weight = id('com.iceboxcontrol:id/foodmanage_item_weight')
            # @foodmanage_item_Unit = id('com.iceboxcontrol:id/foodmanage_item_Unit')
            # @foodmanage_item_remaindays = id('com.iceboxcontrol:id/foodmanage_item_remaindays')
         end
         after :all do
            sleep 3
         end
         it 'check foodmanage_page elements' do
            expect(@foodmanage_title.text).to eq('食品管理')
            expect(@foodmanage_foodadd.displayed?).to be true
            expect(text('名称').displayed?).to be true
            expect(text('数量/重量').displayed?).to be true
            expect(text('剩余时限').displayed?).to be true
            expect(@foodmanage_categary_list.displayed?).to be true
         end
         it 'delete all foods before add' do
            begin
               10000.times do
                  if exists{id('com.iceboxcontrol:id/foodmanage_item_name')} == false
                     break
                  else
                  food = id('com.iceboxcontrol:id/foodmanage_item_name')
                  delete_food_from_categary_list = Appium::TouchAction.new.press(element:food).wait(4000).perform#.release(element:food).perform
                  button('确定').click
                  sleep 3
                  end
               end
            ensure
               expect(exists{food}).to be false
            end
         end
         context 'food add page' do
            before :each do
               enter_foodadd_page()
               @foodadd_title = id('com.iceboxcontrol:id/foodadd_title')
               @foodadd_back = id('com.iceboxcontrol:id/foodadd_back')
               @foodadd_voiceinput = id('com.iceboxcontrol:id/foodadd_voiceinput')
               @foodadd_left = id('com.iceboxcontrol:id/foodadd_left')
               @foodadd_right = id('com.iceboxcontrol:id/foodadd_right')
               @foodadd_search_input = id('com.iceboxcontrol:id/foodadd_searchfood')
               @foodadd_search_icon = id('com.iceboxcontrol:id/foodadd_search_icon')
            end
            after :each do
               @foodadd_back.click
            end

            it 'check food add page elements' do
               expect(@foodadd_title.text).to eq('食品添加')
               expect(@foodadd_back.displayed?).to be true
               expect(@foodadd_voiceinput.displayed?).to be true
               expect(@foodadd_left.displayed?).to be true
               expect(@foodadd_right.displayed?).to be true
               expect(@foodadd_search_input.displayed?).to be true
               expect(@foodadd_search_icon.displayed?).to be true
            end
            it 'check each food add categary' do
               text('蔬菜').click
               expect(text('白菜').displayed?).to be true
               text('肉类').click
               expect(text('鹅').displayed?).to be true
               text('豆蛋制品').click
               expect(text('鹌鹑蛋').displayed?).to be true
               text('乳制品').click
               expect(text('冰激凌').displayed?).to be true
            end
            it 'food add categary can swipe' do
               swipe(start_x: 900, start_y: 300, end_x: 50, end_y: 300, duration: 4000)
               expect(text('剩菜剩饭').displayed?).to be true
               text('水果').click
               expect(text('板栗').displayed?).to be true
               text('其他').click
               expect(text('茶饮料').displayed?).to be true
               text('水产品').click
               expect(text('鲍鱼').displayed?).to be true
               text('剩菜剩饭').click
               expect(text_exact('剩菜').displayed?).to be true
            end
            it 'foodadd_left and foodadd_right are work' do
               3.times {@foodadd_right.click; sleep 1}
               text('剩菜剩饭').click
               expect(exists{text_exact('剩菜')}).to be true
               3.times {@foodadd_left.click; sleep 1}
               text('蔬菜').click
               expect(exists{text('白菜')}).to be true
            end
            it 'search do not work with full blank' do
                  foodadd_search(foodname = "  ")
                  expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
            it 'search do not work with "*"' do
                  foodadd_search(foodname = "豆腐*")
                  expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
            it 'search do not work with blank before food name' do
                  foodadd_search(foodname = ' 豆腐')#空格为转义字符,不能用双引号
                  expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
            it 'search do not work with blank between food name' do
                  foodadd_search(foodname = "豆 腐")
                  expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
            it 'search do not work with blank after food name' do
                  foodadd_search(foodname = "豆腐 ")
                  expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
            it 'search food in menu' do
               foodadd_search(foodname = "豆腐")
               expect(text('麻婆豆腐').displayed?).to be true
               expect(texts('豆腐').size).to eq 7
            end
            it 'search food not in menu' do
               foodadd_search(foodname = "果冻")
               expect(exists{id('com.iceboxcontrol:id/foodadd_item_text')}).to be false
            end
         end
      end

      context 'cookbook_page' do
         before :all do
            enter_cookbook_page()
            @title_slect = id('com.iceboxcontrol:id/titleimage2')
            @horizontal_button = tags('android.widget.RadioButton')
            @search_button = id('com.iceboxcontrol:id/titleimage3')
         end
         it 'check cookbook_page elements' do
            expect(text('按推荐').displayed?).to be true
            expect(@title_slect.displayed?).to be true
            expect(@search_button.displayed?).to be true
            expect(text('最新发布').displayed?).to be true
            expect(text('热门菜谱').displayed?).to be true
            expect(text('时令菜蔬').displayed?).to be true
            expect(text('智慧烹饪').displayed?).to be true
         end
      end
   end
end


text:
<?php defined('SYSPATH') OR die('No direct script access.');

abstract class Model extends Kohana_Model {}


text:
package com.intellij.lang.properties;

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author cdr
 */
class RemovePropertyFix implements IntentionAction {
  private final SmartPsiElementPointer<Property> myProperty;

  RemovePropertyFix(@NotNull final Property origProperty) {
    myProperty = SmartPointerManager.getInstance(origProperty.getProject()).createSmartPsiElementPointer(origProperty);
  }

  @Override
  @NotNull
  public String getText() {
    return PropertiesBundle.message("remove.property.intention.text");
  }

  @Override
  @NotNull
  public String getFamilyName() {
    return getText();
  }

  @Override
  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    return file != null &&
           file.isValid() &&
           PsiManager.getInstance(project).isInProject(file) &&
           myProperty.getElement() != null;
  }

  @Nullable
  @Override
  public PsiElement getElementToMakeWritable(@NotNull PsiFile currentFile) {
    return myProperty.getElement();
  }

  @Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    ObjectUtils.notNull(myProperty.getElement()).delete();
  }

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


text:
@interface GTMSignalHandler : NSObject {
 @private
  int signo_;
  __weak id target_;
  SEL action_;
}

// Returns a retained signal handler object that will invoke |handler| on the
// |target| whenever a signal of number |signo| is delivered to the process.
-(id)initWithSignal:(int)signo
             target:(id)target
             action:(SEL)action;

@end


text:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace DanielBogdan.PlainRSS.UI.Properties {
    using System;

    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }

        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DanielBogdan.PlainRSS.UI.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap advanced {
            get {
                object obj = ResourceManager.GetObject("advanced", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap advancedsettings {
            get {
                object obj = ResourceManager.GetObject("advancedsettings", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap agt_web {
            get {
                object obj = ResourceManager.GetObject("agt_web", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap edit {
            get {
                object obj = ResourceManager.GetObject("edit", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap exit {
            get {
                object obj = ResourceManager.GetObject("exit", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap feed_icon_grey_24px {
            get {
                object obj = ResourceManager.GetObject("feed_icon_grey_24px", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap feed_icon_orange_24px {
            get {
                object obj = ResourceManager.GetObject("feed_icon_orange_24px", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap ic_delete_black_24dp_1x {
            get {
                object obj = ResourceManager.GetObject("ic_delete_black_24dp_1x", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap new_window {
            get {
                object obj = ResourceManager.GetObject("new_window", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap rss {
            get {
                object obj = ResourceManager.GetObject("rss", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
        /// </summary>
        internal static System.Drawing.Icon rssico {
            get {
                object obj = ResourceManager.GetObject("rssico", resourceCulture);
                return ((System.Drawing.Icon)(obj));
            }
        }

        /// <summary>
        ///   Looks up a localized string similar to Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
        ///Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
        ///Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
        ///Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
        ///Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/2 [rest of string was truncated]";.
        /// </summary>
        internal static string UserAgents {
            get {
                return ResourceManager.GetString("UserAgents", resourceCulture);
            }
        }

        /// <summary>
        ///   Looks up a localized resource of type System.Drawing.Bitmap.
        /// </summary>
        internal static System.Drawing.Bitmap x {
            get {
                object obj = ResourceManager.GetObject("x", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
    }
}