text:
#include <compiz-core.h>

static CompMetadata commandsMetadata;

static int displayPrivateIndex;

#define COMMANDS_DISPLAY_OPTION_COMMAND0             0
#define COMMANDS_DISPLAY_OPTION_COMMAND1             1
#define COMMANDS_DISPLAY_OPTION_COMMAND2             2
#define COMMANDS_DISPLAY_OPTION_COMMAND3             3
#define COMMANDS_DISPLAY_OPTION_COMMAND4             4
#define COMMANDS_DISPLAY_OPTION_COMMAND5             5
#define COMMANDS_DISPLAY_OPTION_COMMAND6             6
#define COMMANDS_DISPLAY_OPTION_COMMAND7             7
#define COMMANDS_DISPLAY_OPTION_COMMAND8             8
#define COMMANDS_DISPLAY_OPTION_COMMAND9             9
#define COMMANDS_DISPLAY_OPTION_COMMAND10            10
#define COMMANDS_DISPLAY_OPTION_COMMAND11            11
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_KEY     12
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND1_KEY     13
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND2_KEY     14
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND3_KEY     15
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND4_KEY     16
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND5_KEY     17
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND6_KEY     18
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND7_KEY     19
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND8_KEY     20
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND9_KEY     21
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND10_KEY    22
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND11_KEY    23
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_BUTTON  24
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND1_BUTTON  25
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND2_BUTTON  26
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND3_BUTTON  27
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND4_BUTTON  28
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND5_BUTTON  29
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND6_BUTTON  30
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND7_BUTTON  31
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND8_BUTTON  32
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND9_BUTTON  33
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND10_BUTTON 34
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND11_BUTTON 35
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_EDGE    36
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND1_EDGE    37
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND2_EDGE    38
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND3_EDGE    39
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND4_EDGE    40
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND5_EDGE    41
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND6_EDGE    42
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND7_EDGE    43
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND8_EDGE    44
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND9_EDGE    45
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND10_EDGE   46
#define COMMANDS_DISPLAY_OPTION_RUN_COMMAND11_EDGE   47
#define COMMANDS_DISPLAY_OPTION_NUM                  48

typedef struct _CommandsDisplay
{
   CompOption opt[COMMANDS_DISPLAY_OPTION_NUM];
} CommandsDisplay;

#define GET_COMMANDS_DISPLAY(d) \
  ((CommandsDisplay *)(d)->base.privates[displayPrivateIndex].ptr)
#define COMMANDS_DISPLAY(d) \
  CommandsDisplay * cd = GET_COMMANDS_DISPLAY(d)

#define NUM_OPTIONS(d) (sizeof ((d)->opt) / sizeof (CompOption))

static Bool
runCommandDispatch(CompDisplay *d,
                   CompAction *action,
                   CompActionState state,
                   CompOption *option,
                   int nOption)
{
   CompScreen *s;
   Window xid;

   xid = getIntOptionNamed(option, nOption, "root", 0);
   s = findScreenAtDisplay(d, xid);

   if (s)
     {
        int index = COMMANDS_DISPLAY_OPTION_COMMAND0 + action->priv.val;

        COMMANDS_DISPLAY(d);

        runCommand(s, cd->opt[index].value.s);
     }

   return TRUE;
}

static const CompMetadataOptionInfo commandsDisplayOptionInfo[] = {
   { "command0", "string", 0, 0, 0 },
   { "command1", "string", 0, 0, 0 },
   { "command2", "string", 0, 0, 0 },
   { "command3", "string", 0, 0, 0 },
   { "command4", "string", 0, 0, 0 },
   { "command5", "string", 0, 0, 0 },
   { "command6", "string", 0, 0, 0 },
   { "command7", "string", 0, 0, 0 },
   { "command8", "string", 0, 0, 0 },
   { "command9", "string", 0, 0, 0 },
   { "command10", "string", 0, 0, 0 },
   { "command11", "string", 0, 0, 0 },
   { "run_command0_key", "key", 0, runCommandDispatch, 0 },
   { "run_command1_key", "key", 0, runCommandDispatch, 0 },
   { "run_command2_key", "key", 0, runCommandDispatch, 0 },
   { "run_command3_key", "key", 0, runCommandDispatch, 0 },
   { "run_command4_key", "key", 0, runCommandDispatch, 0 },
   { "run_command5_key", "key", 0, runCommandDispatch, 0 },
   { "run_command6_key", "key", 0, runCommandDispatch, 0 },
   { "run_command7_key", "key", 0, runCommandDispatch, 0 },
   { "run_command8_key", "key", 0, runCommandDispatch, 0 },
   { "run_command9_key", "key", 0, runCommandDispatch, 0 },
   { "run_command10_key", "key", 0, runCommandDispatch, 0 },
   { "run_command11_key", "key", 0, runCommandDispatch, 0 },
   { "run_command0_button", "button", 0, runCommandDispatch, 0 },
   { "run_command1_button", "button", 0, runCommandDispatch, 0 },
   { "run_command2_button", "button", 0, runCommandDispatch, 0 },
   { "run_command3_button", "button", 0, runCommandDispatch, 0 },
   { "run_command4_button", "button", 0, runCommandDispatch, 0 },
   { "run_command5_button", "button", 0, runCommandDispatch, 0 },
   { "run_command6_button", "button", 0, runCommandDispatch, 0 },
   { "run_command7_button", "button", 0, runCommandDispatch, 0 },
   { "run_command8_button", "button", 0, runCommandDispatch, 0 },
   { "run_command9_button", "button", 0, runCommandDispatch, 0 },
   { "run_command10_button", "button", 0, runCommandDispatch, 0 },
   { "run_command11_button", "button", 0, runCommandDispatch, 0 },
   { "run_command0_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command1_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command2_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command3_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command4_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command5_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command6_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command7_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command8_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command9_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command10_edge", "edge", 0, runCommandDispatch, 0 },
   { "run_command11_edge", "edge", 0, runCommandDispatch, 0 }
};

