text:
@implementation QFlatAppearance {

}
- (void)setDefaults {
    [super setDefaults];

    self.labelColorDisabled = [UIColor lightGrayColor];
    self.labelColorEnabled = [UIColor blackColor];

    self.actionColorDisabled = [UIColor lightGrayColor];
    self.actionColorEnabled = [UIColor blackColor];

    self.sectionTitleFont = nil;
    self.sectionTitleShadowColor = [UIColor clearColor];
    self.sectionTitleColor = nil;

    self.sectionFooterFont = nil;
    self.sectionFooterColor = [UIColor colorWithRed:0.2417 green:0.5295 blue:0.9396 alpha:1.0000];

    self.labelAlignment = NSTextAlignmentLeft;

    self.backgroundColorDisabled = [UIColor whiteColor];
    self.backgroundColorEnabled = [UIColor whiteColor];

    self.entryTextColorDisabled = [UIColor lightGrayColor];
    self.entryTextColorEnabled = [UIColor colorWithRed:0.243 green:0.306 blue:0.435 alpha:1.0];
    self.entryAlignment = NSTextAlignmentLeft;

    self.buttonAlignment = NSTextAlignmentLeft;

    self.valueColorEnabled = [UIColor colorWithRed:0.1653 green:0.2532 blue:0.4543 alpha:1.0000];
    self.valueColorDisabled = [UIColor lightGrayColor];
    self.valueAlignment = NSTextAlignmentRight;

    self.toolbarStyle = UIBarStyleDefault;
    self.toolbarTranslucent = YES;

    self.cellBorderWidth = 14;

#if __IPHONE_7_0
    if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) {
        self.valueFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        self.labelFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
        self.entryFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    }
#endif

}

- (UIView *)buildHeaderForSection:(QSection *)section andTableView:(QuickDialogTableView *)view andIndex:(NSInteger)index1 {
    return nil;
}

- (UIView *)buildFooterForSection:(QSection *)section andTableView:(QuickDialogTableView *)view andIndex:(NSInteger)index1 {
    return nil;
}

- (void)cell:(UITableViewCell *)cell willAppearForElement:(QElement *)element atIndexPath:(NSIndexPath *)path {
    [super cell:cell willAppearForElement:element atIndexPath:path];
}

- (CGFloat)heightForHeaderInSection:(QSection *)section andTableView:(QuickDialogTableView *)tableView andIndex:(NSInteger)index {
    if (section.headerView!=nil)
        return section.headerView.bounds.size.height;
    return [super heightForHeaderInSection:section andTableView:tableView andIndex:index];
}

@end


text:
package org.elasticsearch.action;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;

import java.io.IOException;

public class PrimaryMissingActionException extends ElasticsearchException {

    public PrimaryMissingActionException(String message) {
        super(message);
    }

    public PrimaryMissingActionException(StreamInput in) throws IOException {
        super(in);
    }
}

redpajama_set_name: RedPajamaGithub


text:
'use strict'
const TraceAnalyser = require('./traceAnalyser')
const TraceRetriever = require('./traceRetriever')
const TraceCache = require('./traceCache')
const TraceStepManager = require('./traceStepManager')

const traceHelper = require('../helpers/traceHelper')
const util = require('../util')

function TraceManager (options) {
  this.web3 = options.web3
  this.isLoading = false
  this.trace = null
  this.traceCache = new TraceCache()
  this.traceAnalyser = new TraceAnalyser(this.traceCache)
  this.traceRetriever = new TraceRetriever({web3: this.web3})
  this.traceStepManager = new TraceStepManager(this.traceAnalyser)
  this.tx
}

// init section
TraceManager.prototype.resolveTrace = function (tx, callback) {
  this.tx = tx
  this.init()
  if (!this.web3) callback('web3 not loaded', false)
  this.isLoading = true
  var self = this
  this.traceRetriever.getTrace(tx.hash, (error, result) => {
    if (error) {
      console.log(error)
      self.isLoading = false
      callback(error, false)
    } else {
      if (result.structLogs.length > 0) {
        self.trace = result.structLogs
        self.traceAnalyser.analyse(result.structLogs, tx, function (error, result) {
          if (error) {
            self.isLoading = false
            console.log(error)
            callback(error, false)
          } else {
            self.isLoading = false
            callback(null, true)
          }
        })
      } else {
        var mes = tx.hash + ' is not a contract invocation or contract creation.'
        console.log(mes)
        self.isLoading = false
        callback(mes, false)
      }
    }
  })
}

TraceManager.prototype.init = function () {
  this.trace = null
  this.traceCache.init()
}

// API section
TraceManager.prototype.inRange = function (step) {
  return this.isLoaded() && step >= 0 && step < this.trace.length
}

TraceManager.prototype.isLoaded = function () {
  return !this.isLoading && this.trace !== null
}

TraceManager.prototype.getLength = function (callback) {
  if (!this.trace) {
    callback('no trace available', null)
  } else {
    callback(null, this.trace.length)
  }
}

TraceManager.prototype.accumulateStorageChanges = function (index, address, storageOrigin, callback) {
  const storage = this.traceCache.accumulateStorageChanges(index, address, storageOrigin)
  callback(null, storage)
}

TraceManager.prototype.getAddresses = function (callback) {
  callback(null, this.traceCache.addresses)
}

TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  const callDataChange = util.findLowerBoundValue(stepIndex, this.traceCache.callDataChanges)
  if (callDataChange === null) return callback('no calldata found', null)
  callback(null, [this.traceCache.callsData[callDataChange]])
}

TraceManager.prototype.buildCallPath = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  const callsPath = util.buildCallPath(stepIndex, this.traceCache.callsTree.call)
  if (callsPath === null) return callback('no call path built', null)
  callback(null, callsPath)
}

TraceManager.prototype.getCallStackAt = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  const call = util.findCall(stepIndex, this.traceCache.callsTree.call)
  if (call === null) return callback('no callstack found', null)
  callback(null, call.callStack)
}

TraceManager.prototype.getStackAt = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  let stack
  if (this.trace[stepIndex] && this.trace[stepIndex].stack) { // there's always a stack
    stack = this.trace[stepIndex].stack.slice(0)
    stack.reverse()
    callback(null, stack)
  } else {
    callback('no stack found', null)
  }
}

TraceManager.prototype.getLastCallChangeSince = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  const callChange = util.findCall(stepIndex, this.traceCache.callsTree.call)
  if (callChange === null) {
    callback(null, 0)
  } else {
    callback(null, callChange)
  }
}

TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  this.getLastCallChangeSince(stepIndex, function (error, resp) {
    if (error) {
      callback(error, null)
    } else {
      if (resp) {
        callback(null, resp.address)
      } else {
        callback('unable to get current called address. ' + stepIndex + ' does not match with a CALL')
      }
    }
  })
}

TraceManager.prototype.getContractCreationCode = function (token, callback) {
  if (this.traceCache.contractCreation[token]) {
    callback(null, this.traceCache.contractCreation[token])
  } else {
    callback('no contract creation named ' + token, null)
  }
}

TraceManager.prototype.getMemoryAt = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  const lastChanges = util.findLowerBoundValue(stepIndex, this.traceCache.memoryChanges)
  if (lastChanges === null) return callback('no memory found', null)
  callback(null, this.trace[lastChanges].memory)
}

TraceManager.prototype.getCurrentPC = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  callback(null, this.trace[stepIndex].pc)
}

TraceManager.prototype.getReturnValue = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  if (!this.traceCache.returnValues[stepIndex]) {
    callback('current step is not a return step')
  } else {
    callback(null, this.traceCache.returnValues[stepIndex])
  }
}

TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  callback(null, this.traceCache.steps[stepIndex])
}

TraceManager.prototype.getMemExpand = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  callback(null, this.trace[stepIndex].memexpand ? this.trace[stepIndex].memexpand : '')
}

TraceManager.prototype.getStepCost = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  callback(null, this.trace[stepIndex].gasCost)
}

TraceManager.prototype.getRemainingGas = function (stepIndex, callback) {
  const check = this.checkRequestedStep(stepIndex)
  if (check) {
    return callback(check, null)
  }
  callback(null, this.trace[stepIndex].gas)
}

TraceManager.prototype.isCreationStep = function (stepIndex) {
  return traceHelper.isCreateInstruction(this.trace[stepIndex])
}

// step section
TraceManager.prototype.findStepOverBack = function (currentStep) {
  return this.traceStepManager.findStepOverBack(currentStep)
}

TraceManager.prototype.findStepOverForward = function (currentStep) {
  return this.traceStepManager.findStepOverForward(currentStep)
}

TraceManager.prototype.findNextCall = function (currentStep) {
  return this.traceStepManager.findNextCall(currentStep)
}

TraceManager.prototype.findStepOut = function (currentStep) {
  return this.traceStepManager.findStepOut(currentStep)
}

// util
TraceManager.prototype.checkRequestedStep = function (stepIndex) {
  if (!this.trace) {
    return 'trace not loaded'
  } else if (stepIndex >= this.trace.length) {
    return 'trace smaller than requested'
  }
  return undefined
}

TraceManager.prototype.waterfall = function (calls, stepindex, cb) {
  let ret = []
  let retError = null
  for (var call in calls) {
    calls[call].apply(this, [stepindex, function (error, result) {
      retError = error
      ret.push({ error: error, value: result })
    }])
  }
  cb(retError, ret)
}

module.exports = TraceManager


text:
package geomesa

package object core {

  // This first string is used as a SimpleFeature attribute name.
  //  Since we would like to be able to use ECQL filters, we are restricted to letters, numbers, and _'s.
  val DEFAULT_GEOMETRY_PROPERTY_NAME = "SF_PROPERTY_GEOMETRY"

  val DEFAULT_FEATURE_TYPE = "geomesa.feature.type"
  val DEFAULT_SCHEMA_NAME = "geomesa.index.schema"
  val DEFAULT_FEATURE_NAME = "geomesa.index.feature"
  val INGEST_TABLE_NAME = "geomesa.ingest.table"
  val DEFAULT_POLY_PROPERTY_NAME = "geomesa.index.poly"
  val DEFAULT_INTERVAL_PROPERTY_NAME = "geomesa.index.interval"
  val DEFAULT_ATTRIBUTE_NAMES = "geomesa.index.shapefile.attribute-names"
  val DEFAULT_CACHE_SIZE_NAME = "geomesa.index.cache-size"
  val DEFAULT_CACHE_TABLE_NAME = "geomesa.index.cache-table"
  val DEFAULT_AGGREGATOR_CLASS_PROPERTY_NAME = "geomesa.iterators.aggregator-class"

  val GEOMESA_ITERATORS_SIMPLE_FEATURE_TYPE = "geomesa.iterators.aggregator-types"
  val GEOMESA_ITERATORS_ECQL_FILTER = "geomesa.iterators.ecql-filter"

}


