text:
/*
  renderer.js needs webgl-utils.js and webgl-debug.js
  gl-matrix and gl-matrix-extended
  textureloader
*/
"use strict";
define(['state','glmatrixExt'], function (State) {

  var RENDERER = {};
  RENDERER.default = {
    POSITION :new Float32Array([0, 0, 0]),
    NORMAL : new Float32Array([0, 0, 1]),
    BINORMAL : new Float32Array([0, 0, 1]),
    COLOR : new Float32Array([1, 1, 1, 1]),
    TEXCOORD_0 : new Float32Array([0, 0])
  };

  // log wrapper
  RENDERER.log = function(_msg) {
    if (console && console.log) console.log(_msg);
  };
  // log error wrapper
    // throw msg ??
  RENDERER.logError = function (msg) {
    if (console && console.logError) console.logError(msg);
    else if (console && console.error) console.error(msg);
    else RENDERER.log('ERROR ' + msg);

  };

  RENDERER.primitive = function(_primitive, _state) {

    this.clear();

    // TODO call gldeletebuffer
    this.glBuffer = {};

    this.setprimitive(_primitive);

    this.state = _state;

    // add primitive to list of primitives - needed for context loss
    this.primitiveID = State.primitives.length;
    State.primitives.push(this);
  }

  RENDERER.primitive.prototype = {
    delete: function () {
      this.clear();
      // remove this primitive from the list of primitives
      State.primitives.splice(State.primitiveID,1);
      // delete this
      this.primitiveID = -1;
    },
    // todo - create static default values in function constructor
    clear: function () {
      this.prim = State.TRIANGLES;
      this.value = {};

      this.buffer = {};

      this.value.POSITION = RENDERER.default.POSITION;
      this.value.NORMAL = RENDERER.default.NORMAL;
      this.value.BINORMAL = RENDERER.default.BINORMAL;
      this.value.COLOR= RENDERER.default.COLOR;
      this.value.TEXCOORD_0 = RENDERER.default.TEXCOORD_0;

      this.numVertices = 1;
      this.numIndices  = 0;
      this.numBones = 0

      this.updateMe = this.createMe = true;

    },
    setprimitive: function (_primitive) {

      for (var key in _primitive) {
        switch (key) {
          case 'POSITION':
            if (_primitive.POSITION) {
              this.buffer.POSITION  = _primitive.POSITION;
              this.numVertices = _primitive.POSITION.length/3;
              delete this.value.POSITION;
            } else {
              this.vertices = RENDERER.default.POSITION;
              this.numVertices = 1;
              this.value.POSITION = this.vertices;
              delete this.buffer.POSITION;
            }
            break;
          case 'INDEX':
            if (_primitive.INDEX) {
              this.numIndices=_primitive.INDEX.length;
              this.buffer.INDEX = _primitive.INDEX;
            } else {
              if (this.buffer.INDEX)
                delete this.buffer.INDEX;
              this.numIndices  = 0;
            }
            break;
          default:
            if (_primitive[key]){
              this.buffer[key] = _primitive[key];
              if (this.value[key])
                delete this.value[key];
            } else {
              this.value[key] = RENDERER.default[key];
              if (this.buffer[key])
                delete this.buffer[key];
            }
        }
      }

      this.createMe=true;
    },
    // separate function to be called in context loss
    createAttributeBuffers: function(_state){
      var gl=_state.gl;
      if (!gl) return _state;
      for (var semantic in _state.program.attributes)
      {
        if (this.buffer[semantic])
        {
          this.glBuffer[semantic] = gl.createBuffer();
          gl.bindBuffer(gl.ARRAY_BUFFER, this.glBuffer[semantic]);
          gl.bufferData(gl.ARRAY_BUFFER, this.buffer[semantic], gl.STATIC_DRAW);
        }
      }
      // special case for indexes, they are not referenced by the program directly
      if (this.buffer.INDEX) {
            this.glBuffer.INDEX = gl.createBuffer();
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.glBuffer.INDEX);
            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.buffer.INDEX, gl.STATIC_DRAW);
        };

        this.createMe = false;
        this.updateMe = false;
    },

    getNumPrims: function () {
        return this.numIndices > 0
          ? this.numIndices / 3
          : this.numVertices / 3
    },
    updateAttributeBuffers: function(_state) {
      var gl = _state.gl;
      if (!gl) return _state;

      for (var semantic in _state.program.attributes){
        if (this.glBuffer[semantic] ) {
           gl.bindBuffer(gl.ARRAY_BUFFER, this.glBuffer[semantic]);
           gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.buffer[semantic]);
        }
      }
      // special case for index
      if (this.glBuffer.INDEX) {
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.glBuffer.INDEX);
        gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, this.buffer.INDEX);
      }
      this.updateMe = false;
    },
    // optimize VertexAttrib
    VertexAttribBool: {},
    // this take a primitive (this), applies _state, and render to channel
    dim: vec4.fromValues(0.35,0.35,0.35,0.5),
    bright: vec4.fromValues(1.,1.,1.,1.),
    render: function(_channel) {

      var state = this.state;
      var gl = _channel.state.gl;

      if (_channel.picking) {
        state = State.pickState;
        state.values.color = this.pickColor;
      } else if (_channel.selected && _channel.selected[this.pickID] !== true)
      {
          //state = State.greyState;
          state.values.TINT = this.dim;
      }
      else
        state.values.TINT = this.bright;

      if (0 !== this.numVertices) {

        // this deals with gl states and uniforms
        State.apply(_channel.state,state);

        if(this.createMe === true)
            this.createAttributeBuffers(_channel.state);
        if (this.updateMe === true)
            this.updateAttributeBuffers(_channel.state);

        // deal with attributes, they point to the primitive buffers
        // need to add possible override ?

        for (var semantic in _channel.state.program.attributes) {
          var attribute = _channel.state.program.attributes[semantic];
          if (attribute.location>=0) {
            // if this attribute is connected to an array

            if (this.glBuffer[semantic]) {

              // enable if not already enabled, or if marked for disable
              if (_channel.VertexAttribBool[attribute.location] === undefined)
                gl.enableVertexAttribArray(attribute.location);
              _channel.VertexAttribBool[attribute.location] = true;

              // todo - create State.bindBuffer() to optimize this
              gl.bindBuffer(gl.ARRAY_BUFFER, this.glBuffer[semantic]);

              switch (attribute.type) {
                case gl.FLOAT:
                  gl.vertexAttribPointer(attribute.location, 1, gl.FLOAT, false, 0, 0);
                  break;
                case gl.FLOAT_VEC2:
                  gl.vertexAttribPointer(attribute.location, 2, gl.FLOAT, false, 0, 0);
                  break;
                case gl.FLOAT_VEC3:
                  gl.vertexAttribPointer(attribute.location, 3, gl.FLOAT, false, 0, 0);
                  break;
                case gl.FLOAT_VEC4:
                  gl.vertexAttribPointer(attribute.location, 4, gl.FLOAT, false, 0, 0);
                  break;
              }
            // if the material overide the primitive settings
            } else {
              // lazy disable - if it was enabled, or marked for disable
              if (_channel.VertexAttribBool[attribute.location] !== undefined) {
                gl.disableVertexAttribArray(attribute.location);
                delete _channel.VertexAttribBool[attribute.location];
              }

              // per state value if exists, then per program value, then per primitive value
              var value = state.values[semantic] || attribute.value || this.value[semantic] || RENDERER.default[semantic];
              switch (attribute.type) {
                case gl.FLOAT:
                  gl.vertexAttrib1f(attribute.location, value);
                  break;
                case gl.FLOAT_VEC2:
                  gl.vertexAttrib2fv(attribute.location, value);
                  break;
                case gl.FLOAT_VEC3:
                  gl.vertexAttrib3fv(attribute.location, value);
                  break;
                case gl.FLOAT_VEC4:
                  gl.vertexAttrib4fv(attribute.location, value);
                  break;
                }
              }
          }
        }

        // flush remeining disable attributes
        for (var location in _channel.VertexAttribBool) {
          if (_channel.VertexAttribBool[location] === false) {
            delete _channel.VertexAttribBool[location] ;
            gl.disableVertexAttribArray(location);
          }
        }

        if (this.glBuffer.INDEX) {
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.glBuffer.INDEX);
            gl.drawElements(this.prim, this.numIndices, gl.UNSIGNED_SHORT, 0);
        } else
            gl.drawArrays(this.prim, 0, this.numVertices);

        // lazy vertex attrib disable
        for (var location in _channel.VertexAttribBool)
          _channel.VertexAttribBool[location] = false;

      }

    }
  };

  return RENDERER;
});

redpajama_set_name: RedPajamaGithub


text:
from app import db
from werkzeug import generate_password_hash
from flask.ext.login import UserMixin

class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(128), nullable=False, unique=True)
    password = db.Column(db.String(192), nullable=False)

    def __init__(self, username, password):
        self.username = username
        self.password = generate_password_hash(password)

    def __repr__(self):
        return '<User %r>' % (self.username)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id


text:
'use strict'

const Application = require( 'spectron' ).Application,
  chai = require( 'chai' ),
  chaiAsPromised = require( 'chai-as-promised' ),
  path = require( 'path' )

chai.should()
chai.use( chaiAsPromised )

describe( '(integration) cmi-data-collector', function describeSuite() {
  this.timeout( 30000 )

  let app

  const setupApp = function setupApp( app ) {
      chaiAsPromised.transferPromiseness = app.transferPromiseness
      return app.client.waitUntilWindowLoaded()
    },
    startApp = function startApp() {
      app = new Application( {
        path: path.join( __dirname, '..', '..', 'node_modules', '.bin', 'electron' ),
        args: [
          path.join( __dirname, '..', '..', 'app' )
        ],
        waitTimeout: 10000
      } )
      return app.start().then( setupApp )
    }

  before( function beforeEach() {
    return startApp()
  } )

  after( function afterEach() {
    if ( app && app.isRunning() ) {
      return app.stop()
    }
  } )

  it( 'opens a window displaying the main screen', function itWindowsOpen() {
    return app.client.getWindowCount().should.eventually.equal( 1 )
      .browserWindow.isMinimized().should.eventually.be.false
      .browserWindow.isDevToolsOpened().should.eventually.be.false
      .browserWindow.isVisible().should.eventually.be.true
      .browserWindow.isFocused().should.eventually.be.true
      .browserWindow.getBounds().should.eventually.have.property( 'width' ).and.be.above( 0 )
      .browserWindow.getBounds().should.eventually.have.property( 'height' ).and.be.above( 0 )
  } )
} )


text:
LT-code
=======

This is an implementation of a Luby Transform code in Python, consisting of two executables, one for each encoding and decoding files. These are thin wrappers around a core stream/file API.

