问:
Route claim it is defined in system.web but it not found error
when i migrate from .netframework to .net core than I get this error in .netcore 3.1 i follow this link here   here but still not able to resolve this issue .

```<code> public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            // Web API configuration and services
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}"
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApiWithActionApi",
                routeTemplate: "api/{controller}/{action}"
            );

            // Configure formatting settings
            ConfigureFormatting(config);

            // Add Global Exception Handling and Logging
            config.Services.Replace(typeof(IExceptionHandler), GlobalExceptionHandler.GetInstance());
            config.Services.Replace(typeof(IExceptionLogger), new GlobalExceptionLogger());
        }
</code>```

Severity    Code    Description Project File    Line    Suppression State
Error   CS7069  Reference to type 'Route' claims it is defined in 'System.Web', but it could not be found   WorkerRole

is their alternet so on change it remove my error it work similar .

any suggestion is accepted.

答:
It looks like a config file in the .NET framework, To achieve this in .NET core 3.1 you should add your configuration in a startup.cs file for .net core.

e.g In configure method of startup.cs file

```<code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseRouting();
            // global cors policy
            app.UseCors(x => x
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader());
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
</code>```

Body:
when i migrate from .netframework to .net core than I get this error in .netcore 3.1 i follow this link here   here but still not able to resolve this issue .

 public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            // Web API configuration and services
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}"
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApiWithActionApi",
                routeTemplate: "api/{controller}/{action}"
            );

            // Configure formatting settings
            ConfigureFormatting(config);

            // Add Global Exception Handling and Logging
            config.Services.Replace(typeof(IExceptionHandler), GlobalExceptionHandler.GetInstance());
            config.Services.Replace(typeof(IExceptionLogger), new GlobalExceptionLogger());
        }

Severity    Code    Description Project File    Line    Suppression State
Error   CS7069  Reference to type 'Route' claims it is defined in 'System.Web', but it could not be found   WorkerRole

is their alternet so on change it remove my error it work similar .

any suggestion is accepted.

Body:
It looks like a config file in the .NET framework, To achieve this in .NET core 3.1 you should add your configuration in a startup.cs file for .net core.

e.g In configure method of startup.cs file

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseRouting();
            // global cors policy
            app.UseCors(x => x
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader());
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }


来源: stackexchange

问:
creating alert in a pine script strategy
I want to convert a TradingView pine script "Price Channel Strategy" to create an alert when a buy, sell or tsl signal is triggered. Can someone please help?

The code is as given below:

```<code>//@version=4
strategy("Price Channel Strategy", overlay=true)
length = input(20)
hh = highest(high, length)
ll = lowest(low, length)
if (not na(close[length]))
    strategy.entry("PChLE", strategy.long, comment="PChLE", stop=hh)
    strategy.entry("PChSE", strategy.short, comment="PChSE", stop=ll)
strategy.exit("long tsl","PChLE", trail_points = 5000, trail_offset=2000)
strategy.exit("short tsl","PChSE", trail_points = 5000, trail_offset=2000)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
</code>```

答:
I don't believe alertcondition for custom alerts can be used in strategy scripts.
You may have to convert your strategy to a study to create custom alerts.

ContentLicense: CC BY-SA 4.0

Body:
I want to convert a TradingView pine script "Price Channel Strategy" to create an alert when a buy, sell or tsl signal is triggered. Can someone please help?

The code is as given below:

//@version=4
strategy("Price Channel Strategy", overlay=true)
length = input(20)
hh = highest(high, length)
ll = lowest(low, length)
if (not na(close[length]))
    strategy.entry("PChLE", strategy.long, comment="PChLE", stop=hh)
    strategy.entry("PChSE", strategy.short, comment="PChSE", stop=ll)
strategy.exit("long tsl","PChLE", trail_points = 5000, trail_offset=2000)
strategy.exit("short tsl","PChSE", trail_points = 5000, trail_offset=2000)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)


问:
PHP setcookie "SameSite=Strict"?
I recently read "RFC 6265" on the attribute "Same Site", I looked at some articles that talked about that in April 2016, "same-site" attribute has been implemented for Chrome 51 and Opera 39 ...

I wonder if current PHP supports creating cookies with this attribute?

Reference:

Feature documentation on Chrome’s chromestatus.com

HTTPbis draft first adopted by Chrome

Latest HTTPbis draft

答:
There are a lot of examples showing how to set this attribute, but not many explanations of why.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#SameSite_attribute

If a cookie is needed to be sent cross-origin, opt out of the SameSite restriction by using the None directive. The None directive requires that the Secure attribute also be used.

The examples that are setting SameSite to None or Lax are only appropriate for cross-domain scenarios. If your code isn't cross-domain, use Strict.

ContentLicense: CC BY-SA 3.0

Title: PHP setcookie "SameSite=Strict"?


问:
Segmentation Fault: CS50 recover.c
This program accepts a filename as input and should recover all jpegs on that file. It reads 512 bytes at a time, checking for the start of a new jpeg.

The program compiles when I run it, but it gives a segmentation fault. Please advise me how I can go about fixing this.

```<code>#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    // check for proper usage
    if (argc != 2)
    {
        printf("Usage: 1 command line argument\n");
        return 1;
    }

    // check if file can be opened
    FILE *file = fopen(argv[1], "r");
    if (file == NULL)
    {
        printf("Cannot be opened\n");
        return 2;
    }

    // read 512 bytes into buffer until end of card
    int buffer[128];
    int counter;
    counter = 0;
    char filename[8];
    FILE *img = NULL;

    while(fread(buffer, 4, 128, file) == 128)
    {
        //check if start of new JPEG
        if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        {
            //check if first JPEG
            if (counter == 0)
            {
                sprintf(filename, "%03i.jpg", counter);
                img = fopen(filename, "w");
                fwrite(buffer, 4, 128, img);
                counter += 1;
            }
            else if (counter > 0)
            {
                fclose(img);
                sprintf(filename, "%03i.jpg", counter);
                img = fopen(filename, "w");
                fwrite(buffer, 4, 128, img);
                counter += 1;
            }
        }
        else if (counter > 0)
        {
            fwrite(buffer, 4, 128, img);
        }
    }
    fclose(img);
    fclose(file);
    return 0;
}
</code>```

答:
The call fread(buffer, 4, 128, file) reads (as you rightly say) 512 bytes into the array of 128 integers. However, when you then test for the start of a new JPEG file in this code:

if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
    //...
```

<p>you are inspecting the <em>low bytes of each of the first four integers</em> in the array, rather than (as you should be) checking the first <strong>four bytes</strong> of the array. These four bytes will all be in the <strong>first</strong> integer element (<code>buffer[0]</code>).</p>

<p>Thus, your program will never find the start of a new JPEG and, consequently, the <code>img</code> file will never be opened ... and you are then calling <code>fclose</code> with a <code>NULL</code> file pointer, which is undefined behaviour and likely to cause the segmentation fault you see.</p>

<p>Instead (assuming the correct 'endianness'), do the following check:</p>

<pre class="lang-c prettyprint-override"><code>if ((buffer[0] & 0xfffffff0) == 0xffd8ffe0)
{
    //...
</code>```

To allow for the 'wrong endianness', you could check for either byte order in buffer[0]:

if ((buffer[0] & 0xfffffff0) == 0xffd8ffe0 || (buffer[0] & 0xf0ffffff) == 0xe0ffd8ff)
{
    //...
```

<p>Better still, just read (and write) the buffer for what it is - an array of 512 bytes, with code like this:</p>

<pre class="lang-c prettyprint-override"><code>unsigned char buffer[512];
//...
while(fread(buffer, 1, 512, file) == 512)
{
    //...
</code>```

This way, you can keep your 'JPEG start' test as it is.

Title: Segmentation Fault: CS50 recover.c

Body:
This program accepts a filename as input and should recover all jpegs on that file. It reads 512 bytes at a time, checking for the start of a new jpeg.

The program compiles when I run it, but it gives a segmentation fault. Please advise me how I can go about fixing this.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    // check for proper usage
    if (argc != 2)
    {
        printf("Usage: 1 command line argument\n");
        return 1;
    }

    // check if file can be opened
    FILE *file = fopen(argv[1], "r");
    if (file == NULL)
    {
        printf("Cannot be opened\n");
        return 2;
    }

    // read 512 bytes into buffer until end of card
    int buffer[128];
    int counter;
    counter = 0;
    char filename[8];
    FILE *img = NULL;

    while(fread(buffer, 4, 128, file) == 128)
    {
        //check if start of new JPEG
        if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        {
            //check if first JPEG
            if (counter == 0)
            {
                sprintf(filename, "%03i.jpg", counter);
                img = fopen(filename, "w");
                fwrite(buffer, 4, 128, img);
                counter += 1;
            }
            else if (counter > 0)
            {
                fclose(img);
                sprintf(filename, "%03i.jpg", counter);
                img = fopen(filename, "w");
                fwrite(buffer, 4, 128, img);
                counter += 1;
            }
        }
        else if (counter > 0)
        {
            fwrite(buffer, 4, 128, img);
        }
    }
    fclose(img);
    fclose(file);
    return 0;
}

Body:
The call fread(buffer, 4, 128, file) reads (as you rightly say) 512 bytes into the array of 128 integers. However, when you then test for the start of a new JPEG file in this code:

if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
    //...

you are inspecting the low bytes of each of the first four integers in the array, rather than (as you should be) checking the first four bytes of the array. These four bytes will all be in the first integer element (buffer[0]).

Thus, your program will never find the start of a new JPEG and, consequently, the img file will never be opened ... and you are then calling fclose with a NULL file pointer, which is undefined behaviour and likely to cause the segmentation fault you see.

Instead (assuming the correct 'endianness'), do the following check:

if ((buffer[0] & 0xfffffff0) == 0xffd8ffe0)
{
    //...

To allow for the 'wrong endianness', you could check for either byte order in buffer[0]:

if ((buffer[0] & 0xfffffff0) == 0xffd8ffe0 || (buffer[0] & 0xf0ffffff) == 0xe0ffd8ff)
{
    //...

Better still, just read (and write) the buffer for what it is - an array of 512 bytes, with code like this:

unsigned char buffer[512];
//...
while(fread(buffer, 1, 512, file) == 512)
{
    //...

This way, you can keep your 'JPEG start' test as it is.


问:
onclick on option tag not working on IE and chrome
I am using onclick event in option tag for select box

```<code><select>
    <option onclick="check()">one</option>
    <option onclick="check()">two</option>
    <option onclick="check()">three</option>
</select>`
</code>```

onclick event is not working on IE and Chrome but it is working fine in firefox,
here I don't want to use onchange event on select tag bcz it will not trigger an event if user selects same option again

Eg:say first time user selects "one" dropdown I will open a popup after processing some stuff  user closes the popup,suppose if user wants to select same "one" dropdown it will not trigger  any event.this can be solved using onclick event on option tag but its not working on IE and chrome

Is there any work around for this ?

答:
This works on different browsers CHROME, FIREFOX, IE, AVAST BROWSER, BRAVE, Etc... And user can change the option as many times as possible with the event still occurring over and over again.</p>

```<code>HTML:
<select id="howtopay">
    <option selected>Select</option>
    <option value="1">ATM - PAYSTACK (Instant Funding)</option>
    <option value="2">BANK DEPOSIT/TRANSFER</option>
</select>

JQUERY:
$(function(){
    $('#howtopay').change(function() {
        if ($(this).val() == "1") {
        $('#fund_with_atm').show();
        $('#fund_with_bank').hide();
      }
        else if ($(this).val() == "2") {
        //Do Nothing
      }
      else {
        //Do Nothing
      }
    });
});
</code>```

Body:
I am using onclick event in option tag for select box

<select>
    <option onclick="check()">one</option>
    <option onclick="check()">two</option>
    <option onclick="check()">three</option>
</select>`

onclick event is not working on IE and Chrome but it is working fine in firefox,
here I don't want to use onchange event on select tag bcz it will not trigger an event if user selects same option again

Eg:say first time user selects "one" dropdown I will open a popup after processing some stuff  user closes the popup,suppose if user wants to select same "one" dropdown it will not trigger  any event.this can be solved using onclick event on option tag but its not working on IE and chrome

Is there any work around for this ?

Body:
This works on different browsers CHROME, FIREFOX, IE, AVAST BROWSER, BRAVE, Etc... And user can change the option as many times as possible with the event still occurring over and over again.

HTML:
<select id="howtopay">
    <option selected>Select</option>
    <option value="1">ATM - PAYSTACK (Instant Funding)</option>
    <option value="2">BANK DEPOSIT/TRANSFER</option>
</select>

JQUERY:
$(function(){
    $('#howtopay').change(function() {
        if ($(this).val() == "1") {
        $('#fund_with_atm').show();
        $('#fund_with_bank').hide();
      }
        else if ($(this).val() == "2") {
        //Do Nothing
      }
      else {
        //Do Nothing
      }
    });
});


问:
Computer try to guess user number in C
I made a programme to guess user number.
I miss something in my code, but i dont know what.
If i give input b (bigger) or s (lower), its still give me the same result.
Can you tell me please what should i add to Code to work correctly?</p>

```<code>#include <stdio.h>
#include <ctype.h>

int main(void)
{
  char answer, input;
  int untere_grenze=1, upper_limit=999, tipp=0, try1=0;

  printf("\n\nThis program tries to guess a number you choose between 1 and 999\n\n");
  do
  {
    try1=0;
    do
    {
      //I think here is my problem

      try1+=1;
      tipp=untere_grenze+(upper_limit-untere_grenze)/2;

      printf("\n%d. try: %d\n", try1, tipp);

      upper_limit=tipp-1;
      untere_grenze=tipp+1;

      //I think here is my problem

      do
      {
        printf("Please enter s (number to be guessed is smaller), b (number to be guessed is larger) or = (guess!):");
        scanf(" %c", &input);
        input=toupper(input);
      } while (input!='S' && input!='B' && input!='=');

    } while(input!='=');

    printf("\n\nThe computer guessed your number in %d attempts.\n\n", try1);
    do
    {
      printf("Do you want to run the program again (J/N)?\n\n");
      scanf(" %c", &answer);
      answer=toupper(answer);
    } while (answer!='J' && answer!='N');
  }  while (answer=='J');

  return 0;
}
</code>```

答:
Your code logic is horrible, recommend to rewrite, you can reference mine.</p>

```<code>#include <stdio.h>
#include <ctype.h>

#define LOWER_BOUND     1
#define UPPER_BOUND     999

int main (void)
{
    int low = LOWER_BOUND, up = UPPER_BOUND, guess, try = 0;
    char input;

    printf("Program will guess a number between 1 and 999,"
        "please input s(smaller), b(bigger), or =(equal)\n");

    while (1)
    {
        if (low <= up)
            guess = low + (up - low) / 2;
        else {
            printf("Program terminate, no more guess value\n");
            break;
        }
        ++try;
retry:
        printf("guess %d, please input (s/b/=)\n", guess);
        scanf(" %c", &input);

        if ((input = tolower(input)) == 's') {
            up = guess - 1;
        } else if (input == 'b')
            low = guess + 1;
        else if (input == '=')
            break;
        else
            goto retry;
    }

    printf("Summary: Trial: %d\n", try);
    return 0;
}
</code>```

Title: Computer try to guess user number in C

Body:
I made a programme to guess user number.
I miss something in my code, but i dont know what.
If i give input b (bigger) or s (lower), its still give me the same result.
Can you tell me please what should i add to Code to work correctly?

#include <stdio.h>
#include <ctype.h>

int main(void)
{
  char answer, input;
  int untere_grenze=1, upper_limit=999, tipp=0, try1=0;

  printf("\n\nThis program tries to guess a number you choose between 1 and 999\n\n");
  do
  {
    try1=0;
    do
    {
      //I think here is my problem

      try1+=1;
      tipp=untere_grenze+(upper_limit-untere_grenze)/2;

      printf("\n%d. try: %d\n", try1, tipp);

      upper_limit=tipp-1;
      untere_grenze=tipp+1;

      //I think here is my problem

      do
      {
        printf("Please enter s (number to be guessed is smaller), b (number to be guessed is larger) or = (guess!):");
        scanf(" %c", &input);
        input=toupper(input);
      } while (input!='S' && input!='B' && input!='=');

    } while(input!='=');

    printf("\n\nThe computer guessed your number in %d attempts.\n\n", try1);
    do
    {
      printf("Do you want to run the program again (J/N)?\n\n");
      scanf(" %c", &answer);
      answer=toupper(answer);
    } while (answer!='J' && answer!='N');
  }  while (answer=='J');

  return 0;
}

Body:
Your code logic is horrible, recommend to rewrite, you can reference mine.

#include <stdio.h>
#include <ctype.h>

#define LOWER_BOUND     1
#define UPPER_BOUND     999

int main (void)
{
    int low = LOWER_BOUND, up = UPPER_BOUND, guess, try = 0;
    char input;

    printf("Program will guess a number between 1 and 999,"
        "please input s(smaller), b(bigger), or =(equal)\n");

    while (1)
    {
        if (low <= up)
            guess = low + (up - low) / 2;
        else {
            printf("Program terminate, no more guess value\n");
            break;
        }
        ++try;
retry:
        printf("guess %d, please input (s/b/=)\n", guess);
        scanf(" %c", &input);

        if ((input = tolower(input)) == 's') {
            up = guess - 1;
        } else if (input == 'b')
            low = guess + 1;
        else if (input == '=')
            break;
        else
            goto retry;
    }

    printf("Summary: Trial: %d\n", try);
    return 0;
}


问:
ContextMenu in Word
Creating a manifest for a Word Add-in. I am trying to put TWO menu items on the ContextMenuText. I am following the guidance here: https://learn.microsoft.com/en-us/office/dev/add-ins/reference/manifest/control#menu-dropdown-button-controls. Here is where I get this understanding:

When used with a PrimaryCommandSurface or ContextMenu extension point, the menu control defines:

A root-level menu item.

A list of submenu items.

Everything I read says this is possible, and when I run NPM VALIDATE, it tells me that my manifest is valid. However, when I try to sideload with NPM START, the taskpane appears with the yellow warning that the manifest was not loaded. Also when I try to sideload in Word Online it tells me that my manifest is invalid.

If I define only a single top level CONTROL as a BUTTON it works fine. But I really need two items on the context menu.

Here is the relevant part of my manifest:

<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
  <Control xsi:type="Menu" id="myMenuId">

    <Supertip>
        <Title resid="ContextMenu.Label" />
        <Description resid="ContextMenu.ToolTip" />
    </Supertip>
    <Icon>
      <bt:Image size="16" resid="Icon.16x16" />
      <bt:Image size="32" resid="Icon.32x32" />
      <bt:Image size="80" resid="Icon.80x80" />
    </Icon>
    <Items>

      <Item id="firstCtxMenuId">

        <Supertip>
          <Title resid="FirstButton.Label"/>
          <Description resid="FirstButton.Tooltip"/>
        </Supertip>
        <Icon>
          <bt:Image size="16" resid="Icon.16x16"/>
          <bt:Image size="32" resid="Icon.32x32"/>
          <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <Action xsi:type="ExecuteFunction">
          <FunctionName>doThing1</FunctionName>
        </Action>
      </Item>

      <Item id="secondCtxMenuId"> -->

        <Supertip>
          <Title resid="SecondButton.Label"/>
          <Description resid="SecondButton.Tooltip"/>
        </Supertip>
        <Icon>
          <bt:Image size="16" resid="Icon.16x16"/>
          <bt:Image size="32" resid="Icon.32x32"/>
          <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <Action xsi:type="ExecuteFunction">
          <FunctionName>doThing2</FunctionName>
        </Action>
      </Item>
    </Items>
  </Control>
</OfficeMenu>
```

Is there something wrong with my manifest that I am just not seeing? Or does Word NOT support multiple items on the context menu?

答:
I assume you have not added the relevant resources at the bottom of the manifest file because I don't see them in your code sample. Try reading this part of the docs more thoroughly, and see if that helps.

Here is a sample manifest I used which accomplishes what I believe you are trying to accomplish:

```<code><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
  <Id>18d46177-646b-4767-a5b8-efe907a59a95</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Patent Theory"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Document"/>
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Document">
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title"/>
            <Description resid="GetStarted.Description"/>
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <FunctionFile resid="Commands.Url"/>
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <OfficeTab id="TabHome">
              <Group id="CommandsGroup">
                <Label resid="CommandsGroup.Label"/>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16"/>
                  <bt:Image size="32" resid="Icon.32x32"/>
                  <bt:Image size="80" resid="Icon.80x80"/>
                </Icon>
                <Control xsi:type="Button" id="TaskpaneButton">
                  <Label resid="TaskpaneButton.Label"/>
                  <Supertip>
                    <Title resid="TaskpaneButton.Label"/>
                    <Description resid="TaskpaneButton.Tooltip"/>
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16"/>
                    <bt:Image size="32" resid="Icon.32x32"/>
                    <bt:Image size="80" resid="Icon.80x80"/>
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Taskpane.Url"/>
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
          <!-- Datajoy New Extension Point -->
          <ExtensionPoint xsi:type="ContextMenu">
            <OfficeMenu id="ContextMenuText">
              <Control xsi:type="Menu" id="MarkAsProfanity.Menu">
                <Label resid="MarkAsProfanity.Label" />
                <Supertip>
                  <Title resid="MarkAsProfanity.Label" />
                  <Description resid="MarkAsProfanity.Description" />
                </Supertip>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16" />
                  <bt:Image size="32" resid="Icon.32x32" />
                  <bt:Image size="80" resid="Icon.80x80" />
                </Icon>
                <Items>
                  <Item id="IgnoreProfanity.Button">
                    <Label resid="IgnoreProfanity.Label"/>
                    <Supertip>
                      <Title resid="IgnoreProfanity.Label" />
                      <Description resid="IgnoreProfanity.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>ignoreProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="ClaimsAndSpec.Button">
                    <Label resid="ClaimsAndSpec.Label"/>
                    <Supertip>
                      <Title resid="ClaimsAndSpec.Label" />
                      <Description resid="ClaimsAndSpec.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsClaimsAndSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Claims.Button">
                    <Label resid="Claims.Label"/>
                    <Supertip>
                      <Title resid="Claims.Label" />
                      <Description resid="Claims.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsClaimsProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Spec.Button">
                    <Label resid="Spec.Label"/>
                    <Supertip>
                      <Title resid="Spec.Label" />
                      <Description resid="Spec.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                </Items>
              </Control>
            </OfficeMenu>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
        <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
        <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
      </bt:Images>
      <bt:Urls>
        <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
        <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
        <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/>
        <bt:String id="CommandsGroup.Label" DefaultValue="Commands Group"/>
        <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
        <bt:String id="MarkAsProfanity.Label" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Label" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Label" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Label" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Label" DefaultValue="Ignore profanity"/>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started."/>
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/>
        <bt:String id="MarkAsProfanity.Description" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Description" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Description" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Description" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Description" DefaultValue="Ignore profanity"/>
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>
</code>```

Title: ContextMenu in Word

Body:
Creating a manifest for a Word Add-in. I am trying to put TWO menu items on the ContextMenuText. I am following the guidance here: https://learn.microsoft.com/en-us/office/dev/add-ins/reference/manifest/control#menu-dropdown-button-controls. Here is where I get this understanding:

When used with a PrimaryCommandSurface or ContextMenu extension point, the menu control defines:

A root-level menu item.

A list of submenu items.

Everything I read says this is possible, and when I run NPM VALIDATE, it tells me that my manifest is valid. However, when I try to sideload with NPM START, the taskpane appears with the yellow warning that the manifest was not loaded. Also when I try to sideload in Word Online it tells me that my manifest is invalid.

If I define only a single top level CONTROL as a BUTTON it works fine. But I really need two items on the context menu.

Here is the relevant part of my manifest:

<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
  <Control xsi:type="Menu" id="myMenuId">

    <Supertip>
        <Title resid="ContextMenu.Label" />
        <Description resid="ContextMenu.ToolTip" />
    </Supertip>
    <Icon>
      <bt:Image size="16" resid="Icon.16x16" />
      <bt:Image size="32" resid="Icon.32x32" />
      <bt:Image size="80" resid="Icon.80x80" />
    </Icon>
    <Items>

      <Item id="firstCtxMenuId">

        <Supertip>
          <Title resid="FirstButton.Label"/>
          <Description resid="FirstButton.Tooltip"/>
        </Supertip>
        <Icon>
          <bt:Image size="16" resid="Icon.16x16"/>
          <bt:Image size="32" resid="Icon.32x32"/>
          <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <Action xsi:type="ExecuteFunction">
          <FunctionName>doThing1</FunctionName>
        </Action>
      </Item>

      <Item id="secondCtxMenuId"> -->

        <Supertip>
          <Title resid="SecondButton.Label"/>
          <Description resid="SecondButton.Tooltip"/>
        </Supertip>
        <Icon>
          <bt:Image size="16" resid="Icon.16x16"/>
          <bt:Image size="32" resid="Icon.32x32"/>
          <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <Action xsi:type="ExecuteFunction">
          <FunctionName>doThing2</FunctionName>
        </Action>
      </Item>
    </Items>
  </Control>
</OfficeMenu>

Is there something wrong with my manifest that I am just not seeing? Or does Word NOT support multiple items on the context menu?

Body:
I assume you have not added the relevant resources at the bottom of the manifest file because I don't see them in your code sample. Try reading this part of the docs more thoroughly, and see if that helps.

Here is a sample manifest I used which accomplishes what I believe you are trying to accomplish:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
  <Id>18d46177-646b-4767-a5b8-efe907a59a95</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Patent Theory"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Document"/>
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Document">
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title"/>
            <Description resid="GetStarted.Description"/>
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <FunctionFile resid="Commands.Url"/>
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <OfficeTab id="TabHome">
              <Group id="CommandsGroup">
                <Label resid="CommandsGroup.Label"/>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16"/>
                  <bt:Image size="32" resid="Icon.32x32"/>
                  <bt:Image size="80" resid="Icon.80x80"/>
                </Icon>
                <Control xsi:type="Button" id="TaskpaneButton">
                  <Label resid="TaskpaneButton.Label"/>
                  <Supertip>
                    <Title resid="TaskpaneButton.Label"/>
                    <Description resid="TaskpaneButton.Tooltip"/>
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16"/>
                    <bt:Image size="32" resid="Icon.32x32"/>
                    <bt:Image size="80" resid="Icon.80x80"/>
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Taskpane.Url"/>
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
          <!-- Datajoy New Extension Point -->
          <ExtensionPoint xsi:type="ContextMenu">
            <OfficeMenu id="ContextMenuText">
              <Control xsi:type="Menu" id="MarkAsProfanity.Menu">
                <Label resid="MarkAsProfanity.Label" />
                <Supertip>
                  <Title resid="MarkAsProfanity.Label" />
                  <Description resid="MarkAsProfanity.Description" />
                </Supertip>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16" />
                  <bt:Image size="32" resid="Icon.32x32" />
                  <bt:Image size="80" resid="Icon.80x80" />
                </Icon>
                <Items>
                  <Item id="IgnoreProfanity.Button">
                    <Label resid="IgnoreProfanity.Label"/>
                    <Supertip>
                      <Title resid="IgnoreProfanity.Label" />
                      <Description resid="IgnoreProfanity.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>ignoreProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="ClaimsAndSpec.Button">
                    <Label resid="ClaimsAndSpec.Label"/>
                    <Supertip>
                      <Title resid="ClaimsAndSpec.Label" />
                      <Description resid="ClaimsAndSpec.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsClaimsAndSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Claims.Button">
                    <Label resid="Claims.Label"/>
                    <Supertip>
                      <Title resid="Claims.Label" />
                      <Description resid="Claims.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsClaimsProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Spec.Button">
                    <Label resid="Spec.Label"/>
                    <Supertip>
                      <Title resid="Spec.Label" />
                      <Description resid="Spec.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>markAsSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                </Items>
              </Control>
            </OfficeMenu>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
        <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
        <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
      </bt:Images>
      <bt:Urls>
        <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
        <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
        <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/>
        <bt:String id="CommandsGroup.Label" DefaultValue="Commands Group"/>
        <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
        <bt:String id="MarkAsProfanity.Label" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Label" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Label" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Label" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Label" DefaultValue="Ignore profanity"/>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started."/>
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/>
        <bt:String id="MarkAsProfanity.Description" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Description" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Description" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Description" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Description" DefaultValue="Ignore profanity"/>
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>


问:
Trying to add freetype to php-gd in Docker official image
I'm trying to add some features to PHP GD installation. I'm using Docker PHP "Official" release as base (php:7.1.15-fpm-jessie).

My current production environment uses CentOS, which GD module comes with FreeType, JPEG and PNG support, as you can see in the phpinfo output:

```<code>GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.5.13
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
</code>```

But this Docker image comes without FreeType and JPEG support and with a much older version of GD (see phpinfo bellow):

```<code>GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XBM Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
</code>```

Do I need to recompile PHP or just the extension? The image uses Debian Jessie.

EDITION (SOLUTION):

After recompiling I found the best solution in this post:

solved! Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"

So I simply added:

```<code>RUN apt-get update && apt-get install libgd3 libgd-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
</code>```

After that my phpinfo start to show:

```<code>GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.2.50
</code>```

答:
for me with php7.3, remove --enable-gd-native-ttf if works for me</p>

```<code>RUN apt-get update && apt-get install -y libpng-dev
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir

RUN docker-php-ext-install gd
</code>```

Body:
I'm trying to add some features to PHP GD installation. I'm using Docker PHP "Official" release as base (php:7.1.15-fpm-jessie).

My current production environment uses CentOS, which GD module comes with FreeType, JPEG and PNG support, as you can see in the phpinfo output:

GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.5.13
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

But this Docker image comes without FreeType and JPEG support and with a much older version of GD (see phpinfo bellow):

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XBM Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

Do I need to recompile PHP or just the extension? The image uses Debian Jessie.

EDITION (SOLUTION):

After recompiling I found the best solution in this post:

solved! Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"

So I simply added:

RUN apt-get update && apt-get install libgd3 libgd-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd

After that my phpinfo start to show:

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.2.50

Body:
for me with php7.3, remove --enable-gd-native-ttf if works for me

RUN apt-get update && apt-get install -y libpng-dev
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir

RUN docker-php-ext-install gd


问:
How do I plot a a grouping of 3 variables?
I would like to plot the monthly quantity sold per client over a year. After a groupby of three variables df.groupby(['Year', 'Week', 'Client'])[Quantity].sum(), I am left with a column like this:

```<code>                       Quantity
Year    Week    Client
2012     1       Coke      200
                 Pepsi     100
                 7UP       400
         2       Coke      500
                 Pepsi     750
                 7UP       200
         3       Coke      120
                 Pepsi     100
                 7UP       050
... ... ... ...
2020    22       Coke      100
             Mountain Dew  650
                Fanta      110
        23       7UP       100
                 Pepsi     199
                 Coke      200
... ... ... ...

</code>```

I want to only show weekly quantities for all Clients in the last 10 weeks of 2020 (i.e. week 15-week 25) out of this entire dataframe.

How would I go on about selecting this data and then plotting a bar plot?

答:
You can do:

```<code>df_groups = df.groupby(['Year', 'Week', 'Client'])['Quantity'].sum()

# slicing the selected weeks
df_plot = df_groups.loc[2020].loc[15:25]

df_plot.unstack('Client').plot.bar()
</code>```

Output:

Body:
I would like to plot the monthly quantity sold per client over a year. After a groupby of three variables df.groupby(['Year', 'Week', 'Client'])[Quantity].sum(), I am left with a column like this:

                       Quantity
Year    Week    Client
2012     1       Coke      200
                 Pepsi     100
                 7UP       400
         2       Coke      500
                 Pepsi     750
                 7UP       200
         3       Coke      120
                 Pepsi     100
                 7UP       050
... ... ... ...
2020    22       Coke      100
             Mountain Dew  650
                Fanta      110
        23       7UP       100
                 Pepsi     199
                 Coke      200
... ... ... ...

I want to only show weekly quantities for all Clients in the last 10 weeks of 2020 (i.e. week 15-week 25) out of this entire dataframe.

How would I go on about selecting this data and then plotting a bar plot?

Body:
You can do:

df_groups = df.groupby(['Year', 'Week', 'Client'])['Quantity'].sum()

# slicing the selected weeks
df_plot = df_groups.loc[2020].loc[15:25]

df_plot.unstack('Client').plot.bar()

Output:


问:
Auto-HTML tags completion in C#
i've been trying to implement a Auto-HTML tags feature in a Winforms Richtextbox. I'm a beginner in C# and i needed a reference so i've come across this article on CodeProject. With this given code:

```<code>    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace AutoCompleteHTMLTags_CSharp
    {
        public partial class Simple_Form : Form
        {
            public Simple_Form()
            {
                InitializeComponent();
            }

            public static String EnteredString = "";
            public static Boolean Is_LessThanKeyPressed = false;
            public static Boolean Is_GreaterThanKeyPressed = false;
            public static Boolean Is_AutoCompleteCharacterPressed = false;
            public Boolean Is_SpaceBarKeyPressed = false;
            public Boolean Is_TagClosedKeyPressed = false;

            public String[] tagslist ={
            "html",
            "head",
            "title",
            "body",
            "h1",
            "h2",
            "h3",
            "h4",
            "h5",
            "h6",
            "b",
            "u",
            "i",
            "sub",
            "sup",
            "center",
            "strike",
            "font",
            "p",
            "style",
            "pre",
            "marquee",
            "ul",
            "ol",
            "a",
            "img",
            "table",
            "tr",
            "th",
            "td",
            "frameset",
            "iframe",
            "form",
            "input",
            "button",
            "textarea",
            "select",
            "div",
            "fieldset",
            "span",
            "strong",
            "em",
            "big",
            "small"
            };

            public void ProcessAutoCompleteBrackets(String s)
            {
                int sel = richTextBox1.SelectionStart;
                switch (s)
                {
                    case "(":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, ")");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;

                    case "[":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "]");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;

                    case "\"":
                        Is_AutoCompleteCharacterPressed = true;
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "\"");
                        richTextBox1.SelectionStart = sel;
                        break;

                    case "'":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "'");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;
                }
            }

            private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                String ch = e.KeyChar.ToString();

                this.ProcessAutoCompleteBrackets(ch);

                if (ch == "<")
                {
                    Is_LessThanKeyPressed = true;
                    Is_SpaceBarKeyPressed = false;
                    EnteredString = "";
                }
                else if (ch == ">")
                {
                    if (!Is_TagClosedKeyPressed)
                    {
                        Is_GreaterThanKeyPressed = true;
                        Is_SpaceBarKeyPressed = false;

                        int oldsel = richTextBox1.SelectionStart;

                        for (int i = 0; i < tagslist.Length; i++)
                        {
                            if (EnteredString == tagslist[i])
                            {
                                richTextBox1.Text = richTextBox1.Text.Insert(oldsel, "</" + tagslist[i] + ">");
                                richTextBox1.SelectionStart = richTextBox1.SelectionStart + oldsel;
                                EnteredString = "";
                            }
                        }

                        Is_LessThanKeyPressed = false;
                    }
                    else
                    {
                        Is_TagClosedKeyPressed = false;
                    }
                }

                else
                {
                    if (Is_LessThanKeyPressed)
                    {
                        for (char a = 'a'; a <= 'z'; a++)
                        {
                            if (a.ToString() == ch)
                            {
                                EnteredString += ch;
                            }
                            else if (a.ToString().ToUpper() == ch)
                            {
                                EnteredString += ch;
                            }
                        }
                        for (int a = 0; a <= 9; a++)
                        {
                            if (a.ToString() == ch)
                            {
                                EnteredString += ch;
                            }
                        }
                    }
                }

                // if user itself closes the tag
                if (Is_LessThanKeyPressed)
                {
                    if (ch == "/")
                    {
                        Is_TagClosedKeyPressed = true;
                        Is_SpaceBarKeyPressed = true;
                        EnteredString = "";
                    }
                }
            }

            private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
            {
                switch (e.KeyCode)
                {
                    case Keys.Space:
                        Is_SpaceBarKeyPressed = true;

                        if (Is_GreaterThanKeyPressed)
                        {
                            Is_GreaterThanKeyPressed = false;
                        }
                        Is_LessThanKeyPressed = false;

                        for (int i = 0; i < tagslist.Length; i++)
                        {
                            if(EnteredString==tagslist[i])
                            {
                                EnteredString = tagslist[i];
                            }
                        }
                        break;

                    case Keys.Up:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Down:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Left:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Right:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Enter: EnteredString = "";
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Back:
                        int sel = richTextBox1.SelectionStart;
                        Point pt = richTextBox1.GetPositionFromCharIndex(sel);
                        char ch = richTextBox1.GetCharFromPosition(pt);
                        if (EnteredString.Length > 0)
                        {
                            if (ch != '>')
                            {
                                EnteredString = EnteredString.Remove(EnteredString.Length - 1);
                                Is_LessThanKeyPressed = true;
                            }
                        }
                        if (ch == '<')
                        {
                            EnteredString = "";
                        }
                        break;
                }
            }
        }
    }
