问:
Nginx fails to load css files
I've recently decided to switch from Apache2 to Nginx. I installed Nginx on my CentOS server and setup a basic configuration.
When I tried to load my site in browser (FF/Chrome) I noticed that css file is not loaded. I checked the error console and saw this message:

Error: The stylesheet http://example.com/style.css was not loaded because its MIME type, "text/html", is not "text/css".

I checked Nginx configuration and everything seems to be fine:

```<code>http {
    include /etc/nginx/mime.types;
    ..........
}
</code>```

The mime type for css files is correctly set in /etc/nginx/mime.types.

text/css css;

Everything seems to be well configured but my css files are still not loaded. I have no explanation.

Another thing worth mentioning. Initially I installed Nginx using epel repositories and i got an old version: 0.8... It appeared to me that my problem was a bug in that version so I uninstalled 0.8 version, added nginx repository to yum and then installed latest version: 1.0.14. I thought the new version will solve my problem, but unfortunately it didn't so I am running out of ideas.

I appreciate any help.

Configuration files:

/etc/nginx/nginx.conf

```<code>user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
</code>```

/etc/nginx/conf.d/default.conf

```<code>server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
         root    /usr/share/nginx/html;
         index  index.html index.htm index.php;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
         include        fastcgi_params;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
</code>```

/etc/nginx/mime.types

```<code>types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/x-javascript              js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;
    ..........................................
    other types here
    ..........................................
}
</code>```

答:
I know this IS late, but after scouring the internet for solutions and while all were concentrated on the config, actually the html itself is as Importnant

on the config side and after you've defined your project root, you should point to your statrics especially css in this case like this for example - I have my css in root/src

```<code>location ~*/src/.css {
    include /etc/nginx/mime.types;
    add_header Content-type text/css;
}
</code>```

and in you HTML:
make sure to use the rel and the type properly

<link rel="stylesheet" href="src/styles.css" type="text/css">

hope this helps others in the future

Title: Nginx fails to load css files

Body:
I've recently decided to switch from Apache2 to Nginx. I installed Nginx on my CentOS server and setup a basic configuration.
When I tried to load my site in browser (FF/Chrome) I noticed that css file is not loaded. I checked the error console and saw this message:

Error: The stylesheet http://example.com/style.css was not loaded because its MIME type, "text/html", is not "text/css".

I checked Nginx configuration and everything seems to be fine:

http {
    include /etc/nginx/mime.types;
    ..........
}

The mime type for css files is correctly set in /etc/nginx/mime.types.

text/css css;

Everything seems to be well configured but my css files are still not loaded. I have no explanation.

Another thing worth mentioning. Initially I installed Nginx using epel repositories and i got an old version: 0.8... It appeared to me that my problem was a bug in that version so I uninstalled 0.8 version, added nginx repository to yum and then installed latest version: 1.0.14. I thought the new version will solve my problem, but unfortunately it didn't so I am running out of ideas.

I appreciate any help.

Configuration files:

/etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
         root    /usr/share/nginx/html;
         index  index.html index.htm index.php;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
         include        fastcgi_params;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

/etc/nginx/mime.types

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/x-javascript              js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;
    ..........................................
    other types here
    ..........................................
}

Body:
I know this IS late, but after scouring the internet for solutions and while all were concentrated on the config, actually the html itself is as Importnant

on the config side and after you've defined your project root, you should point to your statrics especially css in this case like this for example - I have my css in root/src

location ~*/src/.css {
    include /etc/nginx/mime.types;
    add_header Content-type text/css;
}

and in you HTML:
make sure to use the rel and the type properly

<link rel="stylesheet" href="src/styles.css" type="text/css">

hope this helps others in the future


来源: stackexchange

问:
No query results for model [App\Models\Customer] backpack
I am using laravel backpack package and while edit and delete or preview operation I am getting the below error.

No query results for model [App\Models\Customer] record id

I have included the model. What am I am missing?

And one more thing the record id which is showing in the error it is not present in the table, But the backpack list interface is showing. why?
And this table is a master. Any CRUD operation will happen only for its own tbl only not affecting any other tbl.
Below is controller

```<code> <?PHP
   namespace App\Http\Controllers\Admin;
   use App\Models\Customer;
   use Illuminate\Support\Facades\DB;
   use App\Http\Requests\CustomerRequest;
   use Backpack\CRUD\app\Http\Controllers\CrudController;
   use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
   use Carbon\Carbon;

   class CustomerCrudController extends CrudController
  {
   use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
   use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation
   {store as traitstore;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation
   {update as traitupdate;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation
   {destroy as traitDestroy;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;

public function setup()
{
    //$this->crud->enableExportButtons();
    $this->crud->setModel('App\Models\Customer');
    $this->crud->setRoute(config('backpack.base.route_prefix') . '/customer');
    $this->crud->setEntityNameStrings('customer', 'customers');
}

protected function setupListOperation()
{
    // TODO: remove setFromDb() and manually define Columns, maybe Filters
    //$this->crud->setFromDb();

    $this->crud->setColumns([
        [
            'name'  => 'company_name',
            'label' => 'Company',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_address1',
            'label' => 'Primary Add',
            'type'  => 'text',
        ],
        [
            'name'  => 'primary_contact',
            'label' => 'Primary Cont',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_city',
            'label' => 'city',
            'type'  => 'text',
        ]
    ]);

    }
}
</code>```

Model is