See [_D.J.C, MacKay, 'Information theory, inference, and learning algorithms. Cambridge University Press, 2003_](http://www.inference.org.uk/itprnn/book.pdf) for reference on the algorithms.

## Encoding

The encoding algorithm follows the given spec, so no innovations there. A few optimizations are made however. First, the CDF of the degree distribution, M(d), is precomputed for all degrees d = 1, ..., K. This CDF is represented as an array mapping index d => M(d), so sampling from the degree distribution mu(d) becomes a linear search through the CDF array looking for the bucket our random number on \[0, 1) landed in. This random number is generated as specified using the linear congruential generator.

Second, the integer representation of all blocks is held in RAM for maximum speed in block sample generation. This is a limitation on the size of the file practically encoded on most computers, but this decision does not reach far into other parts of the design, and it can be easily addressed if necessary for better memory scalability.

```python
from sys import stdout
from lt import encode

# Stream a fountain of 1024B blocks to stdout
block_size = 1024
with open(filename, 'rb') as f:
    for block in encode.encoder(f, block_size):
        stdout.buffer.write(block)
```

## Decoding

The decoder reads the header, then the body, of each incoming block and conducts all possible steps in the belief propagation algorithm on a representation of the source node/check node graph that become possible given the new check node. This is done using an online algorithm, which computes the appropriate messages incrementally and passes them eagerly as the value of source nodes is resolved. Thus, the decoder will finish decoding once it has read only as many blocks is necessary in the stream to decode the file, and it seems to scale well as the file size, and block size increase.

```python
from sys import stdin, stdout
from lt import decode

# Usage 1: Blocking
# Blocks until decoding is complete, returns bytes
data = decode.decode(stdin.buffer)

# Usage 2: Incremental
# Consume blocks in a loop, breaking when finished
decoder = decode.LtDecoder()
for block in decode.read_blocks(stdin.buffer):
    decoder.consume_block(block)
    if decoder.is_done():
       break

# You can collect the decoded transmission as bytes
data = decoder.bytes_dump()

# Or You can write the output directly to another stream
decoder.stream_dump(sys.stdout.buffer)

```
## Commandline Usage

To run the encoder, invoke the following from the shell
```
$ ./bin/encoder <file> <blocksize> [seed] [c] [delta]
```

For example, the following streams the encoding of `file.txt` to stdout in 64B blocks.
```
$ ./bin/encoder ./file.txt 64
```

To run the decoder on stdin, run the following
```
$ ./bin/decoder
```


text:
.snapshot-listing.ng-enter,
.snapshot-listing.ng-leave,
.snapshot-listing.ng-move {
  -webkit-transition: 1s linear all;
  -moz-transition: 1s linear all;
  -o-transition: 1s linear all;
  transition: 1s linear all;
}

.snapshot-listing.ng-enter,
.snapshot-listing.ng-move {
  opacity: 0;
  width: 0;
}

.snapshot-listing.ng-move.ng-move-active,
.snapshot-listing.ng-enter.ng-enter-active {
  opacity: 1;
  width: 100px;
}

.snapshot-listing.ng-leave {
  opacity: 1;
  overflow: hidden;
}

.snapshot-listing.ng-leave.ng-leave-active {
  opacity: 0;
  width: 0;
  padding-top: 0;
  padding-bottom: 0;
}


text:
package com.hut.zero.adapter;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.hut.zero.BR;
import com.hut.zero.R;
import com.hut.zero.bean.GuokeHandpickNews;
import com.hut.zero.other.OnRecyclerViewOnClickListener;
import com.hut.zero.other.BaseViewHolder;
import com.hut.zero.other.WithListenerViewHolder;

import java.util.List;

/**
 * Created by lizhaotailang on 2016/6/14.
 */
public class GuokeNewsAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private OnRecyclerViewOnClickListener mListener;

    private List<GuokeHandpickNews.Result> data;

    public GuokeNewsAdapter(List<GuokeHandpickNews.Result> list) {
        data=list;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new WithListenerViewHolder(
                DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.home_list_item_layout, parent, false)
                ,mListener);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        GuokeHandpickNews.Result item=data.get(position);

        holder.getBinding().setVariable(BR.imgUrl,item.getHeadline_img_tb());
        holder.getBinding().setVariable(BR.title,item.getTitle());
    }

    public void setItemClickListener(OnRecyclerViewOnClickListener listener){
        this.mListener = listener;
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    private class GuokePostViewHolder extends WithListenerViewHolder {
        public GuokePostViewHolder(ViewDataBinding binding, OnRecyclerViewOnClickListener listener) {
            super(binding,listener);
        }
    }
}


text:
package com.dmytrobilokha.disturber.network;

import com.dmytrobilokha.disturber.SystemMessage;
import com.dmytrobilokha.disturber.appeventbus.AppEvent;
import com.dmytrobilokha.disturber.appeventbus.AppEventType;
import com.dmytrobilokha.disturber.commonmodel.MatrixEvent;
import com.dmytrobilokha.disturber.commonmodel.RoomKey;
import com.dmytrobilokha.disturber.config.account.AccountConfig;
import com.dmytrobilokha.disturber.network.dto.EventContentDto;
import com.dmytrobilokha.disturber.network.dto.EventDto;
import com.dmytrobilokha.disturber.network.dto.InvitedRoomDto;
import com.dmytrobilokha.disturber.network.dto.JoinedRoomDto;
import com.dmytrobilokha.disturber.network.dto.LoginAnswerDto;
import com.dmytrobilokha.disturber.network.dto.LoginPasswordDto;
import com.dmytrobilokha.disturber.network.dto.SyncResponseDto;
import com.dmytrobilokha.disturber.util.ThrowingFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;

/**
 * The class represents synchronizer which should be run in the separate thread and synchronizes matrix events for
 * given account.
 */
class MatrixSynchronizer extends Thread {

    private static final Logger LOG = LoggerFactory.getLogger(MatrixSynchronizer.class);
    private static final int MAX_WAIT_MULTIPLIER = 5;
    private static final String INVITE = "invite";
    private static final String ROOM_MEMBER_TYPE = "m.room.member";
    private static final String ROOM_MESSAGE_TYPE = "m.room.message";
    private static final String TEXT_MESSAGE = "m.text";

    private final Queue<OutgoingEvent> appToServerQueue = new ConcurrentLinkedQueue<>();
    private final AtomicLong messageId = new AtomicLong();
    private final AccountConfig accountConfig;
    private final CrossThreadEventQueue serverToAppQueue;
    private final MatrixApiConnector apiConnector;
    private final ApiExceptionToSystemMessageConverter exceptionConverter;
    private final MatrixEvent.Builder matrixEventBuilder = MatrixEvent.newBuilder();
    private final ConnectionRetryStateHolder retryStateHolder;

    private State state = State.NOT_CONNECTED;
    private boolean haveNewEvents;
    private String accessToken;
    private String nextBatchId;
    private volatile boolean keepGoing = true;

    MatrixSynchronizer(AccountConfig accountConfig, CrossThreadEventQueue serverToAppQueue
            , MatrixApiConnector apiConnector, ApiExceptionToSystemMessageConverter exceptionConverter) {
        this.accountConfig = accountConfig;
        this.serverToAppQueue = serverToAppQueue;
        this.apiConnector = apiConnector;
        this.exceptionConverter = exceptionConverter;
        setName(this.getClass().getSimpleName() + "-" + accountConfig.getUserId());
        this.retryStateHolder = new ConnectionRetryStateHolder(accountConfig.getBetweenSyncPause());
    }

    @Override
    public void run() {
        while (keepGoing) {
            try {
                sleepPauseTime();
            } catch (InterruptedException ex) {
                LOG.error("Thread interrupted", ex);
                Thread.currentThread().interrupt();
                return;
            }
            talkToServer();
            pushServerEventsToApp();
        }
    }

    private void talkToServer() {
        if (!retryStateHolder.isActive()) //If active flag is not set, do nothing, will just sleep all the time
            return;
        switch (state) {
            case NOT_CONNECTED:
                connect();
                break;

            case CONNECTED:
                login();
                break;

            case LOGGEDIN:
                initialSync();
                break;

            case SYNCED:
                sendEventsToServer();
                break;

            case MESSAGES_SENT:
                stepSync();
                break;
        }
    }

    private void pushServerEventsToApp() {
        if (!haveNewEvents)
            return;
        serverToAppQueue.triggerEventCallback();
        haveNewEvents = false;
    }

    private void sleepPauseTime() throws InterruptedException {
        Thread.sleep(retryStateHolder.pauseTime()); //Pause increases on fail to make server's life easier
    }

    //This method to be called from the main FX application thread to recover after fail if user wants
    public void setRetryOn() {
        retryStateHolder.reset();
    }

    //This method to be called from the main FX application thread to "stop the show"
    public void disconnect() {
        retryStateHolder.stop();
        keepGoing = false;
    }

    private void connect() {
        apiConnector.createConnection(accountConfig.getServerAddress()
                , accountConfig.getNetworkTimeout(), accountConfig.getProxyServer());
        handleChangeState(State.CONNECTED);
    }

    private void handleChangeState(State state) {
        retryStateHolder.reset();
        this.state = state;
    }

    private void handleNetworkFail(State state, Exception ex) {
        SystemMessage systemMessage = exceptionConverter.buildSystemMessage(state, accountConfig.getUserId(), ex);
        if (retryStateHolder.getTotalWaitTime() < MAX_WAIT_MULTIPLIER * accountConfig.getNetworkTimeout()) {
            addEvent(AppEvent.withClassifierAndPayload(AppEventType.MATRIX_CONNECTION_ISSUE, accountConfig, systemMessage));
        } else {
            retryStateHolder.stop();
            addEvent(AppEvent.withClassifierAndPayload(AppEventType.MATRIX_CONNECTION_FAILED, accountConfig, systemMessage));
        }
    }

    private void handleResponseFail(State state, Exception ex) {
        retryStateHolder.stop();
        SystemMessage systemMessage = exceptionConverter.buildSystemMessage(state, accountConfig.getUserId(), ex);
        addEvent(AppEvent.withClassifierAndPayload(AppEventType.MATRIX_RESPONSE_FAILED, accountConfig, systemMessage));
    }

    private void login() {
        LoginPasswordDto loginPasswordDto = new LoginPasswordDto();
        loginPasswordDto.setLogin(accountConfig.getLogin());
        loginPasswordDto.setPassword(accountConfig.getPassword());
        LoginAnswerDto answerDto;
        try {
            answerDto = apiConnector.login(loginPasswordDto);
        } catch (ApiConnectException ex) {
            LOG.error("Failed to login with {}", accountConfig, ex);
            handleNetworkFail(State.LOGGEDIN, ex);
            return;
        } catch (ApiRequestException ex) {
            LOG.error("Failed to login with {}, got {}", accountConfig, ex.getApiError(), ex);
            handleResponseFail(State.LOGGEDIN, ex);
            return;
        }
        accessToken = answerDto.getAccessToken();
        String userId = answerDto.getUserId();
        if (!accountConfig.getUserId().equals(userId))
            LOG.warn("After logging in for {} got from server userId={}, but from account have userId={}"
                        , accountConfig, userId, accountConfig.getUserId());
        handleChangeState(State.LOGGEDIN);
        addEvent(AppEvent.withClassifier(AppEventType.MATRIX_LOGGEDIN, userId));
    }

    private void addEvent(AppEvent event) {
        serverToAppQueue.addEvent(event);
        haveNewEvents = true;
    }