text:
#include <aws/gamelift/model/DescribeFleetPortSettingsResult.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/AmazonWebServiceResult.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/UnreferencedParam.h>

#include <utility>

using namespace Aws::GameLift::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
using namespace Aws;

DescribeFleetPortSettingsResult::DescribeFleetPortSettingsResult()
{
}

DescribeFleetPortSettingsResult::DescribeFleetPortSettingsResult(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  *this = result;
}

DescribeFleetPortSettingsResult& DescribeFleetPortSettingsResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
  JsonView jsonValue = result.GetPayload().View();
  if(jsonValue.ValueExists("InboundPermissions"))
  {
    Array<JsonView> inboundPermissionsJsonList = jsonValue.GetArray("InboundPermissions");
    for(unsigned inboundPermissionsIndex = 0; inboundPermissionsIndex < inboundPermissionsJsonList.GetLength(); ++inboundPermissionsIndex)
    {
      m_inboundPermissions.push_back(inboundPermissionsJsonList[inboundPermissionsIndex].AsObject());
    }
  }

  return *this;
}


text:
package io.druid.server.coordination;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;

import java.util.List;

/**
 * Return type of SegmentChangeRequestHistory.getRequestsSince(counter).
 */
public class SegmentChangeRequestsSnapshot
{
  //if true, that means caller should reset the counter and request again.
  private final boolean resetCounter;

  //cause for reset if resetCounter is true
  private final String resetCause;

  //segments requests delta since counter, if resetCounter if false
  private final SegmentChangeRequestHistory.Counter  counter;
  private final List<DataSegmentChangeRequest> requests;

  @JsonCreator
  public SegmentChangeRequestsSnapshot(
      @JsonProperty("resetCounter") boolean resetCounter,
      @JsonProperty("resetCause") String resetCause,
      @JsonProperty("counter") SegmentChangeRequestHistory.Counter counter,
      @JsonProperty("requests") List<DataSegmentChangeRequest> requests
  )
  {
    this.resetCounter = resetCounter;
    this.resetCause = resetCause;

    if (resetCounter) {
      Preconditions.checkNotNull(resetCause, "NULL resetCause when resetCounter is true.");
    }

    this.counter = counter;
    this.requests = requests;
  }

  public static SegmentChangeRequestsSnapshot success(SegmentChangeRequestHistory.Counter counter,
                                                      List<DataSegmentChangeRequest> requests)
  {
    return new SegmentChangeRequestsSnapshot(false, null, counter, requests);
  }

  public static SegmentChangeRequestsSnapshot fail(String resetCause)
  {
    return new SegmentChangeRequestsSnapshot(true, resetCause, null, null);
  }

  @JsonProperty
  public boolean isResetCounter()
  {
    return resetCounter;
  }

  @JsonProperty
  public String getResetCause()
  {
    return resetCause;
  }

  @JsonProperty
  public SegmentChangeRequestHistory.Counter getCounter()
  {
    return counter;
  }

  @JsonProperty
  public List<DataSegmentChangeRequest> getRequests()
  {
    return requests;
  }

  @Override
  public String toString()
  {
    return "SegmentChangeRequestsSnapshot{" +
           "resetCounter=" + resetCounter +
           ", resetCause='" + resetCause + '\'' +
           ", counter=" + counter +
           ", requests=" + requests +
           '}';
  }
}


text:
package org.apereo.cas.mfa.accepto;

import org.apereo.cas.authentication.credential.BasicIdentifiableCredential;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * This is {@link AccepttoMultifactorTokenCredential}.
 *
 * @author Misagh Moayyed
 * @since 6.1.0
 */
@ToString(callSuper = true)
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class AccepttoMultifactorTokenCredential extends BasicIdentifiableCredential {
    private static final long serialVersionUID = -4245622701132144037L;

    public AccepttoMultifactorTokenCredential(final String channel) {
        super(channel);
    }
}


text:
require 'aws-sdk-core'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'webmock/rspec'
require 'vcr'

WebMock.disable_net_connect!

VCR.configure do |c|
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
  c.hook_into :webmock
end

if ENV['PARSER'] == 'future'
  RSpec.configure do |c|
    c.parser = 'future'
  end
end

RSpec::Matchers.define :order_tags_on_output do |expected|
  match do |actual|
    tags = {'b' => 1, 'a' => 2}
    reverse = {'a' => 2, 'b' => 1}
    srv = actual.new(:name => 'sample', :tags => tags )
    expect(srv.property(:tags).insync?(tags)).to be true
    expect(srv.property(:tags).insync?(reverse)).to be true
    expect(srv.property(:tags).should_to_s(tags).to_s).to eq(reverse.to_s)
  end
  failure_message_for_should do |actual|
    "expected that #{actual} would order tags"
  end
end


text:
package com.evolveum.midpoint.web.page.admin.configuration.dto;

import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.QNameUtil;

import java.io.Serializable;

/**
 * @author lazyman
 */
public class InternalsConfigDto implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final String F_CONSISTENCY_CHECKS = "consistencyChecks";
    public static final String F_ENCRYPTION_CHECKS = "encryptionChecks";
    public static final String F_READ_ENCRYPTION_CHECKS = "readEncryptionChecks";
    public static final String F_MODEL_PROFILING = "modelProfiling";
    public static final String F_DETAILED_DEBUG_DUMP = "detailedDebugDump";
    public static final String F_TOLERATE_UNDECLARED_PREFIXES = "tolerateUndeclaredPrefixes";

    //internals config
    private boolean consistencyChecks;
    private boolean encryptionChecks;
    private boolean readEncryptionChecks;
    private boolean modelProfiling;
    //debug util
    private boolean detailedDebugDump;
    //DOM util
    private boolean tolerateUndeclaredPrefixes;

    public InternalsConfigDto() {
        consistencyChecks = InternalsConfig.isConsistencyChecks();
        encryptionChecks = InternalsConfig.isEncryptionChecks();
        readEncryptionChecks = InternalsConfig.isReadEncryptionChecks();
        modelProfiling = InternalsConfig.isModelProfiling();

        detailedDebugDump = DebugUtil.isDetailedDebugDump();

        tolerateUndeclaredPrefixes = QNameUtil.isTolerateUndeclaredPrefixes();
    }

    public boolean isConsistencyChecks() {
        return consistencyChecks;
    }

    public void setConsistencyChecks(boolean consistencyChecks) {
        this.consistencyChecks = consistencyChecks;
    }

    public boolean isEncryptionChecks() {
        return encryptionChecks;
    }

    public void setEncryptionChecks(boolean encryptionChecks) {
        this.encryptionChecks = encryptionChecks;
    }

    public boolean isReadEncryptionChecks() {
        return readEncryptionChecks;
    }

    public void setReadEncryptionChecks(boolean readEncryptionChecks) {
        this.readEncryptionChecks = readEncryptionChecks;
    }

    protected boolean isModelProfiling() {
        return modelProfiling;
    }

    protected void setModelProfiling(boolean modelProfiling) {
        this.modelProfiling = modelProfiling;
    }

    public boolean isDetailedDebugDump() {
        return detailedDebugDump;
    }

    public void setDetailedDebugDump(boolean detailedDebugDump) {
        this.detailedDebugDump = detailedDebugDump;
    }

    public boolean isTolerateUndeclaredPrefixes() {
        return tolerateUndeclaredPrefixes;
    }

    public void setTolerateUndeclaredPrefixes(boolean tolerateUndeclaredPrefixes) {
        this.tolerateUndeclaredPrefixes = tolerateUndeclaredPrefixes;
    }

    // undeclared prefixes is also handled here
    public void saveInternalsConfig() {
        InternalsConfig.setConsistencyChecks(consistencyChecks);
        InternalsConfig.setEncryptionChecks(encryptionChecks);
        InternalsConfig.setReadEncryptionChecks(readEncryptionChecks);
        InternalsConfig.setModelProfiling(modelProfiling);
        QNameUtil.setTolerateUndeclaredPrefixes(tolerateUndeclaredPrefixes);
    }

    public void saveDebugUtil() {
        DebugUtil.setDetailedDebugDump(detailedDebugDump);
    }
}


text:
class G4UIcommand;
class G4UIcmdWithADouble;

namespace RAT {

  //Forward declarations within RAT namespace
  class ReacIBDgen;

  class ReacIBDgenMessenger: public G4UImessenger
  {
  public:
    //ReacIBDgenMessenger(ReacIBDgen*);
    ReacIBDgenMessenger(ReacIBDgen*);
    ~ReacIBDgenMessenger();

    void SetNewValue(G4UIcommand* command, G4String newValues);
    G4String GetCurrentValue(G4UIcommand* command);

  private:
    ReacIBDgen* reacibdgen;

    G4UIcmdWithADouble* U235AmpCmd;
    G4UIcmdWithADouble* U238AmpCmd;
    G4UIcmdWithADouble* Pu239AmpCmd;
    G4UIcmdWithADouble* Pu241AmpCmd;
  };

} // namespace RAT

#endif // RAT_ReacIBDgenMessenger_hh


text:
routeros-api-go
===============

Go library to manage Mikrotik routers using the Mikrotik RouterOS API

