text:
<!DOCTYPE html>

	<meta charset="utf-8">
	<title>Phaser Source: d:/wamp/www/phaser/src/pixi/textures/VideoTexture.js</title>

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

	<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">

	<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">

			Phaser API

					Namespaces

							Phaser

							PIXI

					Classes

							Animation

							AnimationManager

							AnimationParser

							ArrayList

							ArraySet

							ArrayUtils

							AudioSprite

							BitmapData

							BitmapText

							Button

							Cache

							Camera

							Canvas

							Circle

							Color

							Device

							DOM

							Easing

							Ellipse

							Events

							Filter

							FlexGrid

							FlexLayer

							Frame

							FrameData

							Game

							GameObjectCreator

							GameObjectFactory

							Gamepad

							GamepadButton

							Graphics

							Group

							Image

							Input

							InputHandler

							Key

							Keyboard

							Line

							LinkedList

							Loader

							LoaderParser

							Math

							Mouse

							MSPointer

							Net

							Particle

							Particles

							Arcade

							Emitter

							Physics

							Arcade

							Body

							Ninja

							AABB

							Body

							Circle

							Tile

							P2

							Body

							BodyDebug

							CollisionGroup

							ContactMaterial

							DistanceConstraint

							FixtureList

							GearConstraint

							InversePointProxy

							LockConstraint

							Material

							PointProxy

							PrismaticConstraint

							RevoluteConstraint

							RotationalSpring

							Spring

							Plugin

							PluginManager

							Point

							Pointer

							Polygon

							QuadTree

							RandomDataGenerator

							Rectangle

							RenderTexture

							RequestAnimationFrame

							RetroFont

							Rope

							ScaleManager

							Signal

							SignalBinding

							SinglePad

							Sound

							SoundManager

							Sprite

							SpriteBatch

							Stage

							State

							StateManager

							Text

							Tile

							Tilemap

							TilemapLayer

							TilemapParser

							Tileset

							TileSprite

							Time

							Timer

							TimerEvent

							Touch

							Tween

							TweenData

							TweenManager

							Utils

							Debug

							World

							AbstractFilter

							AjaxRequest

							AlphaMaskFilter

							AsciiFilter

							AssetLoader

							AtlasLoader

							BaseTexture

							BitmapFontLoader

							BitmapText

							BlurFilter

							BlurXFilter

							BlurYFilter

							CanvasBuffer

							CanvasGraphics

							CanvasMaskManager

							CanvasRenderer

							CanvasTinter

							Circle

							ColorMatrixFilter

							ColorStepFilter

							ComplexPrimitiveShader

							ConvolutionFilter

							CrossHatchFilter

							DisplacementFilter

							DisplayObject

							DisplayObjectContainer

							DotScreenFilter

							Ellipse

							Event

							EventTarget

							FilterBlock

							FilterTexture

							Graphics

							GraphicsData

							GrayFilter

							ImageLoader

							InteractionData

							InteractionManager

							InvertFilter

							JsonLoader

							Matrix

							MovieClip

							NoiseFilter

							NormalMapFilter

							PixelateFilter

							PIXI

							PixiFastShader

							PixiShader

							Point

							Polygon

							PolyK

							PrimitiveShader

							Rectangle

							RenderTexture

							RGBSplitFilter

							Rope

							RoundedRectangle

							SepiaFilter

							SmartBlurFilter

							Spine

							SpineLoader

							SpineTextureLoader

							Sprite

							SpriteBatch

							SpriteSheetLoader

							Stage

							Strip

							StripShader

							Text

							Texture

							TilingSprite

							TiltShiftFilter

							TiltShiftXFilter

							TiltShiftYFilter

							TwistFilter

							VideoTexture

							WebGLBlendModeManager

							WebGLFastSpriteBatch

							WebGLFilterManager

							WebGLRenderer

					Core

Game

Group

World

Loader

Time

Camera

State Manager

Tween Manager

Sound Manager

Input Manager

Scale Manager

					Game Objects

Factory (game.add)

Creator (game.make)

Sprite

Image

Sound

Particle Emitter

Particle

Text

Tween

BitmapText

Tilemap

BitmapData

RetroFont

Button

Animation

Graphics

RenderTexture

TileSprite

					Geometry

Circle

Rectangle

Point

Line

Ellipse

Polygon

					Physics

Arcade Physics

Body

P2 Physics

Body

Spring

CollisionGroup

ContactMaterial

Ninja Physics

Body

					Input

Input Handler

Pointer

Mouse

Keyboard

Key

Gamepad

					Community

Phaser Books

Phaser Github

Phaser Examples

Phaser Plugins

Forum

Stack Overflow

Newsletter

Twitter

IRC

GitTip

Source: d:/wamp/www/phaser/src/pixi/textures/VideoTexture.js

/**
 * A texture of a [playing] Video.
 *
 * See the ["deus" demo](http://www.goodboydigital.com/pixijs/examples/deus/).
 *
 * @class VideoTexture
 * @extends BaseTexture
 * @constructor
 * @param source {HTMLVideoElement}
 * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
 */
PIXI.VideoTexture = function( source, scaleMode )
{
    if( !source ){
        throw new Error( 'No video source element specified.' );
    }

    // hook in here to check if video is already available.
    // PIXI.BaseTexture looks for a source.complete boolean, plus width & height.

    if( (source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA ) && source.width && source.height )
    {
        source.complete = true;
    }

    PIXI.BaseTexture.call( this, source, scaleMode );

    this.autoUpdate = false;
    this.updateBound = this._onUpdate.bind(this);

    if( !source.complete )
    {
        this._onCanPlay = this.onCanPlay.bind(this);

        source.addEventListener( 'canplay', this._onCanPlay );
        source.addEventListener( 'canplaythrough', this._onCanPlay );

        // started playing..
        source.addEventListener( 'play', this.onPlayStart.bind(this) );
        source.addEventListener( 'pause', this.onPlayStop.bind(this) );
    }

};

PIXI.VideoTexture.prototype   = Object.create( PIXI.BaseTexture.prototype );

PIXI.VideoTexture.constructor = PIXI.VideoTexture;

PIXI.VideoTexture.prototype._onUpdate = function()
{
    if(this.autoUpdate)
    {
        window.requestAnimationFrame(this.updateBound);
        this.dirty();
    }
};

PIXI.VideoTexture.prototype.onPlayStart = function()
{
    if(!this.autoUpdate)
    {
        window.requestAnimationFrame(this.updateBound);
        this.autoUpdate = true;
    }
};

PIXI.VideoTexture.prototype.onPlayStop = function()
{
    this.autoUpdate = false;
};

PIXI.VideoTexture.prototype.onCanPlay = function()
{
    if( event.type === 'canplaythrough' )
    {
        this.hasLoaded  = true;

        if( this.source )
        {
            this.source.removeEventListener( 'canplay', this._onCanPlay );
            this.source.removeEventListener( 'canplaythrough', this._onCanPlay );

            this.width      = this.source.videoWidth;
            this.height     = this.source.videoHeight;

            // prevent multiple loaded dispatches..
            if( !this.__loaded ){
                this.__loaded = true;
                this.dispatchEvent( { type: 'loaded', content: this } );
            }
        }
    }
};

PIXI.VideoTexture.prototype.destroy = function()
{
    if( this.source && this.source._pixiId )
    {
        PIXI.BaseTextureCache[ this.source._pixiId ] = null;
        delete PIXI.BaseTextureCache[ this.source._pixiId ];

        this.source._pixiId = null;
        delete this.source._pixiId;
    }

    PIXI.BaseTexture.prototype.destroy.call( this );
};

/**
 * Mimic Pixi BaseTexture.from.... method.
 *
 * @static
 * @method baseTextureFromVideo
 * @param video {HTMLVideoElement}
 * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
 * @return {VideoTexture}
 */
PIXI.VideoTexture.baseTextureFromVideo = function( video, scaleMode )
{
    if( !video._pixiId )
    {
        video._pixiId = 'video_' + PIXI.TextureCacheIdGenerator++;
    }

    var baseTexture = PIXI.BaseTextureCache[ video._pixiId ];

    if( !baseTexture )
    {
        baseTexture = new PIXI.VideoTexture( video, scaleMode );
        PIXI.BaseTextureCache[ video._pixiId ] = baseTexture;
    }

    return baseTexture;
};

/**
 * Mimic Pixi BaseTexture.from.... method.
 *
 * @static
 * @method textureFromVideo
 * @param video {HTMLVideoElement}
 * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
 * @return {Texture} A Texture, but not a VideoTexture.
 */
PIXI.VideoTexture.textureFromVideo = function( video, scaleMode )
{
    var baseTexture = PIXI.VideoTexture.baseTextureFromVideo( video, scaleMode );
    return new PIXI.Texture( baseTexture );
};

/**
 * Mimic Pixi BaseTexture.from.... method.
 *
 * @static
 * @method fromUrl
 * @param videoSrc {String} The URL for the video.
 * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
 * @return {VideoTexture}
 */
PIXI.VideoTexture.fromUrl = function( videoSrc, scaleMode )
{
    var video = document.createElement('video');
    video.src = videoSrc;
    video.autoPlay = true;
    video.play();
    return PIXI.VideoTexture.textureFromVideo( video, scaleMode);
};

		Phaser Copyright © 2012-2014 Photon Storm Ltd.

		Documentation generated by JSDoc 3.3.0-dev
		on Tue Jan 06 2015 06:31:49 GMT-0000 (GMT) using the DocStrap template.


text:
#ifndef FRAMELISTENER_H
#define FRAMELISTENER_H

#include <NatNetLinux/NatNet.h>
#include <NatNetLinux/NatNetPacket.h>
#include <NatNetLinux/NatNetSender.h>
#include <boost/thread.hpp>
#include <boost/circular_buffer.hpp>
#include <utility>
#include <time.h>

/*!
 * \brief Thread to listen for MocapFrame data.
 * \author Philip G. Lee
 *
 * This class listens for MocapFrame data on a given socket.
 * It uses a circular buffer to store the frame data, and provides a
 * thread-safe interface to query for the most recent frames.
 */
class FrameListener
{
public:

   /*!
    * \brief Constructor
    *
    * \param sd The socket on which to listen.
    * \param nnMajor NatNet major version.
    * \param nnMinor NatNet minor version.
    * \param bufferSize number of frames in the \c frames() buffer.
    */
   FrameListener(int sd = -1, unsigned char nnMajor=0, unsigned char nnMinor=0, size_t bufferSize=64 ) :
      _thread(0),
      _sd(sd),
      _nnMajor(nnMajor),
      _nnMinor(nnMinor),
      _framesMutex(),
      _frames(bufferSize),
      _run(false)
   {
   }

   ~FrameListener()
   {
      if( running() )
         stop();
      // I think this may be blocking unless the thread is stopped.
      delete _thread;
   }

   //! \brief Begin the listening in new thread. Non-blocking.
   void start()
   {
      _run = true;
      _thread = new boost::thread( &FrameListener::_work, this, _sd);
   }

   //! \brief Cause the thread to stop. Non-blocking.
   void stop()
   {
      _run = false;
   }