    private void addEvents(Collection<AppEvent> events) {
        if (events.isEmpty())
            return;
        serverToAppQueue.addEvents(events);
        haveNewEvents = true;
    }

    private void initialSync() {
        sync(connector -> connector.sync(accessToken));
    }

    private void stepSync() {
        sync(connector -> connector.sync(accessToken, nextBatchId, accountConfig.getSyncTimeout()));
    }

    private void sync(ThrowingFunction<MatrixApiConnector, SyncResponseDto> requestFunction) {
        SyncResponseDto syncResponseDto;
        try {
            syncResponseDto = requestFunction.apply(apiConnector);
        } catch (ApiConnectException ex) {
            LOG.error("Failed to synchronize {} with server because of input/output error", accountConfig, ex);
            handleNetworkFail(State.SYNCED, ex);
            return;
        } catch (ApiRequestException ex) {
            LOG.error("Failed to synchronize {} with server, got {}", accountConfig, ex.getApiError(), ex);
            handleResponseFail(State.SYNCED, ex);
            return;
        } catch (Exception ex) {
            LOG.error("Failed to synchronize {} with server, got unexpected exception", accountConfig, ex);
            handleResponseFail(State.SYNCED, ex);
            return;
        }
        nextBatchId = syncResponseDto.getNextBatch();
        handleChangeState(State.SYNCED);
        addEvent(AppEvent.withClassifier(AppEventType.MATRIX_SYNCED, accountConfig.getUserId()));
        List<AppEvent> events = mapSyncResponseDtoToAppEvents(syncResponseDto);
        addEvents(events);
    }

    private List<AppEvent> mapSyncResponseDtoToAppEvents(SyncResponseDto syncResponseDto) {
        List<AppEvent> appEvents = new ArrayList<>();
        appEvents.addAll(mapJoinedRoomEvents(syncResponseDto.getRooms().getJoinedRoomMap()));
        appEvents.addAll(mapInvitedRoomEvents(syncResponseDto.getRooms().getInvitedRoomMap()));
        return appEvents;
    }

    private List<AppEvent> mapJoinedRoomEvents(Map<String, JoinedRoomDto> joinedRoomMap) {
        List<AppEvent> appEvents = new ArrayList<>();
        for (Map.Entry<String, JoinedRoomDto> joinedRoomDtoEntry : joinedRoomMap.entrySet()) {
            RoomKey roomKey = new RoomKey(accountConfig.getUserId(), joinedRoomDtoEntry.getKey());
            List<EventDto> eventDtos = joinedRoomDtoEntry.getValue().getTimeline().getEvents();
            for (EventDto eventDto : eventDtos) {
                MatrixEvent matrixEvent = matrixEventBuilder
                        .serverTimestamp(eventDto.getServerTimestamp())
                        .sender(eventDto.getSender())
                        .contentType(eventDto.getContent().getMsgType())
                        .content(eventDto.getContent().getBody())
                        .build();
                appEvents.add(AppEvent.withClassifierAndPayload(AppEventType.MATRIX_NEW_EVENT_GOT, roomKey, matrixEvent));
            }
        }
        return appEvents;
    }

    private  List<AppEvent> mapInvitedRoomEvents(Map<String, InvitedRoomDto> invitedRoomMap) {
        List<AppEvent> appEvents = new ArrayList<>();
        for (Map.Entry<String, InvitedRoomDto> invitedRoomDtoEntry : invitedRoomMap.entrySet()) {
            RoomKey roomKey = new RoomKey(accountConfig.getUserId(), invitedRoomDtoEntry.getKey());
            List<EventDto> eventDtos = invitedRoomDtoEntry.getValue().getInviteState().getEvents();
            for (EventDto eventDto : eventDtos) {
                if (!ROOM_MEMBER_TYPE.equals(eventDto.getType()) || !INVITE.equals(eventDto.getContent().getMembership()))
                    continue; //Skip all events which are not invites
                MatrixEvent matrixEvent = matrixEventBuilder
                        .serverTimestamp(eventDto.getServerTimestamp())
                        .sender(eventDto.getSender())
                        .build();
                appEvents.add(AppEvent.withClassifierAndPayload(AppEventType.MATRIX_NEW_INVITE_GOT, roomKey, matrixEvent));
            }
        }
        return appEvents;
    }

    private void sendEventsToServer() {
        OutgoingEvent event;
        while ((event = appToServerQueue.peek()) != null) {
            try {
                switch (event.getType()) { //TODO: change OutgoingEvent to avoid this switch statement
                    case MESSAGE:
                        sendMessageEvent(event);
                        break;
                    case JOIN:
                        sendJoinEvent(event);
                        break;
                    default:
                        LOG.error("Unable to handle outgoing event {} because type is not recognized", event);
                        break;
                }
            } catch (ApiConnectException ex) {
                LOG.error("Failed to send event {}, because of input/output error", event, ex);
                handleNetworkFail(State.MESSAGES_SENT, ex);
                return;
            } catch (ApiRequestException ex) {
                LOG.error("Failed to send event {}, got {}", event, ex.getApiError(), ex);
                handleResponseFail(State.MESSAGES_SENT, ex);
                return;
            }
            appToServerQueue.poll();
        }
        handleChangeState(State.MESSAGES_SENT);
    }

    private void sendMessageEvent(OutgoingEvent event) throws ApiConnectException, ApiRequestException {
        EventContentDto messageContent = new EventContentDto();
        messageContent.setBody(event.getMessageText());
        messageContent.setMsgType(TEXT_MESSAGE);
        apiConnector.sendMessageEvent(accessToken, event.getRoomId()
                , ROOM_MESSAGE_TYPE, event.getLocalId(), messageContent);
    }

    private void sendJoinEvent(OutgoingEvent event) throws ApiConnectException, ApiRequestException {
        String roomId = event.getRoomId();
        apiConnector.joinRoom(accessToken, roomId);
        addEvent(AppEvent.withClassifier(AppEventType.MATRIX_JOINED_OK, new RoomKey(accountConfig.getUserId(), roomId)));
    }

    //Called from JavaFX application thread
    void enqueueOutgoingMessage(String roomId, String message) {
        OutgoingEvent outgoingEvent = OutgoingEvent.createMessageEvent(roomId, message, getNewMessageId());
        appToServerQueue.add(outgoingEvent);
    }

    //Called from JavaFX application thread
    void enqueueJoin(String roomId) {
        OutgoingEvent outgoingEvent = OutgoingEvent.createJoinEvent(roomId);
        appToServerQueue.add(outgoingEvent);
    }

    private String getNewMessageId() {
        return String.valueOf(messageId.getAndIncrement());
    }

    enum State {
        NOT_CONNECTED, CONNECTED, LOGGEDIN, SYNCED, MESSAGES_SENT;
    }

}


text:
using Newtonsoft.Json;
using System;

namespace LMS.Model
{
    /// <summary>
    /// This is an abstract class from which all resources derive. It defines a superset of common properties and methods.
    /// </summary>
    public abstract class DomainResource
    {
        /// <summary>
        /// Gets the name of the resource.
        /// </summary>
        [JsonProperty(PropertyName = "resourceType")]
        public string ResourceType
        {
            get
            {
                return GetType().Name;
            }
        }

        /// <summary>
        /// Gets or sets the unique identifier of the resource.
        /// </summary>
        [JsonProperty(PropertyName = "identifier")]
        public int Id { get; set; }

        /// <summary>
        /// Constructor for the abstract class.
        /// </summary>
        public DomainResource()
        {
        }
    }
}


text:
package com.tkhoon.framework;

import com.tkhoon.framework.helper.AOPHelper;
import com.tkhoon.framework.helper.ActionHelper;
import com.tkhoon.framework.helper.BeanHelper;
import com.tkhoon.framework.helper.DBHelper;
import com.tkhoon.framework.helper.EntityHelper;
import com.tkhoon.framework.helper.IOCHelper;
import com.tkhoon.framework.helper.PluginHelper;
import org.apache.log4j.Logger;

public final class tkhoon {

    private static final Logger logger = Logger.getLogger(tkhoon.class);

    public static void init() {
        try {
            Class<?>[] classList = {
                DBHelper.class,
                EntityHelper.class,
                ActionHelper.class,
                BeanHelper.class,
                AOPHelper.class,
                IOCHelper.class,
                PluginHelper.class,
            };
            for (Class<?> cls : classList) {
                Class.forName(cls.getName());
            }
        } catch (Exception e) {
            logger.error("加载 Helper 出错!", e);
        }
    }
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Simple en Grid</title>

    <link rel="stylesheet" href="../../builds/merged/bsgrid.all.min.css"/>

        XH
        ID
        CHAR
        TEXT
        DATE
        TIME
        NUM
        Operate


text:
## SharePoint Server: PowerShell Script To Test SharePoint Send Mail Functionality ##

<#

Overview: PowerShell Script that uses the Object Model to test sending email using the same 'SPUtility.SendMail' configured in the Incoming/Outgoing Central Admin E-Mail Settings

Environments: SharePoint Server 2010 / 2013 Farms

Usage: Edit the variables below and run the script

#>

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

##### Begin Variables #####
$spsite = "https://devinside.npe.theglobalfund.org" #Provide your SharePoint site details here
$email = "yourname@youremail.com" #Add your recipient email address here
$subject = "SharePoint SendMail Test" #Change your subject here
$body = "Email sent via SharePoint site $spsite" #Change your body text here
##### End Variables #####

$site = New-Object Microsoft.SharePoint.SPSite "$spsite"
$web = $site.OpenWeb()
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,0,0,$email,$subject,$body)


text:
/*
Cleverbot duel

Joakim Bennedich
2012-03-13

Surf to http://cleverbot.com
Open the JavaScript console (F12 | ctrl-shift-J | cmd-shift-J | etc)
Paste all the code into the console and press [Enter]
Press one of the 'Think' buttons or type something
PROFIT!!
*/

/*****************
** EventEmitter **
*****************/

var EventEmitter = ( function () {
	'use strict';
	var p = EventEmitter.prototype;

	function EventEmitter () {
	    this._lstnrs = {};
	}

	p.on = function ( e, lstnr ) {
	    if ( ! this._lstnrs.hasOwnProperty( e ) ) this._lstnrs[ e ] = [];
	    this._lstnrs[ e ].push( lstnr );
	};

	p.off = function ( e, lstnr ) {
	    var i = this._lstnrs[ e ].indexOf( lstnr );
	    i > -1 && this._lstnrs[ e ].splice( i, 1 );
	};

	p.emit = function ( e, arg ) {
	    var i = 0, lstnr, lstnrs = this._lstnrs[ e ];
	    if ( ! lstnrs ) return;
	    while ( lstnr = lstnrs[ i++ ] ) lstnr( arg );
	};

	return EventEmitter;
} )();

/************************
** Cleverbot UIWrapper **
************************/

