text:
#include <cmath>
#include <cstring>
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <boost/format.hpp>
#include "../common/util.hpp"

using namespace std;
using namespace boost;

int main(int argc, char* argv[]) {
	if (argc < 2) {
		cout << format("Usage: %1% <star>") % argv[0]<< endl;
		return EXIT_FAILURE;
	}

	const int star = atoi(argv[1]);

	if (!glfwInit()) {
		throw runtime_error("Failed to initialize GLFW");
	}

	glfwWindowHint(GLFW_SAMPLES, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	GLFWwindow* window = glfwCreateWindow(600, 600, "Hexagram", NULL, NULL);
	if (!window) {
		throw runtime_error("Failed to open GLFW window");
	}
	glfwMakeContextCurrent(window);
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

	glewExperimental = GL_TRUE;
	if (glewInit() != GLEW_OK) {
		throw runtime_error("Failed to initialize GLEW");
	}

	GLuint programID = buildProgram("vertex.shader", "fragment.shader");
	glUseProgram(programID);
	glClearColor(25 / 255.0f, 25 / 255.0, 25 / 255.0, 0.0f);

	GLuint vertexArrayID;
	glGenVertexArrays(1, &vertexArrayID);
	glBindVertexArray(vertexArrayID);

	GLfloat vertexData[star * 12];

	// center vertex
	GLfloat centerVertex[2];
	centerVertex[0] = 0;
	centerVertex[1] = 0;

	for (int i = 0; i < star; i++) {
		vertexData[12 * i] = cos(2 * i * M_PI / star) / 2;
		vertexData[12 * i + 1] = sin(2 * i * M_PI / star) / 2;

		vertexData[12 * i + 2] = cos(2 * (i + 1) * M_PI / star) / 2;
		vertexData[12 * i + 3] = sin(2 * (i + 1) * M_PI / star) / 2;

		memcpy(vertexData + (12 * i + 4), centerVertex, sizeof(GLfloat) * 2);
		memcpy(vertexData + (12 * i + 6), vertexData + (12 * i), sizeof(GLfloat) * 4);

		vertexData[12 * i + 10] = cos((2 * i + 1) * M_PI / star);
		vertexData[12 * i + 11] = sin((2 * i + 1) * M_PI / star);
	}

	GLfloat colorData[star * 18];

	// center color
	GLfloat centerColor[3];
	centerColor[0] = float(rand()) / RAND_MAX;
	centerColor[1] = float(rand()) / RAND_MAX;
	centerColor[2] = float(rand()) / RAND_MAX;

	/*
	 * if: most case first
	 *
	 * first star => generate 3 random color
	 * other star => generate 2 random color, copy 1 color
	 * last  star => generate 1 random color, copy 2 color
	 *
	 */
	for (int i = 0; i < star; i++) {
		if (i != 0) {
			memcpy(colorData + (18 * i), colorData + (18 * i - 6), sizeof(GLfloat) * 3);
		} else {
			colorData[0] = float(rand()) / RAND_MAX;
			colorData[1] = float(rand()) / RAND_MAX;
			colorData[2] = float(rand()) / RAND_MAX;
		}

		if (i != (star - 1)) {
			colorData[18 * i + 3] = float(rand()) / RAND_MAX;
			colorData[18 * i + 4] = float(rand()) / RAND_MAX;
			colorData[18 * i + 5] = float(rand()) / RAND_MAX;
		} else {
			memcpy(colorData + (18 * i + 3), colorData, sizeof(GLfloat) * 3);
		}

		memcpy(colorData + (18 * i + 6), centerColor, sizeof(centerColor));
		memcpy(colorData + (18 * i + 9), colorData + (18 * i), sizeof(GLfloat) * 6);

		colorData[18 * i + 15] = float(rand()) / RAND_MAX;
		colorData[18 * i + 16] = float(rand()) / RAND_MAX;
		colorData[18 * i + 17] = float(rand()) / RAND_MAX;
	}

	GLuint vertexBuffer;
	glGenBuffers(1, &vertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
	glEnableVertexAttribArray(0);

	GLuint colorBuffer;
	glGenBuffers(1, &colorBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(colorData), colorData, GL_STATIC_DRAW);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
	glEnableVertexAttribArray(1);

	do {
		glClear(GL_COLOR_BUFFER_BIT);
		glDrawArrays(GL_TRIANGLES, 0, star * 12);
		glfwSwapBuffers(window);
		glfwPollEvents();
	} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);

	return EXIT_SUCCESS;
}


text:
module Be
  # Map assertion methods to the Errors that they should raise.
  #
  # In the future there is good chance this will depend on the Assay
  # library instead of defining our own error classes here. However
  # we'll wait until that library matures further before making that
  # leap.
  #
  ASSERTION_ERRORS = {}
end

class Exception
  #
  def self.be(name)
    Be::ASSERTION_ERRORS[name.to_sym] = self
  end
end

class TypeError
  be :instance_of?
  be :kind_of?
end

class EqualityError < StandardError
  be :==
  be :eql?
  be :equal?
end

redpajama_set_name: RedPajamaGithub


text:
package com.drisoftie.frags.comp;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.drisoftie.frags.DialogResultState;
import com.drisoftie.frags.IDialogChoice;
import com.drisoftie.frags.R;
import com.drisoftie.frags.handler.IResultHandler;

/**
 * A special {@link DialogFragment} that supports callback mechanisms to get a result.
 *
 * @author Alexander Dridiger
 */
public abstract class BaseDiagResult<ResultT> extends DialogFragment implements IDialogChoice<ResultT> {

    private IResultHandler<ResultT> resultListener;

    private DialogResultState state = DialogResultState.IN_PROGRESS;

    @Override
    public void setBundle(Bundle bundle) {
        setArguments(bundle);
    }

    @Override
    public IResultHandler<ResultT> getResultListener() {
        return resultListener;
    }

    @Override
    public void setResultHandler(IResultHandler<ResultT> resultListener) {
        this.resultListener = resultListener;
    }

    @Override
    public DialogResultState getResultState() {
        return state;
    }

    @Override
    public void setResultState(DialogResultState state) {
        this.state = state;
    }

    @Override
    public Dialog onCreateDialog(@NonNull Bundle savedInstanceState) {
        AlertDialog.Builder builder  = new AlertDialog.Builder(getActivity());
        LayoutInflater      inflater = getActivity().getLayoutInflater();
        View                v        = inflater.inflate(getArguments().getInt(getString(R.string.bundl_diag_layout)), null);
        createDialogComponents(v);
        builder.setView(v);
        if (getArguments().containsKey(getString(R.string.bundl_diag_title))) {
            Object arg = getArguments().get(getString(R.string.bundl_diag_title));
            if (arg instanceof String) {
                builder.setTitle(getArguments().getString(getString(R.string.bundl_diag_title)));
            } else if (arg instanceof Integer) {
                builder.setTitle(getArguments().getInt(getString(R.string.bundl_diag_title)));
            }
        }
        if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
            builder.setPositiveButton(getArguments().getInt(getString(R.string.bundl_diag_btn_positive)),
                                      new DialogInterface.OnClickListener() {
                                          @Override
                                          public void onClick(DialogInterface dialog, int id) {
                                          }
                                      });
        }
        if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
            builder.setNegativeButton(getArguments().getInt(getString(R.string.bundl_diag_btn_negative)),
                                      new DialogInterface.OnClickListener() {
                                          @Override
                                          public void onClick(DialogInterface dialog, int id) {
                                          }
                                      });
        }
        AlertDialog diag = builder.create();
        diag.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return diag;
    }

    @Override
    public void onStart() {
        super.onStart();

        AlertDialog diag = (AlertDialog) getDialog();

        if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
            diag.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setResultState(DialogResultState.POSITIVE);
                    buttonPositivePressed();
                }
            });
        }
        if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
            diag.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setResultState(DialogResultState.NEGATIVE);
                    buttonNegativePressed();
                }
            });
        }
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (DialogResultState.IN_PROGRESS.equals(getResultState())) {
            setResultState(DialogResultState.CANCELED);
        }
        if (isVisible()) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
        dismissDialog(dialog);
    }
}


