答:
Try this:

```<code>String input = File.ReadAllText( @"c:\myfile.txt" );

int i = 0, j = 0;
int[,] res = new int[10, 10];
foreach (var row in input.Split('\n'))
{
   j = 0;
   foreach (var col in row.Trim().Split(' '))
   {
       res[i, j] = int.Parse(col.Trim());
       j++;
   }
   i++;
}
</code>```

If that dint work you also have an alternative:

```<code>int[][] list = File.ReadAllLines("myfile.txt")
               .Select(l => l.Split(',').Select(i => int.Parse(i)).ToArray())
               .ToArray();
</code>```

Title: Read 2D matrix from file to 2D int array in C#

Body:
I have problem in reading 2D text from file and import it to an int array. Specifically, my text file looks like below:

2,3,4,5,6

5,2,3,4,5

2,4,6,7,4

2,7,8,5,6

So each cell in matrix is separated by comma and each new row starts with new line.

I tried many ways to make it works but I can't! Simply, I want an int[][] or int[,] array at the end.

P.S: I can read 1-D matrix simply to int[] as below:

int[] array= File.ReadAllText(fileppath).Split(',').Select(t => int.Parse(t)).ToArray();

Body:
Try this:

String input = File.ReadAllText( @"c:\myfile.txt" );

int i = 0, j = 0;
int[,] res = new int[10, 10];
foreach (var row in input.Split('\n'))
{
   j = 0;
   foreach (var col in row.Trim().Split(' '))
   {
       res[i, j] = int.Parse(col.Trim());
       j++;
   }
   i++;
}

If that dint work you also have an alternative:

int[][] list = File.ReadAllLines("myfile.txt")
               .Select(l => l.Split(',').Select(i => int.Parse(i)).ToArray())
               .ToArray();


来源: stackexchange

问:
How to retrieve data from chrome's network console tool
This is captured from chrome's developer console

Based from the attached image, is it actually possible to retrieve the data in javascript/Node.js?

I've had already looked into Firefox's documentation for performance.getEntries() and it displays were performance results, none of them captured the containing data/responses .

Doing something like

```<code>return performance.getEntries();

or

return performance.getEntriesByType("resource");
</code>```

will return a json formatted lists, none of them contains the data needed to be extracted.

答: It seems to me that it is a ajax request, if you can set a hook of all the ajax request, then you can store and retrieve them. You can do this by type code on chrome's console, and the code you may need is here: Add a "hook" to all AJAX requests on a page. Basically it rewrite the XMLHttpRequest.prototype.send method to do what you need.</p>

ContentLicense: CC BY-SA 3.0

Body:
This is captured from chrome's developer console

Based from the attached image, is it actually possible to retrieve the data in javascript/Node.js?

I've had already looked into Firefox's documentation for performance.getEntries() and it displays were performance results, none of them captured the containing data/responses .

Doing something like

return performance.getEntries();

or

return performance.getEntriesByType("resource");

will return a json formatted lists, none of them contains the data needed to be extracted.


问:
iis express - cant get ssl to work in visual studio 2015
Im trying to get my website to run under https but for some reason IIS express wont play ball.  I have SSL enabled set to true, anonymous authentication is disabled and ive pasted the https url into the project url section.  Whenever I start the app it runs under standard http.  Is there something im missing in the setings ?</p>

答:
Please see if this helps: http://codehotfix.com/enabling-ssl-with-iis-express-in-visual-studio-express-for-web/

Select the startup project and press F4 (the function key) this will open the property window.

To enable the SSL with in IIS Express, you have to just set “SSL Enabled = true” in the project properties.

Once you change the value, Visual Studio set in automatic the SSL URL, e.g., https://localhost:44301/

Copy SSL URL. Go to the Advance properties by pressing Alt+Enter, select the Web tab and set the Project URL with the same value of SSL URL, e.g., https://localhost:44301/

Now you have configured the default URL of the web application, we can run the site (F5 or CTRL + F5).PS: The first time you set the secure protocol on IIS Express, you will be prompted to install the certificate for SSL.


问:
c# ListView cross thread, delegate not working
Trying to make a cross thread log to ListView

```<code>private enum LogType {Info, Error, Warning};
private delegate void AddItemCallback(string line, LogType lt);

private void LogAddInfo(string line, LogType lt)
{

    if (lvLog.InvokeRequired)
    {
        AddItemCallback d = new AddItemCallback(LogAddInfo);
        this.Invoke(d, new { line, lt }); // <-- here is the problem
    }
    else
    {
        // code that adds item to listView (in this case $o)
        lvLog.Items.Add(new ListViewItem(DateTime.Now.ToString(" HH:mm:ss ") + line, (int)lt));
    }

}
</code>```

This will give a parameter count mismatch. How to declare the new object properly?
Thank you in advance,

答:
You can also just use an anonymous delegate and a recursive call like this:</p>

```<code>    private void LogAddInfo(string line, LogType lt)
    {
        if (lvLog.InvokeRequired)
        {
           lvLog.Invoke((MethodInvoker)delegate ()
           {
               this.LogAddInfo(line, lt);
           });
        }
        else
        {
            // code that adds item to listView (in this case $o)
            lvLog.Items.Add(new ListViewItem(DateTime.Now.ToString(" HH:mm:ss ") + line, (int)lt));
        }
    }
</code>```

Body:
Trying to make a cross thread log to ListView

private enum LogType {Info, Error, Warning};
private delegate void AddItemCallback(string line, LogType lt);

private void LogAddInfo(string line, LogType lt)
{

    if (lvLog.InvokeRequired)
    {
        AddItemCallback d = new AddItemCallback(LogAddInfo);
        this.Invoke(d, new { line, lt }); // <-- here is the problem
    }
    else
    {
        // code that adds item to listView (in this case $o)
        lvLog.Items.Add(new ListViewItem(DateTime.Now.ToString(" HH:mm:ss ") + line, (int)lt));
    }

}

This will give a parameter count mismatch. How to declare the new object properly?
Thank you in advance,

Body:
You can also just use an anonymous delegate and a recursive call like this:

    private void LogAddInfo(string line, LogType lt)
    {
        if (lvLog.InvokeRequired)
        {
           lvLog.Invoke((MethodInvoker)delegate ()
           {
               this.LogAddInfo(line, lt);
           });
        }
        else
        {
            // code that adds item to listView (in this case $o)
            lvLog.Items.Add(new ListViewItem(DateTime.Now.ToString(" HH:mm:ss ") + line, (int)lt));
        }
    }


问:
Dynamic Variable Properties
I'm generating a variable in a foreach loop that's name is dynamic and I need to set properties

```<code>$variableName = "res" + $i
New-Variable -Name $variableName -Value New-Object System.Windows.Forms.Label
</code>```

And then I need to add the properties, but just using

```<code>$variableName.text = "ipsum"
</code>```

Would set the property of $variableName and not the created variable.

答:
You should be able to use the Get-Variable cmdlet to do this with the -ValueOnly parameter so that you get the variable returned and not an object that contains properties about the variable:

```<code>(Get-Variable $variableName -ValueOnly).text = "ipsum"
</code>```

Note there was also a bug in your code, in that:

```<code>New-Variable -Name $variableName -Value New-Object System.Windows.Forms.Label
</code>```

Needs to be:

```<code>New-Variable -Name $variableName -Value (New-Object System.Windows.Forms.Label)
</code>```

Screenshot:

Title: Dynamic Variable Properties

Body:
I'm generating a variable in a foreach loop that's name is dynamic and I need to set properties

$variableName = "res" + $i
New-Variable -Name $variableName -Value New-Object System.Windows.Forms.Label

And then I need to add the properties, but just using

$variableName.text = "ipsum"

Would set the property of $variableName and not the created variable.

Body:
You should be able to use the Get-Variable cmdlet to do this with the -ValueOnly parameter so that you get the variable returned and not an object that contains properties about the variable:

(Get-Variable $variableName -ValueOnly).text = "ipsum"

Note there was also a bug in your code, in that:

New-Variable -Name $variableName -Value New-Object System.Windows.Forms.Label

Needs to be:

New-Variable -Name $variableName -Value (New-Object System.Windows.Forms.Label)

Screenshot:


问:
using indexers in c# to get values from struct
I have defined a struct as follows:

```<code>using System;
using System.Collections.Generic;
public struct PacketPenetration
{
    private Dictionary<double, double[,]> penetration;
    public PacketPenetration(Dictionary<double, double[,]> penetration)
    {
        this.penetration = penetration;
    }

    public Dictionary<double, double[,]> Penetration { get { return penetration; } }

    public double this[double index1, int index2, int index3]
    {
        get
        {
            return this.penetration[index1][index2,index3];
        }
    }
}
</code>```

and instantiated like this:

```<code>var penetration = new PacketPenetration();
</code>```

my goal is to be able to add items to penetration and be able to get values from it using the indexer defined in the struct. However The following line of code does not work:

```<code>penetration.Add(3.5, testArray);
</code>```

testArray is a double[,]
Where is the problem?

答:
It does not work because your PacketPenetration doesn't have the method Add.

Your indexer is configured for get-only and moreover having indexer does not make the class implement miraculously the method Add.

How about adding an Add method to PacketPenetration:

```<code>    public void Add(double index , double[,] array)
    {
        penetration.Add(index, array);
    }
</code>```

If you really need to pass through the indexer you can add the following :

```<code>    public double[,] this[double index1, double [,] array]
    {
        set
        {
            this.penetration[index1] = value;
        }
    }
</code>```

Then :

```<code>  penetration[3.5] =  testArray;
</code>```

Body:
I have defined a struct as follows:

using System;
using System.Collections.Generic;
public struct PacketPenetration
{
    private Dictionary<double, double[,]> penetration;
    public PacketPenetration(Dictionary<double, double[,]> penetration)
    {
        this.penetration = penetration;
    }

    public Dictionary<double, double[,]> Penetration { get { return penetration; } }

    public double this[double index1, int index2, int index3]
    {
        get
        {
            return this.penetration[index1][index2,index3];
        }
    }
}

and instantiated like this:

var penetration = new PacketPenetration();

my goal is to be able to add items to penetration and be able to get values from it using the indexer defined in the struct. However The following line of code does not work:

penetration.Add(3.5, testArray);

testArray is a double[,]
Where is the problem?

Body:
It does not work because your PacketPenetration doesn't have the method Add.

Your indexer is configured for get-only and moreover having indexer does not make the class implement miraculously the method Add.