static CompBool
commandsInitDisplay(CompPlugin *p,
                    CompDisplay *d)
{
   CommandsDisplay *cd;
   int i;

   if (!checkPluginABI("core", CORE_ABIVERSION))
     return FALSE;

   cd = malloc(sizeof (CommandsDisplay));
   if (!cd)
     return FALSE;

   if (!compInitDisplayOptionsFromMetadata(d,
                                           &commandsMetadata,
                                           commandsDisplayOptionInfo,
                                           cd->opt,
                                           COMMANDS_DISPLAY_OPTION_NUM))
     {
        free(cd);
        return FALSE;
     }

   for (i = 0; i < 12; i++)
     {
        int opt;

        opt = COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_KEY + i;
        cd->opt[opt].value.action.priv.val = i;
        opt = COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_BUTTON + i;
        cd->opt[opt].value.action.priv.val = i;
        opt = COMMANDS_DISPLAY_OPTION_RUN_COMMAND0_EDGE + i;
        cd->opt[opt].value.action.priv.val = i;
     }

   d->base.privates[displayPrivateIndex].ptr = cd;

   return TRUE;
}

static void
commandsFiniDisplay(CompPlugin *p,
                    CompDisplay *d)
{
   COMMANDS_DISPLAY(d);

   compFiniDisplayOptions(d, cd->opt, COMMANDS_DISPLAY_OPTION_NUM);

   free(cd);
}

static CompOption *
commandsGetDisplayOptions(CompPlugin *p,
                          CompDisplay *d,
                          int *count)
{
   COMMANDS_DISPLAY(d);

   *count = NUM_OPTIONS(cd);
   return cd->opt;
}

static CompBool
commandsSetDisplayOption(CompPlugin *p,
                         CompDisplay *d,
                         const char *name,
                         CompOptionValue *value)
{
   CompOption *o;

   COMMANDS_DISPLAY(d);

   o = compFindOption(cd->opt, NUM_OPTIONS(cd), name, NULL);
   if (!o)
     return FALSE;

   return compSetDisplayOption(d, o, value);
}

static CompBool
commandsInitObject(CompPlugin *p,
                   CompObject *o)
{
   static InitPluginObjectProc dispTab[] = {
      (InitPluginObjectProc)0,    /* InitCore */
      (InitPluginObjectProc)commandsInitDisplay
   };

   RETURN_DISPATCH(o, dispTab, ARRAY_SIZE(dispTab), TRUE, (p, o));
}

static void
commandsFiniObject(CompPlugin *p,
                   CompObject *o)
{
   static FiniPluginObjectProc dispTab[] = {
      (FiniPluginObjectProc)0,    /* FiniCore */
      (FiniPluginObjectProc)commandsFiniDisplay
   };

   DISPATCH(o, dispTab, ARRAY_SIZE(dispTab), (p, o));
}

static CompOption *
commandsGetObjectOptions(CompPlugin *p,
                         CompObject *o,
                         int *count)
{
   static GetPluginObjectOptionsProc dispTab[] = {
      (GetPluginObjectOptionsProc)0,    /* GetCoreOptions */
      (GetPluginObjectOptionsProc)commandsGetDisplayOptions
   };

   *count = 0;
   RETURN_DISPATCH(o, dispTab, ARRAY_SIZE(dispTab),
                   (void *)count, (p, o, count));
}

static CompBool
commandsSetObjectOption(CompPlugin *p,
                        CompObject *o,
                        const char *name,
                        CompOptionValue *value)
{
   static SetPluginObjectOptionProc dispTab[] = {
      (SetPluginObjectOptionProc)0,    /* SetCoreOption */
      (SetPluginObjectOptionProc)commandsSetDisplayOption,
   };

   RETURN_DISPATCH(o, dispTab, ARRAY_SIZE(dispTab), FALSE,
                   (p, o, name, value));
}

static Bool
commandsInit(CompPlugin *p)
{
   if (!compInitPluginMetadataFromInfo(&commandsMetadata,
                                       p->vTable->name,
                                       commandsDisplayOptionInfo,
                                       COMMANDS_DISPLAY_OPTION_NUM, 0, 0))
     return FALSE;

   displayPrivateIndex = allocateDisplayPrivateIndex();
   if (displayPrivateIndex < 0)
     {
        compFiniMetadata(&commandsMetadata);
        return FALSE;
     }

   compAddMetadataFromFile(&commandsMetadata, p->vTable->name);

   return TRUE;
}

static void
commandsFini(CompPlugin *p)
{
   freeDisplayPrivateIndex(displayPrivateIndex);
   compFiniMetadata(&commandsMetadata);
}

static CompMetadata *
commandsGetMetadata(CompPlugin *p)
{
   return &commandsMetadata;
}

