问:
Create specific bean dependant on property
Lets say i have two beans:

class MyBean implements BeanInterface(){}

class MyBean2 implements BeanInterface(){}

And if specific property exists, i want to create MyBean, otherwise I want to create MyBean2(). How can i do this?

```<code>@Bean
@ConditionalOnProperty(name = "property.validation")
public BeanInterface beanInterface() {
    return new MyBean();
}
</code>```

works if I want to create MyBean if property exists, but how do I create MyBean2 if it doesn't?

```<code>@Bean
@ConditionalOnMissingBean(MyBean.class)
public BeanInterface beanInterface() {
    return new MyBean2();
}
</code>```

complains that method with same name exists, and if i understand it correctly, the methods name need to be camelCase name of the bean.

How do i do this?

Thanks

//edit i tried:

```<code>@Bean
@ConditionalOnProperty(name = "property.validation")
@Order(1)
public BeanInterface beanInterface() {
    return new MyBean();
}

@Bean("beanInterface")
@ConditionalOnMissingBean(MyBean.class)
@Order(2)
public BeanInterface beanInterface() {
    return new MyBean2();
}
</code>```

but it didnt work, second bean is not getting created when property is missing.

答:
You have Java configuration at your hands, so use that to your advantage. Not everything needs annotations to be fixed.

@Bean
public BeanInterface myBean(Environment env) {
    String validation = env.getProperty("property.validation", String.class);
    return validation != null ? new MyBean(validation) : new MyBean2();
}
```

The name of the method doesn't matter it can be anything you like.

Body:
Lets say i have two beans:

class MyBean implements BeanInterface(){}

class MyBean2 implements BeanInterface(){}

And if specific property exists, i want to create MyBean, otherwise I want to create MyBean2(). How can i do this?

@Bean
@ConditionalOnProperty(name = "property.validation")
public BeanInterface beanInterface() {
    return new MyBean();
}

works if I want to create MyBean if property exists, but how do I create MyBean2 if it doesn't?

@Bean
@ConditionalOnMissingBean(MyBean.class)
public BeanInterface beanInterface() {
    return new MyBean2();
}

complains that method with same name exists, and if i understand it correctly, the methods name need to be camelCase name of the bean.

How do i do this?

Thanks

//edit i tried:

@Bean
@ConditionalOnProperty(name = "property.validation")
@Order(1)
public BeanInterface beanInterface() {
    return new MyBean();
}

@Bean("beanInterface")
@ConditionalOnMissingBean(MyBean.class)
@Order(2)
public BeanInterface beanInterface() {
    return new MyBean2();
}

but it didnt work, second bean is not getting created when property is missing.

Body:
You have Java configuration at your hands, so use that to your advantage. Not everything needs annotations to be fixed.

@Bean
public BeanInterface myBean(Environment env) {
    String validation = env.getProperty("property.validation", String.class);
    return validation != null ? new MyBean(validation) : new MyBean2();
}

The name of the method doesn't matter it can be anything you like.


来源: stackexchange

问:
Optional parameters, "index seek" plan
In my SELECT statement i use optional parameters in a way like this:

```<code>DECLARE @p1 INT = 1
DECLARE @p2 INT = 1
SELECT name FROM some_table WHERE (id = @p1 OR @p1 IS NULL) AND (name = @p2 OR @p2 IS NULL)
</code>```

In this case the optimizer generates "index scan" (not seek) operations for the entity which is not most effective when parameters are supplied with not null values.

If i add the RECOMPILE hint to the query the optimizer builds more effective plan which uses "seek". It works on my MSSQL 2008 R2 SP1 server and it also means that the optimizer CAN build a plan which consider only one logic branch of my query.

How can i make it to use that plan everywhere i want with no recompiling? The USE PLAN hint seemes not to work in this case.

Below is test code:

```<code>-- see plans
CREATE TABLE test_table(
    id INT IDENTITY(1,1) NOT NULL,
    name varchar(10),
    CONSTRAINT [pk_test_table] PRIMARY KEY CLUSTERED (id ASC))
GO
INSERT INTO test_table(name) VALUES ('a'),('b'),('c')
GO
DECLARE @p INT = 1
SELECT name FROM test_table WHERE id = @p OR @p IS NULL
SELECT name FROM test_table WHERE id = @p OR @p IS NULL OPTION(RECOMPILE)
GO
DROP TABLE test_table
GO
</code>```

Note that not all versions of SQL server will change the plan the way i shown.

答:
Look at this article http://www.bigresource.com/Tracker/Track-ms_sql-fTP7dh01/
It seems that you can try to use proposal solution:

```<code>`SELECT * FROM <table> WHERE IsNull(column, -1) = IsNull(@value, -1)`
</code>```

or

```<code>`SELECT * FROM <table> WHERE COALESCE(column, -1) = COALESCE(@value, -1)`
</code>```

ContentLicense: CC BY-SA 3.0

Title: Optional parameters, "index seek" plan

Body:
In my SELECT statement i use optional parameters in a way like this:

DECLARE @p1 INT = 1
DECLARE @p2 INT = 1
SELECT name FROM some_table WHERE (id = @p1 OR @p1 IS NULL) AND (name = @p2 OR @p2 IS NULL)

In this case the optimizer generates "index scan" (not seek) operations for the entity which is not most effective when parameters are supplied with not null values.

If i add the RECOMPILE hint to the query the optimizer builds more effective plan which uses "seek". It works on my MSSQL 2008 R2 SP1 server and it also means that the optimizer CAN build a plan which consider only one logic branch of my query.

How can i make it to use that plan everywhere i want with no recompiling? The USE PLAN hint seemes not to work in this case.

Below is test code:

-- see plans
CREATE TABLE test_table(
    id INT IDENTITY(1,1) NOT NULL,
    name varchar(10),
    CONSTRAINT [pk_test_table] PRIMARY KEY CLUSTERED (id ASC))
GO
INSERT INTO test_table(name) VALUES ('a'),('b'),('c')
GO
DECLARE @p INT = 1
SELECT name FROM test_table WHERE id = @p OR @p IS NULL
SELECT name FROM test_table WHERE id = @p OR @p IS NULL OPTION(RECOMPILE)
GO
DROP TABLE test_table
GO

Note that not all versions of SQL server will change the plan the way i shown.

Body:
Look at this article http://www.bigresource.com/Tracker/Track-ms_sql-fTP7dh01/
It seems that you can try to use proposal solution:

`SELECT * FROM <table> WHERE IsNull(column, -1) = IsNull(@value, -1)`

or

`SELECT * FROM <table> WHERE COALESCE(column, -1) = COALESCE(@value, -1)`


问:
How can I make JavaScript code more "clean"
I have made this functions

```<code>
let buttonOne = true;
    let buttonTwo = false;
    let buttonThree = false;
    let buttonFour = false;
    let buttonFive = false;

    const handleButtonOne = () => {
        buttonOne = true;
        buttonTwo = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonTwo = () => {
        buttonTwo = true;
        buttonOne = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonThree = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = true;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonFour = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = false;
        buttonFour = true;
        buttonFive = false;
    };

    const handleButtonFive = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = true;
    };

