text:
<?php
/**
 * class RainGaugeModel
 *
 * handle getting values from the conf file, reading information about
 * collections and parsing their data.
 *
 *
 * @author Gavin Towey <gavin@box.com>
 * @created 2012-05-01
 * @license Apache 2.0 license.  See LICENSE document for more info
 */

class RainGaugeModel {

    private $conf;
    private $datasource;

    function __construct($conf, $datasource) {
        $this->conf = $conf;
        $this->datasource = $datasource;
    }

    /**
     * when receiving a file upload, call this method.  This is where we
     * can define any additional actions on a file upload, such as saving to
     * a database
     *
     * @param string $hostname
     * @param int $port
     * @param string $filename
     */
    function save_file($hostname, $port, $filename) {
        // it's a tar.gz ... we want to examine it and store some metadata
        // optionally store metadata in a database as well
        if (is_callable($this->conf['on_file_upload']))
        {
            $callback = $this->conf['on_file_upload'];
            $callback($hostname, $port, $filename);
        }
    }

    /**
     * given a hostname, read the local directory where collections are stored
     * and return a list of all gzipped samples found, along with the timestamp
     * and size
     *
     * @param string $hostname
     * @param int $starttime
     * @param int $endtime
     * @return array a list of arrays describing each samples.
     */
    function list_samples($hostname, $starttime = null, $endtime = null) {
        // get a list of all the .tar.gz files we receive
        $result = array();
        $triggers = array();
        $collection_dir = $this->collection_dir() . '/' . $hostname;

        $SERVERDIR = opendir($collection_dir);
        while ($file = readdir($SERVERDIR)) {
            $time_part = substr($file, 0, 19);
            $trigger = substr($file, 20, 7);
            $reason = substr($file, 28);
            $format = "%Y_%m_%d_%H_%M_%S";
            $time = strptime($time_part, $format);
            $timestamp = mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
            if ($trigger == "trigger") {
                $triggers[$timestamp] = $reason;
            }
        }
        closedir($SERVERDIR);

        $SERVERDIR = opendir($collection_dir);
        while ($file = readdir($SERVERDIR)) {
            $time_part = substr($file, -26);
            $format = "%Y_%m_%d_%H_%M_%S.tar.gz";
            $time = strptime($time_part, $format);

            if (is_array($time)) {
                $timestamp = mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
                if (isset($starttime) and $timestamp < $starttime) {
                    continue;
                }
                if (isset($endtime) and $timestamp > $endtime) {
                    continue;
                }

                $result[] = array(
                    'timestamp' => $timestamp,
                    'size' => filesize(join('/', array($collection_dir, $file))),
                    'name' => $file,
                    'trigger' => $triggers[$timestamp]
                );
            }
        }
        closedir($SERVERDIR);
        return $result;
    }

    /**
     * For a hostname, and a given filename, open the archive and return
     * information about the files in it. This will extract the gzip archive to
     * a temp directory.
     *
     * @param string $hostname
     * @param string $filename
     * @return array    list of arrays which describe each file.
     * @throws Exception    when the given $filename doesn't exist, or there is an error extracting the archive
     */
    function get_sample($hostname, $filename) {
        // get information about stats collected
        $source_file = $this->collection_dir() . '/' . $hostname . '/' . $filename;
        $tmp_dir = $this->tmp_dir() . '/' . $filename;
        // print "tmp_dir: {$tmp_dir}
";
        if (!file_exists($source_file)) {
            throw new Exception("File {$filename} doesn't exist for {$hostname}");
        }
        if (!is_dir($tmp_dir)) {
            mkdir($tmp_dir);
            $cmd = "tar -zxf {$source_file} -C {$tmp_dir}";
            //print "cmd: [{$cmd}]
";
            $result = exec($cmd);
            if ($result) {
                throw new Exception("Cannot untar {$source_file} to {$tmp_dir}");
            }
        }

        $result = array();
        $DIR = opendir($tmp_dir);
        while ($file = readdir($DIR)) {
            if (in_array($file, array('.', '..', 'saved_trigger_values'))) {
                continue;
            }
            $result[] = array('name' => $file,
                'short_name' => substr($file, 20)
            );
        }

        return $result;
    }

    /**
     * Given a sample for a server, return it's position in the list of all
     * samples as a percentage when sorted by time.
     *
     * @param string $hostname
     * @param string $sample
     * @return int
     */
    public function get_sample_percent($hostname, $sample) {
        $samples = $this->list_samples($hostname);

        $sort_key = 'timestamp';
        usort($samples, function ($a, $b) use ($sort_key) {
                    return $a[$sort_key] > $b[$sort_key];
                });

        $n = 0;
        $i = 0;
        foreach ($samples as $s) {
            if ($s['name'] == $sample) {
                $n = $i;
                break;
            }
            $i++;
        }

        return $n / count($samples) * 100;
    }

    public function get_mutex_deltas($hostname, $sample, $ts)
    {
        //print "$hostname / $sample / $ts ";
        $mutex1 = $this->get_file($hostname, $sample, $ts.'-mutex-status1');
        $mutex2 = $this->get_file($hostname, $sample, $ts.'-mutex-status2');

        $result = array();
        for ($i=0; $i < count($mutex1); $i++)
        {

            $m1_parts = explode("\t", $mutex1[$i]);
            $m2_parts = explode("\t", $mutex2[$i]);

            $mutex_name = $m1_parts[1];

            list($none, $m1_value) = explode("=", $m1_parts[2]);
            list($none, $m2_value) = explode("=", $m2_parts[2]);

            //print "$mutex_name: $m1_value, $m2_value
";
            if (!array_key_exists($mutex_name, $result))
            {
                $result[$mutex_name] = $m2_value - $m1_value;
            }
            else
            {
                $result[$mutex_name] += $m2_value - $m1_value;
            }
        }
        return $result;
    }

    /**
     * given a server and filename, get a valid full path to a collection archive file.
     *
     * @param string $server
     * @param string $file
     * @return mixed the string representation of the full file path if the file exists. Otherwise, false.
     */
    public function get_collection_filename($server, $file) {
        // TODO: (ganderson) this is horribly insecure. We need to make sure the path doesn't step out of this directory.
        $file = $this->collection_dir() . '/' . $server . '/' . $file;
        if (file_exists($file)) {
            return $file;
        }
        return false;
    }

    /**
     * return the contents of a specific file in a sample.
     *
     * @param string $hostname
     * @param string $sample
     * @param string $file
     * @return array    The lines of the file
     */
    public function get_file($hostname, $sample, $file) {
        $file = $this->tmp_dir() . '/' . $sample . '/' . $file;
        if (file_exists($file)) {
            return file($file);
        }
        return array();
    }

    /**
     * Many samples are collected multiple times with a timestamp between each
     * sample.  This function will try to split these types of files into
     * an array of pages to make it easier to display part of the file at a time.
     *
     * @param string $hostname
     * @param string $sample
     * @param string $file
     * @return array an array with an element for each page, which itself is an array of lines for that page
     */
    public function get_file_pages($hostname, $sample, $file) {
        $file = $this->get_file($hostname, $sample, $file);
        $page_boundary = 0;
        $result = array();
        for ($i = 0; $i < count($file); $i++) {

            if (preg_match("/^\s*TS\s*\d+\.\d+/", $file[$i])) {
                //print "matched boundary $page_boundary at $i  length ".($i-$page_boundary )."
\n";
                if ($page_boundary > 0 and $i - $page_boundary > 1) {
                    $result[] = array_slice($file, $page_boundary, $i - $page_boundary);
                }
                $page_boundary = $i;
            }
        }
        if (!count($result)) {
            return array($file);
        }

        return $result;
    }

    /**
     * given the text output of the mysqladmin variables dump, parse them into
     * key, value pairs
     *
     * @param array $lines
     * @return array  array of Variable_name=>Value pairs
     */
    function parse_mysqladmin(array $lines) {
        $status = array();
        foreach ($lines as $line) {
            if (preg_match("/\|\s+(\w+)\s+\|\s+([\w\d]+)\s+\|/", $line, $match)) {
                if ($match[1] == 'Variable_name') {
                    continue;
                }

                $status[$match[1]][] = $match[2];
            }
        }
        return $status;
    }

    /**
     * Given the output from files such as processlist that use the \G style output
     * turn that column format into an array with one element per record.
     * @param array $lines
     * @return array    The array of records
     */
    function parse_rows_to_result_set(array $lines) {
        $result = array();
        foreach ($lines as $line) {
            if (substr($line, 1, 8) == '********') {
                if (isset($row) && is_array($row)) {
                    $result[] = $row;
                }
                $row = array();
            } else if (substr($line, 0, 3) != 'TS ' and $column = preg_split("/:/", $line)) {

                $column_name = trim($column[0]);
                if ($column_name == 'Rows_sent') {
                    $in_query = false;
                }

                if ($column_name == 'Info') {
                    $row[$column_name] = trim($column[1]);
                    $in_query = true;
                    continue;
                }

                if (!$in_query) {
                    $row[$column_name] = trim($column[1]);
                } else {
                    $row['Info'] .= $line;
                }
            }
        }

        if (is_array($row)) {
            $result[] = $row;
        }

        return $result;
    }

    /**
     * run pt-sift on the given sample
     *
     * @param string $hostname
     * @param string $filename
     * @param string $action    the action to pass to pt-sift
     * @return array    the output from pt-sift
     */
    function sift($hostname, $filename, $action = null) {
        $tmp_dir = $this->tmp_dir() . '/' . $filename;

        if (!isset($action)) {
            $action = 'DEFAULT';
        }
        // pt-sift required that HOME be defined, but some php
        // configurations don't set this for proc_open by default
        $env_home = getenv('HOME');
        if (!isset($env_home))
        {
            $env_home = '/root';
        }
        $cmd = "ACTION=$action HOME={$env_home} pt-sift {$tmp_dir}";
        $output = $this->exec_external_script($cmd, 'q');
        return array($output);
    }

    /**
     * return the tmp_dir setting configured by the conf file.
     *
     * @return string the tmp dir name
     */
    private function tmp_dir() {
        $dir = $this->conf['tmp_dir'];
        if (substr($dir, 0, 1) != '/') {
            $dir = $this->conf['base_dir'] . '/' . $dir;
        }
        return $dir;
    }

    /**
     * return the collection_dir setting configured by the conf file.
     * @return string   the collection dir setting
     */
    private function collection_dir() {
        $dir = $this->conf['collection_dir'];
        if (substr($dir, 0, 1) != '/') {
            $dir = $this->conf['base_dir'] . '/' . $dir;
        }

        return $dir;
    }

    /**
     * for each server, read it's data from the collection dir, and build
     * and array suitable to pass to flot for graphing
     *
     * @param string $hostname
     * @return array    array of information about all collections to pass to flot.
     *
     * @throws Exception    when a collection dir cannot be read
     */
    function get_collection_graph($hostname = null) {
        // build a series for each server in the collection dir
        // add a point for each collection
        $data = array();

        $collection_dir = $this->collection_dir();
        $DIR = opendir($collection_dir);
        if (!isset($DIR)) {
            throw new Exception("Can't read collection dir {$collection_dir}");
        }

        $last_sample = array();
        while ($entry = readdir($DIR)) {
            if (!is_dir($collection_dir . '/' . $entry) or in_array($entry, array('..', '.'))) {
                continue;
            }

            if (isset($hostname) and $hostname != $entry) {
                continue;
            }

            $SERVERDIR = opendir($collection_dir . '/' . $entry);

            while ($file = readdir($SERVERDIR)) {
                $time_part = substr($file, -26);
                $format = "%Y_%m_%d_%H_%M_%S.tar.gz";
                $time = strptime($time_part, $format);
                if (is_array($time)) {
                    $timestamp = mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
                    $data[$entry][] = array($timestamp, filesize(join('/', array($collection_dir, $entry, $file))));

                    if (!array_key_exists($entry, $last_sample) or $timestamp > $last_sample[$entry])
                    {
                        $last_sample[$entry] = $timestamp;
                    }
                }
            }
            closedir($SERVERDIR);
        }
        closedir($DIR);

        arsort($last_sample);
        $finaldata = array();
        $i = 0;
        foreach ($last_sample as $server => $time) {
            $series = $data[$server];
            if (!count($series)) {
                continue;
            }
            usort($series, function ($a, $b) {
                        return $a[0] > $b[0];
                    });
            $finaldata[] = array('label' => $server, 'data' => $series, 'color' => $i++);
        }

        return $finaldata;
    }