[API Documentation](http://godoc.org/github.com/Netwurx/routeros-api-go)

## To Do
* Write better docstrings
* Make README
* Add support for command/response tags
* Add checking for error codes


text:
package org.jgroups.protocols.dns;

import org.jgroups.Address;
import org.jgroups.JChannel;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
import org.jgroups.protocols.TCP;
import org.jgroups.protocols.UNICAST3;
import org.jgroups.protocols.pbcast.GMS;
import org.jgroups.protocols.pbcast.NAKACK2;
import org.jgroups.protocols.pbcast.STABLE;
import org.jgroups.stack.Protocol;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class DNSDiscoveryTester {

   private final MockDNSResolverBuilder dnsResolverBuilder = MockDNSResolverBuilder.newDefault();
   private final int numberOfTestedInstances;
   private final int timeout;
   private final TimeUnit unit;
   private final int portStart;

   public DNSDiscoveryTester(int numberOfTestedInstances, int portStart, int timeout, TimeUnit unit) {
      this.numberOfTestedInstances = numberOfTestedInstances;
      this.timeout = timeout;
      this.unit = unit;
      this.portStart = portStart;
   }

   public DNSDiscoveryTester add(String dnsRecord, DNSResolver.DNSRecordType recordType, Address address) {
      dnsResolverBuilder.add(dnsRecord, recordType, address);
      return this;
   }

   public boolean runTestAndCheckIfViewWasReceived(String dnsQuery, String recordType) throws Exception {
      List<JChannel> channels = new ArrayList<>();

      CountDownLatch waitForViewToForm = new CountDownLatch(1);

      for(int i = 0; i < numberOfTestedInstances; ++i) {
         DNS_PING ping = new DNS_PING();
         ping.dns_resolver = dnsResolverBuilder.build();
         ping.dns_query = dnsQuery;
         ping.dns_record_type = recordType;
         ping.dns_address = "fake.com";

         Protocol[] protocols={
               new TCP().setBindAddress(InetAddress.getLoopbackAddress()). setBindPort(portStart).setPortRange(1),
               ping,
               new NAKACK2(),
               new UNICAST3(),
               new STABLE(),
               new GMS().joinTimeout(timeout)
         };

         JChannel c = new JChannel(protocols).name(String.valueOf(i+1));
         channels.add(c);

         c.setReceiver(new ReceiverAdapter() {
            @Override
            public void viewAccepted(View view) {
               if(view.getMembers().size() == numberOfTestedInstances) {
                  waitForViewToForm.countDown();
               }
            }
         });

         c.connect("TEST");
      }

      boolean viewReceived = waitForViewToForm.await(timeout, unit);
      channels.forEach(JChannel::close);

      return viewReceived;
   }

}


text:
export * from './lobby.module';
export * from './lobby-page/lobby-page.component';


text:
#ifndef __DESC_H__
#define __DESC_H__

#include <linux/types.h>
#include <linux/mm.h>
#include "linux/ieee80211.h"

#define B_OWNED_BY_CHIP     1
#define B_OWNED_BY_HOST     0

/* Bits in the RSR register */
#define RSR_ADDRBROAD       0x80
#define RSR_ADDRMULTI       0x40
#define RSR_ADDRUNI         0x00
#define RSR_IVLDTYP         0x20
#define RSR_IVLDLEN         0x10        /* invalid len (> 2312 byte) */
#define RSR_BSSIDOK         0x08
#define RSR_CRCOK           0x04
#define RSR_BCNSSIDOK       0x02
#define RSR_ADDROK          0x01

/* Bits in the new RSR register */
#define NEWRSR_DECRYPTOK    0x10
#define NEWRSR_CFPIND       0x08
#define NEWRSR_HWUTSF       0x04
#define NEWRSR_BCNHITAID    0x02
#define NEWRSR_BCNHITAID0   0x01

/* Bits in the TSR0 register */
#define TSR0_PWRSTS1_2      0xC0
#define TSR0_PWRSTS7        0x20
#define TSR0_NCR            0x1F

/* Bits in the TSR1 register */
#define TSR1_TERR           0x80
#define TSR1_PWRSTS4_6      0x70
#define TSR1_RETRYTMO       0x08
#define TSR1_TMO            0x04
#define TSR1_PWRSTS3        0x02
#define ACK_DATA            0x01

/* Bits in the TCR register */
#define EDMSDU              0x04        /* end of sdu */
#define TCR_EDP             0x02        /* end of packet */
#define TCR_STP             0x01        /* start of packet */

/* max transmit or receive buffer size */
#define CB_MAX_BUF_SIZE     2900U
					/* NOTE: must be multiple of 4 */
#define CB_MAX_TX_BUF_SIZE          CB_MAX_BUF_SIZE
#define CB_MAX_RX_BUF_SIZE_NORMAL   CB_MAX_BUF_SIZE

#define CB_BEACON_BUF_SIZE  512U

#define CB_MAX_RX_DESC      128
#define CB_MIN_RX_DESC      16
#define CB_MAX_TX_DESC      64
#define CB_MIN_TX_DESC      16

#define CB_MAX_RECEIVED_PACKETS     16
				/*
				 * limit our receive routine to indicating
				 * this many at a time for 2 reasons:
				 * 1. driver flow control to protocol layer
				 * 2. limit the time used in ISR routine
				 */

#define CB_EXTRA_RD_NUM     32
#define CB_RD_NUM           32
#define CB_TD_NUM           32

/*
 * max number of physical segments in a single NDIS packet. Above this
 * threshold, the packet is copied into a single physically contiguous buffer
 */
#define CB_MAX_SEGMENT      4

#define CB_MIN_MAP_REG_NUM  4
#define CB_MAX_MAP_REG_NUM  CB_MAX_TX_DESC

#define CB_PROTOCOL_RESERVED_SECTION    16

/*
 * if retrys excess 15 times , tx will abort, and if tx fifo underflow,
 * tx will fail, we should try to resend it
 */
#define CB_MAX_TX_ABORT_RETRY   3

/* WMAC definition FIFO Control */
#define FIFOCTL_AUTO_FB_1   0x1000
#define FIFOCTL_AUTO_FB_0   0x0800
#define FIFOCTL_GRPACK      0x0400
#define FIFOCTL_11GA        0x0300
#define FIFOCTL_11GB        0x0200
#define FIFOCTL_11B         0x0100
#define FIFOCTL_11A         0x0000
#define FIFOCTL_RTS         0x0080
#define FIFOCTL_ISDMA0      0x0040
#define FIFOCTL_GENINT      0x0020
#define FIFOCTL_TMOEN       0x0010
#define FIFOCTL_LRETRY      0x0008
#define FIFOCTL_CRCDIS      0x0004
#define FIFOCTL_NEEDACK     0x0002
#define FIFOCTL_LHEAD       0x0001

/* WMAC definition Frag Control */
#define FRAGCTL_AES         0x0300
#define FRAGCTL_TKIP        0x0200
#define FRAGCTL_LEGACY      0x0100
#define FRAGCTL_NONENCRYPT  0x0000
#define FRAGCTL_ENDFRAG     0x0003
#define FRAGCTL_MIDFRAG     0x0002
#define FRAGCTL_STAFRAG     0x0001
#define FRAGCTL_NONFRAG     0x0000

#define TYPE_TXDMA0     0
#define TYPE_AC0DMA     1
#define TYPE_ATIMDMA    2
#define TYPE_SYNCDMA    3
#define TYPE_MAXTD      2

#define TYPE_BEACONDMA  4

#define TYPE_RXDMA0     0
#define TYPE_RXDMA1     1
#define TYPE_MAXRD      2

/* TD_INFO flags control bit */
#define TD_FLAGS_NETIF_SKB      0x01    /* check if need release skb */
#define TD_FLAGS_PRIV_SKB       0x02    /* check if called from private skb (hostap) */
#define TD_FLAGS_PS_RETRY       0x04    /* check if PS STA frame re-transmit */

/*
 * ref_sk_buff is used for mapping the skb structure between pre-built
 * driver-obj & running kernel. Since different kernel version (2.4x) may
 * change skb structure, i.e. pre-built driver-obj may link to older skb that
 * leads error.
 */

typedef struct tagDEVICE_RD_INFO {
	struct sk_buff *skb;
	dma_addr_t  skb_dma;
} DEVICE_RD_INFO,   *PDEVICE_RD_INFO;

#ifdef __BIG_ENDIAN

typedef struct tagRDES0 {
	volatile __le16 wResCount;
	union {
		volatile u16    f15Reserved;
		struct {
			volatile u8 f8Reserved1;
			volatile u8 f1Owner:1;
			volatile u8 f7Reserved:7;
		} __attribute__ ((__packed__));
	} __attribute__ ((__packed__));
} __attribute__ ((__packed__))
SRDES0, *PSRDES0;

#else

typedef struct tagRDES0 {
	__le16         wResCount;
	unsigned short f15Reserved:15;
	unsigned short f1Owner:1;
} __attribute__ ((__packed__))
SRDES0;

#endif

typedef struct tagRDES1 {
	__le16	       wReqCount;
	unsigned short wReserved;
} __attribute__ ((__packed__))
SRDES1;

/* Rx descriptor*/
typedef struct tagSRxDesc {
	volatile SRDES0 m_rd0RD0;
	volatile SRDES1 m_rd1RD1;
	volatile __le32 buff_addr;
	volatile __le32 next_desc;
	struct tagSRxDesc *next __aligned(8);
	volatile PDEVICE_RD_INFO pRDInfo __aligned(8);
} __attribute__ ((__packed__))
SRxDesc, *PSRxDesc;
typedef const SRxDesc *PCSRxDesc;

struct vnt_tdes0 {
	volatile u8 tsr0;
	volatile u8 tsr1;
#ifdef __BIG_ENDIAN
	union {
		volatile u16 f15_txtime;
		struct {
			volatile u8 f8_reserved;
			volatile u8 owner:1;
			volatile u8 f7_reserved:7;
		} __packed;
	} __packed;
#else
	volatile u16 f15_txtime:15;
	volatile u16 owner:1;
#endif
} __packed;

struct vnt_tdes1 {
	volatile __le16 req_count;
	volatile u8 tcr;
	volatile u8 reserved;
} __packed;

struct vnt_td_info {
	void *mic_hdr;
	struct sk_buff *skb;
	unsigned char *buf;
	dma_addr_t buf_dma;
	u16 req_count;
	u8 flags;
};

/* transmit descriptor */
struct vnt_tx_desc {
	volatile struct vnt_tdes0 td0;
	volatile struct vnt_tdes1 td1;
	volatile __le32 buff_addr;
	volatile __le32 next_desc;
	struct vnt_tx_desc *next __aligned(8);
	struct vnt_td_info *td_info __aligned(8);
} __packed;

/* Length, Service, and Signal fields of Phy for Tx */
struct vnt_phy_field {
	u8 signal;
	u8 service;
	__le16 len;
} __packed;

union vnt_phy_field_swap {
	struct vnt_phy_field field_read;
	u16 swap[2];
	u32 field_write;
};

#endif /* __DESC_H__ */


text:
/*AN INTRODUCTION TO PROGRAMMING WITH PROCESSING by LYNDON DANIELS*/
body{
background-image: url(images/bkg2.png);
color: rgb(102, 102, 102);
font-family: Helvetica, Arial, Verdana,sans-serif;
font-size: 1em;
background-color: rgb(233, 236, 250);
margin: 0;
}

/*Text*/

h1 {
font-size: 1.8em;
}

h2 {
font-size: 1.1em;
}

p {
font-size: .8em;
text-align: justify;
}

/*Content*/

#header {
background-color: #ffffff;
border-bottom: 1px #000000 solid;
}

#content {

}

	#navbar, #navbar ul {
	padding: 0;
	margin:0;
	list-style: none;
	float: left;
	width: 215px;
	background:none;
	border: none;
	border-width: 1px;
	line-height: 1.2;
	}

#navbar a.arrow {
	background: url(images/arrow.gif) center right no-repeat;
}

#navbar a.offset {
	position: absolute;
	margin-top : 0.85em;
}