</code>```

This functions are to change the state of the different buttons and show different content to the user when the state of button is true. This works well, however, I thinks it's not the right way to do it.

My question is. How can I do the same with less code and more elegant way? Any tips?

答:
You only have 1 item to be true, then it will be easier you put it in paremeter of the function

let num = ["One", "Two", "Three", "Four", "Five"]

function create(trueindex) {
  for (let i in num) {
    if (i == num[trueindex]) {
      window[`button${num[i]}`] = true
    } else {
      window[`button${num[i]}`] = false
    }
  }
}
create(1)
console.log(buttonOne)```

ContentLicense: CC BY-SA 4.0

Body:
I have made this functions

let buttonOne = true;
    let buttonTwo = false;
    let buttonThree = false;
    let buttonFour = false;
    let buttonFive = false;

    const handleButtonOne = () => {
        buttonOne = true;
        buttonTwo = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonTwo = () => {
        buttonTwo = true;
        buttonOne = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonThree = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = true;
        buttonFour = false;
        buttonFive = false;
    };

    const handleButtonFour = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = false;
        buttonFour = true;
        buttonFive = false;
    };

    const handleButtonFive = () => {
        buttonTwo = false;
        buttonOne = false;
        buttonThree = false;
        buttonFour = false;
        buttonFive = true;
    };

This functions are to change the state of the different buttons and show different content to the user when the state of button is true. This works well, however, I thinks it's not the right way to do it.

My question is. How can I do the same with less code and more elegant way? Any tips?


问:
How to Align a Select Element and Button Element
I am trying to align the select element and the button, but could not succeed. I tried the following code:

echo "

```<code>         <select class='form-select form-select-sm' id='tstatus' name='tstatus'>
         <option selected value='$status'>Status</option>
         <option value='Booked'>Booked</option>
         <option value='Ontrip'>On Trip</option>
         <option value='Cancelled'>Cancelled</option>

         </select>
         <input type='hidden' class='form-control' id='tid' name='tid' value='$id'>
         <input class='btn btn-primary' type='submit'  name='thestatus' id='thestatus'  value='Go'>

         </form>
         </td>";

          </td>";
</code>```

答:
Since you are using bootstrap, you can wrap the select and the button in a div with a class of input-group. Try this

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    <select class="form-select form-select-sm" id="tstatus" name="tstatus">
         <option selected value="$status">Status</option>
         <option value="Booked">Booked</option>
         <option value="Ontrip">On Trip</option>
         <option value="Cancelled">Cancelled</option>
    </select>
    <input type="hidden" class="form-control" id="tid" name="tid" value="$id"> <input class="btn btn-primary" type="submit"  name="thestatus" id="thestatus"  value="Go">

```

Body:
I am trying to align the select element and the button, but could not succeed. I tried the following code:

echo "

         <select class='form-select form-select-sm' id='tstatus' name='tstatus'>
         <option selected value='$status'>Status</option>
         <option value='Booked'>Booked</option>
         <option value='Ontrip'>On Trip</option>
         <option value='Cancelled'>Cancelled</option>

         </select>
         <input type='hidden' class='form-control' id='tid' name='tid' value='$id'>
         <input class='btn btn-primary' type='submit'  name='thestatus' id='thestatus'  value='Go'>

         </form>
         	";

          	";

Body:
Since you are using bootstrap, you can wrap the select and the button in a div with a class of input-group. Try this

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="input-group">
    <select class="form-select form-select-sm" id="tstatus" name="tstatus">
         <option selected value="$status">Status</option>
         <option value="Booked">Booked</option>
         <option value="Ontrip">On Trip</option>
         <option value="Cancelled">Cancelled</option>
    </select>
    <input type="hidden" class="form-control" id="tid" name="tid" value="$id"> <input class="btn btn-primary" type="submit"  name="thestatus" id="thestatus"  value="Go">
</div>


问:
Uncaught SyntaxErrror: Unexpected token ILLEGAL in chrome
I'm having a problem within the jQuery ajax function. The following code works fine in Mozilla but doesn't work in IE or Chrome, when I try to identify the problem using Developer Tools in chrome I get the error:

```<code>Uncaught SyntaxError: Unexpected token ILLEGAL \n
$.ajax.success
</code>```

and when I click on it it directs me to the var obj = JSON.parse(data); line.

```<code>function getdata(){
    $.ajax({
        type:"GET",
        url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
        data: "",
        success: function(data) {
            var obj = JSON.parse(data);
            displayPlaylists(obj);
        }

    });
}
</code>```

EDIT:
Ive found a solution that works in chrome but still not in IE

```<code>function getdata(){
        $.ajax({
                type:"GET",
                url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
                dataType:"json",
                success: function(data) {
                    displayPlaylists(data);
                }

            });
    }
</code>```

the addition of dataType:"json" means that the function expects json data to be returned and therefore parses it on arrival (it is equivalent to using jQuery.parseJSON), however as i said this solution still doesn't work in IE

答:
Quite ironically, I have had that same problem in Chrome during the last week, but I suspect that it's not only with Chrome but with any browser.

Using Chrome Javascript Debugger, place a breakpoint on the like where you fill the var 'obj' and check if 'data' has more than one object contained inside the array. In case it does, you're probably trying to access the object that is inside the first index position of your data object.

If you sent an anonymous json object from the server to the page, access the first index, instead of data directly.

Like so:

```<code>function getdata(){
        $.ajax({
                type:"GET",
                url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
                data: "",
                success: function(data) {
                    var obj = data.data.items;
                    displayPlaylists(obj);
                }

            });
    }
</code>```

EDIT:

I debugged your link myself and after testing it further, I found that you don't even need to parse this object, really.
Look at my example above, pass data.data.items to your var obj and it will be loaded with all your objects from within the array.

See if that helps.

Body:
I'm having a problem within the jQuery ajax function. The following code works fine in Mozilla but doesn't work in IE or Chrome, when I try to identify the problem using Developer Tools in chrome I get the error:

Uncaught SyntaxError: Unexpected token ILLEGAL \n
$.ajax.success

and when I click on it it directs me to the var obj = JSON.parse(data); line.

function getdata(){
    $.ajax({
        type:"GET",
        url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
        data: "",
        success: function(data) {
            var obj = JSON.parse(data);
            displayPlaylists(obj);
        }

    });
}

EDIT:
Ive found a solution that works in chrome but still not in IE

function getdata(){
        $.ajax({
                type:"GET",
                url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
                dataType:"json",
                success: function(data) {
                    displayPlaylists(data);
                }

            });
    }

the addition of dataType:"json" means that the function expects json data to be returned and therefore parses it on arrival (it is equivalent to using jQuery.parseJSON), however as i said this solution still doesn't work in IE

Body:
Quite ironically, I have had that same problem in Chrome during the last week, but I suspect that it's not only with Chrome but with any browser.

Using Chrome Javascript Debugger, place a breakpoint on the like where you fill the var 'obj' and check if 'data' has more than one object contained inside the array. In case it does, you're probably trying to access the object that is inside the first index position of your data object.

If you sent an anonymous json object from the server to the page, access the first index, instead of data directly.

Like so:

function getdata(){
        $.ajax({
                type:"GET",
                url: "https://gdata.youtube.com/feeds/api/users/TheSyndicateProject/playlists?v=2&alt=jsonc",
                data: "",
                success: function(data) {
                    var obj = data.data.items;
                    displayPlaylists(obj);
                }

            });
    }

EDIT:

I debugged your link myself and after testing it further, I found that you don't even need to parse this object, really.
Look at my example above, pass data.data.items to your var obj and it will be loaded with all your objects from within the array.

See if that helps.


问:
Redirect from a Python AWS Lambda with AWS Gateway API Proxy
Posting here because I just can't get a redirect working. Using AWS API Gateway linked to a Python Lambda function as a proxy just returns the response and header json. Here is the code

```<code>import json