text:
class j1Window;
class j1Input;
class j1Render;
class j1Textures;
class j1Audio;
class j1MainMenu;
class j1Scene;
class j1Map;
class j1Gui;
class j1Fonts;
//class Player;
//class EnemyNormal;
//class EnemyFly;
class ManagerCriatures;
class ParticleManager;
class j1FadeToBlack;
class ModuleCollision;

class j1App
{
public:

	// Constructor
	j1App(int argc, char* args[]);

	// Destructor
	virtual ~j1App();

	// Called before render is available
	bool Awake();

	// Called before the first frame
	bool Start();

	// Called each loop iteration
	bool Update();

	// Called before quitting
	bool CleanUp();

	// Add a new module to handle
	void AddModule(j1Module* module);

	// Exposing some properties for reading
	int GetArgc() const;
	const char* GetArgv(int index) const;
	const char* GetTitle() const;
	const char* GetOrganization() const;

	// DT
	float GetDT()
	{
		return dt;
	}

	//Call to load and save function
	void Load();
	void Save() const;

private:

	// Load config file
	bool LoadConfig();

	// Call modules before each loop iteration
	void PrepareUpdate();

	// Call modules before each loop iteration
	void FinishUpdate();

	// Call modules before each loop iteration
	bool PreUpdate();

	// Call modules on each loop iteration
	bool DoUpdate();

	// Call modules after each loop iteration
	bool PostUpdate();

	//Load and save functions on XML
	bool  DocLoad();
	bool  DocSave() const;

public:

	// Modules
	j1Window*			win;
	j1Input*			input;
	j1Render*			render;
	j1Textures*			tex;
	j1Audio*			audio;
	j1Map*              map;
	j1Gui*				gui;
	j1Fonts*			font;
	j1MainMenu*			mainmenu;
	j1Scene*			scene;
	ManagerCriatures*	managerC;
	//Player*				player;
	//EnemyNormal*		enemy_normal;
	//EnemyFly*			enemy_fly;
	ParticleManager*    particles;
	j1FadeToBlack*		fade;
	ModuleCollision*	collision;

	uint64				frame_count = 0;
	j1TimeNormal		startup_time;
	j1TimeNormal		frame_time;
	j1TimeNormal	    last_sec_frame_time;
	uint32				last_sec_frame_count = 0;
	uint32				prev_last_sec_frame_count = 0;
	//float				dt = 0.0f;
	int					capped_ms = -1;

private:

	p2List<j1Module*>	modules;
	uint				frames;
	float				dt;
	pugi::xml_document	config_file;
	pugi::xml_node		config;
	pugi::xml_node		app_config;
	int					argc;
	char**				args;

	p2SString			title;
	p2SString			organization;

	mutable bool        need_save = false;
	bool                need_load = false;

};

extern j1App* App;

#endif


text:
<?php

/**
 * 产品分类
 */
class ProjectCategory extends FrontendController
{
    public function index() {
        $categories = (new CategoryModel())->getAllCategories();
        $this->view('projectCategory/index', array('categories' => $categories));
    }
}


text:
#pragma once

#include <string>
#include <vector>
#include <map>

class HttpStream
{
	std::vector<uint8_t> m_buff;
	int m_socket = -1;
	std::map<std::string, std::string> m_response;
	size_t			m_data_start;

#ifdef _WIN32
	void far * m_hSession;
	void far * m_hConnect;
	void far * m_hRequest;
#endif

	void * m_ssl = nullptr;
	int parser_response(std::string rep);
public:
	HttpStream();
	int HttpGetHeader(std::string host, std::string path, int port = 80, bool ishttps=false);
	size_t HttpGetFileSize();
	int HttpDownload(char *buff, size_t sz);
	~HttpStream();

private:
	int RecvPacket(char *buff, size_t sz);
	int SendPacket(char *buff, size_t sz);
};


text:
"""
test_readycloud
----------------------------------

Tests for `readycloud.readycloud` module.
"""

import json
import unittest

from mock import patch, Mock

from readycloud import ReadyCloud
from readycloud.exceptions import ReadyCloudServerError

