text:
                @eyewitness_svg('ui-04', 'svgcolor-white')

Settings for {{ $queue->connection }} ({{ $queue->tube }})

                <eye-menu title='Delete' color='svgcolor-white' background='bg-brand shadow-lg btn-pop'>

                        <button class="block px-4 py-3 border-b text-grey-darkest bg-white hover:text-white bg-circuit-hover bg-md-hover hover:bg-brand svg-hover w-full" @click="submitForm" data-action="{{ route('eyewitness.queues.destroy', $queue->id) }}" data-method="delete">

                                    @eyewitness_svg('trash', 'dropdown-menu-svg', 20, 20)

                                    Delete

                        </button>

                </eye-menu>

        @eyewitness_tutorial('Here you can configure how this specific queue tube is monitored and which alert(s) are sent. This gives you the flexibility to disable alerts on certain queues that you do not worry about. You can also set normal thresholds, and Eyewitness will alert you if the queue starts operating outside of those boundaries.')

        @eyewitness_info('A setting of "0" means that alert will be disabled.')

        <form v-on:submit.capture="formSubmit" class="form pt-8" method="POST" action="{{ route('eyewitness.queues.update', $queue->id) }}">
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <input type="hidden" name="_method" value="put">
            <input type="hidden" name="alert_on_failed_job" value="0">

                    Send alert if queue has failed job

                        <input id="alert_on_failed_job" type="checkbox" {{ old('alert_on_failed_job', $queue->alert_on_failed_job) == '1' ? 'checked="checked"' : '' }} value="1" name="alert_on_failed_job"/>

                    Alert if last queue heartbeat time greater than (seconds)

                        <eye-input id="alert_heartbeat_greater_than" type="text" name="alert_heartbeat_greater_than" label="" value="{{ old('alert_heartbeat_greater_than', $queue->alert_heartbeat_greater_than) }}"></eye-input>

                    Alert if queue wait time greater than (seconds)

                        <eye-input id="alert_wait_time_greater_than" type="text" name="alert_wait_time_greater_than" label="" value="{{ old('alert_wait_time_greater_than', $queue->alert_wait_time_greater_than) }}"></eye-input>

                    Alert if queue pending jobs greater than

                        <eye-input id="alert_pending_jobs_greater_than" type="text" name="alert_pending_jobs_greater_than" label="" value="{{ old('alert_pending_jobs_greater_than', $queue->alert_pending_jobs_greater_than) }}"></eye-input>

                    Alert if queue failed jobs greater than

                        <eye-input id="alert_failed_jobs_greater_than" type="text" name="alert_failed_jobs_greater_than" label="" value="{{ old('alert_failed_jobs_greater_than', $queue->alert_failed_jobs_greater_than) }}"></eye-input>

                <eye-btn color="bg-brand" type="submit" icon='@eyewitness_svg('check-square-11', 'svgcolor-white h-4 w-4')'>Update queue</eye-btn>

        </form>


text:
<?php

// We hijack filter_init (which core filter module does not implement) as
// a convenient place to affect early changes.
if (!function_exists('filter_init')) {
  // Check function_exists as a safety net in case it is added in future.
  function filter_init() {
    global $conf, $user;
    // Inject values into the $conf array - will apply to all sites.
    // This can be a useful place to apply generic development settings.
    $conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF')));
    // Merge in the injected conf, overriding existing items.
    $conf = array_merge($conf, $conf_inject);
  }
}

// We hijack system_watchdog (which core system module does not implement) as
// a convenient place to capture logs.
if (!function_exists('system_watchdog')) {
  // Check function_exists as a safety net in case it is added in future.
  function system_watchdog($log_entry = array()) {
    $uid = $log_entry['user']->uid;
    $message = strtr('Watchdog: !message | severity: !severity | type: !type | uid: !uid | !ip | !request_uri | !referer | !link', array(
      '!message'     => strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])),
      '!severity'    => $log_entry['severity'],
      '!type'        => $log_entry['type'],
      '!ip'          => $log_entry['ip'],
      '!request_uri' => $log_entry['request_uri'],
      '!referer'     => $log_entry['referer'],
      '!uid'         => $uid,
      '!link'        => strip_tags($log_entry['link']),
    ));
    error_log($message);
  }
}

// Get a $_SERVER key, or equivalent environment variable
// if it is not set in $_SERVER.
function runserver_env($key) {
  if (isset($_SERVER[$key])) {
    return $_SERVER[$key];
  }
  else {
    return getenv($key);
  }
}

$url = parse_url($_SERVER["REQUEST_URI"]);
if (file_exists('.' . urldecode($url['path']))) {
  // Serve the requested resource as-is.
  return FALSE;
}

// Populate the "q" query key with the path, skip the leading slash.
$_GET['q'] = $_REQUEST['q'] = substr($url['path'], 1);

// We set the base_url so that Drupal generates correct URLs for runserver
// (e.g. http://127.0.0.1:8888/...), but can still select and serve a specific
// site in a multisite configuration (e.g. http://mysite.com/...).
$base_url = runserver_env('RUNSERVER_BASE_URL');