How about adding an Add method to PacketPenetration:

    public void Add(double index , double[,] array)
    {
        penetration.Add(index, array);
    }

If you really need to pass through the indexer you can add the following :

    public double[,] this[double index1, double [,] array]
    {
        set
        {
            this.penetration[index1] = value;
        }
    }

Then :

  penetration[3.5] =  testArray;


问:
JQuery UI Autocomplete WebService Source returning JSON
I have been trying for two months to get this code working, and I am close, but still confused. I want the JQuery UI Autocomplete function to call an web service which returns JSON data and display that data for selection, and on selection put the selected value into a hidden field.

There are several issues:
1) The autocomplete function is not firing
2) The source: "/AutoSuggest.asmx/DOTFind?" line throws an invalid object exception
3) The service requires two parameters: (string prefixText, int count) - count tells it how many records to return.
4) I am not at all certain that this code will accept JSON data that comes back from the service

Here is the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

    Untitled Page

```<code><script type="text/javascript">
    if ($) {
        $(document).ready(
                function() {
                    $('h4').addClass('tmpFrameworkLoaded');
                    $('h4').text('jQuery successfully loaded and running!');
                }
            );
    }

</script>

<style>
    .ui-autocomplete-loading
    {
        background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
    }
</style>
<div id="divDOTJQuery" runat="server">

    <script type="text/javascript">
        $(function() {
            function log(message) {
                alert(message);
                $("<div/").text(message).prependTo("#log");
                $("#log").attr("scrollTop", 0);
            }
        });

        $("#dotmatch").autocomplete({
            source: "/AutoSuggest.asmx/DOTFind?",
            minLength: 2,
            select: function(event, ui) {
                log(ui.item ?
                    "Selected: " + ui.item.value + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value);
            }
        });
    </script>

    <div class="ui-widget">
        DOT Job Title or #:
        <input type="text" id="dotmatch" />
        <input type="hidden" id="DOTNumber" name="DOTNumber" />
    </div>
    <div class="ui-widget" style="margin-top: 2em; font-family: Arial">
        Results:<br />
        <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content">
        </div>
    </div>
</div>
</form>
</code>```

and here is the web service:

```<code>[WebMethod(BufferResponse = true, Description = "Lookup a DOT record using part of DOT Number or DOT Title")]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string DOTFind(string prefixText, int count)
{
    if (count == 0)
    {
        count = 10;
    }
    DOT D = new DOT();

    DataView DV = D.View(prefixText, count);
    List<DOT> items = new List<DOT>();
    foreach (DataRow DR in DV.Table.Rows)
    {
        items.Add(new DOT(SQL.ColumnToString(DR, "DOTNumber").Trim(),SQL.ColumnToString(DR, "JobTitle").Trim()));
    }
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
    MemoryStream ms = new MemoryStream();
    serializer.WriteObject(ms, items);
    string jsonString = Encoding.Default.GetString(ms.ToArray());
    ms.Close();
    return jsonString;
}
</code>```

I would deeply appreciate any help with this that you can offer.

Thanks,

Bob

答:
autocomplete uses JSONP, NOT JSON,

so add parameter callback=?, or anything you like

```<code>$("#dotmatch").autocomplete({
    source: "/AutoSuggest.asmx/DOTFind?callback=?",
    minLength: 2,
    select: function(event, ui) {
        log(ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value);
    }
});
</code>```

In a webservice try wrap JSON into callback_value(YOUR_JSON);

But I'am not sure about get parameters in WebMethods, so you can use Generic Handler (ashx) instead.

ContentLicense: CC BY-SA 2.5

Body:
I have been trying for two months to get this code working, and I am close, but still confused. I want the JQuery UI Autocomplete function to call an web service which returns JSON data and display that data for selection, and on selection put the selected value into a hidden field.

There are several issues:
1) The autocomplete function is not firing
2) The source: "/AutoSuggest.asmx/DOTFind?" line throws an invalid object exception
3) The service requires two parameters: (string prefixText, int count) - count tells it how many records to return.
4) I am not at all certain that this code will accept JSON data that comes back from the service

Here is the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

    Untitled Page

        DOT Job Title or #:
        <input type="text" id="dotmatch" />
        <input type="hidden" id="DOTNumber" name="DOTNumber" />

        Results:

</form>

and here is the web service:

[WebMethod(BufferResponse = true, Description = "Lookup a DOT record using part of DOT Number or DOT Title")]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string DOTFind(string prefixText, int count)
{
    if (count == 0)
    {
        count = 10;
    }
    DOT D = new DOT();

    DataView DV = D.View(prefixText, count);
    List<DOT> items = new List<DOT>();
    foreach (DataRow DR in DV.Table.Rows)
    {
        items.Add(new DOT(SQL.ColumnToString(DR, "DOTNumber").Trim(),SQL.ColumnToString(DR, "JobTitle").Trim()));
    }
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
    MemoryStream ms = new MemoryStream();
    serializer.WriteObject(ms, items);
    string jsonString = Encoding.Default.GetString(ms.ToArray());
    ms.Close();
    return jsonString;
}

I would deeply appreciate any help with this that you can offer.

Thanks,

Bob

Body:
autocomplete uses JSONP, NOT JSON,

so add parameter callback=?, or anything you like

$("#dotmatch").autocomplete({
    source: "/AutoSuggest.asmx/DOTFind?callback=?",
    minLength: 2,
    select: function(event, ui) {
        log(ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value);
    }
});

In a webservice try wrap JSON into callback_value(YOUR_JSON);

But I'am not sure about get parameters in WebMethods, so you can use Generic Handler (ashx) instead.


问:
Channel data properties : Carousel?
I want to get media from a website. That media should be listed something like Carousel card template.

With loop i want to store all the media in one object.

Have this :

```<code> resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments = new List<Attachment>();
                var fbObject = new object[activities.Count];
    while (!stop)
    {
     if (activities[counter].MediaTypeValue != (int)MediaTypeEnum.Video)
                        {
                            fbObject[counter] = new
                            {
                                type = "image",
                                payload = new object[]
                                {
                                        new
                                        {
                                           url = activities[counter].DocumentPath
                                        },
                                }
                            };
                        }
                        else
                        {
                            fbObject[counter] = new
                            {
                                type = "video",
                                buttons = new object[]
                                {
                                        new
                                        {
                                            type = "web_url",
                                            url = activities[counter].DocumentPath,
                                            title = activities[counter].FirstName + " " + activities[counter].LastName + " posted " + BotHelper.UserPosted(activities[counter].MediaTypeValue),
                                             webview_height_ratio = "compact",
                                            messenger_extensions = true
                                        }
                                }
                            };
                        }
  counter--;
                    if (counter < 0)
                        stop = true;

    }

 resultMessage.ChannelData = JObject.FromObject(new { fbObject }); ;
                await context.PostAsync(resultMessage);
</code>```

But Facebook messenger does not render it as "carousel".

Any idea how to show object like Carousel type of card ?

答:
Facebook will render the carousel if you have Attachments in your message. Your attachments collection is empty and you are sending channel data info, which won't be rendered as a carousel.

Both Image and Video are supported attachments in BotFramework and you can just use the available rich cards instead of using channel data to send them to the user.

Take a look to the RichCards sample to understand how to create each of the supported cards. Also, you might also want to review the Carousel sample.

Finally, it's always a good idea to review the documentation around attachments and Rich cards. See this and this.

Title: Channel data properties : Carousel?

Body:
I want to get media from a website. That media should be listed something like Carousel card template.

With loop i want to store all the media in one object.

Have this :

 resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments = new List<Attachment>();
                var fbObject = new object[activities.Count];
    while (!stop)
    {
     if (activities[counter].MediaTypeValue != (int)MediaTypeEnum.Video)
                        {
                            fbObject[counter] = new
                            {
                                type = "image",
                                payload = new object[]
                                {
                                        new
                                        {
                                           url = activities[counter].DocumentPath
                                        },
                                }
                            };
                        }
                        else
                        {
                            fbObject[counter] = new
                            {
                                type = "video",
                                buttons = new object[]
                                {
                                        new
                                        {
                                            type = "web_url",
                                            url = activities[counter].DocumentPath,
                                            title = activities[counter].FirstName + " " + activities[counter].LastName + " posted " + BotHelper.UserPosted(activities[counter].MediaTypeValue),
                                             webview_height_ratio = "compact",
                                            messenger_extensions = true
                                        }
                                }
                            };
                        }
  counter--;
                    if (counter < 0)
                        stop = true;

    }

 resultMessage.ChannelData = JObject.FromObject(new { fbObject }); ;
                await context.PostAsync(resultMessage);

But Facebook messenger does not render it as "carousel".

Any idea how to show object like Carousel type of card ?


问:
AngularJs : Call controller function bound to 'this' from outside(eg. Browser console)
I have below code, now let's assume I want to call foo(val) function from somewhere outside, let's say browser console.

```<code>angular.module('app', []);
angular.module('app')
    .controller('MyController', MyController);

function MyController() {
    var self = this;
    self.foo = function(val) {
        console.log(val);
    };
    return self;
}
</code>```

Below code works only when foo() is bound to $scope.

```<code>angular.element(document.getElementById('MyController')).scope().foo('Hello');
</code>```

Is there any work around or I will be forced to use $scope for this ?

答:
When controllers are instantiated with "controllerAs" syntax, the this context is bound to the scope property with the specified name:

```<code><div id="MyController" ng-controller="MyController as vm">
    <button ng-click="vm.foo()">
        Click foo
    </button>
</div>
</code>```

```<code>$scope = angular.element(document.getElementById('MyController')).scope()

$scope.vm.foo('Hello');
$scope.$apply();
</code>```

The above commands executed from the console will do the same action as clicking the Click foo button.

Body:
I have below code, now let's assume I want to call foo(val) function from somewhere outside, let's say browser console.

angular.module('app', []);
angular.module('app')
    .controller('MyController', MyController);

function MyController() {
    var self = this;
    self.foo = function(val) {
        console.log(val);
    };
    return self;
}

Below code works only when foo() is bound to $scope.

angular.element(document.getElementById('MyController')).scope().foo('Hello');

Is there any work around or I will be forced to use $scope for this ?

Body:
When controllers are instantiated with "controllerAs" syntax, the this context is bound to the scope property with the specified name:

<div id="MyController" ng-controller="MyController as vm">
    <button ng-click="vm.foo()">
        Click foo
    </button>
</div>

$scope = angular.element(document.getElementById('MyController')).scope()

$scope.vm.foo('Hello');
$scope.$apply();