   //! \brief Return true iff the listener thread is running. Non-blocking.
   bool running()
   {
      return _run;
   }

   //! \brief Wait for the listening thread to stop. Blocking.
   void join()
   {
      if(_thread)
         _thread->join();
   }

   // Data access =============================================================

   /*!
    * \brief Get the latest frame and remove it from the internal buffer. Thread-safe.
    *
    * This function may block while reading the buffer. \c success will be false only if there
    * is no more data in the internal buffer.
    *
    * \param success
    *    input parameter. If not null, its value is set to true if the return
    *    value is valid, and false otherwise.
    * \returns
    *    most recent frame/timestamp pair if the internal buffer has data.
    *    Otherwise, returns an invalid frame. The timestamp is the result of
    *    \c clock_gettime( \c CLOCK_REALTIME, ...) when the data is read
    *    from the UDP interface.
    *
    * \sa tryPop()
    */
   std::pair<MocapFrame, struct timespec> pop(bool* success=0)
   {
      std::pair<MocapFrame, struct timespec> ret;
      bool retSuccess = false;

      _framesMutex.lock();
      if( !_frames.empty() )
      {
         retSuccess = true;
         ret = _frames.back();
         _frames.pop_back();
      }
      _framesMutex.unlock();

      if( success )
         *success = retSuccess;
      return ret;
   }

   /*!
    * \brief Get the latest frame and remove it from the internal buffer. Thread-safe *non-blocking*.
    *
    * This function is just like \c pop(), but never blocks. If you are willing
    * to wait to acquire the lock to read the internal data buffer, then use
    * the blocking version \c pop(). If you use \c tryPop(),
    * it will not block, but \c success will be false if either the
    * buffer is currently being written, *or* if there is no more data.
    *
    * \param success
    *    input parameter. If not null, its value is set to true if the return
    *    value is valid, and false otherwise.
    * \returns
    *    most recent frame/timestamp pair if the internal buffer has data
    *    *and* is available for reading immediately.
    *    Otherwise, returns an invalid frame. The timestamp is the result of
    *    \c clock_gettime( \c CLOCK_REALTIME, ...) when the data is read
    *    from the UDP interface.
    *
    * \sa pop()
    */
   std::pair<MocapFrame, struct timespec> tryPop(bool* success=0)
   {
      std::pair<MocapFrame, struct timespec> ret;
      bool retSuccess = false;

      if( _framesMutex.try_lock() )
      {
         if( !_frames.empty() )
         {
            retSuccess = true;
            ret = _frames.back();
            _frames.pop_back();
         }
         _framesMutex.unlock();
      }

      if( success )
         *success = retSuccess;
      return ret;
   }

   //--------------------------------------------------------------------------

private:

   boost::thread* _thread;
   int _sd;
   unsigned char _nnMajor;
   unsigned char _nnMinor;
   mutable boost::mutex _framesMutex;
   boost::circular_buffer< std::pair<MocapFrame, struct timespec> > _frames;
   bool _run;

   void _work(int sd)
   {
      printf(" Frame listener work started\n");

      NatNetPacket nnp;
      struct timespec ts;
      size_t dataBytes;

      fd_set rfds, exeptfds;
      struct timeval timeout;

      while(_run)
      {
        fprintf(stderr," Frame listener: work loop\n");
         // Wait for at most 1 second until the socket has data (read()
         // will not block). Otherwise, continue. This gives outside threads
         // a chance to kill this thread every second.
         timeout.tv_sec = 5; timeout.tv_usec = 0;
         FD_ZERO(&rfds); FD_SET(sd, &rfds);

         // Handle errors on the socket
         FD_ZERO(&exeptfds); FD_SET(sd,&exeptfds);

         fprintf(stderr,"about to select \n");
         int selcRslt; // store the result of calling select
         if( ( selcRslt = select(sd+1, &rfds, 0, &exeptfds, &timeout)) <= 0 )
         {
            if(selcRslt == 0)
                 printf("(Time expired)continueuing ...\n");
            else
                  printf("(Select failed) continueing ... \n");
            continue;
         }
         fprintf(stderr,"Fram listener: finished select()\n");
         //clock_gettime( CLOCK_REALTIME, &ts );

         dataBytes = read( sd, nnp.rawPtr(), nnp.maxLength() );
         fprintf(stderr,"frame thread called read()");
         if( dataBytes > 0 && nnp.iMessage() == NatNetPacket::NAT_FRAMEOFDATA )
         {
            MocapFrame mFrame(_nnMajor,_nnMinor);
            mFrame.unpack(nnp.rawPayloadPtr());
            _framesMutex.lock();
               _frames.push_back(std::make_pair(mFrame,ts));
            _framesMutex.unlock();
         }
      }
   }
};

#endif /*FRAMELISTENER_H*/

redpajama_set_name: RedPajamaGithub


text:
package org.apache.pinot.core.query.optimizer;

import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.pinot.common.request.BrokerRequest;
import org.apache.pinot.common.request.Expression;
import org.apache.pinot.common.request.FilterQuery;
import org.apache.pinot.common.request.PinotQuery;
import org.apache.pinot.common.utils.request.FilterQueryTree;
import org.apache.pinot.common.utils.request.RequestUtils;
import org.apache.pinot.core.query.optimizer.filter.FilterOptimizer;
import org.apache.pinot.core.query.optimizer.filter.FlattenAndOrFilterOptimizer;
import org.apache.pinot.core.query.optimizer.filter.MergeEqInFilterOptimizer;
import org.apache.pinot.core.query.optimizer.filter.MergeRangeFilterOptimizer;
import org.apache.pinot.spi.data.Schema;

public class QueryOptimizer {
  private static final List<FilterOptimizer> FILTER_OPTIMIZERS = Arrays
      .asList(new FlattenAndOrFilterOptimizer(), new MergeEqInFilterOptimizer(), new MergeRangeFilterOptimizer());

  /**
   * Optimizes the given PQL query.
   */
  public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) {
    FilterQuery filterQuery = brokerRequest.getFilterQuery();
    if (filterQuery != null) {
      FilterQueryTree filterQueryTree =
          RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap());
      for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) {
        filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema);
      }
      RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest);
    }
  }

  /**
   * Optimizes the given SQL query.
   */
  public void optimize(PinotQuery pinotQuery, @Nullable Schema schema) {
    Expression filterExpression = pinotQuery.getFilterExpression();
    if (filterExpression != null) {
      for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) {
        filterExpression = filterOptimizer.optimize(filterExpression, schema);
      }
      pinotQuery.setFilterExpression(filterExpression);
    }
  }
}


text:
// flow-typed signature: 35b8847c7e74d9bc0b85101714beb05f
// flow-typed version: <<STUB>>/get-line-from-pos_v^1.0.0/flow_v0.49.1

/**
 * This is an autogenerated libdef stub for:
 *
 *   'get-line-from-pos'
 *
 * Fill this stub out by replacing all the `any` types.
 *
 * Once filled out, we encourage you to share your work with the
 * community by sending a pull request to:
 * https://github.com/flowtype/flow-typed
 */

declare module 'get-line-from-pos' {
  declare module.exports: any;
}

/**
 * We include stubs for each file inside this npm package in case you need to
 * require those files directly. Feel free to delete any files that aren't
 * needed.
 */

// Filename aliases
declare module 'get-line-from-pos/index' {
  declare module.exports: $Exports<'get-line-from-pos'>;
}
declare module 'get-line-from-pos/index.js' {
  declare module.exports: $Exports<'get-line-from-pos'>;
}


text:
package hudson.model;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequest;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.Fingerprinter;
import jenkins.fingerprints.FileFingerprintStorage;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.CreateFileBuilder;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;

import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.logging.Level;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class FingerprintSEC2023Test {

    @Rule
    public JenkinsRule rule = new JenkinsRule();

    @Rule
    public LoggerRule loggerRule = new LoggerRule();

    @Test
    public void checkNormalFingerprint() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        Fingerprint loadedFingerprint = Fingerprint.load(fp.getHashString());
        assertEquals(fp.getDisplayName(), loadedFingerprint.getDisplayName());
    }

    @Test
    public void checkNormalFingerprintWithWebClient() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");

        Page page = rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), "fingerprint/" + fp.getHashString() + "/")));
        assertEquals(200, page.getWebResponse().getStatusCode());

        // could also be reached using static/<anything>/
        Page page2 = rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), "static/abc/fingerprint/" + fp.getHashString() + "/")));
        assertEquals(200, page2.getWebResponse().getStatusCode());
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryEmptyFileExistence() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        File targetFile = new File(rule.jenkins.getRootDir(), "../cf1.xml");
        Util.touch(targetFile);
        // required as cf1.xml is outside the temporary folders created for the test
        // and if the test is failing, it will not be deleted
        targetFile.deleteOnExit();
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);
        String id = first + second + "/../../" + first + "/" + second + "/../../../../cf1";
        Fingerprint fingerprint = Fingerprint.load(id);
        assertNull(fingerprint);
        assertTrue(targetFile.exists());
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryEmptyFileExistenceWithWebClient() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        File targetFile = new File(rule.jenkins.getRootDir(), "../cf2.xml");
        Util.touch(targetFile);
        targetFile.deleteOnExit();
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);
        rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), "static/abc/fingerprint/" + first + second + "%2f..%2f..%2f" + first + "%2f" + second + "%2f..%2f..%2f..%2f..%2fcf2/")));
        assertTrue(targetFile.exists());
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryFileExistence() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        File sourceFile = new File(rule.jenkins.getRootDir(), "config.xml");
        File targetFile = new File(rule.jenkins.getRootDir(), "../cf3.xml");
        Util.copyFile(sourceFile, targetFile);
        targetFile.deleteOnExit();
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);
        String id = first + second + "/../../" + first + "/" + second + "/../../../../cf3";
        Fingerprint fingerprint = Fingerprint.load(id);
        assertNull(fingerprint);
        assertTrue(targetFile.exists());
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryFileExistenceWithWebClient() throws Exception {
        loggerRule.record(FileFingerprintStorage.class, Level.WARNING)
                .record(FileFingerprintStorage.class, Level.WARNING)
                .capture(1000);

        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        File sourceFile = new File(rule.jenkins.getRootDir(), "config.xml");
        File targetFile = new File(rule.jenkins.getRootDir(), "../cf4.xml");
        Util.copyFile(sourceFile, targetFile);
        targetFile.deleteOnExit();
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);

        rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), "static/abc/fingerprint/" + first + second + "%2f..%2f..%2f" + first + "%2f" + second + "%2f..%2f..%2f..%2f..%2fcf4/")));
        assertTrue(targetFile.exists());
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryFileNonexistence() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);
        String id = first + second + "/../../" + first + "/" + second + "/../../../../cf5";
        Fingerprint fingerprint = Fingerprint.load(id);
        assertNull(fingerprint);
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryFileNonexistenceWithWebClient() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);
        rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), "static/abc/fingerprint/" + first + second + "%2f..%2f..%2f" + first + "%2f" + second + "%2f..%2f..%2f..%2f..%2fcf6/")));
    }

    @Test
    @Issue("SECURITY-2023")
    public void checkArbitraryFingerprintConfigFileExistenceWithWebClient() throws Exception {
        FreeStyleProject project = rule.createFreeStyleProject();
        project.getBuildersList().add(new CreateFileBuilder("test.txt", "Hello, world!"));
        ArtifactArchiver archiver = new ArtifactArchiver("test.txt");
        archiver.setFingerprint(true);
        project.getPublishersList().add(archiver);
        FreeStyleBuild build = rule.buildAndAssertSuccess(project);

        Fingerprint fp = getFingerprint(build, "test.txt");
        File targetFile = new File(rule.jenkins.getRootDir(), "../cf7.xml");
        FileUtils.writeStringToFile(targetFile, TEST_FINGERPRINT_CONFIG_FILE_CONTENT, StandardCharsets.UTF_8);
        targetFile.deleteOnExit();

        String first = fp.getHashString().substring(0,2);
        String second = fp.getHashString().substring(2,4);

        Page page = null;
        try {
            // that file exists, so we need to ensure if it's returned, the content is not the expected one from the test data.
            String partialUrl = "static/abc/fingerprint/" + first + second + "%2f..%2f..%2f" + first + "%2f" + second + "%2f..%2f..%2f..%2f..%2fcf7/";
            page = rule.createWebClient().getPage(new WebRequest(new URL(rule.getURL(), partialUrl)));
        } catch (FailingHttpStatusCodeException e) {
            // expected refusal after the correction
            assertEquals(500, e.getStatusCode());
        }
        if (page != null) {
            // content retrieval occurred before the correction, we have to check the content to ensure non-regression
            String pageContent = page.getWebResponse().getContentAsString();
            assertThat(pageContent, not(containsString(TEST_FINGERPRINT_ID)));
        }
        assertTrue(targetFile.exists());
    }

    @NonNull
    private Fingerprint getFingerprint(@CheckForNull Run<?, ?> run, @NonNull String filename) {
        assertNotNull("Input run is null", run);
        Fingerprinter.FingerprintAction action = run.getAction(Fingerprinter.FingerprintAction.class);
        assertNotNull("Fingerprint action has not been created in " + run, action);
        Map<String, Fingerprint> fingerprints = action.getFingerprints();
        final Fingerprint fp = fingerprints.get(filename);
        assertNotNull("No reference to '" + filename + "' from the Fingerprint action", fp);
        return fp;
    }

    private static final String TEST_FINGERPRINT_ID = "0123456789abcdef0123456789abcdef";
    private static final String TEST_FINGERPRINT_CONFIG_FILE_CONTENT = "<?xml version='1.1' encoding='UTF-8'?>\n" +
            "<fingerprint>\n" +
            "  <timestamp>2020-10-27 14:01:22.551 UTC</timestamp>\n" +
            "  <original>\n" +
            "    <name>test0</name>\n" +
            "    <number>1</number>\n" +
            "  </original>\n" +
            "  <md5sum>"+TEST_FINGERPRINT_ID+"</md5sum>\n" +
            "  <fileName>test.txt</fileName>\n" +
            "  <usages>\n" +
            "  </usages>\n" +
            "  <facets/>\n" +
            "</fingerprint>";
}


