text:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Mandelbrot</title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            cursor: pointer;
            color: black;
        }
        * {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
    </style>
</head>
<body>

<canvas id="canvas"></canvas>

<script src="lib/three.min.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/dat.gui.min.js"></script>

<script type="x-shader/x-vertex" id="passthroughVS">
precision highp float;
attribute vec3 position;

void main() {
    gl_Position = vec4(position, 1.0);
}
</script>

<script type="x-shader/x-fragment" id="mandelbrotFS">
precision highp float;

// GLSL requires a compile-time constant upper limit for the number of iterations
#define maxIterations 2000
// variable number of maximum iterations used to break out of the loop
uniform int iterations;
// size of the viewport in pixels
uniform vec2 viewport;
// center of the view in the complex plane
uniform vec2 centerRe;
uniform vec2 centerIm;
// zoom factor, inverse of the visible range in the complex plane
uniform float zoom;
// switch to enable double precision emulation
uniform bool doubleEmulation;
// switch to enable 4x anti-aliasing
uniform bool antialiasing;
// switch to enable smooth coloring
uniform bool smoothColoring;
// variables used for color mapping
uniform vec3 colorFrequency;
uniform vec3 colorPhase;
uniform float colorExponent;

// escape threshold for the mandelbrot series
const float escape = 65536.0;

// constants
const float escape2 = escape*escape;
//const float oneOverLog2 = 1.0 / log(2.0);
const float oneOverLog2 = 1.4426950408889634073599246810019;

// normalizes screen coordinates
vec2 position(vec2 fragCoord)
{
    return (fragCoord / viewport - 0.5) * vec2(1.0, viewport.y / viewport.x);
}

// multiplication of values a and b with emulated double precision
vec2 mul(vec2 a, vec2 b)
{
    float r = a.x*b.y + a.y*b.x;
    return vec2(a.x*b.x, a.y*b.y + r);
}

// squared length of a complex number with emulated double precision
float lenSquared(vec2 re, vec2 im)
{
    return dot(mul(re, re) + mul(im, im), vec2(1.0));
}

// iterates the mandelbrot series with emulated double precision using two floats for each value
// currently very unstable, for some center positions it works good for some not at all
vec2 mandelbrot_emu(vec2 pos)
{
    vec2 cr = centerRe;
    vec2 ci = centerIm;
    // add the pixel offset to the small part
    cr.y += pos.x / zoom;
    ci.y += pos.y / zoom;
    vec2 zr = vec2(0.0);
    vec2 zi = vec2(0.0);
    for (int i = 0; i < maxIterations; i++)
    {
        if (i >= iterations) break;
        // z(n+1) = z(n)^2 + c
        vec2 re = mul(zr, zr) - mul(zi, zi);
        zi = 2.0 * mul(zr, zi);
        zr = re;
        zr += cr;
        zi += ci;
        float len2 = lenSquared(zr, zi);
        if (len2 > escape2) return vec2(float(i), len2);
    }
    return vec2(0.0);
}

// iterates the mandelbrot series with single precision
vec2 mandelbrot(vec2 pos)
{
    vec2 c = pos / zoom + vec2(centerRe.x, centerIm.x);
    vec2 z = vec2(0.0);
    for (int i = 0; i < maxIterations; i++)
    {
        if (i >= iterations) break;
        // z(n+1) = z(n)^2 + c
        float re = z.x*z.x - z.y*z.y;
        z.y = 2.0 * z.x * z.y;
        z.x = re;
        z += c;
        float len2 = z.x*z.x + z.y*z.y;
        if (len2 > escape2) return vec2(float(i), len2);
    }
    return vec2(0.0);
}

// fancy color oscillator
vec3 color(float iterations)
{
    return pow(-cos(iterations*colorFrequency + colorPhase)*0.5 + 0.5, vec3(colorExponent));
}

// get color for subpixel with given offset
vec3 get(vec2 offset)
{
    vec2 pos = position(gl_FragCoord.xy + offset);
    vec2 mandel;
    if (doubleEmulation)
    {
        mandel = mandelbrot_emu(pos);
    }
    else
    {
        mandel = mandelbrot(pos);
    }
    if (smoothColoring)
    {
        // source: https://en.wikipedia.org/wiki/Mandelbrot_set#Continuous_.28smooth.29_coloring
        float logZ = log(mandel.y) / 2.0;
        mandel.x += 1.0 - log(logZ * oneOverLog2) * oneOverLog2;
    }
    return color(mandel.x);
}

void main()
{
    vec2 a = vec2(0.0, 0.5);
    vec3 color = get(a.xx);
    if (antialiasing)
    {
        color += get(a.xy);
        color += get(a.yx);
        color += get(a.yy);
        color *= 0.25;
    }
    gl_FragColor = vec4(color, 1.0);
}
</script>

<script>

    var canvas, stats, gui, guiControllers;
    var renderer, scene, camera;
    var material, mesh;
    var parameters = {};
    var defaultParameters = {
        centerRe: -0.5,
        centerIm: 0,
        zoom: 0,
        targetZoom: 0.25,
        iterations: 256,
//        colorFrequency: "#101623",
//        colorFrequency: "#12151b",
        // red glow
//        colorFrequency: "#18181a",
//        colorPhase: "#ff0000",
        // white brown blue
        colorFrequency: "#090a0c",
        colorPhase: "#FFFFFF",
        colorExponent: 1.8,
        smoothColoring: true,
        antialiasing: true,
        doubleEmulation: false
    };

    function get(name) {
        return parameters[name];
    }

    function set(name, value) {
        parameters[name] = value;
        setUniform(name, value);
        requestRender();
        updateParameterGUI();
    }

    function reset() {
        for (var name in defaultParameters) {
            set(name, defaultParameters[name]);
        }
    }

    function setUniform(name, value) {
        // parse strings as color values
        if (typeof(value) == "string") value = new THREE.Color(value);
        // use two floats for the center position to increase precision
        if (name == "centerRe" || name == "centerIm") value = splitDouble(value);
        // set uniform on the shader material
        var uniforms = material.uniforms;
        if (!uniforms[name]) uniforms[name] = {};
        uniforms[name].value = value;
    }

    function splitDouble(input) {
        var split = new Float32Array(2);
        split[0] = input;
        split[1] = input - split[0];
        return split;
    }

    function initialize() {
        // append stats graph
        stats = new Stats();
        document.body.appendChild(stats.dom);
        // initialize renderer
        canvas = document.getElementById("canvas");
        renderer = new THREE.WebGLRenderer({ canvas: canvas });
        // initialize
        initializeScene();
        reset();
        initializeParameterGUI();
        addEventHandlers();
        windowResize();
    }

    function getShader(id) {
        return document.getElementById(id).textContent;
    }

    function initializeScene() {
        // most arguments are meaningless here as the projection and modelview matrix are not used in the shader
        camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 1, 3);
        camera.position.z = 2;
        // create the mandelbrot materials
        material = new THREE.RawShaderMaterial({
            vertexShader: getShader("passthroughVS"),
            fragmentShader: getShader("mandelbrotFS"),
            depthTest: false,
            depthWrite: false
        });
        // create a plane mesh for each material
        var plane = new THREE.PlaneGeometry(2, 2);
        mesh = new THREE.Mesh(plane, material);
        scene = new THREE.Scene();
        scene.add(camera);
        scene.add(mesh);
    }

    function addParameter(folder, name, options) {
        var c = folder.add(parameters, name);
        if (options) for (var o in options) c = c[o](options[o]);
        c.onChange(function () { set(name, parameters[name]); });
        return c;
    }

    function addColor(folder, name) {
        var c = folder.addColor(parameters, name);
        c.onChange(function () { set(name, parameters[name]); });
        return c;
    }

    function initializeParameterGUI() {
        gui = new dat.GUI();
        var mandel = gui.addFolder("view");
        var color = gui.addFolder("coloring");
        var common = gui.addFolder("common");
        var double = gui.addFolder("unstable double precision emulation");
        guiControllers = [
            addParameter(mandel, "centerRe", { step: 1e-6 }),
            addParameter(mandel, "centerIm", { step: 1e-6 }),
            addParameter(mandel, "targetZoom", { min: 0.01 }),
            addColor(color, "colorFrequency"),
            addColor(color, "colorPhase"),
            addParameter(color, "colorExponent", { min: 0.1, max: 20 }),
            addParameter(color, "smoothColoring"),
            addParameter(common, "iterations", { min: 2, max: 2000 }),
            addParameter(common, "antialiasing"),
            addParameter(double, "doubleEmulation")
        ];
        gui.add({ reset: reset }, "reset");
        common.open();
    }

    function updateParameterGUI() {
        // manually update the gui
        if (guiControllers) {
            for (var i in guiControllers) {
                guiControllers[i].updateDisplay();
            }
        }
    }

    var rendering = false;
    function requestRender() {
        if (rendering) return;
        rendering = true;
        requestAnimationFrame(render);
    }

    function render() {
        var targetZoom = get("targetZoom");
        var zoom = get("zoom");
        if (!floatAlmostEqual(zoom, targetZoom)) {
            zoom += (targetZoom - zoom) * 0.1;
            set("zoom", zoom)
        } else {
            // stop render loop
            rendering = false;
        }
        renderer.render(scene, camera);
        stats.update();
        if (rendering) {
            requestAnimationFrame(render);
        }
    }

    function floatAlmostEqual(a, b) {
        var epsilon = 0.001;
        return Math.abs(a-b)/ (Math.abs(a) + Math.abs(b)) < epsilon;
    }

    function addEventHandlers() {
        canvas.addEventListener("touchstart", touchStart);
        canvas.addEventListener("touchmove", touchMove);
        canvas.addEventListener("mousedown", mouseDown);
        canvas.addEventListener("mousemove", mouseMove);
        canvas.addEventListener("wheel", mouseWheel);
        window.addEventListener("resize", windowResize);
        window.addEventListener("scroll", preventMotion);
        window.addEventListener("touchmove", preventMotion);
    }

    var swipeGesture = false;
    var pinchGesture = false;
    var pinchGestureDistance = 0;
    var pinchGestureZoom = 0;
    var lastX = null;
    var lastY = null;

    function touchStart(e) {
        e.preventDefault();
        swipeGesture = e.touches.length == 1;
        pinchGesture = e.touches.length == 2;
        if (swipeGesture) {
            lastX = null;
            lastY = null;
        }
        if (pinchGesture) {
            pinchGestureDistance = touchDistance(e.touches[0], e.touches[1]);
            pinchGestureZoom = get("targetZoom");
        }
    }

    function touchDistance(a, b){
        var dx = a.screenX - b.screenX;
        var dy = a.screenY - b.screenY;
        return Math.sqrt(dx*dx + dy*dy);
    }

    function touchMove(e) {
        e.preventDefault();
        if (swipeGesture) {
            move(e.touches[0].screenX, e.touches[0].screenY);
        }
        if (pinchGesture) {
            var target = pinchGestureZoom * touchDistance(e.touches[0], e.touches[1]) / pinchGestureDistance;
            set("targetZoom", target);
        }
    }

    function mouseDown(e) {
        swipeGesture = e.buttons == 1;
        if (swipeGesture) {
            lastX = null;
            lastY = null;
        }
    }

    function mouseMove(e) {
        if (e.buttons != 1) swipeGesture = false;
        if (swipeGesture) {
            move(e.screenX, e.screenY);
        }
    }

    function move(x, y) {
        if (lastX != null && lastY != null) {
            var zoom = get("zoom");
            var centerRe = get("centerRe") - (x - lastX) / canvas.width / zoom;
            var centerIm = get("centerIm") + (y - lastY) / canvas.width / zoom;
            set("centerRe", centerRe);
            set("centerIm", centerIm);
        }
        lastX = x;
        lastY = y;
    }

    function mouseWheel(e) {
        var factor = 0.1;
        var target = get("targetZoom");
        var delta = e.wheelDelta || e.deltaY || e.detail;
        if (delta > 0) target *= 1 + factor;
        if (delta < 0) target *= 1 - factor;
        set("targetZoom", target);
    }

    function windowResize() {
        var w = window.innerWidth;
        var h = window.innerHeight;
        renderer.setSize(w, h);
        setUniform("viewport", new Float32Array([w, h]));
        requestRender();
    }

    function preventMotion(event) {
        window.scrollTo(0, 0);
        event.preventDefault();
        event.stopPropagation();
    }

    initialize();
    render();