    /**
     * Open a two-way communication with an external script.  Used to send
     * data to the program on STDIN and collect output on STDOUT.
     *
     * @param string $script        The script to invoke
     * @param string $input         The input to send to the script on STDIN
     * @return string   The output from the script
     */
    private function exec_external_script($script, $input) {
        $descriptorspec = array(
            0 => array("pipe", "r"), // stdin is a pipe that the child will read from
            1 => array("pipe", "w"), // stdout is a pipe that the child will write to
            2 => array("pipe", "w"), // stderr pipe to check for errors
        );

        $process = proc_open($script, $descriptorspec, $pipes, "/tmp");
        if (is_resource($process)) {
            fwrite($pipes[0], $input);
            fclose($pipes[0]);

            $result = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
            fclose($pipes[1]);
            fclose($pipes[2]);

            $ret_val = proc_close($process);
            return $result;
        }
        return null;
    }

    /**
     * given an array which represents something like a sql result set with an array
     * for each row, return the result formatted as tab separated text values and
     * a newline at the end of each row.
     *
     * @param type $result
     * @return string  The result set as a tab-text string
     */
    function result_as_table($result) {
        $table = '';
        foreach ($result as $row) {
            $table .= join("\t", array_values($row)) . "\n";
        }
        return $table;
    }

    /**
     * grep through a sample and return results
     *
     * @param string $hostname
     * @param string $sample
     * @param string $pattern
     * @param string $file
     * @param int $context
     * @return array    the results of the grep command
     */
    public function search_sample($hostname, $sample, $pattern, $file, $context) {
        $file = $this->tmp_dir() . '/' . $sample . '/' . $file;
        if (intval($context)) {
            $context = " -C{$context} ";
        } else {
            $context = '';
        }
        $cmd = "grep -h -ri {$context} \"" . addslashes($pattern) . "\" {$file}";
        //print $cmd . "\n";
        $output = array();
        exec($cmd, $output);
        return $output;
    }

    /**
     * return a list of servers in the collection dir
     * @return type
     */
    public function get_server_list() {
        $servers = array();
        $collection_dir = $this->collection_dir();
        $DIR = opendir($collection_dir);
        while ($server = readdir($DIR)) {
            if (in_array($server, array('.', '..'))) {
                continue;
            }

            if (is_dir($collection_dir . '/' . $server)) {
                $servers[] = $server;
            }
        }
        return $servers;
    }

    /**
     * given a file name, remove the date prefix to get the file type
     * @param type $name
     * @return type
     */
    public function get_type($name) {
        //print "$name
\n";
        return substr($name, 20);
    }