def lambda_handler(event, context):
    response = {}
    response["statusCode"]=301
    response["headers"]=[{"key": 'Location',"value":
     'https://www.google.com'}]
    data = {}
    response["body"]=json.dumps(data)
return response
</code>```

Any help will be appreciated?

Thanks

答:
a bit less line, with the same output</p>
```<code>def handler(event, context):
    response = {
        "headers": {"Location": "https://www.google.com", },
        "statusCode": 301,
    }

    return response
</code>```

Body:
Posting here because I just can't get a redirect working. Using AWS API Gateway linked to a Python Lambda function as a proxy just returns the response and header json. Here is the code

import json

def lambda_handler(event, context):
    response = {}
    response["statusCode"]=301
    response["headers"]=[{"key": 'Location',"value":
     'https://www.google.com'}]
    data = {}
    response["body"]=json.dumps(data)
return response

Any help will be appreciated?

Thanks

Body:
a bit less line, with the same output

def handler(event, context):
    response = {
        "headers": {"Location": "https://www.google.com", },
        "statusCode": 301,
    }

    return response


问:
BLAT Does Not Accept my %BODY% argument
Trying to understand how to send the BODY variable correctly?

I receive the following from using BLAT in my batch file:

```<code>SET BODY="exit error code from NET USE = %ERRORLEVEL%. Please contact the Business Systems Technical Team On Call Person"
</code>```

Here's the use of BLAT:

```<code>"C:\Program Files\BLAT\blat.exe" -To myemail@domain.org -Subject "RAD File Transfer Error" -Body %BODY%
</code>```

Blat v3.2.19 (build : Nov 18 2017 03:15:08) 64-bit Windows, Full, Unicode

Blat saw and processed these options, and found fault with the last
  one...

-To myemail@domain.org

     -Subject RAD File Transfer Error

     -Body Not enough arguments supplied for option: -Body Blat found fault with: -body

-body     : message body, surround with quotes (") to include spaces

Here's where the SET BODY is:

```<code>copy /Y "C:\channels\filetransfer_process\*" "D:\MSCMRADbackups1\"
echo %ERRORLEVEL%
    IF %ERRORLEVEL% NEQ 0 (
    IF %ERRORLEVEL% NEQ 1 (
    echo Setting BODY1 at: %date% %time%
    SET BODY="exit error code from Backup of RAD file = %ERRORLEVEL%."
    goto :mailerror
    )
 ) ELSE (
 EXIT
 )
</code>```

答:
Another belated answer here, but posting it anyway in the hope it will help someone.

The -Body option expects one -- and only one -- argument.  The fact that you get the following error:
"-Body Not enough arguments supplied for option: " means that you did not supply an option, which means that %BODY% was null when you passed it to Blat.

You're depending upon BODY being set within nested IF statements.  I'd suggest you try using the following line before the outer IF block:

```<code>SETLOCAL ENABLEDELAYEDEXPANSION
</code>```

After you've SET BODY, access the delayed expansion value by using bangs (exclamation marks) instead of percent signs.  So, in your blat command, use:

```<code>blat ... -Body !BODY!
</code>```

(Quotation marks not needed here if they were supplied in the SET command.)

Look for help on SETLOCAL ENABLEDELAYEDEXPANSION (and ENDLOCAL, which is not always necessary) elsewhere.  Much has already been written about it.

Title: BLAT Does Not Accept my %BODY% argument

Body:
Trying to understand how to send the BODY variable correctly?

I receive the following from using BLAT in my batch file:

SET BODY="exit error code from NET USE = %ERRORLEVEL%. Please contact the Business Systems Technical Team On Call Person"

Here's the use of BLAT:

"C:\Program Files\BLAT\blat.exe" -To myemail@domain.org -Subject "RAD File Transfer Error" -Body %BODY%

Blat v3.2.19 (build : Nov 18 2017 03:15:08) 64-bit Windows, Full, Unicode

Blat saw and processed these options, and found fault with the last
  one...

-To myemail@domain.org

     -Subject RAD File Transfer Error

     -Body Not enough arguments supplied for option: -Body Blat found fault with: -body

-body     : message body, surround with quotes (") to include spaces

Here's where the SET BODY is:

copy /Y "C:\channels\filetransfer_process\*" "D:\MSCMRADbackups1\"
echo %ERRORLEVEL%
    IF %ERRORLEVEL% NEQ 0 (
    IF %ERRORLEVEL% NEQ 1 (
    echo Setting BODY1 at: %date% %time%
    SET BODY="exit error code from Backup of RAD file = %ERRORLEVEL%."
    goto :mailerror
    )
 ) ELSE (
 EXIT
 )

Body:
Another belated answer here, but posting it anyway in the hope it will help someone.

The -Body option expects one -- and only one -- argument.  The fact that you get the following error:
"-Body Not enough arguments supplied for option: " means that you did not supply an option, which means that %BODY% was null when you passed it to Blat.

You're depending upon BODY being set within nested IF statements.  I'd suggest you try using the following line before the outer IF block:

SETLOCAL ENABLEDELAYEDEXPANSION

After you've SET BODY, access the delayed expansion value by using bangs (exclamation marks) instead of percent signs.  So, in your blat command, use:

blat ... -Body !BODY!

(Quotation marks not needed here if they were supplied in the SET command.)

Look for help on SETLOCAL ENABLEDELAYEDEXPANSION (and ENDLOCAL, which is not always necessary) elsewhere.  Much has already been written about it.


问:
Ruby On Rails - NoMethodError: undefined method `[]' for nil:NilClass
I'm trying to run on a new computer some ruby code and I receive the following error (rails db:migrate --trace)