</code>```

Problem:

The implementation works fine, the only problem is when you type  (or any other keyword), the completion becomes , but it scrolls down to the end of the TextBox:

Anyone knows how to fix this?

答: In the ScrollToCaret() method, the RichTextBox will scroll the contents of the control to the current caret position.

Title: Auto-HTML tags completion in C#

Body:
i've been trying to implement a Auto-HTML tags feature in a Winforms Richtextbox. I'm a beginner in C# and i needed a reference so i've come across this article on CodeProject. With this given code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace AutoCompleteHTMLTags_CSharp
    {
        public partial class Simple_Form : Form
        {
            public Simple_Form()
            {
                InitializeComponent();
            }

            public static String EnteredString = "";
            public static Boolean Is_LessThanKeyPressed = false;
            public static Boolean Is_GreaterThanKeyPressed = false;
            public static Boolean Is_AutoCompleteCharacterPressed = false;
            public Boolean Is_SpaceBarKeyPressed = false;
            public Boolean Is_TagClosedKeyPressed = false;

            public String[] tagslist ={
            "html",
            "head",
            "title",
            "body",
            "h1",
            "h2",
            "h3",
            "h4",
            "h5",
            "h6",
            "b",
            "u",
            "i",
            "sub",
            "sup",
            "center",
            "strike",
            "font",
            "p",
            "style",
            "pre",
            "marquee",
            "ul",
            "ol",
            "a",
            "img",
            "table",
            "tr",
            "th",
            "td",
            "frameset",
            "iframe",
            "form",
            "input",
            "button",
            "textarea",
            "select",
            "div",
            "fieldset",
            "span",
            "strong",
            "em",
            "big",
            "small"
            };

            public void ProcessAutoCompleteBrackets(String s)
            {
                int sel = richTextBox1.SelectionStart;
                switch (s)
                {
                    case "(":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, ")");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;

                    case "[":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "]");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;

                    case "\"":
                        Is_AutoCompleteCharacterPressed = true;
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "\"");
                        richTextBox1.SelectionStart = sel;
                        break;

                    case "'":
                        richTextBox1.Text = richTextBox1.Text.Insert(sel, "'");
                        richTextBox1.SelectionStart = sel;
                        Is_AutoCompleteCharacterPressed = true;
                        break;
                }
            }

            private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                String ch = e.KeyChar.ToString();

                this.ProcessAutoCompleteBrackets(ch);

                if (ch == "<")
                {
                    Is_LessThanKeyPressed = true;
                    Is_SpaceBarKeyPressed = false;
                    EnteredString = "";
                }
                else if (ch == ">")
                {
                    if (!Is_TagClosedKeyPressed)
                    {
                        Is_GreaterThanKeyPressed = true;
                        Is_SpaceBarKeyPressed = false;

                        int oldsel = richTextBox1.SelectionStart;

                        for (int i = 0; i < tagslist.Length; i++)
                        {
                            if (EnteredString == tagslist[i])
                            {
                                richTextBox1.Text = richTextBox1.Text.Insert(oldsel, "</" + tagslist[i] + ">");
                                richTextBox1.SelectionStart = richTextBox1.SelectionStart + oldsel;
                                EnteredString = "";
                            }
                        }

                        Is_LessThanKeyPressed = false;
                    }
                    else
                    {
                        Is_TagClosedKeyPressed = false;
                    }
                }

                else
                {
                    if (Is_LessThanKeyPressed)
                    {
                        for (char a = 'a'; a <= 'z'; a++)
                        {
                            if (a.ToString() == ch)
                            {
                                EnteredString += ch;
                            }
                            else if (a.ToString().ToUpper() == ch)
                            {
                                EnteredString += ch;
                            }
                        }
                        for (int a = 0; a <= 9; a++)
                        {
                            if (a.ToString() == ch)
                            {
                                EnteredString += ch;
                            }
                        }
                    }
                }

                // if user itself closes the tag
                if (Is_LessThanKeyPressed)
                {
                    if (ch == "/")
                    {
                        Is_TagClosedKeyPressed = true;
                        Is_SpaceBarKeyPressed = true;
                        EnteredString = "";
                    }
                }
            }

            private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
            {
                switch (e.KeyCode)
                {
                    case Keys.Space:
                        Is_SpaceBarKeyPressed = true;

                        if (Is_GreaterThanKeyPressed)
                        {
                            Is_GreaterThanKeyPressed = false;
                        }
                        Is_LessThanKeyPressed = false;

                        for (int i = 0; i < tagslist.Length; i++)
                        {
                            if(EnteredString==tagslist[i])
                            {
                                EnteredString = tagslist[i];
                            }
                        }
                        break;

                    case Keys.Up:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Down:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Left:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Right:
                        if (Is_AutoCompleteCharacterPressed == false)
                        {
                            EnteredString = "";
                            Is_AutoCompleteCharacterPressed = false;
                        }
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Enter: EnteredString = "";
                        Is_SpaceBarKeyPressed = false;
                        break;

                    case Keys.Back:
                        int sel = richTextBox1.SelectionStart;
                        Point pt = richTextBox1.GetPositionFromCharIndex(sel);
                        char ch = richTextBox1.GetCharFromPosition(pt);
                        if (EnteredString.Length > 0)
                        {
                            if (ch != '>')
                            {
                                EnteredString = EnteredString.Remove(EnteredString.Length - 1);
                                Is_LessThanKeyPressed = true;
                            }
                        }
                        if (ch == '<')
                        {
                            EnteredString = "";
                        }
                        break;
                }
            }
        }
    }

Problem:

The implementation works fine, the only problem is when you type  (or any other keyword), the completion becomes , but it scrolls down to the end of the TextBox:

Anyone knows how to fix this?


问:
Best way for Processing to display graphics on a custom built remote display?
The goal is to use Processing as a scripting environment for creating graphics and to have the output display on a custom display device that is something like an LED light panel. The server running the program will be on a 1U rack. The idea is all the LED stuff is custom hardware, but rather than reinvent the wheel, it would be better to use an existing stack to drive the display. The problem is getting java to display on this device.

My initial thoughts are:
1. Run Java in headless mode.
2. Use Xvbf as the framebuffer.
3. Have a program run that reads the framebuffer, unpacks it, and then displays it on the remote device, at 30 fps.
4. Use Processing scripts to generate the graphics.

Does this make sense? Is there a better way? I'm not that knowledgeable about this area, but it seems better than trying to create a new java.awt.

答: If the "remote device" is just something directly attached by USB or some PCI controller, this seems sound (and exactly the sort of thing xvfb is made for).  But if the remote device is something connected by ethernet or wifi, depending on it's resolution you might find the naive approach of copying all the data each frame requires too much bandwidth and before you know it you'll be rolling your own frame-differencing image compression.  If you find yourself going down that route look at the VNC/TightVNC class of software which (at least in the form it's normally used on headless servers) provides an Xvfb-like virtual framebuffer/X-server accessible by a TCP/IP protocol which can transmit the content reasonably efficiently using compression and display it with VNC client software.</p>


问:
Vue.js and Immutable.js
I'm working on a Vue.js application where I have to deal with deeply nested data structures (trees and forests).

After reading about using simple data structures, pure functions and reducing (non-local) mutation, I belief that embracing those ideas would increase the maintainability and simplicity of my code.

While implementing a tree manipulation module using nothing but pure functions, I learned two things:

avoiding unintentional mutation of nested objects in JavaScript requires a lot of attention and discipline, especially with larger teams

I don't like littering my code with cloneDeep() invocations

Yesterday, I stumbled upon Immutable.js, which looks great to me. After a bit of playing around with it, I feel like it makes my pure functions much easier to reason about.

My Vue.js components would use fromJS(treeNode) and treeNode.toJS() when interacting with the manipulation module.

My question: is it technically possible to Vue.js and Immutable.js together? What are things to keep in mind? Are people using this combination in production? I found this post, which seems to suggest the opposite. That's all I could find.

What are the caveats or practical downsides? Would you suggest to use Immutable.js or to keep deeply cloning regular objects?

edit: updated my question in response to the votes, to make it (less) opinion-based

答:
I just tried this (out of curiosity).</p>

```<code><!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script src="https://unpkg.com/vue"></script>
        <script src="https://unpkg.com/vuex"></script>
        <script src="https://unpkg.com/immutable"></script>
    </head>
    <body>
        <div id="app">
            <button @click="increment">
                + (Increment)
            </button>
            {{ count }}
            <button @click="decrement">
                - (Decrement)
            </button>
            <hr>
            <input v-model="count" placeholder="Change Value"/>
        </div>
        <script>