</script>
</body>
</html>


text:
package geometry.hulls

import org.salgo.geometry.hulls.QuickHull3D
import org.salgo.geometry.structures.Point3D
import org.scalatest.{FunSuite, Matchers}

class QuickHullSpec3D extends FunSuite with Matchers {
  test("Hull 3D with no points") { QuickHull3D.solve(Traversable.empty[Point3D]) should have size 0 }
  test("Hull 3D with one points") { QuickHull3D.solve(Seq(Point3D(1,1,1))) should contain only Point3D(1,1,1) }
  test("Hull 3D with two points") { QuickHull3D.solve(Seq(Point3D(1,1,1), Point3D(1,2,3))) should contain theSameElementsAs Seq(Point3D(1,1,1), Point3D(1,2,3)) }
  test("Hull 3D with three points") { QuickHull3D.solve(Seq(Point3D(1,1,1), Point3D(1,2,3), Point3D(2,4,7))) should contain theSameElementsAs Seq(Point3D(1,1,1), Point3D(1,2,3), Point3D(2,4,7)) }
  test("Hull 3D for simple cloud") { QuickHull3D.solve(this.getPointsForSimpleCloud) should contain theSameElementsAs this.getExpectedPointsForSimpleCloud}
  test("Hull 3D for simple cloud with border point") { QuickHull3D.solve(this.getPointsForSimpleCloudWithBorderPoint) should contain theSameElementsAs this.getExpectedPointsForSimpleCloud}
  test("Hull 3D for complex cloud") { QuickHull3D.solve(this.getPointsForComplexCloud) should contain theSameElementsAs this.getExpectedPointsForComplexCloud}

  private def getPointsForSimpleCloud: Traversable[Point3D] = {
    Point3D((5,0,0),(0,-5,0),(-5,0,0),(0,0,4),(0,5,0),(0,0,5),(0,0,-5))
  }

  private def getPointsForSimpleCloudWithBorderPoint: Traversable[Point3D] = {
    Point3D((5,0,0),(0,-5,0),(-5,0,0),(0,0,4),(0,5,0),(0,0,5),(0,0,-5))
  }

  private def getExpectedPointsForSimpleCloud: Traversable[Point3D] = {
    Point3D((5,0,0),(0,-5,0),(-5,0,0),(0,5,0),(0,0,5),(0,0,-5))
  }

  private def getPointsForComplexCloud: Traversable[Point3D] = {
    Point3D((5,0,0),(0,-5,0),(2,1,-1),(-5,0,0),(1,1,1),(0,5,0),(-2,1,1),(0,0,5),(0,0,4),(0,0,-5))
  }

  private def getExpectedPointsForComplexCloud: Traversable[Point3D] = {
    Point3D((5,0,0),(0,-5,0),(-5,0,0),(0,5,0),(0,0,5),(0,0,-5))
  }
}

redpajama_set_name: RedPajamaGithub