static CompPluginVTable commandsVTable = {
   "commands",
   commandsGetMetadata,
   commandsInit,
   commandsFini,
   commandsInitObject,
   commandsFiniObject,
   commandsGetObjectOptions,
   commandsSetObjectOption
};

CompPluginVTable *
getCompPluginInfo20070830(void)
{
   return &commandsVTable;
}


text:
<!DOCTYPE html>

  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>AngularJS Touch Slider</title>

  <link rel="stylesheet" href="./lib/bootstrap.min.css">
  <link rel="stylesheet" href="../dist/rzslider.css"/>
  <link rel="stylesheet" href="demo.css"/>
  <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>

AngularJS Touch Slider

Simple slider

    Model: <input type="number" ng-model="minSlider.value"/>

    <rzslider rz-slider-model="minSlider.value"></rzslider>

Range slider

    Min Value: <input type="number" ng-model="rangeSlider.minValue"/>

    Max Value: <input type="number" ng-model="rangeSlider.maxValue"/>

    <rzslider
      data-rz-slider-model="rangeSlider.minValue"
      data-rz-slider-high="rangeSlider.maxValue"
      data-rz-slider-options="rangeSlider.options"
    ></rzslider>

Range slider with min limit set to 10 and max limit set to 90

    <rzslider
      rz-slider-model="minMaxLimitSlider.value"
      rz-slider-options="minMaxLimitSlider.options"
    ></rzslider>

Range slider with minimum range of 10 and maximum of 50

    <rzslider
      rz-slider-model="minMaxRangeSlider.minValue"
      rz-slider-high="minMaxRangeSlider.maxValue"
      rz-slider-options="minMaxRangeSlider.options"
    ></rzslider>

Range slider with noSwitching=true

    <rzslider
      rz-slider-model="noSwitchingSlider.minValue"
      rz-slider-high="noSwitchingSlider.maxValue"
      rz-slider-options="noSwitchingSlider.options"
    ></rzslider>

Range slider with minimum range of 10 and pushRange option

    <rzslider
      rz-slider-model="minPushRangeSlider.minValue"
      rz-slider-high="minPushRangeSlider.maxValue"
      rz-slider-options="minPushRangeSlider.options"
    ></rzslider>

Slider with visible selection bar

    <rzslider
      rz-slider-model="slider_visible_bar.value"
      rz-slider-options="slider_visible_bar.options"
    ></rzslider>

Slider with visible selection bar at the end

    <rzslider
      rz-slider-model="slider_visible_bar_end.value"
      rz-slider-options="slider_visible_bar_end.options"
    ></rzslider>

Slider with visible selection bar from a value

    <rzslider
      rz-slider-model="slider_visible_bar_from_value.value"
      rz-slider-options="slider_visible_bar_from_value.options"
    ></rzslider>

Slider with dynamic selection bar colors

    <rzslider
      rz-slider-model="color_slider_bar.value"
      rz-slider-options="color_slider_bar.options"
    ></rzslider>

Slider with dynamic pointer color

    <rzslider
      rz-slider-model="color_slider_pointer.value"
      rz-slider-options="color_slider_pointer.options"
    ></rzslider>

Slider with custom floor/ceil/step

    <rzslider
      rz-slider-model="slider_floor_ceil.value"
      rz-slider-options="slider_floor_ceil.options"
    ></rzslider>

Slider with logarithmic scale

    <rzslider
      rz-slider-model="slider_log.value"
      rz-slider-options="slider_log.options"
    ></rzslider>

Slider with custom scale

    <rzslider
      rz-slider-model="slider_custom_scale.value"
      rz-slider-options="slider_custom_scale.options"
    ></rzslider>

Right to left slider with custom floor/ceil/step

    <rzslider
      rz-slider-model="slider_floor_ceil_rtl.value"
      rz-slider-options="slider_floor_ceil_rtl.options"
    ></rzslider>

Slider with callbacks on start, change and end

Value linked on start: {{ otherData.start }}

Value linked on change: {{ otherData.change }}

Value linked on end: {{ otherData.end }}

    <rzslider
      rz-slider-model="slider_callbacks.value"
      rz-slider-options="slider_callbacks.options"
    ></rzslider>

Slider with custom display function

    <rzslider
      rz-slider-model="slider_translate.minValue"
      rz-slider-high="slider_translate.maxValue"
      rz-slider-options="slider_translate.options"
    ></rzslider>

Slider with custom display function using html formatting

    <rzslider
      rz-slider-model="slider_translate_html.minValue"
      rz-slider-high="slider_translate_html.maxValue"
      rz-slider-options="slider_translate_html.options"
    ></rzslider>

Slider with Alphabet

    Current letter: {{ slider_alphabet.value }}
    <rzslider
      rz-slider-model="slider_alphabet.value"
      rz-slider-options="slider_alphabet.options"
    ></rzslider>

Slider with ticks

    <rzslider
      rz-slider-model="slider_ticks.value"
      rz-slider-options="slider_ticks.options"
    ></rzslider>

Slider with ticks at specific positions

    <rzslider
      rz-slider-model="slider_ticks_array.value"
      rz-slider-options="slider_ticks_array.options"
    ></rzslider>

Slider with ticks and tooltips

    <rzslider
      rz-slider-model="slider_ticks_tooltip.value"
      rz-slider-options="slider_ticks_tooltip.options"
    ></rzslider>

Slider with ticks and values (and tooltips)

    <rzslider
      rz-slider-model="slider_ticks_values.value"
      rz-slider-options="slider_ticks_values.options"
    ></rzslider>