const { Store } = Vuex;
const { Map } = Immutable;

const immutableCount = Map({
    value: 0
})

const countReducer = ({ state, type, value}) => {
    const count = state.count;
    let newCount;
    switch(type) {
        case 'INCREMENT':
            newCount = count.update('value', x => x + 1);
        break;
        case 'DECREMENT':
            newCount = count.update('value', x => x - 1);
        break;
        case 'SET_VALUE':
            newCount = count.set('value', value);
        break;
    }
    state.count = newCount;
}

const state = {
    count: immutableCount
}

const mutations = {
    INCREMENT(state) {
        countReducer({
            state,
            type: 'INCREMENT'
        })
    },
    DECREMENT(state) {
        countReducer({
            state,
            type: 'DECREMENT'
        })
    },
    SET_VALUE(state, value) {
        countReducer({
            state,
            type: 'SET_VALUE',
            value
        })
    }
}

const actions = {
    increment({ commit }) {
        commit('INCREMENT');
    },
    decrement({ commit }) {
        commit('DECREMENT');
    },
    setValue({ commit }, value) {
        commit('SET_VALUE', value);
    }
}

const store = new Store({
    state,
    mutations,
    actions
})

const dispatchers = {
    increment() {
        this.$store.dispatch('increment');
    },
    decrement() {
        this.$store.dispatch('decrement');
    },
    setValue(value) {
        this.$store.dispatch('setValue', value)
    }
}