class ReadyCloudTestCase(unittest.TestCase):
    def setUp(self):
        self.rc = ReadyCloud(token='12345', host='https://readycloud.com/', api=ReadyCloud.API_V1)
        self.rc_v2 = ReadyCloud(token='12345', host='https://readycloud.com/', org_id='1', api=ReadyCloud.API_V2)

    def test_get_orders_url_should_return_full_orders_url(self):
        self.assertEqual(self.rc.get_orders_url(), 'https://readycloud.com/api/v1/orders/')

    def test_get_order_url_should_return_full_order_url_with_id(self):
        self.assertEqual(self.rc.get_order_url('1'), 'https://readycloud.com/api/v1/orders/1/')

    def test_get_headers_should_return_right_headers(self):
        expected_headers = {
            'content-type': 'application/json',
            'AUTHORIZATION': 'bearer 12345',
        }
        self.assertEqual(self.rc.get_headers(), expected_headers)

    @patch('requests.get')
    def test_get_orders_should_send_get_with_right_params(self, get):
        self.rc.get_orders(limit=2)
        get.assert_called_once_with(
            'https://readycloud.com/api/v1/orders/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            params={'limit': 2})

    @patch('requests.get')
    def test_get_orders_via_api_2_should_send_get_with_right_params(self, get):
        self.rc_v2.get_orders(limit=2)
        get.assert_called_once_with(
            'https://readycloud.com/api/v2/orgs/1/orders/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            params={'limit': 2})

    @patch('requests.post')
    def test_created_order_should_send_post_with_right_params(self, post):
        order = {
            'message': 'test',
        }
        self.rc.create_order(order)
        post.assert_called_once_with(
            'https://readycloud.com/api/v1/orders/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps(order))

    @patch('requests.post')
    def test_created_order_via_api_2_should_send_post_with_right_params(self, post):
        order = {
            'message': 'test',
        }
        self.rc_v2.create_order(order)
        post.assert_called_once_with(
            'https://readycloud.com/api/v2/orgs/1/orders/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps(order))

    @patch('requests.put')
    def test_update_order_should_send_put_with_right_params(self, put):
        order = {
            'message': 'test',
        }
        self.rc.update_order('1', order)
        put.assert_called_once_with(
            'https://readycloud.com/api/v1/orders/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps(order))

    @patch('requests.put')
    def test_update_order_via_api_2_should_send_put_with_right_params(self, put):
        order = {
            'message': 'test',
        }
        self.rc_v2.update_order('1', order)
        put.assert_called_once_with(
            'https://readycloud.com/api/v2/orgs/1/orders/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps(order))

    @patch('requests.delete')
    def test_delete_order_should_send_delete(self, delete):
        self.rc.delete_order('1')
        delete.assert_called_once_with(
            'https://readycloud.com/api/v1/orders/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'})

    @patch('requests.get')
    def test_if_rc_returns_500_should_raise_exception(self, get):
        get.return_value = Mock(status_code=500)
        self.assertRaises(ReadyCloudServerError, self.rc.get_orders, limit=2)

    @patch('requests.post')
    def test_create_orders_webhooks_should_send_post_with_right_params(self, post):
        self.rc.create_orders_webhook('https://example.com/test')
        post.assert_called_once_with(
            'https://readycloud.com/api/v1/webhooks/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps({
                'entity': 'orders',
                'url': 'https://example.com/test',
            }))

    @patch('requests.get')
    def test_get_webhooks_should_send_get_with_right_params(self, get):
        self.rc.get_webhooks(limit=2)
        get.assert_called_once_with(
            'https://readycloud.com/api/v1/webhooks/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            params={'limit': 2})

    @patch('requests.put')
    def test_update_orders_webhook_should_send_put_with_right_params(self, put):
        self.rc.update_orders_webhook(1, 'https://example.com/new-url')
        put.assert_called_once_with(
            'https://readycloud.com/api/v1/webhooks/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            data=json.dumps({
                'entity': 'orders',
                'url': 'https://example.com/new-url',
            }))

    @patch('requests.delete')
    def test_delete_webhook_should_send_delete(self, delete):
        self.rc.delete_webhook(1)
        delete.assert_called_once_with(
            'https://readycloud.com/api/v1/webhooks/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'})

    @patch('requests.get')
    def test_get_organizations_should_return_right_params(self, get):
        self.rc_v2.get_organizations()
        get.assert_called_once_with(
            'https://readycloud.com/api/v2/orgs/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            params={})

    @patch('requests.get')
    def test_get_organization_with_pk_should_return_right_params(self, get):
        self.rc_v2.get_organization('1')
        get.assert_called_once_with(
            'https://readycloud.com/api/v2/orgs/1/',
            headers={
                'content-type': 'application/json',
                'AUTHORIZATION': 'bearer 12345'},
            params={})

if __name__ == '__main__':
    unittest.main()


text:
"""
compute column means and standard deviations from data in csv file
"""

import sys, csv
import numpy as np
import argparse

parser = argparse.ArgumentParser()
parser.add_argument( "input_file", help = "path to csv input file" )
parser.add_argument( "output_file", help = "path to output file" )
parser.add_argument( "--header", help = "Specify if file has header",
	action="store_true", default = False )
parser.add_argument( "-l", "--label_index", help = "Specify label index",
	type = int, default = False )

args = parser.parse_args()

i = open( args.input_file )
reader = csv.reader( i )
writer = csv.writer( open( args.output_file, 'wb' ))

# check headers

if args.header:
	first_line = reader.next()

n = 0

for line in reader:
	n += 1

	#to handle empty lines at the end if file
	if not line:
		break

	if args.label_index:
		line.pop( args.label_index )

	x = np.array( map( float, line ))
	x2 = np.square( x )

	# First pass initialize np arrays
	if n == 1:
		sums_x = x
		sums_x2 = x2
	else:
		sums_x += x
		sums_x2 += x2

# preparation

print n
print sums_x
print sums_x2

means = sums_x / n
sums2_x = np.square( sums_x )

#print means
#print sums2_x

variances = sums_x2 / n - sums2_x / ( n ** 2 )
standard_deviations = np.sqrt( variances )

#print variances
#print standard_deviations

# save stats
if args.header:
   writer.writerow( first_line )

writer.writerow( means )
writer.writerow( standard_deviations )


text:
"""Loop controller."""

from .loopmgr import LoopManager  # NOQA


text:
if [ -z "$ghprbPullId" -o -z "$ghprbTargetBranch" ]; then
  echo "Not all necessary environment variables set: ghprbPullId, ghprbTargetBranch"
  exit 1
fi

echo "Executing Pylint for PR ID $ghprbPullId and target branch $ghprbTargetBranch"

# Setup the environment
if [[ -f env_unittest_py3.sh ]]
then
    echo "Sourcing a python3 unittest environment"
    source env_unittest_py3.sh
    JSON_FILENAME=pylintpy3Report.json
    PEP8_FILENAME=pep8py3.txt
else
    echo "Sourcing a python2 unittest environment"
    source env_unittest.sh
    JSON_FILENAME=pylintReport.json
    PEP8_FILENAME=pep8.txt
fi

pushd wmcore_unittest/WMCore
export PYTHONPATH=`pwd`/test/python:`pwd`/src/python:$PYTHONPATH

# Figure out the one commit we are interested in and what happens to the repo if we were to merge it
git config remote.origin.url https://github.com/dmwm/WMCore.git
git fetch origin pull/${ghprbPullId}/merge:PR_MERGE
export COMMIT=`git rev-parse "PR_MERGE^{commit}"`
git checkout ${ghprbTargetBranch}
git pull

# Which python files changed?
git diff --name-only  ${ghprbTargetBranch}..${COMMIT} > allChangedFiles.txt
${HOME}/ContainerScripts/IdentifyPythonFiles.py allChangedFiles.txt > changedFiles.txt

echo "Printing Pylint version"
pylint --version

# Get pylint report for master
git checkout -f $ghprbTargetBranch
echo "{}" > pylintReport.json
echo "*** Running Pylint on the changed files against the $ghprbTargetBranch"
while read name; do
  pylint --evaluation='10.0 - ((float(5 * error + warning) / statement) * 10)'  --rcfile standards/.pylintrc --msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'  $name > pylint.out || true
 ${HOME}/ContainerScripts/AggregatePylint.py base
done <changedFiles.txt

# Get pylint report for the tip of our branch
git checkout -f $COMMIT
echo "*** Running Pylint on the changed files against the feature branch"
while read name; do
  pylint --evaluation='10.0 - ((float(5 * error + warning) / statement) * 10)'  --rcfile standards/.pylintrc  --msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'  $name  > pylint.out || true
 ${HOME}/ContainerScripts/AggregatePylint.py test
done <changedFiles.txt

# Save the artifacts to a directory shared by the container and the node
# update file if it's a python3 pylint job
mv pylintReport.json ${JSON_FILENAME} || true
cp *.json ${HOME}/artifacts/

# Do pep8 analysis on tip of branch
# Renamed pycodestyle in future iterations
# Hack to fix broken pep8
echo "#! /usr/bin/env python" > ./pep8
cat `which pep8` >> ./pep8
chmod +x pep8

touch NOTHING # If changedFiles.txt is empty, this will keep it from parsing the whole directory tree
./pep8 NOTHING `< changedFiles.txt` > ${PEP8_FILENAME}
cp ${PEP8_FILENAME} ${HOME}/artifacts/

popd


text:
archive: tag
layout: archive
permalink: /tag/animals/
tag: animals
title: Archive for animals

---


text:
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

ActiveRecord::Migration.maintain_test_schema!

Capybara.default_driver = :webkit
Capybara.javascript_driver = :webkit

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!

  config.include Features::GoogleAuth, type: :feature
  config.include FactoryGirl::Syntax::Methods

  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.clean_with :truncation
  end

  config.before(:each) do |example|
    if example.metadata[:js]
      DatabaseCleaner.strategy = :truncation
    else
      DatabaseCleaner.strategy = :transaction
    end
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end


text:
"""Google Cloud Datalab - notebook extension functionality."""

try:
  import IPython as _
except ImportError:
  raise Exception('This package requires an IPython notebook installation')

__all__ = ['_']

def _jupyter_nbextension_paths():
  return [dict(section="notebook", src="static", dest="gcpdatalab")]


text:
<!doctype html>

    <meta charset="utf-8">
    <title>amp-sidebar</title>
    <link rel="canonical" href="//example.com" >
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">

    <amp-sidebar id="sidebar" layout="nodisplay">

Item 1

Item 2

Item 3

Item 4

    </amp-sidebar>

    <button id="open" on="tap:sidebar.open">
        Open Sidebar
    </button>


text:
package com.planet_ink.coffee_mud.MOBS;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
import com.planet_ink.coffee_mud.core.collections.*;
import com.planet_ink.coffee_mud.Abilities.interfaces.*;
import com.planet_ink.coffee_mud.Areas.interfaces.*;
import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
import com.planet_ink.coffee_mud.Commands.interfaces.*;
import com.planet_ink.coffee_mud.Common.interfaces.*;
import com.planet_ink.coffee_mud.Exits.interfaces.*;
import com.planet_ink.coffee_mud.Items.interfaces.*;
import com.planet_ink.coffee_mud.Libraries.interfaces.*;
import com.planet_ink.coffee_mud.Locales.interfaces.*;
import com.planet_ink.coffee_mud.MOBS.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;

import java.util.*;

public class Swordfish extends StdMOB
{
	@Override
	public String ID()
	{
		return "Swordfish";
	}

	public Swordfish()
	{
		super();
		_name="a swordfish";
		setDescription("It\\`s a shark with a long piercing nose.");
		setDisplayText("A swordfish is here.");
		CMLib.factions().setAlignment(this,Faction.Align.NEUTRAL);
		setMoney(0);
		setWimpHitPoint(2);

		basePhyStats().setDamage(6);

		baseCharStats().setStat(CharStats.STAT_INTELLIGENCE,1);

		basePhyStats().setAbility(0);
		basePhyStats().setLevel(1);
		basePhyStats().setArmor(90);

		baseCharStats().setMyRace(CMClass.getRace("Swordfish"));
		baseCharStats().getMyRace().startRacing(this,false);
		baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(),11,basePhyStats().level()));

		recoverMaxState();
		resetToMaxState();
		recoverPhyStats();
		recoverCharStats();
	}

}


text:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;

namespace JesseJohnston
{
	/// <summary>
	/// A node in the filter expression tree.  A node may be a terminal expression (i.e. property name, value, and relational operator)
	/// or a sub-tree containing a logical operator, left and right terms.
	/// </summary>
	internal class FilterNode : IEnumerable<FilterNode>
	{
		#region Types
		private class FilterNodeEnumerator : IEnumerator<FilterNode>
		{
			private FilterNode tree;
			private FilterNode current;
			private Stack<FilterNode> nodes = new Stack<FilterNode>();

			public FilterNodeEnumerator(FilterNode tree)
			{
				this.tree = tree;
			}

			#region IEnumerator<FilterNode> Members
			public FilterNode Current
			{
				get
				{
					if (this.current == null)
						throw new InvalidOperationException("Current");
					else
						return this.current;
				}
			}
			#endregion

			#region IDisposable Members
			public void Dispose()
			{
			}
			#endregion

			#region IEnumerator Members
			object IEnumerator.Current
			{
				get { return ((IEnumerator<FilterNode>)this).Current; }
			}
			public bool MoveNext()
			{
				// Initially, current is null, so we traverse the left edge.
				if (this.current == null)
				{
					this.current = this.tree;

					if (this.current.left == null && this.current.right == null)
						return true;

					// don't return it; we want to go down the left side first.
				}
				else if (this.current.right != null)
				{
					this.current = this.current.right;

					if (this.current.left == null && this.current.right == null)
						return true;

					// don't return it; we want to go down the left side first.
				}

				if (this.current.left != null)
				{
					while (this.current.left != null)
					{
						this.nodes.Push(this.current);
						this.current = this.current.left;
					}

					return true;
				}
				else if (this.nodes.Count > 0)
				{
					this.current = this.nodes.Pop();
					return true;
				}
				else
					return false;
			}
			public void Reset()
			{
				this.current = null;
				this.nodes.Clear();
			}
			#endregion
		}
		private enum TokenType
		{
			Term,
			Relation,
			Condition,
			OpenParen,
			CloseParen,
			ResolvedExpression,
			ResolvedNode
		}
		private class Token
		{
			private string term;
			private LogicalOperator logOp;
			private RelationalOperator relOp;
			private RelationalExpression expr;
			private FilterNode node;
			private TokenType type;

			public LogicalOperator Condition
			{
				get
				{
					if (type != TokenType.Condition)
						throw new StrongTypingException("Token is not a condition.");
					return logOp;
				}
			}
			public RelationalOperator Relation
			{
				get
				{
					if (this.type != TokenType.Relation)
						throw new StrongTypingException("Token is not a relation.");
					return relOp;
				}
			}
			public RelationalExpression ResolvedExpression
			{
				get
				{
					if (this.type != TokenType.ResolvedExpression)
						throw new StrongTypingException("Token is not a resolved expression.");
					return this.expr;
				}
			}
			public FilterNode ResolvedNode
			{
				get
				{
					if (this.type != TokenType.ResolvedNode)
						throw new StrongTypingException("Token is not a resolved node.");
					return node;
				}
			}
			public string Term
			{
				get
				{
					if (this.type != TokenType.Term)
						throw new StrongTypingException("Token is not a term.");
					return term;
				}
			}
			public TokenType Type
			{
				get { return type; }
			}

			public Token(string term)
			{
				if (term == "(")
					this.type = TokenType.OpenParen;
				else if (term == ")")
					this.type = TokenType.CloseParen;
				else
				{
					this.type = TokenType.Term;
					this.term = term;
				}
			}
			public Token(LogicalOperator condition)
			{
				this.type = TokenType.Condition;
				this.logOp = condition;
			}
			public Token(RelationalOperator relation)
			{
				this.type = TokenType.Relation;
				this.relOp = relation;
			}
			public Token(RelationalExpression expression)
			{
				this.type = TokenType.ResolvedExpression;
				this.expr = expression;
			}
			public Token(FilterNode node)
			{
				this.type = TokenType.ResolvedNode;
				this.node = node;
			}
		}
		private class Tokenizer : IEnumerable<Token>
		{
			private List<Token> tokens = new List<Token>();
			private static Dictionary<string, LogicalOperator> logicalOps = new Dictionary<string,LogicalOperator>();
			private static Dictionary<string, RelationalOperator> relationalOps = new Dictionary<string,RelationalOperator>();
			private static List<string> multiCharRelationalOps = new List<string>();

			static Tokenizer()
			{
				logicalOps.Add("And", LogicalOperator.And);
				logicalOps.Add("Or", LogicalOperator.Or);

				relationalOps.Add("=", RelationalOperator.Equal);
				relationalOps.Add("==", RelationalOperator.Equal);
				relationalOps.Add("!=", RelationalOperator.NotEqual);
				relationalOps.Add("<>", RelationalOperator.NotEqual);
				relationalOps.Add("<", RelationalOperator.Less);
				relationalOps.Add("<=", RelationalOperator.LessEqual);
				relationalOps.Add(">", RelationalOperator.Greater);
				relationalOps.Add(">=", RelationalOperator.GreaterEqual);

				foreach (string op in relationalOps.Keys)
				{
					if (op.Length > 1)
						multiCharRelationalOps.Add(op);
				}
			}