#navbar a.offsetarrow {
	background: url(images/arrow.gif) center right no-repeat;
	position: relative;

	margin-top : 0em;

}

	#navbar li { /* all list items */
	position : relative;
	float : left;
	line-height : 1.5em;
	margin-bottom : -3px;
	width:215px;
	background:white;
	border:none;
	}

	#navbar li ul { /* second-level lists */
		position : absolute;
		left: -999em;
		margin-left : 13.4em;
		margin-top : -2.7em;
	}

	#navbar li ul ul { /* third-and-above-level lists */
		left: -999em;
	}

	#navbar li ul ul ul { /* fourth-and-above-level lists */
		left: -999em;
	}

	#navbar li a {
		width: 193px;

		display : block;
		color : black;
		font-weight : medium;
		text-decoration : none;
		background-color : white;
		border : 3px solid #71d5ee;
		padding : 0 0.5em;
	}

	#navbar li a:hover {
		color : black;
		background-color : #71d5ee;
	}

	#navbar li:hover ul ul, #navbar li:hover ul ul ul, #navbar li:hover ul ul ul ul, #navbar li.sfhover ul ul, #navbar li.sfhover ul ul ul, #navbar li.sfhover ul ul ul ul {
		left: -999em;
	}

	#navbar li:hover ul, #navbar li li:hover ul, #navbar li li li:hover ul, #navbar li li li li:hover ul, #navbar li.sfhover ul, #navbar li li.sfhover ul, #navbar li li li.sfhover ul, #navbar li li li li.sfhover ul { /* lists nested under hovered list items */
		left: auto;
	}

	#navbar li:hover, #navbar li.sfhover {
	background: #71d5ee;
	}


text:
# global parameters
g_tmp_folder="ncdc_tmp";
g_output_folder="ncdc_data";

g_remote_host="ftp.ncdc.noaa.gov";
g_remote_path="pub/data/noaa";

# $1: folder_path
function create_folder {
    if [ -d "$1" ]; then
        rm -rf "$1";
    fi
    mkdir "$1"
}

# $1: year to download
function download_data {
    local source_url="ftp://$g_remote_host/$g_remote_path/$1"
    wget -r -c -q --no-parent -P "$g_tmp_folder" "$source_url";
}