The above commands executed from the console will do the same action as clicking the Click foo button.


问:
Students-t distribution and histogram overlay
Does anyone know why the t-distribution in the histogram overlay is just an horizontal line? The warnings() in fit.std result from the etimation of the dof, which can lead to an infinite likelihood - see Fernandez & Steel (1999).

```<code>library(zoo)
library(rugarch)

data(sp500ret)

g= zoo(sp500ret$SP500RET, as.Date(rownames(sp500ret)))
(fit.std = fitdistr(g,"t"))

mu.std = fit.std$estimate[["m"]]
lambda = fit.std$estimate[["s"]]
nu = fit.std$estimate[["df"]]

# plot
hist(g, density=20, breaks=20, prob=T)
curve(dt(x, nu, lambda), col="red", lwd=2, add=TRUE, yaxt="n")
</code>```

答:
From the help file for fitdistr:

For the "t" named distribution the density is taken to be the location-scale family with location m and scale s.

For a location-scale family if we have a location parameter m and a scale parameter s then we can get the density at 'x' using the standardized version (location = 0, scale = 1, call it f) by using:

```<code>f((x-m)/s)/s
</code>```

So for you we have mu.std is the location parameter and lambda is the scale so we would want to change your line to:

```<code>curve(dt((x-mu.std)/lambda, nu)/lambda, col="red", lwd=2, add=TRUE, yaxt="n")
</code>```

Body:
Does anyone know why the t-distribution in the histogram overlay is just an horizontal line? The warnings() in fit.std result from the etimation of the dof, which can lead to an infinite likelihood - see Fernandez & Steel (1999).

library(zoo)
library(rugarch)

data(sp500ret)

g= zoo(sp500ret$SP500RET, as.Date(rownames(sp500ret)))
(fit.std = fitdistr(g,"t"))

mu.std = fit.std$estimate[["m"]]
lambda = fit.std$estimate[["s"]]
nu = fit.std$estimate[["df"]]

# plot
hist(g, density=20, breaks=20, prob=T)
curve(dt(x, nu, lambda), col="red", lwd=2, add=TRUE, yaxt="n")

Body:
From the help file for fitdistr:

For the "t" named distribution the density is taken to be the location-scale family with location m and scale s.

For a location-scale family if we have a location parameter m and a scale parameter s then we can get the density at 'x' using the standardized version (location = 0, scale = 1, call it f) by using:

f((x-m)/s)/s

So for you we have mu.std is the location parameter and lambda is the scale so we would want to change your line to:

curve(dt((x-mu.std)/lambda, nu)/lambda, col="red", lwd=2, add=TRUE, yaxt="n")


问:
Dplyr tally/count by multiple filters
I am trying to create a summarise/filter dplyr pipeline which will be equivalent to the below:

```<code>iris %>%
mutate(Sepal.Area = Sepal.Length * Sepal.Width,
       Petal.Area = Petal.Length * Petal.Width) %>%
  group_by(Species) %>%
      filter(Sepal.Area < 17) %>%
        tally() %>%
      filter(Sepal.Area > 17 & Sepal.Area < 22) %>%
        tally() %>%
      filter(Sepal.Area > 22) %>%
        tally()
</code>```

Or another potential approach:

```<code>iris %>%
  mutate(Sepal.Area = Sepal.Length * Sepal.Width,
         Petal.Area = Petal.Length * Petal.Width) %>%
  group_by(Species) %>%
    summarise(n(Sepal.Area < 17),
              n(Sepal.Area > 17 & Sepal.Area < 22),
              n(Sepal.Area > 22))
</code>```

What is the easiest way to get counts by multiple filters on a grouping?
Or simply run each one and join them later?

答:
I think using cut is the right approach.  I don't have the reputation to comment on this answer , but you can also use labels.</p>

```<code>iris %>%
mutate(Sepal.Area = Sepal.Length * Sepal.Width,
       Petal.Area = Petal.Length * Petal.Width) %>%
mutate(size = cut(Sepal.Area, breaks = c(0, 17, 22, Inf),
                              labels = c("small", "medium", "large"))) %>%
group_by(size) %>% summarize(count = n())
</code>```

Title: Dplyr tally/count by multiple filters

Body:
I am trying to create a summarise/filter dplyr pipeline which will be equivalent to the below:

iris %>%
mutate(Sepal.Area = Sepal.Length * Sepal.Width,
       Petal.Area = Petal.Length * Petal.Width) %>%
  group_by(Species) %>%
      filter(Sepal.Area < 17) %>%
        tally() %>%
      filter(Sepal.Area > 17 & Sepal.Area < 22) %>%
        tally() %>%
      filter(Sepal.Area > 22) %>%
        tally()

Or another potential approach:

iris %>%
  mutate(Sepal.Area = Sepal.Length * Sepal.Width,
         Petal.Area = Petal.Length * Petal.Width) %>%
  group_by(Species) %>%
    summarise(n(Sepal.Area < 17),
              n(Sepal.Area > 17 & Sepal.Area < 22),
              n(Sepal.Area > 22))

What is the easiest way to get counts by multiple filters on a grouping?
Or simply run each one and join them later?

Body:
I think using cut is the right approach.  I don't have the reputation to comment on this answer , but you can also use labels.

iris %>%
mutate(Sepal.Area = Sepal.Length * Sepal.Width,
       Petal.Area = Petal.Length * Petal.Width) %>%
mutate(size = cut(Sepal.Area, breaks = c(0, 17, 22, Inf),
                              labels = c("small", "medium", "large"))) %>%
group_by(size) %>% summarize(count = n())


问:
array_search fails for particular value even if value is present
I have a very large PHP array, I use array_search for predefined values on this array. only for 3 keys the array_search fails

```<code> $headings = array("Summary ","Experience","Projects","Languages","Skills & Expertise","Education","Volunteer Experience","Certifications","Courses","Publications","Honors and Awards","Test Scores","Organizations","Patents");
for ($x = 0; $x <= 13; $x++) {
      $present = $headings[$x];
      $key = array_search($present, $cvdata, true);

      if($key) {
      echo "<br />";    echo "Key Present-----------------".$present.$key;
      }else {
        echo "<br />"; echo "No Match-----------".$present;
      }

    }
</code>```

Output for above code is

```<code>No Match-----------Summary
No Match-----------Experience
Key Present-----------------Projects20

Key Present-----------------Languages41

Key Present-----------------Skills & Expertise46

Key Present-----------------Education58

No Match-----------Volunteer Experience
Key Present-----------------Certifications71

Key Present-----------------Courses79

Key Present-----------------Publications251

Key Present-----------------Honors and Awards259

Key Present-----------------Test Scores267

Key Present-----------------Organizations277

Key Present-----------------Patents285
</code>```

For Summary, Experience & Volunteer Experience - array_search can't find the key. what can be the reason?
This is my array.

```<code>Array
(
    [0] =>
    [1] => Page
    [2] => 1
    [3] => Jagan Krishnaraj
    [4] => UI Architect
    [5] => test
    [6] => Summary
    [7] => I am passionate about creating web applications for people to use.
    [8] => Experience
    [9] => UI Architect
    [10] => May 2015  -  Present
    [11] => (1 year 11 months)
    [12] => Your Security Matters !
    [13] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [14] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [15] =>  COMODOâ„¢ to protect your personal and confidential information
    [16] => UI Developer
    [17] => January 2013  -  April 2015
    [18] => (2 years 4 months)
    [19] => Creation of UI design
    [20] => Projects
    [21] => LivePositiveWay
    [22] => August 2013 to November 2013
    [23] => Members:Jagan Krishnaraj
    [24] => LivePositiveWay.com is first of its kind to give people a personal online space to save and share the
    [25] =>  inspiration in their personal life with the world. The amount of inspiration every user spread to this world
    [26] =>  using this site is measured on a numerical scale called Positivity Score. The Positivity Score can also be a
    [27] =>  numerical estimation of amount of positivity every user created in this world
    [28] => Any user can create an account with livepositiveway.com and write their story, share their inspiration with
    [29] =>  the world for free & get inspired by the rating and social sharing happening on their inspiration that is
    [30] =>  accurately tracked and displayed on user's dashboard & also through the Positivity Score received.
    [31] => Responsive CV
    [32] => July 2013 to November 2014
    [33] => Members:Jagan Krishnaraj
    [34] => Your Security Matters !
    [35] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [36] =>
    [37] => Page
    [38] => 2
    [39] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [40] =>  COMODOâ„¢ to protect your personal and confidential information
    [41] => Languages
    [42] => Tamil
    [43] => Telugu
    [44] => Hindi
    [45] => English
    [46] => Skills & Expertise
    [47] => JavaScript
    [48] => jQuery
    [49] => CSS
    [50] => MySQL
    [51] => XML
    [52] => PHP
    [53] => AJAX
    [54] => SQL
    [55] => Web Development
    [56] => User Interface Design
    [57] => Web Applications
    [58] => Education
    [59] => Ramakrishna School
    [60] => SSLC, Biology, 1995 - 2005
    [61] => Activities and Societies:
    [62] => Participated in the School Footbal Team, Shool Table tennis team
    [63] => Arunai college of Engineering
    [64] => Bachelor's degree, Instrumentation Technology/Technician, 2005
    [65] => Activities and Societies:
    [66] => Organized cultural events and symposium
    [67] => Volunteer Experience
    [68] => Back Office Executive  at   Isha Foundation
    [69] => January 2015  -  Present
    [70] => I  volunteered here.
    [71] => Certifications
    [72] => Microsoft Certified
    [73] => Microsoft       February 2015 to April 2015
    [74] => Google Certified
    [75] => Google   License ANTPJ3242    March 2016
    [76] =>
    [77] => Page
    [78] => 3
    [79] => Courses
    [80] =>
    [81] => UI Developer
    [82] => Symphony Teleca
    [83] => Angular 4
    [84] => 323233
    [85] =>
    [86] => .
    [87] => .
    [88] => .
    [89] => .
    [90] => .
    [91] => .
    [92] => .
    [93] => .
    [94] => .
    [95] => .
    [96] => .
    [97] => .
    [98] => .
    [99] => .
    [100] => .
    [101] => .
    [102] => .
    [103] => .
    [104] => .
    [105] => .
    [106] => .
    [107] => .
    [108] => .
    [109] => .
    [110] => .
    [111] => .
    [112] => .
    [113] => .
    [114] => .
    [115] => .
    [116] => .
    [117] => .
    [118] => .
    [119] => .
    [120] => .
    [121] => .
    [122] => .
    [123] => .
    [124] => .
    [125] => .
    [126] => .
    [127] => .
    [128] => .
    [129] => .
    [130] => .
    [131] => .
    [132] => .
    [133] => .
    [134] => .
    [135] => .
    [136] => .
    [137] => .
    [138] => .
    [139] => .
    [140] => .
    [141] => .
    [142] => .
    [143] => .
    [144] => .
    [145] => .
    [146] => .
    [147] => .
    [148] => .
    [149] => .
    [150] => .
    [151] => .
    [152] => .
    [153] => .
    [154] => .
    [155] => .
    [156] => .
    [157] => .
    [158] => .
    [159] => .
    [160] => .
    [161] => .
    [162] => .
    [163] => .
    [164] => .
    [165] => .
    [166] => .
    [167] => .
    [168] => .
    [169] => .
    [170] => .
    [171] => .
    [172] => .
    [173] => .
    [174] => .
    [175] => .
    [176] => .
    [177] => .
    [178] => .
    [179] => .
    [180] => .
    [181] => .
    [182] => .
    [183] => .
    [184] => .
    [185] => .
    [186] => .
    [187] => .
    [188] => .
    [189] => .
    [190] => .
    [191] => .
    [192] => .
    [193] => .
    [194] => .
    [195] => .
    [196] => .
    [197] => .
    [198] => .
    [199] => .
    [200] => .
    [201] => .
    [202] => .
    [203] => .
    [204] => .
    [205] => .
    [206] => .
    [207] => .
    [208] => .
    [209] => .
    [210] => .
    [211] => .
    [212] => .
    [213] => .
    [214] => .
    [215] => .
    [216] => .
    [217] => .
    [218] => .
    [219] => .
    [220] => .
    [221] => .
    [222] => .
    [223] => .
    [224] => .
    [225] => .
    [226] => .
    [227] => .
    [228] => .
    [229] => .
    [230] => .
    [231] => .
    [232] => .
    [233] => .
    [234] => .
    [235] => .
    [236] => .
    [237] => .
    [238] => .
    [239] => .
    [240] => .
    [241] => .
    [242] => .
    [243] => .
    [244] => .
    [245] => .
    [246] => .
    [247] =>
    [248] => Independent Coursework
    [249] =>
    [250] => Angular 2
    [251] => Publications
    [252] => Publication On Angular & Node
    [253] =>    June 6, 2008
    [254] => Authors: Jagan Krishnaraj
    [255] => Your Security Matters !
    [256] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [257] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [258] =>  COMODOâ„¢ to protect your personal and confidential information
    [259] => Honors and Awards
    [260] => Best Student Award
    [261] => Microsoft
    [262] => April 2014
    [263] => Your Security Matters !
    [264] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [265] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [266] =>  COMODOâ„¢ to protect your personal and confidential information
    [267] => Test Scores
    [268] => Test Score
    [269] => February 2016   Score:98
    [270] => Your Security Matters !
    [271] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [272] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [273] =>  COMODOâ„¢ to protect your personal and confidential information
    [274] =>
    [275] => Page
    [276] => 4
    [277] => Organizations
    [278] => Infosys
    [279] => manager
    [280] => January 2013 to May 2014
    [281] => Your Security Matters !
    [282] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [283] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [284] =>  COMODOâ„¢ to protect your personal and confidential information
    [285] => Patents
    [286] => Responsive CV Patent
    [287] => India Patent Application 32333
    [288] => Inventors: Jagan Krishnaraj
    [289] => Your Security Matters !
    [290] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [291] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [292] =>  COMODOâ„¢ to protect your personal and confidential information
)
</code>```