```<code><?PHP

namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use CrudTrait, SoftDeletes;

    protected $table = 'customers';
    protected $primaryKey = "cust_id";

    protected $fillable = [
        'company_name',
        'company_address1',
        'company_address2',
        'company_city',
        'company_zip',
        'company_country',
        'company_state',
        'company_vat',
        'company_id',
        'primary_contact',
        'technical_contact',
        'financial_contact',
        'cust_def_time_zone',
        'created_at',
        'updated_at',
        'deleted_at' ];
}
</code>```

答:
edit setupShowOperation function in CustomerCrudController
add this

```<code>Customer::withTrashed()->find(\request()->id);
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I am using laravel backpack package and while edit and delete or preview operation I am getting the below error.

No query results for model [App\Models\Customer] record id

I have included the model. What am I am missing?

And one more thing the record id which is showing in the error it is not present in the table, But the backpack list interface is showing. why?
And this table is a master. Any CRUD operation will happen only for its own tbl only not affecting any other tbl.
Below is controller

 <?PHP
   namespace App\Http\Controllers\Admin;
   use App\Models\Customer;
   use Illuminate\Support\Facades\DB;
   use App\Http\Requests\CustomerRequest;
   use Backpack\CRUD\app\Http\Controllers\CrudController;
   use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
   use Carbon\Carbon;

   class CustomerCrudController extends CrudController
  {
   use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
   use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation
   {store as traitstore;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation
   {update as traitupdate;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation
   {destroy as traitDestroy;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;

public function setup()
{
    //$this->crud->enableExportButtons();
    $this->crud->setModel('App\Models\Customer');
    $this->crud->setRoute(config('backpack.base.route_prefix') . '/customer');
    $this->crud->setEntityNameStrings('customer', 'customers');
}

protected function setupListOperation()
{
    // TODO: remove setFromDb() and manually define Columns, maybe Filters
    //$this->crud->setFromDb();

    $this->crud->setColumns([
        [
            'name'  => 'company_name',
            'label' => 'Company',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_address1',
            'label' => 'Primary Add',
            'type'  => 'text',
        ],
        [
            'name'  => 'primary_contact',
            'label' => 'Primary Cont',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_city',
            'label' => 'city',
            'type'  => 'text',
        ]
    ]);

    }
}

Model is

<?PHP

namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use CrudTrait, SoftDeletes;

    protected $table = 'customers';
    protected $primaryKey = "cust_id";

    protected $fillable = [
        'company_name',
        'company_address1',
        'company_address2',
        'company_city',
        'company_zip',
        'company_country',
        'company_state',
        'company_vat',
        'company_id',
        'primary_contact',
        'technical_contact',
        'financial_contact',
        'cust_def_time_zone',
        'created_at',
        'updated_at',
        'deleted_at' ];
}

Body:
edit setupShowOperation function in CustomerCrudController
add this

Customer::withTrashed()->find(\request()->id);


问:
Generate a data frame with years as columns and conditional values in R

This is the kind of problem that I could easily solve for one observation and do it on excel, but I am not being able to replicate it in R.

I have a dataset that has information on cars gas expenditure by team. Each time can have one or more cars in circulation. Some of those cars will stop using gas (stop year) , but other new cars will start using gas (start year)

Team   Gas.Consumption   StopUsing        StartUsing

A           45000           2025            1999

A           50444           2035            1998

A           45666            NA             1999

A           45000            NA             2024

B           45000           2043            1997

B           56777            NA             2030

B           87666            NA            2033

I need to have a dataframe or time-series that gives me the total yearly consumption from today (2022) to 2100.

The new dataframe would have to sum all the cars in use from 2022 on, consider when these cars stop being used (and not sum their consumption anymore), and add the cars that start being used (and their consumptions). All of this information grouped by team.

In the end should be something like:

2022  2023  2024 .... 2100

A (yearly consumption 22)... (yearly consumption 2100)

B (yearly consumption 22)... (yearly consumption 2100)

I tried a for loop but I am not being able to code it properly. Thanks a lot!

Body:
I'm not sure if I understood correctly, but I believe this is what you are looking for.

library(tidyverse)
tribble(
  ~Team, ~Gas.Consumption, ~StopUsing, ~StartUsing,
  "A", 45000, 2025, 1999,
  "A", 50444, 2035, 1998,
  "A", 45666, NA, 1999,
  "A", 45000, NA, 2024,
  "B", 45000, 2043, 1997,
  "B", 56777, NA, 2030,
  "B", 87666, NA, 2033
) %>%
  mutate(StopUsing=if_else(is.na(StopUsing), 2100, StopUsing),
         TimeSeries=map2(StartUsing, StopUsing, ~ .x:.y)) %>%
  unnest(cols=TimeSeries) %>% filter(TimeSeries>=2022) %>% group_by(Team, TimeSeries) %>%
  summarize(Gas.Consumption=sum(Gas.Consumption), .groups="drop") %>%
  pivot_wider(names_from=TimeSeries, values_from=Gas.Consumption)
#> # A tibble: 2 x 80
#>   Team  `2022` `2023` `2024` `2025` `2026` `2027` `2028` `2029` `2030` `2031`
#>   <chr>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
#> 1 A     141110 141110 186110 186110 141110 141110 141110 141110 141110 141110
#> 2 B      45000  45000  45000  45000  45000  45000  45000  45000 101777 101777
#> # … with 69 more variables: 2032 <dbl>, 2033 <dbl>, 2034 <dbl>, 2035 <dbl>,
#> #   2036 <dbl>, 2037 <dbl>, 2038 <dbl>, 2039 <dbl>, 2040 <dbl>, 2041 <dbl>,
#> #   2042 <dbl>, 2043 <dbl>, 2044 <dbl>, 2045 <dbl>, 2046 <dbl>, 2047 <dbl>,
#> #   2048 <dbl>, 2049 <dbl>, 2050 <dbl>, 2051 <dbl>, 2052 <dbl>, 2053 <dbl>,
#> #   2054 <dbl>, 2055 <dbl>, 2056 <dbl>, 2057 <dbl>, 2058 <dbl>, 2059 <dbl>,
#> #   2060 <dbl>, 2061 <dbl>, 2062 <dbl>, 2063 <dbl>, 2064 <dbl>, 2065 <dbl>,
#> #   2066 <dbl>, 2067 <dbl>, 2068 <dbl>, 2069 <dbl>, 2070 <dbl>, 2071 <dbl>,
#> #   2072 <dbl>, 2073 <dbl>, 2074 <dbl>, 2075 <dbl>, 2076 <dbl>, 2077 <dbl>,
#> #   2078 <dbl>, 2079 <dbl>, 2080 <dbl>, 2081 <dbl>, 2082 <dbl>, 2083 <dbl>,
#> #   2084 <dbl>, 2085 <dbl>, 2086 <dbl>, 2087 <dbl>, 2088 <dbl>, 2089 <dbl>,
#> #   2090 <dbl>, 2091 <dbl>, 2092 <dbl>, 2093 <dbl>, 2094 <dbl>, 2095 <dbl>,
#> #   2096 <dbl>, 2097 <dbl>, 2098 <dbl>, 2099 <dbl>, 2100 <dbl>

Created on 2022-02-09 by the reprex package (v2.0.0)


问:
Is it possible to make a layout auto adjust from Row layout to Column layout while changing windows size in browser?
I am trying to create a flutter web App. I have created a Row with Form with 3 TextFormFields. My Requirement is: If i change the web page's window Size big to small, That TextFormFields should be viewed as Column Layout, And if i change the size from small to big that TextFormFields should be viewed as row layout. And someTimes i will use TextFormFields more than 3. If it is possible How to do. Or If any other Ideas aso Please let me know. Or Let me know incase any other widgets are there Rather than that row and column.
My Example code with Row:</p>
```<code>SingleChildScrollView(
                    child: Row(
                      children: [
                        Form(
                          key: _formkey,
                          child: Align(
                            alignment: Alignment.topCenter,
                            child: Card(
                              child: Padding(
                                padding: const EdgeInsets.all(16),
                                child: Row(
                                  children: [
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '1',
                                        ),
                                      ),
                                    ),
                                    const SizedBox(
                                      width: 10,
                                    ),
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '2',
                                        ),
                                      ),
                                    ),
                                    const SizedBox(
                                      width: 10,
                                    ),
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '3',
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
</code>```

答:
The widget you are probably looking for is the OverflowBar widget. It is used for example in dialogs for its buttons. In case there is not enough horizontal space then the buttons are laid out as a column instead of a row.

You can see its documentation here: https://api.flutter.dev/flutter/widgets/OverflowBar-class.html

Body:
I am trying to create a flutter web App. I have created a Row with Form with 3 TextFormFields. My Requirement is: If i change the web page's window Size big to small, That TextFormFields should be viewed as Column Layout, And if i change the size from small to big that TextFormFields should be viewed as row layout. And someTimes i will use TextFormFields more than 3. If it is possible How to do. Or If any other Ideas aso Please let me know. Or Let me know incase any other widgets are there Rather than that row and column.
My Example code with Row:

SingleChildScrollView(
                    child: Row(
                      children: [
                        Form(
                          key: _formkey,
                          child: Align(
                            alignment: Alignment.topCenter,
                            child: Card(
                              child: Padding(
                                padding: const EdgeInsets.all(16),
                                child: Row(
                                  children: [
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '1',
                                        ),
                                      ),
                                    ),
                                    const SizedBox(
                                      width: 10,
                                    ),
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '2',
                                        ),
                                      ),
                                    ),
                                    const SizedBox(
                                      width: 10,
                                    ),
                                    ConstrainedBox(
                                      constraints:
                                          const BoxConstraints(maxWidth: 400),
                                      child: TextFormField(
                                        readOnly: true,
                                        decoration: const InputDecoration(
                                          border: OutlineInputBorder(),
                                          filled: true,
                                          labelText: '3',
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),


问:
Why confirm option of rails button_to helper is not working
I have a rail button_to where I want it to show a confirm dialog box before proceeding.

```<code><%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{confirm: "Are you sure you want to reset the indexes?" }) %>
</code>```

The actions are occurring but I'm not getting a confirmation box. I read that the problem could be related to javascript. I thought I had that enabled.

```<code>application.js
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//= require tinymce-jquery
//= require ckeditor/init
//= require ckeditor/config.js
//= require jquery.are-you-sure
//= require script
//= require script.responsive
//= require_tree .
</code>```

If I do an inspect on the button, I see

```<code><form class="button_to" method="post" action="/help/rebuild_indexes?data%5Bconfirm%5D=Are+you+sure+you+want+to+reset+the+indexes%3F">
  <input type="submit" value="Rebuild indexes">
  <input type="hidden" name="authenticity_token" value="3mnAMmyHaINiDngjQn87EMmhmetp2VJcX+lwcmbUlhwBfv7V1hpLc9ZY1OF5JAFm9erFJjX+qyDz35/KK41jaA==">
</form>
</code>```

What am I missing in getting a confirmation box to appear?

答:
Just a quick note for those who want to create a button_to with confirmation text (in rails 7):</p>
```<code><%= button_to 'Rebuild indexes', action: :rebuild_indexes,
  form: {data: {turbo_confirm: 'Are you sure?'}} %>
</code>```

Body:
I have a rail button_to where I want it to show a confirm dialog box before proceeding.

<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{confirm: "Are you sure you want to reset the indexes?" }) %>

The actions are occurring but I'm not getting a confirmation box. I read that the problem could be related to javascript. I thought I had that enabled.

application.js
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//= require tinymce-jquery
//= require ckeditor/init
//= require ckeditor/config.js
//= require jquery.are-you-sure
//= require script
//= require script.responsive
//= require_tree .

If I do an inspect on the button, I see

<form class="button_to" method="post" action="/help/rebuild_indexes?data%5Bconfirm%5D=Are+you+sure+you+want+to+reset+the+indexes%3F">
  <input type="submit" value="Rebuild indexes">
  <input type="hidden" name="authenticity_token" value="3mnAMmyHaINiDngjQn87EMmhmetp2VJcX+lwcmbUlhwBfv7V1hpLc9ZY1OF5JAFm9erFJjX+qyDz35/KK41jaA==">
</form>

What am I missing in getting a confirmation box to appear?

Body:
Just a quick note for those who want to create a button_to with confirmation text (in rails 7):

<%= button_to 'Rebuild indexes', action: :rebuild_indexes,
  form: {data: {turbo_confirm: 'Are you sure?'}} %>


问:
Amazon EC2 micro instance not responding
I have a couple of micro instances that have been working fine for weeks. Both are running WordPress blogs. In the last 24 hours one of them has stopped. I can't ssh in even after a reboot. The other instance is working fine.

```<code>ssh: connect to host ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com port 22: Operation timed out
</code>```

There in nothing obvious in the log that looks like a problem. The last few lines are:

```<code>cloud-init:  runcmd[  OK  ]
Mounting other filesystems:  [  OK  ]
Retrigger failed udev events[  OK  ]
Generating SSH1 RSA host key: [  OK  ]
Starting sshd: [  OK  ]
Starting ntpd: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
Starting crond: [  OK  ]
[  OK  ]
Starting atd: [  OK  ]
Starting yum-updatesd: [  OK  ]
Running cloud-init user-scripts (none found)[  OK  ]
Amazon Linux AMI release 2011.02.1.1 (beta)
Kernel 2.6.35.11-83.9.amzn1.i686 on an i686
ip-xx-xxx-xx-xx login:
</code>```

The management console states that everything is running and normal.

I use the same security group and .pem file for both instances.

I suspect that this instance has been getting more traffic than the other one. Is there anyway that the micro instance could run out of memory and just stop responding? What could be going wrong?

Here is a screen shot of the Monitoring panel

Thanks

答:
There are several possibilities, but the two most likely are:

High load on the host that your Micro instance is running on - Micro instances get a small slice of resources anyway, and get scaled back quite harshly when the host is under load.

A fault has occurred on the host which is impacting VM responsiveness - this is actually relatively common, and can exhibit the type of behaviour you're seeing.

In either case, the quickest solution is to nuke the instance and restart it - you'll likely get a new instance on a different host, which may be less stressed or less broken. ;)

ContentLicense: CC BY-SA 3.0

Body:
I have a couple of micro instances that have been working fine for weeks. Both are running WordPress blogs. In the last 24 hours one of them has stopped. I can't ssh in even after a reboot. The other instance is working fine.

ssh: connect to host ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com port 22: Operation timed out

There in nothing obvious in the log that looks like a problem. The last few lines are:

cloud-init:  runcmd[  OK  ]
Mounting other filesystems:  [  OK  ]
Retrigger failed udev events[  OK  ]
Generating SSH1 RSA host key: [  OK  ]
Starting sshd: [  OK  ]
Starting ntpd: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
Starting crond: [  OK  ]
[  OK  ]
Starting atd: [  OK  ]
Starting yum-updatesd: [  OK  ]
Running cloud-init user-scripts (none found)[  OK  ]
Amazon Linux AMI release 2011.02.1.1 (beta)
Kernel 2.6.35.11-83.9.amzn1.i686 on an i686
ip-xx-xxx-xx-xx login:

The management console states that everything is running and normal.

I use the same security group and .pem file for both instances.

I suspect that this instance has been getting more traffic than the other one. Is there anyway that the micro instance could run out of memory and just stop responding? What could be going wrong?

Here is a screen shot of the Monitoring panel

Thanks


问:
Change class types in a list
I have run a series of "lmerModLmerTest" class-type models, which I have saved in a list. I would like to change the class of these models from "lmerModLmerTest" to "lmerTest".

For one model, I would change it like this, which works nicely:

```<code>class(model_1) <- "lmerMod"
</code>```

However as I have many models I would ideally like to loop through the list in which I have saved all these models (old_models).

However when I run this code:

```<code>mylist.df <- lapply(names(old_models),
                   function(x){
                   b <- as(old_models[[x]],"lmerMod")
                   b
                   })
</code>```

the resulting new list (mylist.df) has 0 elements. Any ideas as to why this is the case?
Many thanks!

答:
Do not use names:

library(lmerTest)
#> Loading required package: lme4
#> Loading required package: Matrix
#>
#> Attaching package: 'lmerTest'
#> The following object is masked from 'package:lme4':
#>
#>     lmer
#> The following object is masked from 'package:stats':
#>
#>     step
library(lme4)

old_models <- list(
  lmerTest::lmer(Sepal.Length ~ Sepal.Width + (1|Species) , data = iris),
  lmerTest::lmer(Sepal.Width ~ Sepal.Length + (1|Species) , data = iris)
)

old_models
#> [[1]]
#> Linear mixed model fit by REML ['lmerModLmerTest']
#> Formula: Sepal.Length ~ Sepal.Width + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 194.6361
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 1.010
#>  Residual             0.438
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#> (Intercept)  Sepal.Width
#>      3.4062       0.7972
#>
#> [[2]]
#> Linear mixed model fit by REML ['lmerModLmerTest']
#> Formula: Sepal.Width ~ Sepal.Length + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 71.8035
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 0.5706
#>  Residual             0.2890
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#>  (Intercept)  Sepal.Length
#>       1.0448        0.3444
sapply(old_models, class)
#> [1] "lmerModLmerTest" "lmerModLmerTest"

new_models <- lapply(old_models, function(x) as(x, "lmerMod"))
new_models
#> [[1]]
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Sepal.Length ~ Sepal.Width + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 194.6361
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 1.010
#>  Residual             0.438
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#> (Intercept)  Sepal.Width
#>      3.4062       0.7972
#>
#> [[2]]
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Sepal.Width ~ Sepal.Length + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 71.8035
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 0.5706
#>  Residual             0.2890
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#>  (Intercept)  Sepal.Length
#>       1.0448        0.3444
sapply(new_models, class)
#> [1] "lmerMod" "lmerMod"
```

Created on 2022-02-09 by the reprex package (v2.0.1)

Title: Change class types in a list

Body:
I have run a series of "lmerModLmerTest" class-type models, which I have saved in a list. I would like to change the class of these models from "lmerModLmerTest" to "lmerTest".

For one model, I would change it like this, which works nicely:

class(model_1) <- "lmerMod"

However as I have many models I would ideally like to loop through the list in which I have saved all these models (old_models).

However when I run this code:

mylist.df <- lapply(names(old_models),
                   function(x){
                   b <- as(old_models[[x]],"lmerMod")
                   b
                   })

the resulting new list (mylist.df) has 0 elements. Any ideas as to why this is the case?
Many thanks!

Body:
Do not use names:

library(lmerTest)
#> Loading required package: lme4
#> Loading required package: Matrix
#>
#> Attaching package: 'lmerTest'
#> The following object is masked from 'package:lme4':
#>
#>     lmer
#> The following object is masked from 'package:stats':
#>
#>     step
library(lme4)

old_models <- list(
  lmerTest::lmer(Sepal.Length ~ Sepal.Width + (1|Species) , data = iris),
  lmerTest::lmer(Sepal.Width ~ Sepal.Length + (1|Species) , data = iris)
)

old_models
#> [[1]]
#> Linear mixed model fit by REML ['lmerModLmerTest']
#> Formula: Sepal.Length ~ Sepal.Width + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 194.6361
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 1.010
#>  Residual             0.438
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#> (Intercept)  Sepal.Width
#>      3.4062       0.7972
#>
#> [[2]]
#> Linear mixed model fit by REML ['lmerModLmerTest']
#> Formula: Sepal.Width ~ Sepal.Length + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 71.8035
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 0.5706
#>  Residual             0.2890
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#>  (Intercept)  Sepal.Length
#>       1.0448        0.3444
sapply(old_models, class)
#> [1] "lmerModLmerTest" "lmerModLmerTest"

new_models <- lapply(old_models, function(x) as(x, "lmerMod"))
new_models
#> [[1]]
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Sepal.Length ~ Sepal.Width + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 194.6361
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 1.010
#>  Residual             0.438
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#> (Intercept)  Sepal.Width
#>      3.4062       0.7972
#>
#> [[2]]
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Sepal.Width ~ Sepal.Length + (1 | Species)
#>    Data: iris
#> REML criterion at convergence: 71.8035
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Species  (Intercept) 0.5706
#>  Residual             0.2890
#> Number of obs: 150, groups:  Species, 3
#> Fixed Effects:
#>  (Intercept)  Sepal.Length
#>       1.0448        0.3444
sapply(new_models, class)
#> [1] "lmerMod" "lmerMod"

Created on 2022-02-09 by the reprex package (v2.0.1)


问:
Accessing the google calendar using a refresh token
Is this the right way to access the google calendar api using a refresh token? That's 2 weeks after a user gave me his consent.

```<code>const oauth2Client = new google.auth.OAuth2(
    process.env.GOOGLE_OAUTH_CLIENT_ID,
    process.env.GOOGLE_OAUTH_CLIENT_SECRET,
    process.env.DOMAIN_NAME + "/google/oauth/callback"
);

 oauth2Client.setCredentials({
        refresh_token: refreshToken
    })
    const calendar = google.calendar({version: "v3", auth: oauth2Client});
    calendar.events.watch({
        auth: oauth2Client,
        resource: {
            id: makeid(10) + Date.now(),
            token: process.env.GOOGLE_API_WATCH_TOKEN,
            type: 'web_hook',
            address: "https://" + process.env.DOMAIN_NAME + "/google/notifications"
        },
        calendarId: "primary"
    }, function(error, response) {
        if (error) {
            defer.reject(error);
        } else {
            defer.resolve(response);
        }
    });
    return defer.promise;
</code>```

I'm not using jwt.

答:
Your code shows a valid approach to token handling if it doesn't generate any issues. As an answer, I show below an alternative to OAuth 2.0 token handling.

This code will first read the token file with the readFile method. Then it will be fed to the authorize function. That function will set up the objects used on the authentication flow, and if it fails (due to an invalid token, per example) then it will call the getAccessToken function to gather new tokens.

const fs = require('fs');
const readline = require('readline');
const {
  google
} = require('googleapis');

const SCOPES = ['{YOUR SCOPES HERE}'];
const TOKEN_PATH = 'token.json';

fs.readFile('credentials.json', (err, content) => {
  if (err) return console.log('Error loading client secret file:', err);
  authorize(JSON.parse(content), listEvents);
});

function authorize(credentials, callback) {
  const {
    client_secret,
    client_id,
    redirect_uris
  } = credentials.installed;
  const oAuth2Client = new google.auth.OAuth2(
    client_id, client_secret, redirect_uris[0]);

  fs.readFile(TOKEN_PATH, (err, token) => {
    if (err) return getAccessToken(oAuth2Client, callback);
    oAuth2Client.setCredentials(JSON.parse(token));
    callback(oAuth2Client);
  });
}

function getAccessToken(oAuth2Client, callback) {
  const authUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES,
  });

  console.log('Authorize this app by visiting this url:', authUrl);

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  rl.question('Enter the code from that page here: ', (code) => {
    rl.close();
    oAuth2Client.getToken(code, (err, token) => {
      if (err) return console.error('Error retrieving access token',
        err);
      oAuth2Client.setCredentials(token);
      fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
        if (err) return console.error(err);
        console.log('Token stored to', TOKEN_PATH);
      });
      callback(oAuth2Client);
    });
  });
}
```

Please write back if you have doubts about this approach or your own.

Body:
Is this the right way to access the google calendar api using a refresh token? That's 2 weeks after a user gave me his consent.

const oauth2Client = new google.auth.OAuth2(
    process.env.GOOGLE_OAUTH_CLIENT_ID,
    process.env.GOOGLE_OAUTH_CLIENT_SECRET,
    process.env.DOMAIN_NAME + "/google/oauth/callback"
);

 oauth2Client.setCredentials({
        refresh_token: refreshToken
    })
    const calendar = google.calendar({version: "v3", auth: oauth2Client});
    calendar.events.watch({
        auth: oauth2Client,
        resource: {
            id: makeid(10) + Date.now(),
            token: process.env.GOOGLE_API_WATCH_TOKEN,
            type: 'web_hook',
            address: "https://" + process.env.DOMAIN_NAME + "/google/notifications"
        },
        calendarId: "primary"
    }, function(error, response) {
        if (error) {
            defer.reject(error);
        } else {
            defer.resolve(response);
        }
    });
    return defer.promise;

I'm not using jwt.

Body:
Your code shows a valid approach to token handling if it doesn't generate any issues. As an answer, I show below an alternative to OAuth 2.0 token handling.

This code will first read the token file with the readFile method. Then it will be fed to the authorize function. That function will set up the objects used on the authentication flow, and if it fails (due to an invalid token, per example) then it will call the getAccessToken function to gather new tokens.

const fs = require('fs');
const readline = require('readline');
const {
  google
} = require('googleapis');

const SCOPES = ['{YOUR SCOPES HERE}'];
const TOKEN_PATH = 'token.json';

fs.readFile('credentials.json', (err, content) => {
  if (err) return console.log('Error loading client secret file:', err);
  authorize(JSON.parse(content), listEvents);
});

function authorize(credentials, callback) {
  const {
    client_secret,
    client_id,
    redirect_uris
  } = credentials.installed;
  const oAuth2Client = new google.auth.OAuth2(
    client_id, client_secret, redirect_uris[0]);

  fs.readFile(TOKEN_PATH, (err, token) => {
    if (err) return getAccessToken(oAuth2Client, callback);
    oAuth2Client.setCredentials(JSON.parse(token));
    callback(oAuth2Client);
  });
}

function getAccessToken(oAuth2Client, callback) {
  const authUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES,
  });

  console.log('Authorize this app by visiting this url:', authUrl);

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  rl.question('Enter the code from that page here: ', (code) => {
    rl.close();
    oAuth2Client.getToken(code, (err, token) => {
      if (err) return console.error('Error retrieving access token',
        err);
      oAuth2Client.setCredentials(token);
      fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
        if (err) return console.error(err);
        console.log('Token stored to', TOKEN_PATH);
      });
      callback(oAuth2Client);
    });
  });
}

Please write back if you have doubts about this approach or your own.


问:
find specific Byte in File and read until specific byte in Lua
Is it possible to search at first inside the file after an specific byte and find the position and read just the bytes from the file in until that specific byte?

At the moment it is just possible for me to read some bytes or the whole file in and afterwards search for that specific byte.
like this:

```<code>local function read_file(path)
  local file = open(path, "r") -- r read mode and b binary mode
  if not file then return nil end
  local content = file:read(64) -- reading 64 bytes
  file:close()
  return content
