问:
How to select rows of a dataframe using MultiIndex in Pandas
I have this two dataframes I need to relate.

The first one, HOLIDAYS, gives me local holiday dates and the stores code in which they're celebrated

Holiday date
Store code

01/02
18005

01/02
18032

...
...

31/03
18043

The second one, BALANCE, shows balance of stores in certain dates with date and number stores as index.

balance

01/02
18001
$35,00

01/02
18002
$38,00

...
...
...

31/03
18099
$20,45

What I need to do is to create a column in BALANCE named Holiday with a boolean value showing if a certain row is showing a balance obtained during a holiday or not.

I tried to create the column 'Holiday' setting the initial value as False and then assigning every value of HOLIDAY in index of BALANCE dataframe to True, I'm getting ValueError (possibly because a dataframe cannot be passed as index of other). I tried to convert HOLIDAY to MultiIndex but again it's not working.

BALANCE['Holiday'] = False
H = pd.MultiIndex.from_frame(HOLIDAY)
BALANCE.loc[H, 'Holiday'] = True
```

I'm pretty sure this should not be difficult but I'm out of ideas now. There is any way I could work with the first dataframe as MultiIndex of the second?

答:
Your example doesn't have any rows which match, but this should work:</p>
```<code>HOLIDAYS['is_holiday'] = True

res = pd.merge(BALANCE,
               HOLIDAYS,
               how='left',
               left_index=True,
               right_on=['Holiday_date', 'Store_code'])

res['is_holiday'] = res['is_holiday'].fillna(False)
</code>```

Body:
I have this two dataframes I need to relate.

The first one, HOLIDAYS, gives me local holiday dates and the stores code in which they're celebrated

Holiday date
Store code

01/02
18005

01/02
18032

...
...

31/03
18043

The second one, BALANCE, shows balance of stores in certain dates with date and number stores as index.

balance

01/02
18001
$35,00

01/02
18002
$38,00

...
...
...

31/03
18099
$20,45

What I need to do is to create a column in BALANCE named Holiday with a boolean value showing if a certain row is showing a balance obtained during a holiday or not.

I tried to create the column 'Holiday' setting the initial value as False and then assigning every value of HOLIDAY in index of BALANCE dataframe to True, I'm getting ValueError (possibly because a dataframe cannot be passed as index of other). I tried to convert HOLIDAY to MultiIndex but again it's not working.

BALANCE['Holiday'] = False
H = pd.MultiIndex.from_frame(HOLIDAY)
BALANCE.loc[H, 'Holiday'] = True

I'm pretty sure this should not be difficult but I'm out of ideas now. There is any way I could work with the first dataframe as MultiIndex of the second?

Body:
Your example doesn't have any rows which match, but this should work:

HOLIDAYS['is_holiday'] = True

res = pd.merge(BALANCE,
               HOLIDAYS,
               how='left',
               left_index=True,
               right_on=['Holiday_date', 'Store_code'])

res['is_holiday'] = res['is_holiday'].fillna(False)


来源: stackexchange

问:
What is the hash function for a normal class and why don't dataclasses have the same hash function?
Following is an example where the dataclass "fails" to be hashable but the normal class does produce a hash value fine.

Why does this work given that the normal class has the np.ndarray as well and should be unhashable?

```<code>import numpy as np
from dataclasses import dataclass

class X:
    def __init__(self):
        x = np.ndarray([0,1,1,0,110])

@dataclass(frozen=True, eq=True)
class Y:
    name: str
    unit_price: np.ndarray

a = X()
print(a.__hash__())

b = Y(10, np.array([0,1,2]))
print(b.__hash__())

</code>```

Ouput:

```<code>8787234869218
Traceback (most recent call last):
  File "t.py", line 37, in <module>
    print(b.__hash__())
  File "<string>", line 3, in __hash__
TypeError: unhashable type: 'numpy.ndarray'
</code>```

答:
Because you used:

```<code>@dataclass(frozen=True, eq=True)
</code>```

The rules here are described in the docs:

If eq and frozen are both true, by default dataclass() will generate a
__hash__() method for you. If eq is true and frozen is false, __hash__() will be set to None, marking it unhashable (which it is, since it is mutable). If eq is false, __hash__() will be left
untouched meaning the __hash__() method of the superclass will be used
(if the superclass is object, this means it will fall back to id-based
hashing).

The dataclass generated a hash function that is hashing based on the attributes. Of course, it doesn't actually work because you used a numpy.ndarray.

By default, user-defined objects inherit object.__hash__, which just hashes based on identity, pretty much return id(self) (although not exactly).

The two won't behave the same, in the first case, because you told the dataclass code generator to make an "immutable" type with a corresponding __eq__ that is based on the attributes of the object.  The hash, of course, is consistent with the __eq__ and is based on the values of the attributes. In the second case, the hash (and equality) is based on the identity of the object.

To illustrate these differences:

```<code>>>> from dataclasses import dataclass
>>> @dataclass(frozen=True, eq=True)
... class Point1:
...     x: int
...     y: int
...
>>> points = set()
>>> points.add(Point1(0, 0))
>>> Point1(0, 0) in points
True
</code>```

So notice, a different point object with the same value was in the set.

However, here is how identity based hashing/equality would function:

```<code>>>> class Point2:
...     def __init__(self, x, y):
...         self.x = x
...         self.y = y
...
>>> p = Point2(0, 0)
>>> points = set()
>>> points.add(p)
>>> Point2(0, 0) in points
False
>>> p in points
True
</code>```

ContentLicense: CC BY-SA 4.0

Body:
Following is an example where the dataclass "fails" to be hashable but the normal class does produce a hash value fine.

Why does this work given that the normal class has the np.ndarray as well and should be unhashable?

import numpy as np
from dataclasses import dataclass

class X:
    def __init__(self):
        x = np.ndarray([0,1,1,0,110])

@dataclass(frozen=True, eq=True)
class Y:
    name: str
    unit_price: np.ndarray

a = X()
print(a.__hash__())

b = Y(10, np.array([0,1,2]))
print(b.__hash__())

Ouput:

8787234869218
Traceback (most recent call last):
  File "t.py", line 37, in <module>
    print(b.__hash__())
  File "<string>", line 3, in __hash__
TypeError: unhashable type: 'numpy.ndarray'

Body:
Because you used:

@dataclass(frozen=True, eq=True)

The rules here are described in the docs:

If eq and frozen are both true, by default dataclass() will generate a
__hash__() method for you. If eq is true and frozen is false, __hash__() will be set to None, marking it unhashable (which it is, since it is mutable). If eq is false, __hash__() will be left
untouched meaning the __hash__() method of the superclass will be used
(if the superclass is object, this means it will fall back to id-based
hashing).

The dataclass generated a hash function that is hashing based on the attributes. Of course, it doesn't actually work because you used a numpy.ndarray.

By default, user-defined objects inherit object.__hash__, which just hashes based on identity, pretty much return id(self) (although not exactly).

The two won't behave the same, in the first case, because you told the dataclass code generator to make an "immutable" type with a corresponding __eq__ that is based on the attributes of the object.  The hash, of course, is consistent with the __eq__ and is based on the values of the attributes. In the second case, the hash (and equality) is based on the identity of the object.

To illustrate these differences:

>>> from dataclasses import dataclass
>>> @dataclass(frozen=True, eq=True)
... class Point1:
...     x: int
...     y: int
...
>>> points = set()
>>> points.add(Point1(0, 0))
>>> Point1(0, 0) in points
True

So notice, a different point object with the same value was in the set.

However, here is how identity based hashing/equality would function:

>>> class Point2:
...     def __init__(self, x, y):
...         self.x = x
...         self.y = y
...
>>> p = Point2(0, 0)
>>> points = set()
>>> points.add(p)
>>> Point2(0, 0) in points
False
>>> p in points
True


问:
AWS ECS ALB Error (Request timed out)
I am trying to learn/use AWS ECS but keep getting

service  has reached a steady state.

Followed by:

service  (instance i-05873e2a55ecba2f6) (port 32768) is unhealthy in target-group  due to (reason Request timed out)

I'm not really sure which info you need to help, but I was using this load balancer across EC2 instances before, but I am replacing those EC2 instances with ones launched through ECS and now I am running into this error.

My cluster is in my default VPC and I am including all 3 subnets (East zone). The security group is my load balancer security group which allows all traffic on ports 40 and 443. I have tried changing security group so that it allows anyone on any port but that doesn't work.

My host port in my task definition is 0 and my container port is 3000 which is what I exposed in Dockerfile.

The healthcheck is just on the target port at path "/"

答: Remember to check the outbound rule of your ALB security group. Target group health check actually issues the request from ALB. So if your ALB is not allowed to talk to your target, it will also fail.</p>

ContentLicense: CC BY-SA 3.0

Title: AWS ECS ALB Error (Request timed out)


问:
PHP WebServer hosted in Google Cloud Run environment: persist files (images)
I have built and deployed a PHP-based website hosted in a Google Cloud Run container where images sit in a /images folder and a link to each image is stored in a MySQL database hosted in a Google Cloud VM. All this works well.

Now I'm working on an admin function to upload images to the web server. There are plenty of resources available for uploading images (and I've developed a similar solution before) including PHP handling file uploads. So no perceived issues there.

My challenge is that any files (images) uploaded to the web server will be destroyed when I redeploy my code to the container (content is wiped when the container is stopped).

I found this resource which suggests that Google Cloud Storage would be an appropriate solution. What I can't find, though, is any guidance on how to connect my Google Cloud Run instance to a Google Cloud Storage location, or how to point a folder within the Google Cloud Run instance to Google Cloud Storage. I can see that Firestore is another option. Cloud SQL is not an option for me as I don't wish to store the images in the database (though I could if this were considered the best option for my environment).

Ironically, Google (the search engine) is not being my friend here and I'm struggling to find guidance on how to go about achieving my objective. Are you aware of a resource the explains at least the basics of how to do this?

答:
An approach you can consider is to mount Google Cloud Storage buckets using gcsfuse.

Mounting a file system allows for sharing resources between a host system and container instances and for resources to persist after a container instance is garbage collected.

Here's a sample Dockerfile:

```<code># https://github.com/chiaen/docker-gcsfuse
FROM golang:1.17.5-alpine as gcsfuse
RUN apk add --no-cache git
ENV GOPATH /go
RUN go get -u github.com/googlecloudplatform/gcsfuse