    public function pmp_summary($sample, $file)
    {
        $file = $this->tmp_dir() . '/' . $sample . '/' . $file;

        $cmd = "cat {$file} | awk '
  BEGIN { s = \"\"; }
  /^Thread/ { print s; s = \"\"; }
  /^\#/ { if (s != \"\" ) { s = s \",\" $4} else { s = $4 } }
  END { print s }' | sort | uniq -c | sort -r -n -k 1,1";

        $output = array();
        exec($cmd,$output);
        //print "
";
        //print_r($output);
        //print "
";
        return join("\n", $output);
    }

}

?>


text:
namespace ListPlayers.PcdbModel
{
    public sealed class PcdbEntry : IPcdbField
    {
        public readonly PcdbItemContainer<string> Hash = new PcdbItemContainer<string>(PcdbFieldId.Hash);
        public readonly PcdbItemContainer<string> Info = new PcdbItemContainer<string>(PcdbFieldId.Comment);
        public readonly PcdbListContainer<PcdbName> Names = new PcdbListContainer<PcdbName>(PcdbFieldId.Name);
        public readonly PcdbListContainer<PcdbIp> Ips = new PcdbListContainer<PcdbIp>(PcdbFieldId.Ip);
        public readonly PcdbListContainer<PcdbGsid> Gsids = new PcdbListContainer<PcdbGsid>(PcdbFieldId.Gsid);

        public PcdbEntry(string hash) { Hash.Item = hash; }

        public PcdbFieldId Id
        {
            get { return PcdbFieldId.Group | PcdbFieldId.Hash; }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="horizontal"
    android:layout_width="match_parent"
      android:layout_height="match_parent"

   >

  <VideoView
         android:orientation="vertical"
      android:id="@+id/video"
              android:layout_gravity="center"

         android:layout_width="fill_parent"
   android:layout_height="wrap_content"
      />

  	   <Button
    android:id="@+id/button1"
    style="@style/ButtonText"
    android:layout_width="120dp"
    android:layout_height="50dp"
    android:layout_gravity="center|top"
    android:background="@drawable/btn_red"
    android:text="Play Now"
    android:textSize="20dp" />

</FrameLayout>


text:
package gui;

public class AngularDynamo
{
  // ##### CONSTANTS #####
  public static final double UP    = (0d/2d) * Math.PI;
  public static final double LEFT  = (1d/2d) * Math.PI;
  public static final double DOWN  = (2d/2d) * Math.PI;
  public static final double RIGHT = (3d/2d) * Math.PI;

  // ##### FIELDS #####
  protected double θ;   // Current angular position [rad]. θ = 0 is upwards.
  protected double v;   // Current angular velocity [rad/s]. v > 0 is counter-clockwise.

  // ##### CONSTRUCTOR / ACCESSORS #####
  public AngularDynamo()
  {
    this.θ = 0;
    this.v = 0;
  }

  public double getθ() { return θ; }
  public double getv() { return v; }

  // ##### METHODS #####
  public void init(double θ, double v)
  {
    this.θ = normalize(θ);
    this.v = normalize(v);
  }

  public void move(double F, double dt)
  {
    v = v + F*dt;
    θ = normalize(θ + v*dt);
  }

  private double normalize(double arg)
  {
    arg = arg % (2*Math.PI);
    if (arg < 0)
      arg = 2*Math.PI + arg;
    return arg;
  }
}


text:
<?php

namespace webignition\Tests\Model\Stripe;

use Doctrine\Common\Collections\ArrayCollection;
use webignition\Model\Stripe\Invoice\LineItem\Subscription as SubscriptionLineItem;
use webignition\Model\Stripe\ObjectList;

class ObjectListTest extends AbstractBaseTest
{
    public function testGetEmptyObjectListProperties()
    {
        /* @var ObjectList $objectList */
        $objectList = new ObjectList($this->loadFixture('/ObjectList/objectlist.empty.json'));

        $this->assertInstanceOf(ObjectList::class, $objectList);

        $this->assertEquals(null, $objectList->getUrl());
        $this->assertEquals(new ArrayCollection(), $objectList->getItems());
        $this->assertEquals(
            [
                'object' => 'list',
            ],
            $objectList->__toArray()
        );
    }

    public function testGetInvoiceLinesObjectListProperties()
    {
        /* @var ObjectList $objectList */
        $objectList = new ObjectList($this->loadFixture('/ObjectList/objectlist.invoicelines.json'));

        $this->assertInstanceOf(ObjectList::class, $objectList);

        $this->assertEquals('/v1/invoices/in_3ceX5TY5UBN4Lr/lines', $objectList->getUrl());

        $items = $objectList->getItems();
        $this->assertInstanceOf(ArrayCollection::class, $items);
        $this->assertFalse($items->isEmpty());
        $this->assertEquals(1, $items->count());

        /* @var SubscriptionLineItem $subscriptionLineItem */
        $subscriptionLineItem = $items->first();
        $this->assertInstanceOf(SubscriptionLineItem::class, $subscriptionLineItem);

        $objectListAsArray = $objectList->__toArray();

        $this->assertArraySubset(
            [
                'object' => 'list',
                'count' => 1,
                'url' => '/v1/invoices/in_3ceX5TY5UBN4Lr/lines',
            ],
            $objectListAsArray
        );

        $objectListAsArrayData = $objectListAsArray['data'];
        $this->assertInternalType('array', $objectListAsArrayData);
        $this->assertCount(1, $objectListAsArrayData);

        $this->assertEquals($objectListAsArrayData[0], $subscriptionLineItem->__toArray());
    }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/demo_collection_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="collection fragments"
        android:layout_gravity="center"/>

</FrameLayout>


text:
package test;

import com.jeesuite.common.http.HttpRequestEntity;
import com.jeesuite.common.http.HttpResponseEntity;
import com.jeesuite.common.util.HttpUtils;
import com.jeesuite.common.util.ResourceUtils;

public class HttpUtilsTest {

	public static void main(String[] args) {

		ResourceUtils.add("jeesuite.httputil.provider","httpClient");

		HttpResponseEntity entity;
		entity = HttpUtils.get("http://www.kuaidi100.com/query?type=yuantong&postid=11111111111");
		System.out.println(entity);

		String json = "{\"example\":{\"env\":\"dev\"},\"pageNo\":1,\"pageSize\":10}";
		entity = HttpUtils.postJson("http://openapi.mytest.com/api/commonlog/custom_log/list?_logType=mq_produce_logs", json);
		System.out.println(entity);

		HttpRequestEntity requestEntity = HttpRequestEntity.get("http://").basicAuth("admin", "123456");
		entity = HttpUtils.execute(requestEntity);
		System.out.println(entity);
	}

}


text:
var args = arguments[0] || {};

$.nePropTmpl1Wrap.estate=args.estateno;
$.nePropTmpl1Image.estate=args.estateno;
$.nePropTmpl1Bld.estate=args.estateno;
$.space.estate=args.estateno;
if (args.attachment){
$.nePropTmpl1Image.image=Ti.Utils.base64decode(args.attachment);
}

$.nePropTmpl1Bld.text = args.chinesename || '';


text:
package com.softwarelma.epe.p1.app;

import java.io.File;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public abstract class EpeAppUtils {

    public static void checkNull(String name, String value) throws EpeAppException {
        if (name == null) {
            throw new EpeAppException("Null name");
        }

        if (value == null) {
            throw new EpeAppException("Null " + name);
        }
    }

    public static void checkNull(String name, Object value) throws EpeAppException {
        checkNull("name", name);

        if (value == null) {
            throw new EpeAppException("Null " + name);
        }
    }

    public static void checkNullForceNull(String name, String value) throws EpeAppException {
        checkNull("name", name);

        if (value != null) {
            throw new EpeAppException("Not null " + name);
        }
    }

    public static void checkNullForceNull(String name, String value, String message) throws EpeAppException {
        checkNull("name", name);

        if (value != null) {
            throw new EpeAppException(message);
        }
    }

    public static void checkNullForceNull(String name, Object value) throws EpeAppException {
        checkNull("name", name);

        if (value != null) {
            throw new EpeAppException("Not null " + name);
        }
    }

    public static void checkNullForceNull(String name, Object value, String message) throws EpeAppException {
        checkNull("name", name);

        if (value != null) {
            throw new EpeAppException(message);
        }
    }

    public static void checkBooleanForceTrue(String name, boolean b) throws EpeAppException {
        checkNull("name", name);

        if (!b) {
            throw new EpeAppException("Found false in " + name);
        }
    }

    public static void checkBooleanForceTrue(String name, boolean b, String message) throws EpeAppException {
        checkNull("name", name);

        if (!b) {
            throw new EpeAppException(message);
        }
    }

    public static void checkBooleanForceFalse(String name, boolean b) throws EpeAppException {
        checkNull("name", name);

        if (b) {
            throw new EpeAppException("Found true in " + name);
        }
    }

    public static void checkBooleanForceFalse(String name, boolean b, String message) throws EpeAppException {
        checkNull("name", name);

        if (b) {
            throw new EpeAppException(message);
        }
    }

    public static void checkMinorOrEqual(int value1, int value2) throws EpeAppException {
        if (value1 > value2) {
            throw new EpeAppException("Value " + value1 + " should be <= " + value2);
        }
    }

    public static void checkEquals(String name1, String name2, Object value1, Object value2) throws EpeAppException {
        checkEquals(name1, name2, value1, value2, null);
    }

    public static void checkEquals(String name1, String name2, Object value1, Object value2, String message)
            throws EpeAppException {
        checkNull("name1", name1);
        checkNull("name2", name2);

        if (value1 == null && value2 == null) {
            return;
        }

        if (value1 == null || value2 == null || !value1.equals(value2)) {
            throw new EpeAppException(
                    message == null ? "Vars " + name1 + " and " + name2 + " are not equals" : message);
        }
    }

    public static void checkEquals(String name1, String name2, List<String> list, Set<String> set)
            throws EpeAppException {
        checkNull("name1", name1);
        checkNull("name2", name2);

        if (list == null && set == null) {
            return;
        }

        if (list.isEmpty() && set.isEmpty()) {
            return;
        }

        if (list.size() != set.size()) {
            throw new EpeAppException("Vars " + name1 + " and " + name2 + " are not equals, list size " + list.size()
                    + " != set size " + set.size());
        }

        List<String> listTmp = new ArrayList<>(list);

        for (String str : set) {
            if (!listTmp.remove(str)) {
                throw new EpeAppException("Vars " + name1 + " and " + name2
                        + " are not equals, the list does not contain \"" + str + "\"");
            }
        }
    }

    public static void checkContains(Set<String> set, String name, String value) throws EpeAppException {
        checkNull("name", name);
        checkNull("set", set);

        if (!set.contains(value)) {
            throw new EpeAppException(name + " \"" + value + "\" is not contained in " + set);
        }
    }

    public static void checkContains(List<String> list, String name, String value) throws EpeAppException {
        checkNull("name", name);
        checkNull("list", list);

        if (!list.contains(value)) {
            throw new EpeAppException(name + " \"" + value + "\" is not contained in " + list);
        }
    }

    public static void checkContains(String[] array, String name, String value) throws EpeAppException {
        checkNull("name", name);
        checkNull("array", array);
        List<String> list = Arrays.asList(array);
        checkContains(list, name, value);
    }

    public static void checkRange(int i, int i0, int i1, boolean open0, boolean open1) throws EpeAppException {
        checkRange(i, i0, i1, open0, open1, "");
    }

    public static void checkRange(int i, int i0, int i1, boolean open0, boolean open1, String postMessage)
            throws EpeAppException {
        checkRange(i, i0, i1, open0, open1, "", postMessage);
    }

    public static void checkRange(int i, int i0, int i1, boolean open0, boolean open1, String paramName,
            String postMessage) throws EpeAppException {
        paramName = paramName == null ? "" : paramName + " ";
        postMessage = postMessage == null ? "" : postMessage;

        if (open0) {
            if (i < i0) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + " (" + i + ") is < " + i0 + ". " + postMessage);
            } else if (i == i0) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + "(" + i + ") is == " + i0 + ". " + postMessage);
            }
        } else {
            if (i < i0) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + "(" + i + ") is < " + i0 + ". " + postMessage);
            }
        }

        if (open1) {
            if (i > i1) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + "(" + i + ") is > " + i1 + ". " + postMessage);
            } else if (i == i1) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + "(" + i + ") is == " + i1 + ". " + postMessage);
            }
        } else {
            if (i > i1) {
                throw new EpeAppException(
                        "Out of range, the param " + paramName + "(" + i + ") is > " + i1 + ". " + postMessage);
            }
        }
    }

    public static <T> void checkSize(String name, List<T> list, int size) throws EpeAppException {
        checkNull(name, list);

        if (list.size() != size) {
            throw new EpeAppException("Wrong list size: " + list.size() + " != " + size);
        }
    }

    public static void checkEmpty(String paramName, Object paramValue) throws EpeAppException {
        checkEmpty(paramName, paramValue, "The param ", " cannot be empty");
    }

    public static void checkEmptyIT(String paramName, Object paramValue) throws EpeAppException {
        checkEmpty(paramName, paramValue, "Il parametro ", " non puo' essere vuoto");
    }

    public static void checkEmpty(String paramName, Object paramValue, String theParam, String cannotBeEmpty)
            throws EpeAppException {
        checkNull("paramName", paramName);
        theParam = theParam == null ? "The param " : theParam;
        cannotBeEmpty = cannotBeEmpty == null ? " cannot be empty" : cannotBeEmpty;

        if (paramValue == null || paramValue.toString().trim().isEmpty()) {
            throw new EpeAppException(theParam + paramName + cannotBeEmpty);
        }
    }

    public static void checkEmptyNoTrim(String paramName, Object paramValue) throws EpeAppException {
        checkEmptyNoTrim(paramName, paramValue, "The param ", " cannot be empty");
    }

    public static void checkEmptyNoTrimIT(String paramName, Object paramValue) throws EpeAppException {
        checkEmptyNoTrim(paramName, paramValue, "Il parametro ", " non puo' essere vuoto");
    }

    public static void checkEmptyNoTrim(String paramName, Object paramValue, String theParam, String cannotBeEmpty)
            throws EpeAppException {
        checkNull("paramName", paramName);
        theParam = theParam == null ? "The param " : theParam;
        cannotBeEmpty = cannotBeEmpty == null ? " cannot be empty" : cannotBeEmpty;

        if (paramValue == null || paramValue.toString().isEmpty()) {
            throw new EpeAppException(theParam + paramName + cannotBeEmpty);
        }
    }

    public static void checkEmptyForceEmpty(String paramName, Object paramValue) throws EpeAppException {
        checkEmptyForceEmpty(paramName, paramValue, "The param ", " must be empty, found: ");
    }

    public static void checkEmptyForceEmptyIT(String paramName, Object paramValue) throws EpeAppException {
        checkEmptyForceEmpty(paramName, paramValue, "Il parametro ", " dev'essere vuoto, trovato: ");
    }

    public static void checkEmptyForceEmpty(String paramName, Object paramValue, String theParam, String mustBeEmpty)
            throws EpeAppException {
        checkNull("paramName", paramName);
        theParam = theParam == null ? "The param " : theParam;
        mustBeEmpty = mustBeEmpty == null ? " must be empty, found: " : mustBeEmpty;

        if (paramValue != null && !paramValue.toString().trim().isEmpty()) {
            throw new EpeAppException(theParam + paramName + mustBeEmpty + paramValue);
        }
    }

    public static <T> void checkEmptyArray(String paramName, T[] paramValue) throws EpeAppException {
        checkEmptyArray(paramName, paramValue, "The param ", " cannot be empty");
    }

    public static <T> void checkEmptyArrayIT(String paramName, T[] paramValue) throws EpeAppException {
        checkEmptyArray(paramName, paramValue, "Il parametro ", " non puo' essere vuoto");
    }

    public static <T> void checkEmptyArray(String paramName, T[] paramValue, String theParam, String cannotBeEmpty)
            throws EpeAppException {
        checkEmpty("paramName", paramName);
        theParam = theParam == null ? "The param " : theParam;
        cannotBeEmpty = cannotBeEmpty == null ? " cannot be empty" : cannotBeEmpty;

        if (paramValue == null || paramValue.length == 0) {
            throw new EpeAppException(theParam + paramName + cannotBeEmpty);
        }
    }

    public static <T> void checkNullListContent(String paramName, List<T> paramValue) throws EpeAppException {
        checkNull(paramName, paramValue);

        for (int i = 0; i < paramValue.size(); i++) {
            T t = paramValue.get(i);
            checkNull(paramName + "[" + i + "]", t);
        }
    }

    public static <T> void checkEmptyListContent(String paramName, List<T> paramValue) throws EpeAppException {
        checkEmptyList(paramName, paramValue, "The param ", " cannot be empty");

        for (int i = 0; i < paramValue.size(); i++) {
            T t = paramValue.get(i);
            checkEmpty(paramName + "[" + i + "]", t);
        }
    }

    public static <T> void checkEmptyList(String paramName, List<T> paramValue) throws EpeAppException {
        checkEmptyList(paramName, paramValue, "The param ", " cannot be empty");
    }

    public static <T> void checkEmptyListIT(String paramName, List<T> paramValue) throws EpeAppException {
        checkEmptyList(paramName, paramValue, "Il parametro ", " non puo' essere vuoto");
    }

    public static <T> void checkEmptyList(String paramName, List<T> paramValue, String theParam, String cannotBeEmpty)
            throws EpeAppException {
        checkNull("paramName", paramName);
        theParam = theParam == null ? "The param " : theParam;
        cannotBeEmpty = cannotBeEmpty == null ? " cannot be empty" : cannotBeEmpty;

        if (paramValue == null || paramValue.isEmpty()) {
            throw new EpeAppException(theParam + paramName + cannotBeEmpty);
        }
    }

    public static <K, V> void checkEmptyMap(String paramName, Map<K, V> paramValue) throws EpeAppException {
        checkNull("paramName", paramName);
        checkNull(paramName, paramValue);

        if (paramValue.isEmpty()) {
            throw new EpeAppException("Empty " + paramName);
        }
    }

    public static void checkDir(File dir) throws EpeAppException {
        checkNull("dir", dir);

        if (!dir.isDirectory()) {
            throw new EpeAppException("The file \"" + dir.getName() + "\" is not a dir");
        }
    }

    public static void checkInstanceOf(String name, Object value, Class<?> clazz) throws EpeAppException {
        EpeAppUtils.checkNull("name", name);
        // value can be null
        EpeAppUtils.checkNull("clazz", clazz);

        if (value != null && !clazz.isInstance(value)) {
            throw new EpeAppException("Invalid class for " + name + ", required " + clazz.getName() + ", found "
                    + value.getClass().getName());
        }
    }

    public static <T> boolean isEmptyArray(T[] param) throws EpeAppException {
        return param == null || param.length == 0;
    }

    public static <T> boolean isEmptyList(List<T> param) throws EpeAppException {
        return param == null || param.isEmpty();
    }

    /**
     * it must be negative
     */
    public static void checkNegative(int param) throws EpeAppException {
        if (param >= 0)
            throw new EpeAppException("Expected < 0, found: " + param);
    }

    /**
     * it must be negative
     */
    public static void checkNotNegative(int param) throws EpeAppException {
        if (param < 0)
            throw new EpeAppException("Expected >= 0, found: " + param);
    }

    /**
     * it must be positive
     */
    public static void checkPositive(int param) throws EpeAppException {
        if (param <= 0)
            throw new EpeAppException("Expected > 0, found: " + param);
    }

    /**
     * it must be not positive
     */
    public static void checkNotPositive(int param) throws EpeAppException {
        if (param > 0)
            throw new EpeAppException("Expected <= 0, found: " + param);
    }

    public static boolean isEmpty(String param) {
        return param == null || param.isEmpty();
    }

    public static boolean isEmptyTrimming(String param) {
        return param == null || param.isEmpty() || param.trim().isEmpty()
                || param.trim().replace("\t", "").replace("\r\n", "").replace("\n", "").isEmpty();
    }

    public static String retrieveVisualTrim(String param) {
        if (param == null || param.isEmpty())
            return param;
        int i0 = 0;
        int i1 = param.length();
        char c;

        for (int i = 0; i < param.length() + 1; i++) {
            i0 = i;
            if (i0 == param.length())
                break;
            c = param.charAt(i);
            if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
                break;
        }

        for (int i = param.length(); i > 0 && i >= i0; i--) {
            i1 = i;
            c = param.charAt(i - 1);
            if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
                break;
        }

        return param.substring(i0, i1);
    }

    public static String getNotContainedString(String text, String open, String close) throws EpeAppException {
        EpeAppUtils.checkNull("text", text);
        EpeAppUtils.checkNull("open", open);
        EpeAppUtils.checkNull("close", close);
        int i = 0;

        while (text.contains(open + i + close)) {
            i++;
        }

        return open + i + close;
    }

    public static String getNotContainedString(String text) throws EpeAppException {
        return getNotContainedString(text, EpeAppConstants.CONTAINED_STRING_OPEN,
                EpeAppConstants.CONTAINED_STRING_CLOSE);
    }

    public static String getNotContainedString(String notContained, int iter, String close) throws EpeAppException {
        EpeAppUtils.checkNull("notContained", notContained);
        notContained = notContained.substring(0, notContained.length() - 1) + "-" + iter + close;
        return notContained;
    }

    public static String getNotContainedString(String notContained, int iter) throws EpeAppException {
        return getNotContainedString(notContained, iter, EpeAppConstants.CONTAINED_STRING_CLOSE);
    }

    public static String cleanFilename(String filename) throws EpeAppException {
        checkNull("filename", filename);
        return filename.replace("\\", "/");
    }

    public static String cleanDirName(String dirName) throws EpeAppException {
        checkNull("dirName", dirName);
        dirName = cleanFilename(dirName);
        dirName = dirName.endsWith("/") || dirName.isEmpty() ? dirName : dirName + "/";
        return dirName;
    }

    public static Map.Entry<String, String> retrieveKeyAndValue(String fullprop) throws EpeAppException {
        checkEmpty("fullprop", fullprop);
        if (!fullprop.contains("="))
            throw new EpeAppException("fullprop not valid \"" + fullprop + "\", should be like key=value");
        String key = fullprop.substring(0, fullprop.indexOf("="));
        String value = fullprop.substring(fullprop.indexOf("=") + 1);
        Map.Entry<String, String> keyValue = new AbstractMap.SimpleEntry<>(key, value);
        return keyValue;
    }

    public static Map.Entry<String, String> retrieveKeyAndValueVisualTrim(String fullprop) throws EpeAppException {
        Map.Entry<String, String> keyValue = retrieveKeyAndValue(fullprop);
        Map.Entry<String, String> keyValueVisualTrim = new AbstractMap.SimpleEntry<>(
                retrieveVisualTrim(keyValue.getKey()), retrieveVisualTrim(keyValue.getValue()));
        return keyValueVisualTrim;
    }

    public static Map.Entry<String, String> retrieveFilePathAndName(String fullFileName) throws EpeAppException {
        return retrievePathAndLast(fullFileName, "/");
    }

    public static Map.Entry<String, String> retrievePathAndLast(String fullPath, String separator)
            throws EpeAppException {
        checkEmpty("fullPath", fullPath);
        fullPath = cleanFilename(fullPath);
        fullPath = fullPath.endsWith(separator) ? fullPath.substring(0, fullPath.length() - 1) : fullPath;
        String[] array = fullPath.split(separator);

        String name = array[array.length - 1];
        String path = fullPath.substring(0, fullPath.length() - name.length());

        Map.Entry<String, String> filePathAndLast = new AbstractMap.SimpleEntry<>(path, name);
        return filePathAndLast;
    }

    public static String replaceNotContainedWithReplaced(String sentStr, Map<String, String> mapNotContainedReplaced) {
        for (String notContained : mapNotContainedReplaced.keySet()) {
            sentStr = sentStr.replace(notContained, mapNotContainedReplaced.get(notContained));
        }

        return sentStr;
    }

    public static String retrieveTimestamp(String format) throws EpeAppException {
        checkEmpty("format", format);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format.trim());
        return simpleDateFormat.format(new Date());
        // DateTimeFormatter formatter =
        // DateTimeFormatter.ofPattern(format.trim());
        // return LocalDateTime.now().format(formatter);
    }

    public static String retrieveTimestamp(String format, Date date) throws EpeAppException {
        checkEmpty("format", format);
        checkNull("date", date);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format.trim());
        return simpleDateFormat.format(date);
    }

    public static long parseLong(String s) throws EpeAppException {
        try {
            return Long.parseLong(s);
        } catch (NumberFormatException e) {
            throw new EpeAppException("Invalid long " + s, e);
        }
    }

    public static int parseInt(String str) throws EpeAppException {
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            throw new EpeAppException("Invalid int " + str, e);
        }
    }

    public static boolean parseBoolean(String str) throws EpeAppException {
        checkContains(new String[] { "true", "false" }, "str", str);
        return Boolean.parseBoolean(str);
    }

    public static Date parseTimestampToDate(String format, String timestampStr) throws EpeAppException {
        checkEmpty("format", format);
        checkEmpty("timestampStr", timestampStr);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format.trim());

        try {
            return simpleDateFormat.parse(timestampStr);
        } catch (ParseException e) {
            throw new EpeAppException("Invalid timestamp string " + timestampStr, e);
        }
    }

    public static Timestamp parseTimestampToTimestamp(String format, String timestampStr) throws EpeAppException {
        checkEmpty("format", format);
        checkEmpty("timestampStr", timestampStr);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format.trim());

        try {
            Date date = simpleDateFormat.parse(timestampStr);
            return new Timestamp(date.getTime());
        } catch (ParseException e) {
            throw new EpeAppException("Invalid timestamp string " + timestampStr, e);
        }
    }

    public static <T> List<T> asList(T[] array) {
        List<T> list = new ArrayList<T>();

        for (T t : array) {
            list.add(t);
        }

        return list;
    }

    public static void checkForceLower(String name, String value) throws EpeAppException {
        EpeAppUtils.checkNull("name", name);
        EpeAppUtils.checkNull("value", value);

        if (!value.toLowerCase().equals(value)) {
            throw new EpeAppException("The param " + name + " is not in lower case, found: " + value);
        }
    }

    public static void checkForceUpper(String name, String value) throws EpeAppException {
        EpeAppUtils.checkNull("name", name);
        EpeAppUtils.checkNull("value", value);

        if (!value.toUpperCase().equals(value)) {
            throw new EpeAppException("The param " + name + " is not in upper case, found: " + value);
        }
    }

}


