text:
require 'http'
require 'json'
require 'stash_core_api/error'

module StashCoreAPI
  # Wrapper around HTTP, does basic auth on every request
  class Request
    BASE_API_PATH = '/rest/api/1.0'

    def initialize(client, endpoint)
      @client = client
      @endpoint = endpoint
    end

    def get
      response = HTTP
                 .basic_auth(user: @client.user, pass: @client.pass)
                 .get(req_url(@endpoint))
      process(response)
    end

    private

    def process(response)
      code = response.code
      body = response.parse

      error = error(code, body)
      raise(error) if error

      body
    end

    def error(code, body)
      klass = StashCoreAPI::Error::ERRORS[code]
      klass&.new(body)
    end

    def req_url(endpoint)
      # build req_url and remove double slashes from it
      project = "/projects/#{@client.project}"
      repo = "/repos/#{@client.repository}"
      url = "#{@client.stash_url}/#{BASE_API_PATH}/#{project}/#{repo}/#{endpoint}"
      url.gsub(%r{([^:])//}, '\1/')
    end
  end
end


text:
<?php

namespace PHPixie\Tests\Paginate;

/**
 * @coversDefaultClass PHPixie\Paginate\Builder
 */
class BuilderTest extends \PHPixie\Test\Testcase
{
    protected $builder;

    public function setUp()
    {
        $this->builder = new \PHPixie\Paginate\Builder();
    }

    /**
     * @covers ::pager
     * @covers ::<protected>
     */
    public function testPager()
    {
        $loader = $this->quickMock('\PHPixie\Paginate\Loader');
        $pager = $this->builder->pager($loader, 15);

        $this->assertInstance($pager, '\PHPixie\Paginate\Pager', array(
            'loader' => $loader,
            'pageSize'   => 15
        ));
    }

    /**
     * @covers ::arrayLoader
     * @covers ::<protected>
     */
    public function testArrayLoader()
    {
        $items = array('test');
        $loader = $this->builder->arrayLoader($items);

        $this->assertInstance($loader, '\PHPixie\Paginate\Loader\ArrayAccess', array(
            'items' => $items
        ));
    }
}

redpajama_set_name: RedPajamaGithub


text:
from __future__ import print_function
import os
import unittest
import operator

from ansible import errors
from ansible.inventory.manager import InventoryManager

from ansible import __version__ as ansible_version
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager

class AnsibleInventoryTests(unittest.TestCase):
    var_manager = VariableManager()
    dataloader = DataLoader()
    yml_inv = InventoryManager(
        sources="{}/inv.sh".format(os.path.dirname(__file__)),
        loader=dataloader
    )

    def test_check_host_with_tags(self):
        yml = self.yml_inv.get_host("myhost2.example.com").get_vars()
        yml.pop('inventory_file',None)
        yml.pop('inventory_dir',None)
        result = {
            'inventory_hostname': u'myhost2.example.com',
            'group_names': [
                u'com',
                u'example',
                u'myhost',
                u'mytag',
                u'root',
                u'root-docker',
                u'root-docker-com',
                u'root-docker-example',
                u'root-docker-myhost',
                u'root-docker-mytag'
                ],
            'inventory_hostname_short': u'myhost2'
            }
        self.assertDictEqual(yml, result, msg="\nGot:    {}\nExpect: {}".format(yml, result))

    def test_check_host_with_name_syntax(self):
        yml = self.yml_inv.get_host("myhost1.example.com").get_vars()
        yml.pop('inventory_file',None)
        yml.pop('inventory_dir',None)
        result = {
            'inventory_hostname': u'myhost1.example.com',
            'group_names': [
                u'com',
                u'example',
                u'myhost',
                u'root',
                u'root-docker',
                u'root-docker-com',
                u'root-docker-example',
                u'root-docker-myhost'
                ],
            'inventory_hostname_short': u'myhost1'
            }
        self.assertDictEqual(yml, result, msg="\nGot:    {}\nExpect: {}".format(yml, result))

    def test_list_hosts(self):
        yml = self.yml_inv.list_hosts()
        yml = sorted(list(map((lambda x : repr(x).decode('utf-8')), yml)))
        result = [u'myhost1.example.com', u'myhost2.example.com']
        self.assertListEqual(yml, result, msg="\nGot:    {}\nExpect: {}".format(yml, result))

if __name__ == '__main__':
    print("\n### Execute test {}\n".format( __file__))
    unittest.main(verbosity=2)


text:
function initPushwoosh() {
	var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");
	if(device.platform == "Android")
	{
		registerPushwooshAndroid();
	}

	if(device.platform == "iPhone" || device.platform == "iOS")
	{
		registerPushwooshIOS();
	}

	if (device.platform == "Win32NT") {
	    registerPushwooshWP();
	}
}

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        // initPushwoosh();
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
				navigator.geolocation.getCurrentPosition(app.onSuccess, app.onError);
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
				// alert('test');
    },

		// onSuccess Callback
    //   This method accepts a `Position` object, which contains
    //   the current GPS coordinates
    //
  	onSuccess: function(position) {
        alert('Latitude: '          + position.coords.latitude          + '\n' +
              'Longitude: '         + position.coords.longitude         + '\n' +
              'Altitude: '          + position.coords.altitude          + '\n' +
              'Accuracy: '          + position.coords.accuracy          + '\n' +
              'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
              'Heading: '           + position.coords.heading           + '\n' +
              'Speed: '             + position.coords.speed             + '\n' +
              'Timestamp: '         + position.timestamp                + '\n');
    },

    // onError Callback receives a PositionError object
    //
    onError: function(error) {
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    }
};


text:
package com.github.phudekar.downloader;

public class ConsoleOutput implements ProgressListener {

    private StringBuilder messageBuilder = new StringBuilder();

    @Override
    public void onProgress(DownloadEntry entry) {
        if (entry.getStatus().isComplete()) {
            printProgress(entry);
            System.out.println("\nFile downloaded successfully at " + entry.getLocation());
        } else {
            printProgress(entry);
        }
    }

    private void printProgress(DownloadEntry entry) {
        DownloadStatus status = entry.getStatus();
        for (int i = 0; i < messageBuilder.length() + 5; i++) {
            System.out.print("\b");
        }
        messageBuilder = new StringBuilder();
        messageBuilder.append("[");

        int progressBarWidth = 20;
        for (int i = 1; i <= progressBarWidth; i++) {
            if (status.getDownloadedSize() * progressBarWidth / status.getTotalSize() >= i)
                messageBuilder.append("=");
            else
                messageBuilder.append(".");
        }

        messageBuilder.append("] ");
        messageBuilder.append(Math.round(status.getDownloadedSize() / 1024) + "/" + Math.round(status.getTotalSize() / 1024) + " KB ");
        messageBuilder.append("Enter '" + ConsoleInput.PAUSE + "' to pause ");

        System.out.print(messageBuilder.toString());
    }

}


text:
require 'fog/rage4/core'

module Fog
  module DNS
    class Rage4 < Fog::Service
      requires :rage4_email, :rage4_api_key
      recognizes :rage4_url, :host, :path, :port, :scheme, :persistent

      model_path 'fog/rage4/models/dns'
      model       :record
      collection  :records
      model       :zone
      collection  :zones

      request_path 'fog/rage4/requests/dns'
      request :list_domains
      request :create_domain
      request :create_domain_vanity
      request :create_reverse_domain_4
      request :get_domain
      request :get_domain_by_name
      request :update_domain
      request :delete_domain
      request :show_current_usage
      request :show_global_usage
      request :list_record_types
      request :list_geo_regions
      request :create_record
      request :update_record
      request :list_records
      request :delete_record
      request :set_record_failover

      class Real
        def initialize(options={})
          @rage4_email = options[:rage4_email]
          @rage4_password  = options[:rage4_api_key]
          @connection_options = options[:connection_options] || {}
          if options[:rage4_url]
            uri = URI.parse(options[:rage4_url])
            options[:host]    = uri.host
            options[:port]    = uri.port
            options[:scheme]  = uri.scheme
          end
          @host       = options[:host]        || "secure.rage4.com"
          @persistent = options[:persistent]  || false
          @port       = options[:port]        || 443
          @scheme     = options[:scheme]      || 'https'
          @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
        end

        def reload
          @connection.reset
        end

        def request(params)
          params[:headers] ||= {}
          key = "#{@rage4_email}:#{@rage4_password}"
          params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",'')})

          response = @connection.request(params)

          unless response.body.empty?
            response.body = Fog::JSON.decode(response.body)
          end
          response
        end
      end
    end
  end
end


text:
title: 'read/[1,2]'
group: Input Output
module: sio
iso: readterm
predicates:
- {sig: 'read', args: {
    1: 'read a term from the current input stream',
    2: 'read a term from specified stream'
  }}
- {sig: 'read_term', args: {
    2: 'read term from current input with options',
    3: 'read term from specified stream with options'
  }}
---

## FORMS
```
read(Term)

read(Stream_or_Alias, Term)

read_term(Term, Options)

read_term(Stream_or_Alias, Term, Options)
```
## DESCRIPTION

These predicates are used to read a term from a stream using the operator declarations in effect at the time of the read. The end of the term read from the stream is indicated by a fullstop token appearing in the stream. The fullstop token is a period(' . ') followed by a newline, white space character, or line comment character. If the stream is positioned so that there are no more terms to be read and the stream has the property `eof_action(eof_code)`, then `Term` will be unified with the atom `end_of_file`.

`read/1` reads a term from the current input stream and unifies it with `Term`.

`read/2` reads a term from the input stream specified by `Stream_or_Alias` and unifies it with `Term`.

`read_term/2` reads a term from the current input stream with options `Options` (see below) and unifies the term read with `Term`.

`read_term/3` reads a term from the input stream specified by `Stream_or_Alias` and unifies it with `Term`. The options specified by `Options` are used in the process of reading the term.

`read_term/2` and `read_term/`3 take the parameter `Options` which is a list of options to `read_term`. These options either affect the behavior of `read_term` or are used to retrieve additional information about the term which was read.

The following options supported by ALS Prolog are options specified by the March'93 ISO Prolog Standard:

- `variables(Vars)` -- After reading a term, `Vars` shall be a list of the variables in the term read in left-to-right traversal order.
- `variable_names(VN_list)` -- After reading a term, `VN_list` will be unified with a list of elements of the form `V = A` where `V` is a variable in the term and `A` is an atom representing the name of the variable. Anonymous variables (variables whose name is `'_'`) will not appear in this list.

- `singletons(VN_list)` -- After reading a term, `VN_list` will be unified with a list of elements of the form `V = A`, where `V` is a variable occurring in the term only once and `A` is an atom which represents the name of the variable. Anonymous variables will not appear in this list.

The following additional options are supported by ALS Prolog:

- `vars_and_names(Vars,Names)` -- After reading a term, `Vars` shall be a list of the variables in the term read in left-to-right traversal order, `Names` is a list of the associated names of the variables. `'_'` is the only variable name which may occur more than once on the list `Names`.

- `attach_fullstop(Bool)` -- `Bool` is either `true` or `false`. The default is `false`. When `Bool` is `true`, a fullstop is inserted before the end of the stream. This option is most useful for reading single terms from atom, character, and character code streams.

- `blocking(Bool)` -- For streams such as socket streams or IPC queue streams, it is possible for the stream to remain open, yet there be no characters available at the time a read is issued. The value of `Bool` controls the behavior of the read in this setting. The values of `Bool` are as follows:

    **`true`** In this type of read, the read suspends or waits until enough characters are available to parse as a valid Prolog term.

    **`false`** In this type of read, if no characters are available, the read will immediately return with success, unifying the 'read term argument' (which is argument 1 for `read_term/2` and is argument 2 for `read_term/3`) with the term `unfinished_read`; any tokens consumed in the read attempt are saved in the stream data structure, and subsequent attempts to read from this stream begin with these tokens, followed by tokens created from further characters which arrive at later times.