FROM composer:2 as vendor
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --ignore-platform-reqs --no-interaction --prefer-dist

FROM craftcms/nginx:7.4

ENV MNT_DIR /mnt/gcs

USER root
RUN apk add --no-cache mysql-client postgresql-client ca-certificates fuse nano sudo tini bash
RUN mkdir -p $MNT_DIR
RUN chown www-data:www-data $MNT_DIR

COPY --chown=www-data:www-data --from=vendor /app/vendor/ /app/vendor/
COPY --chown=www-data:www-data . .
COPY --from=gcsfuse /go/bin/gcsfuse /usr/local/bin
COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf
</code>```

Body:
An approach you can consider is to mount Google Cloud Storage buckets using gcsfuse.

Mounting a file system allows for sharing resources between a host system and container instances and for resources to persist after a container instance is garbage collected.

Here's a sample Dockerfile:

# https://github.com/chiaen/docker-gcsfuse
FROM golang:1.17.5-alpine as gcsfuse
RUN apk add --no-cache git
ENV GOPATH /go
RUN go get -u github.com/googlecloudplatform/gcsfuse

FROM composer:2 as vendor
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --ignore-platform-reqs --no-interaction --prefer-dist

FROM craftcms/nginx:7.4

ENV MNT_DIR /mnt/gcs

USER root
RUN apk add --no-cache mysql-client postgresql-client ca-certificates fuse nano sudo tini bash
RUN mkdir -p $MNT_DIR
RUN chown www-data:www-data $MNT_DIR

COPY --chown=www-data:www-data --from=vendor /app/vendor/ /app/vendor/
COPY --chown=www-data:www-data . .
COPY --from=gcsfuse /go/bin/gcsfuse /usr/local/bin
COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf


问:
Error while trying to use the following icon from the Manifest
While running react app my console always shows this error message.

```<code>> "Error while trying to use the following icon from the Manifest:
> http://localhost:3000/favicon.ico (Resource size is not correct - typo
> in the Manifest?)"
</code>```

Why this is showing?

答: Try to change the "x" to "*"</p>

Body:
While running react app my console always shows this error message.

> "Error while trying to use the following icon from the Manifest:
> http://localhost:3000/favicon.ico (Resource size is not correct - typo
> in the Manifest?)"

Why this is showing?

Body: Try to change the "x" to "*"


问:
Signature Creating for txt files
I am making a code that is counting all the words in a text file and is supposed to sort the top 25 most occurring words in the text file, which is known as a signature, and then store it in a list. Next, it is supposed to compare the signatures using the Jaccard Similarity Measure. I have the code for Jaccard similarity but I need to modify it for my program since I took it from a different example. The code that is creating the signature is giving me this error:
Column 'Prophet' has dtype object, cannot use method 'nlargest' with this type</p>
```<code>I was doing research on ways to how I can sort all the words by the top 25 most common ones and this is the most efficient way but it's giving me this error. Is there another way that I can sort this out? Also, how would I then add the 25 words into a new list for each text? Any feedback is greatly appreciated. Please show the change in code. Thanks in advance!

</code>```

答:
Cause of error:

nlargest cannot act on object column such as a string column, and because in your df there is at least one column (except for "Word") that is an object column, so it raised the error at that column.

Fix of error:

print(df.dtypes) to inspect the data type of each column, and either not to apply nlargest on object column, or convert object column to other type (such as int, float).

how I can sort all the words by the top 25 most common ones and this is the most efficient way ... Is there another way that I can sort this out?

I think nlargest should be your choice, just make sure the column that you are applying nlargest is the number of counts of the corresponding word. Also, if you have such column, you don't actually need to use a loop to iterate over all columns, because you only need to do nlargest on that particular column.

Also, how would I then add the 25 words into a new list for each text?

Refers to this example

```<code>df = pd.DataFrame({
    'Word': ['happy', 'hello', 'you', 'he', 'she', 'it'],
    'Count': [27, 32,19, 6,80, 5]
})

largest = df.set_index('Word')['Count'].nlargest(3)
print(largest)
</code>```

Output:

```<code>Word
she      80
hello    32
happy    27
Name: Count, dtype: int64
</code>```

You will get a pd.Series of the (3) largest counts, and the corresponding word as the index. Then you can extract the index and convert it into a list by

```<code>largest.index.tolist()
</code>```

Lastly, if your dataframe has a different column format from my example above, it would be better for you to convert yours into mine. If you are not sure how to convert, you need to share a subdataframe here for us to look at. You can export the first 10 rows of your dataframe by print(df.head(10).to_dict('list')) and paste the outcome as text in your question.

Title: Signature Creating for txt files

Body:
I am making a code that is counting all the words in a text file and is supposed to sort the top 25 most occurring words in the text file, which is known as a signature, and then store it in a list. Next, it is supposed to compare the signatures using the Jaccard Similarity Measure. I have the code for Jaccard similarity but I need to modify it for my program since I took it from a different example. The code that is creating the signature is giving me this error:
Column 'Prophet' has dtype object, cannot use method 'nlargest' with this type

I was doing research on ways to how I can sort all the words by the top 25 most common ones and this is the most efficient way but it's giving me this error. Is there another way that I can sort this out? Also, how would I then add the 25 words into a new list for each text? Any feedback is greatly appreciated. Please show the change in code. Thanks in advance!

Body:
Cause of error:

nlargest cannot act on object column such as a string column, and because in your df there is at least one column (except for "Word") that is an object column, so it raised the error at that column.

Fix of error:

print(df.dtypes) to inspect the data type of each column, and either not to apply nlargest on object column, or convert object column to other type (such as int, float).

how I can sort all the words by the top 25 most common ones and this is the most efficient way ... Is there another way that I can sort this out?

I think nlargest should be your choice, just make sure the column that you are applying nlargest is the number of counts of the corresponding word. Also, if you have such column, you don't actually need to use a loop to iterate over all columns, because you only need to do nlargest on that particular column.

Also, how would I then add the 25 words into a new list for each text?

Refers to this example

df = pd.DataFrame({
    'Word': ['happy', 'hello', 'you', 'he', 'she', 'it'],
    'Count': [27, 32,19, 6,80, 5]
})

largest = df.set_index('Word')['Count'].nlargest(3)
print(largest)

Output:

Word
she      80
hello    32
happy    27
Name: Count, dtype: int64

You will get a pd.Series of the (3) largest counts, and the corresponding word as the index. Then you can extract the index and convert it into a list by

largest.index.tolist()

Lastly, if your dataframe has a different column format from my example above, it would be better for you to convert yours into mine. If you are not sure how to convert, you need to share a subdataframe here for us to look at. You can export the first 10 rows of your dataframe by print(df.head(10).to_dict('list')) and paste the outcome as text in your question.


问:
How to format a nested multiple-value-bind the let way?
Recently, I've been often nesting several functions that return multiple values. However, unlike let, which me allows to write these calls elegantly into one big statement, I always end up with a lot of indentation.

My question is: having several multiple-valued functions such as

(defun return-1-and-2 ()
  (values 1 2))

(defun return-3-and-4 ()
  (values 3 4))
```

<p>is it possible to achieve the same as</p>

```(multiple-value-bind (one two)
    (return-1-and-2)
  (multiple-value-bind (three four)
      (return-3-and-4)
    (list one two three four)))
```

<p>but write it more concisely the <code>let</code>-way, i.e., something like</p>

<pre class="lang-lisp prettyprint-override"><code>(multiple-let (((one two) (return-1-and-2))
               ((three four) (return-3-and-4)))
  (list one two three four))