var UIWrapper = ( function () {
    'use strict';
    var p = UIWrapper.prototype;

    function UIWrapper ( win ) {
        EventEmitter.call( this );

        this.window = win;
        this.document = win.document;
        this.inSelector = '#stimulus';
        this.outSelector = '#typArea';
        this.in = null;
        this.out = null;
        this.timerId = null;
        this.respArea = this.document.querySelector( '#respArea' );

        this.init = this.init.bind( this );
        this.listen = this.listen.bind( this );
        this._listen = this._listen.bind( this );
        this.read = this.read.bind( this );
        this._read = this._read.bind( this );

        this.init();
    }

    // inherit EventEmitter
    p = UIWrapper.prototype = Object.create(
        EventEmitter.prototype,
        { constructor : { value : UIWrapper } }
    );

    p.init = function () {
        var self = this;
        // wait for cleverbot to get ready then start listening for inital changes
        setTimeout( function () {
            self.respArea.addEventListener( 'DOMSubtreeModified', function onInit () {
                self.respArea.removeEventListener( 'DOMSubtreeModified', onInit );
                self.listen();
            } );
        }, 3e3 );
    };

    p.listen = function () {
        setTimeout( this._listen, 10 );
    };

    p._listen = function () {
        //console.log( '*' );
        this.out = this.document.querySelector( this.outSelector );
        this.out.addEventListener( 'DOMNodeRemovedFromDocument', this.listen );
        this.out.addEventListener( 'DOMNodeInserted', this.read );
    };

    p.read = function () {
        //console.log( '**', this.out.textContent );
        if ( this.out.textContent.length < 2 )
            return;
        clearTimeout( this.timerId );
        this.timerId = setTimeout( this._read, 4e2 );
    };

    p._read = function () {
        //console.log( '***', this.out.textContent );
        this.emit( 'newData', this.out.textContent );
    };

    p.write = function ( data ) {
        this.in = this.document.querySelector( this.inSelector );
        this.in.value = data;
        this.window.lCBtn( 'Say' );
    };

    return UIWrapper;
} )();

/*********
** MAIN **
*********/

var Main = ( function () {
    'use strict';
    var p = Main.prototype;

    function Main () {
        this.initExtUIWrapper = this.initExtUIWrapper.bind( this );
        this.onNewDataFromExt = this.onNewDataFromExt.bind( this );
        this.onNewDataFromMain = this.onNewDataFromMain.bind( this );

        this.initExtWindow();
        this.ext.addEventListener( 'DOMContentLoaded', this.initExtUIWrapper );
        this.initMainUIWrapper();
    }

    p.initExtWindow = function () {
        var url  = '.',
            name = 'ext',
            opts = 'width=1024,height=720,top=0,left=0';
        this.ext = window.open( url, name, opts );
    };

    p.initExtUIWrapper = function () {
        this.extUIWrapper = new UIWrapper( this.ext.window );
        this.extUIWrapper.on( 'newData', this.onNewDataFromExt );
    };

    p.initMainUIWrapper = function () {
        this.mainUIWrapper = new UIWrapper( window );
        this.mainUIWrapper.on( 'newData', this.onNewDataFromMain );
    };

    p.onNewDataFromExt = function ( data ) {
        //console.log( '[ext]:', data );
        this.mainUIWrapper.write( data );
    };

    p.onNewDataFromMain = function ( data ) {
        //console.log( '[main]:', data );
        this.extUIWrapper.write( data );
    };

    return Main;
} )();

var m = new Main;


text:
import './Mixin'

export function mix(parentClass) {
	return new Mixin(parentClass)
}


text:
.class Landroid/widget/AbsListView$PerformClick;
.super Landroid/widget/AbsListView$WindowRunnnable;
.source "AbsListView.java"

# interfaces
.implements Ljava/lang/Runnable;

# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Landroid/widget/AbsListView;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x2
    name = "PerformClick"
.end annotation

# instance fields
.field mClickMotionPosition:I

.field final synthetic this$0:Landroid/widget/AbsListView;

# direct methods
.method private constructor <init>(Landroid/widget/AbsListView;)V
    .locals 1
    .parameter

    .prologue
    .line 2554
    iput-object p1, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    const/4 v0, 0x0

    invoke-direct {p0, p1, v0}, Landroid/widget/AbsListView$WindowRunnnable;-><init>(Landroid/widget/AbsListView;Landroid/widget/AbsListView$1;)V

    return-void
.end method

.method synthetic constructor <init>(Landroid/widget/AbsListView;Landroid/widget/AbsListView$1;)V
    .locals 0
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 2554
    invoke-direct {p0, p1}, Landroid/widget/AbsListView$PerformClick;-><init>(Landroid/widget/AbsListView;)V

    return-void
.end method

# virtual methods
.method public run()V
    .locals 6

    .prologue
    .line 2560
    iget-object v3, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    iget-boolean v3, v3, Landroid/widget/AdapterView;->mDataChanged:Z

    if-eqz v3, :cond_1

    .line 2574
    :cond_0
    :goto_0
    return-void

    .line 2562
    :cond_1
    iget-object v3, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    iget-object v0, v3, Landroid/widget/AbsListView;->mAdapter:Landroid/widget/ListAdapter;

    .line 2563
    .local v0, adapter:Landroid/widget/ListAdapter;
    iget v1, p0, Landroid/widget/AbsListView$PerformClick;->mClickMotionPosition:I

    .line 2564
    .local v1, motionPosition:I
    if-eqz v0, :cond_0

    iget-object v3, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    iget v3, v3, Landroid/widget/AdapterView;->mItemCount:I

    if-lez v3, :cond_0

    const/4 v3, -0x1

    if-eq v1, v3, :cond_0

    invoke-interface {v0}, Landroid/widget/ListAdapter;->getCount()I

    move-result v3

    if-ge v1, v3, :cond_0

    invoke-virtual {p0}, Landroid/widget/AbsListView$PerformClick;->sameWindow()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 2567
    iget-object v3, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    iget-object v4, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    iget v4, v4, Landroid/widget/AdapterView;->mFirstPosition:I

    sub-int v4, v1, v4

    invoke-virtual {v3, v4}, Landroid/widget/AbsListView;->getChildAt(I)Landroid/view/View;

    move-result-object v2

    .line 2570
    .local v2, view:Landroid/view/View;
    if-eqz v2, :cond_0

    .line 2571
    iget-object v3, p0, Landroid/widget/AbsListView$PerformClick;->this$0:Landroid/widget/AbsListView;

    invoke-interface {v0, v1}, Landroid/widget/ListAdapter;->getItemId(I)J

    move-result-wide v4

    invoke-virtual {v3, v2, v1, v4, v5}, Landroid/widget/AbsListView;->performItemClick(Landroid/view/View;IJ)Z

    goto :goto_0
.end method


text:
POMDOG_SUPPRESS_WARNINGS_GENERATED_BY_STD_HEADERS_BEGIN
#include <functional>
#include <type_traits>
#include <utility>
POMDOG_SUPPRESS_WARNINGS_GENERATED_BY_STD_HEADERS_END

namespace pomdog::detail {

template <typename T, class Tag>
class POMDOG_EXPORT Tagged final {
public:
    static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
    static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");

    using value_type = T;
    using tag_type = Tag;

    T value;

public:
    Tagged() = default;
    Tagged(const Tagged&) = default;
    Tagged(Tagged&&) = default;

    Tagged& operator=(const Tagged&) = default;
    Tagged& operator=(Tagged&&) = default;

    Tagged(const value_type& v)
        : value(v)
    {
    }

    Tagged(value_type&& v)
        : value(std::move(v))
    {
    }

    constexpr const T* Data() const noexcept
    {
        return &value;
    }

    T* Data() noexcept
    {
        return &value;
    }

    constexpr bool operator==(const Tagged& v) const
    {
        return value == v.value;
    }

    constexpr bool operator!=(const Tagged& v) const
    {
        return value != v.value;
    }
};

template <typename T, class Tag, class... Arguments>
Tagged<T, Tag> MakeTagged(Arguments&&... arguments)
{
    static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
    static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
    return Tagged<T, Tag>(std::forward<T>(arguments)...);
}

} // namespace pomdog::detail

namespace std {

template <typename T, class U>
struct hash<pomdog::detail::Tagged<T, U>> {
    std::size_t operator()(const pomdog::detail::Tagged<T, U>& key) const
    {
        return std::hash<T>()(key.value);
    }
};

} // namespace std


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

package com.google.cloud.spanner.pgadapter.parsers;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Translate from wire protocol to string.
 */
public class StringParser extends Parser<String> {

  public StringParser(ResultSet item, int position) throws SQLException {
    this.item = item.getString(position);
  }

  public StringParser(Object item) {
    this.item = (String) item;
  }

  public StringParser(byte[] item) {
    this.item = new String(item, UTF8);
  }

  @Override
  public String getItem() {
    return this.item;
  }

  @Override
  protected String stringParse() {
    return this.item;
  }
}


text:
<html>
<head>
<script src="jquery-1.4.2.min.js"></script>
<script src="../src/jschannel.js"></script>
<script src="conduit.js"></script>
</head>
</html>


text:
namespace NumbersFromOneToN
{
    using System;

    /// <summary>
    /// Problem 1. Numbers from 1 to N
    /// Write a program that enters from the console a positive integer `n` and prints all the numbers from `1` to `n`, on a single line, separated by a space.
    /// Examples:
    /// | n            | output    |
    /// |--------------|-----------|
    /// | 3            | 1 2 3     |
    /// | 5            | 1 2 3 4 5 |
    /// </summary>
    public class NumbersFromOneToN
    {
        public static void Main()
        {
            Console.WriteLine("Problem 1.	Numbers from 1 to N \nWrite a program that enters from the console a positive integer `n` and prints all the numbers from `1` to `n`, on a single line, separated by a space.\n");

            Console.Write("Please enter a positive integer N: ");

            int n;

            if (!int.TryParse(Console.ReadLine(), out n) || n < 1)
            {
                Console.WriteLine("Input not in the correct format.");
                return;
            }

            for (int i = 1; i <= n; i++)
            {
                Console.Write("{0} ", i);
            }

            Console.WriteLine();
        }
    }
}


text:
//
//  GPKGUserCustomDao.h
//  geopackage-ios
//
//  Created by Brian Osborn on 6/19/18.
//  Copyright © 2018 NGA. All rights reserved.
//

#import "GPKGUserDao.h"
#import "GPKGUserCustomRow.h"
#import "GPKGUserCustomTable.h"

/**
 * User Custom DAO for reading user custom data tables
 */
@interface GPKGUserCustomDao : GPKGUserDao

/**
 * Initializer
 *
 * @param database        database connection
 * @param table           user custom table
 * @return new user custom dao
 */
-(instancetype) initWithDatabase: (GPKGConnection *) database andTable: (GPKGUserCustomTable *) table;

/**
 * Initializer
 *
 * @param dao        user custom dao
 * @return new user custom dao
 */
-(instancetype) initWithDao: (GPKGUserCustomDao *) dao;

/**
 * Initializer
 *
 * @param dao        user custom dao
 * @param table           user custom table
 * @return new user custom dao
 */
-(instancetype) initWithDao: (GPKGUserCustomDao *) dao andTable: (GPKGUserCustomTable *) table;