// The built in webserver incorrectly sets $_SERVER['SCRIPT_NAME'] when URLs
// contain multiple dots (such as config entity IDs) in the path. Since this is
// a virtual resource, served by index.php set the script name explicitly.
// See https://github.com/drush-ops/drush/issues/2033 for more information.
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Include the main index.php and let Drupal take over.
// n.b. Drush sets the cwd to the Drupal root during bootstrap.
include 'index.php';

redpajama_set_name: RedPajamaGithub


text:
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe ObjectSpace, "#classes" do
  it 'returns only classes, nothing else' do
    ObjectSpace.classes.each do |klass|
      Class.should === klass
    end
  end
end


text:
struct ID3D11Device;
struct IDXGISwapChain;
struct ID3D11DeviceContext;
struct ID3D11RenderTargetView;
struct ID3D11Texture2D;
struct ID3D11DepthStencilView;
struct ID3DUserDefinedAnnotation;

namespace TB
{
    struct IDirectXFrame
    {
        virtual ~IDirectXFrame() {}
        virtual void init(const std::shared_ptr<class DirectXRenderer>& renderer) {}
        virtual void render() {}
        virtual void update(float delta) {}
    };

    struct DirectXViewConstants
    {
        DirectX::XMMATRIX worldToView;
        DirectX::XMMATRIX viewToClip;
    };

    struct DirectXWorldConstants
    {
        DirectX::XMVECTOR mainLightDir;
    };

    struct DirectXObjectConstants
    {
        DirectX::XMMATRIX localToWorld;
    };

    class DirectXRenderer : public Renderer, public std::enable_shared_from_this<DirectXRenderer>
    {
    public:
        DirectXRenderer(const std::shared_ptr<class Canvas>& canvas, const std::shared_ptr<struct IDirectXFrame>& frame);
        virtual ~DirectXRenderer();

        virtual RendererType getType() const override { return RendererType::DirectXRenderer; }

        virtual bool init(int multisampleLevel) override;
        virtual void deinit() override;
        virtual void render() override;
        virtual void update(float delta) override;

        virtual std::shared_ptr<class Scene> loadScene(const std::string& path) override;
        virtual std::shared_ptr<class Scene> loadScene(const std::string& path, const MeshModifierCallback& meshModifier) override;
        virtual std::shared_ptr<Shader> loadShader(const std::string& path, const std::string& entryPoint, ShaderType type) override;
        virtual std::shared_ptr<Texture> loadTexture(const std::string& path) override;

        void clear(ID3D11RenderTargetView* rtv, const math::float4& color);
        void clear(ID3D11DepthStencilView* dsv);
        void clear(ID3D11DepthStencilView* dsv, float depth, int stencil);

        DirectX::XMMATRIX getProjMatrix(float fovAngleY, int viewportW, int viewportH, float nearZ) const;
        DirectX::XMMATRIX getProjMatrix(float fovAngleY, int viewportW, int viewportH, float nearZ, float offsetX, float offsetY) const;

        int32_t getWidth() const { return mWidth; }
        int32_t getHeight() const { return mHeight; }
        const ComPtr<ID3D11Device>& getDevice() const { return mDevice; }
        const ComPtr<ID3D11DeviceContext>& getImmediateContext() const { return mImmediateContext; }

        const ComPtr<ID3D11RenderTargetView>& getBackBufferRTV() const { return mBackBufferRTV; }
        const ComPtr<ID3D11DepthStencilView>& getBackBufferDSV() const { return mBackBufferDSV; }

        void beginEvent(const wchar_t* name) const;
        void endEvent() const;

        void drawQuad() const;

    private:
        std::shared_ptr<class WindowsCanvas> mCanvas;
        int32_t mWidth, mHeight;

        ComPtr<ID3D11Device> mDevice;
        ComPtr<IDXGISwapChain> mSwapChain;
        ComPtr<ID3D11DeviceContext> mImmediateContext;

        ComPtr<ID3D11RenderTargetView> mBackBufferRTV;
        ComPtr<ID3D11Texture2D> mDepthStencil;
        ComPtr<ID3D11DepthStencilView> mBackBufferDSV;

        ComPtr<ID3DUserDefinedAnnotation> mUserDefinedAnnotation;

        std::shared_ptr<class DirectXModel> mUnitQuad;
        std::shared_ptr<struct IDirectXFrame> mFrame;
    };
}

#endif


text:
package com.formkiq.core.domain.type;

/**
 * Sort Direction.
 *
 */
public enum SortDirection {
    /** Ascending. */
    ASC,
    /** Descending. */
    DESC;
}


text:
package net.bytebuddy.implementation.attribute;

import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationValue;
import net.bytebuddy.description.field.FieldDescription;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.test.utility.MockitoRule;
import net.bytebuddy.test.utility.ObjectPropertyAssertion;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.mockito.Mock;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.*;

public class AnnotationValueFilterDefaultTest {

    @Rule
    public TestRule mockitoRule = new MockitoRule(this);

    @Mock
    private AnnotationDescription annotationDescription;