text:
"""
Created on Sat May 13 20:55:28 2017

@author: moamin
"""

import os, sys, time, gzip, math
import numpy as np,csv, json, re
from gensim.models import Word2Vec
import matplotlib, string
matplotlib.use('Agg')
import matplotlib.pyplot as plt
#from sets import Set

first_word2vec_model = Word2Vec.load('updated_liberals_wordvec/model_visualize/model_liberal')#(sys.argv[0])
second_word2vec_model = Word2Vec.load('updated_conservatives_wordvec/model_visualize/model_conservative')#(sys.argv[1])

keywords = [key for key in first_word2vec_model.wv.vocab.keys()]
total_percentage_similar_list = []
print("Total Keywords: ", len(keywords))

n_words = 100
max_words = int(sys.argv[1])
top_n_words = [0 for i in range(0, n_words+1)]
model_intersection_words = []

file_first = open("disagreement_in_words_liberals.csv", "w")
file_second = open("disagreement_in_words_conservatives.csv", "w")

neighbor_first = open("neighbor_words_for_liberals.csv", "w")
neighbor_second = open("neighbor_words_for_conservatives.csv", "w")

exclude = set(string.punctuation)

for word in keywords:
    print("Word: ", word)
    print_word = ''.join(ch for ch in word if ch not in exclude)
    if len(print_word) < 1:
        continue
    #first_neighbors_set = set(first_word2vec_model.wv.most_similar(word, topn=10))
    #print(first_neighbors_set)
    #continue

    similar_word_found = False
    for i in range(1, len(top_n_words)):
        first_neighbors_list = first_word2vec_model.wv.most_similar(word, topn=i)
        first_neighbors_set = set([w[0] for w in first_neighbors_list])
        try:
            second_neighbors_list = second_word2vec_model.wv.most_similar(word, topn=i)
            second_neighbors_set = set([w[0] for w in second_neighbors_list])
        except:
            continue

        #print(first_neighbors_set)
        #print(second_neighbors_set)

        intersection_set = first_neighbors_set & second_neighbors_set
        #print("Intersection: %d: %d " %(i, len(intersection_set)))
        if len(intersection_set) > 0:
            top_n_words[i] += 1
            similar_word_found = True

            first_neighbors_list = first_word2vec_model.wv.most_similar(word, topn=100)
            first_neighbors_set = set([w[0] for w in first_neighbors_list])

            second_neighbors_list = second_word2vec_model.wv.most_similar(word, topn=100)
            second_neighbors_set = set([w[0] for w in second_neighbors_list])

            intersection_set = first_neighbors_set & second_neighbors_set
            print_word += "," + str(len(intersection_set)) + "," + str(i)

            str_first = print_word + "," + ','.join(str(n) for n in first_word2vec_model[word]) + "\n"
            file_first.write(str_first)

            str_second = print_word + "," + ','.join(str(n) for n in second_word2vec_model[word]) + "\n"
            file_second.write(str_second)

            neighbor_first.write(print_word + "," + ','.join(w[0] for w in first_neighbors_list) + "\n")
            neighbor_second.write(print_word + "," + ','.join(w[0] for w in second_neighbors_list) + "\n")

            assert(len(str_first.split(",")) == 103)
            assert(len(str_second.split(",")) == 103)

            break

    if similar_word_found == True:
        model_intersection_words.append(word)
    if len(model_intersection_words) >= max_words:
        break

percentage = [0 for i in range(0, n_words+1)]
logscale = [0 for i in range(0, n_words+1)]
for i in range(1, len(top_n_words)):
    percentage[i] = 100.0 * top_n_words[i] / len(model_intersection_words)
    logscale[i] = math.log10(top_n_words[i]+1)

print("Total Words: ", len(model_intersection_words))
print("--------------------------------------------")
print(top_n_words)
'''
#plt.figure(1, figsize=(20, 16))
plt.plot(top_n_words)
plt.xlim(1, len(top_n_words))
plt.xlabel('Nearest Neighbors')
plt.ylabel('Rank of First Agreement')
plt.savefig("rank_agreement_top_n_words.png")
#plt.show()
plt.close()

#plt.figure(1, figsize=(20, 16))
plt.plot(percentage)
plt.xlim(1, len(top_n_words))
plt.xlabel('Nearest Neighbors')
plt.ylabel('Rank of First Agreement')
plt.savefig("rank_agreement_percentage")
#plt.show()
plt.close()

#plt.figure(1, figsize=(20, 16))
plt.plot(logscale)
plt.xlim(1, len(top_n_words))
plt.xlabel('Nearest Neighbors')
plt.ylabel('Rank of First Agreement')
plt.savefig("rank_agreement_logscale")
#plt.show()
plt.close()
'''