```<code>** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
rails aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Users/jairochavez/Documents/Rails/rfdf_bolivia/config/initializers/stripe.rb:2:in `<main>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:657:in `block in load_config_initializer'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:170:in `instrument'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:656:in `load_config_initializer'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `block in <class:Engine>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `tsort_each_child'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/config/environment.rb:5:in `<main>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:238:in `block in invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:238:in `block in invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:160:in `invoke_task'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/bin/rails:9:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
</code>```

config/initializers/stripe.rb

```<code>Rails.configuration.stripe = {
  publishable_key: Rails.application.credentials[Rails.env.to_sym][:stripe][:public_key],
  secret_key:      Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_key]
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
</code>```

答: When cloning an existing repo, you might run into this error if you do not have a config/master.key file, (which is not checked in to source control, e.g. GitHub). This is because, as @Elias Glyptis pointed out, credentials are needed to compile assets, (as documented in Rails #32947).

Body:
I'm trying to run on a new computer some ruby code and I receive the following error (rails db:migrate --trace)

** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
rails aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Users/jairochavez/Documents/Rails/rfdf_bolivia/config/initializers/stripe.rb:2:in `'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:657:in `block in load_config_initializer'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:170:in `instrument'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:656:in `load_config_initializer'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `block in <class:Engine>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `tsort_each_child'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/config/environment.rb:5:in `'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:238:in `block in invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:238:in `block in invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:236:in `invoke_prerequisites'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:160:in `invoke_task'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/bin/rails:9:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jairochavez/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jairochavez/Documents/Rails/rfdf_bolivia/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `'
Tasks: TOP => db:migrate => db:load_config => environment

config/initializers/stripe.rb

Rails.configuration.stripe = {
  publishable_key: Rails.application.credentials[Rails.env.to_sym][:stripe][:public_key],
  secret_key:      Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_key]
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]


问:
Raster operations in DotSpatial
Searching for advice: We are rewriting (in c#) the graphical user interface for the Watershed Risk Analysis Management Framework model, and are using the DotSpatial libraries for our map operations. We need to perform some simple tabulations on raster data, and I'm having trouble finding examples. We need to calculate land use (using national land cover dataset) percentages within polygons, calculate average slope and aspect within polygons. Pretty standard stuff for hydrologic analysis. Does anyone know of tutorials or available code sources for DotSpatial raster analysis? Thanks for your time.</p>

答:
did you find a way to do it? I am in the same position. For the moment, my current workaround is this. I have converted my raster into a List<GeoAPI.Geometries.IPoint> listPts using the center coordinates of the pixels, with the Z value as the corresponding raster pixel value. Then, with my PolygonShapefile, I loop over each feature, and use the feature.Geometry.Covers(listPts[i]) methode to build a list of the points failing in each polygons. After that, I simply cross the two lists together to calculates the corresponding statistics that I need.

I would like a better suggestion, but for the moment, it fits my needs.

Title: Raster operations in DotSpatial


问:
How to filter in OData for a specific value inside
In our Cosmos database, we have an attribute for a document that is an array of objects. The objects in this array have two attributes, Key and Value. So it's "a bit like" a IDictionary<string, string>.

Here is some example data:

```<code>{
  // other attributes
  // .....
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    },
    {
      "Key": "level2",
      "Value": "UNITED KINGDOM"
    }
  ]
}
</code>```

However, there are also objects in the database where level2, for example, does not exist, resulting in JSON like this:

```<code>{
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    }
  ]
}
</code>```

A user is able to select level2 filters through the UI so the application makes sure they are included. The user can also select filters and mark them as excluded, i.e. that he wants every result where a specific country is not present.

At first I created the following query in order to get all for a specific country:

```<code>&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Evil Corporation') and (Tags/Any (c:c/Key eq 'level2' and c/Value eq 'UNITED KINGDOM')
</code>```

I am having trouble with the query where I select every item where a specific country does not exist. I tried:

```<code>&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Nestlé') and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')
</code>```

This now returns every item where level2 is not UNITED KINGDOM, however if a document does not have level2 configured at all, such as when there is no object with key=level2 in the document, then it's not returned.

So, basically, I need this query:

```<code>(Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')` and combine it somehow with `OR Tags/Any (c:c/Key {IS NOT PRESENT}
</code>```

and this is where I am stuck.

I don't know how to write this into ODATA. When I searched Google for a non-existent column and ODATA it only returns results for people having issues with ODATA not returning a specific column, but that's exactly what I want to do.

I tried to write this query:

```<code>and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM') or Tags/All (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM'))
</code>```

which I got from https://stackoverflow.com/a/57405406/2823419

but it returns an error that it can't parse the query.

What function do I need to use?

答:
Depending on your implementation, the OData specification has a Logical Negation operator: not(), it's usage is not explicitly documented in the spec but it is listed in 5.1.1.14 Operator Precedence

The usage of this would be to wrap the expression that you want to negate inside a not() function:

&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Nestlé') and not((Tags/Any (c:c/Key eq 'level2' and c/Value eq 'UNITED KINGDOM'))

or if you simply wanted to exclude all records if any key had a value of 'UNITED KINGDOM' then you could more simply use this:

&$filter=not(Tags/Any (t:t/Value eq 'UNITED KINGDOM'))

NOTE:

not(any()) should produce the same results as all(field ne value) but an all() lambda requires evaluation of every single record, whereas any() we break out of evaluation at the first match. not(any()) should always produce the most efficient result, it is also more resilient to missing properties.

Body:
In our Cosmos database, we have an attribute for a document that is an array of objects. The objects in this array have two attributes, Key and Value. So it's "a bit like" a IDictionary<string, string>.

Here is some example data:

{
  // other attributes
  // .....
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    },
    {
      "Key": "level2",
      "Value": "UNITED KINGDOM"
    }
  ]
}

However, there are also objects in the database where level2, for example, does not exist, resulting in JSON like this:

{
  "Tags": [
    {
      "Key": "client",
      "Value": "Evil Corporation"
    },
    {
      "Key": "level1",
      "Value": "EUROPE"
    }
  ]
}

A user is able to select level2 filters through the UI so the application makes sure they are included. The user can also select filters and mark them as excluded, i.e. that he wants every result where a specific country is not present.

At first I created the following query in order to get all for a specific country:

&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Evil Corporation') and (Tags/Any (c:c/Key eq 'level2' and c/Value eq 'UNITED KINGDOM')

I am having trouble with the query where I select every item where a specific country does not exist. I tried:

&$filter=Tags/Any (c:c/Key eq 'client' and c/Value eq 'Nestlé') and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')

This now returns every item where level2 is not UNITED KINGDOM, however if a document does not have level2 configured at all, such as when there is no object with key=level2 in the document, then it's not returned.

So, basically, I need this query:

(Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM')` and combine it somehow with `OR Tags/Any (c:c/Key {IS NOT PRESENT}

and this is where I am stuck.

I don't know how to write this into ODATA. When I searched Google for a non-existent column and ODATA it only returns results for people having issues with ODATA not returning a specific column, but that's exactly what I want to do.

I tried to write this query:

and (Tags/Any (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM') or Tags/All (c:c/Key eq 'level2' and c/Value ne 'UNITED KINGDOM'))

which I got from https://stackoverflow.com/a/57405406/2823419

but it returns an error that it can't parse the query.

What function do I need to use?


问:
set value to state in React
I am new to React, and I have a question of set state, this is the code:

```<code>this.setState((prevState) => {
                return{
                    prevVal: prevState.currentVal,
                    currentVal: 'DIGIT LIMIT MET'
                }
});
</code>```

In this code, the prevVal in my project will be updated to 'DIGIT LIMIT MET', but I want it to be the last currentVal which is prevState.currentVal.

```<code>this.setState({
                    prevVal: this.state.currentVal,
                    currentVal: 'DIGIT LIMIT MET'

});
</code>```

In this code , the problem will not appear, but according to React document, it can not make sure that the this.state.currentVal is the prevState.currentVal.

How to solve this problem perfectly? Am I misunderstanding something?

答:
```<code> this.setState(
      prevState => {
        const prev = prevState.currentVal;
        return {
          prevVal: prev,
          currentVal: 'DIGIT LIMIT MET'
        };
      },
      () => console.log(this.state)
    );
