问:
WPF Changing ListBox background color, enabled and disabled
I'm searching how to change the background color of my WPF Listbox, nothing worked...  I don't want to change the background of the Item Template, but of the ListBox himself.

I tried the differents solutions answered here Answers

Here is my Listbox :

```<code><ListBox Name="myListBox" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="myListBox_SelectionChanged" Background="#FFC3DDF7" Margin="0,0,0,10">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Value.IsOk}" Value="True">
                                <Setter Property="Background" Value="Green"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Width="200">
                                <TextBlock FontSize="10" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=Key}" />
                                <TextBlock FontSize="10" VerticalAlignment="Center" TextWrapping="Wrap">
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0} {1} {2}">
                                            <Binding Path="Value.TextA" />
                                            <Binding Path="Value.TextB" />
                                            <Binding Path="Value.TextC" />
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
</code>```

Maybe the item template is on the foreground ?

Tried these codes :

```<code><ListBox.Style>
<Style TargetType="{x:Type ListBox}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue"/>
    </Style.Resources>
</Style>
</code>```

and

```<code> <ListBox>
    <ListBox.Style>
        <Style TargetType="{x:Type ListBox}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Background" Value="Blue" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.Style>
</ListBox>
</code>```

Not working. The down right corner, between the two scrollbars, became blue... But that's all !

答:
First off all - this msdn link ListBox Styles and Templates will help you the most. You can check this way - what applies where in a ListBox and a ListBoxItem.

If you check the Style of the ListBoxItem you will see that the ContentPresenter gets no Foreground applied.

```<code>  <Style TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter   x:Name="contentPresenter"
                                                Content="{TemplateBinding Content}"
                                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                Margin="{TemplateBinding Padding}"/><!-- No foreground gets applied. -->
                            <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed" RadiusX="1" RadiusY="1" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</code>```

Anyway here is your solution:

```<code>    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal"
                        Width="200">
                <TextBlock VerticalAlignment="Center"
                               FontSize="10"
                               TextWrapping="Wrap">

                        <Run FontWeight="Bold" Text="{Binding Path=Key}" />
                        <LineBreak />
                        <Run>
                            <Run.Text>
                                <MultiBinding StringFormat="{}{0} {1} {2}">
                                    <Binding Path="Value.TextA" />
                                    <Binding Path="Value.TextB" />
                                    <Binding Path="Value.TextC" />
                                </MultiBinding>
                            </Run.Text>
                        </Run>
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsOk}" Value="True" >
                                    <Setter Property="Foreground" Value="Green"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</code>```

The TextBlock now listens to isOk and will applys the Foreground.

Body:
I'm searching how to change the background color of my WPF Listbox, nothing worked...  I don't want to change the background of the Item Template, but of the ListBox himself.

I tried the differents solutions answered here Answers

Here is my Listbox :

<ListBox Name="myListBox" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="myListBox_SelectionChanged" Background="#FFC3DDF7" Margin="0,0,0,10">
                <ListBox.ItemContainerStyle>

                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Width="200">
                                <TextBlock FontSize="10" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=Key}" />
                                <TextBlock FontSize="10" VerticalAlignment="Center" TextWrapping="Wrap">
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0} {1} {2}">
                                            <Binding Path="Value.TextA" />
                                            <Binding Path="Value.TextB" />
                                            <Binding Path="Value.TextC" />
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Maybe the item template is on the foreground ?

Tried these codes :

<ListBox.Style>

</Style>

and

 <ListBox>
    <ListBox.Style>

        </Style>
    </ListBox.Style>
</ListBox>

Not working. The down right corner, between the two scrollbars, became blue... But that's all !

Body:
First off all - this msdn link ListBox Styles and Templates will help you the most. You can check this way - what applies where in a ListBox and a ListBoxItem.

If you check the Style of the ListBoxItem you will see that the ContentPresenter gets no Foreground applied.

  <Style TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter   x:Name="contentPresenter"
                                                Content="{TemplateBinding Content}"
                                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                Margin="{TemplateBinding Padding}"/><!-- No foreground gets applied. -->
                            <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed" RadiusX="1" RadiusY="1" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Anyway here is your solution:

    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal"
                        Width="200">
                <TextBlock VerticalAlignment="Center"
                               FontSize="10"
                               TextWrapping="Wrap">

                        <Run FontWeight="Bold" Text="{Binding Path=Key}" />
                        <LineBreak />
                        <Run>
                            <Run.Text>
                                <MultiBinding StringFormat="{}{0} {1} {2}">
                                    <Binding Path="Value.TextA" />
                                    <Binding Path="Value.TextB" />
                                    <Binding Path="Value.TextC" />
                                </MultiBinding>
                            </Run.Text>
                        </Run>
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsOk}" Value="True" >
                                    <Setter Property="Foreground" Value="Green"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>

The TextBlock now listens to isOk and will applys the Foreground.


来源: stackexchange

问:
Splitting divs into 2 columns
I have a code like this:

title1

article1

title2

article2

title3

article3

title4

article4

```
</div>
</div>
</p>

<p>and I want to transform this 1 lined column into 2 columns like this:</p>

<p><img src="https://i.stack.imgur.com/NKI4c.png" alt="example image"></p>

<p>I already tried to use this code, but is there any different way to split the div?</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.article-container {
  display: flex;
  flex-wrap: wrap;
}

.article {
  flex-grow: 1;
  flex-basis: 50%;
}

.article:after {
  content: "";
  flex: auto;
}</code>```

title1

article1

title2

article2

title3

article3

title4

article4

```

It's different from this other question Split Div Into 2 Columns Using CSS, the "article" arrangement from this question is different. Anyone got the idea?

答:
You may try using CSS3 Columns. But in this case, it looks a bit different in the information flow.

.article-container {
  -webkit-columns: 2; /* Chrome, Safari, Opera */
  -moz-columns: 2; /* Firefox */
  columns: 2;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="article-container">
  <div class="article">
    <h3>title1</h3>
    <p>article1</p>
  </div>
  <div class="article">
    <h3>title2</h3>
    <p>article2</p>
  </div>
  <div class="article">
    <h3>title3</h3>
    <p>article3</p>
  </div>
  <div class="article">
    <h3>title4</h3>
    <p>article4</p>
  </div>
</div></code>```

ContentLicense: CC BY-SA 3.0

Title: Splitting divs into 2 columns

Body:
I have a code like this:

title1

article1

title2

article2

title3

article3

title4

article4

and I want to transform this 1 lined column into 2 columns like this:

I already tried to use this code, but is there any different way to split the div?

.article-container {
  display: flex;
  flex-wrap: wrap;
}

.article {
  flex-grow: 1;
  flex-basis: 50%;
}

.article:after {
  content: "";
  flex: auto;
}

title1

article1

title2

article2

title3

article3

title4

article4

It's different from this other question Split Div Into 2 Columns Using CSS, the "article" arrangement from this question is different. Anyone got the idea?

Body:
You may try using CSS3 Columns. But in this case, it looks a bit different in the information flow.

.article-container {
  -webkit-columns: 2; /* Chrome, Safari, Opera */
  -moz-columns: 2; /* Firefox */
  columns: 2;
}

<div class="article-container">
  <div class="article">
    <h3>title1</h3>
    <p>article1</p>
  </div>
  <div class="article">
    <h3>title2</h3>
    <p>article2</p>
  </div>
  <div class="article">
    <h3>title3</h3>
    <p>article3</p>
  </div>
  <div class="article">
    <h3>title4</h3>
    <p>article4</p>
  </div>
</div>


问:
SQL Server cannot execute query
When I try to execute any query in sql server, I get this error message many times:

Cannot execute script - Additional information: The process cannot access the file 'C:\Users\AppData\Local\Temp\tmpC9BA.tmp' because it is being used by another process. (mscorlib)".

I then have to click ok and run the query again and it will work fine.

答: Mscorlib is actually .net dll, but I faced such file locking issue due to my antivirus sometime back. Could be an issue for u too.</p>

Title: SQL Server cannot execute query


问:
Which constructor should I use for the StringBuilder class?
I'm building a large string from a list of items.  Each item will generate a string which is approximately 200 characters long (plus or minus 100%).

Will I get a (noticeable) performance benefit from using

```<code>Dim sb = New StringBuilder(averageCharacterCount * items.Count)
</code>```

instead of

```<code>Dim sb = New StringBuilder()
</code>```

even if the specified capacity is just a guess?

答:
Starting in the right ball-park will save a few reallocations/copies, but note that since it is a doubling algorithm it will approach the size pretty quickly. If it is within 100% that is only one more reallocation/copy for the worst case, so yes - starting with that approach will help some.

But in many ways this is a micro-optimisation; you're already doing it the right way, so unless our profiling shows this is still a bottleneck (ad you therefore need to squeeze the last few cycles out), forget it and move on to the next thing.

ContentLicense: CC BY-SA 2.5

Body:
I'm building a large string from a list of items.  Each item will generate a string which is approximately 200 characters long (plus or minus 100%).

Will I get a (noticeable) performance benefit from using

Dim sb = New StringBuilder(averageCharacterCount * items.Count)

instead of

Dim sb = New StringBuilder()

even if the specified capacity is just a guess?


问:
Finding if an element is in an array using C (syntax issue)
I'm trying to write a function that checks if an element is an array in C. I have a function here, but it always returns 0, so any debugging help would be appreciated:</p>

```<code>#include <stdio.h>
int array[] = {1, 2, 3};
int *parray = &array;
int j;
int n = sizeof(array)/sizeof(array[0]);

int ifInList(int array[], int n){
    for (j = 0; j < n; j++){
        if (array[j] == n){
           return 1;
        }
    }
    return 0;
}

int main(){
    printf("The number is %d \n", ifInList(&array[n], 1));
    return 0;
}
</code>```

答:
Working code for checking if element n is in an array:

```<code>int ifInList(int array[], int size, int n) {
    int j;
    for(j=0; j<size; j++)
        if(array[i]==n)
            return 1;
    return 0;
}
</code>```

You will need three parameters to do this. The array, the size and the element you're looking for.

Other things about your code:

Global variables are in general a bad habit. While you could (theoretically, maybe, but probably not) get away with having the array and the size of it as a global, there's absolutely no reason at all to let j be a global. It should be inside the function ifInList.

As a general rule:

If you're using global variables for convenience, you're doing something wrong.

