## PowerShell problem with array and grouping objects

I am having problems to group an array of objects by Environment. The following script show three environments with servers in each one. Now, I am trying to loop those objects by groups but getting errors with the Environment names. The following is my sample logic:

``````\$array = @(("DEVELOPMENT", ("SRV1")), ("QA", ("SRV2", "SRV3")), ("PRODUCTION", ("SRV4", "SRV5")))

ForEach (\$system in \$array) {
\$envName = \$array(0)
ForEach (\$hostname in \$system(1)) {
Write-Host ("Result for " + \$hostname + " in " + \$envName)
}
}
``````

The variable name \$envName always returns the same wrong result.

``````(0):"DEVELOPMENT"
(1):"SRV1"
``````

How can I group and loop \$array(0) and \$system(1) in the following way?

``````DEVELOPMENT = SRV1
QA          = SRV2, SRV3
PRODUCTION = SRV4, SRV5
``````

## Splitting \$n^2\$ objects into \$n\$ unordered groups

Is there a way to prove that the number of ways to split up $$n^2$$ objects into $$n$$ unordered groups of size $$n$$ is $$(((n^2)!)/((n!)^{(n+1)}))$$

Question arises from: https://artofproblemsolving.com/wiki/index.php/2019_AMC_10A_Problems/Problem_25

I tried to solve it using summation but that didn’t work.
Any ideas?

## sdl2 – How should I store the objects to render?

From what I understand, in order to show all elements of a 2D game in the proper way, I need to render them in order, from the further away from the camera to the closest. So I should sort them by depth before displaying them. Since sorting a list 60 times per second seems kinda clunky, would it be a better idea to store the objects to render in a binary search tree? Is there an ideal way to do store these objects? Or did I get something wrong? about this?

## spfx webparts – Iterate nested array of objects and append children to a particular object using jQuery/React

Iterate nested array of JSON objects and append children to a particular object using jQuery/React

We are trying to create a tree view navigation using PnP react TreeView control for SharePoint document library using SPFx web part. We are are getting and setting initial data to the component’s state by making an REST call to get first level folders.
Below is the JSON array we are setting to the component state.

``````TreeLinks: [
{
key: UniqueId,
label: "Training Documents",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Training Videos",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Training Events",
data: ServerRelativeUrl
}
]
``````

Note: “TreeLinks” is an array of type “ITreeItem” and it is state of the component.
We want to add children to a specific node on select/click event. Suppose we clicked on “Training Documents” and it’s sub folders are “SharePoint, PowerApps, Power Automate, Power BI, SQL”

Expected output.

``````TreeLinks: [
{
key: UniqueId,
label: "Training Documents",
data: ServerRelativeUrl,
children: [
{
key: UniqueId,
label: "SharePoint",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "PowerApps",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Power Automate",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Power BI",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "SQL",
data: ServerRelativeUrl
}
]
}
{
key: UniqueId,
label: "Training Videos",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Training Events",
data: ServerRelativeUrl
}
]
``````

and if we click further on “PowerApps” node, expected output

``````TreeLinks: [
{
key: UniqueId,
label: "Training Documents",
data: ServerRelativeUrl,
children: [
{
key: UniqueId,
label: "SharePoint",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "PowerApps",
data: ServerRelativeUrl,
children: [
{
key: UniqueId,
label: "Canvas Apps",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Model Driven Apps",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Portal Apps",
data: ServerRelativeUrl
}
]
}
{
key: UniqueId,
label: "Power Automate",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Power BI",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "SQL",
data: ServerRelativeUrl
}
]
}
{
key: UniqueId,
label: "Training Videos",
data: ServerRelativeUrl
}
{
key: UniqueId,
label: "Training Events",
data: ServerRelativeUrl
}
]
``````

IMPORTANT: Nesting can be upto n number of levels.

Requesting to help us out on adding children to nested array of JSON objects dynamically.

## mvc – Do Domain Objects Have To Be Persisted?

Does a domain object have to be persisted, or does this violate some convention about domain objects?

For example, let’s say I’m using an object called `AuthenticationState` to represent authentication state in the application. This object has a boolean field `isLoggedIn`. I want to force the user to re-login each time so when I start the application again, I just create a new instance of the model with `isLoggedIn` set to false, instead of attempting to load one from local device/browser storage.

I feel like I may be overthinking things, but every example I’ve found online always has its domain objects use some sort of persistence. Is using domain objects in this way still acceptable?

## classes – Class in python modifies several objects instead of just one

I have written the following piece of code (which is actually a toy example for a more complex application I have).

We have the class Points, which are basically two lists of equal length containing x et y coordinates of points. We can add a point to a Points object with the add_point method.