Range slider with ticks and values

    <rzslider
      rz-slider-model="range_slider_ticks_values.minValue"
      rz-slider-high="range_slider_ticks_values.maxValue"
      rz-slider-options="range_slider_ticks_values.options"
    ></rzslider>

Slider with ticks at intermediate positions

    <rzslider
      rz-slider-model="slider_ticks_at.value"
      rz-slider-options="slider_ticks_at.options"
    ></rzslider>

Slider with ticks and values at intermediate positions

    <rzslider
      rz-slider-model="slider_ticks_values_at.value"
      rz-slider-options="slider_ticks_values_at.options"
    ></rzslider>

Slider with ticks values and legend

    <rzslider class="with-legend"
      rz-slider-model="slider_ticks_legend.value"
      rz-slider-options="slider_ticks_legend.options"
    ></rzslider>

Slider with dynamic tick color

    <rzslider
      rz-slider-model="slider_tick_color.value"
      rz-slider-options="slider_tick_color.options"
    ></rzslider>

Slider with date values

    <rzslider
      rz-slider-model="slider_dates.value"
      rz-slider-options="slider_dates.options"
    ></rzslider>

Slider with draggable range

    <rzslider
      rz-slider-model="slider_draggable_range.minValue"
      rz-slider-high="slider_draggable_range.maxValue"
      rz-slider-options="slider_draggable_range.options"
    ></rzslider>

Slider with draggable range only

    <rzslider
      rz-slider-model="slider_draggable_range_only.minValue"
      rz-slider-high="slider_draggable_range_only.maxValue"
      rz-slider-options="slider_draggable_range_only.options"
    ></rzslider>

Vertical sliders

        <rzslider rz-slider-model="verticalSlider1.value" rz-slider-options="verticalSlider1.options"></rzslider>

        <rzslider rz-slider-model="verticalSlider2.minValue" rz-slider-high="verticalSlider2.maxValue"
                  rz-slider-options="verticalSlider2.options"></rzslider>

        <rzslider rz-slider-model="verticalSlider3.value" rz-slider-options="verticalSlider3.options"></rzslider>

        <rzslider rz-slider-model="verticalSlider4.minValue" rz-slider-high="verticalSlider4.maxValue"
                  rz-slider-options="verticalSlider4.options"></rzslider>

        <rzslider rz-slider-model="verticalSlider5.value" rz-slider-options="verticalSlider5.options"></rzslider>

        <rzslider rz-slider-model="verticalSlider6.value" rz-slider-options="verticalSlider6.options"></rzslider>

Disabled slider

    Disabled <input type="checkbox" ng-model="disabled_slider.options.disabled">
    <rzslider
      rz-slider-model="disabled_slider.minValue"
      rz-slider-high="disabled_slider.maxValue"
      rz-slider-options="disabled_slider.options"
    ></rzslider>

Read-only slider

    Read-only <input type="checkbox" ng-model="read_only_slider.options.readOnly">
    <rzslider
      rz-slider-model="read_only_slider.value"
      rz-slider-options="read_only_slider.options"
    ></rzslider>

Toggle slider example

    <button ng-click="toggle()">{{ visible ? 'Hide' : 'Show' }}</button>

      <rzslider
        rz-slider-model="slider_toggle.value"
        rz-slider-options="slider_toggle.options"></rzslider>

Sliders inside a modal

    Normal slider value: {{percentages.normal.low}}%

    Range slider values: {{percentages.range.low}}% and {{percentages.range.high}}%

    <button type="button" ng-click="openModal()" class="btn btn-default btn-lg">Open Modal!</button>

Sliders inside tabs

Price 1: {{tabSliders.slider1.value}}

Price 2: {{tabSliders.slider2.value}}

    <uib-tabset>
      <uib-tab heading="Slider 1" select="refreshSlider()">
        <rzslider rz-slider-model="tabSliders.slider1.value"></rzslider>
      </uib-tab>
      <uib-tab heading="Slider 2" select="refreshSlider()">
        <rzslider rz-slider-model="tabSliders.slider2.value"></rzslider>
      </uib-tab>
    </uib-tabset>

Slider with angular directive inside custom template

    <rzslider
      rz-slider-model="slider_custom_directive_inside_template.minValue"
      rz-slider-high="slider_custom_directive_inside_template.maxValue"
      rz-slider-options="slider_custom_directive_inside_template.options"
      rz-slider-tpl-url="directiveInCustomTemplate.html"
    ></rzslider>

Slider with all options demo

        Min Value: <input type="number" ng-model="slider_all_options.minValue"/>

        <input type="checkbox" ng-click="toggleHighValue()"> Max Value:
        <input type="number" ng-model="slider_all_options.maxValue" ng-disabled="slider_all_options.maxValue == null"/>

        Floor: <input type="number" ng-model="slider_all_options.options.floor"/>

        Ceil: <input type="number" ng-model="slider_all_options.options.ceil"/>

        Step: <input type="number" ng-model="slider_all_options.options.step"/>

        Precision: <input type="number" ng-model="slider_all_options.options.precision"/>

        Hide limits <input type="checkbox" ng-model="slider_all_options.options.hideLimitLabels">

        Draggable range <input type="checkbox" ng-model="slider_all_options.options.draggableRange">

        Show ticks <input type="checkbox" ng-model="slider_all_options.options.showTicks">

        Show ticks values <input type="checkbox" ng-model="slider_all_options.options.showTicksValues">

        Disabled <input type="checkbox" ng-model="slider_all_options.options.disabled">

        Read-Only <input type="checkbox" ng-model="slider_all_options.options.readOnly">

        Right to Left <input type="checkbox" ng-model="slider_all_options.options.rightToLeft">

    <rzslider
      rz-slider-model="slider_all_options.minValue"
      rz-slider-high="slider_all_options.maxValue"
      rz-slider-options="slider_all_options.options"
    ></rzslider>