--Edit Requested Information--

$cvdata is coming from a pdf file through a php class that converts it to HTML then to plain text.

This is var_dump of cvdata

```<code>array(300) { [0]=> string(0) "" [1]=> string(4) "Page" [2]=> string(1) "1" [3]=> string(17) "Jagan Krishnaraj " [4]=> string(37) "UI Architect at International " [5]=> string(24) "jaxplore@gmail.com " [6]=> string(8) "Summary " [7]=> string(67) "I am passionate about creating web applications for people to use. " [8]=> string(11) "Experience " [9]=> string(40) "UI Architect at International " [10]=> string(21) "May 2015 - Present " [11]=> string(19) "(1 year 11 months) " [12]=> string(24) "Your Security Matters ! " [13]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [14]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [15]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [16]=> string(35) "UI Developer at Symphony Teleca " [17]=> string(29) "January 2013 - April 2015 " [18]=> string(19) "(2 years 4 months) " [19]=> string(22) "Creation of UI design " [20]=> string(8) "Projects" [21]=> string(16) "LivePositiveWay " [22]=> string(29) "August 2013 to November 2013 " [23]=> string(25) "Members:Jagan Krishnaraj " [24]=> string(102) "LivePositiveWay.com is first of its kind to give people a personal online space to save and share the " [25]=> string(110) " inspiration in their personal life with the world. The amount of inspiration every user spread to this world " [26]=> string(110) " using this site is measured on a numerical scale called Positivity Score. The Positivity Score can also be a " [27]=> string(79) " numerical estimation of amount of positivity every user created in this world " [28]=> string(108) "Any user can create an account with livepositiveway.com and write their story, share their inspiration with " [29]=> string(107) " the world for free & get inspired by the rating and social sharing happening on their inspiration that is " [30]=> string(100) " accurately tracked and displayed on user's dashboard & also through the Positivity Score received. " [31]=> string(14) "Responsive CV " [32]=> string(27) "July 2013 to November 2014 " [33]=> string(25) "Members:Jagan Krishnaraj " [34]=> string(24) "Your Security Matters ! " [35]=> string(109) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence." [36]=> string(0) "" [37]=> string(4) "Page" [38]=> string(1) "2" [39]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [40]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [41]=> string(9) "Languages" [42]=> string(5) "Tamil" [43]=> string(6) "Telugu" [44]=> string(5) "Hindi" [45]=> string(7) "English" [46]=> string(18) "Skills & Expertise" [47]=> string(10) "JavaScript" [48]=> string(6) "jQuery" [49]=> string(3) "CSS" [50]=> string(5) "MySQL" [51]=> string(3) "XML" [52]=> string(3) "PHP" [53]=> string(4) "AJAX" [54]=> string(3) "SQL" [55]=> string(15) "Web Development" [56]=> string(21) "User Interface Design" [57]=> string(16) "Web Applications" [58]=> string(9) "Education" [59]=> string(19) "Ramakrishna School " [60]=> string(27) "SSLC, Biology, 1995 - 2005 " [61]=> string(27) "Activities and Societies: " [62]=> string(65) "Participated in the School Footbal Team, Shool Table tennis team " [63]=> string(30) "Arunai college of Engineering " [64]=> string(63) "Bachelor's degree, Instrumentation Technology/Technician, 2005 " [65]=> string(27) "Activities and Societies: " [66]=> string(40) "Organized cultural events and symposium " [67]=> string(21) "Volunteer Experience " [68]=> string(44) "Back Office Executive at Isha Foundation " [69]=> string(25) "January 2015 - Present " [70]=> string(22) "I volunteered here. " [71]=> string(14) "Certifications" [72]=> string(20) "Microsoft Certified " [73]=> string(44) "Microsoft February 2015 to April 2015 " [74]=> string(17) "Google Certified " [75]=> string(40) "Google License ANTPJ3242 March 2016" [76]=> string(0) "" [77]=> string(4) "Page" [78]=> string(1) "3" [79]=> string(7) "Courses" [80]=> string(1) " " [81]=> string(13) "UI Developer " [82]=> string(16) "Symphony Teleca " [83]=> string(9) "Angular 4" [84]=> string(6) "323233" [85]=> string(2) " " [86]=> string(1) "." [87]=> string(1) "." [88]=> string(1) "." [89]=> string(1) "." [90]=> string(1) "." [91]=> string(1) "." [92]=> string(1) "." [93]=> string(1) "." [94]=> string(1) "." [95]=> string(1) "." [96]=> string(1) "." [97]=> string(1) "." [98]=> string(1) "." [99]=> string(1) "." [100]=> string(1) "." [101]=> string(1) "." [102]=> string(1) "." [103]=> string(1) "." [104]=> string(1) "." [105]=> string(1) "." [106]=> string(1) "." [107]=> string(1) "." [108]=> string(1) "." [109]=> string(1) "." [110]=> string(1) "." [111]=> string(1) "." [112]=> string(1) "." [113]=> string(1) "." [114]=> string(1) "." [115]=> string(1) "." [116]=> string(1) "." [117]=> string(1) "." [118]=> string(1) "." [119]=> string(1) "." [120]=> string(1) "." [121]=> string(1) "." [122]=> string(1) "." [123]=> string(1) "." [124]=> string(1) "." [125]=> string(1) "." [126]=> string(1) "." [127]=> string(1) "." [128]=> string(1) "." [129]=> string(1) "." [130]=> string(1) "." [131]=> string(1) "." [132]=> string(1) "." [133]=> string(1) "." [134]=> string(1) "." [135]=> string(1) "." [136]=> string(1) "." [137]=> string(1) "." [138]=> string(1) "." [139]=> string(1) "." [140]=> string(1) "." [141]=> string(1) "." [142]=> string(1) "." [143]=> string(1) "." [144]=> string(1) "." [145]=> string(1) "." [146]=> string(1) "." [147]=> string(1) "." [148]=> string(1) "." [149]=> string(1) "." [150]=> string(1) "." [151]=> string(1) "." [152]=> string(1) "." [153]=> string(1) "." [154]=> string(1) "." [155]=> string(1) "." [156]=> string(1) "." [157]=> string(1) "." [158]=> string(1) "." [159]=> string(1) "." [160]=> string(1) "." [161]=> string(1) "." [162]=> string(1) "." [163]=> string(1) "." [164]=> string(1) "." [165]=> string(1) "." [166]=> string(1) "." [167]=> string(1) "." [168]=> string(1) "." [169]=> string(1) "." [170]=> string(1) "." [171]=> string(1) "." [172]=> string(1) "." [173]=> string(1) "." [174]=> string(1) "." [175]=> string(1) "." [176]=> string(1) "." [177]=> string(1) "." [178]=> string(1) "." [179]=> string(1) "." [180]=> string(1) "." [181]=> string(1) "." [182]=> string(1) "." [183]=> string(1) "." [184]=> string(1) "." [185]=> string(1) "." [186]=> string(1) "." [187]=> string(1) "." [188]=> string(1) "." [189]=> string(1) "." [190]=> string(1) "." [191]=> string(1) "." [192]=> string(1) "." [193]=> string(1) "." [194]=> string(1) "." [195]=> string(1) "." [196]=> string(1) "." [197]=> string(1) "." [198]=> string(1) "." [199]=> string(1) "." [200]=> string(1) "." [201]=> string(1) "." [202]=> string(1) "." [203]=> string(1) "." [204]=> string(1) "." [205]=> string(1) "." [206]=> string(1) "." [207]=> string(1) "." [208]=> string(1) "." [209]=> string(1) "." [210]=> string(1) "." [211]=> string(1) "." [212]=> string(1) "." [213]=> string(1) "." [214]=> string(1) "." [215]=> string(1) "." [216]=> string(1) "." [217]=> string(1) "." [218]=> string(1) "." [219]=> string(1) "." [220]=> string(1) "." [221]=> string(1) "." [222]=> string(1) "." [223]=> string(1) "." [224]=> string(1) "." [225]=> string(1) "." [226]=> string(1) "." [227]=> string(1) "." [228]=> string(1) "." [229]=> string(1) "." [230]=> string(1) "." [231]=> string(1) "." [232]=> string(1) "." [233]=> string(1) "." [234]=> string(1) "." [235]=> string(1) "." [236]=> string(1) "." [237]=> string(1) "." [238]=> string(1) "." [239]=> string(1) "." [240]=> string(1) "." [241]=> string(1) "." [242]=> string(1) "." [243]=> string(1) "." [244]=> string(1) "." [245]=> string(1) "." [246]=> string(2) ". " [247]=> string(1) " " [248]=> string(22) "Independent Coursework" [249]=> string(1) " " [250]=> string(9) "Angular 2" [251]=> string(12) "Publications" [252]=> string(30) "Publication On Angular & Node " [253]=> string(16) " June 6, 2008 " [254]=> string(26) "Authors: Jagan Krishnaraj " [255]=> string(24) "Your Security Matters ! " [256]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [257]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [258]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [259]=> string(17) "Honors and Awards" [260]=> string(19) "Best Student Award " [261]=> string(10) "Microsoft " [262]=> string(11) "April 2014 " [263]=> string(24) "Your Security Matters ! " [264]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [265]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [266]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [267]=> string(11) "Test Scores" [268]=> string(11) "Test Score " [269]=> string(25) "February 2016 Score:98 " [270]=> string(24) "Your Security Matters ! " [271]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [272]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [273]=> string(64) " COMODOâ„¢ to protect your personal and confidential information" [274]=> string(0) "" [275]=> string(4) "Page" [276]=> string(1) "4" [277]=> string(13) "Organizations" [278]=> string(8) "Infosys " [279]=> string(8) "manager " [280]=> string(25) "January 2013 to May 2014 " [281]=> string(24) "Your Security Matters ! " [282]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [283]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [284]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [285]=> string(7) "Patents" [286]=> string(21) "Responsive CV Patent " [287]=> string(34) "India Patent Application 32333 " [288]=> string(28) "Inventors: Jagan Krishnaraj " [289]=> string(24) "Your Security Matters ! " [290]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [291]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [292]=> string(64) " COMODOâ„¢ to protect your personal and confidential information" [293]=> string(0) "" [294]=> string(4) "Page" [295]=> string(1) "5" [296]=> string(17) "Jagan Krishnaraj " [297]=> string(37) "UI Architect at ' International " [298]=> string(24) "jaxplore@gmail.com " [299]=> string(25) "Contact Jagan on LinkedIn" }
</code>```