text:
import 'zone.js'
import 'reflect-metadata'
import {NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {Timer} from './components/timer/component'
import {RouterModule} from '@angular/router'
import {FormsModule} from '@angular/forms'
import ScreenGames from './components/screen-games/component'
import GameDetail from './components/game-detail/component'
import {GamesList, GamesDuration} from './components/games-list/component'
import GamesListItem from './components/games-list-item/component'
import NavigationBar from './components/navigation-bar/component'
import {ScreenSettings} from './components/screen-settings/component'
import {MenuGame, MenuGameTrigger} from './components/menu-game/component'
import {MenuGameService} from './components/menu-game/service'
import {ButtonFile} from './components/button-file/component'

import {MomentPipe} from 'a2/pipes/moment'
import {DurationPipe, GameDurationPipe, SessionDurationPipe} from 'a2/pipes/duration'
import {SlugPipe} from 'a2/pipes/slug'
import {StoreModule, combineReducers} from '@ngrx/store'
import {compose} from '@ngrx/core/compose'
import {localStorageSync} from 'ngrx-store-localstorage'
import {gamesReducer} from './stores/games'
import {MaterialModule} from '@angular/material'
import {GameSessionItem} from 'a2/components/game-session-item/component'
import {GameStateIcon} from 'a2/components/game-state-icon/component'
import {HotkeyModule} from 'angular2-hotkeys'
import * as services from './services'

import {VirtualRepeaterModule} from 'a2/components/virtual-repeater/module'

@NgModule({
	imports: [
		VirtualRepeaterModule,
		BrowserModule,
		FormsModule,
		MaterialModule.forRoot(),
		RouterModule.forRoot([
			{
				path: '',
				redirectTo: 'games/all',
				pathMatch: 'full'
			},
			{
				path: 'games',
				redirectTo: 'games/all',
				pathMatch: 'full'
			},
			{
				path: 'games/:state',
				component: ScreenGames,
			},
			{
				path: 'settings',
				component: ScreenSettings
			}
		]),
		StoreModule.provideStore(
			compose(
				localStorageSync(['games'], true), combineReducers
			)({games: gamesReducer})
		),
		HotkeyModule.forRoot()
	],
	declarations: [
		Timer,
		ScreenGames,
		GameDetail,
		GamesList,
		GamesDuration,
		GamesListItem,
		DurationPipe,
		GameDurationPipe,
		SessionDurationPipe,
		SlugPipe,
		NavigationBar,
		ScreenSettings,
		MenuGame,
		MenuGameTrigger,
		ButtonFile,
		GameSessionItem,
		GameStateIcon,
		MomentPipe,
	],
	providers: [
		...Object.keys(services).map(key => services[key]),
		MenuGameService
	],
	bootstrap: [Timer]
})
export class App {}


text:
package org.motechproject.mds.builder.impl;

import org.apache.velocity.app.VelocityEngine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.motechproject.mds.dto.EntityDto;
import org.motechproject.mds.dto.FieldBasicDto;
import org.motechproject.mds.dto.FieldDto;
import org.motechproject.mds.dto.LookupDto;
import org.motechproject.mds.dto.LookupFieldDto;
import org.motechproject.mds.service.EntityService;
import org.motechproject.mds.service.impl.EntityServiceImpl;
import org.motechproject.mds.testutil.FieldTestHelper;

import java.util.LinkedList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class MdsDataProviderBuilderImplTest {

    private MDSDataProviderBuilderImpl mdsDataProviderBuilder = new MDSDataProviderBuilderImpl();

    private List<EntityDto> entityList = new LinkedList<>();
    private List<LookupDto> lookupList = new LinkedList<>();
    private List<FieldDto> fieldList = new LinkedList<>();

    @Mock
    private EntityService entityService = new EntityServiceImpl();

    private VelocityEngine velocityEngine = new VelocityEngine();

    @Before
    public void setUp() {
        when(entityService.listEntities()).thenReturn(entityList);
        when(entityService.getEntityLookups(Long.valueOf("1"))).thenReturn(lookupList);
        when(entityService.getEntityFields(Long.valueOf("1"))).thenReturn(fieldList);
        mdsDataProviderBuilder.setEntityService(entityService);

        velocityEngine.addProperty("resource.loader", "classpath");
        velocityEngine.addProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        mdsDataProviderBuilder.setVelocityEngine(velocityEngine);
    }

    @Test
    public void shouldGenerateEmptyJson() {
        String generatedJson = mdsDataProviderBuilder.generateDataProvider();
        assertEquals("", generatedJson);
    }

    @Test
    public void shouldGenerateJson() {
        String json = "{\n" +
                "    \"name\": \"data-services\",\n" +
                "    \"objects\": [         {\n" +
                "            \"displayName\": \"TestEntity\",\n" +
                "            \"type\": \"org.motechproject.TestEntity\",\n" +
                "            \"lookupFields\": [                 {\n" +
                "                    \"displayName\": \"TestLookupName\",\n" +
                "                    \"fields\": [\n" +
                "                         \"TestFieldName\"                      ]\n" +
                "                },                {\n" +
                "                    \"displayName\": \"mds.dataprovider.byinstanceid\",\n" +
                "                    \"fields\": [\n" +
                "                        \"mds.dataprovider.instanceid\"\n" +
                "                    ]\n" +
                "                }\n" +
                "            ],\n" +
                "            \"fields\": [\n" +
                "                                {\n" +
                "                    \"displayName\": \"TestFieldDisplayName\",\n" +
                "                    \"fieldKey\": \"TestFieldName\"\n" +
                "                }              ]\n" +
                "        }      ]\n" +
                "}\n";

        EntityDto entity = new EntityDto();
        entity.setId(Long.valueOf("1"));
        entity.setName("TestEntity");
        entity.setClassName("org.motechproject.TestEntity");

        FieldDto field = new FieldDto();
        FieldBasicDto fieldBasicDto = new FieldBasicDto();
        fieldBasicDto.setName("TestFieldName");
        fieldBasicDto.setDisplayName("TestFieldDisplayName");
        field.setBasic(fieldBasicDto);
        fieldList.add(field);

        LookupDto lookup = new LookupDto();
        lookup.setLookupName("TestLookupName");
        List<LookupFieldDto> lookupFields = new LinkedList<>();
        lookupFields.add(FieldTestHelper.lookupFieldDto("TestFieldName"));
        lookup.setLookupFields(lookupFields);
        lookupList.add(lookup);
        entityList.add(entity);

        String generatedJson = mdsDataProviderBuilder.generateDataProvider();

        assertEquals(json, generatedJson.replace("\r\n", "\n"));
    }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <bean id="ApplicationContextProperties" class="java.lang.String">
    <constructor-arg value="/testdata/mocktestdata/applicationContext.properties"/>
  </bean>

  <bean id="FeedConnection"
        class="com.google.enterprise.connector.pusher.MockFeedConnection">
  </bean>

  <bean id="PusherFactory"
        class="com.google.enterprise.connector.pusher.DocPusherFactory">
    <constructor-arg index="0" ref="FeedConnection" />
  </bean>

  <bean id="LoadManagerFactory"
        class="com.google.enterprise.connector.scheduler.HostLoadManagerFactory">
    <property name="feedConnection" ref="FeedConnection"/>
  </bean>

  <bean id="ConnectorScheduleStore"
        class="com.google.enterprise.connector.persist.MockPersistentStore">
  </bean>

  <bean id="ConnectorStateStore"
        class="com.google.enterprise.connector.persist.MockPersistentStore">
  </bean>

  <bean id="ConnectorConfigStore"
        class="com.google.enterprise.connector.persist.FileStore">
    <property name="typeMap" ref="TypeMap" />
  </bean>

  <bean id="PersistentStore"
        class="com.google.enterprise.connector.persist.HybridPersistentStore">
    <constructor-arg index="0" ref="ConnectorConfigStore"/>
    <constructor-arg index="1" ref="ConnectorScheduleStore"/>
    <constructor-arg index="2" ref="ConnectorStateStore"/>
  </bean>

  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod"
              value="com.google.enterprise.connector.instantiator.InstanceInfo.setPersistentStore"/>
    <property name="arguments">
      <list>
        <ref bean="PersistentStore"/>
      </list>
    </property>
  </bean>

  <bean id="ConnectorCoordinatorFactory"
        class="com.google.enterprise.connector.instantiator.ConnectorCoordinatorImplFactory">
    <property name="pusherFactory" ref="PusherFactory" />
    <property name="loadManagerFactory" ref="LoadManagerFactory"/>
    <property name="threadPool" ref="ThreadPool" />
    <property name="changeDetector" ref="ChangeDetector"/>
    <property name="clock" ref="Clock"/>
  </bean>

  <bean id="ConnectorCoordinatorMap"
        class="com.google.enterprise.connector.instantiator.ConnectorCoordinatorMap">
    <property name="connectorCoordinatorFactory" ref="ConnectorCoordinatorFactory" />
  </bean>

  <bean id="TypeMap"
        class="com.google.enterprise.connector.instantiator.TypeMap"/>

  <bean id="ChangeListener"
        class="com.google.enterprise.connector.instantiator.ChangeListenerImpl">
    <constructor-arg index="0" ref="TypeMap"/>
    <constructor-arg index="1" ref="ConnectorCoordinatorMap"/>
  </bean>

  <bean id="ChangeDetector"
        class="com.google.enterprise.connector.instantiator.ChangeDetectorImpl">
    <constructor-arg index="0" ref="PersistentStore"/>
    <constructor-arg index="1" ref="ChangeListener"/>
  </bean>

  <bean id="ChangeDetectorTask"
        class="com.google.enterprise.connector.instantiator.ChangeDetectorTask">
    <constructor-arg index="0" ref="ChangeDetector"/>
    <constructor-arg index="1" value="0"/>
    <constructor-arg index="2" value="0"/>
  </bean>

  <bean id="Instantiator"
        class="com.google.enterprise.connector.instantiator.SpringInstantiator">
    <property name="connectorCoordinatorMap" ref="ConnectorCoordinatorMap" />
    <property name="threadPool" ref="ThreadPool" />
    <property name="typeMap" ref="TypeMap" />
    <property name="changeDetectorTask" ref="ChangeDetectorTask" />
  </bean>

  <bean id="Clock" class="com.google.enterprise.connector.util.SystemClock" />

  <bean id="ThreadPool"
        class="com.google.enterprise.connector.instantiator.ThreadPool">
    <constructor-arg index="0" type="int" value="5"/>
    <constructor-arg index="1" ref="Clock"/>
  </bean>

  <bean id="Manager"
        class="com.google.enterprise.connector.manager.ProductionManager">
    <property name="instantiator" ref="Instantiator" />
    <property name="feedConnection" ref="FeedConnection" />
  </bean>

  <bean id="TraversalScheduler"
        class="com.google.enterprise.connector.scheduler.TraversalScheduler">
    <constructor-arg index="0" ref="Instantiator" />
  </bean>
</beans>


text:
@class MFError, Message, MessageBody, MessageStore, NSArray, NSMutableDictionary, NSString;

@interface MimePart : NSObject <NSURLDownloadDelegate>
{
    struct _NSRange _range;
    id _parentOrBody;
    MimePart *_nextPart;
    long long _typeCode;
    long long _subtypeCode;
    NSString *_type;
    NSString *_subtype;
    NSMutableDictionary *_bodyParameters;
    NSString *_contentTransferEncoding;
    NSMutableDictionary *_otherIvars;
    id _encryptSignLock;
    MessageBody *_decryptedMessageBody;
    Message *_decryptedMessage;
    MessageStore *_decryptedMessageStore;
    NSArray *_messageSigners;
    MFError *_smimeError;
    BOOL _isMimeEncrypted;
    BOOL _isMimeSigned;
}

- (void)dealloc;
- (void)finalize;
- (id)init;
- (long long)typeCode;
- (id)type;
- (void)setType:(id)arg1;
- (long long)subtypeCode;
- (id)subtype;
- (void)setSubtype:(id)arg1;
- (BOOL)isType:(id)arg1 subtype:(id)arg2;
- (BOOL)isTypeCode:(long long)arg1 subtypeCode:(long long)arg2;
- (id)bodyParameterForKey:(id)arg1;
- (void)setBodyParameter:(id)arg1 forKey:(id)arg2;
- (id)bodyParameterKeys;
- (id)disposition;
- (void)setDisposition:(id)arg1;
- (id)dispositionParameterForKey:(id)arg1;
- (void)setDispositionParameter:(id)arg1 forKey:(id)arg2;
- (id)dispositionParameterKeys;
- (id)contentDescription;
- (void)setContentDescription:(id)arg1;
- (id)contentID;
- (void)setContentID:(id)arg1;
@property(readonly) NSString *contentIDURLString;
- (id)contentLocation;
- (void)setContentLocation:(id)arg1;
- (id)languages;
- (void)setLanguages:(id)arg1;
- (id)parentPart;
- (id)firstChildPart;
- (id)nextSiblingPart;
- (id)subparts;
- (id)subpartAtIndex:(long long)arg1;
- (void)setSubparts:(id)arg1;
- (void)addSubpart:(id)arg1;
- (struct _NSRange)range;
- (void)setRange:(struct _NSRange)arg1;
- (id)bodyData;
- (id)bodyConvertedFromFlowedText;
- (id)mimeBody;
- (void)setMimeBody:(id)arg1;
- (id)description;
- (id)attachmentFilenameWithHiddenExtension:(char *)arg1;
- (id)attachmentFilename;
@property(readonly) BOOL isSigned;
@property(readonly) BOOL isEncrypted;
- (BOOL)hasCachedDataInStore;
- (unsigned int)numberOfAttachments;
- (void)getNumberOfAttachments:(unsigned int *)arg1 numberOfTNEFAttachments:(unsigned int *)arg2 isSigned:(char *)arg3 isEncrypted:(char *)arg4;
- (id)attachments;
- (id)attachmentFilenames;
- (unsigned int)textEncoding;
- (unsigned long long)approximateRawSize;
- (unsigned long long)approximateDecodedSize;
- (BOOL)isReadableText;
@property(readonly) BOOL isImage;
- (BOOL)isCalendar;
- (BOOL)isStationeryImage;
- (void)markAsStationeryImage;
- (id)_partThatIsAttachment;
- (BOOL)isMessageExternalBodyWithURL;
- (BOOL)shouldConsiderInlineOverridingExchangeServer;
- (BOOL)isAttachment;
- (BOOL)isRich;
- (BOOL)isHTML;
- (BOOL)usesKnownSignatureProtocol;
@property(readonly) BOOL isAutoArchivePart;
- (id)_newAttachment;
- (id)_createFileWrapper;
- (id)_getMessageAttachment:(unsigned long long)arg1 context:(id)arg2;
- (id)_getMessageAttachment:(unsigned long long)arg1;
- (id)attributedString;
- (id)fileWrapper;
- (id)_remoteFileWrapper;
- (void)download:(id)arg1 didReceiveResponse:(id)arg2;
- (void)download:(id)arg1 didReceiveDataOfLength:(unsigned long long)arg2;
- (void)download:(id)arg1 didFailWithError:(id)arg2;
- (void)downloadDidFinish:(id)arg1;
- (void)configureFileWrapper:(id)arg1;
- (id)startPart;
- (long long)numberOfAlternatives;
- (id)alternativeAtIndex:(long long)arg1;
- (id)signedData;
- (id)textPart;
- (id)textHtmlPart;
- (void)htmlString:(id *)arg1 createWebResource:(id *)arg2 forFileWrapper:(id)arg3 partNumber:(id)arg4;
- (id)htmlStringForMimePart:(id)arg1 attachment:(id)arg2;
- (id)decodedContentWithContext:(id)arg1;
- (id)decodedContent;
- (id)_archiveForData:(id)arg1 URL:(id)arg2 MIMEType:(id)arg3 textEncodingName:(id)arg4 frameName:(id)arg5 subresources:(id)arg6 subframeArchives:(id)arg7;
- (id)_archiveForData:(id)arg1 URL:(id)arg2 MIMEType:(id)arg3 textEncodingName:(id)arg4 frameName:(id)arg5;
- (id)_archiveForString:(id)arg1 URL:(id)arg2 needsPlainTextBodyClass:(BOOL)arg3;
- (id)_archiveForFileWrapper:(id)arg1 URL:(id)arg2;
- (id)_createArchiveWithConvertedPlainTextBodyClassFromArchive:(id)arg1;
- (id)parsedMessage;
- (id)parsedMessageWithContext:(id)arg1;
- (id)webArchive;
- (id)decryptedMessageBodyIsEncrypted:(char *)arg1 isSigned:(char *)arg2 error:(id *)arg3;
- (void)clearCachedDecryptedMessageBody;
- (void)setDecryptedMessageBody:(id)arg1 isEncrypted:(BOOL)arg2 isSigned:(BOOL)arg3 error:(id)arg4;
@property(retain, nonatomic) MessageStore *decryptedMessageStore; // @synthesize decryptedMessageStore=_decryptedMessageStore;
@property(retain, nonatomic) Message *decryptedMessage; // @synthesize decryptedMessage=_decryptedMessage;
@property(retain, nonatomic) MessageBody *decryptedMessageBody; // @synthesize decryptedMessageBody=_decryptedMessageBody;
@property(nonatomic) BOOL isMimeSigned; // @synthesize isMimeSigned=_isMimeSigned;
@property(nonatomic) BOOL isMimeEncrypted; // @synthesize isMimeEncrypted=_isMimeEncrypted;
@property(copy) NSString *contentTransferEncoding; // @synthesize contentTransferEncoding=_contentTransferEncoding;
- (BOOL)writeAttachmentToSpotlightCacheIfNeededUnder:(id)arg1;
- (void)renderString:(id)arg1;
- (id)_fullMimeTypeEvenInsideAppleDouble;
- (id)decodeWithContext:(id)arg1;
- (id)decode;
- (id)decodeTextPlainWithContext:(id)arg1;
- (id)decodeTextWithContext:(id)arg1;
- (id)decodeTextRichtextWithContext:(id)arg1;
- (id)decodeTextRtfWithContext:(id)arg1;
- (id)decodeTextEnrichedWithContext:(id)arg1;
- (id)decodeTextHtmlWithContext:(id)arg1;
- (id)decodeTextCalendarWithContext:(id)arg1;
- (id)decodeMultipartWithContext:(id)arg1;
- (id)decodeMultipartAlternativeWithContext:(id)arg1;
- (id)decodeMultipartRelatedWithContext:(id)arg1;
- (id)decodeMultipartFolderWithContext:(id)arg1;
- (id)decodeApplicationApple_msg_composite_imageWithContext:(id)arg1;
- (id)decodeApplicationOctet_streamWithContext:(id)arg1;
- (id)decodeApplicationZipWithContext:(id)arg1;
- (id)decodeApplicationSmilWithContext:(id)arg1;
- (id)decodeMessageDelivery_statusWithContext:(id)arg1;
- (id)decodeMessageRfc822WithContext:(id)arg1;
- (id)decodeMessagePartialWithContext:(id)arg1;
- (id)decodeMessageExternal_bodyWithContext:(id)arg1;
- (id)decodeApplicationMac_binhex40WithContext:(id)arg1;
- (id)decodeApplicationApplefileWithContext:(id)arg1;
- (id)decodeMultipartAppledoubleWithContext:(id)arg1;
- (BOOL)parseIMAPPropertyList:(id)arg1;
- (id)partNumber;
- (BOOL)parseMimeBodyFetchIfNotAvailable:(BOOL)arg1 allowPartial:(BOOL)arg2;
- (BOOL)parseMimeBody;
- (int)_addDataConvertingLineEndingsFromUnixToNetwork:(id)arg1 toCMSEncoder:(struct _CMSEncoder *)arg2;
- (id)newSignedPartWithData:(id)arg1 sender:(id)arg2 signatureData:(id *)arg3;
- (id)newEncryptedPartWithData:(id)arg1 recipients:(id)arg2 encryptedData:(id *)arg3;
- (struct _CMSDecoder *)_newCMSDecoderWithMimePart:(id)arg1 error:(id *)arg2;
- (id)_verifySignatureWithCMSDecoder:(struct _CMSDecoder *)arg1 againstSender:(id)arg2 signingError:(id *)arg3;
- (id)decodeMultipartSignedWithContext:(id)arg1;
- (id)decodeApplicationPkcs7_mimeWithContext:(id)arg1;
- (BOOL)needsSignatureVerification:(id *)arg1;
- (void)verifySignature;
- (id)copyMessageSigners;
- (id)copySignerLabels;

@end


text:
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Diagnostics.Contracts;
using System;

// Disable the "this variable is not used" warning as every field would imply it.
#pragma warning disable 0414
// Disable the "this variable is never assigned to".
#pragma warning disable 0067
// Disable the "this event is never assigned to".
#pragma warning disable 0649
// Disable the "this variable is never used".
#pragma warning disable 0169
// Disable the "new keyword not required" warning.
#pragma warning disable 0109
// Disable the "extern without DllImport" warning.
#pragma warning disable 0626
// Disable the "could hide other member" warning, can happen on certain properties.
#pragma warning disable 0108

namespace System
{
  public partial struct DateTimeOffset : IComparable, IFormattable, System.Runtime.Serialization.ISerializable, System.Runtime.Serialization.IDeserializationCallback, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>
  {
    #region Methods and constructors
    public static System.DateTimeOffset operator - (System.DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static TimeSpan operator - (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(TimeSpan);
    }

    public static bool operator != (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public static System.DateTimeOffset operator + (System.DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static bool operator < (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public static bool operator <=(System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public static bool operator == (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public static bool operator > (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public static bool operator >= (System.DateTimeOffset left, System.DateTimeOffset right)
    {
      return default(bool);
    }

    public System.DateTimeOffset Add(TimeSpan timeSpan)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddDays(double days)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddHours(double hours)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddMilliseconds(double milliseconds)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddMinutes(double minutes)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddMonths(int months)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddSeconds(double seconds)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddTicks(long ticks)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset AddYears(int years)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static int Compare(System.DateTimeOffset first, System.DateTimeOffset second)
    {
      Contract.Ensures(-1 <= Contract.Result<int>());
      Contract.Ensures(Contract.Result<int>() <= 1);

      return default(int);
    }

    public int CompareTo(System.DateTimeOffset other)
    {
      return default(int);
    }

    public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
    {
      Contract.Ensures(false);
    }

    public DateTimeOffset(DateTime dateTime, TimeSpan offset)
    {
      Contract.Ensures(false);
    }

    public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar, TimeSpan offset)
    {
      Contract.Ensures(false);
    }

    public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
    {
      Contract.Ensures(false);
    }

    public DateTimeOffset(DateTime dateTime)
    {
      Contract.Ensures(false);
    }

    public DateTimeOffset(long ticks, TimeSpan offset)
    {
      Contract.Ensures(false);
    }

    public override bool Equals(Object obj)
    {
      return default(bool);
    }

    public static bool Equals(System.DateTimeOffset first, System.DateTimeOffset second)
    {
      return default(bool);
    }

    public bool Equals(System.DateTimeOffset other)
    {
      return default(bool);
    }

    public bool EqualsExact(System.DateTimeOffset other)
    {
      return default(bool);
    }

    public static System.DateTimeOffset FromFileTime(long fileTime)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public override int GetHashCode()
    {
      return default(int);
    }

    public static System.DateTimeOffset Parse(string input)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static System.DateTimeOffset Parse(string input, IFormatProvider formatProvider)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static System.DateTimeOffset Parse(string input, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static System.DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static System.DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static System.DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset Subtract(TimeSpan value)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public TimeSpan Subtract(System.DateTimeOffset value)
    {
      return default(TimeSpan);
    }

    public static implicit operator System.DateTimeOffset(DateTime dateTime)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    int System.IComparable.CompareTo(Object obj)
    {
      return default(int);
    }

    void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(Object sender)
    {
    }

    void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
    {
    }

    public long ToFileTime()
    {
      Contract.Ensures(0 <= Contract.Result<long>());
      Contract.Ensures(Contract.Result<long>() <= 8718460804854775808);

      return default(long);
    }

    public System.DateTimeOffset ToLocalTime()
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public System.DateTimeOffset ToOffset(TimeSpan offset)
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public override string ToString()
    {
      return default(string);
    }

    public string ToString(IFormatProvider formatProvider)
    {
      Contract.Ensures(0 <= string.Empty.Length);

      return default(string);
    }

    public string ToString(string format, IFormatProvider formatProvider)
    {
      return default(string);
    }

    public string ToString(string format)
    {
      Contract.Ensures(0 <= string.Empty.Length);

      return default(string);
    }

    public System.DateTimeOffset ToUniversalTime()
    {
      Contract.Ensures(false);

      return default(System.DateTimeOffset);
    }

    public static bool TryParse(string input, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result)
    {
      Contract.Ensures(false);

      result = default(System.DateTimeOffset);

      return default(bool);
    }

    public static bool TryParse(string input, out System.DateTimeOffset result)
    {
      Contract.Ensures(false);

      result = default(System.DateTimeOffset);

      return default(bool);
    }

    public static bool TryParseExact(string input, string format, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result)
    {
      Contract.Ensures(false);

      result = default(System.DateTimeOffset);

      return default(bool);
    }

    public static bool TryParseExact(string input, string[] formats, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result)
    {
      Contract.Ensures(false);

      result = default(System.DateTimeOffset);

      return default(bool);
    }
    #endregion

    #region Properties and indexers
    public System.DateTime Date
    {
      get
      {
        return default(System.DateTime);
      }
    }

    public DateTime DateTime
    {
      get
      {
        return default(DateTime);
      }
    }

    public int Day
    {
      get
      {
        return default(int);
      }
    }

    public DayOfWeek DayOfWeek
    {
      get
      {
        return default(DayOfWeek);
      }
    }

    public int DayOfYear
    {
      get
      {
        return default(int);
      }
    }

    public int Hour
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<int>());
        Contract.Ensures(Contract.Result<int>() <= 23);

        return default(int);
      }
    }

    public System.DateTime LocalDateTime
    {
      get
      {
        return default(System.DateTime);
      }
    }

    public int Millisecond
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<int>());
        Contract.Ensures(Contract.Result<int>() <= 999);

        return default(int);
      }
    }

    public int Minute
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<int>());
        Contract.Ensures(Contract.Result<int>() <= 59);

        return default(int);
      }
    }

    public int Month
    {
      get
      {
        return default(int);
      }
    }

    public static System.DateTimeOffset Now
    {
      get
      {
        Contract.Ensures(false);

        return default(System.DateTimeOffset);
      }
    }

    public TimeSpan Offset
    {
      get
      {
        return default(TimeSpan);
      }
    }

    public int Second
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<int>());
        Contract.Ensures(Contract.Result<int>() <= 59);

        return default(int);
      }
    }

    public long Ticks
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<long>());

        return default(long);
      }
    }

    public TimeSpan TimeOfDay
    {
      get
      {
        return default(TimeSpan);
      }
    }

    public System.DateTime UtcDateTime
    {
      get
      {
        return default(System.DateTime);
      }
    }

    public static System.DateTimeOffset UtcNow
    {
      get
      {
        Contract.Ensures(false);

        return default(System.DateTimeOffset);
      }
    }

    public long UtcTicks
    {
      get
      {
        Contract.Ensures(0 <= Contract.Result<long>());

        return default(long);
      }
    }

    public int Year
    {
      get
      {
        return default(int);
      }
    }
    #endregion

    #region Fields
    public readonly static System.DateTimeOffset MaxValue;
    public readonly static System.DateTimeOffset MinValue;
    #endregion
  }
}


