问:
Formatting input for currency with NSNumberFormatter in Swift
I am creating a budget app that allows the user to input their budget as well as transactions. I need to allow the user to enter both pence and pounds from separate text fields and they need to be formatted together with currency symbols. I have this working fine at the moment but would like to make it localised as currently it only works with GBP. I have been struggling to convert NSNumberFormatter examples from Objective-C to Swift.

My first issue is the fact that I need to set the placeholders for the input fields to be specific to the users location. Eg. Pounds and Pence, Dollars and Cents etc...

The second issue is that the values inputted in each of the text fields such as 10216 and 32 need to be formatted and the currency symbol specific to the users location needs to be added. So it would become £10,216.32 or $10,216.32 etc...

Also, I need to use the result of the formatted number in a calculation. So how can I do this without running into issues without running into issues with the currency symbol?

答:
Details

Xcode 10.2.1 (10E1001), Swift 5

Solution

```<code>import Foundation

class CurrencyFormatter {
    static var outputFormatter = CurrencyFormatter.create()
    class func create(locale: Locale = Locale.current,
                      groupingSeparator: String? = nil,
                      decimalSeparator: String? = nil,
                      style: NumberFormatter.Style = NumberFormatter.Style.currency) -> NumberFormatter {
        let outputFormatter = NumberFormatter()
        outputFormatter.locale = locale
        outputFormatter.decimalSeparator = decimalSeparator ?? locale.decimalSeparator
        outputFormatter.groupingSeparator = groupingSeparator ?? locale.groupingSeparator
        outputFormatter.numberStyle = style
        return outputFormatter
    }
}

extension Numeric {
    func toCurrency(formatter: NumberFormatter = CurrencyFormatter.outputFormatter) -> String? {
        guard let num = self as? NSNumber else { return nil }
        var formatedSting = formatter.string(from: num)
        guard let locale = formatter.locale else { return formatedSting }
        if let separator = formatter.groupingSeparator, let localeValue = locale.groupingSeparator {
            formatedSting = formatedSting?.replacingOccurrences(of: localeValue, with: separator)
        }
        if let separator = formatter.decimalSeparator, let localeValue = locale.decimalSeparator {
            formatedSting = formatedSting?.replacingOccurrences(of: localeValue, with: separator)
        }
        return formatedSting
    }
}
</code>```

Usage

```<code>let price = 12423.42
print(price.toCurrency() ?? "")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(style: .currencyISOCode)
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(locale: Locale(identifier: "es_ES"))
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(locale: Locale(identifier: "de_DE"), groupingSeparator: " ", style: .currencyISOCode)
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(groupingSeparator: "_", decimalSeparator: ".", style: .currencyPlural)
print(price.toCurrency() ?? "nil")

let formatter = CurrencyFormatter.create(locale: Locale(identifier: "de_DE"), groupingSeparator: " ", decimalSeparator: ",", style: .currencyPlural)
print(price.toCurrency(formatter: formatter) ?? "nil")
</code>```

Results

```<code>$12,423.42
USD12,423.42
12.423,42 €
12 423,42 EUR
12_423.42 US dollars
12 423,42 Euro
</code>```

Body:
Details

Xcode 10.2.1 (10E1001), Swift 5

Solution

import Foundation

class CurrencyFormatter {
    static var outputFormatter = CurrencyFormatter.create()
    class func create(locale: Locale = Locale.current,
                      groupingSeparator: String? = nil,
                      decimalSeparator: String? = nil,
                      style: NumberFormatter.Style = NumberFormatter.Style.currency) -> NumberFormatter {
        let outputFormatter = NumberFormatter()
        outputFormatter.locale = locale
        outputFormatter.decimalSeparator = decimalSeparator ?? locale.decimalSeparator
        outputFormatter.groupingSeparator = groupingSeparator ?? locale.groupingSeparator
        outputFormatter.numberStyle = style
        return outputFormatter
    }
}

extension Numeric {
    func toCurrency(formatter: NumberFormatter = CurrencyFormatter.outputFormatter) -> String? {
        guard let num = self as? NSNumber else { return nil }
        var formatedSting = formatter.string(from: num)
        guard let locale = formatter.locale else { return formatedSting }
        if let separator = formatter.groupingSeparator, let localeValue = locale.groupingSeparator {
            formatedSting = formatedSting?.replacingOccurrences(of: localeValue, with: separator)
        }
        if let separator = formatter.decimalSeparator, let localeValue = locale.decimalSeparator {
            formatedSting = formatedSting?.replacingOccurrences(of: localeValue, with: separator)
        }
        return formatedSting
    }
}

Usage

let price = 12423.42
print(price.toCurrency() ?? "")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(style: .currencyISOCode)
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(locale: Locale(identifier: "es_ES"))
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(locale: Locale(identifier: "de_DE"), groupingSeparator: " ", style: .currencyISOCode)
print(price.toCurrency() ?? "nil")

CurrencyFormatter.outputFormatter = CurrencyFormatter.create(groupingSeparator: "_", decimalSeparator: ".", style: .currencyPlural)
print(price.toCurrency() ?? "nil")

let formatter = CurrencyFormatter.create(locale: Locale(identifier: "de_DE"), groupingSeparator: " ", decimalSeparator: ",", style: .currencyPlural)
print(price.toCurrency(formatter: formatter) ?? "nil")

Results

$12,423.42
USD12,423.42
12.423,42 €
12 423,42 EUR
12_423.42 US dollars
12 423,42 Euro


来源: stackexchange

问:
Java program for permutation and combination
I was given a program with the below inputs

```<code>List of integers = {1,2,3}
int n = 5;
</code>```

The output should be the unique combination of the list elements which can be added to form the integer n.

The expected output = 5
because the unique combinations which can form 5 using the above array is

```<code>1,1,1,1,1
1,1,1,2
1,1,3
2,2,1
2,3
</code>```

The function I have created is like below

```<code>static void printAllCobinations(List<Integer> rooms,int t){
    int count = 0;
    for (int i=0;i<rooms.size();i++){
        int temp = t;
        while (temp>0){
            if((rooms.contains(temp))){
                count++;
            }
            temp-=rooms.get(i);
        }
    }
</code>```

Its giving the output as 6, as in addition to the above scenario its considering
3,2 also.

Actual expectation is if 2, 3 is considered no need to consider 3,2 .

How can i accomplish that ?

Note : the input array and n can change.

答:
```<code>int[] arr = new int[s.length() / 2 + 1];
</code>```

if s.length is 3 the arr.length = 3

if s.length is 4 the arr.length = 3

I have the feeling your problem lies there.

As an advice, I would suggest sepparating the part of the code that translates input from the code that actually calculates stuff. And then test them separately to see if you get the outcomes you want.

ContentLicense: CC BY-SA 3.0

Body:
I was given a program with the below inputs

List of integers = {1,2,3}
int n = 5;

The output should be the unique combination of the list elements which can be added to form the integer n.

The expected output = 5
because the unique combinations which can form 5 using the above array is

1,1,1,1,1
1,1,1,2
1,1,3
2,2,1
2,3

The function I have created is like below

