text:
import optparse
import logging
import sys
from unfurl import Crawler, Page, Snapshot, Database
from unfurl.config import DEFAULT_CONFIG, CONFIG, ConfigurationError
import sqlite3

LOG = logging.getLogger(__name__)

class UnfurlOptionParser(optparse.OptionParser):
    def load_database(self):
        try:
            return Database()
        except Exception, e:
            self.error(e.args[0])

    def load_config(self, config=None):
        config = config or CONFIG
        try:
            config.load()
        except ConfigurationError, e:
            self.error('problem understanding configuration: ' + e.exception.args[0])

    def load_environment(self):
        self.load_config()
        self.load_database()

def error(message):
    sys.stderr.write(' unfurl: error: %s\n' % message)

def abort(message):
    error(message)
    raise SystemExit(1)

def get_cli():
    cli = UnfurlOptionParser(prog='unfurl',
      usage='unfurl <subcommand> [arguments] [options]',
      epilog='Valid subcommands: %s' % ', '.join(COMMANDS.keys()))
    cli.add_option('--debug', action='store_true',
      help='enable debug output')
    return cli

def get_crawl_cli():
    cli = UnfurlOptionParser(prog='unfurl crawl',
        usage='unfurl crawl <url> [url, url, ...] [options]')
    cli.add_option('-p', '--period', type=int,
      help='Time in seconds between crawls (defaults to 1 hour)')
    cli.add_option('-c', '--count', type=int,
      help='Crawl a specified number of times (defaults to forever)')
    cli.add_option('-m', '--max-threads', type=int,
      help='Maximum number of threads to use for crawling')
    cli.add_option('--threading', action='store_true',
      help='Whether to enable multi-threaded mode (defaults to false)')
    return cli

def get_diff_cli():
    cli = UnfurlOptionParser(prog='unfurl diff',
        usage='unfurl diff <url> [options]')
    cli.add_option('-o', '--old', type=int, default=1,
      help='Offset of the "old" snapshot (0 is latest, 1 is next oldest, etc.)'
           ' Defaults to 1.')
    cli.add_option('-n', '--new', type=int, default=0,
      help='Offset of the "old" snapshot (0 is latest, 1 is next oldest, etc.)'
           ' Defaults to 0.')
    return cli

def get_dump_cli():
    cli = UnfurlOptionParser(prog='unfurl dump',
        usage='unfurl dump <url> [options]')
    cli.add_option('-o', '--offset', type=int, default=1,
      help='Offset of the snapshot to dump (0 is latest, 1 is next oldest, etc.)'
           ' Defaults to 0 (latest).')
    return cli

def get_snap_cli():
    cli = UnfurlOptionParser(prog='unfurl snap',
        usage='unfurl snap <url> [options]')
    return cli

def main_main(argv):
    cli = get_cli()
    opts, args = cli.parse_args(['-h'])

def main_diff(argv):
    cli = get_diff_cli()
    opts, args = cli.parse_args(argv)

    if len(args) < 1:
        cli.error('requires a url')

    cli.load_environment()

    diff = Snapshot.diff(args[0], old_offset=opts.old, new_offset=opts.new)
    sys.stdout.write(diff)

def main_crawl(argv):
    cli = get_crawl_cli()
    opts, args = cli.parse_args(argv)

    if args:
        LOG.debug('command-line set to crawl pages: %s' % ', '.join(args))

    cli.load_environment()

    crawler = Crawler(
      period=CONFIG.prefer(opts.period, 'crawler', 'period'),
      count=CONFIG.prefer(opts.count, 'crawler', 'count'),
      threaded=CONFIG.prefer(opts.threading, 'crawler', 'threaded'),
      max_threads=CONFIG.prefer(opts.max_threads, 'crawler', 'max_threads')
    )
    pages = list(set(args + CONFIG.pages))
    pages = [ Page(i) for i in pages ]
    crawler.crawl(pages)

def main_snap(argv):
    cli = get_snap_cli()
    opts, args = cli.parse_args(argv)

    if not args:
        cli.error('requires a url')

    cli.load_environment()

    crawler = Crawler(period=0, count=1, threaded=False, log_level=logging.NOTSET)
    crawler.crawl([ Page(args[0]) ])

def main_dump(argv):
    cli = get_dump_cli()
    opts, args = cli.parse_args(argv)

    if not args:
        cli.error('requires a url')

    cli.load_environment()

    success = Snapshot.dump(url=args[0])

    if not success:
        abort('no snapshots for that url')

COMMANDS = {
  'diff': main_diff,
  'crawl': main_crawl,
  'snap': main_snap,
  'dump': main_dump,
}

def main(argv=None):
    argv = argv or sys.argv
    argv.pop(0) # discard runtime

    try:
        command = argv.pop(0)
    except IndexError:
        command = None

    if command and command.startswith('-'):
        command = None

    LOG.debug('subcommand is "%s"' % command)

    driver = COMMANDS.get(command, main_main)
    LOG.debug('mapped to driver "%s"' % driver.__name__)

    try:
        driver(argv)
    except sqlite3.OperationalError, e:
        abort(e.args[0])