# $1: year to process
function process_data {
    local year="$1"
    local local_path="$g_tmp_folder/$g_remote_host/$g_remote_path/$year"
    local tmp_output_file="$g_tmp_folder/$year"
    for file in $local_path/*; do
        gunzip -c $file >> "$tmp_output_file"
    done
    zipped_file="$g_output_folder/$year.gz"
    gzip -c "$tmp_output_file" >> "$zipped_file"
    echo "created file: $zipped_file"

    rm -rf "$local_path"
    rm "$tmp_output_file"
}

# $1 - start year
# $2 - finish year
function main {
    local start_year=2014
    local finish_year=2014

    if [ -n "$1" ]; then
        start_year=$1
    fi

    if [ -n "$2" ]; then
        finish_year=$2
    fi

    create_folder $g_tmp_folder
    create_folder $g_output_folder

    for year in `seq $start_year $finish_year`; do
        download_data $year
        process_data $year
    done

    rm -rf "$g_tmp_folder"
}

main $1 $2


text:
<!DOCTYPE html>

		<title>OzzA - Apresentação do Layout</title>
		<meta charset="utf-8" />
		<meta lang="pt-BR" />

		<meta name="description" content="OzzA - Apresentação do Layout" />
		<meta name="keywords" content="OzzA - Apresentação do Layout" />
		<meta name="author" content="Mais Interativo" />

		<link rel="stylesheet" type="text/css" href="css/style.css" />


text:
#ifndef IO_H_
#define IO_H_

#define IO_REVISION 1

/*
 * enum io_direction
 * direction of the pin
 */
#define FOREACH_IO_PORT_DIR(DV)\
		DV(IO_PORT_DIR_IN, (uint8_t) 0)\
		DV(IO_PORT_DIR_OUT, (uint8_t) 1)\
		DV(IO_PORT_DIR_BI, (uint8_t) 2)

enum io_direction
{
	FOREACH_IO_PORT_DIR(GENERATE_ENUM_VAL)
};

typedef int8_t io_id;               //io identification nummber (unused, will be removed later)

struct io_setup
{
     enum io_direction e_io_dir;
     enum ports e_port;
     uint8_t bit_mask;
};

struct io_null_envlp
{
    enum io_direction e_io_dir;     //direction of the allocated pins
	enum ports e_port;              //ports
	uint8_t bit_mask;               //mask
};

struct io_null_dev
{
	//io_id id;
	struct dev_descr_node * ddn;        //fd instance (owner)
	enum io_direction e_io_dir;     //direction of the allocated pins
	enum ports e_port;              //ports
	uint8_t bit_mask;               //mask
	uint8_t bit_count;              //amount of pins
};

VERIFY_ENUM_FUNCTION_DEC_P(io_dir_func);

/*
 *   Standart module functions
 */
int8_t io_hal_message(struct dev_descr_node * ddn,
                          enum dd_event e_event,
                          void * data0,
                          size_t * dsize0);

int8_t io_kstream_init(struct dev_descr_node * ddn,
                           struct kstream * ks);

int8_t io_stream_init(struct dev_descr_node * ddn,
                             FILE * file);

/*
 * io_get_by_fid
 * looks up in the io table for record by fid
 */
//struct io_null_dev * io_get_by_did(t_dev_id did);

/*
 * io_count_ones
 * this function counts amount of bits set to 1
 * i.e 00000100 will return 1
 */
int8_t io_count_ones(struct io_null_dev * iod);

/*
 * io_find_less_significant_bit
 * looks fot less significant bit in mask
 */
uint8_t io_find_less_significant_bit(struct io_null_dev * iod);

/*
 * io_find_mask_by_order
 * looks up for mask by order (this function will be removed)
 */
uint8_t io_find_mask_by_order(struct io_null_dev * iod, uint8_t n);

/*
 * io_mask_prepare
 * this function is designed to prepare you input (2nd argument) to
 *  to work with selected instance of io_null_dev
 * i.e iod->mask = 00001100
 *          mask = 01001010
 *          res  = 00001000
 */
uint8_t io_mask_prepare(struct io_null_dev * iod, uint8_t mask);

/*
 * io_find_mask_by_selector
 * this function retuens the mask of the value by order
 *  i.e iod->mask = 00001100
 *              n = 1
 *          result= 00000100
 */
uint8_t io_find_mask_by_selector(struct io_null_dev * iod, uint8_t n);

/*
 * io_write8_direct
 * writes 2nd argument ready_mask to the hardware defined by instance of io_null_dev
 *  you must prepare mask by calling io_mask_repare
 *  i.e io_write8_direct(iod, io_mask_repare(iod, my_value);
 */
int8_t io_write8_direct(struct io_null_dev * iod, uint8_t ready_mask);

/*
 * io_read8_direct
 * reads data according to the io_null_dev port and mask
 */
int8_t io_read8_direct(struct io_null_dev * iod, uint8_t * data_out);

/*
 * unused
 */
int8_t io_write8(struct io_null_dev * iod, uint8_t dt);
int8_t io_read8(struct io_null_dev * iod, uint8_t * data_out);

int8_t io_get_mask(struct io_null_dev * iod, uint8_t * mask_out);

#endif /* IO_H_ */


text:
var _ = require('underscore');

var Server = function (options) {
    this.initialize.apply(this, arguments);
};

_.extend(Server.prototype, {
    /**
     * Attaches listener for incoming connections
     *
     * @param  {Object} options
     */
    initialize: function (options) {
        options.incoming.on('error', this.error);
        options.incoming.on('connection', this.handle);
    },

    /**
     * Logs the error to the console
     *
     * @param  {Error} error
     */
    error: function (error) {
        console.log('Server Error:', error);
    },

    /**
     * Handles the incoming connection
     *
     * @param  {Socket} socket
     */
    handle: function (socket) {}
});

module.exports = Server;


text:
package org.apache.lucene.analysis.synonym;

import java.io.IOException;
import java.util.Arrays;

import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute;
import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
import org.apache.lucene.store.ByteArrayDataInput;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.lucene.util.fst.FST;

/**
 * Matches single or multi word synonyms in a token stream.
 * This token stream cannot properly handle position
 * increments != 1, ie, you should place this filter before
 * filtering out stop words.
 *
 *
Note that with the current implementation, parsing is
 * greedy, so whenever multiple parses would apply, the rule
 * starting the earliest and parsing the most tokens wins.
 * For example if you have these rules:
 *
 *

 *   a -> x
 *   a b -> y
 *   b c d -> z
 *

 *
 * Then input a b c d e parses to y b c
 * d, ie the 2nd rule "wins" because it started
 * earliest and matched the most input tokens of other rules
 * starting at that point.

 *
 *
A future improvement to this filter could allow
 * non-greedy parsing, such that the 3rd rule would win, and
 * also separately allow multiple parses, such that all 3
 * rules would match, perhaps even on a rule by rule
 * basis.

 *
 *
NOTE: when a match occurs, the output tokens
 * associated with the matching rule are "stacked" on top of
 * the input stream (if the rule had
 * keepOrig=true) and also on top of another
 * matched rule's output tokens.  This is not a correct
 * solution, as really the output should be an arbitrary
 * graph/lattice.  For example, with the above match, you
 * would expect an exact PhraseQuery "y b
 * c" to match the parsed tokens, but it will fail to
 * do so.  This limitation is necessary because Lucene's
 * TokenStream (and index) cannot yet represent an arbitrary
 * graph.

 *
 *
NOTE: If multiple incoming tokens arrive on the
 * same position, only the first token at that position is
 * used for parsing.  Subsequent tokens simply pass through
 * and are not parsed.  A future improvement would be to
 * allow these tokens to also be matched.

 */

// TODO: maybe we should resolve token -> wordID then run
// FST on wordIDs, for better perf?

// TODO: a more efficient approach would be Aho/Corasick's
// algorithm
// http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm
// It improves over the current approach here
// because it does not fully re-start matching at every
// token.  For example if one pattern is "a b c x"
// and another is "b c d" and the input is "a b c d", on
// trying to parse "a b c x" but failing when you got to x,
// rather than starting over again your really should
// immediately recognize that "b c d" matches at the next
// input.  I suspect this won't matter that much in
// practice, but it's possible on some set of synonyms it
// will.  We'd have to modify Aho/Corasick to enforce our
// conflict resolving (eg greedy matching) because that algo
// finds all matches.  This really amounts to adding a .*
// closure to the FST and then determinizing it.
//
// Another possible solution is described at http://www.cis.uni-muenchen.de/people/Schulz/Pub/dictle5.ps

public final class SynonymFilter extends TokenFilter {

  public static final String TYPE_SYNONYM = "SYNONYM";

  private final SynonymMap synonyms;

  private final boolean ignoreCase;
  private final int rollBufferSize;

  private int captureCount;

  // TODO: we should set PositionLengthAttr too...

  private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
  private final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);
  private final PositionLengthAttribute posLenAtt = addAttribute(PositionLengthAttribute.class);
  private final TypeAttribute typeAtt = addAttribute(TypeAttribute.class);
  private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);

  // How many future input tokens have already been matched
  // to a synonym; because the matching is "greedy" we don't
  // try to do any more matching for such tokens:
  private int inputSkipCount;

  // Hold all buffered (read ahead) stacked input tokens for
  // a future position.  When multiple tokens are at the
  // same position, we only store (and match against) the
  // term for the first token at the position, but capture
  // state for (and enumerate) all other tokens at this
  // position:
  private static class PendingInput {
    final CharsRefBuilder term = new CharsRefBuilder();
    AttributeSource.State state;
    boolean keepOrig;
    boolean matched;
    boolean consumed = true;
    int startOffset;
    int endOffset;

    public void reset() {
      state = null;
      consumed = true;
      keepOrig = false;
      matched = false;
    }
  };

  // Rolling buffer, holding pending input tokens we had to
  // clone because we needed to look ahead, indexed by
  // position:
  private final PendingInput[] futureInputs;

  // Holds pending output synonyms for one future position:
  private static class PendingOutputs {
    CharsRefBuilder[] outputs;
    int[] endOffsets;
    int[] posLengths;
    int upto;
    int count;
    int posIncr = 1;
    int lastEndOffset;
    int lastPosLength;

    public PendingOutputs() {
      outputs = new CharsRefBuilder[1];
      endOffsets = new int[1];
      posLengths = new int[1];
    }

    public void reset() {
      upto = count = 0;
      posIncr = 1;
    }

    public CharsRef pullNext() {
      assert upto < count;
      lastEndOffset = endOffsets[upto];
      lastPosLength = posLengths[upto];
      final CharsRefBuilder result = outputs[upto++];
      posIncr = 0;
      if (upto == count) {
        reset();
      }
      return result.get();
    }

    public int getLastEndOffset() {
      return lastEndOffset;
    }

    public int getLastPosLength() {
      return lastPosLength;
    }

    public void add(char[] output, int offset, int len, int endOffset, int posLength) {
      if (count == outputs.length) {
        outputs = Arrays.copyOf(outputs, ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
      }
      if (count == endOffsets.length) {
        final int[] next = new int[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_INT)];
        System.arraycopy(endOffsets, 0, next, 0, count);
        endOffsets = next;
      }
      if (count == posLengths.length) {
        final int[] next = new int[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_INT)];
        System.arraycopy(posLengths, 0, next, 0, count);
        posLengths = next;
      }
      if (outputs[count] == null) {
        outputs[count] = new CharsRefBuilder();
      }
      outputs[count].copyChars(output, offset, len);
      // endOffset can be -1, in which case we should simply
      // use the endOffset of the input token, or X >= 0, in
      // which case we use X as the endOffset for this output
      endOffsets[count] = endOffset;
      posLengths[count] = posLength;
      count++;
    }
  };

  private final ByteArrayDataInput bytesReader = new ByteArrayDataInput();

  // Rolling buffer, holding stack of pending synonym
  // outputs, indexed by position:
  private final PendingOutputs[] futureOutputs;

  // Where (in rolling buffers) to write next input saved state:
  private int nextWrite;

  // Where (in rolling buffers) to read next input saved state:
  private int nextRead;

  // True once we've read last token
  private boolean finished;

  private final FST.Arc<BytesRef> scratchArc;

  private final FST<BytesRef> fst;

  private final FST.BytesReader fstReader;

  private final BytesRef scratchBytes = new BytesRef();
  private final CharsRefBuilder scratchChars = new CharsRefBuilder();

  /**
   * @param input input tokenstream
   * @param synonyms synonym map
   * @param ignoreCase case-folds input for matching with {@link Character#toLowerCase(int)}.
   *                   Note, if you set this to true, it's your responsibility to lowercase
   *                   the input entries when you create the {@link SynonymMap}
   */
  public SynonymFilter(TokenStream input, SynonymMap synonyms, boolean ignoreCase) {
    super(input);
    this.synonyms = synonyms;
    this.ignoreCase = ignoreCase;
    this.fst = synonyms.fst;
    if (fst == null) {
      throw new IllegalArgumentException("fst must be non-null");
    }
    this.fstReader = fst.getBytesReader();

    // Must be 1+ so that when roll buffer is at full
    // lookahead we can distinguish this full buffer from
    // the empty buffer:
    rollBufferSize = 1+synonyms.maxHorizontalContext;

    futureInputs = new PendingInput[rollBufferSize];
    futureOutputs = new PendingOutputs[rollBufferSize];
    for(int pos=0;pos<rollBufferSize;pos++) {
      futureInputs[pos] = new PendingInput();
      futureOutputs[pos] = new PendingOutputs();
    }

    //System.out.println("FSTFilt maxH=" + synonyms.maxHorizontalContext);

    scratchArc = new FST.Arc<>();
  }

  private void capture() {
    captureCount++;
    //System.out.println("  capture slot=" + nextWrite);
    final PendingInput input = futureInputs[nextWrite];

    input.state = captureState();
    input.consumed = false;
    input.term.copyChars(termAtt.buffer(), 0, termAtt.length());

    nextWrite = rollIncr(nextWrite);

    // Buffer head should never catch up to tail:
    assert nextWrite != nextRead;
  }

  /*
   This is the core of this TokenFilter: it locates the
   synonym matches and buffers up the results into
   futureInputs/Outputs.

   NOTE: this calls input.incrementToken and does not
   capture the state if no further tokens were checked.  So
   caller must then forward state to our caller, or capture:
  */
  private int lastStartOffset;
  private int lastEndOffset;

  private void parse() throws IOException {
    //System.out.println("\nS: parse");

    assert inputSkipCount == 0;

    int curNextRead = nextRead;

    // Holds the longest match we've seen so far:
    BytesRef matchOutput = null;
    int matchInputLength = 0;
    int matchEndOffset = -1;

    BytesRef pendingOutput = fst.outputs.getNoOutput();
    fst.getFirstArc(scratchArc);

    assert scratchArc.output == fst.outputs.getNoOutput();

    int tokenCount = 0;

    byToken:
    while(true) {

      // Pull next token's chars:
      final char[] buffer;
      final int bufferLen;
      //System.out.println("  cycle nextRead=" + curNextRead + " nextWrite=" + nextWrite);

      int inputEndOffset = 0;

      if (curNextRead == nextWrite) {

        // We used up our lookahead buffer of input tokens
        // -- pull next real input token:

        if (finished) {
          break;
        } else  {
          //System.out.println("  input.incrToken");
          assert futureInputs[nextWrite].consumed;
          // Not correct: a syn match whose output is longer
          // than its input can set future inputs keepOrig
          // to true:
          //assert !futureInputs[nextWrite].keepOrig;
          if (input.incrementToken()) {
            buffer = termAtt.buffer();
            bufferLen = termAtt.length();
            final PendingInput input = futureInputs[nextWrite];
            lastStartOffset = input.startOffset = offsetAtt.startOffset();
            lastEndOffset = input.endOffset = offsetAtt.endOffset();
            inputEndOffset = input.endOffset;
            //System.out.println("  new token=" + new String(buffer, 0, bufferLen));
            if (nextRead != nextWrite) {
              capture();
            } else {
              input.consumed = false;
            }

          } else {
            // No more input tokens
            //System.out.println("      set end");
            finished = true;
            break;
          }
        }
      } else {
        // Still in our lookahead
        buffer = futureInputs[curNextRead].term.chars();
        bufferLen = futureInputs[curNextRead].term.length();
        inputEndOffset = futureInputs[curNextRead].endOffset;
        //System.out.println("  old token=" + new String(buffer, 0, bufferLen));
      }

      tokenCount++;

      // Run each char in this token through the FST:
      int bufUpto = 0;
      while(bufUpto < bufferLen) {
        final int codePoint = Character.codePointAt(buffer, bufUpto, bufferLen);
        if (fst.findTargetArc(ignoreCase ? Character.toLowerCase(codePoint) : codePoint, scratchArc, scratchArc, fstReader) == null) {
          //System.out.println("    stop");
          break byToken;
        }

        // Accum the output
        pendingOutput = fst.outputs.add(pendingOutput, scratchArc.output);
        //System.out.println("    char=" + buffer[bufUpto] + " output=" + pendingOutput + " arc.output=" + scratchArc.output);
        bufUpto += Character.charCount(codePoint);
      }

      // OK, entire token matched; now see if this is a final
      // state:
      if (scratchArc.isFinal()) {
        matchOutput = fst.outputs.add(pendingOutput, scratchArc.nextFinalOutput);
        matchInputLength = tokenCount;
        matchEndOffset = inputEndOffset;
        //System.out.println("  found matchLength=" + matchInputLength + " output=" + matchOutput);
      }

      // See if the FST wants to continue matching (ie, needs to
      // see the next input token):
      if (fst.findTargetArc(SynonymMap.WORD_SEPARATOR, scratchArc, scratchArc, fstReader) == null) {
        // No further rules can match here; we're done
        // searching for matching rules starting at the
        // current input position.
        break;
      } else {
        // More matching is possible -- accum the output (if
        // any) of the WORD_SEP arc:
        pendingOutput = fst.outputs.add(pendingOutput, scratchArc.output);
        if (nextRead == nextWrite) {
          capture();
        }
      }

      curNextRead = rollIncr(curNextRead);
    }

    if (nextRead == nextWrite && !finished) {
      //System.out.println("  skip write slot=" + nextWrite);
      nextWrite = rollIncr(nextWrite);
    }

    if (matchOutput != null) {
      //System.out.println("  add matchLength=" + matchInputLength + " output=" + matchOutput);
      inputSkipCount = matchInputLength;
      addOutput(matchOutput, matchInputLength, matchEndOffset);
    } else if (nextRead != nextWrite) {
      // Even though we had no match here, we set to 1
      // because we need to skip current input token before
      // trying to match again:
      inputSkipCount = 1;
    } else {
      assert finished;
    }

    //System.out.println("  parse done inputSkipCount=" + inputSkipCount + " nextRead=" + nextRead + " nextWrite=" + nextWrite);
  }

  // Interleaves all output tokens onto the futureOutputs:
  private void addOutput(BytesRef bytes, int matchInputLength, int matchEndOffset) {
    bytesReader.reset(bytes.bytes, bytes.offset, bytes.length);

    final int code = bytesReader.readVInt();
    final boolean keepOrig = (code & 0x1) == 0;
    final int count = code >>> 1;
    //System.out.println("  addOutput count=" + count + " keepOrig=" + keepOrig);
    for(int outputIDX=0;outputIDX<count;outputIDX++) {
      synonyms.words.get(bytesReader.readVInt(),
                         scratchBytes);
      //System.out.println("    outIDX=" + outputIDX + " bytes=" + scratchBytes.length);
      scratchChars.copyUTF8Bytes(scratchBytes);
      int lastStart = 0;
      final int chEnd = lastStart + scratchChars.length();
      int outputUpto = nextRead;
      for(int chIDX=lastStart;chIDX<=chEnd;chIDX++) {
        if (chIDX == chEnd || scratchChars.charAt(chIDX) == SynonymMap.WORD_SEPARATOR) {
          final int outputLen = chIDX - lastStart;
          // Caller is not allowed to have empty string in
          // the output:
          assert outputLen > 0: "output contains empty string: " + scratchChars;
          final int endOffset;
          final int posLen;
          if (chIDX == chEnd && lastStart == 0) {
            // This rule had a single output token, so, we set
            // this output's endOffset to the current
            // endOffset (ie, endOffset of the last input
            // token it matched):
            endOffset = matchEndOffset;
            posLen = keepOrig ? matchInputLength : 1;
          } else {
            // This rule has more than one output token; we
            // can't pick any particular endOffset for this
            // case, so, we inherit the endOffset for the
            // input token which this output overlaps:
            endOffset = -1;
            posLen = 1;
          }
          futureOutputs[outputUpto].add(scratchChars.chars(), lastStart, outputLen, endOffset, posLen);
          //System.out.println("      " + new String(scratchChars.chars, lastStart, outputLen) + " outputUpto=" + outputUpto);
          lastStart = 1+chIDX;
          //System.out.println("  slot=" + outputUpto + " keepOrig=" + keepOrig);
          outputUpto = rollIncr(outputUpto);
          assert futureOutputs[outputUpto].posIncr == 1: "outputUpto=" + outputUpto + " vs nextWrite=" + nextWrite;
        }
      }
    }

    int upto = nextRead;
    for(int idx=0;idx<matchInputLength;idx++) {
      futureInputs[upto].keepOrig |= keepOrig;
      futureInputs[upto].matched = true;
      upto = rollIncr(upto);
    }
  }

  // ++ mod rollBufferSize
  private int rollIncr(int count) {
    count++;
    if (count == rollBufferSize) {
      return 0;
    } else {
      return count;
    }
  }

  // for testing
  int getCaptureCount() {
    return captureCount;
  }

  @Override
  public boolean incrementToken() throws IOException {

    //System.out.println("\nS: incrToken inputSkipCount=" + inputSkipCount + " nextRead=" + nextRead + " nextWrite=" + nextWrite);

    while(true) {

      // First play back any buffered future inputs/outputs
      // w/o running parsing again:
      while (inputSkipCount != 0) {

        // At each position, we first output the original
        // token

        // TODO: maybe just a PendingState class, holding
        // both input & outputs?
        final PendingInput input = futureInputs[nextRead];
        final PendingOutputs outputs = futureOutputs[nextRead];

        //System.out.println("  cycle nextRead=" + nextRead + " nextWrite=" + nextWrite + " inputSkipCount="+ inputSkipCount + " input.keepOrig=" + input.keepOrig + " input.consumed=" + input.consumed + " input.state=" + input.state);

        if (!input.consumed && (input.keepOrig || !input.matched)) {
          if (input.state != null) {
            // Return a previously saved token (because we
            // had to lookahead):
            restoreState(input.state);
          } else {
            // Pass-through case: return token we just pulled
            // but didn't capture:
            assert inputSkipCount == 1: "inputSkipCount=" + inputSkipCount + " nextRead=" + nextRead;
          }
          input.reset();
          if (outputs.count > 0) {
            outputs.posIncr = 0;
          } else {
            nextRead = rollIncr(nextRead);
            inputSkipCount--;
          }
          //System.out.println("  return token=" + termAtt.toString());
          return true;
        } else if (outputs.upto < outputs.count) {
          // Still have pending outputs to replay at this
          // position
          input.reset();
          final int posIncr = outputs.posIncr;
          final CharsRef output = outputs.pullNext();
          clearAttributes();
          termAtt.copyBuffer(output.chars, output.offset, output.length);
          typeAtt.setType(TYPE_SYNONYM);
          int endOffset = outputs.getLastEndOffset();
          if (endOffset == -1) {
            endOffset = input.endOffset;
          }
          offsetAtt.setOffset(input.startOffset, endOffset);
          posIncrAtt.setPositionIncrement(posIncr);
          posLenAtt.setPositionLength(outputs.getLastPosLength());
          if (outputs.count == 0) {
            // Done with the buffered input and all outputs at
            // this position
            nextRead = rollIncr(nextRead);
            inputSkipCount--;
          }
          //System.out.println("  return token=" + termAtt.toString());
          return true;
        } else {
          // Done with the buffered input and all outputs at
          // this position
          input.reset();
          nextRead = rollIncr(nextRead);
          inputSkipCount--;
        }
      }

      if (finished && nextRead == nextWrite) {
        // End case: if any output syns went beyond end of
        // input stream, enumerate them now:
        final PendingOutputs outputs = futureOutputs[nextRead];
        if (outputs.upto < outputs.count) {
          final int posIncr = outputs.posIncr;
          final CharsRef output = outputs.pullNext();
          futureInputs[nextRead].reset();
          if (outputs.count == 0) {
            nextWrite = nextRead = rollIncr(nextRead);
          }
          clearAttributes();
          // Keep offset from last input token:
          offsetAtt.setOffset(lastStartOffset, lastEndOffset);
          termAtt.copyBuffer(output.chars, output.offset, output.length);
          typeAtt.setType(TYPE_SYNONYM);
          //System.out.println("  set posIncr=" + outputs.posIncr + " outputs=" + outputs);
          posIncrAtt.setPositionIncrement(posIncr);
          //System.out.println("  return token=" + termAtt.toString());
          return true;
        } else {
          return false;
        }
      }

      // Find new synonym matches:
      parse();
    }
  }

  @Override
  public void reset() throws IOException {
    super.reset();
    captureCount = 0;
    finished = false;
    inputSkipCount = 0;
    nextRead = nextWrite = 0;

    // In normal usage these resets would not be needed,
    // since they reset-as-they-are-consumed, but the app
    // may not consume all input tokens (or we might hit an
    // exception), in which case we have leftover state
    // here:
    for (PendingInput input : futureInputs) {
      input.reset();
    }
    for (PendingOutputs output : futureOutputs) {
      output.reset();
    }
  }
}