end

local fileContent = read_file("../test/l_0.dat");
print(fileContent)

function parse(line)
   if line then
     len = 1
     a = line:find("V", len +1) --find V in content
     return a
   else
     return false
   end
end

a = parse(fileContent) --position of V in content
print(a)
print(string.sub(fileContent, a)) -- content until first found V
</code>```

In this example i find at position 21 the first V. So it would be cool to read in only 21 bytes except of 64 bytes or the whole file. But then i need to find the position before reading something in. Is this possible ? (The 21byte are variable, it could be 20 or 50 or so on)

答:
You can specify a file position using file:seek and read a certain number of characters (bytes) by providing an integer to file:read

```<code>local file = file:open(somePath)
if file then
  -- set cursor to -5 bytes from the file's end
  file:seek("end", -5)
  -- read 3 bytes
  print(file:read(3))
  file:close()
end
</code>```

You cannot search in a file without reading it. If you don't want to read the entire file you can read it in chunks either by reading it linewise (if there are lines in your file) or by reading a specific number of bytes each time until you find something.
Of course you can also read it byte-wise.

You can argue if it makes more sense to read a 64 byte file as a whole or in chunks. I mean in most scenarios you won't notice any difference.

So you could file:read(1) in a loop that terminates once you found a V or reach the end of the file.

```<code>local file = io.open(somePath)
if file then
  local data = ""
  for i = 1, 64 do
    local b = file:read(1)
    if not b then print("no V in file") data = nil break end
    data = data .. b
    if b == "V" then print(data) break end
  end
  file:close()