/**
 *  Get the user custom table
 *
 *  @return user custom table
 */
-(GPKGUserCustomTable *) userCustomTable;

/**
 *  Get the user custom row for the current result in the result set
 *
 *  @param results result set
 *
 *  @return user custom row
 */
-(GPKGUserCustomRow *) row: (GPKGResultSet *) results;

/**
 *  Get a user custom row from the row
 *
 *  @param row result row
 *
 *  @return user custom row
 */
-(GPKGUserCustomRow *) rowWithRow: (GPKGRow *) row;

/**
 *  Create a new user custom row
 *
 *  @return user custom row
 */
-(GPKGUserCustomRow *) newRow;

/**
 * Get the count of the result set and close it
 *
 * @param resultSet
 *            result set
 * @return count
 */
-(int) countOfResultSet: (GPKGResultSet *) resultSet;

/**
 * Read the database table and create a DAO
 *
 * @param database
 *            database name
 * @param connection
 *            db connection
 * @param tableName
 *            table name
 * @return user custom DAO
 */
+(GPKGUserCustomDao *) readTableWithDatabase: (NSString *) database andConnection: (GPKGConnection *) connection andTable: (NSString *) tableName;

@end


text:
package org.apache.shindig.common;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * Serializes a JSONObject.
 *
 * The methods here are designed to be substantially more CPU and memory efficient than those found
 * in org.json or net.sf.json. In profiling, the performance of both of these libraries has been
 * found to be woefully inadequate for large scale deployments.
 *
 * The append*() methods can be used to serialize directly into an Appendable, such as an output
 * stream. This avoids unnecessary copies to intermediate objects.
 */
public final class JsonSerializer {
  // Multiplier to use for allocating the buffer.
  private static final int BASE_MULTIPLIER = 256;

  private static final char[] HEX_DIGITS = {
    '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  };

  private JsonSerializer() {}

  /**
   * Serialize a JSONObject. Does not guard against cyclical references.
   */
  public static String serialize(JSONObject object) {
    StringBuilder buf = new StringBuilder(object.length() * BASE_MULTIPLIER);
    try {
      appendJsonObject(buf, object);
    } catch (IOException e) {
      // Shouldn't ever happen unless someone adds something to append*.
      throw new RuntimeException(e);
    }
    return buf.toString();
  }

  /**
   * Serializes a Map as a JSON object. Does not guard against cyclical references.
   */
  public static String serialize(Map<String, ? extends Object> map) {
    StringBuilder buf = new StringBuilder(map.size() * BASE_MULTIPLIER);
    try {
      appendMap(buf, map);
    } catch (IOException e) {
      // Shouldn't ever happen unless someone adds something to append*.
      throw new RuntimeException(e);
    }
    return buf.toString();
  }

  /**
   * Serializes a Collection as a JSON array. Does not guard against cyclical references.
   */
  public static String serialize(Collection<? extends Object> collection) {
    StringBuilder buf = new StringBuilder(collection.size() * BASE_MULTIPLIER);
    try {
      appendCollection(buf, collection);
    } catch (IOException e) {
      // Shouldn't ever happen unless someone adds something to append*.
      throw new RuntimeException(e);
    }
    return buf.toString();
  }

  /**
   * Serializes an array as a JSON array. Does not guard against cyclical references
   */
  public static String serialize(Object[] array) {
    StringBuilder buf = new StringBuilder(array.length * BASE_MULTIPLIER);
    try {
      appendArray(buf, array);
    } catch (IOException e) {
      // Shouldn't ever happen unless someone adds something to append*.
      throw new RuntimeException(e);
    }
    return buf.toString();
  }

  /**
   * Serializes a JSON array. Does not guard against cyclical references
   */
  public static String serialize(JSONArray array) {
    StringBuilder buf = new StringBuilder(array.length() * BASE_MULTIPLIER);
    try {
      appendJsonArray(buf, array);
    } catch (IOException e) {
      // Shouldn't ever happen unless someone adds something to append*.
      throw new RuntimeException(e);
    }
    return buf.toString();
  }

  /**
   * Appends a value to the buffer.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  @SuppressWarnings("unchecked")
  public static void append(Appendable buf, Object value) throws IOException {
    if (value == null) {
      buf.append("null");
    } else if (value instanceof JSONObject) {
      appendJsonObject(buf, (JSONObject)value);
    } else if (value instanceof String) {
      appendString(buf, (String)value);
    } else if (value instanceof Number || value instanceof Boolean) {
      buf.append(value.toString());
    } else if (value instanceof JSONArray) {
      buf.append(value.toString());
    } else if (value instanceof Map) {
      appendMap(buf, (Map<String, Object>)value);
    } else if (value instanceof Collection) {
      appendCollection(buf, (Collection<Object>)value);
    } else if (value.getClass().isArray()) {
      appendArray(buf, (Object[])value);
    } else {
      appendString(buf, value.toString());
    }
  }

  /**
   * Appends an array to the buffer.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  public static void appendArray(Appendable buf, Object[] array) throws IOException {
    buf.append('[');
    boolean firstDone = false;
    for (Object o : array) {
      if (firstDone) {
        buf.append(',');
      } else {
        firstDone = true;
      }
      append(buf, o);
    }
    buf.append(']');
  }

  /**
   * Append a JSONArray to the buffer.
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  public static void appendJsonArray(Appendable buf, JSONArray array) throws IOException {
    buf.append('[');
    boolean firstDone = false;
    for (int i = 0, j = array.length(); i < j; ++i) {
      if (firstDone) {
        buf.append(',');
      } else {
        firstDone = true;
      }
      append(buf, array.opt(i));
    }
    buf.append(']');
  }

  /**
   * Appends a Collection to the buffer.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  public static void appendCollection(Appendable buf, Collection<? extends Object> collection)
      throws IOException {
    buf.append('[');
    boolean firstDone = false;
    for (Object o : collection) {
      if (firstDone) {
        buf.append(',');
      } else {
        firstDone = true;
      }
      append(buf, o);
    }
    buf.append(']');
  }

  /**
   * Appends a Map to the buffer.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  public static void appendMap(Appendable buf, Map<String, ? extends Object> map)
      throws IOException {
    buf.append('{');
    boolean firstDone = false;
    for (Map.Entry<String, ? extends Object> entry : map.entrySet()) {
      if (firstDone) {
        buf.append(',');
      } else {
        firstDone = true;
      }
      appendString(buf, entry.getKey());
      buf.append(':');
      append(buf, entry.getValue());
    }
    buf.append('}');
  }

  /**
   * Appends a JSONObject to the buffer.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  @SuppressWarnings("unchecked")
  public static void appendJsonObject(Appendable buf, JSONObject object) throws IOException {
    buf.append('{');
    Iterator<String> keys = object.keys();
    boolean firstDone = false;
    while (keys.hasNext()) {
      if (firstDone) {
        buf.append(',');
      } else {
        firstDone = true;
      }
      String key = keys.next();
      appendString(buf, key);
      buf.append(':');
      append(buf, object.opt(key));
    }
    buf.append('}');
  }

  /**
   * Appends a string to the buffer. The string will be JSON encoded and enclosed in quotes.
   *
   * @throws IOException If {@link Appendable#append(char)} throws an exception.
   */
  public static void appendString(Appendable buf, CharSequence string) throws IOException {
    if (string == null || string.length() == 0) {
      buf.append("\"\"");
      return;
    }

    char previous, current = 0;
    buf.append('"');
    for (int i = 0, j = string.length(); i < j; ++i) {
      previous = current;
      current = string.charAt(i);
      switch (current) {
        case '\\':
        case '"':
          buf.append('\\');
          buf.append(current);
          break;
        case '/':
          if (previous == '<') {
            buf.append('\\');
          }
          buf.append(current);
          break;
        default:
          if (current < ' ' || (current >= '\u0080' && current < '\u00a0') ||
              (current >= '\u2000' && current < '\u2100')) {
            buf.append('\\');
            switch (current) {
              case '\b':
                buf.append('b');
                break;
              case '\t':
                buf.append('t');
                break;
              case '\n':
                buf.append('n');
                break;
              case '\f':
                buf.append('f');
                break;
              case '\r':
                buf.append('r');
                break;
              default:
                // The three possible alternative approaches for dealing with unicode characters are
                // as follows:
                // Method 1 (from json.org.JSONObject)
                // 1. Append "000" + Integer.toHexString(current)
                // 2. Truncate this value to 4 digits by using value.substring(value.length() - 4)
                //
                // Method 2 (from net.sf.json.JSONObject)
                // This method is fairly unique because the entire thing uses an intermediate fixed
                // size buffer of 1KB. It's an interesting approach, but overall performs worse than
                // org.json
                // 1. Append "000" + Integer.toHexString(current)
                // 2. Append value.charAt(value.length() - 4)
                // 2. Append value.charAt(value.length() - 3)
                // 2. Append value.charAt(value.length() - 2)
                // 2. Append value.charAt(value.length() - 1)
                //
                // Method 3 (previous experiment)
                // 1. Calculate Integer.hexString(current)
                // 2. for (int i = 0; i < 4 - value.length(); ++i) { buf.append('0'); }
                // 3. buf.append(value)
                //
                // Method 4 (Sun conversion from java.util.Properties)
                // 1. Append '\'
                // 2. Append 'u'
                // 3. Append each of 4 octets by indexing into a hex array.
                //
                // Method 5
                // Index into a single lookup table of all relevant lookup values.
                buf.append('u');
                buf.append(HEX_DIGITS[(current >> 12) & 0xF]);
                buf.append(HEX_DIGITS[(current >>  8) & 0xF]);
                buf.append(HEX_DIGITS[(current >>  4) & 0xF]);
                buf.append(HEX_DIGITS[current & 0xF]);
             }
          } else {
            buf.append(current);
          }
      }
    }
    buf.append('"');
  }
}


text:
{% if jekyll.environment == "production" %}
  {% assign css-files = site.static_files | where: "dist-css", true %}
{% else %}
  {% assign css-files = site.static_files | where: "dev-css", true %}
{% endif %}

{% for css in css-files %}
  <link rel="stylesheet" href="{{ site.baseurl }}{{ css.path }}"{% if css.path contains "print" %} media="print"{% endif %}>
{% endfor %}


text: chmod 000 directory_name


text: unsplash_download /unsplash %1 %2


text:
<macros>
    <token name="@VERSION@">5.0.3</token>
    <xml name="requirements">
        <requirements>
            <requirement type="package" version="@VERSION@">cat</requirement>
            <yield/>
        </requirements>
    </xml>
    <xml name="version_command">
        <version_command><![CDATA[CAT --version]]></version_command>
    </xml>
    <token name="@DATABASE_FOLDER@">CAT_database</token>
    <token name="@TAXONOMY_FOLDER@">taxonomy</token>
    <xml name="cat_db">
        <conditional name="db">
            <param name="db_src" type="select" label="CAT database (--database_folder,--taxonomy_folder) from">
                <option value="cached">local cached database</option>
                <option value="history">history</option>
            </param>
            <when value="cached">
                <param name="cat_builtin" type="select" label="Use a built-in CAT database" help="If the CAT database of interest is not listed, contact your Galaxy administrator">
                    <options from_data_table="cat_database">
                        <filter type="sort_by" column="2" />
                        <validator type="no_options" message="No CAT database is available." />
                    </options>
                </param>
            </when>
            <when value="history">
                <param name="cat_db" type="data" format="txt" label="A history dataset from CAT prepare tool"/>
            </when>
        </conditional>
    </xml>
    <token name="@CAT_DB@"><![CDATA[
        #if $db.db_src == 'cached':
        --database_folder '$db.cat_builtin.fields.database_folder'
        --taxonomy_folder '$db.cat_builtin.fields.taxonomy_folder'
        #else
        #import os.path
        #set $catdb = $db.cat_db.extra_files_path
        --database_folder '$os.path.join($catdb,"@DATABASE_FOLDER@")'
        --taxonomy_folder '$os.path.join($catdb,"@TAXONOMY_FOLDER@")'
        #end if
]]></token>
    <token name="@CAT_TAXONOMY@"><![CDATA[
        #if $db.db_src == 'cached':
        --taxonomy_folder '$db.cat_builtin.fields.taxonomy_folder'
        #else
        #import os.path
        #set $catdb = $db.cat_db.extra_files_path
        --taxonomy_folder '$os.path.join($catdb,"@TAXONOMY_FOLDER@")'
        #end if
]]></token>
    <xml name="test_catdb">
        <conditional name="db">
            <param name="db_src" value="cached"/>
            <param name="cat_builtin" value="CAT_prepare_test"/>
        </conditional>
    </xml>
    <xml name="use_intermediates">
        <conditional name="previous">
            <param name="use_previous" type="select" label="Use previous prodigal gene prediction and diamond alignment">
                <help>predicted_proteins.faa and alignment.diamond from previous CAT run.</help>
                <option value="yes">Yes</option>
                <option value="no" selected="true">No</option>
            </param>
            <when value="yes">
                <param argument="--proteins_fasta" type="data" format="fasta" label="prodigal predicted proteins fasta"/>
                <param argument="--diamond_alignment" type="data" format="tabular" label="alignment.diamond file"/>
            </when>
            <when value="no"/>
        </conditional>
    </xml>
    <token name="@USE_INTERMEDIATES@"><![CDATA[
      #if $previous.use_previous == 'yes'
      --proteins_fasta '$previous.proteins_fasta'
      --diamond_alignment '$previous.diamond_alignment'
      #end if
      --out_prefix 'cat_output'
]]></token>
    <xml name="custom_settings_bins">
        <param argument="--range" type="integer" value="5" min="0" max="49" label="range"/>
        <param argument="--fraction" type="float" value="0.3" min="0" max="0.99" label="fraction"/>
    </xml>
    <xml name="custom_settings_contigs">
        <param argument="--range" type="integer" value="10" min="0" max="49" label="range"/>
        <param argument="--fraction" type="float" value="0.5" min="0" max="0.99" label="fraction"/>
    </xml>
    <token name="@CUSTOM_SETTINGS@"><![CDATA[
      --range '$range'
      --fraction '$fraction'
]]></token>
    <xml name="diamond_options">
        <conditional name="diamond">
            <param name="set_diamond_opts" type="select" label="Set advanced diamond options">
                <option value="yes">Yes</option>
                <option value="no" selected="true">No</option>
            </param>
            <when value="yes">
                <param argument="--sensitive" type="boolean" truevalue="--sensitive" falsevalue="" checked="false"
                    label="Run DIAMOND in sensitive mode (considerably slower)"/>
                <param argument="--block_size" type="float" value="2.0" min="1" max="10" label="DIAMOND block-size parameter."
                    help="lower will decrease memory and temporary disk space usage, higher will increase performance."/>
                <param argument="--index_chunks" type="integer" value="4" min="1" max="10" label="DIAMOND index-chunks parameter"
                    help="Set to 1 on high memory machines. The parameter has no effect on temporary disk space usage."/>
                <param argument="--top" type="integer" value="50" min="1" max="50" label="DIAMOND top parameter"
                    help="Governs hits within range of best hit that are written to the alignment file. This implies you know what you are doing."/>
            </when>
            <when value="no"/>
        </conditional>
    </xml>
    <token name="@DIAMOND_OPTIONS@"><![CDATA[
        #if $diamond.set_diamond_opts == 'yes':
            $diamond.sensitive
            --block_size '$diamond.block_size'
            --index_chunks '$diamond.index_chunks'
            #if $diamond.top < 50:
                --I_know_what_Im_doing
                --top '$diamond.top'
            #end if
        #end if
]]></token>