text:
$settingsFile = "$env:APPDATA\Code\User\settings.json"
$packageFile = "$PSScriptRoot\vscode.json"

& 'C:\Program Files\WinMerge\WinMergeU.exe' $settingsFile $packageFile


text:
import tensorflow as tf
from model import QFunction

import numpy as np
import random

def copy_params(src, dst):
    src_params = [v for v in tf.trainable_variables() if v.name.startswith(src.scope)]
    dst_params = [v for v in tf.trainable_variables() if v.name.startswith(dst.scope)]

    op = [d.assign(s) for s, d in zip(src_params, dst_params)]

    return op

def Hurber_loss(x, y, delta=1.0):
    error = tf.abs(y - x)
    cond = tf.less(error, delta)
    return tf.where(cond,
                    0.5*tf.square(error),
                    delta*error - 0.5*tf.square(delta))
class DQN:
    def __init__(self, input_shape, action_n, gamma=0.99, N=50000):
        self.N = N
        self.shape = input_shape
        self.batch_size = input_shape[0]

        Q = QFunction(input_shape, action_n, scope="Q")
        target_Q = QFunction(input_shape, action_n, scope="target_Q")

        # Forward Q
        self.s = tf.placeholder(shape=[None]+input_shape[1:], dtype=tf.float32)
        self.a = tf.placeholder(shape=[self.batch_size, 1], dtype=tf.int32)
        self.probs = Q(self.s)

        # add offset
        first = tf.expand_dims(tf.range(self.batch_size), axis=1)
        indices = tf.concat(values=[first, self.a], concat_dim=1)

        # gather corresiponding q_vals
        self.q_val = tf.expand_dims(tf.gather_nd(self.probs, indices), axis=1)

        # TD target
        self.done = tf.placeholder(shape=[self.batch_size, 1], dtype=tf.float32)
        self.r = tf.placeholder(shape=[self.batch_size, 1], dtype=tf.float32)
        self.s_ = tf.placeholder(shape=input_shape, dtype=tf.float32)
        self.y = self.r + gamma*(1.0 - self.done)*tf.reduce_max(target_Q(self.s_), axis=1, keep_dims=True)

        # Error Clipping
        self.loss = tf.reduce_mean(Hurber_loss(self.q_val, self.y))

        # Update Q
        opt = tf.train.RMSPropOptimizer(0.00025, 0.99, 0.0, 1e-6)
        grads_and_vars = opt.compute_gradients(self.loss)
        grads_and_vars = [[grad, var] for grad, var in grads_and_vars \
                          if grad is not None and var.name.startswith("Q")]
        self.train_op = opt.apply_gradients(grads_and_vars)

        # Update target Q
        self.target_train_op = copy_params(Q, target_Q)

        # replay buffer
        self.D = []

    def update_target(self, sess):
        _ = sess.run(self.target_train_op)

    def update(self, sess):
        # sample from replay buffer
        samples = random.sample(self.D, self.batch_size)
        s = np.asarray([sample[0] for sample in samples], dtype=np.float32)
        a = np.asarray([[sample[1]] for sample in samples], dtype=np.int32)
        r = np.asarray([[sample[2]] for sample in samples], dtype=np.float32)
        done = np.asarray([[sample[3]] for sample in samples], dtype=np.float32)
        s_ = np.asarray([sample[4] for sample in samples], dtype=np.float32)

        feed={self.s:s, self.a:a, self.r:r, self.done:done, self.s_:s_}
        _ = sess.run(self.train_op, feed_dict=feed)

    def greedy(self, s, sess):
        probs = sess.run( self.probs, feed_dict={self.s:s})
        return np.argmax(probs)

    def set_exp(self, exp):
        if len(self.D) <= self.N:
            self.D.append(exp)
        else:
            s, a, r, done, _ = self.D[0]
            self.D = self.D[1:]
            self.D.append(exp)

            del s, a, r, done


text:
set schema 's';

alter tablespace ts add datafile 'ts1.dat' size 1m
;
alter table t recover indexes
;
select index_name,status,num_blocks_vi from indexes where table_name='T'
;
drop index i3
;
create index i3 on t(c3)
;


text:
'use strict'

const fs = require('fs')
const path = require('path')
const z = require('zero-fill')
const fileExists = require('file-exists').sync
const MatroskaSubtitles = require('matroska-subtitles')

// https://stackoverflow.com/questions/9763441/milliseconds-to-time-in-javascript
function msToTime (s) {
  const ms = s % 1000
  s = (s - ms) / 1000
  const secs = s % 60
  s = (s - secs) / 60
  const mins = s % 60
  const hrs = (s - mins) / 60

  return z(2, hrs) + ':' + z(2, mins) + ':' + z(2, secs) + ',' + z(3, ms)
}

/**
 * Reads mkv file and writes srt files in same location or in outputDir
 */