Body:
I'm trying to write a function that checks if an element is an array in C. I have a function here, but it always returns 0, so any debugging help would be appreciated:

#include <stdio.h>
int array[] = {1, 2, 3};
int *parray = &array;
int j;
int n = sizeof(array)/sizeof(array[0]);

int ifInList(int array[], int n){
    for (j = 0; j < n; j++){
        if (array[j] == n){
           return 1;
        }
    }
    return 0;
}

int main(){
    printf("The number is %d \n", ifInList(&array[n], 1));
    return 0;
}

Body:
Working code for checking if element n is in an array:

int ifInList(int array[], int size, int n) {
    int j;
    for(j=0; j<size; j++)
        if(array[i]==n)
            return 1;
    return 0;
}

You will need three parameters to do this. The array, the size and the element you're looking for.

Other things about your code:

Global variables are in general a bad habit. While you could (theoretically, maybe, but probably not) get away with having the array and the size of it as a global, there's absolutely no reason at all to let j be a global. It should be inside the function ifInList.

As a general rule:

If you're using global variables for convenience, you're doing something wrong.


问:
How to use the forever CLI in Docker?
I am Dockerizing every project of mine and I use a CLI called forever to re-run my scripts if they fail.

I was using the official node.js Docker tutorial to Dockerize my simpler scripts, but when I got to my more complex one (which were using the forever CLI) I didn't know how to run the CLI in Docker.

Is there any way to make this possible, either with using the forever CLI or the module?

答:
I will reiterate Oliver's comment as I think it is actually a valid answer. When running a process as a Docker container, there are mechanisms already in place to handle what forever does for you.

A quick gloss over the forever actions reveals that it actually already looks a bit like Docker:

```<code>  actions:
    start               Start SCRIPT as a daemon
    stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
    stopall             Stop all running forever scripts
    restart             Restart the daemon SCRIPT
    restartall          Restart all running forever scripts
    list                List all running forever scripts
    config              Lists all forever user configuration
    set <key> <val>     Sets the specified forever config <key>
    clear <key>         Clears the specified forever config <key>
    logs                Lists log files for all forever processes
    logs <script|index> Tails the logs for <script|index>
    columns add <col>   Adds the specified column to the output in `forever list`
    columns rm <col>    Removed the specified column from the output in `forever list`
    columns set <cols>  Set all columns for the output in `forever list`
    cleanlogs           [CAREFUL] Deletes all historical forever log files
</code>```

Instead of using forever to manage your process, just use Docker:

The --restart=always option for docker run is the same underlying concept of forever, to restart the application and keep it running should it fail.

docker run is synonymous with forever start. Add -d to docker run to run in the background.

docker ps is synonymous with forever list. In the case of Docker, just make each of your forever processes a Docker container.

docker logs is synonymous with forever logs.

This should make it fairly trivial to just make your process the CMD or ENTRYPOINT in the Dockerfile and do away wth forever entirely.

Further down the road, when you start getting into container orchestration and deployment, have a look at health checks (HEALTHCHECK instruction), Docker Swarm, and Docker Compose.

Title: How to use the forever CLI in Docker?

Body:
I will reiterate Oliver's comment as I think it is actually a valid answer. When running a process as a Docker container, there are mechanisms already in place to handle what forever does for you.

A quick gloss over the forever actions reveals that it actually already looks a bit like Docker:

  actions:
    start               Start SCRIPT as a daemon
    stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
    stopall             Stop all running forever scripts
    restart             Restart the daemon SCRIPT
    restartall          Restart all running forever scripts
    list                List all running forever scripts
    config              Lists all forever user configuration
    set <key> <val>     Sets the specified forever config <key>
    clear <key>         Clears the specified forever config <key>
    logs                Lists log files for all forever processes
    logs <script|index> Tails the logs for <script|index>
    columns add <col>   Adds the specified column to the output in `forever list`
    columns rm <col>    Removed the specified column from the output in `forever list`
    columns set <cols>  Set all columns for the output in `forever list`
    cleanlogs           [CAREFUL] Deletes all historical forever log files

Instead of using forever to manage your process, just use Docker:

The --restart=always option for docker run is the same underlying concept of forever, to restart the application and keep it running should it fail.

docker run is synonymous with forever start. Add -d to docker run to run in the background.

docker ps is synonymous with forever list. In the case of Docker, just make each of your forever processes a Docker container.

docker logs is synonymous with forever logs.

This should make it fairly trivial to just make your process the CMD or ENTRYPOINT in the Dockerfile and do away wth forever entirely.

Further down the road, when you start getting into container orchestration and deployment, have a look at health checks (HEALTHCHECK instruction), Docker Swarm, and Docker Compose.


问:
variable value not updated after recursive call
In one of my methods I'm writing a try catch to validate the user's input. If the user enters the wrong data type the method is called again and they are prompted to re-enter. For some reason when the method is called for the second time no matter what the value entered is, it will always return as 0.

```<code>public static int enterNumGadgets(){

    int numOfGadgetsIn = 0;

    try{
        System.out.println("");
        System.out.println("Please enter the number of items you wish to insure.");
        numOfGadgetsIn = EasyScanner.nextInt();
    }
    catch(InputMismatchException exception){

        System.out.println("You must enter a number.");
        EasyScanner.nextLine(); //consume new line left over
        enterNumGadgets(); //call the method again

    }
    return numOfGadgetsIn;
}
</code>```

Output with correct data type the first time the method is called:

Name: test

Reference Number: te123s

Number of Gadgets: 1

Most expensive item:1.0

Output with incorrect data type on first call, but correct data type on second:

Name: test

Reference Number: te123s

Number of Gadgets: 0

Most expensive item:1.0

Notice how it seems that after the second call to enterNumGadgets() it seems to ignore the new value int numOfGadgetsIn is set to in try{...} and returns it as 0.

Any help would be much appreciated

答:
After a second rekursiv call (where your user data is valid), your data is not assigned to a new variable. instead the variable on your first call (where user data is invalid) is used, which is still 0.

This should work:

```<code>public static int enterNumGadgets(){

int numOfGadgetsIn = 0;

try{
    System.out.println("");
    System.out.println("Please enter the number of items you wish to insure.");
    numOfGadgetsIn = EasyScanner.nextInt();
}
catch(InputMismatchException exception){

    System.out.println("You must enter a number.");
    EasyScanner.nextLine(); //consume new line left over
    numOfGadgetsIn = enterNumGadgets(); //call the method again

}
return numOfGadgetsIn;
</code>```

}

Body:
In one of my methods I'm writing a try catch to validate the user's input. If the user enters the wrong data type the method is called again and they are prompted to re-enter. For some reason when the method is called for the second time no matter what the value entered is, it will always return as 0.

public static int enterNumGadgets(){

    int numOfGadgetsIn = 0;

    try{
        System.out.println("");
        System.out.println("Please enter the number of items you wish to insure.");
        numOfGadgetsIn = EasyScanner.nextInt();
    }
    catch(InputMismatchException exception){

        System.out.println("You must enter a number.");
        EasyScanner.nextLine(); //consume new line left over
        enterNumGadgets(); //call the method again

    }
    return numOfGadgetsIn;
}

Output with correct data type the first time the method is called:

Name: test

Reference Number: te123s

Number of Gadgets: 1

Most expensive item:1.0

Output with incorrect data type on first call, but correct data type on second:

Name: test

Reference Number: te123s

Number of Gadgets: 0

Most expensive item:1.0

Notice how it seems that after the second call to enterNumGadgets() it seems to ignore the new value int numOfGadgetsIn is set to in try{...} and returns it as 0.

Any help would be much appreciated

Body:
After a second rekursiv call (where your user data is valid), your data is not assigned to a new variable. instead the variable on your first call (where user data is invalid) is used, which is still 0.

This should work:

public static int enterNumGadgets(){

int numOfGadgetsIn = 0;

try{
    System.out.println("");
    System.out.println("Please enter the number of items you wish to insure.");
    numOfGadgetsIn = EasyScanner.nextInt();
}
catch(InputMismatchException exception){

    System.out.println("You must enter a number.");
    EasyScanner.nextLine(); //consume new line left over
    numOfGadgetsIn = enterNumGadgets(); //call the method again

}
return numOfGadgetsIn;

}


问:
Create a Jenkins Job to run JMeter tests on a remote EC2 instance
I have a Java application that creates and runs JMeter tests.
Those tests need to be run on a remote EC2 instance.
Is it possible to have some command in Jenkins (which is on a separate AWS machine) to clone a git project to a remote EC2 instance? And run the flow there?

I will appreciate any thoughts and ideas!

答:
So, here is my solution:

in Jenkins in Build section add 'Execute shell' step and do scp there for pom.xml and src folder from the Jenkins workspace to ec2 instance tmp folder
in my case it looks like this:

scp -i ../../../jobs/utilities/keys/.pem pom.xml ec2-user@ec2-00-000-00.compute.amazonaws.com:/tmp

scp -i ../../../jobs/utilities/keys/.pem -r src ec2-user@ec2-00-000-00.compute.amazonaws.com:/tmp

then add 'Send files or execute command over SSH' step and in the Exec command section put next:

sudo rm -rf ../../my_project_folder_name/

sudo mkdir ../../my_project_folder_name

cd ../../tmp

sudo cp pom.xml ../my_project_folder_name/

sudo cp -r src ../my_project_folder_name

cd ../my_project_folder_name

sudo mvn clean test

then add one more 'Execute shell' step to copy all the files from tag=rget folder to be able to use them for different reports:

scp -i ../../../jobs/utilities/keys/.pem -r ec2-user@ec2-00-000-00.compute.amazonaws.com:/my_project_folder_name/target .

That's it :)


问:
For Loop not looping and detecting Char Array [Pointers and Char Arrays]
Basically, the code is asking for a user input. I type in the word hotkdog and I would like to use the function FindIndexOfCharacter 'k', which is 3. However, the function is always returning -1, so I guess my loop isn't being ++i for some reason??   </p>