end
</code>```

vs

```<code>local file = io.open("d:/test.txt", "r")
if file then
  local data = file:read("a")
  local pos = data:find("V")
  if pos then
      print(data:sub(1, pos))
  end
  file:close()
end
</code>```

Body:
Is it possible to search at first inside the file after an specific byte and find the position and read just the bytes from the file in until that specific byte?

At the moment it is just possible for me to read some bytes or the whole file in and afterwards search for that specific byte.
like this:

local function read_file(path)
  local file = open(path, "r") -- r read mode and b binary mode
  if not file then return nil end
  local content = file:read(64) -- reading 64 bytes
  file:close()
  return content
end

local fileContent = read_file("../test/l_0.dat");
print(fileContent)

function parse(line)
   if line then
     len = 1
     a = line:find("V", len +1) --find V in content
     return a
   else
     return false
   end
end

a = parse(fileContent) --position of V in content
print(a)
print(string.sub(fileContent, a)) -- content until first found V

In this example i find at position 21 the first V. So it would be cool to read in only 21 bytes except of 64 bytes or the whole file. But then i need to find the position before reading something in. Is this possible ? (The 21byte are variable, it could be 20 or 50 or so on)

Body:
You can specify a file position using file:seek and read a certain number of characters (bytes) by providing an integer to file:read

local file = file:open(somePath)
if file then
  -- set cursor to -5 bytes from the file's end
  file:seek("end", -5)
  -- read 3 bytes
  print(file:read(3))
  file:close()
end

You cannot search in a file without reading it. If you don't want to read the entire file you can read it in chunks either by reading it linewise (if there are lines in your file) or by reading a specific number of bytes each time until you find something.
Of course you can also read it byte-wise.

You can argue if it makes more sense to read a 64 byte file as a whole or in chunks. I mean in most scenarios you won't notice any difference.

So you could file:read(1) in a loop that terminates once you found a V or reach the end of the file.

local file = io.open(somePath)
if file then
  local data = ""
  for i = 1, 64 do
    local b = file:read(1)
    if not b then print("no V in file") data = nil break end
    data = data .. b
    if b == "V" then print(data) break end
  end
  file:close()
end

vs

local file = io.open("d:/test.txt", "r")
if file then
  local data = file:read("a")
  local pos = data:find("V")
  if pos then
      print(data:sub(1, pos))
  end
  file:close()
end


问:
how to caculate in GF(2^8) in Python?
```<code>x=Symbol('x')