const mkvSubtitleExtractor = (mkvPath, outputDir) => new Promise((resolve, reject) => {
  const dir = outputDir || path.dirname(mkvPath)
  const name = path.basename(mkvPath, path.extname(mkvPath))

  // create srt path from language suffix
  const srtPath = function (language) {
    const languageSuffix = language ? '.' + language : ''
    return path.join(dir, name + languageSuffix + '.srt')
  }

  const tracks = new Map()
  const subs = new MatroskaSubtitles()

  subs.once('tracks', tracks_ => {
    tracks_.forEach(track => {
      // sometimes `und` (undefined) is used as the default value, instead of leaving the tag unassigned
      const language = track.language !== 'und' ? track.language : null
      let subtitlePath = srtPath(language)

      // obtain unique filename (don't overwrite)
      for (let i = 2; fileExists(subtitlePath); i++) {
        subtitlePath = language ? srtPath(language + i) : srtPath(i)
      }

      tracks.set(track.number, {
        index: 1,
        file: fs.createWriteStream(subtitlePath),
        language
      })
    })
  })

  subs.on('subtitle', (sub, trackNumber) => {
    const track = tracks.get(trackNumber)

    // convert to srt format
    track.file.write(`${track.index++}\r\n`)
    track.file.write(`${msToTime(sub.time)} --> ${msToTime(sub.time + sub.duration)}\r\n`)
    track.file.write(`${sub.text}\r\n\r\n`)
  })

  subs.on('finish', () => {
    const tracks_ = []

    tracks.forEach((track, i) => {
      track.file.end()
      tracks_.push({number: i, path: track.file.path, language: track.language})
    })
    resolve(tracks_)
  })

  const file = fs.createReadStream(mkvPath)
  file.on('error', err => reject(err))
  file.pipe(subs)
})

module.exports = mkvSubtitleExtractor


text:
import fs from "fs";
import path from "path";
import crypto from "crypto";

import munger from "../src/mpeg-munger-stream.js";

const hashFile = function(filename) {
  const data = fs.readFileSync(filename);
  return crypto
    .createHmac("sha256", "")
    .update(data)
    .digest("hex");
};

const testForFile = function(fileDetails) {
  const testFile = path.resolve(__dirname, fileDetails.name);
  const testFileOut = path.resolve(__dirname, fileDetails.name + ".out");
  describe(fileDetails.name, function() {
    let readStream;
    let writeStream;

    beforeEach(function() {
      readStream = fs.createReadStream(testFile);
      writeStream = fs.createWriteStream(testFileOut);
    });

    afterEach(function() {
      if (fs.existsSync(testFileOut)) {
        fs.unlinkSync(testFileOut);
      }
    });

    it("should keep streams intact if given no operation", function(done) {
      const mStream = munger();
      readStream.pipe(mStream);
      mStream.pipe(writeStream);
      writeStream.on("finish", function() {
        const inStats = fs.statSync(testFile);
        const outStats = fs.statSync(testFileOut);
        expect(inStats.size).toEqual(outStats.size);
        expect(hashFile(testFile)).toEqual(hashFile(testFileOut));
        done();
      });
    });

    // Gonna do as much monkeypatching for testing as I can, so that every single line of code in
    // the live-video code path is as lean as possible.
    it("should get an accurate packet count", function(done) {
      let packets = 0;
      let headers = 0;
      const mStream = munger();
      const origRewrite = mStream._rewrite;
      const origRewriteHeader = mStream._rewriteHeader;
      mStream._rewrite = function(...args) {
        packets += 1;
        return origRewrite.call(mStream, ...args);
      };
      mStream._rewriteHeader = function(...args) {
        headers += 1;
        return origRewriteHeader.call(mStream, ...args);
      };
      readStream.pipe(mStream);
      mStream.pipe(writeStream);
      writeStream.on("finish", function() {
        expect(packets).toEqual(fileDetails.packets);
        expect(headers).toEqual(fileDetails.headers);
        done();
      });
    });

    it("should handle packets less than and equal to 188 bytes in size", function(done) {
      const mStream = munger();
      readStream.on("data", function(chunk) {
        let startIdx = 0;
        let increment = 0;
        while (startIdx < chunk.length) {
          let endIdx = startIdx + increment;
          if (endIdx > chunk.length) {
            endIdx = chunk.length;
          }
          increment = (increment + 1) % 200;
          mStream.write(chunk.slice(startIdx, endIdx));
          startIdx = endIdx;
        }
      });
      readStream.on("end", function() {
        mStream.end();
      });
      mStream.pipe(writeStream);
      writeStream.on("finish", function() {
        const inStats = fs.statSync(testFile);
        const outStats = fs.statSync(testFileOut);
        expect(inStats.size).toEqual(outStats.size);
        expect(hashFile(testFile)).toEqual(hashFile(testFileOut));
        done();
      });
    });

    // Manually checked from the file
    // First: PTS: 132030, DTS: 126000
    // Last: PTS: 5529060, DTS: 5523030
    // Taking advantage of the fact that PTS is always parsed before DTS here.
    it("should correctly parse PTS and DTS", function(done) {
      let firstPTS = null;
      let firstDTS = null;
      let lastPTS = null;
      let lastDTS = null;
      const mStream = munger();
      mStream.transformPTS = function(pts) {
        if (firstPTS === null) {
          firstPTS = pts;
        }
        lastPTS = pts;
        return pts;
      };
      mStream.transformDTS = function(dts) {
        if (firstDTS === null) {
          firstDTS = dts;
        }
        lastDTS = dts;
        return dts;
      };
      readStream.pipe(mStream);
      mStream.pipe(writeStream);
      writeStream.on("finish", function() {
        expect(firstPTS).toEqual(fileDetails.firstPTS);
        expect(firstDTS).toEqual(fileDetails.firstDTS);
        expect(lastPTS).toEqual(fileDetails.lastPTS);
        expect(lastDTS).toEqual(fileDetails.lastDTS);
        done();
      });
    });

    it("should correctly offset PTS and DTS", function(done) {
      let firstPTS = null;
      let firstDTS = null;
      let lastPTS = null;
      let lastDTS = null;

      const mWriteStream = munger();
      // Never actually do this, lol
      mWriteStream.transformPTS = function(pts) {
        pts += 1000;
        if (firstPTS === null) {
          firstPTS = pts;
        }
        lastPTS = pts;
        return pts;
      };
      mWriteStream.transformDTS = function(dts) {
        dts -= 1000;
        if (firstDTS === null) {
          firstDTS = dts;
        }
        lastDTS = dts;
        return dts;
      };

      const mReadStream = munger();
      readStream.pipe(mWriteStream);
      mWriteStream.pipe(mReadStream);
      mReadStream.pipe(writeStream);
      writeStream.on("finish", function() {
        const expectedFirstDTS = fileDetails.firstDTS
          ? fileDetails.firstDTS - 1000
          : null;
        const expectedLastDTS = fileDetails.lastDTS
          ? fileDetails.lastDTS - 1000
          : null;
        expect(firstPTS).toEqual(fileDetails.firstPTS + 1000);
        expect(firstDTS).toEqual(expectedFirstDTS);
        expect(lastPTS).toEqual(fileDetails.lastPTS + 1000);
        expect(lastDTS).toEqual(expectedLastDTS);
        done();
      });
    });
  });
};

testForFile({
  name: "testvid.ts",
  packets: 2872,
  headers: 1800,
  firstPTS: 132030,
  lastPTS: 5529060,
  firstDTS: 126000,
  lastDTS: 5523030
});

testForFile({
  name: "elis-face.ts",
  packets: 29900,
  headers: 1206,
  firstPTS: 128090,
  lastPTS: 2826017,
  firstDTS: null,
  lastDTS: null
});


text:
/* common.h - Common includes for Chrome EC */

#ifndef __CROS_EC_COMMON_H
#define __CROS_EC_COMMON_H

#include <stdint.h>

/*
 * Macros to concatenate 2 - 4 tokens together to form a single token.
 * Multiple levels of nesting are required to convince the preprocessor to
 * expand currently-defined tokens before concatenation.
 *
 * For example, if you have
 *     #define FOO 1
 *     #define BAR1 42
 * Then
 *     #define BAZ CONCAT2(BAR, FOO)
 * Will evaluate to BAR1, which then evaluates to 42.
 */
#define CONCAT_STAGE_1(w, x, y, z) w ## x ## y ## z
#define CONCAT2(w, x) CONCAT_STAGE_1(w, x, , )
#define CONCAT3(w, x, y) CONCAT_STAGE_1(w, x, y, )
#define CONCAT4(w, x, y, z) CONCAT_STAGE_1(w, x, y, z)

/*
 * Macros to turn the argument into a string constant.
 *
 * Compared to directly using the preprocessor # operator, this 2-stage macro
 * is safe with regards to using nested macros and defined arguments.
 */
#define STRINGIFY0(name)  #name
#define STRINGIFY(name)  STRINGIFY0(name)

/* Macros to access registers */
#define REG32_ADDR(addr) ((volatile uint32_t *)(addr))
#define REG16_ADDR(addr) ((volatile uint16_t *)(addr))
#define REG8_ADDR(addr)  ((volatile uint8_t  *)(addr))

#define REG32(addr) (*REG32_ADDR(addr))
#define REG16(addr) (*REG16_ADDR(addr))
#define REG8(addr)  (*REG8_ADDR(addr))

/*
 * Define __aligned(n) and __packed if someone hasn't beat us to it.  Linux
 * kernel style checking prefers these over __attribute__((packed)) and
 * __attribute__((aligned(n))).
 */
#ifndef __aligned
#define __aligned(n) __attribute__((aligned(n)))
#endif

#ifndef __packed
#define __packed __attribute__((packed))
#endif

/*
 * Force the toolchain to keep a symbol even with Link Time Optimization
 * activated.
 *
 * Useful for C functions called only from assembly or through special sections.
 */
#ifndef __keep
#define __keep __attribute__((used)) __attribute__((externally_visible))
#endif

/* There isn't really a better place for this */
#define C_TO_K(temp_c) ((temp_c) + 273)
#define K_TO_C(temp_c) ((temp_c) - 273)
#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
#define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10)

/* Include top-level configuration file */
#include "config.h"

/* Canonical list of module IDs */
#include "module_id.h"

/* List of common error codes that can be returned */
enum ec_error_list {
	/* Success - no error */
	EC_SUCCESS = 0,
	/* Unknown error */
	EC_ERROR_UNKNOWN = 1,
	/* Function not implemented yet */
	EC_ERROR_UNIMPLEMENTED = 2,
	/* Overflow error; too much input provided. */
	EC_ERROR_OVERFLOW = 3,
	/* Timeout */
	EC_ERROR_TIMEOUT = 4,
	/* Invalid argument */
	EC_ERROR_INVAL = 5,
	/* Already in use, or not ready yet */
	EC_ERROR_BUSY = 6,
	/* Access denied */
	EC_ERROR_ACCESS_DENIED = 7,
	/* Failed because component does not have power */
	EC_ERROR_NOT_POWERED = 8,
	/* Failed because component is not calibrated */
	EC_ERROR_NOT_CALIBRATED = 9,
	/* Failed because CRC error */
	EC_ERROR_CRC = 10,
	/* Invalid console command param (PARAMn means parameter n is bad) */
	EC_ERROR_PARAM1 = 11,
	EC_ERROR_PARAM2 = 12,
	EC_ERROR_PARAM3 = 13,
	EC_ERROR_PARAM4 = 14,
	EC_ERROR_PARAM5 = 15,
	EC_ERROR_PARAM6 = 16,
	EC_ERROR_PARAM7 = 17,
	EC_ERROR_PARAM8 = 18,
	EC_ERROR_PARAM9 = 19,
	EC_ERROR_PARAM_COUNT = 20,  /* Wrong number of params */