text:
r"""
=======================================================
Conical (Konus) Panels (:mod:`compmech.panels.kpanels`)
=======================================================

.. currentmodule:: compmech.panels.kpanels

Can be used to simulate cylindrical panels when `\alpha = 0`. The main
attributes are listed below:

.. figure:: ../../../figures/kpanel.png
   :align: center

=====================  ==================================================
Geometric Attributes   Description
=====================  ==================================================
``r1``                 Radius at the bottom edge
``r2``                 Radius at the top edge
``L``                  Length along the `x` axis
``tmindeg``            Circumferential start angle
``tmaxdeg``            Circumferential end angle
``alphadeg``           Cone semi-vertex angle in degrees
=====================  ==================================================

.. autoclass:: KPanelT
    :members:

.. autoclass:: KPanelCheb
    :members:

"""
from kpanelt import KPanelT
from kpanelcheb import KPanelCheb


text:
<?php
//
// Copyright (c) 2020-2022 Grigore Stefan <g_stefan@yahoo.com>
// Created by Grigore Stefan <g_stefan@yahoo.com>
//
// MIT License (MIT) <http://opensource.org/licenses/MIT>
//

defined("XYO_CLOUD") or die("Access is denied");

$className = "xyo_mod_app_Search";

class xyo_mod_app_Search extends xyo_Module {

	function __construct(&$object, &$cloud) {
		parent::__construct($object, $cloud);
		if ($this->isBase("xyo_mod_app_Search")) {
			$this->setHtmlCss($this->site."lib/xyo/xyo-mod-app-search.css");
			$this->setHtmlJs($this->site."lib/xyo/xyo-mod-app-search.js");
        	}
	}

	public function moduleMain() {
		$this->generateView();
	}

}


text:
using PenguinUpload.DataModels.Files;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PenguinUpload.Services.FileStorage
{
    public static class FileOrganization
    {
        private static string[] GetPathSegments(string path)
        {
            return path.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string JoinPathSegments(string[] segments)
        {
            return "/" + string.Join("/", segments) + "/";
        }

        public static DirectoryStructure BuildStructure(IEnumerable<StoredFile> files)
        {
            var dirStructure = new DirectoryStructure
            {
                Path = "/"
            };
            foreach (var file in files)
            {
                var pathSegments = GetPathSegments(file.ParentDirPath);
                var targetPathSegmentCount = pathSegments.Length;
                var parent = dirStructure;
                for (int i = 0; i < targetPathSegmentCount; i++)
                {
                    var currentSegment = pathSegments[i];
                    var currentFullPath = JoinPathSegments(pathSegments.Take(i + 1).ToArray());
                    DirectoryStructure nextChild;
                    var existingChild = parent.SubDirectories.Where(x => x.Path == currentFullPath).FirstOrDefault();
                    if (existingChild != null)
                    {
                        nextChild = existingChild;
                    }
                    else
                    {
                        // Create and add next directory
                        nextChild = new DirectoryStructure
                        {
                            Name = currentSegment,
                            Path = parent.Path + currentSegment + "/"
                        };
                        parent.SubDirectories.Add(nextChild);
                    }
                    parent = nextChild;
                }
                parent.Files.Add(file);
            }
            return dirStructure;
        }
    }
}


text:
int runes_socket_client_open(char *path);
int runes_socket_server_open(char *path);
int runes_socket_server_accept(int s);
void runes_socket_client_close(int s);
void runes_socket_server_close(int s, char *path);

#endif


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>org.owasp.appsensor.storage.riak (appsensor-parent 2.3.0 API)</title>
<meta name="date" content="2016-09-29">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">

org.owasp.appsensor.storage.riak

Interfaces

RiakConstants


text:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 *
 * @author Kiran
 */
public class TitanGyro extends Gyro{
    // variables for balance tracking
    public Gyro gyro;
    private final double SENSITIVITY=0.007;//Need to find acutal sensitivity and change
    private double angle;
    private double prevAngle;
    private boolean isBalanced;

    /**
     * Constructor that sets sensitivity and uses constructor from WPI gyro class
     */
    public TitanGyro()
    {
        super(HWR.GYRO);
        setSensitivity(SENSITIVITY);
        reset();
    }
    /**
     * Gets the current reading from the gyro
     * @return angle
     */
    public double angle()
    {
        return getAngle();
    }

   /**
     * Prints data out to SmartDashboard
     * and auxStick, button 8, resets gyro
     */
    public void run(){
        SmartDashboard.putNumber("Gyro data", gyro.getAngle());
        if(DriverStation.auxStick.getRawButton(HWR.GYRO_RESET)){
            reset();
        }

    }
}


text:
package restore

import (
	"archive/tar"
	"bytes"
	"encoding/binary"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"strconv"
	"strings"

	"compress/gzip"

	"github.com/influxdata/influxdb/cmd/influxd/backup_util"
	tarstream "github.com/influxdata/influxdb/pkg/tar"
	"github.com/influxdata/influxdb/services/meta"
	"github.com/influxdata/influxdb/services/snapshotter"
)

// Command represents the program execution for "influxd restore".
type Command struct {
	// The logger passed to the ticker during execution.
	StdoutLogger *log.Logger
	StderrLogger *log.Logger

	// Standard input/output, overridden for testing.
	Stderr io.Writer
	Stdout io.Writer

	host   string
	client *snapshotter.Client

	backupFilesPath     string
	metadir             string
	datadir             string
	destinationDatabase string
	sourceDatabase      string
	backupRetention     string
	restoreRetention    string
	shard               uint64
	portable            bool
	online              bool
	manifestMeta        *backup_util.MetaEntry
	manifestFiles       map[uint64]*backup_util.Entry

	// TODO: when the new meta stuff is done this should not be exported or be gone
	MetaConfig *meta.Config

	shardIDMap map[uint64]uint64
}

// NewCommand returns a new instance of Command with default settings.
func NewCommand() *Command {
	return &Command{
		Stdout:     os.Stdout,
		Stderr:     os.Stderr,
		MetaConfig: meta.NewConfig(),
	}
}

// Run executes the program.
func (cmd *Command) Run(args ...string) error {
	// Set up logger.
	cmd.StdoutLogger = log.New(cmd.Stdout, "", log.LstdFlags)
	cmd.StderrLogger = log.New(cmd.Stderr, "", log.LstdFlags)
	if err := cmd.parseFlags(args); err != nil {
		return err
	}

	if cmd.portable {
		return cmd.runOnlinePortable()
	} else if cmd.online {
		return cmd.runOnlineLegacy()
	} else {
		return cmd.runOffline()
	}
}

func (cmd *Command) runOffline() error {
	if cmd.metadir != "" {
		if err := cmd.unpackMeta(); err != nil {
			return err
		}
	}

	if cmd.shard != 0 {
		return cmd.unpackShard(cmd.shard)
	} else if cmd.restoreRetention != "" {
		return cmd.unpackRetention()
	} else if cmd.datadir != "" {
		return cmd.unpackDatabase()
	}
	return nil
}

func (cmd *Command) runOnlinePortable() error {
	err := cmd.updateMetaPortable()
	if err != nil {
		cmd.StderrLogger.Printf("error updating meta: %v", err)
		return err
	}
	err = cmd.uploadShardsPortable()
	if err != nil {
		cmd.StderrLogger.Printf("error updating shards: %v", err)
		return err
	}
	return nil
}

func (cmd *Command) runOnlineLegacy() error {
	err := cmd.updateMetaLegacy()
	if err != nil {
		cmd.StderrLogger.Printf("error updating meta: %v", err)
		return err
	}
	err = cmd.uploadShardsLegacy()
	if err != nil {
		cmd.StderrLogger.Printf("error updating shards: %v", err)
		return err
	}
	return nil
}

// parseFlags parses and validates the command line arguments.
func (cmd *Command) parseFlags(args []string) error {
	fs := flag.NewFlagSet("", flag.ContinueOnError)
	fs.StringVar(&cmd.host, "host", "localhost:8088", "")
	fs.StringVar(&cmd.metadir, "metadir", "", "")
	fs.StringVar(&cmd.datadir, "datadir", "", "")
	fs.StringVar(&cmd.destinationDatabase, "database", "", "")
	fs.StringVar(&cmd.restoreRetention, "retention", "", "")
	fs.StringVar(&cmd.sourceDatabase, "db", "", "")
	fs.StringVar(&cmd.destinationDatabase, "newdb", "", "")
	fs.StringVar(&cmd.backupRetention, "rp", "", "")
	fs.StringVar(&cmd.restoreRetention, "newrp", "", "")
	fs.Uint64Var(&cmd.shard, "shard", 0, "")
	fs.BoolVar(&cmd.online, "online", false, "")
	fs.BoolVar(&cmd.portable, "portable", false, "")
	fs.SetOutput(cmd.Stdout)
	fs.Usage = cmd.printUsage
	if err := fs.Parse(args); err != nil {
		return err
	}

	cmd.MetaConfig = meta.NewConfig()
	cmd.MetaConfig.Dir = cmd.metadir
	cmd.client = snapshotter.NewClient(cmd.host)

	// Require output path.
	cmd.backupFilesPath = fs.Arg(0)
	if cmd.backupFilesPath == "" {
		return fmt.Errorf("path with backup files required")
	}

	fi, err := os.Stat(cmd.backupFilesPath)
	if err != nil || !fi.IsDir() {
		return fmt.Errorf("backup path should be a valid directory: %s", cmd.backupFilesPath)
	}

	if cmd.portable || cmd.online {
		// validate the arguments

		if cmd.metadir != "" {
			return fmt.Errorf("offline parameter metadir found, not compatible with -portable")
		}

		if cmd.datadir != "" {
			return fmt.Errorf("offline parameter datadir found, not compatible with -portable")
		}

		if cmd.restoreRetention == "" {
			cmd.restoreRetention = cmd.backupRetention
		}

		if cmd.portable {
			var err error
			cmd.manifestMeta, cmd.manifestFiles, err = backup_util.LoadIncremental(cmd.backupFilesPath)
			if err != nil {
				return fmt.Errorf("restore failed while processing manifest files: %s", err.Error())
			} else if cmd.manifestMeta == nil {
				// No manifest files found.
				return fmt.Errorf("No manifest files found in: %s\n", cmd.backupFilesPath)

			}
		}
	} else {
		// validate the arguments
		if cmd.metadir == "" && cmd.destinationDatabase == "" {
			return fmt.Errorf("-metadir or -destinationDatabase are required to restore")
		}

		if cmd.destinationDatabase != "" && cmd.datadir == "" {
			return fmt.Errorf("-datadir is required to restore")
		}

		if cmd.shard != 0 {
			if cmd.destinationDatabase == "" {
				return fmt.Errorf("-destinationDatabase is required to restore shard")
			}
			if cmd.backupRetention == "" {
				return fmt.Errorf("-retention is required to restore shard")
			}
		} else if cmd.backupRetention != "" && cmd.destinationDatabase == "" {
			return fmt.Errorf("-destinationDatabase is required to restore retention policy")
		}
	}

	return nil
}

// unpackMeta reads the metadata from the backup directory and initializes a raft
// cluster and replaces the root metadata.
func (cmd *Command) unpackMeta() error {
	// find the meta file
	metaFiles, err := filepath.Glob(filepath.Join(cmd.backupFilesPath, backup_util.Metafile+".*"))
	if err != nil {
		return err
	}

	if len(metaFiles) == 0 {
		return fmt.Errorf("no metastore backups in %s", cmd.backupFilesPath)
	}

	latest := metaFiles[len(metaFiles)-1]

	fmt.Fprintf(cmd.Stdout, "Using metastore snapshot: %v\n", latest)
	// Read the metastore backup
	f, err := os.Open(latest)
	if err != nil {
		return err
	}

	var buf bytes.Buffer
	if _, err := io.Copy(&buf, f); err != nil {
		return fmt.Errorf("copy: %s", err)
	}

	b := buf.Bytes()
	var i int

	// Make sure the file is actually a meta store backup file
	magic := binary.BigEndian.Uint64(b[:8])
	if magic != snapshotter.BackupMagicHeader {
		return fmt.Errorf("invalid metadata file")
	}
	i += 8

	// Size of the meta store bytes
	length := int(binary.BigEndian.Uint64(b[i : i+8]))
	i += 8
	metaBytes := b[i : i+length]
	i += int(length)

	// Size of the node.json bytes
	length = int(binary.BigEndian.Uint64(b[i : i+8]))
	i += 8
	nodeBytes := b[i : i+length]

	// Unpack into metadata.
	var data meta.Data
	if err := data.UnmarshalBinary(metaBytes); err != nil {
		return fmt.Errorf("unmarshal: %s", err)
	}

	// Copy meta config and remove peers so it starts in single mode.
	c := cmd.MetaConfig
	c.Dir = cmd.metadir

	// Create the meta dir
	if err := os.MkdirAll(c.Dir, 0700); err != nil {
		return err
	}

	// Write node.json back to meta dir
	if err := ioutil.WriteFile(filepath.Join(c.Dir, "node.json"), nodeBytes, 0655); err != nil {
		return err
	}

	client := meta.NewClient(c)
	if err := client.Open(); err != nil {
		return err
	}
	defer client.Close()

	// Force set the full metadata.
	if err := client.SetData(&data); err != nil {
		return fmt.Errorf("set data: %s", err)
	}

	// remove the raft.db file if it exists
	err = os.Remove(filepath.Join(cmd.metadir, "raft.db"))
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}

	// remove the node.json file if it exists
	err = os.Remove(filepath.Join(cmd.metadir, "node.json"))
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}

	return nil
}