- `syntax_errors(Val)` -- Val indicates how the system is to handle any syntax errors which occur during the reading of `Term`.  The possible values of `Val` and their interpretations are:

    **`error`** Occurrence of a syntax error will cause the system to raise an exception, which includes outputting a warning message. This is the default.

    **`fail`** Occurrence of a syntax error will cause the attempt to read `Term` to fail, and and error message will be output.

    **`quiet`** Occurrence of a syntax error will cause the attempt to read `Term` to fail quietly, with no message output.

    **`dec10`** Occurrence of a syntax error will cause the attempt to read `Term` to output an error message, to skip over the offending input characters, and attempt to re-read `Term` from the source stream.

## EXAMPLES
`?- read(Term).`

`[+(3,4),9+8].        <<`          _Typed on console (current input)_
```
Term=[3+4,9+8]

yes.
```

`?- read_term(Term,[variables(V),variable_names(VN),singletons(SVN)]).`

`f(X,[Y,Z,W],g(X,Z),[_,U1,_,U2]).        <<`          _Typed on console (current input)_
```
Term=f(_A,[_B,_C,_D],g(_A,_C),[_E,_F,_G,_H])
V=[_A,_B,_C,_D,_E,_F,_G,_H]
VN=[_A = 'X',_B = 'Y',_C = 'Z',_D = 'W',_F = 'U1',_H = 'U2']
SVN=[_B = 'Y',_D = 'W',_F = 'U1',_H = 'U2']

yes.
```

```
?- open(atom('[X,2,3]'),read,S),
   read_term(S,Term,[attach_fullstop(true)]), close(S).

S=stream_descriptor('\002',closed,atom,atom('[X,2,3]'),[input|nooutput],
    false,42,'[X,2,3]',7,7,0,true,0,wt_opts(78,400,flat),[],wait,text,
    eof_code,true,0)
Term=[_A,2,3]

yes.
```

```
?- read_term(user_input,Term,not_an_option_list).
Error: Argument of type list expected instead of not_an_option_list.
- Goal:          sio:read_term(user_input,_A,not_an_option_list)
- Throw pattern: error(type_error(list,not_an_option_list),
                     [sio:read_term(user_input,_A,not_an_option_list)])
```

`?- read(X).`

`foobar        <<`          _Typed on console (current input)_

`zipper.        <<`          _Typed on console (current input)_
```
zipper.
^Syntax error
	'standard input', line 9: Fullstop (period) expected
```

## ERRORS

`Stream_or_Alias` is a variable

-- -- -- -- > instantiation_error.

`Stream_or_Alias` is neither a variable nor a stream descriptor nor an alias

-- -- -- -- > domain_error(stream_or_Alias, Stream_or_Alias) .

`Stream_or_Alias` is not associated with an open stream

-- -- -- -- > existence_error(stream, Stream_or_Alias) .

`Stream_or_Alias` is not an input stream

-- -- -- -- > permission_error(input, stream, Stream_or_Alias) .

`Options` is a variable

-- -- -- -- > instantiation_error.

`Options` is neither a variable nor a list

-- -- -- -- > type_error(list, Option) .

`Options` is a list an element of which is a variable

-- -- -- -- > instantiation_error.

`Options` is a list containing an element E which is neither a variable nor a valid read option

-- -- -- -- > domain_error(read_option, E)

The stream associated with Stream_or_Alias is at the end of the stream and the stream has the property eof_action(error)

-- -- -- -- > existence_error(past_end_of_stream, Stream_or_Alias) .

The stream associated with Stream_or_Alias has no input ready to be read and the stream has the property snr_action(error)

-- -- -- -- > existence_error(stream_not_ready, Stream_or_Alias) .

## SEE ALSO

- [`write/[1,2]`](write.html)
- [`write_term/[2,3]`](write.html)
- [`open/4`](open.html)
- [`close/1`](close.html)
- [`get_char/[1,2]`](get_char.html)
- [`get_code/[1,2]`](get_code.html)

- [User Guide (Prolog I/O)](../guide/10-Prolog-I-O.html)
- {% include book.md id="bowen91"    sec="7.8" %}
- {% include book.md id="sterling86" sec="12.2" %}
- {% include book.md id="bratko86"   sec="6.2.1" %}
- {% include book.md id="clocksin81" sec="5.1" %}


text:
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GSoft.Dynamite.Fields;
using Microsoft.SharePoint;

namespace GSoft.Dynamite.ValueTypes.Readers
{
    /// <summary>
    /// Reads double-based field values
    /// </summary>
    public class DoubleValueReader : BaseValueReader<double?>
    {
        /// <summary>
        /// Reads a field value from a list item
        /// </summary>
        /// <param name="item">The list item we want to extract a field value from</param>
        /// <param name="fieldInternalName">The key to find the field in the item's columns</param>
        /// <returns>The value extracted from the list item's field</returns>
        public override double? ReadValueFromListItem(SPListItem item, string fieldInternalName)
        {
            var fieldValue = item[fieldInternalName];

            if (fieldValue != null)
            {
                return (double)fieldValue;
            }

            return null;
        }

        /// <summary>
        /// Reads a field value from a list item version
        /// </summary>
        /// <param name="itemVersion">The list item version we want to extract a field value from</param>
        /// <param name="fieldInternalName">The key to find the field in the item's columns</param>
        /// <returns>The value extracted from the list item's field</returns>
        public override double? ReadValueFromListItemVersion(SPListItemVersion itemVersion, string fieldInternalName)
        {
            var fieldValue = itemVersion[fieldInternalName];

            if (fieldValue != null)
            {
                return (double)fieldValue;
            }

            return null;
        }

        /// <summary>
        /// Reads a field value from a DataRow returned by a CAML query
        /// </summary>
        /// <param name="web">The context's web</param>
        /// <param name="dataRowFromCamlResult">The CAML-query-result data row we want to extract a field value from</param>
        /// <param name="fieldInternalName">The key to find the field among the data row cells</param>
        /// <returns>The value extracted from the data row's corresponding cell</returns>
        public override double? ReadValueFromCamlResultDataRow(SPWeb web, DataRow dataRowFromCamlResult, string fieldInternalName)
        {
            var fieldValue = dataRowFromCamlResult[fieldInternalName];

            if (fieldValue != null && fieldValue != System.DBNull.Value)
            {
                return double.Parse(fieldValue.ToString(), CultureInfo.InvariantCulture);
            }

            return null;
        }
    }
}


text:
"""
A modification of pyjamas DeferredMethod
@author: Tobias Weber
@contact: tobi-weber@gmx.de
"""

from pyjamas.Timer import Timer

global deferredHandlers
deferredHandlers = []
global timerIsActive
timerIsActive = False

def add(handler, arguments=[]):
    deferredHandlers.append([handler, arguments])
    maybeSetDeferredHandlerTimer()

def flushDeferredHandlers():
    for i in range(len(deferredHandlers)):
        current = deferredHandlers[0]
        del deferredHandlers[0]
        if current:
            handler = current[0]
            args = current[1]
            handler(*args)

def maybeSetDeferredHandlerTimer():
    global timerIsActive

    if (not timerIsActive) and (not len(deferredHandlers)==0):
        Timer(1, onTimer)
        timerIsActive = True

def onTimer(t):
    global timerIsActive

    flushDeferredHandlers()
    timerIsActive = False
    maybeSetDeferredHandlerTimer()


text:
using namespace std;
using namespace cv;

struct feature_node ** LBFRegressor::DeriveBinaryFeat(
                                    const RandomForest& randf,
                                    const vector<Mat_<uchar> >& images,
                                    const vector<Mat_<double> >& current_shapes,
                                    const vector<BoundingBox> & bounding_boxs){

    // initilaize the memory for binfeatures
    struct feature_node **binfeatures;
    binfeatures = new struct feature_node* [images.size()];
    for (int i=0;i<images.size();i++){
         binfeatures[i] = new struct feature_node[randf.max_numtrees_*randf.num_landmark_+1];
    }

//    int bincode;
//    int ind;
//    int leafnode_per_tree = pow(2,(randf.max_depth_-1));

    Mat_<double> rotation;
    double scale;

    // extract feature for each samples
   // #pragma omp parallel for
    for (int i=0;i < images.size();i++){
        SimilarityTransform(ProjectShape(current_shapes[i],bounding_boxs[i]),mean_shape_,rotation,scale);
       	#pragma omp parallel for
        for (int j =0; j <randf.num_landmark_; j++){
	       GetCodefromRandomForest(binfeatures[i], j*randf.max_numtrees_,randf.rfs_[j], images[i], current_shapes[i],
                                    bounding_boxs[i], rotation, scale);
//            for(int k = 0; k< randf.max_numtrees_;k++){
//                bincode = GetCodefromTree(randf.rfs_[j][k],images[i],current_shapes[i],bounding_boxs[i],rotation,scale);
//                ind = j * randf.max_numtrees_ + k;
//                binfeatures[i][ind].index = leafnode_per_tree * ind + bincode;
//                binfeatures[i][ind].value = 1;
//            }

        }
        binfeatures[i][randf.num_landmark_ * randf.max_numtrees_].index = -1;
        binfeatures[i][randf.num_landmark_ * randf.max_numtrees_].value = -1;
    }
    return binfeatures;
}
// get code of one landmark.
// index: the start index of tree.
void LBFRegressor::GetCodefromRandomForest(struct feature_node *binfeature,
                                           const int index,
                                           const vector<Tree>& rand_forest,
                                           const Mat_<uchar>& image,
                                           const Mat_<double>& shape,
                                           const BoundingBox& bounding_box,
                                           const Mat_<double>& rotation,
                                           const double scale){

    int leafnode_per_tree = pow(2,rand_forest[0].max_depth_-1);
    double landmark_x = shape(rand_forest[0].landmarkID_,0);
    double landmark_y = shape(rand_forest[0].landmarkID_,1);

    for (int iter = 0;iter<rand_forest.size();iter++){
        int currnode = 0;
        int bincode = 1;
        for(int i = 0;i<rand_forest[iter].max_depth_-1;i++){
            double x1 = rand_forest[iter].nodes_[currnode].feat[0];
            double y1 = rand_forest[iter].nodes_[currnode].feat[1];
            double x2 = rand_forest[iter].nodes_[currnode].feat[2];
            double y2 = rand_forest[iter].nodes_[currnode].feat[3];

            double project_x1 = rotation(0,0) * x1 + rotation(0,1) * y1;
            double project_y1 = rotation(1,0) * x1 + rotation(1,1) * y1;
            project_x1 = scale * project_x1 * bounding_box.width / 2.0;
            project_y1 = scale * project_y1 * bounding_box.height / 2.0;
            int real_x1 = (int)project_x1 + landmark_x;
            int real_y1 = (int)project_y1 + landmark_y;
            real_x1 = max(0,min(real_x1,image.cols-1));
            real_y1 = max(0,min(real_y1,image.rows-1));

            double project_x2 = rotation(0,0) * x2 + rotation(0,1) * y2;
            double project_y2 = rotation(1,0) * x2 + rotation(1,1) * y2;
            project_x2 = scale * project_x2 * bounding_box.width / 2.0;
            project_y2 = scale * project_y2 * bounding_box.height / 2.0;
            int real_x2 = (int)(project_x2 + landmark_x);
            int real_y2 = (int)(project_y2 + landmark_y);
            real_x2 = max(0,min(real_x2,image.cols-1));
            real_y2 = max(0,min(real_y2,image.rows-1));

            int pdf = (int)(image(real_y1,real_x1))-(int)(image(real_y2,real_x2));
            if (pdf < rand_forest[iter].nodes_[currnode].thresh){
                currnode =rand_forest[iter].nodes_[currnode].cnodes[0];
            }
            else{
                currnode =rand_forest[iter].nodes_[currnode].cnodes[1];
                bincode += pow(2, rand_forest[iter].max_depth_-2-i);
            }
        }
        binfeature[index+iter].index = leafnode_per_tree*(index+iter)+bincode;
        binfeature[index+iter].value = 1;

    }
}
int  LBFRegressor::GetCodefromTree(const Tree& tree,
                                   const Mat_<uchar>& image,
                                   const Mat_<double>& shape,
                                   const BoundingBox& bounding_box,
                                   const Mat_<double>& rotation,
                                   const double scale){
    int currnode = 0;
    int bincode = 1;
    for(int i = 0;i<tree.max_depth_-1;i++){
        double x1 = tree.nodes_[currnode].feat[0];
        double y1 = tree.nodes_[currnode].feat[1];
        double x2 = tree.nodes_[currnode].feat[2];
        double y2 = tree.nodes_[currnode].feat[3];

        double project_x1 = rotation(0,0) * x1 + rotation(0,1) * y1;
        double project_y1 = rotation(1,0) * x1 + rotation(1,1) * y1;
        project_x1 = scale * project_x1 * bounding_box.width / 2.0;
        project_y1 = scale * project_y1 * bounding_box.height / 2.0;
        int real_x1 = project_x1 + shape(tree.landmarkID_,0);
        int real_y1 = project_y1 + shape(tree.landmarkID_,1);
        real_x1 = max(0,min(real_x1,image.cols-1));
        real_y1 = max(0,min(real_y1,image.rows-1));

        double project_x2 = rotation(0,0) * x2 + rotation(0,1) * y2;
        double project_y2 = rotation(1,0) * x2 + rotation(1,1) * y2;
        project_x2 = scale * project_x2 * bounding_box.width / 2.0;
        project_y2 = scale * project_y2 * bounding_box.height / 2.0;
        int real_x2 = project_x2 + shape(tree.landmarkID_,0);
        int real_y2 = project_y2 + shape(tree.landmarkID_,1);
        real_x2 = max(0,min(real_x2,image.cols-1));
        real_y2 = max(0,min(real_y2,image.rows-1));

        int pdf = (int)(image(real_y1,real_x1))-(int)(image(real_y2,real_x2));
        if (pdf < tree.nodes_[currnode].thresh){
            currnode =tree.nodes_[currnode].cnodes[0];
        }
        else{
            currnode =tree.nodes_[currnode].cnodes[1];
            bincode += pow(2, tree.max_depth_-2-i);
        }
    }
    return bincode;
};