text:
namespace device_signals {

const std::string ErrorToString(SignalCollectionError error) {
  switch (error) {
    case SignalCollectionError::kConsentRequired:
      return errors::kConsentRequired;
    case SignalCollectionError::kUnaffiliatedUser:
      return errors::kUnaffiliatedUser;
    case SignalCollectionError::kUnsupported:
      return errors::kUnsupported;
    case SignalCollectionError::kMissingSystemService:
      return errors::kMissingSystemService;
    case SignalCollectionError::kMissingBundle:
      return errors::kMissingBundle;
    case SignalCollectionError::kInvalidUser:
      return errors::kInvalidUser;
    case SignalCollectionError::kMissingParameters:
      return errors::kMissingParameters;
  }
}

BaseSignalResponse::~BaseSignalResponse() = default;

#if BUILDFLAG(IS_WIN)
AntiVirusSignalResponse::AntiVirusSignalResponse() = default;
AntiVirusSignalResponse::AntiVirusSignalResponse(
    const AntiVirusSignalResponse&) = default;

AntiVirusSignalResponse& AntiVirusSignalResponse::operator=(
    const AntiVirusSignalResponse&) = default;

AntiVirusSignalResponse::~AntiVirusSignalResponse() = default;

HotfixSignalResponse::HotfixSignalResponse() = default;
HotfixSignalResponse::HotfixSignalResponse(const HotfixSignalResponse&) =
    default;

HotfixSignalResponse& HotfixSignalResponse::operator=(
    const HotfixSignalResponse&) = default;

HotfixSignalResponse::~HotfixSignalResponse() = default;
#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)

GetSettingsOptions::GetSettingsOptions() = default;
GetSettingsOptions::GetSettingsOptions(const GetSettingsOptions&) = default;

GetSettingsOptions& GetSettingsOptions::operator=(const GetSettingsOptions&) =
    default;

GetSettingsOptions::~GetSettingsOptions() = default;

SettingsItem::SettingsItem() = default;

SettingsItem::SettingsItem(const SettingsItem& other) {
  path = other.path;
  key = other.key;
  hive = other.hive;
  presence = other.presence;
  if (other.setting_value) {
    setting_value = other.setting_value->Clone();
  }
}

SettingsItem& SettingsItem::operator=(const SettingsItem& other) {
  path = other.path;
  key = other.key;
  hive = other.hive;
  presence = other.presence;
  if (other.setting_value) {
    setting_value = other.setting_value->Clone();
  }
  return *this;
}

SettingsItem::~SettingsItem() = default;

SettingsResponse::SettingsResponse() = default;
SettingsResponse::SettingsResponse(const SettingsResponse&) = default;

SettingsResponse& SettingsResponse::operator=(const SettingsResponse&) =
    default;

SettingsResponse::~SettingsResponse() = default;

#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)

FileSystemInfoResponse::FileSystemInfoResponse() = default;
FileSystemInfoResponse::FileSystemInfoResponse(const FileSystemInfoResponse&) =
    default;

FileSystemInfoResponse& FileSystemInfoResponse::operator=(
    const FileSystemInfoResponse&) = default;

FileSystemInfoResponse::~FileSystemInfoResponse() = default;

SignalsAggregationRequest::SignalsAggregationRequest() = default;
SignalsAggregationRequest::SignalsAggregationRequest(
    const SignalsAggregationRequest&) = default;

SignalsAggregationRequest& SignalsAggregationRequest::operator=(
    const SignalsAggregationRequest&) = default;

SignalsAggregationRequest::~SignalsAggregationRequest() = default;

bool SignalsAggregationRequest::operator==(
    const SignalsAggregationRequest& other) const {
  return user_context == other.user_context &&
         signal_names == other.signal_names;
}

SignalsAggregationResponse::SignalsAggregationResponse() = default;
SignalsAggregationResponse::SignalsAggregationResponse(
    const SignalsAggregationResponse&) = default;

SignalsAggregationResponse& SignalsAggregationResponse::operator=(
    const SignalsAggregationResponse&) = default;

SignalsAggregationResponse::~SignalsAggregationResponse() = default;

}  // namespace device_signals

redpajama_set_name: RedPajamaGithub


text:
/* Generated code */

interface GlipPersonInfo {

	/**
	 * Internal identifier of a user
	 */
	id?: string;

	/**
	 * First name of a user
	 */
	firstName?: string;

	/**
	 * Last name of a user
	 */
	lastName?: string;

	/**
	 * Email of a user
	 */
	email?: string;

	/**
	 * Photo of a user
	 */
	avatar?: string;

	/**
	 * Internal identifier of a company
	 */
	companyId?: string;

	/**
	 * Time of creation in ISO 8601 format
	 */
	creationTime?: string;

	/**
	 * Time of last modification in ISO 8601 format
	 */
	lastModifiedTime?: string;
}

export default GlipPersonInfo;


text:
/* Database created using psql for tests - query_test */
DROP TABLE pages;
CREATE TABLE pages (
    id SERIAL NOT NULL,
    title text,
    text text,
    keywords text,
    status integer,
    created_at timestamp NOT NULL,
    updated_at timestamp NOT NULL,
    url text,
    summary text
);

insert into pages (title,text,keywords,status,created_at,updated_at,url,summary) VALUES('Title 1.','test 1 text','keywords1',100,NOW(),NOW(),'test.example.com','');
insert into pages (title,text,keywords,status,created_at,updated_at,url,summary) VALUES('Title 2','test 2 text','keywords 2',100,NOW(),NOW(),'test.example.com','');
insert into pages (title,text,keywords,status,created_at,updated_at,url,summary) VALUES('Title 3 here','test 3 text','keywords,3',100,NOW(),NOW(),'test.example.com','');


text:
title: Defragmenting
...

<M4Definition source="Wikipedia">
In the maintenance of file systems, defragmentation is a process that reduces
the amount of fragmentation. It does this by physically organizing the
contents of the mass storage device used to store files into the smallest
number of contiguous regions (fragments).
</M4Definition>

<Metaphor id="hangers" image="hangers">
<M4Title>Defragmenting is Moving Hangers in your Closet.</M4Title>
As people wear clothing in their closet, they tend to take an article from the
rod and leave the hanger in place.  As time passes, as you search for the next
item you want to wear, the hangers start getting in the way.

Then, when your laundry is ready to hang up, what do most people do?  Rather
than search through the hung clothing for a single hanger on which to hang one
of several items... you find all of the empty hangers and move them to one end.
This makes it easier to find space for your clothes.

Defragmenting a hard drive is the same idea.  As files are stored, they're
placed in empty space as it becomes available.  When you delete a file, the
space you've allocated for that file is freed (an empty hanger).  Finding empty
space for your files begins to take longer and longer as time goes on.

When you defragment the hard drive, you move all of the empty space to one part
of the disk, making it easier for the computer to find space for new files
(and making it easier for the disk to find it later!).
<M4Author handle="livlihood" href="#" />
</Metaphor>

<Metaphor id="suitcase">
<M4Title>Defragmenting is Packing a Suitcase</M4Title>
Imagine the storage device is a suitcase. When we pack, when we add something new, we put something into the suitcase. We might also remove something, which is the opposite: we are pulling something out of the suitcase.

Here is a problem we often have: what if we want to add one more big object into the suitcase? We know that the suitcase has enough space to hold it, we have already pulled enough stuff out. The trouble is the space we need is spread out randomly in the suitcase.

What should we do? Reorganize the suitcase! Bingo! This is the time and the reason we need to defragment our storage device as well!
<M4Author handle="watermelonlh" href="http://www.github.com/watermelonlh" />
</Metaphor>


text:
namespace tests {

  using std::endl;
  using std::make_pair;
  using std::pair;

  ParamMap::ParamMap() {
    addParam("help", "", "prints the command usage message");
  }

  bool ParamMap::addParam(const string& param,
    const string& default_string,
    const string& description) {
      pair<KeyToValueMap::iterator, bool> res;
      res = key_to_value_map_.insert(make_pair(param, default_string));
      if (res.second) {
        res = key_to_description_map_.insert(make_pair(param, description));
        return true;
      }

      return false;
  }