func (cmd *Command) updateMetaPortable() error {
	var metaBytes []byte
	fileName := filepath.Join(cmd.backupFilesPath, cmd.manifestMeta.FileName)

	fileBytes, err := ioutil.ReadFile(fileName)
	if err != nil {
		return err
	}

	var ep backup_util.PortablePacker
	ep.UnmarshalBinary(fileBytes)

	metaBytes = ep.Data

	req := &snapshotter.Request{
		Type:                   snapshotter.RequestMetaStoreUpdate,
		BackupDatabase:         cmd.sourceDatabase,
		RestoreDatabase:        cmd.destinationDatabase,
		BackupRetentionPolicy:  cmd.backupRetention,
		RestoreRetentionPolicy: cmd.restoreRetention,
		UploadSize:             int64(len(metaBytes)),
	}

	shardIDMap, err := cmd.client.UpdateMeta(req, bytes.NewReader(metaBytes))
	cmd.shardIDMap = shardIDMap
	return err

}

// updateMetaLive takes a metadata backup and sends it to the influx server
// for a live merger of metadata.
func (cmd *Command) updateMetaLegacy() error {

	var metaBytes []byte

	// find the meta file
	metaFiles, err := filepath.Glob(filepath.Join(cmd.backupFilesPath, backup_util.Metafile+".*"))
	if err != nil {
		return err
	}

	if len(metaFiles) == 0 {
		return fmt.Errorf("no metastore backups in %s", cmd.backupFilesPath)
	}

	fileName := metaFiles[len(metaFiles)-1]
	cmd.StdoutLogger.Printf("Using metastore snapshot: %v\n", fileName)
	metaBytes, err = backup_util.GetMetaBytes(fileName)
	if err != nil {
		return err
	}

	req := &snapshotter.Request{
		Type:                   snapshotter.RequestMetaStoreUpdate,
		BackupDatabase:         cmd.sourceDatabase,
		RestoreDatabase:        cmd.destinationDatabase,
		BackupRetentionPolicy:  cmd.backupRetention,
		RestoreRetentionPolicy: cmd.restoreRetention,
		UploadSize:             int64(len(metaBytes)),
	}

	shardIDMap, err := cmd.client.UpdateMeta(req, bytes.NewReader(metaBytes))
	cmd.shardIDMap = shardIDMap
	return err
}

// unpackShard will look for all backup files in the path matching this shard ID
// and restore them to the data dir
func (cmd *Command) unpackShard(shard uint64) error {
	shardID := strconv.FormatUint(shard, 10)
	// make sure the shard isn't already there so we don't clobber anything
	restorePath := filepath.Join(cmd.datadir, cmd.destinationDatabase, cmd.restoreRetention, shardID)
	if _, err := os.Stat(restorePath); err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("shard already present: %s", restorePath)
	}

	id, err := strconv.ParseUint(shardID, 10, 64)
	if err != nil {
		return err
	}

	// find the shard backup files
	pat := filepath.Join(cmd.backupFilesPath, fmt.Sprintf(backup_util.BackupFilePattern, cmd.destinationDatabase, cmd.restoreRetention, id))
	return cmd.unpackFiles(pat + ".*")
}

func (cmd *Command) uploadShardsPortable() error {
	for _, file := range cmd.manifestFiles {
		if cmd.sourceDatabase == "" || cmd.sourceDatabase == file.Database {
			if cmd.backupRetention == "" || cmd.backupRetention == file.Policy {
				if cmd.shard == 0 || cmd.shard == file.ShardID {
					oldID := file.ShardID
					// if newID not found then this shard's metadata was NOT imported
					// and should be skipped
					newID, ok := cmd.shardIDMap[oldID]
					if !ok {
						cmd.StdoutLogger.Printf("Meta info not found for shard %d on database %s. Skipping shard file %s", oldID, file.Database, file.FileName)
						continue
					}
					cmd.StdoutLogger.Printf("Restoring shard %d live from backup %s\n", file.ShardID, file.FileName)
					f, err := os.Open(filepath.Join(cmd.backupFilesPath, file.FileName))
					if err != nil {
						f.Close()
						return err
					}
					gr, err := gzip.NewReader(f)
					if err != nil {
						f.Close()
						return err
					}
					tr := tar.NewReader(gr)
					targetDB := cmd.destinationDatabase
					if targetDB == "" {
						targetDB = file.Database
					}

					if err := cmd.client.UploadShard(oldID, newID, targetDB, cmd.restoreRetention, tr); err != nil {
						f.Close()
						return err
					}
					f.Close()
				}
			}
		}
	}
	return nil
}

// unpackFiles will look for backup files matching the pattern and restore them to the data dir
func (cmd *Command) uploadShardsLegacy() error {
	// find the destinationDatabase backup files
	pat := fmt.Sprintf("%s.*", filepath.Join(cmd.backupFilesPath, cmd.sourceDatabase))
	cmd.StdoutLogger.Printf("Restoring live from backup %s\n", pat)
	backupFiles, err := filepath.Glob(pat)
	if err != nil {
		return err
	}
	if len(backupFiles) == 0 {
		return fmt.Errorf("no backup files in %s", cmd.backupFilesPath)
	}

	for _, fn := range backupFiles {
		parts := strings.Split(fn, ".")

		if len(parts) != 4 {
			cmd.StderrLogger.Printf("Skipping mis-named backup file: %s", fn)
		}
		shardID, err := strconv.ParseUint(parts[2], 10, 64)
		if err != nil {
			return err
		}

		// if newID not found then this shard's metadata was NOT imported
		// and should be skipped
		newID, ok := cmd.shardIDMap[shardID]
		if !ok {
			cmd.StdoutLogger.Printf("Meta info not found for shard %d. Skipping shard file %s", shardID, fn)
			continue
		}
		f, err := os.Open(fn)
		if err != nil {
			return err
		}
		tr := tar.NewReader(f)
		if err := cmd.client.UploadShard(shardID, newID, cmd.destinationDatabase, cmd.restoreRetention, tr); err != nil {
			f.Close()
			return err
		}
		f.Close()
	}

	return nil
}

// unpackDatabase will look for all backup files in the path matching this destinationDatabase
// and restore them to the data dir
func (cmd *Command) unpackDatabase() error {
	// make sure the shard isn't already there so we don't clobber anything
	restorePath := filepath.Join(cmd.datadir, cmd.destinationDatabase)
	if _, err := os.Stat(restorePath); err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("database already present: %s", restorePath)
	}

	// find the database backup files
	pat := filepath.Join(cmd.backupFilesPath, cmd.destinationDatabase)
	return cmd.unpackFiles(pat + ".*")
}

// unpackRetention will look for all backup files in the path matching this retention
// and restore them to the data dir
func (cmd *Command) unpackRetention() error {
	// make sure the shard isn't already there so we don't clobber anything
	restorePath := filepath.Join(cmd.datadir, cmd.destinationDatabase, cmd.restoreRetention)
	if _, err := os.Stat(restorePath); err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("retention already present: %s", restorePath)
	}

	// find the retention backup files
	pat := filepath.Join(cmd.backupFilesPath, cmd.destinationDatabase)
	return cmd.unpackFiles(fmt.Sprintf("%s.%s.*", pat, cmd.restoreRetention))
}

// unpackFiles will look for backup files matching the pattern and restore them to the data dir
func (cmd *Command) unpackFiles(pat string) error {
	cmd.StdoutLogger.Printf("Restoring offline from backup %s\n", pat)

	backupFiles, err := filepath.Glob(pat)
	if err != nil {
		return err
	}

	if len(backupFiles) == 0 {
		return fmt.Errorf("no backup files for %s in %s", pat, cmd.backupFilesPath)
	}

	for _, fn := range backupFiles {
		if err := cmd.unpackTar(fn); err != nil {
			return err
		}
	}

	return nil
}

// unpackTar will restore a single tar archive to the data dir
func (cmd *Command) unpackTar(tarFile string) error {
	f, err := os.Open(tarFile)
	if err != nil {
		return err
	}
	defer f.Close()

	// should get us ["db","rp", "00001", "00"]
	pathParts := strings.Split(filepath.Base(tarFile), ".")
	if len(pathParts) != 4 {
		return fmt.Errorf("backup tarfile name incorrect format")
	}

	shardPath := filepath.Join(cmd.datadir, pathParts[0], pathParts[1], strings.Trim(pathParts[2], "0"))
	os.MkdirAll(shardPath, 0755)

	return tarstream.Restore(f, shardPath)
}

// printUsage prints the usage message to STDERR.
func (cmd *Command) printUsage() {
	fmt.Fprintf(cmd.Stdout, `
Uses backups from the PATH to restore the metastore, databases, retention policies, or specific shards.
Default mode requires the instance to be stopped before running, and will wipe all databases from the system
(e.g., for disaster recovery).  The improved online and portable modes require the instance to be running,
and the database name used must not already exist.

Usage: influxd restore [-portable] [flags] PATH

The default mode consumes files in an OSS only file format. PATH is a directory containing the backup data

Options:
    -metadir <path>
            Optional. If set the metastore will be recovered to the given path.
    -datadir <path>
            Optional. If set the restore process will recover the specified
            database, retention policy or shard to the given directory.
    -database <name>
            Optional. Required if no metadir given. Will restore a single database's data.
    -retention <name>
            Optional. If given, -database is required. Will restore the retention policy's
            data.
    -shard <id>
            Optional. If given, -database and -retention are required. Will restore the shard's
            data.
    -online
            Optional. If given, the restore will be done using the new process, detailed below.  All other arguments
            above should be omitted.

The -portable restore mode consumes files in an improved format that includes a file manifest.

Options:
    -host  <host:port>
            The host to connect to and perform a snapshot of. Defaults to '127.0.0.1:8088'.
    -db    <name>
            Identifies the database from the backup that will be restored.
    -newdb <name>
            The name of the database into which the archived data will be imported on the target system.
            If not given, then the value of -db is used.  The new database name must be unique to the target system.
    -rp    <name>
            Identifies the retention policy from the backup that will be restored.  Requires that -db is set.
    -newrp <name>
            The name of the retention policy that will be created on the target system. Requires that -rp is set.
            If not given, the value of -rp is used.
    -shard <id>
            Optional.  If given, -db and -rp are required.  Will restore the single shard's data.
`)
}