void LBFRegressor::GlobalRegression(struct feature_node **binfeatures,
                                    const vector<Mat_<double> >& shapes_residual,
                                    vector<Mat_<double> >& current_shapes,
                                    const vector<BoundingBox> & bounding_boxs,
                                    const Mat_<double>& mean_shape,
                                    //Mat_<double>& W,
                                    vector<struct model*>& models,
                                    int num_feature,
                                    int num_train_sample,
                                    int stage
                                    ){
    // shapes_residual: n*(l*2)
    // construct the problem(expect y)
    struct problem* prob = new struct problem;
    prob -> l = num_train_sample;
    prob -> n = num_feature;
    prob -> x = binfeatures;
    prob -> bias = -1;

    // construct the parameter
    struct parameter* param = new struct parameter;
    param-> solver_type = L2R_L2LOSS_SVR_DUAL;
  //  param-> solver_type = L2R_L2LOSS_SVR;
    param->C = 1.0/num_train_sample;
    param->p = 0;
    param->eps = 0.00001;
    //param->eps = 0.001;

    // initialize the y
    int num_residual = shapes_residual[0].rows*2;
    double** yy = new double*[num_residual];

    for (int i=0;i<num_residual;i++){
        yy[i] = new double[num_train_sample];
    }
    for (int i=0;i < num_train_sample;i++){
        for (int j=0;j<num_residual;j++){
            if (j < num_residual/2){
                yy[j][i] = shapes_residual[i](j,0);
            }
            else{
                yy[j][i] = shapes_residual[i](j-num_residual/2,1);
            }
        }
    }

    //train
    models.clear();
    models.resize(num_residual);
    #pragma omp parallel for
    for (int i=0;i < num_residual;i++){
        clock_t t1 = clock();
        cout << "Train "<< i <<"th landmark"<<endl;
        prob->y = yy[i];
        check_parameter(prob, param);
        struct model* lbfmodel  = train(prob, param);
        models[i] = lbfmodel;
        double time =double(clock() - t1) / CLOCKS_PER_SEC;
        cout << "linear regression of one landmark cost "<< time <<"s"<<endl;
    }
    // update the current shape and shapes_residual
    double tmp;
    double scale;
    Mat_<double>rotation;
    Mat_<double> deltashape_bar(num_residual/2,2);
    Mat_<double> deltashape_bar1(num_residual/2,2);
    for (int i=0;i<num_train_sample;i++){
        #pragma omp parallel for
        for (int j=0;j<num_residual;j++){
            tmp = predict(models[j],binfeatures[i]);
            if (j < num_residual/2){
                deltashape_bar(j,0) = tmp;
            }
            else{
                deltashape_bar(j-num_residual/2,1) = tmp;
            }
        }
        // transfer or not to be decided
        // now transfer
        SimilarityTransform(ProjectShape(current_shapes[i],bounding_boxs[i]),mean_shape,rotation,scale);
        transpose(rotation,rotation);
        deltashape_bar1 = scale * deltashape_bar * rotation;
        current_shapes[i] = ReProjectShape((ProjectShape(current_shapes[i],bounding_boxs[i])+deltashape_bar1),bounding_boxs[i]);

        //updata shapes_residual
       // shapes_residual[i] = shapes_residual[i] - deltashape_bar;
    }
}

void LBFRegressor::GlobalPrediction(struct feature_node** binfeatures,
                                    vector<Mat_<double> >& current_shapes,
                                    const vector<BoundingBox> & bounding_boxs,
                                    int stage){
    int num_train_sample = (int)current_shapes.size();
    int num_residual = current_shapes[0].rows*2;
    double tmp;
    double scale;
    Mat_<double>rotation;
    Mat_<double> deltashape_bar(num_residual/2,2);
   // #pragma omp parallel for
    for (int i=0;i<num_train_sample;i++){
        current_shapes[i] = ProjectShape(current_shapes[i],bounding_boxs[i]);
        double t =(double)cvGetTickCount();
       	#pragma omp parallel for
        for (int j=0;j<num_residual;j++){
            tmp = predict(Models_[stage][j],binfeatures[i]);
            if (j < num_residual/2){
                deltashape_bar(j,0) = tmp;
            }
            else{
                deltashape_bar(j-num_residual/2,1) = tmp;
            }
        }
        // transfer or not to be decided
        // now transfer
        SimilarityTransform(current_shapes[i],mean_shape_,rotation,scale);
        transpose(rotation,rotation);
        deltashape_bar = scale * deltashape_bar * rotation;
        current_shapes[i] = ReProjectShape((current_shapes[i]+deltashape_bar),bounding_boxs[i]);
    }
}

void LBFRegressor::Train(const vector<Mat_<uchar> >& images,
                         const vector<Mat_<double> >& ground_truth_shapes,
                         const vector<BoundingBox> & bounding_boxs){

    // data augmentation and multiple initialization
    vector<Mat_<uchar> > augmented_images;
    vector<BoundingBox> augmented_bounding_boxs;
    vector<Mat_<double> > augmented_ground_truth_shapes;
    vector<Mat_<double> > current_shapes;

    RNG random_generator(getTickCount());
    for(int i = 0;i < images.size();i++){
        for(int j = 0;j < global_params.initial_num;j++){
            int index = 0;
            do{
                // index = (i+j+1) % (images.size());
                index = random_generator.uniform(0, (int)images.size());
            }while(index == i);

            // 1. Select ground truth shapes of other images as initial shapes
            augmented_images.push_back(images[i]);
            augmented_ground_truth_shapes.push_back(ground_truth_shapes[i]);
            augmented_bounding_boxs.push_back(bounding_boxs[i]);

            // 2. Project current shape to bounding box of ground truth shapes
            Mat_<double> temp = ProjectShape(ground_truth_shapes[index], bounding_boxs[index]);
            temp = ReProjectShape(temp, bounding_boxs[i]);
            current_shapes.push_back(temp);
        }
    }

    // get mean shape from training shapes(only origin train images)
    mean_shape_ = GetMeanShape(ground_truth_shapes,bounding_boxs);
    cout << mean_shape_<<endl;
    // train random forest
    int num_feature = global_params.landmark_num * global_params.max_numtrees * pow(2,(global_params.max_depth-1));
    int num_train_sample = (int)augmented_images.size();

    double t0 =(double)cvGetTickCount();
    for (int stage = 0; stage < global_params.max_numstage; stage++){
        double t1 =(double)cvGetTickCount();
        GetShapeResidual(augmented_ground_truth_shapes,current_shapes,augmented_bounding_boxs,
                         mean_shape_,shapes_residual_);

        cout << "train random forest of "<< stage <<" stage" <<endl;
        RandomForest_[stage].Train(augmented_images,augmented_ground_truth_shapes, current_shapes, augmented_bounding_boxs, mean_shape_, shapes_residual_, stage);
        double t2 = (double)cvGetTickCount();
        cout << "the random forest of "<< stage<<" stage has been trained, cost "<< (t2-t1)/((double)cvGetTickFrequency()*1000*1000) <<" s"<<endl<<endl;

        cout << "derive binary codes given learned random forest in stage"<< stage << endl;
        struct feature_node ** binfeatures ;
        binfeatures = DeriveBinaryFeat(RandomForest_[stage], augmented_images, current_shapes, augmented_bounding_boxs);
        double t3 = (double)cvGetTickCount();
        cout << "derive binary features of "<< stage<<" stage has been trained, cost "<< (t3-t2)/((double)cvGetTickFrequency()*1000*1000) <<" s"<<endl<<endl;

        cout << "learn global linear regression given binary feature" << endl;
        GlobalRegression(binfeatures, shapes_residual_, current_shapes, augmented_bounding_boxs, mean_shape_, Models_[stage], num_feature, num_train_sample, stage);
        ReleaseFeatureSpace(binfeatures,(int)augmented_images.size());

        //calculate the error
        double MRSE_sum = 0;
        for (int i =0; i<current_shapes.size();i++){
            MRSE_sum += CalculateError(augmented_ground_truth_shapes[i], current_shapes[i]);
        }
        cout <<"stage "<<stage<<", error: "<<MRSE_sum/current_shapes.size()<<endl;

        //calculate the remaining time
        double t4 = (double)cvGetTickCount();
        cout << "the linear model of "<< stage<<" stage has been trained, cost "<< (t4-t3)/((double)cvGetTickFrequency()*1000*1000) <<" s"<<endl<<endl;

        cout << "the "<<stage<<" has completed, cost "<<(t4-t0)/((double)cvGetTickFrequency()*1000*1000) <<" s"<<endl;
        cout << "Remaining time is about "<< (t4-t0)/((double)cvGetTickFrequency()*1000*1000*(stage+1))*(global_params.max_numstage-stage-1)<< "s"<<endl<<endl;
    }
}
void LBFRegressor::ReleaseFeatureSpace(struct feature_node ** binfeatures,
                         int num_train_sample){
    for (int i = 0;i < num_train_sample;i++){
            delete[] binfeatures[i];
    }
    delete[] binfeatures;
}