答:
Remove the space from the end of "Summary " in your $headings array as suggested in the comments.

```<code>$headings = array("Summary", ...
</code>```

Then, remove any leading or trailing spaces from your $cvdata array.

```<code>$cvdata = array_map('trim', $cvdata);
</code>```

Then the code you already have should work. Note that you should use an explicit comparison to false on the return of array_search in case an item is found at key 0, which would make $key evaluate to false in if ($key). So instead use

```<code>if($key === false) { ...
</code>```

This is mentioned in the red Warning box in the documentation for array_search. For your specific example here it won't matter, but in general it certainly can.

Body:
I have a very large PHP array, I use array_search for predefined values on this array. only for 3 keys the array_search fails

 $headings = array("Summary ","Experience","Projects","Languages","Skills & Expertise","Education","Volunteer Experience","Certifications","Courses","Publications","Honors and Awards","Test Scores","Organizations","Patents");
for ($x = 0; $x <= 13; $x++) {
      $present = $headings[$x];
      $key = array_search($present, $cvdata, true);

      if($key) {
      echo "
";    echo "Key Present-----------------".$present.$key;
      }else {
        echo "
"; echo "No Match-----------".$present;
      }

    }

Output for above code is

No Match-----------Summary
No Match-----------Experience
Key Present-----------------Projects20

Key Present-----------------Languages41

Key Present-----------------Skills & Expertise46

Key Present-----------------Education58

No Match-----------Volunteer Experience
Key Present-----------------Certifications71

Key Present-----------------Courses79

Key Present-----------------Publications251

Key Present-----------------Honors and Awards259

Key Present-----------------Test Scores267

Key Present-----------------Organizations277

Key Present-----------------Patents285

For Summary, Experience & Volunteer Experience - array_search can't find the key. what can be the reason?
This is my array.

Array
(
    [0] =>
    [1] => Page
    [2] => 1
    [3] => Jagan Krishnaraj
    [4] => UI Architect
    [5] => test
    [6] => Summary
    [7] => I am passionate about creating web applications for people to use.
    [8] => Experience
    [9] => UI Architect
    [10] => May 2015  -  Present
    [11] => (1 year 11 months)
    [12] => Your Security Matters !
    [13] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [14] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [15] =>  COMODOâ„¢ to protect your personal and confidential information
    [16] => UI Developer
    [17] => January 2013  -  April 2015
    [18] => (2 years 4 months)
    [19] => Creation of UI design
    [20] => Projects
    [21] => LivePositiveWay
    [22] => August 2013 to November 2013
    [23] => Members:Jagan Krishnaraj
    [24] => LivePositiveWay.com is first of its kind to give people a personal online space to save and share the
    [25] =>  inspiration in their personal life with the world. The amount of inspiration every user spread to this world
    [26] =>  using this site is measured on a numerical scale called Positivity Score. The Positivity Score can also be a
    [27] =>  numerical estimation of amount of positivity every user created in this world
    [28] => Any user can create an account with livepositiveway.com and write their story, share their inspiration with
    [29] =>  the world for free & get inspired by the rating and social sharing happening on their inspiration that is
    [30] =>  accurately tracked and displayed on user's dashboard & also through the Positivity Score received.
    [31] => Responsive CV
    [32] => July 2013 to November 2014
    [33] => Members:Jagan Krishnaraj
    [34] => Your Security Matters !
    [35] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [36] =>
    [37] => Page
    [38] => 2
    [39] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [40] =>  COMODOâ„¢ to protect your personal and confidential information
    [41] => Languages
    [42] => Tamil
    [43] => Telugu
    [44] => Hindi
    [45] => English
    [46] => Skills & Expertise
    [47] => JavaScript
    [48] => jQuery
    [49] => CSS
    [50] => MySQL
    [51] => XML
    [52] => PHP
    [53] => AJAX
    [54] => SQL
    [55] => Web Development
    [56] => User Interface Design
    [57] => Web Applications
    [58] => Education
    [59] => Ramakrishna School
    [60] => SSLC, Biology, 1995 - 2005
    [61] => Activities and Societies:
    [62] => Participated in the School Footbal Team, Shool Table tennis team
    [63] => Arunai college of Engineering
    [64] => Bachelor's degree, Instrumentation Technology/Technician, 2005
    [65] => Activities and Societies:
    [66] => Organized cultural events and symposium
    [67] => Volunteer Experience
    [68] => Back Office Executive  at   Isha Foundation
    [69] => January 2015  -  Present
    [70] => I  volunteered here.
    [71] => Certifications
    [72] => Microsoft Certified
    [73] => Microsoft       February 2015 to April 2015
    [74] => Google Certified
    [75] => Google   License ANTPJ3242    March 2016
    [76] =>
    [77] => Page
    [78] => 3
    [79] => Courses
    [80] =>
    [81] => UI Developer
    [82] => Symphony Teleca
    [83] => Angular 4
    [84] => 323233
    [85] =>
    [86] => .
    [87] => .
    [88] => .
    [89] => .
    [90] => .
    [91] => .
    [92] => .
    [93] => .
    [94] => .
    [95] => .
    [96] => .
    [97] => .
    [98] => .
    [99] => .
    [100] => .
    [101] => .
    [102] => .
    [103] => .
    [104] => .
    [105] => .
    [106] => .
    [107] => .
    [108] => .
    [109] => .
    [110] => .
    [111] => .
    [112] => .
    [113] => .
    [114] => .
    [115] => .
    [116] => .
    [117] => .
    [118] => .
    [119] => .
    [120] => .
    [121] => .
    [122] => .
    [123] => .
    [124] => .
    [125] => .
    [126] => .
    [127] => .
    [128] => .
    [129] => .
    [130] => .
    [131] => .
    [132] => .
    [133] => .
    [134] => .
    [135] => .
    [136] => .
    [137] => .
    [138] => .
    [139] => .
    [140] => .
    [141] => .
    [142] => .
    [143] => .
    [144] => .
    [145] => .
    [146] => .
    [147] => .
    [148] => .
    [149] => .
    [150] => .
    [151] => .
    [152] => .
    [153] => .
    [154] => .
    [155] => .
    [156] => .
    [157] => .
    [158] => .
    [159] => .
    [160] => .
    [161] => .
    [162] => .
    [163] => .
    [164] => .
    [165] => .
    [166] => .
    [167] => .
    [168] => .
    [169] => .
    [170] => .
    [171] => .
    [172] => .
    [173] => .
    [174] => .
    [175] => .
    [176] => .
    [177] => .
    [178] => .
    [179] => .
    [180] => .
    [181] => .
    [182] => .
    [183] => .
    [184] => .
    [185] => .
    [186] => .
    [187] => .
    [188] => .
    [189] => .
    [190] => .
    [191] => .
    [192] => .
    [193] => .
    [194] => .
    [195] => .
    [196] => .
    [197] => .
    [198] => .
    [199] => .
    [200] => .
    [201] => .
    [202] => .
    [203] => .
    [204] => .
    [205] => .
    [206] => .
    [207] => .
    [208] => .
    [209] => .
    [210] => .
    [211] => .
    [212] => .
    [213] => .
    [214] => .
    [215] => .
    [216] => .
    [217] => .
    [218] => .
    [219] => .
    [220] => .
    [221] => .
    [222] => .
    [223] => .
    [224] => .
    [225] => .
    [226] => .
    [227] => .
    [228] => .
    [229] => .
    [230] => .
    [231] => .
    [232] => .
    [233] => .
    [234] => .
    [235] => .
    [236] => .
    [237] => .
    [238] => .
    [239] => .
    [240] => .
    [241] => .
    [242] => .
    [243] => .
    [244] => .
    [245] => .
    [246] => .
    [247] =>
    [248] => Independent Coursework
    [249] =>
    [250] => Angular 2
    [251] => Publications
    [252] => Publication On Angular & Node
    [253] =>    June 6, 2008
    [254] => Authors: Jagan Krishnaraj
    [255] => Your Security Matters !
    [256] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [257] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [258] =>  COMODOâ„¢ to protect your personal and confidential information
    [259] => Honors and Awards
    [260] => Best Student Award
    [261] => Microsoft
    [262] => April 2014
    [263] => Your Security Matters !
    [264] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [265] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [266] =>  COMODOâ„¢ to protect your personal and confidential information
    [267] => Test Scores
    [268] => Test Score
    [269] => February 2016   Score:98
    [270] => Your Security Matters !
    [271] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [272] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [273] =>  COMODOâ„¢ to protect your personal and confidential information
    [274] =>
    [275] => Page
    [276] => 4
    [277] => Organizations
    [278] => Infosys
    [279] => manager
    [280] => January 2013 to May 2014
    [281] => Your Security Matters !
    [282] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [283] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [284] =>  COMODOâ„¢ to protect your personal and confidential information
    [285] => Patents
    [286] => Responsive CV Patent
    [287] => India Patent Application 32333
    [288] => Inventors: Jagan Krishnaraj
    [289] => Your Security Matters !
    [290] => The protection of privacy and the safeguarding of our Clients personal information is our highest precedence.
    [291] => At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by
    [292] =>  COMODOâ„¢ to protect your personal and confidential information
)