text:
'''
Evaluation code for the SICK dataset (SemEval 2014 Task 1)
'''
import numpy as np
import os.path
from util import *
from sklearn.metrics import mean_squared_error as mse
from scipy.stats import pearsonr
from scipy.stats import spearmanr
from sklearn.utils import shuffle
from utils.score import report_score
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.optimizers import Adam
from sklearn.metrics import accuracy_score
from keras.utils.np_utils import to_categorical
import pandas as pd
from sklearn.model_selection import train_test_split
import random
from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Activation, Flatten, Merge, Embedding
from keras import regularizers
from keras.layers import Merge, Input, Multiply, Layer
from sklearn.preprocessing import StandardScaler

def split(train_l,train_r,label,ratio):
    total = train_l.shape[0]
    train_samples = int(total*(1-ratio))
    test_samples = total-train_samples
    tr_l,tst_l,tr_r,tst_r,l_tr,l_tst=[],[],[],[],[],[]
    dat=random.sample(range(total),train_samples)
    for a in dat:
        tr_l.append(train_l[a])
        tr_r.append(train_r[a])
        l_tr.append(label[a])
    print 'splitting - validation samples ',test_samples
    for i in range(total):
        if i not in dat:
            tst_l.append(train_l[i])
            tst_r.append(train_r[i])
            l_tst.append(label[i])
    print 'splitting - train samples ',len(dat)
    tr_l = np.array(tr_l)
    tr_r = np.array(tr_r)
    tst_l = np.array(tst_l)
    tst_r = np.array(tst_r)
    l_tr = np.array(l_tr)
    l_tst = np.array(l_tst)

    return tr_l,tst_l,tr_r,tst_r,l_tr,l_tst

def load_dataset(file_trhead, file_trbody, file_tshead, file_tsbody):
    trhead = pd.read_csv(file_trhead)
    trbody = pd.read_csv(file_trbody)
    tshead = pd.read_csv(file_tshead)
    tsbody = pd.read_csv(file_tsbody)
    tr_head_array = trhead.values
    tr_body_array = trbody.values
    ts_head_array = tshead.values
    ts_body_array = tsbody.values
    tr_labels = tr_head_array[:,2]
    ts_labels = ts_head_array[:,2]

    tr_body_id = tr_head_array[:,1]
    train_dh = tr_head_array[:,0]         ##########
    train_db = []
    for i in range(len(tr_head_array)):
        for j in range(len(tr_body_array)):
            if tr_body_array[j][0] == tr_body_id[i]:
                train_db.append(tr_body_array[j][1])
                break
    tr_lab = []
    for i in tr_labels:
        if i == 'unrelated':
            tr_lab.append(3)
        if i == 'agree':
            tr_lab.append(0)
        if i == 'discuss':
            tr_lab.append(2)
        if i == 'disagree':
            tr_lab.append(1)
    train_db = np.array(train_db)               ##############

    ts_body_id = ts_head_array[:,1]
    test_dh = ts_head_array[:,0]         ##########
    test_db = []
    for i in range(len(ts_head_array)):
        for j in range(len(ts_body_array)):
            if ts_body_array[j][0] == ts_body_id[i]:
                test_db.append(ts_body_array[j][1])
                break
    ts_lab = []
    for i in ts_labels:
        if i == 'unrelated':
            ts_lab.append(3)
        if i == 'agree':
            ts_lab.append(0)
        if i == 'discuss':
            ts_lab.append(2)
        if i == 'disagree':
            ts_lab.append(1)

    test_db= np.array(test_db)                  #############

    #signs=['?','.',]
    print("Refining train datset")
    train_rdh = []
    for i in range(len(train_dh)):
        sentence = ""
        for char in train_dh[i]:
            if char.isalpha() or char == ' ':
                sentence+=char.lower()
            else:
                sentence+=' '
        train_rdh.append(sentence)

    train_rdb = []
    for i in range(len(train_db)):
        sentence = ""
        for char in train_db[i]:
            if char.isalpha() or char == ' ':
                sentence+=char.lower()
            else:
                sentence+=' '
        train_rdb.append(sentence)

    print("Refining test datset")
    test_rdh = []
    for i in range(len(test_dh)):
        sentence = ""
        for char in test_dh[i]:
            if char.isalpha() or char == ' ':
                sentence+=char.lower()
            else:
                sentence+=' '
        test_rdh.append(sentence)

    test_rdb = []
    for i in range(len(test_db)):
        sentence = ""
        for char in test_db[i]:
            if char.isalpha() or char == ' ':
                sentence+=char.lower()
            else:
                sentence+=' '
        test_rdb.append(sentence)

    dic = pd.read_pickle('stop_dic')

    train_new_rdb = []
    test_new_rdb = []

    word_limit = 250
    print 'removing stop words and using', word_limit,'words limit .....'

    for i in train_rdb:
        temp=[]
        for j in i.split():
            try:
                a=dic[j]
            except:
                temp.append(j)
        train_new_rdb.append(' '.join(temp[0:min(len(temp),word_limit)]))

    for i in test_rdb:
        temp=[]
        for j in i.split():
            try:
                a=dic[j]
            except:
                temp.append(j)
        test_new_rdb.append(' '.join(temp[0:min(len(temp),word_limit)]))

    train_rdh = np.array(train_rdh)
    test_rdh = np.array(test_rdh)
    train_new_rdb = np.array(train_new_rdb)
    test_new_rdb = np.array(test_new_rdb)

    return train_rdh, train_new_rdb, test_rdh, test_new_rdb
    #tr_h, dev_h, tr_b, dev_b, tr_s, dev_s = split(np.array(train_rdh), np.array(train_rdb), tr_lab, 0.2)
    #return [tr_h, tr_b], [dev_h, dev_b], [tr_s, dev_s]

def evaluate(encoder=None, seed=1234, evaltest=False, loc='./data/'):
    """
    Run experiment
    """
    print 'Preparing data for fnc...'

    #train, dev, test, scores = load_data(loc)
    #train[0], train[1], scores[0] = shuffle(train[0], train[1], scores[0], random_state=seed)

    '''
    trh, trb, tsh, tsb =\
                load_dataset("/fnc_data/train_stances.csv", "/fnc_data/train_bodies.csv",\
                             "/fnc_data/competition_test_stances.csv", "/fnc_data/test_bodies.csv")
   '''
    train_h = np.load('/fncdata2/encode_train_head.npy')
    train_b = np.load('/fncdata2/encode_train_body.npy')
    test_h = np.load('/fncdata2/encode_test_head.npy')
    test_b = np.load('/fncdata2/encode_test_body.npy')
    score_train = np.load('/fncdata2/score_train.npy')
    score_test = np.load('/fncdata2/score_test.npy')
    #train_b = big_mat
    #train_h, dev_h, train_b, dev_b, score_train, dev_score = split(np.array(train_h), train_b, score_train, 0.2)

    print 'loading training skipthoughts...'
    #trainA = encoder.encode(train_h, verbose=False, use_eos=True)
    #trainB = encoder.encode(train_b, verbose=False, use_eos=True)
    trainA = train_h
    trainB = train_b

    print 'Computing development skipthoughts...'
    #devA = encoder.encode(dev_h, verbose=False, use_eos=True)
    #devB = encoder.encode(dev_b, verbose=False, use_eos=True)
#    devA = dev_h
#    devB = dev_b
    devA = test_h
    devB = test_b
    dev_score = score_test

    print 'Computing feature combinations...'
    trainF = np.c_[np.abs(trainA - trainB), trainA * trainB]
    devF = np.c_[np.abs(devA - devB), devA * devB]

    print 'Encoding labels...'
    #trainY = encode_labels(train_labels)
    #devY = encode_labels(holdout_labels)
    trainY = to_categorical(score_train, 4)
    devY = to_categorical(dev_score, 4)

    train_Fx, test_Fx = load_features()
    #fmodel = generate_feature_model(train_Fx, score_train, test_Fx, dev_score, ninputs=len(train_Fx[0]))

    train_tfidf, test_tfidf = generate_tfidf()

    print 'Compiling model...'
    lrmodel = prepare_model(ninputs=trainF.shape[1],n_feats=train_Fx.shape[1],n_tfidf=train_tfidf.shape[1])

    print 'Training...'
    bestlrmodel = train_model(lrmodel, trainF, trainY, devF, devY, dev_score, train_Fx, test_Fx, train_tfidf, test_tfidf)

    if evaltest:
        print 'Loading test skipthoughts...'
        testA = test_h
        testB = test_b

        print 'Computing feature combinations...'
        testF = np.c_[np.abs(testA - testB), testA * testB]

        yhat = bestlrmodel.predict(testF, verbose=2)
        yhat = [i.argmax()for i in yhat]

        string_predicted,test_stances = [],[]

        for i,j in zip(yhat,score_test):
            if i == 3:
                string_predicted.append('unrelated')
            if i == 0:
                string_predicted.append('agree')
            if i == 2:
                string_predicted.append('discuss')
            if i == 1:
                string_predicted.append('disagree')
            if j == 3:
                test_stances.append('unrelated')
            if j == 0:
                test_stances.append('agree')
            if j == 2:
                test_stances.append('discuss')
            if j == 1:
                test_stances.append('disagree')

        report_score(test_stances,string_predicted)
        score = accuracy_score(score_test, yhat)
        print 'accuracy is ..',score
        #print 'Evaluating...'

def generate_tfidf():
    file_train_instances = "/fncdata/train_stances.csv"
    file_train_bodies = "/fncdata/train_bodies.csv"
    file_test_instances = "/fncdata/competition_test_stances.csv"
    file_test_bodies = "/fncdata/test_bodies.csv"
    raw_train = FNCData(file_train_instances, file_train_bodies)
    raw_test = FNCData(file_test_instances, file_test_bodies)
    n_train = len(raw_train.instances)

    lim_unigram = 5000
    train_set, train_stances, bow_vectorizer, tfreq_vectorizer, tfidf_vectorizer = \
    pipeline_train(raw_train, raw_test, lim_unigram=lim_unigram)
    #feature_size = len(train_set[0])
    test_set = pipeline_test(raw_test, bow_vectorizer, tfreq_vectorizer, tfidf_vectorizer)
    return np.array(train_set), np.array(test_set)

def prepare_model(ninputs=9600, n_feats=45,nclass=4,n_tfidf=10001):
    inp1 = Input(shape=(ninputs,))
    inp2 = Input(shape=(n_feats,))
    inp3 = Input(shape=(n_tfidf,))
    reg = 0.00005
    out_neurons1 = 500
    #out_neurons2 = 20
    #out_neurons2 = 10
    m1 = Dense(input_dim=ninputs, output_dim=out_neurons1,activation='sigmoid'\
                      ,kernel_regularizer=regularizers.l2(0.00000001))(inp1)
    m1 = Dropout(0.2)(m1)
    m1 = Dense(100,activation='sigmoid')(m1)
    #m1 = Dropout(0.2)(m1)
    #m1 = Dense(4, activation='sigmoid')(m1)

    #m2 = Dense(input_dim=n_feats, output_dim=n_feats,activation='relu')(inp2)
    m2 = Dense(50,activation='relu')(inp2)
    #m2=Dense(4,activation='relu')(m2)

    m3 = Dense(500, input_dim=n_tfidf, activation='relu',\
                    kernel_regularizer=regularizers.l2(reg))(inp3)

    m3 = Dropout(0.4)(m3)
    m3 = Dense(50, activation='relu')(m3)
    #m3 = Dropout(0.4)(m3)
    #m3 = Dense(4, activation='softmax')(m3)

    #m1 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='sigmoid')(m1)
    #m2 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='softmax')(m2)

    m = Merge(mode='concat')([m1,m2,m3])

    #mul = Multiply()([m1,m2])
    #add = Abs()([m1,m2])
    #m = Merge(mode='concat')([mul,add])

    score = Dense(output_dim=nclass,activation='softmax')(m)
    model = Model([inp1,inp2,inp3],score)
    model.compile(loss='categorical_crossentropy', optimizer='adam')
    return model