redpajama_set_name: RedPajamaGithub


text:
package com.lenox.beyondj.routes;

import com.beyondj.gateway.model.HttpProxyRule;
import com.beyondj.gateway.model.UriTemplateDefinition;
import com.beyondj.gateway.scaling.IScalingDataService;
import com.beyondjservlet.gateway.servlet.HttpMappingResult;
import com.beyondjservlet.gateway.servlet.HttpMappingRuleResolver;
import com.beyondjservlet.gateway.servlet.ProxyDetails;
import com.lenox.beyondj.CoreMetricsService;
import com.lenox.beyondj.metrics.MetricFieldCollection;
import com.lenox.common.util.IpAddresssUtil;
import com.lenox.platform.*;
import com.lenox.platform.scaling.ApplicationScalingData;
import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
import org.apache.camel.Exchange;
import org.apache.camel.RoutingSlip;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.URL;
import java.util.*;

public class UrlExtractor {

    public static final String DATE = "Date";
    private static final String HOST = "Host";
    private static final String SITE = "__site";
    private IScalingDataService scalingDataService;
    private CoreMetricsService coreMetricsService;
    private HttpMappingRuleResolver resolver = new HttpMappingRuleResolver();

    public UrlExtractor(CoreMetricsService coreMetricsService, IScalingDataService scalingDataService) {
        this.coreMetricsService = coreMetricsService;
        this.scalingDataService = scalingDataService;
    }

    @RoutingSlip
    public String extractUrl(Exchange exchange) throws Exception {
        HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);

        String host = request.getParameter(SITE);
        if (StringUtils.isEmpty(host)) {
            host = exchange.getIn().getHeader(HOST, String.class);
        }

        String contextPath = request.getParameter(UNDER_SCORE_C);

        if (StringUtils.isEmpty(contextPath)) {
            String currentPath = exchange.getIn().getHeader(CAMEL_HTTP_URI, String.class);
            int first = currentPath.indexOf(FWD_SLASH);
            int second = currentPath.indexOf(FWD_SLASH, first + 1);
            if (first > -1 && second > -1) {
                contextPath = currentPath.substring(0, second);
            }
        }

        if (StringUtils.isEmpty(contextPath)) {
            String referer = exchange.getIn().getHeader(REFERER, String.class);

            if (StringUtils.isNotEmpty(referer)) {
                URL url = new URL(referer);

                String currentPath = url.getPath();

                if (currentPath == null || currentPath.equals(FWD_SLASH)) {
                    if (referer.indexOf(UNDER_SCORE_C) > -1) {
                        String newPath = referer.substring(referer.indexOf(UNDER_SCORE_C));
                        String[] parts = newPath.split("=");
                        if (parts.length > 1) {
                            contextPath = parts[1];
                        }
                    }
                }

                if (StringUtils.isEmpty(contextPath) && !FWD_SLASH.equals(currentPath)) {
                    int first = currentPath.indexOf(FWD_SLASH);
                    int second = currentPath.indexOf(FWD_SLASH, first + 1);
                    if (first > -1 && second > -1) {
                        contextPath = currentPath.substring(0, second);
                    }
                }
                if (!contextPath.startsWith(FWD_SLASH)) {
                    contextPath = FWD_SLASH + contextPath;
                }
            }
        }

        if (StringUtils.isBlank(contextPath)) {
            String urlStr = exchange.getIn().getHeader(CAMEL_HTTP_URL, String.class);

            if (StringUtils.isNotBlank(urlStr)) {
                //e.g CamelHttpUrl=http://abc.com/myContext
                URL url = new URL(urlStr);
                String path = url.getPath();

                String[] parts = path.split("/");
                if (parts.length > 1) {
                    contextPath = "/" + parts[1];
                }
            }
        }

        Validate.notEmpty(contextPath, "contextPath must not be empty");

        if (coreMetricsService.isMetricsEnabled()) {
            if (org.apache.commons.lang.StringUtils.isBlank(contextPath)) {
                MetricsMessageCollection collection =
                        createMetricMessage(Collections.unmodifiableMap(exchange.getIn().getHeaders()),
                                "UNKNWON", contextPath, MetricType.REQUEST, coreMetricsService.getHazelCastEndPoint());
                coreMetricsService.publish(collection);
            }
        }

        exchange.getIn().setHeader(CONTEXT_PATH, contextPath);
        exchange.setProperty(CONTEXT_PATH, contextPath);

        ProxyDetails proxyDetails = getProxyDetails(contextPath, exchange);

        String url = proxyDetails.getStringProxyURL();
        // url = url.replace(HTTP, PROXY);
        resetHttp4Headers(exchange);

        exchange.getOut().setHeader(TARGET_URL, url);
        exchange.getOut().setHeader(DATE, new Date().toString());
        exchange.getOut().setHeader(TARGET_CONTEXT, contextPath);
        String requestId = String.valueOf(System.currentTimeMillis() + RAND.nextLong());
        exchange.getOut().setHeader(REQUEST_ID, requestId);