			public Tokenizer(string expression)
			{
				if (expression == null)
					throw new ArgumentNullException("expression");
				if (expression == "")
					throw new ArgumentException("expression");

				// Split into tokens delimited by spaces, relational operators, and parentheses.  Remove extra spaces.
				ICollection<string> parts = ExtractTokens(expression,
														  new char[] { ' ', '<', '>', '=', '!', '(', ')' },
														  new char[] { '<', '>', '=', '!', '(', ')' },
														  new char[] { '\'', '"' });

				if (parts.Count == 0)
					throw new ArgumentException("expression");

				// Parse into tokens that are either operators, terms or a paren.
				Token prevToken = null;
				int parenCount = 0;

				foreach (string part in parts)
				{
					Token t = null;

					// Because a condition could also be the rvalue of a relation (e.g. State = OR), evaluate as a condition
					// only if it does not follow a relational operator.
					if (prevToken == null || prevToken.Type != TokenType.Relation)
					{
						foreach (KeyValuePair<string, LogicalOperator> pair in logicalOps)
						{
							if (string.Compare(part, pair.Key, true) == 0)
							{
								if (prevToken == null || (prevToken.Type != TokenType.Term && prevToken.Type != TokenType.CloseParen))
									throw new ArgumentException("An operator must be preceded by an expression term or closing paren.", "expression");
								t = new Token(pair.Value);
								break;
							}
						}
					}

					if (t == null)
					{
						foreach (KeyValuePair<string, RelationalOperator> pair in relationalOps)
						{
							if (string.Compare(part, pair.Key, true) == 0)
							{
								if (prevToken == null || prevToken.Type != TokenType.Term)
									throw new ArgumentException("An operator must be preceded by an expression term.", "expression");
								t = new Token(pair.Value);
								break;
							}
						}
					}

					if (t == null)
					{
						if (part == "(")
						{
							if (prevToken != null && prevToken.Type != TokenType.Condition && prevToken.Type != TokenType.Relation && prevToken.Type != TokenType.OpenParen)
								throw new ArgumentException("An opening paren must be preceded by an operator or an opening paren.", "expression");
							parenCount++;
						}
						else if (part == ")")
						{
							if (prevToken == null || (prevToken.Type != TokenType.Term && prevToken.Type != TokenType.CloseParen))
								throw new ArgumentException("A closing paren must be preceded by an expression term or a closing paren.", "expression");
							if (parenCount == 0)
								throw new ArgumentException("Unbalanced parentheses.", "expression");
							parenCount--;
						}
						else
						{
							if (prevToken != null && prevToken.Type != TokenType.Condition && prevToken.Type != TokenType.Relation && prevToken.Type != TokenType.OpenParen)
								throw new ArgumentException("An expression term must be preceded by an operator or opening paren.", "expression");
						}

						t = new Token(part);
					}

					tokens.Add(t);
					prevToken = t;
				}

				// The expression must end with a term or a closing paren.
				Token last = tokens[tokens.Count - 1];
				if (last.Type != TokenType.Term && last.Type != TokenType.CloseParen)
					throw new ArgumentException("An expression must end in an expression term or a closing paren.", "expression");

				// The expression must contain at least two terms and a relation.
				int terms = 0;
				int relations = 0;
				foreach (Token t in tokens)
				{
					if (t.Type == TokenType.Term)
						terms++;
					else if (t.Type == TokenType.Relation)
						relations++;
				}

				if (terms < 2 || relations == 0)
					throw new ArgumentException("An expression must contain at least two terms and a relational operator.", "expression");
			}

			private ICollection<string> ExtractTokens(string expression, char[] delimiters, char[] delimitersIncludedAsTokens, char[] quotes)
			{
				List<string> tokens = new List<string>();
				List<char> delims = new List<char>(delimiters);							// delimiters
				List<char> delimTokens = new List<char>(delimitersIncludedAsTokens);	// delimiters which are also tokens
				List<char> quoteChars = new List<char>(quotes);

				int tokenStart = 0;
				int tokenEnd = 0;
				bool inQuote = false;
				char prevQuote = ' ';

				// Remove leading and trailing whitespace.
				expression = expression.Trim();

				for (int i = 0; i < expression.Length; i++)
				{
					char c = expression[i];

					if (i == expression.Length - 1)				// Remainder of string (not ending in a delimiter)
					{
						if (inQuote && c == prevQuote)
							tokens.Add(expression.Substring(tokenStart, i - tokenStart));
						else if (!delims.Contains(c) || delimTokens.Contains(c))
							tokens.Add(expression.Substring(tokenStart));
					}
					else if (quoteChars.Contains(c))			// Quote found
					{
						if (inQuote)
						{
							if (c == prevQuote)
							{
								inQuote = false;

								tokenEnd = i;

								if (tokenEnd > tokenStart)		// Non-empty?
									tokens.Add(expression.Substring(tokenStart, tokenEnd - tokenStart));

								tokenStart = i + 1;				// Start parsing the next token
							}
						}
						else
						{
							inQuote = true;
							prevQuote = c;
							tokenStart = i + 1;					// Start parsing the next token
						}
					}
					else if (!inQuote && delims.Contains(c))	// Delimiter found
					{
						tokenEnd = i;

						if (tokenEnd > tokenStart)				// Non-empty?
							tokens.Add(expression.Substring(tokenStart, tokenEnd - tokenStart));

						if (delimTokens.Contains(c))			// If the delimiter is also a token, add it to the token list
							tokens.Add(new string(c, 1));

						tokenStart = i + 1;						// Start parsing the next token
					}
				}

				// Coalesce adjacent operators that form a multi-character operator (e.g. <>, !=, ==)
				string prevToken = "";
				string[] tokenArray = tokens.ToArray();
				int tokensRemoved = 0;
				for (int j = 0; j < tokenArray.Length ; j++)
				{
					string token = tokenArray[j];
					string compoundToken = prevToken + token;
					if (multiCharRelationalOps.Contains(compoundToken))
					{
						int newPosition = j - 1 - tokensRemoved;
						tokens.RemoveAt(newPosition);
						tokens.RemoveAt(newPosition);
						tokens.Insert(newPosition, compoundToken);
						tokensRemoved++;
					}

					prevToken = token;
				}

				return tokens;
			}

			#region IEnumerable<Token> Members
			public IEnumerator<Token> GetEnumerator()
			{
				return tokens.GetEnumerator();
			}
			#endregion

			#region IEnumerable Members
			System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
			{
				return ((System.Collections.IEnumerable)tokens).GetEnumerator();
			}
			#endregion
		}
		#endregion

		private LogicalOperator op;
		private RelationalExpression term;
		private FilterNode left;
		private FilterNode right;
		private bool? evaluated;