text:
class CreateAdoptionRequests < ActiveRecord::Migration
  def change
    create_table :adoption_requests do |t|
      t.string :group_name
      t.integer :no_of_volunteers
      t.string :first_name
      t.string :last_name
      t.string :add1
      t.string :city
      t.string :state
      t.string :zipcode
      t.string :email
      t.string :phone
      t.references :category, index: true

      t.timestamps
    end
  end
end


text:
package main

import (
	"bytes"
	"database/sql"
	"encoding/gob"
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"

	"github.com/Cloud-Foundations/golib/pkg/awsutil/metadata"
	"github.com/Cloud-Foundations/golib/pkg/awsutil/secretsmgr"
	_ "github.com/lib/pq"
	_ "github.com/mattn/go-sqlite3"
)

const (
	userProfilePrefix = "profile_"
	userProfileSuffix = ".gob"
	profileDBFilename = "userProfiles.sqlite3"
	cachedDBFilename  = "cachedDB.sqlite3"

	dbConnectionLifetimeDefault = time.Minute * 15
	dbConnectionLifetimeMaximum = time.Hour

	dbSyncDelayDefault = time.Second * 3
	dbSyncDelayMinimum = time.Second
	dbSyncDelayMaximum = time.Minute

	dbSyncIntervalDefault = time.Minute * 5
	dbSyncIntervalMinimum = time.Second * 5
	dbSyncIntervalMaximum = time.Minute * 15
)

func (config *ProfileStorageConfig) setSyncLimits() {
	if config.SyncDelay < 1 {
		config.SyncDelay = dbSyncDelayDefault
	} else if config.SyncDelay < dbSyncDelayMinimum {
		config.SyncDelay = dbSyncDelayMinimum
	} else if config.SyncDelay > dbSyncDelayMaximum {
		config.SyncDelay = dbSyncDelayMaximum
	}
	if config.SyncInterval < 1 {
		config.SyncInterval = dbSyncIntervalDefault
	} else if config.SyncInterval < dbSyncIntervalMinimum {
		config.SyncInterval = dbSyncIntervalMinimum
	} else if config.SyncInterval > dbSyncIntervalMaximum {
		config.SyncInterval = dbSyncIntervalMaximum
	}
	if config.ConnectionLifetime < 1 {
		config.ConnectionLifetime = dbConnectionLifetimeDefault
	}
	if config.ConnectionLifetime < config.SyncInterval {
		config.ConnectionLifetime = config.SyncInterval
	} else if config.ConnectionLifetime > dbConnectionLifetimeMaximum {
		config.ConnectionLifetime = dbConnectionLifetimeMaximum
	}
}

func (state *RuntimeState) expandStorageUrl() error {
	config := &state.Config.ProfileStorage
	if config.AwsSecretId == "" {
		return nil
	}
	metadataClient, err := metadata.GetMetadataClient()
	if err != nil {
		return err
	}
	secrets, err := secretsmgr.GetAwsSecret(metadataClient, config.AwsSecretId,
		state.logger)
	if err != nil {
		return err
	}
	config.StorageUrl = os.Expand(config.StorageUrl,
		func(variableName string) string {
			return secrets[variableName]
		})
	return nil
}

func initDB(state *RuntimeState) (err error) {
	logger.Debugf(3, "Top of initDB")
	state.Config.ProfileStorage.setSyncLimits()
	//open/create cache DB first
	cacheDBFilename := filepath.Join(state.Config.Base.DataDirectory,
		cachedDBFilename)
	state.cacheDB, err = initFileDBSQLite(cacheDBFilename, state.cacheDB)
	if err != nil {
		logger.Printf("Failure on creation of cacheDB")
		return err
	}
	logger.Debugf(3, "storage=%s", state.Config.ProfileStorage.StorageUrl)
	storageURL := state.Config.ProfileStorage.StorageUrl
	if storageURL == "" {
		storageURL = "sqlite:"
	}
	splitString := strings.SplitN(storageURL, ":", 2)
	if len(splitString) < 1 {
		logger.Printf("invalid string")
		err := errors.New("Bad storage url string")
		return err
	}
	state.remoteDBQueryTimeout = time.Second * 2
	go state.BackgroundDBCopy(state.Config.ProfileStorage.SyncDelay)
	switch splitString[0] {
	case "sqlite":
		logger.Printf("doing sqlite")
		return initDBSQlite(state)
	case "postgresql":
		logger.Printf("doing postgres")
		return initDBPostgres(state)
	default:
		logger.Printf("invalid storage url string")
		err := errors.New("Bad storage url string")
		return err
	}
}

func initDBPostgres(state *RuntimeState) (err error) {
	state.dbType = "postgres"
	state.db, err = sql.Open("postgres", state.Config.ProfileStorage.StorageUrl)
	if err != nil {
		return err
	}
	/// This should be changed to take care of DB schema
	if true {
		sqlStmt := `create table if not exists user_profile (id serial not null primary key, username text unique, profile_data bytea);`
		_, err = state.db.Exec(sqlStmt)
		if err != nil {
			logger.Printf("init postgres err: %s: %q\n", err, sqlStmt)
			return err
		}
		sqlStmt = `create table if not exists expiring_signed_user_data(id serial not null primary key, username text not null, jws_data text not null, type integer not null, expiration_epoch integer not null, update_epoch integer not null, UNIQUE(username,type));`
		_, err = state.db.Exec(sqlStmt)
		if err != nil {
			logger.Printf("init postgres err: %s: %q\n", err, sqlStmt)
			return err
		}
	}
	// Ensure that broken connections are replaced.
	state.db.SetConnMaxLifetime(state.Config.ProfileStorage.ConnectionLifetime)
	return nil
}

// This call initializes the database if it does not exist.
func initDBSQlite(state *RuntimeState) (err error) {
	state.dbType = "sqlite"
	dbFilename := filepath.Join(state.Config.Base.DataDirectory,
		profileDBFilename)
	state.db, err = initFileDBSQLite(dbFilename, state.db)
	if err != nil {
		return err
	}
	state.db.SetMaxIdleConns(0) // Make the DB NFS-friendly.
	return nil
}

var sqliteinitializationStatements = []string{
	`create table if not exists user_profile (id integer not null primary key, username text unique, profile_data blob);`,
	`create table if not exists expiring_signed_user_data(id integer not null primary key, username text not null, jws_data text not null, type integer not null, expiration_epoch integer not null, update_epoch integer no null, UNIQUE(username,type));`,
}

func initializeSQLitetables(db *sql.DB) error {
	for _, sqlStmt := range sqliteinitializationStatements {
		logger.Debugf(2, "initializing sqlite, statement =%q", sqlStmt)
		_, err := db.Exec(sqlStmt)
		if err != nil {
			logger.Printf("%s: %q\n", err, sqlStmt)
			return err
		}
	}
	return nil
}

// This call initializes the database if it does not exist.
// TODO: update  to perform auto-updates of the db.
func initFileDBSQLite(dbFilename string, currentDB *sql.DB) (*sql.DB, error) {
	if _, err := os.Stat(dbFilename); os.IsNotExist(err) {
		//CREATE NEW DB
		fileDB, err := sql.Open("sqlite3", dbFilename)
		if err != nil {
			logger.Printf("Failure creating new db: %s", dbFilename)
			return nil, err
		}
		logger.Printf("post DB open")
		err = initializeSQLitetables(fileDB)
		if err != nil {
			return nil, err
		}
		return fileDB, nil
	}
	// try open the DB
	if currentDB == nil {
		fileDB, err := sql.Open("sqlite3", dbFilename)
		if err != nil {
			return nil, err
		}
		err = initializeSQLitetables(fileDB)
		if err != nil {
			return nil, err
		}
		return fileDB, nil
	}
	return currentDB, nil
}