</code>```

try this.

Title: set value to state in React

Body:
I am new to React, and I have a question of set state, this is the code:

this.setState((prevState) => {
                return{
                    prevVal: prevState.currentVal,
                    currentVal: 'DIGIT LIMIT MET'
                }
});

In this code, the prevVal in my project will be updated to 'DIGIT LIMIT MET', but I want it to be the last currentVal which is prevState.currentVal.

this.setState({
                    prevVal: this.state.currentVal,
                    currentVal: 'DIGIT LIMIT MET'

});

In this code , the problem will not appear, but according to React document, it can not make sure that the this.state.currentVal is the prevState.currentVal.

How to solve this problem perfectly? Am I misunderstanding something?

Body:
 this.setState(
      prevState => {
        const prev = prevState.currentVal;
        return {
          prevVal: prev,
          currentVal: 'DIGIT LIMIT MET'
        };
      },
      () => console.log(this.state)
    );

try this.


问:
How to call CUDA functions outside main()?
I'm very new to CUDA programming and have NOT had a hard time setting it all up. I'm using the driver API, i've modified the compilation workflow and all of my learning kernels and host programs work great. I'm learning directly from the cuda source samples as the SDK rely mostly on them. Everything is just perfect.

But i'm trying to extend my programs from the classic console example to a GUI and i am having a hard time calling any cuda function outside the classic main() function. I'm under Win32 and any call outside main() results in an "access violation", calling kernels or device query functions inside main() works ok, the gui program works ok too. This happends with all the API calls including cuInit(), so, making contexts current, pushing and popping contexts are not posible. If you take a look at the SDK examples, all of them are coded within main().

Does anyone have a clue about this issue? Does this happends to you as well? How to fix it?

Thank you very much for your comments in advance.

INFO:

CUDA SDK version: 4.0

Device: GeForce GTS 450 (GF106), Device Capability 2.1

Win32 platform (Win7 x64 with WOW64).

CUDA Driver API

Host program made with the D programming language.

答: There are thousands of programs that use CUDA entirely outside main, the problem is more likely to be that your program is written in D and not C/C++. That's not to say it can't work (I've never used D) but you will need to remember that you are calling into a C API and that C is unmanaged.</p>


问:
How to show current URL inside embed
<embed src="snippet.html"> - I need to insert the custom url(othersite.com/directory/something/) + "search part" of the current URL inside src attribute. I get that something like "console.log(window.location.search)" can help, but how could I connect/insert that to be inside src?

In short, my embed code output should looks like: <embed src="othersite.com/directory/something/astalavista"> , when the current URL looks like this mysite.com/info/astalavista

How should my HTML code look like?

I use Wordpress. Need HTML code. Thanks.

答:
If you want to do it right in-place in your HTML, maybe not the best JS ever, but you can go:</p>
```<code>some of your html...
<script>
  let myUrl = "whatever"; // or echo some php variable here?
  window.write(`<embed src="snippet.html/${myUrl}">`);
</script>
carry on with your html...
</code>```

Title: How to show current URL inside embed

Body:
If you want to do it right in-place in your HTML, maybe not the best JS ever, but you can go:

some of your html...
<script>
  let myUrl = "whatever"; // or echo some php variable here?
  window.write(`<embed src="snippet.html/${myUrl}">`);
</script>
carry on with your html...


问:
How do I delete all messages in a discord channel with js?
Using discord.py in python, I can do the following and it'll slowly delete all messages in a channel even if they're more than 2 weeks old:

async def clear(self, ctx):

    length = await ctx.message.channel.history(limit=999).flatten()
    num = len(length)
    div = 100
    target = [num // div(1 if x < num % div else 0) for x in range(div)]

    for tar in target:
        async for message in ctx.message.channel.history(limit=tar):
            await ctx.message.channel.delete_messages([message])
```

How would I go about doing the same thing in javascript discord.js?

答:
This is the common function for it, however bulkDelete does have 2 week limitation and 100 message limit.

```<code>async function clearChat (msg, numb) {
    const channel = msg.channel;
    const messageManager = channel.messages;
    const messages = await messageManager.channel.messages.fetch({ limit: numb });
    channel.bulkDelete(messages,true);

}
</code>```

To call it just:

```<code>clearChat(msg, 100);
</code>```

In your code

Body:
Using discord.py in python, I can do the following and it'll slowly delete all messages in a channel even if they're more than 2 weeks old:

async def clear(self, ctx):

    length = await ctx.message.channel.history(limit=999).flatten()
    num = len(length)
    div = 100
    target = [num // div(1 if x < num % div else 0) for x in range(div)]

    for tar in target:
        async for message in ctx.message.channel.history(limit=tar):
            await ctx.message.channel.delete_messages([message])

How would I go about doing the same thing in javascript discord.js?

Body:
This is the common function for it, however bulkDelete does have 2 week limitation and 100 message limit.

async function clearChat (msg, numb) {
    const channel = msg.channel;
    const messageManager = channel.messages;
    const messages = await messageManager.channel.messages.fetch({ limit: numb });
    channel.bulkDelete(messages,true);

}

To call it just:

clearChat(msg, 100);

In your code


问:
Left-align image and center text on UIButton
I've seen posts regarding right alignment but I can't get left-alignment to work.  I want the button to take up the width of the screen, with the image on the left and the title/text in the center.

This does not work (at least reliably):

```<code>    button.titleLabel.textAlignment = UITextAlignmentCenter;
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, -60.0, 0, 0)];
    button.frame = CGRectMake((self.view.frame.size.width - w ) / 2, self.view.frame.size.height - 140.0,  self.view.frame.size.width - 10.0, 40.0);
</code>```

答:
@trishcode answer worked for me. I am just using it with an extension of the UIButton.

Here is the code:

```<code>extension UIButton {
func centerImageLeft(padding: CGFloat = 30.0){
    let buttonWidth = self.frame.width
    let textWidth = self.titleLabel?.intrinsicContentSize.width ?? 0
    let imageViewWidth = self.imageView?.frame.size.width ?? 0
    let offsetToLeftButtonEdge = buttonWidth - textWidth - imageViewWidth
    let offset = offsetToLeftButtonEdge - padding
    self.imageEdgeInsets = UIEdgeInsets(top: 0.0, left: 0, bottom: 0.0, right: offset)
}
}
</code>```

You can then call it like this in the viewDidAppear Method:

```<code>button.centerImageLeft()
</code>```

Body:
I've seen posts regarding right alignment but I can't get left-alignment to work.  I want the button to take up the width of the screen, with the image on the left and the title/text in the center.

This does not work (at least reliably):

    button.titleLabel.textAlignment = UITextAlignmentCenter;
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, -60.0, 0, 0)];
    button.frame = CGRectMake((self.view.frame.size.width - w ) / 2, self.view.frame.size.height - 140.0,  self.view.frame.size.width - 10.0, 40.0);