vector<Mat_<double> > LBFRegressor::Predict(const vector<Mat_<uchar> >& images,
                                    const vector<BoundingBox>& bounding_boxs,
                                    const vector<Mat_<double> >& ground_truth_shapes,
                                    int initial_num){

    vector<Mat_<double> > current_shapes;

    for (int i=0; i<images.size();i++){
        Mat_<double> current_shape = ReProjectShape(mean_shape_, bounding_boxs[i]);
        current_shapes.push_back(current_shape);
    }
    double MRSE_sum = 0;
    for (int i =0; i<current_shapes.size();i++){
        MRSE_sum += CalculateError(ground_truth_shapes[i], current_shapes[i]);
    }
    cout <<"mean shape "<<", error: "<<MRSE_sum/current_shapes.size()<<endl;

    int stage1 =0;
    for ( int stage = 0; stage < global_params.max_numstage; stage++){
        if(stage<global_params.max_numstage){
            stage1 = stage;
        }
        else{
            stage1 = global_params.max_numstage-1;
        }
        struct feature_node ** binfeatures ;
        binfeatures = DeriveBinaryFeat(RandomForest_[stage1],images,current_shapes,bounding_boxs);
        GlobalPrediction(binfeatures, current_shapes,bounding_boxs,stage1);
        ReleaseFeatureSpace(binfeatures,images.size());
        double MRSE_sum = 0;
        for (int i =0; i<current_shapes.size();i++){
            MRSE_sum += CalculateError(ground_truth_shapes[i], current_shapes[i]);
        }
        cout <<"stage "<<stage<<", error: "<<MRSE_sum/current_shapes.size()<<endl;
    }

    return current_shapes;
}

Mat_<double>  LBFRegressor::Predict(const cv::Mat_<uchar>& image,
                                    const BoundingBox& bounding_box,
                                    int initial_num){
    vector<Mat_<uchar> > images;
    vector<Mat_<double> > current_shapes;
    vector<BoundingBox>  bounding_boxs;

    images.push_back(image);
    bounding_boxs.push_back(bounding_box);
    current_shapes.push_back(ReProjectShape(mean_shape_, bounding_box));

//    Mat img = imread("/Users/lequan/workspace/LBF/Datasets/lfpw/testset/image_0078.png");
//    // draw result :: red
//    for(int j = 0;j < global_params.landmark_num;j++){
//        circle(img,Point2d(current_shapes[0](j,0),current_shapes[0](j,1)),1,Scalar(255,255,255),-1,8,0);
//    }
//    imshow("result", img);
//    waitKey(0);
//    string name = "example mean.jpg";
//    imwrite(name,img);

    for ( int stage = 0; stage < global_params.max_numstage; stage++){
        struct feature_node ** binfeatures ;
        binfeatures = DeriveBinaryFeat(RandomForest_[stage],images,current_shapes,bounding_boxs);
        GlobalPrediction(binfeatures, current_shapes,bounding_boxs,stage);
        ReleaseFeatureSpace(binfeatures, images.size());

//        Mat image = imread("/Users/lequan/workspace/LBF/Datasets/afw/image_0078.png");
//        // draw result :: red
//        for(int j = 0;j < global_params.landmark_num;j++){
//            circle(image,Point2d(current_shapes[0](j,0),current_shapes[0](j,1)),1,Scalar(255,255,255),-1,8,0);
//        }
//        imshow("result", image);
//        waitKey(0);
//        string name = "example "+ to_string(stage) + ".jpg";
//        imwrite(name,image);

    }
    return current_shapes[0];
}

void LBFRegressor::Save(string path){
    cout << endl<<"Saving model..." << endl;
    ofstream fout;
    fout.open(path);
    // write the Regressor to file
    WriteGlobalParam(fout);
    WriteRegressor(fout);
    fout.close();
    cout << "End" << endl;

}

void LBFRegressor::Load(string path){
    cout << "Loading model from "<< path  << endl;
    ifstream fin;
    fin.open(path);
    ReadGlobalParam(fin);
    ReadRegressor(fin);
    fin.close();
    cout << "End"<<endl;
}
void  LBFRegressor::WriteGlobalParam(ofstream& fout){
    fout << global_params.bagging_overlap << endl;
    fout << global_params.max_numtrees << endl;
    fout << global_params.max_depth << endl;
    fout << global_params.max_numthreshs << endl;
    fout << global_params.landmark_num << endl;
    fout << global_params.initial_num << endl;
    fout << global_params.max_numstage << endl;

    for (int i = 0; i< global_params.max_numstage; i++){
        fout << global_params.max_radio_radius[i] << " ";

    }
    fout << endl;

    for (int i = 0; i < global_params.max_numstage; i++){
        fout << global_params.max_numfeats[i] << " ";
    }
    fout << endl;
}
void  LBFRegressor::WriteRegressor(ofstream& fout){
    for(int i = 0;i < global_params.landmark_num;i++){
        fout << mean_shape_(i,0)<<" "<< mean_shape_(i,1)<<" ";
    }
    fout<<endl;
    ofstream fout_reg;
    fout_reg.open(modelPath + "/Regressor.model",ios::binary);
    for (int i=0; i < global_params.max_numstage; i++ ){
        RandomForest_[i].Write(fout);
        fout << Models_[i].size()<< endl;
        for (int j=0; j<Models_[i].size();j++){
            save_model_bin(fout_reg, Models_[i][j]);
        }
    }
    fout_reg.close();
}
void  LBFRegressor::ReadGlobalParam(ifstream& fin){
    fin >> global_params.bagging_overlap;
    fin >> global_params.max_numtrees;
    fin >> global_params.max_depth;
    fin >> global_params.max_numthreshs;
    fin >> global_params.landmark_num;
    fin >> global_params.initial_num;
    fin >> global_params.max_numstage;

    for (int i = 0; i< global_params.max_numstage; i++){
        fin >> global_params.max_radio_radius[i];
    }

    for (int i = 0; i < global_params.max_numstage; i++){
        fin >> global_params.max_numfeats[i];
    }
}

void LBFRegressor::ReadRegressor(ifstream& fin){
    mean_shape_ = Mat::zeros(global_params.landmark_num,2,CV_64FC1);
    for(int i = 0;i < global_params.landmark_num;i++){
        fin >> mean_shape_(i,0) >> mean_shape_(i,1);
    }
    ifstream fin_reg;
    fin_reg.open(modelPath + "/Regressor.model",ios::binary);
    for (int i=0; i < global_params.max_numstage; i++ ){
        RandomForest_[i].Read(fin);
        int num =0;
        fin >> num;
        Models_[i].resize(num);
        for (int j=0;j<num;j++){
            Models_[i][j]   = load_model_bin(fin_reg);
        }
    }
    fin_reg.close();
}


text:
package com.virdis

/**
  * Created by sandeep on 11/3/15.
  */
class TweetCleanUpSpec extends MySpec {

  def fixture = {
    new {
      val s1 = "I'm at Terminal de Integra\u00e7\u00e3o do Varadouro in Jo\u00e3o Pessoa, PB https:\\/\\/t.co\\/HOl34REL1a"
      val s2 = "Spark Summit East this week! #Spark #Apache"

    }
  }

  "TweetCleanUp" should "should remove unicode character" in {
    val f = fixture
    val result = "I'm at Terminal de Integrao do Varadouro in Joo Pessoa, PB https://t.co/HOl34REL1a"
    tweetCleaner.cleanAndProcessInput(f.s1) == result should be(true)
    tweetCleaner.cleanAndProcessInput(f.s1).length should be(result.length)
  }

  it should "handle ascii characters correctly" in {
    val f = fixture
    tweetCleaner.cleanAndProcessInput(f.s2) == f.s2 should be(true)
    tweetCleaner.cleanAndProcessInput(f.s2).length should be(f.s2.length)
  }

  it should "check for unicode characters" in {
    val f = fixture
    tweetCleaner.checkNonAsciiCharacters(f.s1) should be(true)
    tweetCleaner.checkNonAsciiCharacters(f.s2) should be(false)
  }

}


text:
package it.nerdammer.spash.shell.command;

import it.nerdammer.spash.shell.SpashSession;

/**
 * An abstract Spash command.
 *
 * @author Nicola Ferraro
 */
public interface Command {

    /**
     * Executes the command action.
     *
     * @param ctx the execution context
     * @return the associated {@code CommandResult}
     */
    CommandResult execute(ExecutionContext ctx);

}


text:
from __future__ import absolute_import

import sentry_teamwork

from django import forms
from django.utils.translation import ugettext_lazy as _
from requests.exceptions import RequestException
from sentry.plugins.base import JSONResponse
from sentry.plugins.bases.issue import IssuePlugin, NewIssueForm
from sentry.utils.http import absolute_uri

from .client import TeamworkClient

ISSUES_URL = 'https://github.com/getsentry/sentry-teamwork/issues'

class TeamworkSettingsForm(forms.Form):
    url = forms.URLField(
        label=_('Teamwork URL'),
        help_text=('i.e. http://sentry.teamwork.com'),
    )
    token = forms.CharField(label=_('Teamwork API Token'))

class TeamworkTaskForm(NewIssueForm):
    title = forms.CharField(
        label=_('Title'), max_length=200,
        widget=forms.TextInput(attrs={'class': 'span9'}))
    description = forms.CharField(
        label=_('Description'),
        widget=forms.Textarea(attrs={'class': 'span9'}))
    project = forms.ChoiceField(label=_('Project'), choices=())
    tasklist = forms.ChoiceField(label=_('Task List'), choices=())

    create_issue_template = 'sentry_teamwork/create_issue.html'

    def __init__(self, client, data=None, initial=None):
        super(TeamworkTaskForm, self).__init__(data=data, initial=initial)

        try:
            project_list = client.list_projects()
        except RequestException as e:
            raise forms.ValidationError(
                _('Error contacting Teamwork API: %s') % str(e))

        self.fields['project'].choices = [
            (str(i['id']), i['name']) for i in project_list
        ]
        self.fields['project'].widget.choices = self.fields['project'].choices

        if self.data.get('project'):
            try:
                tasklist_list = client.list_tasklists(data['project'])
            except RequestException as e:
                raise forms.ValidationError(
                    _('Error contacting Teamwork API: %s') % str(e))
            self.fields['tasklist'].choices = [
                (str(i['id']), i['name']) for i in tasklist_list
            ]
            self.fields['tasklist'].widget.choices = self.fields['tasklist'].choices

class TeamworkTaskPlugin(IssuePlugin):
    author = "Sentry Team"
    author_url = "https://github.com/getsentry/sentry-teamwork"
    title = _('Teamwork')
    description = _('Create Teamwork Tasks.')
    slug = 'teamwork'

    resource_links = [
        (_('Bug Tracker'), ISSUES_URL),
        (_('Source'), 'https://github.com/getsentry/sentry-teamwork'),
    ]

    conf_title = title
    conf_key = slug

    version = sentry_teamwork.VERSION
    project_conf_form = TeamworkSettingsForm

    new_issue_form = TeamworkTaskForm
    create_issue_template = 'sentry_teamwork/create_issue.html'

    def _get_group_description(self, request, group, event):
        """
        Return group description in markdown-compatible format.

        This overrides an internal method to IssuePlugin.
        """
        output = [
            absolute_uri(group.get_absolute_url()),
        ]
        body = self._get_group_body(request, group, event)
        if body:
            output.extend([
                '',
                '\n'.join('    ' + line for line in body.splitlines()),
            ])
        return '\n'.join(output)

    def is_configured(self, request, project, **kwargs):
        return all((
            self.get_option(key, project)
            for key in ('url', 'token')
        ))

    def get_client(self, project):
        return TeamworkClient(
            base_url=self.get_option('url', project),
            token=self.get_option('token', project),
        )

    def get_new_issue_form(self, request, group, event, **kwargs):
        """
        Return a Form for the "Create new issue" page.
        """
        return self.new_issue_form(
            client=self.get_client(group.project),
            data=request.POST or None,
            initial=self.get_initial_form_data(request, group, event),
        )

    def get_issue_url(self, group, issue_id, **kwargs):
        url = self.get_option('url', group.project)
        return '%s/tasks/%s' % (url.rstrip('/'), issue_id)

    def get_new_issue_title(self, **kwargs):
        return _('Create Teamwork Task')

    def create_issue(self, request, group, form_data, **kwargs):
        client = self.get_client(group.project)
        try:
            task_id = client.create_task(
                content=form_data['title'],
                description=form_data['description'],
                tasklist_id=form_data['tasklist'],
            )
        except RequestException as e:
            raise forms.ValidationError(
                _('Error creating Teamwork task: %s') % str(e))

        return task_id

    def view(self, request, group, **kwargs):
        op = request.GET.get('op')
        # TODO(dcramer): add caching
        if op == 'getTaskLists':
            project_id = request.GET.get('pid')
            if not project_id:
                return HttpResponse(status=400)

            client = self.get_client(group.project)
            task_list = client.list_tasklists(project_id)
            return JSONResponse([
                {'id': i['id'], 'text': i['name']} for i in task_list
            ])

        return super(TeamworkTaskPlugin, self).view(request, group, **kwargs)


text:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />
        </android.support.design.widget.AppBarLayout>

        <ProgressBar
            android:id="@+id/toolbar_progress_bar"
            style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginTop="?attr/actionBarSize"
            android:indeterminate="true"
            android:visibility="gone" />

        <FrameLayout
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize" />
    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>


text:
**means done**

# week 1

- **mike RStudio**

- **mike R refresher**

- **mike Installing Bioconductor and finding help**

- **rafa Exploratory data analysis**

# week 2

- **mike github**

- **rafa Reading microarray raw data**

- **rafa Microarray EDA**

- **mike Mapping algorithms and software**

- **mike NGS EDA**

- **mike Basic Bioconductor infrastructure: IRanges**

- **mike Basic Bioconductor infrastructure: GenomicRanges**

- **mike Basic Bioconductor infrastructure: ExpressionSet and SummarizedExperiment**

# week 3

- **rafa Monte carlo simulation**

- **rafa Permutation tests**

- **mike Expressing experimental design using R formula** ( add links to more help on formula the UCR manual & http://www.math.montana.edu/Rweb/Rnotes/node77.html )

- **mike Basic inference on microarray part I**

- **mike Basic inference on microarray part II**

# week 4

- **rafa Motivating normalization with EDA**

- **rafa Normalizing microarrays**

# week 5

- **mike Distances, clustering**

- **mike MDS, heatmaps**

- **mike cross-validation**

# week 6

- **rafa Combat, SVA in R**

- **mike PCA and SVD in R**

# week 7

- **mike Using the limma package**

- **mike Mapping features to genes**

- **mike Gene set testing**

# week 8

- rafa Systematic errors in NGS

- rafa Assigning probe locations to genes

- mike Visualizing NGS with Bioconductor, UCSC, IGV

- mike Making NGS read count table in Bioconductor

- mike SNPs and CNVs

- mike RNA-Seq

- rafa DNA methylation: arrays and NGS

- mike ChIP-Seq


text:
<?php

namespace backend\modules\coreengine;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'backend\modules\coreengine\controllers';

    // public $layout = 'admin';

    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
}


text:
rshell is a custom bash shell created for UCR's CS100 course on Software Construction.

##Dependencies
rshell requires the Boost library for C++ to be installed

If you are on Ubuntu, run `sudo apt-get install libboost-all-dev`

If you are on Mac OS X, I'd recomment using Homebrew.
Install Homebrew and use the command `brew install boost`

To manually install, the file can be found here: http://www.boost.org/users/download/

##Build and Run
hw0 is the current working build of the program
Any current branch progress is not tested nor confirmed to work as expected
```
$ git clone  https://github.com/kilenaitor/rshell.git
$ cd rshell
$ git checkout hw0
$ make
$ bin/rshell
```

##Limitations

- Need C++11 for it to properly compile
- Need the boost library for it to properly compile
- Host name is limited to 128 characters
- Does not detect triple connectors like `|||` or `&&&`, they're just interpreted as another command
- Will not prompt for more input if connector is the end. (e.g. `ls &&` just prints ls)
- Connectors cannot be touching other commands or parameters (e.g. `echo "this"|| echo "that"` will not work)
- cd command does not work
- Pressing up on the arrow key does not restore the previous command
- No navigating text input; Enters the literal keys for left, right, up, down, etc.
- `!*command*` does not execute the previous command
- No color output
- Does not allow aliases or general settings
- Does not support `<<<` redirection of raw strings
- Does not support custom file descriptors. e.g `ls 2> file.txt`

##Programs
###cp
- Copy files from one place to another
`cp <file1> <file2>`
###ls
- List files
- Three flags
    - `-l` for listing
    - `-a` for showing hidden files
    - `-R` for recursive search
- Flags can be combined in any order
- Colored output
###mv
- Move command
`mv <location1> <location2>`
###rm
- Remove command
`rm <file>`
- Recursive with `-r`
`rm -r <directory>`


text:
include_recipe "chef-bioinf-worker::numpy"
include_recipe "chef-bioinf-worker::haskell"

package "libfreetype6-dev"
package "libxft-dev"
package "gfortran"
package "libopenblas-dev"
package "liblapack-dev"

bash "install_qiime" do
  code "pip install qiime"
  not_if "#{File.exists?( "/usr/local/bin/print_qiime_config.py" )}"
  retries 1
end


text:
package uk.co.real_logic.sbe.xml;

import org.w3c.dom.Node;

import static uk.co.real_logic.sbe.xml.XmlSchemaParser.getAttributeValue;
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.getAttributeValueOrNull;

/**
 * An SBE type. One of encodedDataType, compositeType, enumType, or setType per the SBE spec.
 */
public abstract class Type
{
    private final String name;
    private final Presence presence;
    private final String description;
    private final String semanticType;

    private int offsetAttribute;

    /**
     * Construct a new Type from XML Schema. Called by subclasses to mostly set common fields
     *
     * @param node      from the XML Schema Parsing
     * @param givenName of this node, if null then the attributed name will be used.
     */
    public Type(final Node node, final String givenName)
    {
        if (null == givenName)
        {
            name = getAttributeValue(node, "name");
        }
        else
        {
            name = givenName;
        }
        presence = Presence.get(getAttributeValue(node, "presence", "required"));
        description = getAttributeValueOrNull(node, "description");
        semanticType = getAttributeValueOrNull(node, "semanticType");
        offsetAttribute = Integer.parseInt(getAttributeValue(node, "offset", "-1"));
    }

    /**
     * Construct a new Type from direct values.
     *
     * @param name         of the type
     * @param presence     of the type
     * @param description  of the type or null
     * @param semanticType of the type or null
     */
    public Type(final String name, final Presence presence, final String description, final String semanticType)
    {
        this.name = name;
        this.presence = presence;
        this.description = description;
        this.semanticType = semanticType;
        this.offsetAttribute = -1;
    }

    /**
     * Return the name of the type
     *
     * @return name of the Type
     */
    public String name()
    {
        return name;
    }

    /**
     * Return the presence of the type
     *
     * @return presence of the Type
     */
    public Presence presence()
    {
        return presence;
    }

    /**
     * The encodedLength (in octets) of the Type.
     * <p>
     * Overridden by subtypes. This returns 0 by default.
     *
     * @return encodedLength of the type in octets
     */
    public abstract int encodedLength();

    /**
     * The description of the Type (if set) or null
     *
     * @return description set by the type or null
     */
    public String description()
    {
        return description;
    }

    /**
     * The semanticType of the Type
     *
     * @return semanticType of the Type if set or null if not set
     */
    public String semanticType()
    {
        return semanticType;
    }

    public abstract boolean isVariableLength();

    /**
     * Return the offset attribute of the {@link Type} from the schema
     *
     * @return the offset attribute value or -1 to indicate not set by the schema
     */
    public int offsetAttribute()
    {
        return offsetAttribute;
    }

    /**
     * Set the offset attribute of the {@link Type} from the schema
     *
     * @param offsetAttribute to set
     */
    public void offsetAttribute(final int offsetAttribute)
    {
        this.offsetAttribute = offsetAttribute;
    }
}


text:
use std::collections::HashSet;
use std::path::{Component, Path, PathBuf};
use std::sync::{Mutex, RwLock, RwLockReadGuard};
use std::{fmt, fs, io};

use futures::future::{self, BoxFuture, Future};
use futures_cpupool::{self, CpuFuture, CpuPool};
use glob::Pattern;
use ignore::gitignore::{Gitignore, GitignoreBuilder};
use ignore;
use ordermap::OrderMap;
use tar;
use tempdir::TempDir;

use hash::{Fingerprint, WriterHasher};

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum Stat {
  Link(Link),
  Dir(Dir),
  File(File),
}

impl Stat {
  pub fn path(&self) -> &Path {
    match self {
      &Stat::Dir(Dir(ref p)) => p.as_path(),
      &Stat::File(File(ref p)) => p.as_path(),
      &Stat::Link(Link(ref p)) => p.as_path(),
    }
  }
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Link(pub PathBuf);

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Dir(pub PathBuf);

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct File(pub PathBuf);

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum PathStat {
  Dir {
    // The symbolic name of some filesystem Path, which is context specific.
    path: PathBuf,
    // The canonical Stat that underlies the Path.
    stat: Dir,
  },
  File {
    // The symbolic name of some filesystem Path, which is context specific.
    path: PathBuf,
    // The canonical Stat that underlies the Path.
    stat: File,
  }
}

impl PathStat {
  fn dir(path: PathBuf, stat: Dir) -> PathStat {
    PathStat::Dir {
      path: path,
      stat: stat,
    }
  }

  fn file(path: PathBuf, stat: File) -> PathStat {
    PathStat::File {
      path: path,
      stat: stat,
    }
  }

