text:
// The MIT License (MIT)
//
// Copyright (c) 2015 Rasmus Mikkelsen
// https://github.com/rasmus/Helpz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Owin;

namespace Helpz.HttpMock
{
    public interface IHttpMock : IDisposable
    {
        Uri Uri { get; }

        void Mock(HttpMethod httpMethod, string path, Func<IOwinContext, Task> handler);
        void Mock(HttpMethod httpMethod, string path, HttpStatusCode httpStatusCode);
        void Mock(HttpMethod httpMethod, string path, string response);
        void Mock(HttpMethod httpMethod, string path, Func<Request, Response> action);
    }
}


text:
/**
 * Autogenerated by Thrift Compiler (0.8.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Thrift;
using Thrift.Collections;
using Thrift.Protocol;
using Thrift.Transport;
namespace Apaf.NFSdb.TestShared.Model
{

  [Serializable]
  public partial class Quote : TBase
  {
    private long _timestamp;
    private string _sym;
    private double _bid;
    private double _ask;
    private int _bidSize;
    private int _askSize;
    private string _mode;
    private string _ex;

    public long Timestamp
    {
      get
      {
        return _timestamp;
      }
      set
      {
        __isset.timestamp = true;
        this._timestamp = value;
      }
    }

    public string Sym
    {
      get
      {
        return _sym;
      }
      set
      {
        __isset.sym = true;
        this._sym = value;
      }
    }

    public double Bid
    {
      get
      {
        return _bid;
      }
      set
      {
        __isset.bid = true;
        this._bid = value;
      }
    }

    public double Ask
    {
      get
      {
        return _ask;
      }
      set
      {
        __isset.ask = true;
        this._ask = value;
      }
    }

    public int BidSize
    {
      get
      {
        return _bidSize;
      }
      set
      {
        __isset.bidSize = true;
        this._bidSize = value;
      }
    }

    public int AskSize
    {
      get
      {
        return _askSize;
      }
      set
      {
        __isset.askSize = true;
        this._askSize = value;
      }
    }

    public string Mode
    {
      get
      {
        return _mode;
      }
      set
      {
        __isset.mode = true;
        this._mode = value;
      }
    }

    public string Ex
    {
      get
      {
        return _ex;
      }
      set
      {
        __isset.ex = true;
        this._ex = value;
      }
    }

    public Isset __isset;
    [Serializable]
    public struct Isset {
      public bool timestamp;
      public bool sym;
      public bool bid;
      public bool ask;
      public bool bidSize;
      public bool askSize;
      public bool mode;
      public bool ex;
    }

    public Quote() {
    }

    public void Read (TProtocol iprot)
    {
      TField field;
      iprot.ReadStructBegin();
      while (true)
      {
        field = iprot.ReadFieldBegin();
        if (field.Type == TType.Stop) {
          break;
        }
        switch (field.ID)
        {
          case 1:
            if (field.Type == TType.I64) {
              Timestamp = iprot.ReadI64();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 2:
            if (field.Type == TType.String) {
              Sym = iprot.ReadString();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 3:
            if (field.Type == TType.Double) {
              Bid = iprot.ReadDouble();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 4:
            if (field.Type == TType.Double) {
              Ask = iprot.ReadDouble();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 5:
            if (field.Type == TType.I32) {
              BidSize = iprot.ReadI32();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 6:
            if (field.Type == TType.I32) {
              AskSize = iprot.ReadI32();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 7:
            if (field.Type == TType.String) {
              Mode = iprot.ReadString();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          case 8:
            if (field.Type == TType.String) {
              Ex = iprot.ReadString();
            } else {
              TProtocolUtil.Skip(iprot, field.Type);
            }
            break;
          default:
            TProtocolUtil.Skip(iprot, field.Type);
            break;
        }
        iprot.ReadFieldEnd();
      }
      iprot.ReadStructEnd();
    }

    public void Write(TProtocol oprot) {
      TStruct struc = new TStruct("Quote");
      oprot.WriteStructBegin(struc);
      TField field = new TField();
      if (__isset.timestamp) {
        field.Name = "timestamp";
        field.Type = TType.I64;
        field.ID = 1;
        oprot.WriteFieldBegin(field);
        oprot.WriteI64(Timestamp);
        oprot.WriteFieldEnd();
      }
      if (Sym != null && __isset.sym) {
        field.Name = "sym";
        field.Type = TType.String;
        field.ID = 2;
        oprot.WriteFieldBegin(field);
        oprot.WriteString(Sym);
        oprot.WriteFieldEnd();
      }
      if (__isset.bid) {
        field.Name = "bid";
        field.Type = TType.Double;
        field.ID = 3;
        oprot.WriteFieldBegin(field);
        oprot.WriteDouble(Bid);
        oprot.WriteFieldEnd();
      }
      if (__isset.ask) {
        field.Name = "ask";
        field.Type = TType.Double;
        field.ID = 4;
        oprot.WriteFieldBegin(field);
        oprot.WriteDouble(Ask);
        oprot.WriteFieldEnd();
      }
      if (__isset.bidSize) {
        field.Name = "bidSize";
        field.Type = TType.I32;
        field.ID = 5;
        oprot.WriteFieldBegin(field);
        oprot.WriteI32(BidSize);
        oprot.WriteFieldEnd();
      }
      if (__isset.askSize) {
        field.Name = "askSize";
        field.Type = TType.I32;
        field.ID = 6;
        oprot.WriteFieldBegin(field);
        oprot.WriteI32(AskSize);
        oprot.WriteFieldEnd();
      }
      if (Mode != null && __isset.mode) {
        field.Name = "mode";
        field.Type = TType.String;
        field.ID = 7;
        oprot.WriteFieldBegin(field);
        oprot.WriteString(Mode);
        oprot.WriteFieldEnd();
      }
      if (Ex != null && __isset.ex) {
        field.Name = "ex";
        field.Type = TType.String;
        field.ID = 8;
        oprot.WriteFieldBegin(field);
        oprot.WriteString(Ex);
        oprot.WriteFieldEnd();
      }
      oprot.WriteFieldStop();
      oprot.WriteStructEnd();
    }

    public override string ToString() {
      StringBuilder sb = new StringBuilder("Quote(");
      sb.Append("Timestamp: ");
      sb.Append(Timestamp);
      sb.Append(",Sym: ");
      sb.Append(Sym);
      sb.Append(",Bid: ");
      sb.Append(Bid);
      sb.Append(",Ask: ");
      sb.Append(Ask);
      sb.Append(",BidSize: ");
      sb.Append(BidSize);
      sb.Append(",AskSize: ");
      sb.Append(AskSize);
      sb.Append(",Mode: ");
      sb.Append(Mode);
      sb.Append(",Ex: ");
      sb.Append(Ex);
      sb.Append(")");
      return sb.ToString();
    }

  }

}

redpajama_set_name: RedPajamaGithub


text:
package com.net2plan.examples.ocnbook.onlineSim;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.google.common.collect.ImmutableMap;
import com.net2plan.examples.general.onlineSim.OnlineTestUtils;
import com.net2plan.examples.general.onlineSim.Online_evGen_doNothing;
import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.simulation.IEventGenerator;
import com.net2plan.interfaces.simulation.IEventProcessor;
import com.net2plan.utils.Constants.RoutingType;
import com.net2plan.utils.InputParameter;

public class Online_evProc_congControlAndBackpressureRoutingDualDecompTest
{
	private NetPlan np;
	@Rule
    public TemporaryFolder temporalDirectoryTests= new TemporaryFolder();
	private final static double TIMEPERSIMULATIONINSECONDS = -1;

	@Before
	public void setUp() throws Exception
	{
		this.np = new NetPlan (new File ("src/test/resources/data/networkTopologies/example4nodes.n2p"));
		np.setTrafficMatrix(new NetPlan (new File ("src/test/resources/data/trafficMatrices/tm4nodes.n2p")).getMatrixNode2NodeOfferedTraffic() , RoutingType.SOURCE_ROUTING);
	}

	@After
	public void tearDown() throws Exception
	{
		np.checkCachesConsistency();
	}

	@Test
	public void test()
	{
		final IEventGenerator generator = new Online_evGen_doNothing();
		final IEventProcessor processor = new Online_evProc_congControlAndBackpressureRoutingDualDecomp();

		final Map<String,String> simulationParameters = new HashMap<> ();
		simulationParameters.put("disableStatistics" , "false");
		simulationParameters.put("refreshTime" , "1");
		simulationParameters.put("simEvents" , "-1");
		simulationParameters.put("transitoryEvents" , "-1");
		simulationParameters.put("transitoryTime" , "" + (TIMEPERSIMULATIONINSECONDS == -1? -1 : TIMEPERSIMULATIONINSECONDS/2));
		simulationParameters.put("simTime" , "" + TIMEPERSIMULATIONINSECONDS);
		final Map<String,String> net2planParameters = ImmutableMap.of("precisionFactor" , "0.001");

		final Map<String,List<String>> generatorParameters = new HashMap <>();
		final List<Map<String,String>> testsParamGenerator = InputParameter.getCartesianProductOfParameters (generatorParameters);
		for (Map<String,String> paramsGeneratorChangingThisTest : testsParamGenerator)
		{
			final Map<String,String> allParamsGeneratorThisTest = InputParameter.getDefaultParameters(generator.getParameters());
			allParamsGeneratorThisTest.putAll(paramsGeneratorChangingThisTest);

			/* Create the processor parameters */
			final Map<String,List<String>> processorParameters = new HashMap <>();

			processorParameters.put("simulation_outFileNameRoot" , Arrays.asList(temporalDirectoryTests.getRoot().getAbsolutePath() + "/rootOutput"));
			final List<Map<String,String>> testsParamProcessor = InputParameter.getCartesianProductOfParameters (processorParameters);

			for (Map<String,String> paramsProcessorChangingThisTest : testsParamProcessor)
			{
				final Map<String,String> allParamsProcessorThisTest = InputParameter.getDefaultParameters(processor.getParameters());
				allParamsProcessorThisTest.putAll(paramsProcessorChangingThisTest);
				System.out.println(allParamsProcessorThisTest);

				final NetPlan npInput = np.copy ();
				final NetPlan npOutput = np.copy ();
				try
				{
					new OnlineTestUtils().runSimulation(npOutput , generator , processor , simulationParameters , net2planParameters ,
							allParamsGeneratorThisTest , allParamsProcessorThisTest , TIMEPERSIMULATIONINSECONDS);
				} catch (UnsatisfiedLinkError e)
				{
					System.err.println(this.getClass().getName() + ": IPOPT_NOT_FOUND_ERROR");
					return;
				}
				checkValidity (npInput , npOutput , allParamsGeneratorThisTest);
			}
		}
	}

	private void checkValidity (NetPlan npInput , NetPlan npOutput , Map<String,String> params)
	{
		assertTrue (npOutput.getVectorDemandOfferedTraffic().zSum() > 1);
		assertTrue (npOutput.getVectorLinkCapacity().zSum() > 1);
		assertEquals (npOutput.getVectorDemandBlockedTraffic().zSum() , 0 , 2.5);
		assertEquals (npOutput.getVectorLinkOversubscribedTraffic().zSum() , 0 , 3);
		assertTrue (npOutput.getVectorDemandOfferedTraffic().zSum() > 1);
	}
}