text:
description: |
    Packer is able to create Amazon AMIs. To achieve this, Packer comes with
    multiple builders depending on the strategy you want to use to build the AMI.
layout: docs
page_title: Amazon AMI Builder
...

# Amazon AMI Builder

Packer is able to create Amazon AMIs. To achieve this, Packer comes with
multiple builders depending on the strategy you want to use to build the AMI.
Packer supports the following builders at the moment:

-   [amazon-ebs](/docs/builders/amazon-ebs.html) - Create EBS-backed AMIs by
    launching a source AMI and re-packaging it into a new AMI
    after provisioning. If in doubt, use this builder, which is the easiest to
    get started with.

-   [amazon-instance](/docs/builders/amazon-instance.html) - Create
    instance-store AMIs by launching and provisioning a source instance, then
    rebundling it and uploading it to S3.

-   [amazon-chroot](/docs/builders/amazon-chroot.html) - Create EBS-backed AMIs
    from an existing EC2 instance by mounting the root device and using a
    [Chroot](https://en.wikipedia.org/wiki/Chroot) environment to provision
    that device. This is an **advanced builder and should not be used by
    newcomers**. However, it is also the fastest way to build an EBS-backed AMI
    since no new EC2 instance needs to be launched.

-> **Don't know which builder to use?** If in doubt, use the [amazon-ebs
builder](/docs/builders/amazon-ebs.html). It is much easier to use and Amazon
generally recommends EBS-backed images nowadays.