  pub fn path(&self) -> &Path {
    match self {
      &PathStat::Dir { ref path, .. } => path.as_path(),
      &PathStat::File { ref path, .. } => path.as_path(),
    }
  }
}

lazy_static! {
  static ref PARENT_DIR: &'static str = "..";

  static ref SINGLE_STAR_GLOB: Pattern = Pattern::new("*").unwrap();

  static ref DOUBLE_STAR: &'static str = "**";
  static ref DOUBLE_STAR_GLOB: Pattern = Pattern::new("**").unwrap();
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum PathGlob {
  Wildcard {
    canonical_dir: Dir,
    symbolic_path: PathBuf,
    wildcard: Pattern,
  },
  DirWildcard {
    canonical_dir: Dir,
    symbolic_path: PathBuf,
    wildcard: Pattern,
    remainder: Vec<Pattern>,
  },
}

impl PathGlob {
  fn wildcard(canonical_dir: Dir, symbolic_path: PathBuf, wildcard: Pattern) -> PathGlob {
    PathGlob::Wildcard {
      canonical_dir: canonical_dir,
      symbolic_path: symbolic_path,
      wildcard: wildcard,
    }
  }

  fn dir_wildcard(canonical_dir: Dir, symbolic_path: PathBuf, wildcard: Pattern, remainder: Vec<Pattern>) -> PathGlob {
    PathGlob::DirWildcard {
      canonical_dir: canonical_dir,
      symbolic_path: symbolic_path,
      wildcard: wildcard,
      remainder: remainder,
    }
  }

  pub fn create(filespecs: &[String]) -> Result<Vec<PathGlob>, String> {
    let mut path_globs = Vec::new();
    for filespec in filespecs {
      let canonical_dir = Dir(PathBuf::new());
      let symbolic_path = PathBuf::new();
      path_globs.extend(PathGlob::parse(canonical_dir, symbolic_path, filespec)?);
    }
    Ok(path_globs)
  }

  ///
  /// Given a filespec String relative to a canonical Dir and path, split it into path components
  /// while eliminating consecutive '**'s (to avoid repetitive traversing), and parse it to a
  /// series of PathGlob objects.
  ///
  fn parse(canonical_dir: Dir, symbolic_path: PathBuf, filespec: &str) -> Result<Vec<PathGlob>, String> {
    let mut parts = Vec::new();
    let mut prev_was_doublestar = false;
    for component in Path::new(filespec).components() {
      let part =
        match component {
          Component::Prefix(..) | Component::RootDir =>
            return Err(format!("Absolute paths not supported: {:?}", filespec)),
          Component::CurDir =>
            continue,
          c => c.as_os_str(),
        };

      // Ignore repeated doublestar instances.
      let cur_is_doublestar = *DOUBLE_STAR == part;
      if prev_was_doublestar && cur_is_doublestar {
        continue;
      }
      prev_was_doublestar = cur_is_doublestar;

      // NB: Because the filespec is a String input, calls to `to_str_lossy` are not lossy; the
      // use of `Path` is strictly for os-independent Path parsing.
      parts.push(
        Pattern::new(&part.to_string_lossy())
          .map_err(|e| format!("Could not parse {:?} as a glob: {:?}", filespec, e))?
      );
    }

    PathGlob::parse_globs(canonical_dir, symbolic_path, &parts)
  }

  ///
  /// Given a filespec as Patterns, create a series of PathGlob objects.
  ///
  fn parse_globs(
    canonical_dir: Dir,
    symbolic_path: PathBuf,
    parts: &[Pattern]
  ) -> Result<Vec<PathGlob>, String> {
    if parts.is_empty() {
      Ok(vec![])
    } else if *DOUBLE_STAR == parts[0].as_str() {
      if parts.len() == 1 {
        // Per https://git-scm.com/docs/gitignore:
        //  "A trailing '/**' matches everything inside. For example, 'abc/**' matches all files inside
        //   directory "abc", relative to the location of the .gitignore file, with infinite depth."
        return Ok(
          vec![
            PathGlob::dir_wildcard(
              canonical_dir.clone(),
              symbolic_path.clone(),
              SINGLE_STAR_GLOB.clone(),
              vec![DOUBLE_STAR_GLOB.clone()]
            ),
            PathGlob::wildcard(canonical_dir, symbolic_path, SINGLE_STAR_GLOB.clone()),
          ]
        );
      }

      // There is a double-wildcard in a dirname of the path: double wildcards are recursive,
      // so there are two remainder possibilities: one with the double wildcard included, and the
      // other without.
      let pathglob_with_doublestar =
        PathGlob::dir_wildcard(
          canonical_dir.clone(),
          symbolic_path.clone(),
          SINGLE_STAR_GLOB.clone(),
          parts[0..].to_vec()
        );
      let pathglob_no_doublestar =
        if parts.len() == 2 {
          PathGlob::wildcard(canonical_dir, symbolic_path, parts[1].clone())
        } else {
          PathGlob::dir_wildcard(canonical_dir, symbolic_path, parts[1].clone(), parts[2..].to_vec())
        };
      Ok(vec![pathglob_with_doublestar, pathglob_no_doublestar])
    } else if *PARENT_DIR == parts[0].as_str() {
      // A request for the parent of `canonical_dir`: since we've already expanded the directory
      // to make it canonical, we can safely drop it directly and recurse without this component.
      // The resulting symbolic path will continue to contain a literal `..`.
      let mut canonical_dir_parent = canonical_dir;
      let mut symbolic_path_parent = symbolic_path;
      if !canonical_dir_parent.0.pop() {
        return Err(format!("Globs may not traverse outside the root: {:?}", parts));
      }
      symbolic_path_parent.push(Path::new(*PARENT_DIR));
      PathGlob::parse_globs(canonical_dir_parent, symbolic_path_parent, &parts[1..])
    } else if parts.len() == 1 {
      // This is the path basename.
      Ok(
        vec![
          PathGlob::wildcard(canonical_dir, symbolic_path, parts[0].clone())
        ]
      )
    } else {
      // This is a path dirname.
      Ok(
        vec![
          PathGlob::dir_wildcard(canonical_dir, symbolic_path, parts[0].clone(), parts[1..].to_vec())
        ]
      )
    }
  }
}

#[derive(Debug)]
pub struct PathGlobs {
  include: Vec<PathGlob>,
  exclude: Vec<PathGlob>,
}

impl PathGlobs {
  pub fn create(include: &[String], exclude: &[String]) -> Result<PathGlobs, String> {
    Ok(
      PathGlobs {
        include: PathGlob::create(include)?,
        exclude: PathGlob::create(exclude)?,
      }
    )
  }
}

#[derive(Debug)]
struct PathGlobsExpansion<T: Sized> {
  context: T,
  // Globs that have yet to be expanded, in order.
  todo: Vec<PathGlob>,
  // Globs that have already been expanded.
  completed: HashSet<PathGlob>,
  // Unique Paths that have been matched, in order.
  outputs: OrderMap<PathStat, ()>,
}

pub struct PosixFS {
  build_root: Dir,
  // The pool needs to be reinitialized after a fork, so it is protected by a lock.
  pool: RwLock<Option<CpuPool>>,
  ignore: Gitignore,
}

impl PosixFS {
  pub fn new(
    build_root: PathBuf,
    ignore_patterns: Vec<String>,
  ) -> Result<PosixFS, String> {
    let canonical_build_root =
      build_root.canonicalize().and_then(|canonical|
        canonical.metadata().and_then(|metadata|
          if metadata.is_dir() {
            Ok(Dir(canonical))
          } else {
            Err(io::Error::new(io::ErrorKind::InvalidInput, "Not a directory."))
          }
        )
      )
      .map_err(|e| format!("Could not canonicalize build root {:?}: {:?}", build_root, e))?;

    let ignore =
      PosixFS::create_ignore(&canonical_build_root, &ignore_patterns)
        .map_err(|e|
          format!("Could not parse build ignore inputs {:?}: {:?}", ignore_patterns, e)
        )?;
    Ok(
      PosixFS {
        build_root: canonical_build_root,
        pool: RwLock::new(None),
        ignore: ignore,
      }
    )
  }

  fn create_pool() -> CpuPool {
    futures_cpupool::Builder::new()
      .name_prefix("vfs-")
      .create()
  }

  fn create_ignore(root: &Dir, patterns: &Vec<String>) -> Result<Gitignore, ignore::Error> {
    let mut ignore_builder = GitignoreBuilder::new(root.0.as_path());
    for pattern in patterns {
      ignore_builder.add_line(None, pattern.as_str())?;
    }
    ignore_builder
      .build()
  }

  fn scandir_sync(dir: Dir, dir_abs: PathBuf) -> Result<Vec<Stat>, io::Error> {
    let mut stats = Vec::new();
    for dir_entry_res in dir_abs.read_dir()? {
      let dir_entry = dir_entry_res?;
      let path = dir.0.join(dir_entry.file_name());
      let file_type = dir_entry.file_type()?;
      if file_type.is_dir() {
        stats.push(Stat::Dir(Dir(path)));
      } else if file_type.is_file() {
        stats.push(Stat::File(File(path)));
      } else if file_type.is_symlink() {
        stats.push(Stat::Link(Link(path)));
      }
      // Else: ignore.
    }
    stats.sort_by(|s1, s2| s1.path().cmp(s2.path()));
    Ok(stats)
  }

  fn pool(&self) -> RwLockReadGuard<Option<CpuPool>> {
    {
      let pool = self.pool.read().unwrap();
      if pool.is_some() {
        return pool;
      }
    }
    // If we get to here, the pool is None and needs re-initializing.
    {
      let mut pool = self.pool.write().unwrap();
      if pool.is_none() {
        *pool = Some(PosixFS::create_pool());
      }
    }
    self.pool.read().unwrap()
  }

  pub fn pre_fork(&self) {
    let mut pool = self.pool.write().unwrap();
    *pool = None;
  }

  pub fn ignore<P: AsRef<Path>>(&self, path: P, is_dir: bool) -> bool {
    match self.ignore.matched(path, is_dir) {
      ignore::Match::None | ignore::Match::Whitelist(_) => false,
      ignore::Match::Ignore(_) => true,
    }
  }

  pub fn read_link(&self, link: &Link) -> BoxFuture<PathBuf, io::Error> {
    let link_parent = link.0.parent().map(|p| p.to_owned());
    let link_abs = self.build_root.0.join(link.0.as_path()).to_owned();
    let pool = self.pool();
    pool.as_ref().expect("Uninitialized CpuPool!")
      .spawn_fn(move || {
        link_abs
          .read_link()
          .and_then(|path_buf| {
            if path_buf.is_absolute() {
              Err(
                io::Error::new(
                  io::ErrorKind::InvalidData, format!("Absolute symlink: {:?}", link_abs)
                )
              )
            } else {
              link_parent
                .map(|parent| parent.join(path_buf))
                .ok_or_else(|| {
                  io::Error::new(
                    io::ErrorKind::InvalidData, format!("Symlink without a parent?: {:?}", link_abs)
                  )
                })
            }
          })
      })
      .boxed()
  }

  pub fn scandir(&self, dir: &Dir) -> BoxFuture<Vec<Stat>, io::Error> {
    let dir = dir.to_owned();
    let dir_abs = self.build_root.0.join(dir.0.as_path());
    let pool = self.pool();
    pool.as_ref().expect("Uninitialized CpuPool!")
      .spawn_fn(move || {
        PosixFS::scandir_sync(dir, dir_abs)
      })
      .boxed()
  }
}

///
/// A context for filesystem operations parameterized on an error type 'E'.
///
pub trait VFS<E: Send + Sync + 'static> : Clone + Send + Sync + 'static {
  fn read_link(&self, link: Link) -> BoxFuture<PathBuf, E>;
  fn scandir(&self, dir: Dir) -> BoxFuture<Vec<Stat>, E>;
  fn ignore<P: AsRef<Path>>(&self, path: P, is_dir: bool) -> bool;
  fn mk_error(msg: &str) -> E;

  ///
  /// Canonicalize the Link for the given Path to an underlying File or Dir. May result
  /// in None if the PathStat represents a broken Link.
  ///
  /// Skips ignored paths both before and after expansion.
  ///
  /// TODO: Should handle symlink loops (which would exhibit as an infinite loop in expand_multi).
  ///
  fn canonicalize(&self, symbolic_path: PathBuf, link: Link) -> BoxFuture<Option<PathStat>, E> {
    // Read the link, which may result in PathGlob(s) that match 0 or 1 Path.
    let context = self.clone();
    self.read_link(link)
      .map(|dest_path| {
        // If the link destination can't be parsed as PathGlob(s), it is broken.
        dest_path.to_str()
          .and_then(|dest_str| {
            let escaped = Pattern::escape(dest_str);
            PathGlob::create(&[escaped]).ok()
          })
          .unwrap_or_else(|| vec![])
      })
      .and_then(move |link_globs| {
        context.expand_multi(link_globs)
      })
      .map(|mut path_stats| {
        // Since we've escaped any globs in the parsed path, expect either 0 or 1 destination.
        path_stats.pop().map(|ps| match ps {
          PathStat::Dir { stat, .. } => PathStat::dir(symbolic_path, stat),
          PathStat::File { stat, .. } => PathStat::file(symbolic_path, stat),
        })
      })
      .boxed()
  }

  fn directory_listing(&self, canonical_dir: Dir, symbolic_path: PathBuf, wildcard: Pattern) -> BoxFuture<Vec<PathStat>, E> {
    // List the directory.
    let context = self.clone();
    self.scandir(canonical_dir)
      .and_then(move |dir_listing| {
        // Match any relevant Stats, and join them into PathStats.
        future::join_all(
          dir_listing.into_iter()
            .filter(|stat| {
              // Match relevant filenames.
              stat.path().file_name()
                .map(|file_name| wildcard.matches_path(Path::new(file_name)))
                .unwrap_or(false)
            })
            .filter_map(|stat| {
              // Append matched filenames.
              stat.path().file_name()
                .map(|file_name| {
                  symbolic_path.join(file_name)
                })
                .map(|symbolic_stat_path| {
                  (symbolic_stat_path, stat)
                })
            })
            .map(|(stat_symbolic_path, stat)| {
              // Canonicalize matched PathStats, and filter ignored paths. Note that we ignore
              // links both before and after expansion.
              match stat {
                Stat::Link(l) => {
                  if context.ignore(l.0.as_path(), false) {
                    future::ok(None).boxed()
                  } else {
                    context.canonicalize(stat_symbolic_path, l)
                  }
                },
                Stat::Dir(d) => {
                  let res =
                    if context.ignore(d.0.as_path(), true) {
                      None
                    } else {
                      Some(PathStat::dir(stat_symbolic_path.to_owned(), d))
                    };
                  future::ok(res).boxed()
                },
                Stat::File(f) => {
                  let res =
                    if context.ignore(f.0.as_path(), false) {
                      None
                    } else {
                      Some(PathStat::file(stat_symbolic_path.to_owned(), f))
                    };
                  future::ok(res).boxed()
                },
              }
            })
            .collect::<Vec<_>>()
        )
      })
      .map(|path_stats| {
        // See the TODO above.
        path_stats.into_iter().filter_map(|pso| pso).collect()
      })
      .boxed()
  }

  ///
  /// Recursively expands PathGlobs into PathStats while applying excludes.
  ///
  /// TODO: Eventually, it would be nice to be able to apply excludes as we go, to
  /// avoid walking into directories that aren't relevant.
  ///
  fn expand(&self, path_globs: PathGlobs) -> BoxFuture<Vec<PathStat>, E> {
    self.expand_multi(path_globs.include).join(self.expand_multi(path_globs.exclude))
      .map(|(include, exclude)| {
        // Exclude matched paths.
        let exclude_set: HashSet<_> = exclude.into_iter().collect();
        include.into_iter().filter(|i| !exclude_set.contains(i)).collect()
      })
      .boxed()
  }

  ///
  /// Recursively expands PathGlobs into PathStats.
  ///
  fn expand_multi(&self, path_globs: Vec<PathGlob>) -> BoxFuture<Vec<PathStat>, E> {
    if path_globs.is_empty() {
      return future::ok(vec![]).boxed();
    }

    let init =
      PathGlobsExpansion {
        context: self.clone(),
        todo: path_globs,
        completed: HashSet::default(),
        outputs: OrderMap::default()
      };
    future::loop_fn(init, |mut expansion| {
      // Request the expansion of all outstanding PathGlobs as a batch.
      let round =
        future::join_all({
          let context = &expansion.context;
          expansion.todo.drain(..)
            .map(|path_glob| context.expand_single(path_glob))
            .collect::<Vec<_>>()
        });
      round
        .map(move |paths_and_globs| {
          // Collect distinct new PathStats and PathGlobs
          for (paths, globs) in paths_and_globs.into_iter() {
            expansion.outputs.extend(paths.into_iter().map(|p| (p, ())));
            let completed = &mut expansion.completed;
            expansion.todo.extend(
              globs.into_iter()
                .filter(|pg| completed.insert(pg.clone()))
            );
          }

          // If there were any new PathGlobs, continue the expansion.
          if expansion.todo.is_empty() {
            future::Loop::Break(expansion)
          } else {
            future::Loop::Continue(expansion)
          }
        })
    })
    .map(|expansion| {
      assert!(
        expansion.todo.is_empty(),
        "Loop shouldn't have exited with work to do: {:?}",
        expansion.todo,
      );
      // Finally, capture the resulting PathStats from the expansion.
      expansion.outputs.into_iter().map(|(k, _)| k).collect()
    })
    .boxed()
  }

  ///
  /// Apply a PathGlob, returning PathStats and additional PathGlobs that are needed for the
  /// expansion.
  ///
  fn expand_single(&self, path_glob: PathGlob) -> BoxFuture<(Vec<PathStat>, Vec<PathGlob>), E> {
    match path_glob {
      PathGlob::Wildcard { canonical_dir, symbolic_path, wildcard } =>
        // Filter directory listing to return PathStats, with no continuation.
        self.directory_listing(canonical_dir, symbolic_path, wildcard)
          .map(|path_stats| (path_stats, vec![]))
          .boxed(),
      PathGlob::DirWildcard { canonical_dir, symbolic_path, wildcard, remainder } =>
        // Filter directory listing and request additional PathGlobs for matched Dirs.
        self.directory_listing(canonical_dir, symbolic_path, wildcard)
          .and_then(move |path_stats| {
            path_stats.into_iter()
              .filter_map(|ps| match ps {
                PathStat::Dir { path, stat } =>
                  Some(
                    PathGlob::parse_globs(stat, path, &remainder)
                      .map_err(|e| Self::mk_error(e.as_str()))
                  ),
                PathStat::File { .. } => None,
              })
              .collect::<Result<Vec<_>, E>>()
          })
          .map(|path_globs| {
            let flattened =
              path_globs.into_iter()
                .flat_map(|path_globs| path_globs.into_iter())
                .collect();
            (vec![], flattened)
          })
          .boxed(),
    }
  }
}

pub struct FileContent {
  pub path: PathBuf,
  pub content: Vec<u8>,
}

#[derive(Clone)]
pub struct Snapshot {
  pub fingerprint: Fingerprint,
  pub path_stats: Vec<PathStat>,
}

impl fmt::Debug for Snapshot {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    write!(f, "Snapshot({}, entries={})", self.fingerprint.to_hex(), self.path_stats.len())
  }
}

// Like std::fs::create_dir_all, except handles concurrent calls among multiple
// threads or processes. Originally lifted from rustc.
fn safe_create_dir_all_ioerror(path: &Path) -> Result<(), io::Error> {
  match fs::create_dir(path) {
    Ok(()) => return Ok(()),
    Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => return Ok(()),
    Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
    Err(e) => return Err(e),
  }
  match path.parent() {
    Some(p) => try!(safe_create_dir_all_ioerror(p)),
    None => return Ok(()),
  }
  match fs::create_dir(path) {
    Ok(()) => Ok(()),
    Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
    Err(e) => Err(e),
  }
}

fn safe_create_dir_all(path: &Path) -> Result<(), String> {
  safe_create_dir_all_ioerror(path).map_err(|e| format!("Failed to create dir {:?} due to {:?}", path, e))
}

fn safe_create_tmpdir_in(base_dir: &Path, prefix: &str) -> Result<TempDir, String> {
  safe_create_dir_all(&base_dir)?;
  Ok(
    TempDir::new_in(&base_dir, prefix)
      .map_err(|e| format!("Failed to create tempdir {:?} due to {:?}", base_dir, e))?
  )
}

///
/// A facade for the snapshot directory, which lives under the pants workdir.
///
pub struct Snapshots {
  snapshots_dir: PathBuf,
  snapshots_generator: Mutex<(TempDir, usize)>,
}

impl Snapshots {
  pub fn new(snapshots_dir: PathBuf) -> Result<Snapshots, String> {
    let snapshots_tmpdir = safe_create_tmpdir_in(&snapshots_dir, ".tmp")?;

    Ok(
      Snapshots {
        snapshots_dir: snapshots_dir,
        snapshots_generator: Mutex::new((snapshots_tmpdir, 0)),
      }
    )
  }