Body:
@trishcode answer worked for me. I am just using it with an extension of the UIButton.

Here is the code:

extension UIButton {
func centerImageLeft(padding: CGFloat = 30.0){
    let buttonWidth = self.frame.width
    let textWidth = self.titleLabel?.intrinsicContentSize.width ?? 0
    let imageViewWidth = self.imageView?.frame.size.width ?? 0
    let offsetToLeftButtonEdge = buttonWidth - textWidth - imageViewWidth
    let offset = offsetToLeftButtonEdge - padding
    self.imageEdgeInsets = UIEdgeInsets(top: 0.0, left: 0, bottom: 0.0, right: offset)
}
}

You can then call it like this in the viewDidAppear Method:

button.centerImageLeft()


问:
java.lang.NoClassDefFoundError with REST-assured 3.0.0 and Java 11 (not observed with Java 8)
Here's what my build.gradle file looks like:

```<code>plugins {
    id 'java'
    id "com.github.lkishalmi.gatling" version "0.7.0"
    id 'application'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.0'
}

task runTests(type: Test) {
    useTestNG() {
        useDefaultListeners = true
        suites 'src/test/testng.xml'
    }
}
</code>```

Here's what my testng.xml looks like:

```<code><!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="my-test-suite">
    <test name="myTest">
        <classes>
            <class name="tests.SomeTests">
                <methods>
                    <include name="testVerifySomething"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>
</code>```

The java.lang.NoClassDefFoundError error originates from the SomeTests class at the line where there is a call to a static method from another class SomeUtils from another package utils.

Here's the full trace:

```<code>java.lang.NoClassDefFoundError: javax.xml.bind.JAXBException
    at io.restassured.config.ObjectMapperConfig.<init>(ObjectMapperConfig.java:49)
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at utils.SomeUtils.createUser(SomeUtils.java:13)
    at tests.SomeTests.createUser(SomeTests.java:63)
    at tests.SomeTests.testCreateUsers(SomeTests.java:47)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:139)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:89)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:131)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.base/java.lang.Thread.run(Thread.java:825)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:768)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1052)
    ... 56 more
</code>```

The directory structure looks like this:

```<code>build.gradle
src
--test
----java
------tests
        SomeTests
------utils
        SomeUtils
</code>```

What I've tried so far:

Add runtime files('src/test/java/utils') inside the dependencies section of my build.gradle.

Add compile files('src/test/java/utils') inside the dependencies section of my build.gradle.

Add both 1 & 2 inside the dependencies section of my build.gradle.

EDIT: After some trial and errors, it seems the Java version is the cause here since the issue is seen with Java 11 and not with Java 8. I verified this behaviour on multiple machines just to ensure there's nothing specific on my machine.

答:
It is because the JAXB library (Java Architecture for XML Binding) is missing in the classpath. JAXB is included in Java SE 10 or older, but it is removed from Java SE from Java 11 or newer –moved to Java EE under Jakarta EE project.
That means if you encounter JAXBException error, it’s very much likely that you are using Java 11 or newer for your project. So to fix this error, you have to options:

Use older Java versions like JDK 8, 9, or 10 which still include the JAXB library by default. Or:

Specify an additional dependency in your project’s pom.xml file as follows:

```<code>    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

</code>```

In case you don’t use Maven
https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.3.0

Body:
Here's what my build.gradle file looks like:

plugins {
    id 'java'
    id "com.github.lkishalmi.gatling" version "0.7.0"
    id 'application'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.0'
}

task runTests(type: Test) {
    useTestNG() {
        useDefaultListeners = true
        suites 'src/test/testng.xml'
    }
}

Here's what my testng.xml looks like:

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="my-test-suite">
    <test name="myTest">
        <classes>
            <class name="tests.SomeTests">
                <methods>
                    <include name="testVerifySomething"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

The java.lang.NoClassDefFoundError error originates from the SomeTests class at the line where there is a call to a static method from another class SomeUtils from another package utils.

Here's the full trace:

java.lang.NoClassDefFoundError: javax.xml.bind.JAXBException
    at io.restassured.config.ObjectMapperConfig.<init>(ObjectMapperConfig.java:49)
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at utils.SomeUtils.createUser(SomeUtils.java:13)
    at tests.SomeTests.createUser(SomeTests.java:63)
    at tests.SomeTests.testCreateUsers(SomeTests.java:47)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:139)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:89)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:131)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.base/java.lang.Thread.run(Thread.java:825)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:768)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1052)
    ... 56 more

The directory structure looks like this:

build.gradle
src
--test
----java
------tests
        SomeTests
------utils
        SomeUtils

What I've tried so far:

Add runtime files('src/test/java/utils') inside the dependencies section of my build.gradle.

Add compile files('src/test/java/utils') inside the dependencies section of my build.gradle.

Add both 1 & 2 inside the dependencies section of my build.gradle.

EDIT: After some trial and errors, it seems the Java version is the cause here since the issue is seen with Java 11 and not with Java 8. I verified this behaviour on multiple machines just to ensure there's nothing specific on my machine.

Body:
It is because the JAXB library (Java Architecture for XML Binding) is missing in the classpath. JAXB is included in Java SE 10 or older, but it is removed from Java SE from Java 11 or newer –moved to Java EE under Jakarta EE project.
That means if you encounter JAXBException error, it’s very much likely that you are using Java 11 or newer for your project. So to fix this error, you have to options:

Use older Java versions like JDK 8, 9, or 10 which still include the JAXB library by default. Or:

Specify an additional dependency in your project’s pom.xml file as follows:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

In case you don’t use Maven
https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.3.0


问:
Prevent passing a temporary to a class that doesn't own it
Is there a way in C++ to prevent passing a owning resource to something?

In particular, I'm thinking about a class that keeps pointers to external independent objects (the class is not the owner of these objects).

And I'm wondering: what's the best way to enforce the fact that this is not an owner?

In other words, how can I prevent a client from doing something like this:

// my class
class NonOwner {
    T * m_p;
public:
    NonOwner(const T* p) : m_p(p) {}
    void DoStuffWithP() { // print m_p or whatever }
};

// client's code
NonOwner o{new T()}
// no! I would like to prevent this, because NonOwner doesn't own the pointer.
// It just keeps a weak reference to it (perhaps a weak_ptr?)
// and doesn't have any code to then free the memory (rightly so).
```
<p>I would like instead to enforce a usage that is always like:</p>
<pre class="lang-cpp prettyprint-override"><code>auto t = new T(); // independent object. Someone owns this. Could be a unique_ptr
NonOwner o{t}; // ok, allowed.
</code>```

答:
You could try to pass a ref to the pointer. But as you cannot automatically convert a non const pointer to a const pointer ref, you need both overloads for const and non const (thanks to Jarod42 for that point):

```<code>class NonOwner {
    T * m_p;
public:
    NonOwner(const T*& p) : m_p(p) {}
    NonOwner(T*& p) : m_p(p) {}
    void DoStuffWithP() { // print m_p or whatever }
};
</code>```

When you later try to use it, you correctly get:

```<code>NonOwner o( new T() ); // croaks for "cannot convert argument 1 from 'T *' to 'T *&'"
auto t = new T();
NonOwner o1(t);        // no error
</code>```

What makes the compiler croak, is that the ref can only be binded to a lvalue what the result of an expression is not.

Body:
Is there a way in C++ to prevent passing a owning resource to something?

In particular, I'm thinking about a class that keeps pointers to external independent objects (the class is not the owner of these objects).

And I'm wondering: what's the best way to enforce the fact that this is not an owner?

In other words, how can I prevent a client from doing something like this:

// my class
class NonOwner {
    T * m_p;
public:
    NonOwner(const T* p) : m_p(p) {}
    void DoStuffWithP() { // print m_p or whatever }
};

// client's code
NonOwner o{new T()}
// no! I would like to prevent this, because NonOwner doesn't own the pointer.
// It just keeps a weak reference to it (perhaps a weak_ptr?)
// and doesn't have any code to then free the memory (rightly so).

I would like instead to enforce a usage that is always like:

auto t = new T(); // independent object. Someone owns this. Could be a unique_ptr
NonOwner o{t}; // ok, allowed.

Body:
You could try to pass a ref to the pointer. But as you cannot automatically convert a non const pointer to a const pointer ref, you need both overloads for const and non const (thanks to Jarod42 for that point):

class NonOwner {
    T * m_p;
public:
    NonOwner(const T*& p) : m_p(p) {}
    NonOwner(T*& p) : m_p(p) {}
    void DoStuffWithP() { // print m_p or whatever }
};

When you later try to use it, you correctly get:

NonOwner o( new T() ); // croaks for "cannot convert argument 1 from 'T *' to 'T *&'"
auto t = new T();
NonOwner o1(t);        // no error

What makes the compiler croak, is that the ref can only be binded to a lvalue what the result of an expression is not.


问:
Translate paragraph in python
I am trying to translate a Paragraph from english to my local language which I have written the code as:

```<code>def translate(inputvalue):
//inputvalue is an array of english paragraphs
        try:
            translatedData = []
            trans = Translator()
            for i in inputvalue:
                sentence = re.sub(r'(?<=[.,])(?=[^\s])', r' ', i)
                //adding space where there is no space after , or ,
                t = trans.translate(sentence, src='en', dest = 'ur')
                //translating from english to my local language urdu
                translatedData.append(t.text)
                //appending data in translatedData array
            DisplayOutput.output(translatedData)
            //finally calling DisplayOutput function to print translated data
</code>```

The problem I am facing here is that my local language begins writing from [Right side]
and googletrans is not giving proper output. It puts periods ,commas, untranslated words at the beginning or at the end for example:

```<code>I am 6 years old. I love to draw cartoons, animals, and plants. I do not have ADHD.
</code>```

it would translate this sentence as:

```<code>میری عمر 6 سال ہے،. مجھے کارٹون جانور اور پودے کھینچنا پسند ہےمجھے ADHD 6نہیں ہے.
</code>```

As you can observe it could not translate ADHD as it is just an abbreviation it puts that at the beginning of the sentence and same goes for periods and numbers and commas.

How should I translate it so that it does not conflict like that.

If putting the sentence in another array like:

```<code>['I am', '6', 'years old', '.', 'I love to draw cartoons',',', 'animals',',', 'and plants','.', 'I do not have', 'ADHD','.']
</code>```

I have no idea how to achieve this type of array but I believe it can solve the problem.
As I can translate only the parts that has English words and then appending the list in a string.

Kindly Help me generate this type of array or any other solution

答:
```<code>string = "I am 6 years old. I love to draw cartoons, animals, and plants. I do not have ADHD."

arr = []

substring = ""
alpha = None
for char in string:
    if char.isalpha() or char == " ": alpha = True
    else: alpha = False
    if substring.replace(" ","").isalpha():
        if alpha:
            substring += char
        else:
            arr.append(substring)
            substring = char
    else:
        if alpha:
            arr.append(substring)
            substring = char

while " " in arr: arr.remove(" ")
while "" in arr: arr.remove("")

print(arr)
</code>```

Loop through each character in the string, then check if it is a letter or not a letter with ".isalpha()". Then depending on the conditions of the current substring, you append to it or create a new one.

Title: Translate paragraph in python

Body:
I am trying to translate a Paragraph from english to my local language which I have written the code as:

def translate(inputvalue):
//inputvalue is an array of english paragraphs
        try:
            translatedData = []
            trans = Translator()
            for i in inputvalue:
                sentence = re.sub(r'(?<=[.,])(?=[^\s])', r' ', i)
                //adding space where there is no space after , or ,
                t = trans.translate(sentence, src='en', dest = 'ur')
                //translating from english to my local language urdu
                translatedData.append(t.text)
                //appending data in translatedData array
            DisplayOutput.output(translatedData)
            //finally calling DisplayOutput function to print translated data

The problem I am facing here is that my local language begins writing from [Right side]
and googletrans is not giving proper output. It puts periods ,commas, untranslated words at the beginning or at the end for example:

I am 6 years old. I love to draw cartoons, animals, and plants. I do not have ADHD.

it would translate this sentence as:

میری عمر 6 سال ہے،. مجھے کارٹون جانور اور پودے کھینچنا پسند ہےمجھے ADHD 6نہیں ہے.

As you can observe it could not translate ADHD as it is just an abbreviation it puts that at the beginning of the sentence and same goes for periods and numbers and commas.

How should I translate it so that it does not conflict like that.

If putting the sentence in another array like:

['I am', '6', 'years old', '.', 'I love to draw cartoons',',', 'animals',',', 'and plants','.', 'I do not have', 'ADHD','.']

I have no idea how to achieve this type of array but I believe it can solve the problem.
As I can translate only the parts that has English words and then appending the list in a string.

Kindly Help me generate this type of array or any other solution

Body:
string = "I am 6 years old. I love to draw cartoons, animals, and plants. I do not have ADHD."

arr = []

substring = ""
alpha = None
for char in string:
    if char.isalpha() or char == " ": alpha = True
    else: alpha = False
    if substring.replace(" ","").isalpha():
        if alpha:
            substring += char
        else:
            arr.append(substring)
            substring = char
    else:
        if alpha:
            arr.append(substring)
            substring = char

while " " in arr: arr.remove(" ")
while "" in arr: arr.remove("")

print(arr)

Loop through each character in the string, then check if it is a letter or not a letter with ".isalpha()". Then depending on the conditions of the current substring, you append to it or create a new one.


问:
How to change the order of rsync in symfony deployment task
I want to deploy a part of my symfony application, say, it's like a module.

I want to exclude all files first, and then include only the files of
  my new module.

For deployment I use the following symfony task

```<code> php symfony project:deploy production -t
</code>```

The parameter -t prints all files to the output that are included in this dry run of rsync.

Content of config/rsync_exclude.txt is only *, since I like to exclude everthing:

```<code>*
</code>```

In config/rsync_include.txt I list all the files and folders for the inclusion:

```<code>config/
config/mysupermodule.yml
lib/model/doctrine/
lib/model/doctrine/MySuperclass.php
lib/model/doctrine/MySuperclassTable.php
lib/
lib/MySuperLibrary/
lib/MySuperLibrary/*
</code>```

The symfony task builds the following rsync command:

```<code>rsync --dry-run -azC --force --delete --progress --exclude-from=config/rsync_exclude.txt --include-from=config/rsync_include.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/
</code>```

Problem 1:  The the task doesn't sync any files.

Solution to 1: Change order: Include first, then exclude.

I figured out, that if I change my need to this one:

I want to include all files of my new module and exclude then all
  other.

This means using the following command:

```<code>rsync --dry-run -azC --force --delete --progress --include-from=config/rsync_include.txt --exclude-from=config/rsync_exclude.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/
</code>```

The rsync works.

Problem 2: How can I change the order of the rsync when using the symfony task?
The symfony task first excludes than includes.

Solution 2: ?

答:
It is NOT possible.

But you can edit the deployment task in lib/task/project/sfProjectDeployTask.class.php.

Replace this (line 145 to 154 in SF 1.4):

```<code>  if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
  {
    $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
  }

  if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
  {
    $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
  }
</code>```

with this:

```<code>  if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
  {
    $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
  }

  if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
  {
    $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
  }
</code>```

In short: switch this two IF statements.

Body:
I want to deploy a part of my symfony application, say, it's like a module.

I want to exclude all files first, and then include only the files of
  my new module.

For deployment I use the following symfony task