# Amazon EBS Volume Builder

Packer is able to create Amazon EBS Volumes which are preinitialized with a
filesystem and data.

-   [amazon-ebsvolume](/docs/builders/amazon-ebsv-volume.html) - Create EBS volumes
    by launching a source AMI with block devices mapped. Provision the instance,
    then destroy it, retaining the EBS volumes.

## Specifying Amazon Credentials

When you use any of the amazon builders, you must provide credentials to the API
in the form of an access key id and secret. These look like:

    access key id:     AKIAIOSFODNN7EXAMPLE
    secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

If you use other AWS tools you may already have these configured. If so, packer
will try to use them, *unless* they are specified in your packer template.
Credentials are resolved in the following order:

1.  Values hard-coded in the packer template are always authoritative.
2.  *Variables* in the packer template may be resolved from command-line flags
    or from environment variables. Please read about [User
    Variables](https://www.packer.io/docs/templates/user-variables.html)
    for details.
3.  If no credentials are found, packer falls back to automatic lookup.

### Automatic Lookup

If no AWS credentials are found in a packer template, we proceed on to the
following steps:

1.  Lookup via environment variables.
    -   First `AWS_ACCESS_KEY_ID`, then `AWS_ACCESS_KEY`
    -   First `AWS_SECRET_ACCESS_KEY`, then `AWS_SECRET_KEY`

2.  Look for [local AWS configuration
    files](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files)
    -   First `~/.aws/credentials`
    -   Next based on `AWS_PROFILE`

3.  Lookup an IAM role for the current EC2 instance (if you're running in EC2)

\~> **Subtle details of automatic lookup may change over time.** The most
reliable way to specify your configuration is by setting them in template
variables (directly or indirectly), or by using the `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY` environment variables.

Environment variables provide the best portability, allowing you to run your
packer build on your workstation, in Atlas, or on another build server.

## Using an IAM Instance Profile

If AWS keys are not specified in the template, a
[credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files)
file or through environment variables Packer will use credentials provided by
the instance's IAM profile, if it has one.

The following policy document provides the minimal set permissions necessary for
Packer to work:

``` {.javascript}
{
  "Version": "2012-10-17",
  "Statement": [{
      "Effect": "Allow",
      "Action" : [
        "ec2:AttachVolume",
        "ec2:AuthorizeSecurityGroupIngress",
        "ec2:CopyImage",
        "ec2:CreateImage",
        "ec2:CreateKeypair",
        "ec2:CreateSecurityGroup",
        "ec2:CreateSnapshot",
        "ec2:CreateTags",
        "ec2:CreateVolume",
        "ec2:DeleteKeypair",
        "ec2:DeleteSecurityGroup",
        "ec2:DeleteSnapshot",
        "ec2:DeleteVolume",
        "ec2:DeregisterImage",
        "ec2:DescribeImageAttribute",
        "ec2:DescribeImages",
        "ec2:DescribeInstances",
        "ec2:DescribeRegions",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSnapshots",
        "ec2:DescribeSubnets",
        "ec2:DescribeTags",
        "ec2:DescribeVolumes",
        "ec2:DetachVolume",
        "ec2:GetPasswordData",
        "ec2:ModifyImageAttribute",
        "ec2:ModifyInstanceAttribute",
        "ec2:RegisterImage",
        "ec2:RunInstances",
        "ec2:StopInstances",
        "ec2:TerminateInstances"
      ],
      "Resource" : "*"
  }]
}
```

## Troubleshooting

### Attaching IAM Policies to Roles

IAM policies can be associated with user or roles. If you use packer with IAM
roles, you may encounter an error like this one:

    ==> amazon-ebs: Error launching source instance: You are not authorized to perform this operation.

You can read more about why this happens on the [Amazon Security
Blog](https://blogs.aws.amazon.com/security/post/Tx3M0IFB5XBOCQX/Granting-Permission-to-Launch-EC2-Instances-with-IAM-Roles-PassRole-Permission).
The example policy below may help packer work with IAM roles. Note that this
example provides more than the minimal set of permissions needed for packer to
work, but specifics will depend on your use-case.

``` {.json}
{
    "Sid": "PackerIAMPassRole",
    "Effect": "Allow",
    "Action": "iam:PassRole",
    "Resource": [
        "*"
    ]
}
```

### Checking that system time is current

Amazon uses the current time as part of the [request signing
process](http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html). If
your system clock is too skewed from the current time, your requests might
fail. If that's the case, you might see an error like this:

    ==> amazon-ebs: Error querying AMI: AuthFailure: AWS was not able to validate the provided access credentials

If you suspect your system's date is wrong, you can compare it against
http://www.time.gov/. On Linux/OS X, you can run the `date` command to get the
current time. If you're on Linux, you can try setting the time with ntp by
running `sudo ntpd -q`.


text:
<?php
namespace IComeFromTheNet\Schedule\Builder;

use DateTime;

/**
  *  Abstract Common Builder
  *
  *  @author Lewis Dyer <getintouch@icomefromthenet.com>
  *  @since 1.0.0;
  */
abstract class CommonBuilder
{

    protected $startDate;

    protected $limitation;

    protected $sequenceOffset = 1;

    protected $parent;

    protected $skip = false;

    /**
     *  Create a Schedule Rule
     *
     *  @access public
     *  @return IComeFromTheNet\Schedule\Rule\RuleInterface
     *
    */
    abstract public function build();

    /**
     *  Set the Start Date of the schedule
     *
     *  @access public
     *  @return CommonBuilder
     *
    */
    public function start(DateTime $start)
    {
        $this->startDate = $start;

        return $this;
    }

    /**
     *  Set the end date of schedule
     *
     *  @access public
     *  @return CommonBuilder
     *  @param DateTime | integer
     *
    */
    public function limit($end)
    {
        $this->limitation = $end;

        return $this;
    }

    /**
     *  Set the sequence offset i.e. late start
     *
     *  @access public
     *  @return CommonBuilder
     *
    */
    public function offset($offset)
    {
        $this->sequenceOffset = $offset;

        return $this;

    }

    /**
     *  Skip the starting date in the iterator
     *  e.g if bill at signup don't skip but if
     *  bill at the end of the month need to skip
     *  the first occurance at the start
     *
     *  @access public
     *  @return void
     *
    */
    public function skipStart()
    {
        $this->skip = true;

        return $this;
    }

}
/* End of Class */


text:
import Vue from 'vue'
import copyBox from '@rundeck/ui-trellis/lib/components/containers/copybox/CopyBox.vue'
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

window.addEventListener('DOMContentLoaded', init)
function init(){
    const els = document.body.getElementsByClassName('vue-copybox')
    if (!els)
        return

    for (var i = 0; i < els.length; i++) {
        const e = els[i]
        /* eslint-disable no-new */
        new Vue({
            el: e,
            components: { copyBox }
        })
    }
}


text:
<!--
  ~  $HomePage: https://github.com/maizi0122/ $
  ~  $Revision: 000001 $
  ~  $Date: 2015-10-18 09:05:31 -0000 (Sun, 18 Oct 2015) $
  ~
  ~  ====================================================================
  ~  Copyright (C) 2011 The Maizi-Studio Open Source Project
  ~
  ~  Licensed under the Apache License, Version 2.0 (the "License");
  ~  you may not use this file except in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~       http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  ~  ====================================================================
  ~
  ~  This project powered by Maizi-Studio, but works with the
  ~  license of apache,so you should abide by this license.
  ~  Any question contacting with email below:
  ~  maizi0122@gmail.com
  -->

<resources>
    <string name="app_name">Ripened</string>
    <string name="title_activity_iv">IVActivity</string>
</resources>


text:
  ## returns the key at the specified position
  function(map_key_at map idx)
    map_keys(${map})
    ans(keys)
    list_normalize_index(keys ${idx})
    ans(idx)
    list_get(keys ${idx})
    ans(key)
    return_ref(key)
  endfunction()


text:
from collections import OrderedDict
import json
import logging
from copy import deepcopy
from datetime import datetime, timedelta
from six import string_types

import requests
import sqlalchemy as sa
from sqlalchemy import (
    Column, Integer, String, ForeignKey, Text, Boolean,
    DateTime,
)
from sqlalchemy.orm import backref, relationship
from dateutil.parser import parse as dparse

from pydruid.client import PyDruid
from pydruid.utils.aggregators import count
from pydruid.utils.filters import Dimension, Filter
from pydruid.utils.postaggregator import (
    Postaggregator, Quantile, Quantiles, Field, Const, HyperUniqueCardinality,
)
from pydruid.utils.having import Aggregation

from flask import Markup, escape
from flask_appbuilder.models.decorators import renders
from flask_appbuilder import Model

from flask_babel import lazy_gettext as _

from superset import conf, db, import_util, utils, sm, get_session
from superset.utils import (
    flasher, MetricPermException, DimSelector, DTTM_ALIAS
)
from superset.connectors.base import BaseDatasource, BaseColumn, BaseMetric
from superset.models.helpers import AuditMixinNullable, QueryResult, set_perm

DRUID_TZ = conf.get("DRUID_TZ")

class JavascriptPostAggregator(Postaggregator):
    def __init__(self, name, field_names, function):
        self.post_aggregator = {
            'type': 'javascript',
            'fieldNames': field_names,
            'name': name,
            'function': function,
        }
        self.name = name

class DruidCluster(Model, AuditMixinNullable):

    """ORM object referencing the Druid clusters"""

    __tablename__ = 'clusters'
    type = "druid"

    id = Column(Integer, primary_key=True)
    verbose_name = Column(String(250), unique=True)
    # short unique name, used in permissions
    cluster_name = Column(String(250), unique=True)
    coordinator_host = Column(String(255))
    coordinator_port = Column(Integer)
    coordinator_endpoint = Column(
        String(255), default='druid/coordinator/v1/metadata')
    broker_host = Column(String(255))
    broker_port = Column(Integer)
    broker_endpoint = Column(String(255), default='druid/v2')
    metadata_last_refreshed = Column(DateTime)
    cache_timeout = Column(Integer)

    def __repr__(self):
        return self.verbose_name if self.verbose_name else self.cluster_name

    def get_pydruid_client(self):
        cli = PyDruid(
            "http://{0}:{1}/".format(self.broker_host, self.broker_port),
            self.broker_endpoint)
        return cli

    def get_datasources(self):
        endpoint = (
            "http://{obj.coordinator_host}:{obj.coordinator_port}/"
            "{obj.coordinator_endpoint}/datasources"
        ).format(obj=self)

        return json.loads(requests.get(endpoint).text)

    def get_druid_version(self):
        endpoint = (
            "http://{obj.coordinator_host}:{obj.coordinator_port}/status"
        ).format(obj=self)
        return json.loads(requests.get(endpoint).text)['version']

    def refresh_datasources(self, datasource_name=None, merge_flag=False):
        """Refresh metadata of all datasources in the cluster
        If ``datasource_name`` is specified, only that datasource is updated
        """
        self.druid_version = self.get_druid_version()
        for datasource in self.get_datasources():
            if datasource not in conf.get('DRUID_DATA_SOURCE_BLACKLIST', []):
                if not datasource_name or datasource_name == datasource:
                    DruidDatasource.sync_to_db(datasource, self, merge_flag)

    @property
    def perm(self):
        return "[{obj.cluster_name}].(id:{obj.id})".format(obj=self)

    def get_perm(self):
        return self.perm

    @property
    def name(self):
        return self.verbose_name if self.verbose_name else self.cluster_name

    @property
    def unique_name(self):
        return self.verbose_name if self.verbose_name else self.cluster_name

class DruidColumn(Model, BaseColumn):
    """ORM model for storing Druid datasource column metadata"""

    __tablename__ = 'columns'

    datasource_name = Column(
        String(255),
        ForeignKey('datasources.datasource_name'))
    # Setting enable_typechecks=False disables polymorphic inheritance.
    datasource = relationship(
        'DruidDatasource',
        backref=backref('columns', cascade='all, delete-orphan'),
        enable_typechecks=False)
    dimension_spec_json = Column(Text)

    export_fields = (
        'datasource_name', 'column_name', 'is_active', 'type', 'groupby',
        'count_distinct', 'sum', 'avg', 'max', 'min', 'filterable',
        'description', 'dimension_spec_json'
    )

    def __repr__(self):
        return self.column_name

    @property
    def expression(self):
        return self.dimension_spec_json

    @property
    def dimension_spec(self):
        if self.dimension_spec_json:
            return json.loads(self.dimension_spec_json)

    def generate_metrics(self):
        """Generate metrics based on the column metadata"""
        M = DruidMetric  # noqa
        metrics = []
        metrics.append(DruidMetric(
            metric_name='count',
            verbose_name='COUNT(*)',
            metric_type='count',
            json=json.dumps({'type': 'count', 'name': 'count'})
        ))
        # Somehow we need to reassign this for UDAFs
        if self.type in ('DOUBLE', 'FLOAT'):
            corrected_type = 'DOUBLE'
        else:
            corrected_type = self.type

        if self.sum and self.is_num:
            mt = corrected_type.lower() + 'Sum'
            name = 'sum__' + self.column_name
            metrics.append(DruidMetric(
                metric_name=name,
                metric_type='sum',
                verbose_name='SUM({})'.format(self.column_name),
                json=json.dumps({
                    'type': mt, 'name': name, 'fieldName': self.column_name})
            ))

        if self.avg and self.is_num:
            mt = corrected_type.lower() + 'Avg'
            name = 'avg__' + self.column_name
            metrics.append(DruidMetric(
                metric_name=name,
                metric_type='avg',
                verbose_name='AVG({})'.format(self.column_name),
                json=json.dumps({
                    'type': mt, 'name': name, 'fieldName': self.column_name})
            ))

        if self.min and self.is_num:
            mt = corrected_type.lower() + 'Min'
            name = 'min__' + self.column_name
            metrics.append(DruidMetric(
                metric_name=name,
                metric_type='min',
                verbose_name='MIN({})'.format(self.column_name),
                json=json.dumps({
                    'type': mt, 'name': name, 'fieldName': self.column_name})
            ))
        if self.max and self.is_num:
            mt = corrected_type.lower() + 'Max'
            name = 'max__' + self.column_name
            metrics.append(DruidMetric(
                metric_name=name,
                metric_type='max',
                verbose_name='MAX({})'.format(self.column_name),
                json=json.dumps({
                    'type': mt, 'name': name, 'fieldName': self.column_name})
            ))
        if self.count_distinct:
            name = 'count_distinct__' + self.column_name
            if self.type == 'hyperUnique' or self.type == 'thetaSketch':
                metrics.append(DruidMetric(
                    metric_name=name,
                    verbose_name='COUNT(DISTINCT {})'.format(self.column_name),
                    metric_type=self.type,
                    json=json.dumps({
                        'type': self.type,
                        'name': name,
                        'fieldName': self.column_name
                    })
                ))
            else:
                mt = 'count_distinct'
                metrics.append(DruidMetric(
                    metric_name=name,
                    verbose_name='COUNT(DISTINCT {})'.format(self.column_name),
                    metric_type='count_distinct',
                    json=json.dumps({
                        'type': 'cardinality',
                        'name': name,
                        'fieldNames': [self.column_name]})
                ))
        session = get_session()
        new_metrics = []
        for metric in metrics:
            m = (
                session.query(M)
                .filter(M.metric_name == metric.metric_name)
                .filter(M.datasource_name == self.datasource_name)
                .filter(DruidCluster.cluster_name == self.datasource.cluster_name)
                .first()
            )
            metric.datasource_name = self.datasource_name
            if not m:
                new_metrics.append(metric)
                session.add(metric)
                session.flush()

    @classmethod
    def import_obj(cls, i_column):
        def lookup_obj(lookup_column):
            return db.session.query(DruidColumn).filter(
                DruidColumn.datasource_name == lookup_column.datasource_name,
                DruidColumn.column_name == lookup_column.column_name).first()

        return import_util.import_simple_obj(db.session, i_column, lookup_obj)

class DruidMetric(Model, BaseMetric):

    """ORM object referencing Druid metrics for a datasource"""

    __tablename__ = 'metrics'
    datasource_name = Column(
        String(255),
        ForeignKey('datasources.datasource_name'))
    # Setting enable_typechecks=False disables polymorphic inheritance.
    datasource = relationship(
        'DruidDatasource',
        backref=backref('metrics', cascade='all, delete-orphan'),
        enable_typechecks=False)
    json = Column(Text)

    export_fields = (
        'metric_name', 'verbose_name', 'metric_type', 'datasource_name',
        'json', 'description', 'is_restricted', 'd3format'
    )

    @property
    def expression(self):
        return self.json

    @property
    def json_obj(self):
        try:
            obj = json.loads(self.json)
        except Exception:
            obj = {}
        return obj

    @property
    def perm(self):
        return (
            "{parent_name}.[{obj.metric_name}](id:{obj.id})"
        ).format(obj=self,
                 parent_name=self.datasource.full_name
                 ) if self.datasource else None

    @classmethod
    def import_obj(cls, i_metric):
        def lookup_obj(lookup_metric):
            return db.session.query(DruidMetric).filter(
                DruidMetric.datasource_name == lookup_metric.datasource_name,
                DruidMetric.metric_name == lookup_metric.metric_name).first()
        return import_util.import_simple_obj(db.session, i_metric, lookup_obj)

class DruidDatasource(Model, BaseDatasource):

    """ORM object referencing Druid datasources (tables)"""

    __tablename__ = 'datasources'

    type = "druid"
    query_langtage = "json"
    cluster_class = DruidCluster
    metric_class = DruidMetric
    column_class = DruidColumn

    baselink = "druiddatasourcemodelview"

    # Columns
    datasource_name = Column(String(255), unique=True)
    is_hidden = Column(Boolean, default=False)
    fetch_values_from = Column(String(100))
    cluster_name = Column(
        String(250), ForeignKey('clusters.cluster_name'))
    cluster = relationship(
        'DruidCluster', backref='datasources', foreign_keys=[cluster_name])
    user_id = Column(Integer, ForeignKey('ab_user.id'))
    owner = relationship(
        sm.user_model,
        backref=backref('datasources', cascade='all, delete-orphan'),
        foreign_keys=[user_id])

    export_fields = (
        'datasource_name', 'is_hidden', 'description', 'default_endpoint',
        'cluster_name', 'offset', 'cache_timeout', 'params'
    )
    slices = relationship(
        'Slice',
        primaryjoin=(
            "DruidDatasource.id == foreign(Slice.datasource_id) and "
            "Slice.datasource_type == 'druid'"))

    @property
    def database(self):
        return self.cluster

    @property
    def num_cols(self):
        return [c.column_name for c in self.columns if c.is_num]

    @property
    def name(self):
        return self.datasource_name

    @property
    def schema(self):
        ds_name = self.datasource_name or ''
        name_pieces = ds_name.split('.')
        if len(name_pieces) > 1:
            return name_pieces[0]
        else:
            return None

    @property
    def schema_perm(self):
        """Returns schema permission if present, cluster one otherwise."""
        return utils.get_schema_perm(self.cluster, self.schema)

    def get_perm(self):
        return (
            "[{obj.cluster_name}].[{obj.datasource_name}]"
            "(id:{obj.id})").format(obj=self)

    @property
    def link(self):
        name = escape(self.datasource_name)
        return Markup('{name}').format(**locals())

    @property
    def full_name(self):
        return utils.get_datasource_full_name(
            self.cluster_name, self.datasource_name)

    @property
    def time_column_grains(self):
        return {
            "time_columns": [
                'all', '5 seconds', '30 seconds', '1 minute',
                '5 minutes', '1 hour', '6 hour', '1 day', '7 days',
                'week', 'week_starting_sunday', 'week_ending_saturday',
                'month',
            ],
            "time_grains": ['now']
        }

    def __repr__(self):
        return self.datasource_name

    @renders('datasource_name')
    def datasource_link(self):
        url = "/superset/explore/{obj.type}/{obj.id}/".format(obj=self)
        name = escape(self.datasource_name)
        return Markup('{name}'.format(**locals()))

    def get_metric_obj(self, metric_name):
        return [
            m.json_obj for m in self.metrics
            if m.metric_name == metric_name
        ][0]

    @classmethod
    def import_obj(cls, i_datasource, import_time=None):
        """Imports the datasource from the object to the database.

         Metrics and columns and datasource will be overridden if exists.
         This function can be used to import/export dashboards between multiple
         superset instances. Audit metadata isn't copies over.
        """
        def lookup_datasource(d):
            return db.session.query(DruidDatasource).join(DruidCluster).filter(
                DruidDatasource.datasource_name == d.datasource_name,
                DruidCluster.cluster_name == d.cluster_name,
            ).first()

        def lookup_cluster(d):
            return db.session.query(DruidCluster).filter_by(
                cluster_name=d.cluster_name).one()
        return import_util.import_datasource(
            db.session, i_datasource, lookup_cluster, lookup_datasource,
            import_time)

    @staticmethod
    def version_higher(v1, v2):
        """is v1 higher than v2

        >>> DruidDatasource.version_higher('0.8.2', '0.9.1')
        False
        >>> DruidDatasource.version_higher('0.8.2', '0.6.1')
        True
        >>> DruidDatasource.version_higher('0.8.2', '0.8.2')
        False
        >>> DruidDatasource.version_higher('0.8.2', '0.9.BETA')
        False
        >>> DruidDatasource.version_higher('0.8.2', '0.9')
        False
        """
        def int_or_0(v):
            try:
                v = int(v)
            except (TypeError, ValueError):
                v = 0
            return v
        v1nums = [int_or_0(n) for n in v1.split('.')]
        v2nums = [int_or_0(n) for n in v2.split('.')]
        v1nums = (v1nums + [0, 0, 0])[:3]
        v2nums = (v2nums + [0, 0, 0])[:3]
        return v1nums[0] > v2nums[0] or \
            (v1nums[0] == v2nums[0] and v1nums[1] > v2nums[1]) or \
            (v1nums[0] == v2nums[0] and v1nums[1] == v2nums[1] and v1nums[2] > v2nums[2])

    def latest_metadata(self):
        """Returns segment metadata from the latest segment"""
        client = self.cluster.get_pydruid_client()
        results = client.time_boundary(datasource=self.datasource_name)
        if not results:
            return
        max_time = results[0]['result']['maxTime']
        max_time = dparse(max_time)
        # Query segmentMetadata for 7 days back. However, due to a bug,
        # we need to set this interval to more than 1 day ago to exclude
        # realtime segments, which triggered a bug (fixed in druid 0.8.2).
        # https://groups.google.com/forum/#!topic/druid-user/gVCqqspHqOQ
        lbound = (max_time - timedelta(days=7)).isoformat()
        rbound = max_time.isoformat()
        if not self.version_higher(self.cluster.druid_version, '0.8.2'):
            rbound = (max_time - timedelta(1)).isoformat()
        segment_metadata = None
        try:
            segment_metadata = client.segment_metadata(
                datasource=self.datasource_name,
                intervals=lbound + '/' + rbound,
                merge=self.merge_flag,
                analysisTypes=conf.get('DRUID_ANALYSIS_TYPES'))
        except Exception as e:
            logging.warning("Failed first attempt to get latest segment")
            logging.exception(e)
        if not segment_metadata:
            # if no segments in the past 7 days, look at all segments
            lbound = datetime(1901, 1, 1).isoformat()[:10]
            rbound = datetime(2050, 1, 1).isoformat()[:10]
            if not self.version_higher(self.cluster.druid_version, '0.8.2'):
                rbound = datetime.now().isoformat()[:10]
            try:
                segment_metadata = client.segment_metadata(
                    datasource=self.datasource_name,
                    intervals=lbound + '/' + rbound,
                    merge=self.merge_flag,
                    analysisTypes=conf.get('DRUID_ANALYSIS_TYPES'))
            except Exception as e:
                logging.warning("Failed 2nd attempt to get latest segment")
                logging.exception(e)
        if segment_metadata:
            return segment_metadata[-1]['columns']

    def generate_metrics(self):
        for col in self.columns:
            col.generate_metrics()

    @classmethod
    def sync_to_db_from_config(cls, druid_config, user, cluster):
        """Merges the ds config from druid_config into one stored in the db."""
        session = db.session()
        datasource = (
            session.query(cls)
            .filter_by(
                datasource_name=druid_config['name'])
            .first()
        )
        # Create a new datasource.
        if not datasource:
            datasource = cls(
                datasource_name=druid_config['name'],
                cluster=cluster,
                owner=user,
                changed_by_fk=user.id,
                created_by_fk=user.id,
            )
            session.add(datasource)

        dimensions = druid_config['dimensions']
        for dim in dimensions:
            col_obj = (
                session.query(DruidColumn)
                .filter_by(
                    datasource_name=druid_config['name'],
                    column_name=dim)
                .first()
            )
            if not col_obj:
                col_obj = DruidColumn(
                    datasource_name=druid_config['name'],
                    column_name=dim,
                    groupby=True,
                    filterable=True,
                    # TODO: fetch type from Hive.
                    type="STRING",
                    datasource=datasource,
                )
                session.add(col_obj)
        # Import Druid metrics
        for metric_spec in druid_config["metrics_spec"]:
            metric_name = metric_spec["name"]
            metric_type = metric_spec["type"]
            metric_json = json.dumps(metric_spec)

            if metric_type == "count":
                metric_type = "longSum"
                metric_json = json.dumps({
                    "type": "longSum",
                    "name": metric_name,
                    "fieldName": metric_name,
                })

            metric_obj = (
                session.query(DruidMetric)
                .filter_by(
                    datasource_name=druid_config['name'],
                    metric_name=metric_name)
            ).first()
            if not metric_obj:
                metric_obj = DruidMetric(
                    metric_name=metric_name,
                    metric_type=metric_type,
                    verbose_name="%s(%s)" % (metric_type, metric_name),
                    datasource=datasource,
                    json=metric_json,
                    description=(
                        "Imported from the airolap config dir for %s" %
                        druid_config['name']),
                )
                session.add(metric_obj)
        session.commit()

    @classmethod
    def sync_to_db(cls, name, cluster, merge):
        """Fetches metadata for that datasource and merges the Superset db"""
        logging.info("Syncing Druid datasource [{}]".format(name))
        session = get_session()
        datasource = session.query(cls).filter_by(datasource_name=name).first()
        if not datasource:
            datasource = cls(datasource_name=name)
            session.add(datasource)
            flasher("Adding new datasource [{}]".format(name), "success")
        else:
            flasher("Refreshing datasource [{}]".format(name), "info")
        session.flush()
        datasource.cluster = cluster
        datasource.merge_flag = merge
        session.flush()

        cols = datasource.latest_metadata()
        if not cols:
            logging.error("Failed at fetching the latest segment")
            return
        for col in cols:
            # Skip the time column
            if col == "__time":
                continue
            col_obj = (
                session
                .query(DruidColumn)
                .filter_by(datasource_name=name, column_name=col)
                .first()
            )
            datatype = cols[col]['type']
            if not col_obj:
                col_obj = DruidColumn(datasource_name=name, column_name=col)
                session.add(col_obj)
            if datatype == "STRING":
                col_obj.groupby = True
                col_obj.filterable = True
            if datatype == "hyperUnique" or datatype == "thetaSketch":
                col_obj.count_distinct = True
            # If long or double, allow sum/min/max
            if datatype == "LONG" or datatype == "DOUBLE":
                col_obj.sum = True
                col_obj.min = True
                col_obj.max = True
            if col_obj:
                col_obj.type = cols[col]['type']
            session.flush()
            col_obj.datasource = datasource
            col_obj.generate_metrics()
            session.flush()

    @staticmethod
    def time_offset(granularity):
        if granularity == 'week_ending_saturday':
            return 6 * 24 * 3600 * 1000  # 6 days
        return 0

    # uses https://en.wikipedia.org/wiki/ISO_8601
    # http://druid.io/docs/0.8.0/querying/granularities.html
    # TODO: pass origin from the UI
    @staticmethod
    def granularity(period_name, timezone=None, origin=None):
        if not period_name or period_name == 'all':
            return 'all'
        iso_8601_dict = {
            '5 seconds': 'PT5S',
            '30 seconds': 'PT30S',
            '1 minute': 'PT1M',
            '5 minutes': 'PT5M',
            '1 hour': 'PT1H',
            '6 hour': 'PT6H',
            'one day': 'P1D',
            '1 day': 'P1D',
            '7 days': 'P7D',
            'week': 'P1W',
            'week_starting_sunday': 'P1W',
            'week_ending_saturday': 'P1W',
            'month': 'P1M',
        }

        granularity = {'type': 'period'}
        if timezone:
            granularity['timeZone'] = timezone

        if origin:
            dttm = utils.parse_human_datetime(origin)
            granularity['origin'] = dttm.isoformat()

        if period_name in iso_8601_dict:
            granularity['period'] = iso_8601_dict[period_name]
            if period_name in ('week_ending_saturday', 'week_starting_sunday'):
                # use Sunday as start of the week
                granularity['origin'] = '2016-01-03T00:00:00'
        elif not isinstance(period_name, string_types):
            granularity['type'] = 'duration'
            granularity['duration'] = period_name
        elif period_name.startswith('P'):
            # identify if the string is the iso_8601 period
            granularity['period'] = period_name
        else:
            granularity['type'] = 'duration'
            granularity['duration'] = utils.parse_human_timedelta(
                period_name).total_seconds() * 1000
        return granularity

    def values_for_column(self,
                          column_name,
                          limit=10000):
        """Retrieve some values for the given column"""
        # TODO: Use Lexicographic TopNMetricSpec once supported by PyDruid
        if self.fetch_values_from:
            from_dttm = utils.parse_human_datetime(self.fetch_values_from)
        else:
            from_dttm = datetime(1970, 1, 1)

        qry = dict(
            datasource=self.datasource_name,
            granularity="all",
            intervals=from_dttm.isoformat() + '/' + datetime.now().isoformat(),
            aggregations=dict(count=count("count")),
            dimension=column_name,
            metric="count",
            threshold=limit,
        )

        client = self.cluster.get_pydruid_client()
        client.topn(**qry)
        df = client.export_pandas()
        return [row[column_name] for row in df.to_records(index=False)]

    def get_query_str(self, query_obj, phase=1, client=None):
        return self.run_query(client=client, phase=phase, **query_obj)

    def run_query(  # noqa / druid
            self,
            groupby, metrics,
            granularity,
            from_dttm, to_dttm,
            filter=None,  # noqa
            is_timeseries=True,
            timeseries_limit=None,
            timeseries_limit_metric=None,
            row_limit=None,
            inner_from_dttm=None, inner_to_dttm=None,
            orderby=None,
            extras=None,  # noqa
            select=None,  # noqa
            columns=None, phase=2, client=None, form_data=None):
        """Runs a query against Druid and returns a dataframe.
        """
        # TODO refactor into using a TBD Query object
        client = client or self.cluster.get_pydruid_client()
        if not is_timeseries:
            granularity = 'all'
        inner_from_dttm = inner_from_dttm or from_dttm
        inner_to_dttm = inner_to_dttm or to_dttm

        # add tzinfo to native datetime with config
        from_dttm = from_dttm.replace(tzinfo=DRUID_TZ)
        to_dttm = to_dttm.replace(tzinfo=DRUID_TZ)
        timezone = from_dttm.tzname()

        query_str = ""
        metrics_dict = {m.metric_name: m for m in self.metrics}
        all_metrics = []
        post_aggs = {}

        columns_dict = {c.column_name: c for c in self.columns}

        def recursive_get_fields(_conf):
            _fields = _conf.get('fields', [])
            field_names = []
            for _f in _fields:
                _type = _f.get('type')
                if _type in ['fieldAccess', 'hyperUniqueCardinality']:
                    field_names.append(_f.get('fieldName'))
                elif _type == 'arithmetic':
                    field_names += recursive_get_fields(_f)
            return list(set(field_names))

        for metric_name in metrics:
            metric = metrics_dict[metric_name]
            if metric.metric_type != 'postagg':
                all_metrics.append(metric_name)
            else:
                mconf = metric.json_obj
                all_metrics += recursive_get_fields(mconf)
                all_metrics += mconf.get('fieldNames', [])
                if mconf.get('type') == 'javascript':
                    post_aggs[metric_name] = JavascriptPostAggregator(
                        name=mconf.get('name', ''),
                        field_names=mconf.get('fieldNames', []),
                        function=mconf.get('function', ''))
                elif mconf.get('type') == 'quantile':
                    post_aggs[metric_name] = Quantile(
                        mconf.get('name', ''),
                        mconf.get('probability', ''),
                    )
                elif mconf.get('type') == 'quantiles':
                    post_aggs[metric_name] = Quantiles(
                        mconf.get('name', ''),
                        mconf.get('probabilities', ''),
                    )
                elif mconf.get('type') == 'fieldAccess':
                    post_aggs[metric_name] = Field(mconf.get('name'))
                elif mconf.get('type') == 'constant':
                    post_aggs[metric_name] = Const(
                        mconf.get('value'),
                        output_name=mconf.get('name', '')
                    )
                elif mconf.get('type') == 'hyperUniqueCardinality':
                    post_aggs[metric_name] = HyperUniqueCardinality(
                        mconf.get('name')
                    )
                else:
                    post_aggs[metric_name] = Postaggregator(
                        mconf.get('fn', "/"),
                        mconf.get('fields', []),
                        mconf.get('name', ''))

        aggregations = OrderedDict()
        for m in self.metrics:
            if m.metric_name in all_metrics:
                aggregations[m.metric_name] = m.json_obj

        rejected_metrics = [
            m.metric_name for m in self.metrics
            if m.is_restricted and
            m.metric_name in aggregations.keys() and
            not sm.has_access('metric_access', m.perm)
        ]

        if rejected_metrics:
            raise MetricPermException(
                "Access to the metrics denied: " + ', '.join(rejected_metrics)
            )

        # the dimensions list with dimensionSpecs expanded
        dimensions = []
        groupby = [gb for gb in groupby if gb in columns_dict]
        for column_name in groupby:
            col = columns_dict.get(column_name)
            dim_spec = col.dimension_spec
            if dim_spec:
                dimensions.append(dim_spec)
            else:
                dimensions.append(column_name)
        qry = dict(
            datasource=self.datasource_name,
            dimensions=dimensions,
            aggregations=aggregations,
            granularity=DruidDatasource.granularity(
                granularity,
                timezone=timezone,
                origin=extras.get('druid_time_origin'),
            ),
            post_aggregations=post_aggs,
            intervals=from_dttm.isoformat() + '/' + to_dttm.isoformat(),
        )

        filters = self.get_filters(filter)
        if filters:
            qry['filter'] = filters

        having_filters = self.get_having_filters(extras.get('having_druid'))
        if having_filters:
            qry['having'] = having_filters

        orig_filters = filters
        if len(groupby) == 0 and not having_filters:
            del qry['dimensions']
            client.timeseries(**qry)
        if not having_filters and len(groupby) == 1:
            qry['threshold'] = timeseries_limit or 1000
            if row_limit and granularity == 'all':
                qry['threshold'] = row_limit
            qry['dimension'] = list(qry.get('dimensions'))[0]
            del qry['dimensions']
            qry['metric'] = list(qry['aggregations'].keys())[0]
            client.topn(**qry)
        elif len(groupby) > 1 or having_filters:
            # If grouping on multiple fields or using a having filter
            # we have to force a groupby query
            if timeseries_limit and is_timeseries:
                order_by = metrics[0] if metrics else self.metrics[0]
                if timeseries_limit_metric:
                    order_by = timeseries_limit_metric
                # Limit on the number of timeseries, doing a two-phases query
                pre_qry = deepcopy(qry)
                pre_qry['granularity'] = "all"
                pre_qry['limit_spec'] = {
                    "type": "default",
                    "limit": timeseries_limit,
                    'intervals': (
                        inner_from_dttm.isoformat() + '/' +
                        inner_to_dttm.isoformat()),
                    "columns": [{
                        "dimension": order_by,
                        "direction": "descending",
                    }],
                }
                client.groupby(**pre_qry)
                query_str += "// Two phase query\n// Phase 1\n"
                query_str += json.dumps(
                    client.query_builder.last_query.query_dict, indent=2)
                query_str += "\n"
                if phase == 1:
                    return query_str
                query_str += (
                    "//\nPhase 2 (built based on phase one's results)\n")
                df = client.export_pandas()
                if df is not None and not df.empty:
                    dims = qry['dimensions']
                    filters = []
                    for unused, row in df.iterrows():
                        fields = []
                        for dim in dims:
                            f = Dimension(dim) == row[dim]
                            fields.append(f)
                        if len(fields) > 1:
                            filt = Filter(type="and", fields=fields)
                            filters.append(filt)
                        elif fields:
                            filters.append(fields[0])

                    if filters:
                        ff = Filter(type="or", fields=filters)
                        if not orig_filters:
                            qry['filter'] = ff
                        else:
                            qry['filter'] = Filter(type="and", fields=[
                                ff,
                                orig_filters])
                    qry['limit_spec'] = None
            if row_limit:
                qry['limit_spec'] = {
                    "type": "default",
                    "limit": row_limit,
                    "columns": [{
                        "dimension": (
                            metrics[0] if metrics else self.metrics[0]),
                        "direction": "descending",
                    }],
                }
            client.groupby(**qry)
        query_str += json.dumps(
            client.query_builder.last_query.query_dict, indent=2)
        return query_str

    def query(self, query_obj):
        qry_start_dttm = datetime.now()
        client = self.cluster.get_pydruid_client()
        query_str = self.get_query_str(
            client=client, query_obj=query_obj, phase=2)
        df = client.export_pandas()

        if df is None or df.size == 0:
            raise Exception(_("No data was returned."))
        df.columns = [
            DTTM_ALIAS if c == 'timestamp' else c for c in df.columns]

        is_timeseries = query_obj['is_timeseries'] \
            if 'is_timeseries' in query_obj else True
        if (
                not is_timeseries and
                DTTM_ALIAS in df.columns):
            del df[DTTM_ALIAS]

        # Reordering columns
        cols = []
        if DTTM_ALIAS in df.columns:
            cols += [DTTM_ALIAS]
        cols += [col for col in query_obj['groupby'] if col in df.columns]
        cols += [col for col in query_obj['metrics'] if col in df.columns]
        df = df[cols]

        time_offset = DruidDatasource.time_offset(query_obj['granularity'])

        def increment_timestamp(ts):
            dt = utils.parse_human_datetime(ts).replace(
                tzinfo=DRUID_TZ)
            return dt + timedelta(milliseconds=time_offset)
        if DTTM_ALIAS in df.columns and time_offset:
            df[DTTM_ALIAS] = df[DTTM_ALIAS].apply(increment_timestamp)

        return QueryResult(
            df=df,
            query=query_str,
            duration=datetime.now() - qry_start_dttm)

    def get_filters(self, raw_filters):  # noqa
        filters = None
        for flt in raw_filters:
            if not all(f in flt for f in ['col', 'op', 'val']):
                continue
            col = flt['col']
            op = flt['op']
            eq = flt['val']
            cond = None
            if op in ('in', 'not in'):
                eq = [
                    types.replace("'", '').strip()
                    if isinstance(types, string_types)
                    else types
                    for types in eq]
            elif not isinstance(flt['val'], string_types):
                eq = eq[0] if len(eq) > 0 else ''
            if col in self.num_cols:
                if op in ('in', 'not in'):
                    eq = [utils.string_to_num(v) for v in eq]
                else:
                    eq = utils.string_to_num(eq)
            if op == '==':
                cond = Dimension(col) == eq
            elif op == '!=':
                cond = ~(Dimension(col) == eq)
            elif op in ('in', 'not in'):
                fields = []
                if len(eq) > 1:
                    for s in eq:
                        fields.append(Dimension(col) == s)
                    cond = Filter(type="or", fields=fields)
                elif len(eq) == 1:
                    cond = Dimension(col) == eq[0]
                if op == 'not in':
                    cond = ~cond
            elif op == 'regex':
                cond = Filter(type="regex", pattern=eq, dimension=col)
            elif op == '>=':
                cond = Dimension(col) >= eq
            elif op == '<=':
                cond = Dimension(col) <= eq
            elif op == '>':
                cond = Dimension(col) > eq
            elif op == '<':
                cond = Dimension(col) < eq
            if filters:
                filters = Filter(type="and", fields=[
                    cond,
                    filters
                ])
            else:
                filters = cond
        return filters

    def _get_having_obj(self, col, op, eq):
        cond = None
        if op == '==':
            if col in self.column_names:
                cond = DimSelector(dimension=col, value=eq)
            else:
                cond = Aggregation(col) == eq
        elif op == '>':
            cond = Aggregation(col) > eq
        elif op == '<':
            cond = Aggregation(col) < eq

        return cond

    def get_having_filters(self, raw_filters):
        filters = None
        reversed_op_map = {
            '!=': '==',
            '>=': '<',
            '<=': '>'
        }

        for flt in raw_filters:
            if not all(f in flt for f in ['col', 'op', 'val']):
                continue
            col = flt['col']
            op = flt['op']
            eq = flt['val']
            cond = None
            if op in ['==', '>', '<']:
                cond = self._get_having_obj(col, op, eq)
            elif op in reversed_op_map:
                cond = ~self._get_having_obj(col, reversed_op_map[op], eq)

            if filters:
                filters = filters & cond
            else:
                filters = cond
        return filters

    @classmethod
    def query_datasources_by_name(
            cls, session, database, datasource_name, schema=None):
        return (
            session.query(cls)
            .filter_by(cluster_name=database.id)
            .filter_by(datasource_name=datasource_name)
            .all()
        )

sa.event.listen(DruidDatasource, 'after_insert', set_perm)
sa.event.listen(DruidDatasource, 'after_update', set_perm)


text:
using System;
using UnityEngine;
using UtyMap.Unity.Animations.Path;
using UtyMap.Unity.Animations.Time;

namespace UtyMap.Unity.Animations
{
    /// <summary> Animates transform position. </summary>
    public class PathAnimation : TransformAnimation
    {
        private readonly IPathInterpolator _pathInterpolator;

        public PathAnimation(Transform transform,
                             ITimeInterpolator timeInterpolator,
                             IPathInterpolator pathInterpolator,
                             TimeSpan duration, bool isLoop = false)
            : base(transform, timeInterpolator, duration, isLoop)
        {
            _pathInterpolator = pathInterpolator;
        }

        /// <inheritdoc />
        protected override void UpdateTransform(Transform transform, float time)
        {
            transform.localPosition = _pathInterpolator.GetPoint(time);
        }
    }
}


text:
import { connect } from 'react-redux';
import GennyMap from './GennyMap.jsx';

function mapStateToProps(state) {
  return { baseEntity: state.baseEntity, sublayout: state.layouts.sublayout };
}

export default connect( mapStateToProps, null )( GennyMap );


text:
using System.ComponentModel.Composition;
using NuGet.Dialog.PackageManagerUI;
using NuGet.VisualStudio;

namespace NuGet.Dialog.Providers {
    [PartCreationPolicy(CreationPolicy.Shared)]
    [Export]
    public sealed class ProviderServices {
        public ILicenseWindowOpener LicenseWindow { get; private set; }
        public IProgressWindowOpener ProgressWindow { get; private set; }
        public IScriptExecutor ScriptExecutor { get; private set; }
        public IOutputConsoleProvider OutputConsoleProvider { get; private set; }

        [ImportingConstructor]
        public ProviderServices(
            ILicenseWindowOpener licenseWindowOpener,
            IProgressWindowOpener progressWindow,
            IScriptExecutor scriptExecutor,
            IOutputConsoleProvider outputConsoleProvider) {

            LicenseWindow = licenseWindowOpener;
            ProgressWindow = progressWindow;
            ScriptExecutor = scriptExecutor;
            OutputConsoleProvider = outputConsoleProvider;
        }
    }
}