    <xml name="add_names_options">
        <param argument="--only_official" type="boolean" truevalue="--only_official" falsevalue="" checked="true"
            label="Only output official level names."/>
        <param argument="--exclude_scores" type="boolean" truevalue="--exclude_scores" falsevalue="" checked="false"
            label="Exclude bit-score support scores in the lineage."/>
    </xml>
    <token name="@ADD_NAMES_OPTIONS@"><![CDATA[
    $only_official $exclude_scores
]]></token>
    <xml name="add_names">
        <conditional name="names">
            <param name="add_names" type="select" label="CAT add_names for"
                help="annotate with taxonomic names.">
                <option value="no">No</option>
                <option value="orf2lca">ORF2LCA.names.txt</option>
                <option value="classification">classification.names.txt</option>
                <option value="both">ORF2LCA.names.txt and classification.names.txt</option>
            </param>
            <when value="no"/>
            <when value="orf2lca">
                <expand macro="add_names_options"/>
            </when>
            <when value="classification">
                <expand macro="add_names_options"/>
            </when>
            <when value="both">
                <expand macro="add_names_options"/>
            </when>
        </conditional>
    </xml>
    <token name="@TXT2TSV@">${__tool_directory__}/tabpad.py</token>
    <token name="@ADD_NAMES@"><![CDATA[
    #if $names.add_names in ['classification','both']:
        && CAT add_names $names.only_official $names.exclude_scores
            @CAT_TAXONOMY@
            #if $bcat == 'CAT'
                -i 'cat_output.contig2classification.tsv'
            #else
                -i 'cat_output.bin2classification.tsv'
            #end if
            -o 'classification_names.txt'
        && ${__tool_directory__}/tabpad.py -i 'classification_names.txt' -o '$classification_names'
    #end if
    #if $names.add_names in ['orf2lca','both']:
        && CAT add_names $names.only_official $names.exclude_scores
            @CAT_TAXONOMY@
            -i 'cat_output.ORF2LCA.tsv'
            -o 'orf2lca_names.txt'
        && ${__tool_directory__}/tabpad.py -i 'orf2lca_names.txt' -o '$orf2lca_names'
    #end if
]]></token>
    <xml name="summarise">
        <param name="summarise" type="select" label="CAT summarise report"
            help="Report the number of assignments to each taxonomic name">
            <option value="no">No</option>
            <option value="classification">classification.summary.txt</option>
        </param>
    </xml>
    <token name="@SUMMARISE@"><![CDATA[
    #if $summarise in ['classification']:
        #if $names.add_names in ['classification','both'] and $names.only_official:
            #set $summary_input = $classification_names
        #else
            #set $summary_input = 'classification_offical_names'
            && CAT add_names --only_official
                @CAT_TAXONOMY@
                #if $bcat == 'CAT'
                    -i 'cat_output.contig2classification.tsv'
                #else
                    -i 'cat_output.bin2classification.tsv'
                #end if
                -o '$summary_input'
        #end if
        && CAT summarise
            #if $bcat == 'CAT'
                -c '$contigs_fasta'
            #end if
            -i '$summary_input'
            -o 'classification_summary.txt'
        && ${__tool_directory__}/tabpad.py -i 'classification_summary.txt' -o '$classification_summary'
    #end if
]]></token>

    <xml name="select_outputs">
        <param name="select_outputs" type="select" multiple="true" optional="false" label="Select outputs">
            <option value="log" selected="true">log</option>
            <option value="predicted_proteins_faa" selected="true">Prodigal predicted_proteins.faa</option>
            <option value="predicted_proteins_gff">Prodigal predicted_proteins.gff</option>
            <option value="alignment_diamond">Diamond blastp alignment.diamond</option>
            <option value="orf2lca" selected="true">ORF2LCA.txt (taxonomic assignment per predicted ORF)</option>
            <yield/>
        </param>
    </xml>
    <xml name="select_cat_outputs">
        <param name="bcat" type="hidden" value="CAT"/>
        <param name="seqtype" type="hidden" value="contig"/>
        <param name="sum_titles" type="hidden" value="contigs,number of ORFs,number of positions"/>
        <param name="bin_col" type="hidden" value=""/>
        <expand macro="select_outputs">
            <option value="contig2classification" selected="true">contig2classification.txt (taxonomic assignment per contig)</option>
        </expand>
    </xml>
    <xml name="select_bat_outputs">
        <param name="bcat" type="hidden" value="BAT"/>
        <param name="seqtype" type="hidden" value="bin"/>
        <param name="sum_titles" type="hidden" value="bins"/>
        <param name="bin_col" type="hidden" value="bin,"/>
        <expand macro="select_outputs">
            <option value="bin2classification" selected="true">bin2classification.txt (taxonomic assignment per metagenome assembly)</option>
        </expand>
    </xml>
    <xml name="outputs">
        <data name="log" format="txt" label="${bcat}.log" from_work_dir="cat_output.log">
            <filter>'log' in select_outputs or not select_outputs</filter>
        </data>
        <data name="predicted_proteins_faa" format="fasta" label="${bcat}.predicted_proteins.faa" from_work_dir="cat_output.predicted_proteins.faa">
            <filter>'predicted_proteins_faa' in select_outputs and previous['use_previous'] == 'no'</filter>
        </data>
        <data name="predicted_proteins_gff" format="gff" label="${bcat}.predicted_proteins.gff" from_work_dir="cat_output.predicted_proteins.gff">
            <filter>'predicted_proteins_gff' in select_outputs and previous['use_previous'] == 'no'</filter>
        </data>
        <data name="alignment_diamond" format="tabular" label="${bcat}.alignment.diamond" from_work_dir="cat_output.alignment.diamond">
            <filter>'alignment_diamond' in select_outputs and previous['use_previous'] == 'no'</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="qseqid,sseqid,pident,length,mismatch,gapopen,qstart,qend,sstart,send,evalue,bitscore" />
            </actions>
        </data>
        <data name="orf2lca" format="tabular" label="${bcat}.ORF2LCA.txt" from_work_dir="cat_output.ORF2LCA.tsv">
            <filter>'orf2lca' in select_outputs</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="ORF,${bin_col}lineage,bit-score" />
            </actions>
        </data>
        <data name="contig2classification" format="tabular" label="${bcat}.contig2classification.txt" from_work_dir="cat_output.contig2classification.tsv">
            <filter>'contig2classification' in select_outputs</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="contig,classification,reason,lineage,lineage scores" />
            </actions>
        </data>
        <data name="bin2classification" format="tabular" label="${bcat}.bin2classification.txt" from_work_dir="cat_output.bin2classification.tsv">
            <filter>'bin2classification' in select_outputs</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="bin,classification,reason,lineage,lineage scores" />
            </actions>
        </data>
        <data name="orf2lca_names" format="tabular" label="${bcat}.ORF2LCA.names.txt">
            <filter>names['add_names'] in ['both','orf2lca']</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="ORF,${bin_col}lineage,bit-score,superkingdom,phylum,class,order,family,genus,species" />
            </actions>
        </data>
        <data name="classification_names" format="tabular" label="${bcat}.${seqtype}2classification.names.txt">
            <filter>names['add_names'] in ['both','classification']</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="1" />
                <action name="column_names" type="metadata" default="${seqtype},classification,reason,lineage,lineage scores,superkingdom,phylum,class,order,family,genus,species" />
            </actions>
        </data>
        <data name="classification_summary" format="tabular" label="${bcat}.${seqtype}2classification.summary.txt">
            <filter>'classification' in summarise</filter>
            <actions>
                <action name="comment_lines" type="metadata" default="4" />
                <action name="column_names" type="metadata" default="rank,clade,number of ${sum_titles}" />
            </actions>
        </data>
    </xml>
    <token name="@COMMON_HELP@"><![CDATA[
The Contig Annotation Tool (CAT) and Bin Annotation Tool (BAT) workflows are described at: https://github.com/dutilh/CAT

  - CAT contigs/CAT bins - runs Prodigal_ prokaryotic protein prediction on the fasta input.
  - CAT contigs/CAT bins - runs Diamond_ to align predicted proteins to the reference proteins in the CAT database.
  - CAT contigs/CAT bins - assigns taxonomic classification to fasta entries and ORFs based on alignments.
  - CAT add_names - annotates outputs with taxonomic names.
  - CAT summerise - reports number of assignments to each taxonomic name.

A CAT database can either be installed by data_manager_cat or in the local history by CAT prepare tool.

.. _Prodigal: https://github.com/hyattpd/Prodigal
.. _Diamond: https://github.com/bbuchfink/diamond

]]></token>
    <token name="@OUTPUTS_HELP@"><![CDATA[

**OUTPUTS**

Any of the files produced by the CAT workflow are available as outputs
  - Prodigal

    - predicted_proteins.faa
    - predicted_proteins.gff

  - Diamond

    - alignment.diamond

  - CAT contigs/bins

    - contigs/bin2classification.txt
    - ORF2LCA.txt

  - CAT add_names (optional)

    - contigs/bin2classification.names.txt
    - ORF2LCA.names.txt

  - CAT summarise (optional)

    - contigs/bin2classification.summary.txt

]]></token>