func (state *RuntimeState) BackgroundDBCopy(initialSleep time.Duration) {
	time.Sleep(initialSleep)
	for {
		logger.Debugf(0, "starting db copy")
		err := copyDBIntoSQLite(state.db, state.cacheDB, "sqlite")
		if err != nil {
			logger.Printf("err='%s'", err)
		} else {
			logger.Debugf(0, "db copy success")
		}
		cleanupDBData(state.db)
		cleanupDBData(state.cacheDB)
		time.Sleep(state.Config.ProfileStorage.SyncInterval)
	}
}

func cleanupDBData(db *sql.DB) error {
	if db == nil {
		err := errors.New("nil database on cleanup")
		return err
	}
	queryStr := fmt.Sprintf(
		"DELETE from expiring_signed_user_data WHERE expiration_epoch < %d",
		time.Now().Unix())
	rows, err := db.Query(queryStr)
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer rows.Close()
	return nil
}

func copyDBIntoSQLite(source, destination *sql.DB,
	destinationType string) error {
	if source == nil || destination == nil {
		err := errors.New("nil databases")
		return err
	}
	// Copy user profiles
	rows, err := source.Query("SELECT username,profile_data FROM user_profile")
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer rows.Close()
	queryStr := fmt.Sprintf(
		"SELECT username, type, jws_data, expiration_epoch,update_epoch FROM expiring_signed_user_data WHERE expiration_epoch > %d",
		time.Now().Unix())
	genericRows, err := source.Query(queryStr)
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer genericRows.Close()
	tx, err := destination.Begin()
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer tx.Rollback()
	deleteProfilesQueryStr := fmt.Sprintf("DELETE from user_profile ")
	if rows, err := destination.Query(deleteProfilesQueryStr); err != nil {
		logger.Printf("err='%s'", err)
		return err
	} else {
		rows.Close()
	}
	stmtText := saveUserProfileStmt[destinationType]
	stmt, err := tx.Prepare(stmtText)
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer stmt.Close()
	for rows.Next() {
		var (
			username     string
			profileBytes []byte
		)
		if err := rows.Scan(&username, &profileBytes); err != nil {
			logger.Printf("err='%s'", err)
			return err
		}
		_, err = stmt.Exec(username, profileBytes)
		if err != nil {
			logger.Printf("err='%s'", err)
			return err
		}
	}
	if err := rows.Err(); err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	expiringUpsertText := saveSignedUserDataStmt[destinationType]
	expiringUpsertStmt, err := tx.Prepare(expiringUpsertText)
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	defer expiringUpsertStmt.Close()
	for genericRows.Next() {
		var (
			username        string
			dataType        int
			jwsData         string
			expirationEpoch int64
			updateEpoch     int64
		)
		if err := genericRows.Scan(&username, &dataType, &jwsData,
			&expirationEpoch, &updateEpoch); err != nil {
			logger.Printf("err='%s'", err)
			return err
		}
		//username, type, jws_data, expiration_epoch, update_epoch
		_, err = expiringUpsertStmt.Exec(username, dataType, jwsData,
			expirationEpoch, updateEpoch)
		if err != nil {
			logger.Printf("err='%s'", err)
			return err
		}
	}
	err = tx.Commit()
	if err != nil {
		logger.Printf("err='%s'", err)
		return err
	}
	return nil
}

var getUsersStmt = map[string]string{
	"sqlite":   "select username from user_profile order by username",
	"postgres": "select username from user_profile order by username",
}

type getUsersData struct {
	Names []string
	Err   error
}

func gatherUsers(stmt *sql.Stmt) ([]string, error) {
	rows, err := stmt.Query()
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var names []string
	for rows.Next() {
		var name string
		if err := rows.Scan(&name); err != nil {
			return nil, err
		}
		names = append(names, name)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return names, nil
}

func (state *RuntimeState) GetUsers() ([]string, bool, error) {
	ch := make(chan getUsersData, 1)
	start := time.Now()
	go func() {
		stmtText := getUsersStmt[state.dbType]
		stmt, err := state.db.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing getUsers statement primary DB: %s",
				err)
			return
		}
		defer stmt.Close()
		if state.remoteDBQueryTimeout == 0 {
			time.Sleep(10 * time.Millisecond)
		}
		names, dbErr := gatherUsers(stmt)
		ch <- getUsersData{Names: names, Err: dbErr}
		close(ch)
	}()
	select {
	case dbMessage := <-ch:
		if dbMessage.Err != nil {
			logger.Printf("Problem with db ='%s'", dbMessage.Err)
		} else {
			metricLogExternalServiceDuration("storage-read", time.Since(start))
		}
		return dbMessage.Names, false, dbMessage.Err
	case <-time.After(state.remoteDBQueryTimeout):
		logger.Println("GetUsers: timed out on primary DB")
		stmtText := getUsersStmt["sqlite"]
		stmt, err := state.cacheDB.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing getUsers statement cached DB: %s",
				err)
			return nil, false, err
		}
		defer stmt.Close()
		names, dbErr := gatherUsers(stmt)
		if dbErr != nil {
			logger.Printf("Problem with db = '%s'", err)
		} else {
			logger.Println("GetUsers: got data from DB cache")
		}
		return names, true, dbErr
	}
}

var loadUserProfileStmt = map[string]string{
	"sqlite":   "select profile_data from user_profile where username = ?",
	"postgres": "select profile_data from user_profile where username = $1",
}

/// Adding api to be load/save per user

// Notice: each operation load/save should be atomic.

type loadUserProfileData struct {
	//fromDB       bool
	ProfileBytes []byte
	Err          error
}

// If there a valid user profile returns: profile, true nil
// If there is NO user profile returns default_object, false, nil
// Any other case: nil, false, error
func (state *RuntimeState) LoadUserProfile(username string) (
	profile *userProfile, ok bool, fromCache bool, err error) {
	var defaultProfile userProfile
	defaultProfile.U2fAuthData = make(map[int64]*u2fAuthData)
	defaultProfile.TOTPAuthData = make(map[int64]*totpAuthData)
	ch := make(chan loadUserProfileData, 1)
	start := time.Now()
	go func(username string) { //loads profile from DB
		var profileMessage loadUserProfileData
		stmtText := loadUserProfileStmt[state.dbType]
		stmt, err := state.db.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing statement LoadUsers primary DB: %s",
				err)
			return
		}
		defer stmt.Close()
		// if the remoteDBQueryTimeout == 0 this means we are actuallty trying
		// to force the cached db. In single core systems, we need to ensure
		// this goroutine yields to sthis sleep is necesary
		if state.remoteDBQueryTimeout == 0 {
			time.Sleep(10 * time.Millisecond)
		}
		profileMessage.Err = stmt.QueryRow(username).Scan(
			&profileMessage.ProfileBytes)
		ch <- profileMessage
	}(username)
	var profileBytes []byte
	fromCache = false
	select {
	case dbMessage := <-ch:
		err = dbMessage.Err
		if err != nil {
			if err.Error() == "sql: no rows in result set" {
				logger.Printf("err='%s'", err)
				return &defaultProfile, false, fromCache, nil
			} else {
				logger.Printf("Problem with db ='%s'", err)
				return nil, false, fromCache, err
			}
		}
		metricLogExternalServiceDuration("storage-read", time.Since(start))
		profileBytes = dbMessage.ProfileBytes
	case <-time.After(state.remoteDBQueryTimeout):
		logger.Println("LoadUserProfile: timed out on primary DB")
		fromCache = true
		// load from cache
		stmtText := loadUserProfileStmt["sqlite"]
		stmt, err := state.cacheDB.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing statement LoadUsers cache DB: %s",
				err)
			return nil, false, false, err
		}
		defer stmt.Close()
		err = stmt.QueryRow(username).Scan(&profileBytes)
		if err != nil {
			if err.Error() == "sql: no rows in result set" {
				logger.Printf("err='%s'", err)
				return &defaultProfile, false, true, nil
			} else {
				logger.Printf("Problem with db ='%s'", err)
				return nil, false, true, err
			}
		}
		logger.Println("LoadUserProfile: got data from DB cache")
	}
	logger.Debugf(10, "profile bytes len=%d", len(profileBytes))
	//gobReader := bytes.NewReader(fileBytes)
	gobReader := bytes.NewReader(profileBytes)
	decoder := gob.NewDecoder(gobReader)
	err = decoder.Decode(&defaultProfile)
	if err != nil {
		return nil, false, fromCache, err
	}
	logger.Debugf(1, "loaded profile=%+v", defaultProfile)
	return &defaultProfile, true, fromCache, nil
}

var saveUserProfileStmt = map[string]string{
	"sqlite":   "insert or replace into user_profile(username, profile_data) values(?, ?)",
	"postgres": "insert into user_profile(username, profile_data) values ($1,$2) on CONFLICT(username) DO UPDATE set  profile_data = excluded.profile_data",
}