```<code>#include <iostream>
#include <cstring>
#include <string>

void ReadString(char * c, int maxLength);
int FindIndexOfCharacter(char * c, char testVal);

int main()
{
    const int SIZE = 10;
    char ca[SIZE];
    char * cpointer = ca;

    ReadString(cpointer, 10);
    std::cout << FindIndexOfCharacter(cpointer, 'k');
    system("pause");
}

void ReadString(char * c, int Length)
{
    std::cout << "Enter a string " << Length << " characters." << std::endl;
    std::cin >> c;
}

int FindIndexOfCharacter(char * c, char Val)
{
    int sizeOfArray2 = std::strlen(c);
    std::cout << sizeOfArray2 << std::endl; // this confirms array size

    for (int i = 0; i < sizeOfArray2; ++i)
    {
        if (c[i] == Val)
            return i;
        else
            return -1;
    }
}
</code>```

答:
You could change your function:  </p>

```<code>char * p_found = strchr(c, Val);
if (p_found != nullptr)
{
  return p_found - c;
}
return -1;
</code>```

Body:
Basically, the code is asking for a user input. I type in the word hotkdog and I would like to use the function FindIndexOfCharacter 'k', which is 3. However, the function is always returning -1, so I guess my loop isn't being ++i for some reason??

#include <iostream>
#include <cstring>
#include <string>

void ReadString(char * c, int maxLength);
int FindIndexOfCharacter(char * c, char testVal);

int main()
{
    const int SIZE = 10;
    char ca[SIZE];
    char * cpointer = ca;

    ReadString(cpointer, 10);
    std::cout << FindIndexOfCharacter(cpointer, 'k');
    system("pause");
}

void ReadString(char * c, int Length)
{
    std::cout << "Enter a string " << Length << " characters." << std::endl;
    std::cin >> c;
}

int FindIndexOfCharacter(char * c, char Val)
{
    int sizeOfArray2 = std::strlen(c);
    std::cout << sizeOfArray2 << std::endl; // this confirms array size

    for (int i = 0; i < sizeOfArray2; ++i)
    {
        if (c[i] == Val)
            return i;
        else
            return -1;
    }
}

Body:
You could change your function:

char * p_found = strchr(c, Val);
if (p_found != nullptr)
{
  return p_found - c;
}
return -1;


问:
long and int same size in eclipse?
Don't know if this is an eclipse specific problem but whenever I declare a long and try to put a value > 2^32 in it complains about "the literal XXXXXX of type int is out of range"

I've tried casting is directly to long but is doesnt seem to have any effect. What am I missing here?

答: Look at this topic . Don't be addictive to IDEs.  </p>

Title: long and int same size in eclipse?


问:
When should I use $.getJSON.done() instead of $.getJSON()?
I would like to know if there are any conceptual differences between these two codes:

Code 1:

```<code>$(function(){
  var url = "url";
  $.getJSON(url, function(data){
  console.log(data);
  })
});
</code>```

Code 2:

```<code>$(function(){
  var url = "url";
  $.getJSON(url).done(function(data){
  console.log(data);
  })
});
</code>```

In which situation the $.getJson().done() method is most relevant ?

答:
The First one uses a callback function as a second param. This allows you to execute code after the function is completed. Note, you are in a separate function.

The Second also uses a callback function as a promise but it is working different under the hood.

// version one
setTimeout(function() {
  doStuff1();
  doStuff2();
}, 1000)

// version one - callback
function doStuff1() {
  doSomething1("value", function(responce) {
    console.log(responce);
  });
};

function doSomething1(v, cb) {
  if (typeof v === "string") {
    cb(true);
  } else {
    cb(false);
  }
  return false;
}

// note the function will always return false but the callback gets the value you want

// version 2, class with promise callback
// look at the class function and see how it works slightly differently
function doStuff2() {
  var $ = new doSomething2();
  $.Something("value").done(function(resp) {
    console.log(resp)
  });
};

class doSomething2 {
  constructor() {
    this.v = false;
  }

  Something(val) {
    if (typeof val === "string") {
      this.v = true;
    } else {
      this.v = false;
    }
    return this;
  }
  done(cb) {
    return cb(this.v);
  }
}```

Body:
I would like to know if there are any conceptual differences between these two codes:

Code 1:

$(function(){
  var url = "url";
  $.getJSON(url, function(data){
  console.log(data);
  })
});

Code 2:

$(function(){
  var url = "url";
  $.getJSON(url).done(function(data){
  console.log(data);
  })
});

In which situation the $.getJson().done() method is most relevant ?


问:
Why does using cURL to request from an API return 200/data but the equivalent Ruby/NetHTTP/HTTParty return 500/error?
I'm trying to get some data from the OneSignal API.

If I run it straight into the terminal (removed Auth key and App ID for this question), no problem:

```<code>$ curl --include --header "Authorization: Basic Yzzzzzzzzzzzzzzzz"
 "https://onesignal.com/api/v1/players?app_id={XXXXXXXXXXX}&limit=300&offset=0"
</code>```

Returns:

```<code>{"total_count":1,"offset":0,"limit":300,"players": [{"id":"XXXXXX","identifier":"XXXXXXX","session_count":3,"language":"en","timezone":-14400,"game_version":"3","device_os":"6.0.1","device_type":1,"device_model":"LG-K240","ad_id":"XXXXXXXX","tags":{},"last_active":1498938033,"playtime":0,"amount_spent":0.0,"created_at":1498935316,"invalid_identifier":false,"badge_count":0,"sdk":"030507","test_type":null}]}
</code>```

If I use what I am lead to believe using this Curl to Ruby converter is the equivalent Ruby in my rake task, instead suddenly I hit unknown errors galore:

```<code>require 'net/http'
require 'uri'

uri = URI.parse("https://onesignal.com/api/v1/players?app_id={XXXXXX}&limit=300&offset=0")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Basic Yzzzzzzzzzzzzzzzz"

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

puts response.code
puts response.body
</code>```

Returns:

```<code>500
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>500 • OneSignal</title>
  <style>
    html, body {
      margin: 0;
      padding: 0;
      background: #F1F1F1;
      font-size: 18px;
    }

    svg#logo {
      width: 240px;
      height: 102px;
    }

    .logo-head {
      margin-top: 1.3em;
    }

    svg#logo-head {
      width: 40px;
      height: 40px;
    }

    #content {
      margin: 2em auto;
      width: 600px;
      padding: 30px;
      text-align: center;
    }

    .text {
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: rgba(0, 0, 0, 0.5);
      font-size: 1em;
      font-weight: 200;
      line-height: 1.6em;
    }

    .text.twitter {
      font-size: 0.85em;
    }

    a {
      text-decoration: none;
    }

    a:hover {
      text-decoration: underline;
    }

    a:visited {
      text-decoration: none;
      color: inherit;
    }

    #message {
      font-weight: 400;
      font-size: 1.4em;
      margin-bottom: 0;
    }

    #submessage {
      font-size: 0.8em;
      margin-bottom: 2.5em;
    }

    footer {
      margin-top: 2em;
    }

    iframe {
      border: 1px solid rgba(0, 0, 0, 0.1) !important;
      border-radius: 4px;
    }
  </style>