Then we have the LayersOfPoints class, which represents several numbered layers of Points. We can add a point to a specific layer with the add_layer_point method.

``````class Points:
def __init__(self,x_coordinates=(),y_coordinates=()):
if len(x_coordinates)!=len(y_coordinates) : raise ValueError("Each should have both a x and a y coordinate")
self.x_coordinates= x_coordinates
self.y_coordinates= y_coordinates

self.x_coordinates.append(x_coordinate)
self.y_coordinates.append(y_coordinate)

class LayersOfPoints:
def __init__(self,number_of_layers):
self.number_of_layers= number_of_layers
self.layers = (Points() for l in range(number_of_layers))

layer_of_points = LayersOfPoints(2)

print(layer_of_points.layers(0).x_coordinates,layer_of_points.layers(0).y_coordinates)
print(layer_of_points.layers(1).x_coordinates,layer_of_points.layers(0).y_coordinates)
``````

It returns

``````(12, 9) (15, 5)
(12, 9) (15, 5)
``````

While to me it should return

``````(12) (15)
(9) (5)
``````

## c# – How to deserialize dynamic Json objects?

I am currently receiving the following JSON response from my api:

``````{"Lastname":("ERRLASTNAMEEMPTY"),"Firstname":("ERRFIRSTNAMEEMPTY")}
``````

Note that the above response is dynamic – i.e sometimes I can have FirstName, sometimes LastName, sometimes both. This response is based on the validation of data.

My question is – is there a way to deserialize this response using JsonSerializer.DeSerialize?

I have tried to use it like this but it does not work:

``````var errorBody = JsonSerializer.Deserialize<dynamic>(body, serializerOptions);
``````

## combinatorics – Combinations – The number of ways of distributing n identical objects among r persons such that each person gets at least one object

So I came across this question and was unable to figure out the logic. Question –

Statement-1:
The number of ways of distributing 10 identical balls in 4 distinct boxes such that no box is empty is C(9,3) ​

Statement-2:
The number of ways of choosing any 3 places from 9 different places is C(9,3)

According to my answer key and the internet, both these statements are true. But I don’t understand how.

Shouldn’t the number of ways of distributing 10 identical balls in 4 distinct boxes such that no box is empty be C(10, 4) instead of C(9,3) ?​

## plugin development – Getting wp_post objects from a single custom INNER JOIN SQL request

I have a custom plugin (written by me) that has, for reasons, got a custom table which contains a post_id field. It makes sense in context.

What I currently do is `SELECT post_id FROM table_name WHERE conditions` which becomes an array of post IDs I `foreach` through those IDs in the template and pass them into `setup_postdata(\$id)`. Then do layout stuff. When I’m done I do a `wp_reset_postdata()` and move on.

I know this is the “WordPress way” even though this seems inefficient to me. I cannot help but wonder if it would be better to go `INNER JOIN wp_posts ON wp_posts.ID=table_name.post_id` and then bonk out an array of wp_post objects.

Is there a way to do this and is it likely to be significantly faster?

## javascript – advice for web communication protocol for “streaming” multiple JSON objects to multiple clients

As a hobby / to learn I am building an app in JavaScript using Node.js where a component of it will take input from a client, send it to a server, and then broadcast it to other clients. For simplicity let’s say that the data looks like: `{"x_pos":0.4, "y_pos":0.2}`, and specifies an avatar’s `(x,y)` position on a map in a game. I want each user to have an avatar, and each avatar’s `(x,y)` position shared.

Currently I am using Websocket (socket.io) to do this. I figured Websocket would be ideal because it is TCP, and will include an identifier of who each user is. However, the fact that communication is bidirectional seems to be sub-optimal. Additionally, I am emitting position data from all clients 30 times a second to the server, which then broadcasts it to all users. This works well for one user, but I do not know how it would scale.

However, I have also heard that UDP is ideal for games, but I understand that UDP is connectionless and doesn’t track user connections etc. So then would this mean that I would not be able to keep track of who incoming `(x,y)` data belongs to? (I suppose I could change the data to be something like `{"user":"id", "x_pos":0.4, "y_pos":0.2}` and handle updates on the Client side that way). There is also WebRTC, that uses UDP, but peer to peer connections I doubt would scale well.

So I am curious what people think is the best protocol here. Am I on the right track by using Websocket to broadcast player position? Or should I be using something else?

I would like to note I am not building a commercial app in any way, and I anticipate the load to be no more than 6 people at once for this. But 6 people * 30 emits a second to the server + 6 * 30 emits to all clients means 360 socket.io `emit()` events a second, which seems maybe not what socket.io was built for here? That said, I hear that Websocket establish a data stream, where UDP does not, so maybe that means that UDP may be more overhead? I honestly do not know and cannot find this information readily online.