        exchange.setProperty(TARGET_URL, url);
        exchange.setProperty(TARGET_CONTEXT, contextPath);
        exchange.setProperty(REQUEST_ID, requestId);

        if (!StringUtils.isEmpty(host)) {
            int index = host.indexOf(":");
            if (index > 0) {
                host = host.substring(0, index);
            }
            exchange.getIn().setHeader(SITE, host);
        }
        URL urlObj = new URL(url);

        InetAddress address = InetAddress.getByName(urlObj.getHost());
        String locationInCluster = address.getHostAddress();
        String localAddress = IpAddresssUtil.getLocalHostAddress();

        if (locationInCluster.equals(localAddress)) {
            ApplicationScalingData applicationScalingData =
                    scalingDataService.getApplicationScalingDataFor(locationInCluster, contextPath);
            if (applicationScalingData != null) {
                applicationScalingData.addRequestToken(requestId);
                LOG.debug("Updating scaling data locally and not through Hazelcast");
            }
            //TODO: scale via hazelcast
        }
        return url;
    }

    static MetricsMessageCollection createMetricMessage(final Map<String, Object> headers, final String url,
                                                        final String contextPath, MetricType metricType,
                                                        String locationInCLuster)
            throws Exception {

        MetricsMessageCollection collection = new MetricsMessageCollection();
        MetricsMessage metricsMessage = new MetricsMessage();
        metricsMessage.setServerId(IpAddresssUtil.getLocalHostAddress().toString());
        metricsMessage.setLocationInCluster(locationInCLuster);
        metricsMessage.setTargetEndpoint(url);
        metricsMessage.setContext(contextPath);
        metricsMessage.setMetricType(metricType);

        Iterator<String> it = headers.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            if (headers.get(key) == null) {
                continue;
            }
            if (MetricFieldCollection.INSTANCE.shouldCaptureField(key) == false) {
                continue;
            }
            try {
                KeyValuePair keyValuePair = new KeyValuePair();
                keyValuePair.setKey(key);
                keyValuePair.setValueType(ValueType.STRING);
                keyValuePair.setStringValue(String.valueOf(headers.get(key)));
                metricsMessage.getHeaders().add(keyValuePair);
            } catch (Exception e) {
                //do nothing
            }
        }

        metricsMessage.setTargetEndpoint(url == null ? "" : url);
        metricsMessage.setServerId(IpAddresssUtil.getLocalHostAddress().toString());
        metricsMessage.setContext(contextPath == null ? "" : contextPath);
        DateTime dateTime = new DateTime();
        final GregorianCalendar calendar = new GregorianCalendar(dateTime.getZone().toTimeZone());
        calendar.setTimeInMillis(dateTime.getMillis());
        metricsMessage.setDateTimeCreated(new XMLGregorianCalendarImpl(calendar));

        collection.getMessages().add(metricsMessage);
        return collection;
    }

    private void resetHttp4Headers(Exchange exchange) {
        String camelHttpPath = exchange.getIn().getHeader(CAMEL_HTTP_PATH, String.class);
        String contextPath = exchange.getIn().getHeader(CONTEXT_PATH, String.class);

        if (camelHttpPath != null) {
            String replacement = contextPath;
            if (!camelHttpPath.startsWith(FWD_SLASH) && contextPath.startsWith(FWD_SLASH)) {
                replacement = contextPath.substring(1);
            }
            replacement = replacement + FWD_SLASH;
            camelHttpPath = camelHttpPath.replace(replacement, "");
            exchange.getIn().setHeader(CAMEL_HTTP_PATH, camelHttpPath);
        }

        String camelHttpUri = exchange.getIn().getHeader(CAMEL_HTTP_URI, String.class);

        if (camelHttpUri != null) {
            if (!contextPath.startsWith(FWD_SLASH)) {
                contextPath = FWD_SLASH + contextPath;
            }
            if (camelHttpUri.startsWith(contextPath)) {
                camelHttpUri = camelHttpUri.replace(contextPath, "");
            }
            exchange.getIn().setHeader(CAMEL_HTTP_URI, camelHttpUri);
        }
    }

    private ProxyDetails getProxyDetails(String contextPath, Exchange exchange) {
        if (!contextPath.startsWith(FWD_SLASH)) {
            contextPath = FWD_SLASH + contextPath;
        }
        int first = contextPath.indexOf(FWD_SLASH);
        int second = contextPath.indexOf(FWD_SLASH, first + 1);
        if (second != -1) {
            contextPath = contextPath.substring(0, second);
        }
        ProxyDetails proxyDetails = createProxyDetails(contextPath, exchange);
        return proxyDetails;
    }

    private ProxyDetails createProxyDetails(String contextPath, Exchange exchange) {
        HttpMappingResult mappingRule = resolver.findMappingRule(contextPath);

        if (mappingRule == null) {
            String referer = (String) exchange.getIn().getHeader(REFERER);
            if (referer != null && referer.indexOf(UNDER_SCORE_C) > -1) {
                String newPath = referer.substring(referer.indexOf(UNDER_SCORE_C));
                String[] parts = newPath.split("=");
                if (parts.length > 1) {
                    contextPath = parts[1];
                    mappingRule = resolver.findMappingRule(contextPath);
                }
            }
        }

        if (mappingRule == null) {
            LOG.error("Could not find mappingRule for {}. Perhaps this a request with / as contextPath ... " +
                    "Please use a named contextPath and not /", contextPath, contextPath);
        }
        Validate.notNull(mappingRule, String.format("Could not find mappingRule for %s. " +
                "Perhaps this a request with / as contextPath ... " +
                "Please use a named contextPath and not /", contextPath));

        final HttpProxyRule proxyRule = mappingRule.getProxyRule();
        if (proxyRule != null) {
            List<UriTemplateDefinition> defs = new ArrayList<>(proxyRule.getDestinationUriTemplates());

            String cookie = exchange.getIn().getHeader(COOKIE, String.class);

            UriTemplateDefinition def = proxyRule
                    .getLoadBalancerDefinition().getLoadBalancer()
                    .choose(defs, cookie);

            if (def == null) {
                StringBuilder builder = new StringBuilder();
                for (UriTemplateDefinition definition : proxyRule.getDestinationUriTemplates()) {
                    builder.append("\n" + definition.toString());
                }
                LOG.error("Could not find template definition for {}. Known templates are {} ",
                        contextPath, proxyRule.getDestinationUriTemplates());
                return null;
            }
            String proxyPath = def.getUriTemplate();
            return new ProxyDetails(true, proxyPath, proxyRule);
        }
        return null;
    }

    //public static final String PROXY = "http4";
    //public static final String HTTP = "http";

    public static final String REQUEST_ID = "__requestId";
    private static final Random RAND = new Random();
    public static final String CONTEXT_PATH = "contextPath";
    public static final String CAMEL_HTTP_PATH = "CamelHttpPath";
    public static final String CAMEL_HTTP_URI = "CamelHttpUri";
    public static final String CAMEL_HTTP_URL = "CamelHttpUrl";
    public static final String REFERER = "Referer";
    public static final String TARGET_URL = "TARGET_URL";
    public static final String TARGET_CONTEXT = "TARGET_CONTEXT";
    public static final String COOKIE = "Cookie";
    public static final String UNDER_SCORE_C = "__c";
    public static final String FWD_SLASH = "/";
    private static final Logger LOG = LoggerFactory.getLogger(UrlExtractor.class);
}