const count = {
    get() {
        return this.$store.state.count.get('value');
    },
    set(value) {
        this.setValue(value ? value : 0)
    }
}

const computed = {
    count
}

const app = new Vue({
    el: '#app',
    computed,
    methods: {
        ...dispatchers
    },
    store
})
        </script>
    </body>
</html>
</code>```

Title: Vue.js and Immutable.js

Body:
I just tried this (out of curiosity).

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script src="https://unpkg.com/vue"></script>
        <script src="https://unpkg.com/vuex"></script>
        <script src="https://unpkg.com/immutable"></script>
    </head>
    <body>
        <div id="app">
            <button @click="increment">
                + (Increment)
            </button>
            {{ count }}
            <button @click="decrement">
                - (Decrement)
            </button>
            <hr>
            <input v-model="count" placeholder="Change Value"/>
        </div>
        <script>
const { Store } = Vuex;
const { Map } = Immutable;

const immutableCount = Map({
    value: 0
})

const countReducer = ({ state, type, value}) => {
    const count = state.count;
    let newCount;
    switch(type) {
        case 'INCREMENT':
            newCount = count.update('value', x => x + 1);
        break;
        case 'DECREMENT':
            newCount = count.update('value', x => x - 1);
        break;
        case 'SET_VALUE':
            newCount = count.set('value', value);
        break;
    }
    state.count = newCount;
}

const state = {
    count: immutableCount
}

const mutations = {
    INCREMENT(state) {
        countReducer({
            state,
            type: 'INCREMENT'
        })
    },
    DECREMENT(state) {
        countReducer({
            state,
            type: 'DECREMENT'
        })
    },
    SET_VALUE(state, value) {
        countReducer({
            state,
            type: 'SET_VALUE',
            value
        })
    }
}

const actions = {
    increment({ commit }) {
        commit('INCREMENT');
    },
    decrement({ commit }) {
        commit('DECREMENT');
    },
    setValue({ commit }, value) {
        commit('SET_VALUE', value);
    }
}

const store = new Store({
    state,
    mutations,
    actions
})

const dispatchers = {
    increment() {
        this.$store.dispatch('increment');
    },
    decrement() {
        this.$store.dispatch('decrement');
    },
    setValue(value) {
        this.$store.dispatch('setValue', value)
    }
}

const count = {
    get() {
        return this.$store.state.count.get('value');
    },
    set(value) {
        this.setValue(value ? value : 0)
    }
}

const computed = {
    count
}

const app = new Vue({
    el: '#app',
    computed,
    methods: {
        ...dispatchers
    },
    store
})
        </script>
    </body>
</html>


问:
How can I remove a certain pattern from a string?
I have this string like "682_2, 682_3, 682_4". (682 is a random number)

How can i get this string "2, 3, 4" using regex and ruby?

答:
A simple regex could be

/_([0-9]+)$/ and in the match group of the result you will have 2 for 682_2 and 3 for 682_3

Ruby code snippet would be "64532_2".match(/_([0-9]+)/).captures[0]


问:
"/anaconda/lib/python3.6/site-packages/nbstripout.py": /anaconda/bin/python: No such file or directory
Any advice how to fix the following error message(s)?

Every time that I am using Terminal with Mac OS Catalina 10.15.1 I get the following output

"/anaconda/bin/python" "/anaconda/lib/python3.6/site-packages/nbstripout.py": /anaconda/bin/python: No such file or directory

error: external filter '"/anaconda/bin/python" "/anaconda/lib/python3.6/site-packages/nbstripout.py"' failed 127

error: external filter '"/anaconda/bin/python" "/anaconda/lib/python3.6/site-packages/nbstripout.py"' failed

fatal: Google Drive/Drive on my xxxx.ipynb: clean filter 'nbstripout' failed

答: This happened to me when I moved my git repo. I had to go into .git/config and edit the [diff .ipynb] section with the updated directory.


Title: Spark Dataframe Scala: add new columns by some conditions

Body:
I revised my question so that it is easier to understand.

original df looks like this:

+---+----------+-------+----+------+
| id|tim       |price  | qty|qtyChg|
+---+----------+-------+----+------+
|  1| 31951.509|  0.370|   1|     1|
|  2| 31951.515|145.380| 100|   100|
|  3| 31951.519|149.370| 100|   100|
|  4| 31951.520|144.370| 100|   100|
|  5| 31951.520|119.370|   5|     5|
|  6| 31951.520|149.370| 300|   200|
|  7| 31951.521|149.370| 400|   100|
|  8| 31951.522|149.370| 410|    10|
|  9| 31951.522|149.870|  50|    50|
| 10| 31951.522|109.370|  50|    50|
| 11| 31951.522|144.370| 400|   300|
| 12| 31951.524|149.370| 610|   200|
| 13| 31951.526|135.130|  22|    22|
| 14| 31951.527|149.370| 750|   140|
| 15| 31951.528| 89.370| 100|   100|
| 16| 31951.528|145.870|  50|    50|
| 17| 31951.528|139.370| 100|   100|
| 18| 31951.531|144.370| 410|    10|
| 19| 31951.531|149.370| 769|    19|
| 20| 31951.538|149.370| 869|   100|
| 21| 31951.538|144.880| 200|   200|
| 22| 31951.541|139.370| 221|   121|
| 23| 31951.542|149.370|1199|   330|
| 24| 31951.542|139.370| 236|    15|
| 25| 31951.542|144.370| 510|   100|
| 26| 31951.543|146.250|  50|    50|
| 27| 31951.543|143.820| 100|   100|
| 28| 31951.543|139.370| 381|   145|
| 29| 31951.544|149.370|1266|    67|
| 30| 31951.544|150.000|  50|    50|
| 31| 31951.544|137.870| 300|   300|
| 32| 31951.544|140.470|  10|    10|
| 33| 31951.545|150.000|  53|     3|
| 34| 31951.545|140.000|  25|    25|
| 35| 31951.545|148.310|   8|     8|
| 36| 31951.547|149.000|  20|    20|
| 37| 31951.549|143.820| 102|     2|
| 38| 31951.549|150.110|  75|    75|
+---+----------+-------+----+------+

then I run the code

val ww = Window.partitionBy().orderBy($"tim")

val step1 = df.withColumn("sequence",sort_array(collect_set(col("price")).over(ww),asc=false))
.withColumn("top1price",col("sequence").getItem(0))
.withColumn("top2price",col("sequence").getItem(1))
.drop("sequence")

The new dataframe looks like this:

+---+---------+-------+----+------+---------+---------+
| id|      tim|  price| qty|qtyChg|top1price|top2price|
+---+---------+-------+----+------+---------+---------+
|  1|31951.509|  0.370|   1|     1|    0.370|     null|
|  2|31951.515|145.380| 100|   100|  145.380|    0.370|
|  3|31951.519|149.370| 100|   100|  149.370|  145.380|
|  4|31951.520|149.370| 300|   200|  149.370|  145.380|
|  5|31951.520|144.370| 100|   100|  149.370|  145.380|
|  6|31951.520|119.370|   5|     5|  149.370|  145.380|
|  7|31951.521|149.370| 400|   100|  149.370|  145.380|
|  8|31951.522|109.370|  50|    50|  149.870|  149.370|
|  9|31951.522|144.370| 400|   300|  149.870|  149.370|
| 10|31951.522|149.870|  50|    50|  149.870|  149.370|
| 11|31951.522|149.370| 410|    10|  149.870|  149.370|
| 12|31951.524|149.370| 610|   200|  149.870|  149.370|
| 13|31951.526|135.130|  22|    22|  149.870|  149.370|
| 14|31951.527|149.370| 750|   140|  149.870|  149.370|
| 15|31951.528| 89.370| 100|   100|  149.870|  149.370|
| 16|31951.528|139.370| 100|   100|  149.870|  149.370|
| 17|31951.528|145.870|  50|    50|  149.870|  149.370|
| 18|31951.531|144.370| 410|    10|  149.870|  149.370|
| 19|31951.531|149.370| 769|    19|  149.870|  149.370|
| 20|31951.538|144.880| 200|   200|  149.870|  149.370|
| 21|31951.538|149.370| 869|   100|  149.870|  149.370|
| 22|31951.541|139.370| 221|   121|  149.870|  149.370|
| 23|31951.542|144.370| 510|   100|  149.870|  149.370|
| 24|31951.542|139.370| 236|    15|  149.870|  149.370|
| 25|31951.542|149.370|1199|   330|  149.870|  149.370|
| 26|31951.543|139.370| 381|   145|  149.870|  149.370|
| 27|31951.543|143.820| 100|   100|  149.870|  149.370|
| 28|31951.543|146.250|  50|    50|  149.870|  149.370|
| 29|31951.544|140.470|  10|    10|  150.000|  149.870|
| 30|31951.544|137.870| 300|   300|  150.000|  149.870|
| 31|31951.544|150.000|  50|    50|  150.000|  149.870|
| 32|31951.544|149.370|1266|    67|  150.000|  149.870|
| 33|31951.545|140.000|  25|    25|  150.000|  149.870|
| 34|31951.545|150.000|  53|     3|  150.000|  149.870|
| 35|31951.545|148.310|   8|     8|  150.000|  149.870|
| 36|31951.547|149.000|  20|    20|  150.000|  149.870|
| 37|31951.549|150.110|  75|    75|  150.110|  150.000|
| 38|31951.549|143.820| 102|     2|  150.110|  150.000|
+---+---------+-------+----+------+---------+---------+

I am hoping to get two new columns top1priceQty, top2priceQty which store the most updated corresponding qty of top1price and top2price.

For example, in row 6, top1price= 149.370, based on this value, I want to get its corresponding qty which is 400(not 100 or 300). in row 33, when top1price=150.00000000, I want to get its corresponding qty which is 53 that comes from row 32, not 50 from row 28. same rule apply to top2price

Thank you all in advance!

Body:
You were very close to the answer by yourself. Instead of collecting set of just one column, collect array of 'LMTPRICE' and it's corresponding 'qty'. Then use getItem(0).getItem(0) for top1price and getItem(0).getItem(1) for top1priceQty. To keep the order by INTEREST_TIME for getting correct qty, use INTEREST_TIME  also after 'LMTPRICE' and before 'qty'.

df.withColumn("sequence",sort_array(collect_set(array("LMTPRICE","INTEREST_TIME","qty")).over(ww),asc=false)).withColumn("top1price",col("sequence").getItem(0).getItem(0)).withColumn("top1priceQty",col("sequence").getItem(0).getItem(2).cast("int")).drop("sequence").show(false)

+-----+-------------+--------+---+------+---------+------------+
|index|INTEREST_TIME|LMTPRICE|qty|qtyChg|top1price|top1priceQty|
+-----+-------------+--------+---+------+---------+------------+
|0    |31951.509    |0.37    |1  |1     |0.37     |1           |
|1    |31951.515    |145.38  |100|100   |145.38   |100         |
|2    |31951.519    |149.37  |100|100   |149.37   |100         |
|3    |31951.52     |119.37  |5  |5     |149.37   |300         |
|4    |31951.52     |144.37  |100|100   |149.37   |300         |
|5    |31951.52     |149.37  |300|200   |149.37   |300         |
|6    |31951.521    |149.37  |400|100   |149.37   |400         |
|7    |31951.522    |149.87  |50 |50    |149.87   |50          |
|8    |31951.522    |149.37  |410|10    |149.87   |50          |
|9    |31951.522    |109.37  |50 |50    |149.87   |50          |
|10   |31951.522    |144.37  |400|300   |149.87   |50          |
|11   |31951.524    |149.87  |610|200   |149.87   |610         |
|12   |31951.526    |135.13  |22 |22    |149.87   |610         |
|13   |31951.527    |149.37  |750|140   |149.87   |610         |
|14   |31951.528    |139.37  |100|100   |149.87   |610         |
|15   |31951.528    |145.87  |50 |50    |149.87   |610         |
|16   |31951.528    |89.37   |100|100   |149.87   |610         |
|17   |31951.531    |144.37  |410|10    |149.87   |610         |
|18   |31951.531    |149.37  |769|19    |149.87   |610         |
|19   |31951.538    |149.37  |869|100   |149.87   |610         |
+-----+-------------+--------+---+------+---------+------------+


问:
How to get post values from first page to third page ,as post
i have 3 pages

Page1.php,page2.php,page3.php

In page1.php, i have some hidden values, for example 'name'

After the submission of page1.php, it will go to page2.

Then after some process in page2.php, it should need to automatically submit to page3.php(where page3.php is in another sever)

Finally,when i print the $_POST  variables in page3.php, i need to get the variable 'name'

答:
you could stick it in the session

```<code><?php
session_start();
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>
</code>```

or you could pass them in hidden vars on page2.php if it has a form...

Body:
you could stick it in the session

<?php
session_start();
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>

or you could pass them in hidden vars on page2.php if it has a form...


问:
Unable to get Active user's email
I tried to log the user's email for debugging purposes. I used Session.getActiveUser().getEmail(). I received the following error.

Exception: You do not have permission to call Session.getActiveUser.getEmail() Required permissions: https://www.googleapis.com/auth/userinfo.email

Hence i added the https://www.googleapis.com/auth/userinfo.email scope to my addon. Now I get the following error

The script does not have permission to get the active user's identity.

However, I don't see the error if I run it on my account(Gsuite) or any other users in our domain. FYI: I am the owner of the addon.

Am I missing any scopes ?

答:
Neither getActiveUser() nor getEffectiveUser() were working for me.
There's an issue open with Google right now and some suggestions in this thread helped me:

(1) Try copying the scopes from (File->Project Properties->Scopes)  into the manifest file (View->Show Manifest File) following the instructions give here.

(2) The issue is with the new App Script runtime powered by Chrome v8. If (1) doesn't work (it didn't work for me) --> disable the App Script runtime as follows: (Run -> Disable App Script runtime powered by Chrome V8). The project will now run with Apps Script Legacy which does not have this issue.

Note: (2) is applicable until the issue is resolved.

Title: Unable to get Active user's email


问:
Transpose Pandas dataframe from wide to long
I have checked pandas.wide_to_long, pandas.melt, and various SO posts, but couldn't find a solution for this problem below.

I have this dataframe:

Could you please show me how to change it to this format? Thanks in advance.

答:
Let's try the following:

```<code>import pandas as pd
import numpy as np

df = pd.DataFrame({'Var1':[*'xyz'],
                  'Var2':['a']*3,
                  'Var1a':[1,5,9],
                  'Var2a':[2,6,10],
                  'Var3':[3,7,11],
                  'Var4':[4,8,12]})

df_out = df.set_index(['Var2', 'Var1']).stack().unstack(1).droplevel(1)
df_out = df_out.rename_axis(index=None, columns=None)
df_out
</code>```

Output:

```<code>   x  y   z
a  1  5   9
a  2  6  10
a  3  7  11
a  4  8  12
</code>```

Body:
Let's try the following:

import pandas as pd
import numpy as np

df = pd.DataFrame({'Var1':[*'xyz'],
                  'Var2':['a']*3,
                  'Var1a':[1,5,9],
                  'Var2a':[2,6,10],
                  'Var3':[3,7,11],
                  'Var4':[4,8,12]})

df_out = df.set_index(['Var2', 'Var1']).stack().unstack(1).droplevel(1)
df_out = df_out.rename_axis(index=None, columns=None)
df_out

Output:

   x  y   z
a  1  5   9
a  2  6  10
a  3  7  11
a  4  8  12