    <token name="@OPTIONS_HELP@"><![CDATA[

Optional arguments:
  -r, --range               cut-off range after alignment [0-49] (default: 10).
  -f, --fraction            fraction of bit-score support for each classification
                            [0-0.99] (default: 0.5).
  -p, --proteins_fasta
                            Path to predicted proteins fasta file. If supplied,
                            CAT will skip the protein prediction step.
  -a, --diamond_alignment
                            Path to DIAMOND alignment table. If supplied, CAT will
                            skip the DIAMOND alignment step and directly classify
                            the sequences. A predicted proteins fasta file should
                            also be supplied with argument [-p / --proteins].

DIAMOND specific optional arguments:
  --sensitive     Run DIAMOND in sensitive mode (default: not enabled).

  --block_size    DIAMOND block-size parameter (default: 2.0). Lower
                  numbers will decrease memory and temporary disk space
                  usage.

  --index_chunks
                  DIAMOND index-chunks parameter (default: 4). Set to 1
                  on high memory machines. The parameter has no effect
                  on temporary disk space usage.

  --top
                  DIAMOND top parameter [0-50] (default: 50). Governs
                  hits within range of best hit that are written to the
                  alignment file. This is not the [-r / --range]
                  parameter!

Setting the DIAMOND --top parameter

You can speed up DIAMOND considerably, and at the same time greatly reduce disk usage, by setting the DIAMOND --top parameter to lower values. This will govern hits within range of the best hit that are written to the alignment file.

You have to be very carefull to 1) not confuse this parameter with the r / --range parameter, which does a similar cut-off but after alignment and 2) be aware that if you want to run CAT or BAT again afterwards with different values of the -r / --range parameter, your options will be limited to the range you have chosen with --top earlier, because all hits that fall outside this range will not be included in the alignment file. Importantly, CAT and BAT currently do not warn you if you choose -r / --range in a second run higher than --top in a previous one, so it's up to you to remember this!

If you have understood all this, or you do not plan to tune -r / --range at all afterwards, you can enjoy a huge speedup with much smaller alignment files! For CAT you can for example set --top 11 and for BAT --top 6.

]]></token>
    <xml name="citations">
        <citations>
            <citation type="doi">https://doi.org/10.1101/072868</citation>
            <citation type="doi">https://doi.org/10.1186/s13059-019-1817-x</citation>
            <citation type="doi">https://doi.org/10.1038/nmeth.3176</citation>
            <citation type="doi">https://doi.org/10.1186/1471-2105-11-119</citation>
            <yield />
        </citations>
    </xml>
</macros>


text:
<todo>

{opts.title}

        <input type="checkbox" checked={done} id="todo-checkbox"
          onclick={parent.toggle}>

  <form onsubmit={add}>
    <input type="button" name="input" onkeyup={edit}>
    <button disabled={!text}>Add #{items.filter(filter).length + 1}</button>
  </form>

</todo>


text:
package chapter1;

import base.Question;

import java.util.Arrays;

public class ArrayList1_UniqueChars implements Question {
    @Override
    public void run() {

        // 1.1 Determine if string characters are all unique.
        String input = "dd";

        int current=0, next=1;
        // initialize
        boolean hasDifference=false;
        if(input.length() != 1){
            // Sort the input first.
            char sorted[]  = input.toCharArray();
            Arrays.sort(sorted);

            for(int i=0; i < input.length()-1; i++){

                // Check
                if(sorted[current] == sorted[next]) {
                    hasDifference=true;
                    break;
                }

                // Advance pointers
                current++;
                next ++;
            }
        }
        if(hasDifference) System.out.println("String is not unique");
        else System.out.println("String is unique");
    }
}


text:
module TestSuite

export supported_eltypes

using GPUArrays

using LinearAlgebra
using Random
using Test

using Adapt

struct ArrayAdaptor{AT} end
Adapt.adapt_storage(::ArrayAdaptor{AT}, xs::AbstractArray) where {AT} = AT(xs)

test_result(a::Number, b::Number; kwargs...) = ≈(a, b; kwargs...)
test_result(a::Missing, b::Missing; kwargs...) = true
test_result(a::Number, b::Missing; kwargs...) = false
test_result(a::Missing, b::Number; kwargs...) = false
function test_result(a::AbstractArray{T}, b::AbstractArray{T}; kwargs...) where {T<:Number}
    ≈(collect(a), collect(b); kwargs...)
end
function test_result(a::AbstractArray{T}, b::AbstractArray{T};
                     kwargs...) where {T<:NTuple{N,<:Number} where {N}}
    ET = eltype(T)
    ≈(reinterpret(ET, collect(a)), reinterpret(ET, collect(b)); kwargs...)
end
function test_result(as::NTuple{N,Any}, bs::NTuple{N,Any}; kwargs...) where {N}
    all(zip(as, bs)) do (a, b)
        test_result(a, b; kwargs...)
    end
end

function compare(f, AT::Type{<:AbstractGPUArray}, xs...; kwargs...)
    # copy on the CPU, adapt on the GPU, but keep Ref's
    cpu_in = map(x -> isa(x, Base.RefValue) ? x[] : deepcopy(x), xs)
    gpu_in = map(x -> isa(x, Base.RefValue) ? x[] : adapt(ArrayAdaptor{AT}(), x), xs)

    cpu_out = f(cpu_in...)
    gpu_out = f(gpu_in...)

    test_result(cpu_out, gpu_out; kwargs...)
end

function compare(f, AT::Type{<:Array}, xs...; kwargs...)
    # no need to actually run this tests: we have nothing to compoare against,
    # and we'll run it on a CPU array anyhow when comparing to a GPU array.
    #
    # this method exists so that we can at least run the test suite with Array,
    # and make sure we cover other tests (that don't call `compare`) too.
    return true
end

# element types that are supported by the array type
supported_eltypes(AT, test) = supported_eltypes(AT)
supported_eltypes(AT) = supported_eltypes()
supported_eltypes() = (Int16, Int32, Int64,
                       Float16, Float32, Float64,
                       ComplexF16, ComplexF32, ComplexF64,
                       Complex{Int16}, Complex{Int32}, Complex{Int64})

# some convenience predicates for filtering test eltypes
isrealtype(T) = T <: Real
iscomplextype(T) = T <: Complex
isrealfloattype(T) = T <: AbstractFloat
isfloattype(T) = T <: AbstractFloat || T <: Complex{<:AbstractFloat}

# list of tests
const tests = Dict()
macro testsuite(name, ex)
    safe_name = lowercase(replace(replace(name, " "=>"_"), "/"=>"_"))
    fn = Symbol("test_$(safe_name)")
    quote
        # the supported element types can be overrided by passing in a different set,
        # or by specializing the `supported_eltypes` function on the array type and test.
        $(esc(fn))(AT; eltypes=supported_eltypes(AT, $(esc(fn)))) = $(esc(ex))(AT, eltypes)

        @assert !haskey(tests, $name)
        tests[$name] = $fn
    end
end

include("testsuite/construction.jl")
include("testsuite/gpuinterface.jl")
include("testsuite/indexing.jl")
include("testsuite/base.jl")
#include("testsuite/vector.jl")
include("testsuite/reductions.jl")
include("testsuite/broadcasting.jl")
include("testsuite/linalg.jl")
include("testsuite/math.jl")
include("testsuite/random.jl")
include("testsuite/uniformscaling.jl")
include("testsuite/statistics.jl")

"""
Runs the entire GPUArrays test suite on array type `AT`
"""
function test(AT::Type)
    for (name, fun) in tests
        code = quote
            $fun($AT)
        end
        @eval @testset $name $code
    end
end

end