text:
using System.Threading.Tasks;
using Nest;
using Tests.Framework;
using static Tests.Framework.UrlTester;

namespace Tests.Search.SearchTemplate.GetSearchTemplate
{
	public class GetSearchTemplateUrlTests
	{
		[U] public async Task Urls()
		{
			var id = "the-id";
			await GET("/_search/template/the-id")
				.Fluent(c => c.GetSearchTemplate(id))
				.Request(c=>c.GetSearchTemplate(new GetSearchTemplateRequest(id)))
				.FluentAsync(c => c.GetSearchTemplateAsync(id))
				.RequestAsync(c=>c.GetSearchTemplateAsync(new GetSearchTemplateRequest(id)))
				;
		}
	}
}


text:
/* global define */

define([
  'jquery'
], function($) {

    function sameOrigin(url) {
        var host = document.location.host,
            protocol = document.location.protocol,
            srOrigin = '//' + host,
            origin = protocol + srOrigin;

        return (url === origin || url.slice(0, origin.length + 1) === origin + '/') || (url === srOrigin || url.slice(0, srOrigin.length + 1) === srOrigin + '/') || !(/^(\/\/|http:|https:).*/.test(url));     // jshint ignore:line
    }

    function safeMethod(method) {
        return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method);
    }

    function apply(header, token) {
        $.ajaxPrefilter(function(settings, origSettings, xhr) {
            if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
                return xhr.setRequestHeader(header, token);
            }
        });
    }

    return {
        apply: apply
    };
});


text:
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager(
    cef_completion_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Unverified params: callback

  // Execute
  CefRefPtr<CefCookieManager> _retval = CefCookieManager::GetGlobalManager(
      CefCompletionCallbackCToCpp::Wrap(callback));

  // Return type: refptr_same
  return CefCookieManagerCppToC::Wrap(_retval);
}

CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
    const cef_string_t* path, int persist_session_cookies,
    cef_completion_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Unverified params: path, callback

  // Execute
  CefRefPtr<CefCookieManager> _retval = CefCookieManager::CreateManager(
      CefString(path),
      persist_session_cookies?true:false,
      CefCompletionCallbackCToCpp::Wrap(callback));

  // Return type: refptr_same
  return CefCookieManagerCppToC::Wrap(_retval);
}

namespace {

// MEMBER FUNCTIONS - Body may be edited by hand.

void CEF_CALLBACK cookie_manager_set_supported_schemes(
    struct _cef_cookie_manager_t* self, cef_string_list_t schemes,
    cef_completion_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return;
  // Verify param: schemes; type: string_vec_byref_const
  DCHECK(schemes);
  if (!schemes)
    return;
  // Unverified params: callback

  // Translate param: schemes; type: string_vec_byref_const
  std::vector<CefString> schemesList;
  transfer_string_list_contents(schemes, schemesList);

  // Execute
  CefCookieManagerCppToC::Get(self)->SetSupportedSchemes(
      schemesList,
      CefCompletionCallbackCToCpp::Wrap(callback));
}

int CEF_CALLBACK cookie_manager_visit_all_cookies(
    struct _cef_cookie_manager_t* self,
    struct _cef_cookie_visitor_t* visitor) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Verify param: visitor; type: refptr_diff
  DCHECK(visitor);
  if (!visitor)
    return 0;

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->VisitAllCookies(
      CefCookieVisitorCToCpp::Wrap(visitor));