  bool ParamMap::getParam(const string& param, string* value) const {
    // The 'value' parameter is optional.
    string dummy;
    if (value == nullptr) {
      value = &dummy;
    }

    KeyToValueMap::const_iterator it = key_to_value_map_.find(param);
    if (it != key_to_value_map_.end()) {
      *value = it->second;
      return true;
    }

    return false;
  }

  bool ParamMap::parseArgv(int argc, const char* const argv[]) {
    program_name_ = argv[0];
    for (int i = 1; i < argc; i++) {
      string name;
      string value;
      string param(argv[i]);

      // Param must start with "--".
      if (param.find("--") != 0) {
        return false;
      }

      // Param must have a name.
      string::size_type pos = param.find("=");
      if (pos == 2) {
        return false;
      }

      // Value for a parameter is not mandatory.
      if (pos == string::npos) {
        name = param.substr(2);
      } else {
        name = param.substr(2, pos-2);
        value = param.substr(pos+1);
      }

      if (name == "help") {
        return false;
      } else {
        key_to_value_map_[name] = value;
      }
    }

    return true;
  }

  void ParamMap::printUsage() const {
    printf("Usage %s ", program_name_.c_str());
    for (KeyToValueMap::const_iterator itp = key_to_value_map_.begin();
      itp != key_to_value_map_.end();
      ++itp) {
        printf("--%s=[%s]", itp->first.c_str(), itp->second.c_str());
    }
    printf("\n");

    printf("where \n");
    KeyToDescriptionMap::const_iterator itd;
    for (itd = key_to_description_map_.begin();
      itd != key_to_description_map_.end();
      ++itd) {
        printf(" %s: %s \n", itd->first.c_str(), itd->second.c_str());
    }
  }

}  // namespace tests


text:
namespace phi {

template <typename T, typename Context>
void GumbelSoftmaxGradKernel(const Context& dev_ctx,
                             const DenseTensor& out,
                             const DenseTensor& dout,
                             int axis,
                             DenseTensor* dx);

}  // namespace phi


text:
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { AddonMessagesSettingsPage } from './settings';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { AddonMessagesComponentsModule } from '../../components/components.module';

@NgModule({
    declarations: [
        AddonMessagesSettingsPage,
    ],
    imports: [
        CoreComponentsModule,
        CoreDirectivesModule,
        AddonMessagesComponentsModule,
        IonicPageModule.forChild(AddonMessagesSettingsPage),
        TranslateModule.forChild()
    ],
})
export class AddonMessagesSettingsPageModule {}


text:
$:.push File.expand_path('../lib', __FILE__)

require 'rubygems'
require 'hashie'

require 'punchtab/version'
require 'punchtab/utils'
require 'punchtab/api'

module Punchtab

  class Client

    attr_reader :access_token

    def self.version
      Punchtab::VERSION
    end

    # authentication api methods
    def initialize(options = {})
      # initialize the API
      @api = Punchtab::API.new(options)

      # authenticate
      @access_token = @api.authenticate

    end

    def status
      @api.status
    end

    def logout
      @api.logout
    end

    # activity api methods
    def get_activity(options={})
      @api.get_activity(options)
    end

    def create_activity(activity_name, options={})
      @api.create_activity(activity_name, options)
    end

    def redeem_activity_offer(reward_id)
      @api.redeem_activity_offer(reward_id)
    end

    # user api methods
    def get_user
      @api.get_user
    end

    # reward api methods
    def get_reward(options={})
      @api.get_reward(options)
    end

    # leaderboard api methods
    def get_leaderboard(options={})
      @api.get_leaderboard(options)
    end

  end
end


text:
package prompt

import (
	"os"

	"golang.org/x/sys/unix"
)

const (
	tcgets  = unix.TCGETS
	tcsetsf = unix.TCSETSF
	tcsets  = unix.TCSETS
)

// terminalSize retrieves the cols/rows for the terminal connected to out.
func terminalSize(out *os.File) (int, int, error) {
	ws, err := unix.IoctlGetWinsize(int(out.Fd()), unix.TIOCGWINSZ)
	if err != nil {
		return 0, 0, err
	}

	return int(ws.Col), int(ws.Row), nil
}

// getTermios retrieves the termios settings for the terminal descriptor.
func getTermios(fd uintptr) (*unix.Termios, error) {
	return unix.IoctlGetTermios(int(fd), tcgets)
}

// setTermios sets the termios settings for the terminal descriptor,
// optionally flushing the buffer before setting.
func setTermios(fd uintptr, flush bool, mode *unix.Termios) error {
	req := tcsets
	if flush {
		req = tcsetsf
	}

	return unix.IoctlSetTermios(int(fd), uint(req), mode)
}


text:
package com.it114.android.oneframework.sample1.demo.mvplogin;

/**
 * Created by andy on 10/15/2015.
 */
public interface LoginInteractor {

    public void login(String userName,String password,LoginListener linstner);

}


text:
from os.path import realpath
from mininet.util import errFail, quietRun, errRun
from mininet.log import debug, info

# Utility functions for unmounting a tree

# Real path of OSHI's dir
MNRUNDIR = realpath( '/var/run/mn' )

# Take the mounted points of the root machine
def mountPoints():
    "Return list of mounted file systems"
    mtab, _err, _ret = errFail( 'cat /proc/mounts' )
    lines = mtab.split( '\n' )
    mounts = []
    for line in lines:
        if not line:
            continue
        fields = line.split( ' ')
        mount = fields[ 1 ]
        mounts.append( mount )
    return mounts

# Utility Function for unmount all the dirs
def unmountAll( rootdir=MNRUNDIR ):
    "Unmount all mounts under a directory tree"
    rootdir = realpath( rootdir )
    # Find all mounts below rootdir
    # This is subtle because /foo is not
    # a parent of /foot
    dirslash = rootdir + '/'
    mounts = [ m for m in mountPoints()
              if m == dir or m.find( dirslash ) == 0 ]
    # Unmount them from bottom to top
    mounts.sort( reverse=True )
    for mount in mounts:
        debug( 'Unmounting', mount, '\n' )
        _out, err, code = errRun( 'umount', mount )
        if code != 0:
            info( '*** Warning: failed to umount', mount, '\n' )
            info( err )

def fixIntf(hosts):
	for i in range(0, len(hosts)):
		for obj in hosts[i].nameToIntf:
	  		if 'lo' not in obj:
				fixNetworkManager(obj)
		fixNetworkManager(hosts[i])