		public bool? Evaluated
		{
			get { return this.evaluated; }
		}
		public FilterNode Left
		{
			get { return this.left; }
		}
		public LogicalOperator Operator
		{
			get { return this.op; }
		}
		public FilterNode Right
		{
			get { return this.right; }
		}
		public RelationalExpression Term
		{
			get { return this.term; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="FilterNode"/> class that is a terminal node.
		/// </summary>
		/// <remarks>
		/// A terminal node is a relational expression, and contains no child nodes.
		/// </remarks>
		/// <param name="term">The expression term.</param>
		public FilterNode(RelationalExpression term)
		{
			if (term == null)
				throw new ArgumentNullException("term");
			this.term = term;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="FilterNode"/> class that is not a terminal node.
		/// </summary>
		/// <param name="left">The left child node.</param>
		/// <param name="right">The right node.</param>
		/// <param name="op">The operator relating the child nodes.</param>
		public FilterNode(FilterNode left, FilterNode right, LogicalOperator op)
		{
			if (left == null)
				throw new ArgumentNullException("left");
			if (right == null)
				throw new ArgumentNullException("right");
			if (op == LogicalOperator.None)
				throw new ArgumentException("op");

			this.left = left;
			this.right = right;
			this.op = op;
		}

		/// <summary>
		/// Parses the specified text into a binary expression tree.
		/// </summary>
		/// <param name="expression">The expression text to parse.</param>
		/// <returns></returns>
		public static FilterNode Parse(string expression)
		{
			List<Token> tokens = new List<Token>(new Tokenizer(expression));

			// Combine terms and relational operators into expressions.
			while (true)
			{
				int evaluationIndex = -1;
				for (int i = 0; i < tokens.Count; i++)
				{
					if (tokens[i].Type == TokenType.Relation)
					{
						evaluationIndex = i;
						break;
					}
				}

				if (evaluationIndex > -1)
				{
					RelationalExpression expr = new RelationalExpression(tokens[evaluationIndex - 1].Term,
																		 tokens[evaluationIndex + 1].Term,
																		 tokens[evaluationIndex].Relation);
					tokens.RemoveAt(evaluationIndex - 1);
					tokens.RemoveAt(evaluationIndex - 1);
					tokens.RemoveAt(evaluationIndex - 1);

					tokens.Insert(evaluationIndex - 1, new Token(expr));

					// Remove parentheses surrounding a resolved expression.
					if (evaluationIndex - 2 > -1 && tokens[evaluationIndex - 2].Type == TokenType.OpenParen &&
						evaluationIndex < tokens.Count && tokens[evaluationIndex].Type == TokenType.CloseParen)
					{
						// New resolved expression is now at evaluationIndex - 1.
						tokens.RemoveAt(evaluationIndex - 2);
						// New resolved expression is now at evaluationIndex - 2.
						tokens.RemoveAt(evaluationIndex - 1);
					}
				}
				else
					break;
			}

			// If the token list contains only a single relational expression, we can return a simple filter node based on that.
			if (tokens.Count == 1 && tokens[0].Type == TokenType.ResolvedExpression)
				return new FilterNode(tokens[0].ResolvedExpression);

			// The token list now contains only RelationalExpressions, conditional operators (AND and OR) and parentheses.
			// Combine the expressions and operators into nodes, prioritizing binding according to the natural order of precedence
			// for boolean operators and parentheses.
			Dictionary<LogicalOperator, int> operatorPriorities = new Dictionary<LogicalOperator, int>();
			operatorPriorities.Add(LogicalOperator.Or, 1);
			operatorPriorities.Add(LogicalOperator.And, 2);
			int parenAddedPriority = operatorPriorities.Count;

			while (true)
			{
				int contextPriority = 0;
				int evaluationPriorityMax = -1;
				int evaluationIndex = -1;

				for (int i = 0; i < tokens.Count; i++)
				{
					TokenType type = tokens[i].Type;

					if (type == TokenType.Condition)
					{
						int evaluationPriority = operatorPriorities[tokens[i].Condition] + contextPriority;
						if (evaluationPriority > evaluationPriorityMax)
						{
							evaluationIndex = i;
							evaluationPriorityMax = evaluationPriority;
						}
					}
					else if (type == TokenType.OpenParen)
					{
						contextPriority += parenAddedPriority;
					}
					else if (type == TokenType.CloseParen)
					{
						contextPriority -= parenAddedPriority;
					}
				}

				if (evaluationIndex > -1)
				{
					Token prevToken = tokens[evaluationIndex - 1];
					Token nextToken = tokens[evaluationIndex + 1];

					FilterNode nodeLeft = null;
					FilterNode nodeRight = null;

					// Tokens surrounding the AND or OR must now be either a relational expression or a resolved FilterNode.
					if (prevToken.Type == TokenType.ResolvedExpression)
						nodeLeft = new FilterNode(prevToken.ResolvedExpression);
					else
						nodeLeft = prevToken.ResolvedNode;
					if (nextToken.Type == TokenType.ResolvedExpression)
						nodeRight = new FilterNode(nextToken.ResolvedExpression);
					else
						nodeRight = nextToken.ResolvedNode;

					FilterNode node = new FilterNode(nodeLeft, nodeRight, tokens[evaluationIndex].Condition);

					tokens.RemoveAt(evaluationIndex - 1);
					tokens.RemoveAt(evaluationIndex - 1);
					tokens.RemoveAt(evaluationIndex - 1);

					tokens.Insert(evaluationIndex - 1, new Token(node));

					// Remove parentheses surrounding a resolved node.
					if (evaluationIndex - 2 > -1 && tokens[evaluationIndex - 2].Type == TokenType.OpenParen &&
						evaluationIndex < tokens.Count && tokens[evaluationIndex].Type == TokenType.CloseParen)
					{
						// New resolved node is now at evaluationIndex - 1.
						tokens.RemoveAt(evaluationIndex - 2);
						// New resolved node is now at evaluationIndex - 2.
						tokens.RemoveAt(evaluationIndex - 1);
					}
				}
				else
					break;
			}

			// The token list should now contain a single FilterNode.
			return tokens[0].ResolvedNode;
		}

		/// <summary>
		/// Evaluates the current node and it's child nodes.
		/// </summary>
		/// <param name="evaluator">The delegate used to evaluate terminal nodes.</param>
		/// <returns>True if the current node and it's children evaluate to true; false otherwise.</returns>
		public bool Evaluate(ExpressionEvaluator evaluator)
		{
			FilterNode current = this;
			Stack<FilterNode> nodes = new Stack<FilterNode>();

			while (true)
			{
				// A terminal expression?
				if (current.op == LogicalOperator.None)
				{
					current.evaluated = evaluator(current);
				}
				else
				{
					if (!current.left.evaluated.HasValue)
					{
						nodes.Push(current);
						current = current.left;
						continue;
					}

					if (!current.right.evaluated.HasValue)
					{
						nodes.Push(current);
						current = current.right;
						continue;
					}

					if (current.op == LogicalOperator.And)
						current.evaluated = current.left.evaluated.Value && current.right.evaluated.Value;
					else
						current.evaluated = current.left.evaluated.Value || current.right.evaluated.Value;
				}

				if (nodes.Count > 0)
					current = nodes.Pop();
				else
					return current.evaluated.Value;
			}
		}

		/// <summary>
		/// Resets the evaluation status for each node in the expression tree, so that it can be re-evaluated.
		/// </summary>
		public void Reset()
		{
			foreach (FilterNode node in this)
			{
				node.evaluated = null;
			}
		}

		#region IEnumerable<FilterNode> Members
		public IEnumerator<FilterNode> GetEnumerator()
		{
			return new FilterNodeEnumerator(this);
		}
		#endregion

		#region IEnumerable Members
		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable<FilterNode>)this).GetEnumerator();
		}
		#endregion
	}

	internal delegate bool ExpressionEvaluator(FilterNode expression);
}


text:
print all lines containing foo in input.txt

    grep "foo" input.txt

print all lines matching the regex "^start" in input.txt

    grep -e "^start" input.txt

print all lines containing bar by recursively searching a directory

    grep -r "bar" directory

# Basic Usage

Search each line in `input_file` for a match against `pattern` and print
matching lines:

    grep "<pattern>" <input_file>

# Find Lines NOT Matching

Print lines that do NOT match a pattern by using the `-v` flag. This will
print all lines that do NOT contain a z (`-v "z"`):

    grep -v "z" input.xt

# Print File Names

Show only the file names containing matches, rather than the matching lines
themselves, by using the `-l` flag.

    grep -r -l "target_pattern" directory

Show only the file names that do NOT contain matches by using the `-L` flag:

    grep -r -L "unwanted_pattern" directory

# Regular Expressions

Regular expressions can be passed to `grep` using the `-e` flag. `egrep` is
equivalent to using the `-e` flag.

The following file is used in the examples:

    $ cat input.txt
    1 2 3
    omega
    alpha foo
    alpha bar
    baz omega
    4 5 6

Match lines beginning (`^`) with `alpha` (`^alpha`):

    $ grep -e "^alpha" input.txt
    alpha foo
    alpha bar

Match lines ending (`$`) with `omega` (`omega$`):

    $ grep -e "omega$" input.txt
    omega
    baz omega

Match any line containing `a` and `o` separated by 0 or more characters (`.*`):

    $ grep -e "a.*o" input.txt
    alpha foo
    baz omega

Match any line containing `z` or `f` (`[zf]`):

    $ grep -e "[zf]" input.txt
    alpha foo
    baz omega