def prepare_model2(ninputs=9600, n_feats=45,nclass=4,n_tfidf=10001):
    inp1 = Input(shape=(ninputs,))
    inp2 = Input(shape=(n_feats,))
    inp3 = Input(shape=(n_tfidf,))
    reg = 0.00005
    out_neurons1 = 500
    #out_neurons2 = 20
    #out_neurons2 = 10
    m1 = Dense(input_dim=ninputs, output_dim=out_neurons1,activation='sigmoid'\
                      ,kernel_regularizer=regularizers.l2(0.00000001))(inp1)
    m1 = Dropout(0.2)(m1)
    m1 = Dense(100,activation='sigmoid')(m1)
    #m1 = Dropout(0.2)(m1)
    #m1 = Dense(4, activation='sigmoid')(m1)

    m2 = Dense(input_dim=n_feats, output_dim=n_feats,activation='relu')(inp2)
    m2 = Dense(4,activation='relu')(inp2)
    #m2=Dense(4,activation='relu')(m2)

    m3 = Dense(500, input_dim=n_tfidf, activation='relu',\
                    kernel_regularizer=regularizers.l2(reg))(inp3)

    m3 = Dropout(0.4)(m3)
    m3 = Dense(50, activation='relu')(m3)
    #m3 = Dropout(0.4)(m3)
    #m3 = Dense(4, activation='softmax')(m3)

    #m1 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='sigmoid')(m1)
    #m2 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='softmax')(m2)

    m = Merge(mode='concat')([m1,m2,m3])

    #mul = Multiply()([m1,m2])
    #add = Abs()([m1,m2])
    #m = Merge(mode='concat')([mul,add])

    score = Dense(output_dim=nclass,activation='softmax')(m)
    model = Model([inp1,inp2,inp3],score)
    model.compile(loss='categorical_crossentropy', optimizer='adam')
    return model

def prepare_model1(ninputs=9600, n_feats=45,nclass=4,n_tfidf=10001):
    inp1 = Input(shape=(ninputs,))
    inp2 = Input(shape=(n_feats,))
    inp3 = Input(shape=(n_tfidf,))
    reg = 0.00005
    out_neurons1 = 500
    #out_neurons2 = 20
    #out_neurons2 = 10
    m1 = Dense(input_dim=ninputs, output_dim=out_neurons1,activation='sigmoid'\
                      ,kernel_regularizer=regularizers.l2(0.00000001))(inp1)
    m1 = Dropout(0.5)(m1)
    m1 = Dense(100,activation='sigmoid')(m1)
    m1 = Dropout(0.5)(m1)

    m2 = Dense(input_dim=n_feats, output_dim=n_feats,activation='relu')(inp2)
    m2 = Dense(30,activation='relu')(m2)

    m3 = Dense(500, input_dim=n_tfidf, activation='relu',\
                    kernel_regularizer=regularizers.l2(reg))(inp3)

    m3 = Dropout(0.6)(m3)
    m3 = Dense(100, activation='relu')(m3)
    m3 = Dropout(0.4)(m3)
    m3 = Dense(4, activation='softmax')(m3)

    #m1 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='sigmoid')(m1)
    #m2 = Dense(input_dim=ninputs, output_dim=out_neurons2,activation='softmax')(m2)

    m = Merge(mode='concat')([m1,m2,m3])

    #mul = Multiply()([m1,m2])
    #add = Abs()([m1,m2])
    #m = Merge(mode='concat')([mul,add])

    score = Dense(output_dim=nclass,activation='softmax')(m)
    model = Model([inp1,inp2,inp3],score)
    model.compile(loss='categorical_crossentropy', optimizer='adam')
    return model

    """
    Set up and compile the model architecture (Logistic regression)

    print 'changed'
    out_neurons1 = 500
    lrmodel = Sequential()
    lrmodel.add(Dense(input_dim=ninputs, output_dim=out_neurons1,activation='sigmoid'\
                      ,kernel_regularizer=regularizers.l2(0.00000001)))
    lrmodel.add(Dropout(0.5))
    #lrmodel.add(Dense(out_neurons2))
    #lrmodel.add(Dropout(0.5))
    lrmodel.add(Dense(output_dim=nclass))

    #lrmodel.add(Dense(input_dim=ninputs, output_dim=nclass))
    #lrmodel.add(Dropout(0.3))
    lrmodel.add(Activation('softmax'))
    lrmodel.compile(loss='categorical_crossentropy', optimizer='adam')
    return lrmodel
    """

def train_model(lrmodel, X, Y, devX, devY, devscores, feat_train, feat_dev, train_tfidf, test_tfidf):
    """
    Train model, using pearsonr on dev for early stopping
    """
    done = False
    best = -1.0
    #r = np.arange(1,5)

    while not done:
        # Every 100 epochs, check Pearson on development set
        lrmodel.fit([X,feat_train,train_tfidf], Y, verbose=2, shuffle=False, nb_epoch = 3, validation_data=([devX,feat_dev,test_tfidf], devY))
        #yhat = np.dot(lrmodel.predict(devX, verbose=2), r)
        yhat = lrmodel.predict([devX,feat_dev,test_tfidf], verbose=2)
        yhat = [i.argmax()for i in yhat]

        string_predicted,test_stances = [],[]

        for i,j in zip(yhat,devscores):
            if i == 3:
                string_predicted.append('unrelated')
            if i == 0:
                string_predicted.append('agree')
            if i == 2:
                string_predicted.append('discuss')
            if i == 1:
                string_predicted.append('disagree')
            if j == 3:
                test_stances.append('unrelated')
            if j == 0:
                test_stances.append('agree')
            if j == 2:
                test_stances.append('discuss')
            if j == 1:
                test_stances.append('disagree')
        print 'using new limit value....'
        #score = accuracy_score(devscores, yhat)
        score = report_score(test_stances,string_predicted,val=True)
        #return lrmodel

        if score > best:
            print score
            best = score
            bestlrmodel = prepare_model(ninputs=X.shape[1],n_feats=feat_train.shape[1],n_tfidf=train_tfidf.shape[1])
            bestlrmodel.set_weights(lrmodel.get_weights())
        else:
            done = True
            print '***** best model obtained with score',best,'******'

    yhat = bestlrmodel.predict([devX, feat_dev, test_tfidf], verbose=2)
    yhat = [i.argmax()for i in yhat]
    string_predicted,test_stances = [],[]

    for i,j in zip(yhat,devscores):
        if i == 3:
            string_predicted.append('unrelated')
        if i == 0:
            string_predicted.append('agree')
        if i == 2:
            string_predicted.append('discuss')
        if i == 1:
            string_predicted.append('disagree')
        if j == 3:
            test_stances.append('unrelated')
        if j == 0:
            test_stances.append('agree')
        if j == 2:
            test_stances.append('discuss')
        if j == 1:
            test_stances.append('disagree')

    report_score(test_stances,string_predicted)
    return bestlrmodel

import math

def load_features():

    train_hand = np.load('/fncdata3/hand.train.npy')
    #train_overlap = np.load('/fncdata3/overlap.train.npy')
    #train_refuting = np.load('/fncdata3/refuting.train.npy')
    #train_polarity = np.load('/fncdata3/polarity.train.npy')
    test_hand = np.load('/fncdata3/hand.test.npy')
    #test_overlap = np.load('/fncdata3/overlap.test.npy')
    #test_refuting = np.load('/fncdata3/refuting.test.npy')
    #test_polarity = np.load('/fncdata3/polarity.test.npy')
    '''
    train_other = np.load('/fncdata4/x_train.npy')
    test_other = np.load('/fncdata4/x_test.npy')
    train_other = train_other[:,16]
    test_other = test_other[:,16]
    #train_X = np.c_[train_polarity, train_refuting, train_overlap]
    #test_X = np.c_[test_polarity, test_refuting, test_overlap]
    for k,i in enumerate(test_other):
        if math.isnan(i):
            #print 'here',k
            test_other[k] = 0.0

    train_X = np.c_[train_hand, train_other]
    test_X = np.c_[test_hand, test_other]

    train_feat = np.load('/fncdata3/feat_train.npy')
    train_other = np.load('/fncdata3/x_train.npy')
    test_feat = np.load('/fncdata3/feat_test.npy')
    test_other = np.load('/fncdata3/x_test.npy')
    train_X = np.c_[train_feat, train_other]
    test_X = np.c_[test_feat, test_other]

    for k,i in enumerate(test_X):
        for ind,j in enumerate(i):
            if math.isnan(j):
                #print 'here',k
                test_X[k][ind] = 0.0

    ss = StandardScaler()
    ss.fit(np.vstack((train_X, test_X)))
    feat1_train = ss.transform(train_X)
    feat1_test = ss.transform(test_X)

    #feat_dev = feat1_train[len(trainF):]
    #feat1_train = feat1_train[0:len(trainF)]

    #feat_dev = feat1_test
    '''
    return train_hand, test_hand


text:
from .base import Output, NotConfiguredException

class LoggerOutput(Output):

    def output(self):
        if 'message' not in self.output_config:
            raise NotConfiguredException('No log message defined!')

        message_template = self.jinja_environment.from_string(
            self.output_config['message'])
        message_template.name = 'message'
        message_rendered = message_template.render()

        extra_vars = {}
        if 'variables' in self.output_config:
            for k, v in self.output_config['variables'].items():
                variable_template = self.jinja_environment.from_string(v)
                variable_template.name = 'variable'
                val = variable_template.render()
                extra_vars[k] = val

        log_level = 'info'
        if 'level' in self.output_config:
            loglevel_template = self.jinja_environment.from_string(
                self.output_config['level'])
            loglevel_template.name = 'loglevel'
            log_level = loglevel_template.render()
        if log_level == 'error' or log_level == 'err':
            self.logger.error(message_rendered, extra=extra_vars)
        elif log_level == 'warn' or log_level == 'warning':
            self.logger.warning(message_rendered, extra=extra_vars)
        else:
            self.logger.info(message_rendered, extra=extra_vars)


text:
typedef enum EAccountType
{
	k_EAccountTypeInvalid = 0,
	k_EAccountTypeIndividual = 1,		// single user account
	k_EAccountTypeMultiseat = 2,		// multiseat (e.g. cybercafe) account
	k_EAccountTypeGameServer = 3,		// game server account
	k_EAccountTypeAnonGameServer = 4,	// anonymous game server account
	k_EAccountTypePending = 5,			// pending
	k_EAccountTypeContentServer = 6,	// content server
	k_EAccountTypeClan = 7,
	k_EAccountTypeChat = 8,
	k_EAccountTypeConsoleUser = 9,		// Fake SteamID for local PSN account on PS3 or Live account on 360, etc.
	k_EAccountTypeAnonUser = 10,

	// Max of 16 items in this field
	k_EAccountTypeMax
} EAccountType;

#endif // EACCOUNTTYPE_H


text:
package com.socialize.ui.image;

import com.socialize.util.SafeBitmapDrawable;

/**
 * @author Jason Polites
 *
 */
public interface ImageLoadListener {

	public void onImageLoad(ImageLoadRequest request, SafeBitmapDrawable drawable);

	public void onImageLoadFail(ImageLoadRequest request, Exception error);

}