  pub fn snapshot_path(&self) -> &Path {
    self.snapshots_dir.as_path()
  }

  fn next_temp_path(&self) -> Result<PathBuf, String> {
    let mut gen = self.snapshots_generator.lock().unwrap();
    gen.1 += 1;

    // N.B. Sometimes, in e.g. a `./pants clean-all test ...` the snapshot tempdir created at the
    // beginning of a run can be removed out from under us by e.g. the `clean-all` task. Here, we
    // we double check existence of the `TempDir`'s path when the path is accessed and replace if
    // necessary.
    if !gen.0.path().exists() {
      gen.0 = safe_create_tmpdir_in(&self.snapshots_dir, ".tmp")?;
    }

    Ok(
      gen.0.path().join(format!("{}.tmp", gen.1))
    )
  }

  ///
  /// A non-canonical (does not expand symlinks) in-memory form of normalize. Used to collapse
  /// parent and cur components, which are legal in symbolic paths in PathStats, but not in
  /// Tar files.
  ///
  fn normalize(path: &Path) -> Result<PathBuf, String> {
    let mut res = PathBuf::new();
    for component in path.components() {
      match component {
        Component::Prefix(..) | Component::RootDir =>
          return Err(format!("Absolute paths not supported: {:?}", path)),
        Component::CurDir =>
          continue,
        Component::ParentDir => {
          // Pop the previous component.
          if !res.pop() {
            return Err(format!("Globs may not traverse outside the root: {:?}", path));
          } else {
            continue
          }
        },
        Component::Normal(p) =>
          res.push(p),
      }
    }
    Ok(res)
  }

  ///
  /// Create a tar file on the given Write instance containing the given paths, or
  /// return an error string.
  ///
  fn tar_create<W: io::Write>(
    dest: W,
    paths: &Vec<PathStat>,
    relative_to: &Dir
  ) -> Result<W, String> {
    let mut tar_builder = tar::Builder::new(dest);
    tar_builder.mode(tar::HeaderMode::Deterministic);
    for path_stat in paths {
      // Append the PathStat using the symbolic name and underlying stat.
      let append_res =
        match path_stat {
          &PathStat::File { ref path, ref stat } => {
            let normalized = Snapshots::normalize(path)?;
            let mut input =
              fs::File::open(relative_to.0.join(stat.0.as_path()))
                .map_err(|e| format!("Failed to open {:?}: {:?}", path_stat, e))?;
            tar_builder.append_file(normalized, &mut input)
          },
          &PathStat::Dir { ref path, ref stat } => {
            let normalized = Snapshots::normalize(path)?;
            tar_builder.append_dir(normalized, relative_to.0.join(stat.0.as_path()))
          },
        };
      append_res
        .map_err(|e| format!("Failed to tar {:?}: {:?}", path_stat, e))?;
    }

    // Finish the tar file, returning ownership of the stream to the caller.
    Ok(
      tar_builder.into_inner()
        .map_err(|e| format!("Failed to finalize snapshot tar: {:?}", e))?
    )
  }

  ///
  /// Create a tar file at the given dest Path containing the given paths, while
  /// fingerprinting the written stream.
  ///
  fn tar_create_fingerprinted(
    dest: &Path,
    paths: &Vec<PathStat>,
    relative_to: &Dir
  ) -> Result<Fingerprint, String> {
    // Wrap buffering around a fingerprinted stream above a File.
    let stream =
      io::BufWriter::new(
        WriterHasher::new(
          fs::File::create(dest)
            .map_err(|e| format!("Failed to create destination file: {:?}", e))?
        )
      );

    // Then append the tar to the stream, and retrieve the Fingerprint to flush all writers.
    Ok(
      Snapshots::tar_create(stream, paths, relative_to)?
        .into_inner()
        .map_err(|e| format!("Failed to flush to {:?}: {:?}", dest, e.error()))?
        .finish()
    )
  }