</code>```

?

答:
I extended the above to allow let to handle not just   multiple-value-bind but also labels.  My code is a little simpler than serapeum's since they handle more cool cases than me. For example in serapeum's code, if a let+ has no special features, it expands to a normal let*. By ignoring those  cool features, I get to write it all in just a dozen lines:

```<code>(defun %let+ (body xs)
  (labels ((fun (x) (and (listp x) (> (length x) 2)))
           (mvb (x) (and (listp x) (listp (car x)))))
    (if (null xs)
      body
      (let ((x (pop xs)))
        (cond
          ((fun x) `(labels ((,(pop x) ,(pop x) ,@x))       ,(%let+ body xs)))
          ((mvb x) `(multiple-value-bind ,(pop x) ,(pop x) ,@(%let+ body xs)))
          (t       `(let (,x)                          ,(%let+ body xs))))))))

(defmacro let+ (spec &rest body) (%let+ body spec))
</code>```

In this let+ macro...

(let+ (x (y 1))... expands as normal

(let+ ((fn1 (arg1 arg1b) body1))...  wraps fn1 in labels.

(let+ ((arg2a arg2b) body2))... does a multiple-value-bind on body2, binding its results to arg2a arg2b.

Example:

```<code>(defun fn2 (x y ) (values x (+ x y)))

(defun test-let+(&optional (x 1))
  (let+ (z                          ; normal let stuff
         (y 1)                      ; normal let stuff
         (z 2)                      ; normal let stuff
         (fn1 (x y) (+ x y))        ; define a local function
         ((a b) (fn2 x (fn1 y z)))) ; call multiple-value-bind
      (format t "~&a ~a b ~a x ~a y ~a z ~a~%" a b x y z)))
</code>```

Which expands into this:

```<code>(DEFUN TEST-LET+ (&OPTIONAL (X 1))
  (LET (Z)
    (LET ((Y 1))
      (LET ((Z 2))
        (LABELS ((FN1 (X Y)
                   (+ X Y)))
          (MULTIPLE-VALUE-BIND (A B)
              (FN2 X (FN1 Y Z))
            (FORMAT T "a ~a b ~a x ~a y ~a z ~a~%" A B X Y Z)))))))
</code>```

And runs like this....

```<code>> (test-let+)

a 1 b 4 x 1 y 1 z 2
</code>```

Body:
Recently, I've been often nesting several functions that return multiple values. However, unlike let, which me allows to write these calls elegantly into one big statement, I always end up with a lot of indentation.

My question is: having several multiple-valued functions such as

(defun return-1-and-2 ()
  (values 1 2))

(defun return-3-and-4 ()
  (values 3 4))

is it possible to achieve the same as

(multiple-value-bind (one two)
    (return-1-and-2)
  (multiple-value-bind (three four)
      (return-3-and-4)
    (list one two three four)))

but write it more concisely the let-way, i.e., something like

(multiple-let (((one two) (return-1-and-2))
               ((three four) (return-3-and-4)))
  (list one two three four))

?

Body:
I extended the above to allow let to handle not just   multiple-value-bind but also labels.  My code is a little simpler than serapeum's since they handle more cool cases than me. For example in serapeum's code, if a let+ has no special features, it expands to a normal let*. By ignoring those  cool features, I get to write it all in just a dozen lines:

(defun %let+ (body xs)
  (labels ((fun (x) (and (listp x) (> (length x) 2)))
           (mvb (x) (and (listp x) (listp (car x)))))
    (if (null xs)
      body
      (let ((x (pop xs)))
        (cond
          ((fun x) `(labels ((,(pop x) ,(pop x) ,@x))       ,(%let+ body xs)))
          ((mvb x) `(multiple-value-bind ,(pop x) ,(pop x) ,@(%let+ body xs)))
          (t       `(let (,x)                          ,(%let+ body xs))))))))

(defmacro let+ (spec &rest body) (%let+ body spec))

In this let+ macro...

(let+ (x (y 1))... expands as normal

(let+ ((fn1 (arg1 arg1b) body1))...  wraps fn1 in labels.

(let+ ((arg2a arg2b) body2))... does a multiple-value-bind on body2, binding its results to arg2a arg2b.

Example:

(defun fn2 (x y ) (values x (+ x y)))

(defun test-let+(&optional (x 1))
  (let+ (z                          ; normal let stuff
         (y 1)                      ; normal let stuff
         (z 2)                      ; normal let stuff
         (fn1 (x y) (+ x y))        ; define a local function
         ((a b) (fn2 x (fn1 y z)))) ; call multiple-value-bind
      (format t "~&a ~a b ~a x ~a y ~a z ~a~%" a b x y z)))

Which expands into this:

(DEFUN TEST-LET+ (&OPTIONAL (X 1))
  (LET (Z)
    (LET ((Y 1))
      (LET ((Z 2))
        (LABELS ((FN1 (X Y)
                   (+ X Y)))
          (MULTIPLE-VALUE-BIND (A B)
              (FN2 X (FN1 Y Z))
            (FORMAT T "a ~a b ~a x ~a y ~a z ~a~%" A B X Y Z)))))))

And runs like this....

> (test-let+)

a 1 b 4 x 1 y 1 z 2


问:
How do I extract form data in html with js
I'm trying to create a web app, and I need to know the user input from form.

<form action="" method="get" class="settings">

      length of character(s):
      <input type="number" name="length" id="length" placeholder="5" required>
      <input type="submit" value="Change">

  </form>```
</div>
</div>
</p>
<p>I need the form to run a js func foo()
so I assume that I need to put it</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><form action="" method="get" class="settings">
              ↑</code>```

how do I get the value of id="length" and use it in form action"foo()"?

答:
You can get the value of length with document.getElementById("id").value;

In order to run a js from form, you need to use onsubmit="" instead of action=""

onsubmit="" allows you to execute a js function upon submission of the form,
while action="" allows you to be redirected to another page/site upon submission.

Read more about action="" in this site

onsubmit="" is here

Here is a workable code based on your example

function foo(){
  var lgt = document.getElementById("length").value;
  alert(lgt);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form class="settings" onsubmit="foo()">
    <div class="settings">
      <label for="length">length of character(s): </label>
      <input type="number" name="length" id="length" placeholder="5" required>
      <input type="submit" value="Change">
    </div>
  </form></code>```

Body:
I'm trying to create a web app, and I need to know the user input from form.

<form action="" method="get" class="settings">

      length of character(s):
      <input type="number" name="length" id="length" placeholder="5" required>
      <input type="submit" value="Change">

  </form>

I need the form to run a js func foo()
so I assume that I need to put it

<form action="" method="get" class="settings">
              ↑

how do I get the value of id="length" and use it in form action"foo()"?

Body:
You can get the value of length with document.getElementById("id").value;

In order to run a js from form, you need to use onsubmit="" instead of action=""

onsubmit="" allows you to execute a js function upon submission of the form,
while action="" allows you to be redirected to another page/site upon submission.

Read more about action="" in this site

onsubmit="" is here

Here is a workable code based on your example

function foo(){
  var lgt = document.getElementById("length").value;
  alert(lgt);
}

<form class="settings" onsubmit="foo()">
    <div class="settings">
      <label for="length">length of character(s): </label>
      <input type="number" name="length" id="length" placeholder="5" required>
      <input type="submit" value="Change">
    </div>
  </form>


问:
Flickity carousel doesn't work when
 are generated with js
i have found a carousel based on Flickity, you can check it here:

https://codepen.io/atelierbram/pen/LRkAxQ thanks to atelierbram

now i want to generate the  containing the images with JS and i made the following code:

```<code><head>
    <script   src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>

<link rel="stylesheet" href="flickity.css"></head>
<h1>Image slider with Thumbnails and Flickity - asNavFor</h1>

<div class="container">
<!-- Flickity HTML init -->
<div id="img_c" class="carousel carousel-main" data-flickity='{"pageDots": false }'>

</div>

<div id="img_d" class="carousel carousel-nav"
  data-flickity='{ "asNavFor": ".carousel-main", "contain": true, "pageDots": false }'>

</div>

</div><!-- /.container -->

<script>
    var folder = 'img/';
var carousel = 'carousel-cell';
var img_thumb='120px';
    $.ajax({
        url : folder,
        success: function (data) {
            $(data).find('a').attr('href', function (i, val) {
                if (val.match(/\.(jpe?g|png|gif)$/)) {
                    for (var i = 1; i <= 1; i++) {
                       $('<div class='+carousel+' ><img src=' + val + '></div>').appendTo(img_c);
                       $('<div class='+carousel+' ><img src=' + val + ' width='+img_thumb+'></div>').appendTo(img_d);

                    }
                }
            });
        }

    });

</script>

<script>$(document).on('ready', function() {
   document.write('<script type="text/javascript" src="flickity.js">');
});</script>
</code>```

The problem is that Flickity is not fired properly and it doesn't append any value to

the output of my code is

```<code><div id="img_c" class="carousel carousel-main" data-flickity="{"pageDots": false }">

<div class="carousel-cell"><img src="/img/100271519.jpg"></div><div class="carousel-cell"><img src="img/140178627_04.jpg"></div><div class="carousel-cell"><img src="img/200157969.jpg"></div><div class="carousel-cell"><img src="img/200157969_13.jpg"></div></div>
</code>```

And the output should be like:

```<code><div class="container">
<!-- Flickity HTML init -->
<div class="carousel carousel-main flickity-enabled is-draggable" data-flickity="{ "asNavFor": ".carousel-main", "contain": true, "pageDots": false }" tabindex="0">

<div class="flickity-viewport" style="height: 504px; touch-action: pan-y;"><div class="flickity-slider" style="left: 0px; transform: translateX(0%);"><div class="carousel-cell is-selected" style="position: absolute; left: 0%;"><img src="//via.placeholder.com/672x504/3391cc/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 101.19%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/3366cc/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 202.38%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/394cc6/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 303.57%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/5946b9/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 404.76%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/8946b9/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 505.95%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/bf409f/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 607.14%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/d92f26/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 708.33%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/d2562d/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 809.52%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/d98026/ffffff"></div><div class="carousel-cell" style="position: absolute; left: 910.71%;" aria-hidden="true"><img src="//via.placeholder.com/672x504/cca633/ffffff"></div></div></div><button class="flickity-button flickity-prev-next-button previous" type="button" disabled="" aria-label="Previous"><svg class="flickity-button-icon" viewBox="0 0 100 100"><path d="M 10,50 L 60,100 L 70,90 L 30,50  L 70,10 L 60,0 Z" class="arrow"></path></svg></button><button class="flickity-button flickity-prev-next-button next" type="button" aria-label="Next"><svg class="flickity-button-icon" viewBox="0 0 100 100"><path d="M 10,50 L 60,100 L 70,90 L 30,50  L 70,10 L 60,0 Z" class="arrow" transform="translate(100, 100) rotate(180) "></path></svg></button></div>

<div class="carousel carousel-nav flickity-enabled is-draggable" data-flickity="{ "asNavFor": ".carousel-main", "contain": true, "pageDots": false }" tabindex="0">
</code>```

Can anyone help me to get the right output?

Thank you!

答: I found the Flickity being loaded twice somewhere, this cause the problem.</p>

Title: Flickity carousel doesn't work when <div> are generated with js

Body:
i have found a carousel based on Flickity, you can check it here:

https://codepen.io/atelierbram/pen/LRkAxQ thanks to atelierbram

now i want to generate the  containing the images with JS and i made the following code:

<link rel="stylesheet" href="flickity.css">

Image slider with Thumbnails and Flickity - asNavFor

The problem is that Flickity is not fired properly and it doesn't append any value to

the output of my code is

And the output should be like:

<button class="flickity-button flickity-prev-next-button previous" type="button" disabled="" aria-label="Previous"><svg class="flickity-button-icon" viewBox="0 0 100 100"><path d="M 10,50 L 60,100 L 70,90 L 30,50  L 70,10 L 60,0 Z" class="arrow"></path></svg></button><button class="flickity-button flickity-prev-next-button next" type="button" aria-label="Next"><svg class="flickity-button-icon" viewBox="0 0 100 100"><path d="M 10,50 L 60,100 L 70,90 L 30,50  L 70,10 L 60,0 Z" class="arrow" transform="translate(100, 100) rotate(180) "></path></svg></button>

Can anyone help me to get the right output?

Thank you!


问:
Running tasks in a specific time in airflow
I have 3 tasks in an airflow dag.

These three tasks have time dependency

Task 1 - 8 am morning

Task - 2 - 10 am morning

Task -3 - 12 am

I'm not finding any doc referring to that. Its telling to set upstream or downstream jobs only. Could anyone helps on this

I'm using Google CLoud Composer

答: You can use a TimeSensor. Add a time sensor as a sub-task that keeps polling whether the time point has passed.  Although it is less elegant, it works.</p>


问:
Getting "corrupted size vs. prev_size" in C++
I'm trying to create a program to print a 2D matrix after reading in data from a file.

My program works fine if the 2D matrix is a square with equal X & Y values, but I get the "corrupted size vs. prev_size" error if its a rectangle, for example with x=8 and y=10.

Here is an example of what it should look like if run successfully (where x is 8 and y is 8):

```<code>  # # # # # # # # # # #
8 #     2 2           #
7 #     2 2       1   #
6 #                   #
5 #                   #
4 #                   #
3 #   3 3 3           #
2 #   3 3 3           #
1 #   3 3 3           #
0 #                   #
  # # # # # # # # # # #
    0 1 2 3 4 5 6 7 8
</code>```

When I try to use a configuration file where x is 8 and y is 10 I get the error as such:

```<code>Please enter your choice : 1

[ Read in and process a configuration file ]
Please enter config filename : TestCases_Config.txt

Reading in GridX_IdxRange : GridX_IdxRange=0-8 ... done!
Reading in GridY_IdxRange : GridY_IdxRange=0-10 ... done!

Storing data from input file :
*** Error in `./csci251_a1.exe': corrupted size vs. prev_size: 0x08e63d40 ***
Aborted (core dumped)
</code>```

This is what my code looks like:

```<code>#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm> // To use unique function
#include <iomanip> // For setprecision
#include <vector> // To use vectors

using namespace std;

// Struct to store the maximum grid values from config file
struct gridSize
{
    int gridXHighestVal;
    int gridYHighestVal;

    string toString();
};

// Struct object to store individual grid tile details
struct gridTileDetails
{
    int x, y;
    bool isOccupied;
    int cityID;
    string cityName;
    int cloudIndex, singleCloudIndex, pressureIndex, singlePressureIndex;
    char cloudLMH, pressureLMH;

    string toString();
};

gridSize gridSize; // Global gridSize struct to be used to obtain maximum X & Y values
gridTileDetails **grid; // Global pointer-to-pointer variable to be used for dynamically allocating 2D array

// All function/method prototypes
// Functions for reading of data (Menu option #1)
gridTileDetails processConfigFile();
gridTileDetails readCityFile(string);
gridTileDetails readCloudFile(string);
gridTileDetails readPressureFile(string);

// Functions for menu options #2 - #7
void displayCityMap(int, int);
void displayCloudMap(int, int);
void displayCloudMapLMH(int, int);
void displayPressureMap(int, int);
void displayPressureMapLMH(int, int);
void generateWeatherReport(int, int);

// Helper functions
void safelyDeallocateMemory (int arrayCols, gridTileDetails **grid);
vector<string> tokenizeString(string, string);
vector<int> removeDuplicates(vector<int> &vec);
char getLMH(int);
int printCity(int, int, vector<int> , int);
double calculateRain(char, char);
void printRain(double);

int main()
{

    int userChoice;

    // Main menu to run constantly until user enters 8
    while (userChoice != 8)
    {
        cout << "Welcome to Weather Information Processing System!" << endl;

        cout << endl;

        cout << "1)\tRead in and process a configuration file" << endl;
        cout << "2)\tDisplay city map" << endl;
        cout << "3)\tDisplay cloud coverage map (cloudiness index)" << endl;
        cout << "4)\tDisplay cloud coverage map (LMH symbols)" << endl;
        cout << "5)\tDisplay atmospheric pressure map (pressure index)" << endl;
        cout << "6)\tDisplay atmospheric pressure map (LMH symbols)" << endl;
        cout << "7)\tShow forecast summary report" << endl;
        cout << "8)\tQuit" << endl;

        cout << endl;

        cout << "Please enter your choice : ";
        cin >> userChoice;

        cout << endl;

        switch (userChoice)
        {
            case 1:
                // Process configuration file
                **grid = processConfigFile();
                break;
            case 2:
                // Display city map
                displayCityMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 3:
                // Display cloud coverage map (cloudiness index)
                displayCloudMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 4:
                // Display cloud coverage map (LMH symbols)
                displayCloudMapLMH(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 5:
                // Display atmospheric pressure map (pressure index)
                displayPressureMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 6:
                // Display atmospheric pressure map (LMH symbols)
                displayPressureMapLMH(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 7:
                // Show weather forecast summary report
                generateWeatherReport(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 8:
                // Message to be shown for quiting program
                cout << "Thank you for using the Weather Information Processing System!" << endl;
                break;
            default:
                cout << "Please enter a valid input!" << endl << endl;
        }
    }

    safelyDeallocateMemory (gridSize.gridXHighestVal, grid);

    return (0);
}

// Begin reading of files
gridTileDetails processConfigFile()
{
    string filename;

    cout << "[ Read in and process a configuration file ]" << endl;
    cout << "Please enter config filename : ";
    cin >> filename;

    cout << endl;

    // Create fstream object
    fstream input_file(filename.c_str(), fstream::in);

    string aline;
    string gridX = "GridX_IdxRange";
    string gridY = "GridY_IdxRange";

    while (getline(input_file, aline)) // With input_file as the source, store each "line" into our string variable aline;
    {

        if (aline.find(gridX) != string::npos) // If "GridX_IdxRange" is found within aline
        {
            string numString = aline.substr(15); // Obtain only the number range portion of string

            vector<string> individualNums = tokenizeString(numString, "-"); // Use "-" as delimiter to obtain individual numbers

            int gridX = stoi(individualNums[1]); // Convert string to an int variable

            gridSize.gridXHighestVal = gridX; // Store grid X maximum value into custom struct object

            cout << "Reading in GridX_IdxRange : " << aline << " ... done!" << endl;
            individualNums.clear();
        }

        if (aline.find(gridY) != string::npos) // If "GridY_IdxRange" is found within aline
        {

            string numString = aline.substr(15); // Obtain only the number range portion of string

            vector<string> individualNums = tokenizeString(numString, "-"); // Use "-" as delimiter to obtain individual numbers

            int gridY = stoi(individualNums[1]); // Convert string to an int variable

            gridSize.gridYHighestVal = gridY; // Store grid Y maximum value into custom struct object

            cout << "Reading in GridY_IdxRange : " << aline << " ... done!" << endl;
            individualNums.clear();
        }

        if (gridSize.gridXHighestVal != 0 && gridSize.gridYHighestVal != 0) // Break out of the while-loop if both X & Y values are populated, to continue processing
        {
            break;
        }
    }

    cout << endl;

    // Dynamic memory allocation for 2D array
    grid = new gridTileDetails * [gridSize.gridXHighestVal + 1];
    for (int i = 0; i < gridSize.gridYHighestVal + 1; i++)
    {
        grid[i] = new gridTileDetails[gridSize.gridYHighestVal + 1];
    }

    // Putting x (columns) and y (rows) values into 2D array
    for (int col = 0; col < gridSize.gridXHighestVal + 1; col++)
    {
        for (int row = 0; row < gridSize.gridYHighestVal + 1; row++)
        {
            grid[col][row].x = col;
            grid[col][row].y = row;
        }
    }

    int fileCounter = 0; // File counter variable to decide which file method to use
    cout << "Storing data from input file :" << endl;

    while (getline(input_file, aline))
    {

        if (aline.find(".txt") != string::npos) // If aline contains ".txt" at the end, we know it is one of the configuration files
        {

            switch (fileCounter)
            {
                case 0: // Get city details
                    **grid = readCityFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
                case 1: // Get cloud details
                    **grid = readCloudFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
                case 2: // Get pressure details
                    **grid = readPressureFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
            }
            fileCounter++;
        }

    }
    cout << endl;

    cout << "All records successfully stored. Going back to main menu ..." << endl;

    cout << endl;

    return **grid;
}

// Method for reading city file
gridTileDetails readCityFile(string filename)
{

    // Create fstream object
    fstream input_file(filename.c_str(), fstream::in);

    string aline;

    while (getline(input_file, aline))
    {
        if (aline == "")
        {
            break;
        }

        vector<string> allConfigInfo = tokenizeString(aline, "-"); // Separates all data with delimiter "-" Eg. [1,1] 3 Big_City

        string gridString = allConfigInfo[0]; // Gets part of vector storing grid info
        string cityID = allConfigInfo[1];
        string cityName = allConfigInfo[2];

        gridString = gridString.substr(1, gridString.size() - 2); // Removes [ and ] brackets

        vector<string> gridValues = tokenizeString(gridString, ", "); // Get individual grid values

        // Get grid values
        int gridX = stoi(gridValues[0]);
        int gridY = stoi(gridValues[1]);

        // Get city ID
        int intCityID = stoi(cityID);

        // Inserting values into 2D array
        grid[gridX][gridY].cityID = intCityID;
        grid[gridX][gridY].isOccupied = true;
        grid[gridX][gridY].cityName = cityName;

    }
    return **grid;
}
</code>```

I suspect the issues lies with the reading of the other files and populating the 2D array with its data (city, cloud, pressure files) but I can't seem to understand where I went wrong.

I tried commenting out the bottom portion of processConfigFile just to see if the 2D array gets created correctly without inserting any information to each tile and although the alignment got messed up a little, it worked (where x is 8 and y is 10):

```<code>  # # # # # # # # # # #
10 #                   #
9 #                   #
8 #                   #
7 #                   #
6 #                   #
5 #                   #
4 #                   #
3 #                   #
2 #                   #
1 #                   #
0 #                   #
  # # # # # # # # # # #
    0 1 2 3 4 5 6 7 8
</code>```

I didn't include the code for the reading of the other files as its mostly the same, just with some minor adjustments.

Any help provided would be greatly appreciated!

答:
Well, let's just address the glaringly obvious mistake.  I'll bet this is not the only problem with this program, because looking through it I see repeated misunderstanding of memory, pointer use and object lifetime.

Anyway, right here you have:

```<code>grid = new gridTileDetails * [gridSize.gridXHighestVal + 1];
for (int i = 0; i < gridSize.gridYHighestVal + 1; i++)
{
    grid[i] = new gridTileDetails[gridSize.gridYHighestVal + 1];
}
</code>```

Notice that you allocated an array of pointers that can hold gridSize.gridXHighestVal + 1 values, but you then populate that array with gridSize.gridYHighestVal + 1 values.  If the dimensions are not square, then you'll either allocate too few sub-arrays, or you'll overrun the buffer and write pointers into memory you have no business writing to.

So the loop should instead be:

```<code>for (int i = 0; i < gridSize.gridXHighestVal + 1; i++)
</code>```

Body:
I'm trying to create a program to print a 2D matrix after reading in data from a file.

My program works fine if the 2D matrix is a square with equal X & Y values, but I get the "corrupted size vs. prev_size" error if its a rectangle, for example with x=8 and y=10.

Here is an example of what it should look like if run successfully (where x is 8 and y is 8):

  # # # # # # # # # # #
8 #     2 2           #
7 #     2 2       1   #
6 #                   #
5 #                   #
4 #                   #
3 #   3 3 3           #
2 #   3 3 3           #
1 #   3 3 3           #
0 #                   #
  # # # # # # # # # # #
    0 1 2 3 4 5 6 7 8

When I try to use a configuration file where x is 8 and y is 10 I get the error as such:

Please enter your choice : 1

[ Read in and process a configuration file ]
Please enter config filename : TestCases_Config.txt

Reading in GridX_IdxRange : GridX_IdxRange=0-8 ... done!
Reading in GridY_IdxRange : GridY_IdxRange=0-10 ... done!

Storing data from input file :
*** Error in `./csci251_a1.exe': corrupted size vs. prev_size: 0x08e63d40 ***
Aborted (core dumped)

This is what my code looks like:

#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm> // To use unique function
#include <iomanip> // For setprecision
#include <vector> // To use vectors

using namespace std;

// Struct to store the maximum grid values from config file
struct gridSize
{
    int gridXHighestVal;
    int gridYHighestVal;

    string toString();
};

// Struct object to store individual grid tile details
struct gridTileDetails
{
    int x, y;
    bool isOccupied;
    int cityID;
    string cityName;
    int cloudIndex, singleCloudIndex, pressureIndex, singlePressureIndex;
    char cloudLMH, pressureLMH;

    string toString();
};

gridSize gridSize; // Global gridSize struct to be used to obtain maximum X & Y values
gridTileDetails **grid; // Global pointer-to-pointer variable to be used for dynamically allocating 2D array

// All function/method prototypes
// Functions for reading of data (Menu option #1)
gridTileDetails processConfigFile();
gridTileDetails readCityFile(string);
gridTileDetails readCloudFile(string);
gridTileDetails readPressureFile(string);

// Functions for menu options #2 - #7
void displayCityMap(int, int);
void displayCloudMap(int, int);
void displayCloudMapLMH(int, int);
void displayPressureMap(int, int);
void displayPressureMapLMH(int, int);
void generateWeatherReport(int, int);

// Helper functions
void safelyDeallocateMemory (int arrayCols, gridTileDetails **grid);
vector<string> tokenizeString(string, string);
vector<int> removeDuplicates(vector<int> &vec);
char getLMH(int);
int printCity(int, int, vector<int> , int);
double calculateRain(char, char);
void printRain(double);

int main()
{

    int userChoice;

    // Main menu to run constantly until user enters 8
    while (userChoice != 8)
    {
        cout << "Welcome to Weather Information Processing System!" << endl;

        cout << endl;

        cout << "1)\tRead in and process a configuration file" << endl;
        cout << "2)\tDisplay city map" << endl;
        cout << "3)\tDisplay cloud coverage map (cloudiness index)" << endl;
        cout << "4)\tDisplay cloud coverage map (LMH symbols)" << endl;
        cout << "5)\tDisplay atmospheric pressure map (pressure index)" << endl;
        cout << "6)\tDisplay atmospheric pressure map (LMH symbols)" << endl;
        cout << "7)\tShow forecast summary report" << endl;
        cout << "8)\tQuit" << endl;

        cout << endl;

        cout << "Please enter your choice : ";
        cin >> userChoice;

        cout << endl;

        switch (userChoice)
        {
            case 1:
                // Process configuration file
                **grid = processConfigFile();
                break;
            case 2:
                // Display city map
                displayCityMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 3:
                // Display cloud coverage map (cloudiness index)
                displayCloudMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 4:
                // Display cloud coverage map (LMH symbols)
                displayCloudMapLMH(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 5:
                // Display atmospheric pressure map (pressure index)
                displayPressureMap(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 6:
                // Display atmospheric pressure map (LMH symbols)
                displayPressureMapLMH(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 7:
                // Show weather forecast summary report
                generateWeatherReport(gridSize.gridXHighestVal, gridSize.gridYHighestVal);
                break;
            case 8:
                // Message to be shown for quiting program
                cout << "Thank you for using the Weather Information Processing System!" << endl;
                break;
            default:
                cout << "Please enter a valid input!" << endl << endl;
        }
    }

    safelyDeallocateMemory (gridSize.gridXHighestVal, grid);

    return (0);
}

// Begin reading of files
gridTileDetails processConfigFile()
{
    string filename;

    cout << "[ Read in and process a configuration file ]" << endl;
    cout << "Please enter config filename : ";
    cin >> filename;

    cout << endl;

    // Create fstream object
    fstream input_file(filename.c_str(), fstream::in);

    string aline;
    string gridX = "GridX_IdxRange";
    string gridY = "GridY_IdxRange";

    while (getline(input_file, aline)) // With input_file as the source, store each "line" into our string variable aline;
    {

        if (aline.find(gridX) != string::npos) // If "GridX_IdxRange" is found within aline
        {
            string numString = aline.substr(15); // Obtain only the number range portion of string

            vector<string> individualNums = tokenizeString(numString, "-"); // Use "-" as delimiter to obtain individual numbers

            int gridX = stoi(individualNums[1]); // Convert string to an int variable

            gridSize.gridXHighestVal = gridX; // Store grid X maximum value into custom struct object

            cout << "Reading in GridX_IdxRange : " << aline << " ... done!" << endl;
            individualNums.clear();
        }

        if (aline.find(gridY) != string::npos) // If "GridY_IdxRange" is found within aline
        {

            string numString = aline.substr(15); // Obtain only the number range portion of string

            vector<string> individualNums = tokenizeString(numString, "-"); // Use "-" as delimiter to obtain individual numbers

            int gridY = stoi(individualNums[1]); // Convert string to an int variable

            gridSize.gridYHighestVal = gridY; // Store grid Y maximum value into custom struct object

            cout << "Reading in GridY_IdxRange : " << aline << " ... done!" << endl;
            individualNums.clear();
        }

        if (gridSize.gridXHighestVal != 0 && gridSize.gridYHighestVal != 0) // Break out of the while-loop if both X & Y values are populated, to continue processing
        {
            break;
        }
    }

    cout << endl;

    // Dynamic memory allocation for 2D array
    grid = new gridTileDetails * [gridSize.gridXHighestVal + 1];
    for (int i = 0; i < gridSize.gridYHighestVal + 1; i++)
    {
        grid[i] = new gridTileDetails[gridSize.gridYHighestVal + 1];
    }

    // Putting x (columns) and y (rows) values into 2D array
    for (int col = 0; col < gridSize.gridXHighestVal + 1; col++)
    {
        for (int row = 0; row < gridSize.gridYHighestVal + 1; row++)
        {
            grid[col][row].x = col;
            grid[col][row].y = row;
        }
    }

    int fileCounter = 0; // File counter variable to decide which file method to use
    cout << "Storing data from input file :" << endl;

    while (getline(input_file, aline))
    {

        if (aline.find(".txt") != string::npos) // If aline contains ".txt" at the end, we know it is one of the configuration files
        {

            switch (fileCounter)
            {
                case 0: // Get city details
                    **grid = readCityFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
                case 1: // Get cloud details
                    **grid = readCloudFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
                case 2: // Get pressure details
                    **grid = readPressureFile(aline);
                    cout << aline << " ... done!" << endl;
                    break;
            }
            fileCounter++;
        }

    }
    cout << endl;

    cout << "All records successfully stored. Going back to main menu ..." << endl;

    cout << endl;

    return **grid;
}

// Method for reading city file
gridTileDetails readCityFile(string filename)
{

    // Create fstream object
    fstream input_file(filename.c_str(), fstream::in);

    string aline;

    while (getline(input_file, aline))
    {
        if (aline == "")
        {
            break;
        }

        vector<string> allConfigInfo = tokenizeString(aline, "-"); // Separates all data with delimiter "-" Eg. [1,1] 3 Big_City

        string gridString = allConfigInfo[0]; // Gets part of vector storing grid info
        string cityID = allConfigInfo[1];
        string cityName = allConfigInfo[2];

        gridString = gridString.substr(1, gridString.size() - 2); // Removes [ and ] brackets

        vector<string> gridValues = tokenizeString(gridString, ", "); // Get individual grid values

        // Get grid values
        int gridX = stoi(gridValues[0]);
        int gridY = stoi(gridValues[1]);

        // Get city ID
        int intCityID = stoi(cityID);

        // Inserting values into 2D array
        grid[gridX][gridY].cityID = intCityID;
        grid[gridX][gridY].isOccupied = true;
        grid[gridX][gridY].cityName = cityName;

    }
    return **grid;
}

I suspect the issues lies with the reading of the other files and populating the 2D array with its data (city, cloud, pressure files) but I can't seem to understand where I went wrong.

I tried commenting out the bottom portion of processConfigFile just to see if the 2D array gets created correctly without inserting any information to each tile and although the alignment got messed up a little, it worked (where x is 8 and y is 10):

  # # # # # # # # # # #
10 #                   #
9 #                   #
8 #                   #
7 #                   #
6 #                   #
5 #                   #
4 #                   #
3 #                   #
2 #                   #
1 #                   #
0 #                   #
  # # # # # # # # # # #
    0 1 2 3 4 5 6 7 8

I didn't include the code for the reading of the other files as its mostly the same, just with some minor adjustments.

Any help provided would be greatly appreciated!

Body:
Well, let's just address the glaringly obvious mistake.  I'll bet this is not the only problem with this program, because looking through it I see repeated misunderstanding of memory, pointer use and object lifetime.

Anyway, right here you have:

grid = new gridTileDetails * [gridSize.gridXHighestVal + 1];
for (int i = 0; i < gridSize.gridYHighestVal + 1; i++)
{
    grid[i] = new gridTileDetails[gridSize.gridYHighestVal + 1];
}

Notice that you allocated an array of pointers that can hold gridSize.gridXHighestVal + 1 values, but you then populate that array with gridSize.gridYHighestVal + 1 values.  If the dimensions are not square, then you'll either allocate too few sub-arrays, or you'll overrun the buffer and write pointers into memory you have no business writing to.

So the loop should instead be:

for (int i = 0; i < gridSize.gridXHighestVal + 1; i++)


问:
Threading a variable number of heterogeneous input files, process the input and output to a single file
I am trying improve the performance of the job listed below.  As is, without threading, it runs successfully.  But is runs very slow.  I would like to thread step 2 where 95% of the work happens in the reading, filtering and transforming the input data read from very large heterogeneous files.  The job:

•   Step1 gets some job parameters that are passed into Step2.

•   Step2 will read in X number of files.  Each file is heterogenous, i.e., contains several different record formats.  The records are filtered, transformed and sent to a single output file.

Does Spring Batch have a built-in way to thread Step2 in this scenario?  For example, can I add some type of executor to step2?  I’ve tried SimpleAsyncTaskExecutor and ThreadPoolTaskExecutor.  Neither work.  Adding SimpleAsyncTaskExecutor throws an exception. (See can we process the multiple files sequentially using spring Batch while multiple threads used to process individual files data..?)

Here is the batch configuration:

```<code>                public Job job() {
                                return jobBuilderFactory.get("MyJob")
                                                                .start(step1())
                                                                .next(step2())
                                                                .build();
                }

                @Bean
                public Step step1()  {
                                return stepBuilderFactory.get("Step1GetJobParams")
                                                                .tasklet(MyParamsTasklet)
                                                                .build();
                }

                @Bean
                public Step step2() {
                                return stepBuilderFactory.get("Step2")
                                                                .<InputDO, OutputDO>chunk(1000)
                                                                .reader(myMultiResourceReader())
                                                                .processor(myStep2ItemProcessor)
                                                                .writer(myStep2FileWriter())
                                                                .taskExecutor(???)                                          line #23
                            .build();
                }

                @Bean
                public MultiResourceItemReader<InputDO> myMultiResourceReader(){
                                MultiResourceItemReader<InputDO> multiResourceItemReader = new MultiResourceItemReader<InputDO>();
                                multiResourceItemReader.setResources(resourceManager.getResources());
                                multiResourceItemReader.setDelegate(myStep2FileReader());
                                multiResourceItemReader.setSaveState(false);
                                return multiResourceItemReader;
                }

                @Bean
                public FlatFileItemReader<InputDO> myStep2FileReader() {
                                return new FlatFileItemReaderBuilder<InputDO>()
                                                               .name("MyStep2FileReader")
                                                               .lineMapper(myCompositeLineMapper())
                                                               .build();
                }

                @Bean
                 public PatternMatchingCompositeLineMapper<InputDO> myCompositeLineMapper() {
                                PatternMatchingCompositeLineMapper<InputDO> lineMapper = new PatternMatchingCompositeLineMapper<InputDO>();
                                Map<String, LineTokenizer> tokenizers = new HashMap<String, LineTokenizer>();
                                tokenizers.put("A", InputDOTokenizer.getInputDOTokenizer());
                                tokenizers.put("*", InputDOFillerTokenizer.getInputDOFillerTokenizer());
                                lineMapper.setTokenizers(tokenizers);
                                Map<String, FieldSetMapper<InputDO>> mappers = new HashMap<String, FieldSetMapper<InputDO>>();
                                mappers.put("A", new InputDOFieldSetMapper());
                                mappers.put("*", new InputDOFillerFieldSetMapper());
                                lineMapper.setFieldSetMappers(mappers);
                                return lineMapper;
                 }

                @Bean
                public FlatFileItemWriter<OutputDO> myOutputDOFileWriter() {
                                return  new FlatFileItemWriterBuilder<OutputDO>()
                                               .name("MyOutputDOFileWriter")
                                               .resource(resourceManager.getFileSystemResource("myOutputDOFileName"))
                                               .lineAggregator(new DelimitedLineAggregator<OutputDO>() {
                                                               {
                                                                                setDelimiter("");
                                                                                setFieldExtractor(outputDOFieldExtractor.getOutputDOFieldExtractor());
                                                                                };
                                               })
                                               .lineSeparator("\r\n")
                                               .build();
                }
</code>```

Any/all guidance is much appreciated!

答:
I guess you want to use this mode of Multi-threaded Step to resolve read slowly problem. more details is available from spring batch office - Multi-threaded Step about it.

Hope to help you.

Body:
I am trying improve the performance of the job listed below.  As is, without threading, it runs successfully.  But is runs very slow.  I would like to thread step 2 where 95% of the work happens in the reading, filtering and transforming the input data read from very large heterogeneous files.  The job:

•   Step1 gets some job parameters that are passed into Step2.

•   Step2 will read in X number of files.  Each file is heterogenous, i.e., contains several different record formats.  The records are filtered, transformed and sent to a single output file.

Does Spring Batch have a built-in way to thread Step2 in this scenario?  For example, can I add some type of executor to step2?  I’ve tried SimpleAsyncTaskExecutor and ThreadPoolTaskExecutor.  Neither work.  Adding SimpleAsyncTaskExecutor throws an exception. (See can we process the multiple files sequentially using spring Batch while multiple threads used to process individual files data..?)

Here is the batch configuration:

                public Job job() {
                                return jobBuilderFactory.get("MyJob")
                                                                .start(step1())
                                                                .next(step2())
                                                                .build();
                }

                @Bean
                public Step step1()  {
                                return stepBuilderFactory.get("Step1GetJobParams")
                                                                .tasklet(MyParamsTasklet)
                                                                .build();
                }

                @Bean
                public Step step2() {
                                return stepBuilderFactory.get("Step2")
                                                                .<InputDO, OutputDO>chunk(1000)
                                                                .reader(myMultiResourceReader())
                                                                .processor(myStep2ItemProcessor)
                                                                .writer(myStep2FileWriter())
                                                                .taskExecutor(???)                                          line #23
                            .build();
                }

                @Bean
                public MultiResourceItemReader<InputDO> myMultiResourceReader(){
                                MultiResourceItemReader<InputDO> multiResourceItemReader = new MultiResourceItemReader<InputDO>();
                                multiResourceItemReader.setResources(resourceManager.getResources());
                                multiResourceItemReader.setDelegate(myStep2FileReader());
                                multiResourceItemReader.setSaveState(false);
                                return multiResourceItemReader;
                }

                @Bean
                public FlatFileItemReader<InputDO> myStep2FileReader() {
                                return new FlatFileItemReaderBuilder<InputDO>()
                                                               .name("MyStep2FileReader")
                                                               .lineMapper(myCompositeLineMapper())
                                                               .build();
                }

                @Bean
                 public PatternMatchingCompositeLineMapper<InputDO> myCompositeLineMapper() {
                                PatternMatchingCompositeLineMapper<InputDO> lineMapper = new PatternMatchingCompositeLineMapper<InputDO>();
                                Map<String, LineTokenizer> tokenizers = new HashMap<String, LineTokenizer>();
                                tokenizers.put("A", InputDOTokenizer.getInputDOTokenizer());
                                tokenizers.put("*", InputDOFillerTokenizer.getInputDOFillerTokenizer());
                                lineMapper.setTokenizers(tokenizers);
                                Map<String, FieldSetMapper<InputDO>> mappers = new HashMap<String, FieldSetMapper<InputDO>>();
                                mappers.put("A", new InputDOFieldSetMapper());
                                mappers.put("*", new InputDOFillerFieldSetMapper());
                                lineMapper.setFieldSetMappers(mappers);
                                return lineMapper;
                 }

                @Bean
                public FlatFileItemWriter<OutputDO> myOutputDOFileWriter() {
                                return  new FlatFileItemWriterBuilder<OutputDO>()
                                               .name("MyOutputDOFileWriter")
                                               .resource(resourceManager.getFileSystemResource("myOutputDOFileName"))
                                               .lineAggregator(new DelimitedLineAggregator<OutputDO>() {
                                                               {
                                                                                setDelimiter("");
                                                                                setFieldExtractor(outputDOFieldExtractor.getOutputDOFieldExtractor());
                                                                                };
                                               })
                                               .lineSeparator("\r\n")
                                               .build();
                }

Any/all guidance is much appreciated!


问:
Code to simulate Collatz Conjecture is showing 1 as an even number
My code is the following

```<code>output_even = "Even: "
output_odd = "Odd: "

if varnum % 2 == 0:
 varnum /= 2
 print(output_even, varnum)
 time.sleep(0.1)
elif varnum % 2 != 0:
 varnum *= 3
 varnum += 1
 print(output_odd, varnum)
 time.sleep(0.1)
</code>```

Output (integer 5):

Odd:  16

Even:  8.0

Even:  4.0

Even:  2.0

Even:  1.0

Conjecture not solved

I know that one should not be an even number. But for some reason, it is listed as an even number as shown by the output with the original number being 5.

Edit: Full loop with code for extra clarification hopefully

```<code>        while varnum != 1:
            if varnum % 2 == 0:
                print(output_even, varnum)
                varnum /= 2
                time.sleep(0.1)
            elif varnum % 2 != 0:
                print(output_odd, varnum)
                varnum *= 3
                varnum += 1
                time.sleep(0.1)
        if varnum == 1:
            print("Conjecture not solved")
        else:
            print("Conjecture solved")
</code>```

答:
2 is even, though.

You're dividing varnum by 2 and then printing the result of that division.

Try swapping the arithmetic and printing operations.

Body:
My code is the following

output_even = "Even: "
output_odd = "Odd: "

if varnum % 2 == 0:
 varnum /= 2
 print(output_even, varnum)
 time.sleep(0.1)
elif varnum % 2 != 0:
 varnum *= 3
 varnum += 1
 print(output_odd, varnum)
 time.sleep(0.1)

Output (integer 5):

Odd:  16

Even:  8.0

Even:  4.0

Even:  2.0

Even:  1.0

Conjecture not solved

I know that one should not be an even number. But for some reason, it is listed as an even number as shown by the output with the original number being 5.

Edit: Full loop with code for extra clarification hopefully

        while varnum != 1:
            if varnum % 2 == 0:
                print(output_even, varnum)
                varnum /= 2
                time.sleep(0.1)
            elif varnum % 2 != 0:
                print(output_odd, varnum)
                varnum *= 3
                varnum += 1
                time.sleep(0.1)
        if varnum == 1:
            print("Conjecture not solved")
        else:
            print("Conjecture solved")


问:
How to get file change count from Gitlab API?
Using Gitlab commit API with the attribute 'with_stats' set as yes, I am able to get the line change additions, deletions and total but I dont see an option to get the file change count as available at :

```<code>git show --stat
</code>```

or even at Gitlab UI :

.

With the gitlab API:

```<code>https://<gitlab_server>/api/v4/projects/:id/repository/commits?with_stats=yes
</code>```

I see a response like :
"stats": {
"additions": 9,
"deletions": 2,
"total": 11
}

but nothing like { "file_changes": 1 }

答:
I am not sure if exist a direct method for it, but you can try this below command on your terminal

git show --format=oneline --stat COMMIT_SHA | grep "|" | wc -l

Body:
Using Gitlab commit API with the attribute 'with_stats' set as yes, I am able to get the line change additions, deletions and total but I dont see an option to get the file change count as available at :

git show --stat

or even at Gitlab UI :

.

With the gitlab API:

https://<gitlab_server>/api/v4/projects/:id/repository/commits?with_stats=yes

I see a response like :
"stats": {
"additions": 9,
"deletions": 2,
"total": 11
}

but nothing like { "file_changes": 1 }


问:
Security negotiation exception in WCF
Consider:

I'm getting this error while connection to a WCF service. I have WCF username and password authentication in the WCF service. I want clients to require a username and password to connect to this service. This is my service configuration:

```<code><system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="NewBinding0">
                <security>
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="WcfUserNamePasswordAuthentication.Service1Behavior"
                 name="WcfUserNamePasswordAuthentication.Service1">
            <endpoint address="" binding="wsHttpBinding" contract="WcfUserNamePasswordAuthentication.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="WcfUserNamePasswordAuthentication.Service1Behavior">

                <!-- To avoid disclosing metadata information, set the value below to
                     false and remove the metadata endpoint above before deployment. -->
                <serviceMetadata httpGetEnabled="true"/>

                <!-- To receive exception details in faults for debugging
                     purposes, set the value below to true. Set to false
                     before deployment to avoid disclosing exception
                     information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>

                <serviceCredentials>
                    <serviceCertificate findValue="CertMohan"
                                        storeLocation="LocalMachine"
                                        storeName="My"
                                        x509FindType="FindBySubjectName" />
                    <userNameAuthentication userNamePasswordValidationMode="Custom"
                                            customUserNamePasswordValidatorType="WcfUserNamePasswordAuthentication.UserNameAuthentication, WcfUserNamePasswordAuthentication"
                    />
                </serviceCredentials>

            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
</code>```

And this is my client configuration:

```<code><system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
               bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
               maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
               textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                 maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                 enabled="false" />

                <security mode="Message">

                    <message clientCredentialType="UserName" negotiateServiceCredential="true"
                     algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://abc31.org.in/WcfUserName/Service1.svc"
           binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
           contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">

            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>
</code>```

And this way I am connecting to my service:

```<code>ServiceReference1.Service1Client sc = new WebApplication3.ServiceReference1.Service1Client();
EndpointIdentity.CreateDnsIdentity("localhost");
var binding = new WSHttpBinding();

binding.Security.Mode = SecurityMode.Message;

binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
sc.ClientCredentials.UserName.UserName = "Mohan";
sc.ClientCredentials.UserName.Password = "Sharma";
lblRecord.Text = sc.GetData(1000);
</code>```

答: DnsEndpointIdentity cannot be localhost. It must be subject name of the certificate which is in your case CertMohan.

Title: Security negotiation exception in WCF

Body:
Consider:

I'm getting this error while connection to a WCF service. I have WCF username and password authentication in the WCF service. I want clients to require a username and password to connect to this service. This is my service configuration:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="NewBinding0">
                <security>
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="WcfUserNamePasswordAuthentication.Service1Behavior"
                 name="WcfUserNamePasswordAuthentication.Service1">
            <endpoint address="" binding="wsHttpBinding" contract="WcfUserNamePasswordAuthentication.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="WcfUserNamePasswordAuthentication.Service1Behavior">

                <serviceMetadata httpGetEnabled="true"/>

                <serviceDebug includeExceptionDetailInFaults="false"/>

                <serviceCredentials>
                    <serviceCertificate findValue="CertMohan"
                                        storeLocation="LocalMachine"
                                        storeName="My"
                                        x509FindType="FindBySubjectName" />
                    <userNameAuthentication userNamePasswordValidationMode="Custom"
                                            customUserNamePasswordValidatorType="WcfUserNamePasswordAuthentication.UserNameAuthentication, WcfUserNamePasswordAuthentication"
                    />
                </serviceCredentials>

            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

And this is my client configuration:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
               bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
               maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
               textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                 maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                 enabled="false" />

                <security mode="Message">

                    <message clientCredentialType="UserName" negotiateServiceCredential="true"
                     algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://abc31.org.in/WcfUserName/Service1.svc"
           binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
           contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">

            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

And this way I am connecting to my service:

ServiceReference1.Service1Client sc = new WebApplication3.ServiceReference1.Service1Client();
EndpointIdentity.CreateDnsIdentity("localhost");
var binding = new WSHttpBinding();

binding.Security.Mode = SecurityMode.Message;

binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
sc.ClientCredentials.UserName.UserName = "Mohan";
sc.ClientCredentials.UserName.Password = "Sharma";
lblRecord.Text = sc.GetData(1000);


问:
Azure devops service connection and central pipeline
I have a requirement of giving multiple teams access to a shared resource in azure. I therefore want to limit how people can publish changes to the shared resource.

The idea is to limit the use of a service connection to a specific pipeline, as per this documentation. However if the pipeline is stored in their own repo the developer could change it. This would not give me enough control. I therefore found that it was possible using a template from a central repo. Using a shared repo, would then allow me to have a service connection solely for the template?

So how I imagine doing the above is I need to grant project X a service connection for my BuildTemplates Repo. But this is basically just access to the repo and to be able to use the shared templates. Then in BuildTemplates repo I can have a service connection for my template A.

Now the developer in project X - creates her deployments and configurations for her pipeline with her own service connection scoped for her resources. Then she inherits a template from BuildTemplates Repo and passes relevant parameters for the template A.

She cannot alter the template pipeline A and only the template pipeline A can publish to the shared resource, because of the scoped service connection. I can therefore create relevant guards for the shared azure resource in the template pipeline A - so I restrict how developer X can publish to my shared azure resource.

does this make sense and is it viable?

The pipeline part in A cannot be edited by developer in X ?

The service connection in A will not propagate out so developer in X can use it in an inappropriate way?

Update

The above solution does not seem to be viable since the pipeline template is executed in the source branch scope.

Proposed Solution

The benefits I see with the above suggestion doe not seem possible, because of the issues. However one can utilise pipeline triggers, as a viable solution. This however results in a new issue. When a pipeline is triggered by Developer Y in Y's repository and it succeeds. Then a trigger is made in MAIN repository and the pipeline in MAIN fails e.g., because the artifacts from Y introduced an Issue. How does developer Y get notified about the issues in MAIN pipeline?

答:
Here is my solution, in same Azure organization, we can create a Azure Project, then create a repo to save common pipeline template.
All the repos in other Azure project can access this pipeline template.

UserProject/UserRepo/azure-pipelines.yml

```<code>trigger:
  branches:
    include:
    - master
  paths:
    exclude:
    - nuget.config
    - README.md
    - azure-pipelines.yml
    - .gitignore

resources:
  repositories:
  - repository: devops-tools
    type: git
    name: PipelineTemplateProject/CommonPipeline
    ref: 'refs/heads/master'

jobs:
- template: template-pipeline.yml@devops-tools
</code>```

PipelineTemplateProject/CommonPipeline/template-pipeline.yml

Since the inline script of pipeline has 5000 characters limitation,
you can put your script(not only powershell, but also other languages) in PipelineTemplateProject/CommonPipeline/scripts/test.ps1

```<code># Common Pipeline Template
jobs:
 - job: Test_Job
   pool:
     name: AgentPoolName
   steps:
   - script: |
       echo "$(Build.RequestedForEmail)"
       echo "$(Build.RequestedFor)"
       git config user.email "$(Build.RequestedForEmail)"
       git config user.name "$(Build.RequestedFor)"
       git config --global http.sslbackend schannel
       echo '------------------------------------'
       git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" -b $(ToolsRepoBranch) --single-branch --depth=1 "https://PipelineTemplateProject/_git/CommonPipeline" DevOps_Tools
       echo '------------------------------------'
     displayName: 'Clone DevOps_Tools'

   - task: PowerShell@2
     displayName: 'Pipeline Debug'
     inputs:
       targetType: 'inline'
       script: 'Get-ChildItem -Path Env:\ | Format-List'
     condition: always()

   - task: PowerShell@2
     displayName: 'Run Powershell Scripts'
     inputs:
       targetType: filePath
       filePath: 'DevOps_Tools/scripts/test.ps1'
       arguments: "$(System.AccessToken)"
</code>```

Notes:
Organization Setting - Settings - Disable Limit job authorization scope to current project for release pipelines

Organization Setting - Settings - Limit job authorization scope to current project for non-release pipelines

Check some option in project setting as well.

So the normal user only access their own repo, cannot access DevOps project, and DevOps owner can edit template pipeline only.

For the notification issue, I use an Email extention "rvo.SendEmailTask.send-email-build-task.SendEmail@1"

Body:
Here is my solution, in same Azure organization, we can create a Azure Project, then create a repo to save common pipeline template.
All the repos in other Azure project can access this pipeline template.

UserProject/UserRepo/azure-pipelines.yml

trigger:
  branches:
    include:
    - master
  paths:
    exclude:
    - nuget.config
    - README.md
    - azure-pipelines.yml
    - .gitignore

resources:
  repositories:
  - repository: devops-tools
    type: git
    name: PipelineTemplateProject/CommonPipeline
    ref: 'refs/heads/master'

jobs:
- template: template-pipeline.yml@devops-tools

PipelineTemplateProject/CommonPipeline/template-pipeline.yml

Since the inline script of pipeline has 5000 characters limitation,
you can put your script(not only powershell, but also other languages) in PipelineTemplateProject/CommonPipeline/scripts/test.ps1

# Common Pipeline Template
jobs:
 - job: Test_Job
   pool:
     name: AgentPoolName
   steps:
   - script: |
       echo "$(Build.RequestedForEmail)"
       echo "$(Build.RequestedFor)"
       git config user.email "$(Build.RequestedForEmail)"
       git config user.name "$(Build.RequestedFor)"
       git config --global http.sslbackend schannel
       echo '------------------------------------'
       git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" -b $(ToolsRepoBranch) --single-branch --depth=1 "https://PipelineTemplateProject/_git/CommonPipeline" DevOps_Tools
       echo '------------------------------------'
     displayName: 'Clone DevOps_Tools'

   - task: PowerShell@2
     displayName: 'Pipeline Debug'
     inputs:
       targetType: 'inline'
       script: 'Get-ChildItem -Path Env:\ | Format-List'
     condition: always()

   - task: PowerShell@2
     displayName: 'Run Powershell Scripts'
     inputs:
       targetType: filePath
       filePath: 'DevOps_Tools/scripts/test.ps1'
       arguments: "$(System.AccessToken)"

Notes:
Organization Setting - Settings - Disable Limit job authorization scope to current project for release pipelines

Organization Setting - Settings - Limit job authorization scope to current project for non-release pipelines

Check some option in project setting as well.

So the normal user only access their own repo, cannot access DevOps project, and DevOps owner can edit template pipeline only.

For the notification issue, I use an Email extention "rvo.SendEmailTask.send-email-build-task.SendEmail@1"


问:
The selected value of the select attribute is not displayed. TypeScript/Angular
I don't see anything in the item selection window. The elements are loaded from the Web APi server. Here is the photo of problem.

Component class

```<code>carsDynamic!: Array<Car>

private loadDynamicData(){
  this.dynamic.getDynamicCars().subscribe((data: Car[]) => {
  this.carsDynamic = data
})
</code>```

HTML page

```<code><select  class="form-control" [(ngModel)]="editedSale.carId">
  <option disabled selected>--Select--</option>
  <option *ngFor="let car of carsDynamic"
          value={{car.id}}>
          {{car.brandName}}
  </option>
</select>
</code>```

How to fix this problem ?

答:
Problem originates from [(ngModel)]="editedSale.carId". You have to choose, either template driven from or reactive form.

@Component({
  selector: 'select-reset-example',
  templateUrl: 'select-reset-example.html',
  styleUrls: ['select-reset-example.css'],
})
export class SelectResetExample {
  dynamic = new ReplaySubject<any>(1);
  carsDynamic: any[];
  data = [
    { id: 1, brandName: 'Audi' },
    { id: 2, brandName: 'BMW' },
  ];

  constructor() {
    this.loadDynamicData();
    this.dynamic.next(this.data);
  }

  private loadDynamicData() {
    this.dynamic.subscribe((data: Car[]) => {
      this.carsDynamic = data;
    });
  }

  onSelect(event: any) {
    console.log(event.target.value);
  }
}

export interface Car {
  id: number;
  brandName: string;
}

```
<pre class="lang-html prettyprint-override"><code><select class="form-control" (change)="onSelect($event)">
  <option disabled selected>--Select--</option>
  <ng-container *ngFor="let car of carsDynamic">
    <option value="{{car | json}}">{{car.brandName}}</option>
  </ng-container>
</select>

<select class="form-control" (change)="onSelect($event)">
  <option disabled selected>--Select--</option>
  <ng-container *ngFor="let car of carsDynamic">
    <option value="{{car.id}}">{{car.brandName}}</option>
  </ng-container>
</select>

<select class="form-control" (change)="onSelect($event)">
<option disabled selected>--Select--</option>
<ng-container *ngFor="let car of carsDynamic">
  <option value="{{car.brandName}}">{{car.brandName}}</option>
</ng-container>
</select>
</code>```

Look into console log.
Working example: https://stackblitz.com/edit/angular-material-matselect-ybbg2t?file=app%2Fselect-reset-example.ts

Body:
I don't see anything in the item selection window. The elements are loaded from the Web APi server. Here is the photo of problem.

Component class

carsDynamic!: Array<Car>

private loadDynamicData(){
  this.dynamic.getDynamicCars().subscribe((data: Car[]) => {
  this.carsDynamic = data
})

HTML page

<select  class="form-control" [(ngModel)]="editedSale.carId">
  <option disabled selected>--Select--</option>
  <option *ngFor="let car of carsDynamic"
          value={{car.id}}>
          {{car.brandName}}
  </option>
</select>

How to fix this problem ?

Body:
Problem originates from [(ngModel)]="editedSale.carId". You have to choose, either template driven from or reactive form.

@Component({
  selector: 'select-reset-example',
  templateUrl: 'select-reset-example.html',
  styleUrls: ['select-reset-example.css'],
})
export class SelectResetExample {
  dynamic = new ReplaySubject<any>(1);
  carsDynamic: any[];
  data = [
    { id: 1, brandName: 'Audi' },
    { id: 2, brandName: 'BMW' },
  ];

  constructor() {
    this.loadDynamicData();
    this.dynamic.next(this.data);
  }

  private loadDynamicData() {
    this.dynamic.subscribe((data: Car[]) => {
      this.carsDynamic = data;
    });
  }

  onSelect(event: any) {
    console.log(event.target.value);
  }
}

export interface Car {
  id: number;
  brandName: string;
}

<select class="form-control" (change)="onSelect($event)">
  <option disabled selected>--Select--</option>
  <ng-container *ngFor="let car of carsDynamic">
    <option value="{{car | json}}">{{car.brandName}}</option>
  </ng-container>
</select>

<select class="form-control" (change)="onSelect($event)">
  <option disabled selected>--Select--</option>
  <ng-container *ngFor="let car of carsDynamic">
    <option value="{{car.id}}">{{car.brandName}}</option>
  </ng-container>
</select>

<select class="form-control" (change)="onSelect($event)">
<option disabled selected>--Select--</option>
<ng-container *ngFor="let car of carsDynamic">
  <option value="{{car.brandName}}">{{car.brandName}}</option>
</ng-container>
</select>

Look into console log.
Working example: https://stackblitz.com/edit/angular-material-matselect-ybbg2t?file=app%2Fselect-reset-example.ts


问:
Is there a way to insert columns at specific indices using pandas?
I have done it with a sort-of brute force method (below), but is there a way to do this with maybe making one dictionary and utilizing a pandas function or something? There has to be a cleaner way to do this. I know you can just add these columns as you create them but I need them to be in a specific order.</p>
```<code># Notice there are missing indices from the lists because those are already occupied by other columns
new_col_names = ['col1',
    'col2',
    'col3',
    'col4',
    'col5',
    'col7',
    'col9',
    'col10',
    'col11',
    'col12',
    'col15',
    'col17',
    'col18',
    'col19',
    'col20',
    'col21',
    'col22',
    'col23',
    'col24',
    'col25',
    'col26',
    'col31',
    'col32',
]
indexes_to_append = [1, 2, 3, 4, 5, 7, 9, 10, 11, 12, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 31, 32]

for i in range(len(new_col_names)):
    dataframe.insert(loc=indexes_to_append[i], column=new_col_names[i], value=pd.NA)
</code>```

答:
You can reindex by a complete list of columns. An example using 10 cols for readability:

```<code>df = pd.DataFrame([[6, 8]],
                  columns=['col6', 'col8'])

print(df)
   col6  col8
0     6     8

cols = [f'col{x}' for x in range(1, 11)]

print(cols)
['col1',
 'col2',
 'col3',
 'col4',
 'col5',
 'col6',
 'col7',
 'col8',
 'col9',
 'col10']

df = df.reindex(cols, axis=1)
print(df)

   col1  col2  col3  col4  col5  col6  col7  col8  col9  col10
0   NaN   NaN   NaN   NaN   NaN     6   NaN     8   NaN    NaN
</code>```

Body:
I have done it with a sort-of brute force method (below), but is there a way to do this with maybe making one dictionary and utilizing a pandas function or something? There has to be a cleaner way to do this. I know you can just add these columns as you create them but I need them to be in a specific order.

# Notice there are missing indices from the lists because those are already occupied by other columns
new_col_names = ['col1',
    'col2',
    'col3',
    'col4',
    'col5',
    'col7',
    'col9',
    'col10',
    'col11',
    'col12',
    'col15',
    'col17',
    'col18',
    'col19',
    'col20',
    'col21',
    'col22',
    'col23',
    'col24',
    'col25',
    'col26',
    'col31',
    'col32',
]
indexes_to_append = [1, 2, 3, 4, 5, 7, 9, 10, 11, 12, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 31, 32]

for i in range(len(new_col_names)):
    dataframe.insert(loc=indexes_to_append[i], column=new_col_names[i], value=pd.NA)

Body:
You can reindex by a complete list of columns. An example using 10 cols for readability:

df = pd.DataFrame([[6, 8]],
                  columns=['col6', 'col8'])

print(df)
   col6  col8
0     6     8

cols = [f'col{x}' for x in range(1, 11)]

print(cols)
['col1',
 'col2',
 'col3',
 'col4',
 'col5',
 'col6',
 'col7',
 'col8',
 'col9',
 'col10']

df = df.reindex(cols, axis=1)
print(df)

   col1  col2  col3  col4  col5  col6  col7  col8  col9  col10
0   NaN   NaN   NaN   NaN   NaN     6   NaN     8   NaN    NaN