M=Matrix([[1,x],[x^2,x^3]])

s=M.det()

f=lambdify(x,s)
</code>```

I need to know f(2)=? in GF(2^8),the caculate rules obey the GF(2^8)

答:
In GF(2^8), the elements are usually represented as formal polynomials of degree 7, which are sums of monic monomials. E.g. x² + x, which can be written in the compact form 00000110 (this is not to be taken as an ordinary binary number).

Evaluating the polynomial at some x does not make sense and is not made, especially as x should not be other than 0 or 1. (You might be tempted to say that 0²+0=0 and 1²+1=0, but this is irrelevant.)

Title: how to caculate in GF(2^8) in Python?

Body:
x=Symbol('x')

M=Matrix([[1,x],[x^2,x^3]])

s=M.det()

f=lambdify(x,s)

I need to know f(2)=? in GF(2^8),the caculate rules obey the GF(2^8)


问:
is there any way to change the default type for xsd:element?

If i declare an xsd element without explicitly specifying a type: <xsd:element name="e"> what would be the assumed type?

Is there any way to change the "default type" ?

答:
It is the ur-type, http://www.w3.org/TR/xmlschema-1/#ur-type-itself, or anyType. So anything goes!

Not that I'm aware of


问:
finish git rebase operation after conflict
For my job I need to do a git rebase of my feature branch onto the development branch.

These are my commands thus far to prepare the rebase:

```<code>git checkout feature-branch
git rebase development
# resolve conflicts in Visual Studio
git rebase --continue
</code>```

After this, I'm getting the following in the cmd:

Now it's just as if I'm typing a novel in Notepad. Hitting enter, ctrl + C, ... doesn't do anything.

I've already read other questions like this one but this doesn't offer me a clue of how to complete the rebase / exit the shell.

So how do I finish this rebase operation? What buttons do I need to press?

答: It looks like you've been dropped into the vim editor, and currently in replace mode.  You can get out of that by just hitting esc. Then you can type i to enter insert mode (which will probably behave more as you'd expect). Type your commit message, then hit esc again (back to command mode), then :wq (write-quit) and enter, and you're done.

Body:
For my job I need to do a git rebase of my feature branch onto the development branch.

These are my commands thus far to prepare the rebase:

git checkout feature-branch
git rebase development
# resolve conflicts in Visual Studio
git rebase --continue

After this, I'm getting the following in the cmd:

Now it's just as if I'm typing a novel in Notepad. Hitting enter, ctrl + C, ... doesn't do anything.

I've already read other questions like this one but this doesn't offer me a clue of how to complete the rebase / exit the shell.

So how do I finish this rebase operation? What buttons do I need to press?


问:
Generate new variable by grouping an old one according to its value characteristic
I want to generate a new variable in Stata by grouping an old one according to its value characteristics. I have one variable called status that reflects employment type and status, so it has values like "Manager", "Ex-Manager", "Employee", "Ex-Employee".

Now I want to generate a new dummy variable that equals 1 if the person is still employed (contains "Manager" and "Employee") and equals 0 if the person is no longer employed ("Ex-Employee", "Ex-Manager").

答:
```<code>generate wanted = inlist(status, "Manager", "Employee") if !missing(status)
</code>```

will produce an indicator variable that is 1 if status is either of the specified values, 0 if it is another specified value, and missing if status is missing (meaning, an empty string).

See the help for inlist() and FAQs such as

https://www.stata.com/support/faqs/data-management/creating-dummy-variables/

https://www.stata.com/support/faqs/data-management/true-and-false/

Note that the comparison is entirely literal (no incorrect spellings or extra spaces or characters).

Body:
generate wanted = inlist(status, "Manager", "Employee") if !missing(status)

will produce an indicator variable that is 1 if status is either of the specified values, 0 if it is another specified value, and missing if status is missing (meaning, an empty string).

See the help for inlist() and FAQs such as

https://www.stata.com/support/faqs/data-management/creating-dummy-variables/

https://www.stata.com/support/faqs/data-management/true-and-false/

Note that the comparison is entirely literal (no incorrect spellings or extra spaces or characters).


问:
Device not applicable for the "main.dart" configuration ,
I use Android Studio as my IDE in coding Flutter. I was able to create 2 projects before this and it worked absolutely fine. I had to clone a repo from Github. The IDE said to get config. I did that then this happened.

I already installed sdk .

My android devices android version is 7.0

Flutter Doctor result:

```<code>[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-US)
    • Flutter version 1.12.13+hotfix.8 at C:\src\flutter\flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[!] Android Studio
    • Android Studio at C:\Program
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = C:\Program
    X Android Studio not found at C:\Program
    • Try updating or re-installing Android Studio.
    • Consider removing your android-studio-dir setting by running:
      flutter config --android-studio-dir=