    @Mock
    private MethodDescription.InDefinedShape methodDescription;

    @Test
    public void testAppendsDefaults() throws Exception {
        AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
        MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
        assertThat(AnnotationValueFilter.Default.APPEND_DEFAULTS.isRelevant(annotationDescription, methodDescription), is(true));
        verifyZeroInteractions(annotationDescription);
        verifyZeroInteractions(methodDescription);
    }

    @Test
    public void testSkipDefaultsNoDefault() throws Exception {
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.isRelevant(annotationDescription, methodDescription), is(true));
        verifyZeroInteractions(annotationDescription);
        verify(methodDescription).getDefaultValue();
        verifyNoMoreInteractions(methodDescription);
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testSkipDefaultsNoEquality() throws Exception {
        when(methodDescription.getDefaultValue()).thenReturn(mock(AnnotationValue.class));
        when(annotationDescription.getValue(methodDescription)).thenReturn(mock(AnnotationValue.class));
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.isRelevant(annotationDescription, methodDescription), is(true));
        verify(annotationDescription).getValue(methodDescription);
        verifyNoMoreInteractions(annotationDescription);
        verify(methodDescription).getDefaultValue();
        verifyNoMoreInteractions(methodDescription);
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testSkipDefaultsEquality() throws Exception {
        AnnotationValue<?, ?> annotationValue = mock(AnnotationValue.class);
        when(methodDescription.getDefaultValue()).thenReturn((AnnotationValue) annotationValue);
        when(annotationDescription.getValue(methodDescription)).thenReturn((AnnotationValue) annotationValue);
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.isRelevant(annotationDescription, methodDescription), is(false));
        verify(annotationDescription).getValue(methodDescription);
        verifyNoMoreInteractions(annotationDescription);
        verify(methodDescription).getDefaultValue();
        verifyNoMoreInteractions(methodDescription);
    }

    @Test
    public void testFactory() throws Exception {
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.on(mock(FieldDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.SKIP_DEFAULTS));
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.on(mock(MethodDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.SKIP_DEFAULTS));
        assertThat(AnnotationValueFilter.Default.SKIP_DEFAULTS.on(mock(TypeDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.SKIP_DEFAULTS));
        assertThat(AnnotationValueFilter.Default.APPEND_DEFAULTS.on(mock(FieldDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.APPEND_DEFAULTS));
        assertThat(AnnotationValueFilter.Default.APPEND_DEFAULTS.on(mock(MethodDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.APPEND_DEFAULTS));
        assertThat(AnnotationValueFilter.Default.APPEND_DEFAULTS.on(mock(TypeDescription.class)),
                is((AnnotationValueFilter) AnnotationValueFilter.Default.APPEND_DEFAULTS));
    }

    @Test
    public void testObjectProperties() throws Exception {
        ObjectPropertyAssertion.of(AnnotationAppender.Default.class).apply();
    }
}


text:
package org.newdawn.slick.opengl;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.newdawn.slick.util.Log;

import javax.annotation.Nullable;

/**
 * The PNG imge data source that is pure java reading PNGs
 *
 * @author Matthias Mann (original code)
 */
public class PNGImageData implements LoadableImageData {
    /** The width of the data loaded */
    private int width;
    /** The height of the data loaded */
    private int height;
    /** The texture height */
    private int texHeight;
    /** The texture width */
    private int texWidth;
    /** The data format of this PNG */
    private Format format;
    /** The scratch buffer storing the image data */
    private ByteBuffer scratch;

    /**
     * @see org.newdawn.slick.opengl.ImageData#getFormat()
     */
    public Format getFormat() {
        return format;
    }

    /**
     * @see org.newdawn.slick.opengl.ImageData#getImageBufferData()
     */
    public ByteBuffer getImageBufferData() {
        return scratch;
    }

    /**
     * @see org.newdawn.slick.opengl.ImageData#getTexHeight()
     */
    public int getTexHeight() {
        return texHeight;
    }

    /**
     * @see org.newdawn.slick.opengl.ImageData#getTexWidth()
     */
    public int getTexWidth() {
        return texWidth;
    }

    /**
     * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream)
     */
    public ByteBuffer loadImage(InputStream fis) throws IOException {
        return loadImage(fis, false, null);
    }

    /**
     * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, int[])
     */
    public ByteBuffer loadImage(InputStream fis, boolean flipped, @Nullable int[] transparent) throws IOException {
        return loadImage(fis, flipped, false, transparent);
    }

    /**
     * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
     */
    public ByteBuffer loadImage(InputStream fis, boolean flipped, boolean forceAlpha, @Nullable int[] transparent) throws IOException {
        if (transparent != null) {
            forceAlpha = true;
        }

        PNGDecoder decoder = new PNGDecoder(fis);

        width = decoder.getWidth();
        height = decoder.getHeight();
        texWidth = get2Fold(width);
        texHeight = get2Fold(height);

        final PNGDecoder.Format decoderFormat;
        if (forceAlpha) {
            if (decoder.isRGB()) {
                decoderFormat = decoder.decideTextureFormat(PNGDecoder.Format.RGBA);
            } else {
                decoderFormat = decoder.decideTextureFormat(PNGDecoder.Format.LUMINANCE_ALPHA);
            }
        } else {
            decoderFormat = decoder.decideTextureFormat(PNGDecoder.Format.LUMINANCE);
        }

        switch (decoderFormat) {
            case RGB:
                format = Format.RGB;
                break;
            case RGBA:
                format = Format.RGBA;
                break;
            case BGRA:
                format = Format.BGRA;
                break;
            case LUMINANCE:
                format = Format.GRAY;
                break;
            case LUMINANCE_ALPHA:
                format = Format.GRAYALPHA;
                break;
            default:
                throw new IOException("Unsupported Image format.");
        }

        int perPixel = format.getColorComponents();

        // Get a pointer to the image memory
        scratch = BufferUtils.createByteBuffer(texWidth * texHeight * perPixel);

        if (flipped) {
            decoder.decodeFlipped(scratch, texWidth * perPixel, decoderFormat);
        } else {
            decoder.decode(scratch, texWidth * perPixel, decoderFormat);
        }

        if (height < texHeight-1) {
            int topOffset = (texHeight-1) * (texWidth*perPixel);
            int bottomOffset = (height-1) * (texWidth*perPixel);
            for (int x=0;x<texWidth;x++) {
                for (int i=0;i<perPixel;i++) {
                    scratch.put(topOffset+x+i, scratch.get(x+i));
                    scratch.put(bottomOffset+(texWidth*perPixel)+x+i, scratch.get(bottomOffset+x+i));
                }
            }
        }
        if (width < texWidth-1) {
            for (int y=0;y<texHeight;y++) {
                for (int i=0;i<perPixel;i++) {
                    scratch.put(((y+1)*(texWidth*perPixel))-perPixel+i, scratch.get(y*(texWidth*perPixel)+i));
                    scratch.put((y*(texWidth*perPixel))+(width*perPixel)+i, scratch.get((y*(texWidth*perPixel))+((width-1)*perPixel)+i));
                }
            }
        }

        scratch.position(0);

        if (transparent != null) {
            // components will now be + 1
            final int components = format.getColorComponents();

            if (transparent.length != components - 1) {
                Log.warn("The amount of color components of the transparent color does not fit the number of color components of the actual image.");
            }

            if (transparent.length < components - 1) {
                Log.error("Failed to apply transparent color, not enough color values in color definition.");
            } else {

                final int size = texWidth * texHeight * components;
                boolean match;

                for (int i = 0; i < size; i += components) {
                    match = true;
                    for (int c = 0; c < components - 1; c++) {
                        if (toInt(scratch.get(i + c)) != transparent[c]) {
                            match = false;
                            break;
                        }
                    }
                    if (match) {
                        scratch.put(i + components - 1, (byte) 0);
                    }
                }
            }
        }

        scratch.position(0);

        return scratch;
    }

    /**
     * Safe convert byte to int
     *
     * @param b The byte to convert
     * @return The converted byte
     */
    private int toInt(byte b) {
        if (b < 0) {
            return 256+b;
        }

        return b;
    }

    /**
     * Get the closest greater power of 2 to the fold number
     *
     * @param fold The target number
     * @return The power of 2
     */
    private int get2Fold(int fold) {
        int ret = 2;
        while (ret < fold) {
            ret *= 2;
        }
        return ret;
    }

    /**
     * @see org.newdawn.slick.opengl.LoadableImageData#configureEdging(boolean)
     */
    public void configureEdging(boolean edging) {
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }
}


text:
package com.sjc.cc.base.vo;

import java.io.Serializable;

/**
 * Ajax提交返回对象

 * AjaxResult在JavaScript使用方法:

 * 如果data字段中存放的是如下Class的实例:

 * public class KeyValue { private String key; private String value; public
 * KeyValue(String key, String value) { this.key = key; this.value = value; }
 * public String getKey() { return key; } public String getValue() { return
 * value; } }

 * 那么在EXT的Ajax调用中写如下代码: action.result.data.key
 * 返回KeyValue的key值;action.result.data.value返回KeyValue的value值。
 *
 * @author 龚林林
 */
public class AjaxResult implements Serializable {
    private static final long serialVersionUID = 1L;
    /** 为Ajax提交 */
    public static final int AJAX_SUBMIT = 1;
    /** Ajax取数据 */
    public static final int AJAX_DATA = 2;

    private boolean success;
    /**
     * Ajax返回结果
     */
    private Object data;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 请求类型,1、为Ajax提交;2、为Ajax取数据
     */
    private int requestType;

    public boolean isSuccess() {
        return success;
    }

    public Object getData() {
        return data;
    }

    public int getRequestType() {
        return requestType;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * Ajax提交
     *
     * @param success Ajax提交操作是否成功
     * @param data Ajax提交后的回页面数据
     */
    public AjaxResult(boolean success, Object data) {
        this.success = success;
        this.data = data;
        requestType = 1;
    }

    /**
     * Ajax提交出错
     *
     * @param success
     * @param errorMessage
     */
    public AjaxResult(boolean success, String errorMessage) {
        this.success = success;
        if (success) {// 防止出现data为String类型的请求返回
            this.data = errorMessage;
        }
        else {
            this.errorMessage = errorMessage;
        }
        requestType = 1;
    }

    /**
     * Ajax提交
     *
     * @param success Ajax提交操作是否成功
     */
    public AjaxResult(boolean success) {
        this.success = success;
        requestType = 1;
    }

    /**
     * Ajax取数据
     *
     *
     * @param data Ajax取的数据
     */
    public AjaxResult(Object data) {
        this.data = data;
        requestType = 2;
    }

    public String toString() {
        switch (requestType) {
        case AJAX_SUBMIT:// Ajax提交,需要有是否成功的标志
            return "success=" + success + ", data=" + data;
        case AJAX_DATA:// Ajax取数据,仅有数据即可
            return "data=" + data;
        default:
            return "未知类型[" + requestType + "],success=" + success + ", data="
                    + data;
        }
    }
}


text:
from model.customer import Customer
import random

def test_delete_some_customer(app, db, check_ui):
    if len(db.get_customer_list) == 0:
        app.customer.create(Customer(firstname = "newFirstname", lastname = "newLastname", address = "newAddres",
                                    email = "newEmail", homephone = "12345667", mobilephone="1243224",
                                    workphone="1231412", secondaryphone="423423423"))
    old_customers = db.get_customer_list()
    customer = random.choice(old_customers)
    app.customer.delete_customer_by_id(customer.id)
    #assert len(old_customers) - 1 == app.customer.count()
    new_customers = db.get_customer_list()
    old_customers.remove(customer)
    assert old_customers == new_customers
    if check_ui:
        assert sorted(new_customers, key=Customer.id_or_max) == sorted(app.customer.get_customer_list(),
                                                                      key=Customer.id_or_max)


text:
// Copyright 2015-2019 Hans Dembinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_HISTOGRAM_AXIS_OPTION_HPP
#define BOOST_HISTOGRAM_AXIS_OPTION_HPP

#include <type_traits>

/**
  \file option.hpp Options for builtin axis types.

  Options `circular` and `growth` are mutually exclusive.
  Options `circular` and `underflow` are mutually exclusive.
*/

namespace boost {
namespace histogram {
namespace axis {
namespace option {

/// Holder of axis options.
template <unsigned Bits>
struct bitset : std::integral_constant<unsigned, Bits> {

  /// Returns true if all option flags in the argument are set and false otherwise.
  template <unsigned B>
  static constexpr auto test(bitset<B>) {
    // B + 0 needed to avoid false positive -Wtautological-compare in gcc-6
    return std::integral_constant<bool, static_cast<bool>((Bits & B) == (B + 0))>{};
  }
};

/// Set union of the axis option arguments.
template <unsigned B1, unsigned B2>
constexpr auto operator|(bitset<B1>, bitset<B2>) {
  return bitset<(B1 | B2)>{};
}

/// Set intersection of the option arguments.
template <unsigned B1, unsigned B2>
constexpr auto operator&(bitset<B1>, bitset<B2>) {
  return bitset<(B1 & B2)>{};
}

/// Set difference of the option arguments.
template <unsigned B1, unsigned B2>
constexpr auto operator-(bitset<B1>, bitset<B2>) {
  return bitset<(B1 & ~B2)>{};
}

/**
  Single option flag.

  @tparam Pos position of the bit in the set.
*/
template <unsigned Pos>
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
using bit = bitset<(1 << Pos)>;
#else
struct bit;
#endif

/// All options off.
using none_t = bitset<0>;
/// Axis has an underflow bin. Mutually exclusive with `circular`.
using underflow_t = bit<0>;
/// Axis has overflow bin.
using overflow_t = bit<1>;
/// Axis is circular. Mutually exclusive with `growth` and `underflow`.
using circular_t = bit<2>;
/// Axis can grow. Mutually exclusive with `circular`.
using growth_t = bit<3>;

constexpr none_t none{};           ///< Instance of `none_t`.
constexpr underflow_t underflow{}; ///< Instance of `underflow_t`.
constexpr overflow_t overflow{};   ///< Instance of `overflow_t`.
constexpr circular_t circular{};   ///< Instance of `circular_t`.
constexpr growth_t growth{};       ///< Instance of `growth_t`.

} // namespace option
} // namespace axis
} // namespace histogram
} // namespace boost

#endif


text:
A simple python crawler for [sexinsex board](http://www.sexinsex.net)

Also works for most Discuz! forums. Just change the start url in config file.

# Usage

First change the settings in config.py

To download the initial page:

    python3 initializer.py

To extract all thread ids in the initial page (extracted thread ids are stored in a list and dumped to a pickle file):

    python3 thread_tids_extractor.py

To download all threads from the list you just extracted from the initial page (all html files are saved to the html folder):

    python3 selenium_html_downloader.py

To extract the main contents of all html files in the html folder (saved to the text folder):

    python3 page_content_extractor.py

To extract attachment ids in all html files in the html folder (extracted attachment ids are stored in a list and dumped to a pickle file):

    python3 page_aids_extractor.py

To download all attachments from the list you just extracted from files in the html folder (attachments are saved to your Downloads folder):

    python3 selenium_attachment_downloader.py

Note that you must have selenium and chromedriver installed to run programs that start with "selenium". Most pages and attachments are only available after you login, so you may need to fill in your login credentials in config.py to download them.

# Known bugs

There are a lot of empty .crdownload files generated in your download folder if you run selenium_attachment_downloader.py, but all files actually finished downloading and it's safe to remove these empty .crdownload files. You will not miss any  attachment.


text:
package org.apache.activemq.leveldb.test;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.leveldb.replicated.ElectingLevelDBStore;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import javax.jms.*;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.*;

/**
 * Holds broker unit tests of the replicated leveldb store.
 */
public class ReplicatedLevelDBBrokerTest extends ZooKeeperTestSupport {

    protected static final Logger LOG = LoggerFactory.getLogger(ReplicatedLevelDBBrokerTest.class);
    final SynchronousQueue<BrokerService> masterQueue = new SynchronousQueue<BrokerService>();
    ArrayList<BrokerService> brokers = new ArrayList<BrokerService>();

    /**
     * Tries to replicate the problem reported at:
     * https://issues.apache.org/jira/browse/AMQ-4837
     */
    @Ignore("https://issues.apache.org/jira/browse/AMQ-5512")
    @Test(timeout = 1000*60*10)
    public void testAMQ4837viaJMS() throws Throwable {
        testAMQ4837(false);
    }

  /**
     * Tries to replicate the problem reported at:
     * https://issues.apache.org/jira/browse/AMQ-4837
     */
   @Ignore("https://issues.apache.org/jira/browse/AMQ-5512")
    @Test(timeout = 1000*60*10)
    public void testAMQ4837viaJMX() throws Throwable {
        for (int i = 0; i < 2; i++) {
            LOG.info("testAMQ4837viaJMX - Iteration: " + i);
            resetDataDirs();
            testAMQ4837(true);
            stopBrokers();
        }
    }

    @Before
    public void resetDataDirs() throws IOException {
        deleteDirectory("node-1");
        deleteDirectory("node-2");
        deleteDirectory("node-3");
    }

    public interface Client{
        public void execute(Connection connection) throws Exception;
    }

    protected Thread startFailoverClient(String name, final Client client) throws IOException, URISyntaxException {
        String url = "failover://(tcp://localhost:"+port+")?maxReconnectDelay=500&nested.wireFormat.maxInactivityDuration=1000";
        final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
        Thread rc = new Thread(name) {
            @Override
            public void run() {
                Connection connection = null;
                try {
                    connection = factory.createConnection();
                    client.execute(connection);
                } catch (Throwable e) {
                    e.printStackTrace();
                } finally {
                    try {
                        connection.close();
                    } catch (JMSException e) {
                    }
                }
            }
        };
        rc.start();
        return rc;
    }

    @Test
    @Ignore
    public void testReplicationQuorumLoss() throws Throwable {

        System.out.println("======================================");
        System.out.println(" Start 2 ActiveMQ nodes.");
        System.out.println("======================================");
        startBrokerAsync(createBrokerNode("node-1", port));
        startBrokerAsync(createBrokerNode("node-2", port));
        BrokerService master = waitForNextMaster();
        System.out.println("======================================");
        System.out.println(" Start the producer and consumer");
        System.out.println("======================================");

        final AtomicBoolean stopClients = new AtomicBoolean(false);
        final ArrayBlockingQueue<String> errors = new ArrayBlockingQueue<String>(100);
        final AtomicLong receivedCounter = new AtomicLong();
        final AtomicLong sentCounter = new AtomicLong();
        Thread producer = startFailoverClient("producer", new Client() {
            @Override
            public void execute(Connection connection) throws Exception {
                Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
                MessageProducer producer = session.createProducer(session.createQueue("test"));
                long actual = 0;
                while(!stopClients.get()) {
                    TextMessage msg = session.createTextMessage("Hello World");
                    msg.setLongProperty("id", actual++);
                    producer.send(msg);
                    sentCounter.incrementAndGet();
                }
            }
        });

        Thread consumer = startFailoverClient("consumer", new Client() {
            @Override
            public void execute(Connection connection) throws Exception {
                connection.start();
                Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
                MessageConsumer consumer = session.createConsumer(session.createQueue("test"));
                long expected = 0;
                while(!stopClients.get()) {
                    Message msg = consumer.receive(200);
                    if( msg!=null ) {
                        long actual = msg.getLongProperty("id");
                        if( actual != expected ) {
                            errors.offer("Received got unexpected msg id: "+actual+", expected: "+expected);
                        }
                        msg.acknowledge();
                        expected = actual+1;
                        receivedCounter.incrementAndGet();
                    }
                }
            }
        });

        try {
            assertCounterMakesProgress(sentCounter, 10, TimeUnit.SECONDS);
            assertCounterMakesProgress(receivedCounter, 5, TimeUnit.SECONDS);
            assertNull(errors.poll());

            System.out.println("======================================");
            System.out.println(" Master should stop once the quorum is lost.");
            System.out.println("======================================");
            ArrayList<BrokerService> stopped = stopSlaves();// stopping the slaves should kill the quorum.
            assertStopsWithin(master, 10, TimeUnit.SECONDS);
            assertNull(errors.poll()); // clients should not see an error since they are failover clients.
            stopped.add(master);

            System.out.println("======================================");
            System.out.println(" Restart the slave. Clients should make progress again..");
            System.out.println("======================================");
            startBrokersAsync(createBrokerNodes(stopped));
            assertCounterMakesProgress(sentCounter, 10, TimeUnit.SECONDS);
            assertCounterMakesProgress(receivedCounter, 5, TimeUnit.SECONDS);
            assertNull(errors.poll());
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        } finally {
            // Wait for the clients to stop..
            stopClients.set(true);
            producer.join();
            consumer.join();
        }
    }

    protected void startBrokersAsync(ArrayList<BrokerService> brokers) {
        for (BrokerService broker : brokers) {
            startBrokerAsync(broker);
        }
    }

    protected ArrayList<BrokerService> createBrokerNodes(ArrayList<BrokerService> brokers) throws Exception {
        ArrayList<BrokerService> rc = new ArrayList<BrokerService>();
        for (BrokerService b : brokers) {
            rc.add(createBrokerNode(b.getBrokerName(), connectPort(b)));
        }
        return rc;
    }

    protected ArrayList<BrokerService> stopSlaves() throws Exception {
        ArrayList<BrokerService> rc = new ArrayList<BrokerService>();
        for (BrokerService broker : brokers) {
            if( broker.isSlave() ) {
                System.out.println("Stopping slave: "+broker.getBrokerName());
                broker.stop();
                broker.waitUntilStopped();
                rc.add(broker);
            }
        }
        brokers.removeAll(rc);
        return rc;
    }

    protected void assertStopsWithin(final BrokerService master, int timeout, TimeUnit unit) throws InterruptedException {
        within(timeout, unit, new Task(){
            @Override
            public void run() throws Exception {
                assertTrue(master.isStopped());
            }
        });
    }

    protected void assertCounterMakesProgress(final AtomicLong counter, int timeout, TimeUnit unit) throws InterruptedException {
        final long initial = counter.get();
        within(timeout, unit, new Task(){
            public void run() throws Exception {
                assertTrue(initial < counter.get());
            }
        });
    }

    public void testAMQ4837(boolean jmx) throws Throwable {

        try {
            System.out.println("======================================");
            System.out.println("1.	Start 3 activemq nodes.");
            System.out.println("======================================");
            startBrokerAsync(createBrokerNode("node-1"));
            startBrokerAsync(createBrokerNode("node-2"));
            startBrokerAsync(createBrokerNode("node-3"));

            BrokerService master = waitForNextMaster();
            System.out.println("======================================");
            System.out.println("2.	Push a message to the master and browse the queue");
            System.out.println("======================================");
            sendMessage(master, pad("Hello World #1", 1024));
            assertEquals(1, browseMessages(master, jmx).size());

            System.out.println("======================================");
            System.out.println("3.	Stop master node");
            System.out.println("======================================");
            stop(master);
            BrokerService prevMaster = master;
            master = waitForNextMaster();

            System.out.println("======================================");
            System.out.println("4.	Push a message to the new master and browse the queue. Message summary and queue content ok.");
            System.out.println("======================================");
            assertEquals(1, browseMessages(master, jmx).size());
            sendMessage(master, pad("Hello World #2", 1024));
            assertEquals(2, browseMessages(master, jmx).size());

            System.out.println("======================================");
            System.out.println("5.	Restart the stopped node & 6. stop current master");
            System.out.println("======================================");
            brokers.remove(prevMaster);
            prevMaster = createBrokerNode(prevMaster.getBrokerName());
            startBrokerAsync(prevMaster);
            stop(master);

            master = waitForNextMaster();
            System.out.println("======================================");
            System.out.println("7.	Browse the queue on new master");
            System.out.println("======================================");
            assertEquals(2, browseMessages(master, jmx).size());
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }

    }

    private void stop(BrokerService master) throws Exception {
        System.out.println("Stopping "+master.getBrokerName());
        master.stop();
        master.waitUntilStopped();
    }

    private BrokerService waitForNextMaster() throws InterruptedException {
        System.out.println("Wait for master to start up...");
        BrokerService master = masterQueue.poll(60, TimeUnit.SECONDS);
        assertNotNull("Master elected", master);
        assertFalse(master.isSlave());
        assertNull("Only one master elected at a time..", masterQueue.peek());
        System.out.println("Master started: " + master.getBrokerName());
        return master;
    }

    private String pad(String value, int size) {
        while( value.length() < size ) {
            value += " ";
        }
        return value;
    }

    private void startBrokerAsync(BrokerService b) {
        final BrokerService broker = b;
        new Thread("Starting broker node: "+b.getBrokerName()){
            @Override
            public void run() {
                try {
                    broker.start();
                    broker.waitUntilStarted();
                    masterQueue.put(broker);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    private void sendMessage(BrokerService brokerService, String body) throws Exception {
        TransportConnector connector = brokerService.getTransportConnectors().get(0);
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connector.getConnectUri());
        Connection connection = factory.createConnection();
        try {
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(session.createQueue("FOO"));
            producer.send(session.createTextMessage(body));
        } finally {
            connection.close();
        }
    }
    private ArrayList<String> browseMessages(BrokerService brokerService, boolean jmx) throws Exception {
        if( jmx ) {
            return browseMessagesViaJMX(brokerService);
        } else {
            return browseMessagesViaJMS(brokerService);
        }
    }

    private ArrayList<String> browseMessagesViaJMX(BrokerService brokerService) throws Exception {
        ArrayList<String> rc = new ArrayList<String>();
        ObjectName on = new ObjectName("org.apache.activemq:type=Broker,brokerName="+brokerService.getBrokerName()+",destinationType=Queue,destinationName=FOO");
        CompositeData[] browse = (CompositeData[]) ManagementFactory.getPlatformMBeanServer().invoke(on, "browse", null, null);
        for (CompositeData cd : browse) {
            rc.add(cd.get("Text").toString()) ;
        }
        return rc;
    }

    private ArrayList<String> browseMessagesViaJMS(BrokerService brokerService) throws Exception {
        ArrayList<String> rc = new ArrayList<String>();
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:"+ connectPort(brokerService));
        Connection connection = factory.createConnection();
        try {
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueBrowser browser = session.createBrowser(session.createQueue("FOO"));
            Enumeration enumeration = browser.getEnumeration();
            while (enumeration.hasMoreElements()) {
                TextMessage textMessage = (TextMessage) enumeration.nextElement();
                rc.add(textMessage.getText());
            }
        } finally {
            connection.close();
        }
        return rc;
    }

    private int connectPort(BrokerService brokerService) throws IOException, URISyntaxException {
        TransportConnector connector = brokerService.getTransportConnectors().get(0);
        return connector.getConnectUri().getPort();
    }

    int port;
    @Before
    public void findFreePort() throws Exception {
        ServerSocket socket = new ServerSocket(0);
        port = socket.getLocalPort();
        socket.close();
    }

    @After
    public void stopBrokers() throws Exception {
        for (BrokerService broker : brokers) {
            try {
                stop(broker);
            } catch (Exception e) {
            }
        }
        brokers.clear();
        resetDataDirs();
    }

    private BrokerService createBrokerNode(String id) throws Exception {
        return createBrokerNode(id, 0);
    }

    private BrokerService createBrokerNode(String id, int port) throws Exception {
        BrokerService bs = new BrokerService();
        bs.getManagementContext().setCreateConnector(false);
        brokers.add(bs);
        bs.setBrokerName(id);
        bs.setPersistenceAdapter(createStoreNode(id));
        TransportConnector connector = new TransportConnector();
        connector.setUri(new URI("tcp://0.0.0.0:" + port));
        bs.addConnector(connector);
        return bs;
    }

    private ElectingLevelDBStore createStoreNode(String id) {

        // This little hack is in here because we give each of the 3 brokers
        // different broker names so they can show up in JMX correctly,
        // but the store needs to be configured with the same broker name
        // so that they can find each other in ZK properly.
        ElectingLevelDBStore store = new ElectingLevelDBStore() {
            @Override
            public void start() throws Exception {
                this.setBrokerName("localhost");
                super.start();
            }
        };
        store.setDirectory(new File(data_dir(), id));
        store.setContainer(id);
        store.setReplicas(3);
        store.setSync("quorum_disk");
        store.setZkAddress("localhost:" + connector.getLocalPort());
        store.setZkSessionTimeout("15s");
        store.setHostname("localhost");
        store.setBind("tcp://0.0.0.0:0");
        return store;
    }
}


text:
from __future__ import absolute_import, division, print_function, unicode_literals

import os
import logging

log = logging.getLogger('custodian.config')

class Bag(dict):
    def __getattr__(self, k):
        try:
            return self[k]
        except KeyError:
            raise AttributeError(k)

    def __setattr__(self, k, v):
        self[k] = v

class Config(Bag):

    def copy(self, **kw):
        d = {}
        d.update(self)
        d.update(**kw)
        return Config(d)

    @classmethod
    def empty(cls, **kw):
        d = {}
        d.update({
            'region': os.environ.get('AWS_DEFAULT_REGION', 'us-east-1'),
            'regions': (),
            'cache': '',
            'profile': None,
            'account_id': None,
            'assume_role': None,
            'external_id': None,
            'log_group': None,
            'tracer': 'default',
            'metrics_enabled': False,
            'metrics': None,
            'output_dir': '',
            'cache_period': 0,
            'dryrun': False,
            'authorization_file': None})
        d.update(kw)
        return cls(d)