text:
Migrate [espower-babel](https://github.com/power-assert-js/espower-babel "espower-babel") to [babel-preset-power-assert](https://github.com/power-assert-js/babel-preset-power-assert "babel-preset-power-assert").

## Target User

- Using `espower-babel`
- Having `test/mocha.opts`
- Using Babel >= 6

## Installation

    npm install -g migrate-espower-babel-to-babel-preset-power-assert

## Usage

```sh
$ cd project-root-dir/
$ migrate-espower-babel-to-babel-preset-power-assert

Run: npm uninstall -D espower-babel
Run: npm install -D power-assert
Run: npm install -D babel-preset-power-assert
Run: npm install -D babel-register
rewrite mocha.opts
rewrite .babelrc
```

### Before

- using espower-babel

### After

- using babel-register
- using babel-preset-power-assert

## Example

```diff
diff --git a/.babelrc b/.babelrc
index ba2a650..e7e1682 100644
--- a/.babelrc
+++ b/.babelrc
@@ -6,6 +6,9 @@
     "development": {
       "plugins": [
         "jsdoc-to-assert"
+      ],
+      "presets": [
+        "power-assert"
       ]
     }
   }
diff --git a/package.json b/package.json
index ebafaf5..e5e1216 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,8 @@
     "babel-plugin-add-module-exports": "^0.1.2",
     "babel-plugin-jsdoc-to-assert": "^1.4.0",
     "babel-preset-es2015": "^6.6.0",
-    "espower-babel": "^4.0.1",
+    "babel-preset-power-assert": "^1.0.0",
+    "babel-register": "^6.7.2",
     "espower-loader": "^1.0.0",
     "mocha": "^2.2.1",
     "power-assert": "^1.0.0",
diff --git a/test/mocha.opts b/test/mocha.opts
index 8d0282d..b76d223 100644
--- a/test/mocha.opts
+++ b/test/mocha.opts
@@ -1 +1 @@
---compilers js:espower-babel/guess
\ No newline at end of file
+--compilers js:babel-register
\ No newline at end of file
```

See real commit:

- [chore(npm): use babel-preset-power-assert by azu · Pull Request #25 · azu/material-flux](https://github.com/azu/material-flux/pull/25 "chore(npm): use babel-preset-power-assert by azu · Pull Request #25 · azu/material-flux")
- [chore(test): use power-assert preset · azu/match-index@f4f6df8](https://github.com/azu/match-index/commit/f4f6df88ae39a2eb8eab0a13e121f27305085aa3 "chore(test): use power-assert preset · azu/match-index@f4f6df8")

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT


text:
<?php
/**
 * This is a generic Cache Driver for TPCache
 *
 * @author James Thompson
 * @package Tikapot\Framework
 */

abstract class CacheDriver
{
	/**
	 * Is this cache driver available?
	 *
	 * @param array $settings The settings to check with
	 * @return boolean True/False
	 */
	public abstract function available($settings);

	/**
	 * Returns the raw engine
	 *
	 * @return Mixed
	 */
	public abstract function getEngine();

	/**
	 * Get a key from the cache
	 *
	 * @param string $key The key to use
	 * @return Mixed The value related to the key or null if no value was associated
	 */
	public abstract function get($key);

	/**
	 * Set a key on the cache
	 *
	 * @param string $key The key to use
	 * @param string $value The value to use
	 * @param string $expire The expiry time to use, should be (time() + milliseconds)
	 * @return boolean True if success, false if failure
	 */
	public abstract function set($key, $value, $expire = 0);

	/**
	 * Delete a key from the cache
	 *
	 * @param string $key The key to use
	 * @return null
	 */
	public abstract function delete($key);
}


text:
from msrest.serialization import Model

class Resource(Model):
    """The Azure Resource Manager resource.

    Variables are only populated by the server, and will be ignored when
    sending a request.

    :ivar id: The id of the resource.
    :vartype id: str
    :ivar name: The name of the resource.
    :vartype name: str
    :ivar type: The type of the resource
    :vartype type: str
    :param location: The geographic location of the resource. This must be one
     of the supported and registered Azure Geo Regions (for example, West US,
     East US, Southeast Asia, and so forth).
    :type location: str
    :param tags: Tags to help categorize the resource in the Azure portal.
    :type tags: dict
    """

    _validation = {
        'id': {'readonly': True},
        'name': {'readonly': True},
        'type': {'readonly': True},
    }

    _attribute_map = {
        'id': {'key': 'id', 'type': 'str'},
        'name': {'key': 'name', 'type': 'str'},
        'type': {'key': 'type', 'type': 'str'},
        'location': {'key': 'location', 'type': 'str'},
        'tags': {'key': 'tags', 'type': '{str}'},
    }

    def __init__(self, location=None, tags=None):
        self.id = None
        self.name = None
        self.type = None
        self.location = location
        self.tags = tags


text:
package v1

import (
	"github.com/coreos/etcd/store"
	"github.com/coreos/etcd/third_party/github.com/coreos/raft"
	"net/http"
)

// The Server interface provides all the methods required for the v1 API.
type Server interface {
	CommitIndex() uint64
	Term() uint64
	Store() store.Store
	Dispatch(raft.Command, http.ResponseWriter, *http.Request) error
}


text:
from django.utils.translation import gettext_lazy as _

from fluent_contents.extensions import plugin_pool, ContentPlugin

from bluebottle.pages.models import ImageTextItem, DocumentItem, ActionItem, ColumnsItem, ImageTextRoundItem

@plugin_pool.register
class ImageTextPlugin(ContentPlugin):
    model = ImageTextItem
    render_template = "pages/plugins/imagetext/default.html"
    category = _("Multimedia")

@plugin_pool.register
class ImageTextRoundPlugin(ContentPlugin):
    model = ImageTextRoundItem
    render_template = "pages/plugins/imagetext/default.html"
    category = _("Multimedia")

@plugin_pool.register
class DocumentPlugin(ContentPlugin):
    model = DocumentItem
    render_template = "pages/plugins/document/default.html"
    category = _("Multimedia")

@plugin_pool.register
class ActionPlugin(ContentPlugin):
    model = ActionItem
    render_template = "pages/plugins/action/default.html"
    category = _("Multimedia")

@plugin_pool.register
class ColumnsPlugin(ContentPlugin):
    model = ColumnsItem
    render_template = "pages/plugins/columns/default.html"
    category = _("Multimedia")


text:
package com.wangc;

import java.util.UUID;

/**
 * Created by wangchao on 2017/3/16.
 */
public class Test {
    public static void main(String[] args){
        System.out.println(UUID.randomUUID().toString().replace("-",""));
        System.out.println(UUID.randomUUID().toString().replace("-",""));
        System.out.println(UUID.randomUUID().toString().replace("-",""));
        System.out.println(UUID.randomUUID().toString().replace("-",""));

        String str ="{\"username\":\"JerryAndTom\",\"password\":\"123456\"" +
                ",\"email\":\"88888@qq.com\"}";

        System.out.println(str);
    }
}


text:
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router, Route} from 'react-router-dom';
import injectTapEventPlugin from 'react-tap-event-plugin';
import './index.css';
import routes from './routes'
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import {grey800} from 'material-ui/styles/colors';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import ligthBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
//import $ from 'jquery';

const muiTheme = getMuiTheme({
  palette: {
    textColor: grey800,
  }
});

injectTapEventPlugin();

ReactDOM.render(
  <MuiThemeProvider muiTheme={getMuiTheme(ligthBaseTheme)}>
    <App/>
  </MuiThemeProvider>, document.getElementById('root'));
registerServiceWorker();


text:
require 'rbbt-util'
require 'rbbt/workflow'
require 'rbbt/ner/segment/transformed'
require 'rbbt/ner/segment/docid'

$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))

Workflow.require_workflow "Genomics"
require 'rbbt/entity/pmid'
require 'factoid'

module Factoid
  extend Workflow

  CORPUS = Persist.open_tokyocabinet(File.join(File.dirname(__FILE__), 'corpora', 'Factoid.corpus'), false, :string, TokyoCabinet::BDB)
  ANNOTATION_REPO = Persist.open_tokyocabinet(File.join(File.dirname(__FILE__), 'annotations', 'Factoid.repo'), false, :list, TokyoCabinet::BDB)

  NORMALIZE = true
  ORGANISM = "Hsa/jun2011"

  input :text, :text, "Document text"
  returns "Document ID"
  task :add_doc => :string do |text|
    raise "No text provided: #{text}" if text.nil?
    text = Document.setup(text.dup)
    text.text
    text.docid
  end

  input :pmid, :string, "Pubmed ID"
  input :type, :string, "Type: abstract or full_text", :abstract
  returns "Document ID"
  task :add_pmid => :string do |pmid, type|
    pmid = PMID.setup(pmid.dup)
    pmid.text(type)
    pmid.docid(type)
  end

  input :list, :array, "Pubmed ID"
  input :type, :string, "Type: abstract or full_text", :abstract
  returns "Document ID"
  task :add_pmid_list => :yaml do |list, type|
    list = PMID.setup(list.dup)
    list.text(type)
    Misc.zip2hash(list, list.docid(type))
  end

  input :docid, :string, "Document ID"
  task :abner => :annotations do |docid|
    doc = Document.setup(docid)
    doc.abner(NORMALIZE, ORGANISM).each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  task :banner => :annotations do |docid|
    doc = Document.setup(docid)
    doc.banner(NORMALIZE, ORGANISM).each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  input :organism, :string, "Organism codes", "Hsa"
  input :ignore_case, :boolean, "Ignore case on matching", true
  task :gene_names => :annotations do |docid,organism,ignore_case|
    doc = Document.setup(docid)
    doc.dictionary(organism, ignore_case).each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  task :species => :annotations do |docid|
    doc = Document.setup(docid)
    doc.species.each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  input :format, :select, "Format to normalize to", "Compound Name", TextMining.task_info(:compound_mention_recognition)[:input_options][:format]
  task :jochem => :annotations do |docid, format|
    doc = Document.setup(docid)
    doc.jochem(format).each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  task :sentences => :annotations do |docid|
    doc = Document.setup(docid)
    doc.sentences.each{|a| SegmentWithDocid.setup(a, docid)}
  end

  input :docid, :string, "Document ID"
  input :entity_types, :array, "Entities to process", [:dictionary]
  task :sentence_html => :array do |docid, entity_types|
    doc = Document.setup(docid)
    entities = entity_types.inject([]){|acc,type| acc += doc.send(type)}

    entities.each{|a| SegmentWithDocid.setup(a, docid)}

    entity_index = Segment.index(entities, Rbbt.var.segment_indices[docid][entity_types.collect{|e| e.to_s}.sort * ","].find)

    sentences = doc.sentences
    sentences.collect{|sentence|
      entities = entity_index[sentence.range]
      entities = Segment.clean_sort(entities)
      Transformed.transform(sentence, entities) do |entity|
        entity.respond_to?(:link) ? entity.link : entity.html
      end
    }
  end

  export_exec :add_doc, :add_pmid, :add_pmid_list, :species, :gene_names, :abner, :banner, :jochem, :sentences, :sentence_html
end

module Document
  self.corpus = Factoid::CORPUS

  persist :abner, :annotations, :annotation_repo => Factoid::ANNOTATION_REPO
  persist :banner, :annotations, :annotation_repo => Factoid::ANNOTATION_REPO
  persist :dictionary, :annotations, :annotation_repo => Factoid::ANNOTATION_REPO
  persist :jochem, :annotations, :annotation_repo => Factoid::ANNOTATION_REPO
  persist :species, :annotations, :annotation_repo => Factoid::ANNOTATION_REPO
  persist :sentences, :annotations
end

if __FILE__ == $0
  #docid = Factoid.job(:add_pmid, '', :pmid => "21828143", :type => :full_text).exec
  docid = "PMID:21343549:full_text"
  ddd Factoid.job(:sentence_html, '', :docid => docid, :entity_types => [:dictionary, :abner, :banner, :jochem]).exec

end