text:
<?php

declare(strict_types=1);

namespace bizley\migration\table;

interface PrimaryKeyColumnInterface extends ColumnInterface
{
}


text:
package com.facebook.LinkBench.distributions;

/**
 * This code was derived and modified from the Apache Commons
 * Math 3.0 source release and modified for use in LinkBench
 *
 *  @author tarmstrong
 */
import org.apache.commons.math3.util.FastMath;

public class Harmonic {
  /**
   * Calculates the Nth generalized harmonic number. See
   * Harmonic
   * Series.
   *
   * @param n Term in the series to calculate (must be larger than 1)
   * @param m Exponent (special case {@code m = 1} is the harmonic series).
   * @return the nth generalized harmonic number.
   */
  public static double generalizedHarmonic(final long n, final double m) {
      double value = 0;
      for (long k = n; k > 0; --k) {
          value += 1.0 / FastMath.pow(k, m);
      }
      return value;
  }
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

  <title>web.server.api.SetSessionVar</title>
  <link href="css/style.css" rel="stylesheet" type="text/css">
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

    Concept Framework 2.2 documentation
  	Contents | Index

web.server.api.SetSessionVar

     Name
     Version
     Deprecated

     SetSessionVar
     version 1.0
     no

Prototype:

nothing SetSessionVar(string varname, string var_value)

Parameters:

		   	   varname

		   	   the session variable name

		   	   var_value

		   	   the session variable value

Description:

Sets session value for the given variable name.

Example:

import 'web.server.api'

/////////////////////////////////////////////////////////////////////
//
// Settings for Apache ... copy the following paragraph to the end
// of httpd.conf in your Apache installation directory, and replace
// "C:/Distribution/Bin/" with your path to concept Disitrbution
//  directory
//
/////////////////////////////////////////////////////////////////////
//
// ScriptAlias /con/ "c:/Distribution/Bin/"
// AddType application/x-httpd-con .con
// AddType application/x-httpd-con .csp
// Action application/x-httpd-con "/con/concept-cgi.exe"
//
/////////////////////////////////////////////////////////////////////

class Main {
	function Main() {
		var SESSID=SessionStart();

		if (WebVar("action")=="destroy")
			SessionDestroy();
		else {
			ContentType("text/html");
			echo "Server software : "+ ServerVar("SERVER_SOFTWARE") + "<br>";
			echo "Server name : "+ ServerVar("SERVER_NAME") + "<br>";
			echo "Gateway interface : "+ ServerVar("GATEWAY_INTERFACE") + "<br>";
			echo "Server protocol : "+ ServerVar("SERVER_PROTOCOL") + "<br>";
			echo "Server port : "+ ServerVar("SERVER_PORT") + "<br>";
			echo "Request method : "+ ServerVar("REQUEST_METHOD") + "<br>";
			echo "Path info : "+ ServerVar("PATH_INFO") + "<br>";
			echo "Path translated : "+ ServerVar("PATH_TRANSLATED") + "<br>";
			echo "Script name : "+ ServerVar("SCRIPT_NAME") + "<br>";
			echo "Query string : "+ ServerVar("QUERY_STRING") + "<br>";
			echo "Remote host : "+ ServerVar("REMOTE_HOST") + "<br>";
			echo "Remote address : "+ ServerVar("REMOTE_ADDR") + "<br>";
			echo "Authentification type : "+ ServerVar("AUTH_TYPE") + "<br>";
			echo "Remote user : "+ ServerVar("REMOTE_USER") + "<br>";
			echo "Remote ident : "+ ServerVar("REMOTE_IDENT") + "<br>";
			echo "<b>Session ID</b> : " + SESSID;
			echo "<br>";
			echo "<b>Action</b>=" + WebVar("action");
			echo "<br>";
			echo "<b>Action (session)</b>=" + SessionVar("Action");
			SetSessionVar("Action",WebVar("action"));
		}

		SessionDone();
	}
}

Returns:

Returns nothing.

Documented by Eduard Suica, generation time: Sun Jan 27 18:15:18 2013
 GMT	(c)2013 Devronium Applications


text:
layout: default
---

# Changelog for version 0.0.3-alpha.1 (05/25/2014)

- Updated example walkthrough and `spouse_example`
- Added python utility `ddlib` for text manipulation (need exporting PYTHONPATH, usage see its pydoc)
- Added utility script `util/extractor_input_writer.py` to sample extractor inputs
- Updated `nlp_extractor` format (use `sentence_offset`, textual sentence_id)
- Cleaned up unused datastore code
- Update templates
- Bug fixes

# Changelog for version 0.0.3-alpha (05/07/2014)

- **Non-backward-compatible syntax change**: Developers must include `id` column with type `bigint` in any table containing *variables*, but they **MUST NOT use this column** anywhere. This column is preserved for learning and inference, and all values will be erased and reassigned in grounding phase.

- **Non-backward-compatible functionality change**: DeepDive is no longer responsible for any automatic assignment of sequential variable IDs. You may use `examples/spouse_example/scripts/fill_sequence.sh` for this task.

- **Updated dependency requirement**: requires JDK 7 or higher.

- Supported four new types of extractors. See documentation for details:
  - [tsv_extractor]({{site.baseurl}}/doc/extractors.html#tsv_extractor)
  - [plpy_extractor]({{site.baseurl}}/doc/extractors.html#plpy_extractor)
  - [sql_extractor]({{site.baseurl}}/doc/extractors.html#sql_extractor)
  - [cmd_extractor]({{site.baseurl}}/doc/extractors.html#cmd_extractor)

- Even faster factor graph grounding and serialization using better optimized SQL.

- The previous default Java sampler is no longer supported. Made C++ sampler as the default sampler.

- New configuration supported: `pipeline.relearn_from` to skip extraction and grounding, only perform learning and inference with a previous version. Useful for tuning sampler arguments.

- New configuration supported: `inference.skip_learning` to use weights learned in the last execution.

- New configuration supported: `inference.weight_table` to fix factor weights in a table and skip learning. The table is specified by factor description and weights. This table can be results from one execution of DeepDive, or manually assigned, or a combination of them. It is useful for learning once and using learned model for later inference tasks.

- Supported manual holdout by a [holdout query]({{site.baseurl}}/doc/calibration.html#custom_holdout).

- Updated `spouse_example` with implementations in different styles of extractors.

- The nlp_extractor example has changed table requirements and usage. See [HERE]({{site.baseurl}}/doc/walkthrough.html#nlp_extractor).

- In `db.default` configuration, users should define `dbname`, `host`, `port` and `user`. If not defined, by default system will use environmental variables `DBNAME`,`PGHOST`, `PGPORT` and `PGUSER` accordingly.

- Fixed all examples.
- Updated documentation.
- Print SQL query execution plans for extractor inputs.
- Skip grounding, learning and inference if no factors are active.
- If using GreenPlum, users should add `DISTRIBUTED BY` clause in all `CREATE TABLE` commands. Do not use variable id as distribution key. Do not use distribution key that is not initially assigned.


text:
<?php
require 'fibonacci.php';

class FibonacciTest extends PHPUnit_Framework_TestCase{
    public function testCeroFibonacci(){
        $this->assertEquals(fibonacci(0), 0);
        $this->assertEquals(fibonacci_iterative(0), 0);
    }
    public function testPositiveNumberFibonnacci(){
        // Given the next order
        // Keys     [0..14]
        // Values   [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377]
        $this->assertEquals(fibonacci(14), 377);
        $this->assertEquals(fibonacci_iterative(14), 377);
    }
}


text:
package pl.mmorpg.prototype.server.resources;

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

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;

import pl.mmorpg.prototype.server.ServerSettings;
import pl.mmorpg.prototype.server.exceptions.GameException;
import pl.mmorpg.prototype.server.headless.NullBatch;

public class Assets
{
	private static Map<String, Class<?>> classTypes = new HashMap<String, Class<?>>();
	private static AssetManager assets = new AssetManager();
	private static BitmapFont font = new BitmapFont();
	private static Batch batch;

	static
	{
		if (ServerSettings.isHeadless)
			batch = new NullBatch();
		else
			batch = new SpriteBatch();
	}

	public static void loadAssets()
	{
		assets.setLoader(TiledMap.class, new TmxMapLoader());
		addClassTypes();
		loadAll();
	}

	private static void addClassTypes()
	{
		classTypes.put("png", Texture.class);
		classTypes.put("jpg", Texture.class);
		classTypes.put("bmp", Texture.class);
		classTypes.put("gif", Texture.class);
		classTypes.put("mp3", Music.class);
		classTypes.put("ogg", Sound.class);
		classTypes.put("tmx", TiledMap.class);
	}

	private static void loadAll()
	{
		Set<String> files = ReflectionResourceUtils.getClasspathResources(classTypes.keySet(), Assets::isValidResourcePath);
		for (String file : files)
			assets.load(file, getClassFromPath(file));

		assets.finishLoading();
	}

	private static boolean isValidResourcePath(String resourcePath)
	{
		return !resourcePath.startsWith("com") && !resourcePath.startsWith("org") && !resourcePath.startsWith("junit")
				&& !resourcePath.startsWith("lombok");
	}

	private static Class<?> getClassFromPath(String path)
	{
		String extension = getExtension(path);
		if (classTypes.containsKey(extension))
			return classTypes.get(extension);
		else
			throw new UnknownExtensionException(extension);
	}

	private static String getExtension(String path)
	{
		int extensionStartIndex = path.lastIndexOf('.') + 1;
		return path.substring(extensionStartIndex);
	}

	public static <T> T get(String fileName)
	{
		return assets.get(fileName);
	}

	public static <T> T get(String fileName, Class<T> classType)
	{
		return assets.get(fileName, classType);
	}

	public static void dispose()
	{
		assets.dispose();
		font.dispose();
	}

	public static BitmapFont getFont()
	{
		return font;
	}

	private static class UnknownExtensionException extends GameException
	{
		public UnknownExtensionException(String extension)
		{
			super("Extension " + extension + " is not recognized");
		}
	}

	public static Batch getBatch()
	{
		return batch;
	}

}


text:
module.exports = {

  features: {
    client: 'sqlite3',
    connection: {
      filename: './db/features.sqlite3'
    },
    migrations: {
      directory: './db/migrations',
      tableName: 'knex_migrations'
    },
    seeds: {
      directory: './db/seeds' // relative path from the tests/ folder!
    },
    useNullAsDefault: true
  },

  test: {
    client: 'sqlite3',
    connection: {
      filename: '../db/test.sqlite3'
    },
    migrations: {
      directory: './db/migrations',
      tableName: 'knex_migrations'
    },
    seeds: {
      directory: '../db/seeds' // relative path from the tests/ folder!
    },
    useNullAsDefault: true
  },

  development: {
    client: 'sqlite3',
    connection: {
      filename: './db/dev.sqlite3'
    },
    migrations: {
      directory: './db/migrations',
      tableName: 'knex_migrations'
    },
    seeds: {
      directory: './db/seeds'
    },
    useNullAsDefault: true
  },

  staging: {
    client: 'postgresql',
    connection: process.env.DATABASE_URL,
    migrations: {
      tableName: 'knex_migrations'
    }
  },

  production: {
    client: 'postgresql',
    connection: process.env.DATABASE_URL,
    migrations: {
      tableName: 'knex_migrations'
    }
  }

};


text:
@import SafariServices;
#import <AVFoundation/AVFoundation.h>

@interface QRCodeViewController : UIViewController <AVCaptureMetadataOutputObjectsDelegate>

@end


text:
package lint

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"text/template"

	"github.com/Masterminds/sprig"
)

// Templates lints a chart's templates.
func Templates(basepath string) (messages []Message) {
	messages = []Message{}
	path := filepath.Join(basepath, "templates")
	if fi, err := os.Stat(path); err != nil {
		messages = append(messages, Message{Severity: WarningSev, Text: "No templates"})
		return
	} else if !fi.IsDir() {
		messages = append(messages, Message{Severity: ErrorSev, Text: "'templates' is not a directory"})
		return
	}

	tpl := template.New("tpl").Funcs(sprig.TxtFuncMap())

	err := filepath.Walk(basepath, func(name string, fi os.FileInfo, e error) error {
		// If an error is returned, we fail. Non-fatal errors should just be
		// added directly to messages.
		if e != nil {
			return e
		}
		if fi.IsDir() {
			return nil
		}

		data, err := ioutil.ReadFile(name)
		if err != nil {
			messages = append(messages, Message{
				Severity: ErrorSev,
				Text:     fmt.Sprintf("cannot read %s: %s", name, err),
			})
			return nil
		}

		// An error rendering a file should emit a warning.
		newtpl, err := tpl.Parse(string(data))
		if err != nil {
			messages = append(messages, Message{
				Severity: ErrorSev,
				Text:     fmt.Sprintf("error processing %s: %s", name, err),
			})
			return nil
		}
		tpl = newtpl
		return nil
	})

	if err != nil {
		messages = append(messages, Message{Severity: ErrorSev, Text: err.Error()})
	}

	return
}


text:
from bottle import debug, request, response, redirect, BaseRequest, static_file

import logging
import json
import redis
import re

import sys
import os

from jinja2 import contextfunction
from pkg_resources import resource_filename

from six.moves.urllib.parse import urlsplit, urljoin, unquote, urlencode

from pywb.rewrite.templateview import JinjaEnv
from webrecorder.utils import load_wr_config, init_logging, spawn_once

from webrecorder.apiutils import APIBottle, wr_api_spec
from webrecorder.admincontroller import AdminController
from webrecorder.contentcontroller import ContentController
from webrecorder.snapshotcontroller import SnapshotController
from webrecorder.websockcontroller import WebsockController
from webrecorder.recscontroller import RecsController
from webrecorder.collscontroller import CollsController
from webrecorder.listscontroller import ListsController
#from webrecorder.logincontroller import LoginController
from webrecorder.bugreportcontroller import BugReportController
from webrecorder.usercontroller import UserController
from webrecorder.downloadcontroller import DownloadController
from webrecorder.uploadcontroller import UploadController
from webrecorder.appcontroller import AppController
from webrecorder.autocontroller import AutoController
from webrecorder.behaviormgr import BehaviorMgr

from webrecorder.browsermanager import BrowserManager
from webrecorder.solrmanager import SolrManager

from webrecorder.webreccork import WebRecCork

from webrecorder.session import Session, RedisSessionMiddleware

from webrecorder.models.access import SessionAccessCache
from webrecorder.models.usermanager import UserManager
from webrecorder.models.datshare import DatShare

from webrecorder.rec.storage import storagepaths

from webrecorder.basecontroller import BaseController

from wsgiprox.wsgiprox import WSGIProxMiddleware

from webrecorder.standalone.assetsutils import default_build

# ============================================================================
class MainController(BaseController):
    ALL_CONTROLLERS = [DownloadController,
                       UploadController,
                       AppController,
                       #LoginController,
                       UserController,
                       AdminController,
                       BugReportController,
                       SnapshotController,
                       WebsockController,
                       RecsController,
                       CollsController,
                       ListsController,
                       AutoController,
                       BehaviorMgr,
                      ]

    def __init__(self, redis_url=None):
        self._init_logging()

        if getattr(sys, 'frozen', False):
            self.static_root = os.path.join(sys._MEIPASS, 'webrecorder', 'static/')
        else:
            self.static_root = resource_filename('webrecorder', 'static/')

            # only launch if running in place, not from installed package
            if '.egg' not in __file__:
                spawn_once(default_build, worker=1, force_build=False)

        BaseRequest.MEMFILE_MAX = 500000 # 500kb

        bottle_app = APIBottle()
        self.bottle_app = bottle_app

        # JSON encoding for datetime objects
        # self.bottle_app.install(JSONPlugin(json_dumps=lambda s: json.dumps(s, cls=CustomJSONEncoder)))

        config = load_wr_config()

        # Init Redis
        if not redis_url:
            redis_url = os.environ['REDIS_BASE_URL']

        self.redis = redis.StrictRedis.from_url(redis_url, decode_responses=True)
        browser_redis = redis.StrictRedis.from_url(os.environ['REDIS_BROWSER_URL'], decode_responses=True)

        session_redis = redis.StrictRedis.from_url(os.environ['REDIS_SESSION_URL'])

        self.content_error_redirect = os.environ.get('CONTENT_ERROR_REDIRECT')

        # Init Jinja
        jinja_env = self.init_jinja_env(config)

        # Init Cork
        cork = WebRecCork.create_cork(self.redis, config)

        # User Manager
        user_manager = UserManager(redis=self.redis,
                                   cork=cork,
                                   config=config)

        # Init Browser Mgr
        browser_mgr = BrowserManager(config, browser_redis, user_manager)

        # Init Solr Mgr
        if os.environ.get('SEARCH_AUTO') == '1':
            solr_mgr = SolrManager(config)
        else:
            solr_mgr = None

        # Init Dat Share
        DatShare.dat_share = DatShare(self.redis)

        # Init Content Loader/Rewriter
        content_app = ContentController(app=bottle_app,
                                        jinja_env=jinja_env,
                                        user_manager=user_manager,
                                        config=config,
                                        browser_mgr=browser_mgr,
                                        solr_mgr=solr_mgr,
                                        redis=self.redis,
                                        cork=cork)

        # Init Sesion temp_prefix
        Session.temp_prefix = config['temp_prefix']

        kwargs = dict(app=bottle_app,
                      jinja_env=jinja_env,
                      user_manager=user_manager,
                      browser_mgr=browser_mgr,
                      solr_mgr=solr_mgr,
                      content_app=content_app,
                      cork=cork,
                      redis=self.redis,
                      session_redis=session_redis,
                      config=config)

        # Init Core app controllers
        for controller_type in self.ALL_CONTROLLERS:
            x = controller_type(**kwargs)

        # Set Error Handler
        bottle_app.default_error_handler = self.make_err_handler(
                                            bottle_app.default_error_handler)

        final_app = RedisSessionMiddleware(bottle_app,
                                           cork,
                                           session_redis,
                                           config,
                                           access_cls=SessionAccessCache,
                                           access_redis=self.redis)

        final_app = WSGIProxMiddleware(final_app, '/_proxy/',
                                       proxy_host='webrecorder.proxy',
                                       proxy_options=self._get_proxy_options())

        kwargs['app'] = final_app

        super(MainController, self).__init__(**kwargs)

        self.browser_mgr = browser_mgr
        self.content_app = content_app

        wr_api_spec.build_api_spec()

    def _get_proxy_options(self):
        opts = {'ca_name': 'Webrecorder HTTPS Proxy CA'}
        if getattr(sys, 'frozen', False):
            opts['ca_file_cache'] = {}
        else:
            opts['ca_file_cache'] = './proxy-certs/webrecorder-ca.pem'

        # disable CONNECT keepalive for now
        opts['keepalive_max'] = -1

        return opts

    def init_jinja_env(self, config):
        assets_path = os.path.expandvars(config['assets_path'])
        packages = [os.environ.get('WR_TEMPLATE_PKG', 'webrecorder'), 'pywb']

        jinja_env_wrapper = JinjaEnv(assets_path=assets_path,
                                     packages=packages,
                                     env_template_params_key='webrec.template_params')

        jinja_env = jinja_env_wrapper.jinja_env

        jinja_env.globals['metadata'] = config.get('metadata', {})
        jinja_env.globals['static_path'] = 'static'

        def get_coll(context):
            return context.get('coll', '')

        def get_collection(context):
            coll = context.get('coll', '')
            coll_name = context.get('coll_name', '')
            user = get_user(context)
            return get_user(context).get_collection_by_id(coll, coll_name)

        def get_user(context):
            u = context.get('user', '')
            if not u:
                u = context.get('curr_user', '')
            return self.user_manager.all_users.make_user(u)

        def get_browsers():
            return self.browser_mgr.get_browsers()

        def get_app_host():
            return self.app_host or 'http://localhost:8089'

        def get_content_host():
            return self.content_host or 'http://localhost:8092'

        def get_num_collections():
            count = self.access.session_user.num_total_collections()
            return count

        def get_archives():
            return self.content_app.client_archives

        @contextfunction
        def is_public(context):
            return get_collection(context).is_public()

        @contextfunction
        def can_admin(context):
            return self.access.can_admin_coll(get_collection(context))

        @contextfunction
        def is_owner(context):
            res = self.access.is_curr_user(get_user(context))
            return res

        @contextfunction
        def can_write(context):
            res = self.access.can_write_coll(get_collection(context))
            return res

        @contextfunction
        def can_read(context):
            res = self.access.can_read_coll(get_collection(context))

        @contextfunction
        def is_anon(context):
            return self.access.session_user.is_anon()

        def get_announce_list():
            announce_list = os.environ.get('ANNOUNCE_MAILING_LIST', False)
            if announce_list:
                return announce_list
            return False

        @contextfunction
        def get_path(context, user, coll=None, rec=None):
            return self.get_path(user, coll, rec)

        @contextfunction
        def get_body_class(context, action):
            return self.get_body_class(context, action)

        @contextfunction
        def get_share_url(context):
            url = context.get('url')
            br = context.get('browser', '')
            user = context.get('user')
            coll = context.get('coll')
            host = self.app_host + ('' if self.app_host.endswith('/') else '/')
            ts = context.get('timestamp', '')

            if br != '':
                br = '$br:'+br

            return 'https://{host}{user}/{coll}/{ts}{browser}/{url}'.format(
                host=host,
                user=user,
                coll=coll,
                ts=ts,
                browser=br,
                url=url
            )

        @contextfunction
        def get_embed_url(context):
            host = self.app_host + ('' if self.app_host.endswith('/') else '/')
            url = context.get('url')
            br = context.get('browser', '')
            user = context.get('user')
            coll = context.get('coll')
            ts = context.get('timestamp', '')

            if br != '':
                br = '$br:'+br

            return 'https://{host}_embed/{user}/{coll}/{ts}{browser}/{url}'.format(
                host=host,
                user=user,
                coll=coll,
                ts=ts,
                browser=br,
                url=url
            )

        @contextfunction
        def get_recs_for_coll(context):
            collection = get_collection(context)

            return [{'ts': r['timestamp'], 'url': r['url'], 'br': r.get('browser', '')}
                    for r in collection.list_pages()]

        @contextfunction
        def is_out_of_space(context):
            return self.access.session_user.is_out_of_space()

        def trunc_url_expand(value):
            """ Truncate querystrings, appending an ellipses, expand on click
            """
            trunc_value = '?...'
            return re.sub(r'(\?.*)', trunc_value, value)

        def trunc_url(value):
            """ Truncate querystrings, appending an ellipses
            """
            return re.sub(r'(\?.*)', '?...', value)

        def urldecode(value):
            """ Decode url-encoded value
            """
            return unquote(value)

        jinja_env.globals['can_admin'] = can_admin
        jinja_env.globals['can_write'] = can_write
        jinja_env.globals['can_read'] = can_read
        #jinja_env.globals['can_tag'] = can_tag
        jinja_env.globals['is_owner'] = is_owner
        jinja_env.globals['is_anon'] = is_anon
        #jinja_env.globals['is_beta'] = is_beta
        jinja_env.globals['is_public'] = is_public
        jinja_env.globals['get_announce_list'] = get_announce_list
        jinja_env.globals['get_path'] = get_path
        jinja_env.globals['get_body_class'] = get_body_class
        jinja_env.globals['get_share_url'] = get_share_url
        jinja_env.globals['get_embed_url'] = get_embed_url
        jinja_env.globals['get_recs_for_coll'] = get_recs_for_coll
        jinja_env.globals['get_app_host'] = get_app_host
        jinja_env.globals['get_content_host'] = get_content_host
        jinja_env.globals['get_num_collections'] = get_num_collections
        jinja_env.globals['get_archives'] = get_archives
        jinja_env.globals['is_out_of_space'] = is_out_of_space
        jinja_env.globals['get_browsers'] = get_browsers
        #jinja_env.globals['is_extractable'] = is_extractable
        #jinja_env.globals['get_tags'] = get_tags
        #jinja_env.globals['is_tagged'] = is_tagged
        #jinja_env.globals['get_tags_in_collection'] = get_tags_in_collection
        jinja_env.filters['trunc_url'] = trunc_url
        jinja_env.filters['trunc_url_expand'] = trunc_url_expand
        jinja_env.filters['urldecode'] = urldecode

        return jinja_env_wrapper

    def init_routes(self):
        @self.bottle_app.route(['//<url:re:.*>'])
        def empty(url=''):
            self.redirect('/' + url)

        @self.bottle_app.route(['/<user>//<url:re:.*>'])
        def empty2(user, url=''):
            self.redirect('/' + user + '/' + url)

        @self.bottle_app.route(['/static/<path:path>', '/static_cors/<path:path>'])
        def static_files(path):
            res = static_file(path, root=self.static_root)

            if 'HTTP_ORIGIN' in request.environ:
                self.set_options_headers(None, None, res)

            return res

        @self.bottle_app.route('/_message')
        def flash_message():
            message = request.query.getunicode('message', '')
            msg_type = request.query.getunicode('msg_type', '')
            self.flash_message(message, msg_type)
            return {}

        @self.bottle_app.route('/api/v1.yml')
        def get_api_spec_yaml():
            response.content_type = 'text/yaml'
            return wr_api_spec.get_api_spec_yaml(self.access.is_superuser())

        @self.bottle_app.route('/api/v1.json')
        def get_api_spec_json():
            response.content_type = 'application/json'
            return json.dumps(wr_api_spec.get_api_spec_dict(self.access.is_superuser()))

        @self.bottle_app.route('/<:re:.*>', method='ANY')
        def fallthrough():
            self._check_refer_redirect()

    def make_err_handler(self, default_err_handler):
        @self.jinja2_view('error.html', refresh_cookie=False)
        def error_view(out, **params):
            params['err'] = out
            return params

        def json_error(body_dict):
            response.content_type = 'application/json'
            res = json.dumps(body_dict)
            return res

        def err_handler(out):
            if out.status_code == 500:
                print(out.traceback)
            else:
                print(out)

            if out.status_code == 404 and self._check_refer_redirect():
                return

            # return html error view for any content errors
            if self.is_content_request() or out.status_code == 402 or 'wsgiprox.proxy_host' in request.environ:
                if self.content_error_redirect:
                    err_context = {'status': out.status_code,
                                   'error': out.body
                                  }

                    response.status = 303
                    redirect_url = self.content_error_redirect + '?' + urlencode(err_context)
                    response.set_header('Location', redirect_url)
                    return

                else:
                    if self._wrong_content_session_redirect():
                        return

                    return error_view(out)

            if isinstance(out.exception, dict):
                return json_error(out.exception)

            else:
                return json_error({'error': 'not_found'})

        return err_handler

    def _check_refer_redirect(self):
        referer = request.headers.get('Referer')
        if not referer:
            return

        if self.access.sesh.is_new():
            return

        if request.urlparts.path.startswith('/' + self.access.session_user.name):
            return

        if 'http' in request.urlparts.path or '///' in request.urlparts.path:
            return

        host = request.headers.get('Host')
        if host not in referer:
            return

        inx = referer[1:].find('http')
        if not inx:
            inx = referer[1:].find('///')
            if inx > 0:
                inx + 1

        if inx < 0:
            return

        url = referer[inx + 1:]
        host = referer[:inx + 1]

        orig_url = request.urlparts.path
        if request.urlparts.query:
            orig_url += '?' + request.urlparts.query

        full_url = host + urljoin(url, orig_url)

        response.status = 307
        response.set_header('Location', full_url)
        return True

    def _init_logging(self):
        # bottle debug
        debug(True)

        init_logging()