 php symfony project:deploy production -t

The parameter -t prints all files to the output that are included in this dry run of rsync.

Content of config/rsync_exclude.txt is only *, since I like to exclude everthing:

*

In config/rsync_include.txt I list all the files and folders for the inclusion:

config/
config/mysupermodule.yml
lib/model/doctrine/
lib/model/doctrine/MySuperclass.php
lib/model/doctrine/MySuperclassTable.php
lib/
lib/MySuperLibrary/
lib/MySuperLibrary/*

The symfony task builds the following rsync command:

rsync --dry-run -azC --force --delete --progress --exclude-from=config/rsync_exclude.txt --include-from=config/rsync_include.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/

Problem 1:  The the task doesn't sync any files.

Solution to 1: Change order: Include first, then exclude.

I figured out, that if I change my need to this one:

I want to include all files of my new module and exclude then all
  other.

This means using the following command:

rsync --dry-run -azC --force --delete --progress --include-from=config/rsync_include.txt --exclude-from=config/rsync_exclude.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/

The rsync works.

Problem 2: How can I change the order of the rsync when using the symfony task?
The symfony task first excludes than includes.

Solution 2: ?

Body:
It is NOT possible.

But you can edit the deployment task in lib/task/project/sfProjectDeployTask.class.php.

Replace this (line 145 to 154 in SF 1.4):

  if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
  {
    $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
  }

  if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
  {
    $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
  }

with this:

  if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
  {
    $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
  }

  if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
  {
    $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
  }

In short: switch this two IF statements.


问:
Replace double backslashes into single backslashes to be processed by ansi-to-html
I'm trying to process a terminal output. Let's say it's the string "\x1b[01;32mREADME.md". It has a double backslash. If I run console.log("\\x1b[01;32mREADME.md"), it only shows a single backslash, but if I pass it to the toHtml from ansi-to-html, it doesn't work. And by work, I mean transforming the characters into html.

I tried several solutions involving replace or the fact that \ is U+5c in unicode but nothing worked. The options on the library don't help either.

codesandbox example

import Convert from "ansi-to-html";

export default function App() {
  const c = new Convert({ escapeXML: true });
  const single = "\x1b[01;32mREADME.md";
  const double = "\\x1b[01;32mREADME.md";

  console.log(double) // prints single backslash
  const res1 = c.toHtml(single);
  const res2 = c.toHtml(double);

  return (

      single backslash works:
      ```{single}```
      ```{res1}```

      double backslash doesnt work:
      ```{double}```
      ```{res2}```

  );
}
```

Any help is appreciated.

答:
You can use String.raw function:

```<code>const double = String.raw`\\x1b[01;32mREADME.md`;
</code>```

With this you dont need to use convert:

export default function App() {
  const single = String.raw`\x1b[01;32mREADME.md`;
  const double = String.raw`\\x1b[01;32mREADME.md`;

  const res1 = single;
  const res2 = double;

  return (

      single backslash works:
      ```{single}```
      ```{res1}```

      double backslash doesnt work:
      ```{double}```
      ```{res2}```

  );
}```

Body:
I'm trying to process a terminal output. Let's say it's the string "\x1b[01;32mREADME.md". It has a double backslash. If I run console.log("\\x1b[01;32mREADME.md"), it only shows a single backslash, but if I pass it to the toHtml from ansi-to-html, it doesn't work. And by work, I mean transforming the characters into html.

I tried several solutions involving replace or the fact that \ is U+5c in unicode but nothing worked. The options on the library don't help either.

codesandbox example

import Convert from "ansi-to-html";

export default function App() {
  const c = new Convert({ escapeXML: true });
  const single = "\x1b[01;32mREADME.md";
  const double = "\\x1b[01;32mREADME.md";

  console.log(double) // prints single backslash
  const res1 = c.toHtml(single);
  const res2 = c.toHtml(double);

  return (

      single backslash works:

{single}

{res1}

      double backslash doesnt work:

{double}

{res2}

  );
}

Any help is appreciated.

Body:
You can use String.raw function:

const double = String.raw`\\x1b[01;32mREADME.md`;

With this you dont need to use convert:

export default function App() {
  const single = String.raw`\x1b[01;32mREADME.md`;
  const double = String.raw`\\x1b[01;32mREADME.md`;

  const res1 = single;
  const res2 = double;

  return (
    <div className="App">
      single backslash works:
      <pre>{single}</pre>
      <pre>{res1}</pre>
      <br />
      <br />
      double backslash doesnt work:
      <pre>{double}</pre>
      <pre>{res2}</pre>
    </div>
  );
}