def fixNetworkManager(intf):
	cfile = '/etc/network/interfaces'
  	line1 = 'iface %s inet manual\n' % intf
  	config = open( cfile ).read()
  	if ( line1 ) not in config:
		print '*** Adding', line1.strip(), 'to', cfile
		with open( cfile, 'a' ) as f:
	  		f.write( line1 )
	  	f.close();

def fixEnvironment():
	cfile = '/etc/environment'
  	line1 = 'VTYSH_PAGER=more\n'
  	config = open( cfile ).read()
  	if ( line1 ) not in config:
		print '*** Adding', line1.strip(), 'to', cfile
		with open( cfile, 'a' ) as f:
	  		f.write( line1 )
	  	f.close();

def strip_number(intf):
	intf = str(intf)
	a = intf.split('-')
	if len(a) > 2:
		print "*** WARNING BAD NAME FOR INTF - EXIT"
		sys.exit(-1)
	return int(a[1][3:])

def strip_ip(oshi):
	for intf in oshi.nameToIntf:
		if 'lo' not in intf:
			if 'eth0' in intf:
				oshi.cmd("ifconfig " + intf + " 0")


text:
from distutils.core import setup

setup(
    name='leastsqbound',
    version='1.1',
    author='Jonathan J. Helmus',
    author_email='jjhelmus@gmail.com',
    py_modules=['leastsqbound'],
    license='BSD',
    url='https://github.com/jjhelmus/leastsqbound-scipy',
    description='Constrained multivariate least-squares optimizer',
    long_description=open('README.txt').read(),
    requires=['numpy', 'scipy'],
    classifiers=[
        'Intended Audience :: Science/Research',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Programming Language :: Python',
        'Topic :: Scientific/Engineering',
        'Operating System :: MacOS :: MacOS X',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: POSIX :: Linux'
    ]
)