Match all lines with lower case or capital letters a through z (`[a-zA-Z]`):

    $ grep -e "[a-zA-Z]" input.txt
    omega
    alpha foo
    alpha bar
    baz omega

Match all lines containg numbers (`[0-9]`):

    $ grep -e "[0-9]" input.txt
    1 2 3
    4 5 6

Match all lines containing white space (`[[:space:]]`):

    $ grep -e "[[:space:]]" input.txt
    1 2 3
    alpha foo
    alpha bar
    baz omega
    4 5 6


text:
"""
Multiclass
from:
https://github.com/guillaumegenthial/tf_metrics/blob/master/tf_metrics/__init__.py

"""

__author__ = "Guillaume Genthial"

import numpy as np
import tensorflow as tf
from tensorflow.python.ops.metrics_impl import _streaming_confusion_matrix

def precision(labels, predictions, num_classes, pos_indices=None,
              weights=None, average='micro'):
    """Multi-class precision metric for Tensorflow
    Parameters
    ----------
    labels : Tensor of tf.int32 or tf.int64
        The true labels
    predictions : Tensor of tf.int32 or tf.int64
        The predictions, same shape as labels
    num_classes : int
        The number of classes
    pos_indices : list of int, optional
        The indices of the positive classes, default is all
    weights : Tensor of tf.int32, optional
        Mask, must be of compatible shape with labels
    average : str, optional
        'micro': counts the total number of true positives, false
            positives, and false negatives for the classes in
            `pos_indices` and infer the metric from it.
        'macro': will compute the metric separately for each class in
            `pos_indices` and average. Will not account for class
            imbalance.
        'weighted': will compute the metric separately for each class in
            `pos_indices` and perform a weighted average by the total
            number of true labels for each class.
    Returns
    -------
    tuple of (scalar float Tensor, update_op)
    """
    cm, op = _streaming_confusion_matrix(
        labels, predictions, num_classes, weights)
    pr, _, _ = metrics_from_confusion_matrix(
        cm, pos_indices, average=average)
    op, _, _ = metrics_from_confusion_matrix(
        op, pos_indices, average=average)
    return (pr, op)

def recall(labels, predictions, num_classes, pos_indices=None, weights=None,
           average='micro'):
    """Multi-class recall metric for Tensorflow
    Parameters
    ----------
    labels : Tensor of tf.int32 or tf.int64
        The true labels
    predictions : Tensor of tf.int32 or tf.int64
        The predictions, same shape as labels
    num_classes : int
        The number of classes
    pos_indices : list of int, optional
        The indices of the positive classes, default is all
    weights : Tensor of tf.int32, optional
        Mask, must be of compatible shape with labels
    average : str, optional
        'micro': counts the total number of true positives, false
            positives, and false negatives for the classes in
            `pos_indices` and infer the metric from it.
        'macro': will compute the metric separately for each class in
            `pos_indices` and average. Will not account for class
            imbalance.
        'weighted': will compute the metric separately for each class in
            `pos_indices` and perform a weighted average by the total
            number of true labels for each class.
    Returns
    -------
    tuple of (scalar float Tensor, update_op)
    """
    cm, op = _streaming_confusion_matrix(
        labels, predictions, num_classes, weights)
    _, re, _ = metrics_from_confusion_matrix(
        cm, pos_indices, average=average)
    _, op, _ = metrics_from_confusion_matrix(
        op, pos_indices, average=average)
    return (re, op)

def f1(labels, predictions, num_classes, pos_indices=None, weights=None,
       average='micro'):
    return fbeta(labels, predictions, num_classes, pos_indices, weights,
                 average)

def fbeta(labels, predictions, num_classes, pos_indices=None, weights=None,
          average='micro', beta=1):
    """Multi-class fbeta metric for Tensorflow
    Parameters
    ----------
    labels : Tensor of tf.int32 or tf.int64
        The true labels
    predictions : Tensor of tf.int32 or tf.int64
        The predictions, same shape as labels
    num_classes : int
        The number of classes
    pos_indices : list of int, optional
        The indices of the positive classes, default is all
    weights : Tensor of tf.int32, optional
        Mask, must be of compatible shape with labels
    average : str, optional
        'micro': counts the total number of true positives, false
            positives, and false negatives for the classes in
            `pos_indices` and infer the metric from it.
        'macro': will compute the metric separately for each class in
            `pos_indices` and average. Will not account for class
            imbalance.
        'weighted': will compute the metric separately for each class in
            `pos_indices` and perform a weighted average by the total
            number of true labels for each class.
    beta : int, optional
        Weight of precision in harmonic mean
    Returns
    -------
    tuple of (scalar float Tensor, update_op)
    """
    cm, op = _streaming_confusion_matrix(
        labels, predictions, num_classes, weights)
    _, _, fbeta = metrics_from_confusion_matrix(
        cm, pos_indices, average=average, beta=beta)
    _, _, op = metrics_from_confusion_matrix(
        op, pos_indices, average=average, beta=beta)
    return (fbeta, op)

def safe_div(numerator, denominator):
    """Safe division, return 0 if denominator is 0"""
    numerator, denominator = tf.to_float(numerator), tf.to_float(denominator)
    zeros = tf.zeros_like(numerator, dtype=numerator.dtype)
    denominator_is_zero = tf.equal(denominator, zeros)
    return tf.where(denominator_is_zero, zeros, numerator / denominator)

def pr_re_fbeta(cm, pos_indices, beta=1):
    """Uses a confusion matrix to compute precision, recall and fbeta"""
    num_classes = cm.shape[0]
    neg_indices = [i for i in range(num_classes) if i not in pos_indices]
    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[neg_indices, neg_indices] = 0
    diag_sum = tf.reduce_sum(tf.diag_part(cm * cm_mask))

    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[:, neg_indices] = 0
    tot_pred = tf.reduce_sum(cm * cm_mask)

    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[neg_indices, :] = 0
    tot_gold = tf.reduce_sum(cm * cm_mask)

    pr = safe_div(diag_sum, tot_pred)
    re = safe_div(diag_sum, tot_gold)
    fbeta = safe_div((1. + beta**2) * pr * re, beta**2 * pr + re)

    return pr, re, fbeta

def metrics_from_confusion_matrix(cm, pos_indices=None, average='micro',
                                  beta=1):
    """Precision, Recall and F1 from the confusion matrix
    Parameters
    ----------
    cm : tf.Tensor of type tf.int32, of shape (num_classes, num_classes)
        The streaming confusion matrix.
    pos_indices : list of int, optional
        The indices of the positive classes
    beta : int, optional
        Weight of precision in harmonic mean
    average : str, optional
        'micro', 'macro' or 'weighted'
    """
    num_classes = cm.shape[0]
    if pos_indices is None:
        pos_indices = [i for i in range(num_classes)]

    if average == 'micro':
        return pr_re_fbeta(cm, pos_indices, beta)
    elif average in {'macro', 'weighted'}:
        precisions, recalls, fbetas, n_golds = [], [], [], []
        for idx in pos_indices:
            pr, re, fbeta = pr_re_fbeta(cm, [idx], beta)
            precisions.append(pr)
            recalls.append(re)
            fbetas.append(fbeta)
            cm_mask = np.zeros([num_classes, num_classes])
            cm_mask[idx, :] = 1
            n_golds.append(tf.to_float(tf.reduce_sum(cm * cm_mask)))

        if average == 'macro':
            pr = tf.reduce_mean(precisions)
            re = tf.reduce_mean(recalls)
            fbeta = tf.reduce_mean(fbetas)
            return pr, re, fbeta
        if average == 'weighted':
            n_gold = tf.reduce_sum(n_golds)
            pr_sum = sum(p * n for p, n in zip(precisions, n_golds))
            pr = safe_div(pr_sum, n_gold)
            re_sum = sum(r * n for r, n in zip(recalls, n_golds))
            re = safe_div(re_sum, n_gold)
            fbeta_sum = sum(f * n for f, n in zip(fbetas, n_golds))
            fbeta = safe_div(fbeta_sum, n_gold)
            return pr, re, fbeta

    else:
        raise NotImplementedError()