	/* Module-internal error codes may use this range.   */
	EC_ERROR_INTERNAL_FIRST = 0x10000,
	EC_ERROR_INTERNAL_LAST =  0x1FFFF
};

/*
 * Define test_mockable and test_mockable_static for mocking
 * functions.
 */
#ifdef TEST_BUILD
#define test_mockable __attribute__((weak))
#define test_mockable_static __attribute__((weak))
#define test_export_static
#else
#define test_mockable
#define test_mockable_static static
#define test_export_static static
#endif

#endif  /* __CROS_EC_COMMON_H */


text:
**Advanced Lane Finding Project**

The goals / steps of this project are the following:

* Compute the camera calibration matrix and distortion coefficients given a set of chessboard images.
* Apply a distortion correction to raw images.
* Use color transforms, gradients, etc., to create a thresholded binary image.
* Apply a perspective transform to rectify binary image ("birds-eye view").
* Detect lane pixels and fit to find the lane boundary.
* Determine the curvature of the lane and vehicle position with respect to center.
* Warp the detected lane boundaries back onto the original image.
* Output visual display of the lane boundaries and numerical estimation of lane curvature and vehicle position.

[//]: # (Image References)

[image1]: /writeup_imgs/chess.png "Undistorted chessboard"
[image2]: /writeup_imgs/undistort.png "Road Transformed"
[image3]: /writeup_imgs/tresholds.png "Binary Example"
[image4]: /writeup_imgs/warped.png "Warp Example"
[image5]: /writeup_imgs/fit.png "Fit Visual"
[image6]: /writeup_imgs/drawed.png "Output"

## [Rubric](https://review.udacity.com/#!/rubrics/571/view) Points

### Here I will consider the rubric points individually and describe how I addressed each point in my implementation.

---

### Camera Calibration

#### 1. Briefly state how you computed the camera matrix and distortion coefficients. Provide an example of a distortion corrected calibration image.

The code for this step is contained in the first three code cells of the IPython notebook  "Advanced_lane_finding"

I start by preparing "object points", which will be the (x, y, z) coordinates of the chessboard corners in the real world. Here I am assuming the chessboard is fixed on the (x, y) plane at z=0, such that the object points are the same for each calibration image.  Thus, `objp` is just a replicated array of coordinates, and `objpoints` will be appended with a copy of it every time I successfully detect all chessboard corners in a test image.  `imgpoints` will be appended with the (x, y) pixel position of each of the corners in the image plane with each successful chessboard detection.

I then used the output `objpoints` and `imgpoints` to compute the camera calibration and distortion coefficients using the `cv2.calibrateCamera()` function.  I applied this distortion correction to the test image using the `cv2.undistort()` function and the obtained distortion coeficients sved in the "mtx" and "dist" arrays. The undistorted chessboard images look like the following result:

![alt text][image1]

### Pipeline (single images)

#### 1. Provide an example of a distortion-corrected image.

To demonstrate this step, I will describe how I apply the distortion correction to one of the test images like this one:
![alt text][image2]

The image was undistorted calling the OpenCV function "undistort(img,mtx,dist,None,mtx)" using the previously obtained distortion coeficents as explained in the previous point.

#### 2. Describe how (and identify where in your code) you used color transforms, gradients or other methods to create a thresholded binary image.  Provide an example of a binary image result.

I used a combination of color and gradient thresholds to generate a binary image (thresholding steps at cell 9 in `Avanced_line_finding.pynb`).  Here's an example of my output for this step.

![alt text][image3]

First the image was converted to HLS and LAB color spaces and after try error loops S and B channels were found as the critical ones to use. Once isolated the S and B channels, x and y sobel gradient tresholds where applyed to the image loosing less information than with the usual grayscaled image. The undiscarded noise of trees and other objects is later discarded correctl aplying the perspective transform.

#### 3. Describe how (and identify where in your code) you performed a perspective transform and provide an example of a transformed image.

The code for my perspective transform includes a function called `warp()`, which appears in the cell 10 in the file `Avanced_line_finding.pynb`.  The `warp()` function takes as inputs an image (`img`), as well as M transformation matrix calculated in the cell number 9 from the defined source and destination points.  I chose the hardcode the source and destination points in the following manner:

```python
#SOURCE RECTANGLE POINTS
src = np.float32([(565,460),
                  (728,460),
                  (1195,685),
                  (150,685)])

#WARPED RECTANGLE POINTS
dst = np.float32([(350,0),
                  (img.shape[1]-350,0),
                  (img.shape[1]-350,img.shape[0]),
                  (350,img.shape[0])])
```

This resulted in the following source and destination points:

| Source        | Destination   |
|:-------------:|:-------------:|
| 565, 460      | 350, 0        |
| 728, 460      | 930, 0        |
| 1197, 685     | 930, 720      |
| 150, 685      | 350, 720      |

I verified that my perspective transform was working as expected by drawing the rectangle formed by `src` and `dst` points onto a test image and its warped counterpart to verify that the lines appear parallel in the warped image.

![alt text][image4]

#### 4. Describe how (and identify where in your code) you identified lane-line pixels and fit their positions with a polynomial?

Using the code provided by Udacity, I implemented the sliding window search method `polyfit_sliding_window` (cell 12) backed by the histogram peak first aproximation. Once detected the pixel point belonging to the lines, a secon order polynomial was fitted to each right and left lines.

Following the class advices I created a Line class (cell 16)  to save the 10 previous best fits obtained and checked with a brief sanity check that compares the coeficients of the recently obtained fit with the previous saved average. If there is a fit saved and considerated best fit, the other explained method is used.

This other method `polyfit_next_frame` (cell 12) is quite faster, as it searches for the line within a 40px margin from the previous fit.

![alt text][image5]

#### 5. Describe how (and identify where in your code) you calculated the radius of curvature of the lane and the position of the vehicle with respect to center.

I did this in the function `calc_curv_rad_center`, in the cell number 14 of the notebook, converting from pixel to metric world using the Udacity provided conversions, I calculated the distance to the center comparing the image center point with the center of the two fitted polynomials in the bottom of the picture.

```python
car_position = (bin_img.shape[1])/2
l_fit_x_int = l_fit[0]*h**2 + l_fit[1]*h + l_fit[2]
r_fit_x_int = r_fit[0]*h**2 + r_fit[1]*h + r_fit[2]
lane_center_position = (r_fit_x_int + l_fit_x_int) /2
center_dist = (car_position - lane_center_position) * xm_per_pix
```

For the curvature, I used the code provided in the classroom as follows

```python
 Calculate the new radii of curvature
        left_curverad = ((1 + (2*left_fit_cr[0]*y_eval*ym_per_pix + left_fit_cr[1])**2)**1.5) / np.absolute(2*left_fit_cr[0])
        right_curverad = ((1 + (2*right_fit_cr[0]*y_eval*ym_per_pix + right_fit_cr[1])**2)**1.5) / np.absolute(2*right_fit_cr[0])
```

#### 6. Provide an example image of your result plotted back down onto the road such that the lane area is identified clearly.

I implemented this step in the cell  14, in the function `draw_lane()`.  Here is an example of my result on a test image:

![alt text][image6]

As can be seen the function, appends the curvature and center to distance values using the values obtained by the `calc_curv_rad_center` function and draws the identifyed lane portion using the classroom code

---

### Pipeline (video)

#### 1. Provide a link to your final video output.  Your pipeline should perform reasonably well on the entire project video (wobbly lines are ok but no catastrophic failures that would cause the car to drive off the road!).

Here's a [link to my video result](/project_video_out.mp4)

---

### Discussion

#### 1. Briefly discuss any problems / issues you faced in your implementation of this project.  Where will your pipeline likely fail?  What could you do to make it more robust?

The pipeline may fail in very extreme curvature radius, as the perspective transform discards the sourroundings maybe too agresively.

On the other hand, it could also fail in different lighting conditions, as the tresholds have been adapted to the project video data to perform better, in a certain sense the pipeline is overfitted to the project video and a more robust pipeline should be developed based in more invariant data in the future


text:
(function() {
  Polymer({
    is: "da-date-field",
    properties: {
      _day: {
        type: Number,
        notify: true
      },
      _month: {
        type: Number,
        notify: true
      },
      _year: {
        type: Number,
        notify: true
      },
      editing: {
        type: Boolean,
        notify: true,
        value: false
      },
      label: {
        type: String,
        value: "BS"
      },
      format: {
        type: String,
        value: "long"
      },
      date: {
        type: Date,
        notify: true,
        observer: 'dateChange'
      },
      formattedDate: {
        type: String,
        computed: "_formattedDate(date)",
        notify: true
      }
    },
    listeners: {
      'paper-dropdown-open': 'open'
    },
    focusField: function(e) {
      window.clearTimeout(this.timeout);
      return e.target.$.input.select();
    },
    blurField: function(e) {
      if (e.detail.sourceEvent != null) {
        if (e.detail.sourceEvent.relatedTarget != null) {
          if (e.detail.sourceEvent.relatedTarget.tagName !== "PAPER-ITEM") {
            return this.timeout = setTimeout((function(_this) {
              return function() {
                return _this.finish();
              };
            })(this), "25");
          } else {
            return e.target.focus();
          }
        } else {
          return this.timeout = setTimeout((function(_this) {
            return function() {
              return _this.finish();
            };
          })(this), "25");
        }
      }
    },
    change: function(e) {
      if (e.srcElement.maxLength < e.srcElement.value.length + 1) {
        if (this.$.month.focused) {
          return this.$.day.$.input.focus();
        } else if (this.$.day.focused) {
          return this.$.year.$.input.focus();
        } else if (this.$.year.focused) {
          return this.$.year.blur();
        }
      }
    },
    finish: function(e) {
      this.date = moment(this._month + "-" + this._day + "-" + this._year).format("MM-DD-YYYY");
      return this.editing = false;
    },
    open: function() {
      this._day = moment(this.date).date();
      this._month = moment(this.date).month() + 1;
      this._year = moment(this.date).year();
      this.editing = true;
      return this.$.month.$.input.focus();
    },
    dateChange: function(newVal, oldVal) {
      this.$.dropdown._setSelectedItem(this.$.resetter);
      return this.$.dropdown._setSelectedItem(this.$.label);
    },
    _formattedDate: function(date) {
      if (this.format === "short") {
        return moment(this.date).format(date, "MM-DD-YY");
      } else {
        return moment(this.date).format("ddd, MMMM Do, YYYY");
      }
    }
  });

}).call(this);