</head>
<body>
<div id="content">
  <svg version="1.1" id="logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
             x="0px" y="0px"
             viewBox="0 0 160 34" style="enable-background:new 0 0 160 34;" xml:space="preserve">
        <style type="text/css">
            .st0{fill:#E44A49;}
            .st1{fill:#515151;}
        </style>
        <g id="XMLID_1_">
            <path id="XMLID_2_" class="st0" d="M55.3,27.1c-1.1,0-2.1-0.2-3-0.7c-0.9-0.4-1.7-1-2.3-1.8c-0.6-0.7-1.1-1.6-1.5-2.5
                c-0.4-1-0.5-1.9-0.5-2.9s0.2-2,0.6-3s0.9-1.8,1.6-2.5s1.4-1.3,2.3-1.7s1.9-0.6,2.9-0.6c1.1,0,2.1,0.2,3,0.7s1.7,1.1,2.3,1.8
                c0.6,0.7,1.1,1.6,1.5,2.5s0.5,1.9,0.5,2.9s-0.2,2-0.6,3s-0.9,1.8-1.5,2.5c-0.7,0.7-1.4,1.3-2.3,1.7C57.3,26.9,56.3,27.1,55.3,27.1z
                 M49.5,19.2c0,0.9,0.1,1.7,0.4,2.5s0.7,1.5,1.2,2.1s1.1,1.1,1.8,1.5c0.7,0.4,1.5,0.5,2.4,0.5s1.7-0.2,2.4-0.6
                c0.7-0.4,1.3-0.9,1.8-1.5s0.9-1.3,1.2-2.1c0.3-0.8,0.4-1.6,0.4-2.4s-0.1-1.7-0.4-2.5s-0.7-1.5-1.2-2.1s-1.1-1.1-1.8-1.4
                c-0.7-0.4-1.5-0.5-2.3-0.5c-0.9,0-1.7,0.2-2.4,0.6c-0.7,0.4-1.3,0.9-1.8,1.5s-0.9,1.3-1.2,2.1C49.6,17.6,49.5,18.4,49.5,19.2z"/>
            <path id="XMLID_5_" class="st0" d="M75.5,27H74v-6.4c0-1.4-0.2-2.4-0.6-3s-1-0.9-1.8-0.9c-0.4,0-0.9,0.1-1.3,0.2
                c-0.4,0.2-0.9,0.4-1.2,0.7c-0.4,0.3-0.7,0.6-1,1s-0.5,0.8-0.6,1.3v7H66V15.5h1.3v2.6c0.2-0.4,0.5-0.8,0.9-1.1
                c0.3-0.3,0.7-0.6,1.2-0.9c0.4-0.2,0.9-0.4,1.4-0.6c0.5-0.1,1-0.2,1.5-0.2c0.6,0,1.2,0.1,1.6,0.4c0.4,0.2,0.8,0.6,1,1
                s0.5,0.9,0.6,1.6c0.1,0.6,0.2,1.3,0.2,2V27L75.5,27L75.5,27z"/>
            <path id="XMLID_7_" class="st0" d="M84.3,27.2c-0.8,0-1.6-0.2-2.3-0.5s-1.3-0.7-1.8-1.3s-0.9-1.2-1.2-1.9c-0.3-0.7-0.4-1.5-0.4-2.3
                s0.1-1.6,0.4-2.3s0.7-1.3,1.2-1.9c0.5-0.5,1.1-1,1.8-1.3c0.7-0.3,1.5-0.5,2.3-0.5s1.6,0.2,2.3,0.5c0.7,0.3,1.3,0.7,1.8,1.3
                c0.5,0.5,0.9,1.2,1.2,1.9s0.4,1.5,0.4,2.2c0,0.1,0,0.2,0,0.4c0,0.1,0,0.2,0,0.2h-9.8c0,0.6,0.2,1.2,0.4,1.7c0.2,0.5,0.5,1,0.9,1.4
                s0.8,0.7,1.3,0.9s1,0.3,1.6,0.3c0.4,0,0.8-0.1,1.1-0.2c0.4-0.1,0.7-0.2,1-0.4s0.6-0.4,0.8-0.6c0.2-0.3,0.4-0.5,0.6-0.8l1.3,0.4
                c-0.2,0.4-0.4,0.8-0.7,1.2c-0.3,0.3-0.7,0.6-1.1,0.9C87,26.8,86.5,27,86,27.1C85.3,27.2,84.8,27.2,84.3,27.2z M88.5,20.7
                c0-0.6-0.2-1.2-0.4-1.7c-0.2-0.5-0.5-0.9-0.9-1.3c-0.4-0.4-0.8-0.7-1.3-0.9s-1-0.3-1.6-0.3s-1.1,0.1-1.6,0.3s-0.9,0.5-1.3,0.9
                s-0.7,0.8-0.9,1.3c-0.2,0.5-0.4,1.1-0.4,1.7H88.5z"/>
            <path id="XMLID_10_" class="st1" d="M102.2,15.5c-0.1-0.1-0.3-0.2-0.6-0.4s-0.6-0.3-1-0.5s-0.8-0.3-1.3-0.4S98.4,14,97.9,14
                c-0.8,0-1.5,0.2-1.9,0.5s-0.6,0.7-0.6,1.3c0,0.3,0.1,0.6,0.2,0.8c0.2,0.2,0.4,0.4,0.7,0.6c0.3,0.2,0.7,0.3,1.1,0.4
                c0.4,0.1,1,0.3,1.6,0.4c0.8,0.2,1.5,0.4,2.1,0.7c0.6,0.2,1.2,0.5,1.6,0.9c0.4,0.4,0.8,0.8,1,1.3s0.4,1.1,0.4,1.8
                c0,0.8-0.2,1.6-0.5,2.1c-0.3,0.6-0.7,1.1-1.3,1.4c-0.5,0.4-1.1,0.6-1.8,0.8s-1.4,0.3-2.2,0.3c-1.2,0-2.3-0.2-3.5-0.5
                c-1.1-0.4-2.2-0.9-3.1-1.5l1.3-2.6c0.1,0.1,0.4,0.3,0.7,0.5s0.8,0.4,1.2,0.6c0.5,0.2,1,0.4,1.6,0.5s1.2,0.2,1.8,0.2
                c1.7,0,2.5-0.5,2.5-1.6c0-0.4-0.1-0.6-0.3-0.9c-0.2-0.2-0.5-0.4-0.8-0.6c-0.4-0.2-0.8-0.3-1.3-0.5c-0.5-0.1-1.1-0.3-1.7-0.5
                c-0.7-0.2-1.4-0.4-1.9-0.7c-0.6-0.2-1-0.5-1.4-0.8s-0.6-0.7-0.8-1.1s-0.3-1-0.3-1.6c0-0.8,0.1-1.5,0.4-2.1s0.7-1.1,1.2-1.5
                s1.1-0.7,1.8-0.9s1.4-0.3,2.2-0.3c1.1,0,2.1,0.2,3,0.5s1.7,0.8,2.4,1.2L102.2,15.5z"/>
            <path id="XMLID_12_" class="st1" d="M106.7,13.9V11h2.9v2.9H106.7z M106.7,27V15.5h2.9V27H106.7z"/>
            <path id="XMLID_15_" class="st1" d="M117.3,27.1c-0.8,0-1.5-0.2-2.1-0.5s-1.2-0.7-1.6-1.3c-0.5-0.5-0.8-1.2-1.1-1.9
                c-0.2-0.7-0.4-1.5-0.4-2.2c0-0.8,0.1-1.6,0.4-2.3s0.6-1.3,1.1-1.9c0.5-0.5,1-1,1.7-1.3s1.4-0.5,2.2-0.5c0.9,0,1.7,0.2,2.4,0.6
                s1.2,0.9,1.7,1.6v-2h2.6v11c0,0.9-0.2,1.6-0.5,2.3s-0.8,1.2-1.3,1.7s-1.2,0.8-2,1.1c-0.8,0.2-1.6,0.4-2.6,0.4
                c-1.3,0-2.3-0.2-3.2-0.6s-1.6-1-2.2-1.8l1.6-1.6c0.4,0.5,1,1,1.7,1.3s1.4,0.5,2.1,0.5c0.5,0,0.9-0.1,1.3-0.2
                c0.4-0.1,0.8-0.3,1.1-0.6s0.6-0.6,0.7-1c0.2-0.4,0.3-0.9,0.3-1.5V25c-0.4,0.7-0.9,1.2-1.6,1.5S118.1,27.1,117.3,27.1z M118.4,24.7
                c0.3,0,0.6-0.1,0.9-0.2c0.3-0.1,0.6-0.2,0.8-0.4s0.5-0.4,0.6-0.6c0.2-0.2,0.3-0.5,0.4-0.7V20c-0.3-0.7-0.7-1.2-1.2-1.6
                c-0.6-0.4-1.1-0.6-1.8-0.6c-0.5,0-0.9,0.1-1.2,0.3s-0.7,0.5-1,0.8s-0.5,0.7-0.6,1.1c-0.1,0.4-0.2,0.9-0.2,1.3
                c0,0.5,0.1,0.9,0.2,1.3c0.2,0.4,0.4,0.8,0.7,1.1s0.6,0.5,1,0.7C117.5,24.6,117.9,24.7,118.4,24.7z"/>
            <path id="XMLID_18_" class="st1" d="M138,27h-2.9v-6.5c0-0.9-0.2-1.6-0.5-2s-0.8-0.6-1.3-0.6c-0.3,0-0.6,0.1-0.9,0.2
                c-0.3,0.1-0.6,0.3-0.9,0.5c-0.3,0.2-0.5,0.5-0.7,0.8s-0.4,0.6-0.5,1v6.7h-3V15.5h2.7v2.1c0.4-0.7,1-1.3,1.8-1.7s1.7-0.6,2.7-0.6
                c0.7,0,1.3,0.1,1.8,0.4c0.5,0.3,0.8,0.6,1.1,1s0.4,0.9,0.5,1.5c0.1,0.5,0.1,1.1,0.1,1.7L138,27L138,27z"/>
            <path id="XMLID_20_" class="st1" d="M144.3,27.2c-0.6,0-1.1-0.1-1.6-0.3s-0.9-0.4-1.3-0.8c-0.4-0.3-0.6-0.7-0.8-1.2
                c-0.2-0.4-0.3-0.9-0.3-1.5c0-0.5,0.1-1,0.4-1.5c0.2-0.5,0.6-0.9,1-1.2s1-0.6,1.6-0.8s1.3-0.3,2-0.3c0.5,0,1,0,1.5,0.1
                s0.9,0.2,1.3,0.4v-0.7c0-0.8-0.2-1.3-0.6-1.8s-1.1-0.6-1.9-0.6c-0.6,0-1.2,0.1-1.8,0.3s-1.2,0.5-1.8,1l-0.9-1.9
                c1.5-1,3.1-1.5,4.8-1.5s2.9,0.4,3.9,1.2c0.9,0.8,1.4,2,1.4,3.5v3.6c0,0.3,0.1,0.5,0.2,0.7c0.1,0.1,0.3,0.2,0.6,0.2v2.5
                c-0.3,0.1-0.5,0.1-0.8,0.1s-0.5,0-0.6,0c-0.6,0-1-0.1-1.3-0.4c-0.3-0.3-0.5-0.6-0.5-1l-0.1-0.6c-0.5,0.7-1.1,1.2-1.9,1.5
                C145.9,27,145.1,27.2,144.3,27.2z M145.1,25.1c0.5,0,1-0.1,1.4-0.3s0.8-0.4,1-0.7c0.3-0.2,0.5-0.5,0.5-0.8V22
                c-0.4-0.1-0.7-0.2-1.1-0.3c-0.4-0.1-0.8-0.1-1.2-0.1c-0.8,0-1.4,0.2-1.9,0.5s-0.7,0.8-0.7,1.3s0.2,0.9,0.6,1.2
                C144.1,24.9,144.6,25.1,145.1,25.1z"/>
            <path id="XMLID_23_" class="st1" d="M154.3,10.9h2.9v12.2c0,0.9,0.4,1.3,1.2,1.3c0.2,0,0.3,0,0.6-0.1c0.2-0.1,0.4-0.1,0.6-0.2
                l0.4,2.4c-0.4,0.2-0.9,0.3-1.4,0.4s-1,0.2-1.4,0.2c-0.9,0-1.6-0.2-2.1-0.7s-0.8-1.2-0.8-2.1V10.9z"/>
        </g>
        <path id="XMLID_8438_" class="st0" d="M18.5,0C8.3,0,0,8.3,0,18.5C0,25,3.4,30.7,8.4,34c0.3-0.2,0.6-0.4,0.9-0.6
            c0.2-0.1,0.5-0.3,0.7-0.4c0.3-0.1,0.6-0.3,0.8-0.4c0.3-0.1,0.6-0.2,0.9-0.4c0.2-0.1,0.5-0.2,0.7-0.3c0.3-0.1,0.7-0.2,1-0.3
            s0.5-0.1,0.8-0.2c0.3-0.1,0.5-0.1,0.8-0.2s0.6-0.1,0.9-0.1l0,0c0.3,0,0.7-0.1,1-0.1l0,0v-1.2v-1v-4.1v-1V20h-1v-2h1h3h1v5.4v1.1v4.2
            v1v1.5l0,0c2.8,0.4,5.3,1.4,7.6,2.8l0,0c5.1-3.3,8.4-9,8.4-15.5C37,8.3,28.7,0,18.5,0z M24,18.5c0-3-2.5-5.5-5.5-5.5
            S13,15.5,13,18.5c0,2.1,1.2,4,3,4.9v1.1c-2.3-1-4-3.3-4-6c0-3.6,2.9-6.5,6.5-6.5s6.5,2.9,6.5,6.5c0,2.3-1.2,4.3-3,5.5v-1.2
            C23.2,21.7,24,20.2,24,18.5z M22,29.4v-1.1c4.1-1.4,7-5.3,7-9.9C29,12.7,24.3,8,18.5,8S8,12.7,8,18.5c0,4.9,3.4,9.1,8,10.2v1
            c-5.1-1.1-9-5.7-9-11.2C7,12.1,12.1,7,18.5,7S30,12.1,30,18.5C30,23.6,26.6,28,22,29.4z"/>
        </svg>
  <p id="message" class="text">An Unexpected Error Occurred</p>
  <p id="submessage" class="text">Error Code: 500</p>
  <p id="explanation" class="text">
    We track these errors automatically, but if the problem persists feel free to contact us.
  </p>
</div>
</body>
</html>
</code>```

This is insanity.  Am I not making the EXACT same request? Why does the first one return the data I want (although I don't understand how to parse it into Ruby), but the second one hits an error?

Alternatively, how do I parse the successful response from using the curl command into JSON or something my Ruby app can use?

```<code>string = `curl --include --header "Authorization: Basic Yzzzzzzzzzzzzzzzz" "https://onesignal.com/api/v1/players?app_id={XXXXXXX}&limit=300&offset=0"`
puts string
parsed = JSON.parse(string)
</code>```

Returns:

```<code>JSON::ParserError: 776: unexpected token at 'HTTP/1.1 200 OK
Date: Sat, 01 Jul 2017 20:06:17 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __yyyyyyyyyyyyyyy; expires=Sun, 01-Jul-18 20:06:17 GMT; path=/; domain=.onesignal.com; HttpOnly
Status: 200 OK
Cache-Control: max-age=0, private, must-revalidate
Access-Control-Allow-Origin: *
X-XSS-Protection: 1; mode=block
X-Request-Id: yyyyyyyyyyyy
Access-Control-Allow-Headers: SDK-Version
ETag: W/"e57da9b403c50294b432635d4ce4acfa"
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.065356
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 5.1.4
Server: cloudflare-nginx
CF-RAY: 377bfc285ebe096f-SCL

{"total_count":1,"offset":0,"limit":300,"players":[{"id":"zzzzzzzzzz","identifier":"zzzzzzzzzz","session_count":3,"language":"en","timezone":-14400,"game_version":"3","device_os":"6.0.1","device_type":1,"device_model":"LG-K240","ad_id":"zzzzzzzzzzzzz","tags":{},"last_active":1498938033,"playtime":0,"amount_spent":0.0,"created_at":1498935316,"invalid_identifier":false,"badge_count":0,"sdk":"030507","test_type":null}]}'
/Users/Me/Code/my_project/lib/tasks/scheduler.rake:57:in `block in <top (required)>'
/Users/Me/.rvm/gems/ruby-2.2.3/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => daily_notifications
(See full trace by running task with --trace)
</code>```

Edit: Curl response with --verbose

```<code>*   Trying 104.16.204.165...
* TCP_NODELAY set
* Connected to onesignal.com (104.16.204.165) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate: ssl473492.cloudflaressl.com
* Server certificate: COMODO ECC Domain Validation Secure Server CA 2
* Server certificate: COMODO ECC Certification Authority
> GET /api/v1/players?app_id=zzzzzzzzzzzzzzzzzz&limit=300&offset=0 HTTP/1.1
> Host: onesignal.com
> User-Agent: curl/7.51.0
> Accept: */*
> Authorization: Basic Yzzzzzzzzzzzzzzzzzzz
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Thu, 06 Jul 2017 13:48:54 GMT
Date: Thu, 06 Jul 2017 13:48:54 GMT
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< Set-Cookie: __cfduid=d9b57682d26de2755426b575293a211d21499348933; expires=Fri, 06-Jul-18 13:48:53 GMT; path=/; domain=.onesignal.com; HttpOnly
Set-Cookie: __cfduid=d9b57682d26de2755426b575293a211d21499348933; expires=Fri, 06-Jul-18 13:48:53 GMT; path=/; domain=.onesignal.com; HttpOnly
< Status: 200 OK
Status: 200 OK
< Cache-Control: max-age=0, private, must-revalidate
Cache-Control: max-age=0, private, must-revalidate
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
< X-Request-Id: d6276562-3cee-4c20-aa4e-5d781e7a7957
X-Request-Id: d6276562-3cee-4c20-aa4e-5d781e7a7957
< Access-Control-Allow-Headers: SDK-Version
Access-Control-Allow-Headers: SDK-Version
< ETag: W/"cef2128118655721c75aa04b81b2ce26"
ETag: W/"cef2128118655721c75aa04b81b2ce26"
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< X-Runtime: 0.019079
X-Runtime: 0.019079
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< X-Powered-By: Phusion Passenger 5.1.4
X-Powered-By: Phusion Passenger 5.1.4
< Server: cloudflare-nginx
Server: cloudflare-nginx
< CF-RAY: 37a306343f03162f-LIM
CF-RAY: 37a306343f03162f-LIM

<
* Curl_http_done: called premature == 0
* Connection #0 to host onesignal.com left intact
</code>```

答:
The only explanation is that the requests are different. First of all, I'd recommend using Faraday gem to help you with requests in Ruby. You can easily inspect Faraday object to see what went wrong. I can also see that you are passing req_options which is not part of your curl.

So I advise you to make the simplest call with Faraday, perhaps even on a different endpoint to make sure it works and then with this endpoint. If it's still not working, updating this question with Faraday request and response details would help further debug this

P.S. You should definitely not use Curl in your Ruby app.

Body:
I'm trying to get some data from the OneSignal API.

If I run it straight into the terminal (removed Auth key and App ID for this question), no problem:

$ curl --include --header "Authorization: Basic Yzzzzzzzzzzzzzzzz"
 "https://onesignal.com/api/v1/players?app_id={XXXXXXXXXXX}&limit=300&offset=0"

Returns:

{"total_count":1,"offset":0,"limit":300,"players": [{"id":"XXXXXX","identifier":"XXXXXXX","session_count":3,"language":"en","timezone":-14400,"game_version":"3","device_os":"6.0.1","device_type":1,"device_model":"LG-K240","ad_id":"XXXXXXXX","tags":{},"last_active":1498938033,"playtime":0,"amount_spent":0.0,"created_at":1498935316,"invalid_identifier":false,"badge_count":0,"sdk":"030507","test_type":null}]}

If I use what I am lead to believe using this Curl to Ruby converter is the equivalent Ruby in my rake task, instead suddenly I hit unknown errors galore:

require 'net/http'
require 'uri'

uri = URI.parse("https://onesignal.com/api/v1/players?app_id={XXXXXX}&limit=300&offset=0")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Basic Yzzzzzzzzzzzzzzzz"

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

puts response.code
puts response.body

Returns:

500
<!DOCTYPE html>

  <meta charset="UTF-8">
  <title>500 • OneSignal</title>

  <svg version="1.1" id="logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
             x="0px" y="0px"
             viewBox="0 0 160 34" style="enable-background:new 0 0 160 34;" xml:space="preserve">

        <g id="XMLID_1_">
            <path id="XMLID_2_" class="st0" d="M55.3,27.1c-1.1,0-2.1-0.2-3-0.7c-0.9-0.4-1.7-1-2.3-1.8c-0.6-0.7-1.1-1.6-1.5-2.5
                c-0.4-1-0.5-1.9-0.5-2.9s0.2-2,0.6-3s0.9-1.8,1.6-2.5s1.4-1.3,2.3-1.7s1.9-0.6,2.9-0.6c1.1,0,2.1,0.2,3,0.7s1.7,1.1,2.3,1.8
                c0.6,0.7,1.1,1.6,1.5,2.5s0.5,1.9,0.5,2.9s-0.2,2-0.6,3s-0.9,1.8-1.5,2.5c-0.7,0.7-1.4,1.3-2.3,1.7C57.3,26.9,56.3,27.1,55.3,27.1z
                 M49.5,19.2c0,0.9,0.1,1.7,0.4,2.5s0.7,1.5,1.2,2.1s1.1,1.1,1.8,1.5c0.7,0.4,1.5,0.5,2.4,0.5s1.7-0.2,2.4-0.6
                c0.7-0.4,1.3-0.9,1.8-1.5s0.9-1.3,1.2-2.1c0.3-0.8,0.4-1.6,0.4-2.4s-0.1-1.7-0.4-2.5s-0.7-1.5-1.2-2.1s-1.1-1.1-1.8-1.4
                c-0.7-0.4-1.5-0.5-2.3-0.5c-0.9,0-1.7,0.2-2.4,0.6c-0.7,0.4-1.3,0.9-1.8,1.5s-0.9,1.3-1.2,2.1C49.6,17.6,49.5,18.4,49.5,19.2z"/>
            <path id="XMLID_5_" class="st0" d="M75.5,27H74v-6.4c0-1.4-0.2-2.4-0.6-3s-1-0.9-1.8-0.9c-0.4,0-0.9,0.1-1.3,0.2
                c-0.4,0.2-0.9,0.4-1.2,0.7c-0.4,0.3-0.7,0.6-1,1s-0.5,0.8-0.6,1.3v7H66V15.5h1.3v2.6c0.2-0.4,0.5-0.8,0.9-1.1
                c0.3-0.3,0.7-0.6,1.2-0.9c0.4-0.2,0.9-0.4,1.4-0.6c0.5-0.1,1-0.2,1.5-0.2c0.6,0,1.2,0.1,1.6,0.4c0.4,0.2,0.8,0.6,1,1
                s0.5,0.9,0.6,1.6c0.1,0.6,0.2,1.3,0.2,2V27L75.5,27L75.5,27z"/>
            <path id="XMLID_7_" class="st0" d="M84.3,27.2c-0.8,0-1.6-0.2-2.3-0.5s-1.3-0.7-1.8-1.3s-0.9-1.2-1.2-1.9c-0.3-0.7-0.4-1.5-0.4-2.3
                s0.1-1.6,0.4-2.3s0.7-1.3,1.2-1.9c0.5-0.5,1.1-1,1.8-1.3c0.7-0.3,1.5-0.5,2.3-0.5s1.6,0.2,2.3,0.5c0.7,0.3,1.3,0.7,1.8,1.3
                c0.5,0.5,0.9,1.2,1.2,1.9s0.4,1.5,0.4,2.2c0,0.1,0,0.2,0,0.4c0,0.1,0,0.2,0,0.2h-9.8c0,0.6,0.2,1.2,0.4,1.7c0.2,0.5,0.5,1,0.9,1.4
                s0.8,0.7,1.3,0.9s1,0.3,1.6,0.3c0.4,0,0.8-0.1,1.1-0.2c0.4-0.1,0.7-0.2,1-0.4s0.6-0.4,0.8-0.6c0.2-0.3,0.4-0.5,0.6-0.8l1.3,0.4
                c-0.2,0.4-0.4,0.8-0.7,1.2c-0.3,0.3-0.7,0.6-1.1,0.9C87,26.8,86.5,27,86,27.1C85.3,27.2,84.8,27.2,84.3,27.2z M88.5,20.7
                c0-0.6-0.2-1.2-0.4-1.7c-0.2-0.5-0.5-0.9-0.9-1.3c-0.4-0.4-0.8-0.7-1.3-0.9s-1-0.3-1.6-0.3s-1.1,0.1-1.6,0.3s-0.9,0.5-1.3,0.9
                s-0.7,0.8-0.9,1.3c-0.2,0.5-0.4,1.1-0.4,1.7H88.5z"/>
            <path id="XMLID_10_" class="st1" d="M102.2,15.5c-0.1-0.1-0.3-0.2-0.6-0.4s-0.6-0.3-1-0.5s-0.8-0.3-1.3-0.4S98.4,14,97.9,14
                c-0.8,0-1.5,0.2-1.9,0.5s-0.6,0.7-0.6,1.3c0,0.3,0.1,0.6,0.2,0.8c0.2,0.2,0.4,0.4,0.7,0.6c0.3,0.2,0.7,0.3,1.1,0.4
                c0.4,0.1,1,0.3,1.6,0.4c0.8,0.2,1.5,0.4,2.1,0.7c0.6,0.2,1.2,0.5,1.6,0.9c0.4,0.4,0.8,0.8,1,1.3s0.4,1.1,0.4,1.8
                c0,0.8-0.2,1.6-0.5,2.1c-0.3,0.6-0.7,1.1-1.3,1.4c-0.5,0.4-1.1,0.6-1.8,0.8s-1.4,0.3-2.2,0.3c-1.2,0-2.3-0.2-3.5-0.5
                c-1.1-0.4-2.2-0.9-3.1-1.5l1.3-2.6c0.1,0.1,0.4,0.3,0.7,0.5s0.8,0.4,1.2,0.6c0.5,0.2,1,0.4,1.6,0.5s1.2,0.2,1.8,0.2
                c1.7,0,2.5-0.5,2.5-1.6c0-0.4-0.1-0.6-0.3-0.9c-0.2-0.2-0.5-0.4-0.8-0.6c-0.4-0.2-0.8-0.3-1.3-0.5c-0.5-0.1-1.1-0.3-1.7-0.5
                c-0.7-0.2-1.4-0.4-1.9-0.7c-0.6-0.2-1-0.5-1.4-0.8s-0.6-0.7-0.8-1.1s-0.3-1-0.3-1.6c0-0.8,0.1-1.5,0.4-2.1s0.7-1.1,1.2-1.5
                s1.1-0.7,1.8-0.9s1.4-0.3,2.2-0.3c1.1,0,2.1,0.2,3,0.5s1.7,0.8,2.4,1.2L102.2,15.5z"/>
            <path id="XMLID_12_" class="st1" d="M106.7,13.9V11h2.9v2.9H106.7z M106.7,27V15.5h2.9V27H106.7z"/>
            <path id="XMLID_15_" class="st1" d="M117.3,27.1c-0.8,0-1.5-0.2-2.1-0.5s-1.2-0.7-1.6-1.3c-0.5-0.5-0.8-1.2-1.1-1.9
                c-0.2-0.7-0.4-1.5-0.4-2.2c0-0.8,0.1-1.6,0.4-2.3s0.6-1.3,1.1-1.9c0.5-0.5,1-1,1.7-1.3s1.4-0.5,2.2-0.5c0.9,0,1.7,0.2,2.4,0.6
                s1.2,0.9,1.7,1.6v-2h2.6v11c0,0.9-0.2,1.6-0.5,2.3s-0.8,1.2-1.3,1.7s-1.2,0.8-2,1.1c-0.8,0.2-1.6,0.4-2.6,0.4
                c-1.3,0-2.3-0.2-3.2-0.6s-1.6-1-2.2-1.8l1.6-1.6c0.4,0.5,1,1,1.7,1.3s1.4,0.5,2.1,0.5c0.5,0,0.9-0.1,1.3-0.2
                c0.4-0.1,0.8-0.3,1.1-0.6s0.6-0.6,0.7-1c0.2-0.4,0.3-0.9,0.3-1.5V25c-0.4,0.7-0.9,1.2-1.6,1.5S118.1,27.1,117.3,27.1z M118.4,24.7
                c0.3,0,0.6-0.1,0.9-0.2c0.3-0.1,0.6-0.2,0.8-0.4s0.5-0.4,0.6-0.6c0.2-0.2,0.3-0.5,0.4-0.7V20c-0.3-0.7-0.7-1.2-1.2-1.6
                c-0.6-0.4-1.1-0.6-1.8-0.6c-0.5,0-0.9,0.1-1.2,0.3s-0.7,0.5-1,0.8s-0.5,0.7-0.6,1.1c-0.1,0.4-0.2,0.9-0.2,1.3
                c0,0.5,0.1,0.9,0.2,1.3c0.2,0.4,0.4,0.8,0.7,1.1s0.6,0.5,1,0.7C117.5,24.6,117.9,24.7,118.4,24.7z"/>
            <path id="XMLID_18_" class="st1" d="M138,27h-2.9v-6.5c0-0.9-0.2-1.6-0.5-2s-0.8-0.6-1.3-0.6c-0.3,0-0.6,0.1-0.9,0.2
                c-0.3,0.1-0.6,0.3-0.9,0.5c-0.3,0.2-0.5,0.5-0.7,0.8s-0.4,0.6-0.5,1v6.7h-3V15.5h2.7v2.1c0.4-0.7,1-1.3,1.8-1.7s1.7-0.6,2.7-0.6
                c0.7,0,1.3,0.1,1.8,0.4c0.5,0.3,0.8,0.6,1.1,1s0.4,0.9,0.5,1.5c0.1,0.5,0.1,1.1,0.1,1.7L138,27L138,27z"/>
            <path id="XMLID_20_" class="st1" d="M144.3,27.2c-0.6,0-1.1-0.1-1.6-0.3s-0.9-0.4-1.3-0.8c-0.4-0.3-0.6-0.7-0.8-1.2
                c-0.2-0.4-0.3-0.9-0.3-1.5c0-0.5,0.1-1,0.4-1.5c0.2-0.5,0.6-0.9,1-1.2s1-0.6,1.6-0.8s1.3-0.3,2-0.3c0.5,0,1,0,1.5,0.1
                s0.9,0.2,1.3,0.4v-0.7c0-0.8-0.2-1.3-0.6-1.8s-1.1-0.6-1.9-0.6c-0.6,0-1.2,0.1-1.8,0.3s-1.2,0.5-1.8,1l-0.9-1.9
                c1.5-1,3.1-1.5,4.8-1.5s2.9,0.4,3.9,1.2c0.9,0.8,1.4,2,1.4,3.5v3.6c0,0.3,0.1,0.5,0.2,0.7c0.1,0.1,0.3,0.2,0.6,0.2v2.5
                c-0.3,0.1-0.5,0.1-0.8,0.1s-0.5,0-0.6,0c-0.6,0-1-0.1-1.3-0.4c-0.3-0.3-0.5-0.6-0.5-1l-0.1-0.6c-0.5,0.7-1.1,1.2-1.9,1.5
                C145.9,27,145.1,27.2,144.3,27.2z M145.1,25.1c0.5,0,1-0.1,1.4-0.3s0.8-0.4,1-0.7c0.3-0.2,0.5-0.5,0.5-0.8V22
                c-0.4-0.1-0.7-0.2-1.1-0.3c-0.4-0.1-0.8-0.1-1.2-0.1c-0.8,0-1.4,0.2-1.9,0.5s-0.7,0.8-0.7,1.3s0.2,0.9,0.6,1.2
                C144.1,24.9,144.6,25.1,145.1,25.1z"/>
            <path id="XMLID_23_" class="st1" d="M154.3,10.9h2.9v12.2c0,0.9,0.4,1.3,1.2,1.3c0.2,0,0.3,0,0.6-0.1c0.2-0.1,0.4-0.1,0.6-0.2
                l0.4,2.4c-0.4,0.2-0.9,0.3-1.4,0.4s-1,0.2-1.4,0.2c-0.9,0-1.6-0.2-2.1-0.7s-0.8-1.2-0.8-2.1V10.9z"/>
        </g>
        <path id="XMLID_8438_" class="st0" d="M18.5,0C8.3,0,0,8.3,0,18.5C0,25,3.4,30.7,8.4,34c0.3-0.2,0.6-0.4,0.9-0.6
            c0.2-0.1,0.5-0.3,0.7-0.4c0.3-0.1,0.6-0.3,0.8-0.4c0.3-0.1,0.6-0.2,0.9-0.4c0.2-0.1,0.5-0.2,0.7-0.3c0.3-0.1,0.7-0.2,1-0.3
            s0.5-0.1,0.8-0.2c0.3-0.1,0.5-0.1,0.8-0.2s0.6-0.1,0.9-0.1l0,0c0.3,0,0.7-0.1,1-0.1l0,0v-1.2v-1v-4.1v-1V20h-1v-2h1h3h1v5.4v1.1v4.2
            v1v1.5l0,0c2.8,0.4,5.3,1.4,7.6,2.8l0,0c5.1-3.3,8.4-9,8.4-15.5C37,8.3,28.7,0,18.5,0z M24,18.5c0-3-2.5-5.5-5.5-5.5
            S13,15.5,13,18.5c0,2.1,1.2,4,3,4.9v1.1c-2.3-1-4-3.3-4-6c0-3.6,2.9-6.5,6.5-6.5s6.5,2.9,6.5,6.5c0,2.3-1.2,4.3-3,5.5v-1.2
            C23.2,21.7,24,20.2,24,18.5z M22,29.4v-1.1c4.1-1.4,7-5.3,7-9.9C29,12.7,24.3,8,18.5,8S8,12.7,8,18.5c0,4.9,3.4,9.1,8,10.2v1
            c-5.1-1.1-9-5.7-9-11.2C7,12.1,12.1,7,18.5,7S30,12.1,30,18.5C30,23.6,26.6,28,22,29.4z"/>
        </svg>

An Unexpected Error Occurred

Error Code: 500

    We track these errors automatically, but if the problem persists feel free to contact us.

This is insanity.  Am I not making the EXACT same request? Why does the first one return the data I want (although I don't understand how to parse it into Ruby), but the second one hits an error?

Alternatively, how do I parse the successful response from using the curl command into JSON or something my Ruby app can use?

string = `curl --include --header "Authorization: Basic Yzzzzzzzzzzzzzzzz" "https://onesignal.com/api/v1/players?app_id={XXXXXXX}&limit=300&offset=0"`
puts string
parsed = JSON.parse(string)

Returns:

JSON::ParserError: 776: unexpected token at 'HTTP/1.1 200 OK
Date: Sat, 01 Jul 2017 20:06:17 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __yyyyyyyyyyyyyyy; expires=Sun, 01-Jul-18 20:06:17 GMT; path=/; domain=.onesignal.com; HttpOnly
Status: 200 OK
Cache-Control: max-age=0, private, must-revalidate
Access-Control-Allow-Origin: *
X-XSS-Protection: 1; mode=block
X-Request-Id: yyyyyyyyyyyy
Access-Control-Allow-Headers: SDK-Version
ETag: W/"e57da9b403c50294b432635d4ce4acfa"
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.065356
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 5.1.4
Server: cloudflare-nginx
CF-RAY: 377bfc285ebe096f-SCL

{"total_count":1,"offset":0,"limit":300,"players":[{"id":"zzzzzzzzzz","identifier":"zzzzzzzzzz","session_count":3,"language":"en","timezone":-14400,"game_version":"3","device_os":"6.0.1","device_type":1,"device_model":"LG-K240","ad_id":"zzzzzzzzzzzzz","tags":{},"last_active":1498938033,"playtime":0,"amount_spent":0.0,"created_at":1498935316,"invalid_identifier":false,"badge_count":0,"sdk":"030507","test_type":null}]}'
/Users/Me/Code/my_project/lib/tasks/scheduler.rake:57:in `block in <top (required)>'
/Users/Me/.rvm/gems/ruby-2.2.3/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => daily_notifications
(See full trace by running task with --trace)

Edit: Curl response with --verbose

*   Trying 104.16.204.165...
* TCP_NODELAY set
* Connected to onesignal.com (104.16.204.165) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate: ssl473492.cloudflaressl.com
* Server certificate: COMODO ECC Domain Validation Secure Server CA 2
* Server certificate: COMODO ECC Certification Authority
> GET /api/v1/players?app_id=zzzzzzzzzzzzzzzzzz&limit=300&offset=0 HTTP/1.1
> Host: onesignal.com
> User-Agent: curl/7.51.0
> Accept: */*
> Authorization: Basic Yzzzzzzzzzzzzzzzzzzz
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Thu, 06 Jul 2017 13:48:54 GMT
Date: Thu, 06 Jul 2017 13:48:54 GMT
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< Set-Cookie: __cfduid=d9b57682d26de2755426b575293a211d21499348933; expires=Fri, 06-Jul-18 13:48:53 GMT; path=/; domain=.onesignal.com; HttpOnly
Set-Cookie: __cfduid=d9b57682d26de2755426b575293a211d21499348933; expires=Fri, 06-Jul-18 13:48:53 GMT; path=/; domain=.onesignal.com; HttpOnly
< Status: 200 OK
Status: 200 OK
< Cache-Control: max-age=0, private, must-revalidate
Cache-Control: max-age=0, private, must-revalidate
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
< X-Request-Id: d6276562-3cee-4c20-aa4e-5d781e7a7957
X-Request-Id: d6276562-3cee-4c20-aa4e-5d781e7a7957
< Access-Control-Allow-Headers: SDK-Version
Access-Control-Allow-Headers: SDK-Version
< ETag: W/"cef2128118655721c75aa04b81b2ce26"
ETag: W/"cef2128118655721c75aa04b81b2ce26"
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< X-Runtime: 0.019079
X-Runtime: 0.019079
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< X-Powered-By: Phusion Passenger 5.1.4
X-Powered-By: Phusion Passenger 5.1.4
< Server: cloudflare-nginx
Server: cloudflare-nginx
< CF-RAY: 37a306343f03162f-LIM
CF-RAY: 37a306343f03162f-LIM

<
* Curl_http_done: called premature == 0
* Connection #0 to host onesignal.com left intact


问:
Can I use Thread.Sleep when the loading spinner and the error message has the same element xpath?
This is the logic I am trying to implement. I press a tab in a page and if there is an error message, I System.out.println a custom error message to the console. If the error message does not occur, I proceed with other functionalities.

The problem is after I click the tab, there is a spinner that loads before loading the data. Xpath for the spinner and error message is the same. So, When the WebDriver sees the spinner, it identifies it as an error and gives me an error message.

When I add a Thread.Sleep in between, then it identifies the loaded section and is not giving me the error message.

Apart from using Thread.sleep, can I do anything to wait until the data loads properly after the spinner?

```<code>    private Boolean BenInErr() throws InterruptedException
{
    try {
        Thread.sleep(4000);
        WebDriverWait BErr = new WebDriverWait (driver, 10);
        WebElement BErrText = driver.findElement(By.xpath("//div[@id='plan-details-benefits-and-cost-content']/div/services-list/div/mc-loading-error/div/div/span"));
        //String Text = BErrText.getText();
        BErr.until(ExpectedConditions.visibilityOf(BErrText));
        return BErrText.isDisplayed();
    }

    catch (Exception Ex1)
    {
        System.out.println("Benefit information is available");
        return false;
    }
}

public void mngBenInfErr() throws InterruptedException
{
 if (BenInErr())
{
    System.out.println("There is an error in Benefits & Coverage tab in Benefit information section");
}
}
</code>```

答:
I would suggest to write a wait method for this, later you can reuse it, for example:</p>

```<code>    public static void waitForLoaderToDisappear() {
    _wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id(YOURLOADERID)));
}
</code>```

Body:
This is the logic I am trying to implement. I press a tab in a page and if there is an error message, I System.out.println a custom error message to the console. If the error message does not occur, I proceed with other functionalities.

The problem is after I click the tab, there is a spinner that loads before loading the data. Xpath for the spinner and error message is the same. So, When the WebDriver sees the spinner, it identifies it as an error and gives me an error message.

When I add a Thread.Sleep in between, then it identifies the loaded section and is not giving me the error message.

Apart from using Thread.sleep, can I do anything to wait until the data loads properly after the spinner?

    private Boolean BenInErr() throws InterruptedException
{
    try {
        Thread.sleep(4000);
        WebDriverWait BErr = new WebDriverWait (driver, 10);
        WebElement BErrText = driver.findElement(By.xpath("//div[@id='plan-details-benefits-and-cost-content']/div/services-list/div/mc-loading-error/div/div/span"));
        //String Text = BErrText.getText();
        BErr.until(ExpectedConditions.visibilityOf(BErrText));
        return BErrText.isDisplayed();
    }

    catch (Exception Ex1)
    {
        System.out.println("Benefit information is available");
        return false;
    }
}

public void mngBenInfErr() throws InterruptedException
{
 if (BenInErr())
{
    System.out.println("There is an error in Benefits & Coverage tab in Benefit information section");
}
}

Body:
I would suggest to write a wait method for this, later you can reuse it, for example:

    public static void waitForLoaderToDisappear() {
    _wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id(YOURLOADERID)));
}


问:
Calculate vacation days accumulated
I have a 2007 MS Access database that I use and I want to add a subform that shows vacation calculations based on the employee among other things. I have a module I use that I found on the net that calculates the elapsed time between two dates and gives a result like 1 Year 2 Months 3 Days or 2 Years ect. I need to have the result give me vacation weeks instead of years, months and days. in my query it will be based on [DateOfHire] and Date()

1 year Service = 1 week vacation

2 year Service = 2 week vacation

8 year Service = 3 week vacation

15 year Service = 4 week vacation

25 year Service = 5 week vacation

-

```<code>Public Function fElapsedTimeYMD(varStartDate As Variant, varEndDate) As String

    Dim dtToday As Date
    Dim intStartYear As Integer, intStartMonth As Integer, intStartDay As Integer
    Dim intEndYear As Integer, intEndMonth As Integer, intEndDay As Integer
    Dim intTmpYear As Integer, intTmpMonth As Integer, intTmpDay As Integer
    Dim strYear As String, strMonth As String, strDay As String
    Dim sngLeap As Single

    If Not IsDate(varStartDate) Or Not IsDate(varEndDate) Then Exit Function

    dtToday = Date
    intStartYear = Year(varStartDate)
    intStartMonth = Month(varStartDate)
    intStartDay = Day(varStartDate)
    intEndYear = Year(varEndDate)
    intEndMonth = Month(varEndDate)
    intEndDay = Day(varEndDate)

    If intStartDay > intEndDay Then
        Select Case intEndMonth
        Case Is = 1
            intEndDay = intEndDay + 31
            intEndMonth = 12
            intEndYear = intEndYear - 1
        Case Is = 2    ' Check for Leap Year
            If varStartDate = DateSerial(intEndYear, 2, 29) Then
                intEndDay = intEndDay + 29
                intEndMonth = intEndMonth - 1
            Else
                intEndDay = intEndDay + 28
                intEndMonth = intEndMonth - 1
            End If
        Case Is = 4, 6, 9, 11
            intEndDay = intEndDay + 30
            intEndMonth = intEndMonth - 1
        Case Is = 3, 5, 7, 8, 10, 12
            intEndDay = intEndDay + 31
            intEndMonth = intEndMonth - 1
        End Select
    End If

    If intStartMonth > intEndMonth Then
        Select Case intEndMonth
        Case Is = 1
            intEndMonth = 13
            intEndYear = intEndYear - 1
        Case Else
            intEndMonth = intEndMonth + 12
            intEndYear = intEndYear - 1
        End Select
    End If

    intTmpYear = intEndYear - intStartYear
    intTmpMonth = intEndMonth - intStartMonth
    intTmpDay = intEndDay - intStartDay

    Select Case intTmpYear
    Case Is = 0
        strYear = ""
    Case Is = 1
        strYear = Trim(Str(intTmpYear)) & " Year"
    Case Else
        strYear = Trim(Str(intTmpYear)) & " Years"
    End Select

    Select Case intTmpMonth
    Case Is = 0
        strMonth = ""
    Case Is = 1
        strMonth = Trim(Str(intTmpMonth)) & " Month"
    Case Else
        strMonth = Trim(Str(intTmpMonth)) & " Months"
    End Select

    Select Case intTmpDay
    Case Is = 0
        strDay = ""
    Case Is = 1
        strDay = Trim(Str(intTmpDay)) & " Day"
    Case Else
        strDay = Trim(Str(intTmpDay)) & " Days"
    End Select

    fElapsedTimeYMD = Trim(strYear & " " & strMonth & " " & strDay)

End Function
</code>```

Title: Calculate vacation days accumulated

Body:
I have a 2007 MS Access database that I use and I want to add a subform that shows vacation calculations based on the employee among other things. I have a module I use that I found on the net that calculates the elapsed time between two dates and gives a result like 1 Year 2 Months 3 Days or 2 Years ect. I need to have the result give me vacation weeks instead of years, months and days. in my query it will be based on [DateOfHire] and Date()

1 year Service = 1 week vacation

2 year Service = 2 week vacation

8 year Service = 3 week vacation

15 year Service = 4 week vacation

25 year Service = 5 week vacation

-

Public Function fElapsedTimeYMD(varStartDate As Variant, varEndDate) As String

    Dim dtToday As Date
    Dim intStartYear As Integer, intStartMonth As Integer, intStartDay As Integer
    Dim intEndYear As Integer, intEndMonth As Integer, intEndDay As Integer
    Dim intTmpYear As Integer, intTmpMonth As Integer, intTmpDay As Integer
    Dim strYear As String, strMonth As String, strDay As String
    Dim sngLeap As Single

    If Not IsDate(varStartDate) Or Not IsDate(varEndDate) Then Exit Function

    dtToday = Date
    intStartYear = Year(varStartDate)
    intStartMonth = Month(varStartDate)
    intStartDay = Day(varStartDate)
    intEndYear = Year(varEndDate)
    intEndMonth = Month(varEndDate)
    intEndDay = Day(varEndDate)

    If intStartDay > intEndDay Then
        Select Case intEndMonth
        Case Is = 1
            intEndDay = intEndDay + 31
            intEndMonth = 12
            intEndYear = intEndYear - 1
        Case Is = 2    ' Check for Leap Year
            If varStartDate = DateSerial(intEndYear, 2, 29) Then
                intEndDay = intEndDay + 29
                intEndMonth = intEndMonth - 1
            Else
                intEndDay = intEndDay + 28
                intEndMonth = intEndMonth - 1
            End If
        Case Is = 4, 6, 9, 11
            intEndDay = intEndDay + 30
            intEndMonth = intEndMonth - 1
        Case Is = 3, 5, 7, 8, 10, 12
            intEndDay = intEndDay + 31
            intEndMonth = intEndMonth - 1
        End Select
    End If

    If intStartMonth > intEndMonth Then
        Select Case intEndMonth
        Case Is = 1
            intEndMonth = 13
            intEndYear = intEndYear - 1
        Case Else
            intEndMonth = intEndMonth + 12
            intEndYear = intEndYear - 1
        End Select
    End If

    intTmpYear = intEndYear - intStartYear
    intTmpMonth = intEndMonth - intStartMonth
    intTmpDay = intEndDay - intStartDay

    Select Case intTmpYear
    Case Is = 0
        strYear = ""
    Case Is = 1
        strYear = Trim(Str(intTmpYear)) & " Year"
    Case Else
        strYear = Trim(Str(intTmpYear)) & " Years"
    End Select

    Select Case intTmpMonth
    Case Is = 0
        strMonth = ""
    Case Is = 1
        strMonth = Trim(Str(intTmpMonth)) & " Month"
    Case Else
        strMonth = Trim(Str(intTmpMonth)) & " Months"
    End Select

    Select Case intTmpDay
    Case Is = 0
        strDay = ""
    Case Is = 1
        strDay = Trim(Str(intTmpDay)) & " Day"
    Case Else
        strDay = Trim(Str(intTmpDay)) & " Days"
    End Select

    fElapsedTimeYMD = Trim(strYear & " " & strMonth & " " & strDay)

End Function


问:
Laravel 4 is not reading env file
At first, this is not duplicate. I've already tried the next and any of them worked:

Laravel 5.2 not reading env file

Laravel 5.2 is not reading from .env on ubuntu

Laravel env file is not loading

Laravel 4 with forge, environment variables issue

I'm using Mac and Homestead on Virtual Box to virtualize Laravel 4.

What I did:

Download the project from the repository

composer install and composer dump-autoload within vm

set up env file

set up homestead.yaml and /etc/hosts

vagrant halt / vagrant up --provision

This is the error:
https://i.gyazo.com/77effc81c4b99b40d1b8b3c0b41d9f6d.png (I'm not allowed to add images blablabla...)

So I decided to remove and create env file again. I checked my version of php, environment and hostname and all of them are right...

If you need further information just let me know. Thanks for everyone in advance.

EDIT: Obviously I tried every solution suggested in the previous Stackoverflow questions posted.

答:
I finally solved it. It was some shit about env file and PhpStorm. I removed the env file and created again with sublime text, wrote manually all keys and values and it worked!!!

Thank you for Shahzaib Sheikh help.

Title: Laravel 4 is not reading env file


问:
How do I select rows from a DataFrame based on column values?
How can I select rows from a DataFrame based on values in some column in Pandas?

In SQL, I would use:

SELECT *
FROM table
WHERE column_name = some_value
```

答:
Faster results can be achieved using numpy.where.

For example, with unubtu's setup -

```<code>In [76]: df.iloc[np.where(df.A.values=='foo')]
Out[76]:
     A      B  C   D
0  foo    one  0   0
2  foo    two  2   4
4  foo    two  4   8
6  foo    one  6  12
7  foo  three  7  14
</code>```

Timing comparisons:

```<code>In [68]: %timeit df.iloc[np.where(df.A.values=='foo')]  # fastest
1000 loops, best of 3: 380 µs per loop

In [69]: %timeit df.loc[df['A'] == 'foo']
1000 loops, best of 3: 745 µs per loop

In [71]: %timeit df.loc[df['A'].isin(['foo'])]
1000 loops, best of 3: 562 µs per loop

In [72]: %timeit df[df.A=='foo']
1000 loops, best of 3: 796 µs per loop

In [74]: %timeit df.query('(A=="foo")')  # slowest
1000 loops, best of 3: 1.71 ms per loop
</code>```

ContentLicense: CC BY-SA 4.0

Body:
Faster results can be achieved using numpy.where.

For example, with unubtu's setup -

In [76]: df.iloc[np.where(df.A.values=='foo')]
Out[76]:
     A      B  C   D
0  foo    one  0   0
2  foo    two  2   4
4  foo    two  4   8
6  foo    one  6  12
7  foo  three  7  14

Timing comparisons:

In [68]: %timeit df.iloc[np.where(df.A.values=='foo')]  # fastest
1000 loops, best of 3: 380 µs per loop

In [69]: %timeit df.loc[df['A'] == 'foo']
1000 loops, best of 3: 745 µs per loop

In [71]: %timeit df.loc[df['A'].isin(['foo'])]
1000 loops, best of 3: 562 µs per loop

In [72]: %timeit df[df.A=='foo']
1000 loops, best of 3: 796 µs per loop

In [74]: %timeit df.query('(A=="foo")')  # slowest
1000 loops, best of 3: 1.71 ms per loop


问:
Change Background Color with jQuery
I have a form with multiple drop downs... I would like to set the background color of the visible dropdowns to gray when they are disabled. All of these dropdown's id's begin with usrControl. Here is what I have this far..

```<code>    $('select[id ^= "usrControl"]:visible').each(function(){
this.css("background-color")
});
</code>```

Not sure how to get the disabled/enabled selectors.

Thanks in advance

```<code>Protected _picklistColorScriptText As String = "$(document).ready(function(){ " + _
                                                "$('[id ^= ""usrControl""]:visible:disabled').css(""background-color"", '#DCDCDC'); " + _
                                                "$('[id ^= ""usrControl""]:visible:enabled').css(""background-color"", '#FFFFFF');" + _
                                                "});"
</code>```

This works. However, this sets the background for the entire control to gray, how can I change the color of the selected item to gray?

答:
You can use the :disabled pseudo-selector. Plus you don't need jQuery.each. Just work against the returned nodeset.

```<code>$('select[id ^= "usrControl"]:visible:disabled').css("background-color", 'gray');
</code>```

Working example here: http://jsfiddle.net/Cwm4W/

UPDATE: Responding to OP's clarification below, you can simply select the contained option like so:

```<code>$('select[id ^= "usrControl"]:visible:disabled option').css("background-color", 'gray');
</code>```

Working example here: http://jsfiddle.net/Cwm4W/1/

Title: Change Background Color with jQuery

Body:
I have a form with multiple drop downs... I would like to set the background color of the visible dropdowns to gray when they are disabled. All of these dropdown's id's begin with usrControl. Here is what I have this far..

    $('select[id ^= "usrControl"]:visible').each(function(){
this.css("background-color")
});

Not sure how to get the disabled/enabled selectors.

Thanks in advance

Protected _picklistColorScriptText As String = "$(document).ready(function(){ " + _
                                                "$('[id ^= ""usrControl""]:visible:disabled').css(""background-color"", '#DCDCDC'); " + _
                                                "$('[id ^= ""usrControl""]:visible:enabled').css(""background-color"", '#FFFFFF');" + _
                                                "});"

This works. However, this sets the background for the entire control to gray, how can I change the color of the selected item to gray?

Body:
You can use the :disabled pseudo-selector. Plus you don't need jQuery.each. Just work against the returned nodeset.

$('select[id ^= "usrControl"]:visible:disabled').css("background-color", 'gray');

Working example here: http://jsfiddle.net/Cwm4W/

UPDATE: Responding to OP's clarification below, you can simply select the contained option like so:

$('select[id ^= "usrControl"]:visible:disabled option').css("background-color", 'gray');

Working example here: http://jsfiddle.net/Cwm4W/1/