[!] VS Code
    • VS Code at C:\Users\Tamim Mostafa\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected device
    ! No devices available

! Doctor found issues in 4 categories.
</code>```

I also tried changing the directory an using folder with no white space. I moved the Sdk folder to D:\Android\Sdk. flutter doctor -v:

```<code>[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-US)
    • Flutter version 1.12.13+hotfix.8 at C:\src\flutter\flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[X] Android toolchain - develop for Android devices
    X ANDROID_HOME = D:\Android\Sdk
      but Android SDK not found at this location.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[!] Android Studio
    • Android Studio at C:\Program
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = C:\Program
    X Android Studio not found at C:\Program
    • Try updating or re-installing Android Studio.
    • Consider removing your android-studio-dir setting by running:
      flutter config --android-studio-dir=

[!] VS Code
    • VS Code at C:\Users\Tamim Mostafa\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected device
    ! No devices available

! Doctor found issues in 4 categories.
</code>```

答:
Check your Dart SDK and Flutter SDK path setup in the Environment variable setup and inside the setting of the android studio as well.

If it is ok then Do Invalid Caches/ Restart the project and Check.

It might be helped. !!!

Body:
I use Android Studio as my IDE in coding Flutter. I was able to create 2 projects before this and it worked absolutely fine. I had to clone a repo from Github. The IDE said to get config. I did that then this happened.

I already installed sdk .

My android devices android version is 7.0

Flutter Doctor result:

[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-US)
    • Flutter version 1.12.13+hotfix.8 at C:\src\flutter\flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[!] Android Studio
    • Android Studio at C:\Program
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = C:\Program
    X Android Studio not found at C:\Program
    • Try updating or re-installing Android Studio.
    • Consider removing your android-studio-dir setting by running:
      flutter config --android-studio-dir=

[!] VS Code
    • VS Code at C:\Users\Tamim Mostafa\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected device
    ! No devices available

! Doctor found issues in 4 categories.

I also tried changing the directory an using folder with no white space. I moved the Sdk folder to D:\Android\Sdk. flutter doctor -v:

[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.720], locale en-US)
    • Flutter version 1.12.13+hotfix.8 at C:\src\flutter\flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[X] Android toolchain - develop for Android devices
    X ANDROID_HOME = D:\Android\Sdk
      but Android SDK not found at this location.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[!] Android Studio
    • Android Studio at C:\Program
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = C:\Program
    X Android Studio not found at C:\Program
    • Try updating or re-installing Android Studio.
    • Consider removing your android-studio-dir setting by running:
      flutter config --android-studio-dir=

[!] VS Code
    • VS Code at C:\Users\Tamim Mostafa\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected device
    ! No devices available

! Doctor found issues in 4 categories.