text:
[![NPM version](http://img.shields.io/npm/v/htmlhint-app.svg)](https://www.npmjs.org/package/htmlhint-app)
![Dependency Status](https://david-dm.org/mikwoskop/htmlhint-app.svg)

> Simple HTMLhint app

* * *

## Getting Started

**Note:** this is the first (and too fast made) version of the app. The design is ugly, and will be change soon.
The purpose was to test `node-webkit` system. :)

### Download binaries

#### Version 0.1.1

Just download & unzip the file, then run the application !

* Windows: [download](https://github.com/mikwoskop/htmlhint-app/raw/bb64167337d95824af506f62c447940e32a8773b/releases/win/mikwoskop-htmlhint.zip)
* Mac OSX: [download](https://github.com/mikwoskop/htmlhint-app/raw/bb64167337d95824af506f62c447940e32a8773b/releases/mac/mikwoskop-htmlhint.zip)
* Linux (32Bits): [download](https://github.com/mikwoskop/htmlhint-app/raw/bb64167337d95824af506f62c447940e32a8773b/releases/linux32/mikwoskop-htmlhint.zip)
* Linux (64Bits): [download](https://github.com/mikwoskop/htmlhint-app/raw/bb64167337d95824af506f62c447940e32a8773b/releases/linux64/mikwoskop-htmlhint.zip)

### Build the app from the sources

You can build the app by yourself:

1. Clone the repository
2. Run `npm install` to get the dependencies
3. Run `grunt build` to build the app
4. Find the app binaries in `/releases` folder.

## Contributing

_(Coming soon)_

### TODO

* [x] First release (0.1)
* [ ] Compact design
* [ ] Refactor code
* [ ] Add drag'n'drop support
* [ ] Specific design for:
    * [ ] Mac OS X Mavericks
    * [ ] Mac OS X Yosemite
    * [ ] Windows
    * [ ] Linux

## Release History

* **2014/06/15:** starting project

## License
Copyright (c) 2014 Leny
Licensed under the MIT license.


text:
package org.apache.drill.exec.rpc.user;

import io.netty.buffer.ByteBuf;
import io.netty.channel.EventLoopGroup;

import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
import org.apache.drill.exec.proto.GeneralRPCProtos.Ack;
import org.apache.drill.exec.proto.UserBitShared;
import org.apache.drill.exec.proto.UserBitShared.QueryData;
import org.apache.drill.exec.proto.UserBitShared.QueryId;
import org.apache.drill.exec.proto.UserBitShared.QueryResult;
import org.apache.drill.exec.proto.UserProtos.BitToUserHandshake;
import org.apache.drill.exec.proto.UserProtos.HandshakeStatus;
import org.apache.drill.exec.proto.UserProtos.RpcType;
import org.apache.drill.exec.proto.UserProtos.RunQuery;
import org.apache.drill.exec.proto.UserProtos.UserProperties;
import org.apache.drill.exec.proto.UserProtos.UserToBitHandshake;
import org.apache.drill.exec.rpc.Acks;
import org.apache.drill.exec.rpc.BasicClientWithConnection;
import org.apache.drill.exec.rpc.OutOfMemoryHandler;
import org.apache.drill.exec.rpc.ProtobufLengthDecoder;
import org.apache.drill.exec.rpc.Response;
import org.apache.drill.exec.rpc.RpcConnectionHandler;
import org.apache.drill.exec.rpc.RpcException;

import com.google.protobuf.MessageLite;

public class UserClient extends BasicClientWithConnection<RpcType, UserToBitHandshake, BitToUserHandshake> {
  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UserClient.class);

  private final QueryResultHandler queryResultHandler = new QueryResultHandler();

  private boolean supportComplexTypes = true;

  public UserClient(DrillConfig config, boolean supportComplexTypes, BufferAllocator alloc,
      EventLoopGroup eventLoopGroup) {
    super(
        UserRpcConfig.getMapping(config),
        alloc,
        eventLoopGroup,
        RpcType.HANDSHAKE,
        BitToUserHandshake.class,
        BitToUserHandshake.PARSER,
        "user client");
    this.supportComplexTypes = supportComplexTypes;
  }

  public void submitQuery(UserResultsListener resultsListener, RunQuery query) {
    send(queryResultHandler.getWrappedListener(connection, resultsListener), RpcType.RUN_QUERY, query, QueryId.class);
  }

  public void connect(RpcConnectionHandler<ServerConnection> handler, DrillbitEndpoint endpoint, UserProperties props, UserBitShared.UserCredentials credentials)
      throws RpcException {
    UserToBitHandshake.Builder hsBuilder = UserToBitHandshake.newBuilder()
        .setRpcVersion(UserRpcConfig.RPC_VERSION)
        .setSupportListening(true)
        .setSupportComplexTypes(supportComplexTypes)
        .setSupportTimeout(true)
        .setCredentials(credentials);

    if (props != null) {
      hsBuilder.setProperties(props);
    }

    this.connectAsClient(handler, hsBuilder.build(), endpoint.getAddress(), endpoint.getUserPort());
  }

  @Override
  protected MessageLite getResponseDefaultInstance(int rpcType) throws RpcException {
    switch (rpcType) {
    case RpcType.ACK_VALUE:
      return Ack.getDefaultInstance();
    case RpcType.HANDSHAKE_VALUE:
      return BitToUserHandshake.getDefaultInstance();
    case RpcType.QUERY_HANDLE_VALUE:
      return QueryId.getDefaultInstance();
      case RpcType.QUERY_RESULT_VALUE:
        return QueryResult.getDefaultInstance();
    case RpcType.QUERY_DATA_VALUE:
      return QueryData.getDefaultInstance();
    }
    throw new RpcException(String.format("Unable to deal with RpcType of %d", rpcType));
  }

  @Override
  protected Response handleReponse(ConnectionThrottle throttle, int rpcType, ByteBuf pBody, ByteBuf dBody) throws RpcException {
    switch (rpcType) {
    case RpcType.QUERY_DATA_VALUE:
      queryResultHandler.batchArrived(throttle, pBody, dBody);
      return new Response(RpcType.ACK, Acks.OK);
    case RpcType.QUERY_RESULT_VALUE:
      queryResultHandler.resultArrived(pBody);
      return new Response(RpcType.ACK, Acks.OK);
    default:
      throw new RpcException(String.format("Unknown Rpc Type %d. ", rpcType));
    }

  }

  @Override
  protected void validateHandshake(BitToUserHandshake inbound) throws RpcException {
//    logger.debug("Handling handshake from bit to user. {}", inbound);
    if (inbound.getStatus() != HandshakeStatus.SUCCESS) {
      final String errMsg = String.format("Status: %s, Error Id: %s, Error message: %s",
          inbound.getStatus(), inbound.getErrorId(), inbound.getErrorMessage());
      logger.error(errMsg);
      throw new RpcException(errMsg);
    }
  }

  @Override
  protected void finalizeConnection(BitToUserHandshake handshake, BasicClientWithConnection.ServerConnection connection) {
  }

  @Override
  public ProtobufLengthDecoder getDecoder(BufferAllocator allocator) {
    return new UserProtobufLengthDecoder(allocator, OutOfMemoryHandler.DEFAULT_INSTANCE);
  }

}


text:
<?php

declare(strict_types=1);

/*
 * This file is part of PHP CS Fixer.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace PhpCsFixer\ConfigurationException;

/**
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
 *
 * @internal
 */
final class InvalidForEnvFixerConfigurationException extends InvalidFixerConfigurationException
{
}


text:
package com.epimorphics.registry.security;

import static com.epimorphics.registry.security.RegAction.Grant;
import static com.epimorphics.registry.security.RegAction.Register;
import static com.epimorphics.registry.security.RegAction.StatusUpdate;
import static com.epimorphics.registry.security.RegAction.Update;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.shiro.authz.Permission;

import com.epimorphics.util.EpiException;

/**
 * Represents registry permission structure. The basic string form is:
 *

 *   action:/path
 *

 * Where the action can be a comma separated list of actions and the
 * path is register or register item relative to the root of the registry.
 * Permissions inherit down the path structure so that some granted:
 *

 *   update:/def/reg
 *

 * is also implicitly granted:
 *

 *   update:/def/reg/sub
 *

 *

 * The set of actions is constrained to match a {@link RegAction}.
 *

 * @author Dave Reynolds
 */
public class RegPermission implements Permission {

    protected Set<RegAction> actions;
    protected String path = "";
    protected String impliedPath;

    protected static Map<String, RegAction[]> roleAliases = new HashMap<String, RegAction[]>();
    static {
        roleAliases.put("Manager", new RegAction[]{Register, Update, StatusUpdate, Grant});
        roleAliases.put("Maintainer", new RegAction[]{Update, Grant});
        roleAliases.put("Authorized", new RegAction[]{Register, Update, StatusUpdate});
    }

    public RegPermission(String permission) {
        int split = permission.indexOf(':');
        if (split != -1) {
            actions = parseActions( permission.substring(0, split) );
            path = permission.substring(split+1).trim();
            checkImpliedPath();
        } else {
            actions = parseActions(permission);
        }
    }

    public RegPermission(String actions, String path) {
        this(parseActions(actions), path);
    }

    public RegPermission(RegAction action, String path) {
        this(singleAction(action), path);
    }

    public RegPermission(Set<RegAction> actions, String path) {
        this.actions = actions;
        this.path = path.trim();
        checkImpliedPath();
    }

    private void checkImpliedPath() {
        if (path.contains("/_")) {
            impliedPath = path.replace("/_", "/");
        }
    }

    private static Set<RegAction> singleAction(RegAction action) {
        Set<RegAction> actions = new HashSet<RegAction>(1);
        actions.add(action);
        return actions;
    }

    private static Set<RegAction> parseActions(String actionsStr) {
        if (actionsStr.trim().equals("*")) {
            return singleAction(RegAction.WildCard);
        }
        Set<RegAction> actions = new HashSet<RegAction>(5);
        for (String actionStr : actionsStr.split(",")) {
            if (roleAliases.containsKey(actionStr)) {
                for (RegAction action : roleAliases.get(actionStr)) {
                    actions.add(action);
                }
            } else {
                RegAction action = RegAction.forString(actionStr.trim());
                if (action != null) {
                    actions.add(action);
                } else {
                    throw new EpiException("Illegal action in permissions string: " + actionStr);
                }
            }
        }
        return actions;
    }

    public Set<RegAction> getActions() {
        return actions;
    }

    public void setActions(Set<RegAction> actions) {
        this.actions = actions;
    }

    public void addAction(RegAction action) {
        this.actions.add(action);
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
        checkImpliedPath();
    }

    protected String getImpliedPath() {
        return impliedPath;
    }

    /**
     * Returns the part of p which is not covered by this permission.
     * If there is no match then this is simply p itself.
     * If p is fully granted then returns null.
     * Otherwise returns a new target permission that has the same path
     * but a reduced set of actions
     */
    public RegPermission residual(RegPermission p) {
        if ( ! pathCovered(p) ) return p;

        if (actions.contains(RegAction.WildCard) || actions.containsAll(p.actions)) {
            return null;
        }

        Set<RegAction> residualActions = new HashSet<RegAction>( p.actions );
        residualActions.removeAll(actions);
        return new RegPermission(residualActions, p.path);
    }

    @Override
    public boolean implies(Permission p) {
        if ( ! (p instanceof RegPermission) ) return false;
        RegPermission other = (RegPermission)p;

        if (actions.contains(RegAction.WildCard) || actions.containsAll(other.actions)) {
            if (pathCovered(other)) {
                return true;
            }
        }
        return false;
    }

    private boolean pathCovered(RegPermission p) {
        if  (p.path.startsWith(path)) {
            return true;
        } else {
            if (impliedPath != null && p.path.startsWith(impliedPath)) {
                return true;
            }
        }
        return false;
    }

    public String getActionString() {
        StringBuffer buff = new StringBuffer();
        boolean started = false;
        for (RegAction action : actions) {
            if (started) {
                buff.append(",");
            } else {
                started = true;
            }
            buff.append(action.name());
        }
        return buff.toString();
    }

    @Override
    public String toString() {
        return getActionString() + ":" + path;
    }
}


text:
require 'sprockets_test'
require 'shellwords'
require 'tmpdir'

class TestSprockets < Sprockets::TestCase
  parallelize_me!

  def setup
    super
    @env = Sprockets::Environment.new(".") do |env|
      env.append_path(fixture_path('default'))
    end

    @dir = Dir.mktmpdir("sprockets")
  end

  def teardown
    FileUtils.rm_rf @dir
    super
  end

  test "show version for -v flag" do
    output = sprockets "-v"
    assert_equal "#{Sprockets::VERSION}\n", output
  end

  test "show help for -h flag" do
    output = sprockets "-h"
    assert_match "Usage: sprockets", output
  end

  test "show help for no flags or inputs" do
    output = sprockets
    assert_match "Usage: sprockets", output
  end

  test "error if load path is missing" do
    sprockets fixture_path("default/gallery.js")
    assert_equal 1, $?.exitstatus
  end

  test "compile simple file" do
    output = sprockets "-I", fixture_path("default"), fixture_path("default/gallery.js")
    assert_equal "var Gallery = {};\n", output
  end

  test "show error if multiple files are given" do
    sprockets fixture_path("default/gallery.js"), fixture_path("default/application.js")
    assert_equal 1, $?.exitstatus
  end

  test "compile file with dependencies" do
    output = sprockets "-I", fixture_path("asset"), fixture_path("asset/application.js")
    assert_equal "var Project = {\n  find: function(id) {\n  }\n};\nvar Users = {\n  find: function(id) {\n  }\n};\n\n\n\ndocument.on('dom:loaded', function() {\n  $('search').focus();\n});\n", output
  end

  test "compile asset to output directory" do
    digest_path = @env['gallery.js'].digest_path
    output = sprockets "-I", fixture_path("default"), "-o", @dir, fixture_path("default/gallery.js")
    assert_equal "", output
    assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
    assert File.exist?("#{@dir}/#{digest_path}")
  end

  test "compile multiple assets to output directory" do
    digest_path1, digest_path2 = @env['gallery.js'].digest_path, @env['gallery.css'].digest_path
    output = sprockets "-I", fixture_path("default"), "-o", @dir, fixture_path("default/gallery.js"), fixture_path("default/gallery.css.erb")
    assert_equal "", output
    assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
    assert File.exist?("#{@dir}/#{digest_path1}")
    assert File.exist?("#{@dir}/#{digest_path2}")
  end

  test "minify js with uglify" do
    output = sprockets "-I", fixture_path("default"), "--js-compressor", "uglify", fixture_path("default/gallery.js")
    assert_equal "var Gallery={};\n", output
  end

  test "compress css with sass" do
    output = sprockets "-I", fixture_path("default"), "--css-compressor", "sass", fixture_path("default/gallery.css.erb")
    assert_equal ".gallery{color:red}\n", output
  end

  def sprockets(*args)
    script = File.expand_path("../../bin/sprockets", __FILE__)
    lib    = File.expand_path("../../lib", __FILE__)
    `ruby -I#{lib} #{script} #{Shellwords.join(args)} 2>&1`
  end
end


text:
(function (window, undefined) {

    var Certamb = function (config) {
        if (!(this instanceof Certamb)) {
            return new Certamb(config);
        }

        var sc = this;
        var adapter;

        sc.init = function (initOptions) {

            if (window.Cordova) {
                adapter = loadAdapter('cordova');
            } else {
                adapter = loadAdapter();
            }

            var promise = createPromise();

            var initPromise = createPromise();
            initPromise.promise.success(function () {
                promise.setSuccess();
            }).error(function () {
                promise.setError();
            });

            var configPromise = loadConfig(config);

            function onLoad() {
                var doLogin = function (prompt) {
                    if (!prompt) {
                        options.prompt = 'none';
                    }
                    sc.login(options).success(function () {
                        initPromise.setSuccess();
                    }).error(function () {
                        initPromise.setError();
                    });
                };

                var options = {};
                switch (initOptions.onLoad) {
                    case 'login-required':
                        doLogin(true);
                        break;
                    default:
                        throw 'Invalid value for onLoad';
                }
            }

            configPromise.success(onLoad);
            configPromise.error(function () {
                promise.setError();
            });

            return promise.promise;
        };

        sc.login = function (options) {
            return adapter.login(options);
        };

        sc.loadTrabajador = function() {
            var url = getServerUrl() + '/session/account/trabajador';
            var req = new XMLHttpRequest();
            req.open('GET', url, true);
            req.setRequestHeader('Accept', 'application/json');
            req.setRequestHeader('Authorization', 'bearer ' + sc.authenticatedToken);

            var promise = createPromise();

            req.onreadystatechange = function () {
                if (req.readyState == 4) {
                    if (req.status == 200) {
                        sc.trabajador = JSON.parse(req.responseText);
                        sc.trabajadorLoaded = true;
                        promise.setSuccess(sc.trabajador);
                    } else if (req.status == 204) {
                        sc.trabajador = undefined;
                        sc.trabajadorLoaded = true;
                        promise.setSuccess(sc.trabajador);
                    } else {
                        promise.setError();
                    }
                }
            };

            req.send();

            return promise.promise;
        };

        sc.loadDireccionRegional = function() {
            var url = getServerUrl() + '/session/account/direccionRegional';
            var req = new XMLHttpRequest();
            req.open('GET', url, true);
            req.setRequestHeader('Accept', 'application/json');
            req.setRequestHeader('Authorization', 'bearer ' + sc.authenticatedToken);

            var promise = createPromise();

            req.onreadystatechange = function () {
                if (req.readyState == 4) {
                    if (req.status == 200) {
                        sc.direccionRegional = JSON.parse(req.responseText);
                        sc.direccionRegionalLoaded = true;
                        promise.setSuccess(sc.direccionRegional);
                    } else if (req.status == 204) {
                        sc.direccionRegional = undefined;
                        sc.direccionRegionalLoaded = true;
                        promise.setSuccess(sc.direccionRegional);
                    } else {
                        promise.setError();
                    }
                }
            };

            req.send();

            return promise.promise;
        };

        function getServerUrl() {
            return sc.authServerUrl;
        }

        function getAuthenticatedToken() {
            return sc.authenticatedToken;
        }

        function loadConfig(url) {
            var promise = createPromise();
            var configUrl;

            if (!config) {
                configUrl = 'certamb.json';
            } else if (typeof config === 'string') {
                configUrl = config;
            }

            if (configUrl) {
                var req = new XMLHttpRequest();
                req.open('GET', configUrl, true);
                req.setRequestHeader('Accept', 'application/json');

                req.onreadystatechange = function () {
                    if (req.readyState == 4) {
                        if (req.status == 200) {
                            var config = JSON.parse(req.responseText);

                            sc.authServerUrl = config['auth-server-url'];
                            sc.authenticatedToken = config['authenticatedToken'];

                            promise.setSuccess();
                        } else {
                            promise.setError();
                        }
                    }
                };

                req.send();
            } else {
                if (!config['url']) {
                    var scripts = document.getElementsByTagName('script');
                    for (var i = 0; i < scripts.length; i++) {
                        if (scripts[i].src.match(/.*certamb\.js/)) {
                            config.url = scripts[i].src.substr(0, scripts[i].src.indexOf('/js/certamb.js'));
                            break;
                        }
                    }
                }

                if (!config.authenticatedToken) {
                    throw 'authenticatedToken missing';
                }

                sc.authServerUrl = config.url;
                sc.authenticatedToken = config.authenticatedToken;

                promise.setSuccess();
            }

            return promise.promise;
        }

        function createPromise() {
            var p = {
                setSuccess: function (result) {
                    p.success = true;
                    p.result = result;
                    if (p.successCallback) {
                        p.successCallback(result);
                    }
                },

                setError: function (result) {
                    p.error = true;
                    p.result = result;
                    if (p.errorCallback) {
                        p.errorCallback(result);
                    }
                },

                promise: {
                    success: function (callback) {
                        if (p.success) {
                            callback(p.result);
                        } else if (!p.error) {
                            p.successCallback = callback;
                        }
                        return p.promise;
                    },
                    error: function (callback) {
                        if (p.error) {
                            callback(p.result);
                        } else if (!p.success) {
                            p.errorCallback = callback;
                        }
                        return p.promise;
                    }
                }
            };
            return p;
        }

        function loadAdapter(type) {
            if (!type || type == 'default') {
                return {
                    login: function (options) {
                        var promise = createPromise();

                        //load Direccion regional
                        sc.loadDireccionRegional().success(function () {
                            if(sc.trabajadorLoaded && sc.direccionRegionalLoaded) {
                                promise.setSuccess();
                            }
                        }).error(function () {
                            promise.setError();
                        });

                        //load Trabajador
                        sc.loadTrabajador().success(function () {
                            if(sc.trabajadorLoaded && sc.direccionRegionalLoaded) {
                                promise.setSuccess();
                            }
                        }).error(function () {
                            promise.setError();
                        });

                        return promise.promise;
                    }
                };
            }

            throw 'invalid adapter type: ' + type;
        }
    };

    if (typeof module === "object" && module && typeof module.exports === "object") {
        module.exports = Certamb;
    } else {
        window.Certamb = Certamb;

        if (typeof define === "function" && define.amd) {
            define("certamb", [], function () {
                return Certamb;
            });
        }
    }
})(window);


text:
package net.winterly.dropwizard.hk2bundle;

import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

public class ExampleAppConfiguration extends Configuration {

    @Valid
    @NotNull
    public DataSourceFactory database;
}


text:
package org.gradle.internal.featurelifecycle;

import com.google.common.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.List;

/**
 * An immutable description of the usage of a deprecated feature.
 */
public abstract class FeatureUsage {

    private final String summary;
    private final Class<?> calledFrom;
    private final Exception traceException;

    private List<StackTraceElement> stack;

    protected FeatureUsage(String summary, Class<?> calledFrom) {
        this(summary, calledFrom, new Exception());
    }

    @VisibleForTesting
    protected FeatureUsage(String summary, Class<?> calledFrom, Exception traceException) {
        this.summary = summary;
        this.calledFrom = calledFrom;
        this.traceException = traceException;
    }

    /**
     * A concise sentence summarising the usage.
     *
     * Example: Method Foo.bar() has been deprecated.
     */
    public String getSummary() {
        return summary;
    }

    protected Class<?> getCalledFrom() {
        return calledFrom;
    }

    public List<StackTraceElement> getStack() {
        if (stack == null) {
            stack = calculateStack(calledFrom, traceException);
        }
        return stack;
    }

    private static List<StackTraceElement> calculateStack(Class<?> calledFrom, Exception traceRoot) {
        StackTraceElement[] originalStack = traceRoot.getStackTrace();
        List<StackTraceElement> result = new ArrayList<StackTraceElement>();
        final String calledFromName = calledFrom.getName();
        boolean calledFromFound = false;
        int caller;
        for (caller = 0; caller < originalStack.length; caller++) {
            StackTraceElement current = originalStack[caller];
            if (!calledFromFound) {
                if (current.getClassName().startsWith(calledFromName)) {
                    calledFromFound = true;
                }
            } else {
                if (!current.getClassName().startsWith(calledFromName)) {
                    break;
                }
            }
        }
        for (; caller < originalStack.length; caller++) {
            StackTraceElement stackTraceElement = originalStack[caller];
            if (!isSystemStackFrame(stackTraceElement.getClassName())) {
                result.add(stackTraceElement);
            }
        }
        return result;
    }

    private static boolean isSystemStackFrame(String className) {
        return className.startsWith("jdk.internal.") ||
            className.startsWith("sun.") ||
            className.startsWith("com.sun.") ||
            className.startsWith("org.codehaus.groovy.") ||
            className.startsWith("org.gradle.internal.metaobject.") ||
            className.startsWith("org.gradle.kotlin.dsl.execution.");
    }

    public String formattedMessage() {
        return summary;
    }

}


text:
package org.ingrahamrobotics.robot2013.dashboardrelations;

import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.ingrahamrobotics.robot2013.DisableNotifable;
import org.ingrahamrobotics.robot2013.RobotMain;

/**
 *
 */
public final class BooleanDashObject implements DisableNotifable {

    private final SendableChooser sendable;
    private final String name;

    public BooleanDashObject(String name, String trueName, String falseName, boolean defaultValue) {
        this.name = name;
        sendable = new SendableChooser();
        sendable.addDefault(defaultValue ? trueName : falseName, Boolean.valueOf(defaultValue));
        sendable.addObject(defaultValue ? falseName : trueName, Boolean.valueOf(!defaultValue));
        SmartDashboard.putData(name, sendable);
        RobotMain.addDisableNotifable(this);
    }

    public boolean getValue() {
        if (!(sendable.getSelected() instanceof Boolean)) {
            return false;
        }
        boolean value = ((Boolean) sendable.getSelected()).booleanValue();
        return value;
    }

    public void disable() {
        SmartDashboard.putData(name, sendable);
    }
}


text:
#ifndef UNISPARKS_EFFECTS_RIDER_H
#define UNISPARKS_EFFECTS_RIDER_H
#include "unisparks/effects/functional.hpp"
#include "unisparks/util/math.hpp"

namespace unisparks {

constexpr auto rider = []() {
  return effect([](const Frame & frame) {
    Milliseconds riderPeriod = adjustDuration(frame, 2000);
    Milliseconds huePeriod = adjustDuration(frame, 8000);

    int width = frame.size.width;
    uint8_t cycleHue = 256 * frame.time / huePeriod;
    uint8_t riderPos = 256 * frame.time / riderPeriod;

    return [ = ](Point p) -> Color {
      using namespace internal;

      // this is the same for all values of y, so we can potentially optimize
      HslColor riderColor;
      int brightness =
      absi(p.x * (256 / (width % 256)) - triwave8(riderPos) * 2 + 127) * 3;
      if (brightness > 255) {
        brightness = 255;
      }
      brightness = 255 - brightness;
      riderColor = HslColor(cycleHue, 255, brightness);
      return riderColor;
    };
  });
};

} // namespace unisparks
#endif /* UNISPARKS_EFFECTS_RIDER_H */


text:
namespace MoM.Module.Dtos
{
    public class SiteSettingAuthenticationGoogleDto
    {
        public string clientId { get; set; }
        public string clientSecret { get; set; }
        public bool enabled { get; set; }
    }
}


text:
require 'fileutils'
module HealthDataStandards
  module Import
    class BulkRecordImporter

      def self.import_directory(source_dir, failed_dir=nil)
        failed_dir ||= File.join(source_dir, '../', 'failed_imports')
        files = Dir.glob(File.join(source_dir, '*.*'))
        files.each do |file|
          self.import_file(file,File.new(file).read,failed_dir)
        end
      end

      def self.import_archive(file, failed_dir=nil)
        begin
        failed_dir ||=File.join(File.dirname(file))

        patient_id_list = nil

        Zip::ZipFile.open(file.path) do |zipfile|
          zipfile.entries.each do |entry|
            if entry.name
              if entry.name.split("/").last == "patient_manifest.txt"
                patient_id_list = zipfile.read(entry.name)
                next
              end
            end
            next if entry.directory?
            data = zipfile.read(entry.name)
            self.import_file(entry.name,data,failed_dir)
          end
        end

        missing_patients = []

        #if there was a patient manifest, theres a patient id list we need to load
        if patient_id_list
          patient_id_list.split("\n").each do |id|
            patient = Record.where(:medical_record_number => id).first
            if patient == nil
              missing_patients << id
            end
          end
        end

        missing_patients

      rescue
        FileUtils.mkdir_p(failed_dir)
        FileUtils.cp(file,File.join(failed_dir,File.basename(file)))
        File.open(File.join(failed_dir,"#{file}.error")) do |f|
          f.puts($!.message)
          f.puts($!.backtrace)
        end
        raise $!
      end
      end

      def self.import_file(name,data,failed_dir,provider_map={})
        begin
          ext = File.extname(name)
          if ext == ".json"
            self.import_json(data)
          else
            self.import(data)
          end
        rescue
          FileUtils.mkdir_p(File.dirname(File.join(failed_dir,name)))
          File.open(File.join(failed_dir,name),"w") do |f|
            f.puts(data)
          end
          File.open(File.join(failed_dir,"#{name}.error"),"w") do |f|
            f.puts($!.message)
            f.puts($!.backtrace)
          end
        end
      end

      def self.import_json(data,provider_map = {})
        json = JSON.parse(data,:max_nesting=>100)
        record = Record.update_or_create(Record.new(json))
        providers = record.provider_performances
        providers.each do |prov|
          prov.provider.ancestors.each do |ancestor|
            record.provider_performances.push(ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
          end
        end
        record.save!
      end

      def self.import(xml_data, provider_map = {}, doc = Nokogiri::XML(xml_data))
        providers = []
        root_element_name = doc.root.name

        if root_element_name == 'ClinicalDocument'
          doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
          doc.root.add_namespace_definition('sdtc', 'urn:hl7-org:sdtc')

          if doc.at_xpath("/cda:ClinicalDocument/cda:templateId[@root='2.16.840.1.113883.3.88.11.32.1']")
            patient_data = C32::PatientImporter.instance.parse_c32(doc)
          elsif doc.at_xpath("/cda:ClinicalDocument/cda:templateId[@root='2.16.840.1.113883.10.20.22.1.2']")
            patient_data = CCDA::PatientImporter.instance.parse_ccda(doc)
          elsif doc.at_xpath("/cda:ClinicalDocument/cda:templateId[@root='2.16.840.1.113883.10.20.24.1.2']")
            patient_data = Cat1::PatientImporter.instance.parse_cat1(doc)
          else
            STDERR.puts("Unable to determinate document template/type of CDA document")
            return {status: 'error', message: "Document templateId does not identify it as a C32 or CCDA", status_code: 400}
          end

          record = Record.update_or_create(patient_data)

          begin
            providers = CDA::ProviderImporter.instance.extract_providers(doc, record)
          rescue Exception => e
            STDERR.puts "error extracting providers"
          end
        else
          return {status: 'error', message: 'Unknown XML Format', status_code: 400}
        end

        record.provider_performances = providers
        providers.each do |prov|
          prov.provider.ancestors.each do |ancestor|
            record.provider_performances.push(ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
          end
        end
        record.save

      end
    end
  end
end