  ///
  /// Attempts to rename src to dst, and _succeeds_ if dst already exists. This is safe in
  /// the case of Snapshots because the destination path is unique to its content.
  ///
  fn finalize(temp_path: &Path, dest_path: &Path) -> Result<(), String> {
    if dest_path.is_file() {
      // The Snapshot has already been created.
      fs::remove_file(temp_path).unwrap_or(());
      Ok(())
    } else {
      let dest_dir = dest_path.parent().expect("All snapshot paths must have parent directories.");
      safe_create_dir_all(dest_dir)?;
      match fs::rename(temp_path, dest_path) {
        Ok(_) => Ok(()),
        Err(_) if dest_path.is_file() => Ok(()),
        Err(e) => Err(format!("Failed to finalize snapshot at {:?}: {:?}", dest_path, e))
      }
    }
  }

  fn path_for(&self, fingerprint: &Fingerprint) -> PathBuf {
    Snapshots::path_under_for(self.snapshot_path(), fingerprint)
  }

  fn path_under_for(path: &Path, fingerprint: &Fingerprint) -> PathBuf {
    let hex = fingerprint.to_hex();
    path.join(&hex[0..2]).join(&hex[2..4]).join(format!("{}.tar", hex))
  }

  ///
  /// Creates a Snapshot for the given paths under the given VFS.
  ///
  pub fn create(&self, fs: &PosixFS, paths: Vec<PathStat>) -> CpuFuture<Snapshot, String> {
    let dest_dir = self.snapshot_path().to_owned();
    let build_root = fs.build_root.clone();
    let temp_path = self.next_temp_path().expect("Couldn't get the next temp path.");

    let pool = fs.pool();
    pool.as_ref().expect("Uninitialized CpuPool!")
      .spawn_fn(move || {
        // Write the tar deterministically to a temporary file while fingerprinting.
        let fingerprint =
          Snapshots::tar_create_fingerprinted(temp_path.as_path(), &paths, &build_root)?;

        // Rename to the final path if it does not already exist.
        Snapshots::finalize(
          temp_path.as_path(),
          Snapshots::path_under_for(&dest_dir, &fingerprint).as_path()
        )?;

        Ok(
          Snapshot {
           fingerprint: fingerprint,
            path_stats: paths,
          }
        )
      })
  }

  fn contents_for_sync(snapshot: Snapshot, path: PathBuf) -> Result<Vec<FileContent>, io::Error> {
    let mut archive = fs::File::open(path).map(|f| tar::Archive::new(f))?;

    // Zip the in-memory Snapshot to the on disk representation, validating as we go.
    let mut files_content = Vec::new();
    for (entry_res, path_stat) in archive.entries()?.zip(snapshot.path_stats.into_iter()) {
      let mut entry = entry_res?;
      if entry.header().entry_type() == tar::EntryType::file() {
        let path =
          match path_stat {
            PathStat::File { path, .. } => path,
            PathStat::Dir { .. } => panic!("Snapshot contents changed after storage."),
          };
        let mut content = Vec::new();
        io::Read::read_to_end(&mut entry, &mut content)?;
        files_content.push(
          FileContent {
            path: path,
            content: content,
          }
        );
      }
    }
    Ok(files_content)
  }

  pub fn contents_for(&self, fs: &PosixFS, snapshot: Snapshot) -> CpuFuture<Vec<FileContent>, String> {
    let archive_path = self.path_for(&snapshot.fingerprint);
    let pool = fs.pool();
    pool.as_ref().expect("Uninitialized CpuPool!")
      .spawn_fn(move || {
        let snapshot_str = format!("{:?}", snapshot);
        Snapshots::contents_for_sync(snapshot, archive_path)
          .map_err(|e| format!("Failed to open Snapshot {}: {:?}", snapshot_str, e))
      })
  }
}


text:
$: << '../'

require 'OpenNebula'
require 'helpers/MockClient'

module OpenNebula

    describe "VirtualMachinePool using NOKOGIRI" do
        before(:all) do
            NOKOGIRI=true

            client = MockClient.new()
            @vm_pool = VirtualMachinePool.new(client)
        end

        it "should update the VM_POOL info" do
            rc = @vm_pool.info()
            rc.nil?.should eql(true)
        end

        it "should iterate the VM_POOL elements and get info from them using to_hash" do
            vm_pool = @vm_pool.to_hash

            vm_pool['VM_POOL']['VM'].each{ |vm|
                if vm['ID'] == 6
                    vm.name.should eql('vm-example')
                    vm.state.should eql(3)
                    vm.state_str.should eql('ACTIVE')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY']['HOSTNAME'].should eql('dummyhost')
                    vm['HISTORY']['STIME'].should eql('1277375186')
                    vm['HISTORY']['REASON'].should eql('0')
                elsif vm['ID'] == 8
                    vm.name.should eql('vmext')
                    vm.state.should eql(4)
                    vm.state_str.should eql('STOPPED')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY']['HOSTNAME'].should eql('thost')
                    vm['HISTORY']['STIME'].should eql('1277377556')
                    vm['HISTORY']['REASON'].should eql('0')
                end
            }
        end

        it "should iterate the VM_POOL elements and get info from them" do
            rc = @vm_pool.each{ |vm|
                vm.class.to_s.should eql("OpenNebula::VirtualMachine")
                if vm.id == 6
                    vm.name.should eql('vm-example')
                    vm.state.should eql(3)
                    vm.state_str.should eql('ACTIVE')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY/HOSTNAME'].should eql('dummyhost')
                    vm['HISTORY/STIME'].should eql('1277375186')
                    vm['HISTORY/REASON'].should eql('0')
                elsif vm.id == 8
                    vm.name.should eql('vmext')
                    vm.state.should eql(4)
                    vm.state_str.should eql('STOPPED')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY/HOSTNAME'].should eql('thost')
                    vm['HISTORY/STIME'].should eql('1277377556')
                    vm['HISTORY/REASON'].should eql('0')
                end
            }
        end
    end

    describe "VirtualMachinePool using REXML" do
        before(:all) do
            NOKOGIRI=false

            client = MockClient.new()
            @vm_pool = VirtualMachinePool.new(client)
        end

        it "should update the VM_POOL info" do
            rc = @vm_pool.info()
            rc.nil?.should eql(true)
        end

        it "should iterate the VM_POOL elements and get info from them" do
            rc = @vm_pool.each{ |vm|
                vm.class.to_s.should eql("OpenNebula::VirtualMachine")
                if vm.id == 6
                    vm.name.should eql('vm-example')
                    vm.state.should eql(3)
                    vm.state_str.should eql('ACTIVE')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY/HOSTNAME'].should eql('dummyhost')
                    vm['HISTORY/STIME'].should eql('1277375186')
                    vm['HISTORY/REASON'].should eql('0')
                elsif vm.id == 8
                    vm.name.should eql('vmext')
                    vm.state.should eql(4)
                    vm.state_str.should eql('STOPPED')
                    vm['UID'].should eql('0')
                    vm['USERNAME'].should eql('oneadmin')
                    vm['LAST_POLL'].should eql('1277910006')
                    vm['HISTORY/HOSTNAME'].should eql('thost')
                    vm['HISTORY/STIME'].should eql('1277377556')
                    vm['HISTORY/REASON'].should eql('0')
                end
            }
        end
    end
end


text:
package edu.gemini.obslog.TextExport.support;

import edu.gemini.obslog.config.model.OlLogItem;
import edu.gemini.obslog.obslog.ConfigMap;
import edu.gemini.obslog.obslog.ConfigMapUtil;
import edu.gemini.obslog.obslog.IObservingLogSegment;

import java.util.List;
import java.util.Map;

/**
 * Gemini Observatory/AURA
 * $Id: InstrumentTextSegmentExporter.java,v 1.2 2006/12/05 14:56:16 gillies Exp $
 */
public class InstrumentTextSegmentExporter extends AbstractDatasetExporterSupport implements ITextExporter {
    static protected final String OBSERVATION_ID_PROPERTY_NAME = ConfigMapUtil.OBSLOG_OBSERVATIONID_ITEM_NAME;
    static protected final String DATASETCOMMENT_PROPERTY_NAME = ConfigMapUtil.OBSLOG_DATASETCOMMENTS_ITEM_NAME;

    // When set, only look for observations from  this program
    private String _thisProgramOnly;

    public InstrumentTextSegmentExporter(IObservingLogSegment segment) {
        super(segment);
    }

    public InstrumentTextSegmentExporter(IObservingLogSegment segment, String programID) {
        super(segment);
        _thisProgramOnly = programID;
    }

    public static ITextExporterFactory FACTORY = new ITextExporterFactory() {
        public ITextExporter create(IObservingLogSegment segment) {
            return new InstrumentTextSegmentExporter(segment);
        }
    };

    protected void _setupColumns() {
        Map<String, ColumnInfo> columns = _getColumnInfoMap();

        // For weather, special case the time info
        OlLogItem logItem = _lookupColumnInfo(OBSERVATION_ID_PROPERTY_NAME);
        ColumnInfo cinfo = new ColumnInfo(logItem);
        columns.put(logItem.getProperty(), cinfo);
    }

    private void _printComment(StringBuilder sb, ConfigMap row) {
        ColumnInfo obsIDinfo = _getColumnInfoMap().get(OBSERVATION_ID_PROPERTY_NAME);
        // Could be null for segments like weather
        if (obsIDinfo == null) return;

        String observationID = row.sget(OBSERVATION_ID_PROPERTY_NAME);
        String comment = row.sget(COMMENT_PROPERTY_NAME);

        //String[] lines = _splitComment(comment);
        //LOG.info("Length is: " + lines.length);
        _printJustifiedMultilineComment(sb, obsIDinfo.getMaxColumnWidth(), observationID, comment);
    }

    // Check to make the text a little clearer
    private boolean _oneProgramOnly() {
        return _thisProgramOnly != null;
    }
    private boolean _useThisRow(ConfigMap rowMap) {
        String observationID = rowMap.sget(OBSERVATION_ID_PROPERTY_NAME);
        return observationID.startsWith(_thisProgramOnly);
    }

    // This goes through all the rows in the segment checking to see if an observation matches the sample observation
    private boolean _inThisSegment(List<ConfigMap> rowMaps) {
        for (ConfigMap rowMap : rowMaps) {
            if (_useThisRow(rowMap)) return true;
        }
        return false;
    }

    private void _printRows(StringBuilder sb, List<ConfigMap> rowMaps) {

        int size = rowMaps.size();
        if (size == 0) {
            sb.append("No information in the database");
            sb.append(NEWLINE);
        }

        for (ConfigMap rowMap : rowMaps) {
            // Check to see if we should use this row
            if (_oneProgramOnly() && !_useThisRow(rowMap)) continue;

            _printOneRow(sb, rowMap);
            sb.append(NEWLINE);
            // Prints each rows
            _printComment(sb, rowMap);
            _printDatasetComments(sb, rowMap);
        }
        sb.append(NEWLINE);
    }

    public StringBuilder export(StringBuilder sb) {

        List<ConfigMap> rowMaps = _getRows();

        if (_oneProgramOnly() && !_inThisSegment(rowMaps)) return sb;

        // This segment has some observation in the program
        _printCaption(sb, _getSegment().getSegmentCaption());

        _printDivider(sb, DIVIDER, _getTotalWidth());

        _printHeading(sb);

        _printDivider(sb, DIVIDER, _getTotalWidth());

        _printRows(sb, _getRows());

        return sb;
    }
}


text:
package net.dryanhild.collada.schema14.data;

import net.dryanhild.collada.data.NameableType;

public abstract class AbstractAddressableNameable extends AbstractAddressable implements NameableType {

    private final String name;

    public AbstractAddressableNameable(String id, String name) {
        super(id);
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

}