func (state *RuntimeState) SaveUserProfile(username string,
	profile *userProfile) error {
	var gobBuffer bytes.Buffer
	encoder := gob.NewEncoder(&gobBuffer)
	if err := encoder.Encode(profile); err != nil {
		return err
	}
	start := time.Now()
	//insert into DB
	tx, err := state.db.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback()
	stmtText := saveUserProfileStmt[state.dbType]
	stmt, err := tx.Prepare(stmtText)
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(username, gobBuffer.Bytes())
	if err != nil {
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	metricLogExternalServiceDuration("storage-save", time.Since(start))
	return nil
}

var deleteUserProfileStmt = map[string]string{
	"sqlite":   "delete from  user_profile where username = ?",
	"postgres": "delete from  user_profile where username = $1",
}

func (state *RuntimeState) DeleteUserProfile(username string) error {
	//delete from DB
	tx, err := state.db.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback()
	stmtText := deleteUserProfileStmt[state.dbType]
	stmt, err := tx.Prepare(stmtText)
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(username)
	if err != nil {
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	return nil
}

var deleteSignedUserDataStmt = map[string]string{
	"sqlite":   "delete from expiring_signed_user_data where username = ? and type = ?",
	"postgres": "delete from expiring_signed_user_data where username = $1 and type = $2",
}

func (state *RuntimeState) DeleteSigned(username string, dataType int) error {
	//insert into DB
	tx, err := state.db.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback()
	stmtText := deleteSignedUserDataStmt[state.dbType]
	stmt, err := tx.Prepare(stmtText)
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(username, dataType)
	if err != nil {
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	return nil
}

type getSignedData struct {
	JWSData string
	Err     error
}

var getSignedUserDataStmt = map[string]string{
	"sqlite":   "select jws_data from expiring_signed_user_data where username = ? and type =? and expiration_epoch > ?",
	"postgres": "select jws_data from expiring_signed_user_data where username = $1 and type = $2 and expiration_epoch > $3",
}

func (state *RuntimeState) GetSigned(username string,
	dataType int) (bool, string, error) {
	logger.Printf("top of GetSigned")
	//var jwsData string
	ch := make(chan getSignedData, 1)
	//start := time.Now()
	go func(username string, dataType int) { //loads profile from DB
		var signedDataMessage getSignedData
		stmtText := getSignedUserDataStmt[state.dbType]
		stmt, err := state.db.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing statement GetSigned Primary DB: %s",
				err)
			return
		}
		defer stmt.Close()
		if state.remoteDBQueryTimeout == 0 {
			time.Sleep(10 * time.Millisecond)
		}
		signedDataMessage.Err = stmt.QueryRow(username, dataType,
			time.Now().Unix()).Scan(&signedDataMessage.JWSData)
		ch <- signedDataMessage
	}(username, dataType)
	var jwsData string
	select {
	case dbMessage := <-ch:
		logger.Debugf(2, "got data from db. dbMessage=%+v", dbMessage)
		err := dbMessage.Err
		if err != nil {
			err = dbMessage.Err
			if err.Error() == "sql: no rows in result set" {
				logger.Printf("err='%s'", err)
				return false, "", nil
			} else {
				logger.Printf("Problem with db ='%s'", err)
				return false, "", err
			}
		}
		jwsData = dbMessage.JWSData
	case <-time.After(state.remoteDBQueryTimeout):
		logger.Println("GetSigned: timed out on primary DB")
		// load from cache
		stmtText := getSignedUserDataStmt["sqlite"]
		stmt, err := state.cacheDB.Prepare(stmtText)
		if err != nil {
			logger.Printf("Error Preparing statement GetSigned Cache DB: %s",
				err)
			return false, "", err
		}
		defer stmt.Close()
		err = stmt.QueryRow(username, dataType, time.Now().Unix()).Scan(
			&jwsData)
		if err != nil {
			if err.Error() == "sql: no rows in result set" {
				logger.Printf("err='%s'", err)
				return false, "", nil
			} else {
				logger.Printf("Problem with db ='%s'", err)
				return false, "", err
			}
		}
		logger.Println("GetSigned: got data from DB cache")
	}
	logger.Println("GetSigned: got jwsdata")
	storageJWT, err := state.getStorageDataFromStorageStringDataJWT(jwsData)
	if err != nil {
		logger.Debugf(2, "failed to get storage data %s data=%s", err, jwsData)
		return false, "", err
	}
	if storageJWT.Subject != username {
		logger.Debugf(2, "%s for %s", err, username)
		return false, "", errors.New("inconsistent data coming from DB")
	}
	return true, storageJWT.Data, nil
}

var saveSignedUserDataStmt = map[string]string{
	"sqlite":   "insert or replace into expiring_signed_user_data(username, type, jws_data, expiration_epoch, update_epoch) values(?,?, ?, ?, ?)",
	"postgres": "insert into expiring_signed_user_data(username, type, jws_data, expiration_epoch, update_epoch) values ($1,$2,$3,$4, $5) ON CONFLICT(username,type) DO UPDATE SET  jws_data = excluded.jws_data, expiration_epoch = excluded.expiration_epoch",
}

func (state *RuntimeState) UpsertSigned(username string, dataType int,
	expirationEpoch int64, data string) error {
	logger.Debugf(2, "top of UpsertSigned")
	//expirationEpoch := expiration.Unix()
	stringData, err := state.genNewSerializedStorageStringDataJWT(username,
		dataType, data, expirationEpoch)
	if err != nil {
		return err
	}
	start := time.Now()
	//insert into DB
	tx, err := state.db.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback()
	stmtText := saveSignedUserDataStmt[state.dbType]
	stmt, err := tx.Prepare(stmtText)
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(username, dataType, stringData, expirationEpoch,
		time.Now().Unix())
	if err != nil {
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	metricLogExternalServiceDuration("storage-save", time.Since(start))
	return nil
}


text:
<?php

namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;

use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;

/**
 * Class representing ReverseNestedAggregation.
 *
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
 */
class ReverseNestedAggregation extends AbstractAggregation
{
    use BucketingTrait;

    /**
     * @var string
     */
    private $path;

    /**
     * Inner aggregations container init.
     *
     * @param string $name
     * @param string $path
     */
    public function __construct($name, $path = null)
    {
        parent::__construct($name);

        $this->setPath($path);
    }

    /**
     * Return path.
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path;
    }

    /**
     * @param string $path
     *
     * @return $this
     */
    public function setPath($path)
    {
        $this->path = $path;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getType()
    {
        return 'reverse_nested';
    }

    /**
     * {@inheritdoc}
     */
    public function getArray()
    {
        $output = new \stdClass();
        if ($this->getPath()) {
            $output = ['path' => $this->getPath()];
        }

        return $output;
    }
}


text:
<component name="ProjectDictionaryState">
  <dictionary name="agentx" />
</component>


text:
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-BottomSheet-green.svg?style=flat)](https://android-arsenal.com/details/1/2315)

![screenshot](https://github.com/Kennyc1012/BottomSheet/blob/master/art/list.png)
![screenshot](https://github.com/Kennyc1012/BottomSheet/blob/master/art/grid.png)
![screenshot](https://github.com/Kennyc1012/BottomSheet/blob/master/art/tablet_list.png)
![screenshot](https://github.com/Kennyc1012/BottomSheet/blob/master/art/tablet_grid.png)
![screenshot](https://github.com/Kennyc1012/BottomSheet/blob/master/art/share_list.png)

#Features
- Both list and grid style
- Custom Views
- Simple Messages
- Light and Dark theme as well as custom themeing options
- XML style support
- Tablet support
- Share Intent Picker
- API 14+

#Using BottomSheet
To get started using BottomSheet, first you'll need to create a menu resource file with the defined actions.
```xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/share"
        android:icon="@drawable/ic_share_grey_600_24dp"
        android:title="Share" />

    <item
        android:id="@+id/upload"
        android:icon="@drawable/ic_cloud_upload_grey_600_24dp"
        android:title="Upload" />

    <item
        android:id="@+id/copy"
        android:icon="@drawable/ic_content_copy_grey_600_24dp"
        android:title="Copy" />

    <item
        android:id="@+id/print"
        android:icon="@drawable/ic_print_grey_600_24dp"
        android:title="Print" />

</menu>
```

Then create a BottomSheet via the Builder interface
```java
new BottomSheet.Builder(getActivity())
  .setSheet(R.menu.bottom_sheet)
  .setTitle(R.string.options)
  .setListener(myListener)
  .show();
  ```
#Simple Messages
BottomSheet can also display a simple message like a standard dialog. Setting one up is just as simple
```java
new BottomSheet.Builder(this)
    .setTitle(R.string.title)
    .setMessage(R.string.message)
    .setPositiveButton(R.string.ok)
    .setNegativeButton(R.string.close)
    .setIcon(R.drawable.my_icon)
    .setListener(myListener)
    .show();
```

To handle which button was pressed, the [BottomSheetListener.onSheetDismissed(int)](https://github.com/Kennyc1012/BottomSheet/blob/master/library/src/main/java/com/kennyc/bottomsheet/BottomSheetListener.java#L29) specifies which button was pressed using the constant values BUTTON_POSITIVE, BUTTON_NEGATIVE, and BUTTON_NEUTRAL from the [Dialog](http://developer.android.com/reference/android/app/Dialog.html) class. If neither button was pressed and the dialog was just dismissed, which will be Integer.MIN_VALUE

#Custom Views
For even further customization, you can set the BottomSheet to use a custom view.
```java
View v = ...

new BottomSheet.Builder(this)
    .setView(v)
    .show();
```
There are a few limitations when using a custom view. First, it <b>MUST</b> have a background set or it will appear transparent. Second, the root layout dimensions should always be ```layout_width="match_parent``` and ```layout_height="wrap_content```. Lastly, you will need to manage any click events as the BottomSheetListener can not determine anything from your custom view. If setting a custom view, all other builder settings will be ignored.

#Styling
BottomSheet comes with both a Light and Dark theme to accommodate most scenarios. However, if you want to customize the color more, you can create your own style and supply it to the builder.
</br> Customizable attributes are:
```xml
<attr name="bottom_sheet_bg_color" format="color" />
    <attr name="bottom_sheet_title_text_appearance" format="reference" />
    <attr name="bottom_sheet_list_text_appearance" format="reference" />
    <attr name="bottom_sheet_grid_text_appearance" format="reference" />
    <attr name="bottom_sheet_message_text_appearance" format="reference" />
    <attr name="bottom_sheet_message_title_text_appearance" format="reference" />
    <attr name="bottom_sheet_button_text_appearance" format="reference" />
    <attr name="bottom_sheet_item_icon_color" format="color" />
```

Then create a style and pass it into the Builder
```xml
<style name="MyBottomSheetStyle" parent="@style/BottomSheet">
    <item name="bottom_sheet_bg_color">@android:color/holo_blue_light</item>
    <item name="bottom_sheet_title_text_appearance">@style/TitleAppearance</item>
    <item name="bottom_sheet_list_text_appearance">@style/ListAppearance</item>
    <item name="bottom_sheet_grid_text_appearance">@style/GridAppearance</item>
</style>

<style name="TitleAppearance" parent="BottomSheet.Title.TextAppearance">
    <item name="android:textColor">@android:color/holo_green_light</item>
</style>

<style name="ListAppearance" parent="BottomSheet.ListItem.TextAppearance">
    <item name="android:textColor">@android:color/holo_red_light</item>
    <item name="android:textSize">18sp</item>
</style>

<style name="GridAppearance" parent="BottomSheet.GridItem.TextAppearance">
    <item name="android:textColor">@android:color/holo_red_light</item>
    <item name="android:textSize">20sp</item>
</style>
```

```java
new BottomSheet.Builder(getActivity(), R.style.MyBottomSheetStyle)
  .setSheet(R.menu.bottom_sheet)
  .setTitle(R.string.options)
  .setListener(myListener)
  .show();
```

##Icons
Based on the [Material Design Guidelines](http://www.google.com/design/spec/components/bottom-sheets.html#bottom-sheets-specs), icons for a linear list styled BottomSheet should be 24dp, where as a grid styled BottomSheet should be 48dp.

#Share Intents
BottomSheet can also be used to create a Share Intent Picker that will be styled like the ones found in Android 5.x+. To create one, simply call one of the static  ```createShareBottomSheet``` methods.
```java
// Create the intent for sharing
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/*");
intent.putExtra(Intent.EXTRA_TEXT, "My text to share");
// Pass the intent into the createShareBottomSheet method to generate the BottomSheet.
BottomSheet share = BottomSheet.createShareBottomSheet(getActivity(), intent, "My Title");
// Make sure that it doesn't return null! If the system can not handle the intent, null will be returned.
if (share != null) share.show();
// By default, it will be styled as a list. For a grid, pass the boolean value true after the title parameter
```

#Callbacks
BottomSheet uses the [BottomSheetListener](https://github.com/Kennyc1012/BottomSheet/blob/master/library/src/main/java/com/kennyc/bottomsheet/BottomSheetListener.java) for callbacks
```java
// Called when the BottomSheet it first displayed
onSheetShown()

// Called when the BottomSheet has been dismissed. Passed value represent which button was pressed if displaying
// a simple message
onSheetDismissed(int which)

// Called when an item is selected from the BottomSheet
onSheetItemSelected(MenuItem item)
```

#Upgrading From 1.x
When upgrading to 2.x from a 1.x release, some changes will have to be made.
- All of the builder methods for settings colors have been removed. All customzing should be done through themes.
- The style attributes have been change to text appearances rather than colors.
- The Builder constructor no longer takes a menu object. You will need to call ```setSheet(...)```.
- The ```onSheetDismissed``` callback now takes an int as an argument for simple message support.
- The gradle dependency has changed and needs to be updated.

#Including in your project
To include BottomSheet in your project, make the following changes to your build.gradle file

## Add repository
```groovy
repositories {
    maven { url "https://jitpack.io" }
}
```
## Add dependency
```groovy
dependencies {
    compile 'com.github.Kennyc1012:BottomSheet:2.0.1'
}
```

#Contribution
Pull requests are welcomed and encouraged. If you experience any bugs, please file an [issue](https://github.com/Kennyc1012/BottomSheet/issues)

License
=======

    Copyright 2015 Kenny Campagna

    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.


text:
'use strict';

// reserved Postgres words
var reservedMap = require(__dirname + '/reserved.js');

var fmtPattern = {
    ident: 'I',
    literal: 'L',
    string: 's',
};

// convert to Postgres default ISO 8601 format
function formatDate(date) {
    date = date.replace('T', ' ');
    date = date.replace('Z', '+00');
    return date;
}

function isReserved(value) {
    if (reservedMap[value.toUpperCase()]) {
        return true;
    }
    return false;
}

function arrayToList(useSpace, array, formatter) {
    var sql = '';
    var temp = [];

    sql += useSpace ? ' (' : '(';
    for (var i = 0; i < array.length; i++) {
      sql += (i === 0 ? '' : ', ') + formatter(array[i]);
    }
    sql += ')';

    return sql;
}

// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
function quoteIdent(value) {

    if (value === undefined || value === null) {
        throw new Error('SQL identifier cannot be null or undefined');
    } else if (value === false) {
        return '"f"';
    } else if (value === true) {
        return '"t"';
    } else if (value instanceof Date) {
        return '"' + formatDate(value.toISOString()) + '"';
    } else if (value instanceof Buffer) {
        throw new Error('SQL identifier cannot be a buffer');
    } else if (Array.isArray(value) === true) {
        var temp = [];
        for (var i = 0; i < value.length; i++) {
            if (Array.isArray(value[i]) === true) {
                throw new Error('Nested array to grouped list conversion is not supported for SQL identifier');
            } else {
                temp.push(quoteIdent(value[i]));
            }
        }
        return temp.toString();
    } else if (value === Object(value)) {
        throw new Error('SQL identifier cannot be an object');
    }

    var ident = value.toString().slice(0); // create copy

    // do not quote a valid, unquoted identifier
    if (/^[a-z_][a-z0-9_$]*$/.test(ident) === true && isReserved(ident) === false) {
        return ident;
    }

    var quoted = '"';

    for (var i = 0; i < ident.length; i++) {
        var c = ident[i];
        if (c === '"') {
            quoted += c + c;
        } else {
            quoted += c;
        }
    }

    quoted += '"';

    return quoted;
};

// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
function quoteLiteral(value) {

    var literal = null;
    var explicitCast = null;

    if (value === undefined || value === null) {
        return 'NULL';
    } else if (value === false) {
        return "'f'";
    } else if (value === true) {
        return "'t'";
    } else if (value instanceof Date) {
        return "'" + formatDate(value.toISOString()) + "'";
    } else if (value instanceof Buffer) {
        return "E'\\\\x" + value.toString('hex') + "'";
    } else if (Array.isArray(value) === true) {
        var temp = [];
        for (var i = 0; i < value.length; i++) {
            if (Array.isArray(value[i]) === true) {
                temp.push(arrayToList(i !== 0, value[i], quoteLiteral))
            } else {
                temp.push(quoteLiteral(value[i]));
            }
        }
        return temp.toString();
    } else if (value === Object(value)) {
        explicitCast = 'jsonb';
        literal = JSON.stringify(value);
    } else {
        literal = value.toString().slice(0); // create copy
    }

    var hasBackslash = false;
    var quoted = '\'';

    for (var i = 0; i < literal.length; i++) {
        var c = literal[i];
        if (c === '\'') {
            quoted += c + c;
        } else if (c === '\\') {
            quoted += c + c;
            hasBackslash = true;
        } else {
            quoted += c;
        }
    }

    quoted += '\'';

    if (hasBackslash === true) {
        quoted = 'E' + quoted;
    }

    if (explicitCast) {
        quoted += '::' + explicitCast;
    }

    return quoted;
};

function quoteString(value) {

    if (value === undefined || value === null) {
        return '';
    } else if (value === false) {
        return 'f';
    } else if (value === true) {
        return 't';
    } else if (value instanceof Date) {
        return formatDate(value.toISOString());
    } else if (value instanceof Buffer) {
        return '\\x' + value.toString('hex');
    } else if (Array.isArray(value) === true) {
        var temp = [];
        for (var i = 0; i < value.length; i++) {
            if (value[i] !== null && value[i] !== undefined) {
                if (Array.isArray(value[i]) === true) {
                    temp.push(arrayToList(i !== 0, value[i], quoteString));
                } else {
                    temp.push(quoteString(value[i]));
                }
            }
        }
        return temp.toString();
    } else if (value === Object(value)) {
        return JSON.stringify(value);
    }

    return value.toString().slice(0); // return copy
}

function config(cfg) {

    // default
    fmtPattern.ident = 'I';
    fmtPattern.literal = 'L';
    fmtPattern.string = 's';

    if (cfg && cfg.pattern) {
        if (cfg.pattern.ident) { fmtPattern.ident = cfg.pattern.ident; }
        if (cfg.pattern.literal) { fmtPattern.literal = cfg.pattern.literal; }
        if (cfg.pattern.string) { fmtPattern.string = cfg.pattern.string; }
    }
}

function formatWithArray(fmt, parameters) {

    var index = 0;
    var params = parameters;

    var re = '%(%|(\\d+\\$)?[';
    re += fmtPattern.ident;
    re += fmtPattern.literal;
    re += fmtPattern.string;
    re += '])';
    re = new RegExp(re, 'g');

    return fmt.replace(re, function(_, type) {

        if (type === '%') {
            return '%';
        }

        var position = index;
        var tokens = type.split('$');

        if (tokens.length > 1) {
            position = parseInt(tokens[0]) - 1;
            type = tokens[1];
        }

        if (position < 0) {
            throw new Error('specified argument 0 but arguments start at 1');
        } else if (position > params.length - 1) {
            throw new Error('too few arguments');
        }

        index = position + 1;

        if (type === fmtPattern.ident) {
            return quoteIdent(params[position]);
        } else if (type === fmtPattern.literal) {
            return quoteLiteral(params[position]);
        } else if (type === fmtPattern.string) {
            return quoteString(params[position]);
        }
    });
}

function format(fmt) {
    var args = Array.prototype.slice.call(arguments);
    args = args.slice(1); // first argument is fmt
    return formatWithArray(fmt, args);
}

exports = module.exports = format;
exports.config = config;
exports.ident = quoteIdent;
exports.literal = quoteLiteral;
exports.string = quoteString;
exports.withArray = formatWithArray;


text:
using System.ComponentModel;
using Moq;
using ScaffoldR.Core.Commands;
using ScaffoldR.Core.Transactions;
using ScaffoldR.Infrastructure.Commands;
using ScaffoldR.Tests.Infrastructure.Commands.Fakes;
using Xunit;

namespace ScaffoldR.Tests.Infrastructure.Commands
{
    public class CommandTransactionDecoratorTests
    {
        [Fact]
        public void ExecuteTransaction_WhenCommandHasTransactionalAttribute()
        {
            var command = new FakeCommandWithoutValidator();
            Assert.IsAssignableFrom<ICommand>(command);

            var transactionProcessor = new Mock<IProcessTransactions>(MockBehavior.Strict);
            transactionProcessor.Setup(x => x.Execute());

            var decorated = new Mock<IHandleCommand<FakeCommandWithoutValidator>>(MockBehavior.Strict);
            var typeDescriptionProvider = TypeDescriptor.AddAttributes(decorated.Object.GetType(), new TransactionalAttribute());
            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandTransactionDecorator<FakeCommandWithoutValidator>(transactionProcessor.Object, () => decorated.Object);
            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            transactionProcessor.Verify(x => x.Execute(), Times.Once);

            // Clean the provider for next test, or else it will fail - very odd.
            TypeDescriptor.RemoveProvider(typeDescriptionProvider, decorated.Object.GetType());
        }

        [Fact]
        public void DoNotExecuteTransaction_WhenCommandDoNotHaveTransactionalAttribute()
        {
            var command = new FakeCommandWithoutValidator();
            Assert.IsAssignableFrom<ICommand>(command);

            var transactionProcessor = new Mock<IProcessTransactions>(MockBehavior.Strict);
            transactionProcessor.Setup(x => x.Execute());

            var decorated = new Mock<IHandleCommand<FakeCommandWithoutValidator>>(MockBehavior.Strict);
            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandTransactionDecorator<FakeCommandWithoutValidator>(transactionProcessor.Object, () => decorated.Object);
            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            transactionProcessor.Verify(x => x.Execute(), Times.Never);
        }

    }
}


text:
import keras
import numpy as np
from keras.datasets import cifar10
from keras.preprocessing.image import ImageDataGenerator
from keras.layers.normalization import BatchNormalization
from keras.layers import Conv2D, Dense, Input, add, Activation, GlobalAveragePooling2D
from keras.initializers import he_normal
from keras.callbacks import LearningRateScheduler, TensorBoard
from keras.models import Model
from keras import optimizers
from keras import regularizers

depth              = 16
wide               = 8
num_classes        = 10
img_rows, img_cols = 32, 32
img_channels       = 3
batch_size         = 128
epochs             = 200
iterations         = 391
weight_decay       = 0.0005
log_filepath       = r'./w_resnet/'

def scheduler(epoch):
    if epoch <= 60:
        return 0.1
    if epoch <= 120:
        return 0.02
    if epoch <= 160:
        return 0.004
    return 0.0008

def color_preprocessing(x_train,x_test):
    x_train = x_train.astype('float32')
    x_test = x_test.astype('float32')
    x_train[:,:,:,0] = (x_train[:,:,:,0] - np.mean(x_train[:,:,:,0])) / np.std(x_train[:,:,:,0])
    x_train[:,:,:,1] = (x_train[:,:,:,1] - np.mean(x_train[:,:,:,1])) / np.std(x_train[:,:,:,1])
    x_train[:,:,:,2] = (x_train[:,:,:,2] - np.mean(x_train[:,:,:,2])) / np.std(x_train[:,:,:,2])
    x_test[:,:,:,0] = (x_test[:,:,:,0] - np.mean(x_test[:,:,:,0])) / np.std(x_test[:,:,:,0])
    x_test[:,:,:,1] = (x_test[:,:,:,1] - np.mean(x_test[:,:,:,1])) / np.std(x_test[:,:,:,1])
    x_test[:,:,:,2] = (x_test[:,:,:,2] - np.mean(x_test[:,:,:,2])) / np.std(x_test[:,:,:,2])

    return x_train, x_test

def wide_residual_network(img_input,classes_num,depth,k):

    print('Wide-Resnet %dx%d' %(depth, k))
    n_filters  = [16, 16*k, 32*k, 64*k]
    n_stack    = (depth - 4) / 6
    in_filters = 16

    def conv3x3(x,filters):
    	return Conv2D(filters=filters, kernel_size=(3,3), strides=(1,1), padding='same',
    	kernel_initializer=he_normal(),
        kernel_regularizer=regularizers.l2(weight_decay))(x)

    def residual_block(x,out_filters,increase_filter=False):
        if increase_filter:
            first_stride = (2,2)
        else:
            first_stride = (1,1)
        pre_bn   = BatchNormalization()(x)
        pre_relu = Activation('relu')(pre_bn)
        conv_1 = Conv2D(out_filters,kernel_size=(3,3),strides=first_stride,padding='same',kernel_initializer=he_normal(),kernel_regularizer=regularizers.l2(weight_decay))(pre_relu)
        bn_1   = BatchNormalization()(conv_1)
        relu1  = Activation('relu')(bn_1)
        conv_2 = Conv2D(out_filters, kernel_size=(3,3), strides=(1,1), padding='same', kernel_initializer=he_normal(),kernel_regularizer=regularizers.l2(weight_decay))(relu1)
        if increase_filter or in_filters != out_filters:
            projection = Conv2D(out_filters,kernel_size=(1,1),strides=first_stride,padding='same',kernel_initializer=he_normal(),kernel_regularizer=regularizers.l2(weight_decay))(x)
            block = add([conv_2, projection])
        else:
            block = add([conv_2,x])
        return block

    def wide_residual_layer(x,out_filters,increase_filter=False):
    	x = residual_block(x,out_filters,increase_filter)
    	in_filters = out_filters
    	for _ in range(1,int(n_stack)):
    		x = residual_block(x,out_filters)
    	return x

    x = conv3x3(img_input,n_filters[0])
    x = wide_residual_layer(x,n_filters[1])
    x = wide_residual_layer(x,n_filters[2],increase_filter=True)
    x = wide_residual_layer(x,n_filters[3],increase_filter=True)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = GlobalAveragePooling2D()(x)
    x = Dense(classes_num,activation='softmax',kernel_initializer=he_normal(),kernel_regularizer=regularizers.l2(weight_decay))(x)
    return x

if __name__ == '__main__':

    # load data
    (x_train, y_train), (x_test, y_test) = cifar10.load_data()
    y_train = keras.utils.to_categorical(y_train, num_classes)
    y_test = keras.utils.to_categorical(y_test, num_classes)

    # color preprocessing
    x_train, x_test = color_preprocessing(x_train, x_test)

    # build network
    img_input = Input(shape=(img_rows,img_cols,img_channels))
    output = wide_residual_network(img_input,num_classes,depth,wide)
    resnet = Model(img_input, output)
    print(resnet.summary())
    # set optimizer
    sgd = optimizers.SGD(lr=.1, momentum=0.9, nesterov=True)
    resnet.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])

    # set callback
    tb_cb = TensorBoard(log_dir=log_filepath, histogram_freq=0)
    change_lr = LearningRateScheduler(scheduler)
    cbks = [change_lr,tb_cb]

    # set data augmentation
    print('Using real-time data augmentation.')
    datagen = ImageDataGenerator(horizontal_flip=True,
            width_shift_range=0.125,height_shift_range=0.125,fill_mode='constant',cval=0.)

    datagen.fit(x_train)

    # start training
    resnet.fit_generator(datagen.flow(x_train, y_train,batch_size=batch_size),
                        steps_per_epoch=iterations,
                        epochs=epochs,
                        callbacks=cbks,
                        validation_data=(x_test, y_test))
    resnet.save('resnet.h5')


text:
const port = 3003;

const bodyParser = require('body-parser')
const express = require('express')
const server = express()
const allowCors = require('./cors')

server.use(bodyParser.urlencoded({ extended: true }))
server.use(bodyParser.json())
server.use(allowCors)

server.listen(port, function(){
    console.log(`running on port ${port}.`)
})

module.exports = server


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <artifactId>quarkus-extensions-parent</artifactId>
        <groupId>io.quarkus</groupId>
        <version>999-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>quarkus-funqy-parent</artifactId>
    <name>Quarkus - Funqy</name>
    <packaging>pom</packaging>
    <modules>
        <module>funqy-server-common</module>
        <module>funqy-http</module>
        <module>funqy-amazon-lambda</module>
        <module>funqy-knative-events</module>
        <module>funqy-google-cloud-functions</module>
    </modules>
</project>


text:
from a10sdk.common.A10BaseClass import A10BaseClass

class Suffix(A10BaseClass):

    """Class Description::
    DNS suffix.

    Class suffix supports CRUD Operations and inherits from `common/A10BaseClass`.
    This class is the `"PARENT"` class for this module.`

    :param domain_name: {"description": "DNS suffix", "format": "string", "minLength": 1, "optional": true, "maxLength": 32, "type": "string"}
    :param uuid: {"description": "uuid of the object", "format": "string", "minLength": 1, "modify-not-allowed": 1, "optional": true, "maxLength": 64, "type": "string"}
    :param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`

    URL for this object::
    `https://<Hostname|Ip address>//axapi/v3/ip/dns/suffix`.

    """
    def __init__(self, **kwargs):
        self.ERROR_MSG = ""
        self.required=[]
        self.b_key = "suffix"
        self.a10_url="/axapi/v3/ip/dns/suffix"
        self.DeviceProxy = ""
        self.domain_name = ""
        self.uuid = ""

        for keys, value in kwargs.items():
            setattr(self,keys, value)


text:
<?php
/**
 * params-local.php
 *
 * @author: antonio ramirez <antonio@clevertech.biz>
 * Date: 7/22/12
 * Time: 5:59 PM
 *
 *
 * ANY CONFIGURATION OPTIONS HERE WILL REPLACE THOSE INCLUDED ON THE params-env.php file!!!
 * It holds your local configuration settings.
 *
 * Replace following tokens for your local correspondent configuration data
 *
 * {DATABASE-NAME} ->   database name
 * {DATABASE-HOST} -> database server host name or ip address
 * {DATABASE-USERNAME} -> user name access
 * {DATABASE-PASSWORD} -> user password
 *
 * {DATABASE-TEST-NAME} ->   Test database name
 * {DATABASE-TEST-HOST} -> Test database server host name or ip address
 * {DATABASE-USERNAME} -> Test user name access
 * {DATABASE-PASSWORD} -> Test user password
 */
return array(
	'env.code' => 'private',
	// DB connection configurations
//	'db.name' => '',
//	'db.connectionString' => 'mysql:host={DATABASE-HOST};dbname={DATABASE-NAME}',
//	'db.username' => '{DATABASE-USERNAME}',
//	'db.password' => '{DATABASE-PASSWORD}',
//
//	// test database {
//	'testdb.name' => '',
//	'testdb.connectionString' => 'mysql:host={DATABASE-HOST};dbname={DATABASE-NAME}_test',
//	'testdb.username' => '{DATABASE-USERNAME}',
//	'testdb.password' => '{DATABASE-PASSWORD}',

);


text:
1. [Features](#features).
- [Supported frameworks](#frameworks).
- [Installation](#installation).
- [Usage](#usage).
- [Contact](#contact).

----

## Features

- **Very easy to implement**.
- Supports multiple observer locations
- Supports multiple observer method names
- Supports Ardent style methods names

## Supported frameworks

The library is build for usage with Laravel 4 and Eloquent.

## Installation

In your Laravel base directory run

    composer require "jlis/obsrvs":"dev-master"

Then edit `app/config/app.php` and add the service provider within the `providers` array

    'providers' => array(
        ...
        'Jlis\Obsrvs\ObsrvsServiceProvider'

## Usage

First of all, you need to tell your models to use the Eloquent extension:

```php
<?php
use Jlis\Obsrvs\EloquentObserverable;

class User extends EloquentObserverable
{
    // model code here...
}
```
Just replace the `extends Eloquent` part with `extends EloquentObserverable`.

### Callback methods/hooks

The callback methods/hooks can be placed in multiple locations. You can put the in your model files (i.e `app/models/User.php`) or in separate observer classes (i.e. `app/observers/UserObserver.php`).

To add a callback for the `created` event add

```php
public method onCreated($user)
{
    // if there's a new password, hash it
    if($this->isDirty('password')) {
        $this->password = Hash::make($this->password);
    }

    return true;
    //or don't return nothing, since only a boolean false will halt the operation
}
```

or

```php
public method afterCreate($user)
{
    // some code here...
}
```

Available callback method/hook names in the model class:
- `onCreating()`/`beforeCreate()`
- `onCreated()`/`afterCreate()`
- `onUpdating()`/`beforeUpdate()`
- `onUpdated()`/`afterUpdate()`
- `onSaving()`/`beforeSave()`
- `onSaved()`/`afterSave()`
- `onDeleting()`/`beforeDelete()`
- `onDeleted()`/`afterDelete()`
- `onRestoring()`/`beforeRestore()`
- `onRestored()`/`afterRestore()`

Available callback method/hook names in separate observer classes:
- `creating()`/`onCreating()`/`beforeCreate()`
- `created()`/`onCreated()`/`afterCreate()`
- `updating()`/`onUpdating()`/`beforeUpdate()`
- `updated()`/`onUpdated()`/`afterUpdate()`
- `saving()`/`onSaving()`/`beforeSave()`
- `saved()`/`onSaved()`/`afterSave()`
- `deleting()`/`onDeleting()`/`beforeDelete()`
- `deleted()`/`onDeleted()`/`afterDelete()`
- `restoring()`/`onRestoring()`/`beforeRestore()`
- `restored()`/`onRestored()`/`afterRestore()`

*Warning: try to avoid having multiple method names for the event in the save model/observer class.*

### Autoloading for separate observer classes

To add your separate observer classes like `app/observers/UserObserver.php` to the autoloading, edit your `composer.json` file and add the following:

    "autoload": {
            "classmap": [
                ...
                "app/observers"
            ]
        },

Now just run `composer dump-autoload` to let composer recreate it's autoload index.

### Best practice and clean code

To avoid implementing the `use Jlis\Obsrvs\EloquentObserverable;` for each model, it's a nice idea to create a `BaseModel` and extend all regular models with it.

Just create a new `BaseModel.php` in `app/models/` and use the following code:

```php
<?php
use Jlis\Obsrvs\EloquentObserverable;

class BaseModel extends EloquentObserverable
{
    // this can be empty
}
```
Now you just have to edit your regular models to extend the `BaseModel` instead of `Eloquent`:

```php
<?php
class User extends BaseModel
{
    // model code here...
}
```

----

## Contact

Please report issues on the project's [GitHub Issues](https://github.com/jlis/obsrvs/issues) page.
If you have questions or would like to leave some general feedback, please leave me a mail (see composer.json for mail address) or write me on skype (raiiid).


text:
#pragma once

#include <dquote/tmp/has_xxx.hpp>

#include <Windows.h>

namespace dquote{ namespace win32{

	namespace detail{

		/*DQUOTE_DECLARE_HAS_NON_TYPE(is_subclass);

		template <bool, class Window>
		bool set_subclass_impl(HWND hwnd)
		{
			return static_cast<Derived*>(this)->set_subclass(hwnd);
		}
		template <>
		bool set_subclass_impl<false>(HWND)
		{
			return true;
		}

		bool set_subclass_(std::true_type&, HWND hwnd)
		{
			return set_subclass_impl<Derived::is_subclass>(hwnd);
		}
		bool set_subclass_(std::false_type&, HWND)
		{
			return true;
		}*/

	}

	struct creation_params{
		DWORD exstyle, style;
		const wchar_t *classname, *title;
		int x, y, w, h;
		HWND hparent;
	};

	template <class Window>
	bool create(Window &w, creation_params &cp)
	{
		if(cp.w != CW_USEDEFAULT){
			RECT rc = {0, 0, cp.w, cp.h};
			::AdjustWindowRectEx(&rc, cp.style, FALSE, cp.exstyle);
			cp.w = rc.right - rc.left;
			cp.h = rc.bottom - rc.top;
		}
		HWND hwnd = ::CreateWindowExW(
			cp.exstyle,
			cp.classname,
			cp.title,
			cp.style,
			cp.x,
			cp.y,
			cp.w,
			cp.h,
			cp.hparent,
			nullptr,
			::GetModuleHandleW(nullptr),
			std::addressof(w));
		/*if(!set_subclass_(typename aux::has_is_subclass<Derived>::type(), hwnd)){
			::DestroyWindow(hwnd);
			hwnd = nullptr;
		}*/
		return hwnd != nullptr;
	}

	template <class Window, class Parent>
	bool create(Window &window, Parent &parent, const wchar_t *classname=nullptr, const wchar_t *title=L"", int x=INT_MAX, int y=INT_MAX, int w=-1, int h=-1)
	{
		creation_params params ={
			0,
			WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
			((classname != nullptr) ? classname : window.get_class_name()),
			title,
			((x == INT_MAX || y == INT_MAX) ? CW_USEDEFAULT : x),
			y,
			((w == -1 || h == -1) ? CW_USEDEFAULT : w),
			h,
			parent.get_hwnd(),
		};

		return create(window, params);
	}

	template <class Window>
	bool create(Window &window, const wchar_t *classname=nullptr, const wchar_t *title=L"", int x=INT_MAX, int y=INT_MAX, int w=-1, int h=-1)
	{
		creation_params params ={
			0,
			WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
			((classname != nullptr) ? classname : window.get_class_name()),
			title,
			((x == INT_MAX || y == INT_MAX) ? CW_USEDEFAULT : x),
			y,
			((w == -1 || h == -1) ? CW_USEDEFAULT : w),
			h,
			nullptr,
		};

		return create(window, params);
	}

} }


text:
import unittest
import collections
from SequenceUtils import calcIdenticalRate, getMismatchIndex

class RoleSequenceCriteria:
  def __init__(self, identicalSequenceStart, identicalSequence):
    self.IdenticalSequence = identicalSequence
    self.IdenticalSequenceStart = identicalSequenceStart
    self.IdenticalSequenceEnd = self.IdenticalSequenceStart + len(self.IdenticalSequence)

  def accept(self, sequence):
    return(True)

  def getSequence(self, sequence):
    return(sequence[self.IdenticalSequenceStart:self.IdenticalSequenceEnd])

class TestSequenceCriteria(unittest.TestCase):
    def setUp(self):
        self.criteria = RoleSequenceCriteria(25, "RTRCGTRRTCCTRTTGAGCATAGCCGGTTCAATTCGCGGACTAAGGCCATCATGAA")

    def testGetSequence(self):
        sequence = "TTATGAGCTGGACCGGTATGTAGCAgTACGTAGTCCTATTGAGCATAGCCGGTTCAATTCGCGGACTAAGGCCATCATGAAGATTGCCATCGTTTGGGCAATATCAATAGGAGTTTCAGTTCCTATCCCTGTGATTGGACTGAGGGACGAAAGCAAAGTGTTCGTGAATAATACTACCTGCGTGCTCAATGACCCGAACTTCGTTCTCATCGGGTCCTTCGTGGCATTCTTCATCCCGTTGACAATTATGGTGATCACCTACTTCTTAACGATCTACGTCCTACGCCGTCAAGCTTTGAT"
        self.assertEqual("gTACGTAGTCCTATTGAGCATAGCCGGTTCAATTCGCGGACTAAGGCCATCATGAA", self.criteria.getSequence(sequence))


text:
using System;

namespace Cradiator.Model
{
	public interface IDateTimeNow
	{
		DateTime Now { get; set; }
	}

	// a class just used for mocking out calls to DateTime
	public class DateTimeNow : IDateTimeNow
	{
		public DateTime Now
		{
			get => DateTime.Now;
			set {  }
		}
	}
}


text:
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">

  <title>ansible.plugins.lookup.password</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />

         Home

         Trees

         Indices

         Help

ansible

        Package ansible ::
        Package plugins ::
        Package lookup ::
        Module password

[hide private]

[frames] | no frames]

Module password

source code

        Classes
        [hide private]

        LookupModule

        Functions
        [hide private]

          _parse_parameters(term)

            source code

        Variables
        [hide private]

        DEFAULT_LENGTH = 20

        VALID_PARAMS = frozenset(['chars', 'encrypt', 'length'])

        __package__ = None

      hash(x)

Imports:
  __metaclass__,
  os,
  string,
  random,
  ascii_letters,
  digits,
  C,
  AnsibleError,
  LookupBase,
  parse_kv,
  do_encrypt,
  makedirs_safe

         Home

         Trees

         Indices

         Help

ansible

    Generated by Epydoc 3.0.1 on Fri Jul 29 13:11:37 2016

      http://epydoc.sourceforge.net


text:
package brooklyn.entity.nosql.couchdb;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import brooklyn.entity.basic.ApplicationBuilder;
import brooklyn.entity.basic.Entities;
import brooklyn.location.Location;
import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.test.entity.TestApplication;
import brooklyn.util.internal.TimeExtras;

/**
 * CouchDB test framework for integration and live tests.
 */
public class AbstractCouchDBNodeTest {

    private static final Logger log = LoggerFactory.getLogger(AbstractCouchDBNodeTest.class);

    static {
        TimeExtras.init();
    }

    protected TestApplication app;
    protected Location testLocation;
    protected CouchDBNode couchdb;

    @BeforeMethod(alwaysRun = true)
    public void setup() throws Exception {
        app = ApplicationBuilder.newManagedApp(TestApplication.class);
        testLocation = new LocalhostMachineProvisioningLocation();
        // testLocation = app.managementContext.locationRegistry.resolve("named:test");
    }

    @AfterMethod(alwaysRun = true)
    public void shutdown() {
        Entities.destroyAll(app.getManagementContext());
    }
}


text:
using GhostRunner.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GhostRunner.ViewModels.History
{
    public class IndexModel : ViewModel
    {
        public IndexModel()
        {
            Tasks = new List<Task>();
        }

        public Project Project { get; set; }

        public IList<Task> Tasks { get; set; }
    }
}


text:
package io.crate.execution.engine.aggregation;

import io.crate.breaker.RamAccounting;
import io.crate.data.Input;
import io.crate.memory.MemoryManager;
import io.crate.metadata.FunctionImplementation;
import io.crate.types.DataType;
import org.elasticsearch.Version;
import org.elasticsearch.common.breaker.CircuitBreakingException;
import org.elasticsearch.index.mapper.MappedFieldType;

import javax.annotation.Nullable;
import java.util.List;

/**
 * A special FunctionImplementation that compute a single result from a set of input values
 *
 * @param <TPartial> the intermediate type of the value used during aggregation
 * @param <TFinal>   the final type of the value after the aggregation is finished
 */
public abstract class AggregationFunction<TPartial, TFinal> implements FunctionImplementation {

    /**
     * Called once per "aggregation cycle" to create an initial partial-state-value.
     *
     * @param ramAccounting used to account the memory used for the state.
     * @param indexVersionCreated the version the current index was created on, this is useful for BWC
     * @return a new state instance or null
     */
    @Nullable
    public abstract TPartial newState(RamAccounting ramAccounting,
                                      Version indexVersionCreated,
                                      Version minNodeInCluster,
                                      MemoryManager memoryManager);

    /**
     * the "aggregate" function.
     *
     * @param ramAccounting used to account for additional memory usage if the state grows in size
     * @param state                the previous aggregation state
     * @param args                 arguments / input values matching the types of FunctionInfo.argumentTypes.
     *                             These are usually used to increment/modify the previous state
     * @return The new/changed state. This might be either a new instance or the same but mutated instance.
     * Users of the AggregationFunction should always use the return value, but must be aware that the input state might have changed too.
     */
    public abstract TPartial iterate(RamAccounting ramAccounting,
                                     MemoryManager memoryManager,
                                     TPartial state,
                                     Input... args)
        throws CircuitBreakingException;

    /**
     * This function merges two aggregation states together and returns that merged state.
     * <p>
     * This is used in a distributed aggregation workflow where 2 partial aggregations are reduced into 1 partial aggregation
     *
     * @return the reduced state. This might be a new instance or a mutated state1 or state2.
     */
    public abstract TPartial reduce(RamAccounting ramAccounting, TPartial state1, TPartial state2);

    /**
     * Called to transform partial states into their final form.
     * This might result in a loss of "meta data" that was necessary to compute the final value.
     */
    public abstract TFinal terminatePartial(RamAccounting ramAccounting, TPartial state);

    public abstract DataType<?> partialType();

    /**
     * Executing aggregations as window functions might require different runtime implementations in order to still be
     * performant. This attempts to compile a new implementation that will be optimized for the window functions
     * scenario (eg. a function might use a different execution path in order to become removable cumulative)
     */
    public AggregationFunction<?, TFinal> optimizeForExecutionAsWindowFunction() {
        return this;
    }

    /**
     * Indicates if this aggregation permits the removal of state from the previous aggregate state as defined in
     * http://www.vldb.org/pvldb/vol8/p1058-leis.pdf
     * If a function is removable cumulative it will allow clients to remove previously aggregate values from the partial
     * state using {@link #removeFromAggregatedState(RamAccounting, Object, Input[])}
     */
    public boolean isRemovableCumulative() {
        return false;
    }

    public TPartial removeFromAggregatedState(RamAccounting ramAccounting,
                                              TPartial previousAggState,
                                              Input[] stateToRemove) {
        throw new UnsupportedOperationException("Cannot remove state from the aggregated state as the function is " +
                                                "not removable cumulative");
    }

    @Nullable
    public DocValueAggregator<?> getDocValueAggregator(List<DataType<?>> argumentTypes, List<MappedFieldType> fieldTypes) {
        return null;
    }
}