text:
package idtoken_test

import (
	"context"
	"net/http"

	"google.golang.org/api/idtoken"
)

func ExampleNewTokenSource_setAuthorizationHeader() {
	ctx := context.Background()
	audience := "http://example.com"
	ts, err := idtoken.NewTokenSource(ctx, audience)
	if err != nil {
		// TODO: Handle error.
	}
	token, err := ts.Token()
	if err != nil {
		// TODO: Handle error.
	}
	req, err := http.NewRequest(http.MethodGet, audience, nil)
	if err != nil {
		// TODO: Handle error.
	}
	token.SetAuthHeader(req)
}


text:
/**
 * Used by `_.trim` and `_.trimLeft` to get the index of the first character
 * of `string` that is not found in `chars`.
 *
 * @private
 * @param {string} string The string to inspect.
 * @param {string} chars The characters to find.
 * @returns {number} Returns the index of the first character not found in `chars`.
 */
function charsLeftIndex(string, chars) {
  var index = -1,
      length = string.length;

  while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  return index;
}

module.exports = charsLeftIndex;


text:
package source

import (
	"context"
	"go/ast"
	"go/doc"
	"go/format"
	"go/types"
	"strings"

	"golang.org/x/tools/internal/telemetry/trace"
	errors "golang.org/x/xerrors"
)

type HoverInformation struct {
	// Signature is the symbol's signature.
	Signature string `json:"signature"`

	// SingleLine is a single line describing the symbol.
	// This is recommended only for use in clients that show a single line for hover.
	SingleLine string `json:"singleLine"`

	// Synopsis is a single sentence synopsis of the symbol's documentation.
	Synopsis string `json:"synopsis"`

	// FullDocumentation is the symbol's full documentation.
	FullDocumentation string `json:"fullDocumentation"`

	source  interface{}
	comment *ast.CommentGroup
}

func (i *IdentifierInfo) Hover(ctx context.Context) (*HoverInformation, error) {
	ctx, done := trace.StartSpan(ctx, "source.Hover")
	defer done()

	h, err := i.decl.hover(ctx)
	if err != nil {
		return nil, err
	}
	// Determine the symbol's signature.
	switch x := h.source.(type) {
	case ast.Node:
		var b strings.Builder
		if err := format.Node(&b, i.File.FileSet(), x); err != nil {
			return nil, err
		}
		h.Signature = b.String()
	case types.Object:
		h.Signature = types.ObjectString(x, i.qf)
	}

	// Set the documentation.
	if i.decl.obj != nil {
		h.SingleLine = types.ObjectString(i.decl.obj, i.qf)
	}
	if h.comment != nil {
		h.FullDocumentation = h.comment.Text()
		h.Synopsis = doc.Synopsis(h.FullDocumentation)
	}
	return h, nil
}

func (d declaration) hover(ctx context.Context) (*HoverInformation, error) {
	ctx, done := trace.StartSpan(ctx, "source.hover")
	defer done()
	obj := d.obj
	switch node := d.node.(type) {
	case *ast.ImportSpec:
		return &HoverInformation{source: node}, nil
	case *ast.GenDecl:
		switch obj := obj.(type) {
		case *types.TypeName, *types.Var, *types.Const, *types.Func:
			return formatGenDecl(node, obj, obj.Type())
		}
	case *ast.TypeSpec:
		if obj.Parent() == types.Universe {
			if obj.Name() == "error" {
				return &HoverInformation{source: node}, nil
			}
			return &HoverInformation{source: node.Name}, nil // comments not needed for builtins
		}
	case *ast.FuncDecl:
		switch obj.(type) {
		case *types.Func:
			return &HoverInformation{source: obj, comment: node.Doc}, nil
		case *types.Builtin:
			return &HoverInformation{source: node.Type, comment: node.Doc}, nil
		}
	}
	return &HoverInformation{source: obj}, nil
}

func formatGenDecl(node *ast.GenDecl, obj types.Object, typ types.Type) (*HoverInformation, error) {
	if _, ok := typ.(*types.Named); ok {
		switch typ.Underlying().(type) {
		case *types.Interface, *types.Struct:
			return formatGenDecl(node, obj, typ.Underlying())
		}
	}
	var spec ast.Spec
	for _, s := range node.Specs {
		if s.Pos() <= obj.Pos() && obj.Pos() <= s.End() {
			spec = s
			break
		}
	}
	if spec == nil {
		return nil, errors.Errorf("no spec for node %v at position %v", node, obj.Pos())
	}
	// If we have a field or method.
	switch obj.(type) {
	case *types.Var, *types.Const, *types.Func:
		return formatVar(spec, obj)
	}
	// Handle types.
	switch spec := spec.(type) {
	case *ast.TypeSpec:
		if len(node.Specs) > 1 {
			// If multiple types are declared in the same block.
			return &HoverInformation{source: spec.Type, comment: spec.Doc}, nil
		} else {
			return &HoverInformation{source: spec, comment: node.Doc}, nil
		}
	case *ast.ValueSpec:
		return &HoverInformation{source: spec, comment: spec.Doc}, nil
	case *ast.ImportSpec:
		return &HoverInformation{source: spec, comment: spec.Doc}, nil
	}
	return nil, errors.Errorf("unable to format spec %v (%T)", spec, spec)
}

func formatVar(node ast.Spec, obj types.Object) (*HoverInformation, error) {
	var fieldList *ast.FieldList
	if spec, ok := node.(*ast.TypeSpec); ok {
		switch t := spec.Type.(type) {
		case *ast.StructType:
			fieldList = t.Fields
		case *ast.InterfaceType:
			fieldList = t.Methods
		}
	}
	// If we have a struct or interface declaration,
	// we need to match the object to the corresponding field or method.
	if fieldList != nil {
		for i := 0; i < len(fieldList.List); i++ {
			field := fieldList.List[i]
			if field.Pos() <= obj.Pos() && obj.Pos() <= field.End() {
				if field.Doc.Text() != "" {
					return &HoverInformation{source: obj, comment: field.Doc}, nil
				} else if field.Comment.Text() != "" {
					return &HoverInformation{source: obj, comment: field.Comment}, nil
				}
			}
		}
	}
	// If we weren't able to find documentation for the object.
	return &HoverInformation{source: obj}, nil
}


text:
/* istanbul ignore next */
(function IIFE() {
  'use strict';

  const chalk = require('chalk');

  if(!process.env.NODE_ENV) {
    console.log(chalk.red('No environment specified...') + chalk.blue('defaulting to \'development\''));
    process.env.NODE_ENV = 'development';
  }

  const express = require('express');
  <% if(mongoose) { %>const mongoose = require('mongoose');<% } %>

  const config = require('./config/environment');

  <% if(mongoose) { %>mongoose.connect(config.mongo.uri, config.mongo.options);

  mongoose.connection.on('error', function(err) {
    console.error('Mongo Error: ' + err);
  });<% } %>

  const app = express();
  const server = require('http').createServer(app);

  require('./config/express')(app);
  require('./routes')(app);

  server.listen(config.port, config.ip, function() {
    console.log('<%= appNameSlug %> listening on %d in %s mode', config.port, app.get('env'));
  });

  exports = module.exports = app;
})();