  // Return type: bool
  return _retval;
}

int CEF_CALLBACK cookie_manager_visit_url_cookies(
    struct _cef_cookie_manager_t* self, const cef_string_t* url,
    int includeHttpOnly, struct _cef_cookie_visitor_t* visitor) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Verify param: url; type: string_byref_const
  DCHECK(url);
  if (!url)
    return 0;
  // Verify param: visitor; type: refptr_diff
  DCHECK(visitor);
  if (!visitor)
    return 0;

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->VisitUrlCookies(
      CefString(url),
      includeHttpOnly?true:false,
      CefCookieVisitorCToCpp::Wrap(visitor));

  // Return type: bool
  return _retval;
}

int CEF_CALLBACK cookie_manager_set_cookie(struct _cef_cookie_manager_t* self,
    const cef_string_t* url, const struct _cef_cookie_t* cookie,
    struct _cef_set_cookie_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Verify param: url; type: string_byref_const
  DCHECK(url);
  if (!url)
    return 0;
  // Verify param: cookie; type: struct_byref_const
  DCHECK(cookie);
  if (!cookie)
    return 0;
  // Unverified params: callback

  // Translate param: cookie; type: struct_byref_const
  CefCookie cookieObj;
  if (cookie)
    cookieObj.Set(*cookie, false);

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->SetCookie(
      CefString(url),
      cookieObj,
      CefSetCookieCallbackCToCpp::Wrap(callback));

  // Return type: bool
  return _retval;
}

int CEF_CALLBACK cookie_manager_delete_cookies(
    struct _cef_cookie_manager_t* self, const cef_string_t* url,
    const cef_string_t* cookie_name,
    struct _cef_delete_cookies_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Unverified params: url, cookie_name, callback

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->DeleteCookies(
      CefString(url),
      CefString(cookie_name),
      CefDeleteCookiesCallbackCToCpp::Wrap(callback));

  // Return type: bool
  return _retval;
}

int CEF_CALLBACK cookie_manager_set_storage_path(
    struct _cef_cookie_manager_t* self, const cef_string_t* path,
    int persist_session_cookies, cef_completion_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Unverified params: path, callback

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->SetStoragePath(
      CefString(path),
      persist_session_cookies?true:false,
      CefCompletionCallbackCToCpp::Wrap(callback));

  // Return type: bool
  return _retval;
}

int CEF_CALLBACK cookie_manager_flush_store(struct _cef_cookie_manager_t* self,
    cef_completion_callback_t* callback) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self)
    return 0;
  // Unverified params: callback

  // Execute
  bool _retval = CefCookieManagerCppToC::Get(self)->FlushStore(
      CefCompletionCallbackCToCpp::Wrap(callback));

  // Return type: bool
  return _retval;
}

}  // namespace

// CONSTRUCTOR - Do not edit by hand.

CefCookieManagerCppToC::CefCookieManagerCppToC() {
  GetStruct()->set_supported_schemes = cookie_manager_set_supported_schemes;
  GetStruct()->visit_all_cookies = cookie_manager_visit_all_cookies;
  GetStruct()->visit_url_cookies = cookie_manager_visit_url_cookies;
  GetStruct()->set_cookie = cookie_manager_set_cookie;
  GetStruct()->delete_cookies = cookie_manager_delete_cookies;
  GetStruct()->set_storage_path = cookie_manager_set_storage_path;
  GetStruct()->flush_store = cookie_manager_flush_store;
}

template<> CefRefPtr<CefCookieManager> CefCppToC<CefCookieManagerCppToC,
    CefCookieManager, cef_cookie_manager_t>::UnwrapDerived(CefWrapperType type,
    cef_cookie_manager_t* s) {
  NOTREACHED() << "Unexpected class type: " << type;
  return NULL;
}

#ifndef NDEBUG
template<> base::AtomicRefCount CefCppToC<CefCookieManagerCppToC,
    CefCookieManager, cef_cookie_manager_t>::DebugObjCt = 0;
#endif

template<> CefWrapperType CefCppToC<CefCookieManagerCppToC, CefCookieManager,
    cef_cookie_manager_t>::kWrapperType = WT_COOKIE_MANAGER;


text:
use crate::utils;

use clap::Parser;

#[test]
fn it_works() {
    #[derive(Debug, PartialEq, Parser)]
    #[command(rename_all_env = "kebab")]
    struct BehaviorModel {
        #[arg(env)]
        be_nice: String,
    }

    let help = utils::get_help::<BehaviorModel>();
    assert!(help.contains("[env: be-nice=]"));
}

#[test]
fn default_is_screaming() {
    #[derive(Debug, PartialEq, Parser)]
    struct BehaviorModel {
        #[arg(env)]
        be_nice: String,
    }

    let help = utils::get_help::<BehaviorModel>();
    assert!(help.contains("[env: BE_NICE=]"));
}

#[test]
fn overridable() {
    #[derive(Debug, PartialEq, Parser)]
    #[command(rename_all_env = "kebab")]
    struct BehaviorModel {
        #[arg(env)]
        be_nice: String,

        #[arg(rename_all_env = "pascal", env)]
        be_aggressive: String,
    }

    let help = utils::get_help::<BehaviorModel>();
    assert!(help.contains("[env: be-nice=]"));
    assert!(help.contains("[env: BeAggressive=]"));
}