static void printAllCobinations(List<Integer> rooms,int t){
    int count = 0;
    for (int i=0;i<rooms.size();i++){
        int temp = t;
        while (temp>0){
            if((rooms.contains(temp))){
                count++;
            }
            temp-=rooms.get(i);
        }
    }

Its giving the output as 6, as in addition to the above scenario its considering
3,2 also.

Actual expectation is if 2, 3 is considered no need to consider 3,2 .

How can i accomplish that ?

Note : the input array and n can change.

Body:
int[] arr = new int[s.length() / 2 + 1];

if s.length is 3 the arr.length = 3

if s.length is 4 the arr.length = 3

I have the feeling your problem lies there.

As an advice, I would suggest sepparating the part of the code that translates input from the code that actually calculates stuff. And then test them separately to see if you get the outcomes you want.


问:
How do I get over my fears of <% %> in my ASP.Net MVC markup?
So I totally buy into the basic tenents of ASP.NET, testability, SoC, HTML control...it's awesome.  However being new to it I have a huge hang up with the markup.  I know it comes from my hatred of classic ASP, and I can't help but feel like I've entered the twilight zone when I see this.

I don't know what the alternative is (can I use server controls, databinding etc...?)

答:
I'd suggest looking at the Velocity templating engine that MonoRails used.  ASP.NET MVC models itself very closely on the MonoRails format, so using the Velocity templates is fairly easy.

Click here to learn more.

OwnerDisplayName: Webjedi

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: Fabian Steeg

OwnerDisplayName: Soviut


问:
How to evaluate the current field value using a FieldArray?
Is it possible to get the current value of a field while using a FieldArray? For example, I have the following code:

import React from 'react';
import { Form, ArrayField, reduxForm } from 'redux-form';
import { Container, Row, Col } from 'reactstrap';
import { connect } from 'react-redux';

const mapStateToProps = (state) => ({
  initialValues: {
    customers: state.currentOffice.customers
  }
});

const renderCustomers = (fields, meta) => (
  <Container>
  {
    fields.map((customer, index) => (
      <Row>
        <Col lg='6'>
          { /* I need the current customer name be shown here */ }

          <Field
            name={`${customer}.name`}
            component='input'
            className='form-control'
          />
        </Col>
      </Row>
    ))
  }
  </Container>
);

const MyForm = reduxForm({ form: 'customersForm' })((props) => (
  <Form onSubmit={(e) => e.preventDefault()}>
    <FieldArray name='customers' component={renderCustomers} />
  </Form>
));

export default connect(mapStateToProps)(MyForm);
```

I need the customer name be shown in line 18, but when I try to evaluate the customer name between the JSX curly braces, I receive literally customers[0].name.

Is it possible to achieve that using redux-form?

答: I think fields.get(index) is the answer you seek.

Body:
Is it possible to get the current value of a field while using a FieldArray? For example, I have the following code:

import React from 'react';
import { Form, ArrayField, reduxForm } from 'redux-form';
import { Container, Row, Col } from 'reactstrap';
import { connect } from 'react-redux';

const mapStateToProps = (state) => ({
  initialValues: {
    customers: state.currentOffice.customers
  }
});

const renderCustomers = (fields, meta) => (
  <Container>
  {
    fields.map((customer, index) => (
      <Row>
        <Col lg='6'>
          { /* I need the current customer name be shown here */ }

          <Field
            name={`${customer}.name`}
            component='input'
            className='form-control'
          />
        </Col>
      </Row>
    ))
  }
  </Container>
);

const MyForm = reduxForm({ form: 'customersForm' })((props) => (
  <Form onSubmit={(e) => e.preventDefault()}>
    <FieldArray name='customers' component={renderCustomers} />
  </Form>
));

export default connect(mapStateToProps)(MyForm);

I need the customer name be shown in line 18, but when I try to evaluate the customer name between the JSX curly braces, I receive literally customers[0].name.

Is it possible to achieve that using redux-form?


问:
How do I hide a button until all elements are clicked in HTML?
I am trying to hide a button until all required elements on the page have been clicked. I found how to hide an element until one item is clicked but not sure how to set this to hide the button until all items are clicked.

The elements I want the users to click on are accordion panels with the ID's as "collaspeone", "collaspetwo" and so on. I want the user to click on each panel (which causes them to expand) then once they have clicked on each panel, show a button on the bottom of the page which allows them to continue to the next page.

Here is the element I want to show only when every panel has been clicked on.

```<code><button id="Continue" class="btn btn-primary"><a href="AddSupplier-SubmitReq.aspx" style="color:white">Continue to Set-Up<i class="fa fa-arrow-right" aria-hidden="true"></i></a></button>
</code>```

Here is my full HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<meta name="WebPartPageExpansion" content="full" />
<meta charset="utf-8"/>
    <meta http-equiv="x-ua-compatible" content="ie=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="canonical" href="http://html5-templates.com/" />
 <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
 <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
 <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"/>
 <link rel="manifest" href="/manifest.json"/>
 <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"/>
 <meta name="theme-color" content="#ffffff"/>
    <title>MySLM Portal</title>
 <meta name="description" content="A minimalist Bootstrap theme by StartBootstrap. Contains everything you need to get started building your website. All you have to do is change the text and images.">
    <link href="css/bootstrap.min.css" rel="stylesheet"/>
    <link href="css/modern-business.css" rel="stylesheet"/>
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="css/footer.css" rel="stylesheet" type="text/css"/>

                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    Toggle navigation

                </button>

                        Scope

                        General Questions

                        FAQ's

                        Processes

                                Create a New Supplier

                                Update an Existing Supplier

                                Reactivate a Supplier

                                Deactivate a Supplier

                        Contact

                        Resources

                                ERS Agreement Library

                                Corp Record List

                                Sanctioned Supplier List

                                Supplier Deactivation Listing

                                RemedyForce Training

                                Select Supplier Search

                                Yammer: Source to Pay NA

                                Job Aids

                                Knowledge/Self Help Articles

                                Policies

Sourcing and Purchasing Policy

Anti-bribery Policy

Bank Account & Payment Control Policy

Competition Policy

Conflicts of Interest Policy

Country Risk Policy

Insider Trading Policy

Legal Services Policy

Supplier Code of Conduct

Trade Sanctions Policy

United states & Canada Purchasing Cards Procedure

                        Links

                                Ariba

                                P2P Business Stakeholder Library

                                RemedyForce

                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

Wait! Make Your Job Easier!

Source through CSSP!

By sourcing through CSSP you can avoid having to navigate the entire complex supplier setup process and focus on your job while CSSP works for you in the background sourcing you a supplier and having them set-up in the appropriate ERP system for your use!

                 <button class="btn btn-primary">Lets go!  </button>

                  <button type="button" class="btn btn-default" data-dismiss="modal">No, I do not want to make my job easier</button>

Set-up a New Supplier
                    First Steps

The following steps should be completed by the requester prior to submitting a request to set-up a new supplier. Failure to perform these steps may result in rejection of, or delays on your request.

                        1

                    Panel Title

Panel Body

                        2

                    Panel Title

Panel Body

                        3

                    Panel Title

Panel Body

                        4

                    Panel Title

Panel Body

                        5

                    Panel Title

Panel Body

        <button id="Continue" class="btn btn-primary hidden disabled">Continue to Set-Up</button>

Questions? Check out our FAQ's

                    Go to FAQ's!

                            Code of Conduct

                            Supplier Code of Conduct

                            Policy Center

© 2017 Cargill, Incorporated. All Rights Reserved

```

答:
Another variation would be to add a class "clicked" and display the button if the number of panels with class clicked is equal to total number of panels within the accordion.

$('div.panel-group#accordion .panel').click(function() {
  $(this).addClass('clicked');
  var count = $(this).parent().find('.panel').length, ctr = 0;
  $(this).parent().find('.panel').each(function() {
   if($(this).hasClass('clicked')) { ctr++; }
  });
  if(ctr === count) {
    $('button#Continue').removeClass('hidden disabled');
  }
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Content Row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel-group" id="accordion">
            <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">1</i>
                                                </span>
                                            </td>
                                            <td> </td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>

                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">2</i>
                                                </span>
                                            </td>
                                            <td> </td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>

                        </h4>
                    </div>
                    <div id="collapsetwo" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">3</i>
                                                </span>
                                            </td>
                                            <td> </td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>

                        </h4>
                    </div>
                    <div id="collapsethree" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>

                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">4</i>
                                                </span>
                                            </td>
                                            <td> </td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>

                        </h4>
                    </div>
                    <div id="collapsefour" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>

                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">5</i>
                                                </span>
                                            </td>
                                            <td> </td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>

                        </h4>
                    </div>
                    <div id="collapsefive" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->

            </div>
            <!-- /.panel-group -->
        </div>
        <!-- /.col-lg-12 -->
    </div>

    <button id="Continue" class="btn btn-primary hidden disabled">Continue to Set-Up<i class="fa fa-arrow-right" aria-hidden="true"></i></button></code>```

Hope this helps.

Body:
I am trying to hide a button until all required elements on the page have been clicked. I found how to hide an element until one item is clicked but not sure how to set this to hide the button until all items are clicked.

The elements I want the users to click on are accordion panels with the ID's as "collaspeone", "collaspetwo" and so on. I want the user to click on each panel (which causes them to expand) then once they have clicked on each panel, show a button on the bottom of the page which allows them to continue to the next page.

Here is the element I want to show only when every panel has been clicked on.

<button id="Continue" class="btn btn-primary">Continue to Set-Up</button>

Here is my full HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<meta name="WebPartPageExpansion" content="full" />
<meta charset="utf-8"/>
    <meta http-equiv="x-ua-compatible" content="ie=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="canonical" href="http://html5-templates.com/" />
 <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
 <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
 <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"/>
 <link rel="manifest" href="/manifest.json"/>
 <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"/>
 <meta name="theme-color" content="#ffffff"/>
    <title>MySLM Portal</title>
 <meta name="description" content="A minimalist Bootstrap theme by StartBootstrap. Contains everything you need to get started building your website. All you have to do is change the text and images.">
    <link href="css/bootstrap.min.css" rel="stylesheet"/>
    <link href="css/modern-business.css" rel="stylesheet"/>
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="css/footer.css" rel="stylesheet" type="text/css"/>

                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    Toggle navigation

                </button>

                        Scope

                        General Questions

                        FAQ's

                        Processes

                                Create a New Supplier

                                Update an Existing Supplier

                                Reactivate a Supplier

                                Deactivate a Supplier

                        Contact

                        Resources

                                ERS Agreement Library

                                Corp Record List

                                Sanctioned Supplier List

                                Supplier Deactivation Listing

                                RemedyForce Training

                                Select Supplier Search

                                Yammer: Source to Pay NA

                                Job Aids

                                Knowledge/Self Help Articles

                                Policies

Sourcing and Purchasing Policy

Anti-bribery Policy

Bank Account & Payment Control Policy

Competition Policy

Conflicts of Interest Policy

Country Risk Policy

Insider Trading Policy

Legal Services Policy

Supplier Code of Conduct

Trade Sanctions Policy

United states & Canada Purchasing Cards Procedure

                        Links

                                Ariba

                                P2P Business Stakeholder Library

                                RemedyForce

                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

Wait! Make Your Job Easier!

Source through CSSP!

By sourcing through CSSP you can avoid having to navigate the entire complex supplier setup process and focus on your job while CSSP works for you in the background sourcing you a supplier and having them set-up in the appropriate ERP system for your use!

                 <button class="btn btn-primary">Lets go!  </button>

                  <button type="button" class="btn btn-default" data-dismiss="modal">No, I do not want to make my job easier</button>

Set-up a New Supplier
                    First Steps

The following steps should be completed by the requester prior to submitting a request to set-up a new supplier. Failure to perform these steps may result in rejection of, or delays on your request.

                        1

                    Panel Title

Panel Body

                        2

                    Panel Title

Panel Body

                        3

                    Panel Title

Panel Body

                        4

                    Panel Title

Panel Body

                        5

                    Panel Title

Panel Body

        <button id="Continue" class="btn btn-primary hidden disabled">Continue to Set-Up</button>

Questions? Check out our FAQ's

                    Go to FAQ's!

                            Code of Conduct

                            Supplier Code of Conduct

                            Policy Center

© 2017 Cargill, Incorporated. All Rights Reserved

Body:
Another variation would be to add a class "clicked" and display the button if the number of panels with class clicked is equal to total number of panels within the accordion.

$('div.panel-group#accordion .panel').click(function() {
  $(this).addClass('clicked');
  var count = $(this).parent().find('.panel').length, ctr = 0;
  $(this).parent().find('.panel').each(function() {
   if($(this).hasClass('clicked')) { ctr++; }
  });
  if(ctr === count) {
    $('button#Continue').removeClass('hidden disabled');
  }
})

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Content Row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel-group" id="accordion">
            <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">1</i>
                                                </span>
                                            </td>
                                            <td>&nbsp;</td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapsetwo">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">2</i>
                                                </span>
                                            </td>
                                            <td>&nbsp;</td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </a>
                        </h4>
                    </div>
                    <div id="collapsetwo" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapsethree">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">3</i>
                                                </span>
                                            </td>
                                            <td>&nbsp;</td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </a>
                        </h4>
                    </div>
                    <div id="collapsethree" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>

                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapsefour">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">4</i>
                                                </span>
                                            </td>
                                            <td>&nbsp;</td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </a>
                        </h4>
                    </div>
                    <div id="collapsefour" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>

                        </div>
                    </div>
                </div>
                <!-- /.panel -->
                <!-- panel -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapsefive">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <span class="fa-stack fa-2x">
                                                    <i class="fa fa-circle fa-stack-2x text-primary"></i>
                                                    <i class="fa-stack-1x fa-inverse">5</i>
                                                </span>
                                            </td>
                                            <td>&nbsp;</td>
                                            <td style="font-size:16pt">Panel Title</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </a>
                        </h4>
                    </div>
                    <div id="collapsefive" class="panel-collapse collapse">
                        <div class="panel-body">
                            <p>Panel Body</p>
                        </div>
                    </div>
                </div>
                <!-- /.panel -->

            </div>
            <!-- /.panel-group -->
        </div>
        <!-- /.col-lg-12 -->
    </div>

    <button id="Continue" class="btn btn-primary hidden disabled"><a href="AddSupplier-SubmitReq.aspx" style="color:white">Continue to Set-Up<i class="fa fa-arrow-right" aria-hidden="true"></i></a></button>

Hope this helps.


问:
How can I order items in a Matlab legend via the figure editor?
I've created a histogram with multiple sets of data.  The data sets are color imgages converted to grayscale and taken over a given time period (e.g. pic 1 @ time=0, pic 2 @ time=5min, etc.) which is why I need the legend entries to show up in  a specific order.  When I put the legend in, the entries are scattered around in no specific order and I can't figure out how to get the entries switched up the way I need them.  </p>

答:
The answer above also works for R2017a and higher...here is a little bit more general example:</p>

```<code>x = 1:10;
y1 = x;
y2 = 2*x;
y3 = 3*x;
y4 = x.^2;
figure
plot(x, y1, x, y2, x, y3, x, y4);
lh = legend('y = x', 'y = 2*x', 'y = 3*x', 'y = x.^2');

legendEntries = get(gca,'legend')
plotHandles = get(gca,'children')
legendEntries = legendEntries.String;
newOrder = [3,4,1,2];
legend([plotHandles(newOrder)],legendEntries{newOrder})
</code>```

Body:
The answer above also works for R2017a and higher...here is a little bit more general example:

x = 1:10;
y1 = x;
y2 = 2*x;
y3 = 3*x;
y4 = x.^2;
figure
plot(x, y1, x, y2, x, y3, x, y4);
lh = legend('y = x', 'y = 2*x', 'y = 3*x', 'y = x.^2');

legendEntries = get(gca,'legend')
plotHandles = get(gca,'children')
legendEntries = legendEntries.String;
newOrder = [3,4,1,2];
legend([plotHandles(newOrder)],legendEntries{newOrder})


问:
How to make my local spark that i have modified as dependency in maven
I have modified the core of Spark and I added a library
to execute tasks in gpu but i want to compile some tests
with maven .How can make this local modified spark as dependency
to compile my tests scala files with maven</p>

答:
I think you can give local repository in pom.</p>

```<code><repository>
    <id>in-project</id>
    <name>In Project Repo</name>
    <url>file://${project.basedir}/library</url>
</repository>
</code>```

Body:
I think you can give local repository in pom.

<repository>
    <id>in-project</id>
    <name>In Project Repo</name>
    <url>file://${project.basedir}/library</url>
</repository>


问:
Filtering using viewsets in django rest framework
Please consider these three models:

```<code>class Movie(models.Model):
    name = models.CharField(max_length=254, unique=True)
    language = models.CharField(max_length=14)
    synopsis = models.TextField()

class TimeTable(models.Model):
    date = models.DateField()

class Show(models.Model):
    day = models.ForeignKey(TimeTable)
    time = models.TimeField(choices=CHOICE_TIME)
    movie = models.ForeignKey(Movie)

    class Meta:
        unique_together = ('day', 'time')
</code>```

And each of them has their serializers:

```<code>class MovieSerializer(serializers.HyperlinkedModelSerializer):
    movie_id = serializers.IntegerField(read_only=True, source="id")

    class Meta:
        model = Movie
        fields = '__all__'

class TimeTableSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = TimeTable
        fields = '__all__'

class ShowSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Show
        fields = '__all__'
</code>```

And their routers

```<code>router.register(r'movie-list', views.MovieViewSet)
router.register(r'time-table', views.TimeTableViewSet)
router.register(r'show-list', views.ShowViewSet)
</code>```

Now I would like to get all the TimeTable objects (i.e. date list) by filtering all the Show objects by a specific movie object. This code seems to be the working and getting the list like I want it

```<code>m = Movie.objects.get(id=request_id)
TimeTable.objects.filter(show__movie=m).distinct()
</code>```

But I have no clue how to use this in django rest framework? I tried doing this way (which I am  pretty sure its wrong), and I am getting error:

views.py:

```<code>class DateListViewSet(viewsets.ModelViewSet, movie_id):
    movie = Movie.objects.get(id=movie_id)
    queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    serializer_class = TimeTableSerializer
</code>```

urls.py:

```<code>router.register(r'date-list/(?P<movie_id>.+)/', views.DateListViewSet)
</code>```

error:

class DateListViewSet(viewsets.ModelViewSet, movie_id):
  NameError: name 'movie_id' is not defined

How can I filter using viewsets in django rest framework? Or if there is any other prefered way than please list it out. Thank you.

答:
To improve @all-is-vanity answer, you can explicitly use movie_id as a parameter in the retrieve function since you are overriding the lookup_field class property:

```<code>def retrieve(self, request, movie_id=None):
    movie = Movie.objects.get(id=movie_id)
    self.queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    return super(DateListViewSet, self).retrieve(request, *args, **kwargs)
</code>```

You can also call self.get_object() to get the object:

```<code>def retrieve(self, request, movie_id=None):
    movie = self.get_object()
    self.queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    return super(DateListViewSet, self).retrieve(request, *args, **kwargs)
</code>```

Body:
Please consider these three models:

class Movie(models.Model):
    name = models.CharField(max_length=254, unique=True)
    language = models.CharField(max_length=14)
    synopsis = models.TextField()

class TimeTable(models.Model):
    date = models.DateField()

class Show(models.Model):
    day = models.ForeignKey(TimeTable)
    time = models.TimeField(choices=CHOICE_TIME)
    movie = models.ForeignKey(Movie)

    class Meta:
        unique_together = ('day', 'time')

And each of them has their serializers:

class MovieSerializer(serializers.HyperlinkedModelSerializer):
    movie_id = serializers.IntegerField(read_only=True, source="id")

    class Meta:
        model = Movie
        fields = '__all__'

class TimeTableSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = TimeTable
        fields = '__all__'

class ShowSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Show
        fields = '__all__'

And their routers

router.register(r'movie-list', views.MovieViewSet)
router.register(r'time-table', views.TimeTableViewSet)
router.register(r'show-list', views.ShowViewSet)

Now I would like to get all the TimeTable objects (i.e. date list) by filtering all the Show objects by a specific movie object. This code seems to be the working and getting the list like I want it

m = Movie.objects.get(id=request_id)
TimeTable.objects.filter(show__movie=m).distinct()

But I have no clue how to use this in django rest framework? I tried doing this way (which I am  pretty sure its wrong), and I am getting error:

views.py:

class DateListViewSet(viewsets.ModelViewSet, movie_id):
    movie = Movie.objects.get(id=movie_id)
    queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    serializer_class = TimeTableSerializer

urls.py:

router.register(r'date-list/(?P<movie_id>.+)/', views.DateListViewSet)

error:

class DateListViewSet(viewsets.ModelViewSet, movie_id):
  NameError: name 'movie_id' is not defined

How can I filter using viewsets in django rest framework? Or if there is any other prefered way than please list it out. Thank you.

Body:
To improve @all-is-vanity answer, you can explicitly use movie_id as a parameter in the retrieve function since you are overriding the lookup_field class property:

def retrieve(self, request, movie_id=None):
    movie = Movie.objects.get(id=movie_id)
    self.queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    return super(DateListViewSet, self).retrieve(request, *args, **kwargs)

You can also call self.get_object() to get the object:

def retrieve(self, request, movie_id=None):
    movie = self.get_object()
    self.queryset = TimeTable.objects.filter(show__movie=movie).distinct()
    return super(DateListViewSet, self).retrieve(request, *args, **kwargs)


问:
Build Windows DllMain DLL with CMake
I have a question similar to this one. I am trying to compile a DLL for windows similar to how Visual Studio would, except with CLion and CMake. I've tried the answer in the question, as well as the steps shown here, but I still get an error while injecting.

My dll code is very simple, a similar dll compiled in visual studio works fine:

```<code>#include <windows.h>
#include <iostream>
using namespace std;

void hello() {
    AllocConsole();
    freopen("CONOUT$", "w", stdout);
    cout << "Hello, World!" << endl;
}

bool __stdcall DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/) {
    if (reason == DLL_PROCESS_ATTACH) hello();
    return true;
}
</code>```

Also, here's what I tried in CMakeLists.txt: sorry, there should have been a space between PROJECT_NAME and MODULE

```<code>cmake_minimum_required(VERSION 3.9)
project(PROJECT_NAME)
include (GenerateExportHeader)
set(CMAKE_CXX_STANDARD 17)

add_library(PROJECT_NAME MODULE main.cpp)
set_target_properties(PROJECT_NAME PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
GENERATE_EXPORT_HEADER(PROJECT_NAME
    BASE_NAME PROJECT_NAME
    EXPORT_MACRO_NAME PROJECT_NAME_EXPORT
    EXPORT_FILE_NAME PROJECT_NAME_Export.h
    STATIC_DEFINE PROJECT_NAME_BUILT_AS_STATIC)
</code>```

答:
You have two options:

Add the BUILD_SHARED_LIBS variable to CMake's cache as a boolean value then check it. This will modify the behaviour of the add_library command to make a shared library i.e. a DLL file on Windows.

Explicitly create the library as shared: add_library(PROJECT_NAMEMODULE SHARED main.cpp)

BUILD_SHARED_LIBS variable documentation: https://cmake.org/cmake/help/v3.10/variable/BUILD_SHARED_LIBS.html

Title: Build Windows DllMain DLL with CMake

Body:
I have a question similar to this one. I am trying to compile a DLL for windows similar to how Visual Studio would, except with CLion and CMake. I've tried the answer in the question, as well as the steps shown here, but I still get an error while injecting.

My dll code is very simple, a similar dll compiled in visual studio works fine:

#include <windows.h>
#include <iostream>
using namespace std;

void hello() {
    AllocConsole();
    freopen("CONOUT$", "w", stdout);
    cout << "Hello, World!" << endl;
}

bool __stdcall DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/) {
    if (reason == DLL_PROCESS_ATTACH) hello();
    return true;
}

Also, here's what I tried in CMakeLists.txt: sorry, there should have been a space between PROJECT_NAME and MODULE

cmake_minimum_required(VERSION 3.9)
project(PROJECT_NAME)
include (GenerateExportHeader)
set(CMAKE_CXX_STANDARD 17)

add_library(PROJECT_NAME MODULE main.cpp)
set_target_properties(PROJECT_NAME PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
GENERATE_EXPORT_HEADER(PROJECT_NAME
    BASE_NAME PROJECT_NAME
    EXPORT_MACRO_NAME PROJECT_NAME_EXPORT
    EXPORT_FILE_NAME PROJECT_NAME_Export.h
    STATIC_DEFINE PROJECT_NAME_BUILT_AS_STATIC)


问:
looping over different factor levels in a dataframe
I have some code to take random samples of 1 to 10 rows from a data frame, replicate that random sampling 5 times and calculate a network metric (connectance) on each of the random samples. However, I would like to run this code separately over each level of "site" and "method" in my data frame.

How do I split the data frame (df) by site and method, run the code below on each subset and then return all outputs into a single file that has the columns "site", "method", "size" (number of rows sampled) and "connectance"?

Here is what I have so far:

```<code>df <- read.table(text = "bird_sp plant_sp value site method
                  1  species_a  plant_a     1    a      m
                  2  species_a  plant_a     1    a      m
                  3  species_b  plant_b     1    a      m
                  4  species_b  plant_b     1    a      m
                  5  species_c  plant_c     1    a      m
                  6  species_a  plant_a     1    b      m
                  7  species_a  plant_a     1    b      m
                  8  species_b  plant_b     1    b      m
                  9  species_b  plant_b     1    b      m
                  10 species_c  plant_c     1    b      m
                  11 species_a  plant_a     1    a      f
                  12 species_a  plant_a     1    a      f
                  13 species_b  plant_b     1    a      f
                  14 species_b  plant_b     1    a      f
                  15 species_c  plant_c     1    a      f
                  16 species_a  plant_a     1    b      f
                  17 species_a  plant_a     1    b      f
                  18 species_b  plant_b     1    b      f
                  19 species_b  plant_b     1    b      f
                  20 species_c  plant_c     1    b      f", header = TRUE)

#make sample function
sample_fun <- function(x,size){
rows <- sample(1:nrow(x),size,replace=FALSE)
intlist <- x[rows,]
return(intlist)
}

#convert list to interaction matrix
make_mat <- function(x){
mat <- with(x,tapply(value, list(plant_sp, bird_sp), sum))
mat[is.na(mat)] <- 0
return(mat)
}

#create vector with required sample size and replication
size_vector <- rep(1:10,5)

#use vector to generate list of interactions
samples_Data <- lapply(size_vector, function(x) sample_fun(df,x))

output <- lapply(samples_Data, function(x)
make_mat(x))

library(bipartite)

#calculate connectance on each element (matrix) in output list
#ignore warnings
metrics <- lapply(output, networklevel, index=c("connectance"))
met <- data.frame(unlist(metrics))
names(met) <- names(metrics[[1]])

#Add number of interactions sampled
met$size <- size_vector
</code>```

答:
You can split the dataset by site and method with the following command.

```<code>df_split <- split(df, paste0(df$site, df$method))
</code>```

Afterwards you can apply a function to each subset with lapply, i.e.:

```<code>lapply(df_split, FUN = nrow)
</code>```

To get your output you can do, i.e.:

```<code>result <- unique(df[, c("site", "method")])
result <- result[order(result$site, result$method),] # !! SEE BELOW
result$rows <- lapply(df_split, FUN = nrow)
result
    site method rows
 11    a      f    5
 1     a      m    5
 16    b      f    5
 6     b      m    5
</code>```

Be sure to do the order command!! Split seems to automatically order the subsets alphabetically.

To generate your variable just put all your code from above into a function and run it on each subset the same way as the nrow function seen above.

Body:
I have some code to take random samples of 1 to 10 rows from a data frame, replicate that random sampling 5 times and calculate a network metric (connectance) on each of the random samples. However, I would like to run this code separately over each level of "site" and "method" in my data frame.

How do I split the data frame (df) by site and method, run the code below on each subset and then return all outputs into a single file that has the columns "site", "method", "size" (number of rows sampled) and "connectance"?

Here is what I have so far:

df <- read.table(text = "bird_sp plant_sp value site method
                  1  species_a  plant_a     1    a      m
                  2  species_a  plant_a     1    a      m
                  3  species_b  plant_b     1    a      m
                  4  species_b  plant_b     1    a      m
                  5  species_c  plant_c     1    a      m
                  6  species_a  plant_a     1    b      m
                  7  species_a  plant_a     1    b      m
                  8  species_b  plant_b     1    b      m
                  9  species_b  plant_b     1    b      m
                  10 species_c  plant_c     1    b      m
                  11 species_a  plant_a     1    a      f
                  12 species_a  plant_a     1    a      f
                  13 species_b  plant_b     1    a      f
                  14 species_b  plant_b     1    a      f
                  15 species_c  plant_c     1    a      f
                  16 species_a  plant_a     1    b      f
                  17 species_a  plant_a     1    b      f
                  18 species_b  plant_b     1    b      f
                  19 species_b  plant_b     1    b      f
                  20 species_c  plant_c     1    b      f", header = TRUE)

#make sample function
sample_fun <- function(x,size){
rows <- sample(1:nrow(x),size,replace=FALSE)
intlist <- x[rows,]
return(intlist)
}

#convert list to interaction matrix
make_mat <- function(x){
mat <- with(x,tapply(value, list(plant_sp, bird_sp), sum))
mat[is.na(mat)] <- 0
return(mat)
}

#create vector with required sample size and replication
size_vector <- rep(1:10,5)

#use vector to generate list of interactions
samples_Data <- lapply(size_vector, function(x) sample_fun(df,x))

output <- lapply(samples_Data, function(x)
make_mat(x))

library(bipartite)

#calculate connectance on each element (matrix) in output list
#ignore warnings
metrics <- lapply(output, networklevel, index=c("connectance"))
met <- data.frame(unlist(metrics))
names(met) <- names(metrics[[1]])

#Add number of interactions sampled
met$size <- size_vector

Body:
You can split the dataset by site and method with the following command.

df_split <- split(df, paste0(df$site, df$method))

Afterwards you can apply a function to each subset with lapply, i.e.:

lapply(df_split, FUN = nrow)

To get your output you can do, i.e.:

result <- unique(df[, c("site", "method")])
result <- result[order(result$site, result$method),] # !! SEE BELOW
result$rows <- lapply(df_split, FUN = nrow)
result
    site method rows
 11    a      f    5
 1     a      m    5
 16    b      f    5
 6     b      m    5

Be sure to do the order command!! Split seems to automatically order the subsets alphabetically.

To generate your variable just put all your code from above into a function and run it on each subset the same way as the nrow function seen above.


问:
MS Access 2007 error number: 2950 on Trusted Document?
In my *.mdb file I have a macro with an action that runs TransferText and gives me an Error Number of 2950 which according to Microsoft means that the document is not trusted, as far as I know it is trusted!  It's located in the Trust Center Trusted Locations.

Is there an explanation point next to the Action causing this in the macro whose tooltip reads This action will not be allowed if the database is not Trusted.

I already tried running a compact and repair on it, what could be causing this?

答:
In my case there was a naming conflict. The macro in turn called a VBA function, and I had inadvertently named the function with the same name as the module it was in. They were both named "RobertsReport". Once I changed the name, everything worked as expected.

Tip: As troubleshooting steps, try running the macro solo by double-clicking on it. If you can, copy only the line that generates the error to a new macro to test it by itself, and of course include any preceding commands it may need to run properly. Once I did this it greatly narrowed down the problem until the lightbulb came on over my head.


问:
Bitwise operators won't translate from JavaScript to PHP
I'm trying to translate this segment of code which makes use of bitwise operators in a loop, from JavaScript to PHP.  Here is the JavaScript code:

```<code>for( var k = 0, iTop = str.length; k < iTop; k++ )
{
    crc = (crc >> 8) ^ ("0x" + table.substr(((crc ^ str.charCodeAt(k) ) & 0x000000FF) * 9, 8));
    document.write(crc);
}
</code>```

Here is the same code translated into PHP

```<code>for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
{
    $crc = ($crc >> 8) ^ ("0x" . substr($table, (($crc ^ ord($str[$k]) ) & 0x000000FF) * 9, 8));
    echo $crc;
}
</code>```

These two segments give different values for the crc variable.  All the variables going into both of them are identical.

Am I making a silly error, or will this code not translate because of some difficulty with translating bitwise operators?

Here is the complete code for both:

Javascript:

```<code><html><head><meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta http-equiv="CacheControl" content="no-cache"/>
<script type="text/javascript">function test(){var table = "00000000 77073096 EE0E612C     990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
var c = 1750271245;
var slt = "2qGU4Lt1";
var s1 = 'v';
var s2 = 'z';
var n = 4;
var start = s1.charCodeAt(0);
var end   = s2.charCodeAt(0);
var arr = new Array(n);
var m = Math.pow(((end - start) + 1),n);
for (var i=0; i<n; i++)
    arr[i] = s1;
for (var i=0; i<m-1; i++){
    for(var j=n-1; j>=0;--j) {
        var t = arr[j].charCodeAt(0);
        t++; arr[j] = String.fromCharCode(t);
        if (arr[j].charCodeAt(0)<=end) {
            break;
        } else {
            arr[j] = s1 ;
        }
    }
    var chlg = arr.join(""); var str = chlg + slt;
    var crc = 0;
    var crc = crc ^ (-1);

    for( var k = 0, iTop = str.length; k < iTop; k++ )
    {
        document.write((((crc ^ str.charCodeAt(k) ) & 0x000000FF) * 9) + "\n");
        crc = (crc >> 8) ^ ("0x" + table.substr(((crc ^ str.charCodeAt(k) ) & 0x000000FF) * 9, 8));
    }
    crc =  crc ^ (-1);
    crc = Math.abs(crc);
    if (crc == parseInt(c)){
        break;
    }
}
document.cookie ="TS884e96_75=" + "8643a82fd76d477a904aa3267724056d:" + chlg + ":" + slt + ":" + crc + ";Max-Age=3600;path=/";}</script></head><body onload="test()">
</body></html>
</code>```

PHP

```<code><?php

ini_set("display_errors","1");

$table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";

$c = 1750271245; //we'd get this from reading the script
$slt = "2qGU4Lt1"; //we'd get this from reading the script

$s1 = 'v'; //we'd get this from reading the script
$s2 = 'z'; //we'd get this from reading the script
$n = 4; //we'd get this from reading the script, just to be safe
$start = ord($s1);
$end = ord($s2);
$arr = array();
$m = pow(($end - $start + 1 ), $n);
for ($i=0; $i<$n; $i++)
{
    $arr[$i] = $s1;
}
for ($i=0; $i<$m-1; $i++)
{
    for ($j = $n-1; $j>=0; $j--)
    {
        $t = ord($arr[$j]);
        $t++;
        $arr[$j] = chr($t);
        if (ord($arr[$j]) <= $end)
        {
        break;
        }
        else
        {
        $arr[$j] = $s1;
        }
}
$chlg = implode('', $arr);
$str = $chlg . $slt;
$crc = 0;
$crc = $crc ^ (-1);
//ord($str[$k]) Is correct
//

    for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
    {
        $crc = ($crc >> 8) ^ ("0x" . substr($table, (($crc ^ ord($str[$k]) ) & 0x000000FF) * 9, 8));
    }
    $crc =  $crc ^ (-1);
    $crc = abs($crc);
    if ($crc == intval($c))
    {
        break;
    }
}

echo $chlg;
?>
</code>```

UPDATE:  It's definitely a 32 bit issue.  I know because echo (int) -1 ^ (int) 2489596804; gives -2489596805 instead of 1805370491.  What should I do?

GMP CODE:

```<code>for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
{
    $crc = gmp_xor(
                    (gmp_intval($crc) >> 8),
                    hexdec(substr(
                        $table,
                        gmp_intval(gmp_mul(
                            gmp_and(gmp_xor($crc, ord($str[$k])), 0x000000FF),
                            9)),
                        8))
                ); //we use gmp because we're on 32 bit and bitwise operator cant work for that.
    echo gmp_strval($crc) . "\n";
}
</code>```

答:
The "0x" trick won't work in PHP. While PHP interprets an "0x1234" string as number in some contexts, for binary arithmetic with & 0x00FF it won't work.

Instead try hexdec() around the substr(). It might however fail for too big values (which PHPs hexdec returns as float).

Body:
I'm trying to translate this segment of code which makes use of bitwise operators in a loop, from JavaScript to PHP.  Here is the JavaScript code:

for( var k = 0, iTop = str.length; k < iTop; k++ )
{
    crc = (crc >> 8) ^ ("0x" + table.substr(((crc ^ str.charCodeAt(k) ) & 0x000000FF) * 9, 8));
    document.write(crc);
}

Here is the same code translated into PHP

for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
{
    $crc = ($crc >> 8) ^ ("0x" . substr($table, (($crc ^ ord($str[$k]) ) & 0x000000FF) * 9, 8));
    echo $crc;
}

These two segments give different values for the crc variable.  All the variables going into both of them are identical.

Am I making a silly error, or will this code not translate because of some difficulty with translating bitwise operators?

Here is the complete code for both:

Javascript:

<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta http-equiv="CacheControl" content="no-cache"/>

PHP

<?php

ini_set("display_errors","1");

$table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";

$c = 1750271245; //we'd get this from reading the script
$slt = "2qGU4Lt1"; //we'd get this from reading the script

$s1 = 'v'; //we'd get this from reading the script
$s2 = 'z'; //we'd get this from reading the script
$n = 4; //we'd get this from reading the script, just to be safe
$start = ord($s1);
$end = ord($s2);
$arr = array();
$m = pow(($end - $start + 1 ), $n);
for ($i=0; $i<$n; $i++)
{
    $arr[$i] = $s1;
}
for ($i=0; $i<$m-1; $i++)
{
    for ($j = $n-1; $j>=0; $j--)
    {
        $t = ord($arr[$j]);
        $t++;
        $arr[$j] = chr($t);
        if (ord($arr[$j]) <= $end)
        {
        break;
        }
        else
        {
        $arr[$j] = $s1;
        }
}
$chlg = implode('', $arr);
$str = $chlg . $slt;
$crc = 0;
$crc = $crc ^ (-1);
//ord($str[$k]) Is correct
//

    for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
    {
        $crc = ($crc >> 8) ^ ("0x" . substr($table, (($crc ^ ord($str[$k]) ) & 0x000000FF) * 9, 8));
    }
    $crc =  $crc ^ (-1);
    $crc = abs($crc);
    if ($crc == intval($c))
    {
        break;
    }
}

echo $chlg;
?>

UPDATE:  It's definitely a 32 bit issue.  I know because echo (int) -1 ^ (int) 2489596804; gives -2489596805 instead of 1805370491.  What should I do?

GMP CODE:

for($k = 0, $iTop = strlen($str); $k < $iTop; $k++ )
{
    $crc = gmp_xor(
                    (gmp_intval($crc) >> 8),
                    hexdec(substr(
                        $table,
                        gmp_intval(gmp_mul(
                            gmp_and(gmp_xor($crc, ord($str[$k])), 0x000000FF),
                            9)),
                        8))
                ); //we use gmp because we're on 32 bit and bitwise operator cant work for that.
    echo gmp_strval($crc) . "\n";
}


问:
how to reload the chat Message/listing of chat automatically in applozic framework
how to reload the chat Message/listing of chat automatically in applozic framework. in the demo of the Applozic gives refresh button to reload chat message and listing of chat.</p>

答:
If you have done the notification setup correct  it will reload the chat listing automatically

You can check this in push notification test tool, if the setup is correct or not  you will get success  response in status column

Push notification test tool link

This is doc link for ios  push notification setup   link


问:
How to deploy Nestjs App (on Azure)?
I am trying to deploy a Nestjs API (with Auth0 authentication). When I run it in VS Code with npm run start:watch server, everything's fine.
Now the question is: what should I do to deploy it on a webserver? Should I only copy the dist folder (after runnin tsc)? what about node_modules? Should I leave the port to 3000?
As a side note I am trying to deploy it on Azure but I guess the questions holds for any platform.

Many thanks!

答:
Modify your package.json file, and add a postinstall script, this script should be tsc or tsc --sourceMap false if you would like to avoid sourceMaps from being generated.

That would make azure to run tsc after installing all npm packages, remember to change start script also, so its value is 'node dist/index.js'

Title: How to deploy Nestjs App (on Azure)?


答:
An expression for that:

```<code>sed -E 's,./.,-1,g' <(echo './.')
</code>```

You can use delimiters different from /, so you don't have to escape them, . doesn't have to be excaped if you are using extended regular expressions.

Possible delimiters(there may be others):

:

_

,

|

So in your case:

```<code>sed -E -i.backup 's,./.,-1,g' File_name
</code>```

, or you are able to escape .-s and /-s, but that can lead to a mess:

```<code>sed -i.backup 's/\.\/\./-1/g' File_name
</code>```

Please use an extension name after the i flag to make a backup file if you're not sure about the result of the sed command.

Title: How can we replace "./." with "-1"

Body:
Input:

7058    7067    7111    7186    7288    7322    7328    7373
./. ./. ./. ./. ./. 0|0 ./. 0|0
./. ./. 0|0 ./. ./. 0|0 ./. 0|0
./. ./. ./. ./. ./. 0|0 ./. 0|0
./. ./. ./. ./. ./. 0|0 ./. 1|1

Desired output:

7058    7067    7111    7186    7288    7322    7328    7373
-1  -1  -1  -1  -1  0|0 -1  0|0
-1  -1  0|0 -1  -1  0|0 -1  0|0
-1  -1  -1  -1  -1  0|0 -1  0|0
-1  -1  -1  -1  -1  0|0 -1  1|1

I have tried sed -i 's/././-1/g' File_name but it didn't work.

Body:
An expression for that:

sed -E 's,./.,-1,g' <(echo './.')

You can use delimiters different from /, so you don't have to escape them, . doesn't have to be excaped if you are using extended regular expressions.

Possible delimiters(there may be others):

:

_

,

|

So in your case:

sed -E -i.backup 's,./.,-1,g' File_name

, or you are able to escape .-s and /-s, but that can lead to a mess:

sed -i.backup 's/\.\/\./-1/g' File_name

Please use an extension name after the i flag to make a backup file if you're not sure about the result of the sed command.


问:
Toggle multiple css classes on div with javascript
I have a problem to toggle between 4 color classes.
I trying to change color everytime this function is used.

```<code>function changeBackground() {
    var all = getSelected();

    var blue = document.getElementsByClassName("blue");
    for (var i = 0; i < all.length; i++) {
        all[i].classList.add("green");
        all[i].classList.remove("blue");
    }

    var red = document.getElementsByClassName("red");
    for (var i = 0; i < red.length; i++) {
        all[i].classList.add("blue");
        all[i].classList.remove("red");
    }

    var yellow = document.getElementsByClassName("yellow");
    for (var i = 0; i < yellow.length; i++) {
        all[i].classList.add("red");
        all[i].classList.remove("yellow");
    }

    for (var i = 0; i < all.length; i++) {
        all[i].classList.add("yellow");
        all[i].classList.remove("green");

    }
}
</code>```

getSelected returns document.getElementsByClassName("selected");
and make sure only divs who are selected do change background.

Html looks like this:

Works well untill it comes to blue->green and the classes won't be removed.
How do i solve this?

答:
Please check this https://jsfiddle.net/maflorezp/1u3xjxaq/1/

You have some errors walking the elements and you need validate class before change

```<code>function changeBackground() {
    var all = getSelected();

    for (var i = 0; i < all.length; i++) {
        var color = all[i].classList;
        if(color.contains("blue")){
          all[i].classList.add("green");
          all[i].classList.remove("blue");
        } else if(color.contains("red")){
          all[i].classList.add("blue");
          all[i].classList.remove("red");
        } else if(color.contains("yellow")){
          all[i].classList.add("red");
          all[i].classList.remove("yellow");
        } else if(color.contains("green")){
          all[i].classList.add("yellow");
          all[i].classList.remove("green");
        }
    }
}
</code>```

Body:
I have a problem to toggle between 4 color classes.
I trying to change color everytime this function is used.

function changeBackground() {
    var all = getSelected();

    var blue = document.getElementsByClassName("blue");
    for (var i = 0; i < all.length; i++) {
        all[i].classList.add("green");
        all[i].classList.remove("blue");
    }

    var red = document.getElementsByClassName("red");
    for (var i = 0; i < red.length; i++) {
        all[i].classList.add("blue");
        all[i].classList.remove("red");
    }

    var yellow = document.getElementsByClassName("yellow");
    for (var i = 0; i < yellow.length; i++) {
        all[i].classList.add("red");
        all[i].classList.remove("yellow");
    }

    for (var i = 0; i < all.length; i++) {
        all[i].classList.add("yellow");
        all[i].classList.remove("green");

    }
}

getSelected returns document.getElementsByClassName("selected");
and make sure only divs who are selected do change background.

Html looks like this:

Works well untill it comes to blue->green and the classes won't be removed.
How do i solve this?

Body:
Please check this https://jsfiddle.net/maflorezp/1u3xjxaq/1/

You have some errors walking the elements and you need validate class before change

function changeBackground() {
    var all = getSelected();

    for (var i = 0; i < all.length; i++) {
        var color = all[i].classList;
        if(color.contains("blue")){
          all[i].classList.add("green");
          all[i].classList.remove("blue");
        } else if(color.contains("red")){
          all[i].classList.add("blue");
          all[i].classList.remove("red");
        } else if(color.contains("yellow")){
          all[i].classList.add("red");
          all[i].classList.remove("yellow");
        } else if(color.contains("green")){
          all[i].classList.add("yellow");
          all[i].classList.remove("green");
        }
    }
}


问:
Update a store property
I am getting a response from an API as below:

```<code>{
    "results": {
        "6": {
            "id": 6,
            "name": "akkha madrasi mirchi1",
        },
        "7": {
            "id": 7,
            "name": "almonds",
        },
        "8": {
            "id": 8,
            "name": "alu1",
        }
    }
}
</code>```

I am storing response.results in results reducer store {} so that I can access results as store.results. I want to modify an object inside the results. The API only returns the updated object. Now I want to update  id: 6 in store.results.

```<code>{
    "results": {
        "6": {
            "id": 6,
            "name": "Modified akkha madrasi mirchi1",
        }
    }
}
</code>```

If I do this in the results reducer:

```<code>[...state,action.response]
</code>```

will the object with key 6 replace the object with matching keys?

I am expecting state to be (note name changed to Modified akkha madrasi mirchi1 for id: 6):

```<code>"results": {
    "6": {
        "id": 6,
        "name": "Modified akkha madrasi mirchi1",
    },
    "7": {
        "id": 7,
        "name": "almonds",
    },
    "8": {
        "id": 8,
        "name": "alu1",
    }
}
</code>```

I want objects to be updated even if they are nested. Just match the key and keep on replacing.

答:
Assuming that state is:

```<code>{
    "6": {
        "id": 6,
        "name": "akkha madrasi mirchi1"
    },
    "7": {
        "id": 7,
        "name": "almonds"
    },
    "8": {
        "id": 8,
        "name": "alu1"
    }
}
</code>```

and you want to update with the following:

```<code>const obj = {
  "6": {
        "id": 6,
        "name": "Modified akkha madrasi mirchi1"
   }
};
</code>```

Then the following will do it:

```<code>state = Object.assign( {}, state, obj);
</code>```

Title: Update a store property

Body:
I am getting a response from an API as below:

{
    "results": {
        "6": {
            "id": 6,
            "name": "akkha madrasi mirchi1",
        },
        "7": {
            "id": 7,
            "name": "almonds",
        },
        "8": {
            "id": 8,
            "name": "alu1",
        }
    }
}

I am storing response.results in results reducer store {} so that I can access results as store.results. I want to modify an object inside the results. The API only returns the updated object. Now I want to update  id: 6 in store.results.

{
    "results": {
        "6": {
            "id": 6,
            "name": "Modified akkha madrasi mirchi1",
        }
    }
}

If I do this in the results reducer:

[...state,action.response]

will the object with key 6 replace the object with matching keys?

I am expecting state to be (note name changed to Modified akkha madrasi mirchi1 for id: 6):

"results": {
    "6": {
        "id": 6,
        "name": "Modified akkha madrasi mirchi1",
    },
    "7": {
        "id": 7,
        "name": "almonds",
    },
    "8": {
        "id": 8,
        "name": "alu1",
    }
}

I want objects to be updated even if they are nested. Just match the key and keep on replacing.

Body:
Assuming that state is:

{
    "6": {
        "id": 6,
        "name": "akkha madrasi mirchi1"
    },
    "7": {
        "id": 7,
        "name": "almonds"
    },
    "8": {
        "id": 8,
        "name": "alu1"
    }
}

and you want to update with the following:

const obj = {
  "6": {
        "id": 6,
        "name": "Modified akkha madrasi mirchi1"
   }
};

Then the following will do it:

state = Object.assign( {}, state, obj);


问:
Is there an easy way in xunit.net to compare two collections without regarding the items' order?
In one of my tests, I want to ensure that a collection has certain items. Therefore, I want to compare this collection with the items of an expected collection not regarding the order of the items. Currently, my test code looks somewhat like this:

```<code>[Fact]
public void SomeTest()
{
    // Do something in Arrange and Act phase to obtain a collection
    List<int> actual = ...

    // Now the important stuff in the Assert phase
    var expected = new List<int> { 42, 87, 30 };
    Assert.Equal(expected.Count, actual.Count);
    foreach (var item in actual)
        Assert.True(expected.Contains(item));
}
</code>```

Is there any easier way to achieve this in xunit.net? I can't use Assert.Equal as this method checks if the order of the items is the same in both collections. I had a look at Assert.Collection but that doesn't remove the Assert.Equal(expected.Count, actual.Count) statement in the code above.

答:
You can use CollectionAssert.AreEquivalent from Microsoft

```<code>CollectionAssert.AreEquivalent(expected, actual);
</code>```

ContentLicense: CC BY-SA 4.0

Body:
In one of my tests, I want to ensure that a collection has certain items. Therefore, I want to compare this collection with the items of an expected collection not regarding the order of the items. Currently, my test code looks somewhat like this:

[Fact]
public void SomeTest()
{
    // Do something in Arrange and Act phase to obtain a collection
    List<int> actual = ...

    // Now the important stuff in the Assert phase
    var expected = new List<int> { 42, 87, 30 };
    Assert.Equal(expected.Count, actual.Count);
    foreach (var item in actual)
        Assert.True(expected.Contains(item));
}

Is there any easier way to achieve this in xunit.net? I can't use Assert.Equal as this method checks if the order of the items is the same in both collections. I had a look at Assert.Collection but that doesn't remove the Assert.Equal(expected.Count, actual.Count) statement in the code above.

Body:
You can use CollectionAssert.AreEquivalent from Microsoft

CollectionAssert.AreEquivalent(expected, actual);


问:
classical inheritance vs prototypal inheritance in javascript
I have googled so many links and can't get good idea about the difference between classical inheritance and prototypal inheritance?

I have learned some things from these but I'm still confused about the concepts.

Benefits of prototypal inheritance over classical?

http://aaditmshah.github.io/why-prototypal-inheritance-matters/

Classical inheritance

```<code>// Shape - superclass
function Shape() {
  this.x = 0;
  this.y = 0;
}

//superclass method
Shape.prototype.move = function(x, y) {
    this.x += x;
    this.y += y;
    console.info("Shape moved.");
};

// Rectangle - subclass
function Rectangle() {
  Shape.call(this); //call super constructor.
}

//subclass extends superclass
Rectangle.prototype = Object.create(Shape.prototype);
</code>```

Does classical inheritance use prototypal inheritance inside?

http://aaditmshah.github.io/why-prototypal-inheritance-matters/

From above link, I learned we can't add new methods at run time in classical inheritance. Is this correct? But you can check the above code I can add "move" method and any methods at run time through prototype. So this is prototype based classical inheritance? If so what is actual classical inheritance and prototype inheritance? I am confused about that.

Prototypal inheritance.

```<code>function Circle(radius) {
    this.radius = radius;
}
Circle.prototype.area = function () {
    var radius = this.radius;
    return Math.PI * radius * radius;
};
Circle.prototype.circumference: function () {
    return 2 * Math.PI * this.radius;
};
var circle = new Circle(5);
var circle2 = new Circle(10);
</code>```

Is this similar to classical inheritance? I'm totally confused about what is prototypal inheritance? What is classical inheritance? Why is classical inheritance bad?

Can you give me a simple example for better understanding these in a simple manner.

Thanks,

Siva

答:
Before jumping into inheritance, we will take a look at two primary models to create instances (objects) in javascript:

Classical model: Object is created from a blueprint (class)

```<code>class Person {
  fn() {...}
} // or constructor function say, function Person() {}

// create instance
let person = new Person();
</code>```

Prototypal model: Object is created directly from another object.

```<code>// base object
let Person = { fn(){...} }

// instance
let person = Object.create(Person);
</code>```

In either case, Inheritance* is achieved by linking objects using prototype object.

(*base class methods are accessible via. derived class through the prototype object and not required to be explicitly present in derived class.)

Here is a good explanation to understand better (http://www.objectplayground.com/)

Body:
I have googled so many links and can't get good idea about the difference between classical inheritance and prototypal inheritance?

I have learned some things from these but I'm still confused about the concepts.

Benefits of prototypal inheritance over classical?

http://aaditmshah.github.io/why-prototypal-inheritance-matters/

Classical inheritance

// Shape - superclass
function Shape() {
  this.x = 0;
  this.y = 0;
}

//superclass method
Shape.prototype.move = function(x, y) {
    this.x += x;
    this.y += y;
    console.info("Shape moved.");
};

// Rectangle - subclass
function Rectangle() {
  Shape.call(this); //call super constructor.
}

//subclass extends superclass
Rectangle.prototype = Object.create(Shape.prototype);

Does classical inheritance use prototypal inheritance inside?

http://aaditmshah.github.io/why-prototypal-inheritance-matters/

From above link, I learned we can't add new methods at run time in classical inheritance. Is this correct? But you can check the above code I can add "move" method and any methods at run time through prototype. So this is prototype based classical inheritance? If so what is actual classical inheritance and prototype inheritance? I am confused about that.

Prototypal inheritance.

function Circle(radius) {
    this.radius = radius;
}
Circle.prototype.area = function () {
    var radius = this.radius;
    return Math.PI * radius * radius;
};
Circle.prototype.circumference: function () {
    return 2 * Math.PI * this.radius;
};
var circle = new Circle(5);
var circle2 = new Circle(10);

Is this similar to classical inheritance? I'm totally confused about what is prototypal inheritance? What is classical inheritance? Why is classical inheritance bad?

Can you give me a simple example for better understanding these in a simple manner.

Thanks,

Siva

Body:
Before jumping into inheritance, we will take a look at two primary models to create instances (objects) in javascript:

Classical model: Object is created from a blueprint (class)

class Person {
  fn() {...}
} // or constructor function say, function Person() {}

// create instance
let person = new Person();

Prototypal model: Object is created directly from another object.

// base object
let Person = { fn(){...} }

// instance
let person = Object.create(Person);

In either case, Inheritance* is achieved by linking objects using prototype object.

(*base class methods are accessible via. derived class through the prototype object and not required to be explicitly present in derived class.)

Here is a good explanation to understand better (http://www.objectplayground.com/)


问:
Howto add documentation to TYPO3 Extension
Is there a step by step manual how to add documentation to a TYPO3 extension?
I added two extensions to the repository but I would like to add some documentation, too. In earlier times of the TYPO3 repository this was quite easy - as far as I can remember a OpenOffice document had to be added to the extension...
I found this "howto"

I'm using macOS Sierra and I installed a lot of stuff: Xcode, MacPorts, Sphinx,...

I did all these pip installs

But calling make in the _make directory of the documentation directory of github.com/marble/typo3-docs-typo3-org-resources gives me the following

error:

sphinx-build -b html -d build/doctrees  -c . -a -E -w
  ./_not_versioned/warnings.txt .. build/html Running Sphinx v1.5.1

Exception occurred:   File "conf.py", line 24, in
      import t3SphinxThemeRtd ImportError: No module named t3SphinxThemeRtd

The full traceback has been saved in /tmp/sphinx-err-bGi8t6.log, if
  you want to report the issue to the developers. Please also report
  this if it was a user error, so that a better error message can be
  provided next time. A bug report can be filed in the tracker at
  https://github.com/sphinx-doc/sphinx/issues. Thanks!

So the module t3SphinxThemeRtd was not found although I added it with the pip command!?

Is there not an easy method to add a documentation? I think this complex procedure will stop many developers to add a documentation to their extensions!?

答:
Do not create an OpenOffice document. You do not need to install sphinx locally! (though no-one can stop you if you want to). You can use the supplied Docker image , which gives you a full working environment for rendering the documentation.

The official documentation for writing documentation for extensions has been updated:

How to Start Documentation for your TYPO3 Extension

What documents do you need?

Your extension should have a directory Documentation in it, which should contain the documentation as reStructuredText (.rst) documents (e.g. Index.rst). Markdown is also supported. Alternatively, you can have a one-file solution (e.g. only Readme.rst).

Directories and Filenames

For creating extension documentation there are several options:

There is an example extension manual. How to use this to start your documentation from scratch is already described in the link I gave above.

Or, start your ReST files from scratch

Or, use existing extensions for inspiration, e.g. ext:form

Or, use the extension builder (rename the Documentation.tmpl directory to Documentation).

How to edit the .rst files

You can just edit the files in a simple Text Editor or IDE (preferably use an IDE with reStructuredText support, e.g. for PhpStorm, use the reStructuredText plugin, for Visual Studio Code, use LeXtudio reStructuredText plugin).

Tip 1: Read the reStructuredText & Sphinx Introduction

Tip 2: Use the reST & Sphinx Cheat Sheet

Tip 3: Read Common Pitfalls to avoid errors

Rendering the ReST files

If you want to test how your reST files will look, you should render them locally.

For this you have several options, but the recommended method is to use Docker.


问:
How to do Alfresco Using Alfresco Web Service
i am working in a IT Company and i need to learn Alfresco. Using Apache CMIS i am able to all operations like Creating Folder, Creating Document, Creating Link of Folder and Document and blah blah.
Now I need to do all the operation using alfresco own web service.
I did google a lot but not able to get a single link over that.
Can any body suggest link or contents from where i can do all the operations using Alfresco own webservice. Document is good but i have less time and i cannot go through the whole document.
It will be helpful if i can get an example build on maven(java)

答:
If you are asking how to use Alfresco via a SOAP-based web service, that no longer exists.

If you are asking how to use Alfresco's native REST API, then you could start by looking at https://api-explorer.alfresco.com/api-explorer/.

If you need to write your own RESTful endpoints in Alfresco that you will then call remotely, you can read my tutorial on Web Scripts: http://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html.