--Edit Requested Information--

$cvdata is coming from a pdf file through a php class that converts it to HTML then to plain text.

This is var_dump of cvdata

array(300) { [0]=> string(0) "" [1]=> string(4) "Page" [2]=> string(1) "1" [3]=> string(17) "Jagan Krishnaraj " [4]=> string(37) "UI Architect at International " [5]=> string(24) "jaxplore@gmail.com " [6]=> string(8) "Summary " [7]=> string(67) "I am passionate about creating web applications for people to use. " [8]=> string(11) "Experience " [9]=> string(40) "UI Architect at International " [10]=> string(21) "May 2015 - Present " [11]=> string(19) "(1 year 11 months) " [12]=> string(24) "Your Security Matters ! " [13]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [14]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [15]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [16]=> string(35) "UI Developer at Symphony Teleca " [17]=> string(29) "January 2013 - April 2015 " [18]=> string(19) "(2 years 4 months) " [19]=> string(22) "Creation of UI design " [20]=> string(8) "Projects" [21]=> string(16) "LivePositiveWay " [22]=> string(29) "August 2013 to November 2013 " [23]=> string(25) "Members:Jagan Krishnaraj " [24]=> string(102) "LivePositiveWay.com is first of its kind to give people a personal online space to save and share the " [25]=> string(110) " inspiration in their personal life with the world. The amount of inspiration every user spread to this world " [26]=> string(110) " using this site is measured on a numerical scale called Positivity Score. The Positivity Score can also be a " [27]=> string(79) " numerical estimation of amount of positivity every user created in this world " [28]=> string(108) "Any user can create an account with livepositiveway.com and write their story, share their inspiration with " [29]=> string(107) " the world for free & get inspired by the rating and social sharing happening on their inspiration that is " [30]=> string(100) " accurately tracked and displayed on user's dashboard & also through the Positivity Score received. " [31]=> string(14) "Responsive CV " [32]=> string(27) "July 2013 to November 2014 " [33]=> string(25) "Members:Jagan Krishnaraj " [34]=> string(24) "Your Security Matters ! " [35]=> string(109) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence." [36]=> string(0) "" [37]=> string(4) "Page" [38]=> string(1) "2" [39]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [40]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [41]=> string(9) "Languages" [42]=> string(5) "Tamil" [43]=> string(6) "Telugu" [44]=> string(5) "Hindi" [45]=> string(7) "English" [46]=> string(18) "Skills & Expertise" [47]=> string(10) "JavaScript" [48]=> string(6) "jQuery" [49]=> string(3) "CSS" [50]=> string(5) "MySQL" [51]=> string(3) "XML" [52]=> string(3) "PHP" [53]=> string(4) "AJAX" [54]=> string(3) "SQL" [55]=> string(15) "Web Development" [56]=> string(21) "User Interface Design" [57]=> string(16) "Web Applications" [58]=> string(9) "Education" [59]=> string(19) "Ramakrishna School " [60]=> string(27) "SSLC, Biology, 1995 - 2005 " [61]=> string(27) "Activities and Societies: " [62]=> string(65) "Participated in the School Footbal Team, Shool Table tennis team " [63]=> string(30) "Arunai college of Engineering " [64]=> string(63) "Bachelor's degree, Instrumentation Technology/Technician, 2005 " [65]=> string(27) "Activities and Societies: " [66]=> string(40) "Organized cultural events and symposium " [67]=> string(21) "Volunteer Experience " [68]=> string(44) "Back Office Executive at Isha Foundation " [69]=> string(25) "January 2015 - Present " [70]=> string(22) "I volunteered here. " [71]=> string(14) "Certifications" [72]=> string(20) "Microsoft Certified " [73]=> string(44) "Microsoft February 2015 to April 2015 " [74]=> string(17) "Google Certified " [75]=> string(40) "Google License ANTPJ3242 March 2016" [76]=> string(0) "" [77]=> string(4) "Page" [78]=> string(1) "3" [79]=> string(7) "Courses" [80]=> string(1) " " [81]=> string(13) "UI Developer " [82]=> string(16) "Symphony Teleca " [83]=> string(9) "Angular 4" [84]=> string(6) "323233" [85]=> string(2) " " [86]=> string(1) "." [87]=> string(1) "." [88]=> string(1) "." [89]=> string(1) "." [90]=> string(1) "." [91]=> string(1) "." [92]=> string(1) "." [93]=> string(1) "." [94]=> string(1) "." [95]=> string(1) "." [96]=> string(1) "." [97]=> string(1) "." [98]=> string(1) "." [99]=> string(1) "." [100]=> string(1) "." [101]=> string(1) "." [102]=> string(1) "." [103]=> string(1) "." [104]=> string(1) "." [105]=> string(1) "." [106]=> string(1) "." [107]=> string(1) "." [108]=> string(1) "." [109]=> string(1) "." [110]=> string(1) "." [111]=> string(1) "." [112]=> string(1) "." [113]=> string(1) "." [114]=> string(1) "." [115]=> string(1) "." [116]=> string(1) "." [117]=> string(1) "." [118]=> string(1) "." [119]=> string(1) "." [120]=> string(1) "." [121]=> string(1) "." [122]=> string(1) "." [123]=> string(1) "." [124]=> string(1) "." [125]=> string(1) "." [126]=> string(1) "." [127]=> string(1) "." [128]=> string(1) "." [129]=> string(1) "." [130]=> string(1) "." [131]=> string(1) "." [132]=> string(1) "." [133]=> string(1) "." [134]=> string(1) "." [135]=> string(1) "." [136]=> string(1) "." [137]=> string(1) "." [138]=> string(1) "." [139]=> string(1) "." [140]=> string(1) "." [141]=> string(1) "." [142]=> string(1) "." [143]=> string(1) "." [144]=> string(1) "." [145]=> string(1) "." [146]=> string(1) "." [147]=> string(1) "." [148]=> string(1) "." [149]=> string(1) "." [150]=> string(1) "." [151]=> string(1) "." [152]=> string(1) "." [153]=> string(1) "." [154]=> string(1) "." [155]=> string(1) "." [156]=> string(1) "." [157]=> string(1) "." [158]=> string(1) "." [159]=> string(1) "." [160]=> string(1) "." [161]=> string(1) "." [162]=> string(1) "." [163]=> string(1) "." [164]=> string(1) "." [165]=> string(1) "." [166]=> string(1) "." [167]=> string(1) "." [168]=> string(1) "." [169]=> string(1) "." [170]=> string(1) "." [171]=> string(1) "." [172]=> string(1) "." [173]=> string(1) "." [174]=> string(1) "." [175]=> string(1) "." [176]=> string(1) "." [177]=> string(1) "." [178]=> string(1) "." [179]=> string(1) "." [180]=> string(1) "." [181]=> string(1) "." [182]=> string(1) "." [183]=> string(1) "." [184]=> string(1) "." [185]=> string(1) "." [186]=> string(1) "." [187]=> string(1) "." [188]=> string(1) "." [189]=> string(1) "." [190]=> string(1) "." [191]=> string(1) "." [192]=> string(1) "." [193]=> string(1) "." [194]=> string(1) "." [195]=> string(1) "." [196]=> string(1) "." [197]=> string(1) "." [198]=> string(1) "." [199]=> string(1) "." [200]=> string(1) "." [201]=> string(1) "." [202]=> string(1) "." [203]=> string(1) "." [204]=> string(1) "." [205]=> string(1) "." [206]=> string(1) "." [207]=> string(1) "." [208]=> string(1) "." [209]=> string(1) "." [210]=> string(1) "." [211]=> string(1) "." [212]=> string(1) "." [213]=> string(1) "." [214]=> string(1) "." [215]=> string(1) "." [216]=> string(1) "." [217]=> string(1) "." [218]=> string(1) "." [219]=> string(1) "." [220]=> string(1) "." [221]=> string(1) "." [222]=> string(1) "." [223]=> string(1) "." [224]=> string(1) "." [225]=> string(1) "." [226]=> string(1) "." [227]=> string(1) "." [228]=> string(1) "." [229]=> string(1) "." [230]=> string(1) "." [231]=> string(1) "." [232]=> string(1) "." [233]=> string(1) "." [234]=> string(1) "." [235]=> string(1) "." [236]=> string(1) "." [237]=> string(1) "." [238]=> string(1) "." [239]=> string(1) "." [240]=> string(1) "." [241]=> string(1) "." [242]=> string(1) "." [243]=> string(1) "." [244]=> string(1) "." [245]=> string(1) "." [246]=> string(2) ". " [247]=> string(1) " " [248]=> string(22) "Independent Coursework" [249]=> string(1) " " [250]=> string(9) "Angular 2" [251]=> string(12) "Publications" [252]=> string(30) "Publication On Angular & Node " [253]=> string(16) " June 6, 2008 " [254]=> string(26) "Authors: Jagan Krishnaraj " [255]=> string(24) "Your Security Matters ! " [256]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [257]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [258]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [259]=> string(17) "Honors and Awards" [260]=> string(19) "Best Student Award " [261]=> string(10) "Microsoft " [262]=> string(11) "April 2014 " [263]=> string(24) "Your Security Matters ! " [264]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [265]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [266]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [267]=> string(11) "Test Scores" [268]=> string(11) "Test Score " [269]=> string(25) "February 2016 Score:98 " [270]=> string(24) "Your Security Matters ! " [271]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [272]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [273]=> string(64) " COMODOâ„¢ to protect your personal and confidential information" [274]=> string(0) "" [275]=> string(4) "Page" [276]=> string(1) "4" [277]=> string(13) "Organizations" [278]=> string(8) "Infosys " [279]=> string(8) "manager " [280]=> string(25) "January 2013 to May 2014 " [281]=> string(24) "Your Security Matters ! " [282]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [283]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [284]=> string(65) " COMODOâ„¢ to protect your personal and confidential information " [285]=> string(7) "Patents" [286]=> string(21) "Responsive CV Patent " [287]=> string(34) "India Patent Application 32333 " [288]=> string(28) "Inventors: Jagan Krishnaraj " [289]=> string(24) "Your Security Matters ! " [290]=> string(110) "The protection of privacy and the safeguarding of our Clients personal information is our highest precedence. " [291]=> string(104) "At TheResponsiveCV, we use the highest levels of security, including 128-bit SSL encryption verified by " [292]=> string(64) " COMODOâ„¢ to protect your personal and confidential information" [293]=> string(0) "" [294]=> string(4) "Page" [295]=> string(1) "5" [296]=> string(17) "Jagan Krishnaraj " [297]=> string(37) "UI Architect at ' International " [298]=> string(24) "jaxplore@gmail.com " [299]=> string(25) "Contact Jagan on LinkedIn" }

Body:
Remove the space from the end of "Summary " in your $headings array as suggested in the comments.

$headings = array("Summary", ...

Then, remove any leading or trailing spaces from your $cvdata array.

$cvdata = array_map('trim', $cvdata);

Then the code you already have should work. Note that you should use an explicit comparison to false on the return of array_search in case an item is found at key 0, which would make $key evaluate to false in if ($key). So instead use

if($key === false) { ...

This is mentioned in the red Warning box in the documentation for array_search. For your specific example here it won't matter, but in general it certainly can.


问:
What mangement tools does SQL server 2008 R2 standard edition (with SBS) ship with
I'm considering purchasing SBS 2008 and wanted to know the tools SQL Server Standard ships with.

Here is a MS article with all the tools. http://msdn.microsoft.com/en-us/library/ms144275.aspx

I developed an ERP on SQL Server 2008 Enterprise and would migrate that into the new server. I used the "SQL Server Management Studio" and "Server Profiler" tools very frequently when developing and would still need them to do many tasks.

Are those two tools included in the Standard edition too?

答:
Yes.

Check the article that's linked from the one you posted.


问:
sending date time stamps to elasticsearch through python
I have 3 of 5 columns of my data that is in pandas to_datetime format:

```<code>col1                 col2                col3                col4            a
2017-01-01 21:07:57  2017-01-01 21:07:58 2017-01-01 21:07:59 misc_text_data  text
2017-01-01 21:07:42  2017-01-01 21:07:48 2017-01-01 21:07:49 misc_test_data  text2
2017-01-01 21:07:33  2017-01-01 21:07:22 2017-01-01 21:07:21 mist_test_fata  fext3
</code>```

How can I send my data to elasticsearch via the elasticsearch.py field?

I am trying to get elasticsearch to recognize the format as timedate stamps so I can do timeline analysis from these dates.

I am currently sending my data like below with no recognition of the times:

```<code>mylist = []
for doc in df_json:
    doc['tag'] = "mytags"
    action = { "_index":"myindexoftimes", "_type": "mytimes", "_source":doc}
    mylist.append(action)

helpers.bulk(es, mylist)
</code>```

Any assistance would be helpful. thank you.

答:
Not sure what is the problem in your code, it is probably to do with the timestamp format.

Anyway panda to_json with iso format selected worked for me:

```<code>import pandas as pd
from elasticsearch import Elasticsearch
import json

es = Elasticsearch()

data = ["2017-01-01 21:07:57,  2017-01-01 21:07:58, 2017-01-01    21:07:59, misc_text_data,  text".split(','),
    "2017-01-01 21:07:42,  2017-01-01 21:07:48, 2017-01-01 21 07:49, misc_test_data,  text2".split(','),
    "2017-01-01 21:07:33,  2017-01-01 21:07:22, 2017-01-01 21 07:21, misc_test_fata,  fext3".split(',')]

df = pd.DataFrame(data,columns = ['col1','col2','col3','col4','a'])
for col in ['col1','col2','col3']:
df[col] = pd.to_datetime(df[col])

jsons = json.loads(df.to_json(orient='records',date_format='iso'))

for j in jsons:
    j['injection_timestamp'] = pd.to_datetime('now')
    es.index(index="test33", doc_type='time_text', body=j)
</code>```

Body:
I have 3 of 5 columns of my data that is in pandas to_datetime format:

col1                 col2                col3                col4            a
2017-01-01 21:07:57  2017-01-01 21:07:58 2017-01-01 21:07:59 misc_text_data  text
2017-01-01 21:07:42  2017-01-01 21:07:48 2017-01-01 21:07:49 misc_test_data  text2
2017-01-01 21:07:33  2017-01-01 21:07:22 2017-01-01 21:07:21 mist_test_fata  fext3

How can I send my data to elasticsearch via the elasticsearch.py field?

I am trying to get elasticsearch to recognize the format as timedate stamps so I can do timeline analysis from these dates.

I am currently sending my data like below with no recognition of the times:

mylist = []
for doc in df_json:
    doc['tag'] = "mytags"
    action = { "_index":"myindexoftimes", "_type": "mytimes", "_source":doc}
    mylist.append(action)

helpers.bulk(es, mylist)

Any assistance would be helpful. thank you.

Body:
Not sure what is the problem in your code, it is probably to do with the timestamp format.

Anyway panda to_json with iso format selected worked for me:

import pandas as pd
from elasticsearch import Elasticsearch
import json

es = Elasticsearch()

data = ["2017-01-01 21:07:57,  2017-01-01 21:07:58, 2017-01-01    21:07:59, misc_text_data,  text".split(','),
    "2017-01-01 21:07:42,  2017-01-01 21:07:48, 2017-01-01 21 07:49, misc_test_data,  text2".split(','),
    "2017-01-01 21:07:33,  2017-01-01 21:07:22, 2017-01-01 21 07:21, misc_test_fata,  fext3".split(',')]

df = pd.DataFrame(data,columns = ['col1','col2','col3','col4','a'])
for col in ['col1','col2','col3']:
df[col] = pd.to_datetime(df[col])

jsons = json.loads(df.to_json(orient='records',date_format='iso'))

for j in jsons:
    j['injection_timestamp'] = pd.to_datetime('now')
    es.index(index="test33", doc_type='time_text', body=j)


问:
Two AND/OR in one bash if statement
I have a special condition to test in a bash script.
I thought about something like:

```<code>if [[ $categorie = "DG" || $categorie = "DI" ]] && [[ $client != "host1" || $client != "host2" ]]; then
    echo "requirements are met"
else
    echo "requirements not met"
fi
</code>```

In words: If categorie is DG OR DI AND client is NOT host1 OR host2 then do stuff.

Is this correct?
For me it looks like it just cares about the categorie and if the categorie condition is met it's ok and prints "requirements are met" and doesn't care about the condition for the client at all.

答:
You can get around negating OR by comparing to patterns instead of doing multiple comparisons, which simplifies the test to</p>

```<code>if [[ $categorie == D[GI] ]] && [[ $client != host[12] ]]; then
    echo "requirements are met"
else
    echo "requirements not met"
fi
</code>```

Title: Two AND/OR in one bash if statement

Body:
I have a special condition to test in a bash script.
I thought about something like:

if [[ $categorie = "DG" || $categorie = "DI" ]] && [[ $client != "host1" || $client != "host2" ]]; then
    echo "requirements are met"
else
    echo "requirements not met"
fi

In words: If categorie is DG OR DI AND client is NOT host1 OR host2 then do stuff.

Is this correct?
For me it looks like it just cares about the categorie and if the categorie condition is met it's ok and prints "requirements are met" and doesn't care about the condition for the client at all.

Body:
You can get around negating OR by comparing to patterns instead of doing multiple comparisons, which simplifies the test to

if [[ $categorie == D[GI] ]] && [[ $client != host[12] ]]; then
    echo "requirements are met"
else
    echo "requirements not met"
fi


问:
Maven build fails on Bluemix dev ops pipeline but passes locally
I am receiving the following error for an app being build on Bluemix using the devops pipeline. The build command is

```<code>mvn -B package
</code>```

and the same command works without a problem on my local server.

```<code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compilerplugin:3.1:compile (default-compile) on project api: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
</code>```

My build pipeline

Am I missing a configuration step in my pipeline? Why the delta?

Two nice features: I want to name the custom stages. If you delete the red/green stage I want to create a new one as a template.

答:
In your build script try setting JAVA_HOME to Java8 and adding it to the path.  Java7 is there by default.</p>

```<code>export JAVA_HOME=$JAVA8_HOME
export PATH="$JAVA_HOME/bin:$PATH"
</code>```

Body:
I am receiving the following error for an app being build on Bluemix using the devops pipeline. The build command is

mvn -B package

and the same command works without a problem on my local server.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compilerplugin:3.1:compile (default-compile) on project api: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

My build pipeline

Am I missing a configuration step in my pipeline? Why the delta?

Two nice features: I want to name the custom stages. If you delete the red/green stage I want to create a new one as a template.

Body:
In your build script try setting JAVA_HOME to Java8 and adding it to the path.  Java7 is there by default.

export JAVA_HOME=$JAVA8_HOME
export PATH="$JAVA_HOME/bin:$PATH"


问:
Append div not being triggered
I'm trying to add a div right after the product's name by using append.

Here's the code I have:

```<code>var txt1 = "<div id='yotpo-bottomline-placeholder'></div>"; // This is the DIV
$('#v65-product-parent > tbody > tr:nth-child(1) > td > font').append(txt1);
</code>```

The div is correctly being added right after the product's name. The problem is that this div was supposed to trigger the Star Rating Review widget. See below

When I add this div directly into the HTML code (before the Retail Price) it is being triggered. But I'm using Volusion so I have limited access to the HTML file that's why I need to use the append. See below

Help?

答:
When you append the markup to the DOM, you are doing exactly that. Appending some HTML to the DOM.

It is likely that the star review JS you're using is triggered in the $(document).ready() event, however that appended markup does not exist in the DOM when that event is triggered.

You will need to initialise the star rating manually.

Title: Append div not being triggered

Body:
I'm trying to add a div right after the product's name by using append.

Here's the code I have:

var txt1 = "

"; // This is the DIV
$('#v65-product-parent > tbody > tr:nth-child(1) > td > font').append(txt1);

The div is correctly being added right after the product's name. The problem is that this div was supposed to trigger the Star Rating Review widget. See below

When I add this div directly into the HTML code (before the Retail Price) it is being triggered. But I'm using Volusion so I have limited access to the HTML file that's why I need to use the append. See below

Help?


问:
DNN Language Selector works only on Home Page
I am facing very strange issue in my DotNetNuke website (8.04 Version). I have dual language installed (German and English) in which German is default language.
From the homepage i can switch to English or German which is working fine, but from all other pages (including host and admin pages) I can only able to switch English but can not change to German. When i choose German, Page is reloaded but language is always English, if i need to switch to German, only option i have is to go to home page. Any help will be appropriated.

Thnx

答:
This is quite standard behaviour if you have not yet translated the pages from one language to the other.

Follow these steps:

Navigate to Admin > Advanced Settings >  Languages

Select the page that you want to translate, using the dropdown menu

In the German language column, translate the page title, description and module titles

Tick the checkbox that says "translated".

Hit update and repeat steps 1-5 for every page you need to translate.

Here's an image that shows the same

Ref: DNN documentation


问:
What are the chronological steps in building a cross browser compatible site?
I am working on my first project that requires me to worry about cross browser compatibility.  Since this is my first time doing so, I dont know how to go about completing the project.  I am specifically worried about IE.  Should I complete my project in a more graceful browser then hack it to work in IE, or should I simultaneously build my program up in both environments?</p>

答:
In theory would be best to develop for all browsers at once, always testing for every browser...

Realistically, that rarely happens... I typically develop/test with firefox. when I introduce complex javascript or css, I check in ie... this tool is incredibly handy for checking all versions at once... google ie tester.

By checking all browsers at regular intervals, and when you make complex changes, you ensure that major features are compatable :)

Also, ensuring that all of your code is valid is not only good practice, but helps identify cross browser issues.. google w3schools validator :)

Using javascript libraries such as jquery also aid in cross browser compatability, and some even come with css libraries as well. These libraries are purpose built for quick, reliable features that are typically cross browser guaranteed.

Finally, before launching, use launchlist to check that all works: http://lite.launchlist.net/

Hope all that makes sense and helps with your first project :)


问:
Hiveconf/hivevar: possible to have a dot ('.') in a variable name?
Is it possible to use a dot in a name of hiveconf variable?

All examples in a documentation show simple variable names like a.

If yes:

How do I reference it in HQL script? select ${hiveconf:airflow.ctx.dag.dag_id} as dag_id; produces syntax error (while ${hiveconf:abcd} is ok).

If no:

Why does airflow or azkaban pass variables to hive scripts like this? Wouldn't the authors know that it's not possible to reference these variables?

hive -hiveconf airflow.ctx.dag.dag_id=video-plays-adverts -f test-hiveconf.hql

Thanks!

答:
Have checked, this works:

```<code>set hiveconf:airflow.ctx.dag.dag_id=abc;
hive> select '${hiveconf:airflow.ctx.dag.dag_id}';
OK
abc
Time taken: 0.212 seconds, Fetched: 1 row(s)
</code>```

Probably you forgot about quotes.

Body:
Have checked, this works:

set hiveconf:airflow.ctx.dag.dag_id=abc;
hive> select '${hiveconf:airflow.ctx.dag.dag_id}';
OK
abc
Time taken: 0.212 seconds, Fetched: 1 row(s)

Probably you forgot about quotes.


问:
Java - make a method run only ONCE upon initial startup
I'm working on a program that will include a method startup() for user configuration purposes. I only want this method to run once, upon initial startup of the program. how would I go about doing this?</p>

答:
You can use static initializer block.

```<code>public class MyClass {
static {
 // code to be executed once on startup
 }
}
</code>```

Such static initializer blocks are executed when the class is loaded, even before constructor or main method is called.

You can have any number of these blocks and they will be executed in the order they appear in the code.

Body:
You can use static initializer block.

public class MyClass {
static {
 // code to be executed once on startup
 }
}

Such static initializer blocks are executed when the class is loaded, even before constructor or main method is called.

You can have any number of these blocks and they will be executed in the order they appear in the code.


问:
Excluding child values
I have a property within my Entity which links to another Entity:

```<code> /**
 * @Groups({"bookReviews"})
 * @ORM\ManyToOne(targetEntity="Book\MainBundle\Entity\Book", inversedBy="reviews")
 * @ORM\JoinColumn(name="bookID", referencedColumnName="id")
 */
private $bookID;
</code>```

Within my controller when this is called:

```<code>    public function getReviewsAction()
{
    $serializer = $this->get('serializer');
    $em = $this->getDoctrine()->getManager();
    $reviews = $em->getRepository('BookMainBundle:Review')->findAll();
    $data = $serializer->serialize($reviews, 'json', SerializationContext::create()->setGroups(array('Default')));
    return $this->handleView($this->view($reviews));
}
</code>```

This retrieves a JSON with the following result:

```<code>{
 "id": 17,
 "book_i_d": {
 "id": 10,
 "author": "J.K Rowling",
 "title": "Harry Potter: Philosopher's Stone",
 "posted": "2017-01-03T04:19:18+0000",
 "summary": "Harry Potter and the Philosopher's Stone is the first novel in the Harry Potter series and J. K. Rowling's debut novel, first published in 1997 by Bloomsbury. It was published in the United States as Harry Potter and the Sorcerer's Stone by Scholastic Corporation in 1998. The plot follows Harry Potter, a young wizard who discovers his magical heritage as he makes close friends and a few enemies in his first year at the Hogwarts School of Witchcraft and Wizardry. With the help of his friends, Harry faces an attempted comeback by the dark wizard Lord Voldemort, who killed Harry's parents, but failed to kill Harry when he was just a year old.",
 "image": "cde5910f46d0e6bed33ffa18aa24ec5c.jpeg"
},
"posted": "2017-01-03T04:19:19+0000",
"review": "The author started Harry's journey with this book. It's the beginning and it's bloody brilliant!"
}
</code>```

However, as you notice.. irrelevant information of the book is retrieved. At this point, the only detail I want to retrieve of the book is the book's ID.

What can I do about this?

答:
Create specific method in the Review class

```<code>public function findAllAndOnlyBookId()
{
    $query = $this->createQueryBuilder('u')
        ->select('a.id, b.id')
        ->from('BookMainBundle\Review', 'a')
        ->leftJoin('a.book_id', 'b');
    ;

    return $query->getQuery()->getResult();
}
</code>```

And after call your method

```<code> $reviews = $this->getDoctrine()->getRepository('BookMainBundle:Review')-> findAllAndOnlyBookId();
</code>```

P.S. I don't know if the query or path is correct because I need to try It, but the concept is clear I think

Title: Excluding child values

Body:
I have a property within my Entity which links to another Entity:

 /**
 * @Groups({"bookReviews"})
 * @ORM\ManyToOne(targetEntity="Book\MainBundle\Entity\Book", inversedBy="reviews")
 * @ORM\JoinColumn(name="bookID", referencedColumnName="id")
 */
private $bookID;

Within my controller when this is called:

    public function getReviewsAction()
{
    $serializer = $this->get('serializer');
    $em = $this->getDoctrine()->getManager();
    $reviews = $em->getRepository('BookMainBundle:Review')->findAll();
    $data = $serializer->serialize($reviews, 'json', SerializationContext::create()->setGroups(array('Default')));
    return $this->handleView($this->view($reviews));
}

This retrieves a JSON with the following result:

{
 "id": 17,
 "book_i_d": {
 "id": 10,
 "author": "J.K Rowling",
 "title": "Harry Potter: Philosopher's Stone",
 "posted": "2017-01-03T04:19:18+0000",
 "summary": "Harry Potter and the Philosopher's Stone is the first novel in the Harry Potter series and J. K. Rowling's debut novel, first published in 1997 by Bloomsbury. It was published in the United States as Harry Potter and the Sorcerer's Stone by Scholastic Corporation in 1998. The plot follows Harry Potter, a young wizard who discovers his magical heritage as he makes close friends and a few enemies in his first year at the Hogwarts School of Witchcraft and Wizardry. With the help of his friends, Harry faces an attempted comeback by the dark wizard Lord Voldemort, who killed Harry's parents, but failed to kill Harry when he was just a year old.",
 "image": "cde5910f46d0e6bed33ffa18aa24ec5c.jpeg"
},
"posted": "2017-01-03T04:19:19+0000",
"review": "The author started Harry's journey with this book. It's the beginning and it's bloody brilliant!"
}

However, as you notice.. irrelevant information of the book is retrieved. At this point, the only detail I want to retrieve of the book is the book's ID.

What can I do about this?

Body:
Create specific method in the Review class

public function findAllAndOnlyBookId()
{
    $query = $this->createQueryBuilder('u')
        ->select('a.id, b.id')
        ->from('BookMainBundle\Review', 'a')
        ->leftJoin('a.book_id', 'b');
    ;

    return $query->getQuery()->getResult();
}

And after call your method

 $reviews = $this->getDoctrine()->getRepository('BookMainBundle:Review')-> findAllAndOnlyBookId();

P.S. I don't know if the query or path is